]> git.ipfire.org Git - people/arne_f/kernel.git/blame - net/smc/smc_core.h
smc: initialize IB transport incl. PD, MR, QP, CQ, event, WR
[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
f38ba179 14#include <linux/atomic.h>
0cfdd8f9
UB
15#include <rdma/ib_verbs.h>
16
17#include "smc.h"
18#include "smc_ib.h"
19
cd6851f3
UB
20#define SMC_RMBS_PER_LGR_MAX 255 /* max. # of RMBs per link group */
21
0cfdd8f9
UB
22struct smc_lgr_list { /* list of link group definition */
23 struct list_head list;
24 spinlock_t lock; /* protects list of link groups */
25};
26
27extern struct smc_lgr_list smc_lgr_list; /* list of link groups */
28
29enum smc_lgr_role { /* possible roles of a link group */
30 SMC_CLNT, /* client */
31 SMC_SERV /* server */
32};
33
f38ba179
UB
34#define SMC_WR_BUF_SIZE 48 /* size of work request buffer */
35
36struct smc_wr_buf {
37 u8 raw[SMC_WR_BUF_SIZE];
38};
39
0cfdd8f9
UB
40struct smc_link {
41 struct smc_ib_device *smcibdev; /* ib-device */
42 u8 ibport; /* port - values 1 | 2 */
f38ba179
UB
43 struct ib_pd *roce_pd; /* IB protection domain,
44 * unique for every RoCE QP
45 */
0cfdd8f9
UB
46 struct ib_qp *roce_qp; /* IB queue pair */
47 struct ib_qp_attr qp_attr; /* IB queue pair attributes */
f38ba179
UB
48
49 struct smc_wr_buf *wr_tx_bufs; /* WR send payload buffers */
50 struct ib_send_wr *wr_tx_ibs; /* WR send meta data */
51 struct ib_sge *wr_tx_sges; /* WR send gather meta data */
52 struct smc_wr_tx_pend *wr_tx_pends; /* WR send waiting for CQE */
53 /* above four vectors have wr_tx_cnt elements and use the same index */
54 dma_addr_t wr_tx_dma_addr; /* DMA address of wr_tx_bufs */
55 atomic_long_t wr_tx_id; /* seq # of last sent WR */
56 unsigned long *wr_tx_mask; /* bit mask of used indexes */
57 u32 wr_tx_cnt; /* number of WR send buffers */
58 wait_queue_head_t wr_tx_wait; /* wait for free WR send buf */
59
60 struct smc_wr_buf *wr_rx_bufs; /* WR recv payload buffers */
61 struct ib_recv_wr *wr_rx_ibs; /* WR recv meta data */
62 struct ib_sge *wr_rx_sges; /* WR recv scatter meta data */
63 /* above three vectors have wr_rx_cnt elements and use the same index */
64 dma_addr_t wr_rx_dma_addr; /* DMA address of wr_rx_bufs */
65 u64 wr_rx_id; /* seq # of last recv WR */
66 u32 wr_rx_cnt; /* number of WR recv buffers */
67
0cfdd8f9
UB
68 union ib_gid gid; /* gid matching used vlan id */
69 u32 peer_qpn; /* QP number of peer */
70 enum ib_mtu path_mtu; /* used mtu */
71 enum ib_mtu peer_mtu; /* mtu size of peer */
72 u32 psn_initial; /* QP tx initial packet seqno */
73 u32 peer_psn; /* QP rx initial packet seqno */
74 u8 peer_mac[ETH_ALEN]; /* = gid[8:10||13:15] */
75 u8 peer_gid[sizeof(union ib_gid)]; /* gid of peer*/
76};
77
78/* For now we just allow one parallel link per link group. The SMC protocol
79 * allows more (up to 8).
80 */
81#define SMC_LINKS_PER_LGR_MAX 1
82#define SMC_SINGLE_LINK 0
83
84#define SMC_FIRST_CONTACT 1 /* first contact to a peer */
85#define SMC_REUSE_CONTACT 0 /* follow-on contact to a peer*/
86
cd6851f3
UB
87/* tx/rx buffer list element for sndbufs list and rmbs list of a lgr */
88struct smc_buf_desc {
89 struct list_head list;
90 u64 dma_addr[SMC_LINKS_PER_LGR_MAX];
91 /* mapped address of buffer */
92 void *cpu_addr; /* virtual address of buffer */
bd4ad577
UB
93 struct ib_mr *mr_rx[SMC_LINKS_PER_LGR_MAX];
94 /* for rmb only:
95 * rkey provided to peer
96 */
cd6851f3
UB
97 u32 used; /* currently used / unused */
98};
99
bd4ad577
UB
100struct smc_rtoken { /* address/key of remote RMB */
101 u64 dma_addr;
102 u32 rkey;
103};
104
0cfdd8f9
UB
105struct smc_link_group {
106 struct list_head list;
107 enum smc_lgr_role role; /* client or server */
108 __be32 daddr; /* destination ip address */
109 struct smc_link lnk[SMC_LINKS_PER_LGR_MAX]; /* smc link */
110 char peer_systemid[SMC_SYSTEMID_LEN];
111 /* unique system_id of peer */
112 struct rb_root conns_all; /* connection tree */
113 rwlock_t conns_lock; /* protects conns_all */
114 unsigned int conns_num; /* current # of connections */
115 unsigned short vlan_id; /* vlan id of link group */
cd6851f3
UB
116
117 struct list_head sndbufs[SMC_RMBE_SIZES];/* tx buffers */
118 rwlock_t sndbufs_lock; /* protects tx buffers */
119 struct list_head rmbs[SMC_RMBE_SIZES]; /* rx buffers */
120 rwlock_t rmbs_lock; /* protects rx buffers */
bd4ad577
UB
121 struct smc_rtoken rtokens[SMC_RMBS_PER_LGR_MAX]
122 [SMC_LINKS_PER_LGR_MAX];
123 /* remote addr/key pairs */
124 unsigned long rtokens_used_mask[BITS_TO_LONGS(
125 SMC_RMBS_PER_LGR_MAX)];
126 /* used rtoken elements */
127
0cfdd8f9
UB
128 struct delayed_work free_work; /* delayed freeing of an lgr */
129 bool sync_err; /* lgr no longer fits to peer */
130};
131
132/* Find the connection associated with the given alert token in the link group.
133 * To use rbtrees we have to implement our own search core.
134 * Requires @conns_lock
135 * @token alert token to search for
136 * @lgr link group to search in
137 * Returns connection associated with token if found, NULL otherwise.
138 */
139static inline struct smc_connection *smc_lgr_find_conn(
140 u32 token, struct smc_link_group *lgr)
141{
142 struct smc_connection *res = NULL;
143 struct rb_node *node;
144
145 node = lgr->conns_all.rb_node;
146 while (node) {
147 struct smc_connection *cur = rb_entry(node,
148 struct smc_connection, alert_node);
149
150 if (cur->alert_token_local > token) {
151 node = node->rb_left;
152 } else {
153 if (cur->alert_token_local < token) {
154 node = node->rb_right;
155 } else {
156 res = cur;
157 break;
158 }
159 }
160 }
161
162 return res;
163}
164
cd6851f3
UB
165struct smc_sock;
166struct smc_clc_msg_accept_confirm;
167
0cfdd8f9
UB
168void smc_lgr_free(struct smc_link_group *lgr);
169void smc_lgr_terminate(struct smc_link_group *lgr);
cd6851f3
UB
170int smc_sndbuf_create(struct smc_sock *smc);
171int smc_rmb_create(struct smc_sock *smc);
bd4ad577
UB
172int smc_rmb_rtoken_handling(struct smc_connection *conn,
173 struct smc_clc_msg_accept_confirm *clc);
0cfdd8f9
UB
174
175#endif