2 * Shared Memory Communications over RDMA (SMC-R) and RoCE
4 * Definitions for SMC Connections, Link Groups and Links
6 * Copyright IBM Corp. 2016
8 * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com>
14 #include <rdma/ib_verbs.h>
19 struct smc_lgr_list { /* list of link group definition */
20 struct list_head list;
21 spinlock_t lock; /* protects list of link groups */
24 extern struct smc_lgr_list smc_lgr_list; /* list of link groups */
26 enum smc_lgr_role { /* possible roles of a link group */
27 SMC_CLNT, /* client */
32 struct smc_ib_device *smcibdev; /* ib-device */
33 u8 ibport; /* port - values 1 | 2 */
34 struct ib_qp *roce_qp; /* IB queue pair */
35 struct ib_qp_attr qp_attr; /* IB queue pair attributes */
36 union ib_gid gid; /* gid matching used vlan id */
37 u32 peer_qpn; /* QP number of peer */
38 enum ib_mtu path_mtu; /* used mtu */
39 enum ib_mtu peer_mtu; /* mtu size of peer */
40 u32 psn_initial; /* QP tx initial packet seqno */
41 u32 peer_psn; /* QP rx initial packet seqno */
42 u8 peer_mac[ETH_ALEN]; /* = gid[8:10||13:15] */
43 u8 peer_gid[sizeof(union ib_gid)]; /* gid of peer*/
46 /* For now we just allow one parallel link per link group. The SMC protocol
47 * allows more (up to 8).
49 #define SMC_LINKS_PER_LGR_MAX 1
50 #define SMC_SINGLE_LINK 0
52 #define SMC_FIRST_CONTACT 1 /* first contact to a peer */
53 #define SMC_REUSE_CONTACT 0 /* follow-on contact to a peer*/
55 struct smc_link_group {
56 struct list_head list;
57 enum smc_lgr_role role; /* client or server */
58 __be32 daddr; /* destination ip address */
59 struct smc_link lnk[SMC_LINKS_PER_LGR_MAX]; /* smc link */
60 char peer_systemid[SMC_SYSTEMID_LEN];
61 /* unique system_id of peer */
62 struct rb_root conns_all; /* connection tree */
63 rwlock_t conns_lock; /* protects conns_all */
64 unsigned int conns_num; /* current # of connections */
65 unsigned short vlan_id; /* vlan id of link group */
66 struct delayed_work free_work; /* delayed freeing of an lgr */
67 bool sync_err; /* lgr no longer fits to peer */
70 /* Find the connection associated with the given alert token in the link group.
71 * To use rbtrees we have to implement our own search core.
72 * Requires @conns_lock
73 * @token alert token to search for
74 * @lgr link group to search in
75 * Returns connection associated with token if found, NULL otherwise.
77 static inline struct smc_connection *smc_lgr_find_conn(
78 u32 token, struct smc_link_group *lgr)
80 struct smc_connection *res = NULL;
83 node = lgr->conns_all.rb_node;
85 struct smc_connection *cur = rb_entry(node,
86 struct smc_connection, alert_node);
88 if (cur->alert_token_local > token) {
91 if (cur->alert_token_local < token) {
92 node = node->rb_right;
103 void smc_lgr_free(struct smc_link_group *lgr);
104 void smc_lgr_terminate(struct smc_link_group *lgr);