14b787abae02a58cb3bbc620d014d548bc097411
[platform/kernel/linux-rpi.git] / net / smc / smc_core.h
1 /*
2  * Shared Memory Communications over RDMA (SMC-R) and RoCE
3  *
4  *  Definitions for SMC Connections, Link Groups and Links
5  *
6  *  Copyright IBM Corp. 2016
7  *
8  *  Author(s):  Ursula Braun <ubraun@linux.vnet.ibm.com>
9  */
10
11 #ifndef _SMC_CORE_H
12 #define _SMC_CORE_H
13
14 #include <rdma/ib_verbs.h>
15
16 #include "smc.h"
17 #include "smc_ib.h"
18
19 struct smc_lgr_list {                   /* list of link group definition */
20         struct list_head        list;
21         spinlock_t              lock;   /* protects list of link groups */
22 };
23
24 extern struct smc_lgr_list      smc_lgr_list; /* list of link groups */
25
26 enum smc_lgr_role {             /* possible roles of a link group */
27         SMC_CLNT,       /* client */
28         SMC_SERV        /* server */
29 };
30
31 struct smc_link {
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*/
44 };
45
46 /* For now we just allow one parallel link per link group. The SMC protocol
47  * allows more (up to 8).
48  */
49 #define SMC_LINKS_PER_LGR_MAX   1
50 #define SMC_SINGLE_LINK         0
51
52 #define SMC_FIRST_CONTACT       1               /* first contact to a peer */
53 #define SMC_REUSE_CONTACT       0               /* follow-on contact to a peer*/
54
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 */
68 };
69
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.
76  */
77 static inline struct smc_connection *smc_lgr_find_conn(
78         u32 token, struct smc_link_group *lgr)
79 {
80         struct smc_connection *res = NULL;
81         struct rb_node *node;
82
83         node = lgr->conns_all.rb_node;
84         while (node) {
85                 struct smc_connection *cur = rb_entry(node,
86                                         struct smc_connection, alert_node);
87
88                 if (cur->alert_token_local > token) {
89                         node = node->rb_left;
90                 } else {
91                         if (cur->alert_token_local < token) {
92                                 node = node->rb_right;
93                         } else {
94                                 res = cur;
95                                 break;
96                         }
97                 }
98         }
99
100         return res;
101 }
102
103 void smc_lgr_free(struct smc_link_group *lgr);
104 void smc_lgr_terminate(struct smc_link_group *lgr);
105
106 #endif