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 ssize_t tcm_qla2xxx_npiv_format_wwn(char *buf, size_t len,
190 put_unaligned_be64(wwpn, b);
191 put_unaligned_be64(wwnn, b2);
192 return snprintf(buf, len,
193 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x,"
194 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
195 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
196 b2[0], b2[1], b2[2], b2[3], b2[4], b2[5], b2[6], b2[7]);
199 static char *tcm_qla2xxx_npiv_get_fabric_name(void)
201 return "qla2xxx_npiv";
204 static u8 tcm_qla2xxx_get_fabric_proto_ident(struct se_portal_group *se_tpg)
206 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
207 struct tcm_qla2xxx_tpg, se_tpg);
208 struct tcm_qla2xxx_lport *lport = tpg->lport;
211 switch (lport->lport_proto_id) {
212 case SCSI_PROTOCOL_FCP:
214 proto_id = fc_get_fabric_proto_ident(se_tpg);
221 static char *tcm_qla2xxx_get_fabric_wwn(struct se_portal_group *se_tpg)
223 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
224 struct tcm_qla2xxx_tpg, se_tpg);
225 struct tcm_qla2xxx_lport *lport = tpg->lport;
227 return lport->lport_naa_name;
230 static char *tcm_qla2xxx_npiv_get_fabric_wwn(struct se_portal_group *se_tpg)
232 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
233 struct tcm_qla2xxx_tpg, se_tpg);
234 struct tcm_qla2xxx_lport *lport = tpg->lport;
236 return &lport->lport_npiv_name[0];
239 static u16 tcm_qla2xxx_get_tag(struct se_portal_group *se_tpg)
241 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
242 struct tcm_qla2xxx_tpg, se_tpg);
243 return tpg->lport_tpgt;
246 static u32 tcm_qla2xxx_get_default_depth(struct se_portal_group *se_tpg)
251 static u32 tcm_qla2xxx_get_pr_transport_id(
252 struct se_portal_group *se_tpg,
253 struct se_node_acl *se_nacl,
254 struct t10_pr_registration *pr_reg,
258 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
259 struct tcm_qla2xxx_tpg, se_tpg);
260 struct tcm_qla2xxx_lport *lport = tpg->lport;
263 switch (lport->lport_proto_id) {
264 case SCSI_PROTOCOL_FCP:
266 ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
274 static u32 tcm_qla2xxx_get_pr_transport_id_len(
275 struct se_portal_group *se_tpg,
276 struct se_node_acl *se_nacl,
277 struct t10_pr_registration *pr_reg,
280 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
281 struct tcm_qla2xxx_tpg, se_tpg);
282 struct tcm_qla2xxx_lport *lport = tpg->lport;
285 switch (lport->lport_proto_id) {
286 case SCSI_PROTOCOL_FCP:
288 ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
296 static char *tcm_qla2xxx_parse_pr_out_transport_id(
297 struct se_portal_group *se_tpg,
300 char **port_nexus_ptr)
302 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
303 struct tcm_qla2xxx_tpg, se_tpg);
304 struct tcm_qla2xxx_lport *lport = tpg->lport;
307 switch (lport->lport_proto_id) {
308 case SCSI_PROTOCOL_FCP:
310 tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
318 static int tcm_qla2xxx_check_demo_mode(struct se_portal_group *se_tpg)
320 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
321 struct tcm_qla2xxx_tpg, se_tpg);
323 return tpg->tpg_attrib.generate_node_acls;
326 static int tcm_qla2xxx_check_demo_mode_cache(struct se_portal_group *se_tpg)
328 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
329 struct tcm_qla2xxx_tpg, se_tpg);
331 return tpg->tpg_attrib.cache_dynamic_acls;
334 static int tcm_qla2xxx_check_demo_write_protect(struct se_portal_group *se_tpg)
336 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
337 struct tcm_qla2xxx_tpg, se_tpg);
339 return tpg->tpg_attrib.demo_mode_write_protect;
342 static int tcm_qla2xxx_check_prod_write_protect(struct se_portal_group *se_tpg)
344 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
345 struct tcm_qla2xxx_tpg, se_tpg);
347 return tpg->tpg_attrib.prod_mode_write_protect;
350 static int tcm_qla2xxx_check_demo_mode_login_only(struct se_portal_group *se_tpg)
352 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
353 struct tcm_qla2xxx_tpg, se_tpg);
355 return tpg->tpg_attrib.demo_mode_login_only;
358 static struct se_node_acl *tcm_qla2xxx_alloc_fabric_acl(
359 struct se_portal_group *se_tpg)
361 struct tcm_qla2xxx_nacl *nacl;
363 nacl = kzalloc(sizeof(struct tcm_qla2xxx_nacl), GFP_KERNEL);
365 pr_err("Unable to allocate struct tcm_qla2xxx_nacl\n");
369 return &nacl->se_node_acl;
372 static void tcm_qla2xxx_release_fabric_acl(
373 struct se_portal_group *se_tpg,
374 struct se_node_acl *se_nacl)
376 struct tcm_qla2xxx_nacl *nacl = container_of(se_nacl,
377 struct tcm_qla2xxx_nacl, se_node_acl);
381 static u32 tcm_qla2xxx_tpg_get_inst_index(struct se_portal_group *se_tpg)
383 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
384 struct tcm_qla2xxx_tpg, se_tpg);
386 return tpg->lport_tpgt;
389 static void tcm_qla2xxx_complete_mcmd(struct work_struct *work)
391 struct qla_tgt_mgmt_cmd *mcmd = container_of(work,
392 struct qla_tgt_mgmt_cmd, free_work);
394 transport_generic_free_cmd(&mcmd->se_cmd, 0);
398 * Called from qla_target_template->free_mcmd(), and will call
399 * tcm_qla2xxx_release_cmd() via normal struct target_core_fabric_ops
400 * release callback. qla_hw_data->hardware_lock is expected to be held
402 static void tcm_qla2xxx_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd)
404 INIT_WORK(&mcmd->free_work, tcm_qla2xxx_complete_mcmd);
405 queue_work(tcm_qla2xxx_free_wq, &mcmd->free_work);
408 static void tcm_qla2xxx_complete_free(struct work_struct *work)
410 struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work);
412 transport_generic_free_cmd(&cmd->se_cmd, 0);
416 * Called from qla_target_template->free_cmd(), and will call
417 * tcm_qla2xxx_release_cmd via normal struct target_core_fabric_ops
418 * release callback. qla_hw_data->hardware_lock is expected to be held
420 static void tcm_qla2xxx_free_cmd(struct qla_tgt_cmd *cmd)
422 INIT_WORK(&cmd->work, tcm_qla2xxx_complete_free);
423 queue_work(tcm_qla2xxx_free_wq, &cmd->work);
427 * Called from struct target_core_fabric_ops->check_stop_free() context
429 static int tcm_qla2xxx_check_stop_free(struct se_cmd *se_cmd)
431 return target_put_sess_cmd(se_cmd->se_sess, se_cmd);
434 /* tcm_qla2xxx_release_cmd - Callback from TCM Core to release underlying
435 * fabric descriptor @se_cmd command to release
437 static void tcm_qla2xxx_release_cmd(struct se_cmd *se_cmd)
439 struct qla_tgt_cmd *cmd;
441 if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) {
442 struct qla_tgt_mgmt_cmd *mcmd = container_of(se_cmd,
443 struct qla_tgt_mgmt_cmd, se_cmd);
448 cmd = container_of(se_cmd, struct qla_tgt_cmd, se_cmd);
452 static int tcm_qla2xxx_shutdown_session(struct se_session *se_sess)
454 struct qla_tgt_sess *sess = se_sess->fabric_sess_ptr;
455 struct scsi_qla_host *vha;
461 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
462 target_sess_cmd_list_set_waiting(se_sess);
463 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
468 static void tcm_qla2xxx_close_session(struct se_session *se_sess)
470 struct qla_tgt_sess *sess = se_sess->fabric_sess_ptr;
471 struct scsi_qla_host *vha;
477 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
478 qlt_unreg_sess(sess);
479 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
482 static u32 tcm_qla2xxx_sess_get_index(struct se_session *se_sess)
487 static int tcm_qla2xxx_write_pending(struct se_cmd *se_cmd)
489 struct qla_tgt_cmd *cmd = container_of(se_cmd,
490 struct qla_tgt_cmd, se_cmd);
492 cmd->bufflen = se_cmd->data_length;
493 cmd->dma_data_direction = target_reverse_dma_direction(se_cmd);
495 cmd->sg_cnt = se_cmd->t_data_nents;
496 cmd->sg = se_cmd->t_data_sg;
499 * qla_target.c:qlt_rdy_to_xfer() will call pci_map_sg() to setup
500 * the SGL mappings into PCIe memory for incoming FCP WRITE data.
502 return qlt_rdy_to_xfer(cmd);
505 static int tcm_qla2xxx_write_pending_status(struct se_cmd *se_cmd)
509 * Check for WRITE_PENDING status to determine if we need to wait for
510 * CTIO aborts to be posted via hardware in tcm_qla2xxx_handle_data().
512 spin_lock_irqsave(&se_cmd->t_state_lock, flags);
513 if (se_cmd->t_state == TRANSPORT_WRITE_PENDING ||
514 se_cmd->t_state == TRANSPORT_COMPLETE_QF_WP) {
515 spin_unlock_irqrestore(&se_cmd->t_state_lock, flags);
516 wait_for_completion_timeout(&se_cmd->t_transport_stop_comp,
520 spin_unlock_irqrestore(&se_cmd->t_state_lock, flags);
525 static void tcm_qla2xxx_set_default_node_attrs(struct se_node_acl *nacl)
530 static u32 tcm_qla2xxx_get_task_tag(struct se_cmd *se_cmd)
532 struct qla_tgt_cmd *cmd = container_of(se_cmd,
533 struct qla_tgt_cmd, se_cmd);
538 static int tcm_qla2xxx_get_cmd_state(struct se_cmd *se_cmd)
544 * Called from process context in qla_target.c:qlt_do_work() code
546 static int tcm_qla2xxx_handle_cmd(scsi_qla_host_t *vha, struct qla_tgt_cmd *cmd,
547 unsigned char *cdb, uint32_t data_length, int fcp_task_attr,
548 int data_dir, int bidi)
550 struct se_cmd *se_cmd = &cmd->se_cmd;
551 struct se_session *se_sess;
552 struct qla_tgt_sess *sess;
553 int flags = TARGET_SCF_ACK_KREF;
556 flags |= TARGET_SCF_BIDI_OP;
560 pr_err("Unable to locate struct qla_tgt_sess from qla_tgt_cmd\n");
564 se_sess = sess->se_sess;
566 pr_err("Unable to locate active struct se_session\n");
570 return target_submit_cmd(se_cmd, se_sess, cdb, &cmd->sense_buffer[0],
571 cmd->unpacked_lun, data_length, fcp_task_attr,
575 static void tcm_qla2xxx_handle_data_work(struct work_struct *work)
577 struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work);
580 * Ensure that the complete FCP WRITE payload has been received.
581 * Otherwise return an exception via CHECK_CONDITION status.
583 if (!cmd->write_data_transferred) {
585 * Check if se_cmd has already been aborted via LUN_RESET, and
586 * waiting upon completion in tcm_qla2xxx_write_pending_status()
588 if (cmd->se_cmd.transport_state & CMD_T_ABORTED) {
589 complete(&cmd->se_cmd.t_transport_stop_comp);
593 transport_generic_request_failure(&cmd->se_cmd,
594 TCM_CHECK_CONDITION_ABORT_CMD);
598 return target_execute_cmd(&cmd->se_cmd);
602 * Called from qla_target.c:qlt_do_ctio_completion()
604 static void tcm_qla2xxx_handle_data(struct qla_tgt_cmd *cmd)
606 INIT_WORK(&cmd->work, tcm_qla2xxx_handle_data_work);
607 queue_work(tcm_qla2xxx_free_wq, &cmd->work);
611 * Called from qla_target.c:qlt_issue_task_mgmt()
613 static int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd *mcmd, uint32_t lun,
614 uint8_t tmr_func, uint32_t tag)
616 struct qla_tgt_sess *sess = mcmd->sess;
617 struct se_cmd *se_cmd = &mcmd->se_cmd;
619 return target_submit_tmr(se_cmd, sess->se_sess, NULL, lun, mcmd,
620 tmr_func, GFP_ATOMIC, tag, TARGET_SCF_ACK_KREF);
623 static int tcm_qla2xxx_queue_data_in(struct se_cmd *se_cmd)
625 struct qla_tgt_cmd *cmd = container_of(se_cmd,
626 struct qla_tgt_cmd, se_cmd);
628 cmd->bufflen = se_cmd->data_length;
629 cmd->dma_data_direction = target_reverse_dma_direction(se_cmd);
630 cmd->aborted = (se_cmd->transport_state & CMD_T_ABORTED);
632 cmd->sg_cnt = se_cmd->t_data_nents;
633 cmd->sg = se_cmd->t_data_sg;
637 * Now queue completed DATA_IN the qla2xxx LLD and response ring
639 return qlt_xmit_response(cmd, QLA_TGT_XMIT_DATA|QLA_TGT_XMIT_STATUS,
640 se_cmd->scsi_status);
643 static int tcm_qla2xxx_queue_status(struct se_cmd *se_cmd)
645 struct qla_tgt_cmd *cmd = container_of(se_cmd,
646 struct qla_tgt_cmd, se_cmd);
647 int xmit_type = QLA_TGT_XMIT_STATUS;
649 cmd->bufflen = se_cmd->data_length;
653 cmd->dma_data_direction = target_reverse_dma_direction(se_cmd);
654 cmd->aborted = (se_cmd->transport_state & CMD_T_ABORTED);
656 if (se_cmd->data_direction == DMA_FROM_DEVICE) {
658 * For FCP_READ with CHECK_CONDITION status, clear cmd->bufflen
659 * for qla_tgt_xmit_response LLD code
661 if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) {
662 se_cmd->se_cmd_flags &= ~SCF_OVERFLOW_BIT;
663 se_cmd->residual_count = 0;
665 se_cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT;
666 se_cmd->residual_count += se_cmd->data_length;
671 * Now queue status response to qla2xxx LLD code and response ring
673 return qlt_xmit_response(cmd, xmit_type, se_cmd->scsi_status);
676 static void tcm_qla2xxx_queue_tm_rsp(struct se_cmd *se_cmd)
678 struct se_tmr_req *se_tmr = se_cmd->se_tmr_req;
679 struct qla_tgt_mgmt_cmd *mcmd = container_of(se_cmd,
680 struct qla_tgt_mgmt_cmd, se_cmd);
682 pr_debug("queue_tm_rsp: mcmd: %p func: 0x%02x response: 0x%02x\n",
683 mcmd, se_tmr->function, se_tmr->response);
685 * Do translation between TCM TM response codes and
686 * QLA2xxx FC TM response codes.
688 switch (se_tmr->response) {
689 case TMR_FUNCTION_COMPLETE:
690 mcmd->fc_tm_rsp = FC_TM_SUCCESS;
692 case TMR_TASK_DOES_NOT_EXIST:
693 mcmd->fc_tm_rsp = FC_TM_BAD_CMD;
695 case TMR_FUNCTION_REJECTED:
696 mcmd->fc_tm_rsp = FC_TM_REJECT;
698 case TMR_LUN_DOES_NOT_EXIST:
700 mcmd->fc_tm_rsp = FC_TM_FAILED;
704 * Queue the TM response to QLA2xxx LLD to build a
705 * CTIO response packet.
707 qlt_xmit_tm_rsp(mcmd);
710 /* Local pointer to allocated TCM configfs fabric module */
711 struct target_fabric_configfs *tcm_qla2xxx_fabric_configfs;
712 struct target_fabric_configfs *tcm_qla2xxx_npiv_fabric_configfs;
714 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport *,
715 struct tcm_qla2xxx_nacl *, struct qla_tgt_sess *);
717 * Expected to be called with struct qla_hw_data->hardware_lock held
719 static void tcm_qla2xxx_clear_nacl_from_fcport_map(struct qla_tgt_sess *sess)
721 struct se_node_acl *se_nacl = sess->se_sess->se_node_acl;
722 struct se_portal_group *se_tpg = se_nacl->se_tpg;
723 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
724 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
725 struct tcm_qla2xxx_lport, lport_wwn);
726 struct tcm_qla2xxx_nacl *nacl = container_of(se_nacl,
727 struct tcm_qla2xxx_nacl, se_node_acl);
730 pr_debug("fc_rport domain: port_id 0x%06x\n", nacl->nport_id);
732 node = btree_remove32(&lport->lport_fcport_map, nacl->nport_id);
733 WARN_ON(node && (node != se_nacl));
735 pr_debug("Removed from fcport_map: %p for WWNN: 0x%016LX, port_id: 0x%06x\n",
736 se_nacl, nacl->nport_wwnn, nacl->nport_id);
738 * Now clear the se_nacl and session pointers from our HW lport lookup
739 * table mapping for this initiator's fabric S_ID and LOOP_ID entries.
741 * This is done ahead of callbacks into tcm_qla2xxx_free_session() ->
742 * target_wait_for_sess_cmds() before the session waits for outstanding
743 * I/O to complete, to avoid a race between session shutdown execution
744 * and incoming ATIOs or TMRs picking up a stale se_node_act reference.
746 tcm_qla2xxx_clear_sess_lookup(lport, nacl, sess);
749 static void tcm_qla2xxx_release_session(struct kref *kref)
751 struct se_session *se_sess = container_of(kref,
752 struct se_session, sess_kref);
754 qlt_unreg_sess(se_sess->fabric_sess_ptr);
757 static void tcm_qla2xxx_put_session(struct se_session *se_sess)
759 struct qla_tgt_sess *sess = se_sess->fabric_sess_ptr;
760 struct qla_hw_data *ha = sess->vha->hw;
763 spin_lock_irqsave(&ha->hardware_lock, flags);
764 kref_put(&se_sess->sess_kref, tcm_qla2xxx_release_session);
765 spin_unlock_irqrestore(&ha->hardware_lock, flags);
768 static void tcm_qla2xxx_put_sess(struct qla_tgt_sess *sess)
773 assert_spin_locked(&sess->vha->hw->hardware_lock);
774 kref_put(&sess->se_sess->sess_kref, tcm_qla2xxx_release_session);
777 static void tcm_qla2xxx_shutdown_sess(struct qla_tgt_sess *sess)
779 assert_spin_locked(&sess->vha->hw->hardware_lock);
780 target_sess_cmd_list_set_waiting(sess->se_sess);
783 static struct se_node_acl *tcm_qla2xxx_make_nodeacl(
784 struct se_portal_group *se_tpg,
785 struct config_group *group,
788 struct se_node_acl *se_nacl, *se_nacl_new;
789 struct tcm_qla2xxx_nacl *nacl;
791 u32 qla2xxx_nexus_depth;
793 if (tcm_qla2xxx_parse_wwn(name, &wwnn, 1) < 0)
794 return ERR_PTR(-EINVAL);
796 se_nacl_new = tcm_qla2xxx_alloc_fabric_acl(se_tpg);
798 return ERR_PTR(-ENOMEM);
799 /* #warning FIXME: Hardcoded qla2xxx_nexus depth in tcm_qla2xxx_make_nodeacl */
800 qla2xxx_nexus_depth = 1;
803 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
804 * when converting a NodeACL from demo mode -> explict
806 se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,
807 name, qla2xxx_nexus_depth);
808 if (IS_ERR(se_nacl)) {
809 tcm_qla2xxx_release_fabric_acl(se_tpg, se_nacl_new);
813 * Locate our struct tcm_qla2xxx_nacl and set the FC Nport WWPN
815 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
816 nacl->nport_wwnn = wwnn;
817 tcm_qla2xxx_format_wwn(&nacl->nport_name[0], TCM_QLA2XXX_NAMELEN, wwnn);
822 static void tcm_qla2xxx_drop_nodeacl(struct se_node_acl *se_acl)
824 struct se_portal_group *se_tpg = se_acl->se_tpg;
825 struct tcm_qla2xxx_nacl *nacl = container_of(se_acl,
826 struct tcm_qla2xxx_nacl, se_node_acl);
828 core_tpg_del_initiator_node_acl(se_tpg, se_acl, 1);
832 /* Start items for tcm_qla2xxx_tpg_attrib_cit */
834 #define DEF_QLA_TPG_ATTRIB(name) \
836 static ssize_t tcm_qla2xxx_tpg_attrib_show_##name( \
837 struct se_portal_group *se_tpg, \
840 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
841 struct tcm_qla2xxx_tpg, se_tpg); \
843 return sprintf(page, "%u\n", tpg->tpg_attrib.name); \
846 static ssize_t tcm_qla2xxx_tpg_attrib_store_##name( \
847 struct se_portal_group *se_tpg, \
851 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
852 struct tcm_qla2xxx_tpg, se_tpg); \
856 ret = kstrtoul(page, 0, &val); \
858 pr_err("kstrtoul() failed with" \
859 " ret: %d\n", ret); \
862 ret = tcm_qla2xxx_set_attrib_##name(tpg, val); \
864 return (!ret) ? count : -EINVAL; \
867 #define DEF_QLA_TPG_ATTR_BOOL(_name) \
869 static int tcm_qla2xxx_set_attrib_##_name( \
870 struct tcm_qla2xxx_tpg *tpg, \
873 struct tcm_qla2xxx_tpg_attrib *a = &tpg->tpg_attrib; \
875 if ((val != 0) && (val != 1)) { \
876 pr_err("Illegal boolean value %lu\n", val); \
884 #define QLA_TPG_ATTR(_name, _mode) \
885 TF_TPG_ATTRIB_ATTR(tcm_qla2xxx, _name, _mode);
888 * Define tcm_qla2xxx_tpg_attrib_s_generate_node_acls
890 DEF_QLA_TPG_ATTR_BOOL(generate_node_acls);
891 DEF_QLA_TPG_ATTRIB(generate_node_acls);
892 QLA_TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR);
895 Define tcm_qla2xxx_attrib_s_cache_dynamic_acls
897 DEF_QLA_TPG_ATTR_BOOL(cache_dynamic_acls);
898 DEF_QLA_TPG_ATTRIB(cache_dynamic_acls);
899 QLA_TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR);
902 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_write_protect
904 DEF_QLA_TPG_ATTR_BOOL(demo_mode_write_protect);
905 DEF_QLA_TPG_ATTRIB(demo_mode_write_protect);
906 QLA_TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR);
909 * Define tcm_qla2xxx_tpg_attrib_s_prod_mode_write_protect
911 DEF_QLA_TPG_ATTR_BOOL(prod_mode_write_protect);
912 DEF_QLA_TPG_ATTRIB(prod_mode_write_protect);
913 QLA_TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR);
916 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_login_only
918 DEF_QLA_TPG_ATTR_BOOL(demo_mode_login_only);
919 DEF_QLA_TPG_ATTRIB(demo_mode_login_only);
920 QLA_TPG_ATTR(demo_mode_login_only, S_IRUGO | S_IWUSR);
922 static struct configfs_attribute *tcm_qla2xxx_tpg_attrib_attrs[] = {
923 &tcm_qla2xxx_tpg_attrib_generate_node_acls.attr,
924 &tcm_qla2xxx_tpg_attrib_cache_dynamic_acls.attr,
925 &tcm_qla2xxx_tpg_attrib_demo_mode_write_protect.attr,
926 &tcm_qla2xxx_tpg_attrib_prod_mode_write_protect.attr,
927 &tcm_qla2xxx_tpg_attrib_demo_mode_login_only.attr,
931 /* End items for tcm_qla2xxx_tpg_attrib_cit */
933 static ssize_t tcm_qla2xxx_tpg_show_enable(
934 struct se_portal_group *se_tpg,
937 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
938 struct tcm_qla2xxx_tpg, se_tpg);
940 return snprintf(page, PAGE_SIZE, "%d\n",
941 atomic_read(&tpg->lport_tpg_enabled));
944 static void tcm_qla2xxx_depend_tpg(struct work_struct *work)
946 struct tcm_qla2xxx_tpg *base_tpg = container_of(work,
947 struct tcm_qla2xxx_tpg, tpg_base_work);
948 struct se_portal_group *se_tpg = &base_tpg->se_tpg;
949 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha;
951 if (!configfs_depend_item(se_tpg->se_tpg_tfo->tf_subsys,
952 &se_tpg->tpg_group.cg_item)) {
953 atomic_set(&base_tpg->lport_tpg_enabled, 1);
954 qlt_enable_vha(base_vha);
956 complete(&base_tpg->tpg_base_comp);
959 static void tcm_qla2xxx_undepend_tpg(struct work_struct *work)
961 struct tcm_qla2xxx_tpg *base_tpg = container_of(work,
962 struct tcm_qla2xxx_tpg, tpg_base_work);
963 struct se_portal_group *se_tpg = &base_tpg->se_tpg;
964 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha;
966 if (!qlt_stop_phase1(base_vha->vha_tgt.qla_tgt)) {
967 atomic_set(&base_tpg->lport_tpg_enabled, 0);
968 configfs_undepend_item(se_tpg->se_tpg_tfo->tf_subsys,
969 &se_tpg->tpg_group.cg_item);
971 complete(&base_tpg->tpg_base_comp);
974 static ssize_t tcm_qla2xxx_tpg_store_enable(
975 struct se_portal_group *se_tpg,
979 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
980 struct tcm_qla2xxx_tpg, se_tpg);
984 rc = kstrtoul(page, 0, &op);
986 pr_err("kstrtoul() returned %d\n", rc);
989 if ((op != 1) && (op != 0)) {
990 pr_err("Illegal value for tpg_enable: %lu\n", op);
994 if (atomic_read(&tpg->lport_tpg_enabled))
997 INIT_WORK(&tpg->tpg_base_work, tcm_qla2xxx_depend_tpg);
999 if (!atomic_read(&tpg->lport_tpg_enabled))
1002 INIT_WORK(&tpg->tpg_base_work, tcm_qla2xxx_undepend_tpg);
1004 init_completion(&tpg->tpg_base_comp);
1005 schedule_work(&tpg->tpg_base_work);
1006 wait_for_completion(&tpg->tpg_base_comp);
1009 if (!atomic_read(&tpg->lport_tpg_enabled))
1012 if (atomic_read(&tpg->lport_tpg_enabled))
1018 TF_TPG_BASE_ATTR(tcm_qla2xxx, enable, S_IRUGO | S_IWUSR);
1020 static struct configfs_attribute *tcm_qla2xxx_tpg_attrs[] = {
1021 &tcm_qla2xxx_tpg_enable.attr,
1025 static struct se_portal_group *tcm_qla2xxx_make_tpg(
1027 struct config_group *group,
1030 struct tcm_qla2xxx_lport *lport = container_of(wwn,
1031 struct tcm_qla2xxx_lport, lport_wwn);
1032 struct tcm_qla2xxx_tpg *tpg;
1036 if (strstr(name, "tpgt_") != name)
1037 return ERR_PTR(-EINVAL);
1038 if (kstrtoul(name + 5, 10, &tpgt) || tpgt > USHRT_MAX)
1039 return ERR_PTR(-EINVAL);
1042 pr_err("In non NPIV mode, a single TPG=1 is used for HW port mappings\n");
1043 return ERR_PTR(-ENOSYS);
1046 tpg = kzalloc(sizeof(struct tcm_qla2xxx_tpg), GFP_KERNEL);
1048 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1049 return ERR_PTR(-ENOMEM);
1052 tpg->lport_tpgt = tpgt;
1054 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1057 tpg->tpg_attrib.generate_node_acls = 1;
1058 tpg->tpg_attrib.demo_mode_write_protect = 1;
1059 tpg->tpg_attrib.cache_dynamic_acls = 1;
1060 tpg->tpg_attrib.demo_mode_login_only = 1;
1062 ret = core_tpg_register(&tcm_qla2xxx_fabric_configfs->tf_ops, wwn,
1063 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL);
1071 return &tpg->se_tpg;
1074 static void tcm_qla2xxx_drop_tpg(struct se_portal_group *se_tpg)
1076 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
1077 struct tcm_qla2xxx_tpg, se_tpg);
1078 struct tcm_qla2xxx_lport *lport = tpg->lport;
1079 struct scsi_qla_host *vha = lport->qla_vha;
1081 * Call into qla2x_target.c LLD logic to shutdown the active
1082 * FC Nexuses and disable target mode operation for this qla_hw_data
1084 if (vha->vha_tgt.qla_tgt && !vha->vha_tgt.qla_tgt->tgt_stop)
1085 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
1087 core_tpg_deregister(se_tpg);
1089 * Clear local TPG=1 pointer for non NPIV mode.
1091 lport->tpg_1 = NULL;
1095 static ssize_t tcm_qla2xxx_npiv_tpg_show_enable(
1096 struct se_portal_group *se_tpg,
1099 return tcm_qla2xxx_tpg_show_enable(se_tpg, page);
1102 static ssize_t tcm_qla2xxx_npiv_tpg_store_enable(
1103 struct se_portal_group *se_tpg,
1107 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
1108 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
1109 struct tcm_qla2xxx_lport, lport_wwn);
1110 struct scsi_qla_host *vha = lport->qla_vha;
1111 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
1112 struct tcm_qla2xxx_tpg, se_tpg);
1116 rc = kstrtoul(page, 0, &op);
1118 pr_err("kstrtoul() returned %d\n", rc);
1121 if ((op != 1) && (op != 0)) {
1122 pr_err("Illegal value for tpg_enable: %lu\n", op);
1126 if (atomic_read(&tpg->lport_tpg_enabled))
1129 atomic_set(&tpg->lport_tpg_enabled, 1);
1130 qlt_enable_vha(vha);
1132 if (!atomic_read(&tpg->lport_tpg_enabled))
1135 atomic_set(&tpg->lport_tpg_enabled, 0);
1136 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
1142 TF_TPG_BASE_ATTR(tcm_qla2xxx_npiv, enable, S_IRUGO | S_IWUSR);
1144 static struct configfs_attribute *tcm_qla2xxx_npiv_tpg_attrs[] = {
1145 &tcm_qla2xxx_npiv_tpg_enable.attr,
1149 static struct se_portal_group *tcm_qla2xxx_npiv_make_tpg(
1151 struct config_group *group,
1154 struct tcm_qla2xxx_lport *lport = container_of(wwn,
1155 struct tcm_qla2xxx_lport, lport_wwn);
1156 struct tcm_qla2xxx_tpg *tpg;
1160 if (strstr(name, "tpgt_") != name)
1161 return ERR_PTR(-EINVAL);
1162 if (kstrtoul(name + 5, 10, &tpgt) || tpgt > USHRT_MAX)
1163 return ERR_PTR(-EINVAL);
1165 tpg = kzalloc(sizeof(struct tcm_qla2xxx_tpg), GFP_KERNEL);
1167 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1168 return ERR_PTR(-ENOMEM);
1171 tpg->lport_tpgt = tpgt;
1174 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1177 tpg->tpg_attrib.generate_node_acls = 1;
1178 tpg->tpg_attrib.demo_mode_write_protect = 1;
1179 tpg->tpg_attrib.cache_dynamic_acls = 1;
1180 tpg->tpg_attrib.demo_mode_login_only = 1;
1182 ret = core_tpg_register(&tcm_qla2xxx_npiv_fabric_configfs->tf_ops, wwn,
1183 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL);
1189 return &tpg->se_tpg;
1193 * Expected to be called with struct qla_hw_data->hardware_lock held
1195 static struct qla_tgt_sess *tcm_qla2xxx_find_sess_by_s_id(
1196 scsi_qla_host_t *vha,
1197 const uint8_t *s_id)
1199 struct tcm_qla2xxx_lport *lport;
1200 struct se_node_acl *se_nacl;
1201 struct tcm_qla2xxx_nacl *nacl;
1204 lport = vha->vha_tgt.target_lport_ptr;
1206 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1211 key = (((unsigned long)s_id[0] << 16) |
1212 ((unsigned long)s_id[1] << 8) |
1213 (unsigned long)s_id[2]);
1214 pr_debug("find_sess_by_s_id: 0x%06x\n", key);
1216 se_nacl = btree_lookup32(&lport->lport_fcport_map, key);
1218 pr_debug("Unable to locate s_id: 0x%06x\n", key);
1221 pr_debug("find_sess_by_s_id: located se_nacl: %p, initiatorname: %s\n",
1222 se_nacl, se_nacl->initiatorname);
1224 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
1225 if (!nacl->qla_tgt_sess) {
1226 pr_err("Unable to locate struct qla_tgt_sess\n");
1230 return nacl->qla_tgt_sess;
1234 * Expected to be called with struct qla_hw_data->hardware_lock held
1236 static void tcm_qla2xxx_set_sess_by_s_id(
1237 struct tcm_qla2xxx_lport *lport,
1238 struct se_node_acl *new_se_nacl,
1239 struct tcm_qla2xxx_nacl *nacl,
1240 struct se_session *se_sess,
1241 struct qla_tgt_sess *qla_tgt_sess,
1248 key = (((unsigned long)s_id[0] << 16) |
1249 ((unsigned long)s_id[1] << 8) |
1250 (unsigned long)s_id[2]);
1251 pr_debug("set_sess_by_s_id: %06x\n", key);
1253 slot = btree_lookup32(&lport->lport_fcport_map, key);
1256 pr_debug("Setting up new fc_port entry to new_se_nacl\n");
1257 nacl->nport_id = key;
1258 rc = btree_insert32(&lport->lport_fcport_map, key,
1259 new_se_nacl, GFP_ATOMIC);
1261 printk(KERN_ERR "Unable to insert s_id into fcport_map: %06x\n",
1264 pr_debug("Wiping nonexisting fc_port entry\n");
1267 qla_tgt_sess->se_sess = se_sess;
1268 nacl->qla_tgt_sess = qla_tgt_sess;
1272 if (nacl->qla_tgt_sess) {
1273 if (new_se_nacl == NULL) {
1274 pr_debug("Clearing existing nacl->qla_tgt_sess and fc_port entry\n");
1275 btree_remove32(&lport->lport_fcport_map, key);
1276 nacl->qla_tgt_sess = NULL;
1279 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_port entry\n");
1280 btree_update32(&lport->lport_fcport_map, key, new_se_nacl);
1281 qla_tgt_sess->se_sess = se_sess;
1282 nacl->qla_tgt_sess = qla_tgt_sess;
1286 if (new_se_nacl == NULL) {
1287 pr_debug("Clearing existing fc_port entry\n");
1288 btree_remove32(&lport->lport_fcport_map, key);
1292 pr_debug("Replacing existing fc_port entry w/o active nacl->qla_tgt_sess\n");
1293 btree_update32(&lport->lport_fcport_map, key, new_se_nacl);
1294 qla_tgt_sess->se_sess = se_sess;
1295 nacl->qla_tgt_sess = qla_tgt_sess;
1297 pr_debug("Setup nacl->qla_tgt_sess %p by s_id for se_nacl: %p, initiatorname: %s\n",
1298 nacl->qla_tgt_sess, new_se_nacl, new_se_nacl->initiatorname);
1302 * Expected to be called with struct qla_hw_data->hardware_lock held
1304 static struct qla_tgt_sess *tcm_qla2xxx_find_sess_by_loop_id(
1305 scsi_qla_host_t *vha,
1306 const uint16_t loop_id)
1308 struct tcm_qla2xxx_lport *lport;
1309 struct se_node_acl *se_nacl;
1310 struct tcm_qla2xxx_nacl *nacl;
1311 struct tcm_qla2xxx_fc_loopid *fc_loopid;
1313 lport = vha->vha_tgt.target_lport_ptr;
1315 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1320 pr_debug("find_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id);
1322 fc_loopid = lport->lport_loopid_map + loop_id;
1323 se_nacl = fc_loopid->se_nacl;
1325 pr_debug("Unable to locate se_nacl by loop_id: 0x%04x\n",
1330 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
1332 if (!nacl->qla_tgt_sess) {
1333 pr_err("Unable to locate struct qla_tgt_sess\n");
1337 return nacl->qla_tgt_sess;
1341 * Expected to be called with struct qla_hw_data->hardware_lock held
1343 static void tcm_qla2xxx_set_sess_by_loop_id(
1344 struct tcm_qla2xxx_lport *lport,
1345 struct se_node_acl *new_se_nacl,
1346 struct tcm_qla2xxx_nacl *nacl,
1347 struct se_session *se_sess,
1348 struct qla_tgt_sess *qla_tgt_sess,
1351 struct se_node_acl *saved_nacl;
1352 struct tcm_qla2xxx_fc_loopid *fc_loopid;
1354 pr_debug("set_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id);
1356 fc_loopid = &((struct tcm_qla2xxx_fc_loopid *)
1357 lport->lport_loopid_map)[loop_id];
1359 saved_nacl = fc_loopid->se_nacl;
1361 pr_debug("Setting up new fc_loopid->se_nacl to new_se_nacl\n");
1362 fc_loopid->se_nacl = new_se_nacl;
1363 if (qla_tgt_sess->se_sess != se_sess)
1364 qla_tgt_sess->se_sess = se_sess;
1365 if (nacl->qla_tgt_sess != qla_tgt_sess)
1366 nacl->qla_tgt_sess = qla_tgt_sess;
1370 if (nacl->qla_tgt_sess) {
1371 if (new_se_nacl == NULL) {
1372 pr_debug("Clearing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1373 fc_loopid->se_nacl = NULL;
1374 nacl->qla_tgt_sess = NULL;
1378 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1379 fc_loopid->se_nacl = new_se_nacl;
1380 if (qla_tgt_sess->se_sess != se_sess)
1381 qla_tgt_sess->se_sess = se_sess;
1382 if (nacl->qla_tgt_sess != qla_tgt_sess)
1383 nacl->qla_tgt_sess = qla_tgt_sess;
1387 if (new_se_nacl == NULL) {
1388 pr_debug("Clearing fc_loopid->se_nacl\n");
1389 fc_loopid->se_nacl = NULL;
1393 pr_debug("Replacing existing fc_loopid->se_nacl w/o active nacl->qla_tgt_sess\n");
1394 fc_loopid->se_nacl = new_se_nacl;
1395 if (qla_tgt_sess->se_sess != se_sess)
1396 qla_tgt_sess->se_sess = se_sess;
1397 if (nacl->qla_tgt_sess != qla_tgt_sess)
1398 nacl->qla_tgt_sess = qla_tgt_sess;
1400 pr_debug("Setup nacl->qla_tgt_sess %p by loop_id for se_nacl: %p, initiatorname: %s\n",
1401 nacl->qla_tgt_sess, new_se_nacl, new_se_nacl->initiatorname);
1405 * Should always be called with qla_hw_data->hardware_lock held.
1407 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport *lport,
1408 struct tcm_qla2xxx_nacl *nacl, struct qla_tgt_sess *sess)
1410 struct se_session *se_sess = sess->se_sess;
1411 unsigned char be_sid[3];
1413 be_sid[0] = sess->s_id.b.domain;
1414 be_sid[1] = sess->s_id.b.area;
1415 be_sid[2] = sess->s_id.b.al_pa;
1417 tcm_qla2xxx_set_sess_by_s_id(lport, NULL, nacl, se_sess,
1419 tcm_qla2xxx_set_sess_by_loop_id(lport, NULL, nacl, se_sess,
1420 sess, sess->loop_id);
1423 static void tcm_qla2xxx_free_session(struct qla_tgt_sess *sess)
1425 struct qla_tgt *tgt = sess->tgt;
1426 struct qla_hw_data *ha = tgt->ha;
1427 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1428 struct se_session *se_sess;
1429 struct se_node_acl *se_nacl;
1430 struct tcm_qla2xxx_lport *lport;
1431 struct tcm_qla2xxx_nacl *nacl;
1433 BUG_ON(in_interrupt());
1435 se_sess = sess->se_sess;
1437 pr_err("struct qla_tgt_sess->se_sess is NULL\n");
1441 se_nacl = se_sess->se_node_acl;
1442 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
1444 lport = vha->vha_tgt.target_lport_ptr;
1446 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1450 target_wait_for_sess_cmds(se_sess);
1452 transport_deregister_session_configfs(sess->se_sess);
1453 transport_deregister_session(sess->se_sess);
1457 * Called via qlt_create_sess():ha->qla2x_tmpl->check_initiator_node_acl()
1458 * to locate struct se_node_acl
1460 static int tcm_qla2xxx_check_initiator_node_acl(
1461 scsi_qla_host_t *vha,
1462 unsigned char *fc_wwpn,
1467 struct qla_hw_data *ha = vha->hw;
1468 struct tcm_qla2xxx_lport *lport;
1469 struct tcm_qla2xxx_tpg *tpg;
1470 struct tcm_qla2xxx_nacl *nacl;
1471 struct se_portal_group *se_tpg;
1472 struct se_node_acl *se_nacl;
1473 struct se_session *se_sess;
1474 struct qla_tgt_sess *sess = qla_tgt_sess;
1475 unsigned char port_name[36];
1476 unsigned long flags;
1478 lport = vha->vha_tgt.target_lport_ptr;
1480 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1485 * Locate the TPG=1 reference..
1489 pr_err("Unable to lcoate struct tcm_qla2xxx_lport->tpg_1\n");
1492 se_tpg = &tpg->se_tpg;
1494 se_sess = transport_init_session();
1495 if (IS_ERR(se_sess)) {
1496 pr_err("Unable to initialize struct se_session\n");
1497 return PTR_ERR(se_sess);
1500 * Format the FCP Initiator port_name into colon seperated values to
1501 * match the format by tcm_qla2xxx explict ConfigFS NodeACLs.
1503 memset(&port_name, 0, 36);
1504 snprintf(port_name, 36, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1505 fc_wwpn[0], fc_wwpn[1], fc_wwpn[2], fc_wwpn[3], fc_wwpn[4],
1506 fc_wwpn[5], fc_wwpn[6], fc_wwpn[7]);
1508 * Locate our struct se_node_acl either from an explict NodeACL created
1509 * via ConfigFS, or via running in TPG demo mode.
1511 se_sess->se_node_acl = core_tpg_check_initiator_node_acl(se_tpg,
1513 if (!se_sess->se_node_acl) {
1514 transport_free_session(se_sess);
1517 se_nacl = se_sess->se_node_acl;
1518 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
1520 * And now setup the new se_nacl and session pointers into our HW lport
1521 * mappings for fabric S_ID and LOOP_ID.
1523 spin_lock_irqsave(&ha->hardware_lock, flags);
1524 tcm_qla2xxx_set_sess_by_s_id(lport, se_nacl, nacl, se_sess,
1525 qla_tgt_sess, s_id);
1526 tcm_qla2xxx_set_sess_by_loop_id(lport, se_nacl, nacl, se_sess,
1527 qla_tgt_sess, loop_id);
1528 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1530 * Finally register the new FC Nexus with TCM
1532 __transport_register_session(se_nacl->se_tpg, se_nacl, se_sess, sess);
1537 static void tcm_qla2xxx_update_sess(struct qla_tgt_sess *sess, port_id_t s_id,
1538 uint16_t loop_id, bool conf_compl_supported)
1540 struct qla_tgt *tgt = sess->tgt;
1541 struct qla_hw_data *ha = tgt->ha;
1542 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1543 struct tcm_qla2xxx_lport *lport = vha->vha_tgt.target_lport_ptr;
1544 struct se_node_acl *se_nacl = sess->se_sess->se_node_acl;
1545 struct tcm_qla2xxx_nacl *nacl = container_of(se_nacl,
1546 struct tcm_qla2xxx_nacl, se_node_acl);
1550 if (sess->loop_id != loop_id || sess->s_id.b24 != s_id.b24)
1551 pr_info("Updating session %p from port %8phC loop_id %d -> %d s_id %x:%x:%x -> %x:%x:%x\n",
1552 sess, sess->port_name,
1553 sess->loop_id, loop_id, sess->s_id.b.domain,
1554 sess->s_id.b.area, sess->s_id.b.al_pa, s_id.b.domain,
1555 s_id.b.area, s_id.b.al_pa);
1557 if (sess->loop_id != loop_id) {
1559 * Because we can shuffle loop IDs around and we
1560 * update different sessions non-atomically, we might
1561 * have overwritten this session's old loop ID
1562 * already, and we might end up overwriting some other
1563 * session that will be updated later. So we have to
1564 * be extra careful and we can't warn about those things...
1566 if (lport->lport_loopid_map[sess->loop_id].se_nacl == se_nacl)
1567 lport->lport_loopid_map[sess->loop_id].se_nacl = NULL;
1569 lport->lport_loopid_map[loop_id].se_nacl = se_nacl;
1571 sess->loop_id = loop_id;
1574 if (sess->s_id.b24 != s_id.b24) {
1575 key = (((u32) sess->s_id.b.domain << 16) |
1576 ((u32) sess->s_id.b.area << 8) |
1577 ((u32) sess->s_id.b.al_pa));
1579 if (btree_lookup32(&lport->lport_fcport_map, key))
1580 WARN(btree_remove32(&lport->lport_fcport_map, key) != se_nacl,
1581 "Found wrong se_nacl when updating s_id %x:%x:%x\n",
1582 sess->s_id.b.domain, sess->s_id.b.area, sess->s_id.b.al_pa);
1584 WARN(1, "No lport_fcport_map entry for s_id %x:%x:%x\n",
1585 sess->s_id.b.domain, sess->s_id.b.area, sess->s_id.b.al_pa);
1587 key = (((u32) s_id.b.domain << 16) |
1588 ((u32) s_id.b.area << 8) |
1589 ((u32) s_id.b.al_pa));
1591 if (btree_lookup32(&lport->lport_fcport_map, key)) {
1592 WARN(1, "Already have lport_fcport_map entry for s_id %x:%x:%x\n",
1593 s_id.b.domain, s_id.b.area, s_id.b.al_pa);
1594 btree_update32(&lport->lport_fcport_map, key, se_nacl);
1596 btree_insert32(&lport->lport_fcport_map, key, se_nacl, GFP_ATOMIC);
1600 nacl->nport_id = key;
1603 sess->conf_compl_supported = conf_compl_supported;
1607 * Calls into tcm_qla2xxx used by qla2xxx LLD I/O path.
1609 static struct qla_tgt_func_tmpl tcm_qla2xxx_template = {
1610 .handle_cmd = tcm_qla2xxx_handle_cmd,
1611 .handle_data = tcm_qla2xxx_handle_data,
1612 .handle_tmr = tcm_qla2xxx_handle_tmr,
1613 .free_cmd = tcm_qla2xxx_free_cmd,
1614 .free_mcmd = tcm_qla2xxx_free_mcmd,
1615 .free_session = tcm_qla2xxx_free_session,
1616 .update_sess = tcm_qla2xxx_update_sess,
1617 .check_initiator_node_acl = tcm_qla2xxx_check_initiator_node_acl,
1618 .find_sess_by_s_id = tcm_qla2xxx_find_sess_by_s_id,
1619 .find_sess_by_loop_id = tcm_qla2xxx_find_sess_by_loop_id,
1620 .clear_nacl_from_fcport_map = tcm_qla2xxx_clear_nacl_from_fcport_map,
1621 .put_sess = tcm_qla2xxx_put_sess,
1622 .shutdown_sess = tcm_qla2xxx_shutdown_sess,
1625 static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport *lport)
1629 rc = btree_init32(&lport->lport_fcport_map);
1631 pr_err("Unable to initialize lport->lport_fcport_map btree\n");
1635 lport->lport_loopid_map = vmalloc(sizeof(struct tcm_qla2xxx_fc_loopid) *
1637 if (!lport->lport_loopid_map) {
1638 pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n",
1639 sizeof(struct tcm_qla2xxx_fc_loopid) * 65536);
1640 btree_destroy32(&lport->lport_fcport_map);
1643 memset(lport->lport_loopid_map, 0, sizeof(struct tcm_qla2xxx_fc_loopid)
1645 pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n",
1646 sizeof(struct tcm_qla2xxx_fc_loopid) * 65536);
1650 static int tcm_qla2xxx_lport_register_cb(struct scsi_qla_host *vha,
1651 void *target_lport_ptr,
1652 u64 npiv_wwpn, u64 npiv_wwnn)
1654 struct qla_hw_data *ha = vha->hw;
1655 struct tcm_qla2xxx_lport *lport =
1656 (struct tcm_qla2xxx_lport *)target_lport_ptr;
1658 * Setup tgt_ops, local pointer to vha and target_lport_ptr
1660 ha->tgt.tgt_ops = &tcm_qla2xxx_template;
1661 vha->vha_tgt.target_lport_ptr = target_lport_ptr;
1662 lport->qla_vha = vha;
1667 static struct se_wwn *tcm_qla2xxx_make_lport(
1668 struct target_fabric_configfs *tf,
1669 struct config_group *group,
1672 struct tcm_qla2xxx_lport *lport;
1676 if (tcm_qla2xxx_parse_wwn(name, &wwpn, 1) < 0)
1677 return ERR_PTR(-EINVAL);
1679 lport = kzalloc(sizeof(struct tcm_qla2xxx_lport), GFP_KERNEL);
1681 pr_err("Unable to allocate struct tcm_qla2xxx_lport\n");
1682 return ERR_PTR(-ENOMEM);
1684 lport->lport_wwpn = wwpn;
1685 tcm_qla2xxx_format_wwn(&lport->lport_name[0], TCM_QLA2XXX_NAMELEN,
1687 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) wwpn);
1689 ret = tcm_qla2xxx_init_lport(lport);
1693 ret = qlt_lport_register(lport, wwpn, 0, 0,
1694 tcm_qla2xxx_lport_register_cb);
1698 return &lport->lport_wwn;
1700 vfree(lport->lport_loopid_map);
1701 btree_destroy32(&lport->lport_fcport_map);
1704 return ERR_PTR(ret);
1707 static void tcm_qla2xxx_drop_lport(struct se_wwn *wwn)
1709 struct tcm_qla2xxx_lport *lport = container_of(wwn,
1710 struct tcm_qla2xxx_lport, lport_wwn);
1711 struct scsi_qla_host *vha = lport->qla_vha;
1712 struct se_node_acl *node;
1716 * Call into qla2x_target.c LLD logic to complete the
1717 * shutdown of struct qla_tgt after the call to
1718 * qlt_stop_phase1() from tcm_qla2xxx_drop_tpg() above..
1720 if (vha->vha_tgt.qla_tgt && !vha->vha_tgt.qla_tgt->tgt_stopped)
1721 qlt_stop_phase2(vha->vha_tgt.qla_tgt);
1723 qlt_lport_deregister(vha);
1725 vfree(lport->lport_loopid_map);
1726 btree_for_each_safe32(&lport->lport_fcport_map, key, node)
1727 btree_remove32(&lport->lport_fcport_map, key);
1728 btree_destroy32(&lport->lport_fcport_map);
1732 static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host *base_vha,
1733 void *target_lport_ptr,
1734 u64 npiv_wwpn, u64 npiv_wwnn)
1736 struct fc_vport *vport;
1737 struct Scsi_Host *sh = base_vha->host;
1738 struct scsi_qla_host *npiv_vha;
1739 struct tcm_qla2xxx_lport *lport =
1740 (struct tcm_qla2xxx_lport *)target_lport_ptr;
1741 struct tcm_qla2xxx_lport *base_lport =
1742 (struct tcm_qla2xxx_lport *)base_vha->vha_tgt.target_lport_ptr;
1743 struct tcm_qla2xxx_tpg *base_tpg;
1744 struct fc_vport_identifiers vport_id;
1746 if (!qla_tgt_mode_enabled(base_vha)) {
1747 pr_err("qla2xxx base_vha not enabled for target mode\n");
1751 if (!base_lport || !base_lport->tpg_1 ||
1752 !atomic_read(&base_lport->tpg_1->lport_tpg_enabled)) {
1753 pr_err("qla2xxx base_lport or tpg_1 not available\n");
1756 base_tpg = base_lport->tpg_1;
1758 memset(&vport_id, 0, sizeof(vport_id));
1759 vport_id.port_name = npiv_wwpn;
1760 vport_id.node_name = npiv_wwnn;
1761 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
1762 vport_id.vport_type = FC_PORTTYPE_NPIV;
1763 vport_id.disable = false;
1765 vport = fc_vport_create(sh, 0, &vport_id);
1767 pr_err("fc_vport_create failed for qla2xxx_npiv\n");
1771 * Setup local pointer to NPIV vhba + target_lport_ptr
1773 npiv_vha = (struct scsi_qla_host *)vport->dd_data;
1774 npiv_vha->vha_tgt.target_lport_ptr = target_lport_ptr;
1775 lport->qla_vha = npiv_vha;
1776 scsi_host_get(npiv_vha->host);
1781 static struct se_wwn *tcm_qla2xxx_npiv_make_lport(
1782 struct target_fabric_configfs *tf,
1783 struct config_group *group,
1786 struct tcm_qla2xxx_lport *lport;
1787 u64 phys_wwpn, npiv_wwpn, npiv_wwnn;
1791 snprintf(tmp, 128, "%s", name);
1793 p = strchr(tmp, '@');
1795 pr_err("Unable to locate NPIV '@' seperator\n");
1796 return ERR_PTR(-EINVAL);
1800 if (tcm_qla2xxx_parse_wwn(tmp, &phys_wwpn, 1) < 0)
1801 return ERR_PTR(-EINVAL);
1803 if (tcm_qla2xxx_npiv_parse_wwn(p, strlen(p)+1,
1804 &npiv_wwpn, &npiv_wwnn) < 0)
1805 return ERR_PTR(-EINVAL);
1807 lport = kzalloc(sizeof(struct tcm_qla2xxx_lport), GFP_KERNEL);
1809 pr_err("Unable to allocate struct tcm_qla2xxx_lport for NPIV\n");
1810 return ERR_PTR(-ENOMEM);
1812 lport->lport_npiv_wwpn = npiv_wwpn;
1813 lport->lport_npiv_wwnn = npiv_wwnn;
1814 tcm_qla2xxx_npiv_format_wwn(&lport->lport_npiv_name[0],
1815 TCM_QLA2XXX_NAMELEN, npiv_wwpn, npiv_wwnn);
1816 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) npiv_wwpn);
1818 ret = tcm_qla2xxx_init_lport(lport);
1822 ret = qlt_lport_register(lport, phys_wwpn, npiv_wwpn, npiv_wwnn,
1823 tcm_qla2xxx_lport_register_npiv_cb);
1827 return &lport->lport_wwn;
1829 vfree(lport->lport_loopid_map);
1830 btree_destroy32(&lport->lport_fcport_map);
1833 return ERR_PTR(ret);
1836 static void tcm_qla2xxx_npiv_drop_lport(struct se_wwn *wwn)
1838 struct tcm_qla2xxx_lport *lport = container_of(wwn,
1839 struct tcm_qla2xxx_lport, lport_wwn);
1840 struct scsi_qla_host *npiv_vha = lport->qla_vha;
1841 struct qla_hw_data *ha = npiv_vha->hw;
1842 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1844 scsi_host_put(npiv_vha->host);
1846 * Notify libfc that we want to release the vha->fc_vport
1848 fc_vport_terminate(npiv_vha->fc_vport);
1849 scsi_host_put(base_vha->host);
1854 static ssize_t tcm_qla2xxx_wwn_show_attr_version(
1855 struct target_fabric_configfs *tf,
1858 return sprintf(page,
1859 "TCM QLOGIC QLA2XXX NPIV capable fabric module %s on %s/%s on "
1860 UTS_RELEASE"\n", TCM_QLA2XXX_VERSION, utsname()->sysname,
1861 utsname()->machine);
1864 TF_WWN_ATTR_RO(tcm_qla2xxx, version);
1866 static struct configfs_attribute *tcm_qla2xxx_wwn_attrs[] = {
1867 &tcm_qla2xxx_wwn_version.attr,
1871 static struct target_core_fabric_ops tcm_qla2xxx_ops = {
1872 .get_fabric_name = tcm_qla2xxx_get_fabric_name,
1873 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident,
1874 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn,
1875 .tpg_get_tag = tcm_qla2xxx_get_tag,
1876 .tpg_get_default_depth = tcm_qla2xxx_get_default_depth,
1877 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id,
1878 .tpg_get_pr_transport_id_len = tcm_qla2xxx_get_pr_transport_id_len,
1879 .tpg_parse_pr_out_transport_id = tcm_qla2xxx_parse_pr_out_transport_id,
1880 .tpg_check_demo_mode = tcm_qla2xxx_check_demo_mode,
1881 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_demo_mode_cache,
1882 .tpg_check_demo_mode_write_protect =
1883 tcm_qla2xxx_check_demo_write_protect,
1884 .tpg_check_prod_mode_write_protect =
1885 tcm_qla2xxx_check_prod_write_protect,
1886 .tpg_check_demo_mode_login_only = tcm_qla2xxx_check_demo_mode_login_only,
1887 .tpg_alloc_fabric_acl = tcm_qla2xxx_alloc_fabric_acl,
1888 .tpg_release_fabric_acl = tcm_qla2xxx_release_fabric_acl,
1889 .tpg_get_inst_index = tcm_qla2xxx_tpg_get_inst_index,
1890 .check_stop_free = tcm_qla2xxx_check_stop_free,
1891 .release_cmd = tcm_qla2xxx_release_cmd,
1892 .put_session = tcm_qla2xxx_put_session,
1893 .shutdown_session = tcm_qla2xxx_shutdown_session,
1894 .close_session = tcm_qla2xxx_close_session,
1895 .sess_get_index = tcm_qla2xxx_sess_get_index,
1896 .sess_get_initiator_sid = NULL,
1897 .write_pending = tcm_qla2xxx_write_pending,
1898 .write_pending_status = tcm_qla2xxx_write_pending_status,
1899 .set_default_node_attributes = tcm_qla2xxx_set_default_node_attrs,
1900 .get_task_tag = tcm_qla2xxx_get_task_tag,
1901 .get_cmd_state = tcm_qla2xxx_get_cmd_state,
1902 .queue_data_in = tcm_qla2xxx_queue_data_in,
1903 .queue_status = tcm_qla2xxx_queue_status,
1904 .queue_tm_rsp = tcm_qla2xxx_queue_tm_rsp,
1906 * Setup function pointers for generic logic in
1907 * target_core_fabric_configfs.c
1909 .fabric_make_wwn = tcm_qla2xxx_make_lport,
1910 .fabric_drop_wwn = tcm_qla2xxx_drop_lport,
1911 .fabric_make_tpg = tcm_qla2xxx_make_tpg,
1912 .fabric_drop_tpg = tcm_qla2xxx_drop_tpg,
1913 .fabric_post_link = NULL,
1914 .fabric_pre_unlink = NULL,
1915 .fabric_make_np = NULL,
1916 .fabric_drop_np = NULL,
1917 .fabric_make_nodeacl = tcm_qla2xxx_make_nodeacl,
1918 .fabric_drop_nodeacl = tcm_qla2xxx_drop_nodeacl,
1921 static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
1922 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name,
1923 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident,
1924 .tpg_get_wwn = tcm_qla2xxx_npiv_get_fabric_wwn,
1925 .tpg_get_tag = tcm_qla2xxx_get_tag,
1926 .tpg_get_default_depth = tcm_qla2xxx_get_default_depth,
1927 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id,
1928 .tpg_get_pr_transport_id_len = tcm_qla2xxx_get_pr_transport_id_len,
1929 .tpg_parse_pr_out_transport_id = tcm_qla2xxx_parse_pr_out_transport_id,
1930 .tpg_check_demo_mode = tcm_qla2xxx_check_demo_mode,
1931 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_demo_mode_cache,
1932 .tpg_check_demo_mode_write_protect = tcm_qla2xxx_check_demo_mode,
1933 .tpg_check_prod_mode_write_protect =
1934 tcm_qla2xxx_check_prod_write_protect,
1935 .tpg_check_demo_mode_login_only = tcm_qla2xxx_check_demo_mode_login_only,
1936 .tpg_alloc_fabric_acl = tcm_qla2xxx_alloc_fabric_acl,
1937 .tpg_release_fabric_acl = tcm_qla2xxx_release_fabric_acl,
1938 .tpg_get_inst_index = tcm_qla2xxx_tpg_get_inst_index,
1939 .check_stop_free = tcm_qla2xxx_check_stop_free,
1940 .release_cmd = tcm_qla2xxx_release_cmd,
1941 .put_session = tcm_qla2xxx_put_session,
1942 .shutdown_session = tcm_qla2xxx_shutdown_session,
1943 .close_session = tcm_qla2xxx_close_session,
1944 .sess_get_index = tcm_qla2xxx_sess_get_index,
1945 .sess_get_initiator_sid = NULL,
1946 .write_pending = tcm_qla2xxx_write_pending,
1947 .write_pending_status = tcm_qla2xxx_write_pending_status,
1948 .set_default_node_attributes = tcm_qla2xxx_set_default_node_attrs,
1949 .get_task_tag = tcm_qla2xxx_get_task_tag,
1950 .get_cmd_state = tcm_qla2xxx_get_cmd_state,
1951 .queue_data_in = tcm_qla2xxx_queue_data_in,
1952 .queue_status = tcm_qla2xxx_queue_status,
1953 .queue_tm_rsp = tcm_qla2xxx_queue_tm_rsp,
1955 * Setup function pointers for generic logic in
1956 * target_core_fabric_configfs.c
1958 .fabric_make_wwn = tcm_qla2xxx_npiv_make_lport,
1959 .fabric_drop_wwn = tcm_qla2xxx_npiv_drop_lport,
1960 .fabric_make_tpg = tcm_qla2xxx_npiv_make_tpg,
1961 .fabric_drop_tpg = tcm_qla2xxx_drop_tpg,
1962 .fabric_post_link = NULL,
1963 .fabric_pre_unlink = NULL,
1964 .fabric_make_np = NULL,
1965 .fabric_drop_np = NULL,
1966 .fabric_make_nodeacl = tcm_qla2xxx_make_nodeacl,
1967 .fabric_drop_nodeacl = tcm_qla2xxx_drop_nodeacl,
1970 static int tcm_qla2xxx_register_configfs(void)
1972 struct target_fabric_configfs *fabric, *npiv_fabric;
1975 pr_debug("TCM QLOGIC QLA2XXX fabric module %s on %s/%s on "
1976 UTS_RELEASE"\n", TCM_QLA2XXX_VERSION, utsname()->sysname,
1977 utsname()->machine);
1979 * Register the top level struct config_item_type with TCM core
1981 fabric = target_fabric_configfs_init(THIS_MODULE, "qla2xxx");
1982 if (IS_ERR(fabric)) {
1983 pr_err("target_fabric_configfs_init() failed\n");
1984 return PTR_ERR(fabric);
1987 * Setup fabric->tf_ops from our local tcm_qla2xxx_ops
1989 fabric->tf_ops = tcm_qla2xxx_ops;
1991 * Setup default attribute lists for various fabric->tf_cit_tmpl
1993 fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs;
1994 fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = tcm_qla2xxx_tpg_attrs;
1995 fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs =
1996 tcm_qla2xxx_tpg_attrib_attrs;
1997 fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
1998 fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
1999 fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL;
2000 fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
2001 fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
2002 fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
2004 * Register the fabric for use within TCM
2006 ret = target_fabric_configfs_register(fabric);
2008 pr_err("target_fabric_configfs_register() failed for TCM_QLA2XXX\n");
2012 * Setup our local pointer to *fabric
2014 tcm_qla2xxx_fabric_configfs = fabric;
2015 pr_debug("TCM_QLA2XXX[0] - Set fabric -> tcm_qla2xxx_fabric_configfs\n");
2018 * Register the top level struct config_item_type for NPIV with TCM core
2020 npiv_fabric = target_fabric_configfs_init(THIS_MODULE, "qla2xxx_npiv");
2021 if (IS_ERR(npiv_fabric)) {
2022 pr_err("target_fabric_configfs_init() failed\n");
2023 ret = PTR_ERR(npiv_fabric);
2027 * Setup fabric->tf_ops from our local tcm_qla2xxx_npiv_ops
2029 npiv_fabric->tf_ops = tcm_qla2xxx_npiv_ops;
2031 * Setup default attribute lists for various npiv_fabric->tf_cit_tmpl
2033 npiv_fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs;
2034 npiv_fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs =
2035 tcm_qla2xxx_npiv_tpg_attrs;
2036 npiv_fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
2037 npiv_fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
2038 npiv_fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
2039 npiv_fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL;
2040 npiv_fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
2041 npiv_fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
2042 npiv_fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
2044 * Register the npiv_fabric for use within TCM
2046 ret = target_fabric_configfs_register(npiv_fabric);
2048 pr_err("target_fabric_configfs_register() failed for TCM_QLA2XXX\n");
2052 * Setup our local pointer to *npiv_fabric
2054 tcm_qla2xxx_npiv_fabric_configfs = npiv_fabric;
2055 pr_debug("TCM_QLA2XXX[0] - Set fabric -> tcm_qla2xxx_npiv_fabric_configfs\n");
2057 tcm_qla2xxx_free_wq = alloc_workqueue("tcm_qla2xxx_free",
2059 if (!tcm_qla2xxx_free_wq) {
2061 goto out_fabric_npiv;
2064 tcm_qla2xxx_cmd_wq = alloc_workqueue("tcm_qla2xxx_cmd", 0, 0);
2065 if (!tcm_qla2xxx_cmd_wq) {
2073 destroy_workqueue(tcm_qla2xxx_free_wq);
2075 target_fabric_configfs_deregister(tcm_qla2xxx_npiv_fabric_configfs);
2077 target_fabric_configfs_deregister(tcm_qla2xxx_fabric_configfs);
2081 static void tcm_qla2xxx_deregister_configfs(void)
2083 destroy_workqueue(tcm_qla2xxx_cmd_wq);
2084 destroy_workqueue(tcm_qla2xxx_free_wq);
2086 target_fabric_configfs_deregister(tcm_qla2xxx_fabric_configfs);
2087 tcm_qla2xxx_fabric_configfs = NULL;
2088 pr_debug("TCM_QLA2XXX[0] - Cleared tcm_qla2xxx_fabric_configfs\n");
2090 target_fabric_configfs_deregister(tcm_qla2xxx_npiv_fabric_configfs);
2091 tcm_qla2xxx_npiv_fabric_configfs = NULL;
2092 pr_debug("TCM_QLA2XXX[0] - Cleared tcm_qla2xxx_npiv_fabric_configfs\n");
2095 static int __init tcm_qla2xxx_init(void)
2099 ret = tcm_qla2xxx_register_configfs();
2106 static void __exit tcm_qla2xxx_exit(void)
2108 tcm_qla2xxx_deregister_configfs();
2111 MODULE_DESCRIPTION("TCM QLA2XXX series NPIV enabled fabric driver");
2112 MODULE_LICENSE("GPL");
2113 module_init(tcm_qla2xxx_init);
2114 module_exit(tcm_qla2xxx_exit);