1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <net/tcp.h>
17#include <rdma/ib_verbs.h>
18
19#include "smc.h"
20#include "smc_core.h"
21#include "smc_clc.h"
22#include "smc_llc.h"
23
24
25
26struct smc_llc_tx_pend {
27};
28
29
30static void smc_llc_tx_handler(struct smc_wr_tx_pend_priv *pend,
31 struct smc_link *link,
32 enum ib_wc_status wc_status)
33{
34
35}
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50static int smc_llc_add_pending_send(struct smc_link *link,
51 struct smc_wr_buf **wr_buf,
52 struct smc_wr_tx_pend_priv **pend)
53{
54 int rc;
55
56 rc = smc_wr_tx_get_free_slot(link, smc_llc_tx_handler, wr_buf, pend);
57 if (rc < 0)
58 return rc;
59 BUILD_BUG_ON_MSG(
60 sizeof(union smc_llc_msg) > SMC_WR_BUF_SIZE,
61 "must increase SMC_WR_BUF_SIZE to at least sizeof(struct smc_llc_msg)");
62 BUILD_BUG_ON_MSG(
63 sizeof(union smc_llc_msg) != SMC_WR_TX_SIZE,
64 "must adapt SMC_WR_TX_SIZE to sizeof(struct smc_llc_msg); if not all smc_wr upper layer protocols use the same message size any more, must start to set link->wr_tx_sges[i].length on each individual smc_wr_tx_send()");
65 BUILD_BUG_ON_MSG(
66 sizeof(struct smc_llc_tx_pend) > SMC_WR_TX_PEND_PRIV_SIZE,
67 "must increase SMC_WR_TX_PEND_PRIV_SIZE to at least sizeof(struct smc_llc_tx_pend)");
68 return 0;
69}
70
71
72int smc_llc_send_confirm_link(struct smc_link *link, u8 mac[],
73 union ib_gid *gid,
74 enum smc_llc_reqresp reqresp)
75{
76 struct smc_link_group *lgr = container_of(link, struct smc_link_group,
77 lnk[SMC_SINGLE_LINK]);
78 struct smc_llc_msg_confirm_link *confllc;
79 struct smc_wr_tx_pend_priv *pend;
80 struct smc_wr_buf *wr_buf;
81 int rc;
82
83 rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
84 if (rc)
85 return rc;
86 confllc = (struct smc_llc_msg_confirm_link *)wr_buf;
87 memset(confllc, 0, sizeof(*confllc));
88 confllc->hd.common.type = SMC_LLC_CONFIRM_LINK;
89 confllc->hd.length = sizeof(struct smc_llc_msg_confirm_link);
90 if (reqresp == SMC_LLC_RESP)
91 confllc->hd.flags |= SMC_LLC_FLAG_RESP;
92 memcpy(confllc->sender_mac, mac, ETH_ALEN);
93 memcpy(confllc->sender_gid, gid, SMC_GID_SIZE);
94 hton24(confllc->sender_qp_num, link->roce_qp->qp_num);
95
96 memcpy(confllc->link_uid, lgr->id, SMC_LGR_ID_SIZE);
97 confllc->max_links = SMC_LINKS_PER_LGR_MAX;
98
99 rc = smc_wr_tx_send(link, pend);
100 return rc;
101}
102
103
104
105static void smc_llc_rx_confirm_link(struct smc_link *link,
106 struct smc_llc_msg_confirm_link *llc)
107{
108 struct smc_link_group *lgr;
109
110 lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
111 if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
112 if (lgr->role == SMC_SERV)
113 complete(&link->llc_confirm_resp);
114 } else {
115 if (lgr->role == SMC_CLNT) {
116 link->link_id = llc->link_num;
117 complete(&link->llc_confirm);
118 }
119 }
120}
121
122static void smc_llc_rx_handler(struct ib_wc *wc, void *buf)
123{
124 struct smc_link *link = (struct smc_link *)wc->qp->qp_context;
125 union smc_llc_msg *llc = buf;
126
127 if (wc->byte_len < sizeof(*llc))
128 return;
129 if (llc->raw.hdr.length != sizeof(*llc))
130 return;
131 if (llc->raw.hdr.common.type == SMC_LLC_CONFIRM_LINK)
132 smc_llc_rx_confirm_link(link, &llc->confirm_link);
133}
134
135
136
137static struct smc_wr_rx_handler smc_llc_rx_handlers[] = {
138 {
139 .handler = smc_llc_rx_handler,
140 .type = SMC_LLC_CONFIRM_LINK
141 },
142 {
143 .handler = NULL,
144 }
145};
146
147int __init smc_llc_init(void)
148{
149 struct smc_wr_rx_handler *handler;
150 int rc = 0;
151
152 for (handler = smc_llc_rx_handlers; handler->handler; handler++) {
153 INIT_HLIST_NODE(&handler->list);
154 rc = smc_wr_rx_register_handler(handler);
155 if (rc)
156 break;
157 }
158 return rc;
159}
160