]> git.ipfire.org Git - people/arne_f/kernel.git/blame - net/smc/smc_core.h
smc: remote memory buffers (RMBs)
[people/arne_f/kernel.git] / net / smc / smc_core.h
CommitLineData
0cfdd8f9
UB
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
cd6851f3
UB
19#define SMC_RMBS_PER_LGR_MAX 255 /* max. # of RMBs per link group */
20
0cfdd8f9
UB
21struct smc_lgr_list { /* list of link group definition */
22 struct list_head list;
23 spinlock_t lock; /* protects list of link groups */
24};
25
26extern struct smc_lgr_list smc_lgr_list; /* list of link groups */
27
28enum smc_lgr_role { /* possible roles of a link group */
29 SMC_CLNT, /* client */
30 SMC_SERV /* server */
31};
32
33struct smc_link {
34 struct smc_ib_device *smcibdev; /* ib-device */
35 u8 ibport; /* port - values 1 | 2 */
36 struct ib_qp *roce_qp; /* IB queue pair */
37 struct ib_qp_attr qp_attr; /* IB queue pair attributes */
38 union ib_gid gid; /* gid matching used vlan id */
39 u32 peer_qpn; /* QP number of peer */
40 enum ib_mtu path_mtu; /* used mtu */
41 enum ib_mtu peer_mtu; /* mtu size of peer */
42 u32 psn_initial; /* QP tx initial packet seqno */
43 u32 peer_psn; /* QP rx initial packet seqno */
44 u8 peer_mac[ETH_ALEN]; /* = gid[8:10||13:15] */
45 u8 peer_gid[sizeof(union ib_gid)]; /* gid of peer*/
46};
47
48/* For now we just allow one parallel link per link group. The SMC protocol
49 * allows more (up to 8).
50 */
51#define SMC_LINKS_PER_LGR_MAX 1
52#define SMC_SINGLE_LINK 0
53
54#define SMC_FIRST_CONTACT 1 /* first contact to a peer */
55#define SMC_REUSE_CONTACT 0 /* follow-on contact to a peer*/
56
cd6851f3
UB
57/* tx/rx buffer list element for sndbufs list and rmbs list of a lgr */
58struct smc_buf_desc {
59 struct list_head list;
60 u64 dma_addr[SMC_LINKS_PER_LGR_MAX];
61 /* mapped address of buffer */
62 void *cpu_addr; /* virtual address of buffer */
63 u32 used; /* currently used / unused */
64};
65
0cfdd8f9
UB
66struct smc_link_group {
67 struct list_head list;
68 enum smc_lgr_role role; /* client or server */
69 __be32 daddr; /* destination ip address */
70 struct smc_link lnk[SMC_LINKS_PER_LGR_MAX]; /* smc link */
71 char peer_systemid[SMC_SYSTEMID_LEN];
72 /* unique system_id of peer */
73 struct rb_root conns_all; /* connection tree */
74 rwlock_t conns_lock; /* protects conns_all */
75 unsigned int conns_num; /* current # of connections */
76 unsigned short vlan_id; /* vlan id of link group */
cd6851f3
UB
77
78 struct list_head sndbufs[SMC_RMBE_SIZES];/* tx buffers */
79 rwlock_t sndbufs_lock; /* protects tx buffers */
80 struct list_head rmbs[SMC_RMBE_SIZES]; /* rx buffers */
81 rwlock_t rmbs_lock; /* protects rx buffers */
0cfdd8f9
UB
82 struct delayed_work free_work; /* delayed freeing of an lgr */
83 bool sync_err; /* lgr no longer fits to peer */
84};
85
86/* Find the connection associated with the given alert token in the link group.
87 * To use rbtrees we have to implement our own search core.
88 * Requires @conns_lock
89 * @token alert token to search for
90 * @lgr link group to search in
91 * Returns connection associated with token if found, NULL otherwise.
92 */
93static inline struct smc_connection *smc_lgr_find_conn(
94 u32 token, struct smc_link_group *lgr)
95{
96 struct smc_connection *res = NULL;
97 struct rb_node *node;
98
99 node = lgr->conns_all.rb_node;
100 while (node) {
101 struct smc_connection *cur = rb_entry(node,
102 struct smc_connection, alert_node);
103
104 if (cur->alert_token_local > token) {
105 node = node->rb_left;
106 } else {
107 if (cur->alert_token_local < token) {
108 node = node->rb_right;
109 } else {
110 res = cur;
111 break;
112 }
113 }
114 }
115
116 return res;
117}
118
cd6851f3
UB
119struct smc_sock;
120struct smc_clc_msg_accept_confirm;
121
0cfdd8f9
UB
122void smc_lgr_free(struct smc_link_group *lgr);
123void smc_lgr_terminate(struct smc_link_group *lgr);
cd6851f3
UB
124int smc_sndbuf_create(struct smc_sock *smc);
125int smc_rmb_create(struct smc_sock *smc);
0cfdd8f9
UB
126
127#endif