2 * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx
4 * based on qla2x00t.c code:
6 * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
7 * Copyright (C) 2004 - 2005 Leonid Stoljar
8 * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
9 * Copyright (C) 2006 - 2010 ID7 Ltd.
11 * Forward port and refactoring to modern qla2xxx and target/configfs
13 * Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org>
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation, version 2
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/blkdev.h>
30 #include <linux/interrupt.h>
31 #include <linux/pci.h>
32 #include <linux/delay.h>
33 #include <linux/list.h>
34 #include <linux/workqueue.h>
35 #include <asm/unaligned.h>
36 #include <scsi/scsi.h>
37 #include <scsi/scsi_host.h>
38 #include <scsi/scsi_tcq.h>
39 #include <target/target_core_base.h>
40 #include <target/target_core_fabric.h>
43 #include "qla_target.h"
45 static int ql2xtgt_tape_enable
;
46 module_param(ql2xtgt_tape_enable
, int, S_IRUGO
|S_IWUSR
);
47 MODULE_PARM_DESC(ql2xtgt_tape_enable
,
48 "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER.");
50 static char *qlini_mode
= QLA2XXX_INI_MODE_STR_ENABLED
;
51 module_param(qlini_mode
, charp
, S_IRUGO
);
52 MODULE_PARM_DESC(qlini_mode
,
53 "Determines when initiator mode will be enabled. Possible values: "
54 "\"exclusive\" - initiator mode will be enabled on load, "
55 "disabled on enabling target mode and then on disabling target mode "
57 "\"disabled\" - initiator mode will never be enabled; "
58 "\"dual\" - Initiator Modes will be enabled. Target Mode can be activated "
60 "\"enabled\" (default) - initiator mode will always stay enabled.");
62 static int ql_dm_tgt_ex_pct
= 0;
63 module_param(ql_dm_tgt_ex_pct
, int, S_IRUGO
|S_IWUSR
);
64 MODULE_PARM_DESC(ql_dm_tgt_ex_pct
,
65 "For Dual Mode (qlini_mode=dual), this parameter determines "
66 "the percentage of exchanges/cmds FW will allocate resources "
70 module_param(ql2xuctrlirq
, int, 0644);
71 MODULE_PARM_DESC(ql2xuctrlirq
,
72 "User to control IRQ placement via smp_affinity."
73 "Valid with qlini_mode=disabled."
74 "1(default): enable");
76 int ql2x_ini_mode
= QLA2XXX_INI_MODE_EXCLUSIVE
;
78 static int temp_sam_status
= SAM_STAT_BUSY
;
81 * From scsi/fc/fc_fcp.h
83 enum fcp_resp_rsp_codes
{
85 FCP_DATA_LEN_INVALID
= 1,
86 FCP_CMND_FIELDS_INVALID
= 2,
87 FCP_DATA_PARAM_MISMATCH
= 3,
90 FCP_TMF_INVALID_LUN
= 9,
94 * fc_pri_ta from scsi/fc/fc_fcp.h
96 #define FCP_PTA_SIMPLE 0 /* simple task attribute */
97 #define FCP_PTA_HEADQ 1 /* head of queue task attribute */
98 #define FCP_PTA_ORDERED 2 /* ordered task attribute */
99 #define FCP_PTA_ACA 4 /* auto. contingent allegiance */
100 #define FCP_PTA_MASK 7 /* mask for task attribute field */
101 #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */
102 #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */
105 * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which
106 * must be called under HW lock and could unlock/lock it inside.
107 * It isn't an issue, since in the current implementation on the time when
108 * those functions are called:
110 * - Either context is IRQ and only IRQ handler can modify HW data,
111 * including rings related fields,
113 * - Or access to target mode variables from struct qla_tgt doesn't
114 * cross those functions boundaries, except tgt_stop, which
115 * additionally protected by irq_cmd_count.
117 /* Predefs for callbacks handed to qla2xxx LLD */
118 static void qlt_24xx_atio_pkt(struct scsi_qla_host
*ha
,
119 struct atio_from_isp
*pkt
, uint8_t);
120 static void qlt_response_pkt(struct scsi_qla_host
*ha
, struct rsp_que
*rsp
,
122 static int qlt_issue_task_mgmt(struct fc_port
*sess
, u64 lun
,
123 int fn
, void *iocb
, int flags
);
124 static void qlt_send_term_exchange(struct qla_qpair
*, struct qla_tgt_cmd
125 *cmd
, struct atio_from_isp
*atio
, int ha_locked
, int ul_abort
);
126 static void qlt_alloc_qfull_cmd(struct scsi_qla_host
*vha
,
127 struct atio_from_isp
*atio
, uint16_t status
, int qfull
);
128 static void qlt_disable_vha(struct scsi_qla_host
*vha
);
129 static void qlt_clear_tgt_db(struct qla_tgt
*tgt
);
130 static void qlt_send_notify_ack(struct qla_qpair
*qpair
,
131 struct imm_ntfy_from_isp
*ntfy
,
132 uint32_t add_flags
, uint16_t resp_code
, int resp_code_valid
,
133 uint16_t srr_flags
, uint16_t srr_reject_code
, uint8_t srr_explan
);
134 static void qlt_send_term_imm_notif(struct scsi_qla_host
*vha
,
135 struct imm_ntfy_from_isp
*imm
, int ha_locked
);
136 static struct fc_port
*qlt_create_sess(struct scsi_qla_host
*vha
,
137 fc_port_t
*fcport
, bool local
);
138 void qlt_unreg_sess(struct fc_port
*sess
);
139 static void qlt_24xx_handle_abts(struct scsi_qla_host
*,
140 struct abts_recv_from_24xx
*);
141 static void qlt_send_busy(struct qla_qpair
*, struct atio_from_isp
*,
147 static struct kmem_cache
*qla_tgt_mgmt_cmd_cachep
;
148 struct kmem_cache
*qla_tgt_plogi_cachep
;
149 static mempool_t
*qla_tgt_mgmt_cmd_mempool
;
150 static struct workqueue_struct
*qla_tgt_wq
;
151 static DEFINE_MUTEX(qla_tgt_mutex
);
152 static LIST_HEAD(qla_tgt_glist
);
154 static const char *prot_op_str(u32 prot_op
)
157 case TARGET_PROT_NORMAL
: return "NORMAL";
158 case TARGET_PROT_DIN_INSERT
: return "DIN_INSERT";
159 case TARGET_PROT_DOUT_INSERT
: return "DOUT_INSERT";
160 case TARGET_PROT_DIN_STRIP
: return "DIN_STRIP";
161 case TARGET_PROT_DOUT_STRIP
: return "DOUT_STRIP";
162 case TARGET_PROT_DIN_PASS
: return "DIN_PASS";
163 case TARGET_PROT_DOUT_PASS
: return "DOUT_PASS";
164 default: return "UNKNOWN";
168 /* This API intentionally takes dest as a parameter, rather than returning
169 * int value to avoid caller forgetting to issue wmb() after the store */
170 void qlt_do_generation_tick(struct scsi_qla_host
*vha
, int *dest
)
172 scsi_qla_host_t
*base_vha
= pci_get_drvdata(vha
->hw
->pdev
);
173 *dest
= atomic_inc_return(&base_vha
->generation_tick
);
178 /* Might release hw lock, then reaquire!! */
179 static inline int qlt_issue_marker(struct scsi_qla_host
*vha
, int vha_locked
)
181 /* Send marker if required */
182 if (unlikely(vha
->marker_needed
!= 0)) {
183 int rc
= qla2x00_issue_marker(vha
, vha_locked
);
184 if (rc
!= QLA_SUCCESS
) {
185 ql_dbg(ql_dbg_tgt
, vha
, 0xe03d,
186 "qla_target(%d): issue_marker() failed\n",
195 struct scsi_qla_host
*qlt_find_host_by_d_id(struct scsi_qla_host
*vha
,
198 struct scsi_qla_host
*host
;
201 if ((vha
->d_id
.b
.area
== d_id
[1]) && (vha
->d_id
.b
.domain
== d_id
[0]) &&
202 (vha
->d_id
.b
.al_pa
== d_id
[2]))
205 key
= (uint32_t)d_id
[0] << 16;
206 key
|= (uint32_t)d_id
[1] << 8;
207 key
|= (uint32_t)d_id
[2];
209 host
= btree_lookup32(&vha
->hw
->tgt
.host_map
, key
);
211 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf005,
212 "Unable to find host %06x\n", key
);
218 struct scsi_qla_host
*qlt_find_host_by_vp_idx(struct scsi_qla_host
*vha
,
221 struct qla_hw_data
*ha
= vha
->hw
;
223 if (vha
->vp_idx
== vp_idx
)
226 BUG_ON(ha
->tgt
.tgt_vp_map
== NULL
);
227 if (likely(test_bit(vp_idx
, ha
->vp_idx_map
)))
228 return ha
->tgt
.tgt_vp_map
[vp_idx
].vha
;
233 static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host
*vha
)
237 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
239 vha
->hw
->tgt
.num_pend_cmds
++;
240 if (vha
->hw
->tgt
.num_pend_cmds
> vha
->qla_stats
.stat_max_pend_cmds
)
241 vha
->qla_stats
.stat_max_pend_cmds
=
242 vha
->hw
->tgt
.num_pend_cmds
;
243 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
245 static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host
*vha
)
249 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
250 vha
->hw
->tgt
.num_pend_cmds
--;
251 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
255 static void qlt_queue_unknown_atio(scsi_qla_host_t
*vha
,
256 struct atio_from_isp
*atio
, uint8_t ha_locked
)
258 struct qla_tgt_sess_op
*u
;
259 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
263 ql_dbg(ql_dbg_async
, vha
, 0x502c,
264 "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped",
269 u
= kzalloc(sizeof(*u
), GFP_ATOMIC
);
274 memcpy(&u
->atio
, atio
, sizeof(*atio
));
275 INIT_LIST_HEAD(&u
->cmd_list
);
277 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
278 list_add_tail(&u
->cmd_list
, &vha
->unknown_atio_list
);
279 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
281 schedule_delayed_work(&vha
->unknown_atio_work
, 1);
287 qlt_send_term_exchange(vha
->hw
->base_qpair
, NULL
, atio
, ha_locked
, 0);
291 static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host
*vha
,
294 struct qla_tgt_sess_op
*u
, *t
;
295 scsi_qla_host_t
*host
;
296 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
300 list_for_each_entry_safe(u
, t
, &vha
->unknown_atio_list
, cmd_list
) {
302 ql_dbg(ql_dbg_async
, vha
, 0x502e,
303 "Freeing unknown %s %p, because of Abort\n",
305 qlt_send_term_exchange(vha
->hw
->base_qpair
, NULL
,
306 &u
->atio
, ha_locked
, 0);
310 host
= qlt_find_host_by_d_id(vha
, u
->atio
.u
.isp24
.fcp_hdr
.d_id
);
312 ql_dbg(ql_dbg_async
, vha
, 0x502f,
313 "Requeuing unknown ATIO_TYPE7 %p\n", u
);
314 qlt_24xx_atio_pkt(host
, &u
->atio
, ha_locked
);
315 } else if (tgt
->tgt_stop
) {
316 ql_dbg(ql_dbg_async
, vha
, 0x503a,
317 "Freeing unknown %s %p, because tgt is being stopped\n",
319 qlt_send_term_exchange(vha
->hw
->base_qpair
, NULL
,
320 &u
->atio
, ha_locked
, 0);
322 ql_dbg(ql_dbg_async
, vha
, 0x503d,
323 "Reschedule u %p, vha %p, host %p\n", u
, vha
, host
);
326 schedule_delayed_work(&vha
->unknown_atio_work
,
333 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
334 list_del(&u
->cmd_list
);
335 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
340 void qlt_unknown_atio_work_fn(struct work_struct
*work
)
342 struct scsi_qla_host
*vha
= container_of(to_delayed_work(work
),
343 struct scsi_qla_host
, unknown_atio_work
);
345 qlt_try_to_dequeue_unknown_atios(vha
, 0);
348 static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host
*vha
,
349 struct atio_from_isp
*atio
, uint8_t ha_locked
)
351 ql_dbg(ql_dbg_tgt
, vha
, 0xe072,
352 "%s: qla_target(%d): type %x ox_id %04x\n",
353 __func__
, vha
->vp_idx
, atio
->u
.raw
.entry_type
,
354 be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
));
356 switch (atio
->u
.raw
.entry_type
) {
359 struct scsi_qla_host
*host
= qlt_find_host_by_d_id(vha
,
360 atio
->u
.isp24
.fcp_hdr
.d_id
);
361 if (unlikely(NULL
== host
)) {
362 ql_dbg(ql_dbg_tgt
, vha
, 0xe03e,
363 "qla_target(%d): Received ATIO_TYPE7 "
364 "with unknown d_id %x:%x:%x\n", vha
->vp_idx
,
365 atio
->u
.isp24
.fcp_hdr
.d_id
[0],
366 atio
->u
.isp24
.fcp_hdr
.d_id
[1],
367 atio
->u
.isp24
.fcp_hdr
.d_id
[2]);
370 qlt_queue_unknown_atio(vha
, atio
, ha_locked
);
373 if (unlikely(!list_empty(&vha
->unknown_atio_list
)))
374 qlt_try_to_dequeue_unknown_atios(vha
, ha_locked
);
376 qlt_24xx_atio_pkt(host
, atio
, ha_locked
);
380 case IMMED_NOTIFY_TYPE
:
382 struct scsi_qla_host
*host
= vha
;
383 struct imm_ntfy_from_isp
*entry
=
384 (struct imm_ntfy_from_isp
*)atio
;
386 qlt_issue_marker(vha
, ha_locked
);
388 if ((entry
->u
.isp24
.vp_index
!= 0xFF) &&
389 (entry
->u
.isp24
.nport_handle
!= 0xFFFF)) {
390 host
= qlt_find_host_by_vp_idx(vha
,
391 entry
->u
.isp24
.vp_index
);
392 if (unlikely(!host
)) {
393 ql_dbg(ql_dbg_tgt
, vha
, 0xe03f,
394 "qla_target(%d): Received "
395 "ATIO (IMMED_NOTIFY_TYPE) "
396 "with unknown vp_index %d\n",
397 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
401 qlt_24xx_atio_pkt(host
, atio
, ha_locked
);
405 case VP_RPT_ID_IOCB_TYPE
:
406 qla24xx_report_id_acquisition(vha
,
407 (struct vp_rpt_id_entry_24xx
*)atio
);
412 struct abts_recv_from_24xx
*entry
=
413 (struct abts_recv_from_24xx
*)atio
;
414 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
418 if (unlikely(!host
)) {
419 ql_dbg(ql_dbg_tgt
, vha
, 0xe00a,
420 "qla_target(%d): Response pkt (ABTS_RECV_24XX) "
421 "received, with unknown vp_index %d\n",
422 vha
->vp_idx
, entry
->vp_index
);
426 spin_lock_irqsave(&host
->hw
->hardware_lock
, flags
);
427 qlt_24xx_handle_abts(host
, (struct abts_recv_from_24xx
*)atio
);
429 spin_unlock_irqrestore(&host
->hw
->hardware_lock
, flags
);
433 /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */
436 ql_dbg(ql_dbg_tgt
, vha
, 0xe040,
437 "qla_target(%d): Received unknown ATIO atio "
438 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
445 void qlt_response_pkt_all_vps(struct scsi_qla_host
*vha
,
446 struct rsp_que
*rsp
, response_t
*pkt
)
448 switch (pkt
->entry_type
) {
450 ql_dbg(ql_dbg_tgt
, vha
, 0xe073,
451 "qla_target(%d):%s: CRC2 Response pkt\n",
452 vha
->vp_idx
, __func__
);
455 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
456 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
458 if (unlikely(!host
)) {
459 ql_dbg(ql_dbg_tgt
, vha
, 0xe041,
460 "qla_target(%d): Response pkt (CTIO_TYPE7) "
461 "received, with unknown vp_index %d\n",
462 vha
->vp_idx
, entry
->vp_index
);
465 qlt_response_pkt(host
, rsp
, pkt
);
469 case IMMED_NOTIFY_TYPE
:
471 struct scsi_qla_host
*host
= vha
;
472 struct imm_ntfy_from_isp
*entry
=
473 (struct imm_ntfy_from_isp
*)pkt
;
475 host
= qlt_find_host_by_vp_idx(vha
, entry
->u
.isp24
.vp_index
);
476 if (unlikely(!host
)) {
477 ql_dbg(ql_dbg_tgt
, vha
, 0xe042,
478 "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
479 "received, with unknown vp_index %d\n",
480 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
483 qlt_response_pkt(host
, rsp
, pkt
);
487 case NOTIFY_ACK_TYPE
:
489 struct scsi_qla_host
*host
= vha
;
490 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
492 if (0xFF != entry
->u
.isp24
.vp_index
) {
493 host
= qlt_find_host_by_vp_idx(vha
,
494 entry
->u
.isp24
.vp_index
);
495 if (unlikely(!host
)) {
496 ql_dbg(ql_dbg_tgt
, vha
, 0xe043,
497 "qla_target(%d): Response "
498 "pkt (NOTIFY_ACK_TYPE) "
499 "received, with unknown "
500 "vp_index %d\n", vha
->vp_idx
,
501 entry
->u
.isp24
.vp_index
);
505 qlt_response_pkt(host
, rsp
, pkt
);
511 struct abts_recv_from_24xx
*entry
=
512 (struct abts_recv_from_24xx
*)pkt
;
513 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
515 if (unlikely(!host
)) {
516 ql_dbg(ql_dbg_tgt
, vha
, 0xe044,
517 "qla_target(%d): Response pkt "
518 "(ABTS_RECV_24XX) received, with unknown "
519 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
522 qlt_response_pkt(host
, rsp
, pkt
);
528 struct abts_resp_to_24xx
*entry
=
529 (struct abts_resp_to_24xx
*)pkt
;
530 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
532 if (unlikely(!host
)) {
533 ql_dbg(ql_dbg_tgt
, vha
, 0xe045,
534 "qla_target(%d): Response pkt "
535 "(ABTS_RECV_24XX) received, with unknown "
536 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
539 qlt_response_pkt(host
, rsp
, pkt
);
544 qlt_response_pkt(vha
, rsp
, pkt
);
551 * All qlt_plogi_ack_t operations are protected by hardware_lock
553 static int qla24xx_post_nack_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
554 struct imm_ntfy_from_isp
*ntfy
, int type
)
556 struct qla_work_evt
*e
;
557 e
= qla2x00_alloc_work(vha
, QLA_EVT_NACK
);
559 return QLA_FUNCTION_FAILED
;
561 e
->u
.nack
.fcport
= fcport
;
562 e
->u
.nack
.type
= type
;
563 memcpy(e
->u
.nack
.iocb
, ntfy
, sizeof(struct imm_ntfy_from_isp
));
564 return qla2x00_post_work(vha
, e
);
568 void qla2x00_async_nack_sp_done(void *s
, int res
)
570 struct srb
*sp
= (struct srb
*)s
;
571 struct scsi_qla_host
*vha
= sp
->vha
;
574 ql_dbg(ql_dbg_disc
, vha
, 0x20f2,
575 "Async done-%s res %x %8phC type %d\n",
576 sp
->name
, res
, sp
->fcport
->port_name
, sp
->type
);
578 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
579 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
580 sp
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
584 sp
->fcport
->login_gen
++;
585 sp
->fcport
->fw_login_state
= DSC_LS_PLOGI_COMP
;
586 sp
->fcport
->logout_on_delete
= 1;
587 sp
->fcport
->plogi_nack_done_deadline
= jiffies
+ HZ
;
588 sp
->fcport
->send_els_logo
= 0;
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;
602 if (!IS_IIDMA_CAPABLE(vha
->hw
) ||
603 !vha
->hw
->flags
.gpsc_supported
) {
604 ql_dbg(ql_dbg_disc
, vha
, 0x20f3,
605 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
607 sp
->fcport
->port_name
,
610 qla24xx_post_upd_fcport_work(vha
, sp
->fcport
);
612 ql_dbg(ql_dbg_disc
, vha
, 0x20f5,
613 "%s %d %8phC post gpsc fcp_cnt %d\n",
615 sp
->fcport
->port_name
,
618 qla24xx_post_gpsc_work(vha
, sp
->fcport
);
624 sp
->fcport
->login_gen
++;
625 sp
->fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
626 qlt_logo_completion_handler(sp
->fcport
, MBS_COMMAND_COMPLETE
);
629 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
634 int qla24xx_async_notify_ack(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
635 struct imm_ntfy_from_isp
*ntfy
, int type
)
637 int rval
= QLA_FUNCTION_FAILED
;
641 fcport
->flags
|= FCF_ASYNC_SENT
;
644 fcport
->fw_login_state
= DSC_LS_PLOGI_PEND
;
648 fcport
->fw_login_state
= DSC_LS_PRLI_PEND
;
653 fcport
->fw_login_state
= DSC_LS_LOGO_PEND
;
658 sp
= qla2x00_get_sp(vha
, fcport
, GFP_ATOMIC
);
665 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
)+2);
667 sp
->u
.iocb_cmd
.u
.nack
.ntfy
= ntfy
;
668 sp
->u
.iocb_cmd
.timeout
= qla2x00_async_iocb_timeout
;
669 sp
->done
= qla2x00_async_nack_sp_done
;
671 rval
= qla2x00_start_sp(sp
);
672 if (rval
!= QLA_SUCCESS
)
675 ql_dbg(ql_dbg_disc
, vha
, 0x20f4,
676 "Async-%s %8phC hndl %x %s\n",
677 sp
->name
, fcport
->port_name
, sp
->handle
, c
);
684 fcport
->flags
&= ~FCF_ASYNC_SENT
;
688 void qla24xx_do_nack_work(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
)
693 switch (e
->u
.nack
.type
) {
695 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
696 t
= qlt_create_sess(vha
, e
->u
.nack
.fcport
, 0);
697 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
699 ql_log(ql_log_info
, vha
, 0xd034,
700 "%s create sess success %p", __func__
, t
);
701 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
702 /* create sess has an extra kref */
703 vha
->hw
->tgt
.tgt_ops
->put_sess(e
->u
.nack
.fcport
);
704 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
708 qla24xx_async_notify_ack(vha
, e
->u
.nack
.fcport
,
709 (struct imm_ntfy_from_isp
*)e
->u
.nack
.iocb
, e
->u
.nack
.type
);
712 void qla24xx_delete_sess_fn(struct work_struct
*work
)
714 fc_port_t
*fcport
= container_of(work
, struct fc_port
, del_work
);
715 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
718 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
720 if (fcport
->se_sess
) {
721 ha
->tgt
.tgt_ops
->shutdown_sess(fcport
);
722 ha
->tgt
.tgt_ops
->put_sess(fcport
);
724 qlt_unreg_sess(fcport
);
726 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
730 * Called from qla2x00_reg_remote_port()
732 void qlt_fc_port_added(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
734 struct qla_hw_data
*ha
= vha
->hw
;
735 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
736 struct fc_port
*sess
= fcport
;
739 if (!vha
->hw
->tgt
.tgt_ops
)
742 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
744 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
748 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
749 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
753 if (!sess
->se_sess
) {
754 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
756 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
757 sess
= qlt_create_sess(vha
, fcport
, false);
758 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
760 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
762 if (fcport
->fw_login_state
== DSC_LS_PRLI_COMP
) {
763 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
767 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
768 ql_dbg(ql_dbg_disc
, vha
, 0x2107,
769 "%s: kref_get fail sess %8phC \n",
770 __func__
, sess
->port_name
);
771 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
775 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04c,
776 "qla_target(%u): %ssession for port %8phC "
777 "(loop ID %d) reappeared\n", vha
->vp_idx
,
778 sess
->local
? "local " : "", sess
->port_name
, sess
->loop_id
);
780 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf007,
781 "Reappeared sess %p\n", sess
);
783 ha
->tgt
.tgt_ops
->update_sess(sess
, fcport
->d_id
,
785 (fcport
->flags
& FCF_CONF_COMP_SUPPORTED
));
788 if (sess
&& sess
->local
) {
789 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04d,
790 "qla_target(%u): local session for "
791 "port %8phC (loop ID %d) became global\n", vha
->vp_idx
,
792 fcport
->port_name
, sess
->loop_id
);
795 ha
->tgt
.tgt_ops
->put_sess(sess
);
796 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
800 * This is a zero-base ref-counting solution, since hardware_lock
801 * guarantees that ref_count is not modified concurrently.
802 * Upon successful return content of iocb is undefined
804 static struct qlt_plogi_ack_t
*
805 qlt_plogi_ack_find_add(struct scsi_qla_host
*vha
, port_id_t
*id
,
806 struct imm_ntfy_from_isp
*iocb
)
808 struct qlt_plogi_ack_t
*pla
;
810 list_for_each_entry(pla
, &vha
->plogi_ack_list
, list
) {
811 if (pla
->id
.b24
== id
->b24
) {
812 qlt_send_term_imm_notif(vha
, &pla
->iocb
, 1);
813 memcpy(&pla
->iocb
, iocb
, sizeof(pla
->iocb
));
818 pla
= kmem_cache_zalloc(qla_tgt_plogi_cachep
, GFP_ATOMIC
);
820 ql_dbg(ql_dbg_async
, vha
, 0x5088,
821 "qla_target(%d): Allocation of plogi_ack failed\n",
826 memcpy(&pla
->iocb
, iocb
, sizeof(pla
->iocb
));
828 list_add_tail(&pla
->list
, &vha
->plogi_ack_list
);
833 void qlt_plogi_ack_unref(struct scsi_qla_host
*vha
,
834 struct qlt_plogi_ack_t
*pla
)
836 struct imm_ntfy_from_isp
*iocb
= &pla
->iocb
;
839 fc_port_t
*fcport
= pla
->fcport
;
841 BUG_ON(!pla
->ref_count
);
847 ql_dbg(ql_dbg_disc
, vha
, 0x5089,
848 "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x"
849 " exch %#x ox_id %#x\n", iocb
->u
.isp24
.port_name
,
850 iocb
->u
.isp24
.port_id
[2], iocb
->u
.isp24
.port_id
[1],
851 iocb
->u
.isp24
.port_id
[0],
852 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
853 iocb
->u
.isp24
.exchange_address
, iocb
->ox_id
);
855 port_id
.b
.domain
= iocb
->u
.isp24
.port_id
[2];
856 port_id
.b
.area
= iocb
->u
.isp24
.port_id
[1];
857 port_id
.b
.al_pa
= iocb
->u
.isp24
.port_id
[0];
858 port_id
.b
.rsvd_1
= 0;
860 loop_id
= le16_to_cpu(iocb
->u
.isp24
.nport_handle
);
862 fcport
->loop_id
= loop_id
;
863 fcport
->d_id
= port_id
;
864 qla24xx_post_nack_work(vha
, fcport
, iocb
, SRB_NACK_PLOGI
);
866 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
867 if (fcport
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] == pla
)
868 fcport
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] = NULL
;
869 if (fcport
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] == pla
)
870 fcport
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] = NULL
;
873 list_del(&pla
->list
);
874 kmem_cache_free(qla_tgt_plogi_cachep
, pla
);
878 qlt_plogi_ack_link(struct scsi_qla_host
*vha
, struct qlt_plogi_ack_t
*pla
,
879 struct fc_port
*sess
, enum qlt_plogi_link_t link
)
881 struct imm_ntfy_from_isp
*iocb
= &pla
->iocb
;
882 /* Inc ref_count first because link might already be pointing at pla */
885 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf097,
886 "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC"
887 " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n",
888 sess
, link
, sess
->port_name
,
889 iocb
->u
.isp24
.port_name
, iocb
->u
.isp24
.port_id
[2],
890 iocb
->u
.isp24
.port_id
[1], iocb
->u
.isp24
.port_id
[0],
891 pla
->ref_count
, pla
, link
);
893 if (link
== QLT_PLOGI_LINK_CONFLICT
) {
894 switch (sess
->disc_state
) {
896 case DSC_DELETE_PEND
:
904 if (sess
->plogi_link
[link
])
905 qlt_plogi_ack_unref(vha
, sess
->plogi_link
[link
]);
907 if (link
== QLT_PLOGI_LINK_SAME_WWN
)
910 sess
->plogi_link
[link
] = pla
;
914 /* These fields must be initialized by the caller */
917 * number of cmds dropped while we were waiting for
918 * initiator to ack LOGO initialize to 1 if LOGO is
919 * triggered by a command, otherwise, to 0
923 /* These fields are used by callee */
924 struct list_head list
;
928 qlt_send_first_logo(struct scsi_qla_host
*vha
, qlt_port_logo_t
*logo
)
930 qlt_port_logo_t
*tmp
;
933 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
935 list_for_each_entry(tmp
, &vha
->logo_list
, list
) {
936 if (tmp
->id
.b24
== logo
->id
.b24
) {
937 tmp
->cmd_count
+= logo
->cmd_count
;
938 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
943 list_add_tail(&logo
->list
, &vha
->logo_list
);
945 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
947 res
= qla24xx_els_dcmd_iocb(vha
, ELS_DCMD_LOGO
, logo
->id
);
949 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
950 list_del(&logo
->list
);
951 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
953 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf098,
954 "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n",
955 logo
->id
.b
.domain
, logo
->id
.b
.area
, logo
->id
.b
.al_pa
,
956 logo
->cmd_count
, res
);
959 static void qlt_free_session_done(struct work_struct
*work
)
961 struct fc_port
*sess
= container_of(work
, struct fc_port
,
963 struct qla_tgt
*tgt
= sess
->tgt
;
964 struct scsi_qla_host
*vha
= sess
->vha
;
965 struct qla_hw_data
*ha
= vha
->hw
;
967 bool logout_started
= false;
969 scsi_qla_host_t
*base_vha
;
971 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf084,
972 "%s: se_sess %p / sess %p from port %8phC loop_id %#04x"
973 " s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n",
974 __func__
, sess
->se_sess
, sess
, sess
->port_name
, sess
->loop_id
,
975 sess
->d_id
.b
.domain
, sess
->d_id
.b
.area
, sess
->d_id
.b
.al_pa
,
976 sess
->logout_on_delete
, sess
->keep_nport_handle
,
977 sess
->send_els_logo
);
979 if (!IS_SW_RESV_ADDR(sess
->d_id
)) {
980 if (sess
->send_els_logo
) {
981 qlt_port_logo_t logo
;
983 logo
.id
= sess
->d_id
;
985 qlt_send_first_logo(vha
, &logo
);
988 if (sess
->logout_on_delete
) {
991 rc
= qla2x00_post_async_logout_work(vha
, sess
, NULL
);
992 if (rc
!= QLA_SUCCESS
)
993 ql_log(ql_log_warn
, vha
, 0xf085,
994 "Schedule logo failed sess %p rc %d\n",
997 logout_started
= true;
1002 * Release the target session for FC Nexus from fabric module code.
1004 if (sess
->se_sess
!= NULL
)
1005 ha
->tgt
.tgt_ops
->free_session(sess
);
1007 if (logout_started
) {
1008 bool traced
= false;
1010 while (!READ_ONCE(sess
->logout_completed
)) {
1012 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf086,
1013 "%s: waiting for sess %p logout\n",
1020 ql_dbg(ql_dbg_disc
, vha
, 0xf087,
1021 "%s: sess %p logout completed\n",__func__
, sess
);
1024 if (sess
->logo_ack_needed
) {
1025 sess
->logo_ack_needed
= 0;
1026 qla24xx_async_notify_ack(vha
, sess
,
1027 (struct imm_ntfy_from_isp
*)sess
->iocb
, SRB_NACK_LOGO
);
1030 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1031 if (sess
->se_sess
) {
1032 sess
->se_sess
= NULL
;
1033 if (tgt
&& !IS_SW_RESV_ADDR(sess
->d_id
))
1037 sess
->disc_state
= DSC_DELETED
;
1038 sess
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1039 sess
->deleted
= QLA_SESS_DELETED
;
1040 sess
->login_retry
= vha
->hw
->login_retry_count
;
1042 if (sess
->login_succ
&& !IS_SW_RESV_ADDR(sess
->d_id
)) {
1043 vha
->fcport_count
--;
1044 sess
->login_succ
= 0;
1047 if (sess
->chip_reset
!= ha
->base_qpair
->chip_reset
)
1048 qla2x00_clear_loop_id(sess
);
1050 if (sess
->conflict
) {
1051 sess
->conflict
->login_pause
= 0;
1052 sess
->conflict
= NULL
;
1053 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
1054 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1058 struct qlt_plogi_ack_t
*own
=
1059 sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
];
1060 struct qlt_plogi_ack_t
*con
=
1061 sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
];
1062 struct imm_ntfy_from_isp
*iocb
;
1066 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf099,
1067 "se_sess %p / sess %p port %8phC is gone,"
1068 " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n",
1069 sess
->se_sess
, sess
, sess
->port_name
,
1070 own
? "releasing own PLOGI" : "no own PLOGI pending",
1071 own
? own
->ref_count
: -1,
1072 iocb
->u
.isp24
.port_name
, con
->ref_count
);
1073 qlt_plogi_ack_unref(vha
, con
);
1074 sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] = NULL
;
1076 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf09a,
1077 "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n",
1078 sess
->se_sess
, sess
, sess
->port_name
,
1079 own
? "releasing own PLOGI" :
1080 "no own PLOGI pending",
1081 own
? own
->ref_count
: -1);
1085 sess
->fw_login_state
= DSC_LS_PLOGI_PEND
;
1086 qlt_plogi_ack_unref(vha
, own
);
1087 sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] = NULL
;
1090 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1092 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf001,
1093 "Unregistration of sess %p %8phC finished fcp_cnt %d\n",
1094 sess
, sess
->port_name
, vha
->fcport_count
);
1096 if (tgt
&& (tgt
->sess_count
== 0))
1097 wake_up_all(&tgt
->waitQ
);
1099 if (vha
->fcport_count
== 0)
1100 wake_up_all(&vha
->fcport_waitQ
);
1102 base_vha
= pci_get_drvdata(ha
->pdev
);
1103 if (test_bit(PFLG_DRIVER_REMOVING
, &base_vha
->pci_flags
))
1106 if (!tgt
|| !tgt
->tgt_stop
) {
1107 memset(&ea
, 0, sizeof(ea
));
1108 ea
.event
= FCME_DELETE_DONE
;
1110 qla2x00_fcport_event_handler(vha
, &ea
);
1114 /* ha->tgt.sess_lock supposed to be held on entry */
1115 void qlt_unreg_sess(struct fc_port
*sess
)
1117 struct scsi_qla_host
*vha
= sess
->vha
;
1119 ql_dbg(ql_dbg_disc
, sess
->vha
, 0x210a,
1120 "%s sess %p for deletion %8phC\n",
1121 __func__
, sess
, sess
->port_name
);
1124 vha
->hw
->tgt
.tgt_ops
->clear_nacl_from_fcport_map(sess
);
1126 qla2x00_mark_device_lost(vha
, sess
, 1, 1);
1128 sess
->deleted
= QLA_SESS_DELETION_IN_PROGRESS
;
1129 sess
->disc_state
= DSC_DELETE_PEND
;
1130 sess
->last_rscn_gen
= sess
->rscn_gen
;
1131 sess
->last_login_gen
= sess
->login_gen
;
1133 if (sess
->nvme_flag
& NVME_FLAG_REGISTERED
)
1134 schedule_work(&sess
->nvme_del_work
);
1136 INIT_WORK(&sess
->free_work
, qlt_free_session_done
);
1137 schedule_work(&sess
->free_work
);
1139 EXPORT_SYMBOL(qlt_unreg_sess
);
1141 static int qlt_reset(struct scsi_qla_host
*vha
, void *iocb
, int mcmd
)
1143 struct qla_hw_data
*ha
= vha
->hw
;
1144 struct fc_port
*sess
= NULL
;
1147 struct imm_ntfy_from_isp
*n
= (struct imm_ntfy_from_isp
*)iocb
;
1148 unsigned long flags
;
1150 loop_id
= le16_to_cpu(n
->u
.isp24
.nport_handle
);
1151 if (loop_id
== 0xFFFF) {
1153 atomic_inc(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
);
1154 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1155 qlt_clear_tgt_db(vha
->vha_tgt
.qla_tgt
);
1156 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1158 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1159 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
1160 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1163 ql_dbg(ql_dbg_tgt
, vha
, 0xe000,
1164 "Using sess for qla_tgt_reset: %p\n", sess
);
1170 ql_dbg(ql_dbg_tgt
, vha
, 0xe047,
1171 "scsi(%ld): resetting (session %p from port %8phC mcmd %x, "
1172 "loop_id %d)\n", vha
->host_no
, sess
, sess
->port_name
,
1175 return qlt_issue_task_mgmt(sess
, 0, mcmd
, iocb
, QLA24XX_MGMT_SEND_NACK
);
1178 static void qla24xx_chk_fcp_state(struct fc_port
*sess
)
1180 if (sess
->chip_reset
!= sess
->vha
->hw
->base_qpair
->chip_reset
) {
1181 sess
->logout_on_delete
= 0;
1182 sess
->logo_ack_needed
= 0;
1183 sess
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1184 sess
->scan_state
= 0;
1188 /* ha->tgt.sess_lock supposed to be held on entry */
1189 void qlt_schedule_sess_for_deletion(struct fc_port
*sess
,
1192 struct qla_tgt
*tgt
= sess
->tgt
;
1194 if (sess
->disc_state
== DSC_DELETE_PEND
)
1197 if (sess
->disc_state
== DSC_DELETED
) {
1198 if (tgt
&& tgt
->tgt_stop
&& (tgt
->sess_count
== 0))
1199 wake_up_all(&tgt
->waitQ
);
1200 if (sess
->vha
->fcport_count
== 0)
1201 wake_up_all(&sess
->vha
->fcport_waitQ
);
1203 if (!sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] &&
1204 !sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
])
1208 sess
->disc_state
= DSC_DELETE_PEND
;
1210 if (sess
->deleted
== QLA_SESS_DELETED
)
1211 sess
->logout_on_delete
= 0;
1213 sess
->deleted
= QLA_SESS_DELETION_IN_PROGRESS
;
1214 qla24xx_chk_fcp_state(sess
);
1216 ql_dbg(ql_dbg_tgt
, sess
->vha
, 0xe001,
1217 "Scheduling sess %p for deletion\n", sess
);
1219 INIT_WORK(&sess
->del_work
, qla24xx_delete_sess_fn
);
1220 queue_work(sess
->vha
->hw
->wq
, &sess
->del_work
);
1223 void qlt_schedule_sess_for_deletion_lock(struct fc_port
*sess
)
1225 unsigned long flags
;
1226 struct qla_hw_data
*ha
= sess
->vha
->hw
;
1227 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1228 qlt_schedule_sess_for_deletion(sess
, 1);
1229 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1232 /* ha->tgt.sess_lock supposed to be held on entry */
1233 static void qlt_clear_tgt_db(struct qla_tgt
*tgt
)
1235 struct fc_port
*sess
;
1236 scsi_qla_host_t
*vha
= tgt
->vha
;
1238 list_for_each_entry(sess
, &vha
->vp_fcports
, list
) {
1240 qlt_schedule_sess_for_deletion(sess
, 1);
1243 /* At this point tgt could be already dead */
1246 static int qla24xx_get_loop_id(struct scsi_qla_host
*vha
, const uint8_t *s_id
,
1249 struct qla_hw_data
*ha
= vha
->hw
;
1250 dma_addr_t gid_list_dma
;
1251 struct gid_list_info
*gid_list
;
1256 gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
1257 &gid_list_dma
, GFP_KERNEL
);
1259 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf044,
1260 "qla_target(%d): DMA Alloc failed of %u\n",
1261 vha
->vp_idx
, qla2x00_gid_list_size(ha
));
1265 /* Get list of logged in devices */
1266 rc
= qla24xx_gidlist_wait(vha
, gid_list
, gid_list_dma
, &entries
);
1267 if (rc
!= QLA_SUCCESS
) {
1268 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf045,
1269 "qla_target(%d): get_id_list() failed: %x\n",
1272 goto out_free_id_list
;
1275 id_iter
= (char *)gid_list
;
1277 for (i
= 0; i
< entries
; i
++) {
1278 struct gid_list_info
*gid
= (struct gid_list_info
*)id_iter
;
1279 if ((gid
->al_pa
== s_id
[2]) &&
1280 (gid
->area
== s_id
[1]) &&
1281 (gid
->domain
== s_id
[0])) {
1282 *loop_id
= le16_to_cpu(gid
->loop_id
);
1286 id_iter
+= ha
->gid_list_info_size
;
1290 dma_free_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
1291 gid_list
, gid_list_dma
);
1296 * Adds an extra ref to allow to drop hw lock after adding sess to the list.
1297 * Caller must put it.
1299 static struct fc_port
*qlt_create_sess(
1300 struct scsi_qla_host
*vha
,
1304 struct qla_hw_data
*ha
= vha
->hw
;
1305 struct fc_port
*sess
= fcport
;
1306 unsigned long flags
;
1308 if (vha
->vha_tgt
.qla_tgt
->tgt_stop
)
1311 if (fcport
->se_sess
) {
1312 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
1313 ql_dbg(ql_dbg_disc
, vha
, 0x20f6,
1314 "%s: kref_get_unless_zero failed for %8phC\n",
1315 __func__
, sess
->port_name
);
1320 sess
->tgt
= vha
->vha_tgt
.qla_tgt
;
1321 sess
->local
= local
;
1324 * Under normal circumstances we want to logout from firmware when
1325 * session eventually ends and release corresponding nport handle.
1326 * In the exception cases (e.g. when new PLOGI is waiting) corresponding
1327 * code will adjust these flags as necessary.
1329 sess
->logout_on_delete
= 1;
1330 sess
->keep_nport_handle
= 0;
1331 sess
->logout_completed
= 0;
1333 if (ha
->tgt
.tgt_ops
->check_initiator_node_acl(vha
,
1334 &fcport
->port_name
[0], sess
) < 0) {
1335 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf015,
1336 "(%d) %8phC check_initiator_node_acl failed\n",
1337 vha
->vp_idx
, fcport
->port_name
);
1340 kref_init(&fcport
->sess_kref
);
1342 * Take an extra reference to ->sess_kref here to handle
1343 * fc_port access across ->tgt.sess_lock reaquire.
1345 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
1346 ql_dbg(ql_dbg_disc
, vha
, 0x20f7,
1347 "%s: kref_get_unless_zero failed for %8phC\n",
1348 __func__
, sess
->port_name
);
1352 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1353 if (!IS_SW_RESV_ADDR(sess
->d_id
))
1354 vha
->vha_tgt
.qla_tgt
->sess_count
++;
1356 qlt_do_generation_tick(vha
, &sess
->generation
);
1357 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1360 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf006,
1361 "Adding sess %p se_sess %p to tgt %p sess_count %d\n",
1362 sess
, sess
->se_sess
, vha
->vha_tgt
.qla_tgt
,
1363 vha
->vha_tgt
.qla_tgt
->sess_count
);
1365 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04b,
1366 "qla_target(%d): %ssession for wwn %8phC (loop_id %d, "
1367 "s_id %x:%x:%x, confirmed completion %ssupported) added\n",
1368 vha
->vp_idx
, local
? "local " : "", fcport
->port_name
,
1369 fcport
->loop_id
, sess
->d_id
.b
.domain
, sess
->d_id
.b
.area
,
1370 sess
->d_id
.b
.al_pa
, sess
->conf_compl_supported
? "" : "not ");
1376 * max_gen - specifies maximum session generation
1377 * at which this deletion requestion is still valid
1380 qlt_fc_port_deleted(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, int max_gen
)
1382 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
1383 struct fc_port
*sess
= fcport
;
1384 unsigned long flags
;
1386 if (!vha
->hw
->tgt
.tgt_ops
)
1392 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1393 if (tgt
->tgt_stop
) {
1394 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1397 if (!sess
->se_sess
) {
1398 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1402 if (max_gen
- sess
->generation
< 0) {
1403 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1404 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf092,
1405 "Ignoring stale deletion request for se_sess %p / sess %p"
1406 " for port %8phC, req_gen %d, sess_gen %d\n",
1407 sess
->se_sess
, sess
, sess
->port_name
, max_gen
,
1412 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf008, "qla_tgt_fc_port_deleted %p", sess
);
1415 qlt_schedule_sess_for_deletion(sess
, false);
1416 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1419 static inline int test_tgt_sess_count(struct qla_tgt
*tgt
)
1421 struct qla_hw_data
*ha
= tgt
->ha
;
1422 unsigned long flags
;
1425 * We need to protect against race, when tgt is freed before or
1428 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1429 ql_dbg(ql_dbg_tgt
, tgt
->vha
, 0xe002,
1430 "tgt %p, sess_count=%d\n",
1431 tgt
, tgt
->sess_count
);
1432 res
= (tgt
->sess_count
== 0);
1433 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1438 /* Called by tcm_qla2xxx configfs code */
1439 int qlt_stop_phase1(struct qla_tgt
*tgt
)
1441 struct scsi_qla_host
*vha
= tgt
->vha
;
1442 struct qla_hw_data
*ha
= tgt
->ha
;
1443 unsigned long flags
;
1445 mutex_lock(&qla_tgt_mutex
);
1446 if (!vha
->fc_vport
) {
1447 struct Scsi_Host
*sh
= vha
->host
;
1448 struct fc_host_attrs
*fc_host
= shost_to_fc_host(sh
);
1451 spin_lock_irqsave(sh
->host_lock
, flags
);
1452 npiv_vports
= (fc_host
->npiv_vports_inuse
);
1453 spin_unlock_irqrestore(sh
->host_lock
, flags
);
1456 mutex_unlock(&qla_tgt_mutex
);
1457 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf021,
1458 "NPIV is in use. Can not stop target\n");
1462 if (tgt
->tgt_stop
|| tgt
->tgt_stopped
) {
1463 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04e,
1464 "Already in tgt->tgt_stop or tgt_stopped state\n");
1465 mutex_unlock(&qla_tgt_mutex
);
1469 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xe003, "Stopping target for host %ld(%p)\n",
1472 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
1473 * Lock is needed, because we still can get an incoming packet.
1475 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
1476 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1478 qlt_clear_tgt_db(tgt
);
1479 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1480 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
1481 mutex_unlock(&qla_tgt_mutex
);
1483 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf009,
1484 "Waiting for sess works (tgt %p)", tgt
);
1485 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1486 while (!list_empty(&tgt
->sess_works_list
)) {
1487 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1488 flush_scheduled_work();
1489 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1491 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1493 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00a,
1494 "Waiting for tgt %p: sess_count=%d\n", tgt
, tgt
->sess_count
);
1496 wait_event_timeout(tgt
->waitQ
, test_tgt_sess_count(tgt
), 10*HZ
);
1499 if (!ha
->flags
.host_shutting_down
&&
1500 (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)))
1501 qlt_disable_vha(vha
);
1503 /* Wait for sessions to clear out (just in case) */
1504 wait_event_timeout(tgt
->waitQ
, test_tgt_sess_count(tgt
), 10*HZ
);
1507 EXPORT_SYMBOL(qlt_stop_phase1
);
1509 /* Called by tcm_qla2xxx configfs code */
1510 void qlt_stop_phase2(struct qla_tgt
*tgt
)
1512 scsi_qla_host_t
*vha
= tgt
->vha
;
1514 if (tgt
->tgt_stopped
) {
1515 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04f,
1516 "Already in tgt->tgt_stopped state\n");
1520 if (!tgt
->tgt_stop
) {
1521 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00b,
1522 "%s: phase1 stop is not completed\n", __func__
);
1527 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
1529 tgt
->tgt_stopped
= 1;
1530 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
1532 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00c, "Stop of tgt %p finished\n",
1535 EXPORT_SYMBOL(qlt_stop_phase2
);
1537 /* Called from qlt_remove_target() -> qla2x00_remove_one() */
1538 static void qlt_release(struct qla_tgt
*tgt
)
1540 scsi_qla_host_t
*vha
= tgt
->vha
;
1544 struct qla_qpair_hint
*h
;
1545 struct qla_hw_data
*ha
= vha
->hw
;
1547 if ((vha
->vha_tgt
.qla_tgt
!= NULL
) && !tgt
->tgt_stop
&&
1549 qlt_stop_phase1(tgt
);
1551 if ((vha
->vha_tgt
.qla_tgt
!= NULL
) && !tgt
->tgt_stopped
)
1552 qlt_stop_phase2(tgt
);
1554 for (i
= 0; i
< vha
->hw
->max_qpairs
+ 1; i
++) {
1555 unsigned long flags
;
1557 h
= &tgt
->qphints
[i
];
1559 spin_lock_irqsave(h
->qpair
->qp_lock_ptr
, flags
);
1560 list_del(&h
->hint_elem
);
1561 spin_unlock_irqrestore(h
->qpair
->qp_lock_ptr
, flags
);
1565 kfree(tgt
->qphints
);
1566 mutex_lock(&qla_tgt_mutex
);
1567 list_del(&vha
->vha_tgt
.qla_tgt
->tgt_list_entry
);
1568 mutex_unlock(&qla_tgt_mutex
);
1570 btree_for_each_safe64(&tgt
->lun_qpair_map
, key
, node
)
1571 btree_remove64(&tgt
->lun_qpair_map
, key
);
1573 btree_destroy64(&tgt
->lun_qpair_map
);
1576 if (ha
->tgt
.tgt_ops
&&
1577 ha
->tgt
.tgt_ops
->remove_target
&&
1578 vha
->vha_tgt
.target_lport_ptr
)
1579 ha
->tgt
.tgt_ops
->remove_target(vha
);
1581 vha
->vha_tgt
.qla_tgt
= NULL
;
1583 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00d,
1584 "Release of tgt %p finished\n", tgt
);
1589 /* ha->hardware_lock supposed to be held on entry */
1590 static int qlt_sched_sess_work(struct qla_tgt
*tgt
, int type
,
1591 const void *param
, unsigned int param_size
)
1593 struct qla_tgt_sess_work_param
*prm
;
1594 unsigned long flags
;
1596 prm
= kzalloc(sizeof(*prm
), GFP_ATOMIC
);
1598 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf050,
1599 "qla_target(%d): Unable to create session "
1600 "work, command will be refused", 0);
1604 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf00e,
1605 "Scheduling work (type %d, prm %p)"
1606 " to find session for param %p (size %d, tgt %p)\n",
1607 type
, prm
, param
, param_size
, tgt
);
1610 memcpy(&prm
->tm_iocb
, param
, param_size
);
1612 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1613 list_add_tail(&prm
->sess_works_list_entry
, &tgt
->sess_works_list
);
1614 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1616 schedule_work(&tgt
->sess_work
);
1622 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1624 static void qlt_send_notify_ack(struct qla_qpair
*qpair
,
1625 struct imm_ntfy_from_isp
*ntfy
,
1626 uint32_t add_flags
, uint16_t resp_code
, int resp_code_valid
,
1627 uint16_t srr_flags
, uint16_t srr_reject_code
, uint8_t srr_explan
)
1629 struct scsi_qla_host
*vha
= qpair
->vha
;
1630 struct qla_hw_data
*ha
= vha
->hw
;
1632 struct nack_to_isp
*nack
;
1634 if (!ha
->flags
.fw_started
)
1637 ql_dbg(ql_dbg_tgt
, vha
, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha
);
1639 pkt
= (request_t
*)__qla2x00_alloc_iocbs(qpair
, NULL
);
1641 ql_dbg(ql_dbg_tgt
, vha
, 0xe049,
1642 "qla_target(%d): %s failed: unable to allocate "
1643 "request packet\n", vha
->vp_idx
, __func__
);
1647 if (vha
->vha_tgt
.qla_tgt
!= NULL
)
1648 vha
->vha_tgt
.qla_tgt
->notify_ack_expected
++;
1650 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
1651 pkt
->entry_count
= 1;
1653 nack
= (struct nack_to_isp
*)pkt
;
1654 nack
->ox_id
= ntfy
->ox_id
;
1656 nack
->u
.isp24
.handle
= QLA_TGT_SKIP_HANDLE
;
1657 nack
->u
.isp24
.nport_handle
= ntfy
->u
.isp24
.nport_handle
;
1658 if (le16_to_cpu(ntfy
->u
.isp24
.status
) == IMM_NTFY_ELS
) {
1659 nack
->u
.isp24
.flags
= ntfy
->u
.isp24
.flags
&
1660 cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB
);
1662 nack
->u
.isp24
.srr_rx_id
= ntfy
->u
.isp24
.srr_rx_id
;
1663 nack
->u
.isp24
.status
= ntfy
->u
.isp24
.status
;
1664 nack
->u
.isp24
.status_subcode
= ntfy
->u
.isp24
.status_subcode
;
1665 nack
->u
.isp24
.fw_handle
= ntfy
->u
.isp24
.fw_handle
;
1666 nack
->u
.isp24
.exchange_address
= ntfy
->u
.isp24
.exchange_address
;
1667 nack
->u
.isp24
.srr_rel_offs
= ntfy
->u
.isp24
.srr_rel_offs
;
1668 nack
->u
.isp24
.srr_ui
= ntfy
->u
.isp24
.srr_ui
;
1669 nack
->u
.isp24
.srr_flags
= cpu_to_le16(srr_flags
);
1670 nack
->u
.isp24
.srr_reject_code
= srr_reject_code
;
1671 nack
->u
.isp24
.srr_reject_code_expl
= srr_explan
;
1672 nack
->u
.isp24
.vp_index
= ntfy
->u
.isp24
.vp_index
;
1674 ql_dbg(ql_dbg_tgt
, vha
, 0xe005,
1675 "qla_target(%d): Sending 24xx Notify Ack %d\n",
1676 vha
->vp_idx
, nack
->u
.isp24
.status
);
1678 /* Memory Barrier */
1680 qla2x00_start_iocbs(vha
, qpair
->req
);
1684 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1686 static void qlt_24xx_send_abts_resp(struct qla_qpair
*qpair
,
1687 struct abts_recv_from_24xx
*abts
, uint32_t status
,
1690 struct scsi_qla_host
*vha
= qpair
->vha
;
1691 struct qla_hw_data
*ha
= vha
->hw
;
1692 struct abts_resp_to_24xx
*resp
;
1696 ql_dbg(ql_dbg_tgt
, vha
, 0xe006,
1697 "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
1700 resp
= (struct abts_resp_to_24xx
*)qla2x00_alloc_iocbs_ready(qpair
,
1703 ql_dbg(ql_dbg_tgt
, vha
, 0xe04a,
1704 "qla_target(%d): %s failed: unable to allocate "
1705 "request packet", vha
->vp_idx
, __func__
);
1709 resp
->entry_type
= ABTS_RESP_24XX
;
1710 resp
->entry_count
= 1;
1711 resp
->nport_handle
= abts
->nport_handle
;
1712 resp
->vp_index
= vha
->vp_idx
;
1713 resp
->sof_type
= abts
->sof_type
;
1714 resp
->exchange_address
= abts
->exchange_address
;
1715 resp
->fcp_hdr_le
= abts
->fcp_hdr_le
;
1716 f_ctl
= cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP
|
1717 F_CTL_LAST_SEQ
| F_CTL_END_SEQ
|
1718 F_CTL_SEQ_INITIATIVE
);
1719 p
= (uint8_t *)&f_ctl
;
1720 resp
->fcp_hdr_le
.f_ctl
[0] = *p
++;
1721 resp
->fcp_hdr_le
.f_ctl
[1] = *p
++;
1722 resp
->fcp_hdr_le
.f_ctl
[2] = *p
;
1724 resp
->fcp_hdr_le
.d_id
[0] = abts
->fcp_hdr_le
.d_id
[0];
1725 resp
->fcp_hdr_le
.d_id
[1] = abts
->fcp_hdr_le
.d_id
[1];
1726 resp
->fcp_hdr_le
.d_id
[2] = abts
->fcp_hdr_le
.d_id
[2];
1727 resp
->fcp_hdr_le
.s_id
[0] = abts
->fcp_hdr_le
.s_id
[0];
1728 resp
->fcp_hdr_le
.s_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1729 resp
->fcp_hdr_le
.s_id
[2] = abts
->fcp_hdr_le
.s_id
[2];
1731 resp
->fcp_hdr_le
.d_id
[0] = abts
->fcp_hdr_le
.s_id
[0];
1732 resp
->fcp_hdr_le
.d_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1733 resp
->fcp_hdr_le
.d_id
[2] = abts
->fcp_hdr_le
.s_id
[2];
1734 resp
->fcp_hdr_le
.s_id
[0] = abts
->fcp_hdr_le
.d_id
[0];
1735 resp
->fcp_hdr_le
.s_id
[1] = abts
->fcp_hdr_le
.d_id
[1];
1736 resp
->fcp_hdr_le
.s_id
[2] = abts
->fcp_hdr_le
.d_id
[2];
1738 resp
->exchange_addr_to_abort
= abts
->exchange_addr_to_abort
;
1739 if (status
== FCP_TMF_CMPL
) {
1740 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_ACC
;
1741 resp
->payload
.ba_acct
.seq_id_valid
= SEQ_ID_INVALID
;
1742 resp
->payload
.ba_acct
.low_seq_cnt
= 0x0000;
1743 resp
->payload
.ba_acct
.high_seq_cnt
= 0xFFFF;
1744 resp
->payload
.ba_acct
.ox_id
= abts
->fcp_hdr_le
.ox_id
;
1745 resp
->payload
.ba_acct
.rx_id
= abts
->fcp_hdr_le
.rx_id
;
1747 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_RJT
;
1748 resp
->payload
.ba_rjt
.reason_code
=
1749 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM
;
1750 /* Other bytes are zero */
1753 vha
->vha_tgt
.qla_tgt
->abts_resp_expected
++;
1755 /* Memory Barrier */
1757 if (qpair
->reqq_start_iocbs
)
1758 qpair
->reqq_start_iocbs(qpair
);
1760 qla2x00_start_iocbs(vha
, qpair
->req
);
1764 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1766 static void qlt_24xx_retry_term_exchange(struct scsi_qla_host
*vha
,
1767 struct abts_resp_from_24xx_fw
*entry
)
1769 struct ctio7_to_24xx
*ctio
;
1771 ql_dbg(ql_dbg_tgt
, vha
, 0xe007,
1772 "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha
->hw
);
1774 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs_ready(
1775 vha
->hw
->base_qpair
, NULL
);
1777 ql_dbg(ql_dbg_tgt
, vha
, 0xe04b,
1778 "qla_target(%d): %s failed: unable to allocate "
1779 "request packet\n", vha
->vp_idx
, __func__
);
1784 * We've got on entrance firmware's response on by us generated
1785 * ABTS response. So, in it ID fields are reversed.
1788 ctio
->entry_type
= CTIO_TYPE7
;
1789 ctio
->entry_count
= 1;
1790 ctio
->nport_handle
= entry
->nport_handle
;
1791 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
1792 ctio
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
1793 ctio
->vp_index
= vha
->vp_idx
;
1794 ctio
->initiator_id
[0] = entry
->fcp_hdr_le
.d_id
[0];
1795 ctio
->initiator_id
[1] = entry
->fcp_hdr_le
.d_id
[1];
1796 ctio
->initiator_id
[2] = entry
->fcp_hdr_le
.d_id
[2];
1797 ctio
->exchange_addr
= entry
->exchange_addr_to_abort
;
1798 ctio
->u
.status1
.flags
= cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
|
1799 CTIO7_FLAGS_TERMINATE
);
1800 ctio
->u
.status1
.ox_id
= cpu_to_le16(entry
->fcp_hdr_le
.ox_id
);
1802 /* Memory Barrier */
1804 qla2x00_start_iocbs(vha
, vha
->req
);
1806 qlt_24xx_send_abts_resp(vha
->hw
->base_qpair
,
1807 (struct abts_recv_from_24xx
*)entry
,
1808 FCP_TMF_CMPL
, true);
1811 static int abort_cmd_for_tag(struct scsi_qla_host
*vha
, uint32_t tag
)
1813 struct qla_tgt_sess_op
*op
;
1814 struct qla_tgt_cmd
*cmd
;
1815 unsigned long flags
;
1817 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
1818 list_for_each_entry(op
, &vha
->qla_sess_op_cmd_list
, cmd_list
) {
1819 if (tag
== op
->atio
.u
.isp24
.exchange_addr
) {
1821 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
1826 list_for_each_entry(op
, &vha
->unknown_atio_list
, cmd_list
) {
1827 if (tag
== op
->atio
.u
.isp24
.exchange_addr
) {
1829 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
1834 list_for_each_entry(cmd
, &vha
->qla_cmd_list
, cmd_list
) {
1835 if (tag
== cmd
->atio
.u
.isp24
.exchange_addr
) {
1837 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
1841 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
1846 /* drop cmds for the given lun
1847 * XXX only looks for cmds on the port through which lun reset was recieved
1848 * XXX does not go through the list of other port (which may have cmds
1851 static void abort_cmds_for_lun(struct scsi_qla_host
*vha
,
1852 u64 lun
, uint8_t *s_id
)
1854 struct qla_tgt_sess_op
*op
;
1855 struct qla_tgt_cmd
*cmd
;
1857 unsigned long flags
;
1859 key
= sid_to_key(s_id
);
1860 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
1861 list_for_each_entry(op
, &vha
->qla_sess_op_cmd_list
, cmd_list
) {
1865 op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
1866 op_lun
= scsilun_to_int(
1867 (struct scsi_lun
*)&op
->atio
.u
.isp24
.fcp_cmnd
.lun
);
1868 if (op_key
== key
&& op_lun
== lun
)
1872 list_for_each_entry(op
, &vha
->unknown_atio_list
, cmd_list
) {
1876 op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
1877 op_lun
= scsilun_to_int(
1878 (struct scsi_lun
*)&op
->atio
.u
.isp24
.fcp_cmnd
.lun
);
1879 if (op_key
== key
&& op_lun
== lun
)
1883 list_for_each_entry(cmd
, &vha
->qla_cmd_list
, cmd_list
) {
1887 cmd_key
= sid_to_key(cmd
->atio
.u
.isp24
.fcp_hdr
.s_id
);
1888 cmd_lun
= scsilun_to_int(
1889 (struct scsi_lun
*)&cmd
->atio
.u
.isp24
.fcp_cmnd
.lun
);
1890 if (cmd_key
== key
&& cmd_lun
== lun
)
1893 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
1896 /* ha->hardware_lock supposed to be held on entry */
1897 static int __qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
1898 struct abts_recv_from_24xx
*abts
, struct fc_port
*sess
)
1900 struct qla_hw_data
*ha
= vha
->hw
;
1901 struct qla_tgt_mgmt_cmd
*mcmd
;
1904 if (abort_cmd_for_tag(vha
, abts
->exchange_addr_to_abort
)) {
1905 /* send TASK_ABORT response immediately */
1906 qlt_24xx_send_abts_resp(ha
->base_qpair
, abts
, FCP_TMF_CMPL
, false);
1910 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00f,
1911 "qla_target(%d): task abort (tag=%d)\n",
1912 vha
->vp_idx
, abts
->exchange_addr_to_abort
);
1914 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
1916 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf051,
1917 "qla_target(%d): %s: Allocation of ABORT cmd failed",
1918 vha
->vp_idx
, __func__
);
1921 memset(mcmd
, 0, sizeof(*mcmd
));
1924 memcpy(&mcmd
->orig_iocb
.abts
, abts
, sizeof(mcmd
->orig_iocb
.abts
));
1925 mcmd
->reset_count
= ha
->base_qpair
->chip_reset
;
1926 mcmd
->tmr_func
= QLA_TGT_ABTS
;
1927 mcmd
->qpair
= ha
->base_qpair
;
1931 * LUN is looked up by target-core internally based on the passed
1932 * abts->exchange_addr_to_abort tag.
1934 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, 0, mcmd
->tmr_func
,
1935 abts
->exchange_addr_to_abort
);
1937 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf052,
1938 "qla_target(%d): tgt_ops->handle_tmr()"
1939 " failed: %d", vha
->vp_idx
, rc
);
1940 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
1948 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1950 static void qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
1951 struct abts_recv_from_24xx
*abts
)
1953 struct qla_hw_data
*ha
= vha
->hw
;
1954 struct fc_port
*sess
;
1955 uint32_t tag
= abts
->exchange_addr_to_abort
;
1958 unsigned long flags
;
1960 if (le32_to_cpu(abts
->fcp_hdr_le
.parameter
) & ABTS_PARAM_ABORT_SEQ
) {
1961 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf053,
1962 "qla_target(%d): ABTS: Abort Sequence not "
1963 "supported\n", vha
->vp_idx
);
1964 qlt_24xx_send_abts_resp(ha
->base_qpair
, abts
, FCP_TMF_REJECTED
,
1969 if (tag
== ATIO_EXCHANGE_ADDRESS_UNKNOWN
) {
1970 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf010,
1971 "qla_target(%d): ABTS: Unknown Exchange "
1972 "Address received\n", vha
->vp_idx
);
1973 qlt_24xx_send_abts_resp(ha
->base_qpair
, abts
, FCP_TMF_REJECTED
,
1978 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf011,
1979 "qla_target(%d): task abort (s_id=%x:%x:%x, "
1980 "tag=%d, param=%x)\n", vha
->vp_idx
, abts
->fcp_hdr_le
.s_id
[2],
1981 abts
->fcp_hdr_le
.s_id
[1], abts
->fcp_hdr_le
.s_id
[0], tag
,
1982 le32_to_cpu(abts
->fcp_hdr_le
.parameter
));
1984 s_id
[0] = abts
->fcp_hdr_le
.s_id
[2];
1985 s_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1986 s_id
[2] = abts
->fcp_hdr_le
.s_id
[0];
1988 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1989 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
1991 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf012,
1992 "qla_target(%d): task abort for non-existant session\n",
1994 rc
= qlt_sched_sess_work(vha
->vha_tgt
.qla_tgt
,
1995 QLA_TGT_SESS_WORK_ABORT
, abts
, sizeof(*abts
));
1997 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
2000 qlt_24xx_send_abts_resp(ha
->base_qpair
, abts
,
2001 FCP_TMF_REJECTED
, false);
2005 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
2008 if (sess
->deleted
) {
2009 qlt_24xx_send_abts_resp(ha
->base_qpair
, abts
, FCP_TMF_REJECTED
,
2014 rc
= __qlt_24xx_handle_abts(vha
, abts
, sess
);
2016 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf054,
2017 "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
2019 qlt_24xx_send_abts_resp(ha
->base_qpair
, abts
, FCP_TMF_REJECTED
,
2026 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2028 static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair
*qpair
,
2029 struct qla_tgt_mgmt_cmd
*mcmd
, uint32_t resp_code
)
2031 struct scsi_qla_host
*ha
= mcmd
->vha
;
2032 struct atio_from_isp
*atio
= &mcmd
->orig_iocb
.atio
;
2033 struct ctio7_to_24xx
*ctio
;
2036 ql_dbg(ql_dbg_tgt
, ha
, 0xe008,
2037 "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
2038 ha
, atio
, resp_code
);
2041 ctio
= (struct ctio7_to_24xx
*)__qla2x00_alloc_iocbs(qpair
, NULL
);
2043 ql_dbg(ql_dbg_tgt
, ha
, 0xe04c,
2044 "qla_target(%d): %s failed: unable to allocate "
2045 "request packet\n", ha
->vp_idx
, __func__
);
2049 ctio
->entry_type
= CTIO_TYPE7
;
2050 ctio
->entry_count
= 1;
2051 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
2052 ctio
->nport_handle
= mcmd
->sess
->loop_id
;
2053 ctio
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2054 ctio
->vp_index
= ha
->vp_idx
;
2055 ctio
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2056 ctio
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2057 ctio
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2058 ctio
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2059 temp
= (atio
->u
.isp24
.attr
<< 9)|
2060 CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
;
2061 ctio
->u
.status1
.flags
= cpu_to_le16(temp
);
2062 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2063 ctio
->u
.status1
.ox_id
= cpu_to_le16(temp
);
2064 ctio
->u
.status1
.scsi_status
=
2065 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID
);
2066 ctio
->u
.status1
.response_len
= cpu_to_le16(8);
2067 ctio
->u
.status1
.sense_data
[0] = resp_code
;
2069 /* Memory Barrier */
2071 if (qpair
->reqq_start_iocbs
)
2072 qpair
->reqq_start_iocbs(qpair
);
2074 qla2x00_start_iocbs(ha
, qpair
->req
);
2077 void qlt_free_mcmd(struct qla_tgt_mgmt_cmd
*mcmd
)
2079 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2081 EXPORT_SYMBOL(qlt_free_mcmd
);
2084 * ha->hardware_lock supposed to be held on entry. Might drop it, then
2087 void qlt_send_resp_ctio(struct qla_qpair
*qpair
, struct qla_tgt_cmd
*cmd
,
2088 uint8_t scsi_status
, uint8_t sense_key
, uint8_t asc
, uint8_t ascq
)
2090 struct atio_from_isp
*atio
= &cmd
->atio
;
2091 struct ctio7_to_24xx
*ctio
;
2093 struct scsi_qla_host
*vha
= cmd
->vha
;
2095 ql_dbg(ql_dbg_tgt_dif
, vha
, 0x3066,
2096 "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, "
2097 "sense_key=%02x, asc=%02x, ascq=%02x",
2098 vha
, atio
, scsi_status
, sense_key
, asc
, ascq
);
2100 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs(vha
, NULL
);
2102 ql_dbg(ql_dbg_async
, vha
, 0x3067,
2103 "qla2x00t(%ld): %s failed: unable to allocate request packet",
2104 vha
->host_no
, __func__
);
2108 ctio
->entry_type
= CTIO_TYPE7
;
2109 ctio
->entry_count
= 1;
2110 ctio
->handle
= QLA_TGT_SKIP_HANDLE
;
2111 ctio
->nport_handle
= cmd
->sess
->loop_id
;
2112 ctio
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2113 ctio
->vp_index
= vha
->vp_idx
;
2114 ctio
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2115 ctio
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2116 ctio
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2117 ctio
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2118 temp
= (atio
->u
.isp24
.attr
<< 9) |
2119 CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
;
2120 ctio
->u
.status1
.flags
= cpu_to_le16(temp
);
2121 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2122 ctio
->u
.status1
.ox_id
= cpu_to_le16(temp
);
2123 ctio
->u
.status1
.scsi_status
=
2124 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID
| scsi_status
);
2125 ctio
->u
.status1
.response_len
= cpu_to_le16(18);
2126 ctio
->u
.status1
.residual
= cpu_to_le32(get_datalen_for_atio(atio
));
2128 if (ctio
->u
.status1
.residual
!= 0)
2129 ctio
->u
.status1
.scsi_status
|=
2130 cpu_to_le16(SS_RESIDUAL_UNDER
);
2132 /* Response code and sense key */
2133 put_unaligned_le32(((0x70 << 24) | (sense_key
<< 8)),
2134 (&ctio
->u
.status1
.sense_data
)[0]);
2135 /* Additional sense length */
2136 put_unaligned_le32(0x0a, (&ctio
->u
.status1
.sense_data
)[1]);
2138 put_unaligned_le32(((asc
<< 24) | (ascq
<< 16)),
2139 (&ctio
->u
.status1
.sense_data
)[3]);
2141 /* Memory Barrier */
2144 if (qpair
->reqq_start_iocbs
)
2145 qpair
->reqq_start_iocbs(qpair
);
2147 qla2x00_start_iocbs(vha
, qpair
->req
);
2153 /* callback from target fabric module code */
2154 void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd
*mcmd
)
2156 struct scsi_qla_host
*vha
= mcmd
->sess
->vha
;
2157 struct qla_hw_data
*ha
= vha
->hw
;
2158 unsigned long flags
;
2159 struct qla_qpair
*qpair
= mcmd
->qpair
;
2161 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf013,
2162 "TM response mcmd (%p) status %#x state %#x",
2163 mcmd
, mcmd
->fc_tm_rsp
, mcmd
->flags
);
2165 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
2167 if (!vha
->flags
.online
|| mcmd
->reset_count
!= qpair
->chip_reset
) {
2169 * Either the port is not online or this request was from
2170 * previous life, just abort the processing.
2172 ql_dbg(ql_dbg_async
, vha
, 0xe100,
2173 "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n",
2174 vha
->flags
.online
, qla2x00_reset_active(vha
),
2175 mcmd
->reset_count
, qpair
->chip_reset
);
2176 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
2177 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
2181 if (mcmd
->flags
== QLA24XX_MGMT_SEND_NACK
) {
2182 if (mcmd
->orig_iocb
.imm_ntfy
.u
.isp24
.status_subcode
==
2184 mcmd
->orig_iocb
.imm_ntfy
.u
.isp24
.status_subcode
==
2186 mcmd
->orig_iocb
.imm_ntfy
.u
.isp24
.status_subcode
==
2188 ql_dbg(ql_dbg_disc
, vha
, 0x2106,
2189 "TM response logo %phC status %#x state %#x",
2190 mcmd
->sess
->port_name
, mcmd
->fc_tm_rsp
,
2192 qlt_schedule_sess_for_deletion_lock(mcmd
->sess
);
2194 qlt_send_notify_ack(vha
->hw
->base_qpair
,
2195 &mcmd
->orig_iocb
.imm_ntfy
, 0, 0, 0, 0, 0, 0);
2198 if (mcmd
->orig_iocb
.atio
.u
.raw
.entry_type
== ABTS_RECV_24XX
)
2199 qlt_24xx_send_abts_resp(qpair
, &mcmd
->orig_iocb
.abts
,
2200 mcmd
->fc_tm_rsp
, false);
2202 qlt_24xx_send_task_mgmt_ctio(qpair
, mcmd
,
2206 * Make the callback for ->free_mcmd() to queue_work() and invoke
2207 * target_put_sess_cmd() to drop cmd_kref to 1. The final
2208 * target_put_sess_cmd() call will be made from TFO->check_stop_free()
2209 * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd
2210 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
2211 * qlt_xmit_tm_rsp() returns here..
2213 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
2214 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
2216 EXPORT_SYMBOL(qlt_xmit_tm_rsp
);
2219 static int qlt_pci_map_calc_cnt(struct qla_tgt_prm
*prm
)
2221 struct qla_tgt_cmd
*cmd
= prm
->cmd
;
2223 BUG_ON(cmd
->sg_cnt
== 0);
2225 prm
->sg
= (struct scatterlist
*)cmd
->sg
;
2226 prm
->seg_cnt
= pci_map_sg(cmd
->qpair
->pdev
, cmd
->sg
,
2227 cmd
->sg_cnt
, cmd
->dma_data_direction
);
2228 if (unlikely(prm
->seg_cnt
== 0))
2231 prm
->cmd
->sg_mapped
= 1;
2233 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
) {
2235 * If greater than four sg entries then we need to allocate
2236 * the continuation entries
2238 if (prm
->seg_cnt
> QLA_TGT_DATASEGS_PER_CMD_24XX
)
2239 prm
->req_cnt
+= DIV_ROUND_UP(prm
->seg_cnt
-
2240 QLA_TGT_DATASEGS_PER_CMD_24XX
,
2241 QLA_TGT_DATASEGS_PER_CONT_24XX
);
2244 if ((cmd
->se_cmd
.prot_op
== TARGET_PROT_DIN_INSERT
) ||
2245 (cmd
->se_cmd
.prot_op
== TARGET_PROT_DOUT_STRIP
)) {
2246 prm
->seg_cnt
= DIV_ROUND_UP(cmd
->bufflen
, cmd
->blk_sz
);
2247 prm
->tot_dsds
= prm
->seg_cnt
;
2249 prm
->tot_dsds
= prm
->seg_cnt
;
2251 if (cmd
->prot_sg_cnt
) {
2252 prm
->prot_sg
= cmd
->prot_sg
;
2253 prm
->prot_seg_cnt
= pci_map_sg(cmd
->qpair
->pdev
,
2254 cmd
->prot_sg
, cmd
->prot_sg_cnt
,
2255 cmd
->dma_data_direction
);
2256 if (unlikely(prm
->prot_seg_cnt
== 0))
2259 if ((cmd
->se_cmd
.prot_op
== TARGET_PROT_DIN_INSERT
) ||
2260 (cmd
->se_cmd
.prot_op
== TARGET_PROT_DOUT_STRIP
)) {
2261 /* Dif Bundling not support here */
2262 prm
->prot_seg_cnt
= DIV_ROUND_UP(cmd
->bufflen
,
2264 prm
->tot_dsds
+= prm
->prot_seg_cnt
;
2266 prm
->tot_dsds
+= prm
->prot_seg_cnt
;
2273 ql_dbg_qp(ql_dbg_tgt
, prm
->cmd
->qpair
, 0xe04d,
2274 "qla_target(%d): PCI mapping failed: sg_cnt=%d",
2275 0, prm
->cmd
->sg_cnt
);
2279 static void qlt_unmap_sg(struct scsi_qla_host
*vha
, struct qla_tgt_cmd
*cmd
)
2281 struct qla_hw_data
*ha
;
2282 struct qla_qpair
*qpair
;
2283 if (!cmd
->sg_mapped
)
2288 pci_unmap_sg(qpair
->pdev
, cmd
->sg
, cmd
->sg_cnt
,
2289 cmd
->dma_data_direction
);
2292 if (cmd
->prot_sg_cnt
)
2293 pci_unmap_sg(qpair
->pdev
, cmd
->prot_sg
, cmd
->prot_sg_cnt
,
2294 cmd
->dma_data_direction
);
2299 if (cmd
->ctx_dsd_alloced
)
2300 qla2x00_clean_dsd_pool(ha
, cmd
->ctx
);
2302 dma_pool_free(ha
->dl_dma_pool
, cmd
->ctx
, cmd
->ctx
->crc_ctx_dma
);
2305 static int qlt_check_reserve_free_req(struct qla_qpair
*qpair
,
2309 struct req_que
*req
= qpair
->req
;
2311 if (req
->cnt
< (req_cnt
+ 2)) {
2312 cnt
= (uint16_t)(qpair
->use_shadow_reg
? *req
->out_ptr
:
2313 RD_REG_DWORD_RELAXED(req
->req_q_out
));
2315 if (req
->ring_index
< cnt
)
2316 req
->cnt
= cnt
- req
->ring_index
;
2318 req
->cnt
= req
->length
- (req
->ring_index
- cnt
);
2320 if (unlikely(req
->cnt
< (req_cnt
+ 2)))
2324 req
->cnt
-= req_cnt
;
2330 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2332 static inline void *qlt_get_req_pkt(struct req_que
*req
)
2334 /* Adjust ring index. */
2336 if (req
->ring_index
== req
->length
) {
2337 req
->ring_index
= 0;
2338 req
->ring_ptr
= req
->ring
;
2342 return (cont_entry_t
*)req
->ring_ptr
;
2345 /* ha->hardware_lock supposed to be held on entry */
2346 static inline uint32_t qlt_make_handle(struct qla_qpair
*qpair
)
2351 struct req_que
*req
= qpair
->req
;
2353 h
= req
->current_outstanding_cmd
;
2355 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
2357 if (h
== req
->num_outstanding_cmds
)
2360 if (h
== QLA_TGT_SKIP_HANDLE
)
2363 if (!req
->outstanding_cmds
[h
]) {
2370 req
->current_outstanding_cmd
= h
;
2372 ql_dbg(ql_dbg_io
, qpair
->vha
, 0x305b,
2373 "qla_target(%d): Ran out of empty cmd slots\n",
2374 qpair
->vha
->vp_idx
);
2375 h
= QLA_TGT_NULL_HANDLE
;
2381 /* ha->hardware_lock supposed to be held on entry */
2382 static int qlt_24xx_build_ctio_pkt(struct qla_qpair
*qpair
,
2383 struct qla_tgt_prm
*prm
)
2386 struct ctio7_to_24xx
*pkt
;
2387 struct atio_from_isp
*atio
= &prm
->cmd
->atio
;
2390 pkt
= (struct ctio7_to_24xx
*)qpair
->req
->ring_ptr
;
2392 memset(pkt
, 0, sizeof(*pkt
));
2394 pkt
->entry_type
= CTIO_TYPE7
;
2395 pkt
->entry_count
= (uint8_t)prm
->req_cnt
;
2396 pkt
->vp_index
= prm
->cmd
->vp_idx
;
2398 h
= qlt_make_handle(qpair
);
2399 if (unlikely(h
== QLA_TGT_NULL_HANDLE
)) {
2401 * CTIO type 7 from the firmware doesn't provide a way to
2402 * know the initiator's LOOP ID, hence we can't find
2403 * the session and, so, the command.
2407 qpair
->req
->outstanding_cmds
[h
] = (srb_t
*)prm
->cmd
;
2409 pkt
->handle
= MAKE_HANDLE(qpair
->req
->id
, h
);
2410 pkt
->handle
|= CTIO_COMPLETION_HANDLE_MARK
;
2411 pkt
->nport_handle
= cpu_to_le16(prm
->cmd
->loop_id
);
2412 pkt
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2413 pkt
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2414 pkt
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2415 pkt
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2416 pkt
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2417 temp
= atio
->u
.isp24
.attr
<< 9;
2418 pkt
->u
.status0
.flags
|= cpu_to_le16(temp
);
2419 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2420 pkt
->u
.status0
.ox_id
= cpu_to_le16(temp
);
2421 pkt
->u
.status0
.relative_offset
= cpu_to_le32(prm
->cmd
->offset
);
2427 * ha->hardware_lock supposed to be held on entry. We have already made sure
2428 * that there is sufficient amount of request entries to not drop it.
2430 static void qlt_load_cont_data_segments(struct qla_tgt_prm
*prm
)
2433 uint32_t *dword_ptr
;
2435 /* Build continuation packets */
2436 while (prm
->seg_cnt
> 0) {
2437 cont_a64_entry_t
*cont_pkt64
=
2438 (cont_a64_entry_t
*)qlt_get_req_pkt(
2439 prm
->cmd
->qpair
->req
);
2442 * Make sure that from cont_pkt64 none of
2443 * 64-bit specific fields used for 32-bit
2444 * addressing. Cast to (cont_entry_t *) for
2448 memset(cont_pkt64
, 0, sizeof(*cont_pkt64
));
2450 cont_pkt64
->entry_count
= 1;
2451 cont_pkt64
->sys_define
= 0;
2453 cont_pkt64
->entry_type
= CONTINUE_A64_TYPE
;
2454 dword_ptr
= (uint32_t *)&cont_pkt64
->dseg_0_address
;
2456 /* Load continuation entry data segments */
2458 cnt
< QLA_TGT_DATASEGS_PER_CONT_24XX
&& prm
->seg_cnt
;
2459 cnt
++, prm
->seg_cnt
--) {
2461 cpu_to_le32(pci_dma_lo32
2462 (sg_dma_address(prm
->sg
)));
2463 *dword_ptr
++ = cpu_to_le32(pci_dma_hi32
2464 (sg_dma_address(prm
->sg
)));
2465 *dword_ptr
++ = cpu_to_le32(sg_dma_len(prm
->sg
));
2467 prm
->sg
= sg_next(prm
->sg
);
2473 * ha->hardware_lock supposed to be held on entry. We have already made sure
2474 * that there is sufficient amount of request entries to not drop it.
2476 static void qlt_load_data_segments(struct qla_tgt_prm
*prm
)
2479 uint32_t *dword_ptr
;
2480 struct ctio7_to_24xx
*pkt24
= (struct ctio7_to_24xx
*)prm
->pkt
;
2482 pkt24
->u
.status0
.transfer_length
= cpu_to_le32(prm
->cmd
->bufflen
);
2484 /* Setup packet address segment pointer */
2485 dword_ptr
= pkt24
->u
.status0
.dseg_0_address
;
2487 /* Set total data segment count */
2489 pkt24
->dseg_count
= cpu_to_le16(prm
->seg_cnt
);
2491 if (prm
->seg_cnt
== 0) {
2492 /* No data transfer */
2498 /* If scatter gather */
2500 /* Load command entry data segments */
2502 (cnt
< QLA_TGT_DATASEGS_PER_CMD_24XX
) && prm
->seg_cnt
;
2503 cnt
++, prm
->seg_cnt
--) {
2505 cpu_to_le32(pci_dma_lo32(sg_dma_address(prm
->sg
)));
2507 *dword_ptr
++ = cpu_to_le32(pci_dma_hi32(
2508 sg_dma_address(prm
->sg
)));
2510 *dword_ptr
++ = cpu_to_le32(sg_dma_len(prm
->sg
));
2512 prm
->sg
= sg_next(prm
->sg
);
2515 qlt_load_cont_data_segments(prm
);
2518 static inline int qlt_has_data(struct qla_tgt_cmd
*cmd
)
2520 return cmd
->bufflen
> 0;
2523 static void qlt_print_dif_err(struct qla_tgt_prm
*prm
)
2525 struct qla_tgt_cmd
*cmd
;
2526 struct scsi_qla_host
*vha
;
2528 /* asc 0x10=dif error */
2529 if (prm
->sense_buffer
&& (prm
->sense_buffer
[12] == 0x10)) {
2533 switch (prm
->sense_buffer
[13]) {
2535 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe00b,
2536 "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2537 "se_cmd=%p tag[%x]",
2538 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2539 cmd
->atio
.u
.isp24
.exchange_addr
);
2542 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe00c,
2543 "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2544 "se_cmd=%p tag[%x]",
2545 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2546 cmd
->atio
.u
.isp24
.exchange_addr
);
2549 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe00f,
2550 "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2551 "se_cmd=%p tag[%x]",
2552 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2553 cmd
->atio
.u
.isp24
.exchange_addr
);
2556 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe010,
2557 "BE detected Dif ERR: lba[%llx|%lld] len[%x] "
2558 "se_cmd=%p tag[%x]",
2559 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2560 cmd
->atio
.u
.isp24
.exchange_addr
);
2563 ql_dump_buffer(ql_dbg_tgt_dif
, vha
, 0xe011, cmd
->cdb
, 16);
2568 * Called without ha->hardware_lock held
2570 static int qlt_pre_xmit_response(struct qla_tgt_cmd
*cmd
,
2571 struct qla_tgt_prm
*prm
, int xmit_type
, uint8_t scsi_status
,
2572 uint32_t *full_req_cnt
)
2574 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
2575 struct qla_qpair
*qpair
= cmd
->qpair
;
2578 prm
->tgt
= cmd
->tgt
;
2580 prm
->rq_result
= scsi_status
;
2581 prm
->sense_buffer
= &cmd
->sense_buffer
[0];
2582 prm
->sense_buffer_len
= TRANSPORT_SENSE_BUFFER
;
2587 prm
->add_status_pkt
= 0;
2588 prm
->prot_sg
= NULL
;
2589 prm
->prot_seg_cnt
= 0;
2592 if ((xmit_type
& QLA_TGT_XMIT_DATA
) && qlt_has_data(cmd
)) {
2593 if (qlt_pci_map_calc_cnt(prm
) != 0)
2597 *full_req_cnt
= prm
->req_cnt
;
2599 if (se_cmd
->se_cmd_flags
& SCF_UNDERFLOW_BIT
) {
2600 prm
->residual
= se_cmd
->residual_count
;
2601 ql_dbg_qp(ql_dbg_io
+ ql_dbg_verbose
, qpair
, 0x305c,
2602 "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2603 prm
->residual
, se_cmd
->tag
,
2604 se_cmd
->t_task_cdb
? se_cmd
->t_task_cdb
[0] : 0,
2605 cmd
->bufflen
, prm
->rq_result
);
2606 prm
->rq_result
|= SS_RESIDUAL_UNDER
;
2607 } else if (se_cmd
->se_cmd_flags
& SCF_OVERFLOW_BIT
) {
2608 prm
->residual
= se_cmd
->residual_count
;
2609 ql_dbg_qp(ql_dbg_io
, qpair
, 0x305d,
2610 "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2611 prm
->residual
, se_cmd
->tag
, se_cmd
->t_task_cdb
?
2612 se_cmd
->t_task_cdb
[0] : 0, cmd
->bufflen
, prm
->rq_result
);
2613 prm
->rq_result
|= SS_RESIDUAL_OVER
;
2616 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
2618 * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be
2619 * ignored in *xmit_response() below
2621 if (qlt_has_data(cmd
)) {
2622 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
) ||
2623 (IS_FWI2_CAPABLE(cmd
->vha
->hw
) &&
2624 (prm
->rq_result
!= 0))) {
2625 prm
->add_status_pkt
= 1;
2634 static inline int qlt_need_explicit_conf(struct qla_tgt_cmd
*cmd
,
2637 if (cmd
->qpair
->enable_class_2
)
2641 return cmd
->conf_compl_supported
;
2643 return cmd
->qpair
->enable_explicit_conf
&&
2644 cmd
->conf_compl_supported
;
2647 static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx
*ctio
,
2648 struct qla_tgt_prm
*prm
)
2650 prm
->sense_buffer_len
= min_t(uint32_t, prm
->sense_buffer_len
,
2651 (uint32_t)sizeof(ctio
->u
.status1
.sense_data
));
2652 ctio
->u
.status0
.flags
|= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS
);
2653 if (qlt_need_explicit_conf(prm
->cmd
, 0)) {
2654 ctio
->u
.status0
.flags
|= cpu_to_le16(
2655 CTIO7_FLAGS_EXPLICIT_CONFORM
|
2656 CTIO7_FLAGS_CONFORM_REQ
);
2658 ctio
->u
.status0
.residual
= cpu_to_le32(prm
->residual
);
2659 ctio
->u
.status0
.scsi_status
= cpu_to_le16(prm
->rq_result
);
2660 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
)) {
2663 if (qlt_need_explicit_conf(prm
->cmd
, 1)) {
2664 if ((prm
->rq_result
& SS_SCSI_STATUS_BYTE
) != 0) {
2665 ql_dbg_qp(ql_dbg_tgt
, prm
->cmd
->qpair
, 0xe017,
2666 "Skipping EXPLICIT_CONFORM and "
2667 "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
2668 "non GOOD status\n");
2669 goto skip_explict_conf
;
2671 ctio
->u
.status1
.flags
|= cpu_to_le16(
2672 CTIO7_FLAGS_EXPLICIT_CONFORM
|
2673 CTIO7_FLAGS_CONFORM_REQ
);
2676 ctio
->u
.status1
.flags
&=
2677 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
2678 ctio
->u
.status1
.flags
|=
2679 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
2680 ctio
->u
.status1
.scsi_status
|=
2681 cpu_to_le16(SS_SENSE_LEN_VALID
);
2682 ctio
->u
.status1
.sense_length
=
2683 cpu_to_le16(prm
->sense_buffer_len
);
2684 for (i
= 0; i
< prm
->sense_buffer_len
/4; i
++)
2685 ((uint32_t *)ctio
->u
.status1
.sense_data
)[i
] =
2686 cpu_to_be32(((uint32_t *)prm
->sense_buffer
)[i
]);
2688 qlt_print_dif_err(prm
);
2691 ctio
->u
.status1
.flags
&=
2692 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
2693 ctio
->u
.status1
.flags
|=
2694 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
2695 ctio
->u
.status1
.sense_length
= 0;
2696 memset(ctio
->u
.status1
.sense_data
, 0,
2697 sizeof(ctio
->u
.status1
.sense_data
));
2700 /* Sense with len > 24, is it possible ??? */
2704 qlt_hba_err_chk_enabled(struct se_cmd
*se_cmd
)
2706 switch (se_cmd
->prot_op
) {
2707 case TARGET_PROT_DOUT_INSERT
:
2708 case TARGET_PROT_DIN_STRIP
:
2709 if (ql2xenablehba_err_chk
>= 1)
2712 case TARGET_PROT_DOUT_PASS
:
2713 case TARGET_PROT_DIN_PASS
:
2714 if (ql2xenablehba_err_chk
>= 2)
2717 case TARGET_PROT_DIN_INSERT
:
2718 case TARGET_PROT_DOUT_STRIP
:
2727 qla_tgt_ref_mask_check(struct se_cmd
*se_cmd
)
2729 switch (se_cmd
->prot_op
) {
2730 case TARGET_PROT_DIN_INSERT
:
2731 case TARGET_PROT_DOUT_INSERT
:
2732 case TARGET_PROT_DIN_STRIP
:
2733 case TARGET_PROT_DOUT_STRIP
:
2734 case TARGET_PROT_DIN_PASS
:
2735 case TARGET_PROT_DOUT_PASS
:
2744 * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command
2747 qla_tgt_set_dif_tags(struct qla_tgt_cmd
*cmd
, struct crc_context
*ctx
,
2748 uint16_t *pfw_prot_opts
)
2750 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
2751 uint32_t lba
= 0xffffffff & se_cmd
->t_task_lba
;
2752 scsi_qla_host_t
*vha
= cmd
->tgt
->vha
;
2753 struct qla_hw_data
*ha
= vha
->hw
;
2757 * wait till Mode Sense/Select cmd, modepage Ah, subpage 2
2758 * have been immplemented by TCM, before AppTag is avail.
2759 * Look for modesense_handlers[]
2762 ctx
->app_tag_mask
[0] = 0x0;
2763 ctx
->app_tag_mask
[1] = 0x0;
2765 if (IS_PI_UNINIT_CAPABLE(ha
)) {
2766 if ((se_cmd
->prot_type
== TARGET_DIF_TYPE1_PROT
) ||
2767 (se_cmd
->prot_type
== TARGET_DIF_TYPE2_PROT
))
2768 *pfw_prot_opts
|= PO_DIS_VALD_APP_ESC
;
2769 else if (se_cmd
->prot_type
== TARGET_DIF_TYPE3_PROT
)
2770 *pfw_prot_opts
|= PO_DIS_VALD_APP_REF_ESC
;
2773 t32
= ha
->tgt
.tgt_ops
->get_dif_tags(cmd
, pfw_prot_opts
);
2775 switch (se_cmd
->prot_type
) {
2776 case TARGET_DIF_TYPE0_PROT
:
2778 * No check for ql2xenablehba_err_chk, as it
2779 * would be an I/O error if hba tag generation
2782 ctx
->ref_tag
= cpu_to_le32(lba
);
2783 /* enable ALL bytes of the ref tag */
2784 ctx
->ref_tag_mask
[0] = 0xff;
2785 ctx
->ref_tag_mask
[1] = 0xff;
2786 ctx
->ref_tag_mask
[2] = 0xff;
2787 ctx
->ref_tag_mask
[3] = 0xff;
2789 case TARGET_DIF_TYPE1_PROT
:
2791 * For TYPE 1 protection: 16 bit GUARD tag, 32 bit
2792 * REF tag, and 16 bit app tag.
2794 ctx
->ref_tag
= cpu_to_le32(lba
);
2795 if (!qla_tgt_ref_mask_check(se_cmd
) ||
2796 !(ha
->tgt
.tgt_ops
->chk_dif_tags(t32
))) {
2797 *pfw_prot_opts
|= PO_DIS_REF_TAG_VALD
;
2800 /* enable ALL bytes of the ref tag */
2801 ctx
->ref_tag_mask
[0] = 0xff;
2802 ctx
->ref_tag_mask
[1] = 0xff;
2803 ctx
->ref_tag_mask
[2] = 0xff;
2804 ctx
->ref_tag_mask
[3] = 0xff;
2806 case TARGET_DIF_TYPE2_PROT
:
2808 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF
2809 * tag has to match LBA in CDB + N
2811 ctx
->ref_tag
= cpu_to_le32(lba
);
2812 if (!qla_tgt_ref_mask_check(se_cmd
) ||
2813 !(ha
->tgt
.tgt_ops
->chk_dif_tags(t32
))) {
2814 *pfw_prot_opts
|= PO_DIS_REF_TAG_VALD
;
2817 /* enable ALL bytes of the ref tag */
2818 ctx
->ref_tag_mask
[0] = 0xff;
2819 ctx
->ref_tag_mask
[1] = 0xff;
2820 ctx
->ref_tag_mask
[2] = 0xff;
2821 ctx
->ref_tag_mask
[3] = 0xff;
2823 case TARGET_DIF_TYPE3_PROT
:
2824 /* For TYPE 3 protection: 16 bit GUARD only */
2825 *pfw_prot_opts
|= PO_DIS_REF_TAG_VALD
;
2826 ctx
->ref_tag_mask
[0] = ctx
->ref_tag_mask
[1] =
2827 ctx
->ref_tag_mask
[2] = ctx
->ref_tag_mask
[3] = 0x00;
2833 qlt_build_ctio_crc2_pkt(struct qla_qpair
*qpair
, struct qla_tgt_prm
*prm
)
2836 uint32_t transfer_length
= 0;
2837 uint32_t data_bytes
;
2839 uint8_t bundling
= 1;
2841 struct crc_context
*crc_ctx_pkt
= NULL
;
2842 struct qla_hw_data
*ha
;
2843 struct ctio_crc2_to_fw
*pkt
;
2844 dma_addr_t crc_ctx_dma
;
2845 uint16_t fw_prot_opts
= 0;
2846 struct qla_tgt_cmd
*cmd
= prm
->cmd
;
2847 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
2849 struct atio_from_isp
*atio
= &prm
->cmd
->atio
;
2850 struct qla_tc_param tc
;
2852 scsi_qla_host_t
*vha
= cmd
->vha
;
2856 pkt
= (struct ctio_crc2_to_fw
*)qpair
->req
->ring_ptr
;
2858 memset(pkt
, 0, sizeof(*pkt
));
2860 ql_dbg_qp(ql_dbg_tgt
, cmd
->qpair
, 0xe071,
2861 "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n",
2862 cmd
->vp_idx
, __func__
, se_cmd
, se_cmd
->prot_op
,
2863 prm
->prot_sg
, prm
->prot_seg_cnt
, se_cmd
->t_task_lba
);
2865 if ((se_cmd
->prot_op
== TARGET_PROT_DIN_INSERT
) ||
2866 (se_cmd
->prot_op
== TARGET_PROT_DOUT_STRIP
))
2869 /* Compute dif len and adjust data len to incude protection */
2870 data_bytes
= cmd
->bufflen
;
2871 dif_bytes
= (data_bytes
/ cmd
->blk_sz
) * 8;
2873 switch (se_cmd
->prot_op
) {
2874 case TARGET_PROT_DIN_INSERT
:
2875 case TARGET_PROT_DOUT_STRIP
:
2876 transfer_length
= data_bytes
;
2877 if (cmd
->prot_sg_cnt
)
2878 data_bytes
+= dif_bytes
;
2880 case TARGET_PROT_DIN_STRIP
:
2881 case TARGET_PROT_DOUT_INSERT
:
2882 case TARGET_PROT_DIN_PASS
:
2883 case TARGET_PROT_DOUT_PASS
:
2884 transfer_length
= data_bytes
+ dif_bytes
;
2891 if (!qlt_hba_err_chk_enabled(se_cmd
))
2892 fw_prot_opts
|= 0x10; /* Disable Guard tag checking */
2893 /* HBA error checking enabled */
2894 else if (IS_PI_UNINIT_CAPABLE(ha
)) {
2895 if ((se_cmd
->prot_type
== TARGET_DIF_TYPE1_PROT
) ||
2896 (se_cmd
->prot_type
== TARGET_DIF_TYPE2_PROT
))
2897 fw_prot_opts
|= PO_DIS_VALD_APP_ESC
;
2898 else if (se_cmd
->prot_type
== TARGET_DIF_TYPE3_PROT
)
2899 fw_prot_opts
|= PO_DIS_VALD_APP_REF_ESC
;
2902 switch (se_cmd
->prot_op
) {
2903 case TARGET_PROT_DIN_INSERT
:
2904 case TARGET_PROT_DOUT_INSERT
:
2905 fw_prot_opts
|= PO_MODE_DIF_INSERT
;
2907 case TARGET_PROT_DIN_STRIP
:
2908 case TARGET_PROT_DOUT_STRIP
:
2909 fw_prot_opts
|= PO_MODE_DIF_REMOVE
;
2911 case TARGET_PROT_DIN_PASS
:
2912 case TARGET_PROT_DOUT_PASS
:
2913 fw_prot_opts
|= PO_MODE_DIF_PASS
;
2914 /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */
2916 default:/* Normal Request */
2917 fw_prot_opts
|= PO_MODE_DIF_PASS
;
2922 /* Update entry type to indicate Command Type CRC_2 IOCB */
2923 pkt
->entry_type
= CTIO_CRC2
;
2924 pkt
->entry_count
= 1;
2925 pkt
->vp_index
= cmd
->vp_idx
;
2927 h
= qlt_make_handle(qpair
);
2928 if (unlikely(h
== QLA_TGT_NULL_HANDLE
)) {
2930 * CTIO type 7 from the firmware doesn't provide a way to
2931 * know the initiator's LOOP ID, hence we can't find
2932 * the session and, so, the command.
2936 qpair
->req
->outstanding_cmds
[h
] = (srb_t
*)prm
->cmd
;
2938 pkt
->handle
= MAKE_HANDLE(qpair
->req
->id
, h
);
2939 pkt
->handle
|= CTIO_COMPLETION_HANDLE_MARK
;
2940 pkt
->nport_handle
= cpu_to_le16(prm
->cmd
->loop_id
);
2941 pkt
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2942 pkt
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2943 pkt
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2944 pkt
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2945 pkt
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2947 /* silence compile warning */
2948 t16
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2949 pkt
->ox_id
= cpu_to_le16(t16
);
2951 t16
= (atio
->u
.isp24
.attr
<< 9);
2952 pkt
->flags
|= cpu_to_le16(t16
);
2953 pkt
->relative_offset
= cpu_to_le32(prm
->cmd
->offset
);
2955 /* Set transfer direction */
2956 if (cmd
->dma_data_direction
== DMA_TO_DEVICE
)
2957 pkt
->flags
= cpu_to_le16(CTIO7_FLAGS_DATA_IN
);
2958 else if (cmd
->dma_data_direction
== DMA_FROM_DEVICE
)
2959 pkt
->flags
= cpu_to_le16(CTIO7_FLAGS_DATA_OUT
);
2961 pkt
->dseg_count
= prm
->tot_dsds
;
2962 /* Fibre channel byte count */
2963 pkt
->transfer_length
= cpu_to_le32(transfer_length
);
2965 /* ----- CRC context -------- */
2967 /* Allocate CRC context from global pool */
2968 crc_ctx_pkt
= cmd
->ctx
=
2969 dma_pool_alloc(ha
->dl_dma_pool
, GFP_ATOMIC
, &crc_ctx_dma
);
2972 goto crc_queuing_error
;
2974 /* Zero out CTX area. */
2975 clr_ptr
= (uint8_t *)crc_ctx_pkt
;
2976 memset(clr_ptr
, 0, sizeof(*crc_ctx_pkt
));
2978 crc_ctx_pkt
->crc_ctx_dma
= crc_ctx_dma
;
2979 INIT_LIST_HEAD(&crc_ctx_pkt
->dsd_list
);
2982 crc_ctx_pkt
->handle
= pkt
->handle
;
2984 qla_tgt_set_dif_tags(cmd
, crc_ctx_pkt
, &fw_prot_opts
);
2986 pkt
->crc_context_address
[0] = cpu_to_le32(LSD(crc_ctx_dma
));
2987 pkt
->crc_context_address
[1] = cpu_to_le32(MSD(crc_ctx_dma
));
2988 pkt
->crc_context_len
= CRC_CONTEXT_LEN_FW
;
2991 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.nobundling
.data_address
;
2994 * Configure Bundling if we need to fetch interlaving
2995 * protection PCI accesses
2997 fw_prot_opts
|= PO_ENABLE_DIF_BUNDLING
;
2998 crc_ctx_pkt
->u
.bundling
.dif_byte_count
= cpu_to_le32(dif_bytes
);
2999 crc_ctx_pkt
->u
.bundling
.dseg_count
=
3000 cpu_to_le16(prm
->tot_dsds
- prm
->prot_seg_cnt
);
3001 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.bundling
.data_address
;
3004 /* Finish the common fields of CRC pkt */
3005 crc_ctx_pkt
->blk_size
= cpu_to_le16(cmd
->blk_sz
);
3006 crc_ctx_pkt
->prot_opts
= cpu_to_le16(fw_prot_opts
);
3007 crc_ctx_pkt
->byte_count
= cpu_to_le32(data_bytes
);
3008 crc_ctx_pkt
->guard_seed
= cpu_to_le16(0);
3010 memset((uint8_t *)&tc
, 0 , sizeof(tc
));
3012 tc
.blk_sz
= cmd
->blk_sz
;
3013 tc
.bufflen
= cmd
->bufflen
;
3015 tc
.prot_sg
= cmd
->prot_sg
;
3016 tc
.ctx
= crc_ctx_pkt
;
3017 tc
.ctx_dsd_alloced
= &cmd
->ctx_dsd_alloced
;
3019 /* Walks data segments */
3020 pkt
->flags
|= cpu_to_le16(CTIO7_FLAGS_DSD_PTR
);
3022 if (!bundling
&& prm
->prot_seg_cnt
) {
3023 if (qla24xx_walk_and_build_sglist_no_difb(ha
, NULL
, cur_dsd
,
3024 prm
->tot_dsds
, &tc
))
3025 goto crc_queuing_error
;
3026 } else if (qla24xx_walk_and_build_sglist(ha
, NULL
, cur_dsd
,
3027 (prm
->tot_dsds
- prm
->prot_seg_cnt
), &tc
))
3028 goto crc_queuing_error
;
3030 if (bundling
&& prm
->prot_seg_cnt
) {
3031 /* Walks dif segments */
3032 pkt
->add_flags
|= CTIO_CRC2_AF_DIF_DSD_ENA
;
3034 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.bundling
.dif_address
;
3035 if (qla24xx_walk_and_build_prot_sglist(ha
, NULL
, cur_dsd
,
3036 prm
->prot_seg_cnt
, &tc
))
3037 goto crc_queuing_error
;
3042 /* Cleanup will be performed by the caller */
3043 qpair
->req
->outstanding_cmds
[h
] = NULL
;
3045 return QLA_FUNCTION_FAILED
;
3049 * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and *
3050 * QLA_TGT_XMIT_STATUS for >= 24xx silicon
3052 int qlt_xmit_response(struct qla_tgt_cmd
*cmd
, int xmit_type
,
3053 uint8_t scsi_status
)
3055 struct scsi_qla_host
*vha
= cmd
->vha
;
3056 struct qla_qpair
*qpair
= cmd
->qpair
;
3057 struct ctio7_to_24xx
*pkt
;
3058 struct qla_tgt_prm prm
;
3059 uint32_t full_req_cnt
= 0;
3060 unsigned long flags
= 0;
3063 if (cmd
->sess
&& cmd
->sess
->deleted
) {
3064 cmd
->state
= QLA_TGT_STATE_PROCESSED
;
3065 if (cmd
->sess
->logout_completed
)
3066 /* no need to terminate. FW already freed exchange. */
3067 qlt_abort_cmd_on_host_reset(cmd
->vha
, cmd
);
3069 qlt_send_term_exchange(qpair
, cmd
, &cmd
->atio
, 0, 0);
3073 ql_dbg_qp(ql_dbg_tgt
, qpair
, 0xe018,
3074 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p] qp %d\n",
3075 (xmit_type
& QLA_TGT_XMIT_STATUS
) ?
3076 1 : 0, cmd
->bufflen
, cmd
->sg_cnt
, cmd
->dma_data_direction
,
3077 &cmd
->se_cmd
, qpair
->id
);
3079 res
= qlt_pre_xmit_response(cmd
, &prm
, xmit_type
, scsi_status
,
3081 if (unlikely(res
!= 0)) {
3085 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
3087 if (xmit_type
== QLA_TGT_XMIT_STATUS
)
3088 qpair
->tgt_counters
.core_qla_snd_status
++;
3090 qpair
->tgt_counters
.core_qla_que_buf
++;
3092 if (!qpair
->fw_started
|| cmd
->reset_count
!= qpair
->chip_reset
) {
3094 * Either the port is not online or this request was from
3095 * previous life, just abort the processing.
3097 cmd
->state
= QLA_TGT_STATE_PROCESSED
;
3098 qlt_abort_cmd_on_host_reset(cmd
->vha
, cmd
);
3099 ql_dbg_qp(ql_dbg_async
, qpair
, 0xe101,
3100 "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n",
3101 vha
->flags
.online
, qla2x00_reset_active(vha
),
3102 cmd
->reset_count
, qpair
->chip_reset
);
3103 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
3107 /* Does F/W have an IOCBs for this request */
3108 res
= qlt_check_reserve_free_req(qpair
, full_req_cnt
);
3110 goto out_unmap_unlock
;
3112 if (cmd
->se_cmd
.prot_op
&& (xmit_type
& QLA_TGT_XMIT_DATA
))
3113 res
= qlt_build_ctio_crc2_pkt(qpair
, &prm
);
3115 res
= qlt_24xx_build_ctio_pkt(qpair
, &prm
);
3116 if (unlikely(res
!= 0)) {
3117 qpair
->req
->cnt
+= full_req_cnt
;
3118 goto out_unmap_unlock
;
3121 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
3123 if (qlt_has_data(cmd
) && (xmit_type
& QLA_TGT_XMIT_DATA
)) {
3124 pkt
->u
.status0
.flags
|=
3125 cpu_to_le16(CTIO7_FLAGS_DATA_IN
|
3126 CTIO7_FLAGS_STATUS_MODE_0
);
3128 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
)
3129 qlt_load_data_segments(&prm
);
3131 if (prm
.add_status_pkt
== 0) {
3132 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
3133 pkt
->u
.status0
.scsi_status
=
3134 cpu_to_le16(prm
.rq_result
);
3135 pkt
->u
.status0
.residual
=
3136 cpu_to_le32(prm
.residual
);
3137 pkt
->u
.status0
.flags
|= cpu_to_le16(
3138 CTIO7_FLAGS_SEND_STATUS
);
3139 if (qlt_need_explicit_conf(cmd
, 0)) {
3140 pkt
->u
.status0
.flags
|=
3142 CTIO7_FLAGS_EXPLICIT_CONFORM
|
3143 CTIO7_FLAGS_CONFORM_REQ
);
3149 * We have already made sure that there is sufficient
3150 * amount of request entries to not drop HW lock in
3153 struct ctio7_to_24xx
*ctio
=
3154 (struct ctio7_to_24xx
*)qlt_get_req_pkt(
3157 ql_dbg_qp(ql_dbg_tgt
, qpair
, 0x305e,
3158 "Building additional status packet 0x%p.\n",
3162 * T10Dif: ctio_crc2_to_fw overlay ontop of
3165 memcpy(ctio
, pkt
, sizeof(*ctio
));
3166 /* reset back to CTIO7 */
3167 ctio
->entry_count
= 1;
3168 ctio
->entry_type
= CTIO_TYPE7
;
3169 ctio
->dseg_count
= 0;
3170 ctio
->u
.status1
.flags
&= ~cpu_to_le16(
3171 CTIO7_FLAGS_DATA_IN
);
3173 /* Real finish is ctio_m1's finish */
3174 pkt
->handle
|= CTIO_INTERMEDIATE_HANDLE_MARK
;
3175 pkt
->u
.status0
.flags
|= cpu_to_le16(
3176 CTIO7_FLAGS_DONT_RET_CTIO
);
3178 /* qlt_24xx_init_ctio_to_isp will correct
3179 * all neccessary fields that's part of CTIO7.
3180 * There should be no residual of CTIO-CRC2 data.
3182 qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx
*)ctio
,
3186 qlt_24xx_init_ctio_to_isp(pkt
, &prm
);
3189 cmd
->state
= QLA_TGT_STATE_PROCESSED
; /* Mid-level is done processing */
3190 cmd
->cmd_sent_to_fw
= 1;
3192 /* Memory Barrier */
3194 if (qpair
->reqq_start_iocbs
)
3195 qpair
->reqq_start_iocbs(qpair
);
3197 qla2x00_start_iocbs(vha
, qpair
->req
);
3198 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
3203 qlt_unmap_sg(vha
, cmd
);
3204 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
3208 EXPORT_SYMBOL(qlt_xmit_response
);
3210 int qlt_rdy_to_xfer(struct qla_tgt_cmd
*cmd
)
3212 struct ctio7_to_24xx
*pkt
;
3213 struct scsi_qla_host
*vha
= cmd
->vha
;
3214 struct qla_tgt
*tgt
= cmd
->tgt
;
3215 struct qla_tgt_prm prm
;
3216 unsigned long flags
= 0;
3218 struct qla_qpair
*qpair
= cmd
->qpair
;
3220 memset(&prm
, 0, sizeof(prm
));
3226 /* Calculate number of entries and segments required */
3227 if (qlt_pci_map_calc_cnt(&prm
) != 0)
3230 if (!qpair
->fw_started
|| (cmd
->reset_count
!= qpair
->chip_reset
) ||
3231 (cmd
->sess
&& cmd
->sess
->deleted
)) {
3233 * Either the port is not online or this request was from
3234 * previous life, just abort the processing.
3236 cmd
->state
= QLA_TGT_STATE_NEED_DATA
;
3237 qlt_abort_cmd_on_host_reset(cmd
->vha
, cmd
);
3238 ql_dbg_qp(ql_dbg_async
, qpair
, 0xe102,
3239 "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n",
3240 vha
->flags
.online
, qla2x00_reset_active(vha
),
3241 cmd
->reset_count
, qpair
->chip_reset
);
3245 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
3246 /* Does F/W have an IOCBs for this request */
3247 res
= qlt_check_reserve_free_req(qpair
, prm
.req_cnt
);
3249 goto out_unlock_free_unmap
;
3250 if (cmd
->se_cmd
.prot_op
)
3251 res
= qlt_build_ctio_crc2_pkt(qpair
, &prm
);
3253 res
= qlt_24xx_build_ctio_pkt(qpair
, &prm
);
3255 if (unlikely(res
!= 0)) {
3256 qpair
->req
->cnt
+= prm
.req_cnt
;
3257 goto out_unlock_free_unmap
;
3260 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
3261 pkt
->u
.status0
.flags
|= cpu_to_le16(CTIO7_FLAGS_DATA_OUT
|
3262 CTIO7_FLAGS_STATUS_MODE_0
);
3264 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
)
3265 qlt_load_data_segments(&prm
);
3267 cmd
->state
= QLA_TGT_STATE_NEED_DATA
;
3268 cmd
->cmd_sent_to_fw
= 1;
3270 /* Memory Barrier */
3272 if (qpair
->reqq_start_iocbs
)
3273 qpair
->reqq_start_iocbs(qpair
);
3275 qla2x00_start_iocbs(vha
, qpair
->req
);
3276 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
3280 out_unlock_free_unmap
:
3281 qlt_unmap_sg(vha
, cmd
);
3282 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
3286 EXPORT_SYMBOL(qlt_rdy_to_xfer
);
3290 * it is assumed either hardware_lock or qpair lock is held.
3293 qlt_handle_dif_error(struct qla_qpair
*qpair
, struct qla_tgt_cmd
*cmd
,
3294 struct ctio_crc_from_fw
*sts
)
3296 uint8_t *ap
= &sts
->actual_dif
[0];
3297 uint8_t *ep
= &sts
->expected_dif
[0];
3298 uint64_t lba
= cmd
->se_cmd
.t_task_lba
;
3299 uint8_t scsi_status
, sense_key
, asc
, ascq
;
3300 unsigned long flags
;
3301 struct scsi_qla_host
*vha
= cmd
->vha
;
3303 cmd
->trc_flags
|= TRC_DIF_ERR
;
3305 cmd
->a_guard
= be16_to_cpu(*(uint16_t *)(ap
+ 0));
3306 cmd
->a_app_tag
= be16_to_cpu(*(uint16_t *)(ap
+ 2));
3307 cmd
->a_ref_tag
= be32_to_cpu(*(uint32_t *)(ap
+ 4));
3309 cmd
->e_guard
= be16_to_cpu(*(uint16_t *)(ep
+ 0));
3310 cmd
->e_app_tag
= be16_to_cpu(*(uint16_t *)(ep
+ 2));
3311 cmd
->e_ref_tag
= be32_to_cpu(*(uint32_t *)(ep
+ 4));
3313 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xf075,
3314 "%s: aborted %d state %d\n", __func__
, cmd
->aborted
, cmd
->state
);
3316 scsi_status
= sense_key
= asc
= ascq
= 0;
3318 /* check appl tag */
3319 if (cmd
->e_app_tag
!= cmd
->a_app_tag
) {
3320 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe00d,
3321 "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]",
3322 cmd
->cdb
[0], lba
, (lba
+cmd
->num_blks
), cmd
->num_blks
,
3323 cmd
->a_ref_tag
, cmd
->e_ref_tag
, cmd
->a_app_tag
,
3324 cmd
->e_app_tag
, cmd
->a_guard
, cmd
->e_guard
, cmd
,
3325 cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
);
3327 cmd
->dif_err_code
= DIF_ERR_APP
;
3328 scsi_status
= SAM_STAT_CHECK_CONDITION
;
3329 sense_key
= ABORTED_COMMAND
;
3335 if (cmd
->e_ref_tag
!= cmd
->a_ref_tag
) {
3336 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe00e,
3337 "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] ",
3338 cmd
->cdb
[0], lba
, (lba
+cmd
->num_blks
), cmd
->num_blks
,
3339 cmd
->a_ref_tag
, cmd
->e_ref_tag
, cmd
->a_app_tag
,
3340 cmd
->e_app_tag
, cmd
->a_guard
, cmd
->e_guard
, cmd
,
3341 cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
);
3343 cmd
->dif_err_code
= DIF_ERR_REF
;
3344 scsi_status
= SAM_STAT_CHECK_CONDITION
;
3345 sense_key
= ABORTED_COMMAND
;
3352 if (cmd
->e_guard
!= cmd
->a_guard
) {
3353 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe012,
3354 "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]",
3355 cmd
->cdb
[0], lba
, (lba
+cmd
->num_blks
), cmd
->num_blks
,
3356 cmd
->a_ref_tag
, cmd
->e_ref_tag
, cmd
->a_app_tag
,
3357 cmd
->e_app_tag
, cmd
->a_guard
, cmd
->e_guard
, cmd
,
3358 cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
);
3360 cmd
->dif_err_code
= DIF_ERR_GRD
;
3361 scsi_status
= SAM_STAT_CHECK_CONDITION
;
3362 sense_key
= ABORTED_COMMAND
;
3367 switch (cmd
->state
) {
3368 case QLA_TGT_STATE_NEED_DATA
:
3369 /* handle_data will load DIF error code */
3370 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3371 vha
->hw
->tgt
.tgt_ops
->handle_data(cmd
);
3374 spin_lock_irqsave(&cmd
->cmd_lock
, flags
);
3376 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3377 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
3380 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3382 qlt_send_resp_ctio(qpair
, cmd
, scsi_status
, sense_key
, asc
,
3384 /* assume scsi status gets out on the wire.
3385 * Will not wait for completion.
3387 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
3392 /* If hardware_lock held on entry, might drop it, then reaquire */
3393 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
3394 static int __qlt_send_term_imm_notif(struct scsi_qla_host
*vha
,
3395 struct imm_ntfy_from_isp
*ntfy
)
3397 struct nack_to_isp
*nack
;
3398 struct qla_hw_data
*ha
= vha
->hw
;
3402 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xe01c,
3403 "Sending TERM ELS CTIO (ha=%p)\n", ha
);
3405 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
3407 ql_dbg(ql_dbg_tgt
, vha
, 0xe080,
3408 "qla_target(%d): %s failed: unable to allocate "
3409 "request packet\n", vha
->vp_idx
, __func__
);
3413 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
3414 pkt
->entry_count
= 1;
3415 pkt
->handle
= QLA_TGT_SKIP_HANDLE
;
3417 nack
= (struct nack_to_isp
*)pkt
;
3418 nack
->ox_id
= ntfy
->ox_id
;
3420 nack
->u
.isp24
.nport_handle
= ntfy
->u
.isp24
.nport_handle
;
3421 if (le16_to_cpu(ntfy
->u
.isp24
.status
) == IMM_NTFY_ELS
) {
3422 nack
->u
.isp24
.flags
= ntfy
->u
.isp24
.flags
&
3423 __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB
);
3427 nack
->u
.isp24
.flags
|=
3428 __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE
);
3430 nack
->u
.isp24
.srr_rx_id
= ntfy
->u
.isp24
.srr_rx_id
;
3431 nack
->u
.isp24
.status
= ntfy
->u
.isp24
.status
;
3432 nack
->u
.isp24
.status_subcode
= ntfy
->u
.isp24
.status_subcode
;
3433 nack
->u
.isp24
.fw_handle
= ntfy
->u
.isp24
.fw_handle
;
3434 nack
->u
.isp24
.exchange_address
= ntfy
->u
.isp24
.exchange_address
;
3435 nack
->u
.isp24
.srr_rel_offs
= ntfy
->u
.isp24
.srr_rel_offs
;
3436 nack
->u
.isp24
.srr_ui
= ntfy
->u
.isp24
.srr_ui
;
3437 nack
->u
.isp24
.vp_index
= ntfy
->u
.isp24
.vp_index
;
3439 qla2x00_start_iocbs(vha
, vha
->req
);
3443 static void qlt_send_term_imm_notif(struct scsi_qla_host
*vha
,
3444 struct imm_ntfy_from_isp
*imm
, int ha_locked
)
3446 unsigned long flags
= 0;
3450 rc
= __qlt_send_term_imm_notif(vha
, imm
);
3454 qlt_alloc_qfull_cmd(vha
, imm
, 0, 0);
3462 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
3463 rc
= __qlt_send_term_imm_notif(vha
, imm
);
3467 qlt_alloc_qfull_cmd(vha
, imm
, 0, 0);
3472 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
3476 * If hardware_lock held on entry, might drop it, then reaquire
3477 * This function sends the appropriate CTIO to ISP 2xxx or 24xx
3479 static int __qlt_send_term_exchange(struct qla_qpair
*qpair
,
3480 struct qla_tgt_cmd
*cmd
,
3481 struct atio_from_isp
*atio
)
3483 struct scsi_qla_host
*vha
= qpair
->vha
;
3484 struct ctio7_to_24xx
*ctio24
;
3485 struct qla_hw_data
*ha
= vha
->hw
;
3490 ql_dbg(ql_dbg_tgt
, vha
, 0xe009, "Sending TERM EXCH CTIO (ha=%p)\n", ha
);
3495 pkt
= (request_t
*)qla2x00_alloc_iocbs_ready(qpair
, NULL
);
3497 ql_dbg(ql_dbg_tgt
, vha
, 0xe050,
3498 "qla_target(%d): %s failed: unable to allocate "
3499 "request packet\n", vha
->vp_idx
, __func__
);
3504 if (cmd
->state
< QLA_TGT_STATE_PROCESSED
) {
3505 ql_dbg(ql_dbg_tgt
, vha
, 0xe051,
3506 "qla_target(%d): Terminating cmd %p with "
3507 "incorrect state %d\n", vha
->vp_idx
, cmd
,
3513 qpair
->tgt_counters
.num_term_xchg_sent
++;
3514 pkt
->entry_count
= 1;
3515 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
3517 ctio24
= (struct ctio7_to_24xx
*)pkt
;
3518 ctio24
->entry_type
= CTIO_TYPE7
;
3519 ctio24
->nport_handle
= CTIO7_NHANDLE_UNRECOGNIZED
;
3520 ctio24
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
3521 ctio24
->vp_index
= vha
->vp_idx
;
3522 ctio24
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
3523 ctio24
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
3524 ctio24
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
3525 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
3526 temp
= (atio
->u
.isp24
.attr
<< 9) | CTIO7_FLAGS_STATUS_MODE_1
|
3527 CTIO7_FLAGS_TERMINATE
;
3528 ctio24
->u
.status1
.flags
= cpu_to_le16(temp
);
3529 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
3530 ctio24
->u
.status1
.ox_id
= cpu_to_le16(temp
);
3532 /* Most likely, it isn't needed */
3533 ctio24
->u
.status1
.residual
= get_unaligned((uint32_t *)
3534 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
3535 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]);
3536 if (ctio24
->u
.status1
.residual
!= 0)
3537 ctio24
->u
.status1
.scsi_status
|= SS_RESIDUAL_UNDER
;
3539 /* Memory Barrier */
3541 if (qpair
->reqq_start_iocbs
)
3542 qpair
->reqq_start_iocbs(qpair
);
3544 qla2x00_start_iocbs(vha
, qpair
->req
);
3548 static void qlt_send_term_exchange(struct qla_qpair
*qpair
,
3549 struct qla_tgt_cmd
*cmd
, struct atio_from_isp
*atio
, int ha_locked
,
3552 struct scsi_qla_host
*vha
;
3553 unsigned long flags
= 0;
3556 /* why use different vha? NPIV */
3563 rc
= __qlt_send_term_exchange(qpair
, cmd
, atio
);
3565 qlt_alloc_qfull_cmd(vha
, atio
, 0, 0);
3568 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
3569 rc
= __qlt_send_term_exchange(qpair
, cmd
, atio
);
3571 qlt_alloc_qfull_cmd(vha
, atio
, 0, 0);
3574 if (cmd
&& !ul_abort
&& !cmd
->aborted
) {
3576 qlt_unmap_sg(vha
, cmd
);
3577 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
3581 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
3586 static void qlt_init_term_exchange(struct scsi_qla_host
*vha
)
3588 struct list_head free_list
;
3589 struct qla_tgt_cmd
*cmd
, *tcmd
;
3591 vha
->hw
->tgt
.leak_exchg_thresh_hold
=
3592 (vha
->hw
->cur_fw_xcb_count
/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT
;
3595 if (!list_empty(&vha
->hw
->tgt
.q_full_list
)) {
3596 INIT_LIST_HEAD(&free_list
);
3597 list_splice_init(&vha
->hw
->tgt
.q_full_list
, &free_list
);
3599 list_for_each_entry_safe(cmd
, tcmd
, &free_list
, cmd_list
) {
3600 list_del(&cmd
->cmd_list
);
3601 /* This cmd was never sent to TCM. There is no need
3602 * to schedule free or call free_cmd
3605 vha
->hw
->tgt
.num_qfull_cmds_alloc
--;
3608 vha
->hw
->tgt
.num_qfull_cmds_dropped
= 0;
3611 static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host
*vha
)
3613 uint32_t total_leaked
;
3615 total_leaked
= vha
->hw
->tgt
.num_qfull_cmds_dropped
;
3617 if (vha
->hw
->tgt
.leak_exchg_thresh_hold
&&
3618 (total_leaked
> vha
->hw
->tgt
.leak_exchg_thresh_hold
)) {
3620 ql_dbg(ql_dbg_tgt
, vha
, 0xe079,
3621 "Chip reset due to exchange starvation: %d/%d.\n",
3622 total_leaked
, vha
->hw
->cur_fw_xcb_count
);
3624 if (IS_P3P_TYPE(vha
->hw
))
3625 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
3627 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3628 qla2xxx_wake_dpc(vha
);
3633 int qlt_abort_cmd(struct qla_tgt_cmd
*cmd
)
3635 struct qla_tgt
*tgt
= cmd
->tgt
;
3636 struct scsi_qla_host
*vha
= tgt
->vha
;
3637 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
3638 unsigned long flags
;
3640 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf014,
3641 "qla_target(%d): terminating exchange for aborted cmd=%p "
3642 "(se_cmd=%p, tag=%llu)", vha
->vp_idx
, cmd
, &cmd
->se_cmd
,
3645 spin_lock_irqsave(&cmd
->cmd_lock
, flags
);
3647 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3649 * It's normal to see 2 calls in this path:
3650 * 1) XFER Rdy completion + CMD_T_ABORT
3651 * 2) TCM TMR - drain_state_list
3653 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf016,
3654 "multiple abort. %p transport_state %x, t_state %x, "
3655 "se_cmd_flags %x\n", cmd
, cmd
->se_cmd
.transport_state
,
3656 cmd
->se_cmd
.t_state
, cmd
->se_cmd
.se_cmd_flags
);
3660 cmd
->trc_flags
|= TRC_ABORT
;
3661 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3663 qlt_send_term_exchange(cmd
->qpair
, cmd
, &cmd
->atio
, 0, 1);
3666 EXPORT_SYMBOL(qlt_abort_cmd
);
3668 void qlt_free_cmd(struct qla_tgt_cmd
*cmd
)
3670 struct fc_port
*sess
= cmd
->sess
;
3672 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe074,
3673 "%s: se_cmd[%p] ox_id %04x\n",
3674 __func__
, &cmd
->se_cmd
,
3675 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
3677 BUG_ON(cmd
->cmd_in_wq
);
3680 qlt_unmap_sg(cmd
->vha
, cmd
);
3683 qlt_decr_num_pend_cmds(cmd
->vha
);
3685 BUG_ON(cmd
->sg_mapped
);
3686 cmd
->jiffies_at_free
= get_jiffies_64();
3687 if (unlikely(cmd
->free_sg
))
3690 if (!sess
|| !sess
->se_sess
) {
3694 cmd
->jiffies_at_free
= get_jiffies_64();
3695 percpu_ida_free(&sess
->se_sess
->sess_tag_pool
, cmd
->se_cmd
.map_tag
);
3697 EXPORT_SYMBOL(qlt_free_cmd
);
3700 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3702 static int qlt_term_ctio_exchange(struct qla_qpair
*qpair
, void *ctio
,
3703 struct qla_tgt_cmd
*cmd
, uint32_t status
)
3706 struct scsi_qla_host
*vha
= qpair
->vha
;
3708 if (cmd
->se_cmd
.prot_op
)
3709 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe013,
3710 "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] "
3711 "se_cmd=%p tag[%x] op %#x/%s",
3713 cmd
->num_blks
, &cmd
->se_cmd
,
3714 cmd
->atio
.u
.isp24
.exchange_addr
,
3715 cmd
->se_cmd
.prot_op
,
3716 prot_op_str(cmd
->se_cmd
.prot_op
));
3719 struct ctio7_from_24xx
*c
= (struct ctio7_from_24xx
*)ctio
;
3721 cpu_to_le16(OF_TERM_EXCH
));
3726 qlt_term_ctio_exchange(qpair
, ctio
, cmd
, status
);
3732 /* ha->hardware_lock supposed to be held on entry */
3733 static struct qla_tgt_cmd
*qlt_ctio_to_cmd(struct scsi_qla_host
*vha
,
3734 struct rsp_que
*rsp
, uint32_t handle
, void *ctio
)
3736 struct qla_tgt_cmd
*cmd
= NULL
;
3737 struct req_que
*req
;
3738 int qid
= GET_QID(handle
);
3739 uint32_t h
= handle
& ~QLA_TGT_HANDLE_MASK
;
3741 if (unlikely(h
== QLA_TGT_SKIP_HANDLE
))
3744 if (qid
== rsp
->req
->id
) {
3746 } else if (vha
->hw
->req_q_map
[qid
]) {
3747 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0x1000a,
3748 "qla_target(%d): CTIO completion with different QID %d handle %x\n",
3749 vha
->vp_idx
, rsp
->id
, handle
);
3750 req
= vha
->hw
->req_q_map
[qid
];
3755 h
&= QLA_CMD_HANDLE_MASK
;
3757 if (h
!= QLA_TGT_NULL_HANDLE
) {
3758 if (unlikely(h
>= req
->num_outstanding_cmds
)) {
3759 ql_dbg(ql_dbg_tgt
, vha
, 0xe052,
3760 "qla_target(%d): Wrong handle %x received\n",
3761 vha
->vp_idx
, handle
);
3765 cmd
= (struct qla_tgt_cmd
*)req
->outstanding_cmds
[h
];
3766 if (unlikely(cmd
== NULL
)) {
3767 ql_dbg(ql_dbg_async
, vha
, 0xe053,
3768 "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n",
3769 vha
->vp_idx
, handle
, req
->id
, rsp
->id
);
3772 req
->outstanding_cmds
[h
] = NULL
;
3773 } else if (ctio
!= NULL
) {
3774 /* We can't get loop ID from CTIO7 */
3775 ql_dbg(ql_dbg_tgt
, vha
, 0xe054,
3776 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
3777 "support NULL handles\n", vha
->vp_idx
);
3784 /* hardware_lock should be held by caller. */
3786 qlt_abort_cmd_on_host_reset(struct scsi_qla_host
*vha
, struct qla_tgt_cmd
*cmd
)
3788 struct qla_hw_data
*ha
= vha
->hw
;
3791 qlt_unmap_sg(vha
, cmd
);
3793 /* TODO: fix debug message type and ids. */
3794 if (cmd
->state
== QLA_TGT_STATE_PROCESSED
) {
3795 ql_dbg(ql_dbg_io
, vha
, 0xff00,
3796 "HOST-ABORT: state=PROCESSED.\n");
3797 } else if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
3798 cmd
->write_data_transferred
= 0;
3799 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3801 ql_dbg(ql_dbg_io
, vha
, 0xff01,
3802 "HOST-ABORT: state=DATA_IN.\n");
3804 ha
->tgt
.tgt_ops
->handle_data(cmd
);
3807 ql_dbg(ql_dbg_io
, vha
, 0xff03,
3808 "HOST-ABORT: state=BAD(%d).\n",
3813 cmd
->trc_flags
|= TRC_FLUSH
;
3814 ha
->tgt
.tgt_ops
->free_cmd(cmd
);
3818 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3820 static void qlt_do_ctio_completion(struct scsi_qla_host
*vha
,
3821 struct rsp_que
*rsp
, uint32_t handle
, uint32_t status
, void *ctio
)
3823 struct qla_hw_data
*ha
= vha
->hw
;
3824 struct se_cmd
*se_cmd
;
3825 struct qla_tgt_cmd
*cmd
;
3826 struct qla_qpair
*qpair
= rsp
->qpair
;
3828 if (handle
& CTIO_INTERMEDIATE_HANDLE_MARK
) {
3829 /* That could happen only in case of an error/reset/abort */
3830 if (status
!= CTIO_SUCCESS
) {
3831 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01d,
3832 "Intermediate CTIO received"
3833 " (status %x)\n", status
);
3838 cmd
= qlt_ctio_to_cmd(vha
, rsp
, handle
, ctio
);
3842 se_cmd
= &cmd
->se_cmd
;
3843 cmd
->cmd_sent_to_fw
= 0;
3845 qlt_unmap_sg(vha
, cmd
);
3847 if (unlikely(status
!= CTIO_SUCCESS
)) {
3848 switch (status
& 0xFFFF) {
3849 case CTIO_LIP_RESET
:
3850 case CTIO_TARGET_RESET
:
3852 /* driver request abort via Terminate exchange */
3854 case CTIO_INVALID_RX_ID
:
3856 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf058,
3857 "qla_target(%d): CTIO with "
3858 "status %#x received, state %x, se_cmd %p, "
3859 "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
3860 "TIMEOUT=b, INVALID_RX_ID=8)\n", vha
->vp_idx
,
3861 status
, cmd
->state
, se_cmd
);
3864 case CTIO_PORT_LOGGED_OUT
:
3865 case CTIO_PORT_UNAVAILABLE
:
3868 (status
& 0xFFFF) == CTIO_PORT_LOGGED_OUT
;
3870 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf059,
3871 "qla_target(%d): CTIO with %s status %x "
3872 "received (state %x, se_cmd %p)\n", vha
->vp_idx
,
3873 logged_out
? "PORT LOGGED OUT" : "PORT UNAVAILABLE",
3874 status
, cmd
->state
, se_cmd
);
3876 if (logged_out
&& cmd
->sess
) {
3878 * Session is already logged out, but we need
3879 * to notify initiator, who's not aware of this
3881 cmd
->sess
->logout_on_delete
= 0;
3882 cmd
->sess
->send_els_logo
= 1;
3883 ql_dbg(ql_dbg_disc
, vha
, 0x20f8,
3884 "%s %d %8phC post del sess\n",
3885 __func__
, __LINE__
, cmd
->sess
->port_name
);
3887 qlt_schedule_sess_for_deletion_lock(cmd
->sess
);
3891 case CTIO_DIF_ERROR
: {
3892 struct ctio_crc_from_fw
*crc
=
3893 (struct ctio_crc_from_fw
*)ctio
;
3894 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf073,
3895 "qla_target(%d): CTIO with DIF_ERROR status %x "
3896 "received (state %x, ulp_cmd %p) actual_dif[0x%llx] "
3897 "expect_dif[0x%llx]\n",
3898 vha
->vp_idx
, status
, cmd
->state
, se_cmd
,
3899 *((u64
*)&crc
->actual_dif
[0]),
3900 *((u64
*)&crc
->expected_dif
[0]));
3902 qlt_handle_dif_error(qpair
, cmd
, ctio
);
3906 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05b,
3907 "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n",
3908 vha
->vp_idx
, status
, cmd
->state
, se_cmd
);
3913 /* "cmd->aborted" means
3914 * cmd is already aborted/terminated, we don't
3915 * need to terminate again. The exchange is already
3916 * cleaned up/freed at FW level. Just cleanup at driver
3919 if ((cmd
->state
!= QLA_TGT_STATE_NEED_DATA
) &&
3921 cmd
->trc_flags
|= TRC_CTIO_ERR
;
3922 if (qlt_term_ctio_exchange(qpair
, ctio
, cmd
, status
))
3927 if (cmd
->state
== QLA_TGT_STATE_PROCESSED
) {
3928 cmd
->trc_flags
|= TRC_CTIO_DONE
;
3929 } else if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
3930 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3932 if (status
== CTIO_SUCCESS
)
3933 cmd
->write_data_transferred
= 1;
3935 ha
->tgt
.tgt_ops
->handle_data(cmd
);
3937 } else if (cmd
->aborted
) {
3938 cmd
->trc_flags
|= TRC_CTIO_ABORTED
;
3939 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01e,
3940 "Aborted command %p (tag %lld) finished\n", cmd
, se_cmd
->tag
);
3942 cmd
->trc_flags
|= TRC_CTIO_STRANGE
;
3943 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05c,
3944 "qla_target(%d): A command in state (%d) should "
3945 "not return a CTIO complete\n", vha
->vp_idx
, cmd
->state
);
3948 if (unlikely(status
!= CTIO_SUCCESS
) &&
3950 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01f, "Finishing failed CTIO\n");
3954 ha
->tgt
.tgt_ops
->free_cmd(cmd
);
3957 static inline int qlt_get_fcp_task_attr(struct scsi_qla_host
*vha
,
3962 switch (task_codes
) {
3963 case ATIO_SIMPLE_QUEUE
:
3964 fcp_task_attr
= TCM_SIMPLE_TAG
;
3966 case ATIO_HEAD_OF_QUEUE
:
3967 fcp_task_attr
= TCM_HEAD_TAG
;
3969 case ATIO_ORDERED_QUEUE
:
3970 fcp_task_attr
= TCM_ORDERED_TAG
;
3972 case ATIO_ACA_QUEUE
:
3973 fcp_task_attr
= TCM_ACA_TAG
;
3976 fcp_task_attr
= TCM_SIMPLE_TAG
;
3979 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05d,
3980 "qla_target: unknown task code %x, use ORDERED instead\n",
3982 fcp_task_attr
= TCM_ORDERED_TAG
;
3986 return fcp_task_attr
;
3989 static struct fc_port
*qlt_make_local_sess(struct scsi_qla_host
*,
3992 * Process context for I/O path into tcm_qla2xxx code
3994 static void __qlt_do_work(struct qla_tgt_cmd
*cmd
)
3996 scsi_qla_host_t
*vha
= cmd
->vha
;
3997 struct qla_hw_data
*ha
= vha
->hw
;
3998 struct fc_port
*sess
= cmd
->sess
;
3999 struct atio_from_isp
*atio
= &cmd
->atio
;
4001 unsigned long flags
;
4002 uint32_t data_length
;
4003 int ret
, fcp_task_attr
, data_dir
, bidi
= 0;
4004 struct qla_qpair
*qpair
= cmd
->qpair
;
4007 cmd
->trc_flags
|= TRC_DO_WORK
;
4010 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf082,
4011 "cmd with tag %u is aborted\n",
4012 cmd
->atio
.u
.isp24
.exchange_addr
);
4016 spin_lock_init(&cmd
->cmd_lock
);
4017 cdb
= &atio
->u
.isp24
.fcp_cmnd
.cdb
[0];
4018 cmd
->se_cmd
.tag
= atio
->u
.isp24
.exchange_addr
;
4020 if (atio
->u
.isp24
.fcp_cmnd
.rddata
&&
4021 atio
->u
.isp24
.fcp_cmnd
.wrdata
) {
4023 data_dir
= DMA_TO_DEVICE
;
4024 } else if (atio
->u
.isp24
.fcp_cmnd
.rddata
)
4025 data_dir
= DMA_FROM_DEVICE
;
4026 else if (atio
->u
.isp24
.fcp_cmnd
.wrdata
)
4027 data_dir
= DMA_TO_DEVICE
;
4029 data_dir
= DMA_NONE
;
4031 fcp_task_attr
= qlt_get_fcp_task_attr(vha
,
4032 atio
->u
.isp24
.fcp_cmnd
.task_attr
);
4033 data_length
= be32_to_cpu(get_unaligned((uint32_t *)
4034 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
4035 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]));
4037 ret
= ha
->tgt
.tgt_ops
->handle_cmd(vha
, cmd
, cdb
, data_length
,
4038 fcp_task_attr
, data_dir
, bidi
);
4042 * Drop extra session reference from qla_tgt_handle_cmd_for_atio*(
4044 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4045 ha
->tgt
.tgt_ops
->put_sess(sess
);
4046 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4050 ql_dbg(ql_dbg_io
, vha
, 0x3060, "Terminating work cmd %p", cmd
);
4052 * cmd has not sent to target yet, so pass NULL as the second
4053 * argument to qlt_send_term_exchange() and free the memory here.
4055 cmd
->trc_flags
|= TRC_DO_WORK_ERR
;
4056 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
4057 qlt_send_term_exchange(qpair
, NULL
, &cmd
->atio
, 1, 0);
4059 qlt_decr_num_pend_cmds(vha
);
4060 percpu_ida_free(&sess
->se_sess
->sess_tag_pool
, cmd
->se_cmd
.map_tag
);
4061 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
4063 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4064 ha
->tgt
.tgt_ops
->put_sess(sess
);
4065 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4068 static void qlt_do_work(struct work_struct
*work
)
4070 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
4071 scsi_qla_host_t
*vha
= cmd
->vha
;
4072 unsigned long flags
;
4074 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4075 list_del(&cmd
->cmd_list
);
4076 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4081 void qlt_clr_qp_table(struct scsi_qla_host
*vha
)
4083 unsigned long flags
;
4084 struct qla_hw_data
*ha
= vha
->hw
;
4085 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4089 ql_log(ql_log_info
, vha
, 0x706c,
4090 "User update Number of Active Qpairs %d\n",
4091 ha
->tgt
.num_act_qpairs
);
4093 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
4095 btree_for_each_safe64(&tgt
->lun_qpair_map
, key
, node
)
4096 btree_remove64(&tgt
->lun_qpair_map
, key
);
4098 ha
->base_qpair
->lun_cnt
= 0;
4099 for (key
= 0; key
< ha
->max_qpairs
; key
++)
4100 if (ha
->queue_pair_map
[key
])
4101 ha
->queue_pair_map
[key
]->lun_cnt
= 0;
4103 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags
);
4106 static void qlt_assign_qpair(struct scsi_qla_host
*vha
,
4107 struct qla_tgt_cmd
*cmd
)
4109 struct qla_qpair
*qpair
, *qp
;
4110 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4111 struct qla_qpair_hint
*h
;
4113 if (vha
->flags
.qpairs_available
) {
4114 h
= btree_lookup64(&tgt
->lun_qpair_map
, cmd
->unpacked_lun
);
4116 /* spread lun to qpair ratio evently */
4118 struct scsi_qla_host
*base_vha
=
4119 pci_get_drvdata(vha
->hw
->pdev
);
4121 qpair
= vha
->hw
->base_qpair
;
4122 if (qpair
->lun_cnt
== 0) {
4124 h
= qla_qpair_to_hint(tgt
, qpair
);
4126 rc
= btree_insert64(&tgt
->lun_qpair_map
,
4127 cmd
->unpacked_lun
, h
, GFP_ATOMIC
);
4130 ql_log(ql_log_info
, vha
, 0xd037,
4131 "Unable to insert lun %llx into lun_qpair_map\n",
4136 lcnt
= qpair
->lun_cnt
;
4140 list_for_each_entry(qp
, &base_vha
->qp_list
,
4142 if (qp
->lun_cnt
== 0) {
4144 h
= qla_qpair_to_hint(tgt
, qp
);
4146 rc
= btree_insert64(&tgt
->lun_qpair_map
,
4147 cmd
->unpacked_lun
, h
, GFP_ATOMIC
);
4150 ql_log(ql_log_info
, vha
, 0xd038,
4151 "Unable to insert lun %llx into lun_qpair_map\n",
4157 if (qp
->lun_cnt
< lcnt
) {
4166 h
= qla_qpair_to_hint(tgt
, qpair
);
4168 rc
= btree_insert64(&tgt
->lun_qpair_map
,
4169 cmd
->unpacked_lun
, h
, GFP_ATOMIC
);
4172 ql_log(ql_log_info
, vha
, 0xd039,
4173 "Unable to insert lun %llx into lun_qpair_map\n",
4178 h
= &tgt
->qphints
[0];
4181 cmd
->qpair
= h
->qpair
;
4182 cmd
->se_cmd
.cpuid
= h
->cpuid
;
4185 static struct qla_tgt_cmd
*qlt_get_tag(scsi_qla_host_t
*vha
,
4186 struct fc_port
*sess
,
4187 struct atio_from_isp
*atio
)
4189 struct se_session
*se_sess
= sess
->se_sess
;
4190 struct qla_tgt_cmd
*cmd
;
4193 tag
= percpu_ida_alloc(&se_sess
->sess_tag_pool
, TASK_RUNNING
);
4197 cmd
= &((struct qla_tgt_cmd
*)se_sess
->sess_cmd_map
)[tag
];
4198 memset(cmd
, 0, sizeof(struct qla_tgt_cmd
));
4199 cmd
->cmd_type
= TYPE_TGT_CMD
;
4200 memcpy(&cmd
->atio
, atio
, sizeof(*atio
));
4201 cmd
->state
= QLA_TGT_STATE_NEW
;
4202 cmd
->tgt
= vha
->vha_tgt
.qla_tgt
;
4203 qlt_incr_num_pend_cmds(vha
);
4205 cmd
->se_cmd
.map_tag
= tag
;
4207 cmd
->loop_id
= sess
->loop_id
;
4208 cmd
->conf_compl_supported
= sess
->conf_compl_supported
;
4211 cmd
->jiffies_at_alloc
= get_jiffies_64();
4213 cmd
->unpacked_lun
= scsilun_to_int(
4214 (struct scsi_lun
*)&atio
->u
.isp24
.fcp_cmnd
.lun
);
4215 qlt_assign_qpair(vha
, cmd
);
4216 cmd
->reset_count
= vha
->hw
->base_qpair
->chip_reset
;
4217 cmd
->vp_idx
= vha
->vp_idx
;
4222 static void qlt_create_sess_from_atio(struct work_struct
*work
)
4224 struct qla_tgt_sess_op
*op
= container_of(work
,
4225 struct qla_tgt_sess_op
, work
);
4226 scsi_qla_host_t
*vha
= op
->vha
;
4227 struct qla_hw_data
*ha
= vha
->hw
;
4228 struct fc_port
*sess
;
4229 struct qla_tgt_cmd
*cmd
;
4230 unsigned long flags
;
4231 uint8_t *s_id
= op
->atio
.u
.isp24
.fcp_hdr
.s_id
;
4233 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4234 list_del(&op
->cmd_list
);
4235 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4238 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf083,
4239 "sess_op with tag %u is aborted\n",
4240 op
->atio
.u
.isp24
.exchange_addr
);
4244 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf022,
4245 "qla_target(%d): Unable to find wwn login"
4246 " (s_id %x:%x:%x), trying to create it manually\n",
4247 vha
->vp_idx
, s_id
[0], s_id
[1], s_id
[2]);
4249 if (op
->atio
.u
.raw
.entry_count
> 1) {
4250 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf023,
4251 "Dropping multy entry atio %p\n", &op
->atio
);
4255 sess
= qlt_make_local_sess(vha
, s_id
);
4256 /* sess has an extra creation ref. */
4261 * Now obtain a pre-allocated session tag using the original op->atio
4262 * packet header, and dispatch into __qlt_do_work() using the existing
4265 cmd
= qlt_get_tag(vha
, sess
, &op
->atio
);
4267 struct qla_qpair
*qpair
= ha
->base_qpair
;
4269 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
4270 qlt_send_busy(qpair
, &op
->atio
, SAM_STAT_BUSY
);
4271 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
4273 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4274 ha
->tgt
.tgt_ops
->put_sess(sess
);
4275 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4281 * __qlt_do_work() will call qlt_put_sess() to release
4282 * the extra reference taken above by qlt_make_local_sess()
4288 qlt_send_term_exchange(vha
->hw
->base_qpair
, NULL
, &op
->atio
, 0, 0);
4292 /* ha->hardware_lock supposed to be held on entry */
4293 static int qlt_handle_cmd_for_atio(struct scsi_qla_host
*vha
,
4294 struct atio_from_isp
*atio
)
4296 struct qla_hw_data
*ha
= vha
->hw
;
4297 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4298 struct fc_port
*sess
;
4299 struct qla_tgt_cmd
*cmd
;
4300 unsigned long flags
;
4302 if (unlikely(tgt
->tgt_stop
)) {
4303 ql_dbg(ql_dbg_io
, vha
, 0x3061,
4304 "New command while device %p is shutting down\n", tgt
);
4308 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, atio
->u
.isp24
.fcp_hdr
.s_id
);
4309 if (unlikely(!sess
)) {
4310 struct qla_tgt_sess_op
*op
= kzalloc(sizeof(struct qla_tgt_sess_op
),
4315 memcpy(&op
->atio
, atio
, sizeof(*atio
));
4318 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4319 list_add_tail(&op
->cmd_list
, &vha
->qla_sess_op_cmd_list
);
4320 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4322 INIT_WORK(&op
->work
, qlt_create_sess_from_atio
);
4323 queue_work(qla_tgt_wq
, &op
->work
);
4327 /* Another WWN used to have our s_id. Our PLOGI scheduled its
4328 * session deletion, but it's still in sess_del_work wq */
4329 if (sess
->deleted
) {
4330 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf002,
4331 "New command while old session %p is being deleted\n",
4337 * Do kref_get() before returning + dropping qla_hw_data->hardware_lock.
4339 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
4340 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf004,
4341 "%s: kref_get fail, %8phC oxid %x \n",
4342 __func__
, sess
->port_name
,
4343 be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
));
4347 cmd
= qlt_get_tag(vha
, sess
, atio
);
4349 ql_dbg(ql_dbg_io
, vha
, 0x3062,
4350 "qla_target(%d): Allocation of cmd failed\n", vha
->vp_idx
);
4351 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4352 ha
->tgt
.tgt_ops
->put_sess(sess
);
4353 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4358 cmd
->trc_flags
|= TRC_NEW_CMD
;
4360 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4361 list_add_tail(&cmd
->cmd_list
, &vha
->qla_cmd_list
);
4362 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4364 INIT_WORK(&cmd
->work
, qlt_do_work
);
4365 if (vha
->flags
.qpairs_available
) {
4366 queue_work_on(cmd
->se_cmd
.cpuid
, qla_tgt_wq
, &cmd
->work
);
4367 } else if (ha
->msix_count
) {
4368 if (cmd
->atio
.u
.isp24
.fcp_cmnd
.rddata
)
4369 queue_work_on(smp_processor_id(), qla_tgt_wq
,
4372 queue_work_on(cmd
->se_cmd
.cpuid
, qla_tgt_wq
,
4375 queue_work(qla_tgt_wq
, &cmd
->work
);
4381 /* ha->hardware_lock supposed to be held on entry */
4382 static int qlt_issue_task_mgmt(struct fc_port
*sess
, u64 lun
,
4383 int fn
, void *iocb
, int flags
)
4385 struct scsi_qla_host
*vha
= sess
->vha
;
4386 struct qla_hw_data
*ha
= vha
->hw
;
4387 struct qla_tgt_mgmt_cmd
*mcmd
;
4388 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4391 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
4393 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10009,
4394 "qla_target(%d): Allocation of management "
4395 "command failed, some commands and their data could "
4396 "leak\n", vha
->vp_idx
);
4399 memset(mcmd
, 0, sizeof(*mcmd
));
4403 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
4404 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
4406 mcmd
->tmr_func
= fn
;
4407 mcmd
->flags
= flags
;
4408 mcmd
->reset_count
= ha
->base_qpair
->chip_reset
;
4409 mcmd
->qpair
= ha
->base_qpair
;
4413 case QLA_TGT_LUN_RESET
:
4414 abort_cmds_for_lun(vha
, lun
, a
->u
.isp24
.fcp_hdr
.s_id
);
4418 res
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, lun
, mcmd
->tmr_func
, 0);
4420 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000b,
4421 "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n",
4422 sess
->vha
->vp_idx
, res
);
4423 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
4430 /* ha->hardware_lock supposed to be held on entry */
4431 static int qlt_handle_task_mgmt(struct scsi_qla_host
*vha
, void *iocb
)
4433 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4434 struct qla_hw_data
*ha
= vha
->hw
;
4435 struct qla_tgt
*tgt
;
4436 struct fc_port
*sess
;
4439 unsigned long flags
;
4441 tgt
= vha
->vha_tgt
.qla_tgt
;
4443 fn
= a
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
;
4445 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4446 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
4447 a
->u
.isp24
.fcp_hdr
.s_id
);
4448 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4451 scsilun_to_int((struct scsi_lun
*)&a
->u
.isp24
.fcp_cmnd
.lun
);
4454 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf024,
4455 "qla_target(%d): task mgmt fn 0x%x for "
4456 "non-existant session\n", vha
->vp_idx
, fn
);
4457 return qlt_sched_sess_work(tgt
, QLA_TGT_SESS_WORK_TM
, iocb
,
4458 sizeof(struct atio_from_isp
));
4464 return qlt_issue_task_mgmt(sess
, unpacked_lun
, fn
, iocb
, 0);
4467 /* ha->hardware_lock supposed to be held on entry */
4468 static int __qlt_abort_task(struct scsi_qla_host
*vha
,
4469 struct imm_ntfy_from_isp
*iocb
, struct fc_port
*sess
)
4471 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4472 struct qla_hw_data
*ha
= vha
->hw
;
4473 struct qla_tgt_mgmt_cmd
*mcmd
;
4477 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
4479 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05f,
4480 "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
4481 vha
->vp_idx
, __func__
);
4484 memset(mcmd
, 0, sizeof(*mcmd
));
4487 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
4488 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
4491 scsilun_to_int((struct scsi_lun
*)&a
->u
.isp24
.fcp_cmnd
.lun
);
4492 mcmd
->reset_count
= ha
->base_qpair
->chip_reset
;
4493 mcmd
->tmr_func
= QLA_TGT_2G_ABORT_TASK
;
4494 mcmd
->qpair
= ha
->base_qpair
;
4496 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, unpacked_lun
, mcmd
->tmr_func
,
4497 le16_to_cpu(iocb
->u
.isp2x
.seq_id
));
4499 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf060,
4500 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
4502 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
4509 /* ha->hardware_lock supposed to be held on entry */
4510 static int qlt_abort_task(struct scsi_qla_host
*vha
,
4511 struct imm_ntfy_from_isp
*iocb
)
4513 struct qla_hw_data
*ha
= vha
->hw
;
4514 struct fc_port
*sess
;
4516 unsigned long flags
;
4518 loop_id
= GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
);
4520 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4521 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
4522 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4525 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf025,
4526 "qla_target(%d): task abort for unexisting "
4527 "session\n", vha
->vp_idx
);
4528 return qlt_sched_sess_work(vha
->vha_tgt
.qla_tgt
,
4529 QLA_TGT_SESS_WORK_ABORT
, iocb
, sizeof(*iocb
));
4532 return __qlt_abort_task(vha
, iocb
, sess
);
4535 void qlt_logo_completion_handler(fc_port_t
*fcport
, int rc
)
4537 if (rc
!= MBS_COMMAND_COMPLETE
) {
4538 ql_dbg(ql_dbg_tgt_mgt
, fcport
->vha
, 0xf093,
4539 "%s: se_sess %p / sess %p from"
4540 " port %8phC loop_id %#04x s_id %02x:%02x:%02x"
4541 " LOGO failed: %#x\n",
4545 fcport
->port_name
, fcport
->loop_id
,
4546 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
4547 fcport
->d_id
.b
.al_pa
, rc
);
4550 fcport
->logout_completed
= 1;
4554 * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list)
4556 * Schedules sessions with matching port_id/loop_id but different wwn for
4557 * deletion. Returns existing session with matching wwn if present.
4561 qlt_find_sess_invalidate_other(scsi_qla_host_t
*vha
, uint64_t wwn
,
4562 port_id_t port_id
, uint16_t loop_id
, struct fc_port
**conflict_sess
)
4564 struct fc_port
*sess
= NULL
, *other_sess
;
4567 *conflict_sess
= NULL
;
4569 list_for_each_entry(other_sess
, &vha
->vp_fcports
, list
) {
4571 other_wwn
= wwn_to_u64(other_sess
->port_name
);
4573 if (wwn
== other_wwn
) {
4579 /* find other sess with nport_id collision */
4580 if (port_id
.b24
== other_sess
->d_id
.b24
) {
4581 if (loop_id
!= other_sess
->loop_id
) {
4582 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000c,
4583 "Invalidating sess %p loop_id %d wwn %llx.\n",
4584 other_sess
, other_sess
->loop_id
, other_wwn
);
4587 * logout_on_delete is set by default, but another
4588 * session that has the same s_id/loop_id combo
4589 * might have cleared it when requested this session
4590 * deletion, so don't touch it
4592 qlt_schedule_sess_for_deletion(other_sess
, true);
4595 * Another wwn used to have our s_id/loop_id
4596 * kill the session, but don't free the loop_id
4598 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xf01b,
4599 "Invalidating sess %p loop_id %d wwn %llx.\n",
4600 other_sess
, other_sess
->loop_id
, other_wwn
);
4603 other_sess
->keep_nport_handle
= 1;
4604 *conflict_sess
= other_sess
;
4605 qlt_schedule_sess_for_deletion(other_sess
,
4611 /* find other sess with nport handle collision */
4612 if ((loop_id
== other_sess
->loop_id
) &&
4613 (loop_id
!= FC_NO_LOOP_ID
)) {
4614 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000d,
4615 "Invalidating sess %p loop_id %d wwn %llx.\n",
4616 other_sess
, other_sess
->loop_id
, other_wwn
);
4618 /* Same loop_id but different s_id
4619 * Ok to kill and logout */
4620 qlt_schedule_sess_for_deletion(other_sess
, true);
4627 /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */
4628 static int abort_cmds_for_s_id(struct scsi_qla_host
*vha
, port_id_t
*s_id
)
4630 struct qla_tgt_sess_op
*op
;
4631 struct qla_tgt_cmd
*cmd
;
4634 unsigned long flags
;
4636 key
= (((u32
)s_id
->b
.domain
<< 16) |
4637 ((u32
)s_id
->b
.area
<< 8) |
4638 ((u32
)s_id
->b
.al_pa
));
4640 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4641 list_for_each_entry(op
, &vha
->qla_sess_op_cmd_list
, cmd_list
) {
4642 uint32_t op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
4644 if (op_key
== key
) {
4650 list_for_each_entry(op
, &vha
->unknown_atio_list
, cmd_list
) {
4651 uint32_t op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
4652 if (op_key
== key
) {
4658 list_for_each_entry(cmd
, &vha
->qla_cmd_list
, cmd_list
) {
4659 uint32_t cmd_key
= sid_to_key(cmd
->atio
.u
.isp24
.fcp_hdr
.s_id
);
4660 if (cmd_key
== key
) {
4665 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4671 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4673 static int qlt_24xx_handle_els(struct scsi_qla_host
*vha
,
4674 struct imm_ntfy_from_isp
*iocb
)
4676 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4677 struct qla_hw_data
*ha
= vha
->hw
;
4678 struct fc_port
*sess
= NULL
, *conflict_sess
= NULL
;
4684 struct qlt_plogi_ack_t
*pla
;
4685 unsigned long flags
;
4687 wwn
= wwn_to_u64(iocb
->u
.isp24
.port_name
);
4689 port_id
.b
.domain
= iocb
->u
.isp24
.port_id
[2];
4690 port_id
.b
.area
= iocb
->u
.isp24
.port_id
[1];
4691 port_id
.b
.al_pa
= iocb
->u
.isp24
.port_id
[0];
4692 port_id
.b
.rsvd_1
= 0;
4694 loop_id
= le16_to_cpu(iocb
->u
.isp24
.nport_handle
);
4696 ql_dbg(ql_dbg_disc
, vha
, 0xf026,
4697 "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n",
4698 vha
->vp_idx
, iocb
->u
.isp24
.port_id
[2],
4699 iocb
->u
.isp24
.port_id
[1], iocb
->u
.isp24
.port_id
[0],
4700 iocb
->u
.isp24
.status_subcode
, loop_id
,
4701 iocb
->u
.isp24
.port_name
);
4703 /* res = 1 means ack at the end of thread
4704 * res = 0 means ack async/later.
4706 switch (iocb
->u
.isp24
.status_subcode
) {
4709 /* Mark all stale commands in qla_tgt_wq for deletion */
4710 abort_cmds_for_s_id(vha
, &port_id
);
4713 spin_lock_irqsave(&tgt
->ha
->tgt
.sess_lock
, flags
);
4714 sess
= qlt_find_sess_invalidate_other(vha
, wwn
,
4715 port_id
, loop_id
, &conflict_sess
);
4716 spin_unlock_irqrestore(&tgt
->ha
->tgt
.sess_lock
, flags
);
4719 if (IS_SW_RESV_ADDR(port_id
)) {
4724 pla
= qlt_plogi_ack_find_add(vha
, &port_id
, iocb
);
4726 qlt_send_term_imm_notif(vha
, iocb
, 1);
4732 if (conflict_sess
) {
4733 conflict_sess
->login_gen
++;
4734 qlt_plogi_ack_link(vha
, pla
, conflict_sess
,
4735 QLT_PLOGI_LINK_CONFLICT
);
4740 qla24xx_post_newsess_work(vha
, &port_id
,
4741 iocb
->u
.isp24
.port_name
, pla
);
4746 qlt_plogi_ack_link(vha
, pla
, sess
, QLT_PLOGI_LINK_SAME_WWN
);
4747 sess
->fw_login_state
= DSC_LS_PLOGI_PEND
;
4748 sess
->d_id
= port_id
;
4751 ql_dbg(ql_dbg_disc
, vha
, 0x20f9,
4752 "%s %d %8phC DS %d\n",
4753 __func__
, __LINE__
, sess
->port_name
, sess
->disc_state
);
4755 switch (sess
->disc_state
) {
4757 qlt_plogi_ack_unref(vha
, pla
);
4762 * Under normal circumstances we want to release nport handle
4763 * during LOGO process to avoid nport handle leaks inside FW.
4764 * The exception is when LOGO is done while another PLOGI with
4765 * the same nport handle is waiting as might be the case here.
4766 * Note: there is always a possibily of a race where session
4767 * deletion has already started for other reasons (e.g. ACL
4768 * removal) and now PLOGI arrives:
4769 * 1. if PLOGI arrived in FW after nport handle has been freed,
4770 * FW must have assigned this PLOGI a new/same handle and we
4771 * can proceed ACK'ing it as usual when session deletion
4773 * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT
4774 * bit reached it, the handle has now been released. We'll
4775 * get an error when we ACK this PLOGI. Nothing will be sent
4776 * back to initiator. Initiator should eventually retry
4777 * PLOGI and situation will correct itself.
4779 sess
->keep_nport_handle
= ((sess
->loop_id
== loop_id
) &&
4780 (sess
->d_id
.b24
== port_id
.b24
));
4782 ql_dbg(ql_dbg_disc
, vha
, 0x20f9,
4783 "%s %d %8phC post del sess\n",
4784 __func__
, __LINE__
, sess
->port_name
);
4787 qlt_schedule_sess_for_deletion_lock(sess
);
4794 wd3_lo
= le16_to_cpu(iocb
->u
.isp24
.u
.prli
.wd3_lo
);
4797 spin_lock_irqsave(&tgt
->ha
->tgt
.sess_lock
, flags
);
4798 sess
= qlt_find_sess_invalidate_other(vha
, wwn
, port_id
,
4799 loop_id
, &conflict_sess
);
4800 spin_unlock_irqrestore(&tgt
->ha
->tgt
.sess_lock
, flags
);
4803 if (conflict_sess
) {
4804 switch (conflict_sess
->disc_state
) {
4806 case DSC_DELETE_PEND
:
4809 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf09b,
4810 "PRLI with conflicting sess %p port %8phC\n",
4811 conflict_sess
, conflict_sess
->port_name
);
4812 conflict_sess
->fw_login_state
=
4813 DSC_LS_PORT_UNAVAIL
;
4814 qlt_send_term_imm_notif(vha
, iocb
, 1);
4821 if (sess
->fw_login_state
!= DSC_LS_PLOGI_PEND
&&
4822 sess
->fw_login_state
!= DSC_LS_PLOGI_COMP
) {
4824 * Impatient initiator sent PRLI before last
4825 * PLOGI could finish. Will force him to re-try,
4826 * while last one finishes.
4828 ql_log(ql_log_warn
, sess
->vha
, 0xf095,
4829 "sess %p PRLI received, before plogi ack.\n",
4831 qlt_send_term_imm_notif(vha
, iocb
, 1);
4837 * This shouldn't happen under normal circumstances,
4838 * since we have deleted the old session during PLOGI
4840 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf096,
4841 "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n",
4842 sess
->loop_id
, sess
, iocb
->u
.isp24
.nport_handle
);
4845 sess
->loop_id
= loop_id
;
4846 sess
->d_id
= port_id
;
4847 sess
->fw_login_state
= DSC_LS_PRLI_PEND
;
4850 sess
->conf_compl_supported
= 1;
4852 if ((wd3_lo
& BIT_4
) == 0)
4853 sess
->port_type
= FCT_INITIATOR
;
4855 sess
->port_type
= FCT_TARGET
;
4857 res
= 1; /* send notify ack */
4859 /* Make session global (not used in fabric mode) */
4860 if (ha
->current_topology
!= ISP_CFG_F
) {
4862 ql_dbg(ql_dbg_disc
, vha
, 0x20fa,
4863 "%s %d %8phC post nack\n",
4864 __func__
, __LINE__
, sess
->port_name
);
4865 qla24xx_post_nack_work(vha
, sess
, iocb
,
4869 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4870 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4871 qla2xxx_wake_dpc(vha
);
4875 ql_dbg(ql_dbg_disc
, vha
, 0x20fb,
4876 "%s %d %8phC post nack\n",
4877 __func__
, __LINE__
, sess
->port_name
);
4878 qla24xx_post_nack_work(vha
, sess
, iocb
,
4886 if (le16_to_cpu(iocb
->u
.isp24
.flags
) &
4887 NOTIFY24XX_FLAGS_GLOBAL_TPRLO
) {
4889 qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
);
4896 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4897 sess
= qla2x00_find_fcport_by_loopid(vha
, loop_id
);
4898 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4902 sess
->fw_login_state
= DSC_LS_LOGO_PEND
;
4903 sess
->logo_ack_needed
= 1;
4904 memcpy(sess
->iocb
, iocb
, IOCB_SIZE
);
4907 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
4909 ql_dbg(ql_dbg_disc
, vha
, 0x20fc,
4910 "%s: logo %llx res %d sess %p ",
4911 __func__
, wwn
, res
, sess
);
4914 * cmd went upper layer, look for qlt_xmit_tm_rsp()
4915 * for LOGO_ACK & sess delete
4920 /* cmd did not go to upper layer. */
4922 qlt_schedule_sess_for_deletion_lock(sess
);
4925 /* else logo will be ack */
4931 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4932 if (tgt
->link_reinit_iocb_pending
) {
4933 qlt_send_notify_ack(ha
->base_qpair
,
4934 &tgt
->link_reinit_iocb
, 0, 0, 0, 0, 0, 0);
4935 tgt
->link_reinit_iocb_pending
= 0;
4938 sess
= qla2x00_find_fcport_by_wwpn(vha
,
4939 iocb
->u
.isp24
.port_name
, 1);
4941 ql_dbg(ql_dbg_disc
, vha
, 0x20fd,
4942 "sess %p lid %d|%d DS %d LS %d\n",
4943 sess
, sess
->loop_id
, loop_id
,
4944 sess
->disc_state
, sess
->fw_login_state
);
4947 res
= 1; /* send notify ack */
4951 case ELS_FLOGI
: /* should never happen */
4953 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf061,
4954 "qla_target(%d): Unsupported ELS command %x "
4955 "received\n", vha
->vp_idx
, iocb
->u
.isp24
.status_subcode
);
4956 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
4964 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4966 static void qlt_handle_imm_notify(struct scsi_qla_host
*vha
,
4967 struct imm_ntfy_from_isp
*iocb
)
4969 struct qla_hw_data
*ha
= vha
->hw
;
4970 uint32_t add_flags
= 0;
4971 int send_notify_ack
= 1;
4974 status
= le16_to_cpu(iocb
->u
.isp2x
.status
);
4976 case IMM_NTFY_LIP_RESET
:
4978 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf032,
4979 "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
4980 vha
->vp_idx
, le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
4981 iocb
->u
.isp24
.status_subcode
);
4983 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
4984 send_notify_ack
= 0;
4988 case IMM_NTFY_LIP_LINK_REINIT
:
4990 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4991 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf033,
4992 "qla_target(%d): LINK REINIT (loop %#x, "
4993 "subcode %x)\n", vha
->vp_idx
,
4994 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
4995 iocb
->u
.isp24
.status_subcode
);
4996 if (tgt
->link_reinit_iocb_pending
) {
4997 qlt_send_notify_ack(ha
->base_qpair
,
4998 &tgt
->link_reinit_iocb
, 0, 0, 0, 0, 0, 0);
5000 memcpy(&tgt
->link_reinit_iocb
, iocb
, sizeof(*iocb
));
5001 tgt
->link_reinit_iocb_pending
= 1;
5003 * QLogic requires to wait after LINK REINIT for possible
5004 * PDISC or ADISC ELS commands
5006 send_notify_ack
= 0;
5010 case IMM_NTFY_PORT_LOGOUT
:
5011 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf034,
5012 "qla_target(%d): Port logout (loop "
5013 "%#x, subcode %x)\n", vha
->vp_idx
,
5014 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
5015 iocb
->u
.isp24
.status_subcode
);
5017 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
) == 0)
5018 send_notify_ack
= 0;
5019 /* The sessions will be cleared in the callback, if needed */
5022 case IMM_NTFY_GLBL_TPRLO
:
5023 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf035,
5024 "qla_target(%d): Global TPRLO (%x)\n", vha
->vp_idx
, status
);
5025 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
5026 send_notify_ack
= 0;
5027 /* The sessions will be cleared in the callback, if needed */
5030 case IMM_NTFY_PORT_CONFIG
:
5031 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf036,
5032 "qla_target(%d): Port config changed (%x)\n", vha
->vp_idx
,
5034 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
5035 send_notify_ack
= 0;
5036 /* The sessions will be cleared in the callback, if needed */
5039 case IMM_NTFY_GLBL_LOGO
:
5040 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06a,
5041 "qla_target(%d): Link failure detected\n",
5043 /* I_T nexus loss */
5044 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
5045 send_notify_ack
= 0;
5048 case IMM_NTFY_IOCB_OVERFLOW
:
5049 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06b,
5050 "qla_target(%d): Cannot provide requested "
5051 "capability (IOCB overflowed the immediate notify "
5052 "resource count)\n", vha
->vp_idx
);
5055 case IMM_NTFY_ABORT_TASK
:
5056 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf037,
5057 "qla_target(%d): Abort Task (S %08x I %#x -> "
5058 "L %#x)\n", vha
->vp_idx
,
5059 le16_to_cpu(iocb
->u
.isp2x
.seq_id
),
5060 GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
),
5061 le16_to_cpu(iocb
->u
.isp2x
.lun
));
5062 if (qlt_abort_task(vha
, iocb
) == 0)
5063 send_notify_ack
= 0;
5066 case IMM_NTFY_RESOURCE
:
5067 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06c,
5068 "qla_target(%d): Out of resources, host %ld\n",
5069 vha
->vp_idx
, vha
->host_no
);
5072 case IMM_NTFY_MSG_RX
:
5073 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf038,
5074 "qla_target(%d): Immediate notify task %x\n",
5075 vha
->vp_idx
, iocb
->u
.isp2x
.task_flags
);
5076 if (qlt_handle_task_mgmt(vha
, iocb
) == 0)
5077 send_notify_ack
= 0;
5081 if (qlt_24xx_handle_els(vha
, iocb
) == 0)
5082 send_notify_ack
= 0;
5085 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06d,
5086 "qla_target(%d): Received unknown immediate "
5087 "notify status %x\n", vha
->vp_idx
, status
);
5091 if (send_notify_ack
)
5092 qlt_send_notify_ack(ha
->base_qpair
, iocb
, add_flags
, 0, 0, 0,
5097 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5098 * This function sends busy to ISP 2xxx or 24xx.
5100 static int __qlt_send_busy(struct qla_qpair
*qpair
,
5101 struct atio_from_isp
*atio
, uint16_t status
)
5103 struct scsi_qla_host
*vha
= qpair
->vha
;
5104 struct ctio7_to_24xx
*ctio24
;
5105 struct qla_hw_data
*ha
= vha
->hw
;
5107 struct fc_port
*sess
= NULL
;
5108 unsigned long flags
;
5111 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
5112 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
5113 atio
->u
.isp24
.fcp_hdr
.s_id
);
5114 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
5116 qlt_send_term_exchange(qpair
, NULL
, atio
, 1, 0);
5119 /* Sending marker isn't necessary, since we called from ISR */
5121 pkt
= (request_t
*)__qla2x00_alloc_iocbs(qpair
, NULL
);
5123 ql_dbg(ql_dbg_io
, vha
, 0x3063,
5124 "qla_target(%d): %s failed: unable to allocate "
5125 "request packet", vha
->vp_idx
, __func__
);
5129 qpair
->tgt_counters
.num_q_full_sent
++;
5130 pkt
->entry_count
= 1;
5131 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
5133 ctio24
= (struct ctio7_to_24xx
*)pkt
;
5134 ctio24
->entry_type
= CTIO_TYPE7
;
5135 ctio24
->nport_handle
= sess
->loop_id
;
5136 ctio24
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
5137 ctio24
->vp_index
= vha
->vp_idx
;
5138 ctio24
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
5139 ctio24
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
5140 ctio24
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
5141 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
5142 temp
= (atio
->u
.isp24
.attr
<< 9) |
5143 CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
|
5144 CTIO7_FLAGS_DONT_RET_CTIO
;
5145 ctio24
->u
.status1
.flags
= cpu_to_le16(temp
);
5147 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
5148 * if the explicit conformation is used.
5150 ctio24
->u
.status1
.ox_id
= swab16(atio
->u
.isp24
.fcp_hdr
.ox_id
);
5151 ctio24
->u
.status1
.scsi_status
= cpu_to_le16(status
);
5152 /* Memory Barrier */
5154 if (qpair
->reqq_start_iocbs
)
5155 qpair
->reqq_start_iocbs(qpair
);
5157 qla2x00_start_iocbs(vha
, qpair
->req
);
5162 * This routine is used to allocate a command for either a QFull condition
5163 * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go
5167 qlt_alloc_qfull_cmd(struct scsi_qla_host
*vha
,
5168 struct atio_from_isp
*atio
, uint16_t status
, int qfull
)
5170 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5171 struct qla_hw_data
*ha
= vha
->hw
;
5172 struct fc_port
*sess
;
5173 struct se_session
*se_sess
;
5174 struct qla_tgt_cmd
*cmd
;
5176 unsigned long flags
;
5178 if (unlikely(tgt
->tgt_stop
)) {
5179 ql_dbg(ql_dbg_io
, vha
, 0x300a,
5180 "New command while device %p is shutting down\n", tgt
);
5184 if ((vha
->hw
->tgt
.num_qfull_cmds_alloc
+ 1) > MAX_QFULL_CMDS_ALLOC
) {
5185 vha
->hw
->tgt
.num_qfull_cmds_dropped
++;
5186 if (vha
->hw
->tgt
.num_qfull_cmds_dropped
>
5187 vha
->qla_stats
.stat_max_qfull_cmds_dropped
)
5188 vha
->qla_stats
.stat_max_qfull_cmds_dropped
=
5189 vha
->hw
->tgt
.num_qfull_cmds_dropped
;
5191 ql_dbg(ql_dbg_io
, vha
, 0x3068,
5192 "qla_target(%d): %s: QFull CMD dropped[%d]\n",
5193 vha
->vp_idx
, __func__
,
5194 vha
->hw
->tgt
.num_qfull_cmds_dropped
);
5196 qlt_chk_exch_leak_thresh_hold(vha
);
5200 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id
5201 (vha
, atio
->u
.isp24
.fcp_hdr
.s_id
);
5205 se_sess
= sess
->se_sess
;
5207 tag
= percpu_ida_alloc(&se_sess
->sess_tag_pool
, TASK_RUNNING
);
5211 cmd
= &((struct qla_tgt_cmd
*)se_sess
->sess_cmd_map
)[tag
];
5213 ql_dbg(ql_dbg_io
, vha
, 0x3009,
5214 "qla_target(%d): %s: Allocation of cmd failed\n",
5215 vha
->vp_idx
, __func__
);
5217 vha
->hw
->tgt
.num_qfull_cmds_dropped
++;
5218 if (vha
->hw
->tgt
.num_qfull_cmds_dropped
>
5219 vha
->qla_stats
.stat_max_qfull_cmds_dropped
)
5220 vha
->qla_stats
.stat_max_qfull_cmds_dropped
=
5221 vha
->hw
->tgt
.num_qfull_cmds_dropped
;
5223 qlt_chk_exch_leak_thresh_hold(vha
);
5227 memset(cmd
, 0, sizeof(struct qla_tgt_cmd
));
5229 qlt_incr_num_pend_cmds(vha
);
5230 INIT_LIST_HEAD(&cmd
->cmd_list
);
5231 memcpy(&cmd
->atio
, atio
, sizeof(*atio
));
5233 cmd
->tgt
= vha
->vha_tgt
.qla_tgt
;
5235 cmd
->reset_count
= ha
->base_qpair
->chip_reset
;
5237 cmd
->qpair
= ha
->base_qpair
;
5241 /* NOTE: borrowing the state field to carry the status */
5242 cmd
->state
= status
;
5244 cmd
->term_exchg
= 1;
5246 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
5247 list_add_tail(&cmd
->cmd_list
, &vha
->hw
->tgt
.q_full_list
);
5249 vha
->hw
->tgt
.num_qfull_cmds_alloc
++;
5250 if (vha
->hw
->tgt
.num_qfull_cmds_alloc
>
5251 vha
->qla_stats
.stat_max_qfull_cmds_alloc
)
5252 vha
->qla_stats
.stat_max_qfull_cmds_alloc
=
5253 vha
->hw
->tgt
.num_qfull_cmds_alloc
;
5254 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
5258 qlt_free_qfull_cmds(struct qla_qpair
*qpair
)
5260 struct scsi_qla_host
*vha
= qpair
->vha
;
5261 struct qla_hw_data
*ha
= vha
->hw
;
5262 unsigned long flags
;
5263 struct qla_tgt_cmd
*cmd
, *tcmd
;
5264 struct list_head free_list
, q_full_list
;
5267 if (list_empty(&ha
->tgt
.q_full_list
))
5270 INIT_LIST_HEAD(&free_list
);
5271 INIT_LIST_HEAD(&q_full_list
);
5273 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
5274 if (list_empty(&ha
->tgt
.q_full_list
)) {
5275 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
5279 list_splice_init(&vha
->hw
->tgt
.q_full_list
, &q_full_list
);
5280 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
5282 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
5283 list_for_each_entry_safe(cmd
, tcmd
, &q_full_list
, cmd_list
) {
5285 /* cmd->state is a borrowed field to hold status */
5286 rc
= __qlt_send_busy(qpair
, &cmd
->atio
, cmd
->state
);
5287 else if (cmd
->term_exchg
)
5288 rc
= __qlt_send_term_exchange(qpair
, NULL
, &cmd
->atio
);
5294 ql_dbg(ql_dbg_io
, vha
, 0x3006,
5295 "%s: busy sent for ox_id[%04x]\n", __func__
,
5296 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
5297 else if (cmd
->term_exchg
)
5298 ql_dbg(ql_dbg_io
, vha
, 0x3007,
5299 "%s: Term exchg sent for ox_id[%04x]\n", __func__
,
5300 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
5302 ql_dbg(ql_dbg_io
, vha
, 0x3008,
5303 "%s: Unexpected cmd in QFull list %p\n", __func__
,
5306 list_del(&cmd
->cmd_list
);
5307 list_add_tail(&cmd
->cmd_list
, &free_list
);
5309 /* piggy back on hardware_lock for protection */
5310 vha
->hw
->tgt
.num_qfull_cmds_alloc
--;
5312 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
5316 list_for_each_entry_safe(cmd
, tcmd
, &free_list
, cmd_list
) {
5317 list_del(&cmd
->cmd_list
);
5318 /* This cmd was never sent to TCM. There is no need
5319 * to schedule free or call free_cmd
5324 if (!list_empty(&q_full_list
)) {
5325 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
5326 list_splice(&q_full_list
, &vha
->hw
->tgt
.q_full_list
);
5327 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
5334 qlt_send_busy(struct qla_qpair
*qpair
, struct atio_from_isp
*atio
,
5338 struct scsi_qla_host
*vha
= qpair
->vha
;
5340 rc
= __qlt_send_busy(qpair
, atio
, status
);
5342 qlt_alloc_qfull_cmd(vha
, atio
, status
, 1);
5346 qlt_chk_qfull_thresh_hold(struct scsi_qla_host
*vha
, struct qla_qpair
*qpair
,
5347 struct atio_from_isp
*atio
, uint8_t ha_locked
)
5349 struct qla_hw_data
*ha
= vha
->hw
;
5351 unsigned long flags
;
5353 if (ha
->tgt
.num_pend_cmds
< Q_FULL_THRESH_HOLD(ha
))
5357 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5358 status
= temp_sam_status
;
5359 qlt_send_busy(qpair
, atio
, status
);
5361 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5366 /* ha->hardware_lock supposed to be held on entry */
5367 /* called via callback from qla2xxx */
5368 static void qlt_24xx_atio_pkt(struct scsi_qla_host
*vha
,
5369 struct atio_from_isp
*atio
, uint8_t ha_locked
)
5371 struct qla_hw_data
*ha
= vha
->hw
;
5372 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5374 unsigned long flags
;
5376 if (unlikely(tgt
== NULL
)) {
5377 ql_dbg(ql_dbg_tgt
, vha
, 0x3064,
5378 "ATIO pkt, but no tgt (ha %p)", ha
);
5382 * In tgt_stop mode we also should allow all requests to pass.
5383 * Otherwise, some commands can stuck.
5386 tgt
->atio_irq_cmd_count
++;
5388 switch (atio
->u
.raw
.entry_type
) {
5390 if (unlikely(atio
->u
.isp24
.exchange_addr
==
5391 ATIO_EXCHANGE_ADDRESS_UNKNOWN
)) {
5392 ql_dbg(ql_dbg_io
, vha
, 0x3065,
5393 "qla_target(%d): ATIO_TYPE7 "
5394 "received with UNKNOWN exchange address, "
5395 "sending QUEUE_FULL\n", vha
->vp_idx
);
5397 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5398 qlt_send_busy(ha
->base_qpair
, atio
,
5399 SAM_STAT_TASK_SET_FULL
);
5401 spin_unlock_irqrestore(&ha
->hardware_lock
,
5406 if (likely(atio
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
== 0)) {
5407 rc
= qlt_chk_qfull_thresh_hold(vha
, ha
->base_qpair
,
5410 tgt
->atio_irq_cmd_count
--;
5413 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
5415 rc
= qlt_handle_task_mgmt(vha
, atio
);
5417 if (unlikely(rc
!= 0)) {
5420 spin_lock_irqsave(&ha
->hardware_lock
,
5423 #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */
5424 qlt_send_busy(ha
->base_qpair
, atio
,
5427 qlt_send_term_exchange(ha
->base_qpair
, NULL
,
5431 spin_unlock_irqrestore(
5432 &ha
->hardware_lock
, flags
);
5434 if (tgt
->tgt_stop
) {
5435 ql_dbg(ql_dbg_tgt
, vha
, 0xe059,
5436 "qla_target: Unable to send "
5437 "command to target for req, "
5440 ql_dbg(ql_dbg_tgt
, vha
, 0xe05a,
5441 "qla_target(%d): Unable to send "
5442 "command to target, sending BUSY "
5443 "status.\n", vha
->vp_idx
);
5446 &ha
->hardware_lock
, flags
);
5447 qlt_send_busy(ha
->base_qpair
,
5448 atio
, SAM_STAT_BUSY
);
5450 spin_unlock_irqrestore(
5451 &ha
->hardware_lock
, flags
);
5457 case IMMED_NOTIFY_TYPE
:
5459 if (unlikely(atio
->u
.isp2x
.entry_status
!= 0)) {
5460 ql_dbg(ql_dbg_tgt
, vha
, 0xe05b,
5461 "qla_target(%d): Received ATIO packet %x "
5462 "with error status %x\n", vha
->vp_idx
,
5463 atio
->u
.raw
.entry_type
,
5464 atio
->u
.isp2x
.entry_status
);
5467 ql_dbg(ql_dbg_tgt
, vha
, 0xe02e, "%s", "IMMED_NOTIFY ATIO");
5470 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5471 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)atio
);
5473 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5478 ql_dbg(ql_dbg_tgt
, vha
, 0xe05c,
5479 "qla_target(%d): Received unknown ATIO atio "
5480 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
5484 tgt
->atio_irq_cmd_count
--;
5487 /* ha->hardware_lock supposed to be held on entry */
5488 /* called via callback from qla2xxx */
5489 static void qlt_response_pkt(struct scsi_qla_host
*vha
,
5490 struct rsp_que
*rsp
, response_t
*pkt
)
5492 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5494 if (unlikely(tgt
== NULL
)) {
5495 ql_dbg(ql_dbg_tgt
, vha
, 0xe05d,
5496 "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n",
5497 vha
->vp_idx
, pkt
->entry_type
, vha
->hw
);
5502 * In tgt_stop mode we also should allow all requests to pass.
5503 * Otherwise, some commands can stuck.
5506 switch (pkt
->entry_type
) {
5510 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
5511 qlt_do_ctio_completion(vha
, rsp
, entry
->handle
,
5512 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5517 case ACCEPT_TGT_IO_TYPE
:
5519 struct atio_from_isp
*atio
= (struct atio_from_isp
*)pkt
;
5521 if (atio
->u
.isp2x
.status
!=
5522 cpu_to_le16(ATIO_CDB_VALID
)) {
5523 ql_dbg(ql_dbg_tgt
, vha
, 0xe05e,
5524 "qla_target(%d): ATIO with error "
5525 "status %x received\n", vha
->vp_idx
,
5526 le16_to_cpu(atio
->u
.isp2x
.status
));
5530 rc
= qlt_chk_qfull_thresh_hold(vha
, rsp
->qpair
, atio
, 1);
5534 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
5535 if (unlikely(rc
!= 0)) {
5537 #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */
5538 qlt_send_busy(rsp
->qpair
, atio
, 0);
5540 qlt_send_term_exchange(rsp
->qpair
, NULL
, atio
, 1, 0);
5543 if (tgt
->tgt_stop
) {
5544 ql_dbg(ql_dbg_tgt
, vha
, 0xe05f,
5545 "qla_target: Unable to send "
5546 "command to target, sending TERM "
5547 "EXCHANGE for rsp\n");
5548 qlt_send_term_exchange(rsp
->qpair
, NULL
,
5551 ql_dbg(ql_dbg_tgt
, vha
, 0xe060,
5552 "qla_target(%d): Unable to send "
5553 "command to target, sending BUSY "
5554 "status\n", vha
->vp_idx
);
5555 qlt_send_busy(rsp
->qpair
, atio
, 0);
5562 case CONTINUE_TGT_IO_TYPE
:
5564 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
5565 qlt_do_ctio_completion(vha
, rsp
, entry
->handle
,
5566 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5573 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
5574 qlt_do_ctio_completion(vha
, rsp
, entry
->handle
,
5575 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5580 case IMMED_NOTIFY_TYPE
:
5581 ql_dbg(ql_dbg_tgt
, vha
, 0xe035, "%s", "IMMED_NOTIFY\n");
5582 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)pkt
);
5585 case NOTIFY_ACK_TYPE
:
5586 if (tgt
->notify_ack_expected
> 0) {
5587 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
5588 ql_dbg(ql_dbg_tgt
, vha
, 0xe036,
5589 "NOTIFY_ACK seq %08x status %x\n",
5590 le16_to_cpu(entry
->u
.isp2x
.seq_id
),
5591 le16_to_cpu(entry
->u
.isp2x
.status
));
5592 tgt
->notify_ack_expected
--;
5593 if (entry
->u
.isp2x
.status
!=
5594 cpu_to_le16(NOTIFY_ACK_SUCCESS
)) {
5595 ql_dbg(ql_dbg_tgt
, vha
, 0xe061,
5596 "qla_target(%d): NOTIFY_ACK "
5597 "failed %x\n", vha
->vp_idx
,
5598 le16_to_cpu(entry
->u
.isp2x
.status
));
5601 ql_dbg(ql_dbg_tgt
, vha
, 0xe062,
5602 "qla_target(%d): Unexpected NOTIFY_ACK received\n",
5607 case ABTS_RECV_24XX
:
5608 ql_dbg(ql_dbg_tgt
, vha
, 0xe037,
5609 "ABTS_RECV_24XX: instance %d\n", vha
->vp_idx
);
5610 qlt_24xx_handle_abts(vha
, (struct abts_recv_from_24xx
*)pkt
);
5613 case ABTS_RESP_24XX
:
5614 if (tgt
->abts_resp_expected
> 0) {
5615 struct abts_resp_from_24xx_fw
*entry
=
5616 (struct abts_resp_from_24xx_fw
*)pkt
;
5617 ql_dbg(ql_dbg_tgt
, vha
, 0xe038,
5618 "ABTS_RESP_24XX: compl_status %x\n",
5619 entry
->compl_status
);
5620 tgt
->abts_resp_expected
--;
5621 if (le16_to_cpu(entry
->compl_status
) !=
5622 ABTS_RESP_COMPL_SUCCESS
) {
5623 if ((entry
->error_subcode1
== 0x1E) &&
5624 (entry
->error_subcode2
== 0)) {
5626 * We've got a race here: aborted
5627 * exchange not terminated, i.e.
5628 * response for the aborted command was
5629 * sent between the abort request was
5630 * received and processed.
5631 * Unfortunately, the firmware has a
5632 * silly requirement that all aborted
5633 * exchanges must be explicitely
5634 * terminated, otherwise it refuses to
5635 * send responses for the abort
5636 * requests. So, we have to
5637 * (re)terminate the exchange and retry
5638 * the abort response.
5640 qlt_24xx_retry_term_exchange(vha
,
5643 ql_dbg(ql_dbg_tgt
, vha
, 0xe063,
5644 "qla_target(%d): ABTS_RESP_24XX "
5645 "failed %x (subcode %x:%x)",
5646 vha
->vp_idx
, entry
->compl_status
,
5647 entry
->error_subcode1
,
5648 entry
->error_subcode2
);
5651 ql_dbg(ql_dbg_tgt
, vha
, 0xe064,
5652 "qla_target(%d): Unexpected ABTS_RESP_24XX "
5653 "received\n", vha
->vp_idx
);
5658 ql_dbg(ql_dbg_tgt
, vha
, 0xe065,
5659 "qla_target(%d): Received unknown response pkt "
5660 "type %x\n", vha
->vp_idx
, pkt
->entry_type
);
5667 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5669 void qlt_async_event(uint16_t code
, struct scsi_qla_host
*vha
,
5672 struct qla_hw_data
*ha
= vha
->hw
;
5673 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5676 if (!tgt
|| tgt
->tgt_stop
|| tgt
->tgt_stopped
)
5679 if (((code
== MBA_POINT_TO_POINT
) || (code
== MBA_CHG_IN_CONNECTION
)) &&
5683 * In tgt_stop mode we also should allow all requests to pass.
5684 * Otherwise, some commands can stuck.
5689 case MBA_RESET
: /* Reset */
5690 case MBA_SYSTEM_ERR
: /* System Error */
5691 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
5692 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
5693 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03a,
5694 "qla_target(%d): System error async event %#x "
5695 "occurred", vha
->vp_idx
, code
);
5697 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up. */
5698 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
5703 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03b,
5704 "qla_target(%d): Async LOOP_UP occurred "
5705 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
,
5706 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5707 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5708 if (tgt
->link_reinit_iocb_pending
) {
5709 qlt_send_notify_ack(ha
->base_qpair
,
5710 (void *)&tgt
->link_reinit_iocb
,
5712 tgt
->link_reinit_iocb_pending
= 0;
5717 case MBA_LIP_OCCURRED
:
5720 case MBA_RSCN_UPDATE
:
5721 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03c,
5722 "qla_target(%d): Async event %#x occurred "
5723 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
5724 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5725 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5728 case MBA_REJECTED_FCP_CMD
:
5729 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf017,
5730 "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)",
5732 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5733 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5735 if (le16_to_cpu(mailbox
[3]) == 1) {
5736 /* exchange starvation. */
5737 vha
->hw
->exch_starvation
++;
5738 if (vha
->hw
->exch_starvation
> 5) {
5739 ql_log(ql_log_warn
, vha
, 0xd03a,
5740 "Exchange starvation-. Resetting RISC\n");
5742 vha
->hw
->exch_starvation
= 0;
5743 if (IS_P3P_TYPE(vha
->hw
))
5744 set_bit(FCOE_CTX_RESET_NEEDED
,
5747 set_bit(ISP_ABORT_NEEDED
,
5749 qla2xxx_wake_dpc(vha
);
5754 case MBA_PORT_UPDATE
:
5755 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03d,
5756 "qla_target(%d): Port update async event %#x "
5757 "occurred: updating the ports database (m[0]=%x, m[1]=%x, "
5758 "m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
5759 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5760 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5762 login_code
= le16_to_cpu(mailbox
[2]);
5763 if (login_code
== 0x4) {
5764 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03e,
5765 "Async MB 2: Got PLOGI Complete\n");
5766 vha
->hw
->exch_starvation
= 0;
5767 } else if (login_code
== 0x7)
5768 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03f,
5769 "Async MB 2: Port Logged Out\n");
5777 static fc_port_t
*qlt_get_port_database(struct scsi_qla_host
*vha
,
5780 fc_port_t
*fcport
, *tfcp
, *del
;
5782 unsigned long flags
;
5785 fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5787 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06f,
5788 "qla_target(%d): Allocation of tmp FC port failed",
5793 fcport
->loop_id
= loop_id
;
5795 rc
= qla24xx_gpdb_wait(vha
, fcport
, 0);
5796 if (rc
!= QLA_SUCCESS
) {
5797 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf070,
5798 "qla_target(%d): Failed to retrieve fcport "
5799 "information -- get_port_database() returned %x "
5800 "(loop_id=0x%04x)", vha
->vp_idx
, rc
, loop_id
);
5806 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5807 tfcp
= qla2x00_find_fcport_by_wwpn(vha
, fcport
->port_name
, 1);
5810 tfcp
->d_id
= fcport
->d_id
;
5811 tfcp
->port_type
= fcport
->port_type
;
5812 tfcp
->supported_classes
= fcport
->supported_classes
;
5813 tfcp
->flags
|= fcport
->flags
;
5814 tfcp
->scan_state
= QLA_FCPORT_FOUND
;
5819 if (vha
->hw
->current_topology
== ISP_CFG_F
)
5820 fcport
->flags
|= FCF_FABRIC_DEVICE
;
5822 list_add_tail(&fcport
->list
, &vha
->vp_fcports
);
5823 if (!IS_SW_RESV_ADDR(fcport
->d_id
))
5824 vha
->fcport_count
++;
5825 fcport
->login_gen
++;
5826 fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
5827 fcport
->login_succ
= 1;
5831 fcport
->deleted
= 0;
5832 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5834 switch (vha
->host
->active_mode
) {
5835 case MODE_INITIATOR
:
5838 if (!IS_IIDMA_CAPABLE(vha
->hw
) || !vha
->hw
->flags
.gpsc_supported
) {
5839 ql_dbg(ql_dbg_disc
, vha
, 0x20fe,
5840 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
5841 __func__
, __LINE__
, fcport
->port_name
, vha
->fcport_count
);
5842 qla24xx_post_upd_fcport_work(vha
, fcport
);
5844 ql_dbg(ql_dbg_disc
, vha
, 0x20ff,
5845 "%s %d %8phC post gpsc fcp_cnt %d\n",
5846 __func__
, __LINE__
, fcport
->port_name
, vha
->fcport_count
);
5847 qla24xx_post_gpsc_work(vha
, fcport
);
5857 qla2x00_free_fcport(del
);
5862 /* Must be called under tgt_mutex */
5863 static struct fc_port
*qlt_make_local_sess(struct scsi_qla_host
*vha
,
5866 struct fc_port
*sess
= NULL
;
5867 fc_port_t
*fcport
= NULL
;
5868 int rc
, global_resets
;
5869 uint16_t loop_id
= 0;
5871 if ((s_id
[0] == 0xFF) && (s_id
[1] == 0xFC)) {
5873 * This is Domain Controller, so it should be
5874 * OK to drop SCSI commands from it.
5876 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf042,
5877 "Unable to find initiator with S_ID %x:%x:%x",
5878 s_id
[0], s_id
[1], s_id
[2]);
5882 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
5886 atomic_read(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
);
5888 rc
= qla24xx_get_loop_id(vha
, s_id
, &loop_id
);
5890 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
5892 ql_log(ql_log_info
, vha
, 0xf071,
5893 "qla_target(%d): Unable to find "
5894 "initiator with S_ID %x:%x:%x",
5895 vha
->vp_idx
, s_id
[0], s_id
[1],
5898 if (rc
== -ENOENT
) {
5899 qlt_port_logo_t logo
;
5900 sid_to_portid(s_id
, &logo
.id
);
5902 qlt_send_first_logo(vha
, &logo
);
5908 fcport
= qlt_get_port_database(vha
, loop_id
);
5910 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
5914 if (global_resets
!=
5915 atomic_read(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
)) {
5916 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf043,
5917 "qla_target(%d): global reset during session discovery "
5918 "(counter was %d, new %d), retrying", vha
->vp_idx
,
5920 atomic_read(&vha
->vha_tgt
.
5921 qla_tgt
->tgt_global_resets_count
));
5925 sess
= qlt_create_sess(vha
, fcport
, true);
5927 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
5932 static void qlt_abort_work(struct qla_tgt
*tgt
,
5933 struct qla_tgt_sess_work_param
*prm
)
5935 struct scsi_qla_host
*vha
= tgt
->vha
;
5936 struct qla_hw_data
*ha
= vha
->hw
;
5937 struct fc_port
*sess
= NULL
;
5938 unsigned long flags
= 0, flags2
= 0;
5943 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags2
);
5948 s_id
[0] = prm
->abts
.fcp_hdr_le
.s_id
[2];
5949 s_id
[1] = prm
->abts
.fcp_hdr_le
.s_id
[1];
5950 s_id
[2] = prm
->abts
.fcp_hdr_le
.s_id
[0];
5952 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
5953 (unsigned char *)&be_s_id
);
5955 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
5957 sess
= qlt_make_local_sess(vha
, s_id
);
5958 /* sess has got an extra creation ref */
5960 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags2
);
5964 if (sess
->deleted
) {
5969 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
5970 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xf01c,
5971 "%s: kref_get fail %8phC \n",
5972 __func__
, sess
->port_name
);
5978 rc
= __qlt_24xx_handle_abts(vha
, &prm
->abts
, sess
);
5979 ha
->tgt
.tgt_ops
->put_sess(sess
);
5980 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
5988 ha
->tgt
.tgt_ops
->put_sess(sess
);
5989 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
5992 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5993 qlt_24xx_send_abts_resp(ha
->base_qpair
, &prm
->abts
,
5994 FCP_TMF_REJECTED
, false);
5995 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5998 static void qlt_tmr_work(struct qla_tgt
*tgt
,
5999 struct qla_tgt_sess_work_param
*prm
)
6001 struct atio_from_isp
*a
= &prm
->tm_iocb2
;
6002 struct scsi_qla_host
*vha
= tgt
->vha
;
6003 struct qla_hw_data
*ha
= vha
->hw
;
6004 struct fc_port
*sess
= NULL
;
6005 unsigned long flags
;
6006 uint8_t *s_id
= NULL
; /* to hide compiler warnings */
6012 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
6017 s_id
= prm
->tm_iocb2
.u
.isp24
.fcp_hdr
.s_id
;
6018 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
6020 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
6022 sess
= qlt_make_local_sess(vha
, s_id
);
6023 /* sess has got an extra creation ref */
6025 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
6029 if (sess
->deleted
) {
6034 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
6035 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xf020,
6036 "%s: kref_get fail %8phC\n",
6037 __func__
, sess
->port_name
);
6044 fn
= a
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
;
6046 scsilun_to_int((struct scsi_lun
*)&a
->u
.isp24
.fcp_cmnd
.lun
);
6048 rc
= qlt_issue_task_mgmt(sess
, unpacked_lun
, fn
, iocb
, 0);
6049 ha
->tgt
.tgt_ops
->put_sess(sess
);
6050 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
6058 ha
->tgt
.tgt_ops
->put_sess(sess
);
6059 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
6061 qlt_send_term_exchange(ha
->base_qpair
, NULL
, &prm
->tm_iocb2
, 1, 0);
6064 static void qlt_sess_work_fn(struct work_struct
*work
)
6066 struct qla_tgt
*tgt
= container_of(work
, struct qla_tgt
, sess_work
);
6067 struct scsi_qla_host
*vha
= tgt
->vha
;
6068 unsigned long flags
;
6070 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf000, "Sess work (tgt %p)", tgt
);
6072 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
6073 while (!list_empty(&tgt
->sess_works_list
)) {
6074 struct qla_tgt_sess_work_param
*prm
= list_entry(
6075 tgt
->sess_works_list
.next
, typeof(*prm
),
6076 sess_works_list_entry
);
6079 * This work can be scheduled on several CPUs at time, so we
6080 * must delete the entry to eliminate double processing
6082 list_del(&prm
->sess_works_list_entry
);
6084 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
6086 switch (prm
->type
) {
6087 case QLA_TGT_SESS_WORK_ABORT
:
6088 qlt_abort_work(tgt
, prm
);
6090 case QLA_TGT_SESS_WORK_TM
:
6091 qlt_tmr_work(tgt
, prm
);
6098 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
6102 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
6105 /* Must be called under tgt_host_action_mutex */
6106 int qlt_add_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*base_vha
)
6108 struct qla_tgt
*tgt
;
6110 struct qla_qpair_hint
*h
;
6112 if (!QLA_TGT_MODE_ENABLED())
6115 if (!IS_TGT_MODE_CAPABLE(ha
)) {
6116 ql_log(ql_log_warn
, base_vha
, 0xe070,
6117 "This adapter does not support target mode.\n");
6121 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe03b,
6122 "Registering target for host %ld(%p).\n", base_vha
->host_no
, ha
);
6124 BUG_ON(base_vha
->vha_tgt
.qla_tgt
!= NULL
);
6126 tgt
= kzalloc(sizeof(struct qla_tgt
), GFP_KERNEL
);
6128 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe066,
6129 "Unable to allocate struct qla_tgt\n");
6133 tgt
->qphints
= kzalloc((ha
->max_qpairs
+ 1) *
6134 sizeof(struct qla_qpair_hint
), GFP_KERNEL
);
6135 if (!tgt
->qphints
) {
6137 ql_log(ql_log_warn
, base_vha
, 0x0197,
6138 "Unable to allocate qpair hints.\n");
6142 if (!(base_vha
->host
->hostt
->supported_mode
& MODE_TARGET
))
6143 base_vha
->host
->hostt
->supported_mode
|= MODE_TARGET
;
6145 rc
= btree_init64(&tgt
->lun_qpair_map
);
6147 kfree(tgt
->qphints
);
6149 ql_log(ql_log_info
, base_vha
, 0x0198,
6150 "Unable to initialize lun_qpair_map btree\n");
6153 h
= &tgt
->qphints
[0];
6154 h
->qpair
= ha
->base_qpair
;
6155 INIT_LIST_HEAD(&h
->hint_elem
);
6156 h
->cpuid
= ha
->base_qpair
->cpuid
;
6157 list_add_tail(&h
->hint_elem
, &ha
->base_qpair
->hints_list
);
6159 for (i
= 0; i
< ha
->max_qpairs
; i
++) {
6160 unsigned long flags
;
6162 struct qla_qpair
*qpair
= ha
->queue_pair_map
[i
];
6163 h
= &tgt
->qphints
[i
+ 1];
6164 INIT_LIST_HEAD(&h
->hint_elem
);
6167 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
6168 list_add_tail(&h
->hint_elem
, &qpair
->hints_list
);
6169 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
6170 h
->cpuid
= qpair
->cpuid
;
6175 tgt
->vha
= base_vha
;
6176 init_waitqueue_head(&tgt
->waitQ
);
6177 INIT_LIST_HEAD(&tgt
->del_sess_list
);
6178 spin_lock_init(&tgt
->sess_work_lock
);
6179 INIT_WORK(&tgt
->sess_work
, qlt_sess_work_fn
);
6180 INIT_LIST_HEAD(&tgt
->sess_works_list
);
6181 atomic_set(&tgt
->tgt_global_resets_count
, 0);
6183 base_vha
->vha_tgt
.qla_tgt
= tgt
;
6185 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe067,
6186 "qla_target(%d): using 64 Bit PCI addressing",
6189 tgt
->sg_tablesize
= QLA_TGT_MAX_SG_24XX(base_vha
->req
->length
- 3);
6191 mutex_lock(&qla_tgt_mutex
);
6192 list_add_tail(&tgt
->tgt_list_entry
, &qla_tgt_glist
);
6193 mutex_unlock(&qla_tgt_mutex
);
6195 if (ha
->tgt
.tgt_ops
&& ha
->tgt
.tgt_ops
->add_target
)
6196 ha
->tgt
.tgt_ops
->add_target(base_vha
);
6201 /* Must be called under tgt_host_action_mutex */
6202 int qlt_remove_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*vha
)
6204 if (!vha
->vha_tgt
.qla_tgt
)
6207 if (vha
->fc_vport
) {
6208 qlt_release(vha
->vha_tgt
.qla_tgt
);
6212 /* free left over qfull cmds */
6213 qlt_init_term_exchange(vha
);
6215 ql_dbg(ql_dbg_tgt
, vha
, 0xe03c, "Unregistering target for host %ld(%p)",
6217 qlt_release(vha
->vha_tgt
.qla_tgt
);
6222 void qlt_remove_target_resources(struct qla_hw_data
*ha
)
6224 struct scsi_qla_host
*node
;
6227 btree_for_each_safe32(&ha
->tgt
.host_map
, key
, node
)
6228 btree_remove32(&ha
->tgt
.host_map
, key
);
6230 btree_destroy32(&ha
->tgt
.host_map
);
6233 static void qlt_lport_dump(struct scsi_qla_host
*vha
, u64 wwpn
,
6238 pr_debug("qla2xxx HW vha->node_name: ");
6239 for (i
= 0; i
< WWN_SIZE
; i
++)
6240 pr_debug("%02x ", vha
->node_name
[i
]);
6242 pr_debug("qla2xxx HW vha->port_name: ");
6243 for (i
= 0; i
< WWN_SIZE
; i
++)
6244 pr_debug("%02x ", vha
->port_name
[i
]);
6247 pr_debug("qla2xxx passed configfs WWPN: ");
6248 put_unaligned_be64(wwpn
, b
);
6249 for (i
= 0; i
< WWN_SIZE
; i
++)
6250 pr_debug("%02x ", b
[i
]);
6255 * qla_tgt_lport_register - register lport with external module
6257 * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops
6258 * @wwpn: Passwd FC target WWPN
6259 * @callback: lport initialization callback for tcm_qla2xxx code
6260 * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
6262 int qlt_lport_register(void *target_lport_ptr
, u64 phys_wwpn
,
6263 u64 npiv_wwpn
, u64 npiv_wwnn
,
6264 int (*callback
)(struct scsi_qla_host
*, void *, u64
, u64
))
6266 struct qla_tgt
*tgt
;
6267 struct scsi_qla_host
*vha
;
6268 struct qla_hw_data
*ha
;
6269 struct Scsi_Host
*host
;
6270 unsigned long flags
;
6274 mutex_lock(&qla_tgt_mutex
);
6275 list_for_each_entry(tgt
, &qla_tgt_glist
, tgt_list_entry
) {
6283 if (!(host
->hostt
->supported_mode
& MODE_TARGET
))
6286 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6287 if ((!npiv_wwpn
|| !npiv_wwnn
) && host
->active_mode
& MODE_TARGET
) {
6288 pr_debug("MODE_TARGET already active on qla2xxx(%d)\n",
6290 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6293 if (tgt
->tgt_stop
) {
6294 pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n",
6296 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6299 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6301 if (!scsi_host_get(host
)) {
6302 ql_dbg(ql_dbg_tgt
, vha
, 0xe068,
6303 "Unable to scsi_host_get() for"
6304 " qla2xxx scsi_host\n");
6307 qlt_lport_dump(vha
, phys_wwpn
, b
);
6309 if (memcmp(vha
->port_name
, b
, WWN_SIZE
)) {
6310 scsi_host_put(host
);
6313 rc
= (*callback
)(vha
, target_lport_ptr
, npiv_wwpn
, npiv_wwnn
);
6315 scsi_host_put(host
);
6317 mutex_unlock(&qla_tgt_mutex
);
6320 mutex_unlock(&qla_tgt_mutex
);
6324 EXPORT_SYMBOL(qlt_lport_register
);
6327 * qla_tgt_lport_deregister - Degister lport
6329 * @vha: Registered scsi_qla_host pointer
6331 void qlt_lport_deregister(struct scsi_qla_host
*vha
)
6333 struct qla_hw_data
*ha
= vha
->hw
;
6334 struct Scsi_Host
*sh
= vha
->host
;
6336 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
6338 vha
->vha_tgt
.target_lport_ptr
= NULL
;
6339 ha
->tgt
.tgt_ops
= NULL
;
6341 * Release the Scsi_Host reference for the underlying qla2xxx host
6345 EXPORT_SYMBOL(qlt_lport_deregister
);
6347 /* Must be called under HW lock */
6348 static void qlt_set_mode(struct scsi_qla_host
*vha
)
6350 switch (ql2x_ini_mode
) {
6351 case QLA2XXX_INI_MODE_DISABLED
:
6352 case QLA2XXX_INI_MODE_EXCLUSIVE
:
6353 vha
->host
->active_mode
= MODE_TARGET
;
6355 case QLA2XXX_INI_MODE_ENABLED
:
6356 vha
->host
->active_mode
= MODE_UNKNOWN
;
6358 case QLA2XXX_INI_MODE_DUAL
:
6359 vha
->host
->active_mode
= MODE_DUAL
;
6366 /* Must be called under HW lock */
6367 static void qlt_clear_mode(struct scsi_qla_host
*vha
)
6369 switch (ql2x_ini_mode
) {
6370 case QLA2XXX_INI_MODE_DISABLED
:
6371 vha
->host
->active_mode
= MODE_UNKNOWN
;
6373 case QLA2XXX_INI_MODE_EXCLUSIVE
:
6374 vha
->host
->active_mode
= MODE_INITIATOR
;
6376 case QLA2XXX_INI_MODE_ENABLED
:
6377 case QLA2XXX_INI_MODE_DUAL
:
6378 vha
->host
->active_mode
= MODE_INITIATOR
;
6386 * qla_tgt_enable_vha - NO LOCK HELD
6388 * host_reset, bring up w/ Target Mode Enabled
6391 qlt_enable_vha(struct scsi_qla_host
*vha
)
6393 struct qla_hw_data
*ha
= vha
->hw
;
6394 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
6395 unsigned long flags
;
6396 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
6399 ql_dbg(ql_dbg_tgt
, vha
, 0xe069,
6400 "Unable to locate qla_tgt pointer from"
6401 " struct qla_hw_data\n");
6406 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6407 tgt
->tgt_stopped
= 0;
6409 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6412 qla24xx_disable_vp(vha
);
6413 qla24xx_enable_vp(vha
);
6415 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
6416 qla2xxx_wake_dpc(base_vha
);
6417 qla2x00_wait_for_hba_online(base_vha
);
6420 EXPORT_SYMBOL(qlt_enable_vha
);
6423 * qla_tgt_disable_vha - NO LOCK HELD
6425 * Disable Target Mode and reset the adapter
6427 static void qlt_disable_vha(struct scsi_qla_host
*vha
)
6429 struct qla_hw_data
*ha
= vha
->hw
;
6430 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
6431 unsigned long flags
;
6434 ql_dbg(ql_dbg_tgt
, vha
, 0xe06a,
6435 "Unable to locate qla_tgt pointer from"
6436 " struct qla_hw_data\n");
6441 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6442 qlt_clear_mode(vha
);
6443 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6445 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6446 qla2xxx_wake_dpc(vha
);
6447 qla2x00_wait_for_hba_online(vha
);
6451 * Called from qla_init.c:qla24xx_vport_create() contex to setup
6452 * the target mode specific struct scsi_qla_host and struct qla_hw_data
6456 qlt_vport_create(struct scsi_qla_host
*vha
, struct qla_hw_data
*ha
)
6458 vha
->vha_tgt
.qla_tgt
= NULL
;
6460 mutex_init(&vha
->vha_tgt
.tgt_mutex
);
6461 mutex_init(&vha
->vha_tgt
.tgt_host_action_mutex
);
6463 qlt_clear_mode(vha
);
6466 * NOTE: Currently the value is kept the same for <24xx and
6467 * >=24xx ISPs. If it is necessary to change it,
6468 * the check should be added for specific ISPs,
6469 * assigning the value appropriately.
6471 ha
->tgt
.atio_q_length
= ATIO_ENTRY_CNT_24XX
;
6473 qlt_add_target(ha
, vha
);
6477 qlt_rff_id(struct scsi_qla_host
*vha
, struct ct_sns_req
*ct_req
)
6480 * FC-4 Feature bit 0 indicates target functionality to the name server.
6482 if (qla_tgt_mode_enabled(vha
)) {
6483 ct_req
->req
.rff_id
.fc4_feature
= BIT_0
;
6484 } else if (qla_ini_mode_enabled(vha
)) {
6485 ct_req
->req
.rff_id
.fc4_feature
= BIT_1
;
6486 } else if (qla_dual_mode_enabled(vha
))
6487 ct_req
->req
.rff_id
.fc4_feature
= BIT_0
| BIT_1
;
6491 * qlt_init_atio_q_entries() - Initializes ATIO queue entries.
6494 * Beginning of ATIO ring has initialization control block already built
6495 * by nvram config routine.
6497 * Returns 0 on success.
6500 qlt_init_atio_q_entries(struct scsi_qla_host
*vha
)
6502 struct qla_hw_data
*ha
= vha
->hw
;
6504 struct atio_from_isp
*pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring
;
6506 if (qla_ini_mode_enabled(vha
))
6509 for (cnt
= 0; cnt
< ha
->tgt
.atio_q_length
; cnt
++) {
6510 pkt
->u
.raw
.signature
= ATIO_PROCESSED
;
6517 * qlt_24xx_process_atio_queue() - Process ATIO queue entries.
6518 * @ha: SCSI driver HA context
6521 qlt_24xx_process_atio_queue(struct scsi_qla_host
*vha
, uint8_t ha_locked
)
6523 struct qla_hw_data
*ha
= vha
->hw
;
6524 struct atio_from_isp
*pkt
;
6527 if (!ha
->flags
.fw_started
)
6530 while ((ha
->tgt
.atio_ring_ptr
->signature
!= ATIO_PROCESSED
) ||
6531 fcpcmd_is_corrupted(ha
->tgt
.atio_ring_ptr
)) {
6532 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
6533 cnt
= pkt
->u
.raw
.entry_count
;
6535 if (unlikely(fcpcmd_is_corrupted(ha
->tgt
.atio_ring_ptr
))) {
6537 * This packet is corrupted. The header + payload
6538 * can not be trusted. There is no point in passing
6541 ql_log(ql_log_warn
, vha
, 0xd03c,
6542 "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n",
6543 pkt
->u
.isp24
.fcp_hdr
.s_id
,
6544 be16_to_cpu(pkt
->u
.isp24
.fcp_hdr
.ox_id
),
6545 le32_to_cpu(pkt
->u
.isp24
.exchange_addr
), pkt
);
6547 adjust_corrupted_atio(pkt
);
6548 qlt_send_term_exchange(ha
->base_qpair
, NULL
, pkt
,
6551 qlt_24xx_atio_pkt_all_vps(vha
,
6552 (struct atio_from_isp
*)pkt
, ha_locked
);
6555 for (i
= 0; i
< cnt
; i
++) {
6556 ha
->tgt
.atio_ring_index
++;
6557 if (ha
->tgt
.atio_ring_index
== ha
->tgt
.atio_q_length
) {
6558 ha
->tgt
.atio_ring_index
= 0;
6559 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
6561 ha
->tgt
.atio_ring_ptr
++;
6563 pkt
->u
.raw
.signature
= ATIO_PROCESSED
;
6564 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
6569 /* Adjust ring index */
6570 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha
), ha
->tgt
.atio_ring_index
);
6574 qlt_24xx_config_rings(struct scsi_qla_host
*vha
)
6576 struct qla_hw_data
*ha
= vha
->hw
;
6577 struct init_cb_24xx
*icb
;
6578 if (!QLA_TGT_MODE_ENABLED())
6581 WRT_REG_DWORD(ISP_ATIO_Q_IN(vha
), 0);
6582 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha
), 0);
6583 RD_REG_DWORD(ISP_ATIO_Q_OUT(vha
));
6585 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
6587 if ((ql2xenablemsix
!= 0) && IS_ATIO_MSIX_CAPABLE(ha
)) {
6588 struct qla_msix_entry
*msix
= &ha
->msix_entries
[2];
6590 icb
->msix_atio
= cpu_to_le16(msix
->entry
);
6591 ql_dbg(ql_dbg_init
, vha
, 0xf072,
6592 "Registering ICB vector 0x%x for atio que.\n",
6594 } else if (ql2xenablemsix
== 0) {
6595 icb
->firmware_options_2
|= cpu_to_le32(BIT_26
);
6596 ql_dbg(ql_dbg_init
, vha
, 0xf07f,
6597 "Registering INTx vector for ATIO.\n");
6602 qlt_24xx_config_nvram_stage1(struct scsi_qla_host
*vha
, struct nvram_24xx
*nv
)
6604 struct qla_hw_data
*ha
= vha
->hw
;
6606 if (!QLA_TGT_MODE_ENABLED())
6609 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
6610 if (!ha
->tgt
.saved_set
) {
6611 /* We save only once */
6612 ha
->tgt
.saved_exchange_count
= nv
->exchange_count
;
6613 ha
->tgt
.saved_firmware_options_1
=
6614 nv
->firmware_options_1
;
6615 ha
->tgt
.saved_firmware_options_2
=
6616 nv
->firmware_options_2
;
6617 ha
->tgt
.saved_firmware_options_3
=
6618 nv
->firmware_options_3
;
6619 ha
->tgt
.saved_set
= 1;
6622 if (qla_tgt_mode_enabled(vha
))
6623 nv
->exchange_count
= cpu_to_le16(0xFFFF);
6625 nv
->exchange_count
= cpu_to_le16(ql2xexchoffld
);
6627 /* Enable target mode */
6628 nv
->firmware_options_1
|= cpu_to_le32(BIT_4
);
6630 /* Disable ini mode, if requested */
6631 if (qla_tgt_mode_enabled(vha
))
6632 nv
->firmware_options_1
|= cpu_to_le32(BIT_5
);
6634 /* Disable Full Login after LIP */
6635 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
6636 /* Enable initial LIP */
6637 nv
->firmware_options_1
&= cpu_to_le32(~BIT_9
);
6638 if (ql2xtgt_tape_enable
)
6639 /* Enable FC Tape support */
6640 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6642 /* Disable FC Tape support */
6643 nv
->firmware_options_2
&= cpu_to_le32(~BIT_12
);
6645 /* Disable Full Login after LIP */
6646 nv
->host_p
&= cpu_to_le32(~BIT_10
);
6649 * clear BIT 15 explicitly as we have seen at least
6650 * a couple of instances where this was set and this
6651 * was causing the firmware to not be initialized.
6653 nv
->firmware_options_1
&= cpu_to_le32(~BIT_15
);
6654 /* Enable target PRLI control */
6655 nv
->firmware_options_2
|= cpu_to_le32(BIT_14
);
6657 if (ha
->tgt
.saved_set
) {
6658 nv
->exchange_count
= ha
->tgt
.saved_exchange_count
;
6659 nv
->firmware_options_1
=
6660 ha
->tgt
.saved_firmware_options_1
;
6661 nv
->firmware_options_2
=
6662 ha
->tgt
.saved_firmware_options_2
;
6663 nv
->firmware_options_3
=
6664 ha
->tgt
.saved_firmware_options_3
;
6669 if (ha
->base_qpair
->enable_class_2
) {
6670 if (vha
->flags
.init_done
)
6671 fc_host_supported_classes(vha
->host
) =
6672 FC_COS_CLASS2
| FC_COS_CLASS3
;
6674 nv
->firmware_options_2
|= cpu_to_le32(BIT_8
);
6676 if (vha
->flags
.init_done
)
6677 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
6679 nv
->firmware_options_2
&= ~cpu_to_le32(BIT_8
);
6684 qlt_24xx_config_nvram_stage2(struct scsi_qla_host
*vha
,
6685 struct init_cb_24xx
*icb
)
6687 struct qla_hw_data
*ha
= vha
->hw
;
6689 if (!QLA_TGT_MODE_ENABLED())
6692 if (ha
->tgt
.node_name_set
) {
6693 memcpy(icb
->node_name
, ha
->tgt
.tgt_node_name
, WWN_SIZE
);
6694 icb
->firmware_options_1
|= cpu_to_le32(BIT_14
);
6697 /* disable ZIO at start time. */
6698 if (!vha
->flags
.init_done
) {
6700 tmp
= le32_to_cpu(icb
->firmware_options_2
);
6701 tmp
&= ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
6702 icb
->firmware_options_2
= cpu_to_le32(tmp
);
6707 qlt_81xx_config_nvram_stage1(struct scsi_qla_host
*vha
, struct nvram_81xx
*nv
)
6709 struct qla_hw_data
*ha
= vha
->hw
;
6711 if (!QLA_TGT_MODE_ENABLED())
6714 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
6715 if (!ha
->tgt
.saved_set
) {
6716 /* We save only once */
6717 ha
->tgt
.saved_exchange_count
= nv
->exchange_count
;
6718 ha
->tgt
.saved_firmware_options_1
=
6719 nv
->firmware_options_1
;
6720 ha
->tgt
.saved_firmware_options_2
=
6721 nv
->firmware_options_2
;
6722 ha
->tgt
.saved_firmware_options_3
=
6723 nv
->firmware_options_3
;
6724 ha
->tgt
.saved_set
= 1;
6727 if (qla_tgt_mode_enabled(vha
))
6728 nv
->exchange_count
= cpu_to_le16(0xFFFF);
6730 nv
->exchange_count
= cpu_to_le16(ql2xexchoffld
);
6732 /* Enable target mode */
6733 nv
->firmware_options_1
|= cpu_to_le32(BIT_4
);
6735 /* Disable ini mode, if requested */
6736 if (qla_tgt_mode_enabled(vha
))
6737 nv
->firmware_options_1
|= cpu_to_le32(BIT_5
);
6738 /* Disable Full Login after LIP */
6739 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
6740 /* Enable initial LIP */
6741 nv
->firmware_options_1
&= cpu_to_le32(~BIT_9
);
6743 * clear BIT 15 explicitly as we have seen at
6744 * least a couple of instances where this was set
6745 * and this was causing the firmware to not be
6748 nv
->firmware_options_1
&= cpu_to_le32(~BIT_15
);
6749 if (ql2xtgt_tape_enable
)
6750 /* Enable FC tape support */
6751 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6753 /* Disable FC tape support */
6754 nv
->firmware_options_2
&= cpu_to_le32(~BIT_12
);
6756 /* Disable Full Login after LIP */
6757 nv
->host_p
&= cpu_to_le32(~BIT_10
);
6758 /* Enable target PRLI control */
6759 nv
->firmware_options_2
|= cpu_to_le32(BIT_14
);
6761 if (ha
->tgt
.saved_set
) {
6762 nv
->exchange_count
= ha
->tgt
.saved_exchange_count
;
6763 nv
->firmware_options_1
=
6764 ha
->tgt
.saved_firmware_options_1
;
6765 nv
->firmware_options_2
=
6766 ha
->tgt
.saved_firmware_options_2
;
6767 nv
->firmware_options_3
=
6768 ha
->tgt
.saved_firmware_options_3
;
6773 if (ha
->base_qpair
->enable_class_2
) {
6774 if (vha
->flags
.init_done
)
6775 fc_host_supported_classes(vha
->host
) =
6776 FC_COS_CLASS2
| FC_COS_CLASS3
;
6778 nv
->firmware_options_2
|= cpu_to_le32(BIT_8
);
6780 if (vha
->flags
.init_done
)
6781 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
6783 nv
->firmware_options_2
&= ~cpu_to_le32(BIT_8
);
6788 qlt_81xx_config_nvram_stage2(struct scsi_qla_host
*vha
,
6789 struct init_cb_81xx
*icb
)
6791 struct qla_hw_data
*ha
= vha
->hw
;
6793 if (!QLA_TGT_MODE_ENABLED())
6796 if (ha
->tgt
.node_name_set
) {
6797 memcpy(icb
->node_name
, ha
->tgt
.tgt_node_name
, WWN_SIZE
);
6798 icb
->firmware_options_1
|= cpu_to_le32(BIT_14
);
6801 /* disable ZIO at start time. */
6802 if (!vha
->flags
.init_done
) {
6804 tmp
= le32_to_cpu(icb
->firmware_options_2
);
6805 tmp
&= ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
6806 icb
->firmware_options_2
= cpu_to_le32(tmp
);
6812 qlt_83xx_iospace_config(struct qla_hw_data
*ha
)
6814 if (!QLA_TGT_MODE_ENABLED())
6817 ha
->msix_count
+= 1; /* For ATIO Q */
6822 qlt_modify_vp_config(struct scsi_qla_host
*vha
,
6823 struct vp_config_entry_24xx
*vpmod
)
6825 /* enable target mode. Bit5 = 1 => disable */
6826 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
6827 vpmod
->options_idx1
&= ~BIT_5
;
6829 /* Disable ini mode, if requested. bit4 = 1 => disable */
6830 if (qla_tgt_mode_enabled(vha
))
6831 vpmod
->options_idx1
&= ~BIT_4
;
6835 qlt_probe_one_stage1(struct scsi_qla_host
*base_vha
, struct qla_hw_data
*ha
)
6839 if (!QLA_TGT_MODE_ENABLED())
6842 if ((ql2xenablemsix
== 0) || IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
6843 ISP_ATIO_Q_IN(base_vha
) = &ha
->mqiobase
->isp25mq
.atio_q_in
;
6844 ISP_ATIO_Q_OUT(base_vha
) = &ha
->mqiobase
->isp25mq
.atio_q_out
;
6846 ISP_ATIO_Q_IN(base_vha
) = &ha
->iobase
->isp24
.atio_q_in
;
6847 ISP_ATIO_Q_OUT(base_vha
) = &ha
->iobase
->isp24
.atio_q_out
;
6850 mutex_init(&base_vha
->vha_tgt
.tgt_mutex
);
6851 mutex_init(&base_vha
->vha_tgt
.tgt_host_action_mutex
);
6853 INIT_LIST_HEAD(&base_vha
->unknown_atio_list
);
6854 INIT_DELAYED_WORK(&base_vha
->unknown_atio_work
,
6855 qlt_unknown_atio_work_fn
);
6857 qlt_clear_mode(base_vha
);
6859 rc
= btree_init32(&ha
->tgt
.host_map
);
6861 ql_log(ql_log_info
, base_vha
, 0xd03d,
6862 "Unable to initialize ha->host_map btree\n");
6864 qlt_update_vp_map(base_vha
, SET_VP_IDX
);
6868 qla83xx_msix_atio_q(int irq
, void *dev_id
)
6870 struct rsp_que
*rsp
;
6871 scsi_qla_host_t
*vha
;
6872 struct qla_hw_data
*ha
;
6873 unsigned long flags
;
6875 rsp
= (struct rsp_que
*) dev_id
;
6877 vha
= pci_get_drvdata(ha
->pdev
);
6879 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
6881 qlt_24xx_process_atio_queue(vha
, 0);
6883 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags
);
6889 qlt_handle_abts_recv_work(struct work_struct
*work
)
6891 struct qla_tgt_sess_op
*op
= container_of(work
,
6892 struct qla_tgt_sess_op
, work
);
6893 scsi_qla_host_t
*vha
= op
->vha
;
6894 struct qla_hw_data
*ha
= vha
->hw
;
6895 unsigned long flags
;
6897 if (qla2x00_reset_active(vha
) ||
6898 (op
->chip_reset
!= ha
->base_qpair
->chip_reset
))
6901 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
6902 qlt_24xx_process_atio_queue(vha
, 0);
6903 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags
);
6905 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6906 qlt_response_pkt_all_vps(vha
, op
->rsp
, (response_t
*)&op
->atio
);
6907 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6913 qlt_handle_abts_recv(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
,
6916 struct qla_tgt_sess_op
*op
;
6918 op
= kzalloc(sizeof(*op
), GFP_ATOMIC
);
6921 /* do not reach for ATIO queue here. This is best effort err
6922 * recovery at this point.
6924 qlt_response_pkt_all_vps(vha
, rsp
, pkt
);
6928 memcpy(&op
->atio
, pkt
, sizeof(*pkt
));
6930 op
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
6932 INIT_WORK(&op
->work
, qlt_handle_abts_recv_work
);
6933 queue_work(qla_tgt_wq
, &op
->work
);
6938 qlt_mem_alloc(struct qla_hw_data
*ha
)
6940 if (!QLA_TGT_MODE_ENABLED())
6943 ha
->tgt
.tgt_vp_map
= kzalloc(sizeof(struct qla_tgt_vp_map
) *
6944 MAX_MULTI_ID_FABRIC
, GFP_KERNEL
);
6945 if (!ha
->tgt
.tgt_vp_map
)
6948 ha
->tgt
.atio_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
6949 (ha
->tgt
.atio_q_length
+ 1) * sizeof(struct atio_from_isp
),
6950 &ha
->tgt
.atio_dma
, GFP_KERNEL
);
6951 if (!ha
->tgt
.atio_ring
) {
6952 kfree(ha
->tgt
.tgt_vp_map
);
6959 qlt_mem_free(struct qla_hw_data
*ha
)
6961 if (!QLA_TGT_MODE_ENABLED())
6964 if (ha
->tgt
.atio_ring
) {
6965 dma_free_coherent(&ha
->pdev
->dev
, (ha
->tgt
.atio_q_length
+ 1) *
6966 sizeof(struct atio_from_isp
), ha
->tgt
.atio_ring
,
6969 kfree(ha
->tgt
.tgt_vp_map
);
6972 /* vport_slock to be held by the caller */
6974 qlt_update_vp_map(struct scsi_qla_host
*vha
, int cmd
)
6980 if (!QLA_TGT_MODE_ENABLED())
6983 key
= vha
->d_id
.b24
;
6987 vha
->hw
->tgt
.tgt_vp_map
[vha
->vp_idx
].vha
= vha
;
6990 slot
= btree_lookup32(&vha
->hw
->tgt
.host_map
, key
);
6992 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf018,
6993 "Save vha in host_map %p %06x\n", vha
, key
);
6994 rc
= btree_insert32(&vha
->hw
->tgt
.host_map
,
6995 key
, vha
, GFP_ATOMIC
);
6997 ql_log(ql_log_info
, vha
, 0xd03e,
6998 "Unable to insert s_id into host_map: %06x\n",
7002 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf019,
7003 "replace existing vha in host_map %p %06x\n", vha
, key
);
7004 btree_update32(&vha
->hw
->tgt
.host_map
, key
, vha
);
7007 vha
->hw
->tgt
.tgt_vp_map
[vha
->vp_idx
].vha
= NULL
;
7010 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01a,
7011 "clear vha in host_map %p %06x\n", vha
, key
);
7012 slot
= btree_lookup32(&vha
->hw
->tgt
.host_map
, key
);
7014 btree_remove32(&vha
->hw
->tgt
.host_map
, key
);
7020 void qlt_update_host_map(struct scsi_qla_host
*vha
, port_id_t id
)
7022 unsigned long flags
;
7023 struct qla_hw_data
*ha
= vha
->hw
;
7025 if (!vha
->d_id
.b24
) {
7026 spin_lock_irqsave(&ha
->vport_slock
, flags
);
7028 qlt_update_vp_map(vha
, SET_AL_PA
);
7029 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
7030 } else if (vha
->d_id
.b24
!= id
.b24
) {
7031 spin_lock_irqsave(&ha
->vport_slock
, flags
);
7032 qlt_update_vp_map(vha
, RESET_AL_PA
);
7034 qlt_update_vp_map(vha
, SET_AL_PA
);
7035 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
7039 static int __init
qlt_parse_ini_mode(void)
7041 if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_EXCLUSIVE
) == 0)
7042 ql2x_ini_mode
= QLA2XXX_INI_MODE_EXCLUSIVE
;
7043 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_DISABLED
) == 0)
7044 ql2x_ini_mode
= QLA2XXX_INI_MODE_DISABLED
;
7045 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_ENABLED
) == 0)
7046 ql2x_ini_mode
= QLA2XXX_INI_MODE_ENABLED
;
7047 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_DUAL
) == 0)
7048 ql2x_ini_mode
= QLA2XXX_INI_MODE_DUAL
;
7055 int __init
qlt_init(void)
7059 if (!qlt_parse_ini_mode()) {
7060 ql_log(ql_log_fatal
, NULL
, 0xe06b,
7061 "qlt_parse_ini_mode() failed\n");
7065 if (!QLA_TGT_MODE_ENABLED())
7068 qla_tgt_mgmt_cmd_cachep
= kmem_cache_create("qla_tgt_mgmt_cmd_cachep",
7069 sizeof(struct qla_tgt_mgmt_cmd
), __alignof__(struct
7070 qla_tgt_mgmt_cmd
), 0, NULL
);
7071 if (!qla_tgt_mgmt_cmd_cachep
) {
7072 ql_log(ql_log_fatal
, NULL
, 0xd04b,
7073 "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
7077 qla_tgt_plogi_cachep
= kmem_cache_create("qla_tgt_plogi_cachep",
7078 sizeof(struct qlt_plogi_ack_t
), __alignof__(struct qlt_plogi_ack_t
),
7081 if (!qla_tgt_plogi_cachep
) {
7082 ql_log(ql_log_fatal
, NULL
, 0xe06d,
7083 "kmem_cache_create for qla_tgt_plogi_cachep failed\n");
7085 goto out_mgmt_cmd_cachep
;
7088 qla_tgt_mgmt_cmd_mempool
= mempool_create(25, mempool_alloc_slab
,
7089 mempool_free_slab
, qla_tgt_mgmt_cmd_cachep
);
7090 if (!qla_tgt_mgmt_cmd_mempool
) {
7091 ql_log(ql_log_fatal
, NULL
, 0xe06e,
7092 "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
7094 goto out_plogi_cachep
;
7097 qla_tgt_wq
= alloc_workqueue("qla_tgt_wq", 0, 0);
7099 ql_log(ql_log_fatal
, NULL
, 0xe06f,
7100 "alloc_workqueue for qla_tgt_wq failed\n");
7102 goto out_cmd_mempool
;
7105 * Return 1 to signal that initiator-mode is being disabled
7107 return (ql2x_ini_mode
== QLA2XXX_INI_MODE_DISABLED
) ? 1 : 0;
7110 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
7112 kmem_cache_destroy(qla_tgt_plogi_cachep
);
7113 out_mgmt_cmd_cachep
:
7114 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);
7120 if (!QLA_TGT_MODE_ENABLED())
7123 destroy_workqueue(qla_tgt_wq
);
7124 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
7125 kmem_cache_destroy(qla_tgt_plogi_cachep
);
7126 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);