net/smc: remove unused fields from smc structures
[linux-block.git] / net / smc / smc_llc.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
9bf9abea
UB
2/*
3 * Shared Memory Communications over RDMA (SMC-R) and RoCE
4 *
5 * Link Layer Control (LLC)
6 *
7 * For now, we only support the necessary "confirm link" functionality
8 * which happens for the first RoCE link after successful CLC handshake.
9 *
10 * Copyright IBM Corp. 2016
11 *
12 * Author(s): Klaus Wacker <Klaus.Wacker@de.ibm.com>
13 * Ursula Braun <ubraun@linux.vnet.ibm.com>
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
0f627126
SR
24#define SMC_LLC_DATA_LEN 40
25
26struct smc_llc_hdr {
27 struct smc_wr_rx_hdr common;
28 u8 length; /* 44 */
29 u8 reserved;
30 u8 flags;
31};
32
33struct smc_llc_msg_confirm_link { /* type 0x01 */
34 struct smc_llc_hdr hd;
35 u8 sender_mac[ETH_ALEN];
36 u8 sender_gid[SMC_GID_SIZE];
37 u8 sender_qp_num[3];
38 u8 link_num;
39 u8 link_uid[SMC_LGR_ID_SIZE];
40 u8 max_links;
41 u8 reserved[9];
42};
43
44union smc_llc_msg {
45 struct smc_llc_msg_confirm_link confirm_link;
46 struct {
47 struct smc_llc_hdr hdr;
48 u8 data[SMC_LLC_DATA_LEN];
49 } raw;
50};
51
52#define SMC_LLC_FLAG_RESP 0x80
53
9bf9abea
UB
54/********************************** send *************************************/
55
56struct smc_llc_tx_pend {
57};
58
59/* handler for send/transmission completion of an LLC msg */
60static void smc_llc_tx_handler(struct smc_wr_tx_pend_priv *pend,
61 struct smc_link *link,
62 enum ib_wc_status wc_status)
63{
64 /* future work: handle wc_status error for recovery and failover */
65}
66
67/**
68 * smc_llc_add_pending_send() - add LLC control message to pending WQE transmits
69 * @link: Pointer to SMC link used for sending LLC control message.
70 * @wr_buf: Out variable returning pointer to work request payload buffer.
71 * @pend: Out variable returning pointer to private pending WR tracking.
72 * It's the context the transmit complete handler will get.
73 *
74 * Reserves and pre-fills an entry for a pending work request send/tx.
75 * Used by mid-level smc_llc_send_msg() to prepare for later actual send/tx.
76 * Can sleep due to smc_get_ctrl_buf (if not in softirq context).
77 *
78 * Return: 0 on success, otherwise an error value.
79 */
80static int smc_llc_add_pending_send(struct smc_link *link,
81 struct smc_wr_buf **wr_buf,
82 struct smc_wr_tx_pend_priv **pend)
83{
84 int rc;
85
86 rc = smc_wr_tx_get_free_slot(link, smc_llc_tx_handler, wr_buf, pend);
87 if (rc < 0)
88 return rc;
89 BUILD_BUG_ON_MSG(
90 sizeof(union smc_llc_msg) > SMC_WR_BUF_SIZE,
91 "must increase SMC_WR_BUF_SIZE to at least sizeof(struct smc_llc_msg)");
92 BUILD_BUG_ON_MSG(
93 sizeof(union smc_llc_msg) != SMC_WR_TX_SIZE,
94 "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()");
95 BUILD_BUG_ON_MSG(
96 sizeof(struct smc_llc_tx_pend) > SMC_WR_TX_PEND_PRIV_SIZE,
97 "must increase SMC_WR_TX_PEND_PRIV_SIZE to at least sizeof(struct smc_llc_tx_pend)");
98 return 0;
99}
100
101/* high-level API to send LLC confirm link */
102int smc_llc_send_confirm_link(struct smc_link *link, u8 mac[],
103 union ib_gid *gid,
104 enum smc_llc_reqresp reqresp)
105{
106 struct smc_link_group *lgr = container_of(link, struct smc_link_group,
107 lnk[SMC_SINGLE_LINK]);
108 struct smc_llc_msg_confirm_link *confllc;
109 struct smc_wr_tx_pend_priv *pend;
110 struct smc_wr_buf *wr_buf;
111 int rc;
112
113 rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
114 if (rc)
115 return rc;
116 confllc = (struct smc_llc_msg_confirm_link *)wr_buf;
117 memset(confllc, 0, sizeof(*confllc));
118 confllc->hd.common.type = SMC_LLC_CONFIRM_LINK;
119 confllc->hd.length = sizeof(struct smc_llc_msg_confirm_link);
120 if (reqresp == SMC_LLC_RESP)
121 confllc->hd.flags |= SMC_LLC_FLAG_RESP;
122 memcpy(confllc->sender_mac, mac, ETH_ALEN);
123 memcpy(confllc->sender_gid, gid, SMC_GID_SIZE);
124 hton24(confllc->sender_qp_num, link->roce_qp->qp_num);
125 /* confllc->link_num = SMC_SINGLE_LINK; already done by memset above */
126 memcpy(confllc->link_uid, lgr->id, SMC_LGR_ID_SIZE);
127 confllc->max_links = SMC_LINKS_PER_LGR_MAX;
128 /* send llc message */
129 rc = smc_wr_tx_send(link, pend);
130 return rc;
131}
132
133/********************************* receive ***********************************/
134
135static void smc_llc_rx_confirm_link(struct smc_link *link,
136 struct smc_llc_msg_confirm_link *llc)
137{
138 struct smc_link_group *lgr;
139
140 lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
141 if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
142 if (lgr->role == SMC_SERV)
143 complete(&link->llc_confirm_resp);
144 } else {
145 if (lgr->role == SMC_CLNT) {
146 link->link_id = llc->link_num;
147 complete(&link->llc_confirm);
148 }
149 }
150}
151
152static void smc_llc_rx_handler(struct ib_wc *wc, void *buf)
153{
154 struct smc_link *link = (struct smc_link *)wc->qp->qp_context;
155 union smc_llc_msg *llc = buf;
156
157 if (wc->byte_len < sizeof(*llc))
158 return; /* short message */
159 if (llc->raw.hdr.length != sizeof(*llc))
160 return; /* invalid message */
161 if (llc->raw.hdr.common.type == SMC_LLC_CONFIRM_LINK)
162 smc_llc_rx_confirm_link(link, &llc->confirm_link);
163}
164
165/***************************** init, exit, misc ******************************/
166
167static struct smc_wr_rx_handler smc_llc_rx_handlers[] = {
168 {
169 .handler = smc_llc_rx_handler,
170 .type = SMC_LLC_CONFIRM_LINK
171 },
172 {
173 .handler = NULL,
174 }
175};
176
177int __init smc_llc_init(void)
178{
179 struct smc_wr_rx_handler *handler;
180 int rc = 0;
181
182 for (handler = smc_llc_rx_handlers; handler->handler; handler++) {
183 INIT_HLIST_NODE(&handler->list);
184 rc = smc_wr_rx_register_handler(handler);
185 if (rc)
186 break;
187 }
188 return rc;
189}