10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57387SRobert.Gordon@Sun.COM * Common Development and Distribution License (the "License"). 67387SRobert.Gordon@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 228695SRajkumar.Sivaprakasam@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 260Sstevel@tonic-gate /* All Rights Reserved */ 270Sstevel@tonic-gate /* 280Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 290Sstevel@tonic-gate * 4.3 BSD under license from the Regents of the University of 300Sstevel@tonic-gate * California. 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate /* 340Sstevel@tonic-gate * Server side of RPC over RDMA in the kernel. 350Sstevel@tonic-gate */ 360Sstevel@tonic-gate 370Sstevel@tonic-gate #include <sys/param.h> 380Sstevel@tonic-gate #include <sys/types.h> 390Sstevel@tonic-gate #include <sys/user.h> 400Sstevel@tonic-gate #include <sys/sysmacros.h> 410Sstevel@tonic-gate #include <sys/proc.h> 420Sstevel@tonic-gate #include <sys/file.h> 430Sstevel@tonic-gate #include <sys/errno.h> 440Sstevel@tonic-gate #include <sys/kmem.h> 450Sstevel@tonic-gate #include <sys/debug.h> 460Sstevel@tonic-gate #include <sys/systm.h> 470Sstevel@tonic-gate #include <sys/cmn_err.h> 480Sstevel@tonic-gate #include <sys/kstat.h> 490Sstevel@tonic-gate #include <sys/vtrace.h> 500Sstevel@tonic-gate #include <sys/debug.h> 510Sstevel@tonic-gate 520Sstevel@tonic-gate #include <rpc/types.h> 530Sstevel@tonic-gate #include <rpc/xdr.h> 540Sstevel@tonic-gate #include <rpc/auth.h> 550Sstevel@tonic-gate #include <rpc/clnt.h> 560Sstevel@tonic-gate #include <rpc/rpc_msg.h> 570Sstevel@tonic-gate #include <rpc/svc.h> 580Sstevel@tonic-gate #include <rpc/rpc_rdma.h> 590Sstevel@tonic-gate #include <sys/ddi.h> 600Sstevel@tonic-gate #include <sys/sunddi.h> 610Sstevel@tonic-gate 620Sstevel@tonic-gate #include <inet/common.h> 630Sstevel@tonic-gate #include <inet/ip.h> 640Sstevel@tonic-gate #include <inet/ip6.h> 650Sstevel@tonic-gate 667387SRobert.Gordon@Sun.COM #include <nfs/nfs.h> 677387SRobert.Gordon@Sun.COM #include <sys/sdt.h> 687387SRobert.Gordon@Sun.COM 697387SRobert.Gordon@Sun.COM #define SVC_RDMA_SUCCESS 0 707387SRobert.Gordon@Sun.COM #define SVC_RDMA_FAIL -1 717387SRobert.Gordon@Sun.COM 727387SRobert.Gordon@Sun.COM #define SVC_CREDIT_FACTOR (0.5) 737387SRobert.Gordon@Sun.COM 747387SRobert.Gordon@Sun.COM #define MSG_IS_RPCSEC_GSS(msg) \ 757387SRobert.Gordon@Sun.COM ((msg)->rm_reply.rp_acpt.ar_verf.oa_flavor == RPCSEC_GSS) 767387SRobert.Gordon@Sun.COM 777387SRobert.Gordon@Sun.COM 787387SRobert.Gordon@Sun.COM uint32_t rdma_bufs_granted = RDMA_BUFS_GRANT; 797387SRobert.Gordon@Sun.COM 800Sstevel@tonic-gate /* 810Sstevel@tonic-gate * RDMA transport specific data associated with SVCMASTERXPRT 820Sstevel@tonic-gate */ 830Sstevel@tonic-gate struct rdma_data { 840Sstevel@tonic-gate SVCMASTERXPRT *rd_xprt; /* back ptr to SVCMASTERXPRT */ 850Sstevel@tonic-gate struct rdma_svc_data rd_data; /* rdma data */ 860Sstevel@tonic-gate rdma_mod_t *r_mod; /* RDMA module containing ops ptr */ 870Sstevel@tonic-gate }; 880Sstevel@tonic-gate 890Sstevel@tonic-gate /* 900Sstevel@tonic-gate * Plugin connection specific data stashed away in clone SVCXPRT 910Sstevel@tonic-gate */ 920Sstevel@tonic-gate struct clone_rdma_data { 930Sstevel@tonic-gate CONN *conn; /* RDMA connection */ 940Sstevel@tonic-gate rdma_buf_t rpcbuf; /* RPC req/resp buffer */ 957387SRobert.Gordon@Sun.COM struct clist *cl_reply; /* reply chunk buffer info */ 967387SRobert.Gordon@Sun.COM struct clist *cl_wlist; /* write list clist */ 970Sstevel@tonic-gate }; 980Sstevel@tonic-gate 990Sstevel@tonic-gate #define MAXADDRLEN 128 /* max length for address mask */ 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate /* 1020Sstevel@tonic-gate * Routines exported through ops vector. 1030Sstevel@tonic-gate */ 1040Sstevel@tonic-gate static bool_t svc_rdma_krecv(SVCXPRT *, mblk_t *, struct rpc_msg *); 1050Sstevel@tonic-gate static bool_t svc_rdma_ksend(SVCXPRT *, struct rpc_msg *); 1060Sstevel@tonic-gate static bool_t svc_rdma_kgetargs(SVCXPRT *, xdrproc_t, caddr_t); 1070Sstevel@tonic-gate static bool_t svc_rdma_kfreeargs(SVCXPRT *, xdrproc_t, caddr_t); 1080Sstevel@tonic-gate void svc_rdma_kdestroy(SVCMASTERXPRT *); 1090Sstevel@tonic-gate static int svc_rdma_kdup(struct svc_req *, caddr_t, int, 1100Sstevel@tonic-gate struct dupreq **, bool_t *); 1110Sstevel@tonic-gate static void svc_rdma_kdupdone(struct dupreq *, caddr_t, 1120Sstevel@tonic-gate void (*)(), int, int); 1130Sstevel@tonic-gate static int32_t *svc_rdma_kgetres(SVCXPRT *, int); 1140Sstevel@tonic-gate static void svc_rdma_kfreeres(SVCXPRT *); 1150Sstevel@tonic-gate static void svc_rdma_kclone_destroy(SVCXPRT *); 1160Sstevel@tonic-gate static void svc_rdma_kstart(SVCMASTERXPRT *); 1170Sstevel@tonic-gate void svc_rdma_kstop(SVCMASTERXPRT *); 1180Sstevel@tonic-gate 1197387SRobert.Gordon@Sun.COM static int svc_process_long_reply(SVCXPRT *, xdrproc_t, 1207387SRobert.Gordon@Sun.COM caddr_t, struct rpc_msg *, bool_t, int *, 1217387SRobert.Gordon@Sun.COM int *, int *, unsigned int *); 1227387SRobert.Gordon@Sun.COM 1237387SRobert.Gordon@Sun.COM static int svc_compose_rpcmsg(SVCXPRT *, CONN *, xdrproc_t, 1247387SRobert.Gordon@Sun.COM caddr_t, rdma_buf_t *, XDR **, struct rpc_msg *, 1257387SRobert.Gordon@Sun.COM bool_t, uint_t *); 1267387SRobert.Gordon@Sun.COM static bool_t rpcmsg_length(xdrproc_t, 1277387SRobert.Gordon@Sun.COM caddr_t, 1287387SRobert.Gordon@Sun.COM struct rpc_msg *, bool_t, int); 1297387SRobert.Gordon@Sun.COM 1300Sstevel@tonic-gate /* 1310Sstevel@tonic-gate * Server transport operations vector. 1320Sstevel@tonic-gate */ 1330Sstevel@tonic-gate struct svc_ops rdma_svc_ops = { 1340Sstevel@tonic-gate svc_rdma_krecv, /* Get requests */ 1350Sstevel@tonic-gate svc_rdma_kgetargs, /* Deserialize arguments */ 1360Sstevel@tonic-gate svc_rdma_ksend, /* Send reply */ 1370Sstevel@tonic-gate svc_rdma_kfreeargs, /* Free argument data space */ 1380Sstevel@tonic-gate svc_rdma_kdestroy, /* Destroy transport handle */ 1390Sstevel@tonic-gate svc_rdma_kdup, /* Check entry in dup req cache */ 1400Sstevel@tonic-gate svc_rdma_kdupdone, /* Mark entry in dup req cache as done */ 1410Sstevel@tonic-gate svc_rdma_kgetres, /* Get pointer to response buffer */ 1420Sstevel@tonic-gate svc_rdma_kfreeres, /* Destroy pre-serialized response header */ 1430Sstevel@tonic-gate svc_rdma_kclone_destroy, /* Destroy a clone xprt */ 1440Sstevel@tonic-gate svc_rdma_kstart /* Tell `ready-to-receive' to rpcmod */ 1450Sstevel@tonic-gate }; 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1480Sstevel@tonic-gate * Server statistics 1490Sstevel@tonic-gate * NOTE: This structure type is duplicated in the NFS fast path. 1500Sstevel@tonic-gate */ 1510Sstevel@tonic-gate struct { 1520Sstevel@tonic-gate kstat_named_t rscalls; 1530Sstevel@tonic-gate kstat_named_t rsbadcalls; 1540Sstevel@tonic-gate kstat_named_t rsnullrecv; 1550Sstevel@tonic-gate kstat_named_t rsbadlen; 1560Sstevel@tonic-gate kstat_named_t rsxdrcall; 1570Sstevel@tonic-gate kstat_named_t rsdupchecks; 1580Sstevel@tonic-gate kstat_named_t rsdupreqs; 1590Sstevel@tonic-gate kstat_named_t rslongrpcs; 1607387SRobert.Gordon@Sun.COM kstat_named_t rstotalreplies; 1617387SRobert.Gordon@Sun.COM kstat_named_t rstotallongreplies; 1627387SRobert.Gordon@Sun.COM kstat_named_t rstotalinlinereplies; 1630Sstevel@tonic-gate } rdmarsstat = { 1640Sstevel@tonic-gate { "calls", KSTAT_DATA_UINT64 }, 1650Sstevel@tonic-gate { "badcalls", KSTAT_DATA_UINT64 }, 1660Sstevel@tonic-gate { "nullrecv", KSTAT_DATA_UINT64 }, 1670Sstevel@tonic-gate { "badlen", KSTAT_DATA_UINT64 }, 1680Sstevel@tonic-gate { "xdrcall", KSTAT_DATA_UINT64 }, 1690Sstevel@tonic-gate { "dupchecks", KSTAT_DATA_UINT64 }, 1700Sstevel@tonic-gate { "dupreqs", KSTAT_DATA_UINT64 }, 1717387SRobert.Gordon@Sun.COM { "longrpcs", KSTAT_DATA_UINT64 }, 1727387SRobert.Gordon@Sun.COM { "totalreplies", KSTAT_DATA_UINT64 }, 1737387SRobert.Gordon@Sun.COM { "totallongreplies", KSTAT_DATA_UINT64 }, 1747387SRobert.Gordon@Sun.COM { "totalinlinereplies", KSTAT_DATA_UINT64 }, 1750Sstevel@tonic-gate }; 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate kstat_named_t *rdmarsstat_ptr = (kstat_named_t *)&rdmarsstat; 1780Sstevel@tonic-gate uint_t rdmarsstat_ndata = sizeof (rdmarsstat) / sizeof (kstat_named_t); 1790Sstevel@tonic-gate 1807387SRobert.Gordon@Sun.COM #define RSSTAT_INCR(x) atomic_add_64(&rdmarsstat.x.value.ui64, 1) 1810Sstevel@tonic-gate /* 1820Sstevel@tonic-gate * Create a transport record. 1830Sstevel@tonic-gate * The transport record, output buffer, and private data structure 1840Sstevel@tonic-gate * are allocated. The output buffer is serialized into using xdrmem. 1850Sstevel@tonic-gate * There is one transport record per user process which implements a 1860Sstevel@tonic-gate * set of services. 1870Sstevel@tonic-gate */ 1880Sstevel@tonic-gate /* ARGSUSED */ 1890Sstevel@tonic-gate int 1900Sstevel@tonic-gate svc_rdma_kcreate(char *netid, SVC_CALLOUT_TABLE *sct, int id, 1917387SRobert.Gordon@Sun.COM rdma_xprt_group_t *started_xprts) 1920Sstevel@tonic-gate { 1930Sstevel@tonic-gate int error; 1940Sstevel@tonic-gate SVCMASTERXPRT *xprt; 1950Sstevel@tonic-gate struct rdma_data *rd; 1960Sstevel@tonic-gate rdma_registry_t *rmod; 1970Sstevel@tonic-gate rdma_xprt_record_t *xprt_rec; 1980Sstevel@tonic-gate queue_t *q; 1990Sstevel@tonic-gate /* 2000Sstevel@tonic-gate * modload the RDMA plugins is not already done. 2010Sstevel@tonic-gate */ 2020Sstevel@tonic-gate if (!rdma_modloaded) { 2037387SRobert.Gordon@Sun.COM /*CONSTANTCONDITION*/ 2047387SRobert.Gordon@Sun.COM ASSERT(sizeof (struct clone_rdma_data) <= SVC_P2LEN); 2057387SRobert.Gordon@Sun.COM 2060Sstevel@tonic-gate mutex_enter(&rdma_modload_lock); 2070Sstevel@tonic-gate if (!rdma_modloaded) { 2080Sstevel@tonic-gate error = rdma_modload(); 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate mutex_exit(&rdma_modload_lock); 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate if (error) 2130Sstevel@tonic-gate return (error); 2140Sstevel@tonic-gate } 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate /* 2170Sstevel@tonic-gate * master_xprt_count is the count of master transport handles 2180Sstevel@tonic-gate * that were successfully created and are ready to recieve for 2190Sstevel@tonic-gate * RDMA based access. 2200Sstevel@tonic-gate */ 2210Sstevel@tonic-gate error = 0; 2220Sstevel@tonic-gate xprt_rec = NULL; 2230Sstevel@tonic-gate rw_enter(&rdma_lock, RW_READER); 2240Sstevel@tonic-gate if (rdma_mod_head == NULL) { 2250Sstevel@tonic-gate started_xprts->rtg_count = 0; 2260Sstevel@tonic-gate rw_exit(&rdma_lock); 2270Sstevel@tonic-gate if (rdma_dev_available) 2280Sstevel@tonic-gate return (EPROTONOSUPPORT); 2290Sstevel@tonic-gate else 2300Sstevel@tonic-gate return (ENODEV); 2310Sstevel@tonic-gate } 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate /* 2340Sstevel@tonic-gate * If we have reached here, then atleast one RDMA plugin has loaded. 2350Sstevel@tonic-gate * Create a master_xprt, make it start listenining on the device, 2360Sstevel@tonic-gate * if an error is generated, record it, we might need to shut 2370Sstevel@tonic-gate * the master_xprt. 2380Sstevel@tonic-gate * SVC_START() calls svc_rdma_kstart which calls plugin binding 2390Sstevel@tonic-gate * routines. 2400Sstevel@tonic-gate */ 2410Sstevel@tonic-gate for (rmod = rdma_mod_head; rmod != NULL; rmod = rmod->r_next) { 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate /* 2440Sstevel@tonic-gate * One SVCMASTERXPRT per RDMA plugin. 2450Sstevel@tonic-gate */ 2460Sstevel@tonic-gate xprt = kmem_zalloc(sizeof (*xprt), KM_SLEEP); 2470Sstevel@tonic-gate xprt->xp_ops = &rdma_svc_ops; 2480Sstevel@tonic-gate xprt->xp_sct = sct; 2490Sstevel@tonic-gate xprt->xp_type = T_RDMA; 2500Sstevel@tonic-gate mutex_init(&xprt->xp_req_lock, NULL, MUTEX_DEFAULT, NULL); 2510Sstevel@tonic-gate mutex_init(&xprt->xp_thread_lock, NULL, MUTEX_DEFAULT, NULL); 2520Sstevel@tonic-gate xprt->xp_req_head = (mblk_t *)0; 2530Sstevel@tonic-gate xprt->xp_req_tail = (mblk_t *)0; 2540Sstevel@tonic-gate xprt->xp_threads = 0; 2550Sstevel@tonic-gate xprt->xp_detached_threads = 0; 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate rd = kmem_zalloc(sizeof (*rd), KM_SLEEP); 2580Sstevel@tonic-gate xprt->xp_p2 = (caddr_t)rd; 2590Sstevel@tonic-gate rd->rd_xprt = xprt; 2600Sstevel@tonic-gate rd->r_mod = rmod->r_mod; 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate q = &rd->rd_data.q; 2630Sstevel@tonic-gate xprt->xp_wq = q; 2640Sstevel@tonic-gate q->q_ptr = &rd->rd_xprt; 2650Sstevel@tonic-gate xprt->xp_netid = NULL; 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate xprt->xp_addrmask.maxlen = 2680Sstevel@tonic-gate xprt->xp_addrmask.len = sizeof (struct sockaddr_in); 2690Sstevel@tonic-gate xprt->xp_addrmask.buf = 2700Sstevel@tonic-gate kmem_zalloc(xprt->xp_addrmask.len, KM_SLEEP); 2710Sstevel@tonic-gate ((struct sockaddr_in *)xprt->xp_addrmask.buf)->sin_addr.s_addr = 2720Sstevel@tonic-gate (uint32_t)~0; 2730Sstevel@tonic-gate ((struct sockaddr_in *)xprt->xp_addrmask.buf)->sin_family = 2740Sstevel@tonic-gate (ushort_t)~0; 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate /* 2770Sstevel@tonic-gate * Each of the plugins will have their own Service ID 2780Sstevel@tonic-gate * to listener specific mapping, like port number for VI 2790Sstevel@tonic-gate * and service name for IB. 2800Sstevel@tonic-gate */ 2810Sstevel@tonic-gate rd->rd_data.svcid = id; 2820Sstevel@tonic-gate error = svc_xprt_register(xprt, id); 2830Sstevel@tonic-gate if (error) { 2847387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__xprt__reg); 2850Sstevel@tonic-gate goto cleanup; 2860Sstevel@tonic-gate } 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate SVC_START(xprt); 2890Sstevel@tonic-gate if (!rd->rd_data.active) { 2900Sstevel@tonic-gate svc_xprt_unregister(xprt); 2910Sstevel@tonic-gate error = rd->rd_data.err_code; 2920Sstevel@tonic-gate goto cleanup; 2930Sstevel@tonic-gate } 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate /* 2960Sstevel@tonic-gate * This is set only when there is atleast one or more 2970Sstevel@tonic-gate * transports successfully created. We insert the pointer 2980Sstevel@tonic-gate * to the created RDMA master xprt into a separately maintained 2990Sstevel@tonic-gate * list. This way we can easily reference it later to cleanup, 3000Sstevel@tonic-gate * when NFS kRPC service pool is going away/unregistered. 3010Sstevel@tonic-gate */ 3020Sstevel@tonic-gate started_xprts->rtg_count ++; 3030Sstevel@tonic-gate xprt_rec = kmem_alloc(sizeof (*xprt_rec), KM_SLEEP); 3040Sstevel@tonic-gate xprt_rec->rtr_xprt_ptr = xprt; 3050Sstevel@tonic-gate xprt_rec->rtr_next = started_xprts->rtg_listhead; 3060Sstevel@tonic-gate started_xprts->rtg_listhead = xprt_rec; 3070Sstevel@tonic-gate continue; 3080Sstevel@tonic-gate cleanup: 3090Sstevel@tonic-gate SVC_DESTROY(xprt); 3100Sstevel@tonic-gate if (error == RDMA_FAILED) 3110Sstevel@tonic-gate error = EPROTONOSUPPORT; 3120Sstevel@tonic-gate } 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate rw_exit(&rdma_lock); 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate /* 3170Sstevel@tonic-gate * Don't return any error even if a single plugin was started 3180Sstevel@tonic-gate * successfully. 3190Sstevel@tonic-gate */ 3200Sstevel@tonic-gate if (started_xprts->rtg_count == 0) 3210Sstevel@tonic-gate return (error); 3220Sstevel@tonic-gate return (0); 3230Sstevel@tonic-gate } 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate /* 3260Sstevel@tonic-gate * Cleanup routine for freeing up memory allocated by 3270Sstevel@tonic-gate * svc_rdma_kcreate() 3280Sstevel@tonic-gate */ 3290Sstevel@tonic-gate void 3300Sstevel@tonic-gate svc_rdma_kdestroy(SVCMASTERXPRT *xprt) 3310Sstevel@tonic-gate { 3320Sstevel@tonic-gate struct rdma_data *rd = (struct rdma_data *)xprt->xp_p2; 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate mutex_destroy(&xprt->xp_req_lock); 3360Sstevel@tonic-gate mutex_destroy(&xprt->xp_thread_lock); 3370Sstevel@tonic-gate kmem_free(rd, sizeof (*rd)); 3380Sstevel@tonic-gate kmem_free(xprt->xp_addrmask.buf, xprt->xp_addrmask.maxlen); 3390Sstevel@tonic-gate kmem_free(xprt, sizeof (*xprt)); 3400Sstevel@tonic-gate } 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate static void 3440Sstevel@tonic-gate svc_rdma_kstart(SVCMASTERXPRT *xprt) 3450Sstevel@tonic-gate { 3460Sstevel@tonic-gate struct rdma_svc_data *svcdata; 3470Sstevel@tonic-gate rdma_mod_t *rmod; 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate svcdata = &((struct rdma_data *)xprt->xp_p2)->rd_data; 3500Sstevel@tonic-gate rmod = ((struct rdma_data *)xprt->xp_p2)->r_mod; 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate /* 3530Sstevel@tonic-gate * Create a listener for module at this port 3540Sstevel@tonic-gate */ 3550Sstevel@tonic-gate 3568695SRajkumar.Sivaprakasam@Sun.COM if (rmod->rdma_count != 0) 3578695SRajkumar.Sivaprakasam@Sun.COM (*rmod->rdma_ops->rdma_svc_listen)(svcdata); 3588695SRajkumar.Sivaprakasam@Sun.COM else 3598695SRajkumar.Sivaprakasam@Sun.COM svcdata->err_code = RDMA_FAILED; 3600Sstevel@tonic-gate } 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate void 3630Sstevel@tonic-gate svc_rdma_kstop(SVCMASTERXPRT *xprt) 3640Sstevel@tonic-gate { 3650Sstevel@tonic-gate struct rdma_svc_data *svcdata; 3660Sstevel@tonic-gate rdma_mod_t *rmod; 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate svcdata = &((struct rdma_data *)xprt->xp_p2)->rd_data; 3690Sstevel@tonic-gate rmod = ((struct rdma_data *)xprt->xp_p2)->r_mod; 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate /* 3728695SRajkumar.Sivaprakasam@Sun.COM * Call the stop listener routine for each plugin. If rdma_count is 3738695SRajkumar.Sivaprakasam@Sun.COM * already zero set active to zero. 3740Sstevel@tonic-gate */ 3758695SRajkumar.Sivaprakasam@Sun.COM if (rmod->rdma_count != 0) 3768695SRajkumar.Sivaprakasam@Sun.COM (*rmod->rdma_ops->rdma_svc_stop)(svcdata); 3778695SRajkumar.Sivaprakasam@Sun.COM else 3788695SRajkumar.Sivaprakasam@Sun.COM svcdata->active = 0; 3790Sstevel@tonic-gate if (svcdata->active) 3807387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__kstop); 3810Sstevel@tonic-gate } 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate /* ARGSUSED */ 3840Sstevel@tonic-gate static void 3850Sstevel@tonic-gate svc_rdma_kclone_destroy(SVCXPRT *clone_xprt) 3860Sstevel@tonic-gate { 3870Sstevel@tonic-gate } 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate static bool_t 3900Sstevel@tonic-gate svc_rdma_krecv(SVCXPRT *clone_xprt, mblk_t *mp, struct rpc_msg *msg) 3910Sstevel@tonic-gate { 3927387SRobert.Gordon@Sun.COM XDR *xdrs; 3937387SRobert.Gordon@Sun.COM CONN *conn; 3947387SRobert.Gordon@Sun.COM rdma_recv_data_t *rdp = (rdma_recv_data_t *)mp->b_rptr; 3957387SRobert.Gordon@Sun.COM struct clone_rdma_data *crdp; 3967387SRobert.Gordon@Sun.COM struct clist *cl = NULL; 3977387SRobert.Gordon@Sun.COM struct clist *wcl = NULL; 3987387SRobert.Gordon@Sun.COM struct clist *cllong = NULL; 3997387SRobert.Gordon@Sun.COM 4007387SRobert.Gordon@Sun.COM rdma_stat status; 4017387SRobert.Gordon@Sun.COM uint32_t vers, op, pos, xid; 4027387SRobert.Gordon@Sun.COM uint32_t rdma_credit; 4037387SRobert.Gordon@Sun.COM uint32_t wcl_total_length = 0; 4047387SRobert.Gordon@Sun.COM bool_t wwl = FALSE; 4057387SRobert.Gordon@Sun.COM 4067387SRobert.Gordon@Sun.COM crdp = (struct clone_rdma_data *)clone_xprt->xp_p2buf; 4070Sstevel@tonic-gate RSSTAT_INCR(rscalls); 4080Sstevel@tonic-gate conn = rdp->conn; 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate status = rdma_svc_postrecv(conn); 4110Sstevel@tonic-gate if (status != RDMA_SUCCESS) { 4127387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__krecv__postrecv); 4137387SRobert.Gordon@Sun.COM goto badrpc_call; 4140Sstevel@tonic-gate } 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate xdrs = &clone_xprt->xp_xdrin; 4170Sstevel@tonic-gate xdrmem_create(xdrs, rdp->rpcmsg.addr, rdp->rpcmsg.len, XDR_DECODE); 4187387SRobert.Gordon@Sun.COM xid = *(uint32_t *)rdp->rpcmsg.addr; 4197387SRobert.Gordon@Sun.COM XDR_SETPOS(xdrs, sizeof (uint32_t)); 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate if (! xdr_u_int(xdrs, &vers) || 4227387SRobert.Gordon@Sun.COM ! xdr_u_int(xdrs, &rdma_credit) || 4230Sstevel@tonic-gate ! xdr_u_int(xdrs, &op)) { 4247387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__krecv__uint); 4257387SRobert.Gordon@Sun.COM goto xdr_err; 4260Sstevel@tonic-gate } 4270Sstevel@tonic-gate 4287387SRobert.Gordon@Sun.COM /* Checking if the status of the recv operation was normal */ 4297387SRobert.Gordon@Sun.COM if (rdp->status != 0) { 4307387SRobert.Gordon@Sun.COM DTRACE_PROBE1(krpc__e__svcrdma__krecv__invalid__status, 4317387SRobert.Gordon@Sun.COM int, rdp->status); 4327387SRobert.Gordon@Sun.COM goto badrpc_call; 4337387SRobert.Gordon@Sun.COM } 4347387SRobert.Gordon@Sun.COM 4350Sstevel@tonic-gate if (! xdr_do_clist(xdrs, &cl)) { 4367387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__krecv__do__clist); 4377387SRobert.Gordon@Sun.COM goto xdr_err; 4380Sstevel@tonic-gate } 4390Sstevel@tonic-gate 4407387SRobert.Gordon@Sun.COM if (!xdr_decode_wlist_svc(xdrs, &wcl, &wwl, &wcl_total_length, conn)) { 4417387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__krecv__decode__wlist); 4427387SRobert.Gordon@Sun.COM if (cl) 4437387SRobert.Gordon@Sun.COM clist_free(cl); 4447387SRobert.Gordon@Sun.COM goto xdr_err; 4457387SRobert.Gordon@Sun.COM } 4467387SRobert.Gordon@Sun.COM crdp->cl_wlist = wcl; 4477387SRobert.Gordon@Sun.COM 4487387SRobert.Gordon@Sun.COM crdp->cl_reply = NULL; 4497387SRobert.Gordon@Sun.COM (void) xdr_decode_reply_wchunk(xdrs, &crdp->cl_reply); 4507387SRobert.Gordon@Sun.COM 4510Sstevel@tonic-gate /* 4520Sstevel@tonic-gate * A chunk at 0 offset indicates that the RPC call message 4530Sstevel@tonic-gate * is in a chunk. Get the RPC call message chunk. 4540Sstevel@tonic-gate */ 4550Sstevel@tonic-gate if (cl != NULL && op == RDMA_NOMSG) { 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate /* Remove RPC call message chunk from chunklist */ 4580Sstevel@tonic-gate cllong = cl; 4590Sstevel@tonic-gate cl = cl->c_next; 4600Sstevel@tonic-gate cllong->c_next = NULL; 4610Sstevel@tonic-gate 4627387SRobert.Gordon@Sun.COM 4630Sstevel@tonic-gate /* Allocate and register memory for the RPC call msg chunk */ 4647387SRobert.Gordon@Sun.COM cllong->rb_longbuf.type = RDMA_LONG_BUFFER; 4657387SRobert.Gordon@Sun.COM cllong->rb_longbuf.len = cllong->c_len > LONG_REPLY_LEN ? 4667387SRobert.Gordon@Sun.COM cllong->c_len : LONG_REPLY_LEN; 4677387SRobert.Gordon@Sun.COM 4687387SRobert.Gordon@Sun.COM if (rdma_buf_alloc(conn, &cllong->rb_longbuf)) { 4690Sstevel@tonic-gate clist_free(cllong); 4707387SRobert.Gordon@Sun.COM goto cll_malloc_err; 4710Sstevel@tonic-gate } 4727387SRobert.Gordon@Sun.COM 4737387SRobert.Gordon@Sun.COM cllong->u.c_daddr3 = cllong->rb_longbuf.addr; 4747387SRobert.Gordon@Sun.COM 4757387SRobert.Gordon@Sun.COM if (cllong->u.c_daddr == NULL) { 4767387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__krecv__nomem); 4777387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &cllong->rb_longbuf); 4787387SRobert.Gordon@Sun.COM clist_free(cllong); 4797387SRobert.Gordon@Sun.COM goto cll_malloc_err; 4807387SRobert.Gordon@Sun.COM } 4817387SRobert.Gordon@Sun.COM 4827387SRobert.Gordon@Sun.COM status = clist_register(conn, cllong, CLIST_REG_DST); 4830Sstevel@tonic-gate if (status) { 4847387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__krecv__clist__reg); 4857387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &cllong->rb_longbuf); 4860Sstevel@tonic-gate clist_free(cllong); 4877387SRobert.Gordon@Sun.COM goto cll_malloc_err; 4880Sstevel@tonic-gate } 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate /* 4910Sstevel@tonic-gate * Now read the RPC call message in 4920Sstevel@tonic-gate */ 4930Sstevel@tonic-gate status = RDMA_READ(conn, cllong, WAIT); 4940Sstevel@tonic-gate if (status) { 4957387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__krecv__read); 4969348SSiddheshwar.Mahesh@Sun.COM (void) clist_deregister(conn, cllong); 4977387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &cllong->rb_longbuf); 4980Sstevel@tonic-gate clist_free(cllong); 4997387SRobert.Gordon@Sun.COM goto cll_malloc_err; 5000Sstevel@tonic-gate } 5010Sstevel@tonic-gate 5027387SRobert.Gordon@Sun.COM status = clist_syncmem(conn, cllong, CLIST_REG_DST); 5039348SSiddheshwar.Mahesh@Sun.COM (void) clist_deregister(conn, cllong); 5040Sstevel@tonic-gate 5057387SRobert.Gordon@Sun.COM xdrrdma_create(xdrs, (caddr_t)(uintptr_t)cllong->u.c_daddr3, 5060Sstevel@tonic-gate cllong->c_len, 0, cl, XDR_DECODE, conn); 5070Sstevel@tonic-gate 5087387SRobert.Gordon@Sun.COM crdp->rpcbuf = cllong->rb_longbuf; 5097387SRobert.Gordon@Sun.COM crdp->rpcbuf.len = cllong->c_len; 5100Sstevel@tonic-gate clist_free(cllong); 5110Sstevel@tonic-gate RDMA_BUF_FREE(conn, &rdp->rpcmsg); 5120Sstevel@tonic-gate } else { 5130Sstevel@tonic-gate pos = XDR_GETPOS(xdrs); 5147387SRobert.Gordon@Sun.COM xdrrdma_create(xdrs, rdp->rpcmsg.addr + pos, 5157387SRobert.Gordon@Sun.COM rdp->rpcmsg.len - pos, 0, cl, XDR_DECODE, conn); 5167387SRobert.Gordon@Sun.COM crdp->rpcbuf = rdp->rpcmsg; 5170Sstevel@tonic-gate 5187387SRobert.Gordon@Sun.COM /* Use xdrrdmablk_ops to indicate there is a read chunk list */ 5197387SRobert.Gordon@Sun.COM if (cl != NULL) { 5207387SRobert.Gordon@Sun.COM int32_t flg = XDR_RDMA_RLIST_REG; 5217387SRobert.Gordon@Sun.COM 5227387SRobert.Gordon@Sun.COM XDR_CONTROL(xdrs, XDR_RDMA_SET_FLAGS, &flg); 5237387SRobert.Gordon@Sun.COM xdrs->x_ops = &xdrrdmablk_ops; 5247387SRobert.Gordon@Sun.COM } 5250Sstevel@tonic-gate } 5267387SRobert.Gordon@Sun.COM 5277387SRobert.Gordon@Sun.COM if (crdp->cl_wlist) { 5287387SRobert.Gordon@Sun.COM int32_t flg = XDR_RDMA_WLIST_REG; 5297387SRobert.Gordon@Sun.COM 5307387SRobert.Gordon@Sun.COM XDR_CONTROL(xdrs, XDR_RDMA_SET_WLIST, crdp->cl_wlist); 5317387SRobert.Gordon@Sun.COM XDR_CONTROL(xdrs, XDR_RDMA_SET_FLAGS, &flg); 5327387SRobert.Gordon@Sun.COM } 5337387SRobert.Gordon@Sun.COM 5340Sstevel@tonic-gate if (! xdr_callmsg(xdrs, msg)) { 5357387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__krecv__callmsg); 5360Sstevel@tonic-gate RSSTAT_INCR(rsxdrcall); 5377387SRobert.Gordon@Sun.COM goto callmsg_err; 5380Sstevel@tonic-gate } 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate /* 5410Sstevel@tonic-gate * Point the remote transport address in the service_transport 5420Sstevel@tonic-gate * handle at the address in the request. 5430Sstevel@tonic-gate */ 5440Sstevel@tonic-gate clone_xprt->xp_rtaddr.buf = conn->c_raddr.buf; 5450Sstevel@tonic-gate clone_xprt->xp_rtaddr.len = conn->c_raddr.len; 5460Sstevel@tonic-gate clone_xprt->xp_rtaddr.maxlen = conn->c_raddr.len; 547*10326SSiddheshwar.Mahesh@Sun.COM 548*10326SSiddheshwar.Mahesh@Sun.COM clone_xprt->xp_lcladdr.buf = conn->c_laddr.buf; 549*10326SSiddheshwar.Mahesh@Sun.COM clone_xprt->xp_lcladdr.len = conn->c_laddr.len; 550*10326SSiddheshwar.Mahesh@Sun.COM clone_xprt->xp_lcladdr.maxlen = conn->c_laddr.len; 551*10326SSiddheshwar.Mahesh@Sun.COM 552*10326SSiddheshwar.Mahesh@Sun.COM /* 553*10326SSiddheshwar.Mahesh@Sun.COM * In case of RDMA, connection management is 554*10326SSiddheshwar.Mahesh@Sun.COM * entirely done in rpcib module and netid in the 555*10326SSiddheshwar.Mahesh@Sun.COM * SVCMASTERXPRT is NULL. Initialize the clone netid 556*10326SSiddheshwar.Mahesh@Sun.COM * from the connection. 557*10326SSiddheshwar.Mahesh@Sun.COM */ 558*10326SSiddheshwar.Mahesh@Sun.COM 559*10326SSiddheshwar.Mahesh@Sun.COM clone_xprt->xp_netid = conn->c_netid; 560*10326SSiddheshwar.Mahesh@Sun.COM 5617387SRobert.Gordon@Sun.COM clone_xprt->xp_xid = xid; 5627387SRobert.Gordon@Sun.COM crdp->conn = conn; 5630Sstevel@tonic-gate 5647387SRobert.Gordon@Sun.COM freeb(mp); 5657387SRobert.Gordon@Sun.COM 5667387SRobert.Gordon@Sun.COM return (TRUE); 5677387SRobert.Gordon@Sun.COM 5687387SRobert.Gordon@Sun.COM callmsg_err: 5697387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &crdp->rpcbuf); 5707387SRobert.Gordon@Sun.COM 5717387SRobert.Gordon@Sun.COM cll_malloc_err: 5727387SRobert.Gordon@Sun.COM if (cl) 5737387SRobert.Gordon@Sun.COM clist_free(cl); 5747387SRobert.Gordon@Sun.COM xdr_err: 5757387SRobert.Gordon@Sun.COM XDR_DESTROY(xdrs); 5767387SRobert.Gordon@Sun.COM 5777387SRobert.Gordon@Sun.COM badrpc_call: 5787387SRobert.Gordon@Sun.COM RDMA_BUF_FREE(conn, &rdp->rpcmsg); 5797387SRobert.Gordon@Sun.COM RDMA_REL_CONN(conn); 5807387SRobert.Gordon@Sun.COM freeb(mp); 5817387SRobert.Gordon@Sun.COM RSSTAT_INCR(rsbadcalls); 5827387SRobert.Gordon@Sun.COM return (FALSE); 5837387SRobert.Gordon@Sun.COM } 5847387SRobert.Gordon@Sun.COM 5857387SRobert.Gordon@Sun.COM static int 5867387SRobert.Gordon@Sun.COM svc_process_long_reply(SVCXPRT * clone_xprt, 5877387SRobert.Gordon@Sun.COM xdrproc_t xdr_results, caddr_t xdr_location, 5887387SRobert.Gordon@Sun.COM struct rpc_msg *msg, bool_t has_args, int *msglen, 5897387SRobert.Gordon@Sun.COM int *freelen, int *numchunks, unsigned int *final_len) 5907387SRobert.Gordon@Sun.COM { 5917387SRobert.Gordon@Sun.COM int status; 5927387SRobert.Gordon@Sun.COM XDR xdrslong; 5937387SRobert.Gordon@Sun.COM struct clist *wcl = NULL; 5947387SRobert.Gordon@Sun.COM int count = 0; 5957387SRobert.Gordon@Sun.COM int alloc_len; 5967387SRobert.Gordon@Sun.COM char *memp; 5977387SRobert.Gordon@Sun.COM rdma_buf_t long_rpc = {0}; 5987387SRobert.Gordon@Sun.COM struct clone_rdma_data *crdp; 5997387SRobert.Gordon@Sun.COM 6007387SRobert.Gordon@Sun.COM crdp = (struct clone_rdma_data *)clone_xprt->xp_p2buf; 6017387SRobert.Gordon@Sun.COM 6027387SRobert.Gordon@Sun.COM bzero(&xdrslong, sizeof (xdrslong)); 6037387SRobert.Gordon@Sun.COM 6047387SRobert.Gordon@Sun.COM /* Choose a size for the long rpc response */ 6057387SRobert.Gordon@Sun.COM if (MSG_IS_RPCSEC_GSS(msg)) { 6067387SRobert.Gordon@Sun.COM alloc_len = RNDUP(MAX_AUTH_BYTES + *msglen); 6077387SRobert.Gordon@Sun.COM } else { 6087387SRobert.Gordon@Sun.COM alloc_len = RNDUP(*msglen); 6097387SRobert.Gordon@Sun.COM } 6107387SRobert.Gordon@Sun.COM 6117387SRobert.Gordon@Sun.COM if (alloc_len <= 64 * 1024) { 6127387SRobert.Gordon@Sun.COM if (alloc_len > 32 * 1024) { 6137387SRobert.Gordon@Sun.COM alloc_len = 64 * 1024; 6147387SRobert.Gordon@Sun.COM } else { 6157387SRobert.Gordon@Sun.COM if (alloc_len > 16 * 1024) { 6167387SRobert.Gordon@Sun.COM alloc_len = 32 * 1024; 6177387SRobert.Gordon@Sun.COM } else { 6187387SRobert.Gordon@Sun.COM alloc_len = 16 * 1024; 6197387SRobert.Gordon@Sun.COM } 6207387SRobert.Gordon@Sun.COM } 6217387SRobert.Gordon@Sun.COM } 6227387SRobert.Gordon@Sun.COM 6237387SRobert.Gordon@Sun.COM long_rpc.type = RDMA_LONG_BUFFER; 6247387SRobert.Gordon@Sun.COM long_rpc.len = alloc_len; 6257387SRobert.Gordon@Sun.COM if (rdma_buf_alloc(crdp->conn, &long_rpc)) { 6267387SRobert.Gordon@Sun.COM return (SVC_RDMA_FAIL); 6277387SRobert.Gordon@Sun.COM } 6287387SRobert.Gordon@Sun.COM 6297387SRobert.Gordon@Sun.COM memp = long_rpc.addr; 6307387SRobert.Gordon@Sun.COM xdrmem_create(&xdrslong, memp, alloc_len, XDR_ENCODE); 6317387SRobert.Gordon@Sun.COM 6327387SRobert.Gordon@Sun.COM msg->rm_xid = clone_xprt->xp_xid; 6337387SRobert.Gordon@Sun.COM 6347387SRobert.Gordon@Sun.COM if (!(xdr_replymsg(&xdrslong, msg) && 6357387SRobert.Gordon@Sun.COM (!has_args || SVCAUTH_WRAP(&clone_xprt->xp_auth, &xdrslong, 6367387SRobert.Gordon@Sun.COM xdr_results, xdr_location)))) { 6377387SRobert.Gordon@Sun.COM rdma_buf_free(crdp->conn, &long_rpc); 6387387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__longrep__authwrap); 6397387SRobert.Gordon@Sun.COM return (SVC_RDMA_FAIL); 6407387SRobert.Gordon@Sun.COM } 6417387SRobert.Gordon@Sun.COM 6427387SRobert.Gordon@Sun.COM *final_len = XDR_GETPOS(&xdrslong); 6437387SRobert.Gordon@Sun.COM 6449348SSiddheshwar.Mahesh@Sun.COM DTRACE_PROBE1(krpc__i__replylen, uint_t, *final_len); 6457387SRobert.Gordon@Sun.COM *numchunks = 0; 6467387SRobert.Gordon@Sun.COM *freelen = 0; 6477387SRobert.Gordon@Sun.COM 6487387SRobert.Gordon@Sun.COM wcl = crdp->cl_reply; 6497387SRobert.Gordon@Sun.COM wcl->rb_longbuf = long_rpc; 6507387SRobert.Gordon@Sun.COM 6517387SRobert.Gordon@Sun.COM count = *final_len; 6529348SSiddheshwar.Mahesh@Sun.COM while ((wcl != NULL) && (count > 0)) { 6539348SSiddheshwar.Mahesh@Sun.COM 6547387SRobert.Gordon@Sun.COM if (wcl->c_dmemhandle.mrc_rmr == 0) 6557387SRobert.Gordon@Sun.COM break; 6560Sstevel@tonic-gate 6579348SSiddheshwar.Mahesh@Sun.COM DTRACE_PROBE2(krpc__i__write__chunks, uint32_t, count, 6589348SSiddheshwar.Mahesh@Sun.COM uint32_t, wcl->c_len); 6599348SSiddheshwar.Mahesh@Sun.COM 6607387SRobert.Gordon@Sun.COM if (wcl->c_len > count) { 6617387SRobert.Gordon@Sun.COM wcl->c_len = count; 6627387SRobert.Gordon@Sun.COM } 6637387SRobert.Gordon@Sun.COM wcl->w.c_saddr3 = (caddr_t)memp; 6647387SRobert.Gordon@Sun.COM 6657387SRobert.Gordon@Sun.COM count -= wcl->c_len; 6667387SRobert.Gordon@Sun.COM *numchunks += 1; 6679348SSiddheshwar.Mahesh@Sun.COM memp += wcl->c_len; 6689348SSiddheshwar.Mahesh@Sun.COM wcl = wcl->c_next; 6699348SSiddheshwar.Mahesh@Sun.COM } 6709348SSiddheshwar.Mahesh@Sun.COM 6719348SSiddheshwar.Mahesh@Sun.COM /* 6729348SSiddheshwar.Mahesh@Sun.COM * Make rest of the chunks 0-len 6739348SSiddheshwar.Mahesh@Sun.COM */ 6749348SSiddheshwar.Mahesh@Sun.COM while (wcl != NULL) { 6759348SSiddheshwar.Mahesh@Sun.COM if (wcl->c_dmemhandle.mrc_rmr == 0) 6767387SRobert.Gordon@Sun.COM break; 6779348SSiddheshwar.Mahesh@Sun.COM wcl->c_len = 0; 6787387SRobert.Gordon@Sun.COM wcl = wcl->c_next; 6797387SRobert.Gordon@Sun.COM } 6807387SRobert.Gordon@Sun.COM 6817387SRobert.Gordon@Sun.COM wcl = crdp->cl_reply; 6827387SRobert.Gordon@Sun.COM 6837387SRobert.Gordon@Sun.COM /* 6847387SRobert.Gordon@Sun.COM * MUST fail if there are still more data 6857387SRobert.Gordon@Sun.COM */ 6867387SRobert.Gordon@Sun.COM if (count > 0) { 6877387SRobert.Gordon@Sun.COM rdma_buf_free(crdp->conn, &long_rpc); 6887387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__longrep__dlen__clist); 6897387SRobert.Gordon@Sun.COM return (SVC_RDMA_FAIL); 6907387SRobert.Gordon@Sun.COM } 6917387SRobert.Gordon@Sun.COM 6927387SRobert.Gordon@Sun.COM if (clist_register(crdp->conn, wcl, CLIST_REG_SOURCE) != RDMA_SUCCESS) { 6937387SRobert.Gordon@Sun.COM rdma_buf_free(crdp->conn, &long_rpc); 6947387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__longrep__clistreg); 6957387SRobert.Gordon@Sun.COM return (SVC_RDMA_FAIL); 6967387SRobert.Gordon@Sun.COM } 6977387SRobert.Gordon@Sun.COM 6987387SRobert.Gordon@Sun.COM status = clist_syncmem(crdp->conn, wcl, CLIST_REG_SOURCE); 6997387SRobert.Gordon@Sun.COM 7007387SRobert.Gordon@Sun.COM if (status) { 7019348SSiddheshwar.Mahesh@Sun.COM (void) clist_deregister(crdp->conn, wcl); 7027387SRobert.Gordon@Sun.COM rdma_buf_free(crdp->conn, &long_rpc); 7037387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__longrep__syncmem); 7047387SRobert.Gordon@Sun.COM return (SVC_RDMA_FAIL); 7050Sstevel@tonic-gate } 7067387SRobert.Gordon@Sun.COM 7077387SRobert.Gordon@Sun.COM status = RDMA_WRITE(crdp->conn, wcl, WAIT); 7087387SRobert.Gordon@Sun.COM 7099348SSiddheshwar.Mahesh@Sun.COM (void) clist_deregister(crdp->conn, wcl); 7107387SRobert.Gordon@Sun.COM rdma_buf_free(crdp->conn, &wcl->rb_longbuf); 7117387SRobert.Gordon@Sun.COM 7127387SRobert.Gordon@Sun.COM if (status != RDMA_SUCCESS) { 7137387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__longrep__write); 7147387SRobert.Gordon@Sun.COM return (SVC_RDMA_FAIL); 7157387SRobert.Gordon@Sun.COM } 7167387SRobert.Gordon@Sun.COM 7177387SRobert.Gordon@Sun.COM return (SVC_RDMA_SUCCESS); 7187387SRobert.Gordon@Sun.COM } 7197387SRobert.Gordon@Sun.COM 7200Sstevel@tonic-gate 7217387SRobert.Gordon@Sun.COM static int 7227387SRobert.Gordon@Sun.COM svc_compose_rpcmsg(SVCXPRT * clone_xprt, CONN * conn, xdrproc_t xdr_results, 7237387SRobert.Gordon@Sun.COM caddr_t xdr_location, rdma_buf_t *rpcreply, XDR ** xdrs, 7247387SRobert.Gordon@Sun.COM struct rpc_msg *msg, bool_t has_args, uint_t *len) 7257387SRobert.Gordon@Sun.COM { 7267387SRobert.Gordon@Sun.COM /* 7277387SRobert.Gordon@Sun.COM * Get a pre-allocated buffer for rpc reply 7287387SRobert.Gordon@Sun.COM */ 7297387SRobert.Gordon@Sun.COM rpcreply->type = SEND_BUFFER; 7307387SRobert.Gordon@Sun.COM if (rdma_buf_alloc(conn, rpcreply)) { 7317387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__rpcmsg__reply__nofreebufs); 7327387SRobert.Gordon@Sun.COM return (SVC_RDMA_FAIL); 7337387SRobert.Gordon@Sun.COM } 7347387SRobert.Gordon@Sun.COM 7357387SRobert.Gordon@Sun.COM xdrrdma_create(*xdrs, rpcreply->addr, rpcreply->len, 7367387SRobert.Gordon@Sun.COM 0, NULL, XDR_ENCODE, conn); 7377387SRobert.Gordon@Sun.COM 7387387SRobert.Gordon@Sun.COM msg->rm_xid = clone_xprt->xp_xid; 7397387SRobert.Gordon@Sun.COM 7407387SRobert.Gordon@Sun.COM if (has_args) { 7417387SRobert.Gordon@Sun.COM if (!(xdr_replymsg(*xdrs, msg) && 7427387SRobert.Gordon@Sun.COM (!has_args || 7437387SRobert.Gordon@Sun.COM SVCAUTH_WRAP(&clone_xprt->xp_auth, *xdrs, 7447387SRobert.Gordon@Sun.COM xdr_results, xdr_location)))) { 7457387SRobert.Gordon@Sun.COM rdma_buf_free(conn, rpcreply); 7467387SRobert.Gordon@Sun.COM DTRACE_PROBE( 7477387SRobert.Gordon@Sun.COM krpc__e__svcrdma__rpcmsg__reply__authwrap1); 7487387SRobert.Gordon@Sun.COM return (SVC_RDMA_FAIL); 7497387SRobert.Gordon@Sun.COM } 7507387SRobert.Gordon@Sun.COM } else { 7517387SRobert.Gordon@Sun.COM if (!xdr_replymsg(*xdrs, msg)) { 7527387SRobert.Gordon@Sun.COM rdma_buf_free(conn, rpcreply); 7537387SRobert.Gordon@Sun.COM DTRACE_PROBE( 7547387SRobert.Gordon@Sun.COM krpc__e__svcrdma__rpcmsg__reply__authwrap2); 7557387SRobert.Gordon@Sun.COM return (SVC_RDMA_FAIL); 7567387SRobert.Gordon@Sun.COM } 7577387SRobert.Gordon@Sun.COM } 7587387SRobert.Gordon@Sun.COM 7597387SRobert.Gordon@Sun.COM *len = XDR_GETPOS(*xdrs); 7607387SRobert.Gordon@Sun.COM 7617387SRobert.Gordon@Sun.COM return (SVC_RDMA_SUCCESS); 7620Sstevel@tonic-gate } 7630Sstevel@tonic-gate 7640Sstevel@tonic-gate /* 7650Sstevel@tonic-gate * Send rpc reply. 7660Sstevel@tonic-gate */ 7670Sstevel@tonic-gate static bool_t 7687387SRobert.Gordon@Sun.COM svc_rdma_ksend(SVCXPRT * clone_xprt, struct rpc_msg *msg) 7690Sstevel@tonic-gate { 7707387SRobert.Gordon@Sun.COM XDR *xdrs_rpc = &(clone_xprt->xp_xdrout); 7717387SRobert.Gordon@Sun.COM XDR xdrs_rhdr; 7727387SRobert.Gordon@Sun.COM CONN *conn = NULL; 7737387SRobert.Gordon@Sun.COM rdma_buf_t rbuf_resp = {0}, rbuf_rpc_resp = {0}; 7747387SRobert.Gordon@Sun.COM 7757387SRobert.Gordon@Sun.COM struct clone_rdma_data *crdp; 7767387SRobert.Gordon@Sun.COM struct clist *cl_read = NULL; 7777387SRobert.Gordon@Sun.COM struct clist *cl_send = NULL; 7787387SRobert.Gordon@Sun.COM struct clist *cl_write = NULL; 7797387SRobert.Gordon@Sun.COM xdrproc_t xdr_results; /* results XDR encoding function */ 7807387SRobert.Gordon@Sun.COM caddr_t xdr_location; /* response results pointer */ 7817387SRobert.Gordon@Sun.COM 7820Sstevel@tonic-gate int retval = FALSE; 7837387SRobert.Gordon@Sun.COM int status, msglen, num_wreply_segments = 0; 7847387SRobert.Gordon@Sun.COM uint32_t rdma_credit = 0; 7857387SRobert.Gordon@Sun.COM int freelen = 0; 7867387SRobert.Gordon@Sun.COM bool_t has_args; 7877387SRobert.Gordon@Sun.COM uint_t final_resp_len, rdma_response_op, vers; 7880Sstevel@tonic-gate 7897387SRobert.Gordon@Sun.COM bzero(&xdrs_rhdr, sizeof (XDR)); 7907387SRobert.Gordon@Sun.COM crdp = (struct clone_rdma_data *)clone_xprt->xp_p2buf; 7917387SRobert.Gordon@Sun.COM conn = crdp->conn; 7920Sstevel@tonic-gate 7930Sstevel@tonic-gate /* 7940Sstevel@tonic-gate * If there is a result procedure specified in the reply message, 7950Sstevel@tonic-gate * it will be processed in the xdr_replymsg and SVCAUTH_WRAP. 7960Sstevel@tonic-gate * We need to make sure it won't be processed twice, so we null 7970Sstevel@tonic-gate * it for xdr_replymsg here. 7980Sstevel@tonic-gate */ 7990Sstevel@tonic-gate has_args = FALSE; 8000Sstevel@tonic-gate if (msg->rm_reply.rp_stat == MSG_ACCEPTED && 8010Sstevel@tonic-gate msg->rm_reply.rp_acpt.ar_stat == SUCCESS) { 8020Sstevel@tonic-gate if ((xdr_results = msg->acpted_rply.ar_results.proc) != NULL) { 8030Sstevel@tonic-gate has_args = TRUE; 8040Sstevel@tonic-gate xdr_location = msg->acpted_rply.ar_results.where; 8050Sstevel@tonic-gate msg->acpted_rply.ar_results.proc = xdr_void; 8060Sstevel@tonic-gate msg->acpted_rply.ar_results.where = NULL; 8070Sstevel@tonic-gate } 8080Sstevel@tonic-gate } 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate /* 8117387SRobert.Gordon@Sun.COM * Given the limit on the inline response size (RPC_MSG_SZ), 8127387SRobert.Gordon@Sun.COM * there is a need to make a guess as to the overall size of 8137387SRobert.Gordon@Sun.COM * the response. If the resultant size is beyond the inline 8147387SRobert.Gordon@Sun.COM * size, then the server needs to use the "reply chunk list" 8157387SRobert.Gordon@Sun.COM * provided by the client (if the client provided one). An 8167387SRobert.Gordon@Sun.COM * example of this type of response would be a READDIR 8177387SRobert.Gordon@Sun.COM * response (e.g. a small directory read would fit in RPC_MSG_SZ 8187387SRobert.Gordon@Sun.COM * and that is the preference but it may not fit) 8197387SRobert.Gordon@Sun.COM * 8207387SRobert.Gordon@Sun.COM * Combine the encoded size and the size of the true results 8217387SRobert.Gordon@Sun.COM * and then make the decision about where to encode and send results. 8227387SRobert.Gordon@Sun.COM * 8237387SRobert.Gordon@Sun.COM * One important note, this calculation is ignoring the size 8247387SRobert.Gordon@Sun.COM * of the encoding of the authentication overhead. The reason 8257387SRobert.Gordon@Sun.COM * for this is rooted in the complexities of access to the 8267387SRobert.Gordon@Sun.COM * encoded size of RPCSEC_GSS related authentiation, 8277387SRobert.Gordon@Sun.COM * integrity, and privacy. 8287387SRobert.Gordon@Sun.COM * 8297387SRobert.Gordon@Sun.COM * If it turns out that the encoded authentication bumps the 8307387SRobert.Gordon@Sun.COM * response over the RPC_MSG_SZ limit, then it may need to 8317387SRobert.Gordon@Sun.COM * attempt to encode for the reply chunk list. 8327387SRobert.Gordon@Sun.COM */ 8337387SRobert.Gordon@Sun.COM 8347387SRobert.Gordon@Sun.COM /* 8357387SRobert.Gordon@Sun.COM * Calculating the "sizeof" the RPC response header and the 8367387SRobert.Gordon@Sun.COM * encoded results. 8370Sstevel@tonic-gate */ 8380Sstevel@tonic-gate msglen = xdr_sizeof(xdr_replymsg, msg); 8397387SRobert.Gordon@Sun.COM 8407387SRobert.Gordon@Sun.COM if (msglen > 0) { 8417387SRobert.Gordon@Sun.COM RSSTAT_INCR(rstotalreplies); 8427387SRobert.Gordon@Sun.COM } 8437387SRobert.Gordon@Sun.COM if (has_args) 8440Sstevel@tonic-gate msglen += xdrrdma_sizeof(xdr_results, xdr_location, 8457387SRobert.Gordon@Sun.COM rdma_minchunk, NULL, NULL); 8467387SRobert.Gordon@Sun.COM 8477387SRobert.Gordon@Sun.COM DTRACE_PROBE1(krpc__i__svcrdma__ksend__msglen, int, msglen); 8480Sstevel@tonic-gate 8497387SRobert.Gordon@Sun.COM status = SVC_RDMA_SUCCESS; 8500Sstevel@tonic-gate 8517387SRobert.Gordon@Sun.COM if (msglen < RPC_MSG_SZ) { 8520Sstevel@tonic-gate /* 8537387SRobert.Gordon@Sun.COM * Looks like the response will fit in the inline 8547387SRobert.Gordon@Sun.COM * response; let's try 8550Sstevel@tonic-gate */ 8567387SRobert.Gordon@Sun.COM RSSTAT_INCR(rstotalinlinereplies); 8577387SRobert.Gordon@Sun.COM 8587387SRobert.Gordon@Sun.COM rdma_response_op = RDMA_MSG; 8590Sstevel@tonic-gate 8607387SRobert.Gordon@Sun.COM status = svc_compose_rpcmsg(clone_xprt, conn, xdr_results, 8617387SRobert.Gordon@Sun.COM xdr_location, &rbuf_rpc_resp, &xdrs_rpc, msg, 8627387SRobert.Gordon@Sun.COM has_args, &final_resp_len); 8637387SRobert.Gordon@Sun.COM 8647387SRobert.Gordon@Sun.COM DTRACE_PROBE1(krpc__i__srdma__ksend__compose_status, 8657387SRobert.Gordon@Sun.COM int, status); 8667387SRobert.Gordon@Sun.COM DTRACE_PROBE1(krpc__i__srdma__ksend__compose_len, 8677387SRobert.Gordon@Sun.COM int, final_resp_len); 8687387SRobert.Gordon@Sun.COM 8697387SRobert.Gordon@Sun.COM if (status == SVC_RDMA_SUCCESS && crdp->cl_reply) { 8707387SRobert.Gordon@Sun.COM clist_free(crdp->cl_reply); 8717387SRobert.Gordon@Sun.COM crdp->cl_reply = NULL; 8720Sstevel@tonic-gate } 8730Sstevel@tonic-gate } 8740Sstevel@tonic-gate 8757387SRobert.Gordon@Sun.COM /* 8767387SRobert.Gordon@Sun.COM * If the encode failed (size?) or the message really is 8777387SRobert.Gordon@Sun.COM * larger than what is allowed, try the response chunk list. 8787387SRobert.Gordon@Sun.COM */ 8797387SRobert.Gordon@Sun.COM if (status != SVC_RDMA_SUCCESS || msglen >= RPC_MSG_SZ) { 8800Sstevel@tonic-gate /* 8817387SRobert.Gordon@Sun.COM * attempting to use a reply chunk list when there 8827387SRobert.Gordon@Sun.COM * isn't one won't get very far... 8830Sstevel@tonic-gate */ 8847387SRobert.Gordon@Sun.COM if (crdp->cl_reply == NULL) { 8857387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__ksend__noreplycl); 8860Sstevel@tonic-gate goto out; 8870Sstevel@tonic-gate } 8880Sstevel@tonic-gate 8897387SRobert.Gordon@Sun.COM RSSTAT_INCR(rstotallongreplies); 8907387SRobert.Gordon@Sun.COM 8917387SRobert.Gordon@Sun.COM msglen = xdr_sizeof(xdr_replymsg, msg); 8927387SRobert.Gordon@Sun.COM msglen += xdrrdma_sizeof(xdr_results, xdr_location, 0, 8937387SRobert.Gordon@Sun.COM NULL, NULL); 8947387SRobert.Gordon@Sun.COM 8957387SRobert.Gordon@Sun.COM status = svc_process_long_reply(clone_xprt, xdr_results, 8967387SRobert.Gordon@Sun.COM xdr_location, msg, has_args, &msglen, &freelen, 8977387SRobert.Gordon@Sun.COM &num_wreply_segments, &final_resp_len); 8987387SRobert.Gordon@Sun.COM 8997387SRobert.Gordon@Sun.COM DTRACE_PROBE1(krpc__i__svcrdma__ksend__longreplen, 9007387SRobert.Gordon@Sun.COM int, final_resp_len); 9017387SRobert.Gordon@Sun.COM 9027387SRobert.Gordon@Sun.COM if (status != SVC_RDMA_SUCCESS) { 9037387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__ksend__compose__failed); 9047387SRobert.Gordon@Sun.COM goto out; 9050Sstevel@tonic-gate } 9060Sstevel@tonic-gate 9077387SRobert.Gordon@Sun.COM rdma_response_op = RDMA_NOMSG; 9080Sstevel@tonic-gate } 9090Sstevel@tonic-gate 9107387SRobert.Gordon@Sun.COM DTRACE_PROBE1(krpc__i__svcrdma__ksend__rdmamsg__len, 9117387SRobert.Gordon@Sun.COM int, final_resp_len); 9120Sstevel@tonic-gate 9137387SRobert.Gordon@Sun.COM rbuf_resp.type = SEND_BUFFER; 9147387SRobert.Gordon@Sun.COM if (rdma_buf_alloc(conn, &rbuf_resp)) { 9157387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &rbuf_rpc_resp); 9167387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__ksend__nofreebufs); 9177387SRobert.Gordon@Sun.COM goto out; 9180Sstevel@tonic-gate } 9190Sstevel@tonic-gate 9207387SRobert.Gordon@Sun.COM rdma_credit = rdma_bufs_granted; 9217387SRobert.Gordon@Sun.COM 9227387SRobert.Gordon@Sun.COM vers = RPCRDMA_VERS; 9237387SRobert.Gordon@Sun.COM xdrmem_create(&xdrs_rhdr, rbuf_resp.addr, rbuf_resp.len, XDR_ENCODE); 9247387SRobert.Gordon@Sun.COM (*(uint32_t *)rbuf_resp.addr) = msg->rm_xid; 9257387SRobert.Gordon@Sun.COM /* Skip xid and set the xdr position accordingly. */ 9267387SRobert.Gordon@Sun.COM XDR_SETPOS(&xdrs_rhdr, sizeof (uint32_t)); 9277387SRobert.Gordon@Sun.COM if (!xdr_u_int(&xdrs_rhdr, &vers) || 9287387SRobert.Gordon@Sun.COM !xdr_u_int(&xdrs_rhdr, &rdma_credit) || 9297387SRobert.Gordon@Sun.COM !xdr_u_int(&xdrs_rhdr, &rdma_response_op)) { 9307387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &rbuf_rpc_resp); 9317387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &rbuf_resp); 9327387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__ksend__uint); 9330Sstevel@tonic-gate goto out; 9340Sstevel@tonic-gate } 9350Sstevel@tonic-gate 9360Sstevel@tonic-gate /* 9377387SRobert.Gordon@Sun.COM * Now XDR the read chunk list, actually always NULL 9380Sstevel@tonic-gate */ 9397387SRobert.Gordon@Sun.COM (void) xdr_encode_rlist_svc(&xdrs_rhdr, cl_read); 9400Sstevel@tonic-gate 9410Sstevel@tonic-gate /* 9427387SRobert.Gordon@Sun.COM * encode write list -- we already drove RDMA_WRITEs 9430Sstevel@tonic-gate */ 9447387SRobert.Gordon@Sun.COM cl_write = crdp->cl_wlist; 9457387SRobert.Gordon@Sun.COM if (!xdr_encode_wlist(&xdrs_rhdr, cl_write)) { 9467387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__svcrdma__ksend__enc__wlist); 9477387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &rbuf_rpc_resp); 9487387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &rbuf_resp); 9490Sstevel@tonic-gate goto out; 9500Sstevel@tonic-gate } 9510Sstevel@tonic-gate 9520Sstevel@tonic-gate /* 9537387SRobert.Gordon@Sun.COM * XDR encode the RDMA_REPLY write chunk 9540Sstevel@tonic-gate */ 9557387SRobert.Gordon@Sun.COM if (!xdr_encode_reply_wchunk(&xdrs_rhdr, crdp->cl_reply, 9567387SRobert.Gordon@Sun.COM num_wreply_segments)) { 9577387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &rbuf_rpc_resp); 9587387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &rbuf_resp); 9597387SRobert.Gordon@Sun.COM goto out; 9600Sstevel@tonic-gate } 9610Sstevel@tonic-gate 9627387SRobert.Gordon@Sun.COM clist_add(&cl_send, 0, XDR_GETPOS(&xdrs_rhdr), &rbuf_resp.handle, 9637387SRobert.Gordon@Sun.COM rbuf_resp.addr, NULL, NULL); 9640Sstevel@tonic-gate 9657387SRobert.Gordon@Sun.COM if (rdma_response_op == RDMA_MSG) { 9667387SRobert.Gordon@Sun.COM clist_add(&cl_send, 0, final_resp_len, &rbuf_rpc_resp.handle, 9677387SRobert.Gordon@Sun.COM rbuf_rpc_resp.addr, NULL, NULL); 9680Sstevel@tonic-gate } 9690Sstevel@tonic-gate 9707387SRobert.Gordon@Sun.COM status = RDMA_SEND(conn, cl_send, msg->rm_xid); 9717387SRobert.Gordon@Sun.COM 9727387SRobert.Gordon@Sun.COM if (status == RDMA_SUCCESS) { 9737387SRobert.Gordon@Sun.COM retval = TRUE; 9740Sstevel@tonic-gate } 9750Sstevel@tonic-gate 9767387SRobert.Gordon@Sun.COM out: 9770Sstevel@tonic-gate /* 9780Sstevel@tonic-gate * Free up sendlist chunks 9790Sstevel@tonic-gate */ 9807387SRobert.Gordon@Sun.COM if (cl_send != NULL) 9817387SRobert.Gordon@Sun.COM clist_free(cl_send); 9820Sstevel@tonic-gate 9830Sstevel@tonic-gate /* 9840Sstevel@tonic-gate * Destroy private data for xdr rdma 9850Sstevel@tonic-gate */ 9867387SRobert.Gordon@Sun.COM if (clone_xprt->xp_xdrout.x_ops != NULL) { 9877387SRobert.Gordon@Sun.COM XDR_DESTROY(&(clone_xprt->xp_xdrout)); 9887387SRobert.Gordon@Sun.COM } 9897387SRobert.Gordon@Sun.COM 9907387SRobert.Gordon@Sun.COM if (crdp->cl_reply) { 9917387SRobert.Gordon@Sun.COM clist_free(crdp->cl_reply); 9927387SRobert.Gordon@Sun.COM crdp->cl_reply = NULL; 9937387SRobert.Gordon@Sun.COM } 9940Sstevel@tonic-gate 9950Sstevel@tonic-gate /* 9960Sstevel@tonic-gate * This is completely disgusting. If public is set it is 9970Sstevel@tonic-gate * a pointer to a structure whose first field is the address 9980Sstevel@tonic-gate * of the function to free that structure and any related 9990Sstevel@tonic-gate * stuff. (see rrokfree in nfs_xdr.c). 10000Sstevel@tonic-gate */ 10017387SRobert.Gordon@Sun.COM if (xdrs_rpc->x_public) { 10020Sstevel@tonic-gate /* LINTED pointer alignment */ 10037387SRobert.Gordon@Sun.COM (**((int (**)()) xdrs_rpc->x_public)) (xdrs_rpc->x_public); 10047387SRobert.Gordon@Sun.COM } 10057387SRobert.Gordon@Sun.COM 10067387SRobert.Gordon@Sun.COM if (xdrs_rhdr.x_ops != NULL) { 10077387SRobert.Gordon@Sun.COM XDR_DESTROY(&xdrs_rhdr); 10080Sstevel@tonic-gate } 10090Sstevel@tonic-gate 10100Sstevel@tonic-gate return (retval); 10110Sstevel@tonic-gate } 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate /* 10140Sstevel@tonic-gate * Deserialize arguments. 10150Sstevel@tonic-gate */ 10160Sstevel@tonic-gate static bool_t 10170Sstevel@tonic-gate svc_rdma_kgetargs(SVCXPRT *clone_xprt, xdrproc_t xdr_args, caddr_t args_ptr) 10180Sstevel@tonic-gate { 10190Sstevel@tonic-gate if ((SVCAUTH_UNWRAP(&clone_xprt->xp_auth, &clone_xprt->xp_xdrin, 10200Sstevel@tonic-gate xdr_args, args_ptr)) != TRUE) 10210Sstevel@tonic-gate return (FALSE); 10220Sstevel@tonic-gate return (TRUE); 10230Sstevel@tonic-gate } 10240Sstevel@tonic-gate 10250Sstevel@tonic-gate static bool_t 10260Sstevel@tonic-gate svc_rdma_kfreeargs(SVCXPRT *clone_xprt, xdrproc_t xdr_args, 10270Sstevel@tonic-gate caddr_t args_ptr) 10280Sstevel@tonic-gate { 10297387SRobert.Gordon@Sun.COM struct clone_rdma_data *crdp; 10300Sstevel@tonic-gate bool_t retval; 10310Sstevel@tonic-gate 10327387SRobert.Gordon@Sun.COM crdp = (struct clone_rdma_data *)clone_xprt->xp_p2buf; 10337387SRobert.Gordon@Sun.COM 10347387SRobert.Gordon@Sun.COM /* 10357387SRobert.Gordon@Sun.COM * Free the args if needed then XDR_DESTROY 10367387SRobert.Gordon@Sun.COM */ 10370Sstevel@tonic-gate if (args_ptr) { 10380Sstevel@tonic-gate XDR *xdrs = &clone_xprt->xp_xdrin; 10390Sstevel@tonic-gate 10400Sstevel@tonic-gate xdrs->x_op = XDR_FREE; 10410Sstevel@tonic-gate retval = (*xdr_args)(xdrs, args_ptr); 10420Sstevel@tonic-gate } 10437387SRobert.Gordon@Sun.COM 10440Sstevel@tonic-gate XDR_DESTROY(&(clone_xprt->xp_xdrin)); 10457387SRobert.Gordon@Sun.COM rdma_buf_free(crdp->conn, &crdp->rpcbuf); 10467387SRobert.Gordon@Sun.COM if (crdp->cl_reply) { 10477387SRobert.Gordon@Sun.COM clist_free(crdp->cl_reply); 10487387SRobert.Gordon@Sun.COM crdp->cl_reply = NULL; 10497387SRobert.Gordon@Sun.COM } 10507387SRobert.Gordon@Sun.COM RDMA_REL_CONN(crdp->conn); 10517387SRobert.Gordon@Sun.COM 10520Sstevel@tonic-gate return (retval); 10530Sstevel@tonic-gate } 10540Sstevel@tonic-gate 10550Sstevel@tonic-gate /* ARGSUSED */ 10560Sstevel@tonic-gate static int32_t * 10570Sstevel@tonic-gate svc_rdma_kgetres(SVCXPRT *clone_xprt, int size) 10580Sstevel@tonic-gate { 10590Sstevel@tonic-gate return (NULL); 10600Sstevel@tonic-gate } 10610Sstevel@tonic-gate 10620Sstevel@tonic-gate /* ARGSUSED */ 10630Sstevel@tonic-gate static void 10640Sstevel@tonic-gate svc_rdma_kfreeres(SVCXPRT *clone_xprt) 10650Sstevel@tonic-gate { 10660Sstevel@tonic-gate } 10670Sstevel@tonic-gate 10680Sstevel@tonic-gate /* 10690Sstevel@tonic-gate * the dup cacheing routines below provide a cache of non-failure 10700Sstevel@tonic-gate * transaction id's. rpc service routines can use this to detect 10710Sstevel@tonic-gate * retransmissions and re-send a non-failure response. 10720Sstevel@tonic-gate */ 10730Sstevel@tonic-gate 10740Sstevel@tonic-gate /* 10750Sstevel@tonic-gate * MAXDUPREQS is the number of cached items. It should be adjusted 10760Sstevel@tonic-gate * to the service load so that there is likely to be a response entry 10770Sstevel@tonic-gate * when the first retransmission comes in. 10780Sstevel@tonic-gate */ 10790Sstevel@tonic-gate #define MAXDUPREQS 1024 10800Sstevel@tonic-gate 10810Sstevel@tonic-gate /* 10820Sstevel@tonic-gate * This should be appropriately scaled to MAXDUPREQS. 10830Sstevel@tonic-gate */ 10840Sstevel@tonic-gate #define DRHASHSZ 257 10850Sstevel@tonic-gate 10860Sstevel@tonic-gate #if ((DRHASHSZ & (DRHASHSZ - 1)) == 0) 10870Sstevel@tonic-gate #define XIDHASH(xid) ((xid) & (DRHASHSZ - 1)) 10880Sstevel@tonic-gate #else 10890Sstevel@tonic-gate #define XIDHASH(xid) ((xid) % DRHASHSZ) 10900Sstevel@tonic-gate #endif 10910Sstevel@tonic-gate #define DRHASH(dr) XIDHASH((dr)->dr_xid) 10920Sstevel@tonic-gate #define REQTOXID(req) ((req)->rq_xprt->xp_xid) 10930Sstevel@tonic-gate 10940Sstevel@tonic-gate static int rdmandupreqs = 0; 10957803Sgt29601@anthrax int rdmamaxdupreqs = MAXDUPREQS; 10960Sstevel@tonic-gate static kmutex_t rdmadupreq_lock; 10970Sstevel@tonic-gate static struct dupreq *rdmadrhashtbl[DRHASHSZ]; 10980Sstevel@tonic-gate static int rdmadrhashstat[DRHASHSZ]; 10990Sstevel@tonic-gate 11000Sstevel@tonic-gate static void unhash(struct dupreq *); 11010Sstevel@tonic-gate 11020Sstevel@tonic-gate /* 11030Sstevel@tonic-gate * rdmadrmru points to the head of a circular linked list in lru order. 11040Sstevel@tonic-gate * rdmadrmru->dr_next == drlru 11050Sstevel@tonic-gate */ 11060Sstevel@tonic-gate struct dupreq *rdmadrmru; 11070Sstevel@tonic-gate 11080Sstevel@tonic-gate /* 11090Sstevel@tonic-gate * svc_rdma_kdup searches the request cache and returns 0 if the 11100Sstevel@tonic-gate * request is not found in the cache. If it is found, then it 11110Sstevel@tonic-gate * returns the state of the request (in progress or done) and 11120Sstevel@tonic-gate * the status or attributes that were part of the original reply. 11130Sstevel@tonic-gate */ 11140Sstevel@tonic-gate static int 11150Sstevel@tonic-gate svc_rdma_kdup(struct svc_req *req, caddr_t res, int size, struct dupreq **drpp, 11160Sstevel@tonic-gate bool_t *dupcachedp) 11170Sstevel@tonic-gate { 11180Sstevel@tonic-gate struct dupreq *dr; 11190Sstevel@tonic-gate uint32_t xid; 11200Sstevel@tonic-gate uint32_t drhash; 11210Sstevel@tonic-gate int status; 11220Sstevel@tonic-gate 11230Sstevel@tonic-gate xid = REQTOXID(req); 11240Sstevel@tonic-gate mutex_enter(&rdmadupreq_lock); 11250Sstevel@tonic-gate RSSTAT_INCR(rsdupchecks); 11260Sstevel@tonic-gate /* 11270Sstevel@tonic-gate * Check to see whether an entry already exists in the cache. 11280Sstevel@tonic-gate */ 11290Sstevel@tonic-gate dr = rdmadrhashtbl[XIDHASH(xid)]; 11300Sstevel@tonic-gate while (dr != NULL) { 11310Sstevel@tonic-gate if (dr->dr_xid == xid && 11320Sstevel@tonic-gate dr->dr_proc == req->rq_proc && 11330Sstevel@tonic-gate dr->dr_prog == req->rq_prog && 11340Sstevel@tonic-gate dr->dr_vers == req->rq_vers && 11350Sstevel@tonic-gate dr->dr_addr.len == req->rq_xprt->xp_rtaddr.len && 11360Sstevel@tonic-gate bcmp((caddr_t)dr->dr_addr.buf, 11370Sstevel@tonic-gate (caddr_t)req->rq_xprt->xp_rtaddr.buf, 11380Sstevel@tonic-gate dr->dr_addr.len) == 0) { 11390Sstevel@tonic-gate status = dr->dr_status; 11400Sstevel@tonic-gate if (status == DUP_DONE) { 11410Sstevel@tonic-gate bcopy(dr->dr_resp.buf, res, size); 11420Sstevel@tonic-gate if (dupcachedp != NULL) 11430Sstevel@tonic-gate *dupcachedp = (dr->dr_resfree != NULL); 11440Sstevel@tonic-gate } else { 11450Sstevel@tonic-gate dr->dr_status = DUP_INPROGRESS; 11460Sstevel@tonic-gate *drpp = dr; 11470Sstevel@tonic-gate } 11480Sstevel@tonic-gate RSSTAT_INCR(rsdupreqs); 11490Sstevel@tonic-gate mutex_exit(&rdmadupreq_lock); 11500Sstevel@tonic-gate return (status); 11510Sstevel@tonic-gate } 11520Sstevel@tonic-gate dr = dr->dr_chain; 11530Sstevel@tonic-gate } 11540Sstevel@tonic-gate 11550Sstevel@tonic-gate /* 11560Sstevel@tonic-gate * There wasn't an entry, either allocate a new one or recycle 11570Sstevel@tonic-gate * an old one. 11580Sstevel@tonic-gate */ 11590Sstevel@tonic-gate if (rdmandupreqs < rdmamaxdupreqs) { 11600Sstevel@tonic-gate dr = kmem_alloc(sizeof (*dr), KM_NOSLEEP); 11610Sstevel@tonic-gate if (dr == NULL) { 11620Sstevel@tonic-gate mutex_exit(&rdmadupreq_lock); 11630Sstevel@tonic-gate return (DUP_ERROR); 11640Sstevel@tonic-gate } 11650Sstevel@tonic-gate dr->dr_resp.buf = NULL; 11660Sstevel@tonic-gate dr->dr_resp.maxlen = 0; 11670Sstevel@tonic-gate dr->dr_addr.buf = NULL; 11680Sstevel@tonic-gate dr->dr_addr.maxlen = 0; 11690Sstevel@tonic-gate if (rdmadrmru) { 11700Sstevel@tonic-gate dr->dr_next = rdmadrmru->dr_next; 11710Sstevel@tonic-gate rdmadrmru->dr_next = dr; 11720Sstevel@tonic-gate } else { 11730Sstevel@tonic-gate dr->dr_next = dr; 11740Sstevel@tonic-gate } 11750Sstevel@tonic-gate rdmandupreqs++; 11760Sstevel@tonic-gate } else { 11770Sstevel@tonic-gate dr = rdmadrmru->dr_next; 11780Sstevel@tonic-gate while (dr->dr_status == DUP_INPROGRESS) { 11790Sstevel@tonic-gate dr = dr->dr_next; 11800Sstevel@tonic-gate if (dr == rdmadrmru->dr_next) { 11810Sstevel@tonic-gate mutex_exit(&rdmadupreq_lock); 11820Sstevel@tonic-gate return (DUP_ERROR); 11830Sstevel@tonic-gate } 11840Sstevel@tonic-gate } 11850Sstevel@tonic-gate unhash(dr); 11860Sstevel@tonic-gate if (dr->dr_resfree) { 11870Sstevel@tonic-gate (*dr->dr_resfree)(dr->dr_resp.buf); 11880Sstevel@tonic-gate } 11890Sstevel@tonic-gate } 11900Sstevel@tonic-gate dr->dr_resfree = NULL; 11910Sstevel@tonic-gate rdmadrmru = dr; 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate dr->dr_xid = REQTOXID(req); 11940Sstevel@tonic-gate dr->dr_prog = req->rq_prog; 11950Sstevel@tonic-gate dr->dr_vers = req->rq_vers; 11960Sstevel@tonic-gate dr->dr_proc = req->rq_proc; 11970Sstevel@tonic-gate if (dr->dr_addr.maxlen < req->rq_xprt->xp_rtaddr.len) { 11980Sstevel@tonic-gate if (dr->dr_addr.buf != NULL) 11990Sstevel@tonic-gate kmem_free(dr->dr_addr.buf, dr->dr_addr.maxlen); 12000Sstevel@tonic-gate dr->dr_addr.maxlen = req->rq_xprt->xp_rtaddr.len; 12010Sstevel@tonic-gate dr->dr_addr.buf = kmem_alloc(dr->dr_addr.maxlen, KM_NOSLEEP); 12020Sstevel@tonic-gate if (dr->dr_addr.buf == NULL) { 12030Sstevel@tonic-gate dr->dr_addr.maxlen = 0; 12040Sstevel@tonic-gate dr->dr_status = DUP_DROP; 12050Sstevel@tonic-gate mutex_exit(&rdmadupreq_lock); 12060Sstevel@tonic-gate return (DUP_ERROR); 12070Sstevel@tonic-gate } 12080Sstevel@tonic-gate } 12090Sstevel@tonic-gate dr->dr_addr.len = req->rq_xprt->xp_rtaddr.len; 12100Sstevel@tonic-gate bcopy(req->rq_xprt->xp_rtaddr.buf, dr->dr_addr.buf, dr->dr_addr.len); 12110Sstevel@tonic-gate if (dr->dr_resp.maxlen < size) { 12120Sstevel@tonic-gate if (dr->dr_resp.buf != NULL) 12130Sstevel@tonic-gate kmem_free(dr->dr_resp.buf, dr->dr_resp.maxlen); 12140Sstevel@tonic-gate dr->dr_resp.maxlen = (unsigned int)size; 12150Sstevel@tonic-gate dr->dr_resp.buf = kmem_alloc(size, KM_NOSLEEP); 12160Sstevel@tonic-gate if (dr->dr_resp.buf == NULL) { 12170Sstevel@tonic-gate dr->dr_resp.maxlen = 0; 12180Sstevel@tonic-gate dr->dr_status = DUP_DROP; 12190Sstevel@tonic-gate mutex_exit(&rdmadupreq_lock); 12200Sstevel@tonic-gate return (DUP_ERROR); 12210Sstevel@tonic-gate } 12220Sstevel@tonic-gate } 12230Sstevel@tonic-gate dr->dr_status = DUP_INPROGRESS; 12240Sstevel@tonic-gate 12250Sstevel@tonic-gate drhash = (uint32_t)DRHASH(dr); 12260Sstevel@tonic-gate dr->dr_chain = rdmadrhashtbl[drhash]; 12270Sstevel@tonic-gate rdmadrhashtbl[drhash] = dr; 12280Sstevel@tonic-gate rdmadrhashstat[drhash]++; 12290Sstevel@tonic-gate mutex_exit(&rdmadupreq_lock); 12300Sstevel@tonic-gate *drpp = dr; 12310Sstevel@tonic-gate return (DUP_NEW); 12320Sstevel@tonic-gate } 12330Sstevel@tonic-gate 12340Sstevel@tonic-gate /* 12350Sstevel@tonic-gate * svc_rdma_kdupdone marks the request done (DUP_DONE or DUP_DROP) 12360Sstevel@tonic-gate * and stores the response. 12370Sstevel@tonic-gate */ 12380Sstevel@tonic-gate static void 12390Sstevel@tonic-gate svc_rdma_kdupdone(struct dupreq *dr, caddr_t res, void (*dis_resfree)(), 12400Sstevel@tonic-gate int size, int status) 12410Sstevel@tonic-gate { 12420Sstevel@tonic-gate ASSERT(dr->dr_resfree == NULL); 12430Sstevel@tonic-gate if (status == DUP_DONE) { 12440Sstevel@tonic-gate bcopy(res, dr->dr_resp.buf, size); 12450Sstevel@tonic-gate dr->dr_resfree = dis_resfree; 12460Sstevel@tonic-gate } 12470Sstevel@tonic-gate dr->dr_status = status; 12480Sstevel@tonic-gate } 12490Sstevel@tonic-gate 12500Sstevel@tonic-gate /* 12510Sstevel@tonic-gate * This routine expects that the mutex, rdmadupreq_lock, is already held. 12520Sstevel@tonic-gate */ 12530Sstevel@tonic-gate static void 12540Sstevel@tonic-gate unhash(struct dupreq *dr) 12550Sstevel@tonic-gate { 12560Sstevel@tonic-gate struct dupreq *drt; 12570Sstevel@tonic-gate struct dupreq *drtprev = NULL; 12580Sstevel@tonic-gate uint32_t drhash; 12590Sstevel@tonic-gate 12600Sstevel@tonic-gate ASSERT(MUTEX_HELD(&rdmadupreq_lock)); 12610Sstevel@tonic-gate 12620Sstevel@tonic-gate drhash = (uint32_t)DRHASH(dr); 12630Sstevel@tonic-gate drt = rdmadrhashtbl[drhash]; 12640Sstevel@tonic-gate while (drt != NULL) { 12650Sstevel@tonic-gate if (drt == dr) { 12660Sstevel@tonic-gate rdmadrhashstat[drhash]--; 12670Sstevel@tonic-gate if (drtprev == NULL) { 12680Sstevel@tonic-gate rdmadrhashtbl[drhash] = drt->dr_chain; 12690Sstevel@tonic-gate } else { 12700Sstevel@tonic-gate drtprev->dr_chain = drt->dr_chain; 12710Sstevel@tonic-gate } 12720Sstevel@tonic-gate return; 12730Sstevel@tonic-gate } 12740Sstevel@tonic-gate drtprev = drt; 12750Sstevel@tonic-gate drt = drt->dr_chain; 12760Sstevel@tonic-gate } 12770Sstevel@tonic-gate } 12787387SRobert.Gordon@Sun.COM 12797387SRobert.Gordon@Sun.COM bool_t 12807387SRobert.Gordon@Sun.COM rdma_get_wchunk(struct svc_req *req, iovec_t *iov, struct clist *wlist) 12817387SRobert.Gordon@Sun.COM { 12827387SRobert.Gordon@Sun.COM struct clist *clist; 12837387SRobert.Gordon@Sun.COM uint32_t tlen; 12847387SRobert.Gordon@Sun.COM 12857387SRobert.Gordon@Sun.COM if (req->rq_xprt->xp_type != T_RDMA) { 12867387SRobert.Gordon@Sun.COM return (FALSE); 12877387SRobert.Gordon@Sun.COM } 12887387SRobert.Gordon@Sun.COM 12897387SRobert.Gordon@Sun.COM tlen = 0; 12907387SRobert.Gordon@Sun.COM clist = wlist; 12917387SRobert.Gordon@Sun.COM while (clist) { 12927387SRobert.Gordon@Sun.COM tlen += clist->c_len; 12937387SRobert.Gordon@Sun.COM clist = clist->c_next; 12947387SRobert.Gordon@Sun.COM } 12957387SRobert.Gordon@Sun.COM 12967387SRobert.Gordon@Sun.COM /* 12977387SRobert.Gordon@Sun.COM * set iov to addr+len of first segment of first wchunk of 12987387SRobert.Gordon@Sun.COM * wlist sent by client. krecv() already malloc'd a buffer 12997387SRobert.Gordon@Sun.COM * large enough, but registration is deferred until we write 13007387SRobert.Gordon@Sun.COM * the buffer back to (NFS) client using RDMA_WRITE. 13017387SRobert.Gordon@Sun.COM */ 13027387SRobert.Gordon@Sun.COM iov->iov_base = (caddr_t)(uintptr_t)wlist->w.c_saddr; 13037387SRobert.Gordon@Sun.COM iov->iov_len = tlen; 13047387SRobert.Gordon@Sun.COM 13057387SRobert.Gordon@Sun.COM return (TRUE); 13067387SRobert.Gordon@Sun.COM } 13079348SSiddheshwar.Mahesh@Sun.COM 13089348SSiddheshwar.Mahesh@Sun.COM /* 13099348SSiddheshwar.Mahesh@Sun.COM * routine to setup the read chunk lists 13109348SSiddheshwar.Mahesh@Sun.COM */ 13119348SSiddheshwar.Mahesh@Sun.COM 13129348SSiddheshwar.Mahesh@Sun.COM int 13139348SSiddheshwar.Mahesh@Sun.COM rdma_setup_read_chunks(struct clist *wcl, uint32_t count, int *wcl_len) 13149348SSiddheshwar.Mahesh@Sun.COM { 13159348SSiddheshwar.Mahesh@Sun.COM int data_len, avail_len; 13169348SSiddheshwar.Mahesh@Sun.COM uint_t round_len; 13179348SSiddheshwar.Mahesh@Sun.COM 13189348SSiddheshwar.Mahesh@Sun.COM data_len = avail_len = 0; 13199348SSiddheshwar.Mahesh@Sun.COM 13209348SSiddheshwar.Mahesh@Sun.COM while (wcl != NULL && count > 0) { 13219348SSiddheshwar.Mahesh@Sun.COM if (wcl->c_dmemhandle.mrc_rmr == 0) 13229348SSiddheshwar.Mahesh@Sun.COM break; 13239348SSiddheshwar.Mahesh@Sun.COM 13249348SSiddheshwar.Mahesh@Sun.COM if (wcl->c_len < count) { 13259348SSiddheshwar.Mahesh@Sun.COM data_len += wcl->c_len; 13269348SSiddheshwar.Mahesh@Sun.COM avail_len = 0; 13279348SSiddheshwar.Mahesh@Sun.COM } else { 13289348SSiddheshwar.Mahesh@Sun.COM data_len += count; 13299348SSiddheshwar.Mahesh@Sun.COM avail_len = wcl->c_len - count; 13309348SSiddheshwar.Mahesh@Sun.COM wcl->c_len = count; 13319348SSiddheshwar.Mahesh@Sun.COM } 13329348SSiddheshwar.Mahesh@Sun.COM count -= wcl->c_len; 13339348SSiddheshwar.Mahesh@Sun.COM 13349348SSiddheshwar.Mahesh@Sun.COM if (count == 0) 13359348SSiddheshwar.Mahesh@Sun.COM break; 13369348SSiddheshwar.Mahesh@Sun.COM 13379348SSiddheshwar.Mahesh@Sun.COM wcl = wcl->c_next; 13389348SSiddheshwar.Mahesh@Sun.COM } 13399348SSiddheshwar.Mahesh@Sun.COM 13409348SSiddheshwar.Mahesh@Sun.COM /* 13419348SSiddheshwar.Mahesh@Sun.COM * MUST fail if there are still more data 13429348SSiddheshwar.Mahesh@Sun.COM */ 13439348SSiddheshwar.Mahesh@Sun.COM if (count > 0) { 13449348SSiddheshwar.Mahesh@Sun.COM DTRACE_PROBE2(krpc__e__rdma_setup_read_chunks_clist_len, 13459348SSiddheshwar.Mahesh@Sun.COM int, data_len, int, count); 13469348SSiddheshwar.Mahesh@Sun.COM return (FALSE); 13479348SSiddheshwar.Mahesh@Sun.COM } 13489348SSiddheshwar.Mahesh@Sun.COM 13499348SSiddheshwar.Mahesh@Sun.COM /* 13509348SSiddheshwar.Mahesh@Sun.COM * Round up the last chunk to 4-byte boundary 13519348SSiddheshwar.Mahesh@Sun.COM */ 13529348SSiddheshwar.Mahesh@Sun.COM *wcl_len = roundup(data_len, BYTES_PER_XDR_UNIT); 13539348SSiddheshwar.Mahesh@Sun.COM round_len = *wcl_len - data_len; 13549348SSiddheshwar.Mahesh@Sun.COM 13559348SSiddheshwar.Mahesh@Sun.COM if (round_len) { 13569348SSiddheshwar.Mahesh@Sun.COM 13579348SSiddheshwar.Mahesh@Sun.COM /* 13589348SSiddheshwar.Mahesh@Sun.COM * If there is space in the current chunk, 13599348SSiddheshwar.Mahesh@Sun.COM * add the roundup to the chunk. 13609348SSiddheshwar.Mahesh@Sun.COM */ 13619348SSiddheshwar.Mahesh@Sun.COM if (avail_len >= round_len) { 13629348SSiddheshwar.Mahesh@Sun.COM wcl->c_len += round_len; 13639348SSiddheshwar.Mahesh@Sun.COM } else { 13649348SSiddheshwar.Mahesh@Sun.COM /* 13659348SSiddheshwar.Mahesh@Sun.COM * try the next one. 13669348SSiddheshwar.Mahesh@Sun.COM */ 13679348SSiddheshwar.Mahesh@Sun.COM wcl = wcl->c_next; 13689348SSiddheshwar.Mahesh@Sun.COM if ((wcl == NULL) || (wcl->c_len < round_len)) { 13699348SSiddheshwar.Mahesh@Sun.COM DTRACE_PROBE1( 13709348SSiddheshwar.Mahesh@Sun.COM krpc__e__rdma_setup_read_chunks_rndup, 13719348SSiddheshwar.Mahesh@Sun.COM int, round_len); 13729348SSiddheshwar.Mahesh@Sun.COM return (FALSE); 13739348SSiddheshwar.Mahesh@Sun.COM } 13749348SSiddheshwar.Mahesh@Sun.COM wcl->c_len = round_len; 13759348SSiddheshwar.Mahesh@Sun.COM } 13769348SSiddheshwar.Mahesh@Sun.COM } 13779348SSiddheshwar.Mahesh@Sun.COM 13789348SSiddheshwar.Mahesh@Sun.COM wcl = wcl->c_next; 13799348SSiddheshwar.Mahesh@Sun.COM 13809348SSiddheshwar.Mahesh@Sun.COM /* 13819348SSiddheshwar.Mahesh@Sun.COM * Make rest of the chunks 0-len 13829348SSiddheshwar.Mahesh@Sun.COM */ 13839348SSiddheshwar.Mahesh@Sun.COM 13849348SSiddheshwar.Mahesh@Sun.COM clist_zero_len(wcl); 13859348SSiddheshwar.Mahesh@Sun.COM 13869348SSiddheshwar.Mahesh@Sun.COM return (TRUE); 13879348SSiddheshwar.Mahesh@Sun.COM } 1388