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); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 133 | static void qlt_24xx_handle_abts(struct scsi_qla_host *, |
| 134 | struct abts_recv_from_24xx *); |
| 135 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 136 | /* |
| 137 | * Global Variables |
| 138 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 139 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 140 | static struct kmem_cache *qla_tgt_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 141 | static mempool_t *qla_tgt_mgmt_cmd_mempool; |
| 142 | static struct workqueue_struct *qla_tgt_wq; |
| 143 | static DEFINE_MUTEX(qla_tgt_mutex); |
| 144 | static LIST_HEAD(qla_tgt_glist); |
| 145 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 146 | /* This API intentionally takes dest as a parameter, rather than returning |
| 147 | * int value to avoid caller forgetting to issue wmb() after the store */ |
| 148 | void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest) |
| 149 | { |
| 150 | scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev); |
| 151 | *dest = atomic_inc_return(&base_vha->generation_tick); |
| 152 | /* memory barrier */ |
| 153 | wmb(); |
| 154 | } |
| 155 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 156 | /* Might release hw lock, then reaquire!! */ |
| 157 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) |
| 158 | { |
| 159 | /* Send marker if required */ |
| 160 | if (unlikely(vha->marker_needed != 0)) { |
| 161 | int rc = qla2x00_issue_marker(vha, vha_locked); |
| 162 | if (rc != QLA_SUCCESS) { |
| 163 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, |
| 164 | "qla_target(%d): issue_marker() failed\n", |
| 165 | vha->vp_idx); |
| 166 | } |
| 167 | return rc; |
| 168 | } |
| 169 | return QLA_SUCCESS; |
| 170 | } |
| 171 | |
| 172 | static inline |
| 173 | struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha, |
| 174 | uint8_t *d_id) |
| 175 | { |
| 176 | struct qla_hw_data *ha = vha->hw; |
| 177 | uint8_t vp_idx; |
| 178 | |
| 179 | if ((vha->d_id.b.area != d_id[1]) || (vha->d_id.b.domain != d_id[0])) |
| 180 | return NULL; |
| 181 | |
| 182 | if (vha->d_id.b.al_pa == d_id[2]) |
| 183 | return vha; |
| 184 | |
| 185 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 186 | vp_idx = ha->tgt.tgt_vp_map[d_id[2]].idx; |
| 187 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 188 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 189 | |
| 190 | return NULL; |
| 191 | } |
| 192 | |
| 193 | static inline |
| 194 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, |
| 195 | uint16_t vp_idx) |
| 196 | { |
| 197 | struct qla_hw_data *ha = vha->hw; |
| 198 | |
| 199 | if (vha->vp_idx == vp_idx) |
| 200 | return vha; |
| 201 | |
| 202 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 203 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 204 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 205 | |
| 206 | return NULL; |
| 207 | } |
| 208 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 209 | static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha) |
| 210 | { |
| 211 | unsigned long flags; |
| 212 | |
| 213 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 214 | |
| 215 | vha->hw->tgt.num_pend_cmds++; |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 216 | if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds) |
| 217 | vha->qla_stats.stat_max_pend_cmds = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 218 | vha->hw->tgt.num_pend_cmds; |
| 219 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 220 | } |
| 221 | static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha) |
| 222 | { |
| 223 | unsigned long flags; |
| 224 | |
| 225 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 226 | vha->hw->tgt.num_pend_cmds--; |
| 227 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 228 | } |
| 229 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 230 | |
| 231 | static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, |
| 232 | struct atio_from_isp *atio, uint8_t ha_locked) |
| 233 | { |
| 234 | struct qla_tgt_sess_op *u; |
| 235 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 236 | unsigned long flags; |
| 237 | |
| 238 | if (tgt->tgt_stop) { |
| 239 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 240 | "qla_target(%d): dropping unknown ATIO_TYPE7, " |
| 241 | "because tgt is being stopped", vha->vp_idx); |
| 242 | goto out_term; |
| 243 | } |
| 244 | |
| 245 | u = kzalloc(sizeof(*u), GFP_ATOMIC); |
| 246 | if (u == NULL) { |
| 247 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 248 | "Alloc of struct unknown_atio (size %zd) failed", sizeof(*u)); |
| 249 | /* It should be harmless and on the next retry should work well */ |
| 250 | goto out_term; |
| 251 | } |
| 252 | |
| 253 | u->vha = vha; |
| 254 | memcpy(&u->atio, atio, sizeof(*atio)); |
| 255 | INIT_LIST_HEAD(&u->cmd_list); |
| 256 | |
| 257 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 258 | list_add_tail(&u->cmd_list, &vha->unknown_atio_list); |
| 259 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 260 | |
| 261 | schedule_delayed_work(&vha->unknown_atio_work, 1); |
| 262 | |
| 263 | out: |
| 264 | return; |
| 265 | |
| 266 | out_term: |
| 267 | qlt_send_term_exchange(vha, NULL, atio, ha_locked, 0); |
| 268 | goto out; |
| 269 | } |
| 270 | |
| 271 | static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha, |
| 272 | uint8_t ha_locked) |
| 273 | { |
| 274 | struct qla_tgt_sess_op *u, *t; |
| 275 | scsi_qla_host_t *host; |
| 276 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 277 | unsigned long flags; |
| 278 | uint8_t queued = 0; |
| 279 | |
| 280 | list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) { |
| 281 | if (u->aborted) { |
| 282 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 283 | "Freeing unknown %s %p, because of Abort", |
| 284 | "ATIO_TYPE7", u); |
| 285 | qlt_send_term_exchange(vha, NULL, &u->atio, |
| 286 | ha_locked, 0); |
| 287 | goto abort; |
| 288 | } |
| 289 | |
| 290 | host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id); |
| 291 | if (host != NULL) { |
| 292 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 293 | "Requeuing unknown ATIO_TYPE7 %p", u); |
| 294 | qlt_24xx_atio_pkt(host, &u->atio, ha_locked); |
| 295 | } else if (tgt->tgt_stop) { |
| 296 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 297 | "Freeing unknown %s %p, because tgt is being stopped", |
| 298 | "ATIO_TYPE7", u); |
| 299 | qlt_send_term_exchange(vha, NULL, &u->atio, |
| 300 | ha_locked, 0); |
| 301 | } else { |
| 302 | ql_dbg(ql_dbg_async, vha, 0xffff, |
| 303 | "u %p, vha %p, host %p, sched again..", u, |
| 304 | vha, host); |
| 305 | if (!queued) { |
| 306 | queued = 1; |
| 307 | schedule_delayed_work(&vha->unknown_atio_work, |
| 308 | 1); |
| 309 | } |
| 310 | continue; |
| 311 | } |
| 312 | |
| 313 | abort: |
| 314 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 315 | list_del(&u->cmd_list); |
| 316 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 317 | kfree(u); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | void qlt_unknown_atio_work_fn(struct work_struct *work) |
| 322 | { |
| 323 | struct scsi_qla_host *vha = container_of(to_delayed_work(work), |
| 324 | struct scsi_qla_host, unknown_atio_work); |
| 325 | |
| 326 | qlt_try_to_dequeue_unknown_atios(vha, 0); |
| 327 | } |
| 328 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 329 | 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] | 330 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 331 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 332 | ql_dbg(ql_dbg_tgt, vha, 0xe072, |
| 333 | "%s: qla_target(%d): type %x ox_id %04x\n", |
| 334 | __func__, vha->vp_idx, atio->u.raw.entry_type, |
| 335 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 336 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 337 | switch (atio->u.raw.entry_type) { |
| 338 | case ATIO_TYPE7: |
| 339 | { |
| 340 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, |
| 341 | atio->u.isp24.fcp_hdr.d_id); |
| 342 | if (unlikely(NULL == host)) { |
| 343 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, |
| 344 | "qla_target(%d): Received ATIO_TYPE7 " |
| 345 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, |
| 346 | atio->u.isp24.fcp_hdr.d_id[0], |
| 347 | atio->u.isp24.fcp_hdr.d_id[1], |
| 348 | atio->u.isp24.fcp_hdr.d_id[2]); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 349 | |
| 350 | |
| 351 | qlt_queue_unknown_atio(vha, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 352 | break; |
| 353 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 354 | if (unlikely(!list_empty(&vha->unknown_atio_list))) |
| 355 | qlt_try_to_dequeue_unknown_atios(vha, ha_locked); |
| 356 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 357 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 358 | break; |
| 359 | } |
| 360 | |
| 361 | case IMMED_NOTIFY_TYPE: |
| 362 | { |
| 363 | struct scsi_qla_host *host = vha; |
| 364 | struct imm_ntfy_from_isp *entry = |
| 365 | (struct imm_ntfy_from_isp *)atio; |
| 366 | |
| 367 | if ((entry->u.isp24.vp_index != 0xFF) && |
| 368 | (entry->u.isp24.nport_handle != 0xFFFF)) { |
| 369 | host = qlt_find_host_by_vp_idx(vha, |
| 370 | entry->u.isp24.vp_index); |
| 371 | if (unlikely(!host)) { |
| 372 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, |
| 373 | "qla_target(%d): Received " |
| 374 | "ATIO (IMMED_NOTIFY_TYPE) " |
| 375 | "with unknown vp_index %d\n", |
| 376 | vha->vp_idx, entry->u.isp24.vp_index); |
| 377 | break; |
| 378 | } |
| 379 | } |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 380 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 381 | break; |
| 382 | } |
| 383 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 384 | case VP_RPT_ID_IOCB_TYPE: |
| 385 | qla24xx_report_id_acquisition(vha, |
| 386 | (struct vp_rpt_id_entry_24xx *)atio); |
| 387 | break; |
| 388 | |
| 389 | case ABTS_RECV_24XX: |
| 390 | { |
| 391 | struct abts_recv_from_24xx *entry = |
| 392 | (struct abts_recv_from_24xx *)atio; |
| 393 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 394 | entry->vp_index); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 395 | unsigned long flags; |
| 396 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 397 | if (unlikely(!host)) { |
| 398 | ql_dbg(ql_dbg_tgt, vha, 0xffff, |
| 399 | "qla_target(%d): Response pkt (ABTS_RECV_24XX) " |
| 400 | "received, with unknown vp_index %d\n", |
| 401 | vha->vp_idx, entry->vp_index); |
| 402 | break; |
| 403 | } |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 404 | if (!ha_locked) |
| 405 | spin_lock_irqsave(&host->hw->hardware_lock, flags); |
| 406 | qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio); |
| 407 | if (!ha_locked) |
| 408 | spin_unlock_irqrestore(&host->hw->hardware_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 409 | break; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */ |
| 413 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 414 | default: |
| 415 | ql_dbg(ql_dbg_tgt, vha, 0xe040, |
| 416 | "qla_target(%d): Received unknown ATIO atio " |
| 417 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 418 | break; |
| 419 | } |
| 420 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 421 | return false; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, response_t *pkt) |
| 425 | { |
| 426 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 427 | case CTIO_CRC2: |
| 428 | ql_dbg(ql_dbg_tgt, vha, 0xe073, |
| 429 | "qla_target(%d):%s: CRC2 Response pkt\n", |
| 430 | vha->vp_idx, __func__); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 431 | case CTIO_TYPE7: |
| 432 | { |
| 433 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
| 434 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 435 | entry->vp_index); |
| 436 | if (unlikely(!host)) { |
| 437 | ql_dbg(ql_dbg_tgt, vha, 0xe041, |
| 438 | "qla_target(%d): Response pkt (CTIO_TYPE7) " |
| 439 | "received, with unknown vp_index %d\n", |
| 440 | vha->vp_idx, entry->vp_index); |
| 441 | break; |
| 442 | } |
| 443 | qlt_response_pkt(host, pkt); |
| 444 | break; |
| 445 | } |
| 446 | |
| 447 | case IMMED_NOTIFY_TYPE: |
| 448 | { |
| 449 | struct scsi_qla_host *host = vha; |
| 450 | struct imm_ntfy_from_isp *entry = |
| 451 | (struct imm_ntfy_from_isp *)pkt; |
| 452 | |
| 453 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); |
| 454 | if (unlikely(!host)) { |
| 455 | ql_dbg(ql_dbg_tgt, vha, 0xe042, |
| 456 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " |
| 457 | "received, with unknown vp_index %d\n", |
| 458 | vha->vp_idx, entry->u.isp24.vp_index); |
| 459 | break; |
| 460 | } |
| 461 | qlt_response_pkt(host, pkt); |
| 462 | break; |
| 463 | } |
| 464 | |
| 465 | case NOTIFY_ACK_TYPE: |
| 466 | { |
| 467 | struct scsi_qla_host *host = vha; |
| 468 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 469 | |
| 470 | if (0xFF != entry->u.isp24.vp_index) { |
| 471 | host = qlt_find_host_by_vp_idx(vha, |
| 472 | entry->u.isp24.vp_index); |
| 473 | if (unlikely(!host)) { |
| 474 | ql_dbg(ql_dbg_tgt, vha, 0xe043, |
| 475 | "qla_target(%d): Response " |
| 476 | "pkt (NOTIFY_ACK_TYPE) " |
| 477 | "received, with unknown " |
| 478 | "vp_index %d\n", vha->vp_idx, |
| 479 | entry->u.isp24.vp_index); |
| 480 | break; |
| 481 | } |
| 482 | } |
| 483 | qlt_response_pkt(host, pkt); |
| 484 | break; |
| 485 | } |
| 486 | |
| 487 | case ABTS_RECV_24XX: |
| 488 | { |
| 489 | struct abts_recv_from_24xx *entry = |
| 490 | (struct abts_recv_from_24xx *)pkt; |
| 491 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 492 | entry->vp_index); |
| 493 | if (unlikely(!host)) { |
| 494 | ql_dbg(ql_dbg_tgt, vha, 0xe044, |
| 495 | "qla_target(%d): Response pkt " |
| 496 | "(ABTS_RECV_24XX) received, with unknown " |
| 497 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 498 | break; |
| 499 | } |
| 500 | qlt_response_pkt(host, pkt); |
| 501 | break; |
| 502 | } |
| 503 | |
| 504 | case ABTS_RESP_24XX: |
| 505 | { |
| 506 | struct abts_resp_to_24xx *entry = |
| 507 | (struct abts_resp_to_24xx *)pkt; |
| 508 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 509 | entry->vp_index); |
| 510 | if (unlikely(!host)) { |
| 511 | ql_dbg(ql_dbg_tgt, vha, 0xe045, |
| 512 | "qla_target(%d): Response pkt " |
| 513 | "(ABTS_RECV_24XX) received, with unknown " |
| 514 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 515 | break; |
| 516 | } |
| 517 | qlt_response_pkt(host, pkt); |
| 518 | break; |
| 519 | } |
| 520 | |
| 521 | default: |
| 522 | qlt_response_pkt(vha, pkt); |
| 523 | break; |
| 524 | } |
| 525 | |
| 526 | } |
| 527 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 528 | /* |
| 529 | * All qlt_plogi_ack_t operations are protected by hardware_lock |
| 530 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 531 | static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 532 | struct imm_ntfy_from_isp *ntfy, int type) |
| 533 | { |
| 534 | struct qla_work_evt *e; |
| 535 | e = qla2x00_alloc_work(vha, QLA_EVT_NACK); |
| 536 | if (!e) |
| 537 | return QLA_FUNCTION_FAILED; |
| 538 | |
| 539 | e->u.nack.fcport = fcport; |
| 540 | e->u.nack.type = type; |
| 541 | memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp)); |
| 542 | return qla2x00_post_work(vha, e); |
| 543 | } |
| 544 | |
| 545 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 546 | void qla2x00_async_nack_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 547 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 548 | struct srb *sp = (struct srb *)s; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 549 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 550 | unsigned long flags; |
| 551 | |
| 552 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 553 | "Async done-%s res %x %8phC type %d\n", |
| 554 | sp->name, res, sp->fcport->port_name, sp->type); |
| 555 | |
| 556 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 557 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
| 558 | sp->fcport->chip_reset = vha->hw->chip_reset; |
| 559 | |
| 560 | switch (sp->type) { |
| 561 | case SRB_NACK_PLOGI: |
| 562 | sp->fcport->login_gen++; |
| 563 | sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP; |
| 564 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame^] | 565 | sp->fcport->plogi_nack_done_deadline = jiffies + HZ; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 566 | break; |
| 567 | |
| 568 | case SRB_NACK_PRLI: |
| 569 | sp->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 570 | sp->fcport->deleted = 0; |
| 571 | |
| 572 | if (!sp->fcport->login_succ && |
| 573 | !IS_SW_RESV_ADDR(sp->fcport->d_id)) { |
| 574 | sp->fcport->login_succ = 1; |
| 575 | |
| 576 | vha->fcport_count++; |
| 577 | |
| 578 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 579 | !vha->hw->flags.gpsc_supported) { |
| 580 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 581 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 582 | __func__, __LINE__, |
| 583 | sp->fcport->port_name, |
| 584 | vha->fcport_count); |
| 585 | |
| 586 | qla24xx_post_upd_fcport_work(vha, sp->fcport); |
| 587 | } else { |
| 588 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 589 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 590 | __func__, __LINE__, |
| 591 | sp->fcport->port_name, |
| 592 | vha->fcport_count); |
| 593 | |
| 594 | qla24xx_post_gpsc_work(vha, sp->fcport); |
| 595 | } |
| 596 | } |
| 597 | break; |
| 598 | |
| 599 | case SRB_NACK_LOGO: |
| 600 | sp->fcport->login_gen++; |
| 601 | sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 602 | qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE); |
| 603 | break; |
| 604 | } |
| 605 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 606 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 607 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport, |
| 611 | struct imm_ntfy_from_isp *ntfy, int type) |
| 612 | { |
| 613 | int rval = QLA_FUNCTION_FAILED; |
| 614 | srb_t *sp; |
| 615 | char *c = NULL; |
| 616 | |
| 617 | fcport->flags |= FCF_ASYNC_SENT; |
| 618 | switch (type) { |
| 619 | case SRB_NACK_PLOGI: |
| 620 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; |
| 621 | c = "PLOGI"; |
| 622 | break; |
| 623 | case SRB_NACK_PRLI: |
| 624 | fcport->fw_login_state = DSC_LS_PRLI_PEND; |
| 625 | c = "PRLI"; |
| 626 | break; |
| 627 | case SRB_NACK_LOGO: |
| 628 | fcport->fw_login_state = DSC_LS_LOGO_PEND; |
| 629 | c = "LOGO"; |
| 630 | break; |
| 631 | } |
| 632 | |
| 633 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
| 634 | if (!sp) |
| 635 | goto done; |
| 636 | |
| 637 | sp->type = type; |
| 638 | sp->name = "nack"; |
| 639 | |
| 640 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 641 | |
| 642 | sp->u.iocb_cmd.u.nack.ntfy = ntfy; |
| 643 | |
| 644 | sp->done = qla2x00_async_nack_sp_done; |
| 645 | |
| 646 | rval = qla2x00_start_sp(sp); |
| 647 | if (rval != QLA_SUCCESS) |
| 648 | goto done_free_sp; |
| 649 | |
| 650 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 651 | "Async-%s %8phC hndl %x %s\n", |
| 652 | sp->name, fcport->port_name, sp->handle, c); |
| 653 | |
| 654 | return rval; |
| 655 | |
| 656 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 657 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 658 | done: |
| 659 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 660 | return rval; |
| 661 | } |
| 662 | |
| 663 | void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
| 664 | { |
| 665 | fc_port_t *t; |
| 666 | unsigned long flags; |
| 667 | |
| 668 | switch (e->u.nack.type) { |
| 669 | case SRB_NACK_PRLI: |
| 670 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 671 | t = qlt_create_sess(vha, e->u.nack.fcport, 0); |
| 672 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 673 | if (t) { |
| 674 | ql_log(ql_log_info, vha, 0xffff, |
| 675 | "%s create sess success %p", __func__, t); |
| 676 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 677 | /* create sess has an extra kref */ |
| 678 | vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport); |
| 679 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 680 | } |
| 681 | break; |
| 682 | } |
| 683 | qla24xx_async_notify_ack(vha, e->u.nack.fcport, |
| 684 | (struct imm_ntfy_from_isp*)e->u.nack.iocb, e->u.nack.type); |
| 685 | } |
| 686 | |
| 687 | void qla24xx_delete_sess_fn(struct work_struct *work) |
| 688 | { |
| 689 | fc_port_t *fcport = container_of(work, struct fc_port, del_work); |
| 690 | struct qla_hw_data *ha = fcport->vha->hw; |
| 691 | unsigned long flags; |
| 692 | |
| 693 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 694 | |
| 695 | if (fcport->se_sess) { |
| 696 | ha->tgt.tgt_ops->shutdown_sess(fcport); |
| 697 | ha->tgt.tgt_ops->put_sess(fcport); |
| 698 | } else { |
| 699 | qlt_unreg_sess(fcport); |
| 700 | } |
| 701 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 702 | } |
| 703 | |
| 704 | /* |
| 705 | * Called from qla2x00_reg_remote_port() |
| 706 | */ |
| 707 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 708 | { |
| 709 | struct qla_hw_data *ha = vha->hw; |
| 710 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 711 | struct fc_port *sess = fcport; |
| 712 | unsigned long flags; |
| 713 | |
| 714 | if (!vha->hw->tgt.tgt_ops) |
| 715 | return; |
| 716 | |
| 717 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 718 | if (tgt->tgt_stop) { |
| 719 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 720 | return; |
| 721 | } |
| 722 | |
| 723 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 724 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 725 | return; |
| 726 | } |
| 727 | |
| 728 | if (!sess->se_sess) { |
| 729 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 730 | |
| 731 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 732 | sess = qlt_create_sess(vha, fcport, false); |
| 733 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 734 | |
| 735 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 736 | } else { |
| 737 | if (fcport->fw_login_state == DSC_LS_PRLI_COMP) { |
| 738 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 743 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 744 | "%s: kref_get fail sess %8phC \n", |
| 745 | __func__, sess->port_name); |
| 746 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 747 | return; |
| 748 | } |
| 749 | |
| 750 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, |
| 751 | "qla_target(%u): %ssession for port %8phC " |
| 752 | "(loop ID %d) reappeared\n", vha->vp_idx, |
| 753 | sess->local ? "local " : "", sess->port_name, sess->loop_id); |
| 754 | |
| 755 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, |
| 756 | "Reappeared sess %p\n", sess); |
| 757 | |
| 758 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, |
| 759 | fcport->loop_id, |
| 760 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
| 761 | } |
| 762 | |
| 763 | if (sess && sess->local) { |
| 764 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, |
| 765 | "qla_target(%u): local session for " |
| 766 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
| 767 | fcport->port_name, sess->loop_id); |
| 768 | sess->local = 0; |
| 769 | } |
| 770 | ha->tgt.tgt_ops->put_sess(sess); |
| 771 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 772 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 773 | |
| 774 | /* |
| 775 | * This is a zero-base ref-counting solution, since hardware_lock |
| 776 | * guarantees that ref_count is not modified concurrently. |
| 777 | * Upon successful return content of iocb is undefined |
| 778 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 779 | static struct qlt_plogi_ack_t * |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 780 | qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id, |
| 781 | struct imm_ntfy_from_isp *iocb) |
| 782 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 783 | struct qlt_plogi_ack_t *pla; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 784 | |
| 785 | list_for_each_entry(pla, &vha->plogi_ack_list, list) { |
| 786 | if (pla->id.b24 == id->b24) { |
| 787 | qlt_send_term_imm_notif(vha, &pla->iocb, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 788 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 789 | return pla; |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC); |
| 794 | if (!pla) { |
| 795 | ql_dbg(ql_dbg_async, vha, 0x5088, |
| 796 | "qla_target(%d): Allocation of plogi_ack failed\n", |
| 797 | vha->vp_idx); |
| 798 | return NULL; |
| 799 | } |
| 800 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 801 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 802 | pla->id = *id; |
| 803 | list_add_tail(&pla->list, &vha->plogi_ack_list); |
| 804 | |
| 805 | return pla; |
| 806 | } |
| 807 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 808 | void qlt_plogi_ack_unref(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 809 | struct qlt_plogi_ack_t *pla) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 810 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 811 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 812 | port_id_t port_id; |
| 813 | uint16_t loop_id; |
| 814 | fc_port_t *fcport = pla->fcport; |
| 815 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 816 | BUG_ON(!pla->ref_count); |
| 817 | pla->ref_count--; |
| 818 | |
| 819 | if (pla->ref_count) |
| 820 | return; |
| 821 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 822 | ql_dbg(ql_dbg_disc, vha, 0x5089, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 823 | "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] | 824 | " exch %#x ox_id %#x\n", iocb->u.isp24.port_name, |
| 825 | iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1], |
| 826 | iocb->u.isp24.port_id[0], |
| 827 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 828 | iocb->u.isp24.exchange_address, iocb->ox_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 829 | |
| 830 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 831 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 832 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 833 | port_id.b.rsvd_1 = 0; |
| 834 | |
| 835 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 836 | |
| 837 | fcport->loop_id = loop_id; |
| 838 | fcport->d_id = port_id; |
| 839 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI); |
| 840 | |
| 841 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 842 | if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla) |
| 843 | fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 844 | if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla) |
| 845 | fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
| 846 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 847 | |
| 848 | list_del(&pla->list); |
| 849 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 850 | } |
| 851 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 852 | void |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 853 | qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla, |
| 854 | struct fc_port *sess, enum qlt_plogi_link_t link) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 855 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 856 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 857 | /* Inc ref_count first because link might already be pointing at pla */ |
| 858 | pla->ref_count++; |
| 859 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 860 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097, |
| 861 | "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC" |
| 862 | " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n", |
| 863 | sess, link, sess->port_name, |
| 864 | iocb->u.isp24.port_name, iocb->u.isp24.port_id[2], |
| 865 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 866 | pla->ref_count, pla, link); |
| 867 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 868 | if (sess->plogi_link[link]) |
| 869 | qlt_plogi_ack_unref(vha, sess->plogi_link[link]); |
| 870 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 871 | if (link == QLT_PLOGI_LINK_SAME_WWN) |
| 872 | pla->fcport = sess; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 873 | |
| 874 | sess->plogi_link[link] = pla; |
| 875 | } |
| 876 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 877 | typedef struct { |
| 878 | /* These fields must be initialized by the caller */ |
| 879 | port_id_t id; |
| 880 | /* |
| 881 | * number of cmds dropped while we were waiting for |
| 882 | * initiator to ack LOGO initialize to 1 if LOGO is |
| 883 | * triggered by a command, otherwise, to 0 |
| 884 | */ |
| 885 | int cmd_count; |
| 886 | |
| 887 | /* These fields are used by callee */ |
| 888 | struct list_head list; |
| 889 | } qlt_port_logo_t; |
| 890 | |
| 891 | static void |
| 892 | qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo) |
| 893 | { |
| 894 | qlt_port_logo_t *tmp; |
| 895 | int res; |
| 896 | |
| 897 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 898 | |
| 899 | list_for_each_entry(tmp, &vha->logo_list, list) { |
| 900 | if (tmp->id.b24 == logo->id.b24) { |
| 901 | tmp->cmd_count += logo->cmd_count; |
| 902 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 903 | return; |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | list_add_tail(&logo->list, &vha->logo_list); |
| 908 | |
| 909 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 910 | |
| 911 | res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id); |
| 912 | |
| 913 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 914 | list_del(&logo->list); |
| 915 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 916 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 917 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098, |
| 918 | "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n", |
| 919 | logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa, |
| 920 | logo->cmd_count, res); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 921 | } |
| 922 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 923 | static void qlt_free_session_done(struct work_struct *work) |
| 924 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 925 | struct fc_port *sess = container_of(work, struct fc_port, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 926 | free_work); |
| 927 | struct qla_tgt *tgt = sess->tgt; |
| 928 | struct scsi_qla_host *vha = sess->vha; |
| 929 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 930 | unsigned long flags; |
| 931 | bool logout_started = false; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 932 | struct event_arg ea; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 933 | scsi_qla_host_t *base_vha; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 934 | |
| 935 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf084, |
| 936 | "%s: se_sess %p / sess %p from port %8phC loop_id %#04x" |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 937 | " 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] | 938 | __func__, sess->se_sess, sess, sess->port_name, sess->loop_id, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 939 | 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] | 940 | sess->logout_on_delete, sess->keep_nport_handle, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 941 | sess->send_els_logo); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 942 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 943 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 944 | if (!IS_SW_RESV_ADDR(sess->d_id)) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 945 | if (sess->send_els_logo) { |
| 946 | qlt_port_logo_t logo; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 947 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 948 | logo.id = sess->d_id; |
| 949 | logo.cmd_count = 0; |
| 950 | qlt_send_first_logo(vha, &logo); |
| 951 | } |
| 952 | |
| 953 | if (sess->logout_on_delete) { |
| 954 | int rc; |
| 955 | |
| 956 | rc = qla2x00_post_async_logout_work(vha, sess, NULL); |
| 957 | if (rc != QLA_SUCCESS) |
| 958 | ql_log(ql_log_warn, vha, 0xf085, |
| 959 | "Schedule logo failed sess %p rc %d\n", |
| 960 | sess, rc); |
| 961 | else |
| 962 | logout_started = true; |
| 963 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 964 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 965 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 966 | /* |
| 967 | * Release the target session for FC Nexus from fabric module code. |
| 968 | */ |
| 969 | if (sess->se_sess != NULL) |
| 970 | ha->tgt.tgt_ops->free_session(sess); |
| 971 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 972 | if (logout_started) { |
| 973 | bool traced = false; |
| 974 | |
| 975 | while (!ACCESS_ONCE(sess->logout_completed)) { |
| 976 | if (!traced) { |
| 977 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf086, |
| 978 | "%s: waiting for sess %p logout\n", |
| 979 | __func__, sess); |
| 980 | traced = true; |
| 981 | } |
| 982 | msleep(100); |
| 983 | } |
| 984 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 985 | ql_dbg(ql_dbg_disc, vha, 0xf087, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 986 | "%s: sess %p logout completed\n",__func__, sess); |
| 987 | } |
| 988 | |
| 989 | if (sess->logo_ack_needed) { |
| 990 | sess->logo_ack_needed = 0; |
| 991 | qla24xx_async_notify_ack(vha, sess, |
| 992 | (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 993 | } |
| 994 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 995 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 996 | if (sess->se_sess) { |
| 997 | sess->se_sess = NULL; |
| 998 | if (tgt && !IS_SW_RESV_ADDR(sess->d_id)) |
| 999 | tgt->sess_count--; |
| 1000 | } |
| 1001 | |
| 1002 | sess->disc_state = DSC_DELETED; |
| 1003 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1004 | sess->deleted = QLA_SESS_DELETED; |
| 1005 | sess->login_retry = vha->hw->login_retry_count; |
| 1006 | |
| 1007 | if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) { |
| 1008 | vha->fcport_count--; |
| 1009 | sess->login_succ = 0; |
| 1010 | } |
| 1011 | |
| 1012 | if (sess->chip_reset != sess->vha->hw->chip_reset) |
| 1013 | qla2x00_clear_loop_id(sess); |
| 1014 | |
| 1015 | if (sess->conflict) { |
| 1016 | sess->conflict->login_pause = 0; |
| 1017 | sess->conflict = NULL; |
| 1018 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 1019 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1020 | } |
| 1021 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1022 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1023 | struct qlt_plogi_ack_t *own = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1024 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1025 | struct qlt_plogi_ack_t *con = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1026 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1027 | struct imm_ntfy_from_isp *iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1028 | |
| 1029 | if (con) { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1030 | iocb = &con->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1031 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1032 | "se_sess %p / sess %p port %8phC is gone," |
| 1033 | " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n", |
| 1034 | sess->se_sess, sess, sess->port_name, |
| 1035 | own ? "releasing own PLOGI" : "no own PLOGI pending", |
| 1036 | own ? own->ref_count : -1, |
| 1037 | iocb->u.isp24.port_name, con->ref_count); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1038 | qlt_plogi_ack_unref(vha, con); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1039 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1040 | } else { |
| 1041 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a, |
| 1042 | "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n", |
| 1043 | sess->se_sess, sess, sess->port_name, |
| 1044 | own ? "releasing own PLOGI" : |
| 1045 | "no own PLOGI pending", |
| 1046 | own ? own->ref_count : -1); |
| 1047 | } |
| 1048 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1049 | if (own) { |
| 1050 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1051 | qlt_plogi_ack_unref(vha, own); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1052 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 1053 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1054 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1055 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1056 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1057 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1058 | "Unregistration of sess %p %8phC finished fcp_cnt %d\n", |
| 1059 | sess, sess->port_name, vha->fcport_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1060 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1061 | if (tgt && (tgt->sess_count == 0)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1062 | wake_up_all(&tgt->waitQ); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1063 | |
| 1064 | if (vha->fcport_count == 0) |
| 1065 | wake_up_all(&vha->fcport_waitQ); |
| 1066 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1067 | base_vha = pci_get_drvdata(ha->pdev); |
| 1068 | if (test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags)) |
| 1069 | return; |
| 1070 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1071 | if (!tgt || !tgt->tgt_stop) { |
| 1072 | memset(&ea, 0, sizeof(ea)); |
| 1073 | ea.event = FCME_DELETE_DONE; |
| 1074 | ea.fcport = sess; |
| 1075 | qla2x00_fcport_event_handler(vha, &ea); |
| 1076 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1077 | } |
| 1078 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1079 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1080 | void qlt_unreg_sess(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1081 | { |
| 1082 | struct scsi_qla_host *vha = sess->vha; |
| 1083 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1084 | ql_dbg(ql_dbg_disc, sess->vha, 0xffff, |
| 1085 | "%s sess %p for deletion %8phC\n", |
| 1086 | __func__, sess, sess->port_name); |
| 1087 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 1088 | if (sess->se_sess) |
| 1089 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1090 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1091 | qla2x00_mark_device_lost(vha, sess, 1, 1); |
| 1092 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1093 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1094 | sess->disc_state = DSC_DELETE_PEND; |
| 1095 | sess->last_rscn_gen = sess->rscn_gen; |
| 1096 | sess->last_login_gen = sess->login_gen; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1097 | |
| 1098 | INIT_WORK(&sess->free_work, qlt_free_session_done); |
| 1099 | schedule_work(&sess->free_work); |
| 1100 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1101 | EXPORT_SYMBOL(qlt_unreg_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1102 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1103 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) |
| 1104 | { |
| 1105 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1106 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1107 | uint16_t loop_id; |
| 1108 | int res = 0; |
| 1109 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1110 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1111 | |
| 1112 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); |
| 1113 | if (loop_id == 0xFFFF) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1114 | /* Global event */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1115 | atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1116 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1117 | qlt_clear_tgt_db(vha->vha_tgt.qla_tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1118 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1119 | } else { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1120 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1121 | 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] | 1122 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | ql_dbg(ql_dbg_tgt, vha, 0xe000, |
| 1126 | "Using sess for qla_tgt_reset: %p\n", sess); |
| 1127 | if (!sess) { |
| 1128 | res = -ESRCH; |
| 1129 | return res; |
| 1130 | } |
| 1131 | |
| 1132 | ql_dbg(ql_dbg_tgt, vha, 0xe047, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1133 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
| 1134 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1135 | mcmd, loop_id); |
| 1136 | |
Quinn Tran | bb1181c | 2016-12-23 18:06:05 -0800 | [diff] [blame] | 1137 | 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] | 1138 | } |
| 1139 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1140 | static void qla24xx_chk_fcp_state(struct fc_port *sess) |
| 1141 | { |
| 1142 | if (sess->chip_reset != sess->vha->hw->chip_reset) { |
| 1143 | sess->logout_on_delete = 0; |
| 1144 | sess->logo_ack_needed = 0; |
| 1145 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1146 | sess->scan_state = 0; |
| 1147 | } |
| 1148 | } |
| 1149 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1150 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1151 | void qlt_schedule_sess_for_deletion(struct fc_port *sess, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1152 | bool immediate) |
| 1153 | { |
| 1154 | struct qla_tgt *tgt = sess->tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1155 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1156 | if (sess->disc_state == DSC_DELETE_PEND) |
| 1157 | return; |
| 1158 | |
| 1159 | if (sess->disc_state == DSC_DELETED) { |
| 1160 | if (tgt && tgt->tgt_stop && (tgt->sess_count == 0)) |
| 1161 | wake_up_all(&tgt->waitQ); |
| 1162 | if (sess->vha->fcport_count == 0) |
| 1163 | wake_up_all(&sess->vha->fcport_waitQ); |
| 1164 | |
| 1165 | if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] && |
| 1166 | !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1167 | return; |
| 1168 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1169 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1170 | sess->disc_state = DSC_DELETE_PEND; |
| 1171 | |
| 1172 | if (sess->deleted == QLA_SESS_DELETED) |
| 1173 | sess->logout_on_delete = 0; |
| 1174 | |
| 1175 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
| 1176 | qla24xx_chk_fcp_state(sess); |
| 1177 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1178 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, |
| 1179 | "Scheduling sess %p for deletion\n", sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1180 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1181 | schedule_work(&sess->del_work); |
| 1182 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1183 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1184 | void qlt_schedule_sess_for_deletion_lock(struct fc_port *sess) |
| 1185 | { |
| 1186 | unsigned long flags; |
| 1187 | struct qla_hw_data *ha = sess->vha->hw; |
| 1188 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1189 | qlt_schedule_sess_for_deletion(sess, 1); |
| 1190 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1191 | } |
| 1192 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1193 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1194 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1195 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1196 | struct fc_port *sess; |
| 1197 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1198 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1199 | list_for_each_entry(sess, &vha->vp_fcports, list) { |
| 1200 | if (sess->se_sess) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1201 | qlt_schedule_sess_for_deletion(sess, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1202 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1203 | |
| 1204 | /* At this point tgt could be already dead */ |
| 1205 | } |
| 1206 | |
| 1207 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id, |
| 1208 | uint16_t *loop_id) |
| 1209 | { |
| 1210 | struct qla_hw_data *ha = vha->hw; |
| 1211 | dma_addr_t gid_list_dma; |
| 1212 | struct gid_list_info *gid_list; |
| 1213 | char *id_iter; |
| 1214 | int res, rc, i; |
| 1215 | uint16_t entries; |
| 1216 | |
| 1217 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1218 | &gid_list_dma, GFP_KERNEL); |
| 1219 | if (!gid_list) { |
| 1220 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, |
| 1221 | "qla_target(%d): DMA Alloc failed of %u\n", |
| 1222 | vha->vp_idx, qla2x00_gid_list_size(ha)); |
| 1223 | return -ENOMEM; |
| 1224 | } |
| 1225 | |
| 1226 | /* Get list of logged in devices */ |
| 1227 | rc = qla2x00_get_id_list(vha, gid_list, gid_list_dma, &entries); |
| 1228 | if (rc != QLA_SUCCESS) { |
| 1229 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, |
| 1230 | "qla_target(%d): get_id_list() failed: %x\n", |
| 1231 | vha->vp_idx, rc); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1232 | res = -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1233 | goto out_free_id_list; |
| 1234 | } |
| 1235 | |
| 1236 | id_iter = (char *)gid_list; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1237 | res = -ENOENT; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1238 | for (i = 0; i < entries; i++) { |
| 1239 | struct gid_list_info *gid = (struct gid_list_info *)id_iter; |
| 1240 | if ((gid->al_pa == s_id[2]) && |
| 1241 | (gid->area == s_id[1]) && |
| 1242 | (gid->domain == s_id[0])) { |
| 1243 | *loop_id = le16_to_cpu(gid->loop_id); |
| 1244 | res = 0; |
| 1245 | break; |
| 1246 | } |
| 1247 | id_iter += ha->gid_list_info_size; |
| 1248 | } |
| 1249 | |
| 1250 | out_free_id_list: |
| 1251 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1252 | gid_list, gid_list_dma); |
| 1253 | return res; |
| 1254 | } |
| 1255 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1256 | /* |
| 1257 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. |
| 1258 | * Caller must put it. |
| 1259 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1260 | static struct fc_port *qlt_create_sess( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1261 | struct scsi_qla_host *vha, |
| 1262 | fc_port_t *fcport, |
| 1263 | bool local) |
| 1264 | { |
| 1265 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1266 | struct fc_port *sess = fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1267 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1268 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1269 | if (vha->vha_tgt.qla_tgt->tgt_stop) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1270 | return NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1271 | |
| 1272 | if (fcport->se_sess) { |
| 1273 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 1274 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1275 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1276 | __func__, sess->port_name); |
| 1277 | return NULL; |
| 1278 | } |
| 1279 | return fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1280 | } |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1281 | sess->tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1282 | sess->local = local; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1283 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1284 | /* |
| 1285 | * Under normal circumstances we want to logout from firmware when |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1286 | * session eventually ends and release corresponding nport handle. |
| 1287 | * In the exception cases (e.g. when new PLOGI is waiting) corresponding |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1288 | * code will adjust these flags as necessary. |
| 1289 | */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1290 | sess->logout_on_delete = 1; |
| 1291 | sess->keep_nport_handle = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1292 | sess->logout_completed = 0; |
| 1293 | |
| 1294 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 1295 | &fcport->port_name[0], sess) < 0) { |
| 1296 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xffff, |
| 1297 | "(%d) %8phC check_initiator_node_acl failed\n", |
| 1298 | vha->vp_idx, fcport->port_name); |
| 1299 | return NULL; |
| 1300 | } else { |
| 1301 | kref_init(&fcport->sess_kref); |
| 1302 | /* |
| 1303 | * Take an extra reference to ->sess_kref here to handle |
| 1304 | * fc_port access across ->tgt.sess_lock reaquire. |
| 1305 | */ |
| 1306 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 1307 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1308 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1309 | __func__, sess->port_name); |
| 1310 | return NULL; |
| 1311 | } |
| 1312 | |
| 1313 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1314 | if (!IS_SW_RESV_ADDR(sess->d_id)) |
| 1315 | vha->vha_tgt.qla_tgt->sess_count++; |
| 1316 | |
| 1317 | qlt_do_generation_tick(vha, &sess->generation); |
| 1318 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1319 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1320 | |
| 1321 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1322 | "Adding sess %p se_sess %p to tgt %p sess_count %d\n", |
| 1323 | sess, sess->se_sess, vha->vha_tgt.qla_tgt, |
| 1324 | vha->vha_tgt.qla_tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1325 | |
| 1326 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1327 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
| 1328 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", |
| 1329 | vha->vp_idx, local ? "local " : "", fcport->port_name, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 1330 | fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area, |
| 1331 | sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1332 | |
| 1333 | return sess; |
| 1334 | } |
| 1335 | |
| 1336 | /* |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1337 | * max_gen - specifies maximum session generation |
| 1338 | * at which this deletion requestion is still valid |
| 1339 | */ |
| 1340 | void |
| 1341 | 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] | 1342 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1343 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1344 | struct fc_port *sess = fcport; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1345 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1346 | |
| 1347 | if (!vha->hw->tgt.tgt_ops) |
| 1348 | return; |
| 1349 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1350 | if (!tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1351 | return; |
| 1352 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1353 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1354 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1355 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1356 | return; |
| 1357 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1358 | if (!sess->se_sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1359 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1360 | return; |
| 1361 | } |
| 1362 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1363 | if (max_gen - sess->generation < 0) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1364 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1365 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092, |
| 1366 | "Ignoring stale deletion request for se_sess %p / sess %p" |
| 1367 | " for port %8phC, req_gen %d, sess_gen %d\n", |
| 1368 | sess->se_sess, sess, sess->port_name, max_gen, |
| 1369 | sess->generation); |
| 1370 | return; |
| 1371 | } |
| 1372 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1373 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); |
| 1374 | |
| 1375 | sess->local = 1; |
| 1376 | qlt_schedule_sess_for_deletion(sess, false); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1377 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) |
| 1381 | { |
| 1382 | struct qla_hw_data *ha = tgt->ha; |
| 1383 | unsigned long flags; |
| 1384 | int res; |
| 1385 | /* |
| 1386 | * We need to protect against race, when tgt is freed before or |
| 1387 | * inside wake_up() |
| 1388 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1389 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1390 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1391 | "tgt %p, sess_count=%d\n", |
| 1392 | tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1393 | res = (tgt->sess_count == 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1394 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1395 | |
| 1396 | return res; |
| 1397 | } |
| 1398 | |
| 1399 | /* Called by tcm_qla2xxx configfs code */ |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1400 | int qlt_stop_phase1(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1401 | { |
| 1402 | struct scsi_qla_host *vha = tgt->vha; |
| 1403 | struct qla_hw_data *ha = tgt->ha; |
| 1404 | unsigned long flags; |
| 1405 | |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1406 | mutex_lock(&qla_tgt_mutex); |
| 1407 | if (!vha->fc_vport) { |
| 1408 | struct Scsi_Host *sh = vha->host; |
| 1409 | struct fc_host_attrs *fc_host = shost_to_fc_host(sh); |
| 1410 | bool npiv_vports; |
| 1411 | |
| 1412 | spin_lock_irqsave(sh->host_lock, flags); |
| 1413 | npiv_vports = (fc_host->npiv_vports_inuse); |
| 1414 | spin_unlock_irqrestore(sh->host_lock, flags); |
| 1415 | |
| 1416 | if (npiv_vports) { |
| 1417 | mutex_unlock(&qla_tgt_mutex); |
| 1418 | return -EPERM; |
| 1419 | } |
| 1420 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1421 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
| 1422 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, |
| 1423 | "Already in tgt->tgt_stop or tgt_stopped state\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1424 | mutex_unlock(&qla_tgt_mutex); |
| 1425 | return -EPERM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | ql_dbg(ql_dbg_tgt, vha, 0xe003, "Stopping target for host %ld(%p)\n", |
| 1429 | vha->host_no, vha); |
| 1430 | /* |
| 1431 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. |
| 1432 | * Lock is needed, because we still can get an incoming packet. |
| 1433 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1434 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1435 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1436 | tgt->tgt_stop = 1; |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1437 | qlt_clear_tgt_db(tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1438 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1439 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1440 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1441 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1442 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, |
| 1443 | "Waiting for sess works (tgt %p)", tgt); |
| 1444 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1445 | while (!list_empty(&tgt->sess_works_list)) { |
| 1446 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1447 | flush_scheduled_work(); |
| 1448 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1449 | } |
| 1450 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1451 | |
| 1452 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1453 | "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1454 | |
| 1455 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); |
| 1456 | |
| 1457 | /* Big hammer */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1458 | if (!ha->flags.host_shutting_down && |
| 1459 | (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1460 | qlt_disable_vha(vha); |
| 1461 | |
| 1462 | /* Wait for sessions to clear out (just in case) */ |
| 1463 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1464 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1465 | } |
| 1466 | EXPORT_SYMBOL(qlt_stop_phase1); |
| 1467 | |
| 1468 | /* Called by tcm_qla2xxx configfs code */ |
| 1469 | void qlt_stop_phase2(struct qla_tgt *tgt) |
| 1470 | { |
| 1471 | struct qla_hw_data *ha = tgt->ha; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1472 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1473 | unsigned long flags; |
| 1474 | |
| 1475 | if (tgt->tgt_stopped) { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1476 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1477 | "Already in tgt->tgt_stopped state\n"); |
| 1478 | dump_stack(); |
| 1479 | return; |
| 1480 | } |
| 1481 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1482 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1483 | "Waiting for %d IRQ commands to complete (tgt %p)", |
| 1484 | tgt->irq_cmd_count, tgt); |
| 1485 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1486 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1487 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 1488 | while ((tgt->irq_cmd_count != 0) || (tgt->atio_irq_cmd_count != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1489 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1490 | udelay(2); |
| 1491 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1492 | } |
| 1493 | tgt->tgt_stop = 0; |
| 1494 | tgt->tgt_stopped = 1; |
| 1495 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1496 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1497 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1498 | 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] | 1499 | tgt); |
| 1500 | } |
| 1501 | EXPORT_SYMBOL(qlt_stop_phase2); |
| 1502 | |
| 1503 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1504 | static void qlt_release(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1505 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1506 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1507 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1508 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1509 | qlt_stop_phase2(tgt); |
| 1510 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1511 | vha->vha_tgt.qla_tgt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1512 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1513 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1514 | "Release of tgt %p finished\n", tgt); |
| 1515 | |
| 1516 | kfree(tgt); |
| 1517 | } |
| 1518 | |
| 1519 | /* ha->hardware_lock supposed to be held on entry */ |
| 1520 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, |
| 1521 | const void *param, unsigned int param_size) |
| 1522 | { |
| 1523 | struct qla_tgt_sess_work_param *prm; |
| 1524 | unsigned long flags; |
| 1525 | |
| 1526 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); |
| 1527 | if (!prm) { |
| 1528 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, |
| 1529 | "qla_target(%d): Unable to create session " |
| 1530 | "work, command will be refused", 0); |
| 1531 | return -ENOMEM; |
| 1532 | } |
| 1533 | |
| 1534 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, |
| 1535 | "Scheduling work (type %d, prm %p)" |
| 1536 | " to find session for param %p (size %d, tgt %p)\n", |
| 1537 | type, prm, param, param_size, tgt); |
| 1538 | |
| 1539 | prm->type = type; |
| 1540 | memcpy(&prm->tm_iocb, param, param_size); |
| 1541 | |
| 1542 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1543 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); |
| 1544 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1545 | |
| 1546 | schedule_work(&tgt->sess_work); |
| 1547 | |
| 1548 | return 0; |
| 1549 | } |
| 1550 | |
| 1551 | /* |
| 1552 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1553 | */ |
| 1554 | static void qlt_send_notify_ack(struct scsi_qla_host *vha, |
| 1555 | struct imm_ntfy_from_isp *ntfy, |
| 1556 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 1557 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) |
| 1558 | { |
| 1559 | struct qla_hw_data *ha = vha->hw; |
| 1560 | request_t *pkt; |
| 1561 | struct nack_to_isp *nack; |
| 1562 | |
| 1563 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); |
| 1564 | |
| 1565 | /* Send marker if required */ |
| 1566 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1567 | return; |
| 1568 | |
| 1569 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
| 1570 | if (!pkt) { |
| 1571 | ql_dbg(ql_dbg_tgt, vha, 0xe049, |
| 1572 | "qla_target(%d): %s failed: unable to allocate " |
| 1573 | "request packet\n", vha->vp_idx, __func__); |
| 1574 | return; |
| 1575 | } |
| 1576 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1577 | if (vha->vha_tgt.qla_tgt != NULL) |
| 1578 | vha->vha_tgt.qla_tgt->notify_ack_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1579 | |
| 1580 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 1581 | pkt->entry_count = 1; |
| 1582 | |
| 1583 | nack = (struct nack_to_isp *)pkt; |
| 1584 | nack->ox_id = ntfy->ox_id; |
| 1585 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1586 | nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1587 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 1588 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 1589 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1590 | cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1591 | } |
| 1592 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 1593 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 1594 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1595 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1596 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 1597 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 1598 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 1599 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); |
| 1600 | nack->u.isp24.srr_reject_code = srr_reject_code; |
| 1601 | nack->u.isp24.srr_reject_code_expl = srr_explan; |
| 1602 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 1603 | |
| 1604 | ql_dbg(ql_dbg_tgt, vha, 0xe005, |
| 1605 | "qla_target(%d): Sending 24xx Notify Ack %d\n", |
| 1606 | vha->vp_idx, nack->u.isp24.status); |
| 1607 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1608 | /* Memory Barrier */ |
| 1609 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1610 | qla2x00_start_iocbs(vha, vha->req); |
| 1611 | } |
| 1612 | |
| 1613 | /* |
| 1614 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1615 | */ |
| 1616 | static void qlt_24xx_send_abts_resp(struct scsi_qla_host *vha, |
| 1617 | struct abts_recv_from_24xx *abts, uint32_t status, |
| 1618 | bool ids_reversed) |
| 1619 | { |
| 1620 | struct qla_hw_data *ha = vha->hw; |
| 1621 | struct abts_resp_to_24xx *resp; |
| 1622 | uint32_t f_ctl; |
| 1623 | uint8_t *p; |
| 1624 | |
| 1625 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1626 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", |
| 1627 | ha, abts, status); |
| 1628 | |
| 1629 | /* Send marker if required */ |
| 1630 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1631 | return; |
| 1632 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1633 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1634 | if (!resp) { |
| 1635 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1636 | "qla_target(%d): %s failed: unable to allocate " |
| 1637 | "request packet", vha->vp_idx, __func__); |
| 1638 | return; |
| 1639 | } |
| 1640 | |
| 1641 | resp->entry_type = ABTS_RESP_24XX; |
| 1642 | resp->entry_count = 1; |
| 1643 | resp->nport_handle = abts->nport_handle; |
| 1644 | resp->vp_index = vha->vp_idx; |
| 1645 | resp->sof_type = abts->sof_type; |
| 1646 | resp->exchange_address = abts->exchange_address; |
| 1647 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1648 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1649 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1650 | F_CTL_SEQ_INITIATIVE); |
| 1651 | p = (uint8_t *)&f_ctl; |
| 1652 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1653 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1654 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1655 | if (ids_reversed) { |
| 1656 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1657 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1658 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1659 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1660 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1661 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1662 | } else { |
| 1663 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1664 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1665 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1666 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1667 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1668 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1669 | } |
| 1670 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1671 | if (status == FCP_TMF_CMPL) { |
| 1672 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1673 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1674 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1675 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1676 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1677 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1678 | } else { |
| 1679 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1680 | resp->payload.ba_rjt.reason_code = |
| 1681 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1682 | /* Other bytes are zero */ |
| 1683 | } |
| 1684 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1685 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1686 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1687 | /* Memory Barrier */ |
| 1688 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1689 | qla2x00_start_iocbs(vha, vha->req); |
| 1690 | } |
| 1691 | |
| 1692 | /* |
| 1693 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1694 | */ |
| 1695 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, |
| 1696 | struct abts_resp_from_24xx_fw *entry) |
| 1697 | { |
| 1698 | struct ctio7_to_24xx *ctio; |
| 1699 | |
| 1700 | ql_dbg(ql_dbg_tgt, vha, 0xe007, |
| 1701 | "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha->hw); |
| 1702 | /* Send marker if required */ |
| 1703 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1704 | return; |
| 1705 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1706 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1707 | if (ctio == NULL) { |
| 1708 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, |
| 1709 | "qla_target(%d): %s failed: unable to allocate " |
| 1710 | "request packet\n", vha->vp_idx, __func__); |
| 1711 | return; |
| 1712 | } |
| 1713 | |
| 1714 | /* |
| 1715 | * We've got on entrance firmware's response on by us generated |
| 1716 | * ABTS response. So, in it ID fields are reversed. |
| 1717 | */ |
| 1718 | |
| 1719 | ctio->entry_type = CTIO_TYPE7; |
| 1720 | ctio->entry_count = 1; |
| 1721 | ctio->nport_handle = entry->nport_handle; |
| 1722 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1723 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1724 | ctio->vp_index = vha->vp_idx; |
| 1725 | ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0]; |
| 1726 | ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1]; |
| 1727 | ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2]; |
| 1728 | ctio->exchange_addr = entry->exchange_addr_to_abort; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1729 | ctio->u.status1.flags = cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | |
| 1730 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1731 | 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] | 1732 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1733 | /* Memory Barrier */ |
| 1734 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1735 | qla2x00_start_iocbs(vha, vha->req); |
| 1736 | |
| 1737 | qlt_24xx_send_abts_resp(vha, (struct abts_recv_from_24xx *)entry, |
| 1738 | FCP_TMF_CMPL, true); |
| 1739 | } |
| 1740 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1741 | static int abort_cmd_for_tag(struct scsi_qla_host *vha, uint32_t tag) |
| 1742 | { |
| 1743 | struct qla_tgt_sess_op *op; |
| 1744 | struct qla_tgt_cmd *cmd; |
| 1745 | |
| 1746 | spin_lock(&vha->cmd_list_lock); |
| 1747 | |
| 1748 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1749 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1750 | op->aborted = true; |
| 1751 | spin_unlock(&vha->cmd_list_lock); |
| 1752 | return 1; |
| 1753 | } |
| 1754 | } |
| 1755 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1756 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1757 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1758 | op->aborted = true; |
| 1759 | spin_unlock(&vha->cmd_list_lock); |
| 1760 | return 1; |
| 1761 | } |
| 1762 | } |
| 1763 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1764 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1765 | if (tag == cmd->atio.u.isp24.exchange_addr) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1766 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1767 | spin_unlock(&vha->cmd_list_lock); |
| 1768 | return 1; |
| 1769 | } |
| 1770 | } |
| 1771 | |
| 1772 | spin_unlock(&vha->cmd_list_lock); |
| 1773 | return 0; |
| 1774 | } |
| 1775 | |
| 1776 | /* drop cmds for the given lun |
| 1777 | * XXX only looks for cmds on the port through which lun reset was recieved |
| 1778 | * XXX does not go through the list of other port (which may have cmds |
| 1779 | * for the same lun) |
| 1780 | */ |
| 1781 | static void abort_cmds_for_lun(struct scsi_qla_host *vha, |
| 1782 | uint32_t lun, uint8_t *s_id) |
| 1783 | { |
| 1784 | struct qla_tgt_sess_op *op; |
| 1785 | struct qla_tgt_cmd *cmd; |
| 1786 | uint32_t key; |
| 1787 | |
| 1788 | key = sid_to_key(s_id); |
| 1789 | spin_lock(&vha->cmd_list_lock); |
| 1790 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1791 | uint32_t op_key; |
| 1792 | uint32_t op_lun; |
| 1793 | |
| 1794 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1795 | op_lun = scsilun_to_int( |
| 1796 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1797 | if (op_key == key && op_lun == lun) |
| 1798 | op->aborted = true; |
| 1799 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1800 | |
| 1801 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1802 | uint32_t op_key; |
| 1803 | u64 op_lun; |
| 1804 | |
| 1805 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1806 | op_lun = scsilun_to_int( |
| 1807 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1808 | if (op_key == key && op_lun == lun) |
| 1809 | op->aborted = true; |
| 1810 | } |
| 1811 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1812 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1813 | uint32_t cmd_key; |
| 1814 | uint32_t cmd_lun; |
| 1815 | |
| 1816 | cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 1817 | cmd_lun = scsilun_to_int( |
| 1818 | (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); |
| 1819 | if (cmd_key == key && cmd_lun == lun) |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1820 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1821 | } |
| 1822 | spin_unlock(&vha->cmd_list_lock); |
| 1823 | } |
| 1824 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1825 | /* ha->hardware_lock supposed to be held on entry */ |
| 1826 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1827 | struct abts_recv_from_24xx *abts, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1828 | { |
| 1829 | struct qla_hw_data *ha = vha->hw; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1830 | struct se_session *se_sess = sess->se_sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1831 | struct qla_tgt_mgmt_cmd *mcmd; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1832 | struct se_cmd *se_cmd; |
| 1833 | u32 lun = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1834 | int rc; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1835 | bool found_lun = false; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1836 | unsigned long flags; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1837 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1838 | spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1839 | list_for_each_entry(se_cmd, &se_sess->sess_cmd_list, se_cmd_list) { |
| 1840 | struct qla_tgt_cmd *cmd = |
| 1841 | container_of(se_cmd, struct qla_tgt_cmd, se_cmd); |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 1842 | if (se_cmd->tag == abts->exchange_addr_to_abort) { |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1843 | lun = cmd->unpacked_lun; |
| 1844 | found_lun = true; |
| 1845 | break; |
| 1846 | } |
| 1847 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1848 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1849 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1850 | /* cmd not in LIO lists, look in qla list */ |
| 1851 | if (!found_lun) { |
| 1852 | if (abort_cmd_for_tag(vha, abts->exchange_addr_to_abort)) { |
| 1853 | /* send TASK_ABORT response immediately */ |
| 1854 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_CMPL, false); |
| 1855 | return 0; |
| 1856 | } else { |
| 1857 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf081, |
| 1858 | "unable to find cmd in driver or LIO for tag 0x%x\n", |
| 1859 | abts->exchange_addr_to_abort); |
| 1860 | return -ENOENT; |
| 1861 | } |
| 1862 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1863 | |
| 1864 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, |
| 1865 | "qla_target(%d): task abort (tag=%d)\n", |
| 1866 | vha->vp_idx, abts->exchange_addr_to_abort); |
| 1867 | |
| 1868 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 1869 | if (mcmd == NULL) { |
| 1870 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, |
| 1871 | "qla_target(%d): %s: Allocation of ABORT cmd failed", |
| 1872 | vha->vp_idx, __func__); |
| 1873 | return -ENOMEM; |
| 1874 | } |
| 1875 | memset(mcmd, 0, sizeof(*mcmd)); |
| 1876 | |
| 1877 | mcmd->sess = sess; |
| 1878 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); |
Arun Easi | 80187f8 | 2014-09-25 06:14:53 -0400 | [diff] [blame] | 1879 | mcmd->reset_count = vha->hw->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 1880 | mcmd->tmr_func = QLA_TGT_ABTS; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1881 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 1882 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, lun, mcmd->tmr_func, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1883 | abts->exchange_addr_to_abort); |
| 1884 | if (rc != 0) { |
| 1885 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf052, |
| 1886 | "qla_target(%d): tgt_ops->handle_tmr()" |
| 1887 | " failed: %d", vha->vp_idx, rc); |
| 1888 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 1889 | return -EFAULT; |
| 1890 | } |
| 1891 | |
| 1892 | return 0; |
| 1893 | } |
| 1894 | |
| 1895 | /* |
| 1896 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1897 | */ |
| 1898 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 1899 | struct abts_recv_from_24xx *abts) |
| 1900 | { |
| 1901 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1902 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1903 | uint32_t tag = abts->exchange_addr_to_abort; |
| 1904 | uint8_t s_id[3]; |
| 1905 | int rc; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1906 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1907 | |
| 1908 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { |
| 1909 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, |
| 1910 | "qla_target(%d): ABTS: Abort Sequence not " |
| 1911 | "supported\n", vha->vp_idx); |
| 1912 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1913 | return; |
| 1914 | } |
| 1915 | |
| 1916 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { |
| 1917 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, |
| 1918 | "qla_target(%d): ABTS: Unknown Exchange " |
| 1919 | "Address received\n", vha->vp_idx); |
| 1920 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1921 | return; |
| 1922 | } |
| 1923 | |
| 1924 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, |
| 1925 | "qla_target(%d): task abort (s_id=%x:%x:%x, " |
| 1926 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2], |
| 1927 | abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag, |
| 1928 | le32_to_cpu(abts->fcp_hdr_le.parameter)); |
| 1929 | |
| 1930 | s_id[0] = abts->fcp_hdr_le.s_id[2]; |
| 1931 | s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1932 | s_id[2] = abts->fcp_hdr_le.s_id[0]; |
| 1933 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1934 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1935 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 1936 | if (!sess) { |
| 1937 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, |
| 1938 | "qla_target(%d): task abort for non-existant session\n", |
| 1939 | vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1940 | rc = qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1941 | QLA_TGT_SESS_WORK_ABORT, abts, sizeof(*abts)); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1942 | |
| 1943 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1944 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1945 | if (rc != 0) { |
| 1946 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, |
| 1947 | false); |
| 1948 | } |
| 1949 | return; |
| 1950 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1951 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1952 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1953 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1954 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 1955 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1956 | return; |
| 1957 | } |
| 1958 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1959 | rc = __qlt_24xx_handle_abts(vha, abts, sess); |
| 1960 | if (rc != 0) { |
| 1961 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, |
| 1962 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", |
| 1963 | vha->vp_idx, rc); |
| 1964 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1965 | return; |
| 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | /* |
| 1970 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1971 | */ |
| 1972 | static void qlt_24xx_send_task_mgmt_ctio(struct scsi_qla_host *ha, |
| 1973 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) |
| 1974 | { |
| 1975 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; |
| 1976 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1977 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1978 | |
| 1979 | ql_dbg(ql_dbg_tgt, ha, 0xe008, |
| 1980 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", |
| 1981 | ha, atio, resp_code); |
| 1982 | |
| 1983 | /* Send marker if required */ |
| 1984 | if (qlt_issue_marker(ha, 1) != QLA_SUCCESS) |
| 1985 | return; |
| 1986 | |
| 1987 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(ha, NULL); |
| 1988 | if (ctio == NULL) { |
| 1989 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, |
| 1990 | "qla_target(%d): %s failed: unable to allocate " |
| 1991 | "request packet\n", ha->vp_idx, __func__); |
| 1992 | return; |
| 1993 | } |
| 1994 | |
| 1995 | ctio->entry_type = CTIO_TYPE7; |
| 1996 | ctio->entry_count = 1; |
| 1997 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 1998 | ctio->nport_handle = mcmd->sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1999 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2000 | ctio->vp_index = ha->vp_idx; |
| 2001 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2002 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2003 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2004 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
| 2005 | ctio->u.status1.flags = (atio->u.isp24.attr << 9) | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2006 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2007 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2008 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2009 | ctio->u.status1.scsi_status = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2010 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); |
| 2011 | ctio->u.status1.response_len = cpu_to_le16(8); |
Roland Dreier | e4b11b8 | 2012-09-18 15:10:56 -0700 | [diff] [blame] | 2012 | ctio->u.status1.sense_data[0] = resp_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2013 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2014 | /* Memory Barrier */ |
| 2015 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2016 | qla2x00_start_iocbs(ha, ha->req); |
| 2017 | } |
| 2018 | |
| 2019 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) |
| 2020 | { |
| 2021 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2022 | } |
| 2023 | EXPORT_SYMBOL(qlt_free_mcmd); |
| 2024 | |
| 2025 | /* callback from target fabric module code */ |
| 2026 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) |
| 2027 | { |
| 2028 | struct scsi_qla_host *vha = mcmd->sess->vha; |
| 2029 | struct qla_hw_data *ha = vha->hw; |
| 2030 | unsigned long flags; |
| 2031 | |
| 2032 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, |
| 2033 | "TM response mcmd (%p) status %#x state %#x", |
| 2034 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); |
| 2035 | |
| 2036 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2037 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2038 | if (!vha->flags.online || mcmd->reset_count != ha->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2039 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2040 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2041 | * previous life, just abort the processing. |
| 2042 | */ |
| 2043 | ql_dbg(ql_dbg_async, vha, 0xe100, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2044 | "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2045 | vha->flags.online, qla2x00_reset_active(vha), |
| 2046 | mcmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2047 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 2048 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2049 | return; |
| 2050 | } |
| 2051 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2052 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) { |
| 2053 | if (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 2054 | ELS_LOGO || |
| 2055 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2056 | ELS_PRLO || |
| 2057 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2058 | ELS_TPRLO) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2059 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 2060 | "TM response logo %phC status %#x state %#x", |
| 2061 | mcmd->sess->port_name, mcmd->fc_tm_rsp, |
| 2062 | mcmd->flags); |
| 2063 | qlt_schedule_sess_for_deletion_lock(mcmd->sess); |
| 2064 | } else { |
| 2065 | qlt_send_notify_ack(vha, &mcmd->orig_iocb.imm_ntfy, |
| 2066 | 0, 0, 0, 0, 0, 0); |
| 2067 | } |
| 2068 | } else { |
Swapnil Nagle | d7236ac | 2016-02-04 11:45:17 -0500 | [diff] [blame] | 2069 | if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2070 | qlt_24xx_send_abts_resp(vha, &mcmd->orig_iocb.abts, |
| 2071 | mcmd->fc_tm_rsp, false); |
| 2072 | else |
| 2073 | qlt_24xx_send_task_mgmt_ctio(vha, mcmd, |
| 2074 | mcmd->fc_tm_rsp); |
| 2075 | } |
| 2076 | /* |
| 2077 | * Make the callback for ->free_mcmd() to queue_work() and invoke |
| 2078 | * target_put_sess_cmd() to drop cmd_kref to 1. The final |
| 2079 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() |
| 2080 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd |
| 2081 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> |
| 2082 | * qlt_xmit_tm_rsp() returns here.. |
| 2083 | */ |
| 2084 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 2085 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2086 | } |
| 2087 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); |
| 2088 | |
| 2089 | /* No locks */ |
| 2090 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) |
| 2091 | { |
| 2092 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2093 | |
| 2094 | BUG_ON(cmd->sg_cnt == 0); |
| 2095 | |
| 2096 | prm->sg = (struct scatterlist *)cmd->sg; |
| 2097 | prm->seg_cnt = pci_map_sg(prm->tgt->ha->pdev, cmd->sg, |
| 2098 | cmd->sg_cnt, cmd->dma_data_direction); |
| 2099 | if (unlikely(prm->seg_cnt == 0)) |
| 2100 | goto out_err; |
| 2101 | |
| 2102 | prm->cmd->sg_mapped = 1; |
| 2103 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2104 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
| 2105 | /* |
| 2106 | * If greater than four sg entries then we need to allocate |
| 2107 | * the continuation entries |
| 2108 | */ |
| 2109 | if (prm->seg_cnt > prm->tgt->datasegs_per_cmd) |
| 2110 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - |
| 2111 | prm->tgt->datasegs_per_cmd, |
| 2112 | prm->tgt->datasegs_per_cont); |
| 2113 | } else { |
| 2114 | /* DIF */ |
| 2115 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2116 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2117 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); |
| 2118 | prm->tot_dsds = prm->seg_cnt; |
| 2119 | } else |
| 2120 | prm->tot_dsds = prm->seg_cnt; |
| 2121 | |
| 2122 | if (cmd->prot_sg_cnt) { |
| 2123 | prm->prot_sg = cmd->prot_sg; |
| 2124 | prm->prot_seg_cnt = pci_map_sg(prm->tgt->ha->pdev, |
| 2125 | cmd->prot_sg, cmd->prot_sg_cnt, |
| 2126 | cmd->dma_data_direction); |
| 2127 | if (unlikely(prm->prot_seg_cnt == 0)) |
| 2128 | goto out_err; |
| 2129 | |
| 2130 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2131 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2132 | /* Dif Bundling not support here */ |
| 2133 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, |
| 2134 | cmd->blk_sz); |
| 2135 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2136 | } else |
| 2137 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2138 | } |
| 2139 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2140 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2141 | return 0; |
| 2142 | |
| 2143 | out_err: |
| 2144 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe04d, |
| 2145 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", |
| 2146 | 0, prm->cmd->sg_cnt); |
| 2147 | return -1; |
| 2148 | } |
| 2149 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2150 | 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] | 2151 | { |
| 2152 | struct qla_hw_data *ha = vha->hw; |
| 2153 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2154 | if (!cmd->sg_mapped) |
| 2155 | return; |
| 2156 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2157 | pci_unmap_sg(ha->pdev, cmd->sg, cmd->sg_cnt, cmd->dma_data_direction); |
| 2158 | cmd->sg_mapped = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2159 | |
| 2160 | if (cmd->prot_sg_cnt) |
| 2161 | pci_unmap_sg(ha->pdev, cmd->prot_sg, cmd->prot_sg_cnt, |
| 2162 | cmd->dma_data_direction); |
| 2163 | |
| 2164 | if (cmd->ctx_dsd_alloced) |
| 2165 | qla2x00_clean_dsd_pool(ha, NULL, cmd); |
| 2166 | |
| 2167 | if (cmd->ctx) |
| 2168 | 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] | 2169 | } |
| 2170 | |
| 2171 | static int qlt_check_reserve_free_req(struct scsi_qla_host *vha, |
| 2172 | uint32_t req_cnt) |
| 2173 | { |
Saurav Kashyap | d29fb73 | 2014-09-25 06:14:49 -0400 | [diff] [blame] | 2174 | uint32_t cnt, cnt_in; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2175 | |
| 2176 | if (vha->req->cnt < (req_cnt + 2)) { |
Arun Easi | 75554b6 | 2014-09-25 06:14:45 -0400 | [diff] [blame] | 2177 | cnt = (uint16_t)RD_REG_DWORD(vha->req->req_q_out); |
Saurav Kashyap | d29fb73 | 2014-09-25 06:14:49 -0400 | [diff] [blame] | 2178 | cnt_in = (uint16_t)RD_REG_DWORD(vha->req->req_q_in); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2179 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2180 | if (vha->req->ring_index < cnt) |
| 2181 | vha->req->cnt = cnt - vha->req->ring_index; |
| 2182 | else |
| 2183 | vha->req->cnt = vha->req->length - |
| 2184 | (vha->req->ring_index - cnt); |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2185 | |
| 2186 | if (unlikely(vha->req->cnt < (req_cnt + 2))) { |
| 2187 | ql_dbg(ql_dbg_io, vha, 0x305a, |
| 2188 | "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", |
| 2189 | vha->vp_idx, vha->req->ring_index, |
| 2190 | vha->req->cnt, req_cnt, cnt, cnt_in, |
| 2191 | vha->req->length); |
| 2192 | return -EAGAIN; |
| 2193 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2194 | } |
| 2195 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2196 | vha->req->cnt -= req_cnt; |
| 2197 | |
| 2198 | return 0; |
| 2199 | } |
| 2200 | |
| 2201 | /* |
| 2202 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2203 | */ |
| 2204 | static inline void *qlt_get_req_pkt(struct scsi_qla_host *vha) |
| 2205 | { |
| 2206 | /* Adjust ring index. */ |
| 2207 | vha->req->ring_index++; |
| 2208 | if (vha->req->ring_index == vha->req->length) { |
| 2209 | vha->req->ring_index = 0; |
| 2210 | vha->req->ring_ptr = vha->req->ring; |
| 2211 | } else { |
| 2212 | vha->req->ring_ptr++; |
| 2213 | } |
| 2214 | return (cont_entry_t *)vha->req->ring_ptr; |
| 2215 | } |
| 2216 | |
| 2217 | /* ha->hardware_lock supposed to be held on entry */ |
| 2218 | static inline uint32_t qlt_make_handle(struct scsi_qla_host *vha) |
| 2219 | { |
| 2220 | struct qla_hw_data *ha = vha->hw; |
| 2221 | uint32_t h; |
| 2222 | |
| 2223 | h = ha->tgt.current_handle; |
| 2224 | /* always increment cmd handle */ |
| 2225 | do { |
| 2226 | ++h; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2227 | if (h > DEFAULT_OUTSTANDING_COMMANDS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2228 | h = 1; /* 0 is QLA_TGT_NULL_HANDLE */ |
| 2229 | if (h == ha->tgt.current_handle) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2230 | ql_dbg(ql_dbg_io, vha, 0x305b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2231 | "qla_target(%d): Ran out of " |
| 2232 | "empty cmd slots in ha %p\n", vha->vp_idx, ha); |
| 2233 | h = QLA_TGT_NULL_HANDLE; |
| 2234 | break; |
| 2235 | } |
| 2236 | } while ((h == QLA_TGT_NULL_HANDLE) || |
| 2237 | (h == QLA_TGT_SKIP_HANDLE) || |
| 2238 | (ha->tgt.cmds[h-1] != NULL)); |
| 2239 | |
| 2240 | if (h != QLA_TGT_NULL_HANDLE) |
| 2241 | ha->tgt.current_handle = h; |
| 2242 | |
| 2243 | return h; |
| 2244 | } |
| 2245 | |
| 2246 | /* ha->hardware_lock supposed to be held on entry */ |
| 2247 | static int qlt_24xx_build_ctio_pkt(struct qla_tgt_prm *prm, |
| 2248 | struct scsi_qla_host *vha) |
| 2249 | { |
| 2250 | uint32_t h; |
| 2251 | struct ctio7_to_24xx *pkt; |
| 2252 | struct qla_hw_data *ha = vha->hw; |
| 2253 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2254 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2255 | |
| 2256 | pkt = (struct ctio7_to_24xx *)vha->req->ring_ptr; |
| 2257 | prm->pkt = pkt; |
| 2258 | memset(pkt, 0, sizeof(*pkt)); |
| 2259 | |
| 2260 | pkt->entry_type = CTIO_TYPE7; |
| 2261 | pkt->entry_count = (uint8_t)prm->req_cnt; |
| 2262 | pkt->vp_index = vha->vp_idx; |
| 2263 | |
| 2264 | h = qlt_make_handle(vha); |
| 2265 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2266 | /* |
| 2267 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2268 | * know the initiator's LOOP ID, hence we can't find |
| 2269 | * the session and, so, the command. |
| 2270 | */ |
| 2271 | return -EAGAIN; |
| 2272 | } else |
| 2273 | ha->tgt.cmds[h-1] = prm->cmd; |
| 2274 | |
| 2275 | pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK; |
| 2276 | pkt->nport_handle = prm->cmd->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2277 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2278 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2279 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2280 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2281 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
| 2282 | pkt->u.status0.flags |= (atio->u.isp24.attr << 9); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2283 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2284 | pkt->u.status0.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2285 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2286 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2287 | return 0; |
| 2288 | } |
| 2289 | |
| 2290 | /* |
| 2291 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2292 | * that there is sufficient amount of request entries to not drop it. |
| 2293 | */ |
| 2294 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm, |
| 2295 | struct scsi_qla_host *vha) |
| 2296 | { |
| 2297 | int cnt; |
| 2298 | uint32_t *dword_ptr; |
| 2299 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; |
| 2300 | |
| 2301 | /* Build continuation packets */ |
| 2302 | while (prm->seg_cnt > 0) { |
| 2303 | cont_a64_entry_t *cont_pkt64 = |
| 2304 | (cont_a64_entry_t *)qlt_get_req_pkt(vha); |
| 2305 | |
| 2306 | /* |
| 2307 | * Make sure that from cont_pkt64 none of |
| 2308 | * 64-bit specific fields used for 32-bit |
| 2309 | * addressing. Cast to (cont_entry_t *) for |
| 2310 | * that. |
| 2311 | */ |
| 2312 | |
| 2313 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); |
| 2314 | |
| 2315 | cont_pkt64->entry_count = 1; |
| 2316 | cont_pkt64->sys_define = 0; |
| 2317 | |
| 2318 | if (enable_64bit_addressing) { |
| 2319 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; |
| 2320 | dword_ptr = |
| 2321 | (uint32_t *)&cont_pkt64->dseg_0_address; |
| 2322 | } else { |
| 2323 | cont_pkt64->entry_type = CONTINUE_TYPE; |
| 2324 | dword_ptr = |
| 2325 | (uint32_t *)&((cont_entry_t *) |
| 2326 | cont_pkt64)->dseg_0_address; |
| 2327 | } |
| 2328 | |
| 2329 | /* Load continuation entry data segments */ |
| 2330 | for (cnt = 0; |
| 2331 | cnt < prm->tgt->datasegs_per_cont && prm->seg_cnt; |
| 2332 | cnt++, prm->seg_cnt--) { |
| 2333 | *dword_ptr++ = |
| 2334 | cpu_to_le32(pci_dma_lo32 |
| 2335 | (sg_dma_address(prm->sg))); |
| 2336 | if (enable_64bit_addressing) { |
| 2337 | *dword_ptr++ = |
| 2338 | cpu_to_le32(pci_dma_hi32 |
| 2339 | (sg_dma_address |
| 2340 | (prm->sg))); |
| 2341 | } |
| 2342 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2343 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2344 | prm->sg = sg_next(prm->sg); |
| 2345 | } |
| 2346 | } |
| 2347 | } |
| 2348 | |
| 2349 | /* |
| 2350 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2351 | * that there is sufficient amount of request entries to not drop it. |
| 2352 | */ |
| 2353 | static void qlt_load_data_segments(struct qla_tgt_prm *prm, |
| 2354 | struct scsi_qla_host *vha) |
| 2355 | { |
| 2356 | int cnt; |
| 2357 | uint32_t *dword_ptr; |
| 2358 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; |
| 2359 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; |
| 2360 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2361 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
| 2362 | |
| 2363 | /* Setup packet address segment pointer */ |
| 2364 | dword_ptr = pkt24->u.status0.dseg_0_address; |
| 2365 | |
| 2366 | /* Set total data segment count */ |
| 2367 | if (prm->seg_cnt) |
| 2368 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); |
| 2369 | |
| 2370 | if (prm->seg_cnt == 0) { |
| 2371 | /* No data transfer */ |
| 2372 | *dword_ptr++ = 0; |
| 2373 | *dword_ptr = 0; |
| 2374 | return; |
| 2375 | } |
| 2376 | |
| 2377 | /* If scatter gather */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2378 | |
| 2379 | /* Load command entry data segments */ |
| 2380 | for (cnt = 0; |
| 2381 | (cnt < prm->tgt->datasegs_per_cmd) && prm->seg_cnt; |
| 2382 | cnt++, prm->seg_cnt--) { |
| 2383 | *dword_ptr++ = |
| 2384 | cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg))); |
| 2385 | if (enable_64bit_addressing) { |
| 2386 | *dword_ptr++ = |
| 2387 | cpu_to_le32(pci_dma_hi32( |
| 2388 | sg_dma_address(prm->sg))); |
| 2389 | } |
| 2390 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2391 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2392 | prm->sg = sg_next(prm->sg); |
| 2393 | } |
| 2394 | |
| 2395 | qlt_load_cont_data_segments(prm, vha); |
| 2396 | } |
| 2397 | |
| 2398 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) |
| 2399 | { |
| 2400 | return cmd->bufflen > 0; |
| 2401 | } |
| 2402 | |
| 2403 | /* |
| 2404 | * Called without ha->hardware_lock held |
| 2405 | */ |
| 2406 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, |
| 2407 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, |
| 2408 | uint32_t *full_req_cnt) |
| 2409 | { |
| 2410 | struct qla_tgt *tgt = cmd->tgt; |
| 2411 | struct scsi_qla_host *vha = tgt->vha; |
| 2412 | struct qla_hw_data *ha = vha->hw; |
| 2413 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2414 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2415 | prm->cmd = cmd; |
| 2416 | prm->tgt = tgt; |
| 2417 | prm->rq_result = scsi_status; |
| 2418 | prm->sense_buffer = &cmd->sense_buffer[0]; |
| 2419 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; |
| 2420 | prm->sg = NULL; |
| 2421 | prm->seg_cnt = -1; |
| 2422 | prm->req_cnt = 1; |
| 2423 | prm->add_status_pkt = 0; |
| 2424 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2425 | /* Send marker if required */ |
| 2426 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) |
| 2427 | return -EFAULT; |
| 2428 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2429 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
| 2430 | if (qlt_pci_map_calc_cnt(prm) != 0) |
| 2431 | return -EAGAIN; |
| 2432 | } |
| 2433 | |
| 2434 | *full_req_cnt = prm->req_cnt; |
| 2435 | |
| 2436 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { |
| 2437 | prm->residual = se_cmd->residual_count; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2438 | ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x305c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2439 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2440 | prm->residual, se_cmd->tag, |
| 2441 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, |
| 2442 | cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2443 | prm->rq_result |= SS_RESIDUAL_UNDER; |
| 2444 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2445 | prm->residual = se_cmd->residual_count; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2446 | ql_dbg(ql_dbg_io, vha, 0x305d, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2447 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2448 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? |
| 2449 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2450 | prm->rq_result |= SS_RESIDUAL_OVER; |
| 2451 | } |
| 2452 | |
| 2453 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2454 | /* |
| 2455 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be |
| 2456 | * ignored in *xmit_response() below |
| 2457 | */ |
| 2458 | if (qlt_has_data(cmd)) { |
| 2459 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || |
| 2460 | (IS_FWI2_CAPABLE(ha) && |
| 2461 | (prm->rq_result != 0))) { |
| 2462 | prm->add_status_pkt = 1; |
| 2463 | (*full_req_cnt)++; |
| 2464 | } |
| 2465 | } |
| 2466 | } |
| 2467 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2468 | return 0; |
| 2469 | } |
| 2470 | |
| 2471 | static inline int qlt_need_explicit_conf(struct qla_hw_data *ha, |
| 2472 | struct qla_tgt_cmd *cmd, int sending_sense) |
| 2473 | { |
| 2474 | if (ha->tgt.enable_class_2) |
| 2475 | return 0; |
| 2476 | |
| 2477 | if (sending_sense) |
| 2478 | return cmd->conf_compl_supported; |
| 2479 | else |
| 2480 | return ha->tgt.enable_explicit_conf && |
| 2481 | cmd->conf_compl_supported; |
| 2482 | } |
| 2483 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2484 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, |
| 2485 | struct qla_tgt_prm *prm) |
| 2486 | { |
| 2487 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, |
| 2488 | (uint32_t)sizeof(ctio->u.status1.sense_data)); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2489 | ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2490 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 0)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2491 | ctio->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2492 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2493 | CTIO7_FLAGS_CONFORM_REQ); |
| 2494 | } |
| 2495 | ctio->u.status0.residual = cpu_to_le32(prm->residual); |
| 2496 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); |
| 2497 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { |
| 2498 | int i; |
| 2499 | |
| 2500 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 1)) { |
Quinn Tran | df2e32c | 2017-01-19 22:27:53 -0800 | [diff] [blame] | 2501 | if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2502 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe017, |
| 2503 | "Skipping EXPLICIT_CONFORM and " |
| 2504 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " |
| 2505 | "non GOOD status\n"); |
| 2506 | goto skip_explict_conf; |
| 2507 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2508 | ctio->u.status1.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2509 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2510 | CTIO7_FLAGS_CONFORM_REQ); |
| 2511 | } |
| 2512 | skip_explict_conf: |
| 2513 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2514 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2515 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2516 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2517 | ctio->u.status1.scsi_status |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2518 | cpu_to_le16(SS_SENSE_LEN_VALID); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2519 | ctio->u.status1.sense_length = |
| 2520 | cpu_to_le16(prm->sense_buffer_len); |
| 2521 | for (i = 0; i < prm->sense_buffer_len/4; i++) |
| 2522 | ((uint32_t *)ctio->u.status1.sense_data)[i] = |
| 2523 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); |
| 2524 | #if 0 |
| 2525 | if (unlikely((prm->sense_buffer_len % 4) != 0)) { |
| 2526 | static int q; |
| 2527 | if (q < 10) { |
| 2528 | ql_dbg(ql_dbg_tgt, vha, 0xe04f, |
| 2529 | "qla_target(%d): %d bytes of sense " |
| 2530 | "lost", prm->tgt->ha->vp_idx, |
| 2531 | prm->sense_buffer_len % 4); |
| 2532 | q++; |
| 2533 | } |
| 2534 | } |
| 2535 | #endif |
| 2536 | } else { |
| 2537 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2538 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2539 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2540 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2541 | ctio->u.status1.sense_length = 0; |
| 2542 | memset(ctio->u.status1.sense_data, 0, |
| 2543 | sizeof(ctio->u.status1.sense_data)); |
| 2544 | } |
| 2545 | |
| 2546 | /* Sense with len > 24, is it possible ??? */ |
| 2547 | } |
| 2548 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2549 | |
| 2550 | |
| 2551 | /* diff */ |
| 2552 | static inline int |
| 2553 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) |
| 2554 | { |
| 2555 | /* |
| 2556 | * Uncomment when corresponding SCSI changes are done. |
| 2557 | * |
| 2558 | if (!sp->cmd->prot_chk) |
| 2559 | return 0; |
| 2560 | * |
| 2561 | */ |
| 2562 | switch (se_cmd->prot_op) { |
| 2563 | case TARGET_PROT_DOUT_INSERT: |
| 2564 | case TARGET_PROT_DIN_STRIP: |
| 2565 | if (ql2xenablehba_err_chk >= 1) |
| 2566 | return 1; |
| 2567 | break; |
| 2568 | case TARGET_PROT_DOUT_PASS: |
| 2569 | case TARGET_PROT_DIN_PASS: |
| 2570 | if (ql2xenablehba_err_chk >= 2) |
| 2571 | return 1; |
| 2572 | break; |
| 2573 | case TARGET_PROT_DIN_INSERT: |
| 2574 | case TARGET_PROT_DOUT_STRIP: |
| 2575 | return 1; |
| 2576 | default: |
| 2577 | break; |
| 2578 | } |
| 2579 | return 0; |
| 2580 | } |
| 2581 | |
| 2582 | /* |
| 2583 | * qla24xx_set_t10dif_tags_from_cmd - Extract Ref and App tags from SCSI command |
| 2584 | * |
| 2585 | */ |
| 2586 | static inline void |
| 2587 | qlt_set_t10dif_tags(struct se_cmd *se_cmd, struct crc_context *ctx) |
| 2588 | { |
| 2589 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; |
| 2590 | |
| 2591 | /* wait til Mode Sense/Select cmd, modepage Ah, subpage 2 |
| 2592 | * have been immplemented by TCM, before AppTag is avail. |
| 2593 | * Look for modesense_handlers[] |
| 2594 | */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2595 | ctx->app_tag = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2596 | ctx->app_tag_mask[0] = 0x0; |
| 2597 | ctx->app_tag_mask[1] = 0x0; |
| 2598 | |
| 2599 | switch (se_cmd->prot_type) { |
| 2600 | case TARGET_DIF_TYPE0_PROT: |
| 2601 | /* |
| 2602 | * No check for ql2xenablehba_err_chk, as it would be an |
| 2603 | * I/O error if hba tag generation is not done. |
| 2604 | */ |
| 2605 | ctx->ref_tag = cpu_to_le32(lba); |
| 2606 | |
| 2607 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2608 | break; |
| 2609 | |
| 2610 | /* enable ALL bytes of the ref tag */ |
| 2611 | ctx->ref_tag_mask[0] = 0xff; |
| 2612 | ctx->ref_tag_mask[1] = 0xff; |
| 2613 | ctx->ref_tag_mask[2] = 0xff; |
| 2614 | ctx->ref_tag_mask[3] = 0xff; |
| 2615 | break; |
| 2616 | /* |
| 2617 | * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and |
| 2618 | * 16 bit app tag. |
| 2619 | */ |
| 2620 | case TARGET_DIF_TYPE1_PROT: |
| 2621 | ctx->ref_tag = cpu_to_le32(lba); |
| 2622 | |
| 2623 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2624 | break; |
| 2625 | |
| 2626 | /* enable ALL bytes of the ref tag */ |
| 2627 | ctx->ref_tag_mask[0] = 0xff; |
| 2628 | ctx->ref_tag_mask[1] = 0xff; |
| 2629 | ctx->ref_tag_mask[2] = 0xff; |
| 2630 | ctx->ref_tag_mask[3] = 0xff; |
| 2631 | break; |
| 2632 | /* |
| 2633 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to |
| 2634 | * match LBA in CDB + N |
| 2635 | */ |
| 2636 | case TARGET_DIF_TYPE2_PROT: |
| 2637 | ctx->ref_tag = cpu_to_le32(lba); |
| 2638 | |
| 2639 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2640 | break; |
| 2641 | |
| 2642 | /* enable ALL bytes of the ref tag */ |
| 2643 | ctx->ref_tag_mask[0] = 0xff; |
| 2644 | ctx->ref_tag_mask[1] = 0xff; |
| 2645 | ctx->ref_tag_mask[2] = 0xff; |
| 2646 | ctx->ref_tag_mask[3] = 0xff; |
| 2647 | break; |
| 2648 | |
| 2649 | /* For Type 3 protection: 16 bit GUARD only */ |
| 2650 | case TARGET_DIF_TYPE3_PROT: |
| 2651 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = |
| 2652 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; |
| 2653 | break; |
| 2654 | } |
| 2655 | } |
| 2656 | |
| 2657 | |
| 2658 | static inline int |
| 2659 | qlt_build_ctio_crc2_pkt(struct qla_tgt_prm *prm, scsi_qla_host_t *vha) |
| 2660 | { |
| 2661 | uint32_t *cur_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2662 | uint32_t transfer_length = 0; |
| 2663 | uint32_t data_bytes; |
| 2664 | uint32_t dif_bytes; |
| 2665 | uint8_t bundling = 1; |
| 2666 | uint8_t *clr_ptr; |
| 2667 | struct crc_context *crc_ctx_pkt = NULL; |
| 2668 | struct qla_hw_data *ha; |
| 2669 | struct ctio_crc2_to_fw *pkt; |
| 2670 | dma_addr_t crc_ctx_dma; |
| 2671 | uint16_t fw_prot_opts = 0; |
| 2672 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2673 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2674 | uint32_t h; |
| 2675 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2676 | uint16_t t16; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2677 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2678 | ha = vha->hw; |
| 2679 | |
| 2680 | pkt = (struct ctio_crc2_to_fw *)vha->req->ring_ptr; |
| 2681 | prm->pkt = pkt; |
| 2682 | memset(pkt, 0, sizeof(*pkt)); |
| 2683 | |
| 2684 | ql_dbg(ql_dbg_tgt, vha, 0xe071, |
| 2685 | "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n", |
| 2686 | vha->vp_idx, __func__, se_cmd, se_cmd->prot_op, |
| 2687 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); |
| 2688 | |
| 2689 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || |
| 2690 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) |
| 2691 | bundling = 0; |
| 2692 | |
| 2693 | /* Compute dif len and adjust data len to incude protection */ |
| 2694 | data_bytes = cmd->bufflen; |
| 2695 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; |
| 2696 | |
| 2697 | switch (se_cmd->prot_op) { |
| 2698 | case TARGET_PROT_DIN_INSERT: |
| 2699 | case TARGET_PROT_DOUT_STRIP: |
| 2700 | transfer_length = data_bytes; |
| 2701 | data_bytes += dif_bytes; |
| 2702 | break; |
| 2703 | |
| 2704 | case TARGET_PROT_DIN_STRIP: |
| 2705 | case TARGET_PROT_DOUT_INSERT: |
| 2706 | case TARGET_PROT_DIN_PASS: |
| 2707 | case TARGET_PROT_DOUT_PASS: |
| 2708 | transfer_length = data_bytes + dif_bytes; |
| 2709 | break; |
| 2710 | |
| 2711 | default: |
| 2712 | BUG(); |
| 2713 | break; |
| 2714 | } |
| 2715 | |
| 2716 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2717 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 2718 | /* HBA error checking enabled */ |
| 2719 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2720 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2721 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2722 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2723 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2724 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2725 | } |
| 2726 | |
| 2727 | switch (se_cmd->prot_op) { |
| 2728 | case TARGET_PROT_DIN_INSERT: |
| 2729 | case TARGET_PROT_DOUT_INSERT: |
| 2730 | fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 2731 | break; |
| 2732 | case TARGET_PROT_DIN_STRIP: |
| 2733 | case TARGET_PROT_DOUT_STRIP: |
| 2734 | fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 2735 | break; |
| 2736 | case TARGET_PROT_DIN_PASS: |
| 2737 | case TARGET_PROT_DOUT_PASS: |
| 2738 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2739 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ |
| 2740 | break; |
| 2741 | default:/* Normal Request */ |
| 2742 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2743 | break; |
| 2744 | } |
| 2745 | |
| 2746 | |
| 2747 | /* ---- PKT ---- */ |
| 2748 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 2749 | pkt->entry_type = CTIO_CRC2; |
| 2750 | pkt->entry_count = 1; |
| 2751 | pkt->vp_index = vha->vp_idx; |
| 2752 | |
| 2753 | h = qlt_make_handle(vha); |
| 2754 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2755 | /* |
| 2756 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2757 | * know the initiator's LOOP ID, hence we can't find |
| 2758 | * the session and, so, the command. |
| 2759 | */ |
| 2760 | return -EAGAIN; |
| 2761 | } else |
| 2762 | ha->tgt.cmds[h-1] = prm->cmd; |
| 2763 | |
| 2764 | |
| 2765 | pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK; |
| 2766 | pkt->nport_handle = prm->cmd->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2767 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2768 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2769 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2770 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2771 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2772 | |
| 2773 | /* silence compile warning */ |
| 2774 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2775 | pkt->ox_id = cpu_to_le16(t16); |
| 2776 | |
| 2777 | t16 = (atio->u.isp24.attr << 9); |
| 2778 | pkt->flags |= cpu_to_le16(t16); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2779 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2780 | |
| 2781 | /* Set transfer direction */ |
| 2782 | if (cmd->dma_data_direction == DMA_TO_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2783 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2784 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2785 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2786 | |
| 2787 | |
| 2788 | pkt->dseg_count = prm->tot_dsds; |
| 2789 | /* Fibre channel byte count */ |
| 2790 | pkt->transfer_length = cpu_to_le32(transfer_length); |
| 2791 | |
| 2792 | |
| 2793 | /* ----- CRC context -------- */ |
| 2794 | |
| 2795 | /* Allocate CRC context from global pool */ |
| 2796 | crc_ctx_pkt = cmd->ctx = |
| 2797 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
| 2798 | |
| 2799 | if (!crc_ctx_pkt) |
| 2800 | goto crc_queuing_error; |
| 2801 | |
| 2802 | /* Zero out CTX area. */ |
| 2803 | clr_ptr = (uint8_t *)crc_ctx_pkt; |
| 2804 | memset(clr_ptr, 0, sizeof(*crc_ctx_pkt)); |
| 2805 | |
| 2806 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 2807 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 2808 | |
| 2809 | /* Set handle */ |
| 2810 | crc_ctx_pkt->handle = pkt->handle; |
| 2811 | |
| 2812 | qlt_set_t10dif_tags(se_cmd, crc_ctx_pkt); |
| 2813 | |
| 2814 | pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); |
| 2815 | pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); |
| 2816 | pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 2817 | |
| 2818 | |
| 2819 | if (!bundling) { |
| 2820 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; |
| 2821 | } else { |
| 2822 | /* |
| 2823 | * Configure Bundling if we need to fetch interlaving |
| 2824 | * protection PCI accesses |
| 2825 | */ |
| 2826 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 2827 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 2828 | crc_ctx_pkt->u.bundling.dseg_count = |
| 2829 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); |
| 2830 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; |
| 2831 | } |
| 2832 | |
| 2833 | /* Finish the common fields of CRC pkt */ |
| 2834 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); |
| 2835 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 2836 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2837 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2838 | |
| 2839 | |
| 2840 | /* Walks data segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2841 | pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2842 | |
| 2843 | if (!bundling && prm->prot_seg_cnt) { |
| 2844 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, |
| 2845 | prm->tot_dsds, cmd)) |
| 2846 | goto crc_queuing_error; |
| 2847 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, |
| 2848 | (prm->tot_dsds - prm->prot_seg_cnt), cmd)) |
| 2849 | goto crc_queuing_error; |
| 2850 | |
| 2851 | if (bundling && prm->prot_seg_cnt) { |
| 2852 | /* Walks dif segments */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2853 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2854 | |
| 2855 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; |
| 2856 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, |
| 2857 | prm->prot_seg_cnt, cmd)) |
| 2858 | goto crc_queuing_error; |
| 2859 | } |
| 2860 | return QLA_SUCCESS; |
| 2861 | |
| 2862 | crc_queuing_error: |
| 2863 | /* Cleanup will be performed by the caller */ |
| 2864 | |
| 2865 | return QLA_FUNCTION_FAILED; |
| 2866 | } |
| 2867 | |
| 2868 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2869 | /* |
| 2870 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * |
| 2871 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon |
| 2872 | */ |
| 2873 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, |
| 2874 | uint8_t scsi_status) |
| 2875 | { |
| 2876 | struct scsi_qla_host *vha = cmd->vha; |
| 2877 | struct qla_hw_data *ha = vha->hw; |
| 2878 | struct ctio7_to_24xx *pkt; |
| 2879 | struct qla_tgt_prm prm; |
| 2880 | uint32_t full_req_cnt = 0; |
| 2881 | unsigned long flags = 0; |
| 2882 | int res; |
| 2883 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 2884 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2885 | if (cmd->sess && cmd->sess->deleted) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 2886 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 2887 | if (cmd->sess->logout_completed) |
| 2888 | /* no need to terminate. FW already freed exchange. */ |
| 2889 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 2890 | else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 2891 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 2892 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2893 | return 0; |
| 2894 | } |
| 2895 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2896 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2897 | memset(&prm, 0, sizeof(prm)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2898 | |
| 2899 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe018, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2900 | "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p]\n", |
| 2901 | (xmit_type & QLA_TGT_XMIT_STATUS) ? |
| 2902 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, |
| 2903 | &cmd->se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2904 | |
| 2905 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, |
| 2906 | &full_req_cnt); |
| 2907 | if (unlikely(res != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2908 | return res; |
| 2909 | } |
| 2910 | |
| 2911 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2912 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 2913 | if (xmit_type == QLA_TGT_XMIT_STATUS) |
| 2914 | vha->tgt_counters.core_qla_snd_status++; |
| 2915 | else |
| 2916 | vha->tgt_counters.core_qla_que_buf++; |
| 2917 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2918 | if (!vha->flags.online || cmd->reset_count != ha->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2919 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2920 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2921 | * previous life, just abort the processing. |
| 2922 | */ |
| 2923 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 2924 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 2925 | ql_dbg(ql_dbg_async, vha, 0xe101, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2926 | "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2927 | vha->flags.online, qla2x00_reset_active(vha), |
| 2928 | cmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2929 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2930 | return 0; |
| 2931 | } |
| 2932 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2933 | /* Does F/W have an IOCBs for this request */ |
| 2934 | res = qlt_check_reserve_free_req(vha, full_req_cnt); |
| 2935 | if (unlikely(res)) |
| 2936 | goto out_unmap_unlock; |
| 2937 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2938 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
| 2939 | res = qlt_build_ctio_crc2_pkt(&prm, vha); |
| 2940 | else |
| 2941 | res = qlt_24xx_build_ctio_pkt(&prm, vha); |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 2942 | if (unlikely(res != 0)) { |
| 2943 | vha->req->cnt += full_req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2944 | goto out_unmap_unlock; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 2945 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2946 | |
| 2947 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
| 2948 | |
| 2949 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { |
| 2950 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2951 | cpu_to_le16(CTIO7_FLAGS_DATA_IN | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2952 | CTIO7_FLAGS_STATUS_MODE_0); |
| 2953 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2954 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
| 2955 | qlt_load_data_segments(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2956 | |
| 2957 | if (prm.add_status_pkt == 0) { |
| 2958 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2959 | pkt->u.status0.scsi_status = |
| 2960 | cpu_to_le16(prm.rq_result); |
| 2961 | pkt->u.status0.residual = |
| 2962 | cpu_to_le32(prm.residual); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2963 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2964 | CTIO7_FLAGS_SEND_STATUS); |
| 2965 | if (qlt_need_explicit_conf(ha, cmd, 0)) { |
| 2966 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2967 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2968 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2969 | CTIO7_FLAGS_CONFORM_REQ); |
| 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | } else { |
| 2974 | /* |
| 2975 | * We have already made sure that there is sufficient |
| 2976 | * amount of request entries to not drop HW lock in |
| 2977 | * req_pkt(). |
| 2978 | */ |
| 2979 | struct ctio7_to_24xx *ctio = |
| 2980 | (struct ctio7_to_24xx *)qlt_get_req_pkt(vha); |
| 2981 | |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2982 | ql_dbg(ql_dbg_io, vha, 0x305e, |
| 2983 | "Building additional status packet 0x%p.\n", |
| 2984 | ctio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2985 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2986 | /* |
| 2987 | * T10Dif: ctio_crc2_to_fw overlay ontop of |
| 2988 | * ctio7_to_24xx |
| 2989 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2990 | memcpy(ctio, pkt, sizeof(*ctio)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2991 | /* reset back to CTIO7 */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2992 | ctio->entry_count = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2993 | ctio->entry_type = CTIO_TYPE7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2994 | ctio->dseg_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2995 | ctio->u.status1.flags &= ~cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2996 | CTIO7_FLAGS_DATA_IN); |
| 2997 | |
| 2998 | /* Real finish is ctio_m1's finish */ |
| 2999 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3000 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3001 | CTIO7_FLAGS_DONT_RET_CTIO); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3002 | |
| 3003 | /* qlt_24xx_init_ctio_to_isp will correct |
| 3004 | * all neccessary fields that's part of CTIO7. |
| 3005 | * There should be no residual of CTIO-CRC2 data. |
| 3006 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3007 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
| 3008 | &prm); |
| 3009 | pr_debug("Status CTIO7: %p\n", ctio); |
| 3010 | } |
| 3011 | } else |
| 3012 | qlt_24xx_init_ctio_to_isp(pkt, &prm); |
| 3013 | |
| 3014 | |
| 3015 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3016 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3017 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3018 | /* Memory Barrier */ |
| 3019 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3020 | qla2x00_start_iocbs(vha, vha->req); |
| 3021 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3022 | |
| 3023 | return 0; |
| 3024 | |
| 3025 | out_unmap_unlock: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3026 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3027 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3028 | |
| 3029 | return res; |
| 3030 | } |
| 3031 | EXPORT_SYMBOL(qlt_xmit_response); |
| 3032 | |
| 3033 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) |
| 3034 | { |
| 3035 | struct ctio7_to_24xx *pkt; |
| 3036 | struct scsi_qla_host *vha = cmd->vha; |
| 3037 | struct qla_hw_data *ha = vha->hw; |
| 3038 | struct qla_tgt *tgt = cmd->tgt; |
| 3039 | struct qla_tgt_prm prm; |
| 3040 | unsigned long flags; |
| 3041 | int res = 0; |
| 3042 | |
| 3043 | memset(&prm, 0, sizeof(prm)); |
| 3044 | prm.cmd = cmd; |
| 3045 | prm.tgt = tgt; |
| 3046 | prm.sg = NULL; |
| 3047 | prm.req_cnt = 1; |
| 3048 | |
| 3049 | /* Send marker if required */ |
| 3050 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) |
| 3051 | return -EIO; |
| 3052 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3053 | /* Calculate number of entries and segments required */ |
| 3054 | if (qlt_pci_map_calc_cnt(&prm) != 0) |
| 3055 | return -EAGAIN; |
| 3056 | |
| 3057 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3058 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3059 | if (!vha->flags.online || (cmd->reset_count != ha->chip_reset) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3060 | (cmd->sess && cmd->sess->deleted)) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3061 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3062 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3063 | * previous life, just abort the processing. |
| 3064 | */ |
| 3065 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
| 3066 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 3067 | ql_dbg(ql_dbg_async, vha, 0xe102, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3068 | "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3069 | vha->flags.online, qla2x00_reset_active(vha), |
| 3070 | cmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3071 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3072 | return 0; |
| 3073 | } |
| 3074 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3075 | /* Does F/W have an IOCBs for this request */ |
| 3076 | res = qlt_check_reserve_free_req(vha, prm.req_cnt); |
| 3077 | if (res != 0) |
| 3078 | goto out_unlock_free_unmap; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3079 | if (cmd->se_cmd.prot_op) |
| 3080 | res = qlt_build_ctio_crc2_pkt(&prm, vha); |
| 3081 | else |
| 3082 | res = qlt_24xx_build_ctio_pkt(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3083 | |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3084 | if (unlikely(res != 0)) { |
| 3085 | vha->req->cnt += prm.req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3086 | goto out_unlock_free_unmap; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3087 | } |
| 3088 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3089 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3090 | pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3091 | CTIO7_FLAGS_STATUS_MODE_0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3092 | |
| 3093 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
| 3094 | qlt_load_data_segments(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3095 | |
| 3096 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3097 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3098 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3099 | /* Memory Barrier */ |
| 3100 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3101 | qla2x00_start_iocbs(vha, vha->req); |
| 3102 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3103 | |
| 3104 | return res; |
| 3105 | |
| 3106 | out_unlock_free_unmap: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3107 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3108 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3109 | |
| 3110 | return res; |
| 3111 | } |
| 3112 | EXPORT_SYMBOL(qlt_rdy_to_xfer); |
| 3113 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3114 | |
| 3115 | /* |
| 3116 | * Checks the guard or meta-data for the type of error |
| 3117 | * detected by the HBA. |
| 3118 | */ |
| 3119 | static inline int |
| 3120 | qlt_handle_dif_error(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd, |
| 3121 | struct ctio_crc_from_fw *sts) |
| 3122 | { |
| 3123 | uint8_t *ap = &sts->actual_dif[0]; |
| 3124 | uint8_t *ep = &sts->expected_dif[0]; |
| 3125 | uint32_t e_ref_tag, a_ref_tag; |
| 3126 | uint16_t e_app_tag, a_app_tag; |
| 3127 | uint16_t e_guard, a_guard; |
| 3128 | uint64_t lba = cmd->se_cmd.t_task_lba; |
| 3129 | |
| 3130 | a_guard = be16_to_cpu(*(uint16_t *)(ap + 0)); |
| 3131 | a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2)); |
| 3132 | a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4)); |
| 3133 | |
| 3134 | e_guard = be16_to_cpu(*(uint16_t *)(ep + 0)); |
| 3135 | e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2)); |
| 3136 | e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4)); |
| 3137 | |
| 3138 | ql_dbg(ql_dbg_tgt, vha, 0xe075, |
| 3139 | "iocb(s) %p Returned STATUS.\n", sts); |
| 3140 | |
| 3141 | ql_dbg(ql_dbg_tgt, vha, 0xf075, |
Hans Wennborg | fc38504 | 2014-08-05 21:43:29 -0700 | [diff] [blame] | 3142 | "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] | 3143 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 3144 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, a_guard, e_guard); |
| 3145 | |
| 3146 | /* |
| 3147 | * Ignore sector if: |
| 3148 | * For type 3: ref & app tag is all 'f's |
| 3149 | * For type 0,1,2: app tag is all 'f's |
| 3150 | */ |
| 3151 | if ((a_app_tag == 0xffff) && |
| 3152 | ((cmd->se_cmd.prot_type != TARGET_DIF_TYPE3_PROT) || |
| 3153 | (a_ref_tag == 0xffffffff))) { |
| 3154 | uint32_t blocks_done; |
| 3155 | |
| 3156 | /* 2TB boundary case covered automatically with this */ |
| 3157 | blocks_done = e_ref_tag - (uint32_t)lba + 1; |
| 3158 | cmd->se_cmd.bad_sector = e_ref_tag; |
| 3159 | cmd->se_cmd.pi_err = 0; |
| 3160 | ql_dbg(ql_dbg_tgt, vha, 0xf074, |
| 3161 | "need to return scsi good\n"); |
| 3162 | |
| 3163 | /* Update protection tag */ |
| 3164 | if (cmd->prot_sg_cnt) { |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 3165 | uint32_t i, k = 0, num_ent; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3166 | struct scatterlist *sg, *sgl; |
| 3167 | |
| 3168 | |
| 3169 | sgl = cmd->prot_sg; |
| 3170 | |
| 3171 | /* Patch the corresponding protection tags */ |
| 3172 | for_each_sg(sgl, sg, cmd->prot_sg_cnt, i) { |
| 3173 | num_ent = sg_dma_len(sg) / 8; |
| 3174 | if (k + num_ent < blocks_done) { |
| 3175 | k += num_ent; |
| 3176 | continue; |
| 3177 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3178 | k = blocks_done; |
| 3179 | break; |
| 3180 | } |
| 3181 | |
| 3182 | if (k != blocks_done) { |
| 3183 | ql_log(ql_log_warn, vha, 0xf076, |
| 3184 | "unexpected tag values tag:lba=%u:%llu)\n", |
| 3185 | e_ref_tag, (unsigned long long)lba); |
| 3186 | goto out; |
| 3187 | } |
| 3188 | |
| 3189 | #if 0 |
| 3190 | struct sd_dif_tuple *spt; |
| 3191 | /* TODO: |
| 3192 | * This section came from initiator. Is it valid here? |
| 3193 | * should ulp be override with actual val??? |
| 3194 | */ |
| 3195 | spt = page_address(sg_page(sg)) + sg->offset; |
| 3196 | spt += j; |
| 3197 | |
| 3198 | spt->app_tag = 0xffff; |
| 3199 | if (cmd->se_cmd.prot_type == SCSI_PROT_DIF_TYPE3) |
| 3200 | spt->ref_tag = 0xffffffff; |
| 3201 | #endif |
| 3202 | } |
| 3203 | |
| 3204 | return 0; |
| 3205 | } |
| 3206 | |
| 3207 | /* check guard */ |
| 3208 | if (e_guard != a_guard) { |
| 3209 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED; |
| 3210 | cmd->se_cmd.bad_sector = cmd->se_cmd.t_task_lba; |
| 3211 | |
| 3212 | ql_log(ql_log_warn, vha, 0xe076, |
| 3213 | "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", |
| 3214 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 3215 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, |
| 3216 | a_guard, e_guard, cmd); |
| 3217 | goto out; |
| 3218 | } |
| 3219 | |
| 3220 | /* check ref tag */ |
| 3221 | if (e_ref_tag != a_ref_tag) { |
| 3222 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED; |
| 3223 | cmd->se_cmd.bad_sector = e_ref_tag; |
| 3224 | |
| 3225 | ql_log(ql_log_warn, vha, 0xe077, |
| 3226 | "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", |
| 3227 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 3228 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, |
| 3229 | a_guard, e_guard, cmd); |
| 3230 | goto out; |
| 3231 | } |
| 3232 | |
| 3233 | /* check appl tag */ |
| 3234 | if (e_app_tag != a_app_tag) { |
| 3235 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED; |
| 3236 | cmd->se_cmd.bad_sector = cmd->se_cmd.t_task_lba; |
| 3237 | |
| 3238 | ql_log(ql_log_warn, vha, 0xe078, |
| 3239 | "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", |
| 3240 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 3241 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, |
| 3242 | a_guard, e_guard, cmd); |
| 3243 | goto out; |
| 3244 | } |
| 3245 | out: |
| 3246 | return 1; |
| 3247 | } |
| 3248 | |
| 3249 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3250 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3251 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3252 | static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3253 | struct imm_ntfy_from_isp *ntfy) |
| 3254 | { |
| 3255 | struct nack_to_isp *nack; |
| 3256 | struct qla_hw_data *ha = vha->hw; |
| 3257 | request_t *pkt; |
| 3258 | int ret = 0; |
| 3259 | |
| 3260 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c, |
| 3261 | "Sending TERM ELS CTIO (ha=%p)\n", ha); |
| 3262 | |
| 3263 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(vha, NULL); |
| 3264 | if (pkt == NULL) { |
| 3265 | ql_dbg(ql_dbg_tgt, vha, 0xe080, |
| 3266 | "qla_target(%d): %s failed: unable to allocate " |
| 3267 | "request packet\n", vha->vp_idx, __func__); |
| 3268 | return -ENOMEM; |
| 3269 | } |
| 3270 | |
| 3271 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 3272 | pkt->entry_count = 1; |
Quinn Tran | 4f06073 | 2016-12-23 18:06:13 -0800 | [diff] [blame] | 3273 | pkt->handle = QLA_TGT_SKIP_HANDLE; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3274 | |
| 3275 | nack = (struct nack_to_isp *)pkt; |
| 3276 | nack->ox_id = ntfy->ox_id; |
| 3277 | |
| 3278 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3279 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3280 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
| 3281 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
| 3282 | } |
| 3283 | |
| 3284 | /* terminate */ |
| 3285 | nack->u.isp24.flags |= |
| 3286 | __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE); |
| 3287 | |
| 3288 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3289 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3290 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3291 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3292 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3293 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3294 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3295 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3296 | |
| 3297 | qla2x00_start_iocbs(vha, vha->req); |
| 3298 | return ret; |
| 3299 | } |
| 3300 | |
| 3301 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3302 | struct imm_ntfy_from_isp *imm, int ha_locked) |
| 3303 | { |
| 3304 | unsigned long flags = 0; |
| 3305 | int rc; |
| 3306 | |
| 3307 | if (qlt_issue_marker(vha, ha_locked) < 0) |
| 3308 | return; |
| 3309 | |
| 3310 | if (ha_locked) { |
| 3311 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3312 | |
| 3313 | #if 0 /* Todo */ |
| 3314 | if (rc == -ENOMEM) |
| 3315 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
Bart Van Assche | 91f42b3 | 2016-03-30 15:25:21 -0700 | [diff] [blame] | 3316 | #else |
| 3317 | if (rc) { |
| 3318 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3319 | #endif |
| 3320 | goto done; |
| 3321 | } |
| 3322 | |
| 3323 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 3324 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3325 | |
| 3326 | #if 0 /* Todo */ |
| 3327 | if (rc == -ENOMEM) |
| 3328 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
| 3329 | #endif |
| 3330 | |
| 3331 | done: |
| 3332 | if (!ha_locked) |
| 3333 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 3334 | } |
| 3335 | |
| 3336 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3337 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3338 | static int __qlt_send_term_exchange(struct scsi_qla_host *vha, |
| 3339 | struct qla_tgt_cmd *cmd, |
| 3340 | struct atio_from_isp *atio) |
| 3341 | { |
| 3342 | struct ctio7_to_24xx *ctio24; |
| 3343 | struct qla_hw_data *ha = vha->hw; |
| 3344 | request_t *pkt; |
| 3345 | int ret = 0; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3346 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3347 | |
| 3348 | ql_dbg(ql_dbg_tgt, vha, 0xe01c, "Sending TERM EXCH CTIO (ha=%p)\n", ha); |
| 3349 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3350 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3351 | if (pkt == NULL) { |
| 3352 | ql_dbg(ql_dbg_tgt, vha, 0xe050, |
| 3353 | "qla_target(%d): %s failed: unable to allocate " |
| 3354 | "request packet\n", vha->vp_idx, __func__); |
| 3355 | return -ENOMEM; |
| 3356 | } |
| 3357 | |
| 3358 | if (cmd != NULL) { |
| 3359 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { |
| 3360 | ql_dbg(ql_dbg_tgt, vha, 0xe051, |
| 3361 | "qla_target(%d): Terminating cmd %p with " |
| 3362 | "incorrect state %d\n", vha->vp_idx, cmd, |
| 3363 | cmd->state); |
| 3364 | } else |
| 3365 | ret = 1; |
| 3366 | } |
| 3367 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3368 | vha->tgt_counters.num_term_xchg_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3369 | pkt->entry_count = 1; |
| 3370 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 3371 | |
| 3372 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 3373 | ctio24->entry_type = CTIO_TYPE7; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3374 | ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3375 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3376 | ctio24->vp_index = vha->vp_idx; |
| 3377 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 3378 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 3379 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 3380 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
| 3381 | ctio24->u.status1.flags = (atio->u.isp24.attr << 9) | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3382 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3383 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3384 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3385 | ctio24->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3386 | |
| 3387 | /* Most likely, it isn't needed */ |
| 3388 | ctio24->u.status1.residual = get_unaligned((uint32_t *) |
| 3389 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 3390 | atio->u.isp24.fcp_cmnd.add_cdb_len]); |
| 3391 | if (ctio24->u.status1.residual != 0) |
| 3392 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; |
| 3393 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3394 | /* Memory Barrier */ |
| 3395 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3396 | qla2x00_start_iocbs(vha, vha->req); |
| 3397 | return ret; |
| 3398 | } |
| 3399 | |
| 3400 | static void qlt_send_term_exchange(struct scsi_qla_host *vha, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3401 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, |
| 3402 | int ul_abort) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3403 | { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3404 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3405 | int rc; |
| 3406 | |
| 3407 | if (qlt_issue_marker(vha, ha_locked) < 0) |
| 3408 | return; |
| 3409 | |
| 3410 | if (ha_locked) { |
| 3411 | rc = __qlt_send_term_exchange(vha, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3412 | if (rc == -ENOMEM) |
| 3413 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3414 | goto done; |
| 3415 | } |
| 3416 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 3417 | rc = __qlt_send_term_exchange(vha, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3418 | if (rc == -ENOMEM) |
| 3419 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3420 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3421 | done: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3422 | if (cmd && !ul_abort && !cmd->aborted) { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3423 | if (cmd->sg_mapped) |
| 3424 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3425 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3426 | } |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3427 | |
| 3428 | if (!ha_locked) |
| 3429 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 3430 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3431 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3432 | } |
| 3433 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3434 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
| 3435 | { |
| 3436 | struct list_head free_list; |
| 3437 | struct qla_tgt_cmd *cmd, *tcmd; |
| 3438 | |
| 3439 | vha->hw->tgt.leak_exchg_thresh_hold = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3440 | (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3441 | |
| 3442 | cmd = tcmd = NULL; |
| 3443 | if (!list_empty(&vha->hw->tgt.q_full_list)) { |
| 3444 | INIT_LIST_HEAD(&free_list); |
| 3445 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); |
| 3446 | |
| 3447 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 3448 | list_del(&cmd->cmd_list); |
| 3449 | /* This cmd was never sent to TCM. There is no need |
| 3450 | * to schedule free or call free_cmd |
| 3451 | */ |
| 3452 | qlt_free_cmd(cmd); |
| 3453 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 3454 | } |
| 3455 | } |
| 3456 | vha->hw->tgt.num_qfull_cmds_dropped = 0; |
| 3457 | } |
| 3458 | |
| 3459 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) |
| 3460 | { |
| 3461 | uint32_t total_leaked; |
| 3462 | |
| 3463 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; |
| 3464 | |
| 3465 | if (vha->hw->tgt.leak_exchg_thresh_hold && |
| 3466 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { |
| 3467 | |
| 3468 | ql_dbg(ql_dbg_tgt, vha, 0xe079, |
| 3469 | "Chip reset due to exchange starvation: %d/%d.\n", |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3470 | total_leaked, vha->hw->cur_fw_xcb_count); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3471 | |
| 3472 | if (IS_P3P_TYPE(vha->hw)) |
| 3473 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 3474 | else |
| 3475 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3476 | qla2xxx_wake_dpc(vha); |
| 3477 | } |
| 3478 | |
| 3479 | } |
| 3480 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3481 | int qlt_abort_cmd(struct qla_tgt_cmd *cmd) |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3482 | { |
| 3483 | struct qla_tgt *tgt = cmd->tgt; |
| 3484 | struct scsi_qla_host *vha = tgt->vha; |
| 3485 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3486 | unsigned long flags; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3487 | |
| 3488 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, |
| 3489 | "qla_target(%d): terminating exchange for aborted cmd=%p " |
| 3490 | "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, |
| 3491 | se_cmd->tag); |
| 3492 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3493 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3494 | if (cmd->aborted) { |
| 3495 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3496 | /* |
| 3497 | * It's normal to see 2 calls in this path: |
| 3498 | * 1) XFER Rdy completion + CMD_T_ABORT |
| 3499 | * 2) TCM TMR - drain_state_list |
| 3500 | */ |
| 3501 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xffff, |
| 3502 | "multiple abort. %p transport_state %x, t_state %x," |
| 3503 | " se_cmd_flags %x \n", cmd, cmd->se_cmd.transport_state, |
| 3504 | cmd->se_cmd.t_state,cmd->se_cmd.se_cmd_flags); |
| 3505 | return EIO; |
| 3506 | } |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3507 | cmd->aborted = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3508 | cmd->trc_flags |= TRC_ABORT; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3509 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3510 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3511 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 0, 1); |
| 3512 | return 0; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3513 | } |
| 3514 | EXPORT_SYMBOL(qlt_abort_cmd); |
| 3515 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3516 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
| 3517 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3518 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3519 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3520 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
| 3521 | "%s: se_cmd[%p] ox_id %04x\n", |
| 3522 | __func__, &cmd->se_cmd, |
| 3523 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3524 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3525 | BUG_ON(cmd->cmd_in_wq); |
| 3526 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3527 | if (cmd->sg_mapped) |
| 3528 | qlt_unmap_sg(cmd->vha, cmd); |
| 3529 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3530 | if (!cmd->q_full) |
| 3531 | qlt_decr_num_pend_cmds(cmd->vha); |
| 3532 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3533 | BUG_ON(cmd->sg_mapped); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3534 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3535 | if (unlikely(cmd->free_sg)) |
| 3536 | kfree(cmd->sg); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3537 | |
| 3538 | if (!sess || !sess->se_sess) { |
| 3539 | WARN_ON(1); |
| 3540 | return; |
| 3541 | } |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3542 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3543 | 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] | 3544 | } |
| 3545 | EXPORT_SYMBOL(qlt_free_cmd); |
| 3546 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3547 | /* |
| 3548 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3549 | */ |
| 3550 | static int qlt_term_ctio_exchange(struct scsi_qla_host *vha, void *ctio, |
| 3551 | struct qla_tgt_cmd *cmd, uint32_t status) |
| 3552 | { |
| 3553 | int term = 0; |
| 3554 | |
| 3555 | if (ctio != NULL) { |
| 3556 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; |
| 3557 | term = !(c->flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3558 | cpu_to_le16(OF_TERM_EXCH)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3559 | } else |
| 3560 | term = 1; |
| 3561 | |
| 3562 | if (term) |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3563 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3564 | |
| 3565 | return term; |
| 3566 | } |
| 3567 | |
| 3568 | /* ha->hardware_lock supposed to be held on entry */ |
| 3569 | static inline struct qla_tgt_cmd *qlt_get_cmd(struct scsi_qla_host *vha, |
| 3570 | uint32_t handle) |
| 3571 | { |
| 3572 | struct qla_hw_data *ha = vha->hw; |
| 3573 | |
| 3574 | handle--; |
| 3575 | if (ha->tgt.cmds[handle] != NULL) { |
| 3576 | struct qla_tgt_cmd *cmd = ha->tgt.cmds[handle]; |
| 3577 | ha->tgt.cmds[handle] = NULL; |
| 3578 | return cmd; |
| 3579 | } else |
| 3580 | return NULL; |
| 3581 | } |
| 3582 | |
| 3583 | /* ha->hardware_lock supposed to be held on entry */ |
| 3584 | static struct qla_tgt_cmd *qlt_ctio_to_cmd(struct scsi_qla_host *vha, |
| 3585 | uint32_t handle, void *ctio) |
| 3586 | { |
| 3587 | struct qla_tgt_cmd *cmd = NULL; |
| 3588 | |
| 3589 | /* Clear out internal marks */ |
| 3590 | handle &= ~(CTIO_COMPLETION_HANDLE_MARK | |
| 3591 | CTIO_INTERMEDIATE_HANDLE_MARK); |
| 3592 | |
| 3593 | if (handle != QLA_TGT_NULL_HANDLE) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3594 | if (unlikely(handle == QLA_TGT_SKIP_HANDLE)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3595 | return NULL; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3596 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3597 | /* handle-1 is actually used */ |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3598 | if (unlikely(handle > DEFAULT_OUTSTANDING_COMMANDS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3599 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
| 3600 | "qla_target(%d): Wrong handle %x received\n", |
| 3601 | vha->vp_idx, handle); |
| 3602 | return NULL; |
| 3603 | } |
| 3604 | cmd = qlt_get_cmd(vha, handle); |
| 3605 | if (unlikely(cmd == NULL)) { |
| 3606 | ql_dbg(ql_dbg_tgt, vha, 0xe053, |
| 3607 | "qla_target(%d): Suspicious: unable to " |
| 3608 | "find the command with handle %x\n", vha->vp_idx, |
| 3609 | handle); |
| 3610 | return NULL; |
| 3611 | } |
| 3612 | } else if (ctio != NULL) { |
| 3613 | /* We can't get loop ID from CTIO7 */ |
| 3614 | ql_dbg(ql_dbg_tgt, vha, 0xe054, |
| 3615 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " |
| 3616 | "support NULL handles\n", vha->vp_idx); |
| 3617 | return NULL; |
| 3618 | } |
| 3619 | |
| 3620 | return cmd; |
| 3621 | } |
| 3622 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3623 | /* hardware_lock should be held by caller. */ |
| 3624 | static void |
| 3625 | qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) |
| 3626 | { |
| 3627 | struct qla_hw_data *ha = vha->hw; |
| 3628 | uint32_t handle; |
| 3629 | |
| 3630 | if (cmd->sg_mapped) |
| 3631 | qlt_unmap_sg(vha, cmd); |
| 3632 | |
| 3633 | handle = qlt_make_handle(vha); |
| 3634 | |
| 3635 | /* TODO: fix debug message type and ids. */ |
| 3636 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
| 3637 | ql_dbg(ql_dbg_io, vha, 0xff00, |
| 3638 | "HOST-ABORT: handle=%d, state=PROCESSED.\n", handle); |
| 3639 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 3640 | cmd->write_data_transferred = 0; |
| 3641 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3642 | |
| 3643 | ql_dbg(ql_dbg_io, vha, 0xff01, |
| 3644 | "HOST-ABORT: handle=%d, state=DATA_IN.\n", handle); |
| 3645 | |
| 3646 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3647 | return; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3648 | } else { |
| 3649 | ql_dbg(ql_dbg_io, vha, 0xff03, |
| 3650 | "HOST-ABORT: handle=%d, state=BAD(%d).\n", handle, |
| 3651 | cmd->state); |
| 3652 | dump_stack(); |
| 3653 | } |
| 3654 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3655 | cmd->trc_flags |= TRC_FLUSH; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3656 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3657 | } |
| 3658 | |
| 3659 | void |
| 3660 | qlt_host_reset_handler(struct qla_hw_data *ha) |
| 3661 | { |
| 3662 | struct qla_tgt_cmd *cmd; |
| 3663 | unsigned long flags; |
| 3664 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
| 3665 | scsi_qla_host_t *vha = NULL; |
| 3666 | struct qla_tgt *tgt = base_vha->vha_tgt.qla_tgt; |
| 3667 | uint32_t i; |
| 3668 | |
| 3669 | if (!base_vha->hw->tgt.tgt_ops) |
| 3670 | return; |
| 3671 | |
| 3672 | if (!tgt || qla_ini_mode_enabled(base_vha)) { |
| 3673 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003, |
| 3674 | "Target mode disabled\n"); |
| 3675 | return; |
| 3676 | } |
| 3677 | |
| 3678 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xff10, |
| 3679 | "HOST-ABORT-HNDLR: base_vha->dpc_flags=%lx.\n", |
| 3680 | base_vha->dpc_flags); |
| 3681 | |
| 3682 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3683 | for (i = 1; i < DEFAULT_OUTSTANDING_COMMANDS + 1; i++) { |
| 3684 | cmd = qlt_get_cmd(base_vha, i); |
| 3685 | if (!cmd) |
| 3686 | continue; |
| 3687 | /* ha->tgt.cmds entry is cleared by qlt_get_cmd. */ |
| 3688 | vha = cmd->vha; |
| 3689 | qlt_abort_cmd_on_host_reset(vha, cmd); |
| 3690 | } |
| 3691 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3692 | } |
| 3693 | |
| 3694 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3695 | /* |
| 3696 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3697 | */ |
| 3698 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, uint32_t handle, |
| 3699 | uint32_t status, void *ctio) |
| 3700 | { |
| 3701 | struct qla_hw_data *ha = vha->hw; |
| 3702 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3703 | struct qla_tgt_cmd *cmd; |
| 3704 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3705 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
| 3706 | /* That could happen only in case of an error/reset/abort */ |
| 3707 | if (status != CTIO_SUCCESS) { |
| 3708 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, |
| 3709 | "Intermediate CTIO received" |
| 3710 | " (status %x)\n", status); |
| 3711 | } |
| 3712 | return; |
| 3713 | } |
| 3714 | |
| 3715 | cmd = qlt_ctio_to_cmd(vha, handle, ctio); |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3716 | if (cmd == NULL) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3717 | return; |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3718 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3719 | se_cmd = &cmd->se_cmd; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3720 | cmd->cmd_sent_to_fw = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3721 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3722 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3723 | |
| 3724 | if (unlikely(status != CTIO_SUCCESS)) { |
| 3725 | switch (status & 0xFFFF) { |
| 3726 | case CTIO_LIP_RESET: |
| 3727 | case CTIO_TARGET_RESET: |
| 3728 | case CTIO_ABORTED: |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3729 | /* driver request abort via Terminate exchange */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3730 | case CTIO_TIMEOUT: |
| 3731 | case CTIO_INVALID_RX_ID: |
| 3732 | /* They are OK */ |
| 3733 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, |
| 3734 | "qla_target(%d): CTIO with " |
| 3735 | "status %#x received, state %x, se_cmd %p, " |
| 3736 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " |
| 3737 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, |
| 3738 | status, cmd->state, se_cmd); |
| 3739 | break; |
| 3740 | |
| 3741 | case CTIO_PORT_LOGGED_OUT: |
| 3742 | case CTIO_PORT_UNAVAILABLE: |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3743 | { |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3744 | int logged_out = |
| 3745 | (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; |
| 3746 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3747 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3748 | "qla_target(%d): CTIO with %s status %x " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3749 | "received (state %x, se_cmd %p)\n", vha->vp_idx, |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3750 | logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3751 | status, cmd->state, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3752 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3753 | if (logged_out && cmd->sess) { |
| 3754 | /* |
| 3755 | * Session is already logged out, but we need |
| 3756 | * to notify initiator, who's not aware of this |
| 3757 | */ |
| 3758 | cmd->sess->logout_on_delete = 0; |
| 3759 | cmd->sess->send_els_logo = 1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3760 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 3761 | "%s %d %8phC post del sess\n", |
| 3762 | __func__, __LINE__, cmd->sess->port_name); |
| 3763 | |
| 3764 | qlt_schedule_sess_for_deletion_lock(cmd->sess); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3765 | } |
| 3766 | break; |
| 3767 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3768 | case CTIO_DIF_ERROR: { |
| 3769 | struct ctio_crc_from_fw *crc = |
| 3770 | (struct ctio_crc_from_fw *)ctio; |
| 3771 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, |
| 3772 | "qla_target(%d): CTIO with DIF_ERROR status %x received (state %x, se_cmd %p) actual_dif[0x%llx] expect_dif[0x%llx]\n", |
| 3773 | vha->vp_idx, status, cmd->state, se_cmd, |
| 3774 | *((u64 *)&crc->actual_dif[0]), |
| 3775 | *((u64 *)&crc->expected_dif[0])); |
| 3776 | |
| 3777 | if (qlt_handle_dif_error(vha, cmd, ctio)) { |
| 3778 | if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 3779 | /* scsi Write/xfer rdy complete */ |
| 3780 | goto skip_term; |
| 3781 | } else { |
| 3782 | /* scsi read/xmit respond complete |
| 3783 | * call handle dif to send scsi status |
| 3784 | * rather than terminate exchange. |
| 3785 | */ |
| 3786 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3787 | ha->tgt.tgt_ops->handle_dif_err(cmd); |
| 3788 | return; |
| 3789 | } |
| 3790 | } else { |
| 3791 | /* Need to generate a SCSI good completion. |
| 3792 | * because FW did not send scsi status. |
| 3793 | */ |
| 3794 | status = 0; |
| 3795 | goto skip_term; |
| 3796 | } |
| 3797 | break; |
| 3798 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3799 | default: |
| 3800 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3801 | "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] | 3802 | vha->vp_idx, status, cmd->state, se_cmd); |
| 3803 | break; |
| 3804 | } |
| 3805 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3806 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3807 | /* "cmd->aborted" means |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3808 | * cmd is already aborted/terminated, we don't |
| 3809 | * need to terminate again. The exchange is already |
| 3810 | * cleaned up/freed at FW level. Just cleanup at driver |
| 3811 | * level. |
| 3812 | */ |
| 3813 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3814 | (!cmd->aborted)) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3815 | cmd->trc_flags |= TRC_CTIO_ERR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3816 | if (qlt_term_ctio_exchange(vha, ctio, cmd, status)) |
| 3817 | return; |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3818 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3819 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3820 | skip_term: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3821 | |
| 3822 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3823 | cmd->trc_flags |= TRC_CTIO_DONE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3824 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3825 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3826 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 3827 | if (status == CTIO_SUCCESS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3828 | cmd->write_data_transferred = 1; |
| 3829 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3830 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3831 | return; |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3832 | } else if (cmd->aborted) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3833 | cmd->trc_flags |= TRC_CTIO_ABORTED; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3834 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 3835 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3836 | } else { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3837 | cmd->trc_flags |= TRC_CTIO_STRANGE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3838 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
| 3839 | "qla_target(%d): A command in state (%d) should " |
| 3840 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); |
| 3841 | } |
| 3842 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3843 | if (unlikely(status != CTIO_SUCCESS) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3844 | !cmd->aborted) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3845 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
| 3846 | dump_stack(); |
| 3847 | } |
| 3848 | |
| 3849 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3850 | } |
| 3851 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3852 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
| 3853 | uint8_t task_codes) |
| 3854 | { |
| 3855 | int fcp_task_attr; |
| 3856 | |
| 3857 | switch (task_codes) { |
| 3858 | case ATIO_SIMPLE_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3859 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3860 | break; |
| 3861 | case ATIO_HEAD_OF_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3862 | fcp_task_attr = TCM_HEAD_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3863 | break; |
| 3864 | case ATIO_ORDERED_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3865 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3866 | break; |
| 3867 | case ATIO_ACA_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3868 | fcp_task_attr = TCM_ACA_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3869 | break; |
| 3870 | case ATIO_UNTAGGED: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3871 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3872 | break; |
| 3873 | default: |
| 3874 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, |
| 3875 | "qla_target: unknown task code %x, use ORDERED instead\n", |
| 3876 | task_codes); |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3877 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3878 | break; |
| 3879 | } |
| 3880 | |
| 3881 | return fcp_task_attr; |
| 3882 | } |
| 3883 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3884 | static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3885 | uint8_t *); |
| 3886 | /* |
| 3887 | * Process context for I/O path into tcm_qla2xxx code |
| 3888 | */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3889 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3890 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3891 | scsi_qla_host_t *vha = cmd->vha; |
| 3892 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 3893 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3894 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3895 | struct atio_from_isp *atio = &cmd->atio; |
| 3896 | unsigned char *cdb; |
| 3897 | unsigned long flags; |
| 3898 | uint32_t data_length; |
| 3899 | int ret, fcp_task_attr, data_dir, bidi = 0; |
| 3900 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3901 | cmd->cmd_in_wq = 0; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3902 | cmd->trc_flags |= TRC_DO_WORK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3903 | if (tgt->tgt_stop) |
| 3904 | goto out_term; |
| 3905 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3906 | if (cmd->aborted) { |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 3907 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082, |
| 3908 | "cmd with tag %u is aborted\n", |
| 3909 | cmd->atio.u.isp24.exchange_addr); |
| 3910 | goto out_term; |
| 3911 | } |
| 3912 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3913 | spin_lock_init(&cmd->cmd_lock); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3914 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 3915 | cmd->se_cmd.tag = atio->u.isp24.exchange_addr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3916 | cmd->unpacked_lun = scsilun_to_int( |
| 3917 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); |
| 3918 | |
| 3919 | if (atio->u.isp24.fcp_cmnd.rddata && |
| 3920 | atio->u.isp24.fcp_cmnd.wrdata) { |
| 3921 | bidi = 1; |
| 3922 | data_dir = DMA_TO_DEVICE; |
| 3923 | } else if (atio->u.isp24.fcp_cmnd.rddata) |
| 3924 | data_dir = DMA_FROM_DEVICE; |
| 3925 | else if (atio->u.isp24.fcp_cmnd.wrdata) |
| 3926 | data_dir = DMA_TO_DEVICE; |
| 3927 | else |
| 3928 | data_dir = DMA_NONE; |
| 3929 | |
| 3930 | fcp_task_attr = qlt_get_fcp_task_attr(vha, |
| 3931 | atio->u.isp24.fcp_cmnd.task_attr); |
| 3932 | data_length = be32_to_cpu(get_unaligned((uint32_t *) |
| 3933 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 3934 | atio->u.isp24.fcp_cmnd.add_cdb_len])); |
| 3935 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3936 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
| 3937 | fcp_task_attr, data_dir, bidi); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3938 | if (ret != 0) |
| 3939 | goto out_term; |
| 3940 | /* |
| 3941 | * Drop extra session reference from qla_tgt_handle_cmd_for_atio*( |
| 3942 | */ |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3943 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3944 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3945 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3946 | return; |
| 3947 | |
| 3948 | out_term: |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3949 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3950 | /* |
Roland Dreier | fae9eaf | 2012-06-11 18:23:16 -0700 | [diff] [blame] | 3951 | * cmd has not sent to target yet, so pass NULL as the second |
| 3952 | * argument to qlt_send_term_exchange() and free the memory here. |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3953 | */ |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3954 | cmd->trc_flags |= TRC_DO_WORK_ERR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3955 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3956 | qlt_send_term_exchange(vha, NULL, &cmd->atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3957 | |
| 3958 | qlt_decr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3959 | 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] | 3960 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3961 | |
| 3962 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3963 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3964 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3965 | } |
| 3966 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3967 | static void qlt_do_work(struct work_struct *work) |
| 3968 | { |
| 3969 | 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] | 3970 | scsi_qla_host_t *vha = cmd->vha; |
| 3971 | unsigned long flags; |
| 3972 | |
| 3973 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 3974 | list_del(&cmd->cmd_list); |
| 3975 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3976 | |
| 3977 | __qlt_do_work(cmd); |
| 3978 | } |
| 3979 | |
| 3980 | 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] | 3981 | struct fc_port *sess, |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3982 | struct atio_from_isp *atio) |
| 3983 | { |
| 3984 | struct se_session *se_sess = sess->se_sess; |
| 3985 | struct qla_tgt_cmd *cmd; |
| 3986 | int tag; |
| 3987 | |
| 3988 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 3989 | if (tag < 0) |
| 3990 | return NULL; |
| 3991 | |
| 3992 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 3993 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 3994 | |
| 3995 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 3996 | cmd->state = QLA_TGT_STATE_NEW; |
| 3997 | cmd->tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3998 | qlt_incr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3999 | cmd->vha = vha; |
| 4000 | cmd->se_cmd.map_tag = tag; |
| 4001 | cmd->sess = sess; |
| 4002 | cmd->loop_id = sess->loop_id; |
| 4003 | cmd->conf_compl_supported = sess->conf_compl_supported; |
| 4004 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4005 | cmd->trc_flags = 0; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4006 | cmd->jiffies_at_alloc = get_jiffies_64(); |
| 4007 | |
| 4008 | cmd->reset_count = vha->hw->chip_reset; |
| 4009 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4010 | return cmd; |
| 4011 | } |
| 4012 | |
| 4013 | static void qlt_send_busy(struct scsi_qla_host *, struct atio_from_isp *, |
| 4014 | uint16_t); |
| 4015 | |
| 4016 | static void qlt_create_sess_from_atio(struct work_struct *work) |
| 4017 | { |
| 4018 | struct qla_tgt_sess_op *op = container_of(work, |
| 4019 | struct qla_tgt_sess_op, work); |
| 4020 | scsi_qla_host_t *vha = op->vha; |
| 4021 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4022 | struct fc_port *sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4023 | struct qla_tgt_cmd *cmd; |
| 4024 | unsigned long flags; |
| 4025 | uint8_t *s_id = op->atio.u.isp24.fcp_hdr.s_id; |
| 4026 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4027 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4028 | list_del(&op->cmd_list); |
| 4029 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 4030 | |
| 4031 | if (op->aborted) { |
| 4032 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf083, |
| 4033 | "sess_op with tag %u is aborted\n", |
| 4034 | op->atio.u.isp24.exchange_addr); |
| 4035 | goto out_term; |
| 4036 | } |
| 4037 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4038 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf022, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4039 | "qla_target(%d): Unable to find wwn login" |
| 4040 | " (s_id %x:%x:%x), trying to create it manually\n", |
| 4041 | vha->vp_idx, s_id[0], s_id[1], s_id[2]); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4042 | |
| 4043 | if (op->atio.u.raw.entry_count > 1) { |
| 4044 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf023, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4045 | "Dropping multy entry atio %p\n", &op->atio); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4046 | goto out_term; |
| 4047 | } |
| 4048 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4049 | sess = qlt_make_local_sess(vha, s_id); |
| 4050 | /* sess has an extra creation ref. */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4051 | |
| 4052 | if (!sess) |
| 4053 | goto out_term; |
| 4054 | /* |
| 4055 | * Now obtain a pre-allocated session tag using the original op->atio |
| 4056 | * packet header, and dispatch into __qlt_do_work() using the existing |
| 4057 | * process context. |
| 4058 | */ |
| 4059 | cmd = qlt_get_tag(vha, sess, &op->atio); |
| 4060 | if (!cmd) { |
| 4061 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4062 | qlt_send_busy(vha, &op->atio, SAM_STAT_BUSY); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4063 | ha->tgt.tgt_ops->put_sess(sess); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4064 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4065 | kfree(op); |
| 4066 | return; |
| 4067 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4068 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4069 | /* |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 4070 | * __qlt_do_work() will call qlt_put_sess() to release |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4071 | * the extra reference taken above by qlt_make_local_sess() |
| 4072 | */ |
| 4073 | __qlt_do_work(cmd); |
| 4074 | kfree(op); |
| 4075 | return; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4076 | out_term: |
| 4077 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4078 | qlt_send_term_exchange(vha, NULL, &op->atio, 1, 0); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4079 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4080 | kfree(op); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4081 | } |
| 4082 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4083 | /* ha->hardware_lock supposed to be held on entry */ |
| 4084 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, |
| 4085 | struct atio_from_isp *atio) |
| 4086 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4087 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4088 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4089 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4090 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4091 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4092 | |
| 4093 | if (unlikely(tgt->tgt_stop)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4094 | ql_dbg(ql_dbg_io, vha, 0x3061, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4095 | "New command while device %p is shutting down\n", tgt); |
| 4096 | return -EFAULT; |
| 4097 | } |
| 4098 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4099 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id); |
| 4100 | if (unlikely(!sess)) { |
| 4101 | struct qla_tgt_sess_op *op = kzalloc(sizeof(struct qla_tgt_sess_op), |
| 4102 | GFP_ATOMIC); |
| 4103 | if (!op) |
| 4104 | return -ENOMEM; |
| 4105 | |
| 4106 | memcpy(&op->atio, atio, sizeof(*atio)); |
Himanshu Madhani | 78c2106 | 2014-09-25 06:14:44 -0400 | [diff] [blame] | 4107 | op->vha = vha; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4108 | |
| 4109 | spin_lock(&vha->cmd_list_lock); |
| 4110 | list_add_tail(&op->cmd_list, &vha->qla_sess_op_cmd_list); |
| 4111 | spin_unlock(&vha->cmd_list_lock); |
| 4112 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4113 | INIT_WORK(&op->work, qlt_create_sess_from_atio); |
| 4114 | queue_work(qla_tgt_wq, &op->work); |
| 4115 | return 0; |
| 4116 | } |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4117 | |
| 4118 | /* Another WWN used to have our s_id. Our PLOGI scheduled its |
| 4119 | * session deletion, but it's still in sess_del_work wq */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4120 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4121 | ql_dbg(ql_dbg_io, vha, 0x3061, |
| 4122 | "New command while old session %p is being deleted\n", |
| 4123 | sess); |
| 4124 | return -EFAULT; |
| 4125 | } |
| 4126 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4127 | /* |
| 4128 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. |
| 4129 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4130 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 4131 | ql_dbg(ql_dbg_tgt, vha, 0xffff, |
| 4132 | "%s: kref_get fail, %8phC oxid %x \n", |
| 4133 | __func__, sess->port_name, |
| 4134 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 4135 | return -EFAULT; |
| 4136 | } |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4137 | |
| 4138 | cmd = qlt_get_tag(vha, sess, atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4139 | if (!cmd) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4140 | ql_dbg(ql_dbg_io, vha, 0x3062, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4141 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4142 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4143 | ha->tgt.tgt_ops->put_sess(sess); |
| 4144 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4145 | return -ENOMEM; |
| 4146 | } |
| 4147 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4148 | cmd->cmd_in_wq = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4149 | cmd->trc_flags |= TRC_NEW_CMD; |
Quinn Tran | 5327c7d | 2016-02-10 18:59:14 -0500 | [diff] [blame] | 4150 | cmd->se_cmd.cpuid = ha->msix_count ? |
| 4151 | ha->tgt.rspq_vector_cpuid : WORK_CPU_UNBOUND; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4152 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4153 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4154 | list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4155 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4156 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4157 | INIT_WORK(&cmd->work, qlt_do_work); |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4158 | if (ha->msix_count) { |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4159 | if (cmd->atio.u.isp24.fcp_cmnd.rddata) |
| 4160 | queue_work_on(smp_processor_id(), qla_tgt_wq, |
| 4161 | &cmd->work); |
| 4162 | else |
| 4163 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, |
| 4164 | &cmd->work); |
| 4165 | } else { |
| 4166 | queue_work(qla_tgt_wq, &cmd->work); |
| 4167 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4168 | return 0; |
| 4169 | |
| 4170 | } |
| 4171 | |
| 4172 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4173 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4174 | int fn, void *iocb, int flags) |
| 4175 | { |
| 4176 | struct scsi_qla_host *vha = sess->vha; |
| 4177 | struct qla_hw_data *ha = vha->hw; |
| 4178 | struct qla_tgt_mgmt_cmd *mcmd; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4179 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4180 | int res; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4181 | |
| 4182 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4183 | if (!mcmd) { |
| 4184 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, |
| 4185 | "qla_target(%d): Allocation of management " |
| 4186 | "command failed, some commands and their data could " |
| 4187 | "leak\n", vha->vp_idx); |
| 4188 | return -ENOMEM; |
| 4189 | } |
| 4190 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4191 | mcmd->sess = sess; |
| 4192 | |
| 4193 | if (iocb) { |
| 4194 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4195 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4196 | } |
| 4197 | mcmd->tmr_func = fn; |
| 4198 | mcmd->flags = flags; |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 4199 | mcmd->reset_count = vha->hw->chip_reset; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4200 | |
| 4201 | switch (fn) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4202 | case QLA_TGT_LUN_RESET: |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4203 | abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id); |
| 4204 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4205 | } |
| 4206 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4207 | 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] | 4208 | if (res != 0) { |
| 4209 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000b, |
| 4210 | "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n", |
| 4211 | sess->vha->vp_idx, res); |
| 4212 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4213 | return -EFAULT; |
| 4214 | } |
| 4215 | |
| 4216 | return 0; |
| 4217 | } |
| 4218 | |
| 4219 | /* ha->hardware_lock supposed to be held on entry */ |
| 4220 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) |
| 4221 | { |
| 4222 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4223 | struct qla_hw_data *ha = vha->hw; |
| 4224 | struct qla_tgt *tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4225 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4226 | uint32_t lun, unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4227 | int fn; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4228 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4229 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4230 | tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4231 | |
| 4232 | lun = a->u.isp24.fcp_cmnd.lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4233 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4234 | |
| 4235 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4236 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4237 | a->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4238 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4239 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4240 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); |
| 4241 | |
| 4242 | if (!sess) { |
| 4243 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf024, |
| 4244 | "qla_target(%d): task mgmt fn 0x%x for " |
| 4245 | "non-existant session\n", vha->vp_idx, fn); |
| 4246 | return qlt_sched_sess_work(tgt, QLA_TGT_SESS_WORK_TM, iocb, |
| 4247 | sizeof(struct atio_from_isp)); |
| 4248 | } |
| 4249 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4250 | if (sess->deleted) |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4251 | return -EFAULT; |
| 4252 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4253 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 4254 | } |
| 4255 | |
| 4256 | /* ha->hardware_lock supposed to be held on entry */ |
| 4257 | static int __qlt_abort_task(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4258 | struct imm_ntfy_from_isp *iocb, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4259 | { |
| 4260 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4261 | struct qla_hw_data *ha = vha->hw; |
| 4262 | struct qla_tgt_mgmt_cmd *mcmd; |
| 4263 | uint32_t lun, unpacked_lun; |
| 4264 | int rc; |
| 4265 | |
| 4266 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4267 | if (mcmd == NULL) { |
| 4268 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, |
| 4269 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", |
| 4270 | vha->vp_idx, __func__); |
| 4271 | return -ENOMEM; |
| 4272 | } |
| 4273 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4274 | |
| 4275 | mcmd->sess = sess; |
| 4276 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4277 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4278 | |
| 4279 | lun = a->u.isp24.fcp_cmnd.lun; |
| 4280 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); |
Arun Easi | 80187f8 | 2014-09-25 06:14:53 -0400 | [diff] [blame] | 4281 | mcmd->reset_count = vha->hw->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4282 | mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4283 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4284 | 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] | 4285 | le16_to_cpu(iocb->u.isp2x.seq_id)); |
| 4286 | if (rc != 0) { |
| 4287 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, |
| 4288 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 4289 | vha->vp_idx, rc); |
| 4290 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4291 | return -EFAULT; |
| 4292 | } |
| 4293 | |
| 4294 | return 0; |
| 4295 | } |
| 4296 | |
| 4297 | /* ha->hardware_lock supposed to be held on entry */ |
| 4298 | static int qlt_abort_task(struct scsi_qla_host *vha, |
| 4299 | struct imm_ntfy_from_isp *iocb) |
| 4300 | { |
| 4301 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4302 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4303 | int loop_id; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4304 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4305 | |
| 4306 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); |
| 4307 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4308 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4309 | 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] | 4310 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4311 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4312 | if (sess == NULL) { |
| 4313 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, |
| 4314 | "qla_target(%d): task abort for unexisting " |
| 4315 | "session\n", vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4316 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4317 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
| 4318 | } |
| 4319 | |
| 4320 | return __qlt_abort_task(vha, iocb, sess); |
| 4321 | } |
| 4322 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4323 | void qlt_logo_completion_handler(fc_port_t *fcport, int rc) |
| 4324 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4325 | if (rc != MBS_COMMAND_COMPLETE) { |
| 4326 | ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093, |
| 4327 | "%s: se_sess %p / sess %p from" |
| 4328 | " port %8phC loop_id %#04x s_id %02x:%02x:%02x" |
| 4329 | " LOGO failed: %#x\n", |
| 4330 | __func__, |
| 4331 | fcport->se_sess, |
| 4332 | fcport, |
| 4333 | fcport->port_name, fcport->loop_id, |
| 4334 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4335 | fcport->d_id.b.al_pa, rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4336 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4337 | |
| 4338 | fcport->logout_completed = 1; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4339 | } |
| 4340 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4341 | /* |
| 4342 | * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) |
| 4343 | * |
| 4344 | * Schedules sessions with matching port_id/loop_id but different wwn for |
| 4345 | * deletion. Returns existing session with matching wwn if present. |
| 4346 | * Null otherwise. |
| 4347 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4348 | struct fc_port * |
| 4349 | 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] | 4350 | 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] | 4351 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4352 | struct fc_port *sess = NULL, *other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4353 | uint64_t other_wwn; |
| 4354 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4355 | *conflict_sess = NULL; |
| 4356 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4357 | list_for_each_entry(other_sess, &vha->vp_fcports, list) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4358 | |
| 4359 | other_wwn = wwn_to_u64(other_sess->port_name); |
| 4360 | |
| 4361 | if (wwn == other_wwn) { |
| 4362 | WARN_ON(sess); |
| 4363 | sess = other_sess; |
| 4364 | continue; |
| 4365 | } |
| 4366 | |
| 4367 | /* find other sess with nport_id collision */ |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4368 | if (port_id.b24 == other_sess->d_id.b24) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4369 | if (loop_id != other_sess->loop_id) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4370 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000c, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4371 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4372 | other_sess, other_sess->loop_id, other_wwn); |
| 4373 | |
| 4374 | /* |
| 4375 | * logout_on_delete is set by default, but another |
| 4376 | * session that has the same s_id/loop_id combo |
| 4377 | * might have cleared it when requested this session |
| 4378 | * deletion, so don't touch it |
| 4379 | */ |
| 4380 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4381 | } else { |
| 4382 | /* |
| 4383 | * Another wwn used to have our s_id/loop_id |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4384 | * kill the session, but don't free the loop_id |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4385 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4386 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xffff, |
| 4387 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4388 | other_sess, other_sess->loop_id, other_wwn); |
| 4389 | |
| 4390 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4391 | other_sess->keep_nport_handle = 1; |
| 4392 | *conflict_sess = other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4393 | qlt_schedule_sess_for_deletion(other_sess, |
| 4394 | true); |
| 4395 | } |
| 4396 | continue; |
| 4397 | } |
| 4398 | |
| 4399 | /* find other sess with nport handle collision */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4400 | if ((loop_id == other_sess->loop_id) && |
| 4401 | (loop_id != FC_NO_LOOP_ID)) { |
| 4402 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000d, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4403 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4404 | other_sess, other_sess->loop_id, other_wwn); |
| 4405 | |
| 4406 | /* Same loop_id but different s_id |
| 4407 | * Ok to kill and logout */ |
| 4408 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | return sess; |
| 4413 | } |
| 4414 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4415 | /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */ |
| 4416 | static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id) |
| 4417 | { |
| 4418 | struct qla_tgt_sess_op *op; |
| 4419 | struct qla_tgt_cmd *cmd; |
| 4420 | uint32_t key; |
| 4421 | int count = 0; |
| 4422 | |
| 4423 | key = (((u32)s_id->b.domain << 16) | |
| 4424 | ((u32)s_id->b.area << 8) | |
| 4425 | ((u32)s_id->b.al_pa)); |
| 4426 | |
| 4427 | spin_lock(&vha->cmd_list_lock); |
| 4428 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 4429 | 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] | 4430 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4431 | if (op_key == key) { |
| 4432 | op->aborted = true; |
| 4433 | count++; |
| 4434 | } |
| 4435 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4436 | |
| 4437 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 4438 | uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 4439 | if (op_key == key) { |
| 4440 | op->aborted = true; |
| 4441 | count++; |
| 4442 | } |
| 4443 | } |
| 4444 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4445 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 4446 | uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 4447 | if (cmd_key == key) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4448 | cmd->aborted = 1; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4449 | count++; |
| 4450 | } |
| 4451 | } |
| 4452 | spin_unlock(&vha->cmd_list_lock); |
| 4453 | |
| 4454 | return count; |
| 4455 | } |
| 4456 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4457 | /* |
| 4458 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4459 | */ |
| 4460 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, |
| 4461 | struct imm_ntfy_from_isp *iocb) |
| 4462 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4463 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4464 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4465 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4466 | uint64_t wwn; |
| 4467 | port_id_t port_id; |
| 4468 | uint16_t loop_id; |
| 4469 | uint16_t wd3_lo; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4470 | int res = 0; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4471 | struct qlt_plogi_ack_t *pla; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4472 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4473 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4474 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4475 | |
| 4476 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4477 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4478 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4479 | port_id.b.rsvd_1 = 0; |
| 4480 | |
| 4481 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4482 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4483 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 4484 | "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n", |
| 4485 | vha->vp_idx, iocb->u.isp24.port_id[2], |
| 4486 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 4487 | iocb->u.isp24.status_subcode, loop_id, |
| 4488 | iocb->u.isp24.port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4489 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4490 | /* res = 1 means ack at the end of thread |
| 4491 | * res = 0 means ack async/later. |
| 4492 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4493 | switch (iocb->u.isp24.status_subcode) { |
| 4494 | case ELS_PLOGI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4495 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4496 | /* Mark all stale commands in qla_tgt_wq for deletion */ |
| 4497 | abort_cmds_for_s_id(vha, &port_id); |
| 4498 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4499 | if (wwn) { |
| 4500 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4501 | sess = qlt_find_sess_invalidate_other(vha, wwn, |
| 4502 | port_id, loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4503 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4504 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4505 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4506 | if (IS_SW_RESV_ADDR(port_id)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4507 | res = 1; |
| 4508 | break; |
| 4509 | } |
| 4510 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4511 | pla = qlt_plogi_ack_find_add(vha, &port_id, iocb); |
| 4512 | if (!pla) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4513 | qlt_send_term_imm_notif(vha, iocb, 1); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4514 | break; |
| 4515 | } |
| 4516 | |
| 4517 | res = 0; |
| 4518 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4519 | if (conflict_sess) { |
| 4520 | conflict_sess->login_gen++; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4521 | qlt_plogi_ack_link(vha, pla, conflict_sess, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4522 | QLT_PLOGI_LINK_CONFLICT); |
| 4523 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4524 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4525 | if (!sess) { |
| 4526 | pla->ref_count++; |
| 4527 | qla24xx_post_newsess_work(vha, &port_id, |
| 4528 | iocb->u.isp24.port_name, pla); |
| 4529 | res = 0; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4530 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4531 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4532 | |
| 4533 | qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4534 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
| 4535 | sess->d_id = port_id; |
| 4536 | sess->login_gen++; |
| 4537 | |
| 4538 | switch (sess->disc_state) { |
| 4539 | case DSC_DELETED: |
| 4540 | qlt_plogi_ack_unref(vha, pla); |
| 4541 | break; |
| 4542 | |
| 4543 | default: |
| 4544 | /* |
| 4545 | * Under normal circumstances we want to release nport handle |
| 4546 | * during LOGO process to avoid nport handle leaks inside FW. |
| 4547 | * The exception is when LOGO is done while another PLOGI with |
| 4548 | * the same nport handle is waiting as might be the case here. |
| 4549 | * Note: there is always a possibily of a race where session |
| 4550 | * deletion has already started for other reasons (e.g. ACL |
| 4551 | * removal) and now PLOGI arrives: |
| 4552 | * 1. if PLOGI arrived in FW after nport handle has been freed, |
| 4553 | * FW must have assigned this PLOGI a new/same handle and we |
| 4554 | * can proceed ACK'ing it as usual when session deletion |
| 4555 | * completes. |
| 4556 | * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT |
| 4557 | * bit reached it, the handle has now been released. We'll |
| 4558 | * get an error when we ACK this PLOGI. Nothing will be sent |
| 4559 | * back to initiator. Initiator should eventually retry |
| 4560 | * PLOGI and situation will correct itself. |
| 4561 | */ |
| 4562 | sess->keep_nport_handle = ((sess->loop_id == loop_id) && |
| 4563 | (sess->d_id.b24 == port_id.b24)); |
| 4564 | |
| 4565 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4566 | "%s %d %8phC post del sess\n", |
| 4567 | __func__, __LINE__, sess->port_name); |
| 4568 | |
| 4569 | |
| 4570 | qlt_schedule_sess_for_deletion_lock(sess); |
| 4571 | break; |
| 4572 | } |
| 4573 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4574 | break; |
| 4575 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4576 | case ELS_PRLI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4577 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4578 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4579 | if (wwn) { |
| 4580 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4581 | sess = qlt_find_sess_invalidate_other(vha, wwn, port_id, |
| 4582 | loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4583 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4584 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4585 | |
| 4586 | if (conflict_sess) { |
| 4587 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b, |
| 4588 | "PRLI with conflicting sess %p port %8phC\n", |
| 4589 | conflict_sess, conflict_sess->port_name); |
| 4590 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4591 | res = 0; |
| 4592 | break; |
| 4593 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4594 | |
| 4595 | if (sess != NULL) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4596 | if (sess->fw_login_state == DSC_LS_PLOGI_PEND) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4597 | /* |
| 4598 | * Impatient initiator sent PRLI before last |
| 4599 | * PLOGI could finish. Will force him to re-try, |
| 4600 | * while last one finishes. |
| 4601 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4602 | ql_log(ql_log_warn, sess->vha, 0xf095, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4603 | "sess %p PRLI received, before plogi ack.\n", |
| 4604 | sess); |
| 4605 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4606 | res = 0; |
| 4607 | break; |
| 4608 | } |
| 4609 | |
| 4610 | /* |
| 4611 | * This shouldn't happen under normal circumstances, |
| 4612 | * since we have deleted the old session during PLOGI |
| 4613 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4614 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4615 | "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n", |
| 4616 | sess->loop_id, sess, iocb->u.isp24.nport_handle); |
| 4617 | |
| 4618 | sess->local = 0; |
| 4619 | sess->loop_id = loop_id; |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4620 | sess->d_id = port_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4621 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4622 | |
| 4623 | if (wd3_lo & BIT_7) |
| 4624 | sess->conf_compl_supported = 1; |
| 4625 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4626 | if ((wd3_lo & BIT_4) == 0) |
| 4627 | sess->port_type = FCT_INITIATOR; |
| 4628 | else |
| 4629 | sess->port_type = FCT_TARGET; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4630 | } |
| 4631 | res = 1; /* send notify ack */ |
| 4632 | |
| 4633 | /* Make session global (not used in fabric mode) */ |
| 4634 | if (ha->current_topology != ISP_CFG_F) { |
| 4635 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4636 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4637 | qla2xxx_wake_dpc(vha); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4638 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4639 | if (sess) { |
| 4640 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4641 | "%s %d %8phC post nack\n", |
| 4642 | __func__, __LINE__, sess->port_name); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4643 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4644 | qla24xx_post_nack_work(vha, sess, iocb, |
| 4645 | SRB_NACK_PRLI); |
| 4646 | res = 0; |
| 4647 | } |
| 4648 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4649 | break; |
| 4650 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4651 | |
| 4652 | case ELS_TPRLO: |
| 4653 | if (le16_to_cpu(iocb->u.isp24.flags) & |
| 4654 | NOTIFY24XX_FLAGS_GLOBAL_TPRLO) { |
| 4655 | loop_id = 0xFFFF; |
| 4656 | qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS); |
| 4657 | res = 1; |
| 4658 | break; |
| 4659 | } |
| 4660 | /* drop through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4661 | case ELS_LOGO: |
| 4662 | case ELS_PRLO: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4663 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4664 | sess = qla2x00_find_fcport_by_loopid(vha, loop_id); |
| 4665 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4666 | |
| 4667 | if (sess) { |
| 4668 | sess->login_gen++; |
| 4669 | sess->fw_login_state = DSC_LS_LOGO_PEND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4670 | sess->logo_ack_needed = 1; |
| 4671 | memcpy(sess->iocb, iocb, IOCB_SIZE); |
| 4672 | } |
| 4673 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4674 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4675 | |
| 4676 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4677 | "%s: logo %llx res %d sess %p ", |
| 4678 | __func__, wwn, res, sess); |
| 4679 | if (res == 0) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4680 | /* |
| 4681 | * cmd went upper layer, look for qlt_xmit_tm_rsp() |
| 4682 | * for LOGO_ACK & sess delete |
| 4683 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4684 | BUG_ON(!sess); |
| 4685 | res = 0; |
| 4686 | } else { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4687 | /* cmd did not go to upper layer. */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4688 | if (sess) { |
| 4689 | qlt_schedule_sess_for_deletion_lock(sess); |
| 4690 | res = 0; |
| 4691 | } |
| 4692 | /* else logo will be ack */ |
| 4693 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4694 | break; |
| 4695 | case ELS_PDISC: |
| 4696 | case ELS_ADISC: |
| 4697 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4698 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4699 | if (tgt->link_reinit_iocb_pending) { |
| 4700 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, |
| 4701 | 0, 0, 0, 0, 0, 0); |
| 4702 | tgt->link_reinit_iocb_pending = 0; |
| 4703 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4704 | |
| 4705 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 4706 | iocb->u.isp24.port_name, 1); |
| 4707 | if (sess) { |
| 4708 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4709 | "sess %p lid %d|%d DS %d LS %d\n", |
| 4710 | sess, sess->loop_id, loop_id, |
| 4711 | sess->disc_state, sess->fw_login_state); |
| 4712 | } |
| 4713 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4714 | res = 1; /* send notify ack */ |
| 4715 | break; |
| 4716 | } |
| 4717 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4718 | case ELS_FLOGI: /* should never happen */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4719 | default: |
| 4720 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, |
| 4721 | "qla_target(%d): Unsupported ELS command %x " |
| 4722 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); |
| 4723 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 4724 | break; |
| 4725 | } |
| 4726 | |
| 4727 | return res; |
| 4728 | } |
| 4729 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4730 | /* |
| 4731 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4732 | */ |
| 4733 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, |
| 4734 | struct imm_ntfy_from_isp *iocb) |
| 4735 | { |
| 4736 | struct qla_hw_data *ha = vha->hw; |
| 4737 | uint32_t add_flags = 0; |
| 4738 | int send_notify_ack = 1; |
| 4739 | uint16_t status; |
| 4740 | |
| 4741 | status = le16_to_cpu(iocb->u.isp2x.status); |
| 4742 | switch (status) { |
| 4743 | case IMM_NTFY_LIP_RESET: |
| 4744 | { |
| 4745 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, |
| 4746 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", |
| 4747 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4748 | iocb->u.isp24.status_subcode); |
| 4749 | |
| 4750 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 4751 | send_notify_ack = 0; |
| 4752 | break; |
| 4753 | } |
| 4754 | |
| 4755 | case IMM_NTFY_LIP_LINK_REINIT: |
| 4756 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4757 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4758 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
| 4759 | "qla_target(%d): LINK REINIT (loop %#x, " |
| 4760 | "subcode %x)\n", vha->vp_idx, |
| 4761 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4762 | iocb->u.isp24.status_subcode); |
| 4763 | if (tgt->link_reinit_iocb_pending) { |
| 4764 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, |
| 4765 | 0, 0, 0, 0, 0, 0); |
| 4766 | } |
| 4767 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); |
| 4768 | tgt->link_reinit_iocb_pending = 1; |
| 4769 | /* |
| 4770 | * QLogic requires to wait after LINK REINIT for possible |
| 4771 | * PDISC or ADISC ELS commands |
| 4772 | */ |
| 4773 | send_notify_ack = 0; |
| 4774 | break; |
| 4775 | } |
| 4776 | |
| 4777 | case IMM_NTFY_PORT_LOGOUT: |
| 4778 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, |
| 4779 | "qla_target(%d): Port logout (loop " |
| 4780 | "%#x, subcode %x)\n", vha->vp_idx, |
| 4781 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4782 | iocb->u.isp24.status_subcode); |
| 4783 | |
| 4784 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) |
| 4785 | send_notify_ack = 0; |
| 4786 | /* The sessions will be cleared in the callback, if needed */ |
| 4787 | break; |
| 4788 | |
| 4789 | case IMM_NTFY_GLBL_TPRLO: |
| 4790 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, |
| 4791 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); |
| 4792 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 4793 | send_notify_ack = 0; |
| 4794 | /* The sessions will be cleared in the callback, if needed */ |
| 4795 | break; |
| 4796 | |
| 4797 | case IMM_NTFY_PORT_CONFIG: |
| 4798 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, |
| 4799 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, |
| 4800 | status); |
| 4801 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 4802 | send_notify_ack = 0; |
| 4803 | /* The sessions will be cleared in the callback, if needed */ |
| 4804 | break; |
| 4805 | |
| 4806 | case IMM_NTFY_GLBL_LOGO: |
| 4807 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, |
| 4808 | "qla_target(%d): Link failure detected\n", |
| 4809 | vha->vp_idx); |
| 4810 | /* I_T nexus loss */ |
| 4811 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 4812 | send_notify_ack = 0; |
| 4813 | break; |
| 4814 | |
| 4815 | case IMM_NTFY_IOCB_OVERFLOW: |
| 4816 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, |
| 4817 | "qla_target(%d): Cannot provide requested " |
| 4818 | "capability (IOCB overflowed the immediate notify " |
| 4819 | "resource count)\n", vha->vp_idx); |
| 4820 | break; |
| 4821 | |
| 4822 | case IMM_NTFY_ABORT_TASK: |
| 4823 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, |
| 4824 | "qla_target(%d): Abort Task (S %08x I %#x -> " |
| 4825 | "L %#x)\n", vha->vp_idx, |
| 4826 | le16_to_cpu(iocb->u.isp2x.seq_id), |
| 4827 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), |
| 4828 | le16_to_cpu(iocb->u.isp2x.lun)); |
| 4829 | if (qlt_abort_task(vha, iocb) == 0) |
| 4830 | send_notify_ack = 0; |
| 4831 | break; |
| 4832 | |
| 4833 | case IMM_NTFY_RESOURCE: |
| 4834 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, |
| 4835 | "qla_target(%d): Out of resources, host %ld\n", |
| 4836 | vha->vp_idx, vha->host_no); |
| 4837 | break; |
| 4838 | |
| 4839 | case IMM_NTFY_MSG_RX: |
| 4840 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, |
| 4841 | "qla_target(%d): Immediate notify task %x\n", |
| 4842 | vha->vp_idx, iocb->u.isp2x.task_flags); |
| 4843 | if (qlt_handle_task_mgmt(vha, iocb) == 0) |
| 4844 | send_notify_ack = 0; |
| 4845 | break; |
| 4846 | |
| 4847 | case IMM_NTFY_ELS: |
| 4848 | if (qlt_24xx_handle_els(vha, iocb) == 0) |
| 4849 | send_notify_ack = 0; |
| 4850 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4851 | default: |
| 4852 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, |
| 4853 | "qla_target(%d): Received unknown immediate " |
| 4854 | "notify status %x\n", vha->vp_idx, status); |
| 4855 | break; |
| 4856 | } |
| 4857 | |
| 4858 | if (send_notify_ack) |
| 4859 | qlt_send_notify_ack(vha, iocb, add_flags, 0, 0, 0, 0, 0); |
| 4860 | } |
| 4861 | |
| 4862 | /* |
| 4863 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4864 | * This function sends busy to ISP 2xxx or 24xx. |
| 4865 | */ |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4866 | static int __qlt_send_busy(struct scsi_qla_host *vha, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4867 | struct atio_from_isp *atio, uint16_t status) |
| 4868 | { |
| 4869 | struct ctio7_to_24xx *ctio24; |
| 4870 | struct qla_hw_data *ha = vha->hw; |
| 4871 | request_t *pkt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4872 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4873 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4874 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4875 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4876 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4877 | atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4878 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4879 | if (!sess) { |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4880 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4881 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4882 | } |
| 4883 | /* Sending marker isn't necessary, since we called from ISR */ |
| 4884 | |
| 4885 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
| 4886 | if (!pkt) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4887 | ql_dbg(ql_dbg_io, vha, 0x3063, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4888 | "qla_target(%d): %s failed: unable to allocate " |
| 4889 | "request packet", vha->vp_idx, __func__); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4890 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4891 | } |
| 4892 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 4893 | vha->tgt_counters.num_q_full_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4894 | pkt->entry_count = 1; |
| 4895 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 4896 | |
| 4897 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 4898 | ctio24->entry_type = CTIO_TYPE7; |
| 4899 | ctio24->nport_handle = sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4900 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4901 | ctio24->vp_index = vha->vp_idx; |
| 4902 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 4903 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 4904 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 4905 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
| 4906 | ctio24->u.status1.flags = (atio->u.isp24.attr << 9) | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4907 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4908 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | |
| 4909 | CTIO7_FLAGS_DONT_RET_CTIO); |
| 4910 | /* |
| 4911 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, |
| 4912 | * if the explicit conformation is used. |
| 4913 | */ |
| 4914 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); |
| 4915 | ctio24->u.status1.scsi_status = cpu_to_le16(status); |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 4916 | /* Memory Barrier */ |
| 4917 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4918 | qla2x00_start_iocbs(vha, vha->req); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4919 | return 0; |
| 4920 | } |
| 4921 | |
| 4922 | /* |
| 4923 | * This routine is used to allocate a command for either a QFull condition |
| 4924 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go |
| 4925 | * out previously. |
| 4926 | */ |
| 4927 | static void |
| 4928 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 4929 | struct atio_from_isp *atio, uint16_t status, int qfull) |
| 4930 | { |
| 4931 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4932 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4933 | struct fc_port *sess; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4934 | struct se_session *se_sess; |
| 4935 | struct qla_tgt_cmd *cmd; |
| 4936 | int tag; |
| 4937 | |
| 4938 | if (unlikely(tgt->tgt_stop)) { |
| 4939 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 4940 | "New command while device %p is shutting down\n", tgt); |
| 4941 | return; |
| 4942 | } |
| 4943 | |
| 4944 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { |
| 4945 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 4946 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 4947 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 4948 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4949 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 4950 | |
| 4951 | ql_dbg(ql_dbg_io, vha, 0x3068, |
| 4952 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", |
| 4953 | vha->vp_idx, __func__, |
| 4954 | vha->hw->tgt.num_qfull_cmds_dropped); |
| 4955 | |
| 4956 | qlt_chk_exch_leak_thresh_hold(vha); |
| 4957 | return; |
| 4958 | } |
| 4959 | |
| 4960 | sess = ha->tgt.tgt_ops->find_sess_by_s_id |
| 4961 | (vha, atio->u.isp24.fcp_hdr.s_id); |
| 4962 | if (!sess) |
| 4963 | return; |
| 4964 | |
| 4965 | se_sess = sess->se_sess; |
| 4966 | |
| 4967 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 4968 | if (tag < 0) |
| 4969 | return; |
| 4970 | |
| 4971 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 4972 | if (!cmd) { |
| 4973 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 4974 | "qla_target(%d): %s: Allocation of cmd failed\n", |
| 4975 | vha->vp_idx, __func__); |
| 4976 | |
| 4977 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 4978 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 4979 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 4980 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4981 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 4982 | |
| 4983 | qlt_chk_exch_leak_thresh_hold(vha); |
| 4984 | return; |
| 4985 | } |
| 4986 | |
| 4987 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 4988 | |
| 4989 | qlt_incr_num_pend_cmds(vha); |
| 4990 | INIT_LIST_HEAD(&cmd->cmd_list); |
| 4991 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 4992 | |
| 4993 | cmd->tgt = vha->vha_tgt.qla_tgt; |
| 4994 | cmd->vha = vha; |
| 4995 | cmd->reset_count = vha->hw->chip_reset; |
| 4996 | cmd->q_full = 1; |
| 4997 | |
| 4998 | if (qfull) { |
| 4999 | cmd->q_full = 1; |
| 5000 | /* NOTE: borrowing the state field to carry the status */ |
| 5001 | cmd->state = status; |
| 5002 | } else |
| 5003 | cmd->term_exchg = 1; |
| 5004 | |
| 5005 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); |
| 5006 | |
| 5007 | vha->hw->tgt.num_qfull_cmds_alloc++; |
| 5008 | if (vha->hw->tgt.num_qfull_cmds_alloc > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5009 | vha->qla_stats.stat_max_qfull_cmds_alloc) |
| 5010 | vha->qla_stats.stat_max_qfull_cmds_alloc = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5011 | vha->hw->tgt.num_qfull_cmds_alloc; |
| 5012 | } |
| 5013 | |
| 5014 | int |
| 5015 | qlt_free_qfull_cmds(struct scsi_qla_host *vha) |
| 5016 | { |
| 5017 | struct qla_hw_data *ha = vha->hw; |
| 5018 | unsigned long flags; |
| 5019 | struct qla_tgt_cmd *cmd, *tcmd; |
| 5020 | struct list_head free_list; |
| 5021 | int rc = 0; |
| 5022 | |
| 5023 | if (list_empty(&ha->tgt.q_full_list)) |
| 5024 | return 0; |
| 5025 | |
| 5026 | INIT_LIST_HEAD(&free_list); |
| 5027 | |
| 5028 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 5029 | |
| 5030 | if (list_empty(&ha->tgt.q_full_list)) { |
| 5031 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 5032 | return 0; |
| 5033 | } |
| 5034 | |
| 5035 | list_for_each_entry_safe(cmd, tcmd, &ha->tgt.q_full_list, cmd_list) { |
| 5036 | if (cmd->q_full) |
| 5037 | /* cmd->state is a borrowed field to hold status */ |
| 5038 | rc = __qlt_send_busy(vha, &cmd->atio, cmd->state); |
| 5039 | else if (cmd->term_exchg) |
| 5040 | rc = __qlt_send_term_exchange(vha, NULL, &cmd->atio); |
| 5041 | |
| 5042 | if (rc == -ENOMEM) |
| 5043 | break; |
| 5044 | |
| 5045 | if (cmd->q_full) |
| 5046 | ql_dbg(ql_dbg_io, vha, 0x3006, |
| 5047 | "%s: busy sent for ox_id[%04x]\n", __func__, |
| 5048 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5049 | else if (cmd->term_exchg) |
| 5050 | ql_dbg(ql_dbg_io, vha, 0x3007, |
| 5051 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, |
| 5052 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5053 | else |
| 5054 | ql_dbg(ql_dbg_io, vha, 0x3008, |
| 5055 | "%s: Unexpected cmd in QFull list %p\n", __func__, |
| 5056 | cmd); |
| 5057 | |
| 5058 | list_del(&cmd->cmd_list); |
| 5059 | list_add_tail(&cmd->cmd_list, &free_list); |
| 5060 | |
| 5061 | /* piggy back on hardware_lock for protection */ |
| 5062 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 5063 | } |
| 5064 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 5065 | |
| 5066 | cmd = NULL; |
| 5067 | |
| 5068 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 5069 | list_del(&cmd->cmd_list); |
| 5070 | /* This cmd was never sent to TCM. There is no need |
| 5071 | * to schedule free or call free_cmd |
| 5072 | */ |
| 5073 | qlt_free_cmd(cmd); |
| 5074 | } |
| 5075 | return rc; |
| 5076 | } |
| 5077 | |
| 5078 | static void |
| 5079 | qlt_send_busy(struct scsi_qla_host *vha, |
| 5080 | struct atio_from_isp *atio, uint16_t status) |
| 5081 | { |
| 5082 | int rc = 0; |
| 5083 | |
| 5084 | rc = __qlt_send_busy(vha, atio, status); |
| 5085 | if (rc == -ENOMEM) |
| 5086 | qlt_alloc_qfull_cmd(vha, atio, status, 1); |
| 5087 | } |
| 5088 | |
| 5089 | static int |
| 5090 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5091 | struct atio_from_isp *atio, bool ha_locked) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5092 | { |
| 5093 | struct qla_hw_data *ha = vha->hw; |
| 5094 | uint16_t status; |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5095 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5096 | |
| 5097 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) |
| 5098 | return 0; |
| 5099 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5100 | if (!ha_locked) |
| 5101 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5102 | status = temp_sam_status; |
| 5103 | qlt_send_busy(vha, atio, status); |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5104 | if (!ha_locked) |
| 5105 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5106 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5107 | return 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5108 | } |
| 5109 | |
| 5110 | /* ha->hardware_lock supposed to be held on entry */ |
| 5111 | /* called via callback from qla2xxx */ |
| 5112 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5113 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5114 | { |
| 5115 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5116 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5117 | int rc; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5118 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5119 | |
| 5120 | if (unlikely(tgt == NULL)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5121 | ql_dbg(ql_dbg_io, vha, 0x3064, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5122 | "ATIO pkt, but no tgt (ha %p)", ha); |
| 5123 | return; |
| 5124 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5125 | /* |
| 5126 | * In tgt_stop mode we also should allow all requests to pass. |
| 5127 | * Otherwise, some commands can stuck. |
| 5128 | */ |
| 5129 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5130 | tgt->atio_irq_cmd_count++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5131 | |
| 5132 | switch (atio->u.raw.entry_type) { |
| 5133 | case ATIO_TYPE7: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5134 | if (unlikely(atio->u.isp24.exchange_addr == |
| 5135 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5136 | ql_dbg(ql_dbg_io, vha, 0x3065, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5137 | "qla_target(%d): ATIO_TYPE7 " |
| 5138 | "received with UNKNOWN exchange address, " |
| 5139 | "sending QUEUE_FULL\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5140 | if (!ha_locked) |
| 5141 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5142 | qlt_send_busy(vha, atio, SAM_STAT_TASK_SET_FULL); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5143 | if (!ha_locked) |
| 5144 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5145 | break; |
| 5146 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5147 | |
| 5148 | |
| 5149 | |
| 5150 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5151 | rc = qlt_chk_qfull_thresh_hold(vha, atio, ha_locked); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5152 | if (rc != 0) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5153 | tgt->atio_irq_cmd_count--; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5154 | return; |
| 5155 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5156 | rc = qlt_handle_cmd_for_atio(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5157 | } else { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5158 | rc = qlt_handle_task_mgmt(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5159 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5160 | if (unlikely(rc != 0)) { |
| 5161 | if (rc == -ESRCH) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5162 | if (!ha_locked) |
| 5163 | spin_lock_irqsave |
| 5164 | (&ha->hardware_lock, flags); |
| 5165 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5166 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
| 5167 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); |
| 5168 | #else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5169 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5170 | #endif |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5171 | |
| 5172 | if (!ha_locked) |
| 5173 | spin_unlock_irqrestore |
| 5174 | (&ha->hardware_lock, flags); |
| 5175 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5176 | } else { |
| 5177 | if (tgt->tgt_stop) { |
| 5178 | ql_dbg(ql_dbg_tgt, vha, 0xe059, |
| 5179 | "qla_target: Unable to send " |
| 5180 | "command to target for req, " |
| 5181 | "ignoring.\n"); |
| 5182 | } else { |
| 5183 | ql_dbg(ql_dbg_tgt, vha, 0xe05a, |
| 5184 | "qla_target(%d): Unable to send " |
| 5185 | "command to target, sending BUSY " |
| 5186 | "status.\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5187 | if (!ha_locked) |
| 5188 | spin_lock_irqsave( |
| 5189 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5190 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5191 | if (!ha_locked) |
| 5192 | spin_unlock_irqrestore( |
| 5193 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5194 | } |
| 5195 | } |
| 5196 | } |
| 5197 | break; |
| 5198 | |
| 5199 | case IMMED_NOTIFY_TYPE: |
| 5200 | { |
| 5201 | if (unlikely(atio->u.isp2x.entry_status != 0)) { |
| 5202 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, |
| 5203 | "qla_target(%d): Received ATIO packet %x " |
| 5204 | "with error status %x\n", vha->vp_idx, |
| 5205 | atio->u.raw.entry_type, |
| 5206 | atio->u.isp2x.entry_status); |
| 5207 | break; |
| 5208 | } |
| 5209 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5210 | |
| 5211 | if (!ha_locked) |
| 5212 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5213 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5214 | if (!ha_locked) |
| 5215 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5216 | break; |
| 5217 | } |
| 5218 | |
| 5219 | default: |
| 5220 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, |
| 5221 | "qla_target(%d): Received unknown ATIO atio " |
| 5222 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 5223 | break; |
| 5224 | } |
| 5225 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5226 | tgt->atio_irq_cmd_count--; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | /* ha->hardware_lock supposed to be held on entry */ |
| 5230 | /* called via callback from qla2xxx */ |
| 5231 | static void qlt_response_pkt(struct scsi_qla_host *vha, response_t *pkt) |
| 5232 | { |
| 5233 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5234 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5235 | |
| 5236 | if (unlikely(tgt == NULL)) { |
| 5237 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, |
| 5238 | "qla_target(%d): Response pkt %x received, but no " |
| 5239 | "tgt (ha %p)\n", vha->vp_idx, pkt->entry_type, ha); |
| 5240 | return; |
| 5241 | } |
| 5242 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5243 | /* |
| 5244 | * In tgt_stop mode we also should allow all requests to pass. |
| 5245 | * Otherwise, some commands can stuck. |
| 5246 | */ |
| 5247 | |
| 5248 | tgt->irq_cmd_count++; |
| 5249 | |
| 5250 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 5251 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5252 | case CTIO_TYPE7: |
| 5253 | { |
| 5254 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5255 | qlt_do_ctio_completion(vha, entry->handle, |
| 5256 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5257 | entry); |
| 5258 | break; |
| 5259 | } |
| 5260 | |
| 5261 | case ACCEPT_TGT_IO_TYPE: |
| 5262 | { |
| 5263 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; |
| 5264 | int rc; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5265 | if (atio->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5266 | cpu_to_le16(ATIO_CDB_VALID)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5267 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, |
| 5268 | "qla_target(%d): ATIO with error " |
| 5269 | "status %x received\n", vha->vp_idx, |
| 5270 | le16_to_cpu(atio->u.isp2x.status)); |
| 5271 | break; |
| 5272 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5273 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5274 | rc = qlt_chk_qfull_thresh_hold(vha, atio, true); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5275 | if (rc != 0) { |
| 5276 | tgt->irq_cmd_count--; |
| 5277 | return; |
| 5278 | } |
| 5279 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5280 | rc = qlt_handle_cmd_for_atio(vha, atio); |
| 5281 | if (unlikely(rc != 0)) { |
| 5282 | if (rc == -ESRCH) { |
| 5283 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
| 5284 | qlt_send_busy(vha, atio, 0); |
| 5285 | #else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5286 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5287 | #endif |
| 5288 | } else { |
| 5289 | if (tgt->tgt_stop) { |
| 5290 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5291 | "qla_target: Unable to send " |
| 5292 | "command to target, sending TERM " |
| 5293 | "EXCHANGE for rsp\n"); |
| 5294 | qlt_send_term_exchange(vha, NULL, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5295 | atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5296 | } else { |
| 5297 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5298 | "qla_target(%d): Unable to send " |
| 5299 | "command to target, sending BUSY " |
| 5300 | "status\n", vha->vp_idx); |
| 5301 | qlt_send_busy(vha, atio, 0); |
| 5302 | } |
| 5303 | } |
| 5304 | } |
| 5305 | } |
| 5306 | break; |
| 5307 | |
| 5308 | case CONTINUE_TGT_IO_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 CTIO_A64_TYPE: |
| 5318 | { |
| 5319 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5320 | qlt_do_ctio_completion(vha, entry->handle, |
| 5321 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5322 | entry); |
| 5323 | break; |
| 5324 | } |
| 5325 | |
| 5326 | case IMMED_NOTIFY_TYPE: |
| 5327 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); |
| 5328 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); |
| 5329 | break; |
| 5330 | |
| 5331 | case NOTIFY_ACK_TYPE: |
| 5332 | if (tgt->notify_ack_expected > 0) { |
| 5333 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 5334 | ql_dbg(ql_dbg_tgt, vha, 0xe036, |
| 5335 | "NOTIFY_ACK seq %08x status %x\n", |
| 5336 | le16_to_cpu(entry->u.isp2x.seq_id), |
| 5337 | le16_to_cpu(entry->u.isp2x.status)); |
| 5338 | tgt->notify_ack_expected--; |
| 5339 | if (entry->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5340 | cpu_to_le16(NOTIFY_ACK_SUCCESS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5341 | ql_dbg(ql_dbg_tgt, vha, 0xe061, |
| 5342 | "qla_target(%d): NOTIFY_ACK " |
| 5343 | "failed %x\n", vha->vp_idx, |
| 5344 | le16_to_cpu(entry->u.isp2x.status)); |
| 5345 | } |
| 5346 | } else { |
| 5347 | ql_dbg(ql_dbg_tgt, vha, 0xe062, |
| 5348 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", |
| 5349 | vha->vp_idx); |
| 5350 | } |
| 5351 | break; |
| 5352 | |
| 5353 | case ABTS_RECV_24XX: |
| 5354 | ql_dbg(ql_dbg_tgt, vha, 0xe037, |
| 5355 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); |
| 5356 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); |
| 5357 | break; |
| 5358 | |
| 5359 | case ABTS_RESP_24XX: |
| 5360 | if (tgt->abts_resp_expected > 0) { |
| 5361 | struct abts_resp_from_24xx_fw *entry = |
| 5362 | (struct abts_resp_from_24xx_fw *)pkt; |
| 5363 | ql_dbg(ql_dbg_tgt, vha, 0xe038, |
| 5364 | "ABTS_RESP_24XX: compl_status %x\n", |
| 5365 | entry->compl_status); |
| 5366 | tgt->abts_resp_expected--; |
| 5367 | if (le16_to_cpu(entry->compl_status) != |
| 5368 | ABTS_RESP_COMPL_SUCCESS) { |
| 5369 | if ((entry->error_subcode1 == 0x1E) && |
| 5370 | (entry->error_subcode2 == 0)) { |
| 5371 | /* |
| 5372 | * We've got a race here: aborted |
| 5373 | * exchange not terminated, i.e. |
| 5374 | * response for the aborted command was |
| 5375 | * sent between the abort request was |
| 5376 | * received and processed. |
| 5377 | * Unfortunately, the firmware has a |
| 5378 | * silly requirement that all aborted |
| 5379 | * exchanges must be explicitely |
| 5380 | * terminated, otherwise it refuses to |
| 5381 | * send responses for the abort |
| 5382 | * requests. So, we have to |
| 5383 | * (re)terminate the exchange and retry |
| 5384 | * the abort response. |
| 5385 | */ |
| 5386 | qlt_24xx_retry_term_exchange(vha, |
| 5387 | entry); |
| 5388 | } else |
| 5389 | ql_dbg(ql_dbg_tgt, vha, 0xe063, |
| 5390 | "qla_target(%d): ABTS_RESP_24XX " |
| 5391 | "failed %x (subcode %x:%x)", |
| 5392 | vha->vp_idx, entry->compl_status, |
| 5393 | entry->error_subcode1, |
| 5394 | entry->error_subcode2); |
| 5395 | } |
| 5396 | } else { |
| 5397 | ql_dbg(ql_dbg_tgt, vha, 0xe064, |
| 5398 | "qla_target(%d): Unexpected ABTS_RESP_24XX " |
| 5399 | "received\n", vha->vp_idx); |
| 5400 | } |
| 5401 | break; |
| 5402 | |
| 5403 | default: |
| 5404 | ql_dbg(ql_dbg_tgt, vha, 0xe065, |
| 5405 | "qla_target(%d): Received unknown response pkt " |
| 5406 | "type %x\n", vha->vp_idx, pkt->entry_type); |
| 5407 | break; |
| 5408 | } |
| 5409 | |
| 5410 | tgt->irq_cmd_count--; |
| 5411 | } |
| 5412 | |
| 5413 | /* |
| 5414 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5415 | */ |
| 5416 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, |
| 5417 | uint16_t *mailbox) |
| 5418 | { |
| 5419 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5420 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5421 | int login_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5422 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5423 | if (!ha->tgt.tgt_ops) |
| 5424 | return; |
| 5425 | |
| 5426 | if (unlikely(tgt == NULL)) { |
| 5427 | ql_dbg(ql_dbg_tgt, vha, 0xe03a, |
| 5428 | "ASYNC EVENT %#x, but no tgt (ha %p)\n", code, ha); |
| 5429 | return; |
| 5430 | } |
| 5431 | |
| 5432 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && |
| 5433 | IS_QLA2100(ha)) |
| 5434 | return; |
| 5435 | /* |
| 5436 | * In tgt_stop mode we also should allow all requests to pass. |
| 5437 | * Otherwise, some commands can stuck. |
| 5438 | */ |
| 5439 | |
| 5440 | tgt->irq_cmd_count++; |
| 5441 | |
| 5442 | switch (code) { |
| 5443 | case MBA_RESET: /* Reset */ |
| 5444 | case MBA_SYSTEM_ERR: /* System Error */ |
| 5445 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 5446 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 5447 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, |
| 5448 | "qla_target(%d): System error async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5449 | "occurred", vha->vp_idx, code); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5450 | break; |
| 5451 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ |
| 5452 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5453 | break; |
| 5454 | |
| 5455 | case MBA_LOOP_UP: |
| 5456 | { |
| 5457 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5458 | "qla_target(%d): Async LOOP_UP occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5459 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 5460 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5461 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5462 | if (tgt->link_reinit_iocb_pending) { |
| 5463 | qlt_send_notify_ack(vha, (void *)&tgt->link_reinit_iocb, |
| 5464 | 0, 0, 0, 0, 0, 0); |
| 5465 | tgt->link_reinit_iocb_pending = 0; |
| 5466 | } |
| 5467 | break; |
| 5468 | } |
| 5469 | |
| 5470 | case MBA_LIP_OCCURRED: |
| 5471 | case MBA_LOOP_DOWN: |
| 5472 | case MBA_LIP_RESET: |
| 5473 | case MBA_RSCN_UPDATE: |
| 5474 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5475 | "qla_target(%d): Async event %#x occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5476 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5477 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5478 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5479 | break; |
| 5480 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5481 | case MBA_REJECTED_FCP_CMD: |
| 5482 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xffff, |
| 5483 | "qla_target(%d): Async event LS_REJECT occurred " |
| 5484 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 5485 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5486 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 5487 | |
| 5488 | if (le16_to_cpu(mailbox[3]) == 1) { |
| 5489 | /* exchange starvation. */ |
| 5490 | vha->hw->exch_starvation++; |
| 5491 | if (vha->hw->exch_starvation > 5) { |
| 5492 | ql_log(ql_log_warn, vha, 0xffff, |
| 5493 | "Exchange starvation-. Resetting RISC\n"); |
| 5494 | |
| 5495 | vha->hw->exch_starvation = 0; |
| 5496 | if (IS_P3P_TYPE(vha->hw)) |
| 5497 | set_bit(FCOE_CTX_RESET_NEEDED, |
| 5498 | &vha->dpc_flags); |
| 5499 | else |
| 5500 | set_bit(ISP_ABORT_NEEDED, |
| 5501 | &vha->dpc_flags); |
| 5502 | qla2xxx_wake_dpc(vha); |
| 5503 | } |
| 5504 | } |
| 5505 | break; |
| 5506 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5507 | case MBA_PORT_UPDATE: |
| 5508 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, |
| 5509 | "qla_target(%d): Port update async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5510 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5511 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5512 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5513 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 5514 | |
| 5515 | login_code = le16_to_cpu(mailbox[2]); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5516 | if (login_code == 0x4) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5517 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
| 5518 | "Async MB 2: Got PLOGI Complete\n"); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5519 | vha->hw->exch_starvation = 0; |
| 5520 | } else if (login_code == 0x7) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5521 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
| 5522 | "Async MB 2: Port Logged Out\n"); |
| 5523 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5524 | default: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5525 | break; |
| 5526 | } |
| 5527 | |
| 5528 | tgt->irq_cmd_count--; |
| 5529 | } |
| 5530 | |
| 5531 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, |
| 5532 | uint16_t loop_id) |
| 5533 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5534 | fc_port_t *fcport, *tfcp, *del; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5535 | int rc; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5536 | unsigned long flags; |
| 5537 | u8 newfcport = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5538 | |
| 5539 | fcport = kzalloc(sizeof(*fcport), GFP_KERNEL); |
| 5540 | if (!fcport) { |
| 5541 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, |
| 5542 | "qla_target(%d): Allocation of tmp FC port failed", |
| 5543 | vha->vp_idx); |
| 5544 | return NULL; |
| 5545 | } |
| 5546 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5547 | fcport->loop_id = loop_id; |
| 5548 | |
| 5549 | rc = qla2x00_get_port_database(vha, fcport, 0); |
| 5550 | if (rc != QLA_SUCCESS) { |
| 5551 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, |
| 5552 | "qla_target(%d): Failed to retrieve fcport " |
| 5553 | "information -- get_port_database() returned %x " |
| 5554 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); |
| 5555 | kfree(fcport); |
| 5556 | return NULL; |
| 5557 | } |
| 5558 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5559 | del = NULL; |
| 5560 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 5561 | tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1); |
| 5562 | |
| 5563 | if (tfcp) { |
| 5564 | tfcp->d_id = fcport->d_id; |
| 5565 | tfcp->port_type = fcport->port_type; |
| 5566 | tfcp->supported_classes = fcport->supported_classes; |
| 5567 | tfcp->flags |= fcport->flags; |
| 5568 | |
| 5569 | del = fcport; |
| 5570 | fcport = tfcp; |
| 5571 | } else { |
| 5572 | if (vha->hw->current_topology == ISP_CFG_F) |
| 5573 | fcport->flags |= FCF_FABRIC_DEVICE; |
| 5574 | |
| 5575 | list_add_tail(&fcport->list, &vha->vp_fcports); |
| 5576 | if (!IS_SW_RESV_ADDR(fcport->d_id)) |
| 5577 | vha->fcport_count++; |
| 5578 | fcport->login_gen++; |
| 5579 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 5580 | fcport->login_succ = 1; |
| 5581 | newfcport = 1; |
| 5582 | } |
| 5583 | |
| 5584 | fcport->deleted = 0; |
| 5585 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 5586 | |
| 5587 | switch (vha->host->active_mode) { |
| 5588 | case MODE_INITIATOR: |
| 5589 | case MODE_DUAL: |
| 5590 | if (newfcport) { |
| 5591 | if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) { |
| 5592 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 5593 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 5594 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5595 | qla24xx_post_upd_fcport_work(vha, fcport); |
| 5596 | } else { |
| 5597 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 5598 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 5599 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5600 | qla24xx_post_gpsc_work(vha, fcport); |
| 5601 | } |
| 5602 | } |
| 5603 | break; |
| 5604 | |
| 5605 | case MODE_TARGET: |
| 5606 | default: |
| 5607 | break; |
| 5608 | } |
| 5609 | if (del) |
| 5610 | qla2x00_free_fcport(del); |
| 5611 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5612 | return fcport; |
| 5613 | } |
| 5614 | |
| 5615 | /* Must be called under tgt_mutex */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5616 | 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] | 5617 | uint8_t *s_id) |
| 5618 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5619 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5620 | fc_port_t *fcport = NULL; |
| 5621 | int rc, global_resets; |
| 5622 | uint16_t loop_id = 0; |
| 5623 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5624 | if ((s_id[0] == 0xFF) && (s_id[1] == 0xFC)) { |
| 5625 | /* |
| 5626 | * This is Domain Controller, so it should be |
| 5627 | * OK to drop SCSI commands from it. |
| 5628 | */ |
| 5629 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, |
| 5630 | "Unable to find initiator with S_ID %x:%x:%x", |
| 5631 | s_id[0], s_id[1], s_id[2]); |
| 5632 | return NULL; |
| 5633 | } |
| 5634 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5635 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 5636 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5637 | retry: |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5638 | global_resets = |
| 5639 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5640 | |
| 5641 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); |
| 5642 | if (rc != 0) { |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5643 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5644 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5645 | ql_log(ql_log_info, vha, 0xf071, |
| 5646 | "qla_target(%d): Unable to find " |
| 5647 | "initiator with S_ID %x:%x:%x", |
| 5648 | vha->vp_idx, s_id[0], s_id[1], |
| 5649 | s_id[2]); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5650 | |
| 5651 | if (rc == -ENOENT) { |
| 5652 | qlt_port_logo_t logo; |
| 5653 | sid_to_portid(s_id, &logo.id); |
| 5654 | logo.cmd_count = 1; |
| 5655 | qlt_send_first_logo(vha, &logo); |
| 5656 | } |
| 5657 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5658 | return NULL; |
| 5659 | } |
| 5660 | |
| 5661 | fcport = qlt_get_port_database(vha, loop_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5662 | if (!fcport) { |
| 5663 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5664 | return NULL; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5665 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5666 | |
| 5667 | if (global_resets != |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5668 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5669 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
| 5670 | "qla_target(%d): global reset during session discovery " |
| 5671 | "(counter was %d, new %d), retrying", vha->vp_idx, |
| 5672 | global_resets, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5673 | atomic_read(&vha->vha_tgt. |
| 5674 | qla_tgt->tgt_global_resets_count)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5675 | goto retry; |
| 5676 | } |
| 5677 | |
| 5678 | sess = qlt_create_sess(vha, fcport, true); |
| 5679 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5680 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5681 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5682 | return sess; |
| 5683 | } |
| 5684 | |
| 5685 | static void qlt_abort_work(struct qla_tgt *tgt, |
| 5686 | struct qla_tgt_sess_work_param *prm) |
| 5687 | { |
| 5688 | struct scsi_qla_host *vha = tgt->vha; |
| 5689 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5690 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5691 | unsigned long flags = 0, flags2 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5692 | uint32_t be_s_id; |
| 5693 | uint8_t s_id[3]; |
| 5694 | int rc; |
| 5695 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5696 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5697 | |
| 5698 | if (tgt->tgt_stop) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5699 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5700 | |
| 5701 | s_id[0] = prm->abts.fcp_hdr_le.s_id[2]; |
| 5702 | s_id[1] = prm->abts.fcp_hdr_le.s_id[1]; |
| 5703 | s_id[2] = prm->abts.fcp_hdr_le.s_id[0]; |
| 5704 | |
| 5705 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 5706 | (unsigned char *)&be_s_id); |
| 5707 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5708 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5709 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5710 | sess = qlt_make_local_sess(vha, s_id); |
| 5711 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5712 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5713 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5714 | if (!sess) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5715 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5716 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5717 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5718 | sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5719 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5720 | } |
| 5721 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5722 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 5723 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xffff, |
| 5724 | "%s: kref_get fail %8phC \n", |
| 5725 | __func__, sess->port_name); |
| 5726 | sess = NULL; |
| 5727 | goto out_term2; |
| 5728 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5729 | } |
| 5730 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5731 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5732 | ha->tgt.tgt_ops->put_sess(sess); |
| 5733 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 5734 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5735 | if (rc != 0) |
| 5736 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5737 | return; |
| 5738 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5739 | out_term2: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5740 | if (sess) |
| 5741 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5742 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5743 | |
| 5744 | out_term: |
| 5745 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5746 | qlt_24xx_send_abts_resp(vha, &prm->abts, FCP_TMF_REJECTED, false); |
| 5747 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5748 | } |
| 5749 | |
| 5750 | static void qlt_tmr_work(struct qla_tgt *tgt, |
| 5751 | struct qla_tgt_sess_work_param *prm) |
| 5752 | { |
| 5753 | struct atio_from_isp *a = &prm->tm_iocb2; |
| 5754 | struct scsi_qla_host *vha = tgt->vha; |
| 5755 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5756 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5757 | unsigned long flags; |
| 5758 | uint8_t *s_id = NULL; /* to hide compiler warnings */ |
| 5759 | int rc; |
| 5760 | uint32_t lun, unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 5761 | int fn; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5762 | void *iocb; |
| 5763 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5764 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5765 | |
| 5766 | if (tgt->tgt_stop) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5767 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5768 | |
| 5769 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; |
| 5770 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 5771 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5772 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5773 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5774 | sess = qlt_make_local_sess(vha, s_id); |
| 5775 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5776 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5777 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5778 | if (!sess) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5779 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5780 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5781 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5782 | sess = NULL; |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5783 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5784 | } |
| 5785 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5786 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
| 5787 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xffff, |
| 5788 | "%s: kref_get fail %8phC\n", |
| 5789 | __func__, sess->port_name); |
| 5790 | sess = NULL; |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5791 | goto out_term2; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5792 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | iocb = a; |
| 5796 | lun = a->u.isp24.fcp_cmnd.lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5797 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
| 5798 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); |
| 5799 | |
| 5800 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5801 | ha->tgt.tgt_ops->put_sess(sess); |
| 5802 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 5803 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5804 | if (rc != 0) |
| 5805 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5806 | return; |
| 5807 | |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5808 | out_term2: |
| 5809 | if (sess) |
| 5810 | ha->tgt.tgt_ops->put_sess(sess); |
| 5811 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5812 | out_term: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5813 | qlt_send_term_exchange(vha, NULL, &prm->tm_iocb2, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | static void qlt_sess_work_fn(struct work_struct *work) |
| 5817 | { |
| 5818 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); |
| 5819 | struct scsi_qla_host *vha = tgt->vha; |
| 5820 | unsigned long flags; |
| 5821 | |
| 5822 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); |
| 5823 | |
| 5824 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 5825 | while (!list_empty(&tgt->sess_works_list)) { |
| 5826 | struct qla_tgt_sess_work_param *prm = list_entry( |
| 5827 | tgt->sess_works_list.next, typeof(*prm), |
| 5828 | sess_works_list_entry); |
| 5829 | |
| 5830 | /* |
| 5831 | * This work can be scheduled on several CPUs at time, so we |
| 5832 | * must delete the entry to eliminate double processing |
| 5833 | */ |
| 5834 | list_del(&prm->sess_works_list_entry); |
| 5835 | |
| 5836 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 5837 | |
| 5838 | switch (prm->type) { |
| 5839 | case QLA_TGT_SESS_WORK_ABORT: |
| 5840 | qlt_abort_work(tgt, prm); |
| 5841 | break; |
| 5842 | case QLA_TGT_SESS_WORK_TM: |
| 5843 | qlt_tmr_work(tgt, prm); |
| 5844 | break; |
| 5845 | default: |
| 5846 | BUG_ON(1); |
| 5847 | break; |
| 5848 | } |
| 5849 | |
| 5850 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 5851 | |
| 5852 | kfree(prm); |
| 5853 | } |
| 5854 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 5855 | } |
| 5856 | |
| 5857 | /* Must be called under tgt_host_action_mutex */ |
| 5858 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) |
| 5859 | { |
| 5860 | struct qla_tgt *tgt; |
| 5861 | |
| 5862 | if (!QLA_TGT_MODE_ENABLED()) |
| 5863 | return 0; |
| 5864 | |
Arun Easi | 33c36c0 | 2013-01-30 03:34:41 -0500 | [diff] [blame] | 5865 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
| 5866 | ql_log(ql_log_warn, base_vha, 0xe070, |
| 5867 | "This adapter does not support target mode.\n"); |
| 5868 | return 0; |
| 5869 | } |
| 5870 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5871 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5872 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5873 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5874 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5875 | |
| 5876 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); |
| 5877 | if (!tgt) { |
| 5878 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, |
| 5879 | "Unable to allocate struct qla_tgt\n"); |
| 5880 | return -ENOMEM; |
| 5881 | } |
| 5882 | |
| 5883 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) |
| 5884 | base_vha->host->hostt->supported_mode |= MODE_TARGET; |
| 5885 | |
| 5886 | tgt->ha = ha; |
| 5887 | tgt->vha = base_vha; |
| 5888 | init_waitqueue_head(&tgt->waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5889 | INIT_LIST_HEAD(&tgt->del_sess_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5890 | spin_lock_init(&tgt->sess_work_lock); |
| 5891 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); |
| 5892 | INIT_LIST_HEAD(&tgt->sess_works_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5893 | atomic_set(&tgt->tgt_global_resets_count, 0); |
| 5894 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5895 | base_vha->vha_tgt.qla_tgt = tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5896 | |
| 5897 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, |
| 5898 | "qla_target(%d): using 64 Bit PCI addressing", |
| 5899 | base_vha->vp_idx); |
| 5900 | tgt->tgt_enable_64bit_addr = 1; |
| 5901 | /* 3 is reserved */ |
| 5902 | tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3); |
| 5903 | tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX; |
| 5904 | tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX; |
| 5905 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 5906 | if (base_vha->fc_vport) |
| 5907 | return 0; |
| 5908 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5909 | mutex_lock(&qla_tgt_mutex); |
| 5910 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); |
| 5911 | mutex_unlock(&qla_tgt_mutex); |
| 5912 | |
| 5913 | return 0; |
| 5914 | } |
| 5915 | |
| 5916 | /* Must be called under tgt_host_action_mutex */ |
| 5917 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) |
| 5918 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5919 | if (!vha->vha_tgt.qla_tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5920 | return 0; |
| 5921 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 5922 | if (vha->fc_vport) { |
| 5923 | qlt_release(vha->vha_tgt.qla_tgt); |
| 5924 | return 0; |
| 5925 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5926 | |
| 5927 | /* free left over qfull cmds */ |
| 5928 | qlt_init_term_exchange(vha); |
| 5929 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5930 | mutex_lock(&qla_tgt_mutex); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5931 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5932 | mutex_unlock(&qla_tgt_mutex); |
| 5933 | |
| 5934 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", |
| 5935 | vha->host_no, ha); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5936 | qlt_release(vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5937 | |
| 5938 | return 0; |
| 5939 | } |
| 5940 | |
| 5941 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, |
| 5942 | unsigned char *b) |
| 5943 | { |
| 5944 | int i; |
| 5945 | |
| 5946 | pr_debug("qla2xxx HW vha->node_name: "); |
| 5947 | for (i = 0; i < WWN_SIZE; i++) |
| 5948 | pr_debug("%02x ", vha->node_name[i]); |
| 5949 | pr_debug("\n"); |
| 5950 | pr_debug("qla2xxx HW vha->port_name: "); |
| 5951 | for (i = 0; i < WWN_SIZE; i++) |
| 5952 | pr_debug("%02x ", vha->port_name[i]); |
| 5953 | pr_debug("\n"); |
| 5954 | |
| 5955 | pr_debug("qla2xxx passed configfs WWPN: "); |
| 5956 | put_unaligned_be64(wwpn, b); |
| 5957 | for (i = 0; i < WWN_SIZE; i++) |
| 5958 | pr_debug("%02x ", b[i]); |
| 5959 | pr_debug("\n"); |
| 5960 | } |
| 5961 | |
| 5962 | /** |
| 5963 | * qla_tgt_lport_register - register lport with external module |
| 5964 | * |
| 5965 | * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops |
| 5966 | * @wwpn: Passwd FC target WWPN |
| 5967 | * @callback: lport initialization callback for tcm_qla2xxx code |
| 5968 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data |
| 5969 | */ |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 5970 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
| 5971 | u64 npiv_wwpn, u64 npiv_wwnn, |
| 5972 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5973 | { |
| 5974 | struct qla_tgt *tgt; |
| 5975 | struct scsi_qla_host *vha; |
| 5976 | struct qla_hw_data *ha; |
| 5977 | struct Scsi_Host *host; |
| 5978 | unsigned long flags; |
| 5979 | int rc; |
| 5980 | u8 b[WWN_SIZE]; |
| 5981 | |
| 5982 | mutex_lock(&qla_tgt_mutex); |
| 5983 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { |
| 5984 | vha = tgt->vha; |
| 5985 | ha = vha->hw; |
| 5986 | |
| 5987 | host = vha->host; |
| 5988 | if (!host) |
| 5989 | continue; |
| 5990 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5991 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
| 5992 | continue; |
| 5993 | |
| 5994 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 5995 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5996 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
| 5997 | host->host_no); |
| 5998 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5999 | continue; |
| 6000 | } |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6001 | if (tgt->tgt_stop) { |
| 6002 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", |
| 6003 | host->host_no); |
| 6004 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6005 | continue; |
| 6006 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6007 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6008 | |
| 6009 | if (!scsi_host_get(host)) { |
| 6010 | ql_dbg(ql_dbg_tgt, vha, 0xe068, |
| 6011 | "Unable to scsi_host_get() for" |
| 6012 | " qla2xxx scsi_host\n"); |
| 6013 | continue; |
| 6014 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6015 | qlt_lport_dump(vha, phys_wwpn, b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6016 | |
| 6017 | if (memcmp(vha->port_name, b, WWN_SIZE)) { |
| 6018 | scsi_host_put(host); |
| 6019 | continue; |
| 6020 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6021 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
| 6022 | if (rc != 0) |
| 6023 | scsi_host_put(host); |
| 6024 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6025 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6026 | return rc; |
| 6027 | } |
| 6028 | mutex_unlock(&qla_tgt_mutex); |
| 6029 | |
| 6030 | return -ENODEV; |
| 6031 | } |
| 6032 | EXPORT_SYMBOL(qlt_lport_register); |
| 6033 | |
| 6034 | /** |
| 6035 | * qla_tgt_lport_deregister - Degister lport |
| 6036 | * |
| 6037 | * @vha: Registered scsi_qla_host pointer |
| 6038 | */ |
| 6039 | void qlt_lport_deregister(struct scsi_qla_host *vha) |
| 6040 | { |
| 6041 | struct qla_hw_data *ha = vha->hw; |
| 6042 | struct Scsi_Host *sh = vha->host; |
| 6043 | /* |
| 6044 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data |
| 6045 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6046 | vha->vha_tgt.target_lport_ptr = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6047 | ha->tgt.tgt_ops = NULL; |
| 6048 | /* |
| 6049 | * Release the Scsi_Host reference for the underlying qla2xxx host |
| 6050 | */ |
| 6051 | scsi_host_put(sh); |
| 6052 | } |
| 6053 | EXPORT_SYMBOL(qlt_lport_deregister); |
| 6054 | |
| 6055 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6056 | static void qlt_set_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6057 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6058 | switch (ql2x_ini_mode) { |
| 6059 | case QLA2XXX_INI_MODE_DISABLED: |
| 6060 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6061 | vha->host->active_mode = MODE_TARGET; |
| 6062 | break; |
| 6063 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6064 | vha->host->active_mode = MODE_UNKNOWN; |
| 6065 | break; |
| 6066 | case QLA2XXX_INI_MODE_DUAL: |
| 6067 | vha->host->active_mode = MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6068 | break; |
| 6069 | default: |
| 6070 | break; |
| 6071 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6072 | } |
| 6073 | |
| 6074 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6075 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6076 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6077 | switch (ql2x_ini_mode) { |
| 6078 | case QLA2XXX_INI_MODE_DISABLED: |
| 6079 | vha->host->active_mode = MODE_UNKNOWN; |
| 6080 | break; |
| 6081 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6082 | vha->host->active_mode = MODE_INITIATOR; |
| 6083 | break; |
| 6084 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6085 | case QLA2XXX_INI_MODE_DUAL: |
| 6086 | vha->host->active_mode = MODE_INITIATOR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6087 | break; |
| 6088 | default: |
| 6089 | break; |
| 6090 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6091 | } |
| 6092 | |
| 6093 | /* |
| 6094 | * qla_tgt_enable_vha - NO LOCK HELD |
| 6095 | * |
| 6096 | * host_reset, bring up w/ Target Mode Enabled |
| 6097 | */ |
| 6098 | void |
| 6099 | qlt_enable_vha(struct scsi_qla_host *vha) |
| 6100 | { |
| 6101 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6102 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6103 | unsigned long flags; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6104 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | cdb898c | 2015-12-17 14:57:05 -0500 | [diff] [blame] | 6105 | int rspq_ent = QLA83XX_RSPQ_MSIX_ENTRY_NUMBER; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6106 | |
| 6107 | if (!tgt) { |
| 6108 | ql_dbg(ql_dbg_tgt, vha, 0xe069, |
| 6109 | "Unable to locate qla_tgt pointer from" |
| 6110 | " struct qla_hw_data\n"); |
| 6111 | dump_stack(); |
| 6112 | return; |
| 6113 | } |
| 6114 | |
| 6115 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6116 | tgt->tgt_stopped = 0; |
| 6117 | qlt_set_mode(vha); |
| 6118 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6119 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6120 | if (vha->vp_idx) { |
| 6121 | qla24xx_disable_vp(vha); |
| 6122 | qla24xx_enable_vp(vha); |
| 6123 | } else { |
Quinn Tran | cdb898c | 2015-12-17 14:57:05 -0500 | [diff] [blame] | 6124 | if (ha->msix_entries) { |
| 6125 | ql_dbg(ql_dbg_tgt, vha, 0xffff, |
| 6126 | "%s: host%ld : vector %d cpu %d\n", |
| 6127 | __func__, vha->host_no, |
| 6128 | ha->msix_entries[rspq_ent].vector, |
| 6129 | ha->msix_entries[rspq_ent].cpuid); |
| 6130 | |
| 6131 | ha->tgt.rspq_vector_cpuid = |
| 6132 | ha->msix_entries[rspq_ent].cpuid; |
| 6133 | } |
| 6134 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6135 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 6136 | qla2xxx_wake_dpc(base_vha); |
| 6137 | qla2x00_wait_for_hba_online(base_vha); |
| 6138 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6139 | } |
| 6140 | EXPORT_SYMBOL(qlt_enable_vha); |
| 6141 | |
| 6142 | /* |
| 6143 | * qla_tgt_disable_vha - NO LOCK HELD |
| 6144 | * |
| 6145 | * Disable Target Mode and reset the adapter |
| 6146 | */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6147 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6148 | { |
| 6149 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6150 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6151 | unsigned long flags; |
| 6152 | |
| 6153 | if (!tgt) { |
| 6154 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, |
| 6155 | "Unable to locate qla_tgt pointer from" |
| 6156 | " struct qla_hw_data\n"); |
| 6157 | dump_stack(); |
| 6158 | return; |
| 6159 | } |
| 6160 | |
| 6161 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6162 | qlt_clear_mode(vha); |
| 6163 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6164 | |
| 6165 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6166 | qla2xxx_wake_dpc(vha); |
| 6167 | qla2x00_wait_for_hba_online(vha); |
| 6168 | } |
| 6169 | |
| 6170 | /* |
| 6171 | * Called from qla_init.c:qla24xx_vport_create() contex to setup |
| 6172 | * the target mode specific struct scsi_qla_host and struct qla_hw_data |
| 6173 | * members. |
| 6174 | */ |
| 6175 | void |
| 6176 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) |
| 6177 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6178 | vha->vha_tgt.qla_tgt = NULL; |
| 6179 | |
| 6180 | mutex_init(&vha->vha_tgt.tgt_mutex); |
| 6181 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6182 | |
| 6183 | qlt_clear_mode(vha); |
| 6184 | |
| 6185 | /* |
| 6186 | * NOTE: Currently the value is kept the same for <24xx and |
| 6187 | * >=24xx ISPs. If it is necessary to change it, |
| 6188 | * the check should be added for specific ISPs, |
| 6189 | * assigning the value appropriately. |
| 6190 | */ |
| 6191 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6192 | |
| 6193 | qlt_add_target(ha, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | void |
| 6197 | qlt_rff_id(struct scsi_qla_host *vha, struct ct_sns_req *ct_req) |
| 6198 | { |
| 6199 | /* |
| 6200 | * FC-4 Feature bit 0 indicates target functionality to the name server. |
| 6201 | */ |
| 6202 | if (qla_tgt_mode_enabled(vha)) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6203 | ct_req->req.rff_id.fc4_feature = BIT_0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6204 | } else if (qla_ini_mode_enabled(vha)) { |
| 6205 | ct_req->req.rff_id.fc4_feature = BIT_1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6206 | } else if (qla_dual_mode_enabled(vha)) |
| 6207 | ct_req->req.rff_id.fc4_feature = BIT_0 | BIT_1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6208 | } |
| 6209 | |
| 6210 | /* |
| 6211 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. |
| 6212 | * @ha: HA context |
| 6213 | * |
| 6214 | * Beginning of ATIO ring has initialization control block already built |
| 6215 | * by nvram config routine. |
| 6216 | * |
| 6217 | * Returns 0 on success. |
| 6218 | */ |
| 6219 | void |
| 6220 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) |
| 6221 | { |
| 6222 | struct qla_hw_data *ha = vha->hw; |
| 6223 | uint16_t cnt; |
| 6224 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; |
| 6225 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6226 | if (qla_ini_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6227 | return; |
| 6228 | |
| 6229 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { |
| 6230 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6231 | pkt++; |
| 6232 | } |
| 6233 | |
| 6234 | } |
| 6235 | |
| 6236 | /* |
| 6237 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. |
| 6238 | * @ha: SCSI driver HA context |
| 6239 | */ |
| 6240 | void |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6241 | 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] | 6242 | { |
| 6243 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6244 | struct atio_from_isp *pkt; |
| 6245 | int cnt, i; |
| 6246 | |
| 6247 | if (!vha->flags.online) |
| 6248 | return; |
| 6249 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6250 | while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) || |
| 6251 | fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6252 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6253 | cnt = pkt->u.raw.entry_count; |
| 6254 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6255 | if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) { |
| 6256 | /* |
| 6257 | * This packet is corrupted. The header + payload |
| 6258 | * can not be trusted. There is no point in passing |
| 6259 | * it further up. |
| 6260 | */ |
| 6261 | ql_log(ql_log_warn, vha, 0xffff, |
| 6262 | "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n", |
| 6263 | pkt->u.isp24.fcp_hdr.s_id, |
| 6264 | be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id), |
| 6265 | le32_to_cpu(pkt->u.isp24.exchange_addr), pkt); |
| 6266 | |
| 6267 | adjust_corrupted_atio(pkt); |
| 6268 | qlt_send_term_exchange(vha, NULL, pkt, ha_locked, 0); |
| 6269 | } else { |
| 6270 | qlt_24xx_atio_pkt_all_vps(vha, |
| 6271 | (struct atio_from_isp *)pkt, ha_locked); |
| 6272 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6273 | |
| 6274 | for (i = 0; i < cnt; i++) { |
| 6275 | ha->tgt.atio_ring_index++; |
| 6276 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { |
| 6277 | ha->tgt.atio_ring_index = 0; |
| 6278 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 6279 | } else |
| 6280 | ha->tgt.atio_ring_ptr++; |
| 6281 | |
| 6282 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6283 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6284 | } |
| 6285 | wmb(); |
| 6286 | } |
| 6287 | |
| 6288 | /* Adjust ring index */ |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6289 | 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] | 6290 | RD_REG_DWORD_RELAXED(ISP_ATIO_Q_OUT(vha)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6291 | } |
| 6292 | |
| 6293 | void |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6294 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6295 | { |
| 6296 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6297 | if (!QLA_TGT_MODE_ENABLED()) |
| 6298 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6299 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6300 | WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0); |
| 6301 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0); |
| 6302 | RD_REG_DWORD(ISP_ATIO_Q_OUT(vha)); |
| 6303 | |
| 6304 | if (IS_ATIO_MSIX_CAPABLE(ha)) { |
| 6305 | struct qla_msix_entry *msix = &ha->msix_entries[2]; |
| 6306 | struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb; |
| 6307 | |
| 6308 | icb->msix_atio = cpu_to_le16(msix->entry); |
| 6309 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6310 | "Registering ICB vector 0x%x for atio que.\n", |
| 6311 | msix->entry); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | void |
| 6316 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) |
| 6317 | { |
| 6318 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6319 | u32 tmp; |
| 6320 | u16 t; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6321 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6322 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6323 | if (!ha->tgt.saved_set) { |
| 6324 | /* We save only once */ |
| 6325 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6326 | ha->tgt.saved_firmware_options_1 = |
| 6327 | nv->firmware_options_1; |
| 6328 | ha->tgt.saved_firmware_options_2 = |
| 6329 | nv->firmware_options_2; |
| 6330 | ha->tgt.saved_firmware_options_3 = |
| 6331 | nv->firmware_options_3; |
| 6332 | ha->tgt.saved_set = 1; |
| 6333 | } |
| 6334 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6335 | if (qla_tgt_mode_enabled(vha)) { |
| 6336 | nv->exchange_count = cpu_to_le16(0xFFFF); |
| 6337 | } else { /* dual */ |
| 6338 | if (ql_dm_tgt_ex_pct > 100) { |
| 6339 | ql_dm_tgt_ex_pct = 50; |
| 6340 | } else if (ql_dm_tgt_ex_pct == 100) { |
| 6341 | /* leave some for FW */ |
| 6342 | ql_dm_tgt_ex_pct = 95; |
| 6343 | } |
| 6344 | |
| 6345 | tmp = ha->orig_fw_xcb_count * ql_dm_tgt_ex_pct; |
| 6346 | tmp = tmp/100; |
| 6347 | if (tmp > 0xffff) |
| 6348 | tmp = 0xffff; |
| 6349 | |
| 6350 | t = tmp & 0xffff; |
| 6351 | nv->exchange_count = cpu_to_le16(t); |
| 6352 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6353 | |
| 6354 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6355 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6356 | |
| 6357 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6358 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6359 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6360 | |
| 6361 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6362 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6363 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6364 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6365 | if (ql2xtgt_tape_enable) |
| 6366 | /* Enable FC Tape support */ |
| 6367 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6368 | else |
| 6369 | /* Disable FC Tape support */ |
| 6370 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6371 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6372 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6373 | nv->host_p &= cpu_to_le32(~BIT_10); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6374 | |
| 6375 | /* |
| 6376 | * clear BIT 15 explicitly as we have seen at least |
| 6377 | * a couple of instances where this was set and this |
| 6378 | * was causing the firmware to not be initialized. |
| 6379 | */ |
| 6380 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6381 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6382 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6383 | } else { |
| 6384 | if (ha->tgt.saved_set) { |
| 6385 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6386 | nv->firmware_options_1 = |
| 6387 | ha->tgt.saved_firmware_options_1; |
| 6388 | nv->firmware_options_2 = |
| 6389 | ha->tgt.saved_firmware_options_2; |
| 6390 | nv->firmware_options_3 = |
| 6391 | ha->tgt.saved_firmware_options_3; |
| 6392 | } |
| 6393 | return; |
| 6394 | } |
| 6395 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6396 | if (ha->tgt.enable_class_2) { |
| 6397 | if (vha->flags.init_done) |
| 6398 | fc_host_supported_classes(vha->host) = |
| 6399 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6400 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6401 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6402 | } else { |
| 6403 | if (vha->flags.init_done) |
| 6404 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6405 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6406 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6407 | } |
| 6408 | } |
| 6409 | |
| 6410 | void |
| 6411 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6412 | struct init_cb_24xx *icb) |
| 6413 | { |
| 6414 | struct qla_hw_data *ha = vha->hw; |
| 6415 | |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6416 | if (!QLA_TGT_MODE_ENABLED()) |
| 6417 | return; |
| 6418 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6419 | if (ha->tgt.node_name_set) { |
| 6420 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6421 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6422 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6423 | |
| 6424 | /* disable ZIO at start time. */ |
| 6425 | if (!vha->flags.init_done) { |
| 6426 | uint32_t tmp; |
| 6427 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6428 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6429 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6430 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6431 | } |
| 6432 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6433 | void |
| 6434 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) |
| 6435 | { |
| 6436 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6437 | u32 tmp; |
| 6438 | u16 t; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6439 | |
| 6440 | if (!QLA_TGT_MODE_ENABLED()) |
| 6441 | return; |
| 6442 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6443 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6444 | if (!ha->tgt.saved_set) { |
| 6445 | /* We save only once */ |
| 6446 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6447 | ha->tgt.saved_firmware_options_1 = |
| 6448 | nv->firmware_options_1; |
| 6449 | ha->tgt.saved_firmware_options_2 = |
| 6450 | nv->firmware_options_2; |
| 6451 | ha->tgt.saved_firmware_options_3 = |
| 6452 | nv->firmware_options_3; |
| 6453 | ha->tgt.saved_set = 1; |
| 6454 | } |
| 6455 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6456 | if (qla_tgt_mode_enabled(vha)) { |
| 6457 | nv->exchange_count = cpu_to_le16(0xFFFF); |
| 6458 | } else { /* dual */ |
| 6459 | if (ql_dm_tgt_ex_pct > 100) { |
| 6460 | ql_dm_tgt_ex_pct = 50; |
| 6461 | } else if (ql_dm_tgt_ex_pct == 100) { |
| 6462 | /* leave some for FW */ |
| 6463 | ql_dm_tgt_ex_pct = 95; |
| 6464 | } |
| 6465 | |
| 6466 | tmp = ha->orig_fw_xcb_count * ql_dm_tgt_ex_pct; |
| 6467 | tmp = tmp/100; |
| 6468 | if (tmp > 0xffff) |
| 6469 | tmp = 0xffff; |
| 6470 | t = tmp & 0xffff; |
| 6471 | nv->exchange_count = cpu_to_le16(t); |
| 6472 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6473 | |
| 6474 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6475 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6476 | |
| 6477 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6478 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6479 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6480 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6481 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6482 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6483 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6484 | /* |
| 6485 | * clear BIT 15 explicitly as we have seen at |
| 6486 | * least a couple of instances where this was set |
| 6487 | * and this was causing the firmware to not be |
| 6488 | * initialized. |
| 6489 | */ |
| 6490 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6491 | if (ql2xtgt_tape_enable) |
| 6492 | /* Enable FC tape support */ |
| 6493 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6494 | else |
| 6495 | /* Disable FC tape support */ |
| 6496 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6497 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6498 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6499 | nv->host_p &= cpu_to_le32(~BIT_10); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6500 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6501 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6502 | } else { |
| 6503 | if (ha->tgt.saved_set) { |
| 6504 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6505 | nv->firmware_options_1 = |
| 6506 | ha->tgt.saved_firmware_options_1; |
| 6507 | nv->firmware_options_2 = |
| 6508 | ha->tgt.saved_firmware_options_2; |
| 6509 | nv->firmware_options_3 = |
| 6510 | ha->tgt.saved_firmware_options_3; |
| 6511 | } |
| 6512 | return; |
| 6513 | } |
| 6514 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6515 | if (ha->tgt.enable_class_2) { |
| 6516 | if (vha->flags.init_done) |
| 6517 | fc_host_supported_classes(vha->host) = |
| 6518 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6519 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6520 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6521 | } else { |
| 6522 | if (vha->flags.init_done) |
| 6523 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6524 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6525 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | void |
| 6530 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6531 | struct init_cb_81xx *icb) |
| 6532 | { |
| 6533 | struct qla_hw_data *ha = vha->hw; |
| 6534 | |
| 6535 | if (!QLA_TGT_MODE_ENABLED()) |
| 6536 | return; |
| 6537 | |
| 6538 | if (ha->tgt.node_name_set) { |
| 6539 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6540 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6541 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6542 | |
| 6543 | /* disable ZIO at start time. */ |
| 6544 | if (!vha->flags.init_done) { |
| 6545 | uint32_t tmp; |
| 6546 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6547 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6548 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6549 | } |
| 6550 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6551 | } |
| 6552 | |
| 6553 | void |
| 6554 | qlt_83xx_iospace_config(struct qla_hw_data *ha) |
| 6555 | { |
| 6556 | if (!QLA_TGT_MODE_ENABLED()) |
| 6557 | return; |
| 6558 | |
| 6559 | ha->msix_count += 1; /* For ATIO Q */ |
| 6560 | } |
| 6561 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6562 | int |
| 6563 | qlt_24xx_process_response_error(struct scsi_qla_host *vha, |
| 6564 | struct sts_entry_24xx *pkt) |
| 6565 | { |
| 6566 | switch (pkt->entry_type) { |
| 6567 | case ABTS_RECV_24XX: |
| 6568 | case ABTS_RESP_24XX: |
| 6569 | case CTIO_TYPE7: |
| 6570 | case NOTIFY_ACK_TYPE: |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 6571 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6572 | return 1; |
| 6573 | default: |
| 6574 | return 0; |
| 6575 | } |
| 6576 | } |
| 6577 | |
| 6578 | void |
| 6579 | qlt_modify_vp_config(struct scsi_qla_host *vha, |
| 6580 | struct vp_config_entry_24xx *vpmod) |
| 6581 | { |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6582 | /* enable target mode. Bit5 = 1 => disable */ |
| 6583 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6584 | vpmod->options_idx1 &= ~BIT_5; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6585 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6586 | /* Disable ini mode, if requested. bit4 = 1 => disable */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6587 | if (qla_tgt_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6588 | vpmod->options_idx1 &= ~BIT_4; |
| 6589 | } |
| 6590 | |
| 6591 | void |
| 6592 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) |
| 6593 | { |
| 6594 | if (!QLA_TGT_MODE_ENABLED()) |
| 6595 | return; |
| 6596 | |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 6597 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6598 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
| 6599 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; |
| 6600 | } else { |
| 6601 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; |
| 6602 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; |
| 6603 | } |
| 6604 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6605 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
| 6606 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6607 | |
| 6608 | INIT_LIST_HEAD(&base_vha->unknown_atio_list); |
| 6609 | INIT_DELAYED_WORK(&base_vha->unknown_atio_work, |
| 6610 | qlt_unknown_atio_work_fn); |
| 6611 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6612 | qlt_clear_mode(base_vha); |
| 6613 | } |
| 6614 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6615 | irqreturn_t |
| 6616 | qla83xx_msix_atio_q(int irq, void *dev_id) |
| 6617 | { |
| 6618 | struct rsp_que *rsp; |
| 6619 | scsi_qla_host_t *vha; |
| 6620 | struct qla_hw_data *ha; |
| 6621 | unsigned long flags; |
| 6622 | |
| 6623 | rsp = (struct rsp_que *) dev_id; |
| 6624 | ha = rsp->hw; |
| 6625 | vha = pci_get_drvdata(ha->pdev); |
| 6626 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6627 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6628 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6629 | qlt_24xx_process_atio_queue(vha, 0); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6630 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6631 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6632 | |
| 6633 | return IRQ_HANDLED; |
| 6634 | } |
| 6635 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6636 | static void |
| 6637 | qlt_handle_abts_recv_work(struct work_struct *work) |
| 6638 | { |
| 6639 | struct qla_tgt_sess_op *op = container_of(work, |
| 6640 | struct qla_tgt_sess_op, work); |
| 6641 | scsi_qla_host_t *vha = op->vha; |
| 6642 | struct qla_hw_data *ha = vha->hw; |
| 6643 | unsigned long flags; |
| 6644 | |
| 6645 | if (qla2x00_reset_active(vha) || (op->chip_reset != ha->chip_reset)) |
| 6646 | return; |
| 6647 | |
| 6648 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 6649 | qlt_24xx_process_atio_queue(vha, 0); |
| 6650 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 6651 | |
| 6652 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6653 | qlt_response_pkt_all_vps(vha, (response_t *)&op->atio); |
| 6654 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | ae940f2 | 2017-03-15 09:48:44 -0700 | [diff] [blame] | 6655 | |
| 6656 | kfree(op); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6657 | } |
| 6658 | |
| 6659 | void |
| 6660 | qlt_handle_abts_recv(struct scsi_qla_host *vha, response_t *pkt) |
| 6661 | { |
| 6662 | struct qla_tgt_sess_op *op; |
| 6663 | |
| 6664 | op = kzalloc(sizeof(*op), GFP_ATOMIC); |
| 6665 | |
| 6666 | if (!op) { |
| 6667 | /* do not reach for ATIO queue here. This is best effort err |
| 6668 | * recovery at this point. |
| 6669 | */ |
| 6670 | qlt_response_pkt_all_vps(vha, pkt); |
| 6671 | return; |
| 6672 | } |
| 6673 | |
| 6674 | memcpy(&op->atio, pkt, sizeof(*pkt)); |
| 6675 | op->vha = vha; |
| 6676 | op->chip_reset = vha->hw->chip_reset; |
| 6677 | INIT_WORK(&op->work, qlt_handle_abts_recv_work); |
| 6678 | queue_work(qla_tgt_wq, &op->work); |
| 6679 | return; |
| 6680 | } |
| 6681 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6682 | int |
| 6683 | qlt_mem_alloc(struct qla_hw_data *ha) |
| 6684 | { |
| 6685 | if (!QLA_TGT_MODE_ENABLED()) |
| 6686 | return 0; |
| 6687 | |
| 6688 | ha->tgt.tgt_vp_map = kzalloc(sizeof(struct qla_tgt_vp_map) * |
| 6689 | MAX_MULTI_ID_FABRIC, GFP_KERNEL); |
| 6690 | if (!ha->tgt.tgt_vp_map) |
| 6691 | return -ENOMEM; |
| 6692 | |
| 6693 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 6694 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), |
| 6695 | &ha->tgt.atio_dma, GFP_KERNEL); |
| 6696 | if (!ha->tgt.atio_ring) { |
| 6697 | kfree(ha->tgt.tgt_vp_map); |
| 6698 | return -ENOMEM; |
| 6699 | } |
| 6700 | return 0; |
| 6701 | } |
| 6702 | |
| 6703 | void |
| 6704 | qlt_mem_free(struct qla_hw_data *ha) |
| 6705 | { |
| 6706 | if (!QLA_TGT_MODE_ENABLED()) |
| 6707 | return; |
| 6708 | |
| 6709 | if (ha->tgt.atio_ring) { |
| 6710 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * |
| 6711 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, |
| 6712 | ha->tgt.atio_dma); |
| 6713 | } |
| 6714 | kfree(ha->tgt.tgt_vp_map); |
| 6715 | } |
| 6716 | |
| 6717 | /* vport_slock to be held by the caller */ |
| 6718 | void |
| 6719 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) |
| 6720 | { |
| 6721 | if (!QLA_TGT_MODE_ENABLED()) |
| 6722 | return; |
| 6723 | |
| 6724 | switch (cmd) { |
| 6725 | case SET_VP_IDX: |
| 6726 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; |
| 6727 | break; |
| 6728 | case SET_AL_PA: |
| 6729 | vha->hw->tgt.tgt_vp_map[vha->d_id.b.al_pa].idx = vha->vp_idx; |
| 6730 | break; |
| 6731 | case RESET_VP_IDX: |
| 6732 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; |
| 6733 | break; |
| 6734 | case RESET_AL_PA: |
| 6735 | vha->hw->tgt.tgt_vp_map[vha->d_id.b.al_pa].idx = 0; |
| 6736 | break; |
| 6737 | } |
| 6738 | } |
| 6739 | |
| 6740 | static int __init qlt_parse_ini_mode(void) |
| 6741 | { |
| 6742 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) |
| 6743 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
| 6744 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) |
| 6745 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; |
| 6746 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) |
| 6747 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6748 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0) |
| 6749 | ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6750 | else |
| 6751 | return false; |
| 6752 | |
| 6753 | return true; |
| 6754 | } |
| 6755 | |
| 6756 | int __init qlt_init(void) |
| 6757 | { |
| 6758 | int ret; |
| 6759 | |
| 6760 | if (!qlt_parse_ini_mode()) { |
| 6761 | ql_log(ql_log_fatal, NULL, 0xe06b, |
| 6762 | "qlt_parse_ini_mode() failed\n"); |
| 6763 | return -EINVAL; |
| 6764 | } |
| 6765 | |
| 6766 | if (!QLA_TGT_MODE_ENABLED()) |
| 6767 | return 0; |
| 6768 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6769 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
| 6770 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct |
| 6771 | qla_tgt_mgmt_cmd), 0, NULL); |
| 6772 | if (!qla_tgt_mgmt_cmd_cachep) { |
| 6773 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 6774 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 6775 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6776 | } |
| 6777 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6778 | qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep", |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6779 | sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t), |
| 6780 | 0, NULL); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6781 | |
| 6782 | if (!qla_tgt_plogi_cachep) { |
| 6783 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 6784 | "kmem_cache_create for qla_tgt_plogi_cachep failed\n"); |
| 6785 | ret = -ENOMEM; |
| 6786 | goto out_mgmt_cmd_cachep; |
| 6787 | } |
| 6788 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6789 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, |
| 6790 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); |
| 6791 | if (!qla_tgt_mgmt_cmd_mempool) { |
| 6792 | ql_log(ql_log_fatal, NULL, 0xe06e, |
| 6793 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); |
| 6794 | ret = -ENOMEM; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6795 | goto out_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6796 | } |
| 6797 | |
| 6798 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); |
| 6799 | if (!qla_tgt_wq) { |
| 6800 | ql_log(ql_log_fatal, NULL, 0xe06f, |
| 6801 | "alloc_workqueue for qla_tgt_wq failed\n"); |
| 6802 | ret = -ENOMEM; |
| 6803 | goto out_cmd_mempool; |
| 6804 | } |
| 6805 | /* |
| 6806 | * Return 1 to signal that initiator-mode is being disabled |
| 6807 | */ |
| 6808 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; |
| 6809 | |
| 6810 | out_cmd_mempool: |
| 6811 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6812 | out_plogi_cachep: |
| 6813 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6814 | out_mgmt_cmd_cachep: |
| 6815 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6816 | return ret; |
| 6817 | } |
| 6818 | |
| 6819 | void qlt_exit(void) |
| 6820 | { |
| 6821 | if (!QLA_TGT_MODE_ENABLED()) |
| 6822 | return; |
| 6823 | |
| 6824 | destroy_workqueue(qla_tgt_wq); |
| 6825 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6826 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6827 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6828 | } |