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 | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 62 | static int ql_dm_tgt_ex_pct = 50; |
| 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); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 133 | /* |
| 134 | * Global Variables |
| 135 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 136 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 137 | static struct kmem_cache *qla_tgt_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 138 | static mempool_t *qla_tgt_mgmt_cmd_mempool; |
| 139 | static struct workqueue_struct *qla_tgt_wq; |
| 140 | static DEFINE_MUTEX(qla_tgt_mutex); |
| 141 | static LIST_HEAD(qla_tgt_glist); |
| 142 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 143 | /* This API intentionally takes dest as a parameter, rather than returning |
| 144 | * int value to avoid caller forgetting to issue wmb() after the store */ |
| 145 | void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest) |
| 146 | { |
| 147 | scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev); |
| 148 | *dest = atomic_inc_return(&base_vha->generation_tick); |
| 149 | /* memory barrier */ |
| 150 | wmb(); |
| 151 | } |
| 152 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 153 | /* Might release hw lock, then reaquire!! */ |
| 154 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) |
| 155 | { |
| 156 | /* Send marker if required */ |
| 157 | if (unlikely(vha->marker_needed != 0)) { |
| 158 | int rc = qla2x00_issue_marker(vha, vha_locked); |
| 159 | if (rc != QLA_SUCCESS) { |
| 160 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, |
| 161 | "qla_target(%d): issue_marker() failed\n", |
| 162 | vha->vp_idx); |
| 163 | } |
| 164 | return rc; |
| 165 | } |
| 166 | return QLA_SUCCESS; |
| 167 | } |
| 168 | |
| 169 | static inline |
| 170 | struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha, |
| 171 | uint8_t *d_id) |
| 172 | { |
| 173 | struct qla_hw_data *ha = vha->hw; |
| 174 | uint8_t vp_idx; |
| 175 | |
| 176 | if ((vha->d_id.b.area != d_id[1]) || (vha->d_id.b.domain != d_id[0])) |
| 177 | return NULL; |
| 178 | |
| 179 | if (vha->d_id.b.al_pa == d_id[2]) |
| 180 | return vha; |
| 181 | |
| 182 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 183 | vp_idx = ha->tgt.tgt_vp_map[d_id[2]].idx; |
| 184 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 185 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 186 | |
| 187 | return NULL; |
| 188 | } |
| 189 | |
| 190 | static inline |
| 191 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, |
| 192 | uint16_t vp_idx) |
| 193 | { |
| 194 | struct qla_hw_data *ha = vha->hw; |
| 195 | |
| 196 | if (vha->vp_idx == vp_idx) |
| 197 | return vha; |
| 198 | |
| 199 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 200 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 201 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 202 | |
| 203 | return NULL; |
| 204 | } |
| 205 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 206 | static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha) |
| 207 | { |
| 208 | unsigned long flags; |
| 209 | |
| 210 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 211 | |
| 212 | vha->hw->tgt.num_pend_cmds++; |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 213 | if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds) |
| 214 | vha->qla_stats.stat_max_pend_cmds = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 215 | vha->hw->tgt.num_pend_cmds; |
| 216 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 217 | } |
| 218 | static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha) |
| 219 | { |
| 220 | unsigned long flags; |
| 221 | |
| 222 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 223 | vha->hw->tgt.num_pend_cmds--; |
| 224 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 225 | } |
| 226 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 227 | |
| 228 | static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, |
| 229 | struct atio_from_isp *atio, uint8_t ha_locked) |
| 230 | { |
| 231 | struct qla_tgt_sess_op *u; |
| 232 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 233 | unsigned long flags; |
| 234 | |
| 235 | if (tgt->tgt_stop) { |
| 236 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 237 | "qla_target(%d): dropping unknown ATIO_TYPE7, " |
| 238 | "because tgt is being stopped", vha->vp_idx); |
| 239 | goto out_term; |
| 240 | } |
| 241 | |
| 242 | u = kzalloc(sizeof(*u), GFP_ATOMIC); |
| 243 | if (u == NULL) { |
| 244 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 245 | "Alloc of struct unknown_atio (size %zd) failed", sizeof(*u)); |
| 246 | /* It should be harmless and on the next retry should work well */ |
| 247 | goto out_term; |
| 248 | } |
| 249 | |
| 250 | u->vha = vha; |
| 251 | memcpy(&u->atio, atio, sizeof(*atio)); |
| 252 | INIT_LIST_HEAD(&u->cmd_list); |
| 253 | |
| 254 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 255 | list_add_tail(&u->cmd_list, &vha->unknown_atio_list); |
| 256 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 257 | |
| 258 | schedule_delayed_work(&vha->unknown_atio_work, 1); |
| 259 | |
| 260 | out: |
| 261 | return; |
| 262 | |
| 263 | out_term: |
| 264 | qlt_send_term_exchange(vha, NULL, atio, ha_locked, 0); |
| 265 | goto out; |
| 266 | } |
| 267 | |
| 268 | static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha, |
| 269 | uint8_t ha_locked) |
| 270 | { |
| 271 | struct qla_tgt_sess_op *u, *t; |
| 272 | scsi_qla_host_t *host; |
| 273 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 274 | unsigned long flags; |
| 275 | uint8_t queued = 0; |
| 276 | |
| 277 | list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) { |
| 278 | if (u->aborted) { |
| 279 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 280 | "Freeing unknown %s %p, because of Abort", |
| 281 | "ATIO_TYPE7", u); |
| 282 | qlt_send_term_exchange(vha, NULL, &u->atio, |
| 283 | ha_locked, 0); |
| 284 | goto abort; |
| 285 | } |
| 286 | |
| 287 | host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id); |
| 288 | if (host != NULL) { |
| 289 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 290 | "Requeuing unknown ATIO_TYPE7 %p", u); |
| 291 | qlt_24xx_atio_pkt(host, &u->atio, ha_locked); |
| 292 | } else if (tgt->tgt_stop) { |
| 293 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 294 | "Freeing unknown %s %p, because tgt is being stopped", |
| 295 | "ATIO_TYPE7", u); |
| 296 | qlt_send_term_exchange(vha, NULL, &u->atio, |
| 297 | ha_locked, 0); |
| 298 | } else { |
| 299 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 300 | "u %p, vha %p, host %p, sched again..", u, |
| 301 | vha, host); |
| 302 | if (!queued) { |
| 303 | queued = 1; |
| 304 | schedule_delayed_work(&vha->unknown_atio_work, |
| 305 | 1); |
| 306 | } |
| 307 | continue; |
| 308 | } |
| 309 | |
| 310 | abort: |
| 311 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 312 | list_del(&u->cmd_list); |
| 313 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 314 | kfree(u); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | void qlt_unknown_atio_work_fn(struct work_struct *work) |
| 319 | { |
| 320 | struct scsi_qla_host *vha = container_of(to_delayed_work(work), |
| 321 | struct scsi_qla_host, unknown_atio_work); |
| 322 | |
| 323 | qlt_try_to_dequeue_unknown_atios(vha, 0); |
| 324 | } |
| 325 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 326 | 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] | 327 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 328 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 329 | ql_dbg(ql_dbg_tgt, vha, 0xe072, |
| 330 | "%s: qla_target(%d): type %x ox_id %04x\n", |
| 331 | __func__, vha->vp_idx, atio->u.raw.entry_type, |
| 332 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 333 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 334 | switch (atio->u.raw.entry_type) { |
| 335 | case ATIO_TYPE7: |
| 336 | { |
| 337 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, |
| 338 | atio->u.isp24.fcp_hdr.d_id); |
| 339 | if (unlikely(NULL == host)) { |
| 340 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, |
| 341 | "qla_target(%d): Received ATIO_TYPE7 " |
| 342 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, |
| 343 | atio->u.isp24.fcp_hdr.d_id[0], |
| 344 | atio->u.isp24.fcp_hdr.d_id[1], |
| 345 | atio->u.isp24.fcp_hdr.d_id[2]); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 346 | |
| 347 | |
| 348 | qlt_queue_unknown_atio(vha, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 349 | break; |
| 350 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 351 | if (unlikely(!list_empty(&vha->unknown_atio_list))) |
| 352 | qlt_try_to_dequeue_unknown_atios(vha, ha_locked); |
| 353 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 354 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 355 | break; |
| 356 | } |
| 357 | |
| 358 | case IMMED_NOTIFY_TYPE: |
| 359 | { |
| 360 | struct scsi_qla_host *host = vha; |
| 361 | struct imm_ntfy_from_isp *entry = |
| 362 | (struct imm_ntfy_from_isp *)atio; |
| 363 | |
| 364 | if ((entry->u.isp24.vp_index != 0xFF) && |
| 365 | (entry->u.isp24.nport_handle != 0xFFFF)) { |
| 366 | host = qlt_find_host_by_vp_idx(vha, |
| 367 | entry->u.isp24.vp_index); |
| 368 | if (unlikely(!host)) { |
| 369 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, |
| 370 | "qla_target(%d): Received " |
| 371 | "ATIO (IMMED_NOTIFY_TYPE) " |
| 372 | "with unknown vp_index %d\n", |
| 373 | vha->vp_idx, entry->u.isp24.vp_index); |
| 374 | break; |
| 375 | } |
| 376 | } |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 377 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 378 | break; |
| 379 | } |
| 380 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 381 | case VP_RPT_ID_IOCB_TYPE: |
| 382 | qla24xx_report_id_acquisition(vha, |
| 383 | (struct vp_rpt_id_entry_24xx *)atio); |
| 384 | break; |
| 385 | |
| 386 | case ABTS_RECV_24XX: |
| 387 | { |
| 388 | struct abts_recv_from_24xx *entry = |
| 389 | (struct abts_recv_from_24xx *)atio; |
| 390 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 391 | entry->vp_index); |
| 392 | if (unlikely(!host)) { |
| 393 | ql_dbg(ql_dbg_tgt, vha, 0xffff, |
| 394 | "qla_target(%d): Response pkt (ABTS_RECV_24XX) " |
| 395 | "received, with unknown vp_index %d\n", |
| 396 | vha->vp_idx, entry->vp_index); |
| 397 | break; |
| 398 | } |
| 399 | qlt_response_pkt(host, (response_t *)atio); |
| 400 | break; |
| 401 | |
| 402 | } |
| 403 | |
| 404 | /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */ |
| 405 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 406 | default: |
| 407 | ql_dbg(ql_dbg_tgt, vha, 0xe040, |
| 408 | "qla_target(%d): Received unknown ATIO atio " |
| 409 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 410 | break; |
| 411 | } |
| 412 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 413 | return false; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, response_t *pkt) |
| 417 | { |
| 418 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 419 | case CTIO_CRC2: |
| 420 | ql_dbg(ql_dbg_tgt, vha, 0xe073, |
| 421 | "qla_target(%d):%s: CRC2 Response pkt\n", |
| 422 | vha->vp_idx, __func__); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 423 | case CTIO_TYPE7: |
| 424 | { |
| 425 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
| 426 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 427 | entry->vp_index); |
| 428 | if (unlikely(!host)) { |
| 429 | ql_dbg(ql_dbg_tgt, vha, 0xe041, |
| 430 | "qla_target(%d): Response pkt (CTIO_TYPE7) " |
| 431 | "received, with unknown vp_index %d\n", |
| 432 | vha->vp_idx, entry->vp_index); |
| 433 | break; |
| 434 | } |
| 435 | qlt_response_pkt(host, pkt); |
| 436 | break; |
| 437 | } |
| 438 | |
| 439 | case IMMED_NOTIFY_TYPE: |
| 440 | { |
| 441 | struct scsi_qla_host *host = vha; |
| 442 | struct imm_ntfy_from_isp *entry = |
| 443 | (struct imm_ntfy_from_isp *)pkt; |
| 444 | |
| 445 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); |
| 446 | if (unlikely(!host)) { |
| 447 | ql_dbg(ql_dbg_tgt, vha, 0xe042, |
| 448 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " |
| 449 | "received, with unknown vp_index %d\n", |
| 450 | vha->vp_idx, entry->u.isp24.vp_index); |
| 451 | break; |
| 452 | } |
| 453 | qlt_response_pkt(host, pkt); |
| 454 | break; |
| 455 | } |
| 456 | |
| 457 | case NOTIFY_ACK_TYPE: |
| 458 | { |
| 459 | struct scsi_qla_host *host = vha; |
| 460 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 461 | |
| 462 | if (0xFF != entry->u.isp24.vp_index) { |
| 463 | host = qlt_find_host_by_vp_idx(vha, |
| 464 | entry->u.isp24.vp_index); |
| 465 | if (unlikely(!host)) { |
| 466 | ql_dbg(ql_dbg_tgt, vha, 0xe043, |
| 467 | "qla_target(%d): Response " |
| 468 | "pkt (NOTIFY_ACK_TYPE) " |
| 469 | "received, with unknown " |
| 470 | "vp_index %d\n", vha->vp_idx, |
| 471 | entry->u.isp24.vp_index); |
| 472 | break; |
| 473 | } |
| 474 | } |
| 475 | qlt_response_pkt(host, pkt); |
| 476 | break; |
| 477 | } |
| 478 | |
| 479 | case ABTS_RECV_24XX: |
| 480 | { |
| 481 | struct abts_recv_from_24xx *entry = |
| 482 | (struct abts_recv_from_24xx *)pkt; |
| 483 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 484 | entry->vp_index); |
| 485 | if (unlikely(!host)) { |
| 486 | ql_dbg(ql_dbg_tgt, vha, 0xe044, |
| 487 | "qla_target(%d): Response pkt " |
| 488 | "(ABTS_RECV_24XX) received, with unknown " |
| 489 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 490 | break; |
| 491 | } |
| 492 | qlt_response_pkt(host, pkt); |
| 493 | break; |
| 494 | } |
| 495 | |
| 496 | case ABTS_RESP_24XX: |
| 497 | { |
| 498 | struct abts_resp_to_24xx *entry = |
| 499 | (struct abts_resp_to_24xx *)pkt; |
| 500 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 501 | entry->vp_index); |
| 502 | if (unlikely(!host)) { |
| 503 | ql_dbg(ql_dbg_tgt, vha, 0xe045, |
| 504 | "qla_target(%d): Response pkt " |
| 505 | "(ABTS_RECV_24XX) received, with unknown " |
| 506 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 507 | break; |
| 508 | } |
| 509 | qlt_response_pkt(host, pkt); |
| 510 | break; |
| 511 | } |
| 512 | |
| 513 | default: |
| 514 | qlt_response_pkt(vha, pkt); |
| 515 | break; |
| 516 | } |
| 517 | |
| 518 | } |
| 519 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 520 | /* |
| 521 | * All qlt_plogi_ack_t operations are protected by hardware_lock |
| 522 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 523 | static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 524 | struct imm_ntfy_from_isp *ntfy, int type) |
| 525 | { |
| 526 | struct qla_work_evt *e; |
| 527 | e = qla2x00_alloc_work(vha, QLA_EVT_NACK); |
| 528 | if (!e) |
| 529 | return QLA_FUNCTION_FAILED; |
| 530 | |
| 531 | e->u.nack.fcport = fcport; |
| 532 | e->u.nack.type = type; |
| 533 | memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp)); |
| 534 | return qla2x00_post_work(vha, e); |
| 535 | } |
| 536 | |
| 537 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 538 | void qla2x00_async_nack_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 539 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 540 | struct srb *sp = (struct srb *)s; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 541 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 542 | unsigned long flags; |
| 543 | |
| 544 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 545 | "Async done-%s res %x %8phC type %d\n", |
| 546 | sp->name, res, sp->fcport->port_name, sp->type); |
| 547 | |
| 548 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 549 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
| 550 | sp->fcport->chip_reset = vha->hw->chip_reset; |
| 551 | |
| 552 | switch (sp->type) { |
| 553 | case SRB_NACK_PLOGI: |
| 554 | sp->fcport->login_gen++; |
| 555 | sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP; |
| 556 | sp->fcport->logout_on_delete = 1; |
| 557 | break; |
| 558 | |
| 559 | case SRB_NACK_PRLI: |
| 560 | sp->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 561 | sp->fcport->deleted = 0; |
| 562 | |
| 563 | if (!sp->fcport->login_succ && |
| 564 | !IS_SW_RESV_ADDR(sp->fcport->d_id)) { |
| 565 | sp->fcport->login_succ = 1; |
| 566 | |
| 567 | vha->fcport_count++; |
| 568 | |
| 569 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 570 | !vha->hw->flags.gpsc_supported) { |
| 571 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 572 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 573 | __func__, __LINE__, |
| 574 | sp->fcport->port_name, |
| 575 | vha->fcport_count); |
| 576 | |
| 577 | qla24xx_post_upd_fcport_work(vha, sp->fcport); |
| 578 | } else { |
| 579 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 580 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 581 | __func__, __LINE__, |
| 582 | sp->fcport->port_name, |
| 583 | vha->fcport_count); |
| 584 | |
| 585 | qla24xx_post_gpsc_work(vha, sp->fcport); |
| 586 | } |
| 587 | } |
| 588 | break; |
| 589 | |
| 590 | case SRB_NACK_LOGO: |
| 591 | sp->fcport->login_gen++; |
| 592 | sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 593 | qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE); |
| 594 | break; |
| 595 | } |
| 596 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 597 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 598 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport, |
| 602 | struct imm_ntfy_from_isp *ntfy, int type) |
| 603 | { |
| 604 | int rval = QLA_FUNCTION_FAILED; |
| 605 | srb_t *sp; |
| 606 | char *c = NULL; |
| 607 | |
| 608 | fcport->flags |= FCF_ASYNC_SENT; |
| 609 | switch (type) { |
| 610 | case SRB_NACK_PLOGI: |
| 611 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; |
| 612 | c = "PLOGI"; |
| 613 | break; |
| 614 | case SRB_NACK_PRLI: |
| 615 | fcport->fw_login_state = DSC_LS_PRLI_PEND; |
| 616 | c = "PRLI"; |
| 617 | break; |
| 618 | case SRB_NACK_LOGO: |
| 619 | fcport->fw_login_state = DSC_LS_LOGO_PEND; |
| 620 | c = "LOGO"; |
| 621 | break; |
| 622 | } |
| 623 | |
| 624 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
| 625 | if (!sp) |
| 626 | goto done; |
| 627 | |
| 628 | sp->type = type; |
| 629 | sp->name = "nack"; |
| 630 | |
| 631 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 632 | |
| 633 | sp->u.iocb_cmd.u.nack.ntfy = ntfy; |
| 634 | |
| 635 | sp->done = qla2x00_async_nack_sp_done; |
| 636 | |
| 637 | rval = qla2x00_start_sp(sp); |
| 638 | if (rval != QLA_SUCCESS) |
| 639 | goto done_free_sp; |
| 640 | |
| 641 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 642 | "Async-%s %8phC hndl %x %s\n", |
| 643 | sp->name, fcport->port_name, sp->handle, c); |
| 644 | |
| 645 | return rval; |
| 646 | |
| 647 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 648 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 649 | done: |
| 650 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 651 | return rval; |
| 652 | } |
| 653 | |
| 654 | void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
| 655 | { |
| 656 | fc_port_t *t; |
| 657 | unsigned long flags; |
| 658 | |
| 659 | switch (e->u.nack.type) { |
| 660 | case SRB_NACK_PRLI: |
| 661 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 662 | t = qlt_create_sess(vha, e->u.nack.fcport, 0); |
| 663 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 664 | if (t) { |
| 665 | ql_log(ql_log_info, vha, 0xffff, |
| 666 | "%s create sess success %p", __func__, t); |
| 667 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 668 | /* create sess has an extra kref */ |
| 669 | vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport); |
| 670 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 671 | } |
| 672 | break; |
| 673 | } |
| 674 | qla24xx_async_notify_ack(vha, e->u.nack.fcport, |
| 675 | (struct imm_ntfy_from_isp*)e->u.nack.iocb, e->u.nack.type); |
| 676 | } |
| 677 | |
| 678 | void qla24xx_delete_sess_fn(struct work_struct *work) |
| 679 | { |
| 680 | fc_port_t *fcport = container_of(work, struct fc_port, del_work); |
| 681 | struct qla_hw_data *ha = fcport->vha->hw; |
| 682 | unsigned long flags; |
| 683 | |
| 684 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 685 | |
| 686 | if (fcport->se_sess) { |
| 687 | ha->tgt.tgt_ops->shutdown_sess(fcport); |
| 688 | ha->tgt.tgt_ops->put_sess(fcport); |
| 689 | } else { |
| 690 | qlt_unreg_sess(fcport); |
| 691 | } |
| 692 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 693 | } |
| 694 | |
| 695 | /* |
| 696 | * Called from qla2x00_reg_remote_port() |
| 697 | */ |
| 698 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 699 | { |
| 700 | struct qla_hw_data *ha = vha->hw; |
| 701 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 702 | struct fc_port *sess = fcport; |
| 703 | unsigned long flags; |
| 704 | |
| 705 | if (!vha->hw->tgt.tgt_ops) |
| 706 | return; |
| 707 | |
| 708 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 709 | if (tgt->tgt_stop) { |
| 710 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 711 | return; |
| 712 | } |
| 713 | |
| 714 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 715 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 716 | return; |
| 717 | } |
| 718 | |
| 719 | if (!sess->se_sess) { |
| 720 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 721 | |
| 722 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 723 | sess = qlt_create_sess(vha, fcport, false); |
| 724 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 725 | |
| 726 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 727 | } else { |
| 728 | if (fcport->fw_login_state == DSC_LS_PRLI_COMP) { |
| 729 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 730 | return; |
| 731 | } |
| 732 | |
| 733 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 734 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 735 | "%s: kref_get fail sess %8phC \n", |
| 736 | __func__, sess->port_name); |
| 737 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 738 | return; |
| 739 | } |
| 740 | |
| 741 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, |
| 742 | "qla_target(%u): %ssession for port %8phC " |
| 743 | "(loop ID %d) reappeared\n", vha->vp_idx, |
| 744 | sess->local ? "local " : "", sess->port_name, sess->loop_id); |
| 745 | |
| 746 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, |
| 747 | "Reappeared sess %p\n", sess); |
| 748 | |
| 749 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, |
| 750 | fcport->loop_id, |
| 751 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
| 752 | } |
| 753 | |
| 754 | if (sess && sess->local) { |
| 755 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, |
| 756 | "qla_target(%u): local session for " |
| 757 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
| 758 | fcport->port_name, sess->loop_id); |
| 759 | sess->local = 0; |
| 760 | } |
| 761 | ha->tgt.tgt_ops->put_sess(sess); |
| 762 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 763 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 764 | |
| 765 | /* |
| 766 | * This is a zero-base ref-counting solution, since hardware_lock |
| 767 | * guarantees that ref_count is not modified concurrently. |
| 768 | * Upon successful return content of iocb is undefined |
| 769 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 770 | static struct qlt_plogi_ack_t * |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 771 | qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id, |
| 772 | struct imm_ntfy_from_isp *iocb) |
| 773 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 774 | struct qlt_plogi_ack_t *pla; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 775 | |
| 776 | list_for_each_entry(pla, &vha->plogi_ack_list, list) { |
| 777 | if (pla->id.b24 == id->b24) { |
| 778 | qlt_send_term_imm_notif(vha, &pla->iocb, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 779 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 780 | return pla; |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC); |
| 785 | if (!pla) { |
| 786 | ql_dbg(ql_dbg_async, vha, 0x5088, |
| 787 | "qla_target(%d): Allocation of plogi_ack failed\n", |
| 788 | vha->vp_idx); |
| 789 | return NULL; |
| 790 | } |
| 791 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 792 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 793 | pla->id = *id; |
| 794 | list_add_tail(&pla->list, &vha->plogi_ack_list); |
| 795 | |
| 796 | return pla; |
| 797 | } |
| 798 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 799 | void qlt_plogi_ack_unref(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 800 | struct qlt_plogi_ack_t *pla) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 801 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 802 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 803 | port_id_t port_id; |
| 804 | uint16_t loop_id; |
| 805 | fc_port_t *fcport = pla->fcport; |
| 806 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 807 | BUG_ON(!pla->ref_count); |
| 808 | pla->ref_count--; |
| 809 | |
| 810 | if (pla->ref_count) |
| 811 | return; |
| 812 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 813 | ql_dbg(ql_dbg_disc, vha, 0x5089, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 814 | "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] | 815 | " exch %#x ox_id %#x\n", iocb->u.isp24.port_name, |
| 816 | iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1], |
| 817 | iocb->u.isp24.port_id[0], |
| 818 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 819 | iocb->u.isp24.exchange_address, iocb->ox_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 820 | |
| 821 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 822 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 823 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 824 | port_id.b.rsvd_1 = 0; |
| 825 | |
| 826 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 827 | |
| 828 | fcport->loop_id = loop_id; |
| 829 | fcport->d_id = port_id; |
| 830 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI); |
| 831 | |
| 832 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 833 | if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla) |
| 834 | fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 835 | if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla) |
| 836 | fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
| 837 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 838 | |
| 839 | list_del(&pla->list); |
| 840 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 841 | } |
| 842 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 843 | void |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 844 | qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla, |
| 845 | struct fc_port *sess, enum qlt_plogi_link_t link) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 846 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 847 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 848 | /* Inc ref_count first because link might already be pointing at pla */ |
| 849 | pla->ref_count++; |
| 850 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 851 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097, |
| 852 | "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC" |
| 853 | " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n", |
| 854 | sess, link, sess->port_name, |
| 855 | iocb->u.isp24.port_name, iocb->u.isp24.port_id[2], |
| 856 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 857 | pla->ref_count, pla, link); |
| 858 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 859 | if (sess->plogi_link[link]) |
| 860 | qlt_plogi_ack_unref(vha, sess->plogi_link[link]); |
| 861 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 862 | if (link == QLT_PLOGI_LINK_SAME_WWN) |
| 863 | pla->fcport = sess; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 864 | |
| 865 | sess->plogi_link[link] = pla; |
| 866 | } |
| 867 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 868 | typedef struct { |
| 869 | /* These fields must be initialized by the caller */ |
| 870 | port_id_t id; |
| 871 | /* |
| 872 | * number of cmds dropped while we were waiting for |
| 873 | * initiator to ack LOGO initialize to 1 if LOGO is |
| 874 | * triggered by a command, otherwise, to 0 |
| 875 | */ |
| 876 | int cmd_count; |
| 877 | |
| 878 | /* These fields are used by callee */ |
| 879 | struct list_head list; |
| 880 | } qlt_port_logo_t; |
| 881 | |
| 882 | static void |
| 883 | qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo) |
| 884 | { |
| 885 | qlt_port_logo_t *tmp; |
| 886 | int res; |
| 887 | |
| 888 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 889 | |
| 890 | list_for_each_entry(tmp, &vha->logo_list, list) { |
| 891 | if (tmp->id.b24 == logo->id.b24) { |
| 892 | tmp->cmd_count += logo->cmd_count; |
| 893 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 894 | return; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | list_add_tail(&logo->list, &vha->logo_list); |
| 899 | |
| 900 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 901 | |
| 902 | res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id); |
| 903 | |
| 904 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 905 | list_del(&logo->list); |
| 906 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 907 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 908 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098, |
| 909 | "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n", |
| 910 | logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa, |
| 911 | logo->cmd_count, res); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 912 | } |
| 913 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 914 | static void qlt_free_session_done(struct work_struct *work) |
| 915 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 916 | struct fc_port *sess = container_of(work, struct fc_port, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 917 | free_work); |
| 918 | struct qla_tgt *tgt = sess->tgt; |
| 919 | struct scsi_qla_host *vha = sess->vha; |
| 920 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 921 | unsigned long flags; |
| 922 | bool logout_started = false; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 923 | struct event_arg ea; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 924 | scsi_qla_host_t *base_vha; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 925 | |
| 926 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf084, |
| 927 | "%s: se_sess %p / sess %p from port %8phC loop_id %#04x" |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 928 | " 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] | 929 | __func__, sess->se_sess, sess, sess->port_name, sess->loop_id, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 930 | 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] | 931 | sess->logout_on_delete, sess->keep_nport_handle, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 932 | sess->send_els_logo); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 933 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 934 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 935 | if (!IS_SW_RESV_ADDR(sess->d_id)) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 936 | if (sess->send_els_logo) { |
| 937 | qlt_port_logo_t logo; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 938 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 939 | logo.id = sess->d_id; |
| 940 | logo.cmd_count = 0; |
| 941 | qlt_send_first_logo(vha, &logo); |
| 942 | } |
| 943 | |
| 944 | if (sess->logout_on_delete) { |
| 945 | int rc; |
| 946 | |
| 947 | rc = qla2x00_post_async_logout_work(vha, sess, NULL); |
| 948 | if (rc != QLA_SUCCESS) |
| 949 | ql_log(ql_log_warn, vha, 0xf085, |
| 950 | "Schedule logo failed sess %p rc %d\n", |
| 951 | sess, rc); |
| 952 | else |
| 953 | logout_started = true; |
| 954 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 955 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 956 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 957 | /* |
| 958 | * Release the target session for FC Nexus from fabric module code. |
| 959 | */ |
| 960 | if (sess->se_sess != NULL) |
| 961 | ha->tgt.tgt_ops->free_session(sess); |
| 962 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 963 | if (logout_started) { |
| 964 | bool traced = false; |
| 965 | |
| 966 | while (!ACCESS_ONCE(sess->logout_completed)) { |
| 967 | if (!traced) { |
| 968 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf086, |
| 969 | "%s: waiting for sess %p logout\n", |
| 970 | __func__, sess); |
| 971 | traced = true; |
| 972 | } |
| 973 | msleep(100); |
| 974 | } |
| 975 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 976 | ql_dbg(ql_dbg_disc, vha, 0xf087, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 977 | "%s: sess %p logout completed\n",__func__, sess); |
| 978 | } |
| 979 | |
| 980 | if (sess->logo_ack_needed) { |
| 981 | sess->logo_ack_needed = 0; |
| 982 | qla24xx_async_notify_ack(vha, sess, |
| 983 | (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 984 | } |
| 985 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 986 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 987 | if (sess->se_sess) { |
| 988 | sess->se_sess = NULL; |
| 989 | if (tgt && !IS_SW_RESV_ADDR(sess->d_id)) |
| 990 | tgt->sess_count--; |
| 991 | } |
| 992 | |
| 993 | sess->disc_state = DSC_DELETED; |
| 994 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 995 | sess->deleted = QLA_SESS_DELETED; |
| 996 | sess->login_retry = vha->hw->login_retry_count; |
| 997 | |
| 998 | if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) { |
| 999 | vha->fcport_count--; |
| 1000 | sess->login_succ = 0; |
| 1001 | } |
| 1002 | |
| 1003 | if (sess->chip_reset != sess->vha->hw->chip_reset) |
| 1004 | qla2x00_clear_loop_id(sess); |
| 1005 | |
| 1006 | if (sess->conflict) { |
| 1007 | sess->conflict->login_pause = 0; |
| 1008 | sess->conflict = NULL; |
| 1009 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 1010 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1011 | } |
| 1012 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1013 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1014 | struct qlt_plogi_ack_t *own = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1015 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1016 | struct qlt_plogi_ack_t *con = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1017 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1018 | struct imm_ntfy_from_isp *iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1019 | |
| 1020 | if (con) { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1021 | iocb = &con->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1022 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1023 | "se_sess %p / sess %p port %8phC is gone," |
| 1024 | " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n", |
| 1025 | sess->se_sess, sess, sess->port_name, |
| 1026 | own ? "releasing own PLOGI" : "no own PLOGI pending", |
| 1027 | own ? own->ref_count : -1, |
| 1028 | iocb->u.isp24.port_name, con->ref_count); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1029 | qlt_plogi_ack_unref(vha, con); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1030 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1031 | } else { |
| 1032 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a, |
| 1033 | "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n", |
| 1034 | sess->se_sess, sess, sess->port_name, |
| 1035 | own ? "releasing own PLOGI" : |
| 1036 | "no own PLOGI pending", |
| 1037 | own ? own->ref_count : -1); |
| 1038 | } |
| 1039 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1040 | if (own) { |
| 1041 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1042 | qlt_plogi_ack_unref(vha, own); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1043 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 1044 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1045 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1046 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1047 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1048 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1049 | "Unregistration of sess %p %8phC finished fcp_cnt %d\n", |
| 1050 | sess, sess->port_name, vha->fcport_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1051 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1052 | if (tgt && (tgt->sess_count == 0)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1053 | wake_up_all(&tgt->waitQ); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1054 | |
| 1055 | if (vha->fcport_count == 0) |
| 1056 | wake_up_all(&vha->fcport_waitQ); |
| 1057 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1058 | base_vha = pci_get_drvdata(ha->pdev); |
| 1059 | if (test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags)) |
| 1060 | return; |
| 1061 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1062 | if (!tgt || !tgt->tgt_stop) { |
| 1063 | memset(&ea, 0, sizeof(ea)); |
| 1064 | ea.event = FCME_DELETE_DONE; |
| 1065 | ea.fcport = sess; |
| 1066 | qla2x00_fcport_event_handler(vha, &ea); |
| 1067 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1068 | } |
| 1069 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1070 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1071 | void qlt_unreg_sess(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1072 | { |
| 1073 | struct scsi_qla_host *vha = sess->vha; |
| 1074 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1075 | ql_dbg(ql_dbg_disc, sess->vha, 0xffff, |
| 1076 | "%s sess %p for deletion %8phC\n", |
| 1077 | __func__, sess, sess->port_name); |
| 1078 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 1079 | if (sess->se_sess) |
| 1080 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1081 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1082 | qla2x00_mark_device_lost(vha, sess, 1, 1); |
| 1083 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1084 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1085 | sess->disc_state = DSC_DELETE_PEND; |
| 1086 | sess->last_rscn_gen = sess->rscn_gen; |
| 1087 | sess->last_login_gen = sess->login_gen; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1088 | |
| 1089 | INIT_WORK(&sess->free_work, qlt_free_session_done); |
| 1090 | schedule_work(&sess->free_work); |
| 1091 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1092 | EXPORT_SYMBOL(qlt_unreg_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1093 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1094 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) |
| 1095 | { |
| 1096 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1097 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1098 | uint16_t loop_id; |
| 1099 | int res = 0; |
| 1100 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1101 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1102 | |
| 1103 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); |
| 1104 | if (loop_id == 0xFFFF) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1105 | /* Global event */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1106 | atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1107 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1108 | qlt_clear_tgt_db(vha->vha_tgt.qla_tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1109 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1110 | } else { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1111 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1112 | 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] | 1113 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | ql_dbg(ql_dbg_tgt, vha, 0xe000, |
| 1117 | "Using sess for qla_tgt_reset: %p\n", sess); |
| 1118 | if (!sess) { |
| 1119 | res = -ESRCH; |
| 1120 | return res; |
| 1121 | } |
| 1122 | |
| 1123 | ql_dbg(ql_dbg_tgt, vha, 0xe047, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1124 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
| 1125 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1126 | mcmd, loop_id); |
| 1127 | |
Quinn Tran | bb1181c | 2016-12-23 18:06:05 -0800 | [diff] [blame] | 1128 | 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] | 1129 | } |
| 1130 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1131 | static void qla24xx_chk_fcp_state(struct fc_port *sess) |
| 1132 | { |
| 1133 | if (sess->chip_reset != sess->vha->hw->chip_reset) { |
| 1134 | sess->logout_on_delete = 0; |
| 1135 | sess->logo_ack_needed = 0; |
| 1136 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1137 | sess->scan_state = 0; |
| 1138 | } |
| 1139 | } |
| 1140 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1141 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1142 | void qlt_schedule_sess_for_deletion(struct fc_port *sess, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1143 | bool immediate) |
| 1144 | { |
| 1145 | struct qla_tgt *tgt = sess->tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1146 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1147 | if (sess->disc_state == DSC_DELETE_PEND) |
| 1148 | return; |
| 1149 | |
| 1150 | if (sess->disc_state == DSC_DELETED) { |
| 1151 | if (tgt && tgt->tgt_stop && (tgt->sess_count == 0)) |
| 1152 | wake_up_all(&tgt->waitQ); |
| 1153 | if (sess->vha->fcport_count == 0) |
| 1154 | wake_up_all(&sess->vha->fcport_waitQ); |
| 1155 | |
| 1156 | if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] && |
| 1157 | !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1158 | return; |
| 1159 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1160 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1161 | sess->disc_state = DSC_DELETE_PEND; |
| 1162 | |
| 1163 | if (sess->deleted == QLA_SESS_DELETED) |
| 1164 | sess->logout_on_delete = 0; |
| 1165 | |
| 1166 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
| 1167 | qla24xx_chk_fcp_state(sess); |
| 1168 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1169 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, |
| 1170 | "Scheduling sess %p for deletion\n", sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1171 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1172 | schedule_work(&sess->del_work); |
| 1173 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1174 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1175 | void qlt_schedule_sess_for_deletion_lock(struct fc_port *sess) |
| 1176 | { |
| 1177 | unsigned long flags; |
| 1178 | struct qla_hw_data *ha = sess->vha->hw; |
| 1179 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1180 | qlt_schedule_sess_for_deletion(sess, 1); |
| 1181 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1182 | } |
| 1183 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1184 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1185 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1186 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1187 | struct fc_port *sess; |
| 1188 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1189 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1190 | list_for_each_entry(sess, &vha->vp_fcports, list) { |
| 1191 | if (sess->se_sess) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1192 | qlt_schedule_sess_for_deletion(sess, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1193 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1194 | |
| 1195 | /* At this point tgt could be already dead */ |
| 1196 | } |
| 1197 | |
| 1198 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id, |
| 1199 | uint16_t *loop_id) |
| 1200 | { |
| 1201 | struct qla_hw_data *ha = vha->hw; |
| 1202 | dma_addr_t gid_list_dma; |
| 1203 | struct gid_list_info *gid_list; |
| 1204 | char *id_iter; |
| 1205 | int res, rc, i; |
| 1206 | uint16_t entries; |
| 1207 | |
| 1208 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1209 | &gid_list_dma, GFP_KERNEL); |
| 1210 | if (!gid_list) { |
| 1211 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, |
| 1212 | "qla_target(%d): DMA Alloc failed of %u\n", |
| 1213 | vha->vp_idx, qla2x00_gid_list_size(ha)); |
| 1214 | return -ENOMEM; |
| 1215 | } |
| 1216 | |
| 1217 | /* Get list of logged in devices */ |
| 1218 | rc = qla2x00_get_id_list(vha, gid_list, gid_list_dma, &entries); |
| 1219 | if (rc != QLA_SUCCESS) { |
| 1220 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, |
| 1221 | "qla_target(%d): get_id_list() failed: %x\n", |
| 1222 | vha->vp_idx, rc); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1223 | res = -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1224 | goto out_free_id_list; |
| 1225 | } |
| 1226 | |
| 1227 | id_iter = (char *)gid_list; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1228 | res = -ENOENT; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1229 | for (i = 0; i < entries; i++) { |
| 1230 | struct gid_list_info *gid = (struct gid_list_info *)id_iter; |
| 1231 | if ((gid->al_pa == s_id[2]) && |
| 1232 | (gid->area == s_id[1]) && |
| 1233 | (gid->domain == s_id[0])) { |
| 1234 | *loop_id = le16_to_cpu(gid->loop_id); |
| 1235 | res = 0; |
| 1236 | break; |
| 1237 | } |
| 1238 | id_iter += ha->gid_list_info_size; |
| 1239 | } |
| 1240 | |
| 1241 | out_free_id_list: |
| 1242 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1243 | gid_list, gid_list_dma); |
| 1244 | return res; |
| 1245 | } |
| 1246 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1247 | /* |
| 1248 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. |
| 1249 | * Caller must put it. |
| 1250 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1251 | static struct fc_port *qlt_create_sess( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1252 | struct scsi_qla_host *vha, |
| 1253 | fc_port_t *fcport, |
| 1254 | bool local) |
| 1255 | { |
| 1256 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1257 | struct fc_port *sess = fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1258 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1259 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1260 | if (vha->vha_tgt.qla_tgt->tgt_stop) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1261 | return NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1262 | |
| 1263 | if (fcport->se_sess) { |
| 1264 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 1265 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1266 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1267 | __func__, sess->port_name); |
| 1268 | return NULL; |
| 1269 | } |
| 1270 | return fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1271 | } |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1272 | sess->tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1273 | sess->local = local; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1274 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1275 | /* |
| 1276 | * Under normal circumstances we want to logout from firmware when |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1277 | * session eventually ends and release corresponding nport handle. |
| 1278 | * In the exception cases (e.g. when new PLOGI is waiting) corresponding |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1279 | * code will adjust these flags as necessary. |
| 1280 | */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1281 | sess->logout_on_delete = 1; |
| 1282 | sess->keep_nport_handle = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1283 | sess->logout_completed = 0; |
| 1284 | |
| 1285 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 1286 | &fcport->port_name[0], sess) < 0) { |
| 1287 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xffff, |
| 1288 | "(%d) %8phC check_initiator_node_acl failed\n", |
| 1289 | vha->vp_idx, fcport->port_name); |
| 1290 | return NULL; |
| 1291 | } else { |
| 1292 | kref_init(&fcport->sess_kref); |
| 1293 | /* |
| 1294 | * Take an extra reference to ->sess_kref here to handle |
| 1295 | * fc_port access across ->tgt.sess_lock reaquire. |
| 1296 | */ |
| 1297 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 1298 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1299 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1300 | __func__, sess->port_name); |
| 1301 | return NULL; |
| 1302 | } |
| 1303 | |
| 1304 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1305 | if (!IS_SW_RESV_ADDR(sess->d_id)) |
| 1306 | vha->vha_tgt.qla_tgt->sess_count++; |
| 1307 | |
| 1308 | qlt_do_generation_tick(vha, &sess->generation); |
| 1309 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1310 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1311 | |
| 1312 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1313 | "Adding sess %p se_sess %p to tgt %p sess_count %d\n", |
| 1314 | sess, sess->se_sess, vha->vha_tgt.qla_tgt, |
| 1315 | vha->vha_tgt.qla_tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1316 | |
| 1317 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1318 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
| 1319 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", |
| 1320 | vha->vp_idx, local ? "local " : "", fcport->port_name, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 1321 | fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area, |
| 1322 | sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1323 | |
| 1324 | return sess; |
| 1325 | } |
| 1326 | |
| 1327 | /* |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1328 | * max_gen - specifies maximum session generation |
| 1329 | * at which this deletion requestion is still valid |
| 1330 | */ |
| 1331 | void |
| 1332 | 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] | 1333 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1334 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1335 | struct fc_port *sess = fcport; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1336 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1337 | |
| 1338 | if (!vha->hw->tgt.tgt_ops) |
| 1339 | return; |
| 1340 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1341 | if (!tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1342 | return; |
| 1343 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1344 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1345 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1346 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1347 | return; |
| 1348 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1349 | if (!sess->se_sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1350 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1351 | return; |
| 1352 | } |
| 1353 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1354 | if (max_gen - sess->generation < 0) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1355 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1356 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092, |
| 1357 | "Ignoring stale deletion request for se_sess %p / sess %p" |
| 1358 | " for port %8phC, req_gen %d, sess_gen %d\n", |
| 1359 | sess->se_sess, sess, sess->port_name, max_gen, |
| 1360 | sess->generation); |
| 1361 | return; |
| 1362 | } |
| 1363 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1364 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); |
| 1365 | |
| 1366 | sess->local = 1; |
| 1367 | qlt_schedule_sess_for_deletion(sess, false); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1368 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) |
| 1372 | { |
| 1373 | struct qla_hw_data *ha = tgt->ha; |
| 1374 | unsigned long flags; |
| 1375 | int res; |
| 1376 | /* |
| 1377 | * We need to protect against race, when tgt is freed before or |
| 1378 | * inside wake_up() |
| 1379 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1380 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1381 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1382 | "tgt %p, sess_count=%d\n", |
| 1383 | tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1384 | res = (tgt->sess_count == 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1385 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1386 | |
| 1387 | return res; |
| 1388 | } |
| 1389 | |
| 1390 | /* Called by tcm_qla2xxx configfs code */ |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1391 | int qlt_stop_phase1(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1392 | { |
| 1393 | struct scsi_qla_host *vha = tgt->vha; |
| 1394 | struct qla_hw_data *ha = tgt->ha; |
| 1395 | unsigned long flags; |
| 1396 | |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1397 | mutex_lock(&qla_tgt_mutex); |
| 1398 | if (!vha->fc_vport) { |
| 1399 | struct Scsi_Host *sh = vha->host; |
| 1400 | struct fc_host_attrs *fc_host = shost_to_fc_host(sh); |
| 1401 | bool npiv_vports; |
| 1402 | |
| 1403 | spin_lock_irqsave(sh->host_lock, flags); |
| 1404 | npiv_vports = (fc_host->npiv_vports_inuse); |
| 1405 | spin_unlock_irqrestore(sh->host_lock, flags); |
| 1406 | |
| 1407 | if (npiv_vports) { |
| 1408 | mutex_unlock(&qla_tgt_mutex); |
| 1409 | return -EPERM; |
| 1410 | } |
| 1411 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1412 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
| 1413 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, |
| 1414 | "Already in tgt->tgt_stop or tgt_stopped state\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1415 | mutex_unlock(&qla_tgt_mutex); |
| 1416 | return -EPERM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | ql_dbg(ql_dbg_tgt, vha, 0xe003, "Stopping target for host %ld(%p)\n", |
| 1420 | vha->host_no, vha); |
| 1421 | /* |
| 1422 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. |
| 1423 | * Lock is needed, because we still can get an incoming packet. |
| 1424 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1425 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1426 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1427 | tgt->tgt_stop = 1; |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1428 | qlt_clear_tgt_db(tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1429 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1430 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1431 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1432 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1433 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, |
| 1434 | "Waiting for sess works (tgt %p)", tgt); |
| 1435 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1436 | while (!list_empty(&tgt->sess_works_list)) { |
| 1437 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1438 | flush_scheduled_work(); |
| 1439 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1440 | } |
| 1441 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1442 | |
| 1443 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1444 | "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1445 | |
| 1446 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); |
| 1447 | |
| 1448 | /* Big hammer */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1449 | if (!ha->flags.host_shutting_down && |
| 1450 | (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1451 | qlt_disable_vha(vha); |
| 1452 | |
| 1453 | /* Wait for sessions to clear out (just in case) */ |
| 1454 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1455 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1456 | } |
| 1457 | EXPORT_SYMBOL(qlt_stop_phase1); |
| 1458 | |
| 1459 | /* Called by tcm_qla2xxx configfs code */ |
| 1460 | void qlt_stop_phase2(struct qla_tgt *tgt) |
| 1461 | { |
| 1462 | struct qla_hw_data *ha = tgt->ha; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1463 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1464 | unsigned long flags; |
| 1465 | |
| 1466 | if (tgt->tgt_stopped) { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1467 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1468 | "Already in tgt->tgt_stopped state\n"); |
| 1469 | dump_stack(); |
| 1470 | return; |
| 1471 | } |
| 1472 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1473 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1474 | "Waiting for %d IRQ commands to complete (tgt %p)", |
| 1475 | tgt->irq_cmd_count, tgt); |
| 1476 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1477 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1478 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 1479 | while ((tgt->irq_cmd_count != 0) || (tgt->atio_irq_cmd_count != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1480 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1481 | udelay(2); |
| 1482 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1483 | } |
| 1484 | tgt->tgt_stop = 0; |
| 1485 | tgt->tgt_stopped = 1; |
| 1486 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1487 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1488 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1489 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00c, "Stop of tgt %p finished", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1490 | tgt); |
| 1491 | } |
| 1492 | EXPORT_SYMBOL(qlt_stop_phase2); |
| 1493 | |
| 1494 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1495 | static void qlt_release(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1496 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1497 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1498 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1499 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1500 | qlt_stop_phase2(tgt); |
| 1501 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1502 | vha->vha_tgt.qla_tgt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1503 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1504 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1505 | "Release of tgt %p finished\n", tgt); |
| 1506 | |
| 1507 | kfree(tgt); |
| 1508 | } |
| 1509 | |
| 1510 | /* ha->hardware_lock supposed to be held on entry */ |
| 1511 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, |
| 1512 | const void *param, unsigned int param_size) |
| 1513 | { |
| 1514 | struct qla_tgt_sess_work_param *prm; |
| 1515 | unsigned long flags; |
| 1516 | |
| 1517 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); |
| 1518 | if (!prm) { |
| 1519 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, |
| 1520 | "qla_target(%d): Unable to create session " |
| 1521 | "work, command will be refused", 0); |
| 1522 | return -ENOMEM; |
| 1523 | } |
| 1524 | |
| 1525 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, |
| 1526 | "Scheduling work (type %d, prm %p)" |
| 1527 | " to find session for param %p (size %d, tgt %p)\n", |
| 1528 | type, prm, param, param_size, tgt); |
| 1529 | |
| 1530 | prm->type = type; |
| 1531 | memcpy(&prm->tm_iocb, param, param_size); |
| 1532 | |
| 1533 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1534 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); |
| 1535 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1536 | |
| 1537 | schedule_work(&tgt->sess_work); |
| 1538 | |
| 1539 | return 0; |
| 1540 | } |
| 1541 | |
| 1542 | /* |
| 1543 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1544 | */ |
| 1545 | static void qlt_send_notify_ack(struct scsi_qla_host *vha, |
| 1546 | struct imm_ntfy_from_isp *ntfy, |
| 1547 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 1548 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) |
| 1549 | { |
| 1550 | struct qla_hw_data *ha = vha->hw; |
| 1551 | request_t *pkt; |
| 1552 | struct nack_to_isp *nack; |
| 1553 | |
| 1554 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); |
| 1555 | |
| 1556 | /* Send marker if required */ |
| 1557 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1558 | return; |
| 1559 | |
| 1560 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
| 1561 | if (!pkt) { |
| 1562 | ql_dbg(ql_dbg_tgt, vha, 0xe049, |
| 1563 | "qla_target(%d): %s failed: unable to allocate " |
| 1564 | "request packet\n", vha->vp_idx, __func__); |
| 1565 | return; |
| 1566 | } |
| 1567 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1568 | if (vha->vha_tgt.qla_tgt != NULL) |
| 1569 | vha->vha_tgt.qla_tgt->notify_ack_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1570 | |
| 1571 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 1572 | pkt->entry_count = 1; |
| 1573 | |
| 1574 | nack = (struct nack_to_isp *)pkt; |
| 1575 | nack->ox_id = ntfy->ox_id; |
| 1576 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1577 | nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1578 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 1579 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 1580 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1581 | cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1582 | } |
| 1583 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 1584 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 1585 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1586 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1587 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 1588 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 1589 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 1590 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); |
| 1591 | nack->u.isp24.srr_reject_code = srr_reject_code; |
| 1592 | nack->u.isp24.srr_reject_code_expl = srr_explan; |
| 1593 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 1594 | |
| 1595 | ql_dbg(ql_dbg_tgt, vha, 0xe005, |
| 1596 | "qla_target(%d): Sending 24xx Notify Ack %d\n", |
| 1597 | vha->vp_idx, nack->u.isp24.status); |
| 1598 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1599 | /* Memory Barrier */ |
| 1600 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1601 | qla2x00_start_iocbs(vha, vha->req); |
| 1602 | } |
| 1603 | |
| 1604 | /* |
| 1605 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1606 | */ |
| 1607 | static void qlt_24xx_send_abts_resp(struct scsi_qla_host *vha, |
| 1608 | struct abts_recv_from_24xx *abts, uint32_t status, |
| 1609 | bool ids_reversed) |
| 1610 | { |
| 1611 | struct qla_hw_data *ha = vha->hw; |
| 1612 | struct abts_resp_to_24xx *resp; |
| 1613 | uint32_t f_ctl; |
| 1614 | uint8_t *p; |
| 1615 | |
| 1616 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1617 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", |
| 1618 | ha, abts, status); |
| 1619 | |
| 1620 | /* Send marker if required */ |
| 1621 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1622 | return; |
| 1623 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1624 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1625 | if (!resp) { |
| 1626 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1627 | "qla_target(%d): %s failed: unable to allocate " |
| 1628 | "request packet", vha->vp_idx, __func__); |
| 1629 | return; |
| 1630 | } |
| 1631 | |
| 1632 | resp->entry_type = ABTS_RESP_24XX; |
| 1633 | resp->entry_count = 1; |
| 1634 | resp->nport_handle = abts->nport_handle; |
| 1635 | resp->vp_index = vha->vp_idx; |
| 1636 | resp->sof_type = abts->sof_type; |
| 1637 | resp->exchange_address = abts->exchange_address; |
| 1638 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1639 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1640 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1641 | F_CTL_SEQ_INITIATIVE); |
| 1642 | p = (uint8_t *)&f_ctl; |
| 1643 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1644 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1645 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1646 | if (ids_reversed) { |
| 1647 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1648 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1649 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1650 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1651 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1652 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1653 | } else { |
| 1654 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1655 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1656 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1657 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1658 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1659 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1660 | } |
| 1661 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1662 | if (status == FCP_TMF_CMPL) { |
| 1663 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1664 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1665 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1666 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1667 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1668 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1669 | } else { |
| 1670 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1671 | resp->payload.ba_rjt.reason_code = |
| 1672 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1673 | /* Other bytes are zero */ |
| 1674 | } |
| 1675 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1676 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1677 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1678 | /* Memory Barrier */ |
| 1679 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1680 | qla2x00_start_iocbs(vha, vha->req); |
| 1681 | } |
| 1682 | |
| 1683 | /* |
| 1684 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1685 | */ |
| 1686 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, |
| 1687 | struct abts_resp_from_24xx_fw *entry) |
| 1688 | { |
| 1689 | struct ctio7_to_24xx *ctio; |
| 1690 | |
| 1691 | ql_dbg(ql_dbg_tgt, vha, 0xe007, |
| 1692 | "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha->hw); |
| 1693 | /* Send marker if required */ |
| 1694 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1695 | return; |
| 1696 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1697 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1698 | if (ctio == NULL) { |
| 1699 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, |
| 1700 | "qla_target(%d): %s failed: unable to allocate " |
| 1701 | "request packet\n", vha->vp_idx, __func__); |
| 1702 | return; |
| 1703 | } |
| 1704 | |
| 1705 | /* |
| 1706 | * We've got on entrance firmware's response on by us generated |
| 1707 | * ABTS response. So, in it ID fields are reversed. |
| 1708 | */ |
| 1709 | |
| 1710 | ctio->entry_type = CTIO_TYPE7; |
| 1711 | ctio->entry_count = 1; |
| 1712 | ctio->nport_handle = entry->nport_handle; |
| 1713 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1714 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1715 | ctio->vp_index = vha->vp_idx; |
| 1716 | ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0]; |
| 1717 | ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1]; |
| 1718 | ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2]; |
| 1719 | ctio->exchange_addr = entry->exchange_addr_to_abort; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1720 | ctio->u.status1.flags = cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | |
| 1721 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1722 | 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] | 1723 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1724 | /* Memory Barrier */ |
| 1725 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1726 | qla2x00_start_iocbs(vha, vha->req); |
| 1727 | |
| 1728 | qlt_24xx_send_abts_resp(vha, (struct abts_recv_from_24xx *)entry, |
| 1729 | FCP_TMF_CMPL, true); |
| 1730 | } |
| 1731 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1732 | static int abort_cmd_for_tag(struct scsi_qla_host *vha, uint32_t tag) |
| 1733 | { |
| 1734 | struct qla_tgt_sess_op *op; |
| 1735 | struct qla_tgt_cmd *cmd; |
| 1736 | |
| 1737 | spin_lock(&vha->cmd_list_lock); |
| 1738 | |
| 1739 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1740 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1741 | op->aborted = true; |
| 1742 | spin_unlock(&vha->cmd_list_lock); |
| 1743 | return 1; |
| 1744 | } |
| 1745 | } |
| 1746 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1747 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1748 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1749 | op->aborted = true; |
| 1750 | spin_unlock(&vha->cmd_list_lock); |
| 1751 | return 1; |
| 1752 | } |
| 1753 | } |
| 1754 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1755 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1756 | if (tag == cmd->atio.u.isp24.exchange_addr) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1757 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1758 | spin_unlock(&vha->cmd_list_lock); |
| 1759 | return 1; |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | spin_unlock(&vha->cmd_list_lock); |
| 1764 | return 0; |
| 1765 | } |
| 1766 | |
| 1767 | /* drop cmds for the given lun |
| 1768 | * XXX only looks for cmds on the port through which lun reset was recieved |
| 1769 | * XXX does not go through the list of other port (which may have cmds |
| 1770 | * for the same lun) |
| 1771 | */ |
| 1772 | static void abort_cmds_for_lun(struct scsi_qla_host *vha, |
| 1773 | uint32_t lun, uint8_t *s_id) |
| 1774 | { |
| 1775 | struct qla_tgt_sess_op *op; |
| 1776 | struct qla_tgt_cmd *cmd; |
| 1777 | uint32_t key; |
| 1778 | |
| 1779 | key = sid_to_key(s_id); |
| 1780 | spin_lock(&vha->cmd_list_lock); |
| 1781 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1782 | uint32_t op_key; |
| 1783 | uint32_t op_lun; |
| 1784 | |
| 1785 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1786 | op_lun = scsilun_to_int( |
| 1787 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1788 | if (op_key == key && op_lun == lun) |
| 1789 | op->aborted = true; |
| 1790 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1791 | |
| 1792 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1793 | uint32_t op_key; |
| 1794 | u64 op_lun; |
| 1795 | |
| 1796 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1797 | op_lun = scsilun_to_int( |
| 1798 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1799 | if (op_key == key && op_lun == lun) |
| 1800 | op->aborted = true; |
| 1801 | } |
| 1802 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1803 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1804 | uint32_t cmd_key; |
| 1805 | uint32_t cmd_lun; |
| 1806 | |
| 1807 | cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 1808 | cmd_lun = scsilun_to_int( |
| 1809 | (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); |
| 1810 | if (cmd_key == key && cmd_lun == lun) |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1811 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1812 | } |
| 1813 | spin_unlock(&vha->cmd_list_lock); |
| 1814 | } |
| 1815 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1816 | /* ha->hardware_lock supposed to be held on entry */ |
| 1817 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1818 | struct abts_recv_from_24xx *abts, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1819 | { |
| 1820 | struct qla_hw_data *ha = vha->hw; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1821 | struct se_session *se_sess = sess->se_sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1822 | struct qla_tgt_mgmt_cmd *mcmd; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1823 | struct se_cmd *se_cmd; |
| 1824 | u32 lun = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1825 | int rc; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1826 | bool found_lun = false; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1827 | unsigned long flags; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1828 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1829 | spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1830 | list_for_each_entry(se_cmd, &se_sess->sess_cmd_list, se_cmd_list) { |
| 1831 | struct qla_tgt_cmd *cmd = |
| 1832 | container_of(se_cmd, struct qla_tgt_cmd, se_cmd); |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 1833 | if (se_cmd->tag == abts->exchange_addr_to_abort) { |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1834 | lun = cmd->unpacked_lun; |
| 1835 | found_lun = true; |
| 1836 | break; |
| 1837 | } |
| 1838 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1839 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1840 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1841 | /* cmd not in LIO lists, look in qla list */ |
| 1842 | if (!found_lun) { |
| 1843 | if (abort_cmd_for_tag(vha, abts->exchange_addr_to_abort)) { |
| 1844 | /* send TASK_ABORT response immediately */ |
| 1845 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_CMPL, false); |
| 1846 | return 0; |
| 1847 | } else { |
| 1848 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf081, |
| 1849 | "unable to find cmd in driver or LIO for tag 0x%x\n", |
| 1850 | abts->exchange_addr_to_abort); |
| 1851 | return -ENOENT; |
| 1852 | } |
| 1853 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1854 | |
| 1855 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, |
| 1856 | "qla_target(%d): task abort (tag=%d)\n", |
| 1857 | vha->vp_idx, abts->exchange_addr_to_abort); |
| 1858 | |
| 1859 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 1860 | if (mcmd == NULL) { |
| 1861 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, |
| 1862 | "qla_target(%d): %s: Allocation of ABORT cmd failed", |
| 1863 | vha->vp_idx, __func__); |
| 1864 | return -ENOMEM; |
| 1865 | } |
| 1866 | memset(mcmd, 0, sizeof(*mcmd)); |
| 1867 | |
| 1868 | mcmd->sess = sess; |
| 1869 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); |
Arun Easi | 80187f8 | 2014-09-25 06:14:53 -0400 | [diff] [blame] | 1870 | mcmd->reset_count = vha->hw->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 1871 | mcmd->tmr_func = QLA_TGT_ABTS; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1872 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 1873 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, lun, mcmd->tmr_func, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1874 | abts->exchange_addr_to_abort); |
| 1875 | if (rc != 0) { |
| 1876 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf052, |
| 1877 | "qla_target(%d): tgt_ops->handle_tmr()" |
| 1878 | " failed: %d", vha->vp_idx, rc); |
| 1879 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 1880 | return -EFAULT; |
| 1881 | } |
| 1882 | |
| 1883 | return 0; |
| 1884 | } |
| 1885 | |
| 1886 | /* |
| 1887 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1888 | */ |
| 1889 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 1890 | struct abts_recv_from_24xx *abts) |
| 1891 | { |
| 1892 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1893 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1894 | uint32_t tag = abts->exchange_addr_to_abort; |
| 1895 | uint8_t s_id[3]; |
| 1896 | int rc; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1897 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1898 | |
| 1899 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { |
| 1900 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, |
| 1901 | "qla_target(%d): ABTS: Abort Sequence not " |
| 1902 | "supported\n", vha->vp_idx); |
| 1903 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1904 | return; |
| 1905 | } |
| 1906 | |
| 1907 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { |
| 1908 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, |
| 1909 | "qla_target(%d): ABTS: Unknown Exchange " |
| 1910 | "Address received\n", vha->vp_idx); |
| 1911 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1912 | return; |
| 1913 | } |
| 1914 | |
| 1915 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, |
| 1916 | "qla_target(%d): task abort (s_id=%x:%x:%x, " |
| 1917 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2], |
| 1918 | abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag, |
| 1919 | le32_to_cpu(abts->fcp_hdr_le.parameter)); |
| 1920 | |
| 1921 | s_id[0] = abts->fcp_hdr_le.s_id[2]; |
| 1922 | s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1923 | s_id[2] = abts->fcp_hdr_le.s_id[0]; |
| 1924 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1925 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1926 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 1927 | if (!sess) { |
| 1928 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, |
| 1929 | "qla_target(%d): task abort for non-existant session\n", |
| 1930 | vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1931 | rc = qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1932 | QLA_TGT_SESS_WORK_ABORT, abts, sizeof(*abts)); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1933 | |
| 1934 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1935 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1936 | if (rc != 0) { |
| 1937 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, |
| 1938 | false); |
| 1939 | } |
| 1940 | return; |
| 1941 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1942 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1943 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1944 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1945 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 1946 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1947 | return; |
| 1948 | } |
| 1949 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1950 | rc = __qlt_24xx_handle_abts(vha, abts, sess); |
| 1951 | if (rc != 0) { |
| 1952 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, |
| 1953 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", |
| 1954 | vha->vp_idx, rc); |
| 1955 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1956 | return; |
| 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | /* |
| 1961 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1962 | */ |
| 1963 | static void qlt_24xx_send_task_mgmt_ctio(struct scsi_qla_host *ha, |
| 1964 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) |
| 1965 | { |
| 1966 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; |
| 1967 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1968 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1969 | |
| 1970 | ql_dbg(ql_dbg_tgt, ha, 0xe008, |
| 1971 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", |
| 1972 | ha, atio, resp_code); |
| 1973 | |
| 1974 | /* Send marker if required */ |
| 1975 | if (qlt_issue_marker(ha, 1) != QLA_SUCCESS) |
| 1976 | return; |
| 1977 | |
| 1978 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(ha, NULL); |
| 1979 | if (ctio == NULL) { |
| 1980 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, |
| 1981 | "qla_target(%d): %s failed: unable to allocate " |
| 1982 | "request packet\n", ha->vp_idx, __func__); |
| 1983 | return; |
| 1984 | } |
| 1985 | |
| 1986 | ctio->entry_type = CTIO_TYPE7; |
| 1987 | ctio->entry_count = 1; |
| 1988 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 1989 | ctio->nport_handle = mcmd->sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1990 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1991 | ctio->vp_index = ha->vp_idx; |
| 1992 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 1993 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 1994 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 1995 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
| 1996 | ctio->u.status1.flags = (atio->u.isp24.attr << 9) | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1997 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1998 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 1999 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2000 | ctio->u.status1.scsi_status = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2001 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); |
| 2002 | ctio->u.status1.response_len = cpu_to_le16(8); |
Roland Dreier | e4b11b8 | 2012-09-18 15:10:56 -0700 | [diff] [blame] | 2003 | ctio->u.status1.sense_data[0] = resp_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2004 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2005 | /* Memory Barrier */ |
| 2006 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2007 | qla2x00_start_iocbs(ha, ha->req); |
| 2008 | } |
| 2009 | |
| 2010 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) |
| 2011 | { |
| 2012 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2013 | } |
| 2014 | EXPORT_SYMBOL(qlt_free_mcmd); |
| 2015 | |
| 2016 | /* callback from target fabric module code */ |
| 2017 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) |
| 2018 | { |
| 2019 | struct scsi_qla_host *vha = mcmd->sess->vha; |
| 2020 | struct qla_hw_data *ha = vha->hw; |
| 2021 | unsigned long flags; |
| 2022 | |
| 2023 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, |
| 2024 | "TM response mcmd (%p) status %#x state %#x", |
| 2025 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); |
| 2026 | |
| 2027 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2028 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2029 | if (!vha->flags.online || mcmd->reset_count != ha->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2030 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2031 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2032 | * previous life, just abort the processing. |
| 2033 | */ |
| 2034 | ql_dbg(ql_dbg_async, vha, 0xe100, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2035 | "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2036 | vha->flags.online, qla2x00_reset_active(vha), |
| 2037 | mcmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2038 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 2039 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2040 | return; |
| 2041 | } |
| 2042 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2043 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) { |
| 2044 | if (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 2045 | ELS_LOGO || |
| 2046 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2047 | ELS_PRLO || |
| 2048 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2049 | ELS_TPRLO) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2050 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 2051 | "TM response logo %phC status %#x state %#x", |
| 2052 | mcmd->sess->port_name, mcmd->fc_tm_rsp, |
| 2053 | mcmd->flags); |
| 2054 | qlt_schedule_sess_for_deletion_lock(mcmd->sess); |
| 2055 | } else { |
| 2056 | qlt_send_notify_ack(vha, &mcmd->orig_iocb.imm_ntfy, |
| 2057 | 0, 0, 0, 0, 0, 0); |
| 2058 | } |
| 2059 | } else { |
Swapnil Nagle | d7236ac | 2016-02-04 11:45:17 -0500 | [diff] [blame] | 2060 | if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2061 | qlt_24xx_send_abts_resp(vha, &mcmd->orig_iocb.abts, |
| 2062 | mcmd->fc_tm_rsp, false); |
| 2063 | else |
| 2064 | qlt_24xx_send_task_mgmt_ctio(vha, mcmd, |
| 2065 | mcmd->fc_tm_rsp); |
| 2066 | } |
| 2067 | /* |
| 2068 | * Make the callback for ->free_mcmd() to queue_work() and invoke |
| 2069 | * target_put_sess_cmd() to drop cmd_kref to 1. The final |
| 2070 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() |
| 2071 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd |
| 2072 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> |
| 2073 | * qlt_xmit_tm_rsp() returns here.. |
| 2074 | */ |
| 2075 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 2076 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2077 | } |
| 2078 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); |
| 2079 | |
| 2080 | /* No locks */ |
| 2081 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) |
| 2082 | { |
| 2083 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2084 | |
| 2085 | BUG_ON(cmd->sg_cnt == 0); |
| 2086 | |
| 2087 | prm->sg = (struct scatterlist *)cmd->sg; |
| 2088 | prm->seg_cnt = pci_map_sg(prm->tgt->ha->pdev, cmd->sg, |
| 2089 | cmd->sg_cnt, cmd->dma_data_direction); |
| 2090 | if (unlikely(prm->seg_cnt == 0)) |
| 2091 | goto out_err; |
| 2092 | |
| 2093 | prm->cmd->sg_mapped = 1; |
| 2094 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2095 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
| 2096 | /* |
| 2097 | * If greater than four sg entries then we need to allocate |
| 2098 | * the continuation entries |
| 2099 | */ |
| 2100 | if (prm->seg_cnt > prm->tgt->datasegs_per_cmd) |
| 2101 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - |
| 2102 | prm->tgt->datasegs_per_cmd, |
| 2103 | prm->tgt->datasegs_per_cont); |
| 2104 | } else { |
| 2105 | /* DIF */ |
| 2106 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2107 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2108 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); |
| 2109 | prm->tot_dsds = prm->seg_cnt; |
| 2110 | } else |
| 2111 | prm->tot_dsds = prm->seg_cnt; |
| 2112 | |
| 2113 | if (cmd->prot_sg_cnt) { |
| 2114 | prm->prot_sg = cmd->prot_sg; |
| 2115 | prm->prot_seg_cnt = pci_map_sg(prm->tgt->ha->pdev, |
| 2116 | cmd->prot_sg, cmd->prot_sg_cnt, |
| 2117 | cmd->dma_data_direction); |
| 2118 | if (unlikely(prm->prot_seg_cnt == 0)) |
| 2119 | goto out_err; |
| 2120 | |
| 2121 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2122 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2123 | /* Dif Bundling not support here */ |
| 2124 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, |
| 2125 | cmd->blk_sz); |
| 2126 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2127 | } else |
| 2128 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2129 | } |
| 2130 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2131 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2132 | return 0; |
| 2133 | |
| 2134 | out_err: |
| 2135 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe04d, |
| 2136 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", |
| 2137 | 0, prm->cmd->sg_cnt); |
| 2138 | return -1; |
| 2139 | } |
| 2140 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2141 | 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] | 2142 | { |
| 2143 | struct qla_hw_data *ha = vha->hw; |
| 2144 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2145 | if (!cmd->sg_mapped) |
| 2146 | return; |
| 2147 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2148 | pci_unmap_sg(ha->pdev, cmd->sg, cmd->sg_cnt, cmd->dma_data_direction); |
| 2149 | cmd->sg_mapped = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2150 | |
| 2151 | if (cmd->prot_sg_cnt) |
| 2152 | pci_unmap_sg(ha->pdev, cmd->prot_sg, cmd->prot_sg_cnt, |
| 2153 | cmd->dma_data_direction); |
| 2154 | |
| 2155 | if (cmd->ctx_dsd_alloced) |
| 2156 | qla2x00_clean_dsd_pool(ha, NULL, cmd); |
| 2157 | |
| 2158 | if (cmd->ctx) |
| 2159 | 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] | 2160 | } |
| 2161 | |
| 2162 | static int qlt_check_reserve_free_req(struct scsi_qla_host *vha, |
| 2163 | uint32_t req_cnt) |
| 2164 | { |
Saurav Kashyap | d29fb73 | 2014-09-25 06:14:49 -0400 | [diff] [blame] | 2165 | uint32_t cnt, cnt_in; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2166 | |
| 2167 | if (vha->req->cnt < (req_cnt + 2)) { |
Arun Easi | 75554b6 | 2014-09-25 06:14:45 -0400 | [diff] [blame] | 2168 | cnt = (uint16_t)RD_REG_DWORD(vha->req->req_q_out); |
Saurav Kashyap | d29fb73 | 2014-09-25 06:14:49 -0400 | [diff] [blame] | 2169 | cnt_in = (uint16_t)RD_REG_DWORD(vha->req->req_q_in); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2170 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2171 | if (vha->req->ring_index < cnt) |
| 2172 | vha->req->cnt = cnt - vha->req->ring_index; |
| 2173 | else |
| 2174 | vha->req->cnt = vha->req->length - |
| 2175 | (vha->req->ring_index - cnt); |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2176 | |
| 2177 | if (unlikely(vha->req->cnt < (req_cnt + 2))) { |
| 2178 | ql_dbg(ql_dbg_io, vha, 0x305a, |
| 2179 | "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", |
| 2180 | vha->vp_idx, vha->req->ring_index, |
| 2181 | vha->req->cnt, req_cnt, cnt, cnt_in, |
| 2182 | vha->req->length); |
| 2183 | return -EAGAIN; |
| 2184 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2185 | } |
| 2186 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2187 | vha->req->cnt -= req_cnt; |
| 2188 | |
| 2189 | return 0; |
| 2190 | } |
| 2191 | |
| 2192 | /* |
| 2193 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2194 | */ |
| 2195 | static inline void *qlt_get_req_pkt(struct scsi_qla_host *vha) |
| 2196 | { |
| 2197 | /* Adjust ring index. */ |
| 2198 | vha->req->ring_index++; |
| 2199 | if (vha->req->ring_index == vha->req->length) { |
| 2200 | vha->req->ring_index = 0; |
| 2201 | vha->req->ring_ptr = vha->req->ring; |
| 2202 | } else { |
| 2203 | vha->req->ring_ptr++; |
| 2204 | } |
| 2205 | return (cont_entry_t *)vha->req->ring_ptr; |
| 2206 | } |
| 2207 | |
| 2208 | /* ha->hardware_lock supposed to be held on entry */ |
| 2209 | static inline uint32_t qlt_make_handle(struct scsi_qla_host *vha) |
| 2210 | { |
| 2211 | struct qla_hw_data *ha = vha->hw; |
| 2212 | uint32_t h; |
| 2213 | |
| 2214 | h = ha->tgt.current_handle; |
| 2215 | /* always increment cmd handle */ |
| 2216 | do { |
| 2217 | ++h; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2218 | if (h > DEFAULT_OUTSTANDING_COMMANDS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2219 | h = 1; /* 0 is QLA_TGT_NULL_HANDLE */ |
| 2220 | if (h == ha->tgt.current_handle) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2221 | ql_dbg(ql_dbg_io, vha, 0x305b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2222 | "qla_target(%d): Ran out of " |
| 2223 | "empty cmd slots in ha %p\n", vha->vp_idx, ha); |
| 2224 | h = QLA_TGT_NULL_HANDLE; |
| 2225 | break; |
| 2226 | } |
| 2227 | } while ((h == QLA_TGT_NULL_HANDLE) || |
| 2228 | (h == QLA_TGT_SKIP_HANDLE) || |
| 2229 | (ha->tgt.cmds[h-1] != NULL)); |
| 2230 | |
| 2231 | if (h != QLA_TGT_NULL_HANDLE) |
| 2232 | ha->tgt.current_handle = h; |
| 2233 | |
| 2234 | return h; |
| 2235 | } |
| 2236 | |
| 2237 | /* ha->hardware_lock supposed to be held on entry */ |
| 2238 | static int qlt_24xx_build_ctio_pkt(struct qla_tgt_prm *prm, |
| 2239 | struct scsi_qla_host *vha) |
| 2240 | { |
| 2241 | uint32_t h; |
| 2242 | struct ctio7_to_24xx *pkt; |
| 2243 | struct qla_hw_data *ha = vha->hw; |
| 2244 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2245 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2246 | |
| 2247 | pkt = (struct ctio7_to_24xx *)vha->req->ring_ptr; |
| 2248 | prm->pkt = pkt; |
| 2249 | memset(pkt, 0, sizeof(*pkt)); |
| 2250 | |
| 2251 | pkt->entry_type = CTIO_TYPE7; |
| 2252 | pkt->entry_count = (uint8_t)prm->req_cnt; |
| 2253 | pkt->vp_index = vha->vp_idx; |
| 2254 | |
| 2255 | h = qlt_make_handle(vha); |
| 2256 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2257 | /* |
| 2258 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2259 | * know the initiator's LOOP ID, hence we can't find |
| 2260 | * the session and, so, the command. |
| 2261 | */ |
| 2262 | return -EAGAIN; |
| 2263 | } else |
| 2264 | ha->tgt.cmds[h-1] = prm->cmd; |
| 2265 | |
| 2266 | pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK; |
| 2267 | pkt->nport_handle = prm->cmd->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2268 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2269 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2270 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2271 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2272 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
| 2273 | pkt->u.status0.flags |= (atio->u.isp24.attr << 9); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2274 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2275 | pkt->u.status0.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2276 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2277 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2278 | return 0; |
| 2279 | } |
| 2280 | |
| 2281 | /* |
| 2282 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2283 | * that there is sufficient amount of request entries to not drop it. |
| 2284 | */ |
| 2285 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm, |
| 2286 | struct scsi_qla_host *vha) |
| 2287 | { |
| 2288 | int cnt; |
| 2289 | uint32_t *dword_ptr; |
| 2290 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; |
| 2291 | |
| 2292 | /* Build continuation packets */ |
| 2293 | while (prm->seg_cnt > 0) { |
| 2294 | cont_a64_entry_t *cont_pkt64 = |
| 2295 | (cont_a64_entry_t *)qlt_get_req_pkt(vha); |
| 2296 | |
| 2297 | /* |
| 2298 | * Make sure that from cont_pkt64 none of |
| 2299 | * 64-bit specific fields used for 32-bit |
| 2300 | * addressing. Cast to (cont_entry_t *) for |
| 2301 | * that. |
| 2302 | */ |
| 2303 | |
| 2304 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); |
| 2305 | |
| 2306 | cont_pkt64->entry_count = 1; |
| 2307 | cont_pkt64->sys_define = 0; |
| 2308 | |
| 2309 | if (enable_64bit_addressing) { |
| 2310 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; |
| 2311 | dword_ptr = |
| 2312 | (uint32_t *)&cont_pkt64->dseg_0_address; |
| 2313 | } else { |
| 2314 | cont_pkt64->entry_type = CONTINUE_TYPE; |
| 2315 | dword_ptr = |
| 2316 | (uint32_t *)&((cont_entry_t *) |
| 2317 | cont_pkt64)->dseg_0_address; |
| 2318 | } |
| 2319 | |
| 2320 | /* Load continuation entry data segments */ |
| 2321 | for (cnt = 0; |
| 2322 | cnt < prm->tgt->datasegs_per_cont && prm->seg_cnt; |
| 2323 | cnt++, prm->seg_cnt--) { |
| 2324 | *dword_ptr++ = |
| 2325 | cpu_to_le32(pci_dma_lo32 |
| 2326 | (sg_dma_address(prm->sg))); |
| 2327 | if (enable_64bit_addressing) { |
| 2328 | *dword_ptr++ = |
| 2329 | cpu_to_le32(pci_dma_hi32 |
| 2330 | (sg_dma_address |
| 2331 | (prm->sg))); |
| 2332 | } |
| 2333 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2334 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2335 | prm->sg = sg_next(prm->sg); |
| 2336 | } |
| 2337 | } |
| 2338 | } |
| 2339 | |
| 2340 | /* |
| 2341 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2342 | * that there is sufficient amount of request entries to not drop it. |
| 2343 | */ |
| 2344 | static void qlt_load_data_segments(struct qla_tgt_prm *prm, |
| 2345 | struct scsi_qla_host *vha) |
| 2346 | { |
| 2347 | int cnt; |
| 2348 | uint32_t *dword_ptr; |
| 2349 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; |
| 2350 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; |
| 2351 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2352 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
| 2353 | |
| 2354 | /* Setup packet address segment pointer */ |
| 2355 | dword_ptr = pkt24->u.status0.dseg_0_address; |
| 2356 | |
| 2357 | /* Set total data segment count */ |
| 2358 | if (prm->seg_cnt) |
| 2359 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); |
| 2360 | |
| 2361 | if (prm->seg_cnt == 0) { |
| 2362 | /* No data transfer */ |
| 2363 | *dword_ptr++ = 0; |
| 2364 | *dword_ptr = 0; |
| 2365 | return; |
| 2366 | } |
| 2367 | |
| 2368 | /* If scatter gather */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2369 | |
| 2370 | /* Load command entry data segments */ |
| 2371 | for (cnt = 0; |
| 2372 | (cnt < prm->tgt->datasegs_per_cmd) && prm->seg_cnt; |
| 2373 | cnt++, prm->seg_cnt--) { |
| 2374 | *dword_ptr++ = |
| 2375 | cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg))); |
| 2376 | if (enable_64bit_addressing) { |
| 2377 | *dword_ptr++ = |
| 2378 | cpu_to_le32(pci_dma_hi32( |
| 2379 | sg_dma_address(prm->sg))); |
| 2380 | } |
| 2381 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2382 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2383 | prm->sg = sg_next(prm->sg); |
| 2384 | } |
| 2385 | |
| 2386 | qlt_load_cont_data_segments(prm, vha); |
| 2387 | } |
| 2388 | |
| 2389 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) |
| 2390 | { |
| 2391 | return cmd->bufflen > 0; |
| 2392 | } |
| 2393 | |
| 2394 | /* |
| 2395 | * Called without ha->hardware_lock held |
| 2396 | */ |
| 2397 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, |
| 2398 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, |
| 2399 | uint32_t *full_req_cnt) |
| 2400 | { |
| 2401 | struct qla_tgt *tgt = cmd->tgt; |
| 2402 | struct scsi_qla_host *vha = tgt->vha; |
| 2403 | struct qla_hw_data *ha = vha->hw; |
| 2404 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2405 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2406 | prm->cmd = cmd; |
| 2407 | prm->tgt = tgt; |
| 2408 | prm->rq_result = scsi_status; |
| 2409 | prm->sense_buffer = &cmd->sense_buffer[0]; |
| 2410 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; |
| 2411 | prm->sg = NULL; |
| 2412 | prm->seg_cnt = -1; |
| 2413 | prm->req_cnt = 1; |
| 2414 | prm->add_status_pkt = 0; |
| 2415 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2416 | /* Send marker if required */ |
| 2417 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) |
| 2418 | return -EFAULT; |
| 2419 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2420 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
| 2421 | if (qlt_pci_map_calc_cnt(prm) != 0) |
| 2422 | return -EAGAIN; |
| 2423 | } |
| 2424 | |
| 2425 | *full_req_cnt = prm->req_cnt; |
| 2426 | |
| 2427 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { |
| 2428 | prm->residual = se_cmd->residual_count; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2429 | ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x305c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2430 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2431 | prm->residual, se_cmd->tag, |
| 2432 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, |
| 2433 | cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2434 | prm->rq_result |= SS_RESIDUAL_UNDER; |
| 2435 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2436 | prm->residual = se_cmd->residual_count; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2437 | ql_dbg(ql_dbg_io, vha, 0x305d, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2438 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2439 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? |
| 2440 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2441 | prm->rq_result |= SS_RESIDUAL_OVER; |
| 2442 | } |
| 2443 | |
| 2444 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2445 | /* |
| 2446 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be |
| 2447 | * ignored in *xmit_response() below |
| 2448 | */ |
| 2449 | if (qlt_has_data(cmd)) { |
| 2450 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || |
| 2451 | (IS_FWI2_CAPABLE(ha) && |
| 2452 | (prm->rq_result != 0))) { |
| 2453 | prm->add_status_pkt = 1; |
| 2454 | (*full_req_cnt)++; |
| 2455 | } |
| 2456 | } |
| 2457 | } |
| 2458 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2459 | return 0; |
| 2460 | } |
| 2461 | |
| 2462 | static inline int qlt_need_explicit_conf(struct qla_hw_data *ha, |
| 2463 | struct qla_tgt_cmd *cmd, int sending_sense) |
| 2464 | { |
| 2465 | if (ha->tgt.enable_class_2) |
| 2466 | return 0; |
| 2467 | |
| 2468 | if (sending_sense) |
| 2469 | return cmd->conf_compl_supported; |
| 2470 | else |
| 2471 | return ha->tgt.enable_explicit_conf && |
| 2472 | cmd->conf_compl_supported; |
| 2473 | } |
| 2474 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2475 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, |
| 2476 | struct qla_tgt_prm *prm) |
| 2477 | { |
| 2478 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, |
| 2479 | (uint32_t)sizeof(ctio->u.status1.sense_data)); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2480 | ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2481 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 0)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2482 | ctio->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2483 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2484 | CTIO7_FLAGS_CONFORM_REQ); |
| 2485 | } |
| 2486 | ctio->u.status0.residual = cpu_to_le32(prm->residual); |
| 2487 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); |
| 2488 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { |
| 2489 | int i; |
| 2490 | |
| 2491 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 1)) { |
Quinn Tran | df2e32c | 2017-01-19 22:27:53 -0800 | [diff] [blame] | 2492 | if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2493 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe017, |
| 2494 | "Skipping EXPLICIT_CONFORM and " |
| 2495 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " |
| 2496 | "non GOOD status\n"); |
| 2497 | goto skip_explict_conf; |
| 2498 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2499 | ctio->u.status1.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2500 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2501 | CTIO7_FLAGS_CONFORM_REQ); |
| 2502 | } |
| 2503 | skip_explict_conf: |
| 2504 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2505 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2506 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2507 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2508 | ctio->u.status1.scsi_status |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2509 | cpu_to_le16(SS_SENSE_LEN_VALID); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2510 | ctio->u.status1.sense_length = |
| 2511 | cpu_to_le16(prm->sense_buffer_len); |
| 2512 | for (i = 0; i < prm->sense_buffer_len/4; i++) |
| 2513 | ((uint32_t *)ctio->u.status1.sense_data)[i] = |
| 2514 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); |
| 2515 | #if 0 |
| 2516 | if (unlikely((prm->sense_buffer_len % 4) != 0)) { |
| 2517 | static int q; |
| 2518 | if (q < 10) { |
| 2519 | ql_dbg(ql_dbg_tgt, vha, 0xe04f, |
| 2520 | "qla_target(%d): %d bytes of sense " |
| 2521 | "lost", prm->tgt->ha->vp_idx, |
| 2522 | prm->sense_buffer_len % 4); |
| 2523 | q++; |
| 2524 | } |
| 2525 | } |
| 2526 | #endif |
| 2527 | } else { |
| 2528 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2529 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2530 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2531 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2532 | ctio->u.status1.sense_length = 0; |
| 2533 | memset(ctio->u.status1.sense_data, 0, |
| 2534 | sizeof(ctio->u.status1.sense_data)); |
| 2535 | } |
| 2536 | |
| 2537 | /* Sense with len > 24, is it possible ??? */ |
| 2538 | } |
| 2539 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2540 | |
| 2541 | |
| 2542 | /* diff */ |
| 2543 | static inline int |
| 2544 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) |
| 2545 | { |
| 2546 | /* |
| 2547 | * Uncomment when corresponding SCSI changes are done. |
| 2548 | * |
| 2549 | if (!sp->cmd->prot_chk) |
| 2550 | return 0; |
| 2551 | * |
| 2552 | */ |
| 2553 | switch (se_cmd->prot_op) { |
| 2554 | case TARGET_PROT_DOUT_INSERT: |
| 2555 | case TARGET_PROT_DIN_STRIP: |
| 2556 | if (ql2xenablehba_err_chk >= 1) |
| 2557 | return 1; |
| 2558 | break; |
| 2559 | case TARGET_PROT_DOUT_PASS: |
| 2560 | case TARGET_PROT_DIN_PASS: |
| 2561 | if (ql2xenablehba_err_chk >= 2) |
| 2562 | return 1; |
| 2563 | break; |
| 2564 | case TARGET_PROT_DIN_INSERT: |
| 2565 | case TARGET_PROT_DOUT_STRIP: |
| 2566 | return 1; |
| 2567 | default: |
| 2568 | break; |
| 2569 | } |
| 2570 | return 0; |
| 2571 | } |
| 2572 | |
| 2573 | /* |
| 2574 | * qla24xx_set_t10dif_tags_from_cmd - Extract Ref and App tags from SCSI command |
| 2575 | * |
| 2576 | */ |
| 2577 | static inline void |
| 2578 | qlt_set_t10dif_tags(struct se_cmd *se_cmd, struct crc_context *ctx) |
| 2579 | { |
| 2580 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; |
| 2581 | |
| 2582 | /* wait til Mode Sense/Select cmd, modepage Ah, subpage 2 |
| 2583 | * have been immplemented by TCM, before AppTag is avail. |
| 2584 | * Look for modesense_handlers[] |
| 2585 | */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2586 | ctx->app_tag = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2587 | ctx->app_tag_mask[0] = 0x0; |
| 2588 | ctx->app_tag_mask[1] = 0x0; |
| 2589 | |
| 2590 | switch (se_cmd->prot_type) { |
| 2591 | case TARGET_DIF_TYPE0_PROT: |
| 2592 | /* |
| 2593 | * No check for ql2xenablehba_err_chk, as it would be an |
| 2594 | * I/O error if hba tag generation is not done. |
| 2595 | */ |
| 2596 | ctx->ref_tag = cpu_to_le32(lba); |
| 2597 | |
| 2598 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2599 | break; |
| 2600 | |
| 2601 | /* enable ALL bytes of the ref tag */ |
| 2602 | ctx->ref_tag_mask[0] = 0xff; |
| 2603 | ctx->ref_tag_mask[1] = 0xff; |
| 2604 | ctx->ref_tag_mask[2] = 0xff; |
| 2605 | ctx->ref_tag_mask[3] = 0xff; |
| 2606 | break; |
| 2607 | /* |
| 2608 | * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and |
| 2609 | * 16 bit app tag. |
| 2610 | */ |
| 2611 | case TARGET_DIF_TYPE1_PROT: |
| 2612 | ctx->ref_tag = cpu_to_le32(lba); |
| 2613 | |
| 2614 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2615 | break; |
| 2616 | |
| 2617 | /* enable ALL bytes of the ref tag */ |
| 2618 | ctx->ref_tag_mask[0] = 0xff; |
| 2619 | ctx->ref_tag_mask[1] = 0xff; |
| 2620 | ctx->ref_tag_mask[2] = 0xff; |
| 2621 | ctx->ref_tag_mask[3] = 0xff; |
| 2622 | break; |
| 2623 | /* |
| 2624 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to |
| 2625 | * match LBA in CDB + N |
| 2626 | */ |
| 2627 | case TARGET_DIF_TYPE2_PROT: |
| 2628 | ctx->ref_tag = cpu_to_le32(lba); |
| 2629 | |
| 2630 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2631 | break; |
| 2632 | |
| 2633 | /* enable ALL bytes of the ref tag */ |
| 2634 | ctx->ref_tag_mask[0] = 0xff; |
| 2635 | ctx->ref_tag_mask[1] = 0xff; |
| 2636 | ctx->ref_tag_mask[2] = 0xff; |
| 2637 | ctx->ref_tag_mask[3] = 0xff; |
| 2638 | break; |
| 2639 | |
| 2640 | /* For Type 3 protection: 16 bit GUARD only */ |
| 2641 | case TARGET_DIF_TYPE3_PROT: |
| 2642 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = |
| 2643 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; |
| 2644 | break; |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | |
| 2649 | static inline int |
| 2650 | qlt_build_ctio_crc2_pkt(struct qla_tgt_prm *prm, scsi_qla_host_t *vha) |
| 2651 | { |
| 2652 | uint32_t *cur_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2653 | uint32_t transfer_length = 0; |
| 2654 | uint32_t data_bytes; |
| 2655 | uint32_t dif_bytes; |
| 2656 | uint8_t bundling = 1; |
| 2657 | uint8_t *clr_ptr; |
| 2658 | struct crc_context *crc_ctx_pkt = NULL; |
| 2659 | struct qla_hw_data *ha; |
| 2660 | struct ctio_crc2_to_fw *pkt; |
| 2661 | dma_addr_t crc_ctx_dma; |
| 2662 | uint16_t fw_prot_opts = 0; |
| 2663 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2664 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2665 | uint32_t h; |
| 2666 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2667 | uint16_t t16; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2668 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2669 | ha = vha->hw; |
| 2670 | |
| 2671 | pkt = (struct ctio_crc2_to_fw *)vha->req->ring_ptr; |
| 2672 | prm->pkt = pkt; |
| 2673 | memset(pkt, 0, sizeof(*pkt)); |
| 2674 | |
| 2675 | ql_dbg(ql_dbg_tgt, vha, 0xe071, |
| 2676 | "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n", |
| 2677 | vha->vp_idx, __func__, se_cmd, se_cmd->prot_op, |
| 2678 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); |
| 2679 | |
| 2680 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || |
| 2681 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) |
| 2682 | bundling = 0; |
| 2683 | |
| 2684 | /* Compute dif len and adjust data len to incude protection */ |
| 2685 | data_bytes = cmd->bufflen; |
| 2686 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; |
| 2687 | |
| 2688 | switch (se_cmd->prot_op) { |
| 2689 | case TARGET_PROT_DIN_INSERT: |
| 2690 | case TARGET_PROT_DOUT_STRIP: |
| 2691 | transfer_length = data_bytes; |
| 2692 | data_bytes += dif_bytes; |
| 2693 | break; |
| 2694 | |
| 2695 | case TARGET_PROT_DIN_STRIP: |
| 2696 | case TARGET_PROT_DOUT_INSERT: |
| 2697 | case TARGET_PROT_DIN_PASS: |
| 2698 | case TARGET_PROT_DOUT_PASS: |
| 2699 | transfer_length = data_bytes + dif_bytes; |
| 2700 | break; |
| 2701 | |
| 2702 | default: |
| 2703 | BUG(); |
| 2704 | break; |
| 2705 | } |
| 2706 | |
| 2707 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2708 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 2709 | /* HBA error checking enabled */ |
| 2710 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2711 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2712 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2713 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2714 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2715 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2716 | } |
| 2717 | |
| 2718 | switch (se_cmd->prot_op) { |
| 2719 | case TARGET_PROT_DIN_INSERT: |
| 2720 | case TARGET_PROT_DOUT_INSERT: |
| 2721 | fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 2722 | break; |
| 2723 | case TARGET_PROT_DIN_STRIP: |
| 2724 | case TARGET_PROT_DOUT_STRIP: |
| 2725 | fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 2726 | break; |
| 2727 | case TARGET_PROT_DIN_PASS: |
| 2728 | case TARGET_PROT_DOUT_PASS: |
| 2729 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2730 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ |
| 2731 | break; |
| 2732 | default:/* Normal Request */ |
| 2733 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2734 | break; |
| 2735 | } |
| 2736 | |
| 2737 | |
| 2738 | /* ---- PKT ---- */ |
| 2739 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 2740 | pkt->entry_type = CTIO_CRC2; |
| 2741 | pkt->entry_count = 1; |
| 2742 | pkt->vp_index = vha->vp_idx; |
| 2743 | |
| 2744 | h = qlt_make_handle(vha); |
| 2745 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2746 | /* |
| 2747 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2748 | * know the initiator's LOOP ID, hence we can't find |
| 2749 | * the session and, so, the command. |
| 2750 | */ |
| 2751 | return -EAGAIN; |
| 2752 | } else |
| 2753 | ha->tgt.cmds[h-1] = prm->cmd; |
| 2754 | |
| 2755 | |
| 2756 | pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK; |
| 2757 | pkt->nport_handle = prm->cmd->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2758 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2759 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2760 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2761 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2762 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2763 | |
| 2764 | /* silence compile warning */ |
| 2765 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2766 | pkt->ox_id = cpu_to_le16(t16); |
| 2767 | |
| 2768 | t16 = (atio->u.isp24.attr << 9); |
| 2769 | pkt->flags |= cpu_to_le16(t16); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2770 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2771 | |
| 2772 | /* Set transfer direction */ |
| 2773 | if (cmd->dma_data_direction == DMA_TO_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2774 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2775 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2776 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2777 | |
| 2778 | |
| 2779 | pkt->dseg_count = prm->tot_dsds; |
| 2780 | /* Fibre channel byte count */ |
| 2781 | pkt->transfer_length = cpu_to_le32(transfer_length); |
| 2782 | |
| 2783 | |
| 2784 | /* ----- CRC context -------- */ |
| 2785 | |
| 2786 | /* Allocate CRC context from global pool */ |
| 2787 | crc_ctx_pkt = cmd->ctx = |
| 2788 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
| 2789 | |
| 2790 | if (!crc_ctx_pkt) |
| 2791 | goto crc_queuing_error; |
| 2792 | |
| 2793 | /* Zero out CTX area. */ |
| 2794 | clr_ptr = (uint8_t *)crc_ctx_pkt; |
| 2795 | memset(clr_ptr, 0, sizeof(*crc_ctx_pkt)); |
| 2796 | |
| 2797 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 2798 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 2799 | |
| 2800 | /* Set handle */ |
| 2801 | crc_ctx_pkt->handle = pkt->handle; |
| 2802 | |
| 2803 | qlt_set_t10dif_tags(se_cmd, crc_ctx_pkt); |
| 2804 | |
| 2805 | pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); |
| 2806 | pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); |
| 2807 | pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 2808 | |
| 2809 | |
| 2810 | if (!bundling) { |
| 2811 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; |
| 2812 | } else { |
| 2813 | /* |
| 2814 | * Configure Bundling if we need to fetch interlaving |
| 2815 | * protection PCI accesses |
| 2816 | */ |
| 2817 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 2818 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 2819 | crc_ctx_pkt->u.bundling.dseg_count = |
| 2820 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); |
| 2821 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; |
| 2822 | } |
| 2823 | |
| 2824 | /* Finish the common fields of CRC pkt */ |
| 2825 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); |
| 2826 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 2827 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2828 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2829 | |
| 2830 | |
| 2831 | /* Walks data segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2832 | pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2833 | |
| 2834 | if (!bundling && prm->prot_seg_cnt) { |
| 2835 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, |
| 2836 | prm->tot_dsds, cmd)) |
| 2837 | goto crc_queuing_error; |
| 2838 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, |
| 2839 | (prm->tot_dsds - prm->prot_seg_cnt), cmd)) |
| 2840 | goto crc_queuing_error; |
| 2841 | |
| 2842 | if (bundling && prm->prot_seg_cnt) { |
| 2843 | /* Walks dif segments */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2844 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2845 | |
| 2846 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; |
| 2847 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, |
| 2848 | prm->prot_seg_cnt, cmd)) |
| 2849 | goto crc_queuing_error; |
| 2850 | } |
| 2851 | return QLA_SUCCESS; |
| 2852 | |
| 2853 | crc_queuing_error: |
| 2854 | /* Cleanup will be performed by the caller */ |
| 2855 | |
| 2856 | return QLA_FUNCTION_FAILED; |
| 2857 | } |
| 2858 | |
| 2859 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2860 | /* |
| 2861 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * |
| 2862 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon |
| 2863 | */ |
| 2864 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, |
| 2865 | uint8_t scsi_status) |
| 2866 | { |
| 2867 | struct scsi_qla_host *vha = cmd->vha; |
| 2868 | struct qla_hw_data *ha = vha->hw; |
| 2869 | struct ctio7_to_24xx *pkt; |
| 2870 | struct qla_tgt_prm prm; |
| 2871 | uint32_t full_req_cnt = 0; |
| 2872 | unsigned long flags = 0; |
| 2873 | int res; |
| 2874 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 2875 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2876 | if (cmd->sess && cmd->sess->deleted) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 2877 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 2878 | if (cmd->sess->logout_completed) |
| 2879 | /* no need to terminate. FW already freed exchange. */ |
| 2880 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 2881 | else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 2882 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 2883 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2884 | return 0; |
| 2885 | } |
| 2886 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2887 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2888 | memset(&prm, 0, sizeof(prm)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2889 | |
| 2890 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe018, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2891 | "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p]\n", |
| 2892 | (xmit_type & QLA_TGT_XMIT_STATUS) ? |
| 2893 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, |
| 2894 | &cmd->se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2895 | |
| 2896 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, |
| 2897 | &full_req_cnt); |
| 2898 | if (unlikely(res != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2899 | return res; |
| 2900 | } |
| 2901 | |
| 2902 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2903 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 2904 | if (xmit_type == QLA_TGT_XMIT_STATUS) |
| 2905 | vha->tgt_counters.core_qla_snd_status++; |
| 2906 | else |
| 2907 | vha->tgt_counters.core_qla_que_buf++; |
| 2908 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2909 | if (!vha->flags.online || cmd->reset_count != ha->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2910 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2911 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2912 | * previous life, just abort the processing. |
| 2913 | */ |
| 2914 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 2915 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 2916 | ql_dbg(ql_dbg_async, vha, 0xe101, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2917 | "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2918 | vha->flags.online, qla2x00_reset_active(vha), |
| 2919 | cmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2920 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2921 | return 0; |
| 2922 | } |
| 2923 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2924 | /* Does F/W have an IOCBs for this request */ |
| 2925 | res = qlt_check_reserve_free_req(vha, full_req_cnt); |
| 2926 | if (unlikely(res)) |
| 2927 | goto out_unmap_unlock; |
| 2928 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2929 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
| 2930 | res = qlt_build_ctio_crc2_pkt(&prm, vha); |
| 2931 | else |
| 2932 | res = qlt_24xx_build_ctio_pkt(&prm, vha); |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 2933 | if (unlikely(res != 0)) { |
| 2934 | vha->req->cnt += full_req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2935 | goto out_unmap_unlock; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 2936 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2937 | |
| 2938 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
| 2939 | |
| 2940 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { |
| 2941 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2942 | cpu_to_le16(CTIO7_FLAGS_DATA_IN | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2943 | CTIO7_FLAGS_STATUS_MODE_0); |
| 2944 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2945 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
| 2946 | qlt_load_data_segments(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2947 | |
| 2948 | if (prm.add_status_pkt == 0) { |
| 2949 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2950 | pkt->u.status0.scsi_status = |
| 2951 | cpu_to_le16(prm.rq_result); |
| 2952 | pkt->u.status0.residual = |
| 2953 | cpu_to_le32(prm.residual); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2954 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2955 | CTIO7_FLAGS_SEND_STATUS); |
| 2956 | if (qlt_need_explicit_conf(ha, cmd, 0)) { |
| 2957 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2958 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2959 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2960 | CTIO7_FLAGS_CONFORM_REQ); |
| 2961 | } |
| 2962 | } |
| 2963 | |
| 2964 | } else { |
| 2965 | /* |
| 2966 | * We have already made sure that there is sufficient |
| 2967 | * amount of request entries to not drop HW lock in |
| 2968 | * req_pkt(). |
| 2969 | */ |
| 2970 | struct ctio7_to_24xx *ctio = |
| 2971 | (struct ctio7_to_24xx *)qlt_get_req_pkt(vha); |
| 2972 | |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2973 | ql_dbg(ql_dbg_io, vha, 0x305e, |
| 2974 | "Building additional status packet 0x%p.\n", |
| 2975 | ctio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2976 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2977 | /* |
| 2978 | * T10Dif: ctio_crc2_to_fw overlay ontop of |
| 2979 | * ctio7_to_24xx |
| 2980 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2981 | memcpy(ctio, pkt, sizeof(*ctio)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2982 | /* reset back to CTIO7 */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2983 | ctio->entry_count = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2984 | ctio->entry_type = CTIO_TYPE7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2985 | ctio->dseg_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2986 | ctio->u.status1.flags &= ~cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2987 | CTIO7_FLAGS_DATA_IN); |
| 2988 | |
| 2989 | /* Real finish is ctio_m1's finish */ |
| 2990 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2991 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2992 | CTIO7_FLAGS_DONT_RET_CTIO); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2993 | |
| 2994 | /* qlt_24xx_init_ctio_to_isp will correct |
| 2995 | * all neccessary fields that's part of CTIO7. |
| 2996 | * There should be no residual of CTIO-CRC2 data. |
| 2997 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2998 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
| 2999 | &prm); |
| 3000 | pr_debug("Status CTIO7: %p\n", ctio); |
| 3001 | } |
| 3002 | } else |
| 3003 | qlt_24xx_init_ctio_to_isp(pkt, &prm); |
| 3004 | |
| 3005 | |
| 3006 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3007 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3008 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3009 | /* Memory Barrier */ |
| 3010 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3011 | qla2x00_start_iocbs(vha, vha->req); |
| 3012 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3013 | |
| 3014 | return 0; |
| 3015 | |
| 3016 | out_unmap_unlock: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3017 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3018 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3019 | |
| 3020 | return res; |
| 3021 | } |
| 3022 | EXPORT_SYMBOL(qlt_xmit_response); |
| 3023 | |
| 3024 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) |
| 3025 | { |
| 3026 | struct ctio7_to_24xx *pkt; |
| 3027 | struct scsi_qla_host *vha = cmd->vha; |
| 3028 | struct qla_hw_data *ha = vha->hw; |
| 3029 | struct qla_tgt *tgt = cmd->tgt; |
| 3030 | struct qla_tgt_prm prm; |
| 3031 | unsigned long flags; |
| 3032 | int res = 0; |
| 3033 | |
| 3034 | memset(&prm, 0, sizeof(prm)); |
| 3035 | prm.cmd = cmd; |
| 3036 | prm.tgt = tgt; |
| 3037 | prm.sg = NULL; |
| 3038 | prm.req_cnt = 1; |
| 3039 | |
| 3040 | /* Send marker if required */ |
| 3041 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) |
| 3042 | return -EIO; |
| 3043 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3044 | /* Calculate number of entries and segments required */ |
| 3045 | if (qlt_pci_map_calc_cnt(&prm) != 0) |
| 3046 | return -EAGAIN; |
| 3047 | |
| 3048 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3049 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3050 | if (!vha->flags.online || (cmd->reset_count != ha->chip_reset) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3051 | (cmd->sess && cmd->sess->deleted)) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3052 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3053 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3054 | * previous life, just abort the processing. |
| 3055 | */ |
| 3056 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
| 3057 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 3058 | ql_dbg(ql_dbg_async, vha, 0xe102, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3059 | "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3060 | vha->flags.online, qla2x00_reset_active(vha), |
| 3061 | cmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3062 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3063 | return 0; |
| 3064 | } |
| 3065 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3066 | /* Does F/W have an IOCBs for this request */ |
| 3067 | res = qlt_check_reserve_free_req(vha, prm.req_cnt); |
| 3068 | if (res != 0) |
| 3069 | goto out_unlock_free_unmap; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3070 | if (cmd->se_cmd.prot_op) |
| 3071 | res = qlt_build_ctio_crc2_pkt(&prm, vha); |
| 3072 | else |
| 3073 | res = qlt_24xx_build_ctio_pkt(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3074 | |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3075 | if (unlikely(res != 0)) { |
| 3076 | vha->req->cnt += prm.req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3077 | goto out_unlock_free_unmap; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3078 | } |
| 3079 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3080 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3081 | pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3082 | CTIO7_FLAGS_STATUS_MODE_0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3083 | |
| 3084 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
| 3085 | qlt_load_data_segments(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3086 | |
| 3087 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3088 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3089 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3090 | /* Memory Barrier */ |
| 3091 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3092 | qla2x00_start_iocbs(vha, vha->req); |
| 3093 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3094 | |
| 3095 | return res; |
| 3096 | |
| 3097 | out_unlock_free_unmap: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3098 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3099 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3100 | |
| 3101 | return res; |
| 3102 | } |
| 3103 | EXPORT_SYMBOL(qlt_rdy_to_xfer); |
| 3104 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3105 | |
| 3106 | /* |
| 3107 | * Checks the guard or meta-data for the type of error |
| 3108 | * detected by the HBA. |
| 3109 | */ |
| 3110 | static inline int |
| 3111 | qlt_handle_dif_error(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd, |
| 3112 | struct ctio_crc_from_fw *sts) |
| 3113 | { |
| 3114 | uint8_t *ap = &sts->actual_dif[0]; |
| 3115 | uint8_t *ep = &sts->expected_dif[0]; |
| 3116 | uint32_t e_ref_tag, a_ref_tag; |
| 3117 | uint16_t e_app_tag, a_app_tag; |
| 3118 | uint16_t e_guard, a_guard; |
| 3119 | uint64_t lba = cmd->se_cmd.t_task_lba; |
| 3120 | |
| 3121 | a_guard = be16_to_cpu(*(uint16_t *)(ap + 0)); |
| 3122 | a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2)); |
| 3123 | a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4)); |
| 3124 | |
| 3125 | e_guard = be16_to_cpu(*(uint16_t *)(ep + 0)); |
| 3126 | e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2)); |
| 3127 | e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4)); |
| 3128 | |
| 3129 | ql_dbg(ql_dbg_tgt, vha, 0xe075, |
| 3130 | "iocb(s) %p Returned STATUS.\n", sts); |
| 3131 | |
| 3132 | ql_dbg(ql_dbg_tgt, vha, 0xf075, |
Hans Wennborg | fc38504 | 2014-08-05 21:43:29 -0700 | [diff] [blame] | 3133 | "dif check TGT cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x]\n", |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3134 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 3135 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, a_guard, e_guard); |
| 3136 | |
| 3137 | /* |
| 3138 | * Ignore sector if: |
| 3139 | * For type 3: ref & app tag is all 'f's |
| 3140 | * For type 0,1,2: app tag is all 'f's |
| 3141 | */ |
| 3142 | if ((a_app_tag == 0xffff) && |
| 3143 | ((cmd->se_cmd.prot_type != TARGET_DIF_TYPE3_PROT) || |
| 3144 | (a_ref_tag == 0xffffffff))) { |
| 3145 | uint32_t blocks_done; |
| 3146 | |
| 3147 | /* 2TB boundary case covered automatically with this */ |
| 3148 | blocks_done = e_ref_tag - (uint32_t)lba + 1; |
| 3149 | cmd->se_cmd.bad_sector = e_ref_tag; |
| 3150 | cmd->se_cmd.pi_err = 0; |
| 3151 | ql_dbg(ql_dbg_tgt, vha, 0xf074, |
| 3152 | "need to return scsi good\n"); |
| 3153 | |
| 3154 | /* Update protection tag */ |
| 3155 | if (cmd->prot_sg_cnt) { |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 3156 | uint32_t i, k = 0, num_ent; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3157 | struct scatterlist *sg, *sgl; |
| 3158 | |
| 3159 | |
| 3160 | sgl = cmd->prot_sg; |
| 3161 | |
| 3162 | /* Patch the corresponding protection tags */ |
| 3163 | for_each_sg(sgl, sg, cmd->prot_sg_cnt, i) { |
| 3164 | num_ent = sg_dma_len(sg) / 8; |
| 3165 | if (k + num_ent < blocks_done) { |
| 3166 | k += num_ent; |
| 3167 | continue; |
| 3168 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3169 | k = blocks_done; |
| 3170 | break; |
| 3171 | } |
| 3172 | |
| 3173 | if (k != blocks_done) { |
| 3174 | ql_log(ql_log_warn, vha, 0xf076, |
| 3175 | "unexpected tag values tag:lba=%u:%llu)\n", |
| 3176 | e_ref_tag, (unsigned long long)lba); |
| 3177 | goto out; |
| 3178 | } |
| 3179 | |
| 3180 | #if 0 |
| 3181 | struct sd_dif_tuple *spt; |
| 3182 | /* TODO: |
| 3183 | * This section came from initiator. Is it valid here? |
| 3184 | * should ulp be override with actual val??? |
| 3185 | */ |
| 3186 | spt = page_address(sg_page(sg)) + sg->offset; |
| 3187 | spt += j; |
| 3188 | |
| 3189 | spt->app_tag = 0xffff; |
| 3190 | if (cmd->se_cmd.prot_type == SCSI_PROT_DIF_TYPE3) |
| 3191 | spt->ref_tag = 0xffffffff; |
| 3192 | #endif |
| 3193 | } |
| 3194 | |
| 3195 | return 0; |
| 3196 | } |
| 3197 | |
| 3198 | /* check guard */ |
| 3199 | if (e_guard != a_guard) { |
| 3200 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED; |
| 3201 | cmd->se_cmd.bad_sector = cmd->se_cmd.t_task_lba; |
| 3202 | |
| 3203 | ql_log(ql_log_warn, vha, 0xe076, |
| 3204 | "Guard ERR: cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x] cmd=%p\n", |
| 3205 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 3206 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, |
| 3207 | a_guard, e_guard, cmd); |
| 3208 | goto out; |
| 3209 | } |
| 3210 | |
| 3211 | /* check ref tag */ |
| 3212 | if (e_ref_tag != a_ref_tag) { |
| 3213 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED; |
| 3214 | cmd->se_cmd.bad_sector = e_ref_tag; |
| 3215 | |
| 3216 | ql_log(ql_log_warn, vha, 0xe077, |
| 3217 | "Ref Tag ERR: cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x] cmd=%p\n", |
| 3218 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 3219 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, |
| 3220 | a_guard, e_guard, cmd); |
| 3221 | goto out; |
| 3222 | } |
| 3223 | |
| 3224 | /* check appl tag */ |
| 3225 | if (e_app_tag != a_app_tag) { |
| 3226 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED; |
| 3227 | cmd->se_cmd.bad_sector = cmd->se_cmd.t_task_lba; |
| 3228 | |
| 3229 | ql_log(ql_log_warn, vha, 0xe078, |
| 3230 | "App Tag ERR: cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x] cmd=%p\n", |
| 3231 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 3232 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, |
| 3233 | a_guard, e_guard, cmd); |
| 3234 | goto out; |
| 3235 | } |
| 3236 | out: |
| 3237 | return 1; |
| 3238 | } |
| 3239 | |
| 3240 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3241 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3242 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3243 | static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3244 | struct imm_ntfy_from_isp *ntfy) |
| 3245 | { |
| 3246 | struct nack_to_isp *nack; |
| 3247 | struct qla_hw_data *ha = vha->hw; |
| 3248 | request_t *pkt; |
| 3249 | int ret = 0; |
| 3250 | |
| 3251 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c, |
| 3252 | "Sending TERM ELS CTIO (ha=%p)\n", ha); |
| 3253 | |
| 3254 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(vha, NULL); |
| 3255 | if (pkt == NULL) { |
| 3256 | ql_dbg(ql_dbg_tgt, vha, 0xe080, |
| 3257 | "qla_target(%d): %s failed: unable to allocate " |
| 3258 | "request packet\n", vha->vp_idx, __func__); |
| 3259 | return -ENOMEM; |
| 3260 | } |
| 3261 | |
| 3262 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 3263 | pkt->entry_count = 1; |
Quinn Tran | 4f06073 | 2016-12-23 18:06:13 -0800 | [diff] [blame] | 3264 | pkt->handle = QLA_TGT_SKIP_HANDLE; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3265 | |
| 3266 | nack = (struct nack_to_isp *)pkt; |
| 3267 | nack->ox_id = ntfy->ox_id; |
| 3268 | |
| 3269 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3270 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3271 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
| 3272 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
| 3273 | } |
| 3274 | |
| 3275 | /* terminate */ |
| 3276 | nack->u.isp24.flags |= |
| 3277 | __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE); |
| 3278 | |
| 3279 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3280 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3281 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3282 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3283 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3284 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3285 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3286 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3287 | |
| 3288 | qla2x00_start_iocbs(vha, vha->req); |
| 3289 | return ret; |
| 3290 | } |
| 3291 | |
| 3292 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3293 | struct imm_ntfy_from_isp *imm, int ha_locked) |
| 3294 | { |
| 3295 | unsigned long flags = 0; |
| 3296 | int rc; |
| 3297 | |
| 3298 | if (qlt_issue_marker(vha, ha_locked) < 0) |
| 3299 | return; |
| 3300 | |
| 3301 | if (ha_locked) { |
| 3302 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3303 | |
| 3304 | #if 0 /* Todo */ |
| 3305 | if (rc == -ENOMEM) |
| 3306 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
Bart Van Assche | 91f42b3 | 2016-03-30 15:25:21 -0700 | [diff] [blame] | 3307 | #else |
| 3308 | if (rc) { |
| 3309 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3310 | #endif |
| 3311 | goto done; |
| 3312 | } |
| 3313 | |
| 3314 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 3315 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3316 | |
| 3317 | #if 0 /* Todo */ |
| 3318 | if (rc == -ENOMEM) |
| 3319 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
| 3320 | #endif |
| 3321 | |
| 3322 | done: |
| 3323 | if (!ha_locked) |
| 3324 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 3325 | } |
| 3326 | |
| 3327 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3328 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3329 | static int __qlt_send_term_exchange(struct scsi_qla_host *vha, |
| 3330 | struct qla_tgt_cmd *cmd, |
| 3331 | struct atio_from_isp *atio) |
| 3332 | { |
| 3333 | struct ctio7_to_24xx *ctio24; |
| 3334 | struct qla_hw_data *ha = vha->hw; |
| 3335 | request_t *pkt; |
| 3336 | int ret = 0; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3337 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3338 | |
| 3339 | ql_dbg(ql_dbg_tgt, vha, 0xe01c, "Sending TERM EXCH CTIO (ha=%p)\n", ha); |
| 3340 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3341 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3342 | if (pkt == NULL) { |
| 3343 | ql_dbg(ql_dbg_tgt, vha, 0xe050, |
| 3344 | "qla_target(%d): %s failed: unable to allocate " |
| 3345 | "request packet\n", vha->vp_idx, __func__); |
| 3346 | return -ENOMEM; |
| 3347 | } |
| 3348 | |
| 3349 | if (cmd != NULL) { |
| 3350 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { |
| 3351 | ql_dbg(ql_dbg_tgt, vha, 0xe051, |
| 3352 | "qla_target(%d): Terminating cmd %p with " |
| 3353 | "incorrect state %d\n", vha->vp_idx, cmd, |
| 3354 | cmd->state); |
| 3355 | } else |
| 3356 | ret = 1; |
| 3357 | } |
| 3358 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3359 | vha->tgt_counters.num_term_xchg_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3360 | pkt->entry_count = 1; |
| 3361 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 3362 | |
| 3363 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 3364 | ctio24->entry_type = CTIO_TYPE7; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3365 | ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3366 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3367 | ctio24->vp_index = vha->vp_idx; |
| 3368 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 3369 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 3370 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 3371 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
| 3372 | ctio24->u.status1.flags = (atio->u.isp24.attr << 9) | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3373 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3374 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3375 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3376 | ctio24->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3377 | |
| 3378 | /* Most likely, it isn't needed */ |
| 3379 | ctio24->u.status1.residual = get_unaligned((uint32_t *) |
| 3380 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 3381 | atio->u.isp24.fcp_cmnd.add_cdb_len]); |
| 3382 | if (ctio24->u.status1.residual != 0) |
| 3383 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; |
| 3384 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3385 | /* Memory Barrier */ |
| 3386 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3387 | qla2x00_start_iocbs(vha, vha->req); |
| 3388 | return ret; |
| 3389 | } |
| 3390 | |
| 3391 | static void qlt_send_term_exchange(struct scsi_qla_host *vha, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3392 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, |
| 3393 | int ul_abort) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3394 | { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3395 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3396 | int rc; |
| 3397 | |
| 3398 | if (qlt_issue_marker(vha, ha_locked) < 0) |
| 3399 | return; |
| 3400 | |
| 3401 | if (ha_locked) { |
| 3402 | rc = __qlt_send_term_exchange(vha, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3403 | if (rc == -ENOMEM) |
| 3404 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3405 | goto done; |
| 3406 | } |
| 3407 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 3408 | rc = __qlt_send_term_exchange(vha, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3409 | if (rc == -ENOMEM) |
| 3410 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3411 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3412 | done: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3413 | if (cmd && !ul_abort && !cmd->aborted) { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3414 | if (cmd->sg_mapped) |
| 3415 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3416 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3417 | } |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3418 | |
| 3419 | if (!ha_locked) |
| 3420 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 3421 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3422 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3423 | } |
| 3424 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3425 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
| 3426 | { |
| 3427 | struct list_head free_list; |
| 3428 | struct qla_tgt_cmd *cmd, *tcmd; |
| 3429 | |
| 3430 | vha->hw->tgt.leak_exchg_thresh_hold = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3431 | (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3432 | |
| 3433 | cmd = tcmd = NULL; |
| 3434 | if (!list_empty(&vha->hw->tgt.q_full_list)) { |
| 3435 | INIT_LIST_HEAD(&free_list); |
| 3436 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); |
| 3437 | |
| 3438 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 3439 | list_del(&cmd->cmd_list); |
| 3440 | /* This cmd was never sent to TCM. There is no need |
| 3441 | * to schedule free or call free_cmd |
| 3442 | */ |
| 3443 | qlt_free_cmd(cmd); |
| 3444 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 3445 | } |
| 3446 | } |
| 3447 | vha->hw->tgt.num_qfull_cmds_dropped = 0; |
| 3448 | } |
| 3449 | |
| 3450 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) |
| 3451 | { |
| 3452 | uint32_t total_leaked; |
| 3453 | |
| 3454 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; |
| 3455 | |
| 3456 | if (vha->hw->tgt.leak_exchg_thresh_hold && |
| 3457 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { |
| 3458 | |
| 3459 | ql_dbg(ql_dbg_tgt, vha, 0xe079, |
| 3460 | "Chip reset due to exchange starvation: %d/%d.\n", |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3461 | total_leaked, vha->hw->cur_fw_xcb_count); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3462 | |
| 3463 | if (IS_P3P_TYPE(vha->hw)) |
| 3464 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 3465 | else |
| 3466 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3467 | qla2xxx_wake_dpc(vha); |
| 3468 | } |
| 3469 | |
| 3470 | } |
| 3471 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3472 | int qlt_abort_cmd(struct qla_tgt_cmd *cmd) |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3473 | { |
| 3474 | struct qla_tgt *tgt = cmd->tgt; |
| 3475 | struct scsi_qla_host *vha = tgt->vha; |
| 3476 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3477 | unsigned long flags; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3478 | |
| 3479 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, |
| 3480 | "qla_target(%d): terminating exchange for aborted cmd=%p " |
| 3481 | "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, |
| 3482 | se_cmd->tag); |
| 3483 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3484 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3485 | if (cmd->aborted) { |
| 3486 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3487 | /* |
| 3488 | * It's normal to see 2 calls in this path: |
| 3489 | * 1) XFER Rdy completion + CMD_T_ABORT |
| 3490 | * 2) TCM TMR - drain_state_list |
| 3491 | */ |
| 3492 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xffff, |
| 3493 | "multiple abort. %p transport_state %x, t_state %x," |
| 3494 | " se_cmd_flags %x \n", cmd, cmd->se_cmd.transport_state, |
| 3495 | cmd->se_cmd.t_state,cmd->se_cmd.se_cmd_flags); |
| 3496 | return EIO; |
| 3497 | } |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3498 | cmd->aborted = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3499 | cmd->trc_flags |= TRC_ABORT; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3500 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3501 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3502 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 0, 1); |
| 3503 | return 0; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3504 | } |
| 3505 | EXPORT_SYMBOL(qlt_abort_cmd); |
| 3506 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3507 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
| 3508 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3509 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3510 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3511 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
| 3512 | "%s: se_cmd[%p] ox_id %04x\n", |
| 3513 | __func__, &cmd->se_cmd, |
| 3514 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3515 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3516 | BUG_ON(cmd->cmd_in_wq); |
| 3517 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3518 | if (cmd->sg_mapped) |
| 3519 | qlt_unmap_sg(cmd->vha, cmd); |
| 3520 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3521 | if (!cmd->q_full) |
| 3522 | qlt_decr_num_pend_cmds(cmd->vha); |
| 3523 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3524 | BUG_ON(cmd->sg_mapped); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3525 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3526 | if (unlikely(cmd->free_sg)) |
| 3527 | kfree(cmd->sg); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3528 | |
| 3529 | if (!sess || !sess->se_sess) { |
| 3530 | WARN_ON(1); |
| 3531 | return; |
| 3532 | } |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3533 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3534 | 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] | 3535 | } |
| 3536 | EXPORT_SYMBOL(qlt_free_cmd); |
| 3537 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3538 | /* |
| 3539 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3540 | */ |
| 3541 | static int qlt_term_ctio_exchange(struct scsi_qla_host *vha, void *ctio, |
| 3542 | struct qla_tgt_cmd *cmd, uint32_t status) |
| 3543 | { |
| 3544 | int term = 0; |
| 3545 | |
| 3546 | if (ctio != NULL) { |
| 3547 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; |
| 3548 | term = !(c->flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3549 | cpu_to_le16(OF_TERM_EXCH)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3550 | } else |
| 3551 | term = 1; |
| 3552 | |
| 3553 | if (term) |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3554 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3555 | |
| 3556 | return term; |
| 3557 | } |
| 3558 | |
| 3559 | /* ha->hardware_lock supposed to be held on entry */ |
| 3560 | static inline struct qla_tgt_cmd *qlt_get_cmd(struct scsi_qla_host *vha, |
| 3561 | uint32_t handle) |
| 3562 | { |
| 3563 | struct qla_hw_data *ha = vha->hw; |
| 3564 | |
| 3565 | handle--; |
| 3566 | if (ha->tgt.cmds[handle] != NULL) { |
| 3567 | struct qla_tgt_cmd *cmd = ha->tgt.cmds[handle]; |
| 3568 | ha->tgt.cmds[handle] = NULL; |
| 3569 | return cmd; |
| 3570 | } else |
| 3571 | return NULL; |
| 3572 | } |
| 3573 | |
| 3574 | /* ha->hardware_lock supposed to be held on entry */ |
| 3575 | static struct qla_tgt_cmd *qlt_ctio_to_cmd(struct scsi_qla_host *vha, |
| 3576 | uint32_t handle, void *ctio) |
| 3577 | { |
| 3578 | struct qla_tgt_cmd *cmd = NULL; |
| 3579 | |
| 3580 | /* Clear out internal marks */ |
| 3581 | handle &= ~(CTIO_COMPLETION_HANDLE_MARK | |
| 3582 | CTIO_INTERMEDIATE_HANDLE_MARK); |
| 3583 | |
| 3584 | if (handle != QLA_TGT_NULL_HANDLE) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3585 | if (unlikely(handle == QLA_TGT_SKIP_HANDLE)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3586 | return NULL; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3587 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3588 | /* handle-1 is actually used */ |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3589 | if (unlikely(handle > DEFAULT_OUTSTANDING_COMMANDS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3590 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
| 3591 | "qla_target(%d): Wrong handle %x received\n", |
| 3592 | vha->vp_idx, handle); |
| 3593 | return NULL; |
| 3594 | } |
| 3595 | cmd = qlt_get_cmd(vha, handle); |
| 3596 | if (unlikely(cmd == NULL)) { |
| 3597 | ql_dbg(ql_dbg_tgt, vha, 0xe053, |
| 3598 | "qla_target(%d): Suspicious: unable to " |
| 3599 | "find the command with handle %x\n", vha->vp_idx, |
| 3600 | handle); |
| 3601 | return NULL; |
| 3602 | } |
| 3603 | } else if (ctio != NULL) { |
| 3604 | /* We can't get loop ID from CTIO7 */ |
| 3605 | ql_dbg(ql_dbg_tgt, vha, 0xe054, |
| 3606 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " |
| 3607 | "support NULL handles\n", vha->vp_idx); |
| 3608 | return NULL; |
| 3609 | } |
| 3610 | |
| 3611 | return cmd; |
| 3612 | } |
| 3613 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3614 | /* hardware_lock should be held by caller. */ |
| 3615 | static void |
| 3616 | qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) |
| 3617 | { |
| 3618 | struct qla_hw_data *ha = vha->hw; |
| 3619 | uint32_t handle; |
| 3620 | |
| 3621 | if (cmd->sg_mapped) |
| 3622 | qlt_unmap_sg(vha, cmd); |
| 3623 | |
| 3624 | handle = qlt_make_handle(vha); |
| 3625 | |
| 3626 | /* TODO: fix debug message type and ids. */ |
| 3627 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
| 3628 | ql_dbg(ql_dbg_io, vha, 0xff00, |
| 3629 | "HOST-ABORT: handle=%d, state=PROCESSED.\n", handle); |
| 3630 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 3631 | cmd->write_data_transferred = 0; |
| 3632 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3633 | |
| 3634 | ql_dbg(ql_dbg_io, vha, 0xff01, |
| 3635 | "HOST-ABORT: handle=%d, state=DATA_IN.\n", handle); |
| 3636 | |
| 3637 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3638 | return; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3639 | } else { |
| 3640 | ql_dbg(ql_dbg_io, vha, 0xff03, |
| 3641 | "HOST-ABORT: handle=%d, state=BAD(%d).\n", handle, |
| 3642 | cmd->state); |
| 3643 | dump_stack(); |
| 3644 | } |
| 3645 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3646 | cmd->trc_flags |= TRC_FLUSH; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3647 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3648 | } |
| 3649 | |
| 3650 | void |
| 3651 | qlt_host_reset_handler(struct qla_hw_data *ha) |
| 3652 | { |
| 3653 | struct qla_tgt_cmd *cmd; |
| 3654 | unsigned long flags; |
| 3655 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
| 3656 | scsi_qla_host_t *vha = NULL; |
| 3657 | struct qla_tgt *tgt = base_vha->vha_tgt.qla_tgt; |
| 3658 | uint32_t i; |
| 3659 | |
| 3660 | if (!base_vha->hw->tgt.tgt_ops) |
| 3661 | return; |
| 3662 | |
| 3663 | if (!tgt || qla_ini_mode_enabled(base_vha)) { |
| 3664 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003, |
| 3665 | "Target mode disabled\n"); |
| 3666 | return; |
| 3667 | } |
| 3668 | |
| 3669 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xff10, |
| 3670 | "HOST-ABORT-HNDLR: base_vha->dpc_flags=%lx.\n", |
| 3671 | base_vha->dpc_flags); |
| 3672 | |
| 3673 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3674 | for (i = 1; i < DEFAULT_OUTSTANDING_COMMANDS + 1; i++) { |
| 3675 | cmd = qlt_get_cmd(base_vha, i); |
| 3676 | if (!cmd) |
| 3677 | continue; |
| 3678 | /* ha->tgt.cmds entry is cleared by qlt_get_cmd. */ |
| 3679 | vha = cmd->vha; |
| 3680 | qlt_abort_cmd_on_host_reset(vha, cmd); |
| 3681 | } |
| 3682 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3683 | } |
| 3684 | |
| 3685 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3686 | /* |
| 3687 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3688 | */ |
| 3689 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, uint32_t handle, |
| 3690 | uint32_t status, void *ctio) |
| 3691 | { |
| 3692 | struct qla_hw_data *ha = vha->hw; |
| 3693 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3694 | struct qla_tgt_cmd *cmd; |
| 3695 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3696 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
| 3697 | /* That could happen only in case of an error/reset/abort */ |
| 3698 | if (status != CTIO_SUCCESS) { |
| 3699 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, |
| 3700 | "Intermediate CTIO received" |
| 3701 | " (status %x)\n", status); |
| 3702 | } |
| 3703 | return; |
| 3704 | } |
| 3705 | |
| 3706 | cmd = qlt_ctio_to_cmd(vha, handle, ctio); |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3707 | if (cmd == NULL) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3708 | return; |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3709 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3710 | se_cmd = &cmd->se_cmd; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3711 | cmd->cmd_sent_to_fw = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3712 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3713 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3714 | |
| 3715 | if (unlikely(status != CTIO_SUCCESS)) { |
| 3716 | switch (status & 0xFFFF) { |
| 3717 | case CTIO_LIP_RESET: |
| 3718 | case CTIO_TARGET_RESET: |
| 3719 | case CTIO_ABORTED: |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3720 | /* driver request abort via Terminate exchange */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3721 | case CTIO_TIMEOUT: |
| 3722 | case CTIO_INVALID_RX_ID: |
| 3723 | /* They are OK */ |
| 3724 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, |
| 3725 | "qla_target(%d): CTIO with " |
| 3726 | "status %#x received, state %x, se_cmd %p, " |
| 3727 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " |
| 3728 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, |
| 3729 | status, cmd->state, se_cmd); |
| 3730 | break; |
| 3731 | |
| 3732 | case CTIO_PORT_LOGGED_OUT: |
| 3733 | case CTIO_PORT_UNAVAILABLE: |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3734 | { |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3735 | int logged_out = |
| 3736 | (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; |
| 3737 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3738 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3739 | "qla_target(%d): CTIO with %s status %x " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3740 | "received (state %x, se_cmd %p)\n", vha->vp_idx, |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3741 | logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3742 | status, cmd->state, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3743 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3744 | if (logged_out && cmd->sess) { |
| 3745 | /* |
| 3746 | * Session is already logged out, but we need |
| 3747 | * to notify initiator, who's not aware of this |
| 3748 | */ |
| 3749 | cmd->sess->logout_on_delete = 0; |
| 3750 | cmd->sess->send_els_logo = 1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3751 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 3752 | "%s %d %8phC post del sess\n", |
| 3753 | __func__, __LINE__, cmd->sess->port_name); |
| 3754 | |
| 3755 | qlt_schedule_sess_for_deletion_lock(cmd->sess); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3756 | } |
| 3757 | break; |
| 3758 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3759 | case CTIO_DIF_ERROR: { |
| 3760 | struct ctio_crc_from_fw *crc = |
| 3761 | (struct ctio_crc_from_fw *)ctio; |
| 3762 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, |
| 3763 | "qla_target(%d): CTIO with DIF_ERROR status %x received (state %x, se_cmd %p) actual_dif[0x%llx] expect_dif[0x%llx]\n", |
| 3764 | vha->vp_idx, status, cmd->state, se_cmd, |
| 3765 | *((u64 *)&crc->actual_dif[0]), |
| 3766 | *((u64 *)&crc->expected_dif[0])); |
| 3767 | |
| 3768 | if (qlt_handle_dif_error(vha, cmd, ctio)) { |
| 3769 | if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 3770 | /* scsi Write/xfer rdy complete */ |
| 3771 | goto skip_term; |
| 3772 | } else { |
| 3773 | /* scsi read/xmit respond complete |
| 3774 | * call handle dif to send scsi status |
| 3775 | * rather than terminate exchange. |
| 3776 | */ |
| 3777 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3778 | ha->tgt.tgt_ops->handle_dif_err(cmd); |
| 3779 | return; |
| 3780 | } |
| 3781 | } else { |
| 3782 | /* Need to generate a SCSI good completion. |
| 3783 | * because FW did not send scsi status. |
| 3784 | */ |
| 3785 | status = 0; |
| 3786 | goto skip_term; |
| 3787 | } |
| 3788 | break; |
| 3789 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3790 | default: |
| 3791 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3792 | "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] | 3793 | vha->vp_idx, status, cmd->state, se_cmd); |
| 3794 | break; |
| 3795 | } |
| 3796 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3797 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3798 | /* "cmd->aborted" means |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3799 | * cmd is already aborted/terminated, we don't |
| 3800 | * need to terminate again. The exchange is already |
| 3801 | * cleaned up/freed at FW level. Just cleanup at driver |
| 3802 | * level. |
| 3803 | */ |
| 3804 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3805 | (!cmd->aborted)) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3806 | cmd->trc_flags |= TRC_CTIO_ERR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3807 | if (qlt_term_ctio_exchange(vha, ctio, cmd, status)) |
| 3808 | return; |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3809 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3810 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3811 | skip_term: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3812 | |
| 3813 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3814 | cmd->trc_flags |= TRC_CTIO_DONE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3815 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3816 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3817 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 3818 | if (status == CTIO_SUCCESS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3819 | cmd->write_data_transferred = 1; |
| 3820 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3821 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3822 | return; |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3823 | } else if (cmd->aborted) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3824 | cmd->trc_flags |= TRC_CTIO_ABORTED; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3825 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 3826 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3827 | } else { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3828 | cmd->trc_flags |= TRC_CTIO_STRANGE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3829 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
| 3830 | "qla_target(%d): A command in state (%d) should " |
| 3831 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); |
| 3832 | } |
| 3833 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3834 | if (unlikely(status != CTIO_SUCCESS) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3835 | !cmd->aborted) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3836 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
| 3837 | dump_stack(); |
| 3838 | } |
| 3839 | |
| 3840 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3841 | } |
| 3842 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3843 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
| 3844 | uint8_t task_codes) |
| 3845 | { |
| 3846 | int fcp_task_attr; |
| 3847 | |
| 3848 | switch (task_codes) { |
| 3849 | case ATIO_SIMPLE_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3850 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3851 | break; |
| 3852 | case ATIO_HEAD_OF_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3853 | fcp_task_attr = TCM_HEAD_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3854 | break; |
| 3855 | case ATIO_ORDERED_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3856 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3857 | break; |
| 3858 | case ATIO_ACA_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3859 | fcp_task_attr = TCM_ACA_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3860 | break; |
| 3861 | case ATIO_UNTAGGED: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3862 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3863 | break; |
| 3864 | default: |
| 3865 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, |
| 3866 | "qla_target: unknown task code %x, use ORDERED instead\n", |
| 3867 | task_codes); |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3868 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3869 | break; |
| 3870 | } |
| 3871 | |
| 3872 | return fcp_task_attr; |
| 3873 | } |
| 3874 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3875 | static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3876 | uint8_t *); |
| 3877 | /* |
| 3878 | * Process context for I/O path into tcm_qla2xxx code |
| 3879 | */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3880 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3881 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3882 | scsi_qla_host_t *vha = cmd->vha; |
| 3883 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 3884 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3885 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3886 | struct atio_from_isp *atio = &cmd->atio; |
| 3887 | unsigned char *cdb; |
| 3888 | unsigned long flags; |
| 3889 | uint32_t data_length; |
| 3890 | int ret, fcp_task_attr, data_dir, bidi = 0; |
| 3891 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3892 | cmd->cmd_in_wq = 0; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3893 | cmd->trc_flags |= TRC_DO_WORK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3894 | if (tgt->tgt_stop) |
| 3895 | goto out_term; |
| 3896 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3897 | if (cmd->aborted) { |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 3898 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082, |
| 3899 | "cmd with tag %u is aborted\n", |
| 3900 | cmd->atio.u.isp24.exchange_addr); |
| 3901 | goto out_term; |
| 3902 | } |
| 3903 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3904 | spin_lock_init(&cmd->cmd_lock); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3905 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 3906 | cmd->se_cmd.tag = atio->u.isp24.exchange_addr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3907 | cmd->unpacked_lun = scsilun_to_int( |
| 3908 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); |
| 3909 | |
| 3910 | if (atio->u.isp24.fcp_cmnd.rddata && |
| 3911 | atio->u.isp24.fcp_cmnd.wrdata) { |
| 3912 | bidi = 1; |
| 3913 | data_dir = DMA_TO_DEVICE; |
| 3914 | } else if (atio->u.isp24.fcp_cmnd.rddata) |
| 3915 | data_dir = DMA_FROM_DEVICE; |
| 3916 | else if (atio->u.isp24.fcp_cmnd.wrdata) |
| 3917 | data_dir = DMA_TO_DEVICE; |
| 3918 | else |
| 3919 | data_dir = DMA_NONE; |
| 3920 | |
| 3921 | fcp_task_attr = qlt_get_fcp_task_attr(vha, |
| 3922 | atio->u.isp24.fcp_cmnd.task_attr); |
| 3923 | data_length = be32_to_cpu(get_unaligned((uint32_t *) |
| 3924 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 3925 | atio->u.isp24.fcp_cmnd.add_cdb_len])); |
| 3926 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3927 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
| 3928 | fcp_task_attr, data_dir, bidi); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3929 | if (ret != 0) |
| 3930 | goto out_term; |
| 3931 | /* |
| 3932 | * Drop extra session reference from qla_tgt_handle_cmd_for_atio*( |
| 3933 | */ |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3934 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3935 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3936 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3937 | return; |
| 3938 | |
| 3939 | out_term: |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3940 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3941 | /* |
Roland Dreier | fae9eaf | 2012-06-11 18:23:16 -0700 | [diff] [blame] | 3942 | * cmd has not sent to target yet, so pass NULL as the second |
| 3943 | * argument to qlt_send_term_exchange() and free the memory here. |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3944 | */ |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3945 | cmd->trc_flags |= TRC_DO_WORK_ERR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3946 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3947 | qlt_send_term_exchange(vha, NULL, &cmd->atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3948 | |
| 3949 | qlt_decr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3950 | 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] | 3951 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3952 | |
| 3953 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3954 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3955 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3956 | } |
| 3957 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3958 | static void qlt_do_work(struct work_struct *work) |
| 3959 | { |
| 3960 | 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] | 3961 | scsi_qla_host_t *vha = cmd->vha; |
| 3962 | unsigned long flags; |
| 3963 | |
| 3964 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 3965 | list_del(&cmd->cmd_list); |
| 3966 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3967 | |
| 3968 | __qlt_do_work(cmd); |
| 3969 | } |
| 3970 | |
| 3971 | 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] | 3972 | struct fc_port *sess, |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3973 | struct atio_from_isp *atio) |
| 3974 | { |
| 3975 | struct se_session *se_sess = sess->se_sess; |
| 3976 | struct qla_tgt_cmd *cmd; |
| 3977 | int tag; |
| 3978 | |
| 3979 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 3980 | if (tag < 0) |
| 3981 | return NULL; |
| 3982 | |
| 3983 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 3984 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 3985 | |
| 3986 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 3987 | cmd->state = QLA_TGT_STATE_NEW; |
| 3988 | cmd->tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3989 | qlt_incr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3990 | cmd->vha = vha; |
| 3991 | cmd->se_cmd.map_tag = tag; |
| 3992 | cmd->sess = sess; |
| 3993 | cmd->loop_id = sess->loop_id; |
| 3994 | cmd->conf_compl_supported = sess->conf_compl_supported; |
| 3995 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3996 | cmd->trc_flags = 0; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 3997 | cmd->jiffies_at_alloc = get_jiffies_64(); |
| 3998 | |
| 3999 | cmd->reset_count = vha->hw->chip_reset; |
| 4000 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4001 | return cmd; |
| 4002 | } |
| 4003 | |
| 4004 | static void qlt_send_busy(struct scsi_qla_host *, struct atio_from_isp *, |
| 4005 | uint16_t); |
| 4006 | |
| 4007 | static void qlt_create_sess_from_atio(struct work_struct *work) |
| 4008 | { |
| 4009 | struct qla_tgt_sess_op *op = container_of(work, |
| 4010 | struct qla_tgt_sess_op, work); |
| 4011 | scsi_qla_host_t *vha = op->vha; |
| 4012 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4013 | struct fc_port *sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4014 | struct qla_tgt_cmd *cmd; |
| 4015 | unsigned long flags; |
| 4016 | uint8_t *s_id = op->atio.u.isp24.fcp_hdr.s_id; |
| 4017 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4018 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4019 | list_del(&op->cmd_list); |
| 4020 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 4021 | |
| 4022 | if (op->aborted) { |
| 4023 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf083, |
| 4024 | "sess_op with tag %u is aborted\n", |
| 4025 | op->atio.u.isp24.exchange_addr); |
| 4026 | goto out_term; |
| 4027 | } |
| 4028 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4029 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf022, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4030 | "qla_target(%d): Unable to find wwn login" |
| 4031 | " (s_id %x:%x:%x), trying to create it manually\n", |
| 4032 | vha->vp_idx, s_id[0], s_id[1], s_id[2]); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4033 | |
| 4034 | if (op->atio.u.raw.entry_count > 1) { |
| 4035 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf023, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4036 | "Dropping multy entry atio %p\n", &op->atio); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4037 | goto out_term; |
| 4038 | } |
| 4039 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4040 | sess = qlt_make_local_sess(vha, s_id); |
| 4041 | /* sess has an extra creation ref. */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4042 | |
| 4043 | if (!sess) |
| 4044 | goto out_term; |
| 4045 | /* |
| 4046 | * Now obtain a pre-allocated session tag using the original op->atio |
| 4047 | * packet header, and dispatch into __qlt_do_work() using the existing |
| 4048 | * process context. |
| 4049 | */ |
| 4050 | cmd = qlt_get_tag(vha, sess, &op->atio); |
| 4051 | if (!cmd) { |
| 4052 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4053 | qlt_send_busy(vha, &op->atio, SAM_STAT_BUSY); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4054 | ha->tgt.tgt_ops->put_sess(sess); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4055 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4056 | kfree(op); |
| 4057 | return; |
| 4058 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4059 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4060 | /* |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 4061 | * __qlt_do_work() will call qlt_put_sess() to release |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4062 | * the extra reference taken above by qlt_make_local_sess() |
| 4063 | */ |
| 4064 | __qlt_do_work(cmd); |
| 4065 | kfree(op); |
| 4066 | return; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4067 | out_term: |
| 4068 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4069 | qlt_send_term_exchange(vha, NULL, &op->atio, 1, 0); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4070 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4071 | kfree(op); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4072 | } |
| 4073 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4074 | /* ha->hardware_lock supposed to be held on entry */ |
| 4075 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, |
| 4076 | struct atio_from_isp *atio) |
| 4077 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4078 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4079 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4080 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4081 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4082 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4083 | |
| 4084 | if (unlikely(tgt->tgt_stop)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4085 | ql_dbg(ql_dbg_io, vha, 0x3061, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4086 | "New command while device %p is shutting down\n", tgt); |
| 4087 | return -EFAULT; |
| 4088 | } |
| 4089 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4090 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id); |
| 4091 | if (unlikely(!sess)) { |
| 4092 | struct qla_tgt_sess_op *op = kzalloc(sizeof(struct qla_tgt_sess_op), |
| 4093 | GFP_ATOMIC); |
| 4094 | if (!op) |
| 4095 | return -ENOMEM; |
| 4096 | |
| 4097 | memcpy(&op->atio, atio, sizeof(*atio)); |
Himanshu Madhani | 78c2106 | 2014-09-25 06:14:44 -0400 | [diff] [blame] | 4098 | op->vha = vha; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4099 | |
| 4100 | spin_lock(&vha->cmd_list_lock); |
| 4101 | list_add_tail(&op->cmd_list, &vha->qla_sess_op_cmd_list); |
| 4102 | spin_unlock(&vha->cmd_list_lock); |
| 4103 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4104 | INIT_WORK(&op->work, qlt_create_sess_from_atio); |
| 4105 | queue_work(qla_tgt_wq, &op->work); |
| 4106 | return 0; |
| 4107 | } |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4108 | |
| 4109 | /* Another WWN used to have our s_id. Our PLOGI scheduled its |
| 4110 | * session deletion, but it's still in sess_del_work wq */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4111 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4112 | ql_dbg(ql_dbg_io, vha, 0x3061, |
| 4113 | "New command while old session %p is being deleted\n", |
| 4114 | sess); |
| 4115 | return -EFAULT; |
| 4116 | } |
| 4117 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4118 | /* |
| 4119 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. |
| 4120 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4121 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 4122 | ql_dbg(ql_dbg_tgt, vha, 0xffff, |
| 4123 | "%s: kref_get fail, %8phC oxid %x \n", |
| 4124 | __func__, sess->port_name, |
| 4125 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 4126 | return -EFAULT; |
| 4127 | } |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4128 | |
| 4129 | cmd = qlt_get_tag(vha, sess, atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4130 | if (!cmd) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4131 | ql_dbg(ql_dbg_io, vha, 0x3062, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4132 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4133 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4134 | ha->tgt.tgt_ops->put_sess(sess); |
| 4135 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4136 | return -ENOMEM; |
| 4137 | } |
| 4138 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4139 | cmd->cmd_in_wq = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4140 | cmd->trc_flags |= TRC_NEW_CMD; |
Quinn Tran | 5327c7d | 2016-02-10 18:59:14 -0500 | [diff] [blame] | 4141 | cmd->se_cmd.cpuid = ha->msix_count ? |
| 4142 | ha->tgt.rspq_vector_cpuid : WORK_CPU_UNBOUND; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4143 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4144 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4145 | list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4146 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4147 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4148 | INIT_WORK(&cmd->work, qlt_do_work); |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4149 | if (ha->msix_count) { |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4150 | if (cmd->atio.u.isp24.fcp_cmnd.rddata) |
| 4151 | queue_work_on(smp_processor_id(), qla_tgt_wq, |
| 4152 | &cmd->work); |
| 4153 | else |
| 4154 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, |
| 4155 | &cmd->work); |
| 4156 | } else { |
| 4157 | queue_work(qla_tgt_wq, &cmd->work); |
| 4158 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4159 | return 0; |
| 4160 | |
| 4161 | } |
| 4162 | |
| 4163 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4164 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4165 | int fn, void *iocb, int flags) |
| 4166 | { |
| 4167 | struct scsi_qla_host *vha = sess->vha; |
| 4168 | struct qla_hw_data *ha = vha->hw; |
| 4169 | struct qla_tgt_mgmt_cmd *mcmd; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4170 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4171 | int res; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4172 | |
| 4173 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4174 | if (!mcmd) { |
| 4175 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, |
| 4176 | "qla_target(%d): Allocation of management " |
| 4177 | "command failed, some commands and their data could " |
| 4178 | "leak\n", vha->vp_idx); |
| 4179 | return -ENOMEM; |
| 4180 | } |
| 4181 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4182 | mcmd->sess = sess; |
| 4183 | |
| 4184 | if (iocb) { |
| 4185 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4186 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4187 | } |
| 4188 | mcmd->tmr_func = fn; |
| 4189 | mcmd->flags = flags; |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 4190 | mcmd->reset_count = vha->hw->chip_reset; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4191 | |
| 4192 | switch (fn) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4193 | case QLA_TGT_LUN_RESET: |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4194 | abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id); |
| 4195 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4196 | } |
| 4197 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4198 | 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] | 4199 | if (res != 0) { |
| 4200 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000b, |
| 4201 | "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n", |
| 4202 | sess->vha->vp_idx, res); |
| 4203 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4204 | return -EFAULT; |
| 4205 | } |
| 4206 | |
| 4207 | return 0; |
| 4208 | } |
| 4209 | |
| 4210 | /* ha->hardware_lock supposed to be held on entry */ |
| 4211 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) |
| 4212 | { |
| 4213 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4214 | struct qla_hw_data *ha = vha->hw; |
| 4215 | struct qla_tgt *tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4216 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4217 | uint32_t lun, unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4218 | int fn; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4219 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4220 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4221 | tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4222 | |
| 4223 | lun = a->u.isp24.fcp_cmnd.lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4224 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4225 | |
| 4226 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4227 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4228 | a->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4229 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4230 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4231 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); |
| 4232 | |
| 4233 | if (!sess) { |
| 4234 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf024, |
| 4235 | "qla_target(%d): task mgmt fn 0x%x for " |
| 4236 | "non-existant session\n", vha->vp_idx, fn); |
| 4237 | return qlt_sched_sess_work(tgt, QLA_TGT_SESS_WORK_TM, iocb, |
| 4238 | sizeof(struct atio_from_isp)); |
| 4239 | } |
| 4240 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4241 | if (sess->deleted) |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4242 | return -EFAULT; |
| 4243 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4244 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 4245 | } |
| 4246 | |
| 4247 | /* ha->hardware_lock supposed to be held on entry */ |
| 4248 | static int __qlt_abort_task(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4249 | struct imm_ntfy_from_isp *iocb, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4250 | { |
| 4251 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4252 | struct qla_hw_data *ha = vha->hw; |
| 4253 | struct qla_tgt_mgmt_cmd *mcmd; |
| 4254 | uint32_t lun, unpacked_lun; |
| 4255 | int rc; |
| 4256 | |
| 4257 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4258 | if (mcmd == NULL) { |
| 4259 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, |
| 4260 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", |
| 4261 | vha->vp_idx, __func__); |
| 4262 | return -ENOMEM; |
| 4263 | } |
| 4264 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4265 | |
| 4266 | mcmd->sess = sess; |
| 4267 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4268 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4269 | |
| 4270 | lun = a->u.isp24.fcp_cmnd.lun; |
| 4271 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); |
Arun Easi | 80187f8 | 2014-09-25 06:14:53 -0400 | [diff] [blame] | 4272 | mcmd->reset_count = vha->hw->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4273 | mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4274 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4275 | 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] | 4276 | le16_to_cpu(iocb->u.isp2x.seq_id)); |
| 4277 | if (rc != 0) { |
| 4278 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, |
| 4279 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 4280 | vha->vp_idx, rc); |
| 4281 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4282 | return -EFAULT; |
| 4283 | } |
| 4284 | |
| 4285 | return 0; |
| 4286 | } |
| 4287 | |
| 4288 | /* ha->hardware_lock supposed to be held on entry */ |
| 4289 | static int qlt_abort_task(struct scsi_qla_host *vha, |
| 4290 | struct imm_ntfy_from_isp *iocb) |
| 4291 | { |
| 4292 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4293 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4294 | int loop_id; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4295 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4296 | |
| 4297 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); |
| 4298 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4299 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4300 | 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] | 4301 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4302 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4303 | if (sess == NULL) { |
| 4304 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, |
| 4305 | "qla_target(%d): task abort for unexisting " |
| 4306 | "session\n", vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4307 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4308 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
| 4309 | } |
| 4310 | |
| 4311 | return __qlt_abort_task(vha, iocb, sess); |
| 4312 | } |
| 4313 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4314 | void qlt_logo_completion_handler(fc_port_t *fcport, int rc) |
| 4315 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4316 | if (rc != MBS_COMMAND_COMPLETE) { |
| 4317 | ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093, |
| 4318 | "%s: se_sess %p / sess %p from" |
| 4319 | " port %8phC loop_id %#04x s_id %02x:%02x:%02x" |
| 4320 | " LOGO failed: %#x\n", |
| 4321 | __func__, |
| 4322 | fcport->se_sess, |
| 4323 | fcport, |
| 4324 | fcport->port_name, fcport->loop_id, |
| 4325 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4326 | fcport->d_id.b.al_pa, rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4327 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4328 | |
| 4329 | fcport->logout_completed = 1; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4330 | } |
| 4331 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4332 | /* |
| 4333 | * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) |
| 4334 | * |
| 4335 | * Schedules sessions with matching port_id/loop_id but different wwn for |
| 4336 | * deletion. Returns existing session with matching wwn if present. |
| 4337 | * Null otherwise. |
| 4338 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4339 | struct fc_port * |
| 4340 | 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] | 4341 | 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] | 4342 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4343 | struct fc_port *sess = NULL, *other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4344 | uint64_t other_wwn; |
| 4345 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4346 | *conflict_sess = NULL; |
| 4347 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4348 | list_for_each_entry(other_sess, &vha->vp_fcports, list) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4349 | |
| 4350 | other_wwn = wwn_to_u64(other_sess->port_name); |
| 4351 | |
| 4352 | if (wwn == other_wwn) { |
| 4353 | WARN_ON(sess); |
| 4354 | sess = other_sess; |
| 4355 | continue; |
| 4356 | } |
| 4357 | |
| 4358 | /* find other sess with nport_id collision */ |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4359 | if (port_id.b24 == other_sess->d_id.b24) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4360 | if (loop_id != other_sess->loop_id) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4361 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000c, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4362 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4363 | other_sess, other_sess->loop_id, other_wwn); |
| 4364 | |
| 4365 | /* |
| 4366 | * logout_on_delete is set by default, but another |
| 4367 | * session that has the same s_id/loop_id combo |
| 4368 | * might have cleared it when requested this session |
| 4369 | * deletion, so don't touch it |
| 4370 | */ |
| 4371 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4372 | } else { |
| 4373 | /* |
| 4374 | * Another wwn used to have our s_id/loop_id |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4375 | * kill the session, but don't free the loop_id |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4376 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4377 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xffff, |
| 4378 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4379 | other_sess, other_sess->loop_id, other_wwn); |
| 4380 | |
| 4381 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4382 | other_sess->keep_nport_handle = 1; |
| 4383 | *conflict_sess = other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4384 | qlt_schedule_sess_for_deletion(other_sess, |
| 4385 | true); |
| 4386 | } |
| 4387 | continue; |
| 4388 | } |
| 4389 | |
| 4390 | /* find other sess with nport handle collision */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4391 | if ((loop_id == other_sess->loop_id) && |
| 4392 | (loop_id != FC_NO_LOOP_ID)) { |
| 4393 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000d, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4394 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4395 | other_sess, other_sess->loop_id, other_wwn); |
| 4396 | |
| 4397 | /* Same loop_id but different s_id |
| 4398 | * Ok to kill and logout */ |
| 4399 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4400 | } |
| 4401 | } |
| 4402 | |
| 4403 | return sess; |
| 4404 | } |
| 4405 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4406 | /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */ |
| 4407 | static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id) |
| 4408 | { |
| 4409 | struct qla_tgt_sess_op *op; |
| 4410 | struct qla_tgt_cmd *cmd; |
| 4411 | uint32_t key; |
| 4412 | int count = 0; |
| 4413 | |
| 4414 | key = (((u32)s_id->b.domain << 16) | |
| 4415 | ((u32)s_id->b.area << 8) | |
| 4416 | ((u32)s_id->b.al_pa)); |
| 4417 | |
| 4418 | spin_lock(&vha->cmd_list_lock); |
| 4419 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 4420 | 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] | 4421 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4422 | if (op_key == key) { |
| 4423 | op->aborted = true; |
| 4424 | count++; |
| 4425 | } |
| 4426 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4427 | |
| 4428 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 4429 | uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 4430 | if (op_key == key) { |
| 4431 | op->aborted = true; |
| 4432 | count++; |
| 4433 | } |
| 4434 | } |
| 4435 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4436 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 4437 | uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 4438 | if (cmd_key == key) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4439 | cmd->aborted = 1; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4440 | count++; |
| 4441 | } |
| 4442 | } |
| 4443 | spin_unlock(&vha->cmd_list_lock); |
| 4444 | |
| 4445 | return count; |
| 4446 | } |
| 4447 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4448 | /* |
| 4449 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4450 | */ |
| 4451 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, |
| 4452 | struct imm_ntfy_from_isp *iocb) |
| 4453 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4454 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4455 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4456 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4457 | uint64_t wwn; |
| 4458 | port_id_t port_id; |
| 4459 | uint16_t loop_id; |
| 4460 | uint16_t wd3_lo; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4461 | int res = 0; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4462 | struct qlt_plogi_ack_t *pla; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4463 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4464 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4465 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4466 | |
| 4467 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4468 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4469 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4470 | port_id.b.rsvd_1 = 0; |
| 4471 | |
| 4472 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4473 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4474 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 4475 | "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n", |
| 4476 | vha->vp_idx, iocb->u.isp24.port_id[2], |
| 4477 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 4478 | iocb->u.isp24.status_subcode, loop_id, |
| 4479 | iocb->u.isp24.port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4480 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4481 | /* res = 1 means ack at the end of thread |
| 4482 | * res = 0 means ack async/later. |
| 4483 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4484 | switch (iocb->u.isp24.status_subcode) { |
| 4485 | case ELS_PLOGI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4486 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4487 | /* Mark all stale commands in qla_tgt_wq for deletion */ |
| 4488 | abort_cmds_for_s_id(vha, &port_id); |
| 4489 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4490 | if (wwn) { |
| 4491 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4492 | sess = qlt_find_sess_invalidate_other(vha, wwn, |
| 4493 | port_id, loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4494 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4495 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4496 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4497 | if (IS_SW_RESV_ADDR(port_id)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4498 | res = 1; |
| 4499 | break; |
| 4500 | } |
| 4501 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4502 | pla = qlt_plogi_ack_find_add(vha, &port_id, iocb); |
| 4503 | if (!pla) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4504 | qlt_send_term_imm_notif(vha, iocb, 1); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4505 | break; |
| 4506 | } |
| 4507 | |
| 4508 | res = 0; |
| 4509 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4510 | if (conflict_sess) { |
| 4511 | conflict_sess->login_gen++; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4512 | qlt_plogi_ack_link(vha, pla, conflict_sess, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4513 | QLT_PLOGI_LINK_CONFLICT); |
| 4514 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4515 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4516 | if (!sess) { |
| 4517 | pla->ref_count++; |
| 4518 | qla24xx_post_newsess_work(vha, &port_id, |
| 4519 | iocb->u.isp24.port_name, pla); |
| 4520 | res = 0; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4521 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4522 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4523 | |
| 4524 | qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4525 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
| 4526 | sess->d_id = port_id; |
| 4527 | sess->login_gen++; |
| 4528 | |
| 4529 | switch (sess->disc_state) { |
| 4530 | case DSC_DELETED: |
| 4531 | qlt_plogi_ack_unref(vha, pla); |
| 4532 | break; |
| 4533 | |
| 4534 | default: |
| 4535 | /* |
| 4536 | * Under normal circumstances we want to release nport handle |
| 4537 | * during LOGO process to avoid nport handle leaks inside FW. |
| 4538 | * The exception is when LOGO is done while another PLOGI with |
| 4539 | * the same nport handle is waiting as might be the case here. |
| 4540 | * Note: there is always a possibily of a race where session |
| 4541 | * deletion has already started for other reasons (e.g. ACL |
| 4542 | * removal) and now PLOGI arrives: |
| 4543 | * 1. if PLOGI arrived in FW after nport handle has been freed, |
| 4544 | * FW must have assigned this PLOGI a new/same handle and we |
| 4545 | * can proceed ACK'ing it as usual when session deletion |
| 4546 | * completes. |
| 4547 | * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT |
| 4548 | * bit reached it, the handle has now been released. We'll |
| 4549 | * get an error when we ACK this PLOGI. Nothing will be sent |
| 4550 | * back to initiator. Initiator should eventually retry |
| 4551 | * PLOGI and situation will correct itself. |
| 4552 | */ |
| 4553 | sess->keep_nport_handle = ((sess->loop_id == loop_id) && |
| 4554 | (sess->d_id.b24 == port_id.b24)); |
| 4555 | |
| 4556 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4557 | "%s %d %8phC post del sess\n", |
| 4558 | __func__, __LINE__, sess->port_name); |
| 4559 | |
| 4560 | |
| 4561 | qlt_schedule_sess_for_deletion_lock(sess); |
| 4562 | break; |
| 4563 | } |
| 4564 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4565 | break; |
| 4566 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4567 | case ELS_PRLI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4568 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4569 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4570 | if (wwn) { |
| 4571 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4572 | sess = qlt_find_sess_invalidate_other(vha, wwn, port_id, |
| 4573 | loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4574 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4575 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4576 | |
| 4577 | if (conflict_sess) { |
| 4578 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b, |
| 4579 | "PRLI with conflicting sess %p port %8phC\n", |
| 4580 | conflict_sess, conflict_sess->port_name); |
| 4581 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4582 | res = 0; |
| 4583 | break; |
| 4584 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4585 | |
| 4586 | if (sess != NULL) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4587 | if (sess->fw_login_state == DSC_LS_PLOGI_PEND) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4588 | /* |
| 4589 | * Impatient initiator sent PRLI before last |
| 4590 | * PLOGI could finish. Will force him to re-try, |
| 4591 | * while last one finishes. |
| 4592 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4593 | ql_log(ql_log_warn, sess->vha, 0xf095, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4594 | "sess %p PRLI received, before plogi ack.\n", |
| 4595 | sess); |
| 4596 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4597 | res = 0; |
| 4598 | break; |
| 4599 | } |
| 4600 | |
| 4601 | /* |
| 4602 | * This shouldn't happen under normal circumstances, |
| 4603 | * since we have deleted the old session during PLOGI |
| 4604 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4605 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4606 | "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n", |
| 4607 | sess->loop_id, sess, iocb->u.isp24.nport_handle); |
| 4608 | |
| 4609 | sess->local = 0; |
| 4610 | sess->loop_id = loop_id; |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4611 | sess->d_id = port_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4612 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4613 | |
| 4614 | if (wd3_lo & BIT_7) |
| 4615 | sess->conf_compl_supported = 1; |
| 4616 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4617 | if ((wd3_lo & BIT_4) == 0) |
| 4618 | sess->port_type = FCT_INITIATOR; |
| 4619 | else |
| 4620 | sess->port_type = FCT_TARGET; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4621 | } |
| 4622 | res = 1; /* send notify ack */ |
| 4623 | |
| 4624 | /* Make session global (not used in fabric mode) */ |
| 4625 | if (ha->current_topology != ISP_CFG_F) { |
| 4626 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4627 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4628 | qla2xxx_wake_dpc(vha); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4629 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4630 | if (sess) { |
| 4631 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4632 | "%s %d %8phC post nack\n", |
| 4633 | __func__, __LINE__, sess->port_name); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4634 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4635 | qla24xx_post_nack_work(vha, sess, iocb, |
| 4636 | SRB_NACK_PRLI); |
| 4637 | res = 0; |
| 4638 | } |
| 4639 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4640 | break; |
| 4641 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4642 | |
| 4643 | case ELS_TPRLO: |
| 4644 | if (le16_to_cpu(iocb->u.isp24.flags) & |
| 4645 | NOTIFY24XX_FLAGS_GLOBAL_TPRLO) { |
| 4646 | loop_id = 0xFFFF; |
| 4647 | qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS); |
| 4648 | res = 1; |
| 4649 | break; |
| 4650 | } |
| 4651 | /* drop through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4652 | case ELS_LOGO: |
| 4653 | case ELS_PRLO: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4654 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4655 | sess = qla2x00_find_fcport_by_loopid(vha, loop_id); |
| 4656 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4657 | |
| 4658 | if (sess) { |
| 4659 | sess->login_gen++; |
| 4660 | sess->fw_login_state = DSC_LS_LOGO_PEND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4661 | sess->logo_ack_needed = 1; |
| 4662 | memcpy(sess->iocb, iocb, IOCB_SIZE); |
| 4663 | } |
| 4664 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4665 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4666 | |
| 4667 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4668 | "%s: logo %llx res %d sess %p ", |
| 4669 | __func__, wwn, res, sess); |
| 4670 | if (res == 0) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4671 | /* |
| 4672 | * cmd went upper layer, look for qlt_xmit_tm_rsp() |
| 4673 | * for LOGO_ACK & sess delete |
| 4674 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4675 | BUG_ON(!sess); |
| 4676 | res = 0; |
| 4677 | } else { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4678 | /* cmd did not go to upper layer. */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4679 | if (sess) { |
| 4680 | qlt_schedule_sess_for_deletion_lock(sess); |
| 4681 | res = 0; |
| 4682 | } |
| 4683 | /* else logo will be ack */ |
| 4684 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4685 | break; |
| 4686 | case ELS_PDISC: |
| 4687 | case ELS_ADISC: |
| 4688 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4689 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4690 | if (tgt->link_reinit_iocb_pending) { |
| 4691 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, |
| 4692 | 0, 0, 0, 0, 0, 0); |
| 4693 | tgt->link_reinit_iocb_pending = 0; |
| 4694 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4695 | |
| 4696 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 4697 | iocb->u.isp24.port_name, 1); |
| 4698 | if (sess) { |
| 4699 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4700 | "sess %p lid %d|%d DS %d LS %d\n", |
| 4701 | sess, sess->loop_id, loop_id, |
| 4702 | sess->disc_state, sess->fw_login_state); |
| 4703 | } |
| 4704 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4705 | res = 1; /* send notify ack */ |
| 4706 | break; |
| 4707 | } |
| 4708 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4709 | case ELS_FLOGI: /* should never happen */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4710 | default: |
| 4711 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, |
| 4712 | "qla_target(%d): Unsupported ELS command %x " |
| 4713 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); |
| 4714 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 4715 | break; |
| 4716 | } |
| 4717 | |
| 4718 | return res; |
| 4719 | } |
| 4720 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4721 | /* |
| 4722 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4723 | */ |
| 4724 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, |
| 4725 | struct imm_ntfy_from_isp *iocb) |
| 4726 | { |
| 4727 | struct qla_hw_data *ha = vha->hw; |
| 4728 | uint32_t add_flags = 0; |
| 4729 | int send_notify_ack = 1; |
| 4730 | uint16_t status; |
| 4731 | |
| 4732 | status = le16_to_cpu(iocb->u.isp2x.status); |
| 4733 | switch (status) { |
| 4734 | case IMM_NTFY_LIP_RESET: |
| 4735 | { |
| 4736 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, |
| 4737 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", |
| 4738 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4739 | iocb->u.isp24.status_subcode); |
| 4740 | |
| 4741 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 4742 | send_notify_ack = 0; |
| 4743 | break; |
| 4744 | } |
| 4745 | |
| 4746 | case IMM_NTFY_LIP_LINK_REINIT: |
| 4747 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4748 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4749 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
| 4750 | "qla_target(%d): LINK REINIT (loop %#x, " |
| 4751 | "subcode %x)\n", vha->vp_idx, |
| 4752 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4753 | iocb->u.isp24.status_subcode); |
| 4754 | if (tgt->link_reinit_iocb_pending) { |
| 4755 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, |
| 4756 | 0, 0, 0, 0, 0, 0); |
| 4757 | } |
| 4758 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); |
| 4759 | tgt->link_reinit_iocb_pending = 1; |
| 4760 | /* |
| 4761 | * QLogic requires to wait after LINK REINIT for possible |
| 4762 | * PDISC or ADISC ELS commands |
| 4763 | */ |
| 4764 | send_notify_ack = 0; |
| 4765 | break; |
| 4766 | } |
| 4767 | |
| 4768 | case IMM_NTFY_PORT_LOGOUT: |
| 4769 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, |
| 4770 | "qla_target(%d): Port logout (loop " |
| 4771 | "%#x, subcode %x)\n", vha->vp_idx, |
| 4772 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4773 | iocb->u.isp24.status_subcode); |
| 4774 | |
| 4775 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) |
| 4776 | send_notify_ack = 0; |
| 4777 | /* The sessions will be cleared in the callback, if needed */ |
| 4778 | break; |
| 4779 | |
| 4780 | case IMM_NTFY_GLBL_TPRLO: |
| 4781 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, |
| 4782 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); |
| 4783 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 4784 | send_notify_ack = 0; |
| 4785 | /* The sessions will be cleared in the callback, if needed */ |
| 4786 | break; |
| 4787 | |
| 4788 | case IMM_NTFY_PORT_CONFIG: |
| 4789 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, |
| 4790 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, |
| 4791 | status); |
| 4792 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 4793 | send_notify_ack = 0; |
| 4794 | /* The sessions will be cleared in the callback, if needed */ |
| 4795 | break; |
| 4796 | |
| 4797 | case IMM_NTFY_GLBL_LOGO: |
| 4798 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, |
| 4799 | "qla_target(%d): Link failure detected\n", |
| 4800 | vha->vp_idx); |
| 4801 | /* I_T nexus loss */ |
| 4802 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 4803 | send_notify_ack = 0; |
| 4804 | break; |
| 4805 | |
| 4806 | case IMM_NTFY_IOCB_OVERFLOW: |
| 4807 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, |
| 4808 | "qla_target(%d): Cannot provide requested " |
| 4809 | "capability (IOCB overflowed the immediate notify " |
| 4810 | "resource count)\n", vha->vp_idx); |
| 4811 | break; |
| 4812 | |
| 4813 | case IMM_NTFY_ABORT_TASK: |
| 4814 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, |
| 4815 | "qla_target(%d): Abort Task (S %08x I %#x -> " |
| 4816 | "L %#x)\n", vha->vp_idx, |
| 4817 | le16_to_cpu(iocb->u.isp2x.seq_id), |
| 4818 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), |
| 4819 | le16_to_cpu(iocb->u.isp2x.lun)); |
| 4820 | if (qlt_abort_task(vha, iocb) == 0) |
| 4821 | send_notify_ack = 0; |
| 4822 | break; |
| 4823 | |
| 4824 | case IMM_NTFY_RESOURCE: |
| 4825 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, |
| 4826 | "qla_target(%d): Out of resources, host %ld\n", |
| 4827 | vha->vp_idx, vha->host_no); |
| 4828 | break; |
| 4829 | |
| 4830 | case IMM_NTFY_MSG_RX: |
| 4831 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, |
| 4832 | "qla_target(%d): Immediate notify task %x\n", |
| 4833 | vha->vp_idx, iocb->u.isp2x.task_flags); |
| 4834 | if (qlt_handle_task_mgmt(vha, iocb) == 0) |
| 4835 | send_notify_ack = 0; |
| 4836 | break; |
| 4837 | |
| 4838 | case IMM_NTFY_ELS: |
| 4839 | if (qlt_24xx_handle_els(vha, iocb) == 0) |
| 4840 | send_notify_ack = 0; |
| 4841 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4842 | default: |
| 4843 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, |
| 4844 | "qla_target(%d): Received unknown immediate " |
| 4845 | "notify status %x\n", vha->vp_idx, status); |
| 4846 | break; |
| 4847 | } |
| 4848 | |
| 4849 | if (send_notify_ack) |
| 4850 | qlt_send_notify_ack(vha, iocb, add_flags, 0, 0, 0, 0, 0); |
| 4851 | } |
| 4852 | |
| 4853 | /* |
| 4854 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4855 | * This function sends busy to ISP 2xxx or 24xx. |
| 4856 | */ |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4857 | static int __qlt_send_busy(struct scsi_qla_host *vha, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4858 | struct atio_from_isp *atio, uint16_t status) |
| 4859 | { |
| 4860 | struct ctio7_to_24xx *ctio24; |
| 4861 | struct qla_hw_data *ha = vha->hw; |
| 4862 | request_t *pkt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4863 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4864 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4865 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4866 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4867 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4868 | atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4869 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4870 | if (!sess) { |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4871 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4872 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4873 | } |
| 4874 | /* Sending marker isn't necessary, since we called from ISR */ |
| 4875 | |
| 4876 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
| 4877 | if (!pkt) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4878 | ql_dbg(ql_dbg_io, vha, 0x3063, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4879 | "qla_target(%d): %s failed: unable to allocate " |
| 4880 | "request packet", vha->vp_idx, __func__); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4881 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4882 | } |
| 4883 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 4884 | vha->tgt_counters.num_q_full_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4885 | pkt->entry_count = 1; |
| 4886 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 4887 | |
| 4888 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 4889 | ctio24->entry_type = CTIO_TYPE7; |
| 4890 | ctio24->nport_handle = sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4891 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4892 | ctio24->vp_index = vha->vp_idx; |
| 4893 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 4894 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 4895 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 4896 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
| 4897 | ctio24->u.status1.flags = (atio->u.isp24.attr << 9) | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4898 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4899 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | |
| 4900 | CTIO7_FLAGS_DONT_RET_CTIO); |
| 4901 | /* |
| 4902 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, |
| 4903 | * if the explicit conformation is used. |
| 4904 | */ |
| 4905 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); |
| 4906 | ctio24->u.status1.scsi_status = cpu_to_le16(status); |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 4907 | /* Memory Barrier */ |
| 4908 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4909 | qla2x00_start_iocbs(vha, vha->req); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4910 | return 0; |
| 4911 | } |
| 4912 | |
| 4913 | /* |
| 4914 | * This routine is used to allocate a command for either a QFull condition |
| 4915 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go |
| 4916 | * out previously. |
| 4917 | */ |
| 4918 | static void |
| 4919 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 4920 | struct atio_from_isp *atio, uint16_t status, int qfull) |
| 4921 | { |
| 4922 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4923 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4924 | struct fc_port *sess; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4925 | struct se_session *se_sess; |
| 4926 | struct qla_tgt_cmd *cmd; |
| 4927 | int tag; |
| 4928 | |
| 4929 | if (unlikely(tgt->tgt_stop)) { |
| 4930 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 4931 | "New command while device %p is shutting down\n", tgt); |
| 4932 | return; |
| 4933 | } |
| 4934 | |
| 4935 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { |
| 4936 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 4937 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 4938 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 4939 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4940 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 4941 | |
| 4942 | ql_dbg(ql_dbg_io, vha, 0x3068, |
| 4943 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", |
| 4944 | vha->vp_idx, __func__, |
| 4945 | vha->hw->tgt.num_qfull_cmds_dropped); |
| 4946 | |
| 4947 | qlt_chk_exch_leak_thresh_hold(vha); |
| 4948 | return; |
| 4949 | } |
| 4950 | |
| 4951 | sess = ha->tgt.tgt_ops->find_sess_by_s_id |
| 4952 | (vha, atio->u.isp24.fcp_hdr.s_id); |
| 4953 | if (!sess) |
| 4954 | return; |
| 4955 | |
| 4956 | se_sess = sess->se_sess; |
| 4957 | |
| 4958 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 4959 | if (tag < 0) |
| 4960 | return; |
| 4961 | |
| 4962 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 4963 | if (!cmd) { |
| 4964 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 4965 | "qla_target(%d): %s: Allocation of cmd failed\n", |
| 4966 | vha->vp_idx, __func__); |
| 4967 | |
| 4968 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 4969 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 4970 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 4971 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4972 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 4973 | |
| 4974 | qlt_chk_exch_leak_thresh_hold(vha); |
| 4975 | return; |
| 4976 | } |
| 4977 | |
| 4978 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 4979 | |
| 4980 | qlt_incr_num_pend_cmds(vha); |
| 4981 | INIT_LIST_HEAD(&cmd->cmd_list); |
| 4982 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 4983 | |
| 4984 | cmd->tgt = vha->vha_tgt.qla_tgt; |
| 4985 | cmd->vha = vha; |
| 4986 | cmd->reset_count = vha->hw->chip_reset; |
| 4987 | cmd->q_full = 1; |
| 4988 | |
| 4989 | if (qfull) { |
| 4990 | cmd->q_full = 1; |
| 4991 | /* NOTE: borrowing the state field to carry the status */ |
| 4992 | cmd->state = status; |
| 4993 | } else |
| 4994 | cmd->term_exchg = 1; |
| 4995 | |
| 4996 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); |
| 4997 | |
| 4998 | vha->hw->tgt.num_qfull_cmds_alloc++; |
| 4999 | if (vha->hw->tgt.num_qfull_cmds_alloc > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5000 | vha->qla_stats.stat_max_qfull_cmds_alloc) |
| 5001 | vha->qla_stats.stat_max_qfull_cmds_alloc = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5002 | vha->hw->tgt.num_qfull_cmds_alloc; |
| 5003 | } |
| 5004 | |
| 5005 | int |
| 5006 | qlt_free_qfull_cmds(struct scsi_qla_host *vha) |
| 5007 | { |
| 5008 | struct qla_hw_data *ha = vha->hw; |
| 5009 | unsigned long flags; |
| 5010 | struct qla_tgt_cmd *cmd, *tcmd; |
| 5011 | struct list_head free_list; |
| 5012 | int rc = 0; |
| 5013 | |
| 5014 | if (list_empty(&ha->tgt.q_full_list)) |
| 5015 | return 0; |
| 5016 | |
| 5017 | INIT_LIST_HEAD(&free_list); |
| 5018 | |
| 5019 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 5020 | |
| 5021 | if (list_empty(&ha->tgt.q_full_list)) { |
| 5022 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 5023 | return 0; |
| 5024 | } |
| 5025 | |
| 5026 | list_for_each_entry_safe(cmd, tcmd, &ha->tgt.q_full_list, cmd_list) { |
| 5027 | if (cmd->q_full) |
| 5028 | /* cmd->state is a borrowed field to hold status */ |
| 5029 | rc = __qlt_send_busy(vha, &cmd->atio, cmd->state); |
| 5030 | else if (cmd->term_exchg) |
| 5031 | rc = __qlt_send_term_exchange(vha, NULL, &cmd->atio); |
| 5032 | |
| 5033 | if (rc == -ENOMEM) |
| 5034 | break; |
| 5035 | |
| 5036 | if (cmd->q_full) |
| 5037 | ql_dbg(ql_dbg_io, vha, 0x3006, |
| 5038 | "%s: busy sent for ox_id[%04x]\n", __func__, |
| 5039 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5040 | else if (cmd->term_exchg) |
| 5041 | ql_dbg(ql_dbg_io, vha, 0x3007, |
| 5042 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, |
| 5043 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5044 | else |
| 5045 | ql_dbg(ql_dbg_io, vha, 0x3008, |
| 5046 | "%s: Unexpected cmd in QFull list %p\n", __func__, |
| 5047 | cmd); |
| 5048 | |
| 5049 | list_del(&cmd->cmd_list); |
| 5050 | list_add_tail(&cmd->cmd_list, &free_list); |
| 5051 | |
| 5052 | /* piggy back on hardware_lock for protection */ |
| 5053 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 5054 | } |
| 5055 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 5056 | |
| 5057 | cmd = NULL; |
| 5058 | |
| 5059 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 5060 | list_del(&cmd->cmd_list); |
| 5061 | /* This cmd was never sent to TCM. There is no need |
| 5062 | * to schedule free or call free_cmd |
| 5063 | */ |
| 5064 | qlt_free_cmd(cmd); |
| 5065 | } |
| 5066 | return rc; |
| 5067 | } |
| 5068 | |
| 5069 | static void |
| 5070 | qlt_send_busy(struct scsi_qla_host *vha, |
| 5071 | struct atio_from_isp *atio, uint16_t status) |
| 5072 | { |
| 5073 | int rc = 0; |
| 5074 | |
| 5075 | rc = __qlt_send_busy(vha, atio, status); |
| 5076 | if (rc == -ENOMEM) |
| 5077 | qlt_alloc_qfull_cmd(vha, atio, status, 1); |
| 5078 | } |
| 5079 | |
| 5080 | static int |
| 5081 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame^] | 5082 | struct atio_from_isp *atio, bool ha_locked) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5083 | { |
| 5084 | struct qla_hw_data *ha = vha->hw; |
| 5085 | uint16_t status; |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame^] | 5086 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5087 | |
| 5088 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) |
| 5089 | return 0; |
| 5090 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame^] | 5091 | if (!ha_locked) |
| 5092 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5093 | status = temp_sam_status; |
| 5094 | qlt_send_busy(vha, atio, status); |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame^] | 5095 | if (!ha_locked) |
| 5096 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5097 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5098 | return 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5099 | } |
| 5100 | |
| 5101 | /* ha->hardware_lock supposed to be held on entry */ |
| 5102 | /* called via callback from qla2xxx */ |
| 5103 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5104 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5105 | { |
| 5106 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5107 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5108 | int rc; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5109 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5110 | |
| 5111 | if (unlikely(tgt == NULL)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5112 | ql_dbg(ql_dbg_io, vha, 0x3064, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5113 | "ATIO pkt, but no tgt (ha %p)", ha); |
| 5114 | return; |
| 5115 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5116 | /* |
| 5117 | * In tgt_stop mode we also should allow all requests to pass. |
| 5118 | * Otherwise, some commands can stuck. |
| 5119 | */ |
| 5120 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5121 | tgt->atio_irq_cmd_count++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5122 | |
| 5123 | switch (atio->u.raw.entry_type) { |
| 5124 | case ATIO_TYPE7: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5125 | if (unlikely(atio->u.isp24.exchange_addr == |
| 5126 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5127 | ql_dbg(ql_dbg_io, vha, 0x3065, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5128 | "qla_target(%d): ATIO_TYPE7 " |
| 5129 | "received with UNKNOWN exchange address, " |
| 5130 | "sending QUEUE_FULL\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5131 | if (!ha_locked) |
| 5132 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5133 | qlt_send_busy(vha, atio, SAM_STAT_TASK_SET_FULL); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5134 | if (!ha_locked) |
| 5135 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5136 | break; |
| 5137 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5138 | |
| 5139 | |
| 5140 | |
| 5141 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame^] | 5142 | rc = qlt_chk_qfull_thresh_hold(vha, atio, ha_locked); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5143 | if (rc != 0) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5144 | tgt->atio_irq_cmd_count--; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5145 | return; |
| 5146 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5147 | rc = qlt_handle_cmd_for_atio(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5148 | } else { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5149 | rc = qlt_handle_task_mgmt(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5150 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5151 | if (unlikely(rc != 0)) { |
| 5152 | if (rc == -ESRCH) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5153 | if (!ha_locked) |
| 5154 | spin_lock_irqsave |
| 5155 | (&ha->hardware_lock, flags); |
| 5156 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5157 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
| 5158 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); |
| 5159 | #else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5160 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5161 | #endif |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5162 | |
| 5163 | if (!ha_locked) |
| 5164 | spin_unlock_irqrestore |
| 5165 | (&ha->hardware_lock, flags); |
| 5166 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5167 | } else { |
| 5168 | if (tgt->tgt_stop) { |
| 5169 | ql_dbg(ql_dbg_tgt, vha, 0xe059, |
| 5170 | "qla_target: Unable to send " |
| 5171 | "command to target for req, " |
| 5172 | "ignoring.\n"); |
| 5173 | } else { |
| 5174 | ql_dbg(ql_dbg_tgt, vha, 0xe05a, |
| 5175 | "qla_target(%d): Unable to send " |
| 5176 | "command to target, sending BUSY " |
| 5177 | "status.\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5178 | if (!ha_locked) |
| 5179 | spin_lock_irqsave( |
| 5180 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5181 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5182 | if (!ha_locked) |
| 5183 | spin_unlock_irqrestore( |
| 5184 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5185 | } |
| 5186 | } |
| 5187 | } |
| 5188 | break; |
| 5189 | |
| 5190 | case IMMED_NOTIFY_TYPE: |
| 5191 | { |
| 5192 | if (unlikely(atio->u.isp2x.entry_status != 0)) { |
| 5193 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, |
| 5194 | "qla_target(%d): Received ATIO packet %x " |
| 5195 | "with error status %x\n", vha->vp_idx, |
| 5196 | atio->u.raw.entry_type, |
| 5197 | atio->u.isp2x.entry_status); |
| 5198 | break; |
| 5199 | } |
| 5200 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5201 | |
| 5202 | if (!ha_locked) |
| 5203 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5204 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5205 | if (!ha_locked) |
| 5206 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5207 | break; |
| 5208 | } |
| 5209 | |
| 5210 | default: |
| 5211 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, |
| 5212 | "qla_target(%d): Received unknown ATIO atio " |
| 5213 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 5214 | break; |
| 5215 | } |
| 5216 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5217 | tgt->atio_irq_cmd_count--; |
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_response_pkt(struct scsi_qla_host *vha, response_t *pkt) |
| 5223 | { |
| 5224 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5225 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5226 | |
| 5227 | if (unlikely(tgt == NULL)) { |
| 5228 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, |
| 5229 | "qla_target(%d): Response pkt %x received, but no " |
| 5230 | "tgt (ha %p)\n", vha->vp_idx, pkt->entry_type, ha); |
| 5231 | return; |
| 5232 | } |
| 5233 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5234 | /* |
| 5235 | * In tgt_stop mode we also should allow all requests to pass. |
| 5236 | * Otherwise, some commands can stuck. |
| 5237 | */ |
| 5238 | |
| 5239 | tgt->irq_cmd_count++; |
| 5240 | |
| 5241 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 5242 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5243 | case CTIO_TYPE7: |
| 5244 | { |
| 5245 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5246 | qlt_do_ctio_completion(vha, entry->handle, |
| 5247 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5248 | entry); |
| 5249 | break; |
| 5250 | } |
| 5251 | |
| 5252 | case ACCEPT_TGT_IO_TYPE: |
| 5253 | { |
| 5254 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; |
| 5255 | int rc; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5256 | if (atio->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5257 | cpu_to_le16(ATIO_CDB_VALID)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5258 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, |
| 5259 | "qla_target(%d): ATIO with error " |
| 5260 | "status %x received\n", vha->vp_idx, |
| 5261 | le16_to_cpu(atio->u.isp2x.status)); |
| 5262 | break; |
| 5263 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5264 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame^] | 5265 | rc = qlt_chk_qfull_thresh_hold(vha, atio, true); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5266 | if (rc != 0) { |
| 5267 | tgt->irq_cmd_count--; |
| 5268 | return; |
| 5269 | } |
| 5270 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5271 | rc = qlt_handle_cmd_for_atio(vha, atio); |
| 5272 | if (unlikely(rc != 0)) { |
| 5273 | if (rc == -ESRCH) { |
| 5274 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
| 5275 | qlt_send_busy(vha, atio, 0); |
| 5276 | #else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5277 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5278 | #endif |
| 5279 | } else { |
| 5280 | if (tgt->tgt_stop) { |
| 5281 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5282 | "qla_target: Unable to send " |
| 5283 | "command to target, sending TERM " |
| 5284 | "EXCHANGE for rsp\n"); |
| 5285 | qlt_send_term_exchange(vha, NULL, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5286 | atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5287 | } else { |
| 5288 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5289 | "qla_target(%d): Unable to send " |
| 5290 | "command to target, sending BUSY " |
| 5291 | "status\n", vha->vp_idx); |
| 5292 | qlt_send_busy(vha, atio, 0); |
| 5293 | } |
| 5294 | } |
| 5295 | } |
| 5296 | } |
| 5297 | break; |
| 5298 | |
| 5299 | case CONTINUE_TGT_IO_TYPE: |
| 5300 | { |
| 5301 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5302 | qlt_do_ctio_completion(vha, entry->handle, |
| 5303 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5304 | entry); |
| 5305 | break; |
| 5306 | } |
| 5307 | |
| 5308 | case CTIO_A64_TYPE: |
| 5309 | { |
| 5310 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5311 | qlt_do_ctio_completion(vha, entry->handle, |
| 5312 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5313 | entry); |
| 5314 | break; |
| 5315 | } |
| 5316 | |
| 5317 | case IMMED_NOTIFY_TYPE: |
| 5318 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); |
| 5319 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); |
| 5320 | break; |
| 5321 | |
| 5322 | case NOTIFY_ACK_TYPE: |
| 5323 | if (tgt->notify_ack_expected > 0) { |
| 5324 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 5325 | ql_dbg(ql_dbg_tgt, vha, 0xe036, |
| 5326 | "NOTIFY_ACK seq %08x status %x\n", |
| 5327 | le16_to_cpu(entry->u.isp2x.seq_id), |
| 5328 | le16_to_cpu(entry->u.isp2x.status)); |
| 5329 | tgt->notify_ack_expected--; |
| 5330 | if (entry->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5331 | cpu_to_le16(NOTIFY_ACK_SUCCESS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5332 | ql_dbg(ql_dbg_tgt, vha, 0xe061, |
| 5333 | "qla_target(%d): NOTIFY_ACK " |
| 5334 | "failed %x\n", vha->vp_idx, |
| 5335 | le16_to_cpu(entry->u.isp2x.status)); |
| 5336 | } |
| 5337 | } else { |
| 5338 | ql_dbg(ql_dbg_tgt, vha, 0xe062, |
| 5339 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", |
| 5340 | vha->vp_idx); |
| 5341 | } |
| 5342 | break; |
| 5343 | |
| 5344 | case ABTS_RECV_24XX: |
| 5345 | ql_dbg(ql_dbg_tgt, vha, 0xe037, |
| 5346 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); |
| 5347 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); |
| 5348 | break; |
| 5349 | |
| 5350 | case ABTS_RESP_24XX: |
| 5351 | if (tgt->abts_resp_expected > 0) { |
| 5352 | struct abts_resp_from_24xx_fw *entry = |
| 5353 | (struct abts_resp_from_24xx_fw *)pkt; |
| 5354 | ql_dbg(ql_dbg_tgt, vha, 0xe038, |
| 5355 | "ABTS_RESP_24XX: compl_status %x\n", |
| 5356 | entry->compl_status); |
| 5357 | tgt->abts_resp_expected--; |
| 5358 | if (le16_to_cpu(entry->compl_status) != |
| 5359 | ABTS_RESP_COMPL_SUCCESS) { |
| 5360 | if ((entry->error_subcode1 == 0x1E) && |
| 5361 | (entry->error_subcode2 == 0)) { |
| 5362 | /* |
| 5363 | * We've got a race here: aborted |
| 5364 | * exchange not terminated, i.e. |
| 5365 | * response for the aborted command was |
| 5366 | * sent between the abort request was |
| 5367 | * received and processed. |
| 5368 | * Unfortunately, the firmware has a |
| 5369 | * silly requirement that all aborted |
| 5370 | * exchanges must be explicitely |
| 5371 | * terminated, otherwise it refuses to |
| 5372 | * send responses for the abort |
| 5373 | * requests. So, we have to |
| 5374 | * (re)terminate the exchange and retry |
| 5375 | * the abort response. |
| 5376 | */ |
| 5377 | qlt_24xx_retry_term_exchange(vha, |
| 5378 | entry); |
| 5379 | } else |
| 5380 | ql_dbg(ql_dbg_tgt, vha, 0xe063, |
| 5381 | "qla_target(%d): ABTS_RESP_24XX " |
| 5382 | "failed %x (subcode %x:%x)", |
| 5383 | vha->vp_idx, entry->compl_status, |
| 5384 | entry->error_subcode1, |
| 5385 | entry->error_subcode2); |
| 5386 | } |
| 5387 | } else { |
| 5388 | ql_dbg(ql_dbg_tgt, vha, 0xe064, |
| 5389 | "qla_target(%d): Unexpected ABTS_RESP_24XX " |
| 5390 | "received\n", vha->vp_idx); |
| 5391 | } |
| 5392 | break; |
| 5393 | |
| 5394 | default: |
| 5395 | ql_dbg(ql_dbg_tgt, vha, 0xe065, |
| 5396 | "qla_target(%d): Received unknown response pkt " |
| 5397 | "type %x\n", vha->vp_idx, pkt->entry_type); |
| 5398 | break; |
| 5399 | } |
| 5400 | |
| 5401 | tgt->irq_cmd_count--; |
| 5402 | } |
| 5403 | |
| 5404 | /* |
| 5405 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5406 | */ |
| 5407 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, |
| 5408 | uint16_t *mailbox) |
| 5409 | { |
| 5410 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5411 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5412 | int login_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5413 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5414 | if (!ha->tgt.tgt_ops) |
| 5415 | return; |
| 5416 | |
| 5417 | if (unlikely(tgt == NULL)) { |
| 5418 | ql_dbg(ql_dbg_tgt, vha, 0xe03a, |
| 5419 | "ASYNC EVENT %#x, but no tgt (ha %p)\n", code, ha); |
| 5420 | return; |
| 5421 | } |
| 5422 | |
| 5423 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && |
| 5424 | IS_QLA2100(ha)) |
| 5425 | return; |
| 5426 | /* |
| 5427 | * In tgt_stop mode we also should allow all requests to pass. |
| 5428 | * Otherwise, some commands can stuck. |
| 5429 | */ |
| 5430 | |
| 5431 | tgt->irq_cmd_count++; |
| 5432 | |
| 5433 | switch (code) { |
| 5434 | case MBA_RESET: /* Reset */ |
| 5435 | case MBA_SYSTEM_ERR: /* System Error */ |
| 5436 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 5437 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 5438 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, |
| 5439 | "qla_target(%d): System error async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5440 | "occurred", vha->vp_idx, code); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5441 | break; |
| 5442 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ |
| 5443 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5444 | break; |
| 5445 | |
| 5446 | case MBA_LOOP_UP: |
| 5447 | { |
| 5448 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5449 | "qla_target(%d): Async LOOP_UP occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5450 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 5451 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5452 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5453 | if (tgt->link_reinit_iocb_pending) { |
| 5454 | qlt_send_notify_ack(vha, (void *)&tgt->link_reinit_iocb, |
| 5455 | 0, 0, 0, 0, 0, 0); |
| 5456 | tgt->link_reinit_iocb_pending = 0; |
| 5457 | } |
| 5458 | break; |
| 5459 | } |
| 5460 | |
| 5461 | case MBA_LIP_OCCURRED: |
| 5462 | case MBA_LOOP_DOWN: |
| 5463 | case MBA_LIP_RESET: |
| 5464 | case MBA_RSCN_UPDATE: |
| 5465 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5466 | "qla_target(%d): Async event %#x occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5467 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5468 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5469 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5470 | break; |
| 5471 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5472 | case MBA_REJECTED_FCP_CMD: |
| 5473 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xffff, |
| 5474 | "qla_target(%d): Async event LS_REJECT occurred " |
| 5475 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 5476 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5477 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 5478 | |
| 5479 | if (le16_to_cpu(mailbox[3]) == 1) { |
| 5480 | /* exchange starvation. */ |
| 5481 | vha->hw->exch_starvation++; |
| 5482 | if (vha->hw->exch_starvation > 5) { |
| 5483 | ql_log(ql_log_warn, vha, 0xffff, |
| 5484 | "Exchange starvation-. Resetting RISC\n"); |
| 5485 | |
| 5486 | vha->hw->exch_starvation = 0; |
| 5487 | if (IS_P3P_TYPE(vha->hw)) |
| 5488 | set_bit(FCOE_CTX_RESET_NEEDED, |
| 5489 | &vha->dpc_flags); |
| 5490 | else |
| 5491 | set_bit(ISP_ABORT_NEEDED, |
| 5492 | &vha->dpc_flags); |
| 5493 | qla2xxx_wake_dpc(vha); |
| 5494 | } |
| 5495 | } |
| 5496 | break; |
| 5497 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5498 | case MBA_PORT_UPDATE: |
| 5499 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, |
| 5500 | "qla_target(%d): Port update async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5501 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5502 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5503 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5504 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 5505 | |
| 5506 | login_code = le16_to_cpu(mailbox[2]); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5507 | if (login_code == 0x4) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5508 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
| 5509 | "Async MB 2: Got PLOGI Complete\n"); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5510 | vha->hw->exch_starvation = 0; |
| 5511 | } else if (login_code == 0x7) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5512 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
| 5513 | "Async MB 2: Port Logged Out\n"); |
| 5514 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5515 | default: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5516 | break; |
| 5517 | } |
| 5518 | |
| 5519 | tgt->irq_cmd_count--; |
| 5520 | } |
| 5521 | |
| 5522 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, |
| 5523 | uint16_t loop_id) |
| 5524 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5525 | fc_port_t *fcport, *tfcp, *del; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5526 | int rc; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5527 | unsigned long flags; |
| 5528 | u8 newfcport = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5529 | |
| 5530 | fcport = kzalloc(sizeof(*fcport), GFP_KERNEL); |
| 5531 | if (!fcport) { |
| 5532 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, |
| 5533 | "qla_target(%d): Allocation of tmp FC port failed", |
| 5534 | vha->vp_idx); |
| 5535 | return NULL; |
| 5536 | } |
| 5537 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5538 | fcport->loop_id = loop_id; |
| 5539 | |
| 5540 | rc = qla2x00_get_port_database(vha, fcport, 0); |
| 5541 | if (rc != QLA_SUCCESS) { |
| 5542 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, |
| 5543 | "qla_target(%d): Failed to retrieve fcport " |
| 5544 | "information -- get_port_database() returned %x " |
| 5545 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); |
| 5546 | kfree(fcport); |
| 5547 | return NULL; |
| 5548 | } |
| 5549 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5550 | del = NULL; |
| 5551 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 5552 | tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1); |
| 5553 | |
| 5554 | if (tfcp) { |
| 5555 | tfcp->d_id = fcport->d_id; |
| 5556 | tfcp->port_type = fcport->port_type; |
| 5557 | tfcp->supported_classes = fcport->supported_classes; |
| 5558 | tfcp->flags |= fcport->flags; |
| 5559 | |
| 5560 | del = fcport; |
| 5561 | fcport = tfcp; |
| 5562 | } else { |
| 5563 | if (vha->hw->current_topology == ISP_CFG_F) |
| 5564 | fcport->flags |= FCF_FABRIC_DEVICE; |
| 5565 | |
| 5566 | list_add_tail(&fcport->list, &vha->vp_fcports); |
| 5567 | if (!IS_SW_RESV_ADDR(fcport->d_id)) |
| 5568 | vha->fcport_count++; |
| 5569 | fcport->login_gen++; |
| 5570 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 5571 | fcport->login_succ = 1; |
| 5572 | newfcport = 1; |
| 5573 | } |
| 5574 | |
| 5575 | fcport->deleted = 0; |
| 5576 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 5577 | |
| 5578 | switch (vha->host->active_mode) { |
| 5579 | case MODE_INITIATOR: |
| 5580 | case MODE_DUAL: |
| 5581 | if (newfcport) { |
| 5582 | if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) { |
| 5583 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 5584 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 5585 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5586 | qla24xx_post_upd_fcport_work(vha, fcport); |
| 5587 | } else { |
| 5588 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 5589 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 5590 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5591 | qla24xx_post_gpsc_work(vha, fcport); |
| 5592 | } |
| 5593 | } |
| 5594 | break; |
| 5595 | |
| 5596 | case MODE_TARGET: |
| 5597 | default: |
| 5598 | break; |
| 5599 | } |
| 5600 | if (del) |
| 5601 | qla2x00_free_fcport(del); |
| 5602 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5603 | return fcport; |
| 5604 | } |
| 5605 | |
| 5606 | /* Must be called under tgt_mutex */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5607 | 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] | 5608 | uint8_t *s_id) |
| 5609 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5610 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5611 | fc_port_t *fcport = NULL; |
| 5612 | int rc, global_resets; |
| 5613 | uint16_t loop_id = 0; |
| 5614 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5615 | if ((s_id[0] == 0xFF) && (s_id[1] == 0xFC)) { |
| 5616 | /* |
| 5617 | * This is Domain Controller, so it should be |
| 5618 | * OK to drop SCSI commands from it. |
| 5619 | */ |
| 5620 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, |
| 5621 | "Unable to find initiator with S_ID %x:%x:%x", |
| 5622 | s_id[0], s_id[1], s_id[2]); |
| 5623 | return NULL; |
| 5624 | } |
| 5625 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5626 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 5627 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5628 | retry: |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5629 | global_resets = |
| 5630 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5631 | |
| 5632 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); |
| 5633 | if (rc != 0) { |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5634 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5635 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5636 | ql_log(ql_log_info, vha, 0xf071, |
| 5637 | "qla_target(%d): Unable to find " |
| 5638 | "initiator with S_ID %x:%x:%x", |
| 5639 | vha->vp_idx, s_id[0], s_id[1], |
| 5640 | s_id[2]); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5641 | |
| 5642 | if (rc == -ENOENT) { |
| 5643 | qlt_port_logo_t logo; |
| 5644 | sid_to_portid(s_id, &logo.id); |
| 5645 | logo.cmd_count = 1; |
| 5646 | qlt_send_first_logo(vha, &logo); |
| 5647 | } |
| 5648 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5649 | return NULL; |
| 5650 | } |
| 5651 | |
| 5652 | fcport = qlt_get_port_database(vha, loop_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5653 | if (!fcport) { |
| 5654 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5655 | return NULL; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5656 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5657 | |
| 5658 | if (global_resets != |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5659 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5660 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
| 5661 | "qla_target(%d): global reset during session discovery " |
| 5662 | "(counter was %d, new %d), retrying", vha->vp_idx, |
| 5663 | global_resets, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5664 | atomic_read(&vha->vha_tgt. |
| 5665 | qla_tgt->tgt_global_resets_count)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5666 | goto retry; |
| 5667 | } |
| 5668 | |
| 5669 | sess = qlt_create_sess(vha, fcport, true); |
| 5670 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5671 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5672 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5673 | return sess; |
| 5674 | } |
| 5675 | |
| 5676 | static void qlt_abort_work(struct qla_tgt *tgt, |
| 5677 | struct qla_tgt_sess_work_param *prm) |
| 5678 | { |
| 5679 | struct scsi_qla_host *vha = tgt->vha; |
| 5680 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5681 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5682 | unsigned long flags = 0, flags2 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5683 | uint32_t be_s_id; |
| 5684 | uint8_t s_id[3]; |
| 5685 | int rc; |
| 5686 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5687 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5688 | |
| 5689 | if (tgt->tgt_stop) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5690 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5691 | |
| 5692 | s_id[0] = prm->abts.fcp_hdr_le.s_id[2]; |
| 5693 | s_id[1] = prm->abts.fcp_hdr_le.s_id[1]; |
| 5694 | s_id[2] = prm->abts.fcp_hdr_le.s_id[0]; |
| 5695 | |
| 5696 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 5697 | (unsigned char *)&be_s_id); |
| 5698 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5699 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5700 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5701 | sess = qlt_make_local_sess(vha, s_id); |
| 5702 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5703 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5704 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5705 | if (!sess) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5706 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5707 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5708 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5709 | sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5710 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5711 | } |
| 5712 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5713 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 5714 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xffff, |
| 5715 | "%s: kref_get fail %8phC \n", |
| 5716 | __func__, sess->port_name); |
| 5717 | sess = NULL; |
| 5718 | goto out_term2; |
| 5719 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5720 | } |
| 5721 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5722 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5723 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5724 | if (tgt->tgt_stop) |
| 5725 | goto out_term; |
| 5726 | |
| 5727 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); |
| 5728 | if (rc != 0) |
| 5729 | goto out_term; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5730 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5731 | if (sess) |
| 5732 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5733 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5734 | return; |
| 5735 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5736 | out_term2: |
| 5737 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5738 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5739 | out_term: |
| 5740 | qlt_24xx_send_abts_resp(vha, &prm->abts, FCP_TMF_REJECTED, false); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5741 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5742 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5743 | if (sess) |
| 5744 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5745 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5746 | } |
| 5747 | |
| 5748 | static void qlt_tmr_work(struct qla_tgt *tgt, |
| 5749 | struct qla_tgt_sess_work_param *prm) |
| 5750 | { |
| 5751 | struct atio_from_isp *a = &prm->tm_iocb2; |
| 5752 | struct scsi_qla_host *vha = tgt->vha; |
| 5753 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5754 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5755 | unsigned long flags; |
| 5756 | uint8_t *s_id = NULL; /* to hide compiler warnings */ |
| 5757 | int rc; |
| 5758 | uint32_t lun, unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 5759 | int fn; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5760 | void *iocb; |
| 5761 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5762 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5763 | |
| 5764 | if (tgt->tgt_stop) |
| 5765 | goto out_term; |
| 5766 | |
| 5767 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; |
| 5768 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 5769 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5770 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5771 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5772 | sess = qlt_make_local_sess(vha, s_id); |
| 5773 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5774 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5775 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5776 | if (!sess) |
| 5777 | goto out_term; |
| 5778 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5779 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5780 | sess = NULL; |
| 5781 | goto out_term; |
| 5782 | } |
| 5783 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5784 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 5785 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xffff, |
| 5786 | "%s: kref_get fail %8phC\n", |
| 5787 | __func__, sess->port_name); |
| 5788 | sess = NULL; |
| 5789 | goto out_term; |
| 5790 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | iocb = a; |
| 5794 | lun = a->u.isp24.fcp_cmnd.lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5795 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
| 5796 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); |
| 5797 | |
| 5798 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 5799 | if (rc != 0) |
| 5800 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5801 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5802 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5803 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5804 | return; |
| 5805 | |
| 5806 | out_term: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5807 | qlt_send_term_exchange(vha, NULL, &prm->tm_iocb2, 1, 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5808 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5809 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5810 | } |
| 5811 | |
| 5812 | static void qlt_sess_work_fn(struct work_struct *work) |
| 5813 | { |
| 5814 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); |
| 5815 | struct scsi_qla_host *vha = tgt->vha; |
| 5816 | unsigned long flags; |
| 5817 | |
| 5818 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); |
| 5819 | |
| 5820 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 5821 | while (!list_empty(&tgt->sess_works_list)) { |
| 5822 | struct qla_tgt_sess_work_param *prm = list_entry( |
| 5823 | tgt->sess_works_list.next, typeof(*prm), |
| 5824 | sess_works_list_entry); |
| 5825 | |
| 5826 | /* |
| 5827 | * This work can be scheduled on several CPUs at time, so we |
| 5828 | * must delete the entry to eliminate double processing |
| 5829 | */ |
| 5830 | list_del(&prm->sess_works_list_entry); |
| 5831 | |
| 5832 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 5833 | |
| 5834 | switch (prm->type) { |
| 5835 | case QLA_TGT_SESS_WORK_ABORT: |
| 5836 | qlt_abort_work(tgt, prm); |
| 5837 | break; |
| 5838 | case QLA_TGT_SESS_WORK_TM: |
| 5839 | qlt_tmr_work(tgt, prm); |
| 5840 | break; |
| 5841 | default: |
| 5842 | BUG_ON(1); |
| 5843 | break; |
| 5844 | } |
| 5845 | |
| 5846 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 5847 | |
| 5848 | kfree(prm); |
| 5849 | } |
| 5850 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 5851 | } |
| 5852 | |
| 5853 | /* Must be called under tgt_host_action_mutex */ |
| 5854 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) |
| 5855 | { |
| 5856 | struct qla_tgt *tgt; |
| 5857 | |
| 5858 | if (!QLA_TGT_MODE_ENABLED()) |
| 5859 | return 0; |
| 5860 | |
Arun Easi | 33c36c0 | 2013-01-30 03:34:41 -0500 | [diff] [blame] | 5861 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
| 5862 | ql_log(ql_log_warn, base_vha, 0xe070, |
| 5863 | "This adapter does not support target mode.\n"); |
| 5864 | return 0; |
| 5865 | } |
| 5866 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5867 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5868 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5869 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5870 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5871 | |
| 5872 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); |
| 5873 | if (!tgt) { |
| 5874 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, |
| 5875 | "Unable to allocate struct qla_tgt\n"); |
| 5876 | return -ENOMEM; |
| 5877 | } |
| 5878 | |
| 5879 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) |
| 5880 | base_vha->host->hostt->supported_mode |= MODE_TARGET; |
| 5881 | |
| 5882 | tgt->ha = ha; |
| 5883 | tgt->vha = base_vha; |
| 5884 | init_waitqueue_head(&tgt->waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5885 | INIT_LIST_HEAD(&tgt->del_sess_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5886 | spin_lock_init(&tgt->sess_work_lock); |
| 5887 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); |
| 5888 | INIT_LIST_HEAD(&tgt->sess_works_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5889 | atomic_set(&tgt->tgt_global_resets_count, 0); |
| 5890 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5891 | base_vha->vha_tgt.qla_tgt = tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5892 | |
| 5893 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, |
| 5894 | "qla_target(%d): using 64 Bit PCI addressing", |
| 5895 | base_vha->vp_idx); |
| 5896 | tgt->tgt_enable_64bit_addr = 1; |
| 5897 | /* 3 is reserved */ |
| 5898 | tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3); |
| 5899 | tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX; |
| 5900 | tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX; |
| 5901 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 5902 | if (base_vha->fc_vport) |
| 5903 | return 0; |
| 5904 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5905 | mutex_lock(&qla_tgt_mutex); |
| 5906 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); |
| 5907 | mutex_unlock(&qla_tgt_mutex); |
| 5908 | |
| 5909 | return 0; |
| 5910 | } |
| 5911 | |
| 5912 | /* Must be called under tgt_host_action_mutex */ |
| 5913 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) |
| 5914 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5915 | if (!vha->vha_tgt.qla_tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5916 | return 0; |
| 5917 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 5918 | if (vha->fc_vport) { |
| 5919 | qlt_release(vha->vha_tgt.qla_tgt); |
| 5920 | return 0; |
| 5921 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5922 | |
| 5923 | /* free left over qfull cmds */ |
| 5924 | qlt_init_term_exchange(vha); |
| 5925 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5926 | mutex_lock(&qla_tgt_mutex); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5927 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5928 | mutex_unlock(&qla_tgt_mutex); |
| 5929 | |
| 5930 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", |
| 5931 | vha->host_no, ha); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5932 | qlt_release(vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5933 | |
| 5934 | return 0; |
| 5935 | } |
| 5936 | |
| 5937 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, |
| 5938 | unsigned char *b) |
| 5939 | { |
| 5940 | int i; |
| 5941 | |
| 5942 | pr_debug("qla2xxx HW vha->node_name: "); |
| 5943 | for (i = 0; i < WWN_SIZE; i++) |
| 5944 | pr_debug("%02x ", vha->node_name[i]); |
| 5945 | pr_debug("\n"); |
| 5946 | pr_debug("qla2xxx HW vha->port_name: "); |
| 5947 | for (i = 0; i < WWN_SIZE; i++) |
| 5948 | pr_debug("%02x ", vha->port_name[i]); |
| 5949 | pr_debug("\n"); |
| 5950 | |
| 5951 | pr_debug("qla2xxx passed configfs WWPN: "); |
| 5952 | put_unaligned_be64(wwpn, b); |
| 5953 | for (i = 0; i < WWN_SIZE; i++) |
| 5954 | pr_debug("%02x ", b[i]); |
| 5955 | pr_debug("\n"); |
| 5956 | } |
| 5957 | |
| 5958 | /** |
| 5959 | * qla_tgt_lport_register - register lport with external module |
| 5960 | * |
| 5961 | * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops |
| 5962 | * @wwpn: Passwd FC target WWPN |
| 5963 | * @callback: lport initialization callback for tcm_qla2xxx code |
| 5964 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data |
| 5965 | */ |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 5966 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
| 5967 | u64 npiv_wwpn, u64 npiv_wwnn, |
| 5968 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5969 | { |
| 5970 | struct qla_tgt *tgt; |
| 5971 | struct scsi_qla_host *vha; |
| 5972 | struct qla_hw_data *ha; |
| 5973 | struct Scsi_Host *host; |
| 5974 | unsigned long flags; |
| 5975 | int rc; |
| 5976 | u8 b[WWN_SIZE]; |
| 5977 | |
| 5978 | mutex_lock(&qla_tgt_mutex); |
| 5979 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { |
| 5980 | vha = tgt->vha; |
| 5981 | ha = vha->hw; |
| 5982 | |
| 5983 | host = vha->host; |
| 5984 | if (!host) |
| 5985 | continue; |
| 5986 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5987 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
| 5988 | continue; |
| 5989 | |
| 5990 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 5991 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5992 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
| 5993 | host->host_no); |
| 5994 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5995 | continue; |
| 5996 | } |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 5997 | if (tgt->tgt_stop) { |
| 5998 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", |
| 5999 | host->host_no); |
| 6000 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6001 | continue; |
| 6002 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6003 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6004 | |
| 6005 | if (!scsi_host_get(host)) { |
| 6006 | ql_dbg(ql_dbg_tgt, vha, 0xe068, |
| 6007 | "Unable to scsi_host_get() for" |
| 6008 | " qla2xxx scsi_host\n"); |
| 6009 | continue; |
| 6010 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6011 | qlt_lport_dump(vha, phys_wwpn, b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6012 | |
| 6013 | if (memcmp(vha->port_name, b, WWN_SIZE)) { |
| 6014 | scsi_host_put(host); |
| 6015 | continue; |
| 6016 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6017 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
| 6018 | if (rc != 0) |
| 6019 | scsi_host_put(host); |
| 6020 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6021 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6022 | return rc; |
| 6023 | } |
| 6024 | mutex_unlock(&qla_tgt_mutex); |
| 6025 | |
| 6026 | return -ENODEV; |
| 6027 | } |
| 6028 | EXPORT_SYMBOL(qlt_lport_register); |
| 6029 | |
| 6030 | /** |
| 6031 | * qla_tgt_lport_deregister - Degister lport |
| 6032 | * |
| 6033 | * @vha: Registered scsi_qla_host pointer |
| 6034 | */ |
| 6035 | void qlt_lport_deregister(struct scsi_qla_host *vha) |
| 6036 | { |
| 6037 | struct qla_hw_data *ha = vha->hw; |
| 6038 | struct Scsi_Host *sh = vha->host; |
| 6039 | /* |
| 6040 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data |
| 6041 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6042 | vha->vha_tgt.target_lport_ptr = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6043 | ha->tgt.tgt_ops = NULL; |
| 6044 | /* |
| 6045 | * Release the Scsi_Host reference for the underlying qla2xxx host |
| 6046 | */ |
| 6047 | scsi_host_put(sh); |
| 6048 | } |
| 6049 | EXPORT_SYMBOL(qlt_lport_deregister); |
| 6050 | |
| 6051 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6052 | static void qlt_set_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6053 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6054 | switch (ql2x_ini_mode) { |
| 6055 | case QLA2XXX_INI_MODE_DISABLED: |
| 6056 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6057 | vha->host->active_mode = MODE_TARGET; |
| 6058 | break; |
| 6059 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6060 | vha->host->active_mode = MODE_UNKNOWN; |
| 6061 | break; |
| 6062 | case QLA2XXX_INI_MODE_DUAL: |
| 6063 | vha->host->active_mode = MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6064 | break; |
| 6065 | default: |
| 6066 | break; |
| 6067 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6068 | } |
| 6069 | |
| 6070 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6071 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6072 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6073 | switch (ql2x_ini_mode) { |
| 6074 | case QLA2XXX_INI_MODE_DISABLED: |
| 6075 | vha->host->active_mode = MODE_UNKNOWN; |
| 6076 | break; |
| 6077 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6078 | vha->host->active_mode = MODE_INITIATOR; |
| 6079 | break; |
| 6080 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6081 | case QLA2XXX_INI_MODE_DUAL: |
| 6082 | vha->host->active_mode = MODE_INITIATOR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6083 | break; |
| 6084 | default: |
| 6085 | break; |
| 6086 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6087 | } |
| 6088 | |
| 6089 | /* |
| 6090 | * qla_tgt_enable_vha - NO LOCK HELD |
| 6091 | * |
| 6092 | * host_reset, bring up w/ Target Mode Enabled |
| 6093 | */ |
| 6094 | void |
| 6095 | qlt_enable_vha(struct scsi_qla_host *vha) |
| 6096 | { |
| 6097 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6098 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6099 | unsigned long flags; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6100 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | cdb898c | 2015-12-17 14:57:05 -0500 | [diff] [blame] | 6101 | int rspq_ent = QLA83XX_RSPQ_MSIX_ENTRY_NUMBER; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6102 | |
| 6103 | if (!tgt) { |
| 6104 | ql_dbg(ql_dbg_tgt, vha, 0xe069, |
| 6105 | "Unable to locate qla_tgt pointer from" |
| 6106 | " struct qla_hw_data\n"); |
| 6107 | dump_stack(); |
| 6108 | return; |
| 6109 | } |
| 6110 | |
| 6111 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6112 | tgt->tgt_stopped = 0; |
| 6113 | qlt_set_mode(vha); |
| 6114 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6115 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6116 | if (vha->vp_idx) { |
| 6117 | qla24xx_disable_vp(vha); |
| 6118 | qla24xx_enable_vp(vha); |
| 6119 | } else { |
Quinn Tran | cdb898c | 2015-12-17 14:57:05 -0500 | [diff] [blame] | 6120 | if (ha->msix_entries) { |
| 6121 | ql_dbg(ql_dbg_tgt, vha, 0xffff, |
| 6122 | "%s: host%ld : vector %d cpu %d\n", |
| 6123 | __func__, vha->host_no, |
| 6124 | ha->msix_entries[rspq_ent].vector, |
| 6125 | ha->msix_entries[rspq_ent].cpuid); |
| 6126 | |
| 6127 | ha->tgt.rspq_vector_cpuid = |
| 6128 | ha->msix_entries[rspq_ent].cpuid; |
| 6129 | } |
| 6130 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6131 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 6132 | qla2xxx_wake_dpc(base_vha); |
| 6133 | qla2x00_wait_for_hba_online(base_vha); |
| 6134 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6135 | } |
| 6136 | EXPORT_SYMBOL(qlt_enable_vha); |
| 6137 | |
| 6138 | /* |
| 6139 | * qla_tgt_disable_vha - NO LOCK HELD |
| 6140 | * |
| 6141 | * Disable Target Mode and reset the adapter |
| 6142 | */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6143 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6144 | { |
| 6145 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6146 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6147 | unsigned long flags; |
| 6148 | |
| 6149 | if (!tgt) { |
| 6150 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, |
| 6151 | "Unable to locate qla_tgt pointer from" |
| 6152 | " struct qla_hw_data\n"); |
| 6153 | dump_stack(); |
| 6154 | return; |
| 6155 | } |
| 6156 | |
| 6157 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6158 | qlt_clear_mode(vha); |
| 6159 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6160 | |
| 6161 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6162 | qla2xxx_wake_dpc(vha); |
| 6163 | qla2x00_wait_for_hba_online(vha); |
| 6164 | } |
| 6165 | |
| 6166 | /* |
| 6167 | * Called from qla_init.c:qla24xx_vport_create() contex to setup |
| 6168 | * the target mode specific struct scsi_qla_host and struct qla_hw_data |
| 6169 | * members. |
| 6170 | */ |
| 6171 | void |
| 6172 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) |
| 6173 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6174 | vha->vha_tgt.qla_tgt = NULL; |
| 6175 | |
| 6176 | mutex_init(&vha->vha_tgt.tgt_mutex); |
| 6177 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6178 | |
| 6179 | qlt_clear_mode(vha); |
| 6180 | |
| 6181 | /* |
| 6182 | * NOTE: Currently the value is kept the same for <24xx and |
| 6183 | * >=24xx ISPs. If it is necessary to change it, |
| 6184 | * the check should be added for specific ISPs, |
| 6185 | * assigning the value appropriately. |
| 6186 | */ |
| 6187 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6188 | |
| 6189 | qlt_add_target(ha, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6190 | } |
| 6191 | |
| 6192 | void |
| 6193 | qlt_rff_id(struct scsi_qla_host *vha, struct ct_sns_req *ct_req) |
| 6194 | { |
| 6195 | /* |
| 6196 | * FC-4 Feature bit 0 indicates target functionality to the name server. |
| 6197 | */ |
| 6198 | if (qla_tgt_mode_enabled(vha)) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6199 | ct_req->req.rff_id.fc4_feature = BIT_0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6200 | } else if (qla_ini_mode_enabled(vha)) { |
| 6201 | ct_req->req.rff_id.fc4_feature = BIT_1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6202 | } else if (qla_dual_mode_enabled(vha)) |
| 6203 | ct_req->req.rff_id.fc4_feature = BIT_0 | BIT_1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | /* |
| 6207 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. |
| 6208 | * @ha: HA context |
| 6209 | * |
| 6210 | * Beginning of ATIO ring has initialization control block already built |
| 6211 | * by nvram config routine. |
| 6212 | * |
| 6213 | * Returns 0 on success. |
| 6214 | */ |
| 6215 | void |
| 6216 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) |
| 6217 | { |
| 6218 | struct qla_hw_data *ha = vha->hw; |
| 6219 | uint16_t cnt; |
| 6220 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; |
| 6221 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6222 | if (qla_ini_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6223 | return; |
| 6224 | |
| 6225 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { |
| 6226 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6227 | pkt++; |
| 6228 | } |
| 6229 | |
| 6230 | } |
| 6231 | |
| 6232 | /* |
| 6233 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. |
| 6234 | * @ha: SCSI driver HA context |
| 6235 | */ |
| 6236 | void |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6237 | 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] | 6238 | { |
| 6239 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6240 | struct atio_from_isp *pkt; |
| 6241 | int cnt, i; |
| 6242 | |
| 6243 | if (!vha->flags.online) |
| 6244 | return; |
| 6245 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6246 | while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) || |
| 6247 | fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6248 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6249 | cnt = pkt->u.raw.entry_count; |
| 6250 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6251 | if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) { |
| 6252 | /* |
| 6253 | * This packet is corrupted. The header + payload |
| 6254 | * can not be trusted. There is no point in passing |
| 6255 | * it further up. |
| 6256 | */ |
| 6257 | ql_log(ql_log_warn, vha, 0xffff, |
| 6258 | "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n", |
| 6259 | pkt->u.isp24.fcp_hdr.s_id, |
| 6260 | be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id), |
| 6261 | le32_to_cpu(pkt->u.isp24.exchange_addr), pkt); |
| 6262 | |
| 6263 | adjust_corrupted_atio(pkt); |
| 6264 | qlt_send_term_exchange(vha, NULL, pkt, ha_locked, 0); |
| 6265 | } else { |
| 6266 | qlt_24xx_atio_pkt_all_vps(vha, |
| 6267 | (struct atio_from_isp *)pkt, ha_locked); |
| 6268 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6269 | |
| 6270 | for (i = 0; i < cnt; i++) { |
| 6271 | ha->tgt.atio_ring_index++; |
| 6272 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { |
| 6273 | ha->tgt.atio_ring_index = 0; |
| 6274 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 6275 | } else |
| 6276 | ha->tgt.atio_ring_ptr++; |
| 6277 | |
| 6278 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6279 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6280 | } |
| 6281 | wmb(); |
| 6282 | } |
| 6283 | |
| 6284 | /* Adjust ring index */ |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6285 | 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] | 6286 | RD_REG_DWORD_RELAXED(ISP_ATIO_Q_OUT(vha)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6287 | } |
| 6288 | |
| 6289 | void |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6290 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6291 | { |
| 6292 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6293 | if (!QLA_TGT_MODE_ENABLED()) |
| 6294 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6295 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6296 | WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0); |
| 6297 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0); |
| 6298 | RD_REG_DWORD(ISP_ATIO_Q_OUT(vha)); |
| 6299 | |
| 6300 | if (IS_ATIO_MSIX_CAPABLE(ha)) { |
| 6301 | struct qla_msix_entry *msix = &ha->msix_entries[2]; |
| 6302 | struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb; |
| 6303 | |
| 6304 | icb->msix_atio = cpu_to_le16(msix->entry); |
| 6305 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6306 | "Registering ICB vector 0x%x for atio que.\n", |
| 6307 | msix->entry); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6308 | } |
| 6309 | } |
| 6310 | |
| 6311 | void |
| 6312 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) |
| 6313 | { |
| 6314 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6315 | u32 tmp; |
| 6316 | u16 t; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6317 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6318 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6319 | if (!ha->tgt.saved_set) { |
| 6320 | /* We save only once */ |
| 6321 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6322 | ha->tgt.saved_firmware_options_1 = |
| 6323 | nv->firmware_options_1; |
| 6324 | ha->tgt.saved_firmware_options_2 = |
| 6325 | nv->firmware_options_2; |
| 6326 | ha->tgt.saved_firmware_options_3 = |
| 6327 | nv->firmware_options_3; |
| 6328 | ha->tgt.saved_set = 1; |
| 6329 | } |
| 6330 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6331 | if (qla_tgt_mode_enabled(vha)) { |
| 6332 | nv->exchange_count = cpu_to_le16(0xFFFF); |
| 6333 | } else { /* dual */ |
| 6334 | if (ql_dm_tgt_ex_pct > 100) { |
| 6335 | ql_dm_tgt_ex_pct = 50; |
| 6336 | } else if (ql_dm_tgt_ex_pct == 100) { |
| 6337 | /* leave some for FW */ |
| 6338 | ql_dm_tgt_ex_pct = 95; |
| 6339 | } |
| 6340 | |
| 6341 | tmp = ha->orig_fw_xcb_count * ql_dm_tgt_ex_pct; |
| 6342 | tmp = tmp/100; |
| 6343 | if (tmp > 0xffff) |
| 6344 | tmp = 0xffff; |
| 6345 | |
| 6346 | t = tmp & 0xffff; |
| 6347 | nv->exchange_count = cpu_to_le16(t); |
| 6348 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6349 | |
| 6350 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6351 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6352 | |
| 6353 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6354 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6355 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6356 | |
| 6357 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6358 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6359 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6360 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6361 | if (ql2xtgt_tape_enable) |
| 6362 | /* Enable FC Tape support */ |
| 6363 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6364 | else |
| 6365 | /* Disable FC Tape support */ |
| 6366 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6367 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6368 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6369 | nv->host_p &= cpu_to_le32(~BIT_10); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6370 | |
| 6371 | /* |
| 6372 | * clear BIT 15 explicitly as we have seen at least |
| 6373 | * a couple of instances where this was set and this |
| 6374 | * was causing the firmware to not be initialized. |
| 6375 | */ |
| 6376 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6377 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6378 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6379 | } else { |
| 6380 | if (ha->tgt.saved_set) { |
| 6381 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6382 | nv->firmware_options_1 = |
| 6383 | ha->tgt.saved_firmware_options_1; |
| 6384 | nv->firmware_options_2 = |
| 6385 | ha->tgt.saved_firmware_options_2; |
| 6386 | nv->firmware_options_3 = |
| 6387 | ha->tgt.saved_firmware_options_3; |
| 6388 | } |
| 6389 | return; |
| 6390 | } |
| 6391 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6392 | if (ha->tgt.enable_class_2) { |
| 6393 | if (vha->flags.init_done) |
| 6394 | fc_host_supported_classes(vha->host) = |
| 6395 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6396 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6397 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6398 | } else { |
| 6399 | if (vha->flags.init_done) |
| 6400 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6401 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6402 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6403 | } |
| 6404 | } |
| 6405 | |
| 6406 | void |
| 6407 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6408 | struct init_cb_24xx *icb) |
| 6409 | { |
| 6410 | struct qla_hw_data *ha = vha->hw; |
| 6411 | |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6412 | if (!QLA_TGT_MODE_ENABLED()) |
| 6413 | return; |
| 6414 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6415 | if (ha->tgt.node_name_set) { |
| 6416 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6417 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6418 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6419 | |
| 6420 | /* disable ZIO at start time. */ |
| 6421 | if (!vha->flags.init_done) { |
| 6422 | uint32_t tmp; |
| 6423 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6424 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6425 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6426 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6427 | } |
| 6428 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6429 | void |
| 6430 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) |
| 6431 | { |
| 6432 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6433 | u32 tmp; |
| 6434 | u16 t; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6435 | |
| 6436 | if (!QLA_TGT_MODE_ENABLED()) |
| 6437 | return; |
| 6438 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6439 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6440 | if (!ha->tgt.saved_set) { |
| 6441 | /* We save only once */ |
| 6442 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6443 | ha->tgt.saved_firmware_options_1 = |
| 6444 | nv->firmware_options_1; |
| 6445 | ha->tgt.saved_firmware_options_2 = |
| 6446 | nv->firmware_options_2; |
| 6447 | ha->tgt.saved_firmware_options_3 = |
| 6448 | nv->firmware_options_3; |
| 6449 | ha->tgt.saved_set = 1; |
| 6450 | } |
| 6451 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6452 | if (qla_tgt_mode_enabled(vha)) { |
| 6453 | nv->exchange_count = cpu_to_le16(0xFFFF); |
| 6454 | } else { /* dual */ |
| 6455 | if (ql_dm_tgt_ex_pct > 100) { |
| 6456 | ql_dm_tgt_ex_pct = 50; |
| 6457 | } else if (ql_dm_tgt_ex_pct == 100) { |
| 6458 | /* leave some for FW */ |
| 6459 | ql_dm_tgt_ex_pct = 95; |
| 6460 | } |
| 6461 | |
| 6462 | tmp = ha->orig_fw_xcb_count * ql_dm_tgt_ex_pct; |
| 6463 | tmp = tmp/100; |
| 6464 | if (tmp > 0xffff) |
| 6465 | tmp = 0xffff; |
| 6466 | t = tmp & 0xffff; |
| 6467 | nv->exchange_count = cpu_to_le16(t); |
| 6468 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6469 | |
| 6470 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6471 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6472 | |
| 6473 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6474 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6475 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6476 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6477 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6478 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6479 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6480 | /* |
| 6481 | * clear BIT 15 explicitly as we have seen at |
| 6482 | * least a couple of instances where this was set |
| 6483 | * and this was causing the firmware to not be |
| 6484 | * initialized. |
| 6485 | */ |
| 6486 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6487 | if (ql2xtgt_tape_enable) |
| 6488 | /* Enable FC tape support */ |
| 6489 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6490 | else |
| 6491 | /* Disable FC tape support */ |
| 6492 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6493 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6494 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6495 | nv->host_p &= cpu_to_le32(~BIT_10); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6496 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6497 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6498 | } else { |
| 6499 | if (ha->tgt.saved_set) { |
| 6500 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6501 | nv->firmware_options_1 = |
| 6502 | ha->tgt.saved_firmware_options_1; |
| 6503 | nv->firmware_options_2 = |
| 6504 | ha->tgt.saved_firmware_options_2; |
| 6505 | nv->firmware_options_3 = |
| 6506 | ha->tgt.saved_firmware_options_3; |
| 6507 | } |
| 6508 | return; |
| 6509 | } |
| 6510 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6511 | if (ha->tgt.enable_class_2) { |
| 6512 | if (vha->flags.init_done) |
| 6513 | fc_host_supported_classes(vha->host) = |
| 6514 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6515 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6516 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6517 | } else { |
| 6518 | if (vha->flags.init_done) |
| 6519 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6520 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6521 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6522 | } |
| 6523 | } |
| 6524 | |
| 6525 | void |
| 6526 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6527 | struct init_cb_81xx *icb) |
| 6528 | { |
| 6529 | struct qla_hw_data *ha = vha->hw; |
| 6530 | |
| 6531 | if (!QLA_TGT_MODE_ENABLED()) |
| 6532 | return; |
| 6533 | |
| 6534 | if (ha->tgt.node_name_set) { |
| 6535 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6536 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6537 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6538 | |
| 6539 | /* disable ZIO at start time. */ |
| 6540 | if (!vha->flags.init_done) { |
| 6541 | uint32_t tmp; |
| 6542 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6543 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6544 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6545 | } |
| 6546 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6547 | } |
| 6548 | |
| 6549 | void |
| 6550 | qlt_83xx_iospace_config(struct qla_hw_data *ha) |
| 6551 | { |
| 6552 | if (!QLA_TGT_MODE_ENABLED()) |
| 6553 | return; |
| 6554 | |
| 6555 | ha->msix_count += 1; /* For ATIO Q */ |
| 6556 | } |
| 6557 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6558 | int |
| 6559 | qlt_24xx_process_response_error(struct scsi_qla_host *vha, |
| 6560 | struct sts_entry_24xx *pkt) |
| 6561 | { |
| 6562 | switch (pkt->entry_type) { |
| 6563 | case ABTS_RECV_24XX: |
| 6564 | case ABTS_RESP_24XX: |
| 6565 | case CTIO_TYPE7: |
| 6566 | case NOTIFY_ACK_TYPE: |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 6567 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6568 | return 1; |
| 6569 | default: |
| 6570 | return 0; |
| 6571 | } |
| 6572 | } |
| 6573 | |
| 6574 | void |
| 6575 | qlt_modify_vp_config(struct scsi_qla_host *vha, |
| 6576 | struct vp_config_entry_24xx *vpmod) |
| 6577 | { |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6578 | /* enable target mode. Bit5 = 1 => disable */ |
| 6579 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6580 | vpmod->options_idx1 &= ~BIT_5; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6581 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6582 | /* Disable ini mode, if requested. bit4 = 1 => disable */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6583 | if (qla_tgt_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6584 | vpmod->options_idx1 &= ~BIT_4; |
| 6585 | } |
| 6586 | |
| 6587 | void |
| 6588 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) |
| 6589 | { |
| 6590 | if (!QLA_TGT_MODE_ENABLED()) |
| 6591 | return; |
| 6592 | |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 6593 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6594 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
| 6595 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; |
| 6596 | } else { |
| 6597 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; |
| 6598 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; |
| 6599 | } |
| 6600 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6601 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
| 6602 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6603 | |
| 6604 | INIT_LIST_HEAD(&base_vha->unknown_atio_list); |
| 6605 | INIT_DELAYED_WORK(&base_vha->unknown_atio_work, |
| 6606 | qlt_unknown_atio_work_fn); |
| 6607 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6608 | qlt_clear_mode(base_vha); |
| 6609 | } |
| 6610 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6611 | irqreturn_t |
| 6612 | qla83xx_msix_atio_q(int irq, void *dev_id) |
| 6613 | { |
| 6614 | struct rsp_que *rsp; |
| 6615 | scsi_qla_host_t *vha; |
| 6616 | struct qla_hw_data *ha; |
| 6617 | unsigned long flags; |
| 6618 | |
| 6619 | rsp = (struct rsp_que *) dev_id; |
| 6620 | ha = rsp->hw; |
| 6621 | vha = pci_get_drvdata(ha->pdev); |
| 6622 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6623 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6624 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6625 | qlt_24xx_process_atio_queue(vha, 0); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6626 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6627 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6628 | |
| 6629 | return IRQ_HANDLED; |
| 6630 | } |
| 6631 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6632 | static void |
| 6633 | qlt_handle_abts_recv_work(struct work_struct *work) |
| 6634 | { |
| 6635 | struct qla_tgt_sess_op *op = container_of(work, |
| 6636 | struct qla_tgt_sess_op, work); |
| 6637 | scsi_qla_host_t *vha = op->vha; |
| 6638 | struct qla_hw_data *ha = vha->hw; |
| 6639 | unsigned long flags; |
| 6640 | |
| 6641 | if (qla2x00_reset_active(vha) || (op->chip_reset != ha->chip_reset)) |
| 6642 | return; |
| 6643 | |
| 6644 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 6645 | qlt_24xx_process_atio_queue(vha, 0); |
| 6646 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 6647 | |
| 6648 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6649 | qlt_response_pkt_all_vps(vha, (response_t *)&op->atio); |
| 6650 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | ae940f2 | 2017-03-15 09:48:44 -0700 | [diff] [blame] | 6651 | |
| 6652 | kfree(op); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6653 | } |
| 6654 | |
| 6655 | void |
| 6656 | qlt_handle_abts_recv(struct scsi_qla_host *vha, response_t *pkt) |
| 6657 | { |
| 6658 | struct qla_tgt_sess_op *op; |
| 6659 | |
| 6660 | op = kzalloc(sizeof(*op), GFP_ATOMIC); |
| 6661 | |
| 6662 | if (!op) { |
| 6663 | /* do not reach for ATIO queue here. This is best effort err |
| 6664 | * recovery at this point. |
| 6665 | */ |
| 6666 | qlt_response_pkt_all_vps(vha, pkt); |
| 6667 | return; |
| 6668 | } |
| 6669 | |
| 6670 | memcpy(&op->atio, pkt, sizeof(*pkt)); |
| 6671 | op->vha = vha; |
| 6672 | op->chip_reset = vha->hw->chip_reset; |
| 6673 | INIT_WORK(&op->work, qlt_handle_abts_recv_work); |
| 6674 | queue_work(qla_tgt_wq, &op->work); |
| 6675 | return; |
| 6676 | } |
| 6677 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6678 | int |
| 6679 | qlt_mem_alloc(struct qla_hw_data *ha) |
| 6680 | { |
| 6681 | if (!QLA_TGT_MODE_ENABLED()) |
| 6682 | return 0; |
| 6683 | |
| 6684 | ha->tgt.tgt_vp_map = kzalloc(sizeof(struct qla_tgt_vp_map) * |
| 6685 | MAX_MULTI_ID_FABRIC, GFP_KERNEL); |
| 6686 | if (!ha->tgt.tgt_vp_map) |
| 6687 | return -ENOMEM; |
| 6688 | |
| 6689 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 6690 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), |
| 6691 | &ha->tgt.atio_dma, GFP_KERNEL); |
| 6692 | if (!ha->tgt.atio_ring) { |
| 6693 | kfree(ha->tgt.tgt_vp_map); |
| 6694 | return -ENOMEM; |
| 6695 | } |
| 6696 | return 0; |
| 6697 | } |
| 6698 | |
| 6699 | void |
| 6700 | qlt_mem_free(struct qla_hw_data *ha) |
| 6701 | { |
| 6702 | if (!QLA_TGT_MODE_ENABLED()) |
| 6703 | return; |
| 6704 | |
| 6705 | if (ha->tgt.atio_ring) { |
| 6706 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * |
| 6707 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, |
| 6708 | ha->tgt.atio_dma); |
| 6709 | } |
| 6710 | kfree(ha->tgt.tgt_vp_map); |
| 6711 | } |
| 6712 | |
| 6713 | /* vport_slock to be held by the caller */ |
| 6714 | void |
| 6715 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) |
| 6716 | { |
| 6717 | if (!QLA_TGT_MODE_ENABLED()) |
| 6718 | return; |
| 6719 | |
| 6720 | switch (cmd) { |
| 6721 | case SET_VP_IDX: |
| 6722 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; |
| 6723 | break; |
| 6724 | case SET_AL_PA: |
| 6725 | vha->hw->tgt.tgt_vp_map[vha->d_id.b.al_pa].idx = vha->vp_idx; |
| 6726 | break; |
| 6727 | case RESET_VP_IDX: |
| 6728 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; |
| 6729 | break; |
| 6730 | case RESET_AL_PA: |
| 6731 | vha->hw->tgt.tgt_vp_map[vha->d_id.b.al_pa].idx = 0; |
| 6732 | break; |
| 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | static int __init qlt_parse_ini_mode(void) |
| 6737 | { |
| 6738 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) |
| 6739 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
| 6740 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) |
| 6741 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; |
| 6742 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) |
| 6743 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6744 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0) |
| 6745 | ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6746 | else |
| 6747 | return false; |
| 6748 | |
| 6749 | return true; |
| 6750 | } |
| 6751 | |
| 6752 | int __init qlt_init(void) |
| 6753 | { |
| 6754 | int ret; |
| 6755 | |
| 6756 | if (!qlt_parse_ini_mode()) { |
| 6757 | ql_log(ql_log_fatal, NULL, 0xe06b, |
| 6758 | "qlt_parse_ini_mode() failed\n"); |
| 6759 | return -EINVAL; |
| 6760 | } |
| 6761 | |
| 6762 | if (!QLA_TGT_MODE_ENABLED()) |
| 6763 | return 0; |
| 6764 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6765 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
| 6766 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct |
| 6767 | qla_tgt_mgmt_cmd), 0, NULL); |
| 6768 | if (!qla_tgt_mgmt_cmd_cachep) { |
| 6769 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 6770 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 6771 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6772 | } |
| 6773 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6774 | qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep", |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6775 | sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t), |
| 6776 | 0, NULL); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6777 | |
| 6778 | if (!qla_tgt_plogi_cachep) { |
| 6779 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 6780 | "kmem_cache_create for qla_tgt_plogi_cachep failed\n"); |
| 6781 | ret = -ENOMEM; |
| 6782 | goto out_mgmt_cmd_cachep; |
| 6783 | } |
| 6784 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6785 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, |
| 6786 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); |
| 6787 | if (!qla_tgt_mgmt_cmd_mempool) { |
| 6788 | ql_log(ql_log_fatal, NULL, 0xe06e, |
| 6789 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); |
| 6790 | ret = -ENOMEM; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6791 | goto out_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6792 | } |
| 6793 | |
| 6794 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); |
| 6795 | if (!qla_tgt_wq) { |
| 6796 | ql_log(ql_log_fatal, NULL, 0xe06f, |
| 6797 | "alloc_workqueue for qla_tgt_wq failed\n"); |
| 6798 | ret = -ENOMEM; |
| 6799 | goto out_cmd_mempool; |
| 6800 | } |
| 6801 | /* |
| 6802 | * Return 1 to signal that initiator-mode is being disabled |
| 6803 | */ |
| 6804 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; |
| 6805 | |
| 6806 | out_cmd_mempool: |
| 6807 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6808 | out_plogi_cachep: |
| 6809 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6810 | out_mgmt_cmd_cachep: |
| 6811 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6812 | return ret; |
| 6813 | } |
| 6814 | |
| 6815 | void qlt_exit(void) |
| 6816 | { |
| 6817 | if (!QLA_TGT_MODE_ENABLED()) |
| 6818 | return; |
| 6819 | |
| 6820 | destroy_workqueue(qla_tgt_wq); |
| 6821 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6822 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6823 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6824 | } |