1 // SPDX-License-Identifier: GPL-2.0-only
3 * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx
5 * based on qla2x00t.c code:
7 * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
8 * Copyright (C) 2004 - 2005 Leonid Stoljar
9 * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
10 * Copyright (C) 2006 - 2010 ID7 Ltd.
12 * Forward port and refactoring to modern qla2xxx and target/configfs
14 * Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/types.h>
20 #include <linux/blkdev.h>
21 #include <linux/interrupt.h>
22 #include <linux/pci.h>
23 #include <linux/delay.h>
24 #include <linux/list.h>
25 #include <linux/workqueue.h>
26 #include <asm/unaligned.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_tcq.h>
32 #include "qla_target.h"
34 static int ql2xtgt_tape_enable;
35 module_param(ql2xtgt_tape_enable, int, S_IRUGO|S_IWUSR);
36 MODULE_PARM_DESC(ql2xtgt_tape_enable,
37 "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER.");
39 static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED;
40 module_param(qlini_mode, charp, S_IRUGO);
41 MODULE_PARM_DESC(qlini_mode,
42 "Determines when initiator mode will be enabled. Possible values: "
43 "\"exclusive\" - initiator mode will be enabled on load, "
44 "disabled on enabling target mode and then on disabling target mode "
46 "\"disabled\" - initiator mode will never be enabled; "
47 "\"dual\" - Initiator Modes will be enabled. Target Mode can be activated "
49 "\"enabled\" (default) - initiator mode will always stay enabled.");
51 static int ql_dm_tgt_ex_pct = 0;
52 module_param(ql_dm_tgt_ex_pct, int, S_IRUGO|S_IWUSR);
53 MODULE_PARM_DESC(ql_dm_tgt_ex_pct,
54 "For Dual Mode (qlini_mode=dual), this parameter determines "
55 "the percentage of exchanges/cmds FW will allocate resources "
59 module_param(ql2xuctrlirq, int, 0644);
60 MODULE_PARM_DESC(ql2xuctrlirq,
61 "User to control IRQ placement via smp_affinity."
62 "Valid with qlini_mode=disabled."
63 "1(default): enable");
65 int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE;
67 static int qla_sam_status = SAM_STAT_BUSY;
68 static int tc_sam_status = SAM_STAT_TASK_SET_FULL; /* target core */
71 * From scsi/fc/fc_fcp.h
73 enum fcp_resp_rsp_codes {
75 FCP_DATA_LEN_INVALID = 1,
76 FCP_CMND_FIELDS_INVALID = 2,
77 FCP_DATA_PARAM_MISMATCH = 3,
80 FCP_TMF_INVALID_LUN = 9,
84 * fc_pri_ta from scsi/fc/fc_fcp.h
86 #define FCP_PTA_SIMPLE 0 /* simple task attribute */
87 #define FCP_PTA_HEADQ 1 /* head of queue task attribute */
88 #define FCP_PTA_ORDERED 2 /* ordered task attribute */
89 #define FCP_PTA_ACA 4 /* auto. contingent allegiance */
90 #define FCP_PTA_MASK 7 /* mask for task attribute field */
91 #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */
92 #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */
95 * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which
96 * must be called under HW lock and could unlock/lock it inside.
97 * It isn't an issue, since in the current implementation on the time when
98 * those functions are called:
100 * - Either context is IRQ and only IRQ handler can modify HW data,
101 * including rings related fields,
103 * - Or access to target mode variables from struct qla_tgt doesn't
104 * cross those functions boundaries, except tgt_stop, which
105 * additionally protected by irq_cmd_count.
107 /* Predefs for callbacks handed to qla2xxx LLD */
108 static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha,
109 struct atio_from_isp *pkt, uint8_t);
110 static void qlt_response_pkt(struct scsi_qla_host *ha, struct rsp_que *rsp,
112 static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun,
113 int fn, void *iocb, int flags);
114 static void qlt_send_term_exchange(struct qla_qpair *, struct qla_tgt_cmd
115 *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort);
116 static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
117 struct atio_from_isp *atio, uint16_t status, int qfull);
118 static void qlt_disable_vha(struct scsi_qla_host *vha);
119 static void qlt_clear_tgt_db(struct qla_tgt *tgt);
120 static void qlt_send_notify_ack(struct qla_qpair *qpair,
121 struct imm_ntfy_from_isp *ntfy,
122 uint32_t add_flags, uint16_t resp_code, int resp_code_valid,
123 uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan);
124 static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
125 struct imm_ntfy_from_isp *imm, int ha_locked);
126 static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha,
127 fc_port_t *fcport, bool local);
128 void qlt_unreg_sess(struct fc_port *sess);
129 static void qlt_24xx_handle_abts(struct scsi_qla_host *,
130 struct abts_recv_from_24xx *);
131 static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *,
133 static int qlt_check_reserve_free_req(struct qla_qpair *qpair, uint32_t);
134 static inline uint32_t qlt_make_handle(struct qla_qpair *);
139 static struct kmem_cache *qla_tgt_mgmt_cmd_cachep;
140 struct kmem_cache *qla_tgt_plogi_cachep;
141 static mempool_t *qla_tgt_mgmt_cmd_mempool;
142 static struct workqueue_struct *qla_tgt_wq;
143 static DEFINE_MUTEX(qla_tgt_mutex);
144 static LIST_HEAD(qla_tgt_glist);
146 static const char *prot_op_str(u32 prot_op)
149 case TARGET_PROT_NORMAL: return "NORMAL";
150 case TARGET_PROT_DIN_INSERT: return "DIN_INSERT";
151 case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT";
152 case TARGET_PROT_DIN_STRIP: return "DIN_STRIP";
153 case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP";
154 case TARGET_PROT_DIN_PASS: return "DIN_PASS";
155 case TARGET_PROT_DOUT_PASS: return "DOUT_PASS";
156 default: return "UNKNOWN";
160 /* This API intentionally takes dest as a parameter, rather than returning
161 * int value to avoid caller forgetting to issue wmb() after the store */
162 void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest)
164 scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev);
165 *dest = atomic_inc_return(&base_vha->generation_tick);
170 /* Might release hw lock, then reaquire!! */
171 static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked)
173 /* Send marker if required */
174 if (unlikely(vha->marker_needed != 0)) {
175 int rc = qla2x00_issue_marker(vha, vha_locked);
177 if (rc != QLA_SUCCESS) {
178 ql_dbg(ql_dbg_tgt, vha, 0xe03d,
179 "qla_target(%d): issue_marker() failed\n",
187 struct scsi_qla_host *qla_find_host_by_d_id(struct scsi_qla_host *vha,
190 struct scsi_qla_host *host;
193 if (vha->d_id.b.area == d_id.area &&
194 vha->d_id.b.domain == d_id.domain &&
195 vha->d_id.b.al_pa == d_id.al_pa)
198 key = be_to_port_id(d_id).b24;
200 host = btree_lookup32(&vha->hw->host_map, key);
202 ql_dbg(ql_dbg_tgt_mgt + ql_dbg_verbose, vha, 0xf005,
203 "Unable to find host %06x\n", key);
209 struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha,
212 struct qla_hw_data *ha = vha->hw;
214 if (vha->vp_idx == vp_idx)
217 BUG_ON(ha->tgt.tgt_vp_map == NULL);
218 if (likely(test_bit(vp_idx, ha->vp_idx_map)))
219 return ha->tgt.tgt_vp_map[vp_idx].vha;
224 static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha)
228 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
230 vha->hw->tgt.num_pend_cmds++;
231 if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds)
232 vha->qla_stats.stat_max_pend_cmds =
233 vha->hw->tgt.num_pend_cmds;
234 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
236 static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha)
240 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
241 vha->hw->tgt.num_pend_cmds--;
242 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
246 static void qlt_queue_unknown_atio(scsi_qla_host_t *vha,
247 struct atio_from_isp *atio, uint8_t ha_locked)
249 struct qla_tgt_sess_op *u;
250 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
254 ql_dbg(ql_dbg_async, vha, 0x502c,
255 "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped",
260 u = kzalloc(sizeof(*u), GFP_ATOMIC);
265 memcpy(&u->atio, atio, sizeof(*atio));
266 INIT_LIST_HEAD(&u->cmd_list);
268 spin_lock_irqsave(&vha->cmd_list_lock, flags);
269 list_add_tail(&u->cmd_list, &vha->unknown_atio_list);
270 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
272 schedule_delayed_work(&vha->unknown_atio_work, 1);
278 qlt_send_term_exchange(vha->hw->base_qpair, NULL, atio, ha_locked, 0);
282 static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha,
285 struct qla_tgt_sess_op *u, *t;
286 scsi_qla_host_t *host;
287 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
291 list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) {
293 ql_dbg(ql_dbg_async, vha, 0x502e,
294 "Freeing unknown %s %p, because of Abort\n",
296 qlt_send_term_exchange(vha->hw->base_qpair, NULL,
297 &u->atio, ha_locked, 0);
301 host = qla_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id);
303 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x502f,
304 "Requeuing unknown ATIO_TYPE7 %p\n", u);
305 qlt_24xx_atio_pkt(host, &u->atio, ha_locked);
306 } else if (tgt->tgt_stop) {
307 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503a,
308 "Freeing unknown %s %p, because tgt is being stopped\n",
310 qlt_send_term_exchange(vha->hw->base_qpair, NULL,
311 &u->atio, ha_locked, 0);
313 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d,
314 "Reschedule u %p, vha %p, host %p\n", u, vha, host);
317 schedule_delayed_work(&vha->unknown_atio_work,
324 spin_lock_irqsave(&vha->cmd_list_lock, flags);
325 list_del(&u->cmd_list);
326 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
331 void qlt_unknown_atio_work_fn(struct work_struct *work)
333 struct scsi_qla_host *vha = container_of(to_delayed_work(work),
334 struct scsi_qla_host, unknown_atio_work);
336 qlt_try_to_dequeue_unknown_atios(vha, 0);
339 static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *vha,
340 struct atio_from_isp *atio, uint8_t ha_locked)
342 ql_dbg(ql_dbg_tgt, vha, 0xe072,
343 "%s: qla_target(%d): type %x ox_id %04x\n",
344 __func__, vha->vp_idx, atio->u.raw.entry_type,
345 be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
347 switch (atio->u.raw.entry_type) {
350 struct scsi_qla_host *host = qla_find_host_by_d_id(vha,
351 atio->u.isp24.fcp_hdr.d_id);
352 if (unlikely(NULL == host)) {
353 ql_dbg(ql_dbg_tgt, vha, 0xe03e,
354 "qla_target(%d): Received ATIO_TYPE7 "
355 "with unknown d_id %x:%x:%x\n", vha->vp_idx,
356 atio->u.isp24.fcp_hdr.d_id.domain,
357 atio->u.isp24.fcp_hdr.d_id.area,
358 atio->u.isp24.fcp_hdr.d_id.al_pa);
361 qlt_queue_unknown_atio(vha, atio, ha_locked);
364 if (unlikely(!list_empty(&vha->unknown_atio_list)))
365 qlt_try_to_dequeue_unknown_atios(vha, ha_locked);
367 qlt_24xx_atio_pkt(host, atio, ha_locked);
371 case IMMED_NOTIFY_TYPE:
373 struct scsi_qla_host *host = vha;
374 struct imm_ntfy_from_isp *entry =
375 (struct imm_ntfy_from_isp *)atio;
377 qlt_issue_marker(vha, ha_locked);
379 if ((entry->u.isp24.vp_index != 0xFF) &&
380 (entry->u.isp24.nport_handle != cpu_to_le16(0xFFFF))) {
381 host = qlt_find_host_by_vp_idx(vha,
382 entry->u.isp24.vp_index);
383 if (unlikely(!host)) {
384 ql_dbg(ql_dbg_tgt, vha, 0xe03f,
385 "qla_target(%d): Received "
386 "ATIO (IMMED_NOTIFY_TYPE) "
387 "with unknown vp_index %d\n",
388 vha->vp_idx, entry->u.isp24.vp_index);
392 qlt_24xx_atio_pkt(host, atio, ha_locked);
396 case VP_RPT_ID_IOCB_TYPE:
397 qla24xx_report_id_acquisition(vha,
398 (struct vp_rpt_id_entry_24xx *)atio);
403 struct abts_recv_from_24xx *entry =
404 (struct abts_recv_from_24xx *)atio;
405 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
409 if (unlikely(!host)) {
410 ql_dbg(ql_dbg_tgt, vha, 0xe00a,
411 "qla_target(%d): Response pkt (ABTS_RECV_24XX) "
412 "received, with unknown vp_index %d\n",
413 vha->vp_idx, entry->vp_index);
417 spin_lock_irqsave(&host->hw->hardware_lock, flags);
418 qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio);
420 spin_unlock_irqrestore(&host->hw->hardware_lock, flags);
424 /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */
427 ql_dbg(ql_dbg_tgt, vha, 0xe040,
428 "qla_target(%d): Received unknown ATIO atio "
429 "type %x\n", vha->vp_idx, atio->u.raw.entry_type);
436 void qlt_response_pkt_all_vps(struct scsi_qla_host *vha,
437 struct rsp_que *rsp, response_t *pkt)
439 switch (pkt->entry_type) {
441 ql_dbg(ql_dbg_tgt, vha, 0xe073,
442 "qla_target(%d):%s: CRC2 Response pkt\n",
443 vha->vp_idx, __func__);
447 struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
448 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
450 if (unlikely(!host)) {
451 ql_dbg(ql_dbg_tgt, vha, 0xe041,
452 "qla_target(%d): Response pkt (CTIO_TYPE7) "
453 "received, with unknown vp_index %d\n",
454 vha->vp_idx, entry->vp_index);
457 qlt_response_pkt(host, rsp, pkt);
461 case IMMED_NOTIFY_TYPE:
463 struct scsi_qla_host *host;
464 struct imm_ntfy_from_isp *entry =
465 (struct imm_ntfy_from_isp *)pkt;
467 host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index);
468 if (unlikely(!host)) {
469 ql_dbg(ql_dbg_tgt, vha, 0xe042,
470 "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
471 "received, with unknown vp_index %d\n",
472 vha->vp_idx, entry->u.isp24.vp_index);
475 qlt_response_pkt(host, rsp, pkt);
479 case NOTIFY_ACK_TYPE:
481 struct scsi_qla_host *host = vha;
482 struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
484 if (0xFF != entry->u.isp24.vp_index) {
485 host = qlt_find_host_by_vp_idx(vha,
486 entry->u.isp24.vp_index);
487 if (unlikely(!host)) {
488 ql_dbg(ql_dbg_tgt, vha, 0xe043,
489 "qla_target(%d): Response "
490 "pkt (NOTIFY_ACK_TYPE) "
491 "received, with unknown "
492 "vp_index %d\n", vha->vp_idx,
493 entry->u.isp24.vp_index);
497 qlt_response_pkt(host, rsp, pkt);
503 struct abts_recv_from_24xx *entry =
504 (struct abts_recv_from_24xx *)pkt;
505 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
507 if (unlikely(!host)) {
508 ql_dbg(ql_dbg_tgt, vha, 0xe044,
509 "qla_target(%d): Response pkt "
510 "(ABTS_RECV_24XX) received, with unknown "
511 "vp_index %d\n", vha->vp_idx, entry->vp_index);
514 qlt_response_pkt(host, rsp, pkt);
520 struct abts_resp_to_24xx *entry =
521 (struct abts_resp_to_24xx *)pkt;
522 struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
524 if (unlikely(!host)) {
525 ql_dbg(ql_dbg_tgt, vha, 0xe045,
526 "qla_target(%d): Response pkt "
527 "(ABTS_RECV_24XX) received, with unknown "
528 "vp_index %d\n", vha->vp_idx, entry->vp_index);
531 qlt_response_pkt(host, rsp, pkt);
535 qlt_response_pkt(vha, rsp, pkt);
542 * All qlt_plogi_ack_t operations are protected by hardware_lock
544 static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport,
545 struct imm_ntfy_from_isp *ntfy, int type)
547 struct qla_work_evt *e;
549 e = qla2x00_alloc_work(vha, QLA_EVT_NACK);
551 return QLA_FUNCTION_FAILED;
553 e->u.nack.fcport = fcport;
554 e->u.nack.type = type;
555 memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp));
556 return qla2x00_post_work(vha, e);
559 static void qla2x00_async_nack_sp_done(srb_t *sp, int res)
561 struct scsi_qla_host *vha = sp->vha;
564 ql_dbg(ql_dbg_disc, vha, 0x20f2,
565 "Async done-%s res %x %8phC type %d\n",
566 sp->name, res, sp->fcport->port_name, sp->type);
568 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
569 sp->fcport->flags &= ~FCF_ASYNC_SENT;
570 sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
574 sp->fcport->login_gen++;
575 sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
576 sp->fcport->logout_on_delete = 1;
577 sp->fcport->plogi_nack_done_deadline = jiffies + HZ;
578 sp->fcport->send_els_logo = 0;
580 if (sp->fcport->flags & FCF_FCSP_DEVICE) {
581 ql_dbg(ql_dbg_edif, vha, 0x20ef,
582 "%s %8phC edif: PLOGI- AUTH WAIT\n", __func__,
583 sp->fcport->port_name);
584 qla2x00_set_fcport_disc_state(sp->fcport,
585 DSC_LOGIN_AUTH_PEND);
586 qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE,
587 sp->fcport->d_id.b24);
592 sp->fcport->fw_login_state = DSC_LS_PRLI_COMP;
593 sp->fcport->deleted = 0;
594 sp->fcport->send_els_logo = 0;
596 if (!sp->fcport->login_succ &&
597 !IS_SW_RESV_ADDR(sp->fcport->d_id)) {
598 sp->fcport->login_succ = 1;
601 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
602 qla24xx_sched_upd_fcport(sp->fcport);
603 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
605 sp->fcport->login_retry = 0;
606 qla2x00_set_fcport_disc_state(sp->fcport,
608 sp->fcport->deleted = 0;
609 sp->fcport->logout_on_delete = 1;
614 sp->fcport->login_gen++;
615 sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
616 qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE);
619 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
624 int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport,
625 struct imm_ntfy_from_isp *ntfy, int type)
627 int rval = QLA_FUNCTION_FAILED;
631 fcport->flags |= FCF_ASYNC_SENT;
634 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
636 if (vha->hw->flags.edif_enabled &&
637 (le16_to_cpu(ntfy->u.isp24.flags) & NOTIFY24XX_FLAGS_FCSP)) {
638 fcport->flags |= FCF_FCSP_DEVICE;
642 fcport->fw_login_state = DSC_LS_PRLI_PEND;
647 fcport->fw_login_state = DSC_LS_LOGO_PEND;
652 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
659 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
660 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
662 sp->u.iocb_cmd.u.nack.ntfy = ntfy;
663 sp->done = qla2x00_async_nack_sp_done;
665 ql_dbg(ql_dbg_disc, vha, 0x20f4,
666 "Async-%s %8phC hndl %x %s\n",
667 sp->name, fcport->port_name, sp->handle, c);
669 rval = qla2x00_start_sp(sp);
670 if (rval != QLA_SUCCESS)
678 fcport->flags &= ~FCF_ASYNC_SENT;
682 void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
686 switch (e->u.nack.type) {
688 t = e->u.nack.fcport;
689 flush_work(&t->del_work);
690 flush_work(&t->free_work);
691 mutex_lock(&vha->vha_tgt.tgt_mutex);
692 t = qlt_create_sess(vha, e->u.nack.fcport, 0);
693 mutex_unlock(&vha->vha_tgt.tgt_mutex);
695 ql_log(ql_log_info, vha, 0xd034,
696 "%s create sess success %p", __func__, t);
697 /* create sess has an extra kref */
698 vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport);
702 qla24xx_async_notify_ack(vha, e->u.nack.fcport,
703 (struct imm_ntfy_from_isp *)e->u.nack.iocb, e->u.nack.type);
706 void qla24xx_delete_sess_fn(struct work_struct *work)
708 fc_port_t *fcport = container_of(work, struct fc_port, del_work);
709 struct qla_hw_data *ha = NULL;
711 if (!fcport || !fcport->vha || !fcport->vha->hw)
714 ha = fcport->vha->hw;
716 if (fcport->se_sess) {
717 ha->tgt.tgt_ops->shutdown_sess(fcport);
718 ha->tgt.tgt_ops->put_sess(fcport);
720 qlt_unreg_sess(fcport);
725 * Called from qla2x00_reg_remote_port()
727 void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport)
729 struct qla_hw_data *ha = vha->hw;
730 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
731 struct fc_port *sess = fcport;
734 if (!vha->hw->tgt.tgt_ops)
737 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
739 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
743 if (fcport->disc_state == DSC_DELETE_PEND) {
744 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
748 if (!sess->se_sess) {
749 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
751 mutex_lock(&vha->vha_tgt.tgt_mutex);
752 sess = qlt_create_sess(vha, fcport, false);
753 mutex_unlock(&vha->vha_tgt.tgt_mutex);
755 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
757 if (fcport->fw_login_state == DSC_LS_PRLI_COMP) {
758 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
762 if (!kref_get_unless_zero(&sess->sess_kref)) {
763 ql_dbg(ql_dbg_disc, vha, 0x2107,
764 "%s: kref_get fail sess %8phC \n",
765 __func__, sess->port_name);
766 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
770 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c,
771 "qla_target(%u): %ssession for port %8phC "
772 "(loop ID %d) reappeared\n", vha->vp_idx,
773 sess->local ? "local " : "", sess->port_name, sess->loop_id);
775 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007,
776 "Reappeared sess %p\n", sess);
778 ha->tgt.tgt_ops->update_sess(sess, fcport->d_id,
780 (fcport->flags & FCF_CONF_COMP_SUPPORTED));
783 if (sess && sess->local) {
784 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d,
785 "qla_target(%u): local session for "
786 "port %8phC (loop ID %d) became global\n", vha->vp_idx,
787 fcport->port_name, sess->loop_id);
790 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
792 ha->tgt.tgt_ops->put_sess(sess);
796 * This is a zero-base ref-counting solution, since hardware_lock
797 * guarantees that ref_count is not modified concurrently.
798 * Upon successful return content of iocb is undefined
800 static struct qlt_plogi_ack_t *
801 qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id,
802 struct imm_ntfy_from_isp *iocb)
804 struct qlt_plogi_ack_t *pla;
806 lockdep_assert_held(&vha->hw->hardware_lock);
808 list_for_each_entry(pla, &vha->plogi_ack_list, list) {
809 if (pla->id.b24 == id->b24) {
810 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x210d,
811 "%s %d %8phC Term INOT due to new INOT",
813 pla->iocb.u.isp24.port_name);
814 qlt_send_term_imm_notif(vha, &pla->iocb, 1);
815 memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
820 pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC);
822 ql_dbg(ql_dbg_async, vha, 0x5088,
823 "qla_target(%d): Allocation of plogi_ack failed\n",
828 memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
830 list_add_tail(&pla->list, &vha->plogi_ack_list);
835 void qlt_plogi_ack_unref(struct scsi_qla_host *vha,
836 struct qlt_plogi_ack_t *pla)
838 struct imm_ntfy_from_isp *iocb = &pla->iocb;
841 fc_port_t *fcport = pla->fcport;
843 BUG_ON(!pla->ref_count);
849 ql_dbg(ql_dbg_disc, vha, 0x5089,
850 "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x"
851 " exch %#x ox_id %#x\n", iocb->u.isp24.port_name,
852 iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1],
853 iocb->u.isp24.port_id[0],
854 le16_to_cpu(iocb->u.isp24.nport_handle),
855 iocb->u.isp24.exchange_address, iocb->ox_id);
857 port_id.b.domain = iocb->u.isp24.port_id[2];
858 port_id.b.area = iocb->u.isp24.port_id[1];
859 port_id.b.al_pa = iocb->u.isp24.port_id[0];
860 port_id.b.rsvd_1 = 0;
862 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
864 fcport->loop_id = loop_id;
865 fcport->d_id = port_id;
866 if (iocb->u.isp24.status_subcode == ELS_PLOGI)
867 qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI);
869 qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PRLI);
871 list_for_each_entry(fcport, &vha->vp_fcports, list) {
872 if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla)
873 fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL;
874 if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla)
875 fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL;
878 list_del(&pla->list);
879 kmem_cache_free(qla_tgt_plogi_cachep, pla);
883 qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla,
884 struct fc_port *sess, enum qlt_plogi_link_t link)
886 struct imm_ntfy_from_isp *iocb = &pla->iocb;
887 /* Inc ref_count first because link might already be pointing at pla */
890 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097,
891 "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC"
892 " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n",
893 sess, link, sess->port_name,
894 iocb->u.isp24.port_name, iocb->u.isp24.port_id[2],
895 iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0],
896 pla->ref_count, pla, link);
898 if (link == QLT_PLOGI_LINK_CONFLICT) {
899 switch (sess->disc_state) {
901 case DSC_DELETE_PEND:
909 if (sess->plogi_link[link])
910 qlt_plogi_ack_unref(vha, sess->plogi_link[link]);
912 if (link == QLT_PLOGI_LINK_SAME_WWN)
915 sess->plogi_link[link] = pla;
919 /* These fields must be initialized by the caller */
922 * number of cmds dropped while we were waiting for
923 * initiator to ack LOGO initialize to 1 if LOGO is
924 * triggered by a command, otherwise, to 0
928 /* These fields are used by callee */
929 struct list_head list;
933 qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo)
935 qlt_port_logo_t *tmp;
938 mutex_lock(&vha->vha_tgt.tgt_mutex);
940 list_for_each_entry(tmp, &vha->logo_list, list) {
941 if (tmp->id.b24 == logo->id.b24) {
942 tmp->cmd_count += logo->cmd_count;
943 mutex_unlock(&vha->vha_tgt.tgt_mutex);
948 list_add_tail(&logo->list, &vha->logo_list);
950 mutex_unlock(&vha->vha_tgt.tgt_mutex);
952 res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id);
954 mutex_lock(&vha->vha_tgt.tgt_mutex);
955 list_del(&logo->list);
956 mutex_unlock(&vha->vha_tgt.tgt_mutex);
958 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098,
959 "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n",
960 logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa,
961 logo->cmd_count, res);
964 void qlt_free_session_done(struct work_struct *work)
966 struct fc_port *sess = container_of(work, struct fc_port,
968 struct qla_tgt *tgt = sess->tgt;
969 struct scsi_qla_host *vha = sess->vha;
970 struct qla_hw_data *ha = vha->hw;
972 bool logout_started = false;
973 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
974 struct qlt_plogi_ack_t *own =
975 sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
977 ql_dbg(ql_dbg_disc, vha, 0xf084,
978 "%s: se_sess %p / sess %p from port %8phC loop_id %#04x"
979 " s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n",
980 __func__, sess->se_sess, sess, sess->port_name, sess->loop_id,
981 sess->d_id.b.domain, sess->d_id.b.area, sess->d_id.b.al_pa,
982 sess->logout_on_delete, sess->keep_nport_handle,
983 sess->send_els_logo);
985 if (!IS_SW_RESV_ADDR(sess->d_id)) {
986 if (ha->flags.edif_enabled &&
987 (!own || own->iocb.u.isp24.status_subcode == ELS_PLOGI)) {
988 if (!ha->flags.host_shutting_down) {
989 ql_dbg(ql_dbg_edif, vha, 0x911e,
990 "%s wwpn %8phC calling qla2x00_release_all_sadb\n",
991 __func__, sess->port_name);
992 qla2x00_release_all_sadb(vha, sess);
994 ql_dbg(ql_dbg_edif, vha, 0x911e,
995 "%s bypassing release_all_sadb\n",
999 qla2x00_mark_device_lost(vha, sess, 0);
1001 if (sess->send_els_logo) {
1002 qlt_port_logo_t logo;
1004 logo.id = sess->d_id;
1006 INIT_LIST_HEAD(&logo.list);
1008 qlt_send_first_logo(vha, &logo);
1009 sess->send_els_logo = 0;
1012 if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) {
1016 (own->iocb.u.isp24.status_subcode == ELS_PLOGI)) {
1017 sess->logout_completed = 0;
1018 rc = qla2x00_post_async_logout_work(vha, sess,
1020 if (rc != QLA_SUCCESS)
1021 ql_log(ql_log_warn, vha, 0xf085,
1022 "Schedule logo failed sess %p rc %d\n",
1025 logout_started = true;
1026 } else if (own && (own->iocb.u.isp24.status_subcode ==
1027 ELS_PRLI) && ha->flags.rida_fmt2) {
1028 rc = qla2x00_post_async_prlo_work(vha, sess,
1030 if (rc != QLA_SUCCESS)
1031 ql_log(ql_log_warn, vha, 0xf085,
1032 "Schedule PRLO failed sess %p rc %d\n",
1035 logout_started = true;
1037 } /* if sess->logout_on_delete */
1039 if (sess->nvme_flag & NVME_FLAG_REGISTERED &&
1040 !(sess->nvme_flag & NVME_FLAG_DELETING)) {
1041 sess->nvme_flag |= NVME_FLAG_DELETING;
1042 qla_nvme_unregister_remote_port(sess);
1047 * Release the target session for FC Nexus from fabric module code.
1049 if (sess->se_sess != NULL)
1050 ha->tgt.tgt_ops->free_session(sess);
1052 if (logout_started) {
1053 bool traced = false;
1056 while (!READ_ONCE(sess->logout_completed)) {
1058 ql_dbg(ql_dbg_disc, vha, 0xf086,
1059 "%s: waiting for sess %p logout\n",
1066 * Driver timeout is set to 22 Sec, update count value to loop
1067 * long enough for log-out to complete before advancing. Otherwise,
1068 * straddling logout can interfere with re-login attempt.
1074 ql_dbg(ql_dbg_disc, vha, 0xf087,
1075 "%s: sess %p logout completed\n", __func__, sess);
1078 if (sess->logo_ack_needed) {
1079 sess->logo_ack_needed = 0;
1080 qla24xx_async_notify_ack(vha, sess,
1081 (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO);
1084 spin_lock_irqsave(&vha->work_lock, flags);
1085 sess->flags &= ~FCF_ASYNC_SENT;
1086 spin_unlock_irqrestore(&vha->work_lock, flags);
1088 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1089 if (sess->se_sess) {
1090 sess->se_sess = NULL;
1091 if (tgt && !IS_SW_RESV_ADDR(sess->d_id))
1095 qla2x00_set_fcport_disc_state(sess, DSC_DELETED);
1096 sess->fw_login_state = DSC_LS_PORT_UNAVAIL;
1097 sess->deleted = QLA_SESS_DELETED;
1099 if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) {
1100 vha->fcport_count--;
1101 sess->login_succ = 0;
1104 qla2x00_clear_loop_id(sess);
1106 if (sess->conflict) {
1107 sess->conflict->login_pause = 0;
1108 sess->conflict = NULL;
1109 if (!test_bit(UNLOADING, &vha->dpc_flags))
1110 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1114 struct qlt_plogi_ack_t *con =
1115 sess->plogi_link[QLT_PLOGI_LINK_CONFLICT];
1116 struct imm_ntfy_from_isp *iocb;
1118 own = sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
1122 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099,
1123 "se_sess %p / sess %p port %8phC is gone,"
1124 " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n",
1125 sess->se_sess, sess, sess->port_name,
1126 own ? "releasing own PLOGI" : "no own PLOGI pending",
1127 own ? own->ref_count : -1,
1128 iocb->u.isp24.port_name, con->ref_count);
1129 qlt_plogi_ack_unref(vha, con);
1130 sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL;
1132 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a,
1133 "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n",
1134 sess->se_sess, sess, sess->port_name,
1135 own ? "releasing own PLOGI" :
1136 "no own PLOGI pending",
1137 own ? own->ref_count : -1);
1141 sess->fw_login_state = DSC_LS_PLOGI_PEND;
1142 qlt_plogi_ack_unref(vha, own);
1143 sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL;
1147 sess->explicit_logout = 0;
1148 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1149 sess->free_pending = 0;
1151 qla2x00_dfs_remove_rport(vha, sess);
1153 ql_dbg(ql_dbg_disc, vha, 0xf001,
1154 "Unregistration of sess %p %8phC finished fcp_cnt %d\n",
1155 sess, sess->port_name, vha->fcport_count);
1157 if (tgt && (tgt->sess_count == 0))
1158 wake_up_all(&tgt->waitQ);
1160 if (!test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags) &&
1161 !(vha->vp_idx && test_bit(VPORT_DELETE, &vha->dpc_flags)) &&
1162 (!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) {
1163 switch (vha->host->active_mode) {
1164 case MODE_INITIATOR:
1166 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1167 qla2xxx_wake_dpc(vha);
1176 if (vha->fcport_count == 0)
1177 wake_up_all(&vha->fcport_waitQ);
1180 /* ha->tgt.sess_lock supposed to be held on entry */
1181 void qlt_unreg_sess(struct fc_port *sess)
1183 struct scsi_qla_host *vha = sess->vha;
1184 unsigned long flags;
1186 ql_dbg(ql_dbg_disc, sess->vha, 0x210a,
1187 "%s sess %p for deletion %8phC\n",
1188 __func__, sess, sess->port_name);
1190 spin_lock_irqsave(&sess->vha->work_lock, flags);
1191 if (sess->free_pending) {
1192 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1195 sess->free_pending = 1;
1197 * Use FCF_ASYNC_SENT flag to block other cmds used in sess
1198 * management from being sent.
1200 sess->flags |= FCF_ASYNC_SENT;
1201 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1204 vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess);
1206 sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
1207 qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND);
1208 sess->last_rscn_gen = sess->rscn_gen;
1209 sess->last_login_gen = sess->login_gen;
1211 queue_work(sess->vha->hw->wq, &sess->free_work);
1213 EXPORT_SYMBOL(qlt_unreg_sess);
1215 static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd)
1217 struct qla_hw_data *ha = vha->hw;
1218 struct fc_port *sess = NULL;
1221 struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb;
1222 unsigned long flags;
1224 loop_id = le16_to_cpu(n->u.isp24.nport_handle);
1225 if (loop_id == 0xFFFF) {
1227 atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count);
1228 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1229 qlt_clear_tgt_db(vha->vha_tgt.qla_tgt);
1230 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1232 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1233 sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
1234 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1237 ql_dbg(ql_dbg_tgt, vha, 0xe000,
1238 "Using sess for qla_tgt_reset: %p\n", sess);
1244 ql_dbg(ql_dbg_tgt, vha, 0xe047,
1245 "scsi(%ld): resetting (session %p from port %8phC mcmd %x, "
1246 "loop_id %d)\n", vha->host_no, sess, sess->port_name,
1249 return qlt_issue_task_mgmt(sess, 0, mcmd, iocb, QLA24XX_MGMT_SEND_NACK);
1252 static void qla24xx_chk_fcp_state(struct fc_port *sess)
1254 if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) {
1255 sess->logout_on_delete = 0;
1256 sess->logo_ack_needed = 0;
1257 sess->fw_login_state = DSC_LS_PORT_UNAVAIL;
1261 void qlt_schedule_sess_for_deletion(struct fc_port *sess)
1263 struct qla_tgt *tgt = sess->tgt;
1264 unsigned long flags;
1267 switch (sess->disc_state) {
1268 case DSC_DELETE_PEND:
1271 if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] &&
1272 !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) {
1273 if (tgt && tgt->tgt_stop && tgt->sess_count == 0)
1274 wake_up_all(&tgt->waitQ);
1276 if (sess->vha->fcport_count == 0)
1277 wake_up_all(&sess->vha->fcport_waitQ);
1281 case DSC_UPD_FCPORT:
1283 * This port is not done reporting to upper layer.
1286 sess->next_disc_state = DSC_DELETE_PEND;
1287 sec = jiffies_to_msecs(jiffies -
1288 sess->jiffies_at_registration)/1000;
1289 if (sess->sec_since_registration < sec && sec && !(sec % 5)) {
1290 sess->sec_since_registration = sec;
1291 ql_dbg(ql_dbg_disc, sess->vha, 0xffff,
1292 "%s %8phC : Slow Rport registration(%d Sec)\n",
1293 __func__, sess->port_name, sec);
1300 spin_lock_irqsave(&sess->vha->work_lock, flags);
1301 if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) {
1302 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1305 sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
1306 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
1308 sess->prli_pend_timer = 0;
1309 qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND);
1311 qla24xx_chk_fcp_state(sess);
1313 ql_dbg(ql_log_warn, sess->vha, 0xe001,
1314 "Scheduling sess %p for deletion %8phC\n",
1315 sess, sess->port_name);
1317 WARN_ON(!queue_work(sess->vha->hw->wq, &sess->del_work));
1320 static void qlt_clear_tgt_db(struct qla_tgt *tgt)
1322 struct fc_port *sess;
1323 scsi_qla_host_t *vha = tgt->vha;
1325 list_for_each_entry(sess, &vha->vp_fcports, list) {
1327 qlt_schedule_sess_for_deletion(sess);
1330 /* At this point tgt could be already dead */
1333 static int qla24xx_get_loop_id(struct scsi_qla_host *vha, be_id_t s_id,
1336 struct qla_hw_data *ha = vha->hw;
1337 dma_addr_t gid_list_dma;
1338 struct gid_list_info *gid_list, *gid;
1342 gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
1343 &gid_list_dma, GFP_KERNEL);
1345 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044,
1346 "qla_target(%d): DMA Alloc failed of %u\n",
1347 vha->vp_idx, qla2x00_gid_list_size(ha));
1351 /* Get list of logged in devices */
1352 rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries);
1353 if (rc != QLA_SUCCESS) {
1354 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045,
1355 "qla_target(%d): get_id_list() failed: %x\n",
1358 goto out_free_id_list;
1363 for (i = 0; i < entries; i++) {
1364 if (gid->al_pa == s_id.al_pa &&
1365 gid->area == s_id.area &&
1366 gid->domain == s_id.domain) {
1367 *loop_id = le16_to_cpu(gid->loop_id);
1371 gid = (void *)gid + ha->gid_list_info_size;
1375 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
1376 gid_list, gid_list_dma);
1381 * Adds an extra ref to allow to drop hw lock after adding sess to the list.
1382 * Caller must put it.
1384 static struct fc_port *qlt_create_sess(
1385 struct scsi_qla_host *vha,
1389 struct qla_hw_data *ha = vha->hw;
1390 struct fc_port *sess = fcport;
1391 unsigned long flags;
1393 if (vha->vha_tgt.qla_tgt->tgt_stop)
1396 if (fcport->se_sess) {
1397 if (!kref_get_unless_zero(&sess->sess_kref)) {
1398 ql_dbg(ql_dbg_disc, vha, 0x20f6,
1399 "%s: kref_get_unless_zero failed for %8phC\n",
1400 __func__, sess->port_name);
1405 sess->tgt = vha->vha_tgt.qla_tgt;
1406 sess->local = local;
1409 * Under normal circumstances we want to logout from firmware when
1410 * session eventually ends and release corresponding nport handle.
1411 * In the exception cases (e.g. when new PLOGI is waiting) corresponding
1412 * code will adjust these flags as necessary.
1414 sess->logout_on_delete = 1;
1415 sess->keep_nport_handle = 0;
1416 sess->logout_completed = 0;
1418 if (ha->tgt.tgt_ops->check_initiator_node_acl(vha,
1419 &fcport->port_name[0], sess) < 0) {
1420 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015,
1421 "(%d) %8phC check_initiator_node_acl failed\n",
1422 vha->vp_idx, fcport->port_name);
1425 kref_init(&fcport->sess_kref);
1427 * Take an extra reference to ->sess_kref here to handle
1428 * fc_port access across ->tgt.sess_lock reaquire.
1430 if (!kref_get_unless_zero(&sess->sess_kref)) {
1431 ql_dbg(ql_dbg_disc, vha, 0x20f7,
1432 "%s: kref_get_unless_zero failed for %8phC\n",
1433 __func__, sess->port_name);
1437 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1438 if (!IS_SW_RESV_ADDR(sess->d_id))
1439 vha->vha_tgt.qla_tgt->sess_count++;
1441 qlt_do_generation_tick(vha, &sess->generation);
1442 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1445 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006,
1446 "Adding sess %p se_sess %p to tgt %p sess_count %d\n",
1447 sess, sess->se_sess, vha->vha_tgt.qla_tgt,
1448 vha->vha_tgt.qla_tgt->sess_count);
1450 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b,
1451 "qla_target(%d): %ssession for wwn %8phC (loop_id %d, "
1452 "s_id %x:%x:%x, confirmed completion %ssupported) added\n",
1453 vha->vp_idx, local ? "local " : "", fcport->port_name,
1454 fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area,
1455 sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not ");
1461 * max_gen - specifies maximum session generation
1462 * at which this deletion requestion is still valid
1465 qlt_fc_port_deleted(struct scsi_qla_host *vha, fc_port_t *fcport, int max_gen)
1467 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1468 struct fc_port *sess = fcport;
1469 unsigned long flags;
1471 if (!vha->hw->tgt.tgt_ops)
1477 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1478 if (tgt->tgt_stop) {
1479 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1482 if (!sess->se_sess) {
1483 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1487 if (max_gen - sess->generation < 0) {
1488 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1489 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092,
1490 "Ignoring stale deletion request for se_sess %p / sess %p"
1491 " for port %8phC, req_gen %d, sess_gen %d\n",
1492 sess->se_sess, sess, sess->port_name, max_gen,
1497 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess);
1500 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1501 qlt_schedule_sess_for_deletion(sess);
1504 static inline int test_tgt_sess_count(struct qla_tgt *tgt)
1506 struct qla_hw_data *ha = tgt->ha;
1507 unsigned long flags;
1510 * We need to protect against race, when tgt is freed before or
1513 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1514 ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002,
1515 "tgt %p, sess_count=%d\n",
1516 tgt, tgt->sess_count);
1517 res = (tgt->sess_count == 0);
1518 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1523 /* Called by tcm_qla2xxx configfs code */
1524 int qlt_stop_phase1(struct qla_tgt *tgt)
1526 struct scsi_qla_host *vha = tgt->vha;
1527 struct qla_hw_data *ha = tgt->ha;
1528 unsigned long flags;
1530 mutex_lock(&ha->optrom_mutex);
1531 mutex_lock(&qla_tgt_mutex);
1533 if (tgt->tgt_stop || tgt->tgt_stopped) {
1534 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e,
1535 "Already in tgt->tgt_stop or tgt_stopped state\n");
1536 mutex_unlock(&qla_tgt_mutex);
1537 mutex_unlock(&ha->optrom_mutex);
1541 ql_dbg(ql_dbg_tgt_mgt, vha, 0xe003, "Stopping target for host %ld(%p)\n",
1544 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
1545 * Lock is needed, because we still can get an incoming packet.
1547 mutex_lock(&vha->vha_tgt.tgt_mutex);
1549 qlt_clear_tgt_db(tgt);
1550 mutex_unlock(&vha->vha_tgt.tgt_mutex);
1551 mutex_unlock(&qla_tgt_mutex);
1553 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009,
1554 "Waiting for sess works (tgt %p)", tgt);
1555 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1556 while (!list_empty(&tgt->sess_works_list)) {
1557 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1558 flush_scheduled_work();
1559 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1561 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1563 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a,
1564 "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count);
1566 wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
1569 if (!ha->flags.host_shutting_down &&
1570 (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)))
1571 qlt_disable_vha(vha);
1573 /* Wait for sessions to clear out (just in case) */
1574 wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
1575 mutex_unlock(&ha->optrom_mutex);
1579 EXPORT_SYMBOL(qlt_stop_phase1);
1581 /* Called by tcm_qla2xxx configfs code */
1582 void qlt_stop_phase2(struct qla_tgt *tgt)
1584 scsi_qla_host_t *vha = tgt->vha;
1586 if (tgt->tgt_stopped) {
1587 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f,
1588 "Already in tgt->tgt_stopped state\n");
1592 if (!tgt->tgt_stop) {
1593 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b,
1594 "%s: phase1 stop is not completed\n", __func__);
1599 mutex_lock(&tgt->ha->optrom_mutex);
1600 mutex_lock(&vha->vha_tgt.tgt_mutex);
1602 tgt->tgt_stopped = 1;
1603 mutex_unlock(&vha->vha_tgt.tgt_mutex);
1604 mutex_unlock(&tgt->ha->optrom_mutex);
1606 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00c, "Stop of tgt %p finished\n",
1609 switch (vha->qlini_mode) {
1610 case QLA2XXX_INI_MODE_EXCLUSIVE:
1611 vha->flags.online = 1;
1612 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1618 EXPORT_SYMBOL(qlt_stop_phase2);
1620 /* Called from qlt_remove_target() -> qla2x00_remove_one() */
1621 static void qlt_release(struct qla_tgt *tgt)
1623 scsi_qla_host_t *vha = tgt->vha;
1627 struct qla_qpair_hint *h;
1628 struct qla_hw_data *ha = vha->hw;
1630 if (!tgt->tgt_stop && !tgt->tgt_stopped)
1631 qlt_stop_phase1(tgt);
1633 if (!tgt->tgt_stopped)
1634 qlt_stop_phase2(tgt);
1636 for (i = 0; i < vha->hw->max_qpairs + 1; i++) {
1637 unsigned long flags;
1639 h = &tgt->qphints[i];
1641 spin_lock_irqsave(h->qpair->qp_lock_ptr, flags);
1642 list_del(&h->hint_elem);
1643 spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags);
1647 kfree(tgt->qphints);
1648 mutex_lock(&qla_tgt_mutex);
1649 list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry);
1650 mutex_unlock(&qla_tgt_mutex);
1652 btree_for_each_safe64(&tgt->lun_qpair_map, key, node)
1653 btree_remove64(&tgt->lun_qpair_map, key);
1655 btree_destroy64(&tgt->lun_qpair_map);
1658 if (ha->tgt.tgt_ops &&
1659 ha->tgt.tgt_ops->remove_target &&
1660 vha->vha_tgt.target_lport_ptr)
1661 ha->tgt.tgt_ops->remove_target(vha);
1663 vha->vha_tgt.qla_tgt = NULL;
1665 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d,
1666 "Release of tgt %p finished\n", tgt);
1671 /* ha->hardware_lock supposed to be held on entry */
1672 static int qlt_sched_sess_work(struct qla_tgt *tgt, int type,
1673 const void *param, unsigned int param_size)
1675 struct qla_tgt_sess_work_param *prm;
1676 unsigned long flags;
1678 prm = kzalloc(sizeof(*prm), GFP_ATOMIC);
1680 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050,
1681 "qla_target(%d): Unable to create session "
1682 "work, command will be refused", 0);
1686 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e,
1687 "Scheduling work (type %d, prm %p)"
1688 " to find session for param %p (size %d, tgt %p)\n",
1689 type, prm, param, param_size, tgt);
1692 memcpy(&prm->tm_iocb, param, param_size);
1694 spin_lock_irqsave(&tgt->sess_work_lock, flags);
1695 list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list);
1696 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
1698 schedule_work(&tgt->sess_work);
1704 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1706 static void qlt_send_notify_ack(struct qla_qpair *qpair,
1707 struct imm_ntfy_from_isp *ntfy,
1708 uint32_t add_flags, uint16_t resp_code, int resp_code_valid,
1709 uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan)
1711 struct scsi_qla_host *vha = qpair->vha;
1712 struct qla_hw_data *ha = vha->hw;
1714 struct nack_to_isp *nack;
1716 if (!ha->flags.fw_started)
1719 ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha);
1721 pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL);
1723 ql_dbg(ql_dbg_tgt, vha, 0xe049,
1724 "qla_target(%d): %s failed: unable to allocate "
1725 "request packet\n", vha->vp_idx, __func__);
1729 if (vha->vha_tgt.qla_tgt != NULL)
1730 vha->vha_tgt.qla_tgt->notify_ack_expected++;
1732 pkt->entry_type = NOTIFY_ACK_TYPE;
1733 pkt->entry_count = 1;
1735 nack = (struct nack_to_isp *)pkt;
1736 nack->ox_id = ntfy->ox_id;
1738 nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE;
1739 nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
1740 if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
1741 nack->u.isp24.flags = ntfy->u.isp24.flags &
1742 cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB);
1744 nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
1745 nack->u.isp24.status = ntfy->u.isp24.status;
1746 nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode;
1747 nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle;
1748 nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address;
1749 nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs;
1750 nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui;
1751 nack->u.isp24.srr_flags = cpu_to_le16(srr_flags);
1752 nack->u.isp24.srr_reject_code = srr_reject_code;
1753 nack->u.isp24.srr_reject_code_expl = srr_explan;
1754 nack->u.isp24.vp_index = ntfy->u.isp24.vp_index;
1756 /* TODO qualify this with EDIF enable */
1757 if (ntfy->u.isp24.status_subcode == ELS_PLOGI &&
1758 (le16_to_cpu(ntfy->u.isp24.flags) & NOTIFY24XX_FLAGS_FCSP)) {
1759 nack->u.isp24.flags |= cpu_to_le16(NOTIFY_ACK_FLAGS_FCSP);
1762 ql_dbg(ql_dbg_tgt, vha, 0xe005,
1763 "qla_target(%d): Sending 24xx Notify Ack %d\n",
1764 vha->vp_idx, nack->u.isp24.status);
1766 /* Memory Barrier */
1768 qla2x00_start_iocbs(vha, qpair->req);
1771 static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd)
1773 struct scsi_qla_host *vha = mcmd->vha;
1774 struct qla_hw_data *ha = vha->hw;
1775 struct abts_resp_to_24xx *resp;
1780 struct abts_recv_from_24xx *abts = &mcmd->orig_iocb.abts;
1781 struct qla_qpair *qpair = mcmd->qpair;
1783 ql_dbg(ql_dbg_tgt, vha, 0xe006,
1784 "Sending task mgmt ABTS response (ha=%p, status=%x)\n",
1785 ha, mcmd->fc_tm_rsp);
1787 rc = qlt_check_reserve_free_req(qpair, 1);
1789 ql_dbg(ql_dbg_tgt, vha, 0xe04a,
1790 "qla_target(%d): %s failed: unable to allocate request packet\n",
1791 vha->vp_idx, __func__);
1795 resp = (struct abts_resp_to_24xx *)qpair->req->ring_ptr;
1796 memset(resp, 0, sizeof(*resp));
1798 h = qlt_make_handle(qpair);
1799 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
1801 * CTIO type 7 from the firmware doesn't provide a way to
1802 * know the initiator's LOOP ID, hence we can't find
1803 * the session and, so, the command.
1807 qpair->req->outstanding_cmds[h] = (srb_t *)mcmd;
1810 resp->handle = make_handle(qpair->req->id, h);
1811 resp->entry_type = ABTS_RESP_24XX;
1812 resp->entry_count = 1;
1813 resp->nport_handle = abts->nport_handle;
1814 resp->vp_index = vha->vp_idx;
1815 resp->sof_type = abts->sof_type;
1816 resp->exchange_address = abts->exchange_address;
1817 resp->fcp_hdr_le = abts->fcp_hdr_le;
1818 f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
1819 F_CTL_LAST_SEQ | F_CTL_END_SEQ |
1820 F_CTL_SEQ_INITIATIVE);
1821 p = (uint8_t *)&f_ctl;
1822 resp->fcp_hdr_le.f_ctl[0] = *p++;
1823 resp->fcp_hdr_le.f_ctl[1] = *p++;
1824 resp->fcp_hdr_le.f_ctl[2] = *p;
1826 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
1827 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
1829 resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
1830 if (mcmd->fc_tm_rsp == FCP_TMF_CMPL) {
1831 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
1832 resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
1833 resp->payload.ba_acct.low_seq_cnt = 0x0000;
1834 resp->payload.ba_acct.high_seq_cnt = cpu_to_le16(0xFFFF);
1835 resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
1836 resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
1838 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT;
1839 resp->payload.ba_rjt.reason_code =
1840 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM;
1841 /* Other bytes are zero */
1844 vha->vha_tgt.qla_tgt->abts_resp_expected++;
1846 /* Memory Barrier */
1848 if (qpair->reqq_start_iocbs)
1849 qpair->reqq_start_iocbs(qpair);
1851 qla2x00_start_iocbs(vha, qpair->req);
1857 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1859 static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair,
1860 struct abts_recv_from_24xx *abts, uint32_t status,
1863 struct scsi_qla_host *vha = qpair->vha;
1864 struct qla_hw_data *ha = vha->hw;
1865 struct abts_resp_to_24xx *resp;
1869 ql_dbg(ql_dbg_tgt, vha, 0xe006,
1870 "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
1873 resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair,
1876 ql_dbg(ql_dbg_tgt, vha, 0xe04a,
1877 "qla_target(%d): %s failed: unable to allocate "
1878 "request packet", vha->vp_idx, __func__);
1882 resp->entry_type = ABTS_RESP_24XX;
1883 resp->handle = QLA_TGT_SKIP_HANDLE;
1884 resp->entry_count = 1;
1885 resp->nport_handle = abts->nport_handle;
1886 resp->vp_index = vha->vp_idx;
1887 resp->sof_type = abts->sof_type;
1888 resp->exchange_address = abts->exchange_address;
1889 resp->fcp_hdr_le = abts->fcp_hdr_le;
1890 f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
1891 F_CTL_LAST_SEQ | F_CTL_END_SEQ |
1892 F_CTL_SEQ_INITIATIVE);
1893 p = (uint8_t *)&f_ctl;
1894 resp->fcp_hdr_le.f_ctl[0] = *p++;
1895 resp->fcp_hdr_le.f_ctl[1] = *p++;
1896 resp->fcp_hdr_le.f_ctl[2] = *p;
1898 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.d_id;
1899 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.s_id;
1901 resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
1902 resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
1904 resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
1905 if (status == FCP_TMF_CMPL) {
1906 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
1907 resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
1908 resp->payload.ba_acct.low_seq_cnt = 0x0000;
1909 resp->payload.ba_acct.high_seq_cnt = cpu_to_le16(0xFFFF);
1910 resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
1911 resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
1913 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT;
1914 resp->payload.ba_rjt.reason_code =
1915 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM;
1916 /* Other bytes are zero */
1919 vha->vha_tgt.qla_tgt->abts_resp_expected++;
1921 /* Memory Barrier */
1923 if (qpair->reqq_start_iocbs)
1924 qpair->reqq_start_iocbs(qpair);
1926 qla2x00_start_iocbs(vha, qpair->req);
1930 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1932 static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha,
1933 struct qla_qpair *qpair, response_t *pkt, struct qla_tgt_mgmt_cmd *mcmd)
1935 struct ctio7_to_24xx *ctio;
1937 struct abts_recv_from_24xx *entry;
1939 ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, NULL);
1941 ql_dbg(ql_dbg_tgt, vha, 0xe04b,
1942 "qla_target(%d): %s failed: unable to allocate "
1943 "request packet\n", vha->vp_idx, __func__);
1948 /* abts from remote port */
1949 entry = &mcmd->orig_iocb.abts;
1951 /* abts from this driver. */
1952 entry = (struct abts_recv_from_24xx *)pkt;
1955 * We've got on entrance firmware's response on by us generated
1956 * ABTS response. So, in it ID fields are reversed.
1959 ctio->entry_type = CTIO_TYPE7;
1960 ctio->entry_count = 1;
1961 ctio->nport_handle = entry->nport_handle;
1962 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
1963 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
1964 ctio->vp_index = vha->vp_idx;
1965 ctio->exchange_addr = entry->exchange_addr_to_abort;
1966 tmp = (CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_TERMINATE);
1969 ctio->initiator_id = entry->fcp_hdr_le.s_id;
1971 if (mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID)
1972 tmp |= (mcmd->abort_io_attr << 9);
1973 else if (qpair->retry_term_cnt & 1)
1976 ctio->initiator_id = entry->fcp_hdr_le.d_id;
1978 if (qpair->retry_term_cnt & 1)
1981 ctio->u.status1.flags = cpu_to_le16(tmp);
1982 ctio->u.status1.ox_id = entry->fcp_hdr_le.ox_id;
1984 ql_dbg(ql_dbg_tgt, vha, 0xe007,
1985 "Sending retry TERM EXCH CTIO7 flags %04xh oxid %04xh attr valid %x\n",
1986 le16_to_cpu(ctio->u.status1.flags),
1987 le16_to_cpu(ctio->u.status1.ox_id),
1988 (mcmd && mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) ? 1 : 0);
1990 /* Memory Barrier */
1992 if (qpair->reqq_start_iocbs)
1993 qpair->reqq_start_iocbs(qpair);
1995 qla2x00_start_iocbs(vha, qpair->req);
1998 qlt_build_abts_resp_iocb(mcmd);
2000 qlt_24xx_send_abts_resp(qpair,
2001 (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true);
2005 /* drop cmds for the given lun
2006 * XXX only looks for cmds on the port through which lun reset was recieved
2007 * XXX does not go through the list of other port (which may have cmds
2010 static void abort_cmds_for_lun(struct scsi_qla_host *vha, u64 lun, be_id_t s_id)
2012 struct qla_tgt_sess_op *op;
2013 struct qla_tgt_cmd *cmd;
2015 unsigned long flags;
2017 key = sid_to_key(s_id);
2018 spin_lock_irqsave(&vha->cmd_list_lock, flags);
2019 list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) {
2023 op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
2024 op_lun = scsilun_to_int(
2025 (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun);
2026 if (op_key == key && op_lun == lun)
2030 list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
2034 op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
2035 op_lun = scsilun_to_int(
2036 (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun);
2037 if (op_key == key && op_lun == lun)
2041 list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
2045 cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id);
2046 cmd_lun = scsilun_to_int(
2047 (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun);
2048 if (cmd_key == key && cmd_lun == lun)
2051 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
2054 static struct qla_qpair_hint *qlt_find_qphint(struct scsi_qla_host *vha,
2055 uint64_t unpacked_lun)
2057 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
2058 struct qla_qpair_hint *h = NULL;
2060 if (vha->flags.qpairs_available) {
2061 h = btree_lookup64(&tgt->lun_qpair_map, unpacked_lun);
2063 h = &tgt->qphints[0];
2065 h = &tgt->qphints[0];
2071 static void qlt_do_tmr_work(struct work_struct *work)
2073 struct qla_tgt_mgmt_cmd *mcmd =
2074 container_of(work, struct qla_tgt_mgmt_cmd, work);
2075 struct qla_hw_data *ha = mcmd->vha->hw;
2078 unsigned long flags;
2080 switch (mcmd->tmr_func) {
2082 tag = le32_to_cpu(mcmd->orig_iocb.abts.exchange_addr_to_abort);
2089 rc = ha->tgt.tgt_ops->handle_tmr(mcmd, mcmd->unpacked_lun,
2090 mcmd->tmr_func, tag);
2093 spin_lock_irqsave(mcmd->qpair->qp_lock_ptr, flags);
2094 switch (mcmd->tmr_func) {
2096 mcmd->fc_tm_rsp = FCP_TMF_REJECTED;
2097 qlt_build_abts_resp_iocb(mcmd);
2099 case QLA_TGT_LUN_RESET:
2100 case QLA_TGT_CLEAR_TS:
2101 case QLA_TGT_ABORT_TS:
2102 case QLA_TGT_CLEAR_ACA:
2103 case QLA_TGT_TARGET_RESET:
2104 qlt_send_busy(mcmd->qpair, &mcmd->orig_iocb.atio,
2108 case QLA_TGT_ABORT_ALL:
2109 case QLA_TGT_NEXUS_LOSS_SESS:
2110 case QLA_TGT_NEXUS_LOSS:
2111 qlt_send_notify_ack(mcmd->qpair,
2112 &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0);
2115 spin_unlock_irqrestore(mcmd->qpair->qp_lock_ptr, flags);
2117 ql_dbg(ql_dbg_tgt_mgt, mcmd->vha, 0xf052,
2118 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
2119 mcmd->vha->vp_idx, rc);
2120 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
2124 /* ha->hardware_lock supposed to be held on entry */
2125 static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha,
2126 struct abts_recv_from_24xx *abts, struct fc_port *sess)
2128 struct qla_hw_data *ha = vha->hw;
2129 struct qla_tgt_mgmt_cmd *mcmd;
2130 struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0];
2131 struct qla_tgt_cmd *abort_cmd;
2133 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f,
2134 "qla_target(%d): task abort (tag=%d)\n",
2135 vha->vp_idx, abts->exchange_addr_to_abort);
2137 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
2139 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051,
2140 "qla_target(%d): %s: Allocation of ABORT cmd failed",
2141 vha->vp_idx, __func__);
2144 memset(mcmd, 0, sizeof(*mcmd));
2145 mcmd->cmd_type = TYPE_TGT_TMCMD;
2147 memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts));
2148 mcmd->reset_count = ha->base_qpair->chip_reset;
2149 mcmd->tmr_func = QLA_TGT_ABTS;
2150 mcmd->qpair = h->qpair;
2154 * LUN is looked up by target-core internally based on the passed
2155 * abts->exchange_addr_to_abort tag.
2157 mcmd->se_cmd.cpuid = h->cpuid;
2159 abort_cmd = ha->tgt.tgt_ops->find_cmd_by_tag(sess,
2160 le32_to_cpu(abts->exchange_addr_to_abort));
2163 mcmd->unpacked_lun = abort_cmd->se_cmd.orig_fe_lun;
2165 if (abort_cmd->qpair) {
2166 mcmd->qpair = abort_cmd->qpair;
2167 mcmd->se_cmd.cpuid = abort_cmd->se_cmd.cpuid;
2168 mcmd->abort_io_attr = abort_cmd->atio.u.isp24.attr;
2169 mcmd->flags = QLA24XX_MGMT_ABORT_IO_ATTR_VALID;
2172 INIT_WORK(&mcmd->work, qlt_do_tmr_work);
2173 queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, &mcmd->work);
2179 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2181 static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
2182 struct abts_recv_from_24xx *abts)
2184 struct qla_hw_data *ha = vha->hw;
2185 struct fc_port *sess;
2186 uint32_t tag = le32_to_cpu(abts->exchange_addr_to_abort);
2189 unsigned long flags;
2191 if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) {
2192 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053,
2193 "qla_target(%d): ABTS: Abort Sequence not "
2194 "supported\n", vha->vp_idx);
2195 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2200 if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) {
2201 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010,
2202 "qla_target(%d): ABTS: Unknown Exchange "
2203 "Address received\n", vha->vp_idx);
2204 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2209 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011,
2210 "qla_target(%d): task abort (s_id=%x:%x:%x, "
2211 "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id.domain,
2212 abts->fcp_hdr_le.s_id.area, abts->fcp_hdr_le.s_id.al_pa, tag,
2213 le32_to_cpu(abts->fcp_hdr_le.parameter));
2215 s_id = le_id_to_be(abts->fcp_hdr_le.s_id);
2217 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2218 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
2220 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012,
2221 "qla_target(%d): task abort for non-existent session\n",
2223 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2225 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2229 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2232 if (sess->deleted) {
2233 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2238 rc = __qlt_24xx_handle_abts(vha, abts, sess);
2240 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054,
2241 "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
2243 qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
2250 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2252 static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair,
2253 struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code)
2255 struct scsi_qla_host *ha = mcmd->vha;
2256 struct atio_from_isp *atio = &mcmd->orig_iocb.atio;
2257 struct ctio7_to_24xx *ctio;
2260 ql_dbg(ql_dbg_tgt, ha, 0xe008,
2261 "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
2262 ha, atio, resp_code);
2265 ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL);
2267 ql_dbg(ql_dbg_tgt, ha, 0xe04c,
2268 "qla_target(%d): %s failed: unable to allocate "
2269 "request packet\n", ha->vp_idx, __func__);
2273 ctio->entry_type = CTIO_TYPE7;
2274 ctio->entry_count = 1;
2275 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
2276 ctio->nport_handle = cpu_to_le16(mcmd->sess->loop_id);
2277 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2278 ctio->vp_index = ha->vp_idx;
2279 ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2280 ctio->exchange_addr = atio->u.isp24.exchange_addr;
2281 temp = (atio->u.isp24.attr << 9)|
2282 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
2283 ctio->u.status1.flags = cpu_to_le16(temp);
2284 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2285 ctio->u.status1.ox_id = cpu_to_le16(temp);
2286 ctio->u.status1.scsi_status =
2287 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID);
2288 ctio->u.status1.response_len = cpu_to_le16(8);
2289 ctio->u.status1.sense_data[0] = resp_code;
2291 /* Memory Barrier */
2293 if (qpair->reqq_start_iocbs)
2294 qpair->reqq_start_iocbs(qpair);
2296 qla2x00_start_iocbs(ha, qpair->req);
2299 void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd)
2301 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
2303 EXPORT_SYMBOL(qlt_free_mcmd);
2306 * ha->hardware_lock supposed to be held on entry. Might drop it, then
2309 void qlt_send_resp_ctio(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd,
2310 uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq)
2312 struct atio_from_isp *atio = &cmd->atio;
2313 struct ctio7_to_24xx *ctio;
2315 struct scsi_qla_host *vha = cmd->vha;
2317 ql_dbg(ql_dbg_tgt_dif, vha, 0x3066,
2318 "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, "
2319 "sense_key=%02x, asc=%02x, ascq=%02x",
2320 vha, atio, scsi_status, sense_key, asc, ascq);
2322 ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL);
2324 ql_dbg(ql_dbg_async, vha, 0x3067,
2325 "qla2x00t(%ld): %s failed: unable to allocate request packet",
2326 vha->host_no, __func__);
2330 ctio->entry_type = CTIO_TYPE7;
2331 ctio->entry_count = 1;
2332 ctio->handle = QLA_TGT_SKIP_HANDLE;
2333 ctio->nport_handle = cpu_to_le16(cmd->sess->loop_id);
2334 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2335 ctio->vp_index = vha->vp_idx;
2336 ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2337 ctio->exchange_addr = atio->u.isp24.exchange_addr;
2338 temp = (atio->u.isp24.attr << 9) |
2339 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
2340 ctio->u.status1.flags = cpu_to_le16(temp);
2341 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2342 ctio->u.status1.ox_id = cpu_to_le16(temp);
2343 ctio->u.status1.scsi_status =
2344 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status);
2345 ctio->u.status1.response_len = cpu_to_le16(18);
2346 ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio));
2348 if (ctio->u.status1.residual != 0)
2349 ctio->u.status1.scsi_status |=
2350 cpu_to_le16(SS_RESIDUAL_UNDER);
2352 /* Fixed format sense data. */
2353 ctio->u.status1.sense_data[0] = 0x70;
2354 ctio->u.status1.sense_data[2] = sense_key;
2355 /* Additional sense length */
2356 ctio->u.status1.sense_data[7] = 0xa;
2358 ctio->u.status1.sense_data[12] = asc;
2359 ctio->u.status1.sense_data[13] = ascq;
2361 /* Memory Barrier */
2364 if (qpair->reqq_start_iocbs)
2365 qpair->reqq_start_iocbs(qpair);
2367 qla2x00_start_iocbs(vha, qpair->req);
2373 /* callback from target fabric module code */
2374 void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd)
2376 struct scsi_qla_host *vha = mcmd->sess->vha;
2377 struct qla_hw_data *ha = vha->hw;
2378 unsigned long flags;
2379 struct qla_qpair *qpair = mcmd->qpair;
2380 bool free_mcmd = true;
2382 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013,
2383 "TM response mcmd (%p) status %#x state %#x",
2384 mcmd, mcmd->fc_tm_rsp, mcmd->flags);
2386 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
2388 if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) {
2390 * Either the port is not online or this request was from
2391 * previous life, just abort the processing.
2393 ql_dbg(ql_dbg_async, vha, 0xe100,
2394 "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n",
2395 vha->flags.online, qla2x00_reset_active(vha),
2396 mcmd->reset_count, qpair->chip_reset);
2397 ha->tgt.tgt_ops->free_mcmd(mcmd);
2398 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2402 if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) {
2403 switch (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode) {
2407 ql_dbg(ql_dbg_disc, vha, 0x2106,
2408 "TM response logo %8phC status %#x state %#x",
2409 mcmd->sess->port_name, mcmd->fc_tm_rsp,
2411 qlt_schedule_sess_for_deletion(mcmd->sess);
2414 qlt_send_notify_ack(vha->hw->base_qpair,
2415 &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0);
2419 if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) {
2420 qlt_build_abts_resp_iocb(mcmd);
2423 qlt_24xx_send_task_mgmt_ctio(qpair, mcmd,
2427 * Make the callback for ->free_mcmd() to queue_work() and invoke
2428 * target_put_sess_cmd() to drop cmd_kref to 1. The final
2429 * target_put_sess_cmd() call will be made from TFO->check_stop_free()
2430 * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd
2431 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
2432 * qlt_xmit_tm_rsp() returns here..
2435 ha->tgt.tgt_ops->free_mcmd(mcmd);
2437 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2439 EXPORT_SYMBOL(qlt_xmit_tm_rsp);
2442 static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm)
2444 struct qla_tgt_cmd *cmd = prm->cmd;
2446 BUG_ON(cmd->sg_cnt == 0);
2448 prm->sg = (struct scatterlist *)cmd->sg;
2449 prm->seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, cmd->sg,
2450 cmd->sg_cnt, cmd->dma_data_direction);
2451 if (unlikely(prm->seg_cnt == 0))
2454 prm->cmd->sg_mapped = 1;
2456 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) {
2458 * If greater than four sg entries then we need to allocate
2459 * the continuation entries
2461 if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX)
2462 prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt -
2463 QLA_TGT_DATASEGS_PER_CMD_24XX,
2464 QLA_TGT_DATASEGS_PER_CONT_24XX);
2467 if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) ||
2468 (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) {
2469 prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz);
2470 prm->tot_dsds = prm->seg_cnt;
2472 prm->tot_dsds = prm->seg_cnt;
2474 if (cmd->prot_sg_cnt) {
2475 prm->prot_sg = cmd->prot_sg;
2476 prm->prot_seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev,
2477 cmd->prot_sg, cmd->prot_sg_cnt,
2478 cmd->dma_data_direction);
2479 if (unlikely(prm->prot_seg_cnt == 0))
2482 if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) ||
2483 (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) {
2484 /* Dif Bundling not support here */
2485 prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen,
2487 prm->tot_dsds += prm->prot_seg_cnt;
2489 prm->tot_dsds += prm->prot_seg_cnt;
2496 ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d,
2497 "qla_target(%d): PCI mapping failed: sg_cnt=%d",
2498 0, prm->cmd->sg_cnt);
2502 static void qlt_unmap_sg(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd)
2504 struct qla_hw_data *ha;
2505 struct qla_qpair *qpair;
2507 if (!cmd->sg_mapped)
2512 dma_unmap_sg(&qpair->pdev->dev, cmd->sg, cmd->sg_cnt,
2513 cmd->dma_data_direction);
2516 if (cmd->prot_sg_cnt)
2517 dma_unmap_sg(&qpair->pdev->dev, cmd->prot_sg, cmd->prot_sg_cnt,
2518 cmd->dma_data_direction);
2523 if (cmd->ctx_dsd_alloced)
2524 qla2x00_clean_dsd_pool(ha, cmd->ctx);
2526 dma_pool_free(ha->dl_dma_pool, cmd->ctx, cmd->ctx->crc_ctx_dma);
2529 static int qlt_check_reserve_free_req(struct qla_qpair *qpair,
2533 struct req_que *req = qpair->req;
2535 if (req->cnt < (req_cnt + 2)) {
2536 cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr :
2537 rd_reg_dword_relaxed(req->req_q_out));
2539 if (req->ring_index < cnt)
2540 req->cnt = cnt - req->ring_index;
2542 req->cnt = req->length - (req->ring_index - cnt);
2544 if (unlikely(req->cnt < (req_cnt + 2)))
2548 req->cnt -= req_cnt;
2554 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2556 static inline void *qlt_get_req_pkt(struct req_que *req)
2558 /* Adjust ring index. */
2560 if (req->ring_index == req->length) {
2561 req->ring_index = 0;
2562 req->ring_ptr = req->ring;
2566 return (cont_entry_t *)req->ring_ptr;
2569 /* ha->hardware_lock supposed to be held on entry */
2570 static inline uint32_t qlt_make_handle(struct qla_qpair *qpair)
2575 struct req_que *req = qpair->req;
2577 h = req->current_outstanding_cmd;
2579 for (index = 1; index < req->num_outstanding_cmds; index++) {
2581 if (h == req->num_outstanding_cmds)
2584 if (h == QLA_TGT_SKIP_HANDLE)
2587 if (!req->outstanding_cmds[h]) {
2594 req->current_outstanding_cmd = h;
2596 ql_dbg(ql_dbg_io, qpair->vha, 0x305b,
2597 "qla_target(%d): Ran out of empty cmd slots\n",
2598 qpair->vha->vp_idx);
2599 h = QLA_TGT_NULL_HANDLE;
2605 /* ha->hardware_lock supposed to be held on entry */
2606 static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair,
2607 struct qla_tgt_prm *prm)
2610 struct ctio7_to_24xx *pkt;
2611 struct atio_from_isp *atio = &prm->cmd->atio;
2614 pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr;
2616 memset(pkt, 0, sizeof(*pkt));
2618 pkt->entry_type = CTIO_TYPE7;
2619 pkt->entry_count = (uint8_t)prm->req_cnt;
2620 pkt->vp_index = prm->cmd->vp_idx;
2622 h = qlt_make_handle(qpair);
2623 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
2625 * CTIO type 7 from the firmware doesn't provide a way to
2626 * know the initiator's LOOP ID, hence we can't find
2627 * the session and, so, the command.
2631 qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
2633 pkt->handle = make_handle(qpair->req->id, h);
2634 pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
2635 pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
2636 pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2637 pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
2638 pkt->exchange_addr = atio->u.isp24.exchange_addr;
2639 temp = atio->u.isp24.attr << 9;
2640 pkt->u.status0.flags |= cpu_to_le16(temp);
2641 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
2642 pkt->u.status0.ox_id = cpu_to_le16(temp);
2643 pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset);
2649 * ha->hardware_lock supposed to be held on entry. We have already made sure
2650 * that there is sufficient amount of request entries to not drop it.
2652 static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm)
2655 struct dsd64 *cur_dsd;
2657 /* Build continuation packets */
2658 while (prm->seg_cnt > 0) {
2659 cont_a64_entry_t *cont_pkt64 =
2660 (cont_a64_entry_t *)qlt_get_req_pkt(
2661 prm->cmd->qpair->req);
2664 * Make sure that from cont_pkt64 none of
2665 * 64-bit specific fields used for 32-bit
2666 * addressing. Cast to (cont_entry_t *) for
2670 memset(cont_pkt64, 0, sizeof(*cont_pkt64));
2672 cont_pkt64->entry_count = 1;
2673 cont_pkt64->sys_define = 0;
2675 cont_pkt64->entry_type = CONTINUE_A64_TYPE;
2676 cur_dsd = cont_pkt64->dsd;
2678 /* Load continuation entry data segments */
2680 cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt;
2681 cnt++, prm->seg_cnt--) {
2682 append_dsd64(&cur_dsd, prm->sg);
2683 prm->sg = sg_next(prm->sg);
2689 * ha->hardware_lock supposed to be held on entry. We have already made sure
2690 * that there is sufficient amount of request entries to not drop it.
2692 static void qlt_load_data_segments(struct qla_tgt_prm *prm)
2695 struct dsd64 *cur_dsd;
2696 struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt;
2698 pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen);
2700 /* Setup packet address segment pointer */
2701 cur_dsd = &pkt24->u.status0.dsd;
2703 /* Set total data segment count */
2705 pkt24->dseg_count = cpu_to_le16(prm->seg_cnt);
2707 if (prm->seg_cnt == 0) {
2708 /* No data transfer */
2709 cur_dsd->address = 0;
2710 cur_dsd->length = 0;
2714 /* If scatter gather */
2716 /* Load command entry data segments */
2718 (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt;
2719 cnt++, prm->seg_cnt--) {
2720 append_dsd64(&cur_dsd, prm->sg);
2721 prm->sg = sg_next(prm->sg);
2724 qlt_load_cont_data_segments(prm);
2727 static inline int qlt_has_data(struct qla_tgt_cmd *cmd)
2729 return cmd->bufflen > 0;
2732 static void qlt_print_dif_err(struct qla_tgt_prm *prm)
2734 struct qla_tgt_cmd *cmd;
2735 struct scsi_qla_host *vha;
2737 /* asc 0x10=dif error */
2738 if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) {
2742 switch (prm->sense_buffer[13]) {
2744 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b,
2745 "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2746 "se_cmd=%p tag[%x]",
2747 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2748 cmd->atio.u.isp24.exchange_addr);
2751 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c,
2752 "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2753 "se_cmd=%p tag[%x]",
2754 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2755 cmd->atio.u.isp24.exchange_addr);
2758 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f,
2759 "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2760 "se_cmd=%p tag[%x]",
2761 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2762 cmd->atio.u.isp24.exchange_addr);
2765 ql_dbg(ql_dbg_tgt_dif, vha, 0xe010,
2766 "BE detected Dif ERR: lba[%llx|%lld] len[%x] "
2767 "se_cmd=%p tag[%x]",
2768 cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
2769 cmd->atio.u.isp24.exchange_addr);
2772 ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16);
2777 * Called without ha->hardware_lock held
2779 static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd,
2780 struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status,
2781 uint32_t *full_req_cnt)
2783 struct se_cmd *se_cmd = &cmd->se_cmd;
2784 struct qla_qpair *qpair = cmd->qpair;
2787 prm->tgt = cmd->tgt;
2789 prm->rq_result = scsi_status;
2790 prm->sense_buffer = &cmd->sense_buffer[0];
2791 prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER;
2796 prm->add_status_pkt = 0;
2797 prm->prot_sg = NULL;
2798 prm->prot_seg_cnt = 0;
2801 if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) {
2802 if (qlt_pci_map_calc_cnt(prm) != 0)
2806 *full_req_cnt = prm->req_cnt;
2808 if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
2809 prm->residual = se_cmd->residual_count;
2810 ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c,
2811 "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2812 prm->residual, se_cmd->tag,
2813 se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0,
2814 cmd->bufflen, prm->rq_result);
2815 prm->rq_result |= SS_RESIDUAL_UNDER;
2816 } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) {
2817 prm->residual = se_cmd->residual_count;
2818 ql_dbg_qp(ql_dbg_io, qpair, 0x305d,
2819 "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2820 prm->residual, se_cmd->tag, se_cmd->t_task_cdb ?
2821 se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result);
2822 prm->rq_result |= SS_RESIDUAL_OVER;
2825 if (xmit_type & QLA_TGT_XMIT_STATUS) {
2827 * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be
2828 * ignored in *xmit_response() below
2830 if (qlt_has_data(cmd)) {
2831 if (QLA_TGT_SENSE_VALID(prm->sense_buffer) ||
2832 (IS_FWI2_CAPABLE(cmd->vha->hw) &&
2833 (prm->rq_result != 0))) {
2834 prm->add_status_pkt = 1;
2843 static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd,
2846 if (cmd->qpair->enable_class_2)
2850 return cmd->conf_compl_supported;
2852 return cmd->qpair->enable_explicit_conf &&
2853 cmd->conf_compl_supported;
2856 static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio,
2857 struct qla_tgt_prm *prm)
2859 prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len,
2860 (uint32_t)sizeof(ctio->u.status1.sense_data));
2861 ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS);
2862 if (qlt_need_explicit_conf(prm->cmd, 0)) {
2863 ctio->u.status0.flags |= cpu_to_le16(
2864 CTIO7_FLAGS_EXPLICIT_CONFORM |
2865 CTIO7_FLAGS_CONFORM_REQ);
2867 ctio->u.status0.residual = cpu_to_le32(prm->residual);
2868 ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result);
2869 if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) {
2872 if (qlt_need_explicit_conf(prm->cmd, 1)) {
2873 if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) {
2874 ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017,
2875 "Skipping EXPLICIT_CONFORM and "
2876 "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
2877 "non GOOD status\n");
2878 goto skip_explict_conf;
2880 ctio->u.status1.flags |= cpu_to_le16(
2881 CTIO7_FLAGS_EXPLICIT_CONFORM |
2882 CTIO7_FLAGS_CONFORM_REQ);
2885 ctio->u.status1.flags &=
2886 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
2887 ctio->u.status1.flags |=
2888 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
2889 ctio->u.status1.scsi_status |=
2890 cpu_to_le16(SS_SENSE_LEN_VALID);
2891 ctio->u.status1.sense_length =
2892 cpu_to_le16(prm->sense_buffer_len);
2893 for (i = 0; i < prm->sense_buffer_len/4; i++) {
2896 v = get_unaligned_be32(
2897 &((uint32_t *)prm->sense_buffer)[i]);
2898 put_unaligned_le32(v,
2899 &((uint32_t *)ctio->u.status1.sense_data)[i]);
2901 qlt_print_dif_err(prm);
2904 ctio->u.status1.flags &=
2905 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
2906 ctio->u.status1.flags |=
2907 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
2908 ctio->u.status1.sense_length = 0;
2909 memset(ctio->u.status1.sense_data, 0,
2910 sizeof(ctio->u.status1.sense_data));
2913 /* Sense with len > 24, is it possible ??? */
2917 qlt_hba_err_chk_enabled(struct se_cmd *se_cmd)
2919 switch (se_cmd->prot_op) {
2920 case TARGET_PROT_DOUT_INSERT:
2921 case TARGET_PROT_DIN_STRIP:
2922 if (ql2xenablehba_err_chk >= 1)
2925 case TARGET_PROT_DOUT_PASS:
2926 case TARGET_PROT_DIN_PASS:
2927 if (ql2xenablehba_err_chk >= 2)
2930 case TARGET_PROT_DIN_INSERT:
2931 case TARGET_PROT_DOUT_STRIP:
2940 qla_tgt_ref_mask_check(struct se_cmd *se_cmd)
2942 switch (se_cmd->prot_op) {
2943 case TARGET_PROT_DIN_INSERT:
2944 case TARGET_PROT_DOUT_INSERT:
2945 case TARGET_PROT_DIN_STRIP:
2946 case TARGET_PROT_DOUT_STRIP:
2947 case TARGET_PROT_DIN_PASS:
2948 case TARGET_PROT_DOUT_PASS:
2957 * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command
2960 qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx,
2961 uint16_t *pfw_prot_opts)
2963 struct se_cmd *se_cmd = &cmd->se_cmd;
2964 uint32_t lba = 0xffffffff & se_cmd->t_task_lba;
2965 scsi_qla_host_t *vha = cmd->tgt->vha;
2966 struct qla_hw_data *ha = vha->hw;
2970 * wait till Mode Sense/Select cmd, modepage Ah, subpage 2
2971 * have been immplemented by TCM, before AppTag is avail.
2972 * Look for modesense_handlers[]
2975 ctx->app_tag_mask[0] = 0x0;
2976 ctx->app_tag_mask[1] = 0x0;
2978 if (IS_PI_UNINIT_CAPABLE(ha)) {
2979 if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) ||
2980 (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT))
2981 *pfw_prot_opts |= PO_DIS_VALD_APP_ESC;
2982 else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT)
2983 *pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC;
2986 t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts);
2988 switch (se_cmd->prot_type) {
2989 case TARGET_DIF_TYPE0_PROT:
2991 * No check for ql2xenablehba_err_chk, as it
2992 * would be an I/O error if hba tag generation
2995 ctx->ref_tag = cpu_to_le32(lba);
2996 /* enable ALL bytes of the ref tag */
2997 ctx->ref_tag_mask[0] = 0xff;
2998 ctx->ref_tag_mask[1] = 0xff;
2999 ctx->ref_tag_mask[2] = 0xff;
3000 ctx->ref_tag_mask[3] = 0xff;
3002 case TARGET_DIF_TYPE1_PROT:
3004 * For TYPE 1 protection: 16 bit GUARD tag, 32 bit
3005 * REF tag, and 16 bit app tag.
3007 ctx->ref_tag = cpu_to_le32(lba);
3008 if (!qla_tgt_ref_mask_check(se_cmd) ||
3009 !(ha->tgt.tgt_ops->chk_dif_tags(t32))) {
3010 *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
3013 /* enable ALL bytes of the ref tag */
3014 ctx->ref_tag_mask[0] = 0xff;
3015 ctx->ref_tag_mask[1] = 0xff;
3016 ctx->ref_tag_mask[2] = 0xff;
3017 ctx->ref_tag_mask[3] = 0xff;
3019 case TARGET_DIF_TYPE2_PROT:
3021 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF
3022 * tag has to match LBA in CDB + N
3024 ctx->ref_tag = cpu_to_le32(lba);
3025 if (!qla_tgt_ref_mask_check(se_cmd) ||
3026 !(ha->tgt.tgt_ops->chk_dif_tags(t32))) {
3027 *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
3030 /* enable ALL bytes of the ref tag */
3031 ctx->ref_tag_mask[0] = 0xff;
3032 ctx->ref_tag_mask[1] = 0xff;
3033 ctx->ref_tag_mask[2] = 0xff;
3034 ctx->ref_tag_mask[3] = 0xff;
3036 case TARGET_DIF_TYPE3_PROT:
3037 /* For TYPE 3 protection: 16 bit GUARD only */
3038 *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
3039 ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] =
3040 ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00;
3046 qlt_build_ctio_crc2_pkt(struct qla_qpair *qpair, struct qla_tgt_prm *prm)
3048 struct dsd64 *cur_dsd;
3049 uint32_t transfer_length = 0;
3050 uint32_t data_bytes;
3052 uint8_t bundling = 1;
3053 struct crc_context *crc_ctx_pkt = NULL;
3054 struct qla_hw_data *ha;
3055 struct ctio_crc2_to_fw *pkt;
3056 dma_addr_t crc_ctx_dma;
3057 uint16_t fw_prot_opts = 0;
3058 struct qla_tgt_cmd *cmd = prm->cmd;
3059 struct se_cmd *se_cmd = &cmd->se_cmd;
3061 struct atio_from_isp *atio = &prm->cmd->atio;
3062 struct qla_tc_param tc;
3064 scsi_qla_host_t *vha = cmd->vha;
3068 pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr;
3070 memset(pkt, 0, sizeof(*pkt));
3072 ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071,
3073 "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n",
3074 cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op,
3075 prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba);
3077 if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) ||
3078 (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP))
3081 /* Compute dif len and adjust data len to incude protection */
3082 data_bytes = cmd->bufflen;
3083 dif_bytes = (data_bytes / cmd->blk_sz) * 8;
3085 switch (se_cmd->prot_op) {
3086 case TARGET_PROT_DIN_INSERT:
3087 case TARGET_PROT_DOUT_STRIP:
3088 transfer_length = data_bytes;
3089 if (cmd->prot_sg_cnt)
3090 data_bytes += dif_bytes;
3092 case TARGET_PROT_DIN_STRIP:
3093 case TARGET_PROT_DOUT_INSERT:
3094 case TARGET_PROT_DIN_PASS:
3095 case TARGET_PROT_DOUT_PASS:
3096 transfer_length = data_bytes + dif_bytes;
3103 if (!qlt_hba_err_chk_enabled(se_cmd))
3104 fw_prot_opts |= 0x10; /* Disable Guard tag checking */
3105 /* HBA error checking enabled */
3106 else if (IS_PI_UNINIT_CAPABLE(ha)) {
3107 if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) ||
3108 (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT))
3109 fw_prot_opts |= PO_DIS_VALD_APP_ESC;
3110 else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT)
3111 fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC;
3114 switch (se_cmd->prot_op) {
3115 case TARGET_PROT_DIN_INSERT:
3116 case TARGET_PROT_DOUT_INSERT:
3117 fw_prot_opts |= PO_MODE_DIF_INSERT;
3119 case TARGET_PROT_DIN_STRIP:
3120 case TARGET_PROT_DOUT_STRIP:
3121 fw_prot_opts |= PO_MODE_DIF_REMOVE;
3123 case TARGET_PROT_DIN_PASS:
3124 case TARGET_PROT_DOUT_PASS:
3125 fw_prot_opts |= PO_MODE_DIF_PASS;
3126 /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */
3128 default:/* Normal Request */
3129 fw_prot_opts |= PO_MODE_DIF_PASS;
3134 /* Update entry type to indicate Command Type CRC_2 IOCB */
3135 pkt->entry_type = CTIO_CRC2;
3136 pkt->entry_count = 1;
3137 pkt->vp_index = cmd->vp_idx;
3139 h = qlt_make_handle(qpair);
3140 if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
3142 * CTIO type 7 from the firmware doesn't provide a way to
3143 * know the initiator's LOOP ID, hence we can't find
3144 * the session and, so, the command.
3148 qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
3150 pkt->handle = make_handle(qpair->req->id, h);
3151 pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
3152 pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
3153 pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
3154 pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
3155 pkt->exchange_addr = atio->u.isp24.exchange_addr;
3157 /* silence compile warning */
3158 t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
3159 pkt->ox_id = cpu_to_le16(t16);
3161 t16 = (atio->u.isp24.attr << 9);
3162 pkt->flags |= cpu_to_le16(t16);
3163 pkt->relative_offset = cpu_to_le32(prm->cmd->offset);
3165 /* Set transfer direction */
3166 if (cmd->dma_data_direction == DMA_TO_DEVICE)
3167 pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN);
3168 else if (cmd->dma_data_direction == DMA_FROM_DEVICE)
3169 pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT);
3171 pkt->dseg_count = cpu_to_le16(prm->tot_dsds);
3172 /* Fibre channel byte count */
3173 pkt->transfer_length = cpu_to_le32(transfer_length);
3175 /* ----- CRC context -------- */
3177 /* Allocate CRC context from global pool */
3178 crc_ctx_pkt = cmd->ctx =
3179 dma_pool_zalloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma);
3182 goto crc_queuing_error;
3184 crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma;
3185 INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list);
3188 crc_ctx_pkt->handle = pkt->handle;
3190 qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts);
3192 put_unaligned_le64(crc_ctx_dma, &pkt->crc_context_address);
3193 pkt->crc_context_len = cpu_to_le16(CRC_CONTEXT_LEN_FW);
3196 cur_dsd = &crc_ctx_pkt->u.nobundling.data_dsd[0];
3199 * Configure Bundling if we need to fetch interlaving
3200 * protection PCI accesses
3202 fw_prot_opts |= PO_ENABLE_DIF_BUNDLING;
3203 crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes);
3204 crc_ctx_pkt->u.bundling.dseg_count =
3205 cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt);
3206 cur_dsd = &crc_ctx_pkt->u.bundling.data_dsd[0];
3209 /* Finish the common fields of CRC pkt */
3210 crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz);
3211 crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts);
3212 crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes);
3213 crc_ctx_pkt->guard_seed = cpu_to_le16(0);
3215 memset((uint8_t *)&tc, 0 , sizeof(tc));
3217 tc.blk_sz = cmd->blk_sz;
3218 tc.bufflen = cmd->bufflen;
3220 tc.prot_sg = cmd->prot_sg;
3221 tc.ctx = crc_ctx_pkt;
3222 tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced;
3224 /* Walks data segments */
3225 pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR);
3227 if (!bundling && prm->prot_seg_cnt) {
3228 if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd,
3229 prm->tot_dsds, &tc))
3230 goto crc_queuing_error;
3231 } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd,
3232 (prm->tot_dsds - prm->prot_seg_cnt), &tc))
3233 goto crc_queuing_error;
3235 if (bundling && prm->prot_seg_cnt) {
3236 /* Walks dif segments */
3237 pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA;
3239 cur_dsd = &crc_ctx_pkt->u.bundling.dif_dsd;
3240 if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd,
3241 prm->prot_seg_cnt, cmd))
3242 goto crc_queuing_error;
3247 /* Cleanup will be performed by the caller */
3248 qpair->req->outstanding_cmds[h] = NULL;
3250 return QLA_FUNCTION_FAILED;
3254 * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and *
3255 * QLA_TGT_XMIT_STATUS for >= 24xx silicon
3257 int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type,
3258 uint8_t scsi_status)
3260 struct scsi_qla_host *vha = cmd->vha;
3261 struct qla_qpair *qpair = cmd->qpair;
3262 struct ctio7_to_24xx *pkt;
3263 struct qla_tgt_prm prm;
3264 uint32_t full_req_cnt = 0;
3265 unsigned long flags = 0;
3268 if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) ||
3269 (cmd->sess && cmd->sess->deleted)) {
3270 cmd->state = QLA_TGT_STATE_PROCESSED;
3274 ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018,
3275 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p] qp %d\n",
3276 (xmit_type & QLA_TGT_XMIT_STATUS) ?
3277 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction,
3278 &cmd->se_cmd, qpair->id);
3280 res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status,
3282 if (unlikely(res != 0)) {
3286 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3288 if (xmit_type == QLA_TGT_XMIT_STATUS)
3289 qpair->tgt_counters.core_qla_snd_status++;
3291 qpair->tgt_counters.core_qla_que_buf++;
3293 if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) {
3295 * Either the port is not online or this request was from
3296 * previous life, just abort the processing.
3298 cmd->state = QLA_TGT_STATE_PROCESSED;
3299 ql_dbg_qp(ql_dbg_async, qpair, 0xe101,
3300 "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n",
3301 vha->flags.online, qla2x00_reset_active(vha),
3302 cmd->reset_count, qpair->chip_reset);
3303 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3307 /* Does F/W have an IOCBs for this request */
3308 res = qlt_check_reserve_free_req(qpair, full_req_cnt);
3310 goto out_unmap_unlock;
3312 if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA))
3313 res = qlt_build_ctio_crc2_pkt(qpair, &prm);
3315 res = qlt_24xx_build_ctio_pkt(qpair, &prm);
3316 if (unlikely(res != 0)) {
3317 qpair->req->cnt += full_req_cnt;
3318 goto out_unmap_unlock;
3321 pkt = (struct ctio7_to_24xx *)prm.pkt;
3323 if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) {
3324 pkt->u.status0.flags |=
3325 cpu_to_le16(CTIO7_FLAGS_DATA_IN |
3326 CTIO7_FLAGS_STATUS_MODE_0);
3328 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
3329 qlt_load_data_segments(&prm);
3331 if (prm.add_status_pkt == 0) {
3332 if (xmit_type & QLA_TGT_XMIT_STATUS) {
3333 pkt->u.status0.scsi_status =
3334 cpu_to_le16(prm.rq_result);
3335 pkt->u.status0.residual =
3336 cpu_to_le32(prm.residual);
3337 pkt->u.status0.flags |= cpu_to_le16(
3338 CTIO7_FLAGS_SEND_STATUS);
3339 if (qlt_need_explicit_conf(cmd, 0)) {
3340 pkt->u.status0.flags |=
3342 CTIO7_FLAGS_EXPLICIT_CONFORM |
3343 CTIO7_FLAGS_CONFORM_REQ);
3349 * We have already made sure that there is sufficient
3350 * amount of request entries to not drop HW lock in
3353 struct ctio7_to_24xx *ctio =
3354 (struct ctio7_to_24xx *)qlt_get_req_pkt(
3357 ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e,
3358 "Building additional status packet 0x%p.\n",
3362 * T10Dif: ctio_crc2_to_fw overlay ontop of
3365 memcpy(ctio, pkt, sizeof(*ctio));
3366 /* reset back to CTIO7 */
3367 ctio->entry_count = 1;
3368 ctio->entry_type = CTIO_TYPE7;
3369 ctio->dseg_count = 0;
3370 ctio->u.status1.flags &= ~cpu_to_le16(
3371 CTIO7_FLAGS_DATA_IN);
3373 /* Real finish is ctio_m1's finish */
3374 pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK;
3375 pkt->u.status0.flags |= cpu_to_le16(
3376 CTIO7_FLAGS_DONT_RET_CTIO);
3378 /* qlt_24xx_init_ctio_to_isp will correct
3379 * all neccessary fields that's part of CTIO7.
3380 * There should be no residual of CTIO-CRC2 data.
3382 qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio,
3386 qlt_24xx_init_ctio_to_isp(pkt, &prm);
3389 cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */
3390 cmd->cmd_sent_to_fw = 1;
3391 cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
3393 /* Memory Barrier */
3395 if (qpair->reqq_start_iocbs)
3396 qpair->reqq_start_iocbs(qpair);
3398 qla2x00_start_iocbs(vha, qpair->req);
3399 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3404 qlt_unmap_sg(vha, cmd);
3405 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3409 EXPORT_SYMBOL(qlt_xmit_response);
3411 int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd)
3413 struct ctio7_to_24xx *pkt;
3414 struct scsi_qla_host *vha = cmd->vha;
3415 struct qla_tgt *tgt = cmd->tgt;
3416 struct qla_tgt_prm prm;
3417 unsigned long flags = 0;
3419 struct qla_qpair *qpair = cmd->qpair;
3421 memset(&prm, 0, sizeof(prm));
3427 /* Calculate number of entries and segments required */
3428 if (qlt_pci_map_calc_cnt(&prm) != 0)
3431 if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) ||
3432 (cmd->sess && cmd->sess->deleted)) {
3434 * Either the port is not online or this request was from
3435 * previous life, just abort the processing.
3438 cmd->write_data_transferred = 0;
3439 cmd->state = QLA_TGT_STATE_DATA_IN;
3440 vha->hw->tgt.tgt_ops->handle_data(cmd);
3441 ql_dbg_qp(ql_dbg_async, qpair, 0xe102,
3442 "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n",
3443 vha->flags.online, qla2x00_reset_active(vha),
3444 cmd->reset_count, qpair->chip_reset);
3448 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3449 /* Does F/W have an IOCBs for this request */
3450 res = qlt_check_reserve_free_req(qpair, prm.req_cnt);
3452 goto out_unlock_free_unmap;
3453 if (cmd->se_cmd.prot_op)
3454 res = qlt_build_ctio_crc2_pkt(qpair, &prm);
3456 res = qlt_24xx_build_ctio_pkt(qpair, &prm);
3458 if (unlikely(res != 0)) {
3459 qpair->req->cnt += prm.req_cnt;
3460 goto out_unlock_free_unmap;
3463 pkt = (struct ctio7_to_24xx *)prm.pkt;
3464 pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT |
3465 CTIO7_FLAGS_STATUS_MODE_0);
3467 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
3468 qlt_load_data_segments(&prm);
3470 cmd->state = QLA_TGT_STATE_NEED_DATA;
3471 cmd->cmd_sent_to_fw = 1;
3472 cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
3474 /* Memory Barrier */
3476 if (qpair->reqq_start_iocbs)
3477 qpair->reqq_start_iocbs(qpair);
3479 qla2x00_start_iocbs(vha, qpair->req);
3480 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3484 out_unlock_free_unmap:
3485 qlt_unmap_sg(vha, cmd);
3486 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3490 EXPORT_SYMBOL(qlt_rdy_to_xfer);
3494 * it is assumed either hardware_lock or qpair lock is held.
3497 qlt_handle_dif_error(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd,
3498 struct ctio_crc_from_fw *sts)
3500 uint8_t *ap = &sts->actual_dif[0];
3501 uint8_t *ep = &sts->expected_dif[0];
3502 uint64_t lba = cmd->se_cmd.t_task_lba;
3503 uint8_t scsi_status, sense_key, asc, ascq;
3504 unsigned long flags;
3505 struct scsi_qla_host *vha = cmd->vha;
3507 cmd->trc_flags |= TRC_DIF_ERR;
3509 cmd->a_guard = get_unaligned_be16(ap + 0);
3510 cmd->a_app_tag = get_unaligned_be16(ap + 2);
3511 cmd->a_ref_tag = get_unaligned_be32(ap + 4);
3513 cmd->e_guard = get_unaligned_be16(ep + 0);
3514 cmd->e_app_tag = get_unaligned_be16(ep + 2);
3515 cmd->e_ref_tag = get_unaligned_be32(ep + 4);
3517 ql_dbg(ql_dbg_tgt_dif, vha, 0xf075,
3518 "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state);
3520 scsi_status = sense_key = asc = ascq = 0;
3522 /* check appl tag */
3523 if (cmd->e_app_tag != cmd->a_app_tag) {
3524 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d,
3525 "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]",
3526 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3527 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3528 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3529 cmd->atio.u.isp24.fcp_hdr.ox_id);
3531 cmd->dif_err_code = DIF_ERR_APP;
3532 scsi_status = SAM_STAT_CHECK_CONDITION;
3533 sense_key = ABORTED_COMMAND;
3539 if (cmd->e_ref_tag != cmd->a_ref_tag) {
3540 ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e,
3541 "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] ",
3542 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3543 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3544 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3545 cmd->atio.u.isp24.fcp_hdr.ox_id);
3547 cmd->dif_err_code = DIF_ERR_REF;
3548 scsi_status = SAM_STAT_CHECK_CONDITION;
3549 sense_key = ABORTED_COMMAND;
3556 if (cmd->e_guard != cmd->a_guard) {
3557 ql_dbg(ql_dbg_tgt_dif, vha, 0xe012,
3558 "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]",
3559 cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
3560 cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
3561 cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
3562 cmd->atio.u.isp24.fcp_hdr.ox_id);
3564 cmd->dif_err_code = DIF_ERR_GRD;
3565 scsi_status = SAM_STAT_CHECK_CONDITION;
3566 sense_key = ABORTED_COMMAND;
3571 switch (cmd->state) {
3572 case QLA_TGT_STATE_NEED_DATA:
3573 /* handle_data will load DIF error code */
3574 cmd->state = QLA_TGT_STATE_DATA_IN;
3575 vha->hw->tgt.tgt_ops->handle_data(cmd);
3578 spin_lock_irqsave(&cmd->cmd_lock, flags);
3580 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3581 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3584 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3586 qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc,
3588 /* assume scsi status gets out on the wire.
3589 * Will not wait for completion.
3591 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3596 /* If hardware_lock held on entry, might drop it, then reaquire */
3597 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
3598 static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha,
3599 struct imm_ntfy_from_isp *ntfy)
3601 struct nack_to_isp *nack;
3602 struct qla_hw_data *ha = vha->hw;
3606 ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c,
3607 "Sending TERM ELS CTIO (ha=%p)\n", ha);
3609 pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL);
3611 ql_dbg(ql_dbg_tgt, vha, 0xe080,
3612 "qla_target(%d): %s failed: unable to allocate "
3613 "request packet\n", vha->vp_idx, __func__);
3617 pkt->entry_type = NOTIFY_ACK_TYPE;
3618 pkt->entry_count = 1;
3619 pkt->handle = QLA_TGT_SKIP_HANDLE;
3621 nack = (struct nack_to_isp *)pkt;
3622 nack->ox_id = ntfy->ox_id;
3624 nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
3625 if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
3626 nack->u.isp24.flags = ntfy->u.isp24.flags &
3627 cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB);
3631 nack->u.isp24.flags |=
3632 __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE);
3634 nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
3635 nack->u.isp24.status = ntfy->u.isp24.status;
3636 nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode;
3637 nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle;
3638 nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address;
3639 nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs;
3640 nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui;
3641 nack->u.isp24.vp_index = ntfy->u.isp24.vp_index;
3643 qla2x00_start_iocbs(vha, vha->req);
3647 static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
3648 struct imm_ntfy_from_isp *imm, int ha_locked)
3652 WARN_ON_ONCE(!ha_locked);
3653 rc = __qlt_send_term_imm_notif(vha, imm);
3654 pr_debug("rc = %d\n", rc);
3658 * If hardware_lock held on entry, might drop it, then reaquire
3659 * This function sends the appropriate CTIO to ISP 2xxx or 24xx
3661 static int __qlt_send_term_exchange(struct qla_qpair *qpair,
3662 struct qla_tgt_cmd *cmd,
3663 struct atio_from_isp *atio)
3665 struct scsi_qla_host *vha = qpair->vha;
3666 struct ctio7_to_24xx *ctio24;
3667 struct qla_hw_data *ha = vha->hw;
3672 ql_dbg(ql_dbg_tgt, vha, 0xe009, "Sending TERM EXCH CTIO (ha=%p)\n", ha);
3677 pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL);
3679 ql_dbg(ql_dbg_tgt, vha, 0xe050,
3680 "qla_target(%d): %s failed: unable to allocate "
3681 "request packet\n", vha->vp_idx, __func__);
3686 if (cmd->state < QLA_TGT_STATE_PROCESSED) {
3687 ql_dbg(ql_dbg_tgt, vha, 0xe051,
3688 "qla_target(%d): Terminating cmd %p with "
3689 "incorrect state %d\n", vha->vp_idx, cmd,
3695 qpair->tgt_counters.num_term_xchg_sent++;
3696 pkt->entry_count = 1;
3697 pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
3699 ctio24 = (struct ctio7_to_24xx *)pkt;
3700 ctio24->entry_type = CTIO_TYPE7;
3701 ctio24->nport_handle = cpu_to_le16(CTIO7_NHANDLE_UNRECOGNIZED);
3702 ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
3703 ctio24->vp_index = vha->vp_idx;
3704 ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
3705 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
3706 temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 |
3707 CTIO7_FLAGS_TERMINATE;
3708 ctio24->u.status1.flags = cpu_to_le16(temp);
3709 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
3710 ctio24->u.status1.ox_id = cpu_to_le16(temp);
3712 /* Memory Barrier */
3714 if (qpair->reqq_start_iocbs)
3715 qpair->reqq_start_iocbs(qpair);
3717 qla2x00_start_iocbs(vha, qpair->req);
3721 static void qlt_send_term_exchange(struct qla_qpair *qpair,
3722 struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked,
3725 struct scsi_qla_host *vha;
3726 unsigned long flags = 0;
3729 /* why use different vha? NPIV */
3736 rc = __qlt_send_term_exchange(qpair, cmd, atio);
3738 qlt_alloc_qfull_cmd(vha, atio, 0, 0);
3741 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
3742 rc = __qlt_send_term_exchange(qpair, cmd, atio);
3744 qlt_alloc_qfull_cmd(vha, atio, 0, 0);
3747 if (cmd && !ul_abort && !cmd->aborted) {
3749 qlt_unmap_sg(vha, cmd);
3750 vha->hw->tgt.tgt_ops->free_cmd(cmd);
3754 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
3759 static void qlt_init_term_exchange(struct scsi_qla_host *vha)
3761 struct list_head free_list;
3762 struct qla_tgt_cmd *cmd, *tcmd;
3764 vha->hw->tgt.leak_exchg_thresh_hold =
3765 (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT;
3768 if (!list_empty(&vha->hw->tgt.q_full_list)) {
3769 INIT_LIST_HEAD(&free_list);
3770 list_splice_init(&vha->hw->tgt.q_full_list, &free_list);
3772 list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) {
3773 list_del(&cmd->cmd_list);
3774 /* This cmd was never sent to TCM. There is no need
3775 * to schedule free or call free_cmd
3778 vha->hw->tgt.num_qfull_cmds_alloc--;
3781 vha->hw->tgt.num_qfull_cmds_dropped = 0;
3784 static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha)
3786 uint32_t total_leaked;
3788 total_leaked = vha->hw->tgt.num_qfull_cmds_dropped;
3790 if (vha->hw->tgt.leak_exchg_thresh_hold &&
3791 (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) {
3793 ql_dbg(ql_dbg_tgt, vha, 0xe079,
3794 "Chip reset due to exchange starvation: %d/%d.\n",
3795 total_leaked, vha->hw->cur_fw_xcb_count);
3797 if (IS_P3P_TYPE(vha->hw))
3798 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
3800 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3801 qla2xxx_wake_dpc(vha);
3806 int qlt_abort_cmd(struct qla_tgt_cmd *cmd)
3808 struct qla_tgt *tgt = cmd->tgt;
3809 struct scsi_qla_host *vha = tgt->vha;
3810 struct se_cmd *se_cmd = &cmd->se_cmd;
3811 unsigned long flags;
3813 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014,
3814 "qla_target(%d): terminating exchange for aborted cmd=%p "
3815 "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd,
3818 spin_lock_irqsave(&cmd->cmd_lock, flags);
3820 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3822 * It's normal to see 2 calls in this path:
3823 * 1) XFER Rdy completion + CMD_T_ABORT
3824 * 2) TCM TMR - drain_state_list
3826 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016,
3827 "multiple abort. %p transport_state %x, t_state %x, "
3828 "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state,
3829 cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags);
3833 cmd->trc_flags |= TRC_ABORT;
3834 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
3836 qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1);
3839 EXPORT_SYMBOL(qlt_abort_cmd);
3841 void qlt_free_cmd(struct qla_tgt_cmd *cmd)
3843 struct fc_port *sess = cmd->sess;
3845 ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074,
3846 "%s: se_cmd[%p] ox_id %04x\n",
3847 __func__, &cmd->se_cmd,
3848 be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
3850 BUG_ON(cmd->cmd_in_wq);
3853 qlt_unmap_sg(cmd->vha, cmd);
3856 qlt_decr_num_pend_cmds(cmd->vha);
3858 BUG_ON(cmd->sg_mapped);
3859 cmd->jiffies_at_free = get_jiffies_64();
3860 if (unlikely(cmd->free_sg))
3863 if (!sess || !sess->se_sess) {
3867 cmd->jiffies_at_free = get_jiffies_64();
3868 cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd);
3870 EXPORT_SYMBOL(qlt_free_cmd);
3873 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3875 static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio,
3876 struct qla_tgt_cmd *cmd, uint32_t status)
3879 struct scsi_qla_host *vha = qpair->vha;
3881 if (cmd->se_cmd.prot_op)
3882 ql_dbg(ql_dbg_tgt_dif, vha, 0xe013,
3883 "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] "
3884 "se_cmd=%p tag[%x] op %#x/%s",
3886 cmd->num_blks, &cmd->se_cmd,
3887 cmd->atio.u.isp24.exchange_addr,
3888 cmd->se_cmd.prot_op,
3889 prot_op_str(cmd->se_cmd.prot_op));
3892 struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio;
3895 cpu_to_le16(OF_TERM_EXCH));
3900 qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1, 0);
3906 /* ha->hardware_lock supposed to be held on entry */
3907 static void *qlt_ctio_to_cmd(struct scsi_qla_host *vha,
3908 struct rsp_que *rsp, uint32_t handle, void *ctio)
3911 struct req_que *req;
3912 int qid = GET_QID(handle);
3913 uint32_t h = handle & ~QLA_TGT_HANDLE_MASK;
3915 if (unlikely(h == QLA_TGT_SKIP_HANDLE))
3918 if (qid == rsp->req->id) {
3920 } else if (vha->hw->req_q_map[qid]) {
3921 ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a,
3922 "qla_target(%d): CTIO completion with different QID %d handle %x\n",
3923 vha->vp_idx, rsp->id, handle);
3924 req = vha->hw->req_q_map[qid];
3929 h &= QLA_CMD_HANDLE_MASK;
3931 if (h != QLA_TGT_NULL_HANDLE) {
3932 if (unlikely(h >= req->num_outstanding_cmds)) {
3933 ql_dbg(ql_dbg_tgt, vha, 0xe052,
3934 "qla_target(%d): Wrong handle %x received\n",
3935 vha->vp_idx, handle);
3939 cmd = req->outstanding_cmds[h];
3940 if (unlikely(cmd == NULL)) {
3941 ql_dbg(ql_dbg_async, vha, 0xe053,
3942 "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n",
3943 vha->vp_idx, handle, req->id, rsp->id);
3946 req->outstanding_cmds[h] = NULL;
3947 } else if (ctio != NULL) {
3948 /* We can't get loop ID from CTIO7 */
3949 ql_dbg(ql_dbg_tgt, vha, 0xe054,
3950 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
3951 "support NULL handles\n", vha->vp_idx);
3959 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3961 static void qlt_do_ctio_completion(struct scsi_qla_host *vha,
3962 struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio)
3964 struct qla_hw_data *ha = vha->hw;
3965 struct se_cmd *se_cmd;
3966 struct qla_tgt_cmd *cmd;
3967 struct qla_qpair *qpair = rsp->qpair;
3969 if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) {
3970 /* That could happen only in case of an error/reset/abort */
3971 if (status != CTIO_SUCCESS) {
3972 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d,
3973 "Intermediate CTIO received"
3974 " (status %x)\n", status);
3979 cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio);
3983 se_cmd = &cmd->se_cmd;
3984 cmd->cmd_sent_to_fw = 0;
3986 qlt_unmap_sg(vha, cmd);
3988 if (unlikely(status != CTIO_SUCCESS)) {
3989 switch (status & 0xFFFF) {
3990 case CTIO_INVALID_RX_ID:
3991 if (printk_ratelimit())
3992 dev_info(&vha->hw->pdev->dev,
3993 "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n",
3994 vha->vp_idx, cmd->atio.u.isp24.attr,
3995 ((cmd->ctio_flags >> 9) & 0xf),
3999 case CTIO_LIP_RESET:
4000 case CTIO_TARGET_RESET:
4002 /* driver request abort via Terminate exchange */
4005 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058,
4006 "qla_target(%d): CTIO with "
4007 "status %#x received, state %x, se_cmd %p, "
4008 "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
4009 "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx,
4010 status, cmd->state, se_cmd);
4013 case CTIO_PORT_LOGGED_OUT:
4014 case CTIO_PORT_UNAVAILABLE:
4017 (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT;
4019 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059,
4020 "qla_target(%d): CTIO with %s status %x "
4021 "received (state %x, se_cmd %p)\n", vha->vp_idx,
4022 logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE",
4023 status, cmd->state, se_cmd);
4025 if (logged_out && cmd->sess) {
4027 * Session is already logged out, but we need
4028 * to notify initiator, who's not aware of this
4030 cmd->sess->send_els_logo = 1;
4031 ql_dbg(ql_dbg_disc, vha, 0x20f8,
4032 "%s %d %8phC post del sess\n",
4033 __func__, __LINE__, cmd->sess->port_name);
4035 qlt_schedule_sess_for_deletion(cmd->sess);
4039 case CTIO_DIF_ERROR: {
4040 struct ctio_crc_from_fw *crc =
4041 (struct ctio_crc_from_fw *)ctio;
4042 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073,
4043 "qla_target(%d): CTIO with DIF_ERROR status %x "
4044 "received (state %x, ulp_cmd %p) actual_dif[0x%llx] "
4045 "expect_dif[0x%llx]\n",
4046 vha->vp_idx, status, cmd->state, se_cmd,
4047 *((u64 *)&crc->actual_dif[0]),
4048 *((u64 *)&crc->expected_dif[0]));
4050 qlt_handle_dif_error(qpair, cmd, ctio);
4054 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b,
4055 "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n",
4056 vha->vp_idx, status, cmd->state, se_cmd);
4061 /* "cmd->aborted" means
4062 * cmd is already aborted/terminated, we don't
4063 * need to terminate again. The exchange is already
4064 * cleaned up/freed at FW level. Just cleanup at driver
4067 if ((cmd->state != QLA_TGT_STATE_NEED_DATA) &&
4069 cmd->trc_flags |= TRC_CTIO_ERR;
4070 if (qlt_term_ctio_exchange(qpair, ctio, cmd, status))
4075 if (cmd->state == QLA_TGT_STATE_PROCESSED) {
4076 cmd->trc_flags |= TRC_CTIO_DONE;
4077 } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) {
4078 cmd->state = QLA_TGT_STATE_DATA_IN;
4080 if (status == CTIO_SUCCESS)
4081 cmd->write_data_transferred = 1;
4083 ha->tgt.tgt_ops->handle_data(cmd);
4085 } else if (cmd->aborted) {
4086 cmd->trc_flags |= TRC_CTIO_ABORTED;
4087 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e,
4088 "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag);
4090 cmd->trc_flags |= TRC_CTIO_STRANGE;
4091 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c,
4092 "qla_target(%d): A command in state (%d) should "
4093 "not return a CTIO complete\n", vha->vp_idx, cmd->state);
4096 if (unlikely(status != CTIO_SUCCESS) &&
4098 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n");
4102 ha->tgt.tgt_ops->free_cmd(cmd);
4105 static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha,
4110 switch (task_codes) {
4111 case ATIO_SIMPLE_QUEUE:
4112 fcp_task_attr = TCM_SIMPLE_TAG;
4114 case ATIO_HEAD_OF_QUEUE:
4115 fcp_task_attr = TCM_HEAD_TAG;
4117 case ATIO_ORDERED_QUEUE:
4118 fcp_task_attr = TCM_ORDERED_TAG;
4120 case ATIO_ACA_QUEUE:
4121 fcp_task_attr = TCM_ACA_TAG;
4124 fcp_task_attr = TCM_SIMPLE_TAG;
4127 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d,
4128 "qla_target: unknown task code %x, use ORDERED instead\n",
4130 fcp_task_attr = TCM_ORDERED_TAG;
4134 return fcp_task_attr;
4138 * Process context for I/O path into tcm_qla2xxx code
4140 static void __qlt_do_work(struct qla_tgt_cmd *cmd)
4142 scsi_qla_host_t *vha = cmd->vha;
4143 struct qla_hw_data *ha = vha->hw;
4144 struct fc_port *sess = cmd->sess;
4145 struct atio_from_isp *atio = &cmd->atio;
4147 unsigned long flags;
4148 uint32_t data_length;
4149 int ret, fcp_task_attr, data_dir, bidi = 0;
4150 struct qla_qpair *qpair = cmd->qpair;
4153 cmd->trc_flags |= TRC_DO_WORK;
4156 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082,
4157 "cmd with tag %u is aborted\n",
4158 cmd->atio.u.isp24.exchange_addr);
4162 spin_lock_init(&cmd->cmd_lock);
4163 cdb = &atio->u.isp24.fcp_cmnd.cdb[0];
4164 cmd->se_cmd.tag = le32_to_cpu(atio->u.isp24.exchange_addr);
4166 if (atio->u.isp24.fcp_cmnd.rddata &&
4167 atio->u.isp24.fcp_cmnd.wrdata) {
4169 data_dir = DMA_TO_DEVICE;
4170 } else if (atio->u.isp24.fcp_cmnd.rddata)
4171 data_dir = DMA_FROM_DEVICE;
4172 else if (atio->u.isp24.fcp_cmnd.wrdata)
4173 data_dir = DMA_TO_DEVICE;
4175 data_dir = DMA_NONE;
4177 fcp_task_attr = qlt_get_fcp_task_attr(vha,
4178 atio->u.isp24.fcp_cmnd.task_attr);
4179 data_length = get_datalen_for_atio(atio);
4181 ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length,
4182 fcp_task_attr, data_dir, bidi);
4186 * Drop extra session reference from qlt_handle_cmd_for_atio().
4188 ha->tgt.tgt_ops->put_sess(sess);
4192 ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd);
4194 * cmd has not sent to target yet, so pass NULL as the second
4195 * argument to qlt_send_term_exchange() and free the memory here.
4197 cmd->trc_flags |= TRC_DO_WORK_ERR;
4198 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
4199 qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0);
4201 qlt_decr_num_pend_cmds(vha);
4202 cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd);
4203 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
4205 ha->tgt.tgt_ops->put_sess(sess);
4208 static void qlt_do_work(struct work_struct *work)
4210 struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work);
4211 scsi_qla_host_t *vha = cmd->vha;
4212 unsigned long flags;
4214 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4215 list_del(&cmd->cmd_list);
4216 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4221 void qlt_clr_qp_table(struct scsi_qla_host *vha)
4223 unsigned long flags;
4224 struct qla_hw_data *ha = vha->hw;
4225 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4229 ql_log(ql_log_info, vha, 0x706c,
4230 "User update Number of Active Qpairs %d\n",
4231 ha->tgt.num_act_qpairs);
4233 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
4235 btree_for_each_safe64(&tgt->lun_qpair_map, key, node)
4236 btree_remove64(&tgt->lun_qpair_map, key);
4238 ha->base_qpair->lun_cnt = 0;
4239 for (key = 0; key < ha->max_qpairs; key++)
4240 if (ha->queue_pair_map[key])
4241 ha->queue_pair_map[key]->lun_cnt = 0;
4243 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
4246 static void qlt_assign_qpair(struct scsi_qla_host *vha,
4247 struct qla_tgt_cmd *cmd)
4249 struct qla_qpair *qpair, *qp;
4250 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4251 struct qla_qpair_hint *h;
4253 if (vha->flags.qpairs_available) {
4254 h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun);
4256 /* spread lun to qpair ratio evently */
4258 struct scsi_qla_host *base_vha =
4259 pci_get_drvdata(vha->hw->pdev);
4261 qpair = vha->hw->base_qpair;
4262 if (qpair->lun_cnt == 0) {
4264 h = qla_qpair_to_hint(tgt, qpair);
4266 rc = btree_insert64(&tgt->lun_qpair_map,
4267 cmd->unpacked_lun, h, GFP_ATOMIC);
4270 ql_log(ql_log_info, vha, 0xd037,
4271 "Unable to insert lun %llx into lun_qpair_map\n",
4276 lcnt = qpair->lun_cnt;
4280 list_for_each_entry(qp, &base_vha->qp_list,
4282 if (qp->lun_cnt == 0) {
4284 h = qla_qpair_to_hint(tgt, qp);
4286 rc = btree_insert64(&tgt->lun_qpair_map,
4287 cmd->unpacked_lun, h, GFP_ATOMIC);
4290 ql_log(ql_log_info, vha, 0xd038,
4291 "Unable to insert lun %llx into lun_qpair_map\n",
4297 if (qp->lun_cnt < lcnt) {
4306 h = qla_qpair_to_hint(tgt, qpair);
4308 rc = btree_insert64(&tgt->lun_qpair_map,
4309 cmd->unpacked_lun, h, GFP_ATOMIC);
4312 ql_log(ql_log_info, vha, 0xd039,
4313 "Unable to insert lun %llx into lun_qpair_map\n",
4318 h = &tgt->qphints[0];
4321 cmd->qpair = h->qpair;
4322 cmd->se_cmd.cpuid = h->cpuid;
4325 static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha,
4326 struct fc_port *sess,
4327 struct atio_from_isp *atio)
4329 struct qla_tgt_cmd *cmd;
4331 cmd = vha->hw->tgt.tgt_ops->get_cmd(sess);
4335 cmd->cmd_type = TYPE_TGT_CMD;
4336 memcpy(&cmd->atio, atio, sizeof(*atio));
4337 INIT_LIST_HEAD(&cmd->sess_cmd_list);
4338 cmd->state = QLA_TGT_STATE_NEW;
4339 cmd->tgt = vha->vha_tgt.qla_tgt;
4340 qlt_incr_num_pend_cmds(vha);
4343 cmd->loop_id = sess->loop_id;
4344 cmd->conf_compl_supported = sess->conf_compl_supported;
4347 cmd->jiffies_at_alloc = get_jiffies_64();
4349 cmd->unpacked_lun = scsilun_to_int(
4350 (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun);
4351 qlt_assign_qpair(vha, cmd);
4352 cmd->reset_count = vha->hw->base_qpair->chip_reset;
4353 cmd->vp_idx = vha->vp_idx;
4358 /* ha->hardware_lock supposed to be held on entry */
4359 static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha,
4360 struct atio_from_isp *atio)
4362 struct qla_hw_data *ha = vha->hw;
4363 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4364 struct fc_port *sess;
4365 struct qla_tgt_cmd *cmd;
4366 unsigned long flags;
4369 if (unlikely(tgt->tgt_stop)) {
4370 ql_dbg(ql_dbg_io, vha, 0x3061,
4371 "New command while device %p is shutting down\n", tgt);
4375 id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
4376 if (IS_SW_RESV_ADDR(id))
4379 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id);
4380 if (unlikely(!sess))
4383 /* Another WWN used to have our s_id. Our PLOGI scheduled its
4384 * session deletion, but it's still in sess_del_work wq */
4385 if (sess->deleted) {
4386 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002,
4387 "New command while old session %p is being deleted\n",
4393 * Do kref_get() before returning + dropping qla_hw_data->hardware_lock.
4395 if (!kref_get_unless_zero(&sess->sess_kref)) {
4396 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004,
4397 "%s: kref_get fail, %8phC oxid %x \n",
4398 __func__, sess->port_name,
4399 be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
4403 cmd = qlt_get_tag(vha, sess, atio);
4405 ql_dbg(ql_dbg_io, vha, 0x3062,
4406 "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx);
4407 ha->tgt.tgt_ops->put_sess(sess);
4412 cmd->trc_flags |= TRC_NEW_CMD;
4414 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4415 list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list);
4416 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4418 INIT_WORK(&cmd->work, qlt_do_work);
4419 if (vha->flags.qpairs_available) {
4420 queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work);
4421 } else if (ha->msix_count) {
4422 if (cmd->atio.u.isp24.fcp_cmnd.rddata)
4423 queue_work_on(smp_processor_id(), qla_tgt_wq,
4426 queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq,
4429 queue_work(qla_tgt_wq, &cmd->work);
4435 /* ha->hardware_lock supposed to be held on entry */
4436 static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun,
4437 int fn, void *iocb, int flags)
4439 struct scsi_qla_host *vha = sess->vha;
4440 struct qla_hw_data *ha = vha->hw;
4441 struct qla_tgt_mgmt_cmd *mcmd;
4442 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4443 struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0];
4445 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
4447 ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009,
4448 "qla_target(%d): Allocation of management "
4449 "command failed, some commands and their data could "
4450 "leak\n", vha->vp_idx);
4453 memset(mcmd, 0, sizeof(*mcmd));
4457 memcpy(&mcmd->orig_iocb.imm_ntfy, iocb,
4458 sizeof(mcmd->orig_iocb.imm_ntfy));
4460 mcmd->tmr_func = fn;
4461 mcmd->flags = flags;
4462 mcmd->reset_count = ha->base_qpair->chip_reset;
4463 mcmd->qpair = h->qpair;
4465 mcmd->se_cmd.cpuid = h->cpuid;
4466 mcmd->unpacked_lun = lun;
4469 case QLA_TGT_LUN_RESET:
4470 case QLA_TGT_CLEAR_TS:
4471 case QLA_TGT_ABORT_TS:
4472 abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id);
4474 case QLA_TGT_CLEAR_ACA:
4475 h = qlt_find_qphint(vha, mcmd->unpacked_lun);
4476 mcmd->qpair = h->qpair;
4477 mcmd->se_cmd.cpuid = h->cpuid;
4480 case QLA_TGT_TARGET_RESET:
4481 case QLA_TGT_NEXUS_LOSS_SESS:
4482 case QLA_TGT_NEXUS_LOSS:
4483 case QLA_TGT_ABORT_ALL:
4489 INIT_WORK(&mcmd->work, qlt_do_tmr_work);
4490 queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq,
4496 /* ha->hardware_lock supposed to be held on entry */
4497 static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb)
4499 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4500 struct qla_hw_data *ha = vha->hw;
4501 struct fc_port *sess;
4504 unsigned long flags;
4506 fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
4508 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
4509 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha,
4510 a->u.isp24.fcp_hdr.s_id);
4511 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
4514 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
4516 if (sess == NULL || sess->deleted)
4519 return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
4522 /* ha->hardware_lock supposed to be held on entry */
4523 static int __qlt_abort_task(struct scsi_qla_host *vha,
4524 struct imm_ntfy_from_isp *iocb, struct fc_port *sess)
4526 struct atio_from_isp *a = (struct atio_from_isp *)iocb;
4527 struct qla_hw_data *ha = vha->hw;
4528 struct qla_tgt_mgmt_cmd *mcmd;
4532 mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
4534 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f,
4535 "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
4536 vha->vp_idx, __func__);
4539 memset(mcmd, 0, sizeof(*mcmd));
4542 memcpy(&mcmd->orig_iocb.imm_ntfy, iocb,
4543 sizeof(mcmd->orig_iocb.imm_ntfy));
4546 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
4547 mcmd->reset_count = ha->base_qpair->chip_reset;
4548 mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK;
4549 mcmd->qpair = ha->base_qpair;
4551 rc = ha->tgt.tgt_ops->handle_tmr(mcmd, unpacked_lun, mcmd->tmr_func,
4552 le16_to_cpu(iocb->u.isp2x.seq_id));
4554 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060,
4555 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
4557 mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
4564 /* ha->hardware_lock supposed to be held on entry */
4565 static int qlt_abort_task(struct scsi_qla_host *vha,
4566 struct imm_ntfy_from_isp *iocb)
4568 struct qla_hw_data *ha = vha->hw;
4569 struct fc_port *sess;
4571 unsigned long flags;
4573 loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb);
4575 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
4576 sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
4577 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
4580 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025,
4581 "qla_target(%d): task abort for unexisting "
4582 "session\n", vha->vp_idx);
4583 return qlt_sched_sess_work(vha->vha_tgt.qla_tgt,
4584 QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb));
4587 return __qlt_abort_task(vha, iocb, sess);
4590 void qlt_logo_completion_handler(fc_port_t *fcport, int rc)
4592 if (rc != MBS_COMMAND_COMPLETE) {
4593 ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093,
4594 "%s: se_sess %p / sess %p from"
4595 " port %8phC loop_id %#04x s_id %02x:%02x:%02x"
4596 " LOGO failed: %#x\n",
4600 fcport->port_name, fcport->loop_id,
4601 fcport->d_id.b.domain, fcport->d_id.b.area,
4602 fcport->d_id.b.al_pa, rc);
4605 fcport->logout_completed = 1;
4609 * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list)
4611 * Schedules sessions with matching port_id/loop_id but different wwn for
4612 * deletion. Returns existing session with matching wwn if present.
4616 qlt_find_sess_invalidate_other(scsi_qla_host_t *vha, uint64_t wwn,
4617 port_id_t port_id, uint16_t loop_id, struct fc_port **conflict_sess)
4619 struct fc_port *sess = NULL, *other_sess;
4622 *conflict_sess = NULL;
4624 list_for_each_entry(other_sess, &vha->vp_fcports, list) {
4626 other_wwn = wwn_to_u64(other_sess->port_name);
4628 if (wwn == other_wwn) {
4634 /* find other sess with nport_id collision */
4635 if (port_id.b24 == other_sess->d_id.b24) {
4636 if (loop_id != other_sess->loop_id) {
4637 ql_dbg(ql_dbg_disc, vha, 0x1000c,
4638 "Invalidating sess %p loop_id %d wwn %llx.\n",
4639 other_sess, other_sess->loop_id, other_wwn);
4642 * logout_on_delete is set by default, but another
4643 * session that has the same s_id/loop_id combo
4644 * might have cleared it when requested this session
4645 * deletion, so don't touch it
4647 qlt_schedule_sess_for_deletion(other_sess);
4650 * Another wwn used to have our s_id/loop_id
4651 * kill the session, but don't free the loop_id
4653 ql_dbg(ql_dbg_disc, vha, 0xf01b,
4654 "Invalidating sess %p loop_id %d wwn %llx.\n",
4655 other_sess, other_sess->loop_id, other_wwn);
4657 other_sess->keep_nport_handle = 1;
4658 if (other_sess->disc_state != DSC_DELETED)
4659 *conflict_sess = other_sess;
4660 qlt_schedule_sess_for_deletion(other_sess);
4665 /* find other sess with nport handle collision */
4666 if ((loop_id == other_sess->loop_id) &&
4667 (loop_id != FC_NO_LOOP_ID)) {
4668 ql_dbg(ql_dbg_disc, vha, 0x1000d,
4669 "Invalidating sess %p loop_id %d wwn %llx.\n",
4670 other_sess, other_sess->loop_id, other_wwn);
4672 /* Same loop_id but different s_id
4673 * Ok to kill and logout */
4674 qlt_schedule_sess_for_deletion(other_sess);
4681 /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */
4682 static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id)
4684 struct qla_tgt_sess_op *op;
4685 struct qla_tgt_cmd *cmd;
4688 unsigned long flags;
4690 key = (((u32)s_id->b.domain << 16) |
4691 ((u32)s_id->b.area << 8) |
4692 ((u32)s_id->b.al_pa));
4694 spin_lock_irqsave(&vha->cmd_list_lock, flags);
4695 list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) {
4696 uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
4698 if (op_key == key) {
4704 list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
4705 uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
4707 if (op_key == key) {
4713 list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
4714 uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id);
4716 if (cmd_key == key) {
4721 spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
4726 static int qlt_handle_login(struct scsi_qla_host *vha,
4727 struct imm_ntfy_from_isp *iocb)
4729 struct fc_port *sess = NULL, *conflict_sess = NULL;
4732 uint16_t loop_id, wd3_lo;
4734 struct qlt_plogi_ack_t *pla;
4735 unsigned long flags;
4737 lockdep_assert_held(&vha->hw->hardware_lock);
4739 wwn = wwn_to_u64(iocb->u.isp24.port_name);
4741 port_id.b.domain = iocb->u.isp24.port_id[2];
4742 port_id.b.area = iocb->u.isp24.port_id[1];
4743 port_id.b.al_pa = iocb->u.isp24.port_id[0];
4744 port_id.b.rsvd_1 = 0;
4746 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
4748 /* Mark all stale commands sitting in qla_tgt_wq for deletion */
4749 abort_cmds_for_s_id(vha, &port_id);
4752 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4753 sess = qlt_find_sess_invalidate_other(vha, wwn,
4754 port_id, loop_id, &conflict_sess);
4755 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4757 ql_dbg(ql_dbg_disc, vha, 0xffff,
4758 "%s %d Term INOT due to WWN=0 lid=%d, NportID %06X ",
4759 __func__, __LINE__, loop_id, port_id.b24);
4760 qlt_send_term_imm_notif(vha, iocb, 1);
4764 if (IS_SW_RESV_ADDR(port_id)) {
4769 if (vha->hw->flags.edif_enabled &&
4770 vha->e_dbell.db_flags != EDB_ACTIVE) {
4771 ql_dbg(ql_dbg_disc, vha, 0xffff,
4772 "%s %d Term INOT due to app not available lid=%d, NportID %06X ",
4773 __func__, __LINE__, loop_id, port_id.b24);
4774 qlt_send_term_imm_notif(vha, iocb, 1);
4778 pla = qlt_plogi_ack_find_add(vha, &port_id, iocb);
4780 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
4781 "%s %d %8phC Term INOT due to mem alloc fail",
4783 iocb->u.isp24.port_name);
4784 qlt_send_term_imm_notif(vha, iocb, 1);
4788 if (conflict_sess) {
4789 conflict_sess->login_gen++;
4790 qlt_plogi_ack_link(vha, pla, conflict_sess,
4791 QLT_PLOGI_LINK_CONFLICT);
4796 ql_dbg(ql_dbg_disc, vha, 0xffff,
4797 "%s %d %8phC post new sess\n",
4798 __func__, __LINE__, iocb->u.isp24.port_name);
4799 if (iocb->u.isp24.status_subcode == ELS_PLOGI)
4800 qla24xx_post_newsess_work(vha, &port_id,
4801 iocb->u.isp24.port_name,
4802 iocb->u.isp24.u.plogi.node_name,
4805 qla24xx_post_newsess_work(vha, &port_id,
4806 iocb->u.isp24.port_name, NULL,
4812 if (sess->disc_state == DSC_UPD_FCPORT) {
4816 * Remote port registration is still going on from
4817 * previous login. Allow it to finish before we
4818 * accept the new login.
4820 sess->next_disc_state = DSC_DELETE_PEND;
4821 sec = jiffies_to_msecs(jiffies -
4822 sess->jiffies_at_registration) / 1000;
4823 if (sess->sec_since_registration < sec && sec &&
4825 sess->sec_since_registration = sec;
4826 ql_dbg(ql_dbg_disc, vha, 0xffff,
4827 "%s %8phC - Slow Rport registration (%d Sec)\n",
4828 __func__, sess->port_name, sec);
4831 if (!conflict_sess) {
4832 list_del(&pla->list);
4833 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4836 qlt_send_term_imm_notif(vha, iocb, 1);
4840 qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN);
4841 sess->d_id = port_id;
4843 sess->loop_id = loop_id;
4845 if (iocb->u.isp24.status_subcode == ELS_PLOGI) {
4846 ql_dbg(ql_dbg_disc, vha, 0xffff,
4847 "%s %8phC - send port online\n",
4848 __func__, sess->port_name);
4850 qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE,
4854 if (iocb->u.isp24.status_subcode == ELS_PRLI) {
4855 sess->fw_login_state = DSC_LS_PRLI_PEND;
4857 sess->loop_id = loop_id;
4858 sess->d_id = port_id;
4859 sess->fw_login_state = DSC_LS_PRLI_PEND;
4860 wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo);
4863 sess->conf_compl_supported = 1;
4865 if ((wd3_lo & BIT_4) == 0)
4866 sess->port_type = FCT_INITIATOR;
4868 sess->port_type = FCT_TARGET;
4871 sess->fw_login_state = DSC_LS_PLOGI_PEND;
4874 ql_dbg(ql_dbg_disc, vha, 0x20f9,
4875 "%s %d %8phC DS %d\n",
4876 __func__, __LINE__, sess->port_name, sess->disc_state);
4878 switch (sess->disc_state) {
4880 case DSC_LOGIN_PEND:
4881 qlt_plogi_ack_unref(vha, pla);
4886 * Under normal circumstances we want to release nport handle
4887 * during LOGO process to avoid nport handle leaks inside FW.
4888 * The exception is when LOGO is done while another PLOGI with
4889 * the same nport handle is waiting as might be the case here.
4890 * Note: there is always a possibily of a race where session
4891 * deletion has already started for other reasons (e.g. ACL
4892 * removal) and now PLOGI arrives:
4893 * 1. if PLOGI arrived in FW after nport handle has been freed,
4894 * FW must have assigned this PLOGI a new/same handle and we
4895 * can proceed ACK'ing it as usual when session deletion
4897 * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT
4898 * bit reached it, the handle has now been released. We'll
4899 * get an error when we ACK this PLOGI. Nothing will be sent
4900 * back to initiator. Initiator should eventually retry
4901 * PLOGI and situation will correct itself.
4903 sess->keep_nport_handle = ((sess->loop_id == loop_id) &&
4904 (sess->d_id.b24 == port_id.b24));
4906 ql_dbg(ql_dbg_disc, vha, 0x20f9,
4907 "%s %d %8phC post del sess\n",
4908 __func__, __LINE__, sess->port_name);
4911 qlt_schedule_sess_for_deletion(sess);
4919 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4921 static int qlt_24xx_handle_els(struct scsi_qla_host *vha,
4922 struct imm_ntfy_from_isp *iocb)
4924 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4925 struct qla_hw_data *ha = vha->hw;
4926 struct fc_port *sess = NULL, *conflict_sess = NULL;
4932 unsigned long flags;
4934 lockdep_assert_held(&ha->hardware_lock);
4936 wwn = wwn_to_u64(iocb->u.isp24.port_name);
4938 port_id.b.domain = iocb->u.isp24.port_id[2];
4939 port_id.b.area = iocb->u.isp24.port_id[1];
4940 port_id.b.al_pa = iocb->u.isp24.port_id[0];
4941 port_id.b.rsvd_1 = 0;
4943 loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
4945 ql_dbg(ql_dbg_disc, vha, 0xf026,
4946 "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n",
4947 vha->vp_idx, iocb->u.isp24.port_id[2],
4948 iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0],
4949 iocb->u.isp24.status_subcode, loop_id,
4950 iocb->u.isp24.port_name);
4952 /* res = 1 means ack at the end of thread
4953 * res = 0 means ack async/later.
4955 switch (iocb->u.isp24.status_subcode) {
4957 res = qlt_handle_login(vha, iocb);
4962 sess = qla2x00_find_fcport_by_wwpn(vha,
4963 iocb->u.isp24.port_name, 1);
4965 if (sess && sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]) {
4966 ql_dbg(ql_dbg_disc, vha, 0xffff,
4967 "%s %d %8phC Term PRLI due to PLOGI ACK not completed\n",
4969 iocb->u.isp24.port_name);
4970 qlt_send_term_imm_notif(vha, iocb, 1);
4974 res = qlt_handle_login(vha, iocb);
4978 if (IS_SW_RESV_ADDR(port_id)) {
4983 wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo);
4986 spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags);
4987 sess = qlt_find_sess_invalidate_other(vha, wwn, port_id,
4988 loop_id, &conflict_sess);
4989 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags);
4992 if (conflict_sess) {
4993 switch (conflict_sess->disc_state) {
4995 case DSC_DELETE_PEND:
4998 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b,
4999 "PRLI with conflicting sess %p port %8phC\n",
5000 conflict_sess, conflict_sess->port_name);
5001 conflict_sess->fw_login_state =
5002 DSC_LS_PORT_UNAVAIL;
5003 qlt_send_term_imm_notif(vha, iocb, 1);
5010 bool delete = false;
5013 spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags);
5014 switch (sess->fw_login_state) {
5015 case DSC_LS_PLOGI_PEND:
5016 case DSC_LS_PLOGI_COMP:
5017 case DSC_LS_PRLI_COMP:
5024 switch (sess->disc_state) {
5025 case DSC_UPD_FCPORT:
5026 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock,
5029 sec = jiffies_to_msecs(jiffies -
5030 sess->jiffies_at_registration)/1000;
5031 if (sess->sec_since_registration < sec && sec &&
5033 sess->sec_since_registration = sec;
5034 ql_dbg(ql_dbg_disc, sess->vha, 0xffff,
5035 "%s %8phC : Slow Rport registration(%d Sec)\n",
5036 __func__, sess->port_name, sec);
5038 qlt_send_term_imm_notif(vha, iocb, 1);
5041 case DSC_LOGIN_PEND:
5043 case DSC_LOGIN_COMPLETE:
5052 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock,
5055 * Impatient initiator sent PRLI before last
5056 * PLOGI could finish. Will force him to re-try,
5057 * while last one finishes.
5059 ql_log(ql_log_warn, sess->vha, 0xf095,
5060 "sess %p PRLI received, before plogi ack.\n",
5062 qlt_send_term_imm_notif(vha, iocb, 1);
5068 * This shouldn't happen under normal circumstances,
5069 * since we have deleted the old session during PLOGI
5071 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096,
5072 "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n",
5073 sess->loop_id, sess, iocb->u.isp24.nport_handle);
5076 sess->loop_id = loop_id;
5077 sess->d_id = port_id;
5078 sess->fw_login_state = DSC_LS_PRLI_PEND;
5081 sess->conf_compl_supported = 1;
5083 if ((wd3_lo & BIT_4) == 0)
5084 sess->port_type = FCT_INITIATOR;
5086 sess->port_type = FCT_TARGET;
5088 spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags);
5090 res = 1; /* send notify ack */
5092 /* Make session global (not used in fabric mode) */
5093 if (ha->current_topology != ISP_CFG_F) {
5095 ql_dbg(ql_dbg_disc, vha, 0x20fa,
5096 "%s %d %8phC post nack\n",
5097 __func__, __LINE__, sess->port_name);
5098 qla24xx_post_nack_work(vha, sess, iocb,
5102 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5103 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5104 qla2xxx_wake_dpc(vha);
5108 ql_dbg(ql_dbg_disc, vha, 0x20fb,
5109 "%s %d %8phC post nack\n",
5110 __func__, __LINE__, sess->port_name);
5111 qla24xx_post_nack_work(vha, sess, iocb,
5119 if (le16_to_cpu(iocb->u.isp24.flags) &
5120 NOTIFY24XX_FLAGS_GLOBAL_TPRLO) {
5122 qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS);
5129 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
5130 sess = qla2x00_find_fcport_by_loopid(vha, loop_id);
5131 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
5135 sess->fw_login_state = DSC_LS_LOGO_PEND;
5136 sess->logo_ack_needed = 1;
5137 memcpy(sess->iocb, iocb, IOCB_SIZE);
5140 res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS);
5142 ql_dbg(ql_dbg_disc, vha, 0x20fc,
5143 "%s: logo %llx res %d sess %p ",
5144 __func__, wwn, res, sess);
5147 * cmd went upper layer, look for qlt_xmit_tm_rsp()
5148 * for LOGO_ACK & sess delete
5153 /* cmd did not go to upper layer. */
5155 qlt_schedule_sess_for_deletion(sess);
5158 /* else logo will be ack */
5164 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5166 if (tgt->link_reinit_iocb_pending) {
5167 qlt_send_notify_ack(ha->base_qpair,
5168 &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0);
5169 tgt->link_reinit_iocb_pending = 0;
5172 sess = qla2x00_find_fcport_by_wwpn(vha,
5173 iocb->u.isp24.port_name, 1);
5175 ql_dbg(ql_dbg_disc, vha, 0x20fd,
5176 "sess %p lid %d|%d DS %d LS %d\n",
5177 sess, sess->loop_id, loop_id,
5178 sess->disc_state, sess->fw_login_state);
5181 res = 1; /* send notify ack */
5185 case ELS_FLOGI: /* should never happen */
5187 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061,
5188 "qla_target(%d): Unsupported ELS command %x "
5189 "received\n", vha->vp_idx, iocb->u.isp24.status_subcode);
5190 res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS);
5194 ql_dbg(ql_dbg_disc, vha, 0xf026,
5195 "qla_target(%d): Exit ELS opcode: 0x%02x res %d\n",
5196 vha->vp_idx, iocb->u.isp24.status_subcode, res);
5202 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5204 static void qlt_handle_imm_notify(struct scsi_qla_host *vha,
5205 struct imm_ntfy_from_isp *iocb)
5207 struct qla_hw_data *ha = vha->hw;
5208 uint32_t add_flags = 0;
5209 int send_notify_ack = 1;
5212 lockdep_assert_held(&ha->hardware_lock);
5214 status = le16_to_cpu(iocb->u.isp2x.status);
5216 case IMM_NTFY_LIP_RESET:
5218 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032,
5219 "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
5220 vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle),
5221 iocb->u.isp24.status_subcode);
5223 if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0)
5224 send_notify_ack = 0;
5228 case IMM_NTFY_LIP_LINK_REINIT:
5230 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5232 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033,
5233 "qla_target(%d): LINK REINIT (loop %#x, "
5234 "subcode %x)\n", vha->vp_idx,
5235 le16_to_cpu(iocb->u.isp24.nport_handle),
5236 iocb->u.isp24.status_subcode);
5237 if (tgt->link_reinit_iocb_pending) {
5238 qlt_send_notify_ack(ha->base_qpair,
5239 &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0);
5241 memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb));
5242 tgt->link_reinit_iocb_pending = 1;
5244 * QLogic requires to wait after LINK REINIT for possible
5245 * PDISC or ADISC ELS commands
5247 send_notify_ack = 0;
5251 case IMM_NTFY_PORT_LOGOUT:
5252 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034,
5253 "qla_target(%d): Port logout (loop "
5254 "%#x, subcode %x)\n", vha->vp_idx,
5255 le16_to_cpu(iocb->u.isp24.nport_handle),
5256 iocb->u.isp24.status_subcode);
5258 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0)
5259 send_notify_ack = 0;
5260 /* The sessions will be cleared in the callback, if needed */
5263 case IMM_NTFY_GLBL_TPRLO:
5264 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035,
5265 "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status);
5266 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0)
5267 send_notify_ack = 0;
5268 /* The sessions will be cleared in the callback, if needed */
5271 case IMM_NTFY_PORT_CONFIG:
5272 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036,
5273 "qla_target(%d): Port config changed (%x)\n", vha->vp_idx,
5275 if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0)
5276 send_notify_ack = 0;
5277 /* The sessions will be cleared in the callback, if needed */
5280 case IMM_NTFY_GLBL_LOGO:
5281 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a,
5282 "qla_target(%d): Link failure detected\n",
5284 /* I_T nexus loss */
5285 if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0)
5286 send_notify_ack = 0;
5289 case IMM_NTFY_IOCB_OVERFLOW:
5290 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b,
5291 "qla_target(%d): Cannot provide requested "
5292 "capability (IOCB overflowed the immediate notify "
5293 "resource count)\n", vha->vp_idx);
5296 case IMM_NTFY_ABORT_TASK:
5297 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037,
5298 "qla_target(%d): Abort Task (S %08x I %#x -> "
5299 "L %#x)\n", vha->vp_idx,
5300 le16_to_cpu(iocb->u.isp2x.seq_id),
5301 GET_TARGET_ID(ha, (struct atio_from_isp *)iocb),
5302 le16_to_cpu(iocb->u.isp2x.lun));
5303 if (qlt_abort_task(vha, iocb) == 0)
5304 send_notify_ack = 0;
5307 case IMM_NTFY_RESOURCE:
5308 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c,
5309 "qla_target(%d): Out of resources, host %ld\n",
5310 vha->vp_idx, vha->host_no);
5313 case IMM_NTFY_MSG_RX:
5314 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038,
5315 "qla_target(%d): Immediate notify task %x\n",
5316 vha->vp_idx, iocb->u.isp2x.task_flags);
5320 if (qlt_24xx_handle_els(vha, iocb) == 0)
5321 send_notify_ack = 0;
5324 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d,
5325 "qla_target(%d): Received unknown immediate "
5326 "notify status %x\n", vha->vp_idx, status);
5330 if (send_notify_ack)
5331 qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0,
5336 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5337 * This function sends busy to ISP 2xxx or 24xx.
5339 static int __qlt_send_busy(struct qla_qpair *qpair,
5340 struct atio_from_isp *atio, uint16_t status)
5342 struct scsi_qla_host *vha = qpair->vha;
5343 struct ctio7_to_24xx *ctio24;
5344 struct qla_hw_data *ha = vha->hw;
5346 struct fc_port *sess = NULL;
5347 unsigned long flags;
5351 id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
5353 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
5354 sess = qla2x00_find_fcport_by_nportid(vha, &id, 1);
5355 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
5357 qlt_send_term_exchange(qpair, NULL, atio, 1, 0);
5360 /* Sending marker isn't necessary, since we called from ISR */
5362 pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL);
5364 ql_dbg(ql_dbg_io, vha, 0x3063,
5365 "qla_target(%d): %s failed: unable to allocate "
5366 "request packet", vha->vp_idx, __func__);
5370 qpair->tgt_counters.num_q_full_sent++;
5371 pkt->entry_count = 1;
5372 pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
5374 ctio24 = (struct ctio7_to_24xx *)pkt;
5375 ctio24->entry_type = CTIO_TYPE7;
5376 ctio24->nport_handle = cpu_to_le16(sess->loop_id);
5377 ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
5378 ctio24->vp_index = vha->vp_idx;
5379 ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
5380 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
5381 temp = (atio->u.isp24.attr << 9) |
5382 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS |
5383 CTIO7_FLAGS_DONT_RET_CTIO;
5384 ctio24->u.status1.flags = cpu_to_le16(temp);
5386 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
5387 * if the explicit conformation is used.
5389 ctio24->u.status1.ox_id =
5390 cpu_to_le16(be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
5391 ctio24->u.status1.scsi_status = cpu_to_le16(status);
5393 ctio24->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio));
5395 if (ctio24->u.status1.residual != 0)
5396 ctio24->u.status1.scsi_status |= cpu_to_le16(SS_RESIDUAL_UNDER);
5398 /* Memory Barrier */
5400 if (qpair->reqq_start_iocbs)
5401 qpair->reqq_start_iocbs(qpair);
5403 qla2x00_start_iocbs(vha, qpair->req);
5408 * This routine is used to allocate a command for either a QFull condition
5409 * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go
5413 qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
5414 struct atio_from_isp *atio, uint16_t status, int qfull)
5416 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5417 struct qla_hw_data *ha = vha->hw;
5418 struct fc_port *sess;
5419 struct qla_tgt_cmd *cmd;
5420 unsigned long flags;
5422 if (unlikely(tgt->tgt_stop)) {
5423 ql_dbg(ql_dbg_io, vha, 0x300a,
5424 "New command while device %p is shutting down\n", tgt);
5428 if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) {
5429 vha->hw->tgt.num_qfull_cmds_dropped++;
5430 if (vha->hw->tgt.num_qfull_cmds_dropped >
5431 vha->qla_stats.stat_max_qfull_cmds_dropped)
5432 vha->qla_stats.stat_max_qfull_cmds_dropped =
5433 vha->hw->tgt.num_qfull_cmds_dropped;
5435 ql_dbg(ql_dbg_io, vha, 0x3068,
5436 "qla_target(%d): %s: QFull CMD dropped[%d]\n",
5437 vha->vp_idx, __func__,
5438 vha->hw->tgt.num_qfull_cmds_dropped);
5440 qlt_chk_exch_leak_thresh_hold(vha);
5444 sess = ha->tgt.tgt_ops->find_sess_by_s_id
5445 (vha, atio->u.isp24.fcp_hdr.s_id);
5449 cmd = ha->tgt.tgt_ops->get_cmd(sess);
5451 ql_dbg(ql_dbg_io, vha, 0x3009,
5452 "qla_target(%d): %s: Allocation of cmd failed\n",
5453 vha->vp_idx, __func__);
5455 vha->hw->tgt.num_qfull_cmds_dropped++;
5456 if (vha->hw->tgt.num_qfull_cmds_dropped >
5457 vha->qla_stats.stat_max_qfull_cmds_dropped)
5458 vha->qla_stats.stat_max_qfull_cmds_dropped =
5459 vha->hw->tgt.num_qfull_cmds_dropped;
5461 qlt_chk_exch_leak_thresh_hold(vha);
5465 qlt_incr_num_pend_cmds(vha);
5466 INIT_LIST_HEAD(&cmd->cmd_list);
5467 memcpy(&cmd->atio, atio, sizeof(*atio));
5469 cmd->tgt = vha->vha_tgt.qla_tgt;
5471 cmd->reset_count = ha->base_qpair->chip_reset;
5473 cmd->qpair = ha->base_qpair;
5477 /* NOTE: borrowing the state field to carry the status */
5478 cmd->state = status;
5480 cmd->term_exchg = 1;
5482 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5483 list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list);
5485 vha->hw->tgt.num_qfull_cmds_alloc++;
5486 if (vha->hw->tgt.num_qfull_cmds_alloc >
5487 vha->qla_stats.stat_max_qfull_cmds_alloc)
5488 vha->qla_stats.stat_max_qfull_cmds_alloc =
5489 vha->hw->tgt.num_qfull_cmds_alloc;
5490 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5494 qlt_free_qfull_cmds(struct qla_qpair *qpair)
5496 struct scsi_qla_host *vha = qpair->vha;
5497 struct qla_hw_data *ha = vha->hw;
5498 unsigned long flags;
5499 struct qla_tgt_cmd *cmd, *tcmd;
5500 struct list_head free_list, q_full_list;
5503 if (list_empty(&ha->tgt.q_full_list))
5506 INIT_LIST_HEAD(&free_list);
5507 INIT_LIST_HEAD(&q_full_list);
5509 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5510 if (list_empty(&ha->tgt.q_full_list)) {
5511 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5515 list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list);
5516 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5518 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
5519 list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) {
5521 /* cmd->state is a borrowed field to hold status */
5522 rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state);
5523 else if (cmd->term_exchg)
5524 rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio);
5530 ql_dbg(ql_dbg_io, vha, 0x3006,
5531 "%s: busy sent for ox_id[%04x]\n", __func__,
5532 be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
5533 else if (cmd->term_exchg)
5534 ql_dbg(ql_dbg_io, vha, 0x3007,
5535 "%s: Term exchg sent for ox_id[%04x]\n", __func__,
5536 be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
5538 ql_dbg(ql_dbg_io, vha, 0x3008,
5539 "%s: Unexpected cmd in QFull list %p\n", __func__,
5542 list_move_tail(&cmd->cmd_list, &free_list);
5544 /* piggy back on hardware_lock for protection */
5545 vha->hw->tgt.num_qfull_cmds_alloc--;
5547 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
5551 list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) {
5552 list_del(&cmd->cmd_list);
5553 /* This cmd was never sent to TCM. There is no need
5554 * to schedule free or call free_cmd
5559 if (!list_empty(&q_full_list)) {
5560 spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
5561 list_splice(&q_full_list, &vha->hw->tgt.q_full_list);
5562 spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
5569 qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio,
5573 struct scsi_qla_host *vha = qpair->vha;
5575 rc = __qlt_send_busy(qpair, atio, status);
5577 qlt_alloc_qfull_cmd(vha, atio, status, 1);
5581 qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair,
5582 struct atio_from_isp *atio, uint8_t ha_locked)
5584 struct qla_hw_data *ha = vha->hw;
5585 unsigned long flags;
5587 if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha))
5591 spin_lock_irqsave(&ha->hardware_lock, flags);
5592 qlt_send_busy(qpair, atio, qla_sam_status);
5594 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5599 /* ha->hardware_lock supposed to be held on entry */
5600 /* called via callback from qla2xxx */
5601 static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha,
5602 struct atio_from_isp *atio, uint8_t ha_locked)
5604 struct qla_hw_data *ha = vha->hw;
5605 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5607 unsigned long flags = 0;
5609 if (unlikely(tgt == NULL)) {
5610 ql_dbg(ql_dbg_tgt, vha, 0x3064,
5611 "ATIO pkt, but no tgt (ha %p)", ha);
5615 * In tgt_stop mode we also should allow all requests to pass.
5616 * Otherwise, some commands can stuck.
5619 tgt->atio_irq_cmd_count++;
5621 switch (atio->u.raw.entry_type) {
5623 if (unlikely(atio->u.isp24.exchange_addr ==
5624 cpu_to_le32(ATIO_EXCHANGE_ADDRESS_UNKNOWN))) {
5625 ql_dbg(ql_dbg_io, vha, 0x3065,
5626 "qla_target(%d): ATIO_TYPE7 "
5627 "received with UNKNOWN exchange address, "
5628 "sending QUEUE_FULL\n", vha->vp_idx);
5630 spin_lock_irqsave(&ha->hardware_lock, flags);
5631 qlt_send_busy(ha->base_qpair, atio, qla_sam_status);
5633 spin_unlock_irqrestore(&ha->hardware_lock,
5638 if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) {
5639 rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair,
5642 tgt->atio_irq_cmd_count--;
5645 rc = qlt_handle_cmd_for_atio(vha, atio);
5647 rc = qlt_handle_task_mgmt(vha, atio);
5649 if (unlikely(rc != 0)) {
5651 spin_lock_irqsave(&ha->hardware_lock, flags);
5654 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5655 "qla_target: Unable to send command to target\n");
5658 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5659 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
5660 qlt_send_term_exchange(ha->base_qpair, NULL,
5664 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5665 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5667 qlt_send_busy(ha->base_qpair, atio,
5671 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5672 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5674 qlt_send_busy(ha->base_qpair, atio,
5679 spin_unlock_irqrestore(&ha->hardware_lock,
5684 case IMMED_NOTIFY_TYPE:
5686 if (unlikely(atio->u.isp2x.entry_status != 0)) {
5687 ql_dbg(ql_dbg_tgt, vha, 0xe05b,
5688 "qla_target(%d): Received ATIO packet %x "
5689 "with error status %x\n", vha->vp_idx,
5690 atio->u.raw.entry_type,
5691 atio->u.isp2x.entry_status);
5694 ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO");
5697 spin_lock_irqsave(&ha->hardware_lock, flags);
5698 qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio);
5700 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5705 ql_dbg(ql_dbg_tgt, vha, 0xe05c,
5706 "qla_target(%d): Received unknown ATIO atio "
5707 "type %x\n", vha->vp_idx, atio->u.raw.entry_type);
5711 tgt->atio_irq_cmd_count--;
5715 * qpair lock is assume to be held
5716 * rc = 0 : send terminate & abts respond
5717 * rc != 0: do not send term & abts respond
5719 static int qlt_chk_unresolv_exchg(struct scsi_qla_host *vha,
5720 struct qla_qpair *qpair, struct abts_resp_from_24xx_fw *entry)
5722 struct qla_hw_data *ha = vha->hw;
5726 * Detect unresolved exchange. If the same ABTS is unable
5727 * to terminate an existing command and the same ABTS loops
5728 * between FW & Driver, then force FW dump. Under 1 jiff,
5729 * we should see multiple loops.
5731 if (qpair->retry_term_exchg_addr == entry->exchange_addr_to_abort &&
5732 qpair->retry_term_jiff == jiffies) {
5733 /* found existing exchange */
5734 qpair->retry_term_cnt++;
5735 if (qpair->retry_term_cnt >= 5) {
5737 qpair->retry_term_cnt = 0;
5738 ql_log(ql_log_warn, vha, 0xffff,
5739 "Unable to send ABTS Respond. Dumping firmware.\n");
5740 ql_dump_buffer(ql_dbg_tgt_mgt + ql_dbg_buffer,
5741 vha, 0xffff, (uint8_t *)entry, sizeof(*entry));
5743 if (qpair == ha->base_qpair)
5744 ha->isp_ops->fw_dump(vha);
5746 qla2xxx_dump_fw(vha);
5748 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5749 qla2xxx_wake_dpc(vha);
5751 } else if (qpair->retry_term_jiff != jiffies) {
5752 qpair->retry_term_exchg_addr = entry->exchange_addr_to_abort;
5753 qpair->retry_term_cnt = 0;
5754 qpair->retry_term_jiff = jiffies;
5761 static void qlt_handle_abts_completion(struct scsi_qla_host *vha,
5762 struct rsp_que *rsp, response_t *pkt)
5764 struct abts_resp_from_24xx_fw *entry =
5765 (struct abts_resp_from_24xx_fw *)pkt;
5766 u32 h = pkt->handle & ~QLA_TGT_HANDLE_MASK;
5767 struct qla_tgt_mgmt_cmd *mcmd;
5768 struct qla_hw_data *ha = vha->hw;
5770 mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, pkt);
5771 if (mcmd == NULL && h != QLA_TGT_SKIP_HANDLE) {
5772 ql_dbg(ql_dbg_async, vha, 0xe064,
5773 "qla_target(%d): ABTS Comp without mcmd\n",
5780 vha->vha_tgt.qla_tgt->abts_resp_expected--;
5782 ql_dbg(ql_dbg_tgt, vha, 0xe038,
5783 "ABTS_RESP_24XX: compl_status %x\n",
5784 entry->compl_status);
5786 if (le16_to_cpu(entry->compl_status) != ABTS_RESP_COMPL_SUCCESS) {
5787 if (le32_to_cpu(entry->error_subcode1) == 0x1E &&
5788 le32_to_cpu(entry->error_subcode2) == 0) {
5789 if (qlt_chk_unresolv_exchg(vha, rsp->qpair, entry)) {
5790 ha->tgt.tgt_ops->free_mcmd(mcmd);
5793 qlt_24xx_retry_term_exchange(vha, rsp->qpair,
5796 ql_dbg(ql_dbg_tgt, vha, 0xe063,
5797 "qla_target(%d): ABTS_RESP_24XX failed %x (subcode %x:%x)",
5798 vha->vp_idx, entry->compl_status,
5799 entry->error_subcode1,
5800 entry->error_subcode2);
5801 ha->tgt.tgt_ops->free_mcmd(mcmd);
5804 ha->tgt.tgt_ops->free_mcmd(mcmd);
5808 /* ha->hardware_lock supposed to be held on entry */
5809 /* called via callback from qla2xxx */
5810 static void qlt_response_pkt(struct scsi_qla_host *vha,
5811 struct rsp_que *rsp, response_t *pkt)
5813 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5815 if (unlikely(tgt == NULL)) {
5816 ql_dbg(ql_dbg_tgt, vha, 0xe05d,
5817 "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n",
5818 vha->vp_idx, pkt->entry_type, vha->hw);
5823 * In tgt_stop mode we also should allow all requests to pass.
5824 * Otherwise, some commands can stuck.
5827 switch (pkt->entry_type) {
5831 struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
5833 qlt_do_ctio_completion(vha, rsp, entry->handle,
5834 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5839 case ACCEPT_TGT_IO_TYPE:
5841 struct atio_from_isp *atio = (struct atio_from_isp *)pkt;
5844 if (atio->u.isp2x.status !=
5845 cpu_to_le16(ATIO_CDB_VALID)) {
5846 ql_dbg(ql_dbg_tgt, vha, 0xe05e,
5847 "qla_target(%d): ATIO with error "
5848 "status %x received\n", vha->vp_idx,
5849 le16_to_cpu(atio->u.isp2x.status));
5853 rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1);
5857 rc = qlt_handle_cmd_for_atio(vha, atio);
5858 if (unlikely(rc != 0)) {
5861 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5862 "qla_target: Unable to send command to target\n");
5865 ql_dbg(ql_dbg_tgt, vha, 0xe05f,
5866 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
5867 qlt_send_term_exchange(rsp->qpair, NULL,
5871 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5872 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5874 qlt_send_busy(rsp->qpair, atio,
5878 ql_dbg(ql_dbg_tgt, vha, 0xe060,
5879 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5881 qlt_send_busy(rsp->qpair, atio,
5889 case CONTINUE_TGT_IO_TYPE:
5891 struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
5893 qlt_do_ctio_completion(vha, rsp, entry->handle,
5894 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5901 struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
5903 qlt_do_ctio_completion(vha, rsp, entry->handle,
5904 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
5909 case IMMED_NOTIFY_TYPE:
5910 ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n");
5911 qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt);
5914 case NOTIFY_ACK_TYPE:
5915 if (tgt->notify_ack_expected > 0) {
5916 struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
5918 ql_dbg(ql_dbg_tgt, vha, 0xe036,
5919 "NOTIFY_ACK seq %08x status %x\n",
5920 le16_to_cpu(entry->u.isp2x.seq_id),
5921 le16_to_cpu(entry->u.isp2x.status));
5922 tgt->notify_ack_expected--;
5923 if (entry->u.isp2x.status !=
5924 cpu_to_le16(NOTIFY_ACK_SUCCESS)) {
5925 ql_dbg(ql_dbg_tgt, vha, 0xe061,
5926 "qla_target(%d): NOTIFY_ACK "
5927 "failed %x\n", vha->vp_idx,
5928 le16_to_cpu(entry->u.isp2x.status));
5931 ql_dbg(ql_dbg_tgt, vha, 0xe062,
5932 "qla_target(%d): Unexpected NOTIFY_ACK received\n",
5937 case ABTS_RECV_24XX:
5938 ql_dbg(ql_dbg_tgt, vha, 0xe037,
5939 "ABTS_RECV_24XX: instance %d\n", vha->vp_idx);
5940 qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt);
5943 case ABTS_RESP_24XX:
5944 if (tgt->abts_resp_expected > 0) {
5945 qlt_handle_abts_completion(vha, rsp, pkt);
5947 ql_dbg(ql_dbg_tgt, vha, 0xe064,
5948 "qla_target(%d): Unexpected ABTS_RESP_24XX "
5949 "received\n", vha->vp_idx);
5954 ql_dbg(ql_dbg_tgt, vha, 0xe065,
5955 "qla_target(%d): Received unknown response pkt "
5956 "type %x\n", vha->vp_idx, pkt->entry_type);
5963 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5965 void qlt_async_event(uint16_t code, struct scsi_qla_host *vha,
5968 struct qla_hw_data *ha = vha->hw;
5969 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5972 if (!tgt || tgt->tgt_stop || tgt->tgt_stopped)
5975 if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) &&
5979 * In tgt_stop mode we also should allow all requests to pass.
5980 * Otherwise, some commands can stuck.
5985 case MBA_RESET: /* Reset */
5986 case MBA_SYSTEM_ERR: /* System Error */
5987 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
5988 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
5989 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a,
5990 "qla_target(%d): System error async event %#x "
5991 "occurred", vha->vp_idx, code);
5993 case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */
5994 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5999 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b,
6000 "qla_target(%d): Async LOOP_UP occurred "
6001 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx,
6002 mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
6003 if (tgt->link_reinit_iocb_pending) {
6004 qlt_send_notify_ack(ha->base_qpair,
6005 &tgt->link_reinit_iocb,
6007 tgt->link_reinit_iocb_pending = 0;
6012 case MBA_LIP_OCCURRED:
6015 case MBA_RSCN_UPDATE:
6016 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c,
6017 "qla_target(%d): Async event %#x occurred "
6018 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code,
6019 mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
6022 case MBA_REJECTED_FCP_CMD:
6023 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017,
6024 "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)",
6026 mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
6028 if (mailbox[3] == 1) {
6029 /* exchange starvation. */
6030 vha->hw->exch_starvation++;
6031 if (vha->hw->exch_starvation > 5) {
6032 ql_log(ql_log_warn, vha, 0xd03a,
6033 "Exchange starvation-. Resetting RISC\n");
6035 vha->hw->exch_starvation = 0;
6036 if (IS_P3P_TYPE(vha->hw))
6037 set_bit(FCOE_CTX_RESET_NEEDED,
6040 set_bit(ISP_ABORT_NEEDED,
6042 qla2xxx_wake_dpc(vha);
6047 case MBA_PORT_UPDATE:
6048 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d,
6049 "qla_target(%d): Port update async event %#x "
6050 "occurred: updating the ports database (m[0]=%x, m[1]=%x, "
6051 "m[2]=%x, m[3]=%x)", vha->vp_idx, code,
6052 mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
6054 login_code = mailbox[2];
6055 if (login_code == 0x4) {
6056 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e,
6057 "Async MB 2: Got PLOGI Complete\n");
6058 vha->hw->exch_starvation = 0;
6059 } else if (login_code == 0x7)
6060 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f,
6061 "Async MB 2: Port Logged Out\n");
6069 static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha,
6072 fc_port_t *fcport, *tfcp, *del;
6074 unsigned long flags;
6077 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6079 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f,
6080 "qla_target(%d): Allocation of tmp FC port failed",
6085 fcport->loop_id = loop_id;
6087 rc = qla24xx_gpdb_wait(vha, fcport, 0);
6088 if (rc != QLA_SUCCESS) {
6089 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070,
6090 "qla_target(%d): Failed to retrieve fcport "
6091 "information -- get_port_database() returned %x "
6092 "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id);
6098 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6099 tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1);
6102 tfcp->d_id = fcport->d_id;
6103 tfcp->port_type = fcport->port_type;
6104 tfcp->supported_classes = fcport->supported_classes;
6105 tfcp->flags |= fcport->flags;
6106 tfcp->scan_state = QLA_FCPORT_FOUND;
6111 if (vha->hw->current_topology == ISP_CFG_F)
6112 fcport->flags |= FCF_FABRIC_DEVICE;
6114 list_add_tail(&fcport->list, &vha->vp_fcports);
6115 if (!IS_SW_RESV_ADDR(fcport->d_id))
6116 vha->fcport_count++;
6117 fcport->login_gen++;
6118 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
6119 fcport->login_succ = 1;
6123 fcport->deleted = 0;
6124 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6126 switch (vha->host->active_mode) {
6127 case MODE_INITIATOR:
6130 if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) {
6131 qla24xx_sched_upd_fcport(fcport);
6133 ql_dbg(ql_dbg_disc, vha, 0x20ff,
6134 "%s %d %8phC post gpsc fcp_cnt %d\n",
6135 __func__, __LINE__, fcport->port_name, vha->fcport_count);
6136 qla24xx_post_gpsc_work(vha, fcport);
6146 qla2x00_free_fcport(del);
6151 /* Must be called under tgt_mutex */
6152 static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *vha,
6155 struct fc_port *sess = NULL;
6156 fc_port_t *fcport = NULL;
6157 int rc, global_resets;
6158 uint16_t loop_id = 0;
6160 if (s_id.domain == 0xFF && s_id.area == 0xFC) {
6162 * This is Domain Controller, so it should be
6163 * OK to drop SCSI commands from it.
6165 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042,
6166 "Unable to find initiator with S_ID %x:%x:%x",
6167 s_id.domain, s_id.area, s_id.al_pa);
6171 mutex_lock(&vha->vha_tgt.tgt_mutex);
6175 atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count);
6177 rc = qla24xx_get_loop_id(vha, s_id, &loop_id);
6179 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6181 ql_log(ql_log_info, vha, 0xf071,
6182 "qla_target(%d): Unable to find "
6183 "initiator with S_ID %x:%x:%x",
6184 vha->vp_idx, s_id.domain, s_id.area, s_id.al_pa);
6186 if (rc == -ENOENT) {
6187 qlt_port_logo_t logo;
6189 logo.id = be_to_port_id(s_id);
6191 qlt_send_first_logo(vha, &logo);
6197 fcport = qlt_get_port_database(vha, loop_id);
6199 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6203 if (global_resets !=
6204 atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) {
6205 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043,
6206 "qla_target(%d): global reset during session discovery "
6207 "(counter was %d, new %d), retrying", vha->vp_idx,
6209 atomic_read(&vha->vha_tgt.
6210 qla_tgt->tgt_global_resets_count));
6214 sess = qlt_create_sess(vha, fcport, true);
6216 mutex_unlock(&vha->vha_tgt.tgt_mutex);
6221 static void qlt_abort_work(struct qla_tgt *tgt,
6222 struct qla_tgt_sess_work_param *prm)
6224 struct scsi_qla_host *vha = tgt->vha;
6225 struct qla_hw_data *ha = vha->hw;
6226 struct fc_port *sess = NULL;
6227 unsigned long flags = 0, flags2 = 0;
6231 spin_lock_irqsave(&ha->tgt.sess_lock, flags2);
6236 s_id = le_id_to_be(prm->abts.fcp_hdr_le.s_id);
6238 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
6240 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6242 sess = qlt_make_local_sess(vha, s_id);
6243 /* sess has got an extra creation ref */
6245 spin_lock_irqsave(&ha->tgt.sess_lock, flags2);
6249 if (sess->deleted) {
6254 if (!kref_get_unless_zero(&sess->sess_kref)) {
6255 ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c,
6256 "%s: kref_get fail %8phC \n",
6257 __func__, sess->port_name);
6263 rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess);
6264 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6266 ha->tgt.tgt_ops->put_sess(sess);
6273 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
6276 spin_lock_irqsave(&ha->hardware_lock, flags);
6277 qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts,
6278 FCP_TMF_REJECTED, false);
6279 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6282 static void qlt_tmr_work(struct qla_tgt *tgt,
6283 struct qla_tgt_sess_work_param *prm)
6285 struct atio_from_isp *a = &prm->tm_iocb2;
6286 struct scsi_qla_host *vha = tgt->vha;
6287 struct qla_hw_data *ha = vha->hw;
6288 struct fc_port *sess;
6289 unsigned long flags;
6296 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
6301 s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id;
6302 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
6304 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6306 sess = qlt_make_local_sess(vha, s_id);
6307 /* sess has got an extra creation ref */
6309 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
6313 if (sess->deleted) {
6317 if (!kref_get_unless_zero(&sess->sess_kref)) {
6318 ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020,
6319 "%s: kref_get fail %8phC\n",
6320 __func__, sess->port_name);
6326 fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
6328 scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
6330 rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
6331 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6333 ha->tgt.tgt_ops->put_sess(sess);
6340 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
6342 qlt_send_term_exchange(ha->base_qpair, NULL, &prm->tm_iocb2, 1, 0);
6345 static void qlt_sess_work_fn(struct work_struct *work)
6347 struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work);
6348 struct scsi_qla_host *vha = tgt->vha;
6349 unsigned long flags;
6351 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt);
6353 spin_lock_irqsave(&tgt->sess_work_lock, flags);
6354 while (!list_empty(&tgt->sess_works_list)) {
6355 struct qla_tgt_sess_work_param *prm = list_entry(
6356 tgt->sess_works_list.next, typeof(*prm),
6357 sess_works_list_entry);
6360 * This work can be scheduled on several CPUs at time, so we
6361 * must delete the entry to eliminate double processing
6363 list_del(&prm->sess_works_list_entry);
6365 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
6367 switch (prm->type) {
6368 case QLA_TGT_SESS_WORK_ABORT:
6369 qlt_abort_work(tgt, prm);
6371 case QLA_TGT_SESS_WORK_TM:
6372 qlt_tmr_work(tgt, prm);
6379 spin_lock_irqsave(&tgt->sess_work_lock, flags);
6383 spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
6386 /* Must be called under tgt_host_action_mutex */
6387 int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha)
6389 struct qla_tgt *tgt;
6391 struct qla_qpair_hint *h;
6393 if (!QLA_TGT_MODE_ENABLED())
6396 if (!IS_TGT_MODE_CAPABLE(ha)) {
6397 ql_log(ql_log_warn, base_vha, 0xe070,
6398 "This adapter does not support target mode.\n");
6402 ql_dbg(ql_dbg_tgt, base_vha, 0xe03b,
6403 "Registering target for host %ld(%p).\n", base_vha->host_no, ha);
6405 BUG_ON(base_vha->vha_tgt.qla_tgt != NULL);
6407 tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL);
6409 ql_dbg(ql_dbg_tgt, base_vha, 0xe066,
6410 "Unable to allocate struct qla_tgt\n");
6414 tgt->qphints = kcalloc(ha->max_qpairs + 1,
6415 sizeof(struct qla_qpair_hint),
6417 if (!tgt->qphints) {
6419 ql_log(ql_log_warn, base_vha, 0x0197,
6420 "Unable to allocate qpair hints.\n");
6424 if (!(base_vha->host->hostt->supported_mode & MODE_TARGET))
6425 base_vha->host->hostt->supported_mode |= MODE_TARGET;
6427 rc = btree_init64(&tgt->lun_qpair_map);
6429 kfree(tgt->qphints);
6431 ql_log(ql_log_info, base_vha, 0x0198,
6432 "Unable to initialize lun_qpair_map btree\n");
6435 h = &tgt->qphints[0];
6436 h->qpair = ha->base_qpair;
6437 INIT_LIST_HEAD(&h->hint_elem);
6438 h->cpuid = ha->base_qpair->cpuid;
6439 list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list);
6441 for (i = 0; i < ha->max_qpairs; i++) {
6442 unsigned long flags;
6444 struct qla_qpair *qpair = ha->queue_pair_map[i];
6446 h = &tgt->qphints[i + 1];
6447 INIT_LIST_HEAD(&h->hint_elem);
6450 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
6451 list_add_tail(&h->hint_elem, &qpair->hints_list);
6452 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
6453 h->cpuid = qpair->cpuid;
6458 tgt->vha = base_vha;
6459 init_waitqueue_head(&tgt->waitQ);
6460 INIT_LIST_HEAD(&tgt->del_sess_list);
6461 spin_lock_init(&tgt->sess_work_lock);
6462 INIT_WORK(&tgt->sess_work, qlt_sess_work_fn);
6463 INIT_LIST_HEAD(&tgt->sess_works_list);
6464 atomic_set(&tgt->tgt_global_resets_count, 0);
6466 base_vha->vha_tgt.qla_tgt = tgt;
6468 ql_dbg(ql_dbg_tgt, base_vha, 0xe067,
6469 "qla_target(%d): using 64 Bit PCI addressing",
6472 tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3);
6474 mutex_lock(&qla_tgt_mutex);
6475 list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist);
6476 mutex_unlock(&qla_tgt_mutex);
6478 if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target)
6479 ha->tgt.tgt_ops->add_target(base_vha);
6484 /* Must be called under tgt_host_action_mutex */
6485 int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha)
6487 if (!vha->vha_tgt.qla_tgt)
6490 if (vha->fc_vport) {
6491 qlt_release(vha->vha_tgt.qla_tgt);
6495 /* free left over qfull cmds */
6496 qlt_init_term_exchange(vha);
6498 ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)",
6500 qlt_release(vha->vha_tgt.qla_tgt);
6505 void qla_remove_hostmap(struct qla_hw_data *ha)
6507 struct scsi_qla_host *node;
6510 btree_for_each_safe32(&ha->host_map, key, node)
6511 btree_remove32(&ha->host_map, key);
6513 btree_destroy32(&ha->host_map);
6516 static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn,
6519 pr_debug("qla2xxx HW vha->node_name: %8phC\n", vha->node_name);
6520 pr_debug("qla2xxx HW vha->port_name: %8phC\n", vha->port_name);
6521 put_unaligned_be64(wwpn, b);
6522 pr_debug("qla2xxx passed configfs WWPN: %8phC\n", b);
6526 * qlt_lport_register - register lport with external module
6528 * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
6529 * @phys_wwpn: physical port WWPN
6530 * @npiv_wwpn: NPIV WWPN
6531 * @npiv_wwnn: NPIV WWNN
6532 * @callback: lport initialization callback for tcm_qla2xxx code
6534 int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn,
6535 u64 npiv_wwpn, u64 npiv_wwnn,
6536 int (*callback)(struct scsi_qla_host *, void *, u64, u64))
6538 struct qla_tgt *tgt;
6539 struct scsi_qla_host *vha;
6540 struct qla_hw_data *ha;
6541 struct Scsi_Host *host;
6542 unsigned long flags;
6546 mutex_lock(&qla_tgt_mutex);
6547 list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) {
6555 if (!(host->hostt->supported_mode & MODE_TARGET))
6558 if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
6561 spin_lock_irqsave(&ha->hardware_lock, flags);
6562 if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) {
6563 pr_debug("MODE_TARGET already active on qla2xxx(%d)\n",
6565 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6568 if (tgt->tgt_stop) {
6569 pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n",
6571 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6574 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6576 if (!scsi_host_get(host)) {
6577 ql_dbg(ql_dbg_tgt, vha, 0xe068,
6578 "Unable to scsi_host_get() for"
6579 " qla2xxx scsi_host\n");
6582 qlt_lport_dump(vha, phys_wwpn, b);
6584 if (memcmp(vha->port_name, b, WWN_SIZE)) {
6585 scsi_host_put(host);
6588 rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn);
6590 scsi_host_put(host);
6592 mutex_unlock(&qla_tgt_mutex);
6595 mutex_unlock(&qla_tgt_mutex);
6599 EXPORT_SYMBOL(qlt_lport_register);
6602 * qlt_lport_deregister - Degister lport
6604 * @vha: Registered scsi_qla_host pointer
6606 void qlt_lport_deregister(struct scsi_qla_host *vha)
6608 struct qla_hw_data *ha = vha->hw;
6609 struct Scsi_Host *sh = vha->host;
6611 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
6613 vha->vha_tgt.target_lport_ptr = NULL;
6614 ha->tgt.tgt_ops = NULL;
6616 * Release the Scsi_Host reference for the underlying qla2xxx host
6620 EXPORT_SYMBOL(qlt_lport_deregister);
6622 /* Must be called under HW lock */
6623 void qlt_set_mode(struct scsi_qla_host *vha)
6625 switch (vha->qlini_mode) {
6626 case QLA2XXX_INI_MODE_DISABLED:
6627 case QLA2XXX_INI_MODE_EXCLUSIVE:
6628 vha->host->active_mode = MODE_TARGET;
6630 case QLA2XXX_INI_MODE_ENABLED:
6631 vha->host->active_mode = MODE_INITIATOR;
6633 case QLA2XXX_INI_MODE_DUAL:
6634 vha->host->active_mode = MODE_DUAL;
6641 /* Must be called under HW lock */
6642 static void qlt_clear_mode(struct scsi_qla_host *vha)
6644 switch (vha->qlini_mode) {
6645 case QLA2XXX_INI_MODE_DISABLED:
6646 vha->host->active_mode = MODE_UNKNOWN;
6648 case QLA2XXX_INI_MODE_EXCLUSIVE:
6649 vha->host->active_mode = MODE_INITIATOR;
6651 case QLA2XXX_INI_MODE_ENABLED:
6652 case QLA2XXX_INI_MODE_DUAL:
6653 vha->host->active_mode = MODE_INITIATOR;
6661 * qla_tgt_enable_vha - NO LOCK HELD
6663 * host_reset, bring up w/ Target Mode Enabled
6666 qlt_enable_vha(struct scsi_qla_host *vha)
6668 struct qla_hw_data *ha = vha->hw;
6669 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
6670 unsigned long flags;
6671 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6674 ql_dbg(ql_dbg_tgt, vha, 0xe069,
6675 "Unable to locate qla_tgt pointer from"
6676 " struct qla_hw_data\n");
6680 if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
6683 if (ha->tgt.num_act_qpairs > ha->max_qpairs)
6684 ha->tgt.num_act_qpairs = ha->max_qpairs;
6685 spin_lock_irqsave(&ha->hardware_lock, flags);
6686 tgt->tgt_stopped = 0;
6688 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6690 mutex_lock(&ha->optrom_mutex);
6691 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021,
6694 qla24xx_disable_vp(vha);
6695 qla24xx_enable_vp(vha);
6697 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6698 qla2xxx_wake_dpc(base_vha);
6699 WARN_ON_ONCE(qla2x00_wait_for_hba_online(base_vha) !=
6702 mutex_unlock(&ha->optrom_mutex);
6704 EXPORT_SYMBOL(qlt_enable_vha);
6707 * qla_tgt_disable_vha - NO LOCK HELD
6709 * Disable Target Mode and reset the adapter
6711 static void qlt_disable_vha(struct scsi_qla_host *vha)
6713 struct qla_hw_data *ha = vha->hw;
6714 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
6715 unsigned long flags;
6718 ql_dbg(ql_dbg_tgt, vha, 0xe06a,
6719 "Unable to locate qla_tgt pointer from"
6720 " struct qla_hw_data\n");
6725 spin_lock_irqsave(&ha->hardware_lock, flags);
6726 qlt_clear_mode(vha);
6727 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6729 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6730 qla2xxx_wake_dpc(vha);
6733 * We are expecting the offline state.
6734 * QLA_FUNCTION_FAILED means that adapter is offline.
6736 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
6737 ql_dbg(ql_dbg_tgt, vha, 0xe081,
6738 "adapter is offline\n");
6742 * Called from qla_init.c:qla24xx_vport_create() contex to setup
6743 * the target mode specific struct scsi_qla_host and struct qla_hw_data
6747 qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha)
6749 vha->vha_tgt.qla_tgt = NULL;
6751 mutex_init(&vha->vha_tgt.tgt_mutex);
6752 mutex_init(&vha->vha_tgt.tgt_host_action_mutex);
6754 qlt_clear_mode(vha);
6757 * NOTE: Currently the value is kept the same for <24xx and
6758 * >=24xx ISPs. If it is necessary to change it,
6759 * the check should be added for specific ISPs,
6760 * assigning the value appropriately.
6762 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
6764 qlt_add_target(ha, vha);
6768 qlt_rff_id(struct scsi_qla_host *vha)
6772 * FC-4 Feature bit 0 indicates target functionality to the name server.
6774 if (qla_tgt_mode_enabled(vha)) {
6775 fc4_feature = BIT_0;
6776 } else if (qla_ini_mode_enabled(vha)) {
6777 fc4_feature = BIT_1;
6778 } else if (qla_dual_mode_enabled(vha))
6779 fc4_feature = BIT_0 | BIT_1;
6785 * qlt_init_atio_q_entries() - Initializes ATIO queue entries.
6788 * Beginning of ATIO ring has initialization control block already built
6789 * by nvram config routine.
6791 * Returns 0 on success.
6794 qlt_init_atio_q_entries(struct scsi_qla_host *vha)
6796 struct qla_hw_data *ha = vha->hw;
6798 struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring;
6800 if (qla_ini_mode_enabled(vha))
6803 for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) {
6804 pkt->u.raw.signature = cpu_to_le32(ATIO_PROCESSED);
6811 * qlt_24xx_process_atio_queue() - Process ATIO queue entries.
6812 * @ha: SCSI driver HA context
6815 qlt_24xx_process_atio_queue(struct scsi_qla_host *vha, uint8_t ha_locked)
6817 struct qla_hw_data *ha = vha->hw;
6818 struct atio_from_isp *pkt;
6821 if (!ha->flags.fw_started)
6824 while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) ||
6825 fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) {
6826 pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
6827 cnt = pkt->u.raw.entry_count;
6829 if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) {
6831 * This packet is corrupted. The header + payload
6832 * can not be trusted. There is no point in passing
6835 ql_log(ql_log_warn, vha, 0xd03c,
6836 "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n",
6837 &pkt->u.isp24.fcp_hdr.s_id,
6838 be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id),
6839 pkt->u.isp24.exchange_addr, pkt);
6841 adjust_corrupted_atio(pkt);
6842 qlt_send_term_exchange(ha->base_qpair, NULL, pkt,
6845 qlt_24xx_atio_pkt_all_vps(vha,
6846 (struct atio_from_isp *)pkt, ha_locked);
6849 for (i = 0; i < cnt; i++) {
6850 ha->tgt.atio_ring_index++;
6851 if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) {
6852 ha->tgt.atio_ring_index = 0;
6853 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
6855 ha->tgt.atio_ring_ptr++;
6857 pkt->u.raw.signature = cpu_to_le32(ATIO_PROCESSED);
6858 pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
6863 /* Adjust ring index */
6864 wrt_reg_dword(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index);
6868 qlt_24xx_config_rings(struct scsi_qla_host *vha)
6870 struct qla_hw_data *ha = vha->hw;
6871 struct qla_msix_entry *msix = &ha->msix_entries[2];
6872 struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb;
6874 if (!QLA_TGT_MODE_ENABLED())
6877 wrt_reg_dword(ISP_ATIO_Q_IN(vha), 0);
6878 wrt_reg_dword(ISP_ATIO_Q_OUT(vha), 0);
6879 rd_reg_dword(ISP_ATIO_Q_OUT(vha));
6881 if (ha->flags.msix_enabled) {
6882 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
6883 if (IS_QLA2071(ha)) {
6884 /* 4 ports Baker: Enable Interrupt Handshake */
6886 icb->firmware_options_2 |= cpu_to_le32(BIT_26);
6888 icb->msix_atio = cpu_to_le16(msix->entry);
6889 icb->firmware_options_2 &= cpu_to_le32(~BIT_26);
6891 ql_dbg(ql_dbg_init, vha, 0xf072,
6892 "Registering ICB vector 0x%x for atio que.\n",
6897 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
6899 icb->firmware_options_2 |= cpu_to_le32(BIT_26);
6900 ql_dbg(ql_dbg_init, vha, 0xf072,
6901 "%s: Use INTx for ATIOQ.\n", __func__);
6907 qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv)
6909 struct qla_hw_data *ha = vha->hw;
6912 if (!QLA_TGT_MODE_ENABLED())
6915 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
6916 if (!ha->tgt.saved_set) {
6917 /* We save only once */
6918 ha->tgt.saved_exchange_count = nv->exchange_count;
6919 ha->tgt.saved_firmware_options_1 =
6920 nv->firmware_options_1;
6921 ha->tgt.saved_firmware_options_2 =
6922 nv->firmware_options_2;
6923 ha->tgt.saved_firmware_options_3 =
6924 nv->firmware_options_3;
6925 ha->tgt.saved_set = 1;
6928 if (qla_tgt_mode_enabled(vha))
6929 nv->exchange_count = cpu_to_le16(0xFFFF);
6931 nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
6933 /* Enable target mode */
6934 nv->firmware_options_1 |= cpu_to_le32(BIT_4);
6936 /* Disable ini mode, if requested */
6937 if (qla_tgt_mode_enabled(vha))
6938 nv->firmware_options_1 |= cpu_to_le32(BIT_5);
6940 /* Disable Full Login after LIP */
6941 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
6942 /* Enable initial LIP */
6943 nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
6944 if (ql2xtgt_tape_enable)
6945 /* Enable FC Tape support */
6946 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6948 /* Disable FC Tape support */
6949 nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
6951 /* Disable Full Login after LIP */
6952 nv->host_p &= cpu_to_le32(~BIT_10);
6955 * clear BIT 15 explicitly as we have seen at least
6956 * a couple of instances where this was set and this
6957 * was causing the firmware to not be initialized.
6959 nv->firmware_options_1 &= cpu_to_le32(~BIT_15);
6960 /* Enable target PRLI control */
6961 nv->firmware_options_2 |= cpu_to_le32(BIT_14);
6963 if (IS_QLA25XX(ha)) {
6964 /* Change Loop-prefer to Pt-Pt */
6965 tmp = ~(BIT_4|BIT_5|BIT_6);
6966 nv->firmware_options_2 &= cpu_to_le32(tmp);
6968 nv->firmware_options_2 |= cpu_to_le32(tmp);
6971 if (ha->tgt.saved_set) {
6972 nv->exchange_count = ha->tgt.saved_exchange_count;
6973 nv->firmware_options_1 =
6974 ha->tgt.saved_firmware_options_1;
6975 nv->firmware_options_2 =
6976 ha->tgt.saved_firmware_options_2;
6977 nv->firmware_options_3 =
6978 ha->tgt.saved_firmware_options_3;
6983 if (ha->base_qpair->enable_class_2) {
6984 if (vha->flags.init_done)
6985 fc_host_supported_classes(vha->host) =
6986 FC_COS_CLASS2 | FC_COS_CLASS3;
6988 nv->firmware_options_2 |= cpu_to_le32(BIT_8);
6990 if (vha->flags.init_done)
6991 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
6993 nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
6998 qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha,
6999 struct init_cb_24xx *icb)
7001 struct qla_hw_data *ha = vha->hw;
7003 if (!QLA_TGT_MODE_ENABLED())
7006 if (ha->tgt.node_name_set) {
7007 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
7008 icb->firmware_options_1 |= cpu_to_le32(BIT_14);
7013 qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv)
7015 struct qla_hw_data *ha = vha->hw;
7018 if (!QLA_TGT_MODE_ENABLED())
7021 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
7022 if (!ha->tgt.saved_set) {
7023 /* We save only once */
7024 ha->tgt.saved_exchange_count = nv->exchange_count;
7025 ha->tgt.saved_firmware_options_1 =
7026 nv->firmware_options_1;
7027 ha->tgt.saved_firmware_options_2 =
7028 nv->firmware_options_2;
7029 ha->tgt.saved_firmware_options_3 =
7030 nv->firmware_options_3;
7031 ha->tgt.saved_set = 1;
7034 if (qla_tgt_mode_enabled(vha))
7035 nv->exchange_count = cpu_to_le16(0xFFFF);
7037 nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
7039 /* Enable target mode */
7040 nv->firmware_options_1 |= cpu_to_le32(BIT_4);
7042 /* Disable ini mode, if requested */
7043 if (qla_tgt_mode_enabled(vha))
7044 nv->firmware_options_1 |= cpu_to_le32(BIT_5);
7045 /* Disable Full Login after LIP */
7046 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7047 /* Enable initial LIP */
7048 nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
7050 * clear BIT 15 explicitly as we have seen at
7051 * least a couple of instances where this was set
7052 * and this was causing the firmware to not be
7055 nv->firmware_options_1 &= cpu_to_le32(~BIT_15);
7056 if (ql2xtgt_tape_enable)
7057 /* Enable FC tape support */
7058 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7060 /* Disable FC tape support */
7061 nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
7063 /* Disable Full Login after LIP */
7064 nv->host_p &= cpu_to_le32(~BIT_10);
7065 /* Enable target PRLI control */
7066 nv->firmware_options_2 |= cpu_to_le32(BIT_14);
7068 /* Change Loop-prefer to Pt-Pt */
7069 tmp = ~(BIT_4|BIT_5|BIT_6);
7070 nv->firmware_options_2 &= cpu_to_le32(tmp);
7072 nv->firmware_options_2 |= cpu_to_le32(tmp);
7074 if (ha->tgt.saved_set) {
7075 nv->exchange_count = ha->tgt.saved_exchange_count;
7076 nv->firmware_options_1 =
7077 ha->tgt.saved_firmware_options_1;
7078 nv->firmware_options_2 =
7079 ha->tgt.saved_firmware_options_2;
7080 nv->firmware_options_3 =
7081 ha->tgt.saved_firmware_options_3;
7086 if (ha->base_qpair->enable_class_2) {
7087 if (vha->flags.init_done)
7088 fc_host_supported_classes(vha->host) =
7089 FC_COS_CLASS2 | FC_COS_CLASS3;
7091 nv->firmware_options_2 |= cpu_to_le32(BIT_8);
7093 if (vha->flags.init_done)
7094 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
7096 nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
7101 qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha,
7102 struct init_cb_81xx *icb)
7104 struct qla_hw_data *ha = vha->hw;
7106 if (!QLA_TGT_MODE_ENABLED())
7109 if (ha->tgt.node_name_set) {
7110 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
7111 icb->firmware_options_1 |= cpu_to_le32(BIT_14);
7116 qlt_83xx_iospace_config(struct qla_hw_data *ha)
7118 if (!QLA_TGT_MODE_ENABLED())
7121 ha->msix_count += 1; /* For ATIO Q */
7126 qlt_modify_vp_config(struct scsi_qla_host *vha,
7127 struct vp_config_entry_24xx *vpmod)
7129 /* enable target mode. Bit5 = 1 => disable */
7130 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7131 vpmod->options_idx1 &= ~BIT_5;
7133 /* Disable ini mode, if requested. bit4 = 1 => disable */
7134 if (qla_tgt_mode_enabled(vha))
7135 vpmod->options_idx1 &= ~BIT_4;
7139 qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha)
7141 mutex_init(&base_vha->vha_tgt.tgt_mutex);
7142 if (!QLA_TGT_MODE_ENABLED())
7145 if ((ql2xenablemsix == 0) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
7147 ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in;
7148 ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out;
7150 ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in;
7151 ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out;
7154 mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex);
7156 INIT_LIST_HEAD(&base_vha->unknown_atio_list);
7157 INIT_DELAYED_WORK(&base_vha->unknown_atio_work,
7158 qlt_unknown_atio_work_fn);
7160 qlt_clear_mode(base_vha);
7162 qlt_update_vp_map(base_vha, SET_VP_IDX);
7166 qla83xx_msix_atio_q(int irq, void *dev_id)
7168 struct rsp_que *rsp;
7169 scsi_qla_host_t *vha;
7170 struct qla_hw_data *ha;
7171 unsigned long flags;
7173 rsp = (struct rsp_que *) dev_id;
7175 vha = pci_get_drvdata(ha->pdev);
7177 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
7179 qlt_24xx_process_atio_queue(vha, 0);
7181 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
7187 qlt_handle_abts_recv_work(struct work_struct *work)
7189 struct qla_tgt_sess_op *op = container_of(work,
7190 struct qla_tgt_sess_op, work);
7191 scsi_qla_host_t *vha = op->vha;
7192 struct qla_hw_data *ha = vha->hw;
7193 unsigned long flags;
7195 if (qla2x00_reset_active(vha) ||
7196 (op->chip_reset != ha->base_qpair->chip_reset))
7199 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
7200 qlt_24xx_process_atio_queue(vha, 0);
7201 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
7203 spin_lock_irqsave(&ha->hardware_lock, flags);
7204 qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio);
7205 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7211 qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp,
7214 struct qla_tgt_sess_op *op;
7216 op = kzalloc(sizeof(*op), GFP_ATOMIC);
7219 /* do not reach for ATIO queue here. This is best effort err
7220 * recovery at this point.
7222 qlt_response_pkt_all_vps(vha, rsp, pkt);
7226 memcpy(&op->atio, pkt, sizeof(*pkt));
7228 op->chip_reset = vha->hw->base_qpair->chip_reset;
7230 INIT_WORK(&op->work, qlt_handle_abts_recv_work);
7231 queue_work(qla_tgt_wq, &op->work);
7236 qlt_mem_alloc(struct qla_hw_data *ha)
7238 if (!QLA_TGT_MODE_ENABLED())
7241 ha->tgt.tgt_vp_map = kcalloc(MAX_MULTI_ID_FABRIC,
7242 sizeof(struct qla_tgt_vp_map),
7244 if (!ha->tgt.tgt_vp_map)
7247 ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev,
7248 (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp),
7249 &ha->tgt.atio_dma, GFP_KERNEL);
7250 if (!ha->tgt.atio_ring) {
7251 kfree(ha->tgt.tgt_vp_map);
7258 qlt_mem_free(struct qla_hw_data *ha)
7260 if (!QLA_TGT_MODE_ENABLED())
7263 if (ha->tgt.atio_ring) {
7264 dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) *
7265 sizeof(struct atio_from_isp), ha->tgt.atio_ring,
7268 ha->tgt.atio_ring = NULL;
7269 ha->tgt.atio_dma = 0;
7270 kfree(ha->tgt.tgt_vp_map);
7271 ha->tgt.tgt_vp_map = NULL;
7274 /* vport_slock to be held by the caller */
7276 qlt_update_vp_map(struct scsi_qla_host *vha, int cmd)
7282 key = vha->d_id.b24;
7286 if (!QLA_TGT_MODE_ENABLED())
7288 vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha;
7291 slot = btree_lookup32(&vha->hw->host_map, key);
7293 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018,
7294 "Save vha in host_map %p %06x\n", vha, key);
7295 rc = btree_insert32(&vha->hw->host_map,
7296 key, vha, GFP_ATOMIC);
7298 ql_log(ql_log_info, vha, 0xd03e,
7299 "Unable to insert s_id into host_map: %06x\n",
7303 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019,
7304 "replace existing vha in host_map %p %06x\n", vha, key);
7305 btree_update32(&vha->hw->host_map, key, vha);
7308 if (!QLA_TGT_MODE_ENABLED())
7310 vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL;
7313 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a,
7314 "clear vha in host_map %p %06x\n", vha, key);
7315 slot = btree_lookup32(&vha->hw->host_map, key);
7317 btree_remove32(&vha->hw->host_map, key);
7323 void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id)
7326 if (!vha->d_id.b24) {
7328 qlt_update_vp_map(vha, SET_AL_PA);
7329 } else if (vha->d_id.b24 != id.b24) {
7330 qlt_update_vp_map(vha, RESET_AL_PA);
7332 qlt_update_vp_map(vha, SET_AL_PA);
7336 static int __init qlt_parse_ini_mode(void)
7338 if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0)
7339 ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE;
7340 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0)
7341 ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED;
7342 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0)
7343 ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED;
7344 else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0)
7345 ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL;
7352 int __init qlt_init(void)
7356 BUILD_BUG_ON(sizeof(struct ctio7_to_24xx) != 64);
7357 BUILD_BUG_ON(sizeof(struct ctio_to_2xxx) != 64);
7359 if (!qlt_parse_ini_mode()) {
7360 ql_log(ql_log_fatal, NULL, 0xe06b,
7361 "qlt_parse_ini_mode() failed\n");
7365 if (!QLA_TGT_MODE_ENABLED())
7368 qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep",
7369 sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct
7370 qla_tgt_mgmt_cmd), 0, NULL);
7371 if (!qla_tgt_mgmt_cmd_cachep) {
7372 ql_log(ql_log_fatal, NULL, 0xd04b,
7373 "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
7377 qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep",
7378 sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t),
7381 if (!qla_tgt_plogi_cachep) {
7382 ql_log(ql_log_fatal, NULL, 0xe06d,
7383 "kmem_cache_create for qla_tgt_plogi_cachep failed\n");
7385 goto out_mgmt_cmd_cachep;
7388 qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab,
7389 mempool_free_slab, qla_tgt_mgmt_cmd_cachep);
7390 if (!qla_tgt_mgmt_cmd_mempool) {
7391 ql_log(ql_log_fatal, NULL, 0xe06e,
7392 "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
7394 goto out_plogi_cachep;
7397 qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0);
7399 ql_log(ql_log_fatal, NULL, 0xe06f,
7400 "alloc_workqueue for qla_tgt_wq failed\n");
7402 goto out_cmd_mempool;
7405 * Return 1 to signal that initiator-mode is being disabled
7407 return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0;
7410 mempool_destroy(qla_tgt_mgmt_cmd_mempool);
7412 kmem_cache_destroy(qla_tgt_plogi_cachep);
7413 out_mgmt_cmd_cachep:
7414 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep);
7420 if (!QLA_TGT_MODE_ENABLED())
7423 destroy_workqueue(qla_tgt_wq);
7424 mempool_destroy(qla_tgt_mgmt_cmd_mempool);
7425 kmem_cache_destroy(qla_tgt_plogi_cachep);
7426 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep);