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 static struct workqueue_struct
*tcm_qla2xxx_free_wq
;
54 static struct workqueue_struct
*tcm_qla2xxx_cmd_wq
;
56 static const struct target_core_fabric_ops tcm_qla2xxx_ops
;
57 static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops
;
61 * If strict, we require lower-case hex and colon separators to be sure
62 * the name is the same as what would be generated by ft_format_wwn()
63 * so the name and wwn are mapped one-to-one.
65 static ssize_t
tcm_qla2xxx_parse_wwn(const char *name
, u64
*wwn
, int strict
)
75 for (cp
= name
; cp
< &name
[TCM_QLA2XXX_NAMELEN
- 1]; cp
++) {
77 if (c
== '\n' && cp
[1] == '\0')
79 if (strict
&& pos
++ == 2 && byte
++ < 7) {
88 if (strict
&& byte
!= 8)
95 else if (isxdigit(c
) && (islower(c
) || !strict
))
96 nibble
= tolower(c
) - 'a' + 10;
99 *wwn
= (*wwn
<< 4) | nibble
;
103 pr_debug("err %u len %zu pos %u byte %u\n",
104 err
, cp
- name
, pos
, byte
);
108 static ssize_t
tcm_qla2xxx_format_wwn(char *buf
, size_t len
, u64 wwn
)
112 put_unaligned_be64(wwn
, b
);
113 return snprintf(buf
, len
,
114 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
115 b
[0], b
[1], b
[2], b
[3], b
[4], b
[5], b
[6], b
[7]);
118 static char *tcm_qla2xxx_get_fabric_name(void)
124 * From drivers/scsi/scsi_transport_fc.c:fc_parse_wwn
126 static int tcm_qla2xxx_npiv_extract_wwn(const char *ns
, u64
*nm
)
131 memset(wwn
, 0, sizeof(wwn
));
133 /* Validate and store the new name */
134 for (i
= 0, j
= 0; i
< 16; i
++) {
137 value
= hex_to_bin(*ns
++);
139 j
= (j
<< 4) | value
;
149 *nm
= wwn_to_u64(wwn
);
154 * This parsing logic follows drivers/scsi/scsi_transport_fc.c:
155 * store_fc_host_vport_create()
157 static int tcm_qla2xxx_npiv_parse_wwn(
163 unsigned int cnt
= count
;
169 /* count may include a LF at end of string */
170 if (name
[cnt
-1] == '\n' || name
[cnt
-1] == 0)
173 /* validate we have enough characters for WWPN */
174 if ((cnt
!= (16+1+16)) || (name
[16] != ':'))
177 rc
= tcm_qla2xxx_npiv_extract_wwn(&name
[0], wwpn
);
181 rc
= tcm_qla2xxx_npiv_extract_wwn(&name
[17], wwnn
);
188 static char *tcm_qla2xxx_npiv_get_fabric_name(void)
190 return "qla2xxx_npiv";
193 static char *tcm_qla2xxx_get_fabric_wwn(struct se_portal_group
*se_tpg
)
195 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
196 struct tcm_qla2xxx_tpg
, se_tpg
);
197 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
199 return lport
->lport_naa_name
;
202 static u16
tcm_qla2xxx_get_tag(struct se_portal_group
*se_tpg
)
204 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
205 struct tcm_qla2xxx_tpg
, se_tpg
);
206 return tpg
->lport_tpgt
;
209 static int tcm_qla2xxx_check_demo_mode(struct se_portal_group
*se_tpg
)
211 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
212 struct tcm_qla2xxx_tpg
, se_tpg
);
214 return tpg
->tpg_attrib
.generate_node_acls
;
217 static int tcm_qla2xxx_check_demo_mode_cache(struct se_portal_group
*se_tpg
)
219 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
220 struct tcm_qla2xxx_tpg
, se_tpg
);
222 return tpg
->tpg_attrib
.cache_dynamic_acls
;
225 static int tcm_qla2xxx_check_demo_write_protect(struct se_portal_group
*se_tpg
)
227 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
228 struct tcm_qla2xxx_tpg
, se_tpg
);
230 return tpg
->tpg_attrib
.demo_mode_write_protect
;
233 static int tcm_qla2xxx_check_prod_write_protect(struct se_portal_group
*se_tpg
)
235 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
236 struct tcm_qla2xxx_tpg
, se_tpg
);
238 return tpg
->tpg_attrib
.prod_mode_write_protect
;
241 static int tcm_qla2xxx_check_demo_mode_login_only(struct se_portal_group
*se_tpg
)
243 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
244 struct tcm_qla2xxx_tpg
, se_tpg
);
246 return tpg
->tpg_attrib
.demo_mode_login_only
;
249 static int tcm_qla2xxx_check_prot_fabric_only(struct se_portal_group
*se_tpg
)
251 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
252 struct tcm_qla2xxx_tpg
, se_tpg
);
254 return tpg
->tpg_attrib
.fabric_prot_type
;
257 static u32
tcm_qla2xxx_tpg_get_inst_index(struct se_portal_group
*se_tpg
)
259 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
260 struct tcm_qla2xxx_tpg
, se_tpg
);
262 return tpg
->lport_tpgt
;
265 static void tcm_qla2xxx_complete_mcmd(struct work_struct
*work
)
267 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(work
,
268 struct qla_tgt_mgmt_cmd
, free_work
);
270 transport_generic_free_cmd(&mcmd
->se_cmd
, 0);
274 * Called from qla_target_template->free_mcmd(), and will call
275 * tcm_qla2xxx_release_cmd() via normal struct target_core_fabric_ops
276 * release callback. qla_hw_data->hardware_lock is expected to be held
278 static void tcm_qla2xxx_free_mcmd(struct qla_tgt_mgmt_cmd
*mcmd
)
280 INIT_WORK(&mcmd
->free_work
, tcm_qla2xxx_complete_mcmd
);
281 queue_work(tcm_qla2xxx_free_wq
, &mcmd
->free_work
);
284 static void tcm_qla2xxx_complete_free(struct work_struct
*work
)
286 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
290 WARN_ON(cmd
->cmd_flags
& BIT_16
);
292 cmd
->cmd_flags
|= BIT_16
;
293 transport_generic_free_cmd(&cmd
->se_cmd
, 0);
297 * Called from qla_target_template->free_cmd(), and will call
298 * tcm_qla2xxx_release_cmd via normal struct target_core_fabric_ops
299 * release callback. qla_hw_data->hardware_lock is expected to be held
301 static void tcm_qla2xxx_free_cmd(struct qla_tgt_cmd
*cmd
)
304 INIT_WORK(&cmd
->work
, tcm_qla2xxx_complete_free
);
305 queue_work(tcm_qla2xxx_free_wq
, &cmd
->work
);
309 * Called from struct target_core_fabric_ops->check_stop_free() context
311 static int tcm_qla2xxx_check_stop_free(struct se_cmd
*se_cmd
)
313 struct qla_tgt_cmd
*cmd
;
315 if ((se_cmd
->se_cmd_flags
& SCF_SCSI_TMR_CDB
) == 0) {
316 cmd
= container_of(se_cmd
, struct qla_tgt_cmd
, se_cmd
);
317 cmd
->cmd_flags
|= BIT_14
;
320 return target_put_sess_cmd(se_cmd
);
323 /* tcm_qla2xxx_release_cmd - Callback from TCM Core to release underlying
324 * fabric descriptor @se_cmd command to release
326 static void tcm_qla2xxx_release_cmd(struct se_cmd
*se_cmd
)
328 struct qla_tgt_cmd
*cmd
;
330 if (se_cmd
->se_cmd_flags
& SCF_SCSI_TMR_CDB
) {
331 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(se_cmd
,
332 struct qla_tgt_mgmt_cmd
, se_cmd
);
337 cmd
= container_of(se_cmd
, struct qla_tgt_cmd
, se_cmd
);
341 static int tcm_qla2xxx_shutdown_session(struct se_session
*se_sess
)
343 struct qla_tgt_sess
*sess
= se_sess
->fabric_sess_ptr
;
344 struct scsi_qla_host
*vha
;
350 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
351 target_sess_cmd_list_set_waiting(se_sess
);
352 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
357 static void tcm_qla2xxx_close_session(struct se_session
*se_sess
)
359 struct qla_tgt_sess
*sess
= se_sess
->fabric_sess_ptr
;
360 struct scsi_qla_host
*vha
;
366 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
367 qlt_unreg_sess(sess
);
368 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
371 static u32
tcm_qla2xxx_sess_get_index(struct se_session
*se_sess
)
376 static int tcm_qla2xxx_write_pending(struct se_cmd
*se_cmd
)
378 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
379 struct qla_tgt_cmd
, se_cmd
);
381 cmd
->bufflen
= se_cmd
->data_length
;
382 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
384 cmd
->sg_cnt
= se_cmd
->t_data_nents
;
385 cmd
->sg
= se_cmd
->t_data_sg
;
387 cmd
->prot_sg_cnt
= se_cmd
->t_prot_nents
;
388 cmd
->prot_sg
= se_cmd
->t_prot_sg
;
389 cmd
->blk_sz
= se_cmd
->se_dev
->dev_attrib
.block_size
;
393 * qla_target.c:qlt_rdy_to_xfer() will call pci_map_sg() to setup
394 * the SGL mappings into PCIe memory for incoming FCP WRITE data.
396 return qlt_rdy_to_xfer(cmd
);
399 static int tcm_qla2xxx_write_pending_status(struct se_cmd
*se_cmd
)
403 * Check for WRITE_PENDING status to determine if we need to wait for
404 * CTIO aborts to be posted via hardware in tcm_qla2xxx_handle_data().
406 spin_lock_irqsave(&se_cmd
->t_state_lock
, flags
);
407 if (se_cmd
->t_state
== TRANSPORT_WRITE_PENDING
||
408 se_cmd
->t_state
== TRANSPORT_COMPLETE_QF_WP
) {
409 spin_unlock_irqrestore(&se_cmd
->t_state_lock
, flags
);
410 wait_for_completion_timeout(&se_cmd
->t_transport_stop_comp
,
414 spin_unlock_irqrestore(&se_cmd
->t_state_lock
, flags
);
419 static void tcm_qla2xxx_set_default_node_attrs(struct se_node_acl
*nacl
)
424 static u32
tcm_qla2xxx_get_task_tag(struct se_cmd
*se_cmd
)
426 struct qla_tgt_cmd
*cmd
;
428 /* check for task mgmt cmd */
429 if (se_cmd
->se_cmd_flags
& SCF_SCSI_TMR_CDB
)
432 cmd
= container_of(se_cmd
, struct qla_tgt_cmd
, se_cmd
);
437 static int tcm_qla2xxx_get_cmd_state(struct se_cmd
*se_cmd
)
443 * Called from process context in qla_target.c:qlt_do_work() code
445 static int tcm_qla2xxx_handle_cmd(scsi_qla_host_t
*vha
, struct qla_tgt_cmd
*cmd
,
446 unsigned char *cdb
, uint32_t data_length
, int fcp_task_attr
,
447 int data_dir
, int bidi
)
449 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
450 struct se_session
*se_sess
;
451 struct qla_tgt_sess
*sess
;
452 int flags
= TARGET_SCF_ACK_KREF
;
455 flags
|= TARGET_SCF_BIDI_OP
;
459 pr_err("Unable to locate struct qla_tgt_sess from qla_tgt_cmd\n");
463 se_sess
= sess
->se_sess
;
465 pr_err("Unable to locate active struct se_session\n");
469 return target_submit_cmd(se_cmd
, se_sess
, cdb
, &cmd
->sense_buffer
[0],
470 cmd
->unpacked_lun
, data_length
, fcp_task_attr
,
474 static void tcm_qla2xxx_handle_data_work(struct work_struct
*work
)
476 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
479 * Ensure that the complete FCP WRITE payload has been received.
480 * Otherwise return an exception via CHECK_CONDITION status.
483 cmd
->cmd_flags
|= BIT_11
;
484 if (!cmd
->write_data_transferred
) {
486 * Check if se_cmd has already been aborted via LUN_RESET, and
487 * waiting upon completion in tcm_qla2xxx_write_pending_status()
489 if (cmd
->se_cmd
.transport_state
& CMD_T_ABORTED
) {
490 complete(&cmd
->se_cmd
.t_transport_stop_comp
);
494 if (cmd
->se_cmd
.pi_err
)
495 transport_generic_request_failure(&cmd
->se_cmd
,
498 transport_generic_request_failure(&cmd
->se_cmd
,
499 TCM_CHECK_CONDITION_ABORT_CMD
);
504 return target_execute_cmd(&cmd
->se_cmd
);
508 * Called from qla_target.c:qlt_do_ctio_completion()
510 static void tcm_qla2xxx_handle_data(struct qla_tgt_cmd
*cmd
)
512 cmd
->cmd_flags
|= BIT_10
;
514 INIT_WORK(&cmd
->work
, tcm_qla2xxx_handle_data_work
);
515 queue_work(tcm_qla2xxx_free_wq
, &cmd
->work
);
518 static void tcm_qla2xxx_handle_dif_work(struct work_struct
*work
)
520 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
522 /* take an extra kref to prevent cmd free too early.
523 * need to wait for SCSI status/check condition to
524 * finish responding generate by transport_generic_request_failure.
526 kref_get(&cmd
->se_cmd
.cmd_kref
);
527 transport_generic_request_failure(&cmd
->se_cmd
, cmd
->se_cmd
.pi_err
);
531 * Called from qla_target.c:qlt_do_ctio_completion()
533 static void tcm_qla2xxx_handle_dif_err(struct qla_tgt_cmd
*cmd
)
535 INIT_WORK(&cmd
->work
, tcm_qla2xxx_handle_dif_work
);
536 queue_work(tcm_qla2xxx_free_wq
, &cmd
->work
);
540 * Called from qla_target.c:qlt_issue_task_mgmt()
542 static int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd
*mcmd
, uint32_t lun
,
543 uint8_t tmr_func
, uint32_t tag
)
545 struct qla_tgt_sess
*sess
= mcmd
->sess
;
546 struct se_cmd
*se_cmd
= &mcmd
->se_cmd
;
548 return target_submit_tmr(se_cmd
, sess
->se_sess
, NULL
, lun
, mcmd
,
549 tmr_func
, GFP_ATOMIC
, tag
, TARGET_SCF_ACK_KREF
);
552 static int tcm_qla2xxx_queue_data_in(struct se_cmd
*se_cmd
)
554 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
555 struct qla_tgt_cmd
, se_cmd
);
557 cmd
->cmd_flags
|= BIT_4
;
558 cmd
->bufflen
= se_cmd
->data_length
;
559 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
560 cmd
->aborted
= (se_cmd
->transport_state
& CMD_T_ABORTED
);
562 cmd
->sg_cnt
= se_cmd
->t_data_nents
;
563 cmd
->sg
= se_cmd
->t_data_sg
;
565 cmd
->cmd_flags
|= BIT_3
;
567 cmd
->prot_sg_cnt
= se_cmd
->t_prot_nents
;
568 cmd
->prot_sg
= se_cmd
->t_prot_sg
;
569 cmd
->blk_sz
= se_cmd
->se_dev
->dev_attrib
.block_size
;
573 * Now queue completed DATA_IN the qla2xxx LLD and response ring
575 return qlt_xmit_response(cmd
, QLA_TGT_XMIT_DATA
|QLA_TGT_XMIT_STATUS
,
576 se_cmd
->scsi_status
);
579 static int tcm_qla2xxx_queue_status(struct se_cmd
*se_cmd
)
581 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
582 struct qla_tgt_cmd
, se_cmd
);
583 int xmit_type
= QLA_TGT_XMIT_STATUS
;
585 cmd
->bufflen
= se_cmd
->data_length
;
589 cmd
->dma_data_direction
= target_reverse_dma_direction(se_cmd
);
590 cmd
->aborted
= (se_cmd
->transport_state
& CMD_T_ABORTED
);
591 if (cmd
->cmd_flags
& BIT_5
) {
592 pr_crit("Bit_5 already set for cmd = %p.\n", cmd
);
595 cmd
->cmd_flags
|= BIT_5
;
597 if (se_cmd
->data_direction
== DMA_FROM_DEVICE
) {
599 * For FCP_READ with CHECK_CONDITION status, clear cmd->bufflen
600 * for qla_tgt_xmit_response LLD code
602 if (se_cmd
->se_cmd_flags
& SCF_OVERFLOW_BIT
) {
603 se_cmd
->se_cmd_flags
&= ~SCF_OVERFLOW_BIT
;
604 se_cmd
->residual_count
= 0;
606 se_cmd
->se_cmd_flags
|= SCF_UNDERFLOW_BIT
;
607 se_cmd
->residual_count
+= se_cmd
->data_length
;
612 * Now queue status response to qla2xxx LLD code and response ring
614 return qlt_xmit_response(cmd
, xmit_type
, se_cmd
->scsi_status
);
617 static void tcm_qla2xxx_queue_tm_rsp(struct se_cmd
*se_cmd
)
619 struct se_tmr_req
*se_tmr
= se_cmd
->se_tmr_req
;
620 struct qla_tgt_mgmt_cmd
*mcmd
= container_of(se_cmd
,
621 struct qla_tgt_mgmt_cmd
, se_cmd
);
623 pr_debug("queue_tm_rsp: mcmd: %p func: 0x%02x response: 0x%02x\n",
624 mcmd
, se_tmr
->function
, se_tmr
->response
);
626 * Do translation between TCM TM response codes and
627 * QLA2xxx FC TM response codes.
629 switch (se_tmr
->response
) {
630 case TMR_FUNCTION_COMPLETE
:
631 mcmd
->fc_tm_rsp
= FC_TM_SUCCESS
;
633 case TMR_TASK_DOES_NOT_EXIST
:
634 mcmd
->fc_tm_rsp
= FC_TM_BAD_CMD
;
636 case TMR_FUNCTION_REJECTED
:
637 mcmd
->fc_tm_rsp
= FC_TM_REJECT
;
639 case TMR_LUN_DOES_NOT_EXIST
:
641 mcmd
->fc_tm_rsp
= FC_TM_FAILED
;
645 * Queue the TM response to QLA2xxx LLD to build a
646 * CTIO response packet.
648 qlt_xmit_tm_rsp(mcmd
);
651 static void tcm_qla2xxx_aborted_task(struct se_cmd
*se_cmd
)
653 struct qla_tgt_cmd
*cmd
= container_of(se_cmd
,
654 struct qla_tgt_cmd
, se_cmd
);
655 struct scsi_qla_host
*vha
= cmd
->vha
;
656 struct qla_hw_data
*ha
= vha
->hw
;
661 pci_unmap_sg(ha
->pdev
, cmd
->sg
, cmd
->sg_cnt
, cmd
->dma_data_direction
);
665 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport
*,
666 struct tcm_qla2xxx_nacl
*, struct qla_tgt_sess
*);
668 * Expected to be called with struct qla_hw_data->hardware_lock held
670 static void tcm_qla2xxx_clear_nacl_from_fcport_map(struct qla_tgt_sess
*sess
)
672 struct se_node_acl
*se_nacl
= sess
->se_sess
->se_node_acl
;
673 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
674 struct se_wwn
*se_wwn
= se_tpg
->se_tpg_wwn
;
675 struct tcm_qla2xxx_lport
*lport
= container_of(se_wwn
,
676 struct tcm_qla2xxx_lport
, lport_wwn
);
677 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
678 struct tcm_qla2xxx_nacl
, se_node_acl
);
681 pr_debug("fc_rport domain: port_id 0x%06x\n", nacl
->nport_id
);
683 node
= btree_remove32(&lport
->lport_fcport_map
, nacl
->nport_id
);
684 if (WARN_ON(node
&& (node
!= se_nacl
))) {
686 * The nacl no longer matches what we think it should be.
687 * Most likely a new dynamic acl has been added while
688 * someone dropped the hardware lock. It clearly is a
689 * bug elsewhere, but this bit can't make things worse.
691 btree_insert32(&lport
->lport_fcport_map
, nacl
->nport_id
,
695 pr_debug("Removed from fcport_map: %p for WWNN: 0x%016LX, port_id: 0x%06x\n",
696 se_nacl
, nacl
->nport_wwnn
, nacl
->nport_id
);
698 * Now clear the se_nacl and session pointers from our HW lport lookup
699 * table mapping for this initiator's fabric S_ID and LOOP_ID entries.
701 * This is done ahead of callbacks into tcm_qla2xxx_free_session() ->
702 * target_wait_for_sess_cmds() before the session waits for outstanding
703 * I/O to complete, to avoid a race between session shutdown execution
704 * and incoming ATIOs or TMRs picking up a stale se_node_act reference.
706 tcm_qla2xxx_clear_sess_lookup(lport
, nacl
, sess
);
709 static void tcm_qla2xxx_release_session(struct kref
*kref
)
711 struct se_session
*se_sess
= container_of(kref
,
712 struct se_session
, sess_kref
);
714 qlt_unreg_sess(se_sess
->fabric_sess_ptr
);
717 static void tcm_qla2xxx_put_session(struct se_session
*se_sess
)
719 struct qla_tgt_sess
*sess
= se_sess
->fabric_sess_ptr
;
720 struct qla_hw_data
*ha
= sess
->vha
->hw
;
723 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
724 kref_put(&se_sess
->sess_kref
, tcm_qla2xxx_release_session
);
725 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
728 static void tcm_qla2xxx_put_sess(struct qla_tgt_sess
*sess
)
733 assert_spin_locked(&sess
->vha
->hw
->hardware_lock
);
734 kref_put(&sess
->se_sess
->sess_kref
, tcm_qla2xxx_release_session
);
737 static void tcm_qla2xxx_shutdown_sess(struct qla_tgt_sess
*sess
)
739 assert_spin_locked(&sess
->vha
->hw
->hardware_lock
);
740 target_sess_cmd_list_set_waiting(sess
->se_sess
);
743 static int tcm_qla2xxx_init_nodeacl(struct se_node_acl
*se_nacl
,
746 struct tcm_qla2xxx_nacl
*nacl
=
747 container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
750 if (tcm_qla2xxx_parse_wwn(name
, &wwnn
, 1) < 0)
753 nacl
->nport_wwnn
= wwnn
;
754 tcm_qla2xxx_format_wwn(&nacl
->nport_name
[0], TCM_QLA2XXX_NAMELEN
, wwnn
);
759 /* Start items for tcm_qla2xxx_tpg_attrib_cit */
761 #define DEF_QLA_TPG_ATTRIB(name) \
763 static ssize_t tcm_qla2xxx_tpg_attrib_show_##name( \
764 struct se_portal_group *se_tpg, \
767 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
768 struct tcm_qla2xxx_tpg, se_tpg); \
770 return sprintf(page, "%u\n", tpg->tpg_attrib.name); \
773 static ssize_t tcm_qla2xxx_tpg_attrib_store_##name( \
774 struct se_portal_group *se_tpg, \
778 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
779 struct tcm_qla2xxx_tpg, se_tpg); \
783 ret = kstrtoul(page, 0, &val); \
785 pr_err("kstrtoul() failed with" \
786 " ret: %d\n", ret); \
789 ret = tcm_qla2xxx_set_attrib_##name(tpg, val); \
791 return (!ret) ? count : -EINVAL; \
794 #define DEF_QLA_TPG_ATTR_BOOL(_name) \
796 static int tcm_qla2xxx_set_attrib_##_name( \
797 struct tcm_qla2xxx_tpg *tpg, \
800 struct tcm_qla2xxx_tpg_attrib *a = &tpg->tpg_attrib; \
802 if ((val != 0) && (val != 1)) { \
803 pr_err("Illegal boolean value %lu\n", val); \
811 #define QLA_TPG_ATTR(_name, _mode) \
812 TF_TPG_ATTRIB_ATTR(tcm_qla2xxx, _name, _mode);
815 * Define tcm_qla2xxx_tpg_attrib_s_generate_node_acls
817 DEF_QLA_TPG_ATTR_BOOL(generate_node_acls
);
818 DEF_QLA_TPG_ATTRIB(generate_node_acls
);
819 QLA_TPG_ATTR(generate_node_acls
, S_IRUGO
| S_IWUSR
);
822 Define tcm_qla2xxx_attrib_s_cache_dynamic_acls
824 DEF_QLA_TPG_ATTR_BOOL(cache_dynamic_acls
);
825 DEF_QLA_TPG_ATTRIB(cache_dynamic_acls
);
826 QLA_TPG_ATTR(cache_dynamic_acls
, S_IRUGO
| S_IWUSR
);
829 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_write_protect
831 DEF_QLA_TPG_ATTR_BOOL(demo_mode_write_protect
);
832 DEF_QLA_TPG_ATTRIB(demo_mode_write_protect
);
833 QLA_TPG_ATTR(demo_mode_write_protect
, S_IRUGO
| S_IWUSR
);
836 * Define tcm_qla2xxx_tpg_attrib_s_prod_mode_write_protect
838 DEF_QLA_TPG_ATTR_BOOL(prod_mode_write_protect
);
839 DEF_QLA_TPG_ATTRIB(prod_mode_write_protect
);
840 QLA_TPG_ATTR(prod_mode_write_protect
, S_IRUGO
| S_IWUSR
);
843 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_login_only
845 DEF_QLA_TPG_ATTR_BOOL(demo_mode_login_only
);
846 DEF_QLA_TPG_ATTRIB(demo_mode_login_only
);
847 QLA_TPG_ATTR(demo_mode_login_only
, S_IRUGO
| S_IWUSR
);
849 static struct configfs_attribute
*tcm_qla2xxx_tpg_attrib_attrs
[] = {
850 &tcm_qla2xxx_tpg_attrib_generate_node_acls
.attr
,
851 &tcm_qla2xxx_tpg_attrib_cache_dynamic_acls
.attr
,
852 &tcm_qla2xxx_tpg_attrib_demo_mode_write_protect
.attr
,
853 &tcm_qla2xxx_tpg_attrib_prod_mode_write_protect
.attr
,
854 &tcm_qla2xxx_tpg_attrib_demo_mode_login_only
.attr
,
858 /* End items for tcm_qla2xxx_tpg_attrib_cit */
860 static ssize_t
tcm_qla2xxx_tpg_show_enable(
861 struct se_portal_group
*se_tpg
,
864 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
865 struct tcm_qla2xxx_tpg
, se_tpg
);
867 return snprintf(page
, PAGE_SIZE
, "%d\n",
868 atomic_read(&tpg
->lport_tpg_enabled
));
871 static void tcm_qla2xxx_depend_tpg(struct work_struct
*work
)
873 struct tcm_qla2xxx_tpg
*base_tpg
= container_of(work
,
874 struct tcm_qla2xxx_tpg
, tpg_base_work
);
875 struct se_portal_group
*se_tpg
= &base_tpg
->se_tpg
;
876 struct scsi_qla_host
*base_vha
= base_tpg
->lport
->qla_vha
;
878 if (!target_depend_item(&se_tpg
->tpg_group
.cg_item
)) {
879 atomic_set(&base_tpg
->lport_tpg_enabled
, 1);
880 qlt_enable_vha(base_vha
);
882 complete(&base_tpg
->tpg_base_comp
);
885 static void tcm_qla2xxx_undepend_tpg(struct work_struct
*work
)
887 struct tcm_qla2xxx_tpg
*base_tpg
= container_of(work
,
888 struct tcm_qla2xxx_tpg
, tpg_base_work
);
889 struct se_portal_group
*se_tpg
= &base_tpg
->se_tpg
;
890 struct scsi_qla_host
*base_vha
= base_tpg
->lport
->qla_vha
;
892 if (!qlt_stop_phase1(base_vha
->vha_tgt
.qla_tgt
)) {
893 atomic_set(&base_tpg
->lport_tpg_enabled
, 0);
894 target_undepend_item(&se_tpg
->tpg_group
.cg_item
);
896 complete(&base_tpg
->tpg_base_comp
);
899 static ssize_t
tcm_qla2xxx_tpg_store_enable(
900 struct se_portal_group
*se_tpg
,
904 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
905 struct tcm_qla2xxx_tpg
, se_tpg
);
909 rc
= kstrtoul(page
, 0, &op
);
911 pr_err("kstrtoul() returned %d\n", rc
);
914 if ((op
!= 1) && (op
!= 0)) {
915 pr_err("Illegal value for tpg_enable: %lu\n", op
);
919 if (atomic_read(&tpg
->lport_tpg_enabled
))
922 INIT_WORK(&tpg
->tpg_base_work
, tcm_qla2xxx_depend_tpg
);
924 if (!atomic_read(&tpg
->lport_tpg_enabled
))
927 INIT_WORK(&tpg
->tpg_base_work
, tcm_qla2xxx_undepend_tpg
);
929 init_completion(&tpg
->tpg_base_comp
);
930 schedule_work(&tpg
->tpg_base_work
);
931 wait_for_completion(&tpg
->tpg_base_comp
);
934 if (!atomic_read(&tpg
->lport_tpg_enabled
))
937 if (atomic_read(&tpg
->lport_tpg_enabled
))
943 TF_TPG_BASE_ATTR(tcm_qla2xxx
, enable
, S_IRUGO
| S_IWUSR
);
945 static ssize_t
tcm_qla2xxx_tpg_show_dynamic_sessions(
946 struct se_portal_group
*se_tpg
,
949 return target_show_dynamic_sessions(se_tpg
, page
);
952 TF_TPG_BASE_ATTR_RO(tcm_qla2xxx
, dynamic_sessions
);
954 static ssize_t
tcm_qla2xxx_tpg_store_fabric_prot_type(
955 struct se_portal_group
*se_tpg
,
959 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
960 struct tcm_qla2xxx_tpg
, se_tpg
);
962 int ret
= kstrtoul(page
, 0, &val
);
965 pr_err("kstrtoul() returned %d for fabric_prot_type\n", ret
);
968 if (val
!= 0 && val
!= 1 && val
!= 3) {
969 pr_err("Invalid qla2xxx fabric_prot_type: %lu\n", val
);
972 tpg
->tpg_attrib
.fabric_prot_type
= val
;
977 static ssize_t
tcm_qla2xxx_tpg_show_fabric_prot_type(
978 struct se_portal_group
*se_tpg
,
981 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
982 struct tcm_qla2xxx_tpg
, se_tpg
);
984 return sprintf(page
, "%d\n", tpg
->tpg_attrib
.fabric_prot_type
);
986 TF_TPG_BASE_ATTR(tcm_qla2xxx
, fabric_prot_type
, S_IRUGO
| S_IWUSR
);
988 static struct configfs_attribute
*tcm_qla2xxx_tpg_attrs
[] = {
989 &tcm_qla2xxx_tpg_enable
.attr
,
990 &tcm_qla2xxx_tpg_dynamic_sessions
.attr
,
991 &tcm_qla2xxx_tpg_fabric_prot_type
.attr
,
995 static struct se_portal_group
*tcm_qla2xxx_make_tpg(
997 struct config_group
*group
,
1000 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1001 struct tcm_qla2xxx_lport
, lport_wwn
);
1002 struct tcm_qla2xxx_tpg
*tpg
;
1006 if (strstr(name
, "tpgt_") != name
)
1007 return ERR_PTR(-EINVAL
);
1008 if (kstrtoul(name
+ 5, 10, &tpgt
) || tpgt
> USHRT_MAX
)
1009 return ERR_PTR(-EINVAL
);
1012 pr_err("In non NPIV mode, a single TPG=1 is used for HW port mappings\n");
1013 return ERR_PTR(-ENOSYS
);
1016 tpg
= kzalloc(sizeof(struct tcm_qla2xxx_tpg
), GFP_KERNEL
);
1018 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1019 return ERR_PTR(-ENOMEM
);
1022 tpg
->lport_tpgt
= tpgt
;
1024 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1027 tpg
->tpg_attrib
.generate_node_acls
= 1;
1028 tpg
->tpg_attrib
.demo_mode_write_protect
= 1;
1029 tpg
->tpg_attrib
.cache_dynamic_acls
= 1;
1030 tpg
->tpg_attrib
.demo_mode_login_only
= 1;
1032 ret
= core_tpg_register(&tcm_qla2xxx_ops
, wwn
, &tpg
->se_tpg
,
1041 return &tpg
->se_tpg
;
1044 static void tcm_qla2xxx_drop_tpg(struct se_portal_group
*se_tpg
)
1046 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1047 struct tcm_qla2xxx_tpg
, se_tpg
);
1048 struct tcm_qla2xxx_lport
*lport
= tpg
->lport
;
1049 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1051 * Call into qla2x_target.c LLD logic to shutdown the active
1052 * FC Nexuses and disable target mode operation for this qla_hw_data
1054 if (vha
->vha_tgt
.qla_tgt
&& !vha
->vha_tgt
.qla_tgt
->tgt_stop
)
1055 qlt_stop_phase1(vha
->vha_tgt
.qla_tgt
);
1057 core_tpg_deregister(se_tpg
);
1059 * Clear local TPG=1 pointer for non NPIV mode.
1061 lport
->tpg_1
= NULL
;
1065 static ssize_t
tcm_qla2xxx_npiv_tpg_show_enable(
1066 struct se_portal_group
*se_tpg
,
1069 return tcm_qla2xxx_tpg_show_enable(se_tpg
, page
);
1072 static ssize_t
tcm_qla2xxx_npiv_tpg_store_enable(
1073 struct se_portal_group
*se_tpg
,
1077 struct se_wwn
*se_wwn
= se_tpg
->se_tpg_wwn
;
1078 struct tcm_qla2xxx_lport
*lport
= container_of(se_wwn
,
1079 struct tcm_qla2xxx_lport
, lport_wwn
);
1080 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1081 struct tcm_qla2xxx_tpg
*tpg
= container_of(se_tpg
,
1082 struct tcm_qla2xxx_tpg
, se_tpg
);
1086 rc
= kstrtoul(page
, 0, &op
);
1088 pr_err("kstrtoul() returned %d\n", rc
);
1091 if ((op
!= 1) && (op
!= 0)) {
1092 pr_err("Illegal value for tpg_enable: %lu\n", op
);
1096 if (atomic_read(&tpg
->lport_tpg_enabled
))
1099 atomic_set(&tpg
->lport_tpg_enabled
, 1);
1100 qlt_enable_vha(vha
);
1102 if (!atomic_read(&tpg
->lport_tpg_enabled
))
1105 atomic_set(&tpg
->lport_tpg_enabled
, 0);
1106 qlt_stop_phase1(vha
->vha_tgt
.qla_tgt
);
1112 TF_TPG_BASE_ATTR(tcm_qla2xxx_npiv
, enable
, S_IRUGO
| S_IWUSR
);
1114 static struct configfs_attribute
*tcm_qla2xxx_npiv_tpg_attrs
[] = {
1115 &tcm_qla2xxx_npiv_tpg_enable
.attr
,
1119 static struct se_portal_group
*tcm_qla2xxx_npiv_make_tpg(
1121 struct config_group
*group
,
1124 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1125 struct tcm_qla2xxx_lport
, lport_wwn
);
1126 struct tcm_qla2xxx_tpg
*tpg
;
1130 if (strstr(name
, "tpgt_") != name
)
1131 return ERR_PTR(-EINVAL
);
1132 if (kstrtoul(name
+ 5, 10, &tpgt
) || tpgt
> USHRT_MAX
)
1133 return ERR_PTR(-EINVAL
);
1135 tpg
= kzalloc(sizeof(struct tcm_qla2xxx_tpg
), GFP_KERNEL
);
1137 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1138 return ERR_PTR(-ENOMEM
);
1141 tpg
->lport_tpgt
= tpgt
;
1144 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1147 tpg
->tpg_attrib
.generate_node_acls
= 1;
1148 tpg
->tpg_attrib
.demo_mode_write_protect
= 1;
1149 tpg
->tpg_attrib
.cache_dynamic_acls
= 1;
1150 tpg
->tpg_attrib
.demo_mode_login_only
= 1;
1152 ret
= core_tpg_register(&tcm_qla2xxx_npiv_ops
, wwn
, &tpg
->se_tpg
,
1159 return &tpg
->se_tpg
;
1163 * Expected to be called with struct qla_hw_data->hardware_lock held
1165 static struct qla_tgt_sess
*tcm_qla2xxx_find_sess_by_s_id(
1166 scsi_qla_host_t
*vha
,
1167 const uint8_t *s_id
)
1169 struct tcm_qla2xxx_lport
*lport
;
1170 struct se_node_acl
*se_nacl
;
1171 struct tcm_qla2xxx_nacl
*nacl
;
1174 lport
= vha
->vha_tgt
.target_lport_ptr
;
1176 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1181 key
= (((unsigned long)s_id
[0] << 16) |
1182 ((unsigned long)s_id
[1] << 8) |
1183 (unsigned long)s_id
[2]);
1184 pr_debug("find_sess_by_s_id: 0x%06x\n", key
);
1186 se_nacl
= btree_lookup32(&lport
->lport_fcport_map
, key
);
1188 pr_debug("Unable to locate s_id: 0x%06x\n", key
);
1191 pr_debug("find_sess_by_s_id: located se_nacl: %p, initiatorname: %s\n",
1192 se_nacl
, se_nacl
->initiatorname
);
1194 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1195 if (!nacl
->qla_tgt_sess
) {
1196 pr_err("Unable to locate struct qla_tgt_sess\n");
1200 return nacl
->qla_tgt_sess
;
1204 * Expected to be called with struct qla_hw_data->hardware_lock held
1206 static void tcm_qla2xxx_set_sess_by_s_id(
1207 struct tcm_qla2xxx_lport
*lport
,
1208 struct se_node_acl
*new_se_nacl
,
1209 struct tcm_qla2xxx_nacl
*nacl
,
1210 struct se_session
*se_sess
,
1211 struct qla_tgt_sess
*qla_tgt_sess
,
1218 key
= (((unsigned long)s_id
[0] << 16) |
1219 ((unsigned long)s_id
[1] << 8) |
1220 (unsigned long)s_id
[2]);
1221 pr_debug("set_sess_by_s_id: %06x\n", key
);
1223 slot
= btree_lookup32(&lport
->lport_fcport_map
, key
);
1226 pr_debug("Setting up new fc_port entry to new_se_nacl\n");
1227 nacl
->nport_id
= key
;
1228 rc
= btree_insert32(&lport
->lport_fcport_map
, key
,
1229 new_se_nacl
, GFP_ATOMIC
);
1231 printk(KERN_ERR
"Unable to insert s_id into fcport_map: %06x\n",
1234 pr_debug("Wiping nonexisting fc_port entry\n");
1237 qla_tgt_sess
->se_sess
= se_sess
;
1238 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1242 if (nacl
->qla_tgt_sess
) {
1243 if (new_se_nacl
== NULL
) {
1244 pr_debug("Clearing existing nacl->qla_tgt_sess and fc_port entry\n");
1245 btree_remove32(&lport
->lport_fcport_map
, key
);
1246 nacl
->qla_tgt_sess
= NULL
;
1249 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_port entry\n");
1250 btree_update32(&lport
->lport_fcport_map
, key
, new_se_nacl
);
1251 qla_tgt_sess
->se_sess
= se_sess
;
1252 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1256 if (new_se_nacl
== NULL
) {
1257 pr_debug("Clearing existing fc_port entry\n");
1258 btree_remove32(&lport
->lport_fcport_map
, key
);
1262 pr_debug("Replacing existing fc_port entry w/o active nacl->qla_tgt_sess\n");
1263 btree_update32(&lport
->lport_fcport_map
, key
, new_se_nacl
);
1264 qla_tgt_sess
->se_sess
= se_sess
;
1265 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1267 pr_debug("Setup nacl->qla_tgt_sess %p by s_id for se_nacl: %p, initiatorname: %s\n",
1268 nacl
->qla_tgt_sess
, new_se_nacl
, new_se_nacl
->initiatorname
);
1272 * Expected to be called with struct qla_hw_data->hardware_lock held
1274 static struct qla_tgt_sess
*tcm_qla2xxx_find_sess_by_loop_id(
1275 scsi_qla_host_t
*vha
,
1276 const uint16_t loop_id
)
1278 struct tcm_qla2xxx_lport
*lport
;
1279 struct se_node_acl
*se_nacl
;
1280 struct tcm_qla2xxx_nacl
*nacl
;
1281 struct tcm_qla2xxx_fc_loopid
*fc_loopid
;
1283 lport
= vha
->vha_tgt
.target_lport_ptr
;
1285 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1290 pr_debug("find_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id
);
1292 fc_loopid
= lport
->lport_loopid_map
+ loop_id
;
1293 se_nacl
= fc_loopid
->se_nacl
;
1295 pr_debug("Unable to locate se_nacl by loop_id: 0x%04x\n",
1300 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1302 if (!nacl
->qla_tgt_sess
) {
1303 pr_err("Unable to locate struct qla_tgt_sess\n");
1307 return nacl
->qla_tgt_sess
;
1311 * Expected to be called with struct qla_hw_data->hardware_lock held
1313 static void tcm_qla2xxx_set_sess_by_loop_id(
1314 struct tcm_qla2xxx_lport
*lport
,
1315 struct se_node_acl
*new_se_nacl
,
1316 struct tcm_qla2xxx_nacl
*nacl
,
1317 struct se_session
*se_sess
,
1318 struct qla_tgt_sess
*qla_tgt_sess
,
1321 struct se_node_acl
*saved_nacl
;
1322 struct tcm_qla2xxx_fc_loopid
*fc_loopid
;
1324 pr_debug("set_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id
);
1326 fc_loopid
= &((struct tcm_qla2xxx_fc_loopid
*)
1327 lport
->lport_loopid_map
)[loop_id
];
1329 saved_nacl
= fc_loopid
->se_nacl
;
1331 pr_debug("Setting up new fc_loopid->se_nacl to new_se_nacl\n");
1332 fc_loopid
->se_nacl
= new_se_nacl
;
1333 if (qla_tgt_sess
->se_sess
!= se_sess
)
1334 qla_tgt_sess
->se_sess
= se_sess
;
1335 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1336 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1340 if (nacl
->qla_tgt_sess
) {
1341 if (new_se_nacl
== NULL
) {
1342 pr_debug("Clearing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1343 fc_loopid
->se_nacl
= NULL
;
1344 nacl
->qla_tgt_sess
= NULL
;
1348 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1349 fc_loopid
->se_nacl
= new_se_nacl
;
1350 if (qla_tgt_sess
->se_sess
!= se_sess
)
1351 qla_tgt_sess
->se_sess
= se_sess
;
1352 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1353 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1357 if (new_se_nacl
== NULL
) {
1358 pr_debug("Clearing fc_loopid->se_nacl\n");
1359 fc_loopid
->se_nacl
= NULL
;
1363 pr_debug("Replacing existing fc_loopid->se_nacl w/o active nacl->qla_tgt_sess\n");
1364 fc_loopid
->se_nacl
= new_se_nacl
;
1365 if (qla_tgt_sess
->se_sess
!= se_sess
)
1366 qla_tgt_sess
->se_sess
= se_sess
;
1367 if (nacl
->qla_tgt_sess
!= qla_tgt_sess
)
1368 nacl
->qla_tgt_sess
= qla_tgt_sess
;
1370 pr_debug("Setup nacl->qla_tgt_sess %p by loop_id for se_nacl: %p, initiatorname: %s\n",
1371 nacl
->qla_tgt_sess
, new_se_nacl
, new_se_nacl
->initiatorname
);
1375 * Should always be called with qla_hw_data->hardware_lock held.
1377 static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport
*lport
,
1378 struct tcm_qla2xxx_nacl
*nacl
, struct qla_tgt_sess
*sess
)
1380 struct se_session
*se_sess
= sess
->se_sess
;
1381 unsigned char be_sid
[3];
1383 be_sid
[0] = sess
->s_id
.b
.domain
;
1384 be_sid
[1] = sess
->s_id
.b
.area
;
1385 be_sid
[2] = sess
->s_id
.b
.al_pa
;
1387 tcm_qla2xxx_set_sess_by_s_id(lport
, NULL
, nacl
, se_sess
,
1389 tcm_qla2xxx_set_sess_by_loop_id(lport
, NULL
, nacl
, se_sess
,
1390 sess
, sess
->loop_id
);
1393 static void tcm_qla2xxx_free_session(struct qla_tgt_sess
*sess
)
1395 struct qla_tgt
*tgt
= sess
->tgt
;
1396 struct qla_hw_data
*ha
= tgt
->ha
;
1397 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
1398 struct se_session
*se_sess
;
1399 struct se_node_acl
*se_nacl
;
1400 struct tcm_qla2xxx_lport
*lport
;
1401 struct tcm_qla2xxx_nacl
*nacl
;
1403 BUG_ON(in_interrupt());
1405 se_sess
= sess
->se_sess
;
1407 pr_err("struct qla_tgt_sess->se_sess is NULL\n");
1411 se_nacl
= se_sess
->se_node_acl
;
1412 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1414 lport
= vha
->vha_tgt
.target_lport_ptr
;
1416 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1420 target_wait_for_sess_cmds(se_sess
);
1422 transport_deregister_session_configfs(sess
->se_sess
);
1423 transport_deregister_session(sess
->se_sess
);
1427 * Called via qlt_create_sess():ha->qla2x_tmpl->check_initiator_node_acl()
1428 * to locate struct se_node_acl
1430 static int tcm_qla2xxx_check_initiator_node_acl(
1431 scsi_qla_host_t
*vha
,
1432 unsigned char *fc_wwpn
,
1437 struct qla_hw_data
*ha
= vha
->hw
;
1438 struct tcm_qla2xxx_lport
*lport
;
1439 struct tcm_qla2xxx_tpg
*tpg
;
1440 struct tcm_qla2xxx_nacl
*nacl
;
1441 struct se_portal_group
*se_tpg
;
1442 struct se_node_acl
*se_nacl
;
1443 struct se_session
*se_sess
;
1444 struct qla_tgt_sess
*sess
= qla_tgt_sess
;
1445 unsigned char port_name
[36];
1446 unsigned long flags
;
1447 int num_tags
= (ha
->fw_xcb_count
) ? ha
->fw_xcb_count
:
1448 TCM_QLA2XXX_DEFAULT_TAGS
;
1450 lport
= vha
->vha_tgt
.target_lport_ptr
;
1452 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1457 * Locate the TPG=1 reference..
1461 pr_err("Unable to lcoate struct tcm_qla2xxx_lport->tpg_1\n");
1464 se_tpg
= &tpg
->se_tpg
;
1466 se_sess
= transport_init_session_tags(num_tags
,
1467 sizeof(struct qla_tgt_cmd
),
1469 if (IS_ERR(se_sess
)) {
1470 pr_err("Unable to initialize struct se_session\n");
1471 return PTR_ERR(se_sess
);
1474 * Format the FCP Initiator port_name into colon seperated values to
1475 * match the format by tcm_qla2xxx explict ConfigFS NodeACLs.
1477 memset(&port_name
, 0, 36);
1478 snprintf(port_name
, sizeof(port_name
), "%8phC", fc_wwpn
);
1480 * Locate our struct se_node_acl either from an explict NodeACL created
1481 * via ConfigFS, or via running in TPG demo mode.
1483 se_sess
->se_node_acl
= core_tpg_check_initiator_node_acl(se_tpg
,
1485 if (!se_sess
->se_node_acl
) {
1486 transport_free_session(se_sess
);
1489 se_nacl
= se_sess
->se_node_acl
;
1490 nacl
= container_of(se_nacl
, struct tcm_qla2xxx_nacl
, se_node_acl
);
1492 * And now setup the new se_nacl and session pointers into our HW lport
1493 * mappings for fabric S_ID and LOOP_ID.
1495 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1496 tcm_qla2xxx_set_sess_by_s_id(lport
, se_nacl
, nacl
, se_sess
,
1497 qla_tgt_sess
, s_id
);
1498 tcm_qla2xxx_set_sess_by_loop_id(lport
, se_nacl
, nacl
, se_sess
,
1499 qla_tgt_sess
, loop_id
);
1500 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1502 * Finally register the new FC Nexus with TCM
1504 transport_register_session(se_nacl
->se_tpg
, se_nacl
, se_sess
, sess
);
1509 static void tcm_qla2xxx_update_sess(struct qla_tgt_sess
*sess
, port_id_t s_id
,
1510 uint16_t loop_id
, bool conf_compl_supported
)
1512 struct qla_tgt
*tgt
= sess
->tgt
;
1513 struct qla_hw_data
*ha
= tgt
->ha
;
1514 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
1515 struct tcm_qla2xxx_lport
*lport
= vha
->vha_tgt
.target_lport_ptr
;
1516 struct se_node_acl
*se_nacl
= sess
->se_sess
->se_node_acl
;
1517 struct tcm_qla2xxx_nacl
*nacl
= container_of(se_nacl
,
1518 struct tcm_qla2xxx_nacl
, se_node_acl
);
1522 if (sess
->loop_id
!= loop_id
|| sess
->s_id
.b24
!= s_id
.b24
)
1523 pr_info("Updating session %p from port %8phC loop_id %d -> %d s_id %x:%x:%x -> %x:%x:%x\n",
1524 sess
, sess
->port_name
,
1525 sess
->loop_id
, loop_id
, sess
->s_id
.b
.domain
,
1526 sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
, s_id
.b
.domain
,
1527 s_id
.b
.area
, s_id
.b
.al_pa
);
1529 if (sess
->loop_id
!= loop_id
) {
1531 * Because we can shuffle loop IDs around and we
1532 * update different sessions non-atomically, we might
1533 * have overwritten this session's old loop ID
1534 * already, and we might end up overwriting some other
1535 * session that will be updated later. So we have to
1536 * be extra careful and we can't warn about those things...
1538 if (lport
->lport_loopid_map
[sess
->loop_id
].se_nacl
== se_nacl
)
1539 lport
->lport_loopid_map
[sess
->loop_id
].se_nacl
= NULL
;
1541 lport
->lport_loopid_map
[loop_id
].se_nacl
= se_nacl
;
1543 sess
->loop_id
= loop_id
;
1546 if (sess
->s_id
.b24
!= s_id
.b24
) {
1547 key
= (((u32
) sess
->s_id
.b
.domain
<< 16) |
1548 ((u32
) sess
->s_id
.b
.area
<< 8) |
1549 ((u32
) sess
->s_id
.b
.al_pa
));
1551 if (btree_lookup32(&lport
->lport_fcport_map
, key
))
1552 WARN(btree_remove32(&lport
->lport_fcport_map
, key
) != se_nacl
,
1553 "Found wrong se_nacl when updating s_id %x:%x:%x\n",
1554 sess
->s_id
.b
.domain
, sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
);
1556 WARN(1, "No lport_fcport_map entry for s_id %x:%x:%x\n",
1557 sess
->s_id
.b
.domain
, sess
->s_id
.b
.area
, sess
->s_id
.b
.al_pa
);
1559 key
= (((u32
) s_id
.b
.domain
<< 16) |
1560 ((u32
) s_id
.b
.area
<< 8) |
1561 ((u32
) s_id
.b
.al_pa
));
1563 if (btree_lookup32(&lport
->lport_fcport_map
, key
)) {
1564 WARN(1, "Already have lport_fcport_map entry for s_id %x:%x:%x\n",
1565 s_id
.b
.domain
, s_id
.b
.area
, s_id
.b
.al_pa
);
1566 btree_update32(&lport
->lport_fcport_map
, key
, se_nacl
);
1568 btree_insert32(&lport
->lport_fcport_map
, key
, se_nacl
, GFP_ATOMIC
);
1572 nacl
->nport_id
= key
;
1575 sess
->conf_compl_supported
= conf_compl_supported
;
1579 * Calls into tcm_qla2xxx used by qla2xxx LLD I/O path.
1581 static struct qla_tgt_func_tmpl tcm_qla2xxx_template
= {
1582 .handle_cmd
= tcm_qla2xxx_handle_cmd
,
1583 .handle_data
= tcm_qla2xxx_handle_data
,
1584 .handle_dif_err
= tcm_qla2xxx_handle_dif_err
,
1585 .handle_tmr
= tcm_qla2xxx_handle_tmr
,
1586 .free_cmd
= tcm_qla2xxx_free_cmd
,
1587 .free_mcmd
= tcm_qla2xxx_free_mcmd
,
1588 .free_session
= tcm_qla2xxx_free_session
,
1589 .update_sess
= tcm_qla2xxx_update_sess
,
1590 .check_initiator_node_acl
= tcm_qla2xxx_check_initiator_node_acl
,
1591 .find_sess_by_s_id
= tcm_qla2xxx_find_sess_by_s_id
,
1592 .find_sess_by_loop_id
= tcm_qla2xxx_find_sess_by_loop_id
,
1593 .clear_nacl_from_fcport_map
= tcm_qla2xxx_clear_nacl_from_fcport_map
,
1594 .put_sess
= tcm_qla2xxx_put_sess
,
1595 .shutdown_sess
= tcm_qla2xxx_shutdown_sess
,
1598 static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport
*lport
)
1602 rc
= btree_init32(&lport
->lport_fcport_map
);
1604 pr_err("Unable to initialize lport->lport_fcport_map btree\n");
1608 lport
->lport_loopid_map
= vmalloc(sizeof(struct tcm_qla2xxx_fc_loopid
) *
1610 if (!lport
->lport_loopid_map
) {
1611 pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n",
1612 sizeof(struct tcm_qla2xxx_fc_loopid
) * 65536);
1613 btree_destroy32(&lport
->lport_fcport_map
);
1616 memset(lport
->lport_loopid_map
, 0, sizeof(struct tcm_qla2xxx_fc_loopid
)
1618 pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n",
1619 sizeof(struct tcm_qla2xxx_fc_loopid
) * 65536);
1623 static int tcm_qla2xxx_lport_register_cb(struct scsi_qla_host
*vha
,
1624 void *target_lport_ptr
,
1625 u64 npiv_wwpn
, u64 npiv_wwnn
)
1627 struct qla_hw_data
*ha
= vha
->hw
;
1628 struct tcm_qla2xxx_lport
*lport
=
1629 (struct tcm_qla2xxx_lport
*)target_lport_ptr
;
1631 * Setup tgt_ops, local pointer to vha and target_lport_ptr
1633 ha
->tgt
.tgt_ops
= &tcm_qla2xxx_template
;
1634 vha
->vha_tgt
.target_lport_ptr
= target_lport_ptr
;
1635 lport
->qla_vha
= vha
;
1640 static struct se_wwn
*tcm_qla2xxx_make_lport(
1641 struct target_fabric_configfs
*tf
,
1642 struct config_group
*group
,
1645 struct tcm_qla2xxx_lport
*lport
;
1649 if (tcm_qla2xxx_parse_wwn(name
, &wwpn
, 1) < 0)
1650 return ERR_PTR(-EINVAL
);
1652 lport
= kzalloc(sizeof(struct tcm_qla2xxx_lport
), GFP_KERNEL
);
1654 pr_err("Unable to allocate struct tcm_qla2xxx_lport\n");
1655 return ERR_PTR(-ENOMEM
);
1657 lport
->lport_wwpn
= wwpn
;
1658 tcm_qla2xxx_format_wwn(&lport
->lport_name
[0], TCM_QLA2XXX_NAMELEN
,
1660 sprintf(lport
->lport_naa_name
, "naa.%016llx", (unsigned long long) wwpn
);
1662 ret
= tcm_qla2xxx_init_lport(lport
);
1666 ret
= qlt_lport_register(lport
, wwpn
, 0, 0,
1667 tcm_qla2xxx_lport_register_cb
);
1671 return &lport
->lport_wwn
;
1673 vfree(lport
->lport_loopid_map
);
1674 btree_destroy32(&lport
->lport_fcport_map
);
1677 return ERR_PTR(ret
);
1680 static void tcm_qla2xxx_drop_lport(struct se_wwn
*wwn
)
1682 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1683 struct tcm_qla2xxx_lport
, lport_wwn
);
1684 struct scsi_qla_host
*vha
= lport
->qla_vha
;
1685 struct se_node_acl
*node
;
1689 * Call into qla2x_target.c LLD logic to complete the
1690 * shutdown of struct qla_tgt after the call to
1691 * qlt_stop_phase1() from tcm_qla2xxx_drop_tpg() above..
1693 if (vha
->vha_tgt
.qla_tgt
&& !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
1694 qlt_stop_phase2(vha
->vha_tgt
.qla_tgt
);
1696 qlt_lport_deregister(vha
);
1698 vfree(lport
->lport_loopid_map
);
1699 btree_for_each_safe32(&lport
->lport_fcport_map
, key
, node
)
1700 btree_remove32(&lport
->lport_fcport_map
, key
);
1701 btree_destroy32(&lport
->lport_fcport_map
);
1705 static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host
*base_vha
,
1706 void *target_lport_ptr
,
1707 u64 npiv_wwpn
, u64 npiv_wwnn
)
1709 struct fc_vport
*vport
;
1710 struct Scsi_Host
*sh
= base_vha
->host
;
1711 struct scsi_qla_host
*npiv_vha
;
1712 struct tcm_qla2xxx_lport
*lport
=
1713 (struct tcm_qla2xxx_lport
*)target_lport_ptr
;
1714 struct tcm_qla2xxx_lport
*base_lport
=
1715 (struct tcm_qla2xxx_lport
*)base_vha
->vha_tgt
.target_lport_ptr
;
1716 struct tcm_qla2xxx_tpg
*base_tpg
;
1717 struct fc_vport_identifiers vport_id
;
1719 if (!qla_tgt_mode_enabled(base_vha
)) {
1720 pr_err("qla2xxx base_vha not enabled for target mode\n");
1724 if (!base_lport
|| !base_lport
->tpg_1
||
1725 !atomic_read(&base_lport
->tpg_1
->lport_tpg_enabled
)) {
1726 pr_err("qla2xxx base_lport or tpg_1 not available\n");
1729 base_tpg
= base_lport
->tpg_1
;
1731 memset(&vport_id
, 0, sizeof(vport_id
));
1732 vport_id
.port_name
= npiv_wwpn
;
1733 vport_id
.node_name
= npiv_wwnn
;
1734 vport_id
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
1735 vport_id
.vport_type
= FC_PORTTYPE_NPIV
;
1736 vport_id
.disable
= false;
1738 vport
= fc_vport_create(sh
, 0, &vport_id
);
1740 pr_err("fc_vport_create failed for qla2xxx_npiv\n");
1744 * Setup local pointer to NPIV vhba + target_lport_ptr
1746 npiv_vha
= (struct scsi_qla_host
*)vport
->dd_data
;
1747 npiv_vha
->vha_tgt
.target_lport_ptr
= target_lport_ptr
;
1748 lport
->qla_vha
= npiv_vha
;
1749 scsi_host_get(npiv_vha
->host
);
1754 static struct se_wwn
*tcm_qla2xxx_npiv_make_lport(
1755 struct target_fabric_configfs
*tf
,
1756 struct config_group
*group
,
1759 struct tcm_qla2xxx_lport
*lport
;
1760 u64 phys_wwpn
, npiv_wwpn
, npiv_wwnn
;
1764 snprintf(tmp
, 128, "%s", name
);
1766 p
= strchr(tmp
, '@');
1768 pr_err("Unable to locate NPIV '@' seperator\n");
1769 return ERR_PTR(-EINVAL
);
1773 if (tcm_qla2xxx_parse_wwn(tmp
, &phys_wwpn
, 1) < 0)
1774 return ERR_PTR(-EINVAL
);
1776 if (tcm_qla2xxx_npiv_parse_wwn(p
, strlen(p
)+1,
1777 &npiv_wwpn
, &npiv_wwnn
) < 0)
1778 return ERR_PTR(-EINVAL
);
1780 lport
= kzalloc(sizeof(struct tcm_qla2xxx_lport
), GFP_KERNEL
);
1782 pr_err("Unable to allocate struct tcm_qla2xxx_lport for NPIV\n");
1783 return ERR_PTR(-ENOMEM
);
1785 lport
->lport_npiv_wwpn
= npiv_wwpn
;
1786 lport
->lport_npiv_wwnn
= npiv_wwnn
;
1787 sprintf(lport
->lport_naa_name
, "naa.%016llx", (unsigned long long) npiv_wwpn
);
1789 ret
= tcm_qla2xxx_init_lport(lport
);
1793 ret
= qlt_lport_register(lport
, phys_wwpn
, npiv_wwpn
, npiv_wwnn
,
1794 tcm_qla2xxx_lport_register_npiv_cb
);
1798 return &lport
->lport_wwn
;
1800 vfree(lport
->lport_loopid_map
);
1801 btree_destroy32(&lport
->lport_fcport_map
);
1804 return ERR_PTR(ret
);
1807 static void tcm_qla2xxx_npiv_drop_lport(struct se_wwn
*wwn
)
1809 struct tcm_qla2xxx_lport
*lport
= container_of(wwn
,
1810 struct tcm_qla2xxx_lport
, lport_wwn
);
1811 struct scsi_qla_host
*npiv_vha
= lport
->qla_vha
;
1812 struct qla_hw_data
*ha
= npiv_vha
->hw
;
1813 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1815 scsi_host_put(npiv_vha
->host
);
1817 * Notify libfc that we want to release the vha->fc_vport
1819 fc_vport_terminate(npiv_vha
->fc_vport
);
1820 scsi_host_put(base_vha
->host
);
1825 static ssize_t
tcm_qla2xxx_wwn_show_attr_version(
1826 struct target_fabric_configfs
*tf
,
1829 return sprintf(page
,
1830 "TCM QLOGIC QLA2XXX NPIV capable fabric module %s on %s/%s on "
1831 UTS_RELEASE
"\n", TCM_QLA2XXX_VERSION
, utsname()->sysname
,
1832 utsname()->machine
);
1835 TF_WWN_ATTR_RO(tcm_qla2xxx
, version
);
1837 static struct configfs_attribute
*tcm_qla2xxx_wwn_attrs
[] = {
1838 &tcm_qla2xxx_wwn_version
.attr
,
1842 static const struct target_core_fabric_ops tcm_qla2xxx_ops
= {
1843 .module
= THIS_MODULE
,
1845 .node_acl_size
= sizeof(struct tcm_qla2xxx_nacl
),
1846 .get_fabric_name
= tcm_qla2xxx_get_fabric_name
,
1847 .tpg_get_wwn
= tcm_qla2xxx_get_fabric_wwn
,
1848 .tpg_get_tag
= tcm_qla2xxx_get_tag
,
1849 .tpg_check_demo_mode
= tcm_qla2xxx_check_demo_mode
,
1850 .tpg_check_demo_mode_cache
= tcm_qla2xxx_check_demo_mode_cache
,
1851 .tpg_check_demo_mode_write_protect
=
1852 tcm_qla2xxx_check_demo_write_protect
,
1853 .tpg_check_prod_mode_write_protect
=
1854 tcm_qla2xxx_check_prod_write_protect
,
1855 .tpg_check_prot_fabric_only
= tcm_qla2xxx_check_prot_fabric_only
,
1856 .tpg_check_demo_mode_login_only
= tcm_qla2xxx_check_demo_mode_login_only
,
1857 .tpg_get_inst_index
= tcm_qla2xxx_tpg_get_inst_index
,
1858 .check_stop_free
= tcm_qla2xxx_check_stop_free
,
1859 .release_cmd
= tcm_qla2xxx_release_cmd
,
1860 .put_session
= tcm_qla2xxx_put_session
,
1861 .shutdown_session
= tcm_qla2xxx_shutdown_session
,
1862 .close_session
= tcm_qla2xxx_close_session
,
1863 .sess_get_index
= tcm_qla2xxx_sess_get_index
,
1864 .sess_get_initiator_sid
= NULL
,
1865 .write_pending
= tcm_qla2xxx_write_pending
,
1866 .write_pending_status
= tcm_qla2xxx_write_pending_status
,
1867 .set_default_node_attributes
= tcm_qla2xxx_set_default_node_attrs
,
1868 .get_task_tag
= tcm_qla2xxx_get_task_tag
,
1869 .get_cmd_state
= tcm_qla2xxx_get_cmd_state
,
1870 .queue_data_in
= tcm_qla2xxx_queue_data_in
,
1871 .queue_status
= tcm_qla2xxx_queue_status
,
1872 .queue_tm_rsp
= tcm_qla2xxx_queue_tm_rsp
,
1873 .aborted_task
= tcm_qla2xxx_aborted_task
,
1875 * Setup function pointers for generic logic in
1876 * target_core_fabric_configfs.c
1878 .fabric_make_wwn
= tcm_qla2xxx_make_lport
,
1879 .fabric_drop_wwn
= tcm_qla2xxx_drop_lport
,
1880 .fabric_make_tpg
= tcm_qla2xxx_make_tpg
,
1881 .fabric_drop_tpg
= tcm_qla2xxx_drop_tpg
,
1882 .fabric_init_nodeacl
= tcm_qla2xxx_init_nodeacl
,
1884 .tfc_wwn_attrs
= tcm_qla2xxx_wwn_attrs
,
1885 .tfc_tpg_base_attrs
= tcm_qla2xxx_tpg_attrs
,
1886 .tfc_tpg_attrib_attrs
= tcm_qla2xxx_tpg_attrib_attrs
,
1889 static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops
= {
1890 .module
= THIS_MODULE
,
1891 .name
= "qla2xxx_npiv",
1892 .node_acl_size
= sizeof(struct tcm_qla2xxx_nacl
),
1893 .get_fabric_name
= tcm_qla2xxx_npiv_get_fabric_name
,
1894 .tpg_get_wwn
= tcm_qla2xxx_get_fabric_wwn
,
1895 .tpg_get_tag
= tcm_qla2xxx_get_tag
,
1896 .tpg_check_demo_mode
= tcm_qla2xxx_check_demo_mode
,
1897 .tpg_check_demo_mode_cache
= tcm_qla2xxx_check_demo_mode_cache
,
1898 .tpg_check_demo_mode_write_protect
= tcm_qla2xxx_check_demo_mode
,
1899 .tpg_check_prod_mode_write_protect
=
1900 tcm_qla2xxx_check_prod_write_protect
,
1901 .tpg_check_demo_mode_login_only
= tcm_qla2xxx_check_demo_mode_login_only
,
1902 .tpg_get_inst_index
= tcm_qla2xxx_tpg_get_inst_index
,
1903 .check_stop_free
= tcm_qla2xxx_check_stop_free
,
1904 .release_cmd
= tcm_qla2xxx_release_cmd
,
1905 .put_session
= tcm_qla2xxx_put_session
,
1906 .shutdown_session
= tcm_qla2xxx_shutdown_session
,
1907 .close_session
= tcm_qla2xxx_close_session
,
1908 .sess_get_index
= tcm_qla2xxx_sess_get_index
,
1909 .sess_get_initiator_sid
= NULL
,
1910 .write_pending
= tcm_qla2xxx_write_pending
,
1911 .write_pending_status
= tcm_qla2xxx_write_pending_status
,
1912 .set_default_node_attributes
= tcm_qla2xxx_set_default_node_attrs
,
1913 .get_task_tag
= tcm_qla2xxx_get_task_tag
,
1914 .get_cmd_state
= tcm_qla2xxx_get_cmd_state
,
1915 .queue_data_in
= tcm_qla2xxx_queue_data_in
,
1916 .queue_status
= tcm_qla2xxx_queue_status
,
1917 .queue_tm_rsp
= tcm_qla2xxx_queue_tm_rsp
,
1918 .aborted_task
= tcm_qla2xxx_aborted_task
,
1920 * Setup function pointers for generic logic in
1921 * target_core_fabric_configfs.c
1923 .fabric_make_wwn
= tcm_qla2xxx_npiv_make_lport
,
1924 .fabric_drop_wwn
= tcm_qla2xxx_npiv_drop_lport
,
1925 .fabric_make_tpg
= tcm_qla2xxx_npiv_make_tpg
,
1926 .fabric_drop_tpg
= tcm_qla2xxx_drop_tpg
,
1927 .fabric_init_nodeacl
= tcm_qla2xxx_init_nodeacl
,
1929 .tfc_wwn_attrs
= tcm_qla2xxx_wwn_attrs
,
1930 .tfc_tpg_base_attrs
= tcm_qla2xxx_npiv_tpg_attrs
,
1933 static int tcm_qla2xxx_register_configfs(void)
1937 pr_debug("TCM QLOGIC QLA2XXX fabric module %s on %s/%s on "
1938 UTS_RELEASE
"\n", TCM_QLA2XXX_VERSION
, utsname()->sysname
,
1939 utsname()->machine
);
1941 ret
= target_register_template(&tcm_qla2xxx_ops
);
1945 ret
= target_register_template(&tcm_qla2xxx_npiv_ops
);
1949 tcm_qla2xxx_free_wq
= alloc_workqueue("tcm_qla2xxx_free",
1951 if (!tcm_qla2xxx_free_wq
) {
1953 goto out_fabric_npiv
;
1956 tcm_qla2xxx_cmd_wq
= alloc_workqueue("tcm_qla2xxx_cmd", 0, 0);
1957 if (!tcm_qla2xxx_cmd_wq
) {
1965 destroy_workqueue(tcm_qla2xxx_free_wq
);
1967 target_unregister_template(&tcm_qla2xxx_npiv_ops
);
1969 target_unregister_template(&tcm_qla2xxx_ops
);
1973 static void tcm_qla2xxx_deregister_configfs(void)
1975 destroy_workqueue(tcm_qla2xxx_cmd_wq
);
1976 destroy_workqueue(tcm_qla2xxx_free_wq
);
1978 target_unregister_template(&tcm_qla2xxx_ops
);
1979 target_unregister_template(&tcm_qla2xxx_npiv_ops
);
1982 static int __init
tcm_qla2xxx_init(void)
1986 ret
= tcm_qla2xxx_register_configfs();
1993 static void __exit
tcm_qla2xxx_exit(void)
1995 tcm_qla2xxx_deregister_configfs();
1998 MODULE_DESCRIPTION("TCM QLA2XXX series NPIV enabled fabric driver");
1999 MODULE_LICENSE("GPL");
2000 module_init(tcm_qla2xxx_init
);
2001 module_exit(tcm_qla2xxx_exit
);