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> |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 30 | |
| 31 | #include "qla_def.h" |
| 32 | #include "qla_target.h" |
| 33 | |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 34 | static int ql2xtgt_tape_enable; |
| 35 | module_param(ql2xtgt_tape_enable, int, S_IRUGO|S_IWUSR); |
| 36 | MODULE_PARM_DESC(ql2xtgt_tape_enable, |
| 37 | "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER."); |
| 38 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 39 | static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED; |
| 40 | module_param(qlini_mode, charp, S_IRUGO); |
| 41 | MODULE_PARM_DESC(qlini_mode, |
| 42 | "Determines when initiator mode will be enabled. Possible values: " |
| 43 | "\"exclusive\" - initiator mode will be enabled on load, " |
| 44 | "disabled on enabling target mode and then on disabling target mode " |
| 45 | "enabled back; " |
| 46 | "\"disabled\" - initiator mode will never be enabled; " |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 47 | "\"dual\" - Initiator Modes will be enabled. Target Mode can be activated " |
| 48 | "when ready " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 49 | "\"enabled\" (default) - initiator mode will always stay enabled."); |
| 50 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 51 | static int ql_dm_tgt_ex_pct = 0; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 52 | module_param(ql_dm_tgt_ex_pct, int, S_IRUGO|S_IWUSR); |
| 53 | MODULE_PARM_DESC(ql_dm_tgt_ex_pct, |
| 54 | "For Dual Mode (qlini_mode=dual), this parameter determines " |
| 55 | "the percentage of exchanges/cmds FW will allocate resources " |
| 56 | "for Target mode."); |
| 57 | |
Quinn Tran | 09620ee | 2017-06-13 20:47:20 -0700 | [diff] [blame] | 58 | int ql2xuctrlirq = 1; |
| 59 | module_param(ql2xuctrlirq, int, 0644); |
| 60 | MODULE_PARM_DESC(ql2xuctrlirq, |
| 61 | "User to control IRQ placement via smp_affinity." |
| 62 | "Valid with qlini_mode=disabled." |
| 63 | "1(default): enable"); |
| 64 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 65 | int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 66 | |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 67 | static int qla_sam_status = SAM_STAT_BUSY; |
| 68 | static int tc_sam_status = SAM_STAT_TASK_SET_FULL; /* target core */ |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 69 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 70 | /* |
| 71 | * From scsi/fc/fc_fcp.h |
| 72 | */ |
| 73 | enum fcp_resp_rsp_codes { |
| 74 | FCP_TMF_CMPL = 0, |
| 75 | FCP_DATA_LEN_INVALID = 1, |
| 76 | FCP_CMND_FIELDS_INVALID = 2, |
| 77 | FCP_DATA_PARAM_MISMATCH = 3, |
| 78 | FCP_TMF_REJECTED = 4, |
| 79 | FCP_TMF_FAILED = 5, |
| 80 | FCP_TMF_INVALID_LUN = 9, |
| 81 | }; |
| 82 | |
| 83 | /* |
| 84 | * fc_pri_ta from scsi/fc/fc_fcp.h |
| 85 | */ |
| 86 | #define FCP_PTA_SIMPLE 0 /* simple task attribute */ |
| 87 | #define FCP_PTA_HEADQ 1 /* head of queue task attribute */ |
| 88 | #define FCP_PTA_ORDERED 2 /* ordered task attribute */ |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 89 | #define FCP_PTA_ACA 4 /* auto. contingent allegiance */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 90 | #define FCP_PTA_MASK 7 /* mask for task attribute field */ |
| 91 | #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */ |
| 92 | #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */ |
| 93 | |
| 94 | /* |
| 95 | * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which |
| 96 | * must be called under HW lock and could unlock/lock it inside. |
| 97 | * It isn't an issue, since in the current implementation on the time when |
| 98 | * those functions are called: |
| 99 | * |
| 100 | * - Either context is IRQ and only IRQ handler can modify HW data, |
| 101 | * including rings related fields, |
| 102 | * |
| 103 | * - Or access to target mode variables from struct qla_tgt doesn't |
| 104 | * cross those functions boundaries, except tgt_stop, which |
| 105 | * additionally protected by irq_cmd_count. |
| 106 | */ |
| 107 | /* Predefs for callbacks handed to qla2xxx LLD */ |
| 108 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 109 | struct atio_from_isp *pkt, uint8_t); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 110 | static void qlt_response_pkt(struct scsi_qla_host *ha, struct rsp_que *rsp, |
| 111 | response_t *pkt); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 112 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 113 | int fn, void *iocb, int flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 114 | 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] | 115 | *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 116 | static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 117 | struct atio_from_isp *atio, uint16_t status, int qfull); |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 118 | static void qlt_disable_vha(struct scsi_qla_host *vha); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 119 | static void qlt_clear_tgt_db(struct qla_tgt *tgt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 120 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 121 | struct imm_ntfy_from_isp *ntfy, |
| 122 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 123 | 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] | 124 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 125 | struct imm_ntfy_from_isp *imm, int ha_locked); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 126 | static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha, |
| 127 | fc_port_t *fcport, bool local); |
| 128 | void qlt_unreg_sess(struct fc_port *sess); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 129 | static void qlt_24xx_handle_abts(struct scsi_qla_host *, |
| 130 | struct abts_recv_from_24xx *); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 131 | static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *, |
| 132 | uint16_t); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 133 | static int qlt_check_reserve_free_req(struct qla_qpair *qpair, uint32_t); |
| 134 | static inline uint32_t qlt_make_handle(struct qla_qpair *); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 135 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 136 | /* |
| 137 | * Global Variables |
| 138 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 139 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; |
Quinn Tran | b5d1531 | 2017-08-30 10:16:49 -0700 | [diff] [blame] | 140 | struct kmem_cache *qla_tgt_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 141 | static mempool_t *qla_tgt_mgmt_cmd_mempool; |
| 142 | static struct workqueue_struct *qla_tgt_wq; |
| 143 | static DEFINE_MUTEX(qla_tgt_mutex); |
| 144 | static LIST_HEAD(qla_tgt_glist); |
| 145 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 146 | static const char *prot_op_str(u32 prot_op) |
| 147 | { |
| 148 | switch (prot_op) { |
| 149 | case TARGET_PROT_NORMAL: return "NORMAL"; |
| 150 | case TARGET_PROT_DIN_INSERT: return "DIN_INSERT"; |
| 151 | case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT"; |
| 152 | case TARGET_PROT_DIN_STRIP: return "DIN_STRIP"; |
| 153 | case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP"; |
| 154 | case TARGET_PROT_DIN_PASS: return "DIN_PASS"; |
| 155 | case TARGET_PROT_DOUT_PASS: return "DOUT_PASS"; |
| 156 | default: return "UNKNOWN"; |
| 157 | } |
| 158 | } |
| 159 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 160 | /* This API intentionally takes dest as a parameter, rather than returning |
| 161 | * int value to avoid caller forgetting to issue wmb() after the store */ |
| 162 | void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest) |
| 163 | { |
| 164 | scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev); |
| 165 | *dest = atomic_inc_return(&base_vha->generation_tick); |
| 166 | /* memory barrier */ |
| 167 | wmb(); |
| 168 | } |
| 169 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 170 | /* Might release hw lock, then reaquire!! */ |
| 171 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) |
| 172 | { |
| 173 | /* Send marker if required */ |
| 174 | if (unlikely(vha->marker_needed != 0)) { |
| 175 | int rc = qla2x00_issue_marker(vha, vha_locked); |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 176 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 177 | if (rc != QLA_SUCCESS) { |
| 178 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, |
| 179 | "qla_target(%d): issue_marker() failed\n", |
| 180 | vha->vp_idx); |
| 181 | } |
| 182 | return rc; |
| 183 | } |
| 184 | return QLA_SUCCESS; |
| 185 | } |
| 186 | |
| 187 | static inline |
| 188 | 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] | 189 | be_id_t d_id) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 190 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 191 | struct scsi_qla_host *host; |
Bart Van Assche | aa20e38 | 2019-08-08 20:02:03 -0700 | [diff] [blame] | 192 | uint32_t key; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 193 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 194 | if (vha->d_id.b.area == d_id.area && |
| 195 | vha->d_id.b.domain == d_id.domain && |
| 196 | vha->d_id.b.al_pa == d_id.al_pa) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 197 | return vha; |
| 198 | |
Bart Van Assche | aa20e38 | 2019-08-08 20:02:03 -0700 | [diff] [blame] | 199 | key = be_to_port_id(d_id).b24; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 200 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 201 | host = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 202 | if (!host) |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 203 | ql_dbg(ql_dbg_tgt_mgt + ql_dbg_verbose, vha, 0xf005, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 204 | "Unable to find host %06x\n", key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 205 | |
| 206 | return host; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static inline |
| 210 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, |
| 211 | uint16_t vp_idx) |
| 212 | { |
| 213 | struct qla_hw_data *ha = vha->hw; |
| 214 | |
| 215 | if (vha->vp_idx == vp_idx) |
| 216 | return vha; |
| 217 | |
| 218 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 219 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 220 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 221 | |
| 222 | return NULL; |
| 223 | } |
| 224 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 225 | static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha) |
| 226 | { |
| 227 | unsigned long flags; |
| 228 | |
| 229 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 230 | |
| 231 | vha->hw->tgt.num_pend_cmds++; |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 232 | if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds) |
| 233 | vha->qla_stats.stat_max_pend_cmds = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 234 | vha->hw->tgt.num_pend_cmds; |
| 235 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 236 | } |
| 237 | static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha) |
| 238 | { |
| 239 | unsigned long flags; |
| 240 | |
| 241 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 242 | vha->hw->tgt.num_pend_cmds--; |
| 243 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 244 | } |
| 245 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 246 | |
| 247 | static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 248 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 249 | { |
| 250 | struct qla_tgt_sess_op *u; |
| 251 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 252 | unsigned long flags; |
| 253 | |
| 254 | if (tgt->tgt_stop) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 255 | ql_dbg(ql_dbg_async, vha, 0x502c, |
| 256 | "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped", |
| 257 | vha->vp_idx); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 258 | goto out_term; |
| 259 | } |
| 260 | |
| 261 | u = kzalloc(sizeof(*u), GFP_ATOMIC); |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 262 | if (u == NULL) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 263 | goto out_term; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 264 | |
| 265 | u->vha = vha; |
| 266 | memcpy(&u->atio, atio, sizeof(*atio)); |
| 267 | INIT_LIST_HEAD(&u->cmd_list); |
| 268 | |
| 269 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 270 | list_add_tail(&u->cmd_list, &vha->unknown_atio_list); |
| 271 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 272 | |
| 273 | schedule_delayed_work(&vha->unknown_atio_work, 1); |
| 274 | |
| 275 | out: |
| 276 | return; |
| 277 | |
| 278 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 279 | 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] | 280 | goto out; |
| 281 | } |
| 282 | |
| 283 | static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha, |
| 284 | uint8_t ha_locked) |
| 285 | { |
| 286 | struct qla_tgt_sess_op *u, *t; |
| 287 | scsi_qla_host_t *host; |
| 288 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 289 | unsigned long flags; |
| 290 | uint8_t queued = 0; |
| 291 | |
| 292 | list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) { |
| 293 | if (u->aborted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 294 | ql_dbg(ql_dbg_async, vha, 0x502e, |
| 295 | "Freeing unknown %s %p, because of Abort\n", |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 296 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 297 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 298 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 299 | goto abort; |
| 300 | } |
| 301 | |
| 302 | host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id); |
| 303 | if (host != NULL) { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 304 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x502f, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 305 | "Requeuing unknown ATIO_TYPE7 %p\n", u); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 306 | qlt_24xx_atio_pkt(host, &u->atio, ha_locked); |
| 307 | } else if (tgt->tgt_stop) { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 308 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503a, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 309 | "Freeing unknown %s %p, because tgt is being stopped\n", |
| 310 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 311 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 312 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 313 | } else { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 314 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 315 | "Reschedule u %p, vha %p, host %p\n", u, vha, host); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 316 | if (!queued) { |
| 317 | queued = 1; |
| 318 | schedule_delayed_work(&vha->unknown_atio_work, |
| 319 | 1); |
| 320 | } |
| 321 | continue; |
| 322 | } |
| 323 | |
| 324 | abort: |
| 325 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 326 | list_del(&u->cmd_list); |
| 327 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 328 | kfree(u); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | void qlt_unknown_atio_work_fn(struct work_struct *work) |
| 333 | { |
| 334 | struct scsi_qla_host *vha = container_of(to_delayed_work(work), |
| 335 | struct scsi_qla_host, unknown_atio_work); |
| 336 | |
| 337 | qlt_try_to_dequeue_unknown_atios(vha, 0); |
| 338 | } |
| 339 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 340 | static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 341 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 342 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 343 | ql_dbg(ql_dbg_tgt, vha, 0xe072, |
| 344 | "%s: qla_target(%d): type %x ox_id %04x\n", |
| 345 | __func__, vha->vp_idx, atio->u.raw.entry_type, |
| 346 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 347 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 348 | switch (atio->u.raw.entry_type) { |
| 349 | case ATIO_TYPE7: |
| 350 | { |
| 351 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, |
| 352 | atio->u.isp24.fcp_hdr.d_id); |
| 353 | if (unlikely(NULL == host)) { |
| 354 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, |
| 355 | "qla_target(%d): Received ATIO_TYPE7 " |
| 356 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 357 | atio->u.isp24.fcp_hdr.d_id.domain, |
| 358 | atio->u.isp24.fcp_hdr.d_id.area, |
| 359 | atio->u.isp24.fcp_hdr.d_id.al_pa); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 360 | |
| 361 | |
| 362 | qlt_queue_unknown_atio(vha, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 363 | break; |
| 364 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 365 | if (unlikely(!list_empty(&vha->unknown_atio_list))) |
| 366 | qlt_try_to_dequeue_unknown_atios(vha, ha_locked); |
| 367 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 368 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 369 | break; |
| 370 | } |
| 371 | |
| 372 | case IMMED_NOTIFY_TYPE: |
| 373 | { |
| 374 | struct scsi_qla_host *host = vha; |
| 375 | struct imm_ntfy_from_isp *entry = |
| 376 | (struct imm_ntfy_from_isp *)atio; |
| 377 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 378 | qlt_issue_marker(vha, ha_locked); |
| 379 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 380 | if ((entry->u.isp24.vp_index != 0xFF) && |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 381 | (entry->u.isp24.nport_handle != cpu_to_le16(0xFFFF))) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 382 | host = qlt_find_host_by_vp_idx(vha, |
| 383 | entry->u.isp24.vp_index); |
| 384 | if (unlikely(!host)) { |
| 385 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, |
| 386 | "qla_target(%d): Received " |
| 387 | "ATIO (IMMED_NOTIFY_TYPE) " |
| 388 | "with unknown vp_index %d\n", |
| 389 | vha->vp_idx, entry->u.isp24.vp_index); |
| 390 | break; |
| 391 | } |
| 392 | } |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 393 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 394 | break; |
| 395 | } |
| 396 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 397 | case VP_RPT_ID_IOCB_TYPE: |
| 398 | qla24xx_report_id_acquisition(vha, |
| 399 | (struct vp_rpt_id_entry_24xx *)atio); |
| 400 | break; |
| 401 | |
| 402 | case ABTS_RECV_24XX: |
| 403 | { |
| 404 | struct abts_recv_from_24xx *entry = |
| 405 | (struct abts_recv_from_24xx *)atio; |
| 406 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 407 | entry->vp_index); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 408 | unsigned long flags; |
| 409 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 410 | if (unlikely(!host)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 411 | ql_dbg(ql_dbg_tgt, vha, 0xe00a, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 412 | "qla_target(%d): Response pkt (ABTS_RECV_24XX) " |
| 413 | "received, with unknown vp_index %d\n", |
| 414 | vha->vp_idx, entry->vp_index); |
| 415 | break; |
| 416 | } |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 417 | if (!ha_locked) |
| 418 | spin_lock_irqsave(&host->hw->hardware_lock, flags); |
| 419 | qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio); |
| 420 | if (!ha_locked) |
| 421 | spin_unlock_irqrestore(&host->hw->hardware_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 422 | break; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */ |
| 426 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 427 | default: |
| 428 | ql_dbg(ql_dbg_tgt, vha, 0xe040, |
| 429 | "qla_target(%d): Received unknown ATIO atio " |
| 430 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 431 | break; |
| 432 | } |
| 433 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 434 | return false; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 435 | } |
| 436 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 437 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, |
| 438 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 439 | { |
| 440 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 441 | case CTIO_CRC2: |
| 442 | ql_dbg(ql_dbg_tgt, vha, 0xe073, |
| 443 | "qla_target(%d):%s: CRC2 Response pkt\n", |
| 444 | vha->vp_idx, __func__); |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 445 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 446 | case CTIO_TYPE7: |
| 447 | { |
| 448 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
| 449 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 450 | entry->vp_index); |
| 451 | if (unlikely(!host)) { |
| 452 | ql_dbg(ql_dbg_tgt, vha, 0xe041, |
| 453 | "qla_target(%d): Response pkt (CTIO_TYPE7) " |
| 454 | "received, with unknown vp_index %d\n", |
| 455 | vha->vp_idx, entry->vp_index); |
| 456 | break; |
| 457 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 458 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 459 | break; |
| 460 | } |
| 461 | |
| 462 | case IMMED_NOTIFY_TYPE: |
| 463 | { |
Colin Ian King | da6d296 | 2019-09-05 14:42:29 +0100 | [diff] [blame] | 464 | struct scsi_qla_host *host; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 465 | struct imm_ntfy_from_isp *entry = |
| 466 | (struct imm_ntfy_from_isp *)pkt; |
| 467 | |
| 468 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); |
| 469 | if (unlikely(!host)) { |
| 470 | ql_dbg(ql_dbg_tgt, vha, 0xe042, |
| 471 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " |
| 472 | "received, with unknown vp_index %d\n", |
| 473 | vha->vp_idx, entry->u.isp24.vp_index); |
| 474 | break; |
| 475 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 476 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 477 | break; |
| 478 | } |
| 479 | |
| 480 | case NOTIFY_ACK_TYPE: |
| 481 | { |
| 482 | struct scsi_qla_host *host = vha; |
| 483 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 484 | |
| 485 | if (0xFF != entry->u.isp24.vp_index) { |
| 486 | host = qlt_find_host_by_vp_idx(vha, |
| 487 | entry->u.isp24.vp_index); |
| 488 | if (unlikely(!host)) { |
| 489 | ql_dbg(ql_dbg_tgt, vha, 0xe043, |
| 490 | "qla_target(%d): Response " |
| 491 | "pkt (NOTIFY_ACK_TYPE) " |
| 492 | "received, with unknown " |
| 493 | "vp_index %d\n", vha->vp_idx, |
| 494 | entry->u.isp24.vp_index); |
| 495 | break; |
| 496 | } |
| 497 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 498 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 499 | break; |
| 500 | } |
| 501 | |
| 502 | case ABTS_RECV_24XX: |
| 503 | { |
| 504 | struct abts_recv_from_24xx *entry = |
| 505 | (struct abts_recv_from_24xx *)pkt; |
| 506 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 507 | entry->vp_index); |
| 508 | if (unlikely(!host)) { |
| 509 | ql_dbg(ql_dbg_tgt, vha, 0xe044, |
| 510 | "qla_target(%d): Response pkt " |
| 511 | "(ABTS_RECV_24XX) received, with unknown " |
| 512 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 513 | break; |
| 514 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 515 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 516 | break; |
| 517 | } |
| 518 | |
| 519 | case ABTS_RESP_24XX: |
| 520 | { |
| 521 | struct abts_resp_to_24xx *entry = |
| 522 | (struct abts_resp_to_24xx *)pkt; |
| 523 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 524 | entry->vp_index); |
| 525 | if (unlikely(!host)) { |
| 526 | ql_dbg(ql_dbg_tgt, vha, 0xe045, |
| 527 | "qla_target(%d): Response pkt " |
| 528 | "(ABTS_RECV_24XX) received, with unknown " |
| 529 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 530 | break; |
| 531 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 532 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 533 | break; |
| 534 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 535 | default: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 536 | qlt_response_pkt(vha, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 537 | break; |
| 538 | } |
| 539 | |
| 540 | } |
| 541 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 542 | /* |
| 543 | * All qlt_plogi_ack_t operations are protected by hardware_lock |
| 544 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 545 | static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 546 | struct imm_ntfy_from_isp *ntfy, int type) |
| 547 | { |
| 548 | struct qla_work_evt *e; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 549 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 550 | e = qla2x00_alloc_work(vha, QLA_EVT_NACK); |
| 551 | if (!e) |
| 552 | return QLA_FUNCTION_FAILED; |
| 553 | |
| 554 | e->u.nack.fcport = fcport; |
| 555 | e->u.nack.type = type; |
| 556 | memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp)); |
| 557 | return qla2x00_post_work(vha, e); |
| 558 | } |
| 559 | |
Bart Van Assche | 6c18a43 | 2019-08-08 20:02:04 -0700 | [diff] [blame] | 560 | static void qla2x00_async_nack_sp_done(srb_t *sp, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 561 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 562 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 563 | unsigned long flags; |
| 564 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 565 | ql_dbg(ql_dbg_disc, vha, 0x20f2, |
| 566 | "Async done-%s res %x %8phC type %d\n", |
| 567 | sp->name, res, sp->fcport->port_name, sp->type); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 568 | |
| 569 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 570 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 571 | sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 572 | |
| 573 | switch (sp->type) { |
| 574 | case SRB_NACK_PLOGI: |
| 575 | sp->fcport->login_gen++; |
| 576 | sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP; |
| 577 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 578 | sp->fcport->plogi_nack_done_deadline = jiffies + HZ; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 579 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 580 | break; |
| 581 | |
| 582 | case SRB_NACK_PRLI: |
| 583 | sp->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 584 | sp->fcport->deleted = 0; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 585 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 586 | |
| 587 | if (!sp->fcport->login_succ && |
| 588 | !IS_SW_RESV_ADDR(sp->fcport->d_id)) { |
| 589 | sp->fcport->login_succ = 1; |
| 590 | |
| 591 | vha->fcport_count++; |
Quinn Tran | 0aca778 | 2018-09-04 14:19:16 -0700 | [diff] [blame] | 592 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 593 | qla24xx_sched_upd_fcport(sp->fcport); |
Quinn Tran | 0aca778 | 2018-09-04 14:19:16 -0700 | [diff] [blame] | 594 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | 2952849 | 2018-05-01 09:01:45 -0700 | [diff] [blame] | 595 | } else { |
| 596 | sp->fcport->login_retry = 0; |
Shyam Sundar | 27258a5 | 2019-12-17 14:06:06 -0800 | [diff] [blame] | 597 | qla2x00_set_fcport_disc_state(sp->fcport, |
| 598 | DSC_LOGIN_COMPLETE); |
Quinn Tran | 2952849 | 2018-05-01 09:01:45 -0700 | [diff] [blame] | 599 | sp->fcport->deleted = 0; |
| 600 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 601 | } |
| 602 | break; |
| 603 | |
| 604 | case SRB_NACK_LOGO: |
| 605 | sp->fcport->login_gen++; |
| 606 | sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 607 | qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE); |
| 608 | break; |
| 609 | } |
| 610 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 611 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 612 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport, |
| 616 | struct imm_ntfy_from_isp *ntfy, int type) |
| 617 | { |
| 618 | int rval = QLA_FUNCTION_FAILED; |
| 619 | srb_t *sp; |
| 620 | char *c = NULL; |
| 621 | |
| 622 | fcport->flags |= FCF_ASYNC_SENT; |
| 623 | switch (type) { |
| 624 | case SRB_NACK_PLOGI: |
| 625 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; |
| 626 | c = "PLOGI"; |
| 627 | break; |
| 628 | case SRB_NACK_PRLI: |
| 629 | fcport->fw_login_state = DSC_LS_PRLI_PEND; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 630 | fcport->deleted = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 631 | c = "PRLI"; |
| 632 | break; |
| 633 | case SRB_NACK_LOGO: |
| 634 | fcport->fw_login_state = DSC_LS_LOGO_PEND; |
| 635 | c = "LOGO"; |
| 636 | break; |
| 637 | } |
| 638 | |
| 639 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
| 640 | if (!sp) |
| 641 | goto done; |
| 642 | |
| 643 | sp->type = type; |
| 644 | sp->name = "nack"; |
| 645 | |
Ben Hutchings | e74e7d9 | 2018-03-20 21:36:14 +0000 | [diff] [blame] | 646 | sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 647 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 648 | |
| 649 | sp->u.iocb_cmd.u.nack.ntfy = ntfy; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 650 | sp->done = qla2x00_async_nack_sp_done; |
| 651 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 652 | ql_dbg(ql_dbg_disc, vha, 0x20f4, |
| 653 | "Async-%s %8phC hndl %x %s\n", |
| 654 | sp->name, fcport->port_name, sp->handle, c); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 655 | |
Bill Kuzeja | f233e8c | 2019-02-14 10:52:29 -0500 | [diff] [blame] | 656 | rval = qla2x00_start_sp(sp); |
| 657 | if (rval != QLA_SUCCESS) |
| 658 | goto done_free_sp; |
| 659 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 660 | return rval; |
| 661 | |
| 662 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 663 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 664 | done: |
| 665 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 666 | return rval; |
| 667 | } |
| 668 | |
| 669 | void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
| 670 | { |
| 671 | fc_port_t *t; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 672 | |
| 673 | switch (e->u.nack.type) { |
| 674 | case SRB_NACK_PRLI: |
Quinn Tran | 1021f0b | 2019-01-24 23:23:45 -0800 | [diff] [blame] | 675 | t = e->u.nack.fcport; |
| 676 | flush_work(&t->del_work); |
| 677 | flush_work(&t->free_work); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 678 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 679 | t = qlt_create_sess(vha, e->u.nack.fcport, 0); |
| 680 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 681 | if (t) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 682 | ql_log(ql_log_info, vha, 0xd034, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 683 | "%s create sess success %p", __func__, t); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 684 | /* create sess has an extra kref */ |
| 685 | vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 686 | } |
| 687 | break; |
| 688 | } |
| 689 | qla24xx_async_notify_ack(vha, e->u.nack.fcport, |
Bart Van Assche | 845bbb0 | 2019-04-11 14:53:18 -0700 | [diff] [blame] | 690 | (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] | 691 | } |
| 692 | |
| 693 | void qla24xx_delete_sess_fn(struct work_struct *work) |
| 694 | { |
| 695 | fc_port_t *fcport = container_of(work, struct fc_port, del_work); |
| 696 | struct qla_hw_data *ha = fcport->vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 697 | |
| 698 | if (fcport->se_sess) { |
| 699 | ha->tgt.tgt_ops->shutdown_sess(fcport); |
| 700 | ha->tgt.tgt_ops->put_sess(fcport); |
| 701 | } else { |
| 702 | qlt_unreg_sess(fcport); |
| 703 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | /* |
| 707 | * Called from qla2x00_reg_remote_port() |
| 708 | */ |
| 709 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 710 | { |
| 711 | struct qla_hw_data *ha = vha->hw; |
| 712 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 713 | struct fc_port *sess = fcport; |
| 714 | unsigned long flags; |
| 715 | |
| 716 | if (!vha->hw->tgt.tgt_ops) |
| 717 | return; |
| 718 | |
| 719 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 720 | if (tgt->tgt_stop) { |
| 721 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 722 | return; |
| 723 | } |
| 724 | |
| 725 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 726 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 727 | return; |
| 728 | } |
| 729 | |
| 730 | if (!sess->se_sess) { |
| 731 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 732 | |
| 733 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 734 | sess = qlt_create_sess(vha, fcport, false); |
| 735 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 736 | |
| 737 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 738 | } else { |
| 739 | if (fcport->fw_login_state == DSC_LS_PRLI_COMP) { |
| 740 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 741 | return; |
| 742 | } |
| 743 | |
| 744 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 745 | ql_dbg(ql_dbg_disc, vha, 0x2107, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 746 | "%s: kref_get fail sess %8phC \n", |
| 747 | __func__, sess->port_name); |
| 748 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 749 | return; |
| 750 | } |
| 751 | |
| 752 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, |
| 753 | "qla_target(%u): %ssession for port %8phC " |
| 754 | "(loop ID %d) reappeared\n", vha->vp_idx, |
| 755 | sess->local ? "local " : "", sess->port_name, sess->loop_id); |
| 756 | |
| 757 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, |
| 758 | "Reappeared sess %p\n", sess); |
| 759 | |
| 760 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, |
| 761 | fcport->loop_id, |
| 762 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
| 763 | } |
| 764 | |
| 765 | if (sess && sess->local) { |
| 766 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, |
| 767 | "qla_target(%u): local session for " |
| 768 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
| 769 | fcport->port_name, sess->loop_id); |
| 770 | sess->local = 0; |
| 771 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 772 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 773 | |
| 774 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 775 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 776 | |
| 777 | /* |
| 778 | * This is a zero-base ref-counting solution, since hardware_lock |
| 779 | * guarantees that ref_count is not modified concurrently. |
| 780 | * Upon successful return content of iocb is undefined |
| 781 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 782 | static struct qlt_plogi_ack_t * |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 783 | qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id, |
| 784 | struct imm_ntfy_from_isp *iocb) |
| 785 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 786 | struct qlt_plogi_ack_t *pla; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 787 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 788 | lockdep_assert_held(&vha->hw->hardware_lock); |
| 789 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 790 | list_for_each_entry(pla, &vha->plogi_ack_list, list) { |
| 791 | if (pla->id.b24 == id->b24) { |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 792 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x210d, |
| 793 | "%s %d %8phC Term INOT due to new INOT", |
| 794 | __func__, __LINE__, |
| 795 | pla->iocb.u.isp24.port_name); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 796 | qlt_send_term_imm_notif(vha, &pla->iocb, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 797 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 798 | return pla; |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC); |
| 803 | if (!pla) { |
| 804 | ql_dbg(ql_dbg_async, vha, 0x5088, |
| 805 | "qla_target(%d): Allocation of plogi_ack failed\n", |
| 806 | vha->vp_idx); |
| 807 | return NULL; |
| 808 | } |
| 809 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 810 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 811 | pla->id = *id; |
| 812 | list_add_tail(&pla->list, &vha->plogi_ack_list); |
| 813 | |
| 814 | return pla; |
| 815 | } |
| 816 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 817 | void qlt_plogi_ack_unref(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 818 | struct qlt_plogi_ack_t *pla) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 819 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 820 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 821 | port_id_t port_id; |
| 822 | uint16_t loop_id; |
| 823 | fc_port_t *fcport = pla->fcport; |
| 824 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 825 | BUG_ON(!pla->ref_count); |
| 826 | pla->ref_count--; |
| 827 | |
| 828 | if (pla->ref_count) |
| 829 | return; |
| 830 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 831 | ql_dbg(ql_dbg_disc, vha, 0x5089, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 832 | "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] | 833 | " exch %#x ox_id %#x\n", iocb->u.isp24.port_name, |
| 834 | iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1], |
| 835 | iocb->u.isp24.port_id[0], |
| 836 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 837 | iocb->u.isp24.exchange_address, iocb->ox_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 838 | |
| 839 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 840 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 841 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 842 | port_id.b.rsvd_1 = 0; |
| 843 | |
| 844 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 845 | |
| 846 | fcport->loop_id = loop_id; |
| 847 | fcport->d_id = port_id; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 848 | if (iocb->u.isp24.status_subcode == ELS_PLOGI) |
| 849 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI); |
| 850 | else |
| 851 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PRLI); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 852 | |
| 853 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 854 | if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla) |
| 855 | fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 856 | if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla) |
| 857 | fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
| 858 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 859 | |
| 860 | list_del(&pla->list); |
| 861 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 862 | } |
| 863 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 864 | void |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 865 | qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla, |
| 866 | struct fc_port *sess, enum qlt_plogi_link_t link) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 867 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 868 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 869 | /* Inc ref_count first because link might already be pointing at pla */ |
| 870 | pla->ref_count++; |
| 871 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 872 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097, |
| 873 | "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC" |
| 874 | " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n", |
| 875 | sess, link, sess->port_name, |
| 876 | iocb->u.isp24.port_name, iocb->u.isp24.port_id[2], |
| 877 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 878 | pla->ref_count, pla, link); |
| 879 | |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 880 | if (link == QLT_PLOGI_LINK_CONFLICT) { |
| 881 | switch (sess->disc_state) { |
| 882 | case DSC_DELETED: |
| 883 | case DSC_DELETE_PEND: |
| 884 | pla->ref_count--; |
| 885 | return; |
| 886 | default: |
| 887 | break; |
| 888 | } |
| 889 | } |
| 890 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 891 | if (sess->plogi_link[link]) |
| 892 | qlt_plogi_ack_unref(vha, sess->plogi_link[link]); |
| 893 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 894 | if (link == QLT_PLOGI_LINK_SAME_WWN) |
| 895 | pla->fcport = sess; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 896 | |
| 897 | sess->plogi_link[link] = pla; |
| 898 | } |
| 899 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 900 | typedef struct { |
| 901 | /* These fields must be initialized by the caller */ |
| 902 | port_id_t id; |
| 903 | /* |
| 904 | * number of cmds dropped while we were waiting for |
| 905 | * initiator to ack LOGO initialize to 1 if LOGO is |
| 906 | * triggered by a command, otherwise, to 0 |
| 907 | */ |
| 908 | int cmd_count; |
| 909 | |
| 910 | /* These fields are used by callee */ |
| 911 | struct list_head list; |
| 912 | } qlt_port_logo_t; |
| 913 | |
| 914 | static void |
| 915 | qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo) |
| 916 | { |
| 917 | qlt_port_logo_t *tmp; |
| 918 | int res; |
| 919 | |
| 920 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 921 | |
| 922 | list_for_each_entry(tmp, &vha->logo_list, list) { |
| 923 | if (tmp->id.b24 == logo->id.b24) { |
| 924 | tmp->cmd_count += logo->cmd_count; |
| 925 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 926 | return; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | list_add_tail(&logo->list, &vha->logo_list); |
| 931 | |
| 932 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 933 | |
| 934 | res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id); |
| 935 | |
| 936 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 937 | list_del(&logo->list); |
| 938 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 939 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 940 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098, |
| 941 | "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n", |
| 942 | logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa, |
| 943 | logo->cmd_count, res); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 944 | } |
| 945 | |
Darren Trapp | 9dd9686 | 2018-03-20 23:09:32 -0700 | [diff] [blame] | 946 | void qlt_free_session_done(struct work_struct *work) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 947 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 948 | struct fc_port *sess = container_of(work, struct fc_port, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 949 | free_work); |
| 950 | struct qla_tgt *tgt = sess->tgt; |
| 951 | struct scsi_qla_host *vha = sess->vha; |
| 952 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 953 | unsigned long flags; |
| 954 | bool logout_started = false; |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 955 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 956 | struct qlt_plogi_ack_t *own = |
| 957 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 958 | |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame] | 959 | ql_dbg(ql_dbg_disc, vha, 0xf084, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 960 | "%s: se_sess %p / sess %p from port %8phC loop_id %#04x" |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 961 | " 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] | 962 | __func__, sess->se_sess, sess, sess->port_name, sess->loop_id, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 963 | 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] | 964 | sess->logout_on_delete, sess->keep_nport_handle, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 965 | sess->send_els_logo); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 966 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 967 | if (!IS_SW_RESV_ADDR(sess->d_id)) { |
Himanshu Madhani | 3c75ad1 | 2019-12-17 14:06:04 -0800 | [diff] [blame] | 968 | qla2x00_mark_device_lost(vha, sess, 0); |
Quinn Tran | 2137490 | 2019-04-23 14:52:35 -0700 | [diff] [blame] | 969 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 970 | if (sess->send_els_logo) { |
| 971 | qlt_port_logo_t logo; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 972 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 973 | logo.id = sess->d_id; |
| 974 | logo.cmd_count = 0; |
Quinn Tran | cb97f2c | 2018-08-02 13:16:51 -0700 | [diff] [blame] | 975 | if (!own) |
| 976 | qlt_send_first_logo(vha, &logo); |
Himanshu Madhani | a239034 | 2018-01-22 12:04:20 -0800 | [diff] [blame] | 977 | sess->send_els_logo = 0; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 978 | } |
| 979 | |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 980 | if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 981 | int rc; |
| 982 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 983 | if (!own || |
| 984 | (own && |
| 985 | (own->iocb.u.isp24.status_subcode == ELS_PLOGI))) { |
| 986 | rc = qla2x00_post_async_logout_work(vha, sess, |
| 987 | NULL); |
| 988 | if (rc != QLA_SUCCESS) |
| 989 | ql_log(ql_log_warn, vha, 0xf085, |
| 990 | "Schedule logo failed sess %p rc %d\n", |
| 991 | sess, rc); |
| 992 | else |
| 993 | logout_started = true; |
| 994 | } else if (own && (own->iocb.u.isp24.status_subcode == |
| 995 | ELS_PRLI) && ha->flags.rida_fmt2) { |
| 996 | rc = qla2x00_post_async_prlo_work(vha, sess, |
| 997 | NULL); |
| 998 | if (rc != QLA_SUCCESS) |
| 999 | ql_log(ql_log_warn, vha, 0xf085, |
| 1000 | "Schedule PRLO failed sess %p rc %d\n", |
| 1001 | sess, rc); |
| 1002 | else |
| 1003 | logout_started = true; |
| 1004 | } |
Quinn Tran | baf23ed | 2019-06-16 08:05:53 -0700 | [diff] [blame] | 1005 | } /* if sess->logout_on_delete */ |
| 1006 | |
| 1007 | if (sess->nvme_flag & NVME_FLAG_REGISTERED && |
| 1008 | !(sess->nvme_flag & NVME_FLAG_DELETING)) { |
| 1009 | sess->nvme_flag |= NVME_FLAG_DELETING; |
| 1010 | qla_nvme_unregister_remote_port(sess); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1011 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1012 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1013 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1014 | /* |
| 1015 | * Release the target session for FC Nexus from fabric module code. |
| 1016 | */ |
| 1017 | if (sess->se_sess != NULL) |
| 1018 | ha->tgt.tgt_ops->free_session(sess); |
| 1019 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1020 | if (logout_started) { |
| 1021 | bool traced = false; |
Quinn Tran | c3b6a1d | 2019-09-12 11:09:06 -0700 | [diff] [blame] | 1022 | u16 cnt = 0; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1023 | |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 1024 | while (!READ_ONCE(sess->logout_completed)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1025 | if (!traced) { |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame] | 1026 | ql_dbg(ql_dbg_disc, vha, 0xf086, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1027 | "%s: waiting for sess %p logout\n", |
| 1028 | __func__, sess); |
| 1029 | traced = true; |
| 1030 | } |
| 1031 | msleep(100); |
Quinn Tran | c3b6a1d | 2019-09-12 11:09:06 -0700 | [diff] [blame] | 1032 | cnt++; |
| 1033 | if (cnt > 200) |
| 1034 | break; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1035 | } |
| 1036 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1037 | ql_dbg(ql_dbg_disc, vha, 0xf087, |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1038 | "%s: sess %p logout completed\n", __func__, sess); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | if (sess->logo_ack_needed) { |
| 1042 | sess->logo_ack_needed = 0; |
| 1043 | qla24xx_async_notify_ack(vha, sess, |
| 1044 | (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame] | 1047 | spin_lock_irqsave(&vha->work_lock, flags); |
| 1048 | sess->flags &= ~FCF_ASYNC_SENT; |
| 1049 | spin_unlock_irqrestore(&vha->work_lock, flags); |
| 1050 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1051 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1052 | if (sess->se_sess) { |
| 1053 | sess->se_sess = NULL; |
| 1054 | if (tgt && !IS_SW_RESV_ADDR(sess->d_id)) |
| 1055 | tgt->sess_count--; |
| 1056 | } |
| 1057 | |
Shyam Sundar | 27258a5 | 2019-12-17 14:06:06 -0800 | [diff] [blame] | 1058 | qla2x00_set_fcport_disc_state(sess, DSC_DELETED); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1059 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1060 | sess->deleted = QLA_SESS_DELETED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1061 | |
| 1062 | if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) { |
| 1063 | vha->fcport_count--; |
| 1064 | sess->login_succ = 0; |
| 1065 | } |
| 1066 | |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 1067 | qla2x00_clear_loop_id(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1068 | |
| 1069 | if (sess->conflict) { |
| 1070 | sess->conflict->login_pause = 0; |
| 1071 | sess->conflict = NULL; |
| 1072 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 1073 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1074 | } |
| 1075 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1076 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1077 | struct qlt_plogi_ack_t *con = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1078 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1079 | struct imm_ntfy_from_isp *iocb; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 1080 | |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 1081 | own = sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1082 | |
| 1083 | if (con) { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1084 | iocb = &con->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1085 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1086 | "se_sess %p / sess %p port %8phC is gone," |
| 1087 | " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n", |
| 1088 | sess->se_sess, sess, sess->port_name, |
| 1089 | own ? "releasing own PLOGI" : "no own PLOGI pending", |
| 1090 | own ? own->ref_count : -1, |
| 1091 | iocb->u.isp24.port_name, con->ref_count); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1092 | qlt_plogi_ack_unref(vha, con); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1093 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1094 | } else { |
| 1095 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a, |
| 1096 | "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n", |
| 1097 | sess->se_sess, sess, sess->port_name, |
| 1098 | own ? "releasing own PLOGI" : |
| 1099 | "no own PLOGI pending", |
| 1100 | own ? own->ref_count : -1); |
| 1101 | } |
| 1102 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1103 | if (own) { |
| 1104 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1105 | qlt_plogi_ack_unref(vha, own); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1106 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 1107 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1108 | } |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1109 | |
Quinn Tran | 86196a8 | 2019-11-25 19:56:51 +0300 | [diff] [blame] | 1110 | sess->explicit_logout = 0; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1111 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 1112 | sess->free_pending = 0; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1113 | |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame] | 1114 | ql_dbg(ql_dbg_disc, vha, 0xf001, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1115 | "Unregistration of sess %p %8phC finished fcp_cnt %d\n", |
| 1116 | sess, sess->port_name, vha->fcport_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1117 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1118 | if (tgt && (tgt->sess_count == 0)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1119 | wake_up_all(&tgt->waitQ); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1120 | |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 1121 | if (!test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags) && |
Quinn Tran | f5187b7 | 2019-09-12 11:09:08 -0700 | [diff] [blame] | 1122 | !(vha->vp_idx && test_bit(VPORT_DELETE, &vha->dpc_flags)) && |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 1123 | (!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1124 | switch (vha->host->active_mode) { |
| 1125 | case MODE_INITIATOR: |
| 1126 | case MODE_DUAL: |
| 1127 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1128 | qla2xxx_wake_dpc(vha); |
| 1129 | break; |
| 1130 | case MODE_TARGET: |
| 1131 | default: |
| 1132 | /* no-op */ |
| 1133 | break; |
| 1134 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1135 | } |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 1136 | |
| 1137 | if (vha->fcport_count == 0) |
| 1138 | wake_up_all(&vha->fcport_waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1139 | } |
| 1140 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1141 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1142 | void qlt_unreg_sess(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1143 | { |
| 1144 | struct scsi_qla_host *vha = sess->vha; |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1145 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1146 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1147 | ql_dbg(ql_dbg_disc, sess->vha, 0x210a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1148 | "%s sess %p for deletion %8phC\n", |
| 1149 | __func__, sess, sess->port_name); |
| 1150 | |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1151 | spin_lock_irqsave(&sess->vha->work_lock, flags); |
| 1152 | if (sess->free_pending) { |
| 1153 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
| 1154 | return; |
| 1155 | } |
| 1156 | sess->free_pending = 1; |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame] | 1157 | /* |
| 1158 | * Use FCF_ASYNC_SENT flag to block other cmds used in sess |
| 1159 | * management from being sent. |
| 1160 | */ |
| 1161 | sess->flags |= FCF_ASYNC_SENT; |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1162 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
| 1163 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 1164 | if (sess->se_sess) |
| 1165 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1166 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1167 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Shyam Sundar | 27258a5 | 2019-12-17 14:06:06 -0800 | [diff] [blame] | 1168 | qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1169 | sess->last_rscn_gen = sess->rscn_gen; |
| 1170 | sess->last_login_gen = sess->login_gen; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1171 | |
Quinn Tran | fd5564b | 2019-09-12 11:09:07 -0700 | [diff] [blame] | 1172 | queue_work(sess->vha->hw->wq, &sess->free_work); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1173 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1174 | EXPORT_SYMBOL(qlt_unreg_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1175 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1176 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) |
| 1177 | { |
| 1178 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1179 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1180 | uint16_t loop_id; |
| 1181 | int res = 0; |
| 1182 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1183 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1184 | |
| 1185 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); |
| 1186 | if (loop_id == 0xFFFF) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1187 | /* Global event */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1188 | atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1189 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1190 | qlt_clear_tgt_db(vha->vha_tgt.qla_tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1191 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1192 | } else { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1193 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1194 | 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] | 1195 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | ql_dbg(ql_dbg_tgt, vha, 0xe000, |
| 1199 | "Using sess for qla_tgt_reset: %p\n", sess); |
| 1200 | if (!sess) { |
| 1201 | res = -ESRCH; |
| 1202 | return res; |
| 1203 | } |
| 1204 | |
| 1205 | ql_dbg(ql_dbg_tgt, vha, 0xe047, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1206 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
| 1207 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1208 | mcmd, loop_id); |
| 1209 | |
Quinn Tran | bb1181c | 2016-12-23 18:06:05 -0800 | [diff] [blame] | 1210 | 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] | 1211 | } |
| 1212 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1213 | static void qla24xx_chk_fcp_state(struct fc_port *sess) |
| 1214 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 1215 | if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1216 | sess->logout_on_delete = 0; |
| 1217 | sess->logo_ack_needed = 0; |
| 1218 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1222 | void qlt_schedule_sess_for_deletion(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1223 | { |
| 1224 | struct qla_tgt *tgt = sess->tgt; |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1225 | unsigned long flags; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1226 | u16 sec; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1227 | |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1228 | switch (sess->disc_state) { |
| 1229 | case DSC_DELETE_PEND: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1230 | return; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1231 | case DSC_DELETED: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1232 | if (tgt && tgt->tgt_stop && (tgt->sess_count == 0)) |
| 1233 | wake_up_all(&tgt->waitQ); |
| 1234 | if (sess->vha->fcport_count == 0) |
| 1235 | wake_up_all(&sess->vha->fcport_waitQ); |
| 1236 | |
| 1237 | if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] && |
| 1238 | !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1239 | return; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1240 | break; |
| 1241 | case DSC_UPD_FCPORT: |
| 1242 | /* |
| 1243 | * This port is not done reporting to upper layer. |
| 1244 | * let it finish |
| 1245 | */ |
| 1246 | sess->next_disc_state = DSC_DELETE_PEND; |
| 1247 | sec = jiffies_to_msecs(jiffies - |
| 1248 | sess->jiffies_at_registration)/1000; |
| 1249 | if (sess->sec_since_registration < sec && sec && !(sec % 5)) { |
| 1250 | sess->sec_since_registration = sec; |
| 1251 | ql_dbg(ql_dbg_disc, sess->vha, 0xffff, |
| 1252 | "%s %8phC : Slow Rport registration(%d Sec)\n", |
| 1253 | __func__, sess->port_name, sec); |
| 1254 | } |
| 1255 | return; |
| 1256 | default: |
| 1257 | break; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1258 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1259 | |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1260 | spin_lock_irqsave(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1261 | if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1262 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1263 | return; |
| 1264 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1265 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1266 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1267 | |
Quinn Tran | 8aaac2d | 2019-12-17 14:06:11 -0800 | [diff] [blame] | 1268 | sess->prli_pend_timer = 0; |
Shyam Sundar | 27258a5 | 2019-12-17 14:06:06 -0800 | [diff] [blame] | 1269 | qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1270 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1271 | qla24xx_chk_fcp_state(sess); |
| 1272 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1273 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, |
Quinn Tran | 5c64005 | 2018-09-26 22:05:14 -0700 | [diff] [blame] | 1274 | "Scheduling sess %p for deletion %8phC\n", |
| 1275 | sess, sess->port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1276 | |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1277 | WARN_ON(!queue_work(sess->vha->hw->wq, &sess->del_work)); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1278 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1279 | |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1280 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1281 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1282 | struct fc_port *sess; |
| 1283 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1284 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1285 | list_for_each_entry(sess, &vha->vp_fcports, list) { |
| 1286 | if (sess->se_sess) |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1287 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1288 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1289 | |
| 1290 | /* At this point tgt could be already dead */ |
| 1291 | } |
| 1292 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1293 | 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] | 1294 | uint16_t *loop_id) |
| 1295 | { |
| 1296 | struct qla_hw_data *ha = vha->hw; |
| 1297 | dma_addr_t gid_list_dma; |
Bart Van Assche | 9c17c3b | 2019-08-08 20:01:35 -0700 | [diff] [blame] | 1298 | struct gid_list_info *gid_list, *gid; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1299 | int res, rc, i; |
| 1300 | uint16_t entries; |
| 1301 | |
| 1302 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1303 | &gid_list_dma, GFP_KERNEL); |
| 1304 | if (!gid_list) { |
| 1305 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, |
| 1306 | "qla_target(%d): DMA Alloc failed of %u\n", |
| 1307 | vha->vp_idx, qla2x00_gid_list_size(ha)); |
| 1308 | return -ENOMEM; |
| 1309 | } |
| 1310 | |
| 1311 | /* Get list of logged in devices */ |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1312 | rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1313 | if (rc != QLA_SUCCESS) { |
| 1314 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, |
| 1315 | "qla_target(%d): get_id_list() failed: %x\n", |
| 1316 | vha->vp_idx, rc); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1317 | res = -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1318 | goto out_free_id_list; |
| 1319 | } |
| 1320 | |
Bart Van Assche | 9c17c3b | 2019-08-08 20:01:35 -0700 | [diff] [blame] | 1321 | gid = gid_list; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1322 | res = -ENOENT; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1323 | for (i = 0; i < entries; i++) { |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1324 | if (gid->al_pa == s_id.al_pa && |
| 1325 | gid->area == s_id.area && |
| 1326 | gid->domain == s_id.domain) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1327 | *loop_id = le16_to_cpu(gid->loop_id); |
| 1328 | res = 0; |
| 1329 | break; |
| 1330 | } |
Bart Van Assche | 9c17c3b | 2019-08-08 20:01:35 -0700 | [diff] [blame] | 1331 | gid = (void *)gid + ha->gid_list_info_size; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | out_free_id_list: |
| 1335 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1336 | gid_list, gid_list_dma); |
| 1337 | return res; |
| 1338 | } |
| 1339 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1340 | /* |
| 1341 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. |
| 1342 | * Caller must put it. |
| 1343 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1344 | static struct fc_port *qlt_create_sess( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1345 | struct scsi_qla_host *vha, |
| 1346 | fc_port_t *fcport, |
| 1347 | bool local) |
| 1348 | { |
| 1349 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1350 | struct fc_port *sess = fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1351 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1352 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1353 | if (vha->vha_tgt.qla_tgt->tgt_stop) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1354 | return NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1355 | |
| 1356 | if (fcport->se_sess) { |
| 1357 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1358 | ql_dbg(ql_dbg_disc, vha, 0x20f6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1359 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1360 | __func__, sess->port_name); |
| 1361 | return NULL; |
| 1362 | } |
| 1363 | return fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1364 | } |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1365 | sess->tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1366 | sess->local = local; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1367 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1368 | /* |
| 1369 | * Under normal circumstances we want to logout from firmware when |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1370 | * session eventually ends and release corresponding nport handle. |
| 1371 | * In the exception cases (e.g. when new PLOGI is waiting) corresponding |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1372 | * code will adjust these flags as necessary. |
| 1373 | */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1374 | sess->logout_on_delete = 1; |
| 1375 | sess->keep_nport_handle = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1376 | sess->logout_completed = 0; |
| 1377 | |
| 1378 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 1379 | &fcport->port_name[0], sess) < 0) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1380 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1381 | "(%d) %8phC check_initiator_node_acl failed\n", |
| 1382 | vha->vp_idx, fcport->port_name); |
| 1383 | return NULL; |
| 1384 | } else { |
| 1385 | kref_init(&fcport->sess_kref); |
| 1386 | /* |
| 1387 | * Take an extra reference to ->sess_kref here to handle |
| 1388 | * fc_port access across ->tgt.sess_lock reaquire. |
| 1389 | */ |
| 1390 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1391 | ql_dbg(ql_dbg_disc, vha, 0x20f7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1392 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1393 | __func__, sess->port_name); |
| 1394 | return NULL; |
| 1395 | } |
| 1396 | |
| 1397 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1398 | if (!IS_SW_RESV_ADDR(sess->d_id)) |
| 1399 | vha->vha_tgt.qla_tgt->sess_count++; |
| 1400 | |
| 1401 | qlt_do_generation_tick(vha, &sess->generation); |
| 1402 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1403 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1404 | |
| 1405 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1406 | "Adding sess %p se_sess %p to tgt %p sess_count %d\n", |
| 1407 | sess, sess->se_sess, vha->vha_tgt.qla_tgt, |
| 1408 | vha->vha_tgt.qla_tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1409 | |
| 1410 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1411 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
| 1412 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", |
| 1413 | vha->vp_idx, local ? "local " : "", fcport->port_name, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 1414 | fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area, |
| 1415 | sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1416 | |
| 1417 | return sess; |
| 1418 | } |
| 1419 | |
| 1420 | /* |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1421 | * max_gen - specifies maximum session generation |
| 1422 | * at which this deletion requestion is still valid |
| 1423 | */ |
| 1424 | void |
| 1425 | 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] | 1426 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1427 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1428 | struct fc_port *sess = fcport; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1429 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1430 | |
| 1431 | if (!vha->hw->tgt.tgt_ops) |
| 1432 | return; |
| 1433 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1434 | if (!tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1435 | return; |
| 1436 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1437 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1438 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1439 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1440 | return; |
| 1441 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1442 | if (!sess->se_sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1443 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1444 | return; |
| 1445 | } |
| 1446 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1447 | if (max_gen - sess->generation < 0) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1448 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1449 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092, |
| 1450 | "Ignoring stale deletion request for se_sess %p / sess %p" |
| 1451 | " for port %8phC, req_gen %d, sess_gen %d\n", |
| 1452 | sess->se_sess, sess, sess->port_name, max_gen, |
| 1453 | sess->generation); |
| 1454 | return; |
| 1455 | } |
| 1456 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1457 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); |
| 1458 | |
| 1459 | sess->local = 1; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1460 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1461 | qlt_schedule_sess_for_deletion(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) |
| 1465 | { |
| 1466 | struct qla_hw_data *ha = tgt->ha; |
| 1467 | unsigned long flags; |
| 1468 | int res; |
| 1469 | /* |
| 1470 | * We need to protect against race, when tgt is freed before or |
| 1471 | * inside wake_up() |
| 1472 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1473 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1474 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1475 | "tgt %p, sess_count=%d\n", |
| 1476 | tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1477 | res = (tgt->sess_count == 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1478 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1479 | |
| 1480 | return res; |
| 1481 | } |
| 1482 | |
| 1483 | /* Called by tcm_qla2xxx configfs code */ |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1484 | int qlt_stop_phase1(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1485 | { |
| 1486 | struct scsi_qla_host *vha = tgt->vha; |
| 1487 | struct qla_hw_data *ha = tgt->ha; |
| 1488 | unsigned long flags; |
| 1489 | |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1490 | mutex_lock(&ha->optrom_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1491 | mutex_lock(&qla_tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1492 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1493 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
| 1494 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, |
| 1495 | "Already in tgt->tgt_stop or tgt_stopped state\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1496 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1497 | mutex_unlock(&ha->optrom_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1498 | return -EPERM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1499 | } |
| 1500 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1501 | 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] | 1502 | vha->host_no, vha); |
| 1503 | /* |
| 1504 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. |
| 1505 | * Lock is needed, because we still can get an incoming packet. |
| 1506 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1507 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1508 | tgt->tgt_stop = 1; |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1509 | qlt_clear_tgt_db(tgt); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1510 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1511 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1512 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1513 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, |
| 1514 | "Waiting for sess works (tgt %p)", tgt); |
| 1515 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1516 | while (!list_empty(&tgt->sess_works_list)) { |
| 1517 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1518 | flush_scheduled_work(); |
| 1519 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1520 | } |
| 1521 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1522 | |
| 1523 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1524 | "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1525 | |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1526 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1527 | |
| 1528 | /* Big hammer */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1529 | if (!ha->flags.host_shutting_down && |
| 1530 | (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1531 | qlt_disable_vha(vha); |
| 1532 | |
| 1533 | /* Wait for sessions to clear out (just in case) */ |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1534 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1535 | mutex_unlock(&ha->optrom_mutex); |
| 1536 | |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1537 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1538 | } |
| 1539 | EXPORT_SYMBOL(qlt_stop_phase1); |
| 1540 | |
| 1541 | /* Called by tcm_qla2xxx configfs code */ |
| 1542 | void qlt_stop_phase2(struct qla_tgt *tgt) |
| 1543 | { |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1544 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1545 | |
| 1546 | if (tgt->tgt_stopped) { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1547 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1548 | "Already in tgt->tgt_stopped state\n"); |
| 1549 | dump_stack(); |
| 1550 | return; |
| 1551 | } |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1552 | if (!tgt->tgt_stop) { |
| 1553 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
| 1554 | "%s: phase1 stop is not completed\n", __func__); |
| 1555 | dump_stack(); |
| 1556 | return; |
| 1557 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1558 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1559 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1560 | tgt->tgt_stop = 0; |
| 1561 | tgt->tgt_stopped = 1; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1562 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1563 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1564 | 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] | 1565 | tgt); |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 1566 | |
| 1567 | switch (vha->qlini_mode) { |
| 1568 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 1569 | vha->flags.online = 1; |
| 1570 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 1571 | break; |
| 1572 | default: |
| 1573 | break; |
| 1574 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1575 | } |
| 1576 | EXPORT_SYMBOL(qlt_stop_phase2); |
| 1577 | |
| 1578 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1579 | static void qlt_release(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1580 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1581 | scsi_qla_host_t *vha = tgt->vha; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1582 | void *node; |
| 1583 | u64 key = 0; |
| 1584 | u16 i; |
| 1585 | struct qla_qpair_hint *h; |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1586 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1587 | |
Bart Van Assche | 8b21900 | 2019-08-08 20:01:38 -0700 | [diff] [blame] | 1588 | if (!tgt->tgt_stop && !tgt->tgt_stopped) |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1589 | qlt_stop_phase1(tgt); |
| 1590 | |
Bart Van Assche | 8b21900 | 2019-08-08 20:01:38 -0700 | [diff] [blame] | 1591 | if (!tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1592 | qlt_stop_phase2(tgt); |
| 1593 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1594 | for (i = 0; i < vha->hw->max_qpairs + 1; i++) { |
| 1595 | unsigned long flags; |
| 1596 | |
| 1597 | h = &tgt->qphints[i]; |
| 1598 | if (h->qpair) { |
| 1599 | spin_lock_irqsave(h->qpair->qp_lock_ptr, flags); |
| 1600 | list_del(&h->hint_elem); |
| 1601 | spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags); |
| 1602 | h->qpair = NULL; |
| 1603 | } |
| 1604 | } |
| 1605 | kfree(tgt->qphints); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1606 | mutex_lock(&qla_tgt_mutex); |
| 1607 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
| 1608 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1609 | |
| 1610 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 1611 | btree_remove64(&tgt->lun_qpair_map, key); |
| 1612 | |
| 1613 | btree_destroy64(&tgt->lun_qpair_map); |
| 1614 | |
Sawan Chandak | 3be63b1e | 2017-12-04 14:45:04 -0800 | [diff] [blame] | 1615 | if (vha->vp_idx) |
| 1616 | if (ha->tgt.tgt_ops && |
| 1617 | ha->tgt.tgt_ops->remove_target && |
| 1618 | vha->vha_tgt.target_lport_ptr) |
| 1619 | ha->tgt.tgt_ops->remove_target(vha); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1620 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1621 | vha->vha_tgt.qla_tgt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1622 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1623 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1624 | "Release of tgt %p finished\n", tgt); |
| 1625 | |
| 1626 | kfree(tgt); |
| 1627 | } |
| 1628 | |
| 1629 | /* ha->hardware_lock supposed to be held on entry */ |
| 1630 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, |
| 1631 | const void *param, unsigned int param_size) |
| 1632 | { |
| 1633 | struct qla_tgt_sess_work_param *prm; |
| 1634 | unsigned long flags; |
| 1635 | |
| 1636 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); |
| 1637 | if (!prm) { |
| 1638 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, |
| 1639 | "qla_target(%d): Unable to create session " |
| 1640 | "work, command will be refused", 0); |
| 1641 | return -ENOMEM; |
| 1642 | } |
| 1643 | |
| 1644 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, |
| 1645 | "Scheduling work (type %d, prm %p)" |
| 1646 | " to find session for param %p (size %d, tgt %p)\n", |
| 1647 | type, prm, param, param_size, tgt); |
| 1648 | |
| 1649 | prm->type = type; |
| 1650 | memcpy(&prm->tm_iocb, param, param_size); |
| 1651 | |
| 1652 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1653 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); |
| 1654 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1655 | |
| 1656 | schedule_work(&tgt->sess_work); |
| 1657 | |
| 1658 | return 0; |
| 1659 | } |
| 1660 | |
| 1661 | /* |
| 1662 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1663 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1664 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1665 | struct imm_ntfy_from_isp *ntfy, |
| 1666 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 1667 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) |
| 1668 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1669 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1670 | struct qla_hw_data *ha = vha->hw; |
| 1671 | request_t *pkt; |
| 1672 | struct nack_to_isp *nack; |
| 1673 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 1674 | if (!ha->flags.fw_started) |
| 1675 | return; |
| 1676 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1677 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); |
| 1678 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1679 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1680 | if (!pkt) { |
| 1681 | ql_dbg(ql_dbg_tgt, vha, 0xe049, |
| 1682 | "qla_target(%d): %s failed: unable to allocate " |
| 1683 | "request packet\n", vha->vp_idx, __func__); |
| 1684 | return; |
| 1685 | } |
| 1686 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1687 | if (vha->vha_tgt.qla_tgt != NULL) |
| 1688 | vha->vha_tgt.qla_tgt->notify_ack_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1689 | |
| 1690 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 1691 | pkt->entry_count = 1; |
| 1692 | |
| 1693 | nack = (struct nack_to_isp *)pkt; |
| 1694 | nack->ox_id = ntfy->ox_id; |
| 1695 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1696 | nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1697 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 1698 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 1699 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 1700 | cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1701 | } |
| 1702 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 1703 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 1704 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1705 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1706 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 1707 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 1708 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 1709 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); |
| 1710 | nack->u.isp24.srr_reject_code = srr_reject_code; |
| 1711 | nack->u.isp24.srr_reject_code_expl = srr_explan; |
| 1712 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 1713 | |
| 1714 | ql_dbg(ql_dbg_tgt, vha, 0xe005, |
| 1715 | "qla_target(%d): Sending 24xx Notify Ack %d\n", |
| 1716 | vha->vp_idx, nack->u.isp24.status); |
| 1717 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1718 | /* Memory Barrier */ |
| 1719 | wmb(); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1720 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1721 | } |
| 1722 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1723 | static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd) |
| 1724 | { |
| 1725 | struct scsi_qla_host *vha = mcmd->vha; |
| 1726 | struct qla_hw_data *ha = vha->hw; |
| 1727 | struct abts_resp_to_24xx *resp; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 1728 | __le32 f_ctl; |
| 1729 | uint32_t h; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1730 | uint8_t *p; |
| 1731 | int rc; |
| 1732 | struct abts_recv_from_24xx *abts = &mcmd->orig_iocb.abts; |
| 1733 | struct qla_qpair *qpair = mcmd->qpair; |
| 1734 | |
| 1735 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1736 | "Sending task mgmt ABTS response (ha=%p, status=%x)\n", |
| 1737 | ha, mcmd->fc_tm_rsp); |
| 1738 | |
| 1739 | rc = qlt_check_reserve_free_req(qpair, 1); |
| 1740 | if (rc) { |
| 1741 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1742 | "qla_target(%d): %s failed: unable to allocate request packet\n", |
| 1743 | vha->vp_idx, __func__); |
| 1744 | return -EAGAIN; |
| 1745 | } |
| 1746 | |
| 1747 | resp = (struct abts_resp_to_24xx *)qpair->req->ring_ptr; |
| 1748 | memset(resp, 0, sizeof(*resp)); |
| 1749 | |
| 1750 | h = qlt_make_handle(qpair); |
| 1751 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 1752 | /* |
| 1753 | * CTIO type 7 from the firmware doesn't provide a way to |
| 1754 | * know the initiator's LOOP ID, hence we can't find |
| 1755 | * the session and, so, the command. |
| 1756 | */ |
| 1757 | return -EAGAIN; |
| 1758 | } else { |
| 1759 | qpair->req->outstanding_cmds[h] = (srb_t *)mcmd; |
| 1760 | } |
| 1761 | |
Bart Van Assche | c25eb70 | 2020-02-19 20:34:40 -0800 | [diff] [blame] | 1762 | resp->handle = make_handle(qpair->req->id, h); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1763 | resp->entry_type = ABTS_RESP_24XX; |
| 1764 | resp->entry_count = 1; |
| 1765 | resp->nport_handle = abts->nport_handle; |
| 1766 | resp->vp_index = vha->vp_idx; |
| 1767 | resp->sof_type = abts->sof_type; |
| 1768 | resp->exchange_address = abts->exchange_address; |
| 1769 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
| 1770 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
| 1771 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1772 | F_CTL_SEQ_INITIATIVE); |
| 1773 | p = (uint8_t *)&f_ctl; |
| 1774 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1775 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1776 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1777 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1778 | resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id; |
| 1779 | resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1780 | |
| 1781 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1782 | if (mcmd->fc_tm_rsp == FCP_TMF_CMPL) { |
| 1783 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1784 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1785 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 1786 | resp->payload.ba_acct.high_seq_cnt = cpu_to_le16(0xFFFF); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1787 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1788 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1789 | } else { |
| 1790 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1791 | resp->payload.ba_rjt.reason_code = |
| 1792 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1793 | /* Other bytes are zero */ |
| 1794 | } |
| 1795 | |
| 1796 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
| 1797 | |
| 1798 | /* Memory Barrier */ |
| 1799 | wmb(); |
| 1800 | if (qpair->reqq_start_iocbs) |
| 1801 | qpair->reqq_start_iocbs(qpair); |
| 1802 | else |
| 1803 | qla2x00_start_iocbs(vha, qpair->req); |
| 1804 | |
| 1805 | return rc; |
| 1806 | } |
| 1807 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1808 | /* |
| 1809 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1810 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1811 | static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1812 | struct abts_recv_from_24xx *abts, uint32_t status, |
| 1813 | bool ids_reversed) |
| 1814 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1815 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1816 | struct qla_hw_data *ha = vha->hw; |
| 1817 | struct abts_resp_to_24xx *resp; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 1818 | __le32 f_ctl; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1819 | uint8_t *p; |
| 1820 | |
| 1821 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1822 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", |
| 1823 | ha, abts, status); |
| 1824 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1825 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, |
| 1826 | NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1827 | if (!resp) { |
| 1828 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1829 | "qla_target(%d): %s failed: unable to allocate " |
| 1830 | "request packet", vha->vp_idx, __func__); |
| 1831 | return; |
| 1832 | } |
| 1833 | |
| 1834 | resp->entry_type = ABTS_RESP_24XX; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1835 | resp->handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1836 | resp->entry_count = 1; |
| 1837 | resp->nport_handle = abts->nport_handle; |
| 1838 | resp->vp_index = vha->vp_idx; |
| 1839 | resp->sof_type = abts->sof_type; |
| 1840 | resp->exchange_address = abts->exchange_address; |
| 1841 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1842 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1843 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1844 | F_CTL_SEQ_INITIATIVE); |
| 1845 | p = (uint8_t *)&f_ctl; |
| 1846 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1847 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1848 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1849 | if (ids_reversed) { |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1850 | resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.d_id; |
| 1851 | resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.s_id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1852 | } else { |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1853 | resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id; |
| 1854 | resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1855 | } |
| 1856 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1857 | if (status == FCP_TMF_CMPL) { |
| 1858 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1859 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1860 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 1861 | resp->payload.ba_acct.high_seq_cnt = cpu_to_le16(0xFFFF); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1862 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1863 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1864 | } else { |
| 1865 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1866 | resp->payload.ba_rjt.reason_code = |
| 1867 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1868 | /* Other bytes are zero */ |
| 1869 | } |
| 1870 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1871 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1872 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1873 | /* Memory Barrier */ |
| 1874 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 1875 | if (qpair->reqq_start_iocbs) |
| 1876 | qpair->reqq_start_iocbs(qpair); |
| 1877 | else |
| 1878 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | /* |
| 1882 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1883 | */ |
| 1884 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1885 | 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] | 1886 | { |
| 1887 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1888 | u16 tmp; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1889 | struct abts_recv_from_24xx *entry; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1890 | |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1891 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1892 | if (ctio == NULL) { |
| 1893 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, |
| 1894 | "qla_target(%d): %s failed: unable to allocate " |
| 1895 | "request packet\n", vha->vp_idx, __func__); |
| 1896 | return; |
| 1897 | } |
| 1898 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1899 | if (mcmd) |
| 1900 | /* abts from remote port */ |
| 1901 | entry = &mcmd->orig_iocb.abts; |
| 1902 | else |
| 1903 | /* abts from this driver. */ |
| 1904 | entry = (struct abts_recv_from_24xx *)pkt; |
| 1905 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1906 | /* |
| 1907 | * We've got on entrance firmware's response on by us generated |
| 1908 | * ABTS response. So, in it ID fields are reversed. |
| 1909 | */ |
| 1910 | |
| 1911 | ctio->entry_type = CTIO_TYPE7; |
| 1912 | ctio->entry_count = 1; |
| 1913 | ctio->nport_handle = entry->nport_handle; |
| 1914 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1915 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1916 | ctio->vp_index = vha->vp_idx; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1917 | ctio->exchange_addr = entry->exchange_addr_to_abort; |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1918 | tmp = (CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1919 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1920 | if (mcmd) { |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1921 | ctio->initiator_id = entry->fcp_hdr_le.s_id; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1922 | |
| 1923 | if (mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) |
| 1924 | tmp |= (mcmd->abort_io_attr << 9); |
| 1925 | else if (qpair->retry_term_cnt & 1) |
| 1926 | tmp |= (0x4 << 9); |
| 1927 | } else { |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1928 | ctio->initiator_id = entry->fcp_hdr_le.d_id; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1929 | |
| 1930 | if (qpair->retry_term_cnt & 1) |
| 1931 | tmp |= (0x4 << 9); |
| 1932 | } |
| 1933 | ctio->u.status1.flags = cpu_to_le16(tmp); |
| 1934 | ctio->u.status1.ox_id = entry->fcp_hdr_le.ox_id; |
| 1935 | |
| 1936 | ql_dbg(ql_dbg_tgt, vha, 0xe007, |
| 1937 | "Sending retry TERM EXCH CTIO7 flags %04xh oxid %04xh attr valid %x\n", |
| 1938 | le16_to_cpu(ctio->u.status1.flags), |
| 1939 | le16_to_cpu(ctio->u.status1.ox_id), |
| 1940 | (mcmd && mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) ? 1 : 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1941 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1942 | /* Memory Barrier */ |
| 1943 | wmb(); |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1944 | if (qpair->reqq_start_iocbs) |
| 1945 | qpair->reqq_start_iocbs(qpair); |
| 1946 | else |
| 1947 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1948 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1949 | if (mcmd) |
| 1950 | qlt_build_abts_resp_iocb(mcmd); |
| 1951 | else |
| 1952 | qlt_24xx_send_abts_resp(qpair, |
| 1953 | (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1954 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | /* drop cmds for the given lun |
| 1958 | * XXX only looks for cmds on the port through which lun reset was recieved |
| 1959 | * XXX does not go through the list of other port (which may have cmds |
| 1960 | * for the same lun) |
| 1961 | */ |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 1962 | 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] | 1963 | { |
| 1964 | struct qla_tgt_sess_op *op; |
| 1965 | struct qla_tgt_cmd *cmd; |
| 1966 | uint32_t key; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1967 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1968 | |
| 1969 | key = sid_to_key(s_id); |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1970 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1971 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1972 | uint32_t op_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1973 | u64 op_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1974 | |
| 1975 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1976 | op_lun = scsilun_to_int( |
| 1977 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1978 | if (op_key == key && op_lun == lun) |
| 1979 | op->aborted = true; |
| 1980 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1981 | |
| 1982 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1983 | uint32_t op_key; |
| 1984 | u64 op_lun; |
| 1985 | |
| 1986 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1987 | op_lun = scsilun_to_int( |
| 1988 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1989 | if (op_key == key && op_lun == lun) |
| 1990 | op->aborted = true; |
| 1991 | } |
| 1992 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1993 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1994 | uint32_t cmd_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1995 | u64 cmd_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1996 | |
| 1997 | cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 1998 | cmd_lun = scsilun_to_int( |
| 1999 | (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); |
| 2000 | if (cmd_key == key && cmd_lun == lun) |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 2001 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2002 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 2003 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2004 | } |
| 2005 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2006 | static struct qla_qpair_hint *qlt_find_qphint(struct scsi_qla_host *vha, |
| 2007 | uint64_t unpacked_lun) |
| 2008 | { |
| 2009 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 2010 | struct qla_qpair_hint *h = NULL; |
| 2011 | |
| 2012 | if (vha->flags.qpairs_available) { |
| 2013 | h = btree_lookup64(&tgt->lun_qpair_map, unpacked_lun); |
| 2014 | if (!h) |
| 2015 | h = &tgt->qphints[0]; |
| 2016 | } else { |
| 2017 | h = &tgt->qphints[0]; |
| 2018 | } |
| 2019 | |
| 2020 | return h; |
| 2021 | } |
| 2022 | |
| 2023 | static void qlt_do_tmr_work(struct work_struct *work) |
| 2024 | { |
| 2025 | struct qla_tgt_mgmt_cmd *mcmd = |
| 2026 | container_of(work, struct qla_tgt_mgmt_cmd, work); |
| 2027 | struct qla_hw_data *ha = mcmd->vha->hw; |
| 2028 | int rc = EIO; |
| 2029 | uint32_t tag; |
| 2030 | unsigned long flags; |
| 2031 | |
| 2032 | switch (mcmd->tmr_func) { |
| 2033 | case QLA_TGT_ABTS: |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 2034 | tag = le32_to_cpu(mcmd->orig_iocb.abts.exchange_addr_to_abort); |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2035 | break; |
| 2036 | default: |
| 2037 | tag = 0; |
| 2038 | break; |
| 2039 | } |
| 2040 | |
| 2041 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, mcmd->unpacked_lun, |
| 2042 | mcmd->tmr_func, tag); |
| 2043 | |
| 2044 | if (rc != 0) { |
| 2045 | spin_lock_irqsave(mcmd->qpair->qp_lock_ptr, flags); |
| 2046 | switch (mcmd->tmr_func) { |
| 2047 | case QLA_TGT_ABTS: |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2048 | mcmd->fc_tm_rsp = FCP_TMF_REJECTED; |
| 2049 | qlt_build_abts_resp_iocb(mcmd); |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2050 | break; |
| 2051 | case QLA_TGT_LUN_RESET: |
| 2052 | case QLA_TGT_CLEAR_TS: |
| 2053 | case QLA_TGT_ABORT_TS: |
| 2054 | case QLA_TGT_CLEAR_ACA: |
| 2055 | case QLA_TGT_TARGET_RESET: |
| 2056 | qlt_send_busy(mcmd->qpair, &mcmd->orig_iocb.atio, |
| 2057 | qla_sam_status); |
| 2058 | break; |
| 2059 | |
| 2060 | case QLA_TGT_ABORT_ALL: |
| 2061 | case QLA_TGT_NEXUS_LOSS_SESS: |
| 2062 | case QLA_TGT_NEXUS_LOSS: |
| 2063 | qlt_send_notify_ack(mcmd->qpair, |
| 2064 | &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); |
| 2065 | break; |
| 2066 | } |
| 2067 | spin_unlock_irqrestore(mcmd->qpair->qp_lock_ptr, flags); |
| 2068 | |
| 2069 | ql_dbg(ql_dbg_tgt_mgt, mcmd->vha, 0xf052, |
| 2070 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 2071 | mcmd->vha->vp_idx, rc); |
| 2072 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2073 | } |
| 2074 | } |
| 2075 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2076 | /* ha->hardware_lock supposed to be held on entry */ |
| 2077 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 2078 | struct abts_recv_from_24xx *abts, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2079 | { |
| 2080 | struct qla_hw_data *ha = vha->hw; |
| 2081 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2082 | struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0]; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 2083 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2084 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, |
| 2085 | "qla_target(%d): task abort (tag=%d)\n", |
| 2086 | vha->vp_idx, abts->exchange_addr_to_abort); |
| 2087 | |
| 2088 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 2089 | if (mcmd == NULL) { |
| 2090 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, |
| 2091 | "qla_target(%d): %s: Allocation of ABORT cmd failed", |
| 2092 | vha->vp_idx, __func__); |
| 2093 | return -ENOMEM; |
| 2094 | } |
| 2095 | memset(mcmd, 0, sizeof(*mcmd)); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2096 | mcmd->cmd_type = TYPE_TGT_TMCMD; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2097 | mcmd->sess = sess; |
| 2098 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2099 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 2100 | mcmd->tmr_func = QLA_TGT_ABTS; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2101 | mcmd->qpair = h->qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 2102 | mcmd->vha = vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2103 | |
Nicholas Bellinger | eb5ae23 | 2017-06-03 07:07:21 -0700 | [diff] [blame] | 2104 | /* |
| 2105 | * LUN is looked up by target-core internally based on the passed |
| 2106 | * abts->exchange_addr_to_abort tag. |
| 2107 | */ |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2108 | mcmd->se_cmd.cpuid = h->cpuid; |
| 2109 | |
| 2110 | if (ha->tgt.tgt_ops->find_cmd_by_tag) { |
| 2111 | struct qla_tgt_cmd *abort_cmd; |
| 2112 | |
| 2113 | abort_cmd = ha->tgt.tgt_ops->find_cmd_by_tag(sess, |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 2114 | le32_to_cpu(abts->exchange_addr_to_abort)); |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2115 | if (abort_cmd && abort_cmd->qpair) { |
| 2116 | mcmd->qpair = abort_cmd->qpair; |
| 2117 | mcmd->se_cmd.cpuid = abort_cmd->se_cmd.cpuid; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2118 | mcmd->abort_io_attr = abort_cmd->atio.u.isp24.attr; |
| 2119 | mcmd->flags = QLA24XX_MGMT_ABORT_IO_ATTR_VALID; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2120 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2121 | } |
| 2122 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2123 | INIT_WORK(&mcmd->work, qlt_do_tmr_work); |
| 2124 | queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, &mcmd->work); |
| 2125 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2126 | return 0; |
| 2127 | } |
| 2128 | |
| 2129 | /* |
| 2130 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2131 | */ |
| 2132 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 2133 | struct abts_recv_from_24xx *abts) |
| 2134 | { |
| 2135 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 2136 | struct fc_port *sess; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 2137 | uint32_t tag = le32_to_cpu(abts->exchange_addr_to_abort); |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2138 | be_id_t s_id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2139 | int rc; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2140 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2141 | |
| 2142 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { |
| 2143 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, |
| 2144 | "qla_target(%d): ABTS: Abort Sequence not " |
| 2145 | "supported\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2146 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2147 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2148 | return; |
| 2149 | } |
| 2150 | |
| 2151 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { |
| 2152 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, |
| 2153 | "qla_target(%d): ABTS: Unknown Exchange " |
| 2154 | "Address received\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2155 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2156 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2157 | return; |
| 2158 | } |
| 2159 | |
| 2160 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, |
| 2161 | "qla_target(%d): task abort (s_id=%x:%x:%x, " |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2162 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id.domain, |
| 2163 | 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] | 2164 | le32_to_cpu(abts->fcp_hdr_le.parameter)); |
| 2165 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2166 | s_id = le_id_to_be(abts->fcp_hdr_le.s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2167 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2168 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2169 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 2170 | if (!sess) { |
| 2171 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, |
Colin Ian King | 03fea73 | 2018-03-19 10:53:41 +0000 | [diff] [blame] | 2172 | "qla_target(%d): task abort for non-existent session\n", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2173 | vha->vp_idx); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2174 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 2175 | |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [diff] [blame] | 2176 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2177 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2178 | return; |
| 2179 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2180 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 2181 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2182 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2183 | if (sess->deleted) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2184 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2185 | false); |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 2186 | return; |
| 2187 | } |
| 2188 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2189 | rc = __qlt_24xx_handle_abts(vha, abts, sess); |
| 2190 | if (rc != 0) { |
| 2191 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, |
| 2192 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", |
| 2193 | vha->vp_idx, rc); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2194 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2195 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2196 | return; |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | /* |
| 2201 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2202 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2203 | static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2204 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) |
| 2205 | { |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 2206 | struct scsi_qla_host *ha = mcmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2207 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; |
| 2208 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2209 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2210 | |
| 2211 | ql_dbg(ql_dbg_tgt, ha, 0xe008, |
| 2212 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", |
| 2213 | ha, atio, resp_code); |
| 2214 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2215 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2216 | ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2217 | if (ctio == NULL) { |
| 2218 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, |
| 2219 | "qla_target(%d): %s failed: unable to allocate " |
| 2220 | "request packet\n", ha->vp_idx, __func__); |
| 2221 | return; |
| 2222 | } |
| 2223 | |
| 2224 | ctio->entry_type = CTIO_TYPE7; |
| 2225 | ctio->entry_count = 1; |
| 2226 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 2227 | ctio->nport_handle = cpu_to_le16(mcmd->sess->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2228 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2229 | ctio->vp_index = ha->vp_idx; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2230 | 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] | 2231 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2232 | temp = (atio->u.isp24.attr << 9)| |
| 2233 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2234 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2235 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2236 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2237 | ctio->u.status1.scsi_status = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2238 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); |
| 2239 | ctio->u.status1.response_len = cpu_to_le16(8); |
Roland Dreier | e4b11b8 | 2012-09-18 15:10:56 -0700 | [diff] [blame] | 2240 | ctio->u.status1.sense_data[0] = resp_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2241 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2242 | /* Memory Barrier */ |
| 2243 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2244 | if (qpair->reqq_start_iocbs) |
| 2245 | qpair->reqq_start_iocbs(qpair); |
| 2246 | else |
| 2247 | qla2x00_start_iocbs(ha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) |
| 2251 | { |
| 2252 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2253 | } |
| 2254 | EXPORT_SYMBOL(qlt_free_mcmd); |
| 2255 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2256 | /* |
| 2257 | * ha->hardware_lock supposed to be held on entry. Might drop it, then |
| 2258 | * reacquire |
| 2259 | */ |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2260 | 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] | 2261 | uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq) |
| 2262 | { |
| 2263 | struct atio_from_isp *atio = &cmd->atio; |
| 2264 | struct ctio7_to_24xx *ctio; |
| 2265 | uint16_t temp; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2266 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2267 | |
| 2268 | ql_dbg(ql_dbg_tgt_dif, vha, 0x3066, |
| 2269 | "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, " |
| 2270 | "sense_key=%02x, asc=%02x, ascq=%02x", |
| 2271 | vha, atio, scsi_status, sense_key, asc, ascq); |
| 2272 | |
| 2273 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL); |
| 2274 | if (!ctio) { |
| 2275 | ql_dbg(ql_dbg_async, vha, 0x3067, |
| 2276 | "qla2x00t(%ld): %s failed: unable to allocate request packet", |
| 2277 | vha->host_no, __func__); |
| 2278 | goto out; |
| 2279 | } |
| 2280 | |
| 2281 | ctio->entry_type = CTIO_TYPE7; |
| 2282 | ctio->entry_count = 1; |
| 2283 | ctio->handle = QLA_TGT_SKIP_HANDLE; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 2284 | ctio->nport_handle = cpu_to_le16(cmd->sess->loop_id); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2285 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
| 2286 | ctio->vp_index = vha->vp_idx; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2287 | 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] | 2288 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2289 | temp = (atio->u.isp24.attr << 9) | |
| 2290 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2291 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2292 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2293 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
| 2294 | ctio->u.status1.scsi_status = |
| 2295 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status); |
| 2296 | ctio->u.status1.response_len = cpu_to_le16(18); |
| 2297 | ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio)); |
| 2298 | |
| 2299 | if (ctio->u.status1.residual != 0) |
| 2300 | ctio->u.status1.scsi_status |= |
| 2301 | cpu_to_le16(SS_RESIDUAL_UNDER); |
| 2302 | |
Bart Van Assche | a861b49 | 2019-04-17 14:44:42 -0700 | [diff] [blame] | 2303 | /* Fixed format sense data. */ |
| 2304 | ctio->u.status1.sense_data[0] = 0x70; |
| 2305 | ctio->u.status1.sense_data[2] = sense_key; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2306 | /* Additional sense length */ |
Bart Van Assche | a861b49 | 2019-04-17 14:44:42 -0700 | [diff] [blame] | 2307 | ctio->u.status1.sense_data[7] = 0xa; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2308 | /* ASC and ASCQ */ |
Bart Van Assche | a861b49 | 2019-04-17 14:44:42 -0700 | [diff] [blame] | 2309 | ctio->u.status1.sense_data[12] = asc; |
| 2310 | ctio->u.status1.sense_data[13] = ascq; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2311 | |
| 2312 | /* Memory Barrier */ |
| 2313 | wmb(); |
| 2314 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2315 | if (qpair->reqq_start_iocbs) |
| 2316 | qpair->reqq_start_iocbs(qpair); |
| 2317 | else |
| 2318 | qla2x00_start_iocbs(vha, qpair->req); |
| 2319 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2320 | out: |
| 2321 | return; |
| 2322 | } |
| 2323 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2324 | /* callback from target fabric module code */ |
| 2325 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) |
| 2326 | { |
| 2327 | struct scsi_qla_host *vha = mcmd->sess->vha; |
| 2328 | struct qla_hw_data *ha = vha->hw; |
| 2329 | unsigned long flags; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2330 | struct qla_qpair *qpair = mcmd->qpair; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2331 | bool free_mcmd = true; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2332 | |
| 2333 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, |
| 2334 | "TM response mcmd (%p) status %#x state %#x", |
| 2335 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); |
| 2336 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2337 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2338 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2339 | if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2340 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2341 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2342 | * previous life, just abort the processing. |
| 2343 | */ |
| 2344 | ql_dbg(ql_dbg_async, vha, 0xe100, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2345 | "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2346 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2347 | mcmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2348 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2349 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2350 | return; |
| 2351 | } |
| 2352 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2353 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) { |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2354 | switch (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode) { |
| 2355 | case ELS_LOGO: |
| 2356 | case ELS_PRLO: |
| 2357 | case ELS_TPRLO: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2358 | ql_dbg(ql_dbg_disc, vha, 0x2106, |
Bart Van Assche | 19ce192 | 2019-04-17 14:44:11 -0700 | [diff] [blame] | 2359 | "TM response logo %8phC status %#x state %#x", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2360 | mcmd->sess->port_name, mcmd->fc_tm_rsp, |
| 2361 | mcmd->flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 2362 | qlt_schedule_sess_for_deletion(mcmd->sess); |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2363 | break; |
| 2364 | default: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2365 | qlt_send_notify_ack(vha->hw->base_qpair, |
| 2366 | &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2367 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2368 | } |
| 2369 | } else { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2370 | if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) { |
| 2371 | qlt_build_abts_resp_iocb(mcmd); |
| 2372 | free_mcmd = false; |
| 2373 | } else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2374 | qlt_24xx_send_task_mgmt_ctio(qpair, mcmd, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2375 | mcmd->fc_tm_rsp); |
| 2376 | } |
| 2377 | /* |
| 2378 | * Make the callback for ->free_mcmd() to queue_work() and invoke |
| 2379 | * target_put_sess_cmd() to drop cmd_kref to 1. The final |
| 2380 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() |
| 2381 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd |
| 2382 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> |
| 2383 | * qlt_xmit_tm_rsp() returns here.. |
| 2384 | */ |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2385 | if (free_mcmd) |
| 2386 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 2387 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2388 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2389 | } |
| 2390 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); |
| 2391 | |
| 2392 | /* No locks */ |
| 2393 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) |
| 2394 | { |
| 2395 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2396 | |
| 2397 | BUG_ON(cmd->sg_cnt == 0); |
| 2398 | |
| 2399 | prm->sg = (struct scatterlist *)cmd->sg; |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2400 | prm->seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, cmd->sg, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2401 | cmd->sg_cnt, cmd->dma_data_direction); |
| 2402 | if (unlikely(prm->seg_cnt == 0)) |
| 2403 | goto out_err; |
| 2404 | |
| 2405 | prm->cmd->sg_mapped = 1; |
| 2406 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2407 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
| 2408 | /* |
| 2409 | * If greater than four sg entries then we need to allocate |
| 2410 | * the continuation entries |
| 2411 | */ |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2412 | if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2413 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2414 | QLA_TGT_DATASEGS_PER_CMD_24XX, |
| 2415 | QLA_TGT_DATASEGS_PER_CONT_24XX); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2416 | } else { |
| 2417 | /* DIF */ |
| 2418 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2419 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2420 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); |
| 2421 | prm->tot_dsds = prm->seg_cnt; |
| 2422 | } else |
| 2423 | prm->tot_dsds = prm->seg_cnt; |
| 2424 | |
| 2425 | if (cmd->prot_sg_cnt) { |
| 2426 | prm->prot_sg = cmd->prot_sg; |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2427 | prm->prot_seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2428 | cmd->prot_sg, cmd->prot_sg_cnt, |
| 2429 | cmd->dma_data_direction); |
| 2430 | if (unlikely(prm->prot_seg_cnt == 0)) |
| 2431 | goto out_err; |
| 2432 | |
| 2433 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2434 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2435 | /* Dif Bundling not support here */ |
| 2436 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, |
| 2437 | cmd->blk_sz); |
| 2438 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2439 | } else |
| 2440 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2441 | } |
| 2442 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2443 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2444 | return 0; |
| 2445 | |
| 2446 | out_err: |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2447 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2448 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", |
| 2449 | 0, prm->cmd->sg_cnt); |
| 2450 | return -1; |
| 2451 | } |
| 2452 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2453 | 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] | 2454 | { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2455 | struct qla_hw_data *ha; |
| 2456 | struct qla_qpair *qpair; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 2457 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2458 | if (!cmd->sg_mapped) |
| 2459 | return; |
| 2460 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2461 | qpair = cmd->qpair; |
| 2462 | |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2463 | dma_unmap_sg(&qpair->pdev->dev, cmd->sg, cmd->sg_cnt, |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2464 | cmd->dma_data_direction); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2465 | cmd->sg_mapped = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2466 | |
| 2467 | if (cmd->prot_sg_cnt) |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2468 | 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] | 2469 | cmd->dma_data_direction); |
| 2470 | |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2471 | if (!cmd->ctx) |
| 2472 | return; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2473 | ha = vha->hw; |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2474 | if (cmd->ctx_dsd_alloced) |
| 2475 | qla2x00_clean_dsd_pool(ha, cmd->ctx); |
| 2476 | |
| 2477 | 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] | 2478 | } |
| 2479 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2480 | static int qlt_check_reserve_free_req(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2481 | uint32_t req_cnt) |
| 2482 | { |
Quinn Tran | d63b328 | 2017-06-02 09:12:07 -0700 | [diff] [blame] | 2483 | uint32_t cnt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2484 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2485 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2486 | if (req->cnt < (req_cnt + 2)) { |
Quinn Tran | af7bb38 | 2017-06-13 20:47:23 -0700 | [diff] [blame] | 2487 | cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr : |
Bart Van Assche | 04474d3 | 2020-05-18 14:17:08 -0700 | [diff] [blame] | 2488 | rd_reg_dword_relaxed(req->req_q_out)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2489 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2490 | if (req->ring_index < cnt) |
| 2491 | req->cnt = cnt - req->ring_index; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2492 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2493 | req->cnt = req->length - (req->ring_index - cnt); |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2494 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2495 | if (unlikely(req->cnt < (req_cnt + 2))) |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2496 | return -EAGAIN; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2497 | } |
| 2498 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2499 | req->cnt -= req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2500 | |
| 2501 | return 0; |
| 2502 | } |
| 2503 | |
| 2504 | /* |
| 2505 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2506 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2507 | static inline void *qlt_get_req_pkt(struct req_que *req) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2508 | { |
| 2509 | /* Adjust ring index. */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2510 | req->ring_index++; |
| 2511 | if (req->ring_index == req->length) { |
| 2512 | req->ring_index = 0; |
| 2513 | req->ring_ptr = req->ring; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2514 | } else { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2515 | req->ring_ptr++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2516 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2517 | return (cont_entry_t *)req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2521 | static inline uint32_t qlt_make_handle(struct qla_qpair *qpair) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2522 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2523 | uint32_t h; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2524 | int index; |
| 2525 | uint8_t found = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2526 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2527 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2528 | h = req->current_outstanding_cmd; |
| 2529 | |
| 2530 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
| 2531 | h++; |
| 2532 | if (h == req->num_outstanding_cmds) |
| 2533 | h = 1; |
| 2534 | |
| 2535 | if (h == QLA_TGT_SKIP_HANDLE) |
| 2536 | continue; |
| 2537 | |
| 2538 | if (!req->outstanding_cmds[h]) { |
| 2539 | found = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2540 | break; |
| 2541 | } |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2542 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2543 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2544 | if (found) { |
| 2545 | req->current_outstanding_cmd = h; |
| 2546 | } else { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2547 | ql_dbg(ql_dbg_io, qpair->vha, 0x305b, |
| 2548 | "qla_target(%d): Ran out of empty cmd slots\n", |
| 2549 | qpair->vha->vp_idx); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2550 | h = QLA_TGT_NULL_HANDLE; |
| 2551 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2552 | |
| 2553 | return h; |
| 2554 | } |
| 2555 | |
| 2556 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2557 | static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair, |
| 2558 | struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2559 | { |
| 2560 | uint32_t h; |
| 2561 | struct ctio7_to_24xx *pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2562 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2563 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2564 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2565 | pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2566 | prm->pkt = pkt; |
| 2567 | memset(pkt, 0, sizeof(*pkt)); |
| 2568 | |
| 2569 | pkt->entry_type = CTIO_TYPE7; |
| 2570 | pkt->entry_count = (uint8_t)prm->req_cnt; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2571 | pkt->vp_index = prm->cmd->vp_idx; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2572 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2573 | h = qlt_make_handle(qpair); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2574 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2575 | /* |
| 2576 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2577 | * know the initiator's LOOP ID, hence we can't find |
| 2578 | * the session and, so, the command. |
| 2579 | */ |
| 2580 | return -EAGAIN; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 2581 | } else |
| 2582 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2583 | |
Bart Van Assche | c25eb70 | 2020-02-19 20:34:40 -0800 | [diff] [blame] | 2584 | pkt->handle = make_handle(qpair->req->id, h); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2585 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
| 2586 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2587 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 2588 | 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] | 2589 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2590 | temp = atio->u.isp24.attr << 9; |
| 2591 | pkt->u.status0.flags |= cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2592 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2593 | pkt->u.status0.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2594 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2595 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2596 | return 0; |
| 2597 | } |
| 2598 | |
| 2599 | /* |
| 2600 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2601 | * that there is sufficient amount of request entries to not drop it. |
| 2602 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2603 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2604 | { |
| 2605 | int cnt; |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2606 | struct dsd64 *cur_dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2607 | |
| 2608 | /* Build continuation packets */ |
| 2609 | while (prm->seg_cnt > 0) { |
| 2610 | cont_a64_entry_t *cont_pkt64 = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2611 | (cont_a64_entry_t *)qlt_get_req_pkt( |
| 2612 | prm->cmd->qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2613 | |
| 2614 | /* |
| 2615 | * Make sure that from cont_pkt64 none of |
| 2616 | * 64-bit specific fields used for 32-bit |
| 2617 | * addressing. Cast to (cont_entry_t *) for |
| 2618 | * that. |
| 2619 | */ |
| 2620 | |
| 2621 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); |
| 2622 | |
| 2623 | cont_pkt64->entry_count = 1; |
| 2624 | cont_pkt64->sys_define = 0; |
| 2625 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2626 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2627 | cur_dsd = cont_pkt64->dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2628 | |
| 2629 | /* Load continuation entry data segments */ |
| 2630 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2631 | cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2632 | cnt++, prm->seg_cnt--) { |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2633 | append_dsd64(&cur_dsd, prm->sg); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2634 | prm->sg = sg_next(prm->sg); |
| 2635 | } |
| 2636 | } |
| 2637 | } |
| 2638 | |
| 2639 | /* |
| 2640 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2641 | * that there is sufficient amount of request entries to not drop it. |
| 2642 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2643 | static void qlt_load_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2644 | { |
| 2645 | int cnt; |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2646 | struct dsd64 *cur_dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2647 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; |
| 2648 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2649 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
| 2650 | |
| 2651 | /* Setup packet address segment pointer */ |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2652 | cur_dsd = &pkt24->u.status0.dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2653 | |
| 2654 | /* Set total data segment count */ |
| 2655 | if (prm->seg_cnt) |
| 2656 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); |
| 2657 | |
| 2658 | if (prm->seg_cnt == 0) { |
| 2659 | /* No data transfer */ |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2660 | cur_dsd->address = 0; |
| 2661 | cur_dsd->length = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2662 | return; |
| 2663 | } |
| 2664 | |
| 2665 | /* If scatter gather */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2666 | |
| 2667 | /* Load command entry data segments */ |
| 2668 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2669 | (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2670 | cnt++, prm->seg_cnt--) { |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2671 | append_dsd64(&cur_dsd, prm->sg); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2672 | prm->sg = sg_next(prm->sg); |
| 2673 | } |
| 2674 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2675 | qlt_load_cont_data_segments(prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) |
| 2679 | { |
| 2680 | return cmd->bufflen > 0; |
| 2681 | } |
| 2682 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2683 | static void qlt_print_dif_err(struct qla_tgt_prm *prm) |
| 2684 | { |
| 2685 | struct qla_tgt_cmd *cmd; |
| 2686 | struct scsi_qla_host *vha; |
| 2687 | |
| 2688 | /* asc 0x10=dif error */ |
| 2689 | if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) { |
| 2690 | cmd = prm->cmd; |
| 2691 | vha = cmd->vha; |
| 2692 | /* ASCQ */ |
| 2693 | switch (prm->sense_buffer[13]) { |
| 2694 | case 1: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2695 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2696 | "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2697 | "se_cmd=%p tag[%x]", |
| 2698 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2699 | cmd->atio.u.isp24.exchange_addr); |
| 2700 | break; |
| 2701 | case 2: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2702 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2703 | "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2704 | "se_cmd=%p tag[%x]", |
| 2705 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2706 | cmd->atio.u.isp24.exchange_addr); |
| 2707 | break; |
| 2708 | case 3: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2709 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2710 | "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2711 | "se_cmd=%p tag[%x]", |
| 2712 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2713 | cmd->atio.u.isp24.exchange_addr); |
| 2714 | break; |
| 2715 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2716 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe010, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2717 | "BE detected Dif ERR: lba[%llx|%lld] len[%x] " |
| 2718 | "se_cmd=%p tag[%x]", |
| 2719 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2720 | cmd->atio.u.isp24.exchange_addr); |
| 2721 | break; |
| 2722 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2723 | ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2724 | } |
| 2725 | } |
| 2726 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2727 | /* |
| 2728 | * Called without ha->hardware_lock held |
| 2729 | */ |
| 2730 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, |
| 2731 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, |
| 2732 | uint32_t *full_req_cnt) |
| 2733 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2734 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2735 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2736 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2737 | prm->cmd = cmd; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2738 | prm->tgt = cmd->tgt; |
| 2739 | prm->pkt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2740 | prm->rq_result = scsi_status; |
| 2741 | prm->sense_buffer = &cmd->sense_buffer[0]; |
| 2742 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; |
| 2743 | prm->sg = NULL; |
| 2744 | prm->seg_cnt = -1; |
| 2745 | prm->req_cnt = 1; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2746 | prm->residual = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2747 | prm->add_status_pkt = 0; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2748 | prm->prot_sg = NULL; |
| 2749 | prm->prot_seg_cnt = 0; |
| 2750 | prm->tot_dsds = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2751 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2752 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
| 2753 | if (qlt_pci_map_calc_cnt(prm) != 0) |
| 2754 | return -EAGAIN; |
| 2755 | } |
| 2756 | |
| 2757 | *full_req_cnt = prm->req_cnt; |
| 2758 | |
| 2759 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { |
| 2760 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2761 | ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2762 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2763 | prm->residual, se_cmd->tag, |
| 2764 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, |
| 2765 | cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2766 | prm->rq_result |= SS_RESIDUAL_UNDER; |
| 2767 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2768 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2769 | ql_dbg_qp(ql_dbg_io, qpair, 0x305d, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2770 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2771 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? |
| 2772 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2773 | prm->rq_result |= SS_RESIDUAL_OVER; |
| 2774 | } |
| 2775 | |
| 2776 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2777 | /* |
| 2778 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be |
| 2779 | * ignored in *xmit_response() below |
| 2780 | */ |
| 2781 | if (qlt_has_data(cmd)) { |
| 2782 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2783 | (IS_FWI2_CAPABLE(cmd->vha->hw) && |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2784 | (prm->rq_result != 0))) { |
| 2785 | prm->add_status_pkt = 1; |
| 2786 | (*full_req_cnt)++; |
| 2787 | } |
| 2788 | } |
| 2789 | } |
| 2790 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2791 | return 0; |
| 2792 | } |
| 2793 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2794 | static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd, |
| 2795 | int sending_sense) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2796 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2797 | if (cmd->qpair->enable_class_2) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2798 | return 0; |
| 2799 | |
| 2800 | if (sending_sense) |
| 2801 | return cmd->conf_compl_supported; |
| 2802 | else |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2803 | return cmd->qpair->enable_explicit_conf && |
| 2804 | cmd->conf_compl_supported; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2805 | } |
| 2806 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2807 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, |
| 2808 | struct qla_tgt_prm *prm) |
| 2809 | { |
| 2810 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, |
| 2811 | (uint32_t)sizeof(ctio->u.status1.sense_data)); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2812 | ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2813 | if (qlt_need_explicit_conf(prm->cmd, 0)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2814 | ctio->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2815 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2816 | CTIO7_FLAGS_CONFORM_REQ); |
| 2817 | } |
| 2818 | ctio->u.status0.residual = cpu_to_le32(prm->residual); |
| 2819 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); |
| 2820 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { |
| 2821 | int i; |
| 2822 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2823 | if (qlt_need_explicit_conf(prm->cmd, 1)) { |
Quinn Tran | df2e32c | 2017-01-19 22:27:53 -0800 | [diff] [blame] | 2824 | if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) { |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2825 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2826 | "Skipping EXPLICIT_CONFORM and " |
| 2827 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " |
| 2828 | "non GOOD status\n"); |
| 2829 | goto skip_explict_conf; |
| 2830 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2831 | ctio->u.status1.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2832 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2833 | CTIO7_FLAGS_CONFORM_REQ); |
| 2834 | } |
| 2835 | skip_explict_conf: |
| 2836 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2837 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2838 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2839 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2840 | ctio->u.status1.scsi_status |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2841 | cpu_to_le16(SS_SENSE_LEN_VALID); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2842 | ctio->u.status1.sense_length = |
| 2843 | cpu_to_le16(prm->sense_buffer_len); |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 2844 | for (i = 0; i < prm->sense_buffer_len/4; i++) { |
| 2845 | uint32_t v; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2846 | |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 2847 | v = get_unaligned_be32( |
| 2848 | &((uint32_t *)prm->sense_buffer)[i]); |
| 2849 | put_unaligned_le32(v, |
| 2850 | &((uint32_t *)ctio->u.status1.sense_data)[i]); |
| 2851 | } |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2852 | qlt_print_dif_err(prm); |
| 2853 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2854 | } else { |
| 2855 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2856 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2857 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2858 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2859 | ctio->u.status1.sense_length = 0; |
| 2860 | memset(ctio->u.status1.sense_data, 0, |
| 2861 | sizeof(ctio->u.status1.sense_data)); |
| 2862 | } |
| 2863 | |
| 2864 | /* Sense with len > 24, is it possible ??? */ |
| 2865 | } |
| 2866 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2867 | static inline int |
| 2868 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) |
| 2869 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2870 | switch (se_cmd->prot_op) { |
| 2871 | case TARGET_PROT_DOUT_INSERT: |
| 2872 | case TARGET_PROT_DIN_STRIP: |
| 2873 | if (ql2xenablehba_err_chk >= 1) |
| 2874 | return 1; |
| 2875 | break; |
| 2876 | case TARGET_PROT_DOUT_PASS: |
| 2877 | case TARGET_PROT_DIN_PASS: |
| 2878 | if (ql2xenablehba_err_chk >= 2) |
| 2879 | return 1; |
| 2880 | break; |
| 2881 | case TARGET_PROT_DIN_INSERT: |
| 2882 | case TARGET_PROT_DOUT_STRIP: |
| 2883 | return 1; |
| 2884 | default: |
| 2885 | break; |
| 2886 | } |
| 2887 | return 0; |
| 2888 | } |
| 2889 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2890 | static inline int |
| 2891 | qla_tgt_ref_mask_check(struct se_cmd *se_cmd) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2892 | { |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2893 | switch (se_cmd->prot_op) { |
| 2894 | case TARGET_PROT_DIN_INSERT: |
| 2895 | case TARGET_PROT_DOUT_INSERT: |
| 2896 | case TARGET_PROT_DIN_STRIP: |
| 2897 | case TARGET_PROT_DOUT_STRIP: |
| 2898 | case TARGET_PROT_DIN_PASS: |
| 2899 | case TARGET_PROT_DOUT_PASS: |
| 2900 | return 1; |
| 2901 | default: |
| 2902 | return 0; |
| 2903 | } |
| 2904 | return 0; |
| 2905 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2906 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2907 | /* |
| 2908 | * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command |
| 2909 | */ |
| 2910 | static void |
| 2911 | qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx, |
| 2912 | uint16_t *pfw_prot_opts) |
| 2913 | { |
| 2914 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2915 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; |
| 2916 | scsi_qla_host_t *vha = cmd->tgt->vha; |
| 2917 | struct qla_hw_data *ha = vha->hw; |
| 2918 | uint32_t t32 = 0; |
| 2919 | |
| 2920 | /* |
| 2921 | * wait till Mode Sense/Select cmd, modepage Ah, subpage 2 |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2922 | * have been immplemented by TCM, before AppTag is avail. |
| 2923 | * Look for modesense_handlers[] |
| 2924 | */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2925 | ctx->app_tag = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2926 | ctx->app_tag_mask[0] = 0x0; |
| 2927 | ctx->app_tag_mask[1] = 0x0; |
| 2928 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2929 | if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2930 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2931 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2932 | *pfw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2933 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2934 | *pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2935 | } |
| 2936 | |
| 2937 | t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts); |
| 2938 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2939 | switch (se_cmd->prot_type) { |
| 2940 | case TARGET_DIF_TYPE0_PROT: |
| 2941 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2942 | * No check for ql2xenablehba_err_chk, as it |
| 2943 | * would be an I/O error if hba tag generation |
| 2944 | * is not done. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2945 | */ |
| 2946 | ctx->ref_tag = cpu_to_le32(lba); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2947 | /* enable ALL bytes of the ref tag */ |
| 2948 | ctx->ref_tag_mask[0] = 0xff; |
| 2949 | ctx->ref_tag_mask[1] = 0xff; |
| 2950 | ctx->ref_tag_mask[2] = 0xff; |
| 2951 | ctx->ref_tag_mask[3] = 0xff; |
| 2952 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2953 | case TARGET_DIF_TYPE1_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2954 | /* |
| 2955 | * For TYPE 1 protection: 16 bit GUARD tag, 32 bit |
| 2956 | * REF tag, and 16 bit app tag. |
| 2957 | */ |
| 2958 | ctx->ref_tag = cpu_to_le32(lba); |
| 2959 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2960 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2961 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2962 | break; |
| 2963 | } |
| 2964 | /* enable ALL bytes of the ref tag */ |
| 2965 | ctx->ref_tag_mask[0] = 0xff; |
| 2966 | ctx->ref_tag_mask[1] = 0xff; |
| 2967 | ctx->ref_tag_mask[2] = 0xff; |
| 2968 | ctx->ref_tag_mask[3] = 0xff; |
| 2969 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2970 | case TARGET_DIF_TYPE2_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2971 | /* |
| 2972 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF |
| 2973 | * tag has to match LBA in CDB + N |
| 2974 | */ |
| 2975 | ctx->ref_tag = cpu_to_le32(lba); |
| 2976 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2977 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2978 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2979 | break; |
| 2980 | } |
| 2981 | /* enable ALL bytes of the ref tag */ |
| 2982 | ctx->ref_tag_mask[0] = 0xff; |
| 2983 | ctx->ref_tag_mask[1] = 0xff; |
| 2984 | ctx->ref_tag_mask[2] = 0xff; |
| 2985 | ctx->ref_tag_mask[3] = 0xff; |
| 2986 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2987 | case TARGET_DIF_TYPE3_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2988 | /* For TYPE 3 protection: 16 bit GUARD only */ |
| 2989 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2990 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = |
| 2991 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; |
| 2992 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2993 | } |
| 2994 | } |
| 2995 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2996 | static inline int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2997 | 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] | 2998 | { |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2999 | struct dsd64 *cur_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3000 | uint32_t transfer_length = 0; |
| 3001 | uint32_t data_bytes; |
| 3002 | uint32_t dif_bytes; |
| 3003 | uint8_t bundling = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3004 | struct crc_context *crc_ctx_pkt = NULL; |
| 3005 | struct qla_hw_data *ha; |
| 3006 | struct ctio_crc2_to_fw *pkt; |
| 3007 | dma_addr_t crc_ctx_dma; |
| 3008 | uint16_t fw_prot_opts = 0; |
| 3009 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 3010 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 3011 | uint32_t h; |
| 3012 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3013 | struct qla_tc_param tc; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3014 | uint16_t t16; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3015 | scsi_qla_host_t *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3016 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3017 | ha = vha->hw; |
| 3018 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3019 | pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3020 | prm->pkt = pkt; |
| 3021 | memset(pkt, 0, sizeof(*pkt)); |
| 3022 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3023 | ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3024 | "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] | 3025 | cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3026 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); |
| 3027 | |
| 3028 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || |
| 3029 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) |
| 3030 | bundling = 0; |
| 3031 | |
| 3032 | /* Compute dif len and adjust data len to incude protection */ |
| 3033 | data_bytes = cmd->bufflen; |
| 3034 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; |
| 3035 | |
| 3036 | switch (se_cmd->prot_op) { |
| 3037 | case TARGET_PROT_DIN_INSERT: |
| 3038 | case TARGET_PROT_DOUT_STRIP: |
| 3039 | transfer_length = data_bytes; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3040 | if (cmd->prot_sg_cnt) |
| 3041 | data_bytes += dif_bytes; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3042 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3043 | case TARGET_PROT_DIN_STRIP: |
| 3044 | case TARGET_PROT_DOUT_INSERT: |
| 3045 | case TARGET_PROT_DIN_PASS: |
| 3046 | case TARGET_PROT_DOUT_PASS: |
| 3047 | transfer_length = data_bytes + dif_bytes; |
| 3048 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3049 | default: |
| 3050 | BUG(); |
| 3051 | break; |
| 3052 | } |
| 3053 | |
| 3054 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 3055 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 3056 | /* HBA error checking enabled */ |
| 3057 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 3058 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 3059 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 3060 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 3061 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 3062 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 3063 | } |
| 3064 | |
| 3065 | switch (se_cmd->prot_op) { |
| 3066 | case TARGET_PROT_DIN_INSERT: |
| 3067 | case TARGET_PROT_DOUT_INSERT: |
| 3068 | fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 3069 | break; |
| 3070 | case TARGET_PROT_DIN_STRIP: |
| 3071 | case TARGET_PROT_DOUT_STRIP: |
| 3072 | fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 3073 | break; |
| 3074 | case TARGET_PROT_DIN_PASS: |
| 3075 | case TARGET_PROT_DOUT_PASS: |
| 3076 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 3077 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ |
| 3078 | break; |
| 3079 | default:/* Normal Request */ |
| 3080 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 3081 | break; |
| 3082 | } |
| 3083 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3084 | /* ---- PKT ---- */ |
| 3085 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 3086 | pkt->entry_type = CTIO_CRC2; |
| 3087 | pkt->entry_count = 1; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3088 | pkt->vp_index = cmd->vp_idx; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3089 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3090 | h = qlt_make_handle(qpair); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3091 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 3092 | /* |
| 3093 | * CTIO type 7 from the firmware doesn't provide a way to |
| 3094 | * know the initiator's LOOP ID, hence we can't find |
| 3095 | * the session and, so, the command. |
| 3096 | */ |
| 3097 | return -EAGAIN; |
| 3098 | } else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3099 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3100 | |
Bart Van Assche | c25eb70 | 2020-02-19 20:34:40 -0800 | [diff] [blame] | 3101 | pkt->handle = make_handle(qpair->req->id, h); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3102 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3103 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3104 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 3105 | 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] | 3106 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3107 | |
| 3108 | /* silence compile warning */ |
| 3109 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3110 | pkt->ox_id = cpu_to_le16(t16); |
| 3111 | |
| 3112 | t16 = (atio->u.isp24.attr << 9); |
| 3113 | pkt->flags |= cpu_to_le16(t16); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3114 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
| 3115 | |
| 3116 | /* Set transfer direction */ |
| 3117 | if (cmd->dma_data_direction == DMA_TO_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3118 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3119 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3120 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3121 | |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 3122 | pkt->dseg_count = cpu_to_le16(prm->tot_dsds); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3123 | /* Fibre channel byte count */ |
| 3124 | pkt->transfer_length = cpu_to_le32(transfer_length); |
| 3125 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3126 | /* ----- CRC context -------- */ |
| 3127 | |
| 3128 | /* Allocate CRC context from global pool */ |
| 3129 | crc_ctx_pkt = cmd->ctx = |
Souptick Joarder | 501017f | 2018-02-15 01:40:38 +0530 | [diff] [blame] | 3130 | dma_pool_zalloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3131 | |
| 3132 | if (!crc_ctx_pkt) |
| 3133 | goto crc_queuing_error; |
| 3134 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3135 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 3136 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 3137 | |
| 3138 | /* Set handle */ |
| 3139 | crc_ctx_pkt->handle = pkt->handle; |
| 3140 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3141 | qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3142 | |
Bart Van Assche | d4556a4 | 2019-04-17 14:44:39 -0700 | [diff] [blame] | 3143 | put_unaligned_le64(crc_ctx_dma, &pkt->crc_context_address); |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 3144 | pkt->crc_context_len = cpu_to_le16(CRC_CONTEXT_LEN_FW); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3145 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3146 | if (!bundling) { |
Bart Van Assche | 9e75b5e | 2019-08-08 20:01:33 -0700 | [diff] [blame] | 3147 | cur_dsd = &crc_ctx_pkt->u.nobundling.data_dsd[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3148 | } else { |
| 3149 | /* |
| 3150 | * Configure Bundling if we need to fetch interlaving |
| 3151 | * protection PCI accesses |
| 3152 | */ |
| 3153 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 3154 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 3155 | crc_ctx_pkt->u.bundling.dseg_count = |
| 3156 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); |
Bart Van Assche | 9e75b5e | 2019-08-08 20:01:33 -0700 | [diff] [blame] | 3157 | cur_dsd = &crc_ctx_pkt->u.bundling.data_dsd[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | /* Finish the common fields of CRC pkt */ |
| 3161 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); |
| 3162 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 3163 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3164 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3165 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3166 | memset((uint8_t *)&tc, 0 , sizeof(tc)); |
| 3167 | tc.vha = vha; |
| 3168 | tc.blk_sz = cmd->blk_sz; |
| 3169 | tc.bufflen = cmd->bufflen; |
| 3170 | tc.sg = cmd->sg; |
| 3171 | tc.prot_sg = cmd->prot_sg; |
| 3172 | tc.ctx = crc_ctx_pkt; |
| 3173 | tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3174 | |
| 3175 | /* Walks data segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3176 | pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3177 | |
| 3178 | if (!bundling && prm->prot_seg_cnt) { |
| 3179 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3180 | prm->tot_dsds, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3181 | goto crc_queuing_error; |
| 3182 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3183 | (prm->tot_dsds - prm->prot_seg_cnt), &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3184 | goto crc_queuing_error; |
| 3185 | |
| 3186 | if (bundling && prm->prot_seg_cnt) { |
| 3187 | /* Walks dif segments */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3188 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3189 | |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 3190 | cur_dsd = &crc_ctx_pkt->u.bundling.dif_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3191 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, |
Giridhar Malavali | 50b8127 | 2018-12-21 09:33:45 -0800 | [diff] [blame] | 3192 | prm->prot_seg_cnt, cmd)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3193 | goto crc_queuing_error; |
| 3194 | } |
| 3195 | return QLA_SUCCESS; |
| 3196 | |
| 3197 | crc_queuing_error: |
| 3198 | /* Cleanup will be performed by the caller */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3199 | qpair->req->outstanding_cmds[h] = NULL; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3200 | |
| 3201 | return QLA_FUNCTION_FAILED; |
| 3202 | } |
| 3203 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3204 | /* |
| 3205 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * |
| 3206 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon |
| 3207 | */ |
| 3208 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, |
| 3209 | uint8_t scsi_status) |
| 3210 | { |
| 3211 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3212 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3213 | struct ctio7_to_24xx *pkt; |
| 3214 | struct qla_tgt_prm prm; |
| 3215 | uint32_t full_req_cnt = 0; |
| 3216 | unsigned long flags = 0; |
| 3217 | int res; |
| 3218 | |
Quinn Tran | 51fd6e6 | 2019-01-24 23:23:43 -0800 | [diff] [blame] | 3219 | if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || |
| 3220 | (cmd->sess && cmd->sess->deleted)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3221 | cmd->state = QLA_TGT_STATE_PROCESSED; |
Bart Van Assche | 0dcec41 | 2019-08-08 20:02:10 -0700 | [diff] [blame] | 3222 | res = 0; |
| 3223 | goto free; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3224 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3225 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3226 | ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3227 | "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] | 3228 | (xmit_type & QLA_TGT_XMIT_STATUS) ? |
| 3229 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3230 | &cmd->se_cmd, qpair->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3231 | |
| 3232 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, |
| 3233 | &full_req_cnt); |
Bart Van Assche | 0dcec41 | 2019-08-08 20:02:10 -0700 | [diff] [blame] | 3234 | if (unlikely(res != 0)) |
| 3235 | goto free; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3236 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3237 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3238 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3239 | if (xmit_type == QLA_TGT_XMIT_STATUS) |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3240 | qpair->tgt_counters.core_qla_snd_status++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3241 | else |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3242 | qpair->tgt_counters.core_qla_que_buf++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3243 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3244 | if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3245 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3246 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3247 | * previous life, just abort the processing. |
| 3248 | */ |
| 3249 | cmd->state = QLA_TGT_STATE_PROCESSED; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3250 | ql_dbg_qp(ql_dbg_async, qpair, 0xe101, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3251 | "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3252 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3253 | cmd->reset_count, qpair->chip_reset); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3254 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Bart Van Assche | 0dcec41 | 2019-08-08 20:02:10 -0700 | [diff] [blame] | 3255 | res = 0; |
| 3256 | goto free; |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3257 | } |
| 3258 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3259 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3260 | res = qlt_check_reserve_free_req(qpair, full_req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3261 | if (unlikely(res)) |
| 3262 | goto out_unmap_unlock; |
| 3263 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3264 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3265 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3266 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3267 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3268 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3269 | qpair->req->cnt += full_req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3270 | goto out_unmap_unlock; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3271 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3272 | |
| 3273 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
| 3274 | |
| 3275 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { |
| 3276 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3277 | cpu_to_le16(CTIO7_FLAGS_DATA_IN | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3278 | CTIO7_FLAGS_STATUS_MODE_0); |
| 3279 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3280 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3281 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3282 | |
| 3283 | if (prm.add_status_pkt == 0) { |
| 3284 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 3285 | pkt->u.status0.scsi_status = |
| 3286 | cpu_to_le16(prm.rq_result); |
| 3287 | pkt->u.status0.residual = |
| 3288 | cpu_to_le32(prm.residual); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3289 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3290 | CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3291 | if (qlt_need_explicit_conf(cmd, 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3292 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3293 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3294 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 3295 | CTIO7_FLAGS_CONFORM_REQ); |
| 3296 | } |
| 3297 | } |
| 3298 | |
| 3299 | } else { |
| 3300 | /* |
| 3301 | * We have already made sure that there is sufficient |
| 3302 | * amount of request entries to not drop HW lock in |
| 3303 | * req_pkt(). |
| 3304 | */ |
| 3305 | struct ctio7_to_24xx *ctio = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3306 | (struct ctio7_to_24xx *)qlt_get_req_pkt( |
| 3307 | qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3308 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3309 | ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e, |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3310 | "Building additional status packet 0x%p.\n", |
| 3311 | ctio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3312 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3313 | /* |
| 3314 | * T10Dif: ctio_crc2_to_fw overlay ontop of |
| 3315 | * ctio7_to_24xx |
| 3316 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3317 | memcpy(ctio, pkt, sizeof(*ctio)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3318 | /* reset back to CTIO7 */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3319 | ctio->entry_count = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3320 | ctio->entry_type = CTIO_TYPE7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3321 | ctio->dseg_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3322 | ctio->u.status1.flags &= ~cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3323 | CTIO7_FLAGS_DATA_IN); |
| 3324 | |
| 3325 | /* Real finish is ctio_m1's finish */ |
| 3326 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3327 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3328 | CTIO7_FLAGS_DONT_RET_CTIO); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3329 | |
| 3330 | /* qlt_24xx_init_ctio_to_isp will correct |
| 3331 | * all neccessary fields that's part of CTIO7. |
| 3332 | * There should be no residual of CTIO-CRC2 data. |
| 3333 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3334 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
| 3335 | &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3336 | } |
| 3337 | } else |
| 3338 | qlt_24xx_init_ctio_to_isp(pkt, &prm); |
| 3339 | |
| 3340 | |
| 3341 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3342 | cmd->cmd_sent_to_fw = 1; |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 3343 | cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3344 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3345 | /* Memory Barrier */ |
| 3346 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3347 | if (qpair->reqq_start_iocbs) |
| 3348 | qpair->reqq_start_iocbs(qpair); |
| 3349 | else |
| 3350 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3351 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3352 | |
| 3353 | return 0; |
| 3354 | |
| 3355 | out_unmap_unlock: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3356 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3357 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3358 | |
Bart Van Assche | 0dcec41 | 2019-08-08 20:02:10 -0700 | [diff] [blame] | 3359 | free: |
| 3360 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3361 | return res; |
| 3362 | } |
| 3363 | EXPORT_SYMBOL(qlt_xmit_response); |
| 3364 | |
| 3365 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) |
| 3366 | { |
| 3367 | struct ctio7_to_24xx *pkt; |
| 3368 | struct scsi_qla_host *vha = cmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3369 | struct qla_tgt *tgt = cmd->tgt; |
| 3370 | struct qla_tgt_prm prm; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3371 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3372 | int res = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3373 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3374 | |
| 3375 | memset(&prm, 0, sizeof(prm)); |
| 3376 | prm.cmd = cmd; |
| 3377 | prm.tgt = tgt; |
| 3378 | prm.sg = NULL; |
| 3379 | prm.req_cnt = 1; |
| 3380 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3381 | /* Calculate number of entries and segments required */ |
| 3382 | if (qlt_pci_map_calc_cnt(&prm) != 0) |
| 3383 | return -EAGAIN; |
| 3384 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3385 | if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3386 | (cmd->sess && cmd->sess->deleted)) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3387 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3388 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3389 | * previous life, just abort the processing. |
| 3390 | */ |
Bart Van Assche | aefed3e | 2019-04-17 14:44:29 -0700 | [diff] [blame] | 3391 | cmd->aborted = 1; |
| 3392 | cmd->write_data_transferred = 0; |
| 3393 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3394 | vha->hw->tgt.tgt_ops->handle_data(cmd); |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3395 | ql_dbg_qp(ql_dbg_async, qpair, 0xe102, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3396 | "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3397 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3398 | cmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3399 | return 0; |
| 3400 | } |
| 3401 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3402 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3403 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3404 | res = qlt_check_reserve_free_req(qpair, prm.req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3405 | if (res != 0) |
| 3406 | goto out_unlock_free_unmap; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3407 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3408 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3409 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3410 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3411 | |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3412 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3413 | qpair->req->cnt += prm.req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3414 | goto out_unlock_free_unmap; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3415 | } |
| 3416 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3417 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3418 | pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3419 | CTIO7_FLAGS_STATUS_MODE_0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3420 | |
| 3421 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3422 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3423 | |
| 3424 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3425 | cmd->cmd_sent_to_fw = 1; |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 3426 | cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3427 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3428 | /* Memory Barrier */ |
| 3429 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3430 | if (qpair->reqq_start_iocbs) |
| 3431 | qpair->reqq_start_iocbs(qpair); |
| 3432 | else |
| 3433 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3434 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3435 | |
| 3436 | return res; |
| 3437 | |
| 3438 | out_unlock_free_unmap: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3439 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3440 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3441 | |
| 3442 | return res; |
| 3443 | } |
| 3444 | EXPORT_SYMBOL(qlt_rdy_to_xfer); |
| 3445 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3446 | |
| 3447 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3448 | * it is assumed either hardware_lock or qpair lock is held. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3449 | */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3450 | static void |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3451 | 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] | 3452 | struct ctio_crc_from_fw *sts) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3453 | { |
| 3454 | uint8_t *ap = &sts->actual_dif[0]; |
| 3455 | uint8_t *ep = &sts->expected_dif[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3456 | uint64_t lba = cmd->se_cmd.t_task_lba; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3457 | uint8_t scsi_status, sense_key, asc, ascq; |
| 3458 | unsigned long flags; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3459 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3460 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3461 | cmd->trc_flags |= TRC_DIF_ERR; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3462 | |
Bart Van Assche | a9c4ae1 | 2019-12-18 16:50:50 -0800 | [diff] [blame] | 3463 | cmd->a_guard = get_unaligned_be16(ap + 0); |
| 3464 | cmd->a_app_tag = get_unaligned_be16(ap + 2); |
| 3465 | cmd->a_ref_tag = get_unaligned_be32(ap + 4); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3466 | |
Bart Van Assche | a9c4ae1 | 2019-12-18 16:50:50 -0800 | [diff] [blame] | 3467 | cmd->e_guard = get_unaligned_be16(ep + 0); |
| 3468 | cmd->e_app_tag = get_unaligned_be16(ep + 2); |
| 3469 | cmd->e_ref_tag = get_unaligned_be32(ep + 4); |
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 | ql_dbg(ql_dbg_tgt_dif, vha, 0xf075, |
| 3472 | "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3473 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3474 | scsi_status = sense_key = asc = ascq = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3475 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3476 | /* check appl tag */ |
| 3477 | if (cmd->e_app_tag != cmd->a_app_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3478 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d, |
| 3479 | "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]", |
| 3480 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3481 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3482 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3483 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3484 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3485 | cmd->dif_err_code = DIF_ERR_APP; |
| 3486 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3487 | sense_key = ABORTED_COMMAND; |
| 3488 | asc = 0x10; |
| 3489 | ascq = 0x2; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | /* check ref tag */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3493 | if (cmd->e_ref_tag != cmd->a_ref_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3494 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e, |
| 3495 | "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] ", |
| 3496 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3497 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3498 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3499 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3500 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3501 | cmd->dif_err_code = DIF_ERR_REF; |
| 3502 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3503 | sense_key = ABORTED_COMMAND; |
| 3504 | asc = 0x10; |
| 3505 | ascq = 0x3; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3506 | goto out; |
| 3507 | } |
| 3508 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3509 | /* check guard */ |
| 3510 | if (cmd->e_guard != cmd->a_guard) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3511 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe012, |
| 3512 | "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]", |
| 3513 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3514 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3515 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3516 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
| 3517 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3518 | cmd->dif_err_code = DIF_ERR_GRD; |
| 3519 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3520 | sense_key = ABORTED_COMMAND; |
| 3521 | asc = 0x10; |
| 3522 | ascq = 0x1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3523 | } |
| 3524 | out: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3525 | switch (cmd->state) { |
| 3526 | case QLA_TGT_STATE_NEED_DATA: |
| 3527 | /* handle_data will load DIF error code */ |
| 3528 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3529 | vha->hw->tgt.tgt_ops->handle_data(cmd); |
| 3530 | break; |
| 3531 | default: |
| 3532 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3533 | if (cmd->aborted) { |
| 3534 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3535 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3536 | break; |
| 3537 | } |
| 3538 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3539 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3540 | qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc, |
| 3541 | ascq); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3542 | /* assume scsi status gets out on the wire. |
| 3543 | * Will not wait for completion. |
| 3544 | */ |
| 3545 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3546 | break; |
| 3547 | } |
| 3548 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3549 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3550 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3551 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3552 | static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3553 | struct imm_ntfy_from_isp *ntfy) |
| 3554 | { |
| 3555 | struct nack_to_isp *nack; |
| 3556 | struct qla_hw_data *ha = vha->hw; |
| 3557 | request_t *pkt; |
| 3558 | int ret = 0; |
| 3559 | |
| 3560 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c, |
| 3561 | "Sending TERM ELS CTIO (ha=%p)\n", ha); |
| 3562 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 3563 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3564 | if (pkt == NULL) { |
| 3565 | ql_dbg(ql_dbg_tgt, vha, 0xe080, |
| 3566 | "qla_target(%d): %s failed: unable to allocate " |
| 3567 | "request packet\n", vha->vp_idx, __func__); |
| 3568 | return -ENOMEM; |
| 3569 | } |
| 3570 | |
| 3571 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 3572 | pkt->entry_count = 1; |
Quinn Tran | 4f06073 | 2016-12-23 18:06:13 -0800 | [diff] [blame] | 3573 | pkt->handle = QLA_TGT_SKIP_HANDLE; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3574 | |
| 3575 | nack = (struct nack_to_isp *)pkt; |
| 3576 | nack->ox_id = ntfy->ox_id; |
| 3577 | |
| 3578 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3579 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3580 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 3581 | cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | /* terminate */ |
| 3585 | nack->u.isp24.flags |= |
| 3586 | __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE); |
| 3587 | |
| 3588 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3589 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3590 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3591 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3592 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3593 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3594 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3595 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3596 | |
| 3597 | qla2x00_start_iocbs(vha, vha->req); |
| 3598 | return ret; |
| 3599 | } |
| 3600 | |
| 3601 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3602 | struct imm_ntfy_from_isp *imm, int ha_locked) |
| 3603 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3604 | int rc; |
| 3605 | |
Bart Van Assche | e65449a | 2019-04-17 14:44:26 -0700 | [diff] [blame] | 3606 | WARN_ON_ONCE(!ha_locked); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3607 | rc = __qlt_send_term_imm_notif(vha, imm); |
Bart Van Assche | e65449a | 2019-04-17 14:44:26 -0700 | [diff] [blame] | 3608 | pr_debug("rc = %d\n", rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3609 | } |
| 3610 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3611 | /* |
| 3612 | * If hardware_lock held on entry, might drop it, then reaquire |
| 3613 | * This function sends the appropriate CTIO to ISP 2xxx or 24xx |
| 3614 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3615 | static int __qlt_send_term_exchange(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3616 | struct qla_tgt_cmd *cmd, |
| 3617 | struct atio_from_isp *atio) |
| 3618 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3619 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3620 | struct ctio7_to_24xx *ctio24; |
| 3621 | struct qla_hw_data *ha = vha->hw; |
| 3622 | request_t *pkt; |
| 3623 | int ret = 0; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3624 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3625 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3626 | 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] | 3627 | |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 3628 | if (cmd) |
| 3629 | vha = cmd->vha; |
| 3630 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3631 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3632 | if (pkt == NULL) { |
| 3633 | ql_dbg(ql_dbg_tgt, vha, 0xe050, |
| 3634 | "qla_target(%d): %s failed: unable to allocate " |
| 3635 | "request packet\n", vha->vp_idx, __func__); |
| 3636 | return -ENOMEM; |
| 3637 | } |
| 3638 | |
| 3639 | if (cmd != NULL) { |
| 3640 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { |
| 3641 | ql_dbg(ql_dbg_tgt, vha, 0xe051, |
| 3642 | "qla_target(%d): Terminating cmd %p with " |
| 3643 | "incorrect state %d\n", vha->vp_idx, cmd, |
| 3644 | cmd->state); |
| 3645 | } else |
| 3646 | ret = 1; |
| 3647 | } |
| 3648 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3649 | qpair->tgt_counters.num_term_xchg_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3650 | pkt->entry_count = 1; |
| 3651 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 3652 | |
| 3653 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 3654 | ctio24->entry_type = CTIO_TYPE7; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 3655 | ctio24->nport_handle = cpu_to_le16(CTIO7_NHANDLE_UNRECOGNIZED); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3656 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3657 | ctio24->vp_index = vha->vp_idx; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 3658 | 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] | 3659 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3660 | temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 | |
| 3661 | CTIO7_FLAGS_TERMINATE; |
| 3662 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3663 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3664 | ctio24->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3665 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3666 | /* Memory Barrier */ |
| 3667 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3668 | if (qpair->reqq_start_iocbs) |
| 3669 | qpair->reqq_start_iocbs(qpair); |
| 3670 | else |
| 3671 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3672 | return ret; |
| 3673 | } |
| 3674 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3675 | static void qlt_send_term_exchange(struct qla_qpair *qpair, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3676 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, |
| 3677 | int ul_abort) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3678 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3679 | struct scsi_qla_host *vha; |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3680 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3681 | int rc; |
| 3682 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3683 | /* why use different vha? NPIV */ |
| 3684 | if (cmd) |
| 3685 | vha = cmd->vha; |
| 3686 | else |
| 3687 | vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3688 | |
| 3689 | if (ha_locked) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3690 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3691 | if (rc == -ENOMEM) |
| 3692 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3693 | goto done; |
| 3694 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3695 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 3696 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3697 | if (rc == -ENOMEM) |
| 3698 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3699 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3700 | done: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3701 | if (cmd && !ul_abort && !cmd->aborted) { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3702 | if (cmd->sg_mapped) |
| 3703 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3704 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3705 | } |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3706 | |
| 3707 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3708 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3709 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3710 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3711 | } |
| 3712 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3713 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
| 3714 | { |
| 3715 | struct list_head free_list; |
| 3716 | struct qla_tgt_cmd *cmd, *tcmd; |
| 3717 | |
| 3718 | vha->hw->tgt.leak_exchg_thresh_hold = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3719 | (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3720 | |
| 3721 | cmd = tcmd = NULL; |
| 3722 | if (!list_empty(&vha->hw->tgt.q_full_list)) { |
| 3723 | INIT_LIST_HEAD(&free_list); |
| 3724 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); |
| 3725 | |
| 3726 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 3727 | list_del(&cmd->cmd_list); |
| 3728 | /* This cmd was never sent to TCM. There is no need |
| 3729 | * to schedule free or call free_cmd |
| 3730 | */ |
| 3731 | qlt_free_cmd(cmd); |
| 3732 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 3733 | } |
| 3734 | } |
| 3735 | vha->hw->tgt.num_qfull_cmds_dropped = 0; |
| 3736 | } |
| 3737 | |
| 3738 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) |
| 3739 | { |
| 3740 | uint32_t total_leaked; |
| 3741 | |
| 3742 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; |
| 3743 | |
| 3744 | if (vha->hw->tgt.leak_exchg_thresh_hold && |
| 3745 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { |
| 3746 | |
| 3747 | ql_dbg(ql_dbg_tgt, vha, 0xe079, |
| 3748 | "Chip reset due to exchange starvation: %d/%d.\n", |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3749 | total_leaked, vha->hw->cur_fw_xcb_count); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3750 | |
| 3751 | if (IS_P3P_TYPE(vha->hw)) |
| 3752 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 3753 | else |
| 3754 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3755 | qla2xxx_wake_dpc(vha); |
| 3756 | } |
| 3757 | |
| 3758 | } |
| 3759 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3760 | int qlt_abort_cmd(struct qla_tgt_cmd *cmd) |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3761 | { |
| 3762 | struct qla_tgt *tgt = cmd->tgt; |
| 3763 | struct scsi_qla_host *vha = tgt->vha; |
| 3764 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3765 | unsigned long flags; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3766 | |
| 3767 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, |
| 3768 | "qla_target(%d): terminating exchange for aborted cmd=%p " |
| 3769 | "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, |
| 3770 | se_cmd->tag); |
| 3771 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3772 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3773 | if (cmd->aborted) { |
| 3774 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3775 | /* |
| 3776 | * It's normal to see 2 calls in this path: |
| 3777 | * 1) XFER Rdy completion + CMD_T_ABORT |
| 3778 | * 2) TCM TMR - drain_state_list |
| 3779 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3780 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016, |
| 3781 | "multiple abort. %p transport_state %x, t_state %x, " |
| 3782 | "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state, |
| 3783 | cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3784 | return EIO; |
| 3785 | } |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3786 | cmd->aborted = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3787 | cmd->trc_flags |= TRC_ABORT; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3788 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3789 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3790 | qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3791 | return 0; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3792 | } |
| 3793 | EXPORT_SYMBOL(qlt_abort_cmd); |
| 3794 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3795 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
| 3796 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3797 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3798 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3799 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
| 3800 | "%s: se_cmd[%p] ox_id %04x\n", |
| 3801 | __func__, &cmd->se_cmd, |
| 3802 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3803 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3804 | BUG_ON(cmd->cmd_in_wq); |
| 3805 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3806 | if (cmd->sg_mapped) |
| 3807 | qlt_unmap_sg(cmd->vha, cmd); |
| 3808 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3809 | if (!cmd->q_full) |
| 3810 | qlt_decr_num_pend_cmds(cmd->vha); |
| 3811 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3812 | BUG_ON(cmd->sg_mapped); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3813 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3814 | if (unlikely(cmd->free_sg)) |
| 3815 | kfree(cmd->sg); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3816 | |
| 3817 | if (!sess || !sess->se_sess) { |
| 3818 | WARN_ON(1); |
| 3819 | return; |
| 3820 | } |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3821 | cmd->jiffies_at_free = get_jiffies_64(); |
Bart Van Assche | 80363e1 | 2020-01-03 11:27:19 -0800 | [diff] [blame] | 3822 | cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3823 | } |
| 3824 | EXPORT_SYMBOL(qlt_free_cmd); |
| 3825 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3826 | /* |
| 3827 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3828 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3829 | static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3830 | struct qla_tgt_cmd *cmd, uint32_t status) |
| 3831 | { |
| 3832 | int term = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3833 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3834 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3835 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3836 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe013, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3837 | "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] " |
| 3838 | "se_cmd=%p tag[%x] op %#x/%s", |
| 3839 | cmd->lba, cmd->lba, |
| 3840 | cmd->num_blks, &cmd->se_cmd, |
| 3841 | cmd->atio.u.isp24.exchange_addr, |
| 3842 | cmd->se_cmd.prot_op, |
| 3843 | prot_op_str(cmd->se_cmd.prot_op)); |
| 3844 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3845 | if (ctio != NULL) { |
| 3846 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 3847 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3848 | term = !(c->flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3849 | cpu_to_le16(OF_TERM_EXCH)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3850 | } else |
| 3851 | term = 1; |
| 3852 | |
| 3853 | if (term) |
himanshu.madhani@cavium.com | 3efc31f | 2018-01-15 20:46:47 -0800 | [diff] [blame] | 3854 | qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3855 | |
| 3856 | return term; |
| 3857 | } |
| 3858 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3859 | |
| 3860 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 3861 | static void *qlt_ctio_to_cmd(struct scsi_qla_host *vha, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3862 | struct rsp_que *rsp, uint32_t handle, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3863 | { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 3864 | void *cmd = NULL; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3865 | struct req_que *req; |
| 3866 | int qid = GET_QID(handle); |
| 3867 | uint32_t h = handle & ~QLA_TGT_HANDLE_MASK; |
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 (unlikely(h == QLA_TGT_SKIP_HANDLE)) |
| 3870 | return NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3871 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3872 | if (qid == rsp->req->id) { |
| 3873 | req = rsp->req; |
| 3874 | } else if (vha->hw->req_q_map[qid]) { |
| 3875 | ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a, |
| 3876 | "qla_target(%d): CTIO completion with different QID %d handle %x\n", |
| 3877 | vha->vp_idx, rsp->id, handle); |
| 3878 | req = vha->hw->req_q_map[qid]; |
| 3879 | } else { |
| 3880 | return NULL; |
| 3881 | } |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3882 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3883 | h &= QLA_CMD_HANDLE_MASK; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3884 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3885 | if (h != QLA_TGT_NULL_HANDLE) { |
Dan Carpenter | fb2028a | 2017-07-10 11:47:40 +0300 | [diff] [blame] | 3886 | if (unlikely(h >= req->num_outstanding_cmds)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3887 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
| 3888 | "qla_target(%d): Wrong handle %x received\n", |
| 3889 | vha->vp_idx, handle); |
| 3890 | return NULL; |
| 3891 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3892 | |
Bart Van Assche | ab053c0 | 2020-05-18 14:17:09 -0700 | [diff] [blame] | 3893 | cmd = req->outstanding_cmds[h]; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3894 | if (unlikely(cmd == NULL)) { |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3895 | ql_dbg(ql_dbg_async, vha, 0xe053, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3896 | "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n", |
| 3897 | vha->vp_idx, handle, req->id, rsp->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3898 | return NULL; |
| 3899 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3900 | req->outstanding_cmds[h] = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3901 | } else if (ctio != NULL) { |
| 3902 | /* We can't get loop ID from CTIO7 */ |
| 3903 | ql_dbg(ql_dbg_tgt, vha, 0xe054, |
| 3904 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " |
| 3905 | "support NULL handles\n", vha->vp_idx); |
| 3906 | return NULL; |
| 3907 | } |
| 3908 | |
| 3909 | return cmd; |
| 3910 | } |
| 3911 | |
| 3912 | /* |
| 3913 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3914 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3915 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, |
| 3916 | struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3917 | { |
| 3918 | struct qla_hw_data *ha = vha->hw; |
| 3919 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3920 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3921 | struct qla_qpair *qpair = rsp->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3922 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3923 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
| 3924 | /* That could happen only in case of an error/reset/abort */ |
| 3925 | if (status != CTIO_SUCCESS) { |
| 3926 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, |
| 3927 | "Intermediate CTIO received" |
| 3928 | " (status %x)\n", status); |
| 3929 | } |
| 3930 | return; |
| 3931 | } |
| 3932 | |
Bart Van Assche | 81bcf1c | 2019-04-11 14:53:24 -0700 | [diff] [blame] | 3933 | cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio); |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3934 | if (cmd == NULL) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3935 | return; |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3936 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3937 | se_cmd = &cmd->se_cmd; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3938 | cmd->cmd_sent_to_fw = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3939 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3940 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3941 | |
| 3942 | if (unlikely(status != CTIO_SUCCESS)) { |
| 3943 | switch (status & 0xFFFF) { |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 3944 | case CTIO_INVALID_RX_ID: |
| 3945 | if (printk_ratelimit()) |
| 3946 | dev_info(&vha->hw->pdev->dev, |
| 3947 | "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n", |
| 3948 | vha->vp_idx, cmd->atio.u.isp24.attr, |
| 3949 | ((cmd->ctio_flags >> 9) & 0xf), |
| 3950 | cmd->ctio_flags); |
| 3951 | |
| 3952 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3953 | case CTIO_LIP_RESET: |
| 3954 | case CTIO_TARGET_RESET: |
| 3955 | case CTIO_ABORTED: |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3956 | /* driver request abort via Terminate exchange */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3957 | case CTIO_TIMEOUT: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3958 | /* They are OK */ |
| 3959 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, |
| 3960 | "qla_target(%d): CTIO with " |
| 3961 | "status %#x received, state %x, se_cmd %p, " |
| 3962 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " |
| 3963 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, |
| 3964 | status, cmd->state, se_cmd); |
| 3965 | break; |
| 3966 | |
| 3967 | case CTIO_PORT_LOGGED_OUT: |
| 3968 | case CTIO_PORT_UNAVAILABLE: |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3969 | { |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3970 | int logged_out = |
| 3971 | (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; |
| 3972 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3973 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3974 | "qla_target(%d): CTIO with %s status %x " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3975 | "received (state %x, se_cmd %p)\n", vha->vp_idx, |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3976 | logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3977 | status, cmd->state, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3978 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3979 | if (logged_out && cmd->sess) { |
| 3980 | /* |
| 3981 | * Session is already logged out, but we need |
| 3982 | * to notify initiator, who's not aware of this |
| 3983 | */ |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3984 | cmd->sess->send_els_logo = 1; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3985 | ql_dbg(ql_dbg_disc, vha, 0x20f8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3986 | "%s %d %8phC post del sess\n", |
| 3987 | __func__, __LINE__, cmd->sess->port_name); |
| 3988 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 3989 | qlt_schedule_sess_for_deletion(cmd->sess); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3990 | } |
| 3991 | break; |
| 3992 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3993 | case CTIO_DIF_ERROR: { |
| 3994 | struct ctio_crc_from_fw *crc = |
| 3995 | (struct ctio_crc_from_fw *)ctio; |
| 3996 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3997 | "qla_target(%d): CTIO with DIF_ERROR status %x " |
| 3998 | "received (state %x, ulp_cmd %p) actual_dif[0x%llx] " |
| 3999 | "expect_dif[0x%llx]\n", |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4000 | vha->vp_idx, status, cmd->state, se_cmd, |
| 4001 | *((u64 *)&crc->actual_dif[0]), |
| 4002 | *((u64 *)&crc->expected_dif[0])); |
| 4003 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 4004 | qlt_handle_dif_error(qpair, cmd, ctio); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 4005 | return; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4006 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4007 | default: |
| 4008 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4009 | "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] | 4010 | vha->vp_idx, status, cmd->state, se_cmd); |
| 4011 | break; |
| 4012 | } |
| 4013 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4014 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4015 | /* "cmd->aborted" means |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4016 | * cmd is already aborted/terminated, we don't |
| 4017 | * need to terminate again. The exchange is already |
| 4018 | * cleaned up/freed at FW level. Just cleanup at driver |
| 4019 | * level. |
| 4020 | */ |
| 4021 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4022 | (!cmd->aborted)) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4023 | cmd->trc_flags |= TRC_CTIO_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4024 | if (qlt_term_ctio_exchange(qpair, ctio, cmd, status)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4025 | return; |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4026 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4030 | cmd->trc_flags |= TRC_CTIO_DONE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4031 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4032 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 4033 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4034 | if (status == CTIO_SUCCESS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4035 | cmd->write_data_transferred = 1; |
| 4036 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4037 | ha->tgt.tgt_ops->handle_data(cmd); |
| 4038 | return; |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4039 | } else if (cmd->aborted) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4040 | cmd->trc_flags |= TRC_CTIO_ABORTED; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4041 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4042 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4043 | } else { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4044 | cmd->trc_flags |= TRC_CTIO_STRANGE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4045 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
| 4046 | "qla_target(%d): A command in state (%d) should " |
| 4047 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); |
| 4048 | } |
| 4049 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4050 | if (unlikely(status != CTIO_SUCCESS) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4051 | !cmd->aborted) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4052 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
| 4053 | dump_stack(); |
| 4054 | } |
| 4055 | |
| 4056 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 4057 | } |
| 4058 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4059 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
| 4060 | uint8_t task_codes) |
| 4061 | { |
| 4062 | int fcp_task_attr; |
| 4063 | |
| 4064 | switch (task_codes) { |
| 4065 | case ATIO_SIMPLE_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4066 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4067 | break; |
| 4068 | case ATIO_HEAD_OF_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4069 | fcp_task_attr = TCM_HEAD_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4070 | break; |
| 4071 | case ATIO_ORDERED_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4072 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4073 | break; |
| 4074 | case ATIO_ACA_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4075 | fcp_task_attr = TCM_ACA_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4076 | break; |
| 4077 | case ATIO_UNTAGGED: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4078 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4079 | break; |
| 4080 | default: |
| 4081 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, |
| 4082 | "qla_target: unknown task code %x, use ORDERED instead\n", |
| 4083 | task_codes); |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4084 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4085 | break; |
| 4086 | } |
| 4087 | |
| 4088 | return fcp_task_attr; |
| 4089 | } |
| 4090 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4091 | /* |
| 4092 | * Process context for I/O path into tcm_qla2xxx code |
| 4093 | */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4094 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4095 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4096 | scsi_qla_host_t *vha = cmd->vha; |
| 4097 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4098 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4099 | struct atio_from_isp *atio = &cmd->atio; |
| 4100 | unsigned char *cdb; |
| 4101 | unsigned long flags; |
| 4102 | uint32_t data_length; |
| 4103 | int ret, fcp_task_attr, data_dir, bidi = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4104 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4105 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4106 | cmd->cmd_in_wq = 0; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4107 | cmd->trc_flags |= TRC_DO_WORK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4108 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4109 | if (cmd->aborted) { |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4110 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082, |
| 4111 | "cmd with tag %u is aborted\n", |
| 4112 | cmd->atio.u.isp24.exchange_addr); |
| 4113 | goto out_term; |
| 4114 | } |
| 4115 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4116 | spin_lock_init(&cmd->cmd_lock); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4117 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 4118 | cmd->se_cmd.tag = le32_to_cpu(atio->u.isp24.exchange_addr); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4119 | |
| 4120 | if (atio->u.isp24.fcp_cmnd.rddata && |
| 4121 | atio->u.isp24.fcp_cmnd.wrdata) { |
| 4122 | bidi = 1; |
| 4123 | data_dir = DMA_TO_DEVICE; |
| 4124 | } else if (atio->u.isp24.fcp_cmnd.rddata) |
| 4125 | data_dir = DMA_FROM_DEVICE; |
| 4126 | else if (atio->u.isp24.fcp_cmnd.wrdata) |
| 4127 | data_dir = DMA_TO_DEVICE; |
| 4128 | else |
| 4129 | data_dir = DMA_NONE; |
| 4130 | |
| 4131 | fcp_task_attr = qlt_get_fcp_task_attr(vha, |
| 4132 | atio->u.isp24.fcp_cmnd.task_attr); |
Quinn Tran | e25f765 | 2018-05-01 09:01:50 -0700 | [diff] [blame] | 4133 | data_length = get_datalen_for_atio(atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4134 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4135 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
| 4136 | fcp_task_attr, data_dir, bidi); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4137 | if (ret != 0) |
| 4138 | goto out_term; |
| 4139 | /* |
Bart Van Assche | 67eb4a60 | 2019-04-17 14:44:10 -0700 | [diff] [blame] | 4140 | * Drop extra session reference from qlt_handle_cmd_for_atio(). |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4141 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4142 | ha->tgt.tgt_ops->put_sess(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4143 | return; |
| 4144 | |
| 4145 | out_term: |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4146 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4147 | /* |
Roland Dreier | fae9eaf | 2012-06-11 18:23:16 -0700 | [diff] [blame] | 4148 | * cmd has not sent to target yet, so pass NULL as the second |
| 4149 | * argument to qlt_send_term_exchange() and free the memory here. |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4150 | */ |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4151 | cmd->trc_flags |= TRC_DO_WORK_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4152 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 4153 | qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4154 | |
| 4155 | qlt_decr_num_pend_cmds(vha); |
Bart Van Assche | 80363e1 | 2020-01-03 11:27:19 -0800 | [diff] [blame] | 4156 | cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4157 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4158 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4159 | ha->tgt.tgt_ops->put_sess(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4160 | } |
| 4161 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4162 | static void qlt_do_work(struct work_struct *work) |
| 4163 | { |
| 4164 | 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] | 4165 | scsi_qla_host_t *vha = cmd->vha; |
| 4166 | unsigned long flags; |
| 4167 | |
| 4168 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4169 | list_del(&cmd->cmd_list); |
| 4170 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4171 | |
| 4172 | __qlt_do_work(cmd); |
| 4173 | } |
| 4174 | |
Quinn Tran | 09620ee | 2017-06-13 20:47:20 -0700 | [diff] [blame] | 4175 | void qlt_clr_qp_table(struct scsi_qla_host *vha) |
| 4176 | { |
| 4177 | unsigned long flags; |
| 4178 | struct qla_hw_data *ha = vha->hw; |
| 4179 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4180 | void *node; |
| 4181 | u64 key = 0; |
| 4182 | |
| 4183 | ql_log(ql_log_info, vha, 0x706c, |
| 4184 | "User update Number of Active Qpairs %d\n", |
| 4185 | ha->tgt.num_act_qpairs); |
| 4186 | |
| 4187 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 4188 | |
| 4189 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 4190 | btree_remove64(&tgt->lun_qpair_map, key); |
| 4191 | |
| 4192 | ha->base_qpair->lun_cnt = 0; |
| 4193 | for (key = 0; key < ha->max_qpairs; key++) |
| 4194 | if (ha->queue_pair_map[key]) |
| 4195 | ha->queue_pair_map[key]->lun_cnt = 0; |
| 4196 | |
| 4197 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 4198 | } |
| 4199 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4200 | static void qlt_assign_qpair(struct scsi_qla_host *vha, |
| 4201 | struct qla_tgt_cmd *cmd) |
| 4202 | { |
| 4203 | struct qla_qpair *qpair, *qp; |
| 4204 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4205 | struct qla_qpair_hint *h; |
| 4206 | |
| 4207 | if (vha->flags.qpairs_available) { |
| 4208 | h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun); |
| 4209 | if (unlikely(!h)) { |
| 4210 | /* spread lun to qpair ratio evently */ |
| 4211 | int lcnt = 0, rc; |
| 4212 | struct scsi_qla_host *base_vha = |
| 4213 | pci_get_drvdata(vha->hw->pdev); |
| 4214 | |
| 4215 | qpair = vha->hw->base_qpair; |
| 4216 | if (qpair->lun_cnt == 0) { |
| 4217 | qpair->lun_cnt++; |
| 4218 | h = qla_qpair_to_hint(tgt, qpair); |
| 4219 | BUG_ON(!h); |
| 4220 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4221 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4222 | if (rc) { |
| 4223 | qpair->lun_cnt--; |
| 4224 | ql_log(ql_log_info, vha, 0xd037, |
| 4225 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4226 | cmd->unpacked_lun); |
| 4227 | } |
| 4228 | goto out; |
| 4229 | } else { |
| 4230 | lcnt = qpair->lun_cnt; |
| 4231 | } |
| 4232 | |
| 4233 | h = NULL; |
| 4234 | list_for_each_entry(qp, &base_vha->qp_list, |
| 4235 | qp_list_elem) { |
| 4236 | if (qp->lun_cnt == 0) { |
| 4237 | qp->lun_cnt++; |
| 4238 | h = qla_qpair_to_hint(tgt, qp); |
| 4239 | BUG_ON(!h); |
| 4240 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4241 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4242 | if (rc) { |
| 4243 | qp->lun_cnt--; |
| 4244 | ql_log(ql_log_info, vha, 0xd038, |
| 4245 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4246 | cmd->unpacked_lun); |
| 4247 | } |
| 4248 | qpair = qp; |
| 4249 | goto out; |
| 4250 | } else { |
| 4251 | if (qp->lun_cnt < lcnt) { |
| 4252 | lcnt = qp->lun_cnt; |
| 4253 | qpair = qp; |
| 4254 | continue; |
| 4255 | } |
| 4256 | } |
| 4257 | } |
| 4258 | BUG_ON(!qpair); |
| 4259 | qpair->lun_cnt++; |
| 4260 | h = qla_qpair_to_hint(tgt, qpair); |
| 4261 | BUG_ON(!h); |
| 4262 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4263 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4264 | if (rc) { |
| 4265 | qpair->lun_cnt--; |
| 4266 | ql_log(ql_log_info, vha, 0xd039, |
| 4267 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4268 | cmd->unpacked_lun); |
| 4269 | } |
| 4270 | } |
| 4271 | } else { |
| 4272 | h = &tgt->qphints[0]; |
| 4273 | } |
| 4274 | out: |
| 4275 | cmd->qpair = h->qpair; |
| 4276 | cmd->se_cmd.cpuid = h->cpuid; |
| 4277 | } |
| 4278 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4279 | 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] | 4280 | struct fc_port *sess, |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4281 | struct atio_from_isp *atio) |
| 4282 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4283 | struct qla_tgt_cmd *cmd; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4284 | |
Bart Van Assche | 80363e1 | 2020-01-03 11:27:19 -0800 | [diff] [blame] | 4285 | cmd = vha->hw->tgt.tgt_ops->get_cmd(sess); |
| 4286 | if (!cmd) |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4287 | return NULL; |
| 4288 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 4289 | cmd->cmd_type = TYPE_TGT_CMD; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4290 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 4291 | cmd->state = QLA_TGT_STATE_NEW; |
| 4292 | cmd->tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4293 | qlt_incr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4294 | cmd->vha = vha; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4295 | cmd->sess = sess; |
| 4296 | cmd->loop_id = sess->loop_id; |
| 4297 | cmd->conf_compl_supported = sess->conf_compl_supported; |
| 4298 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4299 | cmd->trc_flags = 0; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4300 | cmd->jiffies_at_alloc = get_jiffies_64(); |
| 4301 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4302 | cmd->unpacked_lun = scsilun_to_int( |
| 4303 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); |
| 4304 | qlt_assign_qpair(vha, cmd); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4305 | cmd->reset_count = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 4306 | cmd->vp_idx = vha->vp_idx; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4307 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4308 | return cmd; |
| 4309 | } |
| 4310 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4311 | /* ha->hardware_lock supposed to be held on entry */ |
| 4312 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, |
| 4313 | struct atio_from_isp *atio) |
| 4314 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4315 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4316 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4317 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4318 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4319 | unsigned long flags; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4320 | port_id_t id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4321 | |
| 4322 | if (unlikely(tgt->tgt_stop)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4323 | ql_dbg(ql_dbg_io, vha, 0x3061, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4324 | "New command while device %p is shutting down\n", tgt); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 4325 | return -ENODEV; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4326 | } |
| 4327 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 4328 | id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4329 | if (IS_SW_RESV_ADDR(id)) |
| 4330 | return -EBUSY; |
| 4331 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4332 | 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] | 4333 | if (unlikely(!sess)) |
| 4334 | return -EFAULT; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4335 | |
| 4336 | /* Another WWN used to have our s_id. Our PLOGI scheduled its |
| 4337 | * session deletion, but it's still in sess_del_work wq */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4338 | if (sess->deleted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4339 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002, |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4340 | "New command while old session %p is being deleted\n", |
| 4341 | sess); |
| 4342 | return -EFAULT; |
| 4343 | } |
| 4344 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4345 | /* |
| 4346 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. |
| 4347 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4348 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4349 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4350 | "%s: kref_get fail, %8phC oxid %x \n", |
| 4351 | __func__, sess->port_name, |
| 4352 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 4353 | return -EFAULT; |
| 4354 | } |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4355 | |
| 4356 | cmd = qlt_get_tag(vha, sess, atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4357 | if (!cmd) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4358 | ql_dbg(ql_dbg_io, vha, 0x3062, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4359 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4360 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 4361 | return -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4362 | } |
| 4363 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4364 | cmd->cmd_in_wq = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4365 | cmd->trc_flags |= TRC_NEW_CMD; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4366 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4367 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4368 | list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4369 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4370 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4371 | INIT_WORK(&cmd->work, qlt_do_work); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4372 | if (vha->flags.qpairs_available) { |
| 4373 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work); |
| 4374 | } else if (ha->msix_count) { |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4375 | if (cmd->atio.u.isp24.fcp_cmnd.rddata) |
| 4376 | queue_work_on(smp_processor_id(), qla_tgt_wq, |
| 4377 | &cmd->work); |
| 4378 | else |
| 4379 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, |
| 4380 | &cmd->work); |
| 4381 | } else { |
| 4382 | queue_work(qla_tgt_wq, &cmd->work); |
| 4383 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4384 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4385 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4386 | } |
| 4387 | |
| 4388 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4389 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4390 | int fn, void *iocb, int flags) |
| 4391 | { |
| 4392 | struct scsi_qla_host *vha = sess->vha; |
| 4393 | struct qla_hw_data *ha = vha->hw; |
| 4394 | struct qla_tgt_mgmt_cmd *mcmd; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4395 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4396 | struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4397 | |
| 4398 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4399 | if (!mcmd) { |
| 4400 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, |
| 4401 | "qla_target(%d): Allocation of management " |
| 4402 | "command failed, some commands and their data could " |
| 4403 | "leak\n", vha->vp_idx); |
| 4404 | return -ENOMEM; |
| 4405 | } |
| 4406 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4407 | mcmd->sess = sess; |
| 4408 | |
| 4409 | if (iocb) { |
| 4410 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4411 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4412 | } |
| 4413 | mcmd->tmr_func = fn; |
| 4414 | mcmd->flags = flags; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4415 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4416 | mcmd->qpair = h->qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 4417 | mcmd->vha = vha; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4418 | mcmd->se_cmd.cpuid = h->cpuid; |
| 4419 | mcmd->unpacked_lun = lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4420 | |
| 4421 | switch (fn) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4422 | case QLA_TGT_LUN_RESET: |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4423 | case QLA_TGT_CLEAR_TS: |
| 4424 | case QLA_TGT_ABORT_TS: |
| 4425 | 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] | 4426 | /* fall through */ |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4427 | case QLA_TGT_CLEAR_ACA: |
| 4428 | h = qlt_find_qphint(vha, mcmd->unpacked_lun); |
| 4429 | mcmd->qpair = h->qpair; |
| 4430 | mcmd->se_cmd.cpuid = h->cpuid; |
| 4431 | break; |
| 4432 | |
| 4433 | case QLA_TGT_TARGET_RESET: |
| 4434 | case QLA_TGT_NEXUS_LOSS_SESS: |
| 4435 | case QLA_TGT_NEXUS_LOSS: |
| 4436 | case QLA_TGT_ABORT_ALL: |
| 4437 | default: |
| 4438 | /* no-op */ |
| 4439 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4440 | } |
| 4441 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4442 | INIT_WORK(&mcmd->work, qlt_do_tmr_work); |
| 4443 | queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, |
| 4444 | &mcmd->work); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4445 | |
| 4446 | return 0; |
| 4447 | } |
| 4448 | |
| 4449 | /* ha->hardware_lock supposed to be held on entry */ |
| 4450 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) |
| 4451 | { |
| 4452 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4453 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4454 | struct fc_port *sess; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4455 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4456 | int fn; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4457 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4458 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4459 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4460 | |
| 4461 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4462 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4463 | a->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4464 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4465 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4466 | unpacked_lun = |
| 4467 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4468 | |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [diff] [blame] | 4469 | if (sess == NULL || sess->deleted) |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4470 | return -EFAULT; |
| 4471 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4472 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 4473 | } |
| 4474 | |
| 4475 | /* ha->hardware_lock supposed to be held on entry */ |
| 4476 | static int __qlt_abort_task(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4477 | struct imm_ntfy_from_isp *iocb, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4478 | { |
| 4479 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4480 | struct qla_hw_data *ha = vha->hw; |
| 4481 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4482 | u64 unpacked_lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4483 | int rc; |
| 4484 | |
| 4485 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4486 | if (mcmd == NULL) { |
| 4487 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, |
| 4488 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", |
| 4489 | vha->vp_idx, __func__); |
| 4490 | return -ENOMEM; |
| 4491 | } |
| 4492 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4493 | |
| 4494 | mcmd->sess = sess; |
| 4495 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4496 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4497 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4498 | unpacked_lun = |
| 4499 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4500 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4501 | mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4502 | mcmd->qpair = ha->base_qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4503 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4504 | 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] | 4505 | le16_to_cpu(iocb->u.isp2x.seq_id)); |
| 4506 | if (rc != 0) { |
| 4507 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, |
| 4508 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 4509 | vha->vp_idx, rc); |
| 4510 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4511 | return -EFAULT; |
| 4512 | } |
| 4513 | |
| 4514 | return 0; |
| 4515 | } |
| 4516 | |
| 4517 | /* ha->hardware_lock supposed to be held on entry */ |
| 4518 | static int qlt_abort_task(struct scsi_qla_host *vha, |
| 4519 | struct imm_ntfy_from_isp *iocb) |
| 4520 | { |
| 4521 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4522 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4523 | int loop_id; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4524 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4525 | |
| 4526 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); |
| 4527 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4528 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4529 | 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] | 4530 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4531 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4532 | if (sess == NULL) { |
| 4533 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, |
| 4534 | "qla_target(%d): task abort for unexisting " |
| 4535 | "session\n", vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4536 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4537 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
| 4538 | } |
| 4539 | |
| 4540 | return __qlt_abort_task(vha, iocb, sess); |
| 4541 | } |
| 4542 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4543 | void qlt_logo_completion_handler(fc_port_t *fcport, int rc) |
| 4544 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4545 | if (rc != MBS_COMMAND_COMPLETE) { |
| 4546 | ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093, |
| 4547 | "%s: se_sess %p / sess %p from" |
| 4548 | " port %8phC loop_id %#04x s_id %02x:%02x:%02x" |
| 4549 | " LOGO failed: %#x\n", |
| 4550 | __func__, |
| 4551 | fcport->se_sess, |
| 4552 | fcport, |
| 4553 | fcport->port_name, fcport->loop_id, |
| 4554 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4555 | fcport->d_id.b.al_pa, rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4556 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4557 | |
| 4558 | fcport->logout_completed = 1; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4559 | } |
| 4560 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4561 | /* |
| 4562 | * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) |
| 4563 | * |
| 4564 | * Schedules sessions with matching port_id/loop_id but different wwn for |
| 4565 | * deletion. Returns existing session with matching wwn if present. |
| 4566 | * Null otherwise. |
| 4567 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4568 | struct fc_port * |
| 4569 | 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] | 4570 | 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] | 4571 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4572 | struct fc_port *sess = NULL, *other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4573 | uint64_t other_wwn; |
| 4574 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4575 | *conflict_sess = NULL; |
| 4576 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4577 | list_for_each_entry(other_sess, &vha->vp_fcports, list) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4578 | |
| 4579 | other_wwn = wwn_to_u64(other_sess->port_name); |
| 4580 | |
| 4581 | if (wwn == other_wwn) { |
| 4582 | WARN_ON(sess); |
| 4583 | sess = other_sess; |
| 4584 | continue; |
| 4585 | } |
| 4586 | |
| 4587 | /* find other sess with nport_id collision */ |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4588 | if (port_id.b24 == other_sess->d_id.b24) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4589 | if (loop_id != other_sess->loop_id) { |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame] | 4590 | ql_dbg(ql_dbg_disc, vha, 0x1000c, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4591 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4592 | other_sess, other_sess->loop_id, other_wwn); |
| 4593 | |
| 4594 | /* |
| 4595 | * logout_on_delete is set by default, but another |
| 4596 | * session that has the same s_id/loop_id combo |
| 4597 | * might have cleared it when requested this session |
| 4598 | * deletion, so don't touch it |
| 4599 | */ |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4600 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4601 | } else { |
| 4602 | /* |
| 4603 | * Another wwn used to have our s_id/loop_id |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4604 | * kill the session, but don't free the loop_id |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4605 | */ |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame] | 4606 | ql_dbg(ql_dbg_disc, vha, 0xf01b, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4607 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4608 | other_sess, other_sess->loop_id, other_wwn); |
| 4609 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4610 | other_sess->keep_nport_handle = 1; |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 4611 | if (other_sess->disc_state != DSC_DELETED) |
| 4612 | *conflict_sess = other_sess; |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4613 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4614 | } |
| 4615 | continue; |
| 4616 | } |
| 4617 | |
| 4618 | /* find other sess with nport handle collision */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4619 | if ((loop_id == other_sess->loop_id) && |
| 4620 | (loop_id != FC_NO_LOOP_ID)) { |
Quinn Tran | e1217dc | 2019-12-17 14:06:15 -0800 | [diff] [blame] | 4621 | ql_dbg(ql_dbg_disc, vha, 0x1000d, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4622 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4623 | other_sess, other_sess->loop_id, other_wwn); |
| 4624 | |
| 4625 | /* Same loop_id but different s_id |
| 4626 | * Ok to kill and logout */ |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4627 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4628 | } |
| 4629 | } |
| 4630 | |
| 4631 | return sess; |
| 4632 | } |
| 4633 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4634 | /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */ |
| 4635 | static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id) |
| 4636 | { |
| 4637 | struct qla_tgt_sess_op *op; |
| 4638 | struct qla_tgt_cmd *cmd; |
| 4639 | uint32_t key; |
| 4640 | int count = 0; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4641 | unsigned long flags; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4642 | |
| 4643 | key = (((u32)s_id->b.domain << 16) | |
| 4644 | ((u32)s_id->b.area << 8) | |
| 4645 | ((u32)s_id->b.al_pa)); |
| 4646 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4647 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4648 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 4649 | 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] | 4650 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4651 | if (op_key == key) { |
| 4652 | op->aborted = true; |
| 4653 | count++; |
| 4654 | } |
| 4655 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4656 | |
| 4657 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 4658 | 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] | 4659 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4660 | if (op_key == key) { |
| 4661 | op->aborted = true; |
| 4662 | count++; |
| 4663 | } |
| 4664 | } |
| 4665 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4666 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 4667 | 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] | 4668 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4669 | if (cmd_key == key) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4670 | cmd->aborted = 1; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4671 | count++; |
| 4672 | } |
| 4673 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4674 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4675 | |
| 4676 | return count; |
| 4677 | } |
| 4678 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4679 | static int qlt_handle_login(struct scsi_qla_host *vha, |
| 4680 | struct imm_ntfy_from_isp *iocb) |
| 4681 | { |
| 4682 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
| 4683 | uint64_t wwn; |
| 4684 | port_id_t port_id; |
| 4685 | uint16_t loop_id, wd3_lo; |
| 4686 | int res = 0; |
| 4687 | struct qlt_plogi_ack_t *pla; |
| 4688 | unsigned long flags; |
| 4689 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 4690 | lockdep_assert_held(&vha->hw->hardware_lock); |
| 4691 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4692 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4693 | |
| 4694 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4695 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4696 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4697 | port_id.b.rsvd_1 = 0; |
| 4698 | |
| 4699 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4700 | |
| 4701 | /* Mark all stale commands sitting in qla_tgt_wq for deletion */ |
| 4702 | abort_cmds_for_s_id(vha, &port_id); |
| 4703 | |
| 4704 | if (wwn) { |
| 4705 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 4706 | sess = qlt_find_sess_invalidate_other(vha, wwn, |
| 4707 | port_id, loop_id, &conflict_sess); |
| 4708 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | aa9e6d7 | 2018-08-31 11:24:38 -0700 | [diff] [blame] | 4709 | } else { |
| 4710 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4711 | "%s %d Term INOT due to WWN=0 lid=%d, NportID %06X ", |
| 4712 | __func__, __LINE__, loop_id, port_id.b24); |
| 4713 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4714 | goto out; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | if (IS_SW_RESV_ADDR(port_id)) { |
| 4718 | res = 1; |
| 4719 | goto out; |
| 4720 | } |
| 4721 | |
| 4722 | pla = qlt_plogi_ack_find_add(vha, &port_id, iocb); |
| 4723 | if (!pla) { |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 4724 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
| 4725 | "%s %d %8phC Term INOT due to mem alloc fail", |
| 4726 | __func__, __LINE__, |
| 4727 | iocb->u.isp24.port_name); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4728 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4729 | goto out; |
| 4730 | } |
| 4731 | |
| 4732 | if (conflict_sess) { |
| 4733 | conflict_sess->login_gen++; |
| 4734 | qlt_plogi_ack_link(vha, pla, conflict_sess, |
| 4735 | QLT_PLOGI_LINK_CONFLICT); |
| 4736 | } |
| 4737 | |
| 4738 | if (!sess) { |
| 4739 | pla->ref_count++; |
| 4740 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4741 | "%s %d %8phC post new sess\n", |
| 4742 | __func__, __LINE__, iocb->u.isp24.port_name); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4743 | if (iocb->u.isp24.status_subcode == ELS_PLOGI) |
| 4744 | qla24xx_post_newsess_work(vha, &port_id, |
| 4745 | iocb->u.isp24.port_name, |
| 4746 | iocb->u.isp24.u.plogi.node_name, |
Quinn Tran | 8e0e063 | 2020-02-26 14:40:08 -0800 | [diff] [blame] | 4747 | pla, 0); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4748 | else |
| 4749 | qla24xx_post_newsess_work(vha, &port_id, |
| 4750 | iocb->u.isp24.port_name, NULL, |
Quinn Tran | 8e0e063 | 2020-02-26 14:40:08 -0800 | [diff] [blame] | 4751 | pla, 0); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4752 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4753 | goto out; |
| 4754 | } |
| 4755 | |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4756 | if (sess->disc_state == DSC_UPD_FCPORT) { |
| 4757 | u16 sec; |
| 4758 | |
| 4759 | /* |
| 4760 | * Remote port registration is still going on from |
| 4761 | * previous login. Allow it to finish before we |
| 4762 | * accept the new login. |
| 4763 | */ |
| 4764 | sess->next_disc_state = DSC_DELETE_PEND; |
| 4765 | sec = jiffies_to_msecs(jiffies - |
| 4766 | sess->jiffies_at_registration) / 1000; |
| 4767 | if (sess->sec_since_registration < sec && sec && |
| 4768 | !(sec % 5)) { |
| 4769 | sess->sec_since_registration = sec; |
| 4770 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4771 | "%s %8phC - Slow Rport registration (%d Sec)\n", |
| 4772 | __func__, sess->port_name, sec); |
| 4773 | } |
| 4774 | |
Bart Van Assche | 1df627b | 2019-08-08 20:01:42 -0700 | [diff] [blame] | 4775 | if (!conflict_sess) { |
| 4776 | list_del(&pla->list); |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4777 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
Bart Van Assche | 1df627b | 2019-08-08 20:01:42 -0700 | [diff] [blame] | 4778 | } |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4779 | |
| 4780 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4781 | goto out; |
| 4782 | } |
| 4783 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4784 | qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN); |
| 4785 | sess->d_id = port_id; |
| 4786 | sess->login_gen++; |
| 4787 | |
| 4788 | if (iocb->u.isp24.status_subcode == ELS_PRLI) { |
| 4789 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
| 4790 | sess->local = 0; |
| 4791 | sess->loop_id = loop_id; |
| 4792 | sess->d_id = port_id; |
| 4793 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
| 4794 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4795 | |
| 4796 | if (wd3_lo & BIT_7) |
| 4797 | sess->conf_compl_supported = 1; |
| 4798 | |
| 4799 | if ((wd3_lo & BIT_4) == 0) |
| 4800 | sess->port_type = FCT_INITIATOR; |
| 4801 | else |
| 4802 | sess->port_type = FCT_TARGET; |
| 4803 | |
| 4804 | } else |
| 4805 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
| 4806 | |
| 4807 | |
| 4808 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4809 | "%s %d %8phC DS %d\n", |
| 4810 | __func__, __LINE__, sess->port_name, sess->disc_state); |
| 4811 | |
| 4812 | switch (sess->disc_state) { |
| 4813 | case DSC_DELETED: |
Roman Bolshakov | 5e6b01d | 2019-11-25 19:56:59 +0300 | [diff] [blame] | 4814 | case DSC_LOGIN_PEND: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4815 | qlt_plogi_ack_unref(vha, pla); |
| 4816 | break; |
| 4817 | |
| 4818 | default: |
| 4819 | /* |
| 4820 | * Under normal circumstances we want to release nport handle |
| 4821 | * during LOGO process to avoid nport handle leaks inside FW. |
| 4822 | * The exception is when LOGO is done while another PLOGI with |
| 4823 | * the same nport handle is waiting as might be the case here. |
| 4824 | * Note: there is always a possibily of a race where session |
| 4825 | * deletion has already started for other reasons (e.g. ACL |
| 4826 | * removal) and now PLOGI arrives: |
| 4827 | * 1. if PLOGI arrived in FW after nport handle has been freed, |
| 4828 | * FW must have assigned this PLOGI a new/same handle and we |
| 4829 | * can proceed ACK'ing it as usual when session deletion |
| 4830 | * completes. |
| 4831 | * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT |
| 4832 | * bit reached it, the handle has now been released. We'll |
| 4833 | * get an error when we ACK this PLOGI. Nothing will be sent |
| 4834 | * back to initiator. Initiator should eventually retry |
| 4835 | * PLOGI and situation will correct itself. |
| 4836 | */ |
| 4837 | sess->keep_nport_handle = ((sess->loop_id == loop_id) && |
| 4838 | (sess->d_id.b24 == port_id.b24)); |
| 4839 | |
| 4840 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4841 | "%s %d %8phC post del sess\n", |
| 4842 | __func__, __LINE__, sess->port_name); |
| 4843 | |
| 4844 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 4845 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4846 | break; |
| 4847 | } |
| 4848 | out: |
| 4849 | return res; |
| 4850 | } |
| 4851 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4852 | /* |
| 4853 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4854 | */ |
| 4855 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, |
| 4856 | struct imm_ntfy_from_isp *iocb) |
| 4857 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4858 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4859 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4860 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4861 | uint64_t wwn; |
| 4862 | port_id_t port_id; |
| 4863 | uint16_t loop_id; |
| 4864 | uint16_t wd3_lo; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4865 | int res = 0; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4866 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4867 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 4868 | lockdep_assert_held(&ha->hardware_lock); |
| 4869 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4870 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4871 | |
| 4872 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4873 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4874 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4875 | port_id.b.rsvd_1 = 0; |
| 4876 | |
| 4877 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4878 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4879 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 4880 | "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n", |
| 4881 | vha->vp_idx, iocb->u.isp24.port_id[2], |
| 4882 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 4883 | iocb->u.isp24.status_subcode, loop_id, |
| 4884 | iocb->u.isp24.port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4885 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4886 | /* res = 1 means ack at the end of thread |
| 4887 | * res = 0 means ack async/later. |
| 4888 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4889 | switch (iocb->u.isp24.status_subcode) { |
| 4890 | case ELS_PLOGI: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4891 | res = qlt_handle_login(vha, iocb); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4892 | break; |
| 4893 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4894 | case ELS_PRLI: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4895 | if (N2N_TOPO(ha)) { |
| 4896 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 4897 | iocb->u.isp24.port_name, 1); |
| 4898 | |
| 4899 | if (sess && sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]) { |
| 4900 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4901 | "%s %d %8phC Term PRLI due to PLOGI ACK not completed\n", |
| 4902 | __func__, __LINE__, |
| 4903 | iocb->u.isp24.port_name); |
| 4904 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4905 | break; |
| 4906 | } |
| 4907 | |
| 4908 | res = qlt_handle_login(vha, iocb); |
| 4909 | break; |
| 4910 | } |
| 4911 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4912 | if (IS_SW_RESV_ADDR(port_id)) { |
| 4913 | res = 1; |
| 4914 | break; |
| 4915 | } |
| 4916 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4917 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4918 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4919 | if (wwn) { |
| 4920 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4921 | sess = qlt_find_sess_invalidate_other(vha, wwn, port_id, |
| 4922 | loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4923 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4924 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4925 | |
| 4926 | if (conflict_sess) { |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 4927 | switch (conflict_sess->disc_state) { |
| 4928 | case DSC_DELETED: |
| 4929 | case DSC_DELETE_PEND: |
| 4930 | break; |
| 4931 | default: |
| 4932 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b, |
| 4933 | "PRLI with conflicting sess %p port %8phC\n", |
| 4934 | conflict_sess, conflict_sess->port_name); |
| 4935 | conflict_sess->fw_login_state = |
| 4936 | DSC_LS_PORT_UNAVAIL; |
| 4937 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4938 | res = 0; |
| 4939 | break; |
| 4940 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4941 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4942 | |
| 4943 | if (sess != NULL) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4944 | bool delete = false; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4945 | int sec; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 4946 | |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4947 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
| 4948 | switch (sess->fw_login_state) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4949 | case DSC_LS_PLOGI_PEND: |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4950 | case DSC_LS_PLOGI_COMP: |
| 4951 | case DSC_LS_PRLI_COMP: |
| 4952 | break; |
| 4953 | default: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4954 | delete = true; |
| 4955 | break; |
| 4956 | } |
| 4957 | |
| 4958 | switch (sess->disc_state) { |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4959 | case DSC_UPD_FCPORT: |
| 4960 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, |
| 4961 | flags); |
| 4962 | |
| 4963 | sec = jiffies_to_msecs(jiffies - |
| 4964 | sess->jiffies_at_registration)/1000; |
| 4965 | if (sess->sec_since_registration < sec && sec && |
| 4966 | !(sec % 5)) { |
| 4967 | sess->sec_since_registration = sec; |
| 4968 | ql_dbg(ql_dbg_disc, sess->vha, 0xffff, |
| 4969 | "%s %8phC : Slow Rport registration(%d Sec)\n", |
| 4970 | __func__, sess->port_name, sec); |
| 4971 | } |
| 4972 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4973 | return 0; |
| 4974 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4975 | case DSC_LOGIN_PEND: |
| 4976 | case DSC_GPDB: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4977 | case DSC_LOGIN_COMPLETE: |
| 4978 | case DSC_ADISC: |
| 4979 | delete = false; |
| 4980 | break; |
| 4981 | default: |
| 4982 | break; |
| 4983 | } |
| 4984 | |
| 4985 | if (delete) { |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4986 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, |
| 4987 | flags); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4988 | /* |
| 4989 | * Impatient initiator sent PRLI before last |
| 4990 | * PLOGI could finish. Will force him to re-try, |
| 4991 | * while last one finishes. |
| 4992 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4993 | ql_log(ql_log_warn, sess->vha, 0xf095, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4994 | "sess %p PRLI received, before plogi ack.\n", |
| 4995 | sess); |
| 4996 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4997 | res = 0; |
| 4998 | break; |
| 4999 | } |
| 5000 | |
| 5001 | /* |
| 5002 | * This shouldn't happen under normal circumstances, |
| 5003 | * since we have deleted the old session during PLOGI |
| 5004 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5005 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5006 | "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n", |
| 5007 | sess->loop_id, sess, iocb->u.isp24.nport_handle); |
| 5008 | |
| 5009 | sess->local = 0; |
| 5010 | sess->loop_id = loop_id; |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 5011 | sess->d_id = port_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5012 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5013 | |
| 5014 | if (wd3_lo & BIT_7) |
| 5015 | sess->conf_compl_supported = 1; |
| 5016 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5017 | if ((wd3_lo & BIT_4) == 0) |
| 5018 | sess->port_type = FCT_INITIATOR; |
| 5019 | else |
| 5020 | sess->port_type = FCT_TARGET; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 5021 | |
| 5022 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5023 | } |
| 5024 | res = 1; /* send notify ack */ |
| 5025 | |
| 5026 | /* Make session global (not used in fabric mode) */ |
| 5027 | if (ha->current_topology != ISP_CFG_F) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5028 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5029 | ql_dbg(ql_dbg_disc, vha, 0x20fa, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5030 | "%s %d %8phC post nack\n", |
| 5031 | __func__, __LINE__, sess->port_name); |
| 5032 | qla24xx_post_nack_work(vha, sess, iocb, |
| 5033 | SRB_NACK_PRLI); |
| 5034 | res = 0; |
| 5035 | } else { |
| 5036 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5037 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 5038 | qla2xxx_wake_dpc(vha); |
| 5039 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5040 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5041 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5042 | ql_dbg(ql_dbg_disc, vha, 0x20fb, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5043 | "%s %d %8phC post nack\n", |
| 5044 | __func__, __LINE__, sess->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5045 | qla24xx_post_nack_work(vha, sess, iocb, |
| 5046 | SRB_NACK_PRLI); |
| 5047 | res = 0; |
| 5048 | } |
| 5049 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5050 | break; |
| 5051 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5052 | case ELS_TPRLO: |
| 5053 | if (le16_to_cpu(iocb->u.isp24.flags) & |
| 5054 | NOTIFY24XX_FLAGS_GLOBAL_TPRLO) { |
| 5055 | loop_id = 0xFFFF; |
| 5056 | qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS); |
| 5057 | res = 1; |
| 5058 | break; |
| 5059 | } |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 5060 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5061 | case ELS_LOGO: |
| 5062 | case ELS_PRLO: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5063 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 5064 | sess = qla2x00_find_fcport_by_loopid(vha, loop_id); |
| 5065 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 5066 | |
| 5067 | if (sess) { |
| 5068 | sess->login_gen++; |
| 5069 | sess->fw_login_state = DSC_LS_LOGO_PEND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5070 | sess->logo_ack_needed = 1; |
| 5071 | memcpy(sess->iocb, iocb, IOCB_SIZE); |
| 5072 | } |
| 5073 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5074 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5075 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5076 | ql_dbg(ql_dbg_disc, vha, 0x20fc, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5077 | "%s: logo %llx res %d sess %p ", |
| 5078 | __func__, wwn, res, sess); |
| 5079 | if (res == 0) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5080 | /* |
| 5081 | * cmd went upper layer, look for qlt_xmit_tm_rsp() |
| 5082 | * for LOGO_ACK & sess delete |
| 5083 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5084 | BUG_ON(!sess); |
| 5085 | res = 0; |
| 5086 | } else { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5087 | /* cmd did not go to upper layer. */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5088 | if (sess) { |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 5089 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5090 | res = 0; |
| 5091 | } |
| 5092 | /* else logo will be ack */ |
| 5093 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5094 | break; |
| 5095 | case ELS_PDISC: |
| 5096 | case ELS_ADISC: |
| 5097 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5098 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5099 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5100 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5101 | qlt_send_notify_ack(ha->base_qpair, |
| 5102 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5103 | tgt->link_reinit_iocb_pending = 0; |
| 5104 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5105 | |
| 5106 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 5107 | iocb->u.isp24.port_name, 1); |
| 5108 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5109 | ql_dbg(ql_dbg_disc, vha, 0x20fd, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5110 | "sess %p lid %d|%d DS %d LS %d\n", |
| 5111 | sess, sess->loop_id, loop_id, |
| 5112 | sess->disc_state, sess->fw_login_state); |
| 5113 | } |
| 5114 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5115 | res = 1; /* send notify ack */ |
| 5116 | break; |
| 5117 | } |
| 5118 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5119 | case ELS_FLOGI: /* should never happen */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5120 | default: |
| 5121 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, |
| 5122 | "qla_target(%d): Unsupported ELS command %x " |
| 5123 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); |
| 5124 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 5125 | break; |
| 5126 | } |
| 5127 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 5128 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 5129 | "qla_target(%d): Exit ELS opcode: 0x%02x res %d\n", |
| 5130 | vha->vp_idx, iocb->u.isp24.status_subcode, res); |
| 5131 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5132 | return res; |
| 5133 | } |
| 5134 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5135 | /* |
| 5136 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5137 | */ |
| 5138 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, |
| 5139 | struct imm_ntfy_from_isp *iocb) |
| 5140 | { |
| 5141 | struct qla_hw_data *ha = vha->hw; |
| 5142 | uint32_t add_flags = 0; |
| 5143 | int send_notify_ack = 1; |
| 5144 | uint16_t status; |
| 5145 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 5146 | lockdep_assert_held(&ha->hardware_lock); |
| 5147 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5148 | status = le16_to_cpu(iocb->u.isp2x.status); |
| 5149 | switch (status) { |
| 5150 | case IMM_NTFY_LIP_RESET: |
| 5151 | { |
| 5152 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, |
| 5153 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", |
| 5154 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5155 | iocb->u.isp24.status_subcode); |
| 5156 | |
| 5157 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5158 | send_notify_ack = 0; |
| 5159 | break; |
| 5160 | } |
| 5161 | |
| 5162 | case IMM_NTFY_LIP_LINK_REINIT: |
| 5163 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5164 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5165 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5166 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
| 5167 | "qla_target(%d): LINK REINIT (loop %#x, " |
| 5168 | "subcode %x)\n", vha->vp_idx, |
| 5169 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5170 | iocb->u.isp24.status_subcode); |
| 5171 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5172 | qlt_send_notify_ack(ha->base_qpair, |
| 5173 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5174 | } |
| 5175 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); |
| 5176 | tgt->link_reinit_iocb_pending = 1; |
| 5177 | /* |
| 5178 | * QLogic requires to wait after LINK REINIT for possible |
| 5179 | * PDISC or ADISC ELS commands |
| 5180 | */ |
| 5181 | send_notify_ack = 0; |
| 5182 | break; |
| 5183 | } |
| 5184 | |
| 5185 | case IMM_NTFY_PORT_LOGOUT: |
| 5186 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, |
| 5187 | "qla_target(%d): Port logout (loop " |
| 5188 | "%#x, subcode %x)\n", vha->vp_idx, |
| 5189 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5190 | iocb->u.isp24.status_subcode); |
| 5191 | |
| 5192 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) |
| 5193 | send_notify_ack = 0; |
| 5194 | /* The sessions will be cleared in the callback, if needed */ |
| 5195 | break; |
| 5196 | |
| 5197 | case IMM_NTFY_GLBL_TPRLO: |
| 5198 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, |
| 5199 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); |
| 5200 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5201 | send_notify_ack = 0; |
| 5202 | /* The sessions will be cleared in the callback, if needed */ |
| 5203 | break; |
| 5204 | |
| 5205 | case IMM_NTFY_PORT_CONFIG: |
| 5206 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, |
| 5207 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, |
| 5208 | status); |
| 5209 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5210 | send_notify_ack = 0; |
| 5211 | /* The sessions will be cleared in the callback, if needed */ |
| 5212 | break; |
| 5213 | |
| 5214 | case IMM_NTFY_GLBL_LOGO: |
| 5215 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, |
| 5216 | "qla_target(%d): Link failure detected\n", |
| 5217 | vha->vp_idx); |
| 5218 | /* I_T nexus loss */ |
| 5219 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5220 | send_notify_ack = 0; |
| 5221 | break; |
| 5222 | |
| 5223 | case IMM_NTFY_IOCB_OVERFLOW: |
| 5224 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, |
| 5225 | "qla_target(%d): Cannot provide requested " |
| 5226 | "capability (IOCB overflowed the immediate notify " |
| 5227 | "resource count)\n", vha->vp_idx); |
| 5228 | break; |
| 5229 | |
| 5230 | case IMM_NTFY_ABORT_TASK: |
| 5231 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, |
| 5232 | "qla_target(%d): Abort Task (S %08x I %#x -> " |
| 5233 | "L %#x)\n", vha->vp_idx, |
| 5234 | le16_to_cpu(iocb->u.isp2x.seq_id), |
| 5235 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), |
| 5236 | le16_to_cpu(iocb->u.isp2x.lun)); |
| 5237 | if (qlt_abort_task(vha, iocb) == 0) |
| 5238 | send_notify_ack = 0; |
| 5239 | break; |
| 5240 | |
| 5241 | case IMM_NTFY_RESOURCE: |
| 5242 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, |
| 5243 | "qla_target(%d): Out of resources, host %ld\n", |
| 5244 | vha->vp_idx, vha->host_no); |
| 5245 | break; |
| 5246 | |
| 5247 | case IMM_NTFY_MSG_RX: |
| 5248 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, |
| 5249 | "qla_target(%d): Immediate notify task %x\n", |
| 5250 | vha->vp_idx, iocb->u.isp2x.task_flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5251 | break; |
| 5252 | |
| 5253 | case IMM_NTFY_ELS: |
| 5254 | if (qlt_24xx_handle_els(vha, iocb) == 0) |
| 5255 | send_notify_ack = 0; |
| 5256 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5257 | default: |
| 5258 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, |
| 5259 | "qla_target(%d): Received unknown immediate " |
| 5260 | "notify status %x\n", vha->vp_idx, status); |
| 5261 | break; |
| 5262 | } |
| 5263 | |
| 5264 | if (send_notify_ack) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5265 | qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0, |
| 5266 | 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | /* |
| 5270 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5271 | * This function sends busy to ISP 2xxx or 24xx. |
| 5272 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5273 | static int __qlt_send_busy(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5274 | struct atio_from_isp *atio, uint16_t status) |
| 5275 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5276 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5277 | struct ctio7_to_24xx *ctio24; |
| 5278 | struct qla_hw_data *ha = vha->hw; |
| 5279 | request_t *pkt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5280 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5281 | unsigned long flags; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5282 | u16 temp; |
Quinn Tran | 8ea4faf | 2018-05-01 09:01:49 -0700 | [diff] [blame] | 5283 | port_id_t id; |
| 5284 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 5285 | id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5286 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5287 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 8ea4faf | 2018-05-01 09:01:49 -0700 | [diff] [blame] | 5288 | sess = qla2x00_find_fcport_by_nportid(vha, &id, 1); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5289 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5290 | if (!sess) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5291 | qlt_send_term_exchange(qpair, NULL, atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5292 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5293 | } |
| 5294 | /* Sending marker isn't necessary, since we called from ISR */ |
| 5295 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5296 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5297 | if (!pkt) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5298 | ql_dbg(ql_dbg_io, vha, 0x3063, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5299 | "qla_target(%d): %s failed: unable to allocate " |
| 5300 | "request packet", vha->vp_idx, __func__); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5301 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5302 | } |
| 5303 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5304 | qpair->tgt_counters.num_q_full_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5305 | pkt->entry_count = 1; |
| 5306 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 5307 | |
| 5308 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 5309 | ctio24->entry_type = CTIO_TYPE7; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5310 | ctio24->nport_handle = cpu_to_le16(sess->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5311 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5312 | ctio24->vp_index = vha->vp_idx; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 5313 | 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] | 5314 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5315 | temp = (atio->u.isp24.attr << 9) | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5316 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5317 | CTIO7_FLAGS_DONT_RET_CTIO; |
| 5318 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5319 | /* |
| 5320 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, |
| 5321 | * if the explicit conformation is used. |
| 5322 | */ |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5323 | ctio24->u.status1.ox_id = |
| 5324 | cpu_to_le16(be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5325 | ctio24->u.status1.scsi_status = cpu_to_le16(status); |
Quinn Tran | e25f765 | 2018-05-01 09:01:50 -0700 | [diff] [blame] | 5326 | |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5327 | ctio24->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio)); |
Quinn Tran | e25f765 | 2018-05-01 09:01:50 -0700 | [diff] [blame] | 5328 | |
| 5329 | if (ctio24->u.status1.residual != 0) |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5330 | ctio24->u.status1.scsi_status |= cpu_to_le16(SS_RESIDUAL_UNDER); |
Quinn Tran | e25f765 | 2018-05-01 09:01:50 -0700 | [diff] [blame] | 5331 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 5332 | /* Memory Barrier */ |
| 5333 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 5334 | if (qpair->reqq_start_iocbs) |
| 5335 | qpair->reqq_start_iocbs(qpair); |
| 5336 | else |
| 5337 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5338 | return 0; |
| 5339 | } |
| 5340 | |
| 5341 | /* |
| 5342 | * This routine is used to allocate a command for either a QFull condition |
| 5343 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go |
| 5344 | * out previously. |
| 5345 | */ |
| 5346 | static void |
| 5347 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 5348 | struct atio_from_isp *atio, uint16_t status, int qfull) |
| 5349 | { |
| 5350 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 5351 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5352 | struct fc_port *sess; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5353 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5354 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5355 | |
| 5356 | if (unlikely(tgt->tgt_stop)) { |
| 5357 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 5358 | "New command while device %p is shutting down\n", tgt); |
| 5359 | return; |
| 5360 | } |
| 5361 | |
| 5362 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { |
| 5363 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5364 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5365 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5366 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5367 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5368 | |
| 5369 | ql_dbg(ql_dbg_io, vha, 0x3068, |
| 5370 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", |
| 5371 | vha->vp_idx, __func__, |
| 5372 | vha->hw->tgt.num_qfull_cmds_dropped); |
| 5373 | |
| 5374 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5375 | return; |
| 5376 | } |
| 5377 | |
| 5378 | sess = ha->tgt.tgt_ops->find_sess_by_s_id |
| 5379 | (vha, atio->u.isp24.fcp_hdr.s_id); |
| 5380 | if (!sess) |
| 5381 | return; |
| 5382 | |
Bart Van Assche | 80363e1 | 2020-01-03 11:27:19 -0800 | [diff] [blame] | 5383 | cmd = ha->tgt.tgt_ops->get_cmd(sess); |
| 5384 | if (!cmd) { |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5385 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 5386 | "qla_target(%d): %s: Allocation of cmd failed\n", |
| 5387 | vha->vp_idx, __func__); |
| 5388 | |
| 5389 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5390 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5391 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5392 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5393 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5394 | |
| 5395 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5396 | return; |
| 5397 | } |
| 5398 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5399 | qlt_incr_num_pend_cmds(vha); |
| 5400 | INIT_LIST_HEAD(&cmd->cmd_list); |
| 5401 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 5402 | |
| 5403 | cmd->tgt = vha->vha_tgt.qla_tgt; |
| 5404 | cmd->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 5405 | cmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5406 | cmd->q_full = 1; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5407 | cmd->qpair = ha->base_qpair; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5408 | |
| 5409 | if (qfull) { |
| 5410 | cmd->q_full = 1; |
| 5411 | /* NOTE: borrowing the state field to carry the status */ |
| 5412 | cmd->state = status; |
| 5413 | } else |
| 5414 | cmd->term_exchg = 1; |
| 5415 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5416 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5417 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); |
| 5418 | |
| 5419 | vha->hw->tgt.num_qfull_cmds_alloc++; |
| 5420 | if (vha->hw->tgt.num_qfull_cmds_alloc > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5421 | vha->qla_stats.stat_max_qfull_cmds_alloc) |
| 5422 | vha->qla_stats.stat_max_qfull_cmds_alloc = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5423 | vha->hw->tgt.num_qfull_cmds_alloc; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5424 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5428 | qlt_free_qfull_cmds(struct qla_qpair *qpair) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5429 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5430 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5431 | struct qla_hw_data *ha = vha->hw; |
| 5432 | unsigned long flags; |
| 5433 | struct qla_tgt_cmd *cmd, *tcmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5434 | struct list_head free_list, q_full_list; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5435 | int rc = 0; |
| 5436 | |
| 5437 | if (list_empty(&ha->tgt.q_full_list)) |
| 5438 | return 0; |
| 5439 | |
| 5440 | INIT_LIST_HEAD(&free_list); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5441 | INIT_LIST_HEAD(&q_full_list); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5442 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5443 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5444 | if (list_empty(&ha->tgt.q_full_list)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5445 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5446 | return 0; |
| 5447 | } |
| 5448 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5449 | list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list); |
| 5450 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5451 | |
| 5452 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 5453 | list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) { |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5454 | if (cmd->q_full) |
| 5455 | /* cmd->state is a borrowed field to hold status */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5456 | rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5457 | else if (cmd->term_exchg) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5458 | rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5459 | |
| 5460 | if (rc == -ENOMEM) |
| 5461 | break; |
| 5462 | |
| 5463 | if (cmd->q_full) |
| 5464 | ql_dbg(ql_dbg_io, vha, 0x3006, |
| 5465 | "%s: busy sent for ox_id[%04x]\n", __func__, |
| 5466 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5467 | else if (cmd->term_exchg) |
| 5468 | ql_dbg(ql_dbg_io, vha, 0x3007, |
| 5469 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, |
| 5470 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5471 | else |
| 5472 | ql_dbg(ql_dbg_io, vha, 0x3008, |
| 5473 | "%s: Unexpected cmd in QFull list %p\n", __func__, |
| 5474 | cmd); |
| 5475 | |
| 5476 | list_del(&cmd->cmd_list); |
| 5477 | list_add_tail(&cmd->cmd_list, &free_list); |
| 5478 | |
| 5479 | /* piggy back on hardware_lock for protection */ |
| 5480 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 5481 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5482 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5483 | |
| 5484 | cmd = NULL; |
| 5485 | |
| 5486 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 5487 | list_del(&cmd->cmd_list); |
| 5488 | /* This cmd was never sent to TCM. There is no need |
| 5489 | * to schedule free or call free_cmd |
| 5490 | */ |
| 5491 | qlt_free_cmd(cmd); |
| 5492 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5493 | |
| 5494 | if (!list_empty(&q_full_list)) { |
| 5495 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 5496 | list_splice(&q_full_list, &vha->hw->tgt.q_full_list); |
| 5497 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5498 | } |
| 5499 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5500 | return rc; |
| 5501 | } |
| 5502 | |
| 5503 | static void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5504 | qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio, |
| 5505 | uint16_t status) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5506 | { |
| 5507 | int rc = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5508 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5509 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5510 | rc = __qlt_send_busy(qpair, atio, status); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5511 | if (rc == -ENOMEM) |
| 5512 | qlt_alloc_qfull_cmd(vha, atio, status, 1); |
| 5513 | } |
| 5514 | |
| 5515 | static int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5516 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair, |
| 5517 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5518 | { |
| 5519 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5520 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5521 | |
| 5522 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) |
| 5523 | return 0; |
| 5524 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5525 | if (!ha_locked) |
| 5526 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5527 | qlt_send_busy(qpair, atio, qla_sam_status); |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5528 | if (!ha_locked) |
| 5529 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5530 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5531 | return 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | /* ha->hardware_lock supposed to be held on entry */ |
| 5535 | /* called via callback from qla2xxx */ |
| 5536 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5537 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5538 | { |
| 5539 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5540 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5541 | int rc; |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5542 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5543 | |
| 5544 | if (unlikely(tgt == NULL)) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5545 | ql_dbg(ql_dbg_tgt, vha, 0x3064, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5546 | "ATIO pkt, but no tgt (ha %p)", ha); |
| 5547 | return; |
| 5548 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5549 | /* |
| 5550 | * In tgt_stop mode we also should allow all requests to pass. |
| 5551 | * Otherwise, some commands can stuck. |
| 5552 | */ |
| 5553 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5554 | tgt->atio_irq_cmd_count++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5555 | |
| 5556 | switch (atio->u.raw.entry_type) { |
| 5557 | case ATIO_TYPE7: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5558 | if (unlikely(atio->u.isp24.exchange_addr == |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5559 | cpu_to_le32(ATIO_EXCHANGE_ADDRESS_UNKNOWN))) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5560 | ql_dbg(ql_dbg_io, vha, 0x3065, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5561 | "qla_target(%d): ATIO_TYPE7 " |
| 5562 | "received with UNKNOWN exchange address, " |
| 5563 | "sending QUEUE_FULL\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5564 | if (!ha_locked) |
| 5565 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5566 | qlt_send_busy(ha->base_qpair, atio, qla_sam_status); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5567 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5568 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5569 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5570 | break; |
| 5571 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5572 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5573 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5574 | rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair, |
| 5575 | atio, ha_locked); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5576 | if (rc != 0) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5577 | tgt->atio_irq_cmd_count--; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5578 | return; |
| 5579 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5580 | rc = qlt_handle_cmd_for_atio(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5581 | } else { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5582 | rc = qlt_handle_task_mgmt(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5583 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5584 | if (unlikely(rc != 0)) { |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5585 | if (!ha_locked) |
| 5586 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5587 | switch (rc) { |
| 5588 | case -ENODEV: |
| 5589 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5590 | "qla_target: Unable to send command to target\n"); |
| 5591 | break; |
| 5592 | case -EBADF: |
| 5593 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5594 | "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] | 5595 | qlt_send_term_exchange(ha->base_qpair, NULL, |
| 5596 | atio, 1, 0); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5597 | break; |
| 5598 | case -EBUSY: |
| 5599 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5600 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5601 | vha->vp_idx); |
| 5602 | qlt_send_busy(ha->base_qpair, atio, |
| 5603 | tc_sam_status); |
| 5604 | break; |
| 5605 | default: |
| 5606 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5607 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5608 | vha->vp_idx); |
| 5609 | qlt_send_busy(ha->base_qpair, atio, |
| 5610 | qla_sam_status); |
| 5611 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5612 | } |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5613 | if (!ha_locked) |
| 5614 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5615 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5616 | } |
| 5617 | break; |
| 5618 | |
| 5619 | case IMMED_NOTIFY_TYPE: |
| 5620 | { |
| 5621 | if (unlikely(atio->u.isp2x.entry_status != 0)) { |
| 5622 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, |
| 5623 | "qla_target(%d): Received ATIO packet %x " |
| 5624 | "with error status %x\n", vha->vp_idx, |
| 5625 | atio->u.raw.entry_type, |
| 5626 | atio->u.isp2x.entry_status); |
| 5627 | break; |
| 5628 | } |
| 5629 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5630 | |
| 5631 | if (!ha_locked) |
| 5632 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5633 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5634 | if (!ha_locked) |
| 5635 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5636 | break; |
| 5637 | } |
| 5638 | |
| 5639 | default: |
| 5640 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, |
| 5641 | "qla_target(%d): Received unknown ATIO atio " |
| 5642 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 5643 | break; |
| 5644 | } |
| 5645 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5646 | tgt->atio_irq_cmd_count--; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5647 | } |
| 5648 | |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 5649 | /* |
| 5650 | * qpair lock is assume to be held |
| 5651 | * rc = 0 : send terminate & abts respond |
| 5652 | * rc != 0: do not send term & abts respond |
| 5653 | */ |
| 5654 | static int qlt_chk_unresolv_exchg(struct scsi_qla_host *vha, |
| 5655 | struct qla_qpair *qpair, struct abts_resp_from_24xx_fw *entry) |
| 5656 | { |
| 5657 | struct qla_hw_data *ha = vha->hw; |
| 5658 | int rc = 0; |
| 5659 | |
| 5660 | /* |
| 5661 | * Detect unresolved exchange. If the same ABTS is unable |
| 5662 | * to terminate an existing command and the same ABTS loops |
| 5663 | * between FW & Driver, then force FW dump. Under 1 jiff, |
| 5664 | * we should see multiple loops. |
| 5665 | */ |
| 5666 | if (qpair->retry_term_exchg_addr == entry->exchange_addr_to_abort && |
| 5667 | qpair->retry_term_jiff == jiffies) { |
| 5668 | /* found existing exchange */ |
| 5669 | qpair->retry_term_cnt++; |
| 5670 | if (qpair->retry_term_cnt >= 5) { |
| 5671 | rc = EIO; |
| 5672 | qpair->retry_term_cnt = 0; |
| 5673 | ql_log(ql_log_warn, vha, 0xffff, |
| 5674 | "Unable to send ABTS Respond. Dumping firmware.\n"); |
| 5675 | ql_dump_buffer(ql_dbg_tgt_mgt + ql_dbg_buffer, |
| 5676 | vha, 0xffff, (uint8_t *)entry, sizeof(*entry)); |
| 5677 | |
| 5678 | if (qpair == ha->base_qpair) |
Bart Van Assche | 8ae1787 | 2020-05-18 14:17:00 -0700 | [diff] [blame] | 5679 | ha->isp_ops->fw_dump(vha); |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 5680 | else |
Bart Van Assche | 8ae1787 | 2020-05-18 14:17:00 -0700 | [diff] [blame] | 5681 | qla2xxx_dump_fw(vha); |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 5682 | |
| 5683 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5684 | qla2xxx_wake_dpc(vha); |
| 5685 | } |
| 5686 | } else if (qpair->retry_term_jiff != jiffies) { |
| 5687 | qpair->retry_term_exchg_addr = entry->exchange_addr_to_abort; |
| 5688 | qpair->retry_term_cnt = 0; |
| 5689 | qpair->retry_term_jiff = jiffies; |
| 5690 | } |
| 5691 | |
| 5692 | return rc; |
| 5693 | } |
| 5694 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5695 | |
| 5696 | static void qlt_handle_abts_completion(struct scsi_qla_host *vha, |
| 5697 | struct rsp_que *rsp, response_t *pkt) |
| 5698 | { |
| 5699 | struct abts_resp_from_24xx_fw *entry = |
| 5700 | (struct abts_resp_from_24xx_fw *)pkt; |
| 5701 | u32 h = pkt->handle & ~QLA_TGT_HANDLE_MASK; |
| 5702 | struct qla_tgt_mgmt_cmd *mcmd; |
| 5703 | struct qla_hw_data *ha = vha->hw; |
| 5704 | |
Bart Van Assche | 81bcf1c | 2019-04-11 14:53:24 -0700 | [diff] [blame] | 5705 | mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, pkt); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5706 | if (mcmd == NULL && h != QLA_TGT_SKIP_HANDLE) { |
| 5707 | ql_dbg(ql_dbg_async, vha, 0xe064, |
| 5708 | "qla_target(%d): ABTS Comp without mcmd\n", |
| 5709 | vha->vp_idx); |
| 5710 | return; |
| 5711 | } |
| 5712 | |
| 5713 | if (mcmd) |
| 5714 | vha = mcmd->vha; |
| 5715 | vha->vha_tgt.qla_tgt->abts_resp_expected--; |
| 5716 | |
| 5717 | ql_dbg(ql_dbg_tgt, vha, 0xe038, |
| 5718 | "ABTS_RESP_24XX: compl_status %x\n", |
| 5719 | entry->compl_status); |
| 5720 | |
| 5721 | if (le16_to_cpu(entry->compl_status) != ABTS_RESP_COMPL_SUCCESS) { |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5722 | if (le32_to_cpu(entry->error_subcode1) == 0x1E && |
| 5723 | le32_to_cpu(entry->error_subcode2) == 0) { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5724 | if (qlt_chk_unresolv_exchg(vha, rsp->qpair, entry)) { |
| 5725 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5726 | return; |
| 5727 | } |
| 5728 | qlt_24xx_retry_term_exchange(vha, rsp->qpair, |
| 5729 | pkt, mcmd); |
| 5730 | } else { |
| 5731 | ql_dbg(ql_dbg_tgt, vha, 0xe063, |
| 5732 | "qla_target(%d): ABTS_RESP_24XX failed %x (subcode %x:%x)", |
| 5733 | vha->vp_idx, entry->compl_status, |
| 5734 | entry->error_subcode1, |
| 5735 | entry->error_subcode2); |
| 5736 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5737 | } |
Bart Van Assche | e752a04 | 2019-08-08 20:02:07 -0700 | [diff] [blame] | 5738 | } else if (mcmd) { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5739 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5740 | } |
| 5741 | } |
| 5742 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5743 | /* ha->hardware_lock supposed to be held on entry */ |
| 5744 | /* called via callback from qla2xxx */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5745 | static void qlt_response_pkt(struct scsi_qla_host *vha, |
| 5746 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5747 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5748 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5749 | |
| 5750 | if (unlikely(tgt == NULL)) { |
| 5751 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5752 | "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n", |
| 5753 | vha->vp_idx, pkt->entry_type, vha->hw); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5754 | return; |
| 5755 | } |
| 5756 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5757 | /* |
| 5758 | * In tgt_stop mode we also should allow all requests to pass. |
| 5759 | * Otherwise, some commands can stuck. |
| 5760 | */ |
| 5761 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5762 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 5763 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5764 | case CTIO_TYPE7: |
| 5765 | { |
| 5766 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5767 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5768 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5769 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5770 | entry); |
| 5771 | break; |
| 5772 | } |
| 5773 | |
| 5774 | case ACCEPT_TGT_IO_TYPE: |
| 5775 | { |
| 5776 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; |
| 5777 | int rc; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5778 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5779 | if (atio->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5780 | cpu_to_le16(ATIO_CDB_VALID)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5781 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, |
| 5782 | "qla_target(%d): ATIO with error " |
| 5783 | "status %x received\n", vha->vp_idx, |
| 5784 | le16_to_cpu(atio->u.isp2x.status)); |
| 5785 | break; |
| 5786 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5787 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5788 | rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1); |
Quinn Tran | ba68a63 | 2017-06-02 09:12:06 -0700 | [diff] [blame] | 5789 | if (rc != 0) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5790 | return; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5791 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5792 | rc = qlt_handle_cmd_for_atio(vha, atio); |
| 5793 | if (unlikely(rc != 0)) { |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5794 | switch (rc) { |
| 5795 | case -ENODEV: |
| 5796 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5797 | "qla_target: Unable to send command to target\n"); |
| 5798 | break; |
| 5799 | case -EBADF: |
| 5800 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5801 | "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n"); |
| 5802 | qlt_send_term_exchange(rsp->qpair, NULL, |
| 5803 | atio, 1, 0); |
| 5804 | break; |
| 5805 | case -EBUSY: |
| 5806 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5807 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5808 | vha->vp_idx); |
| 5809 | qlt_send_busy(rsp->qpair, atio, |
| 5810 | tc_sam_status); |
| 5811 | break; |
| 5812 | default: |
| 5813 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5814 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5815 | vha->vp_idx); |
| 5816 | qlt_send_busy(rsp->qpair, atio, |
| 5817 | qla_sam_status); |
| 5818 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5819 | } |
| 5820 | } |
| 5821 | } |
| 5822 | break; |
| 5823 | |
| 5824 | case CONTINUE_TGT_IO_TYPE: |
| 5825 | { |
| 5826 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5827 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5828 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5829 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5830 | entry); |
| 5831 | break; |
| 5832 | } |
| 5833 | |
| 5834 | case CTIO_A64_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 IMMED_NOTIFY_TYPE: |
| 5845 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); |
| 5846 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); |
| 5847 | break; |
| 5848 | |
| 5849 | case NOTIFY_ACK_TYPE: |
| 5850 | if (tgt->notify_ack_expected > 0) { |
| 5851 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5852 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5853 | ql_dbg(ql_dbg_tgt, vha, 0xe036, |
| 5854 | "NOTIFY_ACK seq %08x status %x\n", |
| 5855 | le16_to_cpu(entry->u.isp2x.seq_id), |
| 5856 | le16_to_cpu(entry->u.isp2x.status)); |
| 5857 | tgt->notify_ack_expected--; |
| 5858 | if (entry->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5859 | cpu_to_le16(NOTIFY_ACK_SUCCESS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5860 | ql_dbg(ql_dbg_tgt, vha, 0xe061, |
| 5861 | "qla_target(%d): NOTIFY_ACK " |
| 5862 | "failed %x\n", vha->vp_idx, |
| 5863 | le16_to_cpu(entry->u.isp2x.status)); |
| 5864 | } |
| 5865 | } else { |
| 5866 | ql_dbg(ql_dbg_tgt, vha, 0xe062, |
| 5867 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", |
| 5868 | vha->vp_idx); |
| 5869 | } |
| 5870 | break; |
| 5871 | |
| 5872 | case ABTS_RECV_24XX: |
| 5873 | ql_dbg(ql_dbg_tgt, vha, 0xe037, |
| 5874 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); |
| 5875 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); |
| 5876 | break; |
| 5877 | |
| 5878 | case ABTS_RESP_24XX: |
| 5879 | if (tgt->abts_resp_expected > 0) { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5880 | qlt_handle_abts_completion(vha, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5881 | } else { |
| 5882 | ql_dbg(ql_dbg_tgt, vha, 0xe064, |
| 5883 | "qla_target(%d): Unexpected ABTS_RESP_24XX " |
| 5884 | "received\n", vha->vp_idx); |
| 5885 | } |
| 5886 | break; |
| 5887 | |
| 5888 | default: |
| 5889 | ql_dbg(ql_dbg_tgt, vha, 0xe065, |
| 5890 | "qla_target(%d): Received unknown response pkt " |
| 5891 | "type %x\n", vha->vp_idx, pkt->entry_type); |
| 5892 | break; |
| 5893 | } |
| 5894 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5895 | } |
| 5896 | |
| 5897 | /* |
| 5898 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5899 | */ |
| 5900 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, |
| 5901 | uint16_t *mailbox) |
| 5902 | { |
| 5903 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5904 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5905 | int login_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5906 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 5907 | if (!tgt || tgt->tgt_stop || tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5908 | return; |
| 5909 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5910 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && |
| 5911 | IS_QLA2100(ha)) |
| 5912 | return; |
| 5913 | /* |
| 5914 | * In tgt_stop mode we also should allow all requests to pass. |
| 5915 | * Otherwise, some commands can stuck. |
| 5916 | */ |
| 5917 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5918 | |
| 5919 | switch (code) { |
| 5920 | case MBA_RESET: /* Reset */ |
| 5921 | case MBA_SYSTEM_ERR: /* System Error */ |
| 5922 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 5923 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 5924 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, |
| 5925 | "qla_target(%d): System error async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5926 | "occurred", vha->vp_idx, code); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5927 | break; |
| 5928 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ |
| 5929 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5930 | break; |
| 5931 | |
| 5932 | case MBA_LOOP_UP: |
| 5933 | { |
| 5934 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5935 | "qla_target(%d): Async LOOP_UP occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5936 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5937 | mailbox[0], mailbox[1], mailbox[2], mailbox[3]); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5938 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5939 | qlt_send_notify_ack(ha->base_qpair, |
Bart Van Assche | ab053c0 | 2020-05-18 14:17:09 -0700 | [diff] [blame] | 5940 | &tgt->link_reinit_iocb, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5941 | 0, 0, 0, 0, 0, 0); |
| 5942 | tgt->link_reinit_iocb_pending = 0; |
| 5943 | } |
| 5944 | break; |
| 5945 | } |
| 5946 | |
| 5947 | case MBA_LIP_OCCURRED: |
| 5948 | case MBA_LOOP_DOWN: |
| 5949 | case MBA_LIP_RESET: |
| 5950 | case MBA_RSCN_UPDATE: |
| 5951 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5952 | "qla_target(%d): Async event %#x occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5953 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5954 | mailbox[0], mailbox[1], mailbox[2], mailbox[3]); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5955 | break; |
| 5956 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5957 | case MBA_REJECTED_FCP_CMD: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5958 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017, |
| 5959 | "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", |
| 5960 | vha->vp_idx, |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5961 | mailbox[0], mailbox[1], mailbox[2], mailbox[3]); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5962 | |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5963 | if (mailbox[3] == 1) { |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5964 | /* exchange starvation. */ |
| 5965 | vha->hw->exch_starvation++; |
| 5966 | if (vha->hw->exch_starvation > 5) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5967 | ql_log(ql_log_warn, vha, 0xd03a, |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5968 | "Exchange starvation-. Resetting RISC\n"); |
| 5969 | |
| 5970 | vha->hw->exch_starvation = 0; |
| 5971 | if (IS_P3P_TYPE(vha->hw)) |
| 5972 | set_bit(FCOE_CTX_RESET_NEEDED, |
| 5973 | &vha->dpc_flags); |
| 5974 | else |
| 5975 | set_bit(ISP_ABORT_NEEDED, |
| 5976 | &vha->dpc_flags); |
| 5977 | qla2xxx_wake_dpc(vha); |
| 5978 | } |
| 5979 | } |
| 5980 | break; |
| 5981 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5982 | case MBA_PORT_UPDATE: |
| 5983 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, |
| 5984 | "qla_target(%d): Port update async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5985 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5986 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5987 | mailbox[0], mailbox[1], mailbox[2], mailbox[3]); |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5988 | |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 5989 | login_code = mailbox[2]; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5990 | if (login_code == 0x4) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5991 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
| 5992 | "Async MB 2: Got PLOGI Complete\n"); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5993 | vha->hw->exch_starvation = 0; |
| 5994 | } else if (login_code == 0x7) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5995 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
| 5996 | "Async MB 2: Port Logged Out\n"); |
| 5997 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5998 | default: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5999 | break; |
| 6000 | } |
| 6001 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6002 | } |
| 6003 | |
| 6004 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, |
| 6005 | uint16_t loop_id) |
| 6006 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6007 | fc_port_t *fcport, *tfcp, *del; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6008 | int rc; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6009 | unsigned long flags; |
| 6010 | u8 newfcport = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6011 | |
Quinn Tran | 063b36d | 2017-12-04 14:45:10 -0800 | [diff] [blame] | 6012 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6013 | if (!fcport) { |
| 6014 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, |
| 6015 | "qla_target(%d): Allocation of tmp FC port failed", |
| 6016 | vha->vp_idx); |
| 6017 | return NULL; |
| 6018 | } |
| 6019 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6020 | fcport->loop_id = loop_id; |
| 6021 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 6022 | rc = qla24xx_gpdb_wait(vha, fcport, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6023 | if (rc != QLA_SUCCESS) { |
| 6024 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, |
| 6025 | "qla_target(%d): Failed to retrieve fcport " |
| 6026 | "information -- get_port_database() returned %x " |
| 6027 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); |
| 6028 | kfree(fcport); |
| 6029 | return NULL; |
| 6030 | } |
| 6031 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6032 | del = NULL; |
| 6033 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 6034 | tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1); |
| 6035 | |
| 6036 | if (tfcp) { |
| 6037 | tfcp->d_id = fcport->d_id; |
| 6038 | tfcp->port_type = fcport->port_type; |
| 6039 | tfcp->supported_classes = fcport->supported_classes; |
| 6040 | tfcp->flags |= fcport->flags; |
Quinn Tran | 76f9a2d | 2017-12-04 14:45:11 -0800 | [diff] [blame] | 6041 | tfcp->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6042 | |
| 6043 | del = fcport; |
| 6044 | fcport = tfcp; |
| 6045 | } else { |
| 6046 | if (vha->hw->current_topology == ISP_CFG_F) |
| 6047 | fcport->flags |= FCF_FABRIC_DEVICE; |
| 6048 | |
| 6049 | list_add_tail(&fcport->list, &vha->vp_fcports); |
| 6050 | if (!IS_SW_RESV_ADDR(fcport->d_id)) |
| 6051 | vha->fcport_count++; |
| 6052 | fcport->login_gen++; |
Shyam Sundar | 27258a5 | 2019-12-17 14:06:06 -0800 | [diff] [blame] | 6053 | qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6054 | fcport->login_succ = 1; |
| 6055 | newfcport = 1; |
| 6056 | } |
| 6057 | |
| 6058 | fcport->deleted = 0; |
| 6059 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 6060 | |
| 6061 | switch (vha->host->active_mode) { |
| 6062 | case MODE_INITIATOR: |
| 6063 | case MODE_DUAL: |
| 6064 | if (newfcport) { |
| 6065 | if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) { |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 6066 | qla24xx_sched_upd_fcport(fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6067 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6068 | ql_dbg(ql_dbg_disc, vha, 0x20ff, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6069 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 6070 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 6071 | qla24xx_post_gpsc_work(vha, fcport); |
| 6072 | } |
| 6073 | } |
| 6074 | break; |
| 6075 | |
| 6076 | case MODE_TARGET: |
| 6077 | default: |
| 6078 | break; |
| 6079 | } |
| 6080 | if (del) |
| 6081 | qla2x00_free_fcport(del); |
| 6082 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6083 | return fcport; |
| 6084 | } |
| 6085 | |
| 6086 | /* Must be called under tgt_mutex */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6087 | 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] | 6088 | be_id_t s_id) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6089 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6090 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6091 | fc_port_t *fcport = NULL; |
| 6092 | int rc, global_resets; |
| 6093 | uint16_t loop_id = 0; |
| 6094 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6095 | if (s_id.domain == 0xFF && s_id.area == 0xFC) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6096 | /* |
| 6097 | * This is Domain Controller, so it should be |
| 6098 | * OK to drop SCSI commands from it. |
| 6099 | */ |
| 6100 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, |
| 6101 | "Unable to find initiator with S_ID %x:%x:%x", |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6102 | s_id.domain, s_id.area, s_id.al_pa); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6103 | return NULL; |
| 6104 | } |
| 6105 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6106 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 6107 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6108 | retry: |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6109 | global_resets = |
| 6110 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6111 | |
| 6112 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); |
| 6113 | if (rc != 0) { |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6114 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 6115 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6116 | ql_log(ql_log_info, vha, 0xf071, |
| 6117 | "qla_target(%d): Unable to find " |
| 6118 | "initiator with S_ID %x:%x:%x", |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6119 | 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] | 6120 | |
| 6121 | if (rc == -ENOENT) { |
| 6122 | qlt_port_logo_t logo; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 6123 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6124 | logo.id = be_to_port_id(s_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6125 | logo.cmd_count = 1; |
| 6126 | qlt_send_first_logo(vha, &logo); |
| 6127 | } |
| 6128 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6129 | return NULL; |
| 6130 | } |
| 6131 | |
| 6132 | fcport = qlt_get_port_database(vha, loop_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6133 | if (!fcport) { |
| 6134 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6135 | return NULL; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6136 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6137 | |
| 6138 | if (global_resets != |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6139 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6140 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
| 6141 | "qla_target(%d): global reset during session discovery " |
| 6142 | "(counter was %d, new %d), retrying", vha->vp_idx, |
| 6143 | global_resets, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6144 | atomic_read(&vha->vha_tgt. |
| 6145 | qla_tgt->tgt_global_resets_count)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6146 | goto retry; |
| 6147 | } |
| 6148 | |
| 6149 | sess = qlt_create_sess(vha, fcport, true); |
| 6150 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6151 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 6152 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6153 | return sess; |
| 6154 | } |
| 6155 | |
| 6156 | static void qlt_abort_work(struct qla_tgt *tgt, |
| 6157 | struct qla_tgt_sess_work_param *prm) |
| 6158 | { |
| 6159 | struct scsi_qla_host *vha = tgt->vha; |
| 6160 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6161 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6162 | unsigned long flags = 0, flags2 = 0; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6163 | be_id_t s_id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6164 | int rc; |
| 6165 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6166 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6167 | |
| 6168 | if (tgt->tgt_stop) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6169 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6170 | |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6171 | 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] | 6172 | |
Bart Van Assche | ac452b8 | 2019-08-08 20:01:40 -0700 | [diff] [blame] | 6173 | 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] | 6174 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6175 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6176 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6177 | sess = qlt_make_local_sess(vha, s_id); |
| 6178 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 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 | if (!sess) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6182 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6183 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6184 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6185 | sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6186 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6187 | } |
| 6188 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6189 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6190 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6191 | "%s: kref_get fail %8phC \n", |
| 6192 | __func__, sess->port_name); |
| 6193 | sess = NULL; |
| 6194 | goto out_term2; |
| 6195 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6196 | } |
| 6197 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6198 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6199 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 6200 | |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 6201 | ha->tgt.tgt_ops->put_sess(sess); |
| 6202 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6203 | if (rc != 0) |
| 6204 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6205 | return; |
| 6206 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6207 | out_term2: |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 6208 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 6209 | |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6210 | out_term: |
| 6211 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6212 | qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts, |
| 6213 | FCP_TMF_REJECTED, false); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6214 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6215 | } |
| 6216 | |
| 6217 | static void qlt_tmr_work(struct qla_tgt *tgt, |
| 6218 | struct qla_tgt_sess_work_param *prm) |
| 6219 | { |
| 6220 | struct atio_from_isp *a = &prm->tm_iocb2; |
| 6221 | struct scsi_qla_host *vha = tgt->vha; |
| 6222 | struct qla_hw_data *ha = vha->hw; |
Colin Ian King | bb6abdd | 2019-02-15 09:52:32 +0000 | [diff] [blame] | 6223 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6224 | unsigned long flags; |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6225 | be_id_t s_id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6226 | int rc; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6227 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 6228 | int fn; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6229 | void *iocb; |
| 6230 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6231 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6232 | |
| 6233 | if (tgt->tgt_stop) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6234 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6235 | |
| 6236 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; |
| 6237 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 6238 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6239 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6240 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6241 | sess = qlt_make_local_sess(vha, s_id); |
| 6242 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6243 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6244 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6245 | if (!sess) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6246 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6247 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6248 | if (sess->deleted) { |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6249 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6250 | } |
| 6251 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6252 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6253 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6254 | "%s: kref_get fail %8phC\n", |
| 6255 | __func__, sess->port_name); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6256 | goto out_term2; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6257 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | iocb = a; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6261 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6262 | unpacked_lun = |
| 6263 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6264 | |
| 6265 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6266 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 6267 | |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 6268 | ha->tgt.tgt_ops->put_sess(sess); |
| 6269 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6270 | if (rc != 0) |
| 6271 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6272 | return; |
| 6273 | |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6274 | out_term2: |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6275 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6276 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6277 | 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] | 6278 | } |
| 6279 | |
| 6280 | static void qlt_sess_work_fn(struct work_struct *work) |
| 6281 | { |
| 6282 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); |
| 6283 | struct scsi_qla_host *vha = tgt->vha; |
| 6284 | unsigned long flags; |
| 6285 | |
| 6286 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); |
| 6287 | |
| 6288 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6289 | while (!list_empty(&tgt->sess_works_list)) { |
| 6290 | struct qla_tgt_sess_work_param *prm = list_entry( |
| 6291 | tgt->sess_works_list.next, typeof(*prm), |
| 6292 | sess_works_list_entry); |
| 6293 | |
| 6294 | /* |
| 6295 | * This work can be scheduled on several CPUs at time, so we |
| 6296 | * must delete the entry to eliminate double processing |
| 6297 | */ |
| 6298 | list_del(&prm->sess_works_list_entry); |
| 6299 | |
| 6300 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6301 | |
| 6302 | switch (prm->type) { |
| 6303 | case QLA_TGT_SESS_WORK_ABORT: |
| 6304 | qlt_abort_work(tgt, prm); |
| 6305 | break; |
| 6306 | case QLA_TGT_SESS_WORK_TM: |
| 6307 | qlt_tmr_work(tgt, prm); |
| 6308 | break; |
| 6309 | default: |
| 6310 | BUG_ON(1); |
| 6311 | break; |
| 6312 | } |
| 6313 | |
| 6314 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6315 | |
| 6316 | kfree(prm); |
| 6317 | } |
| 6318 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6319 | } |
| 6320 | |
| 6321 | /* Must be called under tgt_host_action_mutex */ |
| 6322 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) |
| 6323 | { |
| 6324 | struct qla_tgt *tgt; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6325 | int rc, i; |
| 6326 | struct qla_qpair_hint *h; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6327 | |
| 6328 | if (!QLA_TGT_MODE_ENABLED()) |
| 6329 | return 0; |
| 6330 | |
Arun Easi | 33c36c0 | 2013-01-30 03:34:41 -0500 | [diff] [blame] | 6331 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
| 6332 | ql_log(ql_log_warn, base_vha, 0xe070, |
| 6333 | "This adapter does not support target mode.\n"); |
| 6334 | return 0; |
| 6335 | } |
| 6336 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6337 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6338 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6339 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6340 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6341 | |
| 6342 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); |
| 6343 | if (!tgt) { |
| 6344 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, |
| 6345 | "Unable to allocate struct qla_tgt\n"); |
| 6346 | return -ENOMEM; |
| 6347 | } |
| 6348 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6349 | tgt->qphints = kcalloc(ha->max_qpairs + 1, |
| 6350 | sizeof(struct qla_qpair_hint), |
| 6351 | GFP_KERNEL); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6352 | if (!tgt->qphints) { |
| 6353 | kfree(tgt); |
| 6354 | ql_log(ql_log_warn, base_vha, 0x0197, |
| 6355 | "Unable to allocate qpair hints.\n"); |
| 6356 | return -ENOMEM; |
| 6357 | } |
| 6358 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6359 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) |
| 6360 | base_vha->host->hostt->supported_mode |= MODE_TARGET; |
| 6361 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6362 | rc = btree_init64(&tgt->lun_qpair_map); |
| 6363 | if (rc) { |
| 6364 | kfree(tgt->qphints); |
| 6365 | kfree(tgt); |
| 6366 | ql_log(ql_log_info, base_vha, 0x0198, |
| 6367 | "Unable to initialize lun_qpair_map btree\n"); |
| 6368 | return -EIO; |
| 6369 | } |
| 6370 | h = &tgt->qphints[0]; |
| 6371 | h->qpair = ha->base_qpair; |
| 6372 | INIT_LIST_HEAD(&h->hint_elem); |
| 6373 | h->cpuid = ha->base_qpair->cpuid; |
| 6374 | list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list); |
| 6375 | |
| 6376 | for (i = 0; i < ha->max_qpairs; i++) { |
| 6377 | unsigned long flags; |
| 6378 | |
| 6379 | struct qla_qpair *qpair = ha->queue_pair_map[i]; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 6380 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6381 | h = &tgt->qphints[i + 1]; |
| 6382 | INIT_LIST_HEAD(&h->hint_elem); |
| 6383 | if (qpair) { |
| 6384 | h->qpair = qpair; |
| 6385 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 6386 | list_add_tail(&h->hint_elem, &qpair->hints_list); |
| 6387 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
| 6388 | h->cpuid = qpair->cpuid; |
| 6389 | } |
| 6390 | } |
| 6391 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6392 | tgt->ha = ha; |
| 6393 | tgt->vha = base_vha; |
| 6394 | init_waitqueue_head(&tgt->waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6395 | INIT_LIST_HEAD(&tgt->del_sess_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6396 | spin_lock_init(&tgt->sess_work_lock); |
| 6397 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); |
| 6398 | INIT_LIST_HEAD(&tgt->sess_works_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6399 | atomic_set(&tgt->tgt_global_resets_count, 0); |
| 6400 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6401 | base_vha->vha_tgt.qla_tgt = tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6402 | |
| 6403 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, |
| 6404 | "qla_target(%d): using 64 Bit PCI addressing", |
| 6405 | base_vha->vp_idx); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6406 | /* 3 is reserved */ |
| 6407 | 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] | 6408 | |
| 6409 | mutex_lock(&qla_tgt_mutex); |
| 6410 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); |
| 6411 | mutex_unlock(&qla_tgt_mutex); |
| 6412 | |
Quinn Tran | f1443ee | 2017-03-15 09:48:51 -0700 | [diff] [blame] | 6413 | if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target) |
| 6414 | ha->tgt.tgt_ops->add_target(base_vha); |
| 6415 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6416 | return 0; |
| 6417 | } |
| 6418 | |
| 6419 | /* Must be called under tgt_host_action_mutex */ |
| 6420 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) |
| 6421 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6422 | if (!vha->vha_tgt.qla_tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6423 | return 0; |
| 6424 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6425 | if (vha->fc_vport) { |
| 6426 | qlt_release(vha->vha_tgt.qla_tgt); |
| 6427 | return 0; |
| 6428 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 6429 | |
| 6430 | /* free left over qfull cmds */ |
| 6431 | qlt_init_term_exchange(vha); |
| 6432 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6433 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", |
| 6434 | vha->host_no, ha); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6435 | qlt_release(vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6436 | |
| 6437 | return 0; |
| 6438 | } |
| 6439 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6440 | void qlt_remove_target_resources(struct qla_hw_data *ha) |
| 6441 | { |
| 6442 | struct scsi_qla_host *node; |
| 6443 | u32 key = 0; |
| 6444 | |
| 6445 | btree_for_each_safe32(&ha->tgt.host_map, key, node) |
| 6446 | btree_remove32(&ha->tgt.host_map, key); |
| 6447 | |
| 6448 | btree_destroy32(&ha->tgt.host_map); |
| 6449 | } |
| 6450 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6451 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, |
| 6452 | unsigned char *b) |
| 6453 | { |
Bart Van Assche | 0943491 | 2019-08-08 20:01:36 -0700 | [diff] [blame] | 6454 | pr_debug("qla2xxx HW vha->node_name: %8phC\n", vha->node_name); |
| 6455 | pr_debug("qla2xxx HW vha->port_name: %8phC\n", vha->port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6456 | put_unaligned_be64(wwpn, b); |
Bart Van Assche | 0943491 | 2019-08-08 20:01:36 -0700 | [diff] [blame] | 6457 | pr_debug("qla2xxx passed configfs WWPN: %8phC\n", b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6458 | } |
| 6459 | |
| 6460 | /** |
| 6461 | * qla_tgt_lport_register - register lport with external module |
| 6462 | * |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6463 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data |
Bart Van Assche | 807eb90 | 2018-10-18 15:45:41 -0700 | [diff] [blame] | 6464 | * @phys_wwpn: physical port WWPN |
| 6465 | * @npiv_wwpn: NPIV WWPN |
| 6466 | * @npiv_wwnn: NPIV WWNN |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 6467 | * @callback: lport initialization callback for tcm_qla2xxx code |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6468 | */ |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6469 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
| 6470 | u64 npiv_wwpn, u64 npiv_wwnn, |
| 6471 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6472 | { |
| 6473 | struct qla_tgt *tgt; |
| 6474 | struct scsi_qla_host *vha; |
| 6475 | struct qla_hw_data *ha; |
| 6476 | struct Scsi_Host *host; |
| 6477 | unsigned long flags; |
| 6478 | int rc; |
| 6479 | u8 b[WWN_SIZE]; |
| 6480 | |
| 6481 | mutex_lock(&qla_tgt_mutex); |
| 6482 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { |
| 6483 | vha = tgt->vha; |
| 6484 | ha = vha->hw; |
| 6485 | |
| 6486 | host = vha->host; |
| 6487 | if (!host) |
| 6488 | continue; |
| 6489 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6490 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
| 6491 | continue; |
| 6492 | |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6493 | if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED) |
| 6494 | continue; |
| 6495 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6496 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6497 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6498 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
| 6499 | host->host_no); |
| 6500 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6501 | continue; |
| 6502 | } |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6503 | if (tgt->tgt_stop) { |
| 6504 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", |
| 6505 | host->host_no); |
| 6506 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6507 | continue; |
| 6508 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6509 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6510 | |
| 6511 | if (!scsi_host_get(host)) { |
| 6512 | ql_dbg(ql_dbg_tgt, vha, 0xe068, |
| 6513 | "Unable to scsi_host_get() for" |
| 6514 | " qla2xxx scsi_host\n"); |
| 6515 | continue; |
| 6516 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6517 | qlt_lport_dump(vha, phys_wwpn, b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6518 | |
| 6519 | if (memcmp(vha->port_name, b, WWN_SIZE)) { |
| 6520 | scsi_host_put(host); |
| 6521 | continue; |
| 6522 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6523 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
| 6524 | if (rc != 0) |
| 6525 | scsi_host_put(host); |
| 6526 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6527 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6528 | return rc; |
| 6529 | } |
| 6530 | mutex_unlock(&qla_tgt_mutex); |
| 6531 | |
| 6532 | return -ENODEV; |
| 6533 | } |
| 6534 | EXPORT_SYMBOL(qlt_lport_register); |
| 6535 | |
| 6536 | /** |
| 6537 | * qla_tgt_lport_deregister - Degister lport |
| 6538 | * |
| 6539 | * @vha: Registered scsi_qla_host pointer |
| 6540 | */ |
| 6541 | void qlt_lport_deregister(struct scsi_qla_host *vha) |
| 6542 | { |
| 6543 | struct qla_hw_data *ha = vha->hw; |
| 6544 | struct Scsi_Host *sh = vha->host; |
| 6545 | /* |
| 6546 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data |
| 6547 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6548 | vha->vha_tgt.target_lport_ptr = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6549 | ha->tgt.tgt_ops = NULL; |
| 6550 | /* |
| 6551 | * Release the Scsi_Host reference for the underlying qla2xxx host |
| 6552 | */ |
| 6553 | scsi_host_put(sh); |
| 6554 | } |
| 6555 | EXPORT_SYMBOL(qlt_lport_deregister); |
| 6556 | |
| 6557 | /* Must be called under HW lock */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6558 | void qlt_set_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6559 | { |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6560 | switch (vha->qlini_mode) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6561 | case QLA2XXX_INI_MODE_DISABLED: |
| 6562 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6563 | vha->host->active_mode = MODE_TARGET; |
| 6564 | break; |
| 6565 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6566 | vha->host->active_mode = MODE_INITIATOR; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6567 | break; |
| 6568 | case QLA2XXX_INI_MODE_DUAL: |
| 6569 | vha->host->active_mode = MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6570 | break; |
| 6571 | default: |
| 6572 | break; |
| 6573 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6574 | } |
| 6575 | |
| 6576 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6577 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6578 | { |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6579 | switch (vha->qlini_mode) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6580 | case QLA2XXX_INI_MODE_DISABLED: |
| 6581 | vha->host->active_mode = MODE_UNKNOWN; |
| 6582 | break; |
| 6583 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6584 | vha->host->active_mode = MODE_INITIATOR; |
| 6585 | break; |
| 6586 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6587 | case QLA2XXX_INI_MODE_DUAL: |
| 6588 | vha->host->active_mode = MODE_INITIATOR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6589 | break; |
| 6590 | default: |
| 6591 | break; |
| 6592 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6593 | } |
| 6594 | |
| 6595 | /* |
| 6596 | * qla_tgt_enable_vha - NO LOCK HELD |
| 6597 | * |
| 6598 | * host_reset, bring up w/ Target Mode Enabled |
| 6599 | */ |
| 6600 | void |
| 6601 | qlt_enable_vha(struct scsi_qla_host *vha) |
| 6602 | { |
| 6603 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6604 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6605 | unsigned long flags; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6606 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6607 | |
| 6608 | if (!tgt) { |
| 6609 | ql_dbg(ql_dbg_tgt, vha, 0xe069, |
| 6610 | "Unable to locate qla_tgt pointer from" |
| 6611 | " struct qla_hw_data\n"); |
| 6612 | dump_stack(); |
| 6613 | return; |
| 6614 | } |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6615 | if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED) |
| 6616 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6617 | |
Quinn Tran | 178235f | 2019-07-26 09:07:29 -0700 | [diff] [blame] | 6618 | if (ha->tgt.num_act_qpairs > ha->max_qpairs) |
| 6619 | ha->tgt.num_act_qpairs = ha->max_qpairs; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6620 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6621 | tgt->tgt_stopped = 0; |
| 6622 | qlt_set_mode(vha); |
| 6623 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6624 | |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 6625 | mutex_lock(&ha->optrom_mutex); |
| 6626 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021, |
| 6627 | "%s.\n", __func__); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6628 | if (vha->vp_idx) { |
| 6629 | qla24xx_disable_vp(vha); |
| 6630 | qla24xx_enable_vp(vha); |
| 6631 | } else { |
| 6632 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 6633 | qla2xxx_wake_dpc(base_vha); |
Bart Van Assche | e6803ef | 2019-08-08 20:01:52 -0700 | [diff] [blame] | 6634 | WARN_ON_ONCE(qla2x00_wait_for_hba_online(base_vha) != |
| 6635 | QLA_SUCCESS); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6636 | } |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 6637 | mutex_unlock(&ha->optrom_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6638 | } |
| 6639 | EXPORT_SYMBOL(qlt_enable_vha); |
| 6640 | |
| 6641 | /* |
| 6642 | * qla_tgt_disable_vha - NO LOCK HELD |
| 6643 | * |
| 6644 | * Disable Target Mode and reset the adapter |
| 6645 | */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6646 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6647 | { |
| 6648 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6649 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6650 | unsigned long flags; |
| 6651 | |
| 6652 | if (!tgt) { |
| 6653 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, |
| 6654 | "Unable to locate qla_tgt pointer from" |
| 6655 | " struct qla_hw_data\n"); |
| 6656 | dump_stack(); |
| 6657 | return; |
| 6658 | } |
| 6659 | |
| 6660 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6661 | qlt_clear_mode(vha); |
| 6662 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6663 | |
| 6664 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6665 | qla2xxx_wake_dpc(vha); |
Viacheslav Dubeyko | 6b3d16f | 2020-04-22 13:51:51 +0300 | [diff] [blame] | 6666 | |
| 6667 | /* |
| 6668 | * We are expecting the offline state. |
| 6669 | * QLA_FUNCTION_FAILED means that adapter is offline. |
| 6670 | */ |
Bart Van Assche | e6803ef | 2019-08-08 20:01:52 -0700 | [diff] [blame] | 6671 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) |
| 6672 | ql_dbg(ql_dbg_tgt, vha, 0xe081, |
Viacheslav Dubeyko | 6b3d16f | 2020-04-22 13:51:51 +0300 | [diff] [blame] | 6673 | "adapter is offline\n"); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6674 | } |
| 6675 | |
| 6676 | /* |
| 6677 | * Called from qla_init.c:qla24xx_vport_create() contex to setup |
| 6678 | * the target mode specific struct scsi_qla_host and struct qla_hw_data |
| 6679 | * members. |
| 6680 | */ |
| 6681 | void |
| 6682 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) |
| 6683 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6684 | vha->vha_tgt.qla_tgt = NULL; |
| 6685 | |
| 6686 | mutex_init(&vha->vha_tgt.tgt_mutex); |
| 6687 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6688 | |
| 6689 | qlt_clear_mode(vha); |
| 6690 | |
| 6691 | /* |
| 6692 | * NOTE: Currently the value is kept the same for <24xx and |
| 6693 | * >=24xx ISPs. If it is necessary to change it, |
| 6694 | * the check should be added for specific ISPs, |
| 6695 | * assigning the value appropriately. |
| 6696 | */ |
| 6697 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6698 | |
| 6699 | qlt_add_target(ha, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6700 | } |
| 6701 | |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6702 | u8 |
| 6703 | qlt_rff_id(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6704 | { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6705 | u8 fc4_feature = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6706 | /* |
| 6707 | * FC-4 Feature bit 0 indicates target functionality to the name server. |
| 6708 | */ |
| 6709 | if (qla_tgt_mode_enabled(vha)) { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6710 | fc4_feature = BIT_0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6711 | } else if (qla_ini_mode_enabled(vha)) { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6712 | fc4_feature = BIT_1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6713 | } else if (qla_dual_mode_enabled(vha)) |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6714 | fc4_feature = BIT_0 | BIT_1; |
| 6715 | |
| 6716 | return fc4_feature; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6717 | } |
| 6718 | |
| 6719 | /* |
| 6720 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. |
| 6721 | * @ha: HA context |
| 6722 | * |
| 6723 | * Beginning of ATIO ring has initialization control block already built |
| 6724 | * by nvram config routine. |
| 6725 | * |
| 6726 | * Returns 0 on success. |
| 6727 | */ |
| 6728 | void |
| 6729 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) |
| 6730 | { |
| 6731 | struct qla_hw_data *ha = vha->hw; |
| 6732 | uint16_t cnt; |
| 6733 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; |
| 6734 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6735 | if (qla_ini_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6736 | return; |
| 6737 | |
| 6738 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 6739 | pkt->u.raw.signature = cpu_to_le32(ATIO_PROCESSED); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6740 | pkt++; |
| 6741 | } |
| 6742 | |
| 6743 | } |
| 6744 | |
| 6745 | /* |
| 6746 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. |
| 6747 | * @ha: SCSI driver HA context |
| 6748 | */ |
| 6749 | void |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6750 | 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] | 6751 | { |
| 6752 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6753 | struct atio_from_isp *pkt; |
| 6754 | int cnt, i; |
| 6755 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6756 | if (!ha->flags.fw_started) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6757 | return; |
| 6758 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6759 | while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) || |
| 6760 | fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6761 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6762 | cnt = pkt->u.raw.entry_count; |
| 6763 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6764 | if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) { |
| 6765 | /* |
| 6766 | * This packet is corrupted. The header + payload |
| 6767 | * can not be trusted. There is no point in passing |
| 6768 | * it further up. |
| 6769 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6770 | ql_log(ql_log_warn, vha, 0xd03c, |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6771 | "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n", |
Bart Van Assche | df95f39 | 2019-08-08 20:01:58 -0700 | [diff] [blame] | 6772 | &pkt->u.isp24.fcp_hdr.s_id, |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6773 | be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id), |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 6774 | pkt->u.isp24.exchange_addr, pkt); |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6775 | |
| 6776 | adjust_corrupted_atio(pkt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6777 | qlt_send_term_exchange(ha->base_qpair, NULL, pkt, |
| 6778 | ha_locked, 0); |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6779 | } else { |
| 6780 | qlt_24xx_atio_pkt_all_vps(vha, |
| 6781 | (struct atio_from_isp *)pkt, ha_locked); |
| 6782 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6783 | |
| 6784 | for (i = 0; i < cnt; i++) { |
| 6785 | ha->tgt.atio_ring_index++; |
| 6786 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { |
| 6787 | ha->tgt.atio_ring_index = 0; |
| 6788 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 6789 | } else |
| 6790 | ha->tgt.atio_ring_ptr++; |
| 6791 | |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 6792 | pkt->u.raw.signature = cpu_to_le32(ATIO_PROCESSED); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6793 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6794 | } |
| 6795 | wmb(); |
| 6796 | } |
| 6797 | |
| 6798 | /* Adjust ring index */ |
Bart Van Assche | 04474d3 | 2020-05-18 14:17:08 -0700 | [diff] [blame] | 6799 | 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] | 6800 | } |
| 6801 | |
| 6802 | void |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6803 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6804 | { |
| 6805 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6806 | struct qla_msix_entry *msix = &ha->msix_entries[2]; |
| 6807 | struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb; |
| 6808 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6809 | if (!QLA_TGT_MODE_ENABLED()) |
| 6810 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6811 | |
Bart Van Assche | 04474d3 | 2020-05-18 14:17:08 -0700 | [diff] [blame] | 6812 | wrt_reg_dword(ISP_ATIO_Q_IN(vha), 0); |
| 6813 | wrt_reg_dword(ISP_ATIO_Q_OUT(vha), 0); |
| 6814 | rd_reg_dword(ISP_ATIO_Q_OUT(vha)); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6815 | |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6816 | if (ha->flags.msix_enabled) { |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 6817 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) { |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6818 | if (IS_QLA2071(ha)) { |
| 6819 | /* 4 ports Baker: Enable Interrupt Handshake */ |
| 6820 | icb->msix_atio = 0; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 6821 | icb->firmware_options_2 |= cpu_to_le32(BIT_26); |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6822 | } else { |
| 6823 | icb->msix_atio = cpu_to_le16(msix->entry); |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 6824 | icb->firmware_options_2 &= cpu_to_le32(~BIT_26); |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6825 | } |
| 6826 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6827 | "Registering ICB vector 0x%x for atio que.\n", |
| 6828 | msix->entry); |
| 6829 | } |
| 6830 | } else { |
| 6831 | /* INTx|MSI */ |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 6832 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) { |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6833 | icb->msix_atio = 0; |
Bart Van Assche | 7ffa5b9 | 2020-05-18 14:17:12 -0700 | [diff] [blame] | 6834 | icb->firmware_options_2 |= cpu_to_le32(BIT_26); |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6835 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6836 | "%s: Use INTx for ATIOQ.\n", __func__); |
| 6837 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6838 | } |
| 6839 | } |
| 6840 | |
| 6841 | void |
| 6842 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) |
| 6843 | { |
| 6844 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6845 | u32 tmp; |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6846 | |
| 6847 | if (!QLA_TGT_MODE_ENABLED()) |
| 6848 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6849 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6850 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6851 | if (!ha->tgt.saved_set) { |
| 6852 | /* We save only once */ |
| 6853 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6854 | ha->tgt.saved_firmware_options_1 = |
| 6855 | nv->firmware_options_1; |
| 6856 | ha->tgt.saved_firmware_options_2 = |
| 6857 | nv->firmware_options_2; |
| 6858 | ha->tgt.saved_firmware_options_3 = |
| 6859 | nv->firmware_options_3; |
| 6860 | ha->tgt.saved_set = 1; |
| 6861 | } |
| 6862 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6863 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6864 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6865 | else /* dual */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6866 | nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6867 | |
| 6868 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6869 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6870 | |
| 6871 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6872 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6873 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6874 | |
| 6875 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6876 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6877 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6878 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6879 | if (ql2xtgt_tape_enable) |
| 6880 | /* Enable FC Tape support */ |
| 6881 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6882 | else |
| 6883 | /* Disable FC Tape support */ |
| 6884 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6885 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6886 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6887 | nv->host_p &= cpu_to_le32(~BIT_10); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6888 | |
| 6889 | /* |
| 6890 | * clear BIT 15 explicitly as we have seen at least |
| 6891 | * a couple of instances where this was set and this |
| 6892 | * was causing the firmware to not be initialized. |
| 6893 | */ |
| 6894 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6895 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6896 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6897 | |
| 6898 | if (IS_QLA25XX(ha)) { |
| 6899 | /* Change Loop-prefer to Pt-Pt */ |
| 6900 | tmp = ~(BIT_4|BIT_5|BIT_6); |
| 6901 | nv->firmware_options_2 &= cpu_to_le32(tmp); |
| 6902 | tmp = P2P << 4; |
| 6903 | nv->firmware_options_2 |= cpu_to_le32(tmp); |
| 6904 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6905 | } else { |
| 6906 | if (ha->tgt.saved_set) { |
| 6907 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6908 | nv->firmware_options_1 = |
| 6909 | ha->tgt.saved_firmware_options_1; |
| 6910 | nv->firmware_options_2 = |
| 6911 | ha->tgt.saved_firmware_options_2; |
| 6912 | nv->firmware_options_3 = |
| 6913 | ha->tgt.saved_firmware_options_3; |
| 6914 | } |
| 6915 | return; |
| 6916 | } |
| 6917 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6918 | if (ha->base_qpair->enable_class_2) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6919 | if (vha->flags.init_done) |
| 6920 | fc_host_supported_classes(vha->host) = |
| 6921 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6922 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6923 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6924 | } else { |
| 6925 | if (vha->flags.init_done) |
| 6926 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6927 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6928 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6929 | } |
| 6930 | } |
| 6931 | |
| 6932 | void |
| 6933 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6934 | struct init_cb_24xx *icb) |
| 6935 | { |
| 6936 | struct qla_hw_data *ha = vha->hw; |
| 6937 | |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6938 | if (!QLA_TGT_MODE_ENABLED()) |
| 6939 | return; |
| 6940 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6941 | if (ha->tgt.node_name_set) { |
| 6942 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6943 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6944 | } |
| 6945 | } |
| 6946 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6947 | void |
| 6948 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) |
| 6949 | { |
| 6950 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6951 | u32 tmp; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6952 | |
| 6953 | if (!QLA_TGT_MODE_ENABLED()) |
| 6954 | return; |
| 6955 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6956 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6957 | if (!ha->tgt.saved_set) { |
| 6958 | /* We save only once */ |
| 6959 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6960 | ha->tgt.saved_firmware_options_1 = |
| 6961 | nv->firmware_options_1; |
| 6962 | ha->tgt.saved_firmware_options_2 = |
| 6963 | nv->firmware_options_2; |
| 6964 | ha->tgt.saved_firmware_options_3 = |
| 6965 | nv->firmware_options_3; |
| 6966 | ha->tgt.saved_set = 1; |
| 6967 | } |
| 6968 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6969 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6970 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6971 | else /* dual */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6972 | nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6973 | |
| 6974 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6975 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6976 | |
| 6977 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6978 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6979 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6980 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6981 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6982 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6983 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6984 | /* |
| 6985 | * clear BIT 15 explicitly as we have seen at |
| 6986 | * least a couple of instances where this was set |
| 6987 | * and this was causing the firmware to not be |
| 6988 | * initialized. |
| 6989 | */ |
| 6990 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6991 | if (ql2xtgt_tape_enable) |
| 6992 | /* Enable FC tape support */ |
| 6993 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6994 | else |
| 6995 | /* Disable FC tape support */ |
| 6996 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6997 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6998 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6999 | nv->host_p &= cpu_to_le32(~BIT_10); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7000 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7001 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 7002 | |
| 7003 | /* Change Loop-prefer to Pt-Pt */ |
| 7004 | tmp = ~(BIT_4|BIT_5|BIT_6); |
| 7005 | nv->firmware_options_2 &= cpu_to_le32(tmp); |
| 7006 | tmp = P2P << 4; |
| 7007 | nv->firmware_options_2 |= cpu_to_le32(tmp); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7008 | } else { |
| 7009 | if (ha->tgt.saved_set) { |
| 7010 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 7011 | nv->firmware_options_1 = |
| 7012 | ha->tgt.saved_firmware_options_1; |
| 7013 | nv->firmware_options_2 = |
| 7014 | ha->tgt.saved_firmware_options_2; |
| 7015 | nv->firmware_options_3 = |
| 7016 | ha->tgt.saved_firmware_options_3; |
| 7017 | } |
| 7018 | return; |
| 7019 | } |
| 7020 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7021 | if (ha->base_qpair->enable_class_2) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7022 | if (vha->flags.init_done) |
| 7023 | fc_host_supported_classes(vha->host) = |
| 7024 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 7025 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7026 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7027 | } else { |
| 7028 | if (vha->flags.init_done) |
| 7029 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 7030 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7031 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7032 | } |
| 7033 | } |
| 7034 | |
| 7035 | void |
| 7036 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 7037 | struct init_cb_81xx *icb) |
| 7038 | { |
| 7039 | struct qla_hw_data *ha = vha->hw; |
| 7040 | |
| 7041 | if (!QLA_TGT_MODE_ENABLED()) |
| 7042 | return; |
| 7043 | |
| 7044 | if (ha->tgt.node_name_set) { |
| 7045 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7046 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7047 | } |
| 7048 | } |
| 7049 | |
| 7050 | void |
| 7051 | qlt_83xx_iospace_config(struct qla_hw_data *ha) |
| 7052 | { |
| 7053 | if (!QLA_TGT_MODE_ENABLED()) |
| 7054 | return; |
| 7055 | |
| 7056 | ha->msix_count += 1; /* For ATIO Q */ |
| 7057 | } |
| 7058 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7059 | |
| 7060 | void |
| 7061 | qlt_modify_vp_config(struct scsi_qla_host *vha, |
| 7062 | struct vp_config_entry_24xx *vpmod) |
| 7063 | { |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7064 | /* enable target mode. Bit5 = 1 => disable */ |
| 7065 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7066 | vpmod->options_idx1 &= ~BIT_5; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 7067 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7068 | /* Disable ini mode, if requested. bit4 = 1 => disable */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 7069 | if (qla_tgt_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7070 | vpmod->options_idx1 &= ~BIT_4; |
| 7071 | } |
| 7072 | |
| 7073 | void |
| 7074 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) |
| 7075 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7076 | int rc; |
| 7077 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7078 | if (!QLA_TGT_MODE_ENABLED()) |
| 7079 | return; |
| 7080 | |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 7081 | if ((ql2xenablemsix == 0) || IS_QLA83XX(ha) || IS_QLA27XX(ha) || |
| 7082 | IS_QLA28XX(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7083 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
| 7084 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; |
| 7085 | } else { |
| 7086 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; |
| 7087 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; |
| 7088 | } |
| 7089 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 7090 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
| 7091 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7092 | |
| 7093 | INIT_LIST_HEAD(&base_vha->unknown_atio_list); |
| 7094 | INIT_DELAYED_WORK(&base_vha->unknown_atio_work, |
| 7095 | qlt_unknown_atio_work_fn); |
| 7096 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7097 | qlt_clear_mode(base_vha); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7098 | |
| 7099 | rc = btree_init32(&ha->tgt.host_map); |
| 7100 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7101 | ql_log(ql_log_info, base_vha, 0xd03d, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7102 | "Unable to initialize ha->host_map btree\n"); |
| 7103 | |
| 7104 | qlt_update_vp_map(base_vha, SET_VP_IDX); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7105 | } |
| 7106 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7107 | irqreturn_t |
| 7108 | qla83xx_msix_atio_q(int irq, void *dev_id) |
| 7109 | { |
| 7110 | struct rsp_que *rsp; |
| 7111 | scsi_qla_host_t *vha; |
| 7112 | struct qla_hw_data *ha; |
| 7113 | unsigned long flags; |
| 7114 | |
| 7115 | rsp = (struct rsp_que *) dev_id; |
| 7116 | ha = rsp->hw; |
| 7117 | vha = pci_get_drvdata(ha->pdev); |
| 7118 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7119 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7120 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7121 | qlt_24xx_process_atio_queue(vha, 0); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7122 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7123 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7124 | |
| 7125 | return IRQ_HANDLED; |
| 7126 | } |
| 7127 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7128 | static void |
| 7129 | qlt_handle_abts_recv_work(struct work_struct *work) |
| 7130 | { |
| 7131 | struct qla_tgt_sess_op *op = container_of(work, |
| 7132 | struct qla_tgt_sess_op, work); |
| 7133 | scsi_qla_host_t *vha = op->vha; |
| 7134 | struct qla_hw_data *ha = vha->hw; |
| 7135 | unsigned long flags; |
| 7136 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7137 | if (qla2x00_reset_active(vha) || |
| 7138 | (op->chip_reset != ha->base_qpair->chip_reset)) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7139 | return; |
| 7140 | |
| 7141 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 7142 | qlt_24xx_process_atio_queue(vha, 0); |
| 7143 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 7144 | |
| 7145 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7146 | qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7147 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | ae940f2 | 2017-03-15 09:48:44 -0700 | [diff] [blame] | 7148 | |
| 7149 | kfree(op); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7150 | } |
| 7151 | |
| 7152 | void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7153 | qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp, |
| 7154 | response_t *pkt) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7155 | { |
| 7156 | struct qla_tgt_sess_op *op; |
| 7157 | |
| 7158 | op = kzalloc(sizeof(*op), GFP_ATOMIC); |
| 7159 | |
| 7160 | if (!op) { |
| 7161 | /* do not reach for ATIO queue here. This is best effort err |
| 7162 | * recovery at this point. |
| 7163 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7164 | qlt_response_pkt_all_vps(vha, rsp, pkt); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7165 | return; |
| 7166 | } |
| 7167 | |
| 7168 | memcpy(&op->atio, pkt, sizeof(*pkt)); |
| 7169 | op->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7170 | op->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7171 | op->rsp = rsp; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7172 | INIT_WORK(&op->work, qlt_handle_abts_recv_work); |
| 7173 | queue_work(qla_tgt_wq, &op->work); |
| 7174 | return; |
| 7175 | } |
| 7176 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7177 | int |
| 7178 | qlt_mem_alloc(struct qla_hw_data *ha) |
| 7179 | { |
| 7180 | if (!QLA_TGT_MODE_ENABLED()) |
| 7181 | return 0; |
| 7182 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7183 | ha->tgt.tgt_vp_map = kcalloc(MAX_MULTI_ID_FABRIC, |
| 7184 | sizeof(struct qla_tgt_vp_map), |
| 7185 | GFP_KERNEL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7186 | if (!ha->tgt.tgt_vp_map) |
| 7187 | return -ENOMEM; |
| 7188 | |
| 7189 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 7190 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), |
| 7191 | &ha->tgt.atio_dma, GFP_KERNEL); |
| 7192 | if (!ha->tgt.atio_ring) { |
| 7193 | kfree(ha->tgt.tgt_vp_map); |
| 7194 | return -ENOMEM; |
| 7195 | } |
| 7196 | return 0; |
| 7197 | } |
| 7198 | |
| 7199 | void |
| 7200 | qlt_mem_free(struct qla_hw_data *ha) |
| 7201 | { |
| 7202 | if (!QLA_TGT_MODE_ENABLED()) |
| 7203 | return; |
| 7204 | |
| 7205 | if (ha->tgt.atio_ring) { |
| 7206 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * |
| 7207 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, |
| 7208 | ha->tgt.atio_dma); |
| 7209 | } |
Bart Van Assche | 5365bf9 | 2019-04-17 14:44:22 -0700 | [diff] [blame] | 7210 | ha->tgt.atio_ring = NULL; |
| 7211 | ha->tgt.atio_dma = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7212 | kfree(ha->tgt.tgt_vp_map); |
Bart Van Assche | 5365bf9 | 2019-04-17 14:44:22 -0700 | [diff] [blame] | 7213 | ha->tgt.tgt_vp_map = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7214 | } |
| 7215 | |
| 7216 | /* vport_slock to be held by the caller */ |
| 7217 | void |
| 7218 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) |
| 7219 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7220 | void *slot; |
| 7221 | u32 key; |
| 7222 | int rc; |
| 7223 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7224 | if (!QLA_TGT_MODE_ENABLED()) |
| 7225 | return; |
| 7226 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7227 | key = vha->d_id.b24; |
| 7228 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7229 | switch (cmd) { |
| 7230 | case SET_VP_IDX: |
| 7231 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; |
| 7232 | break; |
| 7233 | case SET_AL_PA: |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7234 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7235 | if (!slot) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7236 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7237 | "Save vha in host_map %p %06x\n", vha, key); |
| 7238 | rc = btree_insert32(&vha->hw->tgt.host_map, |
| 7239 | key, vha, GFP_ATOMIC); |
| 7240 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7241 | ql_log(ql_log_info, vha, 0xd03e, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7242 | "Unable to insert s_id into host_map: %06x\n", |
| 7243 | key); |
| 7244 | return; |
| 7245 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7246 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019, |
| 7247 | "replace existing vha in host_map %p %06x\n", vha, key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7248 | btree_update32(&vha->hw->tgt.host_map, key, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7249 | break; |
| 7250 | case RESET_VP_IDX: |
| 7251 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; |
| 7252 | break; |
| 7253 | case RESET_AL_PA: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7254 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7255 | "clear vha in host_map %p %06x\n", vha, key); |
| 7256 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7257 | if (slot) |
| 7258 | btree_remove32(&vha->hw->tgt.host_map, key); |
| 7259 | vha->d_id.b24 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7260 | break; |
| 7261 | } |
| 7262 | } |
| 7263 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7264 | void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id) |
| 7265 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7266 | |
| 7267 | if (!vha->d_id.b24) { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7268 | vha->d_id = id; |
| 7269 | qlt_update_vp_map(vha, SET_AL_PA); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7270 | } else if (vha->d_id.b24 != id.b24) { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7271 | qlt_update_vp_map(vha, RESET_AL_PA); |
| 7272 | vha->d_id = id; |
| 7273 | qlt_update_vp_map(vha, SET_AL_PA); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7274 | } |
| 7275 | } |
| 7276 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7277 | static int __init qlt_parse_ini_mode(void) |
| 7278 | { |
| 7279 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) |
| 7280 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
| 7281 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) |
| 7282 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; |
| 7283 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) |
| 7284 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7285 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0) |
| 7286 | ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7287 | else |
| 7288 | return false; |
| 7289 | |
| 7290 | return true; |
| 7291 | } |
| 7292 | |
| 7293 | int __init qlt_init(void) |
| 7294 | { |
| 7295 | int ret; |
| 7296 | |
Bart Van Assche | bc04459 | 2019-04-17 14:44:37 -0700 | [diff] [blame] | 7297 | BUILD_BUG_ON(sizeof(struct ctio7_to_24xx) != 64); |
| 7298 | BUILD_BUG_ON(sizeof(struct ctio_to_2xxx) != 64); |
| 7299 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7300 | if (!qlt_parse_ini_mode()) { |
| 7301 | ql_log(ql_log_fatal, NULL, 0xe06b, |
| 7302 | "qlt_parse_ini_mode() failed\n"); |
| 7303 | return -EINVAL; |
| 7304 | } |
| 7305 | |
| 7306 | if (!QLA_TGT_MODE_ENABLED()) |
| 7307 | return 0; |
| 7308 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7309 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
| 7310 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct |
| 7311 | qla_tgt_mgmt_cmd), 0, NULL); |
| 7312 | if (!qla_tgt_mgmt_cmd_cachep) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7313 | ql_log(ql_log_fatal, NULL, 0xd04b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7314 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 7315 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7316 | } |
| 7317 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7318 | qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep", |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 7319 | sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t), |
| 7320 | 0, NULL); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7321 | |
| 7322 | if (!qla_tgt_plogi_cachep) { |
| 7323 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 7324 | "kmem_cache_create for qla_tgt_plogi_cachep failed\n"); |
| 7325 | ret = -ENOMEM; |
| 7326 | goto out_mgmt_cmd_cachep; |
| 7327 | } |
| 7328 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7329 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, |
| 7330 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); |
| 7331 | if (!qla_tgt_mgmt_cmd_mempool) { |
| 7332 | ql_log(ql_log_fatal, NULL, 0xe06e, |
| 7333 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); |
| 7334 | ret = -ENOMEM; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7335 | goto out_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7336 | } |
| 7337 | |
| 7338 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); |
| 7339 | if (!qla_tgt_wq) { |
| 7340 | ql_log(ql_log_fatal, NULL, 0xe06f, |
| 7341 | "alloc_workqueue for qla_tgt_wq failed\n"); |
| 7342 | ret = -ENOMEM; |
| 7343 | goto out_cmd_mempool; |
| 7344 | } |
| 7345 | /* |
| 7346 | * Return 1 to signal that initiator-mode is being disabled |
| 7347 | */ |
| 7348 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; |
| 7349 | |
| 7350 | out_cmd_mempool: |
| 7351 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7352 | out_plogi_cachep: |
| 7353 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7354 | out_mgmt_cmd_cachep: |
| 7355 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7356 | return ret; |
| 7357 | } |
| 7358 | |
| 7359 | void qlt_exit(void) |
| 7360 | { |
| 7361 | if (!QLA_TGT_MODE_ENABLED()) |
| 7362 | return; |
| 7363 | |
| 7364 | destroy_workqueue(qla_tgt_wq); |
| 7365 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7366 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7367 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7368 | } |