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>
32 #include "qla_target.h"
34 static int ql2xtgt_tape_enable;
35 module_param(ql2xtgt_tape_enable, int, S_IRUGO|S_IWUSR);
36 MODULE_PARM_DESC(ql2xtgt_tape_enable,
37 "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER.");
39 static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED;
40 module_param(qlini_mode, charp, S_IRUGO);
41 MODULE_PARM_DESC(qlini_mode,
42 "Determines when initiator mode will be enabled. Possible values: "
43 "\"exclusive\" - initiator mode will be enabled on load, "
44 "disabled on enabling target mode and then on disabling target mode "
46 "\"disabled\" - initiator mode will never be enabled; "
47 "\"dual\" - Initiator Modes will be enabled. Target Mode can be activated "
49 "\"enabled\" (default) - initiator mode will always stay enabled.");
51 static int ql_dm_tgt_ex_pct = 0;
52 module_param(ql_dm_tgt_ex_pct, int, S_IRUGO|S_IWUSR);
53 MODULE_PARM_DESC(ql_dm_tgt_ex_pct,
54 "For Dual Mode (qlini_mode=dual), this parameter determines "
55 "the percentage of exchanges/cmds FW will allocate resources "
59 module_param(ql2xuctrlirq, int, 0644);
60 MODULE_PARM_DESC(ql2xuctrlirq,
61 "User to control IRQ placement via smp_affinity."
62 "Valid with qlini_mode=disabled."
63 "1(default): enable");
65 int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE;
67 static int qla_sam_status = SAM_STAT_BUSY;
68 static int tc_sam_status = SAM_STAT_TASK_SET_FULL; /* target core */
71 * From scsi/fc/fc_fcp.h
73 enum fcp_resp_rsp_codes {
75 FCP_DATA_LEN_INVALID = 1,
76 FCP_CMND_FIELDS_INVALID = 2,
77 FCP_DATA_PARAM_MISMATCH = 3,
80 FCP_TMF_INVALID_LUN = 9,
84 * fc_pri_ta from scsi/fc/fc_fcp.h
86 #define FCP_PTA_SIMPLE 0 /* simple task attribute */
87 #define FCP_PTA_HEADQ 1 /* head of queue task attribute */
88 #define FCP_PTA_ORDERED 2 /* ordered task attribute */
89 #define FCP_PTA_ACA 4 /* auto. contingent allegiance */
90 #define FCP_PTA_MASK 7 /* mask for task attribute field */
91 #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */
92 #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */
95 * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which
96 * must be called under HW lock and could unlock/lock it inside.
97 * It isn't an issue, since in the current implementation on the time when
98 * those functions are called:
100 * - Either context is IRQ and only IRQ handler can modify HW data,
101 * including rings related fields,
103 * - Or access to target mode variables from struct qla_tgt doesn't
104 * cross those functions boundaries, except tgt_stop, which
105 * additionally protected by irq_cmd_count.
107 /* Predefs for callbacks handed to qla2xxx LLD */
108 static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha,
109 struct atio_from_isp *pkt, uint8_t);
110 static void qlt_response_pkt(struct scsi_qla_host *ha, struct rsp_que *rsp,
112 static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun,
113 int fn, void *iocb, int flags);
114 static void qlt_send_term_exchange(struct qla_qpair *, struct qla_tgt_cmd
115 *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort);
116 static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
117 struct atio_from_isp *atio, uint16_t status, int qfull);
118 static void qlt_disable_vha(struct scsi_qla_host *vha);
119 static void qlt_clear_tgt_db(struct qla_tgt *tgt);
120 static void qlt_send_notify_ack(struct qla_qpair *qpair,
121 struct imm_ntfy_from_isp *ntfy,
122 uint32_t add_flags, uint16_t resp_code, int resp_code_valid,
123 uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan);
124 static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
125 struct imm_ntfy_from_isp *imm, int ha_locked);
126 static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha,
127 fc_port_t *fcport, bool local);
128 void qlt_unreg_sess(struct fc_port *sess);
129 static void qlt_24xx_handle_abts(struct scsi_qla_host *,
130 struct abts_recv_from_24xx *);
131 static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *,
133 static int qlt_check_reserve_free_req(struct qla_qpair *qpair, uint32_t);
134 static inline uint32_t qlt_make_handle(struct qla_qpair *);
139 static struct kmem_cache *qla_tgt_mgmt_cmd_cachep;
140 struct kmem_cache *qla_tgt_plogi_cachep;
141 static mempool_t *qla_tgt_mgmt_cmd_mempool;
142 static struct workqueue_struct *qla_tgt_wq;
143 static DEFINE_MUTEX(qla_tgt_mutex);
144 static LIST_HEAD(qla_tgt_glist);
146 static const char *prot_op_str(u32 prot_op)
149 case TARGET_PROT_NORMAL: return "NORMAL";
150 case TARGET_PROT_DIN_INSERT: return "DIN_INSERT";
151 case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT";
152 case TARGET_PROT_DIN_STRIP: return "DIN_STRIP";
153 case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP";
154 case TARGET_PROT_DIN_PASS: return "DIN_PASS";
155 case TARGET_PROT_DOUT_PASS: return "DOUT_PASS";
156 default: return "UNKNOWN";
160 /* This API intentionally takes dest as a parameter, rather than returning
161 * int value to avoid caller forgetting to issue wmb() after the store */
162 void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest)
164 scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev);
165 *dest = atomic_inc_return(&base_vha->generation_tick);
170 /* Might release hw lock, then reaquire!! */
171 static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked)
173 /* Send marker if required */
174 if (unlikely(vha->marker_needed != 0)) {
175 int rc = qla2x00_issue_marker(vha, vha_locked);
177 if (rc != QLA_SUCCESS) {
178 ql_dbg(ql_dbg_tgt, vha, 0xe03d,
179 "qla_target(%d): issue_marker() failed\n",
188 struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha,
191 struct scsi_qla_host *host;
194 if (vha->d_id.b.area == d_id.area &&
195 vha->d_id.b.domain == d_id.domain &&
196 vha->d_id.b.al_pa == d_id.al_pa)
199 key = be_to_port_id(d_id).b24;
201 host = btree_lookup32(&vha->hw->tgt.host_map, key);
203 ql_dbg(ql_dbg_tgt_mgt + ql_dbg_verbose, vha, 0xf005,
204 "Unable to find host %06x\n", key);
210 struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha,
213 struct qla_hw_data *ha = vha->hw;
215 if (vha->vp_idx == vp_idx)
218 BUG_ON(ha->tgt.tgt_vp_map == NULL);
219 if (likely(test_bit(vp_idx, ha->vp_idx_map)))
220 return ha->tgt.tgt_vp_map[vp_idx].vha;
225 static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha)
229 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
231 vha->hw->tgt.num_pend_cmds++;
232 if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds)
233 vha->qla_stats.stat_max_pend_cmds =
234 vha->hw->tgt.num_pend_cmds;
235 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
237 static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha)
241 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
242 vha->hw->tgt.num_pend_cmds--;
243 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
247 static void qlt_queue_unknown_atio(scsi_qla_host_t *vha,
248 struct atio_from_isp *atio, uint8_t ha_locked)
250 struct qla_tgt_sess_op *u;
251 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
255 ql_dbg(ql_dbg_async, vha, 0x502c,
256 "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped",
261 u = kzalloc(sizeof(*u), GFP_ATOMIC);
266 memcpy(&u->atio, atio, sizeof(*atio));
267 INIT_LIST_HEAD(&u->cmd_list);
269 spin_lock_irqsave(&vha->cmd_list_lock, flags);
270 list_add_tail(&u->cmd_list, &vha->unknown_atio_list);
271 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
273 schedule_delayed_work(&vha->unknown_atio_work, 1);
279 qlt_send_term_exchange(vha->hw->base_qpair, NULL, atio, ha_locked, 0);
283 static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha,
286 struct qla_tgt_sess_op *u, *t;
287 scsi_qla_host_t *host;
288 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
292 list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) {
294 ql_dbg(ql_dbg_async, vha, 0x502e,
295 "Freeing unknown %s %p, because of Abort\n",
297 qlt_send_term_exchange(vha->hw->base_qpair, NULL,
298 &u->atio, ha_locked, 0);
302 host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id);
304 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x502f,
305 "Requeuing unknown ATIO_TYPE7 %p\n", u);
306 qlt_24xx_atio_pkt(host, &u->atio, ha_locked);
307 } else if (tgt->tgt_stop) {
308 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503a,
309 "Freeing unknown %s %p, because tgt is being stopped\n",
311 qlt_send_term_exchange(vha->hw->base_qpair, NULL,
312 &u->atio, ha_locked, 0);
314 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d,
315 "Reschedule u %p, vha %p, host %p\n", u, vha, host);
318 schedule_delayed_work(&vha->unknown_atio_work,
325 spin_lock_irqsave(&vha->cmd_list_lock, flags);
326 list_del(&u->cmd_list);
327 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
332 void qlt_unknown_atio_work_fn(struct work_struct *work)
334 struct scsi_qla_host *vha = container_of(to_delayed_work(work),
335 struct scsi_qla_host, unknown_atio_work);
337 qlt_try_to_dequeue_unknown_atios(vha, 0);
340 static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *vha,
341 struct atio_from_isp *atio, uint8_t ha_locked)
343 ql_dbg(ql_dbg_tgt, vha, 0xe072,
344 "%s: qla_target(%d): type %x ox_id %04x\n",
345 __func__, vha->vp_idx, atio->u.raw.entry_type,
346 be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
348 switch (atio->u.raw.entry_type) {
351 struct scsi_qla_host *host = qlt_find_host_by_d_id(vha,
352 atio->u.isp24.fcp_hdr.d_id);
353 if (unlikely(NULL == host)) {
354 ql_dbg(ql_dbg_tgt, vha, 0xe03e,
355 "qla_target(%d): Received ATIO_TYPE7 "
356 "with unknown d_id %x:%x:%x\n", vha->vp_idx,
357 atio->u.isp24.fcp_hdr.d_id.domain,
358 atio->u.isp24.fcp_hdr.d_id.area,
359 atio->u.isp24.fcp_hdr.d_id.al_pa);
362 qlt_queue_unknown_atio(vha, atio, ha_locked);
365 if (unlikely(!list_empty(&vha->unknown_atio_list)))
366 qlt_try_to_dequeue_unknown_atios(vha, ha_locked);
368 qlt_24xx_atio_pkt(host, atio, ha_locked);
372 case IMMED_NOTIFY_TYPE:
374 struct scsi_qla_host *host = vha;
375 struct imm_ntfy_from_isp *entry =
376 (struct imm_ntfy_from_isp *)atio;
378 qlt_issue_marker(vha, ha_locked);
380 if ((entry->u.isp24.vp_index != 0xFF) &&
381 (entry->u.isp24.nport_handle != cpu_to_le16(0xFFFF))) {
382 host = qlt_find_host_by_vp_idx(vha,
383 entry->u.isp24.vp_index);
384 if (unlikely(!host)) {
385 ql_dbg(ql_dbg_tgt, vha, 0xe03f,
386 "qla_target(%d): Received "
387 "ATIO (IMMED_NOTIFY_TYPE) "
388 "with unknown vp_index %d\n",
389 vha->vp_idx, entry->u.isp24.vp_index);
393 qlt_24xx_atio_pkt(host, atio, ha_locked);
397 case VP_RPT_ID_IOCB_TYPE:
398 qla24xx_report_id_acquisition(vha,
399 (struct vp_rpt_id_entry_24xx *)atio);
404 struct abts_recv_from_24xx *entry =
405 (struct abts_recv_from_24xx *)atio;
406 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
410 if (unlikely(!host)) {
411 ql_dbg(ql_dbg_tgt, vha, 0xe00a,
412 "qla_target(%d): Response pkt (ABTS_RECV_24XX) "
413 "received, with unknown vp_index %d\n",
414 vha->vp_idx, entry->vp_index);
418 spin_lock_irqsave(&host->hw->hardware_lock, flags);
419 qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio);
421 spin_unlock_irqrestore(&host->hw->hardware_lock, flags);
425 /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */
428 ql_dbg(ql_dbg_tgt, vha, 0xe040,
429 "qla_target(%d): Received unknown ATIO atio "
430 "type %x\n", vha->vp_idx, atio->u.raw.entry_type);
437 void qlt_response_pkt_all_vps(struct scsi_qla_host *vha,
438 struct rsp_que *rsp, response_t *pkt)
440 switch (pkt->entry_type) {
442 ql_dbg(ql_dbg_tgt, vha, 0xe073,
443 "qla_target(%d):%s: CRC2 Response pkt\n",
444 vha->vp_idx, __func__);
448 struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
449 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
451 if (unlikely(!host)) {
452 ql_dbg(ql_dbg_tgt, vha, 0xe041,
453 "qla_target(%d): Response pkt (CTIO_TYPE7) "
454 "received, with unknown vp_index %d\n",
455 vha->vp_idx, entry->vp_index);
458 qlt_response_pkt(host, rsp, pkt);
462 case IMMED_NOTIFY_TYPE:
464 struct scsi_qla_host *host;
465 struct imm_ntfy_from_isp *entry =
466 (struct imm_ntfy_from_isp *)pkt;
468 host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index);
469 if (unlikely(!host)) {
470 ql_dbg(ql_dbg_tgt, vha, 0xe042,
471 "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
472 "received, with unknown vp_index %d\n",
473 vha->vp_idx, entry->u.isp24.vp_index);
476 qlt_response_pkt(host, rsp, pkt);
480 case NOTIFY_ACK_TYPE:
482 struct scsi_qla_host *host = vha;
483 struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
485 if (0xFF != entry->u.isp24.vp_index) {
486 host = qlt_find_host_by_vp_idx(vha,
487 entry->u.isp24.vp_index);
488 if (unlikely(!host)) {
489 ql_dbg(ql_dbg_tgt, vha, 0xe043,
490 "qla_target(%d): Response "
491 "pkt (NOTIFY_ACK_TYPE) "
492 "received, with unknown "
493 "vp_index %d\n", vha->vp_idx,
494 entry->u.isp24.vp_index);
498 qlt_response_pkt(host, rsp, pkt);
504 struct abts_recv_from_24xx *entry =
505 (struct abts_recv_from_24xx *)pkt;
506 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
508 if (unlikely(!host)) {
509 ql_dbg(ql_dbg_tgt, vha, 0xe044,
510 "qla_target(%d): Response pkt "
511 "(ABTS_RECV_24XX) received, with unknown "
512 "vp_index %d\n", vha->vp_idx, entry->vp_index);
515 qlt_response_pkt(host, rsp, pkt);
521 struct abts_resp_to_24xx *entry =
522 (struct abts_resp_to_24xx *)pkt;
523 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
525 if (unlikely(!host)) {
526 ql_dbg(ql_dbg_tgt, vha, 0xe045,
527 "qla_target(%d): Response pkt "
528 "(ABTS_RECV_24XX) received, with unknown "
529 "vp_index %d\n", vha->vp_idx, entry->vp_index);
532 qlt_response_pkt(host, rsp, pkt);
536 qlt_response_pkt(vha, rsp, pkt);
543 * All qlt_plogi_ack_t operations are protected by hardware_lock
545 static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport,
546 struct imm_ntfy_from_isp *ntfy, int type)
548 struct qla_work_evt *e;
550 e = qla2x00_alloc_work(vha, QLA_EVT_NACK);
552 return QLA_FUNCTION_FAILED;
554 e->u.nack.fcport = fcport;
555 e->u.nack.type = type;
556 memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp));
557 return qla2x00_post_work(vha, e);
560 static void qla2x00_async_nack_sp_done(srb_t *sp, int res)
562 struct scsi_qla_host *vha = sp->vha;
565 ql_dbg(ql_dbg_disc, vha, 0x20f2,
566 "Async done-%s res %x %8phC type %d\n",
567 sp->name, res, sp->fcport->port_name, sp->type);
569 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
570 sp->fcport->flags &= ~FCF_ASYNC_SENT;
571 sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
575 sp->fcport->login_gen++;
576 sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
577 sp->fcport->logout_on_delete = 1;
578 sp->fcport->plogi_nack_done_deadline = jiffies + HZ;
579 sp->fcport->send_els_logo = 0;
583 sp->fcport->fw_login_state = DSC_LS_PRLI_COMP;
584 sp->fcport->deleted = 0;
585 sp->fcport->send_els_logo = 0;
587 if (!sp->fcport->login_succ &&
588 !IS_SW_RESV_ADDR(sp->fcport->d_id)) {
589 sp->fcport->login_succ = 1;
592 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
593 qla24xx_sched_upd_fcport(sp->fcport);
594 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
596 sp->fcport->login_retry = 0;
597 qla2x00_set_fcport_disc_state(sp->fcport,
599 sp->fcport->deleted = 0;
600 sp->fcport->logout_on_delete = 1;
605 sp->fcport->login_gen++;
606 sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
607 qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE);
610 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
615 int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport,
616 struct imm_ntfy_from_isp *ntfy, int type)
618 int rval = QLA_FUNCTION_FAILED;
622 fcport->flags |= FCF_ASYNC_SENT;
625 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
629 fcport->fw_login_state = DSC_LS_PRLI_PEND;
634 fcport->fw_login_state = DSC_LS_LOGO_PEND;
639 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
646 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
647 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
649 sp->u.iocb_cmd.u.nack.ntfy = ntfy;
650 sp->done = qla2x00_async_nack_sp_done;
652 ql_dbg(ql_dbg_disc, vha, 0x20f4,
653 "Async-%s %8phC hndl %x %s\n",
654 sp->name, fcport->port_name, sp->handle, c);
656 rval = qla2x00_start_sp(sp);
657 if (rval != QLA_SUCCESS)
665 fcport->flags &= ~FCF_ASYNC_SENT;
669 void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
673 switch (e->u.nack.type) {
675 t = e->u.nack.fcport;
676 flush_work(&t->del_work);
677 flush_work(&t->free_work);
678 mutex_lock(&vha->vha_tgt.tgt_mutex);
679 t = qlt_create_sess(vha, e->u.nack.fcport, 0);
680 mutex_unlock(&vha->vha_tgt.tgt_mutex);
682 ql_log(ql_log_info, vha, 0xd034,
683 "%s create sess success %p", __func__, t);
684 /* create sess has an extra kref */
685 vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport);
689 qla24xx_async_notify_ack(vha, e->u.nack.fcport,
690 (struct imm_ntfy_from_isp *)e->u.nack.iocb, e->u.nack.type);
693 void qla24xx_delete_sess_fn(struct work_struct *work)
695 fc_port_t *fcport = container_of(work, struct fc_port, del_work);
696 struct qla_hw_data *ha = fcport->vha->hw;
698 if (fcport->se_sess) {
699 ha->tgt.tgt_ops->shutdown_sess(fcport);
700 ha->tgt.tgt_ops->put_sess(fcport);
702 qlt_unreg_sess(fcport);
707 * Called from qla2x00_reg_remote_port()
709 void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport)
711 struct qla_hw_data *ha = vha->hw;
712 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
713 struct fc_port *sess = fcport;
716 if (!vha->hw->tgt.tgt_ops)
719 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
721 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
725 if (fcport->disc_state == DSC_DELETE_PEND) {
726 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
730 if (!sess->se_sess) {
731 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
733 mutex_lock(&vha->vha_tgt.tgt_mutex);
734 sess = qlt_create_sess(vha, fcport, false);
735 mutex_unlock(&vha->vha_tgt.tgt_mutex);
737 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
739 if (fcport->fw_login_state == DSC_LS_PRLI_COMP) {
740 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
744 if (!kref_get_unless_zero(&sess->sess_kref)) {
745 ql_dbg(ql_dbg_disc, vha, 0x2107,
746 "%s: kref_get fail sess %8phC \n",
747 __func__, sess->port_name);
748 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
752 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c,
753 "qla_target(%u): %ssession for port %8phC "
754 "(loop ID %d) reappeared\n", vha->vp_idx,
755 sess->local ? "local " : "", sess->port_name, sess->loop_id);
757 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007,
758 "Reappeared sess %p\n", sess);
760 ha->tgt.tgt_ops->update_sess(sess, fcport->d_id,
762 (fcport->flags & FCF_CONF_COMP_SUPPORTED));
765 if (sess && sess->local) {
766 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d,
767 "qla_target(%u): local session for "
768 "port %8phC (loop ID %d) became global\n", vha->vp_idx,
769 fcport->port_name, sess->loop_id);
772 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
774 ha->tgt.tgt_ops->put_sess(sess);
778 * This is a zero-base ref-counting solution, since hardware_lock
779 * guarantees that ref_count is not modified concurrently.
780 * Upon successful return content of iocb is undefined
782 static struct qlt_plogi_ack_t *
783 qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id,
784 struct imm_ntfy_from_isp *iocb)
786 struct qlt_plogi_ack_t *pla;
788 lockdep_assert_held(&vha->hw->hardware_lock);
790 list_for_each_entry(pla, &vha->plogi_ack_list, list) {
791 if (pla->id.b24 == id->b24) {
792 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x210d,
793 "%s %d %8phC Term INOT due to new INOT",
795 pla->iocb.u.isp24.port_name);
796 qlt_send_term_imm_notif(vha, &pla->iocb, 1);
797 memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
802 pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC);
804 ql_dbg(ql_dbg_async, vha, 0x5088,
805 "qla_target(%d): Allocation of plogi_ack failed\n",
810 memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
812 list_add_tail(&pla->list, &vha->plogi_ack_list);
817 void qlt_plogi_ack_unref(struct scsi_qla_host *vha,
818 struct qlt_plogi_ack_t *pla)
820 struct imm_ntfy_from_isp *iocb = &pla->iocb;
823 fc_port_t *fcport = pla->fcport;
825 BUG_ON(!pla->ref_count);
831 ql_dbg(ql_dbg_disc, vha, 0x5089,
832 "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x"
833 " exch %#x ox_id %#x\n", iocb->u.isp24.port_name,
834 iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1],
835 iocb->u.isp24.port_id[0],
836 le16_to_cpu(iocb->u.isp24.nport_handle),
837 iocb->u.isp24.exchange_address, iocb->ox_id);
839 port_id.b.domain = iocb->u.isp24.port_id[2];
840 port_id.b.area = iocb->u.isp24.port_id[1];
841 port_id.b.al_pa = iocb->u.isp24.port_id[0];
842 port_id.b.rsvd_1 = 0;
844 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
846 fcport->loop_id = loop_id;
847 fcport->d_id = port_id;
848 if (iocb->u.isp24.status_subcode == ELS_PLOGI)
849 qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI);
851 qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PRLI);
853 list_for_each_entry(fcport, &vha->vp_fcports, list) {
854 if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla)
855 fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL;
856 if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla)
857 fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL;
860 list_del(&pla->list);
861 kmem_cache_free(qla_tgt_plogi_cachep, pla);
865 qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla,
866 struct fc_port *sess, enum qlt_plogi_link_t link)
868 struct imm_ntfy_from_isp *iocb = &pla->iocb;
869 /* Inc ref_count first because link might already be pointing at pla */
872 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097,
873 "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC"
874 " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n",
875 sess, link, sess->port_name,
876 iocb->u.isp24.port_name, iocb->u.isp24.port_id[2],
877 iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0],
878 pla->ref_count, pla, link);
880 if (link == QLT_PLOGI_LINK_CONFLICT) {
881 switch (sess->disc_state) {
883 case DSC_DELETE_PEND:
891 if (sess->plogi_link[link])
892 qlt_plogi_ack_unref(vha, sess->plogi_link[link]);
894 if (link == QLT_PLOGI_LINK_SAME_WWN)
897 sess->plogi_link[link] = pla;
901 /* These fields must be initialized by the caller */
904 * number of cmds dropped while we were waiting for
905 * initiator to ack LOGO initialize to 1 if LOGO is
906 * triggered by a command, otherwise, to 0
910 /* These fields are used by callee */
911 struct list_head list;
915 qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo)
917 qlt_port_logo_t *tmp;
920 mutex_lock(&vha->vha_tgt.tgt_mutex);
922 list_for_each_entry(tmp, &vha->logo_list, list) {
923 if (tmp->id.b24 == logo->id.b24) {
924 tmp->cmd_count += logo->cmd_count;
925 mutex_unlock(&vha->vha_tgt.tgt_mutex);
930 list_add_tail(&logo->list, &vha->logo_list);
932 mutex_unlock(&vha->vha_tgt.tgt_mutex);
934 res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id);
936 mutex_lock(&vha->vha_tgt.tgt_mutex);
937 list_del(&logo->list);
938 mutex_unlock(&vha->vha_tgt.tgt_mutex);
940 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098,
941 "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n",
942 logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa,
943 logo->cmd_count, res);
946 void qlt_free_session_done(struct work_struct *work)
948 struct fc_port *sess = container_of(work, struct fc_port,
950 struct qla_tgt *tgt = sess->tgt;
951 struct scsi_qla_host *vha = sess->vha;
952 struct qla_hw_data *ha = vha->hw;
954 bool logout_started = false;
955 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
956 struct qlt_plogi_ack_t *own =
957 sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
959 ql_dbg(ql_dbg_disc, vha, 0xf084,
960 "%s: se_sess %p / sess %p from port %8phC loop_id %#04x"
961 " s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n",
962 __func__, sess->se_sess, sess, sess->port_name, sess->loop_id,
963 sess->d_id.b.domain, sess->d_id.b.area, sess->d_id.b.al_pa,
964 sess->logout_on_delete, sess->keep_nport_handle,
965 sess->send_els_logo);
967 if (!IS_SW_RESV_ADDR(sess->d_id)) {
968 qla2x00_mark_device_lost(vha, sess, 0);
970 if (sess->send_els_logo) {
971 qlt_port_logo_t logo;
973 logo.id = sess->d_id;
976 qlt_send_first_logo(vha, &logo);
977 sess->send_els_logo = 0;
980 if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) {
984 (own->iocb.u.isp24.status_subcode == ELS_PLOGI)) {
985 rc = qla2x00_post_async_logout_work(vha, sess,
987 if (rc != QLA_SUCCESS)
988 ql_log(ql_log_warn, vha, 0xf085,
989 "Schedule logo failed sess %p rc %d\n",
992 logout_started = true;
993 } else if (own && (own->iocb.u.isp24.status_subcode ==
994 ELS_PRLI) && ha->flags.rida_fmt2) {
995 rc = qla2x00_post_async_prlo_work(vha, sess,
997 if (rc != QLA_SUCCESS)
998 ql_log(ql_log_warn, vha, 0xf085,
999 "Schedule PRLO failed sess %p rc %d\n",
1002 logout_started = true;
1004 } /* if sess->logout_on_delete */
1006 if (sess->nvme_flag & NVME_FLAG_REGISTERED &&
1007 !(sess->nvme_flag & NVME_FLAG_DELETING)) {
1008 sess->nvme_flag |= NVME_FLAG_DELETING;
1009 qla_nvme_unregister_remote_port(sess);
1014 * Release the target session for FC Nexus from fabric module code.
1016 if (sess->se_sess != NULL)
1017 ha->tgt.tgt_ops->free_session(sess);
1019 if (logout_started) {
1020 bool traced = false;
1023 while (!READ_ONCE(sess->logout_completed)) {
1025 ql_dbg(ql_dbg_disc, vha, 0xf086,
1026 "%s: waiting for sess %p logout\n",
1033 * Driver timeout is set to 22 Sec, update count value to loop
1034 * long enough for log-out to complete before advancing. Otherwise,
1035 * straddling logout can interfere with re-login attempt.
1041 ql_dbg(ql_dbg_disc, vha, 0xf087,
1042 "%s: sess %p logout completed\n", __func__, sess);
1045 if (sess->logo_ack_needed) {
1046 sess->logo_ack_needed = 0;
1047 qla24xx_async_notify_ack(vha, sess,
1048 (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO);
1051 spin_lock_irqsave(&vha->work_lock, flags);
1052 sess->flags &= ~FCF_ASYNC_SENT;
1053 spin_unlock_irqrestore(&vha->work_lock, flags);
1055 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1056 if (sess->se_sess) {
1057 sess->se_sess = NULL;
1058 if (tgt && !IS_SW_RESV_ADDR(sess->d_id))
1062 qla2x00_set_fcport_disc_state(sess, DSC_DELETED);
1063 sess->fw_login_state = DSC_LS_PORT_UNAVAIL;
1064 sess->deleted = QLA_SESS_DELETED;
1066 if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) {
1067 vha->fcport_count--;
1068 sess->login_succ = 0;
1071 qla2x00_clear_loop_id(sess);
1073 if (sess->conflict) {
1074 sess->conflict->login_pause = 0;
1075 sess->conflict = NULL;
1076 if (!test_bit(UNLOADING, &vha->dpc_flags))
1077 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1081 struct qlt_plogi_ack_t *con =
1082 sess->plogi_link[QLT_PLOGI_LINK_CONFLICT];
1083 struct imm_ntfy_from_isp *iocb;
1085 own = sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
1089 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099,
1090 "se_sess %p / sess %p port %8phC is gone,"
1091 " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n",
1092 sess->se_sess, sess, sess->port_name,
1093 own ? "releasing own PLOGI" : "no own PLOGI pending",
1094 own ? own->ref_count : -1,
1095 iocb->u.isp24.port_name, con->ref_count);
1096 qlt_plogi_ack_unref(vha, con);
1097 sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL;
1099 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a,
1100 "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n",
1101 sess->se_sess, sess, sess->port_name,
1102 own ? "releasing own PLOGI" :
1103 "no own PLOGI pending",
1104 own ? own->ref_count : -1);
1108 sess->fw_login_state = DSC_LS_PLOGI_PEND;
1109 qlt_plogi_ack_unref(vha, own);
1110 sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL;
1114 sess->explicit_logout = 0;
1115 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1116 sess->free_pending = 0;
1118 qla2x00_dfs_remove_rport(vha, sess);
1120 ql_dbg(ql_dbg_disc, vha, 0xf001,
1121 "Unregistration of sess %p %8phC finished fcp_cnt %d\n",
1122 sess, sess->port_name, vha->fcport_count);
1124 if (tgt && (tgt->sess_count == 0))
1125 wake_up_all(&tgt->waitQ);
1127 if (!test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags) &&
1128 !(vha->vp_idx && test_bit(VPORT_DELETE, &vha->dpc_flags)) &&
1129 (!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) {
1130 switch (vha->host->active_mode) {
1131 case MODE_INITIATOR:
1133 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1134 qla2xxx_wake_dpc(vha);
1143 if (vha->fcport_count == 0)
1144 wake_up_all(&vha->fcport_waitQ);
1147 /* ha->tgt.sess_lock supposed to be held on entry */
1148 void qlt_unreg_sess(struct fc_port *sess)
1150 struct scsi_qla_host *vha = sess->vha;
1151 unsigned long flags;
1153 ql_dbg(ql_dbg_disc, sess->vha, 0x210a,
1154 "%s sess %p for deletion %8phC\n",
1155 __func__, sess, sess->port_name);
1157 spin_lock_irqsave(&sess->vha->work_lock, flags);
1158 if (sess->free_pending) {
1159 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1162 sess->free_pending = 1;
1164 * Use FCF_ASYNC_SENT flag to block other cmds used in sess
1165 * management from being sent.
1167 sess->flags |= FCF_ASYNC_SENT;
1168 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1171 vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess);
1173 sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
1174 qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND);
1175 sess->last_rscn_gen = sess->rscn_gen;
1176 sess->last_login_gen = sess->login_gen;
1178 queue_work(sess->vha->hw->wq, &sess->free_work);
1180 EXPORT_SYMBOL(qlt_unreg_sess);
1182 static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd)
1184 struct qla_hw_data *ha = vha->hw;
1185 struct fc_port *sess = NULL;
1188 struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb;
1189 unsigned long flags;
1191 loop_id = le16_to_cpu(n->u.isp24.nport_handle);
1192 if (loop_id == 0xFFFF) {
1194 atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count);
1195 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1196 qlt_clear_tgt_db(vha->vha_tgt.qla_tgt);
1197 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1199 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1200 sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
1201 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1204 ql_dbg(ql_dbg_tgt, vha, 0xe000,
1205 "Using sess for qla_tgt_reset: %p\n", sess);
1211 ql_dbg(ql_dbg_tgt, vha, 0xe047,
1212 "scsi(%ld): resetting (session %p from port %8phC mcmd %x, "
1213 "loop_id %d)\n", vha->host_no, sess, sess->port_name,
1216 return qlt_issue_task_mgmt(sess, 0, mcmd, iocb, QLA24XX_MGMT_SEND_NACK);
1219 static void qla24xx_chk_fcp_state(struct fc_port *sess)
1221 if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) {
1222 sess->logout_on_delete = 0;
1223 sess->logo_ack_needed = 0;
1224 sess->fw_login_state = DSC_LS_PORT_UNAVAIL;
1228 void qlt_schedule_sess_for_deletion(struct fc_port *sess)
1230 struct qla_tgt *tgt = sess->tgt;
1231 unsigned long flags;
1234 switch (sess->disc_state) {
1235 case DSC_DELETE_PEND:
1238 if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] &&
1239 !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) {
1240 if (tgt && tgt->tgt_stop && tgt->sess_count == 0)
1241 wake_up_all(&tgt->waitQ);
1243 if (sess->vha->fcport_count == 0)
1244 wake_up_all(&sess->vha->fcport_waitQ);
1248 case DSC_UPD_FCPORT:
1250 * This port is not done reporting to upper layer.
1253 sess->next_disc_state = DSC_DELETE_PEND;
1254 sec = jiffies_to_msecs(jiffies -
1255 sess->jiffies_at_registration)/1000;
1256 if (sess->sec_since_registration < sec && sec && !(sec % 5)) {
1257 sess->sec_since_registration = sec;
1258 ql_dbg(ql_dbg_disc, sess->vha, 0xffff,
1259 "%s %8phC : Slow Rport registration(%d Sec)\n",
1260 __func__, sess->port_name, sec);
1267 spin_lock_irqsave(&sess->vha->work_lock, flags);
1268 if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) {
1269 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1272 sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
1273 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1275 sess->prli_pend_timer = 0;
1276 qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND);
1278 qla24xx_chk_fcp_state(sess);
1280 ql_dbg(ql_log_warn, sess->vha, 0xe001,
1281 "Scheduling sess %p for deletion %8phC\n",
1282 sess, sess->port_name);
1284 WARN_ON(!queue_work(sess->vha->hw->wq, &sess->del_work));
1287 static void qlt_clear_tgt_db(struct qla_tgt *tgt)
1289 struct fc_port *sess;
1290 scsi_qla_host_t *vha = tgt->vha;
1292 list_for_each_entry(sess, &vha->vp_fcports, list) {
1294 qlt_schedule_sess_for_deletion(sess);
1297 /* At this point tgt could be already dead */
1300 static int qla24xx_get_loop_id(struct scsi_qla_host *vha, be_id_t s_id,
1303 struct qla_hw_data *ha = vha->hw;
1304 dma_addr_t gid_list_dma;
1305 struct gid_list_info *gid_list, *gid;
1309 gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
1310 &gid_list_dma, GFP_KERNEL);
1312 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044,
1313 "qla_target(%d): DMA Alloc failed of %u\n",
1314 vha->vp_idx, qla2x00_gid_list_size(ha));
1318 /* Get list of logged in devices */
1319 rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries);
1320 if (rc != QLA_SUCCESS) {
1321 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045,
1322 "qla_target(%d): get_id_list() failed: %x\n",
1325 goto out_free_id_list;
1330 for (i = 0; i < entries; i++) {
1331 if (gid->al_pa == s_id.al_pa &&
1332 gid->area == s_id.area &&
1333 gid->domain == s_id.domain) {
1334 *loop_id = le16_to_cpu(gid->loop_id);
1338 gid = (void *)gid + ha->gid_list_info_size;
1342 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
1343 gid_list, gid_list_dma);
1348 * Adds an extra ref to allow to drop hw lock after adding sess to the list.
1349 * Caller must put it.
1351 static struct fc_port *qlt_create_sess(
1352 struct scsi_qla_host *vha,
1356 struct qla_hw_data *ha = vha->hw;
1357 struct fc_port *sess = fcport;
1358 unsigned long flags;
1360 if (vha->vha_tgt.qla_tgt->tgt_stop)
1363 if (fcport->se_sess) {
1364 if (!kref_get_unless_zero(&sess->sess_kref)) {
1365 ql_dbg(ql_dbg_disc, vha, 0x20f6,
1366 "%s: kref_get_unless_zero failed for %8phC\n",
1367 __func__, sess->port_name);
1372 sess->tgt = vha->vha_tgt.qla_tgt;
1373 sess->local = local;
1376 * Under normal circumstances we want to logout from firmware when
1377 * session eventually ends and release corresponding nport handle.
1378 * In the exception cases (e.g. when new PLOGI is waiting) corresponding
1379 * code will adjust these flags as necessary.
1381 sess->logout_on_delete = 1;
1382 sess->keep_nport_handle = 0;
1383 sess->logout_completed = 0;
1385 if (ha->tgt.tgt_ops->check_initiator_node_acl(vha,
1386 &fcport->port_name[0], sess) < 0) {
1387 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015,
1388 "(%d) %8phC check_initiator_node_acl failed\n",
1389 vha->vp_idx, fcport->port_name);
1392 kref_init(&fcport->sess_kref);
1394 * Take an extra reference to ->sess_kref here to handle
1395 * fc_port access across ->tgt.sess_lock reaquire.
1397 if (!kref_get_unless_zero(&sess->sess_kref)) {
1398 ql_dbg(ql_dbg_disc, vha, 0x20f7,
1399 "%s: kref_get_unless_zero failed for %8phC\n",
1400 __func__, sess->port_name);
1404 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1405 if (!IS_SW_RESV_ADDR(sess->d_id))
1406 vha->vha_tgt.qla_tgt->sess_count++;
1408 qlt_do_generation_tick(vha, &sess->generation);
1409 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1412 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006,
1413 "Adding sess %p se_sess %p to tgt %p sess_count %d\n",
1414 sess, sess->se_sess, vha->vha_tgt.qla_tgt,
1415 vha->vha_tgt.qla_tgt->sess_count);
1417 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b,
1418 "qla_target(%d): %ssession for wwn %8phC (loop_id %d, "
1419 "s_id %x:%x:%x, confirmed completion %ssupported) added\n",
1420 vha->vp_idx, local ? "local " : "", fcport->port_name,
1421 fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area,
1422 sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not ");
1428 * max_gen - specifies maximum session generation
1429 * at which this deletion requestion is still valid
1432 qlt_fc_port_deleted(struct scsi_qla_host *vha, fc_port_t *fcport, int max_gen)
1434 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1435 struct fc_port *sess = fcport;
1436 unsigned long flags;
1438 if (!vha->hw->tgt.tgt_ops)
1444 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1445 if (tgt->tgt_stop) {
1446 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1449 if (!sess->se_sess) {
1450 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1454 if (max_gen - sess->generation < 0) {
1455 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1456 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092,
1457 "Ignoring stale deletion request for se_sess %p / sess %p"
1458 " for port %8phC, req_gen %d, sess_gen %d\n",
1459 sess->se_sess, sess, sess->port_name, max_gen,
1464 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess);
1467 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1468 qlt_schedule_sess_for_deletion(sess);
1471 static inline int test_tgt_sess_count(struct qla_tgt *tgt)
1473 struct qla_hw_data *ha = tgt->ha;
1474 unsigned long flags;
1477 * We need to protect against race, when tgt is freed before or
1480 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1481 ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002,
1482 "tgt %p, sess_count=%d\n",
1483 tgt, tgt->sess_count);
1484 res = (tgt->sess_count == 0);
1485 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1490 /* Called by tcm_qla2xxx configfs code */
1491 int qlt_stop_phase1(struct qla_tgt *tgt)
1493 struct scsi_qla_host *vha = tgt->vha;
1494 struct qla_hw_data *ha = tgt->ha;
1495 unsigned long flags;
1497 mutex_lock(&ha->optrom_mutex);
1498 mutex_lock(&qla_tgt_mutex);
1500 if (tgt->tgt_stop || tgt->tgt_stopped) {
1501 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e,
1502 "Already in tgt->tgt_stop or tgt_stopped state\n");
1503 mutex_unlock(&qla_tgt_mutex);
1504 mutex_unlock(&ha->optrom_mutex);
1508 ql_dbg(ql_dbg_tgt_mgt, vha, 0xe003, "Stopping target for host %ld(%p)\n",
1511 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
1512 * Lock is needed, because we still can get an incoming packet.
1514 mutex_lock(&vha->vha_tgt.tgt_mutex);
1516 qlt_clear_tgt_db(tgt);
1517 mutex_unlock(&vha->vha_tgt.tgt_mutex);
1518 mutex_unlock(&qla_tgt_mutex);
1520 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009,
1521 "Waiting for sess works (tgt %p)", tgt);
1522 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1523 while (!list_empty(&tgt->sess_works_list)) {
1524 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1525 flush_scheduled_work();
1526 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1528 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1530 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a,
1531 "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count);
1533 wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
1536 if (!ha->flags.host_shutting_down &&
1537 (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)))
1538 qlt_disable_vha(vha);
1540 /* Wait for sessions to clear out (just in case) */
1541 wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
1542 mutex_unlock(&ha->optrom_mutex);
1546 EXPORT_SYMBOL(qlt_stop_phase1);
1548 /* Called by tcm_qla2xxx configfs code */
1549 void qlt_stop_phase2(struct qla_tgt *tgt)
1551 scsi_qla_host_t *vha = tgt->vha;
1553 if (tgt->tgt_stopped) {
1554 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f,
1555 "Already in tgt->tgt_stopped state\n");
1559 if (!tgt->tgt_stop) {
1560 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b,
1561 "%s: phase1 stop is not completed\n", __func__);
1566 mutex_lock(&tgt->ha->optrom_mutex);
1567 mutex_lock(&vha->vha_tgt.tgt_mutex);
1569 tgt->tgt_stopped = 1;
1570 mutex_unlock(&vha->vha_tgt.tgt_mutex);
1571 mutex_unlock(&tgt->ha->optrom_mutex);
1573 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00c, "Stop of tgt %p finished\n",
1576 switch (vha->qlini_mode) {
1577 case QLA2XXX_INI_MODE_EXCLUSIVE:
1578 vha->flags.online = 1;
1579 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1585 EXPORT_SYMBOL(qlt_stop_phase2);
1587 /* Called from qlt_remove_target() -> qla2x00_remove_one() */
1588 static void qlt_release(struct qla_tgt *tgt)
1590 scsi_qla_host_t *vha = tgt->vha;
1594 struct qla_qpair_hint *h;
1595 struct qla_hw_data *ha = vha->hw;
1597 if (!tgt->tgt_stop && !tgt->tgt_stopped)
1598 qlt_stop_phase1(tgt);
1600 if (!tgt->tgt_stopped)
1601 qlt_stop_phase2(tgt);
1603 for (i = 0; i < vha->hw->max_qpairs + 1; i++) {
1604 unsigned long flags;
1606 h = &tgt->qphints[i];
1608 spin_lock_irqsave(h->qpair->qp_lock_ptr, flags);
1609 list_del(&h->hint_elem);
1610 spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags);
1614 kfree(tgt->qphints);
1615 mutex_lock(&qla_tgt_mutex);
1616 list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry);
1617 mutex_unlock(&qla_tgt_mutex);
1619 btree_for_each_safe64(&tgt->lun_qpair_map, key, node)
1620 btree_remove64(&tgt->lun_qpair_map, key);
1622 btree_destroy64(&tgt->lun_qpair_map);
1625 if (ha->tgt.tgt_ops &&
1626 ha->tgt.tgt_ops->remove_target &&
1627 vha->vha_tgt.target_lport_ptr)
1628 ha->tgt.tgt_ops->remove_target(vha);
1630 vha->vha_tgt.qla_tgt = NULL;
1632 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d,
1633 "Release of tgt %p finished\n", tgt);
1638 /* ha->hardware_lock supposed to be held on entry */
1639 static int qlt_sched_sess_work(struct qla_tgt *tgt, int type,
1640 const void *param, unsigned int param_size)
1642 struct qla_tgt_sess_work_param *prm;
1643 unsigned long flags;
1645 prm = kzalloc(sizeof(*prm), GFP_ATOMIC);
1647 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050,
1648 "qla_target(%d): Unable to create session "
1649 "work, command will be refused", 0);
1653 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e,
1654 "Scheduling work (type %d, prm %p)"
1655 " to find session for param %p (size %d, tgt %p)\n",
1656 type, prm, param, param_size, tgt);
1659 memcpy(&prm->tm_iocb, param, param_size);
1661 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1662 list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list);
1663 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1665 schedule_work(&tgt->sess_work);
1671 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1673 static void qlt_send_notify_ack(struct qla_qpair *qpair,
1674 struct imm_ntfy_from_isp *ntfy,
1675 uint32_t add_flags, uint16_t resp_code, int resp_code_valid,
1676 uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan)
1678 struct scsi_qla_host *vha = qpair->vha;
1679 struct qla_hw_data *ha = vha->hw;
1681 struct nack_to_isp *nack;
1683 if (!ha->flags.fw_started)
1686 ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha);
1688 pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL);
1690 ql_dbg(ql_dbg_tgt, vha, 0xe049,
1691 "qla_target(%d): %s failed: unable to allocate "
1692 "request packet\n", vha->vp_idx, __func__);
1696 if (vha->vha_tgt.qla_tgt != NULL)
1697 vha->vha_tgt.qla_tgt->notify_ack_expected++;
1699 pkt->entry_type = NOTIFY_ACK_TYPE;
1700 pkt->entry_count = 1;
1702 nack = (struct nack_to_isp *)pkt;
1703 nack->ox_id = ntfy->ox_id;
1705 nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE;
1706 nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
1707 if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
1708 nack->u.isp24.flags = ntfy->u.isp24.flags &
1709 cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB);
1711 nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
1712 nack->u.isp24.status = ntfy->u.isp24.status;
1713 nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode;
1714 nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle;
1715 nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address;
1716 nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs;
1717 nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui;
1718 nack->u.isp24.srr_flags = cpu_to_le16(srr_flags);
1719 nack->u.isp24.srr_reject_code = srr_reject_code;
1720 nack->u.isp24.srr_reject_code_expl = srr_explan;
1721 nack->u.isp24.vp_index = ntfy->u.isp24.vp_index;
1723 ql_dbg(ql_dbg_tgt, vha, 0xe005,
1724 "qla_target(%d): Sending 24xx Notify Ack %d\n",
1725 vha->vp_idx, nack->u.isp24.status);
1727 /* Memory Barrier */
1729 qla2x00_start_iocbs(vha, qpair->req);
1732 static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd)
1734 struct scsi_qla_host *vha = mcmd->vha;
1735 struct qla_hw_data *ha = vha->hw;
1736 struct abts_resp_to_24xx *resp;
1741 struct abts_recv_from_24xx *abts = &mcmd->orig_iocb.abts;
1742 struct qla_qpair *qpair = mcmd->qpair;
1744 ql_dbg(ql_dbg_tgt, vha, 0xe006,
1745 "Sending task mgmt ABTS response (ha=%p, status=%x)\n",
1746 ha, mcmd->fc_tm_rsp);
1748 rc = qlt_check_reserve_free_req(qpair, 1);
1750 ql_dbg(ql_dbg_tgt, vha, 0xe04a,
1751 "qla_target(%d): %s failed: unable to allocate request packet\n",
1752 vha->vp_idx, __func__);
1756 resp = (struct abts_resp_to_24xx *)qpair->req->ring_ptr;
1757 memset(resp, 0, sizeof(*resp));
1759 h = qlt_make_handle(qpair);
1760 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
1762 * CTIO type 7 from the firmware doesn't provide a way to
1763 * know the initiator's LOOP ID, hence we can't find
1764 * the session and, so, the command.
1768 qpair->req->outstanding_cmds[h] = (srb_t *)mcmd;
1771 resp->handle = make_handle(qpair->req->id, h);
1772 resp->entry_type = ABTS_RESP_24XX;
1773 resp->entry_count = 1;
1774 resp->nport_handle = abts->nport_handle;
1775 resp->vp_index = vha->vp_idx;
1776 resp->sof_type = abts->sof_type;
1777 resp->exchange_address = abts->exchange_address;
1778 resp->fcp_hdr_le = abts->fcp_hdr_le;
1779 f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
1780 F_CTL_LAST_SEQ | F_CTL_END_SEQ |
1781 F_CTL_SEQ_INITIATIVE);
1782 p = (uint8_t *)&f_ctl;
1783 resp->fcp_hdr_le.f_ctl[0] = *p++;
1784 resp->fcp_hdr_le.f_ctl[1] = *p++;
1785 resp->fcp_hdr_le.f_ctl[2] = *p;
1787 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
1788 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
1790 resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
1791 if (mcmd->fc_tm_rsp == FCP_TMF_CMPL) {
1792 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
1793 resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
1794 resp->payload.ba_acct.low_seq_cnt = 0x0000;
1795 resp->payload.ba_acct.high_seq_cnt = cpu_to_le16(0xFFFF);
1796 resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
1797 resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
1799 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT;
1800 resp->payload.ba_rjt.reason_code =
1801 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM;
1802 /* Other bytes are zero */
1805 vha->vha_tgt.qla_tgt->abts_resp_expected++;
1807 /* Memory Barrier */
1809 if (qpair->reqq_start_iocbs)
1810 qpair->reqq_start_iocbs(qpair);
1812 qla2x00_start_iocbs(vha, qpair->req);
1818 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1820 static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair,
1821 struct abts_recv_from_24xx *abts, uint32_t status,
1824 struct scsi_qla_host *vha = qpair->vha;
1825 struct qla_hw_data *ha = vha->hw;
1826 struct abts_resp_to_24xx *resp;
1830 ql_dbg(ql_dbg_tgt, vha, 0xe006,
1831 "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
1834 resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair,
1837 ql_dbg(ql_dbg_tgt, vha, 0xe04a,
1838 "qla_target(%d): %s failed: unable to allocate "
1839 "request packet", vha->vp_idx, __func__);
1843 resp->entry_type = ABTS_RESP_24XX;
1844 resp->handle = QLA_TGT_SKIP_HANDLE;
1845 resp->entry_count = 1;
1846 resp->nport_handle = abts->nport_handle;
1847 resp->vp_index = vha->vp_idx;
1848 resp->sof_type = abts->sof_type;
1849 resp->exchange_address = abts->exchange_address;
1850 resp->fcp_hdr_le = abts->fcp_hdr_le;
1851 f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
1852 F_CTL_LAST_SEQ | F_CTL_END_SEQ |
1853 F_CTL_SEQ_INITIATIVE);
1854 p = (uint8_t *)&f_ctl;
1855 resp->fcp_hdr_le.f_ctl[0] = *p++;
1856 resp->fcp_hdr_le.f_ctl[1] = *p++;
1857 resp->fcp_hdr_le.f_ctl[2] = *p;
1859 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.d_id;
1860 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.s_id;
1862 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
1863 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
1865 resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
1866 if (status == FCP_TMF_CMPL) {
1867 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
1868 resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
1869 resp->payload.ba_acct.low_seq_cnt = 0x0000;
1870 resp->payload.ba_acct.high_seq_cnt = cpu_to_le16(0xFFFF);
1871 resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
1872 resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
1874 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT;
1875 resp->payload.ba_rjt.reason_code =
1876 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM;
1877 /* Other bytes are zero */
1880 vha->vha_tgt.qla_tgt->abts_resp_expected++;
1882 /* Memory Barrier */
1884 if (qpair->reqq_start_iocbs)
1885 qpair->reqq_start_iocbs(qpair);
1887 qla2x00_start_iocbs(vha, qpair->req);
1891 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1893 static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha,
1894 struct qla_qpair *qpair, response_t *pkt, struct qla_tgt_mgmt_cmd *mcmd)
1896 struct ctio7_to_24xx *ctio;
1898 struct abts_recv_from_24xx *entry;
1900 ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, NULL);
1902 ql_dbg(ql_dbg_tgt, vha, 0xe04b,
1903 "qla_target(%d): %s failed: unable to allocate "
1904 "request packet\n", vha->vp_idx, __func__);
1909 /* abts from remote port */
1910 entry = &mcmd->orig_iocb.abts;
1912 /* abts from this driver. */
1913 entry = (struct abts_recv_from_24xx *)pkt;
1916 * We've got on entrance firmware's response on by us generated
1917 * ABTS response. So, in it ID fields are reversed.
1920 ctio->entry_type = CTIO_TYPE7;
1921 ctio->entry_count = 1;
1922 ctio->nport_handle = entry->nport_handle;
1923 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
1924 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
1925 ctio->vp_index = vha->vp_idx;
1926 ctio->exchange_addr = entry->exchange_addr_to_abort;
1927 tmp = (CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_TERMINATE);
1930 ctio->initiator_id = entry->fcp_hdr_le.s_id;
1932 if (mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID)
1933 tmp |= (mcmd->abort_io_attr << 9);
1934 else if (qpair->retry_term_cnt & 1)
1937 ctio->initiator_id = entry->fcp_hdr_le.d_id;
1939 if (qpair->retry_term_cnt & 1)
1942 ctio->u.status1.flags = cpu_to_le16(tmp);
1943 ctio->u.status1.ox_id = entry->fcp_hdr_le.ox_id;
1945 ql_dbg(ql_dbg_tgt, vha, 0xe007,
1946 "Sending retry TERM EXCH CTIO7 flags %04xh oxid %04xh attr valid %x\n",
1947 le16_to_cpu(ctio->u.status1.flags),
1948 le16_to_cpu(ctio->u.status1.ox_id),
1949 (mcmd && mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) ? 1 : 0);
1951 /* Memory Barrier */
1953 if (qpair->reqq_start_iocbs)
1954 qpair->reqq_start_iocbs(qpair);
1956 qla2x00_start_iocbs(vha, qpair->req);
1959 qlt_build_abts_resp_iocb(mcmd);
1961 qlt_24xx_send_abts_resp(qpair,
1962 (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true);
1966 /* drop cmds for the given lun
1967 * XXX only looks for cmds on the port through which lun reset was recieved
1968 * XXX does not go through the list of other port (which may have cmds
1971 static void abort_cmds_for_lun(struct scsi_qla_host *vha, u64 lun, be_id_t s_id)
1973 struct qla_tgt_sess_op *op;
1974 struct qla_tgt_cmd *cmd;
1976 unsigned long flags;
1978 key = sid_to_key(s_id);
1979 spin_lock_irqsave(&vha->cmd_list_lock, flags);
1980 list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) {
1984 op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
1985 op_lun = scsilun_to_int(
1986 (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun);
1987 if (op_key == key && op_lun == lun)
1991 list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
1995 op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
1996 op_lun = scsilun_to_int(
1997 (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun);
1998 if (op_key == key && op_lun == lun)
2002 list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
2006 cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id);
2007 cmd_lun = scsilun_to_int(
2008 (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun);
2009 if (cmd_key == key && cmd_lun == lun)
2012 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
2015 static struct qla_qpair_hint *qlt_find_qphint(struct scsi_qla_host *vha,
2016 uint64_t unpacked_lun)
2018 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
2019 struct qla_qpair_hint *h = NULL;
2021 if (vha->flags.qpairs_available) {
2022 h = btree_lookup64(&tgt->lun_qpair_map, unpacked_lun);
2024 h = &tgt->qphints[0];
2026 h = &tgt->qphints[0];
2032 static void qlt_do_tmr_work(struct work_struct *work)
2034 struct qla_tgt_mgmt_cmd *mcmd =
2035 container_of(work, struct qla_tgt_mgmt_cmd, work);
2036 struct qla_hw_data *ha = mcmd->vha->hw;
2039 unsigned long flags;
2041 switch (mcmd->tmr_func) {
2043 tag = le32_to_cpu(mcmd->orig_iocb.abts.exchange_addr_to_abort);
2050 rc = ha->tgt.tgt_ops->handle_tmr(mcmd, mcmd->unpacked_lun,
2051 mcmd->tmr_func, tag);
2054 spin_lock_irqsave(mcmd->qpair->qp_lock_ptr, flags);
2055 switch (mcmd->tmr_func) {
2057 mcmd->fc_tm_rsp = FCP_TMF_REJECTED;
2058 qlt_build_abts_resp_iocb(mcmd);
2060 case QLA_TGT_LUN_RESET:
2061 case QLA_TGT_CLEAR_TS:
2062 case QLA_TGT_ABORT_TS:
2063 case QLA_TGT_CLEAR_ACA:
2064 case QLA_TGT_TARGET_RESET:
2065 qlt_send_busy(mcmd->qpair, &mcmd->orig_iocb.atio,
2069 case QLA_TGT_ABORT_ALL:
2070 case QLA_TGT_NEXUS_LOSS_SESS:
2071 case QLA_TGT_NEXUS_LOSS:
2072 qlt_send_notify_ack(mcmd->qpair,
2073 &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0);
2076 spin_unlock_irqrestore(mcmd->qpair->qp_lock_ptr, flags);
2078 ql_dbg(ql_dbg_tgt_mgt, mcmd->vha, 0xf052,
2079 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
2080 mcmd->vha->vp_idx, rc);
2081 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
2085 /* ha->hardware_lock supposed to be held on entry */
2086 static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha,
2087 struct abts_recv_from_24xx *abts, struct fc_port *sess)
2089 struct qla_hw_data *ha = vha->hw;
2090 struct qla_tgt_mgmt_cmd *mcmd;
2091 struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0];
2092 struct qla_tgt_cmd *abort_cmd;
2094 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f,
2095 "qla_target(%d): task abort (tag=%d)\n",
2096 vha->vp_idx, abts->exchange_addr_to_abort);
2098 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
2100 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051,
2101 "qla_target(%d): %s: Allocation of ABORT cmd failed",
2102 vha->vp_idx, __func__);
2105 memset(mcmd, 0, sizeof(*mcmd));
2106 mcmd->cmd_type = TYPE_TGT_TMCMD;
2108 memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts));
2109 mcmd->reset_count = ha->base_qpair->chip_reset;
2110 mcmd->tmr_func = QLA_TGT_ABTS;
2111 mcmd->qpair = h->qpair;
2115 * LUN is looked up by target-core internally based on the passed
2116 * abts->exchange_addr_to_abort tag.
2118 mcmd->se_cmd.cpuid = h->cpuid;
2120 abort_cmd = ha->tgt.tgt_ops->find_cmd_by_tag(sess,
2121 le32_to_cpu(abts->exchange_addr_to_abort));
2124 mcmd->unpacked_lun = abort_cmd->se_cmd.orig_fe_lun;
2126 if (abort_cmd->qpair) {
2127 mcmd->qpair = abort_cmd->qpair;
2128 mcmd->se_cmd.cpuid = abort_cmd->se_cmd.cpuid;
2129 mcmd->abort_io_attr = abort_cmd->atio.u.isp24.attr;
2130 mcmd->flags = QLA24XX_MGMT_ABORT_IO_ATTR_VALID;
2133 INIT_WORK(&mcmd->work, qlt_do_tmr_work);
2134 queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, &mcmd->work);
2140 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2142 static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
2143 struct abts_recv_from_24xx *abts)
2145 struct qla_hw_data *ha = vha->hw;
2146 struct fc_port *sess;
2147 uint32_t tag = le32_to_cpu(abts->exchange_addr_to_abort);
2150 unsigned long flags;
2152 if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) {
2153 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053,
2154 "qla_target(%d): ABTS: Abort Sequence not "
2155 "supported\n", vha->vp_idx);
2156 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2161 if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) {
2162 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010,
2163 "qla_target(%d): ABTS: Unknown Exchange "
2164 "Address received\n", vha->vp_idx);
2165 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2170 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011,
2171 "qla_target(%d): task abort (s_id=%x:%x:%x, "
2172 "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id.domain,
2173 abts->fcp_hdr_le.s_id.area, abts->fcp_hdr_le.s_id.al_pa, tag,
2174 le32_to_cpu(abts->fcp_hdr_le.parameter));
2176 s_id = le_id_to_be(abts->fcp_hdr_le.s_id);
2178 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2179 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
2181 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012,
2182 "qla_target(%d): task abort for non-existent session\n",
2184 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2186 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2190 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2193 if (sess->deleted) {
2194 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2199 rc = __qlt_24xx_handle_abts(vha, abts, sess);
2201 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054,
2202 "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
2204 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2211 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2213 static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair,
2214 struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code)
2216 struct scsi_qla_host *ha = mcmd->vha;
2217 struct atio_from_isp *atio = &mcmd->orig_iocb.atio;
2218 struct ctio7_to_24xx *ctio;
2221 ql_dbg(ql_dbg_tgt, ha, 0xe008,
2222 "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
2223 ha, atio, resp_code);
2226 ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL);
2228 ql_dbg(ql_dbg_tgt, ha, 0xe04c,
2229 "qla_target(%d): %s failed: unable to allocate "
2230 "request packet\n", ha->vp_idx, __func__);
2234 ctio->entry_type = CTIO_TYPE7;
2235 ctio->entry_count = 1;
2236 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
2237 ctio->nport_handle = cpu_to_le16(mcmd->sess->loop_id);
2238 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2239 ctio->vp_index = ha->vp_idx;
2240 ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2241 ctio->exchange_addr = atio->u.isp24.exchange_addr;
2242 temp = (atio->u.isp24.attr << 9)|
2243 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
2244 ctio->u.status1.flags = cpu_to_le16(temp);
2245 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2246 ctio->u.status1.ox_id = cpu_to_le16(temp);
2247 ctio->u.status1.scsi_status =
2248 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID);
2249 ctio->u.status1.response_len = cpu_to_le16(8);
2250 ctio->u.status1.sense_data[0] = resp_code;
2252 /* Memory Barrier */
2254 if (qpair->reqq_start_iocbs)
2255 qpair->reqq_start_iocbs(qpair);
2257 qla2x00_start_iocbs(ha, qpair->req);
2260 void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd)
2262 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
2264 EXPORT_SYMBOL(qlt_free_mcmd);
2267 * ha->hardware_lock supposed to be held on entry. Might drop it, then
2270 void qlt_send_resp_ctio(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd,
2271 uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq)
2273 struct atio_from_isp *atio = &cmd->atio;
2274 struct ctio7_to_24xx *ctio;
2276 struct scsi_qla_host *vha = cmd->vha;
2278 ql_dbg(ql_dbg_tgt_dif, vha, 0x3066,
2279 "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, "
2280 "sense_key=%02x, asc=%02x, ascq=%02x",
2281 vha, atio, scsi_status, sense_key, asc, ascq);
2283 ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL);
2285 ql_dbg(ql_dbg_async, vha, 0x3067,
2286 "qla2x00t(%ld): %s failed: unable to allocate request packet",
2287 vha->host_no, __func__);
2291 ctio->entry_type = CTIO_TYPE7;
2292 ctio->entry_count = 1;
2293 ctio->handle = QLA_TGT_SKIP_HANDLE;
2294 ctio->nport_handle = cpu_to_le16(cmd->sess->loop_id);
2295 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2296 ctio->vp_index = vha->vp_idx;
2297 ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2298 ctio->exchange_addr = atio->u.isp24.exchange_addr;
2299 temp = (atio->u.isp24.attr << 9) |
2300 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
2301 ctio->u.status1.flags = cpu_to_le16(temp);
2302 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2303 ctio->u.status1.ox_id = cpu_to_le16(temp);
2304 ctio->u.status1.scsi_status =
2305 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status);
2306 ctio->u.status1.response_len = cpu_to_le16(18);
2307 ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio));
2309 if (ctio->u.status1.residual != 0)
2310 ctio->u.status1.scsi_status |=
2311 cpu_to_le16(SS_RESIDUAL_UNDER);
2313 /* Fixed format sense data. */
2314 ctio->u.status1.sense_data[0] = 0x70;
2315 ctio->u.status1.sense_data[2] = sense_key;
2316 /* Additional sense length */
2317 ctio->u.status1.sense_data[7] = 0xa;
2319 ctio->u.status1.sense_data[12] = asc;
2320 ctio->u.status1.sense_data[13] = ascq;
2322 /* Memory Barrier */
2325 if (qpair->reqq_start_iocbs)
2326 qpair->reqq_start_iocbs(qpair);
2328 qla2x00_start_iocbs(vha, qpair->req);
2334 /* callback from target fabric module code */
2335 void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd)
2337 struct scsi_qla_host *vha = mcmd->sess->vha;
2338 struct qla_hw_data *ha = vha->hw;
2339 unsigned long flags;
2340 struct qla_qpair *qpair = mcmd->qpair;
2341 bool free_mcmd = true;
2343 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013,
2344 "TM response mcmd (%p) status %#x state %#x",
2345 mcmd, mcmd->fc_tm_rsp, mcmd->flags);
2347 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
2349 if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) {
2351 * Either the port is not online or this request was from
2352 * previous life, just abort the processing.
2354 ql_dbg(ql_dbg_async, vha, 0xe100,
2355 "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n",
2356 vha->flags.online, qla2x00_reset_active(vha),
2357 mcmd->reset_count, qpair->chip_reset);
2358 ha->tgt.tgt_ops->free_mcmd(mcmd);
2359 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2363 if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) {
2364 switch (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode) {
2368 ql_dbg(ql_dbg_disc, vha, 0x2106,
2369 "TM response logo %8phC status %#x state %#x",
2370 mcmd->sess->port_name, mcmd->fc_tm_rsp,
2372 qlt_schedule_sess_for_deletion(mcmd->sess);
2375 qlt_send_notify_ack(vha->hw->base_qpair,
2376 &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0);
2380 if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) {
2381 qlt_build_abts_resp_iocb(mcmd);
2384 qlt_24xx_send_task_mgmt_ctio(qpair, mcmd,
2388 * Make the callback for ->free_mcmd() to queue_work() and invoke
2389 * target_put_sess_cmd() to drop cmd_kref to 1. The final
2390 * target_put_sess_cmd() call will be made from TFO->check_stop_free()
2391 * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd
2392 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
2393 * qlt_xmit_tm_rsp() returns here..
2396 ha->tgt.tgt_ops->free_mcmd(mcmd);
2398 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2400 EXPORT_SYMBOL(qlt_xmit_tm_rsp);
2403 static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm)
2405 struct qla_tgt_cmd *cmd = prm->cmd;
2407 BUG_ON(cmd->sg_cnt == 0);
2409 prm->sg = (struct scatterlist *)cmd->sg;
2410 prm->seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, cmd->sg,
2411 cmd->sg_cnt, cmd->dma_data_direction);
2412 if (unlikely(prm->seg_cnt == 0))
2415 prm->cmd->sg_mapped = 1;
2417 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) {
2419 * If greater than four sg entries then we need to allocate
2420 * the continuation entries
2422 if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX)
2423 prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt -
2424 QLA_TGT_DATASEGS_PER_CMD_24XX,
2425 QLA_TGT_DATASEGS_PER_CONT_24XX);
2428 if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) ||
2429 (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) {
2430 prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz);
2431 prm->tot_dsds = prm->seg_cnt;
2433 prm->tot_dsds = prm->seg_cnt;
2435 if (cmd->prot_sg_cnt) {
2436 prm->prot_sg = cmd->prot_sg;
2437 prm->prot_seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev,
2438 cmd->prot_sg, cmd->prot_sg_cnt,
2439 cmd->dma_data_direction);
2440 if (unlikely(prm->prot_seg_cnt == 0))
2443 if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) ||
2444 (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) {
2445 /* Dif Bundling not support here */
2446 prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen,
2448 prm->tot_dsds += prm->prot_seg_cnt;
2450 prm->tot_dsds += prm->prot_seg_cnt;
2457 ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d,
2458 "qla_target(%d): PCI mapping failed: sg_cnt=%d",
2459 0, prm->cmd->sg_cnt);
2463 static void qlt_unmap_sg(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd)
2465 struct qla_hw_data *ha;
2466 struct qla_qpair *qpair;
2468 if (!cmd->sg_mapped)
2473 dma_unmap_sg(&qpair->pdev->dev, cmd->sg, cmd->sg_cnt,
2474 cmd->dma_data_direction);
2477 if (cmd->prot_sg_cnt)
2478 dma_unmap_sg(&qpair->pdev->dev, cmd->prot_sg, cmd->prot_sg_cnt,
2479 cmd->dma_data_direction);
2484 if (cmd->ctx_dsd_alloced)
2485 qla2x00_clean_dsd_pool(ha, cmd->ctx);
2487 dma_pool_free(ha->dl_dma_pool, cmd->ctx, cmd->ctx->crc_ctx_dma);
2490 static int qlt_check_reserve_free_req(struct qla_qpair *qpair,
2494 struct req_que *req = qpair->req;
2496 if (req->cnt < (req_cnt + 2)) {
2497 cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr :
2498 rd_reg_dword_relaxed(req->req_q_out));
2500 if (req->ring_index < cnt)
2501 req->cnt = cnt - req->ring_index;
2503 req->cnt = req->length - (req->ring_index - cnt);
2505 if (unlikely(req->cnt < (req_cnt + 2)))
2509 req->cnt -= req_cnt;
2515 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2517 static inline void *qlt_get_req_pkt(struct req_que *req)
2519 /* Adjust ring index. */
2521 if (req->ring_index == req->length) {
2522 req->ring_index = 0;
2523 req->ring_ptr = req->ring;
2527 return (cont_entry_t *)req->ring_ptr;
2530 /* ha->hardware_lock supposed to be held on entry */
2531 static inline uint32_t qlt_make_handle(struct qla_qpair *qpair)
2536 struct req_que *req = qpair->req;
2538 h = req->current_outstanding_cmd;
2540 for (index = 1; index < req->num_outstanding_cmds; index++) {
2542 if (h == req->num_outstanding_cmds)
2545 if (h == QLA_TGT_SKIP_HANDLE)
2548 if (!req->outstanding_cmds[h]) {
2555 req->current_outstanding_cmd = h;
2557 ql_dbg(ql_dbg_io, qpair->vha, 0x305b,
2558 "qla_target(%d): Ran out of empty cmd slots\n",
2559 qpair->vha->vp_idx);
2560 h = QLA_TGT_NULL_HANDLE;
2566 /* ha->hardware_lock supposed to be held on entry */
2567 static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair,
2568 struct qla_tgt_prm *prm)
2571 struct ctio7_to_24xx *pkt;
2572 struct atio_from_isp *atio = &prm->cmd->atio;
2575 pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr;
2577 memset(pkt, 0, sizeof(*pkt));
2579 pkt->entry_type = CTIO_TYPE7;
2580 pkt->entry_count = (uint8_t)prm->req_cnt;
2581 pkt->vp_index = prm->cmd->vp_idx;
2583 h = qlt_make_handle(qpair);
2584 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
2586 * CTIO type 7 from the firmware doesn't provide a way to
2587 * know the initiator's LOOP ID, hence we can't find
2588 * the session and, so, the command.
2592 qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
2594 pkt->handle = make_handle(qpair->req->id, h);
2595 pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
2596 pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
2597 pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2598 pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2599 pkt->exchange_addr = atio->u.isp24.exchange_addr;
2600 temp = atio->u.isp24.attr << 9;
2601 pkt->u.status0.flags |= cpu_to_le16(temp);
2602 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2603 pkt->u.status0.ox_id = cpu_to_le16(temp);
2604 pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset);
2610 * ha->hardware_lock supposed to be held on entry. We have already made sure
2611 * that there is sufficient amount of request entries to not drop it.
2613 static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm)
2616 struct dsd64 *cur_dsd;
2618 /* Build continuation packets */
2619 while (prm->seg_cnt > 0) {
2620 cont_a64_entry_t *cont_pkt64 =
2621 (cont_a64_entry_t *)qlt_get_req_pkt(
2622 prm->cmd->qpair->req);
2625 * Make sure that from cont_pkt64 none of
2626 * 64-bit specific fields used for 32-bit
2627 * addressing. Cast to (cont_entry_t *) for
2631 memset(cont_pkt64, 0, sizeof(*cont_pkt64));
2633 cont_pkt64->entry_count = 1;
2634 cont_pkt64->sys_define = 0;
2636 cont_pkt64->entry_type = CONTINUE_A64_TYPE;
2637 cur_dsd = cont_pkt64->dsd;
2639 /* Load continuation entry data segments */
2641 cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt;
2642 cnt++, prm->seg_cnt--) {
2643 append_dsd64(&cur_dsd, prm->sg);
2644 prm->sg = sg_next(prm->sg);
2650 * ha->hardware_lock supposed to be held on entry. We have already made sure
2651 * that there is sufficient amount of request entries to not drop it.
2653 static void qlt_load_data_segments(struct qla_tgt_prm *prm)
2656 struct dsd64 *cur_dsd;
2657 struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt;
2659 pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen);
2661 /* Setup packet address segment pointer */
2662 cur_dsd = &pkt24->u.status0.dsd;
2664 /* Set total data segment count */
2666 pkt24->dseg_count = cpu_to_le16(prm->seg_cnt);
2668 if (prm->seg_cnt == 0) {
2669 /* No data transfer */
2670 cur_dsd->address = 0;
2671 cur_dsd->length = 0;
2675 /* If scatter gather */
2677 /* Load command entry data segments */
2679 (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt;
2680 cnt++, prm->seg_cnt--) {
2681 append_dsd64(&cur_dsd, prm->sg);
2682 prm->sg = sg_next(prm->sg);
2685 qlt_load_cont_data_segments(prm);
2688 static inline int qlt_has_data(struct qla_tgt_cmd *cmd)
2690 return cmd->bufflen > 0;
2693 static void qlt_print_dif_err(struct qla_tgt_prm *prm)
2695 struct qla_tgt_cmd *cmd;
2696 struct scsi_qla_host *vha;
2698 /* asc 0x10=dif error */
2699 if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) {
2703 switch (prm->sense_buffer[13]) {
2705 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b,
2706 "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2707 "se_cmd=%p tag[%x]",
2708 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2709 cmd->atio.u.isp24.exchange_addr);
2712 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c,
2713 "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2714 "se_cmd=%p tag[%x]",
2715 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2716 cmd->atio.u.isp24.exchange_addr);
2719 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f,
2720 "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2721 "se_cmd=%p tag[%x]",
2722 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2723 cmd->atio.u.isp24.exchange_addr);
2726 ql_dbg(ql_dbg_tgt_dif, vha, 0xe010,
2727 "BE detected Dif ERR: lba[%llx|%lld] len[%x] "
2728 "se_cmd=%p tag[%x]",
2729 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2730 cmd->atio.u.isp24.exchange_addr);
2733 ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16);
2738 * Called without ha->hardware_lock held
2740 static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd,
2741 struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status,
2742 uint32_t *full_req_cnt)
2744 struct se_cmd *se_cmd = &cmd->se_cmd;
2745 struct qla_qpair *qpair = cmd->qpair;
2748 prm->tgt = cmd->tgt;
2750 prm->rq_result = scsi_status;
2751 prm->sense_buffer = &cmd->sense_buffer[0];
2752 prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER;
2757 prm->add_status_pkt = 0;
2758 prm->prot_sg = NULL;
2759 prm->prot_seg_cnt = 0;
2762 if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) {
2763 if (qlt_pci_map_calc_cnt(prm) != 0)
2767 *full_req_cnt = prm->req_cnt;
2769 if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
2770 prm->residual = se_cmd->residual_count;
2771 ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c,
2772 "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2773 prm->residual, se_cmd->tag,
2774 se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0,
2775 cmd->bufflen, prm->rq_result);
2776 prm->rq_result |= SS_RESIDUAL_UNDER;
2777 } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) {
2778 prm->residual = se_cmd->residual_count;
2779 ql_dbg_qp(ql_dbg_io, qpair, 0x305d,
2780 "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2781 prm->residual, se_cmd->tag, se_cmd->t_task_cdb ?
2782 se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result);
2783 prm->rq_result |= SS_RESIDUAL_OVER;
2786 if (xmit_type & QLA_TGT_XMIT_STATUS) {
2788 * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be
2789 * ignored in *xmit_response() below
2791 if (qlt_has_data(cmd)) {
2792 if (QLA_TGT_SENSE_VALID(prm->sense_buffer) ||
2793 (IS_FWI2_CAPABLE(cmd->vha->hw) &&
2794 (prm->rq_result != 0))) {
2795 prm->add_status_pkt = 1;
2804 static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd,
2807 if (cmd->qpair->enable_class_2)
2811 return cmd->conf_compl_supported;
2813 return cmd->qpair->enable_explicit_conf &&
2814 cmd->conf_compl_supported;
2817 static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio,
2818 struct qla_tgt_prm *prm)
2820 prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len,
2821 (uint32_t)sizeof(ctio->u.status1.sense_data));
2822 ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS);
2823 if (qlt_need_explicit_conf(prm->cmd, 0)) {
2824 ctio->u.status0.flags |= cpu_to_le16(
2825 CTIO7_FLAGS_EXPLICIT_CONFORM |
2826 CTIO7_FLAGS_CONFORM_REQ);
2828 ctio->u.status0.residual = cpu_to_le32(prm->residual);
2829 ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result);
2830 if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) {
2833 if (qlt_need_explicit_conf(prm->cmd, 1)) {
2834 if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) {
2835 ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017,
2836 "Skipping EXPLICIT_CONFORM and "
2837 "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
2838 "non GOOD status\n");
2839 goto skip_explict_conf;
2841 ctio->u.status1.flags |= cpu_to_le16(
2842 CTIO7_FLAGS_EXPLICIT_CONFORM |
2843 CTIO7_FLAGS_CONFORM_REQ);
2846 ctio->u.status1.flags &=
2847 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
2848 ctio->u.status1.flags |=
2849 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
2850 ctio->u.status1.scsi_status |=
2851 cpu_to_le16(SS_SENSE_LEN_VALID);
2852 ctio->u.status1.sense_length =
2853 cpu_to_le16(prm->sense_buffer_len);
2854 for (i = 0; i < prm->sense_buffer_len/4; i++) {
2857 v = get_unaligned_be32(
2858 &((uint32_t *)prm->sense_buffer)[i]);
2859 put_unaligned_le32(v,
2860 &((uint32_t *)ctio->u.status1.sense_data)[i]);
2862 qlt_print_dif_err(prm);
2865 ctio->u.status1.flags &=
2866 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
2867 ctio->u.status1.flags |=
2868 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
2869 ctio->u.status1.sense_length = 0;
2870 memset(ctio->u.status1.sense_data, 0,
2871 sizeof(ctio->u.status1.sense_data));
2874 /* Sense with len > 24, is it possible ??? */
2878 qlt_hba_err_chk_enabled(struct se_cmd *se_cmd)
2880 switch (se_cmd->prot_op) {
2881 case TARGET_PROT_DOUT_INSERT:
2882 case TARGET_PROT_DIN_STRIP:
2883 if (ql2xenablehba_err_chk >= 1)
2886 case TARGET_PROT_DOUT_PASS:
2887 case TARGET_PROT_DIN_PASS:
2888 if (ql2xenablehba_err_chk >= 2)
2891 case TARGET_PROT_DIN_INSERT:
2892 case TARGET_PROT_DOUT_STRIP:
2901 qla_tgt_ref_mask_check(struct se_cmd *se_cmd)
2903 switch (se_cmd->prot_op) {
2904 case TARGET_PROT_DIN_INSERT:
2905 case TARGET_PROT_DOUT_INSERT:
2906 case TARGET_PROT_DIN_STRIP:
2907 case TARGET_PROT_DOUT_STRIP:
2908 case TARGET_PROT_DIN_PASS:
2909 case TARGET_PROT_DOUT_PASS:
2918 * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command
2921 qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx,
2922 uint16_t *pfw_prot_opts)
2924 struct se_cmd *se_cmd = &cmd->se_cmd;
2925 uint32_t lba = 0xffffffff & se_cmd->t_task_lba;
2926 scsi_qla_host_t *vha = cmd->tgt->vha;
2927 struct qla_hw_data *ha = vha->hw;
2931 * wait till Mode Sense/Select cmd, modepage Ah, subpage 2
2932 * have been immplemented by TCM, before AppTag is avail.
2933 * Look for modesense_handlers[]
2936 ctx->app_tag_mask[0] = 0x0;
2937 ctx->app_tag_mask[1] = 0x0;
2939 if (IS_PI_UNINIT_CAPABLE(ha)) {
2940 if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) ||
2941 (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT))
2942 *pfw_prot_opts |= PO_DIS_VALD_APP_ESC;
2943 else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT)
2944 *pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC;
2947 t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts);
2949 switch (se_cmd->prot_type) {
2950 case TARGET_DIF_TYPE0_PROT:
2952 * No check for ql2xenablehba_err_chk, as it
2953 * would be an I/O error if hba tag generation
2956 ctx->ref_tag = cpu_to_le32(lba);
2957 /* enable ALL bytes of the ref tag */
2958 ctx->ref_tag_mask[0] = 0xff;
2959 ctx->ref_tag_mask[1] = 0xff;
2960 ctx->ref_tag_mask[2] = 0xff;
2961 ctx->ref_tag_mask[3] = 0xff;
2963 case TARGET_DIF_TYPE1_PROT:
2965 * For TYPE 1 protection: 16 bit GUARD tag, 32 bit
2966 * REF tag, and 16 bit app tag.
2968 ctx->ref_tag = cpu_to_le32(lba);
2969 if (!qla_tgt_ref_mask_check(se_cmd) ||
2970 !(ha->tgt.tgt_ops->chk_dif_tags(t32))) {
2971 *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
2974 /* enable ALL bytes of the ref tag */
2975 ctx->ref_tag_mask[0] = 0xff;
2976 ctx->ref_tag_mask[1] = 0xff;
2977 ctx->ref_tag_mask[2] = 0xff;
2978 ctx->ref_tag_mask[3] = 0xff;
2980 case TARGET_DIF_TYPE2_PROT:
2982 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF
2983 * tag has to match LBA in CDB + N
2985 ctx->ref_tag = cpu_to_le32(lba);
2986 if (!qla_tgt_ref_mask_check(se_cmd) ||
2987 !(ha->tgt.tgt_ops->chk_dif_tags(t32))) {
2988 *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
2991 /* enable ALL bytes of the ref tag */
2992 ctx->ref_tag_mask[0] = 0xff;
2993 ctx->ref_tag_mask[1] = 0xff;
2994 ctx->ref_tag_mask[2] = 0xff;
2995 ctx->ref_tag_mask[3] = 0xff;
2997 case TARGET_DIF_TYPE3_PROT:
2998 /* For TYPE 3 protection: 16 bit GUARD only */
2999 *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
3000 ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] =
3001 ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00;
3007 qlt_build_ctio_crc2_pkt(struct qla_qpair *qpair, struct qla_tgt_prm *prm)
3009 struct dsd64 *cur_dsd;
3010 uint32_t transfer_length = 0;
3011 uint32_t data_bytes;
3013 uint8_t bundling = 1;
3014 struct crc_context *crc_ctx_pkt = NULL;
3015 struct qla_hw_data *ha;
3016 struct ctio_crc2_to_fw *pkt;
3017 dma_addr_t crc_ctx_dma;
3018 uint16_t fw_prot_opts = 0;
3019 struct qla_tgt_cmd *cmd = prm->cmd;
3020 struct se_cmd *se_cmd = &cmd->se_cmd;
3022 struct atio_from_isp *atio = &prm->cmd->atio;
3023 struct qla_tc_param tc;
3025 scsi_qla_host_t *vha = cmd->vha;
3029 pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr;
3031 memset(pkt, 0, sizeof(*pkt));
3033 ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071,
3034 "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n",
3035 cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op,
3036 prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba);
3038 if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) ||
3039 (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP))
3042 /* Compute dif len and adjust data len to incude protection */
3043 data_bytes = cmd->bufflen;
3044 dif_bytes = (data_bytes / cmd->blk_sz) * 8;
3046 switch (se_cmd->prot_op) {
3047 case TARGET_PROT_DIN_INSERT:
3048 case TARGET_PROT_DOUT_STRIP:
3049 transfer_length = data_bytes;
3050 if (cmd->prot_sg_cnt)
3051 data_bytes += dif_bytes;
3053 case TARGET_PROT_DIN_STRIP:
3054 case TARGET_PROT_DOUT_INSERT:
3055 case TARGET_PROT_DIN_PASS:
3056 case TARGET_PROT_DOUT_PASS:
3057 transfer_length = data_bytes + dif_bytes;
3064 if (!qlt_hba_err_chk_enabled(se_cmd))
3065 fw_prot_opts |= 0x10; /* Disable Guard tag checking */
3066 /* HBA error checking enabled */
3067 else if (IS_PI_UNINIT_CAPABLE(ha)) {
3068 if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) ||
3069 (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT))
3070 fw_prot_opts |= PO_DIS_VALD_APP_ESC;
3071 else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT)
3072 fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC;
3075 switch (se_cmd->prot_op) {
3076 case TARGET_PROT_DIN_INSERT:
3077 case TARGET_PROT_DOUT_INSERT:
3078 fw_prot_opts |= PO_MODE_DIF_INSERT;
3080 case TARGET_PROT_DIN_STRIP:
3081 case TARGET_PROT_DOUT_STRIP:
3082 fw_prot_opts |= PO_MODE_DIF_REMOVE;
3084 case TARGET_PROT_DIN_PASS:
3085 case TARGET_PROT_DOUT_PASS:
3086 fw_prot_opts |= PO_MODE_DIF_PASS;
3087 /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */
3089 default:/* Normal Request */
3090 fw_prot_opts |= PO_MODE_DIF_PASS;
3095 /* Update entry type to indicate Command Type CRC_2 IOCB */
3096 pkt->entry_type = CTIO_CRC2;
3097 pkt->entry_count = 1;
3098 pkt->vp_index = cmd->vp_idx;
3100 h = qlt_make_handle(qpair);
3101 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
3103 * CTIO type 7 from the firmware doesn't provide a way to
3104 * know the initiator's LOOP ID, hence we can't find
3105 * the session and, so, the command.
3109 qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
3111 pkt->handle = make_handle(qpair->req->id, h);
3112 pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
3113 pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
3114 pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
3115 pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
3116 pkt->exchange_addr = atio->u.isp24.exchange_addr;
3118 /* silence compile warning */
3119 t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
3120 pkt->ox_id = cpu_to_le16(t16);
3122 t16 = (atio->u.isp24.attr << 9);
3123 pkt->flags |= cpu_to_le16(t16);
3124 pkt->relative_offset = cpu_to_le32(prm->cmd->offset);
3126 /* Set transfer direction */
3127 if (cmd->dma_data_direction == DMA_TO_DEVICE)
3128 pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN);
3129 else if (cmd->dma_data_direction == DMA_FROM_DEVICE)
3130 pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT);
3132 pkt->dseg_count = cpu_to_le16(prm->tot_dsds);
3133 /* Fibre channel byte count */
3134 pkt->transfer_length = cpu_to_le32(transfer_length);
3136 /* ----- CRC context -------- */
3138 /* Allocate CRC context from global pool */
3139 crc_ctx_pkt = cmd->ctx =
3140 dma_pool_zalloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma);
3143 goto crc_queuing_error;
3145 crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma;
3146 INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list);
3149 crc_ctx_pkt->handle = pkt->handle;
3151 qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts);
3153 put_unaligned_le64(crc_ctx_dma, &pkt->crc_context_address);
3154 pkt->crc_context_len = cpu_to_le16(CRC_CONTEXT_LEN_FW);
3157 cur_dsd = &crc_ctx_pkt->u.nobundling.data_dsd[0];
3160 * Configure Bundling if we need to fetch interlaving
3161 * protection PCI accesses
3163 fw_prot_opts |= PO_ENABLE_DIF_BUNDLING;
3164 crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes);
3165 crc_ctx_pkt->u.bundling.dseg_count =
3166 cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt);
3167 cur_dsd = &crc_ctx_pkt->u.bundling.data_dsd[0];
3170 /* Finish the common fields of CRC pkt */
3171 crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz);
3172 crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts);
3173 crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes);
3174 crc_ctx_pkt->guard_seed = cpu_to_le16(0);
3176 memset((uint8_t *)&tc, 0 , sizeof(tc));
3178 tc.blk_sz = cmd->blk_sz;
3179 tc.bufflen = cmd->bufflen;
3181 tc.prot_sg = cmd->prot_sg;
3182 tc.ctx = crc_ctx_pkt;
3183 tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced;
3185 /* Walks data segments */
3186 pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR);
3188 if (!bundling && prm->prot_seg_cnt) {
3189 if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd,
3190 prm->tot_dsds, &tc))
3191 goto crc_queuing_error;
3192 } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd,
3193 (prm->tot_dsds - prm->prot_seg_cnt), &tc))
3194 goto crc_queuing_error;
3196 if (bundling && prm->prot_seg_cnt) {
3197 /* Walks dif segments */
3198 pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA;
3200 cur_dsd = &crc_ctx_pkt->u.bundling.dif_dsd;
3201 if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd,
3202 prm->prot_seg_cnt, cmd))
3203 goto crc_queuing_error;
3208 /* Cleanup will be performed by the caller */
3209 qpair->req->outstanding_cmds[h] = NULL;
3211 return QLA_FUNCTION_FAILED;
3215 * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and *
3216 * QLA_TGT_XMIT_STATUS for >= 24xx silicon
3218 int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type,
3219 uint8_t scsi_status)
3221 struct scsi_qla_host *vha = cmd->vha;
3222 struct qla_qpair *qpair = cmd->qpair;
3223 struct ctio7_to_24xx *pkt;
3224 struct qla_tgt_prm prm;
3225 uint32_t full_req_cnt = 0;
3226 unsigned long flags = 0;
3229 if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) ||
3230 (cmd->sess && cmd->sess->deleted)) {
3231 cmd->state = QLA_TGT_STATE_PROCESSED;
3235 ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018,
3236 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p] qp %d\n",
3237 (xmit_type & QLA_TGT_XMIT_STATUS) ?
3238 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction,
3239 &cmd->se_cmd, qpair->id);
3241 res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status,
3243 if (unlikely(res != 0)) {
3247 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3249 if (xmit_type == QLA_TGT_XMIT_STATUS)
3250 qpair->tgt_counters.core_qla_snd_status++;
3252 qpair->tgt_counters.core_qla_que_buf++;
3254 if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) {
3256 * Either the port is not online or this request was from
3257 * previous life, just abort the processing.
3259 cmd->state = QLA_TGT_STATE_PROCESSED;
3260 ql_dbg_qp(ql_dbg_async, qpair, 0xe101,
3261 "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n",
3262 vha->flags.online, qla2x00_reset_active(vha),
3263 cmd->reset_count, qpair->chip_reset);
3264 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3268 /* Does F/W have an IOCBs for this request */
3269 res = qlt_check_reserve_free_req(qpair, full_req_cnt);
3271 goto out_unmap_unlock;
3273 if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA))
3274 res = qlt_build_ctio_crc2_pkt(qpair, &prm);
3276 res = qlt_24xx_build_ctio_pkt(qpair, &prm);
3277 if (unlikely(res != 0)) {
3278 qpair->req->cnt += full_req_cnt;
3279 goto out_unmap_unlock;
3282 pkt = (struct ctio7_to_24xx *)prm.pkt;
3284 if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) {
3285 pkt->u.status0.flags |=
3286 cpu_to_le16(CTIO7_FLAGS_DATA_IN |
3287 CTIO7_FLAGS_STATUS_MODE_0);
3289 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
3290 qlt_load_data_segments(&prm);
3292 if (prm.add_status_pkt == 0) {
3293 if (xmit_type & QLA_TGT_XMIT_STATUS) {
3294 pkt->u.status0.scsi_status =
3295 cpu_to_le16(prm.rq_result);
3296 pkt->u.status0.residual =
3297 cpu_to_le32(prm.residual);
3298 pkt->u.status0.flags |= cpu_to_le16(
3299 CTIO7_FLAGS_SEND_STATUS);
3300 if (qlt_need_explicit_conf(cmd, 0)) {
3301 pkt->u.status0.flags |=
3303 CTIO7_FLAGS_EXPLICIT_CONFORM |
3304 CTIO7_FLAGS_CONFORM_REQ);
3310 * We have already made sure that there is sufficient
3311 * amount of request entries to not drop HW lock in
3314 struct ctio7_to_24xx *ctio =
3315 (struct ctio7_to_24xx *)qlt_get_req_pkt(
3318 ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e,
3319 "Building additional status packet 0x%p.\n",
3323 * T10Dif: ctio_crc2_to_fw overlay ontop of
3326 memcpy(ctio, pkt, sizeof(*ctio));
3327 /* reset back to CTIO7 */
3328 ctio->entry_count = 1;
3329 ctio->entry_type = CTIO_TYPE7;
3330 ctio->dseg_count = 0;
3331 ctio->u.status1.flags &= ~cpu_to_le16(
3332 CTIO7_FLAGS_DATA_IN);
3334 /* Real finish is ctio_m1's finish */
3335 pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK;
3336 pkt->u.status0.flags |= cpu_to_le16(
3337 CTIO7_FLAGS_DONT_RET_CTIO);
3339 /* qlt_24xx_init_ctio_to_isp will correct
3340 * all neccessary fields that's part of CTIO7.
3341 * There should be no residual of CTIO-CRC2 data.
3343 qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio,
3347 qlt_24xx_init_ctio_to_isp(pkt, &prm);
3350 cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */
3351 cmd->cmd_sent_to_fw = 1;
3352 cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
3354 /* Memory Barrier */
3356 if (qpair->reqq_start_iocbs)
3357 qpair->reqq_start_iocbs(qpair);
3359 qla2x00_start_iocbs(vha, qpair->req);
3360 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3365 qlt_unmap_sg(vha, cmd);
3366 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3370 EXPORT_SYMBOL(qlt_xmit_response);
3372 int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd)
3374 struct ctio7_to_24xx *pkt;
3375 struct scsi_qla_host *vha = cmd->vha;
3376 struct qla_tgt *tgt = cmd->tgt;
3377 struct qla_tgt_prm prm;
3378 unsigned long flags = 0;
3380 struct qla_qpair *qpair = cmd->qpair;
3382 memset(&prm, 0, sizeof(prm));
3388 /* Calculate number of entries and segments required */
3389 if (qlt_pci_map_calc_cnt(&prm) != 0)
3392 if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) ||
3393 (cmd->sess && cmd->sess->deleted)) {
3395 * Either the port is not online or this request was from
3396 * previous life, just abort the processing.
3399 cmd->write_data_transferred = 0;
3400 cmd->state = QLA_TGT_STATE_DATA_IN;
3401 vha->hw->tgt.tgt_ops->handle_data(cmd);
3402 ql_dbg_qp(ql_dbg_async, qpair, 0xe102,
3403 "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n",
3404 vha->flags.online, qla2x00_reset_active(vha),
3405 cmd->reset_count, qpair->chip_reset);
3409 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3410 /* Does F/W have an IOCBs for this request */
3411 res = qlt_check_reserve_free_req(qpair, prm.req_cnt);
3413 goto out_unlock_free_unmap;
3414 if (cmd->se_cmd.prot_op)
3415 res = qlt_build_ctio_crc2_pkt(qpair, &prm);
3417 res = qlt_24xx_build_ctio_pkt(qpair, &prm);
3419 if (unlikely(res != 0)) {
3420 qpair->req->cnt += prm.req_cnt;
3421 goto out_unlock_free_unmap;
3424 pkt = (struct ctio7_to_24xx *)prm.pkt;
3425 pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT |
3426 CTIO7_FLAGS_STATUS_MODE_0);
3428 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
3429 qlt_load_data_segments(&prm);
3431 cmd->state = QLA_TGT_STATE_NEED_DATA;
3432 cmd->cmd_sent_to_fw = 1;
3433 cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
3435 /* Memory Barrier */
3437 if (qpair->reqq_start_iocbs)
3438 qpair->reqq_start_iocbs(qpair);
3440 qla2x00_start_iocbs(vha, qpair->req);
3441 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3445 out_unlock_free_unmap:
3446 qlt_unmap_sg(vha, cmd);
3447 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3451 EXPORT_SYMBOL(qlt_rdy_to_xfer);
3455 * it is assumed either hardware_lock or qpair lock is held.
3458 qlt_handle_dif_error(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd,
3459 struct ctio_crc_from_fw *sts)
3461 uint8_t *ap = &sts->actual_dif[0];
3462 uint8_t *ep = &sts->expected_dif[0];
3463 uint64_t lba = cmd->se_cmd.t_task_lba;
3464 uint8_t scsi_status, sense_key, asc, ascq;
3465 unsigned long flags;
3466 struct scsi_qla_host *vha = cmd->vha;
3468 cmd->trc_flags |= TRC_DIF_ERR;
3470 cmd->a_guard = get_unaligned_be16(ap + 0);
3471 cmd->a_app_tag = get_unaligned_be16(ap + 2);
3472 cmd->a_ref_tag = get_unaligned_be32(ap + 4);
3474 cmd->e_guard = get_unaligned_be16(ep + 0);
3475 cmd->e_app_tag = get_unaligned_be16(ep + 2);
3476 cmd->e_ref_tag = get_unaligned_be32(ep + 4);
3478 ql_dbg(ql_dbg_tgt_dif, vha, 0xf075,
3479 "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state);
3481 scsi_status = sense_key = asc = ascq = 0;
3483 /* check appl tag */
3484 if (cmd->e_app_tag != cmd->a_app_tag) {
3485 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d,
3486 "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]",
3487 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3488 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3489 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3490 cmd->atio.u.isp24.fcp_hdr.ox_id);
3492 cmd->dif_err_code = DIF_ERR_APP;
3493 scsi_status = SAM_STAT_CHECK_CONDITION;
3494 sense_key = ABORTED_COMMAND;
3500 if (cmd->e_ref_tag != cmd->a_ref_tag) {
3501 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e,
3502 "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] ",
3503 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3504 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3505 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3506 cmd->atio.u.isp24.fcp_hdr.ox_id);
3508 cmd->dif_err_code = DIF_ERR_REF;
3509 scsi_status = SAM_STAT_CHECK_CONDITION;
3510 sense_key = ABORTED_COMMAND;
3517 if (cmd->e_guard != cmd->a_guard) {
3518 ql_dbg(ql_dbg_tgt_dif, vha, 0xe012,
3519 "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]",
3520 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3521 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3522 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3523 cmd->atio.u.isp24.fcp_hdr.ox_id);
3525 cmd->dif_err_code = DIF_ERR_GRD;
3526 scsi_status = SAM_STAT_CHECK_CONDITION;
3527 sense_key = ABORTED_COMMAND;
3532 switch (cmd->state) {
3533 case QLA_TGT_STATE_NEED_DATA:
3534 /* handle_data will load DIF error code */
3535 cmd->state = QLA_TGT_STATE_DATA_IN;
3536 vha->hw->tgt.tgt_ops->handle_data(cmd);
3539 spin_lock_irqsave(&cmd->cmd_lock, flags);
3541 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3542 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3545 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3547 qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc,
3549 /* assume scsi status gets out on the wire.
3550 * Will not wait for completion.
3552 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3557 /* If hardware_lock held on entry, might drop it, then reaquire */
3558 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
3559 static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha,
3560 struct imm_ntfy_from_isp *ntfy)
3562 struct nack_to_isp *nack;
3563 struct qla_hw_data *ha = vha->hw;
3567 ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c,
3568 "Sending TERM ELS CTIO (ha=%p)\n", ha);
3570 pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL);
3572 ql_dbg(ql_dbg_tgt, vha, 0xe080,
3573 "qla_target(%d): %s failed: unable to allocate "
3574 "request packet\n", vha->vp_idx, __func__);
3578 pkt->entry_type = NOTIFY_ACK_TYPE;
3579 pkt->entry_count = 1;
3580 pkt->handle = QLA_TGT_SKIP_HANDLE;
3582 nack = (struct nack_to_isp *)pkt;
3583 nack->ox_id = ntfy->ox_id;
3585 nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
3586 if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
3587 nack->u.isp24.flags = ntfy->u.isp24.flags &
3588 cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB);
3592 nack->u.isp24.flags |=
3593 __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE);
3595 nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
3596 nack->u.isp24.status = ntfy->u.isp24.status;
3597 nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode;
3598 nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle;
3599 nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address;
3600 nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs;
3601 nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui;
3602 nack->u.isp24.vp_index = ntfy->u.isp24.vp_index;
3604 qla2x00_start_iocbs(vha, vha->req);
3608 static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
3609 struct imm_ntfy_from_isp *imm, int ha_locked)
3613 WARN_ON_ONCE(!ha_locked);
3614 rc = __qlt_send_term_imm_notif(vha, imm);
3615 pr_debug("rc = %d\n", rc);
3619 * If hardware_lock held on entry, might drop it, then reaquire
3620 * This function sends the appropriate CTIO to ISP 2xxx or 24xx
3622 static int __qlt_send_term_exchange(struct qla_qpair *qpair,
3623 struct qla_tgt_cmd *cmd,
3624 struct atio_from_isp *atio)
3626 struct scsi_qla_host *vha = qpair->vha;
3627 struct ctio7_to_24xx *ctio24;
3628 struct qla_hw_data *ha = vha->hw;
3633 ql_dbg(ql_dbg_tgt, vha, 0xe009, "Sending TERM EXCH CTIO (ha=%p)\n", ha);
3638 pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL);
3640 ql_dbg(ql_dbg_tgt, vha, 0xe050,
3641 "qla_target(%d): %s failed: unable to allocate "
3642 "request packet\n", vha->vp_idx, __func__);
3647 if (cmd->state < QLA_TGT_STATE_PROCESSED) {
3648 ql_dbg(ql_dbg_tgt, vha, 0xe051,
3649 "qla_target(%d): Terminating cmd %p with "
3650 "incorrect state %d\n", vha->vp_idx, cmd,
3656 qpair->tgt_counters.num_term_xchg_sent++;
3657 pkt->entry_count = 1;
3658 pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
3660 ctio24 = (struct ctio7_to_24xx *)pkt;
3661 ctio24->entry_type = CTIO_TYPE7;
3662 ctio24->nport_handle = cpu_to_le16(CTIO7_NHANDLE_UNRECOGNIZED);
3663 ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
3664 ctio24->vp_index = vha->vp_idx;
3665 ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
3666 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
3667 temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 |
3668 CTIO7_FLAGS_TERMINATE;
3669 ctio24->u.status1.flags = cpu_to_le16(temp);
3670 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
3671 ctio24->u.status1.ox_id = cpu_to_le16(temp);
3673 /* Memory Barrier */
3675 if (qpair->reqq_start_iocbs)
3676 qpair->reqq_start_iocbs(qpair);
3678 qla2x00_start_iocbs(vha, qpair->req);
3682 static void qlt_send_term_exchange(struct qla_qpair *qpair,
3683 struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked,
3686 struct scsi_qla_host *vha;
3687 unsigned long flags = 0;
3690 /* why use different vha? NPIV */
3697 rc = __qlt_send_term_exchange(qpair, cmd, atio);
3699 qlt_alloc_qfull_cmd(vha, atio, 0, 0);
3702 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3703 rc = __qlt_send_term_exchange(qpair, cmd, atio);
3705 qlt_alloc_qfull_cmd(vha, atio, 0, 0);
3708 if (cmd && !ul_abort && !cmd->aborted) {
3710 qlt_unmap_sg(vha, cmd);
3711 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3715 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3720 static void qlt_init_term_exchange(struct scsi_qla_host *vha)
3722 struct list_head free_list;
3723 struct qla_tgt_cmd *cmd, *tcmd;
3725 vha->hw->tgt.leak_exchg_thresh_hold =
3726 (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT;
3729 if (!list_empty(&vha->hw->tgt.q_full_list)) {
3730 INIT_LIST_HEAD(&free_list);
3731 list_splice_init(&vha->hw->tgt.q_full_list, &free_list);
3733 list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) {
3734 list_del(&cmd->cmd_list);
3735 /* This cmd was never sent to TCM. There is no need
3736 * to schedule free or call free_cmd
3739 vha->hw->tgt.num_qfull_cmds_alloc--;
3742 vha->hw->tgt.num_qfull_cmds_dropped = 0;
3745 static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha)
3747 uint32_t total_leaked;
3749 total_leaked = vha->hw->tgt.num_qfull_cmds_dropped;
3751 if (vha->hw->tgt.leak_exchg_thresh_hold &&
3752 (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) {
3754 ql_dbg(ql_dbg_tgt, vha, 0xe079,
3755 "Chip reset due to exchange starvation: %d/%d.\n",
3756 total_leaked, vha->hw->cur_fw_xcb_count);
3758 if (IS_P3P_TYPE(vha->hw))
3759 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
3761 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3762 qla2xxx_wake_dpc(vha);
3767 int qlt_abort_cmd(struct qla_tgt_cmd *cmd)
3769 struct qla_tgt *tgt = cmd->tgt;
3770 struct scsi_qla_host *vha = tgt->vha;
3771 struct se_cmd *se_cmd = &cmd->se_cmd;
3772 unsigned long flags;
3774 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014,
3775 "qla_target(%d): terminating exchange for aborted cmd=%p "
3776 "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd,
3779 spin_lock_irqsave(&cmd->cmd_lock, flags);
3781 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3783 * It's normal to see 2 calls in this path:
3784 * 1) XFER Rdy completion + CMD_T_ABORT
3785 * 2) TCM TMR - drain_state_list
3787 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016,
3788 "multiple abort. %p transport_state %x, t_state %x, "
3789 "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state,
3790 cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags);
3794 cmd->trc_flags |= TRC_ABORT;
3795 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3797 qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1);
3800 EXPORT_SYMBOL(qlt_abort_cmd);
3802 void qlt_free_cmd(struct qla_tgt_cmd *cmd)
3804 struct fc_port *sess = cmd->sess;
3806 ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074,
3807 "%s: se_cmd[%p] ox_id %04x\n",
3808 __func__, &cmd->se_cmd,
3809 be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
3811 BUG_ON(cmd->cmd_in_wq);
3814 qlt_unmap_sg(cmd->vha, cmd);
3817 qlt_decr_num_pend_cmds(cmd->vha);
3819 BUG_ON(cmd->sg_mapped);
3820 cmd->jiffies_at_free = get_jiffies_64();
3821 if (unlikely(cmd->free_sg))
3824 if (!sess || !sess->se_sess) {
3828 cmd->jiffies_at_free = get_jiffies_64();
3829 cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd);
3831 EXPORT_SYMBOL(qlt_free_cmd);
3834 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3836 static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio,
3837 struct qla_tgt_cmd *cmd, uint32_t status)
3840 struct scsi_qla_host *vha = qpair->vha;
3842 if (cmd->se_cmd.prot_op)
3843 ql_dbg(ql_dbg_tgt_dif, vha, 0xe013,
3844 "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] "
3845 "se_cmd=%p tag[%x] op %#x/%s",
3847 cmd->num_blks, &cmd->se_cmd,
3848 cmd->atio.u.isp24.exchange_addr,
3849 cmd->se_cmd.prot_op,
3850 prot_op_str(cmd->se_cmd.prot_op));
3853 struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio;
3856 cpu_to_le16(OF_TERM_EXCH));
3861 qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1, 0);
3867 /* ha->hardware_lock supposed to be held on entry */
3868 static void *qlt_ctio_to_cmd(struct scsi_qla_host *vha,
3869 struct rsp_que *rsp, uint32_t handle, void *ctio)
3872 struct req_que *req;
3873 int qid = GET_QID(handle);
3874 uint32_t h = handle & ~QLA_TGT_HANDLE_MASK;
3876 if (unlikely(h == QLA_TGT_SKIP_HANDLE))
3879 if (qid == rsp->req->id) {
3881 } else if (vha->hw->req_q_map[qid]) {
3882 ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a,
3883 "qla_target(%d): CTIO completion with different QID %d handle %x\n",
3884 vha->vp_idx, rsp->id, handle);
3885 req = vha->hw->req_q_map[qid];
3890 h &= QLA_CMD_HANDLE_MASK;
3892 if (h != QLA_TGT_NULL_HANDLE) {
3893 if (unlikely(h >= req->num_outstanding_cmds)) {
3894 ql_dbg(ql_dbg_tgt, vha, 0xe052,
3895 "qla_target(%d): Wrong handle %x received\n",
3896 vha->vp_idx, handle);
3900 cmd = req->outstanding_cmds[h];
3901 if (unlikely(cmd == NULL)) {
3902 ql_dbg(ql_dbg_async, vha, 0xe053,
3903 "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n",
3904 vha->vp_idx, handle, req->id, rsp->id);
3907 req->outstanding_cmds[h] = NULL;
3908 } else if (ctio != NULL) {
3909 /* We can't get loop ID from CTIO7 */
3910 ql_dbg(ql_dbg_tgt, vha, 0xe054,
3911 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
3912 "support NULL handles\n", vha->vp_idx);
3920 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3922 static void qlt_do_ctio_completion(struct scsi_qla_host *vha,
3923 struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio)
3925 struct qla_hw_data *ha = vha->hw;
3926 struct se_cmd *se_cmd;
3927 struct qla_tgt_cmd *cmd;
3928 struct qla_qpair *qpair = rsp->qpair;
3930 if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) {
3931 /* That could happen only in case of an error/reset/abort */
3932 if (status != CTIO_SUCCESS) {
3933 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d,
3934 "Intermediate CTIO received"
3935 " (status %x)\n", status);
3940 cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio);
3944 se_cmd = &cmd->se_cmd;
3945 cmd->cmd_sent_to_fw = 0;
3947 qlt_unmap_sg(vha, cmd);
3949 if (unlikely(status != CTIO_SUCCESS)) {
3950 switch (status & 0xFFFF) {
3951 case CTIO_INVALID_RX_ID:
3952 if (printk_ratelimit())
3953 dev_info(&vha->hw->pdev->dev,
3954 "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n",
3955 vha->vp_idx, cmd->atio.u.isp24.attr,
3956 ((cmd->ctio_flags >> 9) & 0xf),
3960 case CTIO_LIP_RESET:
3961 case CTIO_TARGET_RESET:
3963 /* driver request abort via Terminate exchange */
3966 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058,
3967 "qla_target(%d): CTIO with "
3968 "status %#x received, state %x, se_cmd %p, "
3969 "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
3970 "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx,
3971 status, cmd->state, se_cmd);
3974 case CTIO_PORT_LOGGED_OUT:
3975 case CTIO_PORT_UNAVAILABLE:
3978 (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT;
3980 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059,
3981 "qla_target(%d): CTIO with %s status %x "
3982 "received (state %x, se_cmd %p)\n", vha->vp_idx,
3983 logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE",
3984 status, cmd->state, se_cmd);
3986 if (logged_out && cmd->sess) {
3988 * Session is already logged out, but we need
3989 * to notify initiator, who's not aware of this
3991 cmd->sess->send_els_logo = 1;
3992 ql_dbg(ql_dbg_disc, vha, 0x20f8,
3993 "%s %d %8phC post del sess\n",
3994 __func__, __LINE__, cmd->sess->port_name);
3996 qlt_schedule_sess_for_deletion(cmd->sess);
4000 case CTIO_DIF_ERROR: {
4001 struct ctio_crc_from_fw *crc =
4002 (struct ctio_crc_from_fw *)ctio;
4003 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073,
4004 "qla_target(%d): CTIO with DIF_ERROR status %x "
4005 "received (state %x, ulp_cmd %p) actual_dif[0x%llx] "
4006 "expect_dif[0x%llx]\n",
4007 vha->vp_idx, status, cmd->state, se_cmd,
4008 *((u64 *)&crc->actual_dif[0]),
4009 *((u64 *)&crc->expected_dif[0]));
4011 qlt_handle_dif_error(qpair, cmd, ctio);
4015 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b,
4016 "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n",
4017 vha->vp_idx, status, cmd->state, se_cmd);
4022 /* "cmd->aborted" means
4023 * cmd is already aborted/terminated, we don't
4024 * need to terminate again. The exchange is already
4025 * cleaned up/freed at FW level. Just cleanup at driver
4028 if ((cmd->state != QLA_TGT_STATE_NEED_DATA) &&
4030 cmd->trc_flags |= TRC_CTIO_ERR;
4031 if (qlt_term_ctio_exchange(qpair, ctio, cmd, status))
4036 if (cmd->state == QLA_TGT_STATE_PROCESSED) {
4037 cmd->trc_flags |= TRC_CTIO_DONE;
4038 } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) {
4039 cmd->state = QLA_TGT_STATE_DATA_IN;
4041 if (status == CTIO_SUCCESS)
4042 cmd->write_data_transferred = 1;
4044 ha->tgt.tgt_ops->handle_data(cmd);
4046 } else if (cmd->aborted) {
4047 cmd->trc_flags |= TRC_CTIO_ABORTED;
4048 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e,
4049 "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag);
4051 cmd->trc_flags |= TRC_CTIO_STRANGE;
4052 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c,
4053 "qla_target(%d): A command in state (%d) should "
4054 "not return a CTIO complete\n", vha->vp_idx, cmd->state);
4057 if (unlikely(status != CTIO_SUCCESS) &&
4059 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n");
4063 ha->tgt.tgt_ops->free_cmd(cmd);
4066 static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha,
4071 switch (task_codes) {
4072 case ATIO_SIMPLE_QUEUE:
4073 fcp_task_attr = TCM_SIMPLE_TAG;
4075 case ATIO_HEAD_OF_QUEUE:
4076 fcp_task_attr = TCM_HEAD_TAG;
4078 case ATIO_ORDERED_QUEUE:
4079 fcp_task_attr = TCM_ORDERED_TAG;
4081 case ATIO_ACA_QUEUE:
4082 fcp_task_attr = TCM_ACA_TAG;
4085 fcp_task_attr = TCM_SIMPLE_TAG;
4088 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d,
4089 "qla_target: unknown task code %x, use ORDERED instead\n",
4091 fcp_task_attr = TCM_ORDERED_TAG;
4095 return fcp_task_attr;
4099 * Process context for I/O path into tcm_qla2xxx code
4101 static void __qlt_do_work(struct qla_tgt_cmd *cmd)
4103 scsi_qla_host_t *vha = cmd->vha;
4104 struct qla_hw_data *ha = vha->hw;
4105 struct fc_port *sess = cmd->sess;
4106 struct atio_from_isp *atio = &cmd->atio;
4108 unsigned long flags;
4109 uint32_t data_length;
4110 int ret, fcp_task_attr, data_dir, bidi = 0;
4111 struct qla_qpair *qpair = cmd->qpair;
4114 cmd->trc_flags |= TRC_DO_WORK;
4117 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082,
4118 "cmd with tag %u is aborted\n",
4119 cmd->atio.u.isp24.exchange_addr);
4123 spin_lock_init(&cmd->cmd_lock);
4124 cdb = &atio->u.isp24.fcp_cmnd.cdb[0];
4125 cmd->se_cmd.tag = le32_to_cpu(atio->u.isp24.exchange_addr);
4127 if (atio->u.isp24.fcp_cmnd.rddata &&
4128 atio->u.isp24.fcp_cmnd.wrdata) {
4130 data_dir = DMA_TO_DEVICE;
4131 } else if (atio->u.isp24.fcp_cmnd.rddata)
4132 data_dir = DMA_FROM_DEVICE;
4133 else if (atio->u.isp24.fcp_cmnd.wrdata)
4134 data_dir = DMA_TO_DEVICE;
4136 data_dir = DMA_NONE;
4138 fcp_task_attr = qlt_get_fcp_task_attr(vha,
4139 atio->u.isp24.fcp_cmnd.task_attr);
4140 data_length = get_datalen_for_atio(atio);
4142 ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length,
4143 fcp_task_attr, data_dir, bidi);
4147 * Drop extra session reference from qlt_handle_cmd_for_atio().
4149 ha->tgt.tgt_ops->put_sess(sess);
4153 ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd);
4155 * cmd has not sent to target yet, so pass NULL as the second
4156 * argument to qlt_send_term_exchange() and free the memory here.
4158 cmd->trc_flags |= TRC_DO_WORK_ERR;
4159 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
4160 qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0);
4162 qlt_decr_num_pend_cmds(vha);
4163 cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd);
4164 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
4166 ha->tgt.tgt_ops->put_sess(sess);
4169 static void qlt_do_work(struct work_struct *work)
4171 struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work);
4172 scsi_qla_host_t *vha = cmd->vha;
4173 unsigned long flags;
4175 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4176 list_del(&cmd->cmd_list);
4177 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4182 void qlt_clr_qp_table(struct scsi_qla_host *vha)
4184 unsigned long flags;
4185 struct qla_hw_data *ha = vha->hw;
4186 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4190 ql_log(ql_log_info, vha, 0x706c,
4191 "User update Number of Active Qpairs %d\n",
4192 ha->tgt.num_act_qpairs);
4194 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
4196 btree_for_each_safe64(&tgt->lun_qpair_map, key, node)
4197 btree_remove64(&tgt->lun_qpair_map, key);
4199 ha->base_qpair->lun_cnt = 0;
4200 for (key = 0; key < ha->max_qpairs; key++)
4201 if (ha->queue_pair_map[key])
4202 ha->queue_pair_map[key]->lun_cnt = 0;
4204 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
4207 static void qlt_assign_qpair(struct scsi_qla_host *vha,
4208 struct qla_tgt_cmd *cmd)
4210 struct qla_qpair *qpair, *qp;
4211 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4212 struct qla_qpair_hint *h;
4214 if (vha->flags.qpairs_available) {
4215 h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun);
4217 /* spread lun to qpair ratio evently */
4219 struct scsi_qla_host *base_vha =
4220 pci_get_drvdata(vha->hw->pdev);
4222 qpair = vha->hw->base_qpair;
4223 if (qpair->lun_cnt == 0) {
4225 h = qla_qpair_to_hint(tgt, qpair);
4227 rc = btree_insert64(&tgt->lun_qpair_map,
4228 cmd->unpacked_lun, h, GFP_ATOMIC);
4231 ql_log(ql_log_info, vha, 0xd037,
4232 "Unable to insert lun %llx into lun_qpair_map\n",
4237 lcnt = qpair->lun_cnt;
4241 list_for_each_entry(qp, &base_vha->qp_list,
4243 if (qp->lun_cnt == 0) {
4245 h = qla_qpair_to_hint(tgt, qp);
4247 rc = btree_insert64(&tgt->lun_qpair_map,
4248 cmd->unpacked_lun, h, GFP_ATOMIC);
4251 ql_log(ql_log_info, vha, 0xd038,
4252 "Unable to insert lun %llx into lun_qpair_map\n",
4258 if (qp->lun_cnt < lcnt) {
4267 h = qla_qpair_to_hint(tgt, qpair);
4269 rc = btree_insert64(&tgt->lun_qpair_map,
4270 cmd->unpacked_lun, h, GFP_ATOMIC);
4273 ql_log(ql_log_info, vha, 0xd039,
4274 "Unable to insert lun %llx into lun_qpair_map\n",
4279 h = &tgt->qphints[0];
4282 cmd->qpair = h->qpair;
4283 cmd->se_cmd.cpuid = h->cpuid;
4286 static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha,
4287 struct fc_port *sess,
4288 struct atio_from_isp *atio)
4290 struct qla_tgt_cmd *cmd;
4292 cmd = vha->hw->tgt.tgt_ops->get_cmd(sess);
4296 cmd->cmd_type = TYPE_TGT_CMD;
4297 memcpy(&cmd->atio, atio, sizeof(*atio));
4298 INIT_LIST_HEAD(&cmd->sess_cmd_list);
4299 cmd->state = QLA_TGT_STATE_NEW;
4300 cmd->tgt = vha->vha_tgt.qla_tgt;
4301 qlt_incr_num_pend_cmds(vha);
4304 cmd->loop_id = sess->loop_id;
4305 cmd->conf_compl_supported = sess->conf_compl_supported;
4308 cmd->jiffies_at_alloc = get_jiffies_64();
4310 cmd->unpacked_lun = scsilun_to_int(
4311 (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun);
4312 qlt_assign_qpair(vha, cmd);
4313 cmd->reset_count = vha->hw->base_qpair->chip_reset;
4314 cmd->vp_idx = vha->vp_idx;
4319 /* ha->hardware_lock supposed to be held on entry */
4320 static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha,
4321 struct atio_from_isp *atio)
4323 struct qla_hw_data *ha = vha->hw;
4324 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4325 struct fc_port *sess;
4326 struct qla_tgt_cmd *cmd;
4327 unsigned long flags;
4330 if (unlikely(tgt->tgt_stop)) {
4331 ql_dbg(ql_dbg_io, vha, 0x3061,
4332 "New command while device %p is shutting down\n", tgt);
4336 id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
4337 if (IS_SW_RESV_ADDR(id))
4340 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id);
4341 if (unlikely(!sess))
4344 /* Another WWN used to have our s_id. Our PLOGI scheduled its
4345 * session deletion, but it's still in sess_del_work wq */
4346 if (sess->deleted) {
4347 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002,
4348 "New command while old session %p is being deleted\n",
4354 * Do kref_get() before returning + dropping qla_hw_data->hardware_lock.
4356 if (!kref_get_unless_zero(&sess->sess_kref)) {
4357 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004,
4358 "%s: kref_get fail, %8phC oxid %x \n",
4359 __func__, sess->port_name,
4360 be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
4364 cmd = qlt_get_tag(vha, sess, atio);
4366 ql_dbg(ql_dbg_io, vha, 0x3062,
4367 "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx);
4368 ha->tgt.tgt_ops->put_sess(sess);
4373 cmd->trc_flags |= TRC_NEW_CMD;
4375 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4376 list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list);
4377 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4379 INIT_WORK(&cmd->work, qlt_do_work);
4380 if (vha->flags.qpairs_available) {
4381 queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work);
4382 } else if (ha->msix_count) {
4383 if (cmd->atio.u.isp24.fcp_cmnd.rddata)
4384 queue_work_on(smp_processor_id(), qla_tgt_wq,
4387 queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq,
4390 queue_work(qla_tgt_wq, &cmd->work);
4396 /* ha->hardware_lock supposed to be held on entry */
4397 static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun,
4398 int fn, void *iocb, int flags)
4400 struct scsi_qla_host *vha = sess->vha;
4401 struct qla_hw_data *ha = vha->hw;
4402 struct qla_tgt_mgmt_cmd *mcmd;
4403 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4404 struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0];
4406 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
4408 ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009,
4409 "qla_target(%d): Allocation of management "
4410 "command failed, some commands and their data could "
4411 "leak\n", vha->vp_idx);
4414 memset(mcmd, 0, sizeof(*mcmd));
4418 memcpy(&mcmd->orig_iocb.imm_ntfy, iocb,
4419 sizeof(mcmd->orig_iocb.imm_ntfy));
4421 mcmd->tmr_func = fn;
4422 mcmd->flags = flags;
4423 mcmd->reset_count = ha->base_qpair->chip_reset;
4424 mcmd->qpair = h->qpair;
4426 mcmd->se_cmd.cpuid = h->cpuid;
4427 mcmd->unpacked_lun = lun;
4430 case QLA_TGT_LUN_RESET:
4431 case QLA_TGT_CLEAR_TS:
4432 case QLA_TGT_ABORT_TS:
4433 abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id);
4435 case QLA_TGT_CLEAR_ACA:
4436 h = qlt_find_qphint(vha, mcmd->unpacked_lun);
4437 mcmd->qpair = h->qpair;
4438 mcmd->se_cmd.cpuid = h->cpuid;
4441 case QLA_TGT_TARGET_RESET:
4442 case QLA_TGT_NEXUS_LOSS_SESS:
4443 case QLA_TGT_NEXUS_LOSS:
4444 case QLA_TGT_ABORT_ALL:
4450 INIT_WORK(&mcmd->work, qlt_do_tmr_work);
4451 queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq,
4457 /* ha->hardware_lock supposed to be held on entry */
4458 static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb)
4460 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4461 struct qla_hw_data *ha = vha->hw;
4462 struct fc_port *sess;
4465 unsigned long flags;
4467 fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
4469 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
4470 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha,
4471 a->u.isp24.fcp_hdr.s_id);
4472 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
4475 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
4477 if (sess == NULL || sess->deleted)
4480 return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
4483 /* ha->hardware_lock supposed to be held on entry */
4484 static int __qlt_abort_task(struct scsi_qla_host *vha,
4485 struct imm_ntfy_from_isp *iocb, struct fc_port *sess)
4487 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4488 struct qla_hw_data *ha = vha->hw;
4489 struct qla_tgt_mgmt_cmd *mcmd;
4493 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
4495 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f,
4496 "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
4497 vha->vp_idx, __func__);
4500 memset(mcmd, 0, sizeof(*mcmd));
4503 memcpy(&mcmd->orig_iocb.imm_ntfy, iocb,
4504 sizeof(mcmd->orig_iocb.imm_ntfy));
4507 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
4508 mcmd->reset_count = ha->base_qpair->chip_reset;
4509 mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK;
4510 mcmd->qpair = ha->base_qpair;
4512 rc = ha->tgt.tgt_ops->handle_tmr(mcmd, unpacked_lun, mcmd->tmr_func,
4513 le16_to_cpu(iocb->u.isp2x.seq_id));
4515 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060,
4516 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
4518 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
4525 /* ha->hardware_lock supposed to be held on entry */
4526 static int qlt_abort_task(struct scsi_qla_host *vha,
4527 struct imm_ntfy_from_isp *iocb)
4529 struct qla_hw_data *ha = vha->hw;
4530 struct fc_port *sess;
4532 unsigned long flags;
4534 loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb);
4536 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
4537 sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
4538 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
4541 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025,
4542 "qla_target(%d): task abort for unexisting "
4543 "session\n", vha->vp_idx);
4544 return qlt_sched_sess_work(vha->vha_tgt.qla_tgt,
4545 QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb));
4548 return __qlt_abort_task(vha, iocb, sess);
4551 void qlt_logo_completion_handler(fc_port_t *fcport, int rc)
4553 if (rc != MBS_COMMAND_COMPLETE) {
4554 ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093,
4555 "%s: se_sess %p / sess %p from"
4556 " port %8phC loop_id %#04x s_id %02x:%02x:%02x"
4557 " LOGO failed: %#x\n",
4561 fcport->port_name, fcport->loop_id,
4562 fcport->d_id.b.domain, fcport->d_id.b.area,
4563 fcport->d_id.b.al_pa, rc);
4566 fcport->logout_completed = 1;
4570 * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list)
4572 * Schedules sessions with matching port_id/loop_id but different wwn for
4573 * deletion. Returns existing session with matching wwn if present.
4577 qlt_find_sess_invalidate_other(scsi_qla_host_t *vha, uint64_t wwn,
4578 port_id_t port_id, uint16_t loop_id, struct fc_port **conflict_sess)
4580 struct fc_port *sess = NULL, *other_sess;
4583 *conflict_sess = NULL;
4585 list_for_each_entry(other_sess, &vha->vp_fcports, list) {
4587 other_wwn = wwn_to_u64(other_sess->port_name);
4589 if (wwn == other_wwn) {
4595 /* find other sess with nport_id collision */
4596 if (port_id.b24 == other_sess->d_id.b24) {
4597 if (loop_id != other_sess->loop_id) {
4598 ql_dbg(ql_dbg_disc, vha, 0x1000c,
4599 "Invalidating sess %p loop_id %d wwn %llx.\n",
4600 other_sess, other_sess->loop_id, other_wwn);
4603 * logout_on_delete is set by default, but another
4604 * session that has the same s_id/loop_id combo
4605 * might have cleared it when requested this session
4606 * deletion, so don't touch it
4608 qlt_schedule_sess_for_deletion(other_sess);
4611 * Another wwn used to have our s_id/loop_id
4612 * kill the session, but don't free the loop_id
4614 ql_dbg(ql_dbg_disc, vha, 0xf01b,
4615 "Invalidating sess %p loop_id %d wwn %llx.\n",
4616 other_sess, other_sess->loop_id, other_wwn);
4618 other_sess->keep_nport_handle = 1;
4619 if (other_sess->disc_state != DSC_DELETED)
4620 *conflict_sess = other_sess;
4621 qlt_schedule_sess_for_deletion(other_sess);
4626 /* find other sess with nport handle collision */
4627 if ((loop_id == other_sess->loop_id) &&
4628 (loop_id != FC_NO_LOOP_ID)) {
4629 ql_dbg(ql_dbg_disc, vha, 0x1000d,
4630 "Invalidating sess %p loop_id %d wwn %llx.\n",
4631 other_sess, other_sess->loop_id, other_wwn);
4633 /* Same loop_id but different s_id
4634 * Ok to kill and logout */
4635 qlt_schedule_sess_for_deletion(other_sess);
4642 /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */
4643 static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id)
4645 struct qla_tgt_sess_op *op;
4646 struct qla_tgt_cmd *cmd;
4649 unsigned long flags;
4651 key = (((u32)s_id->b.domain << 16) |
4652 ((u32)s_id->b.area << 8) |
4653 ((u32)s_id->b.al_pa));
4655 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4656 list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) {
4657 uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
4659 if (op_key == key) {
4665 list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
4666 uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
4668 if (op_key == key) {
4674 list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
4675 uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id);
4677 if (cmd_key == key) {
4682 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4687 static int qlt_handle_login(struct scsi_qla_host *vha,
4688 struct imm_ntfy_from_isp *iocb)
4690 struct fc_port *sess = NULL, *conflict_sess = NULL;
4693 uint16_t loop_id, wd3_lo;
4695 struct qlt_plogi_ack_t *pla;
4696 unsigned long flags;
4698 lockdep_assert_held(&vha->hw->hardware_lock);
4700 wwn = wwn_to_u64(iocb->u.isp24.port_name);
4702 port_id.b.domain = iocb->u.isp24.port_id[2];
4703 port_id.b.area = iocb->u.isp24.port_id[1];
4704 port_id.b.al_pa = iocb->u.isp24.port_id[0];
4705 port_id.b.rsvd_1 = 0;
4707 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
4709 /* Mark all stale commands sitting in qla_tgt_wq for deletion */
4710 abort_cmds_for_s_id(vha, &port_id);
4713 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4714 sess = qlt_find_sess_invalidate_other(vha, wwn,
4715 port_id, loop_id, &conflict_sess);
4716 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4718 ql_dbg(ql_dbg_disc, vha, 0xffff,
4719 "%s %d Term INOT due to WWN=0 lid=%d, NportID %06X ",
4720 __func__, __LINE__, loop_id, port_id.b24);
4721 qlt_send_term_imm_notif(vha, iocb, 1);
4725 if (IS_SW_RESV_ADDR(port_id)) {
4730 pla = qlt_plogi_ack_find_add(vha, &port_id, iocb);
4732 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
4733 "%s %d %8phC Term INOT due to mem alloc fail",
4735 iocb->u.isp24.port_name);
4736 qlt_send_term_imm_notif(vha, iocb, 1);
4740 if (conflict_sess) {
4741 conflict_sess->login_gen++;
4742 qlt_plogi_ack_link(vha, pla, conflict_sess,
4743 QLT_PLOGI_LINK_CONFLICT);
4748 ql_dbg(ql_dbg_disc, vha, 0xffff,
4749 "%s %d %8phC post new sess\n",
4750 __func__, __LINE__, iocb->u.isp24.port_name);
4751 if (iocb->u.isp24.status_subcode == ELS_PLOGI)
4752 qla24xx_post_newsess_work(vha, &port_id,
4753 iocb->u.isp24.port_name,
4754 iocb->u.isp24.u.plogi.node_name,
4757 qla24xx_post_newsess_work(vha, &port_id,
4758 iocb->u.isp24.port_name, NULL,
4764 if (sess->disc_state == DSC_UPD_FCPORT) {
4768 * Remote port registration is still going on from
4769 * previous login. Allow it to finish before we
4770 * accept the new login.
4772 sess->next_disc_state = DSC_DELETE_PEND;
4773 sec = jiffies_to_msecs(jiffies -
4774 sess->jiffies_at_registration) / 1000;
4775 if (sess->sec_since_registration < sec && sec &&
4777 sess->sec_since_registration = sec;
4778 ql_dbg(ql_dbg_disc, vha, 0xffff,
4779 "%s %8phC - Slow Rport registration (%d Sec)\n",
4780 __func__, sess->port_name, sec);
4783 if (!conflict_sess) {
4784 list_del(&pla->list);
4785 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4788 qlt_send_term_imm_notif(vha, iocb, 1);
4792 qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN);
4793 sess->d_id = port_id;
4796 if (iocb->u.isp24.status_subcode == ELS_PRLI) {
4797 sess->fw_login_state = DSC_LS_PRLI_PEND;
4799 sess->loop_id = loop_id;
4800 sess->d_id = port_id;
4801 sess->fw_login_state = DSC_LS_PRLI_PEND;
4802 wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo);
4805 sess->conf_compl_supported = 1;
4807 if ((wd3_lo & BIT_4) == 0)
4808 sess->port_type = FCT_INITIATOR;
4810 sess->port_type = FCT_TARGET;
4813 sess->fw_login_state = DSC_LS_PLOGI_PEND;
4816 ql_dbg(ql_dbg_disc, vha, 0x20f9,
4817 "%s %d %8phC DS %d\n",
4818 __func__, __LINE__, sess->port_name, sess->disc_state);
4820 switch (sess->disc_state) {
4822 case DSC_LOGIN_PEND:
4823 qlt_plogi_ack_unref(vha, pla);
4828 * Under normal circumstances we want to release nport handle
4829 * during LOGO process to avoid nport handle leaks inside FW.
4830 * The exception is when LOGO is done while another PLOGI with
4831 * the same nport handle is waiting as might be the case here.
4832 * Note: there is always a possibily of a race where session
4833 * deletion has already started for other reasons (e.g. ACL
4834 * removal) and now PLOGI arrives:
4835 * 1. if PLOGI arrived in FW after nport handle has been freed,
4836 * FW must have assigned this PLOGI a new/same handle and we
4837 * can proceed ACK'ing it as usual when session deletion
4839 * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT
4840 * bit reached it, the handle has now been released. We'll
4841 * get an error when we ACK this PLOGI. Nothing will be sent
4842 * back to initiator. Initiator should eventually retry
4843 * PLOGI and situation will correct itself.
4845 sess->keep_nport_handle = ((sess->loop_id == loop_id) &&
4846 (sess->d_id.b24 == port_id.b24));
4848 ql_dbg(ql_dbg_disc, vha, 0x20f9,
4849 "%s %d %8phC post del sess\n",
4850 __func__, __LINE__, sess->port_name);
4853 qlt_schedule_sess_for_deletion(sess);
4861 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4863 static int qlt_24xx_handle_els(struct scsi_qla_host *vha,
4864 struct imm_ntfy_from_isp *iocb)
4866 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4867 struct qla_hw_data *ha = vha->hw;
4868 struct fc_port *sess = NULL, *conflict_sess = NULL;
4874 unsigned long flags;
4876 lockdep_assert_held(&ha->hardware_lock);
4878 wwn = wwn_to_u64(iocb->u.isp24.port_name);
4880 port_id.b.domain = iocb->u.isp24.port_id[2];
4881 port_id.b.area = iocb->u.isp24.port_id[1];
4882 port_id.b.al_pa = iocb->u.isp24.port_id[0];
4883 port_id.b.rsvd_1 = 0;
4885 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
4887 ql_dbg(ql_dbg_disc, vha, 0xf026,
4888 "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n",
4889 vha->vp_idx, iocb->u.isp24.port_id[2],
4890 iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0],
4891 iocb->u.isp24.status_subcode, loop_id,
4892 iocb->u.isp24.port_name);
4894 /* res = 1 means ack at the end of thread
4895 * res = 0 means ack async/later.
4897 switch (iocb->u.isp24.status_subcode) {
4899 res = qlt_handle_login(vha, iocb);
4904 sess = qla2x00_find_fcport_by_wwpn(vha,
4905 iocb->u.isp24.port_name, 1);
4907 if (sess && sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]) {
4908 ql_dbg(ql_dbg_disc, vha, 0xffff,
4909 "%s %d %8phC Term PRLI due to PLOGI ACK not completed\n",
4911 iocb->u.isp24.port_name);
4912 qlt_send_term_imm_notif(vha, iocb, 1);
4916 res = qlt_handle_login(vha, iocb);
4920 if (IS_SW_RESV_ADDR(port_id)) {
4925 wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo);
4928 spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags);
4929 sess = qlt_find_sess_invalidate_other(vha, wwn, port_id,
4930 loop_id, &conflict_sess);
4931 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags);
4934 if (conflict_sess) {
4935 switch (conflict_sess->disc_state) {
4937 case DSC_DELETE_PEND:
4940 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b,
4941 "PRLI with conflicting sess %p port %8phC\n",
4942 conflict_sess, conflict_sess->port_name);
4943 conflict_sess->fw_login_state =
4944 DSC_LS_PORT_UNAVAIL;
4945 qlt_send_term_imm_notif(vha, iocb, 1);
4952 bool delete = false;
4955 spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags);
4956 switch (sess->fw_login_state) {
4957 case DSC_LS_PLOGI_PEND:
4958 case DSC_LS_PLOGI_COMP:
4959 case DSC_LS_PRLI_COMP:
4966 switch (sess->disc_state) {
4967 case DSC_UPD_FCPORT:
4968 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock,
4971 sec = jiffies_to_msecs(jiffies -
4972 sess->jiffies_at_registration)/1000;
4973 if (sess->sec_since_registration < sec && sec &&
4975 sess->sec_since_registration = sec;
4976 ql_dbg(ql_dbg_disc, sess->vha, 0xffff,
4977 "%s %8phC : Slow Rport registration(%d Sec)\n",
4978 __func__, sess->port_name, sec);
4980 qlt_send_term_imm_notif(vha, iocb, 1);
4983 case DSC_LOGIN_PEND:
4985 case DSC_LOGIN_COMPLETE:
4994 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock,
4997 * Impatient initiator sent PRLI before last
4998 * PLOGI could finish. Will force him to re-try,
4999 * while last one finishes.
5001 ql_log(ql_log_warn, sess->vha, 0xf095,
5002 "sess %p PRLI received, before plogi ack.\n",
5004 qlt_send_term_imm_notif(vha, iocb, 1);
5010 * This shouldn't happen under normal circumstances,
5011 * since we have deleted the old session during PLOGI
5013 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096,
5014 "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n",
5015 sess->loop_id, sess, iocb->u.isp24.nport_handle);
5018 sess->loop_id = loop_id;
5019 sess->d_id = port_id;
5020 sess->fw_login_state = DSC_LS_PRLI_PEND;
5023 sess->conf_compl_supported = 1;
5025 if ((wd3_lo & BIT_4) == 0)
5026 sess->port_type = FCT_INITIATOR;
5028 sess->port_type = FCT_TARGET;
5030 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags);
5032 res = 1; /* send notify ack */
5034 /* Make session global (not used in fabric mode) */
5035 if (ha->current_topology != ISP_CFG_F) {
5037 ql_dbg(ql_dbg_disc, vha, 0x20fa,
5038 "%s %d %8phC post nack\n",
5039 __func__, __LINE__, sess->port_name);
5040 qla24xx_post_nack_work(vha, sess, iocb,
5044 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5045 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5046 qla2xxx_wake_dpc(vha);
5050 ql_dbg(ql_dbg_disc, vha, 0x20fb,
5051 "%s %d %8phC post nack\n",
5052 __func__, __LINE__, sess->port_name);
5053 qla24xx_post_nack_work(vha, sess, iocb,
5061 if (le16_to_cpu(iocb->u.isp24.flags) &
5062 NOTIFY24XX_FLAGS_GLOBAL_TPRLO) {
5064 qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS);
5071 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
5072 sess = qla2x00_find_fcport_by_loopid(vha, loop_id);
5073 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
5077 sess->fw_login_state = DSC_LS_LOGO_PEND;
5078 sess->logo_ack_needed = 1;
5079 memcpy(sess->iocb, iocb, IOCB_SIZE);
5082 res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS);
5084 ql_dbg(ql_dbg_disc, vha, 0x20fc,
5085 "%s: logo %llx res %d sess %p ",
5086 __func__, wwn, res, sess);
5089 * cmd went upper layer, look for qlt_xmit_tm_rsp()
5090 * for LOGO_ACK & sess delete
5095 /* cmd did not go to upper layer. */
5097 qlt_schedule_sess_for_deletion(sess);
5100 /* else logo will be ack */
5106 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5108 if (tgt->link_reinit_iocb_pending) {
5109 qlt_send_notify_ack(ha->base_qpair,
5110 &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0);
5111 tgt->link_reinit_iocb_pending = 0;
5114 sess = qla2x00_find_fcport_by_wwpn(vha,
5115 iocb->u.isp24.port_name, 1);
5117 ql_dbg(ql_dbg_disc, vha, 0x20fd,
5118 "sess %p lid %d|%d DS %d LS %d\n",
5119 sess, sess->loop_id, loop_id,
5120 sess->disc_state, sess->fw_login_state);
5123 res = 1; /* send notify ack */
5127 case ELS_FLOGI: /* should never happen */
5129 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061,
5130 "qla_target(%d): Unsupported ELS command %x "
5131 "received\n", vha->vp_idx, iocb->u.isp24.status_subcode);
5132 res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS);
5136 ql_dbg(ql_dbg_disc, vha, 0xf026,
5137 "qla_target(%d): Exit ELS opcode: 0x%02x res %d\n",
5138 vha->vp_idx, iocb->u.isp24.status_subcode, res);
5144 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5146 static void qlt_handle_imm_notify(struct scsi_qla_host *vha,
5147 struct imm_ntfy_from_isp *iocb)
5149 struct qla_hw_data *ha = vha->hw;
5150 uint32_t add_flags = 0;
5151 int send_notify_ack = 1;
5154 lockdep_assert_held(&ha->hardware_lock);
5156 status = le16_to_cpu(iocb->u.isp2x.status);
5158 case IMM_NTFY_LIP_RESET:
5160 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032,
5161 "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
5162 vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle),
5163 iocb->u.isp24.status_subcode);
5165 if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0)
5166 send_notify_ack = 0;
5170 case IMM_NTFY_LIP_LINK_REINIT:
5172 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5174 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033,
5175 "qla_target(%d): LINK REINIT (loop %#x, "
5176 "subcode %x)\n", vha->vp_idx,
5177 le16_to_cpu(iocb->u.isp24.nport_handle),
5178 iocb->u.isp24.status_subcode);
5179 if (tgt->link_reinit_iocb_pending) {
5180 qlt_send_notify_ack(ha->base_qpair,
5181 &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0);
5183 memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb));
5184 tgt->link_reinit_iocb_pending = 1;
5186 * QLogic requires to wait after LINK REINIT for possible
5187 * PDISC or ADISC ELS commands
5189 send_notify_ack = 0;
5193 case IMM_NTFY_PORT_LOGOUT:
5194 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034,
5195 "qla_target(%d): Port logout (loop "
5196 "%#x, subcode %x)\n", vha->vp_idx,
5197 le16_to_cpu(iocb->u.isp24.nport_handle),
5198 iocb->u.isp24.status_subcode);
5200 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0)
5201 send_notify_ack = 0;
5202 /* The sessions will be cleared in the callback, if needed */
5205 case IMM_NTFY_GLBL_TPRLO:
5206 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035,
5207 "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status);
5208 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0)
5209 send_notify_ack = 0;
5210 /* The sessions will be cleared in the callback, if needed */
5213 case IMM_NTFY_PORT_CONFIG:
5214 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036,
5215 "qla_target(%d): Port config changed (%x)\n", vha->vp_idx,
5217 if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0)
5218 send_notify_ack = 0;
5219 /* The sessions will be cleared in the callback, if needed */
5222 case IMM_NTFY_GLBL_LOGO:
5223 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a,
5224 "qla_target(%d): Link failure detected\n",
5226 /* I_T nexus loss */
5227 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0)
5228 send_notify_ack = 0;
5231 case IMM_NTFY_IOCB_OVERFLOW:
5232 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b,
5233 "qla_target(%d): Cannot provide requested "
5234 "capability (IOCB overflowed the immediate notify "
5235 "resource count)\n", vha->vp_idx);
5238 case IMM_NTFY_ABORT_TASK:
5239 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037,
5240 "qla_target(%d): Abort Task (S %08x I %#x -> "
5241 "L %#x)\n", vha->vp_idx,
5242 le16_to_cpu(iocb->u.isp2x.seq_id),
5243 GET_TARGET_ID(ha, (struct atio_from_isp *)iocb),
5244 le16_to_cpu(iocb->u.isp2x.lun));
5245 if (qlt_abort_task(vha, iocb) == 0)
5246 send_notify_ack = 0;
5249 case IMM_NTFY_RESOURCE:
5250 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c,
5251 "qla_target(%d): Out of resources, host %ld\n",
5252 vha->vp_idx, vha->host_no);
5255 case IMM_NTFY_MSG_RX:
5256 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038,
5257 "qla_target(%d): Immediate notify task %x\n",
5258 vha->vp_idx, iocb->u.isp2x.task_flags);
5262 if (qlt_24xx_handle_els(vha, iocb) == 0)
5263 send_notify_ack = 0;
5266 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d,
5267 "qla_target(%d): Received unknown immediate "
5268 "notify status %x\n", vha->vp_idx, status);
5272 if (send_notify_ack)
5273 qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0,
5278 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5279 * This function sends busy to ISP 2xxx or 24xx.
5281 static int __qlt_send_busy(struct qla_qpair *qpair,
5282 struct atio_from_isp *atio, uint16_t status)
5284 struct scsi_qla_host *vha = qpair->vha;
5285 struct ctio7_to_24xx *ctio24;
5286 struct qla_hw_data *ha = vha->hw;
5288 struct fc_port *sess = NULL;
5289 unsigned long flags;
5293 id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
5295 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
5296 sess = qla2x00_find_fcport_by_nportid(vha, &id, 1);
5297 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
5299 qlt_send_term_exchange(qpair, NULL, atio, 1, 0);
5302 /* Sending marker isn't necessary, since we called from ISR */
5304 pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL);
5306 ql_dbg(ql_dbg_io, vha, 0x3063,
5307 "qla_target(%d): %s failed: unable to allocate "
5308 "request packet", vha->vp_idx, __func__);
5312 qpair->tgt_counters.num_q_full_sent++;
5313 pkt->entry_count = 1;
5314 pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
5316 ctio24 = (struct ctio7_to_24xx *)pkt;
5317 ctio24->entry_type = CTIO_TYPE7;
5318 ctio24->nport_handle = cpu_to_le16(sess->loop_id);
5319 ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
5320 ctio24->vp_index = vha->vp_idx;
5321 ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
5322 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
5323 temp = (atio->u.isp24.attr << 9) |
5324 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS |
5325 CTIO7_FLAGS_DONT_RET_CTIO;
5326 ctio24->u.status1.flags = cpu_to_le16(temp);
5328 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
5329 * if the explicit conformation is used.
5331 ctio24->u.status1.ox_id =
5332 cpu_to_le16(be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
5333 ctio24->u.status1.scsi_status = cpu_to_le16(status);
5335 ctio24->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio));
5337 if (ctio24->u.status1.residual != 0)
5338 ctio24->u.status1.scsi_status |= cpu_to_le16(SS_RESIDUAL_UNDER);
5340 /* Memory Barrier */
5342 if (qpair->reqq_start_iocbs)
5343 qpair->reqq_start_iocbs(qpair);
5345 qla2x00_start_iocbs(vha, qpair->req);
5350 * This routine is used to allocate a command for either a QFull condition
5351 * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go
5355 qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
5356 struct atio_from_isp *atio, uint16_t status, int qfull)
5358 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5359 struct qla_hw_data *ha = vha->hw;
5360 struct fc_port *sess;
5361 struct qla_tgt_cmd *cmd;
5362 unsigned long flags;
5364 if (unlikely(tgt->tgt_stop)) {
5365 ql_dbg(ql_dbg_io, vha, 0x300a,
5366 "New command while device %p is shutting down\n", tgt);
5370 if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) {
5371 vha->hw->tgt.num_qfull_cmds_dropped++;
5372 if (vha->hw->tgt.num_qfull_cmds_dropped >
5373 vha->qla_stats.stat_max_qfull_cmds_dropped)
5374 vha->qla_stats.stat_max_qfull_cmds_dropped =
5375 vha->hw->tgt.num_qfull_cmds_dropped;
5377 ql_dbg(ql_dbg_io, vha, 0x3068,
5378 "qla_target(%d): %s: QFull CMD dropped[%d]\n",
5379 vha->vp_idx, __func__,
5380 vha->hw->tgt.num_qfull_cmds_dropped);
5382 qlt_chk_exch_leak_thresh_hold(vha);
5386 sess = ha->tgt.tgt_ops->find_sess_by_s_id
5387 (vha, atio->u.isp24.fcp_hdr.s_id);
5391 cmd = ha->tgt.tgt_ops->get_cmd(sess);
5393 ql_dbg(ql_dbg_io, vha, 0x3009,
5394 "qla_target(%d): %s: Allocation of cmd failed\n",
5395 vha->vp_idx, __func__);
5397 vha->hw->tgt.num_qfull_cmds_dropped++;
5398 if (vha->hw->tgt.num_qfull_cmds_dropped >
5399 vha->qla_stats.stat_max_qfull_cmds_dropped)
5400 vha->qla_stats.stat_max_qfull_cmds_dropped =
5401 vha->hw->tgt.num_qfull_cmds_dropped;
5403 qlt_chk_exch_leak_thresh_hold(vha);
5407 qlt_incr_num_pend_cmds(vha);
5408 INIT_LIST_HEAD(&cmd->cmd_list);
5409 memcpy(&cmd->atio, atio, sizeof(*atio));
5411 cmd->tgt = vha->vha_tgt.qla_tgt;
5413 cmd->reset_count = ha->base_qpair->chip_reset;
5415 cmd->qpair = ha->base_qpair;
5419 /* NOTE: borrowing the state field to carry the status */
5420 cmd->state = status;
5422 cmd->term_exchg = 1;
5424 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5425 list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list);
5427 vha->hw->tgt.num_qfull_cmds_alloc++;
5428 if (vha->hw->tgt.num_qfull_cmds_alloc >
5429 vha->qla_stats.stat_max_qfull_cmds_alloc)
5430 vha->qla_stats.stat_max_qfull_cmds_alloc =
5431 vha->hw->tgt.num_qfull_cmds_alloc;
5432 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5436 qlt_free_qfull_cmds(struct qla_qpair *qpair)
5438 struct scsi_qla_host *vha = qpair->vha;
5439 struct qla_hw_data *ha = vha->hw;
5440 unsigned long flags;
5441 struct qla_tgt_cmd *cmd, *tcmd;
5442 struct list_head free_list, q_full_list;
5445 if (list_empty(&ha->tgt.q_full_list))
5448 INIT_LIST_HEAD(&free_list);
5449 INIT_LIST_HEAD(&q_full_list);
5451 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5452 if (list_empty(&ha->tgt.q_full_list)) {
5453 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5457 list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list);
5458 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5460 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
5461 list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) {
5463 /* cmd->state is a borrowed field to hold status */
5464 rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state);
5465 else if (cmd->term_exchg)
5466 rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio);
5472 ql_dbg(ql_dbg_io, vha, 0x3006,
5473 "%s: busy sent for ox_id[%04x]\n", __func__,
5474 be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
5475 else if (cmd->term_exchg)
5476 ql_dbg(ql_dbg_io, vha, 0x3007,
5477 "%s: Term exchg sent for ox_id[%04x]\n", __func__,
5478 be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
5480 ql_dbg(ql_dbg_io, vha, 0x3008,
5481 "%s: Unexpected cmd in QFull list %p\n", __func__,
5484 list_move_tail(&cmd->cmd_list, &free_list);
5486 /* piggy back on hardware_lock for protection */
5487 vha->hw->tgt.num_qfull_cmds_alloc--;
5489 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
5493 list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) {
5494 list_del(&cmd->cmd_list);
5495 /* This cmd was never sent to TCM. There is no need
5496 * to schedule free or call free_cmd
5501 if (!list_empty(&q_full_list)) {
5502 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5503 list_splice(&q_full_list, &vha->hw->tgt.q_full_list);
5504 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5511 qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio,
5515 struct scsi_qla_host *vha = qpair->vha;
5517 rc = __qlt_send_busy(qpair, atio, status);
5519 qlt_alloc_qfull_cmd(vha, atio, status, 1);
5523 qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair,
5524 struct atio_from_isp *atio, uint8_t ha_locked)
5526 struct qla_hw_data *ha = vha->hw;
5527 unsigned long flags;
5529 if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha))
5533 spin_lock_irqsave(&ha->hardware_lock, flags);
5534 qlt_send_busy(qpair, atio, qla_sam_status);
5536 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5541 /* ha->hardware_lock supposed to be held on entry */
5542 /* called via callback from qla2xxx */
5543 static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha,
5544 struct atio_from_isp *atio, uint8_t ha_locked)
5546 struct qla_hw_data *ha = vha->hw;
5547 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5549 unsigned long flags = 0;
5551 if (unlikely(tgt == NULL)) {
5552 ql_dbg(ql_dbg_tgt, vha, 0x3064,
5553 "ATIO pkt, but no tgt (ha %p)", ha);
5557 * In tgt_stop mode we also should allow all requests to pass.
5558 * Otherwise, some commands can stuck.
5561 tgt->atio_irq_cmd_count++;
5563 switch (atio->u.raw.entry_type) {
5565 if (unlikely(atio->u.isp24.exchange_addr ==
5566 cpu_to_le32(ATIO_EXCHANGE_ADDRESS_UNKNOWN))) {
5567 ql_dbg(ql_dbg_io, vha, 0x3065,
5568 "qla_target(%d): ATIO_TYPE7 "
5569 "received with UNKNOWN exchange address, "
5570 "sending QUEUE_FULL\n", vha->vp_idx);
5572 spin_lock_irqsave(&ha->hardware_lock, flags);
5573 qlt_send_busy(ha->base_qpair, atio, qla_sam_status);
5575 spin_unlock_irqrestore(&ha->hardware_lock,
5580 if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) {
5581 rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair,
5584 tgt->atio_irq_cmd_count--;
5587 rc = qlt_handle_cmd_for_atio(vha, atio);
5589 rc = qlt_handle_task_mgmt(vha, atio);
5591 if (unlikely(rc != 0)) {
5593 spin_lock_irqsave(&ha->hardware_lock, flags);
5596 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5597 "qla_target: Unable to send command to target\n");
5600 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5601 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
5602 qlt_send_term_exchange(ha->base_qpair, NULL,
5606 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5607 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5609 qlt_send_busy(ha->base_qpair, atio,
5613 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5614 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5616 qlt_send_busy(ha->base_qpair, atio,
5621 spin_unlock_irqrestore(&ha->hardware_lock,
5626 case IMMED_NOTIFY_TYPE:
5628 if (unlikely(atio->u.isp2x.entry_status != 0)) {
5629 ql_dbg(ql_dbg_tgt, vha, 0xe05b,
5630 "qla_target(%d): Received ATIO packet %x "
5631 "with error status %x\n", vha->vp_idx,
5632 atio->u.raw.entry_type,
5633 atio->u.isp2x.entry_status);
5636 ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO");
5639 spin_lock_irqsave(&ha->hardware_lock, flags);
5640 qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio);
5642 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5647 ql_dbg(ql_dbg_tgt, vha, 0xe05c,
5648 "qla_target(%d): Received unknown ATIO atio "
5649 "type %x\n", vha->vp_idx, atio->u.raw.entry_type);
5653 tgt->atio_irq_cmd_count--;
5657 * qpair lock is assume to be held
5658 * rc = 0 : send terminate & abts respond
5659 * rc != 0: do not send term & abts respond
5661 static int qlt_chk_unresolv_exchg(struct scsi_qla_host *vha,
5662 struct qla_qpair *qpair, struct abts_resp_from_24xx_fw *entry)
5664 struct qla_hw_data *ha = vha->hw;
5668 * Detect unresolved exchange. If the same ABTS is unable
5669 * to terminate an existing command and the same ABTS loops
5670 * between FW & Driver, then force FW dump. Under 1 jiff,
5671 * we should see multiple loops.
5673 if (qpair->retry_term_exchg_addr == entry->exchange_addr_to_abort &&
5674 qpair->retry_term_jiff == jiffies) {
5675 /* found existing exchange */
5676 qpair->retry_term_cnt++;
5677 if (qpair->retry_term_cnt >= 5) {
5679 qpair->retry_term_cnt = 0;
5680 ql_log(ql_log_warn, vha, 0xffff,
5681 "Unable to send ABTS Respond. Dumping firmware.\n");
5682 ql_dump_buffer(ql_dbg_tgt_mgt + ql_dbg_buffer,
5683 vha, 0xffff, (uint8_t *)entry, sizeof(*entry));
5685 if (qpair == ha->base_qpair)
5686 ha->isp_ops->fw_dump(vha);
5688 qla2xxx_dump_fw(vha);
5690 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5691 qla2xxx_wake_dpc(vha);
5693 } else if (qpair->retry_term_jiff != jiffies) {
5694 qpair->retry_term_exchg_addr = entry->exchange_addr_to_abort;
5695 qpair->retry_term_cnt = 0;
5696 qpair->retry_term_jiff = jiffies;
5703 static void qlt_handle_abts_completion(struct scsi_qla_host *vha,
5704 struct rsp_que *rsp, response_t *pkt)
5706 struct abts_resp_from_24xx_fw *entry =
5707 (struct abts_resp_from_24xx_fw *)pkt;
5708 u32 h = pkt->handle & ~QLA_TGT_HANDLE_MASK;
5709 struct qla_tgt_mgmt_cmd *mcmd;
5710 struct qla_hw_data *ha = vha->hw;
5712 mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, pkt);
5713 if (mcmd == NULL && h != QLA_TGT_SKIP_HANDLE) {
5714 ql_dbg(ql_dbg_async, vha, 0xe064,
5715 "qla_target(%d): ABTS Comp without mcmd\n",
5722 vha->vha_tgt.qla_tgt->abts_resp_expected--;
5724 ql_dbg(ql_dbg_tgt, vha, 0xe038,
5725 "ABTS_RESP_24XX: compl_status %x\n",
5726 entry->compl_status);
5728 if (le16_to_cpu(entry->compl_status) != ABTS_RESP_COMPL_SUCCESS) {
5729 if (le32_to_cpu(entry->error_subcode1) == 0x1E &&
5730 le32_to_cpu(entry->error_subcode2) == 0) {
5731 if (qlt_chk_unresolv_exchg(vha, rsp->qpair, entry)) {
5732 ha->tgt.tgt_ops->free_mcmd(mcmd);
5735 qlt_24xx_retry_term_exchange(vha, rsp->qpair,
5738 ql_dbg(ql_dbg_tgt, vha, 0xe063,
5739 "qla_target(%d): ABTS_RESP_24XX failed %x (subcode %x:%x)",
5740 vha->vp_idx, entry->compl_status,
5741 entry->error_subcode1,
5742 entry->error_subcode2);
5743 ha->tgt.tgt_ops->free_mcmd(mcmd);
5746 ha->tgt.tgt_ops->free_mcmd(mcmd);
5750 /* ha->hardware_lock supposed to be held on entry */
5751 /* called via callback from qla2xxx */
5752 static void qlt_response_pkt(struct scsi_qla_host *vha,
5753 struct rsp_que *rsp, response_t *pkt)
5755 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5757 if (unlikely(tgt == NULL)) {
5758 ql_dbg(ql_dbg_tgt, vha, 0xe05d,
5759 "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n",
5760 vha->vp_idx, pkt->entry_type, vha->hw);
5765 * In tgt_stop mode we also should allow all requests to pass.
5766 * Otherwise, some commands can stuck.
5769 switch (pkt->entry_type) {
5773 struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
5775 qlt_do_ctio_completion(vha, rsp, entry->handle,
5776 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5781 case ACCEPT_TGT_IO_TYPE:
5783 struct atio_from_isp *atio = (struct atio_from_isp *)pkt;
5786 if (atio->u.isp2x.status !=
5787 cpu_to_le16(ATIO_CDB_VALID)) {
5788 ql_dbg(ql_dbg_tgt, vha, 0xe05e,
5789 "qla_target(%d): ATIO with error "
5790 "status %x received\n", vha->vp_idx,
5791 le16_to_cpu(atio->u.isp2x.status));
5795 rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1);
5799 rc = qlt_handle_cmd_for_atio(vha, atio);
5800 if (unlikely(rc != 0)) {
5803 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5804 "qla_target: Unable to send command to target\n");
5807 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5808 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
5809 qlt_send_term_exchange(rsp->qpair, NULL,
5813 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5814 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5816 qlt_send_busy(rsp->qpair, atio,
5820 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5821 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5823 qlt_send_busy(rsp->qpair, atio,
5831 case CONTINUE_TGT_IO_TYPE:
5833 struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
5835 qlt_do_ctio_completion(vha, rsp, entry->handle,
5836 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5843 struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
5845 qlt_do_ctio_completion(vha, rsp, entry->handle,
5846 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5851 case IMMED_NOTIFY_TYPE:
5852 ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n");
5853 qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt);
5856 case NOTIFY_ACK_TYPE:
5857 if (tgt->notify_ack_expected > 0) {
5858 struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
5860 ql_dbg(ql_dbg_tgt, vha, 0xe036,
5861 "NOTIFY_ACK seq %08x status %x\n",
5862 le16_to_cpu(entry->u.isp2x.seq_id),
5863 le16_to_cpu(entry->u.isp2x.status));
5864 tgt->notify_ack_expected--;
5865 if (entry->u.isp2x.status !=
5866 cpu_to_le16(NOTIFY_ACK_SUCCESS)) {
5867 ql_dbg(ql_dbg_tgt, vha, 0xe061,
5868 "qla_target(%d): NOTIFY_ACK "
5869 "failed %x\n", vha->vp_idx,
5870 le16_to_cpu(entry->u.isp2x.status));
5873 ql_dbg(ql_dbg_tgt, vha, 0xe062,
5874 "qla_target(%d): Unexpected NOTIFY_ACK received\n",
5879 case ABTS_RECV_24XX:
5880 ql_dbg(ql_dbg_tgt, vha, 0xe037,
5881 "ABTS_RECV_24XX: instance %d\n", vha->vp_idx);
5882 qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt);
5885 case ABTS_RESP_24XX:
5886 if (tgt->abts_resp_expected > 0) {
5887 qlt_handle_abts_completion(vha, rsp, pkt);
5889 ql_dbg(ql_dbg_tgt, vha, 0xe064,
5890 "qla_target(%d): Unexpected ABTS_RESP_24XX "
5891 "received\n", vha->vp_idx);
5896 ql_dbg(ql_dbg_tgt, vha, 0xe065,
5897 "qla_target(%d): Received unknown response pkt "
5898 "type %x\n", vha->vp_idx, pkt->entry_type);
5905 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5907 void qlt_async_event(uint16_t code, struct scsi_qla_host *vha,
5910 struct qla_hw_data *ha = vha->hw;
5911 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5914 if (!tgt || tgt->tgt_stop || tgt->tgt_stopped)
5917 if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) &&
5921 * In tgt_stop mode we also should allow all requests to pass.
5922 * Otherwise, some commands can stuck.
5927 case MBA_RESET: /* Reset */
5928 case MBA_SYSTEM_ERR: /* System Error */
5929 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
5930 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
5931 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a,
5932 "qla_target(%d): System error async event %#x "
5933 "occurred", vha->vp_idx, code);
5935 case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */
5936 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5941 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b,
5942 "qla_target(%d): Async LOOP_UP occurred "
5943 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx,
5944 mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
5945 if (tgt->link_reinit_iocb_pending) {
5946 qlt_send_notify_ack(ha->base_qpair,
5947 &tgt->link_reinit_iocb,
5949 tgt->link_reinit_iocb_pending = 0;
5954 case MBA_LIP_OCCURRED:
5957 case MBA_RSCN_UPDATE:
5958 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c,
5959 "qla_target(%d): Async event %#x occurred "
5960 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code,
5961 mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
5964 case MBA_REJECTED_FCP_CMD:
5965 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017,
5966 "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)",
5968 mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
5970 if (mailbox[3] == 1) {
5971 /* exchange starvation. */
5972 vha->hw->exch_starvation++;
5973 if (vha->hw->exch_starvation > 5) {
5974 ql_log(ql_log_warn, vha, 0xd03a,
5975 "Exchange starvation-. Resetting RISC\n");
5977 vha->hw->exch_starvation = 0;
5978 if (IS_P3P_TYPE(vha->hw))
5979 set_bit(FCOE_CTX_RESET_NEEDED,
5982 set_bit(ISP_ABORT_NEEDED,
5984 qla2xxx_wake_dpc(vha);
5989 case MBA_PORT_UPDATE:
5990 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d,
5991 "qla_target(%d): Port update async event %#x "
5992 "occurred: updating the ports database (m[0]=%x, m[1]=%x, "
5993 "m[2]=%x, m[3]=%x)", vha->vp_idx, code,
5994 mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
5996 login_code = mailbox[2];
5997 if (login_code == 0x4) {
5998 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e,
5999 "Async MB 2: Got PLOGI Complete\n");
6000 vha->hw->exch_starvation = 0;
6001 } else if (login_code == 0x7)
6002 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f,
6003 "Async MB 2: Port Logged Out\n");
6011 static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha,
6014 fc_port_t *fcport, *tfcp, *del;
6016 unsigned long flags;
6019 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6021 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f,
6022 "qla_target(%d): Allocation of tmp FC port failed",
6027 fcport->loop_id = loop_id;
6029 rc = qla24xx_gpdb_wait(vha, fcport, 0);
6030 if (rc != QLA_SUCCESS) {
6031 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070,
6032 "qla_target(%d): Failed to retrieve fcport "
6033 "information -- get_port_database() returned %x "
6034 "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id);
6040 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6041 tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1);
6044 tfcp->d_id = fcport->d_id;
6045 tfcp->port_type = fcport->port_type;
6046 tfcp->supported_classes = fcport->supported_classes;
6047 tfcp->flags |= fcport->flags;
6048 tfcp->scan_state = QLA_FCPORT_FOUND;
6053 if (vha->hw->current_topology == ISP_CFG_F)
6054 fcport->flags |= FCF_FABRIC_DEVICE;
6056 list_add_tail(&fcport->list, &vha->vp_fcports);
6057 if (!IS_SW_RESV_ADDR(fcport->d_id))
6058 vha->fcport_count++;
6059 fcport->login_gen++;
6060 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
6061 fcport->login_succ = 1;
6065 fcport->deleted = 0;
6066 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6068 switch (vha->host->active_mode) {
6069 case MODE_INITIATOR:
6072 if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) {
6073 qla24xx_sched_upd_fcport(fcport);
6075 ql_dbg(ql_dbg_disc, vha, 0x20ff,
6076 "%s %d %8phC post gpsc fcp_cnt %d\n",
6077 __func__, __LINE__, fcport->port_name, vha->fcport_count);
6078 qla24xx_post_gpsc_work(vha, fcport);
6088 qla2x00_free_fcport(del);
6093 /* Must be called under tgt_mutex */
6094 static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *vha,
6097 struct fc_port *sess = NULL;
6098 fc_port_t *fcport = NULL;
6099 int rc, global_resets;
6100 uint16_t loop_id = 0;
6102 if (s_id.domain == 0xFF && s_id.area == 0xFC) {
6104 * This is Domain Controller, so it should be
6105 * OK to drop SCSI commands from it.
6107 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042,
6108 "Unable to find initiator with S_ID %x:%x:%x",
6109 s_id.domain, s_id.area, s_id.al_pa);
6113 mutex_lock(&vha->vha_tgt.tgt_mutex);
6117 atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count);
6119 rc = qla24xx_get_loop_id(vha, s_id, &loop_id);
6121 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6123 ql_log(ql_log_info, vha, 0xf071,
6124 "qla_target(%d): Unable to find "
6125 "initiator with S_ID %x:%x:%x",
6126 vha->vp_idx, s_id.domain, s_id.area, s_id.al_pa);
6128 if (rc == -ENOENT) {
6129 qlt_port_logo_t logo;
6131 logo.id = be_to_port_id(s_id);
6133 qlt_send_first_logo(vha, &logo);
6139 fcport = qlt_get_port_database(vha, loop_id);
6141 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6145 if (global_resets !=
6146 atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) {
6147 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043,
6148 "qla_target(%d): global reset during session discovery "
6149 "(counter was %d, new %d), retrying", vha->vp_idx,
6151 atomic_read(&vha->vha_tgt.
6152 qla_tgt->tgt_global_resets_count));
6156 sess = qlt_create_sess(vha, fcport, true);
6158 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6163 static void qlt_abort_work(struct qla_tgt *tgt,
6164 struct qla_tgt_sess_work_param *prm)
6166 struct scsi_qla_host *vha = tgt->vha;
6167 struct qla_hw_data *ha = vha->hw;
6168 struct fc_port *sess = NULL;
6169 unsigned long flags = 0, flags2 = 0;
6173 spin_lock_irqsave(&ha->tgt.sess_lock, flags2);
6178 s_id = le_id_to_be(prm->abts.fcp_hdr_le.s_id);
6180 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
6182 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6184 sess = qlt_make_local_sess(vha, s_id);
6185 /* sess has got an extra creation ref */
6187 spin_lock_irqsave(&ha->tgt.sess_lock, flags2);
6191 if (sess->deleted) {
6196 if (!kref_get_unless_zero(&sess->sess_kref)) {
6197 ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c,
6198 "%s: kref_get fail %8phC \n",
6199 __func__, sess->port_name);
6205 rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess);
6206 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6208 ha->tgt.tgt_ops->put_sess(sess);
6215 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6218 spin_lock_irqsave(&ha->hardware_lock, flags);
6219 qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts,
6220 FCP_TMF_REJECTED, false);
6221 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6224 static void qlt_tmr_work(struct qla_tgt *tgt,
6225 struct qla_tgt_sess_work_param *prm)
6227 struct atio_from_isp *a = &prm->tm_iocb2;
6228 struct scsi_qla_host *vha = tgt->vha;
6229 struct qla_hw_data *ha = vha->hw;
6230 struct fc_port *sess;
6231 unsigned long flags;
6238 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
6243 s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id;
6244 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
6246 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6248 sess = qlt_make_local_sess(vha, s_id);
6249 /* sess has got an extra creation ref */
6251 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
6255 if (sess->deleted) {
6259 if (!kref_get_unless_zero(&sess->sess_kref)) {
6260 ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020,
6261 "%s: kref_get fail %8phC\n",
6262 __func__, sess->port_name);
6268 fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
6270 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
6272 rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
6273 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6275 ha->tgt.tgt_ops->put_sess(sess);
6282 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6284 qlt_send_term_exchange(ha->base_qpair, NULL, &prm->tm_iocb2, 1, 0);
6287 static void qlt_sess_work_fn(struct work_struct *work)
6289 struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work);
6290 struct scsi_qla_host *vha = tgt->vha;
6291 unsigned long flags;
6293 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt);
6295 spin_lock_irqsave(&tgt->sess_work_lock, flags);
6296 while (!list_empty(&tgt->sess_works_list)) {
6297 struct qla_tgt_sess_work_param *prm = list_entry(
6298 tgt->sess_works_list.next, typeof(*prm),
6299 sess_works_list_entry);
6302 * This work can be scheduled on several CPUs at time, so we
6303 * must delete the entry to eliminate double processing
6305 list_del(&prm->sess_works_list_entry);
6307 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
6309 switch (prm->type) {
6310 case QLA_TGT_SESS_WORK_ABORT:
6311 qlt_abort_work(tgt, prm);
6313 case QLA_TGT_SESS_WORK_TM:
6314 qlt_tmr_work(tgt, prm);
6321 spin_lock_irqsave(&tgt->sess_work_lock, flags);
6325 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
6328 /* Must be called under tgt_host_action_mutex */
6329 int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha)
6331 struct qla_tgt *tgt;
6333 struct qla_qpair_hint *h;
6335 if (!QLA_TGT_MODE_ENABLED())
6338 if (!IS_TGT_MODE_CAPABLE(ha)) {
6339 ql_log(ql_log_warn, base_vha, 0xe070,
6340 "This adapter does not support target mode.\n");
6344 ql_dbg(ql_dbg_tgt, base_vha, 0xe03b,
6345 "Registering target for host %ld(%p).\n", base_vha->host_no, ha);
6347 BUG_ON(base_vha->vha_tgt.qla_tgt != NULL);
6349 tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL);
6351 ql_dbg(ql_dbg_tgt, base_vha, 0xe066,
6352 "Unable to allocate struct qla_tgt\n");
6356 tgt->qphints = kcalloc(ha->max_qpairs + 1,
6357 sizeof(struct qla_qpair_hint),
6359 if (!tgt->qphints) {
6361 ql_log(ql_log_warn, base_vha, 0x0197,
6362 "Unable to allocate qpair hints.\n");
6366 if (!(base_vha->host->hostt->supported_mode & MODE_TARGET))
6367 base_vha->host->hostt->supported_mode |= MODE_TARGET;
6369 rc = btree_init64(&tgt->lun_qpair_map);
6371 kfree(tgt->qphints);
6373 ql_log(ql_log_info, base_vha, 0x0198,
6374 "Unable to initialize lun_qpair_map btree\n");
6377 h = &tgt->qphints[0];
6378 h->qpair = ha->base_qpair;
6379 INIT_LIST_HEAD(&h->hint_elem);
6380 h->cpuid = ha->base_qpair->cpuid;
6381 list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list);
6383 for (i = 0; i < ha->max_qpairs; i++) {
6384 unsigned long flags;
6386 struct qla_qpair *qpair = ha->queue_pair_map[i];
6388 h = &tgt->qphints[i + 1];
6389 INIT_LIST_HEAD(&h->hint_elem);
6392 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
6393 list_add_tail(&h->hint_elem, &qpair->hints_list);
6394 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
6395 h->cpuid = qpair->cpuid;
6400 tgt->vha = base_vha;
6401 init_waitqueue_head(&tgt->waitQ);
6402 INIT_LIST_HEAD(&tgt->del_sess_list);
6403 spin_lock_init(&tgt->sess_work_lock);
6404 INIT_WORK(&tgt->sess_work, qlt_sess_work_fn);
6405 INIT_LIST_HEAD(&tgt->sess_works_list);
6406 atomic_set(&tgt->tgt_global_resets_count, 0);
6408 base_vha->vha_tgt.qla_tgt = tgt;
6410 ql_dbg(ql_dbg_tgt, base_vha, 0xe067,
6411 "qla_target(%d): using 64 Bit PCI addressing",
6414 tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3);
6416 mutex_lock(&qla_tgt_mutex);
6417 list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist);
6418 mutex_unlock(&qla_tgt_mutex);
6420 if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target)
6421 ha->tgt.tgt_ops->add_target(base_vha);
6426 /* Must be called under tgt_host_action_mutex */
6427 int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha)
6429 if (!vha->vha_tgt.qla_tgt)
6432 if (vha->fc_vport) {
6433 qlt_release(vha->vha_tgt.qla_tgt);
6437 /* free left over qfull cmds */
6438 qlt_init_term_exchange(vha);
6440 ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)",
6442 qlt_release(vha->vha_tgt.qla_tgt);
6447 void qlt_remove_target_resources(struct qla_hw_data *ha)
6449 struct scsi_qla_host *node;
6452 btree_for_each_safe32(&ha->tgt.host_map, key, node)
6453 btree_remove32(&ha->tgt.host_map, key);
6455 btree_destroy32(&ha->tgt.host_map);
6458 static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn,
6461 pr_debug("qla2xxx HW vha->node_name: %8phC\n", vha->node_name);
6462 pr_debug("qla2xxx HW vha->port_name: %8phC\n", vha->port_name);
6463 put_unaligned_be64(wwpn, b);
6464 pr_debug("qla2xxx passed configfs WWPN: %8phC\n", b);
6468 * qlt_lport_register - register lport with external module
6470 * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
6471 * @phys_wwpn: physical port WWPN
6472 * @npiv_wwpn: NPIV WWPN
6473 * @npiv_wwnn: NPIV WWNN
6474 * @callback: lport initialization callback for tcm_qla2xxx code
6476 int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn,
6477 u64 npiv_wwpn, u64 npiv_wwnn,
6478 int (*callback)(struct scsi_qla_host *, void *, u64, u64))
6480 struct qla_tgt *tgt;
6481 struct scsi_qla_host *vha;
6482 struct qla_hw_data *ha;
6483 struct Scsi_Host *host;
6484 unsigned long flags;
6488 mutex_lock(&qla_tgt_mutex);
6489 list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) {
6497 if (!(host->hostt->supported_mode & MODE_TARGET))
6500 if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
6503 spin_lock_irqsave(&ha->hardware_lock, flags);
6504 if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) {
6505 pr_debug("MODE_TARGET already active on qla2xxx(%d)\n",
6507 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6510 if (tgt->tgt_stop) {
6511 pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n",
6513 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6516 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6518 if (!scsi_host_get(host)) {
6519 ql_dbg(ql_dbg_tgt, vha, 0xe068,
6520 "Unable to scsi_host_get() for"
6521 " qla2xxx scsi_host\n");
6524 qlt_lport_dump(vha, phys_wwpn, b);
6526 if (memcmp(vha->port_name, b, WWN_SIZE)) {
6527 scsi_host_put(host);
6530 rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn);
6532 scsi_host_put(host);
6534 mutex_unlock(&qla_tgt_mutex);
6537 mutex_unlock(&qla_tgt_mutex);
6541 EXPORT_SYMBOL(qlt_lport_register);
6544 * qlt_lport_deregister - Degister lport
6546 * @vha: Registered scsi_qla_host pointer
6548 void qlt_lport_deregister(struct scsi_qla_host *vha)
6550 struct qla_hw_data *ha = vha->hw;
6551 struct Scsi_Host *sh = vha->host;
6553 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
6555 vha->vha_tgt.target_lport_ptr = NULL;
6556 ha->tgt.tgt_ops = NULL;
6558 * Release the Scsi_Host reference for the underlying qla2xxx host
6562 EXPORT_SYMBOL(qlt_lport_deregister);
6564 /* Must be called under HW lock */
6565 void qlt_set_mode(struct scsi_qla_host *vha)
6567 switch (vha->qlini_mode) {
6568 case QLA2XXX_INI_MODE_DISABLED:
6569 case QLA2XXX_INI_MODE_EXCLUSIVE:
6570 vha->host->active_mode = MODE_TARGET;
6572 case QLA2XXX_INI_MODE_ENABLED:
6573 vha->host->active_mode = MODE_INITIATOR;
6575 case QLA2XXX_INI_MODE_DUAL:
6576 vha->host->active_mode = MODE_DUAL;
6583 /* Must be called under HW lock */
6584 static void qlt_clear_mode(struct scsi_qla_host *vha)
6586 switch (vha->qlini_mode) {
6587 case QLA2XXX_INI_MODE_DISABLED:
6588 vha->host->active_mode = MODE_UNKNOWN;
6590 case QLA2XXX_INI_MODE_EXCLUSIVE:
6591 vha->host->active_mode = MODE_INITIATOR;
6593 case QLA2XXX_INI_MODE_ENABLED:
6594 case QLA2XXX_INI_MODE_DUAL:
6595 vha->host->active_mode = MODE_INITIATOR;
6603 * qla_tgt_enable_vha - NO LOCK HELD
6605 * host_reset, bring up w/ Target Mode Enabled
6608 qlt_enable_vha(struct scsi_qla_host *vha)
6610 struct qla_hw_data *ha = vha->hw;
6611 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
6612 unsigned long flags;
6613 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6616 ql_dbg(ql_dbg_tgt, vha, 0xe069,
6617 "Unable to locate qla_tgt pointer from"
6618 " struct qla_hw_data\n");
6622 if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
6625 if (ha->tgt.num_act_qpairs > ha->max_qpairs)
6626 ha->tgt.num_act_qpairs = ha->max_qpairs;
6627 spin_lock_irqsave(&ha->hardware_lock, flags);
6628 tgt->tgt_stopped = 0;
6630 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6632 mutex_lock(&ha->optrom_mutex);
6633 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021,
6636 qla24xx_disable_vp(vha);
6637 qla24xx_enable_vp(vha);
6639 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6640 qla2xxx_wake_dpc(base_vha);
6641 WARN_ON_ONCE(qla2x00_wait_for_hba_online(base_vha) !=
6644 mutex_unlock(&ha->optrom_mutex);
6646 EXPORT_SYMBOL(qlt_enable_vha);
6649 * qla_tgt_disable_vha - NO LOCK HELD
6651 * Disable Target Mode and reset the adapter
6653 static void qlt_disable_vha(struct scsi_qla_host *vha)
6655 struct qla_hw_data *ha = vha->hw;
6656 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
6657 unsigned long flags;
6660 ql_dbg(ql_dbg_tgt, vha, 0xe06a,
6661 "Unable to locate qla_tgt pointer from"
6662 " struct qla_hw_data\n");
6667 spin_lock_irqsave(&ha->hardware_lock, flags);
6668 qlt_clear_mode(vha);
6669 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6671 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6672 qla2xxx_wake_dpc(vha);
6675 * We are expecting the offline state.
6676 * QLA_FUNCTION_FAILED means that adapter is offline.
6678 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
6679 ql_dbg(ql_dbg_tgt, vha, 0xe081,
6680 "adapter is offline\n");
6684 * Called from qla_init.c:qla24xx_vport_create() contex to setup
6685 * the target mode specific struct scsi_qla_host and struct qla_hw_data
6689 qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha)
6691 vha->vha_tgt.qla_tgt = NULL;
6693 mutex_init(&vha->vha_tgt.tgt_mutex);
6694 mutex_init(&vha->vha_tgt.tgt_host_action_mutex);
6696 qlt_clear_mode(vha);
6699 * NOTE: Currently the value is kept the same for <24xx and
6700 * >=24xx ISPs. If it is necessary to change it,
6701 * the check should be added for specific ISPs,
6702 * assigning the value appropriately.
6704 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
6706 qlt_add_target(ha, vha);
6710 qlt_rff_id(struct scsi_qla_host *vha)
6714 * FC-4 Feature bit 0 indicates target functionality to the name server.
6716 if (qla_tgt_mode_enabled(vha)) {
6717 fc4_feature = BIT_0;
6718 } else if (qla_ini_mode_enabled(vha)) {
6719 fc4_feature = BIT_1;
6720 } else if (qla_dual_mode_enabled(vha))
6721 fc4_feature = BIT_0 | BIT_1;
6727 * qlt_init_atio_q_entries() - Initializes ATIO queue entries.
6730 * Beginning of ATIO ring has initialization control block already built
6731 * by nvram config routine.
6733 * Returns 0 on success.
6736 qlt_init_atio_q_entries(struct scsi_qla_host *vha)
6738 struct qla_hw_data *ha = vha->hw;
6740 struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring;
6742 if (qla_ini_mode_enabled(vha))
6745 for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) {
6746 pkt->u.raw.signature = cpu_to_le32(ATIO_PROCESSED);
6753 * qlt_24xx_process_atio_queue() - Process ATIO queue entries.
6754 * @ha: SCSI driver HA context
6757 qlt_24xx_process_atio_queue(struct scsi_qla_host *vha, uint8_t ha_locked)
6759 struct qla_hw_data *ha = vha->hw;
6760 struct atio_from_isp *pkt;
6763 if (!ha->flags.fw_started)
6766 while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) ||
6767 fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) {
6768 pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
6769 cnt = pkt->u.raw.entry_count;
6771 if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) {
6773 * This packet is corrupted. The header + payload
6774 * can not be trusted. There is no point in passing
6777 ql_log(ql_log_warn, vha, 0xd03c,
6778 "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n",
6779 &pkt->u.isp24.fcp_hdr.s_id,
6780 be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id),
6781 pkt->u.isp24.exchange_addr, pkt);
6783 adjust_corrupted_atio(pkt);
6784 qlt_send_term_exchange(ha->base_qpair, NULL, pkt,
6787 qlt_24xx_atio_pkt_all_vps(vha,
6788 (struct atio_from_isp *)pkt, ha_locked);
6791 for (i = 0; i < cnt; i++) {
6792 ha->tgt.atio_ring_index++;
6793 if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) {
6794 ha->tgt.atio_ring_index = 0;
6795 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
6797 ha->tgt.atio_ring_ptr++;
6799 pkt->u.raw.signature = cpu_to_le32(ATIO_PROCESSED);
6800 pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
6805 /* Adjust ring index */
6806 wrt_reg_dword(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index);
6810 qlt_24xx_config_rings(struct scsi_qla_host *vha)
6812 struct qla_hw_data *ha = vha->hw;
6813 struct qla_msix_entry *msix = &ha->msix_entries[2];
6814 struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb;
6816 if (!QLA_TGT_MODE_ENABLED())
6819 wrt_reg_dword(ISP_ATIO_Q_IN(vha), 0);
6820 wrt_reg_dword(ISP_ATIO_Q_OUT(vha), 0);
6821 rd_reg_dword(ISP_ATIO_Q_OUT(vha));
6823 if (ha->flags.msix_enabled) {
6824 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
6825 if (IS_QLA2071(ha)) {
6826 /* 4 ports Baker: Enable Interrupt Handshake */
6828 icb->firmware_options_2 |= cpu_to_le32(BIT_26);
6830 icb->msix_atio = cpu_to_le16(msix->entry);
6831 icb->firmware_options_2 &= cpu_to_le32(~BIT_26);
6833 ql_dbg(ql_dbg_init, vha, 0xf072,
6834 "Registering ICB vector 0x%x for atio que.\n",
6839 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
6841 icb->firmware_options_2 |= cpu_to_le32(BIT_26);
6842 ql_dbg(ql_dbg_init, vha, 0xf072,
6843 "%s: Use INTx for ATIOQ.\n", __func__);
6849 qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv)
6851 struct qla_hw_data *ha = vha->hw;
6854 if (!QLA_TGT_MODE_ENABLED())
6857 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
6858 if (!ha->tgt.saved_set) {
6859 /* We save only once */
6860 ha->tgt.saved_exchange_count = nv->exchange_count;
6861 ha->tgt.saved_firmware_options_1 =
6862 nv->firmware_options_1;
6863 ha->tgt.saved_firmware_options_2 =
6864 nv->firmware_options_2;
6865 ha->tgt.saved_firmware_options_3 =
6866 nv->firmware_options_3;
6867 ha->tgt.saved_set = 1;
6870 if (qla_tgt_mode_enabled(vha))
6871 nv->exchange_count = cpu_to_le16(0xFFFF);
6873 nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
6875 /* Enable target mode */
6876 nv->firmware_options_1 |= cpu_to_le32(BIT_4);
6878 /* Disable ini mode, if requested */
6879 if (qla_tgt_mode_enabled(vha))
6880 nv->firmware_options_1 |= cpu_to_le32(BIT_5);
6882 /* Disable Full Login after LIP */
6883 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
6884 /* Enable initial LIP */
6885 nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
6886 if (ql2xtgt_tape_enable)
6887 /* Enable FC Tape support */
6888 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6890 /* Disable FC Tape support */
6891 nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
6893 /* Disable Full Login after LIP */
6894 nv->host_p &= cpu_to_le32(~BIT_10);
6897 * clear BIT 15 explicitly as we have seen at least
6898 * a couple of instances where this was set and this
6899 * was causing the firmware to not be initialized.
6901 nv->firmware_options_1 &= cpu_to_le32(~BIT_15);
6902 /* Enable target PRLI control */
6903 nv->firmware_options_2 |= cpu_to_le32(BIT_14);
6905 if (IS_QLA25XX(ha)) {
6906 /* Change Loop-prefer to Pt-Pt */
6907 tmp = ~(BIT_4|BIT_5|BIT_6);
6908 nv->firmware_options_2 &= cpu_to_le32(tmp);
6910 nv->firmware_options_2 |= cpu_to_le32(tmp);
6913 if (ha->tgt.saved_set) {
6914 nv->exchange_count = ha->tgt.saved_exchange_count;
6915 nv->firmware_options_1 =
6916 ha->tgt.saved_firmware_options_1;
6917 nv->firmware_options_2 =
6918 ha->tgt.saved_firmware_options_2;
6919 nv->firmware_options_3 =
6920 ha->tgt.saved_firmware_options_3;
6925 if (ha->base_qpair->enable_class_2) {
6926 if (vha->flags.init_done)
6927 fc_host_supported_classes(vha->host) =
6928 FC_COS_CLASS2 | FC_COS_CLASS3;
6930 nv->firmware_options_2 |= cpu_to_le32(BIT_8);
6932 if (vha->flags.init_done)
6933 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
6935 nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
6940 qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha,
6941 struct init_cb_24xx *icb)
6943 struct qla_hw_data *ha = vha->hw;
6945 if (!QLA_TGT_MODE_ENABLED())
6948 if (ha->tgt.node_name_set) {
6949 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
6950 icb->firmware_options_1 |= cpu_to_le32(BIT_14);
6955 qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv)
6957 struct qla_hw_data *ha = vha->hw;
6960 if (!QLA_TGT_MODE_ENABLED())
6963 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
6964 if (!ha->tgt.saved_set) {
6965 /* We save only once */
6966 ha->tgt.saved_exchange_count = nv->exchange_count;
6967 ha->tgt.saved_firmware_options_1 =
6968 nv->firmware_options_1;
6969 ha->tgt.saved_firmware_options_2 =
6970 nv->firmware_options_2;
6971 ha->tgt.saved_firmware_options_3 =
6972 nv->firmware_options_3;
6973 ha->tgt.saved_set = 1;
6976 if (qla_tgt_mode_enabled(vha))
6977 nv->exchange_count = cpu_to_le16(0xFFFF);
6979 nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
6981 /* Enable target mode */
6982 nv->firmware_options_1 |= cpu_to_le32(BIT_4);
6984 /* Disable ini mode, if requested */
6985 if (qla_tgt_mode_enabled(vha))
6986 nv->firmware_options_1 |= cpu_to_le32(BIT_5);
6987 /* Disable Full Login after LIP */
6988 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
6989 /* Enable initial LIP */
6990 nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
6992 * clear BIT 15 explicitly as we have seen at
6993 * least a couple of instances where this was set
6994 * and this was causing the firmware to not be
6997 nv->firmware_options_1 &= cpu_to_le32(~BIT_15);
6998 if (ql2xtgt_tape_enable)
6999 /* Enable FC tape support */
7000 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7002 /* Disable FC tape support */
7003 nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
7005 /* Disable Full Login after LIP */
7006 nv->host_p &= cpu_to_le32(~BIT_10);
7007 /* Enable target PRLI control */
7008 nv->firmware_options_2 |= cpu_to_le32(BIT_14);
7010 /* Change Loop-prefer to Pt-Pt */
7011 tmp = ~(BIT_4|BIT_5|BIT_6);
7012 nv->firmware_options_2 &= cpu_to_le32(tmp);
7014 nv->firmware_options_2 |= cpu_to_le32(tmp);
7016 if (ha->tgt.saved_set) {
7017 nv->exchange_count = ha->tgt.saved_exchange_count;
7018 nv->firmware_options_1 =
7019 ha->tgt.saved_firmware_options_1;
7020 nv->firmware_options_2 =
7021 ha->tgt.saved_firmware_options_2;
7022 nv->firmware_options_3 =
7023 ha->tgt.saved_firmware_options_3;
7028 if (ha->base_qpair->enable_class_2) {
7029 if (vha->flags.init_done)
7030 fc_host_supported_classes(vha->host) =
7031 FC_COS_CLASS2 | FC_COS_CLASS3;
7033 nv->firmware_options_2 |= cpu_to_le32(BIT_8);
7035 if (vha->flags.init_done)
7036 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
7038 nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
7043 qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha,
7044 struct init_cb_81xx *icb)
7046 struct qla_hw_data *ha = vha->hw;
7048 if (!QLA_TGT_MODE_ENABLED())
7051 if (ha->tgt.node_name_set) {
7052 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
7053 icb->firmware_options_1 |= cpu_to_le32(BIT_14);
7058 qlt_83xx_iospace_config(struct qla_hw_data *ha)
7060 if (!QLA_TGT_MODE_ENABLED())
7063 ha->msix_count += 1; /* For ATIO Q */
7068 qlt_modify_vp_config(struct scsi_qla_host *vha,
7069 struct vp_config_entry_24xx *vpmod)
7071 /* enable target mode. Bit5 = 1 => disable */
7072 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7073 vpmod->options_idx1 &= ~BIT_5;
7075 /* Disable ini mode, if requested. bit4 = 1 => disable */
7076 if (qla_tgt_mode_enabled(vha))
7077 vpmod->options_idx1 &= ~BIT_4;
7081 qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha)
7085 if (!QLA_TGT_MODE_ENABLED())
7088 if ((ql2xenablemsix == 0) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
7090 ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in;
7091 ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out;
7093 ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in;
7094 ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out;
7097 mutex_init(&base_vha->vha_tgt.tgt_mutex);
7098 mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex);
7100 INIT_LIST_HEAD(&base_vha->unknown_atio_list);
7101 INIT_DELAYED_WORK(&base_vha->unknown_atio_work,
7102 qlt_unknown_atio_work_fn);
7104 qlt_clear_mode(base_vha);
7106 rc = btree_init32(&ha->tgt.host_map);
7108 ql_log(ql_log_info, base_vha, 0xd03d,
7109 "Unable to initialize ha->host_map btree\n");
7111 qlt_update_vp_map(base_vha, SET_VP_IDX);
7115 qla83xx_msix_atio_q(int irq, void *dev_id)
7117 struct rsp_que *rsp;
7118 scsi_qla_host_t *vha;
7119 struct qla_hw_data *ha;
7120 unsigned long flags;
7122 rsp = (struct rsp_que *) dev_id;
7124 vha = pci_get_drvdata(ha->pdev);
7126 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
7128 qlt_24xx_process_atio_queue(vha, 0);
7130 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
7136 qlt_handle_abts_recv_work(struct work_struct *work)
7138 struct qla_tgt_sess_op *op = container_of(work,
7139 struct qla_tgt_sess_op, work);
7140 scsi_qla_host_t *vha = op->vha;
7141 struct qla_hw_data *ha = vha->hw;
7142 unsigned long flags;
7144 if (qla2x00_reset_active(vha) ||
7145 (op->chip_reset != ha->base_qpair->chip_reset))
7148 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
7149 qlt_24xx_process_atio_queue(vha, 0);
7150 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
7152 spin_lock_irqsave(&ha->hardware_lock, flags);
7153 qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio);
7154 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7160 qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp,
7163 struct qla_tgt_sess_op *op;
7165 op = kzalloc(sizeof(*op), GFP_ATOMIC);
7168 /* do not reach for ATIO queue here. This is best effort err
7169 * recovery at this point.
7171 qlt_response_pkt_all_vps(vha, rsp, pkt);
7175 memcpy(&op->atio, pkt, sizeof(*pkt));
7177 op->chip_reset = vha->hw->base_qpair->chip_reset;
7179 INIT_WORK(&op->work, qlt_handle_abts_recv_work);
7180 queue_work(qla_tgt_wq, &op->work);
7185 qlt_mem_alloc(struct qla_hw_data *ha)
7187 if (!QLA_TGT_MODE_ENABLED())
7190 ha->tgt.tgt_vp_map = kcalloc(MAX_MULTI_ID_FABRIC,
7191 sizeof(struct qla_tgt_vp_map),
7193 if (!ha->tgt.tgt_vp_map)
7196 ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev,
7197 (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp),
7198 &ha->tgt.atio_dma, GFP_KERNEL);
7199 if (!ha->tgt.atio_ring) {
7200 kfree(ha->tgt.tgt_vp_map);
7207 qlt_mem_free(struct qla_hw_data *ha)
7209 if (!QLA_TGT_MODE_ENABLED())
7212 if (ha->tgt.atio_ring) {
7213 dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) *
7214 sizeof(struct atio_from_isp), ha->tgt.atio_ring,
7217 ha->tgt.atio_ring = NULL;
7218 ha->tgt.atio_dma = 0;
7219 kfree(ha->tgt.tgt_vp_map);
7220 ha->tgt.tgt_vp_map = NULL;
7223 /* vport_slock to be held by the caller */
7225 qlt_update_vp_map(struct scsi_qla_host *vha, int cmd)
7231 if (!QLA_TGT_MODE_ENABLED())
7234 key = vha->d_id.b24;
7238 vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha;
7241 slot = btree_lookup32(&vha->hw->tgt.host_map, key);
7243 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018,
7244 "Save vha in host_map %p %06x\n", vha, key);
7245 rc = btree_insert32(&vha->hw->tgt.host_map,
7246 key, vha, GFP_ATOMIC);
7248 ql_log(ql_log_info, vha, 0xd03e,
7249 "Unable to insert s_id into host_map: %06x\n",
7253 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019,
7254 "replace existing vha in host_map %p %06x\n", vha, key);
7255 btree_update32(&vha->hw->tgt.host_map, key, vha);
7258 vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL;
7261 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a,
7262 "clear vha in host_map %p %06x\n", vha, key);
7263 slot = btree_lookup32(&vha->hw->tgt.host_map, key);
7265 btree_remove32(&vha->hw->tgt.host_map, key);
7271 void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id)
7274 if (!vha->d_id.b24) {
7276 qlt_update_vp_map(vha, SET_AL_PA);
7277 } else if (vha->d_id.b24 != id.b24) {
7278 qlt_update_vp_map(vha, RESET_AL_PA);
7280 qlt_update_vp_map(vha, SET_AL_PA);
7284 static int __init qlt_parse_ini_mode(void)
7286 if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0)
7287 ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE;
7288 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0)
7289 ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED;
7290 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0)
7291 ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED;
7292 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0)
7293 ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL;
7300 int __init qlt_init(void)
7304 BUILD_BUG_ON(sizeof(struct ctio7_to_24xx) != 64);
7305 BUILD_BUG_ON(sizeof(struct ctio_to_2xxx) != 64);
7307 if (!qlt_parse_ini_mode()) {
7308 ql_log(ql_log_fatal, NULL, 0xe06b,
7309 "qlt_parse_ini_mode() failed\n");
7313 if (!QLA_TGT_MODE_ENABLED())
7316 qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep",
7317 sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct
7318 qla_tgt_mgmt_cmd), 0, NULL);
7319 if (!qla_tgt_mgmt_cmd_cachep) {
7320 ql_log(ql_log_fatal, NULL, 0xd04b,
7321 "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
7325 qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep",
7326 sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t),
7329 if (!qla_tgt_plogi_cachep) {
7330 ql_log(ql_log_fatal, NULL, 0xe06d,
7331 "kmem_cache_create for qla_tgt_plogi_cachep failed\n");
7333 goto out_mgmt_cmd_cachep;
7336 qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab,
7337 mempool_free_slab, qla_tgt_mgmt_cmd_cachep);
7338 if (!qla_tgt_mgmt_cmd_mempool) {
7339 ql_log(ql_log_fatal, NULL, 0xe06e,
7340 "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
7342 goto out_plogi_cachep;
7345 qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0);
7347 ql_log(ql_log_fatal, NULL, 0xe06f,
7348 "alloc_workqueue for qla_tgt_wq failed\n");
7350 goto out_cmd_mempool;
7353 * Return 1 to signal that initiator-mode is being disabled
7355 return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0;
7358 mempool_destroy(qla_tgt_mgmt_cmd_mempool);
7360 kmem_cache_destroy(qla_tgt_plogi_cachep);
7361 out_mgmt_cmd_cachep:
7362 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep);
7368 if (!QLA_TGT_MODE_ENABLED())
7371 destroy_workqueue(qla_tgt_wq);
7372 mempool_destroy(qla_tgt_mgmt_cmd_mempool);
7373 kmem_cache_destroy(qla_tgt_plogi_cachep);
7374 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep);