ibcm_arp.c revision bd670b35a010421b6e1a5536c34453a827007c81
015f8fff605f2fbd5fd0072e555576297804d57bhiremath/*
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * CDDL HEADER START
015f8fff605f2fbd5fd0072e555576297804d57bhiremath *
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * The contents of this file are subject to the terms of the
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * Common Development and Distribution License (the "License").
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * You may not use this file except in compliance with the License.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath *
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * or http://www.opensolaris.org/os/licensing.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * See the License for the specific language governing permissions
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * and limitations under the License.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath *
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * When distributing Covered Code, include this CDDL HEADER in each
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * If applicable, add the following below this CDDL HEADER, with the
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * fields enclosed by brackets "[]" replaced with your own identifying
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * information: Portions Copyright [yyyy] [name of copyright owner]
015f8fff605f2fbd5fd0072e555576297804d57bhiremath *
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * CDDL HEADER END
015f8fff605f2fbd5fd0072e555576297804d57bhiremath */
015f8fff605f2fbd5fd0072e555576297804d57bhiremath/*
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * Use is subject to license terms.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath */
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath#include <sys/types.h>
015f8fff605f2fbd5fd0072e555576297804d57bhiremath#include <sys/ddi.h>
015f8fff605f2fbd5fd0072e555576297804d57bhiremath#include <sys/sunddi.h>
015f8fff605f2fbd5fd0072e555576297804d57bhiremath#include <sys/strsubr.h>
015f8fff605f2fbd5fd0072e555576297804d57bhiremath#include <sys/socket.h>
015f8fff605f2fbd5fd0072e555576297804d57bhiremath#include <net/if_arp.h>
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem#include <net/if_types.h>
015f8fff605f2fbd5fd0072e555576297804d57bhiremath#include <sys/sockio.h>
015f8fff605f2fbd5fd0072e555576297804d57bhiremath#include <sys/pathname.h>
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath#include <sys/ib/mgt/ibcm/ibcm_arp.h>
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath#include <sys/kstr.h>
015f8fff605f2fbd5fd0072e555576297804d57bhiremath#include <sys/t_kuser.h>
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremathextern char cmlog[];
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmarkextern int ibcm_resolver_pr_lookup(ibcm_arp_streams_t *ib_s,
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark ibt_ip_addr_t *dst_addr, ibt_ip_addr_t *src_addr);
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmarkextern void ibcm_arp_delete_prwqn(ibcm_arp_prwqn_t *wqnp);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibt_ip_addr_s))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_ip_t))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_ibd_insts_t))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_prwqn_t))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", sockaddr_in))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", sockaddr_in6))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathint ibcm_printip = 0;
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath/*
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath * Function:
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath * ibcm_ip_print
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath * Input:
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath * label Arbitrary qualifying string
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath * ipa Pointer to IP Address to print
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath */
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathvoid
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathibcm_ip_print(char *label, ibt_ip_addr_t *ipaddr)
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath{
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath char buf[INET6_ADDRSTRLEN];
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath if (ipaddr->family == AF_INET) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L2(cmlog, "%s: %s", label,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath inet_ntop(AF_INET, &ipaddr->un.ip4addr, buf, sizeof (buf)));
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath } else if (ipaddr->family == AF_INET6) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L2(cmlog, "%s: %s", label, inet_ntop(AF_INET6,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath &ipaddr->un.ip6addr, buf, sizeof (buf)));
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath } else {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L2(cmlog, "%s: IP ADDR NOT SPECIFIED ", label);
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath }
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath}
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremathibt_status_t
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathibcm_arp_get_ibaddr(ibt_ip_addr_t srcaddr, ibt_ip_addr_t destaddr,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath ib_gid_t *sgid, ib_gid_t *dgid)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath{
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibcm_arp_streams_t *ib_s;
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath ibcm_arp_prwqn_t *wqnp;
bbd6719318c24a8a2364080d8a139444e9944311hiremath int ret = 0;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibaddr(%p, %p, %p, %p)",
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath srcaddr, destaddr, sgid, dgid);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ib_s = (ibcm_arp_streams_t *)kmem_zalloc(sizeof (ibcm_arp_streams_t),
015f8fff605f2fbd5fd0072e555576297804d57bhiremath KM_SLEEP);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath mutex_init(&ib_s->lock, NULL, MUTEX_DEFAULT, NULL);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath cv_init(&ib_s->cv, NULL, CV_DRIVER, NULL);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
bbd6719318c24a8a2364080d8a139444e9944311hiremath mutex_enter(&ib_s->lock);
bbd6719318c24a8a2364080d8a139444e9944311hiremath ib_s->done = B_FALSE;
bbd6719318c24a8a2364080d8a139444e9944311hiremath mutex_exit(&ib_s->lock);
bbd6719318c24a8a2364080d8a139444e9944311hiremath
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark ret = ibcm_resolver_pr_lookup(ib_s, &destaddr, &srcaddr);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibaddr: ibcm_resolver_pr_lookup "
015f8fff605f2fbd5fd0072e555576297804d57bhiremath "returned: %d", ret);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ret == 0) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath mutex_enter(&ib_s->lock);
bbd6719318c24a8a2364080d8a139444e9944311hiremath while (ib_s->done != B_TRUE)
bbd6719318c24a8a2364080d8a139444e9944311hiremath cv_wait(&ib_s->cv, &ib_s->lock);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath mutex_exit(&ib_s->lock);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
bbd6719318c24a8a2364080d8a139444e9944311hiremath mutex_enter(&ib_s->lock);
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath wqnp = ib_s->wqnp;
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath if (ib_s->status == 0) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (sgid)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath *sgid = ib_s->wqnp->sgid;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (dgid)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath *dgid = ib_s->wqnp->dgid;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibaddr: SGID: %llX:%llX"
015f8fff605f2fbd5fd0072e555576297804d57bhiremath " DGID: %llX:%llX",
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ib_s->wqnp->sgid.gid_prefix, ib_s->wqnp->sgid.gid_guid,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ib_s->wqnp->dgid.gid_prefix, ib_s->wqnp->dgid.gid_guid);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark ibcm_arp_delete_prwqn(wqnp);
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath } else if (ret == 0) {
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath /*
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath * We come here only when lookup has returned empty (failed)
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark * via callback routine.
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath * i.e. ib_s->status is non-zero, while ret is zero.
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath */
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath if (wqnp)
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath kmem_free(wqnp, sizeof (ibcm_arp_prwqn_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath ret = ib_s->status;
bbd6719318c24a8a2364080d8a139444e9944311hiremath mutex_exit(&ib_s->lock);
bbd6719318c24a8a2364080d8a139444e9944311hiremath
bbd6719318c24a8a2364080d8a139444e9944311hirematharp_ibaddr_error:
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath mutex_destroy(&ib_s->lock);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath cv_destroy(&ib_s->cv);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath kmem_free(ib_s, sizeof (ibcm_arp_streams_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ret)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (IBT_FAILURE);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath else
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (IBT_SUCCESS);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath}
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath/*
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * Routine to get list of "local" IP-ADDR to GID/P_KEY mapping information.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * Optionally, if "gid" and/or "p_key" info are specified, then retrieve the
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * IP-ADDR info for that attribute only.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath */
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremathstatic ibcm_arp_ip_t *
015f8fff605f2fbd5fd0072e555576297804d57bhiremathibcm_arp_ibd_gid2mac(ib_gid_t *gid, ib_pkey_t pkey, ibcm_arp_ibd_insts_t *ibdp)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath{
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibcm_arp_ip_t *ipp;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath int i;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath for (i = 0, ipp = ibdp->ibcm_arp_ip; i < ibdp->ibcm_arp_ibd_cnt;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath i++, ipp++) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if ((ipp->ip_port_gid.gid_prefix == gid->gid_prefix) &&
015f8fff605f2fbd5fd0072e555576297804d57bhiremath (ipp->ip_port_gid.gid_guid == gid->gid_guid)) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (pkey) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ipp->ip_pkey == pkey)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (ipp);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath else
015f8fff605f2fbd5fd0072e555576297804d57bhiremath continue;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (ipp);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (NULL);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath}
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremathstatic ibt_status_t
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathibcm_arp_ibd_mac2gid(ibcm_arp_ibd_insts_t *ibdp, ibt_ip_addr_t *srcip,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ib_gid_t *sgid)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath{
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibcm_arp_ip_t *ipp;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath int i;
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath boolean_t found = B_FALSE;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath for (i = 0, ipp = ibdp->ibcm_arp_ip; i < ibdp->ibcm_arp_ibd_cnt;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath i++, ipp++) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_ibd_mac2gid: GID %llX:%llX",
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ipp->ip_port_gid.gid_prefix, ipp->ip_port_gid.gid_guid);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath if (srcip->family == ipp->ip_inet_family) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath if ((srcip->family == AF_INET) &&
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath (bcmp(&srcip->un.ip4addr, &ipp->ip_cm_sin.sin_addr,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath sizeof (in_addr_t)) == 0)) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath found = B_TRUE;
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath } else if ((srcip->family == AF_INET6) &&
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IN6_ARE_ADDR_EQUAL(&srcip->un.ip6addr,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath &ipp->ip_cm_sin6.sin6_addr)) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath found = B_TRUE;
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath }
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath if (found) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath *sgid = ipp->ip_port_gid;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_ibd_mac2gid: "
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath "Found GID %llX:%llX", sgid->gid_prefix,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath sgid->gid_guid);
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath return (IBT_SUCCESS);
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath }
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath } else {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L3(cmlog, "ibcm_arp_ibd_mac2gid: Different"
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath " family keep searching...");
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L3(cmlog, "ibcm_arp_ibd_mac2gid: Matching SRC info "
015f8fff605f2fbd5fd0072e555576297804d57bhiremath "NOT Found");
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (IBT_SRC_IP_NOT_FOUND);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath}
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremathstatic int
015f8fff605f2fbd5fd0072e555576297804d57bhiremathibcm_arp_get_ibd_insts_cb(dev_info_t *dip, void *arg)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath{
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibcm_arp_ibd_insts_t *ibds = (ibcm_arp_ibd_insts_t *)arg;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibcm_arp_ip_t *ipp;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ib_pkey_t pkey;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath uint8_t port;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ib_guid_t hca_guid;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ib_gid_t port_gid;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (i_ddi_devi_attached(dip) &&
015f8fff605f2fbd5fd0072e555576297804d57bhiremath (strcmp(ddi_node_name(dip), "ibport") == 0) &&
015f8fff605f2fbd5fd0072e555576297804d57bhiremath (strstr(ddi_get_name_addr(dip), "ipib") != NULL)) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ibds->ibcm_arp_ibd_cnt >= ibds->ibcm_arp_ibd_alloc) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibcm_arp_ip_t *tmp = NULL;
6db9d0a6a95a320cf284a92628509b477c79f7d9hiremath uint8_t new_count;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath new_count = ibds->ibcm_arp_ibd_alloc +
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBCM_ARP_IBD_INSTANCES;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath tmp = (ibcm_arp_ip_t *)kmem_zalloc(
015f8fff605f2fbd5fd0072e555576297804d57bhiremath new_count * sizeof (ibcm_arp_ip_t), KM_SLEEP);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath bcopy(ibds->ibcm_arp_ip, tmp,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibds->ibcm_arp_ibd_alloc * sizeof (ibcm_arp_ip_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath kmem_free(ibds->ibcm_arp_ip,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibds->ibcm_arp_ibd_alloc * sizeof (ibcm_arp_ip_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibds->ibcm_arp_ibd_alloc = new_count;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibds->ibcm_arp_ip = tmp;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (((hca_guid = ddi_prop_get_int64(DDI_DEV_T_ANY, dip, 0,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath "hca-guid", 0)) == 0) ||
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ((port = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 0,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath "port-number", 0)) == 0) ||
015f8fff605f2fbd5fd0072e555576297804d57bhiremath (ibt_get_port_state_byguid(hca_guid, port, &port_gid,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath NULL) != IBT_SUCCESS) ||
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ((pkey = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 0,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath "port-pkey", IB_PKEY_INVALID_LIMITED)) <=
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IB_PKEY_INVALID_FULL)) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (DDI_WALK_CONTINUE);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ipp = &ibds->ibcm_arp_ip[ibds->ibcm_arp_ibd_cnt];
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ipp->ip_inst = ddi_get_instance(dip);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ipp->ip_pkey = pkey;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ipp->ip_hca_guid = hca_guid;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ipp->ip_port_gid = port_gid;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibds->ibcm_arp_ibd_cnt++;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (DDI_WALK_CONTINUE);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath}
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremathstatic void
015f8fff605f2fbd5fd0072e555576297804d57bhiremathibcm_arp_get_ibd_insts(ibcm_arp_ibd_insts_t *ibds)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath{
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ddi_walk_devs(ddi_root_node(), ibcm_arp_get_ibd_insts_cb, ibds);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath}
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath/*
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Issue an ioctl down to IP. There are several similar versions of this
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * function (e.g., rpcib_do_ip_ioctl()); clearly a utility routine is needed.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath */
015f8fff605f2fbd5fd0072e555576297804d57bhiremathstatic int
e11c3f44f531fdff80941ce57c065d2ae861cefcmeemibcm_do_ip_ioctl(int cmd, int len, void *arg)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath{
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem vnode_t *kvp;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem TIUSER *tiptr;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem struct strioctl iocb;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem int err = 0;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem if (lookupname("/dev/udp", UIO_SYSSPACE, FOLLOW, NULLVPP, &kvp) != 0)
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem return (EPROTO);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem if (t_kopen(NULL, kvp->v_rdev, FREAD|FWRITE, &tiptr, CRED()) != 0) {
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem VN_RELE(kvp);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem return (EPROTO);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem iocb.ic_cmd = cmd;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem iocb.ic_timout = 0;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem iocb.ic_len = len;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem iocb.ic_dp = (caddr_t)arg;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem err = kstr_ioctl(tiptr->fp->f_vnode, I_STR, (intptr_t)&iocb);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem (void) t_kclose(tiptr, 0);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem VN_RELE(kvp);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem return (err);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem}
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem/*
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Issue an SIOCGLIFCONF down to IP and return the result in `lifcp'.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * lifcp->lifc_buf is dynamically allocated to be *bufsizep bytes.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem */
e11c3f44f531fdff80941ce57c065d2ae861cefcmeemstatic int
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathibcm_do_lifconf(struct lifconf *lifcp, uint_t *bufsizep, sa_family_t family_loc)
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem{
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem int err;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem struct lifnum lifn;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem bzero(&lifn, sizeof (struct lifnum));
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath lifn.lifn_family = family_loc;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem err = ibcm_do_ip_ioctl(SIOCGLIFNUM, sizeof (struct lifnum), &lifn);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem if (err != 0)
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem return (err);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_do_lifconf: Family %d, lifn_count %d",
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath family_loc, lifn.lifn_count);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem /*
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Pad the interface count to account for additional interfaces that
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * may have been configured between the SIOCGLIFNUM and SIOCGLIFCONF.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem */
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem lifn.lifn_count += 4;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem bzero(lifcp, sizeof (struct lifconf));
03494a9880d80f834bec10a1e8f0a2f8f7c97bf4Bill Taylor _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*lifcp))
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath lifcp->lifc_family = family_loc;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem lifcp->lifc_len = *bufsizep = lifn.lifn_count * sizeof (struct lifreq);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem lifcp->lifc_buf = kmem_zalloc(*bufsizep, KM_SLEEP);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem err = ibcm_do_ip_ioctl(SIOCGLIFCONF, sizeof (struct lifconf), lifcp);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem if (err != 0) {
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem kmem_free(lifcp->lifc_buf, *bufsizep);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem return (err);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem }
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem return (0);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem}
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem/*
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Fill in `ibds' with IP addresses tied to IFT_IB IP interfaces. Returns
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * B_TRUE if at least one address was filled in.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem */
e11c3f44f531fdff80941ce57c065d2ae861cefcmeemstatic boolean_t
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathibcm_arp_get_ibd_ipaddr(ibcm_arp_ibd_insts_t *ibds, sa_family_t family_loc)
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem{
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem int i, nifs, naddr = 0;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem uint_t bufsize;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem struct lifconf lifc;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem struct lifreq *lifrp;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem ibcm_arp_ip_t *ipp;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath if (ibcm_do_lifconf(&lifc, &bufsize, family_loc) != 0)
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem return (B_FALSE);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem nifs = lifc.lifc_len / sizeof (struct lifreq);
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibd_ipaddr: Family %d, nifs %d",
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath family_loc, nifs);
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem for (lifrp = lifc.lifc_req, i = 0;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem i < nifs && naddr < ibds->ibcm_arp_ibd_cnt; i++, lifrp++) {
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem if (lifrp->lifr_type != IFT_IB)
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem continue;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem ipp = &ibds->ibcm_arp_ip[naddr];
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem switch (lifrp->lifr_addr.ss_family) {
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem case AF_INET:
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ipp->ip_inet_family = AF_INET;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem bcopy(&lifrp->lifr_addr, &ipp->ip_cm_sin,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath sizeof (struct sockaddr_in));
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem naddr++;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem break;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem case AF_INET6:
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem ipp->ip_inet_family = AF_INET6;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem bcopy(&lifrp->lifr_addr, &ipp->ip_cm_sin6,
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem sizeof (struct sockaddr_in6));
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem naddr++;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem break;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem kmem_free(lifc.lifc_buf, bufsize);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem return (naddr > 0);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath}
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremathibt_status_t
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathibcm_arp_get_ibds(ibcm_arp_ibd_insts_t *ibdp, sa_family_t family_loc)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath{
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath#ifdef DEBUG
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath int i;
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath#endif
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds(%p)", ibdp);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibcm_arp_get_ibd_insts(ibdp);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibds: Found %d ibd instances",
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibdp->ibcm_arp_ibd_cnt);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ibdp->ibcm_arp_ibd_cnt == 0)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (IBT_SRC_IP_NOT_FOUND);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath /* Get the IP addresses of active ports. */
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath if (!ibcm_arp_get_ibd_ipaddr(ibdp, family_loc)) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_ibds: failed to get "
015f8fff605f2fbd5fd0072e555576297804d57bhiremath "ibd instance: IBT_SRC_IP_NOT_FOUND");
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (IBT_SRC_IP_NOT_FOUND);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath#ifdef DEBUG
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath for (i = 0; i < ibdp->ibcm_arp_ibd_cnt; i++) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath char my_buf[INET6_ADDRSTRLEN];
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath ibcm_arp_ip_t *aip = &ibdp->ibcm_arp_ip[i];
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds: ibd[%d]: Family %d "
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath "Instance %d PKey 0x%lX \n HCAGUID 0x%llX SGID %llX:%llX",
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath i, aip->ip_inet_family, aip->ip_inst, aip->ip_pkey,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath aip->ip_hca_guid, aip->ip_port_gid.gid_prefix,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath aip->ip_port_gid.gid_guid);
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath if (aip->ip_inet_family == AF_INET) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds: IPV4: %s",
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath inet_ntop(AF_INET, &aip->ip_cm_sin.sin_addr, my_buf,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath sizeof (my_buf)));
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath } else if (aip->ip_inet_family == AF_INET6) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds: IPV6: %s",
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath inet_ntop(AF_INET6, &aip->ip_cm_sin6.sin6_addr,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath my_buf, sizeof (my_buf)));
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath } else {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_ibds: Unknown "
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath "Family %d", aip->ip_inet_family);
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath }
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath }
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath#endif
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (IBT_SUCCESS);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath}
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibtl_cm_port_list_t))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremathibt_status_t
015f8fff605f2fbd5fd0072e555576297804d57bhiremathibcm_arp_get_srcip_plist(ibt_ip_path_attr_t *ipattr, ibt_path_flags_t flags,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibtl_cm_port_list_t **port_list_p)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath{
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibt_path_attr_t attr;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibt_status_t ret;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibcm_arp_ibd_insts_t ibds;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibcm_arp_ip_t *ipp;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibtl_cm_port_list_t *plistp;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ib_gid_t sgid;
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath sa_family_t family_interested = AF_UNSPEC;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_srcip_plist(%p, %llX)",
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ipattr, flags);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath if (ipattr->ipa_src_ip.family != AF_UNSPEC)
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath family_interested = ipattr->ipa_src_ip.family;
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath else
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath family_interested = ipattr->ipa_dst_ip[0].family;
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath sgid.gid_prefix = sgid.gid_guid = 0;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath bzero(&ibds, sizeof (ibcm_arp_ibd_insts_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibds.ibcm_arp_ibd_alloc = IBCM_ARP_IBD_INSTANCES;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibds.ibcm_arp_ibd_cnt = 0;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibds.ibcm_arp_ip = (ibcm_arp_ip_t *)kmem_zalloc(
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ibds.ibcm_arp_ibd_alloc * sizeof (ibcm_arp_ip_t), KM_SLEEP);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath ret = ibcm_arp_get_ibds(&ibds, family_interested);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ret != IBT_SUCCESS) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_srcip_plist: "
015f8fff605f2fbd5fd0072e555576297804d57bhiremath "ibcm_arp_get_ibds failed : 0x%x", ret);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath goto srcip_plist_end;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ipattr->ipa_src_ip.family != AF_UNSPEC) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath ret = ibcm_arp_ibd_mac2gid(&ibds, &ipattr->ipa_src_ip, &sgid);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ret != IBT_SUCCESS) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_srcip_plist: "
015f8fff605f2fbd5fd0072e555576297804d57bhiremath "SGID for the specified SRCIP Not found %X", ret);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath goto srcip_plist_end;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_srcip_plist: SGID "
015f8fff605f2fbd5fd0072e555576297804d57bhiremath "%llX:%llX", sgid.gid_prefix, sgid.gid_guid);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath bzero(&attr, sizeof (ibt_path_attr_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath attr.pa_hca_guid = ipattr->ipa_hca_guid;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath attr.pa_hca_port_num = ipattr->ipa_hca_port_num;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath attr.pa_sgid = sgid;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath bcopy(&ipattr->ipa_mtu, &attr.pa_mtu, sizeof (ibt_mtu_req_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath bcopy(&ipattr->ipa_srate, &attr.pa_srate, sizeof (ibt_srate_req_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath bcopy(&ipattr->ipa_pkt_lt, &attr.pa_pkt_lt, sizeof (ibt_pkt_lt_req_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ret = ibtl_cm_get_active_plist(&attr, flags, port_list_p);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ret == IBT_SUCCESS) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath int i;
6db9d0a6a95a320cf284a92628509b477c79f7d9hiremath uint8_t cnt;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath boolean_t no_srcip_configured = B_FALSE;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath uint8_t no_srcip_cnt = 0;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath plistp = port_list_p[0];
6db9d0a6a95a320cf284a92628509b477c79f7d9hiremath cnt = plistp->p_count;
6db9d0a6a95a320cf284a92628509b477c79f7d9hiremath for (i = 0; i < cnt; i++, plistp++) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ipp = ibcm_arp_ibd_gid2mac(&plistp->p_sgid, 0, &ibds);
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath if ((ipp == NULL) ||
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath (ipp->ip_inet_family == AF_UNSPEC)) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath plistp->p_src_ip.family = AF_UNSPEC;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath no_srcip_configured = B_TRUE;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath no_srcip_cnt++;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath IBTF_DPRINTF_L3(cmlog,
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath "ibcm_arp_get_srcip_plist: SrcIP NOT "
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath "Configured for GID %llX:%llX",
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath plistp->p_sgid.gid_prefix,
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath plistp->p_sgid.gid_guid);
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath } else {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L4(cmlog,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath "ibcm_arp_get_srcip_plist: GID %llX:%llX",
015f8fff605f2fbd5fd0072e555576297804d57bhiremath plistp->p_sgid.gid_prefix,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath plistp->p_sgid.gid_guid);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ipp->ip_inet_family == AF_INET) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath plistp->p_src_ip.family = AF_INET;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath bcopy(&ipp->ip_cm_sin.sin_addr,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath &plistp->p_src_ip.un.ip4addr,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath sizeof (in_addr_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath } else if (ipp->ip_inet_family == AF_INET6) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath plistp->p_src_ip.family = AF_INET6;
015f8fff605f2fbd5fd0072e555576297804d57bhiremath bcopy(&ipp->ip_cm_sin6.sin6_addr,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath &plistp->p_src_ip.un.ip6addr,
015f8fff605f2fbd5fd0072e555576297804d57bhiremath sizeof (in6_addr_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBCM_PRINT_IP("ibcm_arp_get_srcip_plist: "
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath "IP Addr is:", &plistp->p_src_ip);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath if (no_srcip_configured) {
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath ibtl_cm_port_list_t *n_plistp, *tmp_n_plistp;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath uint8_t new_cnt;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath new_cnt = cnt - no_srcip_cnt;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath /*
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath * Looks like some of the SRC GID we found have no
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath * IP ADDR configured, so remove these entries from
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath * our list.
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath */
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath plistp = port_list_p[0];
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_srcip_plist: "
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath "Only %d SGID (%d/%d) have SrcIP Configured",
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath new_cnt, no_srcip_cnt, cnt);
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath if (new_cnt) {
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath /* Allocate Memory to hold Src Point info. */
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath n_plistp = kmem_zalloc(new_cnt *
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath sizeof (ibtl_cm_port_list_t), KM_SLEEP);
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath tmp_n_plistp = n_plistp;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath for (i = 0; i < cnt; i++, plistp++) {
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath if (plistp->p_src_ip.family ==
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath AF_UNSPEC)
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath continue;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath bcopy(plistp, n_plistp,
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath sizeof (ibtl_cm_port_list_t));
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath n_plistp->p_count = new_cnt;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath n_plistp++;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath }
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath plistp = port_list_p[0];
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath *port_list_p = tmp_n_plistp;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath } else {
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath /*
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath * All entries we have, do not have IP-Addr
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath * configured so return empty hand.
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath */
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath IBTF_DPRINTF_L2(cmlog,
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath "ibcm_arp_get_srcip_plist: None of SGID "
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath "found have SrcIP Configured");
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath *port_list_p = NULL;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath ret = IBT_SRC_IP_NOT_FOUND;
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath }
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath IBTF_DPRINTF_L4(cmlog, "FREE OLD list %p, NEW list is "
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath "%p - %p", plistp, port_list_p, *port_list_p);
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath kmem_free(plistp, cnt * sizeof (ibtl_cm_port_list_t));
5c42ea03b5c1802ea660cd888be8aa70c34549c8hiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath }
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremathsrcip_plist_end:
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ibds.ibcm_arp_ip)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath kmem_free(ibds.ibcm_arp_ip, ibds.ibcm_arp_ibd_alloc *
015f8fff605f2fbd5fd0072e555576297804d57bhiremath sizeof (ibcm_arp_ip_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath
015f8fff605f2fbd5fd0072e555576297804d57bhiremath return (ret);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath}