#include "fabrics.h"
 #include <linux/nvme-fc-driver.h>
 #include <linux/nvme-fc.h>
-
+#include <scsi/scsi_transport_fc.h>
 
 /* *************************** Data Structures/Defines ****************** */
 
 
        rdata->pnode = lpfc_nlp_get(ndlp);
 
        if (ndlp->nlp_type & NLP_FCP_TARGET)
-               rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
+               rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
        if (ndlp->nlp_type & NLP_FCP_INITIATOR)
-               rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
+               rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
+       if (ndlp->nlp_type & NLP_NVME_INITIATOR)
+               rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
+       if (ndlp->nlp_type & NLP_NVME_TARGET)
+               rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
+       if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
+               rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
 
        if (rport_ids.roles !=  FC_RPORT_ROLE_UNKNOWN)
                fc_remote_port_rolechg(rport, rport_ids.roles);
 
        FCT_BROADCAST,
        FCT_INITIATOR,
        FCT_TARGET,
-       FCT_NVME
+       FCT_NVME_INITIATOR = 0x10,
+       FCT_NVME_TARGET = 0x20,
+       FCT_NVME_DISCOVERY = 0x40,
+       FCT_NVME = 0xf0,
 } fc_port_type_t;
 
 enum qla_sess_deletion {
 
 
        rport->supported_classes = fcport->supported_classes;
 
-       rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
+       rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
        if (fcport->port_type == FCT_INITIATOR)
-               rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
+               rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
        if (fcport->port_type == FCT_TARGET)
-               rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
+               rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
+       if (fcport->port_type & FCT_NVME_INITIATOR)
+               rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
+       if (fcport->port_type & FCT_NVME_TARGET)
+               rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
+       if (fcport->port_type & FCT_NVME_DISCOVERY)
+               rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
 
        ql_dbg(ql_dbg_disc, vha, 0x20ee,
            "%s %8phN. rport %p is %s mode\n",
            __func__, fcport->port_name, rport,
-           (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
+           (fcport->port_type == FCT_TARGET) ? "tgt" :
+           ((fcport->port_type & FCT_NVME) ? "nvme" :"ini"));
 
        fc_remote_port_rolechg(rport, rport_ids.roles);
 }
 
        fcport->d_id.b.rsvd_1 = 0;
 
        if (fcport->fc4f_nvme) {
-               fcport->port_type = FCT_NVME;
+               fcport->port_type = 0;
+               if ((pd->prli_svc_param_word_3[0] & BIT_5) == 0)
+                       fcport->port_type |= FCT_NVME_INITIATOR;
+               if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
+                       fcport->port_type |= FCT_NVME_TARGET;
+               if ((pd->prli_svc_param_word_3[0] & BIT_3) == 0)
+                       fcport->port_type |= FCT_NVME_DISCOVERY;
        } else {
                /* If not target must be initiator or unknown type. */
                if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
 
        { FC_PORT_ROLE_FCP_INITIATOR,           "FCP Initiator" },
        { FC_PORT_ROLE_IP_PORT,                 "IP Port" },
        { FC_PORT_ROLE_FCP_DUMMY_INITIATOR,     "FCP Dummy Initiator" },
+       { FC_PORT_ROLE_NVME_INITIATOR,          "NVMe Initiator" },
+       { FC_PORT_ROLE_NVME_TARGET,             "NVMe Target" },
+       { FC_PORT_ROLE_NVME_DISCOVERY,          "NVMe Discovery" },
 };
 fc_bitfield_name_search(port_roles, fc_port_role_names)
 
 
 
 
 
-/* FC Port role bitmask - can merge with FC Port Roles in fc transport */
-#define FC_PORT_ROLE_NVME_INITIATOR    0x10
-#define FC_PORT_ROLE_NVME_TARGET       0x20
-#define FC_PORT_ROLE_NVME_DISCOVERY    0x40
-
-
 /**
  * struct nvme_fc_port_info - port-specific ids and FC connection-specific
  *                            data element used during NVME Host role
 
 #define FC_PORT_ROLE_FCP_INITIATOR             0x02
 #define FC_PORT_ROLE_IP_PORT                   0x04
 #define FC_PORT_ROLE_FCP_DUMMY_INITIATOR       0x08
+#define FC_PORT_ROLE_NVME_INITIATOR            0x10
+#define FC_PORT_ROLE_NVME_TARGET               0x20
+#define FC_PORT_ROLE_NVME_DISCOVERY            0x40
 
 /* The following are for compatibility */
 #define FC_RPORT_ROLE_UNKNOWN                  FC_PORT_ROLE_UNKNOWN