1 /*******************************************************************************
2 * This file contains tcm implementation using v4 configfs fabric infrastructure
3 * for QLogic target mode HBAs
5 * (c) Copyright 2010-2013 Datera, Inc.
7 * Author: Nicholas A. Bellinger <nab@daterainc.com>
9 * tcm_qla2xxx_parse_wwn() and tcm_qla2xxx_format_wwn() contains code from
10 * the TCM_FC / Open-FCoE.org fabric module.
12 * Copyright (c) 2010 Cisco Systems, Inc
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 ****************************************************************************/
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/utsname.h>
29 #include <linux/vmalloc.h>
30 #include <linux/init.h>
31 #include <linux/list.h>
32 #include <linux/slab.h>
33 #include <linux/kthread.h>
34 #include <linux/types.h>
35 #include <linux/string.h>
36 #include <linux/configfs.h>
37 #include <linux/ctype.h>
38 #include <asm/unaligned.h>
39 #include <scsi/scsi.h>
40 #include <scsi/scsi_host.h>
41 #include <scsi/scsi_device.h>
42 #include <scsi/scsi_cmnd.h>
43 #include <target/target_core_base.h>
44 #include <target/target_core_fabric.h>
47 #include "qla_target.h"
48 #include "tcm_qla2xxx.h"
50 static struct workqueue_struct
*tcm_qla2xxx_free_wq
;
51 static struct workqueue_struct
*tcm_qla2xxx_cmd_wq
;
55 * If strict, we require lower-case hex and colon separators to be sure
56 * the name is the same as what would be generated by ft_format_wwn()
57 * so the name and wwn are mapped one-to-one.
59 static ssize_t
tcm_qla2xxx_parse_wwn(const char *name
, u64
*wwn
, int strict
)
69 for (cp
= name
; cp
< &name
[TCM_QLA2XXX_NAMELEN
- 1]; cp
++) {
71 if (c
== '\n' && cp
[1] == '\0')
73 if (strict
&& pos
++ == 2 && byte
++ < 7) {
82 if (strict
&& byte
!= 8)
89 else if (isxdigit(c
) && (islower(c
) || !strict
))
90 nibble
= tolower(c
) - 'a' + 10;
93 *wwn
= (*wwn
<< 4) | nibble
;
97 pr_debug("err %u len %zu pos %u byte %u\n",
98 err
, cp
- name
, pos
, byte
);
102 static ssize_t
tcm_qla2xxx_format_wwn(char *buf
, size_t len
, u64 wwn
)
106 put_unaligned_be64(wwn
, b
);
107 return snprintf(buf
, len
,
108 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
109 b
[0], b
[1], b
[2], b
[3], b
[4], b
[5], b
[6], b
[7]);
112 static char *tcm_qla2xxx_get_fabric_name(void)
118 * From drivers/scsi/scsi_transport_fc.c:fc_parse_wwn
120 static int tcm_qla2xxx_npiv_extract_wwn(const char *ns
, u64
*nm
)
125 memset(wwn
, 0, sizeof(wwn
));
127 /* Validate and store the new name */
128 for (i
= 0, j
= 0; i
< 16; i
++) {
131 value
= hex_to_bin(*ns
++);
133 j
= (j
<< 4) | value
;
143 *nm
= wwn_to_u64(wwn
);
148 * This parsing logic follows drivers/scsi/scsi_transport_fc.c:
149 * store_fc_host_vport_create()
151 static int tcm_qla2xxx_npiv_parse_wwn(
157 unsigned int cnt
= count
;
163 /* count may include a LF at end of string */
164 if (name
[cnt
-1] == '\n' || name
[cnt
-1] == 0)
167 /* validate we have enough characters for WWPN */
168 if ((cnt
!= (16+1+16)) || (name
[16] != ':'))
171 rc
= tcm_qla2xxx_npiv_extract_wwn(&name
[0], wwpn
);
175 rc
= tcm_qla2xxx_npiv_extract_wwn(&name
[17], wwnn
);
182 static char *tcm_qla2xxx_npiv_get_fabric_name(void)
184 return "qla2xxx_npiv";
187 static char *tcm_qla2xxx_get_fabric_wwn(struct se_portal_group
*se_tpg
)
189 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
190 struct tcm_qla2xxx_tpg
, se_tpg
);
191 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
193 return lport
->lport_naa_name
;
196 static u16
tcm_qla2xxx_get_tag(struct se_portal_group
*se_tpg
)
198 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
199 struct tcm_qla2xxx_tpg
, se_tpg
);
200 return tpg
->lport_tpgt
;
203 static int tcm_qla2xxx_check_demo_mode(struct se_portal_group
*se_tpg
)
205 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
206 struct tcm_qla2xxx_tpg
, se_tpg
);
208 return tpg
->tpg_attrib
.generate_node_acls
;
211 static int tcm_qla2xxx_check_demo_mode_cache(struct se_portal_group
*se_tpg
)
213 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
214 struct tcm_qla2xxx_tpg
, se_tpg
);
216 return tpg
->tpg_attrib
.cache_dynamic_acls
;
219 static int tcm_qla2xxx_check_demo_write_protect(struct se_portal_group
*se_tpg
)
221 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
222 struct tcm_qla2xxx_tpg
, se_tpg
);
224 return tpg
->tpg_attrib
.demo_mode_write_protect
;
227 static int tcm_qla2xxx_check_prod_write_protect(struct se_portal_group
*se_tpg
)
229 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
230 struct tcm_qla2xxx_tpg
, se_tpg
);
232 return tpg
->tpg_attrib
.prod_mode_write_protect
;
235 static int tcm_qla2xxx_check_demo_mode_login_only(struct se_portal_group
*se_tpg
)
237 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
238 struct tcm_qla2xxx_tpg
, se_tpg
);
240 return tpg
->tpg_attrib
.demo_mode_login_only
;
243 static int tcm_qla2xxx_check_prot_fabric_only(struct se_portal_group
*se_tpg
)
245 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
246 struct tcm_qla2xxx_tpg
, se_tpg
);
248 return tpg
->tpg_attrib
.fabric_prot_type
;
251 static u32
tcm_qla2xxx_tpg_get_inst_index(struct se_portal_group
*se_tpg
)
253 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
254 struct tcm_qla2xxx_tpg
, se_tpg
);
256 return tpg
->lport_tpgt
;
259 static void tcm_qla2xxx_complete_mcmd(struct work_struct
*work
)
261 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(work
,
262 struct qla_tgt_mgmt_cmd
, free_work
);
264 transport_generic_free_cmd(&mcmd
->se_cmd
, 0);
268 * Called from qla_target_template->free_mcmd(), and will call
269 * tcm_qla2xxx_release_cmd() via normal struct target_core_fabric_ops
270 * release callback. qla_hw_data->hardware_lock is expected to be held
272 static void tcm_qla2xxx_free_mcmd(struct qla_tgt_mgmt_cmd
*mcmd
)
274 INIT_WORK(&mcmd
->free_work
, tcm_qla2xxx_complete_mcmd
);
275 queue_work(tcm_qla2xxx_free_wq
, &mcmd
->free_work
);
278 static void tcm_qla2xxx_complete_free(struct work_struct
*work
)
280 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
284 WARN_ON(cmd
->trc_flags
& TRC_CMD_FREE
);
286 cmd
->qpair
->tgt_counters
.qla_core_ret_sta_ctio
++;
287 cmd
->trc_flags
|= TRC_CMD_FREE
;
288 transport_generic_free_cmd(&cmd
->se_cmd
, 0);
292 * Called from qla_target_template->free_cmd(), and will call
293 * tcm_qla2xxx_release_cmd via normal struct target_core_fabric_ops
294 * release callback. qla_hw_data->hardware_lock is expected to be held
296 static void tcm_qla2xxx_free_cmd(struct qla_tgt_cmd
*cmd
)
298 cmd
->qpair
->tgt_counters
.core_qla_free_cmd
++;
301 WARN_ON(cmd
->trc_flags
& TRC_CMD_DONE
);
302 cmd
->trc_flags
|= TRC_CMD_DONE
;
304 INIT_WORK(&cmd
->work
, tcm_qla2xxx_complete_free
);
305 queue_work_on(smp_processor_id(), tcm_qla2xxx_free_wq
, &cmd
->work
);
309 * Called from struct target_core_fabric_ops->check_stop_free() context
311 static int tcm_qla2xxx_check_stop_free(struct se_cmd
*se_cmd
)
313 struct qla_tgt_cmd
*cmd
;
315 if ((se_cmd
->se_cmd_flags
& SCF_SCSI_TMR_CDB
) == 0) {
316 cmd
= container_of(se_cmd
, struct qla_tgt_cmd
, se_cmd
);
317 cmd
->trc_flags
|= TRC_CMD_CHK_STOP
;
320 return target_put_sess_cmd(se_cmd
);
323 /* tcm_qla2xxx_release_cmd - Callback from TCM Core to release underlying
324 * fabric descriptor @se_cmd command to release
326 static void tcm_qla2xxx_release_cmd(struct se_cmd
*se_cmd
)
328 struct qla_tgt_cmd
*cmd
;
330 if (se_cmd
->se_cmd_flags
& SCF_SCSI_TMR_CDB
) {
331 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(se_cmd
,
332 struct qla_tgt_mgmt_cmd
, se_cmd
);
337 cmd
= container_of(se_cmd
, struct qla_tgt_cmd
, se_cmd
);
341 static void tcm_qla2xxx_release_session(struct kref
*kref
)
343 struct fc_port
*sess
= container_of(kref
,
344 struct fc_port
, sess_kref
);
346 qlt_unreg_sess(sess
);
349 static void tcm_qla2xxx_put_sess(struct fc_port
*sess
)
354 assert_spin_locked(&sess
->vha
->hw
->tgt
.sess_lock
);
355 kref_put(&sess
->sess_kref
, tcm_qla2xxx_release_session
);
358 static void tcm_qla2xxx_close_session(struct se_session
*se_sess
)
360 struct fc_port
*sess
= se_sess
->fabric_sess_ptr
;
361 struct scsi_qla_host
*vha
;
367 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
368 target_sess_cmd_list_set_waiting(se_sess
);
369 tcm_qla2xxx_put_sess(sess
);
370 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
373 static u32
tcm_qla2xxx_sess_get_index(struct se_session
*se_sess
)
378 static int tcm_qla2xxx_write_pending(struct se_cmd
*se_cmd
)
380 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
381 struct qla_tgt_cmd
, se_cmd
);
384 /* Cmd can loop during Q-full. tcm_qla2xxx_aborted_task
385 * can get ahead of this cmd. tcm_qla2xxx_aborted_task
386 * already kick start the free.
388 pr_debug("write_pending aborted cmd[%p] refcount %d "
389 "transport_state %x, t_state %x, se_cmd_flags %x\n",
390 cmd
, kref_read(&cmd
->se_cmd
.cmd_kref
),
391 cmd
->se_cmd
.transport_state
,
393 cmd
->se_cmd
.se_cmd_flags
);
396 cmd
->trc_flags
|= TRC_XFR_RDY
;
397 cmd
->bufflen
= se_cmd
->data_length
;
398 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
400 cmd
->sg_cnt
= se_cmd
->t_data_nents
;
401 cmd
->sg
= se_cmd
->t_data_sg
;
403 cmd
->prot_sg_cnt
= se_cmd
->t_prot_nents
;
404 cmd
->prot_sg
= se_cmd
->t_prot_sg
;
405 cmd
->blk_sz
= se_cmd
->se_dev
->dev_attrib
.block_size
;
409 * qla_target.c:qlt_rdy_to_xfer() will call pci_map_sg() to setup
410 * the SGL mappings into PCIe memory for incoming FCP WRITE data.
412 return qlt_rdy_to_xfer(cmd
);
415 static int tcm_qla2xxx_write_pending_status(struct se_cmd
*se_cmd
)
419 * Check for WRITE_PENDING status to determine if we need to wait for
420 * CTIO aborts to be posted via hardware in tcm_qla2xxx_handle_data().
422 spin_lock_irqsave(&se_cmd
->t_state_lock
, flags
);
423 if (se_cmd
->t_state
== TRANSPORT_WRITE_PENDING
||
424 se_cmd
->t_state
== TRANSPORT_COMPLETE_QF_WP
) {
425 spin_unlock_irqrestore(&se_cmd
->t_state_lock
, flags
);
426 wait_for_completion_timeout(&se_cmd
->t_transport_stop_comp
,
430 spin_unlock_irqrestore(&se_cmd
->t_state_lock
, flags
);
435 static void tcm_qla2xxx_set_default_node_attrs(struct se_node_acl
*nacl
)
440 static int tcm_qla2xxx_get_cmd_state(struct se_cmd
*se_cmd
)
442 if (!(se_cmd
->se_cmd_flags
& SCF_SCSI_TMR_CDB
)) {
443 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
444 struct qla_tgt_cmd
, se_cmd
);
452 * Called from process context in qla_target.c:qlt_do_work() code
454 static int tcm_qla2xxx_handle_cmd(scsi_qla_host_t
*vha
, struct qla_tgt_cmd
*cmd
,
455 unsigned char *cdb
, uint32_t data_length
, int fcp_task_attr
,
456 int data_dir
, int bidi
)
458 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
459 struct se_session
*se_sess
;
460 struct fc_port
*sess
;
461 #ifdef CONFIG_TCM_QLA2XXX_DEBUG
462 struct se_portal_group
*se_tpg
;
463 struct tcm_qla2xxx_tpg
*tpg
;
465 int flags
= TARGET_SCF_ACK_KREF
;
468 flags
|= TARGET_SCF_BIDI_OP
;
470 if (se_cmd
->cpuid
!= WORK_CPU_UNBOUND
)
471 flags
|= TARGET_SCF_USE_CPUID
;
475 pr_err("Unable to locate struct fc_port from qla_tgt_cmd\n");
479 se_sess
= sess
->se_sess
;
481 pr_err("Unable to locate active struct se_session\n");
485 #ifdef CONFIG_TCM_QLA2XXX_DEBUG
486 se_tpg
= se_sess
->se_tpg
;
487 tpg
= container_of(se_tpg
, struct tcm_qla2xxx_tpg
, se_tpg
);
488 if (unlikely(tpg
->tpg_attrib
.jam_host
)) {
489 /* return, and dont run target_submit_cmd,discarding command */
494 cmd
->qpair
->tgt_counters
.qla_core_sbt_cmd
++;
495 return target_submit_cmd(se_cmd
, se_sess
, cdb
, &cmd
->sense_buffer
[0],
496 cmd
->unpacked_lun
, data_length
, fcp_task_attr
,
500 static void tcm_qla2xxx_handle_data_work(struct work_struct
*work
)
502 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
506 * Ensure that the complete FCP WRITE payload has been received.
507 * Otherwise return an exception via CHECK_CONDITION status.
511 spin_lock_irqsave(&cmd
->cmd_lock
, flags
);
514 cmd
->data_work_free
= 1;
515 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
517 tcm_qla2xxx_free_cmd(cmd
);
520 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
522 cmd
->qpair
->tgt_counters
.qla_core_ret_ctio
++;
523 if (!cmd
->write_data_transferred
) {
525 * Check if se_cmd has already been aborted via LUN_RESET, and
526 * waiting upon completion in tcm_qla2xxx_write_pending_status()
528 if (cmd
->se_cmd
.transport_state
& CMD_T_ABORTED
) {
529 complete(&cmd
->se_cmd
.t_transport_stop_comp
);
533 switch (cmd
->dif_err_code
) {
536 TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED
;
540 TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED
;
544 TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED
;
551 if (cmd
->se_cmd
.pi_err
)
552 transport_generic_request_failure(&cmd
->se_cmd
,
555 transport_generic_request_failure(&cmd
->se_cmd
,
556 TCM_CHECK_CONDITION_ABORT_CMD
);
561 return target_execute_cmd(&cmd
->se_cmd
);
565 * Called from qla_target.c:qlt_do_ctio_completion()
567 static void tcm_qla2xxx_handle_data(struct qla_tgt_cmd
*cmd
)
569 cmd
->trc_flags
|= TRC_DATA_IN
;
571 INIT_WORK(&cmd
->work
, tcm_qla2xxx_handle_data_work
);
572 queue_work_on(smp_processor_id(), tcm_qla2xxx_free_wq
, &cmd
->work
);
575 static int tcm_qla2xxx_chk_dif_tags(uint32_t tag
)
580 static int tcm_qla2xxx_dif_tags(struct qla_tgt_cmd
*cmd
,
581 uint16_t *pfw_prot_opts
)
583 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
585 if (!(se_cmd
->prot_checks
& TARGET_DIF_CHECK_GUARD
))
586 *pfw_prot_opts
|= PO_DISABLE_GUARD_CHECK
;
588 if (!(se_cmd
->prot_checks
& TARGET_DIF_CHECK_APPTAG
))
589 *pfw_prot_opts
|= PO_DIS_APP_TAG_VALD
;
595 * Called from qla_target.c:qlt_issue_task_mgmt()
597 static int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd
*mcmd
, u64 lun
,
598 uint16_t tmr_func
, uint32_t tag
)
600 struct fc_port
*sess
= mcmd
->sess
;
601 struct se_cmd
*se_cmd
= &mcmd
->se_cmd
;
602 int transl_tmr_func
= 0;
603 int flags
= TARGET_SCF_ACK_KREF
;
607 pr_debug("%ld: ABTS received\n", sess
->vha
->host_no
);
608 transl_tmr_func
= TMR_ABORT_TASK
;
609 flags
|= TARGET_SCF_LOOKUP_LUN_FROM_TAG
;
611 case QLA_TGT_2G_ABORT_TASK
:
612 pr_debug("%ld: 2G Abort Task received\n", sess
->vha
->host_no
);
613 transl_tmr_func
= TMR_ABORT_TASK
;
615 case QLA_TGT_CLEAR_ACA
:
616 pr_debug("%ld: CLEAR_ACA received\n", sess
->vha
->host_no
);
617 transl_tmr_func
= TMR_CLEAR_ACA
;
619 case QLA_TGT_TARGET_RESET
:
620 pr_debug("%ld: TARGET_RESET received\n", sess
->vha
->host_no
);
621 transl_tmr_func
= TMR_TARGET_WARM_RESET
;
623 case QLA_TGT_LUN_RESET
:
624 pr_debug("%ld: LUN_RESET received\n", sess
->vha
->host_no
);
625 transl_tmr_func
= TMR_LUN_RESET
;
627 case QLA_TGT_CLEAR_TS
:
628 pr_debug("%ld: CLEAR_TS received\n", sess
->vha
->host_no
);
629 transl_tmr_func
= TMR_CLEAR_TASK_SET
;
631 case QLA_TGT_ABORT_TS
:
632 pr_debug("%ld: ABORT_TS received\n", sess
->vha
->host_no
);
633 transl_tmr_func
= TMR_ABORT_TASK_SET
;
636 pr_debug("%ld: Unknown task mgmt fn 0x%x\n",
637 sess
->vha
->host_no
, tmr_func
);
641 return target_submit_tmr(se_cmd
, sess
->se_sess
, NULL
, lun
, mcmd
,
642 transl_tmr_func
, GFP_ATOMIC
, tag
, flags
);
645 static int tcm_qla2xxx_queue_data_in(struct se_cmd
*se_cmd
)
647 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
648 struct qla_tgt_cmd
, se_cmd
);
651 /* Cmd can loop during Q-full. tcm_qla2xxx_aborted_task
652 * can get ahead of this cmd. tcm_qla2xxx_aborted_task
653 * already kick start the free.
655 pr_debug("queue_data_in aborted cmd[%p] refcount %d "
656 "transport_state %x, t_state %x, se_cmd_flags %x\n",
657 cmd
, kref_read(&cmd
->se_cmd
.cmd_kref
),
658 cmd
->se_cmd
.transport_state
,
660 cmd
->se_cmd
.se_cmd_flags
);
664 cmd
->trc_flags
|= TRC_XMIT_DATA
;
665 cmd
->bufflen
= se_cmd
->data_length
;
666 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
668 cmd
->sg_cnt
= se_cmd
->t_data_nents
;
669 cmd
->sg
= se_cmd
->t_data_sg
;
672 cmd
->prot_sg_cnt
= se_cmd
->t_prot_nents
;
673 cmd
->prot_sg
= se_cmd
->t_prot_sg
;
674 cmd
->blk_sz
= se_cmd
->se_dev
->dev_attrib
.block_size
;
678 * Now queue completed DATA_IN the qla2xxx LLD and response ring
680 return qlt_xmit_response(cmd
, QLA_TGT_XMIT_DATA
|QLA_TGT_XMIT_STATUS
,
681 se_cmd
->scsi_status
);
684 static int tcm_qla2xxx_queue_status(struct se_cmd
*se_cmd
)
686 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
687 struct qla_tgt_cmd
, se_cmd
);
688 int xmit_type
= QLA_TGT_XMIT_STATUS
;
692 * Cmd can loop during Q-full. tcm_qla2xxx_aborted_task
693 * can get ahead of this cmd. tcm_qla2xxx_aborted_task
694 * already kick start the free.
697 "queue_data_in aborted cmd[%p] refcount %d transport_state %x, t_state %x, se_cmd_flags %x\n",
698 cmd
, kref_read(&cmd
->se_cmd
.cmd_kref
),
699 cmd
->se_cmd
.transport_state
, cmd
->se_cmd
.t_state
,
700 cmd
->se_cmd
.se_cmd_flags
);
703 cmd
->bufflen
= se_cmd
->data_length
;
707 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
708 if (cmd
->trc_flags
& TRC_XMIT_STATUS
) {
709 pr_crit("Multiple calls for status = %p.\n", cmd
);
712 cmd
->trc_flags
|= TRC_XMIT_STATUS
;
714 if (se_cmd
->data_direction
== DMA_FROM_DEVICE
) {
716 * For FCP_READ with CHECK_CONDITION status, clear cmd->bufflen
717 * for qla_tgt_xmit_response LLD code
719 if (se_cmd
->se_cmd_flags
& SCF_OVERFLOW_BIT
) {
720 se_cmd
->se_cmd_flags
&= ~SCF_OVERFLOW_BIT
;
721 se_cmd
->residual_count
= 0;
723 se_cmd
->se_cmd_flags
|= SCF_UNDERFLOW_BIT
;
724 se_cmd
->residual_count
+= se_cmd
->data_length
;
729 * Now queue status response to qla2xxx LLD code and response ring
731 return qlt_xmit_response(cmd
, xmit_type
, se_cmd
->scsi_status
);
734 static void tcm_qla2xxx_queue_tm_rsp(struct se_cmd
*se_cmd
)
736 struct se_tmr_req
*se_tmr
= se_cmd
->se_tmr_req
;
737 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(se_cmd
,
738 struct qla_tgt_mgmt_cmd
, se_cmd
);
740 pr_debug("queue_tm_rsp: mcmd: %p func: 0x%02x response: 0x%02x\n",
741 mcmd
, se_tmr
->function
, se_tmr
->response
);
743 * Do translation between TCM TM response codes and
744 * QLA2xxx FC TM response codes.
746 switch (se_tmr
->response
) {
747 case TMR_FUNCTION_COMPLETE
:
748 mcmd
->fc_tm_rsp
= FC_TM_SUCCESS
;
750 case TMR_TASK_DOES_NOT_EXIST
:
751 mcmd
->fc_tm_rsp
= FC_TM_BAD_CMD
;
753 case TMR_FUNCTION_REJECTED
:
754 mcmd
->fc_tm_rsp
= FC_TM_REJECT
;
756 case TMR_LUN_DOES_NOT_EXIST
:
758 mcmd
->fc_tm_rsp
= FC_TM_FAILED
;
762 * Queue the TM response to QLA2xxx LLD to build a
763 * CTIO response packet.
765 qlt_xmit_tm_rsp(mcmd
);
768 #define DATA_WORK_NOT_FREE(_cmd) (_cmd->data_work && !_cmd->data_work_free)
769 static void tcm_qla2xxx_aborted_task(struct se_cmd
*se_cmd
)
771 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
772 struct qla_tgt_cmd
, se_cmd
);
775 if (qlt_abort_cmd(cmd
))
778 spin_lock_irqsave(&cmd
->cmd_lock
, flags
);
779 if ((cmd
->state
== QLA_TGT_STATE_NEW
)||
780 ((cmd
->state
== QLA_TGT_STATE_DATA_IN
) &&
781 DATA_WORK_NOT_FREE(cmd
))) {
782 cmd
->data_work_free
= 1;
783 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
785 * cmd has not reached fw, Use this trigger to free it.
787 tcm_qla2xxx_free_cmd(cmd
);
790 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
795 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport
*,
796 struct tcm_qla2xxx_nacl
*, struct fc_port
*);
798 * Expected to be called with struct qla_hw_data->tgt.sess_lock held
800 static void tcm_qla2xxx_clear_nacl_from_fcport_map(struct fc_port
*sess
)
802 struct se_node_acl
*se_nacl
= sess
->se_sess
->se_node_acl
;
803 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
804 struct se_wwn
*se_wwn
= se_tpg
->se_tpg_wwn
;
805 struct tcm_qla2xxx_lport
*lport
= container_of(se_wwn
,
806 struct tcm_qla2xxx_lport
, lport_wwn
);
807 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
808 struct tcm_qla2xxx_nacl
, se_node_acl
);
811 pr_debug("fc_rport domain: port_id 0x%06x\n", nacl
->nport_id
);
813 node
= btree_remove32(&lport
->lport_fcport_map
, nacl
->nport_id
);
814 if (WARN_ON(node
&& (node
!= se_nacl
))) {
816 * The nacl no longer matches what we think it should be.
817 * Most likely a new dynamic acl has been added while
818 * someone dropped the hardware lock. It clearly is a
819 * bug elsewhere, but this bit can't make things worse.
821 btree_insert32(&lport
->lport_fcport_map
, nacl
->nport_id
,
825 pr_debug("Removed from fcport_map: %p for WWNN: 0x%016LX, port_id: 0x%06x\n",
826 se_nacl
, nacl
->nport_wwnn
, nacl
->nport_id
);
828 * Now clear the se_nacl and session pointers from our HW lport lookup
829 * table mapping for this initiator's fabric S_ID and LOOP_ID entries.
831 * This is done ahead of callbacks into tcm_qla2xxx_free_session() ->
832 * target_wait_for_sess_cmds() before the session waits for outstanding
833 * I/O to complete, to avoid a race between session shutdown execution
834 * and incoming ATIOs or TMRs picking up a stale se_node_act reference.
836 tcm_qla2xxx_clear_sess_lookup(lport
, nacl
, sess
);
839 static void tcm_qla2xxx_shutdown_sess(struct fc_port
*sess
)
841 assert_spin_locked(&sess
->vha
->hw
->tgt
.sess_lock
);
842 target_sess_cmd_list_set_waiting(sess
->se_sess
);
845 static int tcm_qla2xxx_init_nodeacl(struct se_node_acl
*se_nacl
,
848 struct tcm_qla2xxx_nacl
*nacl
=
849 container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
852 if (tcm_qla2xxx_parse_wwn(name
, &wwnn
, 1) < 0)
855 nacl
->nport_wwnn
= wwnn
;
856 tcm_qla2xxx_format_wwn(&nacl
->nport_name
[0], TCM_QLA2XXX_NAMELEN
, wwnn
);
861 /* Start items for tcm_qla2xxx_tpg_attrib_cit */
863 #define DEF_QLA_TPG_ATTRIB(name) \
865 static ssize_t tcm_qla2xxx_tpg_attrib_##name##_show( \
866 struct config_item *item, char *page) \
868 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
869 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
870 struct tcm_qla2xxx_tpg, se_tpg); \
872 return sprintf(page, "%u\n", tpg->tpg_attrib.name); \
875 static ssize_t tcm_qla2xxx_tpg_attrib_##name##_store( \
876 struct config_item *item, const char *page, size_t count) \
878 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
879 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
880 struct tcm_qla2xxx_tpg, se_tpg); \
881 struct tcm_qla2xxx_tpg_attrib *a = &tpg->tpg_attrib; \
885 ret = kstrtoul(page, 0, &val); \
887 pr_err("kstrtoul() failed with" \
888 " ret: %d\n", ret); \
892 if ((val != 0) && (val != 1)) { \
893 pr_err("Illegal boolean value %lu\n", val); \
901 CONFIGFS_ATTR(tcm_qla2xxx_tpg_attrib_, name)
903 DEF_QLA_TPG_ATTRIB(generate_node_acls
);
904 DEF_QLA_TPG_ATTRIB(cache_dynamic_acls
);
905 DEF_QLA_TPG_ATTRIB(demo_mode_write_protect
);
906 DEF_QLA_TPG_ATTRIB(prod_mode_write_protect
);
907 DEF_QLA_TPG_ATTRIB(demo_mode_login_only
);
908 #ifdef CONFIG_TCM_QLA2XXX_DEBUG
909 DEF_QLA_TPG_ATTRIB(jam_host
);
912 static struct configfs_attribute
*tcm_qla2xxx_tpg_attrib_attrs
[] = {
913 &tcm_qla2xxx_tpg_attrib_attr_generate_node_acls
,
914 &tcm_qla2xxx_tpg_attrib_attr_cache_dynamic_acls
,
915 &tcm_qla2xxx_tpg_attrib_attr_demo_mode_write_protect
,
916 &tcm_qla2xxx_tpg_attrib_attr_prod_mode_write_protect
,
917 &tcm_qla2xxx_tpg_attrib_attr_demo_mode_login_only
,
918 #ifdef CONFIG_TCM_QLA2XXX_DEBUG
919 &tcm_qla2xxx_tpg_attrib_attr_jam_host
,
924 /* End items for tcm_qla2xxx_tpg_attrib_cit */
926 static ssize_t
tcm_qla2xxx_tpg_enable_show(struct config_item
*item
,
929 struct se_portal_group
*se_tpg
= to_tpg(item
);
930 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
931 struct tcm_qla2xxx_tpg
, se_tpg
);
933 return snprintf(page
, PAGE_SIZE
, "%d\n",
934 atomic_read(&tpg
->lport_tpg_enabled
));
937 static void tcm_qla2xxx_depend_tpg(struct work_struct
*work
)
939 struct tcm_qla2xxx_tpg
*base_tpg
= container_of(work
,
940 struct tcm_qla2xxx_tpg
, tpg_base_work
);
941 struct se_portal_group
*se_tpg
= &base_tpg
->se_tpg
;
942 struct scsi_qla_host
*base_vha
= base_tpg
->lport
->qla_vha
;
944 if (!target_depend_item(&se_tpg
->tpg_group
.cg_item
)) {
945 atomic_set(&base_tpg
->lport_tpg_enabled
, 1);
946 qlt_enable_vha(base_vha
);
948 complete(&base_tpg
->tpg_base_comp
);
951 static void tcm_qla2xxx_undepend_tpg(struct work_struct
*work
)
953 struct tcm_qla2xxx_tpg
*base_tpg
= container_of(work
,
954 struct tcm_qla2xxx_tpg
, tpg_base_work
);
955 struct se_portal_group
*se_tpg
= &base_tpg
->se_tpg
;
956 struct scsi_qla_host
*base_vha
= base_tpg
->lport
->qla_vha
;
958 if (!qlt_stop_phase1(base_vha
->vha_tgt
.qla_tgt
)) {
959 atomic_set(&base_tpg
->lport_tpg_enabled
, 0);
960 target_undepend_item(&se_tpg
->tpg_group
.cg_item
);
962 complete(&base_tpg
->tpg_base_comp
);
965 static ssize_t
tcm_qla2xxx_tpg_enable_store(struct config_item
*item
,
966 const char *page
, size_t count
)
968 struct se_portal_group
*se_tpg
= to_tpg(item
);
969 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
970 struct tcm_qla2xxx_tpg
, se_tpg
);
974 rc
= kstrtoul(page
, 0, &op
);
976 pr_err("kstrtoul() returned %d\n", rc
);
979 if ((op
!= 1) && (op
!= 0)) {
980 pr_err("Illegal value for tpg_enable: %lu\n", op
);
984 if (atomic_read(&tpg
->lport_tpg_enabled
))
987 INIT_WORK(&tpg
->tpg_base_work
, tcm_qla2xxx_depend_tpg
);
989 if (!atomic_read(&tpg
->lport_tpg_enabled
))
992 INIT_WORK(&tpg
->tpg_base_work
, tcm_qla2xxx_undepend_tpg
);
994 init_completion(&tpg
->tpg_base_comp
);
995 schedule_work(&tpg
->tpg_base_work
);
996 wait_for_completion(&tpg
->tpg_base_comp
);
999 if (!atomic_read(&tpg
->lport_tpg_enabled
))
1002 if (atomic_read(&tpg
->lport_tpg_enabled
))
1008 static ssize_t
tcm_qla2xxx_tpg_dynamic_sessions_show(struct config_item
*item
,
1011 return target_show_dynamic_sessions(to_tpg(item
), page
);
1014 static ssize_t
tcm_qla2xxx_tpg_fabric_prot_type_store(struct config_item
*item
,
1015 const char *page
, size_t count
)
1017 struct se_portal_group
*se_tpg
= to_tpg(item
);
1018 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1019 struct tcm_qla2xxx_tpg
, se_tpg
);
1021 int ret
= kstrtoul(page
, 0, &val
);
1024 pr_err("kstrtoul() returned %d for fabric_prot_type\n", ret
);
1027 if (val
!= 0 && val
!= 1 && val
!= 3) {
1028 pr_err("Invalid qla2xxx fabric_prot_type: %lu\n", val
);
1031 tpg
->tpg_attrib
.fabric_prot_type
= val
;
1036 static ssize_t
tcm_qla2xxx_tpg_fabric_prot_type_show(struct config_item
*item
,
1039 struct se_portal_group
*se_tpg
= to_tpg(item
);
1040 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1041 struct tcm_qla2xxx_tpg
, se_tpg
);
1043 return sprintf(page
, "%d\n", tpg
->tpg_attrib
.fabric_prot_type
);
1046 CONFIGFS_ATTR(tcm_qla2xxx_tpg_
, enable
);
1047 CONFIGFS_ATTR_RO(tcm_qla2xxx_tpg_
, dynamic_sessions
);
1048 CONFIGFS_ATTR(tcm_qla2xxx_tpg_
, fabric_prot_type
);
1050 static struct configfs_attribute
*tcm_qla2xxx_tpg_attrs
[] = {
1051 &tcm_qla2xxx_tpg_attr_enable
,
1052 &tcm_qla2xxx_tpg_attr_dynamic_sessions
,
1053 &tcm_qla2xxx_tpg_attr_fabric_prot_type
,
1057 static struct se_portal_group
*tcm_qla2xxx_make_tpg(
1059 struct config_group
*group
,
1062 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1063 struct tcm_qla2xxx_lport
, lport_wwn
);
1064 struct tcm_qla2xxx_tpg
*tpg
;
1068 if (strstr(name
, "tpgt_") != name
)
1069 return ERR_PTR(-EINVAL
);
1070 if (kstrtoul(name
+ 5, 10, &tpgt
) || tpgt
> USHRT_MAX
)
1071 return ERR_PTR(-EINVAL
);
1074 pr_err("In non NPIV mode, a single TPG=1 is used for HW port mappings\n");
1075 return ERR_PTR(-ENOSYS
);
1078 tpg
= kzalloc(sizeof(struct tcm_qla2xxx_tpg
), GFP_KERNEL
);
1080 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1081 return ERR_PTR(-ENOMEM
);
1084 tpg
->lport_tpgt
= tpgt
;
1086 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1089 tpg
->tpg_attrib
.generate_node_acls
= 1;
1090 tpg
->tpg_attrib
.demo_mode_write_protect
= 1;
1091 tpg
->tpg_attrib
.cache_dynamic_acls
= 1;
1092 tpg
->tpg_attrib
.demo_mode_login_only
= 1;
1093 tpg
->tpg_attrib
.jam_host
= 0;
1095 ret
= core_tpg_register(wwn
, &tpg
->se_tpg
, SCSI_PROTOCOL_FCP
);
1103 return &tpg
->se_tpg
;
1106 static void tcm_qla2xxx_drop_tpg(struct se_portal_group
*se_tpg
)
1108 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1109 struct tcm_qla2xxx_tpg
, se_tpg
);
1110 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
1111 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1113 * Call into qla2x_target.c LLD logic to shutdown the active
1114 * FC Nexuses and disable target mode operation for this qla_hw_data
1116 if (vha
->vha_tgt
.qla_tgt
&& !vha
->vha_tgt
.qla_tgt
->tgt_stop
)
1117 qlt_stop_phase1(vha
->vha_tgt
.qla_tgt
);
1119 core_tpg_deregister(se_tpg
);
1121 * Clear local TPG=1 pointer for non NPIV mode.
1123 lport
->tpg_1
= NULL
;
1127 static ssize_t
tcm_qla2xxx_npiv_tpg_enable_show(struct config_item
*item
,
1130 return tcm_qla2xxx_tpg_enable_show(item
, page
);
1133 static ssize_t
tcm_qla2xxx_npiv_tpg_enable_store(struct config_item
*item
,
1134 const char *page
, size_t count
)
1136 struct se_portal_group
*se_tpg
= to_tpg(item
);
1137 struct se_wwn
*se_wwn
= se_tpg
->se_tpg_wwn
;
1138 struct tcm_qla2xxx_lport
*lport
= container_of(se_wwn
,
1139 struct tcm_qla2xxx_lport
, lport_wwn
);
1140 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1141 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1142 struct tcm_qla2xxx_tpg
, se_tpg
);
1146 rc
= kstrtoul(page
, 0, &op
);
1148 pr_err("kstrtoul() returned %d\n", rc
);
1151 if ((op
!= 1) && (op
!= 0)) {
1152 pr_err("Illegal value for tpg_enable: %lu\n", op
);
1156 if (atomic_read(&tpg
->lport_tpg_enabled
))
1159 atomic_set(&tpg
->lport_tpg_enabled
, 1);
1160 qlt_enable_vha(vha
);
1162 if (!atomic_read(&tpg
->lport_tpg_enabled
))
1165 atomic_set(&tpg
->lport_tpg_enabled
, 0);
1166 qlt_stop_phase1(vha
->vha_tgt
.qla_tgt
);
1172 CONFIGFS_ATTR(tcm_qla2xxx_npiv_tpg_
, enable
);
1174 static struct configfs_attribute
*tcm_qla2xxx_npiv_tpg_attrs
[] = {
1175 &tcm_qla2xxx_npiv_tpg_attr_enable
,
1179 static struct se_portal_group
*tcm_qla2xxx_npiv_make_tpg(
1181 struct config_group
*group
,
1184 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1185 struct tcm_qla2xxx_lport
, lport_wwn
);
1186 struct tcm_qla2xxx_tpg
*tpg
;
1190 if (strstr(name
, "tpgt_") != name
)
1191 return ERR_PTR(-EINVAL
);
1192 if (kstrtoul(name
+ 5, 10, &tpgt
) || tpgt
> USHRT_MAX
)
1193 return ERR_PTR(-EINVAL
);
1195 tpg
= kzalloc(sizeof(struct tcm_qla2xxx_tpg
), GFP_KERNEL
);
1197 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1198 return ERR_PTR(-ENOMEM
);
1201 tpg
->lport_tpgt
= tpgt
;
1204 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1207 tpg
->tpg_attrib
.generate_node_acls
= 1;
1208 tpg
->tpg_attrib
.demo_mode_write_protect
= 1;
1209 tpg
->tpg_attrib
.cache_dynamic_acls
= 1;
1210 tpg
->tpg_attrib
.demo_mode_login_only
= 1;
1212 ret
= core_tpg_register(wwn
, &tpg
->se_tpg
, SCSI_PROTOCOL_FCP
);
1218 return &tpg
->se_tpg
;
1222 * Expected to be called with struct qla_hw_data->tgt.sess_lock held
1224 static struct fc_port
*tcm_qla2xxx_find_sess_by_s_id(
1225 scsi_qla_host_t
*vha
,
1226 const uint8_t *s_id
)
1228 struct tcm_qla2xxx_lport
*lport
;
1229 struct se_node_acl
*se_nacl
;
1230 struct tcm_qla2xxx_nacl
*nacl
;
1233 lport
= vha
->vha_tgt
.target_lport_ptr
;
1235 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1240 key
= sid_to_key(s_id
);
1241 pr_debug("find_sess_by_s_id: 0x%06x\n", key
);
1243 se_nacl
= btree_lookup32(&lport
->lport_fcport_map
, key
);
1245 pr_debug("Unable to locate s_id: 0x%06x\n", key
);
1248 pr_debug("find_sess_by_s_id: located se_nacl: %p, initiatorname: %s\n",
1249 se_nacl
, se_nacl
->initiatorname
);
1251 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1252 if (!nacl
->fc_port
) {
1253 pr_err("Unable to locate struct fc_port\n");
1257 return nacl
->fc_port
;
1261 * Expected to be called with struct qla_hw_data->tgt.sess_lock held
1263 static void tcm_qla2xxx_set_sess_by_s_id(
1264 struct tcm_qla2xxx_lport
*lport
,
1265 struct se_node_acl
*new_se_nacl
,
1266 struct tcm_qla2xxx_nacl
*nacl
,
1267 struct se_session
*se_sess
,
1268 struct fc_port
*fc_port
,
1275 key
= sid_to_key(s_id
);
1276 pr_debug("set_sess_by_s_id: %06x\n", key
);
1278 slot
= btree_lookup32(&lport
->lport_fcport_map
, key
);
1281 pr_debug("Setting up new fc_port entry to new_se_nacl\n");
1282 nacl
->nport_id
= key
;
1283 rc
= btree_insert32(&lport
->lport_fcport_map
, key
,
1284 new_se_nacl
, GFP_ATOMIC
);
1286 printk(KERN_ERR
"Unable to insert s_id into fcport_map: %06x\n",
1289 pr_debug("Wiping nonexisting fc_port entry\n");
1292 fc_port
->se_sess
= se_sess
;
1293 nacl
->fc_port
= fc_port
;
1297 if (nacl
->fc_port
) {
1298 if (new_se_nacl
== NULL
) {
1299 pr_debug("Clearing existing nacl->fc_port and fc_port entry\n");
1300 btree_remove32(&lport
->lport_fcport_map
, key
);
1301 nacl
->fc_port
= NULL
;
1304 pr_debug("Replacing existing nacl->fc_port and fc_port entry\n");
1305 btree_update32(&lport
->lport_fcport_map
, key
, new_se_nacl
);
1306 fc_port
->se_sess
= se_sess
;
1307 nacl
->fc_port
= fc_port
;
1311 if (new_se_nacl
== NULL
) {
1312 pr_debug("Clearing existing fc_port entry\n");
1313 btree_remove32(&lport
->lport_fcport_map
, key
);
1317 pr_debug("Replacing existing fc_port entry w/o active nacl->fc_port\n");
1318 btree_update32(&lport
->lport_fcport_map
, key
, new_se_nacl
);
1319 fc_port
->se_sess
= se_sess
;
1320 nacl
->fc_port
= fc_port
;
1322 pr_debug("Setup nacl->fc_port %p by s_id for se_nacl: %p, initiatorname: %s\n",
1323 nacl
->fc_port
, new_se_nacl
, new_se_nacl
->initiatorname
);
1327 * Expected to be called with struct qla_hw_data->tgt.sess_lock held
1329 static struct fc_port
*tcm_qla2xxx_find_sess_by_loop_id(
1330 scsi_qla_host_t
*vha
,
1331 const uint16_t loop_id
)
1333 struct tcm_qla2xxx_lport
*lport
;
1334 struct se_node_acl
*se_nacl
;
1335 struct tcm_qla2xxx_nacl
*nacl
;
1336 struct tcm_qla2xxx_fc_loopid
*fc_loopid
;
1338 lport
= vha
->vha_tgt
.target_lport_ptr
;
1340 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1345 pr_debug("find_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id
);
1347 fc_loopid
= lport
->lport_loopid_map
+ loop_id
;
1348 se_nacl
= fc_loopid
->se_nacl
;
1350 pr_debug("Unable to locate se_nacl by loop_id: 0x%04x\n",
1355 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1357 if (!nacl
->fc_port
) {
1358 pr_err("Unable to locate struct fc_port\n");
1362 return nacl
->fc_port
;
1366 * Expected to be called with struct qla_hw_data->tgt.sess_lock held
1368 static void tcm_qla2xxx_set_sess_by_loop_id(
1369 struct tcm_qla2xxx_lport
*lport
,
1370 struct se_node_acl
*new_se_nacl
,
1371 struct tcm_qla2xxx_nacl
*nacl
,
1372 struct se_session
*se_sess
,
1373 struct fc_port
*fc_port
,
1376 struct se_node_acl
*saved_nacl
;
1377 struct tcm_qla2xxx_fc_loopid
*fc_loopid
;
1379 pr_debug("set_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id
);
1381 fc_loopid
= &((struct tcm_qla2xxx_fc_loopid
*)
1382 lport
->lport_loopid_map
)[loop_id
];
1384 saved_nacl
= fc_loopid
->se_nacl
;
1386 pr_debug("Setting up new fc_loopid->se_nacl to new_se_nacl\n");
1387 fc_loopid
->se_nacl
= new_se_nacl
;
1388 if (fc_port
->se_sess
!= se_sess
)
1389 fc_port
->se_sess
= se_sess
;
1390 if (nacl
->fc_port
!= fc_port
)
1391 nacl
->fc_port
= fc_port
;
1395 if (nacl
->fc_port
) {
1396 if (new_se_nacl
== NULL
) {
1397 pr_debug("Clearing nacl->fc_port and fc_loopid->se_nacl\n");
1398 fc_loopid
->se_nacl
= NULL
;
1399 nacl
->fc_port
= NULL
;
1403 pr_debug("Replacing existing nacl->fc_port and fc_loopid->se_nacl\n");
1404 fc_loopid
->se_nacl
= new_se_nacl
;
1405 if (fc_port
->se_sess
!= se_sess
)
1406 fc_port
->se_sess
= se_sess
;
1407 if (nacl
->fc_port
!= fc_port
)
1408 nacl
->fc_port
= fc_port
;
1412 if (new_se_nacl
== NULL
) {
1413 pr_debug("Clearing fc_loopid->se_nacl\n");
1414 fc_loopid
->se_nacl
= NULL
;
1418 pr_debug("Replacing existing fc_loopid->se_nacl w/o active nacl->fc_port\n");
1419 fc_loopid
->se_nacl
= new_se_nacl
;
1420 if (fc_port
->se_sess
!= se_sess
)
1421 fc_port
->se_sess
= se_sess
;
1422 if (nacl
->fc_port
!= fc_port
)
1423 nacl
->fc_port
= fc_port
;
1425 pr_debug("Setup nacl->fc_port %p by loop_id for se_nacl: %p, initiatorname: %s\n",
1426 nacl
->fc_port
, new_se_nacl
, new_se_nacl
->initiatorname
);
1430 * Should always be called with qla_hw_data->tgt.sess_lock held.
1432 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport
*lport
,
1433 struct tcm_qla2xxx_nacl
*nacl
, struct fc_port
*sess
)
1435 struct se_session
*se_sess
= sess
->se_sess
;
1436 unsigned char be_sid
[3];
1438 be_sid
[0] = sess
->d_id
.b
.domain
;
1439 be_sid
[1] = sess
->d_id
.b
.area
;
1440 be_sid
[2] = sess
->d_id
.b
.al_pa
;
1442 tcm_qla2xxx_set_sess_by_s_id(lport
, NULL
, nacl
, se_sess
,
1444 tcm_qla2xxx_set_sess_by_loop_id(lport
, NULL
, nacl
, se_sess
,
1445 sess
, sess
->loop_id
);
1448 static void tcm_qla2xxx_free_session(struct fc_port
*sess
)
1450 struct qla_tgt
*tgt
= sess
->tgt
;
1451 struct qla_hw_data
*ha
= tgt
->ha
;
1452 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
1453 struct se_session
*se_sess
;
1454 struct tcm_qla2xxx_lport
*lport
;
1456 BUG_ON(in_interrupt());
1458 se_sess
= sess
->se_sess
;
1460 pr_err("struct fc_port->se_sess is NULL\n");
1465 lport
= vha
->vha_tgt
.target_lport_ptr
;
1467 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1471 target_wait_for_sess_cmds(se_sess
);
1473 transport_deregister_session_configfs(sess
->se_sess
);
1474 transport_deregister_session(sess
->se_sess
);
1477 static int tcm_qla2xxx_session_cb(struct se_portal_group
*se_tpg
,
1478 struct se_session
*se_sess
, void *p
)
1480 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1481 struct tcm_qla2xxx_tpg
, se_tpg
);
1482 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
1483 struct qla_hw_data
*ha
= lport
->qla_vha
->hw
;
1484 struct se_node_acl
*se_nacl
= se_sess
->se_node_acl
;
1485 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
1486 struct tcm_qla2xxx_nacl
, se_node_acl
);
1487 struct fc_port
*qlat_sess
= p
;
1488 uint16_t loop_id
= qlat_sess
->loop_id
;
1489 unsigned long flags
;
1490 unsigned char be_sid
[3];
1492 be_sid
[0] = qlat_sess
->d_id
.b
.domain
;
1493 be_sid
[1] = qlat_sess
->d_id
.b
.area
;
1494 be_sid
[2] = qlat_sess
->d_id
.b
.al_pa
;
1497 * And now setup se_nacl and session pointers into HW lport internal
1498 * mappings for fabric S_ID and LOOP_ID.
1500 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1501 tcm_qla2xxx_set_sess_by_s_id(lport
, se_nacl
, nacl
,
1502 se_sess
, qlat_sess
, be_sid
);
1503 tcm_qla2xxx_set_sess_by_loop_id(lport
, se_nacl
, nacl
,
1504 se_sess
, qlat_sess
, loop_id
);
1505 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1511 * Called via qlt_create_sess():ha->qla2x_tmpl->check_initiator_node_acl()
1512 * to locate struct se_node_acl
1514 static int tcm_qla2xxx_check_initiator_node_acl(
1515 scsi_qla_host_t
*vha
,
1516 unsigned char *fc_wwpn
,
1517 struct fc_port
*qlat_sess
)
1519 struct qla_hw_data
*ha
= vha
->hw
;
1520 struct tcm_qla2xxx_lport
*lport
;
1521 struct tcm_qla2xxx_tpg
*tpg
;
1522 struct se_session
*se_sess
;
1523 unsigned char port_name
[36];
1524 int num_tags
= (ha
->cur_fw_xcb_count
) ? ha
->cur_fw_xcb_count
:
1525 TCM_QLA2XXX_DEFAULT_TAGS
;
1527 lport
= vha
->vha_tgt
.target_lport_ptr
;
1529 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1534 * Locate the TPG=1 reference..
1538 pr_err("Unable to lcoate struct tcm_qla2xxx_lport->tpg_1\n");
1542 * Format the FCP Initiator port_name into colon seperated values to
1543 * match the format by tcm_qla2xxx explict ConfigFS NodeACLs.
1545 memset(&port_name
, 0, 36);
1546 snprintf(port_name
, sizeof(port_name
), "%8phC", fc_wwpn
);
1548 * Locate our struct se_node_acl either from an explict NodeACL created
1549 * via ConfigFS, or via running in TPG demo mode.
1551 se_sess
= target_alloc_session(&tpg
->se_tpg
, num_tags
,
1552 sizeof(struct qla_tgt_cmd
),
1553 TARGET_PROT_ALL
, port_name
,
1554 qlat_sess
, tcm_qla2xxx_session_cb
);
1555 if (IS_ERR(se_sess
))
1556 return PTR_ERR(se_sess
);
1561 static void tcm_qla2xxx_update_sess(struct fc_port
*sess
, port_id_t s_id
,
1562 uint16_t loop_id
, bool conf_compl_supported
)
1564 struct qla_tgt
*tgt
= sess
->tgt
;
1565 struct qla_hw_data
*ha
= tgt
->ha
;
1566 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
1567 struct tcm_qla2xxx_lport
*lport
= vha
->vha_tgt
.target_lport_ptr
;
1568 struct se_node_acl
*se_nacl
= sess
->se_sess
->se_node_acl
;
1569 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
1570 struct tcm_qla2xxx_nacl
, se_node_acl
);
1574 if (sess
->loop_id
!= loop_id
|| sess
->d_id
.b24
!= s_id
.b24
)
1575 pr_info("Updating session %p from port %8phC loop_id %d -> %d s_id %x:%x:%x -> %x:%x:%x\n",
1576 sess
, sess
->port_name
,
1577 sess
->loop_id
, loop_id
, sess
->d_id
.b
.domain
,
1578 sess
->d_id
.b
.area
, sess
->d_id
.b
.al_pa
, s_id
.b
.domain
,
1579 s_id
.b
.area
, s_id
.b
.al_pa
);
1581 if (sess
->loop_id
!= loop_id
) {
1583 * Because we can shuffle loop IDs around and we
1584 * update different sessions non-atomically, we might
1585 * have overwritten this session's old loop ID
1586 * already, and we might end up overwriting some other
1587 * session that will be updated later. So we have to
1588 * be extra careful and we can't warn about those things...
1590 if (lport
->lport_loopid_map
[sess
->loop_id
].se_nacl
== se_nacl
)
1591 lport
->lport_loopid_map
[sess
->loop_id
].se_nacl
= NULL
;
1593 lport
->lport_loopid_map
[loop_id
].se_nacl
= se_nacl
;
1595 sess
->loop_id
= loop_id
;
1598 if (sess
->d_id
.b24
!= s_id
.b24
) {
1599 key
= (((u32
) sess
->d_id
.b
.domain
<< 16) |
1600 ((u32
) sess
->d_id
.b
.area
<< 8) |
1601 ((u32
) sess
->d_id
.b
.al_pa
));
1603 if (btree_lookup32(&lport
->lport_fcport_map
, key
))
1604 WARN(btree_remove32(&lport
->lport_fcport_map
, key
) !=
1605 se_nacl
, "Found wrong se_nacl when updating s_id %x:%x:%x\n",
1606 sess
->d_id
.b
.domain
, sess
->d_id
.b
.area
,
1607 sess
->d_id
.b
.al_pa
);
1609 WARN(1, "No lport_fcport_map entry for s_id %x:%x:%x\n",
1610 sess
->d_id
.b
.domain
, sess
->d_id
.b
.area
,
1611 sess
->d_id
.b
.al_pa
);
1613 key
= (((u32
) s_id
.b
.domain
<< 16) |
1614 ((u32
) s_id
.b
.area
<< 8) |
1615 ((u32
) s_id
.b
.al_pa
));
1617 if (btree_lookup32(&lport
->lport_fcport_map
, key
)) {
1618 WARN(1, "Already have lport_fcport_map entry for s_id %x:%x:%x\n",
1619 s_id
.b
.domain
, s_id
.b
.area
, s_id
.b
.al_pa
);
1620 btree_update32(&lport
->lport_fcport_map
, key
, se_nacl
);
1622 btree_insert32(&lport
->lport_fcport_map
, key
, se_nacl
,
1627 nacl
->nport_id
= key
;
1630 sess
->conf_compl_supported
= conf_compl_supported
;
1632 /* Reset logout parameters to default */
1633 sess
->logout_on_delete
= 1;
1634 sess
->keep_nport_handle
= 0;
1638 * Calls into tcm_qla2xxx used by qla2xxx LLD I/O path.
1640 static struct qla_tgt_func_tmpl tcm_qla2xxx_template
= {
1641 .handle_cmd
= tcm_qla2xxx_handle_cmd
,
1642 .handle_data
= tcm_qla2xxx_handle_data
,
1643 .handle_tmr
= tcm_qla2xxx_handle_tmr
,
1644 .free_cmd
= tcm_qla2xxx_free_cmd
,
1645 .free_mcmd
= tcm_qla2xxx_free_mcmd
,
1646 .free_session
= tcm_qla2xxx_free_session
,
1647 .update_sess
= tcm_qla2xxx_update_sess
,
1648 .check_initiator_node_acl
= tcm_qla2xxx_check_initiator_node_acl
,
1649 .find_sess_by_s_id
= tcm_qla2xxx_find_sess_by_s_id
,
1650 .find_sess_by_loop_id
= tcm_qla2xxx_find_sess_by_loop_id
,
1651 .clear_nacl_from_fcport_map
= tcm_qla2xxx_clear_nacl_from_fcport_map
,
1652 .put_sess
= tcm_qla2xxx_put_sess
,
1653 .shutdown_sess
= tcm_qla2xxx_shutdown_sess
,
1654 .get_dif_tags
= tcm_qla2xxx_dif_tags
,
1655 .chk_dif_tags
= tcm_qla2xxx_chk_dif_tags
,
1658 static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport
*lport
)
1662 rc
= btree_init32(&lport
->lport_fcport_map
);
1664 pr_err("Unable to initialize lport->lport_fcport_map btree\n");
1668 lport
->lport_loopid_map
= vmalloc(sizeof(struct tcm_qla2xxx_fc_loopid
) *
1670 if (!lport
->lport_loopid_map
) {
1671 pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n",
1672 sizeof(struct tcm_qla2xxx_fc_loopid
) * 65536);
1673 btree_destroy32(&lport
->lport_fcport_map
);
1676 memset(lport
->lport_loopid_map
, 0, sizeof(struct tcm_qla2xxx_fc_loopid
)
1678 pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n",
1679 sizeof(struct tcm_qla2xxx_fc_loopid
) * 65536);
1683 static int tcm_qla2xxx_lport_register_cb(struct scsi_qla_host
*vha
,
1684 void *target_lport_ptr
,
1685 u64 npiv_wwpn
, u64 npiv_wwnn
)
1687 struct qla_hw_data
*ha
= vha
->hw
;
1688 struct tcm_qla2xxx_lport
*lport
=
1689 (struct tcm_qla2xxx_lport
*)target_lport_ptr
;
1691 * Setup tgt_ops, local pointer to vha and target_lport_ptr
1693 ha
->tgt
.tgt_ops
= &tcm_qla2xxx_template
;
1694 vha
->vha_tgt
.target_lport_ptr
= target_lport_ptr
;
1695 lport
->qla_vha
= vha
;
1700 static struct se_wwn
*tcm_qla2xxx_make_lport(
1701 struct target_fabric_configfs
*tf
,
1702 struct config_group
*group
,
1705 struct tcm_qla2xxx_lport
*lport
;
1709 if (tcm_qla2xxx_parse_wwn(name
, &wwpn
, 1) < 0)
1710 return ERR_PTR(-EINVAL
);
1712 lport
= kzalloc(sizeof(struct tcm_qla2xxx_lport
), GFP_KERNEL
);
1714 pr_err("Unable to allocate struct tcm_qla2xxx_lport\n");
1715 return ERR_PTR(-ENOMEM
);
1717 lport
->lport_wwpn
= wwpn
;
1718 tcm_qla2xxx_format_wwn(&lport
->lport_name
[0], TCM_QLA2XXX_NAMELEN
,
1720 sprintf(lport
->lport_naa_name
, "naa.%016llx", (unsigned long long) wwpn
);
1722 ret
= tcm_qla2xxx_init_lport(lport
);
1726 ret
= qlt_lport_register(lport
, wwpn
, 0, 0,
1727 tcm_qla2xxx_lport_register_cb
);
1731 return &lport
->lport_wwn
;
1733 vfree(lport
->lport_loopid_map
);
1734 btree_destroy32(&lport
->lport_fcport_map
);
1737 return ERR_PTR(ret
);
1740 static void tcm_qla2xxx_drop_lport(struct se_wwn
*wwn
)
1742 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1743 struct tcm_qla2xxx_lport
, lport_wwn
);
1744 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1745 struct se_node_acl
*node
;
1749 * Call into qla2x_target.c LLD logic to complete the
1750 * shutdown of struct qla_tgt after the call to
1751 * qlt_stop_phase1() from tcm_qla2xxx_drop_tpg() above..
1753 if (vha
->vha_tgt
.qla_tgt
&& !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
1754 qlt_stop_phase2(vha
->vha_tgt
.qla_tgt
);
1756 qlt_lport_deregister(vha
);
1758 vfree(lport
->lport_loopid_map
);
1759 btree_for_each_safe32(&lport
->lport_fcport_map
, key
, node
)
1760 btree_remove32(&lport
->lport_fcport_map
, key
);
1761 btree_destroy32(&lport
->lport_fcport_map
);
1765 static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host
*base_vha
,
1766 void *target_lport_ptr
,
1767 u64 npiv_wwpn
, u64 npiv_wwnn
)
1769 struct fc_vport
*vport
;
1770 struct Scsi_Host
*sh
= base_vha
->host
;
1771 struct scsi_qla_host
*npiv_vha
;
1772 struct tcm_qla2xxx_lport
*lport
=
1773 (struct tcm_qla2xxx_lport
*)target_lport_ptr
;
1774 struct tcm_qla2xxx_lport
*base_lport
=
1775 (struct tcm_qla2xxx_lport
*)base_vha
->vha_tgt
.target_lport_ptr
;
1776 struct fc_vport_identifiers vport_id
;
1778 if (qla_ini_mode_enabled(base_vha
)) {
1779 pr_err("qla2xxx base_vha not enabled for target mode\n");
1783 if (!base_lport
|| !base_lport
->tpg_1
||
1784 !atomic_read(&base_lport
->tpg_1
->lport_tpg_enabled
)) {
1785 pr_err("qla2xxx base_lport or tpg_1 not available\n");
1789 memset(&vport_id
, 0, sizeof(vport_id
));
1790 vport_id
.port_name
= npiv_wwpn
;
1791 vport_id
.node_name
= npiv_wwnn
;
1792 vport_id
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
1793 vport_id
.vport_type
= FC_PORTTYPE_NPIV
;
1794 vport_id
.disable
= false;
1796 vport
= fc_vport_create(sh
, 0, &vport_id
);
1798 pr_err("fc_vport_create failed for qla2xxx_npiv\n");
1802 * Setup local pointer to NPIV vhba + target_lport_ptr
1804 npiv_vha
= (struct scsi_qla_host
*)vport
->dd_data
;
1805 npiv_vha
->vha_tgt
.target_lport_ptr
= target_lport_ptr
;
1806 lport
->qla_vha
= npiv_vha
;
1807 scsi_host_get(npiv_vha
->host
);
1812 static struct se_wwn
*tcm_qla2xxx_npiv_make_lport(
1813 struct target_fabric_configfs
*tf
,
1814 struct config_group
*group
,
1817 struct tcm_qla2xxx_lport
*lport
;
1818 u64 phys_wwpn
, npiv_wwpn
, npiv_wwnn
;
1822 snprintf(tmp
, 128, "%s", name
);
1824 p
= strchr(tmp
, '@');
1826 pr_err("Unable to locate NPIV '@' separator\n");
1827 return ERR_PTR(-EINVAL
);
1831 if (tcm_qla2xxx_parse_wwn(tmp
, &phys_wwpn
, 1) < 0)
1832 return ERR_PTR(-EINVAL
);
1834 if (tcm_qla2xxx_npiv_parse_wwn(p
, strlen(p
)+1,
1835 &npiv_wwpn
, &npiv_wwnn
) < 0)
1836 return ERR_PTR(-EINVAL
);
1838 lport
= kzalloc(sizeof(struct tcm_qla2xxx_lport
), GFP_KERNEL
);
1840 pr_err("Unable to allocate struct tcm_qla2xxx_lport for NPIV\n");
1841 return ERR_PTR(-ENOMEM
);
1843 lport
->lport_npiv_wwpn
= npiv_wwpn
;
1844 lport
->lport_npiv_wwnn
= npiv_wwnn
;
1845 sprintf(lport
->lport_naa_name
, "naa.%016llx", (unsigned long long) npiv_wwpn
);
1847 ret
= tcm_qla2xxx_init_lport(lport
);
1851 ret
= qlt_lport_register(lport
, phys_wwpn
, npiv_wwpn
, npiv_wwnn
,
1852 tcm_qla2xxx_lport_register_npiv_cb
);
1856 return &lport
->lport_wwn
;
1858 vfree(lport
->lport_loopid_map
);
1859 btree_destroy32(&lport
->lport_fcport_map
);
1862 return ERR_PTR(ret
);
1865 static void tcm_qla2xxx_npiv_drop_lport(struct se_wwn
*wwn
)
1867 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1868 struct tcm_qla2xxx_lport
, lport_wwn
);
1869 struct scsi_qla_host
*npiv_vha
= lport
->qla_vha
;
1870 struct qla_hw_data
*ha
= npiv_vha
->hw
;
1871 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1873 scsi_host_put(npiv_vha
->host
);
1875 * Notify libfc that we want to release the vha->fc_vport
1877 fc_vport_terminate(npiv_vha
->fc_vport
);
1878 scsi_host_put(base_vha
->host
);
1883 static ssize_t
tcm_qla2xxx_wwn_version_show(struct config_item
*item
,
1886 return sprintf(page
,
1887 "TCM QLOGIC QLA2XXX NPIV capable fabric module %s on %s/%s on %s\n",
1888 QLA2XXX_VERSION
, utsname()->sysname
,
1889 utsname()->machine
, utsname()->release
);
1892 CONFIGFS_ATTR_RO(tcm_qla2xxx_wwn_
, version
);
1894 static struct configfs_attribute
*tcm_qla2xxx_wwn_attrs
[] = {
1895 &tcm_qla2xxx_wwn_attr_version
,
1899 static const struct target_core_fabric_ops tcm_qla2xxx_ops
= {
1900 .module
= THIS_MODULE
,
1902 .node_acl_size
= sizeof(struct tcm_qla2xxx_nacl
),
1904 * XXX: Limit assumes single page per scatter-gather-list entry.
1905 * Current maximum is ~4.9 MB per se_cmd->t_data_sg with PAGE_SIZE=4096
1907 .max_data_sg_nents
= 1200,
1908 .get_fabric_name
= tcm_qla2xxx_get_fabric_name
,
1909 .tpg_get_wwn
= tcm_qla2xxx_get_fabric_wwn
,
1910 .tpg_get_tag
= tcm_qla2xxx_get_tag
,
1911 .tpg_check_demo_mode
= tcm_qla2xxx_check_demo_mode
,
1912 .tpg_check_demo_mode_cache
= tcm_qla2xxx_check_demo_mode_cache
,
1913 .tpg_check_demo_mode_write_protect
=
1914 tcm_qla2xxx_check_demo_write_protect
,
1915 .tpg_check_prod_mode_write_protect
=
1916 tcm_qla2xxx_check_prod_write_protect
,
1917 .tpg_check_prot_fabric_only
= tcm_qla2xxx_check_prot_fabric_only
,
1918 .tpg_check_demo_mode_login_only
= tcm_qla2xxx_check_demo_mode_login_only
,
1919 .tpg_get_inst_index
= tcm_qla2xxx_tpg_get_inst_index
,
1920 .check_stop_free
= tcm_qla2xxx_check_stop_free
,
1921 .release_cmd
= tcm_qla2xxx_release_cmd
,
1922 .close_session
= tcm_qla2xxx_close_session
,
1923 .sess_get_index
= tcm_qla2xxx_sess_get_index
,
1924 .sess_get_initiator_sid
= NULL
,
1925 .write_pending
= tcm_qla2xxx_write_pending
,
1926 .write_pending_status
= tcm_qla2xxx_write_pending_status
,
1927 .set_default_node_attributes
= tcm_qla2xxx_set_default_node_attrs
,
1928 .get_cmd_state
= tcm_qla2xxx_get_cmd_state
,
1929 .queue_data_in
= tcm_qla2xxx_queue_data_in
,
1930 .queue_status
= tcm_qla2xxx_queue_status
,
1931 .queue_tm_rsp
= tcm_qla2xxx_queue_tm_rsp
,
1932 .aborted_task
= tcm_qla2xxx_aborted_task
,
1934 * Setup function pointers for generic logic in
1935 * target_core_fabric_configfs.c
1937 .fabric_make_wwn
= tcm_qla2xxx_make_lport
,
1938 .fabric_drop_wwn
= tcm_qla2xxx_drop_lport
,
1939 .fabric_make_tpg
= tcm_qla2xxx_make_tpg
,
1940 .fabric_drop_tpg
= tcm_qla2xxx_drop_tpg
,
1941 .fabric_init_nodeacl
= tcm_qla2xxx_init_nodeacl
,
1943 .tfc_wwn_attrs
= tcm_qla2xxx_wwn_attrs
,
1944 .tfc_tpg_base_attrs
= tcm_qla2xxx_tpg_attrs
,
1945 .tfc_tpg_attrib_attrs
= tcm_qla2xxx_tpg_attrib_attrs
,
1948 static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops
= {
1949 .module
= THIS_MODULE
,
1950 .name
= "qla2xxx_npiv",
1951 .node_acl_size
= sizeof(struct tcm_qla2xxx_nacl
),
1952 .get_fabric_name
= tcm_qla2xxx_npiv_get_fabric_name
,
1953 .tpg_get_wwn
= tcm_qla2xxx_get_fabric_wwn
,
1954 .tpg_get_tag
= tcm_qla2xxx_get_tag
,
1955 .tpg_check_demo_mode
= tcm_qla2xxx_check_demo_mode
,
1956 .tpg_check_demo_mode_cache
= tcm_qla2xxx_check_demo_mode_cache
,
1957 .tpg_check_demo_mode_write_protect
= tcm_qla2xxx_check_demo_mode
,
1958 .tpg_check_prod_mode_write_protect
=
1959 tcm_qla2xxx_check_prod_write_protect
,
1960 .tpg_check_demo_mode_login_only
= tcm_qla2xxx_check_demo_mode_login_only
,
1961 .tpg_get_inst_index
= tcm_qla2xxx_tpg_get_inst_index
,
1962 .check_stop_free
= tcm_qla2xxx_check_stop_free
,
1963 .release_cmd
= tcm_qla2xxx_release_cmd
,
1964 .close_session
= tcm_qla2xxx_close_session
,
1965 .sess_get_index
= tcm_qla2xxx_sess_get_index
,
1966 .sess_get_initiator_sid
= NULL
,
1967 .write_pending
= tcm_qla2xxx_write_pending
,
1968 .write_pending_status
= tcm_qla2xxx_write_pending_status
,
1969 .set_default_node_attributes
= tcm_qla2xxx_set_default_node_attrs
,
1970 .get_cmd_state
= tcm_qla2xxx_get_cmd_state
,
1971 .queue_data_in
= tcm_qla2xxx_queue_data_in
,
1972 .queue_status
= tcm_qla2xxx_queue_status
,
1973 .queue_tm_rsp
= tcm_qla2xxx_queue_tm_rsp
,
1974 .aborted_task
= tcm_qla2xxx_aborted_task
,
1976 * Setup function pointers for generic logic in
1977 * target_core_fabric_configfs.c
1979 .fabric_make_wwn
= tcm_qla2xxx_npiv_make_lport
,
1980 .fabric_drop_wwn
= tcm_qla2xxx_npiv_drop_lport
,
1981 .fabric_make_tpg
= tcm_qla2xxx_npiv_make_tpg
,
1982 .fabric_drop_tpg
= tcm_qla2xxx_drop_tpg
,
1983 .fabric_init_nodeacl
= tcm_qla2xxx_init_nodeacl
,
1985 .tfc_wwn_attrs
= tcm_qla2xxx_wwn_attrs
,
1986 .tfc_tpg_base_attrs
= tcm_qla2xxx_npiv_tpg_attrs
,
1989 static int tcm_qla2xxx_register_configfs(void)
1993 pr_debug("TCM QLOGIC QLA2XXX fabric module %s on %s/%s on %s\n",
1994 QLA2XXX_VERSION
, utsname()->sysname
,
1995 utsname()->machine
, utsname()->release
);
1997 ret
= target_register_template(&tcm_qla2xxx_ops
);
2001 ret
= target_register_template(&tcm_qla2xxx_npiv_ops
);
2005 tcm_qla2xxx_free_wq
= alloc_workqueue("tcm_qla2xxx_free",
2007 if (!tcm_qla2xxx_free_wq
) {
2009 goto out_fabric_npiv
;
2012 tcm_qla2xxx_cmd_wq
= alloc_workqueue("tcm_qla2xxx_cmd", 0, 0);
2013 if (!tcm_qla2xxx_cmd_wq
) {
2021 destroy_workqueue(tcm_qla2xxx_free_wq
);
2023 target_unregister_template(&tcm_qla2xxx_npiv_ops
);
2025 target_unregister_template(&tcm_qla2xxx_ops
);
2029 static void tcm_qla2xxx_deregister_configfs(void)
2031 destroy_workqueue(tcm_qla2xxx_cmd_wq
);
2032 destroy_workqueue(tcm_qla2xxx_free_wq
);
2034 target_unregister_template(&tcm_qla2xxx_ops
);
2035 target_unregister_template(&tcm_qla2xxx_npiv_ops
);
2038 static int __init
tcm_qla2xxx_init(void)
2042 ret
= tcm_qla2xxx_register_configfs();
2049 static void __exit
tcm_qla2xxx_exit(void)
2051 tcm_qla2xxx_deregister_configfs();
2054 MODULE_DESCRIPTION("TCM QLA24XX+ series NPIV enabled fabric driver");
2055 MODULE_LICENSE("GPL");
2056 module_init(tcm_qla2xxx_init
);
2057 module_exit(tcm_qla2xxx_exit
);