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 #include <sys/param.h> 340Sstevel@tonic-gate #include <sys/types.h> 350Sstevel@tonic-gate #include <sys/user.h> 360Sstevel@tonic-gate #include <sys/systm.h> 370Sstevel@tonic-gate #include <sys/sysmacros.h> 380Sstevel@tonic-gate #include <sys/errno.h> 390Sstevel@tonic-gate #include <sys/kmem.h> 400Sstevel@tonic-gate #include <sys/debug.h> 410Sstevel@tonic-gate #include <sys/systm.h> 420Sstevel@tonic-gate #include <sys/kstat.h> 430Sstevel@tonic-gate #include <sys/t_lock.h> 440Sstevel@tonic-gate #include <sys/ddi.h> 450Sstevel@tonic-gate #include <sys/cmn_err.h> 460Sstevel@tonic-gate #include <sys/time.h> 470Sstevel@tonic-gate #include <sys/isa_defs.h> 480Sstevel@tonic-gate #include <sys/zone.h> 497387SRobert.Gordon@Sun.COM #include <sys/sdt.h> 500Sstevel@tonic-gate 510Sstevel@tonic-gate #include <rpc/types.h> 520Sstevel@tonic-gate #include <rpc/xdr.h> 530Sstevel@tonic-gate #include <rpc/auth.h> 540Sstevel@tonic-gate #include <rpc/clnt.h> 550Sstevel@tonic-gate #include <rpc/rpc_msg.h> 560Sstevel@tonic-gate #include <rpc/rpc_rdma.h> 577387SRobert.Gordon@Sun.COM #include <nfs/nfs.h> 587387SRobert.Gordon@Sun.COM #include <nfs/nfs4_kprot.h> 590Sstevel@tonic-gate 607387SRobert.Gordon@Sun.COM static uint32_t rdma_bufs_rqst = RDMA_BUFS_RQST; 617387SRobert.Gordon@Sun.COM 627387SRobert.Gordon@Sun.COM static int clnt_compose_rpcmsg(CLIENT *, rpcproc_t, rdma_buf_t *, 637387SRobert.Gordon@Sun.COM XDR *, xdrproc_t, caddr_t); 647387SRobert.Gordon@Sun.COM static int clnt_compose_rdma_header(CONN *, CLIENT *, rdma_buf_t *, 657387SRobert.Gordon@Sun.COM XDR **, uint_t *); 667387SRobert.Gordon@Sun.COM static int clnt_setup_rlist(CONN *, XDR *, XDR *); 67*9348SSiddheshwar.Mahesh@Sun.COM static int clnt_setup_wlist(CONN *, XDR *, XDR *, rdma_buf_t *); 687387SRobert.Gordon@Sun.COM static int clnt_setup_long_reply(CONN *, struct clist **, uint_t); 697387SRobert.Gordon@Sun.COM static void clnt_check_credit(CONN *); 707387SRobert.Gordon@Sun.COM static void clnt_return_credit(CONN *); 717387SRobert.Gordon@Sun.COM static void clnt_decode_long_reply(CONN *, struct clist *, 727387SRobert.Gordon@Sun.COM struct clist *, XDR *, XDR **, struct clist *, 737387SRobert.Gordon@Sun.COM struct clist *, uint_t, uint_t); 747387SRobert.Gordon@Sun.COM 757387SRobert.Gordon@Sun.COM static void clnt_update_credit(CONN *, uint32_t); 760Sstevel@tonic-gate 770Sstevel@tonic-gate static enum clnt_stat clnt_rdma_kcallit(CLIENT *, rpcproc_t, xdrproc_t, 780Sstevel@tonic-gate caddr_t, xdrproc_t, caddr_t, struct timeval); 790Sstevel@tonic-gate static void clnt_rdma_kabort(CLIENT *); 800Sstevel@tonic-gate static void clnt_rdma_kerror(CLIENT *, struct rpc_err *); 810Sstevel@tonic-gate static bool_t clnt_rdma_kfreeres(CLIENT *, xdrproc_t, caddr_t); 820Sstevel@tonic-gate static void clnt_rdma_kdestroy(CLIENT *); 830Sstevel@tonic-gate static bool_t clnt_rdma_kcontrol(CLIENT *, int, char *); 840Sstevel@tonic-gate static int clnt_rdma_ksettimers(CLIENT *, struct rpc_timers *, 850Sstevel@tonic-gate struct rpc_timers *, int, void(*)(int, int, caddr_t), caddr_t, uint32_t); 860Sstevel@tonic-gate 870Sstevel@tonic-gate /* 880Sstevel@tonic-gate * Operations vector for RDMA based RPC 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate static struct clnt_ops rdma_clnt_ops = { 910Sstevel@tonic-gate clnt_rdma_kcallit, /* do rpc call */ 920Sstevel@tonic-gate clnt_rdma_kabort, /* abort call */ 930Sstevel@tonic-gate clnt_rdma_kerror, /* return error status */ 940Sstevel@tonic-gate clnt_rdma_kfreeres, /* free results */ 950Sstevel@tonic-gate clnt_rdma_kdestroy, /* destroy rpc handle */ 960Sstevel@tonic-gate clnt_rdma_kcontrol, /* the ioctl() of rpc */ 970Sstevel@tonic-gate clnt_rdma_ksettimers, /* set retry timers */ 980Sstevel@tonic-gate }; 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * The size of the preserialized RPC header information. 1020Sstevel@tonic-gate */ 1030Sstevel@tonic-gate #define CKU_HDRSIZE 20 1047387SRobert.Gordon@Sun.COM #define CLNT_RDMA_SUCCESS 0 1057387SRobert.Gordon@Sun.COM #define CLNT_RDMA_FAIL (-1) 1067387SRobert.Gordon@Sun.COM 1077387SRobert.Gordon@Sun.COM #define AUTH_REFRESH_COUNT 2 1087387SRobert.Gordon@Sun.COM 1097387SRobert.Gordon@Sun.COM #define IS_RPCSEC_GSS(authh) \ 1107387SRobert.Gordon@Sun.COM (authh->cl_auth->ah_cred.oa_flavor == RPCSEC_GSS) 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate /* 1130Sstevel@tonic-gate * Per RPC RDMA endpoint details 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate typedef struct cku_private { 1160Sstevel@tonic-gate CLIENT cku_client; /* client handle */ 1170Sstevel@tonic-gate rdma_mod_t *cku_rd_mod; /* underlying RDMA mod */ 1180Sstevel@tonic-gate void *cku_rd_handle; /* underlying RDMA device */ 1190Sstevel@tonic-gate struct netbuf cku_addr; /* remote netbuf address */ 1200Sstevel@tonic-gate int cku_addrfmly; /* for finding addr_type */ 1210Sstevel@tonic-gate struct rpc_err cku_err; /* error status */ 1220Sstevel@tonic-gate struct cred *cku_cred; /* credentials */ 1230Sstevel@tonic-gate XDR cku_outxdr; /* xdr stream for output */ 1240Sstevel@tonic-gate uint32_t cku_outsz; 1250Sstevel@tonic-gate XDR cku_inxdr; /* xdr stream for input */ 1260Sstevel@tonic-gate char cku_rpchdr[CKU_HDRSIZE+4]; /* rpc header */ 1270Sstevel@tonic-gate uint32_t cku_xid; /* current XID */ 1280Sstevel@tonic-gate } cku_private_t; 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate #define CLNT_RDMA_DELAY 10 /* secs to delay after a connection failure */ 1310Sstevel@tonic-gate static int clnt_rdma_min_delay = CLNT_RDMA_DELAY; 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate struct { 1340Sstevel@tonic-gate kstat_named_t rccalls; 1350Sstevel@tonic-gate kstat_named_t rcbadcalls; 1360Sstevel@tonic-gate kstat_named_t rcbadxids; 1370Sstevel@tonic-gate kstat_named_t rctimeouts; 1380Sstevel@tonic-gate kstat_named_t rcnewcreds; 1390Sstevel@tonic-gate kstat_named_t rcbadverfs; 1400Sstevel@tonic-gate kstat_named_t rctimers; 1410Sstevel@tonic-gate kstat_named_t rccantconn; 1420Sstevel@tonic-gate kstat_named_t rcnomem; 1430Sstevel@tonic-gate kstat_named_t rcintrs; 1440Sstevel@tonic-gate kstat_named_t rclongrpcs; 1450Sstevel@tonic-gate } rdmarcstat = { 1460Sstevel@tonic-gate { "calls", KSTAT_DATA_UINT64 }, 1470Sstevel@tonic-gate { "badcalls", KSTAT_DATA_UINT64 }, 1480Sstevel@tonic-gate { "badxids", KSTAT_DATA_UINT64 }, 1490Sstevel@tonic-gate { "timeouts", KSTAT_DATA_UINT64 }, 1500Sstevel@tonic-gate { "newcreds", KSTAT_DATA_UINT64 }, 1510Sstevel@tonic-gate { "badverfs", KSTAT_DATA_UINT64 }, 1520Sstevel@tonic-gate { "timers", KSTAT_DATA_UINT64 }, 1530Sstevel@tonic-gate { "cantconn", KSTAT_DATA_UINT64 }, 1540Sstevel@tonic-gate { "nomem", KSTAT_DATA_UINT64 }, 1550Sstevel@tonic-gate { "interrupts", KSTAT_DATA_UINT64 }, 1560Sstevel@tonic-gate { "longrpc", KSTAT_DATA_UINT64 } 1570Sstevel@tonic-gate }; 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate kstat_named_t *rdmarcstat_ptr = (kstat_named_t *)&rdmarcstat; 1600Sstevel@tonic-gate uint_t rdmarcstat_ndata = sizeof (rdmarcstat) / sizeof (kstat_named_t); 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate #ifdef DEBUG 1630Sstevel@tonic-gate int rdma_clnt_debug = 0; 1640Sstevel@tonic-gate #endif 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate #ifdef accurate_stats 1670Sstevel@tonic-gate extern kmutex_t rdmarcstat_lock; /* mutex for rcstat updates */ 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate #define RCSTAT_INCR(x) \ 1700Sstevel@tonic-gate mutex_enter(&rdmarcstat_lock); \ 1710Sstevel@tonic-gate rdmarcstat.x.value.ui64++; \ 1720Sstevel@tonic-gate mutex_exit(&rdmarcstat_lock); 1730Sstevel@tonic-gate #else 1740Sstevel@tonic-gate #define RCSTAT_INCR(x) \ 1750Sstevel@tonic-gate rdmarcstat.x.value.ui64++; 1760Sstevel@tonic-gate #endif 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate #define ptoh(p) (&((p)->cku_client)) 1790Sstevel@tonic-gate #define htop(h) ((cku_private_t *)((h)->cl_private)) 1800Sstevel@tonic-gate 1817387SRobert.Gordon@Sun.COM uint_t 1827387SRobert.Gordon@Sun.COM calc_length(uint_t len) 1837387SRobert.Gordon@Sun.COM { 1847387SRobert.Gordon@Sun.COM len = RNDUP(len); 1857387SRobert.Gordon@Sun.COM 1867387SRobert.Gordon@Sun.COM if (len <= 64 * 1024) { 1877387SRobert.Gordon@Sun.COM if (len > 32 * 1024) { 1887387SRobert.Gordon@Sun.COM len = 64 * 1024; 1897387SRobert.Gordon@Sun.COM } else { 1907387SRobert.Gordon@Sun.COM if (len > 16 * 1024) { 1917387SRobert.Gordon@Sun.COM len = 32 * 1024; 1927387SRobert.Gordon@Sun.COM } else { 1937387SRobert.Gordon@Sun.COM if (len > 8 * 1024) { 1947387SRobert.Gordon@Sun.COM len = 16 * 1024; 1957387SRobert.Gordon@Sun.COM } else { 1967387SRobert.Gordon@Sun.COM len = 8 * 1024; 1977387SRobert.Gordon@Sun.COM } 1987387SRobert.Gordon@Sun.COM } 1997387SRobert.Gordon@Sun.COM } 2007387SRobert.Gordon@Sun.COM } 2017387SRobert.Gordon@Sun.COM return (len); 2027387SRobert.Gordon@Sun.COM } 2030Sstevel@tonic-gate int 2040Sstevel@tonic-gate clnt_rdma_kcreate(char *proto, void *handle, struct netbuf *raddr, int family, 2050Sstevel@tonic-gate rpcprog_t pgm, rpcvers_t vers, struct cred *cred, CLIENT **cl) 2060Sstevel@tonic-gate { 2070Sstevel@tonic-gate CLIENT *h; 2080Sstevel@tonic-gate struct cku_private *p; 2090Sstevel@tonic-gate struct rpc_msg call_msg; 2100Sstevel@tonic-gate rdma_registry_t *rp; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate ASSERT(INGLOBALZONE(curproc)); 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate if (cl == NULL) 2150Sstevel@tonic-gate return (EINVAL); 2160Sstevel@tonic-gate *cl = NULL; 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate p = kmem_zalloc(sizeof (*p), KM_SLEEP); 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate /* 2210Sstevel@tonic-gate * Find underlying RDMATF plugin 2220Sstevel@tonic-gate */ 2230Sstevel@tonic-gate rw_enter(&rdma_lock, RW_READER); 2240Sstevel@tonic-gate rp = rdma_mod_head; 2250Sstevel@tonic-gate while (rp != NULL) { 2260Sstevel@tonic-gate if (strcmp(rp->r_mod->rdma_api, proto)) 2270Sstevel@tonic-gate rp = rp->r_next; 2280Sstevel@tonic-gate else { 2290Sstevel@tonic-gate p->cku_rd_mod = rp->r_mod; 2300Sstevel@tonic-gate p->cku_rd_handle = handle; 2310Sstevel@tonic-gate break; 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate rw_exit(&rdma_lock); 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate if (p->cku_rd_mod == NULL) { 2370Sstevel@tonic-gate /* 2380Sstevel@tonic-gate * Should not happen. 2390Sstevel@tonic-gate * No matching RDMATF plugin. 2400Sstevel@tonic-gate */ 2410Sstevel@tonic-gate kmem_free(p, sizeof (struct cku_private)); 2420Sstevel@tonic-gate return (EINVAL); 2430Sstevel@tonic-gate } 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate h = ptoh(p); 2460Sstevel@tonic-gate h->cl_ops = &rdma_clnt_ops; 2470Sstevel@tonic-gate h->cl_private = (caddr_t)p; 2480Sstevel@tonic-gate h->cl_auth = authkern_create(); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate /* call message, just used to pre-serialize below */ 2510Sstevel@tonic-gate call_msg.rm_xid = 0; 2520Sstevel@tonic-gate call_msg.rm_direction = CALL; 2530Sstevel@tonic-gate call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION; 2540Sstevel@tonic-gate call_msg.rm_call.cb_prog = pgm; 2550Sstevel@tonic-gate call_msg.rm_call.cb_vers = vers; 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate xdrmem_create(&p->cku_outxdr, p->cku_rpchdr, CKU_HDRSIZE, XDR_ENCODE); 2580Sstevel@tonic-gate /* pre-serialize call message header */ 2590Sstevel@tonic-gate if (!xdr_callhdr(&p->cku_outxdr, &call_msg)) { 2600Sstevel@tonic-gate XDR_DESTROY(&p->cku_outxdr); 2610Sstevel@tonic-gate auth_destroy(h->cl_auth); 2620Sstevel@tonic-gate kmem_free(p, sizeof (struct cku_private)); 2630Sstevel@tonic-gate return (EINVAL); 2640Sstevel@tonic-gate } 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /* 2670Sstevel@tonic-gate * Set up the rpc information 2680Sstevel@tonic-gate */ 2690Sstevel@tonic-gate p->cku_cred = cred; 2700Sstevel@tonic-gate p->cku_addr.buf = kmem_zalloc(raddr->maxlen, KM_SLEEP); 2710Sstevel@tonic-gate p->cku_addr.maxlen = raddr->maxlen; 2720Sstevel@tonic-gate p->cku_addr.len = raddr->len; 2730Sstevel@tonic-gate bcopy(raddr->buf, p->cku_addr.buf, raddr->len); 2740Sstevel@tonic-gate p->cku_addrfmly = family; 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate *cl = h; 2770Sstevel@tonic-gate return (0); 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate static void 2810Sstevel@tonic-gate clnt_rdma_kdestroy(CLIENT *h) 2820Sstevel@tonic-gate { 2830Sstevel@tonic-gate struct cku_private *p = htop(h); 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate kmem_free(p->cku_addr.buf, p->cku_addr.maxlen); 2860Sstevel@tonic-gate kmem_free(p, sizeof (*p)); 2870Sstevel@tonic-gate } 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate void 2900Sstevel@tonic-gate clnt_rdma_kinit(CLIENT *h, char *proto, void *handle, struct netbuf *raddr, 2910Sstevel@tonic-gate struct cred *cred) 2920Sstevel@tonic-gate { 2930Sstevel@tonic-gate struct cku_private *p = htop(h); 2940Sstevel@tonic-gate rdma_registry_t *rp; 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate ASSERT(INGLOBALZONE(curproc)); 2970Sstevel@tonic-gate /* 2980Sstevel@tonic-gate * Find underlying RDMATF plugin 2990Sstevel@tonic-gate */ 3000Sstevel@tonic-gate p->cku_rd_mod = NULL; 3010Sstevel@tonic-gate rw_enter(&rdma_lock, RW_READER); 3020Sstevel@tonic-gate rp = rdma_mod_head; 3030Sstevel@tonic-gate while (rp != NULL) { 3040Sstevel@tonic-gate if (strcmp(rp->r_mod->rdma_api, proto)) 3050Sstevel@tonic-gate rp = rp->r_next; 3060Sstevel@tonic-gate else { 3070Sstevel@tonic-gate p->cku_rd_mod = rp->r_mod; 3080Sstevel@tonic-gate p->cku_rd_handle = handle; 3090Sstevel@tonic-gate break; 3100Sstevel@tonic-gate } 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate } 3130Sstevel@tonic-gate rw_exit(&rdma_lock); 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate /* 3160Sstevel@tonic-gate * Set up the rpc information 3170Sstevel@tonic-gate */ 3180Sstevel@tonic-gate p->cku_cred = cred; 3190Sstevel@tonic-gate p->cku_xid = 0; 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate if (p->cku_addr.maxlen < raddr->len) { 3220Sstevel@tonic-gate if (p->cku_addr.maxlen != 0 && p->cku_addr.buf != NULL) 3230Sstevel@tonic-gate kmem_free(p->cku_addr.buf, p->cku_addr.maxlen); 3240Sstevel@tonic-gate p->cku_addr.buf = kmem_zalloc(raddr->maxlen, KM_SLEEP); 3250Sstevel@tonic-gate p->cku_addr.maxlen = raddr->maxlen; 3260Sstevel@tonic-gate } 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate p->cku_addr.len = raddr->len; 3290Sstevel@tonic-gate bcopy(raddr->buf, p->cku_addr.buf, raddr->len); 3300Sstevel@tonic-gate h->cl_ops = &rdma_clnt_ops; 3310Sstevel@tonic-gate } 3320Sstevel@tonic-gate 3337387SRobert.Gordon@Sun.COM static int 3347387SRobert.Gordon@Sun.COM clnt_compose_rpcmsg(CLIENT *h, rpcproc_t procnum, 3357387SRobert.Gordon@Sun.COM rdma_buf_t *rpcmsg, XDR *xdrs, 3367387SRobert.Gordon@Sun.COM xdrproc_t xdr_args, caddr_t argsp) 3377387SRobert.Gordon@Sun.COM { 3387387SRobert.Gordon@Sun.COM cku_private_t *p = htop(h); 3397387SRobert.Gordon@Sun.COM 3407387SRobert.Gordon@Sun.COM if (h->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) { 3417387SRobert.Gordon@Sun.COM /* 3427387SRobert.Gordon@Sun.COM * Copy in the preserialized RPC header 3437387SRobert.Gordon@Sun.COM * information. 3447387SRobert.Gordon@Sun.COM */ 3457387SRobert.Gordon@Sun.COM bcopy(p->cku_rpchdr, rpcmsg->addr, CKU_HDRSIZE); 3467387SRobert.Gordon@Sun.COM 3477387SRobert.Gordon@Sun.COM /* 3487387SRobert.Gordon@Sun.COM * transaction id is the 1st thing in the output 3497387SRobert.Gordon@Sun.COM * buffer. 3507387SRobert.Gordon@Sun.COM */ 3517387SRobert.Gordon@Sun.COM /* LINTED pointer alignment */ 3527387SRobert.Gordon@Sun.COM (*(uint32_t *)(rpcmsg->addr)) = p->cku_xid; 3537387SRobert.Gordon@Sun.COM 3547387SRobert.Gordon@Sun.COM /* Skip the preserialized stuff. */ 3557387SRobert.Gordon@Sun.COM XDR_SETPOS(xdrs, CKU_HDRSIZE); 3567387SRobert.Gordon@Sun.COM 3577387SRobert.Gordon@Sun.COM /* Serialize dynamic stuff into the output buffer. */ 3587387SRobert.Gordon@Sun.COM if ((!XDR_PUTINT32(xdrs, (int32_t *)&procnum)) || 3597387SRobert.Gordon@Sun.COM (!AUTH_MARSHALL(h->cl_auth, xdrs, p->cku_cred)) || 3607387SRobert.Gordon@Sun.COM (!(*xdr_args)(xdrs, argsp))) { 3617387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__clntrdma__rpcmsg__dynargs); 3627387SRobert.Gordon@Sun.COM return (CLNT_RDMA_FAIL); 3637387SRobert.Gordon@Sun.COM } 3647387SRobert.Gordon@Sun.COM p->cku_outsz = XDR_GETPOS(xdrs); 3657387SRobert.Gordon@Sun.COM } else { 3667387SRobert.Gordon@Sun.COM uint32_t *uproc = (uint32_t *)&p->cku_rpchdr[CKU_HDRSIZE]; 3677387SRobert.Gordon@Sun.COM IXDR_PUT_U_INT32(uproc, procnum); 3687387SRobert.Gordon@Sun.COM (*(uint32_t *)(&p->cku_rpchdr[0])) = p->cku_xid; 3697387SRobert.Gordon@Sun.COM XDR_SETPOS(xdrs, 0); 3707387SRobert.Gordon@Sun.COM 3717387SRobert.Gordon@Sun.COM /* Serialize the procedure number and the arguments. */ 3727387SRobert.Gordon@Sun.COM if (!AUTH_WRAP(h->cl_auth, (caddr_t)p->cku_rpchdr, 3737387SRobert.Gordon@Sun.COM CKU_HDRSIZE+4, xdrs, xdr_args, argsp)) { 3747387SRobert.Gordon@Sun.COM if (rpcmsg->addr != xdrs->x_base) { 3757387SRobert.Gordon@Sun.COM rpcmsg->addr = xdrs->x_base; 3767387SRobert.Gordon@Sun.COM rpcmsg->len = xdr_getbufsize(xdrs); 3777387SRobert.Gordon@Sun.COM } 3787387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__clntrdma__rpcmsg__procnum); 3797387SRobert.Gordon@Sun.COM return (CLNT_RDMA_FAIL); 3807387SRobert.Gordon@Sun.COM } 3817387SRobert.Gordon@Sun.COM /* 3827387SRobert.Gordon@Sun.COM * If we had to allocate a new buffer while encoding 3837387SRobert.Gordon@Sun.COM * then update the addr and len. 3847387SRobert.Gordon@Sun.COM */ 3857387SRobert.Gordon@Sun.COM if (rpcmsg->addr != xdrs->x_base) { 3867387SRobert.Gordon@Sun.COM rpcmsg->addr = xdrs->x_base; 3877387SRobert.Gordon@Sun.COM rpcmsg->len = xdr_getbufsize(xdrs); 3887387SRobert.Gordon@Sun.COM } 3897387SRobert.Gordon@Sun.COM 3907387SRobert.Gordon@Sun.COM p->cku_outsz = XDR_GETPOS(xdrs); 3917387SRobert.Gordon@Sun.COM DTRACE_PROBE1(krpc__i__compose__size__sec, int, p->cku_outsz) 3927387SRobert.Gordon@Sun.COM } 3937387SRobert.Gordon@Sun.COM 3947387SRobert.Gordon@Sun.COM return (CLNT_RDMA_SUCCESS); 3957387SRobert.Gordon@Sun.COM } 3967387SRobert.Gordon@Sun.COM 3977387SRobert.Gordon@Sun.COM static int 3987387SRobert.Gordon@Sun.COM clnt_compose_rdma_header(CONN *conn, CLIENT *h, rdma_buf_t *clmsg, 3997387SRobert.Gordon@Sun.COM XDR **xdrs, uint_t *op) 4007387SRobert.Gordon@Sun.COM { 4017387SRobert.Gordon@Sun.COM cku_private_t *p = htop(h); 4027387SRobert.Gordon@Sun.COM uint_t vers; 4037387SRobert.Gordon@Sun.COM uint32_t rdma_credit = rdma_bufs_rqst; 4047387SRobert.Gordon@Sun.COM 4057387SRobert.Gordon@Sun.COM vers = RPCRDMA_VERS; 4067387SRobert.Gordon@Sun.COM clmsg->type = SEND_BUFFER; 4077387SRobert.Gordon@Sun.COM 4087387SRobert.Gordon@Sun.COM if (rdma_buf_alloc(conn, clmsg)) { 4097387SRobert.Gordon@Sun.COM return (CLNT_RDMA_FAIL); 4107387SRobert.Gordon@Sun.COM } 4117387SRobert.Gordon@Sun.COM 4127387SRobert.Gordon@Sun.COM *xdrs = &p->cku_outxdr; 4137387SRobert.Gordon@Sun.COM xdrmem_create(*xdrs, clmsg->addr, clmsg->len, XDR_ENCODE); 4147387SRobert.Gordon@Sun.COM 4157387SRobert.Gordon@Sun.COM (*(uint32_t *)clmsg->addr) = p->cku_xid; 4167387SRobert.Gordon@Sun.COM XDR_SETPOS(*xdrs, sizeof (uint32_t)); 4177387SRobert.Gordon@Sun.COM (void) xdr_u_int(*xdrs, &vers); 4187387SRobert.Gordon@Sun.COM (void) xdr_u_int(*xdrs, &rdma_credit); 4197387SRobert.Gordon@Sun.COM (void) xdr_u_int(*xdrs, op); 4207387SRobert.Gordon@Sun.COM 4217387SRobert.Gordon@Sun.COM return (CLNT_RDMA_SUCCESS); 4227387SRobert.Gordon@Sun.COM } 4237387SRobert.Gordon@Sun.COM 4247387SRobert.Gordon@Sun.COM /* 4257387SRobert.Gordon@Sun.COM * If xp_cl is NULL value, then the RPC payload will NOT carry 4267387SRobert.Gordon@Sun.COM * an RDMA READ chunk list, in this case we insert FALSE into 4277387SRobert.Gordon@Sun.COM * the XDR stream. Otherwise we use the clist and RDMA register 4287387SRobert.Gordon@Sun.COM * the memory and encode the clist into the outbound XDR stream. 4297387SRobert.Gordon@Sun.COM */ 4307387SRobert.Gordon@Sun.COM static int 4317387SRobert.Gordon@Sun.COM clnt_setup_rlist(CONN *conn, XDR *xdrs, XDR *call_xdrp) 4327387SRobert.Gordon@Sun.COM { 4337387SRobert.Gordon@Sun.COM int status; 4347387SRobert.Gordon@Sun.COM struct clist *rclp; 4357387SRobert.Gordon@Sun.COM int32_t xdr_flag = XDR_RDMA_RLIST_REG; 4367387SRobert.Gordon@Sun.COM 4377387SRobert.Gordon@Sun.COM XDR_CONTROL(call_xdrp, XDR_RDMA_GET_RLIST, &rclp); 4387387SRobert.Gordon@Sun.COM 4397387SRobert.Gordon@Sun.COM if (rclp != NULL) { 4407387SRobert.Gordon@Sun.COM status = clist_register(conn, rclp, CLIST_REG_SOURCE); 4417387SRobert.Gordon@Sun.COM if (status != RDMA_SUCCESS) { 4427387SRobert.Gordon@Sun.COM return (CLNT_RDMA_FAIL); 4437387SRobert.Gordon@Sun.COM } 4447387SRobert.Gordon@Sun.COM XDR_CONTROL(call_xdrp, XDR_RDMA_SET_FLAGS, &xdr_flag); 4457387SRobert.Gordon@Sun.COM } 4467387SRobert.Gordon@Sun.COM (void) xdr_do_clist(xdrs, &rclp); 4477387SRobert.Gordon@Sun.COM 4487387SRobert.Gordon@Sun.COM return (CLNT_RDMA_SUCCESS); 4497387SRobert.Gordon@Sun.COM } 4507387SRobert.Gordon@Sun.COM 4517387SRobert.Gordon@Sun.COM /* 4527387SRobert.Gordon@Sun.COM * If xp_wcl is NULL value, then the RPC payload will NOT carry 4537387SRobert.Gordon@Sun.COM * an RDMA WRITE chunk list, in this case we insert FALSE into 4547387SRobert.Gordon@Sun.COM * the XDR stream. Otherwise we use the clist and RDMA register 4557387SRobert.Gordon@Sun.COM * the memory and encode the clist into the outbound XDR stream. 4567387SRobert.Gordon@Sun.COM */ 4577387SRobert.Gordon@Sun.COM static int 458*9348SSiddheshwar.Mahesh@Sun.COM clnt_setup_wlist(CONN *conn, XDR *xdrs, XDR *call_xdrp, rdma_buf_t *rndbuf) 4597387SRobert.Gordon@Sun.COM { 4607387SRobert.Gordon@Sun.COM int status; 461*9348SSiddheshwar.Mahesh@Sun.COM struct clist *wlist, *rndcl; 462*9348SSiddheshwar.Mahesh@Sun.COM int wlen, rndlen; 4637387SRobert.Gordon@Sun.COM int32_t xdr_flag = XDR_RDMA_WLIST_REG; 4647387SRobert.Gordon@Sun.COM 4657387SRobert.Gordon@Sun.COM XDR_CONTROL(call_xdrp, XDR_RDMA_GET_WLIST, &wlist); 4667387SRobert.Gordon@Sun.COM 4677387SRobert.Gordon@Sun.COM if (wlist != NULL) { 468*9348SSiddheshwar.Mahesh@Sun.COM /* 469*9348SSiddheshwar.Mahesh@Sun.COM * If we are sending a non 4-byte alligned length 470*9348SSiddheshwar.Mahesh@Sun.COM * the server will roundup the length to 4-byte 471*9348SSiddheshwar.Mahesh@Sun.COM * boundary. In such a case, a trailing chunk is 472*9348SSiddheshwar.Mahesh@Sun.COM * added to take any spill over roundup bytes. 473*9348SSiddheshwar.Mahesh@Sun.COM */ 474*9348SSiddheshwar.Mahesh@Sun.COM wlen = clist_len(wlist); 475*9348SSiddheshwar.Mahesh@Sun.COM rndlen = (roundup(wlen, BYTES_PER_XDR_UNIT) - wlen); 476*9348SSiddheshwar.Mahesh@Sun.COM if (rndlen) { 477*9348SSiddheshwar.Mahesh@Sun.COM rndcl = clist_alloc(); 478*9348SSiddheshwar.Mahesh@Sun.COM /* 479*9348SSiddheshwar.Mahesh@Sun.COM * calc_length() will allocate a PAGESIZE 480*9348SSiddheshwar.Mahesh@Sun.COM * buffer below. 481*9348SSiddheshwar.Mahesh@Sun.COM */ 482*9348SSiddheshwar.Mahesh@Sun.COM rndcl->c_len = calc_length(rndlen); 483*9348SSiddheshwar.Mahesh@Sun.COM rndcl->rb_longbuf.type = RDMA_LONG_BUFFER; 484*9348SSiddheshwar.Mahesh@Sun.COM rndcl->rb_longbuf.len = rndcl->c_len; 485*9348SSiddheshwar.Mahesh@Sun.COM if (rdma_buf_alloc(conn, &rndcl->rb_longbuf)) { 486*9348SSiddheshwar.Mahesh@Sun.COM clist_free(rndcl); 487*9348SSiddheshwar.Mahesh@Sun.COM return (CLNT_RDMA_FAIL); 488*9348SSiddheshwar.Mahesh@Sun.COM } 489*9348SSiddheshwar.Mahesh@Sun.COM 490*9348SSiddheshwar.Mahesh@Sun.COM /* Roundup buffer freed back in caller */ 491*9348SSiddheshwar.Mahesh@Sun.COM *rndbuf = rndcl->rb_longbuf; 492*9348SSiddheshwar.Mahesh@Sun.COM 493*9348SSiddheshwar.Mahesh@Sun.COM rndcl->u.c_daddr3 = rndcl->rb_longbuf.addr; 494*9348SSiddheshwar.Mahesh@Sun.COM rndcl->c_next = NULL; 495*9348SSiddheshwar.Mahesh@Sun.COM rndcl->c_dmemhandle = rndcl->rb_longbuf.handle; 496*9348SSiddheshwar.Mahesh@Sun.COM wlist->c_next = rndcl; 497*9348SSiddheshwar.Mahesh@Sun.COM } 498*9348SSiddheshwar.Mahesh@Sun.COM 4997387SRobert.Gordon@Sun.COM status = clist_register(conn, wlist, CLIST_REG_DST); 5007387SRobert.Gordon@Sun.COM if (status != RDMA_SUCCESS) { 501*9348SSiddheshwar.Mahesh@Sun.COM rdma_buf_free(conn, rndbuf); 502*9348SSiddheshwar.Mahesh@Sun.COM bzero(rndbuf, sizeof (rdma_buf_t)); 5037387SRobert.Gordon@Sun.COM return (CLNT_RDMA_FAIL); 5047387SRobert.Gordon@Sun.COM } 5057387SRobert.Gordon@Sun.COM XDR_CONTROL(call_xdrp, XDR_RDMA_SET_FLAGS, &xdr_flag); 5067387SRobert.Gordon@Sun.COM } 5077387SRobert.Gordon@Sun.COM 508*9348SSiddheshwar.Mahesh@Sun.COM if (!xdr_encode_wlist(xdrs, wlist)) { 509*9348SSiddheshwar.Mahesh@Sun.COM if (rndlen) { 510*9348SSiddheshwar.Mahesh@Sun.COM rdma_buf_free(conn, rndbuf); 511*9348SSiddheshwar.Mahesh@Sun.COM bzero(rndbuf, sizeof (rdma_buf_t)); 512*9348SSiddheshwar.Mahesh@Sun.COM } 5137387SRobert.Gordon@Sun.COM return (CLNT_RDMA_FAIL); 514*9348SSiddheshwar.Mahesh@Sun.COM } 5157387SRobert.Gordon@Sun.COM 5167387SRobert.Gordon@Sun.COM return (CLNT_RDMA_SUCCESS); 5177387SRobert.Gordon@Sun.COM } 5187387SRobert.Gordon@Sun.COM 5197387SRobert.Gordon@Sun.COM static int 5207387SRobert.Gordon@Sun.COM clnt_setup_long_reply(CONN *conn, struct clist **clpp, uint_t length) 5217387SRobert.Gordon@Sun.COM { 5227387SRobert.Gordon@Sun.COM if (length == 0) { 5237387SRobert.Gordon@Sun.COM *clpp = NULL; 5247387SRobert.Gordon@Sun.COM return (CLNT_RDMA_SUCCESS); 5257387SRobert.Gordon@Sun.COM } 5267387SRobert.Gordon@Sun.COM 5277387SRobert.Gordon@Sun.COM *clpp = clist_alloc(); 5287387SRobert.Gordon@Sun.COM 5297387SRobert.Gordon@Sun.COM (*clpp)->rb_longbuf.len = calc_length(length); 5307387SRobert.Gordon@Sun.COM (*clpp)->rb_longbuf.type = RDMA_LONG_BUFFER; 5317387SRobert.Gordon@Sun.COM 5327387SRobert.Gordon@Sun.COM if (rdma_buf_alloc(conn, &((*clpp)->rb_longbuf))) { 5337387SRobert.Gordon@Sun.COM clist_free(*clpp); 5347387SRobert.Gordon@Sun.COM *clpp = NULL; 5357387SRobert.Gordon@Sun.COM return (CLNT_RDMA_FAIL); 5367387SRobert.Gordon@Sun.COM } 5377387SRobert.Gordon@Sun.COM 5387387SRobert.Gordon@Sun.COM (*clpp)->u.c_daddr3 = (*clpp)->rb_longbuf.addr; 5397387SRobert.Gordon@Sun.COM (*clpp)->c_len = (*clpp)->rb_longbuf.len; 5407387SRobert.Gordon@Sun.COM (*clpp)->c_next = NULL; 5417387SRobert.Gordon@Sun.COM (*clpp)->c_dmemhandle = (*clpp)->rb_longbuf.handle; 5427387SRobert.Gordon@Sun.COM 5437387SRobert.Gordon@Sun.COM if (clist_register(conn, *clpp, CLIST_REG_DST)) { 5447387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__clntrdma__longrep_regbuf); 5457387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &((*clpp)->rb_longbuf)); 5467387SRobert.Gordon@Sun.COM clist_free(*clpp); 5477387SRobert.Gordon@Sun.COM return (CLNT_RDMA_FAIL); 5487387SRobert.Gordon@Sun.COM } 5497387SRobert.Gordon@Sun.COM 5507387SRobert.Gordon@Sun.COM return (CLNT_RDMA_SUCCESS); 5517387SRobert.Gordon@Sun.COM } 5527387SRobert.Gordon@Sun.COM 5530Sstevel@tonic-gate /* ARGSUSED */ 5540Sstevel@tonic-gate static enum clnt_stat 5550Sstevel@tonic-gate clnt_rdma_kcallit(CLIENT *h, rpcproc_t procnum, xdrproc_t xdr_args, 5567387SRobert.Gordon@Sun.COM caddr_t argsp, xdrproc_t xdr_results, caddr_t resultsp, 5577387SRobert.Gordon@Sun.COM struct timeval wait) 5580Sstevel@tonic-gate { 5590Sstevel@tonic-gate cku_private_t *p = htop(h); 5607387SRobert.Gordon@Sun.COM 5617387SRobert.Gordon@Sun.COM int try_call_again; 5627387SRobert.Gordon@Sun.COM int refresh_attempt = AUTH_REFRESH_COUNT; 5630Sstevel@tonic-gate int status; 5647387SRobert.Gordon@Sun.COM int msglen; 5657387SRobert.Gordon@Sun.COM 5667387SRobert.Gordon@Sun.COM XDR *call_xdrp, callxdr; /* for xdrrdma encoding the RPC call */ 5677387SRobert.Gordon@Sun.COM XDR *reply_xdrp, replyxdr; /* for xdrrdma decoding the RPC reply */ 5687387SRobert.Gordon@Sun.COM XDR *rdmahdr_o_xdrs, *rdmahdr_i_xdrs; 5697387SRobert.Gordon@Sun.COM 5700Sstevel@tonic-gate struct rpc_msg reply_msg; 5718695SRajkumar.Sivaprakasam@Sun.COM rdma_registry_t *m; 5727387SRobert.Gordon@Sun.COM 5737387SRobert.Gordon@Sun.COM struct clist *cl_sendlist; 5747387SRobert.Gordon@Sun.COM struct clist *cl_recvlist; 5757387SRobert.Gordon@Sun.COM struct clist *cl; 5767387SRobert.Gordon@Sun.COM struct clist *cl_rpcmsg; 5777387SRobert.Gordon@Sun.COM struct clist *cl_rdma_reply; 5787387SRobert.Gordon@Sun.COM struct clist *cl_rpcreply_wlist; 5797387SRobert.Gordon@Sun.COM struct clist *cl_long_reply; 580*9348SSiddheshwar.Mahesh@Sun.COM rdma_buf_t rndup; 5817387SRobert.Gordon@Sun.COM 5827387SRobert.Gordon@Sun.COM uint_t vers; 5837387SRobert.Gordon@Sun.COM uint_t op; 5840Sstevel@tonic-gate uint_t off; 5857387SRobert.Gordon@Sun.COM uint32_t seg_array_len; 5867387SRobert.Gordon@Sun.COM uint_t long_reply_len; 5877387SRobert.Gordon@Sun.COM uint_t rpcsec_gss; 5887387SRobert.Gordon@Sun.COM uint_t gss_i_or_p; 5897387SRobert.Gordon@Sun.COM 5900Sstevel@tonic-gate CONN *conn = NULL; 5917387SRobert.Gordon@Sun.COM rdma_buf_t clmsg; 5927387SRobert.Gordon@Sun.COM rdma_buf_t rpcmsg; 5937387SRobert.Gordon@Sun.COM rdma_chunkinfo_lengths_t rcil; 5947387SRobert.Gordon@Sun.COM 5950Sstevel@tonic-gate clock_t ticks; 5967387SRobert.Gordon@Sun.COM bool_t wlist_exists_reply; 5977387SRobert.Gordon@Sun.COM 5987387SRobert.Gordon@Sun.COM uint32_t rdma_credit = rdma_bufs_rqst; 5990Sstevel@tonic-gate 6000Sstevel@tonic-gate RCSTAT_INCR(rccalls); 6017387SRobert.Gordon@Sun.COM 6027387SRobert.Gordon@Sun.COM call_again: 6037387SRobert.Gordon@Sun.COM 6047387SRobert.Gordon@Sun.COM bzero(&clmsg, sizeof (clmsg)); 6057387SRobert.Gordon@Sun.COM bzero(&rpcmsg, sizeof (rpcmsg)); 606*9348SSiddheshwar.Mahesh@Sun.COM bzero(&rndup, sizeof (rndup)); 6077387SRobert.Gordon@Sun.COM try_call_again = 0; 6087387SRobert.Gordon@Sun.COM cl_sendlist = NULL; 6097387SRobert.Gordon@Sun.COM cl_recvlist = NULL; 6107387SRobert.Gordon@Sun.COM cl = NULL; 6117387SRobert.Gordon@Sun.COM cl_rpcmsg = NULL; 6127387SRobert.Gordon@Sun.COM cl_rdma_reply = NULL; 6137387SRobert.Gordon@Sun.COM call_xdrp = NULL; 6147387SRobert.Gordon@Sun.COM reply_xdrp = NULL; 6157387SRobert.Gordon@Sun.COM wlist_exists_reply = FALSE; 6167387SRobert.Gordon@Sun.COM cl_rpcreply_wlist = NULL; 6177387SRobert.Gordon@Sun.COM cl_long_reply = NULL; 6187387SRobert.Gordon@Sun.COM rcil.rcil_len = 0; 6197387SRobert.Gordon@Sun.COM rcil.rcil_len_alt = 0; 6207387SRobert.Gordon@Sun.COM long_reply_len = 0; 6217387SRobert.Gordon@Sun.COM 6228695SRajkumar.Sivaprakasam@Sun.COM rw_enter(&rdma_lock, RW_READER); 6238695SRajkumar.Sivaprakasam@Sun.COM m = (rdma_registry_t *)p->cku_rd_handle; 6248695SRajkumar.Sivaprakasam@Sun.COM if (m->r_mod_state == RDMA_MOD_INACTIVE) { 6258695SRajkumar.Sivaprakasam@Sun.COM /* 6268695SRajkumar.Sivaprakasam@Sun.COM * If we didn't find a matching RDMA module in the registry 6278695SRajkumar.Sivaprakasam@Sun.COM * then there is no transport. 6288695SRajkumar.Sivaprakasam@Sun.COM */ 6298695SRajkumar.Sivaprakasam@Sun.COM rw_exit(&rdma_lock); 6308695SRajkumar.Sivaprakasam@Sun.COM p->cku_err.re_status = RPC_CANTSEND; 6318695SRajkumar.Sivaprakasam@Sun.COM p->cku_err.re_errno = EIO; 6328695SRajkumar.Sivaprakasam@Sun.COM ticks = clnt_rdma_min_delay * drv_usectohz(1000000); 6338695SRajkumar.Sivaprakasam@Sun.COM if (h->cl_nosignal == TRUE) { 6348695SRajkumar.Sivaprakasam@Sun.COM delay(ticks); 6358695SRajkumar.Sivaprakasam@Sun.COM } else { 6368695SRajkumar.Sivaprakasam@Sun.COM if (delay_sig(ticks) == EINTR) { 6378695SRajkumar.Sivaprakasam@Sun.COM p->cku_err.re_status = RPC_INTR; 6388695SRajkumar.Sivaprakasam@Sun.COM p->cku_err.re_errno = EINTR; 6398695SRajkumar.Sivaprakasam@Sun.COM } 6408695SRajkumar.Sivaprakasam@Sun.COM } 6418695SRajkumar.Sivaprakasam@Sun.COM return (RPC_CANTSEND); 6428695SRajkumar.Sivaprakasam@Sun.COM } 6430Sstevel@tonic-gate /* 6440Sstevel@tonic-gate * Get unique xid 6450Sstevel@tonic-gate */ 6460Sstevel@tonic-gate if (p->cku_xid == 0) 6470Sstevel@tonic-gate p->cku_xid = alloc_xid(); 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate status = RDMA_GET_CONN(p->cku_rd_mod->rdma_ops, &p->cku_addr, 6500Sstevel@tonic-gate p->cku_addrfmly, p->cku_rd_handle, &conn); 6518695SRajkumar.Sivaprakasam@Sun.COM rw_exit(&rdma_lock); 6520Sstevel@tonic-gate 6537387SRobert.Gordon@Sun.COM /* 6547387SRobert.Gordon@Sun.COM * If there is a problem with the connection reflect the issue 6557387SRobert.Gordon@Sun.COM * back to the higher level to address, we MAY delay for a short 6567387SRobert.Gordon@Sun.COM * period so that we are kind to the transport. 6577387SRobert.Gordon@Sun.COM */ 6580Sstevel@tonic-gate if (conn == NULL) { 6590Sstevel@tonic-gate /* 6600Sstevel@tonic-gate * Connect failed to server. Could be because of one 6610Sstevel@tonic-gate * of several things. In some cases we don't want 6620Sstevel@tonic-gate * the caller to retry immediately - delay before 6630Sstevel@tonic-gate * returning to caller. 6640Sstevel@tonic-gate */ 6650Sstevel@tonic-gate switch (status) { 6660Sstevel@tonic-gate case RDMA_TIMEDOUT: 6670Sstevel@tonic-gate /* 6680Sstevel@tonic-gate * Already timed out. No need to delay 6690Sstevel@tonic-gate * some more. 6700Sstevel@tonic-gate */ 6710Sstevel@tonic-gate p->cku_err.re_status = RPC_TIMEDOUT; 6720Sstevel@tonic-gate p->cku_err.re_errno = ETIMEDOUT; 6730Sstevel@tonic-gate break; 6740Sstevel@tonic-gate case RDMA_INTR: 6750Sstevel@tonic-gate /* 6760Sstevel@tonic-gate * Failed because of an signal. Very likely 6770Sstevel@tonic-gate * the caller will not retry. 6780Sstevel@tonic-gate */ 6790Sstevel@tonic-gate p->cku_err.re_status = RPC_INTR; 6800Sstevel@tonic-gate p->cku_err.re_errno = EINTR; 6810Sstevel@tonic-gate break; 6820Sstevel@tonic-gate default: 6830Sstevel@tonic-gate /* 6840Sstevel@tonic-gate * All other failures - server down or service 6850Sstevel@tonic-gate * down or temporary resource failure. Delay before 6860Sstevel@tonic-gate * returning to caller. 6870Sstevel@tonic-gate */ 6880Sstevel@tonic-gate ticks = clnt_rdma_min_delay * drv_usectohz(1000000); 6890Sstevel@tonic-gate p->cku_err.re_status = RPC_CANTCONNECT; 6900Sstevel@tonic-gate p->cku_err.re_errno = EIO; 6910Sstevel@tonic-gate 6920Sstevel@tonic-gate if (h->cl_nosignal == TRUE) { 6930Sstevel@tonic-gate delay(ticks); 6940Sstevel@tonic-gate } else { 6950Sstevel@tonic-gate if (delay_sig(ticks) == EINTR) { 6960Sstevel@tonic-gate p->cku_err.re_status = RPC_INTR; 6970Sstevel@tonic-gate p->cku_err.re_errno = EINTR; 6980Sstevel@tonic-gate } 6990Sstevel@tonic-gate } 7000Sstevel@tonic-gate break; 7010Sstevel@tonic-gate } 7020Sstevel@tonic-gate 7030Sstevel@tonic-gate return (p->cku_err.re_status); 7040Sstevel@tonic-gate } 7057387SRobert.Gordon@Sun.COM 7067387SRobert.Gordon@Sun.COM clnt_check_credit(conn); 7070Sstevel@tonic-gate 7087387SRobert.Gordon@Sun.COM status = CLNT_RDMA_FAIL; 7097387SRobert.Gordon@Sun.COM 7107387SRobert.Gordon@Sun.COM rpcsec_gss = gss_i_or_p = FALSE; 7110Sstevel@tonic-gate 7127387SRobert.Gordon@Sun.COM if (IS_RPCSEC_GSS(h)) { 7137387SRobert.Gordon@Sun.COM rpcsec_gss = TRUE; 7147387SRobert.Gordon@Sun.COM if (rpc_gss_get_service_type(h->cl_auth) == 7157387SRobert.Gordon@Sun.COM rpc_gss_svc_integrity || 7167387SRobert.Gordon@Sun.COM rpc_gss_get_service_type(h->cl_auth) == 7177387SRobert.Gordon@Sun.COM rpc_gss_svc_privacy) 7187387SRobert.Gordon@Sun.COM gss_i_or_p = TRUE; 7190Sstevel@tonic-gate } 7200Sstevel@tonic-gate 7217387SRobert.Gordon@Sun.COM /* 7227387SRobert.Gordon@Sun.COM * Try a regular RDMA message if RPCSEC_GSS is not being used 7237387SRobert.Gordon@Sun.COM * or if RPCSEC_GSS is being used for authentication only. 7247387SRobert.Gordon@Sun.COM */ 7257387SRobert.Gordon@Sun.COM if (rpcsec_gss == FALSE || 7267387SRobert.Gordon@Sun.COM (rpcsec_gss == TRUE && gss_i_or_p == FALSE)) { 7270Sstevel@tonic-gate /* 7287387SRobert.Gordon@Sun.COM * Grab a send buffer for the request. Try to 7297387SRobert.Gordon@Sun.COM * encode it to see if it fits. If not, then it 7307387SRobert.Gordon@Sun.COM * needs to be sent in a chunk. 7310Sstevel@tonic-gate */ 7327387SRobert.Gordon@Sun.COM rpcmsg.type = SEND_BUFFER; 7337387SRobert.Gordon@Sun.COM if (rdma_buf_alloc(conn, &rpcmsg)) { 7347387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__clntrdma__callit_nobufs); 7350Sstevel@tonic-gate goto done; 7360Sstevel@tonic-gate } 7377387SRobert.Gordon@Sun.COM 7387387SRobert.Gordon@Sun.COM /* First try to encode into regular send buffer */ 7397387SRobert.Gordon@Sun.COM op = RDMA_MSG; 7400Sstevel@tonic-gate 7417387SRobert.Gordon@Sun.COM call_xdrp = &callxdr; 7427387SRobert.Gordon@Sun.COM 7437387SRobert.Gordon@Sun.COM xdrrdma_create(call_xdrp, rpcmsg.addr, rpcmsg.len, 7447387SRobert.Gordon@Sun.COM rdma_minchunk, NULL, XDR_ENCODE, conn); 7450Sstevel@tonic-gate 7467387SRobert.Gordon@Sun.COM status = clnt_compose_rpcmsg(h, procnum, &rpcmsg, call_xdrp, 7477387SRobert.Gordon@Sun.COM xdr_args, argsp); 7487387SRobert.Gordon@Sun.COM 7497387SRobert.Gordon@Sun.COM if (status != CLNT_RDMA_SUCCESS) { 7507387SRobert.Gordon@Sun.COM /* Clean up from previous encode attempt */ 7517387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &rpcmsg); 7527387SRobert.Gordon@Sun.COM XDR_DESTROY(call_xdrp); 7530Sstevel@tonic-gate } else { 7547387SRobert.Gordon@Sun.COM XDR_CONTROL(call_xdrp, XDR_RDMA_GET_CHUNK_LEN, &rcil); 7550Sstevel@tonic-gate } 7560Sstevel@tonic-gate } 7570Sstevel@tonic-gate 7587387SRobert.Gordon@Sun.COM /* If the encode didn't work, then try a NOMSG */ 7597387SRobert.Gordon@Sun.COM if (status != CLNT_RDMA_SUCCESS) { 7607387SRobert.Gordon@Sun.COM 7617387SRobert.Gordon@Sun.COM msglen = CKU_HDRSIZE + BYTES_PER_XDR_UNIT + MAX_AUTH_BYTES + 7627387SRobert.Gordon@Sun.COM xdr_sizeof(xdr_args, argsp); 7637387SRobert.Gordon@Sun.COM 7647387SRobert.Gordon@Sun.COM msglen = calc_length(msglen); 7657387SRobert.Gordon@Sun.COM 7667387SRobert.Gordon@Sun.COM /* pick up the lengths for the reply buffer needed */ 7677387SRobert.Gordon@Sun.COM (void) xdrrdma_sizeof(xdr_args, argsp, 0, 7687387SRobert.Gordon@Sun.COM &rcil.rcil_len, &rcil.rcil_len_alt); 7697387SRobert.Gordon@Sun.COM 7707387SRobert.Gordon@Sun.COM /* 7717387SRobert.Gordon@Sun.COM * Construct a clist to describe the CHUNK_BUFFER 7727387SRobert.Gordon@Sun.COM * for the rpcmsg. 7737387SRobert.Gordon@Sun.COM */ 7747387SRobert.Gordon@Sun.COM cl_rpcmsg = clist_alloc(); 7757387SRobert.Gordon@Sun.COM cl_rpcmsg->c_len = msglen; 7767387SRobert.Gordon@Sun.COM cl_rpcmsg->rb_longbuf.type = RDMA_LONG_BUFFER; 7777387SRobert.Gordon@Sun.COM cl_rpcmsg->rb_longbuf.len = msglen; 7787387SRobert.Gordon@Sun.COM if (rdma_buf_alloc(conn, &cl_rpcmsg->rb_longbuf)) { 7797387SRobert.Gordon@Sun.COM clist_free(cl_rpcmsg); 7807387SRobert.Gordon@Sun.COM goto done; 7817387SRobert.Gordon@Sun.COM } 7827387SRobert.Gordon@Sun.COM cl_rpcmsg->w.c_saddr3 = cl_rpcmsg->rb_longbuf.addr; 7837387SRobert.Gordon@Sun.COM 7847387SRobert.Gordon@Sun.COM op = RDMA_NOMSG; 7857387SRobert.Gordon@Sun.COM call_xdrp = &callxdr; 7867387SRobert.Gordon@Sun.COM 7877387SRobert.Gordon@Sun.COM xdrrdma_create(call_xdrp, cl_rpcmsg->rb_longbuf.addr, 7887387SRobert.Gordon@Sun.COM cl_rpcmsg->rb_longbuf.len, 0, 7897387SRobert.Gordon@Sun.COM cl_rpcmsg, XDR_ENCODE, conn); 7907387SRobert.Gordon@Sun.COM 7917387SRobert.Gordon@Sun.COM status = clnt_compose_rpcmsg(h, procnum, &rpcmsg, call_xdrp, 7927387SRobert.Gordon@Sun.COM xdr_args, argsp); 7937387SRobert.Gordon@Sun.COM 7947387SRobert.Gordon@Sun.COM if (status != CLNT_RDMA_SUCCESS) { 7957387SRobert.Gordon@Sun.COM p->cku_err.re_status = RPC_CANTENCODEARGS; 7967387SRobert.Gordon@Sun.COM p->cku_err.re_errno = EIO; 7977387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__clntrdma__callit__composemsg); 7987387SRobert.Gordon@Sun.COM goto done; 7997387SRobert.Gordon@Sun.COM } 8007387SRobert.Gordon@Sun.COM } 8017387SRobert.Gordon@Sun.COM 8027387SRobert.Gordon@Sun.COM /* 8037387SRobert.Gordon@Sun.COM * During the XDR_ENCODE we may have "allocated" an RDMA READ or 8047387SRobert.Gordon@Sun.COM * RDMA WRITE clist. 8057387SRobert.Gordon@Sun.COM * 8067387SRobert.Gordon@Sun.COM * First pull the RDMA READ chunk list from the XDR private 8077387SRobert.Gordon@Sun.COM * area to keep it handy. 8087387SRobert.Gordon@Sun.COM */ 8097387SRobert.Gordon@Sun.COM XDR_CONTROL(call_xdrp, XDR_RDMA_GET_RLIST, &cl); 8107387SRobert.Gordon@Sun.COM 8117387SRobert.Gordon@Sun.COM if (gss_i_or_p) { 8127387SRobert.Gordon@Sun.COM long_reply_len = rcil.rcil_len + rcil.rcil_len_alt; 8137387SRobert.Gordon@Sun.COM long_reply_len += MAX_AUTH_BYTES; 8147387SRobert.Gordon@Sun.COM } else { 8157387SRobert.Gordon@Sun.COM long_reply_len = rcil.rcil_len; 8167387SRobert.Gordon@Sun.COM } 8170Sstevel@tonic-gate 8180Sstevel@tonic-gate /* 8190Sstevel@tonic-gate * Update the chunk size information for the Long RPC msg. 8200Sstevel@tonic-gate */ 8210Sstevel@tonic-gate if (cl && op == RDMA_NOMSG) 8220Sstevel@tonic-gate cl->c_len = p->cku_outsz; 8230Sstevel@tonic-gate 8240Sstevel@tonic-gate /* 8257387SRobert.Gordon@Sun.COM * Prepare the RDMA header. On success xdrs will hold the result 8267387SRobert.Gordon@Sun.COM * of xdrmem_create() for a SEND_BUFFER. 8270Sstevel@tonic-gate */ 8287387SRobert.Gordon@Sun.COM status = clnt_compose_rdma_header(conn, h, &clmsg, 8297387SRobert.Gordon@Sun.COM &rdmahdr_o_xdrs, &op); 8307387SRobert.Gordon@Sun.COM 8317387SRobert.Gordon@Sun.COM if (status != CLNT_RDMA_SUCCESS) { 8320Sstevel@tonic-gate p->cku_err.re_status = RPC_CANTSEND; 8330Sstevel@tonic-gate p->cku_err.re_errno = EIO; 8340Sstevel@tonic-gate RCSTAT_INCR(rcnomem); 8357387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__clntrdma__callit__nobufs2); 8360Sstevel@tonic-gate goto done; 8370Sstevel@tonic-gate } 8387387SRobert.Gordon@Sun.COM 8390Sstevel@tonic-gate /* 8407387SRobert.Gordon@Sun.COM * Now insert the RDMA READ list iff present 8410Sstevel@tonic-gate */ 8427387SRobert.Gordon@Sun.COM status = clnt_setup_rlist(conn, rdmahdr_o_xdrs, call_xdrp); 8437387SRobert.Gordon@Sun.COM if (status != CLNT_RDMA_SUCCESS) { 8447387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__clntrdma__callit__clistreg); 8457387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &clmsg); 8467387SRobert.Gordon@Sun.COM p->cku_err.re_status = RPC_CANTSEND; 8477387SRobert.Gordon@Sun.COM p->cku_err.re_errno = EIO; 8487387SRobert.Gordon@Sun.COM goto done; 8497387SRobert.Gordon@Sun.COM } 8507387SRobert.Gordon@Sun.COM 8517387SRobert.Gordon@Sun.COM /* 8527387SRobert.Gordon@Sun.COM * Setup RDMA WRITE chunk list for nfs read operation 8537387SRobert.Gordon@Sun.COM * other operations will have a NULL which will result 8547387SRobert.Gordon@Sun.COM * as a NULL list in the XDR stream. 8557387SRobert.Gordon@Sun.COM */ 856*9348SSiddheshwar.Mahesh@Sun.COM status = clnt_setup_wlist(conn, rdmahdr_o_xdrs, call_xdrp, &rndup); 8577387SRobert.Gordon@Sun.COM if (status != CLNT_RDMA_SUCCESS) { 8587387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &clmsg); 8597387SRobert.Gordon@Sun.COM p->cku_err.re_status = RPC_CANTSEND; 8607387SRobert.Gordon@Sun.COM p->cku_err.re_errno = EIO; 8617387SRobert.Gordon@Sun.COM goto done; 8627387SRobert.Gordon@Sun.COM } 8630Sstevel@tonic-gate 8640Sstevel@tonic-gate /* 8657387SRobert.Gordon@Sun.COM * If NULL call and RPCSEC_GSS, provide a chunk such that 8667387SRobert.Gordon@Sun.COM * large responses can flow back to the client. 8677387SRobert.Gordon@Sun.COM * If RPCSEC_GSS with integrity or privacy is in use, get chunk. 8680Sstevel@tonic-gate */ 8697387SRobert.Gordon@Sun.COM if ((procnum == 0 && rpcsec_gss == TRUE) || 8707387SRobert.Gordon@Sun.COM (rpcsec_gss == TRUE && gss_i_or_p == TRUE)) 8717387SRobert.Gordon@Sun.COM long_reply_len += 1024; 8720Sstevel@tonic-gate 8737387SRobert.Gordon@Sun.COM status = clnt_setup_long_reply(conn, &cl_long_reply, long_reply_len); 8740Sstevel@tonic-gate 8757387SRobert.Gordon@Sun.COM if (status != CLNT_RDMA_SUCCESS) { 8767387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &clmsg); 8777387SRobert.Gordon@Sun.COM p->cku_err.re_status = RPC_CANTSEND; 8787387SRobert.Gordon@Sun.COM p->cku_err.re_errno = EIO; 8797387SRobert.Gordon@Sun.COM goto done; 8800Sstevel@tonic-gate } 8810Sstevel@tonic-gate 8820Sstevel@tonic-gate /* 8837387SRobert.Gordon@Sun.COM * XDR encode the RDMA_REPLY write chunk 8847387SRobert.Gordon@Sun.COM */ 8857387SRobert.Gordon@Sun.COM seg_array_len = (cl_long_reply ? 1 : 0); 8867387SRobert.Gordon@Sun.COM (void) xdr_encode_reply_wchunk(rdmahdr_o_xdrs, cl_long_reply, 8877387SRobert.Gordon@Sun.COM seg_array_len); 8887387SRobert.Gordon@Sun.COM 8897387SRobert.Gordon@Sun.COM /* 8907387SRobert.Gordon@Sun.COM * Construct a clist in "sendlist" that represents what we 8917387SRobert.Gordon@Sun.COM * will push over the wire. 8927387SRobert.Gordon@Sun.COM * 8930Sstevel@tonic-gate * Start with the RDMA header and clist (if any) 8940Sstevel@tonic-gate */ 8957387SRobert.Gordon@Sun.COM clist_add(&cl_sendlist, 0, XDR_GETPOS(rdmahdr_o_xdrs), &clmsg.handle, 8967387SRobert.Gordon@Sun.COM clmsg.addr, NULL, NULL); 8970Sstevel@tonic-gate 8980Sstevel@tonic-gate /* 8997387SRobert.Gordon@Sun.COM * Put the RPC call message in sendlist if small RPC 9000Sstevel@tonic-gate */ 9010Sstevel@tonic-gate if (op == RDMA_MSG) { 9027387SRobert.Gordon@Sun.COM clist_add(&cl_sendlist, 0, p->cku_outsz, &rpcmsg.handle, 9037387SRobert.Gordon@Sun.COM rpcmsg.addr, NULL, NULL); 9040Sstevel@tonic-gate } else { 9050Sstevel@tonic-gate /* Long RPC already in chunk list */ 9060Sstevel@tonic-gate RCSTAT_INCR(rclongrpcs); 9070Sstevel@tonic-gate } 9080Sstevel@tonic-gate 9090Sstevel@tonic-gate /* 9100Sstevel@tonic-gate * Set up a reply buffer ready for the reply 9110Sstevel@tonic-gate */ 9120Sstevel@tonic-gate status = rdma_clnt_postrecv(conn, p->cku_xid); 9130Sstevel@tonic-gate if (status != RDMA_SUCCESS) { 9140Sstevel@tonic-gate rdma_buf_free(conn, &clmsg); 9150Sstevel@tonic-gate p->cku_err.re_status = RPC_CANTSEND; 9160Sstevel@tonic-gate p->cku_err.re_errno = EIO; 9170Sstevel@tonic-gate goto done; 9180Sstevel@tonic-gate } 9197387SRobert.Gordon@Sun.COM 9200Sstevel@tonic-gate /* 9210Sstevel@tonic-gate * sync the memory for dma 9220Sstevel@tonic-gate */ 9230Sstevel@tonic-gate if (cl != NULL) { 9247387SRobert.Gordon@Sun.COM status = clist_syncmem(conn, cl, CLIST_REG_SOURCE); 9250Sstevel@tonic-gate if (status != RDMA_SUCCESS) { 9267387SRobert.Gordon@Sun.COM (void) rdma_clnt_postrecv_remove(conn, p->cku_xid); 9270Sstevel@tonic-gate rdma_buf_free(conn, &clmsg); 9280Sstevel@tonic-gate p->cku_err.re_status = RPC_CANTSEND; 9290Sstevel@tonic-gate p->cku_err.re_errno = EIO; 9300Sstevel@tonic-gate goto done; 9310Sstevel@tonic-gate } 9320Sstevel@tonic-gate } 9330Sstevel@tonic-gate 9340Sstevel@tonic-gate /* 9357387SRobert.Gordon@Sun.COM * Send the RDMA Header and RPC call message to the server 9360Sstevel@tonic-gate */ 9377387SRobert.Gordon@Sun.COM status = RDMA_SEND(conn, cl_sendlist, p->cku_xid); 9380Sstevel@tonic-gate if (status != RDMA_SUCCESS) { 9397387SRobert.Gordon@Sun.COM (void) rdma_clnt_postrecv_remove(conn, p->cku_xid); 9400Sstevel@tonic-gate p->cku_err.re_status = RPC_CANTSEND; 9410Sstevel@tonic-gate p->cku_err.re_errno = EIO; 9420Sstevel@tonic-gate goto done; 9430Sstevel@tonic-gate } 9447387SRobert.Gordon@Sun.COM 9457387SRobert.Gordon@Sun.COM /* 9467387SRobert.Gordon@Sun.COM * RDMA plugin now owns the send msg buffers. 9477387SRobert.Gordon@Sun.COM * Clear them out and don't free them. 9487387SRobert.Gordon@Sun.COM */ 9497387SRobert.Gordon@Sun.COM clmsg.addr = NULL; 9507387SRobert.Gordon@Sun.COM if (rpcmsg.type == SEND_BUFFER) 9517387SRobert.Gordon@Sun.COM rpcmsg.addr = NULL; 9520Sstevel@tonic-gate 9530Sstevel@tonic-gate /* 9540Sstevel@tonic-gate * Recv rpc reply 9550Sstevel@tonic-gate */ 9567387SRobert.Gordon@Sun.COM status = RDMA_RECV(conn, &cl_recvlist, p->cku_xid); 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate /* 9590Sstevel@tonic-gate * Now check recv status 9600Sstevel@tonic-gate */ 9610Sstevel@tonic-gate if (status != 0) { 9620Sstevel@tonic-gate if (status == RDMA_INTR) { 9630Sstevel@tonic-gate p->cku_err.re_status = RPC_INTR; 9640Sstevel@tonic-gate p->cku_err.re_errno = EINTR; 9650Sstevel@tonic-gate RCSTAT_INCR(rcintrs); 9660Sstevel@tonic-gate } else if (status == RPC_TIMEDOUT) { 9670Sstevel@tonic-gate p->cku_err.re_status = RPC_TIMEDOUT; 9680Sstevel@tonic-gate p->cku_err.re_errno = ETIMEDOUT; 9690Sstevel@tonic-gate RCSTAT_INCR(rctimeouts); 9700Sstevel@tonic-gate } else { 9710Sstevel@tonic-gate p->cku_err.re_status = RPC_CANTRECV; 9720Sstevel@tonic-gate p->cku_err.re_errno = EIO; 9730Sstevel@tonic-gate } 9740Sstevel@tonic-gate goto done; 9750Sstevel@tonic-gate } 9767387SRobert.Gordon@Sun.COM 9770Sstevel@tonic-gate /* 9780Sstevel@tonic-gate * Process the reply message. 9790Sstevel@tonic-gate * 9800Sstevel@tonic-gate * First the chunk list (if any) 9810Sstevel@tonic-gate */ 9827387SRobert.Gordon@Sun.COM rdmahdr_i_xdrs = &(p->cku_inxdr); 9837387SRobert.Gordon@Sun.COM xdrmem_create(rdmahdr_i_xdrs, 9847387SRobert.Gordon@Sun.COM (caddr_t)(uintptr_t)cl_recvlist->w.c_saddr3, 9857387SRobert.Gordon@Sun.COM cl_recvlist->c_len, XDR_DECODE); 9867387SRobert.Gordon@Sun.COM 9870Sstevel@tonic-gate /* 9880Sstevel@tonic-gate * Treat xid as opaque (xid is the first entity 9890Sstevel@tonic-gate * in the rpc rdma message). 9907387SRobert.Gordon@Sun.COM * Skip xid and set the xdr position accordingly. 9910Sstevel@tonic-gate */ 9927387SRobert.Gordon@Sun.COM XDR_SETPOS(rdmahdr_i_xdrs, sizeof (uint32_t)); 9937387SRobert.Gordon@Sun.COM (void) xdr_u_int(rdmahdr_i_xdrs, &vers); 9947387SRobert.Gordon@Sun.COM (void) xdr_u_int(rdmahdr_i_xdrs, &rdma_credit); 9957387SRobert.Gordon@Sun.COM (void) xdr_u_int(rdmahdr_i_xdrs, &op); 9967387SRobert.Gordon@Sun.COM (void) xdr_do_clist(rdmahdr_i_xdrs, &cl); 9977387SRobert.Gordon@Sun.COM 9987387SRobert.Gordon@Sun.COM clnt_update_credit(conn, rdma_credit); 9997387SRobert.Gordon@Sun.COM 10007387SRobert.Gordon@Sun.COM wlist_exists_reply = FALSE; 10017387SRobert.Gordon@Sun.COM if (! xdr_decode_wlist(rdmahdr_i_xdrs, &cl_rpcreply_wlist, 10027387SRobert.Gordon@Sun.COM &wlist_exists_reply)) { 10037387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__clntrdma__callit__wlist_decode); 10047387SRobert.Gordon@Sun.COM p->cku_err.re_status = RPC_CANTDECODERES; 10057387SRobert.Gordon@Sun.COM p->cku_err.re_errno = EIO; 10067387SRobert.Gordon@Sun.COM goto done; 10077387SRobert.Gordon@Sun.COM } 10080Sstevel@tonic-gate 10090Sstevel@tonic-gate /* 10107387SRobert.Gordon@Sun.COM * The server shouldn't have sent a RDMA_SEND that 10117387SRobert.Gordon@Sun.COM * the client needs to RDMA_WRITE a reply back to 10127387SRobert.Gordon@Sun.COM * the server. So silently ignoring what the 10137387SRobert.Gordon@Sun.COM * server returns in the rdma_reply section of the 10147387SRobert.Gordon@Sun.COM * header. 10150Sstevel@tonic-gate */ 10167387SRobert.Gordon@Sun.COM (void) xdr_decode_reply_wchunk(rdmahdr_i_xdrs, &cl_rdma_reply); 10177387SRobert.Gordon@Sun.COM off = xdr_getpos(rdmahdr_i_xdrs); 10180Sstevel@tonic-gate 10197387SRobert.Gordon@Sun.COM clnt_decode_long_reply(conn, cl_long_reply, 10207387SRobert.Gordon@Sun.COM cl_rdma_reply, &replyxdr, &reply_xdrp, 10217387SRobert.Gordon@Sun.COM cl, cl_recvlist, op, off); 10220Sstevel@tonic-gate 10237387SRobert.Gordon@Sun.COM if (reply_xdrp == NULL) 10247387SRobert.Gordon@Sun.COM goto done; 10250Sstevel@tonic-gate 10267387SRobert.Gordon@Sun.COM if (wlist_exists_reply) { 10277387SRobert.Gordon@Sun.COM XDR_CONTROL(reply_xdrp, XDR_RDMA_SET_WLIST, cl_rpcreply_wlist); 10280Sstevel@tonic-gate } 10290Sstevel@tonic-gate 10300Sstevel@tonic-gate reply_msg.rm_direction = REPLY; 10310Sstevel@tonic-gate reply_msg.rm_reply.rp_stat = MSG_ACCEPTED; 10320Sstevel@tonic-gate reply_msg.acpted_rply.ar_stat = SUCCESS; 10330Sstevel@tonic-gate reply_msg.acpted_rply.ar_verf = _null_auth; 10347387SRobert.Gordon@Sun.COM 10350Sstevel@tonic-gate /* 10360Sstevel@tonic-gate * xdr_results will be done in AUTH_UNWRAP. 10370Sstevel@tonic-gate */ 10380Sstevel@tonic-gate reply_msg.acpted_rply.ar_results.where = NULL; 10390Sstevel@tonic-gate reply_msg.acpted_rply.ar_results.proc = xdr_void; 10400Sstevel@tonic-gate 10410Sstevel@tonic-gate /* 10420Sstevel@tonic-gate * Decode and validate the response. 10430Sstevel@tonic-gate */ 10447387SRobert.Gordon@Sun.COM if (xdr_replymsg(reply_xdrp, &reply_msg)) { 10450Sstevel@tonic-gate enum clnt_stat re_status; 10460Sstevel@tonic-gate 10470Sstevel@tonic-gate _seterr_reply(&reply_msg, &(p->cku_err)); 10480Sstevel@tonic-gate 10490Sstevel@tonic-gate re_status = p->cku_err.re_status; 10500Sstevel@tonic-gate if (re_status == RPC_SUCCESS) { 10510Sstevel@tonic-gate /* 10520Sstevel@tonic-gate * Reply is good, check auth. 10530Sstevel@tonic-gate */ 10540Sstevel@tonic-gate if (!AUTH_VALIDATE(h->cl_auth, 10550Sstevel@tonic-gate &reply_msg.acpted_rply.ar_verf)) { 10560Sstevel@tonic-gate p->cku_err.re_status = RPC_AUTHERROR; 10570Sstevel@tonic-gate p->cku_err.re_why = AUTH_INVALIDRESP; 10580Sstevel@tonic-gate RCSTAT_INCR(rcbadverfs); 10597387SRobert.Gordon@Sun.COM DTRACE_PROBE( 10607387SRobert.Gordon@Sun.COM krpc__e__clntrdma__callit__authvalidate); 10617387SRobert.Gordon@Sun.COM } else if (!AUTH_UNWRAP(h->cl_auth, reply_xdrp, 10620Sstevel@tonic-gate xdr_results, resultsp)) { 10630Sstevel@tonic-gate p->cku_err.re_status = RPC_CANTDECODERES; 10640Sstevel@tonic-gate p->cku_err.re_errno = EIO; 10657387SRobert.Gordon@Sun.COM DTRACE_PROBE( 10667387SRobert.Gordon@Sun.COM krpc__e__clntrdma__callit__authunwrap); 10670Sstevel@tonic-gate } 10680Sstevel@tonic-gate } else { 10690Sstevel@tonic-gate /* set errno in case we can't recover */ 10700Sstevel@tonic-gate if (re_status != RPC_VERSMISMATCH && 10710Sstevel@tonic-gate re_status != RPC_AUTHERROR && 10720Sstevel@tonic-gate re_status != RPC_PROGVERSMISMATCH) 10730Sstevel@tonic-gate p->cku_err.re_errno = EIO; 10740Sstevel@tonic-gate 10750Sstevel@tonic-gate if (re_status == RPC_AUTHERROR) { 10767387SRobert.Gordon@Sun.COM if ((refresh_attempt > 0) && 10777387SRobert.Gordon@Sun.COM AUTH_REFRESH(h->cl_auth, &reply_msg, 10787387SRobert.Gordon@Sun.COM p->cku_cred)) { 10797387SRobert.Gordon@Sun.COM refresh_attempt--; 10807387SRobert.Gordon@Sun.COM try_call_again = 1; 10817387SRobert.Gordon@Sun.COM goto done; 10827387SRobert.Gordon@Sun.COM } 10837387SRobert.Gordon@Sun.COM 10847387SRobert.Gordon@Sun.COM try_call_again = 0; 10857387SRobert.Gordon@Sun.COM 10867387SRobert.Gordon@Sun.COM /* 10877387SRobert.Gordon@Sun.COM * We have used the client handle to 10887387SRobert.Gordon@Sun.COM * do an AUTH_REFRESH and the RPC status may 10897387SRobert.Gordon@Sun.COM * be set to RPC_SUCCESS; Let's make sure to 10907387SRobert.Gordon@Sun.COM * set it to RPC_AUTHERROR. 10917387SRobert.Gordon@Sun.COM */ 10927387SRobert.Gordon@Sun.COM p->cku_err.re_status = RPC_AUTHERROR; 10937387SRobert.Gordon@Sun.COM 10940Sstevel@tonic-gate /* 10950Sstevel@tonic-gate * Map recoverable and unrecoverable 10960Sstevel@tonic-gate * authentication errors to appropriate 10970Sstevel@tonic-gate * errno 10980Sstevel@tonic-gate */ 10990Sstevel@tonic-gate switch (p->cku_err.re_why) { 11000Sstevel@tonic-gate case AUTH_BADCRED: 11010Sstevel@tonic-gate case AUTH_BADVERF: 11020Sstevel@tonic-gate case AUTH_INVALIDRESP: 11030Sstevel@tonic-gate case AUTH_TOOWEAK: 11040Sstevel@tonic-gate case AUTH_FAILED: 11050Sstevel@tonic-gate case RPCSEC_GSS_NOCRED: 11060Sstevel@tonic-gate case RPCSEC_GSS_FAILED: 11070Sstevel@tonic-gate p->cku_err.re_errno = EACCES; 11080Sstevel@tonic-gate break; 11090Sstevel@tonic-gate case AUTH_REJECTEDCRED: 11100Sstevel@tonic-gate case AUTH_REJECTEDVERF: 11110Sstevel@tonic-gate default: 11120Sstevel@tonic-gate p->cku_err.re_errno = EIO; 11130Sstevel@tonic-gate break; 11140Sstevel@tonic-gate } 11150Sstevel@tonic-gate } 11167387SRobert.Gordon@Sun.COM DTRACE_PROBE1(krpc__e__clntrdma__callit__rpcfailed, 11177387SRobert.Gordon@Sun.COM int, p->cku_err.re_why); 11180Sstevel@tonic-gate } 11190Sstevel@tonic-gate } else { 11200Sstevel@tonic-gate p->cku_err.re_status = RPC_CANTDECODERES; 11210Sstevel@tonic-gate p->cku_err.re_errno = EIO; 11227387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__clntrdma__callit__replymsg); 11230Sstevel@tonic-gate } 11240Sstevel@tonic-gate 11257387SRobert.Gordon@Sun.COM done: 11267387SRobert.Gordon@Sun.COM clnt_return_credit(conn); 11277387SRobert.Gordon@Sun.COM 11287387SRobert.Gordon@Sun.COM if (cl_sendlist != NULL) 11297387SRobert.Gordon@Sun.COM clist_free(cl_sendlist); 11307387SRobert.Gordon@Sun.COM 11310Sstevel@tonic-gate /* 11320Sstevel@tonic-gate * If rpc reply is in a chunk, free it now. 11330Sstevel@tonic-gate */ 11347387SRobert.Gordon@Sun.COM if (cl_long_reply) { 1135*9348SSiddheshwar.Mahesh@Sun.COM (void) clist_deregister(conn, cl_long_reply); 11367387SRobert.Gordon@Sun.COM rdma_buf_free(conn, &cl_long_reply->rb_longbuf); 11377387SRobert.Gordon@Sun.COM clist_free(cl_long_reply); 11387387SRobert.Gordon@Sun.COM } 11390Sstevel@tonic-gate 11407387SRobert.Gordon@Sun.COM if (call_xdrp) 11417387SRobert.Gordon@Sun.COM XDR_DESTROY(call_xdrp); 11420Sstevel@tonic-gate 1143*9348SSiddheshwar.Mahesh@Sun.COM if (rndup.rb_private) { 1144*9348SSiddheshwar.Mahesh@Sun.COM rdma_buf_free(conn, &rndup); 1145*9348SSiddheshwar.Mahesh@Sun.COM } 1146*9348SSiddheshwar.Mahesh@Sun.COM 11477387SRobert.Gordon@Sun.COM if (reply_xdrp) { 11487387SRobert.Gordon@Sun.COM (void) xdr_rpc_free_verifier(reply_xdrp, &reply_msg); 11497387SRobert.Gordon@Sun.COM XDR_DESTROY(reply_xdrp); 11500Sstevel@tonic-gate } 11510Sstevel@tonic-gate 11527387SRobert.Gordon@Sun.COM if (cl_rdma_reply) { 11537387SRobert.Gordon@Sun.COM clist_free(cl_rdma_reply); 11540Sstevel@tonic-gate } 11550Sstevel@tonic-gate 11567387SRobert.Gordon@Sun.COM if (cl_recvlist) { 11577387SRobert.Gordon@Sun.COM rdma_buf_t recvmsg = {0}; 11587387SRobert.Gordon@Sun.COM recvmsg.addr = (caddr_t)(uintptr_t)cl_recvlist->w.c_saddr3; 11590Sstevel@tonic-gate recvmsg.type = RECV_BUFFER; 11600Sstevel@tonic-gate RDMA_BUF_FREE(conn, &recvmsg); 11617387SRobert.Gordon@Sun.COM clist_free(cl_recvlist); 11620Sstevel@tonic-gate } 11637387SRobert.Gordon@Sun.COM 11640Sstevel@tonic-gate RDMA_REL_CONN(conn); 11657387SRobert.Gordon@Sun.COM 11667387SRobert.Gordon@Sun.COM if (try_call_again) 11677387SRobert.Gordon@Sun.COM goto call_again; 11687387SRobert.Gordon@Sun.COM 11690Sstevel@tonic-gate if (p->cku_err.re_status != RPC_SUCCESS) { 11700Sstevel@tonic-gate RCSTAT_INCR(rcbadcalls); 11710Sstevel@tonic-gate } 11720Sstevel@tonic-gate return (p->cku_err.re_status); 11730Sstevel@tonic-gate } 11740Sstevel@tonic-gate 11757387SRobert.Gordon@Sun.COM 11767387SRobert.Gordon@Sun.COM static void 11777387SRobert.Gordon@Sun.COM clnt_decode_long_reply(CONN *conn, 11787387SRobert.Gordon@Sun.COM struct clist *cl_long_reply, 11797387SRobert.Gordon@Sun.COM struct clist *cl_rdma_reply, XDR *xdrs, 11807387SRobert.Gordon@Sun.COM XDR **rxdrp, struct clist *cl, 11817387SRobert.Gordon@Sun.COM struct clist *cl_recvlist, 11827387SRobert.Gordon@Sun.COM uint_t op, uint_t off) 11837387SRobert.Gordon@Sun.COM { 11847387SRobert.Gordon@Sun.COM if (op != RDMA_NOMSG) { 11857387SRobert.Gordon@Sun.COM DTRACE_PROBE1(krpc__i__longrepl__rdmamsg__len, 11867387SRobert.Gordon@Sun.COM int, cl_recvlist->c_len - off); 11877387SRobert.Gordon@Sun.COM xdrrdma_create(xdrs, 11887387SRobert.Gordon@Sun.COM (caddr_t)(uintptr_t)(cl_recvlist->w.c_saddr3 + off), 11897387SRobert.Gordon@Sun.COM cl_recvlist->c_len - off, 0, cl, XDR_DECODE, conn); 11907387SRobert.Gordon@Sun.COM *rxdrp = xdrs; 11917387SRobert.Gordon@Sun.COM return; 11927387SRobert.Gordon@Sun.COM } 11937387SRobert.Gordon@Sun.COM 11947387SRobert.Gordon@Sun.COM /* op must be RDMA_NOMSG */ 11957387SRobert.Gordon@Sun.COM if (cl) { 11967387SRobert.Gordon@Sun.COM DTRACE_PROBE(krpc__e__clntrdma__declongreply__serverreadlist); 11977387SRobert.Gordon@Sun.COM return; 11987387SRobert.Gordon@Sun.COM } 11997387SRobert.Gordon@Sun.COM 12007387SRobert.Gordon@Sun.COM if (cl_long_reply->u.c_daddr) { 12017387SRobert.Gordon@Sun.COM DTRACE_PROBE1(krpc__i__longrepl__rdmanomsg__len, 12027387SRobert.Gordon@Sun.COM int, cl_rdma_reply->c_len); 12037387SRobert.Gordon@Sun.COM 12047387SRobert.Gordon@Sun.COM xdrrdma_create(xdrs, (caddr_t)cl_long_reply->u.c_daddr3, 12057387SRobert.Gordon@Sun.COM cl_rdma_reply->c_len, 0, NULL, XDR_DECODE, conn); 12067387SRobert.Gordon@Sun.COM 12077387SRobert.Gordon@Sun.COM *rxdrp = xdrs; 12087387SRobert.Gordon@Sun.COM } 12097387SRobert.Gordon@Sun.COM } 12107387SRobert.Gordon@Sun.COM 12117387SRobert.Gordon@Sun.COM static void 12127387SRobert.Gordon@Sun.COM clnt_return_credit(CONN *conn) 12137387SRobert.Gordon@Sun.COM { 12147387SRobert.Gordon@Sun.COM rdma_clnt_cred_ctrl_t *cc_info = &conn->rdma_conn_cred_ctrl_u.c_clnt_cc; 12157387SRobert.Gordon@Sun.COM 12167387SRobert.Gordon@Sun.COM mutex_enter(&conn->c_lock); 12177387SRobert.Gordon@Sun.COM cc_info->clnt_cc_in_flight_ops--; 12187387SRobert.Gordon@Sun.COM cv_signal(&cc_info->clnt_cc_cv); 12197387SRobert.Gordon@Sun.COM mutex_exit(&conn->c_lock); 12207387SRobert.Gordon@Sun.COM } 12217387SRobert.Gordon@Sun.COM 12227387SRobert.Gordon@Sun.COM static void 12237387SRobert.Gordon@Sun.COM clnt_update_credit(CONN *conn, uint32_t rdma_credit) 12247387SRobert.Gordon@Sun.COM { 12257387SRobert.Gordon@Sun.COM rdma_clnt_cred_ctrl_t *cc_info = &conn->rdma_conn_cred_ctrl_u.c_clnt_cc; 12267387SRobert.Gordon@Sun.COM 12277387SRobert.Gordon@Sun.COM /* 12287387SRobert.Gordon@Sun.COM * If the granted has not altered, avoid taking the 12297387SRobert.Gordon@Sun.COM * mutex, to essentially do nothing.. 12307387SRobert.Gordon@Sun.COM */ 12317387SRobert.Gordon@Sun.COM if (cc_info->clnt_cc_granted_ops == rdma_credit) 12327387SRobert.Gordon@Sun.COM return; 12337387SRobert.Gordon@Sun.COM /* 12347387SRobert.Gordon@Sun.COM * Get the granted number of buffers for credit control. 12357387SRobert.Gordon@Sun.COM */ 12367387SRobert.Gordon@Sun.COM mutex_enter(&conn->c_lock); 12377387SRobert.Gordon@Sun.COM cc_info->clnt_cc_granted_ops = rdma_credit; 12387387SRobert.Gordon@Sun.COM mutex_exit(&conn->c_lock); 12397387SRobert.Gordon@Sun.COM } 12407387SRobert.Gordon@Sun.COM 12417387SRobert.Gordon@Sun.COM static void 12427387SRobert.Gordon@Sun.COM clnt_check_credit(CONN *conn) 12437387SRobert.Gordon@Sun.COM { 12447387SRobert.Gordon@Sun.COM rdma_clnt_cred_ctrl_t *cc_info = &conn->rdma_conn_cred_ctrl_u.c_clnt_cc; 12457387SRobert.Gordon@Sun.COM 12467387SRobert.Gordon@Sun.COM /* 12477387SRobert.Gordon@Sun.COM * Make sure we are not going over our allowed buffer use 12487387SRobert.Gordon@Sun.COM * (and make sure we have gotten a granted value before). 12497387SRobert.Gordon@Sun.COM */ 12507387SRobert.Gordon@Sun.COM mutex_enter(&conn->c_lock); 12517387SRobert.Gordon@Sun.COM while (cc_info->clnt_cc_in_flight_ops >= cc_info->clnt_cc_granted_ops && 12527387SRobert.Gordon@Sun.COM cc_info->clnt_cc_granted_ops != 0) { 12537387SRobert.Gordon@Sun.COM /* 12547387SRobert.Gordon@Sun.COM * Client has maxed out its granted buffers due to 12557387SRobert.Gordon@Sun.COM * credit control. Current handling is to block and wait. 12567387SRobert.Gordon@Sun.COM */ 12577387SRobert.Gordon@Sun.COM cv_wait(&cc_info->clnt_cc_cv, &conn->c_lock); 12587387SRobert.Gordon@Sun.COM } 12597387SRobert.Gordon@Sun.COM cc_info->clnt_cc_in_flight_ops++; 12607387SRobert.Gordon@Sun.COM mutex_exit(&conn->c_lock); 12617387SRobert.Gordon@Sun.COM } 12627387SRobert.Gordon@Sun.COM 12630Sstevel@tonic-gate /* ARGSUSED */ 12640Sstevel@tonic-gate static void 12650Sstevel@tonic-gate clnt_rdma_kabort(CLIENT *h) 12660Sstevel@tonic-gate { 12670Sstevel@tonic-gate } 12680Sstevel@tonic-gate 12690Sstevel@tonic-gate static void 12700Sstevel@tonic-gate clnt_rdma_kerror(CLIENT *h, struct rpc_err *err) 12710Sstevel@tonic-gate { 12720Sstevel@tonic-gate struct cku_private *p = htop(h); 12730Sstevel@tonic-gate *err = p->cku_err; 12740Sstevel@tonic-gate } 12750Sstevel@tonic-gate 12760Sstevel@tonic-gate static bool_t 12770Sstevel@tonic-gate clnt_rdma_kfreeres(CLIENT *h, xdrproc_t xdr_res, caddr_t res_ptr) 12780Sstevel@tonic-gate { 12790Sstevel@tonic-gate struct cku_private *p = htop(h); 12800Sstevel@tonic-gate XDR *xdrs; 12810Sstevel@tonic-gate 12820Sstevel@tonic-gate xdrs = &(p->cku_outxdr); 12830Sstevel@tonic-gate xdrs->x_op = XDR_FREE; 12840Sstevel@tonic-gate return ((*xdr_res)(xdrs, res_ptr)); 12850Sstevel@tonic-gate } 12860Sstevel@tonic-gate 12870Sstevel@tonic-gate /* ARGSUSED */ 12880Sstevel@tonic-gate static bool_t 12890Sstevel@tonic-gate clnt_rdma_kcontrol(CLIENT *h, int cmd, char *arg) 12900Sstevel@tonic-gate { 12910Sstevel@tonic-gate return (TRUE); 12920Sstevel@tonic-gate } 12930Sstevel@tonic-gate 12940Sstevel@tonic-gate /* ARGSUSED */ 12950Sstevel@tonic-gate static int 12960Sstevel@tonic-gate clnt_rdma_ksettimers(CLIENT *h, struct rpc_timers *t, struct rpc_timers *all, 12970Sstevel@tonic-gate int minimum, void(*feedback)(int, int, caddr_t), caddr_t arg, 12980Sstevel@tonic-gate uint32_t xid) 12990Sstevel@tonic-gate { 13000Sstevel@tonic-gate RCSTAT_INCR(rctimers); 13010Sstevel@tonic-gate return (0); 13020Sstevel@tonic-gate } 13030Sstevel@tonic-gate 13040Sstevel@tonic-gate int 13050Sstevel@tonic-gate rdma_reachable(int addr_type, struct netbuf *addr, struct knetconfig **knconf) 13060Sstevel@tonic-gate { 13070Sstevel@tonic-gate rdma_registry_t *rp; 13080Sstevel@tonic-gate void *handle = NULL; 13090Sstevel@tonic-gate struct knetconfig *knc; 13100Sstevel@tonic-gate char *pf, *p; 13110Sstevel@tonic-gate rdma_stat status; 13120Sstevel@tonic-gate int error = 0; 13130Sstevel@tonic-gate 13140Sstevel@tonic-gate if (!INGLOBALZONE(curproc)) 13150Sstevel@tonic-gate return (-1); 13167387SRobert.Gordon@Sun.COM 13170Sstevel@tonic-gate /* 13180Sstevel@tonic-gate * modload the RDMA plugins if not already done. 13190Sstevel@tonic-gate */ 13200Sstevel@tonic-gate if (!rdma_modloaded) { 13210Sstevel@tonic-gate mutex_enter(&rdma_modload_lock); 13220Sstevel@tonic-gate if (!rdma_modloaded) { 13230Sstevel@tonic-gate error = rdma_modload(); 13240Sstevel@tonic-gate } 13250Sstevel@tonic-gate mutex_exit(&rdma_modload_lock); 13260Sstevel@tonic-gate if (error) 13270Sstevel@tonic-gate return (-1); 13280Sstevel@tonic-gate } 13290Sstevel@tonic-gate 13300Sstevel@tonic-gate if (!rdma_dev_available) 13310Sstevel@tonic-gate return (-1); 13320Sstevel@tonic-gate 13330Sstevel@tonic-gate rw_enter(&rdma_lock, RW_READER); 13340Sstevel@tonic-gate rp = rdma_mod_head; 13350Sstevel@tonic-gate while (rp != NULL) { 13368695SRajkumar.Sivaprakasam@Sun.COM if (rp->r_mod_state == RDMA_MOD_INACTIVE) { 13378695SRajkumar.Sivaprakasam@Sun.COM rp = rp->r_next; 13388695SRajkumar.Sivaprakasam@Sun.COM continue; 13398695SRajkumar.Sivaprakasam@Sun.COM } 13400Sstevel@tonic-gate status = RDMA_REACHABLE(rp->r_mod->rdma_ops, addr_type, addr, 13410Sstevel@tonic-gate &handle); 13420Sstevel@tonic-gate if (status == RDMA_SUCCESS) { 13430Sstevel@tonic-gate knc = kmem_zalloc(sizeof (struct knetconfig), 13447387SRobert.Gordon@Sun.COM KM_SLEEP); 13450Sstevel@tonic-gate knc->knc_semantics = NC_TPI_RDMA; 13460Sstevel@tonic-gate pf = kmem_alloc(KNC_STRSIZE, KM_SLEEP); 13470Sstevel@tonic-gate p = kmem_alloc(KNC_STRSIZE, KM_SLEEP); 13480Sstevel@tonic-gate if (addr_type == AF_INET) 13490Sstevel@tonic-gate (void) strncpy(pf, NC_INET, KNC_STRSIZE); 13500Sstevel@tonic-gate else if (addr_type == AF_INET6) 13510Sstevel@tonic-gate (void) strncpy(pf, NC_INET6, KNC_STRSIZE); 13520Sstevel@tonic-gate pf[KNC_STRSIZE - 1] = '\0'; 13530Sstevel@tonic-gate 13540Sstevel@tonic-gate (void) strncpy(p, rp->r_mod->rdma_api, KNC_STRSIZE); 13550Sstevel@tonic-gate p[KNC_STRSIZE - 1] = '\0'; 13560Sstevel@tonic-gate 13570Sstevel@tonic-gate knc->knc_protofmly = pf; 13580Sstevel@tonic-gate knc->knc_proto = p; 13598695SRajkumar.Sivaprakasam@Sun.COM knc->knc_rdev = (dev_t)rp; 13600Sstevel@tonic-gate *knconf = knc; 13610Sstevel@tonic-gate rw_exit(&rdma_lock); 13620Sstevel@tonic-gate return (0); 13630Sstevel@tonic-gate } 13640Sstevel@tonic-gate rp = rp->r_next; 13650Sstevel@tonic-gate } 13660Sstevel@tonic-gate rw_exit(&rdma_lock); 13670Sstevel@tonic-gate return (-1); 13680Sstevel@tonic-gate } 1369