c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * CDDL HEADER START
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * The contents of this file are subject to the terms of the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Common Development and Distribution License (the "License").
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * You may not use this file except in compliance with the License.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * See the License for the specific language governing permissions
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * and limitations under the License.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * When distributing Covered Code, include this CDDL HEADER in each
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If applicable, add the following below this CDDL HEADER, with the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * fields enclosed by brackets "[]" replaced with your own identifying
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * information: Portions Copyright [yyyy] [name of copyright owner]
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * CDDL HEADER END
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otaextern unsigned int ip_ocsum(ushort_t *address, int halfword_count,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota unsigned int sum);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Check if the IP interface named by `lifrp' is RDS-capable.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_capable_interface", "Enter");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Strip off the logical interface portion before getting
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * intimate with the name.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (void) strlcpy(ifname, lifrp->lifr_name, LIFNAMSIZ);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * loopback is considered RDS-capable
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (ddi_parse(ifname, drv, &ppa) == DDI_SUCCESS &&
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_do_ip_ioctl(ksocket_t so4, void **ipaddrs, int *size, int *nifs)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* snapshot the current number of interfaces */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota lifn.lifn_flags = LIFC_NOXMIT | LIFC_TEMPORARY | LIFC_ALLZONES;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rval = ksocket_ioctl(so4, SIOCGLIFNUM, (intptr_t)&lifn, &rval,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rval != 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_do_ip_ioctl", "No interfaces found");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* allocate extra room in case more interfaces appear */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* get the interface names and ip addresses */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota lifc.lifc_flags = LIFC_NOXMIT | LIFC_TEMPORARY | LIFC_ALLZONES;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rc = ksocket_ioctl(so4, SIOCGLIFCONF, (intptr_t)&lifc, &rval, CRED());
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rc != 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_do_ip_ioctl", "SIOCGLIFCONF failed");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* if our extra room is used up, try again */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* calc actual number of ifconfs */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Count the RDS interfaces
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota for (i = 0, j = 0, lp = lifc.lifc_req; i < n; i++, lp++) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copy as the SIOCGLIFFLAGS ioctl is destructive
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * fetch the flags using the socket of the correct family
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rc = ksocket_ioctl(so4, SIOCGLIFFLAGS, (intptr_t)&lifr,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rc != 0) continue;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If we got the flags, skip uninteresting
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * interfaces based on flags
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (j <= 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_do_ip_ioctl", "No RDS interfaces");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* This is the buffer we pass back */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Examine the array of interfaces and filter uninteresting ones
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota for (i = 0, lp = lifc.lifc_req; i < n; i++, lp++) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copy the address as the SIOCGLIFFLAGS ioctl is destructive
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * fetch the flags using the socket of the correct family
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rc = ksocket_ioctl(so4, SIOCGLIFFLAGS, (intptr_t)&lifr,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rc != 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If we got the flags, skip uninteresting
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * interfaces based on flags
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* save the record */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Check if the IP interface named by `ifrp' is RDS-capable.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_capable_interface_old", "Enter");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Strip off the logical interface portion before getting
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * intimate with the name.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_capable_interface_old", "ifname: %s", ifname);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * loopback and IB are considered RDS-capable
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (ddi_parse(ifname, drv, &ppa) == DDI_SUCCESS &&
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_do_ip_ioctl_old(ksocket_t so4, void **ipaddrs, int *size, int *nifs)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rval = ksocket_ioctl(so4, SIOCGIFNUM, (intptr_t)&ifn, &rval,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rval != 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_do_ip_ioctl_old", "No interfaces found");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* allocate extra room in case more interfaces appear */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* get the interface names and ip addresses */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rc = ksocket_ioctl(so4, SIOCGIFCONF, (intptr_t)&ifc, &rval, CRED());
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rc != 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* if our extra room is used up, try again */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* calc actual number of ifconfs */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Count the RDS interfaces
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota for (i = 0, j = 0, lp = ifc.ifc_req; i < n; i++, lp++) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copy as the SIOCGIFFLAGS ioctl is destructive
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * fetch the flags using the socket of the correct family
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rc = ksocket_ioctl(so4, SIOCGIFFLAGS, (intptr_t)&ifr,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rc != 0) continue;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If we got the flags, skip uninteresting
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * interfaces based on flags
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if ((((ushort_t)ifr.ifr_flags) & IFF_UP) != IFF_UP)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (j <= 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_do_ip_ioctl_old", "No RDS interfaces");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* This is the buffer we pass back */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Examine the array of interfaces and filter uninteresting ones
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copy the address as the SIOCGIFFLAGS ioctl is destructive
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * fetch the flags using the socket of the correct family
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rc = ksocket_ioctl(so4, SIOCGIFFLAGS, (intptr_t)&ifr,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rc != 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "ksocket_ioctl failed: %d for %s",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If we got the flags, skip uninteresting
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * interfaces based on flags
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if ((((ushort_t)ifr.ifr_flags) & IFF_UP) != IFF_UP)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* save the record */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ipst = netstack_find_by_zoneid(GLOBAL_ZONEID)->netstack_ip;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Work Queue Implementation
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* worker thread */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_worker_thread", "Enter(wq: 0x%p)", wq);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* process work */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* No more work, go home, until called again */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_worker_thread", "Return(wq: 0x%p)", wq);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_flush_workqueue", "Enter(wq: %p)", wq);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* nothing to do */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* FALLTHRU */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* already flushing, wait until the flushing is complete */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota } while (wq->wq_state == RDSV3_WQ_THREAD_FLUSHING);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_flush_workqueue", "Return(wq: %p)", wq);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_queue_work(rdsv3_workqueue_struct_t *wq, rdsv3_work_t *wp)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_queue_work", "Enter(wq: %p, wp: %p)", wq, wp);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* This is already in the queue, ignore this call */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF3("rdsv3_queue_work", "already queued: %p", wp);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota } while (wq->wq_state == RDSV3_WQ_THREAD_FLUSHING);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* FALLTHRU */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (void) ddi_taskq_dispatch(rdsv3_taskq, rdsv3_worker_thread, wq,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_queue_work", "Return(wq: %p, wp: %p)", wq, wp);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* timeout handler for delayed work queuing */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_delayed_work_t *dwp = (rdsv3_delayed_work_t *)arg;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (dwp->wq->wq_state == RDSV3_WQ_THREAD_EXITING) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_queue_delayed_work(rdsv3_workqueue_struct_t *wq,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "WQ exiting - don't queue (wq: %p, wp: %p)", wq, dwp);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota dwp->timeid = timeout(rdsv3_work_timeout_handler, dwp,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_queue_delayed_work", "Already queued: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_cancel_delayed_work(rdsv3_delayed_work_t *dwp)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "Nothing to cancel (wq: %p, dwp: %p)", dwp->wq, dwp);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_destroy_task_workqueue(rdsv3_workqueue_struct_t *wq)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_destroy_workqueue", "Enter");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_destroy_workqueue", "Return");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* ARGSUSED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("create_singlethread_workqueue", "Enter (dip: %p)",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_taskq = ddi_taskq_create(rdsv3_dev_info, name,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "ddi_taskq_create failed for rdsv3_taskq");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota wq = kmem_zalloc(sizeof (rdsv3_workqueue_struct_t), KM_NOSLEEP);
6e18d381c642549b8bb1774a803d3510aec6baafagiri RDSV3_DPRINTF2(__FILE__, "kmem_zalloc failed for wq");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota list_create(&wq->wq_queue, sizeof (struct rdsv3_work_s),
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota mutex_init(&wq->wq_lock, NULL, MUTEX_DRIVER, NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("create_singlethread_workqueue", "Return");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Implementation for struct sock
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_sock_exit_data", "rs: %p sk: %p", rs, sk);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota kmem_free(sk->sk_sleep, sizeof (rdsv3_wait_queue_t));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_sock_exit_data", "rs: %p sk: %p", rs, sk);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* XXX - figure out right values */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota sk = kmem_cache_alloc(rdsv3_alloc_cache, KM_SLEEP);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("rdsv3_create", "kmem_cache_alloc failed");
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota bzero(sk, sizeof (struct rsock) + sizeof (struct rdsv3_sock));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota sk->sk_sleep = kmem_zalloc(sizeof (rdsv3_wait_queue_t), KM_SLEEP);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota mutex_init(&sk->sk_lock, NULL, MUTEX_DRIVER, NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Connection cache
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* ARGSUSED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_conn_constructor(void *buf, void *arg, int kmflags)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota mutex_init(&conn->c_lock, NULL, MUTEX_DRIVER, NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota mutex_init(&conn->c_send_lock, NULL, MUTEX_DRIVER, NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota list_create(&conn->c_send_queue, sizeof (struct rdsv3_message),
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota list_create(&conn->c_retrans, sizeof (struct rdsv3_message),
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* ARGSUSED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_conn_compare(const void *conn1, const void *conn2)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota laddr2 = ((struct rdsv3_connection *)conn2)->c_laddr;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota faddr2 = ((struct rdsv3_connection *)conn2)->c_faddr;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (-1);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (1);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (-1);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (1);
d2b539e744e90927cf7a57df3475145c279d68f9agiri/* rdsv3_ib_incoming cache */
d2b539e744e90927cf7a57df3475145c279d68f9agiri/* ARGSUSED */
d2b539e744e90927cf7a57df3475145c279d68f9agirirdsv3_ib_inc_constructor(void *buf, void *arg, int kmflags)
d2b539e744e90927cf7a57df3475145c279d68f9agiri list_create(&((struct rdsv3_ib_incoming *)buf)->ii_frags,
d2b539e744e90927cf7a57df3475145c279d68f9agiri sizeof (struct rdsv3_page_frag),
d2b539e744e90927cf7a57df3475145c279d68f9agiri return (0);
d2b539e744e90927cf7a57df3475145c279d68f9agiri/* ARGSUSED */
d2b539e744e90927cf7a57df3475145c279d68f9agiri list_destroy(&((struct rdsv3_ib_incoming *)buf)->ii_frags);
d2b539e744e90927cf7a57df3475145c279d68f9agiri/* ib_frag_slab cache */
d2b539e744e90927cf7a57df3475145c279d68f9agiri/* ARGSUSED */
d2b539e744e90927cf7a57df3475145c279d68f9agirirdsv3_ib_frag_constructor(void *buf, void *arg, int kmflags)
d2b539e744e90927cf7a57df3475145c279d68f9agiri struct rdsv3_page_frag *frag = (struct rdsv3_page_frag *)buf;
d2b539e744e90927cf7a57df3475145c279d68f9agiri struct rdsv3_ib_device *rds_ibdev = (struct rdsv3_ib_device *)arg;
d2b539e744e90927cf7a57df3475145c279d68f9agiri return (-1);
d2b539e744e90927cf7a57df3475145c279d68f9agiri if (ibt_map_mem_iov(ib_get_ibt_hca_hdl(rds_ibdev->dev),
d2b539e744e90927cf7a57df3475145c279d68f9agiri "ibt_map_mem_iov failed");
d2b539e744e90927cf7a57df3475145c279d68f9agiri return (-1);
d2b539e744e90927cf7a57df3475145c279d68f9agiri return (0);
d2b539e744e90927cf7a57df3475145c279d68f9agiri/* ARGSUSED */
d2b539e744e90927cf7a57df3475145c279d68f9agiri struct rdsv3_page_frag *frag = (struct rdsv3_page_frag *)buf;
d2b539e744e90927cf7a57df3475145c279d68f9agiri struct rdsv3_ib_device *rds_ibdev = (struct rdsv3_ib_device *)arg;
d2b539e744e90927cf7a57df3475145c279d68f9agiri /* unmap the page */
d2b539e744e90927cf7a57df3475145c279d68f9agiri if (ibt_unmap_mem_iov(ib_get_ibt_hca_hdl(rds_ibdev->dev),
d2b539e744e90927cf7a57df3475145c279d68f9agiri "ibt_unmap_mem_iov failed");
d2b539e744e90927cf7a57df3475145c279d68f9agiri /* free the page */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota list_create(&loop_conns, sizeof (struct rdsv3_loop_connection),
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota offsetof(struct rdsv3_loop_connection, loop_node));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota mutex_init(&loop_conns_lock, NULL, MUTEX_DRIVER, NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* IB Rkey is used here for comparison */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (-1);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (1);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* currently, only IB transport */
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota for (i = 0; i < RDS_TRANS_COUNT; i++) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* trans->exit() will remove the trans from the list */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_put_cmsg(struct nmsghdr *msg, int level, int type, size_t size,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "Enter(msg: %p level: %d type: %d sz: %d)",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* check for first cmsg or this is another cmsg to be appended */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* extend the existing cmsg to append the next cmsg */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota kmem_free(msg->msg_control, (size_t)msg->msg_controllen);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* assign payload the proper cmsg location */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (unsigned int)_CMSG_DATA_ALIGN(sizeof (struct cmsghdr)));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_put_cmsg", "Return(cmsg_len: %d)", cp->cmsg_len);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* ARGSUSED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (1);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* checksum */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0xffff &
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (uint16_t)(~ip_ocsum((ushort_t *)hdr, (int)length <<1, 0)));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* scatterlist implementation */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* ARGSUSED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_sg_dma_address(ib_device_t *dev, struct rdsv3_scatterlist *scat,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_dma_map_sg(struct ib_device *dev, struct rdsv3_scatterlist *scat,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_dma_map_sg", "scat %p, num: %d", scat, num);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota iov = kmem_alloc(num * sizeof (ibt_iov_t), KM_SLEEP);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota sgl = kmem_zalloc((num * 2) * sizeof (ibt_wr_ds_t), KM_SLEEP);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota for (i = 0; i < num; i++, s++) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "ibt_map_mem_iov returned: %d", i);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_dma_unmap_sg(ib_device_t *dev, struct rdsv3_scatterlist *scat,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Zero length messages have no scatter gather entries */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (num != 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (void) ibt_unmap_mem_iov(ib_get_ibt_hca_hdl(dev), scat->mihdl);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota kmem_free(scat->sgl, (num * 2) * sizeof (ibt_wr_ds_t));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_alloc_hdrs(ib_device_t *dev, struct rdsv3_ib_connection *ic)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_alloc_hdrs", "Enter(dev: %p)", dev);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota size = (ic->i_send_ring.w_nr + ic->i_recv_ring.w_nr + 1) *
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota sizeof (struct rdsv3_header);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (-1);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ret = ibt_register_mr(ib_get_ibt_hca_hdl(dev), RDSV3_PD2PDHDL(ic->i_pd),
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (-1);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (struct rdsv3_hdrs_mr *)kmem_alloc(sizeof (struct rdsv3_hdrs_mr),
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (ic->i_send_ring.w_nr * sizeof (struct rdsv3_header)));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (ic->i_send_ring.w_nr * sizeof (struct rdsv3_header)));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota sizeof (struct rdsv3_header)));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota sizeof (struct rdsv3_header)));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_alloc_hdrs", "Return(dev: %p)", dev);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_free_hdrs(ib_device_t *dev, struct rdsv3_ib_connection *ic)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_free_hdrs", "Enter(dev: %p)", dev);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (void) ibt_deregister_mr(ib_get_ibt_hca_hdl(dev), ic->i_mr->hdl);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota kmem_free(ic->i_mr, sizeof (struct rdsv3_hdrs_mr));
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_free_hdrs", "Return(dev: %p)", dev);
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota * atomic_add_unless - add unless the number is a given value
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota * @v: pointer of type atomic_t
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota * @a: the amount to add to v...
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota * @u: ...unless v is equal to u.
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota * Atomically adds @a to @v, so long as it was not @u.
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota * Returns non-zero if @v was not @u, and zero otherwise.
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota while (c != u && (old = atomic_cas_uint(v, c, c + a)) != c) {
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota return ((ulong_t)c != u);