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 <generated/utsrelease.h>
29 #include <linux/utsname.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>
45 #include <target/target_core_fabric_configfs.h>
46 #include <target/target_core_configfs.h>
47 #include <target/configfs_macros.h>
50 #include "qla_target.h"
51 #include "tcm_qla2xxx.h"
53 struct workqueue_struct
*tcm_qla2xxx_free_wq
;
54 struct workqueue_struct
*tcm_qla2xxx_cmd_wq
;
58 * If strict, we require lower-case hex and colon separators to be sure
59 * the name is the same as what would be generated by ft_format_wwn()
60 * so the name and wwn are mapped one-to-one.
62 static ssize_t
tcm_qla2xxx_parse_wwn(const char *name
, u64
*wwn
, int strict
)
72 for (cp
= name
; cp
< &name
[TCM_QLA2XXX_NAMELEN
- 1]; cp
++) {
74 if (c
== '\n' && cp
[1] == '\0')
76 if (strict
&& pos
++ == 2 && byte
++ < 7) {
85 if (strict
&& byte
!= 8)
92 else if (isxdigit(c
) && (islower(c
) || !strict
))
93 nibble
= tolower(c
) - 'a' + 10;
96 *wwn
= (*wwn
<< 4) | nibble
;
100 pr_debug("err %u len %zu pos %u byte %u\n",
101 err
, cp
- name
, pos
, byte
);
105 static ssize_t
tcm_qla2xxx_format_wwn(char *buf
, size_t len
, u64 wwn
)
109 put_unaligned_be64(wwn
, b
);
110 return snprintf(buf
, len
,
111 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
112 b
[0], b
[1], b
[2], b
[3], b
[4], b
[5], b
[6], b
[7]);
115 static char *tcm_qla2xxx_get_fabric_name(void)
121 * From drivers/scsi/scsi_transport_fc.c:fc_parse_wwn
123 static int tcm_qla2xxx_npiv_extract_wwn(const char *ns
, u64
*nm
)
128 memset(wwn
, 0, sizeof(wwn
));
130 /* Validate and store the new name */
131 for (i
= 0, j
= 0; i
< 16; i
++) {
134 value
= hex_to_bin(*ns
++);
136 j
= (j
<< 4) | value
;
146 *nm
= wwn_to_u64(wwn
);
151 * This parsing logic follows drivers/scsi/scsi_transport_fc.c:
152 * store_fc_host_vport_create()
154 static int tcm_qla2xxx_npiv_parse_wwn(
160 unsigned int cnt
= count
;
166 /* count may include a LF at end of string */
167 if (name
[cnt
-1] == '\n' || name
[cnt
-1] == 0)
170 /* validate we have enough characters for WWPN */
171 if ((cnt
!= (16+1+16)) || (name
[16] != ':'))
174 rc
= tcm_qla2xxx_npiv_extract_wwn(&name
[0], wwpn
);
178 rc
= tcm_qla2xxx_npiv_extract_wwn(&name
[17], wwnn
);
185 static char *tcm_qla2xxx_npiv_get_fabric_name(void)
187 return "qla2xxx_npiv";
190 static u8
tcm_qla2xxx_get_fabric_proto_ident(struct se_portal_group
*se_tpg
)
192 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
193 struct tcm_qla2xxx_tpg
, se_tpg
);
194 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
197 switch (lport
->lport_proto_id
) {
198 case SCSI_PROTOCOL_FCP
:
200 proto_id
= fc_get_fabric_proto_ident(se_tpg
);
207 static char *tcm_qla2xxx_get_fabric_wwn(struct se_portal_group
*se_tpg
)
209 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
210 struct tcm_qla2xxx_tpg
, se_tpg
);
211 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
213 return lport
->lport_naa_name
;
216 static u16
tcm_qla2xxx_get_tag(struct se_portal_group
*se_tpg
)
218 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
219 struct tcm_qla2xxx_tpg
, se_tpg
);
220 return tpg
->lport_tpgt
;
223 static u32
tcm_qla2xxx_get_default_depth(struct se_portal_group
*se_tpg
)
228 static u32
tcm_qla2xxx_get_pr_transport_id(
229 struct se_portal_group
*se_tpg
,
230 struct se_node_acl
*se_nacl
,
231 struct t10_pr_registration
*pr_reg
,
235 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
236 struct tcm_qla2xxx_tpg
, se_tpg
);
237 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
240 switch (lport
->lport_proto_id
) {
241 case SCSI_PROTOCOL_FCP
:
243 ret
= fc_get_pr_transport_id(se_tpg
, se_nacl
, pr_reg
,
251 static u32
tcm_qla2xxx_get_pr_transport_id_len(
252 struct se_portal_group
*se_tpg
,
253 struct se_node_acl
*se_nacl
,
254 struct t10_pr_registration
*pr_reg
,
257 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
258 struct tcm_qla2xxx_tpg
, se_tpg
);
259 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
262 switch (lport
->lport_proto_id
) {
263 case SCSI_PROTOCOL_FCP
:
265 ret
= fc_get_pr_transport_id_len(se_tpg
, se_nacl
, pr_reg
,
273 static char *tcm_qla2xxx_parse_pr_out_transport_id(
274 struct se_portal_group
*se_tpg
,
277 char **port_nexus_ptr
)
279 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
280 struct tcm_qla2xxx_tpg
, se_tpg
);
281 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
284 switch (lport
->lport_proto_id
) {
285 case SCSI_PROTOCOL_FCP
:
287 tid
= fc_parse_pr_out_transport_id(se_tpg
, buf
, out_tid_len
,
295 static int tcm_qla2xxx_check_demo_mode(struct se_portal_group
*se_tpg
)
297 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
298 struct tcm_qla2xxx_tpg
, se_tpg
);
300 return tpg
->tpg_attrib
.generate_node_acls
;
303 static int tcm_qla2xxx_check_demo_mode_cache(struct se_portal_group
*se_tpg
)
305 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
306 struct tcm_qla2xxx_tpg
, se_tpg
);
308 return tpg
->tpg_attrib
.cache_dynamic_acls
;
311 static int tcm_qla2xxx_check_demo_write_protect(struct se_portal_group
*se_tpg
)
313 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
314 struct tcm_qla2xxx_tpg
, se_tpg
);
316 return tpg
->tpg_attrib
.demo_mode_write_protect
;
319 static int tcm_qla2xxx_check_prod_write_protect(struct se_portal_group
*se_tpg
)
321 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
322 struct tcm_qla2xxx_tpg
, se_tpg
);
324 return tpg
->tpg_attrib
.prod_mode_write_protect
;
327 static int tcm_qla2xxx_check_demo_mode_login_only(struct se_portal_group
*se_tpg
)
329 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
330 struct tcm_qla2xxx_tpg
, se_tpg
);
332 return tpg
->tpg_attrib
.demo_mode_login_only
;
335 static struct se_node_acl
*tcm_qla2xxx_alloc_fabric_acl(
336 struct se_portal_group
*se_tpg
)
338 struct tcm_qla2xxx_nacl
*nacl
;
340 nacl
= kzalloc(sizeof(struct tcm_qla2xxx_nacl
), GFP_KERNEL
);
342 pr_err("Unable to allocate struct tcm_qla2xxx_nacl\n");
346 return &nacl
->se_node_acl
;
349 static void tcm_qla2xxx_release_fabric_acl(
350 struct se_portal_group
*se_tpg
,
351 struct se_node_acl
*se_nacl
)
353 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
354 struct tcm_qla2xxx_nacl
, se_node_acl
);
358 static u32
tcm_qla2xxx_tpg_get_inst_index(struct se_portal_group
*se_tpg
)
360 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
361 struct tcm_qla2xxx_tpg
, se_tpg
);
363 return tpg
->lport_tpgt
;
366 static void tcm_qla2xxx_complete_mcmd(struct work_struct
*work
)
368 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(work
,
369 struct qla_tgt_mgmt_cmd
, free_work
);
371 transport_generic_free_cmd(&mcmd
->se_cmd
, 0);
375 * Called from qla_target_template->free_mcmd(), and will call
376 * tcm_qla2xxx_release_cmd() via normal struct target_core_fabric_ops
377 * release callback. qla_hw_data->hardware_lock is expected to be held
379 static void tcm_qla2xxx_free_mcmd(struct qla_tgt_mgmt_cmd
*mcmd
)
381 INIT_WORK(&mcmd
->free_work
, tcm_qla2xxx_complete_mcmd
);
382 queue_work(tcm_qla2xxx_free_wq
, &mcmd
->free_work
);
385 static void tcm_qla2xxx_complete_free(struct work_struct
*work
)
387 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
389 transport_generic_free_cmd(&cmd
->se_cmd
, 0);
393 * Called from qla_target_template->free_cmd(), and will call
394 * tcm_qla2xxx_release_cmd via normal struct target_core_fabric_ops
395 * release callback. qla_hw_data->hardware_lock is expected to be held
397 static void tcm_qla2xxx_free_cmd(struct qla_tgt_cmd
*cmd
)
399 INIT_WORK(&cmd
->work
, tcm_qla2xxx_complete_free
);
400 queue_work(tcm_qla2xxx_free_wq
, &cmd
->work
);
404 * Called from struct target_core_fabric_ops->check_stop_free() context
406 static int tcm_qla2xxx_check_stop_free(struct se_cmd
*se_cmd
)
408 return target_put_sess_cmd(se_cmd
->se_sess
, se_cmd
);
411 /* tcm_qla2xxx_release_cmd - Callback from TCM Core to release underlying
412 * fabric descriptor @se_cmd command to release
414 static void tcm_qla2xxx_release_cmd(struct se_cmd
*se_cmd
)
416 struct qla_tgt_cmd
*cmd
;
418 if (se_cmd
->se_cmd_flags
& SCF_SCSI_TMR_CDB
) {
419 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(se_cmd
,
420 struct qla_tgt_mgmt_cmd
, se_cmd
);
425 cmd
= container_of(se_cmd
, struct qla_tgt_cmd
, se_cmd
);
429 static int tcm_qla2xxx_shutdown_session(struct se_session
*se_sess
)
431 struct qla_tgt_sess
*sess
= se_sess
->fabric_sess_ptr
;
432 struct scsi_qla_host
*vha
;
438 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
439 target_sess_cmd_list_set_waiting(se_sess
);
440 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
445 static void tcm_qla2xxx_close_session(struct se_session
*se_sess
)
447 struct qla_tgt_sess
*sess
= se_sess
->fabric_sess_ptr
;
448 struct scsi_qla_host
*vha
;
454 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
455 qlt_unreg_sess(sess
);
456 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
459 static u32
tcm_qla2xxx_sess_get_index(struct se_session
*se_sess
)
464 static int tcm_qla2xxx_write_pending(struct se_cmd
*se_cmd
)
466 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
467 struct qla_tgt_cmd
, se_cmd
);
469 cmd
->bufflen
= se_cmd
->data_length
;
470 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
472 cmd
->sg_cnt
= se_cmd
->t_data_nents
;
473 cmd
->sg
= se_cmd
->t_data_sg
;
475 cmd
->prot_sg_cnt
= se_cmd
->t_prot_nents
;
476 cmd
->prot_sg
= se_cmd
->t_prot_sg
;
477 cmd
->blk_sz
= se_cmd
->se_dev
->dev_attrib
.block_size
;
481 * qla_target.c:qlt_rdy_to_xfer() will call pci_map_sg() to setup
482 * the SGL mappings into PCIe memory for incoming FCP WRITE data.
484 return qlt_rdy_to_xfer(cmd
);
487 static int tcm_qla2xxx_write_pending_status(struct se_cmd
*se_cmd
)
491 * Check for WRITE_PENDING status to determine if we need to wait for
492 * CTIO aborts to be posted via hardware in tcm_qla2xxx_handle_data().
494 spin_lock_irqsave(&se_cmd
->t_state_lock
, flags
);
495 if (se_cmd
->t_state
== TRANSPORT_WRITE_PENDING
||
496 se_cmd
->t_state
== TRANSPORT_COMPLETE_QF_WP
) {
497 spin_unlock_irqrestore(&se_cmd
->t_state_lock
, flags
);
498 wait_for_completion_timeout(&se_cmd
->t_transport_stop_comp
,
502 spin_unlock_irqrestore(&se_cmd
->t_state_lock
, flags
);
507 static void tcm_qla2xxx_set_default_node_attrs(struct se_node_acl
*nacl
)
512 static u32
tcm_qla2xxx_get_task_tag(struct se_cmd
*se_cmd
)
514 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
515 struct qla_tgt_cmd
, se_cmd
);
520 static int tcm_qla2xxx_get_cmd_state(struct se_cmd
*se_cmd
)
526 * Called from process context in qla_target.c:qlt_do_work() code
528 static int tcm_qla2xxx_handle_cmd(scsi_qla_host_t
*vha
, struct qla_tgt_cmd
*cmd
,
529 unsigned char *cdb
, uint32_t data_length
, int fcp_task_attr
,
530 int data_dir
, int bidi
)
532 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
533 struct se_session
*se_sess
;
534 struct qla_tgt_sess
*sess
;
535 int flags
= TARGET_SCF_ACK_KREF
;
538 flags
|= TARGET_SCF_BIDI_OP
;
542 pr_err("Unable to locate struct qla_tgt_sess from qla_tgt_cmd\n");
546 se_sess
= sess
->se_sess
;
548 pr_err("Unable to locate active struct se_session\n");
552 return target_submit_cmd(se_cmd
, se_sess
, cdb
, &cmd
->sense_buffer
[0],
553 cmd
->unpacked_lun
, data_length
, fcp_task_attr
,
557 static void tcm_qla2xxx_handle_data_work(struct work_struct
*work
)
559 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
562 * Ensure that the complete FCP WRITE payload has been received.
563 * Otherwise return an exception via CHECK_CONDITION status.
565 if (!cmd
->write_data_transferred
) {
567 * Check if se_cmd has already been aborted via LUN_RESET, and
568 * waiting upon completion in tcm_qla2xxx_write_pending_status()
570 if (cmd
->se_cmd
.transport_state
& CMD_T_ABORTED
) {
571 complete(&cmd
->se_cmd
.t_transport_stop_comp
);
575 if (cmd
->se_cmd
.pi_err
)
576 transport_generic_request_failure(&cmd
->se_cmd
,
579 transport_generic_request_failure(&cmd
->se_cmd
,
580 TCM_CHECK_CONDITION_ABORT_CMD
);
585 return target_execute_cmd(&cmd
->se_cmd
);
589 * Called from qla_target.c:qlt_do_ctio_completion()
591 static void tcm_qla2xxx_handle_data(struct qla_tgt_cmd
*cmd
)
593 INIT_WORK(&cmd
->work
, tcm_qla2xxx_handle_data_work
);
594 queue_work(tcm_qla2xxx_free_wq
, &cmd
->work
);
597 static void tcm_qla2xxx_handle_dif_work(struct work_struct
*work
)
599 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
601 /* take an extra kref to prevent cmd free too early.
602 * need to wait for SCSI status/check condition to
603 * finish responding generate by transport_generic_request_failure.
605 kref_get(&cmd
->se_cmd
.cmd_kref
);
606 transport_generic_request_failure(&cmd
->se_cmd
, cmd
->se_cmd
.pi_err
);
610 * Called from qla_target.c:qlt_do_ctio_completion()
612 static void tcm_qla2xxx_handle_dif_err(struct qla_tgt_cmd
*cmd
)
614 INIT_WORK(&cmd
->work
, tcm_qla2xxx_handle_dif_work
);
615 queue_work(tcm_qla2xxx_free_wq
, &cmd
->work
);
619 * Called from qla_target.c:qlt_issue_task_mgmt()
621 static int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd
*mcmd
, uint32_t lun
,
622 uint8_t tmr_func
, uint32_t tag
)
624 struct qla_tgt_sess
*sess
= mcmd
->sess
;
625 struct se_cmd
*se_cmd
= &mcmd
->se_cmd
;
627 return target_submit_tmr(se_cmd
, sess
->se_sess
, NULL
, lun
, mcmd
,
628 tmr_func
, GFP_ATOMIC
, tag
, TARGET_SCF_ACK_KREF
);
631 static int tcm_qla2xxx_queue_data_in(struct se_cmd
*se_cmd
)
633 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
634 struct qla_tgt_cmd
, se_cmd
);
636 cmd
->bufflen
= se_cmd
->data_length
;
637 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
638 cmd
->aborted
= (se_cmd
->transport_state
& CMD_T_ABORTED
);
640 cmd
->sg_cnt
= se_cmd
->t_data_nents
;
641 cmd
->sg
= se_cmd
->t_data_sg
;
644 cmd
->prot_sg_cnt
= se_cmd
->t_prot_nents
;
645 cmd
->prot_sg
= se_cmd
->t_prot_sg
;
646 cmd
->blk_sz
= se_cmd
->se_dev
->dev_attrib
.block_size
;
650 * Now queue completed DATA_IN the qla2xxx LLD and response ring
652 return qlt_xmit_response(cmd
, QLA_TGT_XMIT_DATA
|QLA_TGT_XMIT_STATUS
,
653 se_cmd
->scsi_status
);
656 static int tcm_qla2xxx_queue_status(struct se_cmd
*se_cmd
)
658 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
659 struct qla_tgt_cmd
, se_cmd
);
660 int xmit_type
= QLA_TGT_XMIT_STATUS
;
662 cmd
->bufflen
= se_cmd
->data_length
;
666 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
667 cmd
->aborted
= (se_cmd
->transport_state
& CMD_T_ABORTED
);
669 if (se_cmd
->data_direction
== DMA_FROM_DEVICE
) {
671 * For FCP_READ with CHECK_CONDITION status, clear cmd->bufflen
672 * for qla_tgt_xmit_response LLD code
674 if (se_cmd
->se_cmd_flags
& SCF_OVERFLOW_BIT
) {
675 se_cmd
->se_cmd_flags
&= ~SCF_OVERFLOW_BIT
;
676 se_cmd
->residual_count
= 0;
678 se_cmd
->se_cmd_flags
|= SCF_UNDERFLOW_BIT
;
679 se_cmd
->residual_count
+= se_cmd
->data_length
;
684 * Now queue status response to qla2xxx LLD code and response ring
686 return qlt_xmit_response(cmd
, xmit_type
, se_cmd
->scsi_status
);
689 static void tcm_qla2xxx_queue_tm_rsp(struct se_cmd
*se_cmd
)
691 struct se_tmr_req
*se_tmr
= se_cmd
->se_tmr_req
;
692 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(se_cmd
,
693 struct qla_tgt_mgmt_cmd
, se_cmd
);
695 pr_debug("queue_tm_rsp: mcmd: %p func: 0x%02x response: 0x%02x\n",
696 mcmd
, se_tmr
->function
, se_tmr
->response
);
698 * Do translation between TCM TM response codes and
699 * QLA2xxx FC TM response codes.
701 switch (se_tmr
->response
) {
702 case TMR_FUNCTION_COMPLETE
:
703 mcmd
->fc_tm_rsp
= FC_TM_SUCCESS
;
705 case TMR_TASK_DOES_NOT_EXIST
:
706 mcmd
->fc_tm_rsp
= FC_TM_BAD_CMD
;
708 case TMR_FUNCTION_REJECTED
:
709 mcmd
->fc_tm_rsp
= FC_TM_REJECT
;
711 case TMR_LUN_DOES_NOT_EXIST
:
713 mcmd
->fc_tm_rsp
= FC_TM_FAILED
;
717 * Queue the TM response to QLA2xxx LLD to build a
718 * CTIO response packet.
720 qlt_xmit_tm_rsp(mcmd
);
723 static void tcm_qla2xxx_aborted_task(struct se_cmd
*se_cmd
)
725 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
726 struct qla_tgt_cmd
, se_cmd
);
727 struct scsi_qla_host
*vha
= cmd
->vha
;
728 struct qla_hw_data
*ha
= vha
->hw
;
733 pci_unmap_sg(ha
->pdev
, cmd
->sg
, cmd
->sg_cnt
, cmd
->dma_data_direction
);
737 /* Local pointer to allocated TCM configfs fabric module */
738 struct target_fabric_configfs
*tcm_qla2xxx_fabric_configfs
;
739 struct target_fabric_configfs
*tcm_qla2xxx_npiv_fabric_configfs
;
741 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport
*,
742 struct tcm_qla2xxx_nacl
*, struct qla_tgt_sess
*);
744 * Expected to be called with struct qla_hw_data->hardware_lock held
746 static void tcm_qla2xxx_clear_nacl_from_fcport_map(struct qla_tgt_sess
*sess
)
748 struct se_node_acl
*se_nacl
= sess
->se_sess
->se_node_acl
;
749 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
750 struct se_wwn
*se_wwn
= se_tpg
->se_tpg_wwn
;
751 struct tcm_qla2xxx_lport
*lport
= container_of(se_wwn
,
752 struct tcm_qla2xxx_lport
, lport_wwn
);
753 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
754 struct tcm_qla2xxx_nacl
, se_node_acl
);
757 pr_debug("fc_rport domain: port_id 0x%06x\n", nacl
->nport_id
);
759 node
= btree_remove32(&lport
->lport_fcport_map
, nacl
->nport_id
);
760 WARN_ON(node
&& (node
!= se_nacl
));
762 pr_debug("Removed from fcport_map: %p for WWNN: 0x%016LX, port_id: 0x%06x\n",
763 se_nacl
, nacl
->nport_wwnn
, nacl
->nport_id
);
765 * Now clear the se_nacl and session pointers from our HW lport lookup
766 * table mapping for this initiator's fabric S_ID and LOOP_ID entries.
768 * This is done ahead of callbacks into tcm_qla2xxx_free_session() ->
769 * target_wait_for_sess_cmds() before the session waits for outstanding
770 * I/O to complete, to avoid a race between session shutdown execution
771 * and incoming ATIOs or TMRs picking up a stale se_node_act reference.
773 tcm_qla2xxx_clear_sess_lookup(lport
, nacl
, sess
);
776 static void tcm_qla2xxx_release_session(struct kref
*kref
)
778 struct se_session
*se_sess
= container_of(kref
,
779 struct se_session
, sess_kref
);
781 qlt_unreg_sess(se_sess
->fabric_sess_ptr
);
784 static void tcm_qla2xxx_put_session(struct se_session
*se_sess
)
786 struct qla_tgt_sess
*sess
= se_sess
->fabric_sess_ptr
;
787 struct qla_hw_data
*ha
= sess
->vha
->hw
;
790 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
791 kref_put(&se_sess
->sess_kref
, tcm_qla2xxx_release_session
);
792 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
795 static void tcm_qla2xxx_put_sess(struct qla_tgt_sess
*sess
)
800 assert_spin_locked(&sess
->vha
->hw
->hardware_lock
);
801 kref_put(&sess
->se_sess
->sess_kref
, tcm_qla2xxx_release_session
);
804 static void tcm_qla2xxx_shutdown_sess(struct qla_tgt_sess
*sess
)
806 assert_spin_locked(&sess
->vha
->hw
->hardware_lock
);
807 target_sess_cmd_list_set_waiting(sess
->se_sess
);
810 static struct se_node_acl
*tcm_qla2xxx_make_nodeacl(
811 struct se_portal_group
*se_tpg
,
812 struct config_group
*group
,
815 struct se_node_acl
*se_nacl
, *se_nacl_new
;
816 struct tcm_qla2xxx_nacl
*nacl
;
818 u32 qla2xxx_nexus_depth
;
820 if (tcm_qla2xxx_parse_wwn(name
, &wwnn
, 1) < 0)
821 return ERR_PTR(-EINVAL
);
823 se_nacl_new
= tcm_qla2xxx_alloc_fabric_acl(se_tpg
);
825 return ERR_PTR(-ENOMEM
);
826 /* #warning FIXME: Hardcoded qla2xxx_nexus depth in tcm_qla2xxx_make_nodeacl */
827 qla2xxx_nexus_depth
= 1;
830 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
831 * when converting a NodeACL from demo mode -> explict
833 se_nacl
= core_tpg_add_initiator_node_acl(se_tpg
, se_nacl_new
,
834 name
, qla2xxx_nexus_depth
);
835 if (IS_ERR(se_nacl
)) {
836 tcm_qla2xxx_release_fabric_acl(se_tpg
, se_nacl_new
);
840 * Locate our struct tcm_qla2xxx_nacl and set the FC Nport WWPN
842 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
843 nacl
->nport_wwnn
= wwnn
;
844 tcm_qla2xxx_format_wwn(&nacl
->nport_name
[0], TCM_QLA2XXX_NAMELEN
, wwnn
);
849 static void tcm_qla2xxx_drop_nodeacl(struct se_node_acl
*se_acl
)
851 struct se_portal_group
*se_tpg
= se_acl
->se_tpg
;
852 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_acl
,
853 struct tcm_qla2xxx_nacl
, se_node_acl
);
855 core_tpg_del_initiator_node_acl(se_tpg
, se_acl
, 1);
859 /* Start items for tcm_qla2xxx_tpg_attrib_cit */
861 #define DEF_QLA_TPG_ATTRIB(name) \
863 static ssize_t tcm_qla2xxx_tpg_attrib_show_##name( \
864 struct se_portal_group *se_tpg, \
867 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
868 struct tcm_qla2xxx_tpg, se_tpg); \
870 return sprintf(page, "%u\n", tpg->tpg_attrib.name); \
873 static ssize_t tcm_qla2xxx_tpg_attrib_store_##name( \
874 struct se_portal_group *se_tpg, \
878 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
879 struct tcm_qla2xxx_tpg, se_tpg); \
883 ret = kstrtoul(page, 0, &val); \
885 pr_err("kstrtoul() failed with" \
886 " ret: %d\n", ret); \
889 ret = tcm_qla2xxx_set_attrib_##name(tpg, val); \
891 return (!ret) ? count : -EINVAL; \
894 #define DEF_QLA_TPG_ATTR_BOOL(_name) \
896 static int tcm_qla2xxx_set_attrib_##_name( \
897 struct tcm_qla2xxx_tpg *tpg, \
900 struct tcm_qla2xxx_tpg_attrib *a = &tpg->tpg_attrib; \
902 if ((val != 0) && (val != 1)) { \
903 pr_err("Illegal boolean value %lu\n", val); \
911 #define QLA_TPG_ATTR(_name, _mode) \
912 TF_TPG_ATTRIB_ATTR(tcm_qla2xxx, _name, _mode);
915 * Define tcm_qla2xxx_tpg_attrib_s_generate_node_acls
917 DEF_QLA_TPG_ATTR_BOOL(generate_node_acls
);
918 DEF_QLA_TPG_ATTRIB(generate_node_acls
);
919 QLA_TPG_ATTR(generate_node_acls
, S_IRUGO
| S_IWUSR
);
922 Define tcm_qla2xxx_attrib_s_cache_dynamic_acls
924 DEF_QLA_TPG_ATTR_BOOL(cache_dynamic_acls
);
925 DEF_QLA_TPG_ATTRIB(cache_dynamic_acls
);
926 QLA_TPG_ATTR(cache_dynamic_acls
, S_IRUGO
| S_IWUSR
);
929 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_write_protect
931 DEF_QLA_TPG_ATTR_BOOL(demo_mode_write_protect
);
932 DEF_QLA_TPG_ATTRIB(demo_mode_write_protect
);
933 QLA_TPG_ATTR(demo_mode_write_protect
, S_IRUGO
| S_IWUSR
);
936 * Define tcm_qla2xxx_tpg_attrib_s_prod_mode_write_protect
938 DEF_QLA_TPG_ATTR_BOOL(prod_mode_write_protect
);
939 DEF_QLA_TPG_ATTRIB(prod_mode_write_protect
);
940 QLA_TPG_ATTR(prod_mode_write_protect
, S_IRUGO
| S_IWUSR
);
943 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_login_only
945 DEF_QLA_TPG_ATTR_BOOL(demo_mode_login_only
);
946 DEF_QLA_TPG_ATTRIB(demo_mode_login_only
);
947 QLA_TPG_ATTR(demo_mode_login_only
, S_IRUGO
| S_IWUSR
);
949 static struct configfs_attribute
*tcm_qla2xxx_tpg_attrib_attrs
[] = {
950 &tcm_qla2xxx_tpg_attrib_generate_node_acls
.attr
,
951 &tcm_qla2xxx_tpg_attrib_cache_dynamic_acls
.attr
,
952 &tcm_qla2xxx_tpg_attrib_demo_mode_write_protect
.attr
,
953 &tcm_qla2xxx_tpg_attrib_prod_mode_write_protect
.attr
,
954 &tcm_qla2xxx_tpg_attrib_demo_mode_login_only
.attr
,
958 /* End items for tcm_qla2xxx_tpg_attrib_cit */
960 static ssize_t
tcm_qla2xxx_tpg_show_enable(
961 struct se_portal_group
*se_tpg
,
964 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
965 struct tcm_qla2xxx_tpg
, se_tpg
);
967 return snprintf(page
, PAGE_SIZE
, "%d\n",
968 atomic_read(&tpg
->lport_tpg_enabled
));
971 static void tcm_qla2xxx_depend_tpg(struct work_struct
*work
)
973 struct tcm_qla2xxx_tpg
*base_tpg
= container_of(work
,
974 struct tcm_qla2xxx_tpg
, tpg_base_work
);
975 struct se_portal_group
*se_tpg
= &base_tpg
->se_tpg
;
976 struct scsi_qla_host
*base_vha
= base_tpg
->lport
->qla_vha
;
978 if (!configfs_depend_item(se_tpg
->se_tpg_tfo
->tf_subsys
,
979 &se_tpg
->tpg_group
.cg_item
)) {
980 atomic_set(&base_tpg
->lport_tpg_enabled
, 1);
981 qlt_enable_vha(base_vha
);
983 complete(&base_tpg
->tpg_base_comp
);
986 static void tcm_qla2xxx_undepend_tpg(struct work_struct
*work
)
988 struct tcm_qla2xxx_tpg
*base_tpg
= container_of(work
,
989 struct tcm_qla2xxx_tpg
, tpg_base_work
);
990 struct se_portal_group
*se_tpg
= &base_tpg
->se_tpg
;
991 struct scsi_qla_host
*base_vha
= base_tpg
->lport
->qla_vha
;
993 if (!qlt_stop_phase1(base_vha
->vha_tgt
.qla_tgt
)) {
994 atomic_set(&base_tpg
->lport_tpg_enabled
, 0);
995 configfs_undepend_item(se_tpg
->se_tpg_tfo
->tf_subsys
,
996 &se_tpg
->tpg_group
.cg_item
);
998 complete(&base_tpg
->tpg_base_comp
);
1001 static ssize_t
tcm_qla2xxx_tpg_store_enable(
1002 struct se_portal_group
*se_tpg
,
1006 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1007 struct tcm_qla2xxx_tpg
, se_tpg
);
1011 rc
= kstrtoul(page
, 0, &op
);
1013 pr_err("kstrtoul() returned %d\n", rc
);
1016 if ((op
!= 1) && (op
!= 0)) {
1017 pr_err("Illegal value for tpg_enable: %lu\n", op
);
1021 if (atomic_read(&tpg
->lport_tpg_enabled
))
1024 INIT_WORK(&tpg
->tpg_base_work
, tcm_qla2xxx_depend_tpg
);
1026 if (!atomic_read(&tpg
->lport_tpg_enabled
))
1029 INIT_WORK(&tpg
->tpg_base_work
, tcm_qla2xxx_undepend_tpg
);
1031 init_completion(&tpg
->tpg_base_comp
);
1032 schedule_work(&tpg
->tpg_base_work
);
1033 wait_for_completion(&tpg
->tpg_base_comp
);
1036 if (!atomic_read(&tpg
->lport_tpg_enabled
))
1039 if (atomic_read(&tpg
->lport_tpg_enabled
))
1045 TF_TPG_BASE_ATTR(tcm_qla2xxx
, enable
, S_IRUGO
| S_IWUSR
);
1047 static struct configfs_attribute
*tcm_qla2xxx_tpg_attrs
[] = {
1048 &tcm_qla2xxx_tpg_enable
.attr
,
1052 static struct se_portal_group
*tcm_qla2xxx_make_tpg(
1054 struct config_group
*group
,
1057 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1058 struct tcm_qla2xxx_lport
, lport_wwn
);
1059 struct tcm_qla2xxx_tpg
*tpg
;
1063 if (strstr(name
, "tpgt_") != name
)
1064 return ERR_PTR(-EINVAL
);
1065 if (kstrtoul(name
+ 5, 10, &tpgt
) || tpgt
> USHRT_MAX
)
1066 return ERR_PTR(-EINVAL
);
1069 pr_err("In non NPIV mode, a single TPG=1 is used for HW port mappings\n");
1070 return ERR_PTR(-ENOSYS
);
1073 tpg
= kzalloc(sizeof(struct tcm_qla2xxx_tpg
), GFP_KERNEL
);
1075 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1076 return ERR_PTR(-ENOMEM
);
1079 tpg
->lport_tpgt
= tpgt
;
1081 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1084 tpg
->tpg_attrib
.generate_node_acls
= 1;
1085 tpg
->tpg_attrib
.demo_mode_write_protect
= 1;
1086 tpg
->tpg_attrib
.cache_dynamic_acls
= 1;
1087 tpg
->tpg_attrib
.demo_mode_login_only
= 1;
1089 ret
= core_tpg_register(&tcm_qla2xxx_fabric_configfs
->tf_ops
, wwn
,
1090 &tpg
->se_tpg
, tpg
, TRANSPORT_TPG_TYPE_NORMAL
);
1098 return &tpg
->se_tpg
;
1101 static void tcm_qla2xxx_drop_tpg(struct se_portal_group
*se_tpg
)
1103 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1104 struct tcm_qla2xxx_tpg
, se_tpg
);
1105 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
1106 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1108 * Call into qla2x_target.c LLD logic to shutdown the active
1109 * FC Nexuses and disable target mode operation for this qla_hw_data
1111 if (vha
->vha_tgt
.qla_tgt
&& !vha
->vha_tgt
.qla_tgt
->tgt_stop
)
1112 qlt_stop_phase1(vha
->vha_tgt
.qla_tgt
);
1114 core_tpg_deregister(se_tpg
);
1116 * Clear local TPG=1 pointer for non NPIV mode.
1118 lport
->tpg_1
= NULL
;
1122 static ssize_t
tcm_qla2xxx_npiv_tpg_show_enable(
1123 struct se_portal_group
*se_tpg
,
1126 return tcm_qla2xxx_tpg_show_enable(se_tpg
, page
);
1129 static ssize_t
tcm_qla2xxx_npiv_tpg_store_enable(
1130 struct se_portal_group
*se_tpg
,
1134 struct se_wwn
*se_wwn
= se_tpg
->se_tpg_wwn
;
1135 struct tcm_qla2xxx_lport
*lport
= container_of(se_wwn
,
1136 struct tcm_qla2xxx_lport
, lport_wwn
);
1137 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1138 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1139 struct tcm_qla2xxx_tpg
, se_tpg
);
1143 rc
= kstrtoul(page
, 0, &op
);
1145 pr_err("kstrtoul() returned %d\n", rc
);
1148 if ((op
!= 1) && (op
!= 0)) {
1149 pr_err("Illegal value for tpg_enable: %lu\n", op
);
1153 if (atomic_read(&tpg
->lport_tpg_enabled
))
1156 atomic_set(&tpg
->lport_tpg_enabled
, 1);
1157 qlt_enable_vha(vha
);
1159 if (!atomic_read(&tpg
->lport_tpg_enabled
))
1162 atomic_set(&tpg
->lport_tpg_enabled
, 0);
1163 qlt_stop_phase1(vha
->vha_tgt
.qla_tgt
);
1169 TF_TPG_BASE_ATTR(tcm_qla2xxx_npiv
, enable
, S_IRUGO
| S_IWUSR
);
1171 static struct configfs_attribute
*tcm_qla2xxx_npiv_tpg_attrs
[] = {
1172 &tcm_qla2xxx_npiv_tpg_enable
.attr
,
1176 static struct se_portal_group
*tcm_qla2xxx_npiv_make_tpg(
1178 struct config_group
*group
,
1181 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1182 struct tcm_qla2xxx_lport
, lport_wwn
);
1183 struct tcm_qla2xxx_tpg
*tpg
;
1187 if (strstr(name
, "tpgt_") != name
)
1188 return ERR_PTR(-EINVAL
);
1189 if (kstrtoul(name
+ 5, 10, &tpgt
) || tpgt
> USHRT_MAX
)
1190 return ERR_PTR(-EINVAL
);
1192 tpg
= kzalloc(sizeof(struct tcm_qla2xxx_tpg
), GFP_KERNEL
);
1194 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1195 return ERR_PTR(-ENOMEM
);
1198 tpg
->lport_tpgt
= tpgt
;
1201 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1204 tpg
->tpg_attrib
.generate_node_acls
= 1;
1205 tpg
->tpg_attrib
.demo_mode_write_protect
= 1;
1206 tpg
->tpg_attrib
.cache_dynamic_acls
= 1;
1207 tpg
->tpg_attrib
.demo_mode_login_only
= 1;
1209 ret
= core_tpg_register(&tcm_qla2xxx_npiv_fabric_configfs
->tf_ops
, wwn
,
1210 &tpg
->se_tpg
, tpg
, TRANSPORT_TPG_TYPE_NORMAL
);
1216 return &tpg
->se_tpg
;
1220 * Expected to be called with struct qla_hw_data->hardware_lock held
1222 static struct qla_tgt_sess
*tcm_qla2xxx_find_sess_by_s_id(
1223 scsi_qla_host_t
*vha
,
1224 const uint8_t *s_id
)
1226 struct tcm_qla2xxx_lport
*lport
;
1227 struct se_node_acl
*se_nacl
;
1228 struct tcm_qla2xxx_nacl
*nacl
;
1231 lport
= vha
->vha_tgt
.target_lport_ptr
;
1233 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1238 key
= (((unsigned long)s_id
[0] << 16) |
1239 ((unsigned long)s_id
[1] << 8) |
1240 (unsigned long)s_id
[2]);
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
->qla_tgt_sess
) {
1253 pr_err("Unable to locate struct qla_tgt_sess\n");
1257 return nacl
->qla_tgt_sess
;
1261 * Expected to be called with struct qla_hw_data->hardware_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 qla_tgt_sess
*qla_tgt_sess
,
1275 key
= (((unsigned long)s_id
[0] << 16) |
1276 ((unsigned long)s_id
[1] << 8) |
1277 (unsigned long)s_id
[2]);
1278 pr_debug("set_sess_by_s_id: %06x\n", key
);
1280 slot
= btree_lookup32(&lport
->lport_fcport_map
, key
);
1283 pr_debug("Setting up new fc_port entry to new_se_nacl\n");
1284 nacl
->nport_id
= key
;
1285 rc
= btree_insert32(&lport
->lport_fcport_map
, key
,
1286 new_se_nacl
, GFP_ATOMIC
);
1288 printk(KERN_ERR
"Unable to insert s_id into fcport_map: %06x\n",
1291 pr_debug("Wiping nonexisting fc_port entry\n");
1294 qla_tgt_sess
->se_sess
= se_sess
;
1295 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1299 if (nacl
->qla_tgt_sess
) {
1300 if (new_se_nacl
== NULL
) {
1301 pr_debug("Clearing existing nacl->qla_tgt_sess and fc_port entry\n");
1302 btree_remove32(&lport
->lport_fcport_map
, key
);
1303 nacl
->qla_tgt_sess
= NULL
;
1306 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_port entry\n");
1307 btree_update32(&lport
->lport_fcport_map
, key
, new_se_nacl
);
1308 qla_tgt_sess
->se_sess
= se_sess
;
1309 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1313 if (new_se_nacl
== NULL
) {
1314 pr_debug("Clearing existing fc_port entry\n");
1315 btree_remove32(&lport
->lport_fcport_map
, key
);
1319 pr_debug("Replacing existing fc_port entry w/o active nacl->qla_tgt_sess\n");
1320 btree_update32(&lport
->lport_fcport_map
, key
, new_se_nacl
);
1321 qla_tgt_sess
->se_sess
= se_sess
;
1322 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1324 pr_debug("Setup nacl->qla_tgt_sess %p by s_id for se_nacl: %p, initiatorname: %s\n",
1325 nacl
->qla_tgt_sess
, new_se_nacl
, new_se_nacl
->initiatorname
);
1329 * Expected to be called with struct qla_hw_data->hardware_lock held
1331 static struct qla_tgt_sess
*tcm_qla2xxx_find_sess_by_loop_id(
1332 scsi_qla_host_t
*vha
,
1333 const uint16_t loop_id
)
1335 struct tcm_qla2xxx_lport
*lport
;
1336 struct se_node_acl
*se_nacl
;
1337 struct tcm_qla2xxx_nacl
*nacl
;
1338 struct tcm_qla2xxx_fc_loopid
*fc_loopid
;
1340 lport
= vha
->vha_tgt
.target_lport_ptr
;
1342 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1347 pr_debug("find_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id
);
1349 fc_loopid
= lport
->lport_loopid_map
+ loop_id
;
1350 se_nacl
= fc_loopid
->se_nacl
;
1352 pr_debug("Unable to locate se_nacl by loop_id: 0x%04x\n",
1357 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1359 if (!nacl
->qla_tgt_sess
) {
1360 pr_err("Unable to locate struct qla_tgt_sess\n");
1364 return nacl
->qla_tgt_sess
;
1368 * Expected to be called with struct qla_hw_data->hardware_lock held
1370 static void tcm_qla2xxx_set_sess_by_loop_id(
1371 struct tcm_qla2xxx_lport
*lport
,
1372 struct se_node_acl
*new_se_nacl
,
1373 struct tcm_qla2xxx_nacl
*nacl
,
1374 struct se_session
*se_sess
,
1375 struct qla_tgt_sess
*qla_tgt_sess
,
1378 struct se_node_acl
*saved_nacl
;
1379 struct tcm_qla2xxx_fc_loopid
*fc_loopid
;
1381 pr_debug("set_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id
);
1383 fc_loopid
= &((struct tcm_qla2xxx_fc_loopid
*)
1384 lport
->lport_loopid_map
)[loop_id
];
1386 saved_nacl
= fc_loopid
->se_nacl
;
1388 pr_debug("Setting up new fc_loopid->se_nacl to new_se_nacl\n");
1389 fc_loopid
->se_nacl
= new_se_nacl
;
1390 if (qla_tgt_sess
->se_sess
!= se_sess
)
1391 qla_tgt_sess
->se_sess
= se_sess
;
1392 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1393 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1397 if (nacl
->qla_tgt_sess
) {
1398 if (new_se_nacl
== NULL
) {
1399 pr_debug("Clearing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1400 fc_loopid
->se_nacl
= NULL
;
1401 nacl
->qla_tgt_sess
= NULL
;
1405 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1406 fc_loopid
->se_nacl
= new_se_nacl
;
1407 if (qla_tgt_sess
->se_sess
!= se_sess
)
1408 qla_tgt_sess
->se_sess
= se_sess
;
1409 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1410 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1414 if (new_se_nacl
== NULL
) {
1415 pr_debug("Clearing fc_loopid->se_nacl\n");
1416 fc_loopid
->se_nacl
= NULL
;
1420 pr_debug("Replacing existing fc_loopid->se_nacl w/o active nacl->qla_tgt_sess\n");
1421 fc_loopid
->se_nacl
= new_se_nacl
;
1422 if (qla_tgt_sess
->se_sess
!= se_sess
)
1423 qla_tgt_sess
->se_sess
= se_sess
;
1424 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1425 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1427 pr_debug("Setup nacl->qla_tgt_sess %p by loop_id for se_nacl: %p, initiatorname: %s\n",
1428 nacl
->qla_tgt_sess
, new_se_nacl
, new_se_nacl
->initiatorname
);
1432 * Should always be called with qla_hw_data->hardware_lock held.
1434 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport
*lport
,
1435 struct tcm_qla2xxx_nacl
*nacl
, struct qla_tgt_sess
*sess
)
1437 struct se_session
*se_sess
= sess
->se_sess
;
1438 unsigned char be_sid
[3];
1440 be_sid
[0] = sess
->s_id
.b
.domain
;
1441 be_sid
[1] = sess
->s_id
.b
.area
;
1442 be_sid
[2] = sess
->s_id
.b
.al_pa
;
1444 tcm_qla2xxx_set_sess_by_s_id(lport
, NULL
, nacl
, se_sess
,
1446 tcm_qla2xxx_set_sess_by_loop_id(lport
, NULL
, nacl
, se_sess
,
1447 sess
, sess
->loop_id
);
1450 static void tcm_qla2xxx_free_session(struct qla_tgt_sess
*sess
)
1452 struct qla_tgt
*tgt
= sess
->tgt
;
1453 struct qla_hw_data
*ha
= tgt
->ha
;
1454 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
1455 struct se_session
*se_sess
;
1456 struct se_node_acl
*se_nacl
;
1457 struct tcm_qla2xxx_lport
*lport
;
1458 struct tcm_qla2xxx_nacl
*nacl
;
1460 BUG_ON(in_interrupt());
1462 se_sess
= sess
->se_sess
;
1464 pr_err("struct qla_tgt_sess->se_sess is NULL\n");
1468 se_nacl
= se_sess
->se_node_acl
;
1469 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1471 lport
= vha
->vha_tgt
.target_lport_ptr
;
1473 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1477 target_wait_for_sess_cmds(se_sess
);
1479 transport_deregister_session_configfs(sess
->se_sess
);
1480 transport_deregister_session(sess
->se_sess
);
1484 * Called via qlt_create_sess():ha->qla2x_tmpl->check_initiator_node_acl()
1485 * to locate struct se_node_acl
1487 static int tcm_qla2xxx_check_initiator_node_acl(
1488 scsi_qla_host_t
*vha
,
1489 unsigned char *fc_wwpn
,
1494 struct qla_hw_data
*ha
= vha
->hw
;
1495 struct tcm_qla2xxx_lport
*lport
;
1496 struct tcm_qla2xxx_tpg
*tpg
;
1497 struct tcm_qla2xxx_nacl
*nacl
;
1498 struct se_portal_group
*se_tpg
;
1499 struct se_node_acl
*se_nacl
;
1500 struct se_session
*se_sess
;
1501 struct qla_tgt_sess
*sess
= qla_tgt_sess
;
1502 unsigned char port_name
[36];
1503 unsigned long flags
;
1504 int num_tags
= (ha
->fw_xcb_count
) ? ha
->fw_xcb_count
:
1505 TCM_QLA2XXX_DEFAULT_TAGS
;
1507 lport
= vha
->vha_tgt
.target_lport_ptr
;
1509 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1514 * Locate the TPG=1 reference..
1518 pr_err("Unable to lcoate struct tcm_qla2xxx_lport->tpg_1\n");
1521 se_tpg
= &tpg
->se_tpg
;
1523 se_sess
= transport_init_session_tags(num_tags
,
1524 sizeof(struct qla_tgt_cmd
),
1525 TARGET_PROT_NORMAL
);
1526 if (IS_ERR(se_sess
)) {
1527 pr_err("Unable to initialize struct se_session\n");
1528 return PTR_ERR(se_sess
);
1531 * Format the FCP Initiator port_name into colon seperated values to
1532 * match the format by tcm_qla2xxx explict ConfigFS NodeACLs.
1534 memset(&port_name
, 0, 36);
1535 snprintf(port_name
, 36, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1536 fc_wwpn
[0], fc_wwpn
[1], fc_wwpn
[2], fc_wwpn
[3], fc_wwpn
[4],
1537 fc_wwpn
[5], fc_wwpn
[6], fc_wwpn
[7]);
1539 * Locate our struct se_node_acl either from an explict NodeACL created
1540 * via ConfigFS, or via running in TPG demo mode.
1542 se_sess
->se_node_acl
= core_tpg_check_initiator_node_acl(se_tpg
,
1544 if (!se_sess
->se_node_acl
) {
1545 transport_free_session(se_sess
);
1548 se_nacl
= se_sess
->se_node_acl
;
1549 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1551 * And now setup the new se_nacl and session pointers into our HW lport
1552 * mappings for fabric S_ID and LOOP_ID.
1554 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1555 tcm_qla2xxx_set_sess_by_s_id(lport
, se_nacl
, nacl
, se_sess
,
1556 qla_tgt_sess
, s_id
);
1557 tcm_qla2xxx_set_sess_by_loop_id(lport
, se_nacl
, nacl
, se_sess
,
1558 qla_tgt_sess
, loop_id
);
1559 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1561 * Finally register the new FC Nexus with TCM
1563 __transport_register_session(se_nacl
->se_tpg
, se_nacl
, se_sess
, sess
);
1568 static void tcm_qla2xxx_update_sess(struct qla_tgt_sess
*sess
, port_id_t s_id
,
1569 uint16_t loop_id
, bool conf_compl_supported
)
1571 struct qla_tgt
*tgt
= sess
->tgt
;
1572 struct qla_hw_data
*ha
= tgt
->ha
;
1573 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
1574 struct tcm_qla2xxx_lport
*lport
= vha
->vha_tgt
.target_lport_ptr
;
1575 struct se_node_acl
*se_nacl
= sess
->se_sess
->se_node_acl
;
1576 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
1577 struct tcm_qla2xxx_nacl
, se_node_acl
);
1581 if (sess
->loop_id
!= loop_id
|| sess
->s_id
.b24
!= s_id
.b24
)
1582 pr_info("Updating session %p from port %8phC loop_id %d -> %d s_id %x:%x:%x -> %x:%x:%x\n",
1583 sess
, sess
->port_name
,
1584 sess
->loop_id
, loop_id
, sess
->s_id
.b
.domain
,
1585 sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
, s_id
.b
.domain
,
1586 s_id
.b
.area
, s_id
.b
.al_pa
);
1588 if (sess
->loop_id
!= loop_id
) {
1590 * Because we can shuffle loop IDs around and we
1591 * update different sessions non-atomically, we might
1592 * have overwritten this session's old loop ID
1593 * already, and we might end up overwriting some other
1594 * session that will be updated later. So we have to
1595 * be extra careful and we can't warn about those things...
1597 if (lport
->lport_loopid_map
[sess
->loop_id
].se_nacl
== se_nacl
)
1598 lport
->lport_loopid_map
[sess
->loop_id
].se_nacl
= NULL
;
1600 lport
->lport_loopid_map
[loop_id
].se_nacl
= se_nacl
;
1602 sess
->loop_id
= loop_id
;
1605 if (sess
->s_id
.b24
!= s_id
.b24
) {
1606 key
= (((u32
) sess
->s_id
.b
.domain
<< 16) |
1607 ((u32
) sess
->s_id
.b
.area
<< 8) |
1608 ((u32
) sess
->s_id
.b
.al_pa
));
1610 if (btree_lookup32(&lport
->lport_fcport_map
, key
))
1611 WARN(btree_remove32(&lport
->lport_fcport_map
, key
) != se_nacl
,
1612 "Found wrong se_nacl when updating s_id %x:%x:%x\n",
1613 sess
->s_id
.b
.domain
, sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
);
1615 WARN(1, "No lport_fcport_map entry for s_id %x:%x:%x\n",
1616 sess
->s_id
.b
.domain
, sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
);
1618 key
= (((u32
) s_id
.b
.domain
<< 16) |
1619 ((u32
) s_id
.b
.area
<< 8) |
1620 ((u32
) s_id
.b
.al_pa
));
1622 if (btree_lookup32(&lport
->lport_fcport_map
, key
)) {
1623 WARN(1, "Already have lport_fcport_map entry for s_id %x:%x:%x\n",
1624 s_id
.b
.domain
, s_id
.b
.area
, s_id
.b
.al_pa
);
1625 btree_update32(&lport
->lport_fcport_map
, key
, se_nacl
);
1627 btree_insert32(&lport
->lport_fcport_map
, key
, se_nacl
, GFP_ATOMIC
);
1631 nacl
->nport_id
= key
;
1634 sess
->conf_compl_supported
= conf_compl_supported
;
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_dif_err
= tcm_qla2xxx_handle_dif_err
,
1644 .handle_tmr
= tcm_qla2xxx_handle_tmr
,
1645 .free_cmd
= tcm_qla2xxx_free_cmd
,
1646 .free_mcmd
= tcm_qla2xxx_free_mcmd
,
1647 .free_session
= tcm_qla2xxx_free_session
,
1648 .update_sess
= tcm_qla2xxx_update_sess
,
1649 .check_initiator_node_acl
= tcm_qla2xxx_check_initiator_node_acl
,
1650 .find_sess_by_s_id
= tcm_qla2xxx_find_sess_by_s_id
,
1651 .find_sess_by_loop_id
= tcm_qla2xxx_find_sess_by_loop_id
,
1652 .clear_nacl_from_fcport_map
= tcm_qla2xxx_clear_nacl_from_fcport_map
,
1653 .put_sess
= tcm_qla2xxx_put_sess
,
1654 .shutdown_sess
= tcm_qla2xxx_shutdown_sess
,
1657 static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport
*lport
)
1661 rc
= btree_init32(&lport
->lport_fcport_map
);
1663 pr_err("Unable to initialize lport->lport_fcport_map btree\n");
1667 lport
->lport_loopid_map
= vmalloc(sizeof(struct tcm_qla2xxx_fc_loopid
) *
1669 if (!lport
->lport_loopid_map
) {
1670 pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n",
1671 sizeof(struct tcm_qla2xxx_fc_loopid
) * 65536);
1672 btree_destroy32(&lport
->lport_fcport_map
);
1675 memset(lport
->lport_loopid_map
, 0, sizeof(struct tcm_qla2xxx_fc_loopid
)
1677 pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n",
1678 sizeof(struct tcm_qla2xxx_fc_loopid
) * 65536);
1682 static int tcm_qla2xxx_lport_register_cb(struct scsi_qla_host
*vha
,
1683 void *target_lport_ptr
,
1684 u64 npiv_wwpn
, u64 npiv_wwnn
)
1686 struct qla_hw_data
*ha
= vha
->hw
;
1687 struct tcm_qla2xxx_lport
*lport
=
1688 (struct tcm_qla2xxx_lport
*)target_lport_ptr
;
1690 * Setup tgt_ops, local pointer to vha and target_lport_ptr
1692 ha
->tgt
.tgt_ops
= &tcm_qla2xxx_template
;
1693 vha
->vha_tgt
.target_lport_ptr
= target_lport_ptr
;
1694 lport
->qla_vha
= vha
;
1699 static struct se_wwn
*tcm_qla2xxx_make_lport(
1700 struct target_fabric_configfs
*tf
,
1701 struct config_group
*group
,
1704 struct tcm_qla2xxx_lport
*lport
;
1708 if (tcm_qla2xxx_parse_wwn(name
, &wwpn
, 1) < 0)
1709 return ERR_PTR(-EINVAL
);
1711 lport
= kzalloc(sizeof(struct tcm_qla2xxx_lport
), GFP_KERNEL
);
1713 pr_err("Unable to allocate struct tcm_qla2xxx_lport\n");
1714 return ERR_PTR(-ENOMEM
);
1716 lport
->lport_wwpn
= wwpn
;
1717 tcm_qla2xxx_format_wwn(&lport
->lport_name
[0], TCM_QLA2XXX_NAMELEN
,
1719 sprintf(lport
->lport_naa_name
, "naa.%016llx", (unsigned long long) wwpn
);
1721 ret
= tcm_qla2xxx_init_lport(lport
);
1725 ret
= qlt_lport_register(lport
, wwpn
, 0, 0,
1726 tcm_qla2xxx_lport_register_cb
);
1730 return &lport
->lport_wwn
;
1732 vfree(lport
->lport_loopid_map
);
1733 btree_destroy32(&lport
->lport_fcport_map
);
1736 return ERR_PTR(ret
);
1739 static void tcm_qla2xxx_drop_lport(struct se_wwn
*wwn
)
1741 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1742 struct tcm_qla2xxx_lport
, lport_wwn
);
1743 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1744 struct se_node_acl
*node
;
1748 * Call into qla2x_target.c LLD logic to complete the
1749 * shutdown of struct qla_tgt after the call to
1750 * qlt_stop_phase1() from tcm_qla2xxx_drop_tpg() above..
1752 if (vha
->vha_tgt
.qla_tgt
&& !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
1753 qlt_stop_phase2(vha
->vha_tgt
.qla_tgt
);
1755 qlt_lport_deregister(vha
);
1757 vfree(lport
->lport_loopid_map
);
1758 btree_for_each_safe32(&lport
->lport_fcport_map
, key
, node
)
1759 btree_remove32(&lport
->lport_fcport_map
, key
);
1760 btree_destroy32(&lport
->lport_fcport_map
);
1764 static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host
*base_vha
,
1765 void *target_lport_ptr
,
1766 u64 npiv_wwpn
, u64 npiv_wwnn
)
1768 struct fc_vport
*vport
;
1769 struct Scsi_Host
*sh
= base_vha
->host
;
1770 struct scsi_qla_host
*npiv_vha
;
1771 struct tcm_qla2xxx_lport
*lport
=
1772 (struct tcm_qla2xxx_lport
*)target_lport_ptr
;
1773 struct tcm_qla2xxx_lport
*base_lport
=
1774 (struct tcm_qla2xxx_lport
*)base_vha
->vha_tgt
.target_lport_ptr
;
1775 struct tcm_qla2xxx_tpg
*base_tpg
;
1776 struct fc_vport_identifiers vport_id
;
1778 if (!qla_tgt_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");
1788 base_tpg
= base_lport
->tpg_1
;
1790 memset(&vport_id
, 0, sizeof(vport_id
));
1791 vport_id
.port_name
= npiv_wwpn
;
1792 vport_id
.node_name
= npiv_wwnn
;
1793 vport_id
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
1794 vport_id
.vport_type
= FC_PORTTYPE_NPIV
;
1795 vport_id
.disable
= false;
1797 vport
= fc_vport_create(sh
, 0, &vport_id
);
1799 pr_err("fc_vport_create failed for qla2xxx_npiv\n");
1803 * Setup local pointer to NPIV vhba + target_lport_ptr
1805 npiv_vha
= (struct scsi_qla_host
*)vport
->dd_data
;
1806 npiv_vha
->vha_tgt
.target_lport_ptr
= target_lport_ptr
;
1807 lport
->qla_vha
= npiv_vha
;
1808 scsi_host_get(npiv_vha
->host
);
1813 static struct se_wwn
*tcm_qla2xxx_npiv_make_lport(
1814 struct target_fabric_configfs
*tf
,
1815 struct config_group
*group
,
1818 struct tcm_qla2xxx_lport
*lport
;
1819 u64 phys_wwpn
, npiv_wwpn
, npiv_wwnn
;
1823 snprintf(tmp
, 128, "%s", name
);
1825 p
= strchr(tmp
, '@');
1827 pr_err("Unable to locate NPIV '@' seperator\n");
1828 return ERR_PTR(-EINVAL
);
1832 if (tcm_qla2xxx_parse_wwn(tmp
, &phys_wwpn
, 1) < 0)
1833 return ERR_PTR(-EINVAL
);
1835 if (tcm_qla2xxx_npiv_parse_wwn(p
, strlen(p
)+1,
1836 &npiv_wwpn
, &npiv_wwnn
) < 0)
1837 return ERR_PTR(-EINVAL
);
1839 lport
= kzalloc(sizeof(struct tcm_qla2xxx_lport
), GFP_KERNEL
);
1841 pr_err("Unable to allocate struct tcm_qla2xxx_lport for NPIV\n");
1842 return ERR_PTR(-ENOMEM
);
1844 lport
->lport_npiv_wwpn
= npiv_wwpn
;
1845 lport
->lport_npiv_wwnn
= npiv_wwnn
;
1846 sprintf(lport
->lport_naa_name
, "naa.%016llx", (unsigned long long) npiv_wwpn
);
1848 ret
= tcm_qla2xxx_init_lport(lport
);
1852 ret
= qlt_lport_register(lport
, phys_wwpn
, npiv_wwpn
, npiv_wwnn
,
1853 tcm_qla2xxx_lport_register_npiv_cb
);
1857 return &lport
->lport_wwn
;
1859 vfree(lport
->lport_loopid_map
);
1860 btree_destroy32(&lport
->lport_fcport_map
);
1863 return ERR_PTR(ret
);
1866 static void tcm_qla2xxx_npiv_drop_lport(struct se_wwn
*wwn
)
1868 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1869 struct tcm_qla2xxx_lport
, lport_wwn
);
1870 struct scsi_qla_host
*npiv_vha
= lport
->qla_vha
;
1871 struct qla_hw_data
*ha
= npiv_vha
->hw
;
1872 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1874 scsi_host_put(npiv_vha
->host
);
1876 * Notify libfc that we want to release the vha->fc_vport
1878 fc_vport_terminate(npiv_vha
->fc_vport
);
1879 scsi_host_put(base_vha
->host
);
1884 static ssize_t
tcm_qla2xxx_wwn_show_attr_version(
1885 struct target_fabric_configfs
*tf
,
1888 return sprintf(page
,
1889 "TCM QLOGIC QLA2XXX NPIV capable fabric module %s on %s/%s on "
1890 UTS_RELEASE
"\n", TCM_QLA2XXX_VERSION
, utsname()->sysname
,
1891 utsname()->machine
);
1894 TF_WWN_ATTR_RO(tcm_qla2xxx
, version
);
1896 static struct configfs_attribute
*tcm_qla2xxx_wwn_attrs
[] = {
1897 &tcm_qla2xxx_wwn_version
.attr
,
1901 static struct target_core_fabric_ops tcm_qla2xxx_ops
= {
1902 .get_fabric_name
= tcm_qla2xxx_get_fabric_name
,
1903 .get_fabric_proto_ident
= tcm_qla2xxx_get_fabric_proto_ident
,
1904 .tpg_get_wwn
= tcm_qla2xxx_get_fabric_wwn
,
1905 .tpg_get_tag
= tcm_qla2xxx_get_tag
,
1906 .tpg_get_default_depth
= tcm_qla2xxx_get_default_depth
,
1907 .tpg_get_pr_transport_id
= tcm_qla2xxx_get_pr_transport_id
,
1908 .tpg_get_pr_transport_id_len
= tcm_qla2xxx_get_pr_transport_id_len
,
1909 .tpg_parse_pr_out_transport_id
= tcm_qla2xxx_parse_pr_out_transport_id
,
1910 .tpg_check_demo_mode
= tcm_qla2xxx_check_demo_mode
,
1911 .tpg_check_demo_mode_cache
= tcm_qla2xxx_check_demo_mode_cache
,
1912 .tpg_check_demo_mode_write_protect
=
1913 tcm_qla2xxx_check_demo_write_protect
,
1914 .tpg_check_prod_mode_write_protect
=
1915 tcm_qla2xxx_check_prod_write_protect
,
1916 .tpg_check_demo_mode_login_only
= tcm_qla2xxx_check_demo_mode_login_only
,
1917 .tpg_alloc_fabric_acl
= tcm_qla2xxx_alloc_fabric_acl
,
1918 .tpg_release_fabric_acl
= tcm_qla2xxx_release_fabric_acl
,
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 .put_session
= tcm_qla2xxx_put_session
,
1923 .shutdown_session
= tcm_qla2xxx_shutdown_session
,
1924 .close_session
= tcm_qla2xxx_close_session
,
1925 .sess_get_index
= tcm_qla2xxx_sess_get_index
,
1926 .sess_get_initiator_sid
= NULL
,
1927 .write_pending
= tcm_qla2xxx_write_pending
,
1928 .write_pending_status
= tcm_qla2xxx_write_pending_status
,
1929 .set_default_node_attributes
= tcm_qla2xxx_set_default_node_attrs
,
1930 .get_task_tag
= tcm_qla2xxx_get_task_tag
,
1931 .get_cmd_state
= tcm_qla2xxx_get_cmd_state
,
1932 .queue_data_in
= tcm_qla2xxx_queue_data_in
,
1933 .queue_status
= tcm_qla2xxx_queue_status
,
1934 .queue_tm_rsp
= tcm_qla2xxx_queue_tm_rsp
,
1935 .aborted_task
= tcm_qla2xxx_aborted_task
,
1937 * Setup function pointers for generic logic in
1938 * target_core_fabric_configfs.c
1940 .fabric_make_wwn
= tcm_qla2xxx_make_lport
,
1941 .fabric_drop_wwn
= tcm_qla2xxx_drop_lport
,
1942 .fabric_make_tpg
= tcm_qla2xxx_make_tpg
,
1943 .fabric_drop_tpg
= tcm_qla2xxx_drop_tpg
,
1944 .fabric_post_link
= NULL
,
1945 .fabric_pre_unlink
= NULL
,
1946 .fabric_make_np
= NULL
,
1947 .fabric_drop_np
= NULL
,
1948 .fabric_make_nodeacl
= tcm_qla2xxx_make_nodeacl
,
1949 .fabric_drop_nodeacl
= tcm_qla2xxx_drop_nodeacl
,
1952 static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops
= {
1953 .get_fabric_name
= tcm_qla2xxx_npiv_get_fabric_name
,
1954 .get_fabric_proto_ident
= tcm_qla2xxx_get_fabric_proto_ident
,
1955 .tpg_get_wwn
= tcm_qla2xxx_get_fabric_wwn
,
1956 .tpg_get_tag
= tcm_qla2xxx_get_tag
,
1957 .tpg_get_default_depth
= tcm_qla2xxx_get_default_depth
,
1958 .tpg_get_pr_transport_id
= tcm_qla2xxx_get_pr_transport_id
,
1959 .tpg_get_pr_transport_id_len
= tcm_qla2xxx_get_pr_transport_id_len
,
1960 .tpg_parse_pr_out_transport_id
= tcm_qla2xxx_parse_pr_out_transport_id
,
1961 .tpg_check_demo_mode
= tcm_qla2xxx_check_demo_mode
,
1962 .tpg_check_demo_mode_cache
= tcm_qla2xxx_check_demo_mode_cache
,
1963 .tpg_check_demo_mode_write_protect
= tcm_qla2xxx_check_demo_mode
,
1964 .tpg_check_prod_mode_write_protect
=
1965 tcm_qla2xxx_check_prod_write_protect
,
1966 .tpg_check_demo_mode_login_only
= tcm_qla2xxx_check_demo_mode_login_only
,
1967 .tpg_alloc_fabric_acl
= tcm_qla2xxx_alloc_fabric_acl
,
1968 .tpg_release_fabric_acl
= tcm_qla2xxx_release_fabric_acl
,
1969 .tpg_get_inst_index
= tcm_qla2xxx_tpg_get_inst_index
,
1970 .check_stop_free
= tcm_qla2xxx_check_stop_free
,
1971 .release_cmd
= tcm_qla2xxx_release_cmd
,
1972 .put_session
= tcm_qla2xxx_put_session
,
1973 .shutdown_session
= tcm_qla2xxx_shutdown_session
,
1974 .close_session
= tcm_qla2xxx_close_session
,
1975 .sess_get_index
= tcm_qla2xxx_sess_get_index
,
1976 .sess_get_initiator_sid
= NULL
,
1977 .write_pending
= tcm_qla2xxx_write_pending
,
1978 .write_pending_status
= tcm_qla2xxx_write_pending_status
,
1979 .set_default_node_attributes
= tcm_qla2xxx_set_default_node_attrs
,
1980 .get_task_tag
= tcm_qla2xxx_get_task_tag
,
1981 .get_cmd_state
= tcm_qla2xxx_get_cmd_state
,
1982 .queue_data_in
= tcm_qla2xxx_queue_data_in
,
1983 .queue_status
= tcm_qla2xxx_queue_status
,
1984 .queue_tm_rsp
= tcm_qla2xxx_queue_tm_rsp
,
1985 .aborted_task
= tcm_qla2xxx_aborted_task
,
1987 * Setup function pointers for generic logic in
1988 * target_core_fabric_configfs.c
1990 .fabric_make_wwn
= tcm_qla2xxx_npiv_make_lport
,
1991 .fabric_drop_wwn
= tcm_qla2xxx_npiv_drop_lport
,
1992 .fabric_make_tpg
= tcm_qla2xxx_npiv_make_tpg
,
1993 .fabric_drop_tpg
= tcm_qla2xxx_drop_tpg
,
1994 .fabric_post_link
= NULL
,
1995 .fabric_pre_unlink
= NULL
,
1996 .fabric_make_np
= NULL
,
1997 .fabric_drop_np
= NULL
,
1998 .fabric_make_nodeacl
= tcm_qla2xxx_make_nodeacl
,
1999 .fabric_drop_nodeacl
= tcm_qla2xxx_drop_nodeacl
,
2002 static int tcm_qla2xxx_register_configfs(void)
2004 struct target_fabric_configfs
*fabric
, *npiv_fabric
;
2007 pr_debug("TCM QLOGIC QLA2XXX fabric module %s on %s/%s on "
2008 UTS_RELEASE
"\n", TCM_QLA2XXX_VERSION
, utsname()->sysname
,
2009 utsname()->machine
);
2011 * Register the top level struct config_item_type with TCM core
2013 fabric
= target_fabric_configfs_init(THIS_MODULE
, "qla2xxx");
2014 if (IS_ERR(fabric
)) {
2015 pr_err("target_fabric_configfs_init() failed\n");
2016 return PTR_ERR(fabric
);
2019 * Setup fabric->tf_ops from our local tcm_qla2xxx_ops
2021 fabric
->tf_ops
= tcm_qla2xxx_ops
;
2023 * Setup default attribute lists for various fabric->tf_cit_tmpl
2025 fabric
->tf_cit_tmpl
.tfc_wwn_cit
.ct_attrs
= tcm_qla2xxx_wwn_attrs
;
2026 fabric
->tf_cit_tmpl
.tfc_tpg_base_cit
.ct_attrs
= tcm_qla2xxx_tpg_attrs
;
2027 fabric
->tf_cit_tmpl
.tfc_tpg_attrib_cit
.ct_attrs
=
2028 tcm_qla2xxx_tpg_attrib_attrs
;
2029 fabric
->tf_cit_tmpl
.tfc_tpg_param_cit
.ct_attrs
= NULL
;
2030 fabric
->tf_cit_tmpl
.tfc_tpg_np_base_cit
.ct_attrs
= NULL
;
2031 fabric
->tf_cit_tmpl
.tfc_tpg_nacl_base_cit
.ct_attrs
= NULL
;
2032 fabric
->tf_cit_tmpl
.tfc_tpg_nacl_attrib_cit
.ct_attrs
= NULL
;
2033 fabric
->tf_cit_tmpl
.tfc_tpg_nacl_auth_cit
.ct_attrs
= NULL
;
2034 fabric
->tf_cit_tmpl
.tfc_tpg_nacl_param_cit
.ct_attrs
= NULL
;
2036 * Register the fabric for use within TCM
2038 ret
= target_fabric_configfs_register(fabric
);
2040 pr_err("target_fabric_configfs_register() failed for TCM_QLA2XXX\n");
2044 * Setup our local pointer to *fabric
2046 tcm_qla2xxx_fabric_configfs
= fabric
;
2047 pr_debug("TCM_QLA2XXX[0] - Set fabric -> tcm_qla2xxx_fabric_configfs\n");
2050 * Register the top level struct config_item_type for NPIV with TCM core
2052 npiv_fabric
= target_fabric_configfs_init(THIS_MODULE
, "qla2xxx_npiv");
2053 if (IS_ERR(npiv_fabric
)) {
2054 pr_err("target_fabric_configfs_init() failed\n");
2055 ret
= PTR_ERR(npiv_fabric
);
2059 * Setup fabric->tf_ops from our local tcm_qla2xxx_npiv_ops
2061 npiv_fabric
->tf_ops
= tcm_qla2xxx_npiv_ops
;
2063 * Setup default attribute lists for various npiv_fabric->tf_cit_tmpl
2065 npiv_fabric
->tf_cit_tmpl
.tfc_wwn_cit
.ct_attrs
= tcm_qla2xxx_wwn_attrs
;
2066 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_base_cit
.ct_attrs
=
2067 tcm_qla2xxx_npiv_tpg_attrs
;
2068 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_attrib_cit
.ct_attrs
= NULL
;
2069 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_param_cit
.ct_attrs
= NULL
;
2070 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_np_base_cit
.ct_attrs
= NULL
;
2071 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_nacl_base_cit
.ct_attrs
= NULL
;
2072 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_nacl_attrib_cit
.ct_attrs
= NULL
;
2073 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_nacl_auth_cit
.ct_attrs
= NULL
;
2074 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_nacl_param_cit
.ct_attrs
= NULL
;
2076 * Register the npiv_fabric for use within TCM
2078 ret
= target_fabric_configfs_register(npiv_fabric
);
2080 pr_err("target_fabric_configfs_register() failed for TCM_QLA2XXX\n");
2084 * Setup our local pointer to *npiv_fabric
2086 tcm_qla2xxx_npiv_fabric_configfs
= npiv_fabric
;
2087 pr_debug("TCM_QLA2XXX[0] - Set fabric -> tcm_qla2xxx_npiv_fabric_configfs\n");
2089 tcm_qla2xxx_free_wq
= alloc_workqueue("tcm_qla2xxx_free",
2091 if (!tcm_qla2xxx_free_wq
) {
2093 goto out_fabric_npiv
;
2096 tcm_qla2xxx_cmd_wq
= alloc_workqueue("tcm_qla2xxx_cmd", 0, 0);
2097 if (!tcm_qla2xxx_cmd_wq
) {
2105 destroy_workqueue(tcm_qla2xxx_free_wq
);
2107 target_fabric_configfs_deregister(tcm_qla2xxx_npiv_fabric_configfs
);
2109 target_fabric_configfs_deregister(tcm_qla2xxx_fabric_configfs
);
2113 static void tcm_qla2xxx_deregister_configfs(void)
2115 destroy_workqueue(tcm_qla2xxx_cmd_wq
);
2116 destroy_workqueue(tcm_qla2xxx_free_wq
);
2118 target_fabric_configfs_deregister(tcm_qla2xxx_fabric_configfs
);
2119 tcm_qla2xxx_fabric_configfs
= NULL
;
2120 pr_debug("TCM_QLA2XXX[0] - Cleared tcm_qla2xxx_fabric_configfs\n");
2122 target_fabric_configfs_deregister(tcm_qla2xxx_npiv_fabric_configfs
);
2123 tcm_qla2xxx_npiv_fabric_configfs
= NULL
;
2124 pr_debug("TCM_QLA2XXX[0] - Cleared tcm_qla2xxx_npiv_fabric_configfs\n");
2127 static int __init
tcm_qla2xxx_init(void)
2131 ret
= tcm_qla2xxx_register_configfs();
2138 static void __exit
tcm_qla2xxx_exit(void)
2140 tcm_qla2xxx_deregister_configfs();
2143 MODULE_DESCRIPTION("TCM QLA2XXX series NPIV enabled fabric driver");
2144 MODULE_LICENSE("GPL");
2145 module_init(tcm_qla2xxx_init
);
2146 module_exit(tcm_qla2xxx_exit
);