1
2
3
4
5
6
7
8
9
10
11
12#ifndef _SMC_CORE_H
13#define _SMC_CORE_H
14
15#include <linux/atomic.h>
16#include <linux/smc.h>
17#include <linux/pci.h>
18#include <rdma/ib_verbs.h>
19#include <net/genetlink.h>
20
21#include "smc.h"
22#include "smc_ib.h"
23
24#define SMC_RMBS_PER_LGR_MAX 255
25
26struct smc_lgr_list {
27 struct list_head list;
28 spinlock_t lock;
29 u32 num;
30};
31
32enum smc_lgr_role {
33 SMC_CLNT,
34 SMC_SERV
35};
36
37enum smc_link_state {
38 SMC_LNK_UNUSED,
39 SMC_LNK_INACTIVE,
40 SMC_LNK_ACTIVATING,
41 SMC_LNK_ACTIVE,
42};
43
44#define SMC_WR_BUF_SIZE 48
45
46struct smc_wr_buf {
47 u8 raw[SMC_WR_BUF_SIZE];
48};
49
50#define SMC_WR_REG_MR_WAIT_TIME (5 * HZ)
51
52enum smc_wr_reg_state {
53 POSTED,
54 CONFIRMED,
55 FAILED
56};
57
58struct smc_rdma_sge {
59 struct ib_sge wr_tx_rdma_sge[SMC_IB_MAX_SEND_SGE];
60};
61
62#define SMC_MAX_RDMA_WRITES 2
63
64
65
66struct smc_rdma_sges {
67 struct smc_rdma_sge tx_rdma_sge[SMC_MAX_RDMA_WRITES];
68};
69
70struct smc_rdma_wr {
71
72
73 struct ib_rdma_wr wr_tx_rdma[SMC_MAX_RDMA_WRITES];
74};
75
76#define SMC_LGR_ID_SIZE 4
77
78struct smc_link {
79 struct smc_ib_device *smcibdev;
80 u8 ibport;
81 struct ib_pd *roce_pd;
82
83
84 struct ib_qp *roce_qp;
85 struct ib_qp_attr qp_attr;
86
87 struct smc_wr_buf *wr_tx_bufs;
88 struct ib_send_wr *wr_tx_ibs;
89 struct ib_sge *wr_tx_sges;
90 struct smc_rdma_sges *wr_tx_rdma_sges;
91 struct smc_rdma_wr *wr_tx_rdmas;
92 struct smc_wr_tx_pend *wr_tx_pends;
93 struct completion *wr_tx_compl;
94
95 dma_addr_t wr_tx_dma_addr;
96 atomic_long_t wr_tx_id;
97 unsigned long *wr_tx_mask;
98 u32 wr_tx_cnt;
99 wait_queue_head_t wr_tx_wait;
100
101 struct smc_wr_buf *wr_rx_bufs;
102 struct ib_recv_wr *wr_rx_ibs;
103 struct ib_sge *wr_rx_sges;
104
105 dma_addr_t wr_rx_dma_addr;
106 u64 wr_rx_id;
107 u32 wr_rx_cnt;
108 unsigned long wr_rx_tstamp;
109
110 struct ib_reg_wr wr_reg;
111 wait_queue_head_t wr_reg_wait;
112 enum smc_wr_reg_state wr_reg_state;
113
114 u8 gid[SMC_GID_SIZE];
115 u8 sgid_index;
116 u32 peer_qpn;
117 enum ib_mtu path_mtu;
118 enum ib_mtu peer_mtu;
119 u32 psn_initial;
120 u32 peer_psn;
121 u8 peer_mac[ETH_ALEN];
122 u8 peer_gid[SMC_GID_SIZE];
123 u8 link_id;
124 u8 link_uid[SMC_LGR_ID_SIZE];
125 u8 peer_link_uid[SMC_LGR_ID_SIZE];
126 u8 link_idx;
127 u8 link_is_asym;
128 struct smc_link_group *lgr;
129 struct work_struct link_down_wrk;
130 char ibname[IB_DEVICE_NAME_MAX];
131 int ndev_ifidx;
132
133 enum smc_link_state state;
134 struct delayed_work llc_testlink_wrk;
135 struct completion llc_testlink_resp;
136 int llc_testlink_time;
137 atomic_t conn_cnt;
138};
139
140
141
142
143#define SMC_LINKS_PER_LGR_MAX 3
144#define SMC_SINGLE_LINK 0
145
146
147struct smc_buf_desc {
148 struct list_head list;
149 void *cpu_addr;
150 struct page *pages;
151 int len;
152 u32 used;
153 union {
154 struct {
155 struct sg_table sgt[SMC_LINKS_PER_LGR_MAX];
156
157 struct ib_mr *mr_rx[SMC_LINKS_PER_LGR_MAX];
158
159
160
161 u32 order;
162
163 u8 is_conf_rkey;
164
165 u8 is_reg_mr[SMC_LINKS_PER_LGR_MAX];
166
167 u8 is_map_ib[SMC_LINKS_PER_LGR_MAX];
168
169 u8 is_reg_err;
170
171 };
172 struct {
173 unsigned short sba_idx;
174
175 u64 token;
176
177 dma_addr_t dma_addr;
178
179 };
180 };
181};
182
183struct smc_rtoken {
184 u64 dma_addr;
185 u32 rkey;
186};
187
188#define SMC_BUF_MIN_SIZE 16384
189#define SMC_RMBE_SIZES 16
190
191
192
193
194
195struct smcd_dev;
196
197enum smc_lgr_type {
198 SMC_LGR_NONE,
199 SMC_LGR_SINGLE,
200 SMC_LGR_SYMMETRIC,
201 SMC_LGR_ASYMMETRIC_PEER,
202 SMC_LGR_ASYMMETRIC_LOCAL,
203};
204
205enum smc_llc_flowtype {
206 SMC_LLC_FLOW_NONE = 0,
207 SMC_LLC_FLOW_ADD_LINK = 2,
208 SMC_LLC_FLOW_DEL_LINK = 4,
209 SMC_LLC_FLOW_RKEY = 6,
210};
211
212struct smc_llc_qentry;
213
214struct smc_llc_flow {
215 enum smc_llc_flowtype type;
216 struct smc_llc_qentry *qentry;
217};
218
219struct smc_link_group {
220 struct list_head list;
221 struct rb_root conns_all;
222 rwlock_t conns_lock;
223 unsigned int conns_num;
224 unsigned short vlan_id;
225
226 struct list_head sndbufs[SMC_RMBE_SIZES];
227 struct mutex sndbufs_lock;
228 struct list_head rmbs[SMC_RMBE_SIZES];
229 struct mutex rmbs_lock;
230
231 u8 id[SMC_LGR_ID_SIZE];
232 struct delayed_work free_work;
233 struct work_struct terminate_work;
234 struct workqueue_struct *tx_wq;
235 u8 sync_err : 1;
236 u8 terminating : 1;
237 u8 freeing : 1;
238
239 bool is_smcd;
240 u8 smc_version;
241 u8 negotiated_eid[SMC_MAX_EID_LEN];
242 u8 peer_os;
243 u8 peer_smc_release;
244 u8 peer_hostname[SMC_MAX_HOSTNAME_LEN];
245 union {
246 struct {
247 enum smc_lgr_role role;
248
249 struct smc_link lnk[SMC_LINKS_PER_LGR_MAX];
250
251 char peer_systemid[SMC_SYSTEMID_LEN];
252
253 struct smc_rtoken rtokens[SMC_RMBS_PER_LGR_MAX]
254 [SMC_LINKS_PER_LGR_MAX];
255
256 DECLARE_BITMAP(rtokens_used_mask, SMC_RMBS_PER_LGR_MAX);
257
258 u8 next_link_id;
259 enum smc_lgr_type type;
260
261 u8 pnet_id[SMC_MAX_PNETID_LEN + 1];
262
263 struct list_head llc_event_q;
264
265 spinlock_t llc_event_q_lock;
266
267 struct mutex llc_conf_mutex;
268
269 struct work_struct llc_add_link_work;
270 struct work_struct llc_del_link_work;
271 struct work_struct llc_event_work;
272
273 wait_queue_head_t llc_flow_waiter;
274
275 wait_queue_head_t llc_msg_waiter;
276
277 struct smc_llc_flow llc_flow_lcl;
278
279 struct smc_llc_flow llc_flow_rmt;
280
281 struct smc_llc_qentry *delayed_event;
282
283 spinlock_t llc_flow_lock;
284
285 int llc_testlink_time;
286
287 u32 llc_termination_rsn;
288
289 };
290 struct {
291 u64 peer_gid;
292
293 struct smcd_dev *smcd;
294
295 u8 peer_shutdown : 1;
296
297 };
298 };
299};
300
301struct smc_clc_msg_local;
302
303struct smc_init_info {
304 u8 is_smcd;
305 u8 smc_type_v1;
306 u8 smc_type_v2;
307 u8 first_contact_peer;
308 u8 first_contact_local;
309 unsigned short vlan_id;
310 u32 rc;
311
312 struct smc_clc_msg_local *ib_lcl;
313 struct smc_ib_device *ib_dev;
314 u8 ib_gid[SMC_GID_SIZE];
315 u8 ib_port;
316 u32 ib_clcqpn;
317
318 u64 ism_peer_gid[SMC_MAX_ISM_DEVS + 1];
319 struct smcd_dev *ism_dev[SMC_MAX_ISM_DEVS + 1];
320 u16 ism_chid[SMC_MAX_ISM_DEVS + 1];
321 u8 ism_offered_cnt;
322 u8 ism_selected;
323 u8 smcd_version;
324};
325
326
327
328
329
330
331
332
333static inline struct smc_connection *smc_lgr_find_conn(
334 u32 token, struct smc_link_group *lgr)
335{
336 struct smc_connection *res = NULL;
337 struct rb_node *node;
338
339 node = lgr->conns_all.rb_node;
340 while (node) {
341 struct smc_connection *cur = rb_entry(node,
342 struct smc_connection, alert_node);
343
344 if (cur->alert_token_local > token) {
345 node = node->rb_left;
346 } else {
347 if (cur->alert_token_local < token) {
348 node = node->rb_right;
349 } else {
350 res = cur;
351 break;
352 }
353 }
354 }
355
356 return res;
357}
358
359
360static inline bool smc_link_usable(struct smc_link *lnk)
361{
362 if (lnk->state == SMC_LNK_UNUSED || lnk->state == SMC_LNK_INACTIVE)
363 return false;
364 return true;
365}
366
367static inline bool smc_link_active(struct smc_link *lnk)
368{
369 return lnk->state == SMC_LNK_ACTIVE;
370}
371
372static inline void smc_gid_be16_convert(__u8 *buf, u8 *gid_raw)
373{
374 sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
375 be16_to_cpu(((__be16 *)gid_raw)[0]),
376 be16_to_cpu(((__be16 *)gid_raw)[1]),
377 be16_to_cpu(((__be16 *)gid_raw)[2]),
378 be16_to_cpu(((__be16 *)gid_raw)[3]),
379 be16_to_cpu(((__be16 *)gid_raw)[4]),
380 be16_to_cpu(((__be16 *)gid_raw)[5]),
381 be16_to_cpu(((__be16 *)gid_raw)[6]),
382 be16_to_cpu(((__be16 *)gid_raw)[7]));
383}
384
385struct smc_pci_dev {
386 __u32 pci_fid;
387 __u16 pci_pchid;
388 __u16 pci_vendor;
389 __u16 pci_device;
390 __u8 pci_id[SMC_PCI_ID_STR_LEN];
391};
392
393static inline void smc_set_pci_values(struct pci_dev *pci_dev,
394 struct smc_pci_dev *smc_dev)
395{
396 smc_dev->pci_vendor = pci_dev->vendor;
397 smc_dev->pci_device = pci_dev->device;
398 snprintf(smc_dev->pci_id, sizeof(smc_dev->pci_id), "%s",
399 pci_name(pci_dev));
400#if IS_ENABLED(CONFIG_S390)
401 {
402 struct zpci_dev *zdev;
403
404 zdev = to_zpci(pci_dev);
405 smc_dev->pci_fid = zdev->fid;
406 smc_dev->pci_pchid = zdev->pchid;
407 }
408#endif
409}
410
411struct smc_sock;
412struct smc_clc_msg_accept_confirm;
413struct smc_clc_msg_local;
414
415void smc_lgr_cleanup_early(struct smc_connection *conn);
416void smc_lgr_terminate_sched(struct smc_link_group *lgr);
417void smcr_port_add(struct smc_ib_device *smcibdev, u8 ibport);
418void smcr_port_err(struct smc_ib_device *smcibdev, u8 ibport);
419void smc_smcd_terminate(struct smcd_dev *dev, u64 peer_gid,
420 unsigned short vlan);
421void smc_smcd_terminate_all(struct smcd_dev *dev);
422void smc_smcr_terminate_all(struct smc_ib_device *smcibdev);
423int smc_buf_create(struct smc_sock *smc, bool is_smcd);
424int smc_uncompress_bufsize(u8 compressed);
425int smc_rmb_rtoken_handling(struct smc_connection *conn, struct smc_link *link,
426 struct smc_clc_msg_accept_confirm *clc);
427int smc_rtoken_add(struct smc_link *lnk, __be64 nw_vaddr, __be32 nw_rkey);
428int smc_rtoken_delete(struct smc_link *lnk, __be32 nw_rkey);
429void smc_rtoken_set(struct smc_link_group *lgr, int link_idx, int link_idx_new,
430 __be32 nw_rkey_known, __be64 nw_vaddr, __be32 nw_rkey);
431void smc_rtoken_set2(struct smc_link_group *lgr, int rtok_idx, int link_id,
432 __be64 nw_vaddr, __be32 nw_rkey);
433void smc_sndbuf_sync_sg_for_cpu(struct smc_connection *conn);
434void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn);
435void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn);
436void smc_rmb_sync_sg_for_device(struct smc_connection *conn);
437int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini);
438
439void smc_conn_free(struct smc_connection *conn);
440int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini);
441void smc_lgr_schedule_free_work_fast(struct smc_link_group *lgr);
442int smc_core_init(void);
443void smc_core_exit(void);
444
445int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk,
446 u8 link_idx, struct smc_init_info *ini);
447void smcr_link_clear(struct smc_link *lnk, bool log);
448int smcr_buf_map_lgr(struct smc_link *lnk);
449int smcr_buf_reg_lgr(struct smc_link *lnk);
450void smcr_lgr_set_type(struct smc_link_group *lgr, enum smc_lgr_type new_type);
451void smcr_lgr_set_type_asym(struct smc_link_group *lgr,
452 enum smc_lgr_type new_type, int asym_lnk_idx);
453int smcr_link_reg_rmb(struct smc_link *link, struct smc_buf_desc *rmb_desc);
454struct smc_link *smc_switch_conns(struct smc_link_group *lgr,
455 struct smc_link *from_lnk, bool is_dev_err);
456void smcr_link_down_cond(struct smc_link *lnk);
457void smcr_link_down_cond_sched(struct smc_link *lnk);
458int smc_nl_get_sys_info(struct sk_buff *skb, struct netlink_callback *cb);
459int smcr_nl_get_lgr(struct sk_buff *skb, struct netlink_callback *cb);
460int smcr_nl_get_link(struct sk_buff *skb, struct netlink_callback *cb);
461int smcd_nl_get_lgr(struct sk_buff *skb, struct netlink_callback *cb);
462
463static inline struct smc_link_group *smc_get_lgr(struct smc_link *link)
464{
465 return link->lgr;
466}
467#endif
468