17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50a701b1eSRobert Gordon * Common Development and Distribution License (the "License"). 60a701b1eSRobert Gordon * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22e11c3f44Smeem * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 260a701b1eSRobert Gordon /* 270a701b1eSRobert Gordon * Copyright (c) 2007, The Ohio State University. All rights reserved. 280a701b1eSRobert Gordon * 290a701b1eSRobert Gordon * Portions of this source code is developed by the team members of 300a701b1eSRobert Gordon * The Ohio State University's Network-Based Computing Laboratory (NBCL), 310a701b1eSRobert Gordon * headed by Professor Dhabaleswar K. (DK) Panda. 320a701b1eSRobert Gordon * 330a701b1eSRobert Gordon * Acknowledgements to contributions from developors: 340a701b1eSRobert Gordon * Ranjit Noronha: noronha@cse.ohio-state.edu 350a701b1eSRobert Gordon * Lei Chai : chail@cse.ohio-state.edu 360a701b1eSRobert Gordon * Weikuan Yu : yuw@cse.ohio-state.edu 370a701b1eSRobert Gordon * 380a701b1eSRobert Gordon */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * The rpcib plugin. Implements the interface for RDMATF's 427c478bd9Sstevel@tonic-gate * interaction with IBTF. 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #include <sys/param.h> 467c478bd9Sstevel@tonic-gate #include <sys/types.h> 477c478bd9Sstevel@tonic-gate #include <sys/user.h> 487c478bd9Sstevel@tonic-gate #include <sys/systm.h> 497c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 507c478bd9Sstevel@tonic-gate #include <sys/proc.h> 517c478bd9Sstevel@tonic-gate #include <sys/socket.h> 527c478bd9Sstevel@tonic-gate #include <sys/file.h> 537c478bd9Sstevel@tonic-gate #include <sys/stream.h> 547c478bd9Sstevel@tonic-gate #include <sys/strsubr.h> 557c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 567c478bd9Sstevel@tonic-gate #include <sys/errno.h> 577c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 587c478bd9Sstevel@tonic-gate #include <sys/debug.h> 597c478bd9Sstevel@tonic-gate #include <sys/pathname.h> 607c478bd9Sstevel@tonic-gate #include <sys/kstat.h> 617c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 627c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 637c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 647c478bd9Sstevel@tonic-gate #include <sys/time.h> 657c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 667c478bd9Sstevel@tonic-gate #include <sys/callb.h> 677c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 687c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 690a701b1eSRobert Gordon #include <sys/sdt.h> 707c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/ibti.h> 717c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 727c478bd9Sstevel@tonic-gate #include <rpc/ib.h> 737c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 747c478bd9Sstevel@tonic-gate #include <sys/kstr.h> 757c478bd9Sstevel@tonic-gate #include <sys/sockio.h> 767c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 777c478bd9Sstevel@tonic-gate #include <sys/tiuser.h> 787c478bd9Sstevel@tonic-gate #include <net/if.h> 79e11c3f44Smeem #include <net/if_types.h> 807c478bd9Sstevel@tonic-gate #include <sys/cred.h> 810a701b1eSRobert Gordon #include <rpc/rpc_rdma.h> 820a701b1eSRobert Gordon #include <nfs/nfs.h> 830a701b1eSRobert Gordon #include <sys/atomic.h> 840a701b1eSRobert Gordon 85f837ee4aSSiddheshwar Mahesh #define NFS_RDMA_PORT 20049 86f837ee4aSSiddheshwar Mahesh 877c478bd9Sstevel@tonic-gate 88e11c3f44Smeem /* 89214ae7d0SSiddheshwar Mahesh * Convenience structures for connection management 90e11c3f44Smeem */ 91e11c3f44Smeem typedef struct rpcib_ipaddrs { 92e11c3f44Smeem void *ri_list; /* pointer to list of addresses */ 93e11c3f44Smeem uint_t ri_count; /* number of addresses in list */ 94e11c3f44Smeem uint_t ri_size; /* size of ri_list in bytes */ 95e11c3f44Smeem } rpcib_ipaddrs_t; 967c478bd9Sstevel@tonic-gate 97214ae7d0SSiddheshwar Mahesh 98214ae7d0SSiddheshwar Mahesh typedef struct rpcib_ping { 99214ae7d0SSiddheshwar Mahesh rib_hca_t *hca; 100214ae7d0SSiddheshwar Mahesh ibt_path_info_t path; 101214ae7d0SSiddheshwar Mahesh ibt_ip_addr_t srcip; 102214ae7d0SSiddheshwar Mahesh ibt_ip_addr_t dstip; 103214ae7d0SSiddheshwar Mahesh } rpcib_ping_t; 104214ae7d0SSiddheshwar Mahesh 1057c478bd9Sstevel@tonic-gate /* 1067c478bd9Sstevel@tonic-gate * Prototype declarations for driver ops 1077c478bd9Sstevel@tonic-gate */ 1087c478bd9Sstevel@tonic-gate static int rpcib_attach(dev_info_t *, ddi_attach_cmd_t); 1097c478bd9Sstevel@tonic-gate static int rpcib_getinfo(dev_info_t *, ddi_info_cmd_t, 1107c478bd9Sstevel@tonic-gate void *, void **); 1117c478bd9Sstevel@tonic-gate static int rpcib_detach(dev_info_t *, ddi_detach_cmd_t); 112e11c3f44Smeem static boolean_t rpcib_rdma_capable_interface(struct lifreq *); 113e11c3f44Smeem static int rpcib_do_ip_ioctl(int, int, void *); 114e11c3f44Smeem static boolean_t rpcib_get_ib_addresses(rpcib_ipaddrs_t *, rpcib_ipaddrs_t *); 1150a701b1eSRobert Gordon static int rpcib_cache_kstat_update(kstat_t *, int); 1160a701b1eSRobert Gordon static void rib_force_cleanup(void *); 1177f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static void rib_stop_hca_services(rib_hca_t *); 1187f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static void rib_attach_hca(void); 1197f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static int rib_find_hca_connection(rib_hca_t *hca, struct netbuf *s_svcaddr, 1207f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States struct netbuf *d_svcaddr, CONN **conn); 1217c478bd9Sstevel@tonic-gate 1220a701b1eSRobert Gordon struct { 1230a701b1eSRobert Gordon kstat_named_t cache_limit; 1240a701b1eSRobert Gordon kstat_named_t cache_allocation; 1250a701b1eSRobert Gordon kstat_named_t cache_hits; 1260a701b1eSRobert Gordon kstat_named_t cache_misses; 1270a701b1eSRobert Gordon kstat_named_t cache_misses_above_the_limit; 1280a701b1eSRobert Gordon } rpcib_kstat = { 1290a701b1eSRobert Gordon {"cache_limit", KSTAT_DATA_UINT64 }, 1300a701b1eSRobert Gordon {"cache_allocation", KSTAT_DATA_UINT64 }, 1310a701b1eSRobert Gordon {"cache_hits", KSTAT_DATA_UINT64 }, 1320a701b1eSRobert Gordon {"cache_misses", KSTAT_DATA_UINT64 }, 1330a701b1eSRobert Gordon {"cache_misses_above_the_limit", KSTAT_DATA_UINT64 }, 1340a701b1eSRobert Gordon }; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* rpcib cb_ops */ 1377c478bd9Sstevel@tonic-gate static struct cb_ops rpcib_cbops = { 1387c478bd9Sstevel@tonic-gate nulldev, /* open */ 1397c478bd9Sstevel@tonic-gate nulldev, /* close */ 1407c478bd9Sstevel@tonic-gate nodev, /* strategy */ 1417c478bd9Sstevel@tonic-gate nodev, /* print */ 1427c478bd9Sstevel@tonic-gate nodev, /* dump */ 1437c478bd9Sstevel@tonic-gate nodev, /* read */ 1447c478bd9Sstevel@tonic-gate nodev, /* write */ 1457c478bd9Sstevel@tonic-gate nodev, /* ioctl */ 1467c478bd9Sstevel@tonic-gate nodev, /* devmap */ 1477c478bd9Sstevel@tonic-gate nodev, /* mmap */ 1487c478bd9Sstevel@tonic-gate nodev, /* segmap */ 1497c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 1507c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 1517c478bd9Sstevel@tonic-gate NULL, /* stream */ 1527c478bd9Sstevel@tonic-gate D_MP, /* cb_flag */ 1537c478bd9Sstevel@tonic-gate CB_REV, /* rev */ 1547c478bd9Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 1557c478bd9Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 1567c478bd9Sstevel@tonic-gate }; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* 1597c478bd9Sstevel@tonic-gate * Device options 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate static struct dev_ops rpcib_ops = { 1627c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 1637c478bd9Sstevel@tonic-gate 0, /* refcnt */ 1647c478bd9Sstevel@tonic-gate rpcib_getinfo, /* info */ 1657c478bd9Sstevel@tonic-gate nulldev, /* identify */ 1667c478bd9Sstevel@tonic-gate nulldev, /* probe */ 1677c478bd9Sstevel@tonic-gate rpcib_attach, /* attach */ 1687c478bd9Sstevel@tonic-gate rpcib_detach, /* detach */ 1697c478bd9Sstevel@tonic-gate nodev, /* reset */ 1707c478bd9Sstevel@tonic-gate &rpcib_cbops, /* driver ops - devctl interfaces */ 1717c478bd9Sstevel@tonic-gate NULL, /* bus operations */ 17219397407SSherry Moore NULL, /* power */ 17319397407SSherry Moore ddi_quiesce_not_needed, /* quiesce */ 1747c478bd9Sstevel@tonic-gate }; 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate /* 1777c478bd9Sstevel@tonic-gate * Module linkage information. 1787c478bd9Sstevel@tonic-gate */ 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate static struct modldrv rib_modldrv = { 1817c478bd9Sstevel@tonic-gate &mod_driverops, /* Driver module */ 18219397407SSherry Moore "RPCIB plugin driver", /* Driver name and version */ 1837c478bd9Sstevel@tonic-gate &rpcib_ops, /* Driver ops */ 1847c478bd9Sstevel@tonic-gate }; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate static struct modlinkage rib_modlinkage = { 1877c478bd9Sstevel@tonic-gate MODREV_1, 1887c478bd9Sstevel@tonic-gate (void *)&rib_modldrv, 1897c478bd9Sstevel@tonic-gate NULL 1907c478bd9Sstevel@tonic-gate }; 1917c478bd9Sstevel@tonic-gate 1920a701b1eSRobert Gordon typedef struct rib_lrc_entry { 1930a701b1eSRobert Gordon struct rib_lrc_entry *forw; 1940a701b1eSRobert Gordon struct rib_lrc_entry *back; 1950a701b1eSRobert Gordon char *lrc_buf; 1960a701b1eSRobert Gordon 1970a701b1eSRobert Gordon uint32_t lrc_len; 1980a701b1eSRobert Gordon void *avl_node; 1990a701b1eSRobert Gordon bool_t registered; 2000a701b1eSRobert Gordon 2010a701b1eSRobert Gordon struct mrc lrc_mhandle; 2020a701b1eSRobert Gordon bool_t lrc_on_freed_list; 2030a701b1eSRobert Gordon } rib_lrc_entry_t; 2040a701b1eSRobert Gordon 2050a701b1eSRobert Gordon typedef struct cache_struct { 2060a701b1eSRobert Gordon rib_lrc_entry_t r; 2070a701b1eSRobert Gordon uint32_t len; 2080a701b1eSRobert Gordon uint32_t elements; 2090a701b1eSRobert Gordon kmutex_t node_lock; 2100a701b1eSRobert Gordon avl_node_t avl_link; 2110a701b1eSRobert Gordon } cache_avl_struct_t; 2120a701b1eSRobert Gordon 2130a701b1eSRobert Gordon uint64_t cache_limit = 100 * 1024 * 1024; 2140a701b1eSRobert Gordon static uint64_t cache_watermark = 80 * 1024 * 1024; 2150a701b1eSRobert Gordon static bool_t stats_enabled = FALSE; 2160a701b1eSRobert Gordon 2170a701b1eSRobert Gordon static uint64_t max_unsignaled_rws = 5; 218f837ee4aSSiddheshwar Mahesh int nfs_rdma_port = NFS_RDMA_PORT; 2190a701b1eSRobert Gordon 220*7523bef8SSiddheshwar Mahesh #define RIBNETID_TCP "tcp" 221*7523bef8SSiddheshwar Mahesh #define RIBNETID_TCP6 "tcp6" 222*7523bef8SSiddheshwar Mahesh 2237c478bd9Sstevel@tonic-gate /* 2247c478bd9Sstevel@tonic-gate * rib_stat: private data pointer used when registering 2257c478bd9Sstevel@tonic-gate * with the IBTF. It is returned to the consumer 2267c478bd9Sstevel@tonic-gate * in all callbacks. 2277c478bd9Sstevel@tonic-gate */ 2287c478bd9Sstevel@tonic-gate static rpcib_state_t *rib_stat = NULL; 2297c478bd9Sstevel@tonic-gate 2300a701b1eSRobert Gordon #define RNR_RETRIES IBT_RNR_RETRY_1 2317c478bd9Sstevel@tonic-gate #define MAX_PORTS 2 232065714dcSSiddheshwar Mahesh #define RDMA_DUMMY_WRID 0x4D3A1D4D3A1D 233065714dcSSiddheshwar Mahesh #define RDMA_CONN_REAP_RETRY 10 /* 10 secs */ 2347c478bd9Sstevel@tonic-gate 2350a701b1eSRobert Gordon int preposted_rbufs = RDMA_BUFS_GRANT; 2367c478bd9Sstevel@tonic-gate int send_threshold = 1; 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* 239065714dcSSiddheshwar Mahesh * Old cards with Tavor driver have limited memory footprint 240065714dcSSiddheshwar Mahesh * when booted in 32bit. The rib_max_rbufs tunable can be 241065714dcSSiddheshwar Mahesh * tuned for more buffers if needed. 242065714dcSSiddheshwar Mahesh */ 243065714dcSSiddheshwar Mahesh 244065714dcSSiddheshwar Mahesh #if !defined(_ELF64) && !defined(__sparc) 245065714dcSSiddheshwar Mahesh int rib_max_rbufs = MAX_BUFS; 246065714dcSSiddheshwar Mahesh #else 247065714dcSSiddheshwar Mahesh int rib_max_rbufs = 10 * MAX_BUFS; 248065714dcSSiddheshwar Mahesh #endif /* !(_ELF64) && !(__sparc) */ 249065714dcSSiddheshwar Mahesh 250065714dcSSiddheshwar Mahesh int rib_conn_timeout = 60 * 12; /* 12 minutes */ 251065714dcSSiddheshwar Mahesh 252065714dcSSiddheshwar Mahesh /* 2537c478bd9Sstevel@tonic-gate * State of the plugin. 2547c478bd9Sstevel@tonic-gate * ACCEPT = accepting new connections and requests. 2557c478bd9Sstevel@tonic-gate * NO_ACCEPT = not accepting new connection and requests. 2567c478bd9Sstevel@tonic-gate * This should eventually move to rpcib_state_t structure, since this 2577c478bd9Sstevel@tonic-gate * will tell in which state the plugin is for a particular type of service 2587c478bd9Sstevel@tonic-gate * like NFS, NLM or v4 Callback deamon. The plugin might be in accept 2597c478bd9Sstevel@tonic-gate * state for one and in no_accept state for the other. 2607c478bd9Sstevel@tonic-gate */ 2617c478bd9Sstevel@tonic-gate int plugin_state; 2627c478bd9Sstevel@tonic-gate kmutex_t plugin_state_lock; 2637c478bd9Sstevel@tonic-gate 2640a701b1eSRobert Gordon ldi_ident_t rpcib_li; 2657c478bd9Sstevel@tonic-gate 2667c478bd9Sstevel@tonic-gate /* 2677c478bd9Sstevel@tonic-gate * RPCIB RDMATF operations 2687c478bd9Sstevel@tonic-gate */ 2697c478bd9Sstevel@tonic-gate static rdma_stat rib_reachable(int addr_type, struct netbuf *, void **handle); 2707c478bd9Sstevel@tonic-gate static rdma_stat rib_disconnect(CONN *conn); 2717c478bd9Sstevel@tonic-gate static void rib_listen(struct rdma_svc_data *rd); 2727c478bd9Sstevel@tonic-gate static void rib_listen_stop(struct rdma_svc_data *rd); 2730a701b1eSRobert Gordon static rdma_stat rib_registermem(CONN *conn, caddr_t adsp, caddr_t buf, 2740a701b1eSRobert Gordon uint_t buflen, struct mrc *buf_handle); 2757c478bd9Sstevel@tonic-gate static rdma_stat rib_deregistermem(CONN *conn, caddr_t buf, 2767c478bd9Sstevel@tonic-gate struct mrc buf_handle); 2770a701b1eSRobert Gordon static rdma_stat rib_registermem_via_hca(rib_hca_t *hca, caddr_t adsp, 2780a701b1eSRobert Gordon caddr_t buf, uint_t buflen, struct mrc *buf_handle); 2790a701b1eSRobert Gordon static rdma_stat rib_deregistermem_via_hca(rib_hca_t *hca, caddr_t buf, 2800a701b1eSRobert Gordon struct mrc buf_handle); 2810a701b1eSRobert Gordon static rdma_stat rib_registermemsync(CONN *conn, caddr_t adsp, caddr_t buf, 2820a701b1eSRobert Gordon uint_t buflen, struct mrc *buf_handle, RIB_SYNCMEM_HANDLE *sync_handle, 2830a701b1eSRobert Gordon void *lrc); 2847c478bd9Sstevel@tonic-gate static rdma_stat rib_deregistermemsync(CONN *conn, caddr_t buf, 2850a701b1eSRobert Gordon struct mrc buf_handle, RIB_SYNCMEM_HANDLE sync_handle, void *); 2867c478bd9Sstevel@tonic-gate static rdma_stat rib_syncmem(CONN *conn, RIB_SYNCMEM_HANDLE shandle, 2877c478bd9Sstevel@tonic-gate caddr_t buf, int len, int cpu); 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate static rdma_stat rib_reg_buf_alloc(CONN *conn, rdma_buf_t *rdbuf); 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate static void rib_reg_buf_free(CONN *conn, rdma_buf_t *rdbuf); 2927c478bd9Sstevel@tonic-gate static void *rib_rbuf_alloc(CONN *, rdma_buf_t *); 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate static void rib_rbuf_free(CONN *conn, int ptype, void *buf); 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate static rdma_stat rib_send(CONN *conn, struct clist *cl, uint32_t msgid); 2977c478bd9Sstevel@tonic-gate static rdma_stat rib_send_resp(CONN *conn, struct clist *cl, uint32_t msgid); 2987c478bd9Sstevel@tonic-gate static rdma_stat rib_post_resp(CONN *conn, struct clist *cl, uint32_t msgid); 2990a701b1eSRobert Gordon static rdma_stat rib_post_resp_remove(CONN *conn, uint32_t msgid); 3007c478bd9Sstevel@tonic-gate static rdma_stat rib_post_recv(CONN *conn, struct clist *cl); 3017c478bd9Sstevel@tonic-gate static rdma_stat rib_recv(CONN *conn, struct clist **clp, uint32_t msgid); 3027c478bd9Sstevel@tonic-gate static rdma_stat rib_read(CONN *conn, struct clist *cl, int wait); 3037c478bd9Sstevel@tonic-gate static rdma_stat rib_write(CONN *conn, struct clist *cl, int wait); 304214ae7d0SSiddheshwar Mahesh static rdma_stat rib_ping_srv(int addr_type, struct netbuf *, rpcib_ping_t *); 3057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static rdma_stat rib_conn_get(struct netbuf *, struct netbuf *, 3067f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States int addr_type, void *, CONN **); 3077c478bd9Sstevel@tonic-gate static rdma_stat rib_conn_release(CONN *conn); 308ed629aefSSiddheshwar Mahesh static rdma_stat rib_connect(struct netbuf *, struct netbuf *, int, 309ed629aefSSiddheshwar Mahesh rpcib_ping_t *, CONN **); 3107c478bd9Sstevel@tonic-gate static rdma_stat rib_getinfo(rdma_info_t *info); 3110a701b1eSRobert Gordon 3120a701b1eSRobert Gordon static rib_lrc_entry_t *rib_get_cache_buf(CONN *conn, uint32_t len); 3130a701b1eSRobert Gordon static void rib_free_cache_buf(CONN *conn, rib_lrc_entry_t *buf); 3140a701b1eSRobert Gordon static void rib_destroy_cache(rib_hca_t *hca); 3150a701b1eSRobert Gordon static void rib_server_side_cache_reclaim(void *argp); 3160a701b1eSRobert Gordon static int avl_compare(const void *t1, const void *t2); 3170a701b1eSRobert Gordon 3187c478bd9Sstevel@tonic-gate static void rib_stop_services(rib_hca_t *); 3190a701b1eSRobert Gordon static void rib_close_channels(rib_conn_list_t *); 320065714dcSSiddheshwar Mahesh static void rib_conn_close(void *); 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate /* 3237c478bd9Sstevel@tonic-gate * RPCIB addressing operations 3247c478bd9Sstevel@tonic-gate */ 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate /* 3277c478bd9Sstevel@tonic-gate * RDMA operations the RPCIB module exports 3287c478bd9Sstevel@tonic-gate */ 3297c478bd9Sstevel@tonic-gate static rdmaops_t rib_ops = { 3307c478bd9Sstevel@tonic-gate rib_reachable, 3317c478bd9Sstevel@tonic-gate rib_conn_get, 3327c478bd9Sstevel@tonic-gate rib_conn_release, 3337c478bd9Sstevel@tonic-gate rib_listen, 3347c478bd9Sstevel@tonic-gate rib_listen_stop, 3357c478bd9Sstevel@tonic-gate rib_registermem, 3367c478bd9Sstevel@tonic-gate rib_deregistermem, 3377c478bd9Sstevel@tonic-gate rib_registermemsync, 3387c478bd9Sstevel@tonic-gate rib_deregistermemsync, 3397c478bd9Sstevel@tonic-gate rib_syncmem, 3407c478bd9Sstevel@tonic-gate rib_reg_buf_alloc, 3417c478bd9Sstevel@tonic-gate rib_reg_buf_free, 3427c478bd9Sstevel@tonic-gate rib_send, 3437c478bd9Sstevel@tonic-gate rib_send_resp, 3447c478bd9Sstevel@tonic-gate rib_post_resp, 3450a701b1eSRobert Gordon rib_post_resp_remove, 3467c478bd9Sstevel@tonic-gate rib_post_recv, 3477c478bd9Sstevel@tonic-gate rib_recv, 3487c478bd9Sstevel@tonic-gate rib_read, 3497c478bd9Sstevel@tonic-gate rib_write, 3500a701b1eSRobert Gordon rib_getinfo, 3517c478bd9Sstevel@tonic-gate }; 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate /* 3547c478bd9Sstevel@tonic-gate * RDMATF RPCIB plugin details 3557c478bd9Sstevel@tonic-gate */ 3567c478bd9Sstevel@tonic-gate static rdma_mod_t rib_mod = { 3577c478bd9Sstevel@tonic-gate "ibtf", /* api name */ 3587c478bd9Sstevel@tonic-gate RDMATF_VERS_1, 3597c478bd9Sstevel@tonic-gate 0, 3607c478bd9Sstevel@tonic-gate &rib_ops, /* rdma op vector for ibtf */ 3617c478bd9Sstevel@tonic-gate }; 3627c478bd9Sstevel@tonic-gate 3637f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static rdma_stat rpcib_open_hcas(rpcib_state_t *); 3647c478bd9Sstevel@tonic-gate static rdma_stat rib_qp_init(rib_qp_t *, int); 3657c478bd9Sstevel@tonic-gate static void rib_svc_scq_handler(ibt_cq_hdl_t, void *); 3667c478bd9Sstevel@tonic-gate static void rib_clnt_scq_handler(ibt_cq_hdl_t, void *); 3677c478bd9Sstevel@tonic-gate static void rib_clnt_rcq_handler(ibt_cq_hdl_t, void *); 3687c478bd9Sstevel@tonic-gate static void rib_svc_rcq_handler(ibt_cq_hdl_t, void *); 3697c478bd9Sstevel@tonic-gate static rib_bufpool_t *rib_rbufpool_create(rib_hca_t *hca, int ptype, int num); 3700a701b1eSRobert Gordon static rdma_stat rib_reg_mem(rib_hca_t *, caddr_t adsp, caddr_t, uint_t, 3710a701b1eSRobert Gordon ibt_mr_flags_t, ibt_mr_hdl_t *, ibt_mr_desc_t *); 3720a701b1eSRobert Gordon static rdma_stat rib_reg_mem_user(rib_hca_t *, caddr_t, uint_t, ibt_mr_flags_t, 3730a701b1eSRobert Gordon ibt_mr_hdl_t *, ibt_mr_desc_t *, caddr_t); 374214ae7d0SSiddheshwar Mahesh static rdma_stat rib_conn_to_srv(rib_hca_t *, rib_qp_t *, rpcib_ping_t *); 3757c478bd9Sstevel@tonic-gate static rdma_stat rib_clnt_create_chan(rib_hca_t *, struct netbuf *, 3767c478bd9Sstevel@tonic-gate rib_qp_t **); 3777c478bd9Sstevel@tonic-gate static rdma_stat rib_svc_create_chan(rib_hca_t *, caddr_t, uint8_t, 3787c478bd9Sstevel@tonic-gate rib_qp_t **); 3797c478bd9Sstevel@tonic-gate static rdma_stat rib_sendwait(rib_qp_t *, struct send_wid *); 3807c478bd9Sstevel@tonic-gate static struct send_wid *rib_init_sendwait(uint32_t, int, rib_qp_t *); 3817c478bd9Sstevel@tonic-gate static int rib_free_sendwait(struct send_wid *); 3827c478bd9Sstevel@tonic-gate static struct rdma_done_list *rdma_done_add(rib_qp_t *qp, uint32_t xid); 3837c478bd9Sstevel@tonic-gate static void rdma_done_rm(rib_qp_t *qp, struct rdma_done_list *rd); 3847c478bd9Sstevel@tonic-gate static void rdma_done_rem_list(rib_qp_t *); 3857c478bd9Sstevel@tonic-gate static void rdma_done_notify(rib_qp_t *qp, uint32_t xid); 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate static void rib_async_handler(void *, 3887c478bd9Sstevel@tonic-gate ibt_hca_hdl_t, ibt_async_code_t, ibt_async_event_t *); 3897c478bd9Sstevel@tonic-gate static rdma_stat rib_rem_rep(rib_qp_t *, struct reply *); 3907c478bd9Sstevel@tonic-gate static struct svc_recv *rib_init_svc_recv(rib_qp_t *, ibt_wr_ds_t *); 3917c478bd9Sstevel@tonic-gate static int rib_free_svc_recv(struct svc_recv *); 3927c478bd9Sstevel@tonic-gate static struct recv_wid *rib_create_wid(rib_qp_t *, ibt_wr_ds_t *, uint32_t); 3937c478bd9Sstevel@tonic-gate static void rib_free_wid(struct recv_wid *); 3947c478bd9Sstevel@tonic-gate static rdma_stat rib_disconnect_channel(CONN *, rib_conn_list_t *); 3957c478bd9Sstevel@tonic-gate static void rib_detach_hca(rib_hca_t *); 396065714dcSSiddheshwar Mahesh static void rib_close_a_channel(CONN *); 397065714dcSSiddheshwar Mahesh static void rib_send_hold(rib_qp_t *); 398065714dcSSiddheshwar Mahesh static void rib_send_rele(rib_qp_t *); 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate /* 4017c478bd9Sstevel@tonic-gate * Registration with IBTF as a consumer 4027c478bd9Sstevel@tonic-gate */ 4037c478bd9Sstevel@tonic-gate static struct ibt_clnt_modinfo_s rib_modinfo = { 40403494a98SBill Taylor IBTI_V_CURR, 4057c478bd9Sstevel@tonic-gate IBT_GENERIC, 4067c478bd9Sstevel@tonic-gate rib_async_handler, /* async event handler */ 4077c478bd9Sstevel@tonic-gate NULL, /* Memory Region Handler */ 4087c478bd9Sstevel@tonic-gate "nfs/ib" 4097c478bd9Sstevel@tonic-gate }; 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate /* 4127c478bd9Sstevel@tonic-gate * Global strucuture 4137c478bd9Sstevel@tonic-gate */ 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate typedef struct rpcib_s { 4167c478bd9Sstevel@tonic-gate dev_info_t *rpcib_dip; 4177c478bd9Sstevel@tonic-gate kmutex_t rpcib_mutex; 4187c478bd9Sstevel@tonic-gate } rpcib_t; 4197c478bd9Sstevel@tonic-gate 4207c478bd9Sstevel@tonic-gate rpcib_t rpcib; 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate /* 4237c478bd9Sstevel@tonic-gate * /etc/system controlled variable to control 4247c478bd9Sstevel@tonic-gate * debugging in rpcib kernel module. 4257c478bd9Sstevel@tonic-gate * Set it to values greater that 1 to control 4267c478bd9Sstevel@tonic-gate * the amount of debugging messages required. 4277c478bd9Sstevel@tonic-gate */ 4287c478bd9Sstevel@tonic-gate int rib_debug = 0; 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate int 4317c478bd9Sstevel@tonic-gate _init(void) 4327c478bd9Sstevel@tonic-gate { 4337c478bd9Sstevel@tonic-gate int error; 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate error = mod_install((struct modlinkage *)&rib_modlinkage); 4367c478bd9Sstevel@tonic-gate if (error != 0) { 4377c478bd9Sstevel@tonic-gate /* 4387c478bd9Sstevel@tonic-gate * Could not load module 4397c478bd9Sstevel@tonic-gate */ 4407c478bd9Sstevel@tonic-gate return (error); 4417c478bd9Sstevel@tonic-gate } 4427c478bd9Sstevel@tonic-gate mutex_init(&plugin_state_lock, NULL, MUTEX_DRIVER, NULL); 4437c478bd9Sstevel@tonic-gate return (0); 4447c478bd9Sstevel@tonic-gate } 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate int 4477c478bd9Sstevel@tonic-gate _fini() 4487c478bd9Sstevel@tonic-gate { 4497c478bd9Sstevel@tonic-gate int status; 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate /* 4527c478bd9Sstevel@tonic-gate * Remove module 4537c478bd9Sstevel@tonic-gate */ 4547c478bd9Sstevel@tonic-gate if ((status = mod_remove(&rib_modlinkage)) != 0) { 4557c478bd9Sstevel@tonic-gate return (status); 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate mutex_destroy(&plugin_state_lock); 4587c478bd9Sstevel@tonic-gate return (0); 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate int 4627c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 4637c478bd9Sstevel@tonic-gate { 4647c478bd9Sstevel@tonic-gate return (mod_info(&rib_modlinkage, modinfop)); 4657c478bd9Sstevel@tonic-gate } 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate /* 4687c478bd9Sstevel@tonic-gate * rpcib_getinfo() 4697c478bd9Sstevel@tonic-gate * Given the device number, return the devinfo pointer or the 4707c478bd9Sstevel@tonic-gate * instance number. 4717c478bd9Sstevel@tonic-gate * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach. 4727c478bd9Sstevel@tonic-gate */ 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4757c478bd9Sstevel@tonic-gate static int 4767c478bd9Sstevel@tonic-gate rpcib_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 4777c478bd9Sstevel@tonic-gate { 4787c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate switch (cmd) { 4817c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 4827c478bd9Sstevel@tonic-gate if (rpcib.rpcib_dip != NULL) 4837c478bd9Sstevel@tonic-gate *result = rpcib.rpcib_dip; 4847c478bd9Sstevel@tonic-gate else { 4857c478bd9Sstevel@tonic-gate *result = NULL; 4867c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 4877c478bd9Sstevel@tonic-gate } 4887c478bd9Sstevel@tonic-gate break; 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 4917c478bd9Sstevel@tonic-gate *result = NULL; 4927c478bd9Sstevel@tonic-gate break; 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate default: 4957c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 4967c478bd9Sstevel@tonic-gate } 4977c478bd9Sstevel@tonic-gate return (ret); 4987c478bd9Sstevel@tonic-gate } 4997c478bd9Sstevel@tonic-gate 5007f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static void 5017f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib_free_hca_list() 5027f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States { 5037f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_hca_t *hca, *hcap; 5047f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 5057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&rib_stat->hcas_list_lock, RW_WRITER); 5067f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca = rib_stat->hcas_list; 5077f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stat->hcas_list = NULL; 5087f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->hcas_list_lock); 5097f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States while (hca != NULL) { 5107f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&hca->state_lock, RW_WRITER); 5117f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hcap = hca; 5127f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca = hca->next; 5137f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stat->nhca_inited--; 5147f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_mod.rdma_count--; 5157f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hcap->state = HCA_DETACHED; 5167f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hcap->state_lock); 5177f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stop_hca_services(hcap); 5187f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 5197f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States kmem_free(hcap, sizeof (*hcap)); 5207f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 5217f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 5227f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 5237f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static rdma_stat 5247f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib_free_service_list() 5257f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States { 5267f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_service_t *service; 5277f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ibt_status_t ret; 5287f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 5297f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&rib_stat->service_list_lock, RW_WRITER); 5307f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States while (rib_stat->service_list != NULL) { 5317f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States service = rib_stat->service_list; 5327f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ret = ibt_unbind_all_services(service->srv_hdl); 5337f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (ret != IBT_SUCCESS) { 5347f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->service_list_lock); 5357f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States #ifdef DEBUG 5367f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States cmn_err(CE_NOTE, "rpcib_free_service_list: " 5377f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States "ibt_unbind_all_services failed (%d)\n", (int)ret); 5387f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States #endif 5397f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (RDMA_FAILED); 5407f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 5417f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ret = ibt_deregister_service(rib_stat->ibt_clnt_hdl, 5427f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States service->srv_hdl); 5437f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (ret != IBT_SUCCESS) { 5447f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->service_list_lock); 5457f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States #ifdef DEBUG 5467f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States cmn_err(CE_NOTE, "rpcib_free_service_list: " 5477f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States "ibt_deregister_service failed (%d)\n", (int)ret); 5487f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States #endif 5497f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (RDMA_FAILED); 5507f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 5517f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stat->service_list = service->next; 5527f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States kmem_free(service, sizeof (rib_service_t)); 5537f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 5547f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->service_list_lock); 5557f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 5567f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (RDMA_SUCCESS); 5577f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 5587f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 5597c478bd9Sstevel@tonic-gate static int 5607c478bd9Sstevel@tonic-gate rpcib_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 5617c478bd9Sstevel@tonic-gate { 5627c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 5637c478bd9Sstevel@tonic-gate rdma_stat r_status; 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate switch (cmd) { 5667c478bd9Sstevel@tonic-gate case DDI_ATTACH: 5677c478bd9Sstevel@tonic-gate break; 5687c478bd9Sstevel@tonic-gate case DDI_RESUME: 5697c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5707c478bd9Sstevel@tonic-gate default: 5717c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5727c478bd9Sstevel@tonic-gate } 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate mutex_init(&rpcib.rpcib_mutex, NULL, MUTEX_DRIVER, NULL); 5757c478bd9Sstevel@tonic-gate 5767c478bd9Sstevel@tonic-gate mutex_enter(&rpcib.rpcib_mutex); 5777c478bd9Sstevel@tonic-gate if (rpcib.rpcib_dip != NULL) { 5787c478bd9Sstevel@tonic-gate mutex_exit(&rpcib.rpcib_mutex); 5797c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5807c478bd9Sstevel@tonic-gate } 5817c478bd9Sstevel@tonic-gate rpcib.rpcib_dip = dip; 5827c478bd9Sstevel@tonic-gate mutex_exit(&rpcib.rpcib_mutex); 5837c478bd9Sstevel@tonic-gate /* 5847c478bd9Sstevel@tonic-gate * Create the "rpcib" minor-node. 5857c478bd9Sstevel@tonic-gate */ 5867c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, 5877c478bd9Sstevel@tonic-gate "rpcib", S_IFCHR, 0, DDI_PSEUDO, 0) != DDI_SUCCESS) { 5887c478bd9Sstevel@tonic-gate /* Error message, no cmn_err as they print on console */ 5897c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5907c478bd9Sstevel@tonic-gate } 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate if (rib_stat == NULL) { 5937c478bd9Sstevel@tonic-gate rib_stat = kmem_zalloc(sizeof (*rib_stat), KM_SLEEP); 5947c478bd9Sstevel@tonic-gate mutex_init(&rib_stat->open_hca_lock, NULL, MUTEX_DRIVER, NULL); 5957f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_init(&rib_stat->hcas_list_lock, NULL, RW_DRIVER, NULL); 5967f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_init(&rib_stat->listen_lock, NULL, MUTEX_DRIVER, NULL); 5977c478bd9Sstevel@tonic-gate } 5987c478bd9Sstevel@tonic-gate 5997f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stat->hca_count = ibt_get_hca_list(NULL); 6007c478bd9Sstevel@tonic-gate if (rib_stat->hca_count < 1) { 6017f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_destroy(&rib_stat->listen_lock); 6027f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_destroy(&rib_stat->hcas_list_lock); 6037c478bd9Sstevel@tonic-gate mutex_destroy(&rib_stat->open_hca_lock); 6047c478bd9Sstevel@tonic-gate kmem_free(rib_stat, sizeof (*rib_stat)); 6057c478bd9Sstevel@tonic-gate rib_stat = NULL; 6067c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6077c478bd9Sstevel@tonic-gate } 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate ibt_status = ibt_attach(&rib_modinfo, dip, 6107c478bd9Sstevel@tonic-gate (void *)rib_stat, &rib_stat->ibt_clnt_hdl); 6110a701b1eSRobert Gordon 6127c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) { 6137f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_destroy(&rib_stat->listen_lock); 6147f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_destroy(&rib_stat->hcas_list_lock); 6157c478bd9Sstevel@tonic-gate mutex_destroy(&rib_stat->open_hca_lock); 6167c478bd9Sstevel@tonic-gate kmem_free(rib_stat, sizeof (*rib_stat)); 6177c478bd9Sstevel@tonic-gate rib_stat = NULL; 6187c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6197c478bd9Sstevel@tonic-gate } 6207c478bd9Sstevel@tonic-gate 6217f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stat->service_list = NULL; 6227f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_init(&rib_stat->service_list_lock, NULL, RW_DRIVER, NULL); 6237c478bd9Sstevel@tonic-gate mutex_enter(&rib_stat->open_hca_lock); 6247f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (rpcib_open_hcas(rib_stat) != RDMA_SUCCESS) { 6257c478bd9Sstevel@tonic-gate mutex_exit(&rib_stat->open_hca_lock); 62651f34d4bSRajkumar Sivaprakasam goto open_fail; 6277c478bd9Sstevel@tonic-gate } 6287c478bd9Sstevel@tonic-gate mutex_exit(&rib_stat->open_hca_lock); 6297c478bd9Sstevel@tonic-gate 63051f34d4bSRajkumar Sivaprakasam if (ddi_prop_update_int(DDI_DEV_T_NONE, dip, DDI_NO_AUTODETACH, 1) != 63151f34d4bSRajkumar Sivaprakasam DDI_PROP_SUCCESS) { 63251f34d4bSRajkumar Sivaprakasam cmn_err(CE_WARN, "rpcib_attach: ddi-no-autodetach prop update " 63351f34d4bSRajkumar Sivaprakasam "failed."); 63451f34d4bSRajkumar Sivaprakasam goto register_fail; 63551f34d4bSRajkumar Sivaprakasam } 63651f34d4bSRajkumar Sivaprakasam 6377c478bd9Sstevel@tonic-gate /* 6387c478bd9Sstevel@tonic-gate * Register with rdmatf 6397c478bd9Sstevel@tonic-gate */ 6407c478bd9Sstevel@tonic-gate r_status = rdma_register_mod(&rib_mod); 6417c478bd9Sstevel@tonic-gate if (r_status != RDMA_SUCCESS && r_status != RDMA_REG_EXIST) { 64251f34d4bSRajkumar Sivaprakasam cmn_err(CE_WARN, "rpcib_attach:rdma_register_mod failed, " 64351f34d4bSRajkumar Sivaprakasam "status = %d", r_status); 64451f34d4bSRajkumar Sivaprakasam goto register_fail; 64551f34d4bSRajkumar Sivaprakasam } 64651f34d4bSRajkumar Sivaprakasam 64751f34d4bSRajkumar Sivaprakasam return (DDI_SUCCESS); 64851f34d4bSRajkumar Sivaprakasam 64951f34d4bSRajkumar Sivaprakasam register_fail: 6507f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 65151f34d4bSRajkumar Sivaprakasam open_fail: 6527c478bd9Sstevel@tonic-gate (void) ibt_detach(rib_stat->ibt_clnt_hdl); 6537f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib_free_hca_list(); 6547f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (void) rpcib_free_service_list(); 6557f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_destroy(&rib_stat->listen_lock); 6567f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_destroy(&rib_stat->hcas_list_lock); 6577c478bd9Sstevel@tonic-gate mutex_destroy(&rib_stat->open_hca_lock); 6587f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_destroy(&rib_stat->service_list_lock); 6597c478bd9Sstevel@tonic-gate kmem_free(rib_stat, sizeof (*rib_stat)); 6607c478bd9Sstevel@tonic-gate rib_stat = NULL; 6617c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6627c478bd9Sstevel@tonic-gate } 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6657c478bd9Sstevel@tonic-gate static int 6667c478bd9Sstevel@tonic-gate rpcib_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 6677c478bd9Sstevel@tonic-gate { 6687c478bd9Sstevel@tonic-gate switch (cmd) { 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate case DDI_DETACH: 6717c478bd9Sstevel@tonic-gate break; 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 6747c478bd9Sstevel@tonic-gate default: 6757c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate 6787c478bd9Sstevel@tonic-gate /* 6797c478bd9Sstevel@tonic-gate * Detach the hca and free resources 6807c478bd9Sstevel@tonic-gate */ 6817c478bd9Sstevel@tonic-gate mutex_enter(&plugin_state_lock); 6827c478bd9Sstevel@tonic-gate plugin_state = NO_ACCEPT; 6837c478bd9Sstevel@tonic-gate mutex_exit(&plugin_state_lock); 6847f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 6857f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (rpcib_free_service_list() != RDMA_SUCCESS) 6867f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (DDI_FAILURE); 6877f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib_free_hca_list(); 6887f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 6897c478bd9Sstevel@tonic-gate (void) ibt_detach(rib_stat->ibt_clnt_hdl); 6907f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_destroy(&rib_stat->listen_lock); 6917f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_destroy(&rib_stat->hcas_list_lock); 69251f34d4bSRajkumar Sivaprakasam mutex_destroy(&rib_stat->open_hca_lock); 6937f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_destroy(&rib_stat->service_list_lock); 6947f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 69551f34d4bSRajkumar Sivaprakasam kmem_free(rib_stat, sizeof (*rib_stat)); 69651f34d4bSRajkumar Sivaprakasam rib_stat = NULL; 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate mutex_enter(&rpcib.rpcib_mutex); 6997c478bd9Sstevel@tonic-gate rpcib.rpcib_dip = NULL; 7007c478bd9Sstevel@tonic-gate mutex_exit(&rpcib.rpcib_mutex); 7017c478bd9Sstevel@tonic-gate mutex_destroy(&rpcib.rpcib_mutex); 7027c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate static void rib_rbufpool_free(rib_hca_t *, int); 7077c478bd9Sstevel@tonic-gate static void rib_rbufpool_deregister(rib_hca_t *, int); 7087c478bd9Sstevel@tonic-gate static void rib_rbufpool_destroy(rib_hca_t *hca, int ptype); 7097c478bd9Sstevel@tonic-gate static struct reply *rib_addreplylist(rib_qp_t *, uint32_t); 7107c478bd9Sstevel@tonic-gate static rdma_stat rib_rem_replylist(rib_qp_t *); 7117c478bd9Sstevel@tonic-gate static int rib_remreply(rib_qp_t *, struct reply *); 7127c478bd9Sstevel@tonic-gate static rdma_stat rib_add_connlist(CONN *, rib_conn_list_t *); 7137c478bd9Sstevel@tonic-gate static rdma_stat rib_rm_conn(CONN *, rib_conn_list_t *); 7147c478bd9Sstevel@tonic-gate 7150a701b1eSRobert Gordon 7167c478bd9Sstevel@tonic-gate /* 7177c478bd9Sstevel@tonic-gate * One CQ pair per HCA 7187c478bd9Sstevel@tonic-gate */ 7197c478bd9Sstevel@tonic-gate static rdma_stat 7207c478bd9Sstevel@tonic-gate rib_create_cq(rib_hca_t *hca, uint32_t cq_size, ibt_cq_handler_t cq_handler, 7217f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_cq_t **cqp) 7227c478bd9Sstevel@tonic-gate { 7237c478bd9Sstevel@tonic-gate rib_cq_t *cq; 7247c478bd9Sstevel@tonic-gate ibt_cq_attr_t cq_attr; 7257c478bd9Sstevel@tonic-gate uint32_t real_size; 7267c478bd9Sstevel@tonic-gate ibt_status_t status; 7277c478bd9Sstevel@tonic-gate rdma_stat error = RDMA_SUCCESS; 7287c478bd9Sstevel@tonic-gate 7297c478bd9Sstevel@tonic-gate cq = kmem_zalloc(sizeof (rib_cq_t), KM_SLEEP); 7307c478bd9Sstevel@tonic-gate cq->rib_hca = hca; 7317c478bd9Sstevel@tonic-gate cq_attr.cq_size = cq_size; 7327c478bd9Sstevel@tonic-gate cq_attr.cq_flags = IBT_CQ_NO_FLAGS; 7337c478bd9Sstevel@tonic-gate status = ibt_alloc_cq(hca->hca_hdl, &cq_attr, &cq->rib_cq_hdl, 7347c478bd9Sstevel@tonic-gate &real_size); 7357c478bd9Sstevel@tonic-gate if (status != IBT_SUCCESS) { 7367c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "rib_create_cq: ibt_alloc_cq() failed," 7377c478bd9Sstevel@tonic-gate " status=%d", status); 7387c478bd9Sstevel@tonic-gate error = RDMA_FAILED; 7397c478bd9Sstevel@tonic-gate goto fail; 7407c478bd9Sstevel@tonic-gate } 7417f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ibt_set_cq_handler(cq->rib_cq_hdl, cq_handler, hca); 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate /* 7447c478bd9Sstevel@tonic-gate * Enable CQ callbacks. CQ Callbacks are single shot 7457c478bd9Sstevel@tonic-gate * (e.g. you have to call ibt_enable_cq_notify() 7467c478bd9Sstevel@tonic-gate * after each callback to get another one). 7477c478bd9Sstevel@tonic-gate */ 7487c478bd9Sstevel@tonic-gate status = ibt_enable_cq_notify(cq->rib_cq_hdl, IBT_NEXT_COMPLETION); 7497c478bd9Sstevel@tonic-gate if (status != IBT_SUCCESS) { 7507c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "rib_create_cq: " 7517c478bd9Sstevel@tonic-gate "enable_cq_notify failed, status %d", status); 7527c478bd9Sstevel@tonic-gate error = RDMA_FAILED; 7537c478bd9Sstevel@tonic-gate goto fail; 7547c478bd9Sstevel@tonic-gate } 7557c478bd9Sstevel@tonic-gate *cqp = cq; 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate return (error); 7587c478bd9Sstevel@tonic-gate fail: 7597c478bd9Sstevel@tonic-gate if (cq->rib_cq_hdl) 7607c478bd9Sstevel@tonic-gate (void) ibt_free_cq(cq->rib_cq_hdl); 7617c478bd9Sstevel@tonic-gate if (cq) 7627c478bd9Sstevel@tonic-gate kmem_free(cq, sizeof (rib_cq_t)); 7637c478bd9Sstevel@tonic-gate return (error); 7647c478bd9Sstevel@tonic-gate } 7657c478bd9Sstevel@tonic-gate 7667f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 7677f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * rpcib_find_hca 7687f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * 7697f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Caller should have already locked the hcas_lock before calling 7707f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * this function. 7717f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 7727f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static rib_hca_t * 7737f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib_find_hca(rpcib_state_t *ribstat, ib_guid_t guid) 7747f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States { 7757f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_hca_t *hca = ribstat->hcas_list; 7767f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 7777f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States while (hca && hca->hca_guid != guid) 7787f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca = hca->next; 7797f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 7807f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (hca); 7817f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 7827f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 7837c478bd9Sstevel@tonic-gate static rdma_stat 7847f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib_open_hcas(rpcib_state_t *ribstat) 7857c478bd9Sstevel@tonic-gate { 7867c478bd9Sstevel@tonic-gate rib_hca_t *hca; 7877c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 7887c478bd9Sstevel@tonic-gate rdma_stat status; 7897c478bd9Sstevel@tonic-gate ibt_hca_portinfo_t *pinfop; 7907c478bd9Sstevel@tonic-gate ibt_pd_flags_t pd_flags = IBT_PD_NO_FLAGS; 7917c478bd9Sstevel@tonic-gate uint_t size, cq_size; 7927c478bd9Sstevel@tonic-gate int i; 7930a701b1eSRobert Gordon kstat_t *ksp; 7940a701b1eSRobert Gordon cache_avl_struct_t example_avl_node; 7950a701b1eSRobert Gordon char rssc_name[32]; 7967f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States int old_nhca_inited = ribstat->nhca_inited; 7977f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ib_guid_t *hca_guids; 7987c478bd9Sstevel@tonic-gate 7997c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ribstat->open_hca_lock)); 8000a701b1eSRobert Gordon 8017f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ribstat->hca_count = ibt_get_hca_list(&hca_guids); 8027f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (ribstat->hca_count == 0) 8037f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (RDMA_FAILED); 8047c478bd9Sstevel@tonic-gate 8057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&ribstat->hcas_list_lock, RW_WRITER); 8067c478bd9Sstevel@tonic-gate /* 8077c478bd9Sstevel@tonic-gate * Open a hca and setup for RDMA 8087c478bd9Sstevel@tonic-gate */ 8097c478bd9Sstevel@tonic-gate for (i = 0; i < ribstat->hca_count; i++) { 8107f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (rpcib_find_hca(ribstat, hca_guids[i])) 8117f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States continue; 8127f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca = kmem_zalloc(sizeof (rib_hca_t), KM_SLEEP); 8137f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 8147c478bd9Sstevel@tonic-gate ibt_status = ibt_open_hca(ribstat->ibt_clnt_hdl, 8157f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca_guids[i], &hca->hca_hdl); 8167c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) { 8177f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States kmem_free(hca, sizeof (rib_hca_t)); 8187c478bd9Sstevel@tonic-gate continue; 8197c478bd9Sstevel@tonic-gate } 8207f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->hca_guid = hca_guids[i]; 8217c478bd9Sstevel@tonic-gate hca->ibt_clnt_hdl = ribstat->ibt_clnt_hdl; 8227c478bd9Sstevel@tonic-gate hca->state = HCA_INITED; 8237c478bd9Sstevel@tonic-gate 8247c478bd9Sstevel@tonic-gate /* 8257c478bd9Sstevel@tonic-gate * query HCA info 8267c478bd9Sstevel@tonic-gate */ 8277c478bd9Sstevel@tonic-gate ibt_status = ibt_query_hca(hca->hca_hdl, &hca->hca_attrs); 8287c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) { 8297c478bd9Sstevel@tonic-gate goto fail1; 8307c478bd9Sstevel@tonic-gate } 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate /* 8337c478bd9Sstevel@tonic-gate * One PD (Protection Domain) per HCA. 8347c478bd9Sstevel@tonic-gate * A qp is allowed to access a memory region 8357c478bd9Sstevel@tonic-gate * only when it's in the same PD as that of 8367c478bd9Sstevel@tonic-gate * the memory region. 8377c478bd9Sstevel@tonic-gate */ 8387c478bd9Sstevel@tonic-gate ibt_status = ibt_alloc_pd(hca->hca_hdl, pd_flags, &hca->pd_hdl); 8397c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) { 8407c478bd9Sstevel@tonic-gate goto fail1; 8417c478bd9Sstevel@tonic-gate } 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate /* 8447c478bd9Sstevel@tonic-gate * query HCA ports 8457c478bd9Sstevel@tonic-gate */ 8467c478bd9Sstevel@tonic-gate ibt_status = ibt_query_hca_ports(hca->hca_hdl, 8477c478bd9Sstevel@tonic-gate 0, &pinfop, &hca->hca_nports, &size); 8487c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) { 8497c478bd9Sstevel@tonic-gate goto fail2; 8507c478bd9Sstevel@tonic-gate } 8517c478bd9Sstevel@tonic-gate hca->hca_ports = pinfop; 8527c478bd9Sstevel@tonic-gate hca->hca_pinfosz = size; 8537c478bd9Sstevel@tonic-gate pinfop = NULL; 8547c478bd9Sstevel@tonic-gate 8557c478bd9Sstevel@tonic-gate cq_size = DEF_CQ_SIZE; /* default cq size */ 8567c478bd9Sstevel@tonic-gate /* 8577c478bd9Sstevel@tonic-gate * Create 2 pairs of cq's (1 pair for client 8587c478bd9Sstevel@tonic-gate * and the other pair for server) on this hca. 8597c478bd9Sstevel@tonic-gate * If number of qp's gets too large, then several 8607c478bd9Sstevel@tonic-gate * cq's will be needed. 8617c478bd9Sstevel@tonic-gate */ 8627c478bd9Sstevel@tonic-gate status = rib_create_cq(hca, cq_size, rib_svc_rcq_handler, 8637f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States &hca->svc_rcq); 8647c478bd9Sstevel@tonic-gate if (status != RDMA_SUCCESS) { 8657c478bd9Sstevel@tonic-gate goto fail3; 8667c478bd9Sstevel@tonic-gate } 8677c478bd9Sstevel@tonic-gate 8687c478bd9Sstevel@tonic-gate status = rib_create_cq(hca, cq_size, rib_svc_scq_handler, 8697f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States &hca->svc_scq); 8707c478bd9Sstevel@tonic-gate if (status != RDMA_SUCCESS) { 8717c478bd9Sstevel@tonic-gate goto fail3; 8727c478bd9Sstevel@tonic-gate } 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate status = rib_create_cq(hca, cq_size, rib_clnt_rcq_handler, 8757f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States &hca->clnt_rcq); 8767c478bd9Sstevel@tonic-gate if (status != RDMA_SUCCESS) { 8777c478bd9Sstevel@tonic-gate goto fail3; 8787c478bd9Sstevel@tonic-gate } 8797c478bd9Sstevel@tonic-gate 8807c478bd9Sstevel@tonic-gate status = rib_create_cq(hca, cq_size, rib_clnt_scq_handler, 8817f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States &hca->clnt_scq); 8827c478bd9Sstevel@tonic-gate if (status != RDMA_SUCCESS) { 8837c478bd9Sstevel@tonic-gate goto fail3; 8847c478bd9Sstevel@tonic-gate } 8857c478bd9Sstevel@tonic-gate 8867c478bd9Sstevel@tonic-gate /* 8877c478bd9Sstevel@tonic-gate * Create buffer pools. 8887c478bd9Sstevel@tonic-gate * Note rib_rbuf_create also allocates memory windows. 8897c478bd9Sstevel@tonic-gate */ 8907c478bd9Sstevel@tonic-gate hca->recv_pool = rib_rbufpool_create(hca, 891065714dcSSiddheshwar Mahesh RECV_BUFFER, rib_max_rbufs); 8927c478bd9Sstevel@tonic-gate if (hca->recv_pool == NULL) { 8937c478bd9Sstevel@tonic-gate goto fail3; 8947c478bd9Sstevel@tonic-gate } 8957c478bd9Sstevel@tonic-gate 8967c478bd9Sstevel@tonic-gate hca->send_pool = rib_rbufpool_create(hca, 897065714dcSSiddheshwar Mahesh SEND_BUFFER, rib_max_rbufs); 8987c478bd9Sstevel@tonic-gate if (hca->send_pool == NULL) { 8997c478bd9Sstevel@tonic-gate rib_rbufpool_destroy(hca, RECV_BUFFER); 9007c478bd9Sstevel@tonic-gate goto fail3; 9017c478bd9Sstevel@tonic-gate } 9027c478bd9Sstevel@tonic-gate 9030a701b1eSRobert Gordon if (hca->server_side_cache == NULL) { 9040a701b1eSRobert Gordon (void) sprintf(rssc_name, 9057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States "rib_srvr_cache_%llx", 9067f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (long long unsigned int) hca->hca_guid); 9070a701b1eSRobert Gordon hca->server_side_cache = kmem_cache_create( 9080a701b1eSRobert Gordon rssc_name, 9090a701b1eSRobert Gordon sizeof (cache_avl_struct_t), 0, 9100a701b1eSRobert Gordon NULL, 9110a701b1eSRobert Gordon NULL, 9120a701b1eSRobert Gordon rib_server_side_cache_reclaim, 9130a701b1eSRobert Gordon hca, NULL, 0); 9140a701b1eSRobert Gordon } 9150a701b1eSRobert Gordon 9160a701b1eSRobert Gordon avl_create(&hca->avl_tree, 9170a701b1eSRobert Gordon avl_compare, 9180a701b1eSRobert Gordon sizeof (cache_avl_struct_t), 9190a701b1eSRobert Gordon (uint_t)(uintptr_t)&example_avl_node.avl_link- 9200a701b1eSRobert Gordon (uint_t)(uintptr_t)&example_avl_node); 9210a701b1eSRobert Gordon 9227f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_init(&hca->bound_services_lock, NULL, RW_DRIVER, 9237f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->iblock); 9247f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_init(&hca->state_lock, NULL, RW_DRIVER, hca->iblock); 9250a701b1eSRobert Gordon rw_init(&hca->avl_rw_lock, 9260a701b1eSRobert Gordon NULL, RW_DRIVER, hca->iblock); 9277f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_init(&hca->cache_allocation_lock, 9280a701b1eSRobert Gordon NULL, MUTEX_DRIVER, NULL); 9290a701b1eSRobert Gordon hca->avl_init = TRUE; 9300a701b1eSRobert Gordon 9310a701b1eSRobert Gordon /* Create kstats for the cache */ 9320a701b1eSRobert Gordon ASSERT(INGLOBALZONE(curproc)); 9330a701b1eSRobert Gordon 9340a701b1eSRobert Gordon if (!stats_enabled) { 9350a701b1eSRobert Gordon ksp = kstat_create_zone("unix", 0, "rpcib_cache", "rpc", 9360a701b1eSRobert Gordon KSTAT_TYPE_NAMED, 9370a701b1eSRobert Gordon sizeof (rpcib_kstat) / sizeof (kstat_named_t), 9380a701b1eSRobert Gordon KSTAT_FLAG_VIRTUAL | KSTAT_FLAG_WRITABLE, 9390a701b1eSRobert Gordon GLOBAL_ZONEID); 9400a701b1eSRobert Gordon if (ksp) { 9410a701b1eSRobert Gordon ksp->ks_data = (void *) &rpcib_kstat; 9420a701b1eSRobert Gordon ksp->ks_update = rpcib_cache_kstat_update; 9430a701b1eSRobert Gordon kstat_install(ksp); 9440a701b1eSRobert Gordon stats_enabled = TRUE; 9450a701b1eSRobert Gordon } 9460a701b1eSRobert Gordon } 947065714dcSSiddheshwar Mahesh if (hca->cleanup_helper == NULL) { 9487f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States char tq_name[sizeof (hca->hca_guid) * 2 + 1]; 9490a701b1eSRobert Gordon 9507f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (void) snprintf(tq_name, sizeof (tq_name), "%llX", 9517f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (unsigned long long int) hca->hca_guid); 9527f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->cleanup_helper = ddi_taskq_create(NULL, 9537f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States tq_name, 1, TASKQ_DEFAULTPRI, 0); 9547f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 9557c478bd9Sstevel@tonic-gate 9567c478bd9Sstevel@tonic-gate mutex_init(&hca->cb_lock, NULL, MUTEX_DRIVER, hca->iblock); 9577c478bd9Sstevel@tonic-gate cv_init(&hca->cb_cv, NULL, CV_DRIVER, NULL); 9587c478bd9Sstevel@tonic-gate rw_init(&hca->cl_conn_list.conn_lock, NULL, RW_DRIVER, 9597c478bd9Sstevel@tonic-gate hca->iblock); 9607c478bd9Sstevel@tonic-gate rw_init(&hca->srv_conn_list.conn_lock, NULL, RW_DRIVER, 9617c478bd9Sstevel@tonic-gate hca->iblock); 9627c478bd9Sstevel@tonic-gate mutex_init(&hca->inuse_lock, NULL, MUTEX_DRIVER, hca->iblock); 9637c478bd9Sstevel@tonic-gate hca->inuse = TRUE; 9647f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 9657f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->next = ribstat->hcas_list; 9667f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ribstat->hcas_list = hca; 9677c478bd9Sstevel@tonic-gate ribstat->nhca_inited++; 9687c478bd9Sstevel@tonic-gate ibt_free_portinfo(hca->hca_ports, hca->hca_pinfosz); 9697f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States continue; 9707c478bd9Sstevel@tonic-gate 9717c478bd9Sstevel@tonic-gate fail3: 9727c478bd9Sstevel@tonic-gate ibt_free_portinfo(hca->hca_ports, hca->hca_pinfosz); 9737c478bd9Sstevel@tonic-gate fail2: 9747c478bd9Sstevel@tonic-gate (void) ibt_free_pd(hca->hca_hdl, hca->pd_hdl); 9757c478bd9Sstevel@tonic-gate fail1: 9767c478bd9Sstevel@tonic-gate (void) ibt_close_hca(hca->hca_hdl); 9777f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States kmem_free(hca, sizeof (rib_hca_t)); 9787c478bd9Sstevel@tonic-gate } 9797f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&ribstat->hcas_list_lock); 9807f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ibt_free_hca_list(hca_guids, ribstat->hca_count); 9817f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_mod.rdma_count = rib_stat->nhca_inited; 9827f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 9837f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 9847f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * return success if at least one new hca has been configured. 9857f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 9867f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (ribstat->nhca_inited != old_nhca_inited) 9877c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 9887c478bd9Sstevel@tonic-gate else 9897c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 9907c478bd9Sstevel@tonic-gate } 9917c478bd9Sstevel@tonic-gate 9927c478bd9Sstevel@tonic-gate /* 9937c478bd9Sstevel@tonic-gate * Callback routines 9947c478bd9Sstevel@tonic-gate */ 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate /* 9977c478bd9Sstevel@tonic-gate * SCQ handlers 9987c478bd9Sstevel@tonic-gate */ 9997c478bd9Sstevel@tonic-gate /* ARGSUSED */ 10007c478bd9Sstevel@tonic-gate static void 10017c478bd9Sstevel@tonic-gate rib_clnt_scq_handler(ibt_cq_hdl_t cq_hdl, void *arg) 10027c478bd9Sstevel@tonic-gate { 10037c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 10047c478bd9Sstevel@tonic-gate ibt_wc_t wc; 1005065714dcSSiddheshwar Mahesh struct send_wid *wd; 1006065714dcSSiddheshwar Mahesh CONN *conn; 1007065714dcSSiddheshwar Mahesh rib_qp_t *qp; 10087c478bd9Sstevel@tonic-gate int i; 10097c478bd9Sstevel@tonic-gate 10107c478bd9Sstevel@tonic-gate /* 10117c478bd9Sstevel@tonic-gate * Re-enable cq notify here to avoid missing any 10127c478bd9Sstevel@tonic-gate * completion queue notification. 10137c478bd9Sstevel@tonic-gate */ 10147c478bd9Sstevel@tonic-gate (void) ibt_enable_cq_notify(cq_hdl, IBT_NEXT_COMPLETION); 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate ibt_status = IBT_SUCCESS; 10177c478bd9Sstevel@tonic-gate while (ibt_status != IBT_CQ_EMPTY) { 10187c478bd9Sstevel@tonic-gate bzero(&wc, sizeof (wc)); 10197c478bd9Sstevel@tonic-gate ibt_status = ibt_poll_cq(cq_hdl, &wc, 1, NULL); 10207c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) 10217c478bd9Sstevel@tonic-gate return; 10227c478bd9Sstevel@tonic-gate 10237c478bd9Sstevel@tonic-gate /* 10247c478bd9Sstevel@tonic-gate * Got a send completion 10257c478bd9Sstevel@tonic-gate */ 1026065714dcSSiddheshwar Mahesh if (wc.wc_id != RDMA_DUMMY_WRID) { 1027065714dcSSiddheshwar Mahesh wd = (struct send_wid *)(uintptr_t)wc.wc_id; 1028065714dcSSiddheshwar Mahesh qp = wd->qp; 1029065714dcSSiddheshwar Mahesh conn = qptoc(qp); 10307c478bd9Sstevel@tonic-gate 10317c478bd9Sstevel@tonic-gate mutex_enter(&wd->sendwait_lock); 10327c478bd9Sstevel@tonic-gate switch (wc.wc_status) { 10337c478bd9Sstevel@tonic-gate case IBT_WC_SUCCESS: 10347c478bd9Sstevel@tonic-gate wd->status = RDMA_SUCCESS; 10357c478bd9Sstevel@tonic-gate break; 10367c478bd9Sstevel@tonic-gate default: 10377c478bd9Sstevel@tonic-gate /* 10387c478bd9Sstevel@tonic-gate * RC Send Q Error Code Local state Remote State 10397c478bd9Sstevel@tonic-gate * ==================== =========== ============ 10407c478bd9Sstevel@tonic-gate * IBT_WC_BAD_RESPONSE_ERR ERROR None 10417c478bd9Sstevel@tonic-gate * IBT_WC_LOCAL_LEN_ERR ERROR None 10427c478bd9Sstevel@tonic-gate * IBT_WC_LOCAL_CHAN_OP_ERR ERROR None 10437c478bd9Sstevel@tonic-gate * IBT_WC_LOCAL_PROTECT_ERR ERROR None 10447c478bd9Sstevel@tonic-gate * IBT_WC_MEM_WIN_BIND_ERR ERROR None 10457c478bd9Sstevel@tonic-gate * IBT_WC_REMOTE_INVALID_REQ_ERR ERROR ERROR 10467c478bd9Sstevel@tonic-gate * IBT_WC_REMOTE_ACCESS_ERR ERROR ERROR 10477c478bd9Sstevel@tonic-gate * IBT_WC_REMOTE_OP_ERR ERROR ERROR 10487c478bd9Sstevel@tonic-gate * IBT_WC_RNR_NAK_TIMEOUT_ERR ERROR None 10497c478bd9Sstevel@tonic-gate * IBT_WC_TRANS_TIMEOUT_ERR ERROR None 1050065714dcSSiddheshwar Mahesh * IBT_WC_WR_FLUSHED_ERR ERROR None 10517c478bd9Sstevel@tonic-gate */ 10527c478bd9Sstevel@tonic-gate /* 10537c478bd9Sstevel@tonic-gate * Channel in error state. Set connection to 10547c478bd9Sstevel@tonic-gate * ERROR and cleanup will happen either from 10557c478bd9Sstevel@tonic-gate * conn_release or from rib_conn_get 10567c478bd9Sstevel@tonic-gate */ 10577c478bd9Sstevel@tonic-gate wd->status = RDMA_FAILED; 10587c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 10597c478bd9Sstevel@tonic-gate if (conn->c_state != C_DISCONN_PEND) 10600a701b1eSRobert Gordon conn->c_state = C_ERROR_CONN; 10617c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 10627c478bd9Sstevel@tonic-gate break; 10637c478bd9Sstevel@tonic-gate } 10640a701b1eSRobert Gordon 10657c478bd9Sstevel@tonic-gate if (wd->cv_sig == 1) { 10667c478bd9Sstevel@tonic-gate /* 10677c478bd9Sstevel@tonic-gate * Notify poster 10687c478bd9Sstevel@tonic-gate */ 10697c478bd9Sstevel@tonic-gate cv_signal(&wd->wait_cv); 10707c478bd9Sstevel@tonic-gate mutex_exit(&wd->sendwait_lock); 10717c478bd9Sstevel@tonic-gate } else { 10727c478bd9Sstevel@tonic-gate /* 10737c478bd9Sstevel@tonic-gate * Poster not waiting for notification. 10747c478bd9Sstevel@tonic-gate * Free the send buffers and send_wid 10757c478bd9Sstevel@tonic-gate */ 10767c478bd9Sstevel@tonic-gate for (i = 0; i < wd->nsbufs; i++) { 1077065714dcSSiddheshwar Mahesh rib_rbuf_free(qptoc(wd->qp), 1078065714dcSSiddheshwar Mahesh SEND_BUFFER, 107911606941Sjwahlig (void *)(uintptr_t)wd->sbufaddr[i]); 10807c478bd9Sstevel@tonic-gate } 1081065714dcSSiddheshwar Mahesh 1082065714dcSSiddheshwar Mahesh /* decrement the send ref count */ 1083065714dcSSiddheshwar Mahesh rib_send_rele(qp); 1084065714dcSSiddheshwar Mahesh 10857c478bd9Sstevel@tonic-gate mutex_exit(&wd->sendwait_lock); 10867c478bd9Sstevel@tonic-gate (void) rib_free_sendwait(wd); 10877c478bd9Sstevel@tonic-gate } 10887c478bd9Sstevel@tonic-gate } 10897c478bd9Sstevel@tonic-gate } 10907c478bd9Sstevel@tonic-gate } 10917c478bd9Sstevel@tonic-gate 10927c478bd9Sstevel@tonic-gate /* ARGSUSED */ 10937c478bd9Sstevel@tonic-gate static void 10947c478bd9Sstevel@tonic-gate rib_svc_scq_handler(ibt_cq_hdl_t cq_hdl, void *arg) 10957c478bd9Sstevel@tonic-gate { 10967c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 10977c478bd9Sstevel@tonic-gate ibt_wc_t wc; 1098065714dcSSiddheshwar Mahesh struct send_wid *wd; 1099065714dcSSiddheshwar Mahesh rib_qp_t *qp; 1100065714dcSSiddheshwar Mahesh CONN *conn; 11017c478bd9Sstevel@tonic-gate int i; 11027c478bd9Sstevel@tonic-gate 11037c478bd9Sstevel@tonic-gate /* 11047c478bd9Sstevel@tonic-gate * Re-enable cq notify here to avoid missing any 11057c478bd9Sstevel@tonic-gate * completion queue notification. 11067c478bd9Sstevel@tonic-gate */ 11077c478bd9Sstevel@tonic-gate (void) ibt_enable_cq_notify(cq_hdl, IBT_NEXT_COMPLETION); 11087c478bd9Sstevel@tonic-gate 11097c478bd9Sstevel@tonic-gate ibt_status = IBT_SUCCESS; 11107c478bd9Sstevel@tonic-gate while (ibt_status != IBT_CQ_EMPTY) { 11117c478bd9Sstevel@tonic-gate bzero(&wc, sizeof (wc)); 11127c478bd9Sstevel@tonic-gate ibt_status = ibt_poll_cq(cq_hdl, &wc, 1, NULL); 11137c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) 11147c478bd9Sstevel@tonic-gate return; 11157c478bd9Sstevel@tonic-gate 11167c478bd9Sstevel@tonic-gate /* 11177c478bd9Sstevel@tonic-gate * Got a send completion 11187c478bd9Sstevel@tonic-gate */ 1119065714dcSSiddheshwar Mahesh if (wc.wc_id != RDMA_DUMMY_WRID) { 1120065714dcSSiddheshwar Mahesh wd = (struct send_wid *)(uintptr_t)wc.wc_id; 1121065714dcSSiddheshwar Mahesh qp = wd->qp; 1122065714dcSSiddheshwar Mahesh conn = qptoc(qp); 11237c478bd9Sstevel@tonic-gate mutex_enter(&wd->sendwait_lock); 1124065714dcSSiddheshwar Mahesh 1125065714dcSSiddheshwar Mahesh switch (wc.wc_status) { 1126065714dcSSiddheshwar Mahesh case IBT_WC_SUCCESS: 1127065714dcSSiddheshwar Mahesh wd->status = RDMA_SUCCESS; 1128065714dcSSiddheshwar Mahesh break; 1129065714dcSSiddheshwar Mahesh default: 1130065714dcSSiddheshwar Mahesh /* 1131065714dcSSiddheshwar Mahesh * Channel in error state. Set connection to 1132065714dcSSiddheshwar Mahesh * ERROR and cleanup will happen either from 1133065714dcSSiddheshwar Mahesh * conn_release or conn timeout. 1134065714dcSSiddheshwar Mahesh */ 1135065714dcSSiddheshwar Mahesh wd->status = RDMA_FAILED; 1136065714dcSSiddheshwar Mahesh mutex_enter(&conn->c_lock); 1137065714dcSSiddheshwar Mahesh if (conn->c_state != C_DISCONN_PEND) 1138065714dcSSiddheshwar Mahesh conn->c_state = C_ERROR_CONN; 1139065714dcSSiddheshwar Mahesh mutex_exit(&conn->c_lock); 1140065714dcSSiddheshwar Mahesh break; 1141065714dcSSiddheshwar Mahesh } 1142065714dcSSiddheshwar Mahesh 11437c478bd9Sstevel@tonic-gate if (wd->cv_sig == 1) { 11447c478bd9Sstevel@tonic-gate /* 11457c478bd9Sstevel@tonic-gate * Update completion status and notify poster 11467c478bd9Sstevel@tonic-gate */ 11477c478bd9Sstevel@tonic-gate cv_signal(&wd->wait_cv); 11487c478bd9Sstevel@tonic-gate mutex_exit(&wd->sendwait_lock); 11497c478bd9Sstevel@tonic-gate } else { 11507c478bd9Sstevel@tonic-gate /* 11517c478bd9Sstevel@tonic-gate * Poster not waiting for notification. 11527c478bd9Sstevel@tonic-gate * Free the send buffers and send_wid 11537c478bd9Sstevel@tonic-gate */ 11547c478bd9Sstevel@tonic-gate for (i = 0; i < wd->nsbufs; i++) { 11550a701b1eSRobert Gordon rib_rbuf_free(qptoc(wd->qp), 11560a701b1eSRobert Gordon SEND_BUFFER, 115711606941Sjwahlig (void *)(uintptr_t)wd->sbufaddr[i]); 11587c478bd9Sstevel@tonic-gate } 1159065714dcSSiddheshwar Mahesh 1160065714dcSSiddheshwar Mahesh /* decrement the send ref count */ 1161065714dcSSiddheshwar Mahesh rib_send_rele(qp); 1162065714dcSSiddheshwar Mahesh 11637c478bd9Sstevel@tonic-gate mutex_exit(&wd->sendwait_lock); 11647c478bd9Sstevel@tonic-gate (void) rib_free_sendwait(wd); 11657c478bd9Sstevel@tonic-gate } 11667c478bd9Sstevel@tonic-gate } 11677c478bd9Sstevel@tonic-gate } 11687c478bd9Sstevel@tonic-gate } 11697c478bd9Sstevel@tonic-gate 11707c478bd9Sstevel@tonic-gate /* 11717c478bd9Sstevel@tonic-gate * RCQ handler 11727c478bd9Sstevel@tonic-gate */ 11737c478bd9Sstevel@tonic-gate /* ARGSUSED */ 11747c478bd9Sstevel@tonic-gate static void 11757c478bd9Sstevel@tonic-gate rib_clnt_rcq_handler(ibt_cq_hdl_t cq_hdl, void *arg) 11767c478bd9Sstevel@tonic-gate { 11777c478bd9Sstevel@tonic-gate rib_qp_t *qp; 11787c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 11797c478bd9Sstevel@tonic-gate ibt_wc_t wc; 11807c478bd9Sstevel@tonic-gate struct recv_wid *rwid; 11817c478bd9Sstevel@tonic-gate 11827c478bd9Sstevel@tonic-gate /* 11837c478bd9Sstevel@tonic-gate * Re-enable cq notify here to avoid missing any 11847c478bd9Sstevel@tonic-gate * completion queue notification. 11857c478bd9Sstevel@tonic-gate */ 11867c478bd9Sstevel@tonic-gate (void) ibt_enable_cq_notify(cq_hdl, IBT_NEXT_COMPLETION); 11877c478bd9Sstevel@tonic-gate 11887c478bd9Sstevel@tonic-gate ibt_status = IBT_SUCCESS; 11897c478bd9Sstevel@tonic-gate while (ibt_status != IBT_CQ_EMPTY) { 11907c478bd9Sstevel@tonic-gate bzero(&wc, sizeof (wc)); 11917c478bd9Sstevel@tonic-gate ibt_status = ibt_poll_cq(cq_hdl, &wc, 1, NULL); 11927c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) 11937c478bd9Sstevel@tonic-gate return; 11947c478bd9Sstevel@tonic-gate 119511606941Sjwahlig rwid = (struct recv_wid *)(uintptr_t)wc.wc_id; 11967c478bd9Sstevel@tonic-gate qp = rwid->qp; 11977c478bd9Sstevel@tonic-gate if (wc.wc_status == IBT_WC_SUCCESS) { 11987c478bd9Sstevel@tonic-gate XDR inxdrs, *xdrs; 11997c478bd9Sstevel@tonic-gate uint_t xid, vers, op, find_xid = 0; 12007c478bd9Sstevel@tonic-gate struct reply *r; 12017c478bd9Sstevel@tonic-gate CONN *conn = qptoc(qp); 12020a701b1eSRobert Gordon uint32_t rdma_credit = 0; 12037c478bd9Sstevel@tonic-gate 12047c478bd9Sstevel@tonic-gate xdrs = &inxdrs; 120511606941Sjwahlig xdrmem_create(xdrs, (caddr_t)(uintptr_t)rwid->addr, 12067c478bd9Sstevel@tonic-gate wc.wc_bytes_xfer, XDR_DECODE); 12077c478bd9Sstevel@tonic-gate /* 12087c478bd9Sstevel@tonic-gate * Treat xid as opaque (xid is the first entity 12097c478bd9Sstevel@tonic-gate * in the rpc rdma message). 12107c478bd9Sstevel@tonic-gate */ 121111606941Sjwahlig xid = *(uint32_t *)(uintptr_t)rwid->addr; 12120a701b1eSRobert Gordon 12137c478bd9Sstevel@tonic-gate /* Skip xid and set the xdr position accordingly. */ 12147c478bd9Sstevel@tonic-gate XDR_SETPOS(xdrs, sizeof (uint32_t)); 12157c478bd9Sstevel@tonic-gate (void) xdr_u_int(xdrs, &vers); 12160a701b1eSRobert Gordon (void) xdr_u_int(xdrs, &rdma_credit); 12177c478bd9Sstevel@tonic-gate (void) xdr_u_int(xdrs, &op); 12187c478bd9Sstevel@tonic-gate XDR_DESTROY(xdrs); 12190a701b1eSRobert Gordon 12207c478bd9Sstevel@tonic-gate if (vers != RPCRDMA_VERS) { 12217c478bd9Sstevel@tonic-gate /* 12220a701b1eSRobert Gordon * Invalid RPC/RDMA version. Cannot 12230a701b1eSRobert Gordon * interoperate. Set connection to 12240a701b1eSRobert Gordon * ERROR state and bail out. 12257c478bd9Sstevel@tonic-gate */ 12267c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 12277c478bd9Sstevel@tonic-gate if (conn->c_state != C_DISCONN_PEND) 12280a701b1eSRobert Gordon conn->c_state = C_ERROR_CONN; 12297c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 123011606941Sjwahlig rib_rbuf_free(conn, RECV_BUFFER, 123111606941Sjwahlig (void *)(uintptr_t)rwid->addr); 12327c478bd9Sstevel@tonic-gate rib_free_wid(rwid); 12337c478bd9Sstevel@tonic-gate continue; 12347c478bd9Sstevel@tonic-gate } 12357c478bd9Sstevel@tonic-gate 12367c478bd9Sstevel@tonic-gate mutex_enter(&qp->replylist_lock); 12377c478bd9Sstevel@tonic-gate for (r = qp->replylist; r != NULL; r = r->next) { 12387c478bd9Sstevel@tonic-gate if (r->xid == xid) { 12397c478bd9Sstevel@tonic-gate find_xid = 1; 12407c478bd9Sstevel@tonic-gate switch (op) { 12417c478bd9Sstevel@tonic-gate case RDMA_MSG: 12427c478bd9Sstevel@tonic-gate case RDMA_NOMSG: 12437c478bd9Sstevel@tonic-gate case RDMA_MSGP: 12447c478bd9Sstevel@tonic-gate r->status = RDMA_SUCCESS; 12457c478bd9Sstevel@tonic-gate r->vaddr_cq = rwid->addr; 12460a701b1eSRobert Gordon r->bytes_xfer = 12470a701b1eSRobert Gordon wc.wc_bytes_xfer; 12487c478bd9Sstevel@tonic-gate cv_signal(&r->wait_cv); 12497c478bd9Sstevel@tonic-gate break; 12507c478bd9Sstevel@tonic-gate default: 12510a701b1eSRobert Gordon rib_rbuf_free(qptoc(qp), 12520a701b1eSRobert Gordon RECV_BUFFER, 12530a701b1eSRobert Gordon (void *)(uintptr_t) 12540a701b1eSRobert Gordon rwid->addr); 12557c478bd9Sstevel@tonic-gate break; 12567c478bd9Sstevel@tonic-gate } 12577c478bd9Sstevel@tonic-gate break; 12587c478bd9Sstevel@tonic-gate } 12597c478bd9Sstevel@tonic-gate } 12607c478bd9Sstevel@tonic-gate mutex_exit(&qp->replylist_lock); 12617c478bd9Sstevel@tonic-gate if (find_xid == 0) { 12627c478bd9Sstevel@tonic-gate /* RPC caller not waiting for reply */ 12630a701b1eSRobert Gordon 12640a701b1eSRobert Gordon DTRACE_PROBE1(rpcib__i__nomatchxid1, 12650a701b1eSRobert Gordon int, xid); 12660a701b1eSRobert Gordon 12677c478bd9Sstevel@tonic-gate rib_rbuf_free(qptoc(qp), RECV_BUFFER, 126811606941Sjwahlig (void *)(uintptr_t)rwid->addr); 12697c478bd9Sstevel@tonic-gate } 12707c478bd9Sstevel@tonic-gate } else if (wc.wc_status == IBT_WC_WR_FLUSHED_ERR) { 12717c478bd9Sstevel@tonic-gate CONN *conn = qptoc(qp); 12727c478bd9Sstevel@tonic-gate 12737c478bd9Sstevel@tonic-gate /* 12747c478bd9Sstevel@tonic-gate * Connection being flushed. Just free 12757c478bd9Sstevel@tonic-gate * the posted buffer 12767c478bd9Sstevel@tonic-gate */ 127711606941Sjwahlig rib_rbuf_free(conn, RECV_BUFFER, 127811606941Sjwahlig (void *)(uintptr_t)rwid->addr); 12797c478bd9Sstevel@tonic-gate } else { 12807c478bd9Sstevel@tonic-gate CONN *conn = qptoc(qp); 12817c478bd9Sstevel@tonic-gate /* 12827c478bd9Sstevel@tonic-gate * RC Recv Q Error Code Local state Remote State 12837c478bd9Sstevel@tonic-gate * ==================== =========== ============ 12847c478bd9Sstevel@tonic-gate * IBT_WC_LOCAL_ACCESS_ERR ERROR ERROR when NAK recvd 12857c478bd9Sstevel@tonic-gate * IBT_WC_LOCAL_LEN_ERR ERROR ERROR when NAK recvd 12867c478bd9Sstevel@tonic-gate * IBT_WC_LOCAL_PROTECT_ERR ERROR ERROR when NAK recvd 12877c478bd9Sstevel@tonic-gate * IBT_WC_LOCAL_CHAN_OP_ERR ERROR ERROR when NAK recvd 12887c478bd9Sstevel@tonic-gate * IBT_WC_REMOTE_INVALID_REQ_ERR ERROR ERROR when NAK recvd 12897c478bd9Sstevel@tonic-gate * IBT_WC_WR_FLUSHED_ERR None None 12907c478bd9Sstevel@tonic-gate */ 12917c478bd9Sstevel@tonic-gate /* 12927c478bd9Sstevel@tonic-gate * Channel in error state. Set connection 12937c478bd9Sstevel@tonic-gate * in ERROR state. 12947c478bd9Sstevel@tonic-gate */ 12957c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 12967c478bd9Sstevel@tonic-gate if (conn->c_state != C_DISCONN_PEND) 12970a701b1eSRobert Gordon conn->c_state = C_ERROR_CONN; 12987c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 129911606941Sjwahlig rib_rbuf_free(conn, RECV_BUFFER, 130011606941Sjwahlig (void *)(uintptr_t)rwid->addr); 13017c478bd9Sstevel@tonic-gate } 13027c478bd9Sstevel@tonic-gate rib_free_wid(rwid); 13037c478bd9Sstevel@tonic-gate } 13047c478bd9Sstevel@tonic-gate } 13057c478bd9Sstevel@tonic-gate 13067c478bd9Sstevel@tonic-gate /* Server side */ 13077c478bd9Sstevel@tonic-gate /* ARGSUSED */ 13087c478bd9Sstevel@tonic-gate static void 13097c478bd9Sstevel@tonic-gate rib_svc_rcq_handler(ibt_cq_hdl_t cq_hdl, void *arg) 13107c478bd9Sstevel@tonic-gate { 13110a701b1eSRobert Gordon rdma_recv_data_t *rdp; 13127c478bd9Sstevel@tonic-gate rib_qp_t *qp; 13137c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 13147c478bd9Sstevel@tonic-gate ibt_wc_t wc; 13157c478bd9Sstevel@tonic-gate struct svc_recv *s_recvp; 13167c478bd9Sstevel@tonic-gate CONN *conn; 13177c478bd9Sstevel@tonic-gate mblk_t *mp; 13187c478bd9Sstevel@tonic-gate 13197c478bd9Sstevel@tonic-gate /* 13207c478bd9Sstevel@tonic-gate * Re-enable cq notify here to avoid missing any 13217c478bd9Sstevel@tonic-gate * completion queue notification. 13227c478bd9Sstevel@tonic-gate */ 13237c478bd9Sstevel@tonic-gate (void) ibt_enable_cq_notify(cq_hdl, IBT_NEXT_COMPLETION); 13247c478bd9Sstevel@tonic-gate 13257c478bd9Sstevel@tonic-gate ibt_status = IBT_SUCCESS; 13267c478bd9Sstevel@tonic-gate while (ibt_status != IBT_CQ_EMPTY) { 13277c478bd9Sstevel@tonic-gate bzero(&wc, sizeof (wc)); 13287c478bd9Sstevel@tonic-gate ibt_status = ibt_poll_cq(cq_hdl, &wc, 1, NULL); 13297c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) 13307c478bd9Sstevel@tonic-gate return; 13317c478bd9Sstevel@tonic-gate 133211606941Sjwahlig s_recvp = (struct svc_recv *)(uintptr_t)wc.wc_id; 13337c478bd9Sstevel@tonic-gate qp = s_recvp->qp; 13347c478bd9Sstevel@tonic-gate conn = qptoc(qp); 13357c478bd9Sstevel@tonic-gate mutex_enter(&qp->posted_rbufs_lock); 13367c478bd9Sstevel@tonic-gate qp->n_posted_rbufs--; 13377c478bd9Sstevel@tonic-gate if (qp->n_posted_rbufs == 0) 13387c478bd9Sstevel@tonic-gate cv_signal(&qp->posted_rbufs_cv); 13397c478bd9Sstevel@tonic-gate mutex_exit(&qp->posted_rbufs_lock); 13407c478bd9Sstevel@tonic-gate 13417c478bd9Sstevel@tonic-gate if (wc.wc_status == IBT_WC_SUCCESS) { 13427c478bd9Sstevel@tonic-gate XDR inxdrs, *xdrs; 13437c478bd9Sstevel@tonic-gate uint_t xid, vers, op; 13440a701b1eSRobert Gordon uint32_t rdma_credit; 13457c478bd9Sstevel@tonic-gate 13467c478bd9Sstevel@tonic-gate xdrs = &inxdrs; 13477c478bd9Sstevel@tonic-gate /* s_recvp->vaddr stores data */ 134811606941Sjwahlig xdrmem_create(xdrs, (caddr_t)(uintptr_t)s_recvp->vaddr, 13497c478bd9Sstevel@tonic-gate wc.wc_bytes_xfer, XDR_DECODE); 13507c478bd9Sstevel@tonic-gate 13517c478bd9Sstevel@tonic-gate /* 13527c478bd9Sstevel@tonic-gate * Treat xid as opaque (xid is the first entity 13537c478bd9Sstevel@tonic-gate * in the rpc rdma message). 13547c478bd9Sstevel@tonic-gate */ 135511606941Sjwahlig xid = *(uint32_t *)(uintptr_t)s_recvp->vaddr; 13567c478bd9Sstevel@tonic-gate /* Skip xid and set the xdr position accordingly. */ 13577c478bd9Sstevel@tonic-gate XDR_SETPOS(xdrs, sizeof (uint32_t)); 13587c478bd9Sstevel@tonic-gate if (!xdr_u_int(xdrs, &vers) || 13590a701b1eSRobert Gordon !xdr_u_int(xdrs, &rdma_credit) || 13607c478bd9Sstevel@tonic-gate !xdr_u_int(xdrs, &op)) { 13617c478bd9Sstevel@tonic-gate rib_rbuf_free(conn, RECV_BUFFER, 136211606941Sjwahlig (void *)(uintptr_t)s_recvp->vaddr); 13637c478bd9Sstevel@tonic-gate XDR_DESTROY(xdrs); 13647c478bd9Sstevel@tonic-gate (void) rib_free_svc_recv(s_recvp); 13657c478bd9Sstevel@tonic-gate continue; 13667c478bd9Sstevel@tonic-gate } 13677c478bd9Sstevel@tonic-gate XDR_DESTROY(xdrs); 13687c478bd9Sstevel@tonic-gate 13697c478bd9Sstevel@tonic-gate if (vers != RPCRDMA_VERS) { 13707c478bd9Sstevel@tonic-gate /* 13710a701b1eSRobert Gordon * Invalid RPC/RDMA version. 13720a701b1eSRobert Gordon * Drop rpc rdma message. 13737c478bd9Sstevel@tonic-gate */ 13747c478bd9Sstevel@tonic-gate rib_rbuf_free(conn, RECV_BUFFER, 137511606941Sjwahlig (void *)(uintptr_t)s_recvp->vaddr); 13767c478bd9Sstevel@tonic-gate (void) rib_free_svc_recv(s_recvp); 13777c478bd9Sstevel@tonic-gate continue; 13787c478bd9Sstevel@tonic-gate } 13797c478bd9Sstevel@tonic-gate /* 13807c478bd9Sstevel@tonic-gate * Is this for RDMA_DONE? 13817c478bd9Sstevel@tonic-gate */ 13827c478bd9Sstevel@tonic-gate if (op == RDMA_DONE) { 13837c478bd9Sstevel@tonic-gate rib_rbuf_free(conn, RECV_BUFFER, 138411606941Sjwahlig (void *)(uintptr_t)s_recvp->vaddr); 13857c478bd9Sstevel@tonic-gate /* 13867c478bd9Sstevel@tonic-gate * Wake up the thread waiting on 13877c478bd9Sstevel@tonic-gate * a RDMA_DONE for xid 13887c478bd9Sstevel@tonic-gate */ 13897c478bd9Sstevel@tonic-gate mutex_enter(&qp->rdlist_lock); 13907c478bd9Sstevel@tonic-gate rdma_done_notify(qp, xid); 13917c478bd9Sstevel@tonic-gate mutex_exit(&qp->rdlist_lock); 13927c478bd9Sstevel@tonic-gate (void) rib_free_svc_recv(s_recvp); 13937c478bd9Sstevel@tonic-gate continue; 13947c478bd9Sstevel@tonic-gate } 13957c478bd9Sstevel@tonic-gate 13967c478bd9Sstevel@tonic-gate mutex_enter(&plugin_state_lock); 13977c478bd9Sstevel@tonic-gate if (plugin_state == ACCEPT) { 13980a701b1eSRobert Gordon while ((mp = allocb(sizeof (*rdp), BPRI_LO)) 13990a701b1eSRobert Gordon == NULL) 14000a701b1eSRobert Gordon (void) strwaitbuf( 14010a701b1eSRobert Gordon sizeof (*rdp), BPRI_LO); 14027c478bd9Sstevel@tonic-gate /* 14037c478bd9Sstevel@tonic-gate * Plugin is in accept state, hence the master 14047c478bd9Sstevel@tonic-gate * transport queue for this is still accepting 14057c478bd9Sstevel@tonic-gate * requests. Hence we can call svc_queuereq to 14067c478bd9Sstevel@tonic-gate * queue this recieved msg. 14077c478bd9Sstevel@tonic-gate */ 14080a701b1eSRobert Gordon rdp = (rdma_recv_data_t *)mp->b_rptr; 14090a701b1eSRobert Gordon rdp->conn = conn; 14100a701b1eSRobert Gordon rdp->rpcmsg.addr = 14110a701b1eSRobert Gordon (caddr_t)(uintptr_t)s_recvp->vaddr; 14120a701b1eSRobert Gordon rdp->rpcmsg.type = RECV_BUFFER; 14130a701b1eSRobert Gordon rdp->rpcmsg.len = wc.wc_bytes_xfer; 14140a701b1eSRobert Gordon rdp->status = wc.wc_status; 14157c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 14167c478bd9Sstevel@tonic-gate conn->c_ref++; 14177c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 14180a701b1eSRobert Gordon mp->b_wptr += sizeof (*rdp); 14197c478bd9Sstevel@tonic-gate svc_queuereq((queue_t *)rib_stat->q, mp); 14207c478bd9Sstevel@tonic-gate mutex_exit(&plugin_state_lock); 14217c478bd9Sstevel@tonic-gate } else { 14227c478bd9Sstevel@tonic-gate /* 14237c478bd9Sstevel@tonic-gate * The master transport for this is going 14247c478bd9Sstevel@tonic-gate * away and the queue is not accepting anymore 14257c478bd9Sstevel@tonic-gate * requests for krpc, so don't do anything, just 14267c478bd9Sstevel@tonic-gate * free the msg. 14277c478bd9Sstevel@tonic-gate */ 14287c478bd9Sstevel@tonic-gate mutex_exit(&plugin_state_lock); 14297c478bd9Sstevel@tonic-gate rib_rbuf_free(conn, RECV_BUFFER, 143011606941Sjwahlig (void *)(uintptr_t)s_recvp->vaddr); 14317c478bd9Sstevel@tonic-gate } 14327c478bd9Sstevel@tonic-gate } else { 14337c478bd9Sstevel@tonic-gate rib_rbuf_free(conn, RECV_BUFFER, 143411606941Sjwahlig (void *)(uintptr_t)s_recvp->vaddr); 14357c478bd9Sstevel@tonic-gate } 14367c478bd9Sstevel@tonic-gate (void) rib_free_svc_recv(s_recvp); 14377c478bd9Sstevel@tonic-gate } 14387c478bd9Sstevel@tonic-gate } 14397c478bd9Sstevel@tonic-gate 14407f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static void 14417f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_attach_hca() 14427f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States { 14437f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_enter(&rib_stat->open_hca_lock); 1444ed629aefSSiddheshwar Mahesh (void) rpcib_open_hcas(rib_stat); 14457f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_listen(NULL); 14467f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&rib_stat->open_hca_lock); 14477f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 14487f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 14497c478bd9Sstevel@tonic-gate /* 14507c478bd9Sstevel@tonic-gate * Handles DR event of IBT_HCA_DETACH_EVENT. 14517c478bd9Sstevel@tonic-gate */ 14527c478bd9Sstevel@tonic-gate /* ARGSUSED */ 14537c478bd9Sstevel@tonic-gate static void 14547c478bd9Sstevel@tonic-gate rib_async_handler(void *clnt_private, ibt_hca_hdl_t hca_hdl, 14557c478bd9Sstevel@tonic-gate ibt_async_code_t code, ibt_async_event_t *event) 14567c478bd9Sstevel@tonic-gate { 14577c478bd9Sstevel@tonic-gate switch (code) { 14587c478bd9Sstevel@tonic-gate case IBT_HCA_ATTACH_EVENT: 14597f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_attach_hca(); 14607c478bd9Sstevel@tonic-gate break; 14617c478bd9Sstevel@tonic-gate case IBT_HCA_DETACH_EVENT: 14627c478bd9Sstevel@tonic-gate { 14637f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_hca_t *hca; 14647f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 14657f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&rib_stat->hcas_list_lock, RW_READER); 14667f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States for (hca = rib_stat->hcas_list; hca; hca = hca->next) { 14677f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&hca->state_lock, RW_READER); 14687f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if ((hca->state != HCA_DETACHED) && 14697f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (hca->hca_hdl == hca_hdl)) { 14707f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 14717f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States break; 14727f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 14737f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 14747f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 14757f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->hcas_list_lock); 14767f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 14777f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca == NULL) 14787f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return; 14797f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ASSERT(hca->hca_hdl == hca_hdl); 14807f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_detach_hca(hca); 14817c478bd9Sstevel@tonic-gate #ifdef DEBUG 14827c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_async_handler(): HCA being detached!\n"); 14837c478bd9Sstevel@tonic-gate #endif 14847c478bd9Sstevel@tonic-gate break; 14857c478bd9Sstevel@tonic-gate } 14867f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States case IBT_EVENT_PORT_UP: 14877f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 14887f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * A port is up. We should call rib_listen() since there is 14897f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * a chance that rib_listen() may have failed during 14907f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * rib_attach_hca() because the port had not been up yet. 14917f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 14927f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_listen(NULL); 14937f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States #ifdef DEBUG 14947f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States cmn_err(CE_NOTE, "rib_async_handler(): IBT_EVENT_PORT_UP\n"); 14957f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States #endif 14967f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States break; 14977c478bd9Sstevel@tonic-gate #ifdef DEBUG 14987c478bd9Sstevel@tonic-gate case IBT_EVENT_PATH_MIGRATED: 14990a701b1eSRobert Gordon cmn_err(CE_NOTE, "rib_async_handler(): " 15000a701b1eSRobert Gordon "IBT_EVENT_PATH_MIGRATED\n"); 15017c478bd9Sstevel@tonic-gate break; 15027c478bd9Sstevel@tonic-gate case IBT_EVENT_SQD: 15037c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_async_handler(): IBT_EVENT_SQD\n"); 15047c478bd9Sstevel@tonic-gate break; 15057c478bd9Sstevel@tonic-gate case IBT_EVENT_COM_EST: 15067c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_async_handler(): IBT_EVENT_COM_EST\n"); 15077c478bd9Sstevel@tonic-gate break; 15087c478bd9Sstevel@tonic-gate case IBT_ERROR_CATASTROPHIC_CHAN: 15090a701b1eSRobert Gordon cmn_err(CE_NOTE, "rib_async_handler(): " 15100a701b1eSRobert Gordon "IBT_ERROR_CATASTROPHIC_CHAN\n"); 15117c478bd9Sstevel@tonic-gate break; 15127c478bd9Sstevel@tonic-gate case IBT_ERROR_INVALID_REQUEST_CHAN: 15137c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_async_handler(): " 15147c478bd9Sstevel@tonic-gate "IBT_ERROR_INVALID_REQUEST_CHAN\n"); 15157c478bd9Sstevel@tonic-gate break; 15167c478bd9Sstevel@tonic-gate case IBT_ERROR_ACCESS_VIOLATION_CHAN: 15177c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_async_handler(): " 15187c478bd9Sstevel@tonic-gate "IBT_ERROR_ACCESS_VIOLATION_CHAN\n"); 15197c478bd9Sstevel@tonic-gate break; 15207c478bd9Sstevel@tonic-gate case IBT_ERROR_PATH_MIGRATE_REQ: 15210a701b1eSRobert Gordon cmn_err(CE_NOTE, "rib_async_handler(): " 15220a701b1eSRobert Gordon "IBT_ERROR_PATH_MIGRATE_REQ\n"); 15237c478bd9Sstevel@tonic-gate break; 15247c478bd9Sstevel@tonic-gate case IBT_ERROR_CQ: 15257c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_async_handler(): IBT_ERROR_CQ\n"); 15267c478bd9Sstevel@tonic-gate break; 15277c478bd9Sstevel@tonic-gate case IBT_ERROR_PORT_DOWN: 15287c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_async_handler(): IBT_ERROR_PORT_DOWN\n"); 15297c478bd9Sstevel@tonic-gate break; 15307c478bd9Sstevel@tonic-gate case IBT_ASYNC_OPAQUE1: 15317c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_async_handler(): IBT_ASYNC_OPAQUE1\n"); 15327c478bd9Sstevel@tonic-gate break; 15337c478bd9Sstevel@tonic-gate case IBT_ASYNC_OPAQUE2: 15347c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_async_handler(): IBT_ASYNC_OPAQUE2\n"); 15357c478bd9Sstevel@tonic-gate break; 15367c478bd9Sstevel@tonic-gate case IBT_ASYNC_OPAQUE3: 15377c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_async_handler(): IBT_ASYNC_OPAQUE3\n"); 15387c478bd9Sstevel@tonic-gate break; 15397c478bd9Sstevel@tonic-gate case IBT_ASYNC_OPAQUE4: 15407c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_async_handler(): IBT_ASYNC_OPAQUE4\n"); 15417c478bd9Sstevel@tonic-gate break; 15427c478bd9Sstevel@tonic-gate #endif 15437c478bd9Sstevel@tonic-gate default: 15447c478bd9Sstevel@tonic-gate break; 15457c478bd9Sstevel@tonic-gate } 15467c478bd9Sstevel@tonic-gate } 15477c478bd9Sstevel@tonic-gate 15487c478bd9Sstevel@tonic-gate /* 15497c478bd9Sstevel@tonic-gate * Client's reachable function. 15507c478bd9Sstevel@tonic-gate */ 15517c478bd9Sstevel@tonic-gate static rdma_stat 15527c478bd9Sstevel@tonic-gate rib_reachable(int addr_type, struct netbuf *raddr, void **handle) 15537c478bd9Sstevel@tonic-gate { 15547c478bd9Sstevel@tonic-gate rdma_stat status; 1555214ae7d0SSiddheshwar Mahesh rpcib_ping_t rpt; 1556ed629aefSSiddheshwar Mahesh struct netbuf saddr; 1557ed629aefSSiddheshwar Mahesh CONN *conn; 15587c478bd9Sstevel@tonic-gate 1559ed629aefSSiddheshwar Mahesh bzero(&saddr, sizeof (struct netbuf)); 1560ed629aefSSiddheshwar Mahesh status = rib_connect(&saddr, raddr, addr_type, &rpt, &conn); 15617c478bd9Sstevel@tonic-gate 15627c478bd9Sstevel@tonic-gate if (status == RDMA_SUCCESS) { 1563214ae7d0SSiddheshwar Mahesh *handle = (void *)rpt.hca; 1564ed629aefSSiddheshwar Mahesh /* release the reference */ 1565ed629aefSSiddheshwar Mahesh (void) rib_conn_release(conn); 15667c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 15677c478bd9Sstevel@tonic-gate } else { 15687c478bd9Sstevel@tonic-gate *handle = NULL; 15690a701b1eSRobert Gordon DTRACE_PROBE(rpcib__i__pingfailed); 15707c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 15717c478bd9Sstevel@tonic-gate } 15727c478bd9Sstevel@tonic-gate } 15737c478bd9Sstevel@tonic-gate 15747c478bd9Sstevel@tonic-gate /* Client side qp creation */ 15757c478bd9Sstevel@tonic-gate static rdma_stat 15767c478bd9Sstevel@tonic-gate rib_clnt_create_chan(rib_hca_t *hca, struct netbuf *raddr, rib_qp_t **qp) 15777c478bd9Sstevel@tonic-gate { 15787c478bd9Sstevel@tonic-gate rib_qp_t *kqp = NULL; 15797c478bd9Sstevel@tonic-gate CONN *conn; 15800a701b1eSRobert Gordon rdma_clnt_cred_ctrl_t *cc_info; 15817c478bd9Sstevel@tonic-gate 15827c478bd9Sstevel@tonic-gate ASSERT(qp != NULL); 15837c478bd9Sstevel@tonic-gate *qp = NULL; 15847c478bd9Sstevel@tonic-gate 15857c478bd9Sstevel@tonic-gate kqp = kmem_zalloc(sizeof (rib_qp_t), KM_SLEEP); 15867c478bd9Sstevel@tonic-gate conn = qptoc(kqp); 15877c478bd9Sstevel@tonic-gate kqp->hca = hca; 15887c478bd9Sstevel@tonic-gate kqp->rdmaconn.c_rdmamod = &rib_mod; 15897c478bd9Sstevel@tonic-gate kqp->rdmaconn.c_private = (caddr_t)kqp; 15907c478bd9Sstevel@tonic-gate 15917c478bd9Sstevel@tonic-gate kqp->mode = RIB_CLIENT; 15927c478bd9Sstevel@tonic-gate kqp->chan_flags = IBT_BLOCKING; 15937c478bd9Sstevel@tonic-gate conn->c_raddr.buf = kmem_alloc(raddr->len, KM_SLEEP); 15947c478bd9Sstevel@tonic-gate bcopy(raddr->buf, conn->c_raddr.buf, raddr->len); 15957c478bd9Sstevel@tonic-gate conn->c_raddr.len = conn->c_raddr.maxlen = raddr->len; 15967c478bd9Sstevel@tonic-gate /* 15977c478bd9Sstevel@tonic-gate * Initialize 15987c478bd9Sstevel@tonic-gate */ 15997c478bd9Sstevel@tonic-gate cv_init(&kqp->cb_conn_cv, NULL, CV_DEFAULT, NULL); 16007c478bd9Sstevel@tonic-gate cv_init(&kqp->posted_rbufs_cv, NULL, CV_DEFAULT, NULL); 16017c478bd9Sstevel@tonic-gate mutex_init(&kqp->posted_rbufs_lock, NULL, MUTEX_DRIVER, hca->iblock); 1602065714dcSSiddheshwar Mahesh cv_init(&kqp->send_rbufs_cv, NULL, CV_DEFAULT, NULL); 1603065714dcSSiddheshwar Mahesh mutex_init(&kqp->send_rbufs_lock, NULL, MUTEX_DRIVER, hca->iblock); 16047c478bd9Sstevel@tonic-gate mutex_init(&kqp->replylist_lock, NULL, MUTEX_DRIVER, hca->iblock); 16057c478bd9Sstevel@tonic-gate mutex_init(&kqp->rdlist_lock, NULL, MUTEX_DEFAULT, hca->iblock); 16067c478bd9Sstevel@tonic-gate mutex_init(&kqp->cb_lock, NULL, MUTEX_DRIVER, hca->iblock); 16077c478bd9Sstevel@tonic-gate cv_init(&kqp->rdmaconn.c_cv, NULL, CV_DEFAULT, NULL); 16087c478bd9Sstevel@tonic-gate mutex_init(&kqp->rdmaconn.c_lock, NULL, MUTEX_DRIVER, hca->iblock); 16090a701b1eSRobert Gordon /* 16100a701b1eSRobert Gordon * Initialize the client credit control 16110a701b1eSRobert Gordon * portion of the rdmaconn struct. 16120a701b1eSRobert Gordon */ 16130a701b1eSRobert Gordon kqp->rdmaconn.c_cc_type = RDMA_CC_CLNT; 16140a701b1eSRobert Gordon cc_info = &kqp->rdmaconn.rdma_conn_cred_ctrl_u.c_clnt_cc; 16150a701b1eSRobert Gordon cc_info->clnt_cc_granted_ops = 0; 16160a701b1eSRobert Gordon cc_info->clnt_cc_in_flight_ops = 0; 16170a701b1eSRobert Gordon cv_init(&cc_info->clnt_cc_cv, NULL, CV_DEFAULT, NULL); 16187c478bd9Sstevel@tonic-gate 16197c478bd9Sstevel@tonic-gate *qp = kqp; 16207c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 16217c478bd9Sstevel@tonic-gate } 16227c478bd9Sstevel@tonic-gate 16237c478bd9Sstevel@tonic-gate /* Server side qp creation */ 16247c478bd9Sstevel@tonic-gate static rdma_stat 16257c478bd9Sstevel@tonic-gate rib_svc_create_chan(rib_hca_t *hca, caddr_t q, uint8_t port, rib_qp_t **qp) 16267c478bd9Sstevel@tonic-gate { 16277c478bd9Sstevel@tonic-gate rib_qp_t *kqp = NULL; 16287c478bd9Sstevel@tonic-gate ibt_chan_sizes_t chan_sizes; 16297c478bd9Sstevel@tonic-gate ibt_rc_chan_alloc_args_t qp_attr; 16307c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 16310a701b1eSRobert Gordon rdma_srv_cred_ctrl_t *cc_info; 16327c478bd9Sstevel@tonic-gate 16337c478bd9Sstevel@tonic-gate *qp = NULL; 16347c478bd9Sstevel@tonic-gate 16357c478bd9Sstevel@tonic-gate kqp = kmem_zalloc(sizeof (rib_qp_t), KM_SLEEP); 16367c478bd9Sstevel@tonic-gate kqp->hca = hca; 16377c478bd9Sstevel@tonic-gate kqp->port_num = port; 16387c478bd9Sstevel@tonic-gate kqp->rdmaconn.c_rdmamod = &rib_mod; 16397c478bd9Sstevel@tonic-gate kqp->rdmaconn.c_private = (caddr_t)kqp; 16407c478bd9Sstevel@tonic-gate 16417c478bd9Sstevel@tonic-gate /* 16427c478bd9Sstevel@tonic-gate * Create the qp handle 16437c478bd9Sstevel@tonic-gate */ 16447c478bd9Sstevel@tonic-gate bzero(&qp_attr, sizeof (ibt_rc_chan_alloc_args_t)); 16457c478bd9Sstevel@tonic-gate qp_attr.rc_scq = hca->svc_scq->rib_cq_hdl; 16467c478bd9Sstevel@tonic-gate qp_attr.rc_rcq = hca->svc_rcq->rib_cq_hdl; 16477c478bd9Sstevel@tonic-gate qp_attr.rc_pd = hca->pd_hdl; 16487c478bd9Sstevel@tonic-gate qp_attr.rc_hca_port_num = port; 16497c478bd9Sstevel@tonic-gate qp_attr.rc_sizes.cs_sq_sgl = DSEG_MAX; 16507c478bd9Sstevel@tonic-gate qp_attr.rc_sizes.cs_rq_sgl = RQ_DSEG_MAX; 16517c478bd9Sstevel@tonic-gate qp_attr.rc_sizes.cs_sq = DEF_SQ_SIZE; 16527c478bd9Sstevel@tonic-gate qp_attr.rc_sizes.cs_rq = DEF_RQ_SIZE; 16537c478bd9Sstevel@tonic-gate qp_attr.rc_clone_chan = NULL; 16547c478bd9Sstevel@tonic-gate qp_attr.rc_control = IBT_CEP_RDMA_RD | IBT_CEP_RDMA_WR; 16557c478bd9Sstevel@tonic-gate qp_attr.rc_flags = IBT_WR_SIGNALED; 16567c478bd9Sstevel@tonic-gate 16577c478bd9Sstevel@tonic-gate rw_enter(&hca->state_lock, RW_READER); 16587c478bd9Sstevel@tonic-gate if (hca->state != HCA_DETACHED) { 16597c478bd9Sstevel@tonic-gate ibt_status = ibt_alloc_rc_channel(hca->hca_hdl, 16607c478bd9Sstevel@tonic-gate IBT_ACHAN_NO_FLAGS, &qp_attr, &kqp->qp_hdl, 16617c478bd9Sstevel@tonic-gate &chan_sizes); 16627c478bd9Sstevel@tonic-gate } else { 16637c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 16647c478bd9Sstevel@tonic-gate goto fail; 16657c478bd9Sstevel@tonic-gate } 16667c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 16677c478bd9Sstevel@tonic-gate 16687c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) { 16690a701b1eSRobert Gordon DTRACE_PROBE1(rpcib__i_svccreatechanfail, 16700a701b1eSRobert Gordon int, ibt_status); 16717c478bd9Sstevel@tonic-gate goto fail; 16727c478bd9Sstevel@tonic-gate } 16737c478bd9Sstevel@tonic-gate 16747c478bd9Sstevel@tonic-gate kqp->mode = RIB_SERVER; 16757c478bd9Sstevel@tonic-gate kqp->chan_flags = IBT_BLOCKING; 16767c478bd9Sstevel@tonic-gate kqp->q = q; /* server ONLY */ 16777c478bd9Sstevel@tonic-gate 16787c478bd9Sstevel@tonic-gate cv_init(&kqp->cb_conn_cv, NULL, CV_DEFAULT, NULL); 16797c478bd9Sstevel@tonic-gate cv_init(&kqp->posted_rbufs_cv, NULL, CV_DEFAULT, NULL); 16807c478bd9Sstevel@tonic-gate mutex_init(&kqp->replylist_lock, NULL, MUTEX_DEFAULT, hca->iblock); 16817c478bd9Sstevel@tonic-gate mutex_init(&kqp->posted_rbufs_lock, NULL, MUTEX_DRIVER, hca->iblock); 1682065714dcSSiddheshwar Mahesh cv_init(&kqp->send_rbufs_cv, NULL, CV_DEFAULT, NULL); 1683065714dcSSiddheshwar Mahesh mutex_init(&kqp->send_rbufs_lock, NULL, MUTEX_DRIVER, hca->iblock); 16847c478bd9Sstevel@tonic-gate mutex_init(&kqp->rdlist_lock, NULL, MUTEX_DEFAULT, hca->iblock); 16857c478bd9Sstevel@tonic-gate mutex_init(&kqp->cb_lock, NULL, MUTEX_DRIVER, hca->iblock); 16867c478bd9Sstevel@tonic-gate cv_init(&kqp->rdmaconn.c_cv, NULL, CV_DEFAULT, NULL); 16877c478bd9Sstevel@tonic-gate mutex_init(&kqp->rdmaconn.c_lock, NULL, MUTEX_DRIVER, hca->iblock); 16887c478bd9Sstevel@tonic-gate /* 16897c478bd9Sstevel@tonic-gate * Set the private data area to qp to be used in callbacks 16907c478bd9Sstevel@tonic-gate */ 16917c478bd9Sstevel@tonic-gate ibt_set_chan_private(kqp->qp_hdl, (void *)kqp); 16927c478bd9Sstevel@tonic-gate kqp->rdmaconn.c_state = C_CONNECTED; 16930a701b1eSRobert Gordon 16940a701b1eSRobert Gordon /* 16950a701b1eSRobert Gordon * Initialize the server credit control 16960a701b1eSRobert Gordon * portion of the rdmaconn struct. 16970a701b1eSRobert Gordon */ 16980a701b1eSRobert Gordon kqp->rdmaconn.c_cc_type = RDMA_CC_SRV; 16990a701b1eSRobert Gordon cc_info = &kqp->rdmaconn.rdma_conn_cred_ctrl_u.c_srv_cc; 17000a701b1eSRobert Gordon cc_info->srv_cc_buffers_granted = preposted_rbufs; 17010a701b1eSRobert Gordon cc_info->srv_cc_cur_buffers_used = 0; 17020a701b1eSRobert Gordon cc_info->srv_cc_posted = preposted_rbufs; 17030a701b1eSRobert Gordon 17047c478bd9Sstevel@tonic-gate *qp = kqp; 17050a701b1eSRobert Gordon 17067c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 17077c478bd9Sstevel@tonic-gate fail: 17087c478bd9Sstevel@tonic-gate if (kqp) 17097c478bd9Sstevel@tonic-gate kmem_free(kqp, sizeof (rib_qp_t)); 17107c478bd9Sstevel@tonic-gate 17117c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 17127c478bd9Sstevel@tonic-gate } 17137c478bd9Sstevel@tonic-gate 17147c478bd9Sstevel@tonic-gate /* ARGSUSED */ 17157c478bd9Sstevel@tonic-gate ibt_cm_status_t 17167c478bd9Sstevel@tonic-gate rib_clnt_cm_handler(void *clnt_hdl, ibt_cm_event_t *event, 17177c478bd9Sstevel@tonic-gate ibt_cm_return_args_t *ret_args, void *priv_data, 17187c478bd9Sstevel@tonic-gate ibt_priv_data_len_t len) 17197c478bd9Sstevel@tonic-gate { 17207c478bd9Sstevel@tonic-gate rib_hca_t *hca; 17217c478bd9Sstevel@tonic-gate 17227f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca = (rib_hca_t *)clnt_hdl; 17237c478bd9Sstevel@tonic-gate 17247c478bd9Sstevel@tonic-gate switch (event->cm_type) { 17257c478bd9Sstevel@tonic-gate 17267c478bd9Sstevel@tonic-gate /* got a connection close event */ 17277c478bd9Sstevel@tonic-gate case IBT_CM_EVENT_CONN_CLOSED: 17287c478bd9Sstevel@tonic-gate { 17297c478bd9Sstevel@tonic-gate CONN *conn; 17307c478bd9Sstevel@tonic-gate rib_qp_t *qp; 17317c478bd9Sstevel@tonic-gate 17327c478bd9Sstevel@tonic-gate /* check reason why connection was closed */ 17337c478bd9Sstevel@tonic-gate switch (event->cm_event.closed) { 17347c478bd9Sstevel@tonic-gate case IBT_CM_CLOSED_DREP_RCVD: 17357c478bd9Sstevel@tonic-gate case IBT_CM_CLOSED_DREQ_TIMEOUT: 17367c478bd9Sstevel@tonic-gate case IBT_CM_CLOSED_DUP: 17377c478bd9Sstevel@tonic-gate case IBT_CM_CLOSED_ABORT: 17387c478bd9Sstevel@tonic-gate case IBT_CM_CLOSED_ALREADY: 17397c478bd9Sstevel@tonic-gate /* 17407c478bd9Sstevel@tonic-gate * These cases indicate the local end initiated 17417c478bd9Sstevel@tonic-gate * the closing of the channel. Nothing to do here. 17427c478bd9Sstevel@tonic-gate */ 17437c478bd9Sstevel@tonic-gate break; 17447c478bd9Sstevel@tonic-gate default: 17457c478bd9Sstevel@tonic-gate /* 17467c478bd9Sstevel@tonic-gate * Reason for CONN_CLOSED event must be one of 17477c478bd9Sstevel@tonic-gate * IBT_CM_CLOSED_DREQ_RCVD or IBT_CM_CLOSED_REJ_RCVD 17487c478bd9Sstevel@tonic-gate * or IBT_CM_CLOSED_STALE. These indicate cases were 17497c478bd9Sstevel@tonic-gate * the remote end is closing the channel. In these 17507c478bd9Sstevel@tonic-gate * cases free the channel and transition to error 17517c478bd9Sstevel@tonic-gate * state 17527c478bd9Sstevel@tonic-gate */ 17537c478bd9Sstevel@tonic-gate qp = ibt_get_chan_private(event->cm_channel); 17547c478bd9Sstevel@tonic-gate conn = qptoc(qp); 17557c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 17567c478bd9Sstevel@tonic-gate if (conn->c_state == C_DISCONN_PEND) { 17577c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 17587c478bd9Sstevel@tonic-gate break; 17597c478bd9Sstevel@tonic-gate } 17607c478bd9Sstevel@tonic-gate 17610a701b1eSRobert Gordon conn->c_state = C_ERROR_CONN; 17627c478bd9Sstevel@tonic-gate 17637c478bd9Sstevel@tonic-gate /* 17647c478bd9Sstevel@tonic-gate * Free the conn if c_ref is down to 0 already 17657c478bd9Sstevel@tonic-gate */ 17667c478bd9Sstevel@tonic-gate if (conn->c_ref == 0) { 17677c478bd9Sstevel@tonic-gate /* 17687c478bd9Sstevel@tonic-gate * Remove from list and free conn 17697c478bd9Sstevel@tonic-gate */ 17707c478bd9Sstevel@tonic-gate conn->c_state = C_DISCONN_PEND; 17717c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 17727f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&hca->state_lock, RW_READER); 17737f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca->state != HCA_DETACHED) 17747c478bd9Sstevel@tonic-gate (void) rib_disconnect_channel(conn, 17757c478bd9Sstevel@tonic-gate &hca->cl_conn_list); 17767f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 17777c478bd9Sstevel@tonic-gate } else { 1778065714dcSSiddheshwar Mahesh /* 1779065714dcSSiddheshwar Mahesh * conn will be freed when c_ref goes to 0. 1780065714dcSSiddheshwar Mahesh * Indicate to cleaning thread not to close 1781065714dcSSiddheshwar Mahesh * the connection, but just free the channel. 1782065714dcSSiddheshwar Mahesh */ 1783065714dcSSiddheshwar Mahesh conn->c_flags |= C_CLOSE_NOTNEEDED; 17847c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 17857c478bd9Sstevel@tonic-gate } 17867c478bd9Sstevel@tonic-gate #ifdef DEBUG 17877c478bd9Sstevel@tonic-gate if (rib_debug) 17887c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_clnt_cm_handler: " 17897c478bd9Sstevel@tonic-gate "(CONN_CLOSED) channel disconnected"); 17907c478bd9Sstevel@tonic-gate #endif 17917c478bd9Sstevel@tonic-gate break; 17927c478bd9Sstevel@tonic-gate } 17937c478bd9Sstevel@tonic-gate break; 17947c478bd9Sstevel@tonic-gate } 17957c478bd9Sstevel@tonic-gate default: 17967c478bd9Sstevel@tonic-gate break; 17977c478bd9Sstevel@tonic-gate } 17987c478bd9Sstevel@tonic-gate return (IBT_CM_ACCEPT); 17997c478bd9Sstevel@tonic-gate } 18007c478bd9Sstevel@tonic-gate 18017c478bd9Sstevel@tonic-gate /* 18027c478bd9Sstevel@tonic-gate * Connect to the server. 18037c478bd9Sstevel@tonic-gate */ 18047c478bd9Sstevel@tonic-gate rdma_stat 1805214ae7d0SSiddheshwar Mahesh rib_conn_to_srv(rib_hca_t *hca, rib_qp_t *qp, rpcib_ping_t *rptp) 18067c478bd9Sstevel@tonic-gate { 18077c478bd9Sstevel@tonic-gate ibt_chan_open_args_t chan_args; /* channel args */ 18087c478bd9Sstevel@tonic-gate ibt_chan_sizes_t chan_sizes; 18097c478bd9Sstevel@tonic-gate ibt_rc_chan_alloc_args_t qp_attr; 18107c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 18117c478bd9Sstevel@tonic-gate ibt_rc_returns_t ret_args; /* conn reject info */ 18127c478bd9Sstevel@tonic-gate int refresh = REFRESH_ATTEMPTS; /* refresh if IBT_CM_CONN_STALE */ 18130a701b1eSRobert Gordon ibt_ip_cm_info_t ipcm_info; 18140a701b1eSRobert Gordon uint8_t cmp_ip_pvt[IBT_IP_HDR_PRIV_DATA_SZ]; 18150a701b1eSRobert Gordon 18167c478bd9Sstevel@tonic-gate 18177c478bd9Sstevel@tonic-gate (void) bzero(&chan_args, sizeof (chan_args)); 18187c478bd9Sstevel@tonic-gate (void) bzero(&qp_attr, sizeof (ibt_rc_chan_alloc_args_t)); 18190a701b1eSRobert Gordon (void) bzero(&ipcm_info, sizeof (ibt_ip_cm_info_t)); 18200a701b1eSRobert Gordon 1821214ae7d0SSiddheshwar Mahesh ipcm_info.src_addr.family = rptp->srcip.family; 1822214ae7d0SSiddheshwar Mahesh switch (ipcm_info.src_addr.family) { 18230a701b1eSRobert Gordon case AF_INET: 1824214ae7d0SSiddheshwar Mahesh ipcm_info.src_addr.un.ip4addr = rptp->srcip.un.ip4addr; 18250a701b1eSRobert Gordon break; 18260a701b1eSRobert Gordon case AF_INET6: 1827214ae7d0SSiddheshwar Mahesh ipcm_info.src_addr.un.ip6addr = rptp->srcip.un.ip6addr; 18280a701b1eSRobert Gordon break; 18290a701b1eSRobert Gordon } 18300a701b1eSRobert Gordon 1831214ae7d0SSiddheshwar Mahesh ipcm_info.dst_addr.family = rptp->srcip.family; 1832214ae7d0SSiddheshwar Mahesh switch (ipcm_info.dst_addr.family) { 18330a701b1eSRobert Gordon case AF_INET: 1834214ae7d0SSiddheshwar Mahesh ipcm_info.dst_addr.un.ip4addr = rptp->dstip.un.ip4addr; 18350a701b1eSRobert Gordon break; 18360a701b1eSRobert Gordon case AF_INET6: 1837214ae7d0SSiddheshwar Mahesh ipcm_info.dst_addr.un.ip6addr = rptp->dstip.un.ip6addr; 18380a701b1eSRobert Gordon break; 18390a701b1eSRobert Gordon } 18400a701b1eSRobert Gordon 1841f837ee4aSSiddheshwar Mahesh ipcm_info.src_port = (in_port_t)nfs_rdma_port; 18420a701b1eSRobert Gordon 18430a701b1eSRobert Gordon ibt_status = ibt_format_ip_private_data(&ipcm_info, 18440a701b1eSRobert Gordon IBT_IP_HDR_PRIV_DATA_SZ, cmp_ip_pvt); 18450a701b1eSRobert Gordon 18460a701b1eSRobert Gordon if (ibt_status != IBT_SUCCESS) { 18470a701b1eSRobert Gordon cmn_err(CE_WARN, "ibt_format_ip_private_data failed\n"); 18480a701b1eSRobert Gordon return (-1); 18490a701b1eSRobert Gordon } 18507c478bd9Sstevel@tonic-gate 1851214ae7d0SSiddheshwar Mahesh qp_attr.rc_hca_port_num = rptp->path.pi_prim_cep_path.cep_hca_port_num; 18527c478bd9Sstevel@tonic-gate /* Alloc a RC channel */ 18537c478bd9Sstevel@tonic-gate qp_attr.rc_scq = hca->clnt_scq->rib_cq_hdl; 18547c478bd9Sstevel@tonic-gate qp_attr.rc_rcq = hca->clnt_rcq->rib_cq_hdl; 18557c478bd9Sstevel@tonic-gate qp_attr.rc_pd = hca->pd_hdl; 18567c478bd9Sstevel@tonic-gate qp_attr.rc_sizes.cs_sq_sgl = DSEG_MAX; 18577c478bd9Sstevel@tonic-gate qp_attr.rc_sizes.cs_rq_sgl = RQ_DSEG_MAX; 18587c478bd9Sstevel@tonic-gate qp_attr.rc_sizes.cs_sq = DEF_SQ_SIZE; 18597c478bd9Sstevel@tonic-gate qp_attr.rc_sizes.cs_rq = DEF_RQ_SIZE; 18607c478bd9Sstevel@tonic-gate qp_attr.rc_clone_chan = NULL; 18617c478bd9Sstevel@tonic-gate qp_attr.rc_control = IBT_CEP_RDMA_RD | IBT_CEP_RDMA_WR; 18627c478bd9Sstevel@tonic-gate qp_attr.rc_flags = IBT_WR_SIGNALED; 18637c478bd9Sstevel@tonic-gate 1864f837ee4aSSiddheshwar Mahesh rptp->path.pi_sid = ibt_get_ip_sid(IPPROTO_TCP, nfs_rdma_port); 1865214ae7d0SSiddheshwar Mahesh chan_args.oc_path = &rptp->path; 1866f837ee4aSSiddheshwar Mahesh 18677c478bd9Sstevel@tonic-gate chan_args.oc_cm_handler = rib_clnt_cm_handler; 18687f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States chan_args.oc_cm_clnt_private = (void *)hca; 18690a701b1eSRobert Gordon chan_args.oc_rdma_ra_out = 4; 18700a701b1eSRobert Gordon chan_args.oc_rdma_ra_in = 4; 18717c478bd9Sstevel@tonic-gate chan_args.oc_path_retry_cnt = 2; 18727c478bd9Sstevel@tonic-gate chan_args.oc_path_rnr_retry_cnt = RNR_RETRIES; 18730a701b1eSRobert Gordon chan_args.oc_priv_data = cmp_ip_pvt; 18740a701b1eSRobert Gordon chan_args.oc_priv_data_len = IBT_IP_HDR_PRIV_DATA_SZ; 18757c478bd9Sstevel@tonic-gate 18767c478bd9Sstevel@tonic-gate refresh: 18777c478bd9Sstevel@tonic-gate rw_enter(&hca->state_lock, RW_READER); 18787c478bd9Sstevel@tonic-gate if (hca->state != HCA_DETACHED) { 18797c478bd9Sstevel@tonic-gate ibt_status = ibt_alloc_rc_channel(hca->hca_hdl, 18800a701b1eSRobert Gordon IBT_ACHAN_NO_FLAGS, 18810a701b1eSRobert Gordon &qp_attr, &qp->qp_hdl, 18827c478bd9Sstevel@tonic-gate &chan_sizes); 18837c478bd9Sstevel@tonic-gate } else { 18847c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 18857c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 18867c478bd9Sstevel@tonic-gate } 18877c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 18887c478bd9Sstevel@tonic-gate 18897c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) { 18900a701b1eSRobert Gordon DTRACE_PROBE1(rpcib__i_conntosrv, 18910a701b1eSRobert Gordon int, ibt_status); 18927c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 18937c478bd9Sstevel@tonic-gate } 18947c478bd9Sstevel@tonic-gate 18957c478bd9Sstevel@tonic-gate /* Connect to the Server */ 18967c478bd9Sstevel@tonic-gate (void) bzero(&ret_args, sizeof (ret_args)); 18977c478bd9Sstevel@tonic-gate mutex_enter(&qp->cb_lock); 18987c478bd9Sstevel@tonic-gate ibt_status = ibt_open_rc_channel(qp->qp_hdl, IBT_OCHAN_NO_FLAGS, 18997c478bd9Sstevel@tonic-gate IBT_BLOCKING, &chan_args, &ret_args); 19007c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) { 19010a701b1eSRobert Gordon DTRACE_PROBE2(rpcib__i_openrctosrv, 19020a701b1eSRobert Gordon int, ibt_status, int, ret_args.rc_status); 19030a701b1eSRobert Gordon 19047c478bd9Sstevel@tonic-gate (void) ibt_free_channel(qp->qp_hdl); 19057c478bd9Sstevel@tonic-gate qp->qp_hdl = NULL; 19067c478bd9Sstevel@tonic-gate mutex_exit(&qp->cb_lock); 19077c478bd9Sstevel@tonic-gate if (refresh-- && ibt_status == IBT_CM_FAILURE && 19087c478bd9Sstevel@tonic-gate ret_args.rc_status == IBT_CM_CONN_STALE) { 19097c478bd9Sstevel@tonic-gate /* 19107c478bd9Sstevel@tonic-gate * Got IBT_CM_CONN_STALE probably because of stale 19117c478bd9Sstevel@tonic-gate * data on the passive end of a channel that existed 19127c478bd9Sstevel@tonic-gate * prior to reboot. Retry establishing a channel 19137c478bd9Sstevel@tonic-gate * REFRESH_ATTEMPTS times, during which time the 19147c478bd9Sstevel@tonic-gate * stale conditions on the server might clear up. 19157c478bd9Sstevel@tonic-gate */ 19167c478bd9Sstevel@tonic-gate goto refresh; 19177c478bd9Sstevel@tonic-gate } 19187c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 19197c478bd9Sstevel@tonic-gate } 19207c478bd9Sstevel@tonic-gate mutex_exit(&qp->cb_lock); 19217c478bd9Sstevel@tonic-gate /* 19227c478bd9Sstevel@tonic-gate * Set the private data area to qp to be used in callbacks 19237c478bd9Sstevel@tonic-gate */ 19247c478bd9Sstevel@tonic-gate ibt_set_chan_private(qp->qp_hdl, (void *)qp); 19257c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 19267c478bd9Sstevel@tonic-gate } 19277c478bd9Sstevel@tonic-gate 19287c478bd9Sstevel@tonic-gate rdma_stat 1929214ae7d0SSiddheshwar Mahesh rib_ping_srv(int addr_type, struct netbuf *raddr, rpcib_ping_t *rptp) 19307c478bd9Sstevel@tonic-gate { 19317f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States uint_t i, addr_count; 19327c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 19330a701b1eSRobert Gordon uint8_t num_paths_p; 19340a701b1eSRobert Gordon ibt_ip_path_attr_t ipattr; 19350a701b1eSRobert Gordon ibt_path_ip_src_t srcip; 1936e11c3f44Smeem rpcib_ipaddrs_t addrs4; 1937e11c3f44Smeem rpcib_ipaddrs_t addrs6; 1938e11c3f44Smeem struct sockaddr_in *sinp; 1939e11c3f44Smeem struct sockaddr_in6 *sin6p; 19407f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rdma_stat retval = RDMA_FAILED; 19417f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_hca_t *hca; 19420a701b1eSRobert Gordon 19437f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if ((addr_type != AF_INET) && (addr_type != AF_INET6)) 19447f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (RDMA_INVAL); 19457c478bd9Sstevel@tonic-gate ASSERT(raddr->buf != NULL); 19467c478bd9Sstevel@tonic-gate 19470a701b1eSRobert Gordon bzero(&ipattr, sizeof (ibt_ip_path_attr_t)); 19487c478bd9Sstevel@tonic-gate 1949e11c3f44Smeem if (!rpcib_get_ib_addresses(&addrs4, &addrs6) || 1950e11c3f44Smeem (addrs4.ri_count == 0 && addrs6.ri_count == 0)) { 1951e11c3f44Smeem retval = RDMA_FAILED; 19527f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States goto done2; 19530a701b1eSRobert Gordon } 19540a701b1eSRobert Gordon 19557f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (addr_type == AF_INET) { 19567f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States addr_count = addrs4.ri_count; 1957e11c3f44Smeem sinp = (struct sockaddr_in *)raddr->buf; 1958214ae7d0SSiddheshwar Mahesh rptp->dstip.family = AF_INET; 1959214ae7d0SSiddheshwar Mahesh rptp->dstip.un.ip4addr = sinp->sin_addr.s_addr; 1960e11c3f44Smeem sinp = addrs4.ri_list; 19617f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } else { 19627f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States addr_count = addrs6.ri_count; 1963e11c3f44Smeem sin6p = (struct sockaddr_in6 *)raddr->buf; 1964214ae7d0SSiddheshwar Mahesh rptp->dstip.family = AF_INET6; 1965214ae7d0SSiddheshwar Mahesh rptp->dstip.un.ip6addr = sin6p->sin6_addr; 1966e11c3f44Smeem sin6p = addrs6.ri_list; 19677f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 19687f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 19697f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&rib_stat->hcas_list_lock, RW_READER); 19707f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States for (hca = rib_stat->hcas_list; hca; hca = hca->next) { 19717f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&hca->state_lock, RW_READER); 19727f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca->state == HCA_DETACHED) { 19737f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 19747f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States continue; 19757f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 19760a701b1eSRobert Gordon 1977214ae7d0SSiddheshwar Mahesh ipattr.ipa_dst_ip = &rptp->dstip; 19787f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ipattr.ipa_hca_guid = hca->hca_guid; 19790a701b1eSRobert Gordon ipattr.ipa_ndst = 1; 19800a701b1eSRobert Gordon ipattr.ipa_max_paths = 1; 1981214ae7d0SSiddheshwar Mahesh ipattr.ipa_src_ip.family = rptp->dstip.family; 19827f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States for (i = 0; i < addr_count; i++) { 1983214ae7d0SSiddheshwar Mahesh num_paths_p = 0; 19847f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (addr_type == AF_INET) { 19857f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ipattr.ipa_src_ip.un.ip4addr = 19867f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States sinp[i].sin_addr.s_addr; 19877f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } else { 19887f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ipattr.ipa_src_ip.un.ip6addr = 19897f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States sin6p[i].sin6_addr; 19907f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 1991214ae7d0SSiddheshwar Mahesh bzero(&srcip, sizeof (ibt_path_ip_src_t)); 19920a701b1eSRobert Gordon 19930a701b1eSRobert Gordon ibt_status = ibt_get_ip_paths(rib_stat->ibt_clnt_hdl, 1994214ae7d0SSiddheshwar Mahesh IBT_PATH_NO_FLAGS, &ipattr, &rptp->path, 1995214ae7d0SSiddheshwar Mahesh &num_paths_p, &srcip); 19960a701b1eSRobert Gordon if (ibt_status == IBT_SUCCESS && 19970a701b1eSRobert Gordon num_paths_p != 0 && 19987f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rptp->path.pi_hca_guid == hca->hca_guid) { 19997f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rptp->hca = hca; 20007f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 20017f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (addr_type == AF_INET) { 20027f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rptp->srcip.family = AF_INET; 20037f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rptp->srcip.un.ip4addr = 20047f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States srcip.ip_primary.un.ip4addr; 20057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } else { 2006214ae7d0SSiddheshwar Mahesh rptp->srcip.family = AF_INET6; 2007214ae7d0SSiddheshwar Mahesh rptp->srcip.un.ip6addr = 2008214ae7d0SSiddheshwar Mahesh srcip.ip_primary.un.ip6addr; 20097c478bd9Sstevel@tonic-gate 20107c478bd9Sstevel@tonic-gate } 20117f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States retval = RDMA_SUCCESS; 20127f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States goto done1; 20137f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 20147f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 20157f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 20167f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 20177f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States done1: 20187f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->hcas_list_lock); 20197f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States done2: 2020e11c3f44Smeem if (addrs4.ri_size > 0) 2021e11c3f44Smeem kmem_free(addrs4.ri_list, addrs4.ri_size); 2022e11c3f44Smeem if (addrs6.ri_size > 0) 2023e11c3f44Smeem kmem_free(addrs6.ri_list, addrs6.ri_size); 2024e11c3f44Smeem return (retval); 20257c478bd9Sstevel@tonic-gate } 20267c478bd9Sstevel@tonic-gate 20277c478bd9Sstevel@tonic-gate /* 20287c478bd9Sstevel@tonic-gate * Close channel, remove from connection list and 20297c478bd9Sstevel@tonic-gate * free up resources allocated for that channel. 20307c478bd9Sstevel@tonic-gate */ 20317c478bd9Sstevel@tonic-gate rdma_stat 20327c478bd9Sstevel@tonic-gate rib_disconnect_channel(CONN *conn, rib_conn_list_t *conn_list) 20337c478bd9Sstevel@tonic-gate { 20347c478bd9Sstevel@tonic-gate rib_qp_t *qp = ctoqp(conn); 20357c478bd9Sstevel@tonic-gate rib_hca_t *hca; 20367c478bd9Sstevel@tonic-gate 2037065714dcSSiddheshwar Mahesh mutex_enter(&conn->c_lock); 2038065714dcSSiddheshwar Mahesh if (conn->c_timeout != NULL) { 2039065714dcSSiddheshwar Mahesh mutex_exit(&conn->c_lock); 2040065714dcSSiddheshwar Mahesh (void) untimeout(conn->c_timeout); 2041065714dcSSiddheshwar Mahesh mutex_enter(&conn->c_lock); 2042065714dcSSiddheshwar Mahesh } 2043065714dcSSiddheshwar Mahesh 2044065714dcSSiddheshwar Mahesh while (conn->c_flags & C_CLOSE_PENDING) { 2045065714dcSSiddheshwar Mahesh cv_wait(&conn->c_cv, &conn->c_lock); 2046065714dcSSiddheshwar Mahesh } 2047065714dcSSiddheshwar Mahesh mutex_exit(&conn->c_lock); 2048065714dcSSiddheshwar Mahesh 20497c478bd9Sstevel@tonic-gate /* 20507c478bd9Sstevel@tonic-gate * c_ref == 0 and connection is in C_DISCONN_PEND 20517c478bd9Sstevel@tonic-gate */ 20527c478bd9Sstevel@tonic-gate hca = qp->hca; 20537c478bd9Sstevel@tonic-gate if (conn_list != NULL) 20547c478bd9Sstevel@tonic-gate (void) rib_rm_conn(conn, conn_list); 20550a701b1eSRobert Gordon 20567c478bd9Sstevel@tonic-gate /* 2057065714dcSSiddheshwar Mahesh * There is only one case where we get here with 2058065714dcSSiddheshwar Mahesh * qp_hdl = NULL, which is during connection setup on 2059065714dcSSiddheshwar Mahesh * the client. In such a case there are no posted 2060065714dcSSiddheshwar Mahesh * send/recv buffers. 20617c478bd9Sstevel@tonic-gate */ 2062065714dcSSiddheshwar Mahesh if (qp->qp_hdl != NULL) { 20637c478bd9Sstevel@tonic-gate mutex_enter(&qp->posted_rbufs_lock); 20647c478bd9Sstevel@tonic-gate while (qp->n_posted_rbufs) 20657c478bd9Sstevel@tonic-gate cv_wait(&qp->posted_rbufs_cv, &qp->posted_rbufs_lock); 20667c478bd9Sstevel@tonic-gate mutex_exit(&qp->posted_rbufs_lock); 2067065714dcSSiddheshwar Mahesh 2068065714dcSSiddheshwar Mahesh mutex_enter(&qp->send_rbufs_lock); 2069065714dcSSiddheshwar Mahesh while (qp->n_send_rbufs) 2070065714dcSSiddheshwar Mahesh cv_wait(&qp->send_rbufs_cv, &qp->send_rbufs_lock); 2071065714dcSSiddheshwar Mahesh mutex_exit(&qp->send_rbufs_lock); 2072065714dcSSiddheshwar Mahesh 20737c478bd9Sstevel@tonic-gate (void) ibt_free_channel(qp->qp_hdl); 20747c478bd9Sstevel@tonic-gate qp->qp_hdl = NULL; 20757c478bd9Sstevel@tonic-gate } 20760a701b1eSRobert Gordon 20777c478bd9Sstevel@tonic-gate ASSERT(qp->rdlist == NULL); 20780a701b1eSRobert Gordon 20797c478bd9Sstevel@tonic-gate if (qp->replylist != NULL) { 20807c478bd9Sstevel@tonic-gate (void) rib_rem_replylist(qp); 20817c478bd9Sstevel@tonic-gate } 20827c478bd9Sstevel@tonic-gate 20837c478bd9Sstevel@tonic-gate cv_destroy(&qp->cb_conn_cv); 20847c478bd9Sstevel@tonic-gate cv_destroy(&qp->posted_rbufs_cv); 2085065714dcSSiddheshwar Mahesh cv_destroy(&qp->send_rbufs_cv); 20867c478bd9Sstevel@tonic-gate mutex_destroy(&qp->cb_lock); 20877c478bd9Sstevel@tonic-gate mutex_destroy(&qp->replylist_lock); 20887c478bd9Sstevel@tonic-gate mutex_destroy(&qp->posted_rbufs_lock); 2089065714dcSSiddheshwar Mahesh mutex_destroy(&qp->send_rbufs_lock); 20907c478bd9Sstevel@tonic-gate mutex_destroy(&qp->rdlist_lock); 20917c478bd9Sstevel@tonic-gate 20927c478bd9Sstevel@tonic-gate cv_destroy(&conn->c_cv); 20937c478bd9Sstevel@tonic-gate mutex_destroy(&conn->c_lock); 20947c478bd9Sstevel@tonic-gate 20957c478bd9Sstevel@tonic-gate if (conn->c_raddr.buf != NULL) { 20967c478bd9Sstevel@tonic-gate kmem_free(conn->c_raddr.buf, conn->c_raddr.len); 20977c478bd9Sstevel@tonic-gate } 20987c478bd9Sstevel@tonic-gate if (conn->c_laddr.buf != NULL) { 20997c478bd9Sstevel@tonic-gate kmem_free(conn->c_laddr.buf, conn->c_laddr.len); 21007c478bd9Sstevel@tonic-gate } 2101*7523bef8SSiddheshwar Mahesh if (conn->c_netid != NULL) { 2102*7523bef8SSiddheshwar Mahesh kmem_free(conn->c_netid, (strlen(conn->c_netid) + 1)); 2103*7523bef8SSiddheshwar Mahesh } 21040a701b1eSRobert Gordon 21050a701b1eSRobert Gordon /* 21060a701b1eSRobert Gordon * Credit control cleanup. 21070a701b1eSRobert Gordon */ 21080a701b1eSRobert Gordon if (qp->rdmaconn.c_cc_type == RDMA_CC_CLNT) { 21090a701b1eSRobert Gordon rdma_clnt_cred_ctrl_t *cc_info; 21100a701b1eSRobert Gordon cc_info = &qp->rdmaconn.rdma_conn_cred_ctrl_u.c_clnt_cc; 21110a701b1eSRobert Gordon cv_destroy(&cc_info->clnt_cc_cv); 21120a701b1eSRobert Gordon } 21130a701b1eSRobert Gordon 21147c478bd9Sstevel@tonic-gate kmem_free(qp, sizeof (rib_qp_t)); 21157c478bd9Sstevel@tonic-gate 21167c478bd9Sstevel@tonic-gate /* 21177c478bd9Sstevel@tonic-gate * If HCA has been DETACHED and the srv/clnt_conn_list is NULL, 21187c478bd9Sstevel@tonic-gate * then the hca is no longer being used. 21197c478bd9Sstevel@tonic-gate */ 21207c478bd9Sstevel@tonic-gate if (conn_list != NULL) { 21217c478bd9Sstevel@tonic-gate rw_enter(&hca->state_lock, RW_READER); 21227c478bd9Sstevel@tonic-gate if (hca->state == HCA_DETACHED) { 21237c478bd9Sstevel@tonic-gate rw_enter(&hca->srv_conn_list.conn_lock, RW_READER); 21247c478bd9Sstevel@tonic-gate if (hca->srv_conn_list.conn_hd == NULL) { 21257c478bd9Sstevel@tonic-gate rw_enter(&hca->cl_conn_list.conn_lock, 21267c478bd9Sstevel@tonic-gate RW_READER); 21270a701b1eSRobert Gordon 21287c478bd9Sstevel@tonic-gate if (hca->cl_conn_list.conn_hd == NULL) { 21297c478bd9Sstevel@tonic-gate mutex_enter(&hca->inuse_lock); 21307c478bd9Sstevel@tonic-gate hca->inuse = FALSE; 21317c478bd9Sstevel@tonic-gate cv_signal(&hca->cb_cv); 21327c478bd9Sstevel@tonic-gate mutex_exit(&hca->inuse_lock); 21337c478bd9Sstevel@tonic-gate } 21347c478bd9Sstevel@tonic-gate rw_exit(&hca->cl_conn_list.conn_lock); 21357c478bd9Sstevel@tonic-gate } 21367c478bd9Sstevel@tonic-gate rw_exit(&hca->srv_conn_list.conn_lock); 21377c478bd9Sstevel@tonic-gate } 21387c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 21397c478bd9Sstevel@tonic-gate } 21400a701b1eSRobert Gordon 21417c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 21427c478bd9Sstevel@tonic-gate } 21437c478bd9Sstevel@tonic-gate 21447c478bd9Sstevel@tonic-gate /* 2145065714dcSSiddheshwar Mahesh * All sends are done under the protection of 2146065714dcSSiddheshwar Mahesh * the wdesc->sendwait_lock. n_send_rbufs count 2147065714dcSSiddheshwar Mahesh * is protected using the send_rbufs_lock. 2148065714dcSSiddheshwar Mahesh * lock ordering is: 2149065714dcSSiddheshwar Mahesh * sendwait_lock -> send_rbufs_lock 2150065714dcSSiddheshwar Mahesh */ 2151065714dcSSiddheshwar Mahesh 2152065714dcSSiddheshwar Mahesh void 2153065714dcSSiddheshwar Mahesh rib_send_hold(rib_qp_t *qp) 2154065714dcSSiddheshwar Mahesh { 2155065714dcSSiddheshwar Mahesh mutex_enter(&qp->send_rbufs_lock); 2156065714dcSSiddheshwar Mahesh qp->n_send_rbufs++; 2157065714dcSSiddheshwar Mahesh mutex_exit(&qp->send_rbufs_lock); 2158065714dcSSiddheshwar Mahesh } 2159065714dcSSiddheshwar Mahesh 2160065714dcSSiddheshwar Mahesh void 2161065714dcSSiddheshwar Mahesh rib_send_rele(rib_qp_t *qp) 2162065714dcSSiddheshwar Mahesh { 2163065714dcSSiddheshwar Mahesh mutex_enter(&qp->send_rbufs_lock); 2164065714dcSSiddheshwar Mahesh qp->n_send_rbufs--; 2165065714dcSSiddheshwar Mahesh if (qp->n_send_rbufs == 0) 2166065714dcSSiddheshwar Mahesh cv_signal(&qp->send_rbufs_cv); 2167065714dcSSiddheshwar Mahesh mutex_exit(&qp->send_rbufs_lock); 2168065714dcSSiddheshwar Mahesh } 2169065714dcSSiddheshwar Mahesh 2170065714dcSSiddheshwar Mahesh /* 21717c478bd9Sstevel@tonic-gate * Wait for send completion notification. Only on receiving a 21727c478bd9Sstevel@tonic-gate * notification be it a successful or error completion, free the 21737c478bd9Sstevel@tonic-gate * send_wid. 21747c478bd9Sstevel@tonic-gate */ 21757c478bd9Sstevel@tonic-gate static rdma_stat 21767c478bd9Sstevel@tonic-gate rib_sendwait(rib_qp_t *qp, struct send_wid *wd) 21777c478bd9Sstevel@tonic-gate { 21787c478bd9Sstevel@tonic-gate clock_t timout, cv_wait_ret; 21797c478bd9Sstevel@tonic-gate rdma_stat error = RDMA_SUCCESS; 21807c478bd9Sstevel@tonic-gate int i; 21817c478bd9Sstevel@tonic-gate 21827c478bd9Sstevel@tonic-gate /* 21837c478bd9Sstevel@tonic-gate * Wait for send to complete 21847c478bd9Sstevel@tonic-gate */ 21857c478bd9Sstevel@tonic-gate ASSERT(wd != NULL); 21867c478bd9Sstevel@tonic-gate mutex_enter(&wd->sendwait_lock); 21877c478bd9Sstevel@tonic-gate if (wd->status == (uint_t)SEND_WAIT) { 21887c478bd9Sstevel@tonic-gate timout = drv_usectohz(SEND_WAIT_TIME * 1000000) + 21897c478bd9Sstevel@tonic-gate ddi_get_lbolt(); 21900a701b1eSRobert Gordon 21917c478bd9Sstevel@tonic-gate if (qp->mode == RIB_SERVER) { 21927c478bd9Sstevel@tonic-gate while ((cv_wait_ret = cv_timedwait(&wd->wait_cv, 21937c478bd9Sstevel@tonic-gate &wd->sendwait_lock, timout)) > 0 && 21947c478bd9Sstevel@tonic-gate wd->status == (uint_t)SEND_WAIT) 21957c478bd9Sstevel@tonic-gate ; 21967c478bd9Sstevel@tonic-gate switch (cv_wait_ret) { 21977c478bd9Sstevel@tonic-gate case -1: /* timeout */ 21980a701b1eSRobert Gordon DTRACE_PROBE(rpcib__i__srvsendwait__timeout); 21990a701b1eSRobert Gordon 22007c478bd9Sstevel@tonic-gate wd->cv_sig = 0; /* no signal needed */ 22017c478bd9Sstevel@tonic-gate error = RDMA_TIMEDOUT; 22027c478bd9Sstevel@tonic-gate break; 22037c478bd9Sstevel@tonic-gate default: /* got send completion */ 22047c478bd9Sstevel@tonic-gate break; 22057c478bd9Sstevel@tonic-gate } 22067c478bd9Sstevel@tonic-gate } else { 22077c478bd9Sstevel@tonic-gate while ((cv_wait_ret = cv_timedwait_sig(&wd->wait_cv, 22087c478bd9Sstevel@tonic-gate &wd->sendwait_lock, timout)) > 0 && 22097c478bd9Sstevel@tonic-gate wd->status == (uint_t)SEND_WAIT) 22107c478bd9Sstevel@tonic-gate ; 22117c478bd9Sstevel@tonic-gate switch (cv_wait_ret) { 22127c478bd9Sstevel@tonic-gate case -1: /* timeout */ 22130a701b1eSRobert Gordon DTRACE_PROBE(rpcib__i__clntsendwait__timeout); 22140a701b1eSRobert Gordon 22157c478bd9Sstevel@tonic-gate wd->cv_sig = 0; /* no signal needed */ 22167c478bd9Sstevel@tonic-gate error = RDMA_TIMEDOUT; 22177c478bd9Sstevel@tonic-gate break; 22187c478bd9Sstevel@tonic-gate case 0: /* interrupted */ 22190a701b1eSRobert Gordon DTRACE_PROBE(rpcib__i__clntsendwait__intr); 22200a701b1eSRobert Gordon 22217c478bd9Sstevel@tonic-gate wd->cv_sig = 0; /* no signal needed */ 22227c478bd9Sstevel@tonic-gate error = RDMA_INTR; 22237c478bd9Sstevel@tonic-gate break; 22247c478bd9Sstevel@tonic-gate default: /* got send completion */ 22257c478bd9Sstevel@tonic-gate break; 22267c478bd9Sstevel@tonic-gate } 22277c478bd9Sstevel@tonic-gate } 22287c478bd9Sstevel@tonic-gate } 22297c478bd9Sstevel@tonic-gate 22307c478bd9Sstevel@tonic-gate if (wd->status != (uint_t)SEND_WAIT) { 22317c478bd9Sstevel@tonic-gate /* got send completion */ 22327c478bd9Sstevel@tonic-gate if (wd->status != RDMA_SUCCESS) { 2233065714dcSSiddheshwar Mahesh switch (wd->status) { 2234065714dcSSiddheshwar Mahesh case RDMA_CONNLOST: 2235f837ee4aSSiddheshwar Mahesh error = RDMA_CONNLOST; 2236065714dcSSiddheshwar Mahesh break; 2237065714dcSSiddheshwar Mahesh default: 2238065714dcSSiddheshwar Mahesh error = RDMA_FAILED; 2239065714dcSSiddheshwar Mahesh break; 2240f837ee4aSSiddheshwar Mahesh } 22417c478bd9Sstevel@tonic-gate } 22427c478bd9Sstevel@tonic-gate for (i = 0; i < wd->nsbufs; i++) { 22437c478bd9Sstevel@tonic-gate rib_rbuf_free(qptoc(qp), SEND_BUFFER, 224411606941Sjwahlig (void *)(uintptr_t)wd->sbufaddr[i]); 22457c478bd9Sstevel@tonic-gate } 2246065714dcSSiddheshwar Mahesh 2247065714dcSSiddheshwar Mahesh rib_send_rele(qp); 2248065714dcSSiddheshwar Mahesh 22497c478bd9Sstevel@tonic-gate mutex_exit(&wd->sendwait_lock); 22507c478bd9Sstevel@tonic-gate (void) rib_free_sendwait(wd); 2251065714dcSSiddheshwar Mahesh 22527c478bd9Sstevel@tonic-gate } else { 22537c478bd9Sstevel@tonic-gate mutex_exit(&wd->sendwait_lock); 22547c478bd9Sstevel@tonic-gate } 22557c478bd9Sstevel@tonic-gate return (error); 22567c478bd9Sstevel@tonic-gate } 22577c478bd9Sstevel@tonic-gate 22587c478bd9Sstevel@tonic-gate static struct send_wid * 22597c478bd9Sstevel@tonic-gate rib_init_sendwait(uint32_t xid, int cv_sig, rib_qp_t *qp) 22607c478bd9Sstevel@tonic-gate { 22617c478bd9Sstevel@tonic-gate struct send_wid *wd; 22627c478bd9Sstevel@tonic-gate 22637c478bd9Sstevel@tonic-gate wd = kmem_zalloc(sizeof (struct send_wid), KM_SLEEP); 22647c478bd9Sstevel@tonic-gate wd->xid = xid; 22657c478bd9Sstevel@tonic-gate wd->cv_sig = cv_sig; 22667c478bd9Sstevel@tonic-gate wd->qp = qp; 22677c478bd9Sstevel@tonic-gate cv_init(&wd->wait_cv, NULL, CV_DEFAULT, NULL); 22687c478bd9Sstevel@tonic-gate mutex_init(&wd->sendwait_lock, NULL, MUTEX_DRIVER, NULL); 22697c478bd9Sstevel@tonic-gate wd->status = (uint_t)SEND_WAIT; 22707c478bd9Sstevel@tonic-gate 22717c478bd9Sstevel@tonic-gate return (wd); 22727c478bd9Sstevel@tonic-gate } 22737c478bd9Sstevel@tonic-gate 22747c478bd9Sstevel@tonic-gate static int 22757c478bd9Sstevel@tonic-gate rib_free_sendwait(struct send_wid *wdesc) 22767c478bd9Sstevel@tonic-gate { 22777c478bd9Sstevel@tonic-gate cv_destroy(&wdesc->wait_cv); 22787c478bd9Sstevel@tonic-gate mutex_destroy(&wdesc->sendwait_lock); 22797c478bd9Sstevel@tonic-gate kmem_free(wdesc, sizeof (*wdesc)); 22807c478bd9Sstevel@tonic-gate 22817c478bd9Sstevel@tonic-gate return (0); 22827c478bd9Sstevel@tonic-gate } 22837c478bd9Sstevel@tonic-gate 22847c478bd9Sstevel@tonic-gate static rdma_stat 22857c478bd9Sstevel@tonic-gate rib_rem_rep(rib_qp_t *qp, struct reply *rep) 22867c478bd9Sstevel@tonic-gate { 22877c478bd9Sstevel@tonic-gate mutex_enter(&qp->replylist_lock); 22887c478bd9Sstevel@tonic-gate if (rep != NULL) { 22897c478bd9Sstevel@tonic-gate (void) rib_remreply(qp, rep); 22907c478bd9Sstevel@tonic-gate mutex_exit(&qp->replylist_lock); 22917c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 22927c478bd9Sstevel@tonic-gate } 22937c478bd9Sstevel@tonic-gate mutex_exit(&qp->replylist_lock); 22947c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 22957c478bd9Sstevel@tonic-gate } 22967c478bd9Sstevel@tonic-gate 22977c478bd9Sstevel@tonic-gate /* 22987c478bd9Sstevel@tonic-gate * Send buffers are freed here only in case of error in posting 22997c478bd9Sstevel@tonic-gate * on QP. If the post succeeded, the send buffers are freed upon 23007c478bd9Sstevel@tonic-gate * send completion in rib_sendwait() or in the scq_handler. 23017c478bd9Sstevel@tonic-gate */ 23027c478bd9Sstevel@tonic-gate rdma_stat 23037c478bd9Sstevel@tonic-gate rib_send_and_wait(CONN *conn, struct clist *cl, uint32_t msgid, 23040a701b1eSRobert Gordon int send_sig, int cv_sig, caddr_t *swid) 23057c478bd9Sstevel@tonic-gate { 23067c478bd9Sstevel@tonic-gate struct send_wid *wdesc; 23077c478bd9Sstevel@tonic-gate struct clist *clp; 23087c478bd9Sstevel@tonic-gate ibt_status_t ibt_status = IBT_SUCCESS; 23097c478bd9Sstevel@tonic-gate rdma_stat ret = RDMA_SUCCESS; 23107c478bd9Sstevel@tonic-gate ibt_send_wr_t tx_wr; 23117c478bd9Sstevel@tonic-gate int i, nds; 23127c478bd9Sstevel@tonic-gate ibt_wr_ds_t sgl[DSEG_MAX]; 23137c478bd9Sstevel@tonic-gate uint_t total_msg_size; 23140a701b1eSRobert Gordon rib_qp_t *qp; 23150a701b1eSRobert Gordon 23160a701b1eSRobert Gordon qp = ctoqp(conn); 23177c478bd9Sstevel@tonic-gate 23187c478bd9Sstevel@tonic-gate ASSERT(cl != NULL); 23197c478bd9Sstevel@tonic-gate 23207c478bd9Sstevel@tonic-gate bzero(&tx_wr, sizeof (ibt_send_wr_t)); 23217c478bd9Sstevel@tonic-gate 23227c478bd9Sstevel@tonic-gate nds = 0; 23237c478bd9Sstevel@tonic-gate total_msg_size = 0; 23247c478bd9Sstevel@tonic-gate clp = cl; 23257c478bd9Sstevel@tonic-gate while (clp != NULL) { 23267c478bd9Sstevel@tonic-gate if (nds >= DSEG_MAX) { 23270a701b1eSRobert Gordon DTRACE_PROBE(rpcib__i__sendandwait_dsegmax_exceeded); 23287c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 23297c478bd9Sstevel@tonic-gate } 23300a701b1eSRobert Gordon sgl[nds].ds_va = clp->w.c_saddr; 23317c478bd9Sstevel@tonic-gate sgl[nds].ds_key = clp->c_smemhandle.mrc_lmr; /* lkey */ 23327c478bd9Sstevel@tonic-gate sgl[nds].ds_len = clp->c_len; 23337c478bd9Sstevel@tonic-gate total_msg_size += clp->c_len; 23347c478bd9Sstevel@tonic-gate clp = clp->c_next; 23357c478bd9Sstevel@tonic-gate nds++; 23367c478bd9Sstevel@tonic-gate } 23377c478bd9Sstevel@tonic-gate 23387c478bd9Sstevel@tonic-gate if (send_sig) { 23397c478bd9Sstevel@tonic-gate /* Set SEND_SIGNAL flag. */ 23407c478bd9Sstevel@tonic-gate tx_wr.wr_flags = IBT_WR_SEND_SIGNAL; 23417c478bd9Sstevel@tonic-gate wdesc = rib_init_sendwait(msgid, cv_sig, qp); 23420a701b1eSRobert Gordon *swid = (caddr_t)wdesc; 2343065714dcSSiddheshwar Mahesh tx_wr.wr_id = (ibt_wrid_t)(uintptr_t)wdesc; 2344065714dcSSiddheshwar Mahesh mutex_enter(&wdesc->sendwait_lock); 23457c478bd9Sstevel@tonic-gate wdesc->nsbufs = nds; 23467c478bd9Sstevel@tonic-gate for (i = 0; i < nds; i++) { 23477c478bd9Sstevel@tonic-gate wdesc->sbufaddr[i] = sgl[i].ds_va; 23487c478bd9Sstevel@tonic-gate } 2349065714dcSSiddheshwar Mahesh } else { 2350065714dcSSiddheshwar Mahesh tx_wr.wr_flags = IBT_WR_NO_FLAGS; 2351065714dcSSiddheshwar Mahesh *swid = NULL; 2352065714dcSSiddheshwar Mahesh tx_wr.wr_id = (ibt_wrid_t)RDMA_DUMMY_WRID; 2353065714dcSSiddheshwar Mahesh } 23547c478bd9Sstevel@tonic-gate 23557c478bd9Sstevel@tonic-gate tx_wr.wr_opcode = IBT_WRC_SEND; 23567c478bd9Sstevel@tonic-gate tx_wr.wr_trans = IBT_RC_SRV; 23577c478bd9Sstevel@tonic-gate tx_wr.wr_nds = nds; 23587c478bd9Sstevel@tonic-gate tx_wr.wr_sgl = sgl; 23597c478bd9Sstevel@tonic-gate 23607c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 23610a701b1eSRobert Gordon if (conn->c_state == C_CONNECTED) { 23627c478bd9Sstevel@tonic-gate ibt_status = ibt_post_send(qp->qp_hdl, &tx_wr, 1, NULL); 23637c478bd9Sstevel@tonic-gate } 23640a701b1eSRobert Gordon if (conn->c_state != C_CONNECTED || 23657c478bd9Sstevel@tonic-gate ibt_status != IBT_SUCCESS) { 23660a701b1eSRobert Gordon if (conn->c_state != C_DISCONN_PEND) 23670a701b1eSRobert Gordon conn->c_state = C_ERROR_CONN; 23687c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 2369065714dcSSiddheshwar Mahesh if (send_sig) { 23707c478bd9Sstevel@tonic-gate for (i = 0; i < nds; i++) { 23717c478bd9Sstevel@tonic-gate rib_rbuf_free(conn, SEND_BUFFER, 237211606941Sjwahlig (void *)(uintptr_t)wdesc->sbufaddr[i]); 23737c478bd9Sstevel@tonic-gate } 2374065714dcSSiddheshwar Mahesh mutex_exit(&wdesc->sendwait_lock); 23757c478bd9Sstevel@tonic-gate (void) rib_free_sendwait(wdesc); 2376065714dcSSiddheshwar Mahesh } 23770a701b1eSRobert Gordon return (RDMA_CONNLOST); 23787c478bd9Sstevel@tonic-gate } 2379065714dcSSiddheshwar Mahesh 23807c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 23817c478bd9Sstevel@tonic-gate 23827c478bd9Sstevel@tonic-gate if (send_sig) { 2383065714dcSSiddheshwar Mahesh rib_send_hold(qp); 2384065714dcSSiddheshwar Mahesh mutex_exit(&wdesc->sendwait_lock); 23857c478bd9Sstevel@tonic-gate if (cv_sig) { 23867c478bd9Sstevel@tonic-gate /* 23877c478bd9Sstevel@tonic-gate * cv_wait for send to complete. 23887c478bd9Sstevel@tonic-gate * We can fail due to a timeout or signal or 23897c478bd9Sstevel@tonic-gate * unsuccessful send. 23907c478bd9Sstevel@tonic-gate */ 23917c478bd9Sstevel@tonic-gate ret = rib_sendwait(qp, wdesc); 23920a701b1eSRobert Gordon 23937c478bd9Sstevel@tonic-gate return (ret); 23947c478bd9Sstevel@tonic-gate } 23957c478bd9Sstevel@tonic-gate } 23967c478bd9Sstevel@tonic-gate 23977c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 23987c478bd9Sstevel@tonic-gate } 23997c478bd9Sstevel@tonic-gate 24000a701b1eSRobert Gordon 24017c478bd9Sstevel@tonic-gate rdma_stat 24027c478bd9Sstevel@tonic-gate rib_send(CONN *conn, struct clist *cl, uint32_t msgid) 24037c478bd9Sstevel@tonic-gate { 24047c478bd9Sstevel@tonic-gate rdma_stat ret; 24050a701b1eSRobert Gordon caddr_t wd; 24067c478bd9Sstevel@tonic-gate 24077c478bd9Sstevel@tonic-gate /* send-wait & cv_signal */ 24080a701b1eSRobert Gordon ret = rib_send_and_wait(conn, cl, msgid, 1, 1, &wd); 24097c478bd9Sstevel@tonic-gate return (ret); 24107c478bd9Sstevel@tonic-gate } 24117c478bd9Sstevel@tonic-gate 24127c478bd9Sstevel@tonic-gate /* 2413065714dcSSiddheshwar Mahesh * Deprecated/obsolete interface not used currently 2414065714dcSSiddheshwar Mahesh * but earlier used for READ-READ protocol. 24157c478bd9Sstevel@tonic-gate * Send RPC reply and wait for RDMA_DONE. 24167c478bd9Sstevel@tonic-gate */ 24177c478bd9Sstevel@tonic-gate rdma_stat 24187c478bd9Sstevel@tonic-gate rib_send_resp(CONN *conn, struct clist *cl, uint32_t msgid) 24197c478bd9Sstevel@tonic-gate { 24207c478bd9Sstevel@tonic-gate rdma_stat ret = RDMA_SUCCESS; 24217c478bd9Sstevel@tonic-gate struct rdma_done_list *rd; 24227c478bd9Sstevel@tonic-gate clock_t timout, cv_wait_ret; 24230a701b1eSRobert Gordon caddr_t *wid = NULL; 24247c478bd9Sstevel@tonic-gate rib_qp_t *qp = ctoqp(conn); 24257c478bd9Sstevel@tonic-gate 24267c478bd9Sstevel@tonic-gate mutex_enter(&qp->rdlist_lock); 24277c478bd9Sstevel@tonic-gate rd = rdma_done_add(qp, msgid); 24287c478bd9Sstevel@tonic-gate 24297c478bd9Sstevel@tonic-gate /* No cv_signal (whether send-wait or no-send-wait) */ 24300a701b1eSRobert Gordon ret = rib_send_and_wait(conn, cl, msgid, 1, 0, wid); 24317c478bd9Sstevel@tonic-gate 24320a701b1eSRobert Gordon if (ret != RDMA_SUCCESS) { 24330a701b1eSRobert Gordon rdma_done_rm(qp, rd); 24340a701b1eSRobert Gordon } else { 24357c478bd9Sstevel@tonic-gate /* 24367c478bd9Sstevel@tonic-gate * Wait for RDMA_DONE from remote end 24377c478bd9Sstevel@tonic-gate */ 24380a701b1eSRobert Gordon timout = 24390a701b1eSRobert Gordon drv_usectohz(REPLY_WAIT_TIME * 1000000) + ddi_get_lbolt(); 24400a701b1eSRobert Gordon cv_wait_ret = cv_timedwait(&rd->rdma_done_cv, 24410a701b1eSRobert Gordon &qp->rdlist_lock, 24427c478bd9Sstevel@tonic-gate timout); 24430a701b1eSRobert Gordon 24447c478bd9Sstevel@tonic-gate rdma_done_rm(qp, rd); 24450a701b1eSRobert Gordon 24467c478bd9Sstevel@tonic-gate if (cv_wait_ret < 0) { 24477c478bd9Sstevel@tonic-gate ret = RDMA_TIMEDOUT; 24480a701b1eSRobert Gordon } 24497c478bd9Sstevel@tonic-gate } 24507c478bd9Sstevel@tonic-gate 24517c478bd9Sstevel@tonic-gate mutex_exit(&qp->rdlist_lock); 24527c478bd9Sstevel@tonic-gate return (ret); 24537c478bd9Sstevel@tonic-gate } 24547c478bd9Sstevel@tonic-gate 24557c478bd9Sstevel@tonic-gate static struct recv_wid * 24567c478bd9Sstevel@tonic-gate rib_create_wid(rib_qp_t *qp, ibt_wr_ds_t *sgl, uint32_t msgid) 24577c478bd9Sstevel@tonic-gate { 24587c478bd9Sstevel@tonic-gate struct recv_wid *rwid; 24597c478bd9Sstevel@tonic-gate 24607c478bd9Sstevel@tonic-gate rwid = kmem_zalloc(sizeof (struct recv_wid), KM_SLEEP); 24617c478bd9Sstevel@tonic-gate rwid->xid = msgid; 24627c478bd9Sstevel@tonic-gate rwid->addr = sgl->ds_va; 24637c478bd9Sstevel@tonic-gate rwid->qp = qp; 24647c478bd9Sstevel@tonic-gate 24657c478bd9Sstevel@tonic-gate return (rwid); 24667c478bd9Sstevel@tonic-gate } 24677c478bd9Sstevel@tonic-gate 24687c478bd9Sstevel@tonic-gate static void 24697c478bd9Sstevel@tonic-gate rib_free_wid(struct recv_wid *rwid) 24707c478bd9Sstevel@tonic-gate { 24717c478bd9Sstevel@tonic-gate kmem_free(rwid, sizeof (struct recv_wid)); 24727c478bd9Sstevel@tonic-gate } 24737c478bd9Sstevel@tonic-gate 24747c478bd9Sstevel@tonic-gate rdma_stat 24757c478bd9Sstevel@tonic-gate rib_clnt_post(CONN* conn, struct clist *cl, uint32_t msgid) 24767c478bd9Sstevel@tonic-gate { 24777c478bd9Sstevel@tonic-gate rib_qp_t *qp = ctoqp(conn); 24787c478bd9Sstevel@tonic-gate struct clist *clp = cl; 24797c478bd9Sstevel@tonic-gate struct reply *rep; 24807c478bd9Sstevel@tonic-gate struct recv_wid *rwid; 24817c478bd9Sstevel@tonic-gate int nds; 24827c478bd9Sstevel@tonic-gate ibt_wr_ds_t sgl[DSEG_MAX]; 24837c478bd9Sstevel@tonic-gate ibt_recv_wr_t recv_wr; 24847c478bd9Sstevel@tonic-gate rdma_stat ret; 24857c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 24867c478bd9Sstevel@tonic-gate 24877c478bd9Sstevel@tonic-gate /* 24887c478bd9Sstevel@tonic-gate * rdma_clnt_postrecv uses RECV_BUFFER. 24897c478bd9Sstevel@tonic-gate */ 24907c478bd9Sstevel@tonic-gate 24917c478bd9Sstevel@tonic-gate nds = 0; 24927c478bd9Sstevel@tonic-gate while (cl != NULL) { 24937c478bd9Sstevel@tonic-gate if (nds >= DSEG_MAX) { 24947c478bd9Sstevel@tonic-gate ret = RDMA_FAILED; 24957c478bd9Sstevel@tonic-gate goto done; 24967c478bd9Sstevel@tonic-gate } 24970a701b1eSRobert Gordon sgl[nds].ds_va = cl->w.c_saddr; 24987c478bd9Sstevel@tonic-gate sgl[nds].ds_key = cl->c_smemhandle.mrc_lmr; /* lkey */ 24997c478bd9Sstevel@tonic-gate sgl[nds].ds_len = cl->c_len; 25007c478bd9Sstevel@tonic-gate cl = cl->c_next; 25017c478bd9Sstevel@tonic-gate nds++; 25027c478bd9Sstevel@tonic-gate } 25037c478bd9Sstevel@tonic-gate 25047c478bd9Sstevel@tonic-gate if (nds != 1) { 25057c478bd9Sstevel@tonic-gate ret = RDMA_FAILED; 25067c478bd9Sstevel@tonic-gate goto done; 25077c478bd9Sstevel@tonic-gate } 25080a701b1eSRobert Gordon 25097c478bd9Sstevel@tonic-gate bzero(&recv_wr, sizeof (ibt_recv_wr_t)); 25107c478bd9Sstevel@tonic-gate recv_wr.wr_nds = nds; 25117c478bd9Sstevel@tonic-gate recv_wr.wr_sgl = sgl; 25127c478bd9Sstevel@tonic-gate 25137c478bd9Sstevel@tonic-gate rwid = rib_create_wid(qp, &sgl[0], msgid); 25147c478bd9Sstevel@tonic-gate if (rwid) { 251511606941Sjwahlig recv_wr.wr_id = (ibt_wrid_t)(uintptr_t)rwid; 25167c478bd9Sstevel@tonic-gate } else { 25177c478bd9Sstevel@tonic-gate ret = RDMA_NORESOURCE; 25187c478bd9Sstevel@tonic-gate goto done; 25197c478bd9Sstevel@tonic-gate } 25207c478bd9Sstevel@tonic-gate rep = rib_addreplylist(qp, msgid); 25217c478bd9Sstevel@tonic-gate if (!rep) { 25227c478bd9Sstevel@tonic-gate rib_free_wid(rwid); 25237c478bd9Sstevel@tonic-gate ret = RDMA_NORESOURCE; 25247c478bd9Sstevel@tonic-gate goto done; 25257c478bd9Sstevel@tonic-gate } 25267c478bd9Sstevel@tonic-gate 25277c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 25280a701b1eSRobert Gordon 25290a701b1eSRobert Gordon if (conn->c_state == C_CONNECTED) { 25307c478bd9Sstevel@tonic-gate ibt_status = ibt_post_recv(qp->qp_hdl, &recv_wr, 1, NULL); 25317c478bd9Sstevel@tonic-gate } 25320a701b1eSRobert Gordon 25330a701b1eSRobert Gordon if (conn->c_state != C_CONNECTED || 25347c478bd9Sstevel@tonic-gate ibt_status != IBT_SUCCESS) { 25350a701b1eSRobert Gordon if (conn->c_state != C_DISCONN_PEND) 25360a701b1eSRobert Gordon conn->c_state = C_ERROR_CONN; 25377c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 25387c478bd9Sstevel@tonic-gate rib_free_wid(rwid); 25397c478bd9Sstevel@tonic-gate (void) rib_rem_rep(qp, rep); 25400a701b1eSRobert Gordon ret = RDMA_CONNLOST; 25417c478bd9Sstevel@tonic-gate goto done; 25427c478bd9Sstevel@tonic-gate } 25437c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 25447c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 25457c478bd9Sstevel@tonic-gate 25467c478bd9Sstevel@tonic-gate done: 25477c478bd9Sstevel@tonic-gate while (clp != NULL) { 25480a701b1eSRobert Gordon rib_rbuf_free(conn, RECV_BUFFER, 25490a701b1eSRobert Gordon (void *)(uintptr_t)clp->w.c_saddr3); 25507c478bd9Sstevel@tonic-gate clp = clp->c_next; 25517c478bd9Sstevel@tonic-gate } 25527c478bd9Sstevel@tonic-gate return (ret); 25537c478bd9Sstevel@tonic-gate } 25547c478bd9Sstevel@tonic-gate 25557c478bd9Sstevel@tonic-gate rdma_stat 25567c478bd9Sstevel@tonic-gate rib_svc_post(CONN* conn, struct clist *cl) 25577c478bd9Sstevel@tonic-gate { 25587c478bd9Sstevel@tonic-gate rib_qp_t *qp = ctoqp(conn); 25597c478bd9Sstevel@tonic-gate struct svc_recv *s_recvp; 25607c478bd9Sstevel@tonic-gate int nds; 25617c478bd9Sstevel@tonic-gate ibt_wr_ds_t sgl[DSEG_MAX]; 25627c478bd9Sstevel@tonic-gate ibt_recv_wr_t recv_wr; 25637c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 25647c478bd9Sstevel@tonic-gate 25657c478bd9Sstevel@tonic-gate nds = 0; 25667c478bd9Sstevel@tonic-gate while (cl != NULL) { 25677c478bd9Sstevel@tonic-gate if (nds >= DSEG_MAX) { 25687c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 25697c478bd9Sstevel@tonic-gate } 25700a701b1eSRobert Gordon sgl[nds].ds_va = cl->w.c_saddr; 25717c478bd9Sstevel@tonic-gate sgl[nds].ds_key = cl->c_smemhandle.mrc_lmr; /* lkey */ 25727c478bd9Sstevel@tonic-gate sgl[nds].ds_len = cl->c_len; 25737c478bd9Sstevel@tonic-gate cl = cl->c_next; 25747c478bd9Sstevel@tonic-gate nds++; 25757c478bd9Sstevel@tonic-gate } 25767c478bd9Sstevel@tonic-gate 25777c478bd9Sstevel@tonic-gate if (nds != 1) { 25780a701b1eSRobert Gordon rib_rbuf_free(conn, RECV_BUFFER, 25790a701b1eSRobert Gordon (caddr_t)(uintptr_t)sgl[0].ds_va); 25800a701b1eSRobert Gordon 25817c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 25827c478bd9Sstevel@tonic-gate } 25830a701b1eSRobert Gordon 25847c478bd9Sstevel@tonic-gate bzero(&recv_wr, sizeof (ibt_recv_wr_t)); 25857c478bd9Sstevel@tonic-gate recv_wr.wr_nds = nds; 25867c478bd9Sstevel@tonic-gate recv_wr.wr_sgl = sgl; 25877c478bd9Sstevel@tonic-gate 25887c478bd9Sstevel@tonic-gate s_recvp = rib_init_svc_recv(qp, &sgl[0]); 258911606941Sjwahlig /* Use s_recvp's addr as wr id */ 259011606941Sjwahlig recv_wr.wr_id = (ibt_wrid_t)(uintptr_t)s_recvp; 25917c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 25920a701b1eSRobert Gordon if (conn->c_state == C_CONNECTED) { 25937c478bd9Sstevel@tonic-gate ibt_status = ibt_post_recv(qp->qp_hdl, &recv_wr, 1, NULL); 25947c478bd9Sstevel@tonic-gate } 25950a701b1eSRobert Gordon if (conn->c_state != C_CONNECTED || 25967c478bd9Sstevel@tonic-gate ibt_status != IBT_SUCCESS) { 25970a701b1eSRobert Gordon if (conn->c_state != C_DISCONN_PEND) 25980a701b1eSRobert Gordon conn->c_state = C_ERROR_CONN; 25997c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 260011606941Sjwahlig rib_rbuf_free(conn, RECV_BUFFER, 260111606941Sjwahlig (caddr_t)(uintptr_t)sgl[0].ds_va); 26027c478bd9Sstevel@tonic-gate (void) rib_free_svc_recv(s_recvp); 26030a701b1eSRobert Gordon 26040a701b1eSRobert Gordon return (RDMA_CONNLOST); 26057c478bd9Sstevel@tonic-gate } 26067c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 26077c478bd9Sstevel@tonic-gate 26087c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 26097c478bd9Sstevel@tonic-gate } 26107c478bd9Sstevel@tonic-gate 26117c478bd9Sstevel@tonic-gate /* Client */ 26127c478bd9Sstevel@tonic-gate rdma_stat 26137c478bd9Sstevel@tonic-gate rib_post_resp(CONN* conn, struct clist *cl, uint32_t msgid) 26147c478bd9Sstevel@tonic-gate { 26157c478bd9Sstevel@tonic-gate 26167c478bd9Sstevel@tonic-gate return (rib_clnt_post(conn, cl, msgid)); 26177c478bd9Sstevel@tonic-gate } 26187c478bd9Sstevel@tonic-gate 26190a701b1eSRobert Gordon /* Client */ 26200a701b1eSRobert Gordon rdma_stat 26210a701b1eSRobert Gordon rib_post_resp_remove(CONN* conn, uint32_t msgid) 26220a701b1eSRobert Gordon { 26230a701b1eSRobert Gordon rib_qp_t *qp = ctoqp(conn); 26240a701b1eSRobert Gordon struct reply *rep; 26250a701b1eSRobert Gordon 26260a701b1eSRobert Gordon mutex_enter(&qp->replylist_lock); 26270a701b1eSRobert Gordon for (rep = qp->replylist; rep != NULL; rep = rep->next) { 26280a701b1eSRobert Gordon if (rep->xid == msgid) { 26290a701b1eSRobert Gordon if (rep->vaddr_cq) { 26300a701b1eSRobert Gordon rib_rbuf_free(conn, RECV_BUFFER, 26310a701b1eSRobert Gordon (caddr_t)(uintptr_t)rep->vaddr_cq); 26320a701b1eSRobert Gordon } 26330a701b1eSRobert Gordon (void) rib_remreply(qp, rep); 26340a701b1eSRobert Gordon break; 26350a701b1eSRobert Gordon } 26360a701b1eSRobert Gordon } 26370a701b1eSRobert Gordon mutex_exit(&qp->replylist_lock); 26380a701b1eSRobert Gordon 26390a701b1eSRobert Gordon return (RDMA_SUCCESS); 26400a701b1eSRobert Gordon } 26410a701b1eSRobert Gordon 26427c478bd9Sstevel@tonic-gate /* Server */ 26437c478bd9Sstevel@tonic-gate rdma_stat 26447c478bd9Sstevel@tonic-gate rib_post_recv(CONN *conn, struct clist *cl) 26457c478bd9Sstevel@tonic-gate { 26467c478bd9Sstevel@tonic-gate rib_qp_t *qp = ctoqp(conn); 26477c478bd9Sstevel@tonic-gate 26487c478bd9Sstevel@tonic-gate if (rib_svc_post(conn, cl) == RDMA_SUCCESS) { 26497c478bd9Sstevel@tonic-gate mutex_enter(&qp->posted_rbufs_lock); 26507c478bd9Sstevel@tonic-gate qp->n_posted_rbufs++; 26517c478bd9Sstevel@tonic-gate mutex_exit(&qp->posted_rbufs_lock); 26527c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 26537c478bd9Sstevel@tonic-gate } 26547c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 26557c478bd9Sstevel@tonic-gate } 26567c478bd9Sstevel@tonic-gate 26577c478bd9Sstevel@tonic-gate /* 26587c478bd9Sstevel@tonic-gate * Client side only interface to "recv" the rpc reply buf 26597c478bd9Sstevel@tonic-gate * posted earlier by rib_post_resp(conn, cl, msgid). 26607c478bd9Sstevel@tonic-gate */ 26617c478bd9Sstevel@tonic-gate rdma_stat 26627c478bd9Sstevel@tonic-gate rib_recv(CONN *conn, struct clist **clp, uint32_t msgid) 26637c478bd9Sstevel@tonic-gate { 26647c478bd9Sstevel@tonic-gate struct reply *rep = NULL; 26657c478bd9Sstevel@tonic-gate clock_t timout, cv_wait_ret; 26667c478bd9Sstevel@tonic-gate rdma_stat ret = RDMA_SUCCESS; 26677c478bd9Sstevel@tonic-gate rib_qp_t *qp = ctoqp(conn); 26687c478bd9Sstevel@tonic-gate 26697c478bd9Sstevel@tonic-gate /* 26707c478bd9Sstevel@tonic-gate * Find the reply structure for this msgid 26717c478bd9Sstevel@tonic-gate */ 26727c478bd9Sstevel@tonic-gate mutex_enter(&qp->replylist_lock); 26737c478bd9Sstevel@tonic-gate 26747c478bd9Sstevel@tonic-gate for (rep = qp->replylist; rep != NULL; rep = rep->next) { 26757c478bd9Sstevel@tonic-gate if (rep->xid == msgid) 26767c478bd9Sstevel@tonic-gate break; 26777c478bd9Sstevel@tonic-gate } 26780a701b1eSRobert Gordon 26797c478bd9Sstevel@tonic-gate if (rep != NULL) { 26807c478bd9Sstevel@tonic-gate /* 26817c478bd9Sstevel@tonic-gate * If message not yet received, wait. 26827c478bd9Sstevel@tonic-gate */ 26837c478bd9Sstevel@tonic-gate if (rep->status == (uint_t)REPLY_WAIT) { 26847c478bd9Sstevel@tonic-gate timout = ddi_get_lbolt() + 26857c478bd9Sstevel@tonic-gate drv_usectohz(REPLY_WAIT_TIME * 1000000); 26860a701b1eSRobert Gordon 26877c478bd9Sstevel@tonic-gate while ((cv_wait_ret = cv_timedwait_sig(&rep->wait_cv, 26887c478bd9Sstevel@tonic-gate &qp->replylist_lock, timout)) > 0 && 26890a701b1eSRobert Gordon rep->status == (uint_t)REPLY_WAIT) 26900a701b1eSRobert Gordon ; 26917c478bd9Sstevel@tonic-gate 26927c478bd9Sstevel@tonic-gate switch (cv_wait_ret) { 26937c478bd9Sstevel@tonic-gate case -1: /* timeout */ 26947c478bd9Sstevel@tonic-gate ret = RDMA_TIMEDOUT; 26957c478bd9Sstevel@tonic-gate break; 26967c478bd9Sstevel@tonic-gate case 0: 26977c478bd9Sstevel@tonic-gate ret = RDMA_INTR; 26987c478bd9Sstevel@tonic-gate break; 26997c478bd9Sstevel@tonic-gate default: 27007c478bd9Sstevel@tonic-gate break; 27017c478bd9Sstevel@tonic-gate } 27027c478bd9Sstevel@tonic-gate } 27037c478bd9Sstevel@tonic-gate 27047c478bd9Sstevel@tonic-gate if (rep->status == RDMA_SUCCESS) { 27057c478bd9Sstevel@tonic-gate struct clist *cl = NULL; 27067c478bd9Sstevel@tonic-gate 27077c478bd9Sstevel@tonic-gate /* 27087c478bd9Sstevel@tonic-gate * Got message successfully 27097c478bd9Sstevel@tonic-gate */ 27107c478bd9Sstevel@tonic-gate clist_add(&cl, 0, rep->bytes_xfer, NULL, 271111606941Sjwahlig (caddr_t)(uintptr_t)rep->vaddr_cq, NULL, NULL); 27127c478bd9Sstevel@tonic-gate *clp = cl; 27137c478bd9Sstevel@tonic-gate } else { 27147c478bd9Sstevel@tonic-gate if (rep->status != (uint_t)REPLY_WAIT) { 27157c478bd9Sstevel@tonic-gate /* 27167c478bd9Sstevel@tonic-gate * Got error in reply message. Free 27177c478bd9Sstevel@tonic-gate * recv buffer here. 27187c478bd9Sstevel@tonic-gate */ 27197c478bd9Sstevel@tonic-gate ret = rep->status; 27207c478bd9Sstevel@tonic-gate rib_rbuf_free(conn, RECV_BUFFER, 272111606941Sjwahlig (caddr_t)(uintptr_t)rep->vaddr_cq); 27227c478bd9Sstevel@tonic-gate } 27237c478bd9Sstevel@tonic-gate } 27247c478bd9Sstevel@tonic-gate (void) rib_remreply(qp, rep); 27257c478bd9Sstevel@tonic-gate } else { 27267c478bd9Sstevel@tonic-gate /* 27277c478bd9Sstevel@tonic-gate * No matching reply structure found for given msgid on the 27287c478bd9Sstevel@tonic-gate * reply wait list. 27297c478bd9Sstevel@tonic-gate */ 27307c478bd9Sstevel@tonic-gate ret = RDMA_INVAL; 27310a701b1eSRobert Gordon DTRACE_PROBE(rpcib__i__nomatchxid2); 27327c478bd9Sstevel@tonic-gate } 27337c478bd9Sstevel@tonic-gate 27347c478bd9Sstevel@tonic-gate /* 27357c478bd9Sstevel@tonic-gate * Done. 27367c478bd9Sstevel@tonic-gate */ 27377c478bd9Sstevel@tonic-gate mutex_exit(&qp->replylist_lock); 27387c478bd9Sstevel@tonic-gate return (ret); 27397c478bd9Sstevel@tonic-gate } 27407c478bd9Sstevel@tonic-gate 27417c478bd9Sstevel@tonic-gate /* 27427c478bd9Sstevel@tonic-gate * RDMA write a buffer to the remote address. 27437c478bd9Sstevel@tonic-gate */ 27447c478bd9Sstevel@tonic-gate rdma_stat 27457c478bd9Sstevel@tonic-gate rib_write(CONN *conn, struct clist *cl, int wait) 27467c478bd9Sstevel@tonic-gate { 27477c478bd9Sstevel@tonic-gate ibt_send_wr_t tx_wr; 27487c478bd9Sstevel@tonic-gate int cv_sig; 27497c478bd9Sstevel@tonic-gate ibt_wr_ds_t sgl[DSEG_MAX]; 27507c478bd9Sstevel@tonic-gate struct send_wid *wdesc; 27517c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 27527c478bd9Sstevel@tonic-gate rdma_stat ret = RDMA_SUCCESS; 27537c478bd9Sstevel@tonic-gate rib_qp_t *qp = ctoqp(conn); 27540a701b1eSRobert Gordon uint64_t n_writes = 0; 27557c478bd9Sstevel@tonic-gate 27567c478bd9Sstevel@tonic-gate if (cl == NULL) { 27577c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 27587c478bd9Sstevel@tonic-gate } 27597c478bd9Sstevel@tonic-gate 27600a701b1eSRobert Gordon while ((cl != NULL)) { 27610a701b1eSRobert Gordon if (cl->c_len > 0) { 27627c478bd9Sstevel@tonic-gate bzero(&tx_wr, sizeof (ibt_send_wr_t)); 27630a701b1eSRobert Gordon tx_wr.wr.rc.rcwr.rdma.rdma_raddr = cl->u.c_daddr; 27640a701b1eSRobert Gordon tx_wr.wr.rc.rcwr.rdma.rdma_rkey = 27650a701b1eSRobert Gordon cl->c_dmemhandle.mrc_rmr; /* rkey */ 27660a701b1eSRobert Gordon sgl[0].ds_va = cl->w.c_saddr; 27670a701b1eSRobert Gordon sgl[0].ds_key = cl->c_smemhandle.mrc_lmr; /* lkey */ 27680a701b1eSRobert Gordon sgl[0].ds_len = cl->c_len; 27697c478bd9Sstevel@tonic-gate 27707c478bd9Sstevel@tonic-gate if (wait) { 27717c478bd9Sstevel@tonic-gate cv_sig = 1; 27727c478bd9Sstevel@tonic-gate } else { 27730a701b1eSRobert Gordon if (n_writes > max_unsignaled_rws) { 27740a701b1eSRobert Gordon n_writes = 0; 27750a701b1eSRobert Gordon cv_sig = 1; 27760a701b1eSRobert Gordon } else { 27777c478bd9Sstevel@tonic-gate cv_sig = 0; 27787c478bd9Sstevel@tonic-gate } 27790a701b1eSRobert Gordon } 27807c478bd9Sstevel@tonic-gate 2781065714dcSSiddheshwar Mahesh if (cv_sig) { 2782065714dcSSiddheshwar Mahesh tx_wr.wr_flags = IBT_WR_SEND_SIGNAL; 27837c478bd9Sstevel@tonic-gate wdesc = rib_init_sendwait(0, cv_sig, qp); 278411606941Sjwahlig tx_wr.wr_id = (ibt_wrid_t)(uintptr_t)wdesc; 2785065714dcSSiddheshwar Mahesh mutex_enter(&wdesc->sendwait_lock); 2786065714dcSSiddheshwar Mahesh } else { 2787065714dcSSiddheshwar Mahesh tx_wr.wr_flags = IBT_WR_NO_FLAGS; 2788065714dcSSiddheshwar Mahesh tx_wr.wr_id = (ibt_wrid_t)RDMA_DUMMY_WRID; 2789065714dcSSiddheshwar Mahesh } 27907c478bd9Sstevel@tonic-gate tx_wr.wr_opcode = IBT_WRC_RDMAW; 27917c478bd9Sstevel@tonic-gate tx_wr.wr_trans = IBT_RC_SRV; 27920a701b1eSRobert Gordon tx_wr.wr_nds = 1; 27937c478bd9Sstevel@tonic-gate tx_wr.wr_sgl = sgl; 27947c478bd9Sstevel@tonic-gate 27957c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 27960a701b1eSRobert Gordon if (conn->c_state == C_CONNECTED) { 27970a701b1eSRobert Gordon ibt_status = 27980a701b1eSRobert Gordon ibt_post_send(qp->qp_hdl, &tx_wr, 1, NULL); 27997c478bd9Sstevel@tonic-gate } 28000a701b1eSRobert Gordon if (conn->c_state != C_CONNECTED || 28017c478bd9Sstevel@tonic-gate ibt_status != IBT_SUCCESS) { 28020a701b1eSRobert Gordon if (conn->c_state != C_DISCONN_PEND) 28030a701b1eSRobert Gordon conn->c_state = C_ERROR_CONN; 28047c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 2805065714dcSSiddheshwar Mahesh if (cv_sig) { 2806065714dcSSiddheshwar Mahesh mutex_exit(&wdesc->sendwait_lock); 28077c478bd9Sstevel@tonic-gate (void) rib_free_sendwait(wdesc); 2808065714dcSSiddheshwar Mahesh } 28090a701b1eSRobert Gordon return (RDMA_CONNLOST); 28107c478bd9Sstevel@tonic-gate } 2811065714dcSSiddheshwar Mahesh 28127c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 28137c478bd9Sstevel@tonic-gate 28147c478bd9Sstevel@tonic-gate /* 28157c478bd9Sstevel@tonic-gate * Wait for send to complete 28167c478bd9Sstevel@tonic-gate */ 2817065714dcSSiddheshwar Mahesh if (cv_sig) { 2818065714dcSSiddheshwar Mahesh 2819065714dcSSiddheshwar Mahesh rib_send_hold(qp); 28200a701b1eSRobert Gordon mutex_exit(&wdesc->sendwait_lock); 2821065714dcSSiddheshwar Mahesh 2822065714dcSSiddheshwar Mahesh ret = rib_sendwait(qp, wdesc); 2823065714dcSSiddheshwar Mahesh if (ret != 0) 2824065714dcSSiddheshwar Mahesh return (ret); 28250a701b1eSRobert Gordon } 28260a701b1eSRobert Gordon n_writes ++; 28270a701b1eSRobert Gordon } 28280a701b1eSRobert Gordon cl = cl->c_next; 28297c478bd9Sstevel@tonic-gate } 28307c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 28317c478bd9Sstevel@tonic-gate } 28327c478bd9Sstevel@tonic-gate 28337c478bd9Sstevel@tonic-gate /* 28347c478bd9Sstevel@tonic-gate * RDMA Read a buffer from the remote address. 28357c478bd9Sstevel@tonic-gate */ 28367c478bd9Sstevel@tonic-gate rdma_stat 28377c478bd9Sstevel@tonic-gate rib_read(CONN *conn, struct clist *cl, int wait) 28387c478bd9Sstevel@tonic-gate { 28397c478bd9Sstevel@tonic-gate ibt_send_wr_t rx_wr; 2840065714dcSSiddheshwar Mahesh int cv_sig = 0; 28410a701b1eSRobert Gordon ibt_wr_ds_t sgl; 28427c478bd9Sstevel@tonic-gate struct send_wid *wdesc; 28437c478bd9Sstevel@tonic-gate ibt_status_t ibt_status = IBT_SUCCESS; 28447c478bd9Sstevel@tonic-gate rdma_stat ret = RDMA_SUCCESS; 28457c478bd9Sstevel@tonic-gate rib_qp_t *qp = ctoqp(conn); 28467c478bd9Sstevel@tonic-gate 28477c478bd9Sstevel@tonic-gate if (cl == NULL) { 28487c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 28497c478bd9Sstevel@tonic-gate } 28507c478bd9Sstevel@tonic-gate 28510a701b1eSRobert Gordon while (cl != NULL) { 28527c478bd9Sstevel@tonic-gate bzero(&rx_wr, sizeof (ibt_send_wr_t)); 28537c478bd9Sstevel@tonic-gate /* 28547c478bd9Sstevel@tonic-gate * Remote address is at the head chunk item in list. 28557c478bd9Sstevel@tonic-gate */ 28560a701b1eSRobert Gordon rx_wr.wr.rc.rcwr.rdma.rdma_raddr = cl->w.c_saddr; 28570a701b1eSRobert Gordon rx_wr.wr.rc.rcwr.rdma.rdma_rkey = cl->c_smemhandle.mrc_rmr; 28587c478bd9Sstevel@tonic-gate 28590a701b1eSRobert Gordon sgl.ds_va = cl->u.c_daddr; 28600a701b1eSRobert Gordon sgl.ds_key = cl->c_dmemhandle.mrc_lmr; /* lkey */ 28610a701b1eSRobert Gordon sgl.ds_len = cl->c_len; 28627c478bd9Sstevel@tonic-gate 2863065714dcSSiddheshwar Mahesh /* 2864065714dcSSiddheshwar Mahesh * If there are multiple chunks to be read, and 2865065714dcSSiddheshwar Mahesh * wait is set, ask for signal only for the last chunk 2866065714dcSSiddheshwar Mahesh * and wait only on the last chunk. The completion of 2867065714dcSSiddheshwar Mahesh * RDMA_READ on last chunk ensures that reads on all 2868065714dcSSiddheshwar Mahesh * previous chunks are also completed. 2869065714dcSSiddheshwar Mahesh */ 2870065714dcSSiddheshwar Mahesh if (wait && (cl->c_next == NULL)) { 28717c478bd9Sstevel@tonic-gate cv_sig = 1; 2872065714dcSSiddheshwar Mahesh wdesc = rib_init_sendwait(0, cv_sig, qp); 2873065714dcSSiddheshwar Mahesh rx_wr.wr_flags = IBT_WR_SEND_SIGNAL; 2874065714dcSSiddheshwar Mahesh rx_wr.wr_id = (ibt_wrid_t)(uintptr_t)wdesc; 2875065714dcSSiddheshwar Mahesh mutex_enter(&wdesc->sendwait_lock); 28767c478bd9Sstevel@tonic-gate } else { 28777c478bd9Sstevel@tonic-gate rx_wr.wr_flags = IBT_WR_NO_FLAGS; 2878065714dcSSiddheshwar Mahesh rx_wr.wr_id = (ibt_wrid_t)RDMA_DUMMY_WRID; 28797c478bd9Sstevel@tonic-gate } 28807c478bd9Sstevel@tonic-gate rx_wr.wr_opcode = IBT_WRC_RDMAR; 28817c478bd9Sstevel@tonic-gate rx_wr.wr_trans = IBT_RC_SRV; 28820a701b1eSRobert Gordon rx_wr.wr_nds = 1; 28830a701b1eSRobert Gordon rx_wr.wr_sgl = &sgl; 28847c478bd9Sstevel@tonic-gate 28857c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 28860a701b1eSRobert Gordon if (conn->c_state == C_CONNECTED) { 28877c478bd9Sstevel@tonic-gate ibt_status = ibt_post_send(qp->qp_hdl, &rx_wr, 1, NULL); 28887c478bd9Sstevel@tonic-gate } 28890a701b1eSRobert Gordon if (conn->c_state != C_CONNECTED || 28907c478bd9Sstevel@tonic-gate ibt_status != IBT_SUCCESS) { 28910a701b1eSRobert Gordon if (conn->c_state != C_DISCONN_PEND) 28920a701b1eSRobert Gordon conn->c_state = C_ERROR_CONN; 28937c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 2894065714dcSSiddheshwar Mahesh if (wait && (cl->c_next == NULL)) { 2895065714dcSSiddheshwar Mahesh mutex_exit(&wdesc->sendwait_lock); 28967c478bd9Sstevel@tonic-gate (void) rib_free_sendwait(wdesc); 2897065714dcSSiddheshwar Mahesh } 28980a701b1eSRobert Gordon return (RDMA_CONNLOST); 28997c478bd9Sstevel@tonic-gate } 2900065714dcSSiddheshwar Mahesh 29017c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 29027c478bd9Sstevel@tonic-gate 29037c478bd9Sstevel@tonic-gate /* 29040a701b1eSRobert Gordon * Wait for send to complete if this is the 29050a701b1eSRobert Gordon * last item in the list. 29067c478bd9Sstevel@tonic-gate */ 29070a701b1eSRobert Gordon if (wait && cl->c_next == NULL) { 2908065714dcSSiddheshwar Mahesh rib_send_hold(qp); 29090a701b1eSRobert Gordon mutex_exit(&wdesc->sendwait_lock); 2910065714dcSSiddheshwar Mahesh 2911065714dcSSiddheshwar Mahesh ret = rib_sendwait(qp, wdesc); 2912065714dcSSiddheshwar Mahesh 2913065714dcSSiddheshwar Mahesh if (ret != 0) 2914065714dcSSiddheshwar Mahesh return (ret); 29150a701b1eSRobert Gordon } 29160a701b1eSRobert Gordon cl = cl->c_next; 29170a701b1eSRobert Gordon } 29187c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 29197c478bd9Sstevel@tonic-gate } 29207c478bd9Sstevel@tonic-gate 29217c478bd9Sstevel@tonic-gate /* 29227c478bd9Sstevel@tonic-gate * rib_srv_cm_handler() 29237c478bd9Sstevel@tonic-gate * Connection Manager callback to handle RC connection requests. 29247c478bd9Sstevel@tonic-gate */ 29257c478bd9Sstevel@tonic-gate /* ARGSUSED */ 29267c478bd9Sstevel@tonic-gate static ibt_cm_status_t 29277c478bd9Sstevel@tonic-gate rib_srv_cm_handler(void *any, ibt_cm_event_t *event, 29287c478bd9Sstevel@tonic-gate ibt_cm_return_args_t *ret_args, void *priv_data, 29297c478bd9Sstevel@tonic-gate ibt_priv_data_len_t len) 29307c478bd9Sstevel@tonic-gate { 29317c478bd9Sstevel@tonic-gate queue_t *q; 29327c478bd9Sstevel@tonic-gate rib_qp_t *qp; 29337c478bd9Sstevel@tonic-gate rib_hca_t *hca; 29347c478bd9Sstevel@tonic-gate rdma_stat status = RDMA_SUCCESS; 29357c478bd9Sstevel@tonic-gate int i; 29367c478bd9Sstevel@tonic-gate struct clist cl; 29370a701b1eSRobert Gordon rdma_buf_t rdbuf = {0}; 29387c478bd9Sstevel@tonic-gate void *buf = NULL; 29397c478bd9Sstevel@tonic-gate CONN *conn; 29400a701b1eSRobert Gordon ibt_ip_cm_info_t ipinfo; 29410a701b1eSRobert Gordon struct sockaddr_in *s; 29420a701b1eSRobert Gordon struct sockaddr_in6 *s6; 29430a701b1eSRobert Gordon int sin_size = sizeof (struct sockaddr_in); 29440a701b1eSRobert Gordon int in_size = sizeof (struct in_addr); 29450a701b1eSRobert Gordon int sin6_size = sizeof (struct sockaddr_in6); 29467c478bd9Sstevel@tonic-gate 29477c478bd9Sstevel@tonic-gate ASSERT(any != NULL); 29487c478bd9Sstevel@tonic-gate ASSERT(event != NULL); 29497c478bd9Sstevel@tonic-gate 29507f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca = (rib_hca_t *)any; 29517c478bd9Sstevel@tonic-gate 29527c478bd9Sstevel@tonic-gate /* got a connection request */ 29537c478bd9Sstevel@tonic-gate switch (event->cm_type) { 29547c478bd9Sstevel@tonic-gate case IBT_CM_EVENT_REQ_RCV: 29557c478bd9Sstevel@tonic-gate /* 29567c478bd9Sstevel@tonic-gate * If the plugin is in the NO_ACCEPT state, bail out. 29577c478bd9Sstevel@tonic-gate */ 29587c478bd9Sstevel@tonic-gate mutex_enter(&plugin_state_lock); 29597c478bd9Sstevel@tonic-gate if (plugin_state == NO_ACCEPT) { 29607c478bd9Sstevel@tonic-gate mutex_exit(&plugin_state_lock); 29617c478bd9Sstevel@tonic-gate return (IBT_CM_REJECT); 29627c478bd9Sstevel@tonic-gate } 29637c478bd9Sstevel@tonic-gate mutex_exit(&plugin_state_lock); 29647c478bd9Sstevel@tonic-gate 29657c478bd9Sstevel@tonic-gate /* 29667c478bd9Sstevel@tonic-gate * Need to send a MRA MAD to CM so that it does not 29677c478bd9Sstevel@tonic-gate * timeout on us. 29687c478bd9Sstevel@tonic-gate */ 29697c478bd9Sstevel@tonic-gate (void) ibt_cm_delay(IBT_CM_DELAY_REQ, event->cm_session_id, 29707c478bd9Sstevel@tonic-gate event->cm_event.req.req_timeout * 8, NULL, 0); 29717c478bd9Sstevel@tonic-gate 29727c478bd9Sstevel@tonic-gate mutex_enter(&rib_stat->open_hca_lock); 29737c478bd9Sstevel@tonic-gate q = rib_stat->q; 29747c478bd9Sstevel@tonic-gate mutex_exit(&rib_stat->open_hca_lock); 29750a701b1eSRobert Gordon 29767c478bd9Sstevel@tonic-gate status = rib_svc_create_chan(hca, (caddr_t)q, 29777c478bd9Sstevel@tonic-gate event->cm_event.req.req_prim_hca_port, &qp); 29780a701b1eSRobert Gordon 29797c478bd9Sstevel@tonic-gate if (status) { 29807c478bd9Sstevel@tonic-gate return (IBT_CM_REJECT); 29817c478bd9Sstevel@tonic-gate } 29827c478bd9Sstevel@tonic-gate 29837c478bd9Sstevel@tonic-gate ret_args->cm_ret.rep.cm_channel = qp->qp_hdl; 29840a701b1eSRobert Gordon ret_args->cm_ret.rep.cm_rdma_ra_out = 4; 29850a701b1eSRobert Gordon ret_args->cm_ret.rep.cm_rdma_ra_in = 4; 29867c478bd9Sstevel@tonic-gate ret_args->cm_ret.rep.cm_rnr_retry_cnt = RNR_RETRIES; 29877c478bd9Sstevel@tonic-gate 29887c478bd9Sstevel@tonic-gate /* 29897c478bd9Sstevel@tonic-gate * Pre-posts RECV buffers 29907c478bd9Sstevel@tonic-gate */ 29917c478bd9Sstevel@tonic-gate conn = qptoc(qp); 29927c478bd9Sstevel@tonic-gate for (i = 0; i < preposted_rbufs; i++) { 29937c478bd9Sstevel@tonic-gate bzero(&rdbuf, sizeof (rdbuf)); 29947c478bd9Sstevel@tonic-gate rdbuf.type = RECV_BUFFER; 29957c478bd9Sstevel@tonic-gate buf = rib_rbuf_alloc(conn, &rdbuf); 29967c478bd9Sstevel@tonic-gate if (buf == NULL) { 2997065714dcSSiddheshwar Mahesh /* 2998065714dcSSiddheshwar Mahesh * A connection is not established yet. 2999065714dcSSiddheshwar Mahesh * Just flush the channel. Buffers 3000065714dcSSiddheshwar Mahesh * posted till now will error out with 3001065714dcSSiddheshwar Mahesh * IBT_WC_WR_FLUSHED_ERR. 3002065714dcSSiddheshwar Mahesh */ 3003065714dcSSiddheshwar Mahesh (void) ibt_flush_channel(qp->qp_hdl); 30047c478bd9Sstevel@tonic-gate (void) rib_disconnect_channel(conn, NULL); 30057c478bd9Sstevel@tonic-gate return (IBT_CM_REJECT); 30067c478bd9Sstevel@tonic-gate } 30077c478bd9Sstevel@tonic-gate 30087c478bd9Sstevel@tonic-gate bzero(&cl, sizeof (cl)); 30090a701b1eSRobert Gordon cl.w.c_saddr3 = (caddr_t)rdbuf.addr; 30107c478bd9Sstevel@tonic-gate cl.c_len = rdbuf.len; 30110a701b1eSRobert Gordon cl.c_smemhandle.mrc_lmr = 30120a701b1eSRobert Gordon rdbuf.handle.mrc_lmr; /* lkey */ 30137c478bd9Sstevel@tonic-gate cl.c_next = NULL; 30147c478bd9Sstevel@tonic-gate status = rib_post_recv(conn, &cl); 30157c478bd9Sstevel@tonic-gate if (status != RDMA_SUCCESS) { 3016065714dcSSiddheshwar Mahesh /* 3017065714dcSSiddheshwar Mahesh * A connection is not established yet. 3018065714dcSSiddheshwar Mahesh * Just flush the channel. Buffers 3019065714dcSSiddheshwar Mahesh * posted till now will error out with 3020065714dcSSiddheshwar Mahesh * IBT_WC_WR_FLUSHED_ERR. 3021065714dcSSiddheshwar Mahesh */ 3022065714dcSSiddheshwar Mahesh (void) ibt_flush_channel(qp->qp_hdl); 30237c478bd9Sstevel@tonic-gate (void) rib_disconnect_channel(conn, NULL); 30247c478bd9Sstevel@tonic-gate return (IBT_CM_REJECT); 30257c478bd9Sstevel@tonic-gate } 30267c478bd9Sstevel@tonic-gate } 30277c478bd9Sstevel@tonic-gate (void) rib_add_connlist(conn, &hca->srv_conn_list); 30287c478bd9Sstevel@tonic-gate 30297c478bd9Sstevel@tonic-gate /* 30300a701b1eSRobert Gordon * Get the address translation 30317c478bd9Sstevel@tonic-gate */ 30327c478bd9Sstevel@tonic-gate rw_enter(&hca->state_lock, RW_READER); 30337c478bd9Sstevel@tonic-gate if (hca->state == HCA_DETACHED) { 30347c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 30357c478bd9Sstevel@tonic-gate return (IBT_CM_REJECT); 30367c478bd9Sstevel@tonic-gate } 30377c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 30387c478bd9Sstevel@tonic-gate 30390a701b1eSRobert Gordon bzero(&ipinfo, sizeof (ibt_ip_cm_info_t)); 30407c478bd9Sstevel@tonic-gate 30410a701b1eSRobert Gordon if (ibt_get_ip_data(event->cm_priv_data_len, 30420a701b1eSRobert Gordon event->cm_priv_data, 30430a701b1eSRobert Gordon &ipinfo) != IBT_SUCCESS) { 30440a701b1eSRobert Gordon 30450a701b1eSRobert Gordon return (IBT_CM_REJECT); 30460a701b1eSRobert Gordon } 30470a701b1eSRobert Gordon 30480a701b1eSRobert Gordon switch (ipinfo.src_addr.family) { 30490a701b1eSRobert Gordon case AF_INET: 30507c478bd9Sstevel@tonic-gate 3051*7523bef8SSiddheshwar Mahesh conn->c_netid = kmem_zalloc(strlen(RIBNETID_TCP) + 1, 3052*7523bef8SSiddheshwar Mahesh KM_SLEEP); 3053*7523bef8SSiddheshwar Mahesh (void) strcpy(conn->c_netid, RIBNETID_TCP); 3054*7523bef8SSiddheshwar Mahesh 30557c478bd9Sstevel@tonic-gate conn->c_raddr.maxlen = 30567c478bd9Sstevel@tonic-gate conn->c_raddr.len = sin_size; 30570a701b1eSRobert Gordon conn->c_raddr.buf = kmem_zalloc(sin_size, KM_SLEEP); 30580a701b1eSRobert Gordon 30597c478bd9Sstevel@tonic-gate s = (struct sockaddr_in *)conn->c_raddr.buf; 30607c478bd9Sstevel@tonic-gate s->sin_family = AF_INET; 30610a701b1eSRobert Gordon bcopy((void *)&ipinfo.src_addr.un.ip4addr, 30620a701b1eSRobert Gordon &s->sin_addr, in_size); 30630a701b1eSRobert Gordon 3064*7523bef8SSiddheshwar Mahesh conn->c_laddr.maxlen = 3065*7523bef8SSiddheshwar Mahesh conn->c_laddr.len = sin_size; 3066*7523bef8SSiddheshwar Mahesh conn->c_laddr.buf = kmem_zalloc(sin_size, KM_SLEEP); 3067*7523bef8SSiddheshwar Mahesh 3068*7523bef8SSiddheshwar Mahesh s = (struct sockaddr_in *)conn->c_laddr.buf; 3069*7523bef8SSiddheshwar Mahesh s->sin_family = AF_INET; 3070*7523bef8SSiddheshwar Mahesh bcopy((void *)&ipinfo.dst_addr.un.ip4addr, 3071*7523bef8SSiddheshwar Mahesh &s->sin_addr, in_size); 3072*7523bef8SSiddheshwar Mahesh 30730a701b1eSRobert Gordon break; 30740a701b1eSRobert Gordon 30750a701b1eSRobert Gordon case AF_INET6: 30767c478bd9Sstevel@tonic-gate 3077*7523bef8SSiddheshwar Mahesh conn->c_netid = kmem_zalloc(strlen(RIBNETID_TCP6) + 1, 3078*7523bef8SSiddheshwar Mahesh KM_SLEEP); 3079*7523bef8SSiddheshwar Mahesh (void) strcpy(conn->c_netid, RIBNETID_TCP6); 3080*7523bef8SSiddheshwar Mahesh 30817c478bd9Sstevel@tonic-gate conn->c_raddr.maxlen = 30827c478bd9Sstevel@tonic-gate conn->c_raddr.len = sin6_size; 30830a701b1eSRobert Gordon conn->c_raddr.buf = kmem_zalloc(sin6_size, KM_SLEEP); 30847c478bd9Sstevel@tonic-gate 30857c478bd9Sstevel@tonic-gate s6 = (struct sockaddr_in6 *)conn->c_raddr.buf; 30867c478bd9Sstevel@tonic-gate s6->sin6_family = AF_INET6; 30870a701b1eSRobert Gordon bcopy((void *)&ipinfo.src_addr.un.ip6addr, 30880a701b1eSRobert Gordon &s6->sin6_addr, 30897c478bd9Sstevel@tonic-gate sizeof (struct in6_addr)); 30907c478bd9Sstevel@tonic-gate 3091*7523bef8SSiddheshwar Mahesh conn->c_laddr.maxlen = 3092*7523bef8SSiddheshwar Mahesh conn->c_laddr.len = sin6_size; 3093*7523bef8SSiddheshwar Mahesh conn->c_laddr.buf = kmem_zalloc(sin6_size, KM_SLEEP); 3094*7523bef8SSiddheshwar Mahesh 3095*7523bef8SSiddheshwar Mahesh s6 = (struct sockaddr_in6 *)conn->c_laddr.buf; 3096*7523bef8SSiddheshwar Mahesh s6->sin6_family = AF_INET6; 3097*7523bef8SSiddheshwar Mahesh bcopy((void *)&ipinfo.dst_addr.un.ip6addr, 3098*7523bef8SSiddheshwar Mahesh &s6->sin6_addr, 3099*7523bef8SSiddheshwar Mahesh sizeof (struct in6_addr)); 3100*7523bef8SSiddheshwar Mahesh 31010a701b1eSRobert Gordon break; 31020a701b1eSRobert Gordon 31030a701b1eSRobert Gordon default: 31040a701b1eSRobert Gordon return (IBT_CM_REJECT); 31057c478bd9Sstevel@tonic-gate } 31060a701b1eSRobert Gordon 31077c478bd9Sstevel@tonic-gate break; 31087c478bd9Sstevel@tonic-gate 31097c478bd9Sstevel@tonic-gate case IBT_CM_EVENT_CONN_CLOSED: 31107c478bd9Sstevel@tonic-gate { 31117c478bd9Sstevel@tonic-gate CONN *conn; 31127c478bd9Sstevel@tonic-gate rib_qp_t *qp; 31137c478bd9Sstevel@tonic-gate 31147c478bd9Sstevel@tonic-gate switch (event->cm_event.closed) { 31157c478bd9Sstevel@tonic-gate case IBT_CM_CLOSED_DREP_RCVD: 31167c478bd9Sstevel@tonic-gate case IBT_CM_CLOSED_DREQ_TIMEOUT: 31177c478bd9Sstevel@tonic-gate case IBT_CM_CLOSED_DUP: 31187c478bd9Sstevel@tonic-gate case IBT_CM_CLOSED_ABORT: 31197c478bd9Sstevel@tonic-gate case IBT_CM_CLOSED_ALREADY: 31207c478bd9Sstevel@tonic-gate /* 31217c478bd9Sstevel@tonic-gate * These cases indicate the local end initiated 31227c478bd9Sstevel@tonic-gate * the closing of the channel. Nothing to do here. 31237c478bd9Sstevel@tonic-gate */ 31247c478bd9Sstevel@tonic-gate break; 31257c478bd9Sstevel@tonic-gate default: 31267c478bd9Sstevel@tonic-gate /* 31277c478bd9Sstevel@tonic-gate * Reason for CONN_CLOSED event must be one of 31287c478bd9Sstevel@tonic-gate * IBT_CM_CLOSED_DREQ_RCVD or IBT_CM_CLOSED_REJ_RCVD 31297c478bd9Sstevel@tonic-gate * or IBT_CM_CLOSED_STALE. These indicate cases were 31307c478bd9Sstevel@tonic-gate * the remote end is closing the channel. In these 31317c478bd9Sstevel@tonic-gate * cases free the channel and transition to error 31327c478bd9Sstevel@tonic-gate * state 31337c478bd9Sstevel@tonic-gate */ 31347c478bd9Sstevel@tonic-gate qp = ibt_get_chan_private(event->cm_channel); 31357c478bd9Sstevel@tonic-gate conn = qptoc(qp); 31367c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 31377c478bd9Sstevel@tonic-gate if (conn->c_state == C_DISCONN_PEND) { 31387c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 31397c478bd9Sstevel@tonic-gate break; 31407c478bd9Sstevel@tonic-gate } 31410a701b1eSRobert Gordon conn->c_state = C_ERROR_CONN; 31427c478bd9Sstevel@tonic-gate 31437c478bd9Sstevel@tonic-gate /* 31447c478bd9Sstevel@tonic-gate * Free the conn if c_ref goes down to 0 31457c478bd9Sstevel@tonic-gate */ 31467c478bd9Sstevel@tonic-gate if (conn->c_ref == 0) { 31477c478bd9Sstevel@tonic-gate /* 31487c478bd9Sstevel@tonic-gate * Remove from list and free conn 31497c478bd9Sstevel@tonic-gate */ 31507c478bd9Sstevel@tonic-gate conn->c_state = C_DISCONN_PEND; 31517c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 31527c478bd9Sstevel@tonic-gate (void) rib_disconnect_channel(conn, 31537c478bd9Sstevel@tonic-gate &hca->srv_conn_list); 31547c478bd9Sstevel@tonic-gate } else { 3155065714dcSSiddheshwar Mahesh /* 3156065714dcSSiddheshwar Mahesh * conn will be freed when c_ref goes to 0. 3157065714dcSSiddheshwar Mahesh * Indicate to cleaning thread not to close 3158065714dcSSiddheshwar Mahesh * the connection, but just free the channel. 3159065714dcSSiddheshwar Mahesh */ 3160065714dcSSiddheshwar Mahesh conn->c_flags |= C_CLOSE_NOTNEEDED; 31617c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 31627c478bd9Sstevel@tonic-gate } 31630a701b1eSRobert Gordon DTRACE_PROBE(rpcib__i__srvcm_chandisconnect); 31647c478bd9Sstevel@tonic-gate break; 31657c478bd9Sstevel@tonic-gate } 31667c478bd9Sstevel@tonic-gate break; 31677c478bd9Sstevel@tonic-gate } 31687c478bd9Sstevel@tonic-gate case IBT_CM_EVENT_CONN_EST: 31697c478bd9Sstevel@tonic-gate /* 31707c478bd9Sstevel@tonic-gate * RTU received, hence connection established. 31717c478bd9Sstevel@tonic-gate */ 31727c478bd9Sstevel@tonic-gate if (rib_debug > 1) 31737c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_srv_cm_handler: " 31747c478bd9Sstevel@tonic-gate "(CONN_EST) channel established"); 31757c478bd9Sstevel@tonic-gate break; 31767c478bd9Sstevel@tonic-gate 31777c478bd9Sstevel@tonic-gate default: 31787c478bd9Sstevel@tonic-gate if (rib_debug > 2) { 31797c478bd9Sstevel@tonic-gate /* Let CM handle the following events. */ 31807c478bd9Sstevel@tonic-gate if (event->cm_type == IBT_CM_EVENT_REP_RCV) { 31817c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_srv_cm_handler: " 31827c478bd9Sstevel@tonic-gate "server recv'ed IBT_CM_EVENT_REP_RCV\n"); 31837c478bd9Sstevel@tonic-gate } else if (event->cm_type == IBT_CM_EVENT_LAP_RCV) { 31847c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_srv_cm_handler: " 31857c478bd9Sstevel@tonic-gate "server recv'ed IBT_CM_EVENT_LAP_RCV\n"); 31867c478bd9Sstevel@tonic-gate } else if (event->cm_type == IBT_CM_EVENT_MRA_RCV) { 31877c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_srv_cm_handler: " 31887c478bd9Sstevel@tonic-gate "server recv'ed IBT_CM_EVENT_MRA_RCV\n"); 31897c478bd9Sstevel@tonic-gate } else if (event->cm_type == IBT_CM_EVENT_APR_RCV) { 31907c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_srv_cm_handler: " 31917c478bd9Sstevel@tonic-gate "server recv'ed IBT_CM_EVENT_APR_RCV\n"); 31927c478bd9Sstevel@tonic-gate } else if (event->cm_type == IBT_CM_EVENT_FAILURE) { 31937c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "rib_srv_cm_handler: " 31947c478bd9Sstevel@tonic-gate "server recv'ed IBT_CM_EVENT_FAILURE\n"); 31957c478bd9Sstevel@tonic-gate } 31967c478bd9Sstevel@tonic-gate } 31970a701b1eSRobert Gordon return (IBT_CM_DEFAULT); 31987c478bd9Sstevel@tonic-gate } 31997c478bd9Sstevel@tonic-gate 32007c478bd9Sstevel@tonic-gate /* accept all other CM messages (i.e. let the CM handle them) */ 32017c478bd9Sstevel@tonic-gate return (IBT_CM_ACCEPT); 32027c478bd9Sstevel@tonic-gate } 32037c478bd9Sstevel@tonic-gate 32047c478bd9Sstevel@tonic-gate static rdma_stat 32057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_register_service(rib_hca_t *hca, int service_type, 32067f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States uint8_t protocol_num, in_port_t dst_port) 32077c478bd9Sstevel@tonic-gate { 32087c478bd9Sstevel@tonic-gate ibt_srv_desc_t sdesc; 32097c478bd9Sstevel@tonic-gate ibt_hca_portinfo_t *port_infop; 32107c478bd9Sstevel@tonic-gate ib_svc_id_t srv_id; 32117c478bd9Sstevel@tonic-gate ibt_srv_hdl_t srv_hdl; 32127c478bd9Sstevel@tonic-gate uint_t port_size; 32130a701b1eSRobert Gordon uint_t pki, i, num_ports, nbinds; 32147c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 32157f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_service_t *service; 32167c478bd9Sstevel@tonic-gate ib_pkey_t pkey; 32177c478bd9Sstevel@tonic-gate 32187c478bd9Sstevel@tonic-gate /* 32197c478bd9Sstevel@tonic-gate * Query all ports for the given HCA 32207c478bd9Sstevel@tonic-gate */ 32217c478bd9Sstevel@tonic-gate rw_enter(&hca->state_lock, RW_READER); 32227c478bd9Sstevel@tonic-gate if (hca->state != HCA_DETACHED) { 32237c478bd9Sstevel@tonic-gate ibt_status = ibt_query_hca_ports(hca->hca_hdl, 0, &port_infop, 32247c478bd9Sstevel@tonic-gate &num_ports, &port_size); 32257c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 32267c478bd9Sstevel@tonic-gate } else { 32277c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 32287c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 32297c478bd9Sstevel@tonic-gate } 32307c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) { 32317c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 32327c478bd9Sstevel@tonic-gate } 32337c478bd9Sstevel@tonic-gate 32340a701b1eSRobert Gordon DTRACE_PROBE1(rpcib__i__regservice_numports, 32350a701b1eSRobert Gordon int, num_ports); 32367c478bd9Sstevel@tonic-gate 32377c478bd9Sstevel@tonic-gate for (i = 0; i < num_ports; i++) { 32387c478bd9Sstevel@tonic-gate if (port_infop[i].p_linkstate != IBT_PORT_ACTIVE) { 32390a701b1eSRobert Gordon DTRACE_PROBE1(rpcib__i__regservice__portinactive, 32400a701b1eSRobert Gordon int, i+1); 32410a701b1eSRobert Gordon } else if (port_infop[i].p_linkstate == IBT_PORT_ACTIVE) { 32420a701b1eSRobert Gordon DTRACE_PROBE1(rpcib__i__regservice__portactive, 32430a701b1eSRobert Gordon int, i+1); 32447c478bd9Sstevel@tonic-gate } 32457c478bd9Sstevel@tonic-gate } 32460a701b1eSRobert Gordon 32477c478bd9Sstevel@tonic-gate /* 32487c478bd9Sstevel@tonic-gate * Get all the IP addresses on this system to register the 32497c478bd9Sstevel@tonic-gate * given "service type" on all DNS recognized IP addrs. 32507c478bd9Sstevel@tonic-gate * Each service type such as NFS will have all the systems 32517c478bd9Sstevel@tonic-gate * IP addresses as its different names. For now the only 32527c478bd9Sstevel@tonic-gate * type of service we support in RPCIB is NFS. 32537c478bd9Sstevel@tonic-gate */ 32547f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&rib_stat->service_list_lock, RW_WRITER); 32557c478bd9Sstevel@tonic-gate /* 32567c478bd9Sstevel@tonic-gate * Start registering and binding service to active 32577c478bd9Sstevel@tonic-gate * on active ports on this HCA. 32587c478bd9Sstevel@tonic-gate */ 32597c478bd9Sstevel@tonic-gate nbinds = 0; 32607f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States for (service = rib_stat->service_list; 32617f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States service && (service->srv_type != service_type); 32627f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States service = service->next) 32637f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ; 32647c478bd9Sstevel@tonic-gate 32657f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (service == NULL) { 32667c478bd9Sstevel@tonic-gate /* 32677c478bd9Sstevel@tonic-gate * We use IP addresses as the service names for 32687c478bd9Sstevel@tonic-gate * service registration. Register each of them 32697c478bd9Sstevel@tonic-gate * with CM to obtain a svc_id and svc_hdl. We do not 32707c478bd9Sstevel@tonic-gate * register the service with machine's loopback address. 32717c478bd9Sstevel@tonic-gate */ 32727c478bd9Sstevel@tonic-gate (void) bzero(&srv_id, sizeof (ib_svc_id_t)); 32737c478bd9Sstevel@tonic-gate (void) bzero(&srv_hdl, sizeof (ibt_srv_hdl_t)); 32747c478bd9Sstevel@tonic-gate (void) bzero(&sdesc, sizeof (ibt_srv_desc_t)); 32757c478bd9Sstevel@tonic-gate sdesc.sd_handler = rib_srv_cm_handler; 32767c478bd9Sstevel@tonic-gate sdesc.sd_flags = 0; 32777c478bd9Sstevel@tonic-gate ibt_status = ibt_register_service(hca->ibt_clnt_hdl, 32787f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States &sdesc, ibt_get_ip_sid(protocol_num, dst_port), 32790a701b1eSRobert Gordon 1, &srv_hdl, &srv_id); 32807f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if ((ibt_status != IBT_SUCCESS) && 32817f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (ibt_status != IBT_CM_SERVICE_EXISTS)) { 32827f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->service_list_lock); 32837f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States DTRACE_PROBE1(rpcib__i__regservice__ibtres, 32847f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States int, ibt_status); 32857f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ibt_free_portinfo(port_infop, port_size); 32867f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (RDMA_FAILED); 32877f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 32887f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 32897f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 32907f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Allocate and prepare a service entry 32917f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 32927f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States service = kmem_zalloc(sizeof (rib_service_t), KM_SLEEP); 32937f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 32947f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States service->srv_type = service_type; 32957f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States service->srv_hdl = srv_hdl; 32967f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States service->srv_id = srv_id; 32977f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 32987f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States service->next = rib_stat->service_list; 32997f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stat->service_list = service; 33007f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States DTRACE_PROBE1(rpcib__i__regservice__new__service, 33017f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States int, service->srv_type); 33027f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } else { 33037f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States srv_hdl = service->srv_hdl; 33047f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States srv_id = service->srv_id; 33057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States DTRACE_PROBE1(rpcib__i__regservice__existing__service, 33067f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States int, service->srv_type); 33077f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 33080a701b1eSRobert Gordon 33097c478bd9Sstevel@tonic-gate for (i = 0; i < num_ports; i++) { 33107f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ibt_sbind_hdl_t sbp; 33117f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_hca_service_t *hca_srv; 33127f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ib_gid_t gid; 33137f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 33147c478bd9Sstevel@tonic-gate if (port_infop[i].p_linkstate != IBT_PORT_ACTIVE) 33157c478bd9Sstevel@tonic-gate continue; 33167c478bd9Sstevel@tonic-gate 33177c478bd9Sstevel@tonic-gate for (pki = 0; pki < port_infop[i].p_pkey_tbl_sz; pki++) { 33187c478bd9Sstevel@tonic-gate pkey = port_infop[i].p_pkey_tbl[pki]; 33197c478bd9Sstevel@tonic-gate 33207f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&hca->bound_services_lock, RW_READER); 33217f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States gid = port_infop[i].p_sgid_tbl[0]; 33227f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States for (hca_srv = hca->bound_services; hca_srv; 33237f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca_srv = hca_srv->next) { 33247f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if ((hca_srv->srv_id == service->srv_id) && 33257f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (hca_srv->gid.gid_prefix == 33267f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States gid.gid_prefix) && 33277f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (hca_srv->gid.gid_guid == gid.gid_guid)) 33287f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States break; 33297f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 33307f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->bound_services_lock); 33317f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca_srv != NULL) { 33327c478bd9Sstevel@tonic-gate /* 33337f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * port is alreay bound the the service 33347c478bd9Sstevel@tonic-gate */ 33357f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States DTRACE_PROBE1( 33367f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib__i__regservice__already__bound, 33377f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States int, i+1); 33387f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States nbinds++; 33397c478bd9Sstevel@tonic-gate continue; 33407c478bd9Sstevel@tonic-gate } 33410a701b1eSRobert Gordon 33427f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if ((pkey & IBSRM_HB) && 33437f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (pkey != IB_PKEY_INVALID_FULL)) { 33447f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 33457f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States sbp = NULL; 33467f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ibt_status = ibt_bind_service(srv_hdl, 33477f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States gid, NULL, hca, &sbp); 33487f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 33497f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (ibt_status == IBT_SUCCESS) { 33507f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca_srv = kmem_zalloc( 33517f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States sizeof (rib_hca_service_t), 33527f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States KM_SLEEP); 33537f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca_srv->srv_id = srv_id; 33547f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca_srv->gid = gid; 33557f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca_srv->sbind_hdl = sbp; 33567f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 33577f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&hca->bound_services_lock, 33587f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States RW_WRITER); 33597f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca_srv->next = hca->bound_services; 33607f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->bound_services = hca_srv; 33617f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->bound_services_lock); 33627c478bd9Sstevel@tonic-gate nbinds++; 33637c478bd9Sstevel@tonic-gate } 33647f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 33657f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States DTRACE_PROBE1(rpcib__i__regservice__bindres, 33667f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States int, ibt_status); 33677c478bd9Sstevel@tonic-gate } 33687c478bd9Sstevel@tonic-gate } 33697f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 33707f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->service_list_lock); 33717c478bd9Sstevel@tonic-gate 33727c478bd9Sstevel@tonic-gate ibt_free_portinfo(port_infop, port_size); 33737c478bd9Sstevel@tonic-gate 33747c478bd9Sstevel@tonic-gate if (nbinds == 0) { 33757c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 33767c478bd9Sstevel@tonic-gate } else { 33777c478bd9Sstevel@tonic-gate /* 33787c478bd9Sstevel@tonic-gate * Put this plugin into accept state, since atleast 33797c478bd9Sstevel@tonic-gate * one registration was successful. 33807c478bd9Sstevel@tonic-gate */ 33817c478bd9Sstevel@tonic-gate mutex_enter(&plugin_state_lock); 33827c478bd9Sstevel@tonic-gate plugin_state = ACCEPT; 33837c478bd9Sstevel@tonic-gate mutex_exit(&plugin_state_lock); 33847c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 33857c478bd9Sstevel@tonic-gate } 33867c478bd9Sstevel@tonic-gate } 33877c478bd9Sstevel@tonic-gate 33887c478bd9Sstevel@tonic-gate void 33897c478bd9Sstevel@tonic-gate rib_listen(struct rdma_svc_data *rd) 33907c478bd9Sstevel@tonic-gate { 33917f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rdma_stat status; 33927f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States int n_listening = 0; 33937f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_hca_t *hca; 33947c478bd9Sstevel@tonic-gate 33957f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_enter(&rib_stat->listen_lock); 33967f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 33977f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * if rd parameter is NULL then it means that rib_stat->q is 33987f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * already initialized by a call from RDMA and we just want to 33997f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * add a newly attached HCA to the same listening state as other 34007f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * HCAs. 34017f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 34027f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (rd == NULL) { 34037f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (rib_stat->q == NULL) { 34047f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&rib_stat->listen_lock); 34057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return; 34067f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 34077f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } else { 34087f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stat->q = &rd->q; 34097f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 34107f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&rib_stat->hcas_list_lock, RW_READER); 34117f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States for (hca = rib_stat->hcas_list; hca; hca = hca->next) { 34127c478bd9Sstevel@tonic-gate /* 34137c478bd9Sstevel@tonic-gate * First check if a hca is still attached 34147c478bd9Sstevel@tonic-gate */ 34157f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&hca->state_lock, RW_READER); 34167f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca->state != HCA_INITED) { 34177f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 34187f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States continue; 34197c478bd9Sstevel@tonic-gate } 34207f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 34217c478bd9Sstevel@tonic-gate 34227c478bd9Sstevel@tonic-gate /* 34237f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Right now the only service type is NFS. Hence 34247f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * force feed this value. Ideally to communicate 34257f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * the service type it should be passed down in 34267f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * rdma_svc_data. 34277c478bd9Sstevel@tonic-gate */ 34287f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States status = rib_register_service(hca, NFS, 34297f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States IPPROTO_TCP, nfs_rdma_port); 34307f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (status == RDMA_SUCCESS) 34317f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States n_listening++; 34327c478bd9Sstevel@tonic-gate } 34337f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->hcas_list_lock); 34347f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 34357c478bd9Sstevel@tonic-gate /* 34367c478bd9Sstevel@tonic-gate * Service active on an HCA, check rd->err_code for more 34377c478bd9Sstevel@tonic-gate * explainable errors. 34387c478bd9Sstevel@tonic-gate */ 34397f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (rd) { 34407f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (n_listening > 0) { 34417c478bd9Sstevel@tonic-gate rd->active = 1; 34427f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rd->err_code = RDMA_SUCCESS; 34437f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } else { 34447f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rd->active = 0; 34457f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rd->err_code = RDMA_FAILED; 34467f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 34477f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 34487f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&rib_stat->listen_lock); 34497c478bd9Sstevel@tonic-gate } 34507c478bd9Sstevel@tonic-gate 34517c478bd9Sstevel@tonic-gate /* XXXX */ 34527c478bd9Sstevel@tonic-gate /* ARGSUSED */ 34537c478bd9Sstevel@tonic-gate static void 34547c478bd9Sstevel@tonic-gate rib_listen_stop(struct rdma_svc_data *svcdata) 34557c478bd9Sstevel@tonic-gate { 34567c478bd9Sstevel@tonic-gate rib_hca_t *hca; 34577c478bd9Sstevel@tonic-gate 34587f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_enter(&rib_stat->listen_lock); 34597c478bd9Sstevel@tonic-gate /* 34607c478bd9Sstevel@tonic-gate * KRPC called the RDMATF to stop the listeners, this means 34617c478bd9Sstevel@tonic-gate * stop sending incomming or recieved requests to KRPC master 34627c478bd9Sstevel@tonic-gate * transport handle for RDMA-IB. This is also means that the 34637c478bd9Sstevel@tonic-gate * master transport handle, responsible for us, is going away. 34647c478bd9Sstevel@tonic-gate */ 34657c478bd9Sstevel@tonic-gate mutex_enter(&plugin_state_lock); 34667c478bd9Sstevel@tonic-gate plugin_state = NO_ACCEPT; 34677c478bd9Sstevel@tonic-gate if (svcdata != NULL) 34687c478bd9Sstevel@tonic-gate svcdata->active = 0; 34697c478bd9Sstevel@tonic-gate mutex_exit(&plugin_state_lock); 34707c478bd9Sstevel@tonic-gate 34717f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&rib_stat->hcas_list_lock, RW_READER); 34727f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States for (hca = rib_stat->hcas_list; hca; hca = hca->next) { 34737c478bd9Sstevel@tonic-gate /* 34747c478bd9Sstevel@tonic-gate * First check if a hca is still attached 34757c478bd9Sstevel@tonic-gate */ 34767c478bd9Sstevel@tonic-gate rw_enter(&hca->state_lock, RW_READER); 34777f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca->state == HCA_DETACHED) { 34787c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 34797f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States continue; 34807c478bd9Sstevel@tonic-gate } 34810a701b1eSRobert Gordon rib_close_channels(&hca->srv_conn_list); 34827c478bd9Sstevel@tonic-gate rib_stop_services(hca); 34837c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 34847c478bd9Sstevel@tonic-gate } 34857f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->hcas_list_lock); 34867f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 34877f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 34887f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Avoid rib_listen() using the stale q field. 34897f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * This could happen if a port goes up after all services 34907f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * are already unregistered. 34917f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 34927f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stat->q = NULL; 34937f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&rib_stat->listen_lock); 34947f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 34957c478bd9Sstevel@tonic-gate 34967c478bd9Sstevel@tonic-gate /* 34977c478bd9Sstevel@tonic-gate * Traverse the HCA's service list to unbind and deregister services. 34987f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * For each bound service of HCA to be removed, first find the corresponding 34997f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * service handle (srv_hdl) and then unbind the service by calling 35007f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * ibt_unbind_service(). 35017c478bd9Sstevel@tonic-gate */ 35027c478bd9Sstevel@tonic-gate static void 35037c478bd9Sstevel@tonic-gate rib_stop_services(rib_hca_t *hca) 35047c478bd9Sstevel@tonic-gate { 35057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_hca_service_t *srv_list, *to_remove; 35067c478bd9Sstevel@tonic-gate 35077c478bd9Sstevel@tonic-gate /* 35087c478bd9Sstevel@tonic-gate * unbind and deregister the services for this service type. 35097c478bd9Sstevel@tonic-gate * Right now there is only one service type. In future it will 35107c478bd9Sstevel@tonic-gate * be passed down to this function. 35117c478bd9Sstevel@tonic-gate */ 35127f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&hca->bound_services_lock, RW_READER); 35137f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States srv_list = hca->bound_services; 35147f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->bound_services = NULL; 35157f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->bound_services_lock); 35167f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 35177c478bd9Sstevel@tonic-gate while (srv_list != NULL) { 35187f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_service_t *sc; 35197f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 35207c478bd9Sstevel@tonic-gate to_remove = srv_list; 35217f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States srv_list = to_remove->next; 35227f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&rib_stat->service_list_lock, RW_READER); 35237f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States for (sc = rib_stat->service_list; 35247f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States sc && (sc->srv_id != to_remove->srv_id); 35257f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States sc = sc->next) 35267f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ; 35277f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 35287f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * if sc is NULL then the service doesn't exist anymore, 35297f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * probably just removed completely through rib_stat. 35307f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 35317f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (sc != NULL) 35327f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (void) ibt_unbind_service(sc->srv_hdl, 35337f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States to_remove->sbind_hdl); 35347f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->service_list_lock); 35357f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States kmem_free(to_remove, sizeof (rib_hca_service_t)); 35367c478bd9Sstevel@tonic-gate } 35377c478bd9Sstevel@tonic-gate } 35387c478bd9Sstevel@tonic-gate 35397c478bd9Sstevel@tonic-gate static struct svc_recv * 35407c478bd9Sstevel@tonic-gate rib_init_svc_recv(rib_qp_t *qp, ibt_wr_ds_t *sgl) 35417c478bd9Sstevel@tonic-gate { 35427c478bd9Sstevel@tonic-gate struct svc_recv *recvp; 35437c478bd9Sstevel@tonic-gate 35447c478bd9Sstevel@tonic-gate recvp = kmem_zalloc(sizeof (struct svc_recv), KM_SLEEP); 35457c478bd9Sstevel@tonic-gate recvp->vaddr = sgl->ds_va; 35467c478bd9Sstevel@tonic-gate recvp->qp = qp; 35477c478bd9Sstevel@tonic-gate recvp->bytes_xfer = 0; 35487c478bd9Sstevel@tonic-gate return (recvp); 35497c478bd9Sstevel@tonic-gate } 35507c478bd9Sstevel@tonic-gate 35517c478bd9Sstevel@tonic-gate static int 35527c478bd9Sstevel@tonic-gate rib_free_svc_recv(struct svc_recv *recvp) 35537c478bd9Sstevel@tonic-gate { 35547c478bd9Sstevel@tonic-gate kmem_free(recvp, sizeof (*recvp)); 35557c478bd9Sstevel@tonic-gate 35567c478bd9Sstevel@tonic-gate return (0); 35577c478bd9Sstevel@tonic-gate } 35587c478bd9Sstevel@tonic-gate 35597c478bd9Sstevel@tonic-gate static struct reply * 35607c478bd9Sstevel@tonic-gate rib_addreplylist(rib_qp_t *qp, uint32_t msgid) 35617c478bd9Sstevel@tonic-gate { 35627c478bd9Sstevel@tonic-gate struct reply *rep; 35637c478bd9Sstevel@tonic-gate 35647c478bd9Sstevel@tonic-gate 35657c478bd9Sstevel@tonic-gate rep = kmem_zalloc(sizeof (struct reply), KM_NOSLEEP); 35667c478bd9Sstevel@tonic-gate if (rep == NULL) { 35670a701b1eSRobert Gordon DTRACE_PROBE(rpcib__i__addrreply__nomem); 35687c478bd9Sstevel@tonic-gate return (NULL); 35697c478bd9Sstevel@tonic-gate } 35707c478bd9Sstevel@tonic-gate rep->xid = msgid; 35717c478bd9Sstevel@tonic-gate rep->vaddr_cq = NULL; 35727c478bd9Sstevel@tonic-gate rep->bytes_xfer = 0; 35737c478bd9Sstevel@tonic-gate rep->status = (uint_t)REPLY_WAIT; 35747c478bd9Sstevel@tonic-gate rep->prev = NULL; 35757c478bd9Sstevel@tonic-gate cv_init(&rep->wait_cv, NULL, CV_DEFAULT, NULL); 35767c478bd9Sstevel@tonic-gate 35777c478bd9Sstevel@tonic-gate mutex_enter(&qp->replylist_lock); 35787c478bd9Sstevel@tonic-gate if (qp->replylist) { 35797c478bd9Sstevel@tonic-gate rep->next = qp->replylist; 35807c478bd9Sstevel@tonic-gate qp->replylist->prev = rep; 35817c478bd9Sstevel@tonic-gate } 35827c478bd9Sstevel@tonic-gate qp->rep_list_size++; 35830a701b1eSRobert Gordon 35840a701b1eSRobert Gordon DTRACE_PROBE1(rpcib__i__addrreply__listsize, 35850a701b1eSRobert Gordon int, qp->rep_list_size); 35860a701b1eSRobert Gordon 35877c478bd9Sstevel@tonic-gate qp->replylist = rep; 35887c478bd9Sstevel@tonic-gate mutex_exit(&qp->replylist_lock); 35897c478bd9Sstevel@tonic-gate 35907c478bd9Sstevel@tonic-gate return (rep); 35917c478bd9Sstevel@tonic-gate } 35927c478bd9Sstevel@tonic-gate 35937c478bd9Sstevel@tonic-gate static rdma_stat 35947c478bd9Sstevel@tonic-gate rib_rem_replylist(rib_qp_t *qp) 35957c478bd9Sstevel@tonic-gate { 35967c478bd9Sstevel@tonic-gate struct reply *r, *n; 35977c478bd9Sstevel@tonic-gate 35987c478bd9Sstevel@tonic-gate mutex_enter(&qp->replylist_lock); 35997c478bd9Sstevel@tonic-gate for (r = qp->replylist; r != NULL; r = n) { 36007c478bd9Sstevel@tonic-gate n = r->next; 36017c478bd9Sstevel@tonic-gate (void) rib_remreply(qp, r); 36027c478bd9Sstevel@tonic-gate } 36037c478bd9Sstevel@tonic-gate mutex_exit(&qp->replylist_lock); 36047c478bd9Sstevel@tonic-gate 36057c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 36067c478bd9Sstevel@tonic-gate } 36077c478bd9Sstevel@tonic-gate 36087c478bd9Sstevel@tonic-gate static int 36097c478bd9Sstevel@tonic-gate rib_remreply(rib_qp_t *qp, struct reply *rep) 36107c478bd9Sstevel@tonic-gate { 36117c478bd9Sstevel@tonic-gate 36127c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&qp->replylist_lock)); 36137c478bd9Sstevel@tonic-gate if (rep->prev) { 36147c478bd9Sstevel@tonic-gate rep->prev->next = rep->next; 36157c478bd9Sstevel@tonic-gate } 36167c478bd9Sstevel@tonic-gate if (rep->next) { 36177c478bd9Sstevel@tonic-gate rep->next->prev = rep->prev; 36187c478bd9Sstevel@tonic-gate } 36197c478bd9Sstevel@tonic-gate if (qp->replylist == rep) 36207c478bd9Sstevel@tonic-gate qp->replylist = rep->next; 36217c478bd9Sstevel@tonic-gate 36227c478bd9Sstevel@tonic-gate cv_destroy(&rep->wait_cv); 36237c478bd9Sstevel@tonic-gate qp->rep_list_size--; 36240a701b1eSRobert Gordon 36250a701b1eSRobert Gordon DTRACE_PROBE1(rpcib__i__remreply__listsize, 36260a701b1eSRobert Gordon int, qp->rep_list_size); 36277c478bd9Sstevel@tonic-gate 36287c478bd9Sstevel@tonic-gate kmem_free(rep, sizeof (*rep)); 36297c478bd9Sstevel@tonic-gate 36307c478bd9Sstevel@tonic-gate return (0); 36317c478bd9Sstevel@tonic-gate } 36327c478bd9Sstevel@tonic-gate 36337c478bd9Sstevel@tonic-gate rdma_stat 36340a701b1eSRobert Gordon rib_registermem(CONN *conn, caddr_t adsp, caddr_t buf, uint_t buflen, 36357c478bd9Sstevel@tonic-gate struct mrc *buf_handle) 36367c478bd9Sstevel@tonic-gate { 36377c478bd9Sstevel@tonic-gate ibt_mr_hdl_t mr_hdl = NULL; /* memory region handle */ 36387c478bd9Sstevel@tonic-gate ibt_mr_desc_t mr_desc; /* vaddr, lkey, rkey */ 36397c478bd9Sstevel@tonic-gate rdma_stat status; 36407c478bd9Sstevel@tonic-gate rib_hca_t *hca = (ctoqp(conn))->hca; 36417c478bd9Sstevel@tonic-gate 36427c478bd9Sstevel@tonic-gate /* 36437c478bd9Sstevel@tonic-gate * Note: ALL buffer pools use the same memory type RDMARW. 36447c478bd9Sstevel@tonic-gate */ 36450a701b1eSRobert Gordon status = rib_reg_mem(hca, adsp, buf, buflen, 0, &mr_hdl, &mr_desc); 36467c478bd9Sstevel@tonic-gate if (status == RDMA_SUCCESS) { 364711606941Sjwahlig buf_handle->mrc_linfo = (uintptr_t)mr_hdl; 36487c478bd9Sstevel@tonic-gate buf_handle->mrc_lmr = (uint32_t)mr_desc.md_lkey; 36497c478bd9Sstevel@tonic-gate buf_handle->mrc_rmr = (uint32_t)mr_desc.md_rkey; 36507c478bd9Sstevel@tonic-gate } else { 36517c478bd9Sstevel@tonic-gate buf_handle->mrc_linfo = NULL; 36527c478bd9Sstevel@tonic-gate buf_handle->mrc_lmr = 0; 36537c478bd9Sstevel@tonic-gate buf_handle->mrc_rmr = 0; 36547c478bd9Sstevel@tonic-gate } 36557c478bd9Sstevel@tonic-gate return (status); 36567c478bd9Sstevel@tonic-gate } 36577c478bd9Sstevel@tonic-gate 36587c478bd9Sstevel@tonic-gate static rdma_stat 36590a701b1eSRobert Gordon rib_reg_mem(rib_hca_t *hca, caddr_t adsp, caddr_t buf, uint_t size, 36600a701b1eSRobert Gordon ibt_mr_flags_t spec, 36617c478bd9Sstevel@tonic-gate ibt_mr_hdl_t *mr_hdlp, ibt_mr_desc_t *mr_descp) 36627c478bd9Sstevel@tonic-gate { 36637c478bd9Sstevel@tonic-gate ibt_mr_attr_t mem_attr; 36647c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 366511606941Sjwahlig mem_attr.mr_vaddr = (uintptr_t)buf; 36667c478bd9Sstevel@tonic-gate mem_attr.mr_len = (ib_msglen_t)size; 36670a701b1eSRobert Gordon mem_attr.mr_as = (struct as *)(caddr_t)adsp; 36687c478bd9Sstevel@tonic-gate mem_attr.mr_flags = IBT_MR_SLEEP | IBT_MR_ENABLE_LOCAL_WRITE | 36697c478bd9Sstevel@tonic-gate IBT_MR_ENABLE_REMOTE_READ | IBT_MR_ENABLE_REMOTE_WRITE | 36707c478bd9Sstevel@tonic-gate IBT_MR_ENABLE_WINDOW_BIND | spec; 36717c478bd9Sstevel@tonic-gate 36727c478bd9Sstevel@tonic-gate rw_enter(&hca->state_lock, RW_READER); 36737f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca->state != HCA_DETACHED) { 36747c478bd9Sstevel@tonic-gate ibt_status = ibt_register_mr(hca->hca_hdl, hca->pd_hdl, 36757c478bd9Sstevel@tonic-gate &mem_attr, mr_hdlp, mr_descp); 36767c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 36777c478bd9Sstevel@tonic-gate } else { 36787c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 36797c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 36807c478bd9Sstevel@tonic-gate } 36817c478bd9Sstevel@tonic-gate 36827c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) { 36837c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 36847c478bd9Sstevel@tonic-gate } 36857c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 36867c478bd9Sstevel@tonic-gate } 36877c478bd9Sstevel@tonic-gate 36887c478bd9Sstevel@tonic-gate rdma_stat 36890a701b1eSRobert Gordon rib_registermemsync(CONN *conn, caddr_t adsp, caddr_t buf, uint_t buflen, 36900a701b1eSRobert Gordon struct mrc *buf_handle, RIB_SYNCMEM_HANDLE *sync_handle, void *lrc) 36917c478bd9Sstevel@tonic-gate { 36927c478bd9Sstevel@tonic-gate ibt_mr_hdl_t mr_hdl = NULL; /* memory region handle */ 36930a701b1eSRobert Gordon rib_lrc_entry_t *l; 36947c478bd9Sstevel@tonic-gate ibt_mr_desc_t mr_desc; /* vaddr, lkey, rkey */ 36957c478bd9Sstevel@tonic-gate rdma_stat status; 36967c478bd9Sstevel@tonic-gate rib_hca_t *hca = (ctoqp(conn))->hca; 36977c478bd9Sstevel@tonic-gate 36987c478bd9Sstevel@tonic-gate /* 36997c478bd9Sstevel@tonic-gate * Non-coherent memory registration. 37007c478bd9Sstevel@tonic-gate */ 37010a701b1eSRobert Gordon l = (rib_lrc_entry_t *)lrc; 37020a701b1eSRobert Gordon if (l) { 37030a701b1eSRobert Gordon if (l->registered) { 37040a701b1eSRobert Gordon buf_handle->mrc_linfo = 37050a701b1eSRobert Gordon (uintptr_t)l->lrc_mhandle.mrc_linfo; 37060a701b1eSRobert Gordon buf_handle->mrc_lmr = 37070a701b1eSRobert Gordon (uint32_t)l->lrc_mhandle.mrc_lmr; 37080a701b1eSRobert Gordon buf_handle->mrc_rmr = 37090a701b1eSRobert Gordon (uint32_t)l->lrc_mhandle.mrc_rmr; 37100a701b1eSRobert Gordon *sync_handle = (RIB_SYNCMEM_HANDLE) 37110a701b1eSRobert Gordon (uintptr_t)l->lrc_mhandle.mrc_linfo; 37120a701b1eSRobert Gordon return (RDMA_SUCCESS); 37130a701b1eSRobert Gordon } else { 37140a701b1eSRobert Gordon /* Always register the whole buffer */ 37150a701b1eSRobert Gordon buf = (caddr_t)l->lrc_buf; 37160a701b1eSRobert Gordon buflen = l->lrc_len; 37170a701b1eSRobert Gordon } 37180a701b1eSRobert Gordon } 37190a701b1eSRobert Gordon status = rib_reg_mem(hca, adsp, buf, buflen, 0, &mr_hdl, &mr_desc); 37200a701b1eSRobert Gordon 37217c478bd9Sstevel@tonic-gate if (status == RDMA_SUCCESS) { 37220a701b1eSRobert Gordon if (l) { 37230a701b1eSRobert Gordon l->lrc_mhandle.mrc_linfo = (uintptr_t)mr_hdl; 37240a701b1eSRobert Gordon l->lrc_mhandle.mrc_lmr = (uint32_t)mr_desc.md_lkey; 37250a701b1eSRobert Gordon l->lrc_mhandle.mrc_rmr = (uint32_t)mr_desc.md_rkey; 37260a701b1eSRobert Gordon l->registered = TRUE; 37270a701b1eSRobert Gordon } 372811606941Sjwahlig buf_handle->mrc_linfo = (uintptr_t)mr_hdl; 37297c478bd9Sstevel@tonic-gate buf_handle->mrc_lmr = (uint32_t)mr_desc.md_lkey; 37307c478bd9Sstevel@tonic-gate buf_handle->mrc_rmr = (uint32_t)mr_desc.md_rkey; 37317c478bd9Sstevel@tonic-gate *sync_handle = (RIB_SYNCMEM_HANDLE)mr_hdl; 37327c478bd9Sstevel@tonic-gate } else { 37337c478bd9Sstevel@tonic-gate buf_handle->mrc_linfo = NULL; 37347c478bd9Sstevel@tonic-gate buf_handle->mrc_lmr = 0; 37357c478bd9Sstevel@tonic-gate buf_handle->mrc_rmr = 0; 37367c478bd9Sstevel@tonic-gate } 37377c478bd9Sstevel@tonic-gate return (status); 37387c478bd9Sstevel@tonic-gate } 37397c478bd9Sstevel@tonic-gate 37407c478bd9Sstevel@tonic-gate /* ARGSUSED */ 37417c478bd9Sstevel@tonic-gate rdma_stat 37427c478bd9Sstevel@tonic-gate rib_deregistermem(CONN *conn, caddr_t buf, struct mrc buf_handle) 37437c478bd9Sstevel@tonic-gate { 37447c478bd9Sstevel@tonic-gate rib_hca_t *hca = (ctoqp(conn))->hca; 37457c478bd9Sstevel@tonic-gate /* 37467c478bd9Sstevel@tonic-gate * Allow memory deregistration even if HCA is 37477c478bd9Sstevel@tonic-gate * getting detached. Need all outstanding 37487c478bd9Sstevel@tonic-gate * memory registrations to be deregistered 37497c478bd9Sstevel@tonic-gate * before HCA_DETACH_EVENT can be accepted. 37507c478bd9Sstevel@tonic-gate */ 37517c478bd9Sstevel@tonic-gate (void) ibt_deregister_mr(hca->hca_hdl, 375211606941Sjwahlig (ibt_mr_hdl_t)(uintptr_t)buf_handle.mrc_linfo); 37537c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 37547c478bd9Sstevel@tonic-gate } 37557c478bd9Sstevel@tonic-gate 37567c478bd9Sstevel@tonic-gate /* ARGSUSED */ 37577c478bd9Sstevel@tonic-gate rdma_stat 37587c478bd9Sstevel@tonic-gate rib_deregistermemsync(CONN *conn, caddr_t buf, struct mrc buf_handle, 37590a701b1eSRobert Gordon RIB_SYNCMEM_HANDLE sync_handle, void *lrc) 37607c478bd9Sstevel@tonic-gate { 37610a701b1eSRobert Gordon rib_lrc_entry_t *l; 37620a701b1eSRobert Gordon l = (rib_lrc_entry_t *)lrc; 37630a701b1eSRobert Gordon if (l) 37640a701b1eSRobert Gordon if (l->registered) 37650a701b1eSRobert Gordon return (RDMA_SUCCESS); 37660a701b1eSRobert Gordon 37677c478bd9Sstevel@tonic-gate (void) rib_deregistermem(conn, buf, buf_handle); 37687c478bd9Sstevel@tonic-gate 37697c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 37707c478bd9Sstevel@tonic-gate } 37717c478bd9Sstevel@tonic-gate 37727c478bd9Sstevel@tonic-gate /* ARGSUSED */ 37737c478bd9Sstevel@tonic-gate rdma_stat 37747c478bd9Sstevel@tonic-gate rib_syncmem(CONN *conn, RIB_SYNCMEM_HANDLE shandle, caddr_t buf, 37757c478bd9Sstevel@tonic-gate int len, int cpu) 37767c478bd9Sstevel@tonic-gate { 37777c478bd9Sstevel@tonic-gate ibt_status_t status; 37787c478bd9Sstevel@tonic-gate rib_hca_t *hca = (ctoqp(conn))->hca; 37797c478bd9Sstevel@tonic-gate ibt_mr_sync_t mr_segment; 37807c478bd9Sstevel@tonic-gate 37817c478bd9Sstevel@tonic-gate mr_segment.ms_handle = (ibt_mr_hdl_t)shandle; 378211606941Sjwahlig mr_segment.ms_vaddr = (ib_vaddr_t)(uintptr_t)buf; 37837c478bd9Sstevel@tonic-gate mr_segment.ms_len = (ib_memlen_t)len; 37847c478bd9Sstevel@tonic-gate if (cpu) { 37857c478bd9Sstevel@tonic-gate /* make incoming data visible to memory */ 37867c478bd9Sstevel@tonic-gate mr_segment.ms_flags = IBT_SYNC_WRITE; 37877c478bd9Sstevel@tonic-gate } else { 37887c478bd9Sstevel@tonic-gate /* make memory changes visible to IO */ 37897c478bd9Sstevel@tonic-gate mr_segment.ms_flags = IBT_SYNC_READ; 37907c478bd9Sstevel@tonic-gate } 37917c478bd9Sstevel@tonic-gate rw_enter(&hca->state_lock, RW_READER); 37927f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca->state != HCA_DETACHED) { 37937c478bd9Sstevel@tonic-gate status = ibt_sync_mr(hca->hca_hdl, &mr_segment, 1); 37947c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 37957c478bd9Sstevel@tonic-gate } else { 37967c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 37977c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 37987c478bd9Sstevel@tonic-gate } 37997c478bd9Sstevel@tonic-gate 38007c478bd9Sstevel@tonic-gate if (status == IBT_SUCCESS) 38017c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 38027c478bd9Sstevel@tonic-gate else { 38037c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 38047c478bd9Sstevel@tonic-gate } 38057c478bd9Sstevel@tonic-gate } 38067c478bd9Sstevel@tonic-gate 38077c478bd9Sstevel@tonic-gate /* 38087c478bd9Sstevel@tonic-gate * XXXX ???? 38097c478bd9Sstevel@tonic-gate */ 38107c478bd9Sstevel@tonic-gate static rdma_stat 38117c478bd9Sstevel@tonic-gate rib_getinfo(rdma_info_t *info) 38127c478bd9Sstevel@tonic-gate { 38137c478bd9Sstevel@tonic-gate /* 38147c478bd9Sstevel@tonic-gate * XXXX Hack! 38157c478bd9Sstevel@tonic-gate */ 38167c478bd9Sstevel@tonic-gate info->addrlen = 16; 38177c478bd9Sstevel@tonic-gate info->mts = 1000000; 38187c478bd9Sstevel@tonic-gate info->mtu = 1000000; 38197c478bd9Sstevel@tonic-gate 38207c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 38217c478bd9Sstevel@tonic-gate } 38227c478bd9Sstevel@tonic-gate 38237c478bd9Sstevel@tonic-gate rib_bufpool_t * 38247c478bd9Sstevel@tonic-gate rib_rbufpool_create(rib_hca_t *hca, int ptype, int num) 38257c478bd9Sstevel@tonic-gate { 38267c478bd9Sstevel@tonic-gate rib_bufpool_t *rbp = NULL; 38277c478bd9Sstevel@tonic-gate bufpool_t *bp = NULL; 38287c478bd9Sstevel@tonic-gate caddr_t buf; 38297c478bd9Sstevel@tonic-gate ibt_mr_attr_t mem_attr; 38307c478bd9Sstevel@tonic-gate ibt_status_t ibt_status; 38317c478bd9Sstevel@tonic-gate int i, j; 38327c478bd9Sstevel@tonic-gate 38337c478bd9Sstevel@tonic-gate rbp = (rib_bufpool_t *)kmem_zalloc(sizeof (rib_bufpool_t), KM_SLEEP); 38347c478bd9Sstevel@tonic-gate 38357c478bd9Sstevel@tonic-gate bp = (bufpool_t *)kmem_zalloc(sizeof (bufpool_t) + 38367c478bd9Sstevel@tonic-gate num * sizeof (void *), KM_SLEEP); 38377c478bd9Sstevel@tonic-gate 38387c478bd9Sstevel@tonic-gate mutex_init(&bp->buflock, NULL, MUTEX_DRIVER, hca->iblock); 38397c478bd9Sstevel@tonic-gate bp->numelems = num; 38407c478bd9Sstevel@tonic-gate 38410a701b1eSRobert Gordon 38427c478bd9Sstevel@tonic-gate switch (ptype) { 38437c478bd9Sstevel@tonic-gate case SEND_BUFFER: 38447c478bd9Sstevel@tonic-gate mem_attr.mr_flags = IBT_MR_SLEEP | IBT_MR_ENABLE_LOCAL_WRITE; 38457c478bd9Sstevel@tonic-gate bp->rsize = RPC_MSG_SZ; 38467c478bd9Sstevel@tonic-gate break; 38477c478bd9Sstevel@tonic-gate case RECV_BUFFER: 38487c478bd9Sstevel@tonic-gate mem_attr.mr_flags = IBT_MR_SLEEP | IBT_MR_ENABLE_LOCAL_WRITE; 38497c478bd9Sstevel@tonic-gate bp->rsize = RPC_BUF_SIZE; 38507c478bd9Sstevel@tonic-gate break; 38517c478bd9Sstevel@tonic-gate default: 38527c478bd9Sstevel@tonic-gate goto fail; 38537c478bd9Sstevel@tonic-gate } 38547c478bd9Sstevel@tonic-gate 38557c478bd9Sstevel@tonic-gate /* 38567c478bd9Sstevel@tonic-gate * Register the pool. 38577c478bd9Sstevel@tonic-gate */ 38587c478bd9Sstevel@tonic-gate bp->bufsize = num * bp->rsize; 38597c478bd9Sstevel@tonic-gate bp->buf = kmem_zalloc(bp->bufsize, KM_SLEEP); 38607c478bd9Sstevel@tonic-gate rbp->mr_hdl = (ibt_mr_hdl_t *)kmem_zalloc(num * 38617c478bd9Sstevel@tonic-gate sizeof (ibt_mr_hdl_t), KM_SLEEP); 38627c478bd9Sstevel@tonic-gate rbp->mr_desc = (ibt_mr_desc_t *)kmem_zalloc(num * 38637c478bd9Sstevel@tonic-gate sizeof (ibt_mr_desc_t), KM_SLEEP); 38647c478bd9Sstevel@tonic-gate rw_enter(&hca->state_lock, RW_READER); 38650a701b1eSRobert Gordon 38667f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca->state == HCA_DETACHED) { 38677c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 38687c478bd9Sstevel@tonic-gate goto fail; 38697c478bd9Sstevel@tonic-gate } 38700a701b1eSRobert Gordon 38717c478bd9Sstevel@tonic-gate for (i = 0, buf = bp->buf; i < num; i++, buf += bp->rsize) { 38727c478bd9Sstevel@tonic-gate bzero(&rbp->mr_desc[i], sizeof (ibt_mr_desc_t)); 387311606941Sjwahlig mem_attr.mr_vaddr = (uintptr_t)buf; 38747c478bd9Sstevel@tonic-gate mem_attr.mr_len = (ib_msglen_t)bp->rsize; 38757c478bd9Sstevel@tonic-gate mem_attr.mr_as = NULL; 38767c478bd9Sstevel@tonic-gate ibt_status = ibt_register_mr(hca->hca_hdl, 38770a701b1eSRobert Gordon hca->pd_hdl, &mem_attr, 38780a701b1eSRobert Gordon &rbp->mr_hdl[i], 38797c478bd9Sstevel@tonic-gate &rbp->mr_desc[i]); 38807c478bd9Sstevel@tonic-gate if (ibt_status != IBT_SUCCESS) { 38817c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 38820a701b1eSRobert Gordon (void) ibt_deregister_mr(hca->hca_hdl, 38830a701b1eSRobert Gordon rbp->mr_hdl[j]); 38847c478bd9Sstevel@tonic-gate } 38857c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 38867c478bd9Sstevel@tonic-gate goto fail; 38877c478bd9Sstevel@tonic-gate } 38887c478bd9Sstevel@tonic-gate } 38897c478bd9Sstevel@tonic-gate rw_exit(&hca->state_lock); 38907c478bd9Sstevel@tonic-gate buf = (caddr_t)bp->buf; 38917c478bd9Sstevel@tonic-gate for (i = 0; i < num; i++, buf += bp->rsize) { 38927c478bd9Sstevel@tonic-gate bp->buflist[i] = (void *)buf; 38937c478bd9Sstevel@tonic-gate } 38947c478bd9Sstevel@tonic-gate bp->buffree = num - 1; /* no. of free buffers */ 38957c478bd9Sstevel@tonic-gate rbp->bpool = bp; 38967c478bd9Sstevel@tonic-gate 38977c478bd9Sstevel@tonic-gate return (rbp); 38987c478bd9Sstevel@tonic-gate fail: 38997c478bd9Sstevel@tonic-gate if (bp) { 39007c478bd9Sstevel@tonic-gate if (bp->buf) 39017c478bd9Sstevel@tonic-gate kmem_free(bp->buf, bp->bufsize); 39027c478bd9Sstevel@tonic-gate kmem_free(bp, sizeof (bufpool_t) + num*sizeof (void *)); 39037c478bd9Sstevel@tonic-gate } 39047c478bd9Sstevel@tonic-gate if (rbp) { 39057c478bd9Sstevel@tonic-gate if (rbp->mr_hdl) 39067c478bd9Sstevel@tonic-gate kmem_free(rbp->mr_hdl, num*sizeof (ibt_mr_hdl_t)); 39077c478bd9Sstevel@tonic-gate if (rbp->mr_desc) 39087c478bd9Sstevel@tonic-gate kmem_free(rbp->mr_desc, num*sizeof (ibt_mr_desc_t)); 39097c478bd9Sstevel@tonic-gate kmem_free(rbp, sizeof (rib_bufpool_t)); 39107c478bd9Sstevel@tonic-gate } 39117c478bd9Sstevel@tonic-gate return (NULL); 39127c478bd9Sstevel@tonic-gate } 39137c478bd9Sstevel@tonic-gate 39147c478bd9Sstevel@tonic-gate static void 39157c478bd9Sstevel@tonic-gate rib_rbufpool_deregister(rib_hca_t *hca, int ptype) 39167c478bd9Sstevel@tonic-gate { 39177c478bd9Sstevel@tonic-gate int i; 39187c478bd9Sstevel@tonic-gate rib_bufpool_t *rbp = NULL; 39197c478bd9Sstevel@tonic-gate bufpool_t *bp; 39207c478bd9Sstevel@tonic-gate 39217c478bd9Sstevel@tonic-gate /* 39227c478bd9Sstevel@tonic-gate * Obtain pool address based on type of pool 39237c478bd9Sstevel@tonic-gate */ 39247c478bd9Sstevel@tonic-gate switch (ptype) { 39257c478bd9Sstevel@tonic-gate case SEND_BUFFER: 39267c478bd9Sstevel@tonic-gate rbp = hca->send_pool; 39277c478bd9Sstevel@tonic-gate break; 39287c478bd9Sstevel@tonic-gate case RECV_BUFFER: 39297c478bd9Sstevel@tonic-gate rbp = hca->recv_pool; 39307c478bd9Sstevel@tonic-gate break; 39317c478bd9Sstevel@tonic-gate default: 39327c478bd9Sstevel@tonic-gate return; 39337c478bd9Sstevel@tonic-gate } 39347c478bd9Sstevel@tonic-gate if (rbp == NULL) 39357c478bd9Sstevel@tonic-gate return; 39367c478bd9Sstevel@tonic-gate 39377c478bd9Sstevel@tonic-gate bp = rbp->bpool; 39387c478bd9Sstevel@tonic-gate 39397c478bd9Sstevel@tonic-gate /* 39407c478bd9Sstevel@tonic-gate * Deregister the pool memory and free it. 39417c478bd9Sstevel@tonic-gate */ 39427c478bd9Sstevel@tonic-gate for (i = 0; i < bp->numelems; i++) { 39437c478bd9Sstevel@tonic-gate (void) ibt_deregister_mr(hca->hca_hdl, rbp->mr_hdl[i]); 39447c478bd9Sstevel@tonic-gate } 39457c478bd9Sstevel@tonic-gate } 39467c478bd9Sstevel@tonic-gate 39477c478bd9Sstevel@tonic-gate static void 39487c478bd9Sstevel@tonic-gate rib_rbufpool_free(rib_hca_t *hca, int ptype) 39497c478bd9Sstevel@tonic-gate { 39507c478bd9Sstevel@tonic-gate 39517c478bd9Sstevel@tonic-gate rib_bufpool_t *rbp = NULL; 39527c478bd9Sstevel@tonic-gate bufpool_t *bp; 39537c478bd9Sstevel@tonic-gate 39547c478bd9Sstevel@tonic-gate /* 39557c478bd9Sstevel@tonic-gate * Obtain pool address based on type of pool 39567c478bd9Sstevel@tonic-gate */ 39577c478bd9Sstevel@tonic-gate switch (ptype) { 39587c478bd9Sstevel@tonic-gate case SEND_BUFFER: 39597c478bd9Sstevel@tonic-gate rbp = hca->send_pool; 39607c478bd9Sstevel@tonic-gate break; 39617c478bd9Sstevel@tonic-gate case RECV_BUFFER: 39627c478bd9Sstevel@tonic-gate rbp = hca->recv_pool; 39637c478bd9Sstevel@tonic-gate break; 39647c478bd9Sstevel@tonic-gate default: 39657c478bd9Sstevel@tonic-gate return; 39667c478bd9Sstevel@tonic-gate } 39677c478bd9Sstevel@tonic-gate if (rbp == NULL) 39687c478bd9Sstevel@tonic-gate return; 39697c478bd9Sstevel@tonic-gate 39707c478bd9Sstevel@tonic-gate bp = rbp->bpool; 39717c478bd9Sstevel@tonic-gate 39727c478bd9Sstevel@tonic-gate /* 39737c478bd9Sstevel@tonic-gate * Free the pool memory. 39747c478bd9Sstevel@tonic-gate */ 39757c478bd9Sstevel@tonic-gate if (rbp->mr_hdl) 39767c478bd9Sstevel@tonic-gate kmem_free(rbp->mr_hdl, bp->numelems*sizeof (ibt_mr_hdl_t)); 39777c478bd9Sstevel@tonic-gate 39787c478bd9Sstevel@tonic-gate if (rbp->mr_desc) 39797c478bd9Sstevel@tonic-gate kmem_free(rbp->mr_desc, bp->numelems*sizeof (ibt_mr_desc_t)); 39807c478bd9Sstevel@tonic-gate if (bp->buf) 39817c478bd9Sstevel@tonic-gate kmem_free(bp->buf, bp->bufsize); 39827c478bd9Sstevel@tonic-gate mutex_destroy(&bp->buflock); 39837c478bd9Sstevel@tonic-gate kmem_free(bp, sizeof (bufpool_t) + bp->numelems*sizeof (void *)); 39847c478bd9Sstevel@tonic-gate kmem_free(rbp, sizeof (rib_bufpool_t)); 39857c478bd9Sstevel@tonic-gate } 39867c478bd9Sstevel@tonic-gate 39877c478bd9Sstevel@tonic-gate void 39887c478bd9Sstevel@tonic-gate rib_rbufpool_destroy(rib_hca_t *hca, int ptype) 39897c478bd9Sstevel@tonic-gate { 39907c478bd9Sstevel@tonic-gate /* 39917c478bd9Sstevel@tonic-gate * Deregister the pool memory and free it. 39927c478bd9Sstevel@tonic-gate */ 39937c478bd9Sstevel@tonic-gate rib_rbufpool_deregister(hca, ptype); 39947c478bd9Sstevel@tonic-gate rib_rbufpool_free(hca, ptype); 39957c478bd9Sstevel@tonic-gate } 39967c478bd9Sstevel@tonic-gate 39977c478bd9Sstevel@tonic-gate /* 39987c478bd9Sstevel@tonic-gate * Fetch a buffer from the pool of type specified in rdbuf->type. 39997c478bd9Sstevel@tonic-gate */ 40007c478bd9Sstevel@tonic-gate static rdma_stat 40017c478bd9Sstevel@tonic-gate rib_reg_buf_alloc(CONN *conn, rdma_buf_t *rdbuf) 40027c478bd9Sstevel@tonic-gate { 40030a701b1eSRobert Gordon rib_lrc_entry_t *rlep; 40040a701b1eSRobert Gordon 40050a701b1eSRobert Gordon if (rdbuf->type == RDMA_LONG_BUFFER) { 40060a701b1eSRobert Gordon rlep = rib_get_cache_buf(conn, rdbuf->len); 40070a701b1eSRobert Gordon rdbuf->rb_private = (caddr_t)rlep; 40080a701b1eSRobert Gordon rdbuf->addr = rlep->lrc_buf; 40090a701b1eSRobert Gordon rdbuf->handle = rlep->lrc_mhandle; 40100a701b1eSRobert Gordon return (RDMA_SUCCESS); 40110a701b1eSRobert Gordon } 40127c478bd9Sstevel@tonic-gate 40137c478bd9Sstevel@tonic-gate rdbuf->addr = rib_rbuf_alloc(conn, rdbuf); 40147c478bd9Sstevel@tonic-gate if (rdbuf->addr) { 40157c478bd9Sstevel@tonic-gate switch (rdbuf->type) { 40167c478bd9Sstevel@tonic-gate case SEND_BUFFER: 40177c478bd9Sstevel@tonic-gate rdbuf->len = RPC_MSG_SZ; /* 1K */ 40187c478bd9Sstevel@tonic-gate break; 40197c478bd9Sstevel@tonic-gate case RECV_BUFFER: 40207c478bd9Sstevel@tonic-gate rdbuf->len = RPC_BUF_SIZE; /* 2K */ 40217c478bd9Sstevel@tonic-gate break; 40227c478bd9Sstevel@tonic-gate default: 40237c478bd9Sstevel@tonic-gate rdbuf->len = 0; 40247c478bd9Sstevel@tonic-gate } 40257c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 40267c478bd9Sstevel@tonic-gate } else 40277c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 40287c478bd9Sstevel@tonic-gate } 40297c478bd9Sstevel@tonic-gate 40307c478bd9Sstevel@tonic-gate /* 40317c478bd9Sstevel@tonic-gate * Fetch a buffer of specified type. 40327c478bd9Sstevel@tonic-gate * Note that rdbuf->handle is mw's rkey. 40337c478bd9Sstevel@tonic-gate */ 40347c478bd9Sstevel@tonic-gate static void * 40357c478bd9Sstevel@tonic-gate rib_rbuf_alloc(CONN *conn, rdma_buf_t *rdbuf) 40367c478bd9Sstevel@tonic-gate { 40377c478bd9Sstevel@tonic-gate rib_qp_t *qp = ctoqp(conn); 40387c478bd9Sstevel@tonic-gate rib_hca_t *hca = qp->hca; 40397c478bd9Sstevel@tonic-gate rdma_btype ptype = rdbuf->type; 40407c478bd9Sstevel@tonic-gate void *buf; 40417c478bd9Sstevel@tonic-gate rib_bufpool_t *rbp = NULL; 40427c478bd9Sstevel@tonic-gate bufpool_t *bp; 40437c478bd9Sstevel@tonic-gate int i; 40447c478bd9Sstevel@tonic-gate 40457c478bd9Sstevel@tonic-gate /* 40467c478bd9Sstevel@tonic-gate * Obtain pool address based on type of pool 40477c478bd9Sstevel@tonic-gate */ 40487c478bd9Sstevel@tonic-gate switch (ptype) { 40497c478bd9Sstevel@tonic-gate case SEND_BUFFER: 40507c478bd9Sstevel@tonic-gate rbp = hca->send_pool; 40517c478bd9Sstevel@tonic-gate break; 40527c478bd9Sstevel@tonic-gate case RECV_BUFFER: 40537c478bd9Sstevel@tonic-gate rbp = hca->recv_pool; 40547c478bd9Sstevel@tonic-gate break; 40557c478bd9Sstevel@tonic-gate default: 40567c478bd9Sstevel@tonic-gate return (NULL); 40577c478bd9Sstevel@tonic-gate } 40587c478bd9Sstevel@tonic-gate if (rbp == NULL) 40597c478bd9Sstevel@tonic-gate return (NULL); 40607c478bd9Sstevel@tonic-gate 40617c478bd9Sstevel@tonic-gate bp = rbp->bpool; 40627c478bd9Sstevel@tonic-gate 40637c478bd9Sstevel@tonic-gate mutex_enter(&bp->buflock); 40647c478bd9Sstevel@tonic-gate if (bp->buffree < 0) { 40657c478bd9Sstevel@tonic-gate mutex_exit(&bp->buflock); 40667c478bd9Sstevel@tonic-gate return (NULL); 40677c478bd9Sstevel@tonic-gate } 40687c478bd9Sstevel@tonic-gate 40697c478bd9Sstevel@tonic-gate /* XXXX put buf, rdbuf->handle.mrc_rmr, ... in one place. */ 40707c478bd9Sstevel@tonic-gate buf = bp->buflist[bp->buffree]; 40717c478bd9Sstevel@tonic-gate rdbuf->addr = buf; 40727c478bd9Sstevel@tonic-gate rdbuf->len = bp->rsize; 40737c478bd9Sstevel@tonic-gate for (i = bp->numelems - 1; i >= 0; i--) { 407411606941Sjwahlig if ((ib_vaddr_t)(uintptr_t)buf == rbp->mr_desc[i].md_vaddr) { 40750a701b1eSRobert Gordon rdbuf->handle.mrc_rmr = 40760a701b1eSRobert Gordon (uint32_t)rbp->mr_desc[i].md_rkey; 40770a701b1eSRobert Gordon rdbuf->handle.mrc_linfo = 40780a701b1eSRobert Gordon (uintptr_t)rbp->mr_hdl[i]; 40790a701b1eSRobert Gordon rdbuf->handle.mrc_lmr = 40800a701b1eSRobert Gordon (uint32_t)rbp->mr_desc[i].md_lkey; 40817c478bd9Sstevel@tonic-gate bp->buffree--; 40827c478bd9Sstevel@tonic-gate 40837c478bd9Sstevel@tonic-gate mutex_exit(&bp->buflock); 40847c478bd9Sstevel@tonic-gate 40857c478bd9Sstevel@tonic-gate return (buf); 40867c478bd9Sstevel@tonic-gate } 40877c478bd9Sstevel@tonic-gate } 40880a701b1eSRobert Gordon 40897c478bd9Sstevel@tonic-gate mutex_exit(&bp->buflock); 40907c478bd9Sstevel@tonic-gate 40917c478bd9Sstevel@tonic-gate return (NULL); 40927c478bd9Sstevel@tonic-gate } 40937c478bd9Sstevel@tonic-gate 40947c478bd9Sstevel@tonic-gate static void 40957c478bd9Sstevel@tonic-gate rib_reg_buf_free(CONN *conn, rdma_buf_t *rdbuf) 40967c478bd9Sstevel@tonic-gate { 40977c478bd9Sstevel@tonic-gate 40980a701b1eSRobert Gordon if (rdbuf->type == RDMA_LONG_BUFFER) { 40990a701b1eSRobert Gordon rib_free_cache_buf(conn, (rib_lrc_entry_t *)rdbuf->rb_private); 41000a701b1eSRobert Gordon rdbuf->rb_private = NULL; 41010a701b1eSRobert Gordon return; 41020a701b1eSRobert Gordon } 41037c478bd9Sstevel@tonic-gate rib_rbuf_free(conn, rdbuf->type, rdbuf->addr); 41047c478bd9Sstevel@tonic-gate } 41057c478bd9Sstevel@tonic-gate 41067c478bd9Sstevel@tonic-gate static void 41077c478bd9Sstevel@tonic-gate rib_rbuf_free(CONN *conn, int ptype, void *buf) 41087c478bd9Sstevel@tonic-gate { 41097c478bd9Sstevel@tonic-gate rib_qp_t *qp = ctoqp(conn); 41107c478bd9Sstevel@tonic-gate rib_hca_t *hca = qp->hca; 41117c478bd9Sstevel@tonic-gate rib_bufpool_t *rbp = NULL; 41127c478bd9Sstevel@tonic-gate bufpool_t *bp; 41137c478bd9Sstevel@tonic-gate 41147c478bd9Sstevel@tonic-gate /* 41157c478bd9Sstevel@tonic-gate * Obtain pool address based on type of pool 41167c478bd9Sstevel@tonic-gate */ 41177c478bd9Sstevel@tonic-gate switch (ptype) { 41187c478bd9Sstevel@tonic-gate case SEND_BUFFER: 41197c478bd9Sstevel@tonic-gate rbp = hca->send_pool; 41207c478bd9Sstevel@tonic-gate break; 41217c478bd9Sstevel@tonic-gate case RECV_BUFFER: 41227c478bd9Sstevel@tonic-gate rbp = hca->recv_pool; 41237c478bd9Sstevel@tonic-gate break; 41247c478bd9Sstevel@tonic-gate default: 41257c478bd9Sstevel@tonic-gate return; 41267c478bd9Sstevel@tonic-gate } 41277c478bd9Sstevel@tonic-gate if (rbp == NULL) 41287c478bd9Sstevel@tonic-gate return; 41297c478bd9Sstevel@tonic-gate 41307c478bd9Sstevel@tonic-gate bp = rbp->bpool; 41317c478bd9Sstevel@tonic-gate 41327c478bd9Sstevel@tonic-gate mutex_enter(&bp->buflock); 41337c478bd9Sstevel@tonic-gate if (++bp->buffree >= bp->numelems) { 41347c478bd9Sstevel@tonic-gate /* 41357c478bd9Sstevel@tonic-gate * Should never happen 41367c478bd9Sstevel@tonic-gate */ 41377c478bd9Sstevel@tonic-gate bp->buffree--; 41387c478bd9Sstevel@tonic-gate } else { 41397c478bd9Sstevel@tonic-gate bp->buflist[bp->buffree] = buf; 41407c478bd9Sstevel@tonic-gate } 41417c478bd9Sstevel@tonic-gate mutex_exit(&bp->buflock); 41427c478bd9Sstevel@tonic-gate } 41437c478bd9Sstevel@tonic-gate 41447c478bd9Sstevel@tonic-gate static rdma_stat 41457c478bd9Sstevel@tonic-gate rib_add_connlist(CONN *cn, rib_conn_list_t *connlist) 41467c478bd9Sstevel@tonic-gate { 41477c478bd9Sstevel@tonic-gate rw_enter(&connlist->conn_lock, RW_WRITER); 41487c478bd9Sstevel@tonic-gate if (connlist->conn_hd) { 41497c478bd9Sstevel@tonic-gate cn->c_next = connlist->conn_hd; 41507c478bd9Sstevel@tonic-gate connlist->conn_hd->c_prev = cn; 41517c478bd9Sstevel@tonic-gate } 41527c478bd9Sstevel@tonic-gate connlist->conn_hd = cn; 41537c478bd9Sstevel@tonic-gate rw_exit(&connlist->conn_lock); 41547c478bd9Sstevel@tonic-gate 41557c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 41567c478bd9Sstevel@tonic-gate } 41577c478bd9Sstevel@tonic-gate 41587c478bd9Sstevel@tonic-gate static rdma_stat 41597c478bd9Sstevel@tonic-gate rib_rm_conn(CONN *cn, rib_conn_list_t *connlist) 41607c478bd9Sstevel@tonic-gate { 41617c478bd9Sstevel@tonic-gate rw_enter(&connlist->conn_lock, RW_WRITER); 41627c478bd9Sstevel@tonic-gate if (cn->c_prev) { 41637c478bd9Sstevel@tonic-gate cn->c_prev->c_next = cn->c_next; 41647c478bd9Sstevel@tonic-gate } 41657c478bd9Sstevel@tonic-gate if (cn->c_next) { 41667c478bd9Sstevel@tonic-gate cn->c_next->c_prev = cn->c_prev; 41677c478bd9Sstevel@tonic-gate } 41687c478bd9Sstevel@tonic-gate if (connlist->conn_hd == cn) 41697c478bd9Sstevel@tonic-gate connlist->conn_hd = cn->c_next; 41707c478bd9Sstevel@tonic-gate rw_exit(&connlist->conn_lock); 41717c478bd9Sstevel@tonic-gate 41727c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 41737c478bd9Sstevel@tonic-gate } 41747c478bd9Sstevel@tonic-gate 4175ed629aefSSiddheshwar Mahesh /* ARGSUSED */ 4176ed629aefSSiddheshwar Mahesh static rdma_stat 4177ed629aefSSiddheshwar Mahesh rib_conn_get(struct netbuf *s_svcaddr, struct netbuf *d_svcaddr, 4178ed629aefSSiddheshwar Mahesh int addr_type, void *handle, CONN **conn) 4179ed629aefSSiddheshwar Mahesh { 4180ed629aefSSiddheshwar Mahesh rdma_stat status; 4181ed629aefSSiddheshwar Mahesh rpcib_ping_t rpt; 4182ed629aefSSiddheshwar Mahesh 4183ed629aefSSiddheshwar Mahesh status = rib_connect(s_svcaddr, d_svcaddr, addr_type, &rpt, conn); 4184ed629aefSSiddheshwar Mahesh return (status); 4185ed629aefSSiddheshwar Mahesh } 4186ed629aefSSiddheshwar Mahesh 41877c478bd9Sstevel@tonic-gate /* 41887f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * rib_find_hca_connection 41897f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * 41907f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * if there is an existing connection to the specified address then 41917f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * it will be returned in conn, otherwise conn will be set to NULL. 41927f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Also cleans up any connection that is in error state. 41937c478bd9Sstevel@tonic-gate */ 41947f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static int 41957f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_find_hca_connection(rib_hca_t *hca, struct netbuf *s_svcaddr, 41967f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States struct netbuf *d_svcaddr, CONN **conn) 41977c478bd9Sstevel@tonic-gate { 41987c478bd9Sstevel@tonic-gate CONN *cn; 41997c478bd9Sstevel@tonic-gate clock_t cv_stat, timout; 42007c478bd9Sstevel@tonic-gate 42017f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States *conn = NULL; 42027c478bd9Sstevel@tonic-gate again: 42037c478bd9Sstevel@tonic-gate rw_enter(&hca->cl_conn_list.conn_lock, RW_READER); 42047c478bd9Sstevel@tonic-gate cn = hca->cl_conn_list.conn_hd; 42057c478bd9Sstevel@tonic-gate while (cn != NULL) { 42067c478bd9Sstevel@tonic-gate /* 42077c478bd9Sstevel@tonic-gate * First, clear up any connection in the ERROR state 42087c478bd9Sstevel@tonic-gate */ 42097c478bd9Sstevel@tonic-gate mutex_enter(&cn->c_lock); 42100a701b1eSRobert Gordon if (cn->c_state == C_ERROR_CONN) { 42117c478bd9Sstevel@tonic-gate if (cn->c_ref == 0) { 42127c478bd9Sstevel@tonic-gate /* 42137c478bd9Sstevel@tonic-gate * Remove connection from list and destroy it. 42147c478bd9Sstevel@tonic-gate */ 42157c478bd9Sstevel@tonic-gate cn->c_state = C_DISCONN_PEND; 42167c478bd9Sstevel@tonic-gate mutex_exit(&cn->c_lock); 42177c478bd9Sstevel@tonic-gate rw_exit(&hca->cl_conn_list.conn_lock); 4218065714dcSSiddheshwar Mahesh rib_conn_close((void *)cn); 42197c478bd9Sstevel@tonic-gate goto again; 42207c478bd9Sstevel@tonic-gate } 42217c478bd9Sstevel@tonic-gate mutex_exit(&cn->c_lock); 42227c478bd9Sstevel@tonic-gate cn = cn->c_next; 42237c478bd9Sstevel@tonic-gate continue; 42240a701b1eSRobert Gordon } 42250a701b1eSRobert Gordon if (cn->c_state == C_DISCONN_PEND) { 42267c478bd9Sstevel@tonic-gate mutex_exit(&cn->c_lock); 42277c478bd9Sstevel@tonic-gate cn = cn->c_next; 42287c478bd9Sstevel@tonic-gate continue; 42297c478bd9Sstevel@tonic-gate } 42307f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 42317f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 42327f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * source address is only checked for if there is one, 42337f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * this is the case for retries. 42347f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 42357f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if ((cn->c_raddr.len == d_svcaddr->len) && 42367f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (bcmp(d_svcaddr->buf, cn->c_raddr.buf, 42377f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States d_svcaddr->len) == 0) && 42387f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ((s_svcaddr->len == 0) || 42397f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ((cn->c_laddr.len == s_svcaddr->len) && 42407f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (bcmp(s_svcaddr->buf, cn->c_laddr.buf, 42417f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States s_svcaddr->len) == 0)))) { 42427c478bd9Sstevel@tonic-gate /* 42437c478bd9Sstevel@tonic-gate * Our connection. Give up conn list lock 42447c478bd9Sstevel@tonic-gate * as we are done traversing the list. 42457c478bd9Sstevel@tonic-gate */ 42467c478bd9Sstevel@tonic-gate rw_exit(&hca->cl_conn_list.conn_lock); 42477c478bd9Sstevel@tonic-gate if (cn->c_state == C_CONNECTED) { 42487c478bd9Sstevel@tonic-gate cn->c_ref++; /* sharing a conn */ 42497c478bd9Sstevel@tonic-gate mutex_exit(&cn->c_lock); 42507c478bd9Sstevel@tonic-gate *conn = cn; 42517f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (RDMA_SUCCESS); 42527c478bd9Sstevel@tonic-gate } 42537c478bd9Sstevel@tonic-gate if (cn->c_state == C_CONN_PEND) { 42547c478bd9Sstevel@tonic-gate /* 42557c478bd9Sstevel@tonic-gate * Hold a reference to this conn before 42567c478bd9Sstevel@tonic-gate * we give up the lock. 42577c478bd9Sstevel@tonic-gate */ 42587c478bd9Sstevel@tonic-gate cn->c_ref++; 42597c478bd9Sstevel@tonic-gate timout = ddi_get_lbolt() + 42607c478bd9Sstevel@tonic-gate drv_usectohz(CONN_WAIT_TIME * 1000000); 42617c478bd9Sstevel@tonic-gate while ((cv_stat = cv_timedwait_sig(&cn->c_cv, 42627c478bd9Sstevel@tonic-gate &cn->c_lock, timout)) > 0 && 42637c478bd9Sstevel@tonic-gate cn->c_state == C_CONN_PEND) 42647c478bd9Sstevel@tonic-gate ; 42657c478bd9Sstevel@tonic-gate if (cv_stat == 0) { 42667c478bd9Sstevel@tonic-gate cn->c_ref--; 42677c478bd9Sstevel@tonic-gate mutex_exit(&cn->c_lock); 42687c478bd9Sstevel@tonic-gate return (RDMA_INTR); 42697c478bd9Sstevel@tonic-gate } 42707c478bd9Sstevel@tonic-gate if (cv_stat < 0) { 42717c478bd9Sstevel@tonic-gate cn->c_ref--; 42727c478bd9Sstevel@tonic-gate mutex_exit(&cn->c_lock); 42737c478bd9Sstevel@tonic-gate return (RDMA_TIMEDOUT); 42747c478bd9Sstevel@tonic-gate } 42757c478bd9Sstevel@tonic-gate if (cn->c_state == C_CONNECTED) { 42767c478bd9Sstevel@tonic-gate *conn = cn; 42777c478bd9Sstevel@tonic-gate mutex_exit(&cn->c_lock); 42787f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (RDMA_SUCCESS); 42797c478bd9Sstevel@tonic-gate } else { 42807c478bd9Sstevel@tonic-gate cn->c_ref--; 42817c478bd9Sstevel@tonic-gate mutex_exit(&cn->c_lock); 42827c478bd9Sstevel@tonic-gate return (RDMA_TIMEDOUT); 42837c478bd9Sstevel@tonic-gate } 42847c478bd9Sstevel@tonic-gate } 42857c478bd9Sstevel@tonic-gate } 42867c478bd9Sstevel@tonic-gate mutex_exit(&cn->c_lock); 42877c478bd9Sstevel@tonic-gate cn = cn->c_next; 42887c478bd9Sstevel@tonic-gate } 42897c478bd9Sstevel@tonic-gate rw_exit(&hca->cl_conn_list.conn_lock); 42907f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States *conn = NULL; 42917c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 42927c478bd9Sstevel@tonic-gate } 42937c478bd9Sstevel@tonic-gate 42947c478bd9Sstevel@tonic-gate /* 42957f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Connection management. 42967f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * IBTF does not support recycling of channels. So connections are only 42977f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * in four states - C_CONN_PEND, or C_CONNECTED, or C_ERROR_CONN or 42987f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * C_DISCONN_PEND state. No C_IDLE state. 42997f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * C_CONN_PEND state: Connection establishment in progress to the server. 43007f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * C_CONNECTED state: A connection when created is in C_CONNECTED state. 43017f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * It has an RC channel associated with it. ibt_post_send/recv are allowed 43027f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * only in this state. 43037f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * C_ERROR_CONN state: A connection transitions to this state when WRs on the 43047f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * channel are completed in error or an IBT_CM_EVENT_CONN_CLOSED event 43057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * happens on the channel or a IBT_HCA_DETACH_EVENT occurs on the HCA. 43067f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * C_DISCONN_PEND state: When a connection is in C_ERROR_CONN state and when 43077f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * c_ref drops to 0 (this indicates that RPC has no more references to this 43087f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * connection), the connection should be destroyed. A connection transitions 43097f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * into this state when it is being destroyed. 43107f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 43117f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* ARGSUSED */ 43127f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static rdma_stat 4313ed629aefSSiddheshwar Mahesh rib_connect(struct netbuf *s_svcaddr, struct netbuf *d_svcaddr, 4314ed629aefSSiddheshwar Mahesh int addr_type, rpcib_ping_t *rpt, CONN **conn) 43157f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States { 43167f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States CONN *cn; 43177f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States int status; 43187f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_hca_t *hca; 43197f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_qp_t *qp; 43207f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States int s_addr_len; 43217f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States char *s_addr_buf; 43227f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 43237f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&rib_stat->hcas_list_lock, RW_READER); 43247f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States for (hca = rib_stat->hcas_list; hca; hca = hca->next) { 43257f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&hca->state_lock, RW_READER); 43267f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca->state != HCA_DETACHED) { 43277f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States status = rib_find_hca_connection(hca, s_svcaddr, 43287f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States d_svcaddr, conn); 43297f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 43307f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if ((status == RDMA_INTR) || (status == RDMA_SUCCESS)) { 43317f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->hcas_list_lock); 43327f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (status); 43337f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 43347f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } else 43357f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 43367f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 43377f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->hcas_list_lock); 43387f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 43397f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 43407f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * No existing connection found, establish a new connection. 43417f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 4342ed629aefSSiddheshwar Mahesh bzero(rpt, sizeof (rpcib_ping_t)); 43437f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 4344ed629aefSSiddheshwar Mahesh status = rib_ping_srv(addr_type, d_svcaddr, rpt); 43457f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (status != RDMA_SUCCESS) { 43467f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (RDMA_FAILED); 43477f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 4348ed629aefSSiddheshwar Mahesh hca = rpt->hca; 43497f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 4350ed629aefSSiddheshwar Mahesh if (rpt->srcip.family == AF_INET) { 4351ed629aefSSiddheshwar Mahesh s_addr_len = sizeof (rpt->srcip.un.ip4addr); 4352ed629aefSSiddheshwar Mahesh s_addr_buf = (char *)&rpt->srcip.un.ip4addr; 4353ed629aefSSiddheshwar Mahesh } else if (rpt->srcip.family == AF_INET6) { 4354ed629aefSSiddheshwar Mahesh s_addr_len = sizeof (rpt->srcip.un.ip6addr); 4355ed629aefSSiddheshwar Mahesh s_addr_buf = (char *)&rpt->srcip.un.ip6addr; 4356ed629aefSSiddheshwar Mahesh } else { 43577f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return (RDMA_FAILED); 4358ed629aefSSiddheshwar Mahesh } 43597f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 43607f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 43617c478bd9Sstevel@tonic-gate * Channel to server doesn't exist yet, create one. 43627c478bd9Sstevel@tonic-gate */ 43637f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (rib_clnt_create_chan(hca, d_svcaddr, &qp) != RDMA_SUCCESS) { 43647c478bd9Sstevel@tonic-gate return (RDMA_FAILED); 43657c478bd9Sstevel@tonic-gate } 43667c478bd9Sstevel@tonic-gate cn = qptoc(qp); 43677c478bd9Sstevel@tonic-gate cn->c_state = C_CONN_PEND; 43687c478bd9Sstevel@tonic-gate cn->c_ref = 1; 43697c478bd9Sstevel@tonic-gate 43707f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States cn->c_laddr.buf = kmem_alloc(s_addr_len, KM_SLEEP); 43717f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States bcopy(s_addr_buf, cn->c_laddr.buf, s_addr_len); 43727f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States cn->c_laddr.len = cn->c_laddr.maxlen = s_addr_len; 43737f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 4374*7523bef8SSiddheshwar Mahesh if (rpt->srcip.family == AF_INET) { 4375*7523bef8SSiddheshwar Mahesh cn->c_netid = kmem_zalloc(strlen(RIBNETID_TCP) + 1, KM_SLEEP); 4376*7523bef8SSiddheshwar Mahesh (void) strcpy(cn->c_netid, RIBNETID_TCP); 4377*7523bef8SSiddheshwar Mahesh } else { 4378*7523bef8SSiddheshwar Mahesh cn->c_netid = kmem_zalloc(strlen(RIBNETID_TCP6) + 1, KM_SLEEP); 4379*7523bef8SSiddheshwar Mahesh (void) strcpy(cn->c_netid, RIBNETID_TCP6); 4380*7523bef8SSiddheshwar Mahesh } 4381*7523bef8SSiddheshwar Mahesh 43827c478bd9Sstevel@tonic-gate /* 43837c478bd9Sstevel@tonic-gate * Add to conn list. 43847c478bd9Sstevel@tonic-gate * We had given up the READER lock. In the time since then, 43857c478bd9Sstevel@tonic-gate * another thread might have created the connection we are 43867c478bd9Sstevel@tonic-gate * trying here. But for now, that is quiet alright - there 43877c478bd9Sstevel@tonic-gate * might be two connections between a pair of hosts instead 43887c478bd9Sstevel@tonic-gate * of one. If we really want to close that window, 43897c478bd9Sstevel@tonic-gate * then need to check the list after acquiring the 43907c478bd9Sstevel@tonic-gate * WRITER lock. 43917c478bd9Sstevel@tonic-gate */ 43927c478bd9Sstevel@tonic-gate (void) rib_add_connlist(cn, &hca->cl_conn_list); 4393ed629aefSSiddheshwar Mahesh status = rib_conn_to_srv(hca, qp, rpt); 43947c478bd9Sstevel@tonic-gate mutex_enter(&cn->c_lock); 43957c478bd9Sstevel@tonic-gate if (status == RDMA_SUCCESS) { 43967c478bd9Sstevel@tonic-gate cn->c_state = C_CONNECTED; 43977c478bd9Sstevel@tonic-gate *conn = cn; 43987c478bd9Sstevel@tonic-gate } else { 43990a701b1eSRobert Gordon cn->c_state = C_ERROR_CONN; 44007c478bd9Sstevel@tonic-gate cn->c_ref--; 44017c478bd9Sstevel@tonic-gate } 44027c478bd9Sstevel@tonic-gate cv_broadcast(&cn->c_cv); 44037c478bd9Sstevel@tonic-gate mutex_exit(&cn->c_lock); 44047c478bd9Sstevel@tonic-gate return (status); 44057c478bd9Sstevel@tonic-gate } 44067c478bd9Sstevel@tonic-gate 4407065714dcSSiddheshwar Mahesh static void 4408065714dcSSiddheshwar Mahesh rib_conn_close(void *rarg) 44097c478bd9Sstevel@tonic-gate { 4410065714dcSSiddheshwar Mahesh CONN *conn = (CONN *)rarg; 44117c478bd9Sstevel@tonic-gate rib_qp_t *qp = ctoqp(conn); 44127c478bd9Sstevel@tonic-gate 44137c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 4414065714dcSSiddheshwar Mahesh if (!(conn->c_flags & C_CLOSE_NOTNEEDED)) { 44157c478bd9Sstevel@tonic-gate 4416065714dcSSiddheshwar Mahesh conn->c_flags |= (C_CLOSE_NOTNEEDED | C_CLOSE_PENDING); 44177c478bd9Sstevel@tonic-gate /* 4418065714dcSSiddheshwar Mahesh * Live connection in CONNECTED state. 44197c478bd9Sstevel@tonic-gate */ 4420065714dcSSiddheshwar Mahesh if (conn->c_state == C_CONNECTED) { 4421065714dcSSiddheshwar Mahesh conn->c_state = C_ERROR_CONN; 4422065714dcSSiddheshwar Mahesh } 44237c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 4424065714dcSSiddheshwar Mahesh 4425065714dcSSiddheshwar Mahesh rib_close_a_channel(conn); 4426065714dcSSiddheshwar Mahesh 4427065714dcSSiddheshwar Mahesh mutex_enter(&conn->c_lock); 4428065714dcSSiddheshwar Mahesh conn->c_flags &= ~C_CLOSE_PENDING; 4429065714dcSSiddheshwar Mahesh cv_signal(&conn->c_cv); 4430065714dcSSiddheshwar Mahesh } 4431065714dcSSiddheshwar Mahesh 4432065714dcSSiddheshwar Mahesh mutex_exit(&conn->c_lock); 4433065714dcSSiddheshwar Mahesh 44347c478bd9Sstevel@tonic-gate if (qp->mode == RIB_SERVER) 44357c478bd9Sstevel@tonic-gate (void) rib_disconnect_channel(conn, 44367c478bd9Sstevel@tonic-gate &qp->hca->srv_conn_list); 44377c478bd9Sstevel@tonic-gate else 44387c478bd9Sstevel@tonic-gate (void) rib_disconnect_channel(conn, 44397c478bd9Sstevel@tonic-gate &qp->hca->cl_conn_list); 4440065714dcSSiddheshwar Mahesh } 4441065714dcSSiddheshwar Mahesh 4442065714dcSSiddheshwar Mahesh static void 4443065714dcSSiddheshwar Mahesh rib_conn_timeout_call(void *carg) 4444065714dcSSiddheshwar Mahesh { 4445065714dcSSiddheshwar Mahesh time_t idle_time; 4446065714dcSSiddheshwar Mahesh CONN *conn = (CONN *)carg; 4447065714dcSSiddheshwar Mahesh rib_hca_t *hca = ctoqp(conn)->hca; 4448065714dcSSiddheshwar Mahesh int error; 4449065714dcSSiddheshwar Mahesh 4450065714dcSSiddheshwar Mahesh mutex_enter(&conn->c_lock); 4451065714dcSSiddheshwar Mahesh if ((conn->c_ref > 0) || 4452065714dcSSiddheshwar Mahesh (conn->c_state == C_DISCONN_PEND)) { 4453065714dcSSiddheshwar Mahesh conn->c_timeout = NULL; 4454065714dcSSiddheshwar Mahesh mutex_exit(&conn->c_lock); 4455065714dcSSiddheshwar Mahesh return; 4456065714dcSSiddheshwar Mahesh } 4457065714dcSSiddheshwar Mahesh 4458065714dcSSiddheshwar Mahesh idle_time = (gethrestime_sec() - conn->c_last_used); 4459065714dcSSiddheshwar Mahesh 4460065714dcSSiddheshwar Mahesh if ((idle_time <= rib_conn_timeout) && 4461065714dcSSiddheshwar Mahesh (conn->c_state != C_ERROR_CONN)) { 4462065714dcSSiddheshwar Mahesh /* 4463065714dcSSiddheshwar Mahesh * There was activity after the last timeout. 4464065714dcSSiddheshwar Mahesh * Extend the conn life. Unless the conn is 4465065714dcSSiddheshwar Mahesh * already in error state. 4466065714dcSSiddheshwar Mahesh */ 4467065714dcSSiddheshwar Mahesh conn->c_timeout = timeout(rib_conn_timeout_call, conn, 4468065714dcSSiddheshwar Mahesh SEC_TO_TICK(rib_conn_timeout - idle_time)); 4469065714dcSSiddheshwar Mahesh mutex_exit(&conn->c_lock); 4470065714dcSSiddheshwar Mahesh return; 4471065714dcSSiddheshwar Mahesh } 4472065714dcSSiddheshwar Mahesh 4473065714dcSSiddheshwar Mahesh error = ddi_taskq_dispatch(hca->cleanup_helper, rib_conn_close, 4474065714dcSSiddheshwar Mahesh (void *)conn, DDI_NOSLEEP); 4475065714dcSSiddheshwar Mahesh 4476065714dcSSiddheshwar Mahesh /* 4477065714dcSSiddheshwar Mahesh * If taskq dispatch fails above, then reset the timeout 4478065714dcSSiddheshwar Mahesh * to try again after 10 secs. 4479065714dcSSiddheshwar Mahesh */ 4480065714dcSSiddheshwar Mahesh 4481065714dcSSiddheshwar Mahesh if (error != DDI_SUCCESS) { 4482065714dcSSiddheshwar Mahesh conn->c_timeout = timeout(rib_conn_timeout_call, conn, 4483065714dcSSiddheshwar Mahesh SEC_TO_TICK(RDMA_CONN_REAP_RETRY)); 4484065714dcSSiddheshwar Mahesh mutex_exit(&conn->c_lock); 4485065714dcSSiddheshwar Mahesh return; 4486065714dcSSiddheshwar Mahesh } 4487065714dcSSiddheshwar Mahesh 4488065714dcSSiddheshwar Mahesh conn->c_state = C_DISCONN_PEND; 4489065714dcSSiddheshwar Mahesh mutex_exit(&conn->c_lock); 4490065714dcSSiddheshwar Mahesh } 4491065714dcSSiddheshwar Mahesh 4492065714dcSSiddheshwar Mahesh static rdma_stat 4493065714dcSSiddheshwar Mahesh rib_conn_release(CONN *conn) 4494065714dcSSiddheshwar Mahesh { 4495065714dcSSiddheshwar Mahesh 4496065714dcSSiddheshwar Mahesh mutex_enter(&conn->c_lock); 4497065714dcSSiddheshwar Mahesh conn->c_ref--; 4498065714dcSSiddheshwar Mahesh 4499065714dcSSiddheshwar Mahesh conn->c_last_used = gethrestime_sec(); 4500065714dcSSiddheshwar Mahesh if (conn->c_ref > 0) { 4501065714dcSSiddheshwar Mahesh mutex_exit(&conn->c_lock); 45027c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 45037c478bd9Sstevel@tonic-gate } 4504065714dcSSiddheshwar Mahesh 4505065714dcSSiddheshwar Mahesh /* 4506065714dcSSiddheshwar Mahesh * If a conn is C_ERROR_CONN, close the channel. 4507065714dcSSiddheshwar Mahesh */ 4508065714dcSSiddheshwar Mahesh if (conn->c_ref == 0 && conn->c_state == C_ERROR_CONN) { 4509065714dcSSiddheshwar Mahesh conn->c_state = C_DISCONN_PEND; 4510065714dcSSiddheshwar Mahesh mutex_exit(&conn->c_lock); 4511065714dcSSiddheshwar Mahesh rib_conn_close((void *)conn); 4512065714dcSSiddheshwar Mahesh return (RDMA_SUCCESS); 4513065714dcSSiddheshwar Mahesh } 4514065714dcSSiddheshwar Mahesh 4515065714dcSSiddheshwar Mahesh /* 4516065714dcSSiddheshwar Mahesh * c_ref == 0, set a timeout for conn release 4517065714dcSSiddheshwar Mahesh */ 4518065714dcSSiddheshwar Mahesh 4519065714dcSSiddheshwar Mahesh if (conn->c_timeout == NULL) { 4520065714dcSSiddheshwar Mahesh conn->c_timeout = timeout(rib_conn_timeout_call, conn, 4521065714dcSSiddheshwar Mahesh SEC_TO_TICK(rib_conn_timeout)); 4522065714dcSSiddheshwar Mahesh } 4523065714dcSSiddheshwar Mahesh 45247c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 45257c478bd9Sstevel@tonic-gate return (RDMA_SUCCESS); 45267c478bd9Sstevel@tonic-gate } 45277c478bd9Sstevel@tonic-gate 45287c478bd9Sstevel@tonic-gate /* 45297c478bd9Sstevel@tonic-gate * Add at front of list 45307c478bd9Sstevel@tonic-gate */ 45317c478bd9Sstevel@tonic-gate static struct rdma_done_list * 45327c478bd9Sstevel@tonic-gate rdma_done_add(rib_qp_t *qp, uint32_t xid) 45337c478bd9Sstevel@tonic-gate { 45347c478bd9Sstevel@tonic-gate struct rdma_done_list *rd; 45357c478bd9Sstevel@tonic-gate 45367c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&qp->rdlist_lock)); 45377c478bd9Sstevel@tonic-gate 45387c478bd9Sstevel@tonic-gate rd = kmem_alloc(sizeof (*rd), KM_SLEEP); 45397c478bd9Sstevel@tonic-gate rd->xid = xid; 45407c478bd9Sstevel@tonic-gate cv_init(&rd->rdma_done_cv, NULL, CV_DEFAULT, NULL); 45417c478bd9Sstevel@tonic-gate 45427c478bd9Sstevel@tonic-gate rd->prev = NULL; 45437c478bd9Sstevel@tonic-gate rd->next = qp->rdlist; 45447c478bd9Sstevel@tonic-gate if (qp->rdlist != NULL) 45457c478bd9Sstevel@tonic-gate qp->rdlist->prev = rd; 45467c478bd9Sstevel@tonic-gate qp->rdlist = rd; 45477c478bd9Sstevel@tonic-gate 45487c478bd9Sstevel@tonic-gate return (rd); 45497c478bd9Sstevel@tonic-gate } 45507c478bd9Sstevel@tonic-gate 45517c478bd9Sstevel@tonic-gate static void 45527c478bd9Sstevel@tonic-gate rdma_done_rm(rib_qp_t *qp, struct rdma_done_list *rd) 45537c478bd9Sstevel@tonic-gate { 45547c478bd9Sstevel@tonic-gate struct rdma_done_list *r; 45557c478bd9Sstevel@tonic-gate 45567c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&qp->rdlist_lock)); 45577c478bd9Sstevel@tonic-gate 45587c478bd9Sstevel@tonic-gate r = rd->next; 45597c478bd9Sstevel@tonic-gate if (r != NULL) { 45607c478bd9Sstevel@tonic-gate r->prev = rd->prev; 45617c478bd9Sstevel@tonic-gate } 45627c478bd9Sstevel@tonic-gate 45637c478bd9Sstevel@tonic-gate r = rd->prev; 45647c478bd9Sstevel@tonic-gate if (r != NULL) { 45657c478bd9Sstevel@tonic-gate r->next = rd->next; 45667c478bd9Sstevel@tonic-gate } else { 45677c478bd9Sstevel@tonic-gate qp->rdlist = rd->next; 45687c478bd9Sstevel@tonic-gate } 45697c478bd9Sstevel@tonic-gate 45707c478bd9Sstevel@tonic-gate cv_destroy(&rd->rdma_done_cv); 45717c478bd9Sstevel@tonic-gate kmem_free(rd, sizeof (*rd)); 45727c478bd9Sstevel@tonic-gate } 45737c478bd9Sstevel@tonic-gate 45747c478bd9Sstevel@tonic-gate static void 45757c478bd9Sstevel@tonic-gate rdma_done_rem_list(rib_qp_t *qp) 45767c478bd9Sstevel@tonic-gate { 45777c478bd9Sstevel@tonic-gate struct rdma_done_list *r, *n; 45787c478bd9Sstevel@tonic-gate 45797c478bd9Sstevel@tonic-gate mutex_enter(&qp->rdlist_lock); 45807c478bd9Sstevel@tonic-gate for (r = qp->rdlist; r != NULL; r = n) { 45817c478bd9Sstevel@tonic-gate n = r->next; 45827c478bd9Sstevel@tonic-gate rdma_done_rm(qp, r); 45837c478bd9Sstevel@tonic-gate } 45847c478bd9Sstevel@tonic-gate mutex_exit(&qp->rdlist_lock); 45857c478bd9Sstevel@tonic-gate } 45867c478bd9Sstevel@tonic-gate 45877c478bd9Sstevel@tonic-gate static void 45887c478bd9Sstevel@tonic-gate rdma_done_notify(rib_qp_t *qp, uint32_t xid) 45897c478bd9Sstevel@tonic-gate { 45907c478bd9Sstevel@tonic-gate struct rdma_done_list *r = qp->rdlist; 45917c478bd9Sstevel@tonic-gate 45927c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&qp->rdlist_lock)); 45937c478bd9Sstevel@tonic-gate 45947c478bd9Sstevel@tonic-gate while (r) { 45957c478bd9Sstevel@tonic-gate if (r->xid == xid) { 45967c478bd9Sstevel@tonic-gate cv_signal(&r->rdma_done_cv); 45977c478bd9Sstevel@tonic-gate return; 45987c478bd9Sstevel@tonic-gate } else { 45997c478bd9Sstevel@tonic-gate r = r->next; 46007c478bd9Sstevel@tonic-gate } 46017c478bd9Sstevel@tonic-gate } 46020a701b1eSRobert Gordon DTRACE_PROBE1(rpcib__i__donenotify__nomatchxid, 46030a701b1eSRobert Gordon int, xid); 46047c478bd9Sstevel@tonic-gate } 46057c478bd9Sstevel@tonic-gate 4606065714dcSSiddheshwar Mahesh /* 4607065714dcSSiddheshwar Mahesh * Expects conn->c_lock to be held by the caller. 4608065714dcSSiddheshwar Mahesh */ 4609065714dcSSiddheshwar Mahesh 4610065714dcSSiddheshwar Mahesh static void 4611065714dcSSiddheshwar Mahesh rib_close_a_channel(CONN *conn) 4612065714dcSSiddheshwar Mahesh { 4613065714dcSSiddheshwar Mahesh rib_qp_t *qp; 4614065714dcSSiddheshwar Mahesh qp = ctoqp(conn); 4615065714dcSSiddheshwar Mahesh 4616065714dcSSiddheshwar Mahesh if (qp->qp_hdl == NULL) { 4617065714dcSSiddheshwar Mahesh /* channel already freed */ 4618065714dcSSiddheshwar Mahesh return; 4619065714dcSSiddheshwar Mahesh } 4620065714dcSSiddheshwar Mahesh 4621065714dcSSiddheshwar Mahesh /* 4622065714dcSSiddheshwar Mahesh * Call ibt_close_rc_channel in blocking mode 4623065714dcSSiddheshwar Mahesh * with no callbacks. 4624065714dcSSiddheshwar Mahesh */ 4625065714dcSSiddheshwar Mahesh (void) ibt_close_rc_channel(qp->qp_hdl, IBT_NOCALLBACKS, 4626065714dcSSiddheshwar Mahesh NULL, 0, NULL, NULL, 0); 4627065714dcSSiddheshwar Mahesh } 46287c478bd9Sstevel@tonic-gate 46297c478bd9Sstevel@tonic-gate /* 46307c478bd9Sstevel@tonic-gate * Goes through all connections and closes the channel 46317c478bd9Sstevel@tonic-gate * This will cause all the WRs on those channels to be 46327c478bd9Sstevel@tonic-gate * flushed. 46337c478bd9Sstevel@tonic-gate */ 46347c478bd9Sstevel@tonic-gate static void 46357c478bd9Sstevel@tonic-gate rib_close_channels(rib_conn_list_t *connlist) 46367c478bd9Sstevel@tonic-gate { 4637065714dcSSiddheshwar Mahesh CONN *conn, *tmp; 46387c478bd9Sstevel@tonic-gate 46397c478bd9Sstevel@tonic-gate rw_enter(&connlist->conn_lock, RW_READER); 46407c478bd9Sstevel@tonic-gate conn = connlist->conn_hd; 46417c478bd9Sstevel@tonic-gate while (conn != NULL) { 46427c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 4643065714dcSSiddheshwar Mahesh tmp = conn->c_next; 4644065714dcSSiddheshwar Mahesh if (!(conn->c_flags & C_CLOSE_NOTNEEDED)) { 4645065714dcSSiddheshwar Mahesh 4646065714dcSSiddheshwar Mahesh conn->c_flags |= (C_CLOSE_NOTNEEDED | C_CLOSE_PENDING); 4647065714dcSSiddheshwar Mahesh 46487c478bd9Sstevel@tonic-gate /* 46497c478bd9Sstevel@tonic-gate * Live connection in CONNECTED state. 46507c478bd9Sstevel@tonic-gate */ 4651065714dcSSiddheshwar Mahesh if (conn->c_state == C_CONNECTED) 46520a701b1eSRobert Gordon conn->c_state = C_ERROR_CONN; 4653065714dcSSiddheshwar Mahesh mutex_exit(&conn->c_lock); 4654065714dcSSiddheshwar Mahesh 4655065714dcSSiddheshwar Mahesh rib_close_a_channel(conn); 4656065714dcSSiddheshwar Mahesh 4657065714dcSSiddheshwar Mahesh mutex_enter(&conn->c_lock); 4658065714dcSSiddheshwar Mahesh conn->c_flags &= ~C_CLOSE_PENDING; 4659065714dcSSiddheshwar Mahesh /* Signal a pending rib_disconnect_channel() */ 4660065714dcSSiddheshwar Mahesh cv_signal(&conn->c_cv); 46617c478bd9Sstevel@tonic-gate } 46627c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 4663065714dcSSiddheshwar Mahesh conn = tmp; 46647c478bd9Sstevel@tonic-gate } 46657c478bd9Sstevel@tonic-gate rw_exit(&connlist->conn_lock); 46667c478bd9Sstevel@tonic-gate } 46677c478bd9Sstevel@tonic-gate 46687c478bd9Sstevel@tonic-gate /* 46697c478bd9Sstevel@tonic-gate * Frees up all connections that are no longer being referenced 46707c478bd9Sstevel@tonic-gate */ 46717c478bd9Sstevel@tonic-gate static void 46727c478bd9Sstevel@tonic-gate rib_purge_connlist(rib_conn_list_t *connlist) 46737c478bd9Sstevel@tonic-gate { 46747c478bd9Sstevel@tonic-gate CONN *conn; 46757c478bd9Sstevel@tonic-gate 46767c478bd9Sstevel@tonic-gate top: 46777c478bd9Sstevel@tonic-gate rw_enter(&connlist->conn_lock, RW_READER); 46787c478bd9Sstevel@tonic-gate conn = connlist->conn_hd; 46797c478bd9Sstevel@tonic-gate while (conn != NULL) { 46807c478bd9Sstevel@tonic-gate mutex_enter(&conn->c_lock); 46817c478bd9Sstevel@tonic-gate 46827c478bd9Sstevel@tonic-gate /* 46837c478bd9Sstevel@tonic-gate * At this point connection is either in ERROR 46847c478bd9Sstevel@tonic-gate * or DISCONN_PEND state. If in DISCONN_PEND state 46857c478bd9Sstevel@tonic-gate * then some other thread is culling that connection. 46867c478bd9Sstevel@tonic-gate * If not and if c_ref is 0, then destroy the connection. 46877c478bd9Sstevel@tonic-gate */ 46887c478bd9Sstevel@tonic-gate if (conn->c_ref == 0 && 46897c478bd9Sstevel@tonic-gate conn->c_state != C_DISCONN_PEND) { 46907c478bd9Sstevel@tonic-gate /* 46917c478bd9Sstevel@tonic-gate * Cull the connection 46927c478bd9Sstevel@tonic-gate */ 46937c478bd9Sstevel@tonic-gate conn->c_state = C_DISCONN_PEND; 46947c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 46957c478bd9Sstevel@tonic-gate rw_exit(&connlist->conn_lock); 46967c478bd9Sstevel@tonic-gate (void) rib_disconnect_channel(conn, connlist); 46977c478bd9Sstevel@tonic-gate goto top; 46987c478bd9Sstevel@tonic-gate } else { 46997c478bd9Sstevel@tonic-gate /* 47007c478bd9Sstevel@tonic-gate * conn disconnect already scheduled or will 47017c478bd9Sstevel@tonic-gate * happen from conn_release when c_ref drops to 0. 47027c478bd9Sstevel@tonic-gate */ 47037c478bd9Sstevel@tonic-gate mutex_exit(&conn->c_lock); 47047c478bd9Sstevel@tonic-gate } 47057c478bd9Sstevel@tonic-gate conn = conn->c_next; 47067c478bd9Sstevel@tonic-gate } 47077c478bd9Sstevel@tonic-gate rw_exit(&connlist->conn_lock); 47087c478bd9Sstevel@tonic-gate 47097c478bd9Sstevel@tonic-gate /* 47107c478bd9Sstevel@tonic-gate * At this point, only connections with c_ref != 0 are on the list 47117c478bd9Sstevel@tonic-gate */ 47127c478bd9Sstevel@tonic-gate } 47137c478bd9Sstevel@tonic-gate 47147c478bd9Sstevel@tonic-gate /* 4715065714dcSSiddheshwar Mahesh * Free all the HCA resources and close 4716065714dcSSiddheshwar Mahesh * the hca. 4717065714dcSSiddheshwar Mahesh */ 4718065714dcSSiddheshwar Mahesh 4719065714dcSSiddheshwar Mahesh static void 4720065714dcSSiddheshwar Mahesh rib_free_hca(rib_hca_t *hca) 4721065714dcSSiddheshwar Mahesh { 4722065714dcSSiddheshwar Mahesh (void) ibt_free_cq(hca->clnt_rcq->rib_cq_hdl); 4723065714dcSSiddheshwar Mahesh (void) ibt_free_cq(hca->clnt_scq->rib_cq_hdl); 4724065714dcSSiddheshwar Mahesh (void) ibt_free_cq(hca->svc_rcq->rib_cq_hdl); 4725065714dcSSiddheshwar Mahesh (void) ibt_free_cq(hca->svc_scq->rib_cq_hdl); 4726065714dcSSiddheshwar Mahesh 4727065714dcSSiddheshwar Mahesh kmem_free(hca->clnt_rcq, sizeof (rib_cq_t)); 4728065714dcSSiddheshwar Mahesh kmem_free(hca->clnt_scq, sizeof (rib_cq_t)); 4729065714dcSSiddheshwar Mahesh kmem_free(hca->svc_rcq, sizeof (rib_cq_t)); 4730065714dcSSiddheshwar Mahesh kmem_free(hca->svc_scq, sizeof (rib_cq_t)); 4731065714dcSSiddheshwar Mahesh 4732065714dcSSiddheshwar Mahesh rib_rbufpool_destroy(hca, RECV_BUFFER); 4733065714dcSSiddheshwar Mahesh rib_rbufpool_destroy(hca, SEND_BUFFER); 4734065714dcSSiddheshwar Mahesh rib_destroy_cache(hca); 4735065714dcSSiddheshwar Mahesh if (rib_mod.rdma_count == 0) 4736065714dcSSiddheshwar Mahesh rdma_unregister_mod(&rib_mod); 4737065714dcSSiddheshwar Mahesh (void) ibt_free_pd(hca->hca_hdl, hca->pd_hdl); 4738065714dcSSiddheshwar Mahesh (void) ibt_close_hca(hca->hca_hdl); 4739065714dcSSiddheshwar Mahesh hca->hca_hdl = NULL; 4740065714dcSSiddheshwar Mahesh } 4741065714dcSSiddheshwar Mahesh 47427f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 47437c478bd9Sstevel@tonic-gate static void 47447f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stop_hca_services(rib_hca_t *hca) 47457c478bd9Sstevel@tonic-gate { 47467c478bd9Sstevel@tonic-gate rib_stop_services(hca); 47477c478bd9Sstevel@tonic-gate rib_close_channels(&hca->cl_conn_list); 47487c478bd9Sstevel@tonic-gate rib_close_channels(&hca->srv_conn_list); 474951f34d4bSRajkumar Sivaprakasam 475051f34d4bSRajkumar Sivaprakasam rib_purge_connlist(&hca->cl_conn_list); 475151f34d4bSRajkumar Sivaprakasam rib_purge_connlist(&hca->srv_conn_list); 475251f34d4bSRajkumar Sivaprakasam 47537f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if ((rib_stat->hcas_list == NULL) && stats_enabled) { 475451f34d4bSRajkumar Sivaprakasam kstat_delete_byname_zone("unix", 0, "rpcib_cache", 475551f34d4bSRajkumar Sivaprakasam GLOBAL_ZONEID); 47567f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States stats_enabled = FALSE; 475751f34d4bSRajkumar Sivaprakasam } 47587c478bd9Sstevel@tonic-gate 47597c478bd9Sstevel@tonic-gate rw_enter(&hca->srv_conn_list.conn_lock, RW_READER); 47607c478bd9Sstevel@tonic-gate rw_enter(&hca->cl_conn_list.conn_lock, RW_READER); 47617c478bd9Sstevel@tonic-gate if (hca->srv_conn_list.conn_hd == NULL && 47627c478bd9Sstevel@tonic-gate hca->cl_conn_list.conn_hd == NULL) { 47637c478bd9Sstevel@tonic-gate /* 47647c478bd9Sstevel@tonic-gate * conn_lists are NULL, so destroy 47657c478bd9Sstevel@tonic-gate * buffers, close hca and be done. 47667c478bd9Sstevel@tonic-gate */ 4767065714dcSSiddheshwar Mahesh rib_free_hca(hca); 47687c478bd9Sstevel@tonic-gate } 47697c478bd9Sstevel@tonic-gate rw_exit(&hca->cl_conn_list.conn_lock); 47707c478bd9Sstevel@tonic-gate rw_exit(&hca->srv_conn_list.conn_lock); 47717c478bd9Sstevel@tonic-gate 47727c478bd9Sstevel@tonic-gate if (hca->hca_hdl != NULL) { 47737c478bd9Sstevel@tonic-gate mutex_enter(&hca->inuse_lock); 47747c478bd9Sstevel@tonic-gate while (hca->inuse) 47757c478bd9Sstevel@tonic-gate cv_wait(&hca->cb_cv, &hca->inuse_lock); 47767c478bd9Sstevel@tonic-gate mutex_exit(&hca->inuse_lock); 477751f34d4bSRajkumar Sivaprakasam 4778065714dcSSiddheshwar Mahesh rib_free_hca(hca); 4779065714dcSSiddheshwar Mahesh } 47807f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_destroy(&hca->bound_services_lock); 478151f34d4bSRajkumar Sivaprakasam 4782065714dcSSiddheshwar Mahesh if (hca->cleanup_helper != NULL) { 4783065714dcSSiddheshwar Mahesh ddi_taskq_destroy(hca->cleanup_helper); 4784065714dcSSiddheshwar Mahesh hca->cleanup_helper = NULL; 47857c478bd9Sstevel@tonic-gate } 47867c478bd9Sstevel@tonic-gate } 47870a701b1eSRobert Gordon 47887f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 47897f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Cleans and closes up all uses of the HCA 47907f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 47917f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static void 47927f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_detach_hca(rib_hca_t *hca) 47937f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States { 47947f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_hca_t **hcap; 47957f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 47967f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States /* 47977f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Stop all services on the HCA 47987f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Go through cl_conn_list and close all rc_channels 47997f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Go through svr_conn_list and close all rc_channels 48007f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Free connections whose c_ref has dropped to 0 48017f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Destroy all CQs 48027f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Deregister and released all buffer pool memory after all 48037f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * connections are destroyed 48047f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * Free the protection domain 48057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States * ibt_close_hca() 48067f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States */ 48077f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&hca->state_lock, RW_WRITER); 48087f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca->state == HCA_DETACHED) { 48097f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 48107f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States return; 48117f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 48127f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 48137f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->state = HCA_DETACHED; 48147f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&rib_stat->hcas_list_lock, RW_WRITER); 48157f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States for (hcap = &rib_stat->hcas_list; *hcap && (*hcap != hca); 48167f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hcap = &(*hcap)->next) 48177f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ; 48187f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States ASSERT(*hcap == hca); 48197f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States *hcap = hca->next; 48207f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stat->nhca_inited--; 48217f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_mod.rdma_count--; 48227f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->hcas_list_lock); 48237f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&hca->state_lock); 48247f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 48257f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_stop_hca_services(hca); 48267f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 48277f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States kmem_free(hca, sizeof (*hca)); 48287f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 48297f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 48300a701b1eSRobert Gordon static void 48310a701b1eSRobert Gordon rib_server_side_cache_reclaim(void *argp) 48320a701b1eSRobert Gordon { 48330a701b1eSRobert Gordon cache_avl_struct_t *rcas; 48340a701b1eSRobert Gordon rib_lrc_entry_t *rb; 48350a701b1eSRobert Gordon rib_hca_t *hca = (rib_hca_t *)argp; 48360a701b1eSRobert Gordon 48370a701b1eSRobert Gordon rw_enter(&hca->avl_rw_lock, RW_WRITER); 48380a701b1eSRobert Gordon rcas = avl_first(&hca->avl_tree); 48390a701b1eSRobert Gordon if (rcas != NULL) 48400a701b1eSRobert Gordon avl_remove(&hca->avl_tree, rcas); 48410a701b1eSRobert Gordon 48420a701b1eSRobert Gordon while (rcas != NULL) { 48430a701b1eSRobert Gordon while (rcas->r.forw != &rcas->r) { 48440a701b1eSRobert Gordon rcas->elements--; 48450a701b1eSRobert Gordon rb = rcas->r.forw; 48460a701b1eSRobert Gordon remque(rb); 48470a701b1eSRobert Gordon if (rb->registered) 48480a701b1eSRobert Gordon (void) rib_deregistermem_via_hca(hca, 48490a701b1eSRobert Gordon rb->lrc_buf, rb->lrc_mhandle); 48507f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 48517f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->cache_allocation -= rb->lrc_len; 48520a701b1eSRobert Gordon kmem_free(rb->lrc_buf, rb->lrc_len); 48530a701b1eSRobert Gordon kmem_free(rb, sizeof (rib_lrc_entry_t)); 48540a701b1eSRobert Gordon } 48550a701b1eSRobert Gordon mutex_destroy(&rcas->node_lock); 48560a701b1eSRobert Gordon kmem_cache_free(hca->server_side_cache, rcas); 48570a701b1eSRobert Gordon rcas = avl_first(&hca->avl_tree); 48580a701b1eSRobert Gordon if (rcas != NULL) 48590a701b1eSRobert Gordon avl_remove(&hca->avl_tree, rcas); 48600a701b1eSRobert Gordon } 48610a701b1eSRobert Gordon rw_exit(&hca->avl_rw_lock); 48620a701b1eSRobert Gordon } 48630a701b1eSRobert Gordon 48640a701b1eSRobert Gordon static void 48650a701b1eSRobert Gordon rib_server_side_cache_cleanup(void *argp) 48660a701b1eSRobert Gordon { 48670a701b1eSRobert Gordon cache_avl_struct_t *rcas; 48680a701b1eSRobert Gordon rib_lrc_entry_t *rb; 48690a701b1eSRobert Gordon rib_hca_t *hca = (rib_hca_t *)argp; 48700a701b1eSRobert Gordon 48717f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_enter(&hca->cache_allocation_lock); 48727f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca->cache_allocation < cache_limit) { 48737f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&hca->cache_allocation_lock); 48740a701b1eSRobert Gordon return; 48750a701b1eSRobert Gordon } 48767f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&hca->cache_allocation_lock); 48770a701b1eSRobert Gordon 48780a701b1eSRobert Gordon rw_enter(&hca->avl_rw_lock, RW_WRITER); 48790a701b1eSRobert Gordon rcas = avl_last(&hca->avl_tree); 48800a701b1eSRobert Gordon if (rcas != NULL) 48810a701b1eSRobert Gordon avl_remove(&hca->avl_tree, rcas); 48820a701b1eSRobert Gordon 48830a701b1eSRobert Gordon while (rcas != NULL) { 48840a701b1eSRobert Gordon while (rcas->r.forw != &rcas->r) { 48850a701b1eSRobert Gordon rcas->elements--; 48860a701b1eSRobert Gordon rb = rcas->r.forw; 48870a701b1eSRobert Gordon remque(rb); 48880a701b1eSRobert Gordon if (rb->registered) 48890a701b1eSRobert Gordon (void) rib_deregistermem_via_hca(hca, 48900a701b1eSRobert Gordon rb->lrc_buf, rb->lrc_mhandle); 48917f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 48927f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->cache_allocation -= rb->lrc_len; 48937f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 48940a701b1eSRobert Gordon kmem_free(rb->lrc_buf, rb->lrc_len); 48950a701b1eSRobert Gordon kmem_free(rb, sizeof (rib_lrc_entry_t)); 48960a701b1eSRobert Gordon } 48970a701b1eSRobert Gordon mutex_destroy(&rcas->node_lock); 489851f34d4bSRajkumar Sivaprakasam if (hca->server_side_cache) { 48990a701b1eSRobert Gordon kmem_cache_free(hca->server_side_cache, rcas); 490051f34d4bSRajkumar Sivaprakasam } 49017f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 49027f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States if (hca->cache_allocation < cache_limit) { 49030a701b1eSRobert Gordon rw_exit(&hca->avl_rw_lock); 49040a701b1eSRobert Gordon return; 49050a701b1eSRobert Gordon } 49060a701b1eSRobert Gordon 49070a701b1eSRobert Gordon rcas = avl_last(&hca->avl_tree); 49080a701b1eSRobert Gordon if (rcas != NULL) 49090a701b1eSRobert Gordon avl_remove(&hca->avl_tree, rcas); 49100a701b1eSRobert Gordon } 49110a701b1eSRobert Gordon rw_exit(&hca->avl_rw_lock); 49120a701b1eSRobert Gordon } 49130a701b1eSRobert Gordon 49140a701b1eSRobert Gordon static int 49150a701b1eSRobert Gordon avl_compare(const void *t1, const void *t2) 49160a701b1eSRobert Gordon { 49170a701b1eSRobert Gordon if (((cache_avl_struct_t *)t1)->len == ((cache_avl_struct_t *)t2)->len) 49180a701b1eSRobert Gordon return (0); 49190a701b1eSRobert Gordon 49200a701b1eSRobert Gordon if (((cache_avl_struct_t *)t1)->len < ((cache_avl_struct_t *)t2)->len) 49210a701b1eSRobert Gordon return (-1); 49220a701b1eSRobert Gordon 49230a701b1eSRobert Gordon return (1); 49240a701b1eSRobert Gordon } 49250a701b1eSRobert Gordon 49260a701b1eSRobert Gordon static void 49270a701b1eSRobert Gordon rib_destroy_cache(rib_hca_t *hca) 49280a701b1eSRobert Gordon { 492951f34d4bSRajkumar Sivaprakasam if (hca->avl_init) { 493051f34d4bSRajkumar Sivaprakasam rib_server_side_cache_reclaim((void *)hca); 493151f34d4bSRajkumar Sivaprakasam if (hca->server_side_cache) { 49320a701b1eSRobert Gordon kmem_cache_destroy(hca->server_side_cache); 493351f34d4bSRajkumar Sivaprakasam hca->server_side_cache = NULL; 493451f34d4bSRajkumar Sivaprakasam } 49350a701b1eSRobert Gordon avl_destroy(&hca->avl_tree); 49367f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_destroy(&hca->cache_allocation_lock); 49370a701b1eSRobert Gordon rw_destroy(&hca->avl_rw_lock); 49380a701b1eSRobert Gordon } 49390a701b1eSRobert Gordon hca->avl_init = FALSE; 49400a701b1eSRobert Gordon } 49410a701b1eSRobert Gordon 49420a701b1eSRobert Gordon static void 49430a701b1eSRobert Gordon rib_force_cleanup(void *hca) 49440a701b1eSRobert Gordon { 4945065714dcSSiddheshwar Mahesh if (((rib_hca_t *)hca)->cleanup_helper != NULL) 49460a701b1eSRobert Gordon (void) ddi_taskq_dispatch( 4947065714dcSSiddheshwar Mahesh ((rib_hca_t *)hca)->cleanup_helper, 49480a701b1eSRobert Gordon rib_server_side_cache_cleanup, 49490a701b1eSRobert Gordon (void *)hca, DDI_NOSLEEP); 49500a701b1eSRobert Gordon } 49510a701b1eSRobert Gordon 49520a701b1eSRobert Gordon static rib_lrc_entry_t * 49530a701b1eSRobert Gordon rib_get_cache_buf(CONN *conn, uint32_t len) 49540a701b1eSRobert Gordon { 49550a701b1eSRobert Gordon cache_avl_struct_t cas, *rcas; 49560a701b1eSRobert Gordon rib_hca_t *hca = (ctoqp(conn))->hca; 49570a701b1eSRobert Gordon rib_lrc_entry_t *reply_buf; 49580a701b1eSRobert Gordon avl_index_t where = NULL; 49590a701b1eSRobert Gordon uint64_t c_alloc = 0; 49600a701b1eSRobert Gordon 49610a701b1eSRobert Gordon if (!hca->avl_init) 49620a701b1eSRobert Gordon goto error_alloc; 49630a701b1eSRobert Gordon 49640a701b1eSRobert Gordon cas.len = len; 49650a701b1eSRobert Gordon 49660a701b1eSRobert Gordon rw_enter(&hca->avl_rw_lock, RW_READER); 49670a701b1eSRobert Gordon 49687f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_enter(&hca->cache_allocation_lock); 49697f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States c_alloc = hca->cache_allocation; 49707f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&hca->cache_allocation_lock); 49710a701b1eSRobert Gordon 49720a701b1eSRobert Gordon if ((rcas = (cache_avl_struct_t *)avl_find(&hca->avl_tree, &cas, 49730a701b1eSRobert Gordon &where)) == NULL) { 49740a701b1eSRobert Gordon /* Am I above the cache limit */ 49750a701b1eSRobert Gordon if ((c_alloc + len) >= cache_limit) { 49760a701b1eSRobert Gordon rib_force_cleanup((void *)hca); 49770a701b1eSRobert Gordon rw_exit(&hca->avl_rw_lock); 49787f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_enter(&hca->cache_allocation_lock); 49797f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->cache_misses_above_the_limit ++; 49807f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&hca->cache_allocation_lock); 49810a701b1eSRobert Gordon 49820a701b1eSRobert Gordon /* Allocate and register the buffer directly */ 49830a701b1eSRobert Gordon goto error_alloc; 49840a701b1eSRobert Gordon } 49850a701b1eSRobert Gordon 49860a701b1eSRobert Gordon rw_exit(&hca->avl_rw_lock); 49870a701b1eSRobert Gordon rw_enter(&hca->avl_rw_lock, RW_WRITER); 49880a701b1eSRobert Gordon 49890a701b1eSRobert Gordon /* Recheck to make sure no other thread added the entry in */ 49900a701b1eSRobert Gordon if ((rcas = (cache_avl_struct_t *)avl_find(&hca->avl_tree, 49910a701b1eSRobert Gordon &cas, &where)) == NULL) { 49920a701b1eSRobert Gordon /* Allocate an avl tree entry */ 49930a701b1eSRobert Gordon rcas = (cache_avl_struct_t *) 49940a701b1eSRobert Gordon kmem_cache_alloc(hca->server_side_cache, KM_SLEEP); 49950a701b1eSRobert Gordon 49960a701b1eSRobert Gordon bzero(rcas, sizeof (cache_avl_struct_t)); 49970a701b1eSRobert Gordon rcas->elements = 0; 49980a701b1eSRobert Gordon rcas->r.forw = &rcas->r; 49990a701b1eSRobert Gordon rcas->r.back = &rcas->r; 50000a701b1eSRobert Gordon rcas->len = len; 50010a701b1eSRobert Gordon mutex_init(&rcas->node_lock, NULL, MUTEX_DEFAULT, NULL); 50020a701b1eSRobert Gordon avl_insert(&hca->avl_tree, rcas, where); 50030a701b1eSRobert Gordon } 50040a701b1eSRobert Gordon } 50050a701b1eSRobert Gordon 50060a701b1eSRobert Gordon mutex_enter(&rcas->node_lock); 50070a701b1eSRobert Gordon 50080a701b1eSRobert Gordon if (rcas->r.forw != &rcas->r && rcas->elements > 0) { 50090a701b1eSRobert Gordon reply_buf = rcas->r.forw; 50100a701b1eSRobert Gordon remque(reply_buf); 50110a701b1eSRobert Gordon rcas->elements--; 50120a701b1eSRobert Gordon mutex_exit(&rcas->node_lock); 50130a701b1eSRobert Gordon rw_exit(&hca->avl_rw_lock); 50147f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 50157f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_enter(&hca->cache_allocation_lock); 50167f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->cache_hits++; 50177f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->cache_allocation -= len; 50187f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&hca->cache_allocation_lock); 50190a701b1eSRobert Gordon } else { 50200a701b1eSRobert Gordon /* Am I above the cache limit */ 50210a701b1eSRobert Gordon mutex_exit(&rcas->node_lock); 50220a701b1eSRobert Gordon if ((c_alloc + len) >= cache_limit) { 50230a701b1eSRobert Gordon rib_force_cleanup((void *)hca); 50240a701b1eSRobert Gordon rw_exit(&hca->avl_rw_lock); 50257f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 50267f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_enter(&hca->cache_allocation_lock); 50277f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->cache_misses_above_the_limit++; 50287f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&hca->cache_allocation_lock); 50290a701b1eSRobert Gordon /* Allocate and register the buffer directly */ 50300a701b1eSRobert Gordon goto error_alloc; 50310a701b1eSRobert Gordon } 50320a701b1eSRobert Gordon rw_exit(&hca->avl_rw_lock); 50337f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_enter(&hca->cache_allocation_lock); 50347f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->cache_misses++; 50357f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&hca->cache_allocation_lock); 50360a701b1eSRobert Gordon /* Allocate a reply_buf entry */ 50370a701b1eSRobert Gordon reply_buf = (rib_lrc_entry_t *) 50380a701b1eSRobert Gordon kmem_zalloc(sizeof (rib_lrc_entry_t), KM_SLEEP); 50390a701b1eSRobert Gordon bzero(reply_buf, sizeof (rib_lrc_entry_t)); 50400a701b1eSRobert Gordon reply_buf->lrc_buf = kmem_alloc(len, KM_SLEEP); 50410a701b1eSRobert Gordon reply_buf->lrc_len = len; 50420a701b1eSRobert Gordon reply_buf->registered = FALSE; 50430a701b1eSRobert Gordon reply_buf->avl_node = (void *)rcas; 50440a701b1eSRobert Gordon } 50450a701b1eSRobert Gordon 50460a701b1eSRobert Gordon return (reply_buf); 50470a701b1eSRobert Gordon 50480a701b1eSRobert Gordon error_alloc: 50490a701b1eSRobert Gordon reply_buf = (rib_lrc_entry_t *) 50500a701b1eSRobert Gordon kmem_zalloc(sizeof (rib_lrc_entry_t), KM_SLEEP); 50510a701b1eSRobert Gordon bzero(reply_buf, sizeof (rib_lrc_entry_t)); 50520a701b1eSRobert Gordon reply_buf->lrc_buf = kmem_alloc(len, KM_SLEEP); 50530a701b1eSRobert Gordon reply_buf->lrc_len = len; 50540a701b1eSRobert Gordon reply_buf->registered = FALSE; 50550a701b1eSRobert Gordon reply_buf->avl_node = NULL; 50560a701b1eSRobert Gordon 50570a701b1eSRobert Gordon return (reply_buf); 50580a701b1eSRobert Gordon } 50590a701b1eSRobert Gordon 50600a701b1eSRobert Gordon /* 50610a701b1eSRobert Gordon * Return a pre-registered back to the cache (without 50620a701b1eSRobert Gordon * unregistering the buffer).. 50630a701b1eSRobert Gordon */ 50640a701b1eSRobert Gordon 50650a701b1eSRobert Gordon static void 50660a701b1eSRobert Gordon rib_free_cache_buf(CONN *conn, rib_lrc_entry_t *reg_buf) 50670a701b1eSRobert Gordon { 50680a701b1eSRobert Gordon cache_avl_struct_t cas, *rcas; 50690a701b1eSRobert Gordon avl_index_t where = NULL; 50700a701b1eSRobert Gordon rib_hca_t *hca = (ctoqp(conn))->hca; 50710a701b1eSRobert Gordon 50720a701b1eSRobert Gordon if (!hca->avl_init) 50730a701b1eSRobert Gordon goto error_free; 50740a701b1eSRobert Gordon 50750a701b1eSRobert Gordon cas.len = reg_buf->lrc_len; 50760a701b1eSRobert Gordon rw_enter(&hca->avl_rw_lock, RW_READER); 50770a701b1eSRobert Gordon if ((rcas = (cache_avl_struct_t *) 50780a701b1eSRobert Gordon avl_find(&hca->avl_tree, &cas, &where)) == NULL) { 50790a701b1eSRobert Gordon rw_exit(&hca->avl_rw_lock); 50800a701b1eSRobert Gordon goto error_free; 50810a701b1eSRobert Gordon } else { 50820a701b1eSRobert Gordon cas.len = reg_buf->lrc_len; 50830a701b1eSRobert Gordon mutex_enter(&rcas->node_lock); 50840a701b1eSRobert Gordon insque(reg_buf, &rcas->r); 50850a701b1eSRobert Gordon rcas->elements ++; 50860a701b1eSRobert Gordon mutex_exit(&rcas->node_lock); 50870a701b1eSRobert Gordon rw_exit(&hca->avl_rw_lock); 50887f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_enter(&hca->cache_allocation_lock); 50897f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States hca->cache_allocation += cas.len; 50907f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States mutex_exit(&hca->cache_allocation_lock); 50910a701b1eSRobert Gordon } 50920a701b1eSRobert Gordon 50930a701b1eSRobert Gordon return; 50940a701b1eSRobert Gordon 50950a701b1eSRobert Gordon error_free: 50960a701b1eSRobert Gordon 50970a701b1eSRobert Gordon if (reg_buf->registered) 50980a701b1eSRobert Gordon (void) rib_deregistermem_via_hca(hca, 50990a701b1eSRobert Gordon reg_buf->lrc_buf, reg_buf->lrc_mhandle); 51000a701b1eSRobert Gordon kmem_free(reg_buf->lrc_buf, reg_buf->lrc_len); 51010a701b1eSRobert Gordon kmem_free(reg_buf, sizeof (rib_lrc_entry_t)); 51020a701b1eSRobert Gordon } 51030a701b1eSRobert Gordon 51040a701b1eSRobert Gordon static rdma_stat 51050a701b1eSRobert Gordon rib_registermem_via_hca(rib_hca_t *hca, caddr_t adsp, caddr_t buf, 51060a701b1eSRobert Gordon uint_t buflen, struct mrc *buf_handle) 51070a701b1eSRobert Gordon { 51080a701b1eSRobert Gordon ibt_mr_hdl_t mr_hdl = NULL; /* memory region handle */ 51090a701b1eSRobert Gordon ibt_mr_desc_t mr_desc; /* vaddr, lkey, rkey */ 51100a701b1eSRobert Gordon rdma_stat status; 51110a701b1eSRobert Gordon 51120a701b1eSRobert Gordon 51130a701b1eSRobert Gordon /* 51140a701b1eSRobert Gordon * Note: ALL buffer pools use the same memory type RDMARW. 51150a701b1eSRobert Gordon */ 51160a701b1eSRobert Gordon status = rib_reg_mem(hca, adsp, buf, buflen, 0, &mr_hdl, &mr_desc); 51170a701b1eSRobert Gordon if (status == RDMA_SUCCESS) { 51180a701b1eSRobert Gordon buf_handle->mrc_linfo = (uint64_t)(uintptr_t)mr_hdl; 51190a701b1eSRobert Gordon buf_handle->mrc_lmr = (uint32_t)mr_desc.md_lkey; 51200a701b1eSRobert Gordon buf_handle->mrc_rmr = (uint32_t)mr_desc.md_rkey; 51210a701b1eSRobert Gordon } else { 51220a701b1eSRobert Gordon buf_handle->mrc_linfo = NULL; 51230a701b1eSRobert Gordon buf_handle->mrc_lmr = 0; 51240a701b1eSRobert Gordon buf_handle->mrc_rmr = 0; 51250a701b1eSRobert Gordon } 51260a701b1eSRobert Gordon return (status); 51270a701b1eSRobert Gordon } 51280a701b1eSRobert Gordon 51290a701b1eSRobert Gordon /* ARGSUSED */ 51300a701b1eSRobert Gordon static rdma_stat 51310a701b1eSRobert Gordon rib_deregistermemsync_via_hca(rib_hca_t *hca, caddr_t buf, 51320a701b1eSRobert Gordon struct mrc buf_handle, RIB_SYNCMEM_HANDLE sync_handle) 51330a701b1eSRobert Gordon { 51340a701b1eSRobert Gordon 51350a701b1eSRobert Gordon (void) rib_deregistermem_via_hca(hca, buf, buf_handle); 51360a701b1eSRobert Gordon return (RDMA_SUCCESS); 51370a701b1eSRobert Gordon } 51380a701b1eSRobert Gordon 51390a701b1eSRobert Gordon /* ARGSUSED */ 51400a701b1eSRobert Gordon static rdma_stat 51410a701b1eSRobert Gordon rib_deregistermem_via_hca(rib_hca_t *hca, caddr_t buf, struct mrc buf_handle) 51420a701b1eSRobert Gordon { 51430a701b1eSRobert Gordon 51440a701b1eSRobert Gordon (void) ibt_deregister_mr(hca->hca_hdl, 51450a701b1eSRobert Gordon (ibt_mr_hdl_t)(uintptr_t)buf_handle.mrc_linfo); 51460a701b1eSRobert Gordon return (RDMA_SUCCESS); 51470a701b1eSRobert Gordon } 51480a701b1eSRobert Gordon 51490a701b1eSRobert Gordon /* 5150e11c3f44Smeem * Check if the IP interface named by `lifrp' is RDMA-capable. 51510a701b1eSRobert Gordon */ 5152e11c3f44Smeem static boolean_t 5153e11c3f44Smeem rpcib_rdma_capable_interface(struct lifreq *lifrp) 51540a701b1eSRobert Gordon { 5155e11c3f44Smeem char ifname[LIFNAMSIZ]; 5156e11c3f44Smeem char *cp; 51570a701b1eSRobert Gordon 5158e11c3f44Smeem if (lifrp->lifr_type == IFT_IB) 5159e11c3f44Smeem return (B_TRUE); 51600a701b1eSRobert Gordon 51610a701b1eSRobert Gordon /* 5162e11c3f44Smeem * Strip off the logical interface portion before getting 5163e11c3f44Smeem * intimate with the name. 51640a701b1eSRobert Gordon */ 5165e11c3f44Smeem (void) strlcpy(ifname, lifrp->lifr_name, LIFNAMSIZ); 5166e11c3f44Smeem if ((cp = strchr(ifname, ':')) != NULL) 5167e11c3f44Smeem *cp = '\0'; 51680a701b1eSRobert Gordon 5169e11c3f44Smeem return (strcmp("lo0", ifname) == 0); 51700a701b1eSRobert Gordon } 51710a701b1eSRobert Gordon 51720a701b1eSRobert Gordon static int 5173e11c3f44Smeem rpcib_do_ip_ioctl(int cmd, int len, void *arg) 51740a701b1eSRobert Gordon { 51750a701b1eSRobert Gordon vnode_t *kvp, *vp; 51760a701b1eSRobert Gordon TIUSER *tiptr; 51770a701b1eSRobert Gordon struct strioctl iocb; 51780a701b1eSRobert Gordon k_sigset_t smask; 51790a701b1eSRobert Gordon int err = 0; 51800a701b1eSRobert Gordon 5181e11c3f44Smeem if (lookupname("/dev/udp", UIO_SYSSPACE, FOLLOW, NULLVPP, &kvp) == 0) { 5182e11c3f44Smeem if (t_kopen(NULL, kvp->v_rdev, FREAD|FWRITE, 51830a701b1eSRobert Gordon &tiptr, CRED()) == 0) { 51840a701b1eSRobert Gordon vp = tiptr->fp->f_vnode; 51850a701b1eSRobert Gordon } else { 51860a701b1eSRobert Gordon VN_RELE(kvp); 51870a701b1eSRobert Gordon return (EPROTO); 51880a701b1eSRobert Gordon } 51890a701b1eSRobert Gordon } else { 51900a701b1eSRobert Gordon return (EPROTO); 51910a701b1eSRobert Gordon } 51920a701b1eSRobert Gordon 51930a701b1eSRobert Gordon iocb.ic_cmd = cmd; 51940a701b1eSRobert Gordon iocb.ic_timout = 0; 51950a701b1eSRobert Gordon iocb.ic_len = len; 5196e11c3f44Smeem iocb.ic_dp = (caddr_t)arg; 51970a701b1eSRobert Gordon sigintr(&smask, 0); 51980a701b1eSRobert Gordon err = kstr_ioctl(vp, I_STR, (intptr_t)&iocb); 51990a701b1eSRobert Gordon sigunintr(&smask); 52000a701b1eSRobert Gordon (void) t_kclose(tiptr, 0); 52010a701b1eSRobert Gordon VN_RELE(kvp); 52020a701b1eSRobert Gordon return (err); 52030a701b1eSRobert Gordon } 52040a701b1eSRobert Gordon 5205e11c3f44Smeem /* 5206e11c3f44Smeem * Issue an SIOCGLIFCONF down to IP and return the result in `lifcp'. 5207e11c3f44Smeem * lifcp->lifc_buf is dynamically allocated to be *bufsizep bytes. 5208e11c3f44Smeem */ 5209e11c3f44Smeem static int 5210e11c3f44Smeem rpcib_do_lifconf(struct lifconf *lifcp, uint_t *bufsizep) 5211e11c3f44Smeem { 5212e11c3f44Smeem int err; 5213e11c3f44Smeem struct lifnum lifn; 5214e11c3f44Smeem 5215e11c3f44Smeem bzero(&lifn, sizeof (struct lifnum)); 5216e11c3f44Smeem lifn.lifn_family = AF_UNSPEC; 5217e11c3f44Smeem 5218e11c3f44Smeem err = rpcib_do_ip_ioctl(SIOCGLIFNUM, sizeof (struct lifnum), &lifn); 5219e11c3f44Smeem if (err != 0) 5220e11c3f44Smeem return (err); 5221e11c3f44Smeem 5222e11c3f44Smeem /* 5223e11c3f44Smeem * Pad the interface count to account for additional interfaces that 5224e11c3f44Smeem * may have been configured between the SIOCGLIFNUM and SIOCGLIFCONF. 5225e11c3f44Smeem */ 5226e11c3f44Smeem lifn.lifn_count += 4; 5227e11c3f44Smeem 5228e11c3f44Smeem bzero(lifcp, sizeof (struct lifconf)); 5229e11c3f44Smeem lifcp->lifc_family = AF_UNSPEC; 5230e11c3f44Smeem lifcp->lifc_len = *bufsizep = lifn.lifn_count * sizeof (struct lifreq); 5231e11c3f44Smeem lifcp->lifc_buf = kmem_zalloc(*bufsizep, KM_SLEEP); 5232e11c3f44Smeem 5233e11c3f44Smeem err = rpcib_do_ip_ioctl(SIOCGLIFCONF, sizeof (struct lifconf), lifcp); 5234e11c3f44Smeem if (err != 0) { 5235e11c3f44Smeem kmem_free(lifcp->lifc_buf, *bufsizep); 5236e11c3f44Smeem return (err); 52370a701b1eSRobert Gordon } 5238e11c3f44Smeem return (0); 52390a701b1eSRobert Gordon } 52400a701b1eSRobert Gordon 52410a701b1eSRobert Gordon static boolean_t 5242e11c3f44Smeem rpcib_get_ib_addresses(rpcib_ipaddrs_t *addrs4, rpcib_ipaddrs_t *addrs6) 52430a701b1eSRobert Gordon { 5244e11c3f44Smeem uint_t i, nifs; 5245e11c3f44Smeem uint_t bufsize; 5246e11c3f44Smeem struct lifconf lifc; 5247e11c3f44Smeem struct lifreq *lifrp; 5248e11c3f44Smeem struct sockaddr_in *sinp; 5249e11c3f44Smeem struct sockaddr_in6 *sin6p; 52500a701b1eSRobert Gordon 5251e11c3f44Smeem bzero(addrs4, sizeof (rpcib_ipaddrs_t)); 5252e11c3f44Smeem bzero(addrs6, sizeof (rpcib_ipaddrs_t)); 52530a701b1eSRobert Gordon 5254e11c3f44Smeem if (rpcib_do_lifconf(&lifc, &bufsize) != 0) 5255e11c3f44Smeem return (B_FALSE); 5256e11c3f44Smeem 5257e11c3f44Smeem if ((nifs = lifc.lifc_len / sizeof (struct lifreq)) == 0) { 5258e11c3f44Smeem kmem_free(lifc.lifc_buf, bufsize); 5259e11c3f44Smeem return (B_FALSE); 52600a701b1eSRobert Gordon } 52610a701b1eSRobert Gordon 5262e11c3f44Smeem /* 5263e11c3f44Smeem * Worst case is that all of the addresses are IB-capable and have 5264e11c3f44Smeem * the same address family, so size our buffers accordingly. 5265e11c3f44Smeem */ 5266e11c3f44Smeem addrs4->ri_size = nifs * sizeof (struct sockaddr_in); 5267e11c3f44Smeem addrs4->ri_list = kmem_zalloc(addrs4->ri_size, KM_SLEEP); 5268e11c3f44Smeem addrs6->ri_size = nifs * sizeof (struct sockaddr_in6); 5269e11c3f44Smeem addrs6->ri_list = kmem_zalloc(addrs6->ri_size, KM_SLEEP); 52700a701b1eSRobert Gordon 5271e11c3f44Smeem for (lifrp = lifc.lifc_req, i = 0; i < nifs; i++, lifrp++) { 5272e11c3f44Smeem if (!rpcib_rdma_capable_interface(lifrp)) 5273e11c3f44Smeem continue; 5274e11c3f44Smeem 5275e11c3f44Smeem if (lifrp->lifr_addr.ss_family == AF_INET) { 5276e11c3f44Smeem sinp = addrs4->ri_list; 5277e11c3f44Smeem bcopy(&lifrp->lifr_addr, &sinp[addrs4->ri_count++], 5278e11c3f44Smeem sizeof (struct sockaddr_in)); 5279e11c3f44Smeem } else if (lifrp->lifr_addr.ss_family == AF_INET6) { 5280e11c3f44Smeem sin6p = addrs6->ri_list; 5281e11c3f44Smeem bcopy(&lifrp->lifr_addr, &sin6p[addrs6->ri_count++], 5282e11c3f44Smeem sizeof (struct sockaddr_in6)); 5283e11c3f44Smeem } 52840a701b1eSRobert Gordon } 52850a701b1eSRobert Gordon 5286e11c3f44Smeem kmem_free(lifc.lifc_buf, bufsize); 5287e11c3f44Smeem return (B_TRUE); 52880a701b1eSRobert Gordon } 52890a701b1eSRobert Gordon 52900a701b1eSRobert Gordon /* ARGSUSED */ 52917f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States static int 52927f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib_cache_kstat_update(kstat_t *ksp, int rw) 52937f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States { 52947f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rib_hca_t *hca; 52950a701b1eSRobert Gordon 52960a701b1eSRobert Gordon if (KSTAT_WRITE == rw) { 52970a701b1eSRobert Gordon return (EACCES); 52980a701b1eSRobert Gordon } 52997f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 53000a701b1eSRobert Gordon rpcib_kstat.cache_limit.value.ui64 = 53010a701b1eSRobert Gordon (uint64_t)cache_limit; 53027f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_enter(&rib_stat->hcas_list_lock, RW_READER); 53037f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States for (hca = rib_stat->hcas_list; hca; hca = hca->next) { 53047f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib_kstat.cache_allocation.value.ui64 += 53057f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (uint64_t)hca->cache_allocation; 53067f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib_kstat.cache_hits.value.ui64 += 53077f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (uint64_t)hca->cache_hits; 53087f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib_kstat.cache_misses.value.ui64 += 53097f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (uint64_t)hca->cache_misses; 53107f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rpcib_kstat.cache_misses_above_the_limit.value.ui64 += 53117f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States (uint64_t)hca->cache_misses_above_the_limit; 53127f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States } 53137f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States rw_exit(&rib_stat->hcas_list_lock); 53140a701b1eSRobert Gordon return (0); 53150a701b1eSRobert Gordon } 5316