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-2011 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 char *qlini_mode
= QLA2XXX_INI_MODE_STR_ENABLED
;
46 module_param(qlini_mode
, charp
, S_IRUGO
);
47 MODULE_PARM_DESC(qlini_mode
,
48 "Determines when initiator mode will be enabled. Possible values: "
49 "\"exclusive\" - initiator mode will be enabled on load, "
50 "disabled on enabling target mode and then on disabling target mode "
52 "\"disabled\" - initiator mode will never be enabled; "
53 "\"enabled\" (default) - initiator mode will always stay enabled.");
55 static int ql2x_ini_mode
= QLA2XXX_INI_MODE_EXCLUSIVE
;
58 * From scsi/fc/fc_fcp.h
60 enum fcp_resp_rsp_codes
{
62 FCP_DATA_LEN_INVALID
= 1,
63 FCP_CMND_FIELDS_INVALID
= 2,
64 FCP_DATA_PARAM_MISMATCH
= 3,
67 FCP_TMF_INVALID_LUN
= 9,
71 * fc_pri_ta from scsi/fc/fc_fcp.h
73 #define FCP_PTA_SIMPLE 0 /* simple task attribute */
74 #define FCP_PTA_HEADQ 1 /* head of queue task attribute */
75 #define FCP_PTA_ORDERED 2 /* ordered task attribute */
76 #define FCP_PTA_ACA 4 /* auto. contigent allegiance */
77 #define FCP_PTA_MASK 7 /* mask for task attribute field */
78 #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */
79 #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */
82 * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which
83 * must be called under HW lock and could unlock/lock it inside.
84 * It isn't an issue, since in the current implementation on the time when
85 * those functions are called:
87 * - Either context is IRQ and only IRQ handler can modify HW data,
88 * including rings related fields,
90 * - Or access to target mode variables from struct qla_tgt doesn't
91 * cross those functions boundaries, except tgt_stop, which
92 * additionally protected by irq_cmd_count.
94 /* Predefs for callbacks handed to qla2xxx LLD */
95 static void qlt_24xx_atio_pkt(struct scsi_qla_host
*ha
,
96 struct atio_from_isp
*pkt
);
97 static void qlt_response_pkt(struct scsi_qla_host
*ha
, response_t
*pkt
);
98 static int qlt_issue_task_mgmt(struct qla_tgt_sess
*sess
, uint32_t lun
,
99 int fn
, void *iocb
, int flags
);
100 static void qlt_send_term_exchange(struct scsi_qla_host
*ha
, struct qla_tgt_cmd
101 *cmd
, struct atio_from_isp
*atio
, int ha_locked
);
102 static void qlt_reject_free_srr_imm(struct scsi_qla_host
*ha
,
103 struct qla_tgt_srr_imm
*imm
, int ha_lock
);
107 static struct kmem_cache
*qla_tgt_cmd_cachep
;
108 static struct kmem_cache
*qla_tgt_mgmt_cmd_cachep
;
109 static mempool_t
*qla_tgt_mgmt_cmd_mempool
;
110 static struct workqueue_struct
*qla_tgt_wq
;
111 static DEFINE_MUTEX(qla_tgt_mutex
);
112 static LIST_HEAD(qla_tgt_glist
);
114 /* ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) */
115 static struct qla_tgt_sess
*qlt_find_sess_by_port_name(
117 const uint8_t *port_name
)
119 struct qla_tgt_sess
*sess
;
121 list_for_each_entry(sess
, &tgt
->sess_list
, sess_list_entry
) {
122 if (!memcmp(sess
->port_name
, port_name
, WWN_SIZE
))
129 /* Might release hw lock, then reaquire!! */
130 static inline int qlt_issue_marker(struct scsi_qla_host
*vha
, int vha_locked
)
132 /* Send marker if required */
133 if (unlikely(vha
->marker_needed
!= 0)) {
134 int rc
= qla2x00_issue_marker(vha
, vha_locked
);
135 if (rc
!= QLA_SUCCESS
) {
136 ql_dbg(ql_dbg_tgt
, vha
, 0xe03d,
137 "qla_target(%d): issue_marker() failed\n",
146 struct scsi_qla_host
*qlt_find_host_by_d_id(struct scsi_qla_host
*vha
,
149 struct qla_hw_data
*ha
= vha
->hw
;
152 if ((vha
->d_id
.b
.area
!= d_id
[1]) || (vha
->d_id
.b
.domain
!= d_id
[0]))
155 if (vha
->d_id
.b
.al_pa
== d_id
[2])
158 BUG_ON(ha
->tgt
.tgt_vp_map
== NULL
);
159 vp_idx
= ha
->tgt
.tgt_vp_map
[d_id
[2]].idx
;
160 if (likely(test_bit(vp_idx
, ha
->vp_idx_map
)))
161 return ha
->tgt
.tgt_vp_map
[vp_idx
].vha
;
167 struct scsi_qla_host
*qlt_find_host_by_vp_idx(struct scsi_qla_host
*vha
,
170 struct qla_hw_data
*ha
= vha
->hw
;
172 if (vha
->vp_idx
== vp_idx
)
175 BUG_ON(ha
->tgt
.tgt_vp_map
== NULL
);
176 if (likely(test_bit(vp_idx
, ha
->vp_idx_map
)))
177 return ha
->tgt
.tgt_vp_map
[vp_idx
].vha
;
182 void qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host
*vha
,
183 struct atio_from_isp
*atio
)
185 switch (atio
->u
.raw
.entry_type
) {
188 struct scsi_qla_host
*host
= qlt_find_host_by_d_id(vha
,
189 atio
->u
.isp24
.fcp_hdr
.d_id
);
190 if (unlikely(NULL
== host
)) {
191 ql_dbg(ql_dbg_tgt
, vha
, 0xe03e,
192 "qla_target(%d): Received ATIO_TYPE7 "
193 "with unknown d_id %x:%x:%x\n", vha
->vp_idx
,
194 atio
->u
.isp24
.fcp_hdr
.d_id
[0],
195 atio
->u
.isp24
.fcp_hdr
.d_id
[1],
196 atio
->u
.isp24
.fcp_hdr
.d_id
[2]);
199 qlt_24xx_atio_pkt(host
, atio
);
203 case IMMED_NOTIFY_TYPE
:
205 struct scsi_qla_host
*host
= vha
;
206 struct imm_ntfy_from_isp
*entry
=
207 (struct imm_ntfy_from_isp
*)atio
;
209 if ((entry
->u
.isp24
.vp_index
!= 0xFF) &&
210 (entry
->u
.isp24
.nport_handle
!= 0xFFFF)) {
211 host
= qlt_find_host_by_vp_idx(vha
,
212 entry
->u
.isp24
.vp_index
);
213 if (unlikely(!host
)) {
214 ql_dbg(ql_dbg_tgt
, vha
, 0xe03f,
215 "qla_target(%d): Received "
216 "ATIO (IMMED_NOTIFY_TYPE) "
217 "with unknown vp_index %d\n",
218 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
222 qlt_24xx_atio_pkt(host
, atio
);
227 ql_dbg(ql_dbg_tgt
, vha
, 0xe040,
228 "qla_target(%d): Received unknown ATIO atio "
229 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
236 void qlt_response_pkt_all_vps(struct scsi_qla_host
*vha
, response_t
*pkt
)
238 switch (pkt
->entry_type
) {
241 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
242 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
244 if (unlikely(!host
)) {
245 ql_dbg(ql_dbg_tgt
, vha
, 0xe041,
246 "qla_target(%d): Response pkt (CTIO_TYPE7) "
247 "received, with unknown vp_index %d\n",
248 vha
->vp_idx
, entry
->vp_index
);
251 qlt_response_pkt(host
, pkt
);
255 case IMMED_NOTIFY_TYPE
:
257 struct scsi_qla_host
*host
= vha
;
258 struct imm_ntfy_from_isp
*entry
=
259 (struct imm_ntfy_from_isp
*)pkt
;
261 host
= qlt_find_host_by_vp_idx(vha
, entry
->u
.isp24
.vp_index
);
262 if (unlikely(!host
)) {
263 ql_dbg(ql_dbg_tgt
, vha
, 0xe042,
264 "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
265 "received, with unknown vp_index %d\n",
266 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
269 qlt_response_pkt(host
, pkt
);
273 case NOTIFY_ACK_TYPE
:
275 struct scsi_qla_host
*host
= vha
;
276 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
278 if (0xFF != entry
->u
.isp24
.vp_index
) {
279 host
= qlt_find_host_by_vp_idx(vha
,
280 entry
->u
.isp24
.vp_index
);
281 if (unlikely(!host
)) {
282 ql_dbg(ql_dbg_tgt
, vha
, 0xe043,
283 "qla_target(%d): Response "
284 "pkt (NOTIFY_ACK_TYPE) "
285 "received, with unknown "
286 "vp_index %d\n", vha
->vp_idx
,
287 entry
->u
.isp24
.vp_index
);
291 qlt_response_pkt(host
, pkt
);
297 struct abts_recv_from_24xx
*entry
=
298 (struct abts_recv_from_24xx
*)pkt
;
299 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
301 if (unlikely(!host
)) {
302 ql_dbg(ql_dbg_tgt
, vha
, 0xe044,
303 "qla_target(%d): Response pkt "
304 "(ABTS_RECV_24XX) received, with unknown "
305 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
308 qlt_response_pkt(host
, pkt
);
314 struct abts_resp_to_24xx
*entry
=
315 (struct abts_resp_to_24xx
*)pkt
;
316 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
318 if (unlikely(!host
)) {
319 ql_dbg(ql_dbg_tgt
, vha
, 0xe045,
320 "qla_target(%d): Response pkt "
321 "(ABTS_RECV_24XX) received, with unknown "
322 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
325 qlt_response_pkt(host
, pkt
);
330 qlt_response_pkt(vha
, pkt
);
336 static void qlt_free_session_done(struct work_struct
*work
)
338 struct qla_tgt_sess
*sess
= container_of(work
, struct qla_tgt_sess
,
340 struct qla_tgt
*tgt
= sess
->tgt
;
341 struct scsi_qla_host
*vha
= sess
->vha
;
342 struct qla_hw_data
*ha
= vha
->hw
;
346 * Release the target session for FC Nexus from fabric module code.
348 if (sess
->se_sess
!= NULL
)
349 ha
->tgt
.tgt_ops
->free_session(sess
);
351 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf001,
352 "Unregistration of sess %p finished\n", sess
);
356 * We need to protect against race, when tgt is freed before or
360 if (tgt
->sess_count
== 0)
361 wake_up_all(&tgt
->waitQ
);
364 /* ha->hardware_lock supposed to be held on entry */
365 void qlt_unreg_sess(struct qla_tgt_sess
*sess
)
367 struct scsi_qla_host
*vha
= sess
->vha
;
369 vha
->hw
->tgt
.tgt_ops
->clear_nacl_from_fcport_map(sess
);
371 list_del(&sess
->sess_list_entry
);
373 list_del(&sess
->del_list_entry
);
375 INIT_WORK(&sess
->free_work
, qlt_free_session_done
);
376 schedule_work(&sess
->free_work
);
378 EXPORT_SYMBOL(qlt_unreg_sess
);
380 /* ha->hardware_lock supposed to be held on entry */
381 static int qlt_reset(struct scsi_qla_host
*vha
, void *iocb
, int mcmd
)
383 struct qla_hw_data
*ha
= vha
->hw
;
384 struct qla_tgt_sess
*sess
= NULL
;
385 uint32_t unpacked_lun
, lun
= 0;
388 struct imm_ntfy_from_isp
*n
= (struct imm_ntfy_from_isp
*)iocb
;
389 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
391 loop_id
= le16_to_cpu(n
->u
.isp24
.nport_handle
);
392 if (loop_id
== 0xFFFF) {
393 #if 0 /* FIXME: Re-enable Global event handling.. */
395 atomic_inc(&ha
->tgt
.qla_tgt
->tgt_global_resets_count
);
396 qlt_clear_tgt_db(ha
->tgt
.qla_tgt
, 1);
397 if (!list_empty(&ha
->tgt
.qla_tgt
->sess_list
)) {
398 sess
= list_entry(ha
->tgt
.qla_tgt
->sess_list
.next
,
399 typeof(*sess
), sess_list_entry
);
401 case QLA_TGT_NEXUS_LOSS_SESS
:
402 mcmd
= QLA_TGT_NEXUS_LOSS
;
404 case QLA_TGT_ABORT_ALL_SESS
:
405 mcmd
= QLA_TGT_ABORT_ALL
;
407 case QLA_TGT_NEXUS_LOSS
:
408 case QLA_TGT_ABORT_ALL
:
411 ql_dbg(ql_dbg_tgt
, vha
, 0xe046,
412 "qla_target(%d): Not allowed "
413 "command %x in %s", vha
->vp_idx
,
422 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
425 ql_dbg(ql_dbg_tgt
, vha
, 0xe000,
426 "Using sess for qla_tgt_reset: %p\n", sess
);
432 ql_dbg(ql_dbg_tgt
, vha
, 0xe047,
433 "scsi(%ld): resetting (session %p from port "
434 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, "
435 "mcmd %x, loop_id %d)\n", vha
->host_no
, sess
,
436 sess
->port_name
[0], sess
->port_name
[1],
437 sess
->port_name
[2], sess
->port_name
[3],
438 sess
->port_name
[4], sess
->port_name
[5],
439 sess
->port_name
[6], sess
->port_name
[7],
442 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
443 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
445 return qlt_issue_task_mgmt(sess
, unpacked_lun
, mcmd
,
446 iocb
, QLA24XX_MGMT_SEND_NACK
);
449 /* ha->hardware_lock supposed to be held on entry */
450 static void qlt_schedule_sess_for_deletion(struct qla_tgt_sess
*sess
,
453 struct qla_tgt
*tgt
= sess
->tgt
;
454 uint32_t dev_loss_tmo
= tgt
->ha
->port_down_retry_count
+ 5;
459 ql_dbg(ql_dbg_tgt
, sess
->vha
, 0xe001,
460 "Scheduling sess %p for deletion\n", sess
);
461 list_add_tail(&sess
->del_list_entry
, &tgt
->del_sess_list
);
467 sess
->expires
= jiffies
+ dev_loss_tmo
* HZ
;
469 ql_dbg(ql_dbg_tgt
, sess
->vha
, 0xe048,
470 "qla_target(%d): session for port %02x:%02x:%02x:"
471 "%02x:%02x:%02x:%02x:%02x (loop ID %d) scheduled for "
472 "deletion in %u secs (expires: %lu) immed: %d\n",
474 sess
->port_name
[0], sess
->port_name
[1],
475 sess
->port_name
[2], sess
->port_name
[3],
476 sess
->port_name
[4], sess
->port_name
[5],
477 sess
->port_name
[6], sess
->port_name
[7],
478 sess
->loop_id
, dev_loss_tmo
, sess
->expires
, immediate
);
481 schedule_delayed_work(&tgt
->sess_del_work
, 0);
483 schedule_delayed_work(&tgt
->sess_del_work
,
484 jiffies
- sess
->expires
);
487 /* ha->hardware_lock supposed to be held on entry */
488 static void qlt_clear_tgt_db(struct qla_tgt
*tgt
, bool local_only
)
490 struct qla_tgt_sess
*sess
;
492 list_for_each_entry(sess
, &tgt
->sess_list
, sess_list_entry
)
493 qlt_schedule_sess_for_deletion(sess
, true);
495 /* At this point tgt could be already dead */
498 static int qla24xx_get_loop_id(struct scsi_qla_host
*vha
, const uint8_t *s_id
,
501 struct qla_hw_data
*ha
= vha
->hw
;
502 dma_addr_t gid_list_dma
;
503 struct gid_list_info
*gid_list
;
508 gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
509 &gid_list_dma
, GFP_KERNEL
);
511 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf044,
512 "qla_target(%d): DMA Alloc failed of %u\n",
513 vha
->vp_idx
, qla2x00_gid_list_size(ha
));
517 /* Get list of logged in devices */
518 rc
= qla2x00_get_id_list(vha
, gid_list
, gid_list_dma
, &entries
);
519 if (rc
!= QLA_SUCCESS
) {
520 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf045,
521 "qla_target(%d): get_id_list() failed: %x\n",
524 goto out_free_id_list
;
527 id_iter
= (char *)gid_list
;
529 for (i
= 0; i
< entries
; i
++) {
530 struct gid_list_info
*gid
= (struct gid_list_info
*)id_iter
;
531 if ((gid
->al_pa
== s_id
[2]) &&
532 (gid
->area
== s_id
[1]) &&
533 (gid
->domain
== s_id
[0])) {
534 *loop_id
= le16_to_cpu(gid
->loop_id
);
538 id_iter
+= ha
->gid_list_info_size
;
542 dma_free_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
543 gid_list
, gid_list_dma
);
547 static bool qlt_check_fcport_exist(struct scsi_qla_host
*vha
,
548 struct qla_tgt_sess
*sess
)
550 struct qla_hw_data
*ha
= vha
->hw
;
551 struct qla_port_24xx_data
*pmap24
;
552 bool res
, found
= false;
554 uint16_t loop_id
= 0xFFFF; /* to eliminate compiler's warning */
562 global_resets
= atomic_read(&ha
->tgt
.qla_tgt
->tgt_global_resets_count
);
564 rc
= qla2x00_get_node_name_list(vha
, &pmap
, &pmap_len
);
565 if (rc
!= QLA_SUCCESS
) {
571 entries
= pmap_len
/sizeof(*pmap24
);
573 for (i
= 0; i
< entries
; ++i
) {
574 if (!memcmp(sess
->port_name
, pmap24
[i
].port_name
, WWN_SIZE
)) {
575 loop_id
= le16_to_cpu(pmap24
[i
].loop_id
);
588 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf046,
589 "qlt_check_fcport_exist(): loop_id %d", loop_id
);
591 fcport
= kzalloc(sizeof(*fcport
), GFP_KERNEL
);
592 if (fcport
== NULL
) {
593 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf047,
594 "qla_target(%d): Allocation of tmp FC port failed",
600 fcport
->loop_id
= loop_id
;
602 rc
= qla2x00_get_port_database(vha
, fcport
, 0);
603 if (rc
!= QLA_SUCCESS
) {
604 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf048,
605 "qla_target(%d): Failed to retrieve fcport "
606 "information -- get_port_database() returned %x "
607 "(loop_id=0x%04x)", vha
->vp_idx
, rc
, loop_id
);
609 goto out_free_fcport
;
613 atomic_read(&ha
->tgt
.qla_tgt
->tgt_global_resets_count
)) {
614 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf002,
615 "qla_target(%d): global reset during session discovery"
616 " (counter was %d, new %d), retrying",
617 vha
->vp_idx
, global_resets
,
618 atomic_read(&ha
->tgt
.qla_tgt
->tgt_global_resets_count
));
622 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf003,
623 "Updating sess %p s_id %x:%x:%x, loop_id %d) to d_id %x:%x:%x, "
624 "loop_id %d", sess
, sess
->s_id
.b
.domain
, sess
->s_id
.b
.al_pa
,
625 sess
->s_id
.b
.area
, sess
->loop_id
, fcport
->d_id
.b
.domain
,
626 fcport
->d_id
.b
.al_pa
, fcport
->d_id
.b
.area
, fcport
->loop_id
);
628 sess
->s_id
= fcport
->d_id
;
629 sess
->loop_id
= fcport
->loop_id
;
630 sess
->conf_compl_supported
= !!(fcport
->flags
&
631 FCF_CONF_COMP_SUPPORTED
);
642 /* ha->hardware_lock supposed to be held on entry */
643 static void qlt_undelete_sess(struct qla_tgt_sess
*sess
)
645 BUG_ON(!sess
->deleted
);
647 list_del(&sess
->del_list_entry
);
651 static void qlt_del_sess_work_fn(struct delayed_work
*work
)
653 struct qla_tgt
*tgt
= container_of(work
, struct qla_tgt
,
655 struct scsi_qla_host
*vha
= tgt
->vha
;
656 struct qla_hw_data
*ha
= vha
->hw
;
657 struct qla_tgt_sess
*sess
;
660 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
661 while (!list_empty(&tgt
->del_sess_list
)) {
662 sess
= list_entry(tgt
->del_sess_list
.next
, typeof(*sess
),
664 if (time_after_eq(jiffies
, sess
->expires
)) {
667 qlt_undelete_sess(sess
);
669 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
670 cancel
= qlt_check_fcport_exist(vha
, sess
);
675 * sess was again deleted while we were
678 spin_lock_irqsave(&ha
->hardware_lock
,
683 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf049,
684 "qla_target(%d): cancel deletion of "
685 "session for port %02x:%02x:%02x:%02x:%02x:"
686 "%02x:%02x:%02x (loop ID %d), because "
687 " it isn't deleted by firmware",
688 vha
->vp_idx
, sess
->port_name
[0],
689 sess
->port_name
[1], sess
->port_name
[2],
690 sess
->port_name
[3], sess
->port_name
[4],
691 sess
->port_name
[5], sess
->port_name
[6],
692 sess
->port_name
[7], sess
->loop_id
);
694 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf004,
695 "Timeout: sess %p about to be deleted\n",
697 ha
->tgt
.tgt_ops
->shutdown_sess(sess
);
698 ha
->tgt
.tgt_ops
->put_sess(sess
);
701 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
703 schedule_delayed_work(&tgt
->sess_del_work
,
704 jiffies
- sess
->expires
);
708 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
712 * Adds an extra ref to allow to drop hw lock after adding sess to the list.
713 * Caller must put it.
715 static struct qla_tgt_sess
*qlt_create_sess(
716 struct scsi_qla_host
*vha
,
720 struct qla_hw_data
*ha
= vha
->hw
;
721 struct qla_tgt_sess
*sess
;
723 unsigned char be_sid
[3];
725 /* Check to avoid double sessions */
726 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
727 list_for_each_entry(sess
, &ha
->tgt
.qla_tgt
->sess_list
,
729 if (!memcmp(sess
->port_name
, fcport
->port_name
, WWN_SIZE
)) {
730 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf005,
731 "Double sess %p found (s_id %x:%x:%x, "
732 "loop_id %d), updating to d_id %x:%x:%x, "
733 "loop_id %d", sess
, sess
->s_id
.b
.domain
,
734 sess
->s_id
.b
.al_pa
, sess
->s_id
.b
.area
,
735 sess
->loop_id
, fcport
->d_id
.b
.domain
,
736 fcport
->d_id
.b
.al_pa
, fcport
->d_id
.b
.area
,
740 qlt_undelete_sess(sess
);
742 kref_get(&sess
->se_sess
->sess_kref
);
743 sess
->s_id
= fcport
->d_id
;
744 sess
->loop_id
= fcport
->loop_id
;
745 sess
->conf_compl_supported
= !!(fcport
->flags
&
746 FCF_CONF_COMP_SUPPORTED
);
747 if (sess
->local
&& !local
)
749 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
754 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
756 sess
= kzalloc(sizeof(*sess
), GFP_KERNEL
);
758 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04a,
759 "qla_target(%u): session allocation failed, "
760 "all commands from port %02x:%02x:%02x:%02x:"
761 "%02x:%02x:%02x:%02x will be refused", vha
->vp_idx
,
762 fcport
->port_name
[0], fcport
->port_name
[1],
763 fcport
->port_name
[2], fcport
->port_name
[3],
764 fcport
->port_name
[4], fcport
->port_name
[5],
765 fcport
->port_name
[6], fcport
->port_name
[7]);
769 sess
->tgt
= ha
->tgt
.qla_tgt
;
771 sess
->s_id
= fcport
->d_id
;
772 sess
->loop_id
= fcport
->loop_id
;
775 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf006,
776 "Adding sess %p to tgt %p via ->check_initiator_node_acl()\n",
777 sess
, ha
->tgt
.qla_tgt
);
779 be_sid
[0] = sess
->s_id
.b
.domain
;
780 be_sid
[1] = sess
->s_id
.b
.area
;
781 be_sid
[2] = sess
->s_id
.b
.al_pa
;
783 * Determine if this fc_port->port_name is allowed to access
784 * target mode using explict NodeACLs+MappedLUNs, or using
785 * TPG demo mode. If this is successful a target mode FC nexus
788 if (ha
->tgt
.tgt_ops
->check_initiator_node_acl(vha
,
789 &fcport
->port_name
[0], sess
, &be_sid
[0], fcport
->loop_id
) < 0) {
794 * Take an extra reference to ->sess_kref here to handle qla_tgt_sess
795 * access across ->hardware_lock reaquire.
797 kref_get(&sess
->se_sess
->sess_kref
);
799 sess
->conf_compl_supported
= !!(fcport
->flags
&
800 FCF_CONF_COMP_SUPPORTED
);
801 BUILD_BUG_ON(sizeof(sess
->port_name
) != sizeof(fcport
->port_name
));
802 memcpy(sess
->port_name
, fcport
->port_name
, sizeof(sess
->port_name
));
804 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
805 list_add_tail(&sess
->sess_list_entry
, &ha
->tgt
.qla_tgt
->sess_list
);
806 ha
->tgt
.qla_tgt
->sess_count
++;
807 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
809 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04b,
810 "qla_target(%d): %ssession for wwn %02x:%02x:%02x:%02x:"
811 "%02x:%02x:%02x:%02x (loop_id %d, s_id %x:%x:%x, confirmed"
812 " completion %ssupported) added\n",
813 vha
->vp_idx
, local
? "local " : "", fcport
->port_name
[0],
814 fcport
->port_name
[1], fcport
->port_name
[2], fcport
->port_name
[3],
815 fcport
->port_name
[4], fcport
->port_name
[5], fcport
->port_name
[6],
816 fcport
->port_name
[7], fcport
->loop_id
, sess
->s_id
.b
.domain
,
817 sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
, sess
->conf_compl_supported
?
824 * Called from drivers/scsi/qla2xxx/qla_init.c:qla2x00_reg_remote_port()
826 void qlt_fc_port_added(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
828 struct qla_hw_data
*ha
= vha
->hw
;
829 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
830 struct qla_tgt_sess
*sess
;
833 if (!vha
->hw
->tgt
.tgt_ops
)
836 if (!tgt
|| (fcport
->port_type
!= FCT_INITIATOR
))
839 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
841 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
844 sess
= qlt_find_sess_by_port_name(tgt
, fcport
->port_name
);
846 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
848 mutex_lock(&ha
->tgt
.tgt_mutex
);
849 sess
= qlt_create_sess(vha
, fcport
, false);
850 mutex_unlock(&ha
->tgt
.tgt_mutex
);
852 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
854 kref_get(&sess
->se_sess
->sess_kref
);
857 qlt_undelete_sess(sess
);
859 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04c,
860 "qla_target(%u): %ssession for port %02x:"
861 "%02x:%02x:%02x:%02x:%02x:%02x:%02x (loop ID %d) "
862 "reappeared\n", vha
->vp_idx
, sess
->local
? "local "
863 : "", sess
->port_name
[0], sess
->port_name
[1],
864 sess
->port_name
[2], sess
->port_name
[3],
865 sess
->port_name
[4], sess
->port_name
[5],
866 sess
->port_name
[6], sess
->port_name
[7],
869 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf007,
870 "Reappeared sess %p\n", sess
);
872 sess
->s_id
= fcport
->d_id
;
873 sess
->loop_id
= fcport
->loop_id
;
874 sess
->conf_compl_supported
= !!(fcport
->flags
&
875 FCF_CONF_COMP_SUPPORTED
);
878 if (sess
&& sess
->local
) {
879 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04d,
880 "qla_target(%u): local session for "
881 "port %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
882 "(loop ID %d) became global\n", vha
->vp_idx
,
883 fcport
->port_name
[0], fcport
->port_name
[1],
884 fcport
->port_name
[2], fcport
->port_name
[3],
885 fcport
->port_name
[4], fcport
->port_name
[5],
886 fcport
->port_name
[6], fcport
->port_name
[7],
890 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
892 ha
->tgt
.tgt_ops
->put_sess(sess
);
895 void qlt_fc_port_deleted(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
897 struct qla_hw_data
*ha
= vha
->hw
;
898 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
899 struct qla_tgt_sess
*sess
;
902 if (!vha
->hw
->tgt
.tgt_ops
)
905 if (!tgt
|| (fcport
->port_type
!= FCT_INITIATOR
))
908 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
910 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
913 sess
= qlt_find_sess_by_port_name(tgt
, fcport
->port_name
);
915 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
919 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf008, "qla_tgt_fc_port_deleted %p", sess
);
922 qlt_schedule_sess_for_deletion(sess
, false);
923 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
926 static inline int test_tgt_sess_count(struct qla_tgt
*tgt
)
928 struct qla_hw_data
*ha
= tgt
->ha
;
932 * We need to protect against race, when tgt is freed before or
935 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
936 ql_dbg(ql_dbg_tgt
, tgt
->vha
, 0xe002,
937 "tgt %p, empty(sess_list)=%d sess_count=%d\n",
938 tgt
, list_empty(&tgt
->sess_list
), tgt
->sess_count
);
939 res
= (tgt
->sess_count
== 0);
940 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
945 /* Called by tcm_qla2xxx configfs code */
946 void qlt_stop_phase1(struct qla_tgt
*tgt
)
948 struct scsi_qla_host
*vha
= tgt
->vha
;
949 struct qla_hw_data
*ha
= tgt
->ha
;
952 if (tgt
->tgt_stop
|| tgt
->tgt_stopped
) {
953 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04e,
954 "Already in tgt->tgt_stop or tgt_stopped state\n");
959 ql_dbg(ql_dbg_tgt
, vha
, 0xe003, "Stopping target for host %ld(%p)\n",
962 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
963 * Lock is needed, because we still can get an incoming packet.
965 mutex_lock(&ha
->tgt
.tgt_mutex
);
966 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
968 qlt_clear_tgt_db(tgt
, true);
969 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
970 mutex_unlock(&ha
->tgt
.tgt_mutex
);
972 flush_delayed_work_sync(&tgt
->sess_del_work
);
974 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf009,
975 "Waiting for sess works (tgt %p)", tgt
);
976 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
977 while (!list_empty(&tgt
->sess_works_list
)) {
978 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
979 flush_scheduled_work();
980 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
982 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
984 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00a,
985 "Waiting for tgt %p: list_empty(sess_list)=%d "
986 "sess_count=%d\n", tgt
, list_empty(&tgt
->sess_list
),
989 wait_event(tgt
->waitQ
, test_tgt_sess_count(tgt
));
992 if (!ha
->flags
.host_shutting_down
&& qla_tgt_mode_enabled(vha
))
993 qlt_disable_vha(vha
);
995 /* Wait for sessions to clear out (just in case) */
996 wait_event(tgt
->waitQ
, test_tgt_sess_count(tgt
));
998 EXPORT_SYMBOL(qlt_stop_phase1
);
1000 /* Called by tcm_qla2xxx configfs code */
1001 void qlt_stop_phase2(struct qla_tgt
*tgt
)
1003 struct qla_hw_data
*ha
= tgt
->ha
;
1004 unsigned long flags
;
1006 if (tgt
->tgt_stopped
) {
1007 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf04f,
1008 "Already in tgt->tgt_stopped state\n");
1013 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf00b,
1014 "Waiting for %d IRQ commands to complete (tgt %p)",
1015 tgt
->irq_cmd_count
, tgt
);
1017 mutex_lock(&ha
->tgt
.tgt_mutex
);
1018 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1019 while (tgt
->irq_cmd_count
!= 0) {
1020 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1022 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1025 tgt
->tgt_stopped
= 1;
1026 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1027 mutex_unlock(&ha
->tgt
.tgt_mutex
);
1029 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf00c, "Stop of tgt %p finished",
1032 EXPORT_SYMBOL(qlt_stop_phase2
);
1034 /* Called from qlt_remove_target() -> qla2x00_remove_one() */
1035 void qlt_release(struct qla_tgt
*tgt
)
1037 struct qla_hw_data
*ha
= tgt
->ha
;
1039 if ((ha
->tgt
.qla_tgt
!= NULL
) && !tgt
->tgt_stopped
)
1040 qlt_stop_phase2(tgt
);
1042 ha
->tgt
.qla_tgt
= NULL
;
1044 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf00d,
1045 "Release of tgt %p finished\n", tgt
);
1050 /* ha->hardware_lock supposed to be held on entry */
1051 static int qlt_sched_sess_work(struct qla_tgt
*tgt
, int type
,
1052 const void *param
, unsigned int param_size
)
1054 struct qla_tgt_sess_work_param
*prm
;
1055 unsigned long flags
;
1057 prm
= kzalloc(sizeof(*prm
), GFP_ATOMIC
);
1059 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf050,
1060 "qla_target(%d): Unable to create session "
1061 "work, command will be refused", 0);
1065 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf00e,
1066 "Scheduling work (type %d, prm %p)"
1067 " to find session for param %p (size %d, tgt %p)\n",
1068 type
, prm
, param
, param_size
, tgt
);
1071 memcpy(&prm
->tm_iocb
, param
, param_size
);
1073 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1074 list_add_tail(&prm
->sess_works_list_entry
, &tgt
->sess_works_list
);
1075 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1077 schedule_work(&tgt
->sess_work
);
1083 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1085 static void qlt_send_notify_ack(struct scsi_qla_host
*vha
,
1086 struct imm_ntfy_from_isp
*ntfy
,
1087 uint32_t add_flags
, uint16_t resp_code
, int resp_code_valid
,
1088 uint16_t srr_flags
, uint16_t srr_reject_code
, uint8_t srr_explan
)
1090 struct qla_hw_data
*ha
= vha
->hw
;
1092 struct nack_to_isp
*nack
;
1094 ql_dbg(ql_dbg_tgt
, vha
, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha
);
1096 /* Send marker if required */
1097 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
1100 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
1102 ql_dbg(ql_dbg_tgt
, vha
, 0xe049,
1103 "qla_target(%d): %s failed: unable to allocate "
1104 "request packet\n", vha
->vp_idx
, __func__
);
1108 if (ha
->tgt
.qla_tgt
!= NULL
)
1109 ha
->tgt
.qla_tgt
->notify_ack_expected
++;
1111 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
1112 pkt
->entry_count
= 1;
1114 nack
= (struct nack_to_isp
*)pkt
;
1115 nack
->ox_id
= ntfy
->ox_id
;
1117 nack
->u
.isp24
.nport_handle
= ntfy
->u
.isp24
.nport_handle
;
1118 if (le16_to_cpu(ntfy
->u
.isp24
.status
) == IMM_NTFY_ELS
) {
1119 nack
->u
.isp24
.flags
= ntfy
->u
.isp24
.flags
&
1120 __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB
);
1122 nack
->u
.isp24
.srr_rx_id
= ntfy
->u
.isp24
.srr_rx_id
;
1123 nack
->u
.isp24
.status
= ntfy
->u
.isp24
.status
;
1124 nack
->u
.isp24
.status_subcode
= ntfy
->u
.isp24
.status_subcode
;
1125 nack
->u
.isp24
.exchange_address
= ntfy
->u
.isp24
.exchange_address
;
1126 nack
->u
.isp24
.srr_rel_offs
= ntfy
->u
.isp24
.srr_rel_offs
;
1127 nack
->u
.isp24
.srr_ui
= ntfy
->u
.isp24
.srr_ui
;
1128 nack
->u
.isp24
.srr_flags
= cpu_to_le16(srr_flags
);
1129 nack
->u
.isp24
.srr_reject_code
= srr_reject_code
;
1130 nack
->u
.isp24
.srr_reject_code_expl
= srr_explan
;
1131 nack
->u
.isp24
.vp_index
= ntfy
->u
.isp24
.vp_index
;
1133 ql_dbg(ql_dbg_tgt
, vha
, 0xe005,
1134 "qla_target(%d): Sending 24xx Notify Ack %d\n",
1135 vha
->vp_idx
, nack
->u
.isp24
.status
);
1137 qla2x00_start_iocbs(vha
, vha
->req
);
1141 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1143 static void qlt_24xx_send_abts_resp(struct scsi_qla_host
*vha
,
1144 struct abts_recv_from_24xx
*abts
, uint32_t status
,
1147 struct qla_hw_data
*ha
= vha
->hw
;
1148 struct abts_resp_to_24xx
*resp
;
1152 ql_dbg(ql_dbg_tgt
, vha
, 0xe006,
1153 "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
1156 /* Send marker if required */
1157 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
1160 resp
= (struct abts_resp_to_24xx
*)qla2x00_alloc_iocbs(vha
, NULL
);
1162 ql_dbg(ql_dbg_tgt
, vha
, 0xe04a,
1163 "qla_target(%d): %s failed: unable to allocate "
1164 "request packet", vha
->vp_idx
, __func__
);
1168 resp
->entry_type
= ABTS_RESP_24XX
;
1169 resp
->entry_count
= 1;
1170 resp
->nport_handle
= abts
->nport_handle
;
1171 resp
->vp_index
= vha
->vp_idx
;
1172 resp
->sof_type
= abts
->sof_type
;
1173 resp
->exchange_address
= abts
->exchange_address
;
1174 resp
->fcp_hdr_le
= abts
->fcp_hdr_le
;
1175 f_ctl
= __constant_cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP
|
1176 F_CTL_LAST_SEQ
| F_CTL_END_SEQ
|
1177 F_CTL_SEQ_INITIATIVE
);
1178 p
= (uint8_t *)&f_ctl
;
1179 resp
->fcp_hdr_le
.f_ctl
[0] = *p
++;
1180 resp
->fcp_hdr_le
.f_ctl
[1] = *p
++;
1181 resp
->fcp_hdr_le
.f_ctl
[2] = *p
;
1183 resp
->fcp_hdr_le
.d_id
[0] = abts
->fcp_hdr_le
.d_id
[0];
1184 resp
->fcp_hdr_le
.d_id
[1] = abts
->fcp_hdr_le
.d_id
[1];
1185 resp
->fcp_hdr_le
.d_id
[2] = abts
->fcp_hdr_le
.d_id
[2];
1186 resp
->fcp_hdr_le
.s_id
[0] = abts
->fcp_hdr_le
.s_id
[0];
1187 resp
->fcp_hdr_le
.s_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1188 resp
->fcp_hdr_le
.s_id
[2] = abts
->fcp_hdr_le
.s_id
[2];
1190 resp
->fcp_hdr_le
.d_id
[0] = abts
->fcp_hdr_le
.s_id
[0];
1191 resp
->fcp_hdr_le
.d_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1192 resp
->fcp_hdr_le
.d_id
[2] = abts
->fcp_hdr_le
.s_id
[2];
1193 resp
->fcp_hdr_le
.s_id
[0] = abts
->fcp_hdr_le
.d_id
[0];
1194 resp
->fcp_hdr_le
.s_id
[1] = abts
->fcp_hdr_le
.d_id
[1];
1195 resp
->fcp_hdr_le
.s_id
[2] = abts
->fcp_hdr_le
.d_id
[2];
1197 resp
->exchange_addr_to_abort
= abts
->exchange_addr_to_abort
;
1198 if (status
== FCP_TMF_CMPL
) {
1199 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_ACC
;
1200 resp
->payload
.ba_acct
.seq_id_valid
= SEQ_ID_INVALID
;
1201 resp
->payload
.ba_acct
.low_seq_cnt
= 0x0000;
1202 resp
->payload
.ba_acct
.high_seq_cnt
= 0xFFFF;
1203 resp
->payload
.ba_acct
.ox_id
= abts
->fcp_hdr_le
.ox_id
;
1204 resp
->payload
.ba_acct
.rx_id
= abts
->fcp_hdr_le
.rx_id
;
1206 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_RJT
;
1207 resp
->payload
.ba_rjt
.reason_code
=
1208 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM
;
1209 /* Other bytes are zero */
1212 ha
->tgt
.qla_tgt
->abts_resp_expected
++;
1214 qla2x00_start_iocbs(vha
, vha
->req
);
1218 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1220 static void qlt_24xx_retry_term_exchange(struct scsi_qla_host
*vha
,
1221 struct abts_resp_from_24xx_fw
*entry
)
1223 struct ctio7_to_24xx
*ctio
;
1225 ql_dbg(ql_dbg_tgt
, vha
, 0xe007,
1226 "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha
->hw
);
1227 /* Send marker if required */
1228 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
1231 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs(vha
, NULL
);
1233 ql_dbg(ql_dbg_tgt
, vha
, 0xe04b,
1234 "qla_target(%d): %s failed: unable to allocate "
1235 "request packet\n", vha
->vp_idx
, __func__
);
1240 * We've got on entrance firmware's response on by us generated
1241 * ABTS response. So, in it ID fields are reversed.
1244 ctio
->entry_type
= CTIO_TYPE7
;
1245 ctio
->entry_count
= 1;
1246 ctio
->nport_handle
= entry
->nport_handle
;
1247 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
1248 ctio
->timeout
= __constant_cpu_to_le16(QLA_TGT_TIMEOUT
);
1249 ctio
->vp_index
= vha
->vp_idx
;
1250 ctio
->initiator_id
[0] = entry
->fcp_hdr_le
.d_id
[0];
1251 ctio
->initiator_id
[1] = entry
->fcp_hdr_le
.d_id
[1];
1252 ctio
->initiator_id
[2] = entry
->fcp_hdr_le
.d_id
[2];
1253 ctio
->exchange_addr
= entry
->exchange_addr_to_abort
;
1254 ctio
->u
.status1
.flags
=
1255 __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
|
1256 CTIO7_FLAGS_TERMINATE
);
1257 ctio
->u
.status1
.ox_id
= entry
->fcp_hdr_le
.ox_id
;
1259 qla2x00_start_iocbs(vha
, vha
->req
);
1261 qlt_24xx_send_abts_resp(vha
, (struct abts_recv_from_24xx
*)entry
,
1262 FCP_TMF_CMPL
, true);
1265 /* ha->hardware_lock supposed to be held on entry */
1266 static int __qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
1267 struct abts_recv_from_24xx
*abts
, struct qla_tgt_sess
*sess
)
1269 struct qla_hw_data
*ha
= vha
->hw
;
1270 struct qla_tgt_mgmt_cmd
*mcmd
;
1273 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00f,
1274 "qla_target(%d): task abort (tag=%d)\n",
1275 vha
->vp_idx
, abts
->exchange_addr_to_abort
);
1277 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
1279 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf051,
1280 "qla_target(%d): %s: Allocation of ABORT cmd failed",
1281 vha
->vp_idx
, __func__
);
1284 memset(mcmd
, 0, sizeof(*mcmd
));
1287 memcpy(&mcmd
->orig_iocb
.abts
, abts
, sizeof(mcmd
->orig_iocb
.abts
));
1289 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, 0, TMR_ABORT_TASK
,
1290 abts
->exchange_addr_to_abort
);
1292 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf052,
1293 "qla_target(%d): tgt_ops->handle_tmr()"
1294 " failed: %d", vha
->vp_idx
, rc
);
1295 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
1303 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1305 static void qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
1306 struct abts_recv_from_24xx
*abts
)
1308 struct qla_hw_data
*ha
= vha
->hw
;
1309 struct qla_tgt_sess
*sess
;
1310 uint32_t tag
= abts
->exchange_addr_to_abort
;
1314 if (le32_to_cpu(abts
->fcp_hdr_le
.parameter
) & ABTS_PARAM_ABORT_SEQ
) {
1315 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf053,
1316 "qla_target(%d): ABTS: Abort Sequence not "
1317 "supported\n", vha
->vp_idx
);
1318 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1322 if (tag
== ATIO_EXCHANGE_ADDRESS_UNKNOWN
) {
1323 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf010,
1324 "qla_target(%d): ABTS: Unknown Exchange "
1325 "Address received\n", vha
->vp_idx
);
1326 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1330 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf011,
1331 "qla_target(%d): task abort (s_id=%x:%x:%x, "
1332 "tag=%d, param=%x)\n", vha
->vp_idx
, abts
->fcp_hdr_le
.s_id
[2],
1333 abts
->fcp_hdr_le
.s_id
[1], abts
->fcp_hdr_le
.s_id
[0], tag
,
1334 le32_to_cpu(abts
->fcp_hdr_le
.parameter
));
1336 s_id
[0] = abts
->fcp_hdr_le
.s_id
[2];
1337 s_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1338 s_id
[2] = abts
->fcp_hdr_le
.s_id
[0];
1340 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
1342 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf012,
1343 "qla_target(%d): task abort for non-existant session\n",
1345 rc
= qlt_sched_sess_work(ha
->tgt
.qla_tgt
,
1346 QLA_TGT_SESS_WORK_ABORT
, abts
, sizeof(*abts
));
1348 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
,
1354 rc
= __qlt_24xx_handle_abts(vha
, abts
, sess
);
1356 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf054,
1357 "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
1359 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1365 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1367 static void qlt_24xx_send_task_mgmt_ctio(struct scsi_qla_host
*ha
,
1368 struct qla_tgt_mgmt_cmd
*mcmd
, uint32_t resp_code
)
1370 struct atio_from_isp
*atio
= &mcmd
->orig_iocb
.atio
;
1371 struct ctio7_to_24xx
*ctio
;
1373 ql_dbg(ql_dbg_tgt
, ha
, 0xe008,
1374 "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
1375 ha
, atio
, resp_code
);
1377 /* Send marker if required */
1378 if (qlt_issue_marker(ha
, 1) != QLA_SUCCESS
)
1381 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs(ha
, NULL
);
1383 ql_dbg(ql_dbg_tgt
, ha
, 0xe04c,
1384 "qla_target(%d): %s failed: unable to allocate "
1385 "request packet\n", ha
->vp_idx
, __func__
);
1389 ctio
->entry_type
= CTIO_TYPE7
;
1390 ctio
->entry_count
= 1;
1391 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
1392 ctio
->nport_handle
= mcmd
->sess
->loop_id
;
1393 ctio
->timeout
= __constant_cpu_to_le16(QLA_TGT_TIMEOUT
);
1394 ctio
->vp_index
= ha
->vp_idx
;
1395 ctio
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
1396 ctio
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
1397 ctio
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
1398 ctio
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
1399 ctio
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
1400 __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
|
1401 CTIO7_FLAGS_SEND_STATUS
);
1402 ctio
->u
.status1
.ox_id
= swab16(atio
->u
.isp24
.fcp_hdr
.ox_id
);
1403 ctio
->u
.status1
.scsi_status
=
1404 __constant_cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID
);
1405 ctio
->u
.status1
.response_len
= __constant_cpu_to_le16(8);
1406 ((uint32_t *)ctio
->u
.status1
.sense_data
)[0] = cpu_to_be32(resp_code
);
1408 qla2x00_start_iocbs(ha
, ha
->req
);
1411 void qlt_free_mcmd(struct qla_tgt_mgmt_cmd
*mcmd
)
1413 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
1415 EXPORT_SYMBOL(qlt_free_mcmd
);
1417 /* callback from target fabric module code */
1418 void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd
*mcmd
)
1420 struct scsi_qla_host
*vha
= mcmd
->sess
->vha
;
1421 struct qla_hw_data
*ha
= vha
->hw
;
1422 unsigned long flags
;
1424 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf013,
1425 "TM response mcmd (%p) status %#x state %#x",
1426 mcmd
, mcmd
->fc_tm_rsp
, mcmd
->flags
);
1428 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1429 if (mcmd
->flags
== QLA24XX_MGMT_SEND_NACK
)
1430 qlt_send_notify_ack(vha
, &mcmd
->orig_iocb
.imm_ntfy
,
1433 if (mcmd
->se_cmd
.se_tmr_req
->function
== TMR_ABORT_TASK
)
1434 qlt_24xx_send_abts_resp(vha
, &mcmd
->orig_iocb
.abts
,
1435 mcmd
->fc_tm_rsp
, false);
1437 qlt_24xx_send_task_mgmt_ctio(vha
, mcmd
,
1441 * Make the callback for ->free_mcmd() to queue_work() and invoke
1442 * target_put_sess_cmd() to drop cmd_kref to 1. The final
1443 * target_put_sess_cmd() call will be made from TFO->check_stop_free()
1444 * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd
1445 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
1446 * qlt_xmit_tm_rsp() returns here..
1448 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
1449 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1451 EXPORT_SYMBOL(qlt_xmit_tm_rsp
);
1454 static int qlt_pci_map_calc_cnt(struct qla_tgt_prm
*prm
)
1456 struct qla_tgt_cmd
*cmd
= prm
->cmd
;
1458 BUG_ON(cmd
->sg_cnt
== 0);
1460 prm
->sg
= (struct scatterlist
*)cmd
->sg
;
1461 prm
->seg_cnt
= pci_map_sg(prm
->tgt
->ha
->pdev
, cmd
->sg
,
1462 cmd
->sg_cnt
, cmd
->dma_data_direction
);
1463 if (unlikely(prm
->seg_cnt
== 0))
1466 prm
->cmd
->sg_mapped
= 1;
1469 * If greater than four sg entries then we need to allocate
1470 * the continuation entries
1472 if (prm
->seg_cnt
> prm
->tgt
->datasegs_per_cmd
)
1473 prm
->req_cnt
+= DIV_ROUND_UP(prm
->seg_cnt
-
1474 prm
->tgt
->datasegs_per_cmd
, prm
->tgt
->datasegs_per_cont
);
1476 ql_dbg(ql_dbg_tgt
, prm
->cmd
->vha
, 0xe009, "seg_cnt=%d, req_cnt=%d\n",
1477 prm
->seg_cnt
, prm
->req_cnt
);
1481 ql_dbg(ql_dbg_tgt
, prm
->cmd
->vha
, 0xe04d,
1482 "qla_target(%d): PCI mapping failed: sg_cnt=%d",
1483 0, prm
->cmd
->sg_cnt
);
1487 static inline void qlt_unmap_sg(struct scsi_qla_host
*vha
,
1488 struct qla_tgt_cmd
*cmd
)
1490 struct qla_hw_data
*ha
= vha
->hw
;
1492 BUG_ON(!cmd
->sg_mapped
);
1493 pci_unmap_sg(ha
->pdev
, cmd
->sg
, cmd
->sg_cnt
, cmd
->dma_data_direction
);
1497 static int qlt_check_reserve_free_req(struct scsi_qla_host
*vha
,
1500 struct qla_hw_data
*ha
= vha
->hw
;
1501 device_reg_t __iomem
*reg
= ha
->iobase
;
1504 if (vha
->req
->cnt
< (req_cnt
+ 2)) {
1505 cnt
= (uint16_t)RD_REG_DWORD(®
->isp24
.req_q_out
);
1507 ql_dbg(ql_dbg_tgt
, vha
, 0xe00a,
1508 "Request ring circled: cnt=%d, vha->->ring_index=%d, "
1509 "vha->req->cnt=%d, req_cnt=%d\n", cnt
,
1510 vha
->req
->ring_index
, vha
->req
->cnt
, req_cnt
);
1511 if (vha
->req
->ring_index
< cnt
)
1512 vha
->req
->cnt
= cnt
- vha
->req
->ring_index
;
1514 vha
->req
->cnt
= vha
->req
->length
-
1515 (vha
->req
->ring_index
- cnt
);
1518 if (unlikely(vha
->req
->cnt
< (req_cnt
+ 2))) {
1519 ql_dbg(ql_dbg_tgt
, vha
, 0xe00b,
1520 "qla_target(%d): There is no room in the "
1521 "request ring: vha->req->ring_index=%d, vha->req->cnt=%d, "
1522 "req_cnt=%d\n", vha
->vp_idx
, vha
->req
->ring_index
,
1523 vha
->req
->cnt
, req_cnt
);
1526 vha
->req
->cnt
-= req_cnt
;
1532 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1534 static inline void *qlt_get_req_pkt(struct scsi_qla_host
*vha
)
1536 /* Adjust ring index. */
1537 vha
->req
->ring_index
++;
1538 if (vha
->req
->ring_index
== vha
->req
->length
) {
1539 vha
->req
->ring_index
= 0;
1540 vha
->req
->ring_ptr
= vha
->req
->ring
;
1542 vha
->req
->ring_ptr
++;
1544 return (cont_entry_t
*)vha
->req
->ring_ptr
;
1547 /* ha->hardware_lock supposed to be held on entry */
1548 static inline uint32_t qlt_make_handle(struct scsi_qla_host
*vha
)
1550 struct qla_hw_data
*ha
= vha
->hw
;
1553 h
= ha
->tgt
.current_handle
;
1554 /* always increment cmd handle */
1557 if (h
> MAX_OUTSTANDING_COMMANDS
)
1558 h
= 1; /* 0 is QLA_TGT_NULL_HANDLE */
1559 if (h
== ha
->tgt
.current_handle
) {
1560 ql_dbg(ql_dbg_tgt
, vha
, 0xe04e,
1561 "qla_target(%d): Ran out of "
1562 "empty cmd slots in ha %p\n", vha
->vp_idx
, ha
);
1563 h
= QLA_TGT_NULL_HANDLE
;
1566 } while ((h
== QLA_TGT_NULL_HANDLE
) ||
1567 (h
== QLA_TGT_SKIP_HANDLE
) ||
1568 (ha
->tgt
.cmds
[h
-1] != NULL
));
1570 if (h
!= QLA_TGT_NULL_HANDLE
)
1571 ha
->tgt
.current_handle
= h
;
1576 /* ha->hardware_lock supposed to be held on entry */
1577 static int qlt_24xx_build_ctio_pkt(struct qla_tgt_prm
*prm
,
1578 struct scsi_qla_host
*vha
)
1581 struct ctio7_to_24xx
*pkt
;
1582 struct qla_hw_data
*ha
= vha
->hw
;
1583 struct atio_from_isp
*atio
= &prm
->cmd
->atio
;
1585 pkt
= (struct ctio7_to_24xx
*)vha
->req
->ring_ptr
;
1587 memset(pkt
, 0, sizeof(*pkt
));
1589 pkt
->entry_type
= CTIO_TYPE7
;
1590 pkt
->entry_count
= (uint8_t)prm
->req_cnt
;
1591 pkt
->vp_index
= vha
->vp_idx
;
1593 h
= qlt_make_handle(vha
);
1594 if (unlikely(h
== QLA_TGT_NULL_HANDLE
)) {
1596 * CTIO type 7 from the firmware doesn't provide a way to
1597 * know the initiator's LOOP ID, hence we can't find
1598 * the session and, so, the command.
1602 ha
->tgt
.cmds
[h
-1] = prm
->cmd
;
1604 pkt
->handle
= h
| CTIO_COMPLETION_HANDLE_MARK
;
1605 pkt
->nport_handle
= prm
->cmd
->loop_id
;
1606 pkt
->timeout
= __constant_cpu_to_le16(QLA_TGT_TIMEOUT
);
1607 pkt
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
1608 pkt
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
1609 pkt
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
1610 pkt
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
1611 pkt
->u
.status0
.flags
|= (atio
->u
.isp24
.attr
<< 9);
1612 pkt
->u
.status0
.ox_id
= swab16(atio
->u
.isp24
.fcp_hdr
.ox_id
);
1613 pkt
->u
.status0
.relative_offset
= cpu_to_le32(prm
->cmd
->offset
);
1615 ql_dbg(ql_dbg_tgt
, vha
, 0xe00c,
1616 "qla_target(%d): handle(cmd) -> %08x, timeout %d, ox_id %#x\n",
1617 vha
->vp_idx
, pkt
->handle
, QLA_TGT_TIMEOUT
,
1618 le16_to_cpu(pkt
->u
.status0
.ox_id
));
1623 * ha->hardware_lock supposed to be held on entry. We have already made sure
1624 * that there is sufficient amount of request entries to not drop it.
1626 static void qlt_load_cont_data_segments(struct qla_tgt_prm
*prm
,
1627 struct scsi_qla_host
*vha
)
1630 uint32_t *dword_ptr
;
1631 int enable_64bit_addressing
= prm
->tgt
->tgt_enable_64bit_addr
;
1633 /* Build continuation packets */
1634 while (prm
->seg_cnt
> 0) {
1635 cont_a64_entry_t
*cont_pkt64
=
1636 (cont_a64_entry_t
*)qlt_get_req_pkt(vha
);
1639 * Make sure that from cont_pkt64 none of
1640 * 64-bit specific fields used for 32-bit
1641 * addressing. Cast to (cont_entry_t *) for
1645 memset(cont_pkt64
, 0, sizeof(*cont_pkt64
));
1647 cont_pkt64
->entry_count
= 1;
1648 cont_pkt64
->sys_define
= 0;
1650 if (enable_64bit_addressing
) {
1651 cont_pkt64
->entry_type
= CONTINUE_A64_TYPE
;
1653 (uint32_t *)&cont_pkt64
->dseg_0_address
;
1655 cont_pkt64
->entry_type
= CONTINUE_TYPE
;
1657 (uint32_t *)&((cont_entry_t
*)
1658 cont_pkt64
)->dseg_0_address
;
1661 /* Load continuation entry data segments */
1663 cnt
< prm
->tgt
->datasegs_per_cont
&& prm
->seg_cnt
;
1664 cnt
++, prm
->seg_cnt
--) {
1666 cpu_to_le32(pci_dma_lo32
1667 (sg_dma_address(prm
->sg
)));
1668 if (enable_64bit_addressing
) {
1670 cpu_to_le32(pci_dma_hi32
1674 *dword_ptr
++ = cpu_to_le32(sg_dma_len(prm
->sg
));
1676 ql_dbg(ql_dbg_tgt
, vha
, 0xe00d,
1677 "S/G Segment Cont. phys_addr=%llx:%llx, len=%d\n",
1678 (long long unsigned int)
1679 pci_dma_hi32(sg_dma_address(prm
->sg
)),
1680 (long long unsigned int)
1681 pci_dma_lo32(sg_dma_address(prm
->sg
)),
1682 (int)sg_dma_len(prm
->sg
));
1684 prm
->sg
= sg_next(prm
->sg
);
1690 * ha->hardware_lock supposed to be held on entry. We have already made sure
1691 * that there is sufficient amount of request entries to not drop it.
1693 static void qlt_load_data_segments(struct qla_tgt_prm
*prm
,
1694 struct scsi_qla_host
*vha
)
1697 uint32_t *dword_ptr
;
1698 int enable_64bit_addressing
= prm
->tgt
->tgt_enable_64bit_addr
;
1699 struct ctio7_to_24xx
*pkt24
= (struct ctio7_to_24xx
*)prm
->pkt
;
1701 ql_dbg(ql_dbg_tgt
, vha
, 0xe00e,
1702 "iocb->scsi_status=%x, iocb->flags=%x\n",
1703 le16_to_cpu(pkt24
->u
.status0
.scsi_status
),
1704 le16_to_cpu(pkt24
->u
.status0
.flags
));
1706 pkt24
->u
.status0
.transfer_length
= cpu_to_le32(prm
->cmd
->bufflen
);
1708 /* Setup packet address segment pointer */
1709 dword_ptr
= pkt24
->u
.status0
.dseg_0_address
;
1711 /* Set total data segment count */
1713 pkt24
->dseg_count
= cpu_to_le16(prm
->seg_cnt
);
1715 if (prm
->seg_cnt
== 0) {
1716 /* No data transfer */
1722 /* If scatter gather */
1723 ql_dbg(ql_dbg_tgt
, vha
, 0xe00f, "%s", "Building S/G data segments...");
1725 /* Load command entry data segments */
1727 (cnt
< prm
->tgt
->datasegs_per_cmd
) && prm
->seg_cnt
;
1728 cnt
++, prm
->seg_cnt
--) {
1730 cpu_to_le32(pci_dma_lo32(sg_dma_address(prm
->sg
)));
1731 if (enable_64bit_addressing
) {
1733 cpu_to_le32(pci_dma_hi32(
1734 sg_dma_address(prm
->sg
)));
1736 *dword_ptr
++ = cpu_to_le32(sg_dma_len(prm
->sg
));
1738 ql_dbg(ql_dbg_tgt
, vha
, 0xe010,
1739 "S/G Segment phys_addr=%llx:%llx, len=%d\n",
1740 (long long unsigned int)pci_dma_hi32(sg_dma_address(
1742 (long long unsigned int)pci_dma_lo32(sg_dma_address(
1744 (int)sg_dma_len(prm
->sg
));
1746 prm
->sg
= sg_next(prm
->sg
);
1749 qlt_load_cont_data_segments(prm
, vha
);
1752 static inline int qlt_has_data(struct qla_tgt_cmd
*cmd
)
1754 return cmd
->bufflen
> 0;
1758 * Called without ha->hardware_lock held
1760 static int qlt_pre_xmit_response(struct qla_tgt_cmd
*cmd
,
1761 struct qla_tgt_prm
*prm
, int xmit_type
, uint8_t scsi_status
,
1762 uint32_t *full_req_cnt
)
1764 struct qla_tgt
*tgt
= cmd
->tgt
;
1765 struct scsi_qla_host
*vha
= tgt
->vha
;
1766 struct qla_hw_data
*ha
= vha
->hw
;
1767 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
1769 if (unlikely(cmd
->aborted
)) {
1770 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf014,
1771 "qla_target(%d): terminating exchange "
1772 "for aborted cmd=%p (se_cmd=%p, tag=%d)", vha
->vp_idx
, cmd
,
1775 cmd
->state
= QLA_TGT_STATE_ABORTED
;
1777 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 0);
1779 /* !! At this point cmd could be already freed !! */
1780 return QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED
;
1783 ql_dbg(ql_dbg_tgt
, vha
, 0xe011, "qla_target(%d): tag=%u\n",
1784 vha
->vp_idx
, cmd
->tag
);
1788 prm
->rq_result
= scsi_status
;
1789 prm
->sense_buffer
= &cmd
->sense_buffer
[0];
1790 prm
->sense_buffer_len
= TRANSPORT_SENSE_BUFFER
;
1794 prm
->add_status_pkt
= 0;
1796 ql_dbg(ql_dbg_tgt
, vha
, 0xe012, "rq_result=%x, xmit_type=%x\n",
1797 prm
->rq_result
, xmit_type
);
1799 /* Send marker if required */
1800 if (qlt_issue_marker(vha
, 0) != QLA_SUCCESS
)
1803 ql_dbg(ql_dbg_tgt
, vha
, 0xe013, "CTIO start: vha(%d)\n", vha
->vp_idx
);
1805 if ((xmit_type
& QLA_TGT_XMIT_DATA
) && qlt_has_data(cmd
)) {
1806 if (qlt_pci_map_calc_cnt(prm
) != 0)
1810 *full_req_cnt
= prm
->req_cnt
;
1812 if (se_cmd
->se_cmd_flags
& SCF_UNDERFLOW_BIT
) {
1813 prm
->residual
= se_cmd
->residual_count
;
1814 ql_dbg(ql_dbg_tgt
, vha
, 0xe014,
1815 "Residual underflow: %d (tag %d, "
1816 "op %x, bufflen %d, rq_result %x)\n", prm
->residual
,
1817 cmd
->tag
, se_cmd
->t_task_cdb
? se_cmd
->t_task_cdb
[0] : 0,
1818 cmd
->bufflen
, prm
->rq_result
);
1819 prm
->rq_result
|= SS_RESIDUAL_UNDER
;
1820 } else if (se_cmd
->se_cmd_flags
& SCF_OVERFLOW_BIT
) {
1821 prm
->residual
= se_cmd
->residual_count
;
1822 ql_dbg(ql_dbg_tgt
, vha
, 0xe015,
1823 "Residual overflow: %d (tag %d, "
1824 "op %x, bufflen %d, rq_result %x)\n", prm
->residual
,
1825 cmd
->tag
, se_cmd
->t_task_cdb
? se_cmd
->t_task_cdb
[0] : 0,
1826 cmd
->bufflen
, prm
->rq_result
);
1827 prm
->rq_result
|= SS_RESIDUAL_OVER
;
1830 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
1832 * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be
1833 * ignored in *xmit_response() below
1835 if (qlt_has_data(cmd
)) {
1836 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
) ||
1837 (IS_FWI2_CAPABLE(ha
) &&
1838 (prm
->rq_result
!= 0))) {
1839 prm
->add_status_pkt
= 1;
1845 ql_dbg(ql_dbg_tgt
, vha
, 0xe016,
1846 "req_cnt=%d, full_req_cnt=%d, add_status_pkt=%d\n",
1847 prm
->req_cnt
, *full_req_cnt
, prm
->add_status_pkt
);
1852 static inline int qlt_need_explicit_conf(struct qla_hw_data
*ha
,
1853 struct qla_tgt_cmd
*cmd
, int sending_sense
)
1855 if (ha
->tgt
.enable_class_2
)
1859 return cmd
->conf_compl_supported
;
1861 return ha
->tgt
.enable_explicit_conf
&&
1862 cmd
->conf_compl_supported
;
1865 #ifdef CONFIG_QLA_TGT_DEBUG_SRR
1867 * Original taken from the XFS code
1869 static unsigned long qlt_srr_random(void)
1872 static unsigned long RandomValue
;
1873 static DEFINE_SPINLOCK(lock
);
1874 /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
1878 unsigned long flags
;
1880 spin_lock_irqsave(&lock
, flags
);
1882 RandomValue
= jiffies
;
1888 rv
= 16807 * lo
- 2836 * hi
;
1892 spin_unlock_irqrestore(&lock
, flags
);
1896 static void qlt_check_srr_debug(struct qla_tgt_cmd
*cmd
, int *xmit_type
)
1898 #if 0 /* This is not a real status packets lost, so it won't lead to SRR */
1899 if ((*xmit_type
& QLA_TGT_XMIT_STATUS
) && (qlt_srr_random() % 200)
1901 *xmit_type
&= ~QLA_TGT_XMIT_STATUS
;
1902 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf015,
1903 "Dropping cmd %p (tag %d) status", cmd
, cmd
->tag
);
1907 * It's currently not possible to simulate SRRs for FCP_WRITE without
1908 * a physical link layer failure, so don't even try here..
1910 if (cmd
->dma_data_direction
!= DMA_FROM_DEVICE
)
1913 if (qlt_has_data(cmd
) && (cmd
->sg_cnt
> 1) &&
1914 ((qlt_srr_random() % 100) == 20)) {
1916 unsigned int tot_len
= 0;
1919 leave
= qlt_srr_random() % cmd
->sg_cnt
;
1921 for (i
= 0; i
< leave
; i
++)
1922 tot_len
+= cmd
->sg
[i
].length
;
1924 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf016,
1925 "Cutting cmd %p (tag %d) buffer"
1926 " tail to len %d, sg_cnt %d (cmd->bufflen %d,"
1927 " cmd->sg_cnt %d)", cmd
, cmd
->tag
, tot_len
, leave
,
1928 cmd
->bufflen
, cmd
->sg_cnt
);
1930 cmd
->bufflen
= tot_len
;
1931 cmd
->sg_cnt
= leave
;
1934 if (qlt_has_data(cmd
) && ((qlt_srr_random() % 100) == 70)) {
1935 unsigned int offset
= qlt_srr_random() % cmd
->bufflen
;
1937 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf017,
1938 "Cutting cmd %p (tag %d) buffer head "
1939 "to offset %d (cmd->bufflen %d)", cmd
, cmd
->tag
, offset
,
1942 *xmit_type
&= ~QLA_TGT_XMIT_DATA
;
1943 else if (qlt_set_data_offset(cmd
, offset
)) {
1944 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf018,
1945 "qlt_set_data_offset() failed (tag %d)", cmd
->tag
);
1950 static inline void qlt_check_srr_debug(struct qla_tgt_cmd
*cmd
, int *xmit_type
)
1954 static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx
*ctio
,
1955 struct qla_tgt_prm
*prm
)
1957 prm
->sense_buffer_len
= min_t(uint32_t, prm
->sense_buffer_len
,
1958 (uint32_t)sizeof(ctio
->u
.status1
.sense_data
));
1959 ctio
->u
.status0
.flags
|=
1960 __constant_cpu_to_le16(CTIO7_FLAGS_SEND_STATUS
);
1961 if (qlt_need_explicit_conf(prm
->tgt
->ha
, prm
->cmd
, 0)) {
1962 ctio
->u
.status0
.flags
|= __constant_cpu_to_le16(
1963 CTIO7_FLAGS_EXPLICIT_CONFORM
|
1964 CTIO7_FLAGS_CONFORM_REQ
);
1966 ctio
->u
.status0
.residual
= cpu_to_le32(prm
->residual
);
1967 ctio
->u
.status0
.scsi_status
= cpu_to_le16(prm
->rq_result
);
1968 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
)) {
1971 if (qlt_need_explicit_conf(prm
->tgt
->ha
, prm
->cmd
, 1)) {
1972 if (prm
->cmd
->se_cmd
.scsi_status
!= 0) {
1973 ql_dbg(ql_dbg_tgt
, prm
->cmd
->vha
, 0xe017,
1974 "Skipping EXPLICIT_CONFORM and "
1975 "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
1976 "non GOOD status\n");
1977 goto skip_explict_conf
;
1979 ctio
->u
.status1
.flags
|= __constant_cpu_to_le16(
1980 CTIO7_FLAGS_EXPLICIT_CONFORM
|
1981 CTIO7_FLAGS_CONFORM_REQ
);
1984 ctio
->u
.status1
.flags
&=
1985 ~__constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
1986 ctio
->u
.status1
.flags
|=
1987 __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
1988 ctio
->u
.status1
.scsi_status
|=
1989 __constant_cpu_to_le16(SS_SENSE_LEN_VALID
);
1990 ctio
->u
.status1
.sense_length
=
1991 cpu_to_le16(prm
->sense_buffer_len
);
1992 for (i
= 0; i
< prm
->sense_buffer_len
/4; i
++)
1993 ((uint32_t *)ctio
->u
.status1
.sense_data
)[i
] =
1994 cpu_to_be32(((uint32_t *)prm
->sense_buffer
)[i
]);
1996 if (unlikely((prm
->sense_buffer_len
% 4) != 0)) {
1999 ql_dbg(ql_dbg_tgt
, vha
, 0xe04f,
2000 "qla_target(%d): %d bytes of sense "
2001 "lost", prm
->tgt
->ha
->vp_idx
,
2002 prm
->sense_buffer_len
% 4);
2008 ctio
->u
.status1
.flags
&=
2009 ~__constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
2010 ctio
->u
.status1
.flags
|=
2011 __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
2012 ctio
->u
.status1
.sense_length
= 0;
2013 memset(ctio
->u
.status1
.sense_data
, 0,
2014 sizeof(ctio
->u
.status1
.sense_data
));
2017 /* Sense with len > 24, is it possible ??? */
2021 * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and *
2022 * QLA_TGT_XMIT_STATUS for >= 24xx silicon
2024 int qlt_xmit_response(struct qla_tgt_cmd
*cmd
, int xmit_type
,
2025 uint8_t scsi_status
)
2027 struct scsi_qla_host
*vha
= cmd
->vha
;
2028 struct qla_hw_data
*ha
= vha
->hw
;
2029 struct ctio7_to_24xx
*pkt
;
2030 struct qla_tgt_prm prm
;
2031 uint32_t full_req_cnt
= 0;
2032 unsigned long flags
= 0;
2035 memset(&prm
, 0, sizeof(prm
));
2036 qlt_check_srr_debug(cmd
, &xmit_type
);
2038 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe018,
2039 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, "
2040 "cmd->dma_data_direction=%d\n", (xmit_type
& QLA_TGT_XMIT_STATUS
) ?
2041 1 : 0, cmd
->bufflen
, cmd
->sg_cnt
, cmd
->dma_data_direction
);
2043 res
= qlt_pre_xmit_response(cmd
, &prm
, xmit_type
, scsi_status
,
2045 if (unlikely(res
!= 0)) {
2046 if (res
== QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED
)
2052 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2054 /* Does F/W have an IOCBs for this request */
2055 res
= qlt_check_reserve_free_req(vha
, full_req_cnt
);
2057 goto out_unmap_unlock
;
2059 res
= qlt_24xx_build_ctio_pkt(&prm
, vha
);
2060 if (unlikely(res
!= 0))
2061 goto out_unmap_unlock
;
2064 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
2066 if (qlt_has_data(cmd
) && (xmit_type
& QLA_TGT_XMIT_DATA
)) {
2067 pkt
->u
.status0
.flags
|=
2068 __constant_cpu_to_le16(CTIO7_FLAGS_DATA_IN
|
2069 CTIO7_FLAGS_STATUS_MODE_0
);
2071 qlt_load_data_segments(&prm
, vha
);
2073 if (prm
.add_status_pkt
== 0) {
2074 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
2075 pkt
->u
.status0
.scsi_status
=
2076 cpu_to_le16(prm
.rq_result
);
2077 pkt
->u
.status0
.residual
=
2078 cpu_to_le32(prm
.residual
);
2079 pkt
->u
.status0
.flags
|= __constant_cpu_to_le16(
2080 CTIO7_FLAGS_SEND_STATUS
);
2081 if (qlt_need_explicit_conf(ha
, cmd
, 0)) {
2082 pkt
->u
.status0
.flags
|=
2083 __constant_cpu_to_le16(
2084 CTIO7_FLAGS_EXPLICIT_CONFORM
|
2085 CTIO7_FLAGS_CONFORM_REQ
);
2091 * We have already made sure that there is sufficient
2092 * amount of request entries to not drop HW lock in
2095 struct ctio7_to_24xx
*ctio
=
2096 (struct ctio7_to_24xx
*)qlt_get_req_pkt(vha
);
2098 ql_dbg(ql_dbg_tgt
, vha
, 0xe019,
2099 "Building additional status packet\n");
2101 memcpy(ctio
, pkt
, sizeof(*ctio
));
2102 ctio
->entry_count
= 1;
2103 ctio
->dseg_count
= 0;
2104 ctio
->u
.status1
.flags
&= ~__constant_cpu_to_le16(
2105 CTIO7_FLAGS_DATA_IN
);
2107 /* Real finish is ctio_m1's finish */
2108 pkt
->handle
|= CTIO_INTERMEDIATE_HANDLE_MARK
;
2109 pkt
->u
.status0
.flags
|= __constant_cpu_to_le16(
2110 CTIO7_FLAGS_DONT_RET_CTIO
);
2111 qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx
*)ctio
,
2113 pr_debug("Status CTIO7: %p\n", ctio
);
2116 qlt_24xx_init_ctio_to_isp(pkt
, &prm
);
2119 cmd
->state
= QLA_TGT_STATE_PROCESSED
; /* Mid-level is done processing */
2121 ql_dbg(ql_dbg_tgt
, vha
, 0xe01a,
2122 "Xmitting CTIO7 response pkt for 24xx: %p scsi_status: 0x%02x\n",
2125 qla2x00_start_iocbs(vha
, vha
->req
);
2126 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2132 qlt_unmap_sg(vha
, cmd
);
2133 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2137 EXPORT_SYMBOL(qlt_xmit_response
);
2139 int qlt_rdy_to_xfer(struct qla_tgt_cmd
*cmd
)
2141 struct ctio7_to_24xx
*pkt
;
2142 struct scsi_qla_host
*vha
= cmd
->vha
;
2143 struct qla_hw_data
*ha
= vha
->hw
;
2144 struct qla_tgt
*tgt
= cmd
->tgt
;
2145 struct qla_tgt_prm prm
;
2146 unsigned long flags
;
2149 memset(&prm
, 0, sizeof(prm
));
2155 /* Send marker if required */
2156 if (qlt_issue_marker(vha
, 0) != QLA_SUCCESS
)
2159 ql_dbg(ql_dbg_tgt
, vha
, 0xe01b, "CTIO_start: vha(%d)",
2162 /* Calculate number of entries and segments required */
2163 if (qlt_pci_map_calc_cnt(&prm
) != 0)
2166 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2168 /* Does F/W have an IOCBs for this request */
2169 res
= qlt_check_reserve_free_req(vha
, prm
.req_cnt
);
2171 goto out_unlock_free_unmap
;
2173 res
= qlt_24xx_build_ctio_pkt(&prm
, vha
);
2174 if (unlikely(res
!= 0))
2175 goto out_unlock_free_unmap
;
2176 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
2177 pkt
->u
.status0
.flags
|= __constant_cpu_to_le16(CTIO7_FLAGS_DATA_OUT
|
2178 CTIO7_FLAGS_STATUS_MODE_0
);
2179 qlt_load_data_segments(&prm
, vha
);
2181 cmd
->state
= QLA_TGT_STATE_NEED_DATA
;
2183 qla2x00_start_iocbs(vha
, vha
->req
);
2184 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2188 out_unlock_free_unmap
:
2190 qlt_unmap_sg(vha
, cmd
);
2191 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2195 EXPORT_SYMBOL(qlt_rdy_to_xfer
);
2197 /* If hardware_lock held on entry, might drop it, then reaquire */
2198 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
2199 static int __qlt_send_term_exchange(struct scsi_qla_host
*vha
,
2200 struct qla_tgt_cmd
*cmd
,
2201 struct atio_from_isp
*atio
)
2203 struct ctio7_to_24xx
*ctio24
;
2204 struct qla_hw_data
*ha
= vha
->hw
;
2208 ql_dbg(ql_dbg_tgt
, vha
, 0xe01c, "Sending TERM EXCH CTIO (ha=%p)\n", ha
);
2210 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
2212 ql_dbg(ql_dbg_tgt
, vha
, 0xe050,
2213 "qla_target(%d): %s failed: unable to allocate "
2214 "request packet\n", vha
->vp_idx
, __func__
);
2219 if (cmd
->state
< QLA_TGT_STATE_PROCESSED
) {
2220 ql_dbg(ql_dbg_tgt
, vha
, 0xe051,
2221 "qla_target(%d): Terminating cmd %p with "
2222 "incorrect state %d\n", vha
->vp_idx
, cmd
,
2228 pkt
->entry_count
= 1;
2229 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
2231 ctio24
= (struct ctio7_to_24xx
*)pkt
;
2232 ctio24
->entry_type
= CTIO_TYPE7
;
2233 ctio24
->nport_handle
= cmd
? cmd
->loop_id
: CTIO7_NHANDLE_UNRECOGNIZED
;
2234 ctio24
->timeout
= __constant_cpu_to_le16(QLA_TGT_TIMEOUT
);
2235 ctio24
->vp_index
= vha
->vp_idx
;
2236 ctio24
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2237 ctio24
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2238 ctio24
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2239 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2240 ctio24
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
2241 __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
|
2242 CTIO7_FLAGS_TERMINATE
);
2243 ctio24
->u
.status1
.ox_id
= swab16(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2245 /* Most likely, it isn't needed */
2246 ctio24
->u
.status1
.residual
= get_unaligned((uint32_t *)
2247 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
2248 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]);
2249 if (ctio24
->u
.status1
.residual
!= 0)
2250 ctio24
->u
.status1
.scsi_status
|= SS_RESIDUAL_UNDER
;
2252 qla2x00_start_iocbs(vha
, vha
->req
);
2256 static void qlt_send_term_exchange(struct scsi_qla_host
*vha
,
2257 struct qla_tgt_cmd
*cmd
, struct atio_from_isp
*atio
, int ha_locked
)
2259 unsigned long flags
;
2262 if (qlt_issue_marker(vha
, ha_locked
) < 0)
2266 rc
= __qlt_send_term_exchange(vha
, cmd
, atio
);
2269 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
2270 rc
= __qlt_send_term_exchange(vha
, cmd
, atio
);
2271 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
2274 if (!ha_locked
&& !in_interrupt())
2275 msleep(250); /* just in case */
2277 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
2281 void qlt_free_cmd(struct qla_tgt_cmd
*cmd
)
2283 BUG_ON(cmd
->sg_mapped
);
2285 if (unlikely(cmd
->free_sg
))
2287 kmem_cache_free(qla_tgt_cmd_cachep
, cmd
);
2289 EXPORT_SYMBOL(qlt_free_cmd
);
2291 /* ha->hardware_lock supposed to be held on entry */
2292 static int qlt_prepare_srr_ctio(struct scsi_qla_host
*vha
,
2293 struct qla_tgt_cmd
*cmd
, void *ctio
)
2295 struct qla_tgt_srr_ctio
*sc
;
2296 struct qla_hw_data
*ha
= vha
->hw
;
2297 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
2298 struct qla_tgt_srr_imm
*imm
;
2302 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf019,
2303 "qla_target(%d): CTIO with SRR status received\n", vha
->vp_idx
);
2306 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf055,
2307 "qla_target(%d): SRR CTIO, but ctio is NULL\n",
2312 sc
= kzalloc(sizeof(*sc
), GFP_ATOMIC
);
2315 /* IRQ is already OFF */
2316 spin_lock(&tgt
->srr_lock
);
2317 sc
->srr_id
= tgt
->ctio_srr_id
;
2318 list_add_tail(&sc
->srr_list_entry
,
2319 &tgt
->srr_ctio_list
);
2320 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01a,
2321 "CTIO SRR %p added (id %d)\n", sc
, sc
->srr_id
);
2322 if (tgt
->imm_srr_id
== tgt
->ctio_srr_id
) {
2324 list_for_each_entry(imm
, &tgt
->srr_imm_list
,
2326 if (imm
->srr_id
== sc
->srr_id
) {
2332 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01b,
2333 "Scheduling srr work\n");
2334 schedule_work(&tgt
->srr_work
);
2336 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf056,
2337 "qla_target(%d): imm_srr_id "
2338 "== ctio_srr_id (%d), but there is no "
2339 "corresponding SRR IMM, deleting CTIO "
2340 "SRR %p\n", vha
->vp_idx
,
2341 tgt
->ctio_srr_id
, sc
);
2342 list_del(&sc
->srr_list_entry
);
2343 spin_unlock(&tgt
->srr_lock
);
2349 spin_unlock(&tgt
->srr_lock
);
2351 struct qla_tgt_srr_imm
*ti
;
2353 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf057,
2354 "qla_target(%d): Unable to allocate SRR CTIO entry\n",
2356 spin_lock(&tgt
->srr_lock
);
2357 list_for_each_entry_safe(imm
, ti
, &tgt
->srr_imm_list
,
2359 if (imm
->srr_id
== tgt
->ctio_srr_id
) {
2360 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01c,
2361 "IMM SRR %p deleted (id %d)\n",
2363 list_del(&imm
->srr_list_entry
);
2364 qlt_reject_free_srr_imm(vha
, imm
, 1);
2367 spin_unlock(&tgt
->srr_lock
);
2376 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2378 static int qlt_term_ctio_exchange(struct scsi_qla_host
*vha
, void *ctio
,
2379 struct qla_tgt_cmd
*cmd
, uint32_t status
)
2384 struct ctio7_from_24xx
*c
= (struct ctio7_from_24xx
*)ctio
;
2386 __constant_cpu_to_le16(OF_TERM_EXCH
));
2391 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 1);
2396 /* ha->hardware_lock supposed to be held on entry */
2397 static inline struct qla_tgt_cmd
*qlt_get_cmd(struct scsi_qla_host
*vha
,
2400 struct qla_hw_data
*ha
= vha
->hw
;
2403 if (ha
->tgt
.cmds
[handle
] != NULL
) {
2404 struct qla_tgt_cmd
*cmd
= ha
->tgt
.cmds
[handle
];
2405 ha
->tgt
.cmds
[handle
] = NULL
;
2411 /* ha->hardware_lock supposed to be held on entry */
2412 static struct qla_tgt_cmd
*qlt_ctio_to_cmd(struct scsi_qla_host
*vha
,
2413 uint32_t handle
, void *ctio
)
2415 struct qla_tgt_cmd
*cmd
= NULL
;
2417 /* Clear out internal marks */
2418 handle
&= ~(CTIO_COMPLETION_HANDLE_MARK
|
2419 CTIO_INTERMEDIATE_HANDLE_MARK
);
2421 if (handle
!= QLA_TGT_NULL_HANDLE
) {
2422 if (unlikely(handle
== QLA_TGT_SKIP_HANDLE
)) {
2423 ql_dbg(ql_dbg_tgt
, vha
, 0xe01d, "%s",
2424 "SKIP_HANDLE CTIO\n");
2427 /* handle-1 is actually used */
2428 if (unlikely(handle
> MAX_OUTSTANDING_COMMANDS
)) {
2429 ql_dbg(ql_dbg_tgt
, vha
, 0xe052,
2430 "qla_target(%d): Wrong handle %x received\n",
2431 vha
->vp_idx
, handle
);
2434 cmd
= qlt_get_cmd(vha
, handle
);
2435 if (unlikely(cmd
== NULL
)) {
2436 ql_dbg(ql_dbg_tgt
, vha
, 0xe053,
2437 "qla_target(%d): Suspicious: unable to "
2438 "find the command with handle %x\n", vha
->vp_idx
,
2442 } else if (ctio
!= NULL
) {
2443 /* We can't get loop ID from CTIO7 */
2444 ql_dbg(ql_dbg_tgt
, vha
, 0xe054,
2445 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
2446 "support NULL handles\n", vha
->vp_idx
);
2454 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2456 static void qlt_do_ctio_completion(struct scsi_qla_host
*vha
, uint32_t handle
,
2457 uint32_t status
, void *ctio
)
2459 struct qla_hw_data
*ha
= vha
->hw
;
2460 struct se_cmd
*se_cmd
;
2461 struct target_core_fabric_ops
*tfo
;
2462 struct qla_tgt_cmd
*cmd
;
2464 ql_dbg(ql_dbg_tgt
, vha
, 0xe01e,
2465 "qla_target(%d): handle(ctio %p status %#x) <- %08x\n",
2466 vha
->vp_idx
, ctio
, status
, handle
);
2468 if (handle
& CTIO_INTERMEDIATE_HANDLE_MARK
) {
2469 /* That could happen only in case of an error/reset/abort */
2470 if (status
!= CTIO_SUCCESS
) {
2471 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01d,
2472 "Intermediate CTIO received"
2473 " (status %x)\n", status
);
2478 cmd
= qlt_ctio_to_cmd(vha
, handle
, ctio
);
2482 se_cmd
= &cmd
->se_cmd
;
2483 tfo
= se_cmd
->se_tfo
;
2486 qlt_unmap_sg(vha
, cmd
);
2488 if (unlikely(status
!= CTIO_SUCCESS
)) {
2489 switch (status
& 0xFFFF) {
2490 case CTIO_LIP_RESET
:
2491 case CTIO_TARGET_RESET
:
2494 case CTIO_INVALID_RX_ID
:
2496 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf058,
2497 "qla_target(%d): CTIO with "
2498 "status %#x received, state %x, se_cmd %p, "
2499 "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
2500 "TIMEOUT=b, INVALID_RX_ID=8)\n", vha
->vp_idx
,
2501 status
, cmd
->state
, se_cmd
);
2504 case CTIO_PORT_LOGGED_OUT
:
2505 case CTIO_PORT_UNAVAILABLE
:
2506 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf059,
2507 "qla_target(%d): CTIO with PORT LOGGED "
2508 "OUT (29) or PORT UNAVAILABLE (28) status %x "
2509 "received (state %x, se_cmd %p)\n", vha
->vp_idx
,
2510 status
, cmd
->state
, se_cmd
);
2513 case CTIO_SRR_RECEIVED
:
2514 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05a,
2515 "qla_target(%d): CTIO with SRR_RECEIVED"
2516 " status %x received (state %x, se_cmd %p)\n",
2517 vha
->vp_idx
, status
, cmd
->state
, se_cmd
);
2518 if (qlt_prepare_srr_ctio(vha
, cmd
, ctio
) != 0)
2524 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05b,
2525 "qla_target(%d): CTIO with error status "
2526 "0x%x received (state %x, se_cmd %p\n",
2527 vha
->vp_idx
, status
, cmd
->state
, se_cmd
);
2531 if (cmd
->state
!= QLA_TGT_STATE_NEED_DATA
)
2532 if (qlt_term_ctio_exchange(vha
, ctio
, cmd
, status
))
2536 if (cmd
->state
== QLA_TGT_STATE_PROCESSED
) {
2537 ql_dbg(ql_dbg_tgt
, vha
, 0xe01f, "Command %p finished\n", cmd
);
2538 } else if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
2541 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
2543 if (unlikely(status
!= CTIO_SUCCESS
))
2546 cmd
->write_data_transferred
= 1;
2548 ql_dbg(ql_dbg_tgt
, vha
, 0xe020,
2549 "Data received, context %x, rx_status %d\n",
2552 ha
->tgt
.tgt_ops
->handle_data(cmd
);
2554 } else if (cmd
->state
== QLA_TGT_STATE_ABORTED
) {
2555 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01e,
2556 "Aborted command %p (tag %d) finished\n", cmd
, cmd
->tag
);
2558 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05c,
2559 "qla_target(%d): A command in state (%d) should "
2560 "not return a CTIO complete\n", vha
->vp_idx
, cmd
->state
);
2563 if (unlikely(status
!= CTIO_SUCCESS
)) {
2564 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01f, "Finishing failed CTIO\n");
2568 ha
->tgt
.tgt_ops
->free_cmd(cmd
);
2571 /* ha->hardware_lock supposed to be held on entry */
2572 /* called via callback from qla2xxx */
2573 void qlt_ctio_completion(struct scsi_qla_host
*vha
, uint32_t handle
)
2575 struct qla_hw_data
*ha
= vha
->hw
;
2576 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
2578 if (likely(tgt
== NULL
)) {
2579 ql_dbg(ql_dbg_tgt
, vha
, 0xe021,
2580 "CTIO, but target mode not enabled"
2581 " (ha %d %p handle %#x)", vha
->vp_idx
, ha
, handle
);
2585 tgt
->irq_cmd_count
++;
2586 qlt_do_ctio_completion(vha
, handle
, CTIO_SUCCESS
, NULL
);
2587 tgt
->irq_cmd_count
--;
2590 static inline int qlt_get_fcp_task_attr(struct scsi_qla_host
*vha
,
2595 switch (task_codes
) {
2596 case ATIO_SIMPLE_QUEUE
:
2597 fcp_task_attr
= MSG_SIMPLE_TAG
;
2599 case ATIO_HEAD_OF_QUEUE
:
2600 fcp_task_attr
= MSG_HEAD_TAG
;
2602 case ATIO_ORDERED_QUEUE
:
2603 fcp_task_attr
= MSG_ORDERED_TAG
;
2605 case ATIO_ACA_QUEUE
:
2606 fcp_task_attr
= MSG_ACA_TAG
;
2609 fcp_task_attr
= MSG_SIMPLE_TAG
;
2612 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05d,
2613 "qla_target: unknown task code %x, use ORDERED instead\n",
2615 fcp_task_attr
= MSG_ORDERED_TAG
;
2619 return fcp_task_attr
;
2622 static struct qla_tgt_sess
*qlt_make_local_sess(struct scsi_qla_host
*,
2625 * Process context for I/O path into tcm_qla2xxx code
2627 static void qlt_do_work(struct work_struct
*work
)
2629 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
2630 scsi_qla_host_t
*vha
= cmd
->vha
;
2631 struct qla_hw_data
*ha
= vha
->hw
;
2632 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
2633 struct qla_tgt_sess
*sess
= NULL
;
2634 struct atio_from_isp
*atio
= &cmd
->atio
;
2636 unsigned long flags
;
2637 uint32_t data_length
;
2638 int ret
, fcp_task_attr
, data_dir
, bidi
= 0;
2643 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2644 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
2645 atio
->u
.isp24
.fcp_hdr
.s_id
);
2646 /* Do kref_get() before dropping qla_hw_data->hardware_lock. */
2648 kref_get(&sess
->se_sess
->sess_kref
);
2649 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2651 if (unlikely(!sess
)) {
2652 uint8_t *s_id
= atio
->u
.isp24
.fcp_hdr
.s_id
;
2654 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf022,
2655 "qla_target(%d): Unable to find wwn login"
2656 " (s_id %x:%x:%x), trying to create it manually\n",
2657 vha
->vp_idx
, s_id
[0], s_id
[1], s_id
[2]);
2659 if (atio
->u
.raw
.entry_count
> 1) {
2660 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf023,
2661 "Dropping multy entry cmd %p\n", cmd
);
2665 mutex_lock(&ha
->tgt
.tgt_mutex
);
2666 sess
= qlt_make_local_sess(vha
, s_id
);
2667 /* sess has an extra creation ref. */
2668 mutex_unlock(&ha
->tgt
.tgt_mutex
);
2675 cmd
->loop_id
= sess
->loop_id
;
2676 cmd
->conf_compl_supported
= sess
->conf_compl_supported
;
2678 cdb
= &atio
->u
.isp24
.fcp_cmnd
.cdb
[0];
2679 cmd
->tag
= atio
->u
.isp24
.exchange_addr
;
2680 cmd
->unpacked_lun
= scsilun_to_int(
2681 (struct scsi_lun
*)&atio
->u
.isp24
.fcp_cmnd
.lun
);
2683 if (atio
->u
.isp24
.fcp_cmnd
.rddata
&&
2684 atio
->u
.isp24
.fcp_cmnd
.wrdata
) {
2686 data_dir
= DMA_TO_DEVICE
;
2687 } else if (atio
->u
.isp24
.fcp_cmnd
.rddata
)
2688 data_dir
= DMA_FROM_DEVICE
;
2689 else if (atio
->u
.isp24
.fcp_cmnd
.wrdata
)
2690 data_dir
= DMA_TO_DEVICE
;
2692 data_dir
= DMA_NONE
;
2694 fcp_task_attr
= qlt_get_fcp_task_attr(vha
,
2695 atio
->u
.isp24
.fcp_cmnd
.task_attr
);
2696 data_length
= be32_to_cpu(get_unaligned((uint32_t *)
2697 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
2698 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]));
2700 ql_dbg(ql_dbg_tgt
, vha
, 0xe022,
2701 "qla_target: START qla command: %p lun: 0x%04x (tag %d)\n",
2702 cmd
, cmd
->unpacked_lun
, cmd
->tag
);
2704 ret
= vha
->hw
->tgt
.tgt_ops
->handle_cmd(vha
, cmd
, cdb
, data_length
,
2705 fcp_task_attr
, data_dir
, bidi
);
2709 * Drop extra session reference from qla_tgt_handle_cmd_for_atio*(
2711 ha
->tgt
.tgt_ops
->put_sess(sess
);
2715 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf020, "Terminating work cmd %p", cmd
);
2717 * cmd has not sent to target yet, so pass NULL as the second
2718 * argument to qlt_send_term_exchange() and free the memory here.
2720 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2721 qlt_send_term_exchange(vha
, NULL
, &cmd
->atio
, 1);
2722 kmem_cache_free(qla_tgt_cmd_cachep
, cmd
);
2723 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2725 ha
->tgt
.tgt_ops
->put_sess(sess
);
2728 /* ha->hardware_lock supposed to be held on entry */
2729 static int qlt_handle_cmd_for_atio(struct scsi_qla_host
*vha
,
2730 struct atio_from_isp
*atio
)
2732 struct qla_hw_data
*ha
= vha
->hw
;
2733 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
2734 struct qla_tgt_cmd
*cmd
;
2736 if (unlikely(tgt
->tgt_stop
)) {
2737 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf021,
2738 "New command while device %p is shutting down\n", tgt
);
2742 cmd
= kmem_cache_zalloc(qla_tgt_cmd_cachep
, GFP_ATOMIC
);
2744 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05e,
2745 "qla_target(%d): Allocation of cmd failed\n", vha
->vp_idx
);
2749 INIT_LIST_HEAD(&cmd
->cmd_list
);
2751 memcpy(&cmd
->atio
, atio
, sizeof(*atio
));
2752 cmd
->state
= QLA_TGT_STATE_NEW
;
2753 cmd
->tgt
= ha
->tgt
.qla_tgt
;
2756 INIT_WORK(&cmd
->work
, qlt_do_work
);
2757 queue_work(qla_tgt_wq
, &cmd
->work
);
2762 /* ha->hardware_lock supposed to be held on entry */
2763 static int qlt_issue_task_mgmt(struct qla_tgt_sess
*sess
, uint32_t lun
,
2764 int fn
, void *iocb
, int flags
)
2766 struct scsi_qla_host
*vha
= sess
->vha
;
2767 struct qla_hw_data
*ha
= vha
->hw
;
2768 struct qla_tgt_mgmt_cmd
*mcmd
;
2772 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
2774 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10009,
2775 "qla_target(%d): Allocation of management "
2776 "command failed, some commands and their data could "
2777 "leak\n", vha
->vp_idx
);
2780 memset(mcmd
, 0, sizeof(*mcmd
));
2784 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
2785 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
2787 mcmd
->tmr_func
= fn
;
2788 mcmd
->flags
= flags
;
2791 case QLA_TGT_CLEAR_ACA
:
2792 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10000,
2793 "qla_target(%d): CLEAR_ACA received\n", sess
->vha
->vp_idx
);
2794 tmr_func
= TMR_CLEAR_ACA
;
2797 case QLA_TGT_TARGET_RESET
:
2798 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10001,
2799 "qla_target(%d): TARGET_RESET received\n",
2801 tmr_func
= TMR_TARGET_WARM_RESET
;
2804 case QLA_TGT_LUN_RESET
:
2805 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10002,
2806 "qla_target(%d): LUN_RESET received\n", sess
->vha
->vp_idx
);
2807 tmr_func
= TMR_LUN_RESET
;
2810 case QLA_TGT_CLEAR_TS
:
2811 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10003,
2812 "qla_target(%d): CLEAR_TS received\n", sess
->vha
->vp_idx
);
2813 tmr_func
= TMR_CLEAR_TASK_SET
;
2816 case QLA_TGT_ABORT_TS
:
2817 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10004,
2818 "qla_target(%d): ABORT_TS received\n", sess
->vha
->vp_idx
);
2819 tmr_func
= TMR_ABORT_TASK_SET
;
2822 case QLA_TGT_ABORT_ALL
:
2823 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10005,
2824 "qla_target(%d): Doing ABORT_ALL_TASKS\n",
2829 case QLA_TGT_ABORT_ALL_SESS
:
2830 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10006,
2831 "qla_target(%d): Doing ABORT_ALL_TASKS_SESS\n",
2836 case QLA_TGT_NEXUS_LOSS_SESS
:
2837 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10007,
2838 "qla_target(%d): Doing NEXUS_LOSS_SESS\n",
2843 case QLA_TGT_NEXUS_LOSS
:
2844 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10008,
2845 "qla_target(%d): Doing NEXUS_LOSS\n", sess
->vha
->vp_idx
);
2850 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000a,
2851 "qla_target(%d): Unknown task mgmt fn 0x%x\n",
2852 sess
->vha
->vp_idx
, fn
);
2853 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2857 res
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, lun
, tmr_func
, 0);
2859 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000b,
2860 "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n",
2861 sess
->vha
->vp_idx
, res
);
2862 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2869 /* ha->hardware_lock supposed to be held on entry */
2870 static int qlt_handle_task_mgmt(struct scsi_qla_host
*vha
, void *iocb
)
2872 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
2873 struct qla_hw_data
*ha
= vha
->hw
;
2874 struct qla_tgt
*tgt
;
2875 struct qla_tgt_sess
*sess
;
2876 uint32_t lun
, unpacked_lun
;
2879 tgt
= ha
->tgt
.qla_tgt
;
2881 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
2882 lun_size
= sizeof(a
->u
.isp24
.fcp_cmnd
.lun
);
2883 fn
= a
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
;
2884 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
2885 a
->u
.isp24
.fcp_hdr
.s_id
);
2886 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
2889 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf024,
2890 "qla_target(%d): task mgmt fn 0x%x for "
2891 "non-existant session\n", vha
->vp_idx
, fn
);
2892 return qlt_sched_sess_work(tgt
, QLA_TGT_SESS_WORK_TM
, iocb
,
2893 sizeof(struct atio_from_isp
));
2896 return qlt_issue_task_mgmt(sess
, unpacked_lun
, fn
, iocb
, 0);
2899 /* ha->hardware_lock supposed to be held on entry */
2900 static int __qlt_abort_task(struct scsi_qla_host
*vha
,
2901 struct imm_ntfy_from_isp
*iocb
, struct qla_tgt_sess
*sess
)
2903 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
2904 struct qla_hw_data
*ha
= vha
->hw
;
2905 struct qla_tgt_mgmt_cmd
*mcmd
;
2906 uint32_t lun
, unpacked_lun
;
2909 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
2911 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05f,
2912 "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
2913 vha
->vp_idx
, __func__
);
2916 memset(mcmd
, 0, sizeof(*mcmd
));
2919 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
2920 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
2922 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
2923 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
2925 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, unpacked_lun
, TMR_ABORT_TASK
,
2926 le16_to_cpu(iocb
->u
.isp2x
.seq_id
));
2928 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf060,
2929 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
2931 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2938 /* ha->hardware_lock supposed to be held on entry */
2939 static int qlt_abort_task(struct scsi_qla_host
*vha
,
2940 struct imm_ntfy_from_isp
*iocb
)
2942 struct qla_hw_data
*ha
= vha
->hw
;
2943 struct qla_tgt_sess
*sess
;
2946 loop_id
= GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
);
2948 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
2950 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf025,
2951 "qla_target(%d): task abort for unexisting "
2952 "session\n", vha
->vp_idx
);
2953 return qlt_sched_sess_work(ha
->tgt
.qla_tgt
,
2954 QLA_TGT_SESS_WORK_ABORT
, iocb
, sizeof(*iocb
));
2957 return __qlt_abort_task(vha
, iocb
, sess
);
2961 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2963 static int qlt_24xx_handle_els(struct scsi_qla_host
*vha
,
2964 struct imm_ntfy_from_isp
*iocb
)
2966 struct qla_hw_data
*ha
= vha
->hw
;
2969 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf026,
2970 "qla_target(%d): Port ID: 0x%02x:%02x:%02x"
2971 " ELS opcode: 0x%02x\n", vha
->vp_idx
, iocb
->u
.isp24
.port_id
[0],
2972 iocb
->u
.isp24
.port_id
[1], iocb
->u
.isp24
.port_id
[2],
2973 iocb
->u
.isp24
.status_subcode
);
2975 switch (iocb
->u
.isp24
.status_subcode
) {
2981 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
2986 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
2987 if (tgt
->link_reinit_iocb_pending
) {
2988 qlt_send_notify_ack(vha
, &tgt
->link_reinit_iocb
,
2990 tgt
->link_reinit_iocb_pending
= 0;
2992 res
= 1; /* send notify ack */
2997 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf061,
2998 "qla_target(%d): Unsupported ELS command %x "
2999 "received\n", vha
->vp_idx
, iocb
->u
.isp24
.status_subcode
);
3000 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
3007 static int qlt_set_data_offset(struct qla_tgt_cmd
*cmd
, uint32_t offset
)
3009 struct scatterlist
*sg
, *sgp
, *sg_srr
, *sg_srr_start
= NULL
;
3010 size_t first_offset
= 0, rem_offset
= offset
, tmp
= 0;
3011 int i
, sg_srr_cnt
, bufflen
= 0;
3013 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe023,
3014 "Entering qla_tgt_set_data_offset: cmd: %p, cmd->sg: %p, "
3015 "cmd->sg_cnt: %u, direction: %d\n",
3016 cmd
, cmd
->sg
, cmd
->sg_cnt
, cmd
->dma_data_direction
);
3019 * FIXME: Reject non zero SRR relative offset until we can test
3020 * this code properly.
3022 pr_debug("Rejecting non zero SRR rel_offs: %u\n", offset
);
3025 if (!cmd
->sg
|| !cmd
->sg_cnt
) {
3026 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe055,
3027 "Missing cmd->sg or zero cmd->sg_cnt in"
3028 " qla_tgt_set_data_offset\n");
3032 * Walk the current cmd->sg list until we locate the new sg_srr_start
3034 for_each_sg(cmd
->sg
, sg
, cmd
->sg_cnt
, i
) {
3035 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe024,
3036 "sg[%d]: %p page: %p, length: %d, offset: %d\n",
3037 i
, sg
, sg_page(sg
), sg
->length
, sg
->offset
);
3039 if ((sg
->length
+ tmp
) > offset
) {
3040 first_offset
= rem_offset
;
3042 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe025,
3043 "Found matching sg[%d], using %p as sg_srr_start, "
3044 "and using first_offset: %zu\n", i
, sg
,
3049 rem_offset
-= sg
->length
;
3052 if (!sg_srr_start
) {
3053 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe056,
3054 "Unable to locate sg_srr_start for offset: %u\n", offset
);
3057 sg_srr_cnt
= (cmd
->sg_cnt
- i
);
3059 sg_srr
= kzalloc(sizeof(struct scatterlist
) * sg_srr_cnt
, GFP_KERNEL
);
3061 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe057,
3062 "Unable to allocate sgp\n");
3065 sg_init_table(sg_srr
, sg_srr_cnt
);
3068 * Walk the remaining list for sg_srr_start, mapping to the newly
3069 * allocated sg_srr taking first_offset into account.
3071 for_each_sg(sg_srr_start
, sg
, sg_srr_cnt
, i
) {
3073 sg_set_page(sgp
, sg_page(sg
),
3074 (sg
->length
- first_offset
), first_offset
);
3077 sg_set_page(sgp
, sg_page(sg
), sg
->length
, 0);
3079 bufflen
+= sgp
->length
;
3087 cmd
->sg_cnt
= sg_srr_cnt
;
3088 cmd
->bufflen
= bufflen
;
3089 cmd
->offset
+= offset
;
3092 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe026, "New cmd->sg: %p\n", cmd
->sg
);
3093 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe027, "New cmd->sg_cnt: %u\n",
3095 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe028, "New cmd->bufflen: %u\n",
3097 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe029, "New cmd->offset: %u\n",
3100 if (cmd
->sg_cnt
< 0)
3103 if (cmd
->bufflen
< 0)
3109 static inline int qlt_srr_adjust_data(struct qla_tgt_cmd
*cmd
,
3110 uint32_t srr_rel_offs
, int *xmit_type
)
3112 int res
= 0, rel_offs
;
3114 rel_offs
= srr_rel_offs
- cmd
->offset
;
3115 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf027, "srr_rel_offs=%d, rel_offs=%d",
3116 srr_rel_offs
, rel_offs
);
3118 *xmit_type
= QLA_TGT_XMIT_ALL
;
3121 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf062,
3122 "qla_target(%d): SRR rel_offs (%d) < 0",
3123 cmd
->vha
->vp_idx
, rel_offs
);
3125 } else if (rel_offs
== cmd
->bufflen
)
3126 *xmit_type
= QLA_TGT_XMIT_STATUS
;
3127 else if (rel_offs
> 0)
3128 res
= qlt_set_data_offset(cmd
, rel_offs
);
3133 /* No locks, thread context */
3134 static void qlt_handle_srr(struct scsi_qla_host
*vha
,
3135 struct qla_tgt_srr_ctio
*sctio
, struct qla_tgt_srr_imm
*imm
)
3137 struct imm_ntfy_from_isp
*ntfy
=
3138 (struct imm_ntfy_from_isp
*)&imm
->imm_ntfy
;
3139 struct qla_hw_data
*ha
= vha
->hw
;
3140 struct qla_tgt_cmd
*cmd
= sctio
->cmd
;
3141 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
3142 unsigned long flags
;
3143 int xmit_type
= 0, resp
= 0;
3147 offset
= le32_to_cpu(ntfy
->u
.isp24
.srr_rel_offs
);
3148 srr_ui
= ntfy
->u
.isp24
.srr_ui
;
3150 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf028, "SRR cmd %p, srr_ui %x\n",
3155 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3156 qlt_send_notify_ack(vha
, ntfy
,
3157 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT
, 0, 0);
3158 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3159 xmit_type
= QLA_TGT_XMIT_STATUS
;
3162 case SRR_IU_DATA_IN
:
3163 if (!cmd
->sg
|| !cmd
->sg_cnt
) {
3164 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf063,
3165 "Unable to process SRR_IU_DATA_IN due to"
3166 " missing cmd->sg, state: %d\n", cmd
->state
);
3170 if (se_cmd
->scsi_status
!= 0) {
3171 ql_dbg(ql_dbg_tgt
, vha
, 0xe02a,
3172 "Rejecting SRR_IU_DATA_IN with non GOOD "
3176 cmd
->bufflen
= se_cmd
->data_length
;
3178 if (qlt_has_data(cmd
)) {
3179 if (qlt_srr_adjust_data(cmd
, offset
, &xmit_type
) != 0)
3181 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3182 qlt_send_notify_ack(vha
, ntfy
,
3183 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT
, 0, 0);
3184 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3187 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf064,
3188 "qla_target(%d): SRR for in data for cmd "
3189 "without them (tag %d, SCSI status %d), "
3190 "reject", vha
->vp_idx
, cmd
->tag
,
3191 cmd
->se_cmd
.scsi_status
);
3195 case SRR_IU_DATA_OUT
:
3196 if (!cmd
->sg
|| !cmd
->sg_cnt
) {
3197 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf065,
3198 "Unable to process SRR_IU_DATA_OUT due to"
3199 " missing cmd->sg\n");
3203 if (se_cmd
->scsi_status
!= 0) {
3204 ql_dbg(ql_dbg_tgt
, vha
, 0xe02b,
3205 "Rejecting SRR_IU_DATA_OUT"
3206 " with non GOOD scsi_status\n");
3209 cmd
->bufflen
= se_cmd
->data_length
;
3211 if (qlt_has_data(cmd
)) {
3212 if (qlt_srr_adjust_data(cmd
, offset
, &xmit_type
) != 0)
3214 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3215 qlt_send_notify_ack(vha
, ntfy
,
3216 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT
, 0, 0);
3217 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3218 if (xmit_type
& QLA_TGT_XMIT_DATA
)
3219 qlt_rdy_to_xfer(cmd
);
3221 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf066,
3222 "qla_target(%d): SRR for out data for cmd "
3223 "without them (tag %d, SCSI status %d), "
3224 "reject", vha
->vp_idx
, cmd
->tag
,
3225 cmd
->se_cmd
.scsi_status
);
3230 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf067,
3231 "qla_target(%d): Unknown srr_ui value %x",
3232 vha
->vp_idx
, srr_ui
);
3236 /* Transmit response in case of status and data-in cases */
3238 qlt_xmit_response(cmd
, xmit_type
, se_cmd
->scsi_status
);
3243 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3244 qlt_send_notify_ack(vha
, ntfy
, 0, 0, 0,
3245 NOTIFY_ACK_SRR_FLAGS_REJECT
,
3246 NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM
,
3247 NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL
);
3248 if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
3249 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3252 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 1);
3253 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3256 static void qlt_reject_free_srr_imm(struct scsi_qla_host
*vha
,
3257 struct qla_tgt_srr_imm
*imm
, int ha_locked
)
3259 struct qla_hw_data
*ha
= vha
->hw
;
3260 unsigned long flags
= 0;
3263 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3265 qlt_send_notify_ack(vha
, (void *)&imm
->imm_ntfy
, 0, 0, 0,
3266 NOTIFY_ACK_SRR_FLAGS_REJECT
,
3267 NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM
,
3268 NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL
);
3271 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3276 static void qlt_handle_srr_work(struct work_struct
*work
)
3278 struct qla_tgt
*tgt
= container_of(work
, struct qla_tgt
, srr_work
);
3279 struct scsi_qla_host
*vha
= tgt
->vha
;
3280 struct qla_tgt_srr_ctio
*sctio
;
3281 unsigned long flags
;
3283 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf029, "Entering SRR work (tgt %p)\n",
3287 spin_lock_irqsave(&tgt
->srr_lock
, flags
);
3288 list_for_each_entry(sctio
, &tgt
->srr_ctio_list
, srr_list_entry
) {
3289 struct qla_tgt_srr_imm
*imm
, *i
, *ti
;
3290 struct qla_tgt_cmd
*cmd
;
3291 struct se_cmd
*se_cmd
;
3294 list_for_each_entry_safe(i
, ti
, &tgt
->srr_imm_list
,
3296 if (i
->srr_id
== sctio
->srr_id
) {
3297 list_del(&i
->srr_list_entry
);
3299 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf068,
3300 "qla_target(%d): There must be "
3301 "only one IMM SRR per CTIO SRR "
3302 "(IMM SRR %p, id %d, CTIO %p\n",
3303 vha
->vp_idx
, i
, i
->srr_id
, sctio
);
3304 qlt_reject_free_srr_imm(tgt
->vha
, i
, 0);
3310 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02a,
3311 "IMM SRR %p, CTIO SRR %p (id %d)\n", imm
, sctio
,
3315 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02b,
3316 "Not found matching IMM for SRR CTIO (id %d)\n",
3320 list_del(&sctio
->srr_list_entry
);
3322 spin_unlock_irqrestore(&tgt
->srr_lock
, flags
);
3326 * Reset qla_tgt_cmd SRR values and SGL pointer+count to follow
3327 * tcm_qla2xxx_write_pending() and tcm_qla2xxx_queue_data_in()
3336 se_cmd
= &cmd
->se_cmd
;
3338 cmd
->sg_cnt
= se_cmd
->t_data_nents
;
3339 cmd
->sg
= se_cmd
->t_data_sg
;
3341 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02c,
3342 "SRR cmd %p (se_cmd %p, tag %d, op %x), "
3343 "sg_cnt=%d, offset=%d", cmd
, &cmd
->se_cmd
, cmd
->tag
,
3344 se_cmd
->t_task_cdb
[0], cmd
->sg_cnt
, cmd
->offset
);
3346 qlt_handle_srr(vha
, sctio
, imm
);
3352 spin_unlock_irqrestore(&tgt
->srr_lock
, flags
);
3355 /* ha->hardware_lock supposed to be held on entry */
3356 static void qlt_prepare_srr_imm(struct scsi_qla_host
*vha
,
3357 struct imm_ntfy_from_isp
*iocb
)
3359 struct qla_tgt_srr_imm
*imm
;
3360 struct qla_hw_data
*ha
= vha
->hw
;
3361 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
3362 struct qla_tgt_srr_ctio
*sctio
;
3366 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02d, "qla_target(%d): SRR received\n",
3369 imm
= kzalloc(sizeof(*imm
), GFP_ATOMIC
);
3371 memcpy(&imm
->imm_ntfy
, iocb
, sizeof(imm
->imm_ntfy
));
3373 /* IRQ is already OFF */
3374 spin_lock(&tgt
->srr_lock
);
3375 imm
->srr_id
= tgt
->imm_srr_id
;
3376 list_add_tail(&imm
->srr_list_entry
,
3377 &tgt
->srr_imm_list
);
3378 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02e,
3379 "IMM NTFY SRR %p added (id %d, ui %x)\n",
3380 imm
, imm
->srr_id
, iocb
->u
.isp24
.srr_ui
);
3381 if (tgt
->imm_srr_id
== tgt
->ctio_srr_id
) {
3383 list_for_each_entry(sctio
, &tgt
->srr_ctio_list
,
3385 if (sctio
->srr_id
== imm
->srr_id
) {
3391 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02f, "%s",
3392 "Scheduling srr work\n");
3393 schedule_work(&tgt
->srr_work
);
3395 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf030,
3396 "qla_target(%d): imm_srr_id "
3397 "== ctio_srr_id (%d), but there is no "
3398 "corresponding SRR CTIO, deleting IMM "
3399 "SRR %p\n", vha
->vp_idx
, tgt
->ctio_srr_id
,
3401 list_del(&imm
->srr_list_entry
);
3405 spin_unlock(&tgt
->srr_lock
);
3409 spin_unlock(&tgt
->srr_lock
);
3411 struct qla_tgt_srr_ctio
*ts
;
3413 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf069,
3414 "qla_target(%d): Unable to allocate SRR IMM "
3415 "entry, SRR request will be rejected\n", vha
->vp_idx
);
3417 /* IRQ is already OFF */
3418 spin_lock(&tgt
->srr_lock
);
3419 list_for_each_entry_safe(sctio
, ts
, &tgt
->srr_ctio_list
,
3421 if (sctio
->srr_id
== tgt
->imm_srr_id
) {
3422 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf031,
3423 "CTIO SRR %p deleted (id %d)\n",
3424 sctio
, sctio
->srr_id
);
3425 list_del(&sctio
->srr_list_entry
);
3426 qlt_send_term_exchange(vha
, sctio
->cmd
,
3427 &sctio
->cmd
->atio
, 1);
3431 spin_unlock(&tgt
->srr_lock
);
3438 qlt_send_notify_ack(vha
, iocb
, 0, 0, 0,
3439 NOTIFY_ACK_SRR_FLAGS_REJECT
,
3440 NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM
,
3441 NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL
);
3445 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3447 static void qlt_handle_imm_notify(struct scsi_qla_host
*vha
,
3448 struct imm_ntfy_from_isp
*iocb
)
3450 struct qla_hw_data
*ha
= vha
->hw
;
3451 uint32_t add_flags
= 0;
3452 int send_notify_ack
= 1;
3455 status
= le16_to_cpu(iocb
->u
.isp2x
.status
);
3457 case IMM_NTFY_LIP_RESET
:
3459 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf032,
3460 "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
3461 vha
->vp_idx
, le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
3462 iocb
->u
.isp24
.status_subcode
);
3464 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
3465 send_notify_ack
= 0;
3469 case IMM_NTFY_LIP_LINK_REINIT
:
3471 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
3472 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf033,
3473 "qla_target(%d): LINK REINIT (loop %#x, "
3474 "subcode %x)\n", vha
->vp_idx
,
3475 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
3476 iocb
->u
.isp24
.status_subcode
);
3477 if (tgt
->link_reinit_iocb_pending
) {
3478 qlt_send_notify_ack(vha
, &tgt
->link_reinit_iocb
,
3481 memcpy(&tgt
->link_reinit_iocb
, iocb
, sizeof(*iocb
));
3482 tgt
->link_reinit_iocb_pending
= 1;
3484 * QLogic requires to wait after LINK REINIT for possible
3485 * PDISC or ADISC ELS commands
3487 send_notify_ack
= 0;
3491 case IMM_NTFY_PORT_LOGOUT
:
3492 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf034,
3493 "qla_target(%d): Port logout (loop "
3494 "%#x, subcode %x)\n", vha
->vp_idx
,
3495 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
3496 iocb
->u
.isp24
.status_subcode
);
3498 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
) == 0)
3499 send_notify_ack
= 0;
3500 /* The sessions will be cleared in the callback, if needed */
3503 case IMM_NTFY_GLBL_TPRLO
:
3504 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf035,
3505 "qla_target(%d): Global TPRLO (%x)\n", vha
->vp_idx
, status
);
3506 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
3507 send_notify_ack
= 0;
3508 /* The sessions will be cleared in the callback, if needed */
3511 case IMM_NTFY_PORT_CONFIG
:
3512 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf036,
3513 "qla_target(%d): Port config changed (%x)\n", vha
->vp_idx
,
3515 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
3516 send_notify_ack
= 0;
3517 /* The sessions will be cleared in the callback, if needed */
3520 case IMM_NTFY_GLBL_LOGO
:
3521 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06a,
3522 "qla_target(%d): Link failure detected\n",
3524 /* I_T nexus loss */
3525 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
3526 send_notify_ack
= 0;
3529 case IMM_NTFY_IOCB_OVERFLOW
:
3530 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06b,
3531 "qla_target(%d): Cannot provide requested "
3532 "capability (IOCB overflowed the immediate notify "
3533 "resource count)\n", vha
->vp_idx
);
3536 case IMM_NTFY_ABORT_TASK
:
3537 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf037,
3538 "qla_target(%d): Abort Task (S %08x I %#x -> "
3539 "L %#x)\n", vha
->vp_idx
,
3540 le16_to_cpu(iocb
->u
.isp2x
.seq_id
),
3541 GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
),
3542 le16_to_cpu(iocb
->u
.isp2x
.lun
));
3543 if (qlt_abort_task(vha
, iocb
) == 0)
3544 send_notify_ack
= 0;
3547 case IMM_NTFY_RESOURCE
:
3548 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06c,
3549 "qla_target(%d): Out of resources, host %ld\n",
3550 vha
->vp_idx
, vha
->host_no
);
3553 case IMM_NTFY_MSG_RX
:
3554 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf038,
3555 "qla_target(%d): Immediate notify task %x\n",
3556 vha
->vp_idx
, iocb
->u
.isp2x
.task_flags
);
3557 if (qlt_handle_task_mgmt(vha
, iocb
) == 0)
3558 send_notify_ack
= 0;
3562 if (qlt_24xx_handle_els(vha
, iocb
) == 0)
3563 send_notify_ack
= 0;
3567 qlt_prepare_srr_imm(vha
, iocb
);
3568 send_notify_ack
= 0;
3572 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06d,
3573 "qla_target(%d): Received unknown immediate "
3574 "notify status %x\n", vha
->vp_idx
, status
);
3578 if (send_notify_ack
)
3579 qlt_send_notify_ack(vha
, iocb
, add_flags
, 0, 0, 0, 0, 0);
3583 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3584 * This function sends busy to ISP 2xxx or 24xx.
3586 static void qlt_send_busy(struct scsi_qla_host
*vha
,
3587 struct atio_from_isp
*atio
, uint16_t status
)
3589 struct ctio7_to_24xx
*ctio24
;
3590 struct qla_hw_data
*ha
= vha
->hw
;
3592 struct qla_tgt_sess
*sess
= NULL
;
3594 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
3595 atio
->u
.isp24
.fcp_hdr
.s_id
);
3597 qlt_send_term_exchange(vha
, NULL
, atio
, 1);
3600 /* Sending marker isn't necessary, since we called from ISR */
3602 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
3604 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06e,
3605 "qla_target(%d): %s failed: unable to allocate "
3606 "request packet", vha
->vp_idx
, __func__
);
3610 pkt
->entry_count
= 1;
3611 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
3613 ctio24
= (struct ctio7_to_24xx
*)pkt
;
3614 ctio24
->entry_type
= CTIO_TYPE7
;
3615 ctio24
->nport_handle
= sess
->loop_id
;
3616 ctio24
->timeout
= __constant_cpu_to_le16(QLA_TGT_TIMEOUT
);
3617 ctio24
->vp_index
= vha
->vp_idx
;
3618 ctio24
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
3619 ctio24
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
3620 ctio24
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
3621 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
3622 ctio24
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
3623 __constant_cpu_to_le16(
3624 CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
|
3625 CTIO7_FLAGS_DONT_RET_CTIO
);
3627 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
3628 * if the explicit conformation is used.
3630 ctio24
->u
.status1
.ox_id
= swab16(atio
->u
.isp24
.fcp_hdr
.ox_id
);
3631 ctio24
->u
.status1
.scsi_status
= cpu_to_le16(status
);
3632 ctio24
->u
.status1
.residual
= get_unaligned((uint32_t *)
3633 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
3634 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]);
3635 if (ctio24
->u
.status1
.residual
!= 0)
3636 ctio24
->u
.status1
.scsi_status
|= SS_RESIDUAL_UNDER
;
3638 qla2x00_start_iocbs(vha
, vha
->req
);
3641 /* ha->hardware_lock supposed to be held on entry */
3642 /* called via callback from qla2xxx */
3643 static void qlt_24xx_atio_pkt(struct scsi_qla_host
*vha
,
3644 struct atio_from_isp
*atio
)
3646 struct qla_hw_data
*ha
= vha
->hw
;
3647 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
3650 if (unlikely(tgt
== NULL
)) {
3651 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf039,
3652 "ATIO pkt, but no tgt (ha %p)", ha
);
3655 ql_dbg(ql_dbg_tgt
, vha
, 0xe02c,
3656 "qla_target(%d): ATIO pkt %p: type %02x count %02x",
3657 vha
->vp_idx
, atio
, atio
->u
.raw
.entry_type
,
3658 atio
->u
.raw
.entry_count
);
3660 * In tgt_stop mode we also should allow all requests to pass.
3661 * Otherwise, some commands can stuck.
3664 tgt
->irq_cmd_count
++;
3666 switch (atio
->u
.raw
.entry_type
) {
3668 ql_dbg(ql_dbg_tgt
, vha
, 0xe02d,
3669 "ATIO_TYPE7 instance %d, lun %Lx, read/write %d/%d, "
3670 "add_cdb_len %d, data_length %04x, s_id %x:%x:%x\n",
3671 vha
->vp_idx
, atio
->u
.isp24
.fcp_cmnd
.lun
,
3672 atio
->u
.isp24
.fcp_cmnd
.rddata
,
3673 atio
->u
.isp24
.fcp_cmnd
.wrdata
,
3674 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
,
3675 be32_to_cpu(get_unaligned((uint32_t *)
3676 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
3677 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
])),
3678 atio
->u
.isp24
.fcp_hdr
.s_id
[0],
3679 atio
->u
.isp24
.fcp_hdr
.s_id
[1],
3680 atio
->u
.isp24
.fcp_hdr
.s_id
[2]);
3682 if (unlikely(atio
->u
.isp24
.exchange_addr
==
3683 ATIO_EXCHANGE_ADDRESS_UNKNOWN
)) {
3684 ql_dbg(ql_dbg_tgt
, vha
, 0xe058,
3685 "qla_target(%d): ATIO_TYPE7 "
3686 "received with UNKNOWN exchange address, "
3687 "sending QUEUE_FULL\n", vha
->vp_idx
);
3688 qlt_send_busy(vha
, atio
, SAM_STAT_TASK_SET_FULL
);
3691 if (likely(atio
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
== 0))
3692 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
3694 rc
= qlt_handle_task_mgmt(vha
, atio
);
3695 if (unlikely(rc
!= 0)) {
3697 #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */
3698 qlt_send_busy(vha
, atio
, SAM_STAT_BUSY
);
3700 qlt_send_term_exchange(vha
, NULL
, atio
, 1);
3703 if (tgt
->tgt_stop
) {
3704 ql_dbg(ql_dbg_tgt
, vha
, 0xe059,
3705 "qla_target: Unable to send "
3706 "command to target for req, "
3709 ql_dbg(ql_dbg_tgt
, vha
, 0xe05a,
3710 "qla_target(%d): Unable to send "
3711 "command to target, sending BUSY "
3712 "status.\n", vha
->vp_idx
);
3713 qlt_send_busy(vha
, atio
, SAM_STAT_BUSY
);
3719 case IMMED_NOTIFY_TYPE
:
3721 if (unlikely(atio
->u
.isp2x
.entry_status
!= 0)) {
3722 ql_dbg(ql_dbg_tgt
, vha
, 0xe05b,
3723 "qla_target(%d): Received ATIO packet %x "
3724 "with error status %x\n", vha
->vp_idx
,
3725 atio
->u
.raw
.entry_type
,
3726 atio
->u
.isp2x
.entry_status
);
3729 ql_dbg(ql_dbg_tgt
, vha
, 0xe02e, "%s", "IMMED_NOTIFY ATIO");
3730 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)atio
);
3735 ql_dbg(ql_dbg_tgt
, vha
, 0xe05c,
3736 "qla_target(%d): Received unknown ATIO atio "
3737 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
3741 tgt
->irq_cmd_count
--;
3744 /* ha->hardware_lock supposed to be held on entry */
3745 /* called via callback from qla2xxx */
3746 static void qlt_response_pkt(struct scsi_qla_host
*vha
, response_t
*pkt
)
3748 struct qla_hw_data
*ha
= vha
->hw
;
3749 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
3751 if (unlikely(tgt
== NULL
)) {
3752 ql_dbg(ql_dbg_tgt
, vha
, 0xe05d,
3753 "qla_target(%d): Response pkt %x received, but no "
3754 "tgt (ha %p)\n", vha
->vp_idx
, pkt
->entry_type
, ha
);
3758 ql_dbg(ql_dbg_tgt
, vha
, 0xe02f,
3759 "qla_target(%d): response pkt %p: T %02x C %02x S %02x "
3760 "handle %#x\n", vha
->vp_idx
, pkt
, pkt
->entry_type
,
3761 pkt
->entry_count
, pkt
->entry_status
, pkt
->handle
);
3764 * In tgt_stop mode we also should allow all requests to pass.
3765 * Otherwise, some commands can stuck.
3768 tgt
->irq_cmd_count
++;
3770 switch (pkt
->entry_type
) {
3773 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
3774 ql_dbg(ql_dbg_tgt
, vha
, 0xe030, "CTIO_TYPE7: instance %d\n",
3776 qlt_do_ctio_completion(vha
, entry
->handle
,
3777 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
3782 case ACCEPT_TGT_IO_TYPE
:
3784 struct atio_from_isp
*atio
= (struct atio_from_isp
*)pkt
;
3786 ql_dbg(ql_dbg_tgt
, vha
, 0xe031,
3787 "ACCEPT_TGT_IO instance %d status %04x "
3788 "lun %04x read/write %d data_length %04x "
3789 "target_id %02x rx_id %04x\n ", vha
->vp_idx
,
3790 le16_to_cpu(atio
->u
.isp2x
.status
),
3791 le16_to_cpu(atio
->u
.isp2x
.lun
),
3792 atio
->u
.isp2x
.execution_codes
,
3793 le32_to_cpu(atio
->u
.isp2x
.data_length
), GET_TARGET_ID(ha
,
3794 atio
), atio
->u
.isp2x
.rx_id
);
3795 if (atio
->u
.isp2x
.status
!=
3796 __constant_cpu_to_le16(ATIO_CDB_VALID
)) {
3797 ql_dbg(ql_dbg_tgt
, vha
, 0xe05e,
3798 "qla_target(%d): ATIO with error "
3799 "status %x received\n", vha
->vp_idx
,
3800 le16_to_cpu(atio
->u
.isp2x
.status
));
3803 ql_dbg(ql_dbg_tgt
, vha
, 0xe032,
3804 "FCP CDB: 0x%02x, sizeof(cdb): %lu",
3805 atio
->u
.isp2x
.cdb
[0], (unsigned long
3806 int)sizeof(atio
->u
.isp2x
.cdb
));
3808 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
3809 if (unlikely(rc
!= 0)) {
3811 #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */
3812 qlt_send_busy(vha
, atio
, 0);
3814 qlt_send_term_exchange(vha
, NULL
, atio
, 1);
3817 if (tgt
->tgt_stop
) {
3818 ql_dbg(ql_dbg_tgt
, vha
, 0xe05f,
3819 "qla_target: Unable to send "
3820 "command to target, sending TERM "
3821 "EXCHANGE for rsp\n");
3822 qlt_send_term_exchange(vha
, NULL
,
3825 ql_dbg(ql_dbg_tgt
, vha
, 0xe060,
3826 "qla_target(%d): Unable to send "
3827 "command to target, sending BUSY "
3828 "status\n", vha
->vp_idx
);
3829 qlt_send_busy(vha
, atio
, 0);
3836 case CONTINUE_TGT_IO_TYPE
:
3838 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
3839 ql_dbg(ql_dbg_tgt
, vha
, 0xe033,
3840 "CONTINUE_TGT_IO: instance %d\n", vha
->vp_idx
);
3841 qlt_do_ctio_completion(vha
, entry
->handle
,
3842 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
3849 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
3850 ql_dbg(ql_dbg_tgt
, vha
, 0xe034, "CTIO_A64: instance %d\n",
3852 qlt_do_ctio_completion(vha
, entry
->handle
,
3853 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
3858 case IMMED_NOTIFY_TYPE
:
3859 ql_dbg(ql_dbg_tgt
, vha
, 0xe035, "%s", "IMMED_NOTIFY\n");
3860 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)pkt
);
3863 case NOTIFY_ACK_TYPE
:
3864 if (tgt
->notify_ack_expected
> 0) {
3865 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
3866 ql_dbg(ql_dbg_tgt
, vha
, 0xe036,
3867 "NOTIFY_ACK seq %08x status %x\n",
3868 le16_to_cpu(entry
->u
.isp2x
.seq_id
),
3869 le16_to_cpu(entry
->u
.isp2x
.status
));
3870 tgt
->notify_ack_expected
--;
3871 if (entry
->u
.isp2x
.status
!=
3872 __constant_cpu_to_le16(NOTIFY_ACK_SUCCESS
)) {
3873 ql_dbg(ql_dbg_tgt
, vha
, 0xe061,
3874 "qla_target(%d): NOTIFY_ACK "
3875 "failed %x\n", vha
->vp_idx
,
3876 le16_to_cpu(entry
->u
.isp2x
.status
));
3879 ql_dbg(ql_dbg_tgt
, vha
, 0xe062,
3880 "qla_target(%d): Unexpected NOTIFY_ACK received\n",
3885 case ABTS_RECV_24XX
:
3886 ql_dbg(ql_dbg_tgt
, vha
, 0xe037,
3887 "ABTS_RECV_24XX: instance %d\n", vha
->vp_idx
);
3888 qlt_24xx_handle_abts(vha
, (struct abts_recv_from_24xx
*)pkt
);
3891 case ABTS_RESP_24XX
:
3892 if (tgt
->abts_resp_expected
> 0) {
3893 struct abts_resp_from_24xx_fw
*entry
=
3894 (struct abts_resp_from_24xx_fw
*)pkt
;
3895 ql_dbg(ql_dbg_tgt
, vha
, 0xe038,
3896 "ABTS_RESP_24XX: compl_status %x\n",
3897 entry
->compl_status
);
3898 tgt
->abts_resp_expected
--;
3899 if (le16_to_cpu(entry
->compl_status
) !=
3900 ABTS_RESP_COMPL_SUCCESS
) {
3901 if ((entry
->error_subcode1
== 0x1E) &&
3902 (entry
->error_subcode2
== 0)) {
3904 * We've got a race here: aborted
3905 * exchange not terminated, i.e.
3906 * response for the aborted command was
3907 * sent between the abort request was
3908 * received and processed.
3909 * Unfortunately, the firmware has a
3910 * silly requirement that all aborted
3911 * exchanges must be explicitely
3912 * terminated, otherwise it refuses to
3913 * send responses for the abort
3914 * requests. So, we have to
3915 * (re)terminate the exchange and retry
3916 * the abort response.
3918 qlt_24xx_retry_term_exchange(vha
,
3921 ql_dbg(ql_dbg_tgt
, vha
, 0xe063,
3922 "qla_target(%d): ABTS_RESP_24XX "
3923 "failed %x (subcode %x:%x)",
3924 vha
->vp_idx
, entry
->compl_status
,
3925 entry
->error_subcode1
,
3926 entry
->error_subcode2
);
3929 ql_dbg(ql_dbg_tgt
, vha
, 0xe064,
3930 "qla_target(%d): Unexpected ABTS_RESP_24XX "
3931 "received\n", vha
->vp_idx
);
3936 ql_dbg(ql_dbg_tgt
, vha
, 0xe065,
3937 "qla_target(%d): Received unknown response pkt "
3938 "type %x\n", vha
->vp_idx
, pkt
->entry_type
);
3942 tgt
->irq_cmd_count
--;
3946 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3948 void qlt_async_event(uint16_t code
, struct scsi_qla_host
*vha
,
3951 struct qla_hw_data
*ha
= vha
->hw
;
3952 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
3955 ql_dbg(ql_dbg_tgt
, vha
, 0xe039,
3956 "scsi(%ld): ha state %d init_done %d oper_mode %d topo %d\n",
3957 vha
->host_no
, atomic_read(&vha
->loop_state
), vha
->flags
.init_done
,
3958 ha
->operating_mode
, ha
->current_topology
);
3960 if (!ha
->tgt
.tgt_ops
)
3963 if (unlikely(tgt
== NULL
)) {
3964 ql_dbg(ql_dbg_tgt
, vha
, 0xe03a,
3965 "ASYNC EVENT %#x, but no tgt (ha %p)\n", code
, ha
);
3969 if (((code
== MBA_POINT_TO_POINT
) || (code
== MBA_CHG_IN_CONNECTION
)) &&
3973 * In tgt_stop mode we also should allow all requests to pass.
3974 * Otherwise, some commands can stuck.
3977 tgt
->irq_cmd_count
++;
3980 case MBA_RESET
: /* Reset */
3981 case MBA_SYSTEM_ERR
: /* System Error */
3982 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
3983 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
3984 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03a,
3985 "qla_target(%d): System error async event %#x "
3986 "occured", vha
->vp_idx
, code
);
3988 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up. */
3989 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3994 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03b,
3995 "qla_target(%d): Async LOOP_UP occured "
3996 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
,
3997 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
3998 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
3999 if (tgt
->link_reinit_iocb_pending
) {
4000 qlt_send_notify_ack(vha
, (void *)&tgt
->link_reinit_iocb
,
4002 tgt
->link_reinit_iocb_pending
= 0;
4007 case MBA_LIP_OCCURRED
:
4010 case MBA_RSCN_UPDATE
:
4011 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03c,
4012 "qla_target(%d): Async event %#x occured "
4013 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
4014 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
4015 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
4018 case MBA_PORT_UPDATE
:
4019 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03d,
4020 "qla_target(%d): Port update async event %#x "
4021 "occured: updating the ports database (m[0]=%x, m[1]=%x, "
4022 "m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
4023 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
4024 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
4026 login_code
= le16_to_cpu(mailbox
[2]);
4027 if (login_code
== 0x4)
4028 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03e,
4029 "Async MB 2: Got PLOGI Complete\n");
4030 else if (login_code
== 0x7)
4031 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03f,
4032 "Async MB 2: Port Logged Out\n");
4036 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf040,
4037 "qla_target(%d): Async event %#x occured: "
4038 "ignore (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
,
4039 code
, le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
4040 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
4044 tgt
->irq_cmd_count
--;
4047 static fc_port_t
*qlt_get_port_database(struct scsi_qla_host
*vha
,
4053 fcport
= kzalloc(sizeof(*fcport
), GFP_KERNEL
);
4055 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06f,
4056 "qla_target(%d): Allocation of tmp FC port failed",
4061 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf041, "loop_id %d", loop_id
);
4063 fcport
->loop_id
= loop_id
;
4065 rc
= qla2x00_get_port_database(vha
, fcport
, 0);
4066 if (rc
!= QLA_SUCCESS
) {
4067 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf070,
4068 "qla_target(%d): Failed to retrieve fcport "
4069 "information -- get_port_database() returned %x "
4070 "(loop_id=0x%04x)", vha
->vp_idx
, rc
, loop_id
);
4078 /* Must be called under tgt_mutex */
4079 static struct qla_tgt_sess
*qlt_make_local_sess(struct scsi_qla_host
*vha
,
4082 struct qla_hw_data
*ha
= vha
->hw
;
4083 struct qla_tgt_sess
*sess
= NULL
;
4084 fc_port_t
*fcport
= NULL
;
4085 int rc
, global_resets
;
4086 uint16_t loop_id
= 0;
4089 global_resets
= atomic_read(&ha
->tgt
.qla_tgt
->tgt_global_resets_count
);
4091 rc
= qla24xx_get_loop_id(vha
, s_id
, &loop_id
);
4093 if ((s_id
[0] == 0xFF) &&
4094 (s_id
[1] == 0xFC)) {
4096 * This is Domain Controller, so it should be
4097 * OK to drop SCSI commands from it.
4099 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf042,
4100 "Unable to find initiator with S_ID %x:%x:%x",
4101 s_id
[0], s_id
[1], s_id
[2]);
4103 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf071,
4104 "qla_target(%d): Unable to find "
4105 "initiator with S_ID %x:%x:%x",
4106 vha
->vp_idx
, s_id
[0], s_id
[1],
4111 fcport
= qlt_get_port_database(vha
, loop_id
);
4115 if (global_resets
!=
4116 atomic_read(&ha
->tgt
.qla_tgt
->tgt_global_resets_count
)) {
4117 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf043,
4118 "qla_target(%d): global reset during session discovery "
4119 "(counter was %d, new %d), retrying", vha
->vp_idx
,
4121 atomic_read(&ha
->tgt
.qla_tgt
->tgt_global_resets_count
));
4125 sess
= qlt_create_sess(vha
, fcport
, true);
4131 static void qlt_abort_work(struct qla_tgt
*tgt
,
4132 struct qla_tgt_sess_work_param
*prm
)
4134 struct scsi_qla_host
*vha
= tgt
->vha
;
4135 struct qla_hw_data
*ha
= vha
->hw
;
4136 struct qla_tgt_sess
*sess
= NULL
;
4137 unsigned long flags
;
4142 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4147 s_id
[0] = prm
->abts
.fcp_hdr_le
.s_id
[2];
4148 s_id
[1] = prm
->abts
.fcp_hdr_le
.s_id
[1];
4149 s_id
[2] = prm
->abts
.fcp_hdr_le
.s_id
[0];
4151 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
4152 (unsigned char *)&be_s_id
);
4154 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4156 mutex_lock(&ha
->tgt
.tgt_mutex
);
4157 sess
= qlt_make_local_sess(vha
, s_id
);
4158 /* sess has got an extra creation ref */
4159 mutex_unlock(&ha
->tgt
.tgt_mutex
);
4161 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4165 kref_get(&sess
->se_sess
->sess_kref
);
4171 rc
= __qlt_24xx_handle_abts(vha
, &prm
->abts
, sess
);
4174 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4176 ha
->tgt
.tgt_ops
->put_sess(sess
);
4180 qlt_24xx_send_abts_resp(vha
, &prm
->abts
, FCP_TMF_REJECTED
, false);
4181 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4183 ha
->tgt
.tgt_ops
->put_sess(sess
);
4186 static void qlt_tmr_work(struct qla_tgt
*tgt
,
4187 struct qla_tgt_sess_work_param
*prm
)
4189 struct atio_from_isp
*a
= &prm
->tm_iocb2
;
4190 struct scsi_qla_host
*vha
= tgt
->vha
;
4191 struct qla_hw_data
*ha
= vha
->hw
;
4192 struct qla_tgt_sess
*sess
= NULL
;
4193 unsigned long flags
;
4194 uint8_t *s_id
= NULL
; /* to hide compiler warnings */
4196 uint32_t lun
, unpacked_lun
;
4200 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4205 s_id
= prm
->tm_iocb2
.u
.isp24
.fcp_hdr
.s_id
;
4206 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
4208 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4210 mutex_lock(&ha
->tgt
.tgt_mutex
);
4211 sess
= qlt_make_local_sess(vha
, s_id
);
4212 /* sess has got an extra creation ref */
4213 mutex_unlock(&ha
->tgt
.tgt_mutex
);
4215 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4219 kref_get(&sess
->se_sess
->sess_kref
);
4223 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
4224 lun_size
= sizeof(lun
);
4225 fn
= a
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
;
4226 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
4228 rc
= qlt_issue_task_mgmt(sess
, unpacked_lun
, fn
, iocb
, 0);
4231 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4233 ha
->tgt
.tgt_ops
->put_sess(sess
);
4237 qlt_send_term_exchange(vha
, NULL
, &prm
->tm_iocb2
, 1);
4238 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4240 ha
->tgt
.tgt_ops
->put_sess(sess
);
4243 static void qlt_sess_work_fn(struct work_struct
*work
)
4245 struct qla_tgt
*tgt
= container_of(work
, struct qla_tgt
, sess_work
);
4246 struct scsi_qla_host
*vha
= tgt
->vha
;
4247 unsigned long flags
;
4249 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf000, "Sess work (tgt %p)", tgt
);
4251 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
4252 while (!list_empty(&tgt
->sess_works_list
)) {
4253 struct qla_tgt_sess_work_param
*prm
= list_entry(
4254 tgt
->sess_works_list
.next
, typeof(*prm
),
4255 sess_works_list_entry
);
4258 * This work can be scheduled on several CPUs at time, so we
4259 * must delete the entry to eliminate double processing
4261 list_del(&prm
->sess_works_list_entry
);
4263 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
4265 switch (prm
->type
) {
4266 case QLA_TGT_SESS_WORK_ABORT
:
4267 qlt_abort_work(tgt
, prm
);
4269 case QLA_TGT_SESS_WORK_TM
:
4270 qlt_tmr_work(tgt
, prm
);
4277 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
4281 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
4284 /* Must be called under tgt_host_action_mutex */
4285 int qlt_add_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*base_vha
)
4287 struct qla_tgt
*tgt
;
4289 if (!QLA_TGT_MODE_ENABLED())
4292 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe03b,
4293 "Registering target for host %ld(%p)", base_vha
->host_no
, ha
);
4295 BUG_ON((ha
->tgt
.qla_tgt
!= NULL
) || (ha
->tgt
.tgt_ops
!= NULL
));
4297 tgt
= kzalloc(sizeof(struct qla_tgt
), GFP_KERNEL
);
4299 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe066,
4300 "Unable to allocate struct qla_tgt\n");
4304 if (!(base_vha
->host
->hostt
->supported_mode
& MODE_TARGET
))
4305 base_vha
->host
->hostt
->supported_mode
|= MODE_TARGET
;
4308 tgt
->vha
= base_vha
;
4309 init_waitqueue_head(&tgt
->waitQ
);
4310 INIT_LIST_HEAD(&tgt
->sess_list
);
4311 INIT_LIST_HEAD(&tgt
->del_sess_list
);
4312 INIT_DELAYED_WORK(&tgt
->sess_del_work
,
4313 (void (*)(struct work_struct
*))qlt_del_sess_work_fn
);
4314 spin_lock_init(&tgt
->sess_work_lock
);
4315 INIT_WORK(&tgt
->sess_work
, qlt_sess_work_fn
);
4316 INIT_LIST_HEAD(&tgt
->sess_works_list
);
4317 spin_lock_init(&tgt
->srr_lock
);
4318 INIT_LIST_HEAD(&tgt
->srr_ctio_list
);
4319 INIT_LIST_HEAD(&tgt
->srr_imm_list
);
4320 INIT_WORK(&tgt
->srr_work
, qlt_handle_srr_work
);
4321 atomic_set(&tgt
->tgt_global_resets_count
, 0);
4323 ha
->tgt
.qla_tgt
= tgt
;
4325 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe067,
4326 "qla_target(%d): using 64 Bit PCI addressing",
4328 tgt
->tgt_enable_64bit_addr
= 1;
4330 tgt
->sg_tablesize
= QLA_TGT_MAX_SG_24XX(base_vha
->req
->length
- 3);
4331 tgt
->datasegs_per_cmd
= QLA_TGT_DATASEGS_PER_CMD_24XX
;
4332 tgt
->datasegs_per_cont
= QLA_TGT_DATASEGS_PER_CONT_24XX
;
4334 mutex_lock(&qla_tgt_mutex
);
4335 list_add_tail(&tgt
->tgt_list_entry
, &qla_tgt_glist
);
4336 mutex_unlock(&qla_tgt_mutex
);
4341 /* Must be called under tgt_host_action_mutex */
4342 int qlt_remove_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*vha
)
4344 if (!ha
->tgt
.qla_tgt
)
4347 mutex_lock(&qla_tgt_mutex
);
4348 list_del(&ha
->tgt
.qla_tgt
->tgt_list_entry
);
4349 mutex_unlock(&qla_tgt_mutex
);
4351 ql_dbg(ql_dbg_tgt
, vha
, 0xe03c, "Unregistering target for host %ld(%p)",
4353 qlt_release(ha
->tgt
.qla_tgt
);
4358 static void qlt_lport_dump(struct scsi_qla_host
*vha
, u64 wwpn
,
4363 pr_debug("qla2xxx HW vha->node_name: ");
4364 for (i
= 0; i
< WWN_SIZE
; i
++)
4365 pr_debug("%02x ", vha
->node_name
[i
]);
4367 pr_debug("qla2xxx HW vha->port_name: ");
4368 for (i
= 0; i
< WWN_SIZE
; i
++)
4369 pr_debug("%02x ", vha
->port_name
[i
]);
4372 pr_debug("qla2xxx passed configfs WWPN: ");
4373 put_unaligned_be64(wwpn
, b
);
4374 for (i
= 0; i
< WWN_SIZE
; i
++)
4375 pr_debug("%02x ", b
[i
]);
4380 * qla_tgt_lport_register - register lport with external module
4382 * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops
4383 * @wwpn: Passwd FC target WWPN
4384 * @callback: lport initialization callback for tcm_qla2xxx code
4385 * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
4387 int qlt_lport_register(struct qla_tgt_func_tmpl
*qla_tgt_ops
, u64 wwpn
,
4388 int (*callback
)(struct scsi_qla_host
*), void *target_lport_ptr
)
4390 struct qla_tgt
*tgt
;
4391 struct scsi_qla_host
*vha
;
4392 struct qla_hw_data
*ha
;
4393 struct Scsi_Host
*host
;
4394 unsigned long flags
;
4398 mutex_lock(&qla_tgt_mutex
);
4399 list_for_each_entry(tgt
, &qla_tgt_glist
, tgt_list_entry
) {
4407 if (ha
->tgt
.tgt_ops
!= NULL
)
4410 if (!(host
->hostt
->supported_mode
& MODE_TARGET
))
4413 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4414 if (host
->active_mode
& MODE_TARGET
) {
4415 pr_debug("MODE_TARGET already active on qla2xxx(%d)\n",
4417 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4420 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4422 if (!scsi_host_get(host
)) {
4423 ql_dbg(ql_dbg_tgt
, vha
, 0xe068,
4424 "Unable to scsi_host_get() for"
4425 " qla2xxx scsi_host\n");
4428 qlt_lport_dump(vha
, wwpn
, b
);
4430 if (memcmp(vha
->port_name
, b
, WWN_SIZE
)) {
4431 scsi_host_put(host
);
4435 * Setup passed parameters ahead of invoking callback
4437 ha
->tgt
.tgt_ops
= qla_tgt_ops
;
4438 ha
->tgt
.target_lport_ptr
= target_lport_ptr
;
4439 rc
= (*callback
)(vha
);
4441 ha
->tgt
.tgt_ops
= NULL
;
4442 ha
->tgt
.target_lport_ptr
= NULL
;
4444 mutex_unlock(&qla_tgt_mutex
);
4447 mutex_unlock(&qla_tgt_mutex
);
4451 EXPORT_SYMBOL(qlt_lport_register
);
4454 * qla_tgt_lport_deregister - Degister lport
4456 * @vha: Registered scsi_qla_host pointer
4458 void qlt_lport_deregister(struct scsi_qla_host
*vha
)
4460 struct qla_hw_data
*ha
= vha
->hw
;
4461 struct Scsi_Host
*sh
= vha
->host
;
4463 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
4465 ha
->tgt
.target_lport_ptr
= NULL
;
4466 ha
->tgt
.tgt_ops
= NULL
;
4468 * Release the Scsi_Host reference for the underlying qla2xxx host
4472 EXPORT_SYMBOL(qlt_lport_deregister
);
4474 /* Must be called under HW lock */
4475 void qlt_set_mode(struct scsi_qla_host
*vha
)
4477 struct qla_hw_data
*ha
= vha
->hw
;
4479 switch (ql2x_ini_mode
) {
4480 case QLA2XXX_INI_MODE_DISABLED
:
4481 case QLA2XXX_INI_MODE_EXCLUSIVE
:
4482 vha
->host
->active_mode
= MODE_TARGET
;
4484 case QLA2XXX_INI_MODE_ENABLED
:
4485 vha
->host
->active_mode
|= MODE_TARGET
;
4491 if (ha
->tgt
.ini_mode_force_reverse
)
4492 qla_reverse_ini_mode(vha
);
4495 /* Must be called under HW lock */
4496 void qlt_clear_mode(struct scsi_qla_host
*vha
)
4498 struct qla_hw_data
*ha
= vha
->hw
;
4500 switch (ql2x_ini_mode
) {
4501 case QLA2XXX_INI_MODE_DISABLED
:
4502 vha
->host
->active_mode
= MODE_UNKNOWN
;
4504 case QLA2XXX_INI_MODE_EXCLUSIVE
:
4505 vha
->host
->active_mode
= MODE_INITIATOR
;
4507 case QLA2XXX_INI_MODE_ENABLED
:
4508 vha
->host
->active_mode
&= ~MODE_TARGET
;
4514 if (ha
->tgt
.ini_mode_force_reverse
)
4515 qla_reverse_ini_mode(vha
);
4519 * qla_tgt_enable_vha - NO LOCK HELD
4521 * host_reset, bring up w/ Target Mode Enabled
4524 qlt_enable_vha(struct scsi_qla_host
*vha
)
4526 struct qla_hw_data
*ha
= vha
->hw
;
4527 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
4528 unsigned long flags
;
4531 ql_dbg(ql_dbg_tgt
, vha
, 0xe069,
4532 "Unable to locate qla_tgt pointer from"
4533 " struct qla_hw_data\n");
4538 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4539 tgt
->tgt_stopped
= 0;
4541 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4543 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
4544 qla2xxx_wake_dpc(vha
);
4545 qla2x00_wait_for_hba_online(vha
);
4547 EXPORT_SYMBOL(qlt_enable_vha
);
4550 * qla_tgt_disable_vha - NO LOCK HELD
4552 * Disable Target Mode and reset the adapter
4555 qlt_disable_vha(struct scsi_qla_host
*vha
)
4557 struct qla_hw_data
*ha
= vha
->hw
;
4558 struct qla_tgt
*tgt
= ha
->tgt
.qla_tgt
;
4559 unsigned long flags
;
4562 ql_dbg(ql_dbg_tgt
, vha
, 0xe06a,
4563 "Unable to locate qla_tgt pointer from"
4564 " struct qla_hw_data\n");
4569 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4570 qlt_clear_mode(vha
);
4571 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4573 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
4574 qla2xxx_wake_dpc(vha
);
4575 qla2x00_wait_for_hba_online(vha
);
4579 * Called from qla_init.c:qla24xx_vport_create() contex to setup
4580 * the target mode specific struct scsi_qla_host and struct qla_hw_data
4584 qlt_vport_create(struct scsi_qla_host
*vha
, struct qla_hw_data
*ha
)
4586 if (!qla_tgt_mode_enabled(vha
))
4589 mutex_init(&ha
->tgt
.tgt_mutex
);
4590 mutex_init(&ha
->tgt
.tgt_host_action_mutex
);
4592 qlt_clear_mode(vha
);
4595 * NOTE: Currently the value is kept the same for <24xx and
4596 * >=24xx ISPs. If it is necessary to change it,
4597 * the check should be added for specific ISPs,
4598 * assigning the value appropriately.
4600 ha
->tgt
.atio_q_length
= ATIO_ENTRY_CNT_24XX
;
4604 qlt_rff_id(struct scsi_qla_host
*vha
, struct ct_sns_req
*ct_req
)
4607 * FC-4 Feature bit 0 indicates target functionality to the name server.
4609 if (qla_tgt_mode_enabled(vha
)) {
4610 if (qla_ini_mode_enabled(vha
))
4611 ct_req
->req
.rff_id
.fc4_feature
= BIT_0
| BIT_1
;
4613 ct_req
->req
.rff_id
.fc4_feature
= BIT_0
;
4614 } else if (qla_ini_mode_enabled(vha
)) {
4615 ct_req
->req
.rff_id
.fc4_feature
= BIT_1
;
4620 * qlt_init_atio_q_entries() - Initializes ATIO queue entries.
4623 * Beginning of ATIO ring has initialization control block already built
4624 * by nvram config routine.
4626 * Returns 0 on success.
4629 qlt_init_atio_q_entries(struct scsi_qla_host
*vha
)
4631 struct qla_hw_data
*ha
= vha
->hw
;
4633 struct atio_from_isp
*pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring
;
4635 if (!qla_tgt_mode_enabled(vha
))
4638 for (cnt
= 0; cnt
< ha
->tgt
.atio_q_length
; cnt
++) {
4639 pkt
->u
.raw
.signature
= ATIO_PROCESSED
;
4646 * qlt_24xx_process_atio_queue() - Process ATIO queue entries.
4647 * @ha: SCSI driver HA context
4650 qlt_24xx_process_atio_queue(struct scsi_qla_host
*vha
)
4652 struct qla_hw_data
*ha
= vha
->hw
;
4653 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
4654 struct atio_from_isp
*pkt
;
4657 if (!vha
->flags
.online
)
4660 while (ha
->tgt
.atio_ring_ptr
->signature
!= ATIO_PROCESSED
) {
4661 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
4662 cnt
= pkt
->u
.raw
.entry_count
;
4664 qlt_24xx_atio_pkt_all_vps(vha
, (struct atio_from_isp
*)pkt
);
4666 for (i
= 0; i
< cnt
; i
++) {
4667 ha
->tgt
.atio_ring_index
++;
4668 if (ha
->tgt
.atio_ring_index
== ha
->tgt
.atio_q_length
) {
4669 ha
->tgt
.atio_ring_index
= 0;
4670 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
4672 ha
->tgt
.atio_ring_ptr
++;
4674 pkt
->u
.raw
.signature
= ATIO_PROCESSED
;
4675 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
4680 /* Adjust ring index */
4681 WRT_REG_DWORD(®
->atio_q_out
, ha
->tgt
.atio_ring_index
);
4685 qlt_24xx_config_rings(struct scsi_qla_host
*vha
, device_reg_t __iomem
*reg
)
4687 struct qla_hw_data
*ha
= vha
->hw
;
4689 /* FIXME: atio_q in/out for ha->mqenable=1..? */
4692 WRT_REG_DWORD(®
->isp25mq
.atio_q_in
, 0);
4693 WRT_REG_DWORD(®
->isp25mq
.atio_q_out
, 0);
4694 RD_REG_DWORD(®
->isp25mq
.atio_q_out
);
4697 /* Setup APTIO registers for target mode */
4698 WRT_REG_DWORD(®
->isp24
.atio_q_in
, 0);
4699 WRT_REG_DWORD(®
->isp24
.atio_q_out
, 0);
4700 RD_REG_DWORD(®
->isp24
.atio_q_out
);
4705 qlt_24xx_config_nvram_stage1(struct scsi_qla_host
*vha
, struct nvram_24xx
*nv
)
4707 struct qla_hw_data
*ha
= vha
->hw
;
4709 if (qla_tgt_mode_enabled(vha
)) {
4710 if (!ha
->tgt
.saved_set
) {
4711 /* We save only once */
4712 ha
->tgt
.saved_exchange_count
= nv
->exchange_count
;
4713 ha
->tgt
.saved_firmware_options_1
=
4714 nv
->firmware_options_1
;
4715 ha
->tgt
.saved_firmware_options_2
=
4716 nv
->firmware_options_2
;
4717 ha
->tgt
.saved_firmware_options_3
=
4718 nv
->firmware_options_3
;
4719 ha
->tgt
.saved_set
= 1;
4722 nv
->exchange_count
= __constant_cpu_to_le16(0xFFFF);
4724 /* Enable target mode */
4725 nv
->firmware_options_1
|= __constant_cpu_to_le32(BIT_4
);
4727 /* Disable ini mode, if requested */
4728 if (!qla_ini_mode_enabled(vha
))
4729 nv
->firmware_options_1
|= __constant_cpu_to_le32(BIT_5
);
4731 /* Disable Full Login after LIP */
4732 nv
->firmware_options_1
&= __constant_cpu_to_le32(~BIT_13
);
4733 /* Enable initial LIP */
4734 nv
->firmware_options_1
&= __constant_cpu_to_le32(~BIT_9
);
4735 /* Enable FC tapes support */
4736 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4737 /* Disable Full Login after LIP */
4738 nv
->host_p
&= __constant_cpu_to_le32(~BIT_10
);
4739 /* Enable target PRLI control */
4740 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_14
);
4742 if (ha
->tgt
.saved_set
) {
4743 nv
->exchange_count
= ha
->tgt
.saved_exchange_count
;
4744 nv
->firmware_options_1
=
4745 ha
->tgt
.saved_firmware_options_1
;
4746 nv
->firmware_options_2
=
4747 ha
->tgt
.saved_firmware_options_2
;
4748 nv
->firmware_options_3
=
4749 ha
->tgt
.saved_firmware_options_3
;
4754 /* out-of-order frames reassembly */
4755 nv
->firmware_options_3
|= BIT_6
|BIT_9
;
4757 if (ha
->tgt
.enable_class_2
) {
4758 if (vha
->flags
.init_done
)
4759 fc_host_supported_classes(vha
->host
) =
4760 FC_COS_CLASS2
| FC_COS_CLASS3
;
4762 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_8
);
4764 if (vha
->flags
.init_done
)
4765 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
4767 nv
->firmware_options_2
&= ~__constant_cpu_to_le32(BIT_8
);
4772 qlt_24xx_config_nvram_stage2(struct scsi_qla_host
*vha
,
4773 struct init_cb_24xx
*icb
)
4775 struct qla_hw_data
*ha
= vha
->hw
;
4777 if (ha
->tgt
.node_name_set
) {
4778 memcpy(icb
->node_name
, ha
->tgt
.tgt_node_name
, WWN_SIZE
);
4779 icb
->firmware_options_1
|= __constant_cpu_to_le32(BIT_14
);
4784 qlt_24xx_process_response_error(struct scsi_qla_host
*vha
,
4785 struct sts_entry_24xx
*pkt
)
4787 switch (pkt
->entry_type
) {
4788 case ABTS_RECV_24XX
:
4789 case ABTS_RESP_24XX
:
4791 case NOTIFY_ACK_TYPE
:
4799 qlt_modify_vp_config(struct scsi_qla_host
*vha
,
4800 struct vp_config_entry_24xx
*vpmod
)
4802 if (qla_tgt_mode_enabled(vha
))
4803 vpmod
->options_idx1
&= ~BIT_5
;
4804 /* Disable ini mode, if requested */
4805 if (!qla_ini_mode_enabled(vha
))
4806 vpmod
->options_idx1
&= ~BIT_4
;
4810 qlt_probe_one_stage1(struct scsi_qla_host
*base_vha
, struct qla_hw_data
*ha
)
4812 if (!QLA_TGT_MODE_ENABLED())
4815 mutex_init(&ha
->tgt
.tgt_mutex
);
4816 mutex_init(&ha
->tgt
.tgt_host_action_mutex
);
4817 qlt_clear_mode(base_vha
);
4821 qlt_mem_alloc(struct qla_hw_data
*ha
)
4823 if (!QLA_TGT_MODE_ENABLED())
4826 ha
->tgt
.tgt_vp_map
= kzalloc(sizeof(struct qla_tgt_vp_map
) *
4827 MAX_MULTI_ID_FABRIC
, GFP_KERNEL
);
4828 if (!ha
->tgt
.tgt_vp_map
)
4831 ha
->tgt
.atio_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
4832 (ha
->tgt
.atio_q_length
+ 1) * sizeof(struct atio_from_isp
),
4833 &ha
->tgt
.atio_dma
, GFP_KERNEL
);
4834 if (!ha
->tgt
.atio_ring
) {
4835 kfree(ha
->tgt
.tgt_vp_map
);
4842 qlt_mem_free(struct qla_hw_data
*ha
)
4844 if (!QLA_TGT_MODE_ENABLED())
4847 if (ha
->tgt
.atio_ring
) {
4848 dma_free_coherent(&ha
->pdev
->dev
, (ha
->tgt
.atio_q_length
+ 1) *
4849 sizeof(struct atio_from_isp
), ha
->tgt
.atio_ring
,
4852 kfree(ha
->tgt
.tgt_vp_map
);
4855 /* vport_slock to be held by the caller */
4857 qlt_update_vp_map(struct scsi_qla_host
*vha
, int cmd
)
4859 if (!QLA_TGT_MODE_ENABLED())
4864 vha
->hw
->tgt
.tgt_vp_map
[vha
->vp_idx
].vha
= vha
;
4867 vha
->hw
->tgt
.tgt_vp_map
[vha
->d_id
.b
.al_pa
].idx
= vha
->vp_idx
;
4870 vha
->hw
->tgt
.tgt_vp_map
[vha
->vp_idx
].vha
= NULL
;
4873 vha
->hw
->tgt
.tgt_vp_map
[vha
->d_id
.b
.al_pa
].idx
= 0;
4878 static int __init
qlt_parse_ini_mode(void)
4880 if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_EXCLUSIVE
) == 0)
4881 ql2x_ini_mode
= QLA2XXX_INI_MODE_EXCLUSIVE
;
4882 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_DISABLED
) == 0)
4883 ql2x_ini_mode
= QLA2XXX_INI_MODE_DISABLED
;
4884 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_ENABLED
) == 0)
4885 ql2x_ini_mode
= QLA2XXX_INI_MODE_ENABLED
;
4892 int __init
qlt_init(void)
4896 if (!qlt_parse_ini_mode()) {
4897 ql_log(ql_log_fatal
, NULL
, 0xe06b,
4898 "qlt_parse_ini_mode() failed\n");
4902 if (!QLA_TGT_MODE_ENABLED())
4905 qla_tgt_cmd_cachep
= kmem_cache_create("qla_tgt_cmd_cachep",
4906 sizeof(struct qla_tgt_cmd
), __alignof__(struct qla_tgt_cmd
), 0,
4908 if (!qla_tgt_cmd_cachep
) {
4909 ql_log(ql_log_fatal
, NULL
, 0xe06c,
4910 "kmem_cache_create for qla_tgt_cmd_cachep failed\n");
4914 qla_tgt_mgmt_cmd_cachep
= kmem_cache_create("qla_tgt_mgmt_cmd_cachep",
4915 sizeof(struct qla_tgt_mgmt_cmd
), __alignof__(struct
4916 qla_tgt_mgmt_cmd
), 0, NULL
);
4917 if (!qla_tgt_mgmt_cmd_cachep
) {
4918 ql_log(ql_log_fatal
, NULL
, 0xe06d,
4919 "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
4924 qla_tgt_mgmt_cmd_mempool
= mempool_create(25, mempool_alloc_slab
,
4925 mempool_free_slab
, qla_tgt_mgmt_cmd_cachep
);
4926 if (!qla_tgt_mgmt_cmd_mempool
) {
4927 ql_log(ql_log_fatal
, NULL
, 0xe06e,
4928 "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
4930 goto out_mgmt_cmd_cachep
;
4933 qla_tgt_wq
= alloc_workqueue("qla_tgt_wq", 0, 0);
4935 ql_log(ql_log_fatal
, NULL
, 0xe06f,
4936 "alloc_workqueue for qla_tgt_wq failed\n");
4938 goto out_cmd_mempool
;
4941 * Return 1 to signal that initiator-mode is being disabled
4943 return (ql2x_ini_mode
== QLA2XXX_INI_MODE_DISABLED
) ? 1 : 0;
4946 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
4947 out_mgmt_cmd_cachep
:
4948 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);
4950 kmem_cache_destroy(qla_tgt_cmd_cachep
);
4956 if (!QLA_TGT_MODE_ENABLED())
4959 destroy_workqueue(qla_tgt_wq
);
4960 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
4961 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);
4962 kmem_cache_destroy(qla_tgt_cmd_cachep
);