@@ -497,65 +497,85 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
497497 return reason_code ;
498498}
499499
500- /* send CLC CONFIRM message across internal TCP socket */
501- int smc_clc_send_confirm (struct smc_sock * smc )
500+ /* build and send CLC CONFIRM / ACCEPT message */
501+ static int smc_clc_send_confirm_accept (struct smc_sock * smc ,
502+ struct smc_clc_msg_accept_confirm * clc ,
503+ int first_contact )
502504{
503505 struct smc_connection * conn = & smc -> conn ;
504- struct smc_clc_msg_accept_confirm cclc ;
505- struct smc_link * link ;
506- int reason_code = 0 ;
507506 struct msghdr msg ;
508507 struct kvec vec ;
509- int len ;
510508
511509 /* send SMC Confirm CLC msg */
512- memset ( & cclc , 0 , sizeof ( cclc ));
513- cclc . hdr . type = SMC_CLC_CONFIRM ;
514- cclc . hdr .version = SMC_V1 ; /* SMC version */
510+ clc -> hdr . version = SMC_V1 ; /* SMC version */
511+ if ( first_contact )
512+ clc -> hdr .flag = 1 ;
515513 if (conn -> lgr -> is_smcd ) {
516514 /* SMC-D specific settings */
517- memcpy (cclc . hdr .eyecatcher , SMCD_EYECATCHER ,
515+ memcpy (clc -> hdr .eyecatcher , SMCD_EYECATCHER ,
518516 sizeof (SMCD_EYECATCHER ));
519- cclc . hdr .path = SMC_TYPE_D ;
520- cclc . hdr .length = htons (SMCD_CLC_ACCEPT_CONFIRM_LEN );
521- cclc .gid = conn -> lgr -> smcd -> local_gid ;
522- cclc .token = conn -> rmb_desc -> token ;
523- cclc .dmbe_size = conn -> rmbe_size_short ;
524- cclc .dmbe_idx = 0 ;
525- memcpy (& cclc .linkid , conn -> lgr -> id , SMC_LGR_ID_SIZE );
526- memcpy (cclc .smcd_trl .eyecatcher , SMCD_EYECATCHER ,
517+ clc -> hdr .path = SMC_TYPE_D ;
518+ clc -> hdr .length = htons (SMCD_CLC_ACCEPT_CONFIRM_LEN );
519+ clc -> d0 .gid = conn -> lgr -> smcd -> local_gid ;
520+ clc -> d0 .token = conn -> rmb_desc -> token ;
521+ clc -> d0 .dmbe_size = conn -> rmbe_size_short ;
522+ clc -> d0 .dmbe_idx = 0 ;
523+ memcpy (& clc -> d0 .linkid , conn -> lgr -> id , SMC_LGR_ID_SIZE );
524+ memcpy (clc -> d0 .smcd_trl .eyecatcher , SMCD_EYECATCHER ,
527525 sizeof (SMCD_EYECATCHER ));
528526 } else {
527+ struct smc_link * link = conn -> lnk ;
528+
529529 /* SMC-R specific settings */
530530 link = conn -> lnk ;
531- memcpy (cclc . hdr .eyecatcher , SMC_EYECATCHER ,
531+ memcpy (clc -> hdr .eyecatcher , SMC_EYECATCHER ,
532532 sizeof (SMC_EYECATCHER ));
533- cclc . hdr .path = SMC_TYPE_R ;
534- cclc . hdr .length = htons (SMCR_CLC_ACCEPT_CONFIRM_LEN );
535- memcpy (cclc .lcl .id_for_peer , local_systemid ,
533+ clc -> hdr .path = SMC_TYPE_R ;
534+ clc -> hdr .length = htons (SMCR_CLC_ACCEPT_CONFIRM_LEN );
535+ memcpy (clc -> r0 .lcl .id_for_peer , local_systemid ,
536536 sizeof (local_systemid ));
537- memcpy (& cclc .lcl .gid , link -> gid , SMC_GID_SIZE );
538- memcpy (& cclc .lcl .mac , & link -> smcibdev -> mac [link -> ibport - 1 ],
537+ memcpy (& clc -> r0 .lcl .gid , link -> gid , SMC_GID_SIZE );
538+ memcpy (& clc -> r0 .lcl .mac , & link -> smcibdev -> mac [link -> ibport - 1 ],
539539 ETH_ALEN );
540- hton24 (cclc .qpn , link -> roce_qp -> qp_num );
541- cclc .rmb_rkey =
540+ hton24 (clc -> r0 .qpn , link -> roce_qp -> qp_num );
541+ clc -> r0 .rmb_rkey =
542542 htonl (conn -> rmb_desc -> mr_rx [link -> link_idx ]-> rkey );
543- cclc .rmbe_idx = 1 ; /* for now: 1 RMB = 1 RMBE */
544- cclc .rmbe_alert_token = htonl (conn -> alert_token_local );
545- cclc .qp_mtu = min (link -> path_mtu , link -> peer_mtu );
546- cclc .rmbe_size = conn -> rmbe_size_short ;
547- cclc .rmb_dma_addr = cpu_to_be64 ((u64 )sg_dma_address
543+ clc -> r0 .rmbe_idx = 1 ; /* for now: 1 RMB = 1 RMBE */
544+ clc -> r0 .rmbe_alert_token = htonl (conn -> alert_token_local );
545+ switch (clc -> hdr .type ) {
546+ case SMC_CLC_ACCEPT :
547+ clc -> r0 .qp_mtu = link -> path_mtu ;
548+ break ;
549+ case SMC_CLC_CONFIRM :
550+ clc -> r0 .qp_mtu = min (link -> path_mtu , link -> peer_mtu );
551+ break ;
552+ }
553+ clc -> r0 .rmbe_size = conn -> rmbe_size_short ;
554+ clc -> r0 .rmb_dma_addr = cpu_to_be64 ((u64 )sg_dma_address
548555 (conn -> rmb_desc -> sgt [link -> link_idx ].sgl ));
549- hton24 (cclc .psn , link -> psn_initial );
550- memcpy (cclc .smcr_trl .eyecatcher , SMC_EYECATCHER ,
556+ hton24 (clc -> r0 .psn , link -> psn_initial );
557+ memcpy (clc -> r0 .smcr_trl .eyecatcher , SMC_EYECATCHER ,
551558 sizeof (SMC_EYECATCHER ));
552559 }
553560
554561 memset (& msg , 0 , sizeof (msg ));
555- vec .iov_base = & cclc ;
556- vec .iov_len = ntohs (cclc .hdr .length );
557- len = kernel_sendmsg (smc -> clcsock , & msg , & vec , 1 ,
558- ntohs (cclc .hdr .length ));
562+ vec .iov_base = clc ;
563+ vec .iov_len = ntohs (clc -> hdr .length );
564+ return kernel_sendmsg (smc -> clcsock , & msg , & vec , 1 ,
565+ ntohs (clc -> hdr .length ));
566+ }
567+
568+ /* send CLC CONFIRM message across internal TCP socket */
569+ int smc_clc_send_confirm (struct smc_sock * smc )
570+ {
571+ struct smc_clc_msg_accept_confirm cclc ;
572+ int reason_code = 0 ;
573+ int len ;
574+
575+ /* send SMC Confirm CLC msg */
576+ memset (& cclc , 0 , sizeof (cclc ));
577+ cclc .hdr .type = SMC_CLC_CONFIRM ;
578+ len = smc_clc_send_confirm_accept (smc , & cclc , 0 );
559579 if (len < ntohs (cclc .hdr .length )) {
560580 if (len >= 0 ) {
561581 reason_code = - ENETUNREACH ;
@@ -571,63 +591,12 @@ int smc_clc_send_confirm(struct smc_sock *smc)
571591/* send CLC ACCEPT message across internal TCP socket */
572592int smc_clc_send_accept (struct smc_sock * new_smc , bool srv_first_contact )
573593{
574- struct smc_connection * conn = & new_smc -> conn ;
575594 struct smc_clc_msg_accept_confirm aclc ;
576- struct smc_link * link ;
577- struct msghdr msg ;
578- struct kvec vec ;
579595 int len ;
580596
581597 memset (& aclc , 0 , sizeof (aclc ));
582598 aclc .hdr .type = SMC_CLC_ACCEPT ;
583- aclc .hdr .version = SMC_V1 ; /* SMC version */
584- if (srv_first_contact )
585- aclc .hdr .flag = 1 ;
586-
587- if (conn -> lgr -> is_smcd ) {
588- /* SMC-D specific settings */
589- aclc .hdr .length = htons (SMCD_CLC_ACCEPT_CONFIRM_LEN );
590- memcpy (aclc .hdr .eyecatcher , SMCD_EYECATCHER ,
591- sizeof (SMCD_EYECATCHER ));
592- aclc .hdr .path = SMC_TYPE_D ;
593- aclc .gid = conn -> lgr -> smcd -> local_gid ;
594- aclc .token = conn -> rmb_desc -> token ;
595- aclc .dmbe_size = conn -> rmbe_size_short ;
596- aclc .dmbe_idx = 0 ;
597- memcpy (& aclc .linkid , conn -> lgr -> id , SMC_LGR_ID_SIZE );
598- memcpy (aclc .smcd_trl .eyecatcher , SMCD_EYECATCHER ,
599- sizeof (SMCD_EYECATCHER ));
600- } else {
601- /* SMC-R specific settings */
602- aclc .hdr .length = htons (SMCR_CLC_ACCEPT_CONFIRM_LEN );
603- memcpy (aclc .hdr .eyecatcher , SMC_EYECATCHER ,
604- sizeof (SMC_EYECATCHER ));
605- aclc .hdr .path = SMC_TYPE_R ;
606- link = conn -> lnk ;
607- memcpy (aclc .lcl .id_for_peer , local_systemid ,
608- sizeof (local_systemid ));
609- memcpy (& aclc .lcl .gid , link -> gid , SMC_GID_SIZE );
610- memcpy (& aclc .lcl .mac , link -> smcibdev -> mac [link -> ibport - 1 ],
611- ETH_ALEN );
612- hton24 (aclc .qpn , link -> roce_qp -> qp_num );
613- aclc .rmb_rkey =
614- htonl (conn -> rmb_desc -> mr_rx [link -> link_idx ]-> rkey );
615- aclc .rmbe_idx = 1 ; /* as long as 1 RMB = 1 RMBE */
616- aclc .rmbe_alert_token = htonl (conn -> alert_token_local );
617- aclc .qp_mtu = link -> path_mtu ;
618- aclc .rmbe_size = conn -> rmbe_size_short ,
619- aclc .rmb_dma_addr = cpu_to_be64 ((u64 )sg_dma_address
620- (conn -> rmb_desc -> sgt [link -> link_idx ].sgl ));
621- hton24 (aclc .psn , link -> psn_initial );
622- memcpy (aclc .smcr_trl .eyecatcher , SMC_EYECATCHER ,
623- sizeof (SMC_EYECATCHER ));
624- }
625-
626- memset (& msg , 0 , sizeof (msg ));
627- vec .iov_base = & aclc ;
628- vec .iov_len = ntohs (aclc .hdr .length );
629- len = kernel_sendmsg (new_smc -> clcsock , & msg , & vec , 1 ,
630- ntohs (aclc .hdr .length ));
599+ len = smc_clc_send_confirm_accept (new_smc , & aclc , srv_first_contact );
631600 if (len < ntohs (aclc .hdr .length ))
632601 len = len >= 0 ? - EPROTO : - new_smc -> clcsock -> sk -> sk_err ;
633602
0 commit comments