Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  Shared Memory Communications over RDMA (SMC-R) and RoCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *  Link Layer Control (LLC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *  Copyright IBM Corp. 2016
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *  Author(s):  Klaus Wacker <Klaus.Wacker@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *              Ursula Braun <ubraun@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <net/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <rdma/ib_verbs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include "smc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include "smc_core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include "smc_clc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include "smc_llc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include "smc_pnet.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #define SMC_LLC_DATA_LEN		40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) struct smc_llc_hdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 	struct smc_wr_rx_hdr common;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 	u8 length;	/* 44 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #if defined(__BIG_ENDIAN_BITFIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 	u8 reserved:4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 	   add_link_rej_rsn:4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #elif defined(__LITTLE_ENDIAN_BITFIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 	u8 add_link_rej_rsn:4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 	   reserved:4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 	u8 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #define SMC_LLC_FLAG_NO_RMBE_EYEC	0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) struct smc_llc_msg_confirm_link {	/* type 0x01 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	struct smc_llc_hdr hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	u8 sender_mac[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	u8 sender_gid[SMC_GID_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	u8 sender_qp_num[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	u8 link_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	u8 link_uid[SMC_LGR_ID_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	u8 max_links;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	u8 reserved[9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #define SMC_LLC_FLAG_ADD_LNK_REJ	0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #define SMC_LLC_REJ_RSN_NO_ALT_PATH	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #define SMC_LLC_ADD_LNK_MAX_LINKS	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) struct smc_llc_msg_add_link {		/* type 0x02 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	struct smc_llc_hdr hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	u8 sender_mac[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	u8 reserved2[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	u8 sender_gid[SMC_GID_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	u8 sender_qp_num[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	u8 link_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #if defined(__BIG_ENDIAN_BITFIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	u8 reserved3 : 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	   qp_mtu   : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #elif defined(__LITTLE_ENDIAN_BITFIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	u8 qp_mtu   : 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	   reserved3 : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	u8 initial_psn[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	u8 reserved[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) struct smc_llc_msg_add_link_cont_rt {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	__be32 rmb_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	__be32 rmb_key_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	__be64 rmb_vaddr_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #define SMC_LLC_RKEYS_PER_CONT_MSG	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) struct smc_llc_msg_add_link_cont {	/* type 0x03 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	struct smc_llc_hdr hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	u8 link_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	u8 num_rkeys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	u8 reserved2[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	struct smc_llc_msg_add_link_cont_rt rt[SMC_LLC_RKEYS_PER_CONT_MSG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	u8 reserved[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) } __packed;			/* format defined in RFC7609 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) #define SMC_LLC_FLAG_DEL_LINK_ALL	0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #define SMC_LLC_FLAG_DEL_LINK_ORDERLY	0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) struct smc_llc_msg_del_link {		/* type 0x04 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	struct smc_llc_hdr hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	u8 link_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	__be32 reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	u8 reserved[35];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) } __packed;			/* format defined in RFC7609 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) struct smc_llc_msg_test_link {		/* type 0x07 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	struct smc_llc_hdr hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	u8 user_data[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	u8 reserved[24];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) struct smc_rmb_rtoken {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 		u8 num_rkeys;	/* first rtoken byte of CONFIRM LINK msg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 				/* is actually the num of rtokens, first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 				/* rtoken is always for the current link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 		u8 link_id;	/* link id of the rtoken */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	__be32 rmb_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	__be64 rmb_vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) } __packed;			/* format defined in RFC7609 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) #define SMC_LLC_RKEYS_PER_MSG	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) struct smc_llc_msg_confirm_rkey {	/* type 0x06 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	struct smc_llc_hdr hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	struct smc_rmb_rtoken rtoken[SMC_LLC_RKEYS_PER_MSG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	u8 reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) #define SMC_LLC_DEL_RKEY_MAX	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) #define SMC_LLC_FLAG_RKEY_RETRY	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) #define SMC_LLC_FLAG_RKEY_NEG	0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) struct smc_llc_msg_delete_rkey {	/* type 0x09 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	struct smc_llc_hdr hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	u8 num_rkeys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	u8 err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	u8 reserved[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	__be32 rkey[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	u8 reserved2[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) union smc_llc_msg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	struct smc_llc_msg_confirm_link confirm_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	struct smc_llc_msg_add_link add_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	struct smc_llc_msg_add_link_cont add_link_cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	struct smc_llc_msg_del_link delete_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	struct smc_llc_msg_confirm_rkey confirm_rkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	struct smc_llc_msg_delete_rkey delete_rkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	struct smc_llc_msg_test_link test_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		struct smc_llc_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		u8 data[SMC_LLC_DATA_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	} raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) #define SMC_LLC_FLAG_RESP		0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) struct smc_llc_qentry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	struct smc_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	union smc_llc_msg msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) static void smc_llc_enqueue(struct smc_link *link, union smc_llc_msg *llc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) struct smc_llc_qentry *smc_llc_flow_qentry_clr(struct smc_llc_flow *flow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	struct smc_llc_qentry *qentry = flow->qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	flow->qentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	return qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) void smc_llc_flow_qentry_del(struct smc_llc_flow *flow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	struct smc_llc_qentry *qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	if (flow->qentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		qentry = flow->qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		flow->qentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		kfree(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) static inline void smc_llc_flow_qentry_set(struct smc_llc_flow *flow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 					   struct smc_llc_qentry *qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	flow->qentry = qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) static void smc_llc_flow_parallel(struct smc_link_group *lgr, u8 flow_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 				  struct smc_llc_qentry *qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	u8 msg_type = qentry->msg.raw.hdr.common.type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	if ((msg_type == SMC_LLC_ADD_LINK || msg_type == SMC_LLC_DELETE_LINK) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	    flow_type != msg_type && !lgr->delayed_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		lgr->delayed_event = qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	/* drop parallel or already-in-progress llc requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	if (flow_type != msg_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		pr_warn_once("smc: SMC-R lg %*phN dropped parallel "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 			     "LLC msg: msg %d flow %d role %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 			     SMC_LGR_ID_SIZE, &lgr->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 			     qentry->msg.raw.hdr.common.type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 			     flow_type, lgr->role);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	kfree(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) /* try to start a new llc flow, initiated by an incoming llc msg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) static bool smc_llc_flow_start(struct smc_llc_flow *flow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 			       struct smc_llc_qentry *qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	struct smc_link_group *lgr = qentry->link->lgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	spin_lock_bh(&lgr->llc_flow_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	if (flow->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 		/* a flow is already active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		smc_llc_flow_parallel(lgr, flow->type, qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		spin_unlock_bh(&lgr->llc_flow_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	switch (qentry->msg.raw.hdr.common.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	case SMC_LLC_ADD_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		flow->type = SMC_LLC_FLOW_ADD_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	case SMC_LLC_DELETE_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		flow->type = SMC_LLC_FLOW_DEL_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	case SMC_LLC_CONFIRM_RKEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	case SMC_LLC_DELETE_RKEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		flow->type = SMC_LLC_FLOW_RKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		flow->type = SMC_LLC_FLOW_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	smc_llc_flow_qentry_set(flow, qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	spin_unlock_bh(&lgr->llc_flow_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) /* start a new local llc flow, wait till current flow finished */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) int smc_llc_flow_initiate(struct smc_link_group *lgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 			  enum smc_llc_flowtype type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	enum smc_llc_flowtype allowed_remote = SMC_LLC_FLOW_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	/* all flows except confirm_rkey and delete_rkey are exclusive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	 * confirm/delete rkey flows can run concurrently (local and remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	if (type == SMC_LLC_FLOW_RKEY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		allowed_remote = SMC_LLC_FLOW_RKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	if (list_empty(&lgr->list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	spin_lock_bh(&lgr->llc_flow_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_NONE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	    (lgr->llc_flow_rmt.type == SMC_LLC_FLOW_NONE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	     lgr->llc_flow_rmt.type == allowed_remote)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		lgr->llc_flow_lcl.type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 		spin_unlock_bh(&lgr->llc_flow_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	spin_unlock_bh(&lgr->llc_flow_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	rc = wait_event_timeout(lgr->llc_flow_waiter, (list_empty(&lgr->list) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 				(lgr->llc_flow_lcl.type == SMC_LLC_FLOW_NONE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 				 (lgr->llc_flow_rmt.type == SMC_LLC_FLOW_NONE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 				  lgr->llc_flow_rmt.type == allowed_remote))),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 				SMC_LLC_WAIT_TIME * 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) /* finish the current llc flow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) void smc_llc_flow_stop(struct smc_link_group *lgr, struct smc_llc_flow *flow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	spin_lock_bh(&lgr->llc_flow_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	memset(flow, 0, sizeof(*flow));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	flow->type = SMC_LLC_FLOW_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	spin_unlock_bh(&lgr->llc_flow_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	if (!list_empty(&lgr->list) && lgr->delayed_event &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	    flow == &lgr->llc_flow_lcl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		schedule_work(&lgr->llc_event_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		wake_up(&lgr->llc_flow_waiter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) /* lnk is optional and used for early wakeup when link goes down, useful in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290)  * cases where we wait for a response on the link after we sent a request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) struct smc_llc_qentry *smc_llc_wait(struct smc_link_group *lgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 				    struct smc_link *lnk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 				    int time_out, u8 exp_msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	struct smc_llc_flow *flow = &lgr->llc_flow_lcl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	u8 rcv_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	wait_event_timeout(lgr->llc_msg_waiter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 			   (flow->qentry ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 			    (lnk && !smc_link_usable(lnk)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 			    list_empty(&lgr->list)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 			   time_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	if (!flow->qentry ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	    (lnk && !smc_link_usable(lnk)) || list_empty(&lgr->list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		smc_llc_flow_qentry_del(flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	rcv_msg = flow->qentry->msg.raw.hdr.common.type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	if (exp_msg && rcv_msg != exp_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		if (exp_msg == SMC_LLC_ADD_LINK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		    rcv_msg == SMC_LLC_DELETE_LINK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 			/* flow_start will delay the unexpected msg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 			smc_llc_flow_start(&lgr->llc_flow_lcl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 					   smc_llc_flow_qentry_clr(flow));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		pr_warn_once("smc: SMC-R lg %*phN dropped unexpected LLC msg: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 			     "msg %d exp %d flow %d role %d flags %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			     SMC_LGR_ID_SIZE, &lgr->id, rcv_msg, exp_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 			     flow->type, lgr->role,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 			     flow->qentry->msg.raw.hdr.flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		smc_llc_flow_qentry_del(flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	return flow->qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) /********************************** send *************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) struct smc_llc_tx_pend {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) /* handler for send/transmission completion of an LLC msg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) static void smc_llc_tx_handler(struct smc_wr_tx_pend_priv *pend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 			       struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 			       enum ib_wc_status wc_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	/* future work: handle wc_status error for recovery and failover */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343)  * smc_llc_add_pending_send() - add LLC control message to pending WQE transmits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344)  * @link: Pointer to SMC link used for sending LLC control message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345)  * @wr_buf: Out variable returning pointer to work request payload buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346)  * @pend: Out variable returning pointer to private pending WR tracking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347)  *	  It's the context the transmit complete handler will get.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349)  * Reserves and pre-fills an entry for a pending work request send/tx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350)  * Used by mid-level smc_llc_send_msg() to prepare for later actual send/tx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351)  * Can sleep due to smc_get_ctrl_buf (if not in softirq context).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353)  * Return: 0 on success, otherwise an error value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) static int smc_llc_add_pending_send(struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 				    struct smc_wr_buf **wr_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 				    struct smc_wr_tx_pend_priv **pend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	rc = smc_wr_tx_get_free_slot(link, smc_llc_tx_handler, wr_buf, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 				     pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	BUILD_BUG_ON_MSG(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		sizeof(union smc_llc_msg) > SMC_WR_BUF_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 		"must increase SMC_WR_BUF_SIZE to at least sizeof(struct smc_llc_msg)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	BUILD_BUG_ON_MSG(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		sizeof(union smc_llc_msg) != SMC_WR_TX_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		"must adapt SMC_WR_TX_SIZE to sizeof(struct smc_llc_msg); if not all smc_wr upper layer protocols use the same message size any more, must start to set link->wr_tx_sges[i].length on each individual smc_wr_tx_send()");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	BUILD_BUG_ON_MSG(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		sizeof(struct smc_llc_tx_pend) > SMC_WR_TX_PEND_PRIV_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		"must increase SMC_WR_TX_PEND_PRIV_SIZE to at least sizeof(struct smc_llc_tx_pend)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) /* high-level API to send LLC confirm link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) int smc_llc_send_confirm_link(struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 			      enum smc_llc_reqresp reqresp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	struct smc_llc_msg_confirm_link *confllc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	struct smc_wr_tx_pend_priv *pend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	struct smc_wr_buf *wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	if (!smc_wr_tx_link_hold(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		goto put_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	confllc = (struct smc_llc_msg_confirm_link *)wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	memset(confllc, 0, sizeof(*confllc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	confllc->hd.common.type = SMC_LLC_CONFIRM_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	confllc->hd.length = sizeof(struct smc_llc_msg_confirm_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	confllc->hd.flags |= SMC_LLC_FLAG_NO_RMBE_EYEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	if (reqresp == SMC_LLC_RESP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		confllc->hd.flags |= SMC_LLC_FLAG_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	memcpy(confllc->sender_mac, link->smcibdev->mac[link->ibport - 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	       ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	memcpy(confllc->sender_gid, link->gid, SMC_GID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	hton24(confllc->sender_qp_num, link->roce_qp->qp_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	confllc->link_num = link->link_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	memcpy(confllc->link_uid, link->link_uid, SMC_LGR_ID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	confllc->max_links = SMC_LLC_ADD_LNK_MAX_LINKS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	/* send llc message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	rc = smc_wr_tx_send(link, pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) put_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	smc_wr_tx_link_put(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) /* send LLC confirm rkey request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) static int smc_llc_send_confirm_rkey(struct smc_link *send_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 				     struct smc_buf_desc *rmb_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	struct smc_llc_msg_confirm_rkey *rkeyllc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	struct smc_wr_tx_pend_priv *pend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	struct smc_wr_buf *wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	struct smc_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	int i, rc, rtok_ix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	if (!smc_wr_tx_link_hold(send_link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	rc = smc_llc_add_pending_send(send_link, &wr_buf, &pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		goto put_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	rkeyllc = (struct smc_llc_msg_confirm_rkey *)wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	memset(rkeyllc, 0, sizeof(*rkeyllc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	rkeyllc->hd.common.type = SMC_LLC_CONFIRM_RKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	rkeyllc->hd.length = sizeof(struct smc_llc_msg_confirm_rkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	rtok_ix = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		link = &send_link->lgr->lnk[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		if (smc_link_active(link) && link != send_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 			rkeyllc->rtoken[rtok_ix].link_id = link->link_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 			rkeyllc->rtoken[rtok_ix].rmb_key =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 				htonl(rmb_desc->mr_rx[link->link_idx]->rkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 			rkeyllc->rtoken[rtok_ix].rmb_vaddr = cpu_to_be64(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 				(u64)sg_dma_address(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 					rmb_desc->sgt[link->link_idx].sgl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 			rtok_ix++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	/* rkey of send_link is in rtoken[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	rkeyllc->rtoken[0].num_rkeys = rtok_ix - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	rkeyllc->rtoken[0].rmb_key =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		htonl(rmb_desc->mr_rx[send_link->link_idx]->rkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	rkeyllc->rtoken[0].rmb_vaddr = cpu_to_be64(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		(u64)sg_dma_address(rmb_desc->sgt[send_link->link_idx].sgl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	/* send llc message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	rc = smc_wr_tx_send(send_link, pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) put_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	smc_wr_tx_link_put(send_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) /* send LLC delete rkey request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) static int smc_llc_send_delete_rkey(struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 				    struct smc_buf_desc *rmb_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	struct smc_llc_msg_delete_rkey *rkeyllc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	struct smc_wr_tx_pend_priv *pend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	struct smc_wr_buf *wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	if (!smc_wr_tx_link_hold(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		goto put_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	rkeyllc = (struct smc_llc_msg_delete_rkey *)wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	memset(rkeyllc, 0, sizeof(*rkeyllc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	rkeyllc->hd.common.type = SMC_LLC_DELETE_RKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	rkeyllc->hd.length = sizeof(struct smc_llc_msg_delete_rkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	rkeyllc->num_rkeys = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	rkeyllc->rkey[0] = htonl(rmb_desc->mr_rx[link->link_idx]->rkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	/* send llc message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	rc = smc_wr_tx_send(link, pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) put_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	smc_wr_tx_link_put(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) /* send ADD LINK request or response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) int smc_llc_send_add_link(struct smc_link *link, u8 mac[], u8 gid[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			  struct smc_link *link_new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 			  enum smc_llc_reqresp reqresp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	struct smc_llc_msg_add_link *addllc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	struct smc_wr_tx_pend_priv *pend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	struct smc_wr_buf *wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	if (!smc_wr_tx_link_hold(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		goto put_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	addllc = (struct smc_llc_msg_add_link *)wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	memset(addllc, 0, sizeof(*addllc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	addllc->hd.common.type = SMC_LLC_ADD_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	addllc->hd.length = sizeof(struct smc_llc_msg_add_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	if (reqresp == SMC_LLC_RESP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		addllc->hd.flags |= SMC_LLC_FLAG_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	memcpy(addllc->sender_mac, mac, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	memcpy(addllc->sender_gid, gid, SMC_GID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	if (link_new) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		addllc->link_num = link_new->link_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		hton24(addllc->sender_qp_num, link_new->roce_qp->qp_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		hton24(addllc->initial_psn, link_new->psn_initial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		if (reqresp == SMC_LLC_REQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 			addllc->qp_mtu = link_new->path_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 			addllc->qp_mtu = min(link_new->path_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 					     link_new->peer_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	/* send llc message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	rc = smc_wr_tx_send(link, pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) put_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	smc_wr_tx_link_put(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) /* send DELETE LINK request or response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) int smc_llc_send_delete_link(struct smc_link *link, u8 link_del_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			     enum smc_llc_reqresp reqresp, bool orderly,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 			     u32 reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	struct smc_llc_msg_del_link *delllc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	struct smc_wr_tx_pend_priv *pend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	struct smc_wr_buf *wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	if (!smc_wr_tx_link_hold(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		goto put_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	delllc = (struct smc_llc_msg_del_link *)wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	memset(delllc, 0, sizeof(*delllc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	delllc->hd.common.type = SMC_LLC_DELETE_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	delllc->hd.length = sizeof(struct smc_llc_msg_del_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	if (reqresp == SMC_LLC_RESP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 		delllc->hd.flags |= SMC_LLC_FLAG_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	if (orderly)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		delllc->hd.flags |= SMC_LLC_FLAG_DEL_LINK_ORDERLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	if (link_del_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		delllc->link_num = link_del_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		delllc->hd.flags |= SMC_LLC_FLAG_DEL_LINK_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	delllc->reason = htonl(reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	/* send llc message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	rc = smc_wr_tx_send(link, pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) put_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	smc_wr_tx_link_put(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) /* send LLC test link request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) static int smc_llc_send_test_link(struct smc_link *link, u8 user_data[16])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	struct smc_llc_msg_test_link *testllc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	struct smc_wr_tx_pend_priv *pend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	struct smc_wr_buf *wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	if (!smc_wr_tx_link_hold(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		goto put_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	testllc = (struct smc_llc_msg_test_link *)wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	memset(testllc, 0, sizeof(*testllc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	testllc->hd.common.type = SMC_LLC_TEST_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	testllc->hd.length = sizeof(struct smc_llc_msg_test_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	memcpy(testllc->user_data, user_data, sizeof(testllc->user_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	/* send llc message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	rc = smc_wr_tx_send(link, pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) put_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	smc_wr_tx_link_put(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) /* schedule an llc send on link, may wait for buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) static int smc_llc_send_message(struct smc_link *link, void *llcbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	struct smc_wr_tx_pend_priv *pend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	struct smc_wr_buf *wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	if (!smc_wr_tx_link_hold(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 		goto put_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	memcpy(wr_buf, llcbuf, sizeof(union smc_llc_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	rc = smc_wr_tx_send(link, pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) put_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	smc_wr_tx_link_put(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) /* schedule an llc send on link, may wait for buffers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607)  * and wait for send completion notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608)  * @return 0 on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) static int smc_llc_send_message_wait(struct smc_link *link, void *llcbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	struct smc_wr_tx_pend_priv *pend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	struct smc_wr_buf *wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	if (!smc_wr_tx_link_hold(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		goto put_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	memcpy(wr_buf, llcbuf, sizeof(union smc_llc_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	rc = smc_wr_tx_send_wait(link, pend, SMC_LLC_WAIT_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) put_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	smc_wr_tx_link_put(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) /********************************* receive ***********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) static int smc_llc_alloc_alt_link(struct smc_link_group *lgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 				  enum smc_lgr_type lgr_new_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	if (lgr->type == SMC_LGR_SYMMETRIC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	    (lgr->type != SMC_LGR_SINGLE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	     (lgr_new_t == SMC_LGR_ASYMMETRIC_LOCAL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	      lgr_new_t == SMC_LGR_ASYMMETRIC_PEER)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		return -EMLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	if (lgr_new_t == SMC_LGR_ASYMMETRIC_LOCAL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	    lgr_new_t == SMC_LGR_ASYMMETRIC_PEER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		for (i = SMC_LINKS_PER_LGR_MAX - 1; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 			if (lgr->lnk[i].state == SMC_LNK_UNUSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 				return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 			if (lgr->lnk[i].state == SMC_LNK_UNUSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 				return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	return -EMLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) /* return first buffer from any of the next buf lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) static struct smc_buf_desc *_smc_llc_get_next_rmb(struct smc_link_group *lgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 						  int *buf_lst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	struct smc_buf_desc *buf_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	while (*buf_lst < SMC_RMBE_SIZES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		buf_pos = list_first_entry_or_null(&lgr->rmbs[*buf_lst],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 						   struct smc_buf_desc, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		if (buf_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 			return buf_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		(*buf_lst)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) /* return next rmb from buffer lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) static struct smc_buf_desc *smc_llc_get_next_rmb(struct smc_link_group *lgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 						 int *buf_lst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 						 struct smc_buf_desc *buf_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	struct smc_buf_desc *buf_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	if (!buf_pos || list_is_last(&buf_pos->list, &lgr->rmbs[*buf_lst])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		(*buf_lst)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		return _smc_llc_get_next_rmb(lgr, buf_lst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	buf_next = list_next_entry(buf_pos, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	return buf_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) static struct smc_buf_desc *smc_llc_get_first_rmb(struct smc_link_group *lgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 						  int *buf_lst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	*buf_lst = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	return smc_llc_get_next_rmb(lgr, buf_lst, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) /* send one add_link_continue msg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) static int smc_llc_add_link_cont(struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 				 struct smc_link *link_new, u8 *num_rkeys_todo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 				 int *buf_lst, struct smc_buf_desc **buf_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	struct smc_llc_msg_add_link_cont *addc_llc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	struct smc_link_group *lgr = link->lgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	int prim_lnk_idx, lnk_idx, i, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	struct smc_wr_tx_pend_priv *pend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	struct smc_wr_buf *wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	struct smc_buf_desc *rmb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	u8 n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	if (!smc_wr_tx_link_hold(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		goto put_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	addc_llc = (struct smc_llc_msg_add_link_cont *)wr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	memset(addc_llc, 0, sizeof(*addc_llc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	prim_lnk_idx = link->link_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	lnk_idx = link_new->link_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	addc_llc->link_num = link_new->link_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	addc_llc->num_rkeys = *num_rkeys_todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	n = *num_rkeys_todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	for (i = 0; i < min_t(u8, n, SMC_LLC_RKEYS_PER_CONT_MSG); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		if (!*buf_pos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 			addc_llc->num_rkeys = addc_llc->num_rkeys -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 					      *num_rkeys_todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 			*num_rkeys_todo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		rmb = *buf_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		addc_llc->rt[i].rmb_key = htonl(rmb->mr_rx[prim_lnk_idx]->rkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		addc_llc->rt[i].rmb_key_new = htonl(rmb->mr_rx[lnk_idx]->rkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		addc_llc->rt[i].rmb_vaddr_new =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 			cpu_to_be64((u64)sg_dma_address(rmb->sgt[lnk_idx].sgl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		(*num_rkeys_todo)--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		*buf_pos = smc_llc_get_next_rmb(lgr, buf_lst, *buf_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		while (*buf_pos && !(*buf_pos)->used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			*buf_pos = smc_llc_get_next_rmb(lgr, buf_lst, *buf_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	addc_llc->hd.common.type = SMC_LLC_ADD_LINK_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	addc_llc->hd.length = sizeof(struct smc_llc_msg_add_link_cont);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	if (lgr->role == SMC_CLNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		addc_llc->hd.flags |= SMC_LLC_FLAG_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	rc = smc_wr_tx_send(link, pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) put_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	smc_wr_tx_link_put(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) static int smc_llc_cli_rkey_exchange(struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 				     struct smc_link *link_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	struct smc_llc_msg_add_link_cont *addc_llc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	struct smc_link_group *lgr = link->lgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	u8 max, num_rkeys_send, num_rkeys_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	struct smc_llc_qentry *qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	struct smc_buf_desc *buf_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	int buf_lst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	mutex_lock(&lgr->rmbs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	num_rkeys_send = lgr->conns_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		qentry = smc_llc_wait(lgr, NULL, SMC_LLC_WAIT_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 				      SMC_LLC_ADD_LINK_CONT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		if (!qentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 			rc = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		addc_llc = &qentry->msg.add_link_cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		num_rkeys_recv = addc_llc->num_rkeys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		max = min_t(u8, num_rkeys_recv, SMC_LLC_RKEYS_PER_CONT_MSG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		for (i = 0; i < max; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 			smc_rtoken_set(lgr, link->link_idx, link_new->link_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 				       addc_llc->rt[i].rmb_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 				       addc_llc->rt[i].rmb_vaddr_new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 				       addc_llc->rt[i].rmb_key_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 			num_rkeys_recv--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		rc = smc_llc_add_link_cont(link, link_new, &num_rkeys_send,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 					   &buf_lst, &buf_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	} while (num_rkeys_send || num_rkeys_recv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	mutex_unlock(&lgr->rmbs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) /* prepare and send an add link reject response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) static int smc_llc_cli_add_link_reject(struct smc_llc_qentry *qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	qentry->msg.raw.hdr.flags |= SMC_LLC_FLAG_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	qentry->msg.raw.hdr.flags |= SMC_LLC_FLAG_ADD_LNK_REJ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	qentry->msg.raw.hdr.add_link_rej_rsn = SMC_LLC_REJ_RSN_NO_ALT_PATH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	return smc_llc_send_message(qentry->link, &qentry->msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) static int smc_llc_cli_conf_link(struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 				 struct smc_init_info *ini,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 				 struct smc_link *link_new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 				 enum smc_lgr_type lgr_new_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	struct smc_link_group *lgr = link->lgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	struct smc_llc_qentry *qentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	/* receive CONFIRM LINK request over RoCE fabric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	qentry = smc_llc_wait(lgr, NULL, SMC_LLC_WAIT_FIRST_TIME, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	if (!qentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		rc = smc_llc_send_delete_link(link, link_new->link_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 					      SMC_LLC_REQ, false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 					      SMC_LLC_DEL_LOST_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	if (qentry->msg.raw.hdr.common.type != SMC_LLC_CONFIRM_LINK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		/* received DELETE_LINK instead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		qentry->msg.raw.hdr.flags |= SMC_LLC_FLAG_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		smc_llc_send_message(link, &qentry->msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	smc_llc_save_peer_uid(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	rc = smc_ib_modify_qp_rts(link_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 					 false, SMC_LLC_DEL_LOST_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	smc_wr_remember_qp_attr(link_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	rc = smcr_buf_reg_lgr(link_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 					 false, SMC_LLC_DEL_LOST_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	/* send CONFIRM LINK response over RoCE fabric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	rc = smc_llc_send_confirm_link(link_new, SMC_LLC_RESP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 					 false, SMC_LLC_DEL_LOST_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	smc_llc_link_active(link_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	if (lgr_new_t == SMC_LGR_ASYMMETRIC_LOCAL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	    lgr_new_t == SMC_LGR_ASYMMETRIC_PEER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		smcr_lgr_set_type_asym(lgr, lgr_new_t, link_new->link_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		smcr_lgr_set_type(lgr, lgr_new_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) static void smc_llc_save_add_link_info(struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 				       struct smc_llc_msg_add_link *add_llc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	link->peer_qpn = ntoh24(add_llc->sender_qp_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	memcpy(link->peer_gid, add_llc->sender_gid, SMC_GID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	memcpy(link->peer_mac, add_llc->sender_mac, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	link->peer_psn = ntoh24(add_llc->initial_psn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	link->peer_mtu = add_llc->qp_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) /* as an SMC client, process an add link request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) int smc_llc_cli_add_link(struct smc_link *link, struct smc_llc_qentry *qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	struct smc_llc_msg_add_link *llc = &qentry->msg.add_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	enum smc_lgr_type lgr_new_t = SMC_LGR_SYMMETRIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	struct smc_link_group *lgr = smc_get_lgr(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	struct smc_link *lnk_new = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	struct smc_init_info ini;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	int lnk_idx, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	if (!llc->qp_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		goto out_reject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	ini.vlan_id = lgr->vlan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	smc_pnet_find_alt_roce(lgr, &ini, link->smcibdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	if (!memcmp(llc->sender_gid, link->peer_gid, SMC_GID_SIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	    !memcmp(llc->sender_mac, link->peer_mac, ETH_ALEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		if (!ini.ib_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 			goto out_reject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		lgr_new_t = SMC_LGR_ASYMMETRIC_PEER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	if (!ini.ib_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		lgr_new_t = SMC_LGR_ASYMMETRIC_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		ini.ib_dev = link->smcibdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		ini.ib_port = link->ibport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	lnk_idx = smc_llc_alloc_alt_link(lgr, lgr_new_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	if (lnk_idx < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		goto out_reject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	lnk_new = &lgr->lnk[lnk_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	rc = smcr_link_init(lgr, lnk_new, lnk_idx, &ini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		goto out_reject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	smc_llc_save_add_link_info(lnk_new, llc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	lnk_new->link_id = llc->link_num;	/* SMC server assigns link id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	smc_llc_link_set_uid(lnk_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	rc = smc_ib_ready_link(lnk_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		goto out_clear_lnk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	rc = smcr_buf_map_lgr(lnk_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		goto out_clear_lnk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	rc = smc_llc_send_add_link(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 				   lnk_new->smcibdev->mac[ini.ib_port - 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 				   lnk_new->gid, lnk_new, SMC_LLC_RESP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		goto out_clear_lnk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	rc = smc_llc_cli_rkey_exchange(link, lnk_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		goto out_clear_lnk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	rc = smc_llc_cli_conf_link(link, &ini, lnk_new, lgr_new_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) out_clear_lnk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	lnk_new->state = SMC_LNK_INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	smcr_link_clear(lnk_new, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) out_reject:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	smc_llc_cli_add_link_reject(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	kfree(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) /* as an SMC client, invite server to start the add_link processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) static void smc_llc_cli_add_link_invite(struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 					struct smc_llc_qentry *qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	struct smc_link_group *lgr = smc_get_lgr(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	struct smc_init_info ini;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	if (lgr->type == SMC_LGR_SYMMETRIC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	    lgr->type == SMC_LGR_ASYMMETRIC_PEER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	ini.vlan_id = lgr->vlan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	smc_pnet_find_alt_roce(lgr, &ini, link->smcibdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	if (!ini.ib_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	smc_llc_send_add_link(link, ini.ib_dev->mac[ini.ib_port - 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 			      ini.ib_gid, NULL, SMC_LLC_REQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	kfree(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) static bool smc_llc_is_empty_llc_message(union smc_llc_msg *llc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	for (i = 0; i < ARRAY_SIZE(llc->raw.data); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		if (llc->raw.data[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) static bool smc_llc_is_local_add_link(union smc_llc_msg *llc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	if (llc->raw.hdr.common.type == SMC_LLC_ADD_LINK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	    smc_llc_is_empty_llc_message(llc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) static void smc_llc_process_cli_add_link(struct smc_link_group *lgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	struct smc_llc_qentry *qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	qentry = smc_llc_flow_qentry_clr(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	mutex_lock(&lgr->llc_conf_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	if (smc_llc_is_local_add_link(&qentry->msg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		smc_llc_cli_add_link_invite(qentry->link, qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		smc_llc_cli_add_link(qentry->link, qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	mutex_unlock(&lgr->llc_conf_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) static int smc_llc_active_link_count(struct smc_link_group *lgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	int i, link_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		if (!smc_link_active(&lgr->lnk[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		link_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	return link_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) /* find the asymmetric link when 3 links are established  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) static struct smc_link *smc_llc_find_asym_link(struct smc_link_group *lgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	int asym_idx = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	int i, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	bool found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	/* determine asymmetric link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		for (j = i + 1; j < SMC_LINKS_PER_LGR_MAX; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 			if (!smc_link_usable(&lgr->lnk[i]) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 			    !smc_link_usable(&lgr->lnk[j]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 			if (!memcmp(lgr->lnk[i].gid, lgr->lnk[j].gid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 				    SMC_GID_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 				found = true;	/* asym_lnk is i or j */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		if (found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	if (!found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		goto out; /* no asymmetric link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	for (k = 0; k < SMC_LINKS_PER_LGR_MAX; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		if (!smc_link_usable(&lgr->lnk[k]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		if (k != i &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		    !memcmp(lgr->lnk[i].peer_gid, lgr->lnk[k].peer_gid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 			    SMC_GID_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 			asym_idx = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		if (k != j &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		    !memcmp(lgr->lnk[j].peer_gid, lgr->lnk[k].peer_gid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 			    SMC_GID_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 			asym_idx = j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	return (asym_idx < 0) ? NULL : &lgr->lnk[asym_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) static void smc_llc_delete_asym_link(struct smc_link_group *lgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	struct smc_link *lnk_new = NULL, *lnk_asym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	struct smc_llc_qentry *qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	lnk_asym = smc_llc_find_asym_link(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	if (!lnk_asym)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		return; /* no asymmetric link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	if (!smc_link_downing(&lnk_asym->state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	lnk_new = smc_switch_conns(lgr, lnk_asym, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	smc_wr_tx_wait_no_pending_sends(lnk_asym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	if (!lnk_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	/* change flow type from ADD_LINK into DEL_LINK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	lgr->llc_flow_lcl.type = SMC_LLC_FLOW_DEL_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	rc = smc_llc_send_delete_link(lnk_new, lnk_asym->link_id, SMC_LLC_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 				      true, SMC_LLC_DEL_NO_ASYM_NEEDED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		smcr_link_down_cond(lnk_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	qentry = smc_llc_wait(lgr, lnk_new, SMC_LLC_WAIT_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 			      SMC_LLC_DELETE_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	if (!qentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		smcr_link_down_cond(lnk_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	smcr_link_clear(lnk_asym, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) static int smc_llc_srv_rkey_exchange(struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 				     struct smc_link *link_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	struct smc_llc_msg_add_link_cont *addc_llc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	struct smc_link_group *lgr = link->lgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	u8 max, num_rkeys_send, num_rkeys_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	struct smc_llc_qentry *qentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	struct smc_buf_desc *buf_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	int buf_lst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	mutex_lock(&lgr->rmbs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	num_rkeys_send = lgr->conns_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		smc_llc_add_link_cont(link, link_new, &num_rkeys_send,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 				      &buf_lst, &buf_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 				      SMC_LLC_ADD_LINK_CONT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		if (!qentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 			rc = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		addc_llc = &qentry->msg.add_link_cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		num_rkeys_recv = addc_llc->num_rkeys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		max = min_t(u8, num_rkeys_recv, SMC_LLC_RKEYS_PER_CONT_MSG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		for (i = 0; i < max; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 			smc_rtoken_set(lgr, link->link_idx, link_new->link_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 				       addc_llc->rt[i].rmb_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 				       addc_llc->rt[i].rmb_vaddr_new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 				       addc_llc->rt[i].rmb_key_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 			num_rkeys_recv--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	} while (num_rkeys_send || num_rkeys_recv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	mutex_unlock(&lgr->rmbs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) static int smc_llc_srv_conf_link(struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 				 struct smc_link *link_new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 				 enum smc_lgr_type lgr_new_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	struct smc_link_group *lgr = link->lgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	struct smc_llc_qentry *qentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	/* send CONFIRM LINK request over the RoCE fabric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	rc = smc_llc_send_confirm_link(link_new, SMC_LLC_REQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	/* receive CONFIRM LINK response over the RoCE fabric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_FIRST_TIME, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	if (!qentry ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	    qentry->msg.raw.hdr.common.type != SMC_LLC_CONFIRM_LINK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		/* send DELETE LINK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 					 false, SMC_LLC_DEL_LOST_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		if (qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 			smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	smc_llc_save_peer_uid(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	smc_llc_link_active(link_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	if (lgr_new_t == SMC_LGR_ASYMMETRIC_LOCAL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	    lgr_new_t == SMC_LGR_ASYMMETRIC_PEER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 		smcr_lgr_set_type_asym(lgr, lgr_new_t, link_new->link_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		smcr_lgr_set_type(lgr, lgr_new_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) int smc_llc_srv_add_link(struct smc_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	enum smc_lgr_type lgr_new_t = SMC_LGR_SYMMETRIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	struct smc_link_group *lgr = link->lgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	struct smc_llc_msg_add_link *add_llc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	struct smc_llc_qentry *qentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	struct smc_link *link_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	struct smc_init_info ini;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	int lnk_idx, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	/* ignore client add link recommendation, start new flow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	ini.vlan_id = lgr->vlan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	smc_pnet_find_alt_roce(lgr, &ini, link->smcibdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	if (!ini.ib_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		lgr_new_t = SMC_LGR_ASYMMETRIC_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 		ini.ib_dev = link->smcibdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		ini.ib_port = link->ibport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	lnk_idx = smc_llc_alloc_alt_link(lgr, lgr_new_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	if (lnk_idx < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	rc = smcr_link_init(lgr, &lgr->lnk[lnk_idx], lnk_idx, &ini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	link_new = &lgr->lnk[lnk_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	rc = smc_llc_send_add_link(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 				   link_new->smcibdev->mac[ini.ib_port - 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 				   link_new->gid, link_new, SMC_LLC_REQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	/* receive ADD LINK response over the RoCE fabric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_TIME, SMC_LLC_ADD_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	if (!qentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		rc = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	add_llc = &qentry->msg.add_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	if (add_llc->hd.flags & SMC_LLC_FLAG_ADD_LNK_REJ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		rc = -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	if (lgr->type == SMC_LGR_SINGLE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	    (!memcmp(add_llc->sender_gid, link->peer_gid, SMC_GID_SIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	     !memcmp(add_llc->sender_mac, link->peer_mac, ETH_ALEN))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 		lgr_new_t = SMC_LGR_ASYMMETRIC_PEER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	smc_llc_save_add_link_info(link_new, add_llc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	rc = smc_ib_ready_link(link_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	rc = smcr_buf_map_lgr(link_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	rc = smcr_buf_reg_lgr(link_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	rc = smc_llc_srv_rkey_exchange(link, link_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	rc = smc_llc_srv_conf_link(link, link_new, lgr_new_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	link_new->state = SMC_LNK_INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	smcr_link_clear(link_new, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) static void smc_llc_process_srv_add_link(struct smc_link_group *lgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	struct smc_link *link = lgr->llc_flow_lcl.qentry->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	mutex_lock(&lgr->llc_conf_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	rc = smc_llc_srv_add_link(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	if (!rc && lgr->type == SMC_LGR_SYMMETRIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 		/* delete any asymmetric link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 		smc_llc_delete_asym_link(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	mutex_unlock(&lgr->llc_conf_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) /* enqueue a local add_link req to trigger a new add_link flow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) void smc_llc_add_link_local(struct smc_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	struct smc_llc_msg_add_link add_llc = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	add_llc.hd.length = sizeof(add_llc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	add_llc.hd.common.type = SMC_LLC_ADD_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	/* no dev and port needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	smc_llc_enqueue(link, (union smc_llc_msg *)&add_llc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) /* worker to process an add link message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) static void smc_llc_add_link_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	struct smc_link_group *lgr = container_of(work, struct smc_link_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 						  llc_add_link_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	if (list_empty(&lgr->list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		/* link group is terminating */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 		smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	if (lgr->role == SMC_CLNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 		smc_llc_process_cli_add_link(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 		smc_llc_process_srv_add_link(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	smc_llc_flow_stop(lgr, &lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) /* enqueue a local del_link msg to trigger a new del_link flow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)  * called only for role SMC_SERV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) void smc_llc_srv_delete_link_local(struct smc_link *link, u8 del_link_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	struct smc_llc_msg_del_link del_llc = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	del_llc.hd.length = sizeof(del_llc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	del_llc.hd.common.type = SMC_LLC_DELETE_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	del_llc.link_num = del_link_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	del_llc.reason = htonl(SMC_LLC_DEL_LOST_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	del_llc.hd.flags |= SMC_LLC_FLAG_DEL_LINK_ORDERLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	smc_llc_enqueue(link, (union smc_llc_msg *)&del_llc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) static void smc_llc_process_cli_delete_link(struct smc_link_group *lgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	struct smc_link *lnk_del = NULL, *lnk_asym, *lnk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	struct smc_llc_msg_del_link *del_llc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	struct smc_llc_qentry *qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	int active_links;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	int lnk_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	qentry = smc_llc_flow_qentry_clr(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	lnk = qentry->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	del_llc = &qentry->msg.delete_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	if (del_llc->hd.flags & SMC_LLC_FLAG_DEL_LINK_ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		smc_lgr_terminate_sched(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	mutex_lock(&lgr->llc_conf_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	/* delete single link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	for (lnk_idx = 0; lnk_idx < SMC_LINKS_PER_LGR_MAX; lnk_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		if (lgr->lnk[lnk_idx].link_id != del_llc->link_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		lnk_del = &lgr->lnk[lnk_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	del_llc->hd.flags |= SMC_LLC_FLAG_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	if (!lnk_del) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 		/* link was not found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		del_llc->reason = htonl(SMC_LLC_DEL_NOLNK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		smc_llc_send_message(lnk, &qentry->msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	lnk_asym = smc_llc_find_asym_link(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	del_llc->reason = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	smc_llc_send_message(lnk, &qentry->msg); /* response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	if (smc_link_downing(&lnk_del->state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		smc_switch_conns(lgr, lnk_del, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	smcr_link_clear(lnk_del, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	active_links = smc_llc_active_link_count(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	if (lnk_del == lnk_asym) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		/* expected deletion of asym link, don't change lgr state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	} else if (active_links == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 		smcr_lgr_set_type(lgr, SMC_LGR_SINGLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	} else if (!active_links) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 		smcr_lgr_set_type(lgr, SMC_LGR_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		smc_lgr_terminate_sched(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	mutex_unlock(&lgr->llc_conf_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	kfree(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) /* try to send a DELETE LINK ALL request on any active link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)  * waiting for send completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) void smc_llc_send_link_delete_all(struct smc_link_group *lgr, bool ord, u32 rsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	struct smc_llc_msg_del_link delllc = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	delllc.hd.common.type = SMC_LLC_DELETE_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	delllc.hd.length = sizeof(delllc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	if (ord)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 		delllc.hd.flags |= SMC_LLC_FLAG_DEL_LINK_ORDERLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	delllc.hd.flags |= SMC_LLC_FLAG_DEL_LINK_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	delllc.reason = htonl(rsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 		if (!smc_link_sendable(&lgr->lnk[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		if (!smc_llc_send_message_wait(&lgr->lnk[i], &delllc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) static void smc_llc_process_srv_delete_link(struct smc_link_group *lgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	struct smc_llc_msg_del_link *del_llc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	struct smc_link *lnk, *lnk_del;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	struct smc_llc_qentry *qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	int active_links;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	mutex_lock(&lgr->llc_conf_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	qentry = smc_llc_flow_qentry_clr(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	lnk = qentry->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	del_llc = &qentry->msg.delete_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	if (qentry->msg.delete_link.hd.flags & SMC_LLC_FLAG_DEL_LINK_ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		/* delete entire lgr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		smc_llc_send_link_delete_all(lgr, true, ntohl(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 					      qentry->msg.delete_link.reason));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 		smc_lgr_terminate_sched(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	/* delete single link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	lnk_del = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		if (lgr->lnk[i].link_id == del_llc->link_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 			lnk_del = &lgr->lnk[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	if (!lnk_del)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 		goto out; /* asymmetric link already deleted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	if (smc_link_downing(&lnk_del->state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		if (smc_switch_conns(lgr, lnk_del, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 			smc_wr_tx_wait_no_pending_sends(lnk_del);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 	if (!list_empty(&lgr->list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		/* qentry is either a request from peer (send it back to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		 * initiate the DELETE_LINK processing), or a locally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		 * enqueued DELETE_LINK request (forward it)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 		if (!smc_llc_send_message(lnk, &qentry->msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 			struct smc_llc_qentry *qentry2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 			qentry2 = smc_llc_wait(lgr, lnk, SMC_LLC_WAIT_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 					       SMC_LLC_DELETE_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 			if (qentry2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 				smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	smcr_link_clear(lnk_del, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	active_links = smc_llc_active_link_count(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	if (active_links == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 		smcr_lgr_set_type(lgr, SMC_LGR_SINGLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	} else if (!active_links) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 		smcr_lgr_set_type(lgr, SMC_LGR_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 		smc_lgr_terminate_sched(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	if (lgr->type == SMC_LGR_SINGLE && !list_empty(&lgr->list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 		/* trigger setup of asymm alt link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 		smc_llc_add_link_local(lnk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	mutex_unlock(&lgr->llc_conf_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	kfree(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) static void smc_llc_delete_link_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	struct smc_link_group *lgr = container_of(work, struct smc_link_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 						  llc_del_link_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	if (list_empty(&lgr->list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 		/* link group is terminating */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	if (lgr->role == SMC_CLNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 		smc_llc_process_cli_delete_link(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		smc_llc_process_srv_delete_link(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	smc_llc_flow_stop(lgr, &lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) /* process a confirm_rkey request from peer, remote flow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) static void smc_llc_rmt_conf_rkey(struct smc_link_group *lgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	struct smc_llc_msg_confirm_rkey *llc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	struct smc_llc_qentry *qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	struct smc_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	int num_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	int rk_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	qentry = lgr->llc_flow_rmt.qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	llc = &qentry->msg.confirm_rkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	link = qentry->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	num_entries = llc->rtoken[0].num_rkeys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	/* first rkey entry is for receiving link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	rk_idx = smc_rtoken_add(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 				llc->rtoken[0].rmb_vaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 				llc->rtoken[0].rmb_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	if (rk_idx < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	for (i = 1; i <= min_t(u8, num_entries, SMC_LLC_RKEYS_PER_MSG - 1); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 		smc_rtoken_set2(lgr, rk_idx, llc->rtoken[i].link_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 				llc->rtoken[i].rmb_vaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 				llc->rtoken[i].rmb_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	/* max links is 3 so there is no need to support conf_rkey_cont msgs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	llc->hd.flags |= SMC_LLC_FLAG_RKEY_NEG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	llc->hd.flags |= SMC_LLC_FLAG_RKEY_RETRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	llc->hd.flags |= SMC_LLC_FLAG_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	smc_llc_send_message(link, &qentry->msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	smc_llc_flow_qentry_del(&lgr->llc_flow_rmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) /* process a delete_rkey request from peer, remote flow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) static void smc_llc_rmt_delete_rkey(struct smc_link_group *lgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	struct smc_llc_msg_delete_rkey *llc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	struct smc_llc_qentry *qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	struct smc_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	u8 err_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	int i, max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	qentry = lgr->llc_flow_rmt.qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	llc = &qentry->msg.delete_rkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	link = qentry->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	max = min_t(u8, llc->num_rkeys, SMC_LLC_DEL_RKEY_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	for (i = 0; i < max; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 		if (smc_rtoken_delete(link, llc->rkey[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 			err_mask |= 1 << (SMC_LLC_DEL_RKEY_MAX - 1 - i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 		llc->hd.flags |= SMC_LLC_FLAG_RKEY_NEG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 		llc->err_mask = err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	llc->hd.flags |= SMC_LLC_FLAG_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	smc_llc_send_message(link, &qentry->msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	smc_llc_flow_qentry_del(&lgr->llc_flow_rmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) static void smc_llc_protocol_violation(struct smc_link_group *lgr, u8 type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	pr_warn_ratelimited("smc: SMC-R lg %*phN LLC protocol violation: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 			    "llc_type %d\n", SMC_LGR_ID_SIZE, &lgr->id, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	smc_llc_set_termination_rsn(lgr, SMC_LLC_DEL_PROT_VIOL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	smc_lgr_terminate_sched(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) /* flush the llc event queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) static void smc_llc_event_flush(struct smc_link_group *lgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	struct smc_llc_qentry *qentry, *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	spin_lock_bh(&lgr->llc_event_q_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	list_for_each_entry_safe(qentry, q, &lgr->llc_event_q, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 		list_del_init(&qentry->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 		kfree(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	spin_unlock_bh(&lgr->llc_event_q_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) static void smc_llc_event_handler(struct smc_llc_qentry *qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	union smc_llc_msg *llc = &qentry->msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	struct smc_link *link = qentry->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	struct smc_link_group *lgr = link->lgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	if (!smc_link_usable(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	switch (llc->raw.hdr.common.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	case SMC_LLC_TEST_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 		llc->test_link.hd.flags |= SMC_LLC_FLAG_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 		smc_llc_send_message(link, llc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 	case SMC_LLC_ADD_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 		if (list_empty(&lgr->list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 			goto out;	/* lgr is terminating */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 		if (lgr->role == SMC_CLNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 			if (smc_llc_is_local_add_link(llc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 				if (lgr->llc_flow_lcl.type ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 				    SMC_LLC_FLOW_ADD_LINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 					break;	/* add_link in progress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 				if (smc_llc_flow_start(&lgr->llc_flow_lcl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 						       qentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 					schedule_work(&lgr->llc_add_link_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 			if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_ADD_LINK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 			    !lgr->llc_flow_lcl.qentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 				/* a flow is waiting for this message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 				smc_llc_flow_qentry_set(&lgr->llc_flow_lcl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 							qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 				wake_up(&lgr->llc_msg_waiter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 			} else if (smc_llc_flow_start(&lgr->llc_flow_lcl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 						      qentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 				schedule_work(&lgr->llc_add_link_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 		} else if (smc_llc_flow_start(&lgr->llc_flow_lcl, qentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 			/* as smc server, handle client suggestion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 			schedule_work(&lgr->llc_add_link_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	case SMC_LLC_CONFIRM_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	case SMC_LLC_ADD_LINK_CONT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 		if (lgr->llc_flow_lcl.type != SMC_LLC_FLOW_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 			/* a flow is waiting for this message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 			smc_llc_flow_qentry_set(&lgr->llc_flow_lcl, qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 			wake_up(&lgr->llc_msg_waiter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	case SMC_LLC_DELETE_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 		if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_ADD_LINK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 		    !lgr->llc_flow_lcl.qentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 			/* DEL LINK REQ during ADD LINK SEQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 			smc_llc_flow_qentry_set(&lgr->llc_flow_lcl, qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 			wake_up(&lgr->llc_msg_waiter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 		} else if (smc_llc_flow_start(&lgr->llc_flow_lcl, qentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 			schedule_work(&lgr->llc_del_link_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	case SMC_LLC_CONFIRM_RKEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 		/* new request from remote, assign to remote flow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 		if (smc_llc_flow_start(&lgr->llc_flow_rmt, qentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 			/* process here, does not wait for more llc msgs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 			smc_llc_rmt_conf_rkey(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 			smc_llc_flow_stop(lgr, &lgr->llc_flow_rmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	case SMC_LLC_CONFIRM_RKEY_CONT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 		/* not used because max links is 3, and 3 rkeys fit into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 		 * one CONFIRM_RKEY message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	case SMC_LLC_DELETE_RKEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 		/* new request from remote, assign to remote flow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 		if (smc_llc_flow_start(&lgr->llc_flow_rmt, qentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 			/* process here, does not wait for more llc msgs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 			smc_llc_rmt_delete_rkey(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 			smc_llc_flow_stop(lgr, &lgr->llc_flow_rmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 		smc_llc_protocol_violation(lgr, llc->raw.hdr.common.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	kfree(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) /* worker to process llc messages on the event queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) static void smc_llc_event_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	struct smc_link_group *lgr = container_of(work, struct smc_link_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 						  llc_event_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	struct smc_llc_qentry *qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	if (!lgr->llc_flow_lcl.type && lgr->delayed_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 		qentry = lgr->delayed_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 		lgr->delayed_event = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 		if (smc_link_usable(qentry->link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 			smc_llc_event_handler(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 			kfree(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	spin_lock_bh(&lgr->llc_event_q_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	if (!list_empty(&lgr->llc_event_q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 		qentry = list_first_entry(&lgr->llc_event_q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 					  struct smc_llc_qentry, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 		list_del_init(&qentry->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 		spin_unlock_bh(&lgr->llc_event_q_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 		smc_llc_event_handler(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 		goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	spin_unlock_bh(&lgr->llc_event_q_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) /* process llc responses in tasklet context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) static void smc_llc_rx_response(struct smc_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 				struct smc_llc_qentry *qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	enum smc_llc_flowtype flowtype = link->lgr->llc_flow_lcl.type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	struct smc_llc_flow *flow = &link->lgr->llc_flow_lcl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	u8 llc_type = qentry->msg.raw.hdr.common.type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	switch (llc_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	case SMC_LLC_TEST_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 		if (smc_link_active(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 			complete(&link->llc_testlink_resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	case SMC_LLC_ADD_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	case SMC_LLC_ADD_LINK_CONT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 	case SMC_LLC_CONFIRM_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 		if (flowtype != SMC_LLC_FLOW_ADD_LINK || flow->qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 			break;	/* drop out-of-flow response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 		goto assign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	case SMC_LLC_DELETE_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 		if (flowtype != SMC_LLC_FLOW_DEL_LINK || flow->qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 			break;	/* drop out-of-flow response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 		goto assign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 	case SMC_LLC_CONFIRM_RKEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	case SMC_LLC_DELETE_RKEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		if (flowtype != SMC_LLC_FLOW_RKEY || flow->qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 			break;	/* drop out-of-flow response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		goto assign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	case SMC_LLC_CONFIRM_RKEY_CONT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		/* not used because max links is 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 		smc_llc_protocol_violation(link->lgr, llc_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	kfree(qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) assign:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	/* assign responses to the local flow, we requested them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 	smc_llc_flow_qentry_set(&link->lgr->llc_flow_lcl, qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	wake_up(&link->lgr->llc_msg_waiter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) static void smc_llc_enqueue(struct smc_link *link, union smc_llc_msg *llc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	struct smc_link_group *lgr = link->lgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	struct smc_llc_qentry *qentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	qentry = kmalloc(sizeof(*qentry), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	if (!qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	qentry->link = link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	INIT_LIST_HEAD(&qentry->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	memcpy(&qentry->msg, llc, sizeof(union smc_llc_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	/* process responses immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	if (llc->raw.hdr.flags & SMC_LLC_FLAG_RESP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 		smc_llc_rx_response(link, qentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	/* add requests to event queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	spin_lock_irqsave(&lgr->llc_event_q_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	list_add_tail(&qentry->list, &lgr->llc_event_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	spin_unlock_irqrestore(&lgr->llc_event_q_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	queue_work(system_highpri_wq, &lgr->llc_event_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) /* copy received msg and add it to the event queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) static void smc_llc_rx_handler(struct ib_wc *wc, void *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	struct smc_link *link = (struct smc_link *)wc->qp->qp_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	union smc_llc_msg *llc = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	if (wc->byte_len < sizeof(*llc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 		return; /* short message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	if (llc->raw.hdr.length != sizeof(*llc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 		return; /* invalid message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 	smc_llc_enqueue(link, llc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) /***************************** worker, utils *********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) static void smc_llc_testlink_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	struct smc_link *link = container_of(to_delayed_work(work),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 					     struct smc_link, llc_testlink_wrk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 	unsigned long next_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	unsigned long expire_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	u8 user_data[16] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	if (!smc_link_active(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 		return;		/* don't reschedule worker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	expire_time = link->wr_rx_tstamp + link->llc_testlink_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	if (time_is_after_jiffies(expire_time)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 		next_interval = expire_time - jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	reinit_completion(&link->llc_testlink_resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	smc_llc_send_test_link(link, user_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	/* receive TEST LINK response over RoCE fabric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	rc = wait_for_completion_interruptible_timeout(&link->llc_testlink_resp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 						       SMC_LLC_WAIT_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	if (!smc_link_active(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 		return;		/* link state changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	if (rc <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 		smcr_link_down_cond_sched(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	next_interval = link->llc_testlink_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	schedule_delayed_work(&link->llc_testlink_wrk, next_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) void smc_llc_lgr_init(struct smc_link_group *lgr, struct smc_sock *smc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	struct net *net = sock_net(smc->clcsock->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	INIT_WORK(&lgr->llc_event_work, smc_llc_event_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	INIT_WORK(&lgr->llc_add_link_work, smc_llc_add_link_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	INIT_WORK(&lgr->llc_del_link_work, smc_llc_delete_link_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	INIT_LIST_HEAD(&lgr->llc_event_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	spin_lock_init(&lgr->llc_event_q_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	spin_lock_init(&lgr->llc_flow_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	init_waitqueue_head(&lgr->llc_flow_waiter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	init_waitqueue_head(&lgr->llc_msg_waiter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	mutex_init(&lgr->llc_conf_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 	lgr->llc_testlink_time = net->ipv4.sysctl_tcp_keepalive_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) /* called after lgr was removed from lgr_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) void smc_llc_lgr_clear(struct smc_link_group *lgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	smc_llc_event_flush(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	wake_up_all(&lgr->llc_flow_waiter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	wake_up_all(&lgr->llc_msg_waiter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	cancel_work_sync(&lgr->llc_event_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	cancel_work_sync(&lgr->llc_add_link_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	cancel_work_sync(&lgr->llc_del_link_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	if (lgr->delayed_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 		kfree(lgr->delayed_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 		lgr->delayed_event = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) int smc_llc_link_init(struct smc_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	init_completion(&link->llc_testlink_resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	INIT_DELAYED_WORK(&link->llc_testlink_wrk, smc_llc_testlink_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) void smc_llc_link_active(struct smc_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	pr_warn_ratelimited("smc: SMC-R lg %*phN link added: id %*phN, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 			    "peerid %*phN, ibdev %s, ibport %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 			    SMC_LGR_ID_SIZE, &link->lgr->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 			    SMC_LGR_ID_SIZE, &link->link_uid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 			    SMC_LGR_ID_SIZE, &link->peer_link_uid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 			    link->smcibdev->ibdev->name, link->ibport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	link->state = SMC_LNK_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	if (link->lgr->llc_testlink_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 		link->llc_testlink_time = link->lgr->llc_testlink_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 		schedule_delayed_work(&link->llc_testlink_wrk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 				      link->llc_testlink_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) /* called in worker context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) void smc_llc_link_clear(struct smc_link *link, bool log)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	if (log)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 		pr_warn_ratelimited("smc: SMC-R lg %*phN link removed: id %*phN"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 				    ", peerid %*phN, ibdev %s, ibport %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 				    SMC_LGR_ID_SIZE, &link->lgr->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 				    SMC_LGR_ID_SIZE, &link->link_uid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 				    SMC_LGR_ID_SIZE, &link->peer_link_uid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 				    link->smcibdev->ibdev->name, link->ibport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	complete(&link->llc_testlink_resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	cancel_delayed_work_sync(&link->llc_testlink_wrk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) /* register a new rtoken at the remote peer (for all links) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) int smc_llc_do_confirm_rkey(struct smc_link *send_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 			    struct smc_buf_desc *rmb_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	struct smc_link_group *lgr = send_link->lgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	struct smc_llc_qentry *qentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 	rc = smc_llc_send_confirm_rkey(send_link, rmb_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	/* receive CONFIRM RKEY response from server over RoCE fabric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	qentry = smc_llc_wait(lgr, send_link, SMC_LLC_WAIT_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 			      SMC_LLC_CONFIRM_RKEY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 	if (!qentry || (qentry->msg.raw.hdr.flags & SMC_LLC_FLAG_RKEY_NEG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 		rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	if (qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 		smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) /* unregister an rtoken at the remote peer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) int smc_llc_do_delete_rkey(struct smc_link_group *lgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 			   struct smc_buf_desc *rmb_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	struct smc_llc_qentry *qentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	struct smc_link *send_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 	send_link = smc_llc_usable_link(lgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 	if (!send_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	/* protected by llc_flow control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	rc = smc_llc_send_delete_rkey(send_link, rmb_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	/* receive DELETE RKEY response from server over RoCE fabric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	qentry = smc_llc_wait(lgr, send_link, SMC_LLC_WAIT_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 			      SMC_LLC_DELETE_RKEY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	if (!qentry || (qentry->msg.raw.hdr.flags & SMC_LLC_FLAG_RKEY_NEG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 		rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	if (qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 		smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) void smc_llc_link_set_uid(struct smc_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	__be32 link_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 	link_uid = htonl(*((u32 *)link->lgr->id) + link->link_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 	memcpy(link->link_uid, &link_uid, SMC_LGR_ID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) /* save peers link user id, used for debug purposes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) void smc_llc_save_peer_uid(struct smc_llc_qentry *qentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 	memcpy(qentry->link->peer_link_uid, qentry->msg.confirm_link.link_uid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	       SMC_LGR_ID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) /* evaluate confirm link request or response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) int smc_llc_eval_conf_link(struct smc_llc_qentry *qentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 			   enum smc_llc_reqresp type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 	if (type == SMC_LLC_REQ) {	/* SMC server assigns link_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 		qentry->link->link_id = qentry->msg.confirm_link.link_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 		smc_llc_link_set_uid(qentry->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 	if (!(qentry->msg.raw.hdr.flags & SMC_LLC_FLAG_NO_RMBE_EYEC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 		return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) /***************************** init, exit, misc ******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) static struct smc_wr_rx_handler smc_llc_rx_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 		.handler	= smc_llc_rx_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 		.type		= SMC_LLC_CONFIRM_LINK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 		.handler	= smc_llc_rx_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 		.type		= SMC_LLC_TEST_LINK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 		.handler	= smc_llc_rx_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 		.type		= SMC_LLC_ADD_LINK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 		.handler	= smc_llc_rx_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 		.type		= SMC_LLC_ADD_LINK_CONT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 		.handler	= smc_llc_rx_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 		.type		= SMC_LLC_DELETE_LINK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 		.handler	= smc_llc_rx_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 		.type		= SMC_LLC_CONFIRM_RKEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 		.handler	= smc_llc_rx_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 		.type		= SMC_LLC_CONFIRM_RKEY_CONT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 		.handler	= smc_llc_rx_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 		.type		= SMC_LLC_DELETE_RKEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 		.handler	= NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) int __init smc_llc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	struct smc_wr_rx_handler *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	for (handler = smc_llc_rx_handlers; handler->handler; handler++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 		INIT_HLIST_NODE(&handler->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 		rc = smc_wr_rx_register_handler(handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) }