aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaurav Kashyap <saurav.kashyap@qlogic.com>2014-01-14 23:40:38 -0500
committerNicholas Bellinger <nab@linux-iscsi.org>2014-01-18 21:22:10 -0500
commit0e8cd71ceca4c15ef544e3af01248bc869c28d8f (patch)
tree12770c0b44a9dfc4ae4dd8cb8c27fe4f28be67c9
parent2930d441592c16b83237ad015628cba5f41cc095 (diff)
qla2xxx: Enhancements to enable NPIV support for QLOGIC ISPs with TCM/LIO.
Signed-off-by: Sawan Chandak <sawan.chandak@qlogic.com> Signed-off-by: Quinn Tran <quinn.tran@qlogic.com> Signed-off-by: Saurav Kashyap <saurav.kashyap@qlogic.com> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h12
-rw-r--r--drivers/scsi/qla2xxx/qla_target.c150
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.c110
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.h4
5 files changed, 153 insertions, 125 deletions
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 5f174b83f56f..9c412b54bbd3 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -1994,6 +1994,8 @@ qla24xx_vport_delete(struct fc_vport *fc_vport)
1994 1994
1995 vha->flags.delete_progress = 1; 1995 vha->flags.delete_progress = 1;
1996 1996
1997 qlt_remove_target(ha, vha);
1998
1997 fc_remove_host(vha->host); 1999 fc_remove_host(vha->host);
1998 2000
1999 scsi_remove_host(vha->host); 2001 scsi_remove_host(vha->host);
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 93db74ef3461..e7be8a5c31b9 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -2750,6 +2750,13 @@ struct qlfc_fw {
2750 uint32_t len; 2750 uint32_t len;
2751}; 2751};
2752 2752
2753struct scsi_qlt_host {
2754 void *target_lport_ptr;
2755 struct mutex tgt_mutex;
2756 struct mutex tgt_host_action_mutex;
2757 struct qla_tgt *qla_tgt;
2758};
2759
2753struct qlt_hw_data { 2760struct qlt_hw_data {
2754 /* Protected by hw lock */ 2761 /* Protected by hw lock */
2755 uint32_t enable_class_2:1; 2762 uint32_t enable_class_2:1;
@@ -2765,15 +2772,11 @@ struct qlt_hw_data {
2765 uint32_t __iomem *atio_q_in; 2772 uint32_t __iomem *atio_q_in;
2766 uint32_t __iomem *atio_q_out; 2773 uint32_t __iomem *atio_q_out;
2767 2774
2768 void *target_lport_ptr;
2769 struct qla_tgt_func_tmpl *tgt_ops; 2775 struct qla_tgt_func_tmpl *tgt_ops;
2770 struct qla_tgt *qla_tgt;
2771 struct qla_tgt_cmd *cmds[DEFAULT_OUTSTANDING_COMMANDS]; 2776 struct qla_tgt_cmd *cmds[DEFAULT_OUTSTANDING_COMMANDS];
2772 uint16_t current_handle; 2777 uint16_t current_handle;
2773 2778
2774 struct qla_tgt_vp_map *tgt_vp_map; 2779 struct qla_tgt_vp_map *tgt_vp_map;
2775 struct mutex tgt_mutex;
2776 struct mutex tgt_host_action_mutex;
2777 2780
2778 int saved_set; 2781 int saved_set;
2779 uint16_t saved_exchange_count; 2782 uint16_t saved_exchange_count;
@@ -3441,6 +3444,7 @@ typedef struct scsi_qla_host {
3441#define VP_ERR_FAB_LOGOUT 4 3444#define VP_ERR_FAB_LOGOUT 4
3442#define VP_ERR_ADAP_NORESOURCES 5 3445#define VP_ERR_ADAP_NORESOURCES 5
3443 struct qla_hw_data *hw; 3446 struct qla_hw_data *hw;
3447 struct scsi_qlt_host vha_tgt;
3444 struct req_que *req; 3448 struct req_que *req;
3445 int fw_heartbeat_counter; 3449 int fw_heartbeat_counter;
3446 int seconds_since_last_heartbeat; 3450 int seconds_since_last_heartbeat;
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index 0b6c5f92cb8e..34ed246aa0db 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -589,7 +589,7 @@ static struct qla_tgt_sess *qlt_create_sess(
589 589
590 /* Check to avoid double sessions */ 590 /* Check to avoid double sessions */
591 spin_lock_irqsave(&ha->hardware_lock, flags); 591 spin_lock_irqsave(&ha->hardware_lock, flags);
592 list_for_each_entry(sess, &ha->tgt.qla_tgt->sess_list, 592 list_for_each_entry(sess, &vha->vha_tgt.qla_tgt->sess_list,
593 sess_list_entry) { 593 sess_list_entry) {
594 if (!memcmp(sess->port_name, fcport->port_name, WWN_SIZE)) { 594 if (!memcmp(sess->port_name, fcport->port_name, WWN_SIZE)) {
595 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf005, 595 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf005,
@@ -626,7 +626,7 @@ static struct qla_tgt_sess *qlt_create_sess(
626 626
627 return NULL; 627 return NULL;
628 } 628 }
629 sess->tgt = ha->tgt.qla_tgt; 629 sess->tgt = vha->vha_tgt.qla_tgt;
630 sess->vha = vha; 630 sess->vha = vha;
631 sess->s_id = fcport->d_id; 631 sess->s_id = fcport->d_id;
632 sess->loop_id = fcport->loop_id; 632 sess->loop_id = fcport->loop_id;
@@ -634,7 +634,7 @@ static struct qla_tgt_sess *qlt_create_sess(
634 634
635 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, 635 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006,
636 "Adding sess %p to tgt %p via ->check_initiator_node_acl()\n", 636 "Adding sess %p to tgt %p via ->check_initiator_node_acl()\n",
637 sess, ha->tgt.qla_tgt); 637 sess, vha->vha_tgt.qla_tgt);
638 638
639 be_sid[0] = sess->s_id.b.domain; 639 be_sid[0] = sess->s_id.b.domain;
640 be_sid[1] = sess->s_id.b.area; 640 be_sid[1] = sess->s_id.b.area;
@@ -661,8 +661,8 @@ static struct qla_tgt_sess *qlt_create_sess(
661 memcpy(sess->port_name, fcport->port_name, sizeof(sess->port_name)); 661 memcpy(sess->port_name, fcport->port_name, sizeof(sess->port_name));
662 662
663 spin_lock_irqsave(&ha->hardware_lock, flags); 663 spin_lock_irqsave(&ha->hardware_lock, flags);
664 list_add_tail(&sess->sess_list_entry, &ha->tgt.qla_tgt->sess_list); 664 list_add_tail(&sess->sess_list_entry, &vha->vha_tgt.qla_tgt->sess_list);
665 ha->tgt.qla_tgt->sess_count++; 665 vha->vha_tgt.qla_tgt->sess_count++;
666 spin_unlock_irqrestore(&ha->hardware_lock, flags); 666 spin_unlock_irqrestore(&ha->hardware_lock, flags);
667 667
668 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, 668 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b,
@@ -681,7 +681,7 @@ static struct qla_tgt_sess *qlt_create_sess(
681void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) 681void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport)
682{ 682{
683 struct qla_hw_data *ha = vha->hw; 683 struct qla_hw_data *ha = vha->hw;
684 struct qla_tgt *tgt = ha->tgt.qla_tgt; 684 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
685 struct qla_tgt_sess *sess; 685 struct qla_tgt_sess *sess;
686 unsigned long flags; 686 unsigned long flags;
687 687
@@ -691,6 +691,9 @@ void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport)
691 if (!tgt || (fcport->port_type != FCT_INITIATOR)) 691 if (!tgt || (fcport->port_type != FCT_INITIATOR))
692 return; 692 return;
693 693
694 if (qla_ini_mode_enabled(vha))
695 return;
696
694 spin_lock_irqsave(&ha->hardware_lock, flags); 697 spin_lock_irqsave(&ha->hardware_lock, flags);
695 if (tgt->tgt_stop) { 698 if (tgt->tgt_stop) {
696 spin_unlock_irqrestore(&ha->hardware_lock, flags); 699 spin_unlock_irqrestore(&ha->hardware_lock, flags);
@@ -700,9 +703,9 @@ void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport)
700 if (!sess) { 703 if (!sess) {
701 spin_unlock_irqrestore(&ha->hardware_lock, flags); 704 spin_unlock_irqrestore(&ha->hardware_lock, flags);
702 705
703 mutex_lock(&ha->tgt.tgt_mutex); 706 mutex_lock(&vha->vha_tgt.tgt_mutex);
704 sess = qlt_create_sess(vha, fcport, false); 707 sess = qlt_create_sess(vha, fcport, false);
705 mutex_unlock(&ha->tgt.tgt_mutex); 708 mutex_unlock(&vha->vha_tgt.tgt_mutex);
706 709
707 spin_lock_irqsave(&ha->hardware_lock, flags); 710 spin_lock_irqsave(&ha->hardware_lock, flags);
708 } else { 711 } else {
@@ -738,7 +741,7 @@ void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport)
738void qlt_fc_port_deleted(struct scsi_qla_host *vha, fc_port_t *fcport) 741void qlt_fc_port_deleted(struct scsi_qla_host *vha, fc_port_t *fcport)
739{ 742{
740 struct qla_hw_data *ha = vha->hw; 743 struct qla_hw_data *ha = vha->hw;
741 struct qla_tgt *tgt = ha->tgt.qla_tgt; 744 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
742 struct qla_tgt_sess *sess; 745 struct qla_tgt_sess *sess;
743 unsigned long flags; 746 unsigned long flags;
744 747
@@ -805,12 +808,12 @@ void qlt_stop_phase1(struct qla_tgt *tgt)
805 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. 808 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
806 * Lock is needed, because we still can get an incoming packet. 809 * Lock is needed, because we still can get an incoming packet.
807 */ 810 */
808 mutex_lock(&ha->tgt.tgt_mutex); 811 mutex_lock(&vha->vha_tgt.tgt_mutex);
809 spin_lock_irqsave(&ha->hardware_lock, flags); 812 spin_lock_irqsave(&ha->hardware_lock, flags);
810 tgt->tgt_stop = 1; 813 tgt->tgt_stop = 1;
811 qlt_clear_tgt_db(tgt, true); 814 qlt_clear_tgt_db(tgt, true);
812 spin_unlock_irqrestore(&ha->hardware_lock, flags); 815 spin_unlock_irqrestore(&ha->hardware_lock, flags);
813 mutex_unlock(&ha->tgt.tgt_mutex); 816 mutex_unlock(&vha->vha_tgt.tgt_mutex);
814 817
815 flush_delayed_work(&tgt->sess_del_work); 818 flush_delayed_work(&tgt->sess_del_work);
816 819
@@ -844,20 +847,21 @@ EXPORT_SYMBOL(qlt_stop_phase1);
844void qlt_stop_phase2(struct qla_tgt *tgt) 847void qlt_stop_phase2(struct qla_tgt *tgt)
845{ 848{
846 struct qla_hw_data *ha = tgt->ha; 849 struct qla_hw_data *ha = tgt->ha;
850 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
847 unsigned long flags; 851 unsigned long flags;
848 852
849 if (tgt->tgt_stopped) { 853 if (tgt->tgt_stopped) {
850 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf04f, 854 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f,
851 "Already in tgt->tgt_stopped state\n"); 855 "Already in tgt->tgt_stopped state\n");
852 dump_stack(); 856 dump_stack();
853 return; 857 return;
854 } 858 }
855 859
856 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00b, 860 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b,
857 "Waiting for %d IRQ commands to complete (tgt %p)", 861 "Waiting for %d IRQ commands to complete (tgt %p)",
858 tgt->irq_cmd_count, tgt); 862 tgt->irq_cmd_count, tgt);
859 863
860 mutex_lock(&ha->tgt.tgt_mutex); 864 mutex_lock(&vha->vha_tgt.tgt_mutex);
861 spin_lock_irqsave(&ha->hardware_lock, flags); 865 spin_lock_irqsave(&ha->hardware_lock, flags);
862 while (tgt->irq_cmd_count != 0) { 866 while (tgt->irq_cmd_count != 0) {
863 spin_unlock_irqrestore(&ha->hardware_lock, flags); 867 spin_unlock_irqrestore(&ha->hardware_lock, flags);
@@ -867,9 +871,9 @@ void qlt_stop_phase2(struct qla_tgt *tgt)
867 tgt->tgt_stop = 0; 871 tgt->tgt_stop = 0;
868 tgt->tgt_stopped = 1; 872 tgt->tgt_stopped = 1;
869 spin_unlock_irqrestore(&ha->hardware_lock, flags); 873 spin_unlock_irqrestore(&ha->hardware_lock, flags);
870 mutex_unlock(&ha->tgt.tgt_mutex); 874 mutex_unlock(&vha->vha_tgt.tgt_mutex);
871 875
872 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00c, "Stop of tgt %p finished", 876 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00c, "Stop of tgt %p finished",
873 tgt); 877 tgt);
874} 878}
875EXPORT_SYMBOL(qlt_stop_phase2); 879EXPORT_SYMBOL(qlt_stop_phase2);
@@ -877,14 +881,14 @@ EXPORT_SYMBOL(qlt_stop_phase2);
877/* Called from qlt_remove_target() -> qla2x00_remove_one() */ 881/* Called from qlt_remove_target() -> qla2x00_remove_one() */
878static void qlt_release(struct qla_tgt *tgt) 882static void qlt_release(struct qla_tgt *tgt)
879{ 883{
880 struct qla_hw_data *ha = tgt->ha; 884 scsi_qla_host_t *vha = tgt->vha;
881 885
882 if ((ha->tgt.qla_tgt != NULL) && !tgt->tgt_stopped) 886 if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stopped)
883 qlt_stop_phase2(tgt); 887 qlt_stop_phase2(tgt);
884 888
885 ha->tgt.qla_tgt = NULL; 889 vha->vha_tgt.qla_tgt = NULL;
886 890
887 ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00d, 891 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d,
888 "Release of tgt %p finished\n", tgt); 892 "Release of tgt %p finished\n", tgt);
889 893
890 kfree(tgt); 894 kfree(tgt);
@@ -948,8 +952,8 @@ static void qlt_send_notify_ack(struct scsi_qla_host *vha,
948 return; 952 return;
949 } 953 }
950 954
951 if (ha->tgt.qla_tgt != NULL) 955 if (vha->vha_tgt.qla_tgt != NULL)
952 ha->tgt.qla_tgt->notify_ack_expected++; 956 vha->vha_tgt.qla_tgt->notify_ack_expected++;
953 957
954 pkt->entry_type = NOTIFY_ACK_TYPE; 958 pkt->entry_type = NOTIFY_ACK_TYPE;
955 pkt->entry_count = 1; 959 pkt->entry_count = 1;
@@ -1053,7 +1057,7 @@ static void qlt_24xx_send_abts_resp(struct scsi_qla_host *vha,
1053 /* Other bytes are zero */ 1057 /* Other bytes are zero */
1054 } 1058 }
1055 1059
1056 ha->tgt.qla_tgt->abts_resp_expected++; 1060 vha->vha_tgt.qla_tgt->abts_resp_expected++;
1057 1061
1058 qla2x00_start_iocbs(vha, vha->req); 1062 qla2x00_start_iocbs(vha, vha->req);
1059} 1063}
@@ -1205,7 +1209,7 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
1205 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, 1209 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012,
1206 "qla_target(%d): task abort for non-existant session\n", 1210 "qla_target(%d): task abort for non-existant session\n",
1207 vha->vp_idx); 1211 vha->vp_idx);
1208 rc = qlt_sched_sess_work(ha->tgt.qla_tgt, 1212 rc = qlt_sched_sess_work(vha->vha_tgt.qla_tgt,
1209 QLA_TGT_SESS_WORK_ABORT, abts, sizeof(*abts)); 1213 QLA_TGT_SESS_WORK_ABORT, abts, sizeof(*abts));
1210 if (rc != 0) { 1214 if (rc != 0) {
1211 qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, 1215 qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED,
@@ -2156,8 +2160,7 @@ static int qlt_prepare_srr_ctio(struct scsi_qla_host *vha,
2156 struct qla_tgt_cmd *cmd, void *ctio) 2160 struct qla_tgt_cmd *cmd, void *ctio)
2157{ 2161{
2158 struct qla_tgt_srr_ctio *sc; 2162 struct qla_tgt_srr_ctio *sc;
2159 struct qla_hw_data *ha = vha->hw; 2163 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
2160 struct qla_tgt *tgt = ha->tgt.qla_tgt;
2161 struct qla_tgt_srr_imm *imm; 2164 struct qla_tgt_srr_imm *imm;
2162 2165
2163 tgt->ctio_srr_id++; 2166 tgt->ctio_srr_id++;
@@ -2473,7 +2476,7 @@ static void qlt_do_work(struct work_struct *work)
2473 struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work); 2476 struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work);
2474 scsi_qla_host_t *vha = cmd->vha; 2477 scsi_qla_host_t *vha = cmd->vha;
2475 struct qla_hw_data *ha = vha->hw; 2478 struct qla_hw_data *ha = vha->hw;
2476 struct qla_tgt *tgt = ha->tgt.qla_tgt; 2479 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
2477 struct qla_tgt_sess *sess = NULL; 2480 struct qla_tgt_sess *sess = NULL;
2478 struct atio_from_isp *atio = &cmd->atio; 2481 struct atio_from_isp *atio = &cmd->atio;
2479 unsigned char *cdb; 2482 unsigned char *cdb;
@@ -2506,10 +2509,10 @@ static void qlt_do_work(struct work_struct *work)
2506 goto out_term; 2509 goto out_term;
2507 } 2510 }
2508 2511
2509 mutex_lock(&ha->tgt.tgt_mutex); 2512 mutex_lock(&vha->vha_tgt.tgt_mutex);
2510 sess = qlt_make_local_sess(vha, s_id); 2513 sess = qlt_make_local_sess(vha, s_id);
2511 /* sess has an extra creation ref. */ 2514 /* sess has an extra creation ref. */
2512 mutex_unlock(&ha->tgt.tgt_mutex); 2515 mutex_unlock(&vha->vha_tgt.tgt_mutex);
2513 2516
2514 if (!sess) 2517 if (!sess)
2515 goto out_term; 2518 goto out_term;
@@ -2575,8 +2578,7 @@ out_term:
2575static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, 2578static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha,
2576 struct atio_from_isp *atio) 2579 struct atio_from_isp *atio)
2577{ 2580{
2578 struct qla_hw_data *ha = vha->hw; 2581 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
2579 struct qla_tgt *tgt = ha->tgt.qla_tgt;
2580 struct qla_tgt_cmd *cmd; 2582 struct qla_tgt_cmd *cmd;
2581 2583
2582 if (unlikely(tgt->tgt_stop)) { 2584 if (unlikely(tgt->tgt_stop)) {
@@ -2596,7 +2598,7 @@ static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha,
2596 2598
2597 memcpy(&cmd->atio, atio, sizeof(*atio)); 2599 memcpy(&cmd->atio, atio, sizeof(*atio));
2598 cmd->state = QLA_TGT_STATE_NEW; 2600 cmd->state = QLA_TGT_STATE_NEW;
2599 cmd->tgt = ha->tgt.qla_tgt; 2601 cmd->tgt = vha->vha_tgt.qla_tgt;
2600 cmd->vha = vha; 2602 cmd->vha = vha;
2601 2603
2602 INIT_WORK(&cmd->work, qlt_do_work); 2604 INIT_WORK(&cmd->work, qlt_do_work);
@@ -2722,7 +2724,7 @@ static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb)
2722 uint32_t lun, unpacked_lun; 2724 uint32_t lun, unpacked_lun;
2723 int lun_size, fn; 2725 int lun_size, fn;
2724 2726
2725 tgt = ha->tgt.qla_tgt; 2727 tgt = vha->vha_tgt.qla_tgt;
2726 2728
2727 lun = a->u.isp24.fcp_cmnd.lun; 2729 lun = a->u.isp24.fcp_cmnd.lun;
2728 lun_size = sizeof(a->u.isp24.fcp_cmnd.lun); 2730 lun_size = sizeof(a->u.isp24.fcp_cmnd.lun);
@@ -2796,7 +2798,7 @@ static int qlt_abort_task(struct scsi_qla_host *vha,
2796 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, 2798 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025,
2797 "qla_target(%d): task abort for unexisting " 2799 "qla_target(%d): task abort for unexisting "
2798 "session\n", vha->vp_idx); 2800 "session\n", vha->vp_idx);
2799 return qlt_sched_sess_work(ha->tgt.qla_tgt, 2801 return qlt_sched_sess_work(vha->vha_tgt.qla_tgt,
2800 QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); 2802 QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb));
2801 } 2803 }
2802 2804
@@ -2809,7 +2811,6 @@ static int qlt_abort_task(struct scsi_qla_host *vha,
2809static int qlt_24xx_handle_els(struct scsi_qla_host *vha, 2811static int qlt_24xx_handle_els(struct scsi_qla_host *vha,
2810 struct imm_ntfy_from_isp *iocb) 2812 struct imm_ntfy_from_isp *iocb)
2811{ 2813{
2812 struct qla_hw_data *ha = vha->hw;
2813 int res = 0; 2814 int res = 0;
2814 2815
2815 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf026, 2816 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf026,
@@ -2827,7 +2828,7 @@ static int qlt_24xx_handle_els(struct scsi_qla_host *vha,
2827 case ELS_PDISC: 2828 case ELS_PDISC:
2828 case ELS_ADISC: 2829 case ELS_ADISC:
2829 { 2830 {
2830 struct qla_tgt *tgt = ha->tgt.qla_tgt; 2831 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
2831 if (tgt->link_reinit_iocb_pending) { 2832 if (tgt->link_reinit_iocb_pending) {
2832 qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, 2833 qlt_send_notify_ack(vha, &tgt->link_reinit_iocb,
2833 0, 0, 0, 0, 0, 0); 2834 0, 0, 0, 0, 0, 0);
@@ -3201,8 +3202,7 @@ static void qlt_prepare_srr_imm(struct scsi_qla_host *vha,
3201 struct imm_ntfy_from_isp *iocb) 3202 struct imm_ntfy_from_isp *iocb)
3202{ 3203{
3203 struct qla_tgt_srr_imm *imm; 3204 struct qla_tgt_srr_imm *imm;
3204 struct qla_hw_data *ha = vha->hw; 3205 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
3205 struct qla_tgt *tgt = ha->tgt.qla_tgt;
3206 struct qla_tgt_srr_ctio *sctio; 3206 struct qla_tgt_srr_ctio *sctio;
3207 3207
3208 tgt->imm_srr_id++; 3208 tgt->imm_srr_id++;
@@ -3312,7 +3312,7 @@ static void qlt_handle_imm_notify(struct scsi_qla_host *vha,
3312 3312
3313 case IMM_NTFY_LIP_LINK_REINIT: 3313 case IMM_NTFY_LIP_LINK_REINIT:
3314 { 3314 {
3315 struct qla_tgt *tgt = ha->tgt.qla_tgt; 3315 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
3316 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, 3316 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033,
3317 "qla_target(%d): LINK REINIT (loop %#x, " 3317 "qla_target(%d): LINK REINIT (loop %#x, "
3318 "subcode %x)\n", vha->vp_idx, 3318 "subcode %x)\n", vha->vp_idx,
@@ -3488,7 +3488,7 @@ static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha,
3488 struct atio_from_isp *atio) 3488 struct atio_from_isp *atio)
3489{ 3489{
3490 struct qla_hw_data *ha = vha->hw; 3490 struct qla_hw_data *ha = vha->hw;
3491 struct qla_tgt *tgt = ha->tgt.qla_tgt; 3491 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
3492 int rc; 3492 int rc;
3493 3493
3494 if (unlikely(tgt == NULL)) { 3494 if (unlikely(tgt == NULL)) {
@@ -3590,7 +3590,7 @@ static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha,
3590static void qlt_response_pkt(struct scsi_qla_host *vha, response_t *pkt) 3590static void qlt_response_pkt(struct scsi_qla_host *vha, response_t *pkt)
3591{ 3591{
3592 struct qla_hw_data *ha = vha->hw; 3592 struct qla_hw_data *ha = vha->hw;
3593 struct qla_tgt *tgt = ha->tgt.qla_tgt; 3593 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
3594 3594
3595 if (unlikely(tgt == NULL)) { 3595 if (unlikely(tgt == NULL)) {
3596 ql_dbg(ql_dbg_tgt, vha, 0xe05d, 3596 ql_dbg(ql_dbg_tgt, vha, 0xe05d,
@@ -3793,7 +3793,7 @@ void qlt_async_event(uint16_t code, struct scsi_qla_host *vha,
3793 uint16_t *mailbox) 3793 uint16_t *mailbox)
3794{ 3794{
3795 struct qla_hw_data *ha = vha->hw; 3795 struct qla_hw_data *ha = vha->hw;
3796 struct qla_tgt *tgt = ha->tgt.qla_tgt; 3796 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
3797 int login_code; 3797 int login_code;
3798 3798
3799 ql_dbg(ql_dbg_tgt, vha, 0xe039, 3799 ql_dbg(ql_dbg_tgt, vha, 0xe039,
@@ -3923,14 +3923,14 @@ static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha,
3923static struct qla_tgt_sess *qlt_make_local_sess(struct scsi_qla_host *vha, 3923static struct qla_tgt_sess *qlt_make_local_sess(struct scsi_qla_host *vha,
3924 uint8_t *s_id) 3924 uint8_t *s_id)
3925{ 3925{
3926 struct qla_hw_data *ha = vha->hw;
3927 struct qla_tgt_sess *sess = NULL; 3926 struct qla_tgt_sess *sess = NULL;
3928 fc_port_t *fcport = NULL; 3927 fc_port_t *fcport = NULL;
3929 int rc, global_resets; 3928 int rc, global_resets;
3930 uint16_t loop_id = 0; 3929 uint16_t loop_id = 0;
3931 3930
3932retry: 3931retry:
3933 global_resets = atomic_read(&ha->tgt.qla_tgt->tgt_global_resets_count); 3932 global_resets =
3933 atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count);
3934 3934
3935 rc = qla24xx_get_loop_id(vha, s_id, &loop_id); 3935 rc = qla24xx_get_loop_id(vha, s_id, &loop_id);
3936 if (rc != 0) { 3936 if (rc != 0) {
@@ -3957,12 +3957,13 @@ retry:
3957 return NULL; 3957 return NULL;
3958 3958
3959 if (global_resets != 3959 if (global_resets !=
3960 atomic_read(&ha->tgt.qla_tgt->tgt_global_resets_count)) { 3960 atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) {
3961 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, 3961 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043,
3962 "qla_target(%d): global reset during session discovery " 3962 "qla_target(%d): global reset during session discovery "
3963 "(counter was %d, new %d), retrying", vha->vp_idx, 3963 "(counter was %d, new %d), retrying", vha->vp_idx,
3964 global_resets, 3964 global_resets,
3965 atomic_read(&ha->tgt.qla_tgt->tgt_global_resets_count)); 3965 atomic_read(&vha->vha_tgt.
3966 qla_tgt->tgt_global_resets_count));
3966 goto retry; 3967 goto retry;
3967 } 3968 }
3968 3969
@@ -3997,10 +3998,10 @@ static void qlt_abort_work(struct qla_tgt *tgt,
3997 if (!sess) { 3998 if (!sess) {
3998 spin_unlock_irqrestore(&ha->hardware_lock, flags); 3999 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3999 4000
4000 mutex_lock(&ha->tgt.tgt_mutex); 4001 mutex_lock(&vha->vha_tgt.tgt_mutex);
4001 sess = qlt_make_local_sess(vha, s_id); 4002 sess = qlt_make_local_sess(vha, s_id);
4002 /* sess has got an extra creation ref */ 4003 /* sess has got an extra creation ref */
4003 mutex_unlock(&ha->tgt.tgt_mutex); 4004 mutex_unlock(&vha->vha_tgt.tgt_mutex);
4004 4005
4005 spin_lock_irqsave(&ha->hardware_lock, flags); 4006 spin_lock_irqsave(&ha->hardware_lock, flags);
4006 if (!sess) 4007 if (!sess)
@@ -4051,10 +4052,10 @@ static void qlt_tmr_work(struct qla_tgt *tgt,
4051 if (!sess) { 4052 if (!sess) {
4052 spin_unlock_irqrestore(&ha->hardware_lock, flags); 4053 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4053 4054
4054 mutex_lock(&ha->tgt.tgt_mutex); 4055 mutex_lock(&vha->vha_tgt.tgt_mutex);
4055 sess = qlt_make_local_sess(vha, s_id); 4056 sess = qlt_make_local_sess(vha, s_id);
4056 /* sess has got an extra creation ref */ 4057 /* sess has got an extra creation ref */
4057 mutex_unlock(&ha->tgt.tgt_mutex); 4058 mutex_unlock(&vha->vha_tgt.tgt_mutex);
4058 4059
4059 spin_lock_irqsave(&ha->hardware_lock, flags); 4060 spin_lock_irqsave(&ha->hardware_lock, flags);
4060 if (!sess) 4061 if (!sess)
@@ -4140,9 +4141,9 @@ int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha)
4140 } 4141 }
4141 4142
4142 ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, 4143 ql_dbg(ql_dbg_tgt, base_vha, 0xe03b,
4143 "Registering target for host %ld(%p)", base_vha->host_no, ha); 4144 "Registering target for host %ld(%p).\n", base_vha->host_no, ha);
4144 4145
4145 BUG_ON((ha->tgt.qla_tgt != NULL) || (ha->tgt.tgt_ops != NULL)); 4146 BUG_ON(base_vha->vha_tgt.qla_tgt != NULL);
4146 4147
4147 tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); 4148 tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL);
4148 if (!tgt) { 4149 if (!tgt) {
@@ -4170,7 +4171,7 @@ int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha)
4170 INIT_WORK(&tgt->srr_work, qlt_handle_srr_work); 4171 INIT_WORK(&tgt->srr_work, qlt_handle_srr_work);
4171 atomic_set(&tgt->tgt_global_resets_count, 0); 4172 atomic_set(&tgt->tgt_global_resets_count, 0);
4172 4173
4173 ha->tgt.qla_tgt = tgt; 4174 base_vha->vha_tgt.qla_tgt = tgt;
4174 4175
4175 ql_dbg(ql_dbg_tgt, base_vha, 0xe067, 4176 ql_dbg(ql_dbg_tgt, base_vha, 0xe067,
4176 "qla_target(%d): using 64 Bit PCI addressing", 4177 "qla_target(%d): using 64 Bit PCI addressing",
@@ -4191,16 +4192,16 @@ int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha)
4191/* Must be called under tgt_host_action_mutex */ 4192/* Must be called under tgt_host_action_mutex */
4192int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) 4193int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha)
4193{ 4194{
4194 if (!ha->tgt.qla_tgt) 4195 if (!vha->vha_tgt.qla_tgt)
4195 return 0; 4196 return 0;
4196 4197
4197 mutex_lock(&qla_tgt_mutex); 4198 mutex_lock(&qla_tgt_mutex);
4198 list_del(&ha->tgt.qla_tgt->tgt_list_entry); 4199 list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry);
4199 mutex_unlock(&qla_tgt_mutex); 4200 mutex_unlock(&qla_tgt_mutex);
4200 4201
4201 ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", 4202 ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)",
4202 vha->host_no, ha); 4203 vha->host_no, ha);
4203 qlt_release(ha->tgt.qla_tgt); 4204 qlt_release(vha->vha_tgt.qla_tgt);
4204 4205
4205 return 0; 4206 return 0;
4206} 4207}
@@ -4254,9 +4255,6 @@ int qlt_lport_register(struct qla_tgt_func_tmpl *qla_tgt_ops, u64 wwpn,
4254 if (!host) 4255 if (!host)
4255 continue; 4256 continue;
4256 4257
4257 if (ha->tgt.tgt_ops != NULL)
4258 continue;
4259
4260 if (!(host->hostt->supported_mode & MODE_TARGET)) 4258 if (!(host->hostt->supported_mode & MODE_TARGET))
4261 continue; 4259 continue;
4262 4260
@@ -4285,11 +4283,11 @@ int qlt_lport_register(struct qla_tgt_func_tmpl *qla_tgt_ops, u64 wwpn,
4285 * Setup passed parameters ahead of invoking callback 4283 * Setup passed parameters ahead of invoking callback
4286 */ 4284 */
4287 ha->tgt.tgt_ops = qla_tgt_ops; 4285 ha->tgt.tgt_ops = qla_tgt_ops;
4288 ha->tgt.target_lport_ptr = target_lport_ptr; 4286 vha->vha_tgt.target_lport_ptr = target_lport_ptr;
4289 rc = (*callback)(vha); 4287 rc = (*callback)(vha);
4290 if (rc != 0) { 4288 if (rc != 0) {
4291 ha->tgt.tgt_ops = NULL; 4289 ha->tgt.tgt_ops = NULL;
4292 ha->tgt.target_lport_ptr = NULL; 4290 vha->vha_tgt.target_lport_ptr = NULL;
4293 scsi_host_put(host); 4291 scsi_host_put(host);
4294 } 4292 }
4295 mutex_unlock(&qla_tgt_mutex); 4293 mutex_unlock(&qla_tgt_mutex);
@@ -4313,7 +4311,7 @@ void qlt_lport_deregister(struct scsi_qla_host *vha)
4313 /* 4311 /*
4314 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data 4312 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
4315 */ 4313 */
4316 ha->tgt.target_lport_ptr = NULL; 4314 vha->vha_tgt.target_lport_ptr = NULL;
4317 ha->tgt.tgt_ops = NULL; 4315 ha->tgt.tgt_ops = NULL;
4318 /* 4316 /*
4319 * Release the Scsi_Host reference for the underlying qla2xxx host 4317 * Release the Scsi_Host reference for the underlying qla2xxx host
@@ -4375,8 +4373,9 @@ void
4375qlt_enable_vha(struct scsi_qla_host *vha) 4373qlt_enable_vha(struct scsi_qla_host *vha)
4376{ 4374{
4377 struct qla_hw_data *ha = vha->hw; 4375 struct qla_hw_data *ha = vha->hw;
4378 struct qla_tgt *tgt = ha->tgt.qla_tgt; 4376 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4379 unsigned long flags; 4377 unsigned long flags;
4378 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4380 4379
4381 if (!tgt) { 4380 if (!tgt) {
4382 ql_dbg(ql_dbg_tgt, vha, 0xe069, 4381 ql_dbg(ql_dbg_tgt, vha, 0xe069,
@@ -4391,9 +4390,14 @@ qlt_enable_vha(struct scsi_qla_host *vha)
4391 qlt_set_mode(vha); 4390 qlt_set_mode(vha);
4392 spin_unlock_irqrestore(&ha->hardware_lock, flags); 4391 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4393 4392
4394 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); 4393 if (vha->vp_idx) {
4395 qla2xxx_wake_dpc(vha); 4394 qla24xx_disable_vp(vha);
4396 qla2x00_wait_for_hba_online(vha); 4395 qla24xx_enable_vp(vha);
4396 } else {
4397 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
4398 qla2xxx_wake_dpc(base_vha);
4399 qla2x00_wait_for_hba_online(base_vha);
4400 }
4397} 4401}
4398EXPORT_SYMBOL(qlt_enable_vha); 4402EXPORT_SYMBOL(qlt_enable_vha);
4399 4403
@@ -4406,7 +4410,7 @@ void
4406qlt_disable_vha(struct scsi_qla_host *vha) 4410qlt_disable_vha(struct scsi_qla_host *vha)
4407{ 4411{
4408 struct qla_hw_data *ha = vha->hw; 4412 struct qla_hw_data *ha = vha->hw;
4409 struct qla_tgt *tgt = ha->tgt.qla_tgt; 4413 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
4410 unsigned long flags; 4414 unsigned long flags;
4411 4415
4412 if (!tgt) { 4416 if (!tgt) {
@@ -4437,8 +4441,10 @@ qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha)
4437 if (!qla_tgt_mode_enabled(vha)) 4441 if (!qla_tgt_mode_enabled(vha))
4438 return; 4442 return;
4439 4443
4440 mutex_init(&ha->tgt.tgt_mutex); 4444 vha->vha_tgt.qla_tgt = NULL;
4441 mutex_init(&ha->tgt.tgt_host_action_mutex); 4445
4446 mutex_init(&vha->vha_tgt.tgt_mutex);
4447 mutex_init(&vha->vha_tgt.tgt_host_action_mutex);
4442 4448
4443 qlt_clear_mode(vha); 4449 qlt_clear_mode(vha);
4444 4450
@@ -4449,6 +4455,8 @@ qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha)
4449 * assigning the value appropriately. 4455 * assigning the value appropriately.
4450 */ 4456 */
4451 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; 4457 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
4458
4459 qlt_add_target(ha, vha);
4452} 4460}
4453 4461
4454void 4462void
@@ -4767,8 +4775,8 @@ qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha)
4767 ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; 4775 ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out;
4768 } 4776 }
4769 4777
4770 mutex_init(&ha->tgt.tgt_mutex); 4778 mutex_init(&base_vha->vha_tgt.tgt_mutex);
4771 mutex_init(&ha->tgt.tgt_host_action_mutex); 4779 mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex);
4772 qlt_clear_mode(base_vha); 4780 qlt_clear_mode(base_vha);
4773} 4781}
4774 4782
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 7eb19be35d46..113ca95d47df 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -53,16 +53,6 @@
53struct workqueue_struct *tcm_qla2xxx_free_wq; 53struct workqueue_struct *tcm_qla2xxx_free_wq;
54struct workqueue_struct *tcm_qla2xxx_cmd_wq; 54struct workqueue_struct *tcm_qla2xxx_cmd_wq;
55 55
56static int tcm_qla2xxx_check_true(struct se_portal_group *se_tpg)
57{
58 return 1;
59}
60
61static int tcm_qla2xxx_check_false(struct se_portal_group *se_tpg)
62{
63 return 0;
64}
65
66/* 56/*
67 * Parse WWN. 57 * Parse WWN.
68 * If strict, we require lower-case hex and colon separators to be sure 58 * If strict, we require lower-case hex and colon separators to be sure
@@ -174,7 +164,7 @@ static int tcm_qla2xxx_npiv_parse_wwn(
174 *wwnn = 0; 164 *wwnn = 0;
175 165
176 /* count may include a LF at end of string */ 166 /* count may include a LF at end of string */
177 if (name[cnt-1] == '\n') 167 if (name[cnt-1] == '\n' || name[cnt-1] == 0)
178 cnt--; 168 cnt--;
179 169
180 /* validate we have enough characters for WWPN */ 170 /* validate we have enough characters for WWPN */
@@ -777,6 +767,9 @@ static void tcm_qla2xxx_put_session(struct se_session *se_sess)
777 767
778static void tcm_qla2xxx_put_sess(struct qla_tgt_sess *sess) 768static void tcm_qla2xxx_put_sess(struct qla_tgt_sess *sess)
779{ 769{
770 if (!sess)
771 return;
772
780 assert_spin_locked(&sess->vha->hw->hardware_lock); 773 assert_spin_locked(&sess->vha->hw->hardware_lock);
781 kref_put(&sess->se_sess->sess_kref, tcm_qla2xxx_release_session); 774 kref_put(&sess->se_sess->sess_kref, tcm_qla2xxx_release_session);
782} 775}
@@ -957,7 +950,6 @@ static ssize_t tcm_qla2xxx_tpg_store_enable(
957 struct tcm_qla2xxx_lport *lport = container_of(se_wwn, 950 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
958 struct tcm_qla2xxx_lport, lport_wwn); 951 struct tcm_qla2xxx_lport, lport_wwn);
959 struct scsi_qla_host *vha = lport->qla_vha; 952 struct scsi_qla_host *vha = lport->qla_vha;
960 struct qla_hw_data *ha = vha->hw;
961 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 953 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
962 struct tcm_qla2xxx_tpg, se_tpg); 954 struct tcm_qla2xxx_tpg, se_tpg);
963 unsigned long op; 955 unsigned long op;
@@ -977,12 +969,12 @@ static ssize_t tcm_qla2xxx_tpg_store_enable(
977 atomic_set(&tpg->lport_tpg_enabled, 1); 969 atomic_set(&tpg->lport_tpg_enabled, 1);
978 qlt_enable_vha(vha); 970 qlt_enable_vha(vha);
979 } else { 971 } else {
980 if (!ha->tgt.qla_tgt) { 972 if (!vha->vha_tgt.qla_tgt) {
981 pr_err("truct qla_hw_data *ha->tgt.qla_tgt is NULL\n"); 973 pr_err("struct qla_hw_data *vha->vha_tgt.qla_tgt is NULL\n");
982 return -ENODEV; 974 return -ENODEV;
983 } 975 }
984 atomic_set(&tpg->lport_tpg_enabled, 0); 976 atomic_set(&tpg->lport_tpg_enabled, 0);
985 qlt_stop_phase1(ha->tgt.qla_tgt); 977 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
986 } 978 }
987 979
988 return count; 980 return count;
@@ -1011,7 +1003,7 @@ static struct se_portal_group *tcm_qla2xxx_make_tpg(
1011 if (kstrtoul(name + 5, 10, &tpgt) || tpgt > USHRT_MAX) 1003 if (kstrtoul(name + 5, 10, &tpgt) || tpgt > USHRT_MAX)
1012 return ERR_PTR(-EINVAL); 1004 return ERR_PTR(-EINVAL);
1013 1005
1014 if (!lport->qla_npiv_vp && (tpgt != 1)) { 1006 if ((tpgt != 1)) {
1015 pr_err("In non NPIV mode, a single TPG=1 is used for HW port mappings\n"); 1007 pr_err("In non NPIV mode, a single TPG=1 is used for HW port mappings\n");
1016 return ERR_PTR(-ENOSYS); 1008 return ERR_PTR(-ENOSYS);
1017 } 1009 }
@@ -1038,11 +1030,8 @@ static struct se_portal_group *tcm_qla2xxx_make_tpg(
1038 kfree(tpg); 1030 kfree(tpg);
1039 return NULL; 1031 return NULL;
1040 } 1032 }
1041 /* 1033
1042 * Setup local TPG=1 pointer for non NPIV mode. 1034 lport->tpg_1 = tpg;
1043 */
1044 if (lport->qla_npiv_vp == NULL)
1045 lport->tpg_1 = tpg;
1046 1035
1047 return &tpg->se_tpg; 1036 return &tpg->se_tpg;
1048} 1037}
@@ -1053,19 +1042,17 @@ static void tcm_qla2xxx_drop_tpg(struct se_portal_group *se_tpg)
1053 struct tcm_qla2xxx_tpg, se_tpg); 1042 struct tcm_qla2xxx_tpg, se_tpg);
1054 struct tcm_qla2xxx_lport *lport = tpg->lport; 1043 struct tcm_qla2xxx_lport *lport = tpg->lport;
1055 struct scsi_qla_host *vha = lport->qla_vha; 1044 struct scsi_qla_host *vha = lport->qla_vha;
1056 struct qla_hw_data *ha = vha->hw;
1057 /* 1045 /*
1058 * Call into qla2x_target.c LLD logic to shutdown the active 1046 * Call into qla2x_target.c LLD logic to shutdown the active
1059 * FC Nexuses and disable target mode operation for this qla_hw_data 1047 * FC Nexuses and disable target mode operation for this qla_hw_data
1060 */ 1048 */
1061 if (ha->tgt.qla_tgt && !ha->tgt.qla_tgt->tgt_stop) 1049 if (vha->vha_tgt.qla_tgt && !vha->vha_tgt.qla_tgt->tgt_stop)
1062 qlt_stop_phase1(ha->tgt.qla_tgt); 1050 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
1063 1051
1064 core_tpg_deregister(se_tpg); 1052 core_tpg_deregister(se_tpg);
1065 /* 1053 /*
1066 * Clear local TPG=1 pointer for non NPIV mode. 1054 * Clear local TPG=1 pointer for non NPIV mode.
1067 */ 1055 */
1068 if (lport->qla_npiv_vp == NULL)
1069 lport->tpg_1 = NULL; 1056 lport->tpg_1 = NULL;
1070 1057
1071 kfree(tpg); 1058 kfree(tpg);
@@ -1095,12 +1082,22 @@ static struct se_portal_group *tcm_qla2xxx_npiv_make_tpg(
1095 tpg->lport = lport; 1082 tpg->lport = lport;
1096 tpg->lport_tpgt = tpgt; 1083 tpg->lport_tpgt = tpgt;
1097 1084
1085 /*
1086 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1087 * NodeACLs
1088 */
1089 tpg->tpg_attrib.generate_node_acls = 1;
1090 tpg->tpg_attrib.demo_mode_write_protect = 1;
1091 tpg->tpg_attrib.cache_dynamic_acls = 1;
1092 tpg->tpg_attrib.demo_mode_login_only = 1;
1093
1098 ret = core_tpg_register(&tcm_qla2xxx_npiv_fabric_configfs->tf_ops, wwn, 1094 ret = core_tpg_register(&tcm_qla2xxx_npiv_fabric_configfs->tf_ops, wwn,
1099 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); 1095 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL);
1100 if (ret < 0) { 1096 if (ret < 0) {
1101 kfree(tpg); 1097 kfree(tpg);
1102 return NULL; 1098 return NULL;
1103 } 1099 }
1100 lport->tpg_1 = tpg;
1104 return &tpg->se_tpg; 1101 return &tpg->se_tpg;
1105} 1102}
1106 1103
@@ -1111,13 +1108,12 @@ static struct qla_tgt_sess *tcm_qla2xxx_find_sess_by_s_id(
1111 scsi_qla_host_t *vha, 1108 scsi_qla_host_t *vha,
1112 const uint8_t *s_id) 1109 const uint8_t *s_id)
1113{ 1110{
1114 struct qla_hw_data *ha = vha->hw;
1115 struct tcm_qla2xxx_lport *lport; 1111 struct tcm_qla2xxx_lport *lport;
1116 struct se_node_acl *se_nacl; 1112 struct se_node_acl *se_nacl;
1117 struct tcm_qla2xxx_nacl *nacl; 1113 struct tcm_qla2xxx_nacl *nacl;
1118 u32 key; 1114 u32 key;
1119 1115
1120 lport = ha->tgt.target_lport_ptr; 1116 lport = vha->vha_tgt.target_lport_ptr;
1121 if (!lport) { 1117 if (!lport) {
1122 pr_err("Unable to locate struct tcm_qla2xxx_lport\n"); 1118 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1123 dump_stack(); 1119 dump_stack();
@@ -1221,13 +1217,12 @@ static struct qla_tgt_sess *tcm_qla2xxx_find_sess_by_loop_id(
1221 scsi_qla_host_t *vha, 1217 scsi_qla_host_t *vha,
1222 const uint16_t loop_id) 1218 const uint16_t loop_id)
1223{ 1219{
1224 struct qla_hw_data *ha = vha->hw;
1225 struct tcm_qla2xxx_lport *lport; 1220 struct tcm_qla2xxx_lport *lport;
1226 struct se_node_acl *se_nacl; 1221 struct se_node_acl *se_nacl;
1227 struct tcm_qla2xxx_nacl *nacl; 1222 struct tcm_qla2xxx_nacl *nacl;
1228 struct tcm_qla2xxx_fc_loopid *fc_loopid; 1223 struct tcm_qla2xxx_fc_loopid *fc_loopid;
1229 1224
1230 lport = ha->tgt.target_lport_ptr; 1225 lport = vha->vha_tgt.target_lport_ptr;
1231 if (!lport) { 1226 if (!lport) {
1232 pr_err("Unable to locate struct tcm_qla2xxx_lport\n"); 1227 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1233 dump_stack(); 1228 dump_stack();
@@ -1341,6 +1336,7 @@ static void tcm_qla2xxx_free_session(struct qla_tgt_sess *sess)
1341{ 1336{
1342 struct qla_tgt *tgt = sess->tgt; 1337 struct qla_tgt *tgt = sess->tgt;
1343 struct qla_hw_data *ha = tgt->ha; 1338 struct qla_hw_data *ha = tgt->ha;
1339 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1344 struct se_session *se_sess; 1340 struct se_session *se_sess;
1345 struct se_node_acl *se_nacl; 1341 struct se_node_acl *se_nacl;
1346 struct tcm_qla2xxx_lport *lport; 1342 struct tcm_qla2xxx_lport *lport;
@@ -1357,7 +1353,7 @@ static void tcm_qla2xxx_free_session(struct qla_tgt_sess *sess)
1357 se_nacl = se_sess->se_node_acl; 1353 se_nacl = se_sess->se_node_acl;
1358 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl); 1354 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
1359 1355
1360 lport = ha->tgt.target_lport_ptr; 1356 lport = vha->vha_tgt.target_lport_ptr;
1361 if (!lport) { 1357 if (!lport) {
1362 pr_err("Unable to locate struct tcm_qla2xxx_lport\n"); 1358 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1363 dump_stack(); 1359 dump_stack();
@@ -1391,7 +1387,7 @@ static int tcm_qla2xxx_check_initiator_node_acl(
1391 unsigned char port_name[36]; 1387 unsigned char port_name[36];
1392 unsigned long flags; 1388 unsigned long flags;
1393 1389
1394 lport = ha->tgt.target_lport_ptr; 1390 lport = vha->vha_tgt.target_lport_ptr;
1395 if (!lport) { 1391 if (!lport) {
1396 pr_err("Unable to locate struct tcm_qla2xxx_lport\n"); 1392 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1397 dump_stack(); 1393 dump_stack();
@@ -1455,7 +1451,8 @@ static void tcm_qla2xxx_update_sess(struct qla_tgt_sess *sess, port_id_t s_id,
1455{ 1451{
1456 struct qla_tgt *tgt = sess->tgt; 1452 struct qla_tgt *tgt = sess->tgt;
1457 struct qla_hw_data *ha = tgt->ha; 1453 struct qla_hw_data *ha = tgt->ha;
1458 struct tcm_qla2xxx_lport *lport = ha->tgt.target_lport_ptr; 1454 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1455 struct tcm_qla2xxx_lport *lport = vha->vha_tgt.target_lport_ptr;
1459 struct se_node_acl *se_nacl = sess->se_sess->se_node_acl; 1456 struct se_node_acl *se_nacl = sess->se_sess->se_node_acl;
1460 struct tcm_qla2xxx_nacl *nacl = container_of(se_nacl, 1457 struct tcm_qla2xxx_nacl *nacl = container_of(se_nacl,
1461 struct tcm_qla2xxx_nacl, se_node_acl); 1458 struct tcm_qla2xxx_nacl, se_node_acl);
@@ -1564,13 +1561,12 @@ static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport *lport)
1564 1561
1565static int tcm_qla2xxx_lport_register_cb(struct scsi_qla_host *vha) 1562static int tcm_qla2xxx_lport_register_cb(struct scsi_qla_host *vha)
1566{ 1563{
1567 struct qla_hw_data *ha = vha->hw;
1568 struct tcm_qla2xxx_lport *lport; 1564 struct tcm_qla2xxx_lport *lport;
1569 /* 1565 /*
1570 * Setup local pointer to vha, NPIV VP pointer (if present) and 1566 * Setup local pointer to vha, NPIV VP pointer (if present) and
1571 * vha->tcm_lport pointer 1567 * vha->tcm_lport pointer
1572 */ 1568 */
1573 lport = (struct tcm_qla2xxx_lport *)ha->tgt.target_lport_ptr; 1569 lport = (struct tcm_qla2xxx_lport *)vha->vha_tgt.target_lport_ptr;
1574 lport->qla_vha = vha; 1570 lport->qla_vha = vha;
1575 1571
1576 return 0; 1572 return 0;
@@ -1621,7 +1617,6 @@ static void tcm_qla2xxx_drop_lport(struct se_wwn *wwn)
1621 struct tcm_qla2xxx_lport *lport = container_of(wwn, 1617 struct tcm_qla2xxx_lport *lport = container_of(wwn,
1622 struct tcm_qla2xxx_lport, lport_wwn); 1618 struct tcm_qla2xxx_lport, lport_wwn);
1623 struct scsi_qla_host *vha = lport->qla_vha; 1619 struct scsi_qla_host *vha = lport->qla_vha;
1624 struct qla_hw_data *ha = vha->hw;
1625 struct se_node_acl *node; 1620 struct se_node_acl *node;
1626 u32 key = 0; 1621 u32 key = 0;
1627 1622
@@ -1630,8 +1625,8 @@ static void tcm_qla2xxx_drop_lport(struct se_wwn *wwn)
1630 * shutdown of struct qla_tgt after the call to 1625 * shutdown of struct qla_tgt after the call to
1631 * qlt_stop_phase1() from tcm_qla2xxx_drop_tpg() above.. 1626 * qlt_stop_phase1() from tcm_qla2xxx_drop_tpg() above..
1632 */ 1627 */
1633 if (ha->tgt.qla_tgt && !ha->tgt.qla_tgt->tgt_stopped) 1628 if (vha->vha_tgt.qla_tgt && !vha->vha_tgt.qla_tgt->tgt_stopped)
1634 qlt_stop_phase2(ha->tgt.qla_tgt); 1629 qlt_stop_phase2(vha->vha_tgt.qla_tgt);
1635 1630
1636 qlt_lport_deregister(vha); 1631 qlt_lport_deregister(vha);
1637 1632
@@ -1650,6 +1645,9 @@ static struct se_wwn *tcm_qla2xxx_npiv_make_lport(
1650 struct tcm_qla2xxx_lport *lport; 1645 struct tcm_qla2xxx_lport *lport;
1651 u64 npiv_wwpn, npiv_wwnn; 1646 u64 npiv_wwpn, npiv_wwnn;
1652 int ret; 1647 int ret;
1648 struct scsi_qla_host *vha = NULL;
1649 struct qla_hw_data *ha = NULL;
1650 scsi_qla_host_t *base_vha = NULL;
1653 1651
1654 if (tcm_qla2xxx_npiv_parse_wwn(name, strlen(name)+1, 1652 if (tcm_qla2xxx_npiv_parse_wwn(name, strlen(name)+1,
1655 &npiv_wwpn, &npiv_wwnn) < 0) 1653 &npiv_wwpn, &npiv_wwnn) < 0)
@@ -1666,12 +1664,29 @@ static struct se_wwn *tcm_qla2xxx_npiv_make_lport(
1666 TCM_QLA2XXX_NAMELEN, npiv_wwpn, npiv_wwnn); 1664 TCM_QLA2XXX_NAMELEN, npiv_wwpn, npiv_wwnn);
1667 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) npiv_wwpn); 1665 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) npiv_wwpn);
1668 1666
1669/* FIXME: tcm_qla2xxx_npiv_make_lport */ 1667 ret = tcm_qla2xxx_init_lport(lport);
1670 ret = -ENOSYS;
1671 if (ret != 0) 1668 if (ret != 0)
1672 goto out; 1669 goto out;
1673 1670
1671 ret = qlt_lport_register(&tcm_qla2xxx_template, npiv_wwpn,
1672 tcm_qla2xxx_lport_register_cb, lport);
1673
1674 if (ret != 0)
1675 goto out_lport;
1676
1677 vha = lport->qla_vha;
1678 ha = vha->hw;
1679 base_vha = pci_get_drvdata(ha->pdev);
1680
1681 if (!qla_tgt_mode_enabled(base_vha)) {
1682 ret = -EPERM;
1683 goto out_lport;
1684 }
1685
1674 return &lport->lport_wwn; 1686 return &lport->lport_wwn;
1687out_lport:
1688 vfree(lport->lport_loopid_map);
1689 btree_destroy32(&lport->lport_fcport_map);
1675out: 1690out:
1676 kfree(lport); 1691 kfree(lport);
1677 return ERR_PTR(ret); 1692 return ERR_PTR(ret);
@@ -1684,9 +1699,9 @@ static void tcm_qla2xxx_npiv_drop_lport(struct se_wwn *wwn)
1684 struct scsi_qla_host *vha = lport->qla_vha; 1699 struct scsi_qla_host *vha = lport->qla_vha;
1685 struct Scsi_Host *sh = vha->host; 1700 struct Scsi_Host *sh = vha->host;
1686 /* 1701 /*
1687 * Notify libfc that we want to release the lport->npiv_vport 1702 * Notify libfc that we want to release the vha->fc_vport
1688 */ 1703 */
1689 fc_vport_terminate(lport->npiv_vport); 1704 fc_vport_terminate(vha->fc_vport);
1690 1705
1691 scsi_host_put(sh); 1706 scsi_host_put(sh);
1692 kfree(lport); 1707 kfree(lport);
@@ -1769,14 +1784,16 @@ static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
1769 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id, 1784 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id,
1770 .tpg_get_pr_transport_id_len = tcm_qla2xxx_get_pr_transport_id_len, 1785 .tpg_get_pr_transport_id_len = tcm_qla2xxx_get_pr_transport_id_len,
1771 .tpg_parse_pr_out_transport_id = tcm_qla2xxx_parse_pr_out_transport_id, 1786 .tpg_parse_pr_out_transport_id = tcm_qla2xxx_parse_pr_out_transport_id,
1772 .tpg_check_demo_mode = tcm_qla2xxx_check_false, 1787 .tpg_check_demo_mode = tcm_qla2xxx_check_demo_mode,
1773 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_true, 1788 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_demo_mode_cache,
1774 .tpg_check_demo_mode_write_protect = tcm_qla2xxx_check_true, 1789 .tpg_check_demo_mode_write_protect = tcm_qla2xxx_check_demo_mode,
1775 .tpg_check_prod_mode_write_protect = tcm_qla2xxx_check_false, 1790 .tpg_check_prod_mode_write_protect =
1791 tcm_qla2xxx_check_prod_write_protect,
1776 .tpg_check_demo_mode_login_only = tcm_qla2xxx_check_demo_mode_login_only, 1792 .tpg_check_demo_mode_login_only = tcm_qla2xxx_check_demo_mode_login_only,
1777 .tpg_alloc_fabric_acl = tcm_qla2xxx_alloc_fabric_acl, 1793 .tpg_alloc_fabric_acl = tcm_qla2xxx_alloc_fabric_acl,
1778 .tpg_release_fabric_acl = tcm_qla2xxx_release_fabric_acl, 1794 .tpg_release_fabric_acl = tcm_qla2xxx_release_fabric_acl,
1779 .tpg_get_inst_index = tcm_qla2xxx_tpg_get_inst_index, 1795 .tpg_get_inst_index = tcm_qla2xxx_tpg_get_inst_index,
1796 .check_stop_free = tcm_qla2xxx_check_stop_free,
1780 .release_cmd = tcm_qla2xxx_release_cmd, 1797 .release_cmd = tcm_qla2xxx_release_cmd,
1781 .put_session = tcm_qla2xxx_put_session, 1798 .put_session = tcm_qla2xxx_put_session,
1782 .shutdown_session = tcm_qla2xxx_shutdown_session, 1799 .shutdown_session = tcm_qla2xxx_shutdown_session,
@@ -1871,7 +1888,8 @@ static int tcm_qla2xxx_register_configfs(void)
1871 * Setup default attribute lists for various npiv_fabric->tf_cit_tmpl 1888 * Setup default attribute lists for various npiv_fabric->tf_cit_tmpl
1872 */ 1889 */
1873 npiv_fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs; 1890 npiv_fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs;
1874 npiv_fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = NULL; 1891 npiv_fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs =
1892 tcm_qla2xxx_tpg_attrs;
1875 npiv_fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL; 1893 npiv_fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
1876 npiv_fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL; 1894 npiv_fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
1877 npiv_fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; 1895 npiv_fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.h b/drivers/scsi/qla2xxx/tcm_qla2xxx.h
index 771f7b816443..275d8b9a7a34 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.h
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.h
@@ -70,12 +70,8 @@ struct tcm_qla2xxx_lport {
70 struct tcm_qla2xxx_fc_loopid *lport_loopid_map; 70 struct tcm_qla2xxx_fc_loopid *lport_loopid_map;
71 /* Pointer to struct scsi_qla_host from qla2xxx LLD */ 71 /* Pointer to struct scsi_qla_host from qla2xxx LLD */
72 struct scsi_qla_host *qla_vha; 72 struct scsi_qla_host *qla_vha;
73 /* Pointer to struct scsi_qla_host for NPIV VP from qla2xxx LLD */
74 struct scsi_qla_host *qla_npiv_vp;
75 /* Pointer to struct qla_tgt pointer */ 73 /* Pointer to struct qla_tgt pointer */
76 struct qla_tgt lport_qla_tgt; 74 struct qla_tgt lport_qla_tgt;
77 /* Pointer to struct fc_vport for NPIV vport from libfc */
78 struct fc_vport *npiv_vport;
79 /* Pointer to TPG=1 for non NPIV mode */ 75 /* Pointer to TPG=1 for non NPIV mode */
80 struct tcm_qla2xxx_tpg *tpg_1; 76 struct tcm_qla2xxx_tpg *tpg_1;
81 /* Returned by tcm_qla2xxx_make_lport() */ 77 /* Returned by tcm_qla2xxx_make_lport() */