50 #include <linux/module.h>
52 #include <linux/slab.h>
58 # define RPCDBG_FACILITY RPCDBG_TRANS
73 static unsigned int xprt_rdma_inline_write_padding;
74 static unsigned int xprt_rdma_memreg_strategy =
RPCRDMA_FRMR;
81 static unsigned int zero;
82 static unsigned int max_padding =
PAGE_SIZE;
90 .
procname =
"rdma_slot_table_entries",
91 .data = &xprt_rdma_slot_table_entries,
92 .maxlen =
sizeof(
unsigned int),
95 .extra1 = &min_slot_table_size,
96 .extra2 = &max_slot_table_size
99 .procname =
"rdma_max_inline_read",
100 .data = &xprt_rdma_max_inline_read,
101 .maxlen =
sizeof(
unsigned int),
106 .procname =
"rdma_max_inline_write",
107 .data = &xprt_rdma_max_inline_write,
108 .maxlen =
sizeof(
unsigned int),
113 .procname =
"rdma_inline_write_padding",
114 .data = &xprt_rdma_inline_write_padding,
115 .maxlen =
sizeof(
unsigned int),
119 .extra2 = &max_padding,
122 .procname =
"rdma_memreg_strategy",
123 .data = &xprt_rdma_memreg_strategy,
124 .maxlen =
sizeof(
unsigned int),
127 .extra1 = &min_memreg,
128 .extra2 = &max_memreg,
131 .procname =
"rdma_pad_optimize",
133 .maxlen =
sizeof(
unsigned int),
144 .child = xr_tunables_table
151 static struct rpc_xprt_ops xprt_rdma_procs;
154 xprt_rdma_format_addresses(
struct rpc_xprt *xprt)
164 snprintf(buf,
sizeof(buf),
"%u", rpc_get_port(sap));
167 xprt->address_strings[RPC_DISPLAY_PROTO] =
"rdma";
172 snprintf(buf,
sizeof(buf),
"%4hx", rpc_get_port(sap));
176 xprt->address_strings[RPC_DISPLAY_NETID] =
"rdma";
180 xprt_rdma_free_addresses(
struct rpc_xprt *xprt)
184 for (i = 0; i < RPC_DISPLAY_MAX; i++)
186 case RPC_DISPLAY_PROTO:
187 case RPC_DISPLAY_NETID:
190 kfree(xprt->address_strings[i]);
199 struct rpc_xprt *xprt = &r_xprt->
xprt;
203 xprt_clear_connected(xprt);
205 dprintk(
"RPC: %s: %sconnect\n", __func__,
206 r_xprt->
rx_ep.rep_connected != 0 ?
"re" :
"");
211 dprintk(
"RPC: %s: exit\n", __func__);
212 xprt_clear_connecting(xprt);
228 xprt_rdma_destroy(
struct rpc_xprt *xprt)
233 dprintk(
"RPC: %s: called\n", __func__);
237 xprt_clear_connected(xprt);
242 dprintk(
"RPC: %s: rpcrdma_ep_destroy returned %i\n",
246 xprt_rdma_free_addresses(xprt);
250 dprintk(
"RPC: %s: returning\n", __func__);
255 static const struct rpc_timeout xprt_rdma_default_timeout = {
256 .to_initval = 60 *
HZ,
257 .to_maxval = 60 *
HZ,
265 static struct rpc_xprt *
266 xprt_setup_rdma(
struct xprt_create *
args)
269 struct rpc_xprt *xprt;
275 if (args->addrlen >
sizeof(xprt->addr)) {
276 dprintk(
"RPC: %s: address too large\n", __func__);
277 return ERR_PTR(-
EBADF);
281 xprt_rdma_slot_table_entries,
282 xprt_rdma_slot_table_entries);
284 dprintk(
"RPC: %s: couldn't allocate rpcrdma_xprt\n",
290 xprt->timeout = &xprt_rdma_default_timeout;
291 xprt->bind_timeout = (60
U *
HZ);
292 xprt->reestablish_timeout = (5
U *
HZ);
293 xprt->idle_timeout = (5
U * 60 *
HZ);
298 xprt->ops = &xprt_rdma_procs;
305 memcpy(&cdata.
addr, args->dstaddr, args->addrlen);
310 xprt->addrlen = args->addrlen;
311 memcpy(&xprt->addr, &cdata.
addr, xprt->addrlen);
315 xprt_set_bound(xprt);
335 cdata.
padding = xprt_rdma_inline_write_padding;
347 xprt_rdma_memreg_strategy);
355 new_ep = &new_xprt->
rx_ep;
382 xprt_rdma_format_addresses(xprt);
390 xprt_rdma_free_addresses(xprt);
405 xprt_rdma_close(
struct rpc_xprt *xprt)
409 dprintk(
"RPC: %s: closing\n", __func__);
410 if (r_xprt->
rx_ep.rep_connected > 0)
411 xprt->reestablish_timeout = 0;
417 xprt_rdma_set_port(
struct rpc_xprt *xprt,
u16 port)
425 dprintk(
"RPC: %s: %u\n", __func__, port);
431 struct rpc_xprt *xprt = (
struct rpc_xprt *)task->tk_xprt;
434 if (r_xprt->rx_ep.rep_connected != 0) {
437 xprt->reestablish_timeout);
438 xprt->reestablish_timeout <<= 1;
439 if (xprt->reestablish_timeout > (30 *
HZ))
440 xprt->reestablish_timeout = (30 *
HZ);
441 else if (xprt->reestablish_timeout < (5 *
HZ))
442 xprt->reestablish_timeout = (5 *
HZ);
451 xprt_rdma_reserve_xprt(
struct rpc_xprt *xprt,
struct rpc_task *task)
457 if (r_xprt->
rx_buf.rb_cwndscale == 0
UL) {
458 r_xprt->
rx_buf.rb_cwndscale = xprt->cwnd;
459 dprintk(
"RPC: %s: cwndscale %lu\n", __func__,
460 r_xprt->
rx_buf.rb_cwndscale);
463 xprt->cwnd = credits * r_xprt->
rx_buf.rb_cwndscale;
478 struct rpc_xprt *xprt = task->tk_xprt;
485 dprintk(
"RPC: %s: size %zd too large for buffer[%zd]: "
486 "prog %d vers %d proc %d\n",
489 task->
tk_msg.rpc_proc->p_proc);
509 dprintk(
"RPC: %s: too much data (%zd) for inline "
510 "(r/w max %d/%d)\n", __func__, size,
545 dprintk(
"RPC: %s: size %zd, request 0x%p\n", __func__, size, req);
560 xprt_rdma_free(
void *
buffer)
571 if (req->
rl_iov.length == 0) {
578 dprintk(
"RPC: %s: called on 0x%p%s\n",
579 __func__, rep, (rep && rep->
rr_func) ?
" (with waiter)" :
"");
601 if (req->
rl_iov.length == 0) {
627 xprt_rdma_send_request(
struct rpc_task *task)
629 struct rpc_rqst *rqst = task->
tk_rqstp;
630 struct rpc_xprt *xprt = task->tk_xprt;
636 r_xprt->
rx_stats.failed_marshal_count++;
637 dprintk(
"RPC: %s: rpcrdma_marshal_req failed\n",
653 goto drop_connection;
657 goto drop_connection;
659 rqst->rq_xmit_bytes_sent += rqst->rq_snd_buf.len;
660 rqst->rq_bytes_sent = 0;
668 static void xprt_rdma_print_stats(
struct rpc_xprt *xprt,
struct seq_file *
seq)
673 if (xprt_connected(xprt))
677 "\txprt:\trdma %u %lu %lu %lu %ld %lu %lu %lu %Lu %Lu "
678 "%lu %lu %lu %Lu %Lu %Lu %Lu %lu %lu %lu\n",
681 xprt->stat.bind_count,
682 xprt->stat.connect_count,
683 xprt->stat.connect_time,
694 r_xprt->
rx_stats.total_rdma_request,
698 r_xprt->
rx_stats.hardway_register_count,
699 r_xprt->
rx_stats.failed_marshal_count,
707 static struct rpc_xprt_ops xprt_rdma_procs = {
708 .reserve_xprt = xprt_rdma_reserve_xprt,
714 .set_port = xprt_rdma_set_port,
715 .connect = xprt_rdma_connect,
716 .buf_alloc = xprt_rdma_allocate,
717 .buf_free = xprt_rdma_free,
718 .send_request = xprt_rdma_send_request,
719 .close = xprt_rdma_close,
720 .destroy = xprt_rdma_destroy,
721 .print_stats = xprt_rdma_print_stats
724 static struct xprt_class xprt_rdma = {
728 .ident = XPRT_TRANSPORT_RDMA,
729 .setup = xprt_setup_rdma,
732 static void __exit xprt_rdma_cleanup(
void)
736 dprintk(
KERN_INFO "RPCRDMA Module Removed, deregister RPC RDMA transport\n");
738 if (sunrpc_table_header) {
740 sunrpc_table_header =
NULL;
745 dprintk(
"RPC: %s: xprt_unregister returned %i\n",
749 static int __init xprt_rdma_init(
void)
762 "\tMaxInlineRead %d\n\tMaxInlineWrite %d\n",
763 xprt_rdma_slot_table_entries,
764 xprt_rdma_max_inline_read, xprt_rdma_max_inline_write);
766 xprt_rdma_inline_write_padding, xprt_rdma_memreg_strategy);
769 if (!sunrpc_table_header)