Thomas Gleixner | 8e8e69d | 2019-05-29 07:17:59 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2 | /* |
| 3 | * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx |
| 4 | * |
| 5 | * based on qla2x00t.c code: |
| 6 | * |
| 7 | * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net> |
| 8 | * Copyright (C) 2004 - 2005 Leonid Stoljar |
| 9 | * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us> |
| 10 | * Copyright (C) 2006 - 2010 ID7 Ltd. |
| 11 | * |
| 12 | * Forward port and refactoring to modern qla2xxx and target/configfs |
| 13 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 14 | * Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org> |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/types.h> |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 20 | #include <linux/blkdev.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/pci.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/list.h> |
| 25 | #include <linux/workqueue.h> |
| 26 | #include <asm/unaligned.h> |
| 27 | #include <scsi/scsi.h> |
| 28 | #include <scsi/scsi_host.h> |
| 29 | #include <scsi/scsi_tcq.h> |
| 30 | #include <target/target_core_base.h> |
| 31 | #include <target/target_core_fabric.h> |
| 32 | |
| 33 | #include "qla_def.h" |
| 34 | #include "qla_target.h" |
| 35 | |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 36 | static int ql2xtgt_tape_enable; |
| 37 | module_param(ql2xtgt_tape_enable, int, S_IRUGO|S_IWUSR); |
| 38 | MODULE_PARM_DESC(ql2xtgt_tape_enable, |
| 39 | "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER."); |
| 40 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 41 | static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED; |
| 42 | module_param(qlini_mode, charp, S_IRUGO); |
| 43 | MODULE_PARM_DESC(qlini_mode, |
| 44 | "Determines when initiator mode will be enabled. Possible values: " |
| 45 | "\"exclusive\" - initiator mode will be enabled on load, " |
| 46 | "disabled on enabling target mode and then on disabling target mode " |
| 47 | "enabled back; " |
| 48 | "\"disabled\" - initiator mode will never be enabled; " |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 49 | "\"dual\" - Initiator Modes will be enabled. Target Mode can be activated " |
| 50 | "when ready " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 51 | "\"enabled\" (default) - initiator mode will always stay enabled."); |
| 52 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 53 | static int ql_dm_tgt_ex_pct = 0; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 54 | module_param(ql_dm_tgt_ex_pct, int, S_IRUGO|S_IWUSR); |
| 55 | MODULE_PARM_DESC(ql_dm_tgt_ex_pct, |
| 56 | "For Dual Mode (qlini_mode=dual), this parameter determines " |
| 57 | "the percentage of exchanges/cmds FW will allocate resources " |
| 58 | "for Target mode."); |
| 59 | |
Quinn Tran | 09620ee | 2017-06-13 20:47:20 -0700 | [diff] [blame] | 60 | int ql2xuctrlirq = 1; |
| 61 | module_param(ql2xuctrlirq, int, 0644); |
| 62 | MODULE_PARM_DESC(ql2xuctrlirq, |
| 63 | "User to control IRQ placement via smp_affinity." |
| 64 | "Valid with qlini_mode=disabled." |
| 65 | "1(default): enable"); |
| 66 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 67 | int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 68 | |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 69 | static int qla_sam_status = SAM_STAT_BUSY; |
| 70 | static int tc_sam_status = SAM_STAT_TASK_SET_FULL; /* target core */ |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 71 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 72 | /* |
| 73 | * From scsi/fc/fc_fcp.h |
| 74 | */ |
| 75 | enum fcp_resp_rsp_codes { |
| 76 | FCP_TMF_CMPL = 0, |
| 77 | FCP_DATA_LEN_INVALID = 1, |
| 78 | FCP_CMND_FIELDS_INVALID = 2, |
| 79 | FCP_DATA_PARAM_MISMATCH = 3, |
| 80 | FCP_TMF_REJECTED = 4, |
| 81 | FCP_TMF_FAILED = 5, |
| 82 | FCP_TMF_INVALID_LUN = 9, |
| 83 | }; |
| 84 | |
| 85 | /* |
| 86 | * fc_pri_ta from scsi/fc/fc_fcp.h |
| 87 | */ |
| 88 | #define FCP_PTA_SIMPLE 0 /* simple task attribute */ |
| 89 | #define FCP_PTA_HEADQ 1 /* head of queue task attribute */ |
| 90 | #define FCP_PTA_ORDERED 2 /* ordered task attribute */ |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 91 | #define FCP_PTA_ACA 4 /* auto. contingent allegiance */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 92 | #define FCP_PTA_MASK 7 /* mask for task attribute field */ |
| 93 | #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */ |
| 94 | #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */ |
| 95 | |
| 96 | /* |
| 97 | * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which |
| 98 | * must be called under HW lock and could unlock/lock it inside. |
| 99 | * It isn't an issue, since in the current implementation on the time when |
| 100 | * those functions are called: |
| 101 | * |
| 102 | * - Either context is IRQ and only IRQ handler can modify HW data, |
| 103 | * including rings related fields, |
| 104 | * |
| 105 | * - Or access to target mode variables from struct qla_tgt doesn't |
| 106 | * cross those functions boundaries, except tgt_stop, which |
| 107 | * additionally protected by irq_cmd_count. |
| 108 | */ |
| 109 | /* Predefs for callbacks handed to qla2xxx LLD */ |
| 110 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 111 | struct atio_from_isp *pkt, uint8_t); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 112 | static void qlt_response_pkt(struct scsi_qla_host *ha, struct rsp_que *rsp, |
| 113 | response_t *pkt); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 114 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 115 | int fn, void *iocb, int flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 116 | static void qlt_send_term_exchange(struct qla_qpair *, struct qla_tgt_cmd |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 117 | *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 118 | static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 119 | struct atio_from_isp *atio, uint16_t status, int qfull); |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 120 | static void qlt_disable_vha(struct scsi_qla_host *vha); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 121 | static void qlt_clear_tgt_db(struct qla_tgt *tgt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 122 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 123 | struct imm_ntfy_from_isp *ntfy, |
| 124 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 125 | 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] | 126 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 127 | struct imm_ntfy_from_isp *imm, int ha_locked); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 128 | static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha, |
| 129 | fc_port_t *fcport, bool local); |
| 130 | void qlt_unreg_sess(struct fc_port *sess); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 131 | static void qlt_24xx_handle_abts(struct scsi_qla_host *, |
| 132 | struct abts_recv_from_24xx *); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 133 | static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *, |
| 134 | uint16_t); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 135 | static int qlt_check_reserve_free_req(struct qla_qpair *qpair, uint32_t); |
| 136 | static inline uint32_t qlt_make_handle(struct qla_qpair *); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 137 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 138 | /* |
| 139 | * Global Variables |
| 140 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 141 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; |
Quinn Tran | b5d1531 | 2017-08-30 10:16:49 -0700 | [diff] [blame] | 142 | struct kmem_cache *qla_tgt_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 143 | static mempool_t *qla_tgt_mgmt_cmd_mempool; |
| 144 | static struct workqueue_struct *qla_tgt_wq; |
| 145 | static DEFINE_MUTEX(qla_tgt_mutex); |
| 146 | static LIST_HEAD(qla_tgt_glist); |
| 147 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 148 | static const char *prot_op_str(u32 prot_op) |
| 149 | { |
| 150 | switch (prot_op) { |
| 151 | case TARGET_PROT_NORMAL: return "NORMAL"; |
| 152 | case TARGET_PROT_DIN_INSERT: return "DIN_INSERT"; |
| 153 | case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT"; |
| 154 | case TARGET_PROT_DIN_STRIP: return "DIN_STRIP"; |
| 155 | case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP"; |
| 156 | case TARGET_PROT_DIN_PASS: return "DIN_PASS"; |
| 157 | case TARGET_PROT_DOUT_PASS: return "DOUT_PASS"; |
| 158 | default: return "UNKNOWN"; |
| 159 | } |
| 160 | } |
| 161 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 162 | /* This API intentionally takes dest as a parameter, rather than returning |
| 163 | * int value to avoid caller forgetting to issue wmb() after the store */ |
| 164 | void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest) |
| 165 | { |
| 166 | scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev); |
| 167 | *dest = atomic_inc_return(&base_vha->generation_tick); |
| 168 | /* memory barrier */ |
| 169 | wmb(); |
| 170 | } |
| 171 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 172 | /* Might release hw lock, then reaquire!! */ |
| 173 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) |
| 174 | { |
| 175 | /* Send marker if required */ |
| 176 | if (unlikely(vha->marker_needed != 0)) { |
| 177 | int rc = qla2x00_issue_marker(vha, vha_locked); |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 178 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 179 | if (rc != QLA_SUCCESS) { |
| 180 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, |
| 181 | "qla_target(%d): issue_marker() failed\n", |
| 182 | vha->vp_idx); |
| 183 | } |
| 184 | return rc; |
| 185 | } |
| 186 | return QLA_SUCCESS; |
| 187 | } |
| 188 | |
| 189 | static inline |
| 190 | struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha, |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 191 | be_id_t d_id) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 192 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 193 | struct scsi_qla_host *host; |
Bart Van Assche | aa20e38 | 2019-08-08 20:02:03 -0700 | [diff] [blame] | 194 | uint32_t key; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 195 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 196 | if (vha->d_id.b.area == d_id.area && |
| 197 | vha->d_id.b.domain == d_id.domain && |
| 198 | vha->d_id.b.al_pa == d_id.al_pa) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 199 | return vha; |
| 200 | |
Bart Van Assche | aa20e38 | 2019-08-08 20:02:03 -0700 | [diff] [blame] | 201 | key = be_to_port_id(d_id).b24; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 202 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 203 | host = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 204 | if (!host) |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 205 | ql_dbg(ql_dbg_tgt_mgt + ql_dbg_verbose, vha, 0xf005, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 206 | "Unable to find host %06x\n", key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 207 | |
| 208 | return host; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | static inline |
| 212 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, |
| 213 | uint16_t vp_idx) |
| 214 | { |
| 215 | struct qla_hw_data *ha = vha->hw; |
| 216 | |
| 217 | if (vha->vp_idx == vp_idx) |
| 218 | return vha; |
| 219 | |
| 220 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 221 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 222 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 223 | |
| 224 | return NULL; |
| 225 | } |
| 226 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 227 | static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha) |
| 228 | { |
| 229 | unsigned long flags; |
| 230 | |
| 231 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 232 | |
| 233 | vha->hw->tgt.num_pend_cmds++; |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 234 | if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds) |
| 235 | vha->qla_stats.stat_max_pend_cmds = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 236 | vha->hw->tgt.num_pend_cmds; |
| 237 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 238 | } |
| 239 | static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha) |
| 240 | { |
| 241 | unsigned long flags; |
| 242 | |
| 243 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 244 | vha->hw->tgt.num_pend_cmds--; |
| 245 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 246 | } |
| 247 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 248 | |
| 249 | static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 250 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 251 | { |
| 252 | struct qla_tgt_sess_op *u; |
| 253 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 254 | unsigned long flags; |
| 255 | |
| 256 | if (tgt->tgt_stop) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 257 | ql_dbg(ql_dbg_async, vha, 0x502c, |
| 258 | "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped", |
| 259 | vha->vp_idx); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 260 | goto out_term; |
| 261 | } |
| 262 | |
| 263 | u = kzalloc(sizeof(*u), GFP_ATOMIC); |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 264 | if (u == NULL) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 265 | goto out_term; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 266 | |
| 267 | u->vha = vha; |
| 268 | memcpy(&u->atio, atio, sizeof(*atio)); |
| 269 | INIT_LIST_HEAD(&u->cmd_list); |
| 270 | |
| 271 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 272 | list_add_tail(&u->cmd_list, &vha->unknown_atio_list); |
| 273 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 274 | |
| 275 | schedule_delayed_work(&vha->unknown_atio_work, 1); |
| 276 | |
| 277 | out: |
| 278 | return; |
| 279 | |
| 280 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 281 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 282 | goto out; |
| 283 | } |
| 284 | |
| 285 | static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha, |
| 286 | uint8_t ha_locked) |
| 287 | { |
| 288 | struct qla_tgt_sess_op *u, *t; |
| 289 | scsi_qla_host_t *host; |
| 290 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 291 | unsigned long flags; |
| 292 | uint8_t queued = 0; |
| 293 | |
| 294 | list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) { |
| 295 | if (u->aborted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 296 | ql_dbg(ql_dbg_async, vha, 0x502e, |
| 297 | "Freeing unknown %s %p, because of Abort\n", |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 298 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 299 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 300 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 301 | goto abort; |
| 302 | } |
| 303 | |
| 304 | host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id); |
| 305 | if (host != NULL) { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 306 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x502f, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 307 | "Requeuing unknown ATIO_TYPE7 %p\n", u); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 308 | qlt_24xx_atio_pkt(host, &u->atio, ha_locked); |
| 309 | } else if (tgt->tgt_stop) { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 310 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503a, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 311 | "Freeing unknown %s %p, because tgt is being stopped\n", |
| 312 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 313 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 314 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 315 | } else { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 316 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 317 | "Reschedule u %p, vha %p, host %p\n", u, vha, host); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 318 | if (!queued) { |
| 319 | queued = 1; |
| 320 | schedule_delayed_work(&vha->unknown_atio_work, |
| 321 | 1); |
| 322 | } |
| 323 | continue; |
| 324 | } |
| 325 | |
| 326 | abort: |
| 327 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 328 | list_del(&u->cmd_list); |
| 329 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 330 | kfree(u); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | void qlt_unknown_atio_work_fn(struct work_struct *work) |
| 335 | { |
| 336 | struct scsi_qla_host *vha = container_of(to_delayed_work(work), |
| 337 | struct scsi_qla_host, unknown_atio_work); |
| 338 | |
| 339 | qlt_try_to_dequeue_unknown_atios(vha, 0); |
| 340 | } |
| 341 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 342 | 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] | 343 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 344 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 345 | ql_dbg(ql_dbg_tgt, vha, 0xe072, |
| 346 | "%s: qla_target(%d): type %x ox_id %04x\n", |
| 347 | __func__, vha->vp_idx, atio->u.raw.entry_type, |
| 348 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 349 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 350 | switch (atio->u.raw.entry_type) { |
| 351 | case ATIO_TYPE7: |
| 352 | { |
| 353 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, |
| 354 | atio->u.isp24.fcp_hdr.d_id); |
| 355 | if (unlikely(NULL == host)) { |
| 356 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, |
| 357 | "qla_target(%d): Received ATIO_TYPE7 " |
| 358 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 359 | atio->u.isp24.fcp_hdr.d_id.domain, |
| 360 | atio->u.isp24.fcp_hdr.d_id.area, |
| 361 | atio->u.isp24.fcp_hdr.d_id.al_pa); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 362 | |
| 363 | |
| 364 | qlt_queue_unknown_atio(vha, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 365 | break; |
| 366 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 367 | if (unlikely(!list_empty(&vha->unknown_atio_list))) |
| 368 | qlt_try_to_dequeue_unknown_atios(vha, ha_locked); |
| 369 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 370 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 371 | break; |
| 372 | } |
| 373 | |
| 374 | case IMMED_NOTIFY_TYPE: |
| 375 | { |
| 376 | struct scsi_qla_host *host = vha; |
| 377 | struct imm_ntfy_from_isp *entry = |
| 378 | (struct imm_ntfy_from_isp *)atio; |
| 379 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 380 | qlt_issue_marker(vha, ha_locked); |
| 381 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 382 | if ((entry->u.isp24.vp_index != 0xFF) && |
| 383 | (entry->u.isp24.nport_handle != 0xFFFF)) { |
| 384 | host = qlt_find_host_by_vp_idx(vha, |
| 385 | entry->u.isp24.vp_index); |
| 386 | if (unlikely(!host)) { |
| 387 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, |
| 388 | "qla_target(%d): Received " |
| 389 | "ATIO (IMMED_NOTIFY_TYPE) " |
| 390 | "with unknown vp_index %d\n", |
| 391 | vha->vp_idx, entry->u.isp24.vp_index); |
| 392 | break; |
| 393 | } |
| 394 | } |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 395 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 396 | break; |
| 397 | } |
| 398 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 399 | case VP_RPT_ID_IOCB_TYPE: |
| 400 | qla24xx_report_id_acquisition(vha, |
| 401 | (struct vp_rpt_id_entry_24xx *)atio); |
| 402 | break; |
| 403 | |
| 404 | case ABTS_RECV_24XX: |
| 405 | { |
| 406 | struct abts_recv_from_24xx *entry = |
| 407 | (struct abts_recv_from_24xx *)atio; |
| 408 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 409 | entry->vp_index); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 410 | unsigned long flags; |
| 411 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 412 | if (unlikely(!host)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 413 | ql_dbg(ql_dbg_tgt, vha, 0xe00a, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 414 | "qla_target(%d): Response pkt (ABTS_RECV_24XX) " |
| 415 | "received, with unknown vp_index %d\n", |
| 416 | vha->vp_idx, entry->vp_index); |
| 417 | break; |
| 418 | } |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 419 | if (!ha_locked) |
| 420 | spin_lock_irqsave(&host->hw->hardware_lock, flags); |
| 421 | qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio); |
| 422 | if (!ha_locked) |
| 423 | spin_unlock_irqrestore(&host->hw->hardware_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 424 | break; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */ |
| 428 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 429 | default: |
| 430 | ql_dbg(ql_dbg_tgt, vha, 0xe040, |
| 431 | "qla_target(%d): Received unknown ATIO atio " |
| 432 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 433 | break; |
| 434 | } |
| 435 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 436 | return false; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 437 | } |
| 438 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 439 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, |
| 440 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 441 | { |
| 442 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 443 | case CTIO_CRC2: |
| 444 | ql_dbg(ql_dbg_tgt, vha, 0xe073, |
| 445 | "qla_target(%d):%s: CRC2 Response pkt\n", |
| 446 | vha->vp_idx, __func__); |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 447 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 448 | case CTIO_TYPE7: |
| 449 | { |
| 450 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
| 451 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 452 | entry->vp_index); |
| 453 | if (unlikely(!host)) { |
| 454 | ql_dbg(ql_dbg_tgt, vha, 0xe041, |
| 455 | "qla_target(%d): Response pkt (CTIO_TYPE7) " |
| 456 | "received, with unknown vp_index %d\n", |
| 457 | vha->vp_idx, entry->vp_index); |
| 458 | break; |
| 459 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 460 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 461 | break; |
| 462 | } |
| 463 | |
| 464 | case IMMED_NOTIFY_TYPE: |
| 465 | { |
Colin Ian King | da6d296 | 2019-09-05 14:42:29 +0100 | [diff] [blame] | 466 | struct scsi_qla_host *host; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 467 | struct imm_ntfy_from_isp *entry = |
| 468 | (struct imm_ntfy_from_isp *)pkt; |
| 469 | |
| 470 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); |
| 471 | if (unlikely(!host)) { |
| 472 | ql_dbg(ql_dbg_tgt, vha, 0xe042, |
| 473 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " |
| 474 | "received, with unknown vp_index %d\n", |
| 475 | vha->vp_idx, entry->u.isp24.vp_index); |
| 476 | break; |
| 477 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 478 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 479 | break; |
| 480 | } |
| 481 | |
| 482 | case NOTIFY_ACK_TYPE: |
| 483 | { |
| 484 | struct scsi_qla_host *host = vha; |
| 485 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 486 | |
| 487 | if (0xFF != entry->u.isp24.vp_index) { |
| 488 | host = qlt_find_host_by_vp_idx(vha, |
| 489 | entry->u.isp24.vp_index); |
| 490 | if (unlikely(!host)) { |
| 491 | ql_dbg(ql_dbg_tgt, vha, 0xe043, |
| 492 | "qla_target(%d): Response " |
| 493 | "pkt (NOTIFY_ACK_TYPE) " |
| 494 | "received, with unknown " |
| 495 | "vp_index %d\n", vha->vp_idx, |
| 496 | entry->u.isp24.vp_index); |
| 497 | break; |
| 498 | } |
| 499 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 500 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 501 | break; |
| 502 | } |
| 503 | |
| 504 | case ABTS_RECV_24XX: |
| 505 | { |
| 506 | struct abts_recv_from_24xx *entry = |
| 507 | (struct abts_recv_from_24xx *)pkt; |
| 508 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 509 | entry->vp_index); |
| 510 | if (unlikely(!host)) { |
| 511 | ql_dbg(ql_dbg_tgt, vha, 0xe044, |
| 512 | "qla_target(%d): Response pkt " |
| 513 | "(ABTS_RECV_24XX) received, with unknown " |
| 514 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 515 | break; |
| 516 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 517 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 518 | break; |
| 519 | } |
| 520 | |
| 521 | case ABTS_RESP_24XX: |
| 522 | { |
| 523 | struct abts_resp_to_24xx *entry = |
| 524 | (struct abts_resp_to_24xx *)pkt; |
| 525 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 526 | entry->vp_index); |
| 527 | if (unlikely(!host)) { |
| 528 | ql_dbg(ql_dbg_tgt, vha, 0xe045, |
| 529 | "qla_target(%d): Response pkt " |
| 530 | "(ABTS_RECV_24XX) received, with unknown " |
| 531 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 532 | break; |
| 533 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 534 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 535 | break; |
| 536 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 537 | default: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 538 | qlt_response_pkt(vha, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 539 | break; |
| 540 | } |
| 541 | |
| 542 | } |
| 543 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 544 | /* |
| 545 | * All qlt_plogi_ack_t operations are protected by hardware_lock |
| 546 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 547 | static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 548 | struct imm_ntfy_from_isp *ntfy, int type) |
| 549 | { |
| 550 | struct qla_work_evt *e; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 551 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 552 | e = qla2x00_alloc_work(vha, QLA_EVT_NACK); |
| 553 | if (!e) |
| 554 | return QLA_FUNCTION_FAILED; |
| 555 | |
| 556 | e->u.nack.fcport = fcport; |
| 557 | e->u.nack.type = type; |
| 558 | memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp)); |
| 559 | return qla2x00_post_work(vha, e); |
| 560 | } |
| 561 | |
Bart Van Assche | 6c18a43 | 2019-08-08 20:02:04 -0700 | [diff] [blame] | 562 | static void qla2x00_async_nack_sp_done(srb_t *sp, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 563 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 564 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 565 | unsigned long flags; |
| 566 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 567 | ql_dbg(ql_dbg_disc, vha, 0x20f2, |
| 568 | "Async done-%s res %x %8phC type %d\n", |
| 569 | sp->name, res, sp->fcport->port_name, sp->type); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 570 | |
| 571 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 572 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 573 | sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 574 | |
| 575 | switch (sp->type) { |
| 576 | case SRB_NACK_PLOGI: |
| 577 | sp->fcport->login_gen++; |
| 578 | sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP; |
| 579 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 580 | sp->fcport->plogi_nack_done_deadline = jiffies + HZ; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 581 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 582 | break; |
| 583 | |
| 584 | case SRB_NACK_PRLI: |
| 585 | sp->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 586 | sp->fcport->deleted = 0; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 587 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 588 | |
| 589 | if (!sp->fcport->login_succ && |
| 590 | !IS_SW_RESV_ADDR(sp->fcport->d_id)) { |
| 591 | sp->fcport->login_succ = 1; |
| 592 | |
| 593 | vha->fcport_count++; |
Quinn Tran | 0aca778 | 2018-09-04 14:19:16 -0700 | [diff] [blame] | 594 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 595 | qla24xx_sched_upd_fcport(sp->fcport); |
Quinn Tran | 0aca778 | 2018-09-04 14:19:16 -0700 | [diff] [blame] | 596 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | 2952849 | 2018-05-01 09:01:45 -0700 | [diff] [blame] | 597 | } else { |
| 598 | sp->fcport->login_retry = 0; |
Shyam Sundar | 27258a5 | 2019-12-17 14:06:06 -0800 | [diff] [blame] | 599 | qla2x00_set_fcport_disc_state(sp->fcport, |
| 600 | DSC_LOGIN_COMPLETE); |
Quinn Tran | 2952849 | 2018-05-01 09:01:45 -0700 | [diff] [blame] | 601 | sp->fcport->deleted = 0; |
| 602 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 603 | } |
| 604 | break; |
| 605 | |
| 606 | case SRB_NACK_LOGO: |
| 607 | sp->fcport->login_gen++; |
| 608 | sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 609 | qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE); |
| 610 | break; |
| 611 | } |
| 612 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 613 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 614 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport, |
| 618 | struct imm_ntfy_from_isp *ntfy, int type) |
| 619 | { |
| 620 | int rval = QLA_FUNCTION_FAILED; |
| 621 | srb_t *sp; |
| 622 | char *c = NULL; |
| 623 | |
| 624 | fcport->flags |= FCF_ASYNC_SENT; |
| 625 | switch (type) { |
| 626 | case SRB_NACK_PLOGI: |
| 627 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; |
| 628 | c = "PLOGI"; |
| 629 | break; |
| 630 | case SRB_NACK_PRLI: |
| 631 | fcport->fw_login_state = DSC_LS_PRLI_PEND; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 632 | fcport->deleted = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 633 | c = "PRLI"; |
| 634 | break; |
| 635 | case SRB_NACK_LOGO: |
| 636 | fcport->fw_login_state = DSC_LS_LOGO_PEND; |
| 637 | c = "LOGO"; |
| 638 | break; |
| 639 | } |
| 640 | |
| 641 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
| 642 | if (!sp) |
| 643 | goto done; |
| 644 | |
| 645 | sp->type = type; |
| 646 | sp->name = "nack"; |
| 647 | |
Ben Hutchings | e74e7d9 | 2018-03-20 21:36:14 +0000 | [diff] [blame] | 648 | sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 649 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 650 | |
| 651 | sp->u.iocb_cmd.u.nack.ntfy = ntfy; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 652 | sp->done = qla2x00_async_nack_sp_done; |
| 653 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 654 | ql_dbg(ql_dbg_disc, vha, 0x20f4, |
| 655 | "Async-%s %8phC hndl %x %s\n", |
| 656 | sp->name, fcport->port_name, sp->handle, c); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 657 | |
Bill Kuzeja | f233e8c | 2019-02-14 10:52:29 -0500 | [diff] [blame] | 658 | rval = qla2x00_start_sp(sp); |
| 659 | if (rval != QLA_SUCCESS) |
| 660 | goto done_free_sp; |
| 661 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 662 | return rval; |
| 663 | |
| 664 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 665 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 666 | done: |
| 667 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 668 | return rval; |
| 669 | } |
| 670 | |
| 671 | void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
| 672 | { |
| 673 | fc_port_t *t; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 674 | |
| 675 | switch (e->u.nack.type) { |
| 676 | case SRB_NACK_PRLI: |
Quinn Tran | 1021f0b | 2019-01-24 23:23:45 -0800 | [diff] [blame] | 677 | t = e->u.nack.fcport; |
| 678 | flush_work(&t->del_work); |
| 679 | flush_work(&t->free_work); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 680 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 681 | t = qlt_create_sess(vha, e->u.nack.fcport, 0); |
| 682 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 683 | if (t) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 684 | ql_log(ql_log_info, vha, 0xd034, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 685 | "%s create sess success %p", __func__, t); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 686 | /* create sess has an extra kref */ |
| 687 | vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 688 | } |
| 689 | break; |
| 690 | } |
| 691 | qla24xx_async_notify_ack(vha, e->u.nack.fcport, |
Bart Van Assche | 845bbb0 | 2019-04-11 14:53:18 -0700 | [diff] [blame] | 692 | (struct imm_ntfy_from_isp *)e->u.nack.iocb, e->u.nack.type); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | void qla24xx_delete_sess_fn(struct work_struct *work) |
| 696 | { |
| 697 | fc_port_t *fcport = container_of(work, struct fc_port, del_work); |
| 698 | struct qla_hw_data *ha = fcport->vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 699 | |
| 700 | if (fcport->se_sess) { |
| 701 | ha->tgt.tgt_ops->shutdown_sess(fcport); |
| 702 | ha->tgt.tgt_ops->put_sess(fcport); |
| 703 | } else { |
| 704 | qlt_unreg_sess(fcport); |
| 705 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | /* |
| 709 | * Called from qla2x00_reg_remote_port() |
| 710 | */ |
| 711 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 712 | { |
| 713 | struct qla_hw_data *ha = vha->hw; |
| 714 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 715 | struct fc_port *sess = fcport; |
| 716 | unsigned long flags; |
| 717 | |
| 718 | if (!vha->hw->tgt.tgt_ops) |
| 719 | return; |
| 720 | |
| 721 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 722 | if (tgt->tgt_stop) { |
| 723 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 724 | return; |
| 725 | } |
| 726 | |
| 727 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 728 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 729 | return; |
| 730 | } |
| 731 | |
| 732 | if (!sess->se_sess) { |
| 733 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 734 | |
| 735 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 736 | sess = qlt_create_sess(vha, fcport, false); |
| 737 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 738 | |
| 739 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 740 | } else { |
| 741 | if (fcport->fw_login_state == DSC_LS_PRLI_COMP) { |
| 742 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 743 | return; |
| 744 | } |
| 745 | |
| 746 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 747 | ql_dbg(ql_dbg_disc, vha, 0x2107, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 748 | "%s: kref_get fail sess %8phC \n", |
| 749 | __func__, sess->port_name); |
| 750 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, |
| 755 | "qla_target(%u): %ssession for port %8phC " |
| 756 | "(loop ID %d) reappeared\n", vha->vp_idx, |
| 757 | sess->local ? "local " : "", sess->port_name, sess->loop_id); |
| 758 | |
| 759 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, |
| 760 | "Reappeared sess %p\n", sess); |
| 761 | |
| 762 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, |
| 763 | fcport->loop_id, |
| 764 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
| 765 | } |
| 766 | |
| 767 | if (sess && sess->local) { |
| 768 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, |
| 769 | "qla_target(%u): local session for " |
| 770 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
| 771 | fcport->port_name, sess->loop_id); |
| 772 | sess->local = 0; |
| 773 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 774 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 775 | |
| 776 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 777 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 778 | |
| 779 | /* |
| 780 | * This is a zero-base ref-counting solution, since hardware_lock |
| 781 | * guarantees that ref_count is not modified concurrently. |
| 782 | * Upon successful return content of iocb is undefined |
| 783 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 784 | static struct qlt_plogi_ack_t * |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 785 | qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id, |
| 786 | struct imm_ntfy_from_isp *iocb) |
| 787 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 788 | struct qlt_plogi_ack_t *pla; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 789 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 790 | lockdep_assert_held(&vha->hw->hardware_lock); |
| 791 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 792 | list_for_each_entry(pla, &vha->plogi_ack_list, list) { |
| 793 | if (pla->id.b24 == id->b24) { |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 794 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x210d, |
| 795 | "%s %d %8phC Term INOT due to new INOT", |
| 796 | __func__, __LINE__, |
| 797 | pla->iocb.u.isp24.port_name); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 798 | qlt_send_term_imm_notif(vha, &pla->iocb, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 799 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 800 | return pla; |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC); |
| 805 | if (!pla) { |
| 806 | ql_dbg(ql_dbg_async, vha, 0x5088, |
| 807 | "qla_target(%d): Allocation of plogi_ack failed\n", |
| 808 | vha->vp_idx); |
| 809 | return NULL; |
| 810 | } |
| 811 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 812 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 813 | pla->id = *id; |
| 814 | list_add_tail(&pla->list, &vha->plogi_ack_list); |
| 815 | |
| 816 | return pla; |
| 817 | } |
| 818 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 819 | void qlt_plogi_ack_unref(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 820 | struct qlt_plogi_ack_t *pla) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 821 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 822 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 823 | port_id_t port_id; |
| 824 | uint16_t loop_id; |
| 825 | fc_port_t *fcport = pla->fcport; |
| 826 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 827 | BUG_ON(!pla->ref_count); |
| 828 | pla->ref_count--; |
| 829 | |
| 830 | if (pla->ref_count) |
| 831 | return; |
| 832 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 833 | ql_dbg(ql_dbg_disc, vha, 0x5089, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 834 | "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x" |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 835 | " exch %#x ox_id %#x\n", iocb->u.isp24.port_name, |
| 836 | iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1], |
| 837 | iocb->u.isp24.port_id[0], |
| 838 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 839 | iocb->u.isp24.exchange_address, iocb->ox_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 840 | |
| 841 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 842 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 843 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 844 | port_id.b.rsvd_1 = 0; |
| 845 | |
| 846 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 847 | |
| 848 | fcport->loop_id = loop_id; |
| 849 | fcport->d_id = port_id; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 850 | if (iocb->u.isp24.status_subcode == ELS_PLOGI) |
| 851 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI); |
| 852 | else |
| 853 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PRLI); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 854 | |
| 855 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 856 | if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla) |
| 857 | fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 858 | if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla) |
| 859 | fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
| 860 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 861 | |
| 862 | list_del(&pla->list); |
| 863 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 864 | } |
| 865 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 866 | void |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 867 | qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla, |
| 868 | struct fc_port *sess, enum qlt_plogi_link_t link) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 869 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 870 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 871 | /* Inc ref_count first because link might already be pointing at pla */ |
| 872 | pla->ref_count++; |
| 873 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 874 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097, |
| 875 | "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC" |
| 876 | " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n", |
| 877 | sess, link, sess->port_name, |
| 878 | iocb->u.isp24.port_name, iocb->u.isp24.port_id[2], |
| 879 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 880 | pla->ref_count, pla, link); |
| 881 | |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 882 | if (link == QLT_PLOGI_LINK_CONFLICT) { |
| 883 | switch (sess->disc_state) { |
| 884 | case DSC_DELETED: |
| 885 | case DSC_DELETE_PEND: |
| 886 | pla->ref_count--; |
| 887 | return; |
| 888 | default: |
| 889 | break; |
| 890 | } |
| 891 | } |
| 892 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 893 | if (sess->plogi_link[link]) |
| 894 | qlt_plogi_ack_unref(vha, sess->plogi_link[link]); |
| 895 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 896 | if (link == QLT_PLOGI_LINK_SAME_WWN) |
| 897 | pla->fcport = sess; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 898 | |
| 899 | sess->plogi_link[link] = pla; |
| 900 | } |
| 901 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 902 | typedef struct { |
| 903 | /* These fields must be initialized by the caller */ |
| 904 | port_id_t id; |
| 905 | /* |
| 906 | * number of cmds dropped while we were waiting for |
| 907 | * initiator to ack LOGO initialize to 1 if LOGO is |
| 908 | * triggered by a command, otherwise, to 0 |
| 909 | */ |
| 910 | int cmd_count; |
| 911 | |
| 912 | /* These fields are used by callee */ |
| 913 | struct list_head list; |
| 914 | } qlt_port_logo_t; |
| 915 | |
| 916 | static void |
| 917 | qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo) |
| 918 | { |
| 919 | qlt_port_logo_t *tmp; |
| 920 | int res; |
| 921 | |
| 922 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 923 | |
| 924 | list_for_each_entry(tmp, &vha->logo_list, list) { |
| 925 | if (tmp->id.b24 == logo->id.b24) { |
| 926 | tmp->cmd_count += logo->cmd_count; |
| 927 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 928 | return; |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | list_add_tail(&logo->list, &vha->logo_list); |
| 933 | |
| 934 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 935 | |
| 936 | res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id); |
| 937 | |
| 938 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 939 | list_del(&logo->list); |
| 940 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 941 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 942 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098, |
| 943 | "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n", |
| 944 | logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa, |
| 945 | logo->cmd_count, res); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 946 | } |
| 947 | |
Darren Trapp | 9dd9686 | 2018-03-20 23:09:32 -0700 | [diff] [blame] | 948 | void qlt_free_session_done(struct work_struct *work) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 949 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 950 | struct fc_port *sess = container_of(work, struct fc_port, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 951 | free_work); |
| 952 | struct qla_tgt *tgt = sess->tgt; |
| 953 | struct scsi_qla_host *vha = sess->vha; |
| 954 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 955 | unsigned long flags; |
| 956 | bool logout_started = false; |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 957 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 958 | struct qlt_plogi_ack_t *own = |
| 959 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 960 | |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame^] | 961 | ql_dbg(ql_dbg_disc, vha, 0xf084, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 962 | "%s: se_sess %p / sess %p from port %8phC loop_id %#04x" |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 963 | " 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] | 964 | __func__, sess->se_sess, sess, sess->port_name, sess->loop_id, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 965 | sess->d_id.b.domain, sess->d_id.b.area, sess->d_id.b.al_pa, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 966 | sess->logout_on_delete, sess->keep_nport_handle, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 967 | sess->send_els_logo); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 968 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 969 | if (!IS_SW_RESV_ADDR(sess->d_id)) { |
Himanshu Madhani | 3c75ad1 | 2019-12-17 14:06:04 -0800 | [diff] [blame] | 970 | qla2x00_mark_device_lost(vha, sess, 0); |
Quinn Tran | 2137490 | 2019-04-23 14:52:35 -0700 | [diff] [blame] | 971 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 972 | if (sess->send_els_logo) { |
| 973 | qlt_port_logo_t logo; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 974 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 975 | logo.id = sess->d_id; |
| 976 | logo.cmd_count = 0; |
Quinn Tran | cb97f2c | 2018-08-02 13:16:51 -0700 | [diff] [blame] | 977 | if (!own) |
| 978 | qlt_send_first_logo(vha, &logo); |
Himanshu Madhani | a239034 | 2018-01-22 12:04:20 -0800 | [diff] [blame] | 979 | sess->send_els_logo = 0; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 980 | } |
| 981 | |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 982 | if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 983 | int rc; |
| 984 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 985 | if (!own || |
| 986 | (own && |
| 987 | (own->iocb.u.isp24.status_subcode == ELS_PLOGI))) { |
| 988 | rc = qla2x00_post_async_logout_work(vha, sess, |
| 989 | NULL); |
| 990 | if (rc != QLA_SUCCESS) |
| 991 | ql_log(ql_log_warn, vha, 0xf085, |
| 992 | "Schedule logo failed sess %p rc %d\n", |
| 993 | sess, rc); |
| 994 | else |
| 995 | logout_started = true; |
| 996 | } else if (own && (own->iocb.u.isp24.status_subcode == |
| 997 | ELS_PRLI) && ha->flags.rida_fmt2) { |
| 998 | rc = qla2x00_post_async_prlo_work(vha, sess, |
| 999 | NULL); |
| 1000 | if (rc != QLA_SUCCESS) |
| 1001 | ql_log(ql_log_warn, vha, 0xf085, |
| 1002 | "Schedule PRLO failed sess %p rc %d\n", |
| 1003 | sess, rc); |
| 1004 | else |
| 1005 | logout_started = true; |
| 1006 | } |
Quinn Tran | baf23ed | 2019-06-16 08:05:53 -0700 | [diff] [blame] | 1007 | } /* if sess->logout_on_delete */ |
| 1008 | |
| 1009 | if (sess->nvme_flag & NVME_FLAG_REGISTERED && |
| 1010 | !(sess->nvme_flag & NVME_FLAG_DELETING)) { |
| 1011 | sess->nvme_flag |= NVME_FLAG_DELETING; |
| 1012 | qla_nvme_unregister_remote_port(sess); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1013 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1014 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1015 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1016 | /* |
| 1017 | * Release the target session for FC Nexus from fabric module code. |
| 1018 | */ |
| 1019 | if (sess->se_sess != NULL) |
| 1020 | ha->tgt.tgt_ops->free_session(sess); |
| 1021 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1022 | if (logout_started) { |
| 1023 | bool traced = false; |
Quinn Tran | c3b6a1d | 2019-09-12 11:09:06 -0700 | [diff] [blame] | 1024 | u16 cnt = 0; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1025 | |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 1026 | while (!READ_ONCE(sess->logout_completed)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1027 | if (!traced) { |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame^] | 1028 | ql_dbg(ql_dbg_disc, vha, 0xf086, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1029 | "%s: waiting for sess %p logout\n", |
| 1030 | __func__, sess); |
| 1031 | traced = true; |
| 1032 | } |
| 1033 | msleep(100); |
Quinn Tran | c3b6a1d | 2019-09-12 11:09:06 -0700 | [diff] [blame] | 1034 | cnt++; |
| 1035 | if (cnt > 200) |
| 1036 | break; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1037 | } |
| 1038 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1039 | ql_dbg(ql_dbg_disc, vha, 0xf087, |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1040 | "%s: sess %p logout completed\n", __func__, sess); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | if (sess->logo_ack_needed) { |
| 1044 | sess->logo_ack_needed = 0; |
| 1045 | qla24xx_async_notify_ack(vha, sess, |
| 1046 | (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1047 | } |
| 1048 | |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame^] | 1049 | spin_lock_irqsave(&vha->work_lock, flags); |
| 1050 | sess->flags &= ~FCF_ASYNC_SENT; |
| 1051 | spin_unlock_irqrestore(&vha->work_lock, flags); |
| 1052 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1053 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1054 | if (sess->se_sess) { |
| 1055 | sess->se_sess = NULL; |
| 1056 | if (tgt && !IS_SW_RESV_ADDR(sess->d_id)) |
| 1057 | tgt->sess_count--; |
| 1058 | } |
| 1059 | |
Shyam Sundar | 27258a5 | 2019-12-17 14:06:06 -0800 | [diff] [blame] | 1060 | qla2x00_set_fcport_disc_state(sess, DSC_DELETED); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1061 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1062 | sess->deleted = QLA_SESS_DELETED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1063 | |
| 1064 | if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) { |
| 1065 | vha->fcport_count--; |
| 1066 | sess->login_succ = 0; |
| 1067 | } |
| 1068 | |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 1069 | qla2x00_clear_loop_id(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1070 | |
| 1071 | if (sess->conflict) { |
| 1072 | sess->conflict->login_pause = 0; |
| 1073 | sess->conflict = NULL; |
| 1074 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 1075 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1076 | } |
| 1077 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1078 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1079 | struct qlt_plogi_ack_t *con = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1080 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1081 | struct imm_ntfy_from_isp *iocb; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 1082 | |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 1083 | own = sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1084 | |
| 1085 | if (con) { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1086 | iocb = &con->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1087 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1088 | "se_sess %p / sess %p port %8phC is gone," |
| 1089 | " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n", |
| 1090 | sess->se_sess, sess, sess->port_name, |
| 1091 | own ? "releasing own PLOGI" : "no own PLOGI pending", |
| 1092 | own ? own->ref_count : -1, |
| 1093 | iocb->u.isp24.port_name, con->ref_count); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1094 | qlt_plogi_ack_unref(vha, con); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1095 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1096 | } else { |
| 1097 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a, |
| 1098 | "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n", |
| 1099 | sess->se_sess, sess, sess->port_name, |
| 1100 | own ? "releasing own PLOGI" : |
| 1101 | "no own PLOGI pending", |
| 1102 | own ? own->ref_count : -1); |
| 1103 | } |
| 1104 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1105 | if (own) { |
| 1106 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1107 | qlt_plogi_ack_unref(vha, own); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1108 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 1109 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1110 | } |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1111 | |
Quinn Tran | 86196a8 | 2019-11-25 19:56:51 +0300 | [diff] [blame] | 1112 | sess->explicit_logout = 0; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1113 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 1114 | sess->free_pending = 0; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1115 | |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame^] | 1116 | ql_dbg(ql_dbg_disc, vha, 0xf001, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1117 | "Unregistration of sess %p %8phC finished fcp_cnt %d\n", |
| 1118 | sess, sess->port_name, vha->fcport_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1119 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1120 | if (tgt && (tgt->sess_count == 0)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1121 | wake_up_all(&tgt->waitQ); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1122 | |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 1123 | if (!test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags) && |
Quinn Tran | f5187b7 | 2019-09-12 11:09:08 -0700 | [diff] [blame] | 1124 | !(vha->vp_idx && test_bit(VPORT_DELETE, &vha->dpc_flags)) && |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 1125 | (!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1126 | switch (vha->host->active_mode) { |
| 1127 | case MODE_INITIATOR: |
| 1128 | case MODE_DUAL: |
| 1129 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1130 | qla2xxx_wake_dpc(vha); |
| 1131 | break; |
| 1132 | case MODE_TARGET: |
| 1133 | default: |
| 1134 | /* no-op */ |
| 1135 | break; |
| 1136 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1137 | } |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 1138 | |
| 1139 | if (vha->fcport_count == 0) |
| 1140 | wake_up_all(&vha->fcport_waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1141 | } |
| 1142 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1143 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1144 | void qlt_unreg_sess(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1145 | { |
| 1146 | struct scsi_qla_host *vha = sess->vha; |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1147 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1148 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1149 | ql_dbg(ql_dbg_disc, sess->vha, 0x210a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1150 | "%s sess %p for deletion %8phC\n", |
| 1151 | __func__, sess, sess->port_name); |
| 1152 | |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1153 | spin_lock_irqsave(&sess->vha->work_lock, flags); |
| 1154 | if (sess->free_pending) { |
| 1155 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
| 1156 | return; |
| 1157 | } |
| 1158 | sess->free_pending = 1; |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame^] | 1159 | /* |
| 1160 | * Use FCF_ASYNC_SENT flag to block other cmds used in sess |
| 1161 | * management from being sent. |
| 1162 | */ |
| 1163 | sess->flags |= FCF_ASYNC_SENT; |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1164 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
| 1165 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 1166 | if (sess->se_sess) |
| 1167 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1168 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1169 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Shyam Sundar | 27258a5 | 2019-12-17 14:06:06 -0800 | [diff] [blame] | 1170 | qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1171 | sess->last_rscn_gen = sess->rscn_gen; |
| 1172 | sess->last_login_gen = sess->login_gen; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1173 | |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 1174 | queue_work(sess->vha->hw->wq, &sess->free_work); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1175 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1176 | EXPORT_SYMBOL(qlt_unreg_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1177 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1178 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) |
| 1179 | { |
| 1180 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1181 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1182 | uint16_t loop_id; |
| 1183 | int res = 0; |
| 1184 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1185 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1186 | |
| 1187 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); |
| 1188 | if (loop_id == 0xFFFF) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1189 | /* Global event */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1190 | atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1191 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1192 | qlt_clear_tgt_db(vha->vha_tgt.qla_tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1193 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1194 | } else { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1195 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1196 | 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] | 1197 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | ql_dbg(ql_dbg_tgt, vha, 0xe000, |
| 1201 | "Using sess for qla_tgt_reset: %p\n", sess); |
| 1202 | if (!sess) { |
| 1203 | res = -ESRCH; |
| 1204 | return res; |
| 1205 | } |
| 1206 | |
| 1207 | ql_dbg(ql_dbg_tgt, vha, 0xe047, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1208 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
| 1209 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1210 | mcmd, loop_id); |
| 1211 | |
Quinn Tran | bb1181c | 2016-12-23 18:06:05 -0800 | [diff] [blame] | 1212 | 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] | 1213 | } |
| 1214 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1215 | static void qla24xx_chk_fcp_state(struct fc_port *sess) |
| 1216 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 1217 | if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1218 | sess->logout_on_delete = 0; |
| 1219 | sess->logo_ack_needed = 0; |
| 1220 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1221 | } |
| 1222 | } |
| 1223 | |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1224 | void qlt_schedule_sess_for_deletion(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1225 | { |
| 1226 | struct qla_tgt *tgt = sess->tgt; |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1227 | unsigned long flags; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1228 | u16 sec; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1229 | |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1230 | switch (sess->disc_state) { |
| 1231 | case DSC_DELETE_PEND: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1232 | return; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1233 | case DSC_DELETED: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1234 | if (tgt && tgt->tgt_stop && (tgt->sess_count == 0)) |
| 1235 | wake_up_all(&tgt->waitQ); |
| 1236 | if (sess->vha->fcport_count == 0) |
| 1237 | wake_up_all(&sess->vha->fcport_waitQ); |
| 1238 | |
| 1239 | if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] && |
| 1240 | !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1241 | return; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1242 | break; |
| 1243 | case DSC_UPD_FCPORT: |
| 1244 | /* |
| 1245 | * This port is not done reporting to upper layer. |
| 1246 | * let it finish |
| 1247 | */ |
| 1248 | sess->next_disc_state = DSC_DELETE_PEND; |
| 1249 | sec = jiffies_to_msecs(jiffies - |
| 1250 | sess->jiffies_at_registration)/1000; |
| 1251 | if (sess->sec_since_registration < sec && sec && !(sec % 5)) { |
| 1252 | sess->sec_since_registration = sec; |
| 1253 | ql_dbg(ql_dbg_disc, sess->vha, 0xffff, |
| 1254 | "%s %8phC : Slow Rport registration(%d Sec)\n", |
| 1255 | __func__, sess->port_name, sec); |
| 1256 | } |
| 1257 | return; |
| 1258 | default: |
| 1259 | break; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1260 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1261 | |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1262 | spin_lock_irqsave(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1263 | if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1264 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1265 | return; |
| 1266 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1267 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1268 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1269 | |
Quinn Tran | 8aaac2d | 2019-12-17 14:06:11 -0800 | [diff] [blame] | 1270 | sess->prli_pend_timer = 0; |
Shyam Sundar | 27258a5 | 2019-12-17 14:06:06 -0800 | [diff] [blame] | 1271 | qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1272 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1273 | qla24xx_chk_fcp_state(sess); |
| 1274 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1275 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, |
Quinn Tran | 5c64005 | 2018-09-26 22:05:14 -0700 | [diff] [blame] | 1276 | "Scheduling sess %p for deletion %8phC\n", |
| 1277 | sess, sess->port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1278 | |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1279 | WARN_ON(!queue_work(sess->vha->hw->wq, &sess->del_work)); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1280 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1281 | |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1282 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1283 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1284 | struct fc_port *sess; |
| 1285 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1286 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1287 | list_for_each_entry(sess, &vha->vp_fcports, list) { |
| 1288 | if (sess->se_sess) |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1289 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1290 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1291 | |
| 1292 | /* At this point tgt could be already dead */ |
| 1293 | } |
| 1294 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1295 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, be_id_t s_id, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1296 | uint16_t *loop_id) |
| 1297 | { |
| 1298 | struct qla_hw_data *ha = vha->hw; |
| 1299 | dma_addr_t gid_list_dma; |
Bart Van Assche | 9c17c3b | 2019-08-08 20:01:35 -0700 | [diff] [blame] | 1300 | struct gid_list_info *gid_list, *gid; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1301 | int res, rc, i; |
| 1302 | uint16_t entries; |
| 1303 | |
| 1304 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1305 | &gid_list_dma, GFP_KERNEL); |
| 1306 | if (!gid_list) { |
| 1307 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, |
| 1308 | "qla_target(%d): DMA Alloc failed of %u\n", |
| 1309 | vha->vp_idx, qla2x00_gid_list_size(ha)); |
| 1310 | return -ENOMEM; |
| 1311 | } |
| 1312 | |
| 1313 | /* Get list of logged in devices */ |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1314 | rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1315 | if (rc != QLA_SUCCESS) { |
| 1316 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, |
| 1317 | "qla_target(%d): get_id_list() failed: %x\n", |
| 1318 | vha->vp_idx, rc); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1319 | res = -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1320 | goto out_free_id_list; |
| 1321 | } |
| 1322 | |
Bart Van Assche | 9c17c3b | 2019-08-08 20:01:35 -0700 | [diff] [blame] | 1323 | gid = gid_list; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1324 | res = -ENOENT; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1325 | for (i = 0; i < entries; i++) { |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1326 | if (gid->al_pa == s_id.al_pa && |
| 1327 | gid->area == s_id.area && |
| 1328 | gid->domain == s_id.domain) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1329 | *loop_id = le16_to_cpu(gid->loop_id); |
| 1330 | res = 0; |
| 1331 | break; |
| 1332 | } |
Bart Van Assche | 9c17c3b | 2019-08-08 20:01:35 -0700 | [diff] [blame] | 1333 | gid = (void *)gid + ha->gid_list_info_size; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | out_free_id_list: |
| 1337 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1338 | gid_list, gid_list_dma); |
| 1339 | return res; |
| 1340 | } |
| 1341 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1342 | /* |
| 1343 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. |
| 1344 | * Caller must put it. |
| 1345 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1346 | static struct fc_port *qlt_create_sess( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1347 | struct scsi_qla_host *vha, |
| 1348 | fc_port_t *fcport, |
| 1349 | bool local) |
| 1350 | { |
| 1351 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1352 | struct fc_port *sess = fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1353 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1354 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1355 | if (vha->vha_tgt.qla_tgt->tgt_stop) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1356 | return NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1357 | |
| 1358 | if (fcport->se_sess) { |
| 1359 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1360 | ql_dbg(ql_dbg_disc, vha, 0x20f6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1361 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1362 | __func__, sess->port_name); |
| 1363 | return NULL; |
| 1364 | } |
| 1365 | return fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1366 | } |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1367 | sess->tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1368 | sess->local = local; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1369 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1370 | /* |
| 1371 | * Under normal circumstances we want to logout from firmware when |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1372 | * session eventually ends and release corresponding nport handle. |
| 1373 | * In the exception cases (e.g. when new PLOGI is waiting) corresponding |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1374 | * code will adjust these flags as necessary. |
| 1375 | */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1376 | sess->logout_on_delete = 1; |
| 1377 | sess->keep_nport_handle = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1378 | sess->logout_completed = 0; |
| 1379 | |
| 1380 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 1381 | &fcport->port_name[0], sess) < 0) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1382 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1383 | "(%d) %8phC check_initiator_node_acl failed\n", |
| 1384 | vha->vp_idx, fcport->port_name); |
| 1385 | return NULL; |
| 1386 | } else { |
| 1387 | kref_init(&fcport->sess_kref); |
| 1388 | /* |
| 1389 | * Take an extra reference to ->sess_kref here to handle |
| 1390 | * fc_port access across ->tgt.sess_lock reaquire. |
| 1391 | */ |
| 1392 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1393 | ql_dbg(ql_dbg_disc, vha, 0x20f7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1394 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1395 | __func__, sess->port_name); |
| 1396 | return NULL; |
| 1397 | } |
| 1398 | |
| 1399 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1400 | if (!IS_SW_RESV_ADDR(sess->d_id)) |
| 1401 | vha->vha_tgt.qla_tgt->sess_count++; |
| 1402 | |
| 1403 | qlt_do_generation_tick(vha, &sess->generation); |
| 1404 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1405 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1406 | |
| 1407 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1408 | "Adding sess %p se_sess %p to tgt %p sess_count %d\n", |
| 1409 | sess, sess->se_sess, vha->vha_tgt.qla_tgt, |
| 1410 | vha->vha_tgt.qla_tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1411 | |
| 1412 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1413 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
| 1414 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", |
| 1415 | vha->vp_idx, local ? "local " : "", fcport->port_name, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 1416 | fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area, |
| 1417 | sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1418 | |
| 1419 | return sess; |
| 1420 | } |
| 1421 | |
| 1422 | /* |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1423 | * max_gen - specifies maximum session generation |
| 1424 | * at which this deletion requestion is still valid |
| 1425 | */ |
| 1426 | void |
| 1427 | 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] | 1428 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1429 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1430 | struct fc_port *sess = fcport; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1431 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1432 | |
| 1433 | if (!vha->hw->tgt.tgt_ops) |
| 1434 | return; |
| 1435 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1436 | if (!tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1437 | return; |
| 1438 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1439 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1440 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1441 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1442 | return; |
| 1443 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1444 | if (!sess->se_sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1445 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1446 | return; |
| 1447 | } |
| 1448 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1449 | if (max_gen - sess->generation < 0) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1450 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1451 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092, |
| 1452 | "Ignoring stale deletion request for se_sess %p / sess %p" |
| 1453 | " for port %8phC, req_gen %d, sess_gen %d\n", |
| 1454 | sess->se_sess, sess, sess->port_name, max_gen, |
| 1455 | sess->generation); |
| 1456 | return; |
| 1457 | } |
| 1458 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1459 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); |
| 1460 | |
| 1461 | sess->local = 1; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1462 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1463 | qlt_schedule_sess_for_deletion(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) |
| 1467 | { |
| 1468 | struct qla_hw_data *ha = tgt->ha; |
| 1469 | unsigned long flags; |
| 1470 | int res; |
| 1471 | /* |
| 1472 | * We need to protect against race, when tgt is freed before or |
| 1473 | * inside wake_up() |
| 1474 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1475 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1476 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1477 | "tgt %p, sess_count=%d\n", |
| 1478 | tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1479 | res = (tgt->sess_count == 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1480 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1481 | |
| 1482 | return res; |
| 1483 | } |
| 1484 | |
| 1485 | /* Called by tcm_qla2xxx configfs code */ |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1486 | int qlt_stop_phase1(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1487 | { |
| 1488 | struct scsi_qla_host *vha = tgt->vha; |
| 1489 | struct qla_hw_data *ha = tgt->ha; |
| 1490 | unsigned long flags; |
| 1491 | |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1492 | mutex_lock(&ha->optrom_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1493 | mutex_lock(&qla_tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1494 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1495 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
| 1496 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, |
| 1497 | "Already in tgt->tgt_stop or tgt_stopped state\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1498 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1499 | mutex_unlock(&ha->optrom_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1500 | return -EPERM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1501 | } |
| 1502 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1503 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xe003, "Stopping target for host %ld(%p)\n", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1504 | vha->host_no, vha); |
| 1505 | /* |
| 1506 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. |
| 1507 | * Lock is needed, because we still can get an incoming packet. |
| 1508 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1509 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1510 | tgt->tgt_stop = 1; |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1511 | qlt_clear_tgt_db(tgt); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1512 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1513 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1514 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1515 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, |
| 1516 | "Waiting for sess works (tgt %p)", tgt); |
| 1517 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1518 | while (!list_empty(&tgt->sess_works_list)) { |
| 1519 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1520 | flush_scheduled_work(); |
| 1521 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1522 | } |
| 1523 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1524 | |
| 1525 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1526 | "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1527 | |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1528 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1529 | |
| 1530 | /* Big hammer */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1531 | if (!ha->flags.host_shutting_down && |
| 1532 | (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1533 | qlt_disable_vha(vha); |
| 1534 | |
| 1535 | /* Wait for sessions to clear out (just in case) */ |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1536 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1537 | mutex_unlock(&ha->optrom_mutex); |
| 1538 | |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1539 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1540 | } |
| 1541 | EXPORT_SYMBOL(qlt_stop_phase1); |
| 1542 | |
| 1543 | /* Called by tcm_qla2xxx configfs code */ |
| 1544 | void qlt_stop_phase2(struct qla_tgt *tgt) |
| 1545 | { |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1546 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1547 | |
| 1548 | if (tgt->tgt_stopped) { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1549 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1550 | "Already in tgt->tgt_stopped state\n"); |
| 1551 | dump_stack(); |
| 1552 | return; |
| 1553 | } |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1554 | if (!tgt->tgt_stop) { |
| 1555 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
| 1556 | "%s: phase1 stop is not completed\n", __func__); |
| 1557 | dump_stack(); |
| 1558 | return; |
| 1559 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1560 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1561 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1562 | tgt->tgt_stop = 0; |
| 1563 | tgt->tgt_stopped = 1; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1564 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1565 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1566 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00c, "Stop of tgt %p finished\n", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1567 | tgt); |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 1568 | |
| 1569 | switch (vha->qlini_mode) { |
| 1570 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 1571 | vha->flags.online = 1; |
| 1572 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 1573 | break; |
| 1574 | default: |
| 1575 | break; |
| 1576 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1577 | } |
| 1578 | EXPORT_SYMBOL(qlt_stop_phase2); |
| 1579 | |
| 1580 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1581 | static void qlt_release(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1582 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1583 | scsi_qla_host_t *vha = tgt->vha; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1584 | void *node; |
| 1585 | u64 key = 0; |
| 1586 | u16 i; |
| 1587 | struct qla_qpair_hint *h; |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1588 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1589 | |
Bart Van Assche | 8b21900 | 2019-08-08 20:01:38 -0700 | [diff] [blame] | 1590 | if (!tgt->tgt_stop && !tgt->tgt_stopped) |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1591 | qlt_stop_phase1(tgt); |
| 1592 | |
Bart Van Assche | 8b21900 | 2019-08-08 20:01:38 -0700 | [diff] [blame] | 1593 | if (!tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1594 | qlt_stop_phase2(tgt); |
| 1595 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1596 | for (i = 0; i < vha->hw->max_qpairs + 1; i++) { |
| 1597 | unsigned long flags; |
| 1598 | |
| 1599 | h = &tgt->qphints[i]; |
| 1600 | if (h->qpair) { |
| 1601 | spin_lock_irqsave(h->qpair->qp_lock_ptr, flags); |
| 1602 | list_del(&h->hint_elem); |
| 1603 | spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags); |
| 1604 | h->qpair = NULL; |
| 1605 | } |
| 1606 | } |
| 1607 | kfree(tgt->qphints); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1608 | mutex_lock(&qla_tgt_mutex); |
| 1609 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
| 1610 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1611 | |
| 1612 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 1613 | btree_remove64(&tgt->lun_qpair_map, key); |
| 1614 | |
| 1615 | btree_destroy64(&tgt->lun_qpair_map); |
| 1616 | |
Sawan Chandak | 3be63b1e | 2017-12-04 14:45:04 -0800 | [diff] [blame] | 1617 | if (vha->vp_idx) |
| 1618 | if (ha->tgt.tgt_ops && |
| 1619 | ha->tgt.tgt_ops->remove_target && |
| 1620 | vha->vha_tgt.target_lport_ptr) |
| 1621 | ha->tgt.tgt_ops->remove_target(vha); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1622 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1623 | vha->vha_tgt.qla_tgt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1624 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1625 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1626 | "Release of tgt %p finished\n", tgt); |
| 1627 | |
| 1628 | kfree(tgt); |
| 1629 | } |
| 1630 | |
| 1631 | /* ha->hardware_lock supposed to be held on entry */ |
| 1632 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, |
| 1633 | const void *param, unsigned int param_size) |
| 1634 | { |
| 1635 | struct qla_tgt_sess_work_param *prm; |
| 1636 | unsigned long flags; |
| 1637 | |
| 1638 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); |
| 1639 | if (!prm) { |
| 1640 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, |
| 1641 | "qla_target(%d): Unable to create session " |
| 1642 | "work, command will be refused", 0); |
| 1643 | return -ENOMEM; |
| 1644 | } |
| 1645 | |
| 1646 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, |
| 1647 | "Scheduling work (type %d, prm %p)" |
| 1648 | " to find session for param %p (size %d, tgt %p)\n", |
| 1649 | type, prm, param, param_size, tgt); |
| 1650 | |
| 1651 | prm->type = type; |
| 1652 | memcpy(&prm->tm_iocb, param, param_size); |
| 1653 | |
| 1654 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1655 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); |
| 1656 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1657 | |
| 1658 | schedule_work(&tgt->sess_work); |
| 1659 | |
| 1660 | return 0; |
| 1661 | } |
| 1662 | |
| 1663 | /* |
| 1664 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1665 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1666 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1667 | struct imm_ntfy_from_isp *ntfy, |
| 1668 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 1669 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) |
| 1670 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1671 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1672 | struct qla_hw_data *ha = vha->hw; |
| 1673 | request_t *pkt; |
| 1674 | struct nack_to_isp *nack; |
| 1675 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 1676 | if (!ha->flags.fw_started) |
| 1677 | return; |
| 1678 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1679 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); |
| 1680 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1681 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1682 | if (!pkt) { |
| 1683 | ql_dbg(ql_dbg_tgt, vha, 0xe049, |
| 1684 | "qla_target(%d): %s failed: unable to allocate " |
| 1685 | "request packet\n", vha->vp_idx, __func__); |
| 1686 | return; |
| 1687 | } |
| 1688 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1689 | if (vha->vha_tgt.qla_tgt != NULL) |
| 1690 | vha->vha_tgt.qla_tgt->notify_ack_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1691 | |
| 1692 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 1693 | pkt->entry_count = 1; |
| 1694 | |
| 1695 | nack = (struct nack_to_isp *)pkt; |
| 1696 | nack->ox_id = ntfy->ox_id; |
| 1697 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1698 | nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1699 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 1700 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 1701 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1702 | cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1703 | } |
| 1704 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 1705 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 1706 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1707 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1708 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 1709 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 1710 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 1711 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); |
| 1712 | nack->u.isp24.srr_reject_code = srr_reject_code; |
| 1713 | nack->u.isp24.srr_reject_code_expl = srr_explan; |
| 1714 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 1715 | |
| 1716 | ql_dbg(ql_dbg_tgt, vha, 0xe005, |
| 1717 | "qla_target(%d): Sending 24xx Notify Ack %d\n", |
| 1718 | vha->vp_idx, nack->u.isp24.status); |
| 1719 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1720 | /* Memory Barrier */ |
| 1721 | wmb(); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1722 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1723 | } |
| 1724 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1725 | static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd) |
| 1726 | { |
| 1727 | struct scsi_qla_host *vha = mcmd->vha; |
| 1728 | struct qla_hw_data *ha = vha->hw; |
| 1729 | struct abts_resp_to_24xx *resp; |
| 1730 | uint32_t f_ctl, h; |
| 1731 | uint8_t *p; |
| 1732 | int rc; |
| 1733 | struct abts_recv_from_24xx *abts = &mcmd->orig_iocb.abts; |
| 1734 | struct qla_qpair *qpair = mcmd->qpair; |
| 1735 | |
| 1736 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1737 | "Sending task mgmt ABTS response (ha=%p, status=%x)\n", |
| 1738 | ha, mcmd->fc_tm_rsp); |
| 1739 | |
| 1740 | rc = qlt_check_reserve_free_req(qpair, 1); |
| 1741 | if (rc) { |
| 1742 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1743 | "qla_target(%d): %s failed: unable to allocate request packet\n", |
| 1744 | vha->vp_idx, __func__); |
| 1745 | return -EAGAIN; |
| 1746 | } |
| 1747 | |
| 1748 | resp = (struct abts_resp_to_24xx *)qpair->req->ring_ptr; |
| 1749 | memset(resp, 0, sizeof(*resp)); |
| 1750 | |
| 1751 | h = qlt_make_handle(qpair); |
| 1752 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 1753 | /* |
| 1754 | * CTIO type 7 from the firmware doesn't provide a way to |
| 1755 | * know the initiator's LOOP ID, hence we can't find |
| 1756 | * the session and, so, the command. |
| 1757 | */ |
| 1758 | return -EAGAIN; |
| 1759 | } else { |
| 1760 | qpair->req->outstanding_cmds[h] = (srb_t *)mcmd; |
| 1761 | } |
| 1762 | |
| 1763 | resp->handle = MAKE_HANDLE(qpair->req->id, h); |
| 1764 | resp->entry_type = ABTS_RESP_24XX; |
| 1765 | resp->entry_count = 1; |
| 1766 | resp->nport_handle = abts->nport_handle; |
| 1767 | resp->vp_index = vha->vp_idx; |
| 1768 | resp->sof_type = abts->sof_type; |
| 1769 | resp->exchange_address = abts->exchange_address; |
| 1770 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
| 1771 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
| 1772 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1773 | F_CTL_SEQ_INITIATIVE); |
| 1774 | p = (uint8_t *)&f_ctl; |
| 1775 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1776 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1777 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1778 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1779 | resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id; |
| 1780 | resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1781 | |
| 1782 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1783 | if (mcmd->fc_tm_rsp == FCP_TMF_CMPL) { |
| 1784 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1785 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1786 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1787 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1788 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1789 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1790 | } else { |
| 1791 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1792 | resp->payload.ba_rjt.reason_code = |
| 1793 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1794 | /* Other bytes are zero */ |
| 1795 | } |
| 1796 | |
| 1797 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
| 1798 | |
| 1799 | /* Memory Barrier */ |
| 1800 | wmb(); |
| 1801 | if (qpair->reqq_start_iocbs) |
| 1802 | qpair->reqq_start_iocbs(qpair); |
| 1803 | else |
| 1804 | qla2x00_start_iocbs(vha, qpair->req); |
| 1805 | |
| 1806 | return rc; |
| 1807 | } |
| 1808 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1809 | /* |
| 1810 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1811 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1812 | static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1813 | struct abts_recv_from_24xx *abts, uint32_t status, |
| 1814 | bool ids_reversed) |
| 1815 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1816 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1817 | struct qla_hw_data *ha = vha->hw; |
| 1818 | struct abts_resp_to_24xx *resp; |
| 1819 | uint32_t f_ctl; |
| 1820 | uint8_t *p; |
| 1821 | |
| 1822 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1823 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", |
| 1824 | ha, abts, status); |
| 1825 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1826 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, |
| 1827 | NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1828 | if (!resp) { |
| 1829 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1830 | "qla_target(%d): %s failed: unable to allocate " |
| 1831 | "request packet", vha->vp_idx, __func__); |
| 1832 | return; |
| 1833 | } |
| 1834 | |
| 1835 | resp->entry_type = ABTS_RESP_24XX; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1836 | resp->handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1837 | resp->entry_count = 1; |
| 1838 | resp->nport_handle = abts->nport_handle; |
| 1839 | resp->vp_index = vha->vp_idx; |
| 1840 | resp->sof_type = abts->sof_type; |
| 1841 | resp->exchange_address = abts->exchange_address; |
| 1842 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1843 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1844 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1845 | F_CTL_SEQ_INITIATIVE); |
| 1846 | p = (uint8_t *)&f_ctl; |
| 1847 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1848 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1849 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1850 | if (ids_reversed) { |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1851 | resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.d_id; |
| 1852 | resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.s_id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1853 | } else { |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1854 | resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id; |
| 1855 | resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1856 | } |
| 1857 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1858 | if (status == FCP_TMF_CMPL) { |
| 1859 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1860 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1861 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1862 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1863 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1864 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1865 | } else { |
| 1866 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1867 | resp->payload.ba_rjt.reason_code = |
| 1868 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1869 | /* Other bytes are zero */ |
| 1870 | } |
| 1871 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1872 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1873 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1874 | /* Memory Barrier */ |
| 1875 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 1876 | if (qpair->reqq_start_iocbs) |
| 1877 | qpair->reqq_start_iocbs(qpair); |
| 1878 | else |
| 1879 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | /* |
| 1883 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1884 | */ |
| 1885 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1886 | struct qla_qpair *qpair, response_t *pkt, struct qla_tgt_mgmt_cmd *mcmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1887 | { |
| 1888 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1889 | u16 tmp; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1890 | struct abts_recv_from_24xx *entry; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1891 | |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1892 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1893 | if (ctio == NULL) { |
| 1894 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, |
| 1895 | "qla_target(%d): %s failed: unable to allocate " |
| 1896 | "request packet\n", vha->vp_idx, __func__); |
| 1897 | return; |
| 1898 | } |
| 1899 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1900 | if (mcmd) |
| 1901 | /* abts from remote port */ |
| 1902 | entry = &mcmd->orig_iocb.abts; |
| 1903 | else |
| 1904 | /* abts from this driver. */ |
| 1905 | entry = (struct abts_recv_from_24xx *)pkt; |
| 1906 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1907 | /* |
| 1908 | * We've got on entrance firmware's response on by us generated |
| 1909 | * ABTS response. So, in it ID fields are reversed. |
| 1910 | */ |
| 1911 | |
| 1912 | ctio->entry_type = CTIO_TYPE7; |
| 1913 | ctio->entry_count = 1; |
| 1914 | ctio->nport_handle = entry->nport_handle; |
| 1915 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1916 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1917 | ctio->vp_index = vha->vp_idx; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1918 | ctio->exchange_addr = entry->exchange_addr_to_abort; |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1919 | tmp = (CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1920 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1921 | if (mcmd) { |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1922 | ctio->initiator_id = entry->fcp_hdr_le.s_id; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1923 | |
| 1924 | if (mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) |
| 1925 | tmp |= (mcmd->abort_io_attr << 9); |
| 1926 | else if (qpair->retry_term_cnt & 1) |
| 1927 | tmp |= (0x4 << 9); |
| 1928 | } else { |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1929 | ctio->initiator_id = entry->fcp_hdr_le.d_id; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1930 | |
| 1931 | if (qpair->retry_term_cnt & 1) |
| 1932 | tmp |= (0x4 << 9); |
| 1933 | } |
| 1934 | ctio->u.status1.flags = cpu_to_le16(tmp); |
| 1935 | ctio->u.status1.ox_id = entry->fcp_hdr_le.ox_id; |
| 1936 | |
| 1937 | ql_dbg(ql_dbg_tgt, vha, 0xe007, |
| 1938 | "Sending retry TERM EXCH CTIO7 flags %04xh oxid %04xh attr valid %x\n", |
| 1939 | le16_to_cpu(ctio->u.status1.flags), |
| 1940 | le16_to_cpu(ctio->u.status1.ox_id), |
| 1941 | (mcmd && mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) ? 1 : 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1942 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1943 | /* Memory Barrier */ |
| 1944 | wmb(); |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1945 | if (qpair->reqq_start_iocbs) |
| 1946 | qpair->reqq_start_iocbs(qpair); |
| 1947 | else |
| 1948 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1949 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1950 | if (mcmd) |
| 1951 | qlt_build_abts_resp_iocb(mcmd); |
| 1952 | else |
| 1953 | qlt_24xx_send_abts_resp(qpair, |
| 1954 | (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1955 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | /* drop cmds for the given lun |
| 1959 | * XXX only looks for cmds on the port through which lun reset was recieved |
| 1960 | * XXX does not go through the list of other port (which may have cmds |
| 1961 | * for the same lun) |
| 1962 | */ |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1963 | static void abort_cmds_for_lun(struct scsi_qla_host *vha, u64 lun, be_id_t s_id) |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1964 | { |
| 1965 | struct qla_tgt_sess_op *op; |
| 1966 | struct qla_tgt_cmd *cmd; |
| 1967 | uint32_t key; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1968 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1969 | |
| 1970 | key = sid_to_key(s_id); |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1971 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1972 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1973 | uint32_t op_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1974 | u64 op_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1975 | |
| 1976 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1977 | op_lun = scsilun_to_int( |
| 1978 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1979 | if (op_key == key && op_lun == lun) |
| 1980 | op->aborted = true; |
| 1981 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1982 | |
| 1983 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1984 | uint32_t op_key; |
| 1985 | u64 op_lun; |
| 1986 | |
| 1987 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1988 | op_lun = scsilun_to_int( |
| 1989 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1990 | if (op_key == key && op_lun == lun) |
| 1991 | op->aborted = true; |
| 1992 | } |
| 1993 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1994 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1995 | uint32_t cmd_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1996 | u64 cmd_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1997 | |
| 1998 | cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 1999 | cmd_lun = scsilun_to_int( |
| 2000 | (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); |
| 2001 | if (cmd_key == key && cmd_lun == lun) |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 2002 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2003 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 2004 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2005 | } |
| 2006 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2007 | static struct qla_qpair_hint *qlt_find_qphint(struct scsi_qla_host *vha, |
| 2008 | uint64_t unpacked_lun) |
| 2009 | { |
| 2010 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 2011 | struct qla_qpair_hint *h = NULL; |
| 2012 | |
| 2013 | if (vha->flags.qpairs_available) { |
| 2014 | h = btree_lookup64(&tgt->lun_qpair_map, unpacked_lun); |
| 2015 | if (!h) |
| 2016 | h = &tgt->qphints[0]; |
| 2017 | } else { |
| 2018 | h = &tgt->qphints[0]; |
| 2019 | } |
| 2020 | |
| 2021 | return h; |
| 2022 | } |
| 2023 | |
| 2024 | static void qlt_do_tmr_work(struct work_struct *work) |
| 2025 | { |
| 2026 | struct qla_tgt_mgmt_cmd *mcmd = |
| 2027 | container_of(work, struct qla_tgt_mgmt_cmd, work); |
| 2028 | struct qla_hw_data *ha = mcmd->vha->hw; |
| 2029 | int rc = EIO; |
| 2030 | uint32_t tag; |
| 2031 | unsigned long flags; |
| 2032 | |
| 2033 | switch (mcmd->tmr_func) { |
| 2034 | case QLA_TGT_ABTS: |
| 2035 | tag = mcmd->orig_iocb.abts.exchange_addr_to_abort; |
| 2036 | break; |
| 2037 | default: |
| 2038 | tag = 0; |
| 2039 | break; |
| 2040 | } |
| 2041 | |
| 2042 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, mcmd->unpacked_lun, |
| 2043 | mcmd->tmr_func, tag); |
| 2044 | |
| 2045 | if (rc != 0) { |
| 2046 | spin_lock_irqsave(mcmd->qpair->qp_lock_ptr, flags); |
| 2047 | switch (mcmd->tmr_func) { |
| 2048 | case QLA_TGT_ABTS: |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2049 | mcmd->fc_tm_rsp = FCP_TMF_REJECTED; |
| 2050 | qlt_build_abts_resp_iocb(mcmd); |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2051 | break; |
| 2052 | case QLA_TGT_LUN_RESET: |
| 2053 | case QLA_TGT_CLEAR_TS: |
| 2054 | case QLA_TGT_ABORT_TS: |
| 2055 | case QLA_TGT_CLEAR_ACA: |
| 2056 | case QLA_TGT_TARGET_RESET: |
| 2057 | qlt_send_busy(mcmd->qpair, &mcmd->orig_iocb.atio, |
| 2058 | qla_sam_status); |
| 2059 | break; |
| 2060 | |
| 2061 | case QLA_TGT_ABORT_ALL: |
| 2062 | case QLA_TGT_NEXUS_LOSS_SESS: |
| 2063 | case QLA_TGT_NEXUS_LOSS: |
| 2064 | qlt_send_notify_ack(mcmd->qpair, |
| 2065 | &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); |
| 2066 | break; |
| 2067 | } |
| 2068 | spin_unlock_irqrestore(mcmd->qpair->qp_lock_ptr, flags); |
| 2069 | |
| 2070 | ql_dbg(ql_dbg_tgt_mgt, mcmd->vha, 0xf052, |
| 2071 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 2072 | mcmd->vha->vp_idx, rc); |
| 2073 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2074 | } |
| 2075 | } |
| 2076 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2077 | /* ha->hardware_lock supposed to be held on entry */ |
| 2078 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 2079 | struct abts_recv_from_24xx *abts, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2080 | { |
| 2081 | struct qla_hw_data *ha = vha->hw; |
| 2082 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2083 | struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0]; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 2084 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2085 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, |
| 2086 | "qla_target(%d): task abort (tag=%d)\n", |
| 2087 | vha->vp_idx, abts->exchange_addr_to_abort); |
| 2088 | |
| 2089 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 2090 | if (mcmd == NULL) { |
| 2091 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, |
| 2092 | "qla_target(%d): %s: Allocation of ABORT cmd failed", |
| 2093 | vha->vp_idx, __func__); |
| 2094 | return -ENOMEM; |
| 2095 | } |
| 2096 | memset(mcmd, 0, sizeof(*mcmd)); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2097 | mcmd->cmd_type = TYPE_TGT_TMCMD; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2098 | mcmd->sess = sess; |
| 2099 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2100 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 2101 | mcmd->tmr_func = QLA_TGT_ABTS; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2102 | mcmd->qpair = h->qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 2103 | mcmd->vha = vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2104 | |
Nicholas Bellinger | eb5ae23 | 2017-06-03 07:07:21 -0700 | [diff] [blame] | 2105 | /* |
| 2106 | * LUN is looked up by target-core internally based on the passed |
| 2107 | * abts->exchange_addr_to_abort tag. |
| 2108 | */ |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2109 | mcmd->se_cmd.cpuid = h->cpuid; |
| 2110 | |
| 2111 | if (ha->tgt.tgt_ops->find_cmd_by_tag) { |
| 2112 | struct qla_tgt_cmd *abort_cmd; |
| 2113 | |
| 2114 | abort_cmd = ha->tgt.tgt_ops->find_cmd_by_tag(sess, |
| 2115 | abts->exchange_addr_to_abort); |
| 2116 | if (abort_cmd && abort_cmd->qpair) { |
| 2117 | mcmd->qpair = abort_cmd->qpair; |
| 2118 | mcmd->se_cmd.cpuid = abort_cmd->se_cmd.cpuid; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2119 | mcmd->abort_io_attr = abort_cmd->atio.u.isp24.attr; |
| 2120 | mcmd->flags = QLA24XX_MGMT_ABORT_IO_ATTR_VALID; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2121 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2122 | } |
| 2123 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2124 | INIT_WORK(&mcmd->work, qlt_do_tmr_work); |
| 2125 | queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, &mcmd->work); |
| 2126 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2127 | return 0; |
| 2128 | } |
| 2129 | |
| 2130 | /* |
| 2131 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2132 | */ |
| 2133 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 2134 | struct abts_recv_from_24xx *abts) |
| 2135 | { |
| 2136 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 2137 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2138 | uint32_t tag = abts->exchange_addr_to_abort; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2139 | be_id_t s_id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2140 | int rc; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2141 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2142 | |
| 2143 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { |
| 2144 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, |
| 2145 | "qla_target(%d): ABTS: Abort Sequence not " |
| 2146 | "supported\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2147 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2148 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2149 | return; |
| 2150 | } |
| 2151 | |
| 2152 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { |
| 2153 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, |
| 2154 | "qla_target(%d): ABTS: Unknown Exchange " |
| 2155 | "Address received\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2156 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2157 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2158 | return; |
| 2159 | } |
| 2160 | |
| 2161 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, |
| 2162 | "qla_target(%d): task abort (s_id=%x:%x:%x, " |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2163 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id.domain, |
| 2164 | abts->fcp_hdr_le.s_id.area, abts->fcp_hdr_le.s_id.al_pa, tag, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2165 | le32_to_cpu(abts->fcp_hdr_le.parameter)); |
| 2166 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2167 | s_id = le_id_to_be(abts->fcp_hdr_le.s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2168 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2169 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2170 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 2171 | if (!sess) { |
| 2172 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, |
Colin Ian King | 03fea73 | 2018-03-19 10:53:41 +0000 | [diff] [blame] | 2173 | "qla_target(%d): task abort for non-existent session\n", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2174 | vha->vp_idx); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2175 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 2176 | |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [diff] [blame] | 2177 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2178 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2179 | return; |
| 2180 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2181 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 2182 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2183 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2184 | if (sess->deleted) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2185 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2186 | false); |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 2187 | return; |
| 2188 | } |
| 2189 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2190 | rc = __qlt_24xx_handle_abts(vha, abts, sess); |
| 2191 | if (rc != 0) { |
| 2192 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, |
| 2193 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", |
| 2194 | vha->vp_idx, rc); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2195 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2196 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2197 | return; |
| 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | /* |
| 2202 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2203 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2204 | static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2205 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) |
| 2206 | { |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 2207 | struct scsi_qla_host *ha = mcmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2208 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; |
| 2209 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2210 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2211 | |
| 2212 | ql_dbg(ql_dbg_tgt, ha, 0xe008, |
| 2213 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", |
| 2214 | ha, atio, resp_code); |
| 2215 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2216 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2217 | ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2218 | if (ctio == NULL) { |
| 2219 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, |
| 2220 | "qla_target(%d): %s failed: unable to allocate " |
| 2221 | "request packet\n", ha->vp_idx, __func__); |
| 2222 | return; |
| 2223 | } |
| 2224 | |
| 2225 | ctio->entry_type = CTIO_TYPE7; |
| 2226 | ctio->entry_count = 1; |
| 2227 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 2228 | ctio->nport_handle = mcmd->sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2229 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2230 | ctio->vp_index = ha->vp_idx; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2231 | ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2232 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2233 | temp = (atio->u.isp24.attr << 9)| |
| 2234 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2235 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2236 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2237 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2238 | ctio->u.status1.scsi_status = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2239 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); |
| 2240 | ctio->u.status1.response_len = cpu_to_le16(8); |
Roland Dreier | e4b11b8 | 2012-09-18 15:10:56 -0700 | [diff] [blame] | 2241 | ctio->u.status1.sense_data[0] = resp_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2242 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2243 | /* Memory Barrier */ |
| 2244 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2245 | if (qpair->reqq_start_iocbs) |
| 2246 | qpair->reqq_start_iocbs(qpair); |
| 2247 | else |
| 2248 | qla2x00_start_iocbs(ha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) |
| 2252 | { |
| 2253 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2254 | } |
| 2255 | EXPORT_SYMBOL(qlt_free_mcmd); |
| 2256 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2257 | /* |
| 2258 | * ha->hardware_lock supposed to be held on entry. Might drop it, then |
| 2259 | * reacquire |
| 2260 | */ |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2261 | void qlt_send_resp_ctio(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2262 | uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq) |
| 2263 | { |
| 2264 | struct atio_from_isp *atio = &cmd->atio; |
| 2265 | struct ctio7_to_24xx *ctio; |
| 2266 | uint16_t temp; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2267 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2268 | |
| 2269 | ql_dbg(ql_dbg_tgt_dif, vha, 0x3066, |
| 2270 | "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, " |
| 2271 | "sense_key=%02x, asc=%02x, ascq=%02x", |
| 2272 | vha, atio, scsi_status, sense_key, asc, ascq); |
| 2273 | |
| 2274 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL); |
| 2275 | if (!ctio) { |
| 2276 | ql_dbg(ql_dbg_async, vha, 0x3067, |
| 2277 | "qla2x00t(%ld): %s failed: unable to allocate request packet", |
| 2278 | vha->host_no, __func__); |
| 2279 | goto out; |
| 2280 | } |
| 2281 | |
| 2282 | ctio->entry_type = CTIO_TYPE7; |
| 2283 | ctio->entry_count = 1; |
| 2284 | ctio->handle = QLA_TGT_SKIP_HANDLE; |
| 2285 | ctio->nport_handle = cmd->sess->loop_id; |
| 2286 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
| 2287 | ctio->vp_index = vha->vp_idx; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2288 | ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2289 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2290 | temp = (atio->u.isp24.attr << 9) | |
| 2291 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2292 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2293 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2294 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
| 2295 | ctio->u.status1.scsi_status = |
| 2296 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status); |
| 2297 | ctio->u.status1.response_len = cpu_to_le16(18); |
| 2298 | ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio)); |
| 2299 | |
| 2300 | if (ctio->u.status1.residual != 0) |
| 2301 | ctio->u.status1.scsi_status |= |
| 2302 | cpu_to_le16(SS_RESIDUAL_UNDER); |
| 2303 | |
Bart Van Assche | a861b49 | 2019-04-17 14:44:42 -0700 | [diff] [blame] | 2304 | /* Fixed format sense data. */ |
| 2305 | ctio->u.status1.sense_data[0] = 0x70; |
| 2306 | ctio->u.status1.sense_data[2] = sense_key; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2307 | /* Additional sense length */ |
Bart Van Assche | a861b49 | 2019-04-17 14:44:42 -0700 | [diff] [blame] | 2308 | ctio->u.status1.sense_data[7] = 0xa; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2309 | /* ASC and ASCQ */ |
Bart Van Assche | a861b49 | 2019-04-17 14:44:42 -0700 | [diff] [blame] | 2310 | ctio->u.status1.sense_data[12] = asc; |
| 2311 | ctio->u.status1.sense_data[13] = ascq; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2312 | |
| 2313 | /* Memory Barrier */ |
| 2314 | wmb(); |
| 2315 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2316 | if (qpair->reqq_start_iocbs) |
| 2317 | qpair->reqq_start_iocbs(qpair); |
| 2318 | else |
| 2319 | qla2x00_start_iocbs(vha, qpair->req); |
| 2320 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2321 | out: |
| 2322 | return; |
| 2323 | } |
| 2324 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2325 | /* callback from target fabric module code */ |
| 2326 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) |
| 2327 | { |
| 2328 | struct scsi_qla_host *vha = mcmd->sess->vha; |
| 2329 | struct qla_hw_data *ha = vha->hw; |
| 2330 | unsigned long flags; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2331 | struct qla_qpair *qpair = mcmd->qpair; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2332 | bool free_mcmd = true; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2333 | |
| 2334 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, |
| 2335 | "TM response mcmd (%p) status %#x state %#x", |
| 2336 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); |
| 2337 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2338 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2339 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2340 | if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2341 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2342 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2343 | * previous life, just abort the processing. |
| 2344 | */ |
| 2345 | ql_dbg(ql_dbg_async, vha, 0xe100, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2346 | "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2347 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2348 | mcmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2349 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2350 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2351 | return; |
| 2352 | } |
| 2353 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2354 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) { |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2355 | switch (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode) { |
| 2356 | case ELS_LOGO: |
| 2357 | case ELS_PRLO: |
| 2358 | case ELS_TPRLO: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2359 | ql_dbg(ql_dbg_disc, vha, 0x2106, |
Bart Van Assche | 19ce192 | 2019-04-17 14:44:11 -0700 | [diff] [blame] | 2360 | "TM response logo %8phC status %#x state %#x", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2361 | mcmd->sess->port_name, mcmd->fc_tm_rsp, |
| 2362 | mcmd->flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 2363 | qlt_schedule_sess_for_deletion(mcmd->sess); |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2364 | break; |
| 2365 | default: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2366 | qlt_send_notify_ack(vha->hw->base_qpair, |
| 2367 | &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2368 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2369 | } |
| 2370 | } else { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2371 | if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) { |
| 2372 | qlt_build_abts_resp_iocb(mcmd); |
| 2373 | free_mcmd = false; |
| 2374 | } else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2375 | qlt_24xx_send_task_mgmt_ctio(qpair, mcmd, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2376 | mcmd->fc_tm_rsp); |
| 2377 | } |
| 2378 | /* |
| 2379 | * Make the callback for ->free_mcmd() to queue_work() and invoke |
| 2380 | * target_put_sess_cmd() to drop cmd_kref to 1. The final |
| 2381 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() |
| 2382 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd |
| 2383 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> |
| 2384 | * qlt_xmit_tm_rsp() returns here.. |
| 2385 | */ |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2386 | if (free_mcmd) |
| 2387 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 2388 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2389 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2390 | } |
| 2391 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); |
| 2392 | |
| 2393 | /* No locks */ |
| 2394 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) |
| 2395 | { |
| 2396 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2397 | |
| 2398 | BUG_ON(cmd->sg_cnt == 0); |
| 2399 | |
| 2400 | prm->sg = (struct scatterlist *)cmd->sg; |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2401 | prm->seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, cmd->sg, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2402 | cmd->sg_cnt, cmd->dma_data_direction); |
| 2403 | if (unlikely(prm->seg_cnt == 0)) |
| 2404 | goto out_err; |
| 2405 | |
| 2406 | prm->cmd->sg_mapped = 1; |
| 2407 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2408 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
| 2409 | /* |
| 2410 | * If greater than four sg entries then we need to allocate |
| 2411 | * the continuation entries |
| 2412 | */ |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2413 | if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2414 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2415 | QLA_TGT_DATASEGS_PER_CMD_24XX, |
| 2416 | QLA_TGT_DATASEGS_PER_CONT_24XX); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2417 | } else { |
| 2418 | /* DIF */ |
| 2419 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2420 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2421 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); |
| 2422 | prm->tot_dsds = prm->seg_cnt; |
| 2423 | } else |
| 2424 | prm->tot_dsds = prm->seg_cnt; |
| 2425 | |
| 2426 | if (cmd->prot_sg_cnt) { |
| 2427 | prm->prot_sg = cmd->prot_sg; |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2428 | prm->prot_seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2429 | cmd->prot_sg, cmd->prot_sg_cnt, |
| 2430 | cmd->dma_data_direction); |
| 2431 | if (unlikely(prm->prot_seg_cnt == 0)) |
| 2432 | goto out_err; |
| 2433 | |
| 2434 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2435 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2436 | /* Dif Bundling not support here */ |
| 2437 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, |
| 2438 | cmd->blk_sz); |
| 2439 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2440 | } else |
| 2441 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2442 | } |
| 2443 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2444 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2445 | return 0; |
| 2446 | |
| 2447 | out_err: |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2448 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2449 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", |
| 2450 | 0, prm->cmd->sg_cnt); |
| 2451 | return -1; |
| 2452 | } |
| 2453 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2454 | 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] | 2455 | { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2456 | struct qla_hw_data *ha; |
| 2457 | struct qla_qpair *qpair; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 2458 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2459 | if (!cmd->sg_mapped) |
| 2460 | return; |
| 2461 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2462 | qpair = cmd->qpair; |
| 2463 | |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2464 | dma_unmap_sg(&qpair->pdev->dev, cmd->sg, cmd->sg_cnt, |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2465 | cmd->dma_data_direction); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2466 | cmd->sg_mapped = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2467 | |
| 2468 | if (cmd->prot_sg_cnt) |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2469 | dma_unmap_sg(&qpair->pdev->dev, cmd->prot_sg, cmd->prot_sg_cnt, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2470 | cmd->dma_data_direction); |
| 2471 | |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2472 | if (!cmd->ctx) |
| 2473 | return; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2474 | ha = vha->hw; |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2475 | if (cmd->ctx_dsd_alloced) |
| 2476 | qla2x00_clean_dsd_pool(ha, cmd->ctx); |
| 2477 | |
| 2478 | 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] | 2479 | } |
| 2480 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2481 | static int qlt_check_reserve_free_req(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2482 | uint32_t req_cnt) |
| 2483 | { |
Quinn Tran | d63b328 | 2017-06-02 09:12:07 -0700 | [diff] [blame] | 2484 | uint32_t cnt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2485 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2486 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2487 | if (req->cnt < (req_cnt + 2)) { |
Quinn Tran | af7bb38 | 2017-06-13 20:47:23 -0700 | [diff] [blame] | 2488 | cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr : |
| 2489 | RD_REG_DWORD_RELAXED(req->req_q_out)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2490 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2491 | if (req->ring_index < cnt) |
| 2492 | req->cnt = cnt - req->ring_index; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2493 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2494 | req->cnt = req->length - (req->ring_index - cnt); |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2495 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2496 | if (unlikely(req->cnt < (req_cnt + 2))) |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2497 | return -EAGAIN; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2498 | } |
| 2499 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2500 | req->cnt -= req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2501 | |
| 2502 | return 0; |
| 2503 | } |
| 2504 | |
| 2505 | /* |
| 2506 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2507 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2508 | static inline void *qlt_get_req_pkt(struct req_que *req) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2509 | { |
| 2510 | /* Adjust ring index. */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2511 | req->ring_index++; |
| 2512 | if (req->ring_index == req->length) { |
| 2513 | req->ring_index = 0; |
| 2514 | req->ring_ptr = req->ring; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2515 | } else { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2516 | req->ring_ptr++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2517 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2518 | return (cont_entry_t *)req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2522 | static inline uint32_t qlt_make_handle(struct qla_qpair *qpair) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2523 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2524 | uint32_t h; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2525 | int index; |
| 2526 | uint8_t found = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2527 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2528 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2529 | h = req->current_outstanding_cmd; |
| 2530 | |
| 2531 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
| 2532 | h++; |
| 2533 | if (h == req->num_outstanding_cmds) |
| 2534 | h = 1; |
| 2535 | |
| 2536 | if (h == QLA_TGT_SKIP_HANDLE) |
| 2537 | continue; |
| 2538 | |
| 2539 | if (!req->outstanding_cmds[h]) { |
| 2540 | found = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2541 | break; |
| 2542 | } |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2543 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2544 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2545 | if (found) { |
| 2546 | req->current_outstanding_cmd = h; |
| 2547 | } else { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2548 | ql_dbg(ql_dbg_io, qpair->vha, 0x305b, |
| 2549 | "qla_target(%d): Ran out of empty cmd slots\n", |
| 2550 | qpair->vha->vp_idx); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2551 | h = QLA_TGT_NULL_HANDLE; |
| 2552 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2553 | |
| 2554 | return h; |
| 2555 | } |
| 2556 | |
| 2557 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2558 | static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair, |
| 2559 | struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2560 | { |
| 2561 | uint32_t h; |
| 2562 | struct ctio7_to_24xx *pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2563 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2564 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2565 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2566 | pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2567 | prm->pkt = pkt; |
| 2568 | memset(pkt, 0, sizeof(*pkt)); |
| 2569 | |
| 2570 | pkt->entry_type = CTIO_TYPE7; |
| 2571 | pkt->entry_count = (uint8_t)prm->req_cnt; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2572 | pkt->vp_index = prm->cmd->vp_idx; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2573 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2574 | h = qlt_make_handle(qpair); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2575 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2576 | /* |
| 2577 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2578 | * know the initiator's LOOP ID, hence we can't find |
| 2579 | * the session and, so, the command. |
| 2580 | */ |
| 2581 | return -EAGAIN; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 2582 | } else |
| 2583 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2584 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2585 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 2586 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
| 2587 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2588 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2589 | pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2590 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2591 | temp = atio->u.isp24.attr << 9; |
| 2592 | pkt->u.status0.flags |= cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2593 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2594 | pkt->u.status0.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2595 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2596 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2597 | return 0; |
| 2598 | } |
| 2599 | |
| 2600 | /* |
| 2601 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2602 | * that there is sufficient amount of request entries to not drop it. |
| 2603 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2604 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2605 | { |
| 2606 | int cnt; |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2607 | struct dsd64 *cur_dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2608 | |
| 2609 | /* Build continuation packets */ |
| 2610 | while (prm->seg_cnt > 0) { |
| 2611 | cont_a64_entry_t *cont_pkt64 = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2612 | (cont_a64_entry_t *)qlt_get_req_pkt( |
| 2613 | prm->cmd->qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2614 | |
| 2615 | /* |
| 2616 | * Make sure that from cont_pkt64 none of |
| 2617 | * 64-bit specific fields used for 32-bit |
| 2618 | * addressing. Cast to (cont_entry_t *) for |
| 2619 | * that. |
| 2620 | */ |
| 2621 | |
| 2622 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); |
| 2623 | |
| 2624 | cont_pkt64->entry_count = 1; |
| 2625 | cont_pkt64->sys_define = 0; |
| 2626 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2627 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2628 | cur_dsd = cont_pkt64->dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2629 | |
| 2630 | /* Load continuation entry data segments */ |
| 2631 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2632 | cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2633 | cnt++, prm->seg_cnt--) { |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2634 | append_dsd64(&cur_dsd, prm->sg); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2635 | prm->sg = sg_next(prm->sg); |
| 2636 | } |
| 2637 | } |
| 2638 | } |
| 2639 | |
| 2640 | /* |
| 2641 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2642 | * that there is sufficient amount of request entries to not drop it. |
| 2643 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2644 | static void qlt_load_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2645 | { |
| 2646 | int cnt; |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2647 | struct dsd64 *cur_dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2648 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; |
| 2649 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2650 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
| 2651 | |
| 2652 | /* Setup packet address segment pointer */ |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2653 | cur_dsd = &pkt24->u.status0.dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2654 | |
| 2655 | /* Set total data segment count */ |
| 2656 | if (prm->seg_cnt) |
| 2657 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); |
| 2658 | |
| 2659 | if (prm->seg_cnt == 0) { |
| 2660 | /* No data transfer */ |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2661 | cur_dsd->address = 0; |
| 2662 | cur_dsd->length = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2663 | return; |
| 2664 | } |
| 2665 | |
| 2666 | /* If scatter gather */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2667 | |
| 2668 | /* Load command entry data segments */ |
| 2669 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2670 | (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2671 | cnt++, prm->seg_cnt--) { |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2672 | append_dsd64(&cur_dsd, prm->sg); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2673 | prm->sg = sg_next(prm->sg); |
| 2674 | } |
| 2675 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2676 | qlt_load_cont_data_segments(prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) |
| 2680 | { |
| 2681 | return cmd->bufflen > 0; |
| 2682 | } |
| 2683 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2684 | static void qlt_print_dif_err(struct qla_tgt_prm *prm) |
| 2685 | { |
| 2686 | struct qla_tgt_cmd *cmd; |
| 2687 | struct scsi_qla_host *vha; |
| 2688 | |
| 2689 | /* asc 0x10=dif error */ |
| 2690 | if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) { |
| 2691 | cmd = prm->cmd; |
| 2692 | vha = cmd->vha; |
| 2693 | /* ASCQ */ |
| 2694 | switch (prm->sense_buffer[13]) { |
| 2695 | case 1: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2696 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2697 | "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2698 | "se_cmd=%p tag[%x]", |
| 2699 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2700 | cmd->atio.u.isp24.exchange_addr); |
| 2701 | break; |
| 2702 | case 2: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2703 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2704 | "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2705 | "se_cmd=%p tag[%x]", |
| 2706 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2707 | cmd->atio.u.isp24.exchange_addr); |
| 2708 | break; |
| 2709 | case 3: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2710 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2711 | "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2712 | "se_cmd=%p tag[%x]", |
| 2713 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2714 | cmd->atio.u.isp24.exchange_addr); |
| 2715 | break; |
| 2716 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2717 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe010, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2718 | "BE detected Dif ERR: lba[%llx|%lld] len[%x] " |
| 2719 | "se_cmd=%p tag[%x]", |
| 2720 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2721 | cmd->atio.u.isp24.exchange_addr); |
| 2722 | break; |
| 2723 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2724 | ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2725 | } |
| 2726 | } |
| 2727 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2728 | /* |
| 2729 | * Called without ha->hardware_lock held |
| 2730 | */ |
| 2731 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, |
| 2732 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, |
| 2733 | uint32_t *full_req_cnt) |
| 2734 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2735 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2736 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2737 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2738 | prm->cmd = cmd; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2739 | prm->tgt = cmd->tgt; |
| 2740 | prm->pkt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2741 | prm->rq_result = scsi_status; |
| 2742 | prm->sense_buffer = &cmd->sense_buffer[0]; |
| 2743 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; |
| 2744 | prm->sg = NULL; |
| 2745 | prm->seg_cnt = -1; |
| 2746 | prm->req_cnt = 1; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2747 | prm->residual = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2748 | prm->add_status_pkt = 0; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2749 | prm->prot_sg = NULL; |
| 2750 | prm->prot_seg_cnt = 0; |
| 2751 | prm->tot_dsds = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2752 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2753 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
| 2754 | if (qlt_pci_map_calc_cnt(prm) != 0) |
| 2755 | return -EAGAIN; |
| 2756 | } |
| 2757 | |
| 2758 | *full_req_cnt = prm->req_cnt; |
| 2759 | |
| 2760 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { |
| 2761 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2762 | ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2763 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2764 | prm->residual, se_cmd->tag, |
| 2765 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, |
| 2766 | cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2767 | prm->rq_result |= SS_RESIDUAL_UNDER; |
| 2768 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2769 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2770 | ql_dbg_qp(ql_dbg_io, qpair, 0x305d, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2771 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2772 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? |
| 2773 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2774 | prm->rq_result |= SS_RESIDUAL_OVER; |
| 2775 | } |
| 2776 | |
| 2777 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2778 | /* |
| 2779 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be |
| 2780 | * ignored in *xmit_response() below |
| 2781 | */ |
| 2782 | if (qlt_has_data(cmd)) { |
| 2783 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2784 | (IS_FWI2_CAPABLE(cmd->vha->hw) && |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2785 | (prm->rq_result != 0))) { |
| 2786 | prm->add_status_pkt = 1; |
| 2787 | (*full_req_cnt)++; |
| 2788 | } |
| 2789 | } |
| 2790 | } |
| 2791 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2792 | return 0; |
| 2793 | } |
| 2794 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2795 | static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd, |
| 2796 | int sending_sense) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2797 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2798 | if (cmd->qpair->enable_class_2) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2799 | return 0; |
| 2800 | |
| 2801 | if (sending_sense) |
| 2802 | return cmd->conf_compl_supported; |
| 2803 | else |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2804 | return cmd->qpair->enable_explicit_conf && |
| 2805 | cmd->conf_compl_supported; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2806 | } |
| 2807 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2808 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, |
| 2809 | struct qla_tgt_prm *prm) |
| 2810 | { |
| 2811 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, |
| 2812 | (uint32_t)sizeof(ctio->u.status1.sense_data)); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2813 | ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2814 | if (qlt_need_explicit_conf(prm->cmd, 0)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2815 | ctio->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2816 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2817 | CTIO7_FLAGS_CONFORM_REQ); |
| 2818 | } |
| 2819 | ctio->u.status0.residual = cpu_to_le32(prm->residual); |
| 2820 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); |
| 2821 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { |
| 2822 | int i; |
| 2823 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2824 | if (qlt_need_explicit_conf(prm->cmd, 1)) { |
Quinn Tran | df2e32c | 2017-01-19 22:27:53 -0800 | [diff] [blame] | 2825 | if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) { |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2826 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2827 | "Skipping EXPLICIT_CONFORM and " |
| 2828 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " |
| 2829 | "non GOOD status\n"); |
| 2830 | goto skip_explict_conf; |
| 2831 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2832 | ctio->u.status1.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2833 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2834 | CTIO7_FLAGS_CONFORM_REQ); |
| 2835 | } |
| 2836 | skip_explict_conf: |
| 2837 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2838 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2839 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2840 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2841 | ctio->u.status1.scsi_status |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2842 | cpu_to_le16(SS_SENSE_LEN_VALID); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2843 | ctio->u.status1.sense_length = |
| 2844 | cpu_to_le16(prm->sense_buffer_len); |
| 2845 | for (i = 0; i < prm->sense_buffer_len/4; i++) |
| 2846 | ((uint32_t *)ctio->u.status1.sense_data)[i] = |
| 2847 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2848 | |
| 2849 | qlt_print_dif_err(prm); |
| 2850 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2851 | } else { |
| 2852 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2853 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2854 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2855 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2856 | ctio->u.status1.sense_length = 0; |
| 2857 | memset(ctio->u.status1.sense_data, 0, |
| 2858 | sizeof(ctio->u.status1.sense_data)); |
| 2859 | } |
| 2860 | |
| 2861 | /* Sense with len > 24, is it possible ??? */ |
| 2862 | } |
| 2863 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2864 | static inline int |
| 2865 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) |
| 2866 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2867 | switch (se_cmd->prot_op) { |
| 2868 | case TARGET_PROT_DOUT_INSERT: |
| 2869 | case TARGET_PROT_DIN_STRIP: |
| 2870 | if (ql2xenablehba_err_chk >= 1) |
| 2871 | return 1; |
| 2872 | break; |
| 2873 | case TARGET_PROT_DOUT_PASS: |
| 2874 | case TARGET_PROT_DIN_PASS: |
| 2875 | if (ql2xenablehba_err_chk >= 2) |
| 2876 | return 1; |
| 2877 | break; |
| 2878 | case TARGET_PROT_DIN_INSERT: |
| 2879 | case TARGET_PROT_DOUT_STRIP: |
| 2880 | return 1; |
| 2881 | default: |
| 2882 | break; |
| 2883 | } |
| 2884 | return 0; |
| 2885 | } |
| 2886 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2887 | static inline int |
| 2888 | qla_tgt_ref_mask_check(struct se_cmd *se_cmd) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2889 | { |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2890 | switch (se_cmd->prot_op) { |
| 2891 | case TARGET_PROT_DIN_INSERT: |
| 2892 | case TARGET_PROT_DOUT_INSERT: |
| 2893 | case TARGET_PROT_DIN_STRIP: |
| 2894 | case TARGET_PROT_DOUT_STRIP: |
| 2895 | case TARGET_PROT_DIN_PASS: |
| 2896 | case TARGET_PROT_DOUT_PASS: |
| 2897 | return 1; |
| 2898 | default: |
| 2899 | return 0; |
| 2900 | } |
| 2901 | return 0; |
| 2902 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2903 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2904 | /* |
| 2905 | * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command |
| 2906 | */ |
| 2907 | static void |
| 2908 | qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx, |
| 2909 | uint16_t *pfw_prot_opts) |
| 2910 | { |
| 2911 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2912 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; |
| 2913 | scsi_qla_host_t *vha = cmd->tgt->vha; |
| 2914 | struct qla_hw_data *ha = vha->hw; |
| 2915 | uint32_t t32 = 0; |
| 2916 | |
| 2917 | /* |
| 2918 | * wait till Mode Sense/Select cmd, modepage Ah, subpage 2 |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2919 | * have been immplemented by TCM, before AppTag is avail. |
| 2920 | * Look for modesense_handlers[] |
| 2921 | */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2922 | ctx->app_tag = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2923 | ctx->app_tag_mask[0] = 0x0; |
| 2924 | ctx->app_tag_mask[1] = 0x0; |
| 2925 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2926 | if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2927 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2928 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2929 | *pfw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2930 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2931 | *pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2932 | } |
| 2933 | |
| 2934 | t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts); |
| 2935 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2936 | switch (se_cmd->prot_type) { |
| 2937 | case TARGET_DIF_TYPE0_PROT: |
| 2938 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2939 | * No check for ql2xenablehba_err_chk, as it |
| 2940 | * would be an I/O error if hba tag generation |
| 2941 | * is not done. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2942 | */ |
| 2943 | ctx->ref_tag = cpu_to_le32(lba); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2944 | /* enable ALL bytes of the ref tag */ |
| 2945 | ctx->ref_tag_mask[0] = 0xff; |
| 2946 | ctx->ref_tag_mask[1] = 0xff; |
| 2947 | ctx->ref_tag_mask[2] = 0xff; |
| 2948 | ctx->ref_tag_mask[3] = 0xff; |
| 2949 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2950 | case TARGET_DIF_TYPE1_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2951 | /* |
| 2952 | * For TYPE 1 protection: 16 bit GUARD tag, 32 bit |
| 2953 | * REF tag, and 16 bit app tag. |
| 2954 | */ |
| 2955 | ctx->ref_tag = cpu_to_le32(lba); |
| 2956 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2957 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2958 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2959 | break; |
| 2960 | } |
| 2961 | /* enable ALL bytes of the ref tag */ |
| 2962 | ctx->ref_tag_mask[0] = 0xff; |
| 2963 | ctx->ref_tag_mask[1] = 0xff; |
| 2964 | ctx->ref_tag_mask[2] = 0xff; |
| 2965 | ctx->ref_tag_mask[3] = 0xff; |
| 2966 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2967 | case TARGET_DIF_TYPE2_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2968 | /* |
| 2969 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF |
| 2970 | * tag has to match LBA in CDB + N |
| 2971 | */ |
| 2972 | ctx->ref_tag = cpu_to_le32(lba); |
| 2973 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2974 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2975 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2976 | break; |
| 2977 | } |
| 2978 | /* enable ALL bytes of the ref tag */ |
| 2979 | ctx->ref_tag_mask[0] = 0xff; |
| 2980 | ctx->ref_tag_mask[1] = 0xff; |
| 2981 | ctx->ref_tag_mask[2] = 0xff; |
| 2982 | ctx->ref_tag_mask[3] = 0xff; |
| 2983 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2984 | case TARGET_DIF_TYPE3_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2985 | /* For TYPE 3 protection: 16 bit GUARD only */ |
| 2986 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2987 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = |
| 2988 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; |
| 2989 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2990 | } |
| 2991 | } |
| 2992 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2993 | static inline int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2994 | qlt_build_ctio_crc2_pkt(struct qla_qpair *qpair, struct qla_tgt_prm *prm) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2995 | { |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2996 | struct dsd64 *cur_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2997 | uint32_t transfer_length = 0; |
| 2998 | uint32_t data_bytes; |
| 2999 | uint32_t dif_bytes; |
| 3000 | uint8_t bundling = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3001 | struct crc_context *crc_ctx_pkt = NULL; |
| 3002 | struct qla_hw_data *ha; |
| 3003 | struct ctio_crc2_to_fw *pkt; |
| 3004 | dma_addr_t crc_ctx_dma; |
| 3005 | uint16_t fw_prot_opts = 0; |
| 3006 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 3007 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 3008 | uint32_t h; |
| 3009 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3010 | struct qla_tc_param tc; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3011 | uint16_t t16; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3012 | scsi_qla_host_t *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3013 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3014 | ha = vha->hw; |
| 3015 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3016 | pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3017 | prm->pkt = pkt; |
| 3018 | memset(pkt, 0, sizeof(*pkt)); |
| 3019 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3020 | ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3021 | "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n", |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3022 | cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3023 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); |
| 3024 | |
| 3025 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || |
| 3026 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) |
| 3027 | bundling = 0; |
| 3028 | |
| 3029 | /* Compute dif len and adjust data len to incude protection */ |
| 3030 | data_bytes = cmd->bufflen; |
| 3031 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; |
| 3032 | |
| 3033 | switch (se_cmd->prot_op) { |
| 3034 | case TARGET_PROT_DIN_INSERT: |
| 3035 | case TARGET_PROT_DOUT_STRIP: |
| 3036 | transfer_length = data_bytes; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3037 | if (cmd->prot_sg_cnt) |
| 3038 | data_bytes += dif_bytes; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3039 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3040 | case TARGET_PROT_DIN_STRIP: |
| 3041 | case TARGET_PROT_DOUT_INSERT: |
| 3042 | case TARGET_PROT_DIN_PASS: |
| 3043 | case TARGET_PROT_DOUT_PASS: |
| 3044 | transfer_length = data_bytes + dif_bytes; |
| 3045 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3046 | default: |
| 3047 | BUG(); |
| 3048 | break; |
| 3049 | } |
| 3050 | |
| 3051 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 3052 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 3053 | /* HBA error checking enabled */ |
| 3054 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 3055 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 3056 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 3057 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 3058 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 3059 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 3060 | } |
| 3061 | |
| 3062 | switch (se_cmd->prot_op) { |
| 3063 | case TARGET_PROT_DIN_INSERT: |
| 3064 | case TARGET_PROT_DOUT_INSERT: |
| 3065 | fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 3066 | break; |
| 3067 | case TARGET_PROT_DIN_STRIP: |
| 3068 | case TARGET_PROT_DOUT_STRIP: |
| 3069 | fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 3070 | break; |
| 3071 | case TARGET_PROT_DIN_PASS: |
| 3072 | case TARGET_PROT_DOUT_PASS: |
| 3073 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 3074 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ |
| 3075 | break; |
| 3076 | default:/* Normal Request */ |
| 3077 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 3078 | break; |
| 3079 | } |
| 3080 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3081 | /* ---- PKT ---- */ |
| 3082 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 3083 | pkt->entry_type = CTIO_CRC2; |
| 3084 | pkt->entry_count = 1; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3085 | pkt->vp_index = cmd->vp_idx; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3086 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3087 | h = qlt_make_handle(qpair); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3088 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 3089 | /* |
| 3090 | * CTIO type 7 from the firmware doesn't provide a way to |
| 3091 | * know the initiator's LOOP ID, hence we can't find |
| 3092 | * the session and, so, the command. |
| 3093 | */ |
| 3094 | return -EAGAIN; |
| 3095 | } else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3096 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3097 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3098 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 3099 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3100 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3101 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 3102 | pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3103 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3104 | |
| 3105 | /* silence compile warning */ |
| 3106 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3107 | pkt->ox_id = cpu_to_le16(t16); |
| 3108 | |
| 3109 | t16 = (atio->u.isp24.attr << 9); |
| 3110 | pkt->flags |= cpu_to_le16(t16); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3111 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
| 3112 | |
| 3113 | /* Set transfer direction */ |
| 3114 | if (cmd->dma_data_direction == DMA_TO_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3115 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3116 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3117 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3118 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3119 | pkt->dseg_count = prm->tot_dsds; |
| 3120 | /* Fibre channel byte count */ |
| 3121 | pkt->transfer_length = cpu_to_le32(transfer_length); |
| 3122 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3123 | /* ----- CRC context -------- */ |
| 3124 | |
| 3125 | /* Allocate CRC context from global pool */ |
| 3126 | crc_ctx_pkt = cmd->ctx = |
Souptick Joarder | 501017f | 2018-02-15 01:40:38 +0530 | [diff] [blame] | 3127 | dma_pool_zalloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3128 | |
| 3129 | if (!crc_ctx_pkt) |
| 3130 | goto crc_queuing_error; |
| 3131 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3132 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 3133 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 3134 | |
| 3135 | /* Set handle */ |
| 3136 | crc_ctx_pkt->handle = pkt->handle; |
| 3137 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3138 | qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3139 | |
Bart Van Assche | d4556a4 | 2019-04-17 14:44:39 -0700 | [diff] [blame] | 3140 | put_unaligned_le64(crc_ctx_dma, &pkt->crc_context_address); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3141 | pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 3142 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3143 | if (!bundling) { |
Bart Van Assche | 9e75b5e | 2019-08-08 20:01:33 -0700 | [diff] [blame] | 3144 | cur_dsd = &crc_ctx_pkt->u.nobundling.data_dsd[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3145 | } else { |
| 3146 | /* |
| 3147 | * Configure Bundling if we need to fetch interlaving |
| 3148 | * protection PCI accesses |
| 3149 | */ |
| 3150 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 3151 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 3152 | crc_ctx_pkt->u.bundling.dseg_count = |
| 3153 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); |
Bart Van Assche | 9e75b5e | 2019-08-08 20:01:33 -0700 | [diff] [blame] | 3154 | cur_dsd = &crc_ctx_pkt->u.bundling.data_dsd[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3155 | } |
| 3156 | |
| 3157 | /* Finish the common fields of CRC pkt */ |
| 3158 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); |
| 3159 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 3160 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3161 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3162 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3163 | memset((uint8_t *)&tc, 0 , sizeof(tc)); |
| 3164 | tc.vha = vha; |
| 3165 | tc.blk_sz = cmd->blk_sz; |
| 3166 | tc.bufflen = cmd->bufflen; |
| 3167 | tc.sg = cmd->sg; |
| 3168 | tc.prot_sg = cmd->prot_sg; |
| 3169 | tc.ctx = crc_ctx_pkt; |
| 3170 | tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3171 | |
| 3172 | /* Walks data segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3173 | pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3174 | |
| 3175 | if (!bundling && prm->prot_seg_cnt) { |
| 3176 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3177 | prm->tot_dsds, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3178 | goto crc_queuing_error; |
| 3179 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3180 | (prm->tot_dsds - prm->prot_seg_cnt), &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3181 | goto crc_queuing_error; |
| 3182 | |
| 3183 | if (bundling && prm->prot_seg_cnt) { |
| 3184 | /* Walks dif segments */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3185 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3186 | |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 3187 | cur_dsd = &crc_ctx_pkt->u.bundling.dif_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3188 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, |
Giridhar Malavali | 50b8127 | 2018-12-21 09:33:45 -0800 | [diff] [blame] | 3189 | prm->prot_seg_cnt, cmd)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3190 | goto crc_queuing_error; |
| 3191 | } |
| 3192 | return QLA_SUCCESS; |
| 3193 | |
| 3194 | crc_queuing_error: |
| 3195 | /* Cleanup will be performed by the caller */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3196 | qpair->req->outstanding_cmds[h] = NULL; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3197 | |
| 3198 | return QLA_FUNCTION_FAILED; |
| 3199 | } |
| 3200 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3201 | /* |
| 3202 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * |
| 3203 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon |
| 3204 | */ |
| 3205 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, |
| 3206 | uint8_t scsi_status) |
| 3207 | { |
| 3208 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3209 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3210 | struct ctio7_to_24xx *pkt; |
| 3211 | struct qla_tgt_prm prm; |
| 3212 | uint32_t full_req_cnt = 0; |
| 3213 | unsigned long flags = 0; |
| 3214 | int res; |
| 3215 | |
Quinn Tran | 51fd6e6 | 2019-01-24 23:23:43 -0800 | [diff] [blame] | 3216 | if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || |
| 3217 | (cmd->sess && cmd->sess->deleted)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3218 | cmd->state = QLA_TGT_STATE_PROCESSED; |
Bart Van Assche | 0dcec41 | 2019-08-08 20:02:10 -0700 | [diff] [blame] | 3219 | res = 0; |
| 3220 | goto free; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3221 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3222 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3223 | ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3224 | "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p] qp %d\n", |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3225 | (xmit_type & QLA_TGT_XMIT_STATUS) ? |
| 3226 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3227 | &cmd->se_cmd, qpair->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3228 | |
| 3229 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, |
| 3230 | &full_req_cnt); |
Bart Van Assche | 0dcec41 | 2019-08-08 20:02:10 -0700 | [diff] [blame] | 3231 | if (unlikely(res != 0)) |
| 3232 | goto free; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3233 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3234 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3235 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3236 | if (xmit_type == QLA_TGT_XMIT_STATUS) |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3237 | qpair->tgt_counters.core_qla_snd_status++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3238 | else |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3239 | qpair->tgt_counters.core_qla_que_buf++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3240 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3241 | if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3242 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3243 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3244 | * previous life, just abort the processing. |
| 3245 | */ |
| 3246 | cmd->state = QLA_TGT_STATE_PROCESSED; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3247 | ql_dbg_qp(ql_dbg_async, qpair, 0xe101, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3248 | "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3249 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3250 | cmd->reset_count, qpair->chip_reset); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3251 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Bart Van Assche | 0dcec41 | 2019-08-08 20:02:10 -0700 | [diff] [blame] | 3252 | res = 0; |
| 3253 | goto free; |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3254 | } |
| 3255 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3256 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3257 | res = qlt_check_reserve_free_req(qpair, full_req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3258 | if (unlikely(res)) |
| 3259 | goto out_unmap_unlock; |
| 3260 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3261 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3262 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3263 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3264 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3265 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3266 | qpair->req->cnt += full_req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3267 | goto out_unmap_unlock; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3268 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3269 | |
| 3270 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
| 3271 | |
| 3272 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { |
| 3273 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3274 | cpu_to_le16(CTIO7_FLAGS_DATA_IN | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3275 | CTIO7_FLAGS_STATUS_MODE_0); |
| 3276 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3277 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3278 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3279 | |
| 3280 | if (prm.add_status_pkt == 0) { |
| 3281 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 3282 | pkt->u.status0.scsi_status = |
| 3283 | cpu_to_le16(prm.rq_result); |
| 3284 | pkt->u.status0.residual = |
| 3285 | cpu_to_le32(prm.residual); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3286 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3287 | CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3288 | if (qlt_need_explicit_conf(cmd, 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3289 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3290 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3291 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 3292 | CTIO7_FLAGS_CONFORM_REQ); |
| 3293 | } |
| 3294 | } |
| 3295 | |
| 3296 | } else { |
| 3297 | /* |
| 3298 | * We have already made sure that there is sufficient |
| 3299 | * amount of request entries to not drop HW lock in |
| 3300 | * req_pkt(). |
| 3301 | */ |
| 3302 | struct ctio7_to_24xx *ctio = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3303 | (struct ctio7_to_24xx *)qlt_get_req_pkt( |
| 3304 | qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3305 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3306 | ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e, |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3307 | "Building additional status packet 0x%p.\n", |
| 3308 | ctio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3309 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3310 | /* |
| 3311 | * T10Dif: ctio_crc2_to_fw overlay ontop of |
| 3312 | * ctio7_to_24xx |
| 3313 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3314 | memcpy(ctio, pkt, sizeof(*ctio)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3315 | /* reset back to CTIO7 */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3316 | ctio->entry_count = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3317 | ctio->entry_type = CTIO_TYPE7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3318 | ctio->dseg_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3319 | ctio->u.status1.flags &= ~cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3320 | CTIO7_FLAGS_DATA_IN); |
| 3321 | |
| 3322 | /* Real finish is ctio_m1's finish */ |
| 3323 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3324 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3325 | CTIO7_FLAGS_DONT_RET_CTIO); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3326 | |
| 3327 | /* qlt_24xx_init_ctio_to_isp will correct |
| 3328 | * all neccessary fields that's part of CTIO7. |
| 3329 | * There should be no residual of CTIO-CRC2 data. |
| 3330 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3331 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
| 3332 | &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3333 | } |
| 3334 | } else |
| 3335 | qlt_24xx_init_ctio_to_isp(pkt, &prm); |
| 3336 | |
| 3337 | |
| 3338 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3339 | cmd->cmd_sent_to_fw = 1; |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 3340 | cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3341 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3342 | /* Memory Barrier */ |
| 3343 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3344 | if (qpair->reqq_start_iocbs) |
| 3345 | qpair->reqq_start_iocbs(qpair); |
| 3346 | else |
| 3347 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3348 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3349 | |
| 3350 | return 0; |
| 3351 | |
| 3352 | out_unmap_unlock: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3353 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3354 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3355 | |
Bart Van Assche | 0dcec41 | 2019-08-08 20:02:10 -0700 | [diff] [blame] | 3356 | free: |
| 3357 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3358 | return res; |
| 3359 | } |
| 3360 | EXPORT_SYMBOL(qlt_xmit_response); |
| 3361 | |
| 3362 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) |
| 3363 | { |
| 3364 | struct ctio7_to_24xx *pkt; |
| 3365 | struct scsi_qla_host *vha = cmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3366 | struct qla_tgt *tgt = cmd->tgt; |
| 3367 | struct qla_tgt_prm prm; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3368 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3369 | int res = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3370 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3371 | |
| 3372 | memset(&prm, 0, sizeof(prm)); |
| 3373 | prm.cmd = cmd; |
| 3374 | prm.tgt = tgt; |
| 3375 | prm.sg = NULL; |
| 3376 | prm.req_cnt = 1; |
| 3377 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3378 | /* Calculate number of entries and segments required */ |
| 3379 | if (qlt_pci_map_calc_cnt(&prm) != 0) |
| 3380 | return -EAGAIN; |
| 3381 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3382 | if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3383 | (cmd->sess && cmd->sess->deleted)) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3384 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3385 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3386 | * previous life, just abort the processing. |
| 3387 | */ |
Bart Van Assche | aefed3e | 2019-04-17 14:44:29 -0700 | [diff] [blame] | 3388 | cmd->aborted = 1; |
| 3389 | cmd->write_data_transferred = 0; |
| 3390 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3391 | vha->hw->tgt.tgt_ops->handle_data(cmd); |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3392 | ql_dbg_qp(ql_dbg_async, qpair, 0xe102, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3393 | "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3394 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3395 | cmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3396 | return 0; |
| 3397 | } |
| 3398 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3399 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3400 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3401 | res = qlt_check_reserve_free_req(qpair, prm.req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3402 | if (res != 0) |
| 3403 | goto out_unlock_free_unmap; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3404 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3405 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3406 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3407 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3408 | |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3409 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3410 | qpair->req->cnt += prm.req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3411 | goto out_unlock_free_unmap; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3412 | } |
| 3413 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3414 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3415 | pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3416 | CTIO7_FLAGS_STATUS_MODE_0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3417 | |
| 3418 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3419 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3420 | |
| 3421 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3422 | cmd->cmd_sent_to_fw = 1; |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 3423 | cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3424 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3425 | /* Memory Barrier */ |
| 3426 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3427 | if (qpair->reqq_start_iocbs) |
| 3428 | qpair->reqq_start_iocbs(qpair); |
| 3429 | else |
| 3430 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3431 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3432 | |
| 3433 | return res; |
| 3434 | |
| 3435 | out_unlock_free_unmap: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3436 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3437 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3438 | |
| 3439 | return res; |
| 3440 | } |
| 3441 | EXPORT_SYMBOL(qlt_rdy_to_xfer); |
| 3442 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3443 | |
| 3444 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3445 | * it is assumed either hardware_lock or qpair lock is held. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3446 | */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3447 | static void |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3448 | qlt_handle_dif_error(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3449 | struct ctio_crc_from_fw *sts) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3450 | { |
| 3451 | uint8_t *ap = &sts->actual_dif[0]; |
| 3452 | uint8_t *ep = &sts->expected_dif[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3453 | uint64_t lba = cmd->se_cmd.t_task_lba; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3454 | uint8_t scsi_status, sense_key, asc, ascq; |
| 3455 | unsigned long flags; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3456 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3457 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3458 | cmd->trc_flags |= TRC_DIF_ERR; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3459 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3460 | cmd->a_guard = be16_to_cpu(*(uint16_t *)(ap + 0)); |
| 3461 | cmd->a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2)); |
| 3462 | cmd->a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3463 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3464 | cmd->e_guard = be16_to_cpu(*(uint16_t *)(ep + 0)); |
| 3465 | cmd->e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2)); |
| 3466 | cmd->e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3467 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3468 | ql_dbg(ql_dbg_tgt_dif, vha, 0xf075, |
| 3469 | "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3470 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3471 | scsi_status = sense_key = asc = ascq = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3472 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3473 | /* check appl tag */ |
| 3474 | if (cmd->e_app_tag != cmd->a_app_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3475 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d, |
| 3476 | "App Tag ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard [%x|%x] cmd=%p ox_id[%04x]", |
| 3477 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3478 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3479 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3480 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3481 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3482 | cmd->dif_err_code = DIF_ERR_APP; |
| 3483 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3484 | sense_key = ABORTED_COMMAND; |
| 3485 | asc = 0x10; |
| 3486 | ascq = 0x2; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3487 | } |
| 3488 | |
| 3489 | /* check ref tag */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3490 | if (cmd->e_ref_tag != cmd->a_ref_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3491 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e, |
| 3492 | "Ref Tag ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard[%x|%x] cmd=%p ox_id[%04x] ", |
| 3493 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3494 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3495 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3496 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3497 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3498 | cmd->dif_err_code = DIF_ERR_REF; |
| 3499 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3500 | sense_key = ABORTED_COMMAND; |
| 3501 | asc = 0x10; |
| 3502 | ascq = 0x3; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3503 | goto out; |
| 3504 | } |
| 3505 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3506 | /* check guard */ |
| 3507 | if (cmd->e_guard != cmd->a_guard) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3508 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe012, |
| 3509 | "Guard ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard [%x|%x] cmd=%p ox_id[%04x]", |
| 3510 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3511 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3512 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3513 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
| 3514 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3515 | cmd->dif_err_code = DIF_ERR_GRD; |
| 3516 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3517 | sense_key = ABORTED_COMMAND; |
| 3518 | asc = 0x10; |
| 3519 | ascq = 0x1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3520 | } |
| 3521 | out: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3522 | switch (cmd->state) { |
| 3523 | case QLA_TGT_STATE_NEED_DATA: |
| 3524 | /* handle_data will load DIF error code */ |
| 3525 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3526 | vha->hw->tgt.tgt_ops->handle_data(cmd); |
| 3527 | break; |
| 3528 | default: |
| 3529 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3530 | if (cmd->aborted) { |
| 3531 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3532 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3533 | break; |
| 3534 | } |
| 3535 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3536 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3537 | qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc, |
| 3538 | ascq); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3539 | /* assume scsi status gets out on the wire. |
| 3540 | * Will not wait for completion. |
| 3541 | */ |
| 3542 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3543 | break; |
| 3544 | } |
| 3545 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3546 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3547 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3548 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3549 | static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3550 | struct imm_ntfy_from_isp *ntfy) |
| 3551 | { |
| 3552 | struct nack_to_isp *nack; |
| 3553 | struct qla_hw_data *ha = vha->hw; |
| 3554 | request_t *pkt; |
| 3555 | int ret = 0; |
| 3556 | |
| 3557 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c, |
| 3558 | "Sending TERM ELS CTIO (ha=%p)\n", ha); |
| 3559 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 3560 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3561 | if (pkt == NULL) { |
| 3562 | ql_dbg(ql_dbg_tgt, vha, 0xe080, |
| 3563 | "qla_target(%d): %s failed: unable to allocate " |
| 3564 | "request packet\n", vha->vp_idx, __func__); |
| 3565 | return -ENOMEM; |
| 3566 | } |
| 3567 | |
| 3568 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 3569 | pkt->entry_count = 1; |
Quinn Tran | 4f06073 | 2016-12-23 18:06:13 -0800 | [diff] [blame] | 3570 | pkt->handle = QLA_TGT_SKIP_HANDLE; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3571 | |
| 3572 | nack = (struct nack_to_isp *)pkt; |
| 3573 | nack->ox_id = ntfy->ox_id; |
| 3574 | |
| 3575 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3576 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3577 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
| 3578 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
| 3579 | } |
| 3580 | |
| 3581 | /* terminate */ |
| 3582 | nack->u.isp24.flags |= |
| 3583 | __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE); |
| 3584 | |
| 3585 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3586 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3587 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3588 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3589 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3590 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3591 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3592 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3593 | |
| 3594 | qla2x00_start_iocbs(vha, vha->req); |
| 3595 | return ret; |
| 3596 | } |
| 3597 | |
| 3598 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3599 | struct imm_ntfy_from_isp *imm, int ha_locked) |
| 3600 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3601 | int rc; |
| 3602 | |
Bart Van Assche | e65449a | 2019-04-17 14:44:26 -0700 | [diff] [blame] | 3603 | WARN_ON_ONCE(!ha_locked); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3604 | rc = __qlt_send_term_imm_notif(vha, imm); |
Bart Van Assche | e65449a | 2019-04-17 14:44:26 -0700 | [diff] [blame] | 3605 | pr_debug("rc = %d\n", rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3606 | } |
| 3607 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3608 | /* |
| 3609 | * If hardware_lock held on entry, might drop it, then reaquire |
| 3610 | * This function sends the appropriate CTIO to ISP 2xxx or 24xx |
| 3611 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3612 | static int __qlt_send_term_exchange(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3613 | struct qla_tgt_cmd *cmd, |
| 3614 | struct atio_from_isp *atio) |
| 3615 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3616 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3617 | struct ctio7_to_24xx *ctio24; |
| 3618 | struct qla_hw_data *ha = vha->hw; |
| 3619 | request_t *pkt; |
| 3620 | int ret = 0; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3621 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3622 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3623 | ql_dbg(ql_dbg_tgt, vha, 0xe009, "Sending TERM EXCH CTIO (ha=%p)\n", ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3624 | |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 3625 | if (cmd) |
| 3626 | vha = cmd->vha; |
| 3627 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3628 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3629 | if (pkt == NULL) { |
| 3630 | ql_dbg(ql_dbg_tgt, vha, 0xe050, |
| 3631 | "qla_target(%d): %s failed: unable to allocate " |
| 3632 | "request packet\n", vha->vp_idx, __func__); |
| 3633 | return -ENOMEM; |
| 3634 | } |
| 3635 | |
| 3636 | if (cmd != NULL) { |
| 3637 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { |
| 3638 | ql_dbg(ql_dbg_tgt, vha, 0xe051, |
| 3639 | "qla_target(%d): Terminating cmd %p with " |
| 3640 | "incorrect state %d\n", vha->vp_idx, cmd, |
| 3641 | cmd->state); |
| 3642 | } else |
| 3643 | ret = 1; |
| 3644 | } |
| 3645 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3646 | qpair->tgt_counters.num_term_xchg_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3647 | pkt->entry_count = 1; |
| 3648 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 3649 | |
| 3650 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 3651 | ctio24->entry_type = CTIO_TYPE7; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3652 | ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3653 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3654 | ctio24->vp_index = vha->vp_idx; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 3655 | ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3656 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3657 | temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 | |
| 3658 | CTIO7_FLAGS_TERMINATE; |
| 3659 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3660 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3661 | ctio24->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3662 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3663 | /* Memory Barrier */ |
| 3664 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3665 | if (qpair->reqq_start_iocbs) |
| 3666 | qpair->reqq_start_iocbs(qpair); |
| 3667 | else |
| 3668 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3669 | return ret; |
| 3670 | } |
| 3671 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3672 | static void qlt_send_term_exchange(struct qla_qpair *qpair, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3673 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, |
| 3674 | int ul_abort) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3675 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3676 | struct scsi_qla_host *vha; |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3677 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3678 | int rc; |
| 3679 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3680 | /* why use different vha? NPIV */ |
| 3681 | if (cmd) |
| 3682 | vha = cmd->vha; |
| 3683 | else |
| 3684 | vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3685 | |
| 3686 | if (ha_locked) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3687 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3688 | if (rc == -ENOMEM) |
| 3689 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3690 | goto done; |
| 3691 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3692 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 3693 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3694 | if (rc == -ENOMEM) |
| 3695 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3696 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3697 | done: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3698 | if (cmd && !ul_abort && !cmd->aborted) { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3699 | if (cmd->sg_mapped) |
| 3700 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3701 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3702 | } |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3703 | |
| 3704 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3705 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3706 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3707 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3708 | } |
| 3709 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3710 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
| 3711 | { |
| 3712 | struct list_head free_list; |
| 3713 | struct qla_tgt_cmd *cmd, *tcmd; |
| 3714 | |
| 3715 | vha->hw->tgt.leak_exchg_thresh_hold = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3716 | (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3717 | |
| 3718 | cmd = tcmd = NULL; |
| 3719 | if (!list_empty(&vha->hw->tgt.q_full_list)) { |
| 3720 | INIT_LIST_HEAD(&free_list); |
| 3721 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); |
| 3722 | |
| 3723 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 3724 | list_del(&cmd->cmd_list); |
| 3725 | /* This cmd was never sent to TCM. There is no need |
| 3726 | * to schedule free or call free_cmd |
| 3727 | */ |
| 3728 | qlt_free_cmd(cmd); |
| 3729 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 3730 | } |
| 3731 | } |
| 3732 | vha->hw->tgt.num_qfull_cmds_dropped = 0; |
| 3733 | } |
| 3734 | |
| 3735 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) |
| 3736 | { |
| 3737 | uint32_t total_leaked; |
| 3738 | |
| 3739 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; |
| 3740 | |
| 3741 | if (vha->hw->tgt.leak_exchg_thresh_hold && |
| 3742 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { |
| 3743 | |
| 3744 | ql_dbg(ql_dbg_tgt, vha, 0xe079, |
| 3745 | "Chip reset due to exchange starvation: %d/%d.\n", |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3746 | total_leaked, vha->hw->cur_fw_xcb_count); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3747 | |
| 3748 | if (IS_P3P_TYPE(vha->hw)) |
| 3749 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 3750 | else |
| 3751 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3752 | qla2xxx_wake_dpc(vha); |
| 3753 | } |
| 3754 | |
| 3755 | } |
| 3756 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3757 | int qlt_abort_cmd(struct qla_tgt_cmd *cmd) |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3758 | { |
| 3759 | struct qla_tgt *tgt = cmd->tgt; |
| 3760 | struct scsi_qla_host *vha = tgt->vha; |
| 3761 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3762 | unsigned long flags; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3763 | |
| 3764 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, |
| 3765 | "qla_target(%d): terminating exchange for aborted cmd=%p " |
| 3766 | "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, |
| 3767 | se_cmd->tag); |
| 3768 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3769 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3770 | if (cmd->aborted) { |
| 3771 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3772 | /* |
| 3773 | * It's normal to see 2 calls in this path: |
| 3774 | * 1) XFER Rdy completion + CMD_T_ABORT |
| 3775 | * 2) TCM TMR - drain_state_list |
| 3776 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3777 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016, |
| 3778 | "multiple abort. %p transport_state %x, t_state %x, " |
| 3779 | "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state, |
| 3780 | cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3781 | return EIO; |
| 3782 | } |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3783 | cmd->aborted = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3784 | cmd->trc_flags |= TRC_ABORT; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3785 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3786 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3787 | qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3788 | return 0; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3789 | } |
| 3790 | EXPORT_SYMBOL(qlt_abort_cmd); |
| 3791 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3792 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
| 3793 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3794 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3795 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3796 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
| 3797 | "%s: se_cmd[%p] ox_id %04x\n", |
| 3798 | __func__, &cmd->se_cmd, |
| 3799 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3800 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3801 | BUG_ON(cmd->cmd_in_wq); |
| 3802 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3803 | if (cmd->sg_mapped) |
| 3804 | qlt_unmap_sg(cmd->vha, cmd); |
| 3805 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3806 | if (!cmd->q_full) |
| 3807 | qlt_decr_num_pend_cmds(cmd->vha); |
| 3808 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3809 | BUG_ON(cmd->sg_mapped); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3810 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3811 | if (unlikely(cmd->free_sg)) |
| 3812 | kfree(cmd->sg); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3813 | |
| 3814 | if (!sess || !sess->se_sess) { |
| 3815 | WARN_ON(1); |
| 3816 | return; |
| 3817 | } |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3818 | cmd->jiffies_at_free = get_jiffies_64(); |
Matthew Wilcox | 83c2b54 | 2018-06-12 12:05:43 -0700 | [diff] [blame] | 3819 | target_free_tag(sess->se_sess, &cmd->se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3820 | } |
| 3821 | EXPORT_SYMBOL(qlt_free_cmd); |
| 3822 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3823 | /* |
| 3824 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3825 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3826 | static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3827 | struct qla_tgt_cmd *cmd, uint32_t status) |
| 3828 | { |
| 3829 | int term = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3830 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3831 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3832 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3833 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe013, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3834 | "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] " |
| 3835 | "se_cmd=%p tag[%x] op %#x/%s", |
| 3836 | cmd->lba, cmd->lba, |
| 3837 | cmd->num_blks, &cmd->se_cmd, |
| 3838 | cmd->atio.u.isp24.exchange_addr, |
| 3839 | cmd->se_cmd.prot_op, |
| 3840 | prot_op_str(cmd->se_cmd.prot_op)); |
| 3841 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3842 | if (ctio != NULL) { |
| 3843 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 3844 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3845 | term = !(c->flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3846 | cpu_to_le16(OF_TERM_EXCH)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3847 | } else |
| 3848 | term = 1; |
| 3849 | |
| 3850 | if (term) |
himanshu.madhani@cavium.com | 3efc31f | 2018-01-15 20:46:47 -0800 | [diff] [blame] | 3851 | qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3852 | |
| 3853 | return term; |
| 3854 | } |
| 3855 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3856 | |
| 3857 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 3858 | static void *qlt_ctio_to_cmd(struct scsi_qla_host *vha, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3859 | struct rsp_que *rsp, uint32_t handle, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3860 | { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 3861 | void *cmd = NULL; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3862 | struct req_que *req; |
| 3863 | int qid = GET_QID(handle); |
| 3864 | uint32_t h = handle & ~QLA_TGT_HANDLE_MASK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3865 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3866 | if (unlikely(h == QLA_TGT_SKIP_HANDLE)) |
| 3867 | return NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3868 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3869 | if (qid == rsp->req->id) { |
| 3870 | req = rsp->req; |
| 3871 | } else if (vha->hw->req_q_map[qid]) { |
| 3872 | ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a, |
| 3873 | "qla_target(%d): CTIO completion with different QID %d handle %x\n", |
| 3874 | vha->vp_idx, rsp->id, handle); |
| 3875 | req = vha->hw->req_q_map[qid]; |
| 3876 | } else { |
| 3877 | return NULL; |
| 3878 | } |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3879 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3880 | h &= QLA_CMD_HANDLE_MASK; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3881 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3882 | if (h != QLA_TGT_NULL_HANDLE) { |
Dan Carpenter | fb2028a | 2017-07-10 11:47:40 +0300 | [diff] [blame] | 3883 | if (unlikely(h >= req->num_outstanding_cmds)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3884 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
| 3885 | "qla_target(%d): Wrong handle %x received\n", |
| 3886 | vha->vp_idx, handle); |
| 3887 | return NULL; |
| 3888 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3889 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 3890 | cmd = (void *) req->outstanding_cmds[h]; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3891 | if (unlikely(cmd == NULL)) { |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3892 | ql_dbg(ql_dbg_async, vha, 0xe053, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3893 | "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n", |
| 3894 | vha->vp_idx, handle, req->id, rsp->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3895 | return NULL; |
| 3896 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3897 | req->outstanding_cmds[h] = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3898 | } else if (ctio != NULL) { |
| 3899 | /* We can't get loop ID from CTIO7 */ |
| 3900 | ql_dbg(ql_dbg_tgt, vha, 0xe054, |
| 3901 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " |
| 3902 | "support NULL handles\n", vha->vp_idx); |
| 3903 | return NULL; |
| 3904 | } |
| 3905 | |
| 3906 | return cmd; |
| 3907 | } |
| 3908 | |
| 3909 | /* |
| 3910 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3911 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3912 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, |
| 3913 | struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3914 | { |
| 3915 | struct qla_hw_data *ha = vha->hw; |
| 3916 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3917 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3918 | struct qla_qpair *qpair = rsp->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3919 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3920 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
| 3921 | /* That could happen only in case of an error/reset/abort */ |
| 3922 | if (status != CTIO_SUCCESS) { |
| 3923 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, |
| 3924 | "Intermediate CTIO received" |
| 3925 | " (status %x)\n", status); |
| 3926 | } |
| 3927 | return; |
| 3928 | } |
| 3929 | |
Bart Van Assche | 81bcf1c | 2019-04-11 14:53:24 -0700 | [diff] [blame] | 3930 | cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio); |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3931 | if (cmd == NULL) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3932 | return; |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3933 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3934 | se_cmd = &cmd->se_cmd; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3935 | cmd->cmd_sent_to_fw = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3936 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3937 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3938 | |
| 3939 | if (unlikely(status != CTIO_SUCCESS)) { |
| 3940 | switch (status & 0xFFFF) { |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 3941 | case CTIO_INVALID_RX_ID: |
| 3942 | if (printk_ratelimit()) |
| 3943 | dev_info(&vha->hw->pdev->dev, |
| 3944 | "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n", |
| 3945 | vha->vp_idx, cmd->atio.u.isp24.attr, |
| 3946 | ((cmd->ctio_flags >> 9) & 0xf), |
| 3947 | cmd->ctio_flags); |
| 3948 | |
| 3949 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3950 | case CTIO_LIP_RESET: |
| 3951 | case CTIO_TARGET_RESET: |
| 3952 | case CTIO_ABORTED: |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3953 | /* driver request abort via Terminate exchange */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3954 | case CTIO_TIMEOUT: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3955 | /* They are OK */ |
| 3956 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, |
| 3957 | "qla_target(%d): CTIO with " |
| 3958 | "status %#x received, state %x, se_cmd %p, " |
| 3959 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " |
| 3960 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, |
| 3961 | status, cmd->state, se_cmd); |
| 3962 | break; |
| 3963 | |
| 3964 | case CTIO_PORT_LOGGED_OUT: |
| 3965 | case CTIO_PORT_UNAVAILABLE: |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3966 | { |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3967 | int logged_out = |
| 3968 | (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; |
| 3969 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3970 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3971 | "qla_target(%d): CTIO with %s status %x " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3972 | "received (state %x, se_cmd %p)\n", vha->vp_idx, |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3973 | logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3974 | status, cmd->state, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3975 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3976 | if (logged_out && cmd->sess) { |
| 3977 | /* |
| 3978 | * Session is already logged out, but we need |
| 3979 | * to notify initiator, who's not aware of this |
| 3980 | */ |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3981 | cmd->sess->send_els_logo = 1; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3982 | ql_dbg(ql_dbg_disc, vha, 0x20f8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3983 | "%s %d %8phC post del sess\n", |
| 3984 | __func__, __LINE__, cmd->sess->port_name); |
| 3985 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 3986 | qlt_schedule_sess_for_deletion(cmd->sess); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3987 | } |
| 3988 | break; |
| 3989 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3990 | case CTIO_DIF_ERROR: { |
| 3991 | struct ctio_crc_from_fw *crc = |
| 3992 | (struct ctio_crc_from_fw *)ctio; |
| 3993 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3994 | "qla_target(%d): CTIO with DIF_ERROR status %x " |
| 3995 | "received (state %x, ulp_cmd %p) actual_dif[0x%llx] " |
| 3996 | "expect_dif[0x%llx]\n", |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3997 | vha->vp_idx, status, cmd->state, se_cmd, |
| 3998 | *((u64 *)&crc->actual_dif[0]), |
| 3999 | *((u64 *)&crc->expected_dif[0])); |
| 4000 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 4001 | qlt_handle_dif_error(qpair, cmd, ctio); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 4002 | return; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4003 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4004 | default: |
| 4005 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4006 | "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] | 4007 | vha->vp_idx, status, cmd->state, se_cmd); |
| 4008 | break; |
| 4009 | } |
| 4010 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4011 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4012 | /* "cmd->aborted" means |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4013 | * cmd is already aborted/terminated, we don't |
| 4014 | * need to terminate again. The exchange is already |
| 4015 | * cleaned up/freed at FW level. Just cleanup at driver |
| 4016 | * level. |
| 4017 | */ |
| 4018 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4019 | (!cmd->aborted)) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4020 | cmd->trc_flags |= TRC_CTIO_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4021 | if (qlt_term_ctio_exchange(qpair, ctio, cmd, status)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4022 | return; |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4023 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4024 | } |
| 4025 | |
| 4026 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4027 | cmd->trc_flags |= TRC_CTIO_DONE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4028 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4029 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 4030 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4031 | if (status == CTIO_SUCCESS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4032 | cmd->write_data_transferred = 1; |
| 4033 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4034 | ha->tgt.tgt_ops->handle_data(cmd); |
| 4035 | return; |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4036 | } else if (cmd->aborted) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4037 | cmd->trc_flags |= TRC_CTIO_ABORTED; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4038 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4039 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4040 | } else { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4041 | cmd->trc_flags |= TRC_CTIO_STRANGE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4042 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
| 4043 | "qla_target(%d): A command in state (%d) should " |
| 4044 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); |
| 4045 | } |
| 4046 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4047 | if (unlikely(status != CTIO_SUCCESS) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4048 | !cmd->aborted) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4049 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
| 4050 | dump_stack(); |
| 4051 | } |
| 4052 | |
| 4053 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 4054 | } |
| 4055 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4056 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
| 4057 | uint8_t task_codes) |
| 4058 | { |
| 4059 | int fcp_task_attr; |
| 4060 | |
| 4061 | switch (task_codes) { |
| 4062 | case ATIO_SIMPLE_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4063 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4064 | break; |
| 4065 | case ATIO_HEAD_OF_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4066 | fcp_task_attr = TCM_HEAD_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4067 | break; |
| 4068 | case ATIO_ORDERED_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4069 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4070 | break; |
| 4071 | case ATIO_ACA_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4072 | fcp_task_attr = TCM_ACA_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4073 | break; |
| 4074 | case ATIO_UNTAGGED: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4075 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4076 | break; |
| 4077 | default: |
| 4078 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, |
| 4079 | "qla_target: unknown task code %x, use ORDERED instead\n", |
| 4080 | task_codes); |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4081 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4082 | break; |
| 4083 | } |
| 4084 | |
| 4085 | return fcp_task_attr; |
| 4086 | } |
| 4087 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4088 | /* |
| 4089 | * Process context for I/O path into tcm_qla2xxx code |
| 4090 | */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4091 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4092 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4093 | scsi_qla_host_t *vha = cmd->vha; |
| 4094 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4095 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4096 | struct atio_from_isp *atio = &cmd->atio; |
| 4097 | unsigned char *cdb; |
| 4098 | unsigned long flags; |
| 4099 | uint32_t data_length; |
| 4100 | int ret, fcp_task_attr, data_dir, bidi = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4101 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4102 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4103 | cmd->cmd_in_wq = 0; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4104 | cmd->trc_flags |= TRC_DO_WORK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4105 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4106 | if (cmd->aborted) { |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4107 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082, |
| 4108 | "cmd with tag %u is aborted\n", |
| 4109 | cmd->atio.u.isp24.exchange_addr); |
| 4110 | goto out_term; |
| 4111 | } |
| 4112 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4113 | spin_lock_init(&cmd->cmd_lock); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4114 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4115 | cmd->se_cmd.tag = atio->u.isp24.exchange_addr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4116 | |
| 4117 | if (atio->u.isp24.fcp_cmnd.rddata && |
| 4118 | atio->u.isp24.fcp_cmnd.wrdata) { |
| 4119 | bidi = 1; |
| 4120 | data_dir = DMA_TO_DEVICE; |
| 4121 | } else if (atio->u.isp24.fcp_cmnd.rddata) |
| 4122 | data_dir = DMA_FROM_DEVICE; |
| 4123 | else if (atio->u.isp24.fcp_cmnd.wrdata) |
| 4124 | data_dir = DMA_TO_DEVICE; |
| 4125 | else |
| 4126 | data_dir = DMA_NONE; |
| 4127 | |
| 4128 | fcp_task_attr = qlt_get_fcp_task_attr(vha, |
| 4129 | atio->u.isp24.fcp_cmnd.task_attr); |
Quinn Tran | e25f765 | 2018-05-01 09:01:50 -0700 | [diff] [blame] | 4130 | data_length = get_datalen_for_atio(atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4131 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4132 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
| 4133 | fcp_task_attr, data_dir, bidi); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4134 | if (ret != 0) |
| 4135 | goto out_term; |
| 4136 | /* |
Bart Van Assche | 67eb4a60 | 2019-04-17 14:44:10 -0700 | [diff] [blame] | 4137 | * Drop extra session reference from qlt_handle_cmd_for_atio(). |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4138 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4139 | ha->tgt.tgt_ops->put_sess(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4140 | return; |
| 4141 | |
| 4142 | out_term: |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4143 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4144 | /* |
Roland Dreier | fae9eaf | 2012-06-11 18:23:16 -0700 | [diff] [blame] | 4145 | * cmd has not sent to target yet, so pass NULL as the second |
| 4146 | * argument to qlt_send_term_exchange() and free the memory here. |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4147 | */ |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4148 | cmd->trc_flags |= TRC_DO_WORK_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4149 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 4150 | qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4151 | |
| 4152 | qlt_decr_num_pend_cmds(vha); |
Matthew Wilcox | 83c2b54 | 2018-06-12 12:05:43 -0700 | [diff] [blame] | 4153 | target_free_tag(sess->se_sess, &cmd->se_cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4154 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4155 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4156 | ha->tgt.tgt_ops->put_sess(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4157 | } |
| 4158 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4159 | static void qlt_do_work(struct work_struct *work) |
| 4160 | { |
| 4161 | 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] | 4162 | scsi_qla_host_t *vha = cmd->vha; |
| 4163 | unsigned long flags; |
| 4164 | |
| 4165 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4166 | list_del(&cmd->cmd_list); |
| 4167 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4168 | |
| 4169 | __qlt_do_work(cmd); |
| 4170 | } |
| 4171 | |
Quinn Tran | 09620ee | 2017-06-13 20:47:20 -0700 | [diff] [blame] | 4172 | void qlt_clr_qp_table(struct scsi_qla_host *vha) |
| 4173 | { |
| 4174 | unsigned long flags; |
| 4175 | struct qla_hw_data *ha = vha->hw; |
| 4176 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4177 | void *node; |
| 4178 | u64 key = 0; |
| 4179 | |
| 4180 | ql_log(ql_log_info, vha, 0x706c, |
| 4181 | "User update Number of Active Qpairs %d\n", |
| 4182 | ha->tgt.num_act_qpairs); |
| 4183 | |
| 4184 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 4185 | |
| 4186 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 4187 | btree_remove64(&tgt->lun_qpair_map, key); |
| 4188 | |
| 4189 | ha->base_qpair->lun_cnt = 0; |
| 4190 | for (key = 0; key < ha->max_qpairs; key++) |
| 4191 | if (ha->queue_pair_map[key]) |
| 4192 | ha->queue_pair_map[key]->lun_cnt = 0; |
| 4193 | |
| 4194 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 4195 | } |
| 4196 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4197 | static void qlt_assign_qpair(struct scsi_qla_host *vha, |
| 4198 | struct qla_tgt_cmd *cmd) |
| 4199 | { |
| 4200 | struct qla_qpair *qpair, *qp; |
| 4201 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4202 | struct qla_qpair_hint *h; |
| 4203 | |
| 4204 | if (vha->flags.qpairs_available) { |
| 4205 | h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun); |
| 4206 | if (unlikely(!h)) { |
| 4207 | /* spread lun to qpair ratio evently */ |
| 4208 | int lcnt = 0, rc; |
| 4209 | struct scsi_qla_host *base_vha = |
| 4210 | pci_get_drvdata(vha->hw->pdev); |
| 4211 | |
| 4212 | qpair = vha->hw->base_qpair; |
| 4213 | if (qpair->lun_cnt == 0) { |
| 4214 | qpair->lun_cnt++; |
| 4215 | h = qla_qpair_to_hint(tgt, qpair); |
| 4216 | BUG_ON(!h); |
| 4217 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4218 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4219 | if (rc) { |
| 4220 | qpair->lun_cnt--; |
| 4221 | ql_log(ql_log_info, vha, 0xd037, |
| 4222 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4223 | cmd->unpacked_lun); |
| 4224 | } |
| 4225 | goto out; |
| 4226 | } else { |
| 4227 | lcnt = qpair->lun_cnt; |
| 4228 | } |
| 4229 | |
| 4230 | h = NULL; |
| 4231 | list_for_each_entry(qp, &base_vha->qp_list, |
| 4232 | qp_list_elem) { |
| 4233 | if (qp->lun_cnt == 0) { |
| 4234 | qp->lun_cnt++; |
| 4235 | h = qla_qpair_to_hint(tgt, qp); |
| 4236 | BUG_ON(!h); |
| 4237 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4238 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4239 | if (rc) { |
| 4240 | qp->lun_cnt--; |
| 4241 | ql_log(ql_log_info, vha, 0xd038, |
| 4242 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4243 | cmd->unpacked_lun); |
| 4244 | } |
| 4245 | qpair = qp; |
| 4246 | goto out; |
| 4247 | } else { |
| 4248 | if (qp->lun_cnt < lcnt) { |
| 4249 | lcnt = qp->lun_cnt; |
| 4250 | qpair = qp; |
| 4251 | continue; |
| 4252 | } |
| 4253 | } |
| 4254 | } |
| 4255 | BUG_ON(!qpair); |
| 4256 | qpair->lun_cnt++; |
| 4257 | h = qla_qpair_to_hint(tgt, qpair); |
| 4258 | BUG_ON(!h); |
| 4259 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4260 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4261 | if (rc) { |
| 4262 | qpair->lun_cnt--; |
| 4263 | ql_log(ql_log_info, vha, 0xd039, |
| 4264 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4265 | cmd->unpacked_lun); |
| 4266 | } |
| 4267 | } |
| 4268 | } else { |
| 4269 | h = &tgt->qphints[0]; |
| 4270 | } |
| 4271 | out: |
| 4272 | cmd->qpair = h->qpair; |
| 4273 | cmd->se_cmd.cpuid = h->cpuid; |
| 4274 | } |
| 4275 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4276 | static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4277 | struct fc_port *sess, |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4278 | struct atio_from_isp *atio) |
| 4279 | { |
| 4280 | struct se_session *se_sess = sess->se_sess; |
| 4281 | struct qla_tgt_cmd *cmd; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 4282 | int tag, cpu; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4283 | |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 4284 | tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4285 | if (tag < 0) |
| 4286 | return NULL; |
| 4287 | |
| 4288 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 4289 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 4290 | cmd->cmd_type = TYPE_TGT_CMD; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4291 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 4292 | cmd->state = QLA_TGT_STATE_NEW; |
| 4293 | cmd->tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4294 | qlt_incr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4295 | cmd->vha = vha; |
| 4296 | cmd->se_cmd.map_tag = tag; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 4297 | cmd->se_cmd.map_cpu = cpu; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4298 | cmd->sess = sess; |
| 4299 | cmd->loop_id = sess->loop_id; |
| 4300 | cmd->conf_compl_supported = sess->conf_compl_supported; |
| 4301 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4302 | cmd->trc_flags = 0; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4303 | cmd->jiffies_at_alloc = get_jiffies_64(); |
| 4304 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4305 | cmd->unpacked_lun = scsilun_to_int( |
| 4306 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); |
| 4307 | qlt_assign_qpair(vha, cmd); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4308 | cmd->reset_count = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 4309 | cmd->vp_idx = vha->vp_idx; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4310 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4311 | return cmd; |
| 4312 | } |
| 4313 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4314 | /* ha->hardware_lock supposed to be held on entry */ |
| 4315 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, |
| 4316 | struct atio_from_isp *atio) |
| 4317 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4318 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4319 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4320 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4321 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4322 | unsigned long flags; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4323 | port_id_t id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4324 | |
| 4325 | if (unlikely(tgt->tgt_stop)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4326 | ql_dbg(ql_dbg_io, vha, 0x3061, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4327 | "New command while device %p is shutting down\n", tgt); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 4328 | return -ENODEV; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4329 | } |
| 4330 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 4331 | id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4332 | if (IS_SW_RESV_ADDR(id)) |
| 4333 | return -EBUSY; |
| 4334 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4335 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [diff] [blame] | 4336 | if (unlikely(!sess)) |
| 4337 | return -EFAULT; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4338 | |
| 4339 | /* Another WWN used to have our s_id. Our PLOGI scheduled its |
| 4340 | * session deletion, but it's still in sess_del_work wq */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4341 | if (sess->deleted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4342 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002, |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4343 | "New command while old session %p is being deleted\n", |
| 4344 | sess); |
| 4345 | return -EFAULT; |
| 4346 | } |
| 4347 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4348 | /* |
| 4349 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. |
| 4350 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4351 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4352 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4353 | "%s: kref_get fail, %8phC oxid %x \n", |
| 4354 | __func__, sess->port_name, |
| 4355 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 4356 | return -EFAULT; |
| 4357 | } |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4358 | |
| 4359 | cmd = qlt_get_tag(vha, sess, atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4360 | if (!cmd) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4361 | ql_dbg(ql_dbg_io, vha, 0x3062, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4362 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4363 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 4364 | return -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4365 | } |
| 4366 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4367 | cmd->cmd_in_wq = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4368 | cmd->trc_flags |= TRC_NEW_CMD; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4369 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4370 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4371 | list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4372 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4373 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4374 | INIT_WORK(&cmd->work, qlt_do_work); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4375 | if (vha->flags.qpairs_available) { |
| 4376 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work); |
| 4377 | } else if (ha->msix_count) { |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4378 | if (cmd->atio.u.isp24.fcp_cmnd.rddata) |
| 4379 | queue_work_on(smp_processor_id(), qla_tgt_wq, |
| 4380 | &cmd->work); |
| 4381 | else |
| 4382 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, |
| 4383 | &cmd->work); |
| 4384 | } else { |
| 4385 | queue_work(qla_tgt_wq, &cmd->work); |
| 4386 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4387 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4388 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4392 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4393 | int fn, void *iocb, int flags) |
| 4394 | { |
| 4395 | struct scsi_qla_host *vha = sess->vha; |
| 4396 | struct qla_hw_data *ha = vha->hw; |
| 4397 | struct qla_tgt_mgmt_cmd *mcmd; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4398 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4399 | struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4400 | |
| 4401 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4402 | if (!mcmd) { |
| 4403 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, |
| 4404 | "qla_target(%d): Allocation of management " |
| 4405 | "command failed, some commands and their data could " |
| 4406 | "leak\n", vha->vp_idx); |
| 4407 | return -ENOMEM; |
| 4408 | } |
| 4409 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4410 | mcmd->sess = sess; |
| 4411 | |
| 4412 | if (iocb) { |
| 4413 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4414 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4415 | } |
| 4416 | mcmd->tmr_func = fn; |
| 4417 | mcmd->flags = flags; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4418 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4419 | mcmd->qpair = h->qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 4420 | mcmd->vha = vha; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4421 | mcmd->se_cmd.cpuid = h->cpuid; |
| 4422 | mcmd->unpacked_lun = lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4423 | |
| 4424 | switch (fn) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4425 | case QLA_TGT_LUN_RESET: |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4426 | case QLA_TGT_CLEAR_TS: |
| 4427 | case QLA_TGT_ABORT_TS: |
| 4428 | abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id); |
Bart Van Assche | 50435d4 | 2018-10-18 15:45:40 -0700 | [diff] [blame] | 4429 | /* fall through */ |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4430 | case QLA_TGT_CLEAR_ACA: |
| 4431 | h = qlt_find_qphint(vha, mcmd->unpacked_lun); |
| 4432 | mcmd->qpair = h->qpair; |
| 4433 | mcmd->se_cmd.cpuid = h->cpuid; |
| 4434 | break; |
| 4435 | |
| 4436 | case QLA_TGT_TARGET_RESET: |
| 4437 | case QLA_TGT_NEXUS_LOSS_SESS: |
| 4438 | case QLA_TGT_NEXUS_LOSS: |
| 4439 | case QLA_TGT_ABORT_ALL: |
| 4440 | default: |
| 4441 | /* no-op */ |
| 4442 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4443 | } |
| 4444 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4445 | INIT_WORK(&mcmd->work, qlt_do_tmr_work); |
| 4446 | queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, |
| 4447 | &mcmd->work); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4448 | |
| 4449 | return 0; |
| 4450 | } |
| 4451 | |
| 4452 | /* ha->hardware_lock supposed to be held on entry */ |
| 4453 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) |
| 4454 | { |
| 4455 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4456 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4457 | struct fc_port *sess; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4458 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4459 | int fn; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4460 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4461 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4462 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4463 | |
| 4464 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4465 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4466 | a->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4467 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4468 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4469 | unpacked_lun = |
| 4470 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4471 | |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [diff] [blame] | 4472 | if (sess == NULL || sess->deleted) |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4473 | return -EFAULT; |
| 4474 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4475 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 4476 | } |
| 4477 | |
| 4478 | /* ha->hardware_lock supposed to be held on entry */ |
| 4479 | static int __qlt_abort_task(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4480 | struct imm_ntfy_from_isp *iocb, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4481 | { |
| 4482 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4483 | struct qla_hw_data *ha = vha->hw; |
| 4484 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4485 | u64 unpacked_lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4486 | int rc; |
| 4487 | |
| 4488 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4489 | if (mcmd == NULL) { |
| 4490 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, |
| 4491 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", |
| 4492 | vha->vp_idx, __func__); |
| 4493 | return -ENOMEM; |
| 4494 | } |
| 4495 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4496 | |
| 4497 | mcmd->sess = sess; |
| 4498 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4499 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4500 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4501 | unpacked_lun = |
| 4502 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4503 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4504 | mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4505 | mcmd->qpair = ha->base_qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4506 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4507 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, unpacked_lun, mcmd->tmr_func, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4508 | le16_to_cpu(iocb->u.isp2x.seq_id)); |
| 4509 | if (rc != 0) { |
| 4510 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, |
| 4511 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 4512 | vha->vp_idx, rc); |
| 4513 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4514 | return -EFAULT; |
| 4515 | } |
| 4516 | |
| 4517 | return 0; |
| 4518 | } |
| 4519 | |
| 4520 | /* ha->hardware_lock supposed to be held on entry */ |
| 4521 | static int qlt_abort_task(struct scsi_qla_host *vha, |
| 4522 | struct imm_ntfy_from_isp *iocb) |
| 4523 | { |
| 4524 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4525 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4526 | int loop_id; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4527 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4528 | |
| 4529 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); |
| 4530 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4531 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4532 | 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] | 4533 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4534 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4535 | if (sess == NULL) { |
| 4536 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, |
| 4537 | "qla_target(%d): task abort for unexisting " |
| 4538 | "session\n", vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4539 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4540 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
| 4541 | } |
| 4542 | |
| 4543 | return __qlt_abort_task(vha, iocb, sess); |
| 4544 | } |
| 4545 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4546 | void qlt_logo_completion_handler(fc_port_t *fcport, int rc) |
| 4547 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4548 | if (rc != MBS_COMMAND_COMPLETE) { |
| 4549 | ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093, |
| 4550 | "%s: se_sess %p / sess %p from" |
| 4551 | " port %8phC loop_id %#04x s_id %02x:%02x:%02x" |
| 4552 | " LOGO failed: %#x\n", |
| 4553 | __func__, |
| 4554 | fcport->se_sess, |
| 4555 | fcport, |
| 4556 | fcport->port_name, fcport->loop_id, |
| 4557 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4558 | fcport->d_id.b.al_pa, rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4559 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4560 | |
| 4561 | fcport->logout_completed = 1; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4562 | } |
| 4563 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4564 | /* |
| 4565 | * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) |
| 4566 | * |
| 4567 | * Schedules sessions with matching port_id/loop_id but different wwn for |
| 4568 | * deletion. Returns existing session with matching wwn if present. |
| 4569 | * Null otherwise. |
| 4570 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4571 | struct fc_port * |
| 4572 | qlt_find_sess_invalidate_other(scsi_qla_host_t *vha, uint64_t wwn, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4573 | port_id_t port_id, uint16_t loop_id, struct fc_port **conflict_sess) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4574 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4575 | struct fc_port *sess = NULL, *other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4576 | uint64_t other_wwn; |
| 4577 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4578 | *conflict_sess = NULL; |
| 4579 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4580 | list_for_each_entry(other_sess, &vha->vp_fcports, list) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4581 | |
| 4582 | other_wwn = wwn_to_u64(other_sess->port_name); |
| 4583 | |
| 4584 | if (wwn == other_wwn) { |
| 4585 | WARN_ON(sess); |
| 4586 | sess = other_sess; |
| 4587 | continue; |
| 4588 | } |
| 4589 | |
| 4590 | /* find other sess with nport_id collision */ |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4591 | if (port_id.b24 == other_sess->d_id.b24) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4592 | if (loop_id != other_sess->loop_id) { |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame^] | 4593 | ql_dbg(ql_dbg_disc, vha, 0x1000c, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4594 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4595 | other_sess, other_sess->loop_id, other_wwn); |
| 4596 | |
| 4597 | /* |
| 4598 | * logout_on_delete is set by default, but another |
| 4599 | * session that has the same s_id/loop_id combo |
| 4600 | * might have cleared it when requested this session |
| 4601 | * deletion, so don't touch it |
| 4602 | */ |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4603 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4604 | } else { |
| 4605 | /* |
| 4606 | * Another wwn used to have our s_id/loop_id |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4607 | * kill the session, but don't free the loop_id |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4608 | */ |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame^] | 4609 | ql_dbg(ql_dbg_disc, vha, 0xf01b, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4610 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4611 | other_sess, other_sess->loop_id, other_wwn); |
| 4612 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4613 | other_sess->keep_nport_handle = 1; |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 4614 | if (other_sess->disc_state != DSC_DELETED) |
| 4615 | *conflict_sess = other_sess; |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4616 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4617 | } |
| 4618 | continue; |
| 4619 | } |
| 4620 | |
| 4621 | /* find other sess with nport handle collision */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4622 | if ((loop_id == other_sess->loop_id) && |
| 4623 | (loop_id != FC_NO_LOOP_ID)) { |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame^] | 4624 | ql_dbg(ql_dbg_disc, vha, 0x1000d, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4625 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4626 | other_sess, other_sess->loop_id, other_wwn); |
| 4627 | |
| 4628 | /* Same loop_id but different s_id |
| 4629 | * Ok to kill and logout */ |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4630 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4631 | } |
| 4632 | } |
| 4633 | |
| 4634 | return sess; |
| 4635 | } |
| 4636 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4637 | /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */ |
| 4638 | static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id) |
| 4639 | { |
| 4640 | struct qla_tgt_sess_op *op; |
| 4641 | struct qla_tgt_cmd *cmd; |
| 4642 | uint32_t key; |
| 4643 | int count = 0; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4644 | unsigned long flags; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4645 | |
| 4646 | key = (((u32)s_id->b.domain << 16) | |
| 4647 | ((u32)s_id->b.area << 8) | |
| 4648 | ((u32)s_id->b.al_pa)); |
| 4649 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4650 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4651 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 4652 | uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4653 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4654 | if (op_key == key) { |
| 4655 | op->aborted = true; |
| 4656 | count++; |
| 4657 | } |
| 4658 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4659 | |
| 4660 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 4661 | uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 4662 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4663 | if (op_key == key) { |
| 4664 | op->aborted = true; |
| 4665 | count++; |
| 4666 | } |
| 4667 | } |
| 4668 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4669 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 4670 | uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 4671 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4672 | if (cmd_key == key) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4673 | cmd->aborted = 1; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4674 | count++; |
| 4675 | } |
| 4676 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4677 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4678 | |
| 4679 | return count; |
| 4680 | } |
| 4681 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4682 | static int qlt_handle_login(struct scsi_qla_host *vha, |
| 4683 | struct imm_ntfy_from_isp *iocb) |
| 4684 | { |
| 4685 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
| 4686 | uint64_t wwn; |
| 4687 | port_id_t port_id; |
| 4688 | uint16_t loop_id, wd3_lo; |
| 4689 | int res = 0; |
| 4690 | struct qlt_plogi_ack_t *pla; |
| 4691 | unsigned long flags; |
| 4692 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 4693 | lockdep_assert_held(&vha->hw->hardware_lock); |
| 4694 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4695 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4696 | |
| 4697 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4698 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4699 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4700 | port_id.b.rsvd_1 = 0; |
| 4701 | |
| 4702 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4703 | |
| 4704 | /* Mark all stale commands sitting in qla_tgt_wq for deletion */ |
| 4705 | abort_cmds_for_s_id(vha, &port_id); |
| 4706 | |
| 4707 | if (wwn) { |
| 4708 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 4709 | sess = qlt_find_sess_invalidate_other(vha, wwn, |
| 4710 | port_id, loop_id, &conflict_sess); |
| 4711 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | aa9e6d7 | 2018-08-31 11:24:38 -0700 | [diff] [blame] | 4712 | } else { |
| 4713 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4714 | "%s %d Term INOT due to WWN=0 lid=%d, NportID %06X ", |
| 4715 | __func__, __LINE__, loop_id, port_id.b24); |
| 4716 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4717 | goto out; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | if (IS_SW_RESV_ADDR(port_id)) { |
| 4721 | res = 1; |
| 4722 | goto out; |
| 4723 | } |
| 4724 | |
| 4725 | pla = qlt_plogi_ack_find_add(vha, &port_id, iocb); |
| 4726 | if (!pla) { |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 4727 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
| 4728 | "%s %d %8phC Term INOT due to mem alloc fail", |
| 4729 | __func__, __LINE__, |
| 4730 | iocb->u.isp24.port_name); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4731 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4732 | goto out; |
| 4733 | } |
| 4734 | |
| 4735 | if (conflict_sess) { |
| 4736 | conflict_sess->login_gen++; |
| 4737 | qlt_plogi_ack_link(vha, pla, conflict_sess, |
| 4738 | QLT_PLOGI_LINK_CONFLICT); |
| 4739 | } |
| 4740 | |
| 4741 | if (!sess) { |
| 4742 | pla->ref_count++; |
| 4743 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4744 | "%s %d %8phC post new sess\n", |
| 4745 | __func__, __LINE__, iocb->u.isp24.port_name); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4746 | if (iocb->u.isp24.status_subcode == ELS_PLOGI) |
| 4747 | qla24xx_post_newsess_work(vha, &port_id, |
| 4748 | iocb->u.isp24.port_name, |
| 4749 | iocb->u.isp24.u.plogi.node_name, |
| 4750 | pla, FC4_TYPE_UNKNOWN); |
| 4751 | else |
| 4752 | qla24xx_post_newsess_work(vha, &port_id, |
| 4753 | iocb->u.isp24.port_name, NULL, |
| 4754 | pla, FC4_TYPE_UNKNOWN); |
| 4755 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4756 | goto out; |
| 4757 | } |
| 4758 | |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4759 | if (sess->disc_state == DSC_UPD_FCPORT) { |
| 4760 | u16 sec; |
| 4761 | |
| 4762 | /* |
| 4763 | * Remote port registration is still going on from |
| 4764 | * previous login. Allow it to finish before we |
| 4765 | * accept the new login. |
| 4766 | */ |
| 4767 | sess->next_disc_state = DSC_DELETE_PEND; |
| 4768 | sec = jiffies_to_msecs(jiffies - |
| 4769 | sess->jiffies_at_registration) / 1000; |
| 4770 | if (sess->sec_since_registration < sec && sec && |
| 4771 | !(sec % 5)) { |
| 4772 | sess->sec_since_registration = sec; |
| 4773 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4774 | "%s %8phC - Slow Rport registration (%d Sec)\n", |
| 4775 | __func__, sess->port_name, sec); |
| 4776 | } |
| 4777 | |
Bart Van Assche | 1df627b | 2019-08-08 20:01:42 -0700 | [diff] [blame] | 4778 | if (!conflict_sess) { |
| 4779 | list_del(&pla->list); |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4780 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
Bart Van Assche | 1df627b | 2019-08-08 20:01:42 -0700 | [diff] [blame] | 4781 | } |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4782 | |
| 4783 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4784 | goto out; |
| 4785 | } |
| 4786 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4787 | qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN); |
| 4788 | sess->d_id = port_id; |
| 4789 | sess->login_gen++; |
| 4790 | |
| 4791 | if (iocb->u.isp24.status_subcode == ELS_PRLI) { |
| 4792 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
| 4793 | sess->local = 0; |
| 4794 | sess->loop_id = loop_id; |
| 4795 | sess->d_id = port_id; |
| 4796 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
| 4797 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4798 | |
| 4799 | if (wd3_lo & BIT_7) |
| 4800 | sess->conf_compl_supported = 1; |
| 4801 | |
| 4802 | if ((wd3_lo & BIT_4) == 0) |
| 4803 | sess->port_type = FCT_INITIATOR; |
| 4804 | else |
| 4805 | sess->port_type = FCT_TARGET; |
| 4806 | |
| 4807 | } else |
| 4808 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
| 4809 | |
| 4810 | |
| 4811 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4812 | "%s %d %8phC DS %d\n", |
| 4813 | __func__, __LINE__, sess->port_name, sess->disc_state); |
| 4814 | |
| 4815 | switch (sess->disc_state) { |
| 4816 | case DSC_DELETED: |
Roman Bolshakov | 5e6b01d | 2019-11-25 19:56:59 +0300 | [diff] [blame] | 4817 | case DSC_LOGIN_PEND: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4818 | qlt_plogi_ack_unref(vha, pla); |
| 4819 | break; |
| 4820 | |
| 4821 | default: |
| 4822 | /* |
| 4823 | * Under normal circumstances we want to release nport handle |
| 4824 | * during LOGO process to avoid nport handle leaks inside FW. |
| 4825 | * The exception is when LOGO is done while another PLOGI with |
| 4826 | * the same nport handle is waiting as might be the case here. |
| 4827 | * Note: there is always a possibily of a race where session |
| 4828 | * deletion has already started for other reasons (e.g. ACL |
| 4829 | * removal) and now PLOGI arrives: |
| 4830 | * 1. if PLOGI arrived in FW after nport handle has been freed, |
| 4831 | * FW must have assigned this PLOGI a new/same handle and we |
| 4832 | * can proceed ACK'ing it as usual when session deletion |
| 4833 | * completes. |
| 4834 | * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT |
| 4835 | * bit reached it, the handle has now been released. We'll |
| 4836 | * get an error when we ACK this PLOGI. Nothing will be sent |
| 4837 | * back to initiator. Initiator should eventually retry |
| 4838 | * PLOGI and situation will correct itself. |
| 4839 | */ |
| 4840 | sess->keep_nport_handle = ((sess->loop_id == loop_id) && |
| 4841 | (sess->d_id.b24 == port_id.b24)); |
| 4842 | |
| 4843 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4844 | "%s %d %8phC post del sess\n", |
| 4845 | __func__, __LINE__, sess->port_name); |
| 4846 | |
| 4847 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 4848 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4849 | break; |
| 4850 | } |
| 4851 | out: |
| 4852 | return res; |
| 4853 | } |
| 4854 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4855 | /* |
| 4856 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4857 | */ |
| 4858 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, |
| 4859 | struct imm_ntfy_from_isp *iocb) |
| 4860 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4861 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4862 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4863 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4864 | uint64_t wwn; |
| 4865 | port_id_t port_id; |
| 4866 | uint16_t loop_id; |
| 4867 | uint16_t wd3_lo; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4868 | int res = 0; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4869 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4870 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 4871 | lockdep_assert_held(&ha->hardware_lock); |
| 4872 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4873 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4874 | |
| 4875 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4876 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4877 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4878 | port_id.b.rsvd_1 = 0; |
| 4879 | |
| 4880 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4881 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4882 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 4883 | "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n", |
| 4884 | vha->vp_idx, iocb->u.isp24.port_id[2], |
| 4885 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 4886 | iocb->u.isp24.status_subcode, loop_id, |
| 4887 | iocb->u.isp24.port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4888 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4889 | /* res = 1 means ack at the end of thread |
| 4890 | * res = 0 means ack async/later. |
| 4891 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4892 | switch (iocb->u.isp24.status_subcode) { |
| 4893 | case ELS_PLOGI: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4894 | res = qlt_handle_login(vha, iocb); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4895 | break; |
| 4896 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4897 | case ELS_PRLI: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4898 | if (N2N_TOPO(ha)) { |
| 4899 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 4900 | iocb->u.isp24.port_name, 1); |
| 4901 | |
| 4902 | if (sess && sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]) { |
| 4903 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4904 | "%s %d %8phC Term PRLI due to PLOGI ACK not completed\n", |
| 4905 | __func__, __LINE__, |
| 4906 | iocb->u.isp24.port_name); |
| 4907 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4908 | break; |
| 4909 | } |
| 4910 | |
| 4911 | res = qlt_handle_login(vha, iocb); |
| 4912 | break; |
| 4913 | } |
| 4914 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4915 | if (IS_SW_RESV_ADDR(port_id)) { |
| 4916 | res = 1; |
| 4917 | break; |
| 4918 | } |
| 4919 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4920 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4921 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4922 | if (wwn) { |
| 4923 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4924 | sess = qlt_find_sess_invalidate_other(vha, wwn, port_id, |
| 4925 | loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4926 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4927 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4928 | |
| 4929 | if (conflict_sess) { |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 4930 | switch (conflict_sess->disc_state) { |
| 4931 | case DSC_DELETED: |
| 4932 | case DSC_DELETE_PEND: |
| 4933 | break; |
| 4934 | default: |
| 4935 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b, |
| 4936 | "PRLI with conflicting sess %p port %8phC\n", |
| 4937 | conflict_sess, conflict_sess->port_name); |
| 4938 | conflict_sess->fw_login_state = |
| 4939 | DSC_LS_PORT_UNAVAIL; |
| 4940 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4941 | res = 0; |
| 4942 | break; |
| 4943 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4944 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4945 | |
| 4946 | if (sess != NULL) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4947 | bool delete = false; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4948 | int sec; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 4949 | |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4950 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
| 4951 | switch (sess->fw_login_state) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4952 | case DSC_LS_PLOGI_PEND: |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4953 | case DSC_LS_PLOGI_COMP: |
| 4954 | case DSC_LS_PRLI_COMP: |
| 4955 | break; |
| 4956 | default: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4957 | delete = true; |
| 4958 | break; |
| 4959 | } |
| 4960 | |
| 4961 | switch (sess->disc_state) { |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4962 | case DSC_UPD_FCPORT: |
| 4963 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, |
| 4964 | flags); |
| 4965 | |
| 4966 | sec = jiffies_to_msecs(jiffies - |
| 4967 | sess->jiffies_at_registration)/1000; |
| 4968 | if (sess->sec_since_registration < sec && sec && |
| 4969 | !(sec % 5)) { |
| 4970 | sess->sec_since_registration = sec; |
| 4971 | ql_dbg(ql_dbg_disc, sess->vha, 0xffff, |
| 4972 | "%s %8phC : Slow Rport registration(%d Sec)\n", |
| 4973 | __func__, sess->port_name, sec); |
| 4974 | } |
| 4975 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4976 | return 0; |
| 4977 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4978 | case DSC_LOGIN_PEND: |
| 4979 | case DSC_GPDB: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4980 | case DSC_LOGIN_COMPLETE: |
| 4981 | case DSC_ADISC: |
| 4982 | delete = false; |
| 4983 | break; |
| 4984 | default: |
| 4985 | break; |
| 4986 | } |
| 4987 | |
| 4988 | if (delete) { |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4989 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, |
| 4990 | flags); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4991 | /* |
| 4992 | * Impatient initiator sent PRLI before last |
| 4993 | * PLOGI could finish. Will force him to re-try, |
| 4994 | * while last one finishes. |
| 4995 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4996 | ql_log(ql_log_warn, sess->vha, 0xf095, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4997 | "sess %p PRLI received, before plogi ack.\n", |
| 4998 | sess); |
| 4999 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 5000 | res = 0; |
| 5001 | break; |
| 5002 | } |
| 5003 | |
| 5004 | /* |
| 5005 | * This shouldn't happen under normal circumstances, |
| 5006 | * since we have deleted the old session during PLOGI |
| 5007 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5008 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5009 | "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n", |
| 5010 | sess->loop_id, sess, iocb->u.isp24.nport_handle); |
| 5011 | |
| 5012 | sess->local = 0; |
| 5013 | sess->loop_id = loop_id; |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 5014 | sess->d_id = port_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5015 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5016 | |
| 5017 | if (wd3_lo & BIT_7) |
| 5018 | sess->conf_compl_supported = 1; |
| 5019 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5020 | if ((wd3_lo & BIT_4) == 0) |
| 5021 | sess->port_type = FCT_INITIATOR; |
| 5022 | else |
| 5023 | sess->port_type = FCT_TARGET; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 5024 | |
| 5025 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5026 | } |
| 5027 | res = 1; /* send notify ack */ |
| 5028 | |
| 5029 | /* Make session global (not used in fabric mode) */ |
| 5030 | if (ha->current_topology != ISP_CFG_F) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5031 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5032 | ql_dbg(ql_dbg_disc, vha, 0x20fa, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5033 | "%s %d %8phC post nack\n", |
| 5034 | __func__, __LINE__, sess->port_name); |
| 5035 | qla24xx_post_nack_work(vha, sess, iocb, |
| 5036 | SRB_NACK_PRLI); |
| 5037 | res = 0; |
| 5038 | } else { |
| 5039 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5040 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 5041 | qla2xxx_wake_dpc(vha); |
| 5042 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5043 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5044 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5045 | ql_dbg(ql_dbg_disc, vha, 0x20fb, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5046 | "%s %d %8phC post nack\n", |
| 5047 | __func__, __LINE__, sess->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5048 | qla24xx_post_nack_work(vha, sess, iocb, |
| 5049 | SRB_NACK_PRLI); |
| 5050 | res = 0; |
| 5051 | } |
| 5052 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5053 | break; |
| 5054 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5055 | case ELS_TPRLO: |
| 5056 | if (le16_to_cpu(iocb->u.isp24.flags) & |
| 5057 | NOTIFY24XX_FLAGS_GLOBAL_TPRLO) { |
| 5058 | loop_id = 0xFFFF; |
| 5059 | qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS); |
| 5060 | res = 1; |
| 5061 | break; |
| 5062 | } |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 5063 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5064 | case ELS_LOGO: |
| 5065 | case ELS_PRLO: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5066 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 5067 | sess = qla2x00_find_fcport_by_loopid(vha, loop_id); |
| 5068 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 5069 | |
| 5070 | if (sess) { |
| 5071 | sess->login_gen++; |
| 5072 | sess->fw_login_state = DSC_LS_LOGO_PEND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5073 | sess->logo_ack_needed = 1; |
| 5074 | memcpy(sess->iocb, iocb, IOCB_SIZE); |
| 5075 | } |
| 5076 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5077 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5078 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5079 | ql_dbg(ql_dbg_disc, vha, 0x20fc, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5080 | "%s: logo %llx res %d sess %p ", |
| 5081 | __func__, wwn, res, sess); |
| 5082 | if (res == 0) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5083 | /* |
| 5084 | * cmd went upper layer, look for qlt_xmit_tm_rsp() |
| 5085 | * for LOGO_ACK & sess delete |
| 5086 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5087 | BUG_ON(!sess); |
| 5088 | res = 0; |
| 5089 | } else { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5090 | /* cmd did not go to upper layer. */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5091 | if (sess) { |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 5092 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5093 | res = 0; |
| 5094 | } |
| 5095 | /* else logo will be ack */ |
| 5096 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5097 | break; |
| 5098 | case ELS_PDISC: |
| 5099 | case ELS_ADISC: |
| 5100 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5101 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5102 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5103 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5104 | qlt_send_notify_ack(ha->base_qpair, |
| 5105 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5106 | tgt->link_reinit_iocb_pending = 0; |
| 5107 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5108 | |
| 5109 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 5110 | iocb->u.isp24.port_name, 1); |
| 5111 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5112 | ql_dbg(ql_dbg_disc, vha, 0x20fd, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5113 | "sess %p lid %d|%d DS %d LS %d\n", |
| 5114 | sess, sess->loop_id, loop_id, |
| 5115 | sess->disc_state, sess->fw_login_state); |
| 5116 | } |
| 5117 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5118 | res = 1; /* send notify ack */ |
| 5119 | break; |
| 5120 | } |
| 5121 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5122 | case ELS_FLOGI: /* should never happen */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5123 | default: |
| 5124 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, |
| 5125 | "qla_target(%d): Unsupported ELS command %x " |
| 5126 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); |
| 5127 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 5128 | break; |
| 5129 | } |
| 5130 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 5131 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 5132 | "qla_target(%d): Exit ELS opcode: 0x%02x res %d\n", |
| 5133 | vha->vp_idx, iocb->u.isp24.status_subcode, res); |
| 5134 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5135 | return res; |
| 5136 | } |
| 5137 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5138 | /* |
| 5139 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5140 | */ |
| 5141 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, |
| 5142 | struct imm_ntfy_from_isp *iocb) |
| 5143 | { |
| 5144 | struct qla_hw_data *ha = vha->hw; |
| 5145 | uint32_t add_flags = 0; |
| 5146 | int send_notify_ack = 1; |
| 5147 | uint16_t status; |
| 5148 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 5149 | lockdep_assert_held(&ha->hardware_lock); |
| 5150 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5151 | status = le16_to_cpu(iocb->u.isp2x.status); |
| 5152 | switch (status) { |
| 5153 | case IMM_NTFY_LIP_RESET: |
| 5154 | { |
| 5155 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, |
| 5156 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", |
| 5157 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5158 | iocb->u.isp24.status_subcode); |
| 5159 | |
| 5160 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5161 | send_notify_ack = 0; |
| 5162 | break; |
| 5163 | } |
| 5164 | |
| 5165 | case IMM_NTFY_LIP_LINK_REINIT: |
| 5166 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5167 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5168 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5169 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
| 5170 | "qla_target(%d): LINK REINIT (loop %#x, " |
| 5171 | "subcode %x)\n", vha->vp_idx, |
| 5172 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5173 | iocb->u.isp24.status_subcode); |
| 5174 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5175 | qlt_send_notify_ack(ha->base_qpair, |
| 5176 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5177 | } |
| 5178 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); |
| 5179 | tgt->link_reinit_iocb_pending = 1; |
| 5180 | /* |
| 5181 | * QLogic requires to wait after LINK REINIT for possible |
| 5182 | * PDISC or ADISC ELS commands |
| 5183 | */ |
| 5184 | send_notify_ack = 0; |
| 5185 | break; |
| 5186 | } |
| 5187 | |
| 5188 | case IMM_NTFY_PORT_LOGOUT: |
| 5189 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, |
| 5190 | "qla_target(%d): Port logout (loop " |
| 5191 | "%#x, subcode %x)\n", vha->vp_idx, |
| 5192 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5193 | iocb->u.isp24.status_subcode); |
| 5194 | |
| 5195 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) |
| 5196 | send_notify_ack = 0; |
| 5197 | /* The sessions will be cleared in the callback, if needed */ |
| 5198 | break; |
| 5199 | |
| 5200 | case IMM_NTFY_GLBL_TPRLO: |
| 5201 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, |
| 5202 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); |
| 5203 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5204 | send_notify_ack = 0; |
| 5205 | /* The sessions will be cleared in the callback, if needed */ |
| 5206 | break; |
| 5207 | |
| 5208 | case IMM_NTFY_PORT_CONFIG: |
| 5209 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, |
| 5210 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, |
| 5211 | status); |
| 5212 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5213 | send_notify_ack = 0; |
| 5214 | /* The sessions will be cleared in the callback, if needed */ |
| 5215 | break; |
| 5216 | |
| 5217 | case IMM_NTFY_GLBL_LOGO: |
| 5218 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, |
| 5219 | "qla_target(%d): Link failure detected\n", |
| 5220 | vha->vp_idx); |
| 5221 | /* I_T nexus loss */ |
| 5222 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5223 | send_notify_ack = 0; |
| 5224 | break; |
| 5225 | |
| 5226 | case IMM_NTFY_IOCB_OVERFLOW: |
| 5227 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, |
| 5228 | "qla_target(%d): Cannot provide requested " |
| 5229 | "capability (IOCB overflowed the immediate notify " |
| 5230 | "resource count)\n", vha->vp_idx); |
| 5231 | break; |
| 5232 | |
| 5233 | case IMM_NTFY_ABORT_TASK: |
| 5234 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, |
| 5235 | "qla_target(%d): Abort Task (S %08x I %#x -> " |
| 5236 | "L %#x)\n", vha->vp_idx, |
| 5237 | le16_to_cpu(iocb->u.isp2x.seq_id), |
| 5238 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), |
| 5239 | le16_to_cpu(iocb->u.isp2x.lun)); |
| 5240 | if (qlt_abort_task(vha, iocb) == 0) |
| 5241 | send_notify_ack = 0; |
| 5242 | break; |
| 5243 | |
| 5244 | case IMM_NTFY_RESOURCE: |
| 5245 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, |
| 5246 | "qla_target(%d): Out of resources, host %ld\n", |
| 5247 | vha->vp_idx, vha->host_no); |
| 5248 | break; |
| 5249 | |
| 5250 | case IMM_NTFY_MSG_RX: |
| 5251 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, |
| 5252 | "qla_target(%d): Immediate notify task %x\n", |
| 5253 | vha->vp_idx, iocb->u.isp2x.task_flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5254 | break; |
| 5255 | |
| 5256 | case IMM_NTFY_ELS: |
| 5257 | if (qlt_24xx_handle_els(vha, iocb) == 0) |
| 5258 | send_notify_ack = 0; |
| 5259 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5260 | default: |
| 5261 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, |
| 5262 | "qla_target(%d): Received unknown immediate " |
| 5263 | "notify status %x\n", vha->vp_idx, status); |
| 5264 | break; |
| 5265 | } |
| 5266 | |
| 5267 | if (send_notify_ack) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5268 | qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0, |
| 5269 | 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5270 | } |
| 5271 | |
| 5272 | /* |
| 5273 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5274 | * This function sends busy to ISP 2xxx or 24xx. |
| 5275 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5276 | static int __qlt_send_busy(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5277 | struct atio_from_isp *atio, uint16_t status) |
| 5278 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5279 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5280 | struct ctio7_to_24xx *ctio24; |
| 5281 | struct qla_hw_data *ha = vha->hw; |
| 5282 | request_t *pkt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5283 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5284 | unsigned long flags; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5285 | u16 temp; |
Quinn Tran | 8ea4faf | 2018-05-01 09:01:49 -0700 | [diff] [blame] | 5286 | port_id_t id; |
| 5287 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 5288 | id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5289 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5290 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 8ea4faf | 2018-05-01 09:01:49 -0700 | [diff] [blame] | 5291 | sess = qla2x00_find_fcport_by_nportid(vha, &id, 1); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5292 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5293 | if (!sess) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5294 | qlt_send_term_exchange(qpair, NULL, atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5295 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5296 | } |
| 5297 | /* Sending marker isn't necessary, since we called from ISR */ |
| 5298 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5299 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5300 | if (!pkt) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5301 | ql_dbg(ql_dbg_io, vha, 0x3063, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5302 | "qla_target(%d): %s failed: unable to allocate " |
| 5303 | "request packet", vha->vp_idx, __func__); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5304 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5305 | } |
| 5306 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5307 | qpair->tgt_counters.num_q_full_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5308 | pkt->entry_count = 1; |
| 5309 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 5310 | |
| 5311 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 5312 | ctio24->entry_type = CTIO_TYPE7; |
| 5313 | ctio24->nport_handle = sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5314 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5315 | ctio24->vp_index = vha->vp_idx; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 5316 | ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5317 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5318 | temp = (atio->u.isp24.attr << 9) | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5319 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5320 | CTIO7_FLAGS_DONT_RET_CTIO; |
| 5321 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5322 | /* |
| 5323 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, |
| 5324 | * if the explicit conformation is used. |
| 5325 | */ |
| 5326 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); |
| 5327 | ctio24->u.status1.scsi_status = cpu_to_le16(status); |
Quinn Tran | e25f765 | 2018-05-01 09:01:50 -0700 | [diff] [blame] | 5328 | |
| 5329 | ctio24->u.status1.residual = get_datalen_for_atio(atio); |
| 5330 | |
| 5331 | if (ctio24->u.status1.residual != 0) |
| 5332 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; |
| 5333 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 5334 | /* Memory Barrier */ |
| 5335 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 5336 | if (qpair->reqq_start_iocbs) |
| 5337 | qpair->reqq_start_iocbs(qpair); |
| 5338 | else |
| 5339 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5340 | return 0; |
| 5341 | } |
| 5342 | |
| 5343 | /* |
| 5344 | * This routine is used to allocate a command for either a QFull condition |
| 5345 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go |
| 5346 | * out previously. |
| 5347 | */ |
| 5348 | static void |
| 5349 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 5350 | struct atio_from_isp *atio, uint16_t status, int qfull) |
| 5351 | { |
| 5352 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 5353 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5354 | struct fc_port *sess; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5355 | struct se_session *se_sess; |
| 5356 | struct qla_tgt_cmd *cmd; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 5357 | int tag, cpu; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5358 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5359 | |
| 5360 | if (unlikely(tgt->tgt_stop)) { |
| 5361 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 5362 | "New command while device %p is shutting down\n", tgt); |
| 5363 | return; |
| 5364 | } |
| 5365 | |
| 5366 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { |
| 5367 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5368 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5369 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5370 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5371 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5372 | |
| 5373 | ql_dbg(ql_dbg_io, vha, 0x3068, |
| 5374 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", |
| 5375 | vha->vp_idx, __func__, |
| 5376 | vha->hw->tgt.num_qfull_cmds_dropped); |
| 5377 | |
| 5378 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5379 | return; |
| 5380 | } |
| 5381 | |
| 5382 | sess = ha->tgt.tgt_ops->find_sess_by_s_id |
| 5383 | (vha, atio->u.isp24.fcp_hdr.s_id); |
| 5384 | if (!sess) |
| 5385 | return; |
| 5386 | |
| 5387 | se_sess = sess->se_sess; |
| 5388 | |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 5389 | tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu); |
Bart Van Assche | c04466c | 2019-04-17 14:44:27 -0700 | [diff] [blame] | 5390 | if (tag < 0) { |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5391 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 5392 | "qla_target(%d): %s: Allocation of cmd failed\n", |
| 5393 | vha->vp_idx, __func__); |
| 5394 | |
| 5395 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5396 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5397 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5398 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5399 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5400 | |
| 5401 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5402 | return; |
| 5403 | } |
| 5404 | |
Bart Van Assche | c04466c | 2019-04-17 14:44:27 -0700 | [diff] [blame] | 5405 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5406 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 5407 | |
| 5408 | qlt_incr_num_pend_cmds(vha); |
| 5409 | INIT_LIST_HEAD(&cmd->cmd_list); |
| 5410 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 5411 | |
| 5412 | cmd->tgt = vha->vha_tgt.qla_tgt; |
| 5413 | cmd->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 5414 | cmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5415 | cmd->q_full = 1; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5416 | cmd->qpair = ha->base_qpair; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 5417 | cmd->se_cmd.map_cpu = cpu; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5418 | |
| 5419 | if (qfull) { |
| 5420 | cmd->q_full = 1; |
| 5421 | /* NOTE: borrowing the state field to carry the status */ |
| 5422 | cmd->state = status; |
| 5423 | } else |
| 5424 | cmd->term_exchg = 1; |
| 5425 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5426 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5427 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); |
| 5428 | |
| 5429 | vha->hw->tgt.num_qfull_cmds_alloc++; |
| 5430 | if (vha->hw->tgt.num_qfull_cmds_alloc > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5431 | vha->qla_stats.stat_max_qfull_cmds_alloc) |
| 5432 | vha->qla_stats.stat_max_qfull_cmds_alloc = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5433 | vha->hw->tgt.num_qfull_cmds_alloc; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5434 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5438 | qlt_free_qfull_cmds(struct qla_qpair *qpair) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5439 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5440 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5441 | struct qla_hw_data *ha = vha->hw; |
| 5442 | unsigned long flags; |
| 5443 | struct qla_tgt_cmd *cmd, *tcmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5444 | struct list_head free_list, q_full_list; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5445 | int rc = 0; |
| 5446 | |
| 5447 | if (list_empty(&ha->tgt.q_full_list)) |
| 5448 | return 0; |
| 5449 | |
| 5450 | INIT_LIST_HEAD(&free_list); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5451 | INIT_LIST_HEAD(&q_full_list); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5452 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5453 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5454 | if (list_empty(&ha->tgt.q_full_list)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5455 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5456 | return 0; |
| 5457 | } |
| 5458 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5459 | list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list); |
| 5460 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5461 | |
| 5462 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 5463 | list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) { |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5464 | if (cmd->q_full) |
| 5465 | /* cmd->state is a borrowed field to hold status */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5466 | rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5467 | else if (cmd->term_exchg) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5468 | rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5469 | |
| 5470 | if (rc == -ENOMEM) |
| 5471 | break; |
| 5472 | |
| 5473 | if (cmd->q_full) |
| 5474 | ql_dbg(ql_dbg_io, vha, 0x3006, |
| 5475 | "%s: busy sent for ox_id[%04x]\n", __func__, |
| 5476 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5477 | else if (cmd->term_exchg) |
| 5478 | ql_dbg(ql_dbg_io, vha, 0x3007, |
| 5479 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, |
| 5480 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5481 | else |
| 5482 | ql_dbg(ql_dbg_io, vha, 0x3008, |
| 5483 | "%s: Unexpected cmd in QFull list %p\n", __func__, |
| 5484 | cmd); |
| 5485 | |
| 5486 | list_del(&cmd->cmd_list); |
| 5487 | list_add_tail(&cmd->cmd_list, &free_list); |
| 5488 | |
| 5489 | /* piggy back on hardware_lock for protection */ |
| 5490 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 5491 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5492 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5493 | |
| 5494 | cmd = NULL; |
| 5495 | |
| 5496 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 5497 | list_del(&cmd->cmd_list); |
| 5498 | /* This cmd was never sent to TCM. There is no need |
| 5499 | * to schedule free or call free_cmd |
| 5500 | */ |
| 5501 | qlt_free_cmd(cmd); |
| 5502 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5503 | |
| 5504 | if (!list_empty(&q_full_list)) { |
| 5505 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 5506 | list_splice(&q_full_list, &vha->hw->tgt.q_full_list); |
| 5507 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5508 | } |
| 5509 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5510 | return rc; |
| 5511 | } |
| 5512 | |
| 5513 | static void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5514 | qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio, |
| 5515 | uint16_t status) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5516 | { |
| 5517 | int rc = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5518 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5519 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5520 | rc = __qlt_send_busy(qpair, atio, status); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5521 | if (rc == -ENOMEM) |
| 5522 | qlt_alloc_qfull_cmd(vha, atio, status, 1); |
| 5523 | } |
| 5524 | |
| 5525 | static int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5526 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair, |
| 5527 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5528 | { |
| 5529 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5530 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5531 | |
| 5532 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) |
| 5533 | return 0; |
| 5534 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5535 | if (!ha_locked) |
| 5536 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5537 | qlt_send_busy(qpair, atio, qla_sam_status); |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5538 | if (!ha_locked) |
| 5539 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5540 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5541 | return 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | /* ha->hardware_lock supposed to be held on entry */ |
| 5545 | /* called via callback from qla2xxx */ |
| 5546 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5547 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5548 | { |
| 5549 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5550 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5551 | int rc; |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5552 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5553 | |
| 5554 | if (unlikely(tgt == NULL)) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5555 | ql_dbg(ql_dbg_tgt, vha, 0x3064, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5556 | "ATIO pkt, but no tgt (ha %p)", ha); |
| 5557 | return; |
| 5558 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5559 | /* |
| 5560 | * In tgt_stop mode we also should allow all requests to pass. |
| 5561 | * Otherwise, some commands can stuck. |
| 5562 | */ |
| 5563 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5564 | tgt->atio_irq_cmd_count++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5565 | |
| 5566 | switch (atio->u.raw.entry_type) { |
| 5567 | case ATIO_TYPE7: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5568 | if (unlikely(atio->u.isp24.exchange_addr == |
| 5569 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5570 | ql_dbg(ql_dbg_io, vha, 0x3065, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5571 | "qla_target(%d): ATIO_TYPE7 " |
| 5572 | "received with UNKNOWN exchange address, " |
| 5573 | "sending QUEUE_FULL\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5574 | if (!ha_locked) |
| 5575 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5576 | qlt_send_busy(ha->base_qpair, atio, qla_sam_status); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5577 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5578 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5579 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5580 | break; |
| 5581 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5582 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5583 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5584 | rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair, |
| 5585 | atio, ha_locked); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5586 | if (rc != 0) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5587 | tgt->atio_irq_cmd_count--; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5588 | return; |
| 5589 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5590 | rc = qlt_handle_cmd_for_atio(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5591 | } else { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5592 | rc = qlt_handle_task_mgmt(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5593 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5594 | if (unlikely(rc != 0)) { |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5595 | if (!ha_locked) |
| 5596 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5597 | switch (rc) { |
| 5598 | case -ENODEV: |
| 5599 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5600 | "qla_target: Unable to send command to target\n"); |
| 5601 | break; |
| 5602 | case -EBADF: |
| 5603 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5604 | "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n"); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5605 | qlt_send_term_exchange(ha->base_qpair, NULL, |
| 5606 | atio, 1, 0); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5607 | break; |
| 5608 | case -EBUSY: |
| 5609 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5610 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5611 | vha->vp_idx); |
| 5612 | qlt_send_busy(ha->base_qpair, atio, |
| 5613 | tc_sam_status); |
| 5614 | break; |
| 5615 | default: |
| 5616 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5617 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5618 | vha->vp_idx); |
| 5619 | qlt_send_busy(ha->base_qpair, atio, |
| 5620 | qla_sam_status); |
| 5621 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5622 | } |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5623 | if (!ha_locked) |
| 5624 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5625 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5626 | } |
| 5627 | break; |
| 5628 | |
| 5629 | case IMMED_NOTIFY_TYPE: |
| 5630 | { |
| 5631 | if (unlikely(atio->u.isp2x.entry_status != 0)) { |
| 5632 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, |
| 5633 | "qla_target(%d): Received ATIO packet %x " |
| 5634 | "with error status %x\n", vha->vp_idx, |
| 5635 | atio->u.raw.entry_type, |
| 5636 | atio->u.isp2x.entry_status); |
| 5637 | break; |
| 5638 | } |
| 5639 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5640 | |
| 5641 | if (!ha_locked) |
| 5642 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5643 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5644 | if (!ha_locked) |
| 5645 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5646 | break; |
| 5647 | } |
| 5648 | |
| 5649 | default: |
| 5650 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, |
| 5651 | "qla_target(%d): Received unknown ATIO atio " |
| 5652 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 5653 | break; |
| 5654 | } |
| 5655 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5656 | tgt->atio_irq_cmd_count--; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5657 | } |
| 5658 | |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 5659 | /* |
| 5660 | * qpair lock is assume to be held |
| 5661 | * rc = 0 : send terminate & abts respond |
| 5662 | * rc != 0: do not send term & abts respond |
| 5663 | */ |
| 5664 | static int qlt_chk_unresolv_exchg(struct scsi_qla_host *vha, |
| 5665 | struct qla_qpair *qpair, struct abts_resp_from_24xx_fw *entry) |
| 5666 | { |
| 5667 | struct qla_hw_data *ha = vha->hw; |
| 5668 | int rc = 0; |
| 5669 | |
| 5670 | /* |
| 5671 | * Detect unresolved exchange. If the same ABTS is unable |
| 5672 | * to terminate an existing command and the same ABTS loops |
| 5673 | * between FW & Driver, then force FW dump. Under 1 jiff, |
| 5674 | * we should see multiple loops. |
| 5675 | */ |
| 5676 | if (qpair->retry_term_exchg_addr == entry->exchange_addr_to_abort && |
| 5677 | qpair->retry_term_jiff == jiffies) { |
| 5678 | /* found existing exchange */ |
| 5679 | qpair->retry_term_cnt++; |
| 5680 | if (qpair->retry_term_cnt >= 5) { |
| 5681 | rc = EIO; |
| 5682 | qpair->retry_term_cnt = 0; |
| 5683 | ql_log(ql_log_warn, vha, 0xffff, |
| 5684 | "Unable to send ABTS Respond. Dumping firmware.\n"); |
| 5685 | ql_dump_buffer(ql_dbg_tgt_mgt + ql_dbg_buffer, |
| 5686 | vha, 0xffff, (uint8_t *)entry, sizeof(*entry)); |
| 5687 | |
| 5688 | if (qpair == ha->base_qpair) |
| 5689 | ha->isp_ops->fw_dump(vha, 1); |
| 5690 | else |
| 5691 | ha->isp_ops->fw_dump(vha, 0); |
| 5692 | |
| 5693 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5694 | qla2xxx_wake_dpc(vha); |
| 5695 | } |
| 5696 | } else if (qpair->retry_term_jiff != jiffies) { |
| 5697 | qpair->retry_term_exchg_addr = entry->exchange_addr_to_abort; |
| 5698 | qpair->retry_term_cnt = 0; |
| 5699 | qpair->retry_term_jiff = jiffies; |
| 5700 | } |
| 5701 | |
| 5702 | return rc; |
| 5703 | } |
| 5704 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5705 | |
| 5706 | static void qlt_handle_abts_completion(struct scsi_qla_host *vha, |
| 5707 | struct rsp_que *rsp, response_t *pkt) |
| 5708 | { |
| 5709 | struct abts_resp_from_24xx_fw *entry = |
| 5710 | (struct abts_resp_from_24xx_fw *)pkt; |
| 5711 | u32 h = pkt->handle & ~QLA_TGT_HANDLE_MASK; |
| 5712 | struct qla_tgt_mgmt_cmd *mcmd; |
| 5713 | struct qla_hw_data *ha = vha->hw; |
| 5714 | |
Bart Van Assche | 81bcf1c | 2019-04-11 14:53:24 -0700 | [diff] [blame] | 5715 | mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, pkt); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5716 | if (mcmd == NULL && h != QLA_TGT_SKIP_HANDLE) { |
| 5717 | ql_dbg(ql_dbg_async, vha, 0xe064, |
| 5718 | "qla_target(%d): ABTS Comp without mcmd\n", |
| 5719 | vha->vp_idx); |
| 5720 | return; |
| 5721 | } |
| 5722 | |
| 5723 | if (mcmd) |
| 5724 | vha = mcmd->vha; |
| 5725 | vha->vha_tgt.qla_tgt->abts_resp_expected--; |
| 5726 | |
| 5727 | ql_dbg(ql_dbg_tgt, vha, 0xe038, |
| 5728 | "ABTS_RESP_24XX: compl_status %x\n", |
| 5729 | entry->compl_status); |
| 5730 | |
| 5731 | if (le16_to_cpu(entry->compl_status) != ABTS_RESP_COMPL_SUCCESS) { |
| 5732 | if ((entry->error_subcode1 == 0x1E) && |
| 5733 | (entry->error_subcode2 == 0)) { |
| 5734 | if (qlt_chk_unresolv_exchg(vha, rsp->qpair, entry)) { |
| 5735 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5736 | return; |
| 5737 | } |
| 5738 | qlt_24xx_retry_term_exchange(vha, rsp->qpair, |
| 5739 | pkt, mcmd); |
| 5740 | } else { |
| 5741 | ql_dbg(ql_dbg_tgt, vha, 0xe063, |
| 5742 | "qla_target(%d): ABTS_RESP_24XX failed %x (subcode %x:%x)", |
| 5743 | vha->vp_idx, entry->compl_status, |
| 5744 | entry->error_subcode1, |
| 5745 | entry->error_subcode2); |
| 5746 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5747 | } |
Bart Van Assche | e752a04 | 2019-08-08 20:02:07 -0700 | [diff] [blame] | 5748 | } else if (mcmd) { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5749 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5750 | } |
| 5751 | } |
| 5752 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5753 | /* ha->hardware_lock supposed to be held on entry */ |
| 5754 | /* called via callback from qla2xxx */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5755 | static void qlt_response_pkt(struct scsi_qla_host *vha, |
| 5756 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5757 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5758 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5759 | |
| 5760 | if (unlikely(tgt == NULL)) { |
| 5761 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5762 | "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n", |
| 5763 | vha->vp_idx, pkt->entry_type, vha->hw); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5764 | return; |
| 5765 | } |
| 5766 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5767 | /* |
| 5768 | * In tgt_stop mode we also should allow all requests to pass. |
| 5769 | * Otherwise, some commands can stuck. |
| 5770 | */ |
| 5771 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5772 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 5773 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5774 | case CTIO_TYPE7: |
| 5775 | { |
| 5776 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5777 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5778 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5779 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5780 | entry); |
| 5781 | break; |
| 5782 | } |
| 5783 | |
| 5784 | case ACCEPT_TGT_IO_TYPE: |
| 5785 | { |
| 5786 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; |
| 5787 | int rc; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5788 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5789 | if (atio->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5790 | cpu_to_le16(ATIO_CDB_VALID)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5791 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, |
| 5792 | "qla_target(%d): ATIO with error " |
| 5793 | "status %x received\n", vha->vp_idx, |
| 5794 | le16_to_cpu(atio->u.isp2x.status)); |
| 5795 | break; |
| 5796 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5797 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5798 | rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1); |
Quinn Tran | ba68a63 | 2017-06-02 09:12:06 -0700 | [diff] [blame] | 5799 | if (rc != 0) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5800 | return; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5801 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5802 | rc = qlt_handle_cmd_for_atio(vha, atio); |
| 5803 | if (unlikely(rc != 0)) { |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5804 | switch (rc) { |
| 5805 | case -ENODEV: |
| 5806 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5807 | "qla_target: Unable to send command to target\n"); |
| 5808 | break; |
| 5809 | case -EBADF: |
| 5810 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5811 | "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n"); |
| 5812 | qlt_send_term_exchange(rsp->qpair, NULL, |
| 5813 | atio, 1, 0); |
| 5814 | break; |
| 5815 | case -EBUSY: |
| 5816 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5817 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5818 | vha->vp_idx); |
| 5819 | qlt_send_busy(rsp->qpair, atio, |
| 5820 | tc_sam_status); |
| 5821 | break; |
| 5822 | default: |
| 5823 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5824 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5825 | vha->vp_idx); |
| 5826 | qlt_send_busy(rsp->qpair, atio, |
| 5827 | qla_sam_status); |
| 5828 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5829 | } |
| 5830 | } |
| 5831 | } |
| 5832 | break; |
| 5833 | |
| 5834 | case CONTINUE_TGT_IO_TYPE: |
| 5835 | { |
| 5836 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5837 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5838 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5839 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5840 | entry); |
| 5841 | break; |
| 5842 | } |
| 5843 | |
| 5844 | case CTIO_A64_TYPE: |
| 5845 | { |
| 5846 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5847 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5848 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5849 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5850 | entry); |
| 5851 | break; |
| 5852 | } |
| 5853 | |
| 5854 | case IMMED_NOTIFY_TYPE: |
| 5855 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); |
| 5856 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); |
| 5857 | break; |
| 5858 | |
| 5859 | case NOTIFY_ACK_TYPE: |
| 5860 | if (tgt->notify_ack_expected > 0) { |
| 5861 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5862 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5863 | ql_dbg(ql_dbg_tgt, vha, 0xe036, |
| 5864 | "NOTIFY_ACK seq %08x status %x\n", |
| 5865 | le16_to_cpu(entry->u.isp2x.seq_id), |
| 5866 | le16_to_cpu(entry->u.isp2x.status)); |
| 5867 | tgt->notify_ack_expected--; |
| 5868 | if (entry->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5869 | cpu_to_le16(NOTIFY_ACK_SUCCESS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5870 | ql_dbg(ql_dbg_tgt, vha, 0xe061, |
| 5871 | "qla_target(%d): NOTIFY_ACK " |
| 5872 | "failed %x\n", vha->vp_idx, |
| 5873 | le16_to_cpu(entry->u.isp2x.status)); |
| 5874 | } |
| 5875 | } else { |
| 5876 | ql_dbg(ql_dbg_tgt, vha, 0xe062, |
| 5877 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", |
| 5878 | vha->vp_idx); |
| 5879 | } |
| 5880 | break; |
| 5881 | |
| 5882 | case ABTS_RECV_24XX: |
| 5883 | ql_dbg(ql_dbg_tgt, vha, 0xe037, |
| 5884 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); |
| 5885 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); |
| 5886 | break; |
| 5887 | |
| 5888 | case ABTS_RESP_24XX: |
| 5889 | if (tgt->abts_resp_expected > 0) { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5890 | qlt_handle_abts_completion(vha, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5891 | } else { |
| 5892 | ql_dbg(ql_dbg_tgt, vha, 0xe064, |
| 5893 | "qla_target(%d): Unexpected ABTS_RESP_24XX " |
| 5894 | "received\n", vha->vp_idx); |
| 5895 | } |
| 5896 | break; |
| 5897 | |
| 5898 | default: |
| 5899 | ql_dbg(ql_dbg_tgt, vha, 0xe065, |
| 5900 | "qla_target(%d): Received unknown response pkt " |
| 5901 | "type %x\n", vha->vp_idx, pkt->entry_type); |
| 5902 | break; |
| 5903 | } |
| 5904 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5905 | } |
| 5906 | |
| 5907 | /* |
| 5908 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5909 | */ |
| 5910 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, |
| 5911 | uint16_t *mailbox) |
| 5912 | { |
| 5913 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5914 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5915 | int login_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5916 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 5917 | if (!tgt || tgt->tgt_stop || tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5918 | return; |
| 5919 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5920 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && |
| 5921 | IS_QLA2100(ha)) |
| 5922 | return; |
| 5923 | /* |
| 5924 | * In tgt_stop mode we also should allow all requests to pass. |
| 5925 | * Otherwise, some commands can stuck. |
| 5926 | */ |
| 5927 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5928 | |
| 5929 | switch (code) { |
| 5930 | case MBA_RESET: /* Reset */ |
| 5931 | case MBA_SYSTEM_ERR: /* System Error */ |
| 5932 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 5933 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 5934 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, |
| 5935 | "qla_target(%d): System error async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5936 | "occurred", vha->vp_idx, code); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5937 | break; |
| 5938 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ |
| 5939 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5940 | break; |
| 5941 | |
| 5942 | case MBA_LOOP_UP: |
| 5943 | { |
| 5944 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5945 | "qla_target(%d): Async LOOP_UP occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5946 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 5947 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5948 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5949 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5950 | qlt_send_notify_ack(ha->base_qpair, |
| 5951 | (void *)&tgt->link_reinit_iocb, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5952 | 0, 0, 0, 0, 0, 0); |
| 5953 | tgt->link_reinit_iocb_pending = 0; |
| 5954 | } |
| 5955 | break; |
| 5956 | } |
| 5957 | |
| 5958 | case MBA_LIP_OCCURRED: |
| 5959 | case MBA_LOOP_DOWN: |
| 5960 | case MBA_LIP_RESET: |
| 5961 | case MBA_RSCN_UPDATE: |
| 5962 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5963 | "qla_target(%d): Async event %#x occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5964 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5965 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5966 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5967 | break; |
| 5968 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5969 | case MBA_REJECTED_FCP_CMD: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5970 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017, |
| 5971 | "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", |
| 5972 | vha->vp_idx, |
| 5973 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5974 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5975 | |
| 5976 | if (le16_to_cpu(mailbox[3]) == 1) { |
| 5977 | /* exchange starvation. */ |
| 5978 | vha->hw->exch_starvation++; |
| 5979 | if (vha->hw->exch_starvation > 5) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5980 | ql_log(ql_log_warn, vha, 0xd03a, |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5981 | "Exchange starvation-. Resetting RISC\n"); |
| 5982 | |
| 5983 | vha->hw->exch_starvation = 0; |
| 5984 | if (IS_P3P_TYPE(vha->hw)) |
| 5985 | set_bit(FCOE_CTX_RESET_NEEDED, |
| 5986 | &vha->dpc_flags); |
| 5987 | else |
| 5988 | set_bit(ISP_ABORT_NEEDED, |
| 5989 | &vha->dpc_flags); |
| 5990 | qla2xxx_wake_dpc(vha); |
| 5991 | } |
| 5992 | } |
| 5993 | break; |
| 5994 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5995 | case MBA_PORT_UPDATE: |
| 5996 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, |
| 5997 | "qla_target(%d): Port update async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5998 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5999 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 6000 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 6001 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 6002 | |
| 6003 | login_code = le16_to_cpu(mailbox[2]); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6004 | if (login_code == 0x4) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6005 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
| 6006 | "Async MB 2: Got PLOGI Complete\n"); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6007 | vha->hw->exch_starvation = 0; |
| 6008 | } else if (login_code == 0x7) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6009 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
| 6010 | "Async MB 2: Port Logged Out\n"); |
| 6011 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6012 | default: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6013 | break; |
| 6014 | } |
| 6015 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6016 | } |
| 6017 | |
| 6018 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, |
| 6019 | uint16_t loop_id) |
| 6020 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6021 | fc_port_t *fcport, *tfcp, *del; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6022 | int rc; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6023 | unsigned long flags; |
| 6024 | u8 newfcport = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6025 | |
Quinn Tran | 063b36d | 2017-12-04 14:45:10 -0800 | [diff] [blame] | 6026 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6027 | if (!fcport) { |
| 6028 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, |
| 6029 | "qla_target(%d): Allocation of tmp FC port failed", |
| 6030 | vha->vp_idx); |
| 6031 | return NULL; |
| 6032 | } |
| 6033 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6034 | fcport->loop_id = loop_id; |
| 6035 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 6036 | rc = qla24xx_gpdb_wait(vha, fcport, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6037 | if (rc != QLA_SUCCESS) { |
| 6038 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, |
| 6039 | "qla_target(%d): Failed to retrieve fcport " |
| 6040 | "information -- get_port_database() returned %x " |
| 6041 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); |
| 6042 | kfree(fcport); |
| 6043 | return NULL; |
| 6044 | } |
| 6045 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6046 | del = NULL; |
| 6047 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 6048 | tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1); |
| 6049 | |
| 6050 | if (tfcp) { |
| 6051 | tfcp->d_id = fcport->d_id; |
| 6052 | tfcp->port_type = fcport->port_type; |
| 6053 | tfcp->supported_classes = fcport->supported_classes; |
| 6054 | tfcp->flags |= fcport->flags; |
Quinn Tran | 76f9a2d | 2017-12-04 14:45:11 -0800 | [diff] [blame] | 6055 | tfcp->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6056 | |
| 6057 | del = fcport; |
| 6058 | fcport = tfcp; |
| 6059 | } else { |
| 6060 | if (vha->hw->current_topology == ISP_CFG_F) |
| 6061 | fcport->flags |= FCF_FABRIC_DEVICE; |
| 6062 | |
| 6063 | list_add_tail(&fcport->list, &vha->vp_fcports); |
| 6064 | if (!IS_SW_RESV_ADDR(fcport->d_id)) |
| 6065 | vha->fcport_count++; |
| 6066 | fcport->login_gen++; |
Shyam Sundar | 27258a5 | 2019-12-17 14:06:06 -0800 | [diff] [blame] | 6067 | qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6068 | fcport->login_succ = 1; |
| 6069 | newfcport = 1; |
| 6070 | } |
| 6071 | |
| 6072 | fcport->deleted = 0; |
| 6073 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 6074 | |
| 6075 | switch (vha->host->active_mode) { |
| 6076 | case MODE_INITIATOR: |
| 6077 | case MODE_DUAL: |
| 6078 | if (newfcport) { |
| 6079 | if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) { |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 6080 | qla24xx_sched_upd_fcport(fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6081 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6082 | ql_dbg(ql_dbg_disc, vha, 0x20ff, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6083 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 6084 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 6085 | qla24xx_post_gpsc_work(vha, fcport); |
| 6086 | } |
| 6087 | } |
| 6088 | break; |
| 6089 | |
| 6090 | case MODE_TARGET: |
| 6091 | default: |
| 6092 | break; |
| 6093 | } |
| 6094 | if (del) |
| 6095 | qla2x00_free_fcport(del); |
| 6096 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6097 | return fcport; |
| 6098 | } |
| 6099 | |
| 6100 | /* Must be called under tgt_mutex */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6101 | static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *vha, |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6102 | be_id_t s_id) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6103 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6104 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6105 | fc_port_t *fcport = NULL; |
| 6106 | int rc, global_resets; |
| 6107 | uint16_t loop_id = 0; |
| 6108 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6109 | if (s_id.domain == 0xFF && s_id.area == 0xFC) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6110 | /* |
| 6111 | * This is Domain Controller, so it should be |
| 6112 | * OK to drop SCSI commands from it. |
| 6113 | */ |
| 6114 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, |
| 6115 | "Unable to find initiator with S_ID %x:%x:%x", |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6116 | s_id.domain, s_id.area, s_id.al_pa); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6117 | return NULL; |
| 6118 | } |
| 6119 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6120 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 6121 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6122 | retry: |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6123 | global_resets = |
| 6124 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6125 | |
| 6126 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); |
| 6127 | if (rc != 0) { |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6128 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 6129 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6130 | ql_log(ql_log_info, vha, 0xf071, |
| 6131 | "qla_target(%d): Unable to find " |
| 6132 | "initiator with S_ID %x:%x:%x", |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6133 | vha->vp_idx, s_id.domain, s_id.area, s_id.al_pa); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6134 | |
| 6135 | if (rc == -ENOENT) { |
| 6136 | qlt_port_logo_t logo; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 6137 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6138 | logo.id = be_to_port_id(s_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6139 | logo.cmd_count = 1; |
| 6140 | qlt_send_first_logo(vha, &logo); |
| 6141 | } |
| 6142 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6143 | return NULL; |
| 6144 | } |
| 6145 | |
| 6146 | fcport = qlt_get_port_database(vha, loop_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6147 | if (!fcport) { |
| 6148 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6149 | return NULL; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6150 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6151 | |
| 6152 | if (global_resets != |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6153 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6154 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
| 6155 | "qla_target(%d): global reset during session discovery " |
| 6156 | "(counter was %d, new %d), retrying", vha->vp_idx, |
| 6157 | global_resets, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6158 | atomic_read(&vha->vha_tgt. |
| 6159 | qla_tgt->tgt_global_resets_count)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6160 | goto retry; |
| 6161 | } |
| 6162 | |
| 6163 | sess = qlt_create_sess(vha, fcport, true); |
| 6164 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6165 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 6166 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6167 | return sess; |
| 6168 | } |
| 6169 | |
| 6170 | static void qlt_abort_work(struct qla_tgt *tgt, |
| 6171 | struct qla_tgt_sess_work_param *prm) |
| 6172 | { |
| 6173 | struct scsi_qla_host *vha = tgt->vha; |
| 6174 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6175 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6176 | unsigned long flags = 0, flags2 = 0; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6177 | be_id_t s_id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6178 | int rc; |
| 6179 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6180 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6181 | |
| 6182 | if (tgt->tgt_stop) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6183 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6184 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6185 | s_id = le_id_to_be(prm->abts.fcp_hdr_le.s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6186 | |
Bart Van Assche | ac452b8 | 2019-08-08 20:01:40 -0700 | [diff] [blame] | 6187 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6188 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6189 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6190 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6191 | sess = qlt_make_local_sess(vha, s_id); |
| 6192 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6193 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6194 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6195 | if (!sess) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6196 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6197 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6198 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6199 | sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6200 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6201 | } |
| 6202 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6203 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6204 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6205 | "%s: kref_get fail %8phC \n", |
| 6206 | __func__, sess->port_name); |
| 6207 | sess = NULL; |
| 6208 | goto out_term2; |
| 6209 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6210 | } |
| 6211 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6212 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6213 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 6214 | |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 6215 | ha->tgt.tgt_ops->put_sess(sess); |
| 6216 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6217 | if (rc != 0) |
| 6218 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6219 | return; |
| 6220 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6221 | out_term2: |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 6222 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 6223 | |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6224 | out_term: |
| 6225 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6226 | qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts, |
| 6227 | FCP_TMF_REJECTED, false); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6228 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | static void qlt_tmr_work(struct qla_tgt *tgt, |
| 6232 | struct qla_tgt_sess_work_param *prm) |
| 6233 | { |
| 6234 | struct atio_from_isp *a = &prm->tm_iocb2; |
| 6235 | struct scsi_qla_host *vha = tgt->vha; |
| 6236 | struct qla_hw_data *ha = vha->hw; |
Colin Ian King | bb6abdd | 2019-02-15 09:52:32 +0000 | [diff] [blame] | 6237 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6238 | unsigned long flags; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6239 | be_id_t s_id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6240 | int rc; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6241 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 6242 | int fn; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6243 | void *iocb; |
| 6244 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6245 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6246 | |
| 6247 | if (tgt->tgt_stop) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6248 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6249 | |
| 6250 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; |
| 6251 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 6252 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6253 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6254 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6255 | sess = qlt_make_local_sess(vha, s_id); |
| 6256 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6257 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6258 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6259 | if (!sess) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6260 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6261 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6262 | if (sess->deleted) { |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6263 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6264 | } |
| 6265 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6266 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6267 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6268 | "%s: kref_get fail %8phC\n", |
| 6269 | __func__, sess->port_name); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6270 | goto out_term2; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6271 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6272 | } |
| 6273 | |
| 6274 | iocb = a; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6275 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6276 | unpacked_lun = |
| 6277 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6278 | |
| 6279 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6280 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 6281 | |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 6282 | ha->tgt.tgt_ops->put_sess(sess); |
| 6283 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6284 | if (rc != 0) |
| 6285 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6286 | return; |
| 6287 | |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6288 | out_term2: |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6289 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6290 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6291 | qlt_send_term_exchange(ha->base_qpair, NULL, &prm->tm_iocb2, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | static void qlt_sess_work_fn(struct work_struct *work) |
| 6295 | { |
| 6296 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); |
| 6297 | struct scsi_qla_host *vha = tgt->vha; |
| 6298 | unsigned long flags; |
| 6299 | |
| 6300 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); |
| 6301 | |
| 6302 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6303 | while (!list_empty(&tgt->sess_works_list)) { |
| 6304 | struct qla_tgt_sess_work_param *prm = list_entry( |
| 6305 | tgt->sess_works_list.next, typeof(*prm), |
| 6306 | sess_works_list_entry); |
| 6307 | |
| 6308 | /* |
| 6309 | * This work can be scheduled on several CPUs at time, so we |
| 6310 | * must delete the entry to eliminate double processing |
| 6311 | */ |
| 6312 | list_del(&prm->sess_works_list_entry); |
| 6313 | |
| 6314 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6315 | |
| 6316 | switch (prm->type) { |
| 6317 | case QLA_TGT_SESS_WORK_ABORT: |
| 6318 | qlt_abort_work(tgt, prm); |
| 6319 | break; |
| 6320 | case QLA_TGT_SESS_WORK_TM: |
| 6321 | qlt_tmr_work(tgt, prm); |
| 6322 | break; |
| 6323 | default: |
| 6324 | BUG_ON(1); |
| 6325 | break; |
| 6326 | } |
| 6327 | |
| 6328 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6329 | |
| 6330 | kfree(prm); |
| 6331 | } |
| 6332 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6333 | } |
| 6334 | |
| 6335 | /* Must be called under tgt_host_action_mutex */ |
| 6336 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) |
| 6337 | { |
| 6338 | struct qla_tgt *tgt; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6339 | int rc, i; |
| 6340 | struct qla_qpair_hint *h; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6341 | |
| 6342 | if (!QLA_TGT_MODE_ENABLED()) |
| 6343 | return 0; |
| 6344 | |
Arun Easi | 33c36c0 | 2013-01-30 03:34:41 -0500 | [diff] [blame] | 6345 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
| 6346 | ql_log(ql_log_warn, base_vha, 0xe070, |
| 6347 | "This adapter does not support target mode.\n"); |
| 6348 | return 0; |
| 6349 | } |
| 6350 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6351 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6352 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6353 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6354 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6355 | |
| 6356 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); |
| 6357 | if (!tgt) { |
| 6358 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, |
| 6359 | "Unable to allocate struct qla_tgt\n"); |
| 6360 | return -ENOMEM; |
| 6361 | } |
| 6362 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6363 | tgt->qphints = kcalloc(ha->max_qpairs + 1, |
| 6364 | sizeof(struct qla_qpair_hint), |
| 6365 | GFP_KERNEL); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6366 | if (!tgt->qphints) { |
| 6367 | kfree(tgt); |
| 6368 | ql_log(ql_log_warn, base_vha, 0x0197, |
| 6369 | "Unable to allocate qpair hints.\n"); |
| 6370 | return -ENOMEM; |
| 6371 | } |
| 6372 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6373 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) |
| 6374 | base_vha->host->hostt->supported_mode |= MODE_TARGET; |
| 6375 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6376 | rc = btree_init64(&tgt->lun_qpair_map); |
| 6377 | if (rc) { |
| 6378 | kfree(tgt->qphints); |
| 6379 | kfree(tgt); |
| 6380 | ql_log(ql_log_info, base_vha, 0x0198, |
| 6381 | "Unable to initialize lun_qpair_map btree\n"); |
| 6382 | return -EIO; |
| 6383 | } |
| 6384 | h = &tgt->qphints[0]; |
| 6385 | h->qpair = ha->base_qpair; |
| 6386 | INIT_LIST_HEAD(&h->hint_elem); |
| 6387 | h->cpuid = ha->base_qpair->cpuid; |
| 6388 | list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list); |
| 6389 | |
| 6390 | for (i = 0; i < ha->max_qpairs; i++) { |
| 6391 | unsigned long flags; |
| 6392 | |
| 6393 | struct qla_qpair *qpair = ha->queue_pair_map[i]; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 6394 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6395 | h = &tgt->qphints[i + 1]; |
| 6396 | INIT_LIST_HEAD(&h->hint_elem); |
| 6397 | if (qpair) { |
| 6398 | h->qpair = qpair; |
| 6399 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 6400 | list_add_tail(&h->hint_elem, &qpair->hints_list); |
| 6401 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
| 6402 | h->cpuid = qpair->cpuid; |
| 6403 | } |
| 6404 | } |
| 6405 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6406 | tgt->ha = ha; |
| 6407 | tgt->vha = base_vha; |
| 6408 | init_waitqueue_head(&tgt->waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6409 | INIT_LIST_HEAD(&tgt->del_sess_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6410 | spin_lock_init(&tgt->sess_work_lock); |
| 6411 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); |
| 6412 | INIT_LIST_HEAD(&tgt->sess_works_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6413 | atomic_set(&tgt->tgt_global_resets_count, 0); |
| 6414 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6415 | base_vha->vha_tgt.qla_tgt = tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6416 | |
| 6417 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, |
| 6418 | "qla_target(%d): using 64 Bit PCI addressing", |
| 6419 | base_vha->vp_idx); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6420 | /* 3 is reserved */ |
| 6421 | tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6422 | |
| 6423 | mutex_lock(&qla_tgt_mutex); |
| 6424 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); |
| 6425 | mutex_unlock(&qla_tgt_mutex); |
| 6426 | |
Quinn Tran | f1443ee | 2017-03-15 09:48:51 -0700 | [diff] [blame] | 6427 | if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target) |
| 6428 | ha->tgt.tgt_ops->add_target(base_vha); |
| 6429 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6430 | return 0; |
| 6431 | } |
| 6432 | |
| 6433 | /* Must be called under tgt_host_action_mutex */ |
| 6434 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) |
| 6435 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6436 | if (!vha->vha_tgt.qla_tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6437 | return 0; |
| 6438 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6439 | if (vha->fc_vport) { |
| 6440 | qlt_release(vha->vha_tgt.qla_tgt); |
| 6441 | return 0; |
| 6442 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 6443 | |
| 6444 | /* free left over qfull cmds */ |
| 6445 | qlt_init_term_exchange(vha); |
| 6446 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6447 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", |
| 6448 | vha->host_no, ha); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6449 | qlt_release(vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6450 | |
| 6451 | return 0; |
| 6452 | } |
| 6453 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6454 | void qlt_remove_target_resources(struct qla_hw_data *ha) |
| 6455 | { |
| 6456 | struct scsi_qla_host *node; |
| 6457 | u32 key = 0; |
| 6458 | |
| 6459 | btree_for_each_safe32(&ha->tgt.host_map, key, node) |
| 6460 | btree_remove32(&ha->tgt.host_map, key); |
| 6461 | |
| 6462 | btree_destroy32(&ha->tgt.host_map); |
| 6463 | } |
| 6464 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6465 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, |
| 6466 | unsigned char *b) |
| 6467 | { |
Bart Van Assche | 0943491 | 2019-08-08 20:01:36 -0700 | [diff] [blame] | 6468 | pr_debug("qla2xxx HW vha->node_name: %8phC\n", vha->node_name); |
| 6469 | pr_debug("qla2xxx HW vha->port_name: %8phC\n", vha->port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6470 | put_unaligned_be64(wwpn, b); |
Bart Van Assche | 0943491 | 2019-08-08 20:01:36 -0700 | [diff] [blame] | 6471 | pr_debug("qla2xxx passed configfs WWPN: %8phC\n", b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6472 | } |
| 6473 | |
| 6474 | /** |
| 6475 | * qla_tgt_lport_register - register lport with external module |
| 6476 | * |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6477 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data |
Bart Van Assche | 807eb90 | 2018-10-18 15:45:41 -0700 | [diff] [blame] | 6478 | * @phys_wwpn: physical port WWPN |
| 6479 | * @npiv_wwpn: NPIV WWPN |
| 6480 | * @npiv_wwnn: NPIV WWNN |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 6481 | * @callback: lport initialization callback for tcm_qla2xxx code |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6482 | */ |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6483 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
| 6484 | u64 npiv_wwpn, u64 npiv_wwnn, |
| 6485 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6486 | { |
| 6487 | struct qla_tgt *tgt; |
| 6488 | struct scsi_qla_host *vha; |
| 6489 | struct qla_hw_data *ha; |
| 6490 | struct Scsi_Host *host; |
| 6491 | unsigned long flags; |
| 6492 | int rc; |
| 6493 | u8 b[WWN_SIZE]; |
| 6494 | |
| 6495 | mutex_lock(&qla_tgt_mutex); |
| 6496 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { |
| 6497 | vha = tgt->vha; |
| 6498 | ha = vha->hw; |
| 6499 | |
| 6500 | host = vha->host; |
| 6501 | if (!host) |
| 6502 | continue; |
| 6503 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6504 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
| 6505 | continue; |
| 6506 | |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6507 | if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED) |
| 6508 | continue; |
| 6509 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6510 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6511 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6512 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
| 6513 | host->host_no); |
| 6514 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6515 | continue; |
| 6516 | } |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6517 | if (tgt->tgt_stop) { |
| 6518 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", |
| 6519 | host->host_no); |
| 6520 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6521 | continue; |
| 6522 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6523 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6524 | |
| 6525 | if (!scsi_host_get(host)) { |
| 6526 | ql_dbg(ql_dbg_tgt, vha, 0xe068, |
| 6527 | "Unable to scsi_host_get() for" |
| 6528 | " qla2xxx scsi_host\n"); |
| 6529 | continue; |
| 6530 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6531 | qlt_lport_dump(vha, phys_wwpn, b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6532 | |
| 6533 | if (memcmp(vha->port_name, b, WWN_SIZE)) { |
| 6534 | scsi_host_put(host); |
| 6535 | continue; |
| 6536 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6537 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
| 6538 | if (rc != 0) |
| 6539 | scsi_host_put(host); |
| 6540 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6541 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6542 | return rc; |
| 6543 | } |
| 6544 | mutex_unlock(&qla_tgt_mutex); |
| 6545 | |
| 6546 | return -ENODEV; |
| 6547 | } |
| 6548 | EXPORT_SYMBOL(qlt_lport_register); |
| 6549 | |
| 6550 | /** |
| 6551 | * qla_tgt_lport_deregister - Degister lport |
| 6552 | * |
| 6553 | * @vha: Registered scsi_qla_host pointer |
| 6554 | */ |
| 6555 | void qlt_lport_deregister(struct scsi_qla_host *vha) |
| 6556 | { |
| 6557 | struct qla_hw_data *ha = vha->hw; |
| 6558 | struct Scsi_Host *sh = vha->host; |
| 6559 | /* |
| 6560 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data |
| 6561 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6562 | vha->vha_tgt.target_lport_ptr = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6563 | ha->tgt.tgt_ops = NULL; |
| 6564 | /* |
| 6565 | * Release the Scsi_Host reference for the underlying qla2xxx host |
| 6566 | */ |
| 6567 | scsi_host_put(sh); |
| 6568 | } |
| 6569 | EXPORT_SYMBOL(qlt_lport_deregister); |
| 6570 | |
| 6571 | /* Must be called under HW lock */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6572 | void qlt_set_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6573 | { |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6574 | switch (vha->qlini_mode) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6575 | case QLA2XXX_INI_MODE_DISABLED: |
| 6576 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6577 | vha->host->active_mode = MODE_TARGET; |
| 6578 | break; |
| 6579 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6580 | vha->host->active_mode = MODE_INITIATOR; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6581 | break; |
| 6582 | case QLA2XXX_INI_MODE_DUAL: |
| 6583 | vha->host->active_mode = MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6584 | break; |
| 6585 | default: |
| 6586 | break; |
| 6587 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6588 | } |
| 6589 | |
| 6590 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6591 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6592 | { |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6593 | switch (vha->qlini_mode) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6594 | case QLA2XXX_INI_MODE_DISABLED: |
| 6595 | vha->host->active_mode = MODE_UNKNOWN; |
| 6596 | break; |
| 6597 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6598 | vha->host->active_mode = MODE_INITIATOR; |
| 6599 | break; |
| 6600 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6601 | case QLA2XXX_INI_MODE_DUAL: |
| 6602 | vha->host->active_mode = MODE_INITIATOR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6603 | break; |
| 6604 | default: |
| 6605 | break; |
| 6606 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6607 | } |
| 6608 | |
| 6609 | /* |
| 6610 | * qla_tgt_enable_vha - NO LOCK HELD |
| 6611 | * |
| 6612 | * host_reset, bring up w/ Target Mode Enabled |
| 6613 | */ |
| 6614 | void |
| 6615 | qlt_enable_vha(struct scsi_qla_host *vha) |
| 6616 | { |
| 6617 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6618 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6619 | unsigned long flags; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6620 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6621 | |
| 6622 | if (!tgt) { |
| 6623 | ql_dbg(ql_dbg_tgt, vha, 0xe069, |
| 6624 | "Unable to locate qla_tgt pointer from" |
| 6625 | " struct qla_hw_data\n"); |
| 6626 | dump_stack(); |
| 6627 | return; |
| 6628 | } |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6629 | if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED) |
| 6630 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6631 | |
Quinn Tran | 178235f | 2019-07-26 09:07:29 -0700 | [diff] [blame] | 6632 | if (ha->tgt.num_act_qpairs > ha->max_qpairs) |
| 6633 | ha->tgt.num_act_qpairs = ha->max_qpairs; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6634 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6635 | tgt->tgt_stopped = 0; |
| 6636 | qlt_set_mode(vha); |
| 6637 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6638 | |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 6639 | mutex_lock(&ha->optrom_mutex); |
| 6640 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021, |
| 6641 | "%s.\n", __func__); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6642 | if (vha->vp_idx) { |
| 6643 | qla24xx_disable_vp(vha); |
| 6644 | qla24xx_enable_vp(vha); |
| 6645 | } else { |
| 6646 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 6647 | qla2xxx_wake_dpc(base_vha); |
Bart Van Assche | e6803ef | 2019-08-08 20:01:52 -0700 | [diff] [blame] | 6648 | WARN_ON_ONCE(qla2x00_wait_for_hba_online(base_vha) != |
| 6649 | QLA_SUCCESS); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6650 | } |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 6651 | mutex_unlock(&ha->optrom_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6652 | } |
| 6653 | EXPORT_SYMBOL(qlt_enable_vha); |
| 6654 | |
| 6655 | /* |
| 6656 | * qla_tgt_disable_vha - NO LOCK HELD |
| 6657 | * |
| 6658 | * Disable Target Mode and reset the adapter |
| 6659 | */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6660 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6661 | { |
| 6662 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6663 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6664 | unsigned long flags; |
| 6665 | |
| 6666 | if (!tgt) { |
| 6667 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, |
| 6668 | "Unable to locate qla_tgt pointer from" |
| 6669 | " struct qla_hw_data\n"); |
| 6670 | dump_stack(); |
| 6671 | return; |
| 6672 | } |
| 6673 | |
| 6674 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6675 | qlt_clear_mode(vha); |
| 6676 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6677 | |
| 6678 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6679 | qla2xxx_wake_dpc(vha); |
Bart Van Assche | e6803ef | 2019-08-08 20:01:52 -0700 | [diff] [blame] | 6680 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) |
| 6681 | ql_dbg(ql_dbg_tgt, vha, 0xe081, |
| 6682 | "qla2x00_wait_for_hba_online() failed\n"); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6683 | } |
| 6684 | |
| 6685 | /* |
| 6686 | * Called from qla_init.c:qla24xx_vport_create() contex to setup |
| 6687 | * the target mode specific struct scsi_qla_host and struct qla_hw_data |
| 6688 | * members. |
| 6689 | */ |
| 6690 | void |
| 6691 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) |
| 6692 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6693 | vha->vha_tgt.qla_tgt = NULL; |
| 6694 | |
| 6695 | mutex_init(&vha->vha_tgt.tgt_mutex); |
| 6696 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6697 | |
| 6698 | qlt_clear_mode(vha); |
| 6699 | |
| 6700 | /* |
| 6701 | * NOTE: Currently the value is kept the same for <24xx and |
| 6702 | * >=24xx ISPs. If it is necessary to change it, |
| 6703 | * the check should be added for specific ISPs, |
| 6704 | * assigning the value appropriately. |
| 6705 | */ |
| 6706 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6707 | |
| 6708 | qlt_add_target(ha, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6709 | } |
| 6710 | |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6711 | u8 |
| 6712 | qlt_rff_id(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6713 | { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6714 | u8 fc4_feature = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6715 | /* |
| 6716 | * FC-4 Feature bit 0 indicates target functionality to the name server. |
| 6717 | */ |
| 6718 | if (qla_tgt_mode_enabled(vha)) { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6719 | fc4_feature = BIT_0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6720 | } else if (qla_ini_mode_enabled(vha)) { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6721 | fc4_feature = BIT_1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6722 | } else if (qla_dual_mode_enabled(vha)) |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6723 | fc4_feature = BIT_0 | BIT_1; |
| 6724 | |
| 6725 | return fc4_feature; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | /* |
| 6729 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. |
| 6730 | * @ha: HA context |
| 6731 | * |
| 6732 | * Beginning of ATIO ring has initialization control block already built |
| 6733 | * by nvram config routine. |
| 6734 | * |
| 6735 | * Returns 0 on success. |
| 6736 | */ |
| 6737 | void |
| 6738 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) |
| 6739 | { |
| 6740 | struct qla_hw_data *ha = vha->hw; |
| 6741 | uint16_t cnt; |
| 6742 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; |
| 6743 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6744 | if (qla_ini_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6745 | return; |
| 6746 | |
| 6747 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { |
| 6748 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6749 | pkt++; |
| 6750 | } |
| 6751 | |
| 6752 | } |
| 6753 | |
| 6754 | /* |
| 6755 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. |
| 6756 | * @ha: SCSI driver HA context |
| 6757 | */ |
| 6758 | void |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6759 | 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] | 6760 | { |
| 6761 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6762 | struct atio_from_isp *pkt; |
| 6763 | int cnt, i; |
| 6764 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6765 | if (!ha->flags.fw_started) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6766 | return; |
| 6767 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6768 | while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) || |
| 6769 | fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6770 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6771 | cnt = pkt->u.raw.entry_count; |
| 6772 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6773 | if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) { |
| 6774 | /* |
| 6775 | * This packet is corrupted. The header + payload |
| 6776 | * can not be trusted. There is no point in passing |
| 6777 | * it further up. |
| 6778 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6779 | ql_log(ql_log_warn, vha, 0xd03c, |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6780 | "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n", |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6781 | &pkt->u.isp24.fcp_hdr.s_id, |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6782 | be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id), |
| 6783 | le32_to_cpu(pkt->u.isp24.exchange_addr), pkt); |
| 6784 | |
| 6785 | adjust_corrupted_atio(pkt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6786 | qlt_send_term_exchange(ha->base_qpair, NULL, pkt, |
| 6787 | ha_locked, 0); |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6788 | } else { |
| 6789 | qlt_24xx_atio_pkt_all_vps(vha, |
| 6790 | (struct atio_from_isp *)pkt, ha_locked); |
| 6791 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6792 | |
| 6793 | for (i = 0; i < cnt; i++) { |
| 6794 | ha->tgt.atio_ring_index++; |
| 6795 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { |
| 6796 | ha->tgt.atio_ring_index = 0; |
| 6797 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 6798 | } else |
| 6799 | ha->tgt.atio_ring_ptr++; |
| 6800 | |
| 6801 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6802 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6803 | } |
| 6804 | wmb(); |
| 6805 | } |
| 6806 | |
| 6807 | /* Adjust ring index */ |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6808 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6809 | } |
| 6810 | |
| 6811 | void |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6812 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6813 | { |
| 6814 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6815 | struct qla_msix_entry *msix = &ha->msix_entries[2]; |
| 6816 | struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb; |
| 6817 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6818 | if (!QLA_TGT_MODE_ENABLED()) |
| 6819 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6820 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6821 | WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0); |
| 6822 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0); |
| 6823 | RD_REG_DWORD(ISP_ATIO_Q_OUT(vha)); |
| 6824 | |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6825 | if (ha->flags.msix_enabled) { |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 6826 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) { |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6827 | if (IS_QLA2071(ha)) { |
| 6828 | /* 4 ports Baker: Enable Interrupt Handshake */ |
| 6829 | icb->msix_atio = 0; |
| 6830 | icb->firmware_options_2 |= BIT_26; |
| 6831 | } else { |
| 6832 | icb->msix_atio = cpu_to_le16(msix->entry); |
| 6833 | icb->firmware_options_2 &= ~BIT_26; |
| 6834 | } |
| 6835 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6836 | "Registering ICB vector 0x%x for atio que.\n", |
| 6837 | msix->entry); |
| 6838 | } |
| 6839 | } else { |
| 6840 | /* INTx|MSI */ |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 6841 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) { |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6842 | icb->msix_atio = 0; |
| 6843 | icb->firmware_options_2 |= BIT_26; |
| 6844 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6845 | "%s: Use INTx for ATIOQ.\n", __func__); |
| 6846 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6847 | } |
| 6848 | } |
| 6849 | |
| 6850 | void |
| 6851 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) |
| 6852 | { |
| 6853 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6854 | u32 tmp; |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6855 | |
| 6856 | if (!QLA_TGT_MODE_ENABLED()) |
| 6857 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6858 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6859 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6860 | if (!ha->tgt.saved_set) { |
| 6861 | /* We save only once */ |
| 6862 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6863 | ha->tgt.saved_firmware_options_1 = |
| 6864 | nv->firmware_options_1; |
| 6865 | ha->tgt.saved_firmware_options_2 = |
| 6866 | nv->firmware_options_2; |
| 6867 | ha->tgt.saved_firmware_options_3 = |
| 6868 | nv->firmware_options_3; |
| 6869 | ha->tgt.saved_set = 1; |
| 6870 | } |
| 6871 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6872 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6873 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6874 | else /* dual */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6875 | nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6876 | |
| 6877 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6878 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6879 | |
| 6880 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6881 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6882 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6883 | |
| 6884 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6885 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6886 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6887 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6888 | if (ql2xtgt_tape_enable) |
| 6889 | /* Enable FC Tape support */ |
| 6890 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6891 | else |
| 6892 | /* Disable FC Tape support */ |
| 6893 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6894 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6895 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6896 | nv->host_p &= cpu_to_le32(~BIT_10); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6897 | |
| 6898 | /* |
| 6899 | * clear BIT 15 explicitly as we have seen at least |
| 6900 | * a couple of instances where this was set and this |
| 6901 | * was causing the firmware to not be initialized. |
| 6902 | */ |
| 6903 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6904 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6905 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6906 | |
| 6907 | if (IS_QLA25XX(ha)) { |
| 6908 | /* Change Loop-prefer to Pt-Pt */ |
| 6909 | tmp = ~(BIT_4|BIT_5|BIT_6); |
| 6910 | nv->firmware_options_2 &= cpu_to_le32(tmp); |
| 6911 | tmp = P2P << 4; |
| 6912 | nv->firmware_options_2 |= cpu_to_le32(tmp); |
| 6913 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6914 | } else { |
| 6915 | if (ha->tgt.saved_set) { |
| 6916 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6917 | nv->firmware_options_1 = |
| 6918 | ha->tgt.saved_firmware_options_1; |
| 6919 | nv->firmware_options_2 = |
| 6920 | ha->tgt.saved_firmware_options_2; |
| 6921 | nv->firmware_options_3 = |
| 6922 | ha->tgt.saved_firmware_options_3; |
| 6923 | } |
| 6924 | return; |
| 6925 | } |
| 6926 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6927 | if (ha->base_qpair->enable_class_2) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6928 | if (vha->flags.init_done) |
| 6929 | fc_host_supported_classes(vha->host) = |
| 6930 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6931 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6932 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6933 | } else { |
| 6934 | if (vha->flags.init_done) |
| 6935 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6936 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6937 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6938 | } |
| 6939 | } |
| 6940 | |
| 6941 | void |
| 6942 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6943 | struct init_cb_24xx *icb) |
| 6944 | { |
| 6945 | struct qla_hw_data *ha = vha->hw; |
| 6946 | |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6947 | if (!QLA_TGT_MODE_ENABLED()) |
| 6948 | return; |
| 6949 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6950 | if (ha->tgt.node_name_set) { |
| 6951 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6952 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6953 | } |
| 6954 | } |
| 6955 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6956 | void |
| 6957 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) |
| 6958 | { |
| 6959 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6960 | u32 tmp; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6961 | |
| 6962 | if (!QLA_TGT_MODE_ENABLED()) |
| 6963 | return; |
| 6964 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6965 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6966 | if (!ha->tgt.saved_set) { |
| 6967 | /* We save only once */ |
| 6968 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6969 | ha->tgt.saved_firmware_options_1 = |
| 6970 | nv->firmware_options_1; |
| 6971 | ha->tgt.saved_firmware_options_2 = |
| 6972 | nv->firmware_options_2; |
| 6973 | ha->tgt.saved_firmware_options_3 = |
| 6974 | nv->firmware_options_3; |
| 6975 | ha->tgt.saved_set = 1; |
| 6976 | } |
| 6977 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6978 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6979 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6980 | else /* dual */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6981 | nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6982 | |
| 6983 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6984 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6985 | |
| 6986 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6987 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6988 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6989 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6990 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6991 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6992 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6993 | /* |
| 6994 | * clear BIT 15 explicitly as we have seen at |
| 6995 | * least a couple of instances where this was set |
| 6996 | * and this was causing the firmware to not be |
| 6997 | * initialized. |
| 6998 | */ |
| 6999 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 7000 | if (ql2xtgt_tape_enable) |
| 7001 | /* Enable FC tape support */ |
| 7002 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 7003 | else |
| 7004 | /* Disable FC tape support */ |
| 7005 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 7006 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7007 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7008 | nv->host_p &= cpu_to_le32(~BIT_10); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7009 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7010 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 7011 | |
| 7012 | /* Change Loop-prefer to Pt-Pt */ |
| 7013 | tmp = ~(BIT_4|BIT_5|BIT_6); |
| 7014 | nv->firmware_options_2 &= cpu_to_le32(tmp); |
| 7015 | tmp = P2P << 4; |
| 7016 | nv->firmware_options_2 |= cpu_to_le32(tmp); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7017 | } else { |
| 7018 | if (ha->tgt.saved_set) { |
| 7019 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 7020 | nv->firmware_options_1 = |
| 7021 | ha->tgt.saved_firmware_options_1; |
| 7022 | nv->firmware_options_2 = |
| 7023 | ha->tgt.saved_firmware_options_2; |
| 7024 | nv->firmware_options_3 = |
| 7025 | ha->tgt.saved_firmware_options_3; |
| 7026 | } |
| 7027 | return; |
| 7028 | } |
| 7029 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7030 | if (ha->base_qpair->enable_class_2) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7031 | if (vha->flags.init_done) |
| 7032 | fc_host_supported_classes(vha->host) = |
| 7033 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 7034 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7035 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7036 | } else { |
| 7037 | if (vha->flags.init_done) |
| 7038 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 7039 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7040 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7041 | } |
| 7042 | } |
| 7043 | |
| 7044 | void |
| 7045 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 7046 | struct init_cb_81xx *icb) |
| 7047 | { |
| 7048 | struct qla_hw_data *ha = vha->hw; |
| 7049 | |
| 7050 | if (!QLA_TGT_MODE_ENABLED()) |
| 7051 | return; |
| 7052 | |
| 7053 | if (ha->tgt.node_name_set) { |
| 7054 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7055 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7056 | } |
| 7057 | } |
| 7058 | |
| 7059 | void |
| 7060 | qlt_83xx_iospace_config(struct qla_hw_data *ha) |
| 7061 | { |
| 7062 | if (!QLA_TGT_MODE_ENABLED()) |
| 7063 | return; |
| 7064 | |
| 7065 | ha->msix_count += 1; /* For ATIO Q */ |
| 7066 | } |
| 7067 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7068 | |
| 7069 | void |
| 7070 | qlt_modify_vp_config(struct scsi_qla_host *vha, |
| 7071 | struct vp_config_entry_24xx *vpmod) |
| 7072 | { |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7073 | /* enable target mode. Bit5 = 1 => disable */ |
| 7074 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7075 | vpmod->options_idx1 &= ~BIT_5; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 7076 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7077 | /* Disable ini mode, if requested. bit4 = 1 => disable */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 7078 | if (qla_tgt_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7079 | vpmod->options_idx1 &= ~BIT_4; |
| 7080 | } |
| 7081 | |
| 7082 | void |
| 7083 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) |
| 7084 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7085 | int rc; |
| 7086 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7087 | if (!QLA_TGT_MODE_ENABLED()) |
| 7088 | return; |
| 7089 | |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 7090 | if ((ql2xenablemsix == 0) || IS_QLA83XX(ha) || IS_QLA27XX(ha) || |
| 7091 | IS_QLA28XX(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7092 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
| 7093 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; |
| 7094 | } else { |
| 7095 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; |
| 7096 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; |
| 7097 | } |
| 7098 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 7099 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
| 7100 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7101 | |
| 7102 | INIT_LIST_HEAD(&base_vha->unknown_atio_list); |
| 7103 | INIT_DELAYED_WORK(&base_vha->unknown_atio_work, |
| 7104 | qlt_unknown_atio_work_fn); |
| 7105 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7106 | qlt_clear_mode(base_vha); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7107 | |
| 7108 | rc = btree_init32(&ha->tgt.host_map); |
| 7109 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7110 | ql_log(ql_log_info, base_vha, 0xd03d, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7111 | "Unable to initialize ha->host_map btree\n"); |
| 7112 | |
| 7113 | qlt_update_vp_map(base_vha, SET_VP_IDX); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7114 | } |
| 7115 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7116 | irqreturn_t |
| 7117 | qla83xx_msix_atio_q(int irq, void *dev_id) |
| 7118 | { |
| 7119 | struct rsp_que *rsp; |
| 7120 | scsi_qla_host_t *vha; |
| 7121 | struct qla_hw_data *ha; |
| 7122 | unsigned long flags; |
| 7123 | |
| 7124 | rsp = (struct rsp_que *) dev_id; |
| 7125 | ha = rsp->hw; |
| 7126 | vha = pci_get_drvdata(ha->pdev); |
| 7127 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7128 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7129 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7130 | qlt_24xx_process_atio_queue(vha, 0); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7131 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7132 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7133 | |
| 7134 | return IRQ_HANDLED; |
| 7135 | } |
| 7136 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7137 | static void |
| 7138 | qlt_handle_abts_recv_work(struct work_struct *work) |
| 7139 | { |
| 7140 | struct qla_tgt_sess_op *op = container_of(work, |
| 7141 | struct qla_tgt_sess_op, work); |
| 7142 | scsi_qla_host_t *vha = op->vha; |
| 7143 | struct qla_hw_data *ha = vha->hw; |
| 7144 | unsigned long flags; |
| 7145 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7146 | if (qla2x00_reset_active(vha) || |
| 7147 | (op->chip_reset != ha->base_qpair->chip_reset)) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7148 | return; |
| 7149 | |
| 7150 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 7151 | qlt_24xx_process_atio_queue(vha, 0); |
| 7152 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 7153 | |
| 7154 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7155 | qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7156 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | ae940f2 | 2017-03-15 09:48:44 -0700 | [diff] [blame] | 7157 | |
| 7158 | kfree(op); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7159 | } |
| 7160 | |
| 7161 | void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7162 | qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp, |
| 7163 | response_t *pkt) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7164 | { |
| 7165 | struct qla_tgt_sess_op *op; |
| 7166 | |
| 7167 | op = kzalloc(sizeof(*op), GFP_ATOMIC); |
| 7168 | |
| 7169 | if (!op) { |
| 7170 | /* do not reach for ATIO queue here. This is best effort err |
| 7171 | * recovery at this point. |
| 7172 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7173 | qlt_response_pkt_all_vps(vha, rsp, pkt); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7174 | return; |
| 7175 | } |
| 7176 | |
| 7177 | memcpy(&op->atio, pkt, sizeof(*pkt)); |
| 7178 | op->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7179 | op->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7180 | op->rsp = rsp; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7181 | INIT_WORK(&op->work, qlt_handle_abts_recv_work); |
| 7182 | queue_work(qla_tgt_wq, &op->work); |
| 7183 | return; |
| 7184 | } |
| 7185 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7186 | int |
| 7187 | qlt_mem_alloc(struct qla_hw_data *ha) |
| 7188 | { |
| 7189 | if (!QLA_TGT_MODE_ENABLED()) |
| 7190 | return 0; |
| 7191 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7192 | ha->tgt.tgt_vp_map = kcalloc(MAX_MULTI_ID_FABRIC, |
| 7193 | sizeof(struct qla_tgt_vp_map), |
| 7194 | GFP_KERNEL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7195 | if (!ha->tgt.tgt_vp_map) |
| 7196 | return -ENOMEM; |
| 7197 | |
| 7198 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 7199 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), |
| 7200 | &ha->tgt.atio_dma, GFP_KERNEL); |
| 7201 | if (!ha->tgt.atio_ring) { |
| 7202 | kfree(ha->tgt.tgt_vp_map); |
| 7203 | return -ENOMEM; |
| 7204 | } |
| 7205 | return 0; |
| 7206 | } |
| 7207 | |
| 7208 | void |
| 7209 | qlt_mem_free(struct qla_hw_data *ha) |
| 7210 | { |
| 7211 | if (!QLA_TGT_MODE_ENABLED()) |
| 7212 | return; |
| 7213 | |
| 7214 | if (ha->tgt.atio_ring) { |
| 7215 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * |
| 7216 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, |
| 7217 | ha->tgt.atio_dma); |
| 7218 | } |
Bart Van Assche | 5365bf9 | 2019-04-17 14:44:22 -0700 | [diff] [blame] | 7219 | ha->tgt.atio_ring = NULL; |
| 7220 | ha->tgt.atio_dma = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7221 | kfree(ha->tgt.tgt_vp_map); |
Bart Van Assche | 5365bf9 | 2019-04-17 14:44:22 -0700 | [diff] [blame] | 7222 | ha->tgt.tgt_vp_map = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7223 | } |
| 7224 | |
| 7225 | /* vport_slock to be held by the caller */ |
| 7226 | void |
| 7227 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) |
| 7228 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7229 | void *slot; |
| 7230 | u32 key; |
| 7231 | int rc; |
| 7232 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7233 | if (!QLA_TGT_MODE_ENABLED()) |
| 7234 | return; |
| 7235 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7236 | key = vha->d_id.b24; |
| 7237 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7238 | switch (cmd) { |
| 7239 | case SET_VP_IDX: |
| 7240 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; |
| 7241 | break; |
| 7242 | case SET_AL_PA: |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7243 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7244 | if (!slot) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7245 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7246 | "Save vha in host_map %p %06x\n", vha, key); |
| 7247 | rc = btree_insert32(&vha->hw->tgt.host_map, |
| 7248 | key, vha, GFP_ATOMIC); |
| 7249 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7250 | ql_log(ql_log_info, vha, 0xd03e, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7251 | "Unable to insert s_id into host_map: %06x\n", |
| 7252 | key); |
| 7253 | return; |
| 7254 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7255 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019, |
| 7256 | "replace existing vha in host_map %p %06x\n", vha, key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7257 | btree_update32(&vha->hw->tgt.host_map, key, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7258 | break; |
| 7259 | case RESET_VP_IDX: |
| 7260 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; |
| 7261 | break; |
| 7262 | case RESET_AL_PA: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7263 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7264 | "clear vha in host_map %p %06x\n", vha, key); |
| 7265 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7266 | if (slot) |
| 7267 | btree_remove32(&vha->hw->tgt.host_map, key); |
| 7268 | vha->d_id.b24 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7269 | break; |
| 7270 | } |
| 7271 | } |
| 7272 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7273 | void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id) |
| 7274 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7275 | |
| 7276 | if (!vha->d_id.b24) { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7277 | vha->d_id = id; |
| 7278 | qlt_update_vp_map(vha, SET_AL_PA); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7279 | } else if (vha->d_id.b24 != id.b24) { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7280 | qlt_update_vp_map(vha, RESET_AL_PA); |
| 7281 | vha->d_id = id; |
| 7282 | qlt_update_vp_map(vha, SET_AL_PA); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7283 | } |
| 7284 | } |
| 7285 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7286 | static int __init qlt_parse_ini_mode(void) |
| 7287 | { |
| 7288 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) |
| 7289 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
| 7290 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) |
| 7291 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; |
| 7292 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) |
| 7293 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7294 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0) |
| 7295 | ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7296 | else |
| 7297 | return false; |
| 7298 | |
| 7299 | return true; |
| 7300 | } |
| 7301 | |
| 7302 | int __init qlt_init(void) |
| 7303 | { |
| 7304 | int ret; |
| 7305 | |
Bart Van Assche | bc04459 | 2019-04-17 14:44:37 -0700 | [diff] [blame] | 7306 | BUILD_BUG_ON(sizeof(struct ctio7_to_24xx) != 64); |
| 7307 | BUILD_BUG_ON(sizeof(struct ctio_to_2xxx) != 64); |
| 7308 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7309 | if (!qlt_parse_ini_mode()) { |
| 7310 | ql_log(ql_log_fatal, NULL, 0xe06b, |
| 7311 | "qlt_parse_ini_mode() failed\n"); |
| 7312 | return -EINVAL; |
| 7313 | } |
| 7314 | |
| 7315 | if (!QLA_TGT_MODE_ENABLED()) |
| 7316 | return 0; |
| 7317 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7318 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
| 7319 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct |
| 7320 | qla_tgt_mgmt_cmd), 0, NULL); |
| 7321 | if (!qla_tgt_mgmt_cmd_cachep) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7322 | ql_log(ql_log_fatal, NULL, 0xd04b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7323 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 7324 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7325 | } |
| 7326 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7327 | qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep", |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 7328 | sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t), |
| 7329 | 0, NULL); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7330 | |
| 7331 | if (!qla_tgt_plogi_cachep) { |
| 7332 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 7333 | "kmem_cache_create for qla_tgt_plogi_cachep failed\n"); |
| 7334 | ret = -ENOMEM; |
| 7335 | goto out_mgmt_cmd_cachep; |
| 7336 | } |
| 7337 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7338 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, |
| 7339 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); |
| 7340 | if (!qla_tgt_mgmt_cmd_mempool) { |
| 7341 | ql_log(ql_log_fatal, NULL, 0xe06e, |
| 7342 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); |
| 7343 | ret = -ENOMEM; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7344 | goto out_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7345 | } |
| 7346 | |
| 7347 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); |
| 7348 | if (!qla_tgt_wq) { |
| 7349 | ql_log(ql_log_fatal, NULL, 0xe06f, |
| 7350 | "alloc_workqueue for qla_tgt_wq failed\n"); |
| 7351 | ret = -ENOMEM; |
| 7352 | goto out_cmd_mempool; |
| 7353 | } |
| 7354 | /* |
| 7355 | * Return 1 to signal that initiator-mode is being disabled |
| 7356 | */ |
| 7357 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; |
| 7358 | |
| 7359 | out_cmd_mempool: |
| 7360 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7361 | out_plogi_cachep: |
| 7362 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7363 | out_mgmt_cmd_cachep: |
| 7364 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7365 | return ret; |
| 7366 | } |
| 7367 | |
| 7368 | void qlt_exit(void) |
| 7369 | { |
| 7370 | if (!QLA_TGT_MODE_ENABLED()) |
| 7371 | return; |
| 7372 | |
| 7373 | destroy_workqueue(qla_tgt_wq); |
| 7374 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7375 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7376 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7377 | } |