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
;
56 static int tcm_qla2xxx_check_true(struct se_portal_group
*se_tpg
)
61 static int tcm_qla2xxx_check_false(struct se_portal_group
*se_tpg
)
68 * If strict, we require lower-case hex and colon separators to be sure
69 * the name is the same as what would be generated by ft_format_wwn()
70 * so the name and wwn are mapped one-to-one.
72 static ssize_t
tcm_qla2xxx_parse_wwn(const char *name
, u64
*wwn
, int strict
)
82 for (cp
= name
; cp
< &name
[TCM_QLA2XXX_NAMELEN
- 1]; cp
++) {
84 if (c
== '\n' && cp
[1] == '\0')
86 if (strict
&& pos
++ == 2 && byte
++ < 7) {
95 if (strict
&& byte
!= 8)
102 else if (isxdigit(c
) && (islower(c
) || !strict
))
103 nibble
= tolower(c
) - 'a' + 10;
106 *wwn
= (*wwn
<< 4) | nibble
;
110 pr_debug("err %u len %zu pos %u byte %u\n",
111 err
, cp
- name
, pos
, byte
);
115 static ssize_t
tcm_qla2xxx_format_wwn(char *buf
, size_t len
, u64 wwn
)
119 put_unaligned_be64(wwn
, b
);
120 return snprintf(buf
, len
,
121 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
122 b
[0], b
[1], b
[2], b
[3], b
[4], b
[5], b
[6], b
[7]);
125 static char *tcm_qla2xxx_get_fabric_name(void)
131 * From drivers/scsi/scsi_transport_fc.c:fc_parse_wwn
133 static int tcm_qla2xxx_npiv_extract_wwn(const char *ns
, u64
*nm
)
138 memset(wwn
, 0, sizeof(wwn
));
140 /* Validate and store the new name */
141 for (i
= 0, j
= 0; i
< 16; i
++) {
144 value
= hex_to_bin(*ns
++);
146 j
= (j
<< 4) | value
;
156 *nm
= wwn_to_u64(wwn
);
161 * This parsing logic follows drivers/scsi/scsi_transport_fc.c:
162 * store_fc_host_vport_create()
164 static int tcm_qla2xxx_npiv_parse_wwn(
170 unsigned int cnt
= count
;
176 /* count may include a LF at end of string */
177 if (name
[cnt
-1] == '\n')
180 /* validate we have enough characters for WWPN */
181 if ((cnt
!= (16+1+16)) || (name
[16] != ':'))
184 rc
= tcm_qla2xxx_npiv_extract_wwn(&name
[0], wwpn
);
188 rc
= tcm_qla2xxx_npiv_extract_wwn(&name
[17], wwnn
);
195 static ssize_t
tcm_qla2xxx_npiv_format_wwn(char *buf
, size_t len
,
200 put_unaligned_be64(wwpn
, b
);
201 put_unaligned_be64(wwnn
, b2
);
202 return snprintf(buf
, len
,
203 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x,"
204 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
205 b
[0], b
[1], b
[2], b
[3], b
[4], b
[5], b
[6], b
[7],
206 b2
[0], b2
[1], b2
[2], b2
[3], b2
[4], b2
[5], b2
[6], b2
[7]);
209 static char *tcm_qla2xxx_npiv_get_fabric_name(void)
211 return "qla2xxx_npiv";
214 static u8
tcm_qla2xxx_get_fabric_proto_ident(struct se_portal_group
*se_tpg
)
216 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
217 struct tcm_qla2xxx_tpg
, se_tpg
);
218 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
221 switch (lport
->lport_proto_id
) {
222 case SCSI_PROTOCOL_FCP
:
224 proto_id
= fc_get_fabric_proto_ident(se_tpg
);
231 static char *tcm_qla2xxx_get_fabric_wwn(struct se_portal_group
*se_tpg
)
233 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
234 struct tcm_qla2xxx_tpg
, se_tpg
);
235 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
237 return lport
->lport_naa_name
;
240 static char *tcm_qla2xxx_npiv_get_fabric_wwn(struct se_portal_group
*se_tpg
)
242 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
243 struct tcm_qla2xxx_tpg
, se_tpg
);
244 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
246 return &lport
->lport_npiv_name
[0];
249 static u16
tcm_qla2xxx_get_tag(struct se_portal_group
*se_tpg
)
251 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
252 struct tcm_qla2xxx_tpg
, se_tpg
);
253 return tpg
->lport_tpgt
;
256 static u32
tcm_qla2xxx_get_default_depth(struct se_portal_group
*se_tpg
)
261 static u32
tcm_qla2xxx_get_pr_transport_id(
262 struct se_portal_group
*se_tpg
,
263 struct se_node_acl
*se_nacl
,
264 struct t10_pr_registration
*pr_reg
,
268 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
269 struct tcm_qla2xxx_tpg
, se_tpg
);
270 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
273 switch (lport
->lport_proto_id
) {
274 case SCSI_PROTOCOL_FCP
:
276 ret
= fc_get_pr_transport_id(se_tpg
, se_nacl
, pr_reg
,
284 static u32
tcm_qla2xxx_get_pr_transport_id_len(
285 struct se_portal_group
*se_tpg
,
286 struct se_node_acl
*se_nacl
,
287 struct t10_pr_registration
*pr_reg
,
290 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
291 struct tcm_qla2xxx_tpg
, se_tpg
);
292 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
295 switch (lport
->lport_proto_id
) {
296 case SCSI_PROTOCOL_FCP
:
298 ret
= fc_get_pr_transport_id_len(se_tpg
, se_nacl
, pr_reg
,
306 static char *tcm_qla2xxx_parse_pr_out_transport_id(
307 struct se_portal_group
*se_tpg
,
310 char **port_nexus_ptr
)
312 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
313 struct tcm_qla2xxx_tpg
, se_tpg
);
314 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
317 switch (lport
->lport_proto_id
) {
318 case SCSI_PROTOCOL_FCP
:
320 tid
= fc_parse_pr_out_transport_id(se_tpg
, buf
, out_tid_len
,
328 static int tcm_qla2xxx_check_demo_mode(struct se_portal_group
*se_tpg
)
330 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
331 struct tcm_qla2xxx_tpg
, se_tpg
);
333 return QLA_TPG_ATTRIB(tpg
)->generate_node_acls
;
336 static int tcm_qla2xxx_check_demo_mode_cache(struct se_portal_group
*se_tpg
)
338 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
339 struct tcm_qla2xxx_tpg
, se_tpg
);
341 return QLA_TPG_ATTRIB(tpg
)->cache_dynamic_acls
;
344 static int tcm_qla2xxx_check_demo_write_protect(struct se_portal_group
*se_tpg
)
346 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
347 struct tcm_qla2xxx_tpg
, se_tpg
);
349 return QLA_TPG_ATTRIB(tpg
)->demo_mode_write_protect
;
352 static int tcm_qla2xxx_check_prod_write_protect(struct se_portal_group
*se_tpg
)
354 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
355 struct tcm_qla2xxx_tpg
, se_tpg
);
357 return QLA_TPG_ATTRIB(tpg
)->prod_mode_write_protect
;
360 static int tcm_qla2xxx_check_demo_mode_login_only(struct se_portal_group
*se_tpg
)
362 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
363 struct tcm_qla2xxx_tpg
, se_tpg
);
365 return QLA_TPG_ATTRIB(tpg
)->demo_mode_login_only
;
368 static struct se_node_acl
*tcm_qla2xxx_alloc_fabric_acl(
369 struct se_portal_group
*se_tpg
)
371 struct tcm_qla2xxx_nacl
*nacl
;
373 nacl
= kzalloc(sizeof(struct tcm_qla2xxx_nacl
), GFP_KERNEL
);
375 pr_err("Unable to allocate struct tcm_qla2xxx_nacl\n");
379 return &nacl
->se_node_acl
;
382 static void tcm_qla2xxx_release_fabric_acl(
383 struct se_portal_group
*se_tpg
,
384 struct se_node_acl
*se_nacl
)
386 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
387 struct tcm_qla2xxx_nacl
, se_node_acl
);
391 static u32
tcm_qla2xxx_tpg_get_inst_index(struct se_portal_group
*se_tpg
)
393 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
394 struct tcm_qla2xxx_tpg
, se_tpg
);
396 return tpg
->lport_tpgt
;
399 static void tcm_qla2xxx_complete_mcmd(struct work_struct
*work
)
401 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(work
,
402 struct qla_tgt_mgmt_cmd
, free_work
);
404 transport_generic_free_cmd(&mcmd
->se_cmd
, 0);
408 * Called from qla_target_template->free_mcmd(), and will call
409 * tcm_qla2xxx_release_cmd() via normal struct target_core_fabric_ops
410 * release callback. qla_hw_data->hardware_lock is expected to be held
412 static void tcm_qla2xxx_free_mcmd(struct qla_tgt_mgmt_cmd
*mcmd
)
414 INIT_WORK(&mcmd
->free_work
, tcm_qla2xxx_complete_mcmd
);
415 queue_work(tcm_qla2xxx_free_wq
, &mcmd
->free_work
);
418 static void tcm_qla2xxx_complete_free(struct work_struct
*work
)
420 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
422 transport_generic_free_cmd(&cmd
->se_cmd
, 0);
426 * Called from qla_target_template->free_cmd(), and will call
427 * tcm_qla2xxx_release_cmd via normal struct target_core_fabric_ops
428 * release callback. qla_hw_data->hardware_lock is expected to be held
430 static void tcm_qla2xxx_free_cmd(struct qla_tgt_cmd
*cmd
)
432 INIT_WORK(&cmd
->work
, tcm_qla2xxx_complete_free
);
433 queue_work(tcm_qla2xxx_free_wq
, &cmd
->work
);
437 * Called from struct target_core_fabric_ops->check_stop_free() context
439 static int tcm_qla2xxx_check_stop_free(struct se_cmd
*se_cmd
)
441 return target_put_sess_cmd(se_cmd
->se_sess
, se_cmd
);
444 /* tcm_qla2xxx_release_cmd - Callback from TCM Core to release underlying
445 * fabric descriptor @se_cmd command to release
447 static void tcm_qla2xxx_release_cmd(struct se_cmd
*se_cmd
)
449 struct qla_tgt_cmd
*cmd
;
451 if (se_cmd
->se_cmd_flags
& SCF_SCSI_TMR_CDB
) {
452 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(se_cmd
,
453 struct qla_tgt_mgmt_cmd
, se_cmd
);
458 cmd
= container_of(se_cmd
, struct qla_tgt_cmd
, se_cmd
);
462 static int tcm_qla2xxx_shutdown_session(struct se_session
*se_sess
)
464 struct qla_tgt_sess
*sess
= se_sess
->fabric_sess_ptr
;
465 struct scsi_qla_host
*vha
;
471 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
472 target_sess_cmd_list_set_waiting(se_sess
);
473 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
478 static void tcm_qla2xxx_close_session(struct se_session
*se_sess
)
480 struct qla_tgt_sess
*sess
= se_sess
->fabric_sess_ptr
;
481 struct scsi_qla_host
*vha
;
487 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
488 qlt_unreg_sess(sess
);
489 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
492 static u32
tcm_qla2xxx_sess_get_index(struct se_session
*se_sess
)
497 static int tcm_qla2xxx_write_pending(struct se_cmd
*se_cmd
)
499 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
500 struct qla_tgt_cmd
, se_cmd
);
502 cmd
->bufflen
= se_cmd
->data_length
;
503 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
505 cmd
->sg_cnt
= se_cmd
->t_data_nents
;
506 cmd
->sg
= se_cmd
->t_data_sg
;
509 * qla_target.c:qlt_rdy_to_xfer() will call pci_map_sg() to setup
510 * the SGL mappings into PCIe memory for incoming FCP WRITE data.
512 return qlt_rdy_to_xfer(cmd
);
515 static int tcm_qla2xxx_write_pending_status(struct se_cmd
*se_cmd
)
519 * Check for WRITE_PENDING status to determine if we need to wait for
520 * CTIO aborts to be posted via hardware in tcm_qla2xxx_handle_data().
522 spin_lock_irqsave(&se_cmd
->t_state_lock
, flags
);
523 if (se_cmd
->t_state
== TRANSPORT_WRITE_PENDING
||
524 se_cmd
->t_state
== TRANSPORT_COMPLETE_QF_WP
) {
525 spin_unlock_irqrestore(&se_cmd
->t_state_lock
, flags
);
526 wait_for_completion_timeout(&se_cmd
->t_transport_stop_comp
,
530 spin_unlock_irqrestore(&se_cmd
->t_state_lock
, flags
);
535 static void tcm_qla2xxx_set_default_node_attrs(struct se_node_acl
*nacl
)
540 static u32
tcm_qla2xxx_get_task_tag(struct se_cmd
*se_cmd
)
542 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
543 struct qla_tgt_cmd
, se_cmd
);
548 static int tcm_qla2xxx_get_cmd_state(struct se_cmd
*se_cmd
)
554 * Called from process context in qla_target.c:qlt_do_work() code
556 static int tcm_qla2xxx_handle_cmd(scsi_qla_host_t
*vha
, struct qla_tgt_cmd
*cmd
,
557 unsigned char *cdb
, uint32_t data_length
, int fcp_task_attr
,
558 int data_dir
, int bidi
)
560 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
561 struct se_session
*se_sess
;
562 struct qla_tgt_sess
*sess
;
563 int flags
= TARGET_SCF_ACK_KREF
;
566 flags
|= TARGET_SCF_BIDI_OP
;
570 pr_err("Unable to locate struct qla_tgt_sess from qla_tgt_cmd\n");
574 se_sess
= sess
->se_sess
;
576 pr_err("Unable to locate active struct se_session\n");
580 return target_submit_cmd(se_cmd
, se_sess
, cdb
, &cmd
->sense_buffer
[0],
581 cmd
->unpacked_lun
, data_length
, fcp_task_attr
,
585 static void tcm_qla2xxx_handle_data_work(struct work_struct
*work
)
587 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
590 * Ensure that the complete FCP WRITE payload has been received.
591 * Otherwise return an exception via CHECK_CONDITION status.
593 if (!cmd
->write_data_transferred
) {
595 * Check if se_cmd has already been aborted via LUN_RESET, and
596 * waiting upon completion in tcm_qla2xxx_write_pending_status()
598 if (cmd
->se_cmd
.transport_state
& CMD_T_ABORTED
) {
599 complete(&cmd
->se_cmd
.t_transport_stop_comp
);
603 transport_generic_request_failure(&cmd
->se_cmd
,
604 TCM_CHECK_CONDITION_ABORT_CMD
);
608 return target_execute_cmd(&cmd
->se_cmd
);
612 * Called from qla_target.c:qlt_do_ctio_completion()
614 static void tcm_qla2xxx_handle_data(struct qla_tgt_cmd
*cmd
)
616 INIT_WORK(&cmd
->work
, tcm_qla2xxx_handle_data_work
);
617 queue_work(tcm_qla2xxx_free_wq
, &cmd
->work
);
621 * Called from qla_target.c:qlt_issue_task_mgmt()
623 static int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd
*mcmd
, uint32_t lun
,
624 uint8_t tmr_func
, uint32_t tag
)
626 struct qla_tgt_sess
*sess
= mcmd
->sess
;
627 struct se_cmd
*se_cmd
= &mcmd
->se_cmd
;
629 return target_submit_tmr(se_cmd
, sess
->se_sess
, NULL
, lun
, mcmd
,
630 tmr_func
, GFP_ATOMIC
, tag
, TARGET_SCF_ACK_KREF
);
633 static int tcm_qla2xxx_queue_data_in(struct se_cmd
*se_cmd
)
635 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
636 struct qla_tgt_cmd
, se_cmd
);
638 cmd
->bufflen
= se_cmd
->data_length
;
639 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
640 cmd
->aborted
= (se_cmd
->transport_state
& CMD_T_ABORTED
);
642 cmd
->sg_cnt
= se_cmd
->t_data_nents
;
643 cmd
->sg
= se_cmd
->t_data_sg
;
647 * Now queue completed DATA_IN the qla2xxx LLD and response ring
649 return qlt_xmit_response(cmd
, QLA_TGT_XMIT_DATA
|QLA_TGT_XMIT_STATUS
,
650 se_cmd
->scsi_status
);
653 static int tcm_qla2xxx_queue_status(struct se_cmd
*se_cmd
)
655 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
656 struct qla_tgt_cmd
, se_cmd
);
657 int xmit_type
= QLA_TGT_XMIT_STATUS
;
659 cmd
->bufflen
= se_cmd
->data_length
;
663 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
664 cmd
->aborted
= (se_cmd
->transport_state
& CMD_T_ABORTED
);
666 if (se_cmd
->data_direction
== DMA_FROM_DEVICE
) {
668 * For FCP_READ with CHECK_CONDITION status, clear cmd->bufflen
669 * for qla_tgt_xmit_response LLD code
671 if (se_cmd
->se_cmd_flags
& SCF_OVERFLOW_BIT
) {
672 se_cmd
->se_cmd_flags
&= ~SCF_OVERFLOW_BIT
;
673 se_cmd
->residual_count
= 0;
675 se_cmd
->se_cmd_flags
|= SCF_UNDERFLOW_BIT
;
676 se_cmd
->residual_count
+= se_cmd
->data_length
;
681 * Now queue status response to qla2xxx LLD code and response ring
683 return qlt_xmit_response(cmd
, xmit_type
, se_cmd
->scsi_status
);
686 static void tcm_qla2xxx_queue_tm_rsp(struct se_cmd
*se_cmd
)
688 struct se_tmr_req
*se_tmr
= se_cmd
->se_tmr_req
;
689 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(se_cmd
,
690 struct qla_tgt_mgmt_cmd
, se_cmd
);
692 pr_debug("queue_tm_rsp: mcmd: %p func: 0x%02x response: 0x%02x\n",
693 mcmd
, se_tmr
->function
, se_tmr
->response
);
695 * Do translation between TCM TM response codes and
696 * QLA2xxx FC TM response codes.
698 switch (se_tmr
->response
) {
699 case TMR_FUNCTION_COMPLETE
:
700 mcmd
->fc_tm_rsp
= FC_TM_SUCCESS
;
702 case TMR_TASK_DOES_NOT_EXIST
:
703 mcmd
->fc_tm_rsp
= FC_TM_BAD_CMD
;
705 case TMR_FUNCTION_REJECTED
:
706 mcmd
->fc_tm_rsp
= FC_TM_REJECT
;
708 case TMR_LUN_DOES_NOT_EXIST
:
710 mcmd
->fc_tm_rsp
= FC_TM_FAILED
;
714 * Queue the TM response to QLA2xxx LLD to build a
715 * CTIO response packet.
717 qlt_xmit_tm_rsp(mcmd
);
720 /* Local pointer to allocated TCM configfs fabric module */
721 struct target_fabric_configfs
*tcm_qla2xxx_fabric_configfs
;
722 struct target_fabric_configfs
*tcm_qla2xxx_npiv_fabric_configfs
;
724 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport
*,
725 struct tcm_qla2xxx_nacl
*, struct qla_tgt_sess
*);
727 * Expected to be called with struct qla_hw_data->hardware_lock held
729 static void tcm_qla2xxx_clear_nacl_from_fcport_map(struct qla_tgt_sess
*sess
)
731 struct se_node_acl
*se_nacl
= sess
->se_sess
->se_node_acl
;
732 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
733 struct se_wwn
*se_wwn
= se_tpg
->se_tpg_wwn
;
734 struct tcm_qla2xxx_lport
*lport
= container_of(se_wwn
,
735 struct tcm_qla2xxx_lport
, lport_wwn
);
736 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
737 struct tcm_qla2xxx_nacl
, se_node_acl
);
740 pr_debug("fc_rport domain: port_id 0x%06x\n", nacl
->nport_id
);
742 node
= btree_remove32(&lport
->lport_fcport_map
, nacl
->nport_id
);
743 if (WARN_ON(node
&& (node
!= se_nacl
))) {
745 * The nacl no longer matches what we think it should be.
746 * Most likely a new dynamic acl has been added while
747 * someone dropped the hardware lock. It clearly is a
748 * bug elsewhere, but this bit can't make things worse.
750 btree_insert32(&lport
->lport_fcport_map
, nacl
->nport_id
,
754 pr_debug("Removed from fcport_map: %p for WWNN: 0x%016LX, port_id: 0x%06x\n",
755 se_nacl
, nacl
->nport_wwnn
, nacl
->nport_id
);
757 * Now clear the se_nacl and session pointers from our HW lport lookup
758 * table mapping for this initiator's fabric S_ID and LOOP_ID entries.
760 * This is done ahead of callbacks into tcm_qla2xxx_free_session() ->
761 * target_wait_for_sess_cmds() before the session waits for outstanding
762 * I/O to complete, to avoid a race between session shutdown execution
763 * and incoming ATIOs or TMRs picking up a stale se_node_act reference.
765 tcm_qla2xxx_clear_sess_lookup(lport
, nacl
, sess
);
768 static void tcm_qla2xxx_release_session(struct kref
*kref
)
770 struct se_session
*se_sess
= container_of(kref
,
771 struct se_session
, sess_kref
);
773 qlt_unreg_sess(se_sess
->fabric_sess_ptr
);
776 static void tcm_qla2xxx_put_session(struct se_session
*se_sess
)
778 struct qla_tgt_sess
*sess
= se_sess
->fabric_sess_ptr
;
779 struct qla_hw_data
*ha
= sess
->vha
->hw
;
782 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
783 kref_put(&se_sess
->sess_kref
, tcm_qla2xxx_release_session
);
784 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
787 static void tcm_qla2xxx_put_sess(struct qla_tgt_sess
*sess
)
789 assert_spin_locked(&sess
->vha
->hw
->hardware_lock
);
790 kref_put(&sess
->se_sess
->sess_kref
, tcm_qla2xxx_release_session
);
793 static void tcm_qla2xxx_shutdown_sess(struct qla_tgt_sess
*sess
)
795 assert_spin_locked(&sess
->vha
->hw
->hardware_lock
);
796 target_sess_cmd_list_set_waiting(sess
->se_sess
);
799 static struct se_node_acl
*tcm_qla2xxx_make_nodeacl(
800 struct se_portal_group
*se_tpg
,
801 struct config_group
*group
,
804 struct se_node_acl
*se_nacl
, *se_nacl_new
;
805 struct tcm_qla2xxx_nacl
*nacl
;
807 u32 qla2xxx_nexus_depth
;
809 if (tcm_qla2xxx_parse_wwn(name
, &wwnn
, 1) < 0)
810 return ERR_PTR(-EINVAL
);
812 se_nacl_new
= tcm_qla2xxx_alloc_fabric_acl(se_tpg
);
814 return ERR_PTR(-ENOMEM
);
815 /* #warning FIXME: Hardcoded qla2xxx_nexus depth in tcm_qla2xxx_make_nodeacl */
816 qla2xxx_nexus_depth
= 1;
819 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
820 * when converting a NodeACL from demo mode -> explict
822 se_nacl
= core_tpg_add_initiator_node_acl(se_tpg
, se_nacl_new
,
823 name
, qla2xxx_nexus_depth
);
824 if (IS_ERR(se_nacl
)) {
825 tcm_qla2xxx_release_fabric_acl(se_tpg
, se_nacl_new
);
829 * Locate our struct tcm_qla2xxx_nacl and set the FC Nport WWPN
831 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
832 nacl
->nport_wwnn
= wwnn
;
833 tcm_qla2xxx_format_wwn(&nacl
->nport_name
[0], TCM_QLA2XXX_NAMELEN
, wwnn
);
838 static void tcm_qla2xxx_drop_nodeacl(struct se_node_acl
*se_acl
)
840 struct se_portal_group
*se_tpg
= se_acl
->se_tpg
;
841 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_acl
,
842 struct tcm_qla2xxx_nacl
, se_node_acl
);
844 core_tpg_del_initiator_node_acl(se_tpg
, se_acl
, 1);
848 /* Start items for tcm_qla2xxx_tpg_attrib_cit */
850 #define DEF_QLA_TPG_ATTRIB(name) \
852 static ssize_t tcm_qla2xxx_tpg_attrib_show_##name( \
853 struct se_portal_group *se_tpg, \
856 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
857 struct tcm_qla2xxx_tpg, se_tpg); \
859 return sprintf(page, "%u\n", QLA_TPG_ATTRIB(tpg)->name); \
862 static ssize_t tcm_qla2xxx_tpg_attrib_store_##name( \
863 struct se_portal_group *se_tpg, \
867 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
868 struct tcm_qla2xxx_tpg, se_tpg); \
872 ret = kstrtoul(page, 0, &val); \
874 pr_err("kstrtoul() failed with" \
875 " ret: %d\n", ret); \
878 ret = tcm_qla2xxx_set_attrib_##name(tpg, val); \
880 return (!ret) ? count : -EINVAL; \
883 #define DEF_QLA_TPG_ATTR_BOOL(_name) \
885 static int tcm_qla2xxx_set_attrib_##_name( \
886 struct tcm_qla2xxx_tpg *tpg, \
889 struct tcm_qla2xxx_tpg_attrib *a = &tpg->tpg_attrib; \
891 if ((val != 0) && (val != 1)) { \
892 pr_err("Illegal boolean value %lu\n", val); \
900 #define QLA_TPG_ATTR(_name, _mode) \
901 TF_TPG_ATTRIB_ATTR(tcm_qla2xxx, _name, _mode);
904 * Define tcm_qla2xxx_tpg_attrib_s_generate_node_acls
906 DEF_QLA_TPG_ATTR_BOOL(generate_node_acls
);
907 DEF_QLA_TPG_ATTRIB(generate_node_acls
);
908 QLA_TPG_ATTR(generate_node_acls
, S_IRUGO
| S_IWUSR
);
911 Define tcm_qla2xxx_attrib_s_cache_dynamic_acls
913 DEF_QLA_TPG_ATTR_BOOL(cache_dynamic_acls
);
914 DEF_QLA_TPG_ATTRIB(cache_dynamic_acls
);
915 QLA_TPG_ATTR(cache_dynamic_acls
, S_IRUGO
| S_IWUSR
);
918 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_write_protect
920 DEF_QLA_TPG_ATTR_BOOL(demo_mode_write_protect
);
921 DEF_QLA_TPG_ATTRIB(demo_mode_write_protect
);
922 QLA_TPG_ATTR(demo_mode_write_protect
, S_IRUGO
| S_IWUSR
);
925 * Define tcm_qla2xxx_tpg_attrib_s_prod_mode_write_protect
927 DEF_QLA_TPG_ATTR_BOOL(prod_mode_write_protect
);
928 DEF_QLA_TPG_ATTRIB(prod_mode_write_protect
);
929 QLA_TPG_ATTR(prod_mode_write_protect
, S_IRUGO
| S_IWUSR
);
932 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_login_only
934 DEF_QLA_TPG_ATTR_BOOL(demo_mode_login_only
);
935 DEF_QLA_TPG_ATTRIB(demo_mode_login_only
);
936 QLA_TPG_ATTR(demo_mode_login_only
, S_IRUGO
| S_IWUSR
);
938 static struct configfs_attribute
*tcm_qla2xxx_tpg_attrib_attrs
[] = {
939 &tcm_qla2xxx_tpg_attrib_generate_node_acls
.attr
,
940 &tcm_qla2xxx_tpg_attrib_cache_dynamic_acls
.attr
,
941 &tcm_qla2xxx_tpg_attrib_demo_mode_write_protect
.attr
,
942 &tcm_qla2xxx_tpg_attrib_prod_mode_write_protect
.attr
,
943 &tcm_qla2xxx_tpg_attrib_demo_mode_login_only
.attr
,
947 /* End items for tcm_qla2xxx_tpg_attrib_cit */
949 static ssize_t
tcm_qla2xxx_tpg_show_enable(
950 struct se_portal_group
*se_tpg
,
953 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
954 struct tcm_qla2xxx_tpg
, se_tpg
);
956 return snprintf(page
, PAGE_SIZE
, "%d\n",
957 atomic_read(&tpg
->lport_tpg_enabled
));
960 static ssize_t
tcm_qla2xxx_tpg_store_enable(
961 struct se_portal_group
*se_tpg
,
965 struct se_wwn
*se_wwn
= se_tpg
->se_tpg_wwn
;
966 struct tcm_qla2xxx_lport
*lport
= container_of(se_wwn
,
967 struct tcm_qla2xxx_lport
, lport_wwn
);
968 struct scsi_qla_host
*vha
= lport
->qla_vha
;
969 struct qla_hw_data
*ha
= vha
->hw
;
970 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
971 struct tcm_qla2xxx_tpg
, se_tpg
);
975 rc
= kstrtoul(page
, 0, &op
);
977 pr_err("kstrtoul() returned %d\n", rc
);
980 if ((op
!= 1) && (op
!= 0)) {
981 pr_err("Illegal value for tpg_enable: %lu\n", op
);
986 atomic_set(&tpg
->lport_tpg_enabled
, 1);
989 if (!ha
->tgt
.qla_tgt
) {
990 pr_err("truct qla_hw_data *ha->tgt.qla_tgt is NULL\n");
993 atomic_set(&tpg
->lport_tpg_enabled
, 0);
994 qlt_stop_phase1(ha
->tgt
.qla_tgt
);
1000 TF_TPG_BASE_ATTR(tcm_qla2xxx
, enable
, S_IRUGO
| S_IWUSR
);
1002 static struct configfs_attribute
*tcm_qla2xxx_tpg_attrs
[] = {
1003 &tcm_qla2xxx_tpg_enable
.attr
,
1007 static struct se_portal_group
*tcm_qla2xxx_make_tpg(
1009 struct config_group
*group
,
1012 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1013 struct tcm_qla2xxx_lport
, lport_wwn
);
1014 struct tcm_qla2xxx_tpg
*tpg
;
1018 if (strstr(name
, "tpgt_") != name
)
1019 return ERR_PTR(-EINVAL
);
1020 if (kstrtoul(name
+ 5, 10, &tpgt
) || tpgt
> USHRT_MAX
)
1021 return ERR_PTR(-EINVAL
);
1023 if (!lport
->qla_npiv_vp
&& (tpgt
!= 1)) {
1024 pr_err("In non NPIV mode, a single TPG=1 is used for HW port mappings\n");
1025 return ERR_PTR(-ENOSYS
);
1028 tpg
= kzalloc(sizeof(struct tcm_qla2xxx_tpg
), GFP_KERNEL
);
1030 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1031 return ERR_PTR(-ENOMEM
);
1034 tpg
->lport_tpgt
= tpgt
;
1036 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1039 QLA_TPG_ATTRIB(tpg
)->generate_node_acls
= 1;
1040 QLA_TPG_ATTRIB(tpg
)->demo_mode_write_protect
= 1;
1041 QLA_TPG_ATTRIB(tpg
)->cache_dynamic_acls
= 1;
1042 QLA_TPG_ATTRIB(tpg
)->demo_mode_login_only
= 1;
1044 ret
= core_tpg_register(&tcm_qla2xxx_fabric_configfs
->tf_ops
, wwn
,
1045 &tpg
->se_tpg
, tpg
, TRANSPORT_TPG_TYPE_NORMAL
);
1051 * Setup local TPG=1 pointer for non NPIV mode.
1053 if (lport
->qla_npiv_vp
== NULL
)
1056 return &tpg
->se_tpg
;
1059 static void tcm_qla2xxx_drop_tpg(struct se_portal_group
*se_tpg
)
1061 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1062 struct tcm_qla2xxx_tpg
, se_tpg
);
1063 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
1064 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1065 struct qla_hw_data
*ha
= vha
->hw
;
1067 * Call into qla2x_target.c LLD logic to shutdown the active
1068 * FC Nexuses and disable target mode operation for this qla_hw_data
1070 if (ha
->tgt
.qla_tgt
&& !ha
->tgt
.qla_tgt
->tgt_stop
)
1071 qlt_stop_phase1(ha
->tgt
.qla_tgt
);
1073 core_tpg_deregister(se_tpg
);
1075 * Clear local TPG=1 pointer for non NPIV mode.
1077 if (lport
->qla_npiv_vp
== NULL
)
1078 lport
->tpg_1
= NULL
;
1083 static struct se_portal_group
*tcm_qla2xxx_npiv_make_tpg(
1085 struct config_group
*group
,
1088 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1089 struct tcm_qla2xxx_lport
, lport_wwn
);
1090 struct tcm_qla2xxx_tpg
*tpg
;
1094 if (strstr(name
, "tpgt_") != name
)
1095 return ERR_PTR(-EINVAL
);
1096 if (kstrtoul(name
+ 5, 10, &tpgt
) || tpgt
> USHRT_MAX
)
1097 return ERR_PTR(-EINVAL
);
1099 tpg
= kzalloc(sizeof(struct tcm_qla2xxx_tpg
), GFP_KERNEL
);
1101 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1102 return ERR_PTR(-ENOMEM
);
1105 tpg
->lport_tpgt
= tpgt
;
1107 ret
= core_tpg_register(&tcm_qla2xxx_npiv_fabric_configfs
->tf_ops
, wwn
,
1108 &tpg
->se_tpg
, tpg
, TRANSPORT_TPG_TYPE_NORMAL
);
1113 return &tpg
->se_tpg
;
1117 * Expected to be called with struct qla_hw_data->hardware_lock held
1119 static struct qla_tgt_sess
*tcm_qla2xxx_find_sess_by_s_id(
1120 scsi_qla_host_t
*vha
,
1121 const uint8_t *s_id
)
1123 struct qla_hw_data
*ha
= vha
->hw
;
1124 struct tcm_qla2xxx_lport
*lport
;
1125 struct se_node_acl
*se_nacl
;
1126 struct tcm_qla2xxx_nacl
*nacl
;
1129 lport
= ha
->tgt
.target_lport_ptr
;
1131 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1136 key
= (((unsigned long)s_id
[0] << 16) |
1137 ((unsigned long)s_id
[1] << 8) |
1138 (unsigned long)s_id
[2]);
1139 pr_debug("find_sess_by_s_id: 0x%06x\n", key
);
1141 se_nacl
= btree_lookup32(&lport
->lport_fcport_map
, key
);
1143 pr_debug("Unable to locate s_id: 0x%06x\n", key
);
1146 pr_debug("find_sess_by_s_id: located se_nacl: %p, initiatorname: %s\n",
1147 se_nacl
, se_nacl
->initiatorname
);
1149 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1150 if (!nacl
->qla_tgt_sess
) {
1151 pr_err("Unable to locate struct qla_tgt_sess\n");
1155 return nacl
->qla_tgt_sess
;
1159 * Expected to be called with struct qla_hw_data->hardware_lock held
1161 static void tcm_qla2xxx_set_sess_by_s_id(
1162 struct tcm_qla2xxx_lport
*lport
,
1163 struct se_node_acl
*new_se_nacl
,
1164 struct tcm_qla2xxx_nacl
*nacl
,
1165 struct se_session
*se_sess
,
1166 struct qla_tgt_sess
*qla_tgt_sess
,
1173 key
= (((unsigned long)s_id
[0] << 16) |
1174 ((unsigned long)s_id
[1] << 8) |
1175 (unsigned long)s_id
[2]);
1176 pr_debug("set_sess_by_s_id: %06x\n", key
);
1178 slot
= btree_lookup32(&lport
->lport_fcport_map
, key
);
1181 pr_debug("Setting up new fc_port entry to new_se_nacl\n");
1182 nacl
->nport_id
= key
;
1183 rc
= btree_insert32(&lport
->lport_fcport_map
, key
,
1184 new_se_nacl
, GFP_ATOMIC
);
1186 printk(KERN_ERR
"Unable to insert s_id into fcport_map: %06x\n",
1189 pr_debug("Wiping nonexisting fc_port entry\n");
1192 qla_tgt_sess
->se_sess
= se_sess
;
1193 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1197 if (nacl
->qla_tgt_sess
) {
1198 if (new_se_nacl
== NULL
) {
1199 pr_debug("Clearing existing nacl->qla_tgt_sess and fc_port entry\n");
1200 btree_remove32(&lport
->lport_fcport_map
, key
);
1201 nacl
->qla_tgt_sess
= NULL
;
1204 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_port entry\n");
1205 btree_update32(&lport
->lport_fcport_map
, key
, new_se_nacl
);
1206 qla_tgt_sess
->se_sess
= se_sess
;
1207 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1211 if (new_se_nacl
== NULL
) {
1212 pr_debug("Clearing existing fc_port entry\n");
1213 btree_remove32(&lport
->lport_fcport_map
, key
);
1217 pr_debug("Replacing existing fc_port entry w/o active nacl->qla_tgt_sess\n");
1218 btree_update32(&lport
->lport_fcport_map
, key
, new_se_nacl
);
1219 qla_tgt_sess
->se_sess
= se_sess
;
1220 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1222 pr_debug("Setup nacl->qla_tgt_sess %p by s_id for se_nacl: %p, initiatorname: %s\n",
1223 nacl
->qla_tgt_sess
, new_se_nacl
, new_se_nacl
->initiatorname
);
1227 * Expected to be called with struct qla_hw_data->hardware_lock held
1229 static struct qla_tgt_sess
*tcm_qla2xxx_find_sess_by_loop_id(
1230 scsi_qla_host_t
*vha
,
1231 const uint16_t loop_id
)
1233 struct qla_hw_data
*ha
= vha
->hw
;
1234 struct tcm_qla2xxx_lport
*lport
;
1235 struct se_node_acl
*se_nacl
;
1236 struct tcm_qla2xxx_nacl
*nacl
;
1237 struct tcm_qla2xxx_fc_loopid
*fc_loopid
;
1239 lport
= ha
->tgt
.target_lport_ptr
;
1241 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1246 pr_debug("find_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id
);
1248 fc_loopid
= lport
->lport_loopid_map
+ loop_id
;
1249 se_nacl
= fc_loopid
->se_nacl
;
1251 pr_debug("Unable to locate se_nacl by loop_id: 0x%04x\n",
1256 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1258 if (!nacl
->qla_tgt_sess
) {
1259 pr_err("Unable to locate struct qla_tgt_sess\n");
1263 return nacl
->qla_tgt_sess
;
1267 * Expected to be called with struct qla_hw_data->hardware_lock held
1269 static void tcm_qla2xxx_set_sess_by_loop_id(
1270 struct tcm_qla2xxx_lport
*lport
,
1271 struct se_node_acl
*new_se_nacl
,
1272 struct tcm_qla2xxx_nacl
*nacl
,
1273 struct se_session
*se_sess
,
1274 struct qla_tgt_sess
*qla_tgt_sess
,
1277 struct se_node_acl
*saved_nacl
;
1278 struct tcm_qla2xxx_fc_loopid
*fc_loopid
;
1280 pr_debug("set_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id
);
1282 fc_loopid
= &((struct tcm_qla2xxx_fc_loopid
*)
1283 lport
->lport_loopid_map
)[loop_id
];
1285 saved_nacl
= fc_loopid
->se_nacl
;
1287 pr_debug("Setting up new fc_loopid->se_nacl to new_se_nacl\n");
1288 fc_loopid
->se_nacl
= new_se_nacl
;
1289 if (qla_tgt_sess
->se_sess
!= se_sess
)
1290 qla_tgt_sess
->se_sess
= se_sess
;
1291 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1292 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1296 if (nacl
->qla_tgt_sess
) {
1297 if (new_se_nacl
== NULL
) {
1298 pr_debug("Clearing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1299 fc_loopid
->se_nacl
= NULL
;
1300 nacl
->qla_tgt_sess
= NULL
;
1304 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1305 fc_loopid
->se_nacl
= new_se_nacl
;
1306 if (qla_tgt_sess
->se_sess
!= se_sess
)
1307 qla_tgt_sess
->se_sess
= se_sess
;
1308 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1309 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1313 if (new_se_nacl
== NULL
) {
1314 pr_debug("Clearing fc_loopid->se_nacl\n");
1315 fc_loopid
->se_nacl
= NULL
;
1319 pr_debug("Replacing existing fc_loopid->se_nacl w/o active nacl->qla_tgt_sess\n");
1320 fc_loopid
->se_nacl
= new_se_nacl
;
1321 if (qla_tgt_sess
->se_sess
!= se_sess
)
1322 qla_tgt_sess
->se_sess
= se_sess
;
1323 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1324 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1326 pr_debug("Setup nacl->qla_tgt_sess %p by loop_id for se_nacl: %p, initiatorname: %s\n",
1327 nacl
->qla_tgt_sess
, new_se_nacl
, new_se_nacl
->initiatorname
);
1331 * Should always be called with qla_hw_data->hardware_lock held.
1333 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport
*lport
,
1334 struct tcm_qla2xxx_nacl
*nacl
, struct qla_tgt_sess
*sess
)
1336 struct se_session
*se_sess
= sess
->se_sess
;
1337 unsigned char be_sid
[3];
1339 be_sid
[0] = sess
->s_id
.b
.domain
;
1340 be_sid
[1] = sess
->s_id
.b
.area
;
1341 be_sid
[2] = sess
->s_id
.b
.al_pa
;
1343 tcm_qla2xxx_set_sess_by_s_id(lport
, NULL
, nacl
, se_sess
,
1345 tcm_qla2xxx_set_sess_by_loop_id(lport
, NULL
, nacl
, se_sess
,
1346 sess
, sess
->loop_id
);
1349 static void tcm_qla2xxx_free_session(struct qla_tgt_sess
*sess
)
1351 struct qla_tgt
*tgt
= sess
->tgt
;
1352 struct qla_hw_data
*ha
= tgt
->ha
;
1353 struct se_session
*se_sess
;
1354 struct se_node_acl
*se_nacl
;
1355 struct tcm_qla2xxx_lport
*lport
;
1356 struct tcm_qla2xxx_nacl
*nacl
;
1358 BUG_ON(in_interrupt());
1360 se_sess
= sess
->se_sess
;
1362 pr_err("struct qla_tgt_sess->se_sess is NULL\n");
1366 se_nacl
= se_sess
->se_node_acl
;
1367 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1369 lport
= ha
->tgt
.target_lport_ptr
;
1371 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1375 target_wait_for_sess_cmds(se_sess
);
1377 transport_deregister_session_configfs(sess
->se_sess
);
1378 transport_deregister_session(sess
->se_sess
);
1382 * Called via qlt_create_sess():ha->qla2x_tmpl->check_initiator_node_acl()
1383 * to locate struct se_node_acl
1385 static int tcm_qla2xxx_check_initiator_node_acl(
1386 scsi_qla_host_t
*vha
,
1387 unsigned char *fc_wwpn
,
1392 struct qla_hw_data
*ha
= vha
->hw
;
1393 struct tcm_qla2xxx_lport
*lport
;
1394 struct tcm_qla2xxx_tpg
*tpg
;
1395 struct tcm_qla2xxx_nacl
*nacl
;
1396 struct se_portal_group
*se_tpg
;
1397 struct se_node_acl
*se_nacl
;
1398 struct se_session
*se_sess
;
1399 struct qla_tgt_sess
*sess
= qla_tgt_sess
;
1400 unsigned char port_name
[36];
1401 unsigned long flags
;
1403 lport
= ha
->tgt
.target_lport_ptr
;
1405 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1410 * Locate the TPG=1 reference..
1414 pr_err("Unable to lcoate struct tcm_qla2xxx_lport->tpg_1\n");
1417 se_tpg
= &tpg
->se_tpg
;
1419 se_sess
= transport_init_session();
1420 if (IS_ERR(se_sess
)) {
1421 pr_err("Unable to initialize struct se_session\n");
1422 return PTR_ERR(se_sess
);
1425 * Format the FCP Initiator port_name into colon seperated values to
1426 * match the format by tcm_qla2xxx explict ConfigFS NodeACLs.
1428 memset(&port_name
, 0, 36);
1429 snprintf(port_name
, 36, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1430 fc_wwpn
[0], fc_wwpn
[1], fc_wwpn
[2], fc_wwpn
[3], fc_wwpn
[4],
1431 fc_wwpn
[5], fc_wwpn
[6], fc_wwpn
[7]);
1433 * Locate our struct se_node_acl either from an explict NodeACL created
1434 * via ConfigFS, or via running in TPG demo mode.
1436 se_sess
->se_node_acl
= core_tpg_check_initiator_node_acl(se_tpg
,
1438 if (!se_sess
->se_node_acl
) {
1439 transport_free_session(se_sess
);
1442 se_nacl
= se_sess
->se_node_acl
;
1443 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1445 * And now setup the new se_nacl and session pointers into our HW lport
1446 * mappings for fabric S_ID and LOOP_ID.
1448 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1449 tcm_qla2xxx_set_sess_by_s_id(lport
, se_nacl
, nacl
, se_sess
,
1450 qla_tgt_sess
, s_id
);
1451 tcm_qla2xxx_set_sess_by_loop_id(lport
, se_nacl
, nacl
, se_sess
,
1452 qla_tgt_sess
, loop_id
);
1453 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1455 * Finally register the new FC Nexus with TCM
1457 transport_register_session(se_nacl
->se_tpg
, se_nacl
, se_sess
, sess
);
1462 static void tcm_qla2xxx_update_sess(struct qla_tgt_sess
*sess
, port_id_t s_id
,
1463 uint16_t loop_id
, bool conf_compl_supported
)
1465 struct qla_tgt
*tgt
= sess
->tgt
;
1466 struct qla_hw_data
*ha
= tgt
->ha
;
1467 struct tcm_qla2xxx_lport
*lport
= ha
->tgt
.target_lport_ptr
;
1468 struct se_node_acl
*se_nacl
= sess
->se_sess
->se_node_acl
;
1469 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
1470 struct tcm_qla2xxx_nacl
, se_node_acl
);
1474 if (sess
->loop_id
!= loop_id
|| sess
->s_id
.b24
!= s_id
.b24
)
1475 pr_info("Updating session %p from port %8phC loop_id %d -> %d s_id %x:%x:%x -> %x:%x:%x\n",
1476 sess
, sess
->port_name
,
1477 sess
->loop_id
, loop_id
, sess
->s_id
.b
.domain
,
1478 sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
, s_id
.b
.domain
,
1479 s_id
.b
.area
, s_id
.b
.al_pa
);
1481 if (sess
->loop_id
!= loop_id
) {
1483 * Because we can shuffle loop IDs around and we
1484 * update different sessions non-atomically, we might
1485 * have overwritten this session's old loop ID
1486 * already, and we might end up overwriting some other
1487 * session that will be updated later. So we have to
1488 * be extra careful and we can't warn about those things...
1490 if (lport
->lport_loopid_map
[sess
->loop_id
].se_nacl
== se_nacl
)
1491 lport
->lport_loopid_map
[sess
->loop_id
].se_nacl
= NULL
;
1493 lport
->lport_loopid_map
[loop_id
].se_nacl
= se_nacl
;
1495 sess
->loop_id
= loop_id
;
1498 if (sess
->s_id
.b24
!= s_id
.b24
) {
1499 key
= (((u32
) sess
->s_id
.b
.domain
<< 16) |
1500 ((u32
) sess
->s_id
.b
.area
<< 8) |
1501 ((u32
) sess
->s_id
.b
.al_pa
));
1503 if (btree_lookup32(&lport
->lport_fcport_map
, key
))
1504 WARN(btree_remove32(&lport
->lport_fcport_map
, key
) != se_nacl
,
1505 "Found wrong se_nacl when updating s_id %x:%x:%x\n",
1506 sess
->s_id
.b
.domain
, sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
);
1508 WARN(1, "No lport_fcport_map entry for s_id %x:%x:%x\n",
1509 sess
->s_id
.b
.domain
, sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
);
1511 key
= (((u32
) s_id
.b
.domain
<< 16) |
1512 ((u32
) s_id
.b
.area
<< 8) |
1513 ((u32
) s_id
.b
.al_pa
));
1515 if (btree_lookup32(&lport
->lport_fcport_map
, key
)) {
1516 WARN(1, "Already have lport_fcport_map entry for s_id %x:%x:%x\n",
1517 s_id
.b
.domain
, s_id
.b
.area
, s_id
.b
.al_pa
);
1518 btree_update32(&lport
->lport_fcport_map
, key
, se_nacl
);
1520 btree_insert32(&lport
->lport_fcport_map
, key
, se_nacl
, GFP_ATOMIC
);
1524 nacl
->nport_id
= key
;
1527 sess
->conf_compl_supported
= conf_compl_supported
;
1531 * Calls into tcm_qla2xxx used by qla2xxx LLD I/O path.
1533 static struct qla_tgt_func_tmpl tcm_qla2xxx_template
= {
1534 .handle_cmd
= tcm_qla2xxx_handle_cmd
,
1535 .handle_data
= tcm_qla2xxx_handle_data
,
1536 .handle_tmr
= tcm_qla2xxx_handle_tmr
,
1537 .free_cmd
= tcm_qla2xxx_free_cmd
,
1538 .free_mcmd
= tcm_qla2xxx_free_mcmd
,
1539 .free_session
= tcm_qla2xxx_free_session
,
1540 .update_sess
= tcm_qla2xxx_update_sess
,
1541 .check_initiator_node_acl
= tcm_qla2xxx_check_initiator_node_acl
,
1542 .find_sess_by_s_id
= tcm_qla2xxx_find_sess_by_s_id
,
1543 .find_sess_by_loop_id
= tcm_qla2xxx_find_sess_by_loop_id
,
1544 .clear_nacl_from_fcport_map
= tcm_qla2xxx_clear_nacl_from_fcport_map
,
1545 .put_sess
= tcm_qla2xxx_put_sess
,
1546 .shutdown_sess
= tcm_qla2xxx_shutdown_sess
,
1549 static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport
*lport
)
1553 rc
= btree_init32(&lport
->lport_fcport_map
);
1555 pr_err("Unable to initialize lport->lport_fcport_map btree\n");
1559 lport
->lport_loopid_map
= vmalloc(sizeof(struct tcm_qla2xxx_fc_loopid
) *
1561 if (!lport
->lport_loopid_map
) {
1562 pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n",
1563 sizeof(struct tcm_qla2xxx_fc_loopid
) * 65536);
1564 btree_destroy32(&lport
->lport_fcport_map
);
1567 memset(lport
->lport_loopid_map
, 0, sizeof(struct tcm_qla2xxx_fc_loopid
)
1569 pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n",
1570 sizeof(struct tcm_qla2xxx_fc_loopid
) * 65536);
1574 static int tcm_qla2xxx_lport_register_cb(struct scsi_qla_host
*vha
)
1576 struct qla_hw_data
*ha
= vha
->hw
;
1577 struct tcm_qla2xxx_lport
*lport
;
1579 * Setup local pointer to vha, NPIV VP pointer (if present) and
1580 * vha->tcm_lport pointer
1582 lport
= (struct tcm_qla2xxx_lport
*)ha
->tgt
.target_lport_ptr
;
1583 lport
->qla_vha
= vha
;
1588 static struct se_wwn
*tcm_qla2xxx_make_lport(
1589 struct target_fabric_configfs
*tf
,
1590 struct config_group
*group
,
1593 struct tcm_qla2xxx_lport
*lport
;
1597 if (tcm_qla2xxx_parse_wwn(name
, &wwpn
, 1) < 0)
1598 return ERR_PTR(-EINVAL
);
1600 lport
= kzalloc(sizeof(struct tcm_qla2xxx_lport
), GFP_KERNEL
);
1602 pr_err("Unable to allocate struct tcm_qla2xxx_lport\n");
1603 return ERR_PTR(-ENOMEM
);
1605 lport
->lport_wwpn
= wwpn
;
1606 tcm_qla2xxx_format_wwn(&lport
->lport_name
[0], TCM_QLA2XXX_NAMELEN
,
1608 sprintf(lport
->lport_naa_name
, "naa.%016llx", (unsigned long long) wwpn
);
1610 ret
= tcm_qla2xxx_init_lport(lport
);
1614 ret
= qlt_lport_register(&tcm_qla2xxx_template
, wwpn
,
1615 tcm_qla2xxx_lport_register_cb
, lport
);
1619 return &lport
->lport_wwn
;
1621 vfree(lport
->lport_loopid_map
);
1622 btree_destroy32(&lport
->lport_fcport_map
);
1625 return ERR_PTR(ret
);
1628 static void tcm_qla2xxx_drop_lport(struct se_wwn
*wwn
)
1630 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1631 struct tcm_qla2xxx_lport
, lport_wwn
);
1632 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1633 struct qla_hw_data
*ha
= vha
->hw
;
1634 struct se_node_acl
*node
;
1638 * Call into qla2x_target.c LLD logic to complete the
1639 * shutdown of struct qla_tgt after the call to
1640 * qlt_stop_phase1() from tcm_qla2xxx_drop_tpg() above..
1642 if (ha
->tgt
.qla_tgt
&& !ha
->tgt
.qla_tgt
->tgt_stopped
)
1643 qlt_stop_phase2(ha
->tgt
.qla_tgt
);
1645 qlt_lport_deregister(vha
);
1647 vfree(lport
->lport_loopid_map
);
1648 btree_for_each_safe32(&lport
->lport_fcport_map
, key
, node
)
1649 btree_remove32(&lport
->lport_fcport_map
, key
);
1650 btree_destroy32(&lport
->lport_fcport_map
);
1654 static struct se_wwn
*tcm_qla2xxx_npiv_make_lport(
1655 struct target_fabric_configfs
*tf
,
1656 struct config_group
*group
,
1659 struct tcm_qla2xxx_lport
*lport
;
1660 u64 npiv_wwpn
, npiv_wwnn
;
1663 if (tcm_qla2xxx_npiv_parse_wwn(name
, strlen(name
)+1,
1664 &npiv_wwpn
, &npiv_wwnn
) < 0)
1665 return ERR_PTR(-EINVAL
);
1667 lport
= kzalloc(sizeof(struct tcm_qla2xxx_lport
), GFP_KERNEL
);
1669 pr_err("Unable to allocate struct tcm_qla2xxx_lport for NPIV\n");
1670 return ERR_PTR(-ENOMEM
);
1672 lport
->lport_npiv_wwpn
= npiv_wwpn
;
1673 lport
->lport_npiv_wwnn
= npiv_wwnn
;
1674 tcm_qla2xxx_npiv_format_wwn(&lport
->lport_npiv_name
[0],
1675 TCM_QLA2XXX_NAMELEN
, npiv_wwpn
, npiv_wwnn
);
1676 sprintf(lport
->lport_naa_name
, "naa.%016llx", (unsigned long long) npiv_wwpn
);
1678 /* FIXME: tcm_qla2xxx_npiv_make_lport */
1683 return &lport
->lport_wwn
;
1686 return ERR_PTR(ret
);
1689 static void tcm_qla2xxx_npiv_drop_lport(struct se_wwn
*wwn
)
1691 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1692 struct tcm_qla2xxx_lport
, lport_wwn
);
1693 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1694 struct Scsi_Host
*sh
= vha
->host
;
1696 * Notify libfc that we want to release the lport->npiv_vport
1698 fc_vport_terminate(lport
->npiv_vport
);
1705 static ssize_t
tcm_qla2xxx_wwn_show_attr_version(
1706 struct target_fabric_configfs
*tf
,
1709 return sprintf(page
,
1710 "TCM QLOGIC QLA2XXX NPIV capable fabric module %s on %s/%s on "
1711 UTS_RELEASE
"\n", TCM_QLA2XXX_VERSION
, utsname()->sysname
,
1712 utsname()->machine
);
1715 TF_WWN_ATTR_RO(tcm_qla2xxx
, version
);
1717 static struct configfs_attribute
*tcm_qla2xxx_wwn_attrs
[] = {
1718 &tcm_qla2xxx_wwn_version
.attr
,
1722 static struct target_core_fabric_ops tcm_qla2xxx_ops
= {
1723 .get_fabric_name
= tcm_qla2xxx_get_fabric_name
,
1724 .get_fabric_proto_ident
= tcm_qla2xxx_get_fabric_proto_ident
,
1725 .tpg_get_wwn
= tcm_qla2xxx_get_fabric_wwn
,
1726 .tpg_get_tag
= tcm_qla2xxx_get_tag
,
1727 .tpg_get_default_depth
= tcm_qla2xxx_get_default_depth
,
1728 .tpg_get_pr_transport_id
= tcm_qla2xxx_get_pr_transport_id
,
1729 .tpg_get_pr_transport_id_len
= tcm_qla2xxx_get_pr_transport_id_len
,
1730 .tpg_parse_pr_out_transport_id
= tcm_qla2xxx_parse_pr_out_transport_id
,
1731 .tpg_check_demo_mode
= tcm_qla2xxx_check_demo_mode
,
1732 .tpg_check_demo_mode_cache
= tcm_qla2xxx_check_demo_mode_cache
,
1733 .tpg_check_demo_mode_write_protect
=
1734 tcm_qla2xxx_check_demo_write_protect
,
1735 .tpg_check_prod_mode_write_protect
=
1736 tcm_qla2xxx_check_prod_write_protect
,
1737 .tpg_check_demo_mode_login_only
= tcm_qla2xxx_check_demo_mode_login_only
,
1738 .tpg_alloc_fabric_acl
= tcm_qla2xxx_alloc_fabric_acl
,
1739 .tpg_release_fabric_acl
= tcm_qla2xxx_release_fabric_acl
,
1740 .tpg_get_inst_index
= tcm_qla2xxx_tpg_get_inst_index
,
1741 .check_stop_free
= tcm_qla2xxx_check_stop_free
,
1742 .release_cmd
= tcm_qla2xxx_release_cmd
,
1743 .put_session
= tcm_qla2xxx_put_session
,
1744 .shutdown_session
= tcm_qla2xxx_shutdown_session
,
1745 .close_session
= tcm_qla2xxx_close_session
,
1746 .sess_get_index
= tcm_qla2xxx_sess_get_index
,
1747 .sess_get_initiator_sid
= NULL
,
1748 .write_pending
= tcm_qla2xxx_write_pending
,
1749 .write_pending_status
= tcm_qla2xxx_write_pending_status
,
1750 .set_default_node_attributes
= tcm_qla2xxx_set_default_node_attrs
,
1751 .get_task_tag
= tcm_qla2xxx_get_task_tag
,
1752 .get_cmd_state
= tcm_qla2xxx_get_cmd_state
,
1753 .queue_data_in
= tcm_qla2xxx_queue_data_in
,
1754 .queue_status
= tcm_qla2xxx_queue_status
,
1755 .queue_tm_rsp
= tcm_qla2xxx_queue_tm_rsp
,
1757 * Setup function pointers for generic logic in
1758 * target_core_fabric_configfs.c
1760 .fabric_make_wwn
= tcm_qla2xxx_make_lport
,
1761 .fabric_drop_wwn
= tcm_qla2xxx_drop_lport
,
1762 .fabric_make_tpg
= tcm_qla2xxx_make_tpg
,
1763 .fabric_drop_tpg
= tcm_qla2xxx_drop_tpg
,
1764 .fabric_post_link
= NULL
,
1765 .fabric_pre_unlink
= NULL
,
1766 .fabric_make_np
= NULL
,
1767 .fabric_drop_np
= NULL
,
1768 .fabric_make_nodeacl
= tcm_qla2xxx_make_nodeacl
,
1769 .fabric_drop_nodeacl
= tcm_qla2xxx_drop_nodeacl
,
1772 static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops
= {
1773 .get_fabric_name
= tcm_qla2xxx_npiv_get_fabric_name
,
1774 .get_fabric_proto_ident
= tcm_qla2xxx_get_fabric_proto_ident
,
1775 .tpg_get_wwn
= tcm_qla2xxx_npiv_get_fabric_wwn
,
1776 .tpg_get_tag
= tcm_qla2xxx_get_tag
,
1777 .tpg_get_default_depth
= tcm_qla2xxx_get_default_depth
,
1778 .tpg_get_pr_transport_id
= tcm_qla2xxx_get_pr_transport_id
,
1779 .tpg_get_pr_transport_id_len
= tcm_qla2xxx_get_pr_transport_id_len
,
1780 .tpg_parse_pr_out_transport_id
= tcm_qla2xxx_parse_pr_out_transport_id
,
1781 .tpg_check_demo_mode
= tcm_qla2xxx_check_false
,
1782 .tpg_check_demo_mode_cache
= tcm_qla2xxx_check_true
,
1783 .tpg_check_demo_mode_write_protect
= tcm_qla2xxx_check_true
,
1784 .tpg_check_prod_mode_write_protect
= tcm_qla2xxx_check_false
,
1785 .tpg_check_demo_mode_login_only
= tcm_qla2xxx_check_demo_mode_login_only
,
1786 .tpg_alloc_fabric_acl
= tcm_qla2xxx_alloc_fabric_acl
,
1787 .tpg_release_fabric_acl
= tcm_qla2xxx_release_fabric_acl
,
1788 .tpg_get_inst_index
= tcm_qla2xxx_tpg_get_inst_index
,
1789 .release_cmd
= tcm_qla2xxx_release_cmd
,
1790 .put_session
= tcm_qla2xxx_put_session
,
1791 .shutdown_session
= tcm_qla2xxx_shutdown_session
,
1792 .close_session
= tcm_qla2xxx_close_session
,
1793 .sess_get_index
= tcm_qla2xxx_sess_get_index
,
1794 .sess_get_initiator_sid
= NULL
,
1795 .write_pending
= tcm_qla2xxx_write_pending
,
1796 .write_pending_status
= tcm_qla2xxx_write_pending_status
,
1797 .set_default_node_attributes
= tcm_qla2xxx_set_default_node_attrs
,
1798 .get_task_tag
= tcm_qla2xxx_get_task_tag
,
1799 .get_cmd_state
= tcm_qla2xxx_get_cmd_state
,
1800 .queue_data_in
= tcm_qla2xxx_queue_data_in
,
1801 .queue_status
= tcm_qla2xxx_queue_status
,
1802 .queue_tm_rsp
= tcm_qla2xxx_queue_tm_rsp
,
1804 * Setup function pointers for generic logic in
1805 * target_core_fabric_configfs.c
1807 .fabric_make_wwn
= tcm_qla2xxx_npiv_make_lport
,
1808 .fabric_drop_wwn
= tcm_qla2xxx_npiv_drop_lport
,
1809 .fabric_make_tpg
= tcm_qla2xxx_npiv_make_tpg
,
1810 .fabric_drop_tpg
= tcm_qla2xxx_drop_tpg
,
1811 .fabric_post_link
= NULL
,
1812 .fabric_pre_unlink
= NULL
,
1813 .fabric_make_np
= NULL
,
1814 .fabric_drop_np
= NULL
,
1815 .fabric_make_nodeacl
= tcm_qla2xxx_make_nodeacl
,
1816 .fabric_drop_nodeacl
= tcm_qla2xxx_drop_nodeacl
,
1819 static int tcm_qla2xxx_register_configfs(void)
1821 struct target_fabric_configfs
*fabric
, *npiv_fabric
;
1824 pr_debug("TCM QLOGIC QLA2XXX fabric module %s on %s/%s on "
1825 UTS_RELEASE
"\n", TCM_QLA2XXX_VERSION
, utsname()->sysname
,
1826 utsname()->machine
);
1828 * Register the top level struct config_item_type with TCM core
1830 fabric
= target_fabric_configfs_init(THIS_MODULE
, "qla2xxx");
1831 if (IS_ERR(fabric
)) {
1832 pr_err("target_fabric_configfs_init() failed\n");
1833 return PTR_ERR(fabric
);
1836 * Setup fabric->tf_ops from our local tcm_qla2xxx_ops
1838 fabric
->tf_ops
= tcm_qla2xxx_ops
;
1840 * Setup default attribute lists for various fabric->tf_cit_tmpl
1842 TF_CIT_TMPL(fabric
)->tfc_wwn_cit
.ct_attrs
= tcm_qla2xxx_wwn_attrs
;
1843 TF_CIT_TMPL(fabric
)->tfc_tpg_base_cit
.ct_attrs
= tcm_qla2xxx_tpg_attrs
;
1844 TF_CIT_TMPL(fabric
)->tfc_tpg_attrib_cit
.ct_attrs
=
1845 tcm_qla2xxx_tpg_attrib_attrs
;
1846 TF_CIT_TMPL(fabric
)->tfc_tpg_param_cit
.ct_attrs
= NULL
;
1847 TF_CIT_TMPL(fabric
)->tfc_tpg_np_base_cit
.ct_attrs
= NULL
;
1848 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_base_cit
.ct_attrs
= NULL
;
1849 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_attrib_cit
.ct_attrs
= NULL
;
1850 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_auth_cit
.ct_attrs
= NULL
;
1851 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_param_cit
.ct_attrs
= NULL
;
1853 * Register the fabric for use within TCM
1855 ret
= target_fabric_configfs_register(fabric
);
1857 pr_err("target_fabric_configfs_register() failed for TCM_QLA2XXX\n");
1861 * Setup our local pointer to *fabric
1863 tcm_qla2xxx_fabric_configfs
= fabric
;
1864 pr_debug("TCM_QLA2XXX[0] - Set fabric -> tcm_qla2xxx_fabric_configfs\n");
1867 * Register the top level struct config_item_type for NPIV with TCM core
1869 npiv_fabric
= target_fabric_configfs_init(THIS_MODULE
, "qla2xxx_npiv");
1870 if (IS_ERR(npiv_fabric
)) {
1871 pr_err("target_fabric_configfs_init() failed\n");
1872 ret
= PTR_ERR(npiv_fabric
);
1876 * Setup fabric->tf_ops from our local tcm_qla2xxx_npiv_ops
1878 npiv_fabric
->tf_ops
= tcm_qla2xxx_npiv_ops
;
1880 * Setup default attribute lists for various npiv_fabric->tf_cit_tmpl
1882 TF_CIT_TMPL(npiv_fabric
)->tfc_wwn_cit
.ct_attrs
= tcm_qla2xxx_wwn_attrs
;
1883 TF_CIT_TMPL(npiv_fabric
)->tfc_tpg_base_cit
.ct_attrs
= NULL
;
1884 TF_CIT_TMPL(npiv_fabric
)->tfc_tpg_attrib_cit
.ct_attrs
= NULL
;
1885 TF_CIT_TMPL(npiv_fabric
)->tfc_tpg_param_cit
.ct_attrs
= NULL
;
1886 TF_CIT_TMPL(npiv_fabric
)->tfc_tpg_np_base_cit
.ct_attrs
= NULL
;
1887 TF_CIT_TMPL(npiv_fabric
)->tfc_tpg_nacl_base_cit
.ct_attrs
= NULL
;
1888 TF_CIT_TMPL(npiv_fabric
)->tfc_tpg_nacl_attrib_cit
.ct_attrs
= NULL
;
1889 TF_CIT_TMPL(npiv_fabric
)->tfc_tpg_nacl_auth_cit
.ct_attrs
= NULL
;
1890 TF_CIT_TMPL(npiv_fabric
)->tfc_tpg_nacl_param_cit
.ct_attrs
= NULL
;
1892 * Register the npiv_fabric for use within TCM
1894 ret
= target_fabric_configfs_register(npiv_fabric
);
1896 pr_err("target_fabric_configfs_register() failed for TCM_QLA2XXX\n");
1900 * Setup our local pointer to *npiv_fabric
1902 tcm_qla2xxx_npiv_fabric_configfs
= npiv_fabric
;
1903 pr_debug("TCM_QLA2XXX[0] - Set fabric -> tcm_qla2xxx_npiv_fabric_configfs\n");
1905 tcm_qla2xxx_free_wq
= alloc_workqueue("tcm_qla2xxx_free",
1907 if (!tcm_qla2xxx_free_wq
) {
1909 goto out_fabric_npiv
;
1912 tcm_qla2xxx_cmd_wq
= alloc_workqueue("tcm_qla2xxx_cmd", 0, 0);
1913 if (!tcm_qla2xxx_cmd_wq
) {
1921 destroy_workqueue(tcm_qla2xxx_free_wq
);
1923 target_fabric_configfs_deregister(tcm_qla2xxx_npiv_fabric_configfs
);
1925 target_fabric_configfs_deregister(tcm_qla2xxx_fabric_configfs
);
1929 static void tcm_qla2xxx_deregister_configfs(void)
1931 destroy_workqueue(tcm_qla2xxx_cmd_wq
);
1932 destroy_workqueue(tcm_qla2xxx_free_wq
);
1934 target_fabric_configfs_deregister(tcm_qla2xxx_fabric_configfs
);
1935 tcm_qla2xxx_fabric_configfs
= NULL
;
1936 pr_debug("TCM_QLA2XXX[0] - Cleared tcm_qla2xxx_fabric_configfs\n");
1938 target_fabric_configfs_deregister(tcm_qla2xxx_npiv_fabric_configfs
);
1939 tcm_qla2xxx_npiv_fabric_configfs
= NULL
;
1940 pr_debug("TCM_QLA2XXX[0] - Cleared tcm_qla2xxx_npiv_fabric_configfs\n");
1943 static int __init
tcm_qla2xxx_init(void)
1947 ret
= tcm_qla2xxx_register_configfs();
1954 static void __exit
tcm_qla2xxx_exit(void)
1956 tcm_qla2xxx_deregister_configfs();
1959 MODULE_DESCRIPTION("TCM QLA2XXX series NPIV enabled fabric driver");
1960 MODULE_LICENSE("GPL");
1961 module_init(tcm_qla2xxx_init
);
1962 module_exit(tcm_qla2xxx_exit
);