1 // SPDX-License-Identifier: GPL-2.0-only
3 * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx
5 * based on qla2x00t.c code:
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.
12 * Forward port and refactoring to modern qla2xxx and target/configfs
14 * Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/types.h>
20 #include <linux/blkdev.h>
21 #include <linux/interrupt.h>
22 #include <linux/pci.h>
23 #include <linux/delay.h>
24 #include <linux/list.h>
25 #include <linux/workqueue.h>
26 #include <asm/unaligned.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_tcq.h>
30 #include <target/target_core_base.h>
31 #include <target/target_core_fabric.h>
34 #include "qla_target.h"
36 static int ql2xtgt_tape_enable;
37 module_param(ql2xtgt_tape_enable, int, S_IRUGO|S_IWUSR);
38 MODULE_PARM_DESC(ql2xtgt_tape_enable,
39 "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER.");
41 static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED;
42 module_param(qlini_mode, charp, S_IRUGO);
43 MODULE_PARM_DESC(qlini_mode,
44 "Determines when initiator mode will be enabled. Possible values: "
45 "\"exclusive\" - initiator mode will be enabled on load, "
46 "disabled on enabling target mode and then on disabling target mode "
48 "\"disabled\" - initiator mode will never be enabled; "
49 "\"dual\" - Initiator Modes will be enabled. Target Mode can be activated "
51 "\"enabled\" (default) - initiator mode will always stay enabled.");
53 static int ql_dm_tgt_ex_pct = 0;
54 module_param(ql_dm_tgt_ex_pct, int, S_IRUGO|S_IWUSR);
55 MODULE_PARM_DESC(ql_dm_tgt_ex_pct,
56 "For Dual Mode (qlini_mode=dual), this parameter determines "
57 "the percentage of exchanges/cmds FW will allocate resources "
61 module_param(ql2xuctrlirq, int, 0644);
62 MODULE_PARM_DESC(ql2xuctrlirq,
63 "User to control IRQ placement via smp_affinity."
64 "Valid with qlini_mode=disabled."
65 "1(default): enable");
67 int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE;
69 static int qla_sam_status = SAM_STAT_BUSY;
70 static int tc_sam_status = SAM_STAT_TASK_SET_FULL; /* target core */
73 * From scsi/fc/fc_fcp.h
75 enum fcp_resp_rsp_codes {
77 FCP_DATA_LEN_INVALID = 1,
78 FCP_CMND_FIELDS_INVALID = 2,
79 FCP_DATA_PARAM_MISMATCH = 3,
82 FCP_TMF_INVALID_LUN = 9,
86 * fc_pri_ta from scsi/fc/fc_fcp.h
88 #define FCP_PTA_SIMPLE 0 /* simple task attribute */
89 #define FCP_PTA_HEADQ 1 /* head of queue task attribute */
90 #define FCP_PTA_ORDERED 2 /* ordered task attribute */
91 #define FCP_PTA_ACA 4 /* auto. contingent allegiance */
92 #define FCP_PTA_MASK 7 /* mask for task attribute field */
93 #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */
94 #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */
97 * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which
98 * must be called under HW lock and could unlock/lock it inside.
99 * It isn't an issue, since in the current implementation on the time when
100 * those functions are called:
102 * - Either context is IRQ and only IRQ handler can modify HW data,
103 * including rings related fields,
105 * - Or access to target mode variables from struct qla_tgt doesn't
106 * cross those functions boundaries, except tgt_stop, which
107 * additionally protected by irq_cmd_count.
109 /* Predefs for callbacks handed to qla2xxx LLD */
110 static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha,
111 struct atio_from_isp *pkt, uint8_t);
112 static void qlt_response_pkt(struct scsi_qla_host *ha, struct rsp_que *rsp,
114 static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun,
115 int fn, void *iocb, int flags);
116 static void qlt_send_term_exchange(struct qla_qpair *, struct qla_tgt_cmd
117 *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort);
118 static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
119 struct atio_from_isp *atio, uint16_t status, int qfull);
120 static void qlt_disable_vha(struct scsi_qla_host *vha);
121 static void qlt_clear_tgt_db(struct qla_tgt *tgt);
122 static void qlt_send_notify_ack(struct qla_qpair *qpair,
123 struct imm_ntfy_from_isp *ntfy,
124 uint32_t add_flags, uint16_t resp_code, int resp_code_valid,
125 uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan);
126 static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
127 struct imm_ntfy_from_isp *imm, int ha_locked);
128 static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha,
129 fc_port_t *fcport, bool local);
130 void qlt_unreg_sess(struct fc_port *sess);
131 static void qlt_24xx_handle_abts(struct scsi_qla_host *,
132 struct abts_recv_from_24xx *);
133 static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *,
135 static int qlt_check_reserve_free_req(struct qla_qpair *qpair, uint32_t);
136 static inline uint32_t qlt_make_handle(struct qla_qpair *);
141 static struct kmem_cache *qla_tgt_mgmt_cmd_cachep;
142 struct kmem_cache *qla_tgt_plogi_cachep;
143 static mempool_t *qla_tgt_mgmt_cmd_mempool;
144 static struct workqueue_struct *qla_tgt_wq;
145 static DEFINE_MUTEX(qla_tgt_mutex);
146 static LIST_HEAD(qla_tgt_glist);
148 static const char *prot_op_str(u32 prot_op)
151 case TARGET_PROT_NORMAL: return "NORMAL";
152 case TARGET_PROT_DIN_INSERT: return "DIN_INSERT";
153 case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT";
154 case TARGET_PROT_DIN_STRIP: return "DIN_STRIP";
155 case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP";
156 case TARGET_PROT_DIN_PASS: return "DIN_PASS";
157 case TARGET_PROT_DOUT_PASS: return "DOUT_PASS";
158 default: return "UNKNOWN";
162 /* This API intentionally takes dest as a parameter, rather than returning
163 * int value to avoid caller forgetting to issue wmb() after the store */
164 void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest)
166 scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev);
167 *dest = atomic_inc_return(&base_vha->generation_tick);
172 /* Might release hw lock, then reaquire!! */
173 static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked)
175 /* Send marker if required */
176 if (unlikely(vha->marker_needed != 0)) {
177 int rc = qla2x00_issue_marker(vha, vha_locked);
179 if (rc != QLA_SUCCESS) {
180 ql_dbg(ql_dbg_tgt, vha, 0xe03d,
181 "qla_target(%d): issue_marker() failed\n",
190 struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha,
193 struct scsi_qla_host *host;
196 if (vha->d_id.b.area == d_id.area &&
197 vha->d_id.b.domain == d_id.domain &&
198 vha->d_id.b.al_pa == d_id.al_pa)
201 key = be_to_port_id(d_id).b24;
203 host = btree_lookup32(&vha->hw->tgt.host_map, key);
205 ql_dbg(ql_dbg_tgt_mgt + ql_dbg_verbose, vha, 0xf005,
206 "Unable to find host %06x\n", key);
212 struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha,
215 struct qla_hw_data *ha = vha->hw;
217 if (vha->vp_idx == vp_idx)
220 BUG_ON(ha->tgt.tgt_vp_map == NULL);
221 if (likely(test_bit(vp_idx, ha->vp_idx_map)))
222 return ha->tgt.tgt_vp_map[vp_idx].vha;
227 static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha)
231 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
233 vha->hw->tgt.num_pend_cmds++;
234 if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds)
235 vha->qla_stats.stat_max_pend_cmds =
236 vha->hw->tgt.num_pend_cmds;
237 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
239 static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha)
243 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
244 vha->hw->tgt.num_pend_cmds--;
245 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
249 static void qlt_queue_unknown_atio(scsi_qla_host_t *vha,
250 struct atio_from_isp *atio, uint8_t ha_locked)
252 struct qla_tgt_sess_op *u;
253 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
257 ql_dbg(ql_dbg_async, vha, 0x502c,
258 "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped",
263 u = kzalloc(sizeof(*u), GFP_ATOMIC);
268 memcpy(&u->atio, atio, sizeof(*atio));
269 INIT_LIST_HEAD(&u->cmd_list);
271 spin_lock_irqsave(&vha->cmd_list_lock, flags);
272 list_add_tail(&u->cmd_list, &vha->unknown_atio_list);
273 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
275 schedule_delayed_work(&vha->unknown_atio_work, 1);
281 qlt_send_term_exchange(vha->hw->base_qpair, NULL, atio, ha_locked, 0);
285 static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha,
288 struct qla_tgt_sess_op *u, *t;
289 scsi_qla_host_t *host;
290 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
294 list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) {
296 ql_dbg(ql_dbg_async, vha, 0x502e,
297 "Freeing unknown %s %p, because of Abort\n",
299 qlt_send_term_exchange(vha->hw->base_qpair, NULL,
300 &u->atio, ha_locked, 0);
304 host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id);
306 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x502f,
307 "Requeuing unknown ATIO_TYPE7 %p\n", u);
308 qlt_24xx_atio_pkt(host, &u->atio, ha_locked);
309 } else if (tgt->tgt_stop) {
310 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503a,
311 "Freeing unknown %s %p, because tgt is being stopped\n",
313 qlt_send_term_exchange(vha->hw->base_qpair, NULL,
314 &u->atio, ha_locked, 0);
316 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d,
317 "Reschedule u %p, vha %p, host %p\n", u, vha, host);
320 schedule_delayed_work(&vha->unknown_atio_work,
327 spin_lock_irqsave(&vha->cmd_list_lock, flags);
328 list_del(&u->cmd_list);
329 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
334 void qlt_unknown_atio_work_fn(struct work_struct *work)
336 struct scsi_qla_host *vha = container_of(to_delayed_work(work),
337 struct scsi_qla_host, unknown_atio_work);
339 qlt_try_to_dequeue_unknown_atios(vha, 0);
342 static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *vha,
343 struct atio_from_isp *atio, uint8_t ha_locked)
345 ql_dbg(ql_dbg_tgt, vha, 0xe072,
346 "%s: qla_target(%d): type %x ox_id %04x\n",
347 __func__, vha->vp_idx, atio->u.raw.entry_type,
348 be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
350 switch (atio->u.raw.entry_type) {
353 struct scsi_qla_host *host = qlt_find_host_by_d_id(vha,
354 atio->u.isp24.fcp_hdr.d_id);
355 if (unlikely(NULL == host)) {
356 ql_dbg(ql_dbg_tgt, vha, 0xe03e,
357 "qla_target(%d): Received ATIO_TYPE7 "
358 "with unknown d_id %x:%x:%x\n", vha->vp_idx,
359 atio->u.isp24.fcp_hdr.d_id.domain,
360 atio->u.isp24.fcp_hdr.d_id.area,
361 atio->u.isp24.fcp_hdr.d_id.al_pa);
364 qlt_queue_unknown_atio(vha, atio, ha_locked);
367 if (unlikely(!list_empty(&vha->unknown_atio_list)))
368 qlt_try_to_dequeue_unknown_atios(vha, ha_locked);
370 qlt_24xx_atio_pkt(host, atio, ha_locked);
374 case IMMED_NOTIFY_TYPE:
376 struct scsi_qla_host *host = vha;
377 struct imm_ntfy_from_isp *entry =
378 (struct imm_ntfy_from_isp *)atio;
380 qlt_issue_marker(vha, ha_locked);
382 if ((entry->u.isp24.vp_index != 0xFF) &&
383 (entry->u.isp24.nport_handle != 0xFFFF)) {
384 host = qlt_find_host_by_vp_idx(vha,
385 entry->u.isp24.vp_index);
386 if (unlikely(!host)) {
387 ql_dbg(ql_dbg_tgt, vha, 0xe03f,
388 "qla_target(%d): Received "
389 "ATIO (IMMED_NOTIFY_TYPE) "
390 "with unknown vp_index %d\n",
391 vha->vp_idx, entry->u.isp24.vp_index);
395 qlt_24xx_atio_pkt(host, atio, ha_locked);
399 case VP_RPT_ID_IOCB_TYPE:
400 qla24xx_report_id_acquisition(vha,
401 (struct vp_rpt_id_entry_24xx *)atio);
406 struct abts_recv_from_24xx *entry =
407 (struct abts_recv_from_24xx *)atio;
408 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
412 if (unlikely(!host)) {
413 ql_dbg(ql_dbg_tgt, vha, 0xe00a,
414 "qla_target(%d): Response pkt (ABTS_RECV_24XX) "
415 "received, with unknown vp_index %d\n",
416 vha->vp_idx, entry->vp_index);
420 spin_lock_irqsave(&host->hw->hardware_lock, flags);
421 qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio);
423 spin_unlock_irqrestore(&host->hw->hardware_lock, flags);
427 /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */
430 ql_dbg(ql_dbg_tgt, vha, 0xe040,
431 "qla_target(%d): Received unknown ATIO atio "
432 "type %x\n", vha->vp_idx, atio->u.raw.entry_type);
439 void qlt_response_pkt_all_vps(struct scsi_qla_host *vha,
440 struct rsp_que *rsp, response_t *pkt)
442 switch (pkt->entry_type) {
444 ql_dbg(ql_dbg_tgt, vha, 0xe073,
445 "qla_target(%d):%s: CRC2 Response pkt\n",
446 vha->vp_idx, __func__);
450 struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
451 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
453 if (unlikely(!host)) {
454 ql_dbg(ql_dbg_tgt, vha, 0xe041,
455 "qla_target(%d): Response pkt (CTIO_TYPE7) "
456 "received, with unknown vp_index %d\n",
457 vha->vp_idx, entry->vp_index);
460 qlt_response_pkt(host, rsp, pkt);
464 case IMMED_NOTIFY_TYPE:
466 struct scsi_qla_host *host = vha;
467 struct imm_ntfy_from_isp *entry =
468 (struct imm_ntfy_from_isp *)pkt;
470 host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index);
471 if (unlikely(!host)) {
472 ql_dbg(ql_dbg_tgt, vha, 0xe042,
473 "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
474 "received, with unknown vp_index %d\n",
475 vha->vp_idx, entry->u.isp24.vp_index);
478 qlt_response_pkt(host, rsp, pkt);
482 case NOTIFY_ACK_TYPE:
484 struct scsi_qla_host *host = vha;
485 struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
487 if (0xFF != entry->u.isp24.vp_index) {
488 host = qlt_find_host_by_vp_idx(vha,
489 entry->u.isp24.vp_index);
490 if (unlikely(!host)) {
491 ql_dbg(ql_dbg_tgt, vha, 0xe043,
492 "qla_target(%d): Response "
493 "pkt (NOTIFY_ACK_TYPE) "
494 "received, with unknown "
495 "vp_index %d\n", vha->vp_idx,
496 entry->u.isp24.vp_index);
500 qlt_response_pkt(host, rsp, pkt);
506 struct abts_recv_from_24xx *entry =
507 (struct abts_recv_from_24xx *)pkt;
508 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
510 if (unlikely(!host)) {
511 ql_dbg(ql_dbg_tgt, vha, 0xe044,
512 "qla_target(%d): Response pkt "
513 "(ABTS_RECV_24XX) received, with unknown "
514 "vp_index %d\n", vha->vp_idx, entry->vp_index);
517 qlt_response_pkt(host, rsp, pkt);
523 struct abts_resp_to_24xx *entry =
524 (struct abts_resp_to_24xx *)pkt;
525 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
527 if (unlikely(!host)) {
528 ql_dbg(ql_dbg_tgt, vha, 0xe045,
529 "qla_target(%d): Response pkt "
530 "(ABTS_RECV_24XX) received, with unknown "
531 "vp_index %d\n", vha->vp_idx, entry->vp_index);
534 qlt_response_pkt(host, rsp, pkt);
538 qlt_response_pkt(vha, rsp, pkt);
545 * All qlt_plogi_ack_t operations are protected by hardware_lock
547 static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport,
548 struct imm_ntfy_from_isp *ntfy, int type)
550 struct qla_work_evt *e;
552 e = qla2x00_alloc_work(vha, QLA_EVT_NACK);
554 return QLA_FUNCTION_FAILED;
556 e->u.nack.fcport = fcport;
557 e->u.nack.type = type;
558 memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp));
559 return qla2x00_post_work(vha, e);
562 static void qla2x00_async_nack_sp_done(srb_t *sp, int res)
564 struct scsi_qla_host *vha = sp->vha;
567 ql_dbg(ql_dbg_disc, vha, 0x20f2,
568 "Async done-%s res %x %8phC type %d\n",
569 sp->name, res, sp->fcport->port_name, sp->type);
571 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
572 sp->fcport->flags &= ~FCF_ASYNC_SENT;
573 sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
577 sp->fcport->login_gen++;
578 sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
579 sp->fcport->logout_on_delete = 1;
580 sp->fcport->plogi_nack_done_deadline = jiffies + HZ;
581 sp->fcport->send_els_logo = 0;
585 sp->fcport->fw_login_state = DSC_LS_PRLI_COMP;
586 sp->fcport->deleted = 0;
587 sp->fcport->send_els_logo = 0;
589 if (!sp->fcport->login_succ &&
590 !IS_SW_RESV_ADDR(sp->fcport->d_id)) {
591 sp->fcport->login_succ = 1;
594 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
595 qla24xx_sched_upd_fcport(sp->fcport);
596 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
598 sp->fcport->login_retry = 0;
599 qla2x00_set_fcport_disc_state(sp->fcport,
601 sp->fcport->deleted = 0;
602 sp->fcport->logout_on_delete = 1;
607 sp->fcport->login_gen++;
608 sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
609 qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE);
612 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
617 int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport,
618 struct imm_ntfy_from_isp *ntfy, int type)
620 int rval = QLA_FUNCTION_FAILED;
624 fcport->flags |= FCF_ASYNC_SENT;
627 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
631 fcport->fw_login_state = DSC_LS_PRLI_PEND;
636 fcport->fw_login_state = DSC_LS_LOGO_PEND;
641 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
648 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
649 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
651 sp->u.iocb_cmd.u.nack.ntfy = ntfy;
652 sp->done = qla2x00_async_nack_sp_done;
654 ql_dbg(ql_dbg_disc, vha, 0x20f4,
655 "Async-%s %8phC hndl %x %s\n",
656 sp->name, fcport->port_name, sp->handle, c);
658 rval = qla2x00_start_sp(sp);
659 if (rval != QLA_SUCCESS)
667 fcport->flags &= ~FCF_ASYNC_SENT;
671 void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
675 switch (e->u.nack.type) {
677 t = e->u.nack.fcport;
678 flush_work(&t->del_work);
679 flush_work(&t->free_work);
680 mutex_lock(&vha->vha_tgt.tgt_mutex);
681 t = qlt_create_sess(vha, e->u.nack.fcport, 0);
682 mutex_unlock(&vha->vha_tgt.tgt_mutex);
684 ql_log(ql_log_info, vha, 0xd034,
685 "%s create sess success %p", __func__, t);
686 /* create sess has an extra kref */
687 vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport);
691 qla24xx_async_notify_ack(vha, e->u.nack.fcport,
692 (struct imm_ntfy_from_isp *)e->u.nack.iocb, e->u.nack.type);
695 void qla24xx_delete_sess_fn(struct work_struct *work)
697 fc_port_t *fcport = container_of(work, struct fc_port, del_work);
698 struct qla_hw_data *ha = fcport->vha->hw;
700 if (fcport->se_sess) {
701 ha->tgt.tgt_ops->shutdown_sess(fcport);
702 ha->tgt.tgt_ops->put_sess(fcport);
704 qlt_unreg_sess(fcport);
709 * Called from qla2x00_reg_remote_port()
711 void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport)
713 struct qla_hw_data *ha = vha->hw;
714 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
715 struct fc_port *sess = fcport;
718 if (!vha->hw->tgt.tgt_ops)
721 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
723 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
727 if (fcport->disc_state == DSC_DELETE_PEND) {
728 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
732 if (!sess->se_sess) {
733 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
735 mutex_lock(&vha->vha_tgt.tgt_mutex);
736 sess = qlt_create_sess(vha, fcport, false);
737 mutex_unlock(&vha->vha_tgt.tgt_mutex);
739 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
741 if (fcport->fw_login_state == DSC_LS_PRLI_COMP) {
742 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
746 if (!kref_get_unless_zero(&sess->sess_kref)) {
747 ql_dbg(ql_dbg_disc, vha, 0x2107,
748 "%s: kref_get fail sess %8phC \n",
749 __func__, sess->port_name);
750 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
754 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c,
755 "qla_target(%u): %ssession for port %8phC "
756 "(loop ID %d) reappeared\n", vha->vp_idx,
757 sess->local ? "local " : "", sess->port_name, sess->loop_id);
759 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007,
760 "Reappeared sess %p\n", sess);
762 ha->tgt.tgt_ops->update_sess(sess, fcport->d_id,
764 (fcport->flags & FCF_CONF_COMP_SUPPORTED));
767 if (sess && sess->local) {
768 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d,
769 "qla_target(%u): local session for "
770 "port %8phC (loop ID %d) became global\n", vha->vp_idx,
771 fcport->port_name, sess->loop_id);
774 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
776 ha->tgt.tgt_ops->put_sess(sess);
780 * This is a zero-base ref-counting solution, since hardware_lock
781 * guarantees that ref_count is not modified concurrently.
782 * Upon successful return content of iocb is undefined
784 static struct qlt_plogi_ack_t *
785 qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id,
786 struct imm_ntfy_from_isp *iocb)
788 struct qlt_plogi_ack_t *pla;
790 lockdep_assert_held(&vha->hw->hardware_lock);
792 list_for_each_entry(pla, &vha->plogi_ack_list, list) {
793 if (pla->id.b24 == id->b24) {
794 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x210d,
795 "%s %d %8phC Term INOT due to new INOT",
797 pla->iocb.u.isp24.port_name);
798 qlt_send_term_imm_notif(vha, &pla->iocb, 1);
799 memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
804 pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC);
806 ql_dbg(ql_dbg_async, vha, 0x5088,
807 "qla_target(%d): Allocation of plogi_ack failed\n",
812 memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
814 list_add_tail(&pla->list, &vha->plogi_ack_list);
819 void qlt_plogi_ack_unref(struct scsi_qla_host *vha,
820 struct qlt_plogi_ack_t *pla)
822 struct imm_ntfy_from_isp *iocb = &pla->iocb;
825 fc_port_t *fcport = pla->fcport;
827 BUG_ON(!pla->ref_count);
833 ql_dbg(ql_dbg_disc, vha, 0x5089,
834 "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x"
835 " exch %#x ox_id %#x\n", iocb->u.isp24.port_name,
836 iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1],
837 iocb->u.isp24.port_id[0],
838 le16_to_cpu(iocb->u.isp24.nport_handle),
839 iocb->u.isp24.exchange_address, iocb->ox_id);
841 port_id.b.domain = iocb->u.isp24.port_id[2];
842 port_id.b.area = iocb->u.isp24.port_id[1];
843 port_id.b.al_pa = iocb->u.isp24.port_id[0];
844 port_id.b.rsvd_1 = 0;
846 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
848 fcport->loop_id = loop_id;
849 fcport->d_id = port_id;
850 if (iocb->u.isp24.status_subcode == ELS_PLOGI)
851 qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI);
853 qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PRLI);
855 list_for_each_entry(fcport, &vha->vp_fcports, list) {
856 if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla)
857 fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL;
858 if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla)
859 fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL;
862 list_del(&pla->list);
863 kmem_cache_free(qla_tgt_plogi_cachep, pla);
867 qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla,
868 struct fc_port *sess, enum qlt_plogi_link_t link)
870 struct imm_ntfy_from_isp *iocb = &pla->iocb;
871 /* Inc ref_count first because link might already be pointing at pla */
874 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097,
875 "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC"
876 " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n",
877 sess, link, sess->port_name,
878 iocb->u.isp24.port_name, iocb->u.isp24.port_id[2],
879 iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0],
880 pla->ref_count, pla, link);
882 if (link == QLT_PLOGI_LINK_CONFLICT) {
883 switch (sess->disc_state) {
885 case DSC_DELETE_PEND:
893 if (sess->plogi_link[link])
894 qlt_plogi_ack_unref(vha, sess->plogi_link[link]);
896 if (link == QLT_PLOGI_LINK_SAME_WWN)
899 sess->plogi_link[link] = pla;
903 /* These fields must be initialized by the caller */
906 * number of cmds dropped while we were waiting for
907 * initiator to ack LOGO initialize to 1 if LOGO is
908 * triggered by a command, otherwise, to 0
912 /* These fields are used by callee */
913 struct list_head list;
917 qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo)
919 qlt_port_logo_t *tmp;
922 mutex_lock(&vha->vha_tgt.tgt_mutex);
924 list_for_each_entry(tmp, &vha->logo_list, list) {
925 if (tmp->id.b24 == logo->id.b24) {
926 tmp->cmd_count += logo->cmd_count;
927 mutex_unlock(&vha->vha_tgt.tgt_mutex);
932 list_add_tail(&logo->list, &vha->logo_list);
934 mutex_unlock(&vha->vha_tgt.tgt_mutex);
936 res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id);
938 mutex_lock(&vha->vha_tgt.tgt_mutex);
939 list_del(&logo->list);
940 mutex_unlock(&vha->vha_tgt.tgt_mutex);
942 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098,
943 "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n",
944 logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa,
945 logo->cmd_count, res);
948 void qlt_free_session_done(struct work_struct *work)
950 struct fc_port *sess = container_of(work, struct fc_port,
952 struct qla_tgt *tgt = sess->tgt;
953 struct scsi_qla_host *vha = sess->vha;
954 struct qla_hw_data *ha = vha->hw;
956 bool logout_started = false;
957 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
958 struct qlt_plogi_ack_t *own =
959 sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
961 ql_dbg(ql_dbg_disc, vha, 0xf084,
962 "%s: se_sess %p / sess %p from port %8phC loop_id %#04x"
963 " s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n",
964 __func__, sess->se_sess, sess, sess->port_name, sess->loop_id,
965 sess->d_id.b.domain, sess->d_id.b.area, sess->d_id.b.al_pa,
966 sess->logout_on_delete, sess->keep_nport_handle,
967 sess->send_els_logo);
969 if (!IS_SW_RESV_ADDR(sess->d_id)) {
970 qla2x00_mark_device_lost(vha, sess, 0, 0);
972 if (sess->send_els_logo) {
973 qlt_port_logo_t logo;
975 logo.id = sess->d_id;
978 qlt_send_first_logo(vha, &logo);
979 sess->send_els_logo = 0;
982 if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) {
987 (own->iocb.u.isp24.status_subcode == ELS_PLOGI))) {
988 rc = qla2x00_post_async_logout_work(vha, sess,
990 if (rc != QLA_SUCCESS)
991 ql_log(ql_log_warn, vha, 0xf085,
992 "Schedule logo failed sess %p rc %d\n",
995 logout_started = true;
996 } else if (own && (own->iocb.u.isp24.status_subcode ==
997 ELS_PRLI) && ha->flags.rida_fmt2) {
998 rc = qla2x00_post_async_prlo_work(vha, sess,
1000 if (rc != QLA_SUCCESS)
1001 ql_log(ql_log_warn, vha, 0xf085,
1002 "Schedule PRLO failed sess %p rc %d\n",
1005 logout_started = true;
1007 } /* if sess->logout_on_delete */
1009 if (sess->nvme_flag & NVME_FLAG_REGISTERED &&
1010 !(sess->nvme_flag & NVME_FLAG_DELETING)) {
1011 sess->nvme_flag |= NVME_FLAG_DELETING;
1012 qla_nvme_unregister_remote_port(sess);
1017 * Release the target session for FC Nexus from fabric module code.
1019 if (sess->se_sess != NULL)
1020 ha->tgt.tgt_ops->free_session(sess);
1022 if (logout_started) {
1023 bool traced = false;
1026 while (!READ_ONCE(sess->logout_completed)) {
1028 ql_dbg(ql_dbg_disc, vha, 0xf086,
1029 "%s: waiting for sess %p logout\n",
1039 ql_dbg(ql_dbg_disc, vha, 0xf087,
1040 "%s: sess %p logout completed\n", __func__, sess);
1043 if (sess->logo_ack_needed) {
1044 sess->logo_ack_needed = 0;
1045 qla24xx_async_notify_ack(vha, sess,
1046 (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO);
1049 spin_lock_irqsave(&vha->work_lock, flags);
1050 sess->flags &= ~FCF_ASYNC_SENT;
1051 spin_unlock_irqrestore(&vha->work_lock, flags);
1053 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1054 if (sess->se_sess) {
1055 sess->se_sess = NULL;
1056 if (tgt && !IS_SW_RESV_ADDR(sess->d_id))
1060 qla2x00_set_fcport_disc_state(sess, DSC_DELETED);
1061 sess->fw_login_state = DSC_LS_PORT_UNAVAIL;
1062 sess->deleted = QLA_SESS_DELETED;
1064 if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) {
1065 vha->fcport_count--;
1066 sess->login_succ = 0;
1069 qla2x00_clear_loop_id(sess);
1071 if (sess->conflict) {
1072 sess->conflict->login_pause = 0;
1073 sess->conflict = NULL;
1074 if (!test_bit(UNLOADING, &vha->dpc_flags))
1075 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1079 struct qlt_plogi_ack_t *con =
1080 sess->plogi_link[QLT_PLOGI_LINK_CONFLICT];
1081 struct imm_ntfy_from_isp *iocb;
1083 own = sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
1087 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099,
1088 "se_sess %p / sess %p port %8phC is gone,"
1089 " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n",
1090 sess->se_sess, sess, sess->port_name,
1091 own ? "releasing own PLOGI" : "no own PLOGI pending",
1092 own ? own->ref_count : -1,
1093 iocb->u.isp24.port_name, con->ref_count);
1094 qlt_plogi_ack_unref(vha, con);
1095 sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL;
1097 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a,
1098 "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n",
1099 sess->se_sess, sess, sess->port_name,
1100 own ? "releasing own PLOGI" :
1101 "no own PLOGI pending",
1102 own ? own->ref_count : -1);
1106 sess->fw_login_state = DSC_LS_PLOGI_PEND;
1107 qlt_plogi_ack_unref(vha, own);
1108 sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL;
1112 sess->explicit_logout = 0;
1113 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1114 sess->free_pending = 0;
1116 ql_dbg(ql_dbg_disc, vha, 0xf001,
1117 "Unregistration of sess %p %8phC finished fcp_cnt %d\n",
1118 sess, sess->port_name, vha->fcport_count);
1120 if (tgt && (tgt->sess_count == 0))
1121 wake_up_all(&tgt->waitQ);
1123 if (!test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags) &&
1124 !(vha->vp_idx && test_bit(VPORT_DELETE, &vha->dpc_flags)) &&
1125 (!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) {
1126 switch (vha->host->active_mode) {
1127 case MODE_INITIATOR:
1129 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1130 qla2xxx_wake_dpc(vha);
1139 if (vha->fcport_count == 0)
1140 wake_up_all(&vha->fcport_waitQ);
1143 /* ha->tgt.sess_lock supposed to be held on entry */
1144 void qlt_unreg_sess(struct fc_port *sess)
1146 struct scsi_qla_host *vha = sess->vha;
1147 unsigned long flags;
1149 ql_dbg(ql_dbg_disc, sess->vha, 0x210a,
1150 "%s sess %p for deletion %8phC\n",
1151 __func__, sess, sess->port_name);
1153 spin_lock_irqsave(&sess->vha->work_lock, flags);
1154 if (sess->free_pending) {
1155 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1158 sess->free_pending = 1;
1160 * Use FCF_ASYNC_SENT flag to block other cmds used in sess
1161 * management from being sent.
1163 sess->flags |= FCF_ASYNC_SENT;
1164 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1167 vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess);
1169 sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
1170 qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND);
1171 sess->last_rscn_gen = sess->rscn_gen;
1172 sess->last_login_gen = sess->login_gen;
1174 queue_work(sess->vha->hw->wq, &sess->free_work);
1176 EXPORT_SYMBOL(qlt_unreg_sess);
1178 static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd)
1180 struct qla_hw_data *ha = vha->hw;
1181 struct fc_port *sess = NULL;
1184 struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb;
1185 unsigned long flags;
1187 loop_id = le16_to_cpu(n->u.isp24.nport_handle);
1188 if (loop_id == 0xFFFF) {
1190 atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count);
1191 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1192 qlt_clear_tgt_db(vha->vha_tgt.qla_tgt);
1193 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1195 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1196 sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
1197 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1200 ql_dbg(ql_dbg_tgt, vha, 0xe000,
1201 "Using sess for qla_tgt_reset: %p\n", sess);
1207 ql_dbg(ql_dbg_tgt, vha, 0xe047,
1208 "scsi(%ld): resetting (session %p from port %8phC mcmd %x, "
1209 "loop_id %d)\n", vha->host_no, sess, sess->port_name,
1212 return qlt_issue_task_mgmt(sess, 0, mcmd, iocb, QLA24XX_MGMT_SEND_NACK);
1215 static void qla24xx_chk_fcp_state(struct fc_port *sess)
1217 if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) {
1218 sess->logout_on_delete = 0;
1219 sess->logo_ack_needed = 0;
1220 sess->fw_login_state = DSC_LS_PORT_UNAVAIL;
1224 void qlt_schedule_sess_for_deletion(struct fc_port *sess)
1226 struct qla_tgt *tgt = sess->tgt;
1227 unsigned long flags;
1230 switch (sess->disc_state) {
1231 case DSC_DELETE_PEND:
1234 if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] &&
1235 !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) {
1236 if (tgt && tgt->tgt_stop && tgt->sess_count == 0)
1237 wake_up_all(&tgt->waitQ);
1239 if (sess->vha->fcport_count == 0)
1240 wake_up_all(&sess->vha->fcport_waitQ);
1244 case DSC_UPD_FCPORT:
1246 * This port is not done reporting to upper layer.
1249 sess->next_disc_state = DSC_DELETE_PEND;
1250 sec = jiffies_to_msecs(jiffies -
1251 sess->jiffies_at_registration)/1000;
1252 if (sess->sec_since_registration < sec && sec && !(sec % 5)) {
1253 sess->sec_since_registration = sec;
1254 ql_dbg(ql_dbg_disc, sess->vha, 0xffff,
1255 "%s %8phC : Slow Rport registration(%d Sec)\n",
1256 __func__, sess->port_name, sec);
1263 spin_lock_irqsave(&sess->vha->work_lock, flags);
1264 if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) {
1265 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1268 sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
1269 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1271 sess->prli_pend_timer = 0;
1272 qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND);
1274 qla24xx_chk_fcp_state(sess);
1276 ql_dbg(ql_dbg_disc, sess->vha, 0xe001,
1277 "Scheduling sess %p for deletion %8phC\n",
1278 sess, sess->port_name);
1280 WARN_ON(!queue_work(sess->vha->hw->wq, &sess->del_work));
1283 static void qlt_clear_tgt_db(struct qla_tgt *tgt)
1285 struct fc_port *sess;
1286 scsi_qla_host_t *vha = tgt->vha;
1288 list_for_each_entry(sess, &vha->vp_fcports, list) {
1290 qlt_schedule_sess_for_deletion(sess);
1293 /* At this point tgt could be already dead */
1296 static int qla24xx_get_loop_id(struct scsi_qla_host *vha, be_id_t s_id,
1299 struct qla_hw_data *ha = vha->hw;
1300 dma_addr_t gid_list_dma;
1301 struct gid_list_info *gid_list, *gid;
1305 gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
1306 &gid_list_dma, GFP_KERNEL);
1308 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044,
1309 "qla_target(%d): DMA Alloc failed of %u\n",
1310 vha->vp_idx, qla2x00_gid_list_size(ha));
1314 /* Get list of logged in devices */
1315 rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries);
1316 if (rc != QLA_SUCCESS) {
1317 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045,
1318 "qla_target(%d): get_id_list() failed: %x\n",
1321 goto out_free_id_list;
1326 for (i = 0; i < entries; i++) {
1327 if (gid->al_pa == s_id.al_pa &&
1328 gid->area == s_id.area &&
1329 gid->domain == s_id.domain) {
1330 *loop_id = le16_to_cpu(gid->loop_id);
1334 gid = (void *)gid + ha->gid_list_info_size;
1338 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
1339 gid_list, gid_list_dma);
1344 * Adds an extra ref to allow to drop hw lock after adding sess to the list.
1345 * Caller must put it.
1347 static struct fc_port *qlt_create_sess(
1348 struct scsi_qla_host *vha,
1352 struct qla_hw_data *ha = vha->hw;
1353 struct fc_port *sess = fcport;
1354 unsigned long flags;
1356 if (vha->vha_tgt.qla_tgt->tgt_stop)
1359 if (fcport->se_sess) {
1360 if (!kref_get_unless_zero(&sess->sess_kref)) {
1361 ql_dbg(ql_dbg_disc, vha, 0x20f6,
1362 "%s: kref_get_unless_zero failed for %8phC\n",
1363 __func__, sess->port_name);
1368 sess->tgt = vha->vha_tgt.qla_tgt;
1369 sess->local = local;
1372 * Under normal circumstances we want to logout from firmware when
1373 * session eventually ends and release corresponding nport handle.
1374 * In the exception cases (e.g. when new PLOGI is waiting) corresponding
1375 * code will adjust these flags as necessary.
1377 sess->logout_on_delete = 1;
1378 sess->keep_nport_handle = 0;
1379 sess->logout_completed = 0;
1381 if (ha->tgt.tgt_ops->check_initiator_node_acl(vha,
1382 &fcport->port_name[0], sess) < 0) {
1383 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015,
1384 "(%d) %8phC check_initiator_node_acl failed\n",
1385 vha->vp_idx, fcport->port_name);
1388 kref_init(&fcport->sess_kref);
1390 * Take an extra reference to ->sess_kref here to handle
1391 * fc_port access across ->tgt.sess_lock reaquire.
1393 if (!kref_get_unless_zero(&sess->sess_kref)) {
1394 ql_dbg(ql_dbg_disc, vha, 0x20f7,
1395 "%s: kref_get_unless_zero failed for %8phC\n",
1396 __func__, sess->port_name);
1400 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1401 if (!IS_SW_RESV_ADDR(sess->d_id))
1402 vha->vha_tgt.qla_tgt->sess_count++;
1404 qlt_do_generation_tick(vha, &sess->generation);
1405 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1408 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006,
1409 "Adding sess %p se_sess %p to tgt %p sess_count %d\n",
1410 sess, sess->se_sess, vha->vha_tgt.qla_tgt,
1411 vha->vha_tgt.qla_tgt->sess_count);
1413 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b,
1414 "qla_target(%d): %ssession for wwn %8phC (loop_id %d, "
1415 "s_id %x:%x:%x, confirmed completion %ssupported) added\n",
1416 vha->vp_idx, local ? "local " : "", fcport->port_name,
1417 fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area,
1418 sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not ");
1424 * max_gen - specifies maximum session generation
1425 * at which this deletion requestion is still valid
1428 qlt_fc_port_deleted(struct scsi_qla_host *vha, fc_port_t *fcport, int max_gen)
1430 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1431 struct fc_port *sess = fcport;
1432 unsigned long flags;
1434 if (!vha->hw->tgt.tgt_ops)
1440 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1441 if (tgt->tgt_stop) {
1442 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1445 if (!sess->se_sess) {
1446 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1450 if (max_gen - sess->generation < 0) {
1451 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1452 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092,
1453 "Ignoring stale deletion request for se_sess %p / sess %p"
1454 " for port %8phC, req_gen %d, sess_gen %d\n",
1455 sess->se_sess, sess, sess->port_name, max_gen,
1460 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess);
1463 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1464 qlt_schedule_sess_for_deletion(sess);
1467 static inline int test_tgt_sess_count(struct qla_tgt *tgt)
1469 struct qla_hw_data *ha = tgt->ha;
1470 unsigned long flags;
1473 * We need to protect against race, when tgt is freed before or
1476 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1477 ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002,
1478 "tgt %p, sess_count=%d\n",
1479 tgt, tgt->sess_count);
1480 res = (tgt->sess_count == 0);
1481 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1486 /* Called by tcm_qla2xxx configfs code */
1487 int qlt_stop_phase1(struct qla_tgt *tgt)
1489 struct scsi_qla_host *vha = tgt->vha;
1490 struct qla_hw_data *ha = tgt->ha;
1491 unsigned long flags;
1493 mutex_lock(&ha->optrom_mutex);
1494 mutex_lock(&qla_tgt_mutex);
1496 if (tgt->tgt_stop || tgt->tgt_stopped) {
1497 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e,
1498 "Already in tgt->tgt_stop or tgt_stopped state\n");
1499 mutex_unlock(&qla_tgt_mutex);
1500 mutex_unlock(&ha->optrom_mutex);
1504 ql_dbg(ql_dbg_tgt_mgt, vha, 0xe003, "Stopping target for host %ld(%p)\n",
1507 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
1508 * Lock is needed, because we still can get an incoming packet.
1510 mutex_lock(&vha->vha_tgt.tgt_mutex);
1512 qlt_clear_tgt_db(tgt);
1513 mutex_unlock(&vha->vha_tgt.tgt_mutex);
1514 mutex_unlock(&qla_tgt_mutex);
1516 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009,
1517 "Waiting for sess works (tgt %p)", tgt);
1518 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1519 while (!list_empty(&tgt->sess_works_list)) {
1520 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1521 flush_scheduled_work();
1522 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1524 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1526 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a,
1527 "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count);
1529 wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
1532 if (!ha->flags.host_shutting_down &&
1533 (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)))
1534 qlt_disable_vha(vha);
1536 /* Wait for sessions to clear out (just in case) */
1537 wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
1538 mutex_unlock(&ha->optrom_mutex);
1542 EXPORT_SYMBOL(qlt_stop_phase1);
1544 /* Called by tcm_qla2xxx configfs code */
1545 void qlt_stop_phase2(struct qla_tgt *tgt)
1547 scsi_qla_host_t *vha = tgt->vha;
1549 if (tgt->tgt_stopped) {
1550 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f,
1551 "Already in tgt->tgt_stopped state\n");
1555 if (!tgt->tgt_stop) {
1556 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b,
1557 "%s: phase1 stop is not completed\n", __func__);
1562 mutex_lock(&tgt->ha->optrom_mutex);
1563 mutex_lock(&vha->vha_tgt.tgt_mutex);
1565 tgt->tgt_stopped = 1;
1566 mutex_unlock(&vha->vha_tgt.tgt_mutex);
1567 mutex_unlock(&tgt->ha->optrom_mutex);
1569 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00c, "Stop of tgt %p finished\n",
1572 switch (vha->qlini_mode) {
1573 case QLA2XXX_INI_MODE_EXCLUSIVE:
1574 vha->flags.online = 1;
1575 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1581 EXPORT_SYMBOL(qlt_stop_phase2);
1583 /* Called from qlt_remove_target() -> qla2x00_remove_one() */
1584 static void qlt_release(struct qla_tgt *tgt)
1586 scsi_qla_host_t *vha = tgt->vha;
1590 struct qla_qpair_hint *h;
1591 struct qla_hw_data *ha = vha->hw;
1593 if (!tgt->tgt_stop && !tgt->tgt_stopped)
1594 qlt_stop_phase1(tgt);
1596 if (!tgt->tgt_stopped)
1597 qlt_stop_phase2(tgt);
1599 for (i = 0; i < vha->hw->max_qpairs + 1; i++) {
1600 unsigned long flags;
1602 h = &tgt->qphints[i];
1604 spin_lock_irqsave(h->qpair->qp_lock_ptr, flags);
1605 list_del(&h->hint_elem);
1606 spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags);
1610 kfree(tgt->qphints);
1611 mutex_lock(&qla_tgt_mutex);
1612 list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry);
1613 mutex_unlock(&qla_tgt_mutex);
1615 btree_for_each_safe64(&tgt->lun_qpair_map, key, node)
1616 btree_remove64(&tgt->lun_qpair_map, key);
1618 btree_destroy64(&tgt->lun_qpair_map);
1621 if (ha->tgt.tgt_ops &&
1622 ha->tgt.tgt_ops->remove_target &&
1623 vha->vha_tgt.target_lport_ptr)
1624 ha->tgt.tgt_ops->remove_target(vha);
1626 vha->vha_tgt.qla_tgt = NULL;
1628 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d,
1629 "Release of tgt %p finished\n", tgt);
1634 /* ha->hardware_lock supposed to be held on entry */
1635 static int qlt_sched_sess_work(struct qla_tgt *tgt, int type,
1636 const void *param, unsigned int param_size)
1638 struct qla_tgt_sess_work_param *prm;
1639 unsigned long flags;
1641 prm = kzalloc(sizeof(*prm), GFP_ATOMIC);
1643 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050,
1644 "qla_target(%d): Unable to create session "
1645 "work, command will be refused", 0);
1649 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e,
1650 "Scheduling work (type %d, prm %p)"
1651 " to find session for param %p (size %d, tgt %p)\n",
1652 type, prm, param, param_size, tgt);
1655 memcpy(&prm->tm_iocb, param, param_size);
1657 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1658 list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list);
1659 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1661 schedule_work(&tgt->sess_work);
1667 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1669 static void qlt_send_notify_ack(struct qla_qpair *qpair,
1670 struct imm_ntfy_from_isp *ntfy,
1671 uint32_t add_flags, uint16_t resp_code, int resp_code_valid,
1672 uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan)
1674 struct scsi_qla_host *vha = qpair->vha;
1675 struct qla_hw_data *ha = vha->hw;
1677 struct nack_to_isp *nack;
1679 if (!ha->flags.fw_started)
1682 ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha);
1684 pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL);
1686 ql_dbg(ql_dbg_tgt, vha, 0xe049,
1687 "qla_target(%d): %s failed: unable to allocate "
1688 "request packet\n", vha->vp_idx, __func__);
1692 if (vha->vha_tgt.qla_tgt != NULL)
1693 vha->vha_tgt.qla_tgt->notify_ack_expected++;
1695 pkt->entry_type = NOTIFY_ACK_TYPE;
1696 pkt->entry_count = 1;
1698 nack = (struct nack_to_isp *)pkt;
1699 nack->ox_id = ntfy->ox_id;
1701 nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE;
1702 nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
1703 if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
1704 nack->u.isp24.flags = ntfy->u.isp24.flags &
1705 cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB);
1707 nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
1708 nack->u.isp24.status = ntfy->u.isp24.status;
1709 nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode;
1710 nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle;
1711 nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address;
1712 nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs;
1713 nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui;
1714 nack->u.isp24.srr_flags = cpu_to_le16(srr_flags);
1715 nack->u.isp24.srr_reject_code = srr_reject_code;
1716 nack->u.isp24.srr_reject_code_expl = srr_explan;
1717 nack->u.isp24.vp_index = ntfy->u.isp24.vp_index;
1719 ql_dbg(ql_dbg_tgt, vha, 0xe005,
1720 "qla_target(%d): Sending 24xx Notify Ack %d\n",
1721 vha->vp_idx, nack->u.isp24.status);
1723 /* Memory Barrier */
1725 qla2x00_start_iocbs(vha, qpair->req);
1728 static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd)
1730 struct scsi_qla_host *vha = mcmd->vha;
1731 struct qla_hw_data *ha = vha->hw;
1732 struct abts_resp_to_24xx *resp;
1736 struct abts_recv_from_24xx *abts = &mcmd->orig_iocb.abts;
1737 struct qla_qpair *qpair = mcmd->qpair;
1739 ql_dbg(ql_dbg_tgt, vha, 0xe006,
1740 "Sending task mgmt ABTS response (ha=%p, status=%x)\n",
1741 ha, mcmd->fc_tm_rsp);
1743 rc = qlt_check_reserve_free_req(qpair, 1);
1745 ql_dbg(ql_dbg_tgt, vha, 0xe04a,
1746 "qla_target(%d): %s failed: unable to allocate request packet\n",
1747 vha->vp_idx, __func__);
1751 resp = (struct abts_resp_to_24xx *)qpair->req->ring_ptr;
1752 memset(resp, 0, sizeof(*resp));
1754 h = qlt_make_handle(qpair);
1755 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
1757 * CTIO type 7 from the firmware doesn't provide a way to
1758 * know the initiator's LOOP ID, hence we can't find
1759 * the session and, so, the command.
1763 qpair->req->outstanding_cmds[h] = (srb_t *)mcmd;
1766 resp->handle = MAKE_HANDLE(qpair->req->id, h);
1767 resp->entry_type = ABTS_RESP_24XX;
1768 resp->entry_count = 1;
1769 resp->nport_handle = abts->nport_handle;
1770 resp->vp_index = vha->vp_idx;
1771 resp->sof_type = abts->sof_type;
1772 resp->exchange_address = abts->exchange_address;
1773 resp->fcp_hdr_le = abts->fcp_hdr_le;
1774 f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
1775 F_CTL_LAST_SEQ | F_CTL_END_SEQ |
1776 F_CTL_SEQ_INITIATIVE);
1777 p = (uint8_t *)&f_ctl;
1778 resp->fcp_hdr_le.f_ctl[0] = *p++;
1779 resp->fcp_hdr_le.f_ctl[1] = *p++;
1780 resp->fcp_hdr_le.f_ctl[2] = *p;
1782 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
1783 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
1785 resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
1786 if (mcmd->fc_tm_rsp == FCP_TMF_CMPL) {
1787 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
1788 resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
1789 resp->payload.ba_acct.low_seq_cnt = 0x0000;
1790 resp->payload.ba_acct.high_seq_cnt = 0xFFFF;
1791 resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
1792 resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
1794 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT;
1795 resp->payload.ba_rjt.reason_code =
1796 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM;
1797 /* Other bytes are zero */
1800 vha->vha_tgt.qla_tgt->abts_resp_expected++;
1802 /* Memory Barrier */
1804 if (qpair->reqq_start_iocbs)
1805 qpair->reqq_start_iocbs(qpair);
1807 qla2x00_start_iocbs(vha, qpair->req);
1813 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1815 static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair,
1816 struct abts_recv_from_24xx *abts, uint32_t status,
1819 struct scsi_qla_host *vha = qpair->vha;
1820 struct qla_hw_data *ha = vha->hw;
1821 struct abts_resp_to_24xx *resp;
1825 ql_dbg(ql_dbg_tgt, vha, 0xe006,
1826 "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
1829 resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair,
1832 ql_dbg(ql_dbg_tgt, vha, 0xe04a,
1833 "qla_target(%d): %s failed: unable to allocate "
1834 "request packet", vha->vp_idx, __func__);
1838 resp->entry_type = ABTS_RESP_24XX;
1839 resp->handle = QLA_TGT_SKIP_HANDLE;
1840 resp->entry_count = 1;
1841 resp->nport_handle = abts->nport_handle;
1842 resp->vp_index = vha->vp_idx;
1843 resp->sof_type = abts->sof_type;
1844 resp->exchange_address = abts->exchange_address;
1845 resp->fcp_hdr_le = abts->fcp_hdr_le;
1846 f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
1847 F_CTL_LAST_SEQ | F_CTL_END_SEQ |
1848 F_CTL_SEQ_INITIATIVE);
1849 p = (uint8_t *)&f_ctl;
1850 resp->fcp_hdr_le.f_ctl[0] = *p++;
1851 resp->fcp_hdr_le.f_ctl[1] = *p++;
1852 resp->fcp_hdr_le.f_ctl[2] = *p;
1854 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.d_id;
1855 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.s_id;
1857 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
1858 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
1860 resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
1861 if (status == FCP_TMF_CMPL) {
1862 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
1863 resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
1864 resp->payload.ba_acct.low_seq_cnt = 0x0000;
1865 resp->payload.ba_acct.high_seq_cnt = 0xFFFF;
1866 resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
1867 resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
1869 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT;
1870 resp->payload.ba_rjt.reason_code =
1871 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM;
1872 /* Other bytes are zero */
1875 vha->vha_tgt.qla_tgt->abts_resp_expected++;
1877 /* Memory Barrier */
1879 if (qpair->reqq_start_iocbs)
1880 qpair->reqq_start_iocbs(qpair);
1882 qla2x00_start_iocbs(vha, qpair->req);
1886 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1888 static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha,
1889 struct qla_qpair *qpair, response_t *pkt, struct qla_tgt_mgmt_cmd *mcmd)
1891 struct ctio7_to_24xx *ctio;
1893 struct abts_recv_from_24xx *entry;
1895 ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, NULL);
1897 ql_dbg(ql_dbg_tgt, vha, 0xe04b,
1898 "qla_target(%d): %s failed: unable to allocate "
1899 "request packet\n", vha->vp_idx, __func__);
1904 /* abts from remote port */
1905 entry = &mcmd->orig_iocb.abts;
1907 /* abts from this driver. */
1908 entry = (struct abts_recv_from_24xx *)pkt;
1911 * We've got on entrance firmware's response on by us generated
1912 * ABTS response. So, in it ID fields are reversed.
1915 ctio->entry_type = CTIO_TYPE7;
1916 ctio->entry_count = 1;
1917 ctio->nport_handle = entry->nport_handle;
1918 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
1919 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
1920 ctio->vp_index = vha->vp_idx;
1921 ctio->exchange_addr = entry->exchange_addr_to_abort;
1922 tmp = (CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_TERMINATE);
1925 ctio->initiator_id = entry->fcp_hdr_le.s_id;
1927 if (mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID)
1928 tmp |= (mcmd->abort_io_attr << 9);
1929 else if (qpair->retry_term_cnt & 1)
1932 ctio->initiator_id = entry->fcp_hdr_le.d_id;
1934 if (qpair->retry_term_cnt & 1)
1937 ctio->u.status1.flags = cpu_to_le16(tmp);
1938 ctio->u.status1.ox_id = entry->fcp_hdr_le.ox_id;
1940 ql_dbg(ql_dbg_tgt, vha, 0xe007,
1941 "Sending retry TERM EXCH CTIO7 flags %04xh oxid %04xh attr valid %x\n",
1942 le16_to_cpu(ctio->u.status1.flags),
1943 le16_to_cpu(ctio->u.status1.ox_id),
1944 (mcmd && mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) ? 1 : 0);
1946 /* Memory Barrier */
1948 if (qpair->reqq_start_iocbs)
1949 qpair->reqq_start_iocbs(qpair);
1951 qla2x00_start_iocbs(vha, qpair->req);
1954 qlt_build_abts_resp_iocb(mcmd);
1956 qlt_24xx_send_abts_resp(qpair,
1957 (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true);
1961 /* drop cmds for the given lun
1962 * XXX only looks for cmds on the port through which lun reset was recieved
1963 * XXX does not go through the list of other port (which may have cmds
1966 static void abort_cmds_for_lun(struct scsi_qla_host *vha, u64 lun, be_id_t s_id)
1968 struct qla_tgt_sess_op *op;
1969 struct qla_tgt_cmd *cmd;
1971 unsigned long flags;
1973 key = sid_to_key(s_id);
1974 spin_lock_irqsave(&vha->cmd_list_lock, flags);
1975 list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) {
1979 op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
1980 op_lun = scsilun_to_int(
1981 (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun);
1982 if (op_key == key && op_lun == lun)
1986 list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
1990 op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
1991 op_lun = scsilun_to_int(
1992 (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun);
1993 if (op_key == key && op_lun == lun)
1997 list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
2001 cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id);
2002 cmd_lun = scsilun_to_int(
2003 (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun);
2004 if (cmd_key == key && cmd_lun == lun)
2007 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
2010 static struct qla_qpair_hint *qlt_find_qphint(struct scsi_qla_host *vha,
2011 uint64_t unpacked_lun)
2013 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
2014 struct qla_qpair_hint *h = NULL;
2016 if (vha->flags.qpairs_available) {
2017 h = btree_lookup64(&tgt->lun_qpair_map, unpacked_lun);
2019 h = &tgt->qphints[0];
2021 h = &tgt->qphints[0];
2027 static void qlt_do_tmr_work(struct work_struct *work)
2029 struct qla_tgt_mgmt_cmd *mcmd =
2030 container_of(work, struct qla_tgt_mgmt_cmd, work);
2031 struct qla_hw_data *ha = mcmd->vha->hw;
2034 unsigned long flags;
2036 switch (mcmd->tmr_func) {
2038 tag = mcmd->orig_iocb.abts.exchange_addr_to_abort;
2045 rc = ha->tgt.tgt_ops->handle_tmr(mcmd, mcmd->unpacked_lun,
2046 mcmd->tmr_func, tag);
2049 spin_lock_irqsave(mcmd->qpair->qp_lock_ptr, flags);
2050 switch (mcmd->tmr_func) {
2052 mcmd->fc_tm_rsp = FCP_TMF_REJECTED;
2053 qlt_build_abts_resp_iocb(mcmd);
2055 case QLA_TGT_LUN_RESET:
2056 case QLA_TGT_CLEAR_TS:
2057 case QLA_TGT_ABORT_TS:
2058 case QLA_TGT_CLEAR_ACA:
2059 case QLA_TGT_TARGET_RESET:
2060 qlt_send_busy(mcmd->qpair, &mcmd->orig_iocb.atio,
2064 case QLA_TGT_ABORT_ALL:
2065 case QLA_TGT_NEXUS_LOSS_SESS:
2066 case QLA_TGT_NEXUS_LOSS:
2067 qlt_send_notify_ack(mcmd->qpair,
2068 &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0);
2071 spin_unlock_irqrestore(mcmd->qpair->qp_lock_ptr, flags);
2073 ql_dbg(ql_dbg_tgt_mgt, mcmd->vha, 0xf052,
2074 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
2075 mcmd->vha->vp_idx, rc);
2076 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
2080 /* ha->hardware_lock supposed to be held on entry */
2081 static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha,
2082 struct abts_recv_from_24xx *abts, struct fc_port *sess)
2084 struct qla_hw_data *ha = vha->hw;
2085 struct qla_tgt_mgmt_cmd *mcmd;
2086 struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0];
2088 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f,
2089 "qla_target(%d): task abort (tag=%d)\n",
2090 vha->vp_idx, abts->exchange_addr_to_abort);
2092 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
2094 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051,
2095 "qla_target(%d): %s: Allocation of ABORT cmd failed",
2096 vha->vp_idx, __func__);
2099 memset(mcmd, 0, sizeof(*mcmd));
2100 mcmd->cmd_type = TYPE_TGT_TMCMD;
2102 memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts));
2103 mcmd->reset_count = ha->base_qpair->chip_reset;
2104 mcmd->tmr_func = QLA_TGT_ABTS;
2105 mcmd->qpair = h->qpair;
2109 * LUN is looked up by target-core internally based on the passed
2110 * abts->exchange_addr_to_abort tag.
2112 mcmd->se_cmd.cpuid = h->cpuid;
2114 if (ha->tgt.tgt_ops->find_cmd_by_tag) {
2115 struct qla_tgt_cmd *abort_cmd;
2117 abort_cmd = ha->tgt.tgt_ops->find_cmd_by_tag(sess,
2118 abts->exchange_addr_to_abort);
2119 if (abort_cmd && abort_cmd->qpair) {
2120 mcmd->qpair = abort_cmd->qpair;
2121 mcmd->se_cmd.cpuid = abort_cmd->se_cmd.cpuid;
2122 mcmd->abort_io_attr = abort_cmd->atio.u.isp24.attr;
2123 mcmd->flags = QLA24XX_MGMT_ABORT_IO_ATTR_VALID;
2127 INIT_WORK(&mcmd->work, qlt_do_tmr_work);
2128 queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, &mcmd->work);
2134 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2136 static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
2137 struct abts_recv_from_24xx *abts)
2139 struct qla_hw_data *ha = vha->hw;
2140 struct fc_port *sess;
2141 uint32_t tag = abts->exchange_addr_to_abort;
2144 unsigned long flags;
2146 if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) {
2147 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053,
2148 "qla_target(%d): ABTS: Abort Sequence not "
2149 "supported\n", vha->vp_idx);
2150 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2155 if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) {
2156 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010,
2157 "qla_target(%d): ABTS: Unknown Exchange "
2158 "Address received\n", vha->vp_idx);
2159 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2164 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011,
2165 "qla_target(%d): task abort (s_id=%x:%x:%x, "
2166 "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id.domain,
2167 abts->fcp_hdr_le.s_id.area, abts->fcp_hdr_le.s_id.al_pa, tag,
2168 le32_to_cpu(abts->fcp_hdr_le.parameter));
2170 s_id = le_id_to_be(abts->fcp_hdr_le.s_id);
2172 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2173 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
2175 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012,
2176 "qla_target(%d): task abort for non-existent session\n",
2178 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2180 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2184 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2187 if (sess->deleted) {
2188 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2193 rc = __qlt_24xx_handle_abts(vha, abts, sess);
2195 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054,
2196 "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
2198 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2205 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2207 static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair,
2208 struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code)
2210 struct scsi_qla_host *ha = mcmd->vha;
2211 struct atio_from_isp *atio = &mcmd->orig_iocb.atio;
2212 struct ctio7_to_24xx *ctio;
2215 ql_dbg(ql_dbg_tgt, ha, 0xe008,
2216 "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
2217 ha, atio, resp_code);
2220 ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL);
2222 ql_dbg(ql_dbg_tgt, ha, 0xe04c,
2223 "qla_target(%d): %s failed: unable to allocate "
2224 "request packet\n", ha->vp_idx, __func__);
2228 ctio->entry_type = CTIO_TYPE7;
2229 ctio->entry_count = 1;
2230 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
2231 ctio->nport_handle = mcmd->sess->loop_id;
2232 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2233 ctio->vp_index = ha->vp_idx;
2234 ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2235 ctio->exchange_addr = atio->u.isp24.exchange_addr;
2236 temp = (atio->u.isp24.attr << 9)|
2237 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
2238 ctio->u.status1.flags = cpu_to_le16(temp);
2239 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2240 ctio->u.status1.ox_id = cpu_to_le16(temp);
2241 ctio->u.status1.scsi_status =
2242 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID);
2243 ctio->u.status1.response_len = cpu_to_le16(8);
2244 ctio->u.status1.sense_data[0] = resp_code;
2246 /* Memory Barrier */
2248 if (qpair->reqq_start_iocbs)
2249 qpair->reqq_start_iocbs(qpair);
2251 qla2x00_start_iocbs(ha, qpair->req);
2254 void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd)
2256 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
2258 EXPORT_SYMBOL(qlt_free_mcmd);
2261 * ha->hardware_lock supposed to be held on entry. Might drop it, then
2264 void qlt_send_resp_ctio(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd,
2265 uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq)
2267 struct atio_from_isp *atio = &cmd->atio;
2268 struct ctio7_to_24xx *ctio;
2270 struct scsi_qla_host *vha = cmd->vha;
2272 ql_dbg(ql_dbg_tgt_dif, vha, 0x3066,
2273 "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, "
2274 "sense_key=%02x, asc=%02x, ascq=%02x",
2275 vha, atio, scsi_status, sense_key, asc, ascq);
2277 ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL);
2279 ql_dbg(ql_dbg_async, vha, 0x3067,
2280 "qla2x00t(%ld): %s failed: unable to allocate request packet",
2281 vha->host_no, __func__);
2285 ctio->entry_type = CTIO_TYPE7;
2286 ctio->entry_count = 1;
2287 ctio->handle = QLA_TGT_SKIP_HANDLE;
2288 ctio->nport_handle = cmd->sess->loop_id;
2289 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2290 ctio->vp_index = vha->vp_idx;
2291 ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2292 ctio->exchange_addr = atio->u.isp24.exchange_addr;
2293 temp = (atio->u.isp24.attr << 9) |
2294 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
2295 ctio->u.status1.flags = cpu_to_le16(temp);
2296 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2297 ctio->u.status1.ox_id = cpu_to_le16(temp);
2298 ctio->u.status1.scsi_status =
2299 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status);
2300 ctio->u.status1.response_len = cpu_to_le16(18);
2301 ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio));
2303 if (ctio->u.status1.residual != 0)
2304 ctio->u.status1.scsi_status |=
2305 cpu_to_le16(SS_RESIDUAL_UNDER);
2307 /* Fixed format sense data. */
2308 ctio->u.status1.sense_data[0] = 0x70;
2309 ctio->u.status1.sense_data[2] = sense_key;
2310 /* Additional sense length */
2311 ctio->u.status1.sense_data[7] = 0xa;
2313 ctio->u.status1.sense_data[12] = asc;
2314 ctio->u.status1.sense_data[13] = ascq;
2316 /* Memory Barrier */
2319 if (qpair->reqq_start_iocbs)
2320 qpair->reqq_start_iocbs(qpair);
2322 qla2x00_start_iocbs(vha, qpair->req);
2328 /* callback from target fabric module code */
2329 void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd)
2331 struct scsi_qla_host *vha = mcmd->sess->vha;
2332 struct qla_hw_data *ha = vha->hw;
2333 unsigned long flags;
2334 struct qla_qpair *qpair = mcmd->qpair;
2335 bool free_mcmd = true;
2337 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013,
2338 "TM response mcmd (%p) status %#x state %#x",
2339 mcmd, mcmd->fc_tm_rsp, mcmd->flags);
2341 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
2343 if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) {
2345 * Either the port is not online or this request was from
2346 * previous life, just abort the processing.
2348 ql_dbg(ql_dbg_async, vha, 0xe100,
2349 "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n",
2350 vha->flags.online, qla2x00_reset_active(vha),
2351 mcmd->reset_count, qpair->chip_reset);
2352 ha->tgt.tgt_ops->free_mcmd(mcmd);
2353 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2357 if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) {
2358 switch (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode) {
2362 ql_dbg(ql_dbg_disc, vha, 0x2106,
2363 "TM response logo %8phC status %#x state %#x",
2364 mcmd->sess->port_name, mcmd->fc_tm_rsp,
2366 qlt_schedule_sess_for_deletion(mcmd->sess);
2369 qlt_send_notify_ack(vha->hw->base_qpair,
2370 &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0);
2374 if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) {
2375 qlt_build_abts_resp_iocb(mcmd);
2378 qlt_24xx_send_task_mgmt_ctio(qpair, mcmd,
2382 * Make the callback for ->free_mcmd() to queue_work() and invoke
2383 * target_put_sess_cmd() to drop cmd_kref to 1. The final
2384 * target_put_sess_cmd() call will be made from TFO->check_stop_free()
2385 * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd
2386 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
2387 * qlt_xmit_tm_rsp() returns here..
2390 ha->tgt.tgt_ops->free_mcmd(mcmd);
2392 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2394 EXPORT_SYMBOL(qlt_xmit_tm_rsp);
2397 static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm)
2399 struct qla_tgt_cmd *cmd = prm->cmd;
2401 BUG_ON(cmd->sg_cnt == 0);
2403 prm->sg = (struct scatterlist *)cmd->sg;
2404 prm->seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, cmd->sg,
2405 cmd->sg_cnt, cmd->dma_data_direction);
2406 if (unlikely(prm->seg_cnt == 0))
2409 prm->cmd->sg_mapped = 1;
2411 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) {
2413 * If greater than four sg entries then we need to allocate
2414 * the continuation entries
2416 if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX)
2417 prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt -
2418 QLA_TGT_DATASEGS_PER_CMD_24XX,
2419 QLA_TGT_DATASEGS_PER_CONT_24XX);
2422 if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) ||
2423 (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) {
2424 prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz);
2425 prm->tot_dsds = prm->seg_cnt;
2427 prm->tot_dsds = prm->seg_cnt;
2429 if (cmd->prot_sg_cnt) {
2430 prm->prot_sg = cmd->prot_sg;
2431 prm->prot_seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev,
2432 cmd->prot_sg, cmd->prot_sg_cnt,
2433 cmd->dma_data_direction);
2434 if (unlikely(prm->prot_seg_cnt == 0))
2437 if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) ||
2438 (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) {
2439 /* Dif Bundling not support here */
2440 prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen,
2442 prm->tot_dsds += prm->prot_seg_cnt;
2444 prm->tot_dsds += prm->prot_seg_cnt;
2451 ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d,
2452 "qla_target(%d): PCI mapping failed: sg_cnt=%d",
2453 0, prm->cmd->sg_cnt);
2457 static void qlt_unmap_sg(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd)
2459 struct qla_hw_data *ha;
2460 struct qla_qpair *qpair;
2462 if (!cmd->sg_mapped)
2467 dma_unmap_sg(&qpair->pdev->dev, cmd->sg, cmd->sg_cnt,
2468 cmd->dma_data_direction);
2471 if (cmd->prot_sg_cnt)
2472 dma_unmap_sg(&qpair->pdev->dev, cmd->prot_sg, cmd->prot_sg_cnt,
2473 cmd->dma_data_direction);
2478 if (cmd->ctx_dsd_alloced)
2479 qla2x00_clean_dsd_pool(ha, cmd->ctx);
2481 dma_pool_free(ha->dl_dma_pool, cmd->ctx, cmd->ctx->crc_ctx_dma);
2484 static int qlt_check_reserve_free_req(struct qla_qpair *qpair,
2488 struct req_que *req = qpair->req;
2490 if (req->cnt < (req_cnt + 2)) {
2491 cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr :
2492 RD_REG_DWORD_RELAXED(req->req_q_out));
2494 if (req->ring_index < cnt)
2495 req->cnt = cnt - req->ring_index;
2497 req->cnt = req->length - (req->ring_index - cnt);
2499 if (unlikely(req->cnt < (req_cnt + 2)))
2503 req->cnt -= req_cnt;
2509 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2511 static inline void *qlt_get_req_pkt(struct req_que *req)
2513 /* Adjust ring index. */
2515 if (req->ring_index == req->length) {
2516 req->ring_index = 0;
2517 req->ring_ptr = req->ring;
2521 return (cont_entry_t *)req->ring_ptr;
2524 /* ha->hardware_lock supposed to be held on entry */
2525 static inline uint32_t qlt_make_handle(struct qla_qpair *qpair)
2530 struct req_que *req = qpair->req;
2532 h = req->current_outstanding_cmd;
2534 for (index = 1; index < req->num_outstanding_cmds; index++) {
2536 if (h == req->num_outstanding_cmds)
2539 if (h == QLA_TGT_SKIP_HANDLE)
2542 if (!req->outstanding_cmds[h]) {
2549 req->current_outstanding_cmd = h;
2551 ql_dbg(ql_dbg_io, qpair->vha, 0x305b,
2552 "qla_target(%d): Ran out of empty cmd slots\n",
2553 qpair->vha->vp_idx);
2554 h = QLA_TGT_NULL_HANDLE;
2560 /* ha->hardware_lock supposed to be held on entry */
2561 static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair,
2562 struct qla_tgt_prm *prm)
2565 struct ctio7_to_24xx *pkt;
2566 struct atio_from_isp *atio = &prm->cmd->atio;
2569 pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr;
2571 memset(pkt, 0, sizeof(*pkt));
2573 pkt->entry_type = CTIO_TYPE7;
2574 pkt->entry_count = (uint8_t)prm->req_cnt;
2575 pkt->vp_index = prm->cmd->vp_idx;
2577 h = qlt_make_handle(qpair);
2578 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
2580 * CTIO type 7 from the firmware doesn't provide a way to
2581 * know the initiator's LOOP ID, hence we can't find
2582 * the session and, so, the command.
2586 qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
2588 pkt->handle = MAKE_HANDLE(qpair->req->id, h);
2589 pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
2590 pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
2591 pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2592 pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2593 pkt->exchange_addr = atio->u.isp24.exchange_addr;
2594 temp = atio->u.isp24.attr << 9;
2595 pkt->u.status0.flags |= cpu_to_le16(temp);
2596 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2597 pkt->u.status0.ox_id = cpu_to_le16(temp);
2598 pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset);
2604 * ha->hardware_lock supposed to be held on entry. We have already made sure
2605 * that there is sufficient amount of request entries to not drop it.
2607 static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm)
2610 struct dsd64 *cur_dsd;
2612 /* Build continuation packets */
2613 while (prm->seg_cnt > 0) {
2614 cont_a64_entry_t *cont_pkt64 =
2615 (cont_a64_entry_t *)qlt_get_req_pkt(
2616 prm->cmd->qpair->req);
2619 * Make sure that from cont_pkt64 none of
2620 * 64-bit specific fields used for 32-bit
2621 * addressing. Cast to (cont_entry_t *) for
2625 memset(cont_pkt64, 0, sizeof(*cont_pkt64));
2627 cont_pkt64->entry_count = 1;
2628 cont_pkt64->sys_define = 0;
2630 cont_pkt64->entry_type = CONTINUE_A64_TYPE;
2631 cur_dsd = cont_pkt64->dsd;
2633 /* Load continuation entry data segments */
2635 cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt;
2636 cnt++, prm->seg_cnt--) {
2637 append_dsd64(&cur_dsd, prm->sg);
2638 prm->sg = sg_next(prm->sg);
2644 * ha->hardware_lock supposed to be held on entry. We have already made sure
2645 * that there is sufficient amount of request entries to not drop it.
2647 static void qlt_load_data_segments(struct qla_tgt_prm *prm)
2650 struct dsd64 *cur_dsd;
2651 struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt;
2653 pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen);
2655 /* Setup packet address segment pointer */
2656 cur_dsd = &pkt24->u.status0.dsd;
2658 /* Set total data segment count */
2660 pkt24->dseg_count = cpu_to_le16(prm->seg_cnt);
2662 if (prm->seg_cnt == 0) {
2663 /* No data transfer */
2664 cur_dsd->address = 0;
2665 cur_dsd->length = 0;
2669 /* If scatter gather */
2671 /* Load command entry data segments */
2673 (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt;
2674 cnt++, prm->seg_cnt--) {
2675 append_dsd64(&cur_dsd, prm->sg);
2676 prm->sg = sg_next(prm->sg);
2679 qlt_load_cont_data_segments(prm);
2682 static inline int qlt_has_data(struct qla_tgt_cmd *cmd)
2684 return cmd->bufflen > 0;
2687 static void qlt_print_dif_err(struct qla_tgt_prm *prm)
2689 struct qla_tgt_cmd *cmd;
2690 struct scsi_qla_host *vha;
2692 /* asc 0x10=dif error */
2693 if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) {
2697 switch (prm->sense_buffer[13]) {
2699 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b,
2700 "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2701 "se_cmd=%p tag[%x]",
2702 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2703 cmd->atio.u.isp24.exchange_addr);
2706 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c,
2707 "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2708 "se_cmd=%p tag[%x]",
2709 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2710 cmd->atio.u.isp24.exchange_addr);
2713 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f,
2714 "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2715 "se_cmd=%p tag[%x]",
2716 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2717 cmd->atio.u.isp24.exchange_addr);
2720 ql_dbg(ql_dbg_tgt_dif, vha, 0xe010,
2721 "BE detected Dif ERR: lba[%llx|%lld] len[%x] "
2722 "se_cmd=%p tag[%x]",
2723 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2724 cmd->atio.u.isp24.exchange_addr);
2727 ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16);
2732 * Called without ha->hardware_lock held
2734 static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd,
2735 struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status,
2736 uint32_t *full_req_cnt)
2738 struct se_cmd *se_cmd = &cmd->se_cmd;
2739 struct qla_qpair *qpair = cmd->qpair;
2742 prm->tgt = cmd->tgt;
2744 prm->rq_result = scsi_status;
2745 prm->sense_buffer = &cmd->sense_buffer[0];
2746 prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER;
2751 prm->add_status_pkt = 0;
2752 prm->prot_sg = NULL;
2753 prm->prot_seg_cnt = 0;
2756 if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) {
2757 if (qlt_pci_map_calc_cnt(prm) != 0)
2761 *full_req_cnt = prm->req_cnt;
2763 if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
2764 prm->residual = se_cmd->residual_count;
2765 ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c,
2766 "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2767 prm->residual, se_cmd->tag,
2768 se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0,
2769 cmd->bufflen, prm->rq_result);
2770 prm->rq_result |= SS_RESIDUAL_UNDER;
2771 } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) {
2772 prm->residual = se_cmd->residual_count;
2773 ql_dbg_qp(ql_dbg_io, qpair, 0x305d,
2774 "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2775 prm->residual, se_cmd->tag, se_cmd->t_task_cdb ?
2776 se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result);
2777 prm->rq_result |= SS_RESIDUAL_OVER;
2780 if (xmit_type & QLA_TGT_XMIT_STATUS) {
2782 * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be
2783 * ignored in *xmit_response() below
2785 if (qlt_has_data(cmd)) {
2786 if (QLA_TGT_SENSE_VALID(prm->sense_buffer) ||
2787 (IS_FWI2_CAPABLE(cmd->vha->hw) &&
2788 (prm->rq_result != 0))) {
2789 prm->add_status_pkt = 1;
2798 static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd,
2801 if (cmd->qpair->enable_class_2)
2805 return cmd->conf_compl_supported;
2807 return cmd->qpair->enable_explicit_conf &&
2808 cmd->conf_compl_supported;
2811 static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio,
2812 struct qla_tgt_prm *prm)
2814 prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len,
2815 (uint32_t)sizeof(ctio->u.status1.sense_data));
2816 ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS);
2817 if (qlt_need_explicit_conf(prm->cmd, 0)) {
2818 ctio->u.status0.flags |= cpu_to_le16(
2819 CTIO7_FLAGS_EXPLICIT_CONFORM |
2820 CTIO7_FLAGS_CONFORM_REQ);
2822 ctio->u.status0.residual = cpu_to_le32(prm->residual);
2823 ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result);
2824 if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) {
2827 if (qlt_need_explicit_conf(prm->cmd, 1)) {
2828 if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) {
2829 ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017,
2830 "Skipping EXPLICIT_CONFORM and "
2831 "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
2832 "non GOOD status\n");
2833 goto skip_explict_conf;
2835 ctio->u.status1.flags |= cpu_to_le16(
2836 CTIO7_FLAGS_EXPLICIT_CONFORM |
2837 CTIO7_FLAGS_CONFORM_REQ);
2840 ctio->u.status1.flags &=
2841 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
2842 ctio->u.status1.flags |=
2843 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
2844 ctio->u.status1.scsi_status |=
2845 cpu_to_le16(SS_SENSE_LEN_VALID);
2846 ctio->u.status1.sense_length =
2847 cpu_to_le16(prm->sense_buffer_len);
2848 for (i = 0; i < prm->sense_buffer_len/4; i++)
2849 ((uint32_t *)ctio->u.status1.sense_data)[i] =
2850 cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]);
2852 qlt_print_dif_err(prm);
2855 ctio->u.status1.flags &=
2856 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
2857 ctio->u.status1.flags |=
2858 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
2859 ctio->u.status1.sense_length = 0;
2860 memset(ctio->u.status1.sense_data, 0,
2861 sizeof(ctio->u.status1.sense_data));
2864 /* Sense with len > 24, is it possible ??? */
2868 qlt_hba_err_chk_enabled(struct se_cmd *se_cmd)
2870 switch (se_cmd->prot_op) {
2871 case TARGET_PROT_DOUT_INSERT:
2872 case TARGET_PROT_DIN_STRIP:
2873 if (ql2xenablehba_err_chk >= 1)
2876 case TARGET_PROT_DOUT_PASS:
2877 case TARGET_PROT_DIN_PASS:
2878 if (ql2xenablehba_err_chk >= 2)
2881 case TARGET_PROT_DIN_INSERT:
2882 case TARGET_PROT_DOUT_STRIP:
2891 qla_tgt_ref_mask_check(struct se_cmd *se_cmd)
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:
2908 * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command
2911 qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx,
2912 uint16_t *pfw_prot_opts)
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;
2921 * wait till Mode Sense/Select cmd, modepage Ah, subpage 2
2922 * have been immplemented by TCM, before AppTag is avail.
2923 * Look for modesense_handlers[]
2926 ctx->app_tag_mask[0] = 0x0;
2927 ctx->app_tag_mask[1] = 0x0;
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;
2937 t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts);
2939 switch (se_cmd->prot_type) {
2940 case TARGET_DIF_TYPE0_PROT:
2942 * No check for ql2xenablehba_err_chk, as it
2943 * would be an I/O error if hba tag generation
2946 ctx->ref_tag = cpu_to_le32(lba);
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;
2953 case TARGET_DIF_TYPE1_PROT:
2955 * For TYPE 1 protection: 16 bit GUARD tag, 32 bit
2956 * REF tag, and 16 bit app tag.
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;
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;
2970 case TARGET_DIF_TYPE2_PROT:
2972 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF
2973 * tag has to match LBA in CDB + N
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;
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;
2987 case TARGET_DIF_TYPE3_PROT:
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;
2997 qlt_build_ctio_crc2_pkt(struct qla_qpair *qpair, struct qla_tgt_prm *prm)
2999 struct dsd64 *cur_dsd;
3000 uint32_t transfer_length = 0;
3001 uint32_t data_bytes;
3003 uint8_t bundling = 1;
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;
3012 struct atio_from_isp *atio = &prm->cmd->atio;
3013 struct qla_tc_param tc;
3015 scsi_qla_host_t *vha = cmd->vha;
3019 pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr;
3021 memset(pkt, 0, sizeof(*pkt));
3023 ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071,
3024 "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n",
3025 cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op,
3026 prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba);
3028 if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) ||
3029 (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP))
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;
3036 switch (se_cmd->prot_op) {
3037 case TARGET_PROT_DIN_INSERT:
3038 case TARGET_PROT_DOUT_STRIP:
3039 transfer_length = data_bytes;
3040 if (cmd->prot_sg_cnt)
3041 data_bytes += dif_bytes;
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;
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;
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;
3070 case TARGET_PROT_DIN_STRIP:
3071 case TARGET_PROT_DOUT_STRIP:
3072 fw_prot_opts |= PO_MODE_DIF_REMOVE;
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? */
3079 default:/* Normal Request */
3080 fw_prot_opts |= PO_MODE_DIF_PASS;
3085 /* Update entry type to indicate Command Type CRC_2 IOCB */
3086 pkt->entry_type = CTIO_CRC2;
3087 pkt->entry_count = 1;
3088 pkt->vp_index = cmd->vp_idx;
3090 h = qlt_make_handle(qpair);
3091 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
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.
3099 qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
3101 pkt->handle = MAKE_HANDLE(qpair->req->id, h);
3102 pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
3103 pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
3104 pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
3105 pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
3106 pkt->exchange_addr = atio->u.isp24.exchange_addr;
3108 /* silence compile warning */
3109 t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
3110 pkt->ox_id = cpu_to_le16(t16);
3112 t16 = (atio->u.isp24.attr << 9);
3113 pkt->flags |= cpu_to_le16(t16);
3114 pkt->relative_offset = cpu_to_le32(prm->cmd->offset);
3116 /* Set transfer direction */
3117 if (cmd->dma_data_direction == DMA_TO_DEVICE)
3118 pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN);
3119 else if (cmd->dma_data_direction == DMA_FROM_DEVICE)
3120 pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT);
3122 pkt->dseg_count = prm->tot_dsds;
3123 /* Fibre channel byte count */
3124 pkt->transfer_length = cpu_to_le32(transfer_length);
3126 /* ----- CRC context -------- */
3128 /* Allocate CRC context from global pool */
3129 crc_ctx_pkt = cmd->ctx =
3130 dma_pool_zalloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma);
3133 goto crc_queuing_error;
3135 crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma;
3136 INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list);
3139 crc_ctx_pkt->handle = pkt->handle;
3141 qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts);
3143 put_unaligned_le64(crc_ctx_dma, &pkt->crc_context_address);
3144 pkt->crc_context_len = CRC_CONTEXT_LEN_FW;
3147 cur_dsd = &crc_ctx_pkt->u.nobundling.data_dsd[0];
3150 * Configure Bundling if we need to fetch interlaving
3151 * protection PCI accesses
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);
3157 cur_dsd = &crc_ctx_pkt->u.bundling.data_dsd[0];
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);
3164 crc_ctx_pkt->guard_seed = cpu_to_le16(0);
3166 memset((uint8_t *)&tc, 0 , sizeof(tc));
3168 tc.blk_sz = cmd->blk_sz;
3169 tc.bufflen = cmd->bufflen;
3171 tc.prot_sg = cmd->prot_sg;
3172 tc.ctx = crc_ctx_pkt;
3173 tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced;
3175 /* Walks data segments */
3176 pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR);
3178 if (!bundling && prm->prot_seg_cnt) {
3179 if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd,
3180 prm->tot_dsds, &tc))
3181 goto crc_queuing_error;
3182 } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd,
3183 (prm->tot_dsds - prm->prot_seg_cnt), &tc))
3184 goto crc_queuing_error;
3186 if (bundling && prm->prot_seg_cnt) {
3187 /* Walks dif segments */
3188 pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA;
3190 cur_dsd = &crc_ctx_pkt->u.bundling.dif_dsd;
3191 if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd,
3192 prm->prot_seg_cnt, cmd))
3193 goto crc_queuing_error;
3198 /* Cleanup will be performed by the caller */
3199 qpair->req->outstanding_cmds[h] = NULL;
3201 return QLA_FUNCTION_FAILED;
3205 * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and *
3206 * QLA_TGT_XMIT_STATUS for >= 24xx silicon
3208 int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type,
3209 uint8_t scsi_status)
3211 struct scsi_qla_host *vha = cmd->vha;
3212 struct qla_qpair *qpair = cmd->qpair;
3213 struct ctio7_to_24xx *pkt;
3214 struct qla_tgt_prm prm;
3215 uint32_t full_req_cnt = 0;
3216 unsigned long flags = 0;
3219 if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) ||
3220 (cmd->sess && cmd->sess->deleted)) {
3221 cmd->state = QLA_TGT_STATE_PROCESSED;
3225 ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018,
3226 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p] qp %d\n",
3227 (xmit_type & QLA_TGT_XMIT_STATUS) ?
3228 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction,
3229 &cmd->se_cmd, qpair->id);
3231 res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status,
3233 if (unlikely(res != 0)) {
3237 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3239 if (xmit_type == QLA_TGT_XMIT_STATUS)
3240 qpair->tgt_counters.core_qla_snd_status++;
3242 qpair->tgt_counters.core_qla_que_buf++;
3244 if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) {
3246 * Either the port is not online or this request was from
3247 * previous life, just abort the processing.
3249 cmd->state = QLA_TGT_STATE_PROCESSED;
3250 ql_dbg_qp(ql_dbg_async, qpair, 0xe101,
3251 "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n",
3252 vha->flags.online, qla2x00_reset_active(vha),
3253 cmd->reset_count, qpair->chip_reset);
3255 goto out_unmap_unlock;
3258 /* Does F/W have an IOCBs for this request */
3259 res = qlt_check_reserve_free_req(qpair, full_req_cnt);
3261 goto out_unmap_unlock;
3263 if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA))
3264 res = qlt_build_ctio_crc2_pkt(qpair, &prm);
3266 res = qlt_24xx_build_ctio_pkt(qpair, &prm);
3267 if (unlikely(res != 0)) {
3268 qpair->req->cnt += full_req_cnt;
3269 goto out_unmap_unlock;
3272 pkt = (struct ctio7_to_24xx *)prm.pkt;
3274 if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) {
3275 pkt->u.status0.flags |=
3276 cpu_to_le16(CTIO7_FLAGS_DATA_IN |
3277 CTIO7_FLAGS_STATUS_MODE_0);
3279 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
3280 qlt_load_data_segments(&prm);
3282 if (prm.add_status_pkt == 0) {
3283 if (xmit_type & QLA_TGT_XMIT_STATUS) {
3284 pkt->u.status0.scsi_status =
3285 cpu_to_le16(prm.rq_result);
3286 pkt->u.status0.residual =
3287 cpu_to_le32(prm.residual);
3288 pkt->u.status0.flags |= cpu_to_le16(
3289 CTIO7_FLAGS_SEND_STATUS);
3290 if (qlt_need_explicit_conf(cmd, 0)) {
3291 pkt->u.status0.flags |=
3293 CTIO7_FLAGS_EXPLICIT_CONFORM |
3294 CTIO7_FLAGS_CONFORM_REQ);
3300 * We have already made sure that there is sufficient
3301 * amount of request entries to not drop HW lock in
3304 struct ctio7_to_24xx *ctio =
3305 (struct ctio7_to_24xx *)qlt_get_req_pkt(
3308 ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e,
3309 "Building additional status packet 0x%p.\n",
3313 * T10Dif: ctio_crc2_to_fw overlay ontop of
3316 memcpy(ctio, pkt, sizeof(*ctio));
3317 /* reset back to CTIO7 */
3318 ctio->entry_count = 1;
3319 ctio->entry_type = CTIO_TYPE7;
3320 ctio->dseg_count = 0;
3321 ctio->u.status1.flags &= ~cpu_to_le16(
3322 CTIO7_FLAGS_DATA_IN);
3324 /* Real finish is ctio_m1's finish */
3325 pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK;
3326 pkt->u.status0.flags |= cpu_to_le16(
3327 CTIO7_FLAGS_DONT_RET_CTIO);
3329 /* qlt_24xx_init_ctio_to_isp will correct
3330 * all neccessary fields that's part of CTIO7.
3331 * There should be no residual of CTIO-CRC2 data.
3333 qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio,
3337 qlt_24xx_init_ctio_to_isp(pkt, &prm);
3340 cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */
3341 cmd->cmd_sent_to_fw = 1;
3342 cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
3344 /* Memory Barrier */
3346 if (qpair->reqq_start_iocbs)
3347 qpair->reqq_start_iocbs(qpair);
3349 qla2x00_start_iocbs(vha, qpair->req);
3350 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3355 qlt_unmap_sg(vha, cmd);
3356 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3360 EXPORT_SYMBOL(qlt_xmit_response);
3362 int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd)
3364 struct ctio7_to_24xx *pkt;
3365 struct scsi_qla_host *vha = cmd->vha;
3366 struct qla_tgt *tgt = cmd->tgt;
3367 struct qla_tgt_prm prm;
3368 unsigned long flags = 0;
3370 struct qla_qpair *qpair = cmd->qpair;
3372 memset(&prm, 0, sizeof(prm));
3378 if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) ||
3379 (cmd->sess && cmd->sess->deleted)) {
3381 * Either the port is not online or this request was from
3382 * previous life, just abort the processing.
3385 cmd->write_data_transferred = 0;
3386 cmd->state = QLA_TGT_STATE_DATA_IN;
3387 vha->hw->tgt.tgt_ops->handle_data(cmd);
3388 ql_dbg_qp(ql_dbg_async, qpair, 0xe102,
3389 "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n",
3390 vha->flags.online, qla2x00_reset_active(vha),
3391 cmd->reset_count, qpair->chip_reset);
3395 /* Calculate number of entries and segments required */
3396 if (qlt_pci_map_calc_cnt(&prm) != 0)
3399 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3400 /* Does F/W have an IOCBs for this request */
3401 res = qlt_check_reserve_free_req(qpair, prm.req_cnt);
3403 goto out_unlock_free_unmap;
3404 if (cmd->se_cmd.prot_op)
3405 res = qlt_build_ctio_crc2_pkt(qpair, &prm);
3407 res = qlt_24xx_build_ctio_pkt(qpair, &prm);
3409 if (unlikely(res != 0)) {
3410 qpair->req->cnt += prm.req_cnt;
3411 goto out_unlock_free_unmap;
3414 pkt = (struct ctio7_to_24xx *)prm.pkt;
3415 pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT |
3416 CTIO7_FLAGS_STATUS_MODE_0);
3418 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
3419 qlt_load_data_segments(&prm);
3421 cmd->state = QLA_TGT_STATE_NEED_DATA;
3422 cmd->cmd_sent_to_fw = 1;
3423 cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
3425 /* Memory Barrier */
3427 if (qpair->reqq_start_iocbs)
3428 qpair->reqq_start_iocbs(qpair);
3430 qla2x00_start_iocbs(vha, qpair->req);
3431 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3435 out_unlock_free_unmap:
3436 qlt_unmap_sg(vha, cmd);
3437 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3441 EXPORT_SYMBOL(qlt_rdy_to_xfer);
3445 * it is assumed either hardware_lock or qpair lock is held.
3448 qlt_handle_dif_error(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd,
3449 struct ctio_crc_from_fw *sts)
3451 uint8_t *ap = &sts->actual_dif[0];
3452 uint8_t *ep = &sts->expected_dif[0];
3453 uint64_t lba = cmd->se_cmd.t_task_lba;
3454 uint8_t scsi_status, sense_key, asc, ascq;
3455 unsigned long flags;
3456 struct scsi_qla_host *vha = cmd->vha;
3458 cmd->trc_flags |= TRC_DIF_ERR;
3460 cmd->a_guard = be16_to_cpu(*(uint16_t *)(ap + 0));
3461 cmd->a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2));
3462 cmd->a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4));
3464 cmd->e_guard = be16_to_cpu(*(uint16_t *)(ep + 0));
3465 cmd->e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2));
3466 cmd->e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4));
3468 ql_dbg(ql_dbg_tgt_dif, vha, 0xf075,
3469 "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state);
3471 scsi_status = sense_key = asc = ascq = 0;
3473 /* check appl tag */
3474 if (cmd->e_app_tag != cmd->a_app_tag) {
3475 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d,
3476 "App Tag ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard [%x|%x] cmd=%p ox_id[%04x]",
3477 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3478 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3479 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3480 cmd->atio.u.isp24.fcp_hdr.ox_id);
3482 cmd->dif_err_code = DIF_ERR_APP;
3483 scsi_status = SAM_STAT_CHECK_CONDITION;
3484 sense_key = ABORTED_COMMAND;
3490 if (cmd->e_ref_tag != cmd->a_ref_tag) {
3491 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e,
3492 "Ref Tag ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard[%x|%x] cmd=%p ox_id[%04x] ",
3493 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3494 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3495 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3496 cmd->atio.u.isp24.fcp_hdr.ox_id);
3498 cmd->dif_err_code = DIF_ERR_REF;
3499 scsi_status = SAM_STAT_CHECK_CONDITION;
3500 sense_key = ABORTED_COMMAND;
3507 if (cmd->e_guard != cmd->a_guard) {
3508 ql_dbg(ql_dbg_tgt_dif, vha, 0xe012,
3509 "Guard ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard [%x|%x] cmd=%p ox_id[%04x]",
3510 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3511 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3512 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3513 cmd->atio.u.isp24.fcp_hdr.ox_id);
3515 cmd->dif_err_code = DIF_ERR_GRD;
3516 scsi_status = SAM_STAT_CHECK_CONDITION;
3517 sense_key = ABORTED_COMMAND;
3522 switch (cmd->state) {
3523 case QLA_TGT_STATE_NEED_DATA:
3524 /* handle_data will load DIF error code */
3525 cmd->state = QLA_TGT_STATE_DATA_IN;
3526 vha->hw->tgt.tgt_ops->handle_data(cmd);
3529 spin_lock_irqsave(&cmd->cmd_lock, flags);
3531 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3532 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3535 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3537 qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc,
3539 /* assume scsi status gets out on the wire.
3540 * Will not wait for completion.
3542 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3547 /* If hardware_lock held on entry, might drop it, then reaquire */
3548 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
3549 static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha,
3550 struct imm_ntfy_from_isp *ntfy)
3552 struct nack_to_isp *nack;
3553 struct qla_hw_data *ha = vha->hw;
3557 ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c,
3558 "Sending TERM ELS CTIO (ha=%p)\n", ha);
3560 pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL);
3562 ql_dbg(ql_dbg_tgt, vha, 0xe080,
3563 "qla_target(%d): %s failed: unable to allocate "
3564 "request packet\n", vha->vp_idx, __func__);
3568 pkt->entry_type = NOTIFY_ACK_TYPE;
3569 pkt->entry_count = 1;
3570 pkt->handle = QLA_TGT_SKIP_HANDLE;
3572 nack = (struct nack_to_isp *)pkt;
3573 nack->ox_id = ntfy->ox_id;
3575 nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
3576 if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
3577 nack->u.isp24.flags = ntfy->u.isp24.flags &
3578 __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB);
3582 nack->u.isp24.flags |=
3583 __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE);
3585 nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
3586 nack->u.isp24.status = ntfy->u.isp24.status;
3587 nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode;
3588 nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle;
3589 nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address;
3590 nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs;
3591 nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui;
3592 nack->u.isp24.vp_index = ntfy->u.isp24.vp_index;
3594 qla2x00_start_iocbs(vha, vha->req);
3598 static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
3599 struct imm_ntfy_from_isp *imm, int ha_locked)
3603 WARN_ON_ONCE(!ha_locked);
3604 rc = __qlt_send_term_imm_notif(vha, imm);
3605 pr_debug("rc = %d\n", rc);
3609 * If hardware_lock held on entry, might drop it, then reaquire
3610 * This function sends the appropriate CTIO to ISP 2xxx or 24xx
3612 static int __qlt_send_term_exchange(struct qla_qpair *qpair,
3613 struct qla_tgt_cmd *cmd,
3614 struct atio_from_isp *atio)
3616 struct scsi_qla_host *vha = qpair->vha;
3617 struct ctio7_to_24xx *ctio24;
3618 struct qla_hw_data *ha = vha->hw;
3623 ql_dbg(ql_dbg_tgt, vha, 0xe009, "Sending TERM EXCH CTIO (ha=%p)\n", ha);
3628 pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL);
3630 ql_dbg(ql_dbg_tgt, vha, 0xe050,
3631 "qla_target(%d): %s failed: unable to allocate "
3632 "request packet\n", vha->vp_idx, __func__);
3637 if (cmd->state < QLA_TGT_STATE_PROCESSED) {
3638 ql_dbg(ql_dbg_tgt, vha, 0xe051,
3639 "qla_target(%d): Terminating cmd %p with "
3640 "incorrect state %d\n", vha->vp_idx, cmd,
3646 qpair->tgt_counters.num_term_xchg_sent++;
3647 pkt->entry_count = 1;
3648 pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
3650 ctio24 = (struct ctio7_to_24xx *)pkt;
3651 ctio24->entry_type = CTIO_TYPE7;
3652 ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED;
3653 ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
3654 ctio24->vp_index = vha->vp_idx;
3655 ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
3656 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
3657 temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 |
3658 CTIO7_FLAGS_TERMINATE;
3659 ctio24->u.status1.flags = cpu_to_le16(temp);
3660 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
3661 ctio24->u.status1.ox_id = cpu_to_le16(temp);
3663 /* Memory Barrier */
3665 if (qpair->reqq_start_iocbs)
3666 qpair->reqq_start_iocbs(qpair);
3668 qla2x00_start_iocbs(vha, qpair->req);
3672 static void qlt_send_term_exchange(struct qla_qpair *qpair,
3673 struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked,
3676 struct scsi_qla_host *vha;
3677 unsigned long flags = 0;
3680 /* why use different vha? NPIV */
3687 rc = __qlt_send_term_exchange(qpair, cmd, atio);
3689 qlt_alloc_qfull_cmd(vha, atio, 0, 0);
3692 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3693 rc = __qlt_send_term_exchange(qpair, cmd, atio);
3695 qlt_alloc_qfull_cmd(vha, atio, 0, 0);
3698 if (cmd && !ul_abort && !cmd->aborted) {
3700 qlt_unmap_sg(vha, cmd);
3701 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3705 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3710 static void qlt_init_term_exchange(struct scsi_qla_host *vha)
3712 struct list_head free_list;
3713 struct qla_tgt_cmd *cmd, *tcmd;
3715 vha->hw->tgt.leak_exchg_thresh_hold =
3716 (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT;
3719 if (!list_empty(&vha->hw->tgt.q_full_list)) {
3720 INIT_LIST_HEAD(&free_list);
3721 list_splice_init(&vha->hw->tgt.q_full_list, &free_list);
3723 list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) {
3724 list_del(&cmd->cmd_list);
3725 /* This cmd was never sent to TCM. There is no need
3726 * to schedule free or call free_cmd
3729 vha->hw->tgt.num_qfull_cmds_alloc--;
3732 vha->hw->tgt.num_qfull_cmds_dropped = 0;
3735 static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha)
3737 uint32_t total_leaked;
3739 total_leaked = vha->hw->tgt.num_qfull_cmds_dropped;
3741 if (vha->hw->tgt.leak_exchg_thresh_hold &&
3742 (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) {
3744 ql_dbg(ql_dbg_tgt, vha, 0xe079,
3745 "Chip reset due to exchange starvation: %d/%d.\n",
3746 total_leaked, vha->hw->cur_fw_xcb_count);
3748 if (IS_P3P_TYPE(vha->hw))
3749 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
3751 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3752 qla2xxx_wake_dpc(vha);
3757 int qlt_abort_cmd(struct qla_tgt_cmd *cmd)
3759 struct qla_tgt *tgt = cmd->tgt;
3760 struct scsi_qla_host *vha = tgt->vha;
3761 struct se_cmd *se_cmd = &cmd->se_cmd;
3762 unsigned long flags;
3764 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014,
3765 "qla_target(%d): terminating exchange for aborted cmd=%p "
3766 "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd,
3769 spin_lock_irqsave(&cmd->cmd_lock, flags);
3772 qlt_unmap_sg(vha, cmd);
3774 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
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
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);
3787 cmd->trc_flags |= TRC_ABORT;
3788 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3790 qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1);
3793 EXPORT_SYMBOL(qlt_abort_cmd);
3795 void qlt_free_cmd(struct qla_tgt_cmd *cmd)
3797 struct fc_port *sess = cmd->sess;
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));
3804 BUG_ON(cmd->cmd_in_wq);
3807 qlt_decr_num_pend_cmds(cmd->vha);
3809 BUG_ON(cmd->sg_mapped);
3810 cmd->jiffies_at_free = get_jiffies_64();
3811 if (unlikely(cmd->free_sg))
3814 if (!sess || !sess->se_sess) {
3818 cmd->jiffies_at_free = get_jiffies_64();
3819 target_free_tag(sess->se_sess, &cmd->se_cmd);
3821 EXPORT_SYMBOL(qlt_free_cmd);
3824 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3826 static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio,
3827 struct qla_tgt_cmd *cmd, uint32_t status)
3830 struct scsi_qla_host *vha = qpair->vha;
3832 if (cmd->se_cmd.prot_op)
3833 ql_dbg(ql_dbg_tgt_dif, vha, 0xe013,
3834 "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] "
3835 "se_cmd=%p tag[%x] op %#x/%s",
3837 cmd->num_blks, &cmd->se_cmd,
3838 cmd->atio.u.isp24.exchange_addr,
3839 cmd->se_cmd.prot_op,
3840 prot_op_str(cmd->se_cmd.prot_op));
3843 struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio;
3846 cpu_to_le16(OF_TERM_EXCH));
3851 qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1, 0);
3857 /* ha->hardware_lock supposed to be held on entry */
3858 static void *qlt_ctio_to_cmd(struct scsi_qla_host *vha,
3859 struct rsp_que *rsp, uint32_t handle, void *ctio)
3862 struct req_que *req;
3863 int qid = GET_QID(handle);
3864 uint32_t h = handle & ~QLA_TGT_HANDLE_MASK;
3866 if (unlikely(h == QLA_TGT_SKIP_HANDLE))
3869 if (qid == rsp->req->id) {
3871 } else if (vha->hw->req_q_map[qid]) {
3872 ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a,
3873 "qla_target(%d): CTIO completion with different QID %d handle %x\n",
3874 vha->vp_idx, rsp->id, handle);
3875 req = vha->hw->req_q_map[qid];
3880 h &= QLA_CMD_HANDLE_MASK;
3882 if (h != QLA_TGT_NULL_HANDLE) {
3883 if (unlikely(h >= req->num_outstanding_cmds)) {
3884 ql_dbg(ql_dbg_tgt, vha, 0xe052,
3885 "qla_target(%d): Wrong handle %x received\n",
3886 vha->vp_idx, handle);
3890 cmd = (void *) req->outstanding_cmds[h];
3891 if (unlikely(cmd == NULL)) {
3892 ql_dbg(ql_dbg_async, vha, 0xe053,
3893 "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n",
3894 vha->vp_idx, handle, req->id, rsp->id);
3897 req->outstanding_cmds[h] = NULL;
3898 } else if (ctio != NULL) {
3899 /* We can't get loop ID from CTIO7 */
3900 ql_dbg(ql_dbg_tgt, vha, 0xe054,
3901 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
3902 "support NULL handles\n", vha->vp_idx);
3910 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3912 static void qlt_do_ctio_completion(struct scsi_qla_host *vha,
3913 struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio)
3915 struct qla_hw_data *ha = vha->hw;
3916 struct se_cmd *se_cmd;
3917 struct qla_tgt_cmd *cmd;
3918 struct qla_qpair *qpair = rsp->qpair;
3920 if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) {
3921 /* That could happen only in case of an error/reset/abort */
3922 if (status != CTIO_SUCCESS) {
3923 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d,
3924 "Intermediate CTIO received"
3925 " (status %x)\n", status);
3930 cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio);
3934 se_cmd = &cmd->se_cmd;
3935 cmd->cmd_sent_to_fw = 0;
3937 qlt_unmap_sg(vha, cmd);
3939 if (unlikely(status != CTIO_SUCCESS)) {
3940 switch (status & 0xFFFF) {
3941 case CTIO_INVALID_RX_ID:
3942 if (printk_ratelimit())
3943 dev_info(&vha->hw->pdev->dev,
3944 "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n",
3945 vha->vp_idx, cmd->atio.u.isp24.attr,
3946 ((cmd->ctio_flags >> 9) & 0xf),
3950 case CTIO_LIP_RESET:
3951 case CTIO_TARGET_RESET:
3953 /* driver request abort via Terminate exchange */
3956 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058,
3957 "qla_target(%d): CTIO with "
3958 "status %#x received, state %x, se_cmd %p, "
3959 "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
3960 "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx,
3961 status, cmd->state, se_cmd);
3964 case CTIO_PORT_LOGGED_OUT:
3965 case CTIO_PORT_UNAVAILABLE:
3968 (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT;
3970 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059,
3971 "qla_target(%d): CTIO with %s status %x "
3972 "received (state %x, se_cmd %p)\n", vha->vp_idx,
3973 logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE",
3974 status, cmd->state, se_cmd);
3976 if (logged_out && cmd->sess) {
3978 * Session is already logged out, but we need
3979 * to notify initiator, who's not aware of this
3981 cmd->sess->send_els_logo = 1;
3982 ql_dbg(ql_dbg_disc, vha, 0x20f8,
3983 "%s %d %8phC post del sess\n",
3984 __func__, __LINE__, cmd->sess->port_name);
3986 qlt_schedule_sess_for_deletion(cmd->sess);
3990 case CTIO_DIF_ERROR: {
3991 struct ctio_crc_from_fw *crc =
3992 (struct ctio_crc_from_fw *)ctio;
3993 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073,
3994 "qla_target(%d): CTIO with DIF_ERROR status %x "
3995 "received (state %x, ulp_cmd %p) actual_dif[0x%llx] "
3996 "expect_dif[0x%llx]\n",
3997 vha->vp_idx, status, cmd->state, se_cmd,
3998 *((u64 *)&crc->actual_dif[0]),
3999 *((u64 *)&crc->expected_dif[0]));
4001 qlt_handle_dif_error(qpair, cmd, ctio);
4005 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b,
4006 "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n",
4007 vha->vp_idx, status, cmd->state, se_cmd);
4012 /* "cmd->aborted" means
4013 * cmd is already aborted/terminated, we don't
4014 * need to terminate again. The exchange is already
4015 * cleaned up/freed at FW level. Just cleanup at driver
4018 if ((cmd->state != QLA_TGT_STATE_NEED_DATA) &&
4020 cmd->trc_flags |= TRC_CTIO_ERR;
4021 if (qlt_term_ctio_exchange(qpair, ctio, cmd, status))
4026 if (cmd->state == QLA_TGT_STATE_PROCESSED) {
4027 cmd->trc_flags |= TRC_CTIO_DONE;
4028 } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) {
4029 cmd->state = QLA_TGT_STATE_DATA_IN;
4031 if (status == CTIO_SUCCESS)
4032 cmd->write_data_transferred = 1;
4034 ha->tgt.tgt_ops->handle_data(cmd);
4036 } else if (cmd->aborted) {
4037 cmd->trc_flags |= TRC_CTIO_ABORTED;
4038 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e,
4039 "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag);
4041 cmd->trc_flags |= TRC_CTIO_STRANGE;
4042 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c,
4043 "qla_target(%d): A command in state (%d) should "
4044 "not return a CTIO complete\n", vha->vp_idx, cmd->state);
4047 if (unlikely(status != CTIO_SUCCESS) &&
4049 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n");
4053 ha->tgt.tgt_ops->free_cmd(cmd);
4056 static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha,
4061 switch (task_codes) {
4062 case ATIO_SIMPLE_QUEUE:
4063 fcp_task_attr = TCM_SIMPLE_TAG;
4065 case ATIO_HEAD_OF_QUEUE:
4066 fcp_task_attr = TCM_HEAD_TAG;
4068 case ATIO_ORDERED_QUEUE:
4069 fcp_task_attr = TCM_ORDERED_TAG;
4071 case ATIO_ACA_QUEUE:
4072 fcp_task_attr = TCM_ACA_TAG;
4075 fcp_task_attr = TCM_SIMPLE_TAG;
4078 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d,
4079 "qla_target: unknown task code %x, use ORDERED instead\n",
4081 fcp_task_attr = TCM_ORDERED_TAG;
4085 return fcp_task_attr;
4089 * Process context for I/O path into tcm_qla2xxx code
4091 static void __qlt_do_work(struct qla_tgt_cmd *cmd)
4093 scsi_qla_host_t *vha = cmd->vha;
4094 struct qla_hw_data *ha = vha->hw;
4095 struct fc_port *sess = cmd->sess;
4096 struct atio_from_isp *atio = &cmd->atio;
4098 unsigned long flags;
4099 uint32_t data_length;
4100 int ret, fcp_task_attr, data_dir, bidi = 0;
4101 struct qla_qpair *qpair = cmd->qpair;
4104 cmd->trc_flags |= TRC_DO_WORK;
4107 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082,
4108 "cmd with tag %u is aborted\n",
4109 cmd->atio.u.isp24.exchange_addr);
4113 spin_lock_init(&cmd->cmd_lock);
4114 cdb = &atio->u.isp24.fcp_cmnd.cdb[0];
4115 cmd->se_cmd.tag = atio->u.isp24.exchange_addr;
4117 if (atio->u.isp24.fcp_cmnd.rddata &&
4118 atio->u.isp24.fcp_cmnd.wrdata) {
4120 data_dir = DMA_TO_DEVICE;
4121 } else if (atio->u.isp24.fcp_cmnd.rddata)
4122 data_dir = DMA_FROM_DEVICE;
4123 else if (atio->u.isp24.fcp_cmnd.wrdata)
4124 data_dir = DMA_TO_DEVICE;
4126 data_dir = DMA_NONE;
4128 fcp_task_attr = qlt_get_fcp_task_attr(vha,
4129 atio->u.isp24.fcp_cmnd.task_attr);
4130 data_length = get_datalen_for_atio(atio);
4132 ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length,
4133 fcp_task_attr, data_dir, bidi);
4137 * Drop extra session reference from qlt_handle_cmd_for_atio().
4139 ha->tgt.tgt_ops->put_sess(sess);
4143 ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd);
4145 * cmd has not sent to target yet, so pass NULL as the second
4146 * argument to qlt_send_term_exchange() and free the memory here.
4148 cmd->trc_flags |= TRC_DO_WORK_ERR;
4149 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
4150 qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0);
4152 qlt_decr_num_pend_cmds(vha);
4153 target_free_tag(sess->se_sess, &cmd->se_cmd);
4154 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
4156 ha->tgt.tgt_ops->put_sess(sess);
4159 static void qlt_do_work(struct work_struct *work)
4161 struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work);
4162 scsi_qla_host_t *vha = cmd->vha;
4163 unsigned long flags;
4165 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4166 list_del(&cmd->cmd_list);
4167 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4172 void qlt_clr_qp_table(struct scsi_qla_host *vha)
4174 unsigned long flags;
4175 struct qla_hw_data *ha = vha->hw;
4176 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4180 ql_log(ql_log_info, vha, 0x706c,
4181 "User update Number of Active Qpairs %d\n",
4182 ha->tgt.num_act_qpairs);
4184 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
4186 btree_for_each_safe64(&tgt->lun_qpair_map, key, node)
4187 btree_remove64(&tgt->lun_qpair_map, key);
4189 ha->base_qpair->lun_cnt = 0;
4190 for (key = 0; key < ha->max_qpairs; key++)
4191 if (ha->queue_pair_map[key])
4192 ha->queue_pair_map[key]->lun_cnt = 0;
4194 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
4197 static void qlt_assign_qpair(struct scsi_qla_host *vha,
4198 struct qla_tgt_cmd *cmd)
4200 struct qla_qpair *qpair, *qp;
4201 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4202 struct qla_qpair_hint *h;
4204 if (vha->flags.qpairs_available) {
4205 h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun);
4207 /* spread lun to qpair ratio evently */
4209 struct scsi_qla_host *base_vha =
4210 pci_get_drvdata(vha->hw->pdev);
4212 qpair = vha->hw->base_qpair;
4213 if (qpair->lun_cnt == 0) {
4215 h = qla_qpair_to_hint(tgt, qpair);
4217 rc = btree_insert64(&tgt->lun_qpair_map,
4218 cmd->unpacked_lun, h, GFP_ATOMIC);
4221 ql_log(ql_log_info, vha, 0xd037,
4222 "Unable to insert lun %llx into lun_qpair_map\n",
4227 lcnt = qpair->lun_cnt;
4231 list_for_each_entry(qp, &base_vha->qp_list,
4233 if (qp->lun_cnt == 0) {
4235 h = qla_qpair_to_hint(tgt, qp);
4237 rc = btree_insert64(&tgt->lun_qpair_map,
4238 cmd->unpacked_lun, h, GFP_ATOMIC);
4241 ql_log(ql_log_info, vha, 0xd038,
4242 "Unable to insert lun %llx into lun_qpair_map\n",
4248 if (qp->lun_cnt < lcnt) {
4257 h = qla_qpair_to_hint(tgt, qpair);
4259 rc = btree_insert64(&tgt->lun_qpair_map,
4260 cmd->unpacked_lun, h, GFP_ATOMIC);
4263 ql_log(ql_log_info, vha, 0xd039,
4264 "Unable to insert lun %llx into lun_qpair_map\n",
4269 h = &tgt->qphints[0];
4272 cmd->qpair = h->qpair;
4273 cmd->se_cmd.cpuid = h->cpuid;
4276 static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha,
4277 struct fc_port *sess,
4278 struct atio_from_isp *atio)
4280 struct se_session *se_sess = sess->se_sess;
4281 struct qla_tgt_cmd *cmd;
4284 tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu);
4288 cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag];
4289 memset(cmd, 0, sizeof(struct qla_tgt_cmd));
4290 cmd->cmd_type = TYPE_TGT_CMD;
4291 memcpy(&cmd->atio, atio, sizeof(*atio));
4292 cmd->state = QLA_TGT_STATE_NEW;
4293 cmd->tgt = vha->vha_tgt.qla_tgt;
4294 qlt_incr_num_pend_cmds(vha);
4296 cmd->se_cmd.map_tag = tag;
4297 cmd->se_cmd.map_cpu = cpu;
4299 cmd->loop_id = sess->loop_id;
4300 cmd->conf_compl_supported = sess->conf_compl_supported;
4303 cmd->jiffies_at_alloc = get_jiffies_64();
4305 cmd->unpacked_lun = scsilun_to_int(
4306 (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun);
4307 qlt_assign_qpair(vha, cmd);
4308 cmd->reset_count = vha->hw->base_qpair->chip_reset;
4309 cmd->vp_idx = vha->vp_idx;
4314 /* ha->hardware_lock supposed to be held on entry */
4315 static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha,
4316 struct atio_from_isp *atio)
4318 struct qla_hw_data *ha = vha->hw;
4319 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4320 struct fc_port *sess;
4321 struct qla_tgt_cmd *cmd;
4322 unsigned long flags;
4325 if (unlikely(tgt->tgt_stop)) {
4326 ql_dbg(ql_dbg_io, vha, 0x3061,
4327 "New command while device %p is shutting down\n", tgt);
4331 id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
4332 if (IS_SW_RESV_ADDR(id))
4335 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id);
4336 if (unlikely(!sess))
4339 /* Another WWN used to have our s_id. Our PLOGI scheduled its
4340 * session deletion, but it's still in sess_del_work wq */
4341 if (sess->deleted) {
4342 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002,
4343 "New command while old session %p is being deleted\n",
4349 * Do kref_get() before returning + dropping qla_hw_data->hardware_lock.
4351 if (!kref_get_unless_zero(&sess->sess_kref)) {
4352 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004,
4353 "%s: kref_get fail, %8phC oxid %x \n",
4354 __func__, sess->port_name,
4355 be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
4359 cmd = qlt_get_tag(vha, sess, atio);
4361 ql_dbg(ql_dbg_io, vha, 0x3062,
4362 "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx);
4363 ha->tgt.tgt_ops->put_sess(sess);
4368 cmd->trc_flags |= TRC_NEW_CMD;
4370 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4371 list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list);
4372 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4374 INIT_WORK(&cmd->work, qlt_do_work);
4375 if (vha->flags.qpairs_available) {
4376 queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work);
4377 } else if (ha->msix_count) {
4378 if (cmd->atio.u.isp24.fcp_cmnd.rddata)
4379 queue_work_on(smp_processor_id(), qla_tgt_wq,
4382 queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq,
4385 queue_work(qla_tgt_wq, &cmd->work);
4391 /* ha->hardware_lock supposed to be held on entry */
4392 static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun,
4393 int fn, void *iocb, int flags)
4395 struct scsi_qla_host *vha = sess->vha;
4396 struct qla_hw_data *ha = vha->hw;
4397 struct qla_tgt_mgmt_cmd *mcmd;
4398 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4399 struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0];
4401 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
4403 ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009,
4404 "qla_target(%d): Allocation of management "
4405 "command failed, some commands and their data could "
4406 "leak\n", vha->vp_idx);
4409 memset(mcmd, 0, sizeof(*mcmd));
4413 memcpy(&mcmd->orig_iocb.imm_ntfy, iocb,
4414 sizeof(mcmd->orig_iocb.imm_ntfy));
4416 mcmd->tmr_func = fn;
4417 mcmd->flags = flags;
4418 mcmd->reset_count = ha->base_qpair->chip_reset;
4419 mcmd->qpair = h->qpair;
4421 mcmd->se_cmd.cpuid = h->cpuid;
4422 mcmd->unpacked_lun = lun;
4425 case QLA_TGT_LUN_RESET:
4426 case QLA_TGT_CLEAR_TS:
4427 case QLA_TGT_ABORT_TS:
4428 abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id);
4430 case QLA_TGT_CLEAR_ACA:
4431 h = qlt_find_qphint(vha, mcmd->unpacked_lun);
4432 mcmd->qpair = h->qpair;
4433 mcmd->se_cmd.cpuid = h->cpuid;
4436 case QLA_TGT_TARGET_RESET:
4437 case QLA_TGT_NEXUS_LOSS_SESS:
4438 case QLA_TGT_NEXUS_LOSS:
4439 case QLA_TGT_ABORT_ALL:
4445 INIT_WORK(&mcmd->work, qlt_do_tmr_work);
4446 queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq,
4452 /* ha->hardware_lock supposed to be held on entry */
4453 static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb)
4455 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4456 struct qla_hw_data *ha = vha->hw;
4457 struct fc_port *sess;
4460 unsigned long flags;
4462 fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
4464 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
4465 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha,
4466 a->u.isp24.fcp_hdr.s_id);
4467 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
4470 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
4472 if (sess == NULL || sess->deleted)
4475 return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
4478 /* ha->hardware_lock supposed to be held on entry */
4479 static int __qlt_abort_task(struct scsi_qla_host *vha,
4480 struct imm_ntfy_from_isp *iocb, struct fc_port *sess)
4482 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4483 struct qla_hw_data *ha = vha->hw;
4484 struct qla_tgt_mgmt_cmd *mcmd;
4488 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
4490 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f,
4491 "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
4492 vha->vp_idx, __func__);
4495 memset(mcmd, 0, sizeof(*mcmd));
4498 memcpy(&mcmd->orig_iocb.imm_ntfy, iocb,
4499 sizeof(mcmd->orig_iocb.imm_ntfy));
4502 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
4503 mcmd->reset_count = ha->base_qpair->chip_reset;
4504 mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK;
4505 mcmd->qpair = ha->base_qpair;
4507 rc = ha->tgt.tgt_ops->handle_tmr(mcmd, unpacked_lun, mcmd->tmr_func,
4508 le16_to_cpu(iocb->u.isp2x.seq_id));
4510 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060,
4511 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
4513 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
4520 /* ha->hardware_lock supposed to be held on entry */
4521 static int qlt_abort_task(struct scsi_qla_host *vha,
4522 struct imm_ntfy_from_isp *iocb)
4524 struct qla_hw_data *ha = vha->hw;
4525 struct fc_port *sess;
4527 unsigned long flags;
4529 loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb);
4531 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
4532 sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
4533 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
4536 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025,
4537 "qla_target(%d): task abort for unexisting "
4538 "session\n", vha->vp_idx);
4539 return qlt_sched_sess_work(vha->vha_tgt.qla_tgt,
4540 QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb));
4543 return __qlt_abort_task(vha, iocb, sess);
4546 void qlt_logo_completion_handler(fc_port_t *fcport, int rc)
4548 if (rc != MBS_COMMAND_COMPLETE) {
4549 ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093,
4550 "%s: se_sess %p / sess %p from"
4551 " port %8phC loop_id %#04x s_id %02x:%02x:%02x"
4552 " LOGO failed: %#x\n",
4556 fcport->port_name, fcport->loop_id,
4557 fcport->d_id.b.domain, fcport->d_id.b.area,
4558 fcport->d_id.b.al_pa, rc);
4561 fcport->logout_completed = 1;
4565 * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list)
4567 * Schedules sessions with matching port_id/loop_id but different wwn for
4568 * deletion. Returns existing session with matching wwn if present.
4572 qlt_find_sess_invalidate_other(scsi_qla_host_t *vha, uint64_t wwn,
4573 port_id_t port_id, uint16_t loop_id, struct fc_port **conflict_sess)
4575 struct fc_port *sess = NULL, *other_sess;
4578 *conflict_sess = NULL;
4580 list_for_each_entry(other_sess, &vha->vp_fcports, list) {
4582 other_wwn = wwn_to_u64(other_sess->port_name);
4584 if (wwn == other_wwn) {
4590 /* find other sess with nport_id collision */
4591 if (port_id.b24 == other_sess->d_id.b24) {
4592 if (loop_id != other_sess->loop_id) {
4593 ql_dbg(ql_dbg_disc, vha, 0x1000c,
4594 "Invalidating sess %p loop_id %d wwn %llx.\n",
4595 other_sess, other_sess->loop_id, other_wwn);
4598 * logout_on_delete is set by default, but another
4599 * session that has the same s_id/loop_id combo
4600 * might have cleared it when requested this session
4601 * deletion, so don't touch it
4603 qlt_schedule_sess_for_deletion(other_sess);
4606 * Another wwn used to have our s_id/loop_id
4607 * kill the session, but don't free the loop_id
4609 ql_dbg(ql_dbg_disc, vha, 0xf01b,
4610 "Invalidating sess %p loop_id %d wwn %llx.\n",
4611 other_sess, other_sess->loop_id, other_wwn);
4613 other_sess->keep_nport_handle = 1;
4614 if (other_sess->disc_state != DSC_DELETED)
4615 *conflict_sess = other_sess;
4616 qlt_schedule_sess_for_deletion(other_sess);
4621 /* find other sess with nport handle collision */
4622 if ((loop_id == other_sess->loop_id) &&
4623 (loop_id != FC_NO_LOOP_ID)) {
4624 ql_dbg(ql_dbg_disc, vha, 0x1000d,
4625 "Invalidating sess %p loop_id %d wwn %llx.\n",
4626 other_sess, other_sess->loop_id, other_wwn);
4628 /* Same loop_id but different s_id
4629 * Ok to kill and logout */
4630 qlt_schedule_sess_for_deletion(other_sess);
4637 /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */
4638 static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id)
4640 struct qla_tgt_sess_op *op;
4641 struct qla_tgt_cmd *cmd;
4644 unsigned long flags;
4646 key = (((u32)s_id->b.domain << 16) |
4647 ((u32)s_id->b.area << 8) |
4648 ((u32)s_id->b.al_pa));
4650 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4651 list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) {
4652 uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
4654 if (op_key == key) {
4660 list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
4661 uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
4663 if (op_key == key) {
4669 list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
4670 uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id);
4672 if (cmd_key == key) {
4677 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4682 static int qlt_handle_login(struct scsi_qla_host *vha,
4683 struct imm_ntfy_from_isp *iocb)
4685 struct fc_port *sess = NULL, *conflict_sess = NULL;
4688 uint16_t loop_id, wd3_lo;
4690 struct qlt_plogi_ack_t *pla;
4691 unsigned long flags;
4693 lockdep_assert_held(&vha->hw->hardware_lock);
4695 wwn = wwn_to_u64(iocb->u.isp24.port_name);
4697 port_id.b.domain = iocb->u.isp24.port_id[2];
4698 port_id.b.area = iocb->u.isp24.port_id[1];
4699 port_id.b.al_pa = iocb->u.isp24.port_id[0];
4700 port_id.b.rsvd_1 = 0;
4702 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
4704 /* Mark all stale commands sitting in qla_tgt_wq for deletion */
4705 abort_cmds_for_s_id(vha, &port_id);
4708 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4709 sess = qlt_find_sess_invalidate_other(vha, wwn,
4710 port_id, loop_id, &conflict_sess);
4711 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4713 ql_dbg(ql_dbg_disc, vha, 0xffff,
4714 "%s %d Term INOT due to WWN=0 lid=%d, NportID %06X ",
4715 __func__, __LINE__, loop_id, port_id.b24);
4716 qlt_send_term_imm_notif(vha, iocb, 1);
4720 if (IS_SW_RESV_ADDR(port_id)) {
4725 pla = qlt_plogi_ack_find_add(vha, &port_id, iocb);
4727 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
4728 "%s %d %8phC Term INOT due to mem alloc fail",
4730 iocb->u.isp24.port_name);
4731 qlt_send_term_imm_notif(vha, iocb, 1);
4735 if (conflict_sess) {
4736 conflict_sess->login_gen++;
4737 qlt_plogi_ack_link(vha, pla, conflict_sess,
4738 QLT_PLOGI_LINK_CONFLICT);
4743 ql_dbg(ql_dbg_disc, vha, 0xffff,
4744 "%s %d %8phC post new sess\n",
4745 __func__, __LINE__, iocb->u.isp24.port_name);
4746 if (iocb->u.isp24.status_subcode == ELS_PLOGI)
4747 qla24xx_post_newsess_work(vha, &port_id,
4748 iocb->u.isp24.port_name,
4749 iocb->u.isp24.u.plogi.node_name,
4750 pla, FC4_TYPE_UNKNOWN);
4752 qla24xx_post_newsess_work(vha, &port_id,
4753 iocb->u.isp24.port_name, NULL,
4754 pla, FC4_TYPE_UNKNOWN);
4759 if (sess->disc_state == DSC_UPD_FCPORT) {
4763 * Remote port registration is still going on from
4764 * previous login. Allow it to finish before we
4765 * accept the new login.
4767 sess->next_disc_state = DSC_DELETE_PEND;
4768 sec = jiffies_to_msecs(jiffies -
4769 sess->jiffies_at_registration) / 1000;
4770 if (sess->sec_since_registration < sec && sec &&
4772 sess->sec_since_registration = sec;
4773 ql_dbg(ql_dbg_disc, vha, 0xffff,
4774 "%s %8phC - Slow Rport registration (%d Sec)\n",
4775 __func__, sess->port_name, sec);
4778 if (!conflict_sess) {
4779 list_del(&pla->list);
4780 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4783 qlt_send_term_imm_notif(vha, iocb, 1);
4787 qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN);
4788 sess->d_id = port_id;
4791 if (iocb->u.isp24.status_subcode == ELS_PRLI) {
4792 sess->fw_login_state = DSC_LS_PRLI_PEND;
4794 sess->loop_id = loop_id;
4795 sess->d_id = port_id;
4796 sess->fw_login_state = DSC_LS_PRLI_PEND;
4797 wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo);
4800 sess->conf_compl_supported = 1;
4802 if ((wd3_lo & BIT_4) == 0)
4803 sess->port_type = FCT_INITIATOR;
4805 sess->port_type = FCT_TARGET;
4808 sess->fw_login_state = DSC_LS_PLOGI_PEND;
4811 ql_dbg(ql_dbg_disc, vha, 0x20f9,
4812 "%s %d %8phC DS %d\n",
4813 __func__, __LINE__, sess->port_name, sess->disc_state);
4815 switch (sess->disc_state) {
4817 case DSC_LOGIN_PEND:
4818 qlt_plogi_ack_unref(vha, pla);
4823 * Under normal circumstances we want to release nport handle
4824 * during LOGO process to avoid nport handle leaks inside FW.
4825 * The exception is when LOGO is done while another PLOGI with
4826 * the same nport handle is waiting as might be the case here.
4827 * Note: there is always a possibily of a race where session
4828 * deletion has already started for other reasons (e.g. ACL
4829 * removal) and now PLOGI arrives:
4830 * 1. if PLOGI arrived in FW after nport handle has been freed,
4831 * FW must have assigned this PLOGI a new/same handle and we
4832 * can proceed ACK'ing it as usual when session deletion
4834 * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT
4835 * bit reached it, the handle has now been released. We'll
4836 * get an error when we ACK this PLOGI. Nothing will be sent
4837 * back to initiator. Initiator should eventually retry
4838 * PLOGI and situation will correct itself.
4840 sess->keep_nport_handle = ((sess->loop_id == loop_id) &&
4841 (sess->d_id.b24 == port_id.b24));
4843 ql_dbg(ql_dbg_disc, vha, 0x20f9,
4844 "%s %d %8phC post del sess\n",
4845 __func__, __LINE__, sess->port_name);
4848 qlt_schedule_sess_for_deletion(sess);
4856 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4858 static int qlt_24xx_handle_els(struct scsi_qla_host *vha,
4859 struct imm_ntfy_from_isp *iocb)
4861 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4862 struct qla_hw_data *ha = vha->hw;
4863 struct fc_port *sess = NULL, *conflict_sess = NULL;
4869 unsigned long flags;
4871 lockdep_assert_held(&ha->hardware_lock);
4873 wwn = wwn_to_u64(iocb->u.isp24.port_name);
4875 port_id.b.domain = iocb->u.isp24.port_id[2];
4876 port_id.b.area = iocb->u.isp24.port_id[1];
4877 port_id.b.al_pa = iocb->u.isp24.port_id[0];
4878 port_id.b.rsvd_1 = 0;
4880 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
4882 ql_dbg(ql_dbg_disc, vha, 0xf026,
4883 "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n",
4884 vha->vp_idx, iocb->u.isp24.port_id[2],
4885 iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0],
4886 iocb->u.isp24.status_subcode, loop_id,
4887 iocb->u.isp24.port_name);
4889 /* res = 1 means ack at the end of thread
4890 * res = 0 means ack async/later.
4892 switch (iocb->u.isp24.status_subcode) {
4894 res = qlt_handle_login(vha, iocb);
4899 sess = qla2x00_find_fcport_by_wwpn(vha,
4900 iocb->u.isp24.port_name, 1);
4902 if (sess && sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]) {
4903 ql_dbg(ql_dbg_disc, vha, 0xffff,
4904 "%s %d %8phC Term PRLI due to PLOGI ACK not completed\n",
4906 iocb->u.isp24.port_name);
4907 qlt_send_term_imm_notif(vha, iocb, 1);
4911 res = qlt_handle_login(vha, iocb);
4915 if (IS_SW_RESV_ADDR(port_id)) {
4920 wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo);
4923 spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags);
4924 sess = qlt_find_sess_invalidate_other(vha, wwn, port_id,
4925 loop_id, &conflict_sess);
4926 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags);
4929 if (conflict_sess) {
4930 switch (conflict_sess->disc_state) {
4932 case DSC_DELETE_PEND:
4935 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b,
4936 "PRLI with conflicting sess %p port %8phC\n",
4937 conflict_sess, conflict_sess->port_name);
4938 conflict_sess->fw_login_state =
4939 DSC_LS_PORT_UNAVAIL;
4940 qlt_send_term_imm_notif(vha, iocb, 1);
4947 bool delete = false;
4950 spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags);
4951 switch (sess->fw_login_state) {
4952 case DSC_LS_PLOGI_PEND:
4953 case DSC_LS_PLOGI_COMP:
4954 case DSC_LS_PRLI_COMP:
4961 switch (sess->disc_state) {
4962 case DSC_UPD_FCPORT:
4963 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock,
4966 sec = jiffies_to_msecs(jiffies -
4967 sess->jiffies_at_registration)/1000;
4968 if (sess->sec_since_registration < sec && sec &&
4970 sess->sec_since_registration = sec;
4971 ql_dbg(ql_dbg_disc, sess->vha, 0xffff,
4972 "%s %8phC : Slow Rport registration(%d Sec)\n",
4973 __func__, sess->port_name, sec);
4975 qlt_send_term_imm_notif(vha, iocb, 1);
4978 case DSC_LOGIN_PEND:
4980 case DSC_LOGIN_COMPLETE:
4989 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock,
4992 * Impatient initiator sent PRLI before last
4993 * PLOGI could finish. Will force him to re-try,
4994 * while last one finishes.
4996 ql_log(ql_log_warn, sess->vha, 0xf095,
4997 "sess %p PRLI received, before plogi ack.\n",
4999 qlt_send_term_imm_notif(vha, iocb, 1);
5005 * This shouldn't happen under normal circumstances,
5006 * since we have deleted the old session during PLOGI
5008 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096,
5009 "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n",
5010 sess->loop_id, sess, iocb->u.isp24.nport_handle);
5013 sess->loop_id = loop_id;
5014 sess->d_id = port_id;
5015 sess->fw_login_state = DSC_LS_PRLI_PEND;
5018 sess->conf_compl_supported = 1;
5020 if ((wd3_lo & BIT_4) == 0)
5021 sess->port_type = FCT_INITIATOR;
5023 sess->port_type = FCT_TARGET;
5025 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags);
5027 res = 1; /* send notify ack */
5029 /* Make session global (not used in fabric mode) */
5030 if (ha->current_topology != ISP_CFG_F) {
5032 ql_dbg(ql_dbg_disc, vha, 0x20fa,
5033 "%s %d %8phC post nack\n",
5034 __func__, __LINE__, sess->port_name);
5035 qla24xx_post_nack_work(vha, sess, iocb,
5039 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5040 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5041 qla2xxx_wake_dpc(vha);
5045 ql_dbg(ql_dbg_disc, vha, 0x20fb,
5046 "%s %d %8phC post nack\n",
5047 __func__, __LINE__, sess->port_name);
5048 qla24xx_post_nack_work(vha, sess, iocb,
5056 if (le16_to_cpu(iocb->u.isp24.flags) &
5057 NOTIFY24XX_FLAGS_GLOBAL_TPRLO) {
5059 qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS);
5066 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
5067 sess = qla2x00_find_fcport_by_loopid(vha, loop_id);
5068 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
5072 sess->fw_login_state = DSC_LS_LOGO_PEND;
5073 sess->logo_ack_needed = 1;
5074 memcpy(sess->iocb, iocb, IOCB_SIZE);
5077 res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS);
5079 ql_dbg(ql_dbg_disc, vha, 0x20fc,
5080 "%s: logo %llx res %d sess %p ",
5081 __func__, wwn, res, sess);
5084 * cmd went upper layer, look for qlt_xmit_tm_rsp()
5085 * for LOGO_ACK & sess delete
5090 /* cmd did not go to upper layer. */
5092 qlt_schedule_sess_for_deletion(sess);
5095 /* else logo will be ack */
5101 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5103 if (tgt->link_reinit_iocb_pending) {
5104 qlt_send_notify_ack(ha->base_qpair,
5105 &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0);
5106 tgt->link_reinit_iocb_pending = 0;
5109 sess = qla2x00_find_fcport_by_wwpn(vha,
5110 iocb->u.isp24.port_name, 1);
5112 ql_dbg(ql_dbg_disc, vha, 0x20fd,
5113 "sess %p lid %d|%d DS %d LS %d\n",
5114 sess, sess->loop_id, loop_id,
5115 sess->disc_state, sess->fw_login_state);
5118 res = 1; /* send notify ack */
5122 case ELS_FLOGI: /* should never happen */
5124 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061,
5125 "qla_target(%d): Unsupported ELS command %x "
5126 "received\n", vha->vp_idx, iocb->u.isp24.status_subcode);
5127 res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS);
5131 ql_dbg(ql_dbg_disc, vha, 0xf026,
5132 "qla_target(%d): Exit ELS opcode: 0x%02x res %d\n",
5133 vha->vp_idx, iocb->u.isp24.status_subcode, res);
5139 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5141 static void qlt_handle_imm_notify(struct scsi_qla_host *vha,
5142 struct imm_ntfy_from_isp *iocb)
5144 struct qla_hw_data *ha = vha->hw;
5145 uint32_t add_flags = 0;
5146 int send_notify_ack = 1;
5149 lockdep_assert_held(&ha->hardware_lock);
5151 status = le16_to_cpu(iocb->u.isp2x.status);
5153 case IMM_NTFY_LIP_RESET:
5155 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032,
5156 "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
5157 vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle),
5158 iocb->u.isp24.status_subcode);
5160 if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0)
5161 send_notify_ack = 0;
5165 case IMM_NTFY_LIP_LINK_REINIT:
5167 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5169 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033,
5170 "qla_target(%d): LINK REINIT (loop %#x, "
5171 "subcode %x)\n", vha->vp_idx,
5172 le16_to_cpu(iocb->u.isp24.nport_handle),
5173 iocb->u.isp24.status_subcode);
5174 if (tgt->link_reinit_iocb_pending) {
5175 qlt_send_notify_ack(ha->base_qpair,
5176 &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0);
5178 memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb));
5179 tgt->link_reinit_iocb_pending = 1;
5181 * QLogic requires to wait after LINK REINIT for possible
5182 * PDISC or ADISC ELS commands
5184 send_notify_ack = 0;
5188 case IMM_NTFY_PORT_LOGOUT:
5189 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034,
5190 "qla_target(%d): Port logout (loop "
5191 "%#x, subcode %x)\n", vha->vp_idx,
5192 le16_to_cpu(iocb->u.isp24.nport_handle),
5193 iocb->u.isp24.status_subcode);
5195 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0)
5196 send_notify_ack = 0;
5197 /* The sessions will be cleared in the callback, if needed */
5200 case IMM_NTFY_GLBL_TPRLO:
5201 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035,
5202 "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status);
5203 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0)
5204 send_notify_ack = 0;
5205 /* The sessions will be cleared in the callback, if needed */
5208 case IMM_NTFY_PORT_CONFIG:
5209 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036,
5210 "qla_target(%d): Port config changed (%x)\n", vha->vp_idx,
5212 if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0)
5213 send_notify_ack = 0;
5214 /* The sessions will be cleared in the callback, if needed */
5217 case IMM_NTFY_GLBL_LOGO:
5218 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a,
5219 "qla_target(%d): Link failure detected\n",
5221 /* I_T nexus loss */
5222 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0)
5223 send_notify_ack = 0;
5226 case IMM_NTFY_IOCB_OVERFLOW:
5227 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b,
5228 "qla_target(%d): Cannot provide requested "
5229 "capability (IOCB overflowed the immediate notify "
5230 "resource count)\n", vha->vp_idx);
5233 case IMM_NTFY_ABORT_TASK:
5234 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037,
5235 "qla_target(%d): Abort Task (S %08x I %#x -> "
5236 "L %#x)\n", vha->vp_idx,
5237 le16_to_cpu(iocb->u.isp2x.seq_id),
5238 GET_TARGET_ID(ha, (struct atio_from_isp *)iocb),
5239 le16_to_cpu(iocb->u.isp2x.lun));
5240 if (qlt_abort_task(vha, iocb) == 0)
5241 send_notify_ack = 0;
5244 case IMM_NTFY_RESOURCE:
5245 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c,
5246 "qla_target(%d): Out of resources, host %ld\n",
5247 vha->vp_idx, vha->host_no);
5250 case IMM_NTFY_MSG_RX:
5251 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038,
5252 "qla_target(%d): Immediate notify task %x\n",
5253 vha->vp_idx, iocb->u.isp2x.task_flags);
5257 if (qlt_24xx_handle_els(vha, iocb) == 0)
5258 send_notify_ack = 0;
5261 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d,
5262 "qla_target(%d): Received unknown immediate "
5263 "notify status %x\n", vha->vp_idx, status);
5267 if (send_notify_ack)
5268 qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0,
5273 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5274 * This function sends busy to ISP 2xxx or 24xx.
5276 static int __qlt_send_busy(struct qla_qpair *qpair,
5277 struct atio_from_isp *atio, uint16_t status)
5279 struct scsi_qla_host *vha = qpair->vha;
5280 struct ctio7_to_24xx *ctio24;
5281 struct qla_hw_data *ha = vha->hw;
5283 struct fc_port *sess = NULL;
5284 unsigned long flags;
5288 id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
5290 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
5291 sess = qla2x00_find_fcport_by_nportid(vha, &id, 1);
5292 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
5294 qlt_send_term_exchange(qpair, NULL, atio, 1, 0);
5297 /* Sending marker isn't necessary, since we called from ISR */
5299 pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL);
5301 ql_dbg(ql_dbg_io, vha, 0x3063,
5302 "qla_target(%d): %s failed: unable to allocate "
5303 "request packet", vha->vp_idx, __func__);
5307 qpair->tgt_counters.num_q_full_sent++;
5308 pkt->entry_count = 1;
5309 pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
5311 ctio24 = (struct ctio7_to_24xx *)pkt;
5312 ctio24->entry_type = CTIO_TYPE7;
5313 ctio24->nport_handle = sess->loop_id;
5314 ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
5315 ctio24->vp_index = vha->vp_idx;
5316 ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
5317 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
5318 temp = (atio->u.isp24.attr << 9) |
5319 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS |
5320 CTIO7_FLAGS_DONT_RET_CTIO;
5321 ctio24->u.status1.flags = cpu_to_le16(temp);
5323 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
5324 * if the explicit conformation is used.
5326 ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id);
5327 ctio24->u.status1.scsi_status = cpu_to_le16(status);
5329 ctio24->u.status1.residual = get_datalen_for_atio(atio);
5331 if (ctio24->u.status1.residual != 0)
5332 ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER;
5334 /* Memory Barrier */
5336 if (qpair->reqq_start_iocbs)
5337 qpair->reqq_start_iocbs(qpair);
5339 qla2x00_start_iocbs(vha, qpair->req);
5344 * This routine is used to allocate a command for either a QFull condition
5345 * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go
5349 qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
5350 struct atio_from_isp *atio, uint16_t status, int qfull)
5352 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5353 struct qla_hw_data *ha = vha->hw;
5354 struct fc_port *sess;
5355 struct se_session *se_sess;
5356 struct qla_tgt_cmd *cmd;
5358 unsigned long flags;
5360 if (unlikely(tgt->tgt_stop)) {
5361 ql_dbg(ql_dbg_io, vha, 0x300a,
5362 "New command while device %p is shutting down\n", tgt);
5366 if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) {
5367 vha->hw->tgt.num_qfull_cmds_dropped++;
5368 if (vha->hw->tgt.num_qfull_cmds_dropped >
5369 vha->qla_stats.stat_max_qfull_cmds_dropped)
5370 vha->qla_stats.stat_max_qfull_cmds_dropped =
5371 vha->hw->tgt.num_qfull_cmds_dropped;
5373 ql_dbg(ql_dbg_io, vha, 0x3068,
5374 "qla_target(%d): %s: QFull CMD dropped[%d]\n",
5375 vha->vp_idx, __func__,
5376 vha->hw->tgt.num_qfull_cmds_dropped);
5378 qlt_chk_exch_leak_thresh_hold(vha);
5382 sess = ha->tgt.tgt_ops->find_sess_by_s_id
5383 (vha, atio->u.isp24.fcp_hdr.s_id);
5387 se_sess = sess->se_sess;
5389 tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu);
5391 ql_dbg(ql_dbg_io, vha, 0x3009,
5392 "qla_target(%d): %s: Allocation of cmd failed\n",
5393 vha->vp_idx, __func__);
5395 vha->hw->tgt.num_qfull_cmds_dropped++;
5396 if (vha->hw->tgt.num_qfull_cmds_dropped >
5397 vha->qla_stats.stat_max_qfull_cmds_dropped)
5398 vha->qla_stats.stat_max_qfull_cmds_dropped =
5399 vha->hw->tgt.num_qfull_cmds_dropped;
5401 qlt_chk_exch_leak_thresh_hold(vha);
5405 cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag];
5406 memset(cmd, 0, sizeof(struct qla_tgt_cmd));
5408 qlt_incr_num_pend_cmds(vha);
5409 INIT_LIST_HEAD(&cmd->cmd_list);
5410 memcpy(&cmd->atio, atio, sizeof(*atio));
5412 cmd->tgt = vha->vha_tgt.qla_tgt;
5414 cmd->reset_count = ha->base_qpair->chip_reset;
5416 cmd->qpair = ha->base_qpair;
5417 cmd->se_cmd.map_cpu = cpu;
5421 /* NOTE: borrowing the state field to carry the status */
5422 cmd->state = status;
5424 cmd->term_exchg = 1;
5426 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5427 list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list);
5429 vha->hw->tgt.num_qfull_cmds_alloc++;
5430 if (vha->hw->tgt.num_qfull_cmds_alloc >
5431 vha->qla_stats.stat_max_qfull_cmds_alloc)
5432 vha->qla_stats.stat_max_qfull_cmds_alloc =
5433 vha->hw->tgt.num_qfull_cmds_alloc;
5434 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5438 qlt_free_qfull_cmds(struct qla_qpair *qpair)
5440 struct scsi_qla_host *vha = qpair->vha;
5441 struct qla_hw_data *ha = vha->hw;
5442 unsigned long flags;
5443 struct qla_tgt_cmd *cmd, *tcmd;
5444 struct list_head free_list, q_full_list;
5447 if (list_empty(&ha->tgt.q_full_list))
5450 INIT_LIST_HEAD(&free_list);
5451 INIT_LIST_HEAD(&q_full_list);
5453 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5454 if (list_empty(&ha->tgt.q_full_list)) {
5455 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5459 list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list);
5460 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5462 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
5463 list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) {
5465 /* cmd->state is a borrowed field to hold status */
5466 rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state);
5467 else if (cmd->term_exchg)
5468 rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio);
5474 ql_dbg(ql_dbg_io, vha, 0x3006,
5475 "%s: busy sent for ox_id[%04x]\n", __func__,
5476 be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
5477 else if (cmd->term_exchg)
5478 ql_dbg(ql_dbg_io, vha, 0x3007,
5479 "%s: Term exchg sent for ox_id[%04x]\n", __func__,
5480 be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
5482 ql_dbg(ql_dbg_io, vha, 0x3008,
5483 "%s: Unexpected cmd in QFull list %p\n", __func__,
5486 list_del(&cmd->cmd_list);
5487 list_add_tail(&cmd->cmd_list, &free_list);
5489 /* piggy back on hardware_lock for protection */
5490 vha->hw->tgt.num_qfull_cmds_alloc--;
5492 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
5496 list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) {
5497 list_del(&cmd->cmd_list);
5498 /* This cmd was never sent to TCM. There is no need
5499 * to schedule free or call free_cmd
5504 if (!list_empty(&q_full_list)) {
5505 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5506 list_splice(&q_full_list, &vha->hw->tgt.q_full_list);
5507 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5514 qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio,
5518 struct scsi_qla_host *vha = qpair->vha;
5520 rc = __qlt_send_busy(qpair, atio, status);
5522 qlt_alloc_qfull_cmd(vha, atio, status, 1);
5526 qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair,
5527 struct atio_from_isp *atio, uint8_t ha_locked)
5529 struct qla_hw_data *ha = vha->hw;
5530 unsigned long flags;
5532 if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha))
5536 spin_lock_irqsave(&ha->hardware_lock, flags);
5537 qlt_send_busy(qpair, atio, qla_sam_status);
5539 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5544 /* ha->hardware_lock supposed to be held on entry */
5545 /* called via callback from qla2xxx */
5546 static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha,
5547 struct atio_from_isp *atio, uint8_t ha_locked)
5549 struct qla_hw_data *ha = vha->hw;
5550 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5552 unsigned long flags = 0;
5554 if (unlikely(tgt == NULL)) {
5555 ql_dbg(ql_dbg_tgt, vha, 0x3064,
5556 "ATIO pkt, but no tgt (ha %p)", ha);
5560 * In tgt_stop mode we also should allow all requests to pass.
5561 * Otherwise, some commands can stuck.
5564 tgt->atio_irq_cmd_count++;
5566 switch (atio->u.raw.entry_type) {
5568 if (unlikely(atio->u.isp24.exchange_addr ==
5569 ATIO_EXCHANGE_ADDRESS_UNKNOWN)) {
5570 ql_dbg(ql_dbg_io, vha, 0x3065,
5571 "qla_target(%d): ATIO_TYPE7 "
5572 "received with UNKNOWN exchange address, "
5573 "sending QUEUE_FULL\n", vha->vp_idx);
5575 spin_lock_irqsave(&ha->hardware_lock, flags);
5576 qlt_send_busy(ha->base_qpair, atio, qla_sam_status);
5578 spin_unlock_irqrestore(&ha->hardware_lock,
5583 if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) {
5584 rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair,
5587 tgt->atio_irq_cmd_count--;
5590 rc = qlt_handle_cmd_for_atio(vha, atio);
5592 rc = qlt_handle_task_mgmt(vha, atio);
5594 if (unlikely(rc != 0)) {
5596 spin_lock_irqsave(&ha->hardware_lock, flags);
5599 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5600 "qla_target: Unable to send command to target\n");
5603 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5604 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
5605 qlt_send_term_exchange(ha->base_qpair, NULL,
5609 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5610 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5612 qlt_send_busy(ha->base_qpair, atio,
5616 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5617 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5619 qlt_send_busy(ha->base_qpair, atio,
5624 spin_unlock_irqrestore(&ha->hardware_lock,
5629 case IMMED_NOTIFY_TYPE:
5631 if (unlikely(atio->u.isp2x.entry_status != 0)) {
5632 ql_dbg(ql_dbg_tgt, vha, 0xe05b,
5633 "qla_target(%d): Received ATIO packet %x "
5634 "with error status %x\n", vha->vp_idx,
5635 atio->u.raw.entry_type,
5636 atio->u.isp2x.entry_status);
5639 ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO");
5642 spin_lock_irqsave(&ha->hardware_lock, flags);
5643 qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio);
5645 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5650 ql_dbg(ql_dbg_tgt, vha, 0xe05c,
5651 "qla_target(%d): Received unknown ATIO atio "
5652 "type %x\n", vha->vp_idx, atio->u.raw.entry_type);
5656 tgt->atio_irq_cmd_count--;
5660 * qpair lock is assume to be held
5661 * rc = 0 : send terminate & abts respond
5662 * rc != 0: do not send term & abts respond
5664 static int qlt_chk_unresolv_exchg(struct scsi_qla_host *vha,
5665 struct qla_qpair *qpair, struct abts_resp_from_24xx_fw *entry)
5667 struct qla_hw_data *ha = vha->hw;
5671 * Detect unresolved exchange. If the same ABTS is unable
5672 * to terminate an existing command and the same ABTS loops
5673 * between FW & Driver, then force FW dump. Under 1 jiff,
5674 * we should see multiple loops.
5676 if (qpair->retry_term_exchg_addr == entry->exchange_addr_to_abort &&
5677 qpair->retry_term_jiff == jiffies) {
5678 /* found existing exchange */
5679 qpair->retry_term_cnt++;
5680 if (qpair->retry_term_cnt >= 5) {
5682 qpair->retry_term_cnt = 0;
5683 ql_log(ql_log_warn, vha, 0xffff,
5684 "Unable to send ABTS Respond. Dumping firmware.\n");
5685 ql_dump_buffer(ql_dbg_tgt_mgt + ql_dbg_buffer,
5686 vha, 0xffff, (uint8_t *)entry, sizeof(*entry));
5688 if (qpair == ha->base_qpair)
5689 ha->isp_ops->fw_dump(vha, 1);
5691 ha->isp_ops->fw_dump(vha, 0);
5693 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5694 qla2xxx_wake_dpc(vha);
5696 } else if (qpair->retry_term_jiff != jiffies) {
5697 qpair->retry_term_exchg_addr = entry->exchange_addr_to_abort;
5698 qpair->retry_term_cnt = 0;
5699 qpair->retry_term_jiff = jiffies;
5706 static void qlt_handle_abts_completion(struct scsi_qla_host *vha,
5707 struct rsp_que *rsp, response_t *pkt)
5709 struct abts_resp_from_24xx_fw *entry =
5710 (struct abts_resp_from_24xx_fw *)pkt;
5711 u32 h = pkt->handle & ~QLA_TGT_HANDLE_MASK;
5712 struct qla_tgt_mgmt_cmd *mcmd;
5713 struct qla_hw_data *ha = vha->hw;
5715 mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, pkt);
5716 if (mcmd == NULL && h != QLA_TGT_SKIP_HANDLE) {
5717 ql_dbg(ql_dbg_async, vha, 0xe064,
5718 "qla_target(%d): ABTS Comp without mcmd\n",
5725 vha->vha_tgt.qla_tgt->abts_resp_expected--;
5727 ql_dbg(ql_dbg_tgt, vha, 0xe038,
5728 "ABTS_RESP_24XX: compl_status %x\n",
5729 entry->compl_status);
5731 if (le16_to_cpu(entry->compl_status) != ABTS_RESP_COMPL_SUCCESS) {
5732 if ((entry->error_subcode1 == 0x1E) &&
5733 (entry->error_subcode2 == 0)) {
5734 if (qlt_chk_unresolv_exchg(vha, rsp->qpair, entry)) {
5735 ha->tgt.tgt_ops->free_mcmd(mcmd);
5738 qlt_24xx_retry_term_exchange(vha, rsp->qpair,
5741 ql_dbg(ql_dbg_tgt, vha, 0xe063,
5742 "qla_target(%d): ABTS_RESP_24XX failed %x (subcode %x:%x)",
5743 vha->vp_idx, entry->compl_status,
5744 entry->error_subcode1,
5745 entry->error_subcode2);
5746 ha->tgt.tgt_ops->free_mcmd(mcmd);
5749 ha->tgt.tgt_ops->free_mcmd(mcmd);
5753 /* ha->hardware_lock supposed to be held on entry */
5754 /* called via callback from qla2xxx */
5755 static void qlt_response_pkt(struct scsi_qla_host *vha,
5756 struct rsp_que *rsp, response_t *pkt)
5758 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5760 if (unlikely(tgt == NULL)) {
5761 ql_dbg(ql_dbg_tgt, vha, 0xe05d,
5762 "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n",
5763 vha->vp_idx, pkt->entry_type, vha->hw);
5768 * In tgt_stop mode we also should allow all requests to pass.
5769 * Otherwise, some commands can stuck.
5772 switch (pkt->entry_type) {
5776 struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
5778 qlt_do_ctio_completion(vha, rsp, entry->handle,
5779 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5784 case ACCEPT_TGT_IO_TYPE:
5786 struct atio_from_isp *atio = (struct atio_from_isp *)pkt;
5789 if (atio->u.isp2x.status !=
5790 cpu_to_le16(ATIO_CDB_VALID)) {
5791 ql_dbg(ql_dbg_tgt, vha, 0xe05e,
5792 "qla_target(%d): ATIO with error "
5793 "status %x received\n", vha->vp_idx,
5794 le16_to_cpu(atio->u.isp2x.status));
5798 rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1);
5802 rc = qlt_handle_cmd_for_atio(vha, atio);
5803 if (unlikely(rc != 0)) {
5806 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5807 "qla_target: Unable to send command to target\n");
5810 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5811 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
5812 qlt_send_term_exchange(rsp->qpair, NULL,
5816 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5817 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5819 qlt_send_busy(rsp->qpair, atio,
5823 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5824 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5826 qlt_send_busy(rsp->qpair, atio,
5834 case CONTINUE_TGT_IO_TYPE:
5836 struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
5838 qlt_do_ctio_completion(vha, rsp, entry->handle,
5839 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5846 struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
5848 qlt_do_ctio_completion(vha, rsp, entry->handle,
5849 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5854 case IMMED_NOTIFY_TYPE:
5855 ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n");
5856 qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt);
5859 case NOTIFY_ACK_TYPE:
5860 if (tgt->notify_ack_expected > 0) {
5861 struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
5863 ql_dbg(ql_dbg_tgt, vha, 0xe036,
5864 "NOTIFY_ACK seq %08x status %x\n",
5865 le16_to_cpu(entry->u.isp2x.seq_id),
5866 le16_to_cpu(entry->u.isp2x.status));
5867 tgt->notify_ack_expected--;
5868 if (entry->u.isp2x.status !=
5869 cpu_to_le16(NOTIFY_ACK_SUCCESS)) {
5870 ql_dbg(ql_dbg_tgt, vha, 0xe061,
5871 "qla_target(%d): NOTIFY_ACK "
5872 "failed %x\n", vha->vp_idx,
5873 le16_to_cpu(entry->u.isp2x.status));
5876 ql_dbg(ql_dbg_tgt, vha, 0xe062,
5877 "qla_target(%d): Unexpected NOTIFY_ACK received\n",
5882 case ABTS_RECV_24XX:
5883 ql_dbg(ql_dbg_tgt, vha, 0xe037,
5884 "ABTS_RECV_24XX: instance %d\n", vha->vp_idx);
5885 qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt);
5888 case ABTS_RESP_24XX:
5889 if (tgt->abts_resp_expected > 0) {
5890 qlt_handle_abts_completion(vha, rsp, pkt);
5892 ql_dbg(ql_dbg_tgt, vha, 0xe064,
5893 "qla_target(%d): Unexpected ABTS_RESP_24XX "
5894 "received\n", vha->vp_idx);
5899 ql_dbg(ql_dbg_tgt, vha, 0xe065,
5900 "qla_target(%d): Received unknown response pkt "
5901 "type %x\n", vha->vp_idx, pkt->entry_type);
5908 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5910 void qlt_async_event(uint16_t code, struct scsi_qla_host *vha,
5913 struct qla_hw_data *ha = vha->hw;
5914 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5917 if (!tgt || tgt->tgt_stop || tgt->tgt_stopped)
5920 if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) &&
5924 * In tgt_stop mode we also should allow all requests to pass.
5925 * Otherwise, some commands can stuck.
5930 case MBA_RESET: /* Reset */
5931 case MBA_SYSTEM_ERR: /* System Error */
5932 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
5933 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
5934 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a,
5935 "qla_target(%d): System error async event %#x "
5936 "occurred", vha->vp_idx, code);
5938 case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */
5939 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5944 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b,
5945 "qla_target(%d): Async LOOP_UP occurred "
5946 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx,
5947 le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
5948 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
5949 if (tgt->link_reinit_iocb_pending) {
5950 qlt_send_notify_ack(ha->base_qpair,
5951 (void *)&tgt->link_reinit_iocb,
5953 tgt->link_reinit_iocb_pending = 0;
5958 case MBA_LIP_OCCURRED:
5961 case MBA_RSCN_UPDATE:
5962 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c,
5963 "qla_target(%d): Async event %#x occurred "
5964 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code,
5965 le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
5966 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
5969 case MBA_REJECTED_FCP_CMD:
5970 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017,
5971 "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)",
5973 le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
5974 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
5976 if (le16_to_cpu(mailbox[3]) == 1) {
5977 /* exchange starvation. */
5978 vha->hw->exch_starvation++;
5979 if (vha->hw->exch_starvation > 5) {
5980 ql_log(ql_log_warn, vha, 0xd03a,
5981 "Exchange starvation-. Resetting RISC\n");
5983 vha->hw->exch_starvation = 0;
5984 if (IS_P3P_TYPE(vha->hw))
5985 set_bit(FCOE_CTX_RESET_NEEDED,
5988 set_bit(ISP_ABORT_NEEDED,
5990 qla2xxx_wake_dpc(vha);
5995 case MBA_PORT_UPDATE:
5996 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d,
5997 "qla_target(%d): Port update async event %#x "
5998 "occurred: updating the ports database (m[0]=%x, m[1]=%x, "
5999 "m[2]=%x, m[3]=%x)", vha->vp_idx, code,
6000 le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
6001 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
6003 login_code = le16_to_cpu(mailbox[2]);
6004 if (login_code == 0x4) {
6005 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e,
6006 "Async MB 2: Got PLOGI Complete\n");
6007 vha->hw->exch_starvation = 0;
6008 } else if (login_code == 0x7)
6009 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f,
6010 "Async MB 2: Port Logged Out\n");
6018 static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha,
6021 fc_port_t *fcport, *tfcp, *del;
6023 unsigned long flags;
6026 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6028 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f,
6029 "qla_target(%d): Allocation of tmp FC port failed",
6034 fcport->loop_id = loop_id;
6036 rc = qla24xx_gpdb_wait(vha, fcport, 0);
6037 if (rc != QLA_SUCCESS) {
6038 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070,
6039 "qla_target(%d): Failed to retrieve fcport "
6040 "information -- get_port_database() returned %x "
6041 "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id);
6047 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6048 tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1);
6051 tfcp->d_id = fcport->d_id;
6052 tfcp->port_type = fcport->port_type;
6053 tfcp->supported_classes = fcport->supported_classes;
6054 tfcp->flags |= fcport->flags;
6055 tfcp->scan_state = QLA_FCPORT_FOUND;
6060 if (vha->hw->current_topology == ISP_CFG_F)
6061 fcport->flags |= FCF_FABRIC_DEVICE;
6063 list_add_tail(&fcport->list, &vha->vp_fcports);
6064 if (!IS_SW_RESV_ADDR(fcport->d_id))
6065 vha->fcport_count++;
6066 fcport->login_gen++;
6067 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
6068 fcport->login_succ = 1;
6072 fcport->deleted = 0;
6073 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6075 switch (vha->host->active_mode) {
6076 case MODE_INITIATOR:
6079 if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) {
6080 qla24xx_sched_upd_fcport(fcport);
6082 ql_dbg(ql_dbg_disc, vha, 0x20ff,
6083 "%s %d %8phC post gpsc fcp_cnt %d\n",
6084 __func__, __LINE__, fcport->port_name, vha->fcport_count);
6085 qla24xx_post_gpsc_work(vha, fcport);
6095 qla2x00_free_fcport(del);
6100 /* Must be called under tgt_mutex */
6101 static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *vha,
6104 struct fc_port *sess = NULL;
6105 fc_port_t *fcport = NULL;
6106 int rc, global_resets;
6107 uint16_t loop_id = 0;
6109 if (s_id.domain == 0xFF && s_id.area == 0xFC) {
6111 * This is Domain Controller, so it should be
6112 * OK to drop SCSI commands from it.
6114 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042,
6115 "Unable to find initiator with S_ID %x:%x:%x",
6116 s_id.domain, s_id.area, s_id.al_pa);
6120 mutex_lock(&vha->vha_tgt.tgt_mutex);
6124 atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count);
6126 rc = qla24xx_get_loop_id(vha, s_id, &loop_id);
6128 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6130 ql_log(ql_log_info, vha, 0xf071,
6131 "qla_target(%d): Unable to find "
6132 "initiator with S_ID %x:%x:%x",
6133 vha->vp_idx, s_id.domain, s_id.area, s_id.al_pa);
6135 if (rc == -ENOENT) {
6136 qlt_port_logo_t logo;
6138 logo.id = be_to_port_id(s_id);
6140 qlt_send_first_logo(vha, &logo);
6146 fcport = qlt_get_port_database(vha, loop_id);
6148 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6152 if (global_resets !=
6153 atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) {
6154 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043,
6155 "qla_target(%d): global reset during session discovery "
6156 "(counter was %d, new %d), retrying", vha->vp_idx,
6158 atomic_read(&vha->vha_tgt.
6159 qla_tgt->tgt_global_resets_count));
6163 sess = qlt_create_sess(vha, fcport, true);
6165 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6170 static void qlt_abort_work(struct qla_tgt *tgt,
6171 struct qla_tgt_sess_work_param *prm)
6173 struct scsi_qla_host *vha = tgt->vha;
6174 struct qla_hw_data *ha = vha->hw;
6175 struct fc_port *sess = NULL;
6176 unsigned long flags = 0, flags2 = 0;
6180 spin_lock_irqsave(&ha->tgt.sess_lock, flags2);
6185 s_id = le_id_to_be(prm->abts.fcp_hdr_le.s_id);
6187 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
6189 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6191 sess = qlt_make_local_sess(vha, s_id);
6192 /* sess has got an extra creation ref */
6194 spin_lock_irqsave(&ha->tgt.sess_lock, flags2);
6198 if (sess->deleted) {
6203 if (!kref_get_unless_zero(&sess->sess_kref)) {
6204 ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c,
6205 "%s: kref_get fail %8phC \n",
6206 __func__, sess->port_name);
6212 rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess);
6213 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6215 ha->tgt.tgt_ops->put_sess(sess);
6222 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6225 spin_lock_irqsave(&ha->hardware_lock, flags);
6226 qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts,
6227 FCP_TMF_REJECTED, false);
6228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6231 static void qlt_tmr_work(struct qla_tgt *tgt,
6232 struct qla_tgt_sess_work_param *prm)
6234 struct atio_from_isp *a = &prm->tm_iocb2;
6235 struct scsi_qla_host *vha = tgt->vha;
6236 struct qla_hw_data *ha = vha->hw;
6237 struct fc_port *sess;
6238 unsigned long flags;
6245 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
6250 s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id;
6251 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
6253 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6255 sess = qlt_make_local_sess(vha, s_id);
6256 /* sess has got an extra creation ref */
6258 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
6262 if (sess->deleted) {
6266 if (!kref_get_unless_zero(&sess->sess_kref)) {
6267 ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020,
6268 "%s: kref_get fail %8phC\n",
6269 __func__, sess->port_name);
6275 fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
6277 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
6279 rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
6280 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6282 ha->tgt.tgt_ops->put_sess(sess);
6289 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6291 qlt_send_term_exchange(ha->base_qpair, NULL, &prm->tm_iocb2, 1, 0);
6294 static void qlt_sess_work_fn(struct work_struct *work)
6296 struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work);
6297 struct scsi_qla_host *vha = tgt->vha;
6298 unsigned long flags;
6300 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt);
6302 spin_lock_irqsave(&tgt->sess_work_lock, flags);
6303 while (!list_empty(&tgt->sess_works_list)) {
6304 struct qla_tgt_sess_work_param *prm = list_entry(
6305 tgt->sess_works_list.next, typeof(*prm),
6306 sess_works_list_entry);
6309 * This work can be scheduled on several CPUs at time, so we
6310 * must delete the entry to eliminate double processing
6312 list_del(&prm->sess_works_list_entry);
6314 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
6316 switch (prm->type) {
6317 case QLA_TGT_SESS_WORK_ABORT:
6318 qlt_abort_work(tgt, prm);
6320 case QLA_TGT_SESS_WORK_TM:
6321 qlt_tmr_work(tgt, prm);
6328 spin_lock_irqsave(&tgt->sess_work_lock, flags);
6332 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
6335 /* Must be called under tgt_host_action_mutex */
6336 int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha)
6338 struct qla_tgt *tgt;
6340 struct qla_qpair_hint *h;
6342 if (!QLA_TGT_MODE_ENABLED())
6345 if (!IS_TGT_MODE_CAPABLE(ha)) {
6346 ql_log(ql_log_warn, base_vha, 0xe070,
6347 "This adapter does not support target mode.\n");
6351 ql_dbg(ql_dbg_tgt, base_vha, 0xe03b,
6352 "Registering target for host %ld(%p).\n", base_vha->host_no, ha);
6354 BUG_ON(base_vha->vha_tgt.qla_tgt != NULL);
6356 tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL);
6358 ql_dbg(ql_dbg_tgt, base_vha, 0xe066,
6359 "Unable to allocate struct qla_tgt\n");
6363 tgt->qphints = kcalloc(ha->max_qpairs + 1,
6364 sizeof(struct qla_qpair_hint),
6366 if (!tgt->qphints) {
6368 ql_log(ql_log_warn, base_vha, 0x0197,
6369 "Unable to allocate qpair hints.\n");
6373 if (!(base_vha->host->hostt->supported_mode & MODE_TARGET))
6374 base_vha->host->hostt->supported_mode |= MODE_TARGET;
6376 rc = btree_init64(&tgt->lun_qpair_map);
6378 kfree(tgt->qphints);
6380 ql_log(ql_log_info, base_vha, 0x0198,
6381 "Unable to initialize lun_qpair_map btree\n");
6384 h = &tgt->qphints[0];
6385 h->qpair = ha->base_qpair;
6386 INIT_LIST_HEAD(&h->hint_elem);
6387 h->cpuid = ha->base_qpair->cpuid;
6388 list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list);
6390 for (i = 0; i < ha->max_qpairs; i++) {
6391 unsigned long flags;
6393 struct qla_qpair *qpair = ha->queue_pair_map[i];
6395 h = &tgt->qphints[i + 1];
6396 INIT_LIST_HEAD(&h->hint_elem);
6399 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
6400 list_add_tail(&h->hint_elem, &qpair->hints_list);
6401 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
6402 h->cpuid = qpair->cpuid;
6407 tgt->vha = base_vha;
6408 init_waitqueue_head(&tgt->waitQ);
6409 INIT_LIST_HEAD(&tgt->del_sess_list);
6410 spin_lock_init(&tgt->sess_work_lock);
6411 INIT_WORK(&tgt->sess_work, qlt_sess_work_fn);
6412 INIT_LIST_HEAD(&tgt->sess_works_list);
6413 atomic_set(&tgt->tgt_global_resets_count, 0);
6415 base_vha->vha_tgt.qla_tgt = tgt;
6417 ql_dbg(ql_dbg_tgt, base_vha, 0xe067,
6418 "qla_target(%d): using 64 Bit PCI addressing",
6421 tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3);
6423 mutex_lock(&qla_tgt_mutex);
6424 list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist);
6425 mutex_unlock(&qla_tgt_mutex);
6427 if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target)
6428 ha->tgt.tgt_ops->add_target(base_vha);
6433 /* Must be called under tgt_host_action_mutex */
6434 int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha)
6436 if (!vha->vha_tgt.qla_tgt)
6439 if (vha->fc_vport) {
6440 qlt_release(vha->vha_tgt.qla_tgt);
6444 /* free left over qfull cmds */
6445 qlt_init_term_exchange(vha);
6447 ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)",
6449 qlt_release(vha->vha_tgt.qla_tgt);
6454 void qlt_remove_target_resources(struct qla_hw_data *ha)
6456 struct scsi_qla_host *node;
6459 btree_for_each_safe32(&ha->tgt.host_map, key, node)
6460 btree_remove32(&ha->tgt.host_map, key);
6462 btree_destroy32(&ha->tgt.host_map);
6465 static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn,
6468 pr_debug("qla2xxx HW vha->node_name: %8phC\n", vha->node_name);
6469 pr_debug("qla2xxx HW vha->port_name: %8phC\n", vha->port_name);
6470 put_unaligned_be64(wwpn, b);
6471 pr_debug("qla2xxx passed configfs WWPN: %8phC\n", b);
6475 * qla_tgt_lport_register - register lport with external module
6477 * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
6478 * @phys_wwpn: physical port WWPN
6479 * @npiv_wwpn: NPIV WWPN
6480 * @npiv_wwnn: NPIV WWNN
6481 * @callback: lport initialization callback for tcm_qla2xxx code
6483 int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn,
6484 u64 npiv_wwpn, u64 npiv_wwnn,
6485 int (*callback)(struct scsi_qla_host *, void *, u64, u64))
6487 struct qla_tgt *tgt;
6488 struct scsi_qla_host *vha;
6489 struct qla_hw_data *ha;
6490 struct Scsi_Host *host;
6491 unsigned long flags;
6495 mutex_lock(&qla_tgt_mutex);
6496 list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) {
6504 if (!(host->hostt->supported_mode & MODE_TARGET))
6507 if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
6510 spin_lock_irqsave(&ha->hardware_lock, flags);
6511 if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) {
6512 pr_debug("MODE_TARGET already active on qla2xxx(%d)\n",
6514 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6517 if (tgt->tgt_stop) {
6518 pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n",
6520 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6523 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6525 if (!scsi_host_get(host)) {
6526 ql_dbg(ql_dbg_tgt, vha, 0xe068,
6527 "Unable to scsi_host_get() for"
6528 " qla2xxx scsi_host\n");
6531 qlt_lport_dump(vha, phys_wwpn, b);
6533 if (memcmp(vha->port_name, b, WWN_SIZE)) {
6534 scsi_host_put(host);
6537 rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn);
6539 scsi_host_put(host);
6541 mutex_unlock(&qla_tgt_mutex);
6544 mutex_unlock(&qla_tgt_mutex);
6548 EXPORT_SYMBOL(qlt_lport_register);
6551 * qla_tgt_lport_deregister - Degister lport
6553 * @vha: Registered scsi_qla_host pointer
6555 void qlt_lport_deregister(struct scsi_qla_host *vha)
6557 struct qla_hw_data *ha = vha->hw;
6558 struct Scsi_Host *sh = vha->host;
6560 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
6562 vha->vha_tgt.target_lport_ptr = NULL;
6563 ha->tgt.tgt_ops = NULL;
6565 * Release the Scsi_Host reference for the underlying qla2xxx host
6569 EXPORT_SYMBOL(qlt_lport_deregister);
6571 /* Must be called under HW lock */
6572 void qlt_set_mode(struct scsi_qla_host *vha)
6574 switch (vha->qlini_mode) {
6575 case QLA2XXX_INI_MODE_DISABLED:
6576 case QLA2XXX_INI_MODE_EXCLUSIVE:
6577 vha->host->active_mode = MODE_TARGET;
6579 case QLA2XXX_INI_MODE_ENABLED:
6580 vha->host->active_mode = MODE_INITIATOR;
6582 case QLA2XXX_INI_MODE_DUAL:
6583 vha->host->active_mode = MODE_DUAL;
6590 /* Must be called under HW lock */
6591 static void qlt_clear_mode(struct scsi_qla_host *vha)
6593 switch (vha->qlini_mode) {
6594 case QLA2XXX_INI_MODE_DISABLED:
6595 vha->host->active_mode = MODE_UNKNOWN;
6597 case QLA2XXX_INI_MODE_EXCLUSIVE:
6598 vha->host->active_mode = MODE_INITIATOR;
6600 case QLA2XXX_INI_MODE_ENABLED:
6601 case QLA2XXX_INI_MODE_DUAL:
6602 vha->host->active_mode = MODE_INITIATOR;
6610 * qla_tgt_enable_vha - NO LOCK HELD
6612 * host_reset, bring up w/ Target Mode Enabled
6615 qlt_enable_vha(struct scsi_qla_host *vha)
6617 struct qla_hw_data *ha = vha->hw;
6618 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
6619 unsigned long flags;
6620 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6623 ql_dbg(ql_dbg_tgt, vha, 0xe069,
6624 "Unable to locate qla_tgt pointer from"
6625 " struct qla_hw_data\n");
6629 if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
6632 if (ha->tgt.num_act_qpairs > ha->max_qpairs)
6633 ha->tgt.num_act_qpairs = ha->max_qpairs;
6634 spin_lock_irqsave(&ha->hardware_lock, flags);
6635 tgt->tgt_stopped = 0;
6637 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6639 mutex_lock(&ha->optrom_mutex);
6640 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021,
6643 qla24xx_disable_vp(vha);
6644 qla24xx_enable_vp(vha);
6646 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6647 qla2xxx_wake_dpc(base_vha);
6648 WARN_ON_ONCE(qla2x00_wait_for_hba_online(base_vha) !=
6651 mutex_unlock(&ha->optrom_mutex);
6653 EXPORT_SYMBOL(qlt_enable_vha);
6656 * qla_tgt_disable_vha - NO LOCK HELD
6658 * Disable Target Mode and reset the adapter
6660 static void qlt_disable_vha(struct scsi_qla_host *vha)
6662 struct qla_hw_data *ha = vha->hw;
6663 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
6664 unsigned long flags;
6667 ql_dbg(ql_dbg_tgt, vha, 0xe06a,
6668 "Unable to locate qla_tgt pointer from"
6669 " struct qla_hw_data\n");
6674 spin_lock_irqsave(&ha->hardware_lock, flags);
6675 qlt_clear_mode(vha);
6676 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6678 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6679 qla2xxx_wake_dpc(vha);
6680 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
6681 ql_dbg(ql_dbg_tgt, vha, 0xe081,
6682 "qla2x00_wait_for_hba_online() failed\n");
6686 * Called from qla_init.c:qla24xx_vport_create() contex to setup
6687 * the target mode specific struct scsi_qla_host and struct qla_hw_data
6691 qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha)
6693 vha->vha_tgt.qla_tgt = NULL;
6695 mutex_init(&vha->vha_tgt.tgt_mutex);
6696 mutex_init(&vha->vha_tgt.tgt_host_action_mutex);
6698 qlt_clear_mode(vha);
6701 * NOTE: Currently the value is kept the same for <24xx and
6702 * >=24xx ISPs. If it is necessary to change it,
6703 * the check should be added for specific ISPs,
6704 * assigning the value appropriately.
6706 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
6708 qlt_add_target(ha, vha);
6712 qlt_rff_id(struct scsi_qla_host *vha)
6716 * FC-4 Feature bit 0 indicates target functionality to the name server.
6718 if (qla_tgt_mode_enabled(vha)) {
6719 fc4_feature = BIT_0;
6720 } else if (qla_ini_mode_enabled(vha)) {
6721 fc4_feature = BIT_1;
6722 } else if (qla_dual_mode_enabled(vha))
6723 fc4_feature = BIT_0 | BIT_1;
6729 * qlt_init_atio_q_entries() - Initializes ATIO queue entries.
6732 * Beginning of ATIO ring has initialization control block already built
6733 * by nvram config routine.
6735 * Returns 0 on success.
6738 qlt_init_atio_q_entries(struct scsi_qla_host *vha)
6740 struct qla_hw_data *ha = vha->hw;
6742 struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring;
6744 if (qla_ini_mode_enabled(vha))
6747 for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) {
6748 pkt->u.raw.signature = ATIO_PROCESSED;
6755 * qlt_24xx_process_atio_queue() - Process ATIO queue entries.
6756 * @ha: SCSI driver HA context
6759 qlt_24xx_process_atio_queue(struct scsi_qla_host *vha, uint8_t ha_locked)
6761 struct qla_hw_data *ha = vha->hw;
6762 struct atio_from_isp *pkt;
6765 if (!ha->flags.fw_started)
6768 while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) ||
6769 fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) {
6770 pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
6771 cnt = pkt->u.raw.entry_count;
6773 if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) {
6775 * This packet is corrupted. The header + payload
6776 * can not be trusted. There is no point in passing
6779 ql_log(ql_log_warn, vha, 0xd03c,
6780 "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n",
6781 &pkt->u.isp24.fcp_hdr.s_id,
6782 be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id),
6783 le32_to_cpu(pkt->u.isp24.exchange_addr), pkt);
6785 adjust_corrupted_atio(pkt);
6786 qlt_send_term_exchange(ha->base_qpair, NULL, pkt,
6789 qlt_24xx_atio_pkt_all_vps(vha,
6790 (struct atio_from_isp *)pkt, ha_locked);
6793 for (i = 0; i < cnt; i++) {
6794 ha->tgt.atio_ring_index++;
6795 if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) {
6796 ha->tgt.atio_ring_index = 0;
6797 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
6799 ha->tgt.atio_ring_ptr++;
6801 pkt->u.raw.signature = ATIO_PROCESSED;
6802 pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
6807 /* Adjust ring index */
6808 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index);
6812 qlt_24xx_config_rings(struct scsi_qla_host *vha)
6814 struct qla_hw_data *ha = vha->hw;
6815 struct qla_msix_entry *msix = &ha->msix_entries[2];
6816 struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb;
6818 if (!QLA_TGT_MODE_ENABLED())
6821 WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0);
6822 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0);
6823 RD_REG_DWORD(ISP_ATIO_Q_OUT(vha));
6825 if (ha->flags.msix_enabled) {
6826 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
6827 if (IS_QLA2071(ha)) {
6828 /* 4 ports Baker: Enable Interrupt Handshake */
6830 icb->firmware_options_2 |= BIT_26;
6832 icb->msix_atio = cpu_to_le16(msix->entry);
6833 icb->firmware_options_2 &= ~BIT_26;
6835 ql_dbg(ql_dbg_init, vha, 0xf072,
6836 "Registering ICB vector 0x%x for atio que.\n",
6841 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
6843 icb->firmware_options_2 |= BIT_26;
6844 ql_dbg(ql_dbg_init, vha, 0xf072,
6845 "%s: Use INTx for ATIOQ.\n", __func__);
6851 qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv)
6853 struct qla_hw_data *ha = vha->hw;
6856 if (!QLA_TGT_MODE_ENABLED())
6859 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
6860 if (!ha->tgt.saved_set) {
6861 /* We save only once */
6862 ha->tgt.saved_exchange_count = nv->exchange_count;
6863 ha->tgt.saved_firmware_options_1 =
6864 nv->firmware_options_1;
6865 ha->tgt.saved_firmware_options_2 =
6866 nv->firmware_options_2;
6867 ha->tgt.saved_firmware_options_3 =
6868 nv->firmware_options_3;
6869 ha->tgt.saved_set = 1;
6872 if (qla_tgt_mode_enabled(vha))
6873 nv->exchange_count = cpu_to_le16(0xFFFF);
6875 nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
6877 /* Enable target mode */
6878 nv->firmware_options_1 |= cpu_to_le32(BIT_4);
6880 /* Disable ini mode, if requested */
6881 if (qla_tgt_mode_enabled(vha))
6882 nv->firmware_options_1 |= cpu_to_le32(BIT_5);
6884 /* Disable Full Login after LIP */
6885 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
6886 /* Enable initial LIP */
6887 nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
6888 if (ql2xtgt_tape_enable)
6889 /* Enable FC Tape support */
6890 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6892 /* Disable FC Tape support */
6893 nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
6895 /* Disable Full Login after LIP */
6896 nv->host_p &= cpu_to_le32(~BIT_10);
6899 * clear BIT 15 explicitly as we have seen at least
6900 * a couple of instances where this was set and this
6901 * was causing the firmware to not be initialized.
6903 nv->firmware_options_1 &= cpu_to_le32(~BIT_15);
6904 /* Enable target PRLI control */
6905 nv->firmware_options_2 |= cpu_to_le32(BIT_14);
6907 if (IS_QLA25XX(ha)) {
6908 /* Change Loop-prefer to Pt-Pt */
6909 tmp = ~(BIT_4|BIT_5|BIT_6);
6910 nv->firmware_options_2 &= cpu_to_le32(tmp);
6912 nv->firmware_options_2 |= cpu_to_le32(tmp);
6915 if (ha->tgt.saved_set) {
6916 nv->exchange_count = ha->tgt.saved_exchange_count;
6917 nv->firmware_options_1 =
6918 ha->tgt.saved_firmware_options_1;
6919 nv->firmware_options_2 =
6920 ha->tgt.saved_firmware_options_2;
6921 nv->firmware_options_3 =
6922 ha->tgt.saved_firmware_options_3;
6927 if (ha->base_qpair->enable_class_2) {
6928 if (vha->flags.init_done)
6929 fc_host_supported_classes(vha->host) =
6930 FC_COS_CLASS2 | FC_COS_CLASS3;
6932 nv->firmware_options_2 |= cpu_to_le32(BIT_8);
6934 if (vha->flags.init_done)
6935 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
6937 nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
6942 qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha,
6943 struct init_cb_24xx *icb)
6945 struct qla_hw_data *ha = vha->hw;
6947 if (!QLA_TGT_MODE_ENABLED())
6950 if (ha->tgt.node_name_set) {
6951 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
6952 icb->firmware_options_1 |= cpu_to_le32(BIT_14);
6957 qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv)
6959 struct qla_hw_data *ha = vha->hw;
6962 if (!QLA_TGT_MODE_ENABLED())
6965 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
6966 if (!ha->tgt.saved_set) {
6967 /* We save only once */
6968 ha->tgt.saved_exchange_count = nv->exchange_count;
6969 ha->tgt.saved_firmware_options_1 =
6970 nv->firmware_options_1;
6971 ha->tgt.saved_firmware_options_2 =
6972 nv->firmware_options_2;
6973 ha->tgt.saved_firmware_options_3 =
6974 nv->firmware_options_3;
6975 ha->tgt.saved_set = 1;
6978 if (qla_tgt_mode_enabled(vha))
6979 nv->exchange_count = cpu_to_le16(0xFFFF);
6981 nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
6983 /* Enable target mode */
6984 nv->firmware_options_1 |= cpu_to_le32(BIT_4);
6986 /* Disable ini mode, if requested */
6987 if (qla_tgt_mode_enabled(vha))
6988 nv->firmware_options_1 |= cpu_to_le32(BIT_5);
6989 /* Disable Full Login after LIP */
6990 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
6991 /* Enable initial LIP */
6992 nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
6994 * clear BIT 15 explicitly as we have seen at
6995 * least a couple of instances where this was set
6996 * and this was causing the firmware to not be
6999 nv->firmware_options_1 &= cpu_to_le32(~BIT_15);
7000 if (ql2xtgt_tape_enable)
7001 /* Enable FC tape support */
7002 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7004 /* Disable FC tape support */
7005 nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
7007 /* Disable Full Login after LIP */
7008 nv->host_p &= cpu_to_le32(~BIT_10);
7009 /* Enable target PRLI control */
7010 nv->firmware_options_2 |= cpu_to_le32(BIT_14);
7012 /* Change Loop-prefer to Pt-Pt */
7013 tmp = ~(BIT_4|BIT_5|BIT_6);
7014 nv->firmware_options_2 &= cpu_to_le32(tmp);
7016 nv->firmware_options_2 |= cpu_to_le32(tmp);
7018 if (ha->tgt.saved_set) {
7019 nv->exchange_count = ha->tgt.saved_exchange_count;
7020 nv->firmware_options_1 =
7021 ha->tgt.saved_firmware_options_1;
7022 nv->firmware_options_2 =
7023 ha->tgt.saved_firmware_options_2;
7024 nv->firmware_options_3 =
7025 ha->tgt.saved_firmware_options_3;
7030 if (ha->base_qpair->enable_class_2) {
7031 if (vha->flags.init_done)
7032 fc_host_supported_classes(vha->host) =
7033 FC_COS_CLASS2 | FC_COS_CLASS3;
7035 nv->firmware_options_2 |= cpu_to_le32(BIT_8);
7037 if (vha->flags.init_done)
7038 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
7040 nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
7045 qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha,
7046 struct init_cb_81xx *icb)
7048 struct qla_hw_data *ha = vha->hw;
7050 if (!QLA_TGT_MODE_ENABLED())
7053 if (ha->tgt.node_name_set) {
7054 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
7055 icb->firmware_options_1 |= cpu_to_le32(BIT_14);
7060 qlt_83xx_iospace_config(struct qla_hw_data *ha)
7062 if (!QLA_TGT_MODE_ENABLED())
7065 ha->msix_count += 1; /* For ATIO Q */
7070 qlt_modify_vp_config(struct scsi_qla_host *vha,
7071 struct vp_config_entry_24xx *vpmod)
7073 /* enable target mode. Bit5 = 1 => disable */
7074 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7075 vpmod->options_idx1 &= ~BIT_5;
7077 /* Disable ini mode, if requested. bit4 = 1 => disable */
7078 if (qla_tgt_mode_enabled(vha))
7079 vpmod->options_idx1 &= ~BIT_4;
7083 qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha)
7087 if (!QLA_TGT_MODE_ENABLED())
7090 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
7091 ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in;
7092 ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out;
7094 ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in;
7095 ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out;
7098 mutex_init(&base_vha->vha_tgt.tgt_mutex);
7099 mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex);
7101 INIT_LIST_HEAD(&base_vha->unknown_atio_list);
7102 INIT_DELAYED_WORK(&base_vha->unknown_atio_work,
7103 qlt_unknown_atio_work_fn);
7105 qlt_clear_mode(base_vha);
7107 rc = btree_init32(&ha->tgt.host_map);
7109 ql_log(ql_log_info, base_vha, 0xd03d,
7110 "Unable to initialize ha->host_map btree\n");
7112 qlt_update_vp_map(base_vha, SET_VP_IDX);
7116 qla83xx_msix_atio_q(int irq, void *dev_id)
7118 struct rsp_que *rsp;
7119 scsi_qla_host_t *vha;
7120 struct qla_hw_data *ha;
7121 unsigned long flags;
7123 rsp = (struct rsp_que *) dev_id;
7125 vha = pci_get_drvdata(ha->pdev);
7127 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
7129 qlt_24xx_process_atio_queue(vha, 0);
7131 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
7137 qlt_handle_abts_recv_work(struct work_struct *work)
7139 struct qla_tgt_sess_op *op = container_of(work,
7140 struct qla_tgt_sess_op, work);
7141 scsi_qla_host_t *vha = op->vha;
7142 struct qla_hw_data *ha = vha->hw;
7143 unsigned long flags;
7145 if (qla2x00_reset_active(vha) ||
7146 (op->chip_reset != ha->base_qpair->chip_reset))
7149 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
7150 qlt_24xx_process_atio_queue(vha, 0);
7151 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
7153 spin_lock_irqsave(&ha->hardware_lock, flags);
7154 qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio);
7155 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7161 qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp,
7164 struct qla_tgt_sess_op *op;
7166 op = kzalloc(sizeof(*op), GFP_ATOMIC);
7169 /* do not reach for ATIO queue here. This is best effort err
7170 * recovery at this point.
7172 qlt_response_pkt_all_vps(vha, rsp, pkt);
7176 memcpy(&op->atio, pkt, sizeof(*pkt));
7178 op->chip_reset = vha->hw->base_qpair->chip_reset;
7180 INIT_WORK(&op->work, qlt_handle_abts_recv_work);
7181 queue_work(qla_tgt_wq, &op->work);
7186 qlt_mem_alloc(struct qla_hw_data *ha)
7188 if (!QLA_TGT_MODE_ENABLED())
7191 ha->tgt.tgt_vp_map = kcalloc(MAX_MULTI_ID_FABRIC,
7192 sizeof(struct qla_tgt_vp_map),
7194 if (!ha->tgt.tgt_vp_map)
7197 ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev,
7198 (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp),
7199 &ha->tgt.atio_dma, GFP_KERNEL);
7200 if (!ha->tgt.atio_ring) {
7201 kfree(ha->tgt.tgt_vp_map);
7208 qlt_mem_free(struct qla_hw_data *ha)
7210 if (!QLA_TGT_MODE_ENABLED())
7213 if (ha->tgt.atio_ring) {
7214 dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) *
7215 sizeof(struct atio_from_isp), ha->tgt.atio_ring,
7218 ha->tgt.atio_ring = NULL;
7219 ha->tgt.atio_dma = 0;
7220 kfree(ha->tgt.tgt_vp_map);
7221 ha->tgt.tgt_vp_map = NULL;
7224 /* vport_slock to be held by the caller */
7226 qlt_update_vp_map(struct scsi_qla_host *vha, int cmd)
7232 if (!QLA_TGT_MODE_ENABLED())
7235 key = vha->d_id.b24;
7239 vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha;
7242 slot = btree_lookup32(&vha->hw->tgt.host_map, key);
7244 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018,
7245 "Save vha in host_map %p %06x\n", vha, key);
7246 rc = btree_insert32(&vha->hw->tgt.host_map,
7247 key, vha, GFP_ATOMIC);
7249 ql_log(ql_log_info, vha, 0xd03e,
7250 "Unable to insert s_id into host_map: %06x\n",
7254 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019,
7255 "replace existing vha in host_map %p %06x\n", vha, key);
7256 btree_update32(&vha->hw->tgt.host_map, key, vha);
7259 vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL;
7262 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a,
7263 "clear vha in host_map %p %06x\n", vha, key);
7264 slot = btree_lookup32(&vha->hw->tgt.host_map, key);
7266 btree_remove32(&vha->hw->tgt.host_map, key);
7272 void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id)
7275 if (!vha->d_id.b24) {
7277 qlt_update_vp_map(vha, SET_AL_PA);
7278 } else if (vha->d_id.b24 != id.b24) {
7279 qlt_update_vp_map(vha, RESET_AL_PA);
7281 qlt_update_vp_map(vha, SET_AL_PA);
7285 static int __init qlt_parse_ini_mode(void)
7287 if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0)
7288 ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE;
7289 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0)
7290 ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED;
7291 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0)
7292 ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED;
7293 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0)
7294 ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL;
7301 int __init qlt_init(void)
7305 BUILD_BUG_ON(sizeof(struct ctio7_to_24xx) != 64);
7306 BUILD_BUG_ON(sizeof(struct ctio_to_2xxx) != 64);
7308 if (!qlt_parse_ini_mode()) {
7309 ql_log(ql_log_fatal, NULL, 0xe06b,
7310 "qlt_parse_ini_mode() failed\n");
7314 if (!QLA_TGT_MODE_ENABLED())
7317 qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep",
7318 sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct
7319 qla_tgt_mgmt_cmd), 0, NULL);
7320 if (!qla_tgt_mgmt_cmd_cachep) {
7321 ql_log(ql_log_fatal, NULL, 0xd04b,
7322 "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
7326 qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep",
7327 sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t),
7330 if (!qla_tgt_plogi_cachep) {
7331 ql_log(ql_log_fatal, NULL, 0xe06d,
7332 "kmem_cache_create for qla_tgt_plogi_cachep failed\n");
7334 goto out_mgmt_cmd_cachep;
7337 qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab,
7338 mempool_free_slab, qla_tgt_mgmt_cmd_cachep);
7339 if (!qla_tgt_mgmt_cmd_mempool) {
7340 ql_log(ql_log_fatal, NULL, 0xe06e,
7341 "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
7343 goto out_plogi_cachep;
7346 qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0);
7348 ql_log(ql_log_fatal, NULL, 0xe06f,
7349 "alloc_workqueue for qla_tgt_wq failed\n");
7351 goto out_cmd_mempool;
7354 * Return 1 to signal that initiator-mode is being disabled
7356 return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0;
7359 mempool_destroy(qla_tgt_mgmt_cmd_mempool);
7361 kmem_cache_destroy(qla_tgt_plogi_cachep);
7362 out_mgmt_cmd_cachep:
7363 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep);
7369 if (!QLA_TGT_MODE_ENABLED())
7372 destroy_workqueue(qla_tgt_wq);
7373 mempool_destroy(qla_tgt_mgmt_cmd_mempool);
7374 kmem_cache_destroy(qla_tgt_plogi_cachep);
7375 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep);