1 // SPDX-License-Identifier: GPL-2.0-only
3 * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx
5 * based on qla2x00t.c code:
7 * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
8 * Copyright (C) 2004 - 2005 Leonid Stoljar
9 * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
10 * Copyright (C) 2006 - 2010 ID7 Ltd.
12 * Forward port and refactoring to modern qla2xxx and target/configfs
14 * Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/types.h>
20 #include <linux/blkdev.h>
21 #include <linux/interrupt.h>
22 #include <linux/pci.h>
23 #include <linux/delay.h>
24 #include <linux/list.h>
25 #include <linux/workqueue.h>
26 #include <asm/unaligned.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_tcq.h>
30 #include <target/target_core_base.h>
31 #include <target/target_core_fabric.h>
34 #include "qla_target.h"
36 static int ql2xtgt_tape_enable;
37 module_param(ql2xtgt_tape_enable, int, S_IRUGO|S_IWUSR);
38 MODULE_PARM_DESC(ql2xtgt_tape_enable,
39 "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER.");
41 static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED;
42 module_param(qlini_mode, charp, S_IRUGO);
43 MODULE_PARM_DESC(qlini_mode,
44 "Determines when initiator mode will be enabled. Possible values: "
45 "\"exclusive\" - initiator mode will be enabled on load, "
46 "disabled on enabling target mode and then on disabling target mode "
48 "\"disabled\" - initiator mode will never be enabled; "
49 "\"dual\" - Initiator Modes will be enabled. Target Mode can be activated "
51 "\"enabled\" (default) - initiator mode will always stay enabled.");
53 static int ql_dm_tgt_ex_pct = 0;
54 module_param(ql_dm_tgt_ex_pct, int, S_IRUGO|S_IWUSR);
55 MODULE_PARM_DESC(ql_dm_tgt_ex_pct,
56 "For Dual Mode (qlini_mode=dual), this parameter determines "
57 "the percentage of exchanges/cmds FW will allocate resources "
61 module_param(ql2xuctrlirq, int, 0644);
62 MODULE_PARM_DESC(ql2xuctrlirq,
63 "User to control IRQ placement via smp_affinity."
64 "Valid with qlini_mode=disabled."
65 "1(default): enable");
67 int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE;
69 static int qla_sam_status = SAM_STAT_BUSY;
70 static int tc_sam_status = SAM_STAT_TASK_SET_FULL; /* target core */
73 * From scsi/fc/fc_fcp.h
75 enum fcp_resp_rsp_codes {
77 FCP_DATA_LEN_INVALID = 1,
78 FCP_CMND_FIELDS_INVALID = 2,
79 FCP_DATA_PARAM_MISMATCH = 3,
82 FCP_TMF_INVALID_LUN = 9,
86 * fc_pri_ta from scsi/fc/fc_fcp.h
88 #define FCP_PTA_SIMPLE 0 /* simple task attribute */
89 #define FCP_PTA_HEADQ 1 /* head of queue task attribute */
90 #define FCP_PTA_ORDERED 2 /* ordered task attribute */
91 #define FCP_PTA_ACA 4 /* auto. contingent allegiance */
92 #define FCP_PTA_MASK 7 /* mask for task attribute field */
93 #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */
94 #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */
97 * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which
98 * must be called under HW lock and could unlock/lock it inside.
99 * It isn't an issue, since in the current implementation on the time when
100 * those functions are called:
102 * - Either context is IRQ and only IRQ handler can modify HW data,
103 * including rings related fields,
105 * - Or access to target mode variables from struct qla_tgt doesn't
106 * cross those functions boundaries, except tgt_stop, which
107 * additionally protected by irq_cmd_count.
109 /* Predefs for callbacks handed to qla2xxx LLD */
110 static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha,
111 struct atio_from_isp *pkt, uint8_t);
112 static void qlt_response_pkt(struct scsi_qla_host *ha, struct rsp_que *rsp,
114 static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun,
115 int fn, void *iocb, int flags);
116 static void qlt_send_term_exchange(struct qla_qpair *, struct qla_tgt_cmd
117 *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort);
118 static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
119 struct atio_from_isp *atio, uint16_t status, int qfull);
120 static void qlt_disable_vha(struct scsi_qla_host *vha);
121 static void qlt_clear_tgt_db(struct qla_tgt *tgt);
122 static void qlt_send_notify_ack(struct qla_qpair *qpair,
123 struct imm_ntfy_from_isp *ntfy,
124 uint32_t add_flags, uint16_t resp_code, int resp_code_valid,
125 uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan);
126 static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
127 struct imm_ntfy_from_isp *imm, int ha_locked);
128 static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha,
129 fc_port_t *fcport, bool local);
130 void qlt_unreg_sess(struct fc_port *sess);
131 static void qlt_24xx_handle_abts(struct scsi_qla_host *,
132 struct abts_recv_from_24xx *);
133 static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *,
135 static int qlt_check_reserve_free_req(struct qla_qpair *qpair, uint32_t);
136 static inline uint32_t qlt_make_handle(struct qla_qpair *);
141 static struct kmem_cache *qla_tgt_mgmt_cmd_cachep;
142 struct kmem_cache *qla_tgt_plogi_cachep;
143 static mempool_t *qla_tgt_mgmt_cmd_mempool;
144 static struct workqueue_struct *qla_tgt_wq;
145 static DEFINE_MUTEX(qla_tgt_mutex);
146 static LIST_HEAD(qla_tgt_glist);
148 static const char *prot_op_str(u32 prot_op)
151 case TARGET_PROT_NORMAL: return "NORMAL";
152 case TARGET_PROT_DIN_INSERT: return "DIN_INSERT";
153 case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT";
154 case TARGET_PROT_DIN_STRIP: return "DIN_STRIP";
155 case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP";
156 case TARGET_PROT_DIN_PASS: return "DIN_PASS";
157 case TARGET_PROT_DOUT_PASS: return "DOUT_PASS";
158 default: return "UNKNOWN";
162 /* This API intentionally takes dest as a parameter, rather than returning
163 * int value to avoid caller forgetting to issue wmb() after the store */
164 void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest)
166 scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev);
167 *dest = atomic_inc_return(&base_vha->generation_tick);
172 /* Might release hw lock, then reaquire!! */
173 static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked)
175 /* Send marker if required */
176 if (unlikely(vha->marker_needed != 0)) {
177 int rc = qla2x00_issue_marker(vha, vha_locked);
179 if (rc != QLA_SUCCESS) {
180 ql_dbg(ql_dbg_tgt, vha, 0xe03d,
181 "qla_target(%d): issue_marker() failed\n",
190 struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha,
193 struct scsi_qla_host *host;
196 if (vha->d_id.b.area == d_id.area &&
197 vha->d_id.b.domain == d_id.domain &&
198 vha->d_id.b.al_pa == d_id.al_pa)
201 key = be_to_port_id(d_id).b24;
203 host = btree_lookup32(&vha->hw->tgt.host_map, key);
205 ql_dbg(ql_dbg_tgt_mgt + ql_dbg_verbose, vha, 0xf005,
206 "Unable to find host %06x\n", key);
212 struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha,
215 struct qla_hw_data *ha = vha->hw;
217 if (vha->vp_idx == vp_idx)
220 BUG_ON(ha->tgt.tgt_vp_map == NULL);
221 if (likely(test_bit(vp_idx, ha->vp_idx_map)))
222 return ha->tgt.tgt_vp_map[vp_idx].vha;
227 static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha)
231 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
233 vha->hw->tgt.num_pend_cmds++;
234 if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds)
235 vha->qla_stats.stat_max_pend_cmds =
236 vha->hw->tgt.num_pend_cmds;
237 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
239 static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha)
243 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
244 vha->hw->tgt.num_pend_cmds--;
245 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
249 static void qlt_queue_unknown_atio(scsi_qla_host_t *vha,
250 struct atio_from_isp *atio, uint8_t ha_locked)
252 struct qla_tgt_sess_op *u;
253 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
257 ql_dbg(ql_dbg_async, vha, 0x502c,
258 "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped",
263 u = kzalloc(sizeof(*u), GFP_ATOMIC);
268 memcpy(&u->atio, atio, sizeof(*atio));
269 INIT_LIST_HEAD(&u->cmd_list);
271 spin_lock_irqsave(&vha->cmd_list_lock, flags);
272 list_add_tail(&u->cmd_list, &vha->unknown_atio_list);
273 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
275 schedule_delayed_work(&vha->unknown_atio_work, 1);
281 qlt_send_term_exchange(vha->hw->base_qpair, NULL, atio, ha_locked, 0);
285 static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha,
288 struct qla_tgt_sess_op *u, *t;
289 scsi_qla_host_t *host;
290 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
294 list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) {
296 ql_dbg(ql_dbg_async, vha, 0x502e,
297 "Freeing unknown %s %p, because of Abort\n",
299 qlt_send_term_exchange(vha->hw->base_qpair, NULL,
300 &u->atio, ha_locked, 0);
304 host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id);
306 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x502f,
307 "Requeuing unknown ATIO_TYPE7 %p\n", u);
308 qlt_24xx_atio_pkt(host, &u->atio, ha_locked);
309 } else if (tgt->tgt_stop) {
310 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503a,
311 "Freeing unknown %s %p, because tgt is being stopped\n",
313 qlt_send_term_exchange(vha->hw->base_qpair, NULL,
314 &u->atio, ha_locked, 0);
316 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d,
317 "Reschedule u %p, vha %p, host %p\n", u, vha, host);
320 schedule_delayed_work(&vha->unknown_atio_work,
327 spin_lock_irqsave(&vha->cmd_list_lock, flags);
328 list_del(&u->cmd_list);
329 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
334 void qlt_unknown_atio_work_fn(struct work_struct *work)
336 struct scsi_qla_host *vha = container_of(to_delayed_work(work),
337 struct scsi_qla_host, unknown_atio_work);
339 qlt_try_to_dequeue_unknown_atios(vha, 0);
342 static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *vha,
343 struct atio_from_isp *atio, uint8_t ha_locked)
345 ql_dbg(ql_dbg_tgt, vha, 0xe072,
346 "%s: qla_target(%d): type %x ox_id %04x\n",
347 __func__, vha->vp_idx, atio->u.raw.entry_type,
348 be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
350 switch (atio->u.raw.entry_type) {
353 struct scsi_qla_host *host = qlt_find_host_by_d_id(vha,
354 atio->u.isp24.fcp_hdr.d_id);
355 if (unlikely(NULL == host)) {
356 ql_dbg(ql_dbg_tgt, vha, 0xe03e,
357 "qla_target(%d): Received ATIO_TYPE7 "
358 "with unknown d_id %x:%x:%x\n", vha->vp_idx,
359 atio->u.isp24.fcp_hdr.d_id.domain,
360 atio->u.isp24.fcp_hdr.d_id.area,
361 atio->u.isp24.fcp_hdr.d_id.al_pa);
364 qlt_queue_unknown_atio(vha, atio, ha_locked);
367 if (unlikely(!list_empty(&vha->unknown_atio_list)))
368 qlt_try_to_dequeue_unknown_atios(vha, ha_locked);
370 qlt_24xx_atio_pkt(host, atio, ha_locked);
374 case IMMED_NOTIFY_TYPE:
376 struct scsi_qla_host *host = vha;
377 struct imm_ntfy_from_isp *entry =
378 (struct imm_ntfy_from_isp *)atio;
380 qlt_issue_marker(vha, ha_locked);
382 if ((entry->u.isp24.vp_index != 0xFF) &&
383 (entry->u.isp24.nport_handle != 0xFFFF)) {
384 host = qlt_find_host_by_vp_idx(vha,
385 entry->u.isp24.vp_index);
386 if (unlikely(!host)) {
387 ql_dbg(ql_dbg_tgt, vha, 0xe03f,
388 "qla_target(%d): Received "
389 "ATIO (IMMED_NOTIFY_TYPE) "
390 "with unknown vp_index %d\n",
391 vha->vp_idx, entry->u.isp24.vp_index);
395 qlt_24xx_atio_pkt(host, atio, ha_locked);
399 case VP_RPT_ID_IOCB_TYPE:
400 qla24xx_report_id_acquisition(vha,
401 (struct vp_rpt_id_entry_24xx *)atio);
406 struct abts_recv_from_24xx *entry =
407 (struct abts_recv_from_24xx *)atio;
408 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
412 if (unlikely(!host)) {
413 ql_dbg(ql_dbg_tgt, vha, 0xe00a,
414 "qla_target(%d): Response pkt (ABTS_RECV_24XX) "
415 "received, with unknown vp_index %d\n",
416 vha->vp_idx, entry->vp_index);
420 spin_lock_irqsave(&host->hw->hardware_lock, flags);
421 qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio);
423 spin_unlock_irqrestore(&host->hw->hardware_lock, flags);
427 /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */
430 ql_dbg(ql_dbg_tgt, vha, 0xe040,
431 "qla_target(%d): Received unknown ATIO atio "
432 "type %x\n", vha->vp_idx, atio->u.raw.entry_type);
439 void qlt_response_pkt_all_vps(struct scsi_qla_host *vha,
440 struct rsp_que *rsp, response_t *pkt)
442 switch (pkt->entry_type) {
444 ql_dbg(ql_dbg_tgt, vha, 0xe073,
445 "qla_target(%d):%s: CRC2 Response pkt\n",
446 vha->vp_idx, __func__);
450 struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
451 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
453 if (unlikely(!host)) {
454 ql_dbg(ql_dbg_tgt, vha, 0xe041,
455 "qla_target(%d): Response pkt (CTIO_TYPE7) "
456 "received, with unknown vp_index %d\n",
457 vha->vp_idx, entry->vp_index);
460 qlt_response_pkt(host, rsp, pkt);
464 case IMMED_NOTIFY_TYPE:
466 struct scsi_qla_host *host = vha;
467 struct imm_ntfy_from_isp *entry =
468 (struct imm_ntfy_from_isp *)pkt;
470 host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index);
471 if (unlikely(!host)) {
472 ql_dbg(ql_dbg_tgt, vha, 0xe042,
473 "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
474 "received, with unknown vp_index %d\n",
475 vha->vp_idx, entry->u.isp24.vp_index);
478 qlt_response_pkt(host, rsp, pkt);
482 case NOTIFY_ACK_TYPE:
484 struct scsi_qla_host *host = vha;
485 struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
487 if (0xFF != entry->u.isp24.vp_index) {
488 host = qlt_find_host_by_vp_idx(vha,
489 entry->u.isp24.vp_index);
490 if (unlikely(!host)) {
491 ql_dbg(ql_dbg_tgt, vha, 0xe043,
492 "qla_target(%d): Response "
493 "pkt (NOTIFY_ACK_TYPE) "
494 "received, with unknown "
495 "vp_index %d\n", vha->vp_idx,
496 entry->u.isp24.vp_index);
500 qlt_response_pkt(host, rsp, pkt);
506 struct abts_recv_from_24xx *entry =
507 (struct abts_recv_from_24xx *)pkt;
508 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
510 if (unlikely(!host)) {
511 ql_dbg(ql_dbg_tgt, vha, 0xe044,
512 "qla_target(%d): Response pkt "
513 "(ABTS_RECV_24XX) received, with unknown "
514 "vp_index %d\n", vha->vp_idx, entry->vp_index);
517 qlt_response_pkt(host, rsp, pkt);
523 struct abts_resp_to_24xx *entry =
524 (struct abts_resp_to_24xx *)pkt;
525 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
527 if (unlikely(!host)) {
528 ql_dbg(ql_dbg_tgt, vha, 0xe045,
529 "qla_target(%d): Response pkt "
530 "(ABTS_RECV_24XX) received, with unknown "
531 "vp_index %d\n", vha->vp_idx, entry->vp_index);
534 qlt_response_pkt(host, rsp, pkt);
538 qlt_response_pkt(vha, rsp, pkt);
545 * All qlt_plogi_ack_t operations are protected by hardware_lock
547 static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport,
548 struct imm_ntfy_from_isp *ntfy, int type)
550 struct qla_work_evt *e;
552 e = qla2x00_alloc_work(vha, QLA_EVT_NACK);
554 return QLA_FUNCTION_FAILED;
556 e->u.nack.fcport = fcport;
557 e->u.nack.type = type;
558 memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp));
559 return qla2x00_post_work(vha, e);
562 static void qla2x00_async_nack_sp_done(srb_t *sp, int res)
564 struct scsi_qla_host *vha = sp->vha;
567 ql_dbg(ql_dbg_disc, vha, 0x20f2,
568 "Async done-%s res %x %8phC type %d\n",
569 sp->name, res, sp->fcport->port_name, sp->type);
571 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
572 sp->fcport->flags &= ~FCF_ASYNC_SENT;
573 sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
577 sp->fcport->login_gen++;
578 sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
579 sp->fcport->logout_on_delete = 1;
580 sp->fcport->plogi_nack_done_deadline = jiffies + HZ;
581 sp->fcport->send_els_logo = 0;
585 sp->fcport->fw_login_state = DSC_LS_PRLI_COMP;
586 sp->fcport->deleted = 0;
587 sp->fcport->send_els_logo = 0;
589 if (!sp->fcport->login_succ &&
590 !IS_SW_RESV_ADDR(sp->fcport->d_id)) {
591 sp->fcport->login_succ = 1;
594 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
595 qla24xx_sched_upd_fcport(sp->fcport);
596 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
598 sp->fcport->login_retry = 0;
599 sp->fcport->disc_state = DSC_LOGIN_COMPLETE;
600 sp->fcport->deleted = 0;
601 sp->fcport->logout_on_delete = 1;
606 sp->fcport->login_gen++;
607 sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
608 qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE);
611 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
616 int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport,
617 struct imm_ntfy_from_isp *ntfy, int type)
619 int rval = QLA_FUNCTION_FAILED;
623 fcport->flags |= FCF_ASYNC_SENT;
626 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
630 fcport->fw_login_state = DSC_LS_PRLI_PEND;
635 fcport->fw_login_state = DSC_LS_LOGO_PEND;
640 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
647 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
648 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
650 sp->u.iocb_cmd.u.nack.ntfy = ntfy;
651 sp->done = qla2x00_async_nack_sp_done;
653 ql_dbg(ql_dbg_disc, vha, 0x20f4,
654 "Async-%s %8phC hndl %x %s\n",
655 sp->name, fcport->port_name, sp->handle, c);
657 rval = qla2x00_start_sp(sp);
658 if (rval != QLA_SUCCESS)
666 fcport->flags &= ~FCF_ASYNC_SENT;
670 void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
674 switch (e->u.nack.type) {
676 t = e->u.nack.fcport;
677 flush_work(&t->del_work);
678 flush_work(&t->free_work);
679 mutex_lock(&vha->vha_tgt.tgt_mutex);
680 t = qlt_create_sess(vha, e->u.nack.fcport, 0);
681 mutex_unlock(&vha->vha_tgt.tgt_mutex);
683 ql_log(ql_log_info, vha, 0xd034,
684 "%s create sess success %p", __func__, t);
685 /* create sess has an extra kref */
686 vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport);
690 qla24xx_async_notify_ack(vha, e->u.nack.fcport,
691 (struct imm_ntfy_from_isp *)e->u.nack.iocb, e->u.nack.type);
694 void qla24xx_delete_sess_fn(struct work_struct *work)
696 fc_port_t *fcport = container_of(work, struct fc_port, del_work);
697 struct qla_hw_data *ha = fcport->vha->hw;
699 if (fcport->se_sess) {
700 ha->tgt.tgt_ops->shutdown_sess(fcport);
701 ha->tgt.tgt_ops->put_sess(fcport);
703 qlt_unreg_sess(fcport);
708 * Called from qla2x00_reg_remote_port()
710 void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport)
712 struct qla_hw_data *ha = vha->hw;
713 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
714 struct fc_port *sess = fcport;
717 if (!vha->hw->tgt.tgt_ops)
720 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
722 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
726 if (fcport->disc_state == DSC_DELETE_PEND) {
727 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
731 if (!sess->se_sess) {
732 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
734 mutex_lock(&vha->vha_tgt.tgt_mutex);
735 sess = qlt_create_sess(vha, fcport, false);
736 mutex_unlock(&vha->vha_tgt.tgt_mutex);
738 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
740 if (fcport->fw_login_state == DSC_LS_PRLI_COMP) {
741 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
745 if (!kref_get_unless_zero(&sess->sess_kref)) {
746 ql_dbg(ql_dbg_disc, vha, 0x2107,
747 "%s: kref_get fail sess %8phC \n",
748 __func__, sess->port_name);
749 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
753 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c,
754 "qla_target(%u): %ssession for port %8phC "
755 "(loop ID %d) reappeared\n", vha->vp_idx,
756 sess->local ? "local " : "", sess->port_name, sess->loop_id);
758 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007,
759 "Reappeared sess %p\n", sess);
761 ha->tgt.tgt_ops->update_sess(sess, fcport->d_id,
763 (fcport->flags & FCF_CONF_COMP_SUPPORTED));
766 if (sess && sess->local) {
767 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d,
768 "qla_target(%u): local session for "
769 "port %8phC (loop ID %d) became global\n", vha->vp_idx,
770 fcport->port_name, sess->loop_id);
773 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
775 ha->tgt.tgt_ops->put_sess(sess);
779 * This is a zero-base ref-counting solution, since hardware_lock
780 * guarantees that ref_count is not modified concurrently.
781 * Upon successful return content of iocb is undefined
783 static struct qlt_plogi_ack_t *
784 qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id,
785 struct imm_ntfy_from_isp *iocb)
787 struct qlt_plogi_ack_t *pla;
789 lockdep_assert_held(&vha->hw->hardware_lock);
791 list_for_each_entry(pla, &vha->plogi_ack_list, list) {
792 if (pla->id.b24 == id->b24) {
793 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x210d,
794 "%s %d %8phC Term INOT due to new INOT",
796 pla->iocb.u.isp24.port_name);
797 qlt_send_term_imm_notif(vha, &pla->iocb, 1);
798 memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
803 pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC);
805 ql_dbg(ql_dbg_async, vha, 0x5088,
806 "qla_target(%d): Allocation of plogi_ack failed\n",
811 memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
813 list_add_tail(&pla->list, &vha->plogi_ack_list);
818 void qlt_plogi_ack_unref(struct scsi_qla_host *vha,
819 struct qlt_plogi_ack_t *pla)
821 struct imm_ntfy_from_isp *iocb = &pla->iocb;
824 fc_port_t *fcport = pla->fcport;
826 BUG_ON(!pla->ref_count);
832 ql_dbg(ql_dbg_disc, vha, 0x5089,
833 "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x"
834 " exch %#x ox_id %#x\n", iocb->u.isp24.port_name,
835 iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1],
836 iocb->u.isp24.port_id[0],
837 le16_to_cpu(iocb->u.isp24.nport_handle),
838 iocb->u.isp24.exchange_address, iocb->ox_id);
840 port_id.b.domain = iocb->u.isp24.port_id[2];
841 port_id.b.area = iocb->u.isp24.port_id[1];
842 port_id.b.al_pa = iocb->u.isp24.port_id[0];
843 port_id.b.rsvd_1 = 0;
845 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
847 fcport->loop_id = loop_id;
848 fcport->d_id = port_id;
849 if (iocb->u.isp24.status_subcode == ELS_PLOGI)
850 qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI);
852 qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PRLI);
854 list_for_each_entry(fcport, &vha->vp_fcports, list) {
855 if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla)
856 fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL;
857 if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla)
858 fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL;
861 list_del(&pla->list);
862 kmem_cache_free(qla_tgt_plogi_cachep, pla);
866 qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla,
867 struct fc_port *sess, enum qlt_plogi_link_t link)
869 struct imm_ntfy_from_isp *iocb = &pla->iocb;
870 /* Inc ref_count first because link might already be pointing at pla */
873 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097,
874 "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC"
875 " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n",
876 sess, link, sess->port_name,
877 iocb->u.isp24.port_name, iocb->u.isp24.port_id[2],
878 iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0],
879 pla->ref_count, pla, link);
881 if (link == QLT_PLOGI_LINK_CONFLICT) {
882 switch (sess->disc_state) {
884 case DSC_DELETE_PEND:
892 if (sess->plogi_link[link])
893 qlt_plogi_ack_unref(vha, sess->plogi_link[link]);
895 if (link == QLT_PLOGI_LINK_SAME_WWN)
898 sess->plogi_link[link] = pla;
902 /* These fields must be initialized by the caller */
905 * number of cmds dropped while we were waiting for
906 * initiator to ack LOGO initialize to 1 if LOGO is
907 * triggered by a command, otherwise, to 0
911 /* These fields are used by callee */
912 struct list_head list;
916 qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo)
918 qlt_port_logo_t *tmp;
921 mutex_lock(&vha->vha_tgt.tgt_mutex);
923 list_for_each_entry(tmp, &vha->logo_list, list) {
924 if (tmp->id.b24 == logo->id.b24) {
925 tmp->cmd_count += logo->cmd_count;
926 mutex_unlock(&vha->vha_tgt.tgt_mutex);
931 list_add_tail(&logo->list, &vha->logo_list);
933 mutex_unlock(&vha->vha_tgt.tgt_mutex);
935 res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id);
937 mutex_lock(&vha->vha_tgt.tgt_mutex);
938 list_del(&logo->list);
939 mutex_unlock(&vha->vha_tgt.tgt_mutex);
941 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098,
942 "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n",
943 logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa,
944 logo->cmd_count, res);
947 void qlt_free_session_done(struct work_struct *work)
949 struct fc_port *sess = container_of(work, struct fc_port,
951 struct qla_tgt *tgt = sess->tgt;
952 struct scsi_qla_host *vha = sess->vha;
953 struct qla_hw_data *ha = vha->hw;
955 bool logout_started = false;
956 scsi_qla_host_t *base_vha;
957 struct qlt_plogi_ack_t *own =
958 sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
960 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf084,
961 "%s: se_sess %p / sess %p from port %8phC loop_id %#04x"
962 " s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n",
963 __func__, sess->se_sess, sess, sess->port_name, sess->loop_id,
964 sess->d_id.b.domain, sess->d_id.b.area, sess->d_id.b.al_pa,
965 sess->logout_on_delete, sess->keep_nport_handle,
966 sess->send_els_logo);
968 if (!IS_SW_RESV_ADDR(sess->d_id)) {
969 qla2x00_mark_device_lost(vha, sess, 0, 0);
971 if (sess->send_els_logo) {
972 qlt_port_logo_t logo;
974 logo.id = sess->d_id;
977 qlt_send_first_logo(vha, &logo);
978 sess->send_els_logo = 0;
981 if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) {
986 (own->iocb.u.isp24.status_subcode == ELS_PLOGI))) {
987 rc = qla2x00_post_async_logout_work(vha, sess,
989 if (rc != QLA_SUCCESS)
990 ql_log(ql_log_warn, vha, 0xf085,
991 "Schedule logo failed sess %p rc %d\n",
994 logout_started = true;
995 } else if (own && (own->iocb.u.isp24.status_subcode ==
996 ELS_PRLI) && ha->flags.rida_fmt2) {
997 rc = qla2x00_post_async_prlo_work(vha, sess,
999 if (rc != QLA_SUCCESS)
1000 ql_log(ql_log_warn, vha, 0xf085,
1001 "Schedule PRLO failed sess %p rc %d\n",
1004 logout_started = true;
1006 } /* if sess->logout_on_delete */
1008 if (sess->nvme_flag & NVME_FLAG_REGISTERED &&
1009 !(sess->nvme_flag & NVME_FLAG_DELETING)) {
1010 sess->nvme_flag |= NVME_FLAG_DELETING;
1011 qla_nvme_unregister_remote_port(sess);
1016 * Release the target session for FC Nexus from fabric module code.
1018 if (sess->se_sess != NULL)
1019 ha->tgt.tgt_ops->free_session(sess);
1021 if (logout_started) {
1022 bool traced = false;
1024 while (!READ_ONCE(sess->logout_completed)) {
1026 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf086,
1027 "%s: waiting for sess %p logout\n",
1034 ql_dbg(ql_dbg_disc, vha, 0xf087,
1035 "%s: sess %p logout completed\n", __func__, sess);
1038 if (sess->logo_ack_needed) {
1039 sess->logo_ack_needed = 0;
1040 qla24xx_async_notify_ack(vha, sess,
1041 (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO);
1044 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1045 if (sess->se_sess) {
1046 sess->se_sess = NULL;
1047 if (tgt && !IS_SW_RESV_ADDR(sess->d_id))
1051 sess->disc_state = DSC_DELETED;
1052 sess->fw_login_state = DSC_LS_PORT_UNAVAIL;
1053 sess->deleted = QLA_SESS_DELETED;
1055 if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) {
1056 vha->fcport_count--;
1057 sess->login_succ = 0;
1060 qla2x00_clear_loop_id(sess);
1062 if (sess->conflict) {
1063 sess->conflict->login_pause = 0;
1064 sess->conflict = NULL;
1065 if (!test_bit(UNLOADING, &vha->dpc_flags))
1066 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1070 struct qlt_plogi_ack_t *con =
1071 sess->plogi_link[QLT_PLOGI_LINK_CONFLICT];
1072 struct imm_ntfy_from_isp *iocb;
1074 own = sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
1078 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099,
1079 "se_sess %p / sess %p port %8phC is gone,"
1080 " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n",
1081 sess->se_sess, sess, sess->port_name,
1082 own ? "releasing own PLOGI" : "no own PLOGI pending",
1083 own ? own->ref_count : -1,
1084 iocb->u.isp24.port_name, con->ref_count);
1085 qlt_plogi_ack_unref(vha, con);
1086 sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL;
1088 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a,
1089 "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n",
1090 sess->se_sess, sess, sess->port_name,
1091 own ? "releasing own PLOGI" :
1092 "no own PLOGI pending",
1093 own ? own->ref_count : -1);
1097 sess->fw_login_state = DSC_LS_PLOGI_PEND;
1098 qlt_plogi_ack_unref(vha, own);
1099 sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL;
1103 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1105 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001,
1106 "Unregistration of sess %p %8phC finished fcp_cnt %d\n",
1107 sess, sess->port_name, vha->fcport_count);
1109 if (tgt && (tgt->sess_count == 0))
1110 wake_up_all(&tgt->waitQ);
1112 if (vha->fcport_count == 0)
1113 wake_up_all(&vha->fcport_waitQ);
1115 base_vha = pci_get_drvdata(ha->pdev);
1117 sess->free_pending = 0;
1119 if (test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags))
1122 if ((!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) {
1123 switch (vha->host->active_mode) {
1124 case MODE_INITIATOR:
1126 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1127 qla2xxx_wake_dpc(vha);
1137 /* ha->tgt.sess_lock supposed to be held on entry */
1138 void qlt_unreg_sess(struct fc_port *sess)
1140 struct scsi_qla_host *vha = sess->vha;
1141 unsigned long flags;
1143 ql_dbg(ql_dbg_disc, sess->vha, 0x210a,
1144 "%s sess %p for deletion %8phC\n",
1145 __func__, sess, sess->port_name);
1147 spin_lock_irqsave(&sess->vha->work_lock, flags);
1148 if (sess->free_pending) {
1149 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1152 sess->free_pending = 1;
1153 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1156 vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess);
1158 sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
1159 sess->disc_state = DSC_DELETE_PEND;
1160 sess->last_rscn_gen = sess->rscn_gen;
1161 sess->last_login_gen = sess->login_gen;
1163 INIT_WORK(&sess->free_work, qlt_free_session_done);
1164 schedule_work(&sess->free_work);
1166 EXPORT_SYMBOL(qlt_unreg_sess);
1168 static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd)
1170 struct qla_hw_data *ha = vha->hw;
1171 struct fc_port *sess = NULL;
1174 struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb;
1175 unsigned long flags;
1177 loop_id = le16_to_cpu(n->u.isp24.nport_handle);
1178 if (loop_id == 0xFFFF) {
1180 atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count);
1181 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1182 qlt_clear_tgt_db(vha->vha_tgt.qla_tgt);
1183 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1185 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1186 sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
1187 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1190 ql_dbg(ql_dbg_tgt, vha, 0xe000,
1191 "Using sess for qla_tgt_reset: %p\n", sess);
1197 ql_dbg(ql_dbg_tgt, vha, 0xe047,
1198 "scsi(%ld): resetting (session %p from port %8phC mcmd %x, "
1199 "loop_id %d)\n", vha->host_no, sess, sess->port_name,
1202 return qlt_issue_task_mgmt(sess, 0, mcmd, iocb, QLA24XX_MGMT_SEND_NACK);
1205 static void qla24xx_chk_fcp_state(struct fc_port *sess)
1207 if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) {
1208 sess->logout_on_delete = 0;
1209 sess->logo_ack_needed = 0;
1210 sess->fw_login_state = DSC_LS_PORT_UNAVAIL;
1214 void qlt_schedule_sess_for_deletion(struct fc_port *sess)
1216 struct qla_tgt *tgt = sess->tgt;
1217 unsigned long flags;
1220 switch (sess->disc_state) {
1221 case DSC_DELETE_PEND:
1224 if (tgt && tgt->tgt_stop && (tgt->sess_count == 0))
1225 wake_up_all(&tgt->waitQ);
1226 if (sess->vha->fcport_count == 0)
1227 wake_up_all(&sess->vha->fcport_waitQ);
1229 if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] &&
1230 !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT])
1233 case DSC_UPD_FCPORT:
1235 * This port is not done reporting to upper layer.
1238 sess->next_disc_state = DSC_DELETE_PEND;
1239 sec = jiffies_to_msecs(jiffies -
1240 sess->jiffies_at_registration)/1000;
1241 if (sess->sec_since_registration < sec && sec && !(sec % 5)) {
1242 sess->sec_since_registration = sec;
1243 ql_dbg(ql_dbg_disc, sess->vha, 0xffff,
1244 "%s %8phC : Slow Rport registration(%d Sec)\n",
1245 __func__, sess->port_name, sec);
1252 spin_lock_irqsave(&sess->vha->work_lock, flags);
1253 if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) {
1254 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1257 sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
1258 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1260 sess->disc_state = DSC_DELETE_PEND;
1262 qla24xx_chk_fcp_state(sess);
1264 ql_dbg(ql_dbg_tgt, sess->vha, 0xe001,
1265 "Scheduling sess %p for deletion %8phC\n",
1266 sess, sess->port_name);
1268 INIT_WORK(&sess->del_work, qla24xx_delete_sess_fn);
1269 WARN_ON(!queue_work(sess->vha->hw->wq, &sess->del_work));
1272 static void qlt_clear_tgt_db(struct qla_tgt *tgt)
1274 struct fc_port *sess;
1275 scsi_qla_host_t *vha = tgt->vha;
1277 list_for_each_entry(sess, &vha->vp_fcports, list) {
1279 qlt_schedule_sess_for_deletion(sess);
1282 /* At this point tgt could be already dead */
1285 static int qla24xx_get_loop_id(struct scsi_qla_host *vha, be_id_t s_id,
1288 struct qla_hw_data *ha = vha->hw;
1289 dma_addr_t gid_list_dma;
1290 struct gid_list_info *gid_list, *gid;
1294 gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
1295 &gid_list_dma, GFP_KERNEL);
1297 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044,
1298 "qla_target(%d): DMA Alloc failed of %u\n",
1299 vha->vp_idx, qla2x00_gid_list_size(ha));
1303 /* Get list of logged in devices */
1304 rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries);
1305 if (rc != QLA_SUCCESS) {
1306 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045,
1307 "qla_target(%d): get_id_list() failed: %x\n",
1310 goto out_free_id_list;
1315 for (i = 0; i < entries; i++) {
1316 if (gid->al_pa == s_id.al_pa &&
1317 gid->area == s_id.area &&
1318 gid->domain == s_id.domain) {
1319 *loop_id = le16_to_cpu(gid->loop_id);
1323 gid = (void *)gid + ha->gid_list_info_size;
1327 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
1328 gid_list, gid_list_dma);
1333 * Adds an extra ref to allow to drop hw lock after adding sess to the list.
1334 * Caller must put it.
1336 static struct fc_port *qlt_create_sess(
1337 struct scsi_qla_host *vha,
1341 struct qla_hw_data *ha = vha->hw;
1342 struct fc_port *sess = fcport;
1343 unsigned long flags;
1345 if (vha->vha_tgt.qla_tgt->tgt_stop)
1348 if (fcport->se_sess) {
1349 if (!kref_get_unless_zero(&sess->sess_kref)) {
1350 ql_dbg(ql_dbg_disc, vha, 0x20f6,
1351 "%s: kref_get_unless_zero failed for %8phC\n",
1352 __func__, sess->port_name);
1357 sess->tgt = vha->vha_tgt.qla_tgt;
1358 sess->local = local;
1361 * Under normal circumstances we want to logout from firmware when
1362 * session eventually ends and release corresponding nport handle.
1363 * In the exception cases (e.g. when new PLOGI is waiting) corresponding
1364 * code will adjust these flags as necessary.
1366 sess->logout_on_delete = 1;
1367 sess->keep_nport_handle = 0;
1368 sess->logout_completed = 0;
1370 if (ha->tgt.tgt_ops->check_initiator_node_acl(vha,
1371 &fcport->port_name[0], sess) < 0) {
1372 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015,
1373 "(%d) %8phC check_initiator_node_acl failed\n",
1374 vha->vp_idx, fcport->port_name);
1377 kref_init(&fcport->sess_kref);
1379 * Take an extra reference to ->sess_kref here to handle
1380 * fc_port access across ->tgt.sess_lock reaquire.
1382 if (!kref_get_unless_zero(&sess->sess_kref)) {
1383 ql_dbg(ql_dbg_disc, vha, 0x20f7,
1384 "%s: kref_get_unless_zero failed for %8phC\n",
1385 __func__, sess->port_name);
1389 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1390 if (!IS_SW_RESV_ADDR(sess->d_id))
1391 vha->vha_tgt.qla_tgt->sess_count++;
1393 qlt_do_generation_tick(vha, &sess->generation);
1394 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1397 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006,
1398 "Adding sess %p se_sess %p to tgt %p sess_count %d\n",
1399 sess, sess->se_sess, vha->vha_tgt.qla_tgt,
1400 vha->vha_tgt.qla_tgt->sess_count);
1402 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b,
1403 "qla_target(%d): %ssession for wwn %8phC (loop_id %d, "
1404 "s_id %x:%x:%x, confirmed completion %ssupported) added\n",
1405 vha->vp_idx, local ? "local " : "", fcport->port_name,
1406 fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area,
1407 sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not ");
1413 * max_gen - specifies maximum session generation
1414 * at which this deletion requestion is still valid
1417 qlt_fc_port_deleted(struct scsi_qla_host *vha, fc_port_t *fcport, int max_gen)
1419 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1420 struct fc_port *sess = fcport;
1421 unsigned long flags;
1423 if (!vha->hw->tgt.tgt_ops)
1429 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1430 if (tgt->tgt_stop) {
1431 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1434 if (!sess->se_sess) {
1435 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1439 if (max_gen - sess->generation < 0) {
1440 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1441 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092,
1442 "Ignoring stale deletion request for se_sess %p / sess %p"
1443 " for port %8phC, req_gen %d, sess_gen %d\n",
1444 sess->se_sess, sess, sess->port_name, max_gen,
1449 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess);
1452 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1453 qlt_schedule_sess_for_deletion(sess);
1456 static inline int test_tgt_sess_count(struct qla_tgt *tgt)
1458 struct qla_hw_data *ha = tgt->ha;
1459 unsigned long flags;
1462 * We need to protect against race, when tgt is freed before or
1465 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1466 ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002,
1467 "tgt %p, sess_count=%d\n",
1468 tgt, tgt->sess_count);
1469 res = (tgt->sess_count == 0);
1470 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1475 /* Called by tcm_qla2xxx configfs code */
1476 int qlt_stop_phase1(struct qla_tgt *tgt)
1478 struct scsi_qla_host *vha = tgt->vha;
1479 struct qla_hw_data *ha = tgt->ha;
1480 unsigned long flags;
1482 mutex_lock(&ha->optrom_mutex);
1483 mutex_lock(&qla_tgt_mutex);
1485 if (tgt->tgt_stop || tgt->tgt_stopped) {
1486 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e,
1487 "Already in tgt->tgt_stop or tgt_stopped state\n");
1488 mutex_unlock(&qla_tgt_mutex);
1489 mutex_unlock(&ha->optrom_mutex);
1493 ql_dbg(ql_dbg_tgt_mgt, vha, 0xe003, "Stopping target for host %ld(%p)\n",
1496 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
1497 * Lock is needed, because we still can get an incoming packet.
1499 mutex_lock(&vha->vha_tgt.tgt_mutex);
1501 qlt_clear_tgt_db(tgt);
1502 mutex_unlock(&vha->vha_tgt.tgt_mutex);
1503 mutex_unlock(&qla_tgt_mutex);
1505 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009,
1506 "Waiting for sess works (tgt %p)", tgt);
1507 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1508 while (!list_empty(&tgt->sess_works_list)) {
1509 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1510 flush_scheduled_work();
1511 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1513 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1515 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a,
1516 "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count);
1518 wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
1521 if (!ha->flags.host_shutting_down &&
1522 (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)))
1523 qlt_disable_vha(vha);
1525 /* Wait for sessions to clear out (just in case) */
1526 wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
1527 mutex_unlock(&ha->optrom_mutex);
1531 EXPORT_SYMBOL(qlt_stop_phase1);
1533 /* Called by tcm_qla2xxx configfs code */
1534 void qlt_stop_phase2(struct qla_tgt *tgt)
1536 scsi_qla_host_t *vha = tgt->vha;
1538 if (tgt->tgt_stopped) {
1539 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f,
1540 "Already in tgt->tgt_stopped state\n");
1544 if (!tgt->tgt_stop) {
1545 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b,
1546 "%s: phase1 stop is not completed\n", __func__);
1551 mutex_lock(&vha->vha_tgt.tgt_mutex);
1553 tgt->tgt_stopped = 1;
1554 mutex_unlock(&vha->vha_tgt.tgt_mutex);
1556 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00c, "Stop of tgt %p finished\n",
1559 switch (vha->qlini_mode) {
1560 case QLA2XXX_INI_MODE_EXCLUSIVE:
1561 vha->flags.online = 1;
1562 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1568 EXPORT_SYMBOL(qlt_stop_phase2);
1570 /* Called from qlt_remove_target() -> qla2x00_remove_one() */
1571 static void qlt_release(struct qla_tgt *tgt)
1573 scsi_qla_host_t *vha = tgt->vha;
1577 struct qla_qpair_hint *h;
1578 struct qla_hw_data *ha = vha->hw;
1580 if (!tgt->tgt_stop && !tgt->tgt_stopped)
1581 qlt_stop_phase1(tgt);
1583 if (!tgt->tgt_stopped)
1584 qlt_stop_phase2(tgt);
1586 for (i = 0; i < vha->hw->max_qpairs + 1; i++) {
1587 unsigned long flags;
1589 h = &tgt->qphints[i];
1591 spin_lock_irqsave(h->qpair->qp_lock_ptr, flags);
1592 list_del(&h->hint_elem);
1593 spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags);
1597 kfree(tgt->qphints);
1598 mutex_lock(&qla_tgt_mutex);
1599 list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry);
1600 mutex_unlock(&qla_tgt_mutex);
1602 btree_for_each_safe64(&tgt->lun_qpair_map, key, node)
1603 btree_remove64(&tgt->lun_qpair_map, key);
1605 btree_destroy64(&tgt->lun_qpair_map);
1608 if (ha->tgt.tgt_ops &&
1609 ha->tgt.tgt_ops->remove_target &&
1610 vha->vha_tgt.target_lport_ptr)
1611 ha->tgt.tgt_ops->remove_target(vha);
1613 vha->vha_tgt.qla_tgt = NULL;
1615 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d,
1616 "Release of tgt %p finished\n", tgt);
1621 /* ha->hardware_lock supposed to be held on entry */
1622 static int qlt_sched_sess_work(struct qla_tgt *tgt, int type,
1623 const void *param, unsigned int param_size)
1625 struct qla_tgt_sess_work_param *prm;
1626 unsigned long flags;
1628 prm = kzalloc(sizeof(*prm), GFP_ATOMIC);
1630 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050,
1631 "qla_target(%d): Unable to create session "
1632 "work, command will be refused", 0);
1636 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e,
1637 "Scheduling work (type %d, prm %p)"
1638 " to find session for param %p (size %d, tgt %p)\n",
1639 type, prm, param, param_size, tgt);
1642 memcpy(&prm->tm_iocb, param, param_size);
1644 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1645 list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list);
1646 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1648 schedule_work(&tgt->sess_work);
1654 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1656 static void qlt_send_notify_ack(struct qla_qpair *qpair,
1657 struct imm_ntfy_from_isp *ntfy,
1658 uint32_t add_flags, uint16_t resp_code, int resp_code_valid,
1659 uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan)
1661 struct scsi_qla_host *vha = qpair->vha;
1662 struct qla_hw_data *ha = vha->hw;
1664 struct nack_to_isp *nack;
1666 if (!ha->flags.fw_started)
1669 ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha);
1671 pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL);
1673 ql_dbg(ql_dbg_tgt, vha, 0xe049,
1674 "qla_target(%d): %s failed: unable to allocate "
1675 "request packet\n", vha->vp_idx, __func__);
1679 if (vha->vha_tgt.qla_tgt != NULL)
1680 vha->vha_tgt.qla_tgt->notify_ack_expected++;
1682 pkt->entry_type = NOTIFY_ACK_TYPE;
1683 pkt->entry_count = 1;
1685 nack = (struct nack_to_isp *)pkt;
1686 nack->ox_id = ntfy->ox_id;
1688 nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE;
1689 nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
1690 if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
1691 nack->u.isp24.flags = ntfy->u.isp24.flags &
1692 cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB);
1694 nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
1695 nack->u.isp24.status = ntfy->u.isp24.status;
1696 nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode;
1697 nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle;
1698 nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address;
1699 nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs;
1700 nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui;
1701 nack->u.isp24.srr_flags = cpu_to_le16(srr_flags);
1702 nack->u.isp24.srr_reject_code = srr_reject_code;
1703 nack->u.isp24.srr_reject_code_expl = srr_explan;
1704 nack->u.isp24.vp_index = ntfy->u.isp24.vp_index;
1706 ql_dbg(ql_dbg_tgt, vha, 0xe005,
1707 "qla_target(%d): Sending 24xx Notify Ack %d\n",
1708 vha->vp_idx, nack->u.isp24.status);
1710 /* Memory Barrier */
1712 qla2x00_start_iocbs(vha, qpair->req);
1715 static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd)
1717 struct scsi_qla_host *vha = mcmd->vha;
1718 struct qla_hw_data *ha = vha->hw;
1719 struct abts_resp_to_24xx *resp;
1723 struct abts_recv_from_24xx *abts = &mcmd->orig_iocb.abts;
1724 struct qla_qpair *qpair = mcmd->qpair;
1726 ql_dbg(ql_dbg_tgt, vha, 0xe006,
1727 "Sending task mgmt ABTS response (ha=%p, status=%x)\n",
1728 ha, mcmd->fc_tm_rsp);
1730 rc = qlt_check_reserve_free_req(qpair, 1);
1732 ql_dbg(ql_dbg_tgt, vha, 0xe04a,
1733 "qla_target(%d): %s failed: unable to allocate request packet\n",
1734 vha->vp_idx, __func__);
1738 resp = (struct abts_resp_to_24xx *)qpair->req->ring_ptr;
1739 memset(resp, 0, sizeof(*resp));
1741 h = qlt_make_handle(qpair);
1742 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
1744 * CTIO type 7 from the firmware doesn't provide a way to
1745 * know the initiator's LOOP ID, hence we can't find
1746 * the session and, so, the command.
1750 qpair->req->outstanding_cmds[h] = (srb_t *)mcmd;
1753 resp->handle = MAKE_HANDLE(qpair->req->id, h);
1754 resp->entry_type = ABTS_RESP_24XX;
1755 resp->entry_count = 1;
1756 resp->nport_handle = abts->nport_handle;
1757 resp->vp_index = vha->vp_idx;
1758 resp->sof_type = abts->sof_type;
1759 resp->exchange_address = abts->exchange_address;
1760 resp->fcp_hdr_le = abts->fcp_hdr_le;
1761 f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
1762 F_CTL_LAST_SEQ | F_CTL_END_SEQ |
1763 F_CTL_SEQ_INITIATIVE);
1764 p = (uint8_t *)&f_ctl;
1765 resp->fcp_hdr_le.f_ctl[0] = *p++;
1766 resp->fcp_hdr_le.f_ctl[1] = *p++;
1767 resp->fcp_hdr_le.f_ctl[2] = *p;
1769 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
1770 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
1772 resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
1773 if (mcmd->fc_tm_rsp == FCP_TMF_CMPL) {
1774 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
1775 resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
1776 resp->payload.ba_acct.low_seq_cnt = 0x0000;
1777 resp->payload.ba_acct.high_seq_cnt = 0xFFFF;
1778 resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
1779 resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
1781 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT;
1782 resp->payload.ba_rjt.reason_code =
1783 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM;
1784 /* Other bytes are zero */
1787 vha->vha_tgt.qla_tgt->abts_resp_expected++;
1789 /* Memory Barrier */
1791 if (qpair->reqq_start_iocbs)
1792 qpair->reqq_start_iocbs(qpair);
1794 qla2x00_start_iocbs(vha, qpair->req);
1800 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1802 static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair,
1803 struct abts_recv_from_24xx *abts, uint32_t status,
1806 struct scsi_qla_host *vha = qpair->vha;
1807 struct qla_hw_data *ha = vha->hw;
1808 struct abts_resp_to_24xx *resp;
1812 ql_dbg(ql_dbg_tgt, vha, 0xe006,
1813 "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
1816 resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair,
1819 ql_dbg(ql_dbg_tgt, vha, 0xe04a,
1820 "qla_target(%d): %s failed: unable to allocate "
1821 "request packet", vha->vp_idx, __func__);
1825 resp->entry_type = ABTS_RESP_24XX;
1826 resp->handle = QLA_TGT_SKIP_HANDLE;
1827 resp->entry_count = 1;
1828 resp->nport_handle = abts->nport_handle;
1829 resp->vp_index = vha->vp_idx;
1830 resp->sof_type = abts->sof_type;
1831 resp->exchange_address = abts->exchange_address;
1832 resp->fcp_hdr_le = abts->fcp_hdr_le;
1833 f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
1834 F_CTL_LAST_SEQ | F_CTL_END_SEQ |
1835 F_CTL_SEQ_INITIATIVE);
1836 p = (uint8_t *)&f_ctl;
1837 resp->fcp_hdr_le.f_ctl[0] = *p++;
1838 resp->fcp_hdr_le.f_ctl[1] = *p++;
1839 resp->fcp_hdr_le.f_ctl[2] = *p;
1841 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.d_id;
1842 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.s_id;
1844 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
1845 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
1847 resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
1848 if (status == FCP_TMF_CMPL) {
1849 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
1850 resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
1851 resp->payload.ba_acct.low_seq_cnt = 0x0000;
1852 resp->payload.ba_acct.high_seq_cnt = 0xFFFF;
1853 resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
1854 resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
1856 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT;
1857 resp->payload.ba_rjt.reason_code =
1858 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM;
1859 /* Other bytes are zero */
1862 vha->vha_tgt.qla_tgt->abts_resp_expected++;
1864 /* Memory Barrier */
1866 if (qpair->reqq_start_iocbs)
1867 qpair->reqq_start_iocbs(qpair);
1869 qla2x00_start_iocbs(vha, qpair->req);
1873 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1875 static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha,
1876 struct qla_qpair *qpair, response_t *pkt, struct qla_tgt_mgmt_cmd *mcmd)
1878 struct ctio7_to_24xx *ctio;
1880 struct abts_recv_from_24xx *entry;
1882 ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, NULL);
1884 ql_dbg(ql_dbg_tgt, vha, 0xe04b,
1885 "qla_target(%d): %s failed: unable to allocate "
1886 "request packet\n", vha->vp_idx, __func__);
1891 /* abts from remote port */
1892 entry = &mcmd->orig_iocb.abts;
1894 /* abts from this driver. */
1895 entry = (struct abts_recv_from_24xx *)pkt;
1898 * We've got on entrance firmware's response on by us generated
1899 * ABTS response. So, in it ID fields are reversed.
1902 ctio->entry_type = CTIO_TYPE7;
1903 ctio->entry_count = 1;
1904 ctio->nport_handle = entry->nport_handle;
1905 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
1906 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
1907 ctio->vp_index = vha->vp_idx;
1908 ctio->exchange_addr = entry->exchange_addr_to_abort;
1909 tmp = (CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_TERMINATE);
1912 ctio->initiator_id = entry->fcp_hdr_le.s_id;
1914 if (mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID)
1915 tmp |= (mcmd->abort_io_attr << 9);
1916 else if (qpair->retry_term_cnt & 1)
1919 ctio->initiator_id = entry->fcp_hdr_le.d_id;
1921 if (qpair->retry_term_cnt & 1)
1924 ctio->u.status1.flags = cpu_to_le16(tmp);
1925 ctio->u.status1.ox_id = entry->fcp_hdr_le.ox_id;
1927 ql_dbg(ql_dbg_tgt, vha, 0xe007,
1928 "Sending retry TERM EXCH CTIO7 flags %04xh oxid %04xh attr valid %x\n",
1929 le16_to_cpu(ctio->u.status1.flags),
1930 le16_to_cpu(ctio->u.status1.ox_id),
1931 (mcmd && mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) ? 1 : 0);
1933 /* Memory Barrier */
1935 if (qpair->reqq_start_iocbs)
1936 qpair->reqq_start_iocbs(qpair);
1938 qla2x00_start_iocbs(vha, qpair->req);
1941 qlt_build_abts_resp_iocb(mcmd);
1943 qlt_24xx_send_abts_resp(qpair,
1944 (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true);
1948 /* drop cmds for the given lun
1949 * XXX only looks for cmds on the port through which lun reset was recieved
1950 * XXX does not go through the list of other port (which may have cmds
1953 static void abort_cmds_for_lun(struct scsi_qla_host *vha, u64 lun, be_id_t s_id)
1955 struct qla_tgt_sess_op *op;
1956 struct qla_tgt_cmd *cmd;
1958 unsigned long flags;
1960 key = sid_to_key(s_id);
1961 spin_lock_irqsave(&vha->cmd_list_lock, flags);
1962 list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) {
1966 op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
1967 op_lun = scsilun_to_int(
1968 (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun);
1969 if (op_key == key && op_lun == lun)
1973 list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
1977 op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
1978 op_lun = scsilun_to_int(
1979 (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun);
1980 if (op_key == key && op_lun == lun)
1984 list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
1988 cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id);
1989 cmd_lun = scsilun_to_int(
1990 (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun);
1991 if (cmd_key == key && cmd_lun == lun)
1994 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
1997 static struct qla_qpair_hint *qlt_find_qphint(struct scsi_qla_host *vha,
1998 uint64_t unpacked_lun)
2000 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
2001 struct qla_qpair_hint *h = NULL;
2003 if (vha->flags.qpairs_available) {
2004 h = btree_lookup64(&tgt->lun_qpair_map, unpacked_lun);
2006 h = &tgt->qphints[0];
2008 h = &tgt->qphints[0];
2014 static void qlt_do_tmr_work(struct work_struct *work)
2016 struct qla_tgt_mgmt_cmd *mcmd =
2017 container_of(work, struct qla_tgt_mgmt_cmd, work);
2018 struct qla_hw_data *ha = mcmd->vha->hw;
2021 unsigned long flags;
2023 switch (mcmd->tmr_func) {
2025 tag = mcmd->orig_iocb.abts.exchange_addr_to_abort;
2032 rc = ha->tgt.tgt_ops->handle_tmr(mcmd, mcmd->unpacked_lun,
2033 mcmd->tmr_func, tag);
2036 spin_lock_irqsave(mcmd->qpair->qp_lock_ptr, flags);
2037 switch (mcmd->tmr_func) {
2039 mcmd->fc_tm_rsp = FCP_TMF_REJECTED;
2040 qlt_build_abts_resp_iocb(mcmd);
2042 case QLA_TGT_LUN_RESET:
2043 case QLA_TGT_CLEAR_TS:
2044 case QLA_TGT_ABORT_TS:
2045 case QLA_TGT_CLEAR_ACA:
2046 case QLA_TGT_TARGET_RESET:
2047 qlt_send_busy(mcmd->qpair, &mcmd->orig_iocb.atio,
2051 case QLA_TGT_ABORT_ALL:
2052 case QLA_TGT_NEXUS_LOSS_SESS:
2053 case QLA_TGT_NEXUS_LOSS:
2054 qlt_send_notify_ack(mcmd->qpair,
2055 &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0);
2058 spin_unlock_irqrestore(mcmd->qpair->qp_lock_ptr, flags);
2060 ql_dbg(ql_dbg_tgt_mgt, mcmd->vha, 0xf052,
2061 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
2062 mcmd->vha->vp_idx, rc);
2063 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
2067 /* ha->hardware_lock supposed to be held on entry */
2068 static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha,
2069 struct abts_recv_from_24xx *abts, struct fc_port *sess)
2071 struct qla_hw_data *ha = vha->hw;
2072 struct qla_tgt_mgmt_cmd *mcmd;
2073 struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0];
2075 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f,
2076 "qla_target(%d): task abort (tag=%d)\n",
2077 vha->vp_idx, abts->exchange_addr_to_abort);
2079 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
2081 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051,
2082 "qla_target(%d): %s: Allocation of ABORT cmd failed",
2083 vha->vp_idx, __func__);
2086 memset(mcmd, 0, sizeof(*mcmd));
2087 mcmd->cmd_type = TYPE_TGT_TMCMD;
2089 memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts));
2090 mcmd->reset_count = ha->base_qpair->chip_reset;
2091 mcmd->tmr_func = QLA_TGT_ABTS;
2092 mcmd->qpair = h->qpair;
2096 * LUN is looked up by target-core internally based on the passed
2097 * abts->exchange_addr_to_abort tag.
2099 mcmd->se_cmd.cpuid = h->cpuid;
2101 if (ha->tgt.tgt_ops->find_cmd_by_tag) {
2102 struct qla_tgt_cmd *abort_cmd;
2104 abort_cmd = ha->tgt.tgt_ops->find_cmd_by_tag(sess,
2105 abts->exchange_addr_to_abort);
2106 if (abort_cmd && abort_cmd->qpair) {
2107 mcmd->qpair = abort_cmd->qpair;
2108 mcmd->se_cmd.cpuid = abort_cmd->se_cmd.cpuid;
2109 mcmd->abort_io_attr = abort_cmd->atio.u.isp24.attr;
2110 mcmd->flags = QLA24XX_MGMT_ABORT_IO_ATTR_VALID;
2114 INIT_WORK(&mcmd->work, qlt_do_tmr_work);
2115 queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, &mcmd->work);
2121 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2123 static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
2124 struct abts_recv_from_24xx *abts)
2126 struct qla_hw_data *ha = vha->hw;
2127 struct fc_port *sess;
2128 uint32_t tag = abts->exchange_addr_to_abort;
2131 unsigned long flags;
2133 if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) {
2134 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053,
2135 "qla_target(%d): ABTS: Abort Sequence not "
2136 "supported\n", vha->vp_idx);
2137 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2142 if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) {
2143 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010,
2144 "qla_target(%d): ABTS: Unknown Exchange "
2145 "Address received\n", vha->vp_idx);
2146 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2151 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011,
2152 "qla_target(%d): task abort (s_id=%x:%x:%x, "
2153 "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id.domain,
2154 abts->fcp_hdr_le.s_id.area, abts->fcp_hdr_le.s_id.al_pa, tag,
2155 le32_to_cpu(abts->fcp_hdr_le.parameter));
2157 s_id = le_id_to_be(abts->fcp_hdr_le.s_id);
2159 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2160 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
2162 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012,
2163 "qla_target(%d): task abort for non-existent session\n",
2165 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2167 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2171 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2174 if (sess->deleted) {
2175 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2180 rc = __qlt_24xx_handle_abts(vha, abts, sess);
2182 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054,
2183 "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
2185 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2192 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2194 static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair,
2195 struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code)
2197 struct scsi_qla_host *ha = mcmd->vha;
2198 struct atio_from_isp *atio = &mcmd->orig_iocb.atio;
2199 struct ctio7_to_24xx *ctio;
2202 ql_dbg(ql_dbg_tgt, ha, 0xe008,
2203 "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
2204 ha, atio, resp_code);
2207 ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL);
2209 ql_dbg(ql_dbg_tgt, ha, 0xe04c,
2210 "qla_target(%d): %s failed: unable to allocate "
2211 "request packet\n", ha->vp_idx, __func__);
2215 ctio->entry_type = CTIO_TYPE7;
2216 ctio->entry_count = 1;
2217 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
2218 ctio->nport_handle = mcmd->sess->loop_id;
2219 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2220 ctio->vp_index = ha->vp_idx;
2221 ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2222 ctio->exchange_addr = atio->u.isp24.exchange_addr;
2223 temp = (atio->u.isp24.attr << 9)|
2224 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
2225 ctio->u.status1.flags = cpu_to_le16(temp);
2226 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2227 ctio->u.status1.ox_id = cpu_to_le16(temp);
2228 ctio->u.status1.scsi_status =
2229 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID);
2230 ctio->u.status1.response_len = cpu_to_le16(8);
2231 ctio->u.status1.sense_data[0] = resp_code;
2233 /* Memory Barrier */
2235 if (qpair->reqq_start_iocbs)
2236 qpair->reqq_start_iocbs(qpair);
2238 qla2x00_start_iocbs(ha, qpair->req);
2241 void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd)
2243 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
2245 EXPORT_SYMBOL(qlt_free_mcmd);
2248 * ha->hardware_lock supposed to be held on entry. Might drop it, then
2251 void qlt_send_resp_ctio(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd,
2252 uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq)
2254 struct atio_from_isp *atio = &cmd->atio;
2255 struct ctio7_to_24xx *ctio;
2257 struct scsi_qla_host *vha = cmd->vha;
2259 ql_dbg(ql_dbg_tgt_dif, vha, 0x3066,
2260 "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, "
2261 "sense_key=%02x, asc=%02x, ascq=%02x",
2262 vha, atio, scsi_status, sense_key, asc, ascq);
2264 ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL);
2266 ql_dbg(ql_dbg_async, vha, 0x3067,
2267 "qla2x00t(%ld): %s failed: unable to allocate request packet",
2268 vha->host_no, __func__);
2272 ctio->entry_type = CTIO_TYPE7;
2273 ctio->entry_count = 1;
2274 ctio->handle = QLA_TGT_SKIP_HANDLE;
2275 ctio->nport_handle = cmd->sess->loop_id;
2276 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2277 ctio->vp_index = vha->vp_idx;
2278 ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2279 ctio->exchange_addr = atio->u.isp24.exchange_addr;
2280 temp = (atio->u.isp24.attr << 9) |
2281 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
2282 ctio->u.status1.flags = cpu_to_le16(temp);
2283 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2284 ctio->u.status1.ox_id = cpu_to_le16(temp);
2285 ctio->u.status1.scsi_status =
2286 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status);
2287 ctio->u.status1.response_len = cpu_to_le16(18);
2288 ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio));
2290 if (ctio->u.status1.residual != 0)
2291 ctio->u.status1.scsi_status |=
2292 cpu_to_le16(SS_RESIDUAL_UNDER);
2294 /* Fixed format sense data. */
2295 ctio->u.status1.sense_data[0] = 0x70;
2296 ctio->u.status1.sense_data[2] = sense_key;
2297 /* Additional sense length */
2298 ctio->u.status1.sense_data[7] = 0xa;
2300 ctio->u.status1.sense_data[12] = asc;
2301 ctio->u.status1.sense_data[13] = ascq;
2303 /* Memory Barrier */
2306 if (qpair->reqq_start_iocbs)
2307 qpair->reqq_start_iocbs(qpair);
2309 qla2x00_start_iocbs(vha, qpair->req);
2315 /* callback from target fabric module code */
2316 void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd)
2318 struct scsi_qla_host *vha = mcmd->sess->vha;
2319 struct qla_hw_data *ha = vha->hw;
2320 unsigned long flags;
2321 struct qla_qpair *qpair = mcmd->qpair;
2322 bool free_mcmd = true;
2324 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013,
2325 "TM response mcmd (%p) status %#x state %#x",
2326 mcmd, mcmd->fc_tm_rsp, mcmd->flags);
2328 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
2330 if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) {
2332 * Either the port is not online or this request was from
2333 * previous life, just abort the processing.
2335 ql_dbg(ql_dbg_async, vha, 0xe100,
2336 "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n",
2337 vha->flags.online, qla2x00_reset_active(vha),
2338 mcmd->reset_count, qpair->chip_reset);
2339 ha->tgt.tgt_ops->free_mcmd(mcmd);
2340 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2344 if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) {
2345 switch (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode) {
2349 ql_dbg(ql_dbg_disc, vha, 0x2106,
2350 "TM response logo %8phC status %#x state %#x",
2351 mcmd->sess->port_name, mcmd->fc_tm_rsp,
2353 qlt_schedule_sess_for_deletion(mcmd->sess);
2356 qlt_send_notify_ack(vha->hw->base_qpair,
2357 &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0);
2361 if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) {
2362 qlt_build_abts_resp_iocb(mcmd);
2365 qlt_24xx_send_task_mgmt_ctio(qpair, mcmd,
2369 * Make the callback for ->free_mcmd() to queue_work() and invoke
2370 * target_put_sess_cmd() to drop cmd_kref to 1. The final
2371 * target_put_sess_cmd() call will be made from TFO->check_stop_free()
2372 * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd
2373 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
2374 * qlt_xmit_tm_rsp() returns here..
2377 ha->tgt.tgt_ops->free_mcmd(mcmd);
2379 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2381 EXPORT_SYMBOL(qlt_xmit_tm_rsp);
2384 static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm)
2386 struct qla_tgt_cmd *cmd = prm->cmd;
2388 BUG_ON(cmd->sg_cnt == 0);
2390 prm->sg = (struct scatterlist *)cmd->sg;
2391 prm->seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, cmd->sg,
2392 cmd->sg_cnt, cmd->dma_data_direction);
2393 if (unlikely(prm->seg_cnt == 0))
2396 prm->cmd->sg_mapped = 1;
2398 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) {
2400 * If greater than four sg entries then we need to allocate
2401 * the continuation entries
2403 if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX)
2404 prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt -
2405 QLA_TGT_DATASEGS_PER_CMD_24XX,
2406 QLA_TGT_DATASEGS_PER_CONT_24XX);
2409 if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) ||
2410 (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) {
2411 prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz);
2412 prm->tot_dsds = prm->seg_cnt;
2414 prm->tot_dsds = prm->seg_cnt;
2416 if (cmd->prot_sg_cnt) {
2417 prm->prot_sg = cmd->prot_sg;
2418 prm->prot_seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev,
2419 cmd->prot_sg, cmd->prot_sg_cnt,
2420 cmd->dma_data_direction);
2421 if (unlikely(prm->prot_seg_cnt == 0))
2424 if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) ||
2425 (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) {
2426 /* Dif Bundling not support here */
2427 prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen,
2429 prm->tot_dsds += prm->prot_seg_cnt;
2431 prm->tot_dsds += prm->prot_seg_cnt;
2438 ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d,
2439 "qla_target(%d): PCI mapping failed: sg_cnt=%d",
2440 0, prm->cmd->sg_cnt);
2444 static void qlt_unmap_sg(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd)
2446 struct qla_hw_data *ha;
2447 struct qla_qpair *qpair;
2449 if (!cmd->sg_mapped)
2454 dma_unmap_sg(&qpair->pdev->dev, cmd->sg, cmd->sg_cnt,
2455 cmd->dma_data_direction);
2458 if (cmd->prot_sg_cnt)
2459 dma_unmap_sg(&qpair->pdev->dev, cmd->prot_sg, cmd->prot_sg_cnt,
2460 cmd->dma_data_direction);
2465 if (cmd->ctx_dsd_alloced)
2466 qla2x00_clean_dsd_pool(ha, cmd->ctx);
2468 dma_pool_free(ha->dl_dma_pool, cmd->ctx, cmd->ctx->crc_ctx_dma);
2471 static int qlt_check_reserve_free_req(struct qla_qpair *qpair,
2475 struct req_que *req = qpair->req;
2477 if (req->cnt < (req_cnt + 2)) {
2478 cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr :
2479 RD_REG_DWORD_RELAXED(req->req_q_out));
2481 if (req->ring_index < cnt)
2482 req->cnt = cnt - req->ring_index;
2484 req->cnt = req->length - (req->ring_index - cnt);
2486 if (unlikely(req->cnt < (req_cnt + 2)))
2490 req->cnt -= req_cnt;
2496 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2498 static inline void *qlt_get_req_pkt(struct req_que *req)
2500 /* Adjust ring index. */
2502 if (req->ring_index == req->length) {
2503 req->ring_index = 0;
2504 req->ring_ptr = req->ring;
2508 return (cont_entry_t *)req->ring_ptr;
2511 /* ha->hardware_lock supposed to be held on entry */
2512 static inline uint32_t qlt_make_handle(struct qla_qpair *qpair)
2517 struct req_que *req = qpair->req;
2519 h = req->current_outstanding_cmd;
2521 for (index = 1; index < req->num_outstanding_cmds; index++) {
2523 if (h == req->num_outstanding_cmds)
2526 if (h == QLA_TGT_SKIP_HANDLE)
2529 if (!req->outstanding_cmds[h]) {
2536 req->current_outstanding_cmd = h;
2538 ql_dbg(ql_dbg_io, qpair->vha, 0x305b,
2539 "qla_target(%d): Ran out of empty cmd slots\n",
2540 qpair->vha->vp_idx);
2541 h = QLA_TGT_NULL_HANDLE;
2547 /* ha->hardware_lock supposed to be held on entry */
2548 static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair,
2549 struct qla_tgt_prm *prm)
2552 struct ctio7_to_24xx *pkt;
2553 struct atio_from_isp *atio = &prm->cmd->atio;
2556 pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr;
2558 memset(pkt, 0, sizeof(*pkt));
2560 pkt->entry_type = CTIO_TYPE7;
2561 pkt->entry_count = (uint8_t)prm->req_cnt;
2562 pkt->vp_index = prm->cmd->vp_idx;
2564 h = qlt_make_handle(qpair);
2565 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
2567 * CTIO type 7 from the firmware doesn't provide a way to
2568 * know the initiator's LOOP ID, hence we can't find
2569 * the session and, so, the command.
2573 qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
2575 pkt->handle = MAKE_HANDLE(qpair->req->id, h);
2576 pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
2577 pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
2578 pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2579 pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2580 pkt->exchange_addr = atio->u.isp24.exchange_addr;
2581 temp = atio->u.isp24.attr << 9;
2582 pkt->u.status0.flags |= cpu_to_le16(temp);
2583 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2584 pkt->u.status0.ox_id = cpu_to_le16(temp);
2585 pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset);
2591 * ha->hardware_lock supposed to be held on entry. We have already made sure
2592 * that there is sufficient amount of request entries to not drop it.
2594 static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm)
2597 struct dsd64 *cur_dsd;
2599 /* Build continuation packets */
2600 while (prm->seg_cnt > 0) {
2601 cont_a64_entry_t *cont_pkt64 =
2602 (cont_a64_entry_t *)qlt_get_req_pkt(
2603 prm->cmd->qpair->req);
2606 * Make sure that from cont_pkt64 none of
2607 * 64-bit specific fields used for 32-bit
2608 * addressing. Cast to (cont_entry_t *) for
2612 memset(cont_pkt64, 0, sizeof(*cont_pkt64));
2614 cont_pkt64->entry_count = 1;
2615 cont_pkt64->sys_define = 0;
2617 cont_pkt64->entry_type = CONTINUE_A64_TYPE;
2618 cur_dsd = cont_pkt64->dsd;
2620 /* Load continuation entry data segments */
2622 cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt;
2623 cnt++, prm->seg_cnt--) {
2624 append_dsd64(&cur_dsd, prm->sg);
2625 prm->sg = sg_next(prm->sg);
2631 * ha->hardware_lock supposed to be held on entry. We have already made sure
2632 * that there is sufficient amount of request entries to not drop it.
2634 static void qlt_load_data_segments(struct qla_tgt_prm *prm)
2637 struct dsd64 *cur_dsd;
2638 struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt;
2640 pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen);
2642 /* Setup packet address segment pointer */
2643 cur_dsd = &pkt24->u.status0.dsd;
2645 /* Set total data segment count */
2647 pkt24->dseg_count = cpu_to_le16(prm->seg_cnt);
2649 if (prm->seg_cnt == 0) {
2650 /* No data transfer */
2651 cur_dsd->address = 0;
2652 cur_dsd->length = 0;
2656 /* If scatter gather */
2658 /* Load command entry data segments */
2660 (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt;
2661 cnt++, prm->seg_cnt--) {
2662 append_dsd64(&cur_dsd, prm->sg);
2663 prm->sg = sg_next(prm->sg);
2666 qlt_load_cont_data_segments(prm);
2669 static inline int qlt_has_data(struct qla_tgt_cmd *cmd)
2671 return cmd->bufflen > 0;
2674 static void qlt_print_dif_err(struct qla_tgt_prm *prm)
2676 struct qla_tgt_cmd *cmd;
2677 struct scsi_qla_host *vha;
2679 /* asc 0x10=dif error */
2680 if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) {
2684 switch (prm->sense_buffer[13]) {
2686 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b,
2687 "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2688 "se_cmd=%p tag[%x]",
2689 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2690 cmd->atio.u.isp24.exchange_addr);
2693 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c,
2694 "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2695 "se_cmd=%p tag[%x]",
2696 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2697 cmd->atio.u.isp24.exchange_addr);
2700 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f,
2701 "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2702 "se_cmd=%p tag[%x]",
2703 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2704 cmd->atio.u.isp24.exchange_addr);
2707 ql_dbg(ql_dbg_tgt_dif, vha, 0xe010,
2708 "BE detected Dif ERR: lba[%llx|%lld] len[%x] "
2709 "se_cmd=%p tag[%x]",
2710 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2711 cmd->atio.u.isp24.exchange_addr);
2714 ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16);
2719 * Called without ha->hardware_lock held
2721 static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd,
2722 struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status,
2723 uint32_t *full_req_cnt)
2725 struct se_cmd *se_cmd = &cmd->se_cmd;
2726 struct qla_qpair *qpair = cmd->qpair;
2729 prm->tgt = cmd->tgt;
2731 prm->rq_result = scsi_status;
2732 prm->sense_buffer = &cmd->sense_buffer[0];
2733 prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER;
2738 prm->add_status_pkt = 0;
2739 prm->prot_sg = NULL;
2740 prm->prot_seg_cnt = 0;
2743 if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) {
2744 if (qlt_pci_map_calc_cnt(prm) != 0)
2748 *full_req_cnt = prm->req_cnt;
2750 if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
2751 prm->residual = se_cmd->residual_count;
2752 ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c,
2753 "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2754 prm->residual, se_cmd->tag,
2755 se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0,
2756 cmd->bufflen, prm->rq_result);
2757 prm->rq_result |= SS_RESIDUAL_UNDER;
2758 } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) {
2759 prm->residual = se_cmd->residual_count;
2760 ql_dbg_qp(ql_dbg_io, qpair, 0x305d,
2761 "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2762 prm->residual, se_cmd->tag, se_cmd->t_task_cdb ?
2763 se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result);
2764 prm->rq_result |= SS_RESIDUAL_OVER;
2767 if (xmit_type & QLA_TGT_XMIT_STATUS) {
2769 * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be
2770 * ignored in *xmit_response() below
2772 if (qlt_has_data(cmd)) {
2773 if (QLA_TGT_SENSE_VALID(prm->sense_buffer) ||
2774 (IS_FWI2_CAPABLE(cmd->vha->hw) &&
2775 (prm->rq_result != 0))) {
2776 prm->add_status_pkt = 1;
2785 static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd,
2788 if (cmd->qpair->enable_class_2)
2792 return cmd->conf_compl_supported;
2794 return cmd->qpair->enable_explicit_conf &&
2795 cmd->conf_compl_supported;
2798 static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio,
2799 struct qla_tgt_prm *prm)
2801 prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len,
2802 (uint32_t)sizeof(ctio->u.status1.sense_data));
2803 ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS);
2804 if (qlt_need_explicit_conf(prm->cmd, 0)) {
2805 ctio->u.status0.flags |= cpu_to_le16(
2806 CTIO7_FLAGS_EXPLICIT_CONFORM |
2807 CTIO7_FLAGS_CONFORM_REQ);
2809 ctio->u.status0.residual = cpu_to_le32(prm->residual);
2810 ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result);
2811 if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) {
2814 if (qlt_need_explicit_conf(prm->cmd, 1)) {
2815 if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) {
2816 ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017,
2817 "Skipping EXPLICIT_CONFORM and "
2818 "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
2819 "non GOOD status\n");
2820 goto skip_explict_conf;
2822 ctio->u.status1.flags |= cpu_to_le16(
2823 CTIO7_FLAGS_EXPLICIT_CONFORM |
2824 CTIO7_FLAGS_CONFORM_REQ);
2827 ctio->u.status1.flags &=
2828 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
2829 ctio->u.status1.flags |=
2830 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
2831 ctio->u.status1.scsi_status |=
2832 cpu_to_le16(SS_SENSE_LEN_VALID);
2833 ctio->u.status1.sense_length =
2834 cpu_to_le16(prm->sense_buffer_len);
2835 for (i = 0; i < prm->sense_buffer_len/4; i++)
2836 ((uint32_t *)ctio->u.status1.sense_data)[i] =
2837 cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]);
2839 qlt_print_dif_err(prm);
2842 ctio->u.status1.flags &=
2843 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
2844 ctio->u.status1.flags |=
2845 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
2846 ctio->u.status1.sense_length = 0;
2847 memset(ctio->u.status1.sense_data, 0,
2848 sizeof(ctio->u.status1.sense_data));
2851 /* Sense with len > 24, is it possible ??? */
2855 qlt_hba_err_chk_enabled(struct se_cmd *se_cmd)
2857 switch (se_cmd->prot_op) {
2858 case TARGET_PROT_DOUT_INSERT:
2859 case TARGET_PROT_DIN_STRIP:
2860 if (ql2xenablehba_err_chk >= 1)
2863 case TARGET_PROT_DOUT_PASS:
2864 case TARGET_PROT_DIN_PASS:
2865 if (ql2xenablehba_err_chk >= 2)
2868 case TARGET_PROT_DIN_INSERT:
2869 case TARGET_PROT_DOUT_STRIP:
2878 qla_tgt_ref_mask_check(struct se_cmd *se_cmd)
2880 switch (se_cmd->prot_op) {
2881 case TARGET_PROT_DIN_INSERT:
2882 case TARGET_PROT_DOUT_INSERT:
2883 case TARGET_PROT_DIN_STRIP:
2884 case TARGET_PROT_DOUT_STRIP:
2885 case TARGET_PROT_DIN_PASS:
2886 case TARGET_PROT_DOUT_PASS:
2895 * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command
2898 qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx,
2899 uint16_t *pfw_prot_opts)
2901 struct se_cmd *se_cmd = &cmd->se_cmd;
2902 uint32_t lba = 0xffffffff & se_cmd->t_task_lba;
2903 scsi_qla_host_t *vha = cmd->tgt->vha;
2904 struct qla_hw_data *ha = vha->hw;
2908 * wait till Mode Sense/Select cmd, modepage Ah, subpage 2
2909 * have been immplemented by TCM, before AppTag is avail.
2910 * Look for modesense_handlers[]
2913 ctx->app_tag_mask[0] = 0x0;
2914 ctx->app_tag_mask[1] = 0x0;
2916 if (IS_PI_UNINIT_CAPABLE(ha)) {
2917 if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) ||
2918 (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT))
2919 *pfw_prot_opts |= PO_DIS_VALD_APP_ESC;
2920 else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT)
2921 *pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC;
2924 t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts);
2926 switch (se_cmd->prot_type) {
2927 case TARGET_DIF_TYPE0_PROT:
2929 * No check for ql2xenablehba_err_chk, as it
2930 * would be an I/O error if hba tag generation
2933 ctx->ref_tag = cpu_to_le32(lba);
2934 /* enable ALL bytes of the ref tag */
2935 ctx->ref_tag_mask[0] = 0xff;
2936 ctx->ref_tag_mask[1] = 0xff;
2937 ctx->ref_tag_mask[2] = 0xff;
2938 ctx->ref_tag_mask[3] = 0xff;
2940 case TARGET_DIF_TYPE1_PROT:
2942 * For TYPE 1 protection: 16 bit GUARD tag, 32 bit
2943 * REF tag, and 16 bit app tag.
2945 ctx->ref_tag = cpu_to_le32(lba);
2946 if (!qla_tgt_ref_mask_check(se_cmd) ||
2947 !(ha->tgt.tgt_ops->chk_dif_tags(t32))) {
2948 *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
2951 /* enable ALL bytes of the ref tag */
2952 ctx->ref_tag_mask[0] = 0xff;
2953 ctx->ref_tag_mask[1] = 0xff;
2954 ctx->ref_tag_mask[2] = 0xff;
2955 ctx->ref_tag_mask[3] = 0xff;
2957 case TARGET_DIF_TYPE2_PROT:
2959 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF
2960 * tag has to match LBA in CDB + N
2962 ctx->ref_tag = cpu_to_le32(lba);
2963 if (!qla_tgt_ref_mask_check(se_cmd) ||
2964 !(ha->tgt.tgt_ops->chk_dif_tags(t32))) {
2965 *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
2968 /* enable ALL bytes of the ref tag */
2969 ctx->ref_tag_mask[0] = 0xff;
2970 ctx->ref_tag_mask[1] = 0xff;
2971 ctx->ref_tag_mask[2] = 0xff;
2972 ctx->ref_tag_mask[3] = 0xff;
2974 case TARGET_DIF_TYPE3_PROT:
2975 /* For TYPE 3 protection: 16 bit GUARD only */
2976 *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
2977 ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] =
2978 ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00;
2984 qlt_build_ctio_crc2_pkt(struct qla_qpair *qpair, struct qla_tgt_prm *prm)
2986 struct dsd64 *cur_dsd;
2987 uint32_t transfer_length = 0;
2988 uint32_t data_bytes;
2990 uint8_t bundling = 1;
2991 struct crc_context *crc_ctx_pkt = NULL;
2992 struct qla_hw_data *ha;
2993 struct ctio_crc2_to_fw *pkt;
2994 dma_addr_t crc_ctx_dma;
2995 uint16_t fw_prot_opts = 0;
2996 struct qla_tgt_cmd *cmd = prm->cmd;
2997 struct se_cmd *se_cmd = &cmd->se_cmd;
2999 struct atio_from_isp *atio = &prm->cmd->atio;
3000 struct qla_tc_param tc;
3002 scsi_qla_host_t *vha = cmd->vha;
3006 pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr;
3008 memset(pkt, 0, sizeof(*pkt));
3010 ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071,
3011 "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n",
3012 cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op,
3013 prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba);
3015 if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) ||
3016 (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP))
3019 /* Compute dif len and adjust data len to incude protection */
3020 data_bytes = cmd->bufflen;
3021 dif_bytes = (data_bytes / cmd->blk_sz) * 8;
3023 switch (se_cmd->prot_op) {
3024 case TARGET_PROT_DIN_INSERT:
3025 case TARGET_PROT_DOUT_STRIP:
3026 transfer_length = data_bytes;
3027 if (cmd->prot_sg_cnt)
3028 data_bytes += dif_bytes;
3030 case TARGET_PROT_DIN_STRIP:
3031 case TARGET_PROT_DOUT_INSERT:
3032 case TARGET_PROT_DIN_PASS:
3033 case TARGET_PROT_DOUT_PASS:
3034 transfer_length = data_bytes + dif_bytes;
3041 if (!qlt_hba_err_chk_enabled(se_cmd))
3042 fw_prot_opts |= 0x10; /* Disable Guard tag checking */
3043 /* HBA error checking enabled */
3044 else if (IS_PI_UNINIT_CAPABLE(ha)) {
3045 if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) ||
3046 (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT))
3047 fw_prot_opts |= PO_DIS_VALD_APP_ESC;
3048 else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT)
3049 fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC;
3052 switch (se_cmd->prot_op) {
3053 case TARGET_PROT_DIN_INSERT:
3054 case TARGET_PROT_DOUT_INSERT:
3055 fw_prot_opts |= PO_MODE_DIF_INSERT;
3057 case TARGET_PROT_DIN_STRIP:
3058 case TARGET_PROT_DOUT_STRIP:
3059 fw_prot_opts |= PO_MODE_DIF_REMOVE;
3061 case TARGET_PROT_DIN_PASS:
3062 case TARGET_PROT_DOUT_PASS:
3063 fw_prot_opts |= PO_MODE_DIF_PASS;
3064 /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */
3066 default:/* Normal Request */
3067 fw_prot_opts |= PO_MODE_DIF_PASS;
3072 /* Update entry type to indicate Command Type CRC_2 IOCB */
3073 pkt->entry_type = CTIO_CRC2;
3074 pkt->entry_count = 1;
3075 pkt->vp_index = cmd->vp_idx;
3077 h = qlt_make_handle(qpair);
3078 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
3080 * CTIO type 7 from the firmware doesn't provide a way to
3081 * know the initiator's LOOP ID, hence we can't find
3082 * the session and, so, the command.
3086 qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
3088 pkt->handle = MAKE_HANDLE(qpair->req->id, h);
3089 pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
3090 pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
3091 pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
3092 pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
3093 pkt->exchange_addr = atio->u.isp24.exchange_addr;
3095 /* silence compile warning */
3096 t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
3097 pkt->ox_id = cpu_to_le16(t16);
3099 t16 = (atio->u.isp24.attr << 9);
3100 pkt->flags |= cpu_to_le16(t16);
3101 pkt->relative_offset = cpu_to_le32(prm->cmd->offset);
3103 /* Set transfer direction */
3104 if (cmd->dma_data_direction == DMA_TO_DEVICE)
3105 pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN);
3106 else if (cmd->dma_data_direction == DMA_FROM_DEVICE)
3107 pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT);
3109 pkt->dseg_count = prm->tot_dsds;
3110 /* Fibre channel byte count */
3111 pkt->transfer_length = cpu_to_le32(transfer_length);
3113 /* ----- CRC context -------- */
3115 /* Allocate CRC context from global pool */
3116 crc_ctx_pkt = cmd->ctx =
3117 dma_pool_zalloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma);
3120 goto crc_queuing_error;
3122 crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma;
3123 INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list);
3126 crc_ctx_pkt->handle = pkt->handle;
3128 qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts);
3130 put_unaligned_le64(crc_ctx_dma, &pkt->crc_context_address);
3131 pkt->crc_context_len = CRC_CONTEXT_LEN_FW;
3134 cur_dsd = &crc_ctx_pkt->u.nobundling.data_dsd[0];
3137 * Configure Bundling if we need to fetch interlaving
3138 * protection PCI accesses
3140 fw_prot_opts |= PO_ENABLE_DIF_BUNDLING;
3141 crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes);
3142 crc_ctx_pkt->u.bundling.dseg_count =
3143 cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt);
3144 cur_dsd = &crc_ctx_pkt->u.bundling.data_dsd[0];
3147 /* Finish the common fields of CRC pkt */
3148 crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz);
3149 crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts);
3150 crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes);
3151 crc_ctx_pkt->guard_seed = cpu_to_le16(0);
3153 memset((uint8_t *)&tc, 0 , sizeof(tc));
3155 tc.blk_sz = cmd->blk_sz;
3156 tc.bufflen = cmd->bufflen;
3158 tc.prot_sg = cmd->prot_sg;
3159 tc.ctx = crc_ctx_pkt;
3160 tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced;
3162 /* Walks data segments */
3163 pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR);
3165 if (!bundling && prm->prot_seg_cnt) {
3166 if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd,
3167 prm->tot_dsds, &tc))
3168 goto crc_queuing_error;
3169 } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd,
3170 (prm->tot_dsds - prm->prot_seg_cnt), &tc))
3171 goto crc_queuing_error;
3173 if (bundling && prm->prot_seg_cnt) {
3174 /* Walks dif segments */
3175 pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA;
3177 cur_dsd = &crc_ctx_pkt->u.bundling.dif_dsd;
3178 if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd,
3179 prm->prot_seg_cnt, cmd))
3180 goto crc_queuing_error;
3185 /* Cleanup will be performed by the caller */
3186 qpair->req->outstanding_cmds[h] = NULL;
3188 return QLA_FUNCTION_FAILED;
3192 * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and *
3193 * QLA_TGT_XMIT_STATUS for >= 24xx silicon
3195 int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type,
3196 uint8_t scsi_status)
3198 struct scsi_qla_host *vha = cmd->vha;
3199 struct qla_qpair *qpair = cmd->qpair;
3200 struct ctio7_to_24xx *pkt;
3201 struct qla_tgt_prm prm;
3202 uint32_t full_req_cnt = 0;
3203 unsigned long flags = 0;
3206 if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) ||
3207 (cmd->sess && cmd->sess->deleted)) {
3208 cmd->state = QLA_TGT_STATE_PROCESSED;
3212 ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018,
3213 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p] qp %d\n",
3214 (xmit_type & QLA_TGT_XMIT_STATUS) ?
3215 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction,
3216 &cmd->se_cmd, qpair->id);
3218 res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status,
3220 if (unlikely(res != 0)) {
3224 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3226 if (xmit_type == QLA_TGT_XMIT_STATUS)
3227 qpair->tgt_counters.core_qla_snd_status++;
3229 qpair->tgt_counters.core_qla_que_buf++;
3231 if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) {
3233 * Either the port is not online or this request was from
3234 * previous life, just abort the processing.
3236 cmd->state = QLA_TGT_STATE_PROCESSED;
3237 ql_dbg_qp(ql_dbg_async, qpair, 0xe101,
3238 "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n",
3239 vha->flags.online, qla2x00_reset_active(vha),
3240 cmd->reset_count, qpair->chip_reset);
3241 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3245 /* Does F/W have an IOCBs for this request */
3246 res = qlt_check_reserve_free_req(qpair, full_req_cnt);
3248 goto out_unmap_unlock;
3250 if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA))
3251 res = qlt_build_ctio_crc2_pkt(qpair, &prm);
3253 res = qlt_24xx_build_ctio_pkt(qpair, &prm);
3254 if (unlikely(res != 0)) {
3255 qpair->req->cnt += full_req_cnt;
3256 goto out_unmap_unlock;
3259 pkt = (struct ctio7_to_24xx *)prm.pkt;
3261 if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) {
3262 pkt->u.status0.flags |=
3263 cpu_to_le16(CTIO7_FLAGS_DATA_IN |
3264 CTIO7_FLAGS_STATUS_MODE_0);
3266 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
3267 qlt_load_data_segments(&prm);
3269 if (prm.add_status_pkt == 0) {
3270 if (xmit_type & QLA_TGT_XMIT_STATUS) {
3271 pkt->u.status0.scsi_status =
3272 cpu_to_le16(prm.rq_result);
3273 pkt->u.status0.residual =
3274 cpu_to_le32(prm.residual);
3275 pkt->u.status0.flags |= cpu_to_le16(
3276 CTIO7_FLAGS_SEND_STATUS);
3277 if (qlt_need_explicit_conf(cmd, 0)) {
3278 pkt->u.status0.flags |=
3280 CTIO7_FLAGS_EXPLICIT_CONFORM |
3281 CTIO7_FLAGS_CONFORM_REQ);
3287 * We have already made sure that there is sufficient
3288 * amount of request entries to not drop HW lock in
3291 struct ctio7_to_24xx *ctio =
3292 (struct ctio7_to_24xx *)qlt_get_req_pkt(
3295 ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e,
3296 "Building additional status packet 0x%p.\n",
3300 * T10Dif: ctio_crc2_to_fw overlay ontop of
3303 memcpy(ctio, pkt, sizeof(*ctio));
3304 /* reset back to CTIO7 */
3305 ctio->entry_count = 1;
3306 ctio->entry_type = CTIO_TYPE7;
3307 ctio->dseg_count = 0;
3308 ctio->u.status1.flags &= ~cpu_to_le16(
3309 CTIO7_FLAGS_DATA_IN);
3311 /* Real finish is ctio_m1's finish */
3312 pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK;
3313 pkt->u.status0.flags |= cpu_to_le16(
3314 CTIO7_FLAGS_DONT_RET_CTIO);
3316 /* qlt_24xx_init_ctio_to_isp will correct
3317 * all neccessary fields that's part of CTIO7.
3318 * There should be no residual of CTIO-CRC2 data.
3320 qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio,
3324 qlt_24xx_init_ctio_to_isp(pkt, &prm);
3327 cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */
3328 cmd->cmd_sent_to_fw = 1;
3329 cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
3331 /* Memory Barrier */
3333 if (qpair->reqq_start_iocbs)
3334 qpair->reqq_start_iocbs(qpair);
3336 qla2x00_start_iocbs(vha, qpair->req);
3337 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3342 qlt_unmap_sg(vha, cmd);
3343 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3347 EXPORT_SYMBOL(qlt_xmit_response);
3349 int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd)
3351 struct ctio7_to_24xx *pkt;
3352 struct scsi_qla_host *vha = cmd->vha;
3353 struct qla_tgt *tgt = cmd->tgt;
3354 struct qla_tgt_prm prm;
3355 unsigned long flags = 0;
3357 struct qla_qpair *qpair = cmd->qpair;
3359 memset(&prm, 0, sizeof(prm));
3365 /* Calculate number of entries and segments required */
3366 if (qlt_pci_map_calc_cnt(&prm) != 0)
3369 if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) ||
3370 (cmd->sess && cmd->sess->deleted)) {
3372 * Either the port is not online or this request was from
3373 * previous life, just abort the processing.
3376 cmd->write_data_transferred = 0;
3377 cmd->state = QLA_TGT_STATE_DATA_IN;
3378 vha->hw->tgt.tgt_ops->handle_data(cmd);
3379 ql_dbg_qp(ql_dbg_async, qpair, 0xe102,
3380 "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n",
3381 vha->flags.online, qla2x00_reset_active(vha),
3382 cmd->reset_count, qpair->chip_reset);
3386 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3387 /* Does F/W have an IOCBs for this request */
3388 res = qlt_check_reserve_free_req(qpair, prm.req_cnt);
3390 goto out_unlock_free_unmap;
3391 if (cmd->se_cmd.prot_op)
3392 res = qlt_build_ctio_crc2_pkt(qpair, &prm);
3394 res = qlt_24xx_build_ctio_pkt(qpair, &prm);
3396 if (unlikely(res != 0)) {
3397 qpair->req->cnt += prm.req_cnt;
3398 goto out_unlock_free_unmap;
3401 pkt = (struct ctio7_to_24xx *)prm.pkt;
3402 pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT |
3403 CTIO7_FLAGS_STATUS_MODE_0);
3405 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
3406 qlt_load_data_segments(&prm);
3408 cmd->state = QLA_TGT_STATE_NEED_DATA;
3409 cmd->cmd_sent_to_fw = 1;
3410 cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
3412 /* Memory Barrier */
3414 if (qpair->reqq_start_iocbs)
3415 qpair->reqq_start_iocbs(qpair);
3417 qla2x00_start_iocbs(vha, qpair->req);
3418 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3422 out_unlock_free_unmap:
3423 qlt_unmap_sg(vha, cmd);
3424 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3428 EXPORT_SYMBOL(qlt_rdy_to_xfer);
3432 * it is assumed either hardware_lock or qpair lock is held.
3435 qlt_handle_dif_error(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd,
3436 struct ctio_crc_from_fw *sts)
3438 uint8_t *ap = &sts->actual_dif[0];
3439 uint8_t *ep = &sts->expected_dif[0];
3440 uint64_t lba = cmd->se_cmd.t_task_lba;
3441 uint8_t scsi_status, sense_key, asc, ascq;
3442 unsigned long flags;
3443 struct scsi_qla_host *vha = cmd->vha;
3445 cmd->trc_flags |= TRC_DIF_ERR;
3447 cmd->a_guard = be16_to_cpu(*(uint16_t *)(ap + 0));
3448 cmd->a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2));
3449 cmd->a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4));
3451 cmd->e_guard = be16_to_cpu(*(uint16_t *)(ep + 0));
3452 cmd->e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2));
3453 cmd->e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4));
3455 ql_dbg(ql_dbg_tgt_dif, vha, 0xf075,
3456 "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state);
3458 scsi_status = sense_key = asc = ascq = 0;
3460 /* check appl tag */
3461 if (cmd->e_app_tag != cmd->a_app_tag) {
3462 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d,
3463 "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]",
3464 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3465 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3466 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3467 cmd->atio.u.isp24.fcp_hdr.ox_id);
3469 cmd->dif_err_code = DIF_ERR_APP;
3470 scsi_status = SAM_STAT_CHECK_CONDITION;
3471 sense_key = ABORTED_COMMAND;
3477 if (cmd->e_ref_tag != cmd->a_ref_tag) {
3478 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e,
3479 "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] ",
3480 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3481 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3482 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3483 cmd->atio.u.isp24.fcp_hdr.ox_id);
3485 cmd->dif_err_code = DIF_ERR_REF;
3486 scsi_status = SAM_STAT_CHECK_CONDITION;
3487 sense_key = ABORTED_COMMAND;
3494 if (cmd->e_guard != cmd->a_guard) {
3495 ql_dbg(ql_dbg_tgt_dif, vha, 0xe012,
3496 "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]",
3497 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3498 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3499 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3500 cmd->atio.u.isp24.fcp_hdr.ox_id);
3502 cmd->dif_err_code = DIF_ERR_GRD;
3503 scsi_status = SAM_STAT_CHECK_CONDITION;
3504 sense_key = ABORTED_COMMAND;
3509 switch (cmd->state) {
3510 case QLA_TGT_STATE_NEED_DATA:
3511 /* handle_data will load DIF error code */
3512 cmd->state = QLA_TGT_STATE_DATA_IN;
3513 vha->hw->tgt.tgt_ops->handle_data(cmd);
3516 spin_lock_irqsave(&cmd->cmd_lock, flags);
3518 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3519 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3522 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3524 qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc,
3526 /* assume scsi status gets out on the wire.
3527 * Will not wait for completion.
3529 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3534 /* If hardware_lock held on entry, might drop it, then reaquire */
3535 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
3536 static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha,
3537 struct imm_ntfy_from_isp *ntfy)
3539 struct nack_to_isp *nack;
3540 struct qla_hw_data *ha = vha->hw;
3544 ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c,
3545 "Sending TERM ELS CTIO (ha=%p)\n", ha);
3547 pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL);
3549 ql_dbg(ql_dbg_tgt, vha, 0xe080,
3550 "qla_target(%d): %s failed: unable to allocate "
3551 "request packet\n", vha->vp_idx, __func__);
3555 pkt->entry_type = NOTIFY_ACK_TYPE;
3556 pkt->entry_count = 1;
3557 pkt->handle = QLA_TGT_SKIP_HANDLE;
3559 nack = (struct nack_to_isp *)pkt;
3560 nack->ox_id = ntfy->ox_id;
3562 nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
3563 if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
3564 nack->u.isp24.flags = ntfy->u.isp24.flags &
3565 __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB);
3569 nack->u.isp24.flags |=
3570 __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE);
3572 nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
3573 nack->u.isp24.status = ntfy->u.isp24.status;
3574 nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode;
3575 nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle;
3576 nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address;
3577 nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs;
3578 nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui;
3579 nack->u.isp24.vp_index = ntfy->u.isp24.vp_index;
3581 qla2x00_start_iocbs(vha, vha->req);
3585 static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
3586 struct imm_ntfy_from_isp *imm, int ha_locked)
3590 WARN_ON_ONCE(!ha_locked);
3591 rc = __qlt_send_term_imm_notif(vha, imm);
3592 pr_debug("rc = %d\n", rc);
3596 * If hardware_lock held on entry, might drop it, then reaquire
3597 * This function sends the appropriate CTIO to ISP 2xxx or 24xx
3599 static int __qlt_send_term_exchange(struct qla_qpair *qpair,
3600 struct qla_tgt_cmd *cmd,
3601 struct atio_from_isp *atio)
3603 struct scsi_qla_host *vha = qpair->vha;
3604 struct ctio7_to_24xx *ctio24;
3605 struct qla_hw_data *ha = vha->hw;
3610 ql_dbg(ql_dbg_tgt, vha, 0xe009, "Sending TERM EXCH CTIO (ha=%p)\n", ha);
3615 pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL);
3617 ql_dbg(ql_dbg_tgt, vha, 0xe050,
3618 "qla_target(%d): %s failed: unable to allocate "
3619 "request packet\n", vha->vp_idx, __func__);
3624 if (cmd->state < QLA_TGT_STATE_PROCESSED) {
3625 ql_dbg(ql_dbg_tgt, vha, 0xe051,
3626 "qla_target(%d): Terminating cmd %p with "
3627 "incorrect state %d\n", vha->vp_idx, cmd,
3633 qpair->tgt_counters.num_term_xchg_sent++;
3634 pkt->entry_count = 1;
3635 pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
3637 ctio24 = (struct ctio7_to_24xx *)pkt;
3638 ctio24->entry_type = CTIO_TYPE7;
3639 ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED;
3640 ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
3641 ctio24->vp_index = vha->vp_idx;
3642 ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
3643 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
3644 temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 |
3645 CTIO7_FLAGS_TERMINATE;
3646 ctio24->u.status1.flags = cpu_to_le16(temp);
3647 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
3648 ctio24->u.status1.ox_id = cpu_to_le16(temp);
3650 /* Memory Barrier */
3652 if (qpair->reqq_start_iocbs)
3653 qpair->reqq_start_iocbs(qpair);
3655 qla2x00_start_iocbs(vha, qpair->req);
3659 static void qlt_send_term_exchange(struct qla_qpair *qpair,
3660 struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked,
3663 struct scsi_qla_host *vha;
3664 unsigned long flags = 0;
3667 /* why use different vha? NPIV */
3674 rc = __qlt_send_term_exchange(qpair, cmd, atio);
3676 qlt_alloc_qfull_cmd(vha, atio, 0, 0);
3679 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3680 rc = __qlt_send_term_exchange(qpair, cmd, atio);
3682 qlt_alloc_qfull_cmd(vha, atio, 0, 0);
3685 if (cmd && !ul_abort && !cmd->aborted) {
3687 qlt_unmap_sg(vha, cmd);
3688 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3692 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3697 static void qlt_init_term_exchange(struct scsi_qla_host *vha)
3699 struct list_head free_list;
3700 struct qla_tgt_cmd *cmd, *tcmd;
3702 vha->hw->tgt.leak_exchg_thresh_hold =
3703 (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT;
3706 if (!list_empty(&vha->hw->tgt.q_full_list)) {
3707 INIT_LIST_HEAD(&free_list);
3708 list_splice_init(&vha->hw->tgt.q_full_list, &free_list);
3710 list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) {
3711 list_del(&cmd->cmd_list);
3712 /* This cmd was never sent to TCM. There is no need
3713 * to schedule free or call free_cmd
3716 vha->hw->tgt.num_qfull_cmds_alloc--;
3719 vha->hw->tgt.num_qfull_cmds_dropped = 0;
3722 static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha)
3724 uint32_t total_leaked;
3726 total_leaked = vha->hw->tgt.num_qfull_cmds_dropped;
3728 if (vha->hw->tgt.leak_exchg_thresh_hold &&
3729 (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) {
3731 ql_dbg(ql_dbg_tgt, vha, 0xe079,
3732 "Chip reset due to exchange starvation: %d/%d.\n",
3733 total_leaked, vha->hw->cur_fw_xcb_count);
3735 if (IS_P3P_TYPE(vha->hw))
3736 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
3738 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3739 qla2xxx_wake_dpc(vha);
3744 int qlt_abort_cmd(struct qla_tgt_cmd *cmd)
3746 struct qla_tgt *tgt = cmd->tgt;
3747 struct scsi_qla_host *vha = tgt->vha;
3748 struct se_cmd *se_cmd = &cmd->se_cmd;
3749 unsigned long flags;
3751 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014,
3752 "qla_target(%d): terminating exchange for aborted cmd=%p "
3753 "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd,
3756 spin_lock_irqsave(&cmd->cmd_lock, flags);
3758 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3760 * It's normal to see 2 calls in this path:
3761 * 1) XFER Rdy completion + CMD_T_ABORT
3762 * 2) TCM TMR - drain_state_list
3764 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016,
3765 "multiple abort. %p transport_state %x, t_state %x, "
3766 "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state,
3767 cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags);
3771 cmd->trc_flags |= TRC_ABORT;
3772 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3774 qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1);
3777 EXPORT_SYMBOL(qlt_abort_cmd);
3779 void qlt_free_cmd(struct qla_tgt_cmd *cmd)
3781 struct fc_port *sess = cmd->sess;
3783 ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074,
3784 "%s: se_cmd[%p] ox_id %04x\n",
3785 __func__, &cmd->se_cmd,
3786 be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
3788 BUG_ON(cmd->cmd_in_wq);
3791 qlt_unmap_sg(cmd->vha, cmd);
3794 qlt_decr_num_pend_cmds(cmd->vha);
3796 BUG_ON(cmd->sg_mapped);
3797 cmd->jiffies_at_free = get_jiffies_64();
3798 if (unlikely(cmd->free_sg))
3801 if (!sess || !sess->se_sess) {
3805 cmd->jiffies_at_free = get_jiffies_64();
3806 target_free_tag(sess->se_sess, &cmd->se_cmd);
3808 EXPORT_SYMBOL(qlt_free_cmd);
3811 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3813 static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio,
3814 struct qla_tgt_cmd *cmd, uint32_t status)
3817 struct scsi_qla_host *vha = qpair->vha;
3819 if (cmd->se_cmd.prot_op)
3820 ql_dbg(ql_dbg_tgt_dif, vha, 0xe013,
3821 "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] "
3822 "se_cmd=%p tag[%x] op %#x/%s",
3824 cmd->num_blks, &cmd->se_cmd,
3825 cmd->atio.u.isp24.exchange_addr,
3826 cmd->se_cmd.prot_op,
3827 prot_op_str(cmd->se_cmd.prot_op));
3830 struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio;
3833 cpu_to_le16(OF_TERM_EXCH));
3838 qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1, 0);
3844 /* ha->hardware_lock supposed to be held on entry */
3845 static void *qlt_ctio_to_cmd(struct scsi_qla_host *vha,
3846 struct rsp_que *rsp, uint32_t handle, void *ctio)
3849 struct req_que *req;
3850 int qid = GET_QID(handle);
3851 uint32_t h = handle & ~QLA_TGT_HANDLE_MASK;
3853 if (unlikely(h == QLA_TGT_SKIP_HANDLE))
3856 if (qid == rsp->req->id) {
3858 } else if (vha->hw->req_q_map[qid]) {
3859 ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a,
3860 "qla_target(%d): CTIO completion with different QID %d handle %x\n",
3861 vha->vp_idx, rsp->id, handle);
3862 req = vha->hw->req_q_map[qid];
3867 h &= QLA_CMD_HANDLE_MASK;
3869 if (h != QLA_TGT_NULL_HANDLE) {
3870 if (unlikely(h >= req->num_outstanding_cmds)) {
3871 ql_dbg(ql_dbg_tgt, vha, 0xe052,
3872 "qla_target(%d): Wrong handle %x received\n",
3873 vha->vp_idx, handle);
3877 cmd = (void *) req->outstanding_cmds[h];
3878 if (unlikely(cmd == NULL)) {
3879 ql_dbg(ql_dbg_async, vha, 0xe053,
3880 "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n",
3881 vha->vp_idx, handle, req->id, rsp->id);
3884 req->outstanding_cmds[h] = NULL;
3885 } else if (ctio != NULL) {
3886 /* We can't get loop ID from CTIO7 */
3887 ql_dbg(ql_dbg_tgt, vha, 0xe054,
3888 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
3889 "support NULL handles\n", vha->vp_idx);
3897 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3899 static void qlt_do_ctio_completion(struct scsi_qla_host *vha,
3900 struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio)
3902 struct qla_hw_data *ha = vha->hw;
3903 struct se_cmd *se_cmd;
3904 struct qla_tgt_cmd *cmd;
3905 struct qla_qpair *qpair = rsp->qpair;
3907 if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) {
3908 /* That could happen only in case of an error/reset/abort */
3909 if (status != CTIO_SUCCESS) {
3910 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d,
3911 "Intermediate CTIO received"
3912 " (status %x)\n", status);
3917 cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio);
3921 se_cmd = &cmd->se_cmd;
3922 cmd->cmd_sent_to_fw = 0;
3924 qlt_unmap_sg(vha, cmd);
3926 if (unlikely(status != CTIO_SUCCESS)) {
3927 switch (status & 0xFFFF) {
3928 case CTIO_INVALID_RX_ID:
3929 if (printk_ratelimit())
3930 dev_info(&vha->hw->pdev->dev,
3931 "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n",
3932 vha->vp_idx, cmd->atio.u.isp24.attr,
3933 ((cmd->ctio_flags >> 9) & 0xf),
3937 case CTIO_LIP_RESET:
3938 case CTIO_TARGET_RESET:
3940 /* driver request abort via Terminate exchange */
3943 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058,
3944 "qla_target(%d): CTIO with "
3945 "status %#x received, state %x, se_cmd %p, "
3946 "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
3947 "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx,
3948 status, cmd->state, se_cmd);
3951 case CTIO_PORT_LOGGED_OUT:
3952 case CTIO_PORT_UNAVAILABLE:
3955 (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT;
3957 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059,
3958 "qla_target(%d): CTIO with %s status %x "
3959 "received (state %x, se_cmd %p)\n", vha->vp_idx,
3960 logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE",
3961 status, cmd->state, se_cmd);
3963 if (logged_out && cmd->sess) {
3965 * Session is already logged out, but we need
3966 * to notify initiator, who's not aware of this
3968 cmd->sess->send_els_logo = 1;
3969 ql_dbg(ql_dbg_disc, vha, 0x20f8,
3970 "%s %d %8phC post del sess\n",
3971 __func__, __LINE__, cmd->sess->port_name);
3973 qlt_schedule_sess_for_deletion(cmd->sess);
3977 case CTIO_DIF_ERROR: {
3978 struct ctio_crc_from_fw *crc =
3979 (struct ctio_crc_from_fw *)ctio;
3980 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073,
3981 "qla_target(%d): CTIO with DIF_ERROR status %x "
3982 "received (state %x, ulp_cmd %p) actual_dif[0x%llx] "
3983 "expect_dif[0x%llx]\n",
3984 vha->vp_idx, status, cmd->state, se_cmd,
3985 *((u64 *)&crc->actual_dif[0]),
3986 *((u64 *)&crc->expected_dif[0]));
3988 qlt_handle_dif_error(qpair, cmd, ctio);
3992 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b,
3993 "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n",
3994 vha->vp_idx, status, cmd->state, se_cmd);
3999 /* "cmd->aborted" means
4000 * cmd is already aborted/terminated, we don't
4001 * need to terminate again. The exchange is already
4002 * cleaned up/freed at FW level. Just cleanup at driver
4005 if ((cmd->state != QLA_TGT_STATE_NEED_DATA) &&
4007 cmd->trc_flags |= TRC_CTIO_ERR;
4008 if (qlt_term_ctio_exchange(qpair, ctio, cmd, status))
4013 if (cmd->state == QLA_TGT_STATE_PROCESSED) {
4014 cmd->trc_flags |= TRC_CTIO_DONE;
4015 } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) {
4016 cmd->state = QLA_TGT_STATE_DATA_IN;
4018 if (status == CTIO_SUCCESS)
4019 cmd->write_data_transferred = 1;
4021 ha->tgt.tgt_ops->handle_data(cmd);
4023 } else if (cmd->aborted) {
4024 cmd->trc_flags |= TRC_CTIO_ABORTED;
4025 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e,
4026 "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag);
4028 cmd->trc_flags |= TRC_CTIO_STRANGE;
4029 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c,
4030 "qla_target(%d): A command in state (%d) should "
4031 "not return a CTIO complete\n", vha->vp_idx, cmd->state);
4034 if (unlikely(status != CTIO_SUCCESS) &&
4036 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n");
4040 ha->tgt.tgt_ops->free_cmd(cmd);
4043 static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha,
4048 switch (task_codes) {
4049 case ATIO_SIMPLE_QUEUE:
4050 fcp_task_attr = TCM_SIMPLE_TAG;
4052 case ATIO_HEAD_OF_QUEUE:
4053 fcp_task_attr = TCM_HEAD_TAG;
4055 case ATIO_ORDERED_QUEUE:
4056 fcp_task_attr = TCM_ORDERED_TAG;
4058 case ATIO_ACA_QUEUE:
4059 fcp_task_attr = TCM_ACA_TAG;
4062 fcp_task_attr = TCM_SIMPLE_TAG;
4065 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d,
4066 "qla_target: unknown task code %x, use ORDERED instead\n",
4068 fcp_task_attr = TCM_ORDERED_TAG;
4072 return fcp_task_attr;
4076 * Process context for I/O path into tcm_qla2xxx code
4078 static void __qlt_do_work(struct qla_tgt_cmd *cmd)
4080 scsi_qla_host_t *vha = cmd->vha;
4081 struct qla_hw_data *ha = vha->hw;
4082 struct fc_port *sess = cmd->sess;
4083 struct atio_from_isp *atio = &cmd->atio;
4085 unsigned long flags;
4086 uint32_t data_length;
4087 int ret, fcp_task_attr, data_dir, bidi = 0;
4088 struct qla_qpair *qpair = cmd->qpair;
4091 cmd->trc_flags |= TRC_DO_WORK;
4094 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082,
4095 "cmd with tag %u is aborted\n",
4096 cmd->atio.u.isp24.exchange_addr);
4100 spin_lock_init(&cmd->cmd_lock);
4101 cdb = &atio->u.isp24.fcp_cmnd.cdb[0];
4102 cmd->se_cmd.tag = atio->u.isp24.exchange_addr;
4104 if (atio->u.isp24.fcp_cmnd.rddata &&
4105 atio->u.isp24.fcp_cmnd.wrdata) {
4107 data_dir = DMA_TO_DEVICE;
4108 } else if (atio->u.isp24.fcp_cmnd.rddata)
4109 data_dir = DMA_FROM_DEVICE;
4110 else if (atio->u.isp24.fcp_cmnd.wrdata)
4111 data_dir = DMA_TO_DEVICE;
4113 data_dir = DMA_NONE;
4115 fcp_task_attr = qlt_get_fcp_task_attr(vha,
4116 atio->u.isp24.fcp_cmnd.task_attr);
4117 data_length = get_datalen_for_atio(atio);
4119 ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length,
4120 fcp_task_attr, data_dir, bidi);
4124 * Drop extra session reference from qlt_handle_cmd_for_atio().
4126 ha->tgt.tgt_ops->put_sess(sess);
4130 ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd);
4132 * cmd has not sent to target yet, so pass NULL as the second
4133 * argument to qlt_send_term_exchange() and free the memory here.
4135 cmd->trc_flags |= TRC_DO_WORK_ERR;
4136 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
4137 qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0);
4139 qlt_decr_num_pend_cmds(vha);
4140 target_free_tag(sess->se_sess, &cmd->se_cmd);
4141 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
4143 ha->tgt.tgt_ops->put_sess(sess);
4146 static void qlt_do_work(struct work_struct *work)
4148 struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work);
4149 scsi_qla_host_t *vha = cmd->vha;
4150 unsigned long flags;
4152 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4153 list_del(&cmd->cmd_list);
4154 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4159 void qlt_clr_qp_table(struct scsi_qla_host *vha)
4161 unsigned long flags;
4162 struct qla_hw_data *ha = vha->hw;
4163 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4167 ql_log(ql_log_info, vha, 0x706c,
4168 "User update Number of Active Qpairs %d\n",
4169 ha->tgt.num_act_qpairs);
4171 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
4173 btree_for_each_safe64(&tgt->lun_qpair_map, key, node)
4174 btree_remove64(&tgt->lun_qpair_map, key);
4176 ha->base_qpair->lun_cnt = 0;
4177 for (key = 0; key < ha->max_qpairs; key++)
4178 if (ha->queue_pair_map[key])
4179 ha->queue_pair_map[key]->lun_cnt = 0;
4181 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
4184 static void qlt_assign_qpair(struct scsi_qla_host *vha,
4185 struct qla_tgt_cmd *cmd)
4187 struct qla_qpair *qpair, *qp;
4188 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4189 struct qla_qpair_hint *h;
4191 if (vha->flags.qpairs_available) {
4192 h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun);
4194 /* spread lun to qpair ratio evently */
4196 struct scsi_qla_host *base_vha =
4197 pci_get_drvdata(vha->hw->pdev);
4199 qpair = vha->hw->base_qpair;
4200 if (qpair->lun_cnt == 0) {
4202 h = qla_qpair_to_hint(tgt, qpair);
4204 rc = btree_insert64(&tgt->lun_qpair_map,
4205 cmd->unpacked_lun, h, GFP_ATOMIC);
4208 ql_log(ql_log_info, vha, 0xd037,
4209 "Unable to insert lun %llx into lun_qpair_map\n",
4214 lcnt = qpair->lun_cnt;
4218 list_for_each_entry(qp, &base_vha->qp_list,
4220 if (qp->lun_cnt == 0) {
4222 h = qla_qpair_to_hint(tgt, qp);
4224 rc = btree_insert64(&tgt->lun_qpair_map,
4225 cmd->unpacked_lun, h, GFP_ATOMIC);
4228 ql_log(ql_log_info, vha, 0xd038,
4229 "Unable to insert lun %llx into lun_qpair_map\n",
4235 if (qp->lun_cnt < lcnt) {
4244 h = qla_qpair_to_hint(tgt, qpair);
4246 rc = btree_insert64(&tgt->lun_qpair_map,
4247 cmd->unpacked_lun, h, GFP_ATOMIC);
4250 ql_log(ql_log_info, vha, 0xd039,
4251 "Unable to insert lun %llx into lun_qpair_map\n",
4256 h = &tgt->qphints[0];
4259 cmd->qpair = h->qpair;
4260 cmd->se_cmd.cpuid = h->cpuid;
4263 static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha,
4264 struct fc_port *sess,
4265 struct atio_from_isp *atio)
4267 struct se_session *se_sess = sess->se_sess;
4268 struct qla_tgt_cmd *cmd;
4271 tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu);
4275 cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag];
4276 memset(cmd, 0, sizeof(struct qla_tgt_cmd));
4277 cmd->cmd_type = TYPE_TGT_CMD;
4278 memcpy(&cmd->atio, atio, sizeof(*atio));
4279 cmd->state = QLA_TGT_STATE_NEW;
4280 cmd->tgt = vha->vha_tgt.qla_tgt;
4281 qlt_incr_num_pend_cmds(vha);
4283 cmd->se_cmd.map_tag = tag;
4284 cmd->se_cmd.map_cpu = cpu;
4286 cmd->loop_id = sess->loop_id;
4287 cmd->conf_compl_supported = sess->conf_compl_supported;
4290 cmd->jiffies_at_alloc = get_jiffies_64();
4292 cmd->unpacked_lun = scsilun_to_int(
4293 (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun);
4294 qlt_assign_qpair(vha, cmd);
4295 cmd->reset_count = vha->hw->base_qpair->chip_reset;
4296 cmd->vp_idx = vha->vp_idx;
4301 /* ha->hardware_lock supposed to be held on entry */
4302 static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha,
4303 struct atio_from_isp *atio)
4305 struct qla_hw_data *ha = vha->hw;
4306 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4307 struct fc_port *sess;
4308 struct qla_tgt_cmd *cmd;
4309 unsigned long flags;
4312 if (unlikely(tgt->tgt_stop)) {
4313 ql_dbg(ql_dbg_io, vha, 0x3061,
4314 "New command while device %p is shutting down\n", tgt);
4318 id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
4319 if (IS_SW_RESV_ADDR(id))
4322 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id);
4323 if (unlikely(!sess))
4326 /* Another WWN used to have our s_id. Our PLOGI scheduled its
4327 * session deletion, but it's still in sess_del_work wq */
4328 if (sess->deleted) {
4329 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002,
4330 "New command while old session %p is being deleted\n",
4336 * Do kref_get() before returning + dropping qla_hw_data->hardware_lock.
4338 if (!kref_get_unless_zero(&sess->sess_kref)) {
4339 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004,
4340 "%s: kref_get fail, %8phC oxid %x \n",
4341 __func__, sess->port_name,
4342 be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
4346 cmd = qlt_get_tag(vha, sess, atio);
4348 ql_dbg(ql_dbg_io, vha, 0x3062,
4349 "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx);
4350 ha->tgt.tgt_ops->put_sess(sess);
4355 cmd->trc_flags |= TRC_NEW_CMD;
4357 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4358 list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list);
4359 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4361 INIT_WORK(&cmd->work, qlt_do_work);
4362 if (vha->flags.qpairs_available) {
4363 queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work);
4364 } else if (ha->msix_count) {
4365 if (cmd->atio.u.isp24.fcp_cmnd.rddata)
4366 queue_work_on(smp_processor_id(), qla_tgt_wq,
4369 queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq,
4372 queue_work(qla_tgt_wq, &cmd->work);
4378 /* ha->hardware_lock supposed to be held on entry */
4379 static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun,
4380 int fn, void *iocb, int flags)
4382 struct scsi_qla_host *vha = sess->vha;
4383 struct qla_hw_data *ha = vha->hw;
4384 struct qla_tgt_mgmt_cmd *mcmd;
4385 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4386 struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0];
4388 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
4390 ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009,
4391 "qla_target(%d): Allocation of management "
4392 "command failed, some commands and their data could "
4393 "leak\n", vha->vp_idx);
4396 memset(mcmd, 0, sizeof(*mcmd));
4400 memcpy(&mcmd->orig_iocb.imm_ntfy, iocb,
4401 sizeof(mcmd->orig_iocb.imm_ntfy));
4403 mcmd->tmr_func = fn;
4404 mcmd->flags = flags;
4405 mcmd->reset_count = ha->base_qpair->chip_reset;
4406 mcmd->qpair = h->qpair;
4408 mcmd->se_cmd.cpuid = h->cpuid;
4409 mcmd->unpacked_lun = lun;
4412 case QLA_TGT_LUN_RESET:
4413 case QLA_TGT_CLEAR_TS:
4414 case QLA_TGT_ABORT_TS:
4415 abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id);
4417 case QLA_TGT_CLEAR_ACA:
4418 h = qlt_find_qphint(vha, mcmd->unpacked_lun);
4419 mcmd->qpair = h->qpair;
4420 mcmd->se_cmd.cpuid = h->cpuid;
4423 case QLA_TGT_TARGET_RESET:
4424 case QLA_TGT_NEXUS_LOSS_SESS:
4425 case QLA_TGT_NEXUS_LOSS:
4426 case QLA_TGT_ABORT_ALL:
4432 INIT_WORK(&mcmd->work, qlt_do_tmr_work);
4433 queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq,
4439 /* ha->hardware_lock supposed to be held on entry */
4440 static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb)
4442 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4443 struct qla_hw_data *ha = vha->hw;
4444 struct fc_port *sess;
4447 unsigned long flags;
4449 fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
4451 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
4452 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha,
4453 a->u.isp24.fcp_hdr.s_id);
4454 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
4457 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
4459 if (sess == NULL || sess->deleted)
4462 return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
4465 /* ha->hardware_lock supposed to be held on entry */
4466 static int __qlt_abort_task(struct scsi_qla_host *vha,
4467 struct imm_ntfy_from_isp *iocb, struct fc_port *sess)
4469 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4470 struct qla_hw_data *ha = vha->hw;
4471 struct qla_tgt_mgmt_cmd *mcmd;
4475 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
4477 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f,
4478 "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
4479 vha->vp_idx, __func__);
4482 memset(mcmd, 0, sizeof(*mcmd));
4485 memcpy(&mcmd->orig_iocb.imm_ntfy, iocb,
4486 sizeof(mcmd->orig_iocb.imm_ntfy));
4489 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
4490 mcmd->reset_count = ha->base_qpair->chip_reset;
4491 mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK;
4492 mcmd->qpair = ha->base_qpair;
4494 rc = ha->tgt.tgt_ops->handle_tmr(mcmd, unpacked_lun, mcmd->tmr_func,
4495 le16_to_cpu(iocb->u.isp2x.seq_id));
4497 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060,
4498 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
4500 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
4507 /* ha->hardware_lock supposed to be held on entry */
4508 static int qlt_abort_task(struct scsi_qla_host *vha,
4509 struct imm_ntfy_from_isp *iocb)
4511 struct qla_hw_data *ha = vha->hw;
4512 struct fc_port *sess;
4514 unsigned long flags;
4516 loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb);
4518 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
4519 sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
4520 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
4523 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025,
4524 "qla_target(%d): task abort for unexisting "
4525 "session\n", vha->vp_idx);
4526 return qlt_sched_sess_work(vha->vha_tgt.qla_tgt,
4527 QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb));
4530 return __qlt_abort_task(vha, iocb, sess);
4533 void qlt_logo_completion_handler(fc_port_t *fcport, int rc)
4535 if (rc != MBS_COMMAND_COMPLETE) {
4536 ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093,
4537 "%s: se_sess %p / sess %p from"
4538 " port %8phC loop_id %#04x s_id %02x:%02x:%02x"
4539 " LOGO failed: %#x\n",
4543 fcport->port_name, fcport->loop_id,
4544 fcport->d_id.b.domain, fcport->d_id.b.area,
4545 fcport->d_id.b.al_pa, rc);
4548 fcport->logout_completed = 1;
4552 * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list)
4554 * Schedules sessions with matching port_id/loop_id but different wwn for
4555 * deletion. Returns existing session with matching wwn if present.
4559 qlt_find_sess_invalidate_other(scsi_qla_host_t *vha, uint64_t wwn,
4560 port_id_t port_id, uint16_t loop_id, struct fc_port **conflict_sess)
4562 struct fc_port *sess = NULL, *other_sess;
4565 *conflict_sess = NULL;
4567 list_for_each_entry(other_sess, &vha->vp_fcports, list) {
4569 other_wwn = wwn_to_u64(other_sess->port_name);
4571 if (wwn == other_wwn) {
4577 /* find other sess with nport_id collision */
4578 if (port_id.b24 == other_sess->d_id.b24) {
4579 if (loop_id != other_sess->loop_id) {
4580 ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000c,
4581 "Invalidating sess %p loop_id %d wwn %llx.\n",
4582 other_sess, other_sess->loop_id, other_wwn);
4585 * logout_on_delete is set by default, but another
4586 * session that has the same s_id/loop_id combo
4587 * might have cleared it when requested this session
4588 * deletion, so don't touch it
4590 qlt_schedule_sess_for_deletion(other_sess);
4593 * Another wwn used to have our s_id/loop_id
4594 * kill the session, but don't free the loop_id
4596 ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01b,
4597 "Invalidating sess %p loop_id %d wwn %llx.\n",
4598 other_sess, other_sess->loop_id, other_wwn);
4600 other_sess->keep_nport_handle = 1;
4601 if (other_sess->disc_state != DSC_DELETED)
4602 *conflict_sess = other_sess;
4603 qlt_schedule_sess_for_deletion(other_sess);
4608 /* find other sess with nport handle collision */
4609 if ((loop_id == other_sess->loop_id) &&
4610 (loop_id != FC_NO_LOOP_ID)) {
4611 ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000d,
4612 "Invalidating sess %p loop_id %d wwn %llx.\n",
4613 other_sess, other_sess->loop_id, other_wwn);
4615 /* Same loop_id but different s_id
4616 * Ok to kill and logout */
4617 qlt_schedule_sess_for_deletion(other_sess);
4624 /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */
4625 static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id)
4627 struct qla_tgt_sess_op *op;
4628 struct qla_tgt_cmd *cmd;
4631 unsigned long flags;
4633 key = (((u32)s_id->b.domain << 16) |
4634 ((u32)s_id->b.area << 8) |
4635 ((u32)s_id->b.al_pa));
4637 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4638 list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) {
4639 uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
4641 if (op_key == key) {
4647 list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
4648 uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
4650 if (op_key == key) {
4656 list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
4657 uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id);
4659 if (cmd_key == key) {
4664 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4669 static int qlt_handle_login(struct scsi_qla_host *vha,
4670 struct imm_ntfy_from_isp *iocb)
4672 struct fc_port *sess = NULL, *conflict_sess = NULL;
4675 uint16_t loop_id, wd3_lo;
4677 struct qlt_plogi_ack_t *pla;
4678 unsigned long flags;
4680 lockdep_assert_held(&vha->hw->hardware_lock);
4682 wwn = wwn_to_u64(iocb->u.isp24.port_name);
4684 port_id.b.domain = iocb->u.isp24.port_id[2];
4685 port_id.b.area = iocb->u.isp24.port_id[1];
4686 port_id.b.al_pa = iocb->u.isp24.port_id[0];
4687 port_id.b.rsvd_1 = 0;
4689 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
4691 /* Mark all stale commands sitting in qla_tgt_wq for deletion */
4692 abort_cmds_for_s_id(vha, &port_id);
4695 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4696 sess = qlt_find_sess_invalidate_other(vha, wwn,
4697 port_id, loop_id, &conflict_sess);
4698 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4700 ql_dbg(ql_dbg_disc, vha, 0xffff,
4701 "%s %d Term INOT due to WWN=0 lid=%d, NportID %06X ",
4702 __func__, __LINE__, loop_id, port_id.b24);
4703 qlt_send_term_imm_notif(vha, iocb, 1);
4707 if (IS_SW_RESV_ADDR(port_id)) {
4712 pla = qlt_plogi_ack_find_add(vha, &port_id, iocb);
4714 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
4715 "%s %d %8phC Term INOT due to mem alloc fail",
4717 iocb->u.isp24.port_name);
4718 qlt_send_term_imm_notif(vha, iocb, 1);
4722 if (conflict_sess) {
4723 conflict_sess->login_gen++;
4724 qlt_plogi_ack_link(vha, pla, conflict_sess,
4725 QLT_PLOGI_LINK_CONFLICT);
4730 ql_dbg(ql_dbg_disc, vha, 0xffff,
4731 "%s %d %8phC post new sess\n",
4732 __func__, __LINE__, iocb->u.isp24.port_name);
4733 if (iocb->u.isp24.status_subcode == ELS_PLOGI)
4734 qla24xx_post_newsess_work(vha, &port_id,
4735 iocb->u.isp24.port_name,
4736 iocb->u.isp24.u.plogi.node_name,
4737 pla, FC4_TYPE_UNKNOWN);
4739 qla24xx_post_newsess_work(vha, &port_id,
4740 iocb->u.isp24.port_name, NULL,
4741 pla, FC4_TYPE_UNKNOWN);
4746 if (sess->disc_state == DSC_UPD_FCPORT) {
4750 * Remote port registration is still going on from
4751 * previous login. Allow it to finish before we
4752 * accept the new login.
4754 sess->next_disc_state = DSC_DELETE_PEND;
4755 sec = jiffies_to_msecs(jiffies -
4756 sess->jiffies_at_registration) / 1000;
4757 if (sess->sec_since_registration < sec && sec &&
4759 sess->sec_since_registration = sec;
4760 ql_dbg(ql_dbg_disc, vha, 0xffff,
4761 "%s %8phC - Slow Rport registration (%d Sec)\n",
4762 __func__, sess->port_name, sec);
4765 if (!conflict_sess) {
4766 list_del(&pla->list);
4767 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4770 qlt_send_term_imm_notif(vha, iocb, 1);
4774 qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN);
4775 sess->d_id = port_id;
4778 if (iocb->u.isp24.status_subcode == ELS_PRLI) {
4779 sess->fw_login_state = DSC_LS_PRLI_PEND;
4781 sess->loop_id = loop_id;
4782 sess->d_id = port_id;
4783 sess->fw_login_state = DSC_LS_PRLI_PEND;
4784 wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo);
4787 sess->conf_compl_supported = 1;
4789 if ((wd3_lo & BIT_4) == 0)
4790 sess->port_type = FCT_INITIATOR;
4792 sess->port_type = FCT_TARGET;
4795 sess->fw_login_state = DSC_LS_PLOGI_PEND;
4798 ql_dbg(ql_dbg_disc, vha, 0x20f9,
4799 "%s %d %8phC DS %d\n",
4800 __func__, __LINE__, sess->port_name, sess->disc_state);
4802 switch (sess->disc_state) {
4804 qlt_plogi_ack_unref(vha, pla);
4809 * Under normal circumstances we want to release nport handle
4810 * during LOGO process to avoid nport handle leaks inside FW.
4811 * The exception is when LOGO is done while another PLOGI with
4812 * the same nport handle is waiting as might be the case here.
4813 * Note: there is always a possibily of a race where session
4814 * deletion has already started for other reasons (e.g. ACL
4815 * removal) and now PLOGI arrives:
4816 * 1. if PLOGI arrived in FW after nport handle has been freed,
4817 * FW must have assigned this PLOGI a new/same handle and we
4818 * can proceed ACK'ing it as usual when session deletion
4820 * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT
4821 * bit reached it, the handle has now been released. We'll
4822 * get an error when we ACK this PLOGI. Nothing will be sent
4823 * back to initiator. Initiator should eventually retry
4824 * PLOGI and situation will correct itself.
4826 sess->keep_nport_handle = ((sess->loop_id == loop_id) &&
4827 (sess->d_id.b24 == port_id.b24));
4829 ql_dbg(ql_dbg_disc, vha, 0x20f9,
4830 "%s %d %8phC post del sess\n",
4831 __func__, __LINE__, sess->port_name);
4834 qlt_schedule_sess_for_deletion(sess);
4842 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4844 static int qlt_24xx_handle_els(struct scsi_qla_host *vha,
4845 struct imm_ntfy_from_isp *iocb)
4847 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4848 struct qla_hw_data *ha = vha->hw;
4849 struct fc_port *sess = NULL, *conflict_sess = NULL;
4855 unsigned long flags;
4857 lockdep_assert_held(&ha->hardware_lock);
4859 wwn = wwn_to_u64(iocb->u.isp24.port_name);
4861 port_id.b.domain = iocb->u.isp24.port_id[2];
4862 port_id.b.area = iocb->u.isp24.port_id[1];
4863 port_id.b.al_pa = iocb->u.isp24.port_id[0];
4864 port_id.b.rsvd_1 = 0;
4866 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
4868 ql_dbg(ql_dbg_disc, vha, 0xf026,
4869 "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n",
4870 vha->vp_idx, iocb->u.isp24.port_id[2],
4871 iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0],
4872 iocb->u.isp24.status_subcode, loop_id,
4873 iocb->u.isp24.port_name);
4875 /* res = 1 means ack at the end of thread
4876 * res = 0 means ack async/later.
4878 switch (iocb->u.isp24.status_subcode) {
4880 res = qlt_handle_login(vha, iocb);
4885 sess = qla2x00_find_fcport_by_wwpn(vha,
4886 iocb->u.isp24.port_name, 1);
4888 if (sess && sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]) {
4889 ql_dbg(ql_dbg_disc, vha, 0xffff,
4890 "%s %d %8phC Term PRLI due to PLOGI ACK not completed\n",
4892 iocb->u.isp24.port_name);
4893 qlt_send_term_imm_notif(vha, iocb, 1);
4897 res = qlt_handle_login(vha, iocb);
4901 if (IS_SW_RESV_ADDR(port_id)) {
4906 wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo);
4909 spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags);
4910 sess = qlt_find_sess_invalidate_other(vha, wwn, port_id,
4911 loop_id, &conflict_sess);
4912 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags);
4915 if (conflict_sess) {
4916 switch (conflict_sess->disc_state) {
4918 case DSC_DELETE_PEND:
4921 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b,
4922 "PRLI with conflicting sess %p port %8phC\n",
4923 conflict_sess, conflict_sess->port_name);
4924 conflict_sess->fw_login_state =
4925 DSC_LS_PORT_UNAVAIL;
4926 qlt_send_term_imm_notif(vha, iocb, 1);
4933 bool delete = false;
4936 spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags);
4937 switch (sess->fw_login_state) {
4938 case DSC_LS_PLOGI_PEND:
4939 case DSC_LS_PLOGI_COMP:
4940 case DSC_LS_PRLI_COMP:
4947 switch (sess->disc_state) {
4948 case DSC_UPD_FCPORT:
4949 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock,
4952 sec = jiffies_to_msecs(jiffies -
4953 sess->jiffies_at_registration)/1000;
4954 if (sess->sec_since_registration < sec && sec &&
4956 sess->sec_since_registration = sec;
4957 ql_dbg(ql_dbg_disc, sess->vha, 0xffff,
4958 "%s %8phC : Slow Rport registration(%d Sec)\n",
4959 __func__, sess->port_name, sec);
4961 qlt_send_term_imm_notif(vha, iocb, 1);
4964 case DSC_LOGIN_PEND:
4966 case DSC_LOGIN_COMPLETE:
4975 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock,
4978 * Impatient initiator sent PRLI before last
4979 * PLOGI could finish. Will force him to re-try,
4980 * while last one finishes.
4982 ql_log(ql_log_warn, sess->vha, 0xf095,
4983 "sess %p PRLI received, before plogi ack.\n",
4985 qlt_send_term_imm_notif(vha, iocb, 1);
4991 * This shouldn't happen under normal circumstances,
4992 * since we have deleted the old session during PLOGI
4994 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096,
4995 "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n",
4996 sess->loop_id, sess, iocb->u.isp24.nport_handle);
4999 sess->loop_id = loop_id;
5000 sess->d_id = port_id;
5001 sess->fw_login_state = DSC_LS_PRLI_PEND;
5004 sess->conf_compl_supported = 1;
5006 if ((wd3_lo & BIT_4) == 0)
5007 sess->port_type = FCT_INITIATOR;
5009 sess->port_type = FCT_TARGET;
5011 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags);
5013 res = 1; /* send notify ack */
5015 /* Make session global (not used in fabric mode) */
5016 if (ha->current_topology != ISP_CFG_F) {
5018 ql_dbg(ql_dbg_disc, vha, 0x20fa,
5019 "%s %d %8phC post nack\n",
5020 __func__, __LINE__, sess->port_name);
5021 qla24xx_post_nack_work(vha, sess, iocb,
5025 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5026 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5027 qla2xxx_wake_dpc(vha);
5031 ql_dbg(ql_dbg_disc, vha, 0x20fb,
5032 "%s %d %8phC post nack\n",
5033 __func__, __LINE__, sess->port_name);
5034 qla24xx_post_nack_work(vha, sess, iocb,
5042 if (le16_to_cpu(iocb->u.isp24.flags) &
5043 NOTIFY24XX_FLAGS_GLOBAL_TPRLO) {
5045 qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS);
5052 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
5053 sess = qla2x00_find_fcport_by_loopid(vha, loop_id);
5054 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
5058 sess->fw_login_state = DSC_LS_LOGO_PEND;
5059 sess->logo_ack_needed = 1;
5060 memcpy(sess->iocb, iocb, IOCB_SIZE);
5063 res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS);
5065 ql_dbg(ql_dbg_disc, vha, 0x20fc,
5066 "%s: logo %llx res %d sess %p ",
5067 __func__, wwn, res, sess);
5070 * cmd went upper layer, look for qlt_xmit_tm_rsp()
5071 * for LOGO_ACK & sess delete
5076 /* cmd did not go to upper layer. */
5078 qlt_schedule_sess_for_deletion(sess);
5081 /* else logo will be ack */
5087 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5089 if (tgt->link_reinit_iocb_pending) {
5090 qlt_send_notify_ack(ha->base_qpair,
5091 &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0);
5092 tgt->link_reinit_iocb_pending = 0;
5095 sess = qla2x00_find_fcport_by_wwpn(vha,
5096 iocb->u.isp24.port_name, 1);
5098 ql_dbg(ql_dbg_disc, vha, 0x20fd,
5099 "sess %p lid %d|%d DS %d LS %d\n",
5100 sess, sess->loop_id, loop_id,
5101 sess->disc_state, sess->fw_login_state);
5104 res = 1; /* send notify ack */
5108 case ELS_FLOGI: /* should never happen */
5110 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061,
5111 "qla_target(%d): Unsupported ELS command %x "
5112 "received\n", vha->vp_idx, iocb->u.isp24.status_subcode);
5113 res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS);
5117 ql_dbg(ql_dbg_disc, vha, 0xf026,
5118 "qla_target(%d): Exit ELS opcode: 0x%02x res %d\n",
5119 vha->vp_idx, iocb->u.isp24.status_subcode, res);
5125 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5127 static void qlt_handle_imm_notify(struct scsi_qla_host *vha,
5128 struct imm_ntfy_from_isp *iocb)
5130 struct qla_hw_data *ha = vha->hw;
5131 uint32_t add_flags = 0;
5132 int send_notify_ack = 1;
5135 lockdep_assert_held(&ha->hardware_lock);
5137 status = le16_to_cpu(iocb->u.isp2x.status);
5139 case IMM_NTFY_LIP_RESET:
5141 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032,
5142 "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
5143 vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle),
5144 iocb->u.isp24.status_subcode);
5146 if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0)
5147 send_notify_ack = 0;
5151 case IMM_NTFY_LIP_LINK_REINIT:
5153 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5155 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033,
5156 "qla_target(%d): LINK REINIT (loop %#x, "
5157 "subcode %x)\n", vha->vp_idx,
5158 le16_to_cpu(iocb->u.isp24.nport_handle),
5159 iocb->u.isp24.status_subcode);
5160 if (tgt->link_reinit_iocb_pending) {
5161 qlt_send_notify_ack(ha->base_qpair,
5162 &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0);
5164 memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb));
5165 tgt->link_reinit_iocb_pending = 1;
5167 * QLogic requires to wait after LINK REINIT for possible
5168 * PDISC or ADISC ELS commands
5170 send_notify_ack = 0;
5174 case IMM_NTFY_PORT_LOGOUT:
5175 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034,
5176 "qla_target(%d): Port logout (loop "
5177 "%#x, subcode %x)\n", vha->vp_idx,
5178 le16_to_cpu(iocb->u.isp24.nport_handle),
5179 iocb->u.isp24.status_subcode);
5181 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0)
5182 send_notify_ack = 0;
5183 /* The sessions will be cleared in the callback, if needed */
5186 case IMM_NTFY_GLBL_TPRLO:
5187 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035,
5188 "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status);
5189 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0)
5190 send_notify_ack = 0;
5191 /* The sessions will be cleared in the callback, if needed */
5194 case IMM_NTFY_PORT_CONFIG:
5195 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036,
5196 "qla_target(%d): Port config changed (%x)\n", vha->vp_idx,
5198 if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0)
5199 send_notify_ack = 0;
5200 /* The sessions will be cleared in the callback, if needed */
5203 case IMM_NTFY_GLBL_LOGO:
5204 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a,
5205 "qla_target(%d): Link failure detected\n",
5207 /* I_T nexus loss */
5208 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0)
5209 send_notify_ack = 0;
5212 case IMM_NTFY_IOCB_OVERFLOW:
5213 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b,
5214 "qla_target(%d): Cannot provide requested "
5215 "capability (IOCB overflowed the immediate notify "
5216 "resource count)\n", vha->vp_idx);
5219 case IMM_NTFY_ABORT_TASK:
5220 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037,
5221 "qla_target(%d): Abort Task (S %08x I %#x -> "
5222 "L %#x)\n", vha->vp_idx,
5223 le16_to_cpu(iocb->u.isp2x.seq_id),
5224 GET_TARGET_ID(ha, (struct atio_from_isp *)iocb),
5225 le16_to_cpu(iocb->u.isp2x.lun));
5226 if (qlt_abort_task(vha, iocb) == 0)
5227 send_notify_ack = 0;
5230 case IMM_NTFY_RESOURCE:
5231 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c,
5232 "qla_target(%d): Out of resources, host %ld\n",
5233 vha->vp_idx, vha->host_no);
5236 case IMM_NTFY_MSG_RX:
5237 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038,
5238 "qla_target(%d): Immediate notify task %x\n",
5239 vha->vp_idx, iocb->u.isp2x.task_flags);
5243 if (qlt_24xx_handle_els(vha, iocb) == 0)
5244 send_notify_ack = 0;
5247 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d,
5248 "qla_target(%d): Received unknown immediate "
5249 "notify status %x\n", vha->vp_idx, status);
5253 if (send_notify_ack)
5254 qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0,
5259 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5260 * This function sends busy to ISP 2xxx or 24xx.
5262 static int __qlt_send_busy(struct qla_qpair *qpair,
5263 struct atio_from_isp *atio, uint16_t status)
5265 struct scsi_qla_host *vha = qpair->vha;
5266 struct ctio7_to_24xx *ctio24;
5267 struct qla_hw_data *ha = vha->hw;
5269 struct fc_port *sess = NULL;
5270 unsigned long flags;
5274 id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
5276 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
5277 sess = qla2x00_find_fcport_by_nportid(vha, &id, 1);
5278 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
5280 qlt_send_term_exchange(qpair, NULL, atio, 1, 0);
5283 /* Sending marker isn't necessary, since we called from ISR */
5285 pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL);
5287 ql_dbg(ql_dbg_io, vha, 0x3063,
5288 "qla_target(%d): %s failed: unable to allocate "
5289 "request packet", vha->vp_idx, __func__);
5293 qpair->tgt_counters.num_q_full_sent++;
5294 pkt->entry_count = 1;
5295 pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
5297 ctio24 = (struct ctio7_to_24xx *)pkt;
5298 ctio24->entry_type = CTIO_TYPE7;
5299 ctio24->nport_handle = sess->loop_id;
5300 ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
5301 ctio24->vp_index = vha->vp_idx;
5302 ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
5303 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
5304 temp = (atio->u.isp24.attr << 9) |
5305 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS |
5306 CTIO7_FLAGS_DONT_RET_CTIO;
5307 ctio24->u.status1.flags = cpu_to_le16(temp);
5309 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
5310 * if the explicit conformation is used.
5312 ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id);
5313 ctio24->u.status1.scsi_status = cpu_to_le16(status);
5315 ctio24->u.status1.residual = get_datalen_for_atio(atio);
5317 if (ctio24->u.status1.residual != 0)
5318 ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER;
5320 /* Memory Barrier */
5322 if (qpair->reqq_start_iocbs)
5323 qpair->reqq_start_iocbs(qpair);
5325 qla2x00_start_iocbs(vha, qpair->req);
5330 * This routine is used to allocate a command for either a QFull condition
5331 * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go
5335 qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
5336 struct atio_from_isp *atio, uint16_t status, int qfull)
5338 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5339 struct qla_hw_data *ha = vha->hw;
5340 struct fc_port *sess;
5341 struct se_session *se_sess;
5342 struct qla_tgt_cmd *cmd;
5344 unsigned long flags;
5346 if (unlikely(tgt->tgt_stop)) {
5347 ql_dbg(ql_dbg_io, vha, 0x300a,
5348 "New command while device %p is shutting down\n", tgt);
5352 if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) {
5353 vha->hw->tgt.num_qfull_cmds_dropped++;
5354 if (vha->hw->tgt.num_qfull_cmds_dropped >
5355 vha->qla_stats.stat_max_qfull_cmds_dropped)
5356 vha->qla_stats.stat_max_qfull_cmds_dropped =
5357 vha->hw->tgt.num_qfull_cmds_dropped;
5359 ql_dbg(ql_dbg_io, vha, 0x3068,
5360 "qla_target(%d): %s: QFull CMD dropped[%d]\n",
5361 vha->vp_idx, __func__,
5362 vha->hw->tgt.num_qfull_cmds_dropped);
5364 qlt_chk_exch_leak_thresh_hold(vha);
5368 sess = ha->tgt.tgt_ops->find_sess_by_s_id
5369 (vha, atio->u.isp24.fcp_hdr.s_id);
5373 se_sess = sess->se_sess;
5375 tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu);
5377 ql_dbg(ql_dbg_io, vha, 0x3009,
5378 "qla_target(%d): %s: Allocation of cmd failed\n",
5379 vha->vp_idx, __func__);
5381 vha->hw->tgt.num_qfull_cmds_dropped++;
5382 if (vha->hw->tgt.num_qfull_cmds_dropped >
5383 vha->qla_stats.stat_max_qfull_cmds_dropped)
5384 vha->qla_stats.stat_max_qfull_cmds_dropped =
5385 vha->hw->tgt.num_qfull_cmds_dropped;
5387 qlt_chk_exch_leak_thresh_hold(vha);
5391 cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag];
5392 memset(cmd, 0, sizeof(struct qla_tgt_cmd));
5394 qlt_incr_num_pend_cmds(vha);
5395 INIT_LIST_HEAD(&cmd->cmd_list);
5396 memcpy(&cmd->atio, atio, sizeof(*atio));
5398 cmd->tgt = vha->vha_tgt.qla_tgt;
5400 cmd->reset_count = ha->base_qpair->chip_reset;
5402 cmd->qpair = ha->base_qpair;
5403 cmd->se_cmd.map_cpu = cpu;
5407 /* NOTE: borrowing the state field to carry the status */
5408 cmd->state = status;
5410 cmd->term_exchg = 1;
5412 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5413 list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list);
5415 vha->hw->tgt.num_qfull_cmds_alloc++;
5416 if (vha->hw->tgt.num_qfull_cmds_alloc >
5417 vha->qla_stats.stat_max_qfull_cmds_alloc)
5418 vha->qla_stats.stat_max_qfull_cmds_alloc =
5419 vha->hw->tgt.num_qfull_cmds_alloc;
5420 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5424 qlt_free_qfull_cmds(struct qla_qpair *qpair)
5426 struct scsi_qla_host *vha = qpair->vha;
5427 struct qla_hw_data *ha = vha->hw;
5428 unsigned long flags;
5429 struct qla_tgt_cmd *cmd, *tcmd;
5430 struct list_head free_list, q_full_list;
5433 if (list_empty(&ha->tgt.q_full_list))
5436 INIT_LIST_HEAD(&free_list);
5437 INIT_LIST_HEAD(&q_full_list);
5439 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5440 if (list_empty(&ha->tgt.q_full_list)) {
5441 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5445 list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list);
5446 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5448 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
5449 list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) {
5451 /* cmd->state is a borrowed field to hold status */
5452 rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state);
5453 else if (cmd->term_exchg)
5454 rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio);
5460 ql_dbg(ql_dbg_io, vha, 0x3006,
5461 "%s: busy sent for ox_id[%04x]\n", __func__,
5462 be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
5463 else if (cmd->term_exchg)
5464 ql_dbg(ql_dbg_io, vha, 0x3007,
5465 "%s: Term exchg sent for ox_id[%04x]\n", __func__,
5466 be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
5468 ql_dbg(ql_dbg_io, vha, 0x3008,
5469 "%s: Unexpected cmd in QFull list %p\n", __func__,
5472 list_del(&cmd->cmd_list);
5473 list_add_tail(&cmd->cmd_list, &free_list);
5475 /* piggy back on hardware_lock for protection */
5476 vha->hw->tgt.num_qfull_cmds_alloc--;
5478 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
5482 list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) {
5483 list_del(&cmd->cmd_list);
5484 /* This cmd was never sent to TCM. There is no need
5485 * to schedule free or call free_cmd
5490 if (!list_empty(&q_full_list)) {
5491 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5492 list_splice(&q_full_list, &vha->hw->tgt.q_full_list);
5493 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5500 qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio,
5504 struct scsi_qla_host *vha = qpair->vha;
5506 rc = __qlt_send_busy(qpair, atio, status);
5508 qlt_alloc_qfull_cmd(vha, atio, status, 1);
5512 qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair,
5513 struct atio_from_isp *atio, uint8_t ha_locked)
5515 struct qla_hw_data *ha = vha->hw;
5516 unsigned long flags;
5518 if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha))
5522 spin_lock_irqsave(&ha->hardware_lock, flags);
5523 qlt_send_busy(qpair, atio, qla_sam_status);
5525 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5530 /* ha->hardware_lock supposed to be held on entry */
5531 /* called via callback from qla2xxx */
5532 static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha,
5533 struct atio_from_isp *atio, uint8_t ha_locked)
5535 struct qla_hw_data *ha = vha->hw;
5536 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5538 unsigned long flags = 0;
5540 if (unlikely(tgt == NULL)) {
5541 ql_dbg(ql_dbg_tgt, vha, 0x3064,
5542 "ATIO pkt, but no tgt (ha %p)", ha);
5546 * In tgt_stop mode we also should allow all requests to pass.
5547 * Otherwise, some commands can stuck.
5550 tgt->atio_irq_cmd_count++;
5552 switch (atio->u.raw.entry_type) {
5554 if (unlikely(atio->u.isp24.exchange_addr ==
5555 ATIO_EXCHANGE_ADDRESS_UNKNOWN)) {
5556 ql_dbg(ql_dbg_io, vha, 0x3065,
5557 "qla_target(%d): ATIO_TYPE7 "
5558 "received with UNKNOWN exchange address, "
5559 "sending QUEUE_FULL\n", vha->vp_idx);
5561 spin_lock_irqsave(&ha->hardware_lock, flags);
5562 qlt_send_busy(ha->base_qpair, atio, qla_sam_status);
5564 spin_unlock_irqrestore(&ha->hardware_lock,
5569 if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) {
5570 rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair,
5573 tgt->atio_irq_cmd_count--;
5576 rc = qlt_handle_cmd_for_atio(vha, atio);
5578 rc = qlt_handle_task_mgmt(vha, atio);
5580 if (unlikely(rc != 0)) {
5582 spin_lock_irqsave(&ha->hardware_lock, flags);
5585 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5586 "qla_target: Unable to send command to target\n");
5589 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5590 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
5591 qlt_send_term_exchange(ha->base_qpair, NULL,
5595 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5596 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5598 qlt_send_busy(ha->base_qpair, atio,
5602 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5603 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5605 qlt_send_busy(ha->base_qpair, atio,
5610 spin_unlock_irqrestore(&ha->hardware_lock,
5615 case IMMED_NOTIFY_TYPE:
5617 if (unlikely(atio->u.isp2x.entry_status != 0)) {
5618 ql_dbg(ql_dbg_tgt, vha, 0xe05b,
5619 "qla_target(%d): Received ATIO packet %x "
5620 "with error status %x\n", vha->vp_idx,
5621 atio->u.raw.entry_type,
5622 atio->u.isp2x.entry_status);
5625 ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO");
5628 spin_lock_irqsave(&ha->hardware_lock, flags);
5629 qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio);
5631 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5636 ql_dbg(ql_dbg_tgt, vha, 0xe05c,
5637 "qla_target(%d): Received unknown ATIO atio "
5638 "type %x\n", vha->vp_idx, atio->u.raw.entry_type);
5642 tgt->atio_irq_cmd_count--;
5646 * qpair lock is assume to be held
5647 * rc = 0 : send terminate & abts respond
5648 * rc != 0: do not send term & abts respond
5650 static int qlt_chk_unresolv_exchg(struct scsi_qla_host *vha,
5651 struct qla_qpair *qpair, struct abts_resp_from_24xx_fw *entry)
5653 struct qla_hw_data *ha = vha->hw;
5657 * Detect unresolved exchange. If the same ABTS is unable
5658 * to terminate an existing command and the same ABTS loops
5659 * between FW & Driver, then force FW dump. Under 1 jiff,
5660 * we should see multiple loops.
5662 if (qpair->retry_term_exchg_addr == entry->exchange_addr_to_abort &&
5663 qpair->retry_term_jiff == jiffies) {
5664 /* found existing exchange */
5665 qpair->retry_term_cnt++;
5666 if (qpair->retry_term_cnt >= 5) {
5668 qpair->retry_term_cnt = 0;
5669 ql_log(ql_log_warn, vha, 0xffff,
5670 "Unable to send ABTS Respond. Dumping firmware.\n");
5671 ql_dump_buffer(ql_dbg_tgt_mgt + ql_dbg_buffer,
5672 vha, 0xffff, (uint8_t *)entry, sizeof(*entry));
5674 if (qpair == ha->base_qpair)
5675 ha->isp_ops->fw_dump(vha, 1);
5677 ha->isp_ops->fw_dump(vha, 0);
5679 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5680 qla2xxx_wake_dpc(vha);
5682 } else if (qpair->retry_term_jiff != jiffies) {
5683 qpair->retry_term_exchg_addr = entry->exchange_addr_to_abort;
5684 qpair->retry_term_cnt = 0;
5685 qpair->retry_term_jiff = jiffies;
5692 static void qlt_handle_abts_completion(struct scsi_qla_host *vha,
5693 struct rsp_que *rsp, response_t *pkt)
5695 struct abts_resp_from_24xx_fw *entry =
5696 (struct abts_resp_from_24xx_fw *)pkt;
5697 u32 h = pkt->handle & ~QLA_TGT_HANDLE_MASK;
5698 struct qla_tgt_mgmt_cmd *mcmd;
5699 struct qla_hw_data *ha = vha->hw;
5701 mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, pkt);
5702 if (mcmd == NULL && h != QLA_TGT_SKIP_HANDLE) {
5703 ql_dbg(ql_dbg_async, vha, 0xe064,
5704 "qla_target(%d): ABTS Comp without mcmd\n",
5711 vha->vha_tgt.qla_tgt->abts_resp_expected--;
5713 ql_dbg(ql_dbg_tgt, vha, 0xe038,
5714 "ABTS_RESP_24XX: compl_status %x\n",
5715 entry->compl_status);
5717 if (le16_to_cpu(entry->compl_status) != ABTS_RESP_COMPL_SUCCESS) {
5718 if ((entry->error_subcode1 == 0x1E) &&
5719 (entry->error_subcode2 == 0)) {
5720 if (qlt_chk_unresolv_exchg(vha, rsp->qpair, entry)) {
5721 ha->tgt.tgt_ops->free_mcmd(mcmd);
5724 qlt_24xx_retry_term_exchange(vha, rsp->qpair,
5727 ql_dbg(ql_dbg_tgt, vha, 0xe063,
5728 "qla_target(%d): ABTS_RESP_24XX failed %x (subcode %x:%x)",
5729 vha->vp_idx, entry->compl_status,
5730 entry->error_subcode1,
5731 entry->error_subcode2);
5732 ha->tgt.tgt_ops->free_mcmd(mcmd);
5735 ha->tgt.tgt_ops->free_mcmd(mcmd);
5739 /* ha->hardware_lock supposed to be held on entry */
5740 /* called via callback from qla2xxx */
5741 static void qlt_response_pkt(struct scsi_qla_host *vha,
5742 struct rsp_que *rsp, response_t *pkt)
5744 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5746 if (unlikely(tgt == NULL)) {
5747 ql_dbg(ql_dbg_tgt, vha, 0xe05d,
5748 "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n",
5749 vha->vp_idx, pkt->entry_type, vha->hw);
5754 * In tgt_stop mode we also should allow all requests to pass.
5755 * Otherwise, some commands can stuck.
5758 switch (pkt->entry_type) {
5762 struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
5764 qlt_do_ctio_completion(vha, rsp, entry->handle,
5765 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5770 case ACCEPT_TGT_IO_TYPE:
5772 struct atio_from_isp *atio = (struct atio_from_isp *)pkt;
5775 if (atio->u.isp2x.status !=
5776 cpu_to_le16(ATIO_CDB_VALID)) {
5777 ql_dbg(ql_dbg_tgt, vha, 0xe05e,
5778 "qla_target(%d): ATIO with error "
5779 "status %x received\n", vha->vp_idx,
5780 le16_to_cpu(atio->u.isp2x.status));
5784 rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1);
5788 rc = qlt_handle_cmd_for_atio(vha, atio);
5789 if (unlikely(rc != 0)) {
5792 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5793 "qla_target: Unable to send command to target\n");
5796 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5797 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
5798 qlt_send_term_exchange(rsp->qpair, NULL,
5802 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5803 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5805 qlt_send_busy(rsp->qpair, atio,
5809 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5810 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5812 qlt_send_busy(rsp->qpair, atio,
5820 case CONTINUE_TGT_IO_TYPE:
5822 struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
5824 qlt_do_ctio_completion(vha, rsp, entry->handle,
5825 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5832 struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
5834 qlt_do_ctio_completion(vha, rsp, entry->handle,
5835 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5840 case IMMED_NOTIFY_TYPE:
5841 ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n");
5842 qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt);
5845 case NOTIFY_ACK_TYPE:
5846 if (tgt->notify_ack_expected > 0) {
5847 struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
5849 ql_dbg(ql_dbg_tgt, vha, 0xe036,
5850 "NOTIFY_ACK seq %08x status %x\n",
5851 le16_to_cpu(entry->u.isp2x.seq_id),
5852 le16_to_cpu(entry->u.isp2x.status));
5853 tgt->notify_ack_expected--;
5854 if (entry->u.isp2x.status !=
5855 cpu_to_le16(NOTIFY_ACK_SUCCESS)) {
5856 ql_dbg(ql_dbg_tgt, vha, 0xe061,
5857 "qla_target(%d): NOTIFY_ACK "
5858 "failed %x\n", vha->vp_idx,
5859 le16_to_cpu(entry->u.isp2x.status));
5862 ql_dbg(ql_dbg_tgt, vha, 0xe062,
5863 "qla_target(%d): Unexpected NOTIFY_ACK received\n",
5868 case ABTS_RECV_24XX:
5869 ql_dbg(ql_dbg_tgt, vha, 0xe037,
5870 "ABTS_RECV_24XX: instance %d\n", vha->vp_idx);
5871 qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt);
5874 case ABTS_RESP_24XX:
5875 if (tgt->abts_resp_expected > 0) {
5876 qlt_handle_abts_completion(vha, rsp, pkt);
5878 ql_dbg(ql_dbg_tgt, vha, 0xe064,
5879 "qla_target(%d): Unexpected ABTS_RESP_24XX "
5880 "received\n", vha->vp_idx);
5885 ql_dbg(ql_dbg_tgt, vha, 0xe065,
5886 "qla_target(%d): Received unknown response pkt "
5887 "type %x\n", vha->vp_idx, pkt->entry_type);
5894 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5896 void qlt_async_event(uint16_t code, struct scsi_qla_host *vha,
5899 struct qla_hw_data *ha = vha->hw;
5900 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5903 if (!tgt || tgt->tgt_stop || tgt->tgt_stopped)
5906 if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) &&
5910 * In tgt_stop mode we also should allow all requests to pass.
5911 * Otherwise, some commands can stuck.
5916 case MBA_RESET: /* Reset */
5917 case MBA_SYSTEM_ERR: /* System Error */
5918 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
5919 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
5920 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a,
5921 "qla_target(%d): System error async event %#x "
5922 "occurred", vha->vp_idx, code);
5924 case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */
5925 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5930 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b,
5931 "qla_target(%d): Async LOOP_UP occurred "
5932 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx,
5933 le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
5934 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
5935 if (tgt->link_reinit_iocb_pending) {
5936 qlt_send_notify_ack(ha->base_qpair,
5937 (void *)&tgt->link_reinit_iocb,
5939 tgt->link_reinit_iocb_pending = 0;
5944 case MBA_LIP_OCCURRED:
5947 case MBA_RSCN_UPDATE:
5948 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c,
5949 "qla_target(%d): Async event %#x occurred "
5950 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code,
5951 le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
5952 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
5955 case MBA_REJECTED_FCP_CMD:
5956 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017,
5957 "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)",
5959 le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
5960 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
5962 if (le16_to_cpu(mailbox[3]) == 1) {
5963 /* exchange starvation. */
5964 vha->hw->exch_starvation++;
5965 if (vha->hw->exch_starvation > 5) {
5966 ql_log(ql_log_warn, vha, 0xd03a,
5967 "Exchange starvation-. Resetting RISC\n");
5969 vha->hw->exch_starvation = 0;
5970 if (IS_P3P_TYPE(vha->hw))
5971 set_bit(FCOE_CTX_RESET_NEEDED,
5974 set_bit(ISP_ABORT_NEEDED,
5976 qla2xxx_wake_dpc(vha);
5981 case MBA_PORT_UPDATE:
5982 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d,
5983 "qla_target(%d): Port update async event %#x "
5984 "occurred: updating the ports database (m[0]=%x, m[1]=%x, "
5985 "m[2]=%x, m[3]=%x)", vha->vp_idx, code,
5986 le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
5987 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
5989 login_code = le16_to_cpu(mailbox[2]);
5990 if (login_code == 0x4) {
5991 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e,
5992 "Async MB 2: Got PLOGI Complete\n");
5993 vha->hw->exch_starvation = 0;
5994 } else if (login_code == 0x7)
5995 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f,
5996 "Async MB 2: Port Logged Out\n");
6004 static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha,
6007 fc_port_t *fcport, *tfcp, *del;
6009 unsigned long flags;
6012 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6014 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f,
6015 "qla_target(%d): Allocation of tmp FC port failed",
6020 fcport->loop_id = loop_id;
6022 rc = qla24xx_gpdb_wait(vha, fcport, 0);
6023 if (rc != QLA_SUCCESS) {
6024 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070,
6025 "qla_target(%d): Failed to retrieve fcport "
6026 "information -- get_port_database() returned %x "
6027 "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id);
6033 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6034 tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1);
6037 tfcp->d_id = fcport->d_id;
6038 tfcp->port_type = fcport->port_type;
6039 tfcp->supported_classes = fcport->supported_classes;
6040 tfcp->flags |= fcport->flags;
6041 tfcp->scan_state = QLA_FCPORT_FOUND;
6046 if (vha->hw->current_topology == ISP_CFG_F)
6047 fcport->flags |= FCF_FABRIC_DEVICE;
6049 list_add_tail(&fcport->list, &vha->vp_fcports);
6050 if (!IS_SW_RESV_ADDR(fcport->d_id))
6051 vha->fcport_count++;
6052 fcport->login_gen++;
6053 fcport->disc_state = DSC_LOGIN_COMPLETE;
6054 fcport->login_succ = 1;
6058 fcport->deleted = 0;
6059 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6061 switch (vha->host->active_mode) {
6062 case MODE_INITIATOR:
6065 if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) {
6066 qla24xx_sched_upd_fcport(fcport);
6068 ql_dbg(ql_dbg_disc, vha, 0x20ff,
6069 "%s %d %8phC post gpsc fcp_cnt %d\n",
6070 __func__, __LINE__, fcport->port_name, vha->fcport_count);
6071 qla24xx_post_gpsc_work(vha, fcport);
6081 qla2x00_free_fcport(del);
6086 /* Must be called under tgt_mutex */
6087 static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *vha,
6090 struct fc_port *sess = NULL;
6091 fc_port_t *fcport = NULL;
6092 int rc, global_resets;
6093 uint16_t loop_id = 0;
6095 if (s_id.domain == 0xFF && s_id.area == 0xFC) {
6097 * This is Domain Controller, so it should be
6098 * OK to drop SCSI commands from it.
6100 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042,
6101 "Unable to find initiator with S_ID %x:%x:%x",
6102 s_id.domain, s_id.area, s_id.al_pa);
6106 mutex_lock(&vha->vha_tgt.tgt_mutex);
6110 atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count);
6112 rc = qla24xx_get_loop_id(vha, s_id, &loop_id);
6114 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6116 ql_log(ql_log_info, vha, 0xf071,
6117 "qla_target(%d): Unable to find "
6118 "initiator with S_ID %x:%x:%x",
6119 vha->vp_idx, s_id.domain, s_id.area, s_id.al_pa);
6121 if (rc == -ENOENT) {
6122 qlt_port_logo_t logo;
6124 logo.id = be_to_port_id(s_id);
6126 qlt_send_first_logo(vha, &logo);
6132 fcport = qlt_get_port_database(vha, loop_id);
6134 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6138 if (global_resets !=
6139 atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) {
6140 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043,
6141 "qla_target(%d): global reset during session discovery "
6142 "(counter was %d, new %d), retrying", vha->vp_idx,
6144 atomic_read(&vha->vha_tgt.
6145 qla_tgt->tgt_global_resets_count));
6149 sess = qlt_create_sess(vha, fcport, true);
6151 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6156 static void qlt_abort_work(struct qla_tgt *tgt,
6157 struct qla_tgt_sess_work_param *prm)
6159 struct scsi_qla_host *vha = tgt->vha;
6160 struct qla_hw_data *ha = vha->hw;
6161 struct fc_port *sess = NULL;
6162 unsigned long flags = 0, flags2 = 0;
6166 spin_lock_irqsave(&ha->tgt.sess_lock, flags2);
6171 s_id = le_id_to_be(prm->abts.fcp_hdr_le.s_id);
6173 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
6175 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6177 sess = qlt_make_local_sess(vha, s_id);
6178 /* sess has got an extra creation ref */
6180 spin_lock_irqsave(&ha->tgt.sess_lock, flags2);
6184 if (sess->deleted) {
6189 if (!kref_get_unless_zero(&sess->sess_kref)) {
6190 ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c,
6191 "%s: kref_get fail %8phC \n",
6192 __func__, sess->port_name);
6198 rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess);
6199 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6201 ha->tgt.tgt_ops->put_sess(sess);
6208 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6211 spin_lock_irqsave(&ha->hardware_lock, flags);
6212 qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts,
6213 FCP_TMF_REJECTED, false);
6214 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6217 static void qlt_tmr_work(struct qla_tgt *tgt,
6218 struct qla_tgt_sess_work_param *prm)
6220 struct atio_from_isp *a = &prm->tm_iocb2;
6221 struct scsi_qla_host *vha = tgt->vha;
6222 struct qla_hw_data *ha = vha->hw;
6223 struct fc_port *sess;
6224 unsigned long flags;
6231 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
6236 s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id;
6237 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
6239 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6241 sess = qlt_make_local_sess(vha, s_id);
6242 /* sess has got an extra creation ref */
6244 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
6248 if (sess->deleted) {
6252 if (!kref_get_unless_zero(&sess->sess_kref)) {
6253 ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020,
6254 "%s: kref_get fail %8phC\n",
6255 __func__, sess->port_name);
6261 fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
6263 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
6265 rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
6266 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6268 ha->tgt.tgt_ops->put_sess(sess);
6275 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6277 qlt_send_term_exchange(ha->base_qpair, NULL, &prm->tm_iocb2, 1, 0);
6280 static void qlt_sess_work_fn(struct work_struct *work)
6282 struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work);
6283 struct scsi_qla_host *vha = tgt->vha;
6284 unsigned long flags;
6286 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt);
6288 spin_lock_irqsave(&tgt->sess_work_lock, flags);
6289 while (!list_empty(&tgt->sess_works_list)) {
6290 struct qla_tgt_sess_work_param *prm = list_entry(
6291 tgt->sess_works_list.next, typeof(*prm),
6292 sess_works_list_entry);
6295 * This work can be scheduled on several CPUs at time, so we
6296 * must delete the entry to eliminate double processing
6298 list_del(&prm->sess_works_list_entry);
6300 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
6302 switch (prm->type) {
6303 case QLA_TGT_SESS_WORK_ABORT:
6304 qlt_abort_work(tgt, prm);
6306 case QLA_TGT_SESS_WORK_TM:
6307 qlt_tmr_work(tgt, prm);
6314 spin_lock_irqsave(&tgt->sess_work_lock, flags);
6318 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
6321 /* Must be called under tgt_host_action_mutex */
6322 int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha)
6324 struct qla_tgt *tgt;
6326 struct qla_qpair_hint *h;
6328 if (!QLA_TGT_MODE_ENABLED())
6331 if (!IS_TGT_MODE_CAPABLE(ha)) {
6332 ql_log(ql_log_warn, base_vha, 0xe070,
6333 "This adapter does not support target mode.\n");
6337 ql_dbg(ql_dbg_tgt, base_vha, 0xe03b,
6338 "Registering target for host %ld(%p).\n", base_vha->host_no, ha);
6340 BUG_ON(base_vha->vha_tgt.qla_tgt != NULL);
6342 tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL);
6344 ql_dbg(ql_dbg_tgt, base_vha, 0xe066,
6345 "Unable to allocate struct qla_tgt\n");
6349 tgt->qphints = kcalloc(ha->max_qpairs + 1,
6350 sizeof(struct qla_qpair_hint),
6352 if (!tgt->qphints) {
6354 ql_log(ql_log_warn, base_vha, 0x0197,
6355 "Unable to allocate qpair hints.\n");
6359 if (!(base_vha->host->hostt->supported_mode & MODE_TARGET))
6360 base_vha->host->hostt->supported_mode |= MODE_TARGET;
6362 rc = btree_init64(&tgt->lun_qpair_map);
6364 kfree(tgt->qphints);
6366 ql_log(ql_log_info, base_vha, 0x0198,
6367 "Unable to initialize lun_qpair_map btree\n");
6370 h = &tgt->qphints[0];
6371 h->qpair = ha->base_qpair;
6372 INIT_LIST_HEAD(&h->hint_elem);
6373 h->cpuid = ha->base_qpair->cpuid;
6374 list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list);
6376 for (i = 0; i < ha->max_qpairs; i++) {
6377 unsigned long flags;
6379 struct qla_qpair *qpair = ha->queue_pair_map[i];
6381 h = &tgt->qphints[i + 1];
6382 INIT_LIST_HEAD(&h->hint_elem);
6385 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
6386 list_add_tail(&h->hint_elem, &qpair->hints_list);
6387 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
6388 h->cpuid = qpair->cpuid;
6393 tgt->vha = base_vha;
6394 init_waitqueue_head(&tgt->waitQ);
6395 INIT_LIST_HEAD(&tgt->del_sess_list);
6396 spin_lock_init(&tgt->sess_work_lock);
6397 INIT_WORK(&tgt->sess_work, qlt_sess_work_fn);
6398 INIT_LIST_HEAD(&tgt->sess_works_list);
6399 atomic_set(&tgt->tgt_global_resets_count, 0);
6401 base_vha->vha_tgt.qla_tgt = tgt;
6403 ql_dbg(ql_dbg_tgt, base_vha, 0xe067,
6404 "qla_target(%d): using 64 Bit PCI addressing",
6407 tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3);
6409 mutex_lock(&qla_tgt_mutex);
6410 list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist);
6411 mutex_unlock(&qla_tgt_mutex);
6413 if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target)
6414 ha->tgt.tgt_ops->add_target(base_vha);
6419 /* Must be called under tgt_host_action_mutex */
6420 int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha)
6422 if (!vha->vha_tgt.qla_tgt)
6425 if (vha->fc_vport) {
6426 qlt_release(vha->vha_tgt.qla_tgt);
6430 /* free left over qfull cmds */
6431 qlt_init_term_exchange(vha);
6433 ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)",
6435 qlt_release(vha->vha_tgt.qla_tgt);
6440 void qlt_remove_target_resources(struct qla_hw_data *ha)
6442 struct scsi_qla_host *node;
6445 btree_for_each_safe32(&ha->tgt.host_map, key, node)
6446 btree_remove32(&ha->tgt.host_map, key);
6448 btree_destroy32(&ha->tgt.host_map);
6451 static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn,
6454 pr_debug("qla2xxx HW vha->node_name: %8phC\n", vha->node_name);
6455 pr_debug("qla2xxx HW vha->port_name: %8phC\n", vha->port_name);
6456 put_unaligned_be64(wwpn, b);
6457 pr_debug("qla2xxx passed configfs WWPN: %8phC\n", b);
6461 * qla_tgt_lport_register - register lport with external module
6463 * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
6464 * @phys_wwpn: physical port WWPN
6465 * @npiv_wwpn: NPIV WWPN
6466 * @npiv_wwnn: NPIV WWNN
6467 * @callback: lport initialization callback for tcm_qla2xxx code
6469 int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn,
6470 u64 npiv_wwpn, u64 npiv_wwnn,
6471 int (*callback)(struct scsi_qla_host *, void *, u64, u64))
6473 struct qla_tgt *tgt;
6474 struct scsi_qla_host *vha;
6475 struct qla_hw_data *ha;
6476 struct Scsi_Host *host;
6477 unsigned long flags;
6481 mutex_lock(&qla_tgt_mutex);
6482 list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) {
6490 if (!(host->hostt->supported_mode & MODE_TARGET))
6493 if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
6496 spin_lock_irqsave(&ha->hardware_lock, flags);
6497 if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) {
6498 pr_debug("MODE_TARGET already active on qla2xxx(%d)\n",
6500 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6503 if (tgt->tgt_stop) {
6504 pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n",
6506 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6509 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6511 if (!scsi_host_get(host)) {
6512 ql_dbg(ql_dbg_tgt, vha, 0xe068,
6513 "Unable to scsi_host_get() for"
6514 " qla2xxx scsi_host\n");
6517 qlt_lport_dump(vha, phys_wwpn, b);
6519 if (memcmp(vha->port_name, b, WWN_SIZE)) {
6520 scsi_host_put(host);
6523 rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn);
6525 scsi_host_put(host);
6527 mutex_unlock(&qla_tgt_mutex);
6530 mutex_unlock(&qla_tgt_mutex);
6534 EXPORT_SYMBOL(qlt_lport_register);
6537 * qla_tgt_lport_deregister - Degister lport
6539 * @vha: Registered scsi_qla_host pointer
6541 void qlt_lport_deregister(struct scsi_qla_host *vha)
6543 struct qla_hw_data *ha = vha->hw;
6544 struct Scsi_Host *sh = vha->host;
6546 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
6548 vha->vha_tgt.target_lport_ptr = NULL;
6549 ha->tgt.tgt_ops = NULL;
6551 * Release the Scsi_Host reference for the underlying qla2xxx host
6555 EXPORT_SYMBOL(qlt_lport_deregister);
6557 /* Must be called under HW lock */
6558 void qlt_set_mode(struct scsi_qla_host *vha)
6560 switch (vha->qlini_mode) {
6561 case QLA2XXX_INI_MODE_DISABLED:
6562 case QLA2XXX_INI_MODE_EXCLUSIVE:
6563 vha->host->active_mode = MODE_TARGET;
6565 case QLA2XXX_INI_MODE_ENABLED:
6566 vha->host->active_mode = MODE_INITIATOR;
6568 case QLA2XXX_INI_MODE_DUAL:
6569 vha->host->active_mode = MODE_DUAL;
6576 /* Must be called under HW lock */
6577 static void qlt_clear_mode(struct scsi_qla_host *vha)
6579 switch (vha->qlini_mode) {
6580 case QLA2XXX_INI_MODE_DISABLED:
6581 vha->host->active_mode = MODE_UNKNOWN;
6583 case QLA2XXX_INI_MODE_EXCLUSIVE:
6584 vha->host->active_mode = MODE_INITIATOR;
6586 case QLA2XXX_INI_MODE_ENABLED:
6587 case QLA2XXX_INI_MODE_DUAL:
6588 vha->host->active_mode = MODE_INITIATOR;
6596 * qla_tgt_enable_vha - NO LOCK HELD
6598 * host_reset, bring up w/ Target Mode Enabled
6601 qlt_enable_vha(struct scsi_qla_host *vha)
6603 struct qla_hw_data *ha = vha->hw;
6604 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
6605 unsigned long flags;
6606 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6609 ql_dbg(ql_dbg_tgt, vha, 0xe069,
6610 "Unable to locate qla_tgt pointer from"
6611 " struct qla_hw_data\n");
6615 if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
6618 if (ha->tgt.num_act_qpairs > ha->max_qpairs)
6619 ha->tgt.num_act_qpairs = ha->max_qpairs;
6620 spin_lock_irqsave(&ha->hardware_lock, flags);
6621 tgt->tgt_stopped = 0;
6623 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6625 mutex_lock(&ha->optrom_mutex);
6626 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021,
6629 qla24xx_disable_vp(vha);
6630 qla24xx_enable_vp(vha);
6632 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6633 qla2xxx_wake_dpc(base_vha);
6634 WARN_ON_ONCE(qla2x00_wait_for_hba_online(base_vha) !=
6637 mutex_unlock(&ha->optrom_mutex);
6639 EXPORT_SYMBOL(qlt_enable_vha);
6642 * qla_tgt_disable_vha - NO LOCK HELD
6644 * Disable Target Mode and reset the adapter
6646 static void qlt_disable_vha(struct scsi_qla_host *vha)
6648 struct qla_hw_data *ha = vha->hw;
6649 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
6650 unsigned long flags;
6653 ql_dbg(ql_dbg_tgt, vha, 0xe06a,
6654 "Unable to locate qla_tgt pointer from"
6655 " struct qla_hw_data\n");
6660 spin_lock_irqsave(&ha->hardware_lock, flags);
6661 qlt_clear_mode(vha);
6662 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6664 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6665 qla2xxx_wake_dpc(vha);
6666 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
6667 ql_dbg(ql_dbg_tgt, vha, 0xe081,
6668 "qla2x00_wait_for_hba_online() failed\n");
6672 * Called from qla_init.c:qla24xx_vport_create() contex to setup
6673 * the target mode specific struct scsi_qla_host and struct qla_hw_data
6677 qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha)
6679 vha->vha_tgt.qla_tgt = NULL;
6681 mutex_init(&vha->vha_tgt.tgt_mutex);
6682 mutex_init(&vha->vha_tgt.tgt_host_action_mutex);
6684 qlt_clear_mode(vha);
6687 * NOTE: Currently the value is kept the same for <24xx and
6688 * >=24xx ISPs. If it is necessary to change it,
6689 * the check should be added for specific ISPs,
6690 * assigning the value appropriately.
6692 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
6694 qlt_add_target(ha, vha);
6698 qlt_rff_id(struct scsi_qla_host *vha)
6702 * FC-4 Feature bit 0 indicates target functionality to the name server.
6704 if (qla_tgt_mode_enabled(vha)) {
6705 fc4_feature = BIT_0;
6706 } else if (qla_ini_mode_enabled(vha)) {
6707 fc4_feature = BIT_1;
6708 } else if (qla_dual_mode_enabled(vha))
6709 fc4_feature = BIT_0 | BIT_1;
6715 * qlt_init_atio_q_entries() - Initializes ATIO queue entries.
6718 * Beginning of ATIO ring has initialization control block already built
6719 * by nvram config routine.
6721 * Returns 0 on success.
6724 qlt_init_atio_q_entries(struct scsi_qla_host *vha)
6726 struct qla_hw_data *ha = vha->hw;
6728 struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring;
6730 if (qla_ini_mode_enabled(vha))
6733 for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) {
6734 pkt->u.raw.signature = ATIO_PROCESSED;
6741 * qlt_24xx_process_atio_queue() - Process ATIO queue entries.
6742 * @ha: SCSI driver HA context
6745 qlt_24xx_process_atio_queue(struct scsi_qla_host *vha, uint8_t ha_locked)
6747 struct qla_hw_data *ha = vha->hw;
6748 struct atio_from_isp *pkt;
6751 if (!ha->flags.fw_started)
6754 while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) ||
6755 fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) {
6756 pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
6757 cnt = pkt->u.raw.entry_count;
6759 if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) {
6761 * This packet is corrupted. The header + payload
6762 * can not be trusted. There is no point in passing
6765 ql_log(ql_log_warn, vha, 0xd03c,
6766 "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n",
6767 &pkt->u.isp24.fcp_hdr.s_id,
6768 be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id),
6769 le32_to_cpu(pkt->u.isp24.exchange_addr), pkt);
6771 adjust_corrupted_atio(pkt);
6772 qlt_send_term_exchange(ha->base_qpair, NULL, pkt,
6775 qlt_24xx_atio_pkt_all_vps(vha,
6776 (struct atio_from_isp *)pkt, ha_locked);
6779 for (i = 0; i < cnt; i++) {
6780 ha->tgt.atio_ring_index++;
6781 if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) {
6782 ha->tgt.atio_ring_index = 0;
6783 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
6785 ha->tgt.atio_ring_ptr++;
6787 pkt->u.raw.signature = ATIO_PROCESSED;
6788 pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
6793 /* Adjust ring index */
6794 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index);
6798 qlt_24xx_config_rings(struct scsi_qla_host *vha)
6800 struct qla_hw_data *ha = vha->hw;
6801 struct qla_msix_entry *msix = &ha->msix_entries[2];
6802 struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb;
6804 if (!QLA_TGT_MODE_ENABLED())
6807 WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0);
6808 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0);
6809 RD_REG_DWORD(ISP_ATIO_Q_OUT(vha));
6811 if (ha->flags.msix_enabled) {
6812 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
6813 if (IS_QLA2071(ha)) {
6814 /* 4 ports Baker: Enable Interrupt Handshake */
6816 icb->firmware_options_2 |= BIT_26;
6818 icb->msix_atio = cpu_to_le16(msix->entry);
6819 icb->firmware_options_2 &= ~BIT_26;
6821 ql_dbg(ql_dbg_init, vha, 0xf072,
6822 "Registering ICB vector 0x%x for atio que.\n",
6827 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
6829 icb->firmware_options_2 |= BIT_26;
6830 ql_dbg(ql_dbg_init, vha, 0xf072,
6831 "%s: Use INTx for ATIOQ.\n", __func__);
6837 qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv)
6839 struct qla_hw_data *ha = vha->hw;
6842 if (!QLA_TGT_MODE_ENABLED())
6845 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
6846 if (!ha->tgt.saved_set) {
6847 /* We save only once */
6848 ha->tgt.saved_exchange_count = nv->exchange_count;
6849 ha->tgt.saved_firmware_options_1 =
6850 nv->firmware_options_1;
6851 ha->tgt.saved_firmware_options_2 =
6852 nv->firmware_options_2;
6853 ha->tgt.saved_firmware_options_3 =
6854 nv->firmware_options_3;
6855 ha->tgt.saved_set = 1;
6858 if (qla_tgt_mode_enabled(vha))
6859 nv->exchange_count = cpu_to_le16(0xFFFF);
6861 nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
6863 /* Enable target mode */
6864 nv->firmware_options_1 |= cpu_to_le32(BIT_4);
6866 /* Disable ini mode, if requested */
6867 if (qla_tgt_mode_enabled(vha))
6868 nv->firmware_options_1 |= cpu_to_le32(BIT_5);
6870 /* Disable Full Login after LIP */
6871 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
6872 /* Enable initial LIP */
6873 nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
6874 if (ql2xtgt_tape_enable)
6875 /* Enable FC Tape support */
6876 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6878 /* Disable FC Tape support */
6879 nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
6881 /* Disable Full Login after LIP */
6882 nv->host_p &= cpu_to_le32(~BIT_10);
6885 * clear BIT 15 explicitly as we have seen at least
6886 * a couple of instances where this was set and this
6887 * was causing the firmware to not be initialized.
6889 nv->firmware_options_1 &= cpu_to_le32(~BIT_15);
6890 /* Enable target PRLI control */
6891 nv->firmware_options_2 |= cpu_to_le32(BIT_14);
6893 if (IS_QLA25XX(ha)) {
6894 /* Change Loop-prefer to Pt-Pt */
6895 tmp = ~(BIT_4|BIT_5|BIT_6);
6896 nv->firmware_options_2 &= cpu_to_le32(tmp);
6898 nv->firmware_options_2 |= cpu_to_le32(tmp);
6901 if (ha->tgt.saved_set) {
6902 nv->exchange_count = ha->tgt.saved_exchange_count;
6903 nv->firmware_options_1 =
6904 ha->tgt.saved_firmware_options_1;
6905 nv->firmware_options_2 =
6906 ha->tgt.saved_firmware_options_2;
6907 nv->firmware_options_3 =
6908 ha->tgt.saved_firmware_options_3;
6913 if (ha->base_qpair->enable_class_2) {
6914 if (vha->flags.init_done)
6915 fc_host_supported_classes(vha->host) =
6916 FC_COS_CLASS2 | FC_COS_CLASS3;
6918 nv->firmware_options_2 |= cpu_to_le32(BIT_8);
6920 if (vha->flags.init_done)
6921 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
6923 nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
6928 qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha,
6929 struct init_cb_24xx *icb)
6931 struct qla_hw_data *ha = vha->hw;
6933 if (!QLA_TGT_MODE_ENABLED())
6936 if (ha->tgt.node_name_set) {
6937 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
6938 icb->firmware_options_1 |= cpu_to_le32(BIT_14);
6943 qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv)
6945 struct qla_hw_data *ha = vha->hw;
6948 if (!QLA_TGT_MODE_ENABLED())
6951 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
6952 if (!ha->tgt.saved_set) {
6953 /* We save only once */
6954 ha->tgt.saved_exchange_count = nv->exchange_count;
6955 ha->tgt.saved_firmware_options_1 =
6956 nv->firmware_options_1;
6957 ha->tgt.saved_firmware_options_2 =
6958 nv->firmware_options_2;
6959 ha->tgt.saved_firmware_options_3 =
6960 nv->firmware_options_3;
6961 ha->tgt.saved_set = 1;
6964 if (qla_tgt_mode_enabled(vha))
6965 nv->exchange_count = cpu_to_le16(0xFFFF);
6967 nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
6969 /* Enable target mode */
6970 nv->firmware_options_1 |= cpu_to_le32(BIT_4);
6972 /* Disable ini mode, if requested */
6973 if (qla_tgt_mode_enabled(vha))
6974 nv->firmware_options_1 |= cpu_to_le32(BIT_5);
6975 /* Disable Full Login after LIP */
6976 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
6977 /* Enable initial LIP */
6978 nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
6980 * clear BIT 15 explicitly as we have seen at
6981 * least a couple of instances where this was set
6982 * and this was causing the firmware to not be
6985 nv->firmware_options_1 &= cpu_to_le32(~BIT_15);
6986 if (ql2xtgt_tape_enable)
6987 /* Enable FC tape support */
6988 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6990 /* Disable FC tape support */
6991 nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
6993 /* Disable Full Login after LIP */
6994 nv->host_p &= cpu_to_le32(~BIT_10);
6995 /* Enable target PRLI control */
6996 nv->firmware_options_2 |= cpu_to_le32(BIT_14);
6998 /* Change Loop-prefer to Pt-Pt */
6999 tmp = ~(BIT_4|BIT_5|BIT_6);
7000 nv->firmware_options_2 &= cpu_to_le32(tmp);
7002 nv->firmware_options_2 |= cpu_to_le32(tmp);
7004 if (ha->tgt.saved_set) {
7005 nv->exchange_count = ha->tgt.saved_exchange_count;
7006 nv->firmware_options_1 =
7007 ha->tgt.saved_firmware_options_1;
7008 nv->firmware_options_2 =
7009 ha->tgt.saved_firmware_options_2;
7010 nv->firmware_options_3 =
7011 ha->tgt.saved_firmware_options_3;
7016 if (ha->base_qpair->enable_class_2) {
7017 if (vha->flags.init_done)
7018 fc_host_supported_classes(vha->host) =
7019 FC_COS_CLASS2 | FC_COS_CLASS3;
7021 nv->firmware_options_2 |= cpu_to_le32(BIT_8);
7023 if (vha->flags.init_done)
7024 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
7026 nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
7031 qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha,
7032 struct init_cb_81xx *icb)
7034 struct qla_hw_data *ha = vha->hw;
7036 if (!QLA_TGT_MODE_ENABLED())
7039 if (ha->tgt.node_name_set) {
7040 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
7041 icb->firmware_options_1 |= cpu_to_le32(BIT_14);
7046 qlt_83xx_iospace_config(struct qla_hw_data *ha)
7048 if (!QLA_TGT_MODE_ENABLED())
7051 ha->msix_count += 1; /* For ATIO Q */
7056 qlt_modify_vp_config(struct scsi_qla_host *vha,
7057 struct vp_config_entry_24xx *vpmod)
7059 /* enable target mode. Bit5 = 1 => disable */
7060 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7061 vpmod->options_idx1 &= ~BIT_5;
7063 /* Disable ini mode, if requested. bit4 = 1 => disable */
7064 if (qla_tgt_mode_enabled(vha))
7065 vpmod->options_idx1 &= ~BIT_4;
7069 qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha)
7073 if (!QLA_TGT_MODE_ENABLED())
7076 if ((ql2xenablemsix == 0) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
7078 ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in;
7079 ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out;
7081 ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in;
7082 ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out;
7085 mutex_init(&base_vha->vha_tgt.tgt_mutex);
7086 mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex);
7088 INIT_LIST_HEAD(&base_vha->unknown_atio_list);
7089 INIT_DELAYED_WORK(&base_vha->unknown_atio_work,
7090 qlt_unknown_atio_work_fn);
7092 qlt_clear_mode(base_vha);
7094 rc = btree_init32(&ha->tgt.host_map);
7096 ql_log(ql_log_info, base_vha, 0xd03d,
7097 "Unable to initialize ha->host_map btree\n");
7099 qlt_update_vp_map(base_vha, SET_VP_IDX);
7103 qla83xx_msix_atio_q(int irq, void *dev_id)
7105 struct rsp_que *rsp;
7106 scsi_qla_host_t *vha;
7107 struct qla_hw_data *ha;
7108 unsigned long flags;
7110 rsp = (struct rsp_que *) dev_id;
7112 vha = pci_get_drvdata(ha->pdev);
7114 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
7116 qlt_24xx_process_atio_queue(vha, 0);
7118 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
7124 qlt_handle_abts_recv_work(struct work_struct *work)
7126 struct qla_tgt_sess_op *op = container_of(work,
7127 struct qla_tgt_sess_op, work);
7128 scsi_qla_host_t *vha = op->vha;
7129 struct qla_hw_data *ha = vha->hw;
7130 unsigned long flags;
7132 if (qla2x00_reset_active(vha) ||
7133 (op->chip_reset != ha->base_qpair->chip_reset))
7136 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
7137 qlt_24xx_process_atio_queue(vha, 0);
7138 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
7140 spin_lock_irqsave(&ha->hardware_lock, flags);
7141 qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio);
7142 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7148 qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp,
7151 struct qla_tgt_sess_op *op;
7153 op = kzalloc(sizeof(*op), GFP_ATOMIC);
7156 /* do not reach for ATIO queue here. This is best effort err
7157 * recovery at this point.
7159 qlt_response_pkt_all_vps(vha, rsp, pkt);
7163 memcpy(&op->atio, pkt, sizeof(*pkt));
7165 op->chip_reset = vha->hw->base_qpair->chip_reset;
7167 INIT_WORK(&op->work, qlt_handle_abts_recv_work);
7168 queue_work(qla_tgt_wq, &op->work);
7173 qlt_mem_alloc(struct qla_hw_data *ha)
7175 if (!QLA_TGT_MODE_ENABLED())
7178 ha->tgt.tgt_vp_map = kcalloc(MAX_MULTI_ID_FABRIC,
7179 sizeof(struct qla_tgt_vp_map),
7181 if (!ha->tgt.tgt_vp_map)
7184 ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev,
7185 (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp),
7186 &ha->tgt.atio_dma, GFP_KERNEL);
7187 if (!ha->tgt.atio_ring) {
7188 kfree(ha->tgt.tgt_vp_map);
7195 qlt_mem_free(struct qla_hw_data *ha)
7197 if (!QLA_TGT_MODE_ENABLED())
7200 if (ha->tgt.atio_ring) {
7201 dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) *
7202 sizeof(struct atio_from_isp), ha->tgt.atio_ring,
7205 ha->tgt.atio_ring = NULL;
7206 ha->tgt.atio_dma = 0;
7207 kfree(ha->tgt.tgt_vp_map);
7208 ha->tgt.tgt_vp_map = NULL;
7211 /* vport_slock to be held by the caller */
7213 qlt_update_vp_map(struct scsi_qla_host *vha, int cmd)
7219 if (!QLA_TGT_MODE_ENABLED())
7222 key = vha->d_id.b24;
7226 vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha;
7229 slot = btree_lookup32(&vha->hw->tgt.host_map, key);
7231 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018,
7232 "Save vha in host_map %p %06x\n", vha, key);
7233 rc = btree_insert32(&vha->hw->tgt.host_map,
7234 key, vha, GFP_ATOMIC);
7236 ql_log(ql_log_info, vha, 0xd03e,
7237 "Unable to insert s_id into host_map: %06x\n",
7241 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019,
7242 "replace existing vha in host_map %p %06x\n", vha, key);
7243 btree_update32(&vha->hw->tgt.host_map, key, vha);
7246 vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL;
7249 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a,
7250 "clear vha in host_map %p %06x\n", vha, key);
7251 slot = btree_lookup32(&vha->hw->tgt.host_map, key);
7253 btree_remove32(&vha->hw->tgt.host_map, key);
7259 void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id)
7262 if (!vha->d_id.b24) {
7264 qlt_update_vp_map(vha, SET_AL_PA);
7265 } else if (vha->d_id.b24 != id.b24) {
7266 qlt_update_vp_map(vha, RESET_AL_PA);
7268 qlt_update_vp_map(vha, SET_AL_PA);
7272 static int __init qlt_parse_ini_mode(void)
7274 if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0)
7275 ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE;
7276 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0)
7277 ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED;
7278 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0)
7279 ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED;
7280 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0)
7281 ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL;
7288 int __init qlt_init(void)
7292 BUILD_BUG_ON(sizeof(struct ctio7_to_24xx) != 64);
7293 BUILD_BUG_ON(sizeof(struct ctio_to_2xxx) != 64);
7295 if (!qlt_parse_ini_mode()) {
7296 ql_log(ql_log_fatal, NULL, 0xe06b,
7297 "qlt_parse_ini_mode() failed\n");
7301 if (!QLA_TGT_MODE_ENABLED())
7304 qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep",
7305 sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct
7306 qla_tgt_mgmt_cmd), 0, NULL);
7307 if (!qla_tgt_mgmt_cmd_cachep) {
7308 ql_log(ql_log_fatal, NULL, 0xd04b,
7309 "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
7313 qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep",
7314 sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t),
7317 if (!qla_tgt_plogi_cachep) {
7318 ql_log(ql_log_fatal, NULL, 0xe06d,
7319 "kmem_cache_create for qla_tgt_plogi_cachep failed\n");
7321 goto out_mgmt_cmd_cachep;
7324 qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab,
7325 mempool_free_slab, qla_tgt_mgmt_cmd_cachep);
7326 if (!qla_tgt_mgmt_cmd_mempool) {
7327 ql_log(ql_log_fatal, NULL, 0xe06e,
7328 "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
7330 goto out_plogi_cachep;
7333 qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0);
7335 ql_log(ql_log_fatal, NULL, 0xe06f,
7336 "alloc_workqueue for qla_tgt_wq failed\n");
7338 goto out_cmd_mempool;
7341 * Return 1 to signal that initiator-mode is being disabled
7343 return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0;
7346 mempool_destroy(qla_tgt_mgmt_cmd_mempool);
7348 kmem_cache_destroy(qla_tgt_plogi_cachep);
7349 out_mgmt_cmd_cachep:
7350 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep);
7356 if (!QLA_TGT_MODE_ENABLED())
7359 destroy_workqueue(qla_tgt_wq);
7360 mempool_destroy(qla_tgt_mgmt_cmd_mempool);
7361 kmem_cache_destroy(qla_tgt_plogi_cachep);
7362 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep);