Skip to content

Commit e0a092e

Browse files
committed
Merge branch 'smc-next'
Ursula Braun says: ==================== net/smc: patches 2019-04-12 here are patches for SMC: * patch 1 improves behavior of non-blocking connect * patches 2, 3, 5, 7, and 8 improve connecting return codes * patches 4 and 6 are a cleanups without functional change ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 6dc400a + 7a62725 commit e0a092e

8 files changed

Lines changed: 294 additions & 274 deletions

File tree

‎net/smc/af_smc.c‎

Lines changed: 182 additions & 173 deletions
Large diffs are not rendered by default.

‎net/smc/smc.h‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,11 @@ struct smc_connection {
190190
u64 peer_token; /* SMC-D token of peer */
191191
};
192192

193-
struct smc_connect_info {
194-
int flags;
195-
int alen;
196-
struct sockaddr addr;
197-
};
198-
199193
struct smc_sock { /* smc sock container */
200194
struct sock sk;
201195
struct socket *clcsock; /* internal tcp socket */
202196
struct smc_connection conn; /* smc connection */
203197
struct smc_sock *listen_smc; /* listen parent */
204-
struct smc_connect_info *connect_info; /* connect address & flags */
205198
struct work_struct connect_work; /* handle non-blocking connect*/
206199
struct work_struct tcp_listen_work;/* handle tcp socket accepts */
207200
struct work_struct smc_listen_work;/* prepare new accept socket */
@@ -219,6 +212,10 @@ struct smc_sock { /* smc sock container */
219212
* started, waiting for unsent
220213
* data to be sent
221214
*/
215+
u8 connect_nonblock : 1;
216+
/* non-blocking connect in
217+
* flight
218+
*/
222219
struct mutex clcsock_release_lock;
223220
/* protects clcsock of a listen
224221
* socket

‎net/smc/smc_clc.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,7 @@ int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info)
385385

386386
/* send CLC PROPOSAL message across internal TCP socket */
387387
int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
388-
struct smc_ib_device *ibdev, u8 ibport, u8 gid[],
389-
struct smcd_dev *ismdev)
388+
struct smc_init_info *ini)
390389
{
391390
struct smc_clc_ipv6_prefix ipv6_prfx[SMC_CLC_MAX_V6_PREFIX];
392391
struct smc_clc_msg_proposal_prefix pclc_prfx;
@@ -416,16 +415,17 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
416415
/* add SMC-R specifics */
417416
memcpy(pclc.lcl.id_for_peer, local_systemid,
418417
sizeof(local_systemid));
419-
memcpy(&pclc.lcl.gid, gid, SMC_GID_SIZE);
420-
memcpy(&pclc.lcl.mac, &ibdev->mac[ibport - 1], ETH_ALEN);
418+
memcpy(&pclc.lcl.gid, ini->ib_gid, SMC_GID_SIZE);
419+
memcpy(&pclc.lcl.mac, &ini->ib_dev->mac[ini->ib_port - 1],
420+
ETH_ALEN);
421421
pclc.iparea_offset = htons(0);
422422
}
423423
if (smc_type == SMC_TYPE_D || smc_type == SMC_TYPE_B) {
424424
/* add SMC-D specifics */
425425
memset(&pclc_smcd, 0, sizeof(pclc_smcd));
426426
plen += sizeof(pclc_smcd);
427427
pclc.iparea_offset = htons(SMC_CLC_PROPOSAL_MAX_OFFSET);
428-
pclc_smcd.gid = ismdev->local_gid;
428+
pclc_smcd.gid = ini->ism_dev->local_gid;
429429
}
430430
pclc.hdr.length = htons(plen);
431431

‎net/smc/smc_clc.h‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,22 @@
3434
#define SMC_CLC_DECL_CNFERR 0x03000000 /* configuration error */
3535
#define SMC_CLC_DECL_PEERNOSMC 0x03010000 /* peer did not indicate SMC */
3636
#define SMC_CLC_DECL_IPSEC 0x03020000 /* IPsec usage */
37-
#define SMC_CLC_DECL_NOSMCDEV 0x03030000 /* no SMC device found */
37+
#define SMC_CLC_DECL_NOSMCDEV 0x03030000 /* no SMC device found (R or D) */
38+
#define SMC_CLC_DECL_NOSMCDDEV 0x03030001 /* no SMC-D device found */
39+
#define SMC_CLC_DECL_NOSMCRDEV 0x03030002 /* no SMC-R device found */
40+
#define SMC_CLC_DECL_SMCDNOTALK 0x03030003 /* SMC-D dev can't talk to peer */
3841
#define SMC_CLC_DECL_MODEUNSUPP 0x03040000 /* smc modes do not match (R or D)*/
3942
#define SMC_CLC_DECL_RMBE_EC 0x03050000 /* peer has eyecatcher in RMBE */
4043
#define SMC_CLC_DECL_OPTUNSUPP 0x03060000 /* fastopen sockopt not supported */
44+
#define SMC_CLC_DECL_DIFFPREFIX 0x03070000 /* IP prefix / subnet mismatch */
45+
#define SMC_CLC_DECL_GETVLANERR 0x03080000 /* err to get vlan id of ip device*/
46+
#define SMC_CLC_DECL_ISMVLANERR 0x03090000 /* err to reg vlan id on ism dev */
4147
#define SMC_CLC_DECL_SYNCERR 0x04000000 /* synchronization error */
4248
#define SMC_CLC_DECL_PEERDECL 0x05000000 /* peer declined during handshake */
43-
#define SMC_CLC_DECL_INTERR 0x99990000 /* internal error */
44-
#define SMC_CLC_DECL_ERR_RTOK 0x99990001 /* rtoken handling failed */
45-
#define SMC_CLC_DECL_ERR_RDYLNK 0x99990002 /* ib ready link failed */
46-
#define SMC_CLC_DECL_ERR_REGRMB 0x99990003 /* reg rmb failed */
49+
#define SMC_CLC_DECL_INTERR 0x09990000 /* internal error */
50+
#define SMC_CLC_DECL_ERR_RTOK 0x09990001 /* rtoken handling failed */
51+
#define SMC_CLC_DECL_ERR_RDYLNK 0x09990002 /* ib ready link failed */
52+
#define SMC_CLC_DECL_ERR_REGRMB 0x09990003 /* reg rmb failed */
4753

4854
struct smc_clc_msg_hdr { /* header1 of clc messages */
4955
u8 eyecatcher[4]; /* eye catcher */
@@ -179,15 +185,15 @@ smc_get_clc_msg_smcd(struct smc_clc_msg_proposal *prop)
179185
}
180186

181187
struct smcd_dev;
188+
struct smc_init_info;
182189

183190
int smc_clc_prfx_match(struct socket *clcsock,
184191
struct smc_clc_msg_proposal_prefix *prop);
185192
int smc_clc_wait_msg(struct smc_sock *smc, void *buf, int buflen,
186193
u8 expected_type, unsigned long timeout);
187194
int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info);
188195
int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
189-
struct smc_ib_device *smcibdev, u8 ibport, u8 gid[],
190-
struct smcd_dev *ismdev);
196+
struct smc_init_info *ini);
191197
int smc_clc_send_confirm(struct smc_sock *smc);
192198
int smc_clc_send_accept(struct smc_sock *smc, int srv_first_contact);
193199

‎net/smc/smc_core.c‎

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -195,31 +195,29 @@ static void smc_lgr_free_work(struct work_struct *work)
195195
}
196196

197197
/* create a new SMC link group */
198-
static int smc_lgr_create(struct smc_sock *smc, bool is_smcd,
199-
struct smc_ib_device *smcibdev, u8 ibport,
200-
char *peer_systemid, unsigned short vlan_id,
201-
struct smcd_dev *smcismdev, u64 peer_gid)
198+
static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
202199
{
203200
struct smc_link_group *lgr;
204201
struct smc_link *lnk;
205202
u8 rndvec[3];
206203
int rc = 0;
207204
int i;
208205

209-
if (is_smcd && vlan_id) {
210-
rc = smc_ism_get_vlan(smcismdev, vlan_id);
211-
if (rc)
206+
if (ini->is_smcd && ini->vlan_id) {
207+
if (smc_ism_get_vlan(ini->ism_dev, ini->vlan_id)) {
208+
rc = SMC_CLC_DECL_ISMVLANERR;
212209
goto out;
210+
}
213211
}
214212

215213
lgr = kzalloc(sizeof(*lgr), GFP_KERNEL);
216214
if (!lgr) {
217-
rc = -ENOMEM;
215+
rc = SMC_CLC_DECL_MEM;
218216
goto out;
219217
}
220-
lgr->is_smcd = is_smcd;
218+
lgr->is_smcd = ini->is_smcd;
221219
lgr->sync_err = 0;
222-
lgr->vlan_id = vlan_id;
220+
lgr->vlan_id = ini->vlan_id;
223221
rwlock_init(&lgr->sndbufs_lock);
224222
rwlock_init(&lgr->rmbs_lock);
225223
rwlock_init(&lgr->conns_lock);
@@ -231,29 +229,32 @@ static int smc_lgr_create(struct smc_sock *smc, bool is_smcd,
231229
memcpy(&lgr->id, (u8 *)&smc_lgr_list.num, SMC_LGR_ID_SIZE);
232230
INIT_DELAYED_WORK(&lgr->free_work, smc_lgr_free_work);
233231
lgr->conns_all = RB_ROOT;
234-
if (is_smcd) {
232+
if (ini->is_smcd) {
235233
/* SMC-D specific settings */
236-
lgr->peer_gid = peer_gid;
237-
lgr->smcd = smcismdev;
234+
lgr->peer_gid = ini->ism_gid;
235+
lgr->smcd = ini->ism_dev;
238236
} else {
239237
/* SMC-R specific settings */
240238
lgr->role = smc->listen_smc ? SMC_SERV : SMC_CLNT;
241-
memcpy(lgr->peer_systemid, peer_systemid, SMC_SYSTEMID_LEN);
239+
memcpy(lgr->peer_systemid, ini->ib_lcl->id_for_peer,
240+
SMC_SYSTEMID_LEN);
242241

243242
lnk = &lgr->lnk[SMC_SINGLE_LINK];
244243
/* initialize link */
245244
lnk->state = SMC_LNK_ACTIVATING;
246245
lnk->link_id = SMC_SINGLE_LINK;
247-
lnk->smcibdev = smcibdev;
248-
lnk->ibport = ibport;
249-
lnk->path_mtu = smcibdev->pattr[ibport - 1].active_mtu;
250-
if (!smcibdev->initialized)
251-
smc_ib_setup_per_ibdev(smcibdev);
246+
lnk->smcibdev = ini->ib_dev;
247+
lnk->ibport = ini->ib_port;
248+
lnk->path_mtu =
249+
ini->ib_dev->pattr[ini->ib_port - 1].active_mtu;
250+
if (!ini->ib_dev->initialized)
251+
smc_ib_setup_per_ibdev(ini->ib_dev);
252252
get_random_bytes(rndvec, sizeof(rndvec));
253253
lnk->psn_initial = rndvec[0] + (rndvec[1] << 8) +
254254
(rndvec[2] << 16);
255255
rc = smc_ib_determine_gid(lnk->smcibdev, lnk->ibport,
256-
vlan_id, lnk->gid, &lnk->sgid_index);
256+
ini->vlan_id, lnk->gid,
257+
&lnk->sgid_index);
257258
if (rc)
258259
goto free_lgr;
259260
rc = smc_llc_link_init(lnk);
@@ -289,6 +290,12 @@ static int smc_lgr_create(struct smc_sock *smc, bool is_smcd,
289290
free_lgr:
290291
kfree(lgr);
291292
out:
293+
if (rc < 0) {
294+
if (rc == -ENOMEM)
295+
rc = SMC_CLC_DECL_MEM;
296+
else
297+
rc = SMC_CLC_DECL_INTERR;
298+
}
292299
return rc;
293300
}
294301

@@ -528,13 +535,13 @@ void smc_smcd_terminate(struct smcd_dev *dev, u64 peer_gid, unsigned short vlan)
528535
/* Determine vlan of internal TCP socket.
529536
* @vlan_id: address to store the determined vlan id into
530537
*/
531-
int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id)
538+
int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini)
532539
{
533540
struct dst_entry *dst = sk_dst_get(clcsock->sk);
534541
struct net_device *ndev;
535542
int i, nest_lvl, rc = 0;
536543

537-
*vlan_id = 0;
544+
ini->vlan_id = 0;
538545
if (!dst) {
539546
rc = -ENOTCONN;
540547
goto out;
@@ -546,7 +553,7 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id)
546553

547554
ndev = dst->dev;
548555
if (is_vlan_dev(ndev)) {
549-
*vlan_id = vlan_dev_vlan_id(ndev);
556+
ini->vlan_id = vlan_dev_vlan_id(ndev);
550557
goto out_rel;
551558
}
552559

@@ -560,7 +567,7 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id)
560567
lower = lower->next;
561568
ndev = (struct net_device *)netdev_lower_get_next(ndev, &lower);
562569
if (is_vlan_dev(ndev)) {
563-
*vlan_id = vlan_dev_vlan_id(ndev);
570+
ini->vlan_id = vlan_dev_vlan_id(ndev);
564571
break;
565572
}
566573
}
@@ -594,39 +601,32 @@ static bool smcd_lgr_match(struct smc_link_group *lgr,
594601
}
595602

596603
/* create a new SMC connection (and a new link group if necessary) */
597-
int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact,
598-
struct smc_ib_device *smcibdev, u8 ibport, u32 clcqpn,
599-
struct smc_clc_msg_local *lcl, struct smcd_dev *smcd,
600-
u64 peer_gid)
604+
int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
601605
{
602606
struct smc_connection *conn = &smc->conn;
603-
int local_contact = SMC_FIRST_CONTACT;
604607
struct smc_link_group *lgr;
605-
unsigned short vlan_id;
606608
enum smc_lgr_role role;
607609
int rc = 0;
608610

611+
ini->cln_first_contact = SMC_FIRST_CONTACT;
609612
role = smc->listen_smc ? SMC_SERV : SMC_CLNT;
610-
rc = smc_vlan_by_tcpsk(smc->clcsock, &vlan_id);
611-
if (rc)
612-
return rc;
613-
614-
if ((role == SMC_CLNT) && srv_first_contact)
613+
if (role == SMC_CLNT && ini->srv_first_contact)
615614
/* create new link group as well */
616615
goto create;
617616

618617
/* determine if an existing link group can be reused */
619618
spin_lock_bh(&smc_lgr_list.lock);
620619
list_for_each_entry(lgr, &smc_lgr_list.list, list) {
621620
write_lock_bh(&lgr->conns_lock);
622-
if ((is_smcd ? smcd_lgr_match(lgr, smcd, peer_gid) :
623-
smcr_lgr_match(lgr, lcl, role, clcqpn)) &&
621+
if ((ini->is_smcd ?
622+
smcd_lgr_match(lgr, ini->ism_dev, ini->ism_gid) :
623+
smcr_lgr_match(lgr, ini->ib_lcl, role, ini->ib_clcqpn)) &&
624624
!lgr->sync_err &&
625-
lgr->vlan_id == vlan_id &&
625+
lgr->vlan_id == ini->vlan_id &&
626626
(role == SMC_CLNT ||
627627
lgr->conns_num < SMC_RMBS_PER_LGR_MAX)) {
628628
/* link group found */
629-
local_contact = SMC_REUSE_CONTACT;
629+
ini->cln_first_contact = SMC_REUSE_CONTACT;
630630
conn->lgr = lgr;
631631
smc_lgr_register_conn(conn); /* add smc conn to lgr */
632632
if (delayed_work_pending(&lgr->free_work))
@@ -638,27 +638,26 @@ int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact,
638638
}
639639
spin_unlock_bh(&smc_lgr_list.lock);
640640

641-
if (role == SMC_CLNT && !srv_first_contact &&
642-
(local_contact == SMC_FIRST_CONTACT)) {
641+
if (role == SMC_CLNT && !ini->srv_first_contact &&
642+
ini->cln_first_contact == SMC_FIRST_CONTACT) {
643643
/* Server reuses a link group, but Client wants to start
644644
* a new one
645645
* send out_of_sync decline, reason synchr. error
646646
*/
647-
return -ENOLINK;
647+
return SMC_CLC_DECL_SYNCERR;
648648
}
649649

650650
create:
651-
if (local_contact == SMC_FIRST_CONTACT) {
652-
rc = smc_lgr_create(smc, is_smcd, smcibdev, ibport,
653-
lcl->id_for_peer, vlan_id, smcd, peer_gid);
651+
if (ini->cln_first_contact == SMC_FIRST_CONTACT) {
652+
rc = smc_lgr_create(smc, ini);
654653
if (rc)
655654
goto out;
656655
smc_lgr_register_conn(conn); /* add smc conn to lgr */
657656
}
658657
conn->local_tx_ctrl.common.type = SMC_CDC_MSG_TYPE;
659658
conn->local_tx_ctrl.len = SMC_WR_TX_SIZE;
660659
conn->urg_state = SMC_URG_READ;
661-
if (is_smcd) {
660+
if (ini->is_smcd) {
662661
conn->rx_off = sizeof(struct smcd_cdc_msg);
663662
smcd_cdc_rx_init(conn); /* init tasklet for this conn */
664663
}
@@ -667,7 +666,7 @@ int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact,
667666
#endif
668667

669668
out:
670-
return rc ? rc : local_contact;
669+
return rc;
671670
}
672671

673672
/* convert the RMB size into the compressed notation - minimum 16K.

‎net/smc/smc_core.h‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,24 @@ struct smc_link_group {
229229
};
230230
};
231231

232+
struct smc_clc_msg_local;
233+
234+
struct smc_init_info {
235+
u8 is_smcd;
236+
unsigned short vlan_id;
237+
int srv_first_contact;
238+
int cln_first_contact;
239+
/* SMC-R */
240+
struct smc_clc_msg_local *ib_lcl;
241+
struct smc_ib_device *ib_dev;
242+
u8 ib_gid[SMC_GID_SIZE];
243+
u8 ib_port;
244+
u32 ib_clcqpn;
245+
/* SMC-D */
246+
u64 ism_gid;
247+
struct smcd_dev *ism_dev;
248+
};
249+
232250
/* Find the connection associated with the given alert token in the link group.
233251
* To use rbtrees we have to implement our own search core.
234252
* Requires @conns_lock
@@ -281,13 +299,10 @@ void smc_sndbuf_sync_sg_for_cpu(struct smc_connection *conn);
281299
void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn);
282300
void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn);
283301
void smc_rmb_sync_sg_for_device(struct smc_connection *conn);
284-
int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id);
302+
int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini);
285303

286304
void smc_conn_free(struct smc_connection *conn);
287-
int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact,
288-
struct smc_ib_device *smcibdev, u8 ibport, u32 clcqpn,
289-
struct smc_clc_msg_local *lcl, struct smcd_dev *smcd,
290-
u64 peer_gid);
305+
int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini);
291306
void smcd_conn_free(struct smc_connection *conn);
292307
void smc_lgr_schedule_free_work_fast(struct smc_link_group *lgr);
293308
void smc_core_exit(void);

0 commit comments

Comments
 (0)