87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg/*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * CDDL HEADER START
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg *
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * The contents of this file are subject to the terms of the
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * Common Development and Distribution License (the "License").
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * You may not use this file except in compliance with the License.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg *
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * or http://www.opensolaris.org/os/licensing.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * See the License for the specific language governing permissions
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * and limitations under the License.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg *
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * When distributing Covered Code, include this CDDL HEADER in each
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * If applicable, add the following below this CDDL HEADER, with the
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * fields enclosed by brackets "[]" replaced with your own identifying
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * information: Portions Copyright [yyyy] [name of copyright owner]
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg *
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * CDDL HEADER END
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg/*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * Use is subject to license terms.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#pragma ident "%Z%%M% %I% %E% SMI"
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg/*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * DL_IB MAC Type plugin for the Nemo mac module
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#include <sys/types.h>
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#include <sys/modctl.h>
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#include <sys/dlpi.h>
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#include <sys/ib/clients/ibd/ibd.h>
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#include <sys/mac.h>
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#include <sys/mac_ib.h>
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#include <sys/dls.h>
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#include <sys/byteorder.h>
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#include <sys/strsun.h>
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#include <inet/common.h>
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg#include <sys/note.h>
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggstatic uint8_t ib_brdcst[] = { 0x00, 0xff, 0xff, 0xff,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg 0xff, 0x10, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggstatic struct modlmisc mac_ib_modlmisc = {
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg &mod_miscops,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg "Infiniband MAC Type plugin 1.0"
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg};
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggstatic struct modlinkage mac_ib_modlinkage = {
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg MODREV_1,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg &mac_ib_modlmisc,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg NULL
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg};
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggstatic mactype_ops_t mac_ib_type_ops;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggint
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg_init(void)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg{
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mactype_register_t *mtrp;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg int err;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if ((mtrp = mactype_alloc(MACTYPE_VERSION)) == NULL)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (ENOTSUP);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mtrp->mtr_ident = MAC_PLUGIN_IDENT_IB;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mtrp->mtr_ops = &mac_ib_type_ops;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mtrp->mtr_mactype = DL_IB;
d62bc4badc1c1f1549c961cfb8b420e650e1272byz mtrp->mtr_nativetype = DL_IB;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mtrp->mtr_addrlen = IPOIB_ADDRL;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mtrp->mtr_brdcst_addr = ib_brdcst;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg /*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * So far, generic stats maintained by GLDv3 are sufficient for IB.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mtrp->mtr_stats = NULL;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mtrp->mtr_statcount = 0;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if ((err = mactype_register(mtrp)) == 0) {
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if ((err = mod_install(&mac_ib_modlinkage)) != 0)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg (void) mactype_unregister(MAC_PLUGIN_IDENT_IB);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg }
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mactype_free(mtrp);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (err);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg}
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggint
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg_fini(void)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg{
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg int err;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if ((err = mactype_unregister(MAC_PLUGIN_IDENT_IB)) != 0)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (err);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (mod_remove(&mac_ib_modlinkage));
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg}
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggint
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg_info(struct modinfo *modinfop)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg{
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (mod_info(&mac_ib_modlinkage, modinfop));
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg}
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg/*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * MAC Type plugin operations
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg/* ARGSUSED */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggint
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggmac_ib_unicst_verify(const void *addr, void *mac_pdata)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg{
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg ipoib_mac_t *ibaddr = (ipoib_mac_t *)addr;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg /*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * The address must not be a multicast address.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (ntohl(ibaddr->ipoib_qpn) == IB_MC_QPN ? EINVAL : 0);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg}
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggint
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggmac_ib_multicst_verify(const void *addr, void *mac_pdata)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg{
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg ipoib_mac_t *ibaddr = (ipoib_mac_t *)addr;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg uint8_t *p_gid = (uint8_t *)addr + sizeof (ipoib_mac_t)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg - MAC_IB_GID_SIZE;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg uint32_t bcst_gid[3] = { 0x0, 0x0, MAC_IB_BROADCAST_GID };
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg _NOTE(ARGUNUSED(mac_pdata));
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg /*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * The address must be a multicast address.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if ((ntohl(ibaddr->ipoib_qpn) & IB_QPN_MASK) != IB_MC_QPN)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (EINVAL);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg /*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * The address must not be the broadcast address.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (bcmp(p_gid, (uint8_t *)bcst_gid + sizeof (bcst_gid) -
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg MAC_IB_GID_SIZE, MAC_IB_GID_SIZE) == 0)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (EINVAL);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (0);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg}
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg/*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * Check the legality of a SAP value. The following values are
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * allowed, as specified by PSARC 2003/150:
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg *
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * min-ethertype-sap (256).. EtherType max(65535) ethertype semantics
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * (0) .. max-802-sap(255) IEEE 802 semantics
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggboolean_t
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggmac_ib_sap_verify(uint32_t sap, uint32_t *bind_sap, void *mac_pdata)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg{
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg _NOTE(ARGUNUSED(mac_pdata));
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (sap > MAC_IB_MAX_802_SAP && sap <= MAC_IB_ETHERTYPE_MAX) {
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (bind_sap != NULL)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg *bind_sap = sap;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (B_TRUE);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg }
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (sap <= MAC_IB_MAX_802_SAP) {
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (bind_sap != NULL)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg *bind_sap = DLS_SAP_LLC;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (B_TRUE);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg }
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (B_FALSE);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg}
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg/* ARGSUSED */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggmblk_t *
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggmac_ib_header(const void *saddr, const void *daddr, uint32_t sap,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg void *mac_pdata, mblk_t *payload, size_t extra_len)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg{
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg ib_header_info_t *ibhp;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mblk_t *mp;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (!mac_ib_sap_verify(sap, NULL, NULL))
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (NULL);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mp = allocb(sizeof (ib_header_info_t) + extra_len, BPRI_HI);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (mp == NULL)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (NULL);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
22eb7cb54d8a6bcf6fe2674cb4b1f0cf2d85cfb6gd ibhp = (void *)mp->b_rptr;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg ibhp->ipib_rhdr.ipoib_type = htons(sap);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg ibhp->ipib_rhdr.ipoib_mbz = 0;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg bcopy(daddr, &ibhp->ib_dst, IPOIB_ADDRL);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mp->b_wptr += sizeof (ib_header_info_t);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (mp);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg}
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggint
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggmac_ib_header_info(mblk_t *mp, void *mac_pdata, mac_header_info_t *hdr_info)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg{
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg ib_header_info_t *ibhp;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg uint16_t sap;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (MBLKL(mp) < sizeof (ib_header_info_t))
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (EINVAL);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
22eb7cb54d8a6bcf6fe2674cb4b1f0cf2d85cfb6gd ibhp = (void *)mp->b_rptr;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg hdr_info->mhi_hdrsize = sizeof (ib_header_info_t);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg hdr_info->mhi_daddr = (const uint8_t *)&(ibhp->ib_dst);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (ibhp->ib_grh.ipoib_vertcflow != 0)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg hdr_info->mhi_saddr = (const uint8_t *)&(ibhp->ib_src);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg else
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg hdr_info->mhi_saddr = NULL;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (mac_ib_unicst_verify(hdr_info->mhi_daddr, mac_pdata) == 0) {
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg hdr_info->mhi_dsttype = MAC_ADDRTYPE_UNICAST;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg } else if (mac_ib_multicst_verify(hdr_info->mhi_daddr,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mac_pdata) == 0) {
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg hdr_info->mhi_dsttype = MAC_ADDRTYPE_MULTICAST;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg } else {
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg hdr_info->mhi_dsttype = MAC_ADDRTYPE_BROADCAST;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg }
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg sap = ntohs(ibhp->ipib_rhdr.ipoib_type);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg hdr_info->mhi_origsap = hdr_info->mhi_bindsap = sap;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg hdr_info->mhi_pktsize = 0;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (0);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg}
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg/*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * Take the provided `mp' (which is expected to have a header "dst + type"),
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * and return a pointer to an mblk_t with a header "GRH + type".
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * If the conversion cannot be performed, return NULL.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggstatic mblk_t *
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggmac_ib_header_cook(mblk_t *mp, void *pdata)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg{
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg ipoib_ptxhdr_t *orig_hp;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mblk_t *llmp;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (MBLKL(mp) < sizeof (ipoib_ptxhdr_t))
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (NULL);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
22eb7cb54d8a6bcf6fe2674cb4b1f0cf2d85cfb6gd orig_hp = (void *)mp->b_rptr;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg llmp = mac_ib_header(NULL, &orig_hp->ipoib_dest,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg ntohs(orig_hp->ipoib_rhdr.ipoib_type), pdata, NULL, 0);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg if (llmp == NULL)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (NULL);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg /*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * The plugin framework guarantees that we have the only reference
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * to the mblk_t, so we can safely modify it.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg ASSERT(DB_REF(mp) == 1);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mp->b_rptr += sizeof (ipoib_ptxhdr_t);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg llmp->b_cont = mp;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (llmp);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg}
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg/*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * Take the provided `mp' (which is expected to have a header "GRH + type"),
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * and return a pointer to an mblk_t with a header "type". If the conversion
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * cannot be performed, return NULL.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggstatic mblk_t *
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggmac_ib_header_uncook(mblk_t *mp, void *pdata)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg{
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg _NOTE(ARGUNUSED(pdata));
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg /*
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * The plugin framework guarantees that we have the only reference to
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg * the mblk_t and the underlying dblk_t, so we can safely modify it.
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg ASSERT(DB_REF(mp) == 1);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mp->b_rptr += sizeof (ib_addrs_t);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg return (mp);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg}
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggvoid
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggmac_ib_link_details(char *buf, size_t sz, mac_handle_t mh, void *mac_pdata)
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg{
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg uint64_t speed;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg _NOTE(ARGUNUSED(mac_pdata));
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg speed = mac_stat_get(mh, MAC_STAT_IFSPEED);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg /* convert to Mbps */
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg speed /= 1000000;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg buf[0] = 0;
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg (void) snprintf(buf, sz, "%u Mbps", (uint32_t)speed);
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg}
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896ggstatic mactype_ops_t mac_ib_type_ops = {
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg MTOPS_HEADER_COOK | MTOPS_HEADER_UNCOOK | MTOPS_LINK_DETAILS,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mac_ib_unicst_verify,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mac_ib_multicst_verify,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mac_ib_sap_verify,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mac_ib_header,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mac_ib_header_info,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg NULL,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mac_ib_header_cook,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mac_ib_header_uncook,
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg mac_ib_link_details
87ba907dbdcf5c1692d70a9b22fe1d0e718d9896gg};