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
;
476 * qla_target.c:qlt_rdy_to_xfer() will call pci_map_sg() to setup
477 * the SGL mappings into PCIe memory for incoming FCP WRITE data.
479 return qlt_rdy_to_xfer(cmd
);
482 static int tcm_qla2xxx_write_pending_status(struct se_cmd
*se_cmd
)
486 * Check for WRITE_PENDING status to determine if we need to wait for
487 * CTIO aborts to be posted via hardware in tcm_qla2xxx_handle_data().
489 spin_lock_irqsave(&se_cmd
->t_state_lock
, flags
);
490 if (se_cmd
->t_state
== TRANSPORT_WRITE_PENDING
||
491 se_cmd
->t_state
== TRANSPORT_COMPLETE_QF_WP
) {
492 spin_unlock_irqrestore(&se_cmd
->t_state_lock
, flags
);
493 wait_for_completion_timeout(&se_cmd
->t_transport_stop_comp
,
497 spin_unlock_irqrestore(&se_cmd
->t_state_lock
, flags
);
502 static void tcm_qla2xxx_set_default_node_attrs(struct se_node_acl
*nacl
)
507 static u32
tcm_qla2xxx_get_task_tag(struct se_cmd
*se_cmd
)
509 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
510 struct qla_tgt_cmd
, se_cmd
);
515 static int tcm_qla2xxx_get_cmd_state(struct se_cmd
*se_cmd
)
521 * Called from process context in qla_target.c:qlt_do_work() code
523 static int tcm_qla2xxx_handle_cmd(scsi_qla_host_t
*vha
, struct qla_tgt_cmd
*cmd
,
524 unsigned char *cdb
, uint32_t data_length
, int fcp_task_attr
,
525 int data_dir
, int bidi
)
527 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
528 struct se_session
*se_sess
;
529 struct qla_tgt_sess
*sess
;
530 int flags
= TARGET_SCF_ACK_KREF
;
533 flags
|= TARGET_SCF_BIDI_OP
;
537 pr_err("Unable to locate struct qla_tgt_sess from qla_tgt_cmd\n");
541 se_sess
= sess
->se_sess
;
543 pr_err("Unable to locate active struct se_session\n");
547 return target_submit_cmd(se_cmd
, se_sess
, cdb
, &cmd
->sense_buffer
[0],
548 cmd
->unpacked_lun
, data_length
, fcp_task_attr
,
552 static void tcm_qla2xxx_handle_data_work(struct work_struct
*work
)
554 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
557 * Ensure that the complete FCP WRITE payload has been received.
558 * Otherwise return an exception via CHECK_CONDITION status.
560 if (!cmd
->write_data_transferred
) {
562 * Check if se_cmd has already been aborted via LUN_RESET, and
563 * waiting upon completion in tcm_qla2xxx_write_pending_status()
565 if (cmd
->se_cmd
.transport_state
& CMD_T_ABORTED
) {
566 complete(&cmd
->se_cmd
.t_transport_stop_comp
);
570 transport_generic_request_failure(&cmd
->se_cmd
,
571 TCM_CHECK_CONDITION_ABORT_CMD
);
575 return target_execute_cmd(&cmd
->se_cmd
);
579 * Called from qla_target.c:qlt_do_ctio_completion()
581 static void tcm_qla2xxx_handle_data(struct qla_tgt_cmd
*cmd
)
583 INIT_WORK(&cmd
->work
, tcm_qla2xxx_handle_data_work
);
584 queue_work(tcm_qla2xxx_free_wq
, &cmd
->work
);
588 * Called from qla_target.c:qlt_issue_task_mgmt()
590 static int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd
*mcmd
, uint32_t lun
,
591 uint8_t tmr_func
, uint32_t tag
)
593 struct qla_tgt_sess
*sess
= mcmd
->sess
;
594 struct se_cmd
*se_cmd
= &mcmd
->se_cmd
;
596 return target_submit_tmr(se_cmd
, sess
->se_sess
, NULL
, lun
, mcmd
,
597 tmr_func
, GFP_ATOMIC
, tag
, TARGET_SCF_ACK_KREF
);
600 static int tcm_qla2xxx_queue_data_in(struct se_cmd
*se_cmd
)
602 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
603 struct qla_tgt_cmd
, se_cmd
);
605 cmd
->bufflen
= se_cmd
->data_length
;
606 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
607 cmd
->aborted
= (se_cmd
->transport_state
& CMD_T_ABORTED
);
609 cmd
->sg_cnt
= se_cmd
->t_data_nents
;
610 cmd
->sg
= se_cmd
->t_data_sg
;
614 * Now queue completed DATA_IN the qla2xxx LLD and response ring
616 return qlt_xmit_response(cmd
, QLA_TGT_XMIT_DATA
|QLA_TGT_XMIT_STATUS
,
617 se_cmd
->scsi_status
);
620 static int tcm_qla2xxx_queue_status(struct se_cmd
*se_cmd
)
622 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
623 struct qla_tgt_cmd
, se_cmd
);
624 int xmit_type
= QLA_TGT_XMIT_STATUS
;
626 cmd
->bufflen
= se_cmd
->data_length
;
630 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
631 cmd
->aborted
= (se_cmd
->transport_state
& CMD_T_ABORTED
);
633 if (se_cmd
->data_direction
== DMA_FROM_DEVICE
) {
635 * For FCP_READ with CHECK_CONDITION status, clear cmd->bufflen
636 * for qla_tgt_xmit_response LLD code
638 if (se_cmd
->se_cmd_flags
& SCF_OVERFLOW_BIT
) {
639 se_cmd
->se_cmd_flags
&= ~SCF_OVERFLOW_BIT
;
640 se_cmd
->residual_count
= 0;
642 se_cmd
->se_cmd_flags
|= SCF_UNDERFLOW_BIT
;
643 se_cmd
->residual_count
+= se_cmd
->data_length
;
648 * Now queue status response to qla2xxx LLD code and response ring
650 return qlt_xmit_response(cmd
, xmit_type
, se_cmd
->scsi_status
);
653 static void tcm_qla2xxx_queue_tm_rsp(struct se_cmd
*se_cmd
)
655 struct se_tmr_req
*se_tmr
= se_cmd
->se_tmr_req
;
656 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(se_cmd
,
657 struct qla_tgt_mgmt_cmd
, se_cmd
);
659 pr_debug("queue_tm_rsp: mcmd: %p func: 0x%02x response: 0x%02x\n",
660 mcmd
, se_tmr
->function
, se_tmr
->response
);
662 * Do translation between TCM TM response codes and
663 * QLA2xxx FC TM response codes.
665 switch (se_tmr
->response
) {
666 case TMR_FUNCTION_COMPLETE
:
667 mcmd
->fc_tm_rsp
= FC_TM_SUCCESS
;
669 case TMR_TASK_DOES_NOT_EXIST
:
670 mcmd
->fc_tm_rsp
= FC_TM_BAD_CMD
;
672 case TMR_FUNCTION_REJECTED
:
673 mcmd
->fc_tm_rsp
= FC_TM_REJECT
;
675 case TMR_LUN_DOES_NOT_EXIST
:
677 mcmd
->fc_tm_rsp
= FC_TM_FAILED
;
681 * Queue the TM response to QLA2xxx LLD to build a
682 * CTIO response packet.
684 qlt_xmit_tm_rsp(mcmd
);
687 static void tcm_qla2xxx_aborted_task(struct se_cmd
*se_cmd
)
689 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
690 struct qla_tgt_cmd
, se_cmd
);
691 struct scsi_qla_host
*vha
= cmd
->vha
;
692 struct qla_hw_data
*ha
= vha
->hw
;
697 pci_unmap_sg(ha
->pdev
, cmd
->sg
, cmd
->sg_cnt
, cmd
->dma_data_direction
);
701 /* Local pointer to allocated TCM configfs fabric module */
702 struct target_fabric_configfs
*tcm_qla2xxx_fabric_configfs
;
703 struct target_fabric_configfs
*tcm_qla2xxx_npiv_fabric_configfs
;
705 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport
*,
706 struct tcm_qla2xxx_nacl
*, struct qla_tgt_sess
*);
708 * Expected to be called with struct qla_hw_data->hardware_lock held
710 static void tcm_qla2xxx_clear_nacl_from_fcport_map(struct qla_tgt_sess
*sess
)
712 struct se_node_acl
*se_nacl
= sess
->se_sess
->se_node_acl
;
713 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
714 struct se_wwn
*se_wwn
= se_tpg
->se_tpg_wwn
;
715 struct tcm_qla2xxx_lport
*lport
= container_of(se_wwn
,
716 struct tcm_qla2xxx_lport
, lport_wwn
);
717 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
718 struct tcm_qla2xxx_nacl
, se_node_acl
);
721 pr_debug("fc_rport domain: port_id 0x%06x\n", nacl
->nport_id
);
723 node
= btree_remove32(&lport
->lport_fcport_map
, nacl
->nport_id
);
724 WARN_ON(node
&& (node
!= se_nacl
));
726 pr_debug("Removed from fcport_map: %p for WWNN: 0x%016LX, port_id: 0x%06x\n",
727 se_nacl
, nacl
->nport_wwnn
, nacl
->nport_id
);
729 * Now clear the se_nacl and session pointers from our HW lport lookup
730 * table mapping for this initiator's fabric S_ID and LOOP_ID entries.
732 * This is done ahead of callbacks into tcm_qla2xxx_free_session() ->
733 * target_wait_for_sess_cmds() before the session waits for outstanding
734 * I/O to complete, to avoid a race between session shutdown execution
735 * and incoming ATIOs or TMRs picking up a stale se_node_act reference.
737 tcm_qla2xxx_clear_sess_lookup(lport
, nacl
, sess
);
740 static void tcm_qla2xxx_release_session(struct kref
*kref
)
742 struct se_session
*se_sess
= container_of(kref
,
743 struct se_session
, sess_kref
);
745 qlt_unreg_sess(se_sess
->fabric_sess_ptr
);
748 static void tcm_qla2xxx_put_session(struct se_session
*se_sess
)
750 struct qla_tgt_sess
*sess
= se_sess
->fabric_sess_ptr
;
751 struct qla_hw_data
*ha
= sess
->vha
->hw
;
754 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
755 kref_put(&se_sess
->sess_kref
, tcm_qla2xxx_release_session
);
756 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
759 static void tcm_qla2xxx_put_sess(struct qla_tgt_sess
*sess
)
764 assert_spin_locked(&sess
->vha
->hw
->hardware_lock
);
765 kref_put(&sess
->se_sess
->sess_kref
, tcm_qla2xxx_release_session
);
768 static void tcm_qla2xxx_shutdown_sess(struct qla_tgt_sess
*sess
)
770 assert_spin_locked(&sess
->vha
->hw
->hardware_lock
);
771 target_sess_cmd_list_set_waiting(sess
->se_sess
);
774 static struct se_node_acl
*tcm_qla2xxx_make_nodeacl(
775 struct se_portal_group
*se_tpg
,
776 struct config_group
*group
,
779 struct se_node_acl
*se_nacl
, *se_nacl_new
;
780 struct tcm_qla2xxx_nacl
*nacl
;
782 u32 qla2xxx_nexus_depth
;
784 if (tcm_qla2xxx_parse_wwn(name
, &wwnn
, 1) < 0)
785 return ERR_PTR(-EINVAL
);
787 se_nacl_new
= tcm_qla2xxx_alloc_fabric_acl(se_tpg
);
789 return ERR_PTR(-ENOMEM
);
790 /* #warning FIXME: Hardcoded qla2xxx_nexus depth in tcm_qla2xxx_make_nodeacl */
791 qla2xxx_nexus_depth
= 1;
794 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
795 * when converting a NodeACL from demo mode -> explict
797 se_nacl
= core_tpg_add_initiator_node_acl(se_tpg
, se_nacl_new
,
798 name
, qla2xxx_nexus_depth
);
799 if (IS_ERR(se_nacl
)) {
800 tcm_qla2xxx_release_fabric_acl(se_tpg
, se_nacl_new
);
804 * Locate our struct tcm_qla2xxx_nacl and set the FC Nport WWPN
806 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
807 nacl
->nport_wwnn
= wwnn
;
808 tcm_qla2xxx_format_wwn(&nacl
->nport_name
[0], TCM_QLA2XXX_NAMELEN
, wwnn
);
813 static void tcm_qla2xxx_drop_nodeacl(struct se_node_acl
*se_acl
)
815 struct se_portal_group
*se_tpg
= se_acl
->se_tpg
;
816 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_acl
,
817 struct tcm_qla2xxx_nacl
, se_node_acl
);
819 core_tpg_del_initiator_node_acl(se_tpg
, se_acl
, 1);
823 /* Start items for tcm_qla2xxx_tpg_attrib_cit */
825 #define DEF_QLA_TPG_ATTRIB(name) \
827 static ssize_t tcm_qla2xxx_tpg_attrib_show_##name( \
828 struct se_portal_group *se_tpg, \
831 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
832 struct tcm_qla2xxx_tpg, se_tpg); \
834 return sprintf(page, "%u\n", tpg->tpg_attrib.name); \
837 static ssize_t tcm_qla2xxx_tpg_attrib_store_##name( \
838 struct se_portal_group *se_tpg, \
842 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
843 struct tcm_qla2xxx_tpg, se_tpg); \
847 ret = kstrtoul(page, 0, &val); \
849 pr_err("kstrtoul() failed with" \
850 " ret: %d\n", ret); \
853 ret = tcm_qla2xxx_set_attrib_##name(tpg, val); \
855 return (!ret) ? count : -EINVAL; \
858 #define DEF_QLA_TPG_ATTR_BOOL(_name) \
860 static int tcm_qla2xxx_set_attrib_##_name( \
861 struct tcm_qla2xxx_tpg *tpg, \
864 struct tcm_qla2xxx_tpg_attrib *a = &tpg->tpg_attrib; \
866 if ((val != 0) && (val != 1)) { \
867 pr_err("Illegal boolean value %lu\n", val); \
875 #define QLA_TPG_ATTR(_name, _mode) \
876 TF_TPG_ATTRIB_ATTR(tcm_qla2xxx, _name, _mode);
879 * Define tcm_qla2xxx_tpg_attrib_s_generate_node_acls
881 DEF_QLA_TPG_ATTR_BOOL(generate_node_acls
);
882 DEF_QLA_TPG_ATTRIB(generate_node_acls
);
883 QLA_TPG_ATTR(generate_node_acls
, S_IRUGO
| S_IWUSR
);
886 Define tcm_qla2xxx_attrib_s_cache_dynamic_acls
888 DEF_QLA_TPG_ATTR_BOOL(cache_dynamic_acls
);
889 DEF_QLA_TPG_ATTRIB(cache_dynamic_acls
);
890 QLA_TPG_ATTR(cache_dynamic_acls
, S_IRUGO
| S_IWUSR
);
893 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_write_protect
895 DEF_QLA_TPG_ATTR_BOOL(demo_mode_write_protect
);
896 DEF_QLA_TPG_ATTRIB(demo_mode_write_protect
);
897 QLA_TPG_ATTR(demo_mode_write_protect
, S_IRUGO
| S_IWUSR
);
900 * Define tcm_qla2xxx_tpg_attrib_s_prod_mode_write_protect
902 DEF_QLA_TPG_ATTR_BOOL(prod_mode_write_protect
);
903 DEF_QLA_TPG_ATTRIB(prod_mode_write_protect
);
904 QLA_TPG_ATTR(prod_mode_write_protect
, S_IRUGO
| S_IWUSR
);
907 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_login_only
909 DEF_QLA_TPG_ATTR_BOOL(demo_mode_login_only
);
910 DEF_QLA_TPG_ATTRIB(demo_mode_login_only
);
911 QLA_TPG_ATTR(demo_mode_login_only
, S_IRUGO
| S_IWUSR
);
913 static struct configfs_attribute
*tcm_qla2xxx_tpg_attrib_attrs
[] = {
914 &tcm_qla2xxx_tpg_attrib_generate_node_acls
.attr
,
915 &tcm_qla2xxx_tpg_attrib_cache_dynamic_acls
.attr
,
916 &tcm_qla2xxx_tpg_attrib_demo_mode_write_protect
.attr
,
917 &tcm_qla2xxx_tpg_attrib_prod_mode_write_protect
.attr
,
918 &tcm_qla2xxx_tpg_attrib_demo_mode_login_only
.attr
,
922 /* End items for tcm_qla2xxx_tpg_attrib_cit */
924 static ssize_t
tcm_qla2xxx_tpg_show_enable(
925 struct se_portal_group
*se_tpg
,
928 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
929 struct tcm_qla2xxx_tpg
, se_tpg
);
931 return snprintf(page
, PAGE_SIZE
, "%d\n",
932 atomic_read(&tpg
->lport_tpg_enabled
));
935 static void tcm_qla2xxx_depend_tpg(struct work_struct
*work
)
937 struct tcm_qla2xxx_tpg
*base_tpg
= container_of(work
,
938 struct tcm_qla2xxx_tpg
, tpg_base_work
);
939 struct se_portal_group
*se_tpg
= &base_tpg
->se_tpg
;
940 struct scsi_qla_host
*base_vha
= base_tpg
->lport
->qla_vha
;
942 if (!configfs_depend_item(se_tpg
->se_tpg_tfo
->tf_subsys
,
943 &se_tpg
->tpg_group
.cg_item
)) {
944 atomic_set(&base_tpg
->lport_tpg_enabled
, 1);
945 qlt_enable_vha(base_vha
);
947 complete(&base_tpg
->tpg_base_comp
);
950 static void tcm_qla2xxx_undepend_tpg(struct work_struct
*work
)
952 struct tcm_qla2xxx_tpg
*base_tpg
= container_of(work
,
953 struct tcm_qla2xxx_tpg
, tpg_base_work
);
954 struct se_portal_group
*se_tpg
= &base_tpg
->se_tpg
;
955 struct scsi_qla_host
*base_vha
= base_tpg
->lport
->qla_vha
;
957 if (!qlt_stop_phase1(base_vha
->vha_tgt
.qla_tgt
)) {
958 atomic_set(&base_tpg
->lport_tpg_enabled
, 0);
959 configfs_undepend_item(se_tpg
->se_tpg_tfo
->tf_subsys
,
960 &se_tpg
->tpg_group
.cg_item
);
962 complete(&base_tpg
->tpg_base_comp
);
965 static ssize_t
tcm_qla2xxx_tpg_store_enable(
966 struct se_portal_group
*se_tpg
,
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
);
985 if (atomic_read(&tpg
->lport_tpg_enabled
))
988 INIT_WORK(&tpg
->tpg_base_work
, tcm_qla2xxx_depend_tpg
);
990 if (!atomic_read(&tpg
->lport_tpg_enabled
))
993 INIT_WORK(&tpg
->tpg_base_work
, tcm_qla2xxx_undepend_tpg
);
995 init_completion(&tpg
->tpg_base_comp
);
996 schedule_work(&tpg
->tpg_base_work
);
997 wait_for_completion(&tpg
->tpg_base_comp
);
1000 if (!atomic_read(&tpg
->lport_tpg_enabled
))
1003 if (atomic_read(&tpg
->lport_tpg_enabled
))
1009 TF_TPG_BASE_ATTR(tcm_qla2xxx
, enable
, S_IRUGO
| S_IWUSR
);
1011 static struct configfs_attribute
*tcm_qla2xxx_tpg_attrs
[] = {
1012 &tcm_qla2xxx_tpg_enable
.attr
,
1016 static struct se_portal_group
*tcm_qla2xxx_make_tpg(
1018 struct config_group
*group
,
1021 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1022 struct tcm_qla2xxx_lport
, lport_wwn
);
1023 struct tcm_qla2xxx_tpg
*tpg
;
1027 if (strstr(name
, "tpgt_") != name
)
1028 return ERR_PTR(-EINVAL
);
1029 if (kstrtoul(name
+ 5, 10, &tpgt
) || tpgt
> USHRT_MAX
)
1030 return ERR_PTR(-EINVAL
);
1033 pr_err("In non NPIV mode, a single TPG=1 is used for HW port mappings\n");
1034 return ERR_PTR(-ENOSYS
);
1037 tpg
= kzalloc(sizeof(struct tcm_qla2xxx_tpg
), GFP_KERNEL
);
1039 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1040 return ERR_PTR(-ENOMEM
);
1043 tpg
->lport_tpgt
= tpgt
;
1045 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1048 tpg
->tpg_attrib
.generate_node_acls
= 1;
1049 tpg
->tpg_attrib
.demo_mode_write_protect
= 1;
1050 tpg
->tpg_attrib
.cache_dynamic_acls
= 1;
1051 tpg
->tpg_attrib
.demo_mode_login_only
= 1;
1053 ret
= core_tpg_register(&tcm_qla2xxx_fabric_configfs
->tf_ops
, wwn
,
1054 &tpg
->se_tpg
, tpg
, TRANSPORT_TPG_TYPE_NORMAL
);
1062 return &tpg
->se_tpg
;
1065 static void tcm_qla2xxx_drop_tpg(struct se_portal_group
*se_tpg
)
1067 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1068 struct tcm_qla2xxx_tpg
, se_tpg
);
1069 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
1070 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1072 * Call into qla2x_target.c LLD logic to shutdown the active
1073 * FC Nexuses and disable target mode operation for this qla_hw_data
1075 if (vha
->vha_tgt
.qla_tgt
&& !vha
->vha_tgt
.qla_tgt
->tgt_stop
)
1076 qlt_stop_phase1(vha
->vha_tgt
.qla_tgt
);
1078 core_tpg_deregister(se_tpg
);
1080 * Clear local TPG=1 pointer for non NPIV mode.
1082 lport
->tpg_1
= NULL
;
1086 static ssize_t
tcm_qla2xxx_npiv_tpg_show_enable(
1087 struct se_portal_group
*se_tpg
,
1090 return tcm_qla2xxx_tpg_show_enable(se_tpg
, page
);
1093 static ssize_t
tcm_qla2xxx_npiv_tpg_store_enable(
1094 struct se_portal_group
*se_tpg
,
1098 struct se_wwn
*se_wwn
= se_tpg
->se_tpg_wwn
;
1099 struct tcm_qla2xxx_lport
*lport
= container_of(se_wwn
,
1100 struct tcm_qla2xxx_lport
, lport_wwn
);
1101 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1102 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1103 struct tcm_qla2xxx_tpg
, se_tpg
);
1107 rc
= kstrtoul(page
, 0, &op
);
1109 pr_err("kstrtoul() returned %d\n", rc
);
1112 if ((op
!= 1) && (op
!= 0)) {
1113 pr_err("Illegal value for tpg_enable: %lu\n", op
);
1117 if (atomic_read(&tpg
->lport_tpg_enabled
))
1120 atomic_set(&tpg
->lport_tpg_enabled
, 1);
1121 qlt_enable_vha(vha
);
1123 if (!atomic_read(&tpg
->lport_tpg_enabled
))
1126 atomic_set(&tpg
->lport_tpg_enabled
, 0);
1127 qlt_stop_phase1(vha
->vha_tgt
.qla_tgt
);
1133 TF_TPG_BASE_ATTR(tcm_qla2xxx_npiv
, enable
, S_IRUGO
| S_IWUSR
);
1135 static struct configfs_attribute
*tcm_qla2xxx_npiv_tpg_attrs
[] = {
1136 &tcm_qla2xxx_npiv_tpg_enable
.attr
,
1140 static struct se_portal_group
*tcm_qla2xxx_npiv_make_tpg(
1142 struct config_group
*group
,
1145 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1146 struct tcm_qla2xxx_lport
, lport_wwn
);
1147 struct tcm_qla2xxx_tpg
*tpg
;
1151 if (strstr(name
, "tpgt_") != name
)
1152 return ERR_PTR(-EINVAL
);
1153 if (kstrtoul(name
+ 5, 10, &tpgt
) || tpgt
> USHRT_MAX
)
1154 return ERR_PTR(-EINVAL
);
1156 tpg
= kzalloc(sizeof(struct tcm_qla2xxx_tpg
), GFP_KERNEL
);
1158 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1159 return ERR_PTR(-ENOMEM
);
1162 tpg
->lport_tpgt
= tpgt
;
1165 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1168 tpg
->tpg_attrib
.generate_node_acls
= 1;
1169 tpg
->tpg_attrib
.demo_mode_write_protect
= 1;
1170 tpg
->tpg_attrib
.cache_dynamic_acls
= 1;
1171 tpg
->tpg_attrib
.demo_mode_login_only
= 1;
1173 ret
= core_tpg_register(&tcm_qla2xxx_npiv_fabric_configfs
->tf_ops
, wwn
,
1174 &tpg
->se_tpg
, tpg
, TRANSPORT_TPG_TYPE_NORMAL
);
1180 return &tpg
->se_tpg
;
1184 * Expected to be called with struct qla_hw_data->hardware_lock held
1186 static struct qla_tgt_sess
*tcm_qla2xxx_find_sess_by_s_id(
1187 scsi_qla_host_t
*vha
,
1188 const uint8_t *s_id
)
1190 struct tcm_qla2xxx_lport
*lport
;
1191 struct se_node_acl
*se_nacl
;
1192 struct tcm_qla2xxx_nacl
*nacl
;
1195 lport
= vha
->vha_tgt
.target_lport_ptr
;
1197 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1202 key
= (((unsigned long)s_id
[0] << 16) |
1203 ((unsigned long)s_id
[1] << 8) |
1204 (unsigned long)s_id
[2]);
1205 pr_debug("find_sess_by_s_id: 0x%06x\n", key
);
1207 se_nacl
= btree_lookup32(&lport
->lport_fcport_map
, key
);
1209 pr_debug("Unable to locate s_id: 0x%06x\n", key
);
1212 pr_debug("find_sess_by_s_id: located se_nacl: %p, initiatorname: %s\n",
1213 se_nacl
, se_nacl
->initiatorname
);
1215 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1216 if (!nacl
->qla_tgt_sess
) {
1217 pr_err("Unable to locate struct qla_tgt_sess\n");
1221 return nacl
->qla_tgt_sess
;
1225 * Expected to be called with struct qla_hw_data->hardware_lock held
1227 static void tcm_qla2xxx_set_sess_by_s_id(
1228 struct tcm_qla2xxx_lport
*lport
,
1229 struct se_node_acl
*new_se_nacl
,
1230 struct tcm_qla2xxx_nacl
*nacl
,
1231 struct se_session
*se_sess
,
1232 struct qla_tgt_sess
*qla_tgt_sess
,
1239 key
= (((unsigned long)s_id
[0] << 16) |
1240 ((unsigned long)s_id
[1] << 8) |
1241 (unsigned long)s_id
[2]);
1242 pr_debug("set_sess_by_s_id: %06x\n", key
);
1244 slot
= btree_lookup32(&lport
->lport_fcport_map
, key
);
1247 pr_debug("Setting up new fc_port entry to new_se_nacl\n");
1248 nacl
->nport_id
= key
;
1249 rc
= btree_insert32(&lport
->lport_fcport_map
, key
,
1250 new_se_nacl
, GFP_ATOMIC
);
1252 printk(KERN_ERR
"Unable to insert s_id into fcport_map: %06x\n",
1255 pr_debug("Wiping nonexisting fc_port entry\n");
1258 qla_tgt_sess
->se_sess
= se_sess
;
1259 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1263 if (nacl
->qla_tgt_sess
) {
1264 if (new_se_nacl
== NULL
) {
1265 pr_debug("Clearing existing nacl->qla_tgt_sess and fc_port entry\n");
1266 btree_remove32(&lport
->lport_fcport_map
, key
);
1267 nacl
->qla_tgt_sess
= NULL
;
1270 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_port entry\n");
1271 btree_update32(&lport
->lport_fcport_map
, key
, new_se_nacl
);
1272 qla_tgt_sess
->se_sess
= se_sess
;
1273 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1277 if (new_se_nacl
== NULL
) {
1278 pr_debug("Clearing existing fc_port entry\n");
1279 btree_remove32(&lport
->lport_fcport_map
, key
);
1283 pr_debug("Replacing existing fc_port entry w/o active nacl->qla_tgt_sess\n");
1284 btree_update32(&lport
->lport_fcport_map
, key
, new_se_nacl
);
1285 qla_tgt_sess
->se_sess
= se_sess
;
1286 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1288 pr_debug("Setup nacl->qla_tgt_sess %p by s_id for se_nacl: %p, initiatorname: %s\n",
1289 nacl
->qla_tgt_sess
, new_se_nacl
, new_se_nacl
->initiatorname
);
1293 * Expected to be called with struct qla_hw_data->hardware_lock held
1295 static struct qla_tgt_sess
*tcm_qla2xxx_find_sess_by_loop_id(
1296 scsi_qla_host_t
*vha
,
1297 const uint16_t loop_id
)
1299 struct tcm_qla2xxx_lport
*lport
;
1300 struct se_node_acl
*se_nacl
;
1301 struct tcm_qla2xxx_nacl
*nacl
;
1302 struct tcm_qla2xxx_fc_loopid
*fc_loopid
;
1304 lport
= vha
->vha_tgt
.target_lport_ptr
;
1306 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1311 pr_debug("find_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id
);
1313 fc_loopid
= lport
->lport_loopid_map
+ loop_id
;
1314 se_nacl
= fc_loopid
->se_nacl
;
1316 pr_debug("Unable to locate se_nacl by loop_id: 0x%04x\n",
1321 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1323 if (!nacl
->qla_tgt_sess
) {
1324 pr_err("Unable to locate struct qla_tgt_sess\n");
1328 return nacl
->qla_tgt_sess
;
1332 * Expected to be called with struct qla_hw_data->hardware_lock held
1334 static void tcm_qla2xxx_set_sess_by_loop_id(
1335 struct tcm_qla2xxx_lport
*lport
,
1336 struct se_node_acl
*new_se_nacl
,
1337 struct tcm_qla2xxx_nacl
*nacl
,
1338 struct se_session
*se_sess
,
1339 struct qla_tgt_sess
*qla_tgt_sess
,
1342 struct se_node_acl
*saved_nacl
;
1343 struct tcm_qla2xxx_fc_loopid
*fc_loopid
;
1345 pr_debug("set_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id
);
1347 fc_loopid
= &((struct tcm_qla2xxx_fc_loopid
*)
1348 lport
->lport_loopid_map
)[loop_id
];
1350 saved_nacl
= fc_loopid
->se_nacl
;
1352 pr_debug("Setting up new fc_loopid->se_nacl to new_se_nacl\n");
1353 fc_loopid
->se_nacl
= new_se_nacl
;
1354 if (qla_tgt_sess
->se_sess
!= se_sess
)
1355 qla_tgt_sess
->se_sess
= se_sess
;
1356 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1357 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1361 if (nacl
->qla_tgt_sess
) {
1362 if (new_se_nacl
== NULL
) {
1363 pr_debug("Clearing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1364 fc_loopid
->se_nacl
= NULL
;
1365 nacl
->qla_tgt_sess
= NULL
;
1369 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1370 fc_loopid
->se_nacl
= new_se_nacl
;
1371 if (qla_tgt_sess
->se_sess
!= se_sess
)
1372 qla_tgt_sess
->se_sess
= se_sess
;
1373 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1374 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1378 if (new_se_nacl
== NULL
) {
1379 pr_debug("Clearing fc_loopid->se_nacl\n");
1380 fc_loopid
->se_nacl
= NULL
;
1384 pr_debug("Replacing existing fc_loopid->se_nacl w/o active nacl->qla_tgt_sess\n");
1385 fc_loopid
->se_nacl
= new_se_nacl
;
1386 if (qla_tgt_sess
->se_sess
!= se_sess
)
1387 qla_tgt_sess
->se_sess
= se_sess
;
1388 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1389 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1391 pr_debug("Setup nacl->qla_tgt_sess %p by loop_id for se_nacl: %p, initiatorname: %s\n",
1392 nacl
->qla_tgt_sess
, new_se_nacl
, new_se_nacl
->initiatorname
);
1396 * Should always be called with qla_hw_data->hardware_lock held.
1398 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport
*lport
,
1399 struct tcm_qla2xxx_nacl
*nacl
, struct qla_tgt_sess
*sess
)
1401 struct se_session
*se_sess
= sess
->se_sess
;
1402 unsigned char be_sid
[3];
1404 be_sid
[0] = sess
->s_id
.b
.domain
;
1405 be_sid
[1] = sess
->s_id
.b
.area
;
1406 be_sid
[2] = sess
->s_id
.b
.al_pa
;
1408 tcm_qla2xxx_set_sess_by_s_id(lport
, NULL
, nacl
, se_sess
,
1410 tcm_qla2xxx_set_sess_by_loop_id(lport
, NULL
, nacl
, se_sess
,
1411 sess
, sess
->loop_id
);
1414 static void tcm_qla2xxx_free_session(struct qla_tgt_sess
*sess
)
1416 struct qla_tgt
*tgt
= sess
->tgt
;
1417 struct qla_hw_data
*ha
= tgt
->ha
;
1418 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
1419 struct se_session
*se_sess
;
1420 struct se_node_acl
*se_nacl
;
1421 struct tcm_qla2xxx_lport
*lport
;
1422 struct tcm_qla2xxx_nacl
*nacl
;
1424 BUG_ON(in_interrupt());
1426 se_sess
= sess
->se_sess
;
1428 pr_err("struct qla_tgt_sess->se_sess is NULL\n");
1432 se_nacl
= se_sess
->se_node_acl
;
1433 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1435 lport
= vha
->vha_tgt
.target_lport_ptr
;
1437 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1441 target_wait_for_sess_cmds(se_sess
);
1443 transport_deregister_session_configfs(sess
->se_sess
);
1444 transport_deregister_session(sess
->se_sess
);
1448 * Called via qlt_create_sess():ha->qla2x_tmpl->check_initiator_node_acl()
1449 * to locate struct se_node_acl
1451 static int tcm_qla2xxx_check_initiator_node_acl(
1452 scsi_qla_host_t
*vha
,
1453 unsigned char *fc_wwpn
,
1458 struct qla_hw_data
*ha
= vha
->hw
;
1459 struct tcm_qla2xxx_lport
*lport
;
1460 struct tcm_qla2xxx_tpg
*tpg
;
1461 struct tcm_qla2xxx_nacl
*nacl
;
1462 struct se_portal_group
*se_tpg
;
1463 struct se_node_acl
*se_nacl
;
1464 struct se_session
*se_sess
;
1465 struct qla_tgt_sess
*sess
= qla_tgt_sess
;
1466 unsigned char port_name
[36];
1467 unsigned long flags
;
1469 lport
= vha
->vha_tgt
.target_lport_ptr
;
1471 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1476 * Locate the TPG=1 reference..
1480 pr_err("Unable to lcoate struct tcm_qla2xxx_lport->tpg_1\n");
1483 se_tpg
= &tpg
->se_tpg
;
1485 se_sess
= transport_init_session(TARGET_PROT_NORMAL
);
1486 if (IS_ERR(se_sess
)) {
1487 pr_err("Unable to initialize struct se_session\n");
1488 return PTR_ERR(se_sess
);
1491 * Format the FCP Initiator port_name into colon seperated values to
1492 * match the format by tcm_qla2xxx explict ConfigFS NodeACLs.
1494 memset(&port_name
, 0, 36);
1495 snprintf(port_name
, 36, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1496 fc_wwpn
[0], fc_wwpn
[1], fc_wwpn
[2], fc_wwpn
[3], fc_wwpn
[4],
1497 fc_wwpn
[5], fc_wwpn
[6], fc_wwpn
[7]);
1499 * Locate our struct se_node_acl either from an explict NodeACL created
1500 * via ConfigFS, or via running in TPG demo mode.
1502 se_sess
->se_node_acl
= core_tpg_check_initiator_node_acl(se_tpg
,
1504 if (!se_sess
->se_node_acl
) {
1505 transport_free_session(se_sess
);
1508 se_nacl
= se_sess
->se_node_acl
;
1509 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1511 * And now setup the new se_nacl and session pointers into our HW lport
1512 * mappings for fabric S_ID and LOOP_ID.
1514 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1515 tcm_qla2xxx_set_sess_by_s_id(lport
, se_nacl
, nacl
, se_sess
,
1516 qla_tgt_sess
, s_id
);
1517 tcm_qla2xxx_set_sess_by_loop_id(lport
, se_nacl
, nacl
, se_sess
,
1518 qla_tgt_sess
, loop_id
);
1519 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1521 * Finally register the new FC Nexus with TCM
1523 __transport_register_session(se_nacl
->se_tpg
, se_nacl
, se_sess
, sess
);
1528 static void tcm_qla2xxx_update_sess(struct qla_tgt_sess
*sess
, port_id_t s_id
,
1529 uint16_t loop_id
, bool conf_compl_supported
)
1531 struct qla_tgt
*tgt
= sess
->tgt
;
1532 struct qla_hw_data
*ha
= tgt
->ha
;
1533 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
1534 struct tcm_qla2xxx_lport
*lport
= vha
->vha_tgt
.target_lport_ptr
;
1535 struct se_node_acl
*se_nacl
= sess
->se_sess
->se_node_acl
;
1536 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
1537 struct tcm_qla2xxx_nacl
, se_node_acl
);
1541 if (sess
->loop_id
!= loop_id
|| sess
->s_id
.b24
!= s_id
.b24
)
1542 pr_info("Updating session %p from port %8phC loop_id %d -> %d s_id %x:%x:%x -> %x:%x:%x\n",
1543 sess
, sess
->port_name
,
1544 sess
->loop_id
, loop_id
, sess
->s_id
.b
.domain
,
1545 sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
, s_id
.b
.domain
,
1546 s_id
.b
.area
, s_id
.b
.al_pa
);
1548 if (sess
->loop_id
!= loop_id
) {
1550 * Because we can shuffle loop IDs around and we
1551 * update different sessions non-atomically, we might
1552 * have overwritten this session's old loop ID
1553 * already, and we might end up overwriting some other
1554 * session that will be updated later. So we have to
1555 * be extra careful and we can't warn about those things...
1557 if (lport
->lport_loopid_map
[sess
->loop_id
].se_nacl
== se_nacl
)
1558 lport
->lport_loopid_map
[sess
->loop_id
].se_nacl
= NULL
;
1560 lport
->lport_loopid_map
[loop_id
].se_nacl
= se_nacl
;
1562 sess
->loop_id
= loop_id
;
1565 if (sess
->s_id
.b24
!= s_id
.b24
) {
1566 key
= (((u32
) sess
->s_id
.b
.domain
<< 16) |
1567 ((u32
) sess
->s_id
.b
.area
<< 8) |
1568 ((u32
) sess
->s_id
.b
.al_pa
));
1570 if (btree_lookup32(&lport
->lport_fcport_map
, key
))
1571 WARN(btree_remove32(&lport
->lport_fcport_map
, key
) != se_nacl
,
1572 "Found wrong se_nacl when updating s_id %x:%x:%x\n",
1573 sess
->s_id
.b
.domain
, sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
);
1575 WARN(1, "No lport_fcport_map entry for s_id %x:%x:%x\n",
1576 sess
->s_id
.b
.domain
, sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
);
1578 key
= (((u32
) s_id
.b
.domain
<< 16) |
1579 ((u32
) s_id
.b
.area
<< 8) |
1580 ((u32
) s_id
.b
.al_pa
));
1582 if (btree_lookup32(&lport
->lport_fcport_map
, key
)) {
1583 WARN(1, "Already have lport_fcport_map entry for s_id %x:%x:%x\n",
1584 s_id
.b
.domain
, s_id
.b
.area
, s_id
.b
.al_pa
);
1585 btree_update32(&lport
->lport_fcport_map
, key
, se_nacl
);
1587 btree_insert32(&lport
->lport_fcport_map
, key
, se_nacl
, GFP_ATOMIC
);
1591 nacl
->nport_id
= key
;
1594 sess
->conf_compl_supported
= conf_compl_supported
;
1598 * Calls into tcm_qla2xxx used by qla2xxx LLD I/O path.
1600 static struct qla_tgt_func_tmpl tcm_qla2xxx_template
= {
1601 .handle_cmd
= tcm_qla2xxx_handle_cmd
,
1602 .handle_data
= tcm_qla2xxx_handle_data
,
1603 .handle_tmr
= tcm_qla2xxx_handle_tmr
,
1604 .free_cmd
= tcm_qla2xxx_free_cmd
,
1605 .free_mcmd
= tcm_qla2xxx_free_mcmd
,
1606 .free_session
= tcm_qla2xxx_free_session
,
1607 .update_sess
= tcm_qla2xxx_update_sess
,
1608 .check_initiator_node_acl
= tcm_qla2xxx_check_initiator_node_acl
,
1609 .find_sess_by_s_id
= tcm_qla2xxx_find_sess_by_s_id
,
1610 .find_sess_by_loop_id
= tcm_qla2xxx_find_sess_by_loop_id
,
1611 .clear_nacl_from_fcport_map
= tcm_qla2xxx_clear_nacl_from_fcport_map
,
1612 .put_sess
= tcm_qla2xxx_put_sess
,
1613 .shutdown_sess
= tcm_qla2xxx_shutdown_sess
,
1616 static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport
*lport
)
1620 rc
= btree_init32(&lport
->lport_fcport_map
);
1622 pr_err("Unable to initialize lport->lport_fcport_map btree\n");
1626 lport
->lport_loopid_map
= vmalloc(sizeof(struct tcm_qla2xxx_fc_loopid
) *
1628 if (!lport
->lport_loopid_map
) {
1629 pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n",
1630 sizeof(struct tcm_qla2xxx_fc_loopid
) * 65536);
1631 btree_destroy32(&lport
->lport_fcport_map
);
1634 memset(lport
->lport_loopid_map
, 0, sizeof(struct tcm_qla2xxx_fc_loopid
)
1636 pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n",
1637 sizeof(struct tcm_qla2xxx_fc_loopid
) * 65536);
1641 static int tcm_qla2xxx_lport_register_cb(struct scsi_qla_host
*vha
,
1642 void *target_lport_ptr
,
1643 u64 npiv_wwpn
, u64 npiv_wwnn
)
1645 struct qla_hw_data
*ha
= vha
->hw
;
1646 struct tcm_qla2xxx_lport
*lport
=
1647 (struct tcm_qla2xxx_lport
*)target_lport_ptr
;
1649 * Setup tgt_ops, local pointer to vha and target_lport_ptr
1651 ha
->tgt
.tgt_ops
= &tcm_qla2xxx_template
;
1652 vha
->vha_tgt
.target_lport_ptr
= target_lport_ptr
;
1653 lport
->qla_vha
= vha
;
1658 static struct se_wwn
*tcm_qla2xxx_make_lport(
1659 struct target_fabric_configfs
*tf
,
1660 struct config_group
*group
,
1663 struct tcm_qla2xxx_lport
*lport
;
1667 if (tcm_qla2xxx_parse_wwn(name
, &wwpn
, 1) < 0)
1668 return ERR_PTR(-EINVAL
);
1670 lport
= kzalloc(sizeof(struct tcm_qla2xxx_lport
), GFP_KERNEL
);
1672 pr_err("Unable to allocate struct tcm_qla2xxx_lport\n");
1673 return ERR_PTR(-ENOMEM
);
1675 lport
->lport_wwpn
= wwpn
;
1676 tcm_qla2xxx_format_wwn(&lport
->lport_name
[0], TCM_QLA2XXX_NAMELEN
,
1678 sprintf(lport
->lport_naa_name
, "naa.%016llx", (unsigned long long) wwpn
);
1680 ret
= tcm_qla2xxx_init_lport(lport
);
1684 ret
= qlt_lport_register(lport
, wwpn
, 0, 0,
1685 tcm_qla2xxx_lport_register_cb
);
1689 return &lport
->lport_wwn
;
1691 vfree(lport
->lport_loopid_map
);
1692 btree_destroy32(&lport
->lport_fcport_map
);
1695 return ERR_PTR(ret
);
1698 static void tcm_qla2xxx_drop_lport(struct se_wwn
*wwn
)
1700 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1701 struct tcm_qla2xxx_lport
, lport_wwn
);
1702 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1703 struct se_node_acl
*node
;
1707 * Call into qla2x_target.c LLD logic to complete the
1708 * shutdown of struct qla_tgt after the call to
1709 * qlt_stop_phase1() from tcm_qla2xxx_drop_tpg() above..
1711 if (vha
->vha_tgt
.qla_tgt
&& !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
1712 qlt_stop_phase2(vha
->vha_tgt
.qla_tgt
);
1714 qlt_lport_deregister(vha
);
1716 vfree(lport
->lport_loopid_map
);
1717 btree_for_each_safe32(&lport
->lport_fcport_map
, key
, node
)
1718 btree_remove32(&lport
->lport_fcport_map
, key
);
1719 btree_destroy32(&lport
->lport_fcport_map
);
1723 static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host
*base_vha
,
1724 void *target_lport_ptr
,
1725 u64 npiv_wwpn
, u64 npiv_wwnn
)
1727 struct fc_vport
*vport
;
1728 struct Scsi_Host
*sh
= base_vha
->host
;
1729 struct scsi_qla_host
*npiv_vha
;
1730 struct tcm_qla2xxx_lport
*lport
=
1731 (struct tcm_qla2xxx_lport
*)target_lport_ptr
;
1732 struct tcm_qla2xxx_lport
*base_lport
=
1733 (struct tcm_qla2xxx_lport
*)base_vha
->vha_tgt
.target_lport_ptr
;
1734 struct tcm_qla2xxx_tpg
*base_tpg
;
1735 struct fc_vport_identifiers vport_id
;
1737 if (!qla_tgt_mode_enabled(base_vha
)) {
1738 pr_err("qla2xxx base_vha not enabled for target mode\n");
1742 if (!base_lport
|| !base_lport
->tpg_1
||
1743 !atomic_read(&base_lport
->tpg_1
->lport_tpg_enabled
)) {
1744 pr_err("qla2xxx base_lport or tpg_1 not available\n");
1747 base_tpg
= base_lport
->tpg_1
;
1749 memset(&vport_id
, 0, sizeof(vport_id
));
1750 vport_id
.port_name
= npiv_wwpn
;
1751 vport_id
.node_name
= npiv_wwnn
;
1752 vport_id
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
1753 vport_id
.vport_type
= FC_PORTTYPE_NPIV
;
1754 vport_id
.disable
= false;
1756 vport
= fc_vport_create(sh
, 0, &vport_id
);
1758 pr_err("fc_vport_create failed for qla2xxx_npiv\n");
1762 * Setup local pointer to NPIV vhba + target_lport_ptr
1764 npiv_vha
= (struct scsi_qla_host
*)vport
->dd_data
;
1765 npiv_vha
->vha_tgt
.target_lport_ptr
= target_lport_ptr
;
1766 lport
->qla_vha
= npiv_vha
;
1767 scsi_host_get(npiv_vha
->host
);
1772 static struct se_wwn
*tcm_qla2xxx_npiv_make_lport(
1773 struct target_fabric_configfs
*tf
,
1774 struct config_group
*group
,
1777 struct tcm_qla2xxx_lport
*lport
;
1778 u64 phys_wwpn
, npiv_wwpn
, npiv_wwnn
;
1782 snprintf(tmp
, 128, "%s", name
);
1784 p
= strchr(tmp
, '@');
1786 pr_err("Unable to locate NPIV '@' seperator\n");
1787 return ERR_PTR(-EINVAL
);
1791 if (tcm_qla2xxx_parse_wwn(tmp
, &phys_wwpn
, 1) < 0)
1792 return ERR_PTR(-EINVAL
);
1794 if (tcm_qla2xxx_npiv_parse_wwn(p
, strlen(p
)+1,
1795 &npiv_wwpn
, &npiv_wwnn
) < 0)
1796 return ERR_PTR(-EINVAL
);
1798 lport
= kzalloc(sizeof(struct tcm_qla2xxx_lport
), GFP_KERNEL
);
1800 pr_err("Unable to allocate struct tcm_qla2xxx_lport for NPIV\n");
1801 return ERR_PTR(-ENOMEM
);
1803 lport
->lport_npiv_wwpn
= npiv_wwpn
;
1804 lport
->lport_npiv_wwnn
= npiv_wwnn
;
1805 sprintf(lport
->lport_naa_name
, "naa.%016llx", (unsigned long long) npiv_wwpn
);
1807 ret
= tcm_qla2xxx_init_lport(lport
);
1811 ret
= qlt_lport_register(lport
, phys_wwpn
, npiv_wwpn
, npiv_wwnn
,
1812 tcm_qla2xxx_lport_register_npiv_cb
);
1816 return &lport
->lport_wwn
;
1818 vfree(lport
->lport_loopid_map
);
1819 btree_destroy32(&lport
->lport_fcport_map
);
1822 return ERR_PTR(ret
);
1825 static void tcm_qla2xxx_npiv_drop_lport(struct se_wwn
*wwn
)
1827 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1828 struct tcm_qla2xxx_lport
, lport_wwn
);
1829 struct scsi_qla_host
*npiv_vha
= lport
->qla_vha
;
1830 struct qla_hw_data
*ha
= npiv_vha
->hw
;
1831 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1833 scsi_host_put(npiv_vha
->host
);
1835 * Notify libfc that we want to release the vha->fc_vport
1837 fc_vport_terminate(npiv_vha
->fc_vport
);
1838 scsi_host_put(base_vha
->host
);
1843 static ssize_t
tcm_qla2xxx_wwn_show_attr_version(
1844 struct target_fabric_configfs
*tf
,
1847 return sprintf(page
,
1848 "TCM QLOGIC QLA2XXX NPIV capable fabric module %s on %s/%s on "
1849 UTS_RELEASE
"\n", TCM_QLA2XXX_VERSION
, utsname()->sysname
,
1850 utsname()->machine
);
1853 TF_WWN_ATTR_RO(tcm_qla2xxx
, version
);
1855 static struct configfs_attribute
*tcm_qla2xxx_wwn_attrs
[] = {
1856 &tcm_qla2xxx_wwn_version
.attr
,
1860 static struct target_core_fabric_ops tcm_qla2xxx_ops
= {
1861 .get_fabric_name
= tcm_qla2xxx_get_fabric_name
,
1862 .get_fabric_proto_ident
= tcm_qla2xxx_get_fabric_proto_ident
,
1863 .tpg_get_wwn
= tcm_qla2xxx_get_fabric_wwn
,
1864 .tpg_get_tag
= tcm_qla2xxx_get_tag
,
1865 .tpg_get_default_depth
= tcm_qla2xxx_get_default_depth
,
1866 .tpg_get_pr_transport_id
= tcm_qla2xxx_get_pr_transport_id
,
1867 .tpg_get_pr_transport_id_len
= tcm_qla2xxx_get_pr_transport_id_len
,
1868 .tpg_parse_pr_out_transport_id
= tcm_qla2xxx_parse_pr_out_transport_id
,
1869 .tpg_check_demo_mode
= tcm_qla2xxx_check_demo_mode
,
1870 .tpg_check_demo_mode_cache
= tcm_qla2xxx_check_demo_mode_cache
,
1871 .tpg_check_demo_mode_write_protect
=
1872 tcm_qla2xxx_check_demo_write_protect
,
1873 .tpg_check_prod_mode_write_protect
=
1874 tcm_qla2xxx_check_prod_write_protect
,
1875 .tpg_check_demo_mode_login_only
= tcm_qla2xxx_check_demo_mode_login_only
,
1876 .tpg_alloc_fabric_acl
= tcm_qla2xxx_alloc_fabric_acl
,
1877 .tpg_release_fabric_acl
= tcm_qla2xxx_release_fabric_acl
,
1878 .tpg_get_inst_index
= tcm_qla2xxx_tpg_get_inst_index
,
1879 .check_stop_free
= tcm_qla2xxx_check_stop_free
,
1880 .release_cmd
= tcm_qla2xxx_release_cmd
,
1881 .put_session
= tcm_qla2xxx_put_session
,
1882 .shutdown_session
= tcm_qla2xxx_shutdown_session
,
1883 .close_session
= tcm_qla2xxx_close_session
,
1884 .sess_get_index
= tcm_qla2xxx_sess_get_index
,
1885 .sess_get_initiator_sid
= NULL
,
1886 .write_pending
= tcm_qla2xxx_write_pending
,
1887 .write_pending_status
= tcm_qla2xxx_write_pending_status
,
1888 .set_default_node_attributes
= tcm_qla2xxx_set_default_node_attrs
,
1889 .get_task_tag
= tcm_qla2xxx_get_task_tag
,
1890 .get_cmd_state
= tcm_qla2xxx_get_cmd_state
,
1891 .queue_data_in
= tcm_qla2xxx_queue_data_in
,
1892 .queue_status
= tcm_qla2xxx_queue_status
,
1893 .queue_tm_rsp
= tcm_qla2xxx_queue_tm_rsp
,
1894 .aborted_task
= tcm_qla2xxx_aborted_task
,
1896 * Setup function pointers for generic logic in
1897 * target_core_fabric_configfs.c
1899 .fabric_make_wwn
= tcm_qla2xxx_make_lport
,
1900 .fabric_drop_wwn
= tcm_qla2xxx_drop_lport
,
1901 .fabric_make_tpg
= tcm_qla2xxx_make_tpg
,
1902 .fabric_drop_tpg
= tcm_qla2xxx_drop_tpg
,
1903 .fabric_post_link
= NULL
,
1904 .fabric_pre_unlink
= NULL
,
1905 .fabric_make_np
= NULL
,
1906 .fabric_drop_np
= NULL
,
1907 .fabric_make_nodeacl
= tcm_qla2xxx_make_nodeacl
,
1908 .fabric_drop_nodeacl
= tcm_qla2xxx_drop_nodeacl
,
1911 static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops
= {
1912 .get_fabric_name
= tcm_qla2xxx_npiv_get_fabric_name
,
1913 .get_fabric_proto_ident
= tcm_qla2xxx_get_fabric_proto_ident
,
1914 .tpg_get_wwn
= tcm_qla2xxx_get_fabric_wwn
,
1915 .tpg_get_tag
= tcm_qla2xxx_get_tag
,
1916 .tpg_get_default_depth
= tcm_qla2xxx_get_default_depth
,
1917 .tpg_get_pr_transport_id
= tcm_qla2xxx_get_pr_transport_id
,
1918 .tpg_get_pr_transport_id_len
= tcm_qla2xxx_get_pr_transport_id_len
,
1919 .tpg_parse_pr_out_transport_id
= tcm_qla2xxx_parse_pr_out_transport_id
,
1920 .tpg_check_demo_mode
= tcm_qla2xxx_check_demo_mode
,
1921 .tpg_check_demo_mode_cache
= tcm_qla2xxx_check_demo_mode_cache
,
1922 .tpg_check_demo_mode_write_protect
= tcm_qla2xxx_check_demo_mode
,
1923 .tpg_check_prod_mode_write_protect
=
1924 tcm_qla2xxx_check_prod_write_protect
,
1925 .tpg_check_demo_mode_login_only
= tcm_qla2xxx_check_demo_mode_login_only
,
1926 .tpg_alloc_fabric_acl
= tcm_qla2xxx_alloc_fabric_acl
,
1927 .tpg_release_fabric_acl
= tcm_qla2xxx_release_fabric_acl
,
1928 .tpg_get_inst_index
= tcm_qla2xxx_tpg_get_inst_index
,
1929 .check_stop_free
= tcm_qla2xxx_check_stop_free
,
1930 .release_cmd
= tcm_qla2xxx_release_cmd
,
1931 .put_session
= tcm_qla2xxx_put_session
,
1932 .shutdown_session
= tcm_qla2xxx_shutdown_session
,
1933 .close_session
= tcm_qla2xxx_close_session
,
1934 .sess_get_index
= tcm_qla2xxx_sess_get_index
,
1935 .sess_get_initiator_sid
= NULL
,
1936 .write_pending
= tcm_qla2xxx_write_pending
,
1937 .write_pending_status
= tcm_qla2xxx_write_pending_status
,
1938 .set_default_node_attributes
= tcm_qla2xxx_set_default_node_attrs
,
1939 .get_task_tag
= tcm_qla2xxx_get_task_tag
,
1940 .get_cmd_state
= tcm_qla2xxx_get_cmd_state
,
1941 .queue_data_in
= tcm_qla2xxx_queue_data_in
,
1942 .queue_status
= tcm_qla2xxx_queue_status
,
1943 .queue_tm_rsp
= tcm_qla2xxx_queue_tm_rsp
,
1944 .aborted_task
= tcm_qla2xxx_aborted_task
,
1946 * Setup function pointers for generic logic in
1947 * target_core_fabric_configfs.c
1949 .fabric_make_wwn
= tcm_qla2xxx_npiv_make_lport
,
1950 .fabric_drop_wwn
= tcm_qla2xxx_npiv_drop_lport
,
1951 .fabric_make_tpg
= tcm_qla2xxx_npiv_make_tpg
,
1952 .fabric_drop_tpg
= tcm_qla2xxx_drop_tpg
,
1953 .fabric_post_link
= NULL
,
1954 .fabric_pre_unlink
= NULL
,
1955 .fabric_make_np
= NULL
,
1956 .fabric_drop_np
= NULL
,
1957 .fabric_make_nodeacl
= tcm_qla2xxx_make_nodeacl
,
1958 .fabric_drop_nodeacl
= tcm_qla2xxx_drop_nodeacl
,
1961 static int tcm_qla2xxx_register_configfs(void)
1963 struct target_fabric_configfs
*fabric
, *npiv_fabric
;
1966 pr_debug("TCM QLOGIC QLA2XXX fabric module %s on %s/%s on "
1967 UTS_RELEASE
"\n", TCM_QLA2XXX_VERSION
, utsname()->sysname
,
1968 utsname()->machine
);
1970 * Register the top level struct config_item_type with TCM core
1972 fabric
= target_fabric_configfs_init(THIS_MODULE
, "qla2xxx");
1973 if (IS_ERR(fabric
)) {
1974 pr_err("target_fabric_configfs_init() failed\n");
1975 return PTR_ERR(fabric
);
1978 * Setup fabric->tf_ops from our local tcm_qla2xxx_ops
1980 fabric
->tf_ops
= tcm_qla2xxx_ops
;
1982 * Setup default attribute lists for various fabric->tf_cit_tmpl
1984 fabric
->tf_cit_tmpl
.tfc_wwn_cit
.ct_attrs
= tcm_qla2xxx_wwn_attrs
;
1985 fabric
->tf_cit_tmpl
.tfc_tpg_base_cit
.ct_attrs
= tcm_qla2xxx_tpg_attrs
;
1986 fabric
->tf_cit_tmpl
.tfc_tpg_attrib_cit
.ct_attrs
=
1987 tcm_qla2xxx_tpg_attrib_attrs
;
1988 fabric
->tf_cit_tmpl
.tfc_tpg_param_cit
.ct_attrs
= NULL
;
1989 fabric
->tf_cit_tmpl
.tfc_tpg_np_base_cit
.ct_attrs
= NULL
;
1990 fabric
->tf_cit_tmpl
.tfc_tpg_nacl_base_cit
.ct_attrs
= NULL
;
1991 fabric
->tf_cit_tmpl
.tfc_tpg_nacl_attrib_cit
.ct_attrs
= NULL
;
1992 fabric
->tf_cit_tmpl
.tfc_tpg_nacl_auth_cit
.ct_attrs
= NULL
;
1993 fabric
->tf_cit_tmpl
.tfc_tpg_nacl_param_cit
.ct_attrs
= NULL
;
1995 * Register the fabric for use within TCM
1997 ret
= target_fabric_configfs_register(fabric
);
1999 pr_err("target_fabric_configfs_register() failed for TCM_QLA2XXX\n");
2003 * Setup our local pointer to *fabric
2005 tcm_qla2xxx_fabric_configfs
= fabric
;
2006 pr_debug("TCM_QLA2XXX[0] - Set fabric -> tcm_qla2xxx_fabric_configfs\n");
2009 * Register the top level struct config_item_type for NPIV with TCM core
2011 npiv_fabric
= target_fabric_configfs_init(THIS_MODULE
, "qla2xxx_npiv");
2012 if (IS_ERR(npiv_fabric
)) {
2013 pr_err("target_fabric_configfs_init() failed\n");
2014 ret
= PTR_ERR(npiv_fabric
);
2018 * Setup fabric->tf_ops from our local tcm_qla2xxx_npiv_ops
2020 npiv_fabric
->tf_ops
= tcm_qla2xxx_npiv_ops
;
2022 * Setup default attribute lists for various npiv_fabric->tf_cit_tmpl
2024 npiv_fabric
->tf_cit_tmpl
.tfc_wwn_cit
.ct_attrs
= tcm_qla2xxx_wwn_attrs
;
2025 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_base_cit
.ct_attrs
=
2026 tcm_qla2xxx_npiv_tpg_attrs
;
2027 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_attrib_cit
.ct_attrs
= NULL
;
2028 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_param_cit
.ct_attrs
= NULL
;
2029 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_np_base_cit
.ct_attrs
= NULL
;
2030 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_nacl_base_cit
.ct_attrs
= NULL
;
2031 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_nacl_attrib_cit
.ct_attrs
= NULL
;
2032 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_nacl_auth_cit
.ct_attrs
= NULL
;
2033 npiv_fabric
->tf_cit_tmpl
.tfc_tpg_nacl_param_cit
.ct_attrs
= NULL
;
2035 * Register the npiv_fabric for use within TCM
2037 ret
= target_fabric_configfs_register(npiv_fabric
);
2039 pr_err("target_fabric_configfs_register() failed for TCM_QLA2XXX\n");
2043 * Setup our local pointer to *npiv_fabric
2045 tcm_qla2xxx_npiv_fabric_configfs
= npiv_fabric
;
2046 pr_debug("TCM_QLA2XXX[0] - Set fabric -> tcm_qla2xxx_npiv_fabric_configfs\n");
2048 tcm_qla2xxx_free_wq
= alloc_workqueue("tcm_qla2xxx_free",
2050 if (!tcm_qla2xxx_free_wq
) {
2052 goto out_fabric_npiv
;
2055 tcm_qla2xxx_cmd_wq
= alloc_workqueue("tcm_qla2xxx_cmd", 0, 0);
2056 if (!tcm_qla2xxx_cmd_wq
) {
2064 destroy_workqueue(tcm_qla2xxx_free_wq
);
2066 target_fabric_configfs_deregister(tcm_qla2xxx_npiv_fabric_configfs
);
2068 target_fabric_configfs_deregister(tcm_qla2xxx_fabric_configfs
);
2072 static void tcm_qla2xxx_deregister_configfs(void)
2074 destroy_workqueue(tcm_qla2xxx_cmd_wq
);
2075 destroy_workqueue(tcm_qla2xxx_free_wq
);
2077 target_fabric_configfs_deregister(tcm_qla2xxx_fabric_configfs
);
2078 tcm_qla2xxx_fabric_configfs
= NULL
;
2079 pr_debug("TCM_QLA2XXX[0] - Cleared tcm_qla2xxx_fabric_configfs\n");
2081 target_fabric_configfs_deregister(tcm_qla2xxx_npiv_fabric_configfs
);
2082 tcm_qla2xxx_npiv_fabric_configfs
= NULL
;
2083 pr_debug("TCM_QLA2XXX[0] - Cleared tcm_qla2xxx_npiv_fabric_configfs\n");
2086 static int __init
tcm_qla2xxx_init(void)
2090 ret
= tcm_qla2xxx_register_configfs();
2097 static void __exit
tcm_qla2xxx_exit(void)
2099 tcm_qla2xxx_deregister_configfs();
2102 MODULE_DESCRIPTION("TCM QLA2XXX series NPIV enabled fabric driver");
2103 MODULE_LICENSE("GPL");
2104 module_init(tcm_qla2xxx_init
);
2105 module_exit(tcm_qla2xxx_exit
);