Skip to content

Commit f38ba17

Browse files
Ursula Braundavem330
authored andcommitted
smc: work request (WR) base for use by LLC and CDC
The base containers for RDMA transport are work requests and completion queue entries processed through Infiniband verbs: * allocate and initialize these areas * map these areas to DMA * implement the basic communication consisting of work request posting and receival of completion queue events Signed-off-by: Ursula Braun <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cd6851f commit f38ba17

File tree

8 files changed

+790
-1
lines changed

8 files changed

+790
-1
lines changed

net/smc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
obj-$(CONFIG_SMC) += smc.o
2-
smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o
2+
smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o

net/smc/smc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <linux/socket.h>
1414
#include <linux/types.h>
15+
#include <linux/compiler.h> /* __aligned */
1516
#include <net/sock.h>
1617

1718
#include "smc_ib.h"
@@ -29,6 +30,10 @@ enum smc_state { /* possible states of an SMC socket */
2930

3031
struct smc_link_group;
3132

33+
struct smc_wr_rx_hdr { /* common prefix part of LLC and CDC to demultiplex */
34+
u8 type;
35+
} __aligned(1);
36+
3237
struct smc_connection {
3338
struct rb_node alert_node;
3439
struct smc_link_group *lgr; /* link group of connection */

net/smc/smc_core.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "smc_clc.h"
2121
#include "smc_core.h"
2222
#include "smc_ib.h"
23+
#include "smc_wr.h"
2324

2425
#define SMC_LGR_FREE_DELAY (600 * HZ)
2526

@@ -161,12 +162,20 @@ static int smc_lgr_create(struct smc_sock *smc, __be32 peer_in_addr,
161162
lnk->path_mtu = smcibdev->pattr[ibport - 1].active_mtu;
162163
get_random_bytes(rndvec, sizeof(rndvec));
163164
lnk->psn_initial = rndvec[0] + (rndvec[1] << 8) + (rndvec[2] << 16);
165+
rc = smc_wr_alloc_link_mem(lnk);
166+
if (rc)
167+
goto free_lgr;
168+
init_waitqueue_head(&lnk->wr_tx_wait);
164169

165170
smc->conn.lgr = lgr;
166171
rwlock_init(&lgr->conns_lock);
167172
spin_lock_bh(&smc_lgr_list.lock);
168173
list_add(&lgr->list, &smc_lgr_list.list);
169174
spin_unlock_bh(&smc_lgr_list.lock);
175+
return 0;
176+
177+
free_lgr:
178+
kfree(lgr);
170179
out:
171180
return rc;
172181
}
@@ -202,6 +211,8 @@ void smc_conn_free(struct smc_connection *conn)
202211
static void smc_link_clear(struct smc_link *lnk)
203212
{
204213
lnk->peer_qpn = 0;
214+
smc_wr_free_link(lnk);
215+
smc_wr_free_link_mem(lnk);
205216
}
206217

207218
static void smc_lgr_free_sndbufs(struct smc_link_group *lgr)

net/smc/smc_core.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#ifndef _SMC_CORE_H
1212
#define _SMC_CORE_H
1313

14+
#include <linux/atomic.h>
1415
#include <rdma/ib_verbs.h>
1516

1617
#include "smc.h"
@@ -30,11 +31,40 @@ enum smc_lgr_role { /* possible roles of a link group */
3031
SMC_SERV /* server */
3132
};
3233

34+
#define SMC_WR_BUF_SIZE 48 /* size of work request buffer */
35+
36+
struct smc_wr_buf {
37+
u8 raw[SMC_WR_BUF_SIZE];
38+
};
39+
3340
struct smc_link {
3441
struct smc_ib_device *smcibdev; /* ib-device */
3542
u8 ibport; /* port - values 1 | 2 */
43+
struct ib_pd *roce_pd; /* IB protection domain,
44+
* unique for every RoCE QP
45+
*/
3646
struct ib_qp *roce_qp; /* IB queue pair */
3747
struct ib_qp_attr qp_attr; /* IB queue pair attributes */
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+
3868
union ib_gid gid; /* gid matching used vlan id */
3969
u32 peer_qpn; /* QP number of peer */
4070
enum ib_mtu path_mtu; /* used mtu */

net/smc/smc_ib.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "smc_pnet.h"
1818
#include "smc_ib.h"
1919
#include "smc_core.h"
20+
#include "smc_wr.h"
2021
#include "smc.h"
2122

2223
struct smc_ib_devices smc_ib_devices = { /* smc-registered ib devices */
@@ -30,6 +31,78 @@ u8 local_systemid[SMC_SYSTEMID_LEN] = SMC_LOCAL_SYSTEMID_RESET; /* unique system
3031
* identifier
3132
*/
3233

34+
void smc_ib_dealloc_protection_domain(struct smc_link *lnk)
35+
{
36+
ib_dealloc_pd(lnk->roce_pd);
37+
lnk->roce_pd = NULL;
38+
}
39+
40+
int smc_ib_create_protection_domain(struct smc_link *lnk)
41+
{
42+
int rc;
43+
44+
lnk->roce_pd = ib_alloc_pd(lnk->smcibdev->ibdev, 0);
45+
rc = PTR_ERR_OR_ZERO(lnk->roce_pd);
46+
if (IS_ERR(lnk->roce_pd))
47+
lnk->roce_pd = NULL;
48+
return rc;
49+
}
50+
51+
static void smc_ib_qp_event_handler(struct ib_event *ibevent, void *priv)
52+
{
53+
switch (ibevent->event) {
54+
case IB_EVENT_DEVICE_FATAL:
55+
case IB_EVENT_GID_CHANGE:
56+
case IB_EVENT_PORT_ERR:
57+
case IB_EVENT_QP_ACCESS_ERR:
58+
/* tbd in follow-on patch:
59+
* abnormal close of corresponding connections
60+
*/
61+
break;
62+
default:
63+
break;
64+
}
65+
}
66+
67+
void smc_ib_destroy_queue_pair(struct smc_link *lnk)
68+
{
69+
ib_destroy_qp(lnk->roce_qp);
70+
lnk->roce_qp = NULL;
71+
}
72+
73+
/* create a queue pair within the protection domain for a link */
74+
int smc_ib_create_queue_pair(struct smc_link *lnk)
75+
{
76+
struct ib_qp_init_attr qp_attr = {
77+
.event_handler = smc_ib_qp_event_handler,
78+
.qp_context = lnk,
79+
.send_cq = lnk->smcibdev->roce_cq_send,
80+
.recv_cq = lnk->smcibdev->roce_cq_recv,
81+
.srq = NULL,
82+
.cap = {
83+
.max_send_wr = SMC_WR_BUF_CNT,
84+
/* include unsolicited rdma_writes as well,
85+
* there are max. 2 RDMA_WRITE per 1 WR_SEND
86+
*/
87+
.max_recv_wr = SMC_WR_BUF_CNT * 3,
88+
.max_send_sge = SMC_IB_MAX_SEND_SGE,
89+
.max_recv_sge = 1,
90+
.max_inline_data = SMC_WR_TX_SIZE,
91+
},
92+
.sq_sig_type = IB_SIGNAL_REQ_WR,
93+
.qp_type = IB_QPT_RC,
94+
};
95+
int rc;
96+
97+
lnk->roce_qp = ib_create_qp(lnk->roce_pd, &qp_attr);
98+
rc = PTR_ERR_OR_ZERO(lnk->roce_qp);
99+
if (IS_ERR(lnk->roce_qp))
100+
lnk->roce_qp = NULL;
101+
else
102+
smc_wr_remember_qp_attr(lnk);
103+
return rc;
104+
}
105+
33106
/* map a new TX or RX buffer to DMA */
34107
int smc_ib_buf_map(struct smc_ib_device *smcibdev, int buf_size,
35108
struct smc_buf_desc *buf_slot,

net/smc/smc_ib.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#define SMC_MAX_PORTS 2 /* Max # of ports */
1717
#define SMC_GID_SIZE sizeof(union ib_gid)
1818

19+
#define SMC_IB_MAX_SEND_SGE 2
20+
1921
struct smc_ib_devices { /* list of smc ib devices definition */
2022
struct list_head list;
2123
spinlock_t lock; /* protects list of smc ib devices */
@@ -27,12 +29,17 @@ struct smc_ib_device { /* ib-device infos for smc */
2729
struct list_head list;
2830
struct ib_device *ibdev;
2931
struct ib_port_attr pattr[SMC_MAX_PORTS]; /* ib dev. port attrs */
32+
struct ib_cq *roce_cq_send; /* send completion queue */
33+
struct ib_cq *roce_cq_recv; /* recv completion queue */
34+
struct tasklet_struct send_tasklet; /* called by send cq handler */
35+
struct tasklet_struct recv_tasklet; /* called by recv cq handler */
3036
char mac[SMC_MAX_PORTS][6]; /* mac address per port*/
3137
union ib_gid gid[SMC_MAX_PORTS]; /* gid per port */
3238
u8 initialized : 1; /* ib dev CQ, evthdl done */
3339
};
3440

3541
struct smc_buf_desc;
42+
struct smc_link;
3643

3744
int smc_ib_register_client(void) __init;
3845
void smc_ib_unregister_client(void);
@@ -41,5 +48,9 @@ int smc_ib_remember_port_attr(struct smc_ib_device *smcibdev, u8 ibport);
4148
int smc_ib_buf_map(struct smc_ib_device *smcibdev, int buf_size,
4249
struct smc_buf_desc *buf_slot,
4350
enum dma_data_direction data_direction);
51+
void smc_ib_dealloc_protection_domain(struct smc_link *lnk);
52+
int smc_ib_create_protection_domain(struct smc_link *lnk);
53+
void smc_ib_destroy_queue_pair(struct smc_link *lnk);
54+
int smc_ib_create_queue_pair(struct smc_link *lnk);
4455

4556
#endif

0 commit comments

Comments
 (0)