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; " |
| 58 | "\"enabled\" (default) - initiator mode will always stay enabled."); |
| 59 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 60 | int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 61 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 62 | static int temp_sam_status = SAM_STAT_BUSY; |
| 63 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 64 | /* |
| 65 | * From scsi/fc/fc_fcp.h |
| 66 | */ |
| 67 | enum fcp_resp_rsp_codes { |
| 68 | FCP_TMF_CMPL = 0, |
| 69 | FCP_DATA_LEN_INVALID = 1, |
| 70 | FCP_CMND_FIELDS_INVALID = 2, |
| 71 | FCP_DATA_PARAM_MISMATCH = 3, |
| 72 | FCP_TMF_REJECTED = 4, |
| 73 | FCP_TMF_FAILED = 5, |
| 74 | FCP_TMF_INVALID_LUN = 9, |
| 75 | }; |
| 76 | |
| 77 | /* |
| 78 | * fc_pri_ta from scsi/fc/fc_fcp.h |
| 79 | */ |
| 80 | #define FCP_PTA_SIMPLE 0 /* simple task attribute */ |
| 81 | #define FCP_PTA_HEADQ 1 /* head of queue task attribute */ |
| 82 | #define FCP_PTA_ORDERED 2 /* ordered task attribute */ |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 83 | #define FCP_PTA_ACA 4 /* auto. contingent allegiance */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 84 | #define FCP_PTA_MASK 7 /* mask for task attribute field */ |
| 85 | #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */ |
| 86 | #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */ |
| 87 | |
| 88 | /* |
| 89 | * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which |
| 90 | * must be called under HW lock and could unlock/lock it inside. |
| 91 | * It isn't an issue, since in the current implementation on the time when |
| 92 | * those functions are called: |
| 93 | * |
| 94 | * - Either context is IRQ and only IRQ handler can modify HW data, |
| 95 | * including rings related fields, |
| 96 | * |
| 97 | * - Or access to target mode variables from struct qla_tgt doesn't |
| 98 | * cross those functions boundaries, except tgt_stop, which |
| 99 | * additionally protected by irq_cmd_count. |
| 100 | */ |
| 101 | /* Predefs for callbacks handed to qla2xxx LLD */ |
| 102 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 103 | struct atio_from_isp *pkt, uint8_t); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 104 | static void qlt_response_pkt(struct scsi_qla_host *ha, response_t *pkt); |
| 105 | static int qlt_issue_task_mgmt(struct qla_tgt_sess *sess, uint32_t lun, |
| 106 | int fn, void *iocb, int flags); |
| 107 | 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] | 108 | *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 109 | static void qlt_reject_free_srr_imm(struct scsi_qla_host *ha, |
| 110 | struct qla_tgt_srr_imm *imm, int ha_lock); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 111 | static void qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, |
| 112 | struct qla_tgt_cmd *cmd); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 113 | static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 114 | struct atio_from_isp *atio, uint16_t status, int qfull); |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 115 | static void qlt_disable_vha(struct scsi_qla_host *vha); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 116 | static void qlt_clear_tgt_db(struct qla_tgt *tgt); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 117 | static void qlt_send_notify_ack(struct scsi_qla_host *vha, |
| 118 | struct imm_ntfy_from_isp *ntfy, |
| 119 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 120 | 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] | 121 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 122 | struct imm_ntfy_from_isp *imm, int ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 123 | /* |
| 124 | * Global Variables |
| 125 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 126 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 127 | static struct kmem_cache *qla_tgt_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 128 | static mempool_t *qla_tgt_mgmt_cmd_mempool; |
| 129 | static struct workqueue_struct *qla_tgt_wq; |
| 130 | static DEFINE_MUTEX(qla_tgt_mutex); |
| 131 | static LIST_HEAD(qla_tgt_glist); |
| 132 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 133 | /* This API intentionally takes dest as a parameter, rather than returning |
| 134 | * int value to avoid caller forgetting to issue wmb() after the store */ |
| 135 | void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest) |
| 136 | { |
| 137 | scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev); |
| 138 | *dest = atomic_inc_return(&base_vha->generation_tick); |
| 139 | /* memory barrier */ |
| 140 | wmb(); |
| 141 | } |
| 142 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 143 | /* ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) */ |
| 144 | static struct qla_tgt_sess *qlt_find_sess_by_port_name( |
| 145 | struct qla_tgt *tgt, |
| 146 | const uint8_t *port_name) |
| 147 | { |
| 148 | struct qla_tgt_sess *sess; |
| 149 | |
| 150 | list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) { |
| 151 | if (!memcmp(sess->port_name, port_name, WWN_SIZE)) |
| 152 | return sess; |
| 153 | } |
| 154 | |
| 155 | return NULL; |
| 156 | } |
| 157 | |
| 158 | /* Might release hw lock, then reaquire!! */ |
| 159 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) |
| 160 | { |
| 161 | /* Send marker if required */ |
| 162 | if (unlikely(vha->marker_needed != 0)) { |
| 163 | int rc = qla2x00_issue_marker(vha, vha_locked); |
| 164 | if (rc != QLA_SUCCESS) { |
| 165 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, |
| 166 | "qla_target(%d): issue_marker() failed\n", |
| 167 | vha->vp_idx); |
| 168 | } |
| 169 | return rc; |
| 170 | } |
| 171 | return QLA_SUCCESS; |
| 172 | } |
| 173 | |
| 174 | static inline |
| 175 | struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha, |
| 176 | uint8_t *d_id) |
| 177 | { |
| 178 | struct qla_hw_data *ha = vha->hw; |
| 179 | uint8_t vp_idx; |
| 180 | |
| 181 | if ((vha->d_id.b.area != d_id[1]) || (vha->d_id.b.domain != d_id[0])) |
| 182 | return NULL; |
| 183 | |
| 184 | if (vha->d_id.b.al_pa == d_id[2]) |
| 185 | return vha; |
| 186 | |
| 187 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 188 | vp_idx = ha->tgt.tgt_vp_map[d_id[2]].idx; |
| 189 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 190 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 191 | |
| 192 | return NULL; |
| 193 | } |
| 194 | |
| 195 | static inline |
| 196 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, |
| 197 | uint16_t vp_idx) |
| 198 | { |
| 199 | struct qla_hw_data *ha = vha->hw; |
| 200 | |
| 201 | if (vha->vp_idx == vp_idx) |
| 202 | return vha; |
| 203 | |
| 204 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 205 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 206 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 207 | |
| 208 | return NULL; |
| 209 | } |
| 210 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 211 | static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha) |
| 212 | { |
| 213 | unsigned long flags; |
| 214 | |
| 215 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 216 | |
| 217 | vha->hw->tgt.num_pend_cmds++; |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 218 | if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds) |
| 219 | vha->qla_stats.stat_max_pend_cmds = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 220 | vha->hw->tgt.num_pend_cmds; |
| 221 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 222 | } |
| 223 | static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha) |
| 224 | { |
| 225 | unsigned long flags; |
| 226 | |
| 227 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 228 | vha->hw->tgt.num_pend_cmds--; |
| 229 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 230 | } |
| 231 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 232 | 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] | 233 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 234 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 235 | ql_dbg(ql_dbg_tgt, vha, 0xe072, |
| 236 | "%s: qla_target(%d): type %x ox_id %04x\n", |
| 237 | __func__, vha->vp_idx, atio->u.raw.entry_type, |
| 238 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 239 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 240 | switch (atio->u.raw.entry_type) { |
| 241 | case ATIO_TYPE7: |
| 242 | { |
| 243 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, |
| 244 | atio->u.isp24.fcp_hdr.d_id); |
| 245 | if (unlikely(NULL == host)) { |
| 246 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, |
| 247 | "qla_target(%d): Received ATIO_TYPE7 " |
| 248 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, |
| 249 | atio->u.isp24.fcp_hdr.d_id[0], |
| 250 | atio->u.isp24.fcp_hdr.d_id[1], |
| 251 | atio->u.isp24.fcp_hdr.d_id[2]); |
| 252 | break; |
| 253 | } |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 254 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 255 | break; |
| 256 | } |
| 257 | |
| 258 | case IMMED_NOTIFY_TYPE: |
| 259 | { |
| 260 | struct scsi_qla_host *host = vha; |
| 261 | struct imm_ntfy_from_isp *entry = |
| 262 | (struct imm_ntfy_from_isp *)atio; |
| 263 | |
| 264 | if ((entry->u.isp24.vp_index != 0xFF) && |
| 265 | (entry->u.isp24.nport_handle != 0xFFFF)) { |
| 266 | host = qlt_find_host_by_vp_idx(vha, |
| 267 | entry->u.isp24.vp_index); |
| 268 | if (unlikely(!host)) { |
| 269 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, |
| 270 | "qla_target(%d): Received " |
| 271 | "ATIO (IMMED_NOTIFY_TYPE) " |
| 272 | "with unknown vp_index %d\n", |
| 273 | vha->vp_idx, entry->u.isp24.vp_index); |
| 274 | break; |
| 275 | } |
| 276 | } |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 277 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 278 | break; |
| 279 | } |
| 280 | |
| 281 | default: |
| 282 | ql_dbg(ql_dbg_tgt, vha, 0xe040, |
| 283 | "qla_target(%d): Received unknown ATIO atio " |
| 284 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 285 | break; |
| 286 | } |
| 287 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 288 | return false; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, response_t *pkt) |
| 292 | { |
| 293 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 294 | case CTIO_CRC2: |
| 295 | ql_dbg(ql_dbg_tgt, vha, 0xe073, |
| 296 | "qla_target(%d):%s: CRC2 Response pkt\n", |
| 297 | vha->vp_idx, __func__); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 298 | case CTIO_TYPE7: |
| 299 | { |
| 300 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
| 301 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 302 | entry->vp_index); |
| 303 | if (unlikely(!host)) { |
| 304 | ql_dbg(ql_dbg_tgt, vha, 0xe041, |
| 305 | "qla_target(%d): Response pkt (CTIO_TYPE7) " |
| 306 | "received, with unknown vp_index %d\n", |
| 307 | vha->vp_idx, entry->vp_index); |
| 308 | break; |
| 309 | } |
| 310 | qlt_response_pkt(host, pkt); |
| 311 | break; |
| 312 | } |
| 313 | |
| 314 | case IMMED_NOTIFY_TYPE: |
| 315 | { |
| 316 | struct scsi_qla_host *host = vha; |
| 317 | struct imm_ntfy_from_isp *entry = |
| 318 | (struct imm_ntfy_from_isp *)pkt; |
| 319 | |
| 320 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); |
| 321 | if (unlikely(!host)) { |
| 322 | ql_dbg(ql_dbg_tgt, vha, 0xe042, |
| 323 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " |
| 324 | "received, with unknown vp_index %d\n", |
| 325 | vha->vp_idx, entry->u.isp24.vp_index); |
| 326 | break; |
| 327 | } |
| 328 | qlt_response_pkt(host, pkt); |
| 329 | break; |
| 330 | } |
| 331 | |
| 332 | case NOTIFY_ACK_TYPE: |
| 333 | { |
| 334 | struct scsi_qla_host *host = vha; |
| 335 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 336 | |
| 337 | if (0xFF != entry->u.isp24.vp_index) { |
| 338 | host = qlt_find_host_by_vp_idx(vha, |
| 339 | entry->u.isp24.vp_index); |
| 340 | if (unlikely(!host)) { |
| 341 | ql_dbg(ql_dbg_tgt, vha, 0xe043, |
| 342 | "qla_target(%d): Response " |
| 343 | "pkt (NOTIFY_ACK_TYPE) " |
| 344 | "received, with unknown " |
| 345 | "vp_index %d\n", vha->vp_idx, |
| 346 | entry->u.isp24.vp_index); |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | qlt_response_pkt(host, pkt); |
| 351 | break; |
| 352 | } |
| 353 | |
| 354 | case ABTS_RECV_24XX: |
| 355 | { |
| 356 | struct abts_recv_from_24xx *entry = |
| 357 | (struct abts_recv_from_24xx *)pkt; |
| 358 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 359 | entry->vp_index); |
| 360 | if (unlikely(!host)) { |
| 361 | ql_dbg(ql_dbg_tgt, vha, 0xe044, |
| 362 | "qla_target(%d): Response pkt " |
| 363 | "(ABTS_RECV_24XX) received, with unknown " |
| 364 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 365 | break; |
| 366 | } |
| 367 | qlt_response_pkt(host, pkt); |
| 368 | break; |
| 369 | } |
| 370 | |
| 371 | case ABTS_RESP_24XX: |
| 372 | { |
| 373 | struct abts_resp_to_24xx *entry = |
| 374 | (struct abts_resp_to_24xx *)pkt; |
| 375 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 376 | entry->vp_index); |
| 377 | if (unlikely(!host)) { |
| 378 | ql_dbg(ql_dbg_tgt, vha, 0xe045, |
| 379 | "qla_target(%d): Response pkt " |
| 380 | "(ABTS_RECV_24XX) received, with unknown " |
| 381 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 382 | break; |
| 383 | } |
| 384 | qlt_response_pkt(host, pkt); |
| 385 | break; |
| 386 | } |
| 387 | |
| 388 | default: |
| 389 | qlt_response_pkt(vha, pkt); |
| 390 | break; |
| 391 | } |
| 392 | |
| 393 | } |
| 394 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 395 | /* |
| 396 | * All qlt_plogi_ack_t operations are protected by hardware_lock |
| 397 | */ |
| 398 | |
| 399 | /* |
| 400 | * This is a zero-base ref-counting solution, since hardware_lock |
| 401 | * guarantees that ref_count is not modified concurrently. |
| 402 | * Upon successful return content of iocb is undefined |
| 403 | */ |
| 404 | static qlt_plogi_ack_t * |
| 405 | qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id, |
| 406 | struct imm_ntfy_from_isp *iocb) |
| 407 | { |
| 408 | qlt_plogi_ack_t *pla; |
| 409 | |
| 410 | list_for_each_entry(pla, &vha->plogi_ack_list, list) { |
| 411 | if (pla->id.b24 == id->b24) { |
| 412 | qlt_send_term_imm_notif(vha, &pla->iocb, 1); |
| 413 | pla->iocb = *iocb; |
| 414 | return pla; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC); |
| 419 | if (!pla) { |
| 420 | ql_dbg(ql_dbg_async, vha, 0x5088, |
| 421 | "qla_target(%d): Allocation of plogi_ack failed\n", |
| 422 | vha->vp_idx); |
| 423 | return NULL; |
| 424 | } |
| 425 | |
| 426 | pla->iocb = *iocb; |
| 427 | pla->id = *id; |
| 428 | list_add_tail(&pla->list, &vha->plogi_ack_list); |
| 429 | |
| 430 | return pla; |
| 431 | } |
| 432 | |
| 433 | static void qlt_plogi_ack_unref(struct scsi_qla_host *vha, qlt_plogi_ack_t *pla) |
| 434 | { |
| 435 | BUG_ON(!pla->ref_count); |
| 436 | pla->ref_count--; |
| 437 | |
| 438 | if (pla->ref_count) |
| 439 | return; |
| 440 | |
| 441 | ql_dbg(ql_dbg_async, vha, 0x5089, |
| 442 | "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x" |
| 443 | " exch %#x ox_id %#x\n", pla->iocb.u.isp24.port_name, |
| 444 | pla->iocb.u.isp24.port_id[2], pla->iocb.u.isp24.port_id[1], |
| 445 | pla->iocb.u.isp24.port_id[0], |
| 446 | le16_to_cpu(pla->iocb.u.isp24.nport_handle), |
| 447 | pla->iocb.u.isp24.exchange_address, pla->iocb.ox_id); |
| 448 | qlt_send_notify_ack(vha, &pla->iocb, 0, 0, 0, 0, 0, 0); |
| 449 | |
| 450 | list_del(&pla->list); |
| 451 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 452 | } |
| 453 | |
| 454 | static void |
| 455 | qlt_plogi_ack_link(struct scsi_qla_host *vha, qlt_plogi_ack_t *pla, |
| 456 | struct qla_tgt_sess *sess, qlt_plogi_link_t link) |
| 457 | { |
| 458 | /* Inc ref_count first because link might already be pointing at pla */ |
| 459 | pla->ref_count++; |
| 460 | |
| 461 | if (sess->plogi_link[link]) |
| 462 | qlt_plogi_ack_unref(vha, sess->plogi_link[link]); |
| 463 | |
| 464 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097, |
| 465 | "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC" |
| 466 | " s_id %02x:%02x:%02x, ref=%d\n", sess, link, sess->port_name, |
| 467 | pla->iocb.u.isp24.port_name, pla->iocb.u.isp24.port_id[2], |
| 468 | pla->iocb.u.isp24.port_id[1], pla->iocb.u.isp24.port_id[0], |
| 469 | pla->ref_count); |
| 470 | |
| 471 | sess->plogi_link[link] = pla; |
| 472 | } |
| 473 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 474 | typedef struct { |
| 475 | /* These fields must be initialized by the caller */ |
| 476 | port_id_t id; |
| 477 | /* |
| 478 | * number of cmds dropped while we were waiting for |
| 479 | * initiator to ack LOGO initialize to 1 if LOGO is |
| 480 | * triggered by a command, otherwise, to 0 |
| 481 | */ |
| 482 | int cmd_count; |
| 483 | |
| 484 | /* These fields are used by callee */ |
| 485 | struct list_head list; |
| 486 | } qlt_port_logo_t; |
| 487 | |
| 488 | static void |
| 489 | qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo) |
| 490 | { |
| 491 | qlt_port_logo_t *tmp; |
| 492 | int res; |
| 493 | |
| 494 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 495 | |
| 496 | list_for_each_entry(tmp, &vha->logo_list, list) { |
| 497 | if (tmp->id.b24 == logo->id.b24) { |
| 498 | tmp->cmd_count += logo->cmd_count; |
| 499 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 500 | return; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | list_add_tail(&logo->list, &vha->logo_list); |
| 505 | |
| 506 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 507 | |
| 508 | res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id); |
| 509 | |
| 510 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 511 | list_del(&logo->list); |
| 512 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 513 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 514 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098, |
| 515 | "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n", |
| 516 | logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa, |
| 517 | logo->cmd_count, res); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 518 | } |
| 519 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 520 | static void qlt_free_session_done(struct work_struct *work) |
| 521 | { |
| 522 | struct qla_tgt_sess *sess = container_of(work, struct qla_tgt_sess, |
| 523 | free_work); |
| 524 | struct qla_tgt *tgt = sess->tgt; |
| 525 | struct scsi_qla_host *vha = sess->vha; |
| 526 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 527 | unsigned long flags; |
| 528 | bool logout_started = false; |
| 529 | fc_port_t fcport; |
| 530 | |
| 531 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf084, |
| 532 | "%s: se_sess %p / sess %p from port %8phC loop_id %#04x" |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 533 | " 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] | 534 | __func__, sess->se_sess, sess, sess->port_name, sess->loop_id, |
| 535 | sess->s_id.b.domain, sess->s_id.b.area, sess->s_id.b.al_pa, |
| 536 | sess->logout_on_delete, sess->keep_nport_handle, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 537 | sess->send_els_logo); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 538 | |
| 539 | BUG_ON(!tgt); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 540 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 541 | if (sess->send_els_logo) { |
| 542 | qlt_port_logo_t logo; |
| 543 | logo.id = sess->s_id; |
| 544 | logo.cmd_count = 0; |
| 545 | qlt_send_first_logo(vha, &logo); |
| 546 | } |
| 547 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 548 | if (sess->logout_on_delete) { |
| 549 | int rc; |
| 550 | |
| 551 | memset(&fcport, 0, sizeof(fcport)); |
| 552 | fcport.loop_id = sess->loop_id; |
| 553 | fcport.d_id = sess->s_id; |
| 554 | memcpy(fcport.port_name, sess->port_name, WWN_SIZE); |
| 555 | fcport.vha = vha; |
| 556 | fcport.tgt_session = sess; |
| 557 | |
| 558 | rc = qla2x00_post_async_logout_work(vha, &fcport, NULL); |
| 559 | if (rc != QLA_SUCCESS) |
| 560 | ql_log(ql_log_warn, vha, 0xf085, |
| 561 | "Schedule logo failed sess %p rc %d\n", |
| 562 | sess, rc); |
| 563 | else |
| 564 | logout_started = true; |
| 565 | } |
| 566 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 567 | /* |
| 568 | * Release the target session for FC Nexus from fabric module code. |
| 569 | */ |
| 570 | if (sess->se_sess != NULL) |
| 571 | ha->tgt.tgt_ops->free_session(sess); |
| 572 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 573 | if (logout_started) { |
| 574 | bool traced = false; |
| 575 | |
| 576 | while (!ACCESS_ONCE(sess->logout_completed)) { |
| 577 | if (!traced) { |
| 578 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf086, |
| 579 | "%s: waiting for sess %p logout\n", |
| 580 | __func__, sess); |
| 581 | traced = true; |
| 582 | } |
| 583 | msleep(100); |
| 584 | } |
| 585 | |
| 586 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf087, |
| 587 | "%s: sess %p logout completed\n", |
| 588 | __func__, sess); |
| 589 | } |
| 590 | |
| 591 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 592 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 593 | { |
| 594 | qlt_plogi_ack_t *own = |
| 595 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
| 596 | qlt_plogi_ack_t *con = |
| 597 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]; |
| 598 | |
| 599 | if (con) { |
| 600 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099, |
| 601 | "se_sess %p / sess %p port %8phC is gone," |
| 602 | " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n", |
| 603 | sess->se_sess, sess, sess->port_name, |
| 604 | own ? "releasing own PLOGI" : |
| 605 | "no own PLOGI pending", |
| 606 | own ? own->ref_count : -1, |
| 607 | con->iocb.u.isp24.port_name, con->ref_count); |
| 608 | qlt_plogi_ack_unref(vha, con); |
| 609 | } else { |
| 610 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a, |
| 611 | "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n", |
| 612 | sess->se_sess, sess, sess->port_name, |
| 613 | own ? "releasing own PLOGI" : |
| 614 | "no own PLOGI pending", |
| 615 | own ? own->ref_count : -1); |
| 616 | } |
| 617 | |
| 618 | if (own) |
| 619 | qlt_plogi_ack_unref(vha, own); |
| 620 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 621 | |
| 622 | list_del(&sess->sess_list_entry); |
| 623 | |
| 624 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 625 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 626 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, |
| 627 | "Unregistration of sess %p finished\n", sess); |
| 628 | |
| 629 | kfree(sess); |
| 630 | /* |
| 631 | * We need to protect against race, when tgt is freed before or |
| 632 | * inside wake_up() |
| 633 | */ |
| 634 | tgt->sess_count--; |
| 635 | if (tgt->sess_count == 0) |
| 636 | wake_up_all(&tgt->waitQ); |
| 637 | } |
| 638 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 639 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 640 | static void qlt_release_session(struct kref *kref) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 641 | { |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 642 | struct qla_tgt_sess *sess = |
| 643 | container_of(kref, struct qla_tgt_sess, sess_kref); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 644 | struct scsi_qla_host *vha = sess->vha; |
| 645 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 646 | if (sess->se_sess) |
| 647 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 648 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 649 | if (!list_empty(&sess->del_list_entry)) |
| 650 | list_del_init(&sess->del_list_entry); |
| 651 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 652 | |
| 653 | INIT_WORK(&sess->free_work, qlt_free_session_done); |
| 654 | schedule_work(&sess->free_work); |
| 655 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 656 | |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 657 | void qlt_put_sess(struct qla_tgt_sess *sess) |
| 658 | { |
| 659 | if (!sess) |
| 660 | return; |
| 661 | |
| 662 | assert_spin_locked(&sess->vha->hw->tgt.sess_lock); |
| 663 | kref_put(&sess->sess_kref, qlt_release_session); |
| 664 | } |
| 665 | EXPORT_SYMBOL(qlt_put_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 666 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 667 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) |
| 668 | { |
| 669 | struct qla_hw_data *ha = vha->hw; |
| 670 | struct qla_tgt_sess *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 671 | uint16_t loop_id; |
| 672 | int res = 0; |
| 673 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 674 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 675 | |
| 676 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); |
| 677 | if (loop_id == 0xFFFF) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 678 | /* Global event */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 679 | atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 680 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 681 | qlt_clear_tgt_db(vha->vha_tgt.qla_tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 682 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 683 | #if 0 /* FIXME: do we need to choose a session here? */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 684 | if (!list_empty(&ha->tgt.qla_tgt->sess_list)) { |
| 685 | sess = list_entry(ha->tgt.qla_tgt->sess_list.next, |
| 686 | typeof(*sess), sess_list_entry); |
| 687 | switch (mcmd) { |
| 688 | case QLA_TGT_NEXUS_LOSS_SESS: |
| 689 | mcmd = QLA_TGT_NEXUS_LOSS; |
| 690 | break; |
| 691 | case QLA_TGT_ABORT_ALL_SESS: |
| 692 | mcmd = QLA_TGT_ABORT_ALL; |
| 693 | break; |
| 694 | case QLA_TGT_NEXUS_LOSS: |
| 695 | case QLA_TGT_ABORT_ALL: |
| 696 | break; |
| 697 | default: |
| 698 | ql_dbg(ql_dbg_tgt, vha, 0xe046, |
| 699 | "qla_target(%d): Not allowed " |
| 700 | "command %x in %s", vha->vp_idx, |
| 701 | mcmd, __func__); |
| 702 | sess = NULL; |
| 703 | break; |
| 704 | } |
| 705 | } else |
| 706 | sess = NULL; |
| 707 | #endif |
| 708 | } else { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 709 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 710 | 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] | 711 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | ql_dbg(ql_dbg_tgt, vha, 0xe000, |
| 715 | "Using sess for qla_tgt_reset: %p\n", sess); |
| 716 | if (!sess) { |
| 717 | res = -ESRCH; |
| 718 | return res; |
| 719 | } |
| 720 | |
| 721 | ql_dbg(ql_dbg_tgt, vha, 0xe047, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 722 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
| 723 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 724 | mcmd, loop_id); |
| 725 | |
Quinn Tran | bb1181c | 2016-12-23 18:06:05 -0800 | [diff] [blame] | 726 | 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] | 727 | } |
| 728 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 729 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 730 | static void qlt_schedule_sess_for_deletion(struct qla_tgt_sess *sess, |
| 731 | bool immediate) |
| 732 | { |
| 733 | struct qla_tgt *tgt = sess->tgt; |
| 734 | uint32_t dev_loss_tmo = tgt->ha->port_down_retry_count + 5; |
| 735 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 736 | if (sess->deleted) { |
| 737 | /* Upgrade to unconditional deletion in case it was temporary */ |
| 738 | if (immediate && sess->deleted == QLA_SESS_DELETION_PENDING) |
| 739 | list_del(&sess->del_list_entry); |
| 740 | else |
| 741 | return; |
| 742 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 743 | |
| 744 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, |
| 745 | "Scheduling sess %p for deletion\n", sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 746 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 747 | if (immediate) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 748 | dev_loss_tmo = 0; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 749 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
| 750 | list_add(&sess->del_list_entry, &tgt->del_sess_list); |
| 751 | } else { |
| 752 | sess->deleted = QLA_SESS_DELETION_PENDING; |
| 753 | list_add_tail(&sess->del_list_entry, &tgt->del_sess_list); |
| 754 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 755 | |
| 756 | sess->expires = jiffies + dev_loss_tmo * HZ; |
| 757 | |
| 758 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe048, |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 759 | "qla_target(%d): session for port %8phC (loop ID %d s_id %02x:%02x:%02x)" |
| 760 | " scheduled for deletion in %u secs (expires: %lu) immed: %d, logout: %d, gen: %#x\n", |
| 761 | sess->vha->vp_idx, sess->port_name, sess->loop_id, |
| 762 | sess->s_id.b.domain, sess->s_id.b.area, sess->s_id.b.al_pa, |
| 763 | dev_loss_tmo, sess->expires, immediate, sess->logout_on_delete, |
| 764 | sess->generation); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 765 | |
| 766 | if (immediate) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 767 | mod_delayed_work(system_wq, &tgt->sess_del_work, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 768 | else |
| 769 | schedule_delayed_work(&tgt->sess_del_work, |
Shivaram Upadhyayula | 63832aa | 2013-12-10 16:06:40 +0530 | [diff] [blame] | 770 | sess->expires - jiffies); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 771 | } |
| 772 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 773 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 774 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 775 | { |
| 776 | struct qla_tgt_sess *sess; |
| 777 | |
| 778 | list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) |
| 779 | qlt_schedule_sess_for_deletion(sess, true); |
| 780 | |
| 781 | /* At this point tgt could be already dead */ |
| 782 | } |
| 783 | |
| 784 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id, |
| 785 | uint16_t *loop_id) |
| 786 | { |
| 787 | struct qla_hw_data *ha = vha->hw; |
| 788 | dma_addr_t gid_list_dma; |
| 789 | struct gid_list_info *gid_list; |
| 790 | char *id_iter; |
| 791 | int res, rc, i; |
| 792 | uint16_t entries; |
| 793 | |
| 794 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 795 | &gid_list_dma, GFP_KERNEL); |
| 796 | if (!gid_list) { |
| 797 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, |
| 798 | "qla_target(%d): DMA Alloc failed of %u\n", |
| 799 | vha->vp_idx, qla2x00_gid_list_size(ha)); |
| 800 | return -ENOMEM; |
| 801 | } |
| 802 | |
| 803 | /* Get list of logged in devices */ |
| 804 | rc = qla2x00_get_id_list(vha, gid_list, gid_list_dma, &entries); |
| 805 | if (rc != QLA_SUCCESS) { |
| 806 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, |
| 807 | "qla_target(%d): get_id_list() failed: %x\n", |
| 808 | vha->vp_idx, rc); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 809 | res = -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 810 | goto out_free_id_list; |
| 811 | } |
| 812 | |
| 813 | id_iter = (char *)gid_list; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 814 | res = -ENOENT; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 815 | for (i = 0; i < entries; i++) { |
| 816 | struct gid_list_info *gid = (struct gid_list_info *)id_iter; |
| 817 | if ((gid->al_pa == s_id[2]) && |
| 818 | (gid->area == s_id[1]) && |
| 819 | (gid->domain == s_id[0])) { |
| 820 | *loop_id = le16_to_cpu(gid->loop_id); |
| 821 | res = 0; |
| 822 | break; |
| 823 | } |
| 824 | id_iter += ha->gid_list_info_size; |
| 825 | } |
| 826 | |
| 827 | out_free_id_list: |
| 828 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 829 | gid_list, gid_list_dma); |
| 830 | return res; |
| 831 | } |
| 832 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 833 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 834 | static void qlt_undelete_sess(struct qla_tgt_sess *sess) |
| 835 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 836 | BUG_ON(sess->deleted != QLA_SESS_DELETION_PENDING); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 837 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 838 | list_del_init(&sess->del_list_entry); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 839 | sess->deleted = 0; |
| 840 | } |
| 841 | |
| 842 | static void qlt_del_sess_work_fn(struct delayed_work *work) |
| 843 | { |
| 844 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, |
| 845 | sess_del_work); |
| 846 | struct scsi_qla_host *vha = tgt->vha; |
| 847 | struct qla_hw_data *ha = vha->hw; |
| 848 | struct qla_tgt_sess *sess; |
Shivaram Upadhyayula | 63832aa | 2013-12-10 16:06:40 +0530 | [diff] [blame] | 849 | unsigned long flags, elapsed; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 850 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 851 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 852 | while (!list_empty(&tgt->del_sess_list)) { |
| 853 | sess = list_entry(tgt->del_sess_list.next, typeof(*sess), |
| 854 | del_list_entry); |
Shivaram Upadhyayula | 63832aa | 2013-12-10 16:06:40 +0530 | [diff] [blame] | 855 | elapsed = jiffies; |
| 856 | if (time_after_eq(elapsed, sess->expires)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 857 | /* No turning back */ |
| 858 | list_del_init(&sess->del_list_entry); |
| 859 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 860 | |
Jörn Engel | 08234e3 | 2013-06-12 16:27:54 -0400 | [diff] [blame] | 861 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004, |
| 862 | "Timeout: sess %p about to be deleted\n", |
| 863 | sess); |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 864 | if (sess->se_sess) |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 865 | ha->tgt.tgt_ops->shutdown_sess(sess); |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 866 | qlt_put_sess(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 867 | } else { |
| 868 | schedule_delayed_work(&tgt->sess_del_work, |
Shivaram Upadhyayula | 63832aa | 2013-12-10 16:06:40 +0530 | [diff] [blame] | 869 | sess->expires - elapsed); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 870 | break; |
| 871 | } |
| 872 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 873 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | /* |
| 877 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. |
| 878 | * Caller must put it. |
| 879 | */ |
| 880 | static struct qla_tgt_sess *qlt_create_sess( |
| 881 | struct scsi_qla_host *vha, |
| 882 | fc_port_t *fcport, |
| 883 | bool local) |
| 884 | { |
| 885 | struct qla_hw_data *ha = vha->hw; |
| 886 | struct qla_tgt_sess *sess; |
| 887 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 888 | |
| 889 | /* Check to avoid double sessions */ |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 890 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 891 | list_for_each_entry(sess, &vha->vha_tgt.qla_tgt->sess_list, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 892 | sess_list_entry) { |
| 893 | if (!memcmp(sess->port_name, fcport->port_name, WWN_SIZE)) { |
| 894 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf005, |
| 895 | "Double sess %p found (s_id %x:%x:%x, " |
| 896 | "loop_id %d), updating to d_id %x:%x:%x, " |
| 897 | "loop_id %d", sess, sess->s_id.b.domain, |
| 898 | sess->s_id.b.al_pa, sess->s_id.b.area, |
| 899 | sess->loop_id, fcport->d_id.b.domain, |
| 900 | fcport->d_id.b.al_pa, fcport->d_id.b.area, |
| 901 | fcport->loop_id); |
| 902 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 903 | /* Cannot undelete at this point */ |
| 904 | if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 905 | spin_unlock_irqrestore(&ha->tgt.sess_lock, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 906 | flags); |
| 907 | return NULL; |
| 908 | } |
| 909 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 910 | if (sess->deleted) |
| 911 | qlt_undelete_sess(sess); |
| 912 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 913 | if (!sess->se_sess) { |
| 914 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 915 | &sess->port_name[0], sess) < 0) { |
| 916 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 917 | return NULL; |
| 918 | } |
| 919 | } |
| 920 | |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 921 | kref_get(&sess->sess_kref); |
Roland Dreier | c8292d1 | 2012-10-11 13:41:32 -0700 | [diff] [blame] | 922 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, fcport->loop_id, |
| 923 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
| 924 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 925 | if (sess->local && !local) |
| 926 | sess->local = 0; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 927 | |
| 928 | qlt_do_generation_tick(vha, &sess->generation); |
| 929 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 930 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 931 | |
| 932 | return sess; |
| 933 | } |
| 934 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 935 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 936 | |
| 937 | sess = kzalloc(sizeof(*sess), GFP_KERNEL); |
| 938 | if (!sess) { |
| 939 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04a, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 940 | "qla_target(%u): session allocation failed, all commands " |
| 941 | "from port %8phC will be refused", vha->vp_idx, |
| 942 | fcport->port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 943 | |
| 944 | return NULL; |
| 945 | } |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 946 | sess->tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 947 | sess->vha = vha; |
| 948 | sess->s_id = fcport->d_id; |
| 949 | sess->loop_id = fcport->loop_id; |
| 950 | sess->local = local; |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 951 | kref_init(&sess->sess_kref); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 952 | INIT_LIST_HEAD(&sess->del_list_entry); |
| 953 | |
| 954 | /* Under normal circumstances we want to logout from firmware when |
| 955 | * session eventually ends and release corresponding nport handle. |
| 956 | * In the exception cases (e.g. when new PLOGI is waiting) corresponding |
| 957 | * code will adjust these flags as necessary. */ |
| 958 | sess->logout_on_delete = 1; |
| 959 | sess->keep_nport_handle = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 960 | |
| 961 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, |
| 962 | "Adding sess %p to tgt %p via ->check_initiator_node_acl()\n", |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 963 | sess, vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 964 | |
Roland Dreier | c8292d1 | 2012-10-11 13:41:32 -0700 | [diff] [blame] | 965 | sess->conf_compl_supported = (fcport->flags & FCF_CONF_COMP_SUPPORTED); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 966 | BUILD_BUG_ON(sizeof(sess->port_name) != sizeof(fcport->port_name)); |
| 967 | memcpy(sess->port_name, fcport->port_name, sizeof(sess->port_name)); |
| 968 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 969 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 970 | list_add_tail(&sess->sess_list_entry, &vha->vha_tgt.qla_tgt->sess_list); |
| 971 | vha->vha_tgt.qla_tgt->sess_count++; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 972 | qlt_do_generation_tick(vha, &sess->generation); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 973 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 974 | |
| 975 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 976 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
| 977 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", |
| 978 | vha->vp_idx, local ? "local " : "", fcport->port_name, |
| 979 | fcport->loop_id, sess->s_id.b.domain, sess->s_id.b.area, |
| 980 | sess->s_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 981 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 982 | /* |
| 983 | * Determine if this fc_port->port_name is allowed to access |
| 984 | * target mode using explict NodeACLs+MappedLUNs, or using |
| 985 | * TPG demo mode. If this is successful a target mode FC nexus |
| 986 | * is created. |
| 987 | */ |
| 988 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 989 | &fcport->port_name[0], sess) < 0) { |
| 990 | return NULL; |
| 991 | } else { |
| 992 | /* |
| 993 | * Take an extra reference to ->sess_kref here to handle qla_tgt_sess |
| 994 | * access across ->tgt.sess_lock reaquire. |
| 995 | */ |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 996 | kref_get(&sess->sess_kref); |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 997 | } |
| 998 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 999 | return sess; |
| 1000 | } |
| 1001 | |
| 1002 | /* |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1003 | * Called from qla2x00_reg_remote_port() |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1004 | */ |
| 1005 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 1006 | { |
| 1007 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1008 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1009 | struct qla_tgt_sess *sess; |
| 1010 | unsigned long flags; |
| 1011 | |
| 1012 | if (!vha->hw->tgt.tgt_ops) |
| 1013 | return; |
| 1014 | |
| 1015 | if (!tgt || (fcport->port_type != FCT_INITIATOR)) |
| 1016 | return; |
| 1017 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1018 | if (qla_ini_mode_enabled(vha)) |
| 1019 | return; |
| 1020 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1021 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1022 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1023 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1024 | return; |
| 1025 | } |
| 1026 | sess = qlt_find_sess_by_port_name(tgt, fcport->port_name); |
| 1027 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1028 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1029 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1030 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1031 | sess = qlt_create_sess(vha, fcport, false); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1032 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1033 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1034 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1035 | } else if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
| 1036 | /* Point of no return */ |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1037 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1038 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1039 | } else { |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 1040 | kref_get(&sess->sess_kref); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1041 | |
| 1042 | if (sess->deleted) { |
| 1043 | qlt_undelete_sess(sess); |
| 1044 | |
| 1045 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1046 | "qla_target(%u): %ssession for port %8phC " |
| 1047 | "(loop ID %d) reappeared\n", vha->vp_idx, |
| 1048 | sess->local ? "local " : "", sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1049 | sess->loop_id); |
| 1050 | |
| 1051 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, |
| 1052 | "Reappeared sess %p\n", sess); |
| 1053 | } |
Roland Dreier | c8292d1 | 2012-10-11 13:41:32 -0700 | [diff] [blame] | 1054 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, fcport->loop_id, |
| 1055 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | if (sess && sess->local) { |
| 1059 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, |
| 1060 | "qla_target(%u): local session for " |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1061 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
| 1062 | fcport->port_name, sess->loop_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1063 | sess->local = 0; |
| 1064 | } |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 1065 | qlt_put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1066 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1067 | } |
| 1068 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1069 | /* |
| 1070 | * max_gen - specifies maximum session generation |
| 1071 | * at which this deletion requestion is still valid |
| 1072 | */ |
| 1073 | void |
| 1074 | 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] | 1075 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1076 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1077 | struct qla_tgt_sess *sess; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1078 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1079 | |
| 1080 | if (!vha->hw->tgt.tgt_ops) |
| 1081 | return; |
| 1082 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1083 | if (!tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1084 | return; |
| 1085 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1086 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1087 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1088 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1089 | return; |
| 1090 | } |
| 1091 | sess = qlt_find_sess_by_port_name(tgt, fcport->port_name); |
| 1092 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1093 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1094 | return; |
| 1095 | } |
| 1096 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1097 | if (max_gen - sess->generation < 0) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1098 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1099 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092, |
| 1100 | "Ignoring stale deletion request for se_sess %p / sess %p" |
| 1101 | " for port %8phC, req_gen %d, sess_gen %d\n", |
| 1102 | sess->se_sess, sess, sess->port_name, max_gen, |
| 1103 | sess->generation); |
| 1104 | return; |
| 1105 | } |
| 1106 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1107 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); |
| 1108 | |
| 1109 | sess->local = 1; |
| 1110 | qlt_schedule_sess_for_deletion(sess, false); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1111 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) |
| 1115 | { |
| 1116 | struct qla_hw_data *ha = tgt->ha; |
| 1117 | unsigned long flags; |
| 1118 | int res; |
| 1119 | /* |
| 1120 | * We need to protect against race, when tgt is freed before or |
| 1121 | * inside wake_up() |
| 1122 | */ |
| 1123 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1124 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, |
| 1125 | "tgt %p, empty(sess_list)=%d sess_count=%d\n", |
| 1126 | tgt, list_empty(&tgt->sess_list), tgt->sess_count); |
| 1127 | res = (tgt->sess_count == 0); |
| 1128 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1129 | |
| 1130 | return res; |
| 1131 | } |
| 1132 | |
| 1133 | /* Called by tcm_qla2xxx configfs code */ |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1134 | int qlt_stop_phase1(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1135 | { |
| 1136 | struct scsi_qla_host *vha = tgt->vha; |
| 1137 | struct qla_hw_data *ha = tgt->ha; |
| 1138 | unsigned long flags; |
| 1139 | |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1140 | mutex_lock(&qla_tgt_mutex); |
| 1141 | if (!vha->fc_vport) { |
| 1142 | struct Scsi_Host *sh = vha->host; |
| 1143 | struct fc_host_attrs *fc_host = shost_to_fc_host(sh); |
| 1144 | bool npiv_vports; |
| 1145 | |
| 1146 | spin_lock_irqsave(sh->host_lock, flags); |
| 1147 | npiv_vports = (fc_host->npiv_vports_inuse); |
| 1148 | spin_unlock_irqrestore(sh->host_lock, flags); |
| 1149 | |
| 1150 | if (npiv_vports) { |
| 1151 | mutex_unlock(&qla_tgt_mutex); |
| 1152 | return -EPERM; |
| 1153 | } |
| 1154 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1155 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
| 1156 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, |
| 1157 | "Already in tgt->tgt_stop or tgt_stopped state\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1158 | mutex_unlock(&qla_tgt_mutex); |
| 1159 | return -EPERM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | ql_dbg(ql_dbg_tgt, vha, 0xe003, "Stopping target for host %ld(%p)\n", |
| 1163 | vha->host_no, vha); |
| 1164 | /* |
| 1165 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. |
| 1166 | * Lock is needed, because we still can get an incoming packet. |
| 1167 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1168 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1169 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1170 | tgt->tgt_stop = 1; |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1171 | qlt_clear_tgt_db(tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1172 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1173 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1174 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1175 | |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1176 | flush_delayed_work(&tgt->sess_del_work); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1177 | |
| 1178 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, |
| 1179 | "Waiting for sess works (tgt %p)", tgt); |
| 1180 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1181 | while (!list_empty(&tgt->sess_works_list)) { |
| 1182 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1183 | flush_scheduled_work(); |
| 1184 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1185 | } |
| 1186 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1187 | |
| 1188 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, |
| 1189 | "Waiting for tgt %p: list_empty(sess_list)=%d " |
| 1190 | "sess_count=%d\n", tgt, list_empty(&tgt->sess_list), |
| 1191 | tgt->sess_count); |
| 1192 | |
| 1193 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); |
| 1194 | |
| 1195 | /* Big hammer */ |
| 1196 | if (!ha->flags.host_shutting_down && qla_tgt_mode_enabled(vha)) |
| 1197 | qlt_disable_vha(vha); |
| 1198 | |
| 1199 | /* Wait for sessions to clear out (just in case) */ |
| 1200 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1201 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1202 | } |
| 1203 | EXPORT_SYMBOL(qlt_stop_phase1); |
| 1204 | |
| 1205 | /* Called by tcm_qla2xxx configfs code */ |
| 1206 | void qlt_stop_phase2(struct qla_tgt *tgt) |
| 1207 | { |
| 1208 | struct qla_hw_data *ha = tgt->ha; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1209 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1210 | unsigned long flags; |
| 1211 | |
| 1212 | if (tgt->tgt_stopped) { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1213 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1214 | "Already in tgt->tgt_stopped state\n"); |
| 1215 | dump_stack(); |
| 1216 | return; |
| 1217 | } |
| 1218 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1219 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1220 | "Waiting for %d IRQ commands to complete (tgt %p)", |
| 1221 | tgt->irq_cmd_count, tgt); |
| 1222 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1223 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1224 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 1225 | while ((tgt->irq_cmd_count != 0) || (tgt->atio_irq_cmd_count != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1226 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1227 | udelay(2); |
| 1228 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1229 | } |
| 1230 | tgt->tgt_stop = 0; |
| 1231 | tgt->tgt_stopped = 1; |
| 1232 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1233 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1234 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1235 | 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] | 1236 | tgt); |
| 1237 | } |
| 1238 | EXPORT_SYMBOL(qlt_stop_phase2); |
| 1239 | |
| 1240 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1241 | static void qlt_release(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1242 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1243 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1244 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1245 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1246 | qlt_stop_phase2(tgt); |
| 1247 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1248 | vha->vha_tgt.qla_tgt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1249 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1250 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1251 | "Release of tgt %p finished\n", tgt); |
| 1252 | |
| 1253 | kfree(tgt); |
| 1254 | } |
| 1255 | |
| 1256 | /* ha->hardware_lock supposed to be held on entry */ |
| 1257 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, |
| 1258 | const void *param, unsigned int param_size) |
| 1259 | { |
| 1260 | struct qla_tgt_sess_work_param *prm; |
| 1261 | unsigned long flags; |
| 1262 | |
| 1263 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); |
| 1264 | if (!prm) { |
| 1265 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, |
| 1266 | "qla_target(%d): Unable to create session " |
| 1267 | "work, command will be refused", 0); |
| 1268 | return -ENOMEM; |
| 1269 | } |
| 1270 | |
| 1271 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, |
| 1272 | "Scheduling work (type %d, prm %p)" |
| 1273 | " to find session for param %p (size %d, tgt %p)\n", |
| 1274 | type, prm, param, param_size, tgt); |
| 1275 | |
| 1276 | prm->type = type; |
| 1277 | memcpy(&prm->tm_iocb, param, param_size); |
| 1278 | |
| 1279 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1280 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); |
| 1281 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1282 | |
| 1283 | schedule_work(&tgt->sess_work); |
| 1284 | |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
| 1288 | /* |
| 1289 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1290 | */ |
| 1291 | static void qlt_send_notify_ack(struct scsi_qla_host *vha, |
| 1292 | struct imm_ntfy_from_isp *ntfy, |
| 1293 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 1294 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) |
| 1295 | { |
| 1296 | struct qla_hw_data *ha = vha->hw; |
| 1297 | request_t *pkt; |
| 1298 | struct nack_to_isp *nack; |
| 1299 | |
| 1300 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); |
| 1301 | |
| 1302 | /* Send marker if required */ |
| 1303 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1304 | return; |
| 1305 | |
| 1306 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
| 1307 | if (!pkt) { |
| 1308 | ql_dbg(ql_dbg_tgt, vha, 0xe049, |
| 1309 | "qla_target(%d): %s failed: unable to allocate " |
| 1310 | "request packet\n", vha->vp_idx, __func__); |
| 1311 | return; |
| 1312 | } |
| 1313 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1314 | if (vha->vha_tgt.qla_tgt != NULL) |
| 1315 | vha->vha_tgt.qla_tgt->notify_ack_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1316 | |
| 1317 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 1318 | pkt->entry_count = 1; |
| 1319 | |
| 1320 | nack = (struct nack_to_isp *)pkt; |
| 1321 | nack->ox_id = ntfy->ox_id; |
| 1322 | |
| 1323 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 1324 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 1325 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1326 | cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1327 | } |
| 1328 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 1329 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 1330 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1331 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1332 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 1333 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 1334 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 1335 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); |
| 1336 | nack->u.isp24.srr_reject_code = srr_reject_code; |
| 1337 | nack->u.isp24.srr_reject_code_expl = srr_explan; |
| 1338 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 1339 | |
| 1340 | ql_dbg(ql_dbg_tgt, vha, 0xe005, |
| 1341 | "qla_target(%d): Sending 24xx Notify Ack %d\n", |
| 1342 | vha->vp_idx, nack->u.isp24.status); |
| 1343 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1344 | /* Memory Barrier */ |
| 1345 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1346 | qla2x00_start_iocbs(vha, vha->req); |
| 1347 | } |
| 1348 | |
| 1349 | /* |
| 1350 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1351 | */ |
| 1352 | static void qlt_24xx_send_abts_resp(struct scsi_qla_host *vha, |
| 1353 | struct abts_recv_from_24xx *abts, uint32_t status, |
| 1354 | bool ids_reversed) |
| 1355 | { |
| 1356 | struct qla_hw_data *ha = vha->hw; |
| 1357 | struct abts_resp_to_24xx *resp; |
| 1358 | uint32_t f_ctl; |
| 1359 | uint8_t *p; |
| 1360 | |
| 1361 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1362 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", |
| 1363 | ha, abts, status); |
| 1364 | |
| 1365 | /* Send marker if required */ |
| 1366 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1367 | return; |
| 1368 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1369 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1370 | if (!resp) { |
| 1371 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1372 | "qla_target(%d): %s failed: unable to allocate " |
| 1373 | "request packet", vha->vp_idx, __func__); |
| 1374 | return; |
| 1375 | } |
| 1376 | |
| 1377 | resp->entry_type = ABTS_RESP_24XX; |
| 1378 | resp->entry_count = 1; |
| 1379 | resp->nport_handle = abts->nport_handle; |
| 1380 | resp->vp_index = vha->vp_idx; |
| 1381 | resp->sof_type = abts->sof_type; |
| 1382 | resp->exchange_address = abts->exchange_address; |
| 1383 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1384 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1385 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1386 | F_CTL_SEQ_INITIATIVE); |
| 1387 | p = (uint8_t *)&f_ctl; |
| 1388 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1389 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1390 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1391 | if (ids_reversed) { |
| 1392 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1393 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1394 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1395 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1396 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1397 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1398 | } else { |
| 1399 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1400 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1401 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1402 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1403 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1404 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1405 | } |
| 1406 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1407 | if (status == FCP_TMF_CMPL) { |
| 1408 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1409 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1410 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1411 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1412 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1413 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1414 | } else { |
| 1415 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1416 | resp->payload.ba_rjt.reason_code = |
| 1417 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1418 | /* Other bytes are zero */ |
| 1419 | } |
| 1420 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1421 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1422 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1423 | /* Memory Barrier */ |
| 1424 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1425 | qla2x00_start_iocbs(vha, vha->req); |
| 1426 | } |
| 1427 | |
| 1428 | /* |
| 1429 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1430 | */ |
| 1431 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, |
| 1432 | struct abts_resp_from_24xx_fw *entry) |
| 1433 | { |
| 1434 | struct ctio7_to_24xx *ctio; |
| 1435 | |
| 1436 | ql_dbg(ql_dbg_tgt, vha, 0xe007, |
| 1437 | "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha->hw); |
| 1438 | /* Send marker if required */ |
| 1439 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1440 | return; |
| 1441 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1442 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1443 | if (ctio == NULL) { |
| 1444 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, |
| 1445 | "qla_target(%d): %s failed: unable to allocate " |
| 1446 | "request packet\n", vha->vp_idx, __func__); |
| 1447 | return; |
| 1448 | } |
| 1449 | |
| 1450 | /* |
| 1451 | * We've got on entrance firmware's response on by us generated |
| 1452 | * ABTS response. So, in it ID fields are reversed. |
| 1453 | */ |
| 1454 | |
| 1455 | ctio->entry_type = CTIO_TYPE7; |
| 1456 | ctio->entry_count = 1; |
| 1457 | ctio->nport_handle = entry->nport_handle; |
| 1458 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1459 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1460 | ctio->vp_index = vha->vp_idx; |
| 1461 | ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0]; |
| 1462 | ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1]; |
| 1463 | ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2]; |
| 1464 | ctio->exchange_addr = entry->exchange_addr_to_abort; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1465 | ctio->u.status1.flags = cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | |
| 1466 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1467 | 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] | 1468 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1469 | /* Memory Barrier */ |
| 1470 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1471 | qla2x00_start_iocbs(vha, vha->req); |
| 1472 | |
| 1473 | qlt_24xx_send_abts_resp(vha, (struct abts_recv_from_24xx *)entry, |
| 1474 | FCP_TMF_CMPL, true); |
| 1475 | } |
| 1476 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1477 | static int abort_cmd_for_tag(struct scsi_qla_host *vha, uint32_t tag) |
| 1478 | { |
| 1479 | struct qla_tgt_sess_op *op; |
| 1480 | struct qla_tgt_cmd *cmd; |
| 1481 | |
| 1482 | spin_lock(&vha->cmd_list_lock); |
| 1483 | |
| 1484 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1485 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1486 | op->aborted = true; |
| 1487 | spin_unlock(&vha->cmd_list_lock); |
| 1488 | return 1; |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1493 | if (tag == cmd->atio.u.isp24.exchange_addr) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1494 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1495 | spin_unlock(&vha->cmd_list_lock); |
| 1496 | return 1; |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | spin_unlock(&vha->cmd_list_lock); |
| 1501 | return 0; |
| 1502 | } |
| 1503 | |
| 1504 | /* drop cmds for the given lun |
| 1505 | * XXX only looks for cmds on the port through which lun reset was recieved |
| 1506 | * XXX does not go through the list of other port (which may have cmds |
| 1507 | * for the same lun) |
| 1508 | */ |
| 1509 | static void abort_cmds_for_lun(struct scsi_qla_host *vha, |
| 1510 | uint32_t lun, uint8_t *s_id) |
| 1511 | { |
| 1512 | struct qla_tgt_sess_op *op; |
| 1513 | struct qla_tgt_cmd *cmd; |
| 1514 | uint32_t key; |
| 1515 | |
| 1516 | key = sid_to_key(s_id); |
| 1517 | spin_lock(&vha->cmd_list_lock); |
| 1518 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1519 | uint32_t op_key; |
| 1520 | uint32_t op_lun; |
| 1521 | |
| 1522 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1523 | op_lun = scsilun_to_int( |
| 1524 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1525 | if (op_key == key && op_lun == lun) |
| 1526 | op->aborted = true; |
| 1527 | } |
| 1528 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1529 | uint32_t cmd_key; |
| 1530 | uint32_t cmd_lun; |
| 1531 | |
| 1532 | cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 1533 | cmd_lun = scsilun_to_int( |
| 1534 | (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); |
| 1535 | if (cmd_key == key && cmd_lun == lun) |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1536 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1537 | } |
| 1538 | spin_unlock(&vha->cmd_list_lock); |
| 1539 | } |
| 1540 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1541 | /* ha->hardware_lock supposed to be held on entry */ |
| 1542 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 1543 | struct abts_recv_from_24xx *abts, struct qla_tgt_sess *sess) |
| 1544 | { |
| 1545 | struct qla_hw_data *ha = vha->hw; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1546 | struct se_session *se_sess = sess->se_sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1547 | struct qla_tgt_mgmt_cmd *mcmd; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1548 | struct se_cmd *se_cmd; |
| 1549 | u32 lun = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1550 | int rc; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1551 | bool found_lun = false; |
| 1552 | |
| 1553 | spin_lock(&se_sess->sess_cmd_lock); |
| 1554 | list_for_each_entry(se_cmd, &se_sess->sess_cmd_list, se_cmd_list) { |
| 1555 | struct qla_tgt_cmd *cmd = |
| 1556 | container_of(se_cmd, struct qla_tgt_cmd, se_cmd); |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 1557 | if (se_cmd->tag == abts->exchange_addr_to_abort) { |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1558 | lun = cmd->unpacked_lun; |
| 1559 | found_lun = true; |
| 1560 | break; |
| 1561 | } |
| 1562 | } |
| 1563 | spin_unlock(&se_sess->sess_cmd_lock); |
| 1564 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1565 | /* cmd not in LIO lists, look in qla list */ |
| 1566 | if (!found_lun) { |
| 1567 | if (abort_cmd_for_tag(vha, abts->exchange_addr_to_abort)) { |
| 1568 | /* send TASK_ABORT response immediately */ |
| 1569 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_CMPL, false); |
| 1570 | return 0; |
| 1571 | } else { |
| 1572 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf081, |
| 1573 | "unable to find cmd in driver or LIO for tag 0x%x\n", |
| 1574 | abts->exchange_addr_to_abort); |
| 1575 | return -ENOENT; |
| 1576 | } |
| 1577 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1578 | |
| 1579 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, |
| 1580 | "qla_target(%d): task abort (tag=%d)\n", |
| 1581 | vha->vp_idx, abts->exchange_addr_to_abort); |
| 1582 | |
| 1583 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 1584 | if (mcmd == NULL) { |
| 1585 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, |
| 1586 | "qla_target(%d): %s: Allocation of ABORT cmd failed", |
| 1587 | vha->vp_idx, __func__); |
| 1588 | return -ENOMEM; |
| 1589 | } |
| 1590 | memset(mcmd, 0, sizeof(*mcmd)); |
| 1591 | |
| 1592 | mcmd->sess = sess; |
| 1593 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); |
Arun Easi | 80187f8 | 2014-09-25 06:14:53 -0400 | [diff] [blame] | 1594 | mcmd->reset_count = vha->hw->chip_reset; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1595 | |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1596 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, lun, TMR_ABORT_TASK, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1597 | abts->exchange_addr_to_abort); |
| 1598 | if (rc != 0) { |
| 1599 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf052, |
| 1600 | "qla_target(%d): tgt_ops->handle_tmr()" |
| 1601 | " failed: %d", vha->vp_idx, rc); |
| 1602 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 1603 | return -EFAULT; |
| 1604 | } |
| 1605 | |
| 1606 | return 0; |
| 1607 | } |
| 1608 | |
| 1609 | /* |
| 1610 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1611 | */ |
| 1612 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 1613 | struct abts_recv_from_24xx *abts) |
| 1614 | { |
| 1615 | struct qla_hw_data *ha = vha->hw; |
| 1616 | struct qla_tgt_sess *sess; |
| 1617 | uint32_t tag = abts->exchange_addr_to_abort; |
| 1618 | uint8_t s_id[3]; |
| 1619 | int rc; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1620 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1621 | |
| 1622 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { |
| 1623 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, |
| 1624 | "qla_target(%d): ABTS: Abort Sequence not " |
| 1625 | "supported\n", vha->vp_idx); |
| 1626 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1627 | return; |
| 1628 | } |
| 1629 | |
| 1630 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { |
| 1631 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, |
| 1632 | "qla_target(%d): ABTS: Unknown Exchange " |
| 1633 | "Address received\n", vha->vp_idx); |
| 1634 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1635 | return; |
| 1636 | } |
| 1637 | |
| 1638 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, |
| 1639 | "qla_target(%d): task abort (s_id=%x:%x:%x, " |
| 1640 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2], |
| 1641 | abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag, |
| 1642 | le32_to_cpu(abts->fcp_hdr_le.parameter)); |
| 1643 | |
| 1644 | s_id[0] = abts->fcp_hdr_le.s_id[2]; |
| 1645 | s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1646 | s_id[2] = abts->fcp_hdr_le.s_id[0]; |
| 1647 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1648 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1649 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 1650 | if (!sess) { |
| 1651 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, |
| 1652 | "qla_target(%d): task abort for non-existant session\n", |
| 1653 | vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1654 | rc = qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1655 | QLA_TGT_SESS_WORK_ABORT, abts, sizeof(*abts)); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1656 | |
| 1657 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1658 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1659 | if (rc != 0) { |
| 1660 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, |
| 1661 | false); |
| 1662 | } |
| 1663 | return; |
| 1664 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1665 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1666 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1667 | |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 1668 | if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
| 1669 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1670 | return; |
| 1671 | } |
| 1672 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1673 | rc = __qlt_24xx_handle_abts(vha, abts, sess); |
| 1674 | if (rc != 0) { |
| 1675 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, |
| 1676 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", |
| 1677 | vha->vp_idx, rc); |
| 1678 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1679 | return; |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | /* |
| 1684 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1685 | */ |
| 1686 | static void qlt_24xx_send_task_mgmt_ctio(struct scsi_qla_host *ha, |
| 1687 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) |
| 1688 | { |
| 1689 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; |
| 1690 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1691 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1692 | |
| 1693 | ql_dbg(ql_dbg_tgt, ha, 0xe008, |
| 1694 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", |
| 1695 | ha, atio, resp_code); |
| 1696 | |
| 1697 | /* Send marker if required */ |
| 1698 | if (qlt_issue_marker(ha, 1) != QLA_SUCCESS) |
| 1699 | return; |
| 1700 | |
| 1701 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(ha, NULL); |
| 1702 | if (ctio == NULL) { |
| 1703 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, |
| 1704 | "qla_target(%d): %s failed: unable to allocate " |
| 1705 | "request packet\n", ha->vp_idx, __func__); |
| 1706 | return; |
| 1707 | } |
| 1708 | |
| 1709 | ctio->entry_type = CTIO_TYPE7; |
| 1710 | ctio->entry_count = 1; |
| 1711 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 1712 | ctio->nport_handle = mcmd->sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1713 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1714 | ctio->vp_index = ha->vp_idx; |
| 1715 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 1716 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 1717 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 1718 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
| 1719 | ctio->u.status1.flags = (atio->u.isp24.attr << 9) | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1720 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1721 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 1722 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1723 | ctio->u.status1.scsi_status = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1724 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); |
| 1725 | ctio->u.status1.response_len = cpu_to_le16(8); |
Roland Dreier | e4b11b8 | 2012-09-18 15:10:56 -0700 | [diff] [blame] | 1726 | ctio->u.status1.sense_data[0] = resp_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1727 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1728 | /* Memory Barrier */ |
| 1729 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1730 | qla2x00_start_iocbs(ha, ha->req); |
| 1731 | } |
| 1732 | |
| 1733 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) |
| 1734 | { |
| 1735 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 1736 | } |
| 1737 | EXPORT_SYMBOL(qlt_free_mcmd); |
| 1738 | |
| 1739 | /* callback from target fabric module code */ |
| 1740 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) |
| 1741 | { |
| 1742 | struct scsi_qla_host *vha = mcmd->sess->vha; |
| 1743 | struct qla_hw_data *ha = vha->hw; |
| 1744 | unsigned long flags; |
| 1745 | |
| 1746 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, |
| 1747 | "TM response mcmd (%p) status %#x state %#x", |
| 1748 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); |
| 1749 | |
| 1750 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1751 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 1752 | if (!vha->flags.online || mcmd->reset_count != ha->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1753 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 1754 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1755 | * previous life, just abort the processing. |
| 1756 | */ |
| 1757 | ql_dbg(ql_dbg_async, vha, 0xe100, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 1758 | "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 1759 | vha->flags.online, qla2x00_reset_active(vha), |
| 1760 | mcmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1761 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 1762 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1763 | return; |
| 1764 | } |
| 1765 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1766 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) |
| 1767 | qlt_send_notify_ack(vha, &mcmd->orig_iocb.imm_ntfy, |
| 1768 | 0, 0, 0, 0, 0, 0); |
| 1769 | else { |
Swapnil Nagle | d7236ac | 2016-02-04 11:45:17 -0500 | [diff] [blame] | 1770 | if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1771 | qlt_24xx_send_abts_resp(vha, &mcmd->orig_iocb.abts, |
| 1772 | mcmd->fc_tm_rsp, false); |
| 1773 | else |
| 1774 | qlt_24xx_send_task_mgmt_ctio(vha, mcmd, |
| 1775 | mcmd->fc_tm_rsp); |
| 1776 | } |
| 1777 | /* |
| 1778 | * Make the callback for ->free_mcmd() to queue_work() and invoke |
| 1779 | * target_put_sess_cmd() to drop cmd_kref to 1. The final |
| 1780 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() |
| 1781 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd |
| 1782 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> |
| 1783 | * qlt_xmit_tm_rsp() returns here.. |
| 1784 | */ |
| 1785 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 1786 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1787 | } |
| 1788 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); |
| 1789 | |
| 1790 | /* No locks */ |
| 1791 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) |
| 1792 | { |
| 1793 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 1794 | |
| 1795 | BUG_ON(cmd->sg_cnt == 0); |
| 1796 | |
| 1797 | prm->sg = (struct scatterlist *)cmd->sg; |
| 1798 | prm->seg_cnt = pci_map_sg(prm->tgt->ha->pdev, cmd->sg, |
| 1799 | cmd->sg_cnt, cmd->dma_data_direction); |
| 1800 | if (unlikely(prm->seg_cnt == 0)) |
| 1801 | goto out_err; |
| 1802 | |
| 1803 | prm->cmd->sg_mapped = 1; |
| 1804 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1805 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
| 1806 | /* |
| 1807 | * If greater than four sg entries then we need to allocate |
| 1808 | * the continuation entries |
| 1809 | */ |
| 1810 | if (prm->seg_cnt > prm->tgt->datasegs_per_cmd) |
| 1811 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - |
| 1812 | prm->tgt->datasegs_per_cmd, |
| 1813 | prm->tgt->datasegs_per_cont); |
| 1814 | } else { |
| 1815 | /* DIF */ |
| 1816 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 1817 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 1818 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); |
| 1819 | prm->tot_dsds = prm->seg_cnt; |
| 1820 | } else |
| 1821 | prm->tot_dsds = prm->seg_cnt; |
| 1822 | |
| 1823 | if (cmd->prot_sg_cnt) { |
| 1824 | prm->prot_sg = cmd->prot_sg; |
| 1825 | prm->prot_seg_cnt = pci_map_sg(prm->tgt->ha->pdev, |
| 1826 | cmd->prot_sg, cmd->prot_sg_cnt, |
| 1827 | cmd->dma_data_direction); |
| 1828 | if (unlikely(prm->prot_seg_cnt == 0)) |
| 1829 | goto out_err; |
| 1830 | |
| 1831 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 1832 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 1833 | /* Dif Bundling not support here */ |
| 1834 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, |
| 1835 | cmd->blk_sz); |
| 1836 | prm->tot_dsds += prm->prot_seg_cnt; |
| 1837 | } else |
| 1838 | prm->tot_dsds += prm->prot_seg_cnt; |
| 1839 | } |
| 1840 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1841 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1842 | return 0; |
| 1843 | |
| 1844 | out_err: |
| 1845 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe04d, |
| 1846 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", |
| 1847 | 0, prm->cmd->sg_cnt); |
| 1848 | return -1; |
| 1849 | } |
| 1850 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 1851 | 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] | 1852 | { |
| 1853 | struct qla_hw_data *ha = vha->hw; |
| 1854 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 1855 | if (!cmd->sg_mapped) |
| 1856 | return; |
| 1857 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1858 | pci_unmap_sg(ha->pdev, cmd->sg, cmd->sg_cnt, cmd->dma_data_direction); |
| 1859 | cmd->sg_mapped = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1860 | |
| 1861 | if (cmd->prot_sg_cnt) |
| 1862 | pci_unmap_sg(ha->pdev, cmd->prot_sg, cmd->prot_sg_cnt, |
| 1863 | cmd->dma_data_direction); |
| 1864 | |
| 1865 | if (cmd->ctx_dsd_alloced) |
| 1866 | qla2x00_clean_dsd_pool(ha, NULL, cmd); |
| 1867 | |
| 1868 | if (cmd->ctx) |
| 1869 | 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] | 1870 | } |
| 1871 | |
| 1872 | static int qlt_check_reserve_free_req(struct scsi_qla_host *vha, |
| 1873 | uint32_t req_cnt) |
| 1874 | { |
Saurav Kashyap | d29fb73 | 2014-09-25 06:14:49 -0400 | [diff] [blame] | 1875 | uint32_t cnt, cnt_in; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1876 | |
| 1877 | if (vha->req->cnt < (req_cnt + 2)) { |
Arun Easi | 75554b6 | 2014-09-25 06:14:45 -0400 | [diff] [blame] | 1878 | cnt = (uint16_t)RD_REG_DWORD(vha->req->req_q_out); |
Saurav Kashyap | d29fb73 | 2014-09-25 06:14:49 -0400 | [diff] [blame] | 1879 | cnt_in = (uint16_t)RD_REG_DWORD(vha->req->req_q_in); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1880 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1881 | if (vha->req->ring_index < cnt) |
| 1882 | vha->req->cnt = cnt - vha->req->ring_index; |
| 1883 | else |
| 1884 | vha->req->cnt = vha->req->length - |
| 1885 | (vha->req->ring_index - cnt); |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 1886 | |
| 1887 | if (unlikely(vha->req->cnt < (req_cnt + 2))) { |
| 1888 | ql_dbg(ql_dbg_io, vha, 0x305a, |
| 1889 | "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", |
| 1890 | vha->vp_idx, vha->req->ring_index, |
| 1891 | vha->req->cnt, req_cnt, cnt, cnt_in, |
| 1892 | vha->req->length); |
| 1893 | return -EAGAIN; |
| 1894 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1895 | } |
| 1896 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1897 | vha->req->cnt -= req_cnt; |
| 1898 | |
| 1899 | return 0; |
| 1900 | } |
| 1901 | |
| 1902 | /* |
| 1903 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1904 | */ |
| 1905 | static inline void *qlt_get_req_pkt(struct scsi_qla_host *vha) |
| 1906 | { |
| 1907 | /* Adjust ring index. */ |
| 1908 | vha->req->ring_index++; |
| 1909 | if (vha->req->ring_index == vha->req->length) { |
| 1910 | vha->req->ring_index = 0; |
| 1911 | vha->req->ring_ptr = vha->req->ring; |
| 1912 | } else { |
| 1913 | vha->req->ring_ptr++; |
| 1914 | } |
| 1915 | return (cont_entry_t *)vha->req->ring_ptr; |
| 1916 | } |
| 1917 | |
| 1918 | /* ha->hardware_lock supposed to be held on entry */ |
| 1919 | static inline uint32_t qlt_make_handle(struct scsi_qla_host *vha) |
| 1920 | { |
| 1921 | struct qla_hw_data *ha = vha->hw; |
| 1922 | uint32_t h; |
| 1923 | |
| 1924 | h = ha->tgt.current_handle; |
| 1925 | /* always increment cmd handle */ |
| 1926 | do { |
| 1927 | ++h; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1928 | if (h > DEFAULT_OUTSTANDING_COMMANDS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1929 | h = 1; /* 0 is QLA_TGT_NULL_HANDLE */ |
| 1930 | if (h == ha->tgt.current_handle) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 1931 | ql_dbg(ql_dbg_io, vha, 0x305b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1932 | "qla_target(%d): Ran out of " |
| 1933 | "empty cmd slots in ha %p\n", vha->vp_idx, ha); |
| 1934 | h = QLA_TGT_NULL_HANDLE; |
| 1935 | break; |
| 1936 | } |
| 1937 | } while ((h == QLA_TGT_NULL_HANDLE) || |
| 1938 | (h == QLA_TGT_SKIP_HANDLE) || |
| 1939 | (ha->tgt.cmds[h-1] != NULL)); |
| 1940 | |
| 1941 | if (h != QLA_TGT_NULL_HANDLE) |
| 1942 | ha->tgt.current_handle = h; |
| 1943 | |
| 1944 | return h; |
| 1945 | } |
| 1946 | |
| 1947 | /* ha->hardware_lock supposed to be held on entry */ |
| 1948 | static int qlt_24xx_build_ctio_pkt(struct qla_tgt_prm *prm, |
| 1949 | struct scsi_qla_host *vha) |
| 1950 | { |
| 1951 | uint32_t h; |
| 1952 | struct ctio7_to_24xx *pkt; |
| 1953 | struct qla_hw_data *ha = vha->hw; |
| 1954 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1955 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1956 | |
| 1957 | pkt = (struct ctio7_to_24xx *)vha->req->ring_ptr; |
| 1958 | prm->pkt = pkt; |
| 1959 | memset(pkt, 0, sizeof(*pkt)); |
| 1960 | |
| 1961 | pkt->entry_type = CTIO_TYPE7; |
| 1962 | pkt->entry_count = (uint8_t)prm->req_cnt; |
| 1963 | pkt->vp_index = vha->vp_idx; |
| 1964 | |
| 1965 | h = qlt_make_handle(vha); |
| 1966 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 1967 | /* |
| 1968 | * CTIO type 7 from the firmware doesn't provide a way to |
| 1969 | * know the initiator's LOOP ID, hence we can't find |
| 1970 | * the session and, so, the command. |
| 1971 | */ |
| 1972 | return -EAGAIN; |
| 1973 | } else |
| 1974 | ha->tgt.cmds[h-1] = prm->cmd; |
| 1975 | |
| 1976 | pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK; |
| 1977 | pkt->nport_handle = prm->cmd->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1978 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1979 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 1980 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 1981 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 1982 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
| 1983 | pkt->u.status0.flags |= (atio->u.isp24.attr << 9); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1984 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 1985 | pkt->u.status0.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1986 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
| 1987 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1988 | return 0; |
| 1989 | } |
| 1990 | |
| 1991 | /* |
| 1992 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 1993 | * that there is sufficient amount of request entries to not drop it. |
| 1994 | */ |
| 1995 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm, |
| 1996 | struct scsi_qla_host *vha) |
| 1997 | { |
| 1998 | int cnt; |
| 1999 | uint32_t *dword_ptr; |
| 2000 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; |
| 2001 | |
| 2002 | /* Build continuation packets */ |
| 2003 | while (prm->seg_cnt > 0) { |
| 2004 | cont_a64_entry_t *cont_pkt64 = |
| 2005 | (cont_a64_entry_t *)qlt_get_req_pkt(vha); |
| 2006 | |
| 2007 | /* |
| 2008 | * Make sure that from cont_pkt64 none of |
| 2009 | * 64-bit specific fields used for 32-bit |
| 2010 | * addressing. Cast to (cont_entry_t *) for |
| 2011 | * that. |
| 2012 | */ |
| 2013 | |
| 2014 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); |
| 2015 | |
| 2016 | cont_pkt64->entry_count = 1; |
| 2017 | cont_pkt64->sys_define = 0; |
| 2018 | |
| 2019 | if (enable_64bit_addressing) { |
| 2020 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; |
| 2021 | dword_ptr = |
| 2022 | (uint32_t *)&cont_pkt64->dseg_0_address; |
| 2023 | } else { |
| 2024 | cont_pkt64->entry_type = CONTINUE_TYPE; |
| 2025 | dword_ptr = |
| 2026 | (uint32_t *)&((cont_entry_t *) |
| 2027 | cont_pkt64)->dseg_0_address; |
| 2028 | } |
| 2029 | |
| 2030 | /* Load continuation entry data segments */ |
| 2031 | for (cnt = 0; |
| 2032 | cnt < prm->tgt->datasegs_per_cont && prm->seg_cnt; |
| 2033 | cnt++, prm->seg_cnt--) { |
| 2034 | *dword_ptr++ = |
| 2035 | cpu_to_le32(pci_dma_lo32 |
| 2036 | (sg_dma_address(prm->sg))); |
| 2037 | if (enable_64bit_addressing) { |
| 2038 | *dword_ptr++ = |
| 2039 | cpu_to_le32(pci_dma_hi32 |
| 2040 | (sg_dma_address |
| 2041 | (prm->sg))); |
| 2042 | } |
| 2043 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2044 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2045 | prm->sg = sg_next(prm->sg); |
| 2046 | } |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | /* |
| 2051 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2052 | * that there is sufficient amount of request entries to not drop it. |
| 2053 | */ |
| 2054 | static void qlt_load_data_segments(struct qla_tgt_prm *prm, |
| 2055 | struct scsi_qla_host *vha) |
| 2056 | { |
| 2057 | int cnt; |
| 2058 | uint32_t *dword_ptr; |
| 2059 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; |
| 2060 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; |
| 2061 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2062 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
| 2063 | |
| 2064 | /* Setup packet address segment pointer */ |
| 2065 | dword_ptr = pkt24->u.status0.dseg_0_address; |
| 2066 | |
| 2067 | /* Set total data segment count */ |
| 2068 | if (prm->seg_cnt) |
| 2069 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); |
| 2070 | |
| 2071 | if (prm->seg_cnt == 0) { |
| 2072 | /* No data transfer */ |
| 2073 | *dword_ptr++ = 0; |
| 2074 | *dword_ptr = 0; |
| 2075 | return; |
| 2076 | } |
| 2077 | |
| 2078 | /* If scatter gather */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2079 | |
| 2080 | /* Load command entry data segments */ |
| 2081 | for (cnt = 0; |
| 2082 | (cnt < prm->tgt->datasegs_per_cmd) && prm->seg_cnt; |
| 2083 | cnt++, prm->seg_cnt--) { |
| 2084 | *dword_ptr++ = |
| 2085 | cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg))); |
| 2086 | if (enable_64bit_addressing) { |
| 2087 | *dword_ptr++ = |
| 2088 | cpu_to_le32(pci_dma_hi32( |
| 2089 | sg_dma_address(prm->sg))); |
| 2090 | } |
| 2091 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2092 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2093 | prm->sg = sg_next(prm->sg); |
| 2094 | } |
| 2095 | |
| 2096 | qlt_load_cont_data_segments(prm, vha); |
| 2097 | } |
| 2098 | |
| 2099 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) |
| 2100 | { |
| 2101 | return cmd->bufflen > 0; |
| 2102 | } |
| 2103 | |
| 2104 | /* |
| 2105 | * Called without ha->hardware_lock held |
| 2106 | */ |
| 2107 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, |
| 2108 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, |
| 2109 | uint32_t *full_req_cnt) |
| 2110 | { |
| 2111 | struct qla_tgt *tgt = cmd->tgt; |
| 2112 | struct scsi_qla_host *vha = tgt->vha; |
| 2113 | struct qla_hw_data *ha = vha->hw; |
| 2114 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2115 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2116 | prm->cmd = cmd; |
| 2117 | prm->tgt = tgt; |
| 2118 | prm->rq_result = scsi_status; |
| 2119 | prm->sense_buffer = &cmd->sense_buffer[0]; |
| 2120 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; |
| 2121 | prm->sg = NULL; |
| 2122 | prm->seg_cnt = -1; |
| 2123 | prm->req_cnt = 1; |
| 2124 | prm->add_status_pkt = 0; |
| 2125 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2126 | /* Send marker if required */ |
| 2127 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) |
| 2128 | return -EFAULT; |
| 2129 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2130 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
| 2131 | if (qlt_pci_map_calc_cnt(prm) != 0) |
| 2132 | return -EAGAIN; |
| 2133 | } |
| 2134 | |
| 2135 | *full_req_cnt = prm->req_cnt; |
| 2136 | |
| 2137 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { |
| 2138 | prm->residual = se_cmd->residual_count; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2139 | ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x305c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2140 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2141 | prm->residual, se_cmd->tag, |
| 2142 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, |
| 2143 | cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2144 | prm->rq_result |= SS_RESIDUAL_UNDER; |
| 2145 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2146 | prm->residual = se_cmd->residual_count; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2147 | ql_dbg(ql_dbg_io, vha, 0x305d, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2148 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2149 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? |
| 2150 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2151 | prm->rq_result |= SS_RESIDUAL_OVER; |
| 2152 | } |
| 2153 | |
| 2154 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2155 | /* |
| 2156 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be |
| 2157 | * ignored in *xmit_response() below |
| 2158 | */ |
| 2159 | if (qlt_has_data(cmd)) { |
| 2160 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || |
| 2161 | (IS_FWI2_CAPABLE(ha) && |
| 2162 | (prm->rq_result != 0))) { |
| 2163 | prm->add_status_pkt = 1; |
| 2164 | (*full_req_cnt)++; |
| 2165 | } |
| 2166 | } |
| 2167 | } |
| 2168 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2169 | return 0; |
| 2170 | } |
| 2171 | |
| 2172 | static inline int qlt_need_explicit_conf(struct qla_hw_data *ha, |
| 2173 | struct qla_tgt_cmd *cmd, int sending_sense) |
| 2174 | { |
| 2175 | if (ha->tgt.enable_class_2) |
| 2176 | return 0; |
| 2177 | |
| 2178 | if (sending_sense) |
| 2179 | return cmd->conf_compl_supported; |
| 2180 | else |
| 2181 | return ha->tgt.enable_explicit_conf && |
| 2182 | cmd->conf_compl_supported; |
| 2183 | } |
| 2184 | |
| 2185 | #ifdef CONFIG_QLA_TGT_DEBUG_SRR |
| 2186 | /* |
| 2187 | * Original taken from the XFS code |
| 2188 | */ |
| 2189 | static unsigned long qlt_srr_random(void) |
| 2190 | { |
| 2191 | static int Inited; |
| 2192 | static unsigned long RandomValue; |
| 2193 | static DEFINE_SPINLOCK(lock); |
| 2194 | /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */ |
| 2195 | register long rv; |
| 2196 | register long lo; |
| 2197 | register long hi; |
| 2198 | unsigned long flags; |
| 2199 | |
| 2200 | spin_lock_irqsave(&lock, flags); |
| 2201 | if (!Inited) { |
| 2202 | RandomValue = jiffies; |
| 2203 | Inited = 1; |
| 2204 | } |
| 2205 | rv = RandomValue; |
| 2206 | hi = rv / 127773; |
| 2207 | lo = rv % 127773; |
| 2208 | rv = 16807 * lo - 2836 * hi; |
| 2209 | if (rv <= 0) |
| 2210 | rv += 2147483647; |
| 2211 | RandomValue = rv; |
| 2212 | spin_unlock_irqrestore(&lock, flags); |
| 2213 | return rv; |
| 2214 | } |
| 2215 | |
| 2216 | static void qlt_check_srr_debug(struct qla_tgt_cmd *cmd, int *xmit_type) |
| 2217 | { |
| 2218 | #if 0 /* This is not a real status packets lost, so it won't lead to SRR */ |
| 2219 | if ((*xmit_type & QLA_TGT_XMIT_STATUS) && (qlt_srr_random() % 200) |
| 2220 | == 50) { |
| 2221 | *xmit_type &= ~QLA_TGT_XMIT_STATUS; |
| 2222 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf015, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2223 | "Dropping cmd %p (tag %d) status", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2224 | } |
| 2225 | #endif |
| 2226 | /* |
| 2227 | * It's currently not possible to simulate SRRs for FCP_WRITE without |
| 2228 | * a physical link layer failure, so don't even try here.. |
| 2229 | */ |
| 2230 | if (cmd->dma_data_direction != DMA_FROM_DEVICE) |
| 2231 | return; |
| 2232 | |
| 2233 | if (qlt_has_data(cmd) && (cmd->sg_cnt > 1) && |
| 2234 | ((qlt_srr_random() % 100) == 20)) { |
| 2235 | int i, leave = 0; |
| 2236 | unsigned int tot_len = 0; |
| 2237 | |
| 2238 | while (leave == 0) |
| 2239 | leave = qlt_srr_random() % cmd->sg_cnt; |
| 2240 | |
| 2241 | for (i = 0; i < leave; i++) |
| 2242 | tot_len += cmd->sg[i].length; |
| 2243 | |
| 2244 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf016, |
| 2245 | "Cutting cmd %p (tag %d) buffer" |
| 2246 | " tail to len %d, sg_cnt %d (cmd->bufflen %d," |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2247 | " cmd->sg_cnt %d)", cmd, se_cmd->tag, tot_len, leave, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2248 | cmd->bufflen, cmd->sg_cnt); |
| 2249 | |
| 2250 | cmd->bufflen = tot_len; |
| 2251 | cmd->sg_cnt = leave; |
| 2252 | } |
| 2253 | |
| 2254 | if (qlt_has_data(cmd) && ((qlt_srr_random() % 100) == 70)) { |
| 2255 | unsigned int offset = qlt_srr_random() % cmd->bufflen; |
| 2256 | |
| 2257 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf017, |
| 2258 | "Cutting cmd %p (tag %d) buffer head " |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2259 | "to offset %d (cmd->bufflen %d)", cmd, se_cmd->tag, offset, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2260 | cmd->bufflen); |
| 2261 | if (offset == 0) |
| 2262 | *xmit_type &= ~QLA_TGT_XMIT_DATA; |
| 2263 | else if (qlt_set_data_offset(cmd, offset)) { |
| 2264 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf018, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2265 | "qlt_set_data_offset() failed (tag %d)", se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2266 | } |
| 2267 | } |
| 2268 | } |
| 2269 | #else |
| 2270 | static inline void qlt_check_srr_debug(struct qla_tgt_cmd *cmd, int *xmit_type) |
| 2271 | {} |
| 2272 | #endif |
| 2273 | |
| 2274 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, |
| 2275 | struct qla_tgt_prm *prm) |
| 2276 | { |
| 2277 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, |
| 2278 | (uint32_t)sizeof(ctio->u.status1.sense_data)); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2279 | ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2280 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 0)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2281 | ctio->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2282 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2283 | CTIO7_FLAGS_CONFORM_REQ); |
| 2284 | } |
| 2285 | ctio->u.status0.residual = cpu_to_le32(prm->residual); |
| 2286 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); |
| 2287 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { |
| 2288 | int i; |
| 2289 | |
| 2290 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 1)) { |
Quinn Tran | df2e32c | 2017-01-19 22:27:53 -0800 | [diff] [blame^] | 2291 | if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2292 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe017, |
| 2293 | "Skipping EXPLICIT_CONFORM and " |
| 2294 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " |
| 2295 | "non GOOD status\n"); |
| 2296 | goto skip_explict_conf; |
| 2297 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2298 | ctio->u.status1.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2299 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2300 | CTIO7_FLAGS_CONFORM_REQ); |
| 2301 | } |
| 2302 | skip_explict_conf: |
| 2303 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2304 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2305 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2306 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2307 | ctio->u.status1.scsi_status |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2308 | cpu_to_le16(SS_SENSE_LEN_VALID); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2309 | ctio->u.status1.sense_length = |
| 2310 | cpu_to_le16(prm->sense_buffer_len); |
| 2311 | for (i = 0; i < prm->sense_buffer_len/4; i++) |
| 2312 | ((uint32_t *)ctio->u.status1.sense_data)[i] = |
| 2313 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); |
| 2314 | #if 0 |
| 2315 | if (unlikely((prm->sense_buffer_len % 4) != 0)) { |
| 2316 | static int q; |
| 2317 | if (q < 10) { |
| 2318 | ql_dbg(ql_dbg_tgt, vha, 0xe04f, |
| 2319 | "qla_target(%d): %d bytes of sense " |
| 2320 | "lost", prm->tgt->ha->vp_idx, |
| 2321 | prm->sense_buffer_len % 4); |
| 2322 | q++; |
| 2323 | } |
| 2324 | } |
| 2325 | #endif |
| 2326 | } else { |
| 2327 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2328 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2329 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2330 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2331 | ctio->u.status1.sense_length = 0; |
| 2332 | memset(ctio->u.status1.sense_data, 0, |
| 2333 | sizeof(ctio->u.status1.sense_data)); |
| 2334 | } |
| 2335 | |
| 2336 | /* Sense with len > 24, is it possible ??? */ |
| 2337 | } |
| 2338 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2339 | |
| 2340 | |
| 2341 | /* diff */ |
| 2342 | static inline int |
| 2343 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) |
| 2344 | { |
| 2345 | /* |
| 2346 | * Uncomment when corresponding SCSI changes are done. |
| 2347 | * |
| 2348 | if (!sp->cmd->prot_chk) |
| 2349 | return 0; |
| 2350 | * |
| 2351 | */ |
| 2352 | switch (se_cmd->prot_op) { |
| 2353 | case TARGET_PROT_DOUT_INSERT: |
| 2354 | case TARGET_PROT_DIN_STRIP: |
| 2355 | if (ql2xenablehba_err_chk >= 1) |
| 2356 | return 1; |
| 2357 | break; |
| 2358 | case TARGET_PROT_DOUT_PASS: |
| 2359 | case TARGET_PROT_DIN_PASS: |
| 2360 | if (ql2xenablehba_err_chk >= 2) |
| 2361 | return 1; |
| 2362 | break; |
| 2363 | case TARGET_PROT_DIN_INSERT: |
| 2364 | case TARGET_PROT_DOUT_STRIP: |
| 2365 | return 1; |
| 2366 | default: |
| 2367 | break; |
| 2368 | } |
| 2369 | return 0; |
| 2370 | } |
| 2371 | |
| 2372 | /* |
| 2373 | * qla24xx_set_t10dif_tags_from_cmd - Extract Ref and App tags from SCSI command |
| 2374 | * |
| 2375 | */ |
| 2376 | static inline void |
| 2377 | qlt_set_t10dif_tags(struct se_cmd *se_cmd, struct crc_context *ctx) |
| 2378 | { |
| 2379 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; |
| 2380 | |
| 2381 | /* wait til Mode Sense/Select cmd, modepage Ah, subpage 2 |
| 2382 | * have been immplemented by TCM, before AppTag is avail. |
| 2383 | * Look for modesense_handlers[] |
| 2384 | */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2385 | ctx->app_tag = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2386 | ctx->app_tag_mask[0] = 0x0; |
| 2387 | ctx->app_tag_mask[1] = 0x0; |
| 2388 | |
| 2389 | switch (se_cmd->prot_type) { |
| 2390 | case TARGET_DIF_TYPE0_PROT: |
| 2391 | /* |
| 2392 | * No check for ql2xenablehba_err_chk, as it would be an |
| 2393 | * I/O error if hba tag generation is not done. |
| 2394 | */ |
| 2395 | ctx->ref_tag = cpu_to_le32(lba); |
| 2396 | |
| 2397 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2398 | break; |
| 2399 | |
| 2400 | /* enable ALL bytes of the ref tag */ |
| 2401 | ctx->ref_tag_mask[0] = 0xff; |
| 2402 | ctx->ref_tag_mask[1] = 0xff; |
| 2403 | ctx->ref_tag_mask[2] = 0xff; |
| 2404 | ctx->ref_tag_mask[3] = 0xff; |
| 2405 | break; |
| 2406 | /* |
| 2407 | * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and |
| 2408 | * 16 bit app tag. |
| 2409 | */ |
| 2410 | case TARGET_DIF_TYPE1_PROT: |
| 2411 | ctx->ref_tag = cpu_to_le32(lba); |
| 2412 | |
| 2413 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2414 | break; |
| 2415 | |
| 2416 | /* enable ALL bytes of the ref tag */ |
| 2417 | ctx->ref_tag_mask[0] = 0xff; |
| 2418 | ctx->ref_tag_mask[1] = 0xff; |
| 2419 | ctx->ref_tag_mask[2] = 0xff; |
| 2420 | ctx->ref_tag_mask[3] = 0xff; |
| 2421 | break; |
| 2422 | /* |
| 2423 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to |
| 2424 | * match LBA in CDB + N |
| 2425 | */ |
| 2426 | case TARGET_DIF_TYPE2_PROT: |
| 2427 | ctx->ref_tag = cpu_to_le32(lba); |
| 2428 | |
| 2429 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2430 | break; |
| 2431 | |
| 2432 | /* enable ALL bytes of the ref tag */ |
| 2433 | ctx->ref_tag_mask[0] = 0xff; |
| 2434 | ctx->ref_tag_mask[1] = 0xff; |
| 2435 | ctx->ref_tag_mask[2] = 0xff; |
| 2436 | ctx->ref_tag_mask[3] = 0xff; |
| 2437 | break; |
| 2438 | |
| 2439 | /* For Type 3 protection: 16 bit GUARD only */ |
| 2440 | case TARGET_DIF_TYPE3_PROT: |
| 2441 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = |
| 2442 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; |
| 2443 | break; |
| 2444 | } |
| 2445 | } |
| 2446 | |
| 2447 | |
| 2448 | static inline int |
| 2449 | qlt_build_ctio_crc2_pkt(struct qla_tgt_prm *prm, scsi_qla_host_t *vha) |
| 2450 | { |
| 2451 | uint32_t *cur_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2452 | uint32_t transfer_length = 0; |
| 2453 | uint32_t data_bytes; |
| 2454 | uint32_t dif_bytes; |
| 2455 | uint8_t bundling = 1; |
| 2456 | uint8_t *clr_ptr; |
| 2457 | struct crc_context *crc_ctx_pkt = NULL; |
| 2458 | struct qla_hw_data *ha; |
| 2459 | struct ctio_crc2_to_fw *pkt; |
| 2460 | dma_addr_t crc_ctx_dma; |
| 2461 | uint16_t fw_prot_opts = 0; |
| 2462 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2463 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2464 | uint32_t h; |
| 2465 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2466 | uint16_t t16; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2467 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2468 | ha = vha->hw; |
| 2469 | |
| 2470 | pkt = (struct ctio_crc2_to_fw *)vha->req->ring_ptr; |
| 2471 | prm->pkt = pkt; |
| 2472 | memset(pkt, 0, sizeof(*pkt)); |
| 2473 | |
| 2474 | ql_dbg(ql_dbg_tgt, vha, 0xe071, |
| 2475 | "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n", |
| 2476 | vha->vp_idx, __func__, se_cmd, se_cmd->prot_op, |
| 2477 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); |
| 2478 | |
| 2479 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || |
| 2480 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) |
| 2481 | bundling = 0; |
| 2482 | |
| 2483 | /* Compute dif len and adjust data len to incude protection */ |
| 2484 | data_bytes = cmd->bufflen; |
| 2485 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; |
| 2486 | |
| 2487 | switch (se_cmd->prot_op) { |
| 2488 | case TARGET_PROT_DIN_INSERT: |
| 2489 | case TARGET_PROT_DOUT_STRIP: |
| 2490 | transfer_length = data_bytes; |
| 2491 | data_bytes += dif_bytes; |
| 2492 | break; |
| 2493 | |
| 2494 | case TARGET_PROT_DIN_STRIP: |
| 2495 | case TARGET_PROT_DOUT_INSERT: |
| 2496 | case TARGET_PROT_DIN_PASS: |
| 2497 | case TARGET_PROT_DOUT_PASS: |
| 2498 | transfer_length = data_bytes + dif_bytes; |
| 2499 | break; |
| 2500 | |
| 2501 | default: |
| 2502 | BUG(); |
| 2503 | break; |
| 2504 | } |
| 2505 | |
| 2506 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2507 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 2508 | /* HBA error checking enabled */ |
| 2509 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2510 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2511 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2512 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2513 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2514 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2515 | } |
| 2516 | |
| 2517 | switch (se_cmd->prot_op) { |
| 2518 | case TARGET_PROT_DIN_INSERT: |
| 2519 | case TARGET_PROT_DOUT_INSERT: |
| 2520 | fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 2521 | break; |
| 2522 | case TARGET_PROT_DIN_STRIP: |
| 2523 | case TARGET_PROT_DOUT_STRIP: |
| 2524 | fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 2525 | break; |
| 2526 | case TARGET_PROT_DIN_PASS: |
| 2527 | case TARGET_PROT_DOUT_PASS: |
| 2528 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2529 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ |
| 2530 | break; |
| 2531 | default:/* Normal Request */ |
| 2532 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2533 | break; |
| 2534 | } |
| 2535 | |
| 2536 | |
| 2537 | /* ---- PKT ---- */ |
| 2538 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 2539 | pkt->entry_type = CTIO_CRC2; |
| 2540 | pkt->entry_count = 1; |
| 2541 | pkt->vp_index = vha->vp_idx; |
| 2542 | |
| 2543 | h = qlt_make_handle(vha); |
| 2544 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2545 | /* |
| 2546 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2547 | * know the initiator's LOOP ID, hence we can't find |
| 2548 | * the session and, so, the command. |
| 2549 | */ |
| 2550 | return -EAGAIN; |
| 2551 | } else |
| 2552 | ha->tgt.cmds[h-1] = prm->cmd; |
| 2553 | |
| 2554 | |
| 2555 | pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK; |
| 2556 | pkt->nport_handle = prm->cmd->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2557 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2558 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2559 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2560 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2561 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2562 | |
| 2563 | /* silence compile warning */ |
| 2564 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2565 | pkt->ox_id = cpu_to_le16(t16); |
| 2566 | |
| 2567 | t16 = (atio->u.isp24.attr << 9); |
| 2568 | pkt->flags |= cpu_to_le16(t16); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2569 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2570 | |
| 2571 | /* Set transfer direction */ |
| 2572 | if (cmd->dma_data_direction == DMA_TO_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2573 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2574 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2575 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2576 | |
| 2577 | |
| 2578 | pkt->dseg_count = prm->tot_dsds; |
| 2579 | /* Fibre channel byte count */ |
| 2580 | pkt->transfer_length = cpu_to_le32(transfer_length); |
| 2581 | |
| 2582 | |
| 2583 | /* ----- CRC context -------- */ |
| 2584 | |
| 2585 | /* Allocate CRC context from global pool */ |
| 2586 | crc_ctx_pkt = cmd->ctx = |
| 2587 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
| 2588 | |
| 2589 | if (!crc_ctx_pkt) |
| 2590 | goto crc_queuing_error; |
| 2591 | |
| 2592 | /* Zero out CTX area. */ |
| 2593 | clr_ptr = (uint8_t *)crc_ctx_pkt; |
| 2594 | memset(clr_ptr, 0, sizeof(*crc_ctx_pkt)); |
| 2595 | |
| 2596 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 2597 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 2598 | |
| 2599 | /* Set handle */ |
| 2600 | crc_ctx_pkt->handle = pkt->handle; |
| 2601 | |
| 2602 | qlt_set_t10dif_tags(se_cmd, crc_ctx_pkt); |
| 2603 | |
| 2604 | pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); |
| 2605 | pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); |
| 2606 | pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 2607 | |
| 2608 | |
| 2609 | if (!bundling) { |
| 2610 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; |
| 2611 | } else { |
| 2612 | /* |
| 2613 | * Configure Bundling if we need to fetch interlaving |
| 2614 | * protection PCI accesses |
| 2615 | */ |
| 2616 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 2617 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 2618 | crc_ctx_pkt->u.bundling.dseg_count = |
| 2619 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); |
| 2620 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; |
| 2621 | } |
| 2622 | |
| 2623 | /* Finish the common fields of CRC pkt */ |
| 2624 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); |
| 2625 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 2626 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2627 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2628 | |
| 2629 | |
| 2630 | /* Walks data segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2631 | pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2632 | |
| 2633 | if (!bundling && prm->prot_seg_cnt) { |
| 2634 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, |
| 2635 | prm->tot_dsds, cmd)) |
| 2636 | goto crc_queuing_error; |
| 2637 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, |
| 2638 | (prm->tot_dsds - prm->prot_seg_cnt), cmd)) |
| 2639 | goto crc_queuing_error; |
| 2640 | |
| 2641 | if (bundling && prm->prot_seg_cnt) { |
| 2642 | /* Walks dif segments */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2643 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2644 | |
| 2645 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; |
| 2646 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, |
| 2647 | prm->prot_seg_cnt, cmd)) |
| 2648 | goto crc_queuing_error; |
| 2649 | } |
| 2650 | return QLA_SUCCESS; |
| 2651 | |
| 2652 | crc_queuing_error: |
| 2653 | /* Cleanup will be performed by the caller */ |
| 2654 | |
| 2655 | return QLA_FUNCTION_FAILED; |
| 2656 | } |
| 2657 | |
| 2658 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2659 | /* |
| 2660 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * |
| 2661 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon |
| 2662 | */ |
| 2663 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, |
| 2664 | uint8_t scsi_status) |
| 2665 | { |
| 2666 | struct scsi_qla_host *vha = cmd->vha; |
| 2667 | struct qla_hw_data *ha = vha->hw; |
| 2668 | struct ctio7_to_24xx *pkt; |
| 2669 | struct qla_tgt_prm prm; |
| 2670 | uint32_t full_req_cnt = 0; |
| 2671 | unsigned long flags = 0; |
| 2672 | int res; |
| 2673 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 2674 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2675 | if (cmd->sess && cmd->sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
| 2676 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 2677 | if (cmd->sess->logout_completed) |
| 2678 | /* no need to terminate. FW already freed exchange. */ |
| 2679 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 2680 | else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 2681 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 2682 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2683 | return 0; |
| 2684 | } |
| 2685 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2686 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2687 | memset(&prm, 0, sizeof(prm)); |
| 2688 | qlt_check_srr_debug(cmd, &xmit_type); |
| 2689 | |
| 2690 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe018, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2691 | "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p]\n", |
| 2692 | (xmit_type & QLA_TGT_XMIT_STATUS) ? |
| 2693 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, |
| 2694 | &cmd->se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2695 | |
| 2696 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, |
| 2697 | &full_req_cnt); |
| 2698 | if (unlikely(res != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2699 | return res; |
| 2700 | } |
| 2701 | |
| 2702 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2703 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 2704 | if (xmit_type == QLA_TGT_XMIT_STATUS) |
| 2705 | vha->tgt_counters.core_qla_snd_status++; |
| 2706 | else |
| 2707 | vha->tgt_counters.core_qla_que_buf++; |
| 2708 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2709 | if (!vha->flags.online || cmd->reset_count != ha->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2710 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2711 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2712 | * previous life, just abort the processing. |
| 2713 | */ |
| 2714 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 2715 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 2716 | ql_dbg(ql_dbg_async, vha, 0xe101, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2717 | "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2718 | vha->flags.online, qla2x00_reset_active(vha), |
| 2719 | cmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2720 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2721 | return 0; |
| 2722 | } |
| 2723 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2724 | /* Does F/W have an IOCBs for this request */ |
| 2725 | res = qlt_check_reserve_free_req(vha, full_req_cnt); |
| 2726 | if (unlikely(res)) |
| 2727 | goto out_unmap_unlock; |
| 2728 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2729 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
| 2730 | res = qlt_build_ctio_crc2_pkt(&prm, vha); |
| 2731 | else |
| 2732 | res = qlt_24xx_build_ctio_pkt(&prm, vha); |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 2733 | if (unlikely(res != 0)) { |
| 2734 | vha->req->cnt += full_req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2735 | goto out_unmap_unlock; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 2736 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2737 | |
| 2738 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
| 2739 | |
| 2740 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { |
| 2741 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2742 | cpu_to_le16(CTIO7_FLAGS_DATA_IN | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2743 | CTIO7_FLAGS_STATUS_MODE_0); |
| 2744 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2745 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
| 2746 | qlt_load_data_segments(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2747 | |
| 2748 | if (prm.add_status_pkt == 0) { |
| 2749 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2750 | pkt->u.status0.scsi_status = |
| 2751 | cpu_to_le16(prm.rq_result); |
| 2752 | pkt->u.status0.residual = |
| 2753 | cpu_to_le32(prm.residual); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2754 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2755 | CTIO7_FLAGS_SEND_STATUS); |
| 2756 | if (qlt_need_explicit_conf(ha, cmd, 0)) { |
| 2757 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2758 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2759 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2760 | CTIO7_FLAGS_CONFORM_REQ); |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | } else { |
| 2765 | /* |
| 2766 | * We have already made sure that there is sufficient |
| 2767 | * amount of request entries to not drop HW lock in |
| 2768 | * req_pkt(). |
| 2769 | */ |
| 2770 | struct ctio7_to_24xx *ctio = |
| 2771 | (struct ctio7_to_24xx *)qlt_get_req_pkt(vha); |
| 2772 | |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2773 | ql_dbg(ql_dbg_io, vha, 0x305e, |
| 2774 | "Building additional status packet 0x%p.\n", |
| 2775 | ctio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2776 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2777 | /* |
| 2778 | * T10Dif: ctio_crc2_to_fw overlay ontop of |
| 2779 | * ctio7_to_24xx |
| 2780 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2781 | memcpy(ctio, pkt, sizeof(*ctio)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2782 | /* reset back to CTIO7 */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2783 | ctio->entry_count = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2784 | ctio->entry_type = CTIO_TYPE7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2785 | ctio->dseg_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2786 | ctio->u.status1.flags &= ~cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2787 | CTIO7_FLAGS_DATA_IN); |
| 2788 | |
| 2789 | /* Real finish is ctio_m1's finish */ |
| 2790 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2791 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2792 | CTIO7_FLAGS_DONT_RET_CTIO); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2793 | |
| 2794 | /* qlt_24xx_init_ctio_to_isp will correct |
| 2795 | * all neccessary fields that's part of CTIO7. |
| 2796 | * There should be no residual of CTIO-CRC2 data. |
| 2797 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2798 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
| 2799 | &prm); |
| 2800 | pr_debug("Status CTIO7: %p\n", ctio); |
| 2801 | } |
| 2802 | } else |
| 2803 | qlt_24xx_init_ctio_to_isp(pkt, &prm); |
| 2804 | |
| 2805 | |
| 2806 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 2807 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2808 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2809 | /* Memory Barrier */ |
| 2810 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2811 | qla2x00_start_iocbs(vha, vha->req); |
| 2812 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2813 | |
| 2814 | return 0; |
| 2815 | |
| 2816 | out_unmap_unlock: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2817 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2818 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2819 | |
| 2820 | return res; |
| 2821 | } |
| 2822 | EXPORT_SYMBOL(qlt_xmit_response); |
| 2823 | |
| 2824 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) |
| 2825 | { |
| 2826 | struct ctio7_to_24xx *pkt; |
| 2827 | struct scsi_qla_host *vha = cmd->vha; |
| 2828 | struct qla_hw_data *ha = vha->hw; |
| 2829 | struct qla_tgt *tgt = cmd->tgt; |
| 2830 | struct qla_tgt_prm prm; |
| 2831 | unsigned long flags; |
| 2832 | int res = 0; |
| 2833 | |
| 2834 | memset(&prm, 0, sizeof(prm)); |
| 2835 | prm.cmd = cmd; |
| 2836 | prm.tgt = tgt; |
| 2837 | prm.sg = NULL; |
| 2838 | prm.req_cnt = 1; |
| 2839 | |
| 2840 | /* Send marker if required */ |
| 2841 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) |
| 2842 | return -EIO; |
| 2843 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2844 | /* Calculate number of entries and segments required */ |
| 2845 | if (qlt_pci_map_calc_cnt(&prm) != 0) |
| 2846 | return -EAGAIN; |
| 2847 | |
| 2848 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2849 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2850 | if (!vha->flags.online || (cmd->reset_count != ha->chip_reset) || |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 2851 | (cmd->sess && cmd->sess->deleted == QLA_SESS_DELETION_IN_PROGRESS)) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2852 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2853 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2854 | * previous life, just abort the processing. |
| 2855 | */ |
| 2856 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
| 2857 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 2858 | ql_dbg(ql_dbg_async, vha, 0xe102, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2859 | "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2860 | vha->flags.online, qla2x00_reset_active(vha), |
| 2861 | cmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2862 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2863 | return 0; |
| 2864 | } |
| 2865 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2866 | /* Does F/W have an IOCBs for this request */ |
| 2867 | res = qlt_check_reserve_free_req(vha, prm.req_cnt); |
| 2868 | if (res != 0) |
| 2869 | goto out_unlock_free_unmap; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2870 | if (cmd->se_cmd.prot_op) |
| 2871 | res = qlt_build_ctio_crc2_pkt(&prm, vha); |
| 2872 | else |
| 2873 | res = qlt_24xx_build_ctio_pkt(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2874 | |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 2875 | if (unlikely(res != 0)) { |
| 2876 | vha->req->cnt += prm.req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2877 | goto out_unlock_free_unmap; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 2878 | } |
| 2879 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2880 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2881 | pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2882 | CTIO7_FLAGS_STATUS_MODE_0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2883 | |
| 2884 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
| 2885 | qlt_load_data_segments(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2886 | |
| 2887 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 2888 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2889 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2890 | /* Memory Barrier */ |
| 2891 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2892 | qla2x00_start_iocbs(vha, vha->req); |
| 2893 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2894 | |
| 2895 | return res; |
| 2896 | |
| 2897 | out_unlock_free_unmap: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2898 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2899 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2900 | |
| 2901 | return res; |
| 2902 | } |
| 2903 | EXPORT_SYMBOL(qlt_rdy_to_xfer); |
| 2904 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2905 | |
| 2906 | /* |
| 2907 | * Checks the guard or meta-data for the type of error |
| 2908 | * detected by the HBA. |
| 2909 | */ |
| 2910 | static inline int |
| 2911 | qlt_handle_dif_error(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd, |
| 2912 | struct ctio_crc_from_fw *sts) |
| 2913 | { |
| 2914 | uint8_t *ap = &sts->actual_dif[0]; |
| 2915 | uint8_t *ep = &sts->expected_dif[0]; |
| 2916 | uint32_t e_ref_tag, a_ref_tag; |
| 2917 | uint16_t e_app_tag, a_app_tag; |
| 2918 | uint16_t e_guard, a_guard; |
| 2919 | uint64_t lba = cmd->se_cmd.t_task_lba; |
| 2920 | |
| 2921 | a_guard = be16_to_cpu(*(uint16_t *)(ap + 0)); |
| 2922 | a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2)); |
| 2923 | a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4)); |
| 2924 | |
| 2925 | e_guard = be16_to_cpu(*(uint16_t *)(ep + 0)); |
| 2926 | e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2)); |
| 2927 | e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4)); |
| 2928 | |
| 2929 | ql_dbg(ql_dbg_tgt, vha, 0xe075, |
| 2930 | "iocb(s) %p Returned STATUS.\n", sts); |
| 2931 | |
| 2932 | ql_dbg(ql_dbg_tgt, vha, 0xf075, |
Hans Wennborg | fc38504 | 2014-08-05 21:43:29 -0700 | [diff] [blame] | 2933 | "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] | 2934 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 2935 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, a_guard, e_guard); |
| 2936 | |
| 2937 | /* |
| 2938 | * Ignore sector if: |
| 2939 | * For type 3: ref & app tag is all 'f's |
| 2940 | * For type 0,1,2: app tag is all 'f's |
| 2941 | */ |
| 2942 | if ((a_app_tag == 0xffff) && |
| 2943 | ((cmd->se_cmd.prot_type != TARGET_DIF_TYPE3_PROT) || |
| 2944 | (a_ref_tag == 0xffffffff))) { |
| 2945 | uint32_t blocks_done; |
| 2946 | |
| 2947 | /* 2TB boundary case covered automatically with this */ |
| 2948 | blocks_done = e_ref_tag - (uint32_t)lba + 1; |
| 2949 | cmd->se_cmd.bad_sector = e_ref_tag; |
| 2950 | cmd->se_cmd.pi_err = 0; |
| 2951 | ql_dbg(ql_dbg_tgt, vha, 0xf074, |
| 2952 | "need to return scsi good\n"); |
| 2953 | |
| 2954 | /* Update protection tag */ |
| 2955 | if (cmd->prot_sg_cnt) { |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2956 | uint32_t i, k = 0, num_ent; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2957 | struct scatterlist *sg, *sgl; |
| 2958 | |
| 2959 | |
| 2960 | sgl = cmd->prot_sg; |
| 2961 | |
| 2962 | /* Patch the corresponding protection tags */ |
| 2963 | for_each_sg(sgl, sg, cmd->prot_sg_cnt, i) { |
| 2964 | num_ent = sg_dma_len(sg) / 8; |
| 2965 | if (k + num_ent < blocks_done) { |
| 2966 | k += num_ent; |
| 2967 | continue; |
| 2968 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2969 | k = blocks_done; |
| 2970 | break; |
| 2971 | } |
| 2972 | |
| 2973 | if (k != blocks_done) { |
| 2974 | ql_log(ql_log_warn, vha, 0xf076, |
| 2975 | "unexpected tag values tag:lba=%u:%llu)\n", |
| 2976 | e_ref_tag, (unsigned long long)lba); |
| 2977 | goto out; |
| 2978 | } |
| 2979 | |
| 2980 | #if 0 |
| 2981 | struct sd_dif_tuple *spt; |
| 2982 | /* TODO: |
| 2983 | * This section came from initiator. Is it valid here? |
| 2984 | * should ulp be override with actual val??? |
| 2985 | */ |
| 2986 | spt = page_address(sg_page(sg)) + sg->offset; |
| 2987 | spt += j; |
| 2988 | |
| 2989 | spt->app_tag = 0xffff; |
| 2990 | if (cmd->se_cmd.prot_type == SCSI_PROT_DIF_TYPE3) |
| 2991 | spt->ref_tag = 0xffffffff; |
| 2992 | #endif |
| 2993 | } |
| 2994 | |
| 2995 | return 0; |
| 2996 | } |
| 2997 | |
| 2998 | /* check guard */ |
| 2999 | if (e_guard != a_guard) { |
| 3000 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED; |
| 3001 | cmd->se_cmd.bad_sector = cmd->se_cmd.t_task_lba; |
| 3002 | |
| 3003 | ql_log(ql_log_warn, vha, 0xe076, |
| 3004 | "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", |
| 3005 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 3006 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, |
| 3007 | a_guard, e_guard, cmd); |
| 3008 | goto out; |
| 3009 | } |
| 3010 | |
| 3011 | /* check ref tag */ |
| 3012 | if (e_ref_tag != a_ref_tag) { |
| 3013 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED; |
| 3014 | cmd->se_cmd.bad_sector = e_ref_tag; |
| 3015 | |
| 3016 | ql_log(ql_log_warn, vha, 0xe077, |
| 3017 | "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", |
| 3018 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 3019 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, |
| 3020 | a_guard, e_guard, cmd); |
| 3021 | goto out; |
| 3022 | } |
| 3023 | |
| 3024 | /* check appl tag */ |
| 3025 | if (e_app_tag != a_app_tag) { |
| 3026 | cmd->se_cmd.pi_err = TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED; |
| 3027 | cmd->se_cmd.bad_sector = cmd->se_cmd.t_task_lba; |
| 3028 | |
| 3029 | ql_log(ql_log_warn, vha, 0xe078, |
| 3030 | "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", |
| 3031 | cmd->atio.u.isp24.fcp_cmnd.cdb[0], lba, |
| 3032 | a_ref_tag, e_ref_tag, a_app_tag, e_app_tag, |
| 3033 | a_guard, e_guard, cmd); |
| 3034 | goto out; |
| 3035 | } |
| 3036 | out: |
| 3037 | return 1; |
| 3038 | } |
| 3039 | |
| 3040 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3041 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3042 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3043 | static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3044 | struct imm_ntfy_from_isp *ntfy) |
| 3045 | { |
| 3046 | struct nack_to_isp *nack; |
| 3047 | struct qla_hw_data *ha = vha->hw; |
| 3048 | request_t *pkt; |
| 3049 | int ret = 0; |
| 3050 | |
| 3051 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c, |
| 3052 | "Sending TERM ELS CTIO (ha=%p)\n", ha); |
| 3053 | |
| 3054 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(vha, NULL); |
| 3055 | if (pkt == NULL) { |
| 3056 | ql_dbg(ql_dbg_tgt, vha, 0xe080, |
| 3057 | "qla_target(%d): %s failed: unable to allocate " |
| 3058 | "request packet\n", vha->vp_idx, __func__); |
| 3059 | return -ENOMEM; |
| 3060 | } |
| 3061 | |
| 3062 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 3063 | pkt->entry_count = 1; |
Quinn Tran | 4f06073 | 2016-12-23 18:06:13 -0800 | [diff] [blame] | 3064 | pkt->handle = QLA_TGT_SKIP_HANDLE; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3065 | |
| 3066 | nack = (struct nack_to_isp *)pkt; |
| 3067 | nack->ox_id = ntfy->ox_id; |
| 3068 | |
| 3069 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3070 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3071 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
| 3072 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
| 3073 | } |
| 3074 | |
| 3075 | /* terminate */ |
| 3076 | nack->u.isp24.flags |= |
| 3077 | __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE); |
| 3078 | |
| 3079 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3080 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3081 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3082 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3083 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3084 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3085 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3086 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3087 | |
| 3088 | qla2x00_start_iocbs(vha, vha->req); |
| 3089 | return ret; |
| 3090 | } |
| 3091 | |
| 3092 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3093 | struct imm_ntfy_from_isp *imm, int ha_locked) |
| 3094 | { |
| 3095 | unsigned long flags = 0; |
| 3096 | int rc; |
| 3097 | |
| 3098 | if (qlt_issue_marker(vha, ha_locked) < 0) |
| 3099 | return; |
| 3100 | |
| 3101 | if (ha_locked) { |
| 3102 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3103 | |
| 3104 | #if 0 /* Todo */ |
| 3105 | if (rc == -ENOMEM) |
| 3106 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
Bart Van Assche | 91f42b3 | 2016-03-30 15:25:21 -0700 | [diff] [blame] | 3107 | #else |
| 3108 | if (rc) { |
| 3109 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3110 | #endif |
| 3111 | goto done; |
| 3112 | } |
| 3113 | |
| 3114 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 3115 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3116 | |
| 3117 | #if 0 /* Todo */ |
| 3118 | if (rc == -ENOMEM) |
| 3119 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
| 3120 | #endif |
| 3121 | |
| 3122 | done: |
| 3123 | if (!ha_locked) |
| 3124 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 3125 | } |
| 3126 | |
| 3127 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3128 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3129 | static int __qlt_send_term_exchange(struct scsi_qla_host *vha, |
| 3130 | struct qla_tgt_cmd *cmd, |
| 3131 | struct atio_from_isp *atio) |
| 3132 | { |
| 3133 | struct ctio7_to_24xx *ctio24; |
| 3134 | struct qla_hw_data *ha = vha->hw; |
| 3135 | request_t *pkt; |
| 3136 | int ret = 0; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3137 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3138 | |
| 3139 | ql_dbg(ql_dbg_tgt, vha, 0xe01c, "Sending TERM EXCH CTIO (ha=%p)\n", ha); |
| 3140 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3141 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3142 | if (pkt == NULL) { |
| 3143 | ql_dbg(ql_dbg_tgt, vha, 0xe050, |
| 3144 | "qla_target(%d): %s failed: unable to allocate " |
| 3145 | "request packet\n", vha->vp_idx, __func__); |
| 3146 | return -ENOMEM; |
| 3147 | } |
| 3148 | |
| 3149 | if (cmd != NULL) { |
| 3150 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { |
| 3151 | ql_dbg(ql_dbg_tgt, vha, 0xe051, |
| 3152 | "qla_target(%d): Terminating cmd %p with " |
| 3153 | "incorrect state %d\n", vha->vp_idx, cmd, |
| 3154 | cmd->state); |
| 3155 | } else |
| 3156 | ret = 1; |
| 3157 | } |
| 3158 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3159 | vha->tgt_counters.num_term_xchg_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3160 | pkt->entry_count = 1; |
| 3161 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 3162 | |
| 3163 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 3164 | ctio24->entry_type = CTIO_TYPE7; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3165 | ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3166 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3167 | ctio24->vp_index = vha->vp_idx; |
| 3168 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 3169 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 3170 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 3171 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
| 3172 | ctio24->u.status1.flags = (atio->u.isp24.attr << 9) | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3173 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3174 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3175 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3176 | ctio24->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3177 | |
| 3178 | /* Most likely, it isn't needed */ |
| 3179 | ctio24->u.status1.residual = get_unaligned((uint32_t *) |
| 3180 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 3181 | atio->u.isp24.fcp_cmnd.add_cdb_len]); |
| 3182 | if (ctio24->u.status1.residual != 0) |
| 3183 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; |
| 3184 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3185 | /* Memory Barrier */ |
| 3186 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3187 | qla2x00_start_iocbs(vha, vha->req); |
| 3188 | return ret; |
| 3189 | } |
| 3190 | |
| 3191 | static void qlt_send_term_exchange(struct scsi_qla_host *vha, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3192 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, |
| 3193 | int ul_abort) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3194 | { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3195 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3196 | int rc; |
| 3197 | |
| 3198 | if (qlt_issue_marker(vha, ha_locked) < 0) |
| 3199 | return; |
| 3200 | |
| 3201 | if (ha_locked) { |
| 3202 | rc = __qlt_send_term_exchange(vha, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3203 | if (rc == -ENOMEM) |
| 3204 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3205 | goto done; |
| 3206 | } |
| 3207 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 3208 | rc = __qlt_send_term_exchange(vha, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3209 | if (rc == -ENOMEM) |
| 3210 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3211 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3212 | done: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3213 | if (cmd && !ul_abort && !cmd->aborted) { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3214 | if (cmd->sg_mapped) |
| 3215 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3216 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3217 | } |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3218 | |
| 3219 | if (!ha_locked) |
| 3220 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 3221 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3222 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3223 | } |
| 3224 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3225 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
| 3226 | { |
| 3227 | struct list_head free_list; |
| 3228 | struct qla_tgt_cmd *cmd, *tcmd; |
| 3229 | |
| 3230 | vha->hw->tgt.leak_exchg_thresh_hold = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3231 | (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3232 | |
| 3233 | cmd = tcmd = NULL; |
| 3234 | if (!list_empty(&vha->hw->tgt.q_full_list)) { |
| 3235 | INIT_LIST_HEAD(&free_list); |
| 3236 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); |
| 3237 | |
| 3238 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 3239 | list_del(&cmd->cmd_list); |
| 3240 | /* This cmd was never sent to TCM. There is no need |
| 3241 | * to schedule free or call free_cmd |
| 3242 | */ |
| 3243 | qlt_free_cmd(cmd); |
| 3244 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 3245 | } |
| 3246 | } |
| 3247 | vha->hw->tgt.num_qfull_cmds_dropped = 0; |
| 3248 | } |
| 3249 | |
| 3250 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) |
| 3251 | { |
| 3252 | uint32_t total_leaked; |
| 3253 | |
| 3254 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; |
| 3255 | |
| 3256 | if (vha->hw->tgt.leak_exchg_thresh_hold && |
| 3257 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { |
| 3258 | |
| 3259 | ql_dbg(ql_dbg_tgt, vha, 0xe079, |
| 3260 | "Chip reset due to exchange starvation: %d/%d.\n", |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3261 | total_leaked, vha->hw->cur_fw_xcb_count); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3262 | |
| 3263 | if (IS_P3P_TYPE(vha->hw)) |
| 3264 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 3265 | else |
| 3266 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3267 | qla2xxx_wake_dpc(vha); |
| 3268 | } |
| 3269 | |
| 3270 | } |
| 3271 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3272 | int qlt_abort_cmd(struct qla_tgt_cmd *cmd) |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3273 | { |
| 3274 | struct qla_tgt *tgt = cmd->tgt; |
| 3275 | struct scsi_qla_host *vha = tgt->vha; |
| 3276 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3277 | unsigned long flags; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3278 | |
| 3279 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, |
| 3280 | "qla_target(%d): terminating exchange for aborted cmd=%p " |
| 3281 | "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, |
| 3282 | se_cmd->tag); |
| 3283 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3284 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3285 | if (cmd->aborted) { |
| 3286 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3287 | /* |
| 3288 | * It's normal to see 2 calls in this path: |
| 3289 | * 1) XFER Rdy completion + CMD_T_ABORT |
| 3290 | * 2) TCM TMR - drain_state_list |
| 3291 | */ |
| 3292 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xffff, |
| 3293 | "multiple abort. %p transport_state %x, t_state %x," |
| 3294 | " se_cmd_flags %x \n", cmd, cmd->se_cmd.transport_state, |
| 3295 | cmd->se_cmd.t_state,cmd->se_cmd.se_cmd_flags); |
| 3296 | return EIO; |
| 3297 | } |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3298 | cmd->aborted = 1; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3299 | cmd->cmd_flags |= BIT_6; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3300 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3301 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3302 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 0, 1); |
| 3303 | return 0; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3304 | } |
| 3305 | EXPORT_SYMBOL(qlt_abort_cmd); |
| 3306 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3307 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
| 3308 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3309 | struct qla_tgt_sess *sess = cmd->sess; |
| 3310 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3311 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
| 3312 | "%s: se_cmd[%p] ox_id %04x\n", |
| 3313 | __func__, &cmd->se_cmd, |
| 3314 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3315 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3316 | BUG_ON(cmd->cmd_in_wq); |
| 3317 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3318 | if (cmd->sg_mapped) |
| 3319 | qlt_unmap_sg(cmd->vha, cmd); |
| 3320 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3321 | if (!cmd->q_full) |
| 3322 | qlt_decr_num_pend_cmds(cmd->vha); |
| 3323 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3324 | BUG_ON(cmd->sg_mapped); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3325 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3326 | if (unlikely(cmd->free_sg)) |
| 3327 | kfree(cmd->sg); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3328 | |
| 3329 | if (!sess || !sess->se_sess) { |
| 3330 | WARN_ON(1); |
| 3331 | return; |
| 3332 | } |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3333 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3334 | 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] | 3335 | } |
| 3336 | EXPORT_SYMBOL(qlt_free_cmd); |
| 3337 | |
| 3338 | /* ha->hardware_lock supposed to be held on entry */ |
| 3339 | static int qlt_prepare_srr_ctio(struct scsi_qla_host *vha, |
| 3340 | struct qla_tgt_cmd *cmd, void *ctio) |
| 3341 | { |
| 3342 | struct qla_tgt_srr_ctio *sc; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 3343 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3344 | struct qla_tgt_srr_imm *imm; |
| 3345 | |
| 3346 | tgt->ctio_srr_id++; |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3347 | cmd->cmd_flags |= BIT_15; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3348 | |
| 3349 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019, |
| 3350 | "qla_target(%d): CTIO with SRR status received\n", vha->vp_idx); |
| 3351 | |
| 3352 | if (!ctio) { |
| 3353 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf055, |
| 3354 | "qla_target(%d): SRR CTIO, but ctio is NULL\n", |
| 3355 | vha->vp_idx); |
| 3356 | return -EINVAL; |
| 3357 | } |
| 3358 | |
| 3359 | sc = kzalloc(sizeof(*sc), GFP_ATOMIC); |
| 3360 | if (sc != NULL) { |
| 3361 | sc->cmd = cmd; |
| 3362 | /* IRQ is already OFF */ |
| 3363 | spin_lock(&tgt->srr_lock); |
| 3364 | sc->srr_id = tgt->ctio_srr_id; |
| 3365 | list_add_tail(&sc->srr_list_entry, |
| 3366 | &tgt->srr_ctio_list); |
| 3367 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a, |
| 3368 | "CTIO SRR %p added (id %d)\n", sc, sc->srr_id); |
| 3369 | if (tgt->imm_srr_id == tgt->ctio_srr_id) { |
| 3370 | int found = 0; |
| 3371 | list_for_each_entry(imm, &tgt->srr_imm_list, |
| 3372 | srr_list_entry) { |
| 3373 | if (imm->srr_id == sc->srr_id) { |
| 3374 | found = 1; |
| 3375 | break; |
| 3376 | } |
| 3377 | } |
| 3378 | if (found) { |
| 3379 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01b, |
| 3380 | "Scheduling srr work\n"); |
| 3381 | schedule_work(&tgt->srr_work); |
| 3382 | } else { |
| 3383 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf056, |
| 3384 | "qla_target(%d): imm_srr_id " |
| 3385 | "== ctio_srr_id (%d), but there is no " |
| 3386 | "corresponding SRR IMM, deleting CTIO " |
| 3387 | "SRR %p\n", vha->vp_idx, |
| 3388 | tgt->ctio_srr_id, sc); |
| 3389 | list_del(&sc->srr_list_entry); |
| 3390 | spin_unlock(&tgt->srr_lock); |
| 3391 | |
| 3392 | kfree(sc); |
| 3393 | return -EINVAL; |
| 3394 | } |
| 3395 | } |
| 3396 | spin_unlock(&tgt->srr_lock); |
| 3397 | } else { |
| 3398 | struct qla_tgt_srr_imm *ti; |
| 3399 | |
| 3400 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf057, |
| 3401 | "qla_target(%d): Unable to allocate SRR CTIO entry\n", |
| 3402 | vha->vp_idx); |
| 3403 | spin_lock(&tgt->srr_lock); |
| 3404 | list_for_each_entry_safe(imm, ti, &tgt->srr_imm_list, |
| 3405 | srr_list_entry) { |
| 3406 | if (imm->srr_id == tgt->ctio_srr_id) { |
| 3407 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01c, |
| 3408 | "IMM SRR %p deleted (id %d)\n", |
| 3409 | imm, imm->srr_id); |
| 3410 | list_del(&imm->srr_list_entry); |
| 3411 | qlt_reject_free_srr_imm(vha, imm, 1); |
| 3412 | } |
| 3413 | } |
| 3414 | spin_unlock(&tgt->srr_lock); |
| 3415 | |
| 3416 | return -ENOMEM; |
| 3417 | } |
| 3418 | |
| 3419 | return 0; |
| 3420 | } |
| 3421 | |
| 3422 | /* |
| 3423 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3424 | */ |
| 3425 | static int qlt_term_ctio_exchange(struct scsi_qla_host *vha, void *ctio, |
| 3426 | struct qla_tgt_cmd *cmd, uint32_t status) |
| 3427 | { |
| 3428 | int term = 0; |
| 3429 | |
| 3430 | if (ctio != NULL) { |
| 3431 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; |
| 3432 | term = !(c->flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3433 | cpu_to_le16(OF_TERM_EXCH)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3434 | } else |
| 3435 | term = 1; |
| 3436 | |
| 3437 | if (term) |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3438 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3439 | |
| 3440 | return term; |
| 3441 | } |
| 3442 | |
| 3443 | /* ha->hardware_lock supposed to be held on entry */ |
| 3444 | static inline struct qla_tgt_cmd *qlt_get_cmd(struct scsi_qla_host *vha, |
| 3445 | uint32_t handle) |
| 3446 | { |
| 3447 | struct qla_hw_data *ha = vha->hw; |
| 3448 | |
| 3449 | handle--; |
| 3450 | if (ha->tgt.cmds[handle] != NULL) { |
| 3451 | struct qla_tgt_cmd *cmd = ha->tgt.cmds[handle]; |
| 3452 | ha->tgt.cmds[handle] = NULL; |
| 3453 | return cmd; |
| 3454 | } else |
| 3455 | return NULL; |
| 3456 | } |
| 3457 | |
| 3458 | /* ha->hardware_lock supposed to be held on entry */ |
| 3459 | static struct qla_tgt_cmd *qlt_ctio_to_cmd(struct scsi_qla_host *vha, |
| 3460 | uint32_t handle, void *ctio) |
| 3461 | { |
| 3462 | struct qla_tgt_cmd *cmd = NULL; |
| 3463 | |
| 3464 | /* Clear out internal marks */ |
| 3465 | handle &= ~(CTIO_COMPLETION_HANDLE_MARK | |
| 3466 | CTIO_INTERMEDIATE_HANDLE_MARK); |
| 3467 | |
| 3468 | if (handle != QLA_TGT_NULL_HANDLE) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3469 | if (unlikely(handle == QLA_TGT_SKIP_HANDLE)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3470 | return NULL; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3471 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3472 | /* handle-1 is actually used */ |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3473 | if (unlikely(handle > DEFAULT_OUTSTANDING_COMMANDS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3474 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
| 3475 | "qla_target(%d): Wrong handle %x received\n", |
| 3476 | vha->vp_idx, handle); |
| 3477 | return NULL; |
| 3478 | } |
| 3479 | cmd = qlt_get_cmd(vha, handle); |
| 3480 | if (unlikely(cmd == NULL)) { |
| 3481 | ql_dbg(ql_dbg_tgt, vha, 0xe053, |
| 3482 | "qla_target(%d): Suspicious: unable to " |
| 3483 | "find the command with handle %x\n", vha->vp_idx, |
| 3484 | handle); |
| 3485 | return NULL; |
| 3486 | } |
| 3487 | } else if (ctio != NULL) { |
| 3488 | /* We can't get loop ID from CTIO7 */ |
| 3489 | ql_dbg(ql_dbg_tgt, vha, 0xe054, |
| 3490 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " |
| 3491 | "support NULL handles\n", vha->vp_idx); |
| 3492 | return NULL; |
| 3493 | } |
| 3494 | |
| 3495 | return cmd; |
| 3496 | } |
| 3497 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3498 | /* hardware_lock should be held by caller. */ |
| 3499 | static void |
| 3500 | qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) |
| 3501 | { |
| 3502 | struct qla_hw_data *ha = vha->hw; |
| 3503 | uint32_t handle; |
| 3504 | |
| 3505 | if (cmd->sg_mapped) |
| 3506 | qlt_unmap_sg(vha, cmd); |
| 3507 | |
| 3508 | handle = qlt_make_handle(vha); |
| 3509 | |
| 3510 | /* TODO: fix debug message type and ids. */ |
| 3511 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
| 3512 | ql_dbg(ql_dbg_io, vha, 0xff00, |
| 3513 | "HOST-ABORT: handle=%d, state=PROCESSED.\n", handle); |
| 3514 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 3515 | cmd->write_data_transferred = 0; |
| 3516 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3517 | |
| 3518 | ql_dbg(ql_dbg_io, vha, 0xff01, |
| 3519 | "HOST-ABORT: handle=%d, state=DATA_IN.\n", handle); |
| 3520 | |
| 3521 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3522 | return; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3523 | } else { |
| 3524 | ql_dbg(ql_dbg_io, vha, 0xff03, |
| 3525 | "HOST-ABORT: handle=%d, state=BAD(%d).\n", handle, |
| 3526 | cmd->state); |
| 3527 | dump_stack(); |
| 3528 | } |
| 3529 | |
Quinn Tran | e5fdee8 | 2015-06-10 11:05:21 -0400 | [diff] [blame] | 3530 | cmd->cmd_flags |= BIT_17; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3531 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3532 | } |
| 3533 | |
| 3534 | void |
| 3535 | qlt_host_reset_handler(struct qla_hw_data *ha) |
| 3536 | { |
| 3537 | struct qla_tgt_cmd *cmd; |
| 3538 | unsigned long flags; |
| 3539 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
| 3540 | scsi_qla_host_t *vha = NULL; |
| 3541 | struct qla_tgt *tgt = base_vha->vha_tgt.qla_tgt; |
| 3542 | uint32_t i; |
| 3543 | |
| 3544 | if (!base_vha->hw->tgt.tgt_ops) |
| 3545 | return; |
| 3546 | |
| 3547 | if (!tgt || qla_ini_mode_enabled(base_vha)) { |
| 3548 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003, |
| 3549 | "Target mode disabled\n"); |
| 3550 | return; |
| 3551 | } |
| 3552 | |
| 3553 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xff10, |
| 3554 | "HOST-ABORT-HNDLR: base_vha->dpc_flags=%lx.\n", |
| 3555 | base_vha->dpc_flags); |
| 3556 | |
| 3557 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3558 | for (i = 1; i < DEFAULT_OUTSTANDING_COMMANDS + 1; i++) { |
| 3559 | cmd = qlt_get_cmd(base_vha, i); |
| 3560 | if (!cmd) |
| 3561 | continue; |
| 3562 | /* ha->tgt.cmds entry is cleared by qlt_get_cmd. */ |
| 3563 | vha = cmd->vha; |
| 3564 | qlt_abort_cmd_on_host_reset(vha, cmd); |
| 3565 | } |
| 3566 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3567 | } |
| 3568 | |
| 3569 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3570 | /* |
| 3571 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3572 | */ |
| 3573 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, uint32_t handle, |
| 3574 | uint32_t status, void *ctio) |
| 3575 | { |
| 3576 | struct qla_hw_data *ha = vha->hw; |
| 3577 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3578 | struct qla_tgt_cmd *cmd; |
| 3579 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3580 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
| 3581 | /* That could happen only in case of an error/reset/abort */ |
| 3582 | if (status != CTIO_SUCCESS) { |
| 3583 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, |
| 3584 | "Intermediate CTIO received" |
| 3585 | " (status %x)\n", status); |
| 3586 | } |
| 3587 | return; |
| 3588 | } |
| 3589 | |
| 3590 | cmd = qlt_ctio_to_cmd(vha, handle, ctio); |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3591 | if (cmd == NULL) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3592 | return; |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3593 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3594 | se_cmd = &cmd->se_cmd; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3595 | cmd->cmd_sent_to_fw = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3596 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3597 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3598 | |
| 3599 | if (unlikely(status != CTIO_SUCCESS)) { |
| 3600 | switch (status & 0xFFFF) { |
| 3601 | case CTIO_LIP_RESET: |
| 3602 | case CTIO_TARGET_RESET: |
| 3603 | case CTIO_ABORTED: |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3604 | /* driver request abort via Terminate exchange */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3605 | case CTIO_TIMEOUT: |
| 3606 | case CTIO_INVALID_RX_ID: |
| 3607 | /* They are OK */ |
| 3608 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, |
| 3609 | "qla_target(%d): CTIO with " |
| 3610 | "status %#x received, state %x, se_cmd %p, " |
| 3611 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " |
| 3612 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, |
| 3613 | status, cmd->state, se_cmd); |
| 3614 | break; |
| 3615 | |
| 3616 | case CTIO_PORT_LOGGED_OUT: |
| 3617 | case CTIO_PORT_UNAVAILABLE: |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3618 | { |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3619 | int logged_out = |
| 3620 | (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; |
| 3621 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3622 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3623 | "qla_target(%d): CTIO with %s status %x " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3624 | "received (state %x, se_cmd %p)\n", vha->vp_idx, |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3625 | logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3626 | status, cmd->state, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3627 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3628 | if (logged_out && cmd->sess) { |
| 3629 | /* |
| 3630 | * Session is already logged out, but we need |
| 3631 | * to notify initiator, who's not aware of this |
| 3632 | */ |
| 3633 | cmd->sess->logout_on_delete = 0; |
| 3634 | cmd->sess->send_els_logo = 1; |
| 3635 | qlt_schedule_sess_for_deletion(cmd->sess, true); |
| 3636 | } |
| 3637 | break; |
| 3638 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3639 | case CTIO_SRR_RECEIVED: |
| 3640 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05a, |
| 3641 | "qla_target(%d): CTIO with SRR_RECEIVED" |
| 3642 | " status %x received (state %x, se_cmd %p)\n", |
| 3643 | vha->vp_idx, status, cmd->state, se_cmd); |
| 3644 | if (qlt_prepare_srr_ctio(vha, cmd, ctio) != 0) |
| 3645 | break; |
| 3646 | else |
| 3647 | return; |
| 3648 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3649 | case CTIO_DIF_ERROR: { |
| 3650 | struct ctio_crc_from_fw *crc = |
| 3651 | (struct ctio_crc_from_fw *)ctio; |
| 3652 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, |
| 3653 | "qla_target(%d): CTIO with DIF_ERROR status %x received (state %x, se_cmd %p) actual_dif[0x%llx] expect_dif[0x%llx]\n", |
| 3654 | vha->vp_idx, status, cmd->state, se_cmd, |
| 3655 | *((u64 *)&crc->actual_dif[0]), |
| 3656 | *((u64 *)&crc->expected_dif[0])); |
| 3657 | |
| 3658 | if (qlt_handle_dif_error(vha, cmd, ctio)) { |
| 3659 | if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 3660 | /* scsi Write/xfer rdy complete */ |
| 3661 | goto skip_term; |
| 3662 | } else { |
| 3663 | /* scsi read/xmit respond complete |
| 3664 | * call handle dif to send scsi status |
| 3665 | * rather than terminate exchange. |
| 3666 | */ |
| 3667 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3668 | ha->tgt.tgt_ops->handle_dif_err(cmd); |
| 3669 | return; |
| 3670 | } |
| 3671 | } else { |
| 3672 | /* Need to generate a SCSI good completion. |
| 3673 | * because FW did not send scsi status. |
| 3674 | */ |
| 3675 | status = 0; |
| 3676 | goto skip_term; |
| 3677 | } |
| 3678 | break; |
| 3679 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3680 | default: |
| 3681 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3682 | "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] | 3683 | vha->vp_idx, status, cmd->state, se_cmd); |
| 3684 | break; |
| 3685 | } |
| 3686 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3687 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3688 | /* "cmd->aborted" means |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3689 | * cmd is already aborted/terminated, we don't |
| 3690 | * need to terminate again. The exchange is already |
| 3691 | * cleaned up/freed at FW level. Just cleanup at driver |
| 3692 | * level. |
| 3693 | */ |
| 3694 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3695 | (!cmd->aborted)) { |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3696 | cmd->cmd_flags |= BIT_13; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3697 | if (qlt_term_ctio_exchange(vha, ctio, cmd, status)) |
| 3698 | return; |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3699 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3700 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3701 | skip_term: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3702 | |
| 3703 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
Quinn Tran | e5fdee8 | 2015-06-10 11:05:21 -0400 | [diff] [blame] | 3704 | cmd->cmd_flags |= BIT_12; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3705 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3706 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3707 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 3708 | if (status == CTIO_SUCCESS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3709 | cmd->write_data_transferred = 1; |
| 3710 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3711 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3712 | return; |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3713 | } else if (cmd->aborted) { |
Quinn Tran | e5fdee8 | 2015-06-10 11:05:21 -0400 | [diff] [blame] | 3714 | cmd->cmd_flags |= BIT_18; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3715 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 3716 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3717 | } else { |
Quinn Tran | e5fdee8 | 2015-06-10 11:05:21 -0400 | [diff] [blame] | 3718 | cmd->cmd_flags |= BIT_19; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3719 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
| 3720 | "qla_target(%d): A command in state (%d) should " |
| 3721 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); |
| 3722 | } |
| 3723 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3724 | if (unlikely(status != CTIO_SUCCESS) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3725 | !cmd->aborted) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3726 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
| 3727 | dump_stack(); |
| 3728 | } |
| 3729 | |
| 3730 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3731 | } |
| 3732 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3733 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
| 3734 | uint8_t task_codes) |
| 3735 | { |
| 3736 | int fcp_task_attr; |
| 3737 | |
| 3738 | switch (task_codes) { |
| 3739 | case ATIO_SIMPLE_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3740 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3741 | break; |
| 3742 | case ATIO_HEAD_OF_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3743 | fcp_task_attr = TCM_HEAD_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3744 | break; |
| 3745 | case ATIO_ORDERED_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3746 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3747 | break; |
| 3748 | case ATIO_ACA_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3749 | fcp_task_attr = TCM_ACA_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3750 | break; |
| 3751 | case ATIO_UNTAGGED: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3752 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3753 | break; |
| 3754 | default: |
| 3755 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, |
| 3756 | "qla_target: unknown task code %x, use ORDERED instead\n", |
| 3757 | task_codes); |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3758 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3759 | break; |
| 3760 | } |
| 3761 | |
| 3762 | return fcp_task_attr; |
| 3763 | } |
| 3764 | |
| 3765 | static struct qla_tgt_sess *qlt_make_local_sess(struct scsi_qla_host *, |
| 3766 | uint8_t *); |
| 3767 | /* |
| 3768 | * Process context for I/O path into tcm_qla2xxx code |
| 3769 | */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3770 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3771 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3772 | scsi_qla_host_t *vha = cmd->vha; |
| 3773 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 3774 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3775 | struct qla_tgt_sess *sess = cmd->sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3776 | struct atio_from_isp *atio = &cmd->atio; |
| 3777 | unsigned char *cdb; |
| 3778 | unsigned long flags; |
| 3779 | uint32_t data_length; |
| 3780 | int ret, fcp_task_attr, data_dir, bidi = 0; |
| 3781 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3782 | cmd->cmd_in_wq = 0; |
| 3783 | cmd->cmd_flags |= BIT_1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3784 | if (tgt->tgt_stop) |
| 3785 | goto out_term; |
| 3786 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3787 | if (cmd->aborted) { |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 3788 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082, |
| 3789 | "cmd with tag %u is aborted\n", |
| 3790 | cmd->atio.u.isp24.exchange_addr); |
| 3791 | goto out_term; |
| 3792 | } |
| 3793 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3794 | spin_lock_init(&cmd->cmd_lock); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3795 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 3796 | cmd->se_cmd.tag = atio->u.isp24.exchange_addr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3797 | cmd->unpacked_lun = scsilun_to_int( |
| 3798 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); |
| 3799 | |
| 3800 | if (atio->u.isp24.fcp_cmnd.rddata && |
| 3801 | atio->u.isp24.fcp_cmnd.wrdata) { |
| 3802 | bidi = 1; |
| 3803 | data_dir = DMA_TO_DEVICE; |
| 3804 | } else if (atio->u.isp24.fcp_cmnd.rddata) |
| 3805 | data_dir = DMA_FROM_DEVICE; |
| 3806 | else if (atio->u.isp24.fcp_cmnd.wrdata) |
| 3807 | data_dir = DMA_TO_DEVICE; |
| 3808 | else |
| 3809 | data_dir = DMA_NONE; |
| 3810 | |
| 3811 | fcp_task_attr = qlt_get_fcp_task_attr(vha, |
| 3812 | atio->u.isp24.fcp_cmnd.task_attr); |
| 3813 | data_length = be32_to_cpu(get_unaligned((uint32_t *) |
| 3814 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 3815 | atio->u.isp24.fcp_cmnd.add_cdb_len])); |
| 3816 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3817 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
| 3818 | fcp_task_attr, data_dir, bidi); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3819 | if (ret != 0) |
| 3820 | goto out_term; |
| 3821 | /* |
| 3822 | * Drop extra session reference from qla_tgt_handle_cmd_for_atio*( |
| 3823 | */ |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3824 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 3825 | qlt_put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3826 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3827 | return; |
| 3828 | |
| 3829 | out_term: |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3830 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3831 | /* |
Roland Dreier | fae9eaf | 2012-06-11 18:23:16 -0700 | [diff] [blame] | 3832 | * cmd has not sent to target yet, so pass NULL as the second |
| 3833 | * argument to qlt_send_term_exchange() and free the memory here. |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3834 | */ |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3835 | cmd->cmd_flags |= BIT_2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3836 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3837 | qlt_send_term_exchange(vha, NULL, &cmd->atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3838 | |
| 3839 | qlt_decr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3840 | 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] | 3841 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3842 | |
| 3843 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 3844 | qlt_put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 3845 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3846 | } |
| 3847 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3848 | static void qlt_do_work(struct work_struct *work) |
| 3849 | { |
| 3850 | 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] | 3851 | scsi_qla_host_t *vha = cmd->vha; |
| 3852 | unsigned long flags; |
| 3853 | |
| 3854 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 3855 | list_del(&cmd->cmd_list); |
| 3856 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3857 | |
| 3858 | __qlt_do_work(cmd); |
| 3859 | } |
| 3860 | |
| 3861 | static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha, |
| 3862 | struct qla_tgt_sess *sess, |
| 3863 | struct atio_from_isp *atio) |
| 3864 | { |
| 3865 | struct se_session *se_sess = sess->se_sess; |
| 3866 | struct qla_tgt_cmd *cmd; |
| 3867 | int tag; |
| 3868 | |
| 3869 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 3870 | if (tag < 0) |
| 3871 | return NULL; |
| 3872 | |
| 3873 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 3874 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 3875 | |
| 3876 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 3877 | cmd->state = QLA_TGT_STATE_NEW; |
| 3878 | cmd->tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3879 | qlt_incr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3880 | cmd->vha = vha; |
| 3881 | cmd->se_cmd.map_tag = tag; |
| 3882 | cmd->sess = sess; |
| 3883 | cmd->loop_id = sess->loop_id; |
| 3884 | cmd->conf_compl_supported = sess->conf_compl_supported; |
| 3885 | |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 3886 | cmd->cmd_flags = 0; |
| 3887 | cmd->jiffies_at_alloc = get_jiffies_64(); |
| 3888 | |
| 3889 | cmd->reset_count = vha->hw->chip_reset; |
| 3890 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3891 | return cmd; |
| 3892 | } |
| 3893 | |
| 3894 | static void qlt_send_busy(struct scsi_qla_host *, struct atio_from_isp *, |
| 3895 | uint16_t); |
| 3896 | |
| 3897 | static void qlt_create_sess_from_atio(struct work_struct *work) |
| 3898 | { |
| 3899 | struct qla_tgt_sess_op *op = container_of(work, |
| 3900 | struct qla_tgt_sess_op, work); |
| 3901 | scsi_qla_host_t *vha = op->vha; |
| 3902 | struct qla_hw_data *ha = vha->hw; |
| 3903 | struct qla_tgt_sess *sess; |
| 3904 | struct qla_tgt_cmd *cmd; |
| 3905 | unsigned long flags; |
| 3906 | uint8_t *s_id = op->atio.u.isp24.fcp_hdr.s_id; |
| 3907 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 3908 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 3909 | list_del(&op->cmd_list); |
| 3910 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 3911 | |
| 3912 | if (op->aborted) { |
| 3913 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf083, |
| 3914 | "sess_op with tag %u is aborted\n", |
| 3915 | op->atio.u.isp24.exchange_addr); |
| 3916 | goto out_term; |
| 3917 | } |
| 3918 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3919 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf022, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 3920 | "qla_target(%d): Unable to find wwn login" |
| 3921 | " (s_id %x:%x:%x), trying to create it manually\n", |
| 3922 | vha->vp_idx, s_id[0], s_id[1], s_id[2]); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3923 | |
| 3924 | if (op->atio.u.raw.entry_count > 1) { |
| 3925 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf023, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 3926 | "Dropping multy entry atio %p\n", &op->atio); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3927 | goto out_term; |
| 3928 | } |
| 3929 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3930 | sess = qlt_make_local_sess(vha, s_id); |
| 3931 | /* sess has an extra creation ref. */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3932 | |
| 3933 | if (!sess) |
| 3934 | goto out_term; |
| 3935 | /* |
| 3936 | * Now obtain a pre-allocated session tag using the original op->atio |
| 3937 | * packet header, and dispatch into __qlt_do_work() using the existing |
| 3938 | * process context. |
| 3939 | */ |
| 3940 | cmd = qlt_get_tag(vha, sess, &op->atio); |
| 3941 | if (!cmd) { |
| 3942 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3943 | qlt_send_busy(vha, &op->atio, SAM_STAT_BUSY); |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 3944 | qlt_put_sess(sess); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3945 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3946 | kfree(op); |
| 3947 | return; |
| 3948 | } |
| 3949 | /* |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 3950 | * __qlt_do_work() will call qlt_put_sess() to release |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3951 | * the extra reference taken above by qlt_make_local_sess() |
| 3952 | */ |
| 3953 | __qlt_do_work(cmd); |
| 3954 | kfree(op); |
| 3955 | return; |
| 3956 | |
| 3957 | out_term: |
| 3958 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3959 | qlt_send_term_exchange(vha, NULL, &op->atio, 1, 0); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3960 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3961 | kfree(op); |
| 3962 | |
| 3963 | } |
| 3964 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3965 | /* ha->hardware_lock supposed to be held on entry */ |
| 3966 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, |
| 3967 | struct atio_from_isp *atio) |
| 3968 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3969 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 3970 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3971 | struct qla_tgt_sess *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3972 | struct qla_tgt_cmd *cmd; |
| 3973 | |
| 3974 | if (unlikely(tgt->tgt_stop)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3975 | ql_dbg(ql_dbg_io, vha, 0x3061, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3976 | "New command while device %p is shutting down\n", tgt); |
| 3977 | return -EFAULT; |
| 3978 | } |
| 3979 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3980 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id); |
| 3981 | if (unlikely(!sess)) { |
| 3982 | struct qla_tgt_sess_op *op = kzalloc(sizeof(struct qla_tgt_sess_op), |
| 3983 | GFP_ATOMIC); |
| 3984 | if (!op) |
| 3985 | return -ENOMEM; |
| 3986 | |
| 3987 | memcpy(&op->atio, atio, sizeof(*atio)); |
Himanshu Madhani | 78c2106 | 2014-09-25 06:14:44 -0400 | [diff] [blame] | 3988 | op->vha = vha; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 3989 | |
| 3990 | spin_lock(&vha->cmd_list_lock); |
| 3991 | list_add_tail(&op->cmd_list, &vha->qla_sess_op_cmd_list); |
| 3992 | spin_unlock(&vha->cmd_list_lock); |
| 3993 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3994 | INIT_WORK(&op->work, qlt_create_sess_from_atio); |
| 3995 | queue_work(qla_tgt_wq, &op->work); |
| 3996 | return 0; |
| 3997 | } |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 3998 | |
| 3999 | /* Another WWN used to have our s_id. Our PLOGI scheduled its |
| 4000 | * session deletion, but it's still in sess_del_work wq */ |
| 4001 | if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
| 4002 | ql_dbg(ql_dbg_io, vha, 0x3061, |
| 4003 | "New command while old session %p is being deleted\n", |
| 4004 | sess); |
| 4005 | return -EFAULT; |
| 4006 | } |
| 4007 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4008 | /* |
| 4009 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. |
| 4010 | */ |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 4011 | kref_get(&sess->sess_kref); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4012 | |
| 4013 | cmd = qlt_get_tag(vha, sess, atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4014 | if (!cmd) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4015 | ql_dbg(ql_dbg_io, vha, 0x3062, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4016 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 4017 | qlt_put_sess(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4018 | return -ENOMEM; |
| 4019 | } |
| 4020 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4021 | cmd->cmd_in_wq = 1; |
| 4022 | cmd->cmd_flags |= BIT_0; |
Quinn Tran | 5327c7d | 2016-02-10 18:59:14 -0500 | [diff] [blame] | 4023 | cmd->se_cmd.cpuid = ha->msix_count ? |
| 4024 | ha->tgt.rspq_vector_cpuid : WORK_CPU_UNBOUND; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4025 | |
| 4026 | spin_lock(&vha->cmd_list_lock); |
| 4027 | list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list); |
| 4028 | spin_unlock(&vha->cmd_list_lock); |
| 4029 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4030 | INIT_WORK(&cmd->work, qlt_do_work); |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4031 | if (ha->msix_count) { |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4032 | if (cmd->atio.u.isp24.fcp_cmnd.rddata) |
| 4033 | queue_work_on(smp_processor_id(), qla_tgt_wq, |
| 4034 | &cmd->work); |
| 4035 | else |
| 4036 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, |
| 4037 | &cmd->work); |
| 4038 | } else { |
| 4039 | queue_work(qla_tgt_wq, &cmd->work); |
| 4040 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4041 | return 0; |
| 4042 | |
| 4043 | } |
| 4044 | |
| 4045 | /* ha->hardware_lock supposed to be held on entry */ |
| 4046 | static int qlt_issue_task_mgmt(struct qla_tgt_sess *sess, uint32_t lun, |
| 4047 | int fn, void *iocb, int flags) |
| 4048 | { |
| 4049 | struct scsi_qla_host *vha = sess->vha; |
| 4050 | struct qla_hw_data *ha = vha->hw; |
| 4051 | struct qla_tgt_mgmt_cmd *mcmd; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4052 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4053 | int res; |
| 4054 | uint8_t tmr_func; |
| 4055 | |
| 4056 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4057 | if (!mcmd) { |
| 4058 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, |
| 4059 | "qla_target(%d): Allocation of management " |
| 4060 | "command failed, some commands and their data could " |
| 4061 | "leak\n", vha->vp_idx); |
| 4062 | return -ENOMEM; |
| 4063 | } |
| 4064 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4065 | mcmd->sess = sess; |
| 4066 | |
| 4067 | if (iocb) { |
| 4068 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4069 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4070 | } |
| 4071 | mcmd->tmr_func = fn; |
| 4072 | mcmd->flags = flags; |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 4073 | mcmd->reset_count = vha->hw->chip_reset; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4074 | |
| 4075 | switch (fn) { |
| 4076 | case QLA_TGT_CLEAR_ACA: |
| 4077 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10000, |
| 4078 | "qla_target(%d): CLEAR_ACA received\n", sess->vha->vp_idx); |
| 4079 | tmr_func = TMR_CLEAR_ACA; |
| 4080 | break; |
| 4081 | |
| 4082 | case QLA_TGT_TARGET_RESET: |
| 4083 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10001, |
| 4084 | "qla_target(%d): TARGET_RESET received\n", |
| 4085 | sess->vha->vp_idx); |
| 4086 | tmr_func = TMR_TARGET_WARM_RESET; |
| 4087 | break; |
| 4088 | |
| 4089 | case QLA_TGT_LUN_RESET: |
| 4090 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10002, |
| 4091 | "qla_target(%d): LUN_RESET received\n", sess->vha->vp_idx); |
| 4092 | tmr_func = TMR_LUN_RESET; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4093 | abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4094 | break; |
| 4095 | |
| 4096 | case QLA_TGT_CLEAR_TS: |
| 4097 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10003, |
| 4098 | "qla_target(%d): CLEAR_TS received\n", sess->vha->vp_idx); |
| 4099 | tmr_func = TMR_CLEAR_TASK_SET; |
| 4100 | break; |
| 4101 | |
| 4102 | case QLA_TGT_ABORT_TS: |
| 4103 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10004, |
| 4104 | "qla_target(%d): ABORT_TS received\n", sess->vha->vp_idx); |
| 4105 | tmr_func = TMR_ABORT_TASK_SET; |
| 4106 | break; |
| 4107 | #if 0 |
| 4108 | case QLA_TGT_ABORT_ALL: |
| 4109 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10005, |
| 4110 | "qla_target(%d): Doing ABORT_ALL_TASKS\n", |
| 4111 | sess->vha->vp_idx); |
| 4112 | tmr_func = 0; |
| 4113 | break; |
| 4114 | |
| 4115 | case QLA_TGT_ABORT_ALL_SESS: |
| 4116 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10006, |
| 4117 | "qla_target(%d): Doing ABORT_ALL_TASKS_SESS\n", |
| 4118 | sess->vha->vp_idx); |
| 4119 | tmr_func = 0; |
| 4120 | break; |
| 4121 | |
| 4122 | case QLA_TGT_NEXUS_LOSS_SESS: |
| 4123 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10007, |
| 4124 | "qla_target(%d): Doing NEXUS_LOSS_SESS\n", |
| 4125 | sess->vha->vp_idx); |
| 4126 | tmr_func = 0; |
| 4127 | break; |
| 4128 | |
| 4129 | case QLA_TGT_NEXUS_LOSS: |
| 4130 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10008, |
| 4131 | "qla_target(%d): Doing NEXUS_LOSS\n", sess->vha->vp_idx); |
| 4132 | tmr_func = 0; |
| 4133 | break; |
| 4134 | #endif |
| 4135 | default: |
| 4136 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000a, |
| 4137 | "qla_target(%d): Unknown task mgmt fn 0x%x\n", |
| 4138 | sess->vha->vp_idx, fn); |
| 4139 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4140 | return -ENOSYS; |
| 4141 | } |
| 4142 | |
| 4143 | res = ha->tgt.tgt_ops->handle_tmr(mcmd, lun, tmr_func, 0); |
| 4144 | if (res != 0) { |
| 4145 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000b, |
| 4146 | "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n", |
| 4147 | sess->vha->vp_idx, res); |
| 4148 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4149 | return -EFAULT; |
| 4150 | } |
| 4151 | |
| 4152 | return 0; |
| 4153 | } |
| 4154 | |
| 4155 | /* ha->hardware_lock supposed to be held on entry */ |
| 4156 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) |
| 4157 | { |
| 4158 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4159 | struct qla_hw_data *ha = vha->hw; |
| 4160 | struct qla_tgt *tgt; |
| 4161 | struct qla_tgt_sess *sess; |
| 4162 | uint32_t lun, unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4163 | int fn; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4164 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4165 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4166 | tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4167 | |
| 4168 | lun = a->u.isp24.fcp_cmnd.lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4169 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4170 | |
| 4171 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4172 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4173 | a->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4174 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4175 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4176 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); |
| 4177 | |
| 4178 | if (!sess) { |
| 4179 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf024, |
| 4180 | "qla_target(%d): task mgmt fn 0x%x for " |
| 4181 | "non-existant session\n", vha->vp_idx, fn); |
| 4182 | return qlt_sched_sess_work(tgt, QLA_TGT_SESS_WORK_TM, iocb, |
| 4183 | sizeof(struct atio_from_isp)); |
| 4184 | } |
| 4185 | |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4186 | if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) |
| 4187 | return -EFAULT; |
| 4188 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4189 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 4190 | } |
| 4191 | |
| 4192 | /* ha->hardware_lock supposed to be held on entry */ |
| 4193 | static int __qlt_abort_task(struct scsi_qla_host *vha, |
| 4194 | struct imm_ntfy_from_isp *iocb, struct qla_tgt_sess *sess) |
| 4195 | { |
| 4196 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4197 | struct qla_hw_data *ha = vha->hw; |
| 4198 | struct qla_tgt_mgmt_cmd *mcmd; |
| 4199 | uint32_t lun, unpacked_lun; |
| 4200 | int rc; |
| 4201 | |
| 4202 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4203 | if (mcmd == NULL) { |
| 4204 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, |
| 4205 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", |
| 4206 | vha->vp_idx, __func__); |
| 4207 | return -ENOMEM; |
| 4208 | } |
| 4209 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4210 | |
| 4211 | mcmd->sess = sess; |
| 4212 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4213 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4214 | |
| 4215 | lun = a->u.isp24.fcp_cmnd.lun; |
| 4216 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); |
Arun Easi | 80187f8 | 2014-09-25 06:14:53 -0400 | [diff] [blame] | 4217 | mcmd->reset_count = vha->hw->chip_reset; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4218 | |
| 4219 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, unpacked_lun, TMR_ABORT_TASK, |
| 4220 | le16_to_cpu(iocb->u.isp2x.seq_id)); |
| 4221 | if (rc != 0) { |
| 4222 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, |
| 4223 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 4224 | vha->vp_idx, rc); |
| 4225 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4226 | return -EFAULT; |
| 4227 | } |
| 4228 | |
| 4229 | return 0; |
| 4230 | } |
| 4231 | |
| 4232 | /* ha->hardware_lock supposed to be held on entry */ |
| 4233 | static int qlt_abort_task(struct scsi_qla_host *vha, |
| 4234 | struct imm_ntfy_from_isp *iocb) |
| 4235 | { |
| 4236 | struct qla_hw_data *ha = vha->hw; |
| 4237 | struct qla_tgt_sess *sess; |
| 4238 | int loop_id; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4239 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4240 | |
| 4241 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); |
| 4242 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4243 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4244 | 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] | 4245 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4246 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4247 | if (sess == NULL) { |
| 4248 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, |
| 4249 | "qla_target(%d): task abort for unexisting " |
| 4250 | "session\n", vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4251 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4252 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
| 4253 | } |
| 4254 | |
| 4255 | return __qlt_abort_task(vha, iocb, sess); |
| 4256 | } |
| 4257 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4258 | void qlt_logo_completion_handler(fc_port_t *fcport, int rc) |
| 4259 | { |
| 4260 | if (fcport->tgt_session) { |
| 4261 | if (rc != MBS_COMMAND_COMPLETE) { |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4262 | ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4263 | "%s: se_sess %p / sess %p from" |
| 4264 | " port %8phC loop_id %#04x s_id %02x:%02x:%02x" |
| 4265 | " LOGO failed: %#x\n", |
| 4266 | __func__, |
| 4267 | fcport->tgt_session->se_sess, |
| 4268 | fcport->tgt_session, |
| 4269 | fcport->port_name, fcport->loop_id, |
| 4270 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4271 | fcport->d_id.b.al_pa, rc); |
| 4272 | } |
| 4273 | |
| 4274 | fcport->tgt_session->logout_completed = 1; |
| 4275 | } |
| 4276 | } |
| 4277 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4278 | /* |
| 4279 | * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) |
| 4280 | * |
| 4281 | * Schedules sessions with matching port_id/loop_id but different wwn for |
| 4282 | * deletion. Returns existing session with matching wwn if present. |
| 4283 | * Null otherwise. |
| 4284 | */ |
| 4285 | static struct qla_tgt_sess * |
| 4286 | qlt_find_sess_invalidate_other(struct qla_tgt *tgt, uint64_t wwn, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4287 | port_id_t port_id, uint16_t loop_id, struct qla_tgt_sess **conflict_sess) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4288 | { |
| 4289 | struct qla_tgt_sess *sess = NULL, *other_sess; |
| 4290 | uint64_t other_wwn; |
| 4291 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4292 | *conflict_sess = NULL; |
| 4293 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4294 | list_for_each_entry(other_sess, &tgt->sess_list, sess_list_entry) { |
| 4295 | |
| 4296 | other_wwn = wwn_to_u64(other_sess->port_name); |
| 4297 | |
| 4298 | if (wwn == other_wwn) { |
| 4299 | WARN_ON(sess); |
| 4300 | sess = other_sess; |
| 4301 | continue; |
| 4302 | } |
| 4303 | |
| 4304 | /* find other sess with nport_id collision */ |
| 4305 | if (port_id.b24 == other_sess->s_id.b24) { |
| 4306 | if (loop_id != other_sess->loop_id) { |
| 4307 | ql_dbg(ql_dbg_tgt_tmr, tgt->vha, 0x1000c, |
| 4308 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4309 | other_sess, other_sess->loop_id, other_wwn); |
| 4310 | |
| 4311 | /* |
| 4312 | * logout_on_delete is set by default, but another |
| 4313 | * session that has the same s_id/loop_id combo |
| 4314 | * might have cleared it when requested this session |
| 4315 | * deletion, so don't touch it |
| 4316 | */ |
| 4317 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4318 | } else { |
| 4319 | /* |
| 4320 | * Another wwn used to have our s_id/loop_id |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4321 | * kill the session, but don't free the loop_id |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4322 | */ |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4323 | other_sess->keep_nport_handle = 1; |
| 4324 | *conflict_sess = other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4325 | qlt_schedule_sess_for_deletion(other_sess, |
| 4326 | true); |
| 4327 | } |
| 4328 | continue; |
| 4329 | } |
| 4330 | |
| 4331 | /* find other sess with nport handle collision */ |
| 4332 | if (loop_id == other_sess->loop_id) { |
| 4333 | ql_dbg(ql_dbg_tgt_tmr, tgt->vha, 0x1000d, |
| 4334 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4335 | other_sess, other_sess->loop_id, other_wwn); |
| 4336 | |
| 4337 | /* Same loop_id but different s_id |
| 4338 | * Ok to kill and logout */ |
| 4339 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4340 | } |
| 4341 | } |
| 4342 | |
| 4343 | return sess; |
| 4344 | } |
| 4345 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4346 | /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */ |
| 4347 | static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id) |
| 4348 | { |
| 4349 | struct qla_tgt_sess_op *op; |
| 4350 | struct qla_tgt_cmd *cmd; |
| 4351 | uint32_t key; |
| 4352 | int count = 0; |
| 4353 | |
| 4354 | key = (((u32)s_id->b.domain << 16) | |
| 4355 | ((u32)s_id->b.area << 8) | |
| 4356 | ((u32)s_id->b.al_pa)); |
| 4357 | |
| 4358 | spin_lock(&vha->cmd_list_lock); |
| 4359 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 4360 | uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 4361 | if (op_key == key) { |
| 4362 | op->aborted = true; |
| 4363 | count++; |
| 4364 | } |
| 4365 | } |
| 4366 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 4367 | uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 4368 | if (cmd_key == key) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4369 | cmd->aborted = 1; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4370 | count++; |
| 4371 | } |
| 4372 | } |
| 4373 | spin_unlock(&vha->cmd_list_lock); |
| 4374 | |
| 4375 | return count; |
| 4376 | } |
| 4377 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4378 | /* |
| 4379 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4380 | */ |
| 4381 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, |
| 4382 | struct imm_ntfy_from_isp *iocb) |
| 4383 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4384 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4385 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4386 | struct qla_tgt_sess *sess = NULL, *conflict_sess = NULL; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4387 | uint64_t wwn; |
| 4388 | port_id_t port_id; |
| 4389 | uint16_t loop_id; |
| 4390 | uint16_t wd3_lo; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4391 | int res = 0; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4392 | qlt_plogi_ack_t *pla; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4393 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4394 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4395 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4396 | |
| 4397 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4398 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4399 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4400 | port_id.b.rsvd_1 = 0; |
| 4401 | |
| 4402 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4403 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4404 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf026, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4405 | "qla_target(%d): Port ID: 0x%3phC ELS opcode: 0x%02x\n", |
| 4406 | vha->vp_idx, iocb->u.isp24.port_id, iocb->u.isp24.status_subcode); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4407 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4408 | /* res = 1 means ack at the end of thread |
| 4409 | * res = 0 means ack async/later. |
| 4410 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4411 | switch (iocb->u.isp24.status_subcode) { |
| 4412 | case ELS_PLOGI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4413 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4414 | /* Mark all stale commands in qla_tgt_wq for deletion */ |
| 4415 | abort_cmds_for_s_id(vha, &port_id); |
| 4416 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4417 | if (wwn) { |
| 4418 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4419 | sess = qlt_find_sess_invalidate_other(tgt, wwn, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4420 | port_id, loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4421 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4422 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4423 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4424 | if (IS_SW_RESV_ADDR(port_id) || (!sess && !conflict_sess)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4425 | res = 1; |
| 4426 | break; |
| 4427 | } |
| 4428 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4429 | pla = qlt_plogi_ack_find_add(vha, &port_id, iocb); |
| 4430 | if (!pla) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4431 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4432 | |
| 4433 | res = 0; |
| 4434 | break; |
| 4435 | } |
| 4436 | |
| 4437 | res = 0; |
| 4438 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4439 | if (conflict_sess) |
| 4440 | qlt_plogi_ack_link(vha, pla, conflict_sess, |
| 4441 | QLT_PLOGI_LINK_CONFLICT); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4442 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4443 | if (!sess) |
| 4444 | break; |
| 4445 | |
| 4446 | qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4447 | /* |
| 4448 | * Under normal circumstances we want to release nport handle |
| 4449 | * during LOGO process to avoid nport handle leaks inside FW. |
| 4450 | * The exception is when LOGO is done while another PLOGI with |
| 4451 | * the same nport handle is waiting as might be the case here. |
| 4452 | * Note: there is always a possibily of a race where session |
| 4453 | * deletion has already started for other reasons (e.g. ACL |
| 4454 | * removal) and now PLOGI arrives: |
| 4455 | * 1. if PLOGI arrived in FW after nport handle has been freed, |
| 4456 | * FW must have assigned this PLOGI a new/same handle and we |
| 4457 | * can proceed ACK'ing it as usual when session deletion |
| 4458 | * completes. |
| 4459 | * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT |
| 4460 | * bit reached it, the handle has now been released. We'll |
| 4461 | * get an error when we ACK this PLOGI. Nothing will be sent |
| 4462 | * back to initiator. Initiator should eventually retry |
| 4463 | * PLOGI and situation will correct itself. |
| 4464 | */ |
| 4465 | sess->keep_nport_handle = ((sess->loop_id == loop_id) && |
| 4466 | (sess->s_id.b24 == port_id.b24)); |
| 4467 | qlt_schedule_sess_for_deletion(sess, true); |
| 4468 | break; |
| 4469 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4470 | case ELS_PRLI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4471 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4472 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4473 | if (wwn) { |
| 4474 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4475 | sess = qlt_find_sess_invalidate_other(tgt, wwn, port_id, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4476 | loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4477 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4478 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4479 | |
| 4480 | if (conflict_sess) { |
| 4481 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b, |
| 4482 | "PRLI with conflicting sess %p port %8phC\n", |
| 4483 | conflict_sess, conflict_sess->port_name); |
| 4484 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4485 | res = 0; |
| 4486 | break; |
| 4487 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4488 | |
| 4489 | if (sess != NULL) { |
| 4490 | if (sess->deleted) { |
| 4491 | /* |
| 4492 | * Impatient initiator sent PRLI before last |
| 4493 | * PLOGI could finish. Will force him to re-try, |
| 4494 | * while last one finishes. |
| 4495 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4496 | ql_log(ql_log_warn, sess->vha, 0xf095, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4497 | "sess %p PRLI received, before plogi ack.\n", |
| 4498 | sess); |
| 4499 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4500 | res = 0; |
| 4501 | break; |
| 4502 | } |
| 4503 | |
| 4504 | /* |
| 4505 | * This shouldn't happen under normal circumstances, |
| 4506 | * since we have deleted the old session during PLOGI |
| 4507 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4508 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4509 | "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n", |
| 4510 | sess->loop_id, sess, iocb->u.isp24.nport_handle); |
| 4511 | |
| 4512 | sess->local = 0; |
| 4513 | sess->loop_id = loop_id; |
| 4514 | sess->s_id = port_id; |
| 4515 | |
| 4516 | if (wd3_lo & BIT_7) |
| 4517 | sess->conf_compl_supported = 1; |
| 4518 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4519 | } |
| 4520 | res = 1; /* send notify ack */ |
| 4521 | |
| 4522 | /* Make session global (not used in fabric mode) */ |
| 4523 | if (ha->current_topology != ISP_CFG_F) { |
| 4524 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4525 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4526 | qla2xxx_wake_dpc(vha); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4527 | } else { |
| 4528 | /* todo: else - create sess here. */ |
| 4529 | res = 1; /* send notify ack */ |
| 4530 | } |
| 4531 | |
| 4532 | break; |
| 4533 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4534 | case ELS_LOGO: |
| 4535 | case ELS_PRLO: |
| 4536 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 4537 | break; |
| 4538 | case ELS_PDISC: |
| 4539 | case ELS_ADISC: |
| 4540 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4541 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4542 | if (tgt->link_reinit_iocb_pending) { |
| 4543 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, |
| 4544 | 0, 0, 0, 0, 0, 0); |
| 4545 | tgt->link_reinit_iocb_pending = 0; |
| 4546 | } |
| 4547 | res = 1; /* send notify ack */ |
| 4548 | break; |
| 4549 | } |
| 4550 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4551 | case ELS_FLOGI: /* should never happen */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4552 | default: |
| 4553 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, |
| 4554 | "qla_target(%d): Unsupported ELS command %x " |
| 4555 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); |
| 4556 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 4557 | break; |
| 4558 | } |
| 4559 | |
| 4560 | return res; |
| 4561 | } |
| 4562 | |
| 4563 | static int qlt_set_data_offset(struct qla_tgt_cmd *cmd, uint32_t offset) |
| 4564 | { |
Bart Van Assche | 5897cb2 | 2015-06-04 15:57:20 -0700 | [diff] [blame] | 4565 | #if 1 |
| 4566 | /* |
| 4567 | * FIXME: Reject non zero SRR relative offset until we can test |
| 4568 | * this code properly. |
| 4569 | */ |
| 4570 | pr_debug("Rejecting non zero SRR rel_offs: %u\n", offset); |
| 4571 | return -1; |
| 4572 | #else |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4573 | struct scatterlist *sg, *sgp, *sg_srr, *sg_srr_start = NULL; |
| 4574 | size_t first_offset = 0, rem_offset = offset, tmp = 0; |
| 4575 | int i, sg_srr_cnt, bufflen = 0; |
| 4576 | |
| 4577 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe023, |
| 4578 | "Entering qla_tgt_set_data_offset: cmd: %p, cmd->sg: %p, " |
| 4579 | "cmd->sg_cnt: %u, direction: %d\n", |
| 4580 | cmd, cmd->sg, cmd->sg_cnt, cmd->dma_data_direction); |
| 4581 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4582 | if (!cmd->sg || !cmd->sg_cnt) { |
| 4583 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe055, |
| 4584 | "Missing cmd->sg or zero cmd->sg_cnt in" |
| 4585 | " qla_tgt_set_data_offset\n"); |
| 4586 | return -EINVAL; |
| 4587 | } |
| 4588 | /* |
| 4589 | * Walk the current cmd->sg list until we locate the new sg_srr_start |
| 4590 | */ |
| 4591 | for_each_sg(cmd->sg, sg, cmd->sg_cnt, i) { |
| 4592 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe024, |
| 4593 | "sg[%d]: %p page: %p, length: %d, offset: %d\n", |
| 4594 | i, sg, sg_page(sg), sg->length, sg->offset); |
| 4595 | |
| 4596 | if ((sg->length + tmp) > offset) { |
| 4597 | first_offset = rem_offset; |
| 4598 | sg_srr_start = sg; |
| 4599 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe025, |
| 4600 | "Found matching sg[%d], using %p as sg_srr_start, " |
| 4601 | "and using first_offset: %zu\n", i, sg, |
| 4602 | first_offset); |
| 4603 | break; |
| 4604 | } |
| 4605 | tmp += sg->length; |
| 4606 | rem_offset -= sg->length; |
| 4607 | } |
| 4608 | |
| 4609 | if (!sg_srr_start) { |
| 4610 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe056, |
| 4611 | "Unable to locate sg_srr_start for offset: %u\n", offset); |
| 4612 | return -EINVAL; |
| 4613 | } |
| 4614 | sg_srr_cnt = (cmd->sg_cnt - i); |
| 4615 | |
| 4616 | sg_srr = kzalloc(sizeof(struct scatterlist) * sg_srr_cnt, GFP_KERNEL); |
| 4617 | if (!sg_srr) { |
| 4618 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe057, |
| 4619 | "Unable to allocate sgp\n"); |
| 4620 | return -ENOMEM; |
| 4621 | } |
| 4622 | sg_init_table(sg_srr, sg_srr_cnt); |
| 4623 | sgp = &sg_srr[0]; |
| 4624 | /* |
| 4625 | * Walk the remaining list for sg_srr_start, mapping to the newly |
| 4626 | * allocated sg_srr taking first_offset into account. |
| 4627 | */ |
| 4628 | for_each_sg(sg_srr_start, sg, sg_srr_cnt, i) { |
| 4629 | if (first_offset) { |
| 4630 | sg_set_page(sgp, sg_page(sg), |
| 4631 | (sg->length - first_offset), first_offset); |
| 4632 | first_offset = 0; |
| 4633 | } else { |
| 4634 | sg_set_page(sgp, sg_page(sg), sg->length, 0); |
| 4635 | } |
| 4636 | bufflen += sgp->length; |
| 4637 | |
| 4638 | sgp = sg_next(sgp); |
| 4639 | if (!sgp) |
| 4640 | break; |
| 4641 | } |
| 4642 | |
| 4643 | cmd->sg = sg_srr; |
| 4644 | cmd->sg_cnt = sg_srr_cnt; |
| 4645 | cmd->bufflen = bufflen; |
| 4646 | cmd->offset += offset; |
| 4647 | cmd->free_sg = 1; |
| 4648 | |
| 4649 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe026, "New cmd->sg: %p\n", cmd->sg); |
| 4650 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe027, "New cmd->sg_cnt: %u\n", |
| 4651 | cmd->sg_cnt); |
| 4652 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe028, "New cmd->bufflen: %u\n", |
| 4653 | cmd->bufflen); |
| 4654 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe029, "New cmd->offset: %u\n", |
| 4655 | cmd->offset); |
| 4656 | |
| 4657 | if (cmd->sg_cnt < 0) |
| 4658 | BUG(); |
| 4659 | |
| 4660 | if (cmd->bufflen < 0) |
| 4661 | BUG(); |
| 4662 | |
| 4663 | return 0; |
Bart Van Assche | 5897cb2 | 2015-06-04 15:57:20 -0700 | [diff] [blame] | 4664 | #endif |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4665 | } |
| 4666 | |
| 4667 | static inline int qlt_srr_adjust_data(struct qla_tgt_cmd *cmd, |
| 4668 | uint32_t srr_rel_offs, int *xmit_type) |
| 4669 | { |
| 4670 | int res = 0, rel_offs; |
| 4671 | |
| 4672 | rel_offs = srr_rel_offs - cmd->offset; |
| 4673 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf027, "srr_rel_offs=%d, rel_offs=%d", |
| 4674 | srr_rel_offs, rel_offs); |
| 4675 | |
| 4676 | *xmit_type = QLA_TGT_XMIT_ALL; |
| 4677 | |
| 4678 | if (rel_offs < 0) { |
| 4679 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf062, |
| 4680 | "qla_target(%d): SRR rel_offs (%d) < 0", |
| 4681 | cmd->vha->vp_idx, rel_offs); |
| 4682 | res = -1; |
| 4683 | } else if (rel_offs == cmd->bufflen) |
| 4684 | *xmit_type = QLA_TGT_XMIT_STATUS; |
| 4685 | else if (rel_offs > 0) |
| 4686 | res = qlt_set_data_offset(cmd, rel_offs); |
| 4687 | |
| 4688 | return res; |
| 4689 | } |
| 4690 | |
| 4691 | /* No locks, thread context */ |
| 4692 | static void qlt_handle_srr(struct scsi_qla_host *vha, |
| 4693 | struct qla_tgt_srr_ctio *sctio, struct qla_tgt_srr_imm *imm) |
| 4694 | { |
| 4695 | struct imm_ntfy_from_isp *ntfy = |
| 4696 | (struct imm_ntfy_from_isp *)&imm->imm_ntfy; |
| 4697 | struct qla_hw_data *ha = vha->hw; |
| 4698 | struct qla_tgt_cmd *cmd = sctio->cmd; |
| 4699 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 4700 | unsigned long flags; |
| 4701 | int xmit_type = 0, resp = 0; |
| 4702 | uint32_t offset; |
| 4703 | uint16_t srr_ui; |
| 4704 | |
| 4705 | offset = le32_to_cpu(ntfy->u.isp24.srr_rel_offs); |
| 4706 | srr_ui = ntfy->u.isp24.srr_ui; |
| 4707 | |
| 4708 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf028, "SRR cmd %p, srr_ui %x\n", |
| 4709 | cmd, srr_ui); |
| 4710 | |
| 4711 | switch (srr_ui) { |
| 4712 | case SRR_IU_STATUS: |
| 4713 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4714 | qlt_send_notify_ack(vha, ntfy, |
| 4715 | 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT, 0, 0); |
| 4716 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4717 | xmit_type = QLA_TGT_XMIT_STATUS; |
| 4718 | resp = 1; |
| 4719 | break; |
| 4720 | case SRR_IU_DATA_IN: |
| 4721 | if (!cmd->sg || !cmd->sg_cnt) { |
| 4722 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf063, |
| 4723 | "Unable to process SRR_IU_DATA_IN due to" |
| 4724 | " missing cmd->sg, state: %d\n", cmd->state); |
| 4725 | dump_stack(); |
| 4726 | goto out_reject; |
| 4727 | } |
| 4728 | if (se_cmd->scsi_status != 0) { |
| 4729 | ql_dbg(ql_dbg_tgt, vha, 0xe02a, |
| 4730 | "Rejecting SRR_IU_DATA_IN with non GOOD " |
| 4731 | "scsi_status\n"); |
| 4732 | goto out_reject; |
| 4733 | } |
| 4734 | cmd->bufflen = se_cmd->data_length; |
| 4735 | |
| 4736 | if (qlt_has_data(cmd)) { |
| 4737 | if (qlt_srr_adjust_data(cmd, offset, &xmit_type) != 0) |
| 4738 | goto out_reject; |
| 4739 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4740 | qlt_send_notify_ack(vha, ntfy, |
| 4741 | 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT, 0, 0); |
| 4742 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4743 | resp = 1; |
| 4744 | } else { |
| 4745 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf064, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4746 | "qla_target(%d): SRR for in data for cmd without them (tag %lld, SCSI status %d), reject", |
| 4747 | vha->vp_idx, se_cmd->tag, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4748 | cmd->se_cmd.scsi_status); |
| 4749 | goto out_reject; |
| 4750 | } |
| 4751 | break; |
| 4752 | case SRR_IU_DATA_OUT: |
| 4753 | if (!cmd->sg || !cmd->sg_cnt) { |
| 4754 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf065, |
| 4755 | "Unable to process SRR_IU_DATA_OUT due to" |
| 4756 | " missing cmd->sg\n"); |
| 4757 | dump_stack(); |
| 4758 | goto out_reject; |
| 4759 | } |
| 4760 | if (se_cmd->scsi_status != 0) { |
| 4761 | ql_dbg(ql_dbg_tgt, vha, 0xe02b, |
| 4762 | "Rejecting SRR_IU_DATA_OUT" |
| 4763 | " with non GOOD scsi_status\n"); |
| 4764 | goto out_reject; |
| 4765 | } |
| 4766 | cmd->bufflen = se_cmd->data_length; |
| 4767 | |
| 4768 | if (qlt_has_data(cmd)) { |
| 4769 | if (qlt_srr_adjust_data(cmd, offset, &xmit_type) != 0) |
| 4770 | goto out_reject; |
| 4771 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4772 | qlt_send_notify_ack(vha, ntfy, |
| 4773 | 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT, 0, 0); |
| 4774 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4775 | if (xmit_type & QLA_TGT_XMIT_DATA) { |
| 4776 | cmd->cmd_flags |= BIT_8; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4777 | qlt_rdy_to_xfer(cmd); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4778 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4779 | } else { |
| 4780 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf066, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4781 | "qla_target(%d): SRR for out data for cmd without them (tag %lld, SCSI status %d), reject", |
| 4782 | vha->vp_idx, se_cmd->tag, cmd->se_cmd.scsi_status); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4783 | goto out_reject; |
| 4784 | } |
| 4785 | break; |
| 4786 | default: |
| 4787 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf067, |
| 4788 | "qla_target(%d): Unknown srr_ui value %x", |
| 4789 | vha->vp_idx, srr_ui); |
| 4790 | goto out_reject; |
| 4791 | } |
| 4792 | |
| 4793 | /* Transmit response in case of status and data-in cases */ |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4794 | if (resp) { |
| 4795 | cmd->cmd_flags |= BIT_7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4796 | qlt_xmit_response(cmd, xmit_type, se_cmd->scsi_status); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4797 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4798 | |
| 4799 | return; |
| 4800 | |
| 4801 | out_reject: |
| 4802 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4803 | qlt_send_notify_ack(vha, ntfy, 0, 0, 0, |
| 4804 | NOTIFY_ACK_SRR_FLAGS_REJECT, |
| 4805 | NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, |
| 4806 | NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL); |
| 4807 | if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 4808 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 4809 | dump_stack(); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4810 | } else { |
| 4811 | cmd->cmd_flags |= BIT_9; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4812 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1, 0); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4813 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4814 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4815 | } |
| 4816 | |
| 4817 | static void qlt_reject_free_srr_imm(struct scsi_qla_host *vha, |
| 4818 | struct qla_tgt_srr_imm *imm, int ha_locked) |
| 4819 | { |
| 4820 | struct qla_hw_data *ha = vha->hw; |
| 4821 | unsigned long flags = 0; |
| 4822 | |
Bart Van Assche | 8d16366 | 2015-07-09 07:25:46 -0700 | [diff] [blame] | 4823 | #ifndef __CHECKER__ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4824 | if (!ha_locked) |
| 4825 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Bart Van Assche | 8d16366 | 2015-07-09 07:25:46 -0700 | [diff] [blame] | 4826 | #endif |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4827 | |
| 4828 | qlt_send_notify_ack(vha, (void *)&imm->imm_ntfy, 0, 0, 0, |
| 4829 | NOTIFY_ACK_SRR_FLAGS_REJECT, |
| 4830 | NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, |
| 4831 | NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL); |
| 4832 | |
Bart Van Assche | 8d16366 | 2015-07-09 07:25:46 -0700 | [diff] [blame] | 4833 | #ifndef __CHECKER__ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4834 | if (!ha_locked) |
| 4835 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Bart Van Assche | 8d16366 | 2015-07-09 07:25:46 -0700 | [diff] [blame] | 4836 | #endif |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4837 | |
| 4838 | kfree(imm); |
| 4839 | } |
| 4840 | |
| 4841 | static void qlt_handle_srr_work(struct work_struct *work) |
| 4842 | { |
| 4843 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, srr_work); |
| 4844 | struct scsi_qla_host *vha = tgt->vha; |
| 4845 | struct qla_tgt_srr_ctio *sctio; |
| 4846 | unsigned long flags; |
| 4847 | |
| 4848 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf029, "Entering SRR work (tgt %p)\n", |
| 4849 | tgt); |
| 4850 | |
| 4851 | restart: |
| 4852 | spin_lock_irqsave(&tgt->srr_lock, flags); |
| 4853 | list_for_each_entry(sctio, &tgt->srr_ctio_list, srr_list_entry) { |
| 4854 | struct qla_tgt_srr_imm *imm, *i, *ti; |
| 4855 | struct qla_tgt_cmd *cmd; |
| 4856 | struct se_cmd *se_cmd; |
| 4857 | |
| 4858 | imm = NULL; |
| 4859 | list_for_each_entry_safe(i, ti, &tgt->srr_imm_list, |
| 4860 | srr_list_entry) { |
| 4861 | if (i->srr_id == sctio->srr_id) { |
| 4862 | list_del(&i->srr_list_entry); |
| 4863 | if (imm) { |
| 4864 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf068, |
| 4865 | "qla_target(%d): There must be " |
| 4866 | "only one IMM SRR per CTIO SRR " |
| 4867 | "(IMM SRR %p, id %d, CTIO %p\n", |
| 4868 | vha->vp_idx, i, i->srr_id, sctio); |
| 4869 | qlt_reject_free_srr_imm(tgt->vha, i, 0); |
| 4870 | } else |
| 4871 | imm = i; |
| 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02a, |
| 4876 | "IMM SRR %p, CTIO SRR %p (id %d)\n", imm, sctio, |
| 4877 | sctio->srr_id); |
| 4878 | |
| 4879 | if (imm == NULL) { |
| 4880 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02b, |
| 4881 | "Not found matching IMM for SRR CTIO (id %d)\n", |
| 4882 | sctio->srr_id); |
| 4883 | continue; |
| 4884 | } else |
| 4885 | list_del(&sctio->srr_list_entry); |
| 4886 | |
| 4887 | spin_unlock_irqrestore(&tgt->srr_lock, flags); |
| 4888 | |
| 4889 | cmd = sctio->cmd; |
| 4890 | /* |
| 4891 | * Reset qla_tgt_cmd SRR values and SGL pointer+count to follow |
| 4892 | * tcm_qla2xxx_write_pending() and tcm_qla2xxx_queue_data_in() |
| 4893 | * logic.. |
| 4894 | */ |
| 4895 | cmd->offset = 0; |
| 4896 | if (cmd->free_sg) { |
| 4897 | kfree(cmd->sg); |
| 4898 | cmd->sg = NULL; |
| 4899 | cmd->free_sg = 0; |
| 4900 | } |
| 4901 | se_cmd = &cmd->se_cmd; |
| 4902 | |
| 4903 | cmd->sg_cnt = se_cmd->t_data_nents; |
| 4904 | cmd->sg = se_cmd->t_data_sg; |
| 4905 | |
| 4906 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4907 | "SRR cmd %p (se_cmd %p, tag %lld, op %x), sg_cnt=%d, offset=%d", |
| 4908 | cmd, &cmd->se_cmd, se_cmd->tag, se_cmd->t_task_cdb ? |
| 4909 | se_cmd->t_task_cdb[0] : 0, cmd->sg_cnt, cmd->offset); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4910 | |
| 4911 | qlt_handle_srr(vha, sctio, imm); |
| 4912 | |
| 4913 | kfree(imm); |
| 4914 | kfree(sctio); |
| 4915 | goto restart; |
| 4916 | } |
| 4917 | spin_unlock_irqrestore(&tgt->srr_lock, flags); |
| 4918 | } |
| 4919 | |
| 4920 | /* ha->hardware_lock supposed to be held on entry */ |
| 4921 | static void qlt_prepare_srr_imm(struct scsi_qla_host *vha, |
| 4922 | struct imm_ntfy_from_isp *iocb) |
| 4923 | { |
| 4924 | struct qla_tgt_srr_imm *imm; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4925 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4926 | struct qla_tgt_srr_ctio *sctio; |
| 4927 | |
| 4928 | tgt->imm_srr_id++; |
| 4929 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4930 | ql_log(ql_log_warn, vha, 0xf02d, "qla_target(%d): SRR received\n", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4931 | vha->vp_idx); |
| 4932 | |
| 4933 | imm = kzalloc(sizeof(*imm), GFP_ATOMIC); |
| 4934 | if (imm != NULL) { |
| 4935 | memcpy(&imm->imm_ntfy, iocb, sizeof(imm->imm_ntfy)); |
| 4936 | |
| 4937 | /* IRQ is already OFF */ |
| 4938 | spin_lock(&tgt->srr_lock); |
| 4939 | imm->srr_id = tgt->imm_srr_id; |
| 4940 | list_add_tail(&imm->srr_list_entry, |
| 4941 | &tgt->srr_imm_list); |
| 4942 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02e, |
| 4943 | "IMM NTFY SRR %p added (id %d, ui %x)\n", |
| 4944 | imm, imm->srr_id, iocb->u.isp24.srr_ui); |
| 4945 | if (tgt->imm_srr_id == tgt->ctio_srr_id) { |
| 4946 | int found = 0; |
| 4947 | list_for_each_entry(sctio, &tgt->srr_ctio_list, |
| 4948 | srr_list_entry) { |
| 4949 | if (sctio->srr_id == imm->srr_id) { |
| 4950 | found = 1; |
| 4951 | break; |
| 4952 | } |
| 4953 | } |
| 4954 | if (found) { |
| 4955 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02f, "%s", |
| 4956 | "Scheduling srr work\n"); |
| 4957 | schedule_work(&tgt->srr_work); |
| 4958 | } else { |
| 4959 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf030, |
| 4960 | "qla_target(%d): imm_srr_id " |
| 4961 | "== ctio_srr_id (%d), but there is no " |
| 4962 | "corresponding SRR CTIO, deleting IMM " |
| 4963 | "SRR %p\n", vha->vp_idx, tgt->ctio_srr_id, |
| 4964 | imm); |
| 4965 | list_del(&imm->srr_list_entry); |
| 4966 | |
| 4967 | kfree(imm); |
| 4968 | |
| 4969 | spin_unlock(&tgt->srr_lock); |
| 4970 | goto out_reject; |
| 4971 | } |
| 4972 | } |
| 4973 | spin_unlock(&tgt->srr_lock); |
| 4974 | } else { |
| 4975 | struct qla_tgt_srr_ctio *ts; |
| 4976 | |
| 4977 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf069, |
| 4978 | "qla_target(%d): Unable to allocate SRR IMM " |
| 4979 | "entry, SRR request will be rejected\n", vha->vp_idx); |
| 4980 | |
| 4981 | /* IRQ is already OFF */ |
| 4982 | spin_lock(&tgt->srr_lock); |
| 4983 | list_for_each_entry_safe(sctio, ts, &tgt->srr_ctio_list, |
| 4984 | srr_list_entry) { |
| 4985 | if (sctio->srr_id == tgt->imm_srr_id) { |
| 4986 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf031, |
| 4987 | "CTIO SRR %p deleted (id %d)\n", |
| 4988 | sctio, sctio->srr_id); |
| 4989 | list_del(&sctio->srr_list_entry); |
| 4990 | qlt_send_term_exchange(vha, sctio->cmd, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4991 | &sctio->cmd->atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4992 | kfree(sctio); |
| 4993 | } |
| 4994 | } |
| 4995 | spin_unlock(&tgt->srr_lock); |
| 4996 | goto out_reject; |
| 4997 | } |
| 4998 | |
| 4999 | return; |
| 5000 | |
| 5001 | out_reject: |
| 5002 | qlt_send_notify_ack(vha, iocb, 0, 0, 0, |
| 5003 | NOTIFY_ACK_SRR_FLAGS_REJECT, |
| 5004 | NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, |
| 5005 | NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL); |
| 5006 | } |
| 5007 | |
| 5008 | /* |
| 5009 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5010 | */ |
| 5011 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, |
| 5012 | struct imm_ntfy_from_isp *iocb) |
| 5013 | { |
| 5014 | struct qla_hw_data *ha = vha->hw; |
| 5015 | uint32_t add_flags = 0; |
| 5016 | int send_notify_ack = 1; |
| 5017 | uint16_t status; |
| 5018 | |
| 5019 | status = le16_to_cpu(iocb->u.isp2x.status); |
| 5020 | switch (status) { |
| 5021 | case IMM_NTFY_LIP_RESET: |
| 5022 | { |
| 5023 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, |
| 5024 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", |
| 5025 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5026 | iocb->u.isp24.status_subcode); |
| 5027 | |
| 5028 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5029 | send_notify_ack = 0; |
| 5030 | break; |
| 5031 | } |
| 5032 | |
| 5033 | case IMM_NTFY_LIP_LINK_REINIT: |
| 5034 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5035 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5036 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
| 5037 | "qla_target(%d): LINK REINIT (loop %#x, " |
| 5038 | "subcode %x)\n", vha->vp_idx, |
| 5039 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5040 | iocb->u.isp24.status_subcode); |
| 5041 | if (tgt->link_reinit_iocb_pending) { |
| 5042 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, |
| 5043 | 0, 0, 0, 0, 0, 0); |
| 5044 | } |
| 5045 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); |
| 5046 | tgt->link_reinit_iocb_pending = 1; |
| 5047 | /* |
| 5048 | * QLogic requires to wait after LINK REINIT for possible |
| 5049 | * PDISC or ADISC ELS commands |
| 5050 | */ |
| 5051 | send_notify_ack = 0; |
| 5052 | break; |
| 5053 | } |
| 5054 | |
| 5055 | case IMM_NTFY_PORT_LOGOUT: |
| 5056 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, |
| 5057 | "qla_target(%d): Port logout (loop " |
| 5058 | "%#x, subcode %x)\n", vha->vp_idx, |
| 5059 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5060 | iocb->u.isp24.status_subcode); |
| 5061 | |
| 5062 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) |
| 5063 | send_notify_ack = 0; |
| 5064 | /* The sessions will be cleared in the callback, if needed */ |
| 5065 | break; |
| 5066 | |
| 5067 | case IMM_NTFY_GLBL_TPRLO: |
| 5068 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, |
| 5069 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); |
| 5070 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5071 | send_notify_ack = 0; |
| 5072 | /* The sessions will be cleared in the callback, if needed */ |
| 5073 | break; |
| 5074 | |
| 5075 | case IMM_NTFY_PORT_CONFIG: |
| 5076 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, |
| 5077 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, |
| 5078 | status); |
| 5079 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5080 | send_notify_ack = 0; |
| 5081 | /* The sessions will be cleared in the callback, if needed */ |
| 5082 | break; |
| 5083 | |
| 5084 | case IMM_NTFY_GLBL_LOGO: |
| 5085 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, |
| 5086 | "qla_target(%d): Link failure detected\n", |
| 5087 | vha->vp_idx); |
| 5088 | /* I_T nexus loss */ |
| 5089 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5090 | send_notify_ack = 0; |
| 5091 | break; |
| 5092 | |
| 5093 | case IMM_NTFY_IOCB_OVERFLOW: |
| 5094 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, |
| 5095 | "qla_target(%d): Cannot provide requested " |
| 5096 | "capability (IOCB overflowed the immediate notify " |
| 5097 | "resource count)\n", vha->vp_idx); |
| 5098 | break; |
| 5099 | |
| 5100 | case IMM_NTFY_ABORT_TASK: |
| 5101 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, |
| 5102 | "qla_target(%d): Abort Task (S %08x I %#x -> " |
| 5103 | "L %#x)\n", vha->vp_idx, |
| 5104 | le16_to_cpu(iocb->u.isp2x.seq_id), |
| 5105 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), |
| 5106 | le16_to_cpu(iocb->u.isp2x.lun)); |
| 5107 | if (qlt_abort_task(vha, iocb) == 0) |
| 5108 | send_notify_ack = 0; |
| 5109 | break; |
| 5110 | |
| 5111 | case IMM_NTFY_RESOURCE: |
| 5112 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, |
| 5113 | "qla_target(%d): Out of resources, host %ld\n", |
| 5114 | vha->vp_idx, vha->host_no); |
| 5115 | break; |
| 5116 | |
| 5117 | case IMM_NTFY_MSG_RX: |
| 5118 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, |
| 5119 | "qla_target(%d): Immediate notify task %x\n", |
| 5120 | vha->vp_idx, iocb->u.isp2x.task_flags); |
| 5121 | if (qlt_handle_task_mgmt(vha, iocb) == 0) |
| 5122 | send_notify_ack = 0; |
| 5123 | break; |
| 5124 | |
| 5125 | case IMM_NTFY_ELS: |
| 5126 | if (qlt_24xx_handle_els(vha, iocb) == 0) |
| 5127 | send_notify_ack = 0; |
| 5128 | break; |
| 5129 | |
| 5130 | case IMM_NTFY_SRR: |
| 5131 | qlt_prepare_srr_imm(vha, iocb); |
| 5132 | send_notify_ack = 0; |
| 5133 | break; |
| 5134 | |
| 5135 | default: |
| 5136 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, |
| 5137 | "qla_target(%d): Received unknown immediate " |
| 5138 | "notify status %x\n", vha->vp_idx, status); |
| 5139 | break; |
| 5140 | } |
| 5141 | |
| 5142 | if (send_notify_ack) |
| 5143 | qlt_send_notify_ack(vha, iocb, add_flags, 0, 0, 0, 0, 0); |
| 5144 | } |
| 5145 | |
| 5146 | /* |
| 5147 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5148 | * This function sends busy to ISP 2xxx or 24xx. |
| 5149 | */ |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5150 | static int __qlt_send_busy(struct scsi_qla_host *vha, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5151 | struct atio_from_isp *atio, uint16_t status) |
| 5152 | { |
| 5153 | struct ctio7_to_24xx *ctio24; |
| 5154 | struct qla_hw_data *ha = vha->hw; |
| 5155 | request_t *pkt; |
| 5156 | struct qla_tgt_sess *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5157 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5158 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5159 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5160 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 5161 | atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5162 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5163 | if (!sess) { |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5164 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5165 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5166 | } |
| 5167 | /* Sending marker isn't necessary, since we called from ISR */ |
| 5168 | |
| 5169 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
| 5170 | if (!pkt) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5171 | ql_dbg(ql_dbg_io, vha, 0x3063, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5172 | "qla_target(%d): %s failed: unable to allocate " |
| 5173 | "request packet", vha->vp_idx, __func__); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5174 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5175 | } |
| 5176 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 5177 | vha->tgt_counters.num_q_full_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5178 | pkt->entry_count = 1; |
| 5179 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 5180 | |
| 5181 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 5182 | ctio24->entry_type = CTIO_TYPE7; |
| 5183 | ctio24->nport_handle = sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5184 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5185 | ctio24->vp_index = vha->vp_idx; |
| 5186 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 5187 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 5188 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 5189 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
| 5190 | ctio24->u.status1.flags = (atio->u.isp24.attr << 9) | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5191 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5192 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | |
| 5193 | CTIO7_FLAGS_DONT_RET_CTIO); |
| 5194 | /* |
| 5195 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, |
| 5196 | * if the explicit conformation is used. |
| 5197 | */ |
| 5198 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); |
| 5199 | ctio24->u.status1.scsi_status = cpu_to_le16(status); |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 5200 | /* Memory Barrier */ |
| 5201 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5202 | qla2x00_start_iocbs(vha, vha->req); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5203 | return 0; |
| 5204 | } |
| 5205 | |
| 5206 | /* |
| 5207 | * This routine is used to allocate a command for either a QFull condition |
| 5208 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go |
| 5209 | * out previously. |
| 5210 | */ |
| 5211 | static void |
| 5212 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 5213 | struct atio_from_isp *atio, uint16_t status, int qfull) |
| 5214 | { |
| 5215 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 5216 | struct qla_hw_data *ha = vha->hw; |
| 5217 | struct qla_tgt_sess *sess; |
| 5218 | struct se_session *se_sess; |
| 5219 | struct qla_tgt_cmd *cmd; |
| 5220 | int tag; |
| 5221 | |
| 5222 | if (unlikely(tgt->tgt_stop)) { |
| 5223 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 5224 | "New command while device %p is shutting down\n", tgt); |
| 5225 | return; |
| 5226 | } |
| 5227 | |
| 5228 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { |
| 5229 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5230 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5231 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5232 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5233 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5234 | |
| 5235 | ql_dbg(ql_dbg_io, vha, 0x3068, |
| 5236 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", |
| 5237 | vha->vp_idx, __func__, |
| 5238 | vha->hw->tgt.num_qfull_cmds_dropped); |
| 5239 | |
| 5240 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5241 | return; |
| 5242 | } |
| 5243 | |
| 5244 | sess = ha->tgt.tgt_ops->find_sess_by_s_id |
| 5245 | (vha, atio->u.isp24.fcp_hdr.s_id); |
| 5246 | if (!sess) |
| 5247 | return; |
| 5248 | |
| 5249 | se_sess = sess->se_sess; |
| 5250 | |
| 5251 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 5252 | if (tag < 0) |
| 5253 | return; |
| 5254 | |
| 5255 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 5256 | if (!cmd) { |
| 5257 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 5258 | "qla_target(%d): %s: Allocation of cmd failed\n", |
| 5259 | vha->vp_idx, __func__); |
| 5260 | |
| 5261 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5262 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5263 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5264 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5265 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5266 | |
| 5267 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5268 | return; |
| 5269 | } |
| 5270 | |
| 5271 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 5272 | |
| 5273 | qlt_incr_num_pend_cmds(vha); |
| 5274 | INIT_LIST_HEAD(&cmd->cmd_list); |
| 5275 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 5276 | |
| 5277 | cmd->tgt = vha->vha_tgt.qla_tgt; |
| 5278 | cmd->vha = vha; |
| 5279 | cmd->reset_count = vha->hw->chip_reset; |
| 5280 | cmd->q_full = 1; |
| 5281 | |
| 5282 | if (qfull) { |
| 5283 | cmd->q_full = 1; |
| 5284 | /* NOTE: borrowing the state field to carry the status */ |
| 5285 | cmd->state = status; |
| 5286 | } else |
| 5287 | cmd->term_exchg = 1; |
| 5288 | |
| 5289 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); |
| 5290 | |
| 5291 | vha->hw->tgt.num_qfull_cmds_alloc++; |
| 5292 | if (vha->hw->tgt.num_qfull_cmds_alloc > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5293 | vha->qla_stats.stat_max_qfull_cmds_alloc) |
| 5294 | vha->qla_stats.stat_max_qfull_cmds_alloc = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5295 | vha->hw->tgt.num_qfull_cmds_alloc; |
| 5296 | } |
| 5297 | |
| 5298 | int |
| 5299 | qlt_free_qfull_cmds(struct scsi_qla_host *vha) |
| 5300 | { |
| 5301 | struct qla_hw_data *ha = vha->hw; |
| 5302 | unsigned long flags; |
| 5303 | struct qla_tgt_cmd *cmd, *tcmd; |
| 5304 | struct list_head free_list; |
| 5305 | int rc = 0; |
| 5306 | |
| 5307 | if (list_empty(&ha->tgt.q_full_list)) |
| 5308 | return 0; |
| 5309 | |
| 5310 | INIT_LIST_HEAD(&free_list); |
| 5311 | |
| 5312 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 5313 | |
| 5314 | if (list_empty(&ha->tgt.q_full_list)) { |
| 5315 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 5316 | return 0; |
| 5317 | } |
| 5318 | |
| 5319 | list_for_each_entry_safe(cmd, tcmd, &ha->tgt.q_full_list, cmd_list) { |
| 5320 | if (cmd->q_full) |
| 5321 | /* cmd->state is a borrowed field to hold status */ |
| 5322 | rc = __qlt_send_busy(vha, &cmd->atio, cmd->state); |
| 5323 | else if (cmd->term_exchg) |
| 5324 | rc = __qlt_send_term_exchange(vha, NULL, &cmd->atio); |
| 5325 | |
| 5326 | if (rc == -ENOMEM) |
| 5327 | break; |
| 5328 | |
| 5329 | if (cmd->q_full) |
| 5330 | ql_dbg(ql_dbg_io, vha, 0x3006, |
| 5331 | "%s: busy sent for ox_id[%04x]\n", __func__, |
| 5332 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5333 | else if (cmd->term_exchg) |
| 5334 | ql_dbg(ql_dbg_io, vha, 0x3007, |
| 5335 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, |
| 5336 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5337 | else |
| 5338 | ql_dbg(ql_dbg_io, vha, 0x3008, |
| 5339 | "%s: Unexpected cmd in QFull list %p\n", __func__, |
| 5340 | cmd); |
| 5341 | |
| 5342 | list_del(&cmd->cmd_list); |
| 5343 | list_add_tail(&cmd->cmd_list, &free_list); |
| 5344 | |
| 5345 | /* piggy back on hardware_lock for protection */ |
| 5346 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 5347 | } |
| 5348 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 5349 | |
| 5350 | cmd = NULL; |
| 5351 | |
| 5352 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 5353 | list_del(&cmd->cmd_list); |
| 5354 | /* This cmd was never sent to TCM. There is no need |
| 5355 | * to schedule free or call free_cmd |
| 5356 | */ |
| 5357 | qlt_free_cmd(cmd); |
| 5358 | } |
| 5359 | return rc; |
| 5360 | } |
| 5361 | |
| 5362 | static void |
| 5363 | qlt_send_busy(struct scsi_qla_host *vha, |
| 5364 | struct atio_from_isp *atio, uint16_t status) |
| 5365 | { |
| 5366 | int rc = 0; |
| 5367 | |
| 5368 | rc = __qlt_send_busy(vha, atio, status); |
| 5369 | if (rc == -ENOMEM) |
| 5370 | qlt_alloc_qfull_cmd(vha, atio, status, 1); |
| 5371 | } |
| 5372 | |
| 5373 | static int |
| 5374 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, |
| 5375 | struct atio_from_isp *atio) |
| 5376 | { |
| 5377 | struct qla_hw_data *ha = vha->hw; |
| 5378 | uint16_t status; |
| 5379 | |
| 5380 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) |
| 5381 | return 0; |
| 5382 | |
| 5383 | status = temp_sam_status; |
| 5384 | qlt_send_busy(vha, atio, status); |
| 5385 | return 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | /* ha->hardware_lock supposed to be held on entry */ |
| 5389 | /* called via callback from qla2xxx */ |
| 5390 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5391 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5392 | { |
| 5393 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5394 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5395 | int rc; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5396 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5397 | |
| 5398 | if (unlikely(tgt == NULL)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5399 | ql_dbg(ql_dbg_io, vha, 0x3064, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5400 | "ATIO pkt, but no tgt (ha %p)", ha); |
| 5401 | return; |
| 5402 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5403 | /* |
| 5404 | * In tgt_stop mode we also should allow all requests to pass. |
| 5405 | * Otherwise, some commands can stuck. |
| 5406 | */ |
| 5407 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5408 | tgt->atio_irq_cmd_count++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5409 | |
| 5410 | switch (atio->u.raw.entry_type) { |
| 5411 | case ATIO_TYPE7: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5412 | if (unlikely(atio->u.isp24.exchange_addr == |
| 5413 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5414 | ql_dbg(ql_dbg_io, vha, 0x3065, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5415 | "qla_target(%d): ATIO_TYPE7 " |
| 5416 | "received with UNKNOWN exchange address, " |
| 5417 | "sending QUEUE_FULL\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5418 | if (!ha_locked) |
| 5419 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5420 | qlt_send_busy(vha, atio, SAM_STAT_TASK_SET_FULL); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5421 | if (!ha_locked) |
| 5422 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5423 | break; |
| 5424 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5425 | |
| 5426 | |
| 5427 | |
| 5428 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { |
| 5429 | rc = qlt_chk_qfull_thresh_hold(vha, atio); |
| 5430 | if (rc != 0) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5431 | tgt->atio_irq_cmd_count--; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5432 | return; |
| 5433 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5434 | rc = qlt_handle_cmd_for_atio(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5435 | } else { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5436 | rc = qlt_handle_task_mgmt(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5437 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5438 | if (unlikely(rc != 0)) { |
| 5439 | if (rc == -ESRCH) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5440 | if (!ha_locked) |
| 5441 | spin_lock_irqsave |
| 5442 | (&ha->hardware_lock, flags); |
| 5443 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5444 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
| 5445 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); |
| 5446 | #else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5447 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5448 | #endif |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5449 | |
| 5450 | if (!ha_locked) |
| 5451 | spin_unlock_irqrestore |
| 5452 | (&ha->hardware_lock, flags); |
| 5453 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5454 | } else { |
| 5455 | if (tgt->tgt_stop) { |
| 5456 | ql_dbg(ql_dbg_tgt, vha, 0xe059, |
| 5457 | "qla_target: Unable to send " |
| 5458 | "command to target for req, " |
| 5459 | "ignoring.\n"); |
| 5460 | } else { |
| 5461 | ql_dbg(ql_dbg_tgt, vha, 0xe05a, |
| 5462 | "qla_target(%d): Unable to send " |
| 5463 | "command to target, sending BUSY " |
| 5464 | "status.\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5465 | if (!ha_locked) |
| 5466 | spin_lock_irqsave( |
| 5467 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5468 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5469 | if (!ha_locked) |
| 5470 | spin_unlock_irqrestore( |
| 5471 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5472 | } |
| 5473 | } |
| 5474 | } |
| 5475 | break; |
| 5476 | |
| 5477 | case IMMED_NOTIFY_TYPE: |
| 5478 | { |
| 5479 | if (unlikely(atio->u.isp2x.entry_status != 0)) { |
| 5480 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, |
| 5481 | "qla_target(%d): Received ATIO packet %x " |
| 5482 | "with error status %x\n", vha->vp_idx, |
| 5483 | atio->u.raw.entry_type, |
| 5484 | atio->u.isp2x.entry_status); |
| 5485 | break; |
| 5486 | } |
| 5487 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5488 | |
| 5489 | if (!ha_locked) |
| 5490 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5491 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5492 | if (!ha_locked) |
| 5493 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5494 | break; |
| 5495 | } |
| 5496 | |
| 5497 | default: |
| 5498 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, |
| 5499 | "qla_target(%d): Received unknown ATIO atio " |
| 5500 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 5501 | break; |
| 5502 | } |
| 5503 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5504 | tgt->atio_irq_cmd_count--; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5505 | } |
| 5506 | |
| 5507 | /* ha->hardware_lock supposed to be held on entry */ |
| 5508 | /* called via callback from qla2xxx */ |
| 5509 | static void qlt_response_pkt(struct scsi_qla_host *vha, response_t *pkt) |
| 5510 | { |
| 5511 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5512 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5513 | |
| 5514 | if (unlikely(tgt == NULL)) { |
| 5515 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, |
| 5516 | "qla_target(%d): Response pkt %x received, but no " |
| 5517 | "tgt (ha %p)\n", vha->vp_idx, pkt->entry_type, ha); |
| 5518 | return; |
| 5519 | } |
| 5520 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5521 | /* |
| 5522 | * In tgt_stop mode we also should allow all requests to pass. |
| 5523 | * Otherwise, some commands can stuck. |
| 5524 | */ |
| 5525 | |
| 5526 | tgt->irq_cmd_count++; |
| 5527 | |
| 5528 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 5529 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5530 | case CTIO_TYPE7: |
| 5531 | { |
| 5532 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5533 | qlt_do_ctio_completion(vha, entry->handle, |
| 5534 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5535 | entry); |
| 5536 | break; |
| 5537 | } |
| 5538 | |
| 5539 | case ACCEPT_TGT_IO_TYPE: |
| 5540 | { |
| 5541 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; |
| 5542 | int rc; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5543 | if (atio->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5544 | cpu_to_le16(ATIO_CDB_VALID)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5545 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, |
| 5546 | "qla_target(%d): ATIO with error " |
| 5547 | "status %x received\n", vha->vp_idx, |
| 5548 | le16_to_cpu(atio->u.isp2x.status)); |
| 5549 | break; |
| 5550 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5551 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5552 | rc = qlt_chk_qfull_thresh_hold(vha, atio); |
| 5553 | if (rc != 0) { |
| 5554 | tgt->irq_cmd_count--; |
| 5555 | return; |
| 5556 | } |
| 5557 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5558 | rc = qlt_handle_cmd_for_atio(vha, atio); |
| 5559 | if (unlikely(rc != 0)) { |
| 5560 | if (rc == -ESRCH) { |
| 5561 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
| 5562 | qlt_send_busy(vha, atio, 0); |
| 5563 | #else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5564 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5565 | #endif |
| 5566 | } else { |
| 5567 | if (tgt->tgt_stop) { |
| 5568 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5569 | "qla_target: Unable to send " |
| 5570 | "command to target, sending TERM " |
| 5571 | "EXCHANGE for rsp\n"); |
| 5572 | qlt_send_term_exchange(vha, NULL, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5573 | atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5574 | } else { |
| 5575 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5576 | "qla_target(%d): Unable to send " |
| 5577 | "command to target, sending BUSY " |
| 5578 | "status\n", vha->vp_idx); |
| 5579 | qlt_send_busy(vha, atio, 0); |
| 5580 | } |
| 5581 | } |
| 5582 | } |
| 5583 | } |
| 5584 | break; |
| 5585 | |
| 5586 | case CONTINUE_TGT_IO_TYPE: |
| 5587 | { |
| 5588 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5589 | qlt_do_ctio_completion(vha, entry->handle, |
| 5590 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5591 | entry); |
| 5592 | break; |
| 5593 | } |
| 5594 | |
| 5595 | case CTIO_A64_TYPE: |
| 5596 | { |
| 5597 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5598 | qlt_do_ctio_completion(vha, entry->handle, |
| 5599 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5600 | entry); |
| 5601 | break; |
| 5602 | } |
| 5603 | |
| 5604 | case IMMED_NOTIFY_TYPE: |
| 5605 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); |
| 5606 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); |
| 5607 | break; |
| 5608 | |
| 5609 | case NOTIFY_ACK_TYPE: |
| 5610 | if (tgt->notify_ack_expected > 0) { |
| 5611 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 5612 | ql_dbg(ql_dbg_tgt, vha, 0xe036, |
| 5613 | "NOTIFY_ACK seq %08x status %x\n", |
| 5614 | le16_to_cpu(entry->u.isp2x.seq_id), |
| 5615 | le16_to_cpu(entry->u.isp2x.status)); |
| 5616 | tgt->notify_ack_expected--; |
| 5617 | if (entry->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5618 | cpu_to_le16(NOTIFY_ACK_SUCCESS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5619 | ql_dbg(ql_dbg_tgt, vha, 0xe061, |
| 5620 | "qla_target(%d): NOTIFY_ACK " |
| 5621 | "failed %x\n", vha->vp_idx, |
| 5622 | le16_to_cpu(entry->u.isp2x.status)); |
| 5623 | } |
| 5624 | } else { |
| 5625 | ql_dbg(ql_dbg_tgt, vha, 0xe062, |
| 5626 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", |
| 5627 | vha->vp_idx); |
| 5628 | } |
| 5629 | break; |
| 5630 | |
| 5631 | case ABTS_RECV_24XX: |
| 5632 | ql_dbg(ql_dbg_tgt, vha, 0xe037, |
| 5633 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); |
| 5634 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); |
| 5635 | break; |
| 5636 | |
| 5637 | case ABTS_RESP_24XX: |
| 5638 | if (tgt->abts_resp_expected > 0) { |
| 5639 | struct abts_resp_from_24xx_fw *entry = |
| 5640 | (struct abts_resp_from_24xx_fw *)pkt; |
| 5641 | ql_dbg(ql_dbg_tgt, vha, 0xe038, |
| 5642 | "ABTS_RESP_24XX: compl_status %x\n", |
| 5643 | entry->compl_status); |
| 5644 | tgt->abts_resp_expected--; |
| 5645 | if (le16_to_cpu(entry->compl_status) != |
| 5646 | ABTS_RESP_COMPL_SUCCESS) { |
| 5647 | if ((entry->error_subcode1 == 0x1E) && |
| 5648 | (entry->error_subcode2 == 0)) { |
| 5649 | /* |
| 5650 | * We've got a race here: aborted |
| 5651 | * exchange not terminated, i.e. |
| 5652 | * response for the aborted command was |
| 5653 | * sent between the abort request was |
| 5654 | * received and processed. |
| 5655 | * Unfortunately, the firmware has a |
| 5656 | * silly requirement that all aborted |
| 5657 | * exchanges must be explicitely |
| 5658 | * terminated, otherwise it refuses to |
| 5659 | * send responses for the abort |
| 5660 | * requests. So, we have to |
| 5661 | * (re)terminate the exchange and retry |
| 5662 | * the abort response. |
| 5663 | */ |
| 5664 | qlt_24xx_retry_term_exchange(vha, |
| 5665 | entry); |
| 5666 | } else |
| 5667 | ql_dbg(ql_dbg_tgt, vha, 0xe063, |
| 5668 | "qla_target(%d): ABTS_RESP_24XX " |
| 5669 | "failed %x (subcode %x:%x)", |
| 5670 | vha->vp_idx, entry->compl_status, |
| 5671 | entry->error_subcode1, |
| 5672 | entry->error_subcode2); |
| 5673 | } |
| 5674 | } else { |
| 5675 | ql_dbg(ql_dbg_tgt, vha, 0xe064, |
| 5676 | "qla_target(%d): Unexpected ABTS_RESP_24XX " |
| 5677 | "received\n", vha->vp_idx); |
| 5678 | } |
| 5679 | break; |
| 5680 | |
| 5681 | default: |
| 5682 | ql_dbg(ql_dbg_tgt, vha, 0xe065, |
| 5683 | "qla_target(%d): Received unknown response pkt " |
| 5684 | "type %x\n", vha->vp_idx, pkt->entry_type); |
| 5685 | break; |
| 5686 | } |
| 5687 | |
| 5688 | tgt->irq_cmd_count--; |
| 5689 | } |
| 5690 | |
| 5691 | /* |
| 5692 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5693 | */ |
| 5694 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, |
| 5695 | uint16_t *mailbox) |
| 5696 | { |
| 5697 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5698 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5699 | int login_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5700 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5701 | if (!ha->tgt.tgt_ops) |
| 5702 | return; |
| 5703 | |
| 5704 | if (unlikely(tgt == NULL)) { |
| 5705 | ql_dbg(ql_dbg_tgt, vha, 0xe03a, |
| 5706 | "ASYNC EVENT %#x, but no tgt (ha %p)\n", code, ha); |
| 5707 | return; |
| 5708 | } |
| 5709 | |
| 5710 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && |
| 5711 | IS_QLA2100(ha)) |
| 5712 | return; |
| 5713 | /* |
| 5714 | * In tgt_stop mode we also should allow all requests to pass. |
| 5715 | * Otherwise, some commands can stuck. |
| 5716 | */ |
| 5717 | |
| 5718 | tgt->irq_cmd_count++; |
| 5719 | |
| 5720 | switch (code) { |
| 5721 | case MBA_RESET: /* Reset */ |
| 5722 | case MBA_SYSTEM_ERR: /* System Error */ |
| 5723 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 5724 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 5725 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, |
| 5726 | "qla_target(%d): System error async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5727 | "occurred", vha->vp_idx, code); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5728 | break; |
| 5729 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ |
| 5730 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5731 | break; |
| 5732 | |
| 5733 | case MBA_LOOP_UP: |
| 5734 | { |
| 5735 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5736 | "qla_target(%d): Async LOOP_UP occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5737 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 5738 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5739 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5740 | if (tgt->link_reinit_iocb_pending) { |
| 5741 | qlt_send_notify_ack(vha, (void *)&tgt->link_reinit_iocb, |
| 5742 | 0, 0, 0, 0, 0, 0); |
| 5743 | tgt->link_reinit_iocb_pending = 0; |
| 5744 | } |
| 5745 | break; |
| 5746 | } |
| 5747 | |
| 5748 | case MBA_LIP_OCCURRED: |
| 5749 | case MBA_LOOP_DOWN: |
| 5750 | case MBA_LIP_RESET: |
| 5751 | case MBA_RSCN_UPDATE: |
| 5752 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5753 | "qla_target(%d): Async event %#x occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5754 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5755 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5756 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5757 | break; |
| 5758 | |
| 5759 | case MBA_PORT_UPDATE: |
| 5760 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, |
| 5761 | "qla_target(%d): Port update async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5762 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5763 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5764 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5765 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 5766 | |
| 5767 | login_code = le16_to_cpu(mailbox[2]); |
| 5768 | if (login_code == 0x4) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5769 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
| 5770 | "Async MB 2: Got PLOGI Complete\n"); |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5771 | else if (login_code == 0x7) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5772 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
| 5773 | "Async MB 2: Port Logged Out\n"); |
| 5774 | break; |
| 5775 | |
| 5776 | default: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5777 | break; |
| 5778 | } |
| 5779 | |
| 5780 | tgt->irq_cmd_count--; |
| 5781 | } |
| 5782 | |
| 5783 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, |
| 5784 | uint16_t loop_id) |
| 5785 | { |
| 5786 | fc_port_t *fcport; |
| 5787 | int rc; |
| 5788 | |
| 5789 | fcport = kzalloc(sizeof(*fcport), GFP_KERNEL); |
| 5790 | if (!fcport) { |
| 5791 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, |
| 5792 | "qla_target(%d): Allocation of tmp FC port failed", |
| 5793 | vha->vp_idx); |
| 5794 | return NULL; |
| 5795 | } |
| 5796 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5797 | fcport->loop_id = loop_id; |
| 5798 | |
| 5799 | rc = qla2x00_get_port_database(vha, fcport, 0); |
| 5800 | if (rc != QLA_SUCCESS) { |
| 5801 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, |
| 5802 | "qla_target(%d): Failed to retrieve fcport " |
| 5803 | "information -- get_port_database() returned %x " |
| 5804 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); |
| 5805 | kfree(fcport); |
| 5806 | return NULL; |
| 5807 | } |
| 5808 | |
| 5809 | return fcport; |
| 5810 | } |
| 5811 | |
| 5812 | /* Must be called under tgt_mutex */ |
| 5813 | static struct qla_tgt_sess *qlt_make_local_sess(struct scsi_qla_host *vha, |
| 5814 | uint8_t *s_id) |
| 5815 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5816 | struct qla_tgt_sess *sess = NULL; |
| 5817 | fc_port_t *fcport = NULL; |
| 5818 | int rc, global_resets; |
| 5819 | uint16_t loop_id = 0; |
| 5820 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5821 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 5822 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5823 | retry: |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5824 | global_resets = |
| 5825 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5826 | |
| 5827 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); |
| 5828 | if (rc != 0) { |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5829 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5830 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5831 | if ((s_id[0] == 0xFF) && |
| 5832 | (s_id[1] == 0xFC)) { |
| 5833 | /* |
| 5834 | * This is Domain Controller, so it should be |
| 5835 | * OK to drop SCSI commands from it. |
| 5836 | */ |
| 5837 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, |
| 5838 | "Unable to find initiator with S_ID %x:%x:%x", |
| 5839 | s_id[0], s_id[1], s_id[2]); |
| 5840 | } else |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5841 | ql_log(ql_log_info, vha, 0xf071, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5842 | "qla_target(%d): Unable to find " |
| 5843 | "initiator with S_ID %x:%x:%x", |
| 5844 | vha->vp_idx, s_id[0], s_id[1], |
| 5845 | s_id[2]); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5846 | |
| 5847 | if (rc == -ENOENT) { |
| 5848 | qlt_port_logo_t logo; |
| 5849 | sid_to_portid(s_id, &logo.id); |
| 5850 | logo.cmd_count = 1; |
| 5851 | qlt_send_first_logo(vha, &logo); |
| 5852 | } |
| 5853 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5854 | return NULL; |
| 5855 | } |
| 5856 | |
| 5857 | fcport = qlt_get_port_database(vha, loop_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5858 | if (!fcport) { |
| 5859 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5860 | return NULL; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5861 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5862 | |
| 5863 | if (global_resets != |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5864 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5865 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
| 5866 | "qla_target(%d): global reset during session discovery " |
| 5867 | "(counter was %d, new %d), retrying", vha->vp_idx, |
| 5868 | global_resets, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5869 | atomic_read(&vha->vha_tgt. |
| 5870 | qla_tgt->tgt_global_resets_count)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5871 | goto retry; |
| 5872 | } |
| 5873 | |
| 5874 | sess = qlt_create_sess(vha, fcport, true); |
| 5875 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5876 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5877 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5878 | kfree(fcport); |
| 5879 | return sess; |
| 5880 | } |
| 5881 | |
| 5882 | static void qlt_abort_work(struct qla_tgt *tgt, |
| 5883 | struct qla_tgt_sess_work_param *prm) |
| 5884 | { |
| 5885 | struct scsi_qla_host *vha = tgt->vha; |
| 5886 | struct qla_hw_data *ha = vha->hw; |
| 5887 | struct qla_tgt_sess *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5888 | unsigned long flags = 0, flags2 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5889 | uint32_t be_s_id; |
| 5890 | uint8_t s_id[3]; |
| 5891 | int rc; |
| 5892 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5893 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5894 | |
| 5895 | if (tgt->tgt_stop) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5896 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5897 | |
| 5898 | s_id[0] = prm->abts.fcp_hdr_le.s_id[2]; |
| 5899 | s_id[1] = prm->abts.fcp_hdr_le.s_id[1]; |
| 5900 | s_id[2] = prm->abts.fcp_hdr_le.s_id[0]; |
| 5901 | |
| 5902 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 5903 | (unsigned char *)&be_s_id); |
| 5904 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5905 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5906 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5907 | sess = qlt_make_local_sess(vha, s_id); |
| 5908 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5909 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5910 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5911 | if (!sess) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5912 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5913 | } else { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5914 | if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
| 5915 | sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5916 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5917 | } |
| 5918 | |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 5919 | kref_get(&sess->sess_kref); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5920 | } |
| 5921 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5922 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5923 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5924 | if (tgt->tgt_stop) |
| 5925 | goto out_term; |
| 5926 | |
| 5927 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); |
| 5928 | if (rc != 0) |
| 5929 | goto out_term; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5930 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5931 | |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 5932 | qlt_put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5933 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5934 | return; |
| 5935 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5936 | out_term2: |
| 5937 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5938 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5939 | out_term: |
| 5940 | qlt_24xx_send_abts_resp(vha, &prm->abts, FCP_TMF_REJECTED, false); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5941 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5942 | |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 5943 | qlt_put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5944 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | static void qlt_tmr_work(struct qla_tgt *tgt, |
| 5948 | struct qla_tgt_sess_work_param *prm) |
| 5949 | { |
| 5950 | struct atio_from_isp *a = &prm->tm_iocb2; |
| 5951 | struct scsi_qla_host *vha = tgt->vha; |
| 5952 | struct qla_hw_data *ha = vha->hw; |
| 5953 | struct qla_tgt_sess *sess = NULL; |
| 5954 | unsigned long flags; |
| 5955 | uint8_t *s_id = NULL; /* to hide compiler warnings */ |
| 5956 | int rc; |
| 5957 | uint32_t lun, unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 5958 | int fn; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5959 | void *iocb; |
| 5960 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5961 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5962 | |
| 5963 | if (tgt->tgt_stop) |
| 5964 | goto out_term; |
| 5965 | |
| 5966 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; |
| 5967 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 5968 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5969 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5970 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5971 | sess = qlt_make_local_sess(vha, s_id); |
| 5972 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5973 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5974 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5975 | if (!sess) |
| 5976 | goto out_term; |
| 5977 | } else { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5978 | if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
| 5979 | sess = NULL; |
| 5980 | goto out_term; |
| 5981 | } |
| 5982 | |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 5983 | kref_get(&sess->sess_kref); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5984 | } |
| 5985 | |
| 5986 | iocb = a; |
| 5987 | lun = a->u.isp24.fcp_cmnd.lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5988 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
| 5989 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); |
| 5990 | |
| 5991 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 5992 | if (rc != 0) |
| 5993 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5994 | |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 5995 | qlt_put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5996 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5997 | return; |
| 5998 | |
| 5999 | out_term: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 6000 | qlt_send_term_exchange(vha, NULL, &prm->tm_iocb2, 1, 0); |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 6001 | qlt_put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6002 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | static void qlt_sess_work_fn(struct work_struct *work) |
| 6006 | { |
| 6007 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); |
| 6008 | struct scsi_qla_host *vha = tgt->vha; |
| 6009 | unsigned long flags; |
| 6010 | |
| 6011 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); |
| 6012 | |
| 6013 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6014 | while (!list_empty(&tgt->sess_works_list)) { |
| 6015 | struct qla_tgt_sess_work_param *prm = list_entry( |
| 6016 | tgt->sess_works_list.next, typeof(*prm), |
| 6017 | sess_works_list_entry); |
| 6018 | |
| 6019 | /* |
| 6020 | * This work can be scheduled on several CPUs at time, so we |
| 6021 | * must delete the entry to eliminate double processing |
| 6022 | */ |
| 6023 | list_del(&prm->sess_works_list_entry); |
| 6024 | |
| 6025 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6026 | |
| 6027 | switch (prm->type) { |
| 6028 | case QLA_TGT_SESS_WORK_ABORT: |
| 6029 | qlt_abort_work(tgt, prm); |
| 6030 | break; |
| 6031 | case QLA_TGT_SESS_WORK_TM: |
| 6032 | qlt_tmr_work(tgt, prm); |
| 6033 | break; |
| 6034 | default: |
| 6035 | BUG_ON(1); |
| 6036 | break; |
| 6037 | } |
| 6038 | |
| 6039 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6040 | |
| 6041 | kfree(prm); |
| 6042 | } |
| 6043 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6044 | } |
| 6045 | |
| 6046 | /* Must be called under tgt_host_action_mutex */ |
| 6047 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) |
| 6048 | { |
| 6049 | struct qla_tgt *tgt; |
| 6050 | |
| 6051 | if (!QLA_TGT_MODE_ENABLED()) |
| 6052 | return 0; |
| 6053 | |
Arun Easi | 33c36c0 | 2013-01-30 03:34:41 -0500 | [diff] [blame] | 6054 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
| 6055 | ql_log(ql_log_warn, base_vha, 0xe070, |
| 6056 | "This adapter does not support target mode.\n"); |
| 6057 | return 0; |
| 6058 | } |
| 6059 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6060 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6061 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6062 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6063 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6064 | |
| 6065 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); |
| 6066 | if (!tgt) { |
| 6067 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, |
| 6068 | "Unable to allocate struct qla_tgt\n"); |
| 6069 | return -ENOMEM; |
| 6070 | } |
| 6071 | |
| 6072 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) |
| 6073 | base_vha->host->hostt->supported_mode |= MODE_TARGET; |
| 6074 | |
| 6075 | tgt->ha = ha; |
| 6076 | tgt->vha = base_vha; |
| 6077 | init_waitqueue_head(&tgt->waitQ); |
| 6078 | INIT_LIST_HEAD(&tgt->sess_list); |
| 6079 | INIT_LIST_HEAD(&tgt->del_sess_list); |
| 6080 | INIT_DELAYED_WORK(&tgt->sess_del_work, |
| 6081 | (void (*)(struct work_struct *))qlt_del_sess_work_fn); |
| 6082 | spin_lock_init(&tgt->sess_work_lock); |
| 6083 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); |
| 6084 | INIT_LIST_HEAD(&tgt->sess_works_list); |
| 6085 | spin_lock_init(&tgt->srr_lock); |
| 6086 | INIT_LIST_HEAD(&tgt->srr_ctio_list); |
| 6087 | INIT_LIST_HEAD(&tgt->srr_imm_list); |
| 6088 | INIT_WORK(&tgt->srr_work, qlt_handle_srr_work); |
| 6089 | atomic_set(&tgt->tgt_global_resets_count, 0); |
| 6090 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6091 | base_vha->vha_tgt.qla_tgt = tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6092 | |
| 6093 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, |
| 6094 | "qla_target(%d): using 64 Bit PCI addressing", |
| 6095 | base_vha->vp_idx); |
| 6096 | tgt->tgt_enable_64bit_addr = 1; |
| 6097 | /* 3 is reserved */ |
| 6098 | tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3); |
| 6099 | tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX; |
| 6100 | tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX; |
| 6101 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6102 | if (base_vha->fc_vport) |
| 6103 | return 0; |
| 6104 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6105 | mutex_lock(&qla_tgt_mutex); |
| 6106 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); |
| 6107 | mutex_unlock(&qla_tgt_mutex); |
| 6108 | |
| 6109 | return 0; |
| 6110 | } |
| 6111 | |
| 6112 | /* Must be called under tgt_host_action_mutex */ |
| 6113 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) |
| 6114 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6115 | if (!vha->vha_tgt.qla_tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6116 | return 0; |
| 6117 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6118 | if (vha->fc_vport) { |
| 6119 | qlt_release(vha->vha_tgt.qla_tgt); |
| 6120 | return 0; |
| 6121 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 6122 | |
| 6123 | /* free left over qfull cmds */ |
| 6124 | qlt_init_term_exchange(vha); |
| 6125 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6126 | mutex_lock(&qla_tgt_mutex); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6127 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6128 | mutex_unlock(&qla_tgt_mutex); |
| 6129 | |
| 6130 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", |
| 6131 | vha->host_no, ha); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6132 | qlt_release(vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6133 | |
| 6134 | return 0; |
| 6135 | } |
| 6136 | |
| 6137 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, |
| 6138 | unsigned char *b) |
| 6139 | { |
| 6140 | int i; |
| 6141 | |
| 6142 | pr_debug("qla2xxx HW vha->node_name: "); |
| 6143 | for (i = 0; i < WWN_SIZE; i++) |
| 6144 | pr_debug("%02x ", vha->node_name[i]); |
| 6145 | pr_debug("\n"); |
| 6146 | pr_debug("qla2xxx HW vha->port_name: "); |
| 6147 | for (i = 0; i < WWN_SIZE; i++) |
| 6148 | pr_debug("%02x ", vha->port_name[i]); |
| 6149 | pr_debug("\n"); |
| 6150 | |
| 6151 | pr_debug("qla2xxx passed configfs WWPN: "); |
| 6152 | put_unaligned_be64(wwpn, b); |
| 6153 | for (i = 0; i < WWN_SIZE; i++) |
| 6154 | pr_debug("%02x ", b[i]); |
| 6155 | pr_debug("\n"); |
| 6156 | } |
| 6157 | |
| 6158 | /** |
| 6159 | * qla_tgt_lport_register - register lport with external module |
| 6160 | * |
| 6161 | * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops |
| 6162 | * @wwpn: Passwd FC target WWPN |
| 6163 | * @callback: lport initialization callback for tcm_qla2xxx code |
| 6164 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data |
| 6165 | */ |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6166 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
| 6167 | u64 npiv_wwpn, u64 npiv_wwnn, |
| 6168 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6169 | { |
| 6170 | struct qla_tgt *tgt; |
| 6171 | struct scsi_qla_host *vha; |
| 6172 | struct qla_hw_data *ha; |
| 6173 | struct Scsi_Host *host; |
| 6174 | unsigned long flags; |
| 6175 | int rc; |
| 6176 | u8 b[WWN_SIZE]; |
| 6177 | |
| 6178 | mutex_lock(&qla_tgt_mutex); |
| 6179 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { |
| 6180 | vha = tgt->vha; |
| 6181 | ha = vha->hw; |
| 6182 | |
| 6183 | host = vha->host; |
| 6184 | if (!host) |
| 6185 | continue; |
| 6186 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6187 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
| 6188 | continue; |
| 6189 | |
| 6190 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6191 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6192 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
| 6193 | host->host_no); |
| 6194 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6195 | continue; |
| 6196 | } |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6197 | if (tgt->tgt_stop) { |
| 6198 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", |
| 6199 | host->host_no); |
| 6200 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6201 | continue; |
| 6202 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6203 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6204 | |
| 6205 | if (!scsi_host_get(host)) { |
| 6206 | ql_dbg(ql_dbg_tgt, vha, 0xe068, |
| 6207 | "Unable to scsi_host_get() for" |
| 6208 | " qla2xxx scsi_host\n"); |
| 6209 | continue; |
| 6210 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6211 | qlt_lport_dump(vha, phys_wwpn, b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6212 | |
| 6213 | if (memcmp(vha->port_name, b, WWN_SIZE)) { |
| 6214 | scsi_host_put(host); |
| 6215 | continue; |
| 6216 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6217 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
| 6218 | if (rc != 0) |
| 6219 | scsi_host_put(host); |
| 6220 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6221 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6222 | return rc; |
| 6223 | } |
| 6224 | mutex_unlock(&qla_tgt_mutex); |
| 6225 | |
| 6226 | return -ENODEV; |
| 6227 | } |
| 6228 | EXPORT_SYMBOL(qlt_lport_register); |
| 6229 | |
| 6230 | /** |
| 6231 | * qla_tgt_lport_deregister - Degister lport |
| 6232 | * |
| 6233 | * @vha: Registered scsi_qla_host pointer |
| 6234 | */ |
| 6235 | void qlt_lport_deregister(struct scsi_qla_host *vha) |
| 6236 | { |
| 6237 | struct qla_hw_data *ha = vha->hw; |
| 6238 | struct Scsi_Host *sh = vha->host; |
| 6239 | /* |
| 6240 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data |
| 6241 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6242 | vha->vha_tgt.target_lport_ptr = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6243 | ha->tgt.tgt_ops = NULL; |
| 6244 | /* |
| 6245 | * Release the Scsi_Host reference for the underlying qla2xxx host |
| 6246 | */ |
| 6247 | scsi_host_put(sh); |
| 6248 | } |
| 6249 | EXPORT_SYMBOL(qlt_lport_deregister); |
| 6250 | |
| 6251 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6252 | static void qlt_set_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6253 | { |
| 6254 | struct qla_hw_data *ha = vha->hw; |
| 6255 | |
| 6256 | switch (ql2x_ini_mode) { |
| 6257 | case QLA2XXX_INI_MODE_DISABLED: |
| 6258 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6259 | vha->host->active_mode = MODE_TARGET; |
| 6260 | break; |
| 6261 | case QLA2XXX_INI_MODE_ENABLED: |
| 6262 | vha->host->active_mode |= MODE_TARGET; |
| 6263 | break; |
| 6264 | default: |
| 6265 | break; |
| 6266 | } |
| 6267 | |
| 6268 | if (ha->tgt.ini_mode_force_reverse) |
| 6269 | qla_reverse_ini_mode(vha); |
| 6270 | } |
| 6271 | |
| 6272 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6273 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6274 | { |
| 6275 | struct qla_hw_data *ha = vha->hw; |
| 6276 | |
| 6277 | switch (ql2x_ini_mode) { |
| 6278 | case QLA2XXX_INI_MODE_DISABLED: |
| 6279 | vha->host->active_mode = MODE_UNKNOWN; |
| 6280 | break; |
| 6281 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6282 | vha->host->active_mode = MODE_INITIATOR; |
| 6283 | break; |
| 6284 | case QLA2XXX_INI_MODE_ENABLED: |
| 6285 | vha->host->active_mode &= ~MODE_TARGET; |
| 6286 | break; |
| 6287 | default: |
| 6288 | break; |
| 6289 | } |
| 6290 | |
| 6291 | if (ha->tgt.ini_mode_force_reverse) |
| 6292 | qla_reverse_ini_mode(vha); |
| 6293 | } |
| 6294 | |
| 6295 | /* |
| 6296 | * qla_tgt_enable_vha - NO LOCK HELD |
| 6297 | * |
| 6298 | * host_reset, bring up w/ Target Mode Enabled |
| 6299 | */ |
| 6300 | void |
| 6301 | qlt_enable_vha(struct scsi_qla_host *vha) |
| 6302 | { |
| 6303 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6304 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6305 | unsigned long flags; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6306 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | cdb898c | 2015-12-17 14:57:05 -0500 | [diff] [blame] | 6307 | int rspq_ent = QLA83XX_RSPQ_MSIX_ENTRY_NUMBER; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6308 | |
| 6309 | if (!tgt) { |
| 6310 | ql_dbg(ql_dbg_tgt, vha, 0xe069, |
| 6311 | "Unable to locate qla_tgt pointer from" |
| 6312 | " struct qla_hw_data\n"); |
| 6313 | dump_stack(); |
| 6314 | return; |
| 6315 | } |
| 6316 | |
| 6317 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6318 | tgt->tgt_stopped = 0; |
| 6319 | qlt_set_mode(vha); |
| 6320 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6321 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6322 | if (vha->vp_idx) { |
| 6323 | qla24xx_disable_vp(vha); |
| 6324 | qla24xx_enable_vp(vha); |
| 6325 | } else { |
Quinn Tran | cdb898c | 2015-12-17 14:57:05 -0500 | [diff] [blame] | 6326 | if (ha->msix_entries) { |
| 6327 | ql_dbg(ql_dbg_tgt, vha, 0xffff, |
| 6328 | "%s: host%ld : vector %d cpu %d\n", |
| 6329 | __func__, vha->host_no, |
| 6330 | ha->msix_entries[rspq_ent].vector, |
| 6331 | ha->msix_entries[rspq_ent].cpuid); |
| 6332 | |
| 6333 | ha->tgt.rspq_vector_cpuid = |
| 6334 | ha->msix_entries[rspq_ent].cpuid; |
| 6335 | } |
| 6336 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6337 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 6338 | qla2xxx_wake_dpc(base_vha); |
| 6339 | qla2x00_wait_for_hba_online(base_vha); |
| 6340 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6341 | } |
| 6342 | EXPORT_SYMBOL(qlt_enable_vha); |
| 6343 | |
| 6344 | /* |
| 6345 | * qla_tgt_disable_vha - NO LOCK HELD |
| 6346 | * |
| 6347 | * Disable Target Mode and reset the adapter |
| 6348 | */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6349 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6350 | { |
| 6351 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6352 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6353 | unsigned long flags; |
| 6354 | |
| 6355 | if (!tgt) { |
| 6356 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, |
| 6357 | "Unable to locate qla_tgt pointer from" |
| 6358 | " struct qla_hw_data\n"); |
| 6359 | dump_stack(); |
| 6360 | return; |
| 6361 | } |
| 6362 | |
| 6363 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6364 | qlt_clear_mode(vha); |
| 6365 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6366 | |
| 6367 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6368 | qla2xxx_wake_dpc(vha); |
| 6369 | qla2x00_wait_for_hba_online(vha); |
| 6370 | } |
| 6371 | |
| 6372 | /* |
| 6373 | * Called from qla_init.c:qla24xx_vport_create() contex to setup |
| 6374 | * the target mode specific struct scsi_qla_host and struct qla_hw_data |
| 6375 | * members. |
| 6376 | */ |
| 6377 | void |
| 6378 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) |
| 6379 | { |
| 6380 | if (!qla_tgt_mode_enabled(vha)) |
| 6381 | return; |
| 6382 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6383 | vha->vha_tgt.qla_tgt = NULL; |
| 6384 | |
| 6385 | mutex_init(&vha->vha_tgt.tgt_mutex); |
| 6386 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6387 | |
| 6388 | qlt_clear_mode(vha); |
| 6389 | |
| 6390 | /* |
| 6391 | * NOTE: Currently the value is kept the same for <24xx and |
| 6392 | * >=24xx ISPs. If it is necessary to change it, |
| 6393 | * the check should be added for specific ISPs, |
| 6394 | * assigning the value appropriately. |
| 6395 | */ |
| 6396 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6397 | |
| 6398 | qlt_add_target(ha, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6399 | } |
| 6400 | |
| 6401 | void |
| 6402 | qlt_rff_id(struct scsi_qla_host *vha, struct ct_sns_req *ct_req) |
| 6403 | { |
| 6404 | /* |
| 6405 | * FC-4 Feature bit 0 indicates target functionality to the name server. |
| 6406 | */ |
| 6407 | if (qla_tgt_mode_enabled(vha)) { |
| 6408 | if (qla_ini_mode_enabled(vha)) |
| 6409 | ct_req->req.rff_id.fc4_feature = BIT_0 | BIT_1; |
| 6410 | else |
| 6411 | ct_req->req.rff_id.fc4_feature = BIT_0; |
| 6412 | } else if (qla_ini_mode_enabled(vha)) { |
| 6413 | ct_req->req.rff_id.fc4_feature = BIT_1; |
| 6414 | } |
| 6415 | } |
| 6416 | |
| 6417 | /* |
| 6418 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. |
| 6419 | * @ha: HA context |
| 6420 | * |
| 6421 | * Beginning of ATIO ring has initialization control block already built |
| 6422 | * by nvram config routine. |
| 6423 | * |
| 6424 | * Returns 0 on success. |
| 6425 | */ |
| 6426 | void |
| 6427 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) |
| 6428 | { |
| 6429 | struct qla_hw_data *ha = vha->hw; |
| 6430 | uint16_t cnt; |
| 6431 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; |
| 6432 | |
| 6433 | if (!qla_tgt_mode_enabled(vha)) |
| 6434 | return; |
| 6435 | |
| 6436 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { |
| 6437 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6438 | pkt++; |
| 6439 | } |
| 6440 | |
| 6441 | } |
| 6442 | |
| 6443 | /* |
| 6444 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. |
| 6445 | * @ha: SCSI driver HA context |
| 6446 | */ |
| 6447 | void |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6448 | 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] | 6449 | { |
| 6450 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6451 | struct atio_from_isp *pkt; |
| 6452 | int cnt, i; |
| 6453 | |
| 6454 | if (!vha->flags.online) |
| 6455 | return; |
| 6456 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6457 | while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) || |
| 6458 | fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6459 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6460 | cnt = pkt->u.raw.entry_count; |
| 6461 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6462 | if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) { |
| 6463 | /* |
| 6464 | * This packet is corrupted. The header + payload |
| 6465 | * can not be trusted. There is no point in passing |
| 6466 | * it further up. |
| 6467 | */ |
| 6468 | ql_log(ql_log_warn, vha, 0xffff, |
| 6469 | "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n", |
| 6470 | pkt->u.isp24.fcp_hdr.s_id, |
| 6471 | be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id), |
| 6472 | le32_to_cpu(pkt->u.isp24.exchange_addr), pkt); |
| 6473 | |
| 6474 | adjust_corrupted_atio(pkt); |
| 6475 | qlt_send_term_exchange(vha, NULL, pkt, ha_locked, 0); |
| 6476 | } else { |
| 6477 | qlt_24xx_atio_pkt_all_vps(vha, |
| 6478 | (struct atio_from_isp *)pkt, ha_locked); |
| 6479 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6480 | |
| 6481 | for (i = 0; i < cnt; i++) { |
| 6482 | ha->tgt.atio_ring_index++; |
| 6483 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { |
| 6484 | ha->tgt.atio_ring_index = 0; |
| 6485 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 6486 | } else |
| 6487 | ha->tgt.atio_ring_ptr++; |
| 6488 | |
| 6489 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6490 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6491 | } |
| 6492 | wmb(); |
| 6493 | } |
| 6494 | |
| 6495 | /* Adjust ring index */ |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6496 | 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] | 6497 | RD_REG_DWORD_RELAXED(ISP_ATIO_Q_OUT(vha)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | void |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6501 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6502 | { |
| 6503 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6504 | if (!QLA_TGT_MODE_ENABLED()) |
| 6505 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6506 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6507 | WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0); |
| 6508 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0); |
| 6509 | RD_REG_DWORD(ISP_ATIO_Q_OUT(vha)); |
| 6510 | |
| 6511 | if (IS_ATIO_MSIX_CAPABLE(ha)) { |
| 6512 | struct qla_msix_entry *msix = &ha->msix_entries[2]; |
| 6513 | struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb; |
| 6514 | |
| 6515 | icb->msix_atio = cpu_to_le16(msix->entry); |
| 6516 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6517 | "Registering ICB vector 0x%x for atio que.\n", |
| 6518 | msix->entry); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | void |
| 6523 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) |
| 6524 | { |
| 6525 | struct qla_hw_data *ha = vha->hw; |
| 6526 | |
| 6527 | if (qla_tgt_mode_enabled(vha)) { |
| 6528 | if (!ha->tgt.saved_set) { |
| 6529 | /* We save only once */ |
| 6530 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6531 | ha->tgt.saved_firmware_options_1 = |
| 6532 | nv->firmware_options_1; |
| 6533 | ha->tgt.saved_firmware_options_2 = |
| 6534 | nv->firmware_options_2; |
| 6535 | ha->tgt.saved_firmware_options_3 = |
| 6536 | nv->firmware_options_3; |
| 6537 | ha->tgt.saved_set = 1; |
| 6538 | } |
| 6539 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6540 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6541 | |
| 6542 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6543 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6544 | |
| 6545 | /* Disable ini mode, if requested */ |
| 6546 | if (!qla_ini_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6547 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6548 | |
| 6549 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6550 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6551 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6552 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6553 | if (ql2xtgt_tape_enable) |
| 6554 | /* Enable FC Tape support */ |
| 6555 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6556 | else |
| 6557 | /* Disable FC Tape support */ |
| 6558 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6559 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6560 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6561 | nv->host_p &= cpu_to_le32(~BIT_10); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6562 | |
| 6563 | /* |
| 6564 | * clear BIT 15 explicitly as we have seen at least |
| 6565 | * a couple of instances where this was set and this |
| 6566 | * was causing the firmware to not be initialized. |
| 6567 | */ |
| 6568 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6569 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6570 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6571 | } else { |
| 6572 | if (ha->tgt.saved_set) { |
| 6573 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6574 | nv->firmware_options_1 = |
| 6575 | ha->tgt.saved_firmware_options_1; |
| 6576 | nv->firmware_options_2 = |
| 6577 | ha->tgt.saved_firmware_options_2; |
| 6578 | nv->firmware_options_3 = |
| 6579 | ha->tgt.saved_firmware_options_3; |
| 6580 | } |
| 6581 | return; |
| 6582 | } |
| 6583 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6584 | if (ha->tgt.enable_class_2) { |
| 6585 | if (vha->flags.init_done) |
| 6586 | fc_host_supported_classes(vha->host) = |
| 6587 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6588 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6589 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6590 | } else { |
| 6591 | if (vha->flags.init_done) |
| 6592 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6593 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6594 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6595 | } |
| 6596 | } |
| 6597 | |
| 6598 | void |
| 6599 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6600 | struct init_cb_24xx *icb) |
| 6601 | { |
| 6602 | struct qla_hw_data *ha = vha->hw; |
| 6603 | |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6604 | if (!QLA_TGT_MODE_ENABLED()) |
| 6605 | return; |
| 6606 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6607 | if (ha->tgt.node_name_set) { |
| 6608 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6609 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6610 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6611 | |
| 6612 | /* disable ZIO at start time. */ |
| 6613 | if (!vha->flags.init_done) { |
| 6614 | uint32_t tmp; |
| 6615 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6616 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6617 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6618 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6619 | } |
| 6620 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6621 | void |
| 6622 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) |
| 6623 | { |
| 6624 | struct qla_hw_data *ha = vha->hw; |
| 6625 | |
| 6626 | if (!QLA_TGT_MODE_ENABLED()) |
| 6627 | return; |
| 6628 | |
| 6629 | if (qla_tgt_mode_enabled(vha)) { |
| 6630 | if (!ha->tgt.saved_set) { |
| 6631 | /* We save only once */ |
| 6632 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6633 | ha->tgt.saved_firmware_options_1 = |
| 6634 | nv->firmware_options_1; |
| 6635 | ha->tgt.saved_firmware_options_2 = |
| 6636 | nv->firmware_options_2; |
| 6637 | ha->tgt.saved_firmware_options_3 = |
| 6638 | nv->firmware_options_3; |
| 6639 | ha->tgt.saved_set = 1; |
| 6640 | } |
| 6641 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6642 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6643 | |
| 6644 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6645 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6646 | |
| 6647 | /* Disable ini mode, if requested */ |
| 6648 | if (!qla_ini_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6649 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6650 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6651 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6652 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6653 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6654 | /* |
| 6655 | * clear BIT 15 explicitly as we have seen at |
| 6656 | * least a couple of instances where this was set |
| 6657 | * and this was causing the firmware to not be |
| 6658 | * initialized. |
| 6659 | */ |
| 6660 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6661 | if (ql2xtgt_tape_enable) |
| 6662 | /* Enable FC tape support */ |
| 6663 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6664 | else |
| 6665 | /* Disable FC tape support */ |
| 6666 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6667 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6668 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6669 | nv->host_p &= cpu_to_le32(~BIT_10); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6670 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6671 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6672 | } else { |
| 6673 | if (ha->tgt.saved_set) { |
| 6674 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6675 | nv->firmware_options_1 = |
| 6676 | ha->tgt.saved_firmware_options_1; |
| 6677 | nv->firmware_options_2 = |
| 6678 | ha->tgt.saved_firmware_options_2; |
| 6679 | nv->firmware_options_3 = |
| 6680 | ha->tgt.saved_firmware_options_3; |
| 6681 | } |
| 6682 | return; |
| 6683 | } |
| 6684 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6685 | if (ha->tgt.enable_class_2) { |
| 6686 | if (vha->flags.init_done) |
| 6687 | fc_host_supported_classes(vha->host) = |
| 6688 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6689 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6690 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6691 | } else { |
| 6692 | if (vha->flags.init_done) |
| 6693 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6694 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6695 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6696 | } |
| 6697 | } |
| 6698 | |
| 6699 | void |
| 6700 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6701 | struct init_cb_81xx *icb) |
| 6702 | { |
| 6703 | struct qla_hw_data *ha = vha->hw; |
| 6704 | |
| 6705 | if (!QLA_TGT_MODE_ENABLED()) |
| 6706 | return; |
| 6707 | |
| 6708 | if (ha->tgt.node_name_set) { |
| 6709 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6710 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6711 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6712 | |
| 6713 | /* disable ZIO at start time. */ |
| 6714 | if (!vha->flags.init_done) { |
| 6715 | uint32_t tmp; |
| 6716 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6717 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6718 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6719 | } |
| 6720 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | void |
| 6724 | qlt_83xx_iospace_config(struct qla_hw_data *ha) |
| 6725 | { |
| 6726 | if (!QLA_TGT_MODE_ENABLED()) |
| 6727 | return; |
| 6728 | |
| 6729 | ha->msix_count += 1; /* For ATIO Q */ |
| 6730 | } |
| 6731 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6732 | int |
| 6733 | qlt_24xx_process_response_error(struct scsi_qla_host *vha, |
| 6734 | struct sts_entry_24xx *pkt) |
| 6735 | { |
| 6736 | switch (pkt->entry_type) { |
| 6737 | case ABTS_RECV_24XX: |
| 6738 | case ABTS_RESP_24XX: |
| 6739 | case CTIO_TYPE7: |
| 6740 | case NOTIFY_ACK_TYPE: |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 6741 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6742 | return 1; |
| 6743 | default: |
| 6744 | return 0; |
| 6745 | } |
| 6746 | } |
| 6747 | |
| 6748 | void |
| 6749 | qlt_modify_vp_config(struct scsi_qla_host *vha, |
| 6750 | struct vp_config_entry_24xx *vpmod) |
| 6751 | { |
| 6752 | if (qla_tgt_mode_enabled(vha)) |
| 6753 | vpmod->options_idx1 &= ~BIT_5; |
| 6754 | /* Disable ini mode, if requested */ |
| 6755 | if (!qla_ini_mode_enabled(vha)) |
| 6756 | vpmod->options_idx1 &= ~BIT_4; |
| 6757 | } |
| 6758 | |
| 6759 | void |
| 6760 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) |
| 6761 | { |
| 6762 | if (!QLA_TGT_MODE_ENABLED()) |
| 6763 | return; |
| 6764 | |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 6765 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6766 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
| 6767 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; |
| 6768 | } else { |
| 6769 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; |
| 6770 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; |
| 6771 | } |
| 6772 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6773 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
| 6774 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6775 | qlt_clear_mode(base_vha); |
| 6776 | } |
| 6777 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6778 | irqreturn_t |
| 6779 | qla83xx_msix_atio_q(int irq, void *dev_id) |
| 6780 | { |
| 6781 | struct rsp_que *rsp; |
| 6782 | scsi_qla_host_t *vha; |
| 6783 | struct qla_hw_data *ha; |
| 6784 | unsigned long flags; |
| 6785 | |
| 6786 | rsp = (struct rsp_que *) dev_id; |
| 6787 | ha = rsp->hw; |
| 6788 | vha = pci_get_drvdata(ha->pdev); |
| 6789 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6790 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6791 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6792 | qlt_24xx_process_atio_queue(vha, 0); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6793 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6794 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6795 | |
| 6796 | return IRQ_HANDLED; |
| 6797 | } |
| 6798 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6799 | static void |
| 6800 | qlt_handle_abts_recv_work(struct work_struct *work) |
| 6801 | { |
| 6802 | struct qla_tgt_sess_op *op = container_of(work, |
| 6803 | struct qla_tgt_sess_op, work); |
| 6804 | scsi_qla_host_t *vha = op->vha; |
| 6805 | struct qla_hw_data *ha = vha->hw; |
| 6806 | unsigned long flags; |
| 6807 | |
| 6808 | if (qla2x00_reset_active(vha) || (op->chip_reset != ha->chip_reset)) |
| 6809 | return; |
| 6810 | |
| 6811 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 6812 | qlt_24xx_process_atio_queue(vha, 0); |
| 6813 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 6814 | |
| 6815 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6816 | qlt_response_pkt_all_vps(vha, (response_t *)&op->atio); |
| 6817 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6818 | } |
| 6819 | |
| 6820 | void |
| 6821 | qlt_handle_abts_recv(struct scsi_qla_host *vha, response_t *pkt) |
| 6822 | { |
| 6823 | struct qla_tgt_sess_op *op; |
| 6824 | |
| 6825 | op = kzalloc(sizeof(*op), GFP_ATOMIC); |
| 6826 | |
| 6827 | if (!op) { |
| 6828 | /* do not reach for ATIO queue here. This is best effort err |
| 6829 | * recovery at this point. |
| 6830 | */ |
| 6831 | qlt_response_pkt_all_vps(vha, pkt); |
| 6832 | return; |
| 6833 | } |
| 6834 | |
| 6835 | memcpy(&op->atio, pkt, sizeof(*pkt)); |
| 6836 | op->vha = vha; |
| 6837 | op->chip_reset = vha->hw->chip_reset; |
| 6838 | INIT_WORK(&op->work, qlt_handle_abts_recv_work); |
| 6839 | queue_work(qla_tgt_wq, &op->work); |
| 6840 | return; |
| 6841 | } |
| 6842 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6843 | int |
| 6844 | qlt_mem_alloc(struct qla_hw_data *ha) |
| 6845 | { |
| 6846 | if (!QLA_TGT_MODE_ENABLED()) |
| 6847 | return 0; |
| 6848 | |
| 6849 | ha->tgt.tgt_vp_map = kzalloc(sizeof(struct qla_tgt_vp_map) * |
| 6850 | MAX_MULTI_ID_FABRIC, GFP_KERNEL); |
| 6851 | if (!ha->tgt.tgt_vp_map) |
| 6852 | return -ENOMEM; |
| 6853 | |
| 6854 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 6855 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), |
| 6856 | &ha->tgt.atio_dma, GFP_KERNEL); |
| 6857 | if (!ha->tgt.atio_ring) { |
| 6858 | kfree(ha->tgt.tgt_vp_map); |
| 6859 | return -ENOMEM; |
| 6860 | } |
| 6861 | return 0; |
| 6862 | } |
| 6863 | |
| 6864 | void |
| 6865 | qlt_mem_free(struct qla_hw_data *ha) |
| 6866 | { |
| 6867 | if (!QLA_TGT_MODE_ENABLED()) |
| 6868 | return; |
| 6869 | |
| 6870 | if (ha->tgt.atio_ring) { |
| 6871 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * |
| 6872 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, |
| 6873 | ha->tgt.atio_dma); |
| 6874 | } |
| 6875 | kfree(ha->tgt.tgt_vp_map); |
| 6876 | } |
| 6877 | |
| 6878 | /* vport_slock to be held by the caller */ |
| 6879 | void |
| 6880 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) |
| 6881 | { |
| 6882 | if (!QLA_TGT_MODE_ENABLED()) |
| 6883 | return; |
| 6884 | |
| 6885 | switch (cmd) { |
| 6886 | case SET_VP_IDX: |
| 6887 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; |
| 6888 | break; |
| 6889 | case SET_AL_PA: |
| 6890 | vha->hw->tgt.tgt_vp_map[vha->d_id.b.al_pa].idx = vha->vp_idx; |
| 6891 | break; |
| 6892 | case RESET_VP_IDX: |
| 6893 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; |
| 6894 | break; |
| 6895 | case RESET_AL_PA: |
| 6896 | vha->hw->tgt.tgt_vp_map[vha->d_id.b.al_pa].idx = 0; |
| 6897 | break; |
| 6898 | } |
| 6899 | } |
| 6900 | |
| 6901 | static int __init qlt_parse_ini_mode(void) |
| 6902 | { |
| 6903 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) |
| 6904 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
| 6905 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) |
| 6906 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; |
| 6907 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) |
| 6908 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; |
| 6909 | else |
| 6910 | return false; |
| 6911 | |
| 6912 | return true; |
| 6913 | } |
| 6914 | |
| 6915 | int __init qlt_init(void) |
| 6916 | { |
| 6917 | int ret; |
| 6918 | |
| 6919 | if (!qlt_parse_ini_mode()) { |
| 6920 | ql_log(ql_log_fatal, NULL, 0xe06b, |
| 6921 | "qlt_parse_ini_mode() failed\n"); |
| 6922 | return -EINVAL; |
| 6923 | } |
| 6924 | |
| 6925 | if (!QLA_TGT_MODE_ENABLED()) |
| 6926 | return 0; |
| 6927 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6928 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
| 6929 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct |
| 6930 | qla_tgt_mgmt_cmd), 0, NULL); |
| 6931 | if (!qla_tgt_mgmt_cmd_cachep) { |
| 6932 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 6933 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 6934 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6935 | } |
| 6936 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6937 | qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep", |
| 6938 | sizeof(qlt_plogi_ack_t), |
| 6939 | __alignof__(qlt_plogi_ack_t), |
| 6940 | 0, NULL); |
| 6941 | |
| 6942 | if (!qla_tgt_plogi_cachep) { |
| 6943 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 6944 | "kmem_cache_create for qla_tgt_plogi_cachep failed\n"); |
| 6945 | ret = -ENOMEM; |
| 6946 | goto out_mgmt_cmd_cachep; |
| 6947 | } |
| 6948 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6949 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, |
| 6950 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); |
| 6951 | if (!qla_tgt_mgmt_cmd_mempool) { |
| 6952 | ql_log(ql_log_fatal, NULL, 0xe06e, |
| 6953 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); |
| 6954 | ret = -ENOMEM; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6955 | goto out_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6956 | } |
| 6957 | |
| 6958 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); |
| 6959 | if (!qla_tgt_wq) { |
| 6960 | ql_log(ql_log_fatal, NULL, 0xe06f, |
| 6961 | "alloc_workqueue for qla_tgt_wq failed\n"); |
| 6962 | ret = -ENOMEM; |
| 6963 | goto out_cmd_mempool; |
| 6964 | } |
| 6965 | /* |
| 6966 | * Return 1 to signal that initiator-mode is being disabled |
| 6967 | */ |
| 6968 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; |
| 6969 | |
| 6970 | out_cmd_mempool: |
| 6971 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6972 | out_plogi_cachep: |
| 6973 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6974 | out_mgmt_cmd_cachep: |
| 6975 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6976 | return ret; |
| 6977 | } |
| 6978 | |
| 6979 | void qlt_exit(void) |
| 6980 | { |
| 6981 | if (!QLA_TGT_MODE_ENABLED()) |
| 6982 | return; |
| 6983 | |
| 6984 | destroy_workqueue(qla_tgt_wq); |
| 6985 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6986 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6987 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6988 | } |