Commit 3236fd61 authored by Bart Van Assche's avatar Bart Van Assche Committed by Jason Gunthorpe

RDMA/srpt: Make the code for handling port identities more systematic

Introduce a new data structure for the information about an RDMA port
name. This patch does not change any functionality.

Link: https://lore.kernel.org/r/20190930231707.48259-15-bvanassche@acm.org
Cc: Honggang LI <honli@redhat.com>
Cc: Laurence Oberman <loberman@redhat.com>
Signed-off-by: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent be408e65
...@@ -567,11 +567,12 @@ static int srpt_refresh_port(struct srpt_port *sport) ...@@ -567,11 +567,12 @@ static int srpt_refresh_port(struct srpt_port *sport)
if (ret) if (ret)
return ret; return ret;
sport->port_guid_wwn.priv = sport; sport->port_guid_id.wwn.priv = sport;
srpt_format_guid(sport->port_guid, sizeof(sport->port_guid), srpt_format_guid(sport->port_guid_id.name,
sizeof(sport->port_guid_id.name),
&sport->gid.global.interface_id); &sport->gid.global.interface_id);
sport->port_gid_wwn.priv = sport; sport->port_gid_id.wwn.priv = sport;
snprintf(sport->port_gid, sizeof(sport->port_gid), snprintf(sport->port_gid_id.name, sizeof(sport->port_gid_id.name),
"0x%016llx%016llx", "0x%016llx%016llx",
be64_to_cpu(sport->gid.global.subnet_prefix), be64_to_cpu(sport->gid.global.subnet_prefix),
be64_to_cpu(sport->gid.global.interface_id)); be64_to_cpu(sport->gid.global.interface_id));
...@@ -2287,17 +2288,17 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev, ...@@ -2287,17 +2288,17 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
tag_num = ch->rq_size; tag_num = ch->rq_size;
tag_size = 1; /* ib_srpt does not use se_sess->sess_cmd_map */ tag_size = 1; /* ib_srpt does not use se_sess->sess_cmd_map */
if (sport->port_guid_tpg.se_tpg_wwn) if (sport->port_guid_id.tpg.se_tpg_wwn)
ch->sess = target_setup_session(&sport->port_guid_tpg, tag_num, ch->sess = target_setup_session(&sport->port_guid_id.tpg, tag_num,
tag_size, TARGET_PROT_NORMAL, tag_size, TARGET_PROT_NORMAL,
ch->sess_name, ch, NULL); ch->sess_name, ch, NULL);
if (sport->port_gid_tpg.se_tpg_wwn && IS_ERR_OR_NULL(ch->sess)) if (sport->port_gid_id.tpg.se_tpg_wwn && IS_ERR_OR_NULL(ch->sess))
ch->sess = target_setup_session(&sport->port_gid_tpg, tag_num, ch->sess = target_setup_session(&sport->port_gid_id.tpg, tag_num,
tag_size, TARGET_PROT_NORMAL, i_port_id, tag_size, TARGET_PROT_NORMAL, i_port_id,
ch, NULL); ch, NULL);
/* Retry without leading "0x" */ /* Retry without leading "0x" */
if (sport->port_gid_tpg.se_tpg_wwn && IS_ERR_OR_NULL(ch->sess)) if (sport->port_gid_id.tpg.se_tpg_wwn && IS_ERR_OR_NULL(ch->sess))
ch->sess = target_setup_session(&sport->port_gid_tpg, tag_num, ch->sess = target_setup_session(&sport->port_gid_id.tpg, tag_num,
tag_size, TARGET_PROT_NORMAL, tag_size, TARGET_PROT_NORMAL,
i_port_id + 2, ch, NULL); i_port_id + 2, ch, NULL);
if (IS_ERR_OR_NULL(ch->sess)) { if (IS_ERR_OR_NULL(ch->sess)) {
...@@ -2959,10 +2960,10 @@ static struct se_wwn *__srpt_lookup_wwn(const char *name) ...@@ -2959,10 +2960,10 @@ static struct se_wwn *__srpt_lookup_wwn(const char *name)
for (i = 0; i < dev->phys_port_cnt; i++) { for (i = 0; i < dev->phys_port_cnt; i++) {
sport = &sdev->port[i]; sport = &sdev->port[i];
if (strcmp(sport->port_guid, name) == 0) if (strcmp(sport->port_guid_id.name, name) == 0)
return &sport->port_guid_wwn; return &sport->port_guid_id.wwn;
if (strcmp(sport->port_gid, name) == 0) if (strcmp(sport->port_gid_id.name, name) == 0)
return &sport->port_gid_wwn; return &sport->port_gid_id.wwn;
} }
} }
...@@ -3241,14 +3242,33 @@ static struct srpt_port *srpt_tpg_to_sport(struct se_portal_group *tpg) ...@@ -3241,14 +3242,33 @@ static struct srpt_port *srpt_tpg_to_sport(struct se_portal_group *tpg)
return tpg->se_tpg_wwn->priv; return tpg->se_tpg_wwn->priv;
} }
static char *srpt_get_fabric_wwn(struct se_portal_group *tpg) static struct srpt_port_id *srpt_tpg_to_sport_id(struct se_portal_group *tpg)
{ {
struct srpt_port *sport = srpt_tpg_to_sport(tpg); struct srpt_port *sport = srpt_tpg_to_sport(tpg);
WARN_ON_ONCE(tpg != &sport->port_guid_tpg && if (tpg == &sport->port_guid_id.tpg)
tpg != &sport->port_gid_tpg); return &sport->port_guid_id;
return tpg == &sport->port_guid_tpg ? sport->port_guid : if (tpg == &sport->port_gid_id.tpg)
sport->port_gid; return &sport->port_gid_id;
WARN_ON_ONCE(true);
return NULL;
}
static struct srpt_port_id *srpt_wwn_to_sport_id(struct se_wwn *wwn)
{
struct srpt_port *sport = wwn->priv;
if (wwn == &sport->port_guid_id.wwn)
return &sport->port_guid_id;
if (wwn == &sport->port_gid_id.wwn)
return &sport->port_gid_id;
WARN_ON_ONCE(true);
return NULL;
}
static char *srpt_get_fabric_wwn(struct se_portal_group *tpg)
{
return srpt_tpg_to_sport_id(tpg)->name;
} }
static u16 srpt_get_tag(struct se_portal_group *tpg) static u16 srpt_get_tag(struct se_portal_group *tpg)
...@@ -3705,13 +3725,9 @@ static struct se_portal_group *srpt_make_tpg(struct se_wwn *wwn, ...@@ -3705,13 +3725,9 @@ static struct se_portal_group *srpt_make_tpg(struct se_wwn *wwn,
const char *name) const char *name)
{ {
struct srpt_port *sport = wwn->priv; struct srpt_port *sport = wwn->priv;
struct se_portal_group *tpg; struct se_portal_group *tpg = &srpt_wwn_to_sport_id(wwn)->tpg;
int res; int res;
WARN_ON_ONCE(wwn != &sport->port_guid_wwn &&
wwn != &sport->port_gid_wwn);
tpg = wwn == &sport->port_guid_wwn ? &sport->port_guid_tpg :
&sport->port_gid_tpg;
res = core_tpg_register(wwn, tpg, SCSI_PROTOCOL_SRP); res = core_tpg_register(wwn, tpg, SCSI_PROTOCOL_SRP);
if (res) if (res)
return ERR_PTR(res); return ERR_PTR(res);
......
...@@ -363,13 +363,26 @@ struct srpt_port_attrib { ...@@ -363,13 +363,26 @@ struct srpt_port_attrib {
bool use_srq; bool use_srq;
}; };
/**
* struct srpt_port_id - information about an RDMA port name
* @tpg: TPG associated with the RDMA port.
* @wwn: WWN associated with the RDMA port.
* @name: ASCII representation of the port name.
*
* Multiple sysfs directories can be associated with a single RDMA port. This
* data structure represents a single (port, name) pair.
*/
struct srpt_port_id {
struct se_portal_group tpg;
struct se_wwn wwn;
char name[64];
};
/** /**
* struct srpt_port - information associated by SRPT with a single IB port * struct srpt_port - information associated by SRPT with a single IB port
* @sdev: backpointer to the HCA information. * @sdev: backpointer to the HCA information.
* @mad_agent: per-port management datagram processing information. * @mad_agent: per-port management datagram processing information.
* @enabled: Whether or not this target port is enabled. * @enabled: Whether or not this target port is enabled.
* @port_guid: ASCII representation of Port GUID
* @port_gid: ASCII representation of Port GID
* @port: one-based port number. * @port: one-based port number.
* @sm_lid: cached value of the port's sm_lid. * @sm_lid: cached value of the port's sm_lid.
* @lid: cached value of the port's lid. * @lid: cached value of the port's lid.
...@@ -390,17 +403,13 @@ struct srpt_port { ...@@ -390,17 +403,13 @@ struct srpt_port {
struct srpt_device *sdev; struct srpt_device *sdev;
struct ib_mad_agent *mad_agent; struct ib_mad_agent *mad_agent;
bool enabled; bool enabled;
u8 port_guid[24];
u8 port_gid[64];
u8 port; u8 port;
u32 sm_lid; u32 sm_lid;
u32 lid; u32 lid;
union ib_gid gid; union ib_gid gid;
struct work_struct work; struct work_struct work;
struct se_portal_group port_guid_tpg; struct srpt_port_id port_guid_id;
struct se_wwn port_guid_wwn; struct srpt_port_id port_gid_id;
struct se_portal_group port_gid_tpg;
struct se_wwn port_gid_wwn;
struct srpt_port_attrib port_attrib; struct srpt_port_attrib port_attrib;
atomic_t refcount; atomic_t refcount;
struct completion *freed_channels; struct completion *freed_channels;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment