Commit 5c21c4cc authored by Ursula Braun's avatar Ursula Braun Committed by David S. Miller

net/smc: determine accepted ISM devices

SMCD Version 2 allows to propose up to 8 additional ISM devices
offered to the peer as candidates for SMCD communication.
This patch covers the server side, i.e. selection of an ISM device
matching one of the proposed ISM devices, that will be used for
CLC accept
Signed-off-by: default avatarUrsula Braun <ubraun@linux.ibm.com>
Signed-off-by: default avatarKarsten Graul <kgraul@linux.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8c3dca34
...@@ -1236,6 +1236,47 @@ static void smc_listen_decline(struct smc_sock *new_smc, int reason_code, ...@@ -1236,6 +1236,47 @@ static void smc_listen_decline(struct smc_sock *new_smc, int reason_code,
smc_listen_out_connected(new_smc); smc_listen_out_connected(new_smc);
} }
/* listen worker: version checking */
static int smc_listen_v2_check(struct smc_sock *new_smc,
struct smc_clc_msg_proposal *pclc,
struct smc_init_info *ini)
{
struct smc_clc_smcd_v2_extension *pclc_smcd_v2_ext;
struct smc_clc_v2_extension *pclc_v2_ext;
ini->smc_type_v1 = pclc->hdr.typev1;
ini->smc_type_v2 = pclc->hdr.typev2;
ini->smcd_version = ini->smc_type_v1 != SMC_TYPE_N ? SMC_V1 : 0;
if (pclc->hdr.version > SMC_V1)
ini->smcd_version |=
ini->smc_type_v2 != SMC_TYPE_N ? SMC_V2 : 0;
if (!smc_ism_v2_capable) {
ini->smcd_version &= ~SMC_V2;
goto out;
}
pclc_v2_ext = smc_get_clc_v2_ext(pclc);
if (!pclc_v2_ext) {
ini->smcd_version &= ~SMC_V2;
goto out;
}
pclc_smcd_v2_ext = smc_get_clc_smcd_v2_ext(pclc_v2_ext);
if (!pclc_smcd_v2_ext)
ini->smcd_version &= ~SMC_V2;
out:
if (!ini->smcd_version) {
if (pclc->hdr.typev1 == SMC_TYPE_B ||
pclc->hdr.typev2 == SMC_TYPE_B)
return SMC_CLC_DECL_NOSMCDEV;
if (pclc->hdr.typev1 == SMC_TYPE_D ||
pclc->hdr.typev2 == SMC_TYPE_D)
return SMC_CLC_DECL_NOSMCDDEV;
return SMC_CLC_DECL_NOSMCRDEV;
}
return 0;
}
/* listen worker: check prefixes */ /* listen worker: check prefixes */
static int smc_listen_prfx_check(struct smc_sock *new_smc, static int smc_listen_prfx_check(struct smc_sock *new_smc,
struct smc_clc_msg_proposal *pclc) struct smc_clc_msg_proposal *pclc)
...@@ -1243,6 +1284,8 @@ static int smc_listen_prfx_check(struct smc_sock *new_smc, ...@@ -1243,6 +1284,8 @@ static int smc_listen_prfx_check(struct smc_sock *new_smc,
struct smc_clc_msg_proposal_prefix *pclc_prfx; struct smc_clc_msg_proposal_prefix *pclc_prfx;
struct socket *newclcsock = new_smc->clcsock; struct socket *newclcsock = new_smc->clcsock;
if (pclc->hdr.typev1 == SMC_TYPE_N)
return 0;
pclc_prfx = smc_clc_proposal_get_prefix(pclc); pclc_prfx = smc_clc_proposal_get_prefix(pclc);
if (smc_clc_prfx_match(newclcsock, pclc_prfx)) if (smc_clc_prfx_match(newclcsock, pclc_prfx))
return SMC_CLC_DECL_DIFFPREFIX; return SMC_CLC_DECL_DIFFPREFIX;
...@@ -1292,20 +1335,119 @@ static int smc_listen_ism_init(struct smc_sock *new_smc, ...@@ -1292,20 +1335,119 @@ static int smc_listen_ism_init(struct smc_sock *new_smc,
return 0; return 0;
} }
static void smc_find_ism_device_serv(struct smc_sock *new_smc, static bool smc_is_already_selected(struct smcd_dev *smcd,
struct smc_clc_msg_proposal *pclc, struct smc_init_info *ini,
struct smc_init_info *ini) int matches)
{
int i;
for (i = 0; i < matches; i++)
if (smcd == ini->ism_dev[i])
return true;
return false;
}
/* check for ISM devices matching proposed ISM devices */
static void smc_check_ism_v2_match(struct smc_init_info *ini,
u16 proposed_chid, u64 proposed_gid,
unsigned int *matches)
{
struct smcd_dev *smcd;
list_for_each_entry(smcd, &smcd_dev_list.list, list) {
if (smcd->going_away)
continue;
if (smc_is_already_selected(smcd, ini, *matches))
continue;
if (smc_ism_get_chid(smcd) == proposed_chid &&
!smc_ism_cantalk(proposed_gid, ISM_RESERVED_VLANID, smcd)) {
ini->ism_peer_gid[*matches] = proposed_gid;
ini->ism_dev[*matches] = smcd;
(*matches)++;
break;
}
}
}
static void smc_find_ism_v2_device_serv(struct smc_sock *new_smc,
struct smc_clc_msg_proposal *pclc,
struct smc_init_info *ini)
{
struct smc_clc_smcd_v2_extension *smcd_v2_ext;
struct smc_clc_v2_extension *smc_v2_ext;
struct smc_clc_msg_smcd *pclc_smcd;
unsigned int matches = 0;
u8 *eid = NULL;
int i;
if (!(ini->smcd_version & SMC_V2) || !smcd_indicated(ini->smc_type_v2))
return;
pclc_smcd = smc_get_clc_msg_smcd(pclc);
smc_v2_ext = smc_get_clc_v2_ext(pclc);
smcd_v2_ext = smc_get_clc_smcd_v2_ext(smc_v2_ext);
if (!smcd_v2_ext ||
!smc_v2_ext->hdr.flag.seid) /* no system EID support for SMCD */
goto not_found;
mutex_lock(&smcd_dev_list.mutex);
if (pclc_smcd->ism.chid)
/* check for ISM device matching proposed native ISM device */
smc_check_ism_v2_match(ini, ntohs(pclc_smcd->ism.chid),
ntohll(pclc_smcd->ism.gid), &matches);
for (i = 1; i <= smc_v2_ext->hdr.ism_gid_cnt; i++) {
/* check for ISM devices matching proposed non-native ISM
* devices
*/
smc_check_ism_v2_match(ini,
ntohs(smcd_v2_ext->gidchid[i - 1].chid),
ntohll(smcd_v2_ext->gidchid[i - 1].gid),
&matches);
}
mutex_unlock(&smcd_dev_list.mutex);
if (ini->ism_dev[0]) {
smc_ism_get_system_eid(ini->ism_dev[0], &eid);
if (memcmp(eid, smcd_v2_ext->system_eid, SMC_MAX_EID_LEN))
goto not_found;
} else {
goto not_found;
}
/* separate - outside the smcd_dev_list.lock */
for (i = 0; i < matches; i++) {
ini->smcd_version = SMC_V2;
ini->is_smcd = true;
ini->ism_selected = i;
if (smc_listen_ism_init(new_smc, ini))
/* try next active ISM device */
continue;
return; /* matching and usable V2 ISM device found */
}
not_found:
ini->smcd_version &= ~SMC_V2;
ini->ism_dev[0] = NULL;
ini->is_smcd = false;
}
static void smc_find_ism_v1_device_serv(struct smc_sock *new_smc,
struct smc_clc_msg_proposal *pclc,
struct smc_init_info *ini)
{ {
struct smc_clc_msg_smcd *pclc_smcd = smc_get_clc_msg_smcd(pclc); struct smc_clc_msg_smcd *pclc_smcd = smc_get_clc_msg_smcd(pclc);
if (!smcd_indicated(pclc->hdr.typev1)) /* check if ISM V1 is available */
if (!(ini->smcd_version & SMC_V1) || !smcd_indicated(ini->smc_type_v1))
goto not_found; goto not_found;
ini->is_smcd = true; /* prepare ISM check */ ini->is_smcd = true; /* prepare ISM check */
ini->ism_peer_gid[0] = ntohll(pclc_smcd->ism.gid); ini->ism_peer_gid[0] = ntohll(pclc_smcd->ism.gid);
if (smc_find_ism_device(new_smc, ini)) if (smc_find_ism_device(new_smc, ini))
goto not_found; goto not_found;
ini->ism_selected = 0;
if (!smc_listen_ism_init(new_smc, ini)) if (!smc_listen_ism_init(new_smc, ini))
return; /* ISM device found */ return; /* V1 ISM device found */
not_found: not_found:
ini->ism_dev[0] = NULL; ini->ism_dev[0] = NULL;
...@@ -1326,13 +1468,13 @@ static int smc_listen_rdma_reg(struct smc_sock *new_smc, bool local_first) ...@@ -1326,13 +1468,13 @@ static int smc_listen_rdma_reg(struct smc_sock *new_smc, bool local_first)
return 0; return 0;
} }
static int smc_find_rdma_device_serv(struct smc_sock *new_smc, static int smc_find_rdma_v1_device_serv(struct smc_sock *new_smc,
struct smc_clc_msg_proposal *pclc, struct smc_clc_msg_proposal *pclc,
struct smc_init_info *ini) struct smc_init_info *ini)
{ {
int rc; int rc;
if (!smcr_indicated(pclc->hdr.typev1)) if (!smcr_indicated(ini->smc_type_v1))
return SMC_CLC_DECL_NOSMCDEV; return SMC_CLC_DECL_NOSMCDEV;
/* prepare RDMA check */ /* prepare RDMA check */
...@@ -1340,7 +1482,7 @@ static int smc_find_rdma_device_serv(struct smc_sock *new_smc, ...@@ -1340,7 +1482,7 @@ static int smc_find_rdma_device_serv(struct smc_sock *new_smc,
rc = smc_find_rdma_device(new_smc, ini); rc = smc_find_rdma_device(new_smc, ini);
if (rc) { if (rc) {
/* no RDMA device found */ /* no RDMA device found */
if (pclc->hdr.typev1 == SMC_TYPE_B) if (ini->smc_type_v1 == SMC_TYPE_B)
/* neither ISM nor RDMA device found */ /* neither ISM nor RDMA device found */
rc = SMC_CLC_DECL_NOSMCDEV; rc = SMC_CLC_DECL_NOSMCDEV;
return rc; return rc;
...@@ -1356,15 +1498,35 @@ static int smc_listen_find_device(struct smc_sock *new_smc, ...@@ -1356,15 +1498,35 @@ static int smc_listen_find_device(struct smc_sock *new_smc,
struct smc_clc_msg_proposal *pclc, struct smc_clc_msg_proposal *pclc,
struct smc_init_info *ini) struct smc_init_info *ini)
{ {
/* check if ISM is available */ int rc;
smc_find_ism_device_serv(new_smc, pclc, ini);
if (ini->is_smcd) /* check for ISM device matching V2 proposed device */
smc_find_ism_v2_device_serv(new_smc, pclc, ini);
if (ini->ism_dev[0])
return 0; return 0;
if (!(ini->smcd_version & SMC_V1))
return SMC_CLC_DECL_NOSMCDEV;
/* check for matching IP prefix and subnet length */
rc = smc_listen_prfx_check(new_smc, pclc);
if (rc)
return rc;
/* get vlan id from IP device */
if (smc_vlan_by_tcpsk(new_smc->clcsock, ini))
return SMC_CLC_DECL_GETVLANERR;
/* check for ISM device matching V1 proposed device */
smc_find_ism_v1_device_serv(new_smc, pclc, ini);
if (ini->ism_dev[0])
return 0;
if (pclc->hdr.typev1 == SMC_TYPE_D) if (pclc->hdr.typev1 == SMC_TYPE_D)
return SMC_CLC_DECL_NOSMCDDEV; /* skip RDMA and decline */ return SMC_CLC_DECL_NOSMCDDEV; /* skip RDMA and decline */
/* check if RDMA is available */ /* check if RDMA is available */
return smc_find_rdma_device_serv(new_smc, pclc, ini); return smc_find_rdma_v1_device_serv(new_smc, pclc, ini);
} }
/* listen worker: finish RDMA setup */ /* listen worker: finish RDMA setup */
...@@ -1440,22 +1602,16 @@ static void smc_listen_work(struct work_struct *work) ...@@ -1440,22 +1602,16 @@ static void smc_listen_work(struct work_struct *work)
goto out_decl; goto out_decl;
} }
/* check for matching IP prefix and subnet length */
rc = smc_listen_prfx_check(new_smc, pclc);
if (rc)
goto out_decl;
ini = kzalloc(sizeof(*ini), GFP_KERNEL); ini = kzalloc(sizeof(*ini), GFP_KERNEL);
if (!ini) { if (!ini) {
rc = SMC_CLC_DECL_MEM; rc = SMC_CLC_DECL_MEM;
goto out_decl; goto out_decl;
} }
/* get vlan id from IP device */ /* initial version checking */
if (smc_vlan_by_tcpsk(new_smc->clcsock, ini)) { rc = smc_listen_v2_check(new_smc, pclc, ini);
rc = SMC_CLC_DECL_GETVLANERR; if (rc)
goto out_decl; goto out_decl;
}
mutex_lock(&smc_server_lgr_pending); mutex_lock(&smc_server_lgr_pending);
smc_close_init(new_smc); smc_close_init(new_smc);
......
...@@ -260,6 +260,22 @@ smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop) ...@@ -260,6 +260,22 @@ smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop)
ntohs(prop_smcd->v2_ext_offset)); ntohs(prop_smcd->v2_ext_offset));
} }
static inline struct smc_clc_smcd_v2_extension *
smc_get_clc_smcd_v2_ext(struct smc_clc_v2_extension *prop_v2ext)
{
if (!prop_v2ext)
return NULL;
if (!ntohs(prop_v2ext->hdr.smcd_v2_ext_offset))
return NULL;
return (struct smc_clc_smcd_v2_extension *)
((u8 *)prop_v2ext +
offsetof(struct smc_clc_v2_extension, hdr) +
offsetof(struct smc_clnt_opts_area_hdr, smcd_v2_ext_offset) +
sizeof(prop_v2ext->hdr.smcd_v2_ext_offset) +
ntohs(prop_v2ext->hdr.smcd_v2_ext_offset));
}
struct smcd_dev; struct smcd_dev;
struct smc_init_info; struct smc_init_info;
......
...@@ -375,7 +375,8 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini) ...@@ -375,7 +375,8 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
int i; int i;
if (ini->is_smcd && ini->vlan_id) { if (ini->is_smcd && ini->vlan_id) {
if (smc_ism_get_vlan(ini->ism_dev[0], ini->vlan_id)) { if (smc_ism_get_vlan(ini->ism_dev[ini->ism_selected],
ini->vlan_id)) {
rc = SMC_CLC_DECL_ISMVLANERR; rc = SMC_CLC_DECL_ISMVLANERR;
goto out; goto out;
} }
...@@ -412,13 +413,13 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini) ...@@ -412,13 +413,13 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
lgr->conns_all = RB_ROOT; lgr->conns_all = RB_ROOT;
if (ini->is_smcd) { if (ini->is_smcd) {
/* SMC-D specific settings */ /* SMC-D specific settings */
get_device(&ini->ism_dev[0]->dev); get_device(&ini->ism_dev[ini->ism_selected]->dev);
lgr->peer_gid = ini->ism_peer_gid[0]; lgr->peer_gid = ini->ism_peer_gid[ini->ism_selected];
lgr->smcd = ini->ism_dev[0]; lgr->smcd = ini->ism_dev[ini->ism_selected];
lgr_list = &ini->ism_dev[0]->lgr_list; lgr_list = &ini->ism_dev[ini->ism_selected]->lgr_list;
lgr_lock = &lgr->smcd->lgr_lock; lgr_lock = &lgr->smcd->lgr_lock;
lgr->peer_shutdown = 0; lgr->peer_shutdown = 0;
atomic_inc(&ini->ism_dev[0]->lgr_cnt); atomic_inc(&ini->ism_dev[ini->ism_selected]->lgr_cnt);
} else { } else {
/* SMC-R specific settings */ /* SMC-R specific settings */
lgr->role = smc->listen_smc ? SMC_SERV : SMC_CLNT; lgr->role = smc->listen_smc ? SMC_SERV : SMC_CLNT;
...@@ -449,7 +450,7 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini) ...@@ -449,7 +450,7 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
kfree(lgr); kfree(lgr);
ism_put_vlan: ism_put_vlan:
if (ini->is_smcd && ini->vlan_id) if (ini->is_smcd && ini->vlan_id)
smc_ism_put_vlan(ini->ism_dev[0], ini->vlan_id); smc_ism_put_vlan(ini->ism_dev[ini->ism_selected], ini->vlan_id);
out: out:
if (rc < 0) { if (rc < 0) {
if (rc == -ENOMEM) if (rc == -ENOMEM)
...@@ -1288,9 +1289,9 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini) ...@@ -1288,9 +1289,9 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
spinlock_t *lgr_lock; spinlock_t *lgr_lock;
int rc = 0; int rc = 0;
lgr_list = ini->is_smcd ? &ini->ism_dev[0]->lgr_list : lgr_list = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_list :
&smc_lgr_list.list; &smc_lgr_list.list;
lgr_lock = ini->is_smcd ? &ini->ism_dev[0]->lgr_lock : lgr_lock = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_lock :
&smc_lgr_list.lock; &smc_lgr_list.lock;
ini->first_contact_local = 1; ini->first_contact_local = 1;
role = smc->listen_smc ? SMC_SERV : SMC_CLNT; role = smc->listen_smc ? SMC_SERV : SMC_CLNT;
...@@ -1303,8 +1304,8 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini) ...@@ -1303,8 +1304,8 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
list_for_each_entry(lgr, lgr_list, list) { list_for_each_entry(lgr, lgr_list, list) {
write_lock_bh(&lgr->conns_lock); write_lock_bh(&lgr->conns_lock);
if ((ini->is_smcd ? if ((ini->is_smcd ?
smcd_lgr_match(lgr, ini->ism_dev[0], smcd_lgr_match(lgr, ini->ism_dev[ini->ism_selected],
ini->ism_peer_gid[0]) : ini->ism_peer_gid[ini->ism_selected]) :
smcr_lgr_match(lgr, ini->ib_lcl, role, ini->ib_clcqpn)) && smcr_lgr_match(lgr, ini->ib_lcl, role, ini->ib_clcqpn)) &&
!lgr->sync_err && !lgr->sync_err &&
lgr->vlan_id == ini->vlan_id && lgr->vlan_id == ini->vlan_id &&
......
...@@ -307,6 +307,7 @@ struct smc_init_info { ...@@ -307,6 +307,7 @@ struct smc_init_info {
struct smcd_dev *ism_dev[SMC_MAX_ISM_DEVS + 1]; struct smcd_dev *ism_dev[SMC_MAX_ISM_DEVS + 1];
u16 ism_chid[SMC_MAX_ISM_DEVS + 1]; u16 ism_chid[SMC_MAX_ISM_DEVS + 1];
u8 ism_offered_cnt; /* # of ISM devices offered */ u8 ism_offered_cnt; /* # of ISM devices offered */
u8 ism_selected; /* index of selected ISM dev*/
u8 smcd_version; u8 smcd_version;
}; };
......
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