]> git.ipfire.org Git - people/arne_f/kernel.git/blame - net/smc/smc_core.h
smc: work request (WR) base for use by LLC and CDC
[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 */
93 u32 used; /* currently used / unused */
94};
95
0cfdd8f9
UB
96struct smc_link_group {
97 struct list_head list;
98 enum smc_lgr_role role; /* client or server */
99 __be32 daddr; /* destination ip address */
100 struct smc_link lnk[SMC_LINKS_PER_LGR_MAX]; /* smc link */
101 char peer_systemid[SMC_SYSTEMID_LEN];
102 /* unique system_id of peer */
103 struct rb_root conns_all; /* connection tree */
104 rwlock_t conns_lock; /* protects conns_all */
105 unsigned int conns_num; /* current # of connections */
106 unsigned short vlan_id; /* vlan id of link group */
cd6851f3
UB
107
108 struct list_head sndbufs[SMC_RMBE_SIZES];/* tx buffers */
109 rwlock_t sndbufs_lock; /* protects tx buffers */
110 struct list_head rmbs[SMC_RMBE_SIZES]; /* rx buffers */
111 rwlock_t rmbs_lock; /* protects rx buffers */
0cfdd8f9
UB
112 struct delayed_work free_work; /* delayed freeing of an lgr */
113 bool sync_err; /* lgr no longer fits to peer */
114};
115
116/* Find the connection associated with the given alert token in the link group.
117 * To use rbtrees we have to implement our own search core.
118 * Requires @conns_lock
119 * @token alert token to search for
120 * @lgr link group to search in
121 * Returns connection associated with token if found, NULL otherwise.
122 */
123static inline struct smc_connection *smc_lgr_find_conn(
124 u32 token, struct smc_link_group *lgr)
125{
126 struct smc_connection *res = NULL;
127 struct rb_node *node;
128
129 node = lgr->conns_all.rb_node;
130 while (node) {
131 struct smc_connection *cur = rb_entry(node,
132 struct smc_connection, alert_node);
133
134 if (cur->alert_token_local > token) {
135 node = node->rb_left;
136 } else {
137 if (cur->alert_token_local < token) {
138 node = node->rb_right;
139 } else {
140 res = cur;
141 break;
142 }
143 }
144 }
145
146 return res;
147}
148
cd6851f3
UB
149struct smc_sock;
150struct smc_clc_msg_accept_confirm;
151
0cfdd8f9
UB
152void smc_lgr_free(struct smc_link_group *lgr);
153void smc_lgr_terminate(struct smc_link_group *lgr);
cd6851f3
UB
154int smc_sndbuf_create(struct smc_sock *smc);
155int smc_rmb_create(struct smc_sock *smc);
0cfdd8f9
UB
156
157#endif