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
5605445d5Sdg * Common Development and Distribution License (the "License").
6605445d5Sdg * 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 *
21605445d5Sdg * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
227c478bd9Sstevel@tonic-gate * Use is subject to license terms.
2348bbca81SDaniel Hoffman * Copyright (c) 2016 by Delphix. All rights reserved.
24*9b664393SGarrett D'Amore * Copyright 2022 Garrett D'Amore
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * gld - Generic LAN Driver
297c478bd9Sstevel@tonic-gate * media dependent routines
307c478bd9Sstevel@tonic-gate */
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/errno.h>
347c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
357c478bd9Sstevel@tonic-gate #include <sys/stream.h>
367c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
377c478bd9Sstevel@tonic-gate #include <sys/stat.h>
387c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
397c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
407c478bd9Sstevel@tonic-gate #include <sys/debug.h>
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate #include <sys/byteorder.h>
437c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
447c478bd9Sstevel@tonic-gate #include <sys/dlpi.h>
457c478bd9Sstevel@tonic-gate #include <sys/ethernet.h>
467c478bd9Sstevel@tonic-gate #include <sys/gld.h>
477c478bd9Sstevel@tonic-gate #include <sys/gldpriv.h>
487c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
497c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
507c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
517c478bd9Sstevel@tonic-gate #include <sys/ib/clients/ibd/ibd.h>
527c478bd9Sstevel@tonic-gate #include <sys/pattr.h>
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate #define DLSAPLENGTH(macinfo) \
557c478bd9Sstevel@tonic-gate ((macinfo)->gldm_addrlen + ABS((macinfo)->gldm_saplen))
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
587c478bd9Sstevel@tonic-gate extern int gld_debug;
597c478bd9Sstevel@tonic-gate #endif
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate extern void gld_bitrevcopy(caddr_t src, caddr_t target, size_t n);
627c478bd9Sstevel@tonic-gate extern char *gld_macaddr_sprintf(char *, unsigned char *, int);
637c478bd9Sstevel@tonic-gate extern gld_vlan_t *gld_find_vlan(gld_mac_info_t *, uint32_t);
647c478bd9Sstevel@tonic-gate extern uint32_t gld_global_options;
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate static struct llc_snap_hdr llc_snap_def = {
677c478bd9Sstevel@tonic-gate LSAP_SNAP, /* DLSAP 0xaa */
687c478bd9Sstevel@tonic-gate LSAP_SNAP, /* SLSAP 0xaa */
697c478bd9Sstevel@tonic-gate CNTL_LLC_UI, /* Control 0x03 */
707c478bd9Sstevel@tonic-gate 0x00, 0x00, 0x00, /* Org[3] */
717c478bd9Sstevel@tonic-gate 0x00 /* Type */
727c478bd9Sstevel@tonic-gate };
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate #define ISETHERTYPE(snaphdr) \
757c478bd9Sstevel@tonic-gate (snaphdr->d_lsap == LSAP_SNAP && \
767c478bd9Sstevel@tonic-gate snaphdr->s_lsap == LSAP_SNAP && \
777c478bd9Sstevel@tonic-gate snaphdr->control == CNTL_LLC_UI && \
787c478bd9Sstevel@tonic-gate snaphdr->org[0] == 0 && \
797c478bd9Sstevel@tonic-gate snaphdr->org[1] == 0 && \
807c478bd9Sstevel@tonic-gate snaphdr->org[2] == 0)
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate /* ======== */
837c478bd9Sstevel@tonic-gate /* Ethernet */
847c478bd9Sstevel@tonic-gate /* ======== */
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate static mac_addr_t ether_broadcast = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate void
gld_init_ether(gld_mac_info_t * macinfo)897c478bd9Sstevel@tonic-gate gld_init_ether(gld_mac_info_t *macinfo)
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate struct gldkstats *sp =
927c478bd9Sstevel@tonic-gate ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->kstatp->ks_data;
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate /* Assumptions we make for this medium */
957c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_type == DL_ETHER);
967c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_addrlen == 6);
977c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_saplen == -2);
987c478bd9Sstevel@tonic-gate #ifndef lint
99605445d5Sdg ASSERT(sizeof (struct ether_header) == 14);
1007c478bd9Sstevel@tonic-gate ASSERT(sizeof (mac_addr_t) == 6);
1017c478bd9Sstevel@tonic-gate #endif
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_frame, "align_errors", KSTAT_DATA_ULONG);
1047c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_crc, "fcs_errors", KSTAT_DATA_ULONG);
1057c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_collisions, "collisions", KSTAT_DATA_ULONG);
1067c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_nocarrier, "carrier_errors",
1077c478bd9Sstevel@tonic-gate KSTAT_DATA_ULONG);
1087c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_defer, "defer_xmts", KSTAT_DATA_ULONG);
1097c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_xmtlatecoll, "tx_late_collisions",
110*9b664393SGarrett D'Amore KSTAT_DATA_ULONG);
1117c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_short, "runt_errors", KSTAT_DATA_ULONG);
1127c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_excoll, "ex_collisions", KSTAT_DATA_ULONG);
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate * only initialize the new statistics if the driver
1167c478bd9Sstevel@tonic-gate * knows about them.
1177c478bd9Sstevel@tonic-gate */
1187c478bd9Sstevel@tonic-gate if (macinfo->gldm_driver_version != GLD_VERSION_200)
1197c478bd9Sstevel@tonic-gate return;
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot3_first_coll,
1227c478bd9Sstevel@tonic-gate "first_collisions", KSTAT_DATA_UINT32);
1237c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot3_multi_coll,
1247c478bd9Sstevel@tonic-gate "multi_collisions", KSTAT_DATA_UINT32);
1257c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot3_sqe_error,
1267c478bd9Sstevel@tonic-gate "sqe_errors", KSTAT_DATA_UINT32);
1277c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot3_mac_xmt_error,
1287c478bd9Sstevel@tonic-gate "macxmt_errors", KSTAT_DATA_UINT32);
1297c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot3_mac_rcv_error,
1307c478bd9Sstevel@tonic-gate "macrcv_errors", KSTAT_DATA_UINT32);
1317c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot3_frame_too_long,
1327c478bd9Sstevel@tonic-gate "toolong_errors", KSTAT_DATA_UINT32);
1337c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_duplex, "duplex", KSTAT_DATA_CHAR);
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1377c478bd9Sstevel@tonic-gate void
gld_uninit_ether(gld_mac_info_t * macinfo)1387c478bd9Sstevel@tonic-gate gld_uninit_ether(gld_mac_info_t *macinfo)
1397c478bd9Sstevel@tonic-gate {
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate int
gld_interpret_ether(gld_mac_info_t * macinfo,mblk_t * mp,pktinfo_t * pktinfo,packet_flag_t flags)1437c478bd9Sstevel@tonic-gate gld_interpret_ether(gld_mac_info_t *macinfo, mblk_t *mp, pktinfo_t *pktinfo,
1447c478bd9Sstevel@tonic-gate packet_flag_t flags)
1457c478bd9Sstevel@tonic-gate {
146605445d5Sdg struct ether_header *mh;
1477c478bd9Sstevel@tonic-gate gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
1487c478bd9Sstevel@tonic-gate struct llc_snap_hdr *snaphdr;
149605445d5Sdg mblk_t *pmp = NULL, *savemp = mp;
1507c478bd9Sstevel@tonic-gate unsigned short typelen;
151605445d5Sdg int ret = 0;
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate * Quickly handle receive fastpath for IPQ hack.
1557c478bd9Sstevel@tonic-gate */
1567c478bd9Sstevel@tonic-gate if (flags == GLD_RXQUICK) {
1577c478bd9Sstevel@tonic-gate pktinfo->pktLen = msgdsize(mp);
1587c478bd9Sstevel@tonic-gate /*
1597c478bd9Sstevel@tonic-gate * Check whether the header is contiguous, which
1607c478bd9Sstevel@tonic-gate * also implicitly makes sure the packet is big enough.
1617c478bd9Sstevel@tonic-gate */
162605445d5Sdg if (MBLKL(mp) < sizeof (struct ether_header))
1637c478bd9Sstevel@tonic-gate return (-1);
164605445d5Sdg mh = (struct ether_header *)mp->b_rptr;
1657c478bd9Sstevel@tonic-gate pktinfo->ethertype = REF_NET_USHORT(mh->ether_type);
166605445d5Sdg pktinfo->isForMe = mac_eq(&mh->ether_dhost,
1677c478bd9Sstevel@tonic-gate mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
168605445d5Sdg pktinfo->macLen = sizeof (struct ether_header);
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate return (0);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate bzero((void *)pktinfo, sizeof (*pktinfo));
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate pktinfo->pktLen = msgdsize(mp);
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate /* make sure packet has at least a whole mac header */
178605445d5Sdg if (pktinfo->pktLen < sizeof (struct ether_header))
1797c478bd9Sstevel@tonic-gate return (-1);
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate /* make sure the mac header falls into contiguous memory */
182605445d5Sdg if (MBLKL(mp) < sizeof (struct ether_header)) {
1837c478bd9Sstevel@tonic-gate if ((pmp = msgpullup(mp, -1)) == NULL) {
1847c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
1857c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
1867c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
1877c478bd9Sstevel@tonic-gate "GLD: interpret_ether cannot msgpullup");
1887c478bd9Sstevel@tonic-gate #endif
1897c478bd9Sstevel@tonic-gate return (-1);
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate mp = pmp; /* this mblk contains the whole mac header */
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate
194605445d5Sdg mh = (struct ether_header *)mp->b_rptr;
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate /* Check to see if the mac is a broadcast or multicast address. */
197605445d5Sdg if (mac_eq(&mh->ether_dhost, ether_broadcast, macinfo->gldm_addrlen))
1987c478bd9Sstevel@tonic-gate pktinfo->isBroadcast = 1;
199605445d5Sdg else if (mh->ether_dhost.ether_addr_octet[0] & 1)
2007c478bd9Sstevel@tonic-gate pktinfo->isMulticast = 1;
2017c478bd9Sstevel@tonic-gate
2027c478bd9Sstevel@tonic-gate typelen = REF_NET_USHORT(mh->ether_type);
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate * If the hardware is capable of VLAN tag insertion
2057c478bd9Sstevel@tonic-gate * strip out the VLAN tag info. Knowing hardware is
2067c478bd9Sstevel@tonic-gate * capable of VLAN can be established by the presance
2077c478bd9Sstevel@tonic-gate * of non null 'macinfo->gldm_send_tagged'.
2087c478bd9Sstevel@tonic-gate */
2097c478bd9Sstevel@tonic-gate if (flags == GLD_TX) {
210605445d5Sdg if ((typelen == ETHERTYPE_VLAN) &&
211605445d5Sdg (macinfo->gldm_send_tagged != NULL)) {
212605445d5Sdg struct ether_vlan_header *evhp;
213605445d5Sdg uint16_t tci;
214605445d5Sdg
215605445d5Sdg if ((MBLKL(mp) < sizeof (struct ether_vlan_header)) &&
216605445d5Sdg (pullupmsg(mp, sizeof (struct ether_vlan_header))
217605445d5Sdg == 0)) {
218605445d5Sdg ret = -1;
219605445d5Sdg goto out;
220605445d5Sdg }
221605445d5Sdg evhp = (struct ether_vlan_header *)mp->b_rptr;
222605445d5Sdg tci = REF_NET_USHORT(evhp->ether_tci);
223605445d5Sdg
224605445d5Sdg /*
225605445d5Sdg * We don't allow the VID and priority are both zero.
226605445d5Sdg */
227605445d5Sdg if ((GLD_VTAG_PRI((int32_t)tci) == 0 &&
228605445d5Sdg GLD_VTAG_VID((int32_t)tci) == VLAN_VID_NONE) ||
229605445d5Sdg (GLD_VTAG_CFI((uint32_t)tci)) != VLAN_CFI_ETHER) {
230605445d5Sdg ret = -1;
231605445d5Sdg goto out;
232605445d5Sdg }
233605445d5Sdg
234605445d5Sdg /*
235605445d5Sdg * Remember the VTAG info in order to reinsert it,
236605445d5Sdg * Then strip the tag. This is required because some
237605445d5Sdg * drivers do not allow the size of message (passed
238605445d5Sdg * by the gldm_send_tagged() function) to be greater
239605445d5Sdg * than ETHERMAX.
240605445d5Sdg */
241605445d5Sdg GLD_SAVE_MBLK_VTAG(savemp, GLD_TCI2VTAG(tci));
242605445d5Sdg ovbcopy(mp->b_rptr, mp->b_rptr + VTAG_SIZE,
243605445d5Sdg 2 * ETHERADDRL);
2447c478bd9Sstevel@tonic-gate mp->b_rptr += VTAG_SIZE;
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate goto out; /* Got all info we need for xmit case */
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate ASSERT(GLDM_LOCK_HELD(macinfo));
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate * Deal with the mac header
2537c478bd9Sstevel@tonic-gate */
2547c478bd9Sstevel@tonic-gate
255605445d5Sdg mac_copy(&mh->ether_dhost, pktinfo->dhost, macinfo->gldm_addrlen);
256605445d5Sdg mac_copy(&mh->ether_shost, pktinfo->shost, macinfo->gldm_addrlen);
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate pktinfo->isLooped = mac_eq(pktinfo->shost,
2597c478bd9Sstevel@tonic-gate mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
2607c478bd9Sstevel@tonic-gate pktinfo->isForMe = mac_eq(pktinfo->dhost,
2617c478bd9Sstevel@tonic-gate mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
2627c478bd9Sstevel@tonic-gate
263605445d5Sdg pktinfo->macLen = sizeof (struct ether_header);
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate if (typelen > ETHERMTU) {
2667c478bd9Sstevel@tonic-gate pktinfo->ethertype = typelen; /* use type interpretation */
2677c478bd9Sstevel@tonic-gate goto out;
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate /*
2717c478bd9Sstevel@tonic-gate * Packet is 802.3 so the ether type/length field
2727c478bd9Sstevel@tonic-gate * specifies the number of bytes that should be present
2737c478bd9Sstevel@tonic-gate * in the data field. Additional bytes are padding, and
2747c478bd9Sstevel@tonic-gate * should be removed
2757c478bd9Sstevel@tonic-gate */
2767c478bd9Sstevel@tonic-gate {
2777c478bd9Sstevel@tonic-gate int delta = pktinfo->pktLen -
278605445d5Sdg (sizeof (struct ether_header) + typelen);
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate if (delta > 0 && adjmsg(mp, -delta))
2817c478bd9Sstevel@tonic-gate pktinfo->pktLen -= delta;
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate /*
2857c478bd9Sstevel@tonic-gate * Before trying to look beyond the MAC header, make sure the LLC
2867c478bd9Sstevel@tonic-gate * header exists, and that both it and any SNAP header are contiguous.
2877c478bd9Sstevel@tonic-gate */
2887c478bd9Sstevel@tonic-gate if (pktinfo->pktLen < pktinfo->macLen + LLC_HDR1_LEN)
2897c478bd9Sstevel@tonic-gate goto out; /* LLC hdr should have been there! */
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate pktinfo->isLLC = 1;
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate if (gld_global_options & GLD_OPT_NO_ETHRXSNAP ||
294605445d5Sdg pktinfo->pktLen < pktinfo->macLen + LLC_SNAP_HDR_LEN)
2957c478bd9Sstevel@tonic-gate goto out;
2967c478bd9Sstevel@tonic-gate
297605445d5Sdg if (MBLKL(mp) < sizeof (struct ether_header) + LLC_SNAP_HDR_LEN &&
2987c478bd9Sstevel@tonic-gate MBLKL(mp) < pktinfo->pktLen) {
2997c478bd9Sstevel@tonic-gate /*
3007c478bd9Sstevel@tonic-gate * we don't have the entire packet within the first mblk (and
3017c478bd9Sstevel@tonic-gate * therefore we didn't do the msgpullup above), AND the first
3027c478bd9Sstevel@tonic-gate * mblk may not contain all the data we need to look at.
3037c478bd9Sstevel@tonic-gate */
3047c478bd9Sstevel@tonic-gate ASSERT(pmp == NULL); /* couldn't have done msgpullup above */
3057c478bd9Sstevel@tonic-gate if ((pmp = msgpullup(mp, -1)) == NULL) {
3067c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
3077c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
3087c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
3097c478bd9Sstevel@tonic-gate "GLD: interpret_ether cannot msgpullup2");
3107c478bd9Sstevel@tonic-gate #endif
3117c478bd9Sstevel@tonic-gate goto out; /* can't interpret this pkt further */
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate mp = pmp; /* this mblk should contain everything needed */
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate /*
3177c478bd9Sstevel@tonic-gate * Check SAP/SNAP information for EtherType.
3187c478bd9Sstevel@tonic-gate */
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate snaphdr = (struct llc_snap_hdr *)(mp->b_rptr + pktinfo->macLen);
3217c478bd9Sstevel@tonic-gate if (ISETHERTYPE(snaphdr)) {
3227c478bd9Sstevel@tonic-gate pktinfo->ethertype = REF_NET_USHORT(snaphdr->type);
3237c478bd9Sstevel@tonic-gate pktinfo->hdrLen = LLC_SNAP_HDR_LEN;
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate out:
3267c478bd9Sstevel@tonic-gate if (pmp != NULL)
3277c478bd9Sstevel@tonic-gate freemsg(pmp);
3287c478bd9Sstevel@tonic-gate
329605445d5Sdg return (ret);
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate mblk_t *
gld_unitdata_ether(gld_t * gld,mblk_t * mp)3337c478bd9Sstevel@tonic-gate gld_unitdata_ether(gld_t *gld, mblk_t *mp)
3347c478bd9Sstevel@tonic-gate {
3357c478bd9Sstevel@tonic-gate gld_mac_info_t *macinfo = gld->gld_mac_info;
3367c478bd9Sstevel@tonic-gate dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_rptr;
3377c478bd9Sstevel@tonic-gate struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
3387c478bd9Sstevel@tonic-gate mac_addr_t dhost;
3397c478bd9Sstevel@tonic-gate unsigned short typelen;
3407c478bd9Sstevel@tonic-gate mblk_t *nmp;
341605445d5Sdg struct ether_header *mh;
3427c478bd9Sstevel@tonic-gate int hdrlen;
3437c478bd9Sstevel@tonic-gate uint32_t vptag;
3447c478bd9Sstevel@tonic-gate gld_vlan_t *gld_vlan;
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate ASSERT(macinfo);
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate /* extract needed info from the mblk before we maybe reuse it */
3497c478bd9Sstevel@tonic-gate mac_copy(gldp->glda_addr, dhost, macinfo->gldm_addrlen);
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate /* look in the unitdata request for a sap, else use bound one */
3527c478bd9Sstevel@tonic-gate if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
3537c478bd9Sstevel@tonic-gate REF_HOST_USHORT(gldp->glda_sap) != 0)
3547c478bd9Sstevel@tonic-gate typelen = REF_HOST_USHORT(gldp->glda_sap);
3557c478bd9Sstevel@tonic-gate else
3567c478bd9Sstevel@tonic-gate typelen = gld->gld_sap;
3577c478bd9Sstevel@tonic-gate
3587c478bd9Sstevel@tonic-gate /*
3597c478bd9Sstevel@tonic-gate * We take values less than or equal to ETHERMTU to mean that the
3607c478bd9Sstevel@tonic-gate * packet should not have an encoded EtherType and so we use the
3617c478bd9Sstevel@tonic-gate * IEEE 802.3 length interpretation of the type/length field.
3627c478bd9Sstevel@tonic-gate */
3637c478bd9Sstevel@tonic-gate if (typelen <= ETHERMTU)
3647c478bd9Sstevel@tonic-gate typelen = msgdsize(mp);
3657c478bd9Sstevel@tonic-gate
366605445d5Sdg hdrlen = sizeof (struct ether_header);
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate /*
3697c478bd9Sstevel@tonic-gate * Check to see if VLAN is enabled on this stream
3707c478bd9Sstevel@tonic-gate * if so then make the header bigger to hold a clone
3717c478bd9Sstevel@tonic-gate * vlan tag.
3727c478bd9Sstevel@tonic-gate */
3737c478bd9Sstevel@tonic-gate gld_vlan = (gld_vlan_t *)gld->gld_vlan;
3747c478bd9Sstevel@tonic-gate if (gld_vlan && (gld_vlan->gldv_id != VLAN_VID_NONE)) {
3757c478bd9Sstevel@tonic-gate hdrlen += VTAG_SIZE;
3767c478bd9Sstevel@tonic-gate vptag = gld_vlan->gldv_ptag;
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate /* need a buffer big enough for the headers */
3807c478bd9Sstevel@tonic-gate nmp = mp->b_cont; /* where the packet payload M_DATA is */
3817c478bd9Sstevel@tonic-gate if (DB_REF(nmp) == 1 && MBLKHEAD(nmp) >= hdrlen) {
3827c478bd9Sstevel@tonic-gate /* it fits at the beginning of the first M_DATA block */
3837c478bd9Sstevel@tonic-gate freeb(mp); /* don't need the M_PROTO anymore */
3847c478bd9Sstevel@tonic-gate } else if (DB_REF(mp) == 1 && MBLKSIZE(mp) >= hdrlen) {
3857c478bd9Sstevel@tonic-gate /* we can reuse the dl_unitdata_req M_PROTO mblk */
3867c478bd9Sstevel@tonic-gate nmp = mp;
3877c478bd9Sstevel@tonic-gate DB_TYPE(nmp) = M_DATA;
3887c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
3897c478bd9Sstevel@tonic-gate } else {
3907c478bd9Sstevel@tonic-gate /* we need to allocate one */
3917c478bd9Sstevel@tonic-gate if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
3927c478bd9Sstevel@tonic-gate return (NULL);
3937c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
3947c478bd9Sstevel@tonic-gate linkb(nmp, mp->b_cont);
3957c478bd9Sstevel@tonic-gate freeb(mp);
3967c478bd9Sstevel@tonic-gate }
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate /* Got the space, now copy in the header components */
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (typelen);
4017c478bd9Sstevel@tonic-gate SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, typelen);
402605445d5Sdg if (hdrlen > sizeof (struct ether_header)) {
4037c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (uint16_t);
4047c478bd9Sstevel@tonic-gate SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, vptag);
4057c478bd9Sstevel@tonic-gate vptag >>= 16;
4067c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (uint16_t);
4077c478bd9Sstevel@tonic-gate SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, vptag);
4087c478bd9Sstevel@tonic-gate }
4097c478bd9Sstevel@tonic-gate nmp->b_rptr -= (ETHERADDRL * 2);
410605445d5Sdg mh = (struct ether_header *)nmp->b_rptr;
411605445d5Sdg mac_copy(dhost, &mh->ether_dhost, macinfo->gldm_addrlen);
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gate /*
4147c478bd9Sstevel@tonic-gate * We access the mac address without the mutex to prevent
4157c478bd9Sstevel@tonic-gate * mutex contention (BUG 4211361)
4167c478bd9Sstevel@tonic-gate */
4177c478bd9Sstevel@tonic-gate mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
418605445d5Sdg &mh->ether_shost, macinfo->gldm_addrlen);
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate return (nmp);
4217c478bd9Sstevel@tonic-gate }
4227c478bd9Sstevel@tonic-gate
423605445d5Sdg /*
424605445d5Sdg * Insert the VLAN tag into the packet. The packet now is an Ethernet header
425605445d5Sdg * without VLAN tag information.
426605445d5Sdg */
427605445d5Sdg mblk_t *
gld_insert_vtag_ether(mblk_t * mp,uint32_t vtag)428605445d5Sdg gld_insert_vtag_ether(mblk_t *mp, uint32_t vtag)
429605445d5Sdg {
430605445d5Sdg struct ether_vlan_header *evhp;
431605445d5Sdg struct ether_header *ehp;
432605445d5Sdg mblk_t *nmp;
433605445d5Sdg
434605445d5Sdg if (vtag == VLAN_VID_NONE)
435605445d5Sdg return (mp);
436605445d5Sdg
437605445d5Sdg if (DB_REF(mp) == 1 && MBLKHEAD(mp) >= VTAG_SIZE) {
438605445d5Sdg /* it fits at the beginning of the message block */
439605445d5Sdg nmp = mp;
440605445d5Sdg ovbcopy(nmp->b_rptr, nmp->b_rptr - VTAG_SIZE, 2 * ETHERADDRL);
441605445d5Sdg nmp->b_rptr -= VTAG_SIZE;
442605445d5Sdg evhp = (struct ether_vlan_header *)nmp->b_rptr;
443605445d5Sdg } else {
444605445d5Sdg /* we need to allocate one */
445605445d5Sdg if ((nmp = allocb(sizeof (struct ether_vlan_header),
446605445d5Sdg BPRI_MED)) == NULL) {
447605445d5Sdg return (NULL);
448605445d5Sdg }
449605445d5Sdg nmp->b_wptr += sizeof (struct ether_vlan_header);
450605445d5Sdg
451605445d5Sdg /* transfer the ether_header fields */
452605445d5Sdg evhp = (struct ether_vlan_header *)nmp->b_rptr;
453605445d5Sdg ehp = (struct ether_header *)mp->b_rptr;
454605445d5Sdg mac_copy(&ehp->ether_dhost, &evhp->ether_dhost, ETHERADDRL);
455605445d5Sdg mac_copy(&ehp->ether_shost, &evhp->ether_shost, ETHERADDRL);
456605445d5Sdg bcopy(&ehp->ether_type, &evhp->ether_type, sizeof (uint16_t));
457605445d5Sdg
458605445d5Sdg /* offset the mp of the MAC header length. */
459605445d5Sdg mp->b_rptr += sizeof (struct ether_header);
460605445d5Sdg if (MBLKL(mp) == 0) {
461605445d5Sdg nmp->b_cont = mp->b_cont;
462605445d5Sdg freeb(mp);
463605445d5Sdg } else {
464605445d5Sdg nmp->b_cont = mp;
465605445d5Sdg }
466605445d5Sdg }
467605445d5Sdg
468605445d5Sdg SET_NET_USHORT(evhp->ether_tci, vtag);
469605445d5Sdg vtag >>= 16;
470605445d5Sdg SET_NET_USHORT(evhp->ether_tpid, vtag);
471605445d5Sdg return (nmp);
472605445d5Sdg }
473605445d5Sdg
4747c478bd9Sstevel@tonic-gate mblk_t *
gld_fastpath_ether(gld_t * gld,mblk_t * mp)4757c478bd9Sstevel@tonic-gate gld_fastpath_ether(gld_t *gld, mblk_t *mp)
4767c478bd9Sstevel@tonic-gate {
4777c478bd9Sstevel@tonic-gate gld_mac_info_t *macinfo = gld->gld_mac_info;
4787c478bd9Sstevel@tonic-gate dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_cont->b_rptr;
4797c478bd9Sstevel@tonic-gate struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
4807c478bd9Sstevel@tonic-gate unsigned short typelen;
4817c478bd9Sstevel@tonic-gate mblk_t *nmp;
482605445d5Sdg struct ether_header *mh;
4837c478bd9Sstevel@tonic-gate int hdrlen;
4847c478bd9Sstevel@tonic-gate uint32_t vptag;
4857c478bd9Sstevel@tonic-gate gld_vlan_t *gld_vlan;
4867c478bd9Sstevel@tonic-gate
4877c478bd9Sstevel@tonic-gate ASSERT(macinfo);
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate /* look in the unitdata request for a sap, else use bound one */
4907c478bd9Sstevel@tonic-gate if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
4917c478bd9Sstevel@tonic-gate REF_HOST_USHORT(gldp->glda_sap) != 0)
4927c478bd9Sstevel@tonic-gate typelen = REF_HOST_USHORT(gldp->glda_sap);
4937c478bd9Sstevel@tonic-gate else
4947c478bd9Sstevel@tonic-gate typelen = gld->gld_sap;
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate /*
4977c478bd9Sstevel@tonic-gate * We only do fast-path for EtherType encoding because this is the only
4987c478bd9Sstevel@tonic-gate * case where the media header will be consistent from packet to packet.
4997c478bd9Sstevel@tonic-gate */
5007c478bd9Sstevel@tonic-gate if (typelen <= ETHERMTU)
5017c478bd9Sstevel@tonic-gate return (NULL);
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate /*
5047c478bd9Sstevel@tonic-gate * Initialize the fast path header to include the
5057c478bd9Sstevel@tonic-gate * basic source address information and type field.
5067c478bd9Sstevel@tonic-gate */
507605445d5Sdg hdrlen = sizeof (struct ether_header);
5087c478bd9Sstevel@tonic-gate
5097c478bd9Sstevel@tonic-gate /*
5107c478bd9Sstevel@tonic-gate * Check to see if VLAN is enabled on this stream
5117c478bd9Sstevel@tonic-gate * if so then make the header bigger to hold a clone
5127c478bd9Sstevel@tonic-gate * vlan tag.
5137c478bd9Sstevel@tonic-gate */
5147c478bd9Sstevel@tonic-gate gld_vlan = (gld_vlan_t *)gld->gld_vlan;
5157c478bd9Sstevel@tonic-gate if (gld_vlan && (gld_vlan->gldv_id != VLAN_VID_NONE)) {
5167c478bd9Sstevel@tonic-gate hdrlen += VTAG_SIZE;
5177c478bd9Sstevel@tonic-gate vptag = gld_vlan->gldv_ptag;
5187c478bd9Sstevel@tonic-gate }
5197c478bd9Sstevel@tonic-gate
5207c478bd9Sstevel@tonic-gate if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
5217c478bd9Sstevel@tonic-gate return (NULL);
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
5247c478bd9Sstevel@tonic-gate
5257c478bd9Sstevel@tonic-gate /* Got the space, now copy in the header components */
5267c478bd9Sstevel@tonic-gate
5277c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (typelen);
5287c478bd9Sstevel@tonic-gate SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, typelen);
5297c478bd9Sstevel@tonic-gate
5307c478bd9Sstevel@tonic-gate /*
5317c478bd9Sstevel@tonic-gate * If the header is for a VLAN stream, then add
5327c478bd9Sstevel@tonic-gate * in the VLAN tag to the clone header.
5337c478bd9Sstevel@tonic-gate */
534605445d5Sdg if (hdrlen > sizeof (struct ether_header)) {
5357c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (uint16_t);
5367c478bd9Sstevel@tonic-gate SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, vptag);
5377c478bd9Sstevel@tonic-gate vptag >>= 16;
5387c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (uint16_t);
5397c478bd9Sstevel@tonic-gate SET_NET_USHORT(*(uint16_t *)nmp->b_rptr, vptag);
5407c478bd9Sstevel@tonic-gate }
5417c478bd9Sstevel@tonic-gate nmp->b_rptr -= (ETHERADDRL * 2);
542605445d5Sdg mh = (struct ether_header *)nmp->b_rptr;
543605445d5Sdg mac_copy(gldp->glda_addr, &mh->ether_dhost, macinfo->gldm_addrlen);
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate GLDM_LOCK(macinfo, RW_WRITER);
5467c478bd9Sstevel@tonic-gate mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
547605445d5Sdg &mh->ether_shost, macinfo->gldm_addrlen);
5487c478bd9Sstevel@tonic-gate GLDM_UNLOCK(macinfo);
5497c478bd9Sstevel@tonic-gate
5507c478bd9Sstevel@tonic-gate return (nmp);
5517c478bd9Sstevel@tonic-gate }
5527c478bd9Sstevel@tonic-gate
5537c478bd9Sstevel@tonic-gate /* == */
5547c478bd9Sstevel@tonic-gate /* IB */
5557c478bd9Sstevel@tonic-gate /* == */
5567c478bd9Sstevel@tonic-gate
5577c478bd9Sstevel@tonic-gate void
gld_init_ib(gld_mac_info_t * macinfo)5587c478bd9Sstevel@tonic-gate gld_init_ib(gld_mac_info_t *macinfo)
5597c478bd9Sstevel@tonic-gate {
5607c478bd9Sstevel@tonic-gate /*
5617c478bd9Sstevel@tonic-gate * Currently, the generic stats maintained by GLD is
5627c478bd9Sstevel@tonic-gate * sufficient for IPoIB.
5637c478bd9Sstevel@tonic-gate */
5647c478bd9Sstevel@tonic-gate
5657c478bd9Sstevel@tonic-gate /* Assumptions we make for this medium */
5667c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_type == DL_IB);
5677c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_addrlen == IPOIB_ADDRL);
5687c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_saplen == -2);
5697c478bd9Sstevel@tonic-gate }
5707c478bd9Sstevel@tonic-gate
5717c478bd9Sstevel@tonic-gate /* ARGSUSED */
5727c478bd9Sstevel@tonic-gate void
gld_uninit_ib(gld_mac_info_t * macinfo)5737c478bd9Sstevel@tonic-gate gld_uninit_ib(gld_mac_info_t *macinfo)
5747c478bd9Sstevel@tonic-gate {
5757c478bd9Sstevel@tonic-gate }
5767c478bd9Sstevel@tonic-gate
5777c478bd9Sstevel@tonic-gate /*
5787c478bd9Sstevel@tonic-gate * The packet format sent to the driver is:
5797c478bd9Sstevel@tonic-gate * IPOIB_ADDRL bytes dest addr :: 2b sap :: 2b 0s :: data
5807c478bd9Sstevel@tonic-gate * The packet format received from the driver is:
5817c478bd9Sstevel@tonic-gate * IPOIB_GRH_SIZE bytes pseudo GRH :: 2b sap :: 2b 0s :: data.
5827c478bd9Sstevel@tonic-gate */
5837c478bd9Sstevel@tonic-gate int
gld_interpret_ib(gld_mac_info_t * macinfo,mblk_t * mp,pktinfo_t * pktinfo,packet_flag_t flags)5847c478bd9Sstevel@tonic-gate gld_interpret_ib(gld_mac_info_t *macinfo, mblk_t *mp, pktinfo_t *pktinfo,
5857c478bd9Sstevel@tonic-gate packet_flag_t flags)
5867c478bd9Sstevel@tonic-gate {
5877c478bd9Sstevel@tonic-gate ipoib_pgrh_t *grh;
5887c478bd9Sstevel@tonic-gate ipoib_ptxhdr_t *gldp;
5897c478bd9Sstevel@tonic-gate mblk_t *pmp = NULL;
5907c478bd9Sstevel@tonic-gate gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate /*
5937c478bd9Sstevel@tonic-gate * Quickly handle receive fastpath for IPQ hack.
5947c478bd9Sstevel@tonic-gate */
5957c478bd9Sstevel@tonic-gate if (flags == GLD_RXQUICK) {
5967c478bd9Sstevel@tonic-gate pktinfo->pktLen = msgdsize(mp) - IPOIB_GRH_SIZE;
5977c478bd9Sstevel@tonic-gate
5987c478bd9Sstevel@tonic-gate /*
5997c478bd9Sstevel@tonic-gate * Check whether the header is contiguous, which
6007c478bd9Sstevel@tonic-gate * also implicitly makes sure the packet is big enough.
6017c478bd9Sstevel@tonic-gate */
6027c478bd9Sstevel@tonic-gate if (MBLKL(mp) < (IPOIB_GRH_SIZE + IPOIB_HDRSIZE))
6037c478bd9Sstevel@tonic-gate return (-1);
6047c478bd9Sstevel@tonic-gate
6057c478bd9Sstevel@tonic-gate /*
6067c478bd9Sstevel@tonic-gate * Almost all times, unicast will not have
6077c478bd9Sstevel@tonic-gate * a valid pgrh; quickly identify and ask for
6087c478bd9Sstevel@tonic-gate * IPQ hack optimization only in that case.
6097c478bd9Sstevel@tonic-gate */
6107c478bd9Sstevel@tonic-gate grh = (ipoib_pgrh_t *)mp->b_rptr;
6117c478bd9Sstevel@tonic-gate if (grh->ipoib_vertcflow == 0) {
6127c478bd9Sstevel@tonic-gate struct ipoib_header *ihp = (struct ipoib_header *)
6137c478bd9Sstevel@tonic-gate (mp->b_rptr + IPOIB_GRH_SIZE);
6147c478bd9Sstevel@tonic-gate
6157c478bd9Sstevel@tonic-gate pktinfo->isForMe = 1;
6167c478bd9Sstevel@tonic-gate pktinfo->ethertype = REF_NET_USHORT(ihp->ipoib_type);
6177c478bd9Sstevel@tonic-gate pktinfo->macLen = IPOIB_GRH_SIZE + IPOIB_HDRSIZE;
6187c478bd9Sstevel@tonic-gate return (0);
6197c478bd9Sstevel@tonic-gate } else {
6207c478bd9Sstevel@tonic-gate return (-1);
6217c478bd9Sstevel@tonic-gate }
6227c478bd9Sstevel@tonic-gate }
6237c478bd9Sstevel@tonic-gate
6247c478bd9Sstevel@tonic-gate /*
6257c478bd9Sstevel@tonic-gate * Handle the GLD_TX, GLD_RX, GLD_RXLOOP cases now.
6267c478bd9Sstevel@tonic-gate */
6277c478bd9Sstevel@tonic-gate ASSERT(flags != GLD_RXQUICK);
6287c478bd9Sstevel@tonic-gate bzero((void *)pktinfo, sizeof (*pktinfo));
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate if (flags != GLD_RX) {
6317c478bd9Sstevel@tonic-gate /*
6327c478bd9Sstevel@tonic-gate * GLD_TX and GLD_RXLOOP cases.
6337c478bd9Sstevel@tonic-gate */
6347c478bd9Sstevel@tonic-gate gldp = (ipoib_ptxhdr_t *)mp->b_rptr;
6357c478bd9Sstevel@tonic-gate pktinfo->pktLen = msgdsize(mp);
6367c478bd9Sstevel@tonic-gate
6377c478bd9Sstevel@tonic-gate /* make sure packet has at least a pseudo header */
6387c478bd9Sstevel@tonic-gate if (pktinfo->pktLen < sizeof (ipoib_ptxhdr_t))
6397c478bd9Sstevel@tonic-gate return (-1);
6407c478bd9Sstevel@tonic-gate
6417c478bd9Sstevel@tonic-gate /* make sure the mac header falls into contiguous memory */
6427c478bd9Sstevel@tonic-gate if (MBLKL(mp) < sizeof (ipoib_ptxhdr_t)) {
6437c478bd9Sstevel@tonic-gate if ((pmp = msgpullup(mp, -1)) == NULL) {
6447c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
6457c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
6467c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
6477c478bd9Sstevel@tonic-gate "GLD: interpret_ib "
6487c478bd9Sstevel@tonic-gate "cannot msgpullup");
6497c478bd9Sstevel@tonic-gate #endif
6507c478bd9Sstevel@tonic-gate return (-1);
6517c478bd9Sstevel@tonic-gate }
6527c478bd9Sstevel@tonic-gate /* this mblk contains the whole mac header */
6537c478bd9Sstevel@tonic-gate mp = pmp;
6547c478bd9Sstevel@tonic-gate }
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate /*
6577c478bd9Sstevel@tonic-gate * Check if mac is broadcast or multicast address; all these
6587c478bd9Sstevel@tonic-gate * types of address have the top 4 bytes as 0x00FFFFFF.
6597c478bd9Sstevel@tonic-gate */
6607c478bd9Sstevel@tonic-gate if (mac_eq(&gldp->ipoib_dest, macinfo->gldm_broadcast_addr,
6617c478bd9Sstevel@tonic-gate sizeof (uint32_t))) {
6627c478bd9Sstevel@tonic-gate if (mac_eq(&gldp->ipoib_dest,
6637c478bd9Sstevel@tonic-gate macinfo->gldm_broadcast_addr, IPOIB_ADDRL))
6647c478bd9Sstevel@tonic-gate pktinfo->isBroadcast = 1;
6657c478bd9Sstevel@tonic-gate else
6667c478bd9Sstevel@tonic-gate pktinfo->isMulticast = 1;
6677c478bd9Sstevel@tonic-gate }
6687c478bd9Sstevel@tonic-gate
6697c478bd9Sstevel@tonic-gate /*
6707c478bd9Sstevel@tonic-gate * Only count bytes we will be sending over the wire
6717c478bd9Sstevel@tonic-gate * or looping back.
6727c478bd9Sstevel@tonic-gate */
6737c478bd9Sstevel@tonic-gate pktinfo->pktLen -= IPOIB_ADDRL;
6747c478bd9Sstevel@tonic-gate if (flags == GLD_TX)
6757c478bd9Sstevel@tonic-gate goto out; /* Got all info we need for xmit case */
6767c478bd9Sstevel@tonic-gate
6777c478bd9Sstevel@tonic-gate /*
6787c478bd9Sstevel@tonic-gate * Loopback case: this is a dup'ed message.
6797c478bd9Sstevel@tonic-gate */
6807c478bd9Sstevel@tonic-gate mp->b_rptr += IPOIB_ADDRL;
6817c478bd9Sstevel@tonic-gate mac_copy(&gldp->ipoib_dest, pktinfo->dhost, IPOIB_ADDRL);
6827c478bd9Sstevel@tonic-gate mac_copy(mac_pvt->curr_macaddr, pktinfo->shost, IPOIB_ADDRL);
6837c478bd9Sstevel@tonic-gate } else {
6847c478bd9Sstevel@tonic-gate /*
6857c478bd9Sstevel@tonic-gate * GLD_RX case; process packet sent from driver.
6867c478bd9Sstevel@tonic-gate */
6877c478bd9Sstevel@tonic-gate ipoib_mac_t *mact, *tact;
6887c478bd9Sstevel@tonic-gate ib_qpn_t dqpn;
6897c478bd9Sstevel@tonic-gate
6907c478bd9Sstevel@tonic-gate pktinfo->pktLen = msgdsize(mp);
6917c478bd9Sstevel@tonic-gate /* make sure packet has at least pgrh and mac header */
6927c478bd9Sstevel@tonic-gate if (pktinfo->pktLen < (IPOIB_GRH_SIZE + IPOIB_HDRSIZE))
6937c478bd9Sstevel@tonic-gate return (-1);
6947c478bd9Sstevel@tonic-gate
6957c478bd9Sstevel@tonic-gate /* make sure the header falls into contiguous memory */
6967c478bd9Sstevel@tonic-gate if (MBLKL(mp) < (IPOIB_GRH_SIZE + IPOIB_HDRSIZE)) {
6977c478bd9Sstevel@tonic-gate if ((pmp = msgpullup(mp, -1)) == NULL) {
6987c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
6997c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
7007c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
7017c478bd9Sstevel@tonic-gate "GLD: interpret_ib "
7027c478bd9Sstevel@tonic-gate "cannot msgpullup2");
7037c478bd9Sstevel@tonic-gate #endif
7047c478bd9Sstevel@tonic-gate return (-1);
7057c478bd9Sstevel@tonic-gate }
7067c478bd9Sstevel@tonic-gate /* this mblk contains the whole mac header */
7077c478bd9Sstevel@tonic-gate mp = pmp;
7087c478bd9Sstevel@tonic-gate }
7097c478bd9Sstevel@tonic-gate
7107c478bd9Sstevel@tonic-gate grh = (ipoib_pgrh_t *)mp->b_rptr;
7117c478bd9Sstevel@tonic-gate mp->b_rptr += IPOIB_GRH_SIZE;
7127c478bd9Sstevel@tonic-gate pktinfo->pktLen -= IPOIB_GRH_SIZE;
7137c478bd9Sstevel@tonic-gate if (grh->ipoib_vertcflow) {
7147c478bd9Sstevel@tonic-gate /*
7157c478bd9Sstevel@tonic-gate * First, copy source address from grh.
7167c478bd9Sstevel@tonic-gate */
7177c478bd9Sstevel@tonic-gate mact = (ipoib_mac_t *)pktinfo->shost;
7187c478bd9Sstevel@tonic-gate mac_copy(&grh->ipoib_sqpn, &mact->ipoib_qpn,
7197c478bd9Sstevel@tonic-gate IPOIB_ADDRL);
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate /*
7227c478bd9Sstevel@tonic-gate * Then copy destination address from grh;
7237c478bd9Sstevel@tonic-gate * first, the 16 bytes of GID.
7247c478bd9Sstevel@tonic-gate */
7257c478bd9Sstevel@tonic-gate mact = (ipoib_mac_t *)pktinfo->dhost;
7267c478bd9Sstevel@tonic-gate mac_copy(&grh->ipoib_dgid_pref,
7277c478bd9Sstevel@tonic-gate &mact->ipoib_gidpref, IPOIB_ADDRL -
7287c478bd9Sstevel@tonic-gate sizeof (mact->ipoib_qpn));
7297c478bd9Sstevel@tonic-gate tact = (ipoib_mac_t *)mac_pvt->curr_macaddr;
7307c478bd9Sstevel@tonic-gate
7317c478bd9Sstevel@tonic-gate /* Is this a multicast address */
7327c478bd9Sstevel@tonic-gate if (*(uchar_t *)(grh->ipoib_dgid_pref) == 0xFF) {
7337c478bd9Sstevel@tonic-gate /*
7347c478bd9Sstevel@tonic-gate * Only check for hardware looping in
7357c478bd9Sstevel@tonic-gate * multicast case. It is assumed higher
7367c478bd9Sstevel@tonic-gate * layer code (IP) will stop unicast loops;
7377c478bd9Sstevel@tonic-gate * ie will prevent a transmit to self.
7387c478bd9Sstevel@tonic-gate */
7397c478bd9Sstevel@tonic-gate if (bcmp(&grh->ipoib_sqpn, tact,
7407c478bd9Sstevel@tonic-gate IPOIB_ADDRL) == 0)
7417c478bd9Sstevel@tonic-gate pktinfo->isLooped = 1;
7427c478bd9Sstevel@tonic-gate
7437c478bd9Sstevel@tonic-gate tact = (ipoib_mac_t *)macinfo->
7447c478bd9Sstevel@tonic-gate gldm_broadcast_addr;
7457c478bd9Sstevel@tonic-gate if (mac_eq(tact->ipoib_gidpref,
7467c478bd9Sstevel@tonic-gate grh->ipoib_dgid_pref,
7477c478bd9Sstevel@tonic-gate IPOIB_ADDRL - sizeof (tact->ipoib_qpn)))
7487c478bd9Sstevel@tonic-gate pktinfo->isBroadcast = 1;
7497c478bd9Sstevel@tonic-gate else
7507c478bd9Sstevel@tonic-gate pktinfo->isMulticast = 1;
7517c478bd9Sstevel@tonic-gate /*
7527c478bd9Sstevel@tonic-gate * Now copy the 4 bytes QPN part of the
7537c478bd9Sstevel@tonic-gate * destination address.
7547c478bd9Sstevel@tonic-gate */
7557c478bd9Sstevel@tonic-gate dqpn = htonl(IB_MC_QPN);
7567c478bd9Sstevel@tonic-gate mac_copy(&dqpn, &mact->ipoib_qpn,
7577c478bd9Sstevel@tonic-gate sizeof (mact->ipoib_qpn));
7587c478bd9Sstevel@tonic-gate } else {
7597c478bd9Sstevel@tonic-gate /*
7607c478bd9Sstevel@tonic-gate * Now copy the 4 bytes QPN part of the
7617c478bd9Sstevel@tonic-gate * destination address.
7627c478bd9Sstevel@tonic-gate */
7637c478bd9Sstevel@tonic-gate mac_copy(&tact->ipoib_qpn, &mact->ipoib_qpn,
7647c478bd9Sstevel@tonic-gate sizeof (mact->ipoib_qpn));
7657c478bd9Sstevel@tonic-gate /*
7667c478bd9Sstevel@tonic-gate * Any unicast packets received on IBA are
7677c478bd9Sstevel@tonic-gate * for the node.
7687c478bd9Sstevel@tonic-gate */
7697c478bd9Sstevel@tonic-gate pktinfo->isForMe = 1;
7707c478bd9Sstevel@tonic-gate }
7717c478bd9Sstevel@tonic-gate } else {
7727c478bd9Sstevel@tonic-gate /*
7737c478bd9Sstevel@tonic-gate * It can not be a IBA multicast packet.
7747c478bd9Sstevel@tonic-gate * Must have been unicast to us. We do not
7757c478bd9Sstevel@tonic-gate * have shost information, which is used in
7767c478bd9Sstevel@tonic-gate * gld_addudind(); IP/ARP does not care.
7777c478bd9Sstevel@tonic-gate */
7787c478bd9Sstevel@tonic-gate pktinfo->nosource = 1;
7797c478bd9Sstevel@tonic-gate mac_copy(mac_pvt->curr_macaddr, pktinfo->dhost,
7807c478bd9Sstevel@tonic-gate IPOIB_ADDRL);
7817c478bd9Sstevel@tonic-gate /*
7827c478bd9Sstevel@tonic-gate * Any unicast packets received on IBA are
7837c478bd9Sstevel@tonic-gate * for the node.
7847c478bd9Sstevel@tonic-gate */
7857c478bd9Sstevel@tonic-gate pktinfo->isForMe = 1;
7867c478bd9Sstevel@tonic-gate }
7877c478bd9Sstevel@tonic-gate }
7887c478bd9Sstevel@tonic-gate
7897c478bd9Sstevel@tonic-gate ASSERT((flags == GLD_RX) || (flags == GLD_RXLOOP));
7907c478bd9Sstevel@tonic-gate ASSERT(GLDM_LOCK_HELD(macinfo));
7917c478bd9Sstevel@tonic-gate pktinfo->ethertype = REF_NET_USHORT(((ipoib_hdr_t *)
7927c478bd9Sstevel@tonic-gate (mp->b_rptr))->ipoib_type);
7937c478bd9Sstevel@tonic-gate pktinfo->macLen = IPOIB_HDRSIZE;
7947c478bd9Sstevel@tonic-gate
7957c478bd9Sstevel@tonic-gate out:
7967c478bd9Sstevel@tonic-gate if (pmp != NULL)
7977c478bd9Sstevel@tonic-gate freemsg(pmp);
7987c478bd9Sstevel@tonic-gate
7997c478bd9Sstevel@tonic-gate return (0);
8007c478bd9Sstevel@tonic-gate }
8017c478bd9Sstevel@tonic-gate
8027c478bd9Sstevel@tonic-gate mblk_t *
gld_unitdata_ib(gld_t * gld,mblk_t * mp)8037c478bd9Sstevel@tonic-gate gld_unitdata_ib(gld_t *gld, mblk_t *mp)
8047c478bd9Sstevel@tonic-gate {
8057c478bd9Sstevel@tonic-gate gld_mac_info_t *macinfo = gld->gld_mac_info;
8067c478bd9Sstevel@tonic-gate dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_rptr;
8077c478bd9Sstevel@tonic-gate ipoib_ptxhdr_t *gldp = IPOIBDLSAP(dlp, dlp->dl_dest_addr_offset);
8087c478bd9Sstevel@tonic-gate ipoib_mac_t dhost;
8097c478bd9Sstevel@tonic-gate unsigned short type;
8107c478bd9Sstevel@tonic-gate mblk_t *nmp;
8117c478bd9Sstevel@tonic-gate int hdrlen;
8127c478bd9Sstevel@tonic-gate
8137c478bd9Sstevel@tonic-gate ASSERT(macinfo != NULL);
8147c478bd9Sstevel@tonic-gate
8157c478bd9Sstevel@tonic-gate /* extract needed info from the mblk before we maybe reuse it */
8167c478bd9Sstevel@tonic-gate mac_copy(&gldp->ipoib_dest, &dhost, IPOIB_ADDRL);
8177c478bd9Sstevel@tonic-gate
8187c478bd9Sstevel@tonic-gate /* look in the unitdata request for a sap, else use bound one */
8197c478bd9Sstevel@tonic-gate if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
8207c478bd9Sstevel@tonic-gate REF_HOST_USHORT(gldp->ipoib_rhdr.ipoib_type) != 0)
8217c478bd9Sstevel@tonic-gate type = REF_HOST_USHORT(gldp->ipoib_rhdr.ipoib_type);
8227c478bd9Sstevel@tonic-gate else
8237c478bd9Sstevel@tonic-gate type = gld->gld_sap;
8247c478bd9Sstevel@tonic-gate
8257c478bd9Sstevel@tonic-gate hdrlen = sizeof (ipoib_ptxhdr_t);
8267c478bd9Sstevel@tonic-gate
8277c478bd9Sstevel@tonic-gate /* need a buffer big enough for the headers */
8287c478bd9Sstevel@tonic-gate nmp = mp->b_cont; /* where the packet payload M_DATA is */
8297c478bd9Sstevel@tonic-gate if (DB_REF(nmp) == 1 && MBLKHEAD(nmp) >= hdrlen) {
8307c478bd9Sstevel@tonic-gate /* it fits at the beginning of the first M_DATA block */
8317c478bd9Sstevel@tonic-gate freeb(mp); /* don't need the M_PROTO anymore */
8327c478bd9Sstevel@tonic-gate } else if (DB_REF(mp) == 1 && MBLKSIZE(mp) >= hdrlen) {
8337c478bd9Sstevel@tonic-gate /* we can reuse the dl_unitdata_req M_PROTO mblk */
8347c478bd9Sstevel@tonic-gate nmp = mp;
8357c478bd9Sstevel@tonic-gate DB_TYPE(nmp) = M_DATA;
8367c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
8377c478bd9Sstevel@tonic-gate } else {
8387c478bd9Sstevel@tonic-gate /* we need to allocate one */
8397c478bd9Sstevel@tonic-gate if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
8407c478bd9Sstevel@tonic-gate return (NULL);
8417c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
8427c478bd9Sstevel@tonic-gate linkb(nmp, mp->b_cont);
8437c478bd9Sstevel@tonic-gate freeb(mp);
8447c478bd9Sstevel@tonic-gate }
8457c478bd9Sstevel@tonic-gate
8467c478bd9Sstevel@tonic-gate /* Got the space, now copy in the header components */
8477c478bd9Sstevel@tonic-gate
8487c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (ipoib_ptxhdr_t);
8497c478bd9Sstevel@tonic-gate gldp = (ipoib_ptxhdr_t *)nmp->b_rptr;
8507c478bd9Sstevel@tonic-gate SET_NET_USHORT(gldp->ipoib_rhdr.ipoib_type, type);
8517c478bd9Sstevel@tonic-gate gldp->ipoib_rhdr.ipoib_mbz = 0;
8527c478bd9Sstevel@tonic-gate mac_copy(&dhost, &gldp->ipoib_dest, IPOIB_ADDRL);
8537c478bd9Sstevel@tonic-gate
8547c478bd9Sstevel@tonic-gate return (nmp);
8557c478bd9Sstevel@tonic-gate }
8567c478bd9Sstevel@tonic-gate
8577c478bd9Sstevel@tonic-gate mblk_t *
gld_fastpath_ib(gld_t * gld,mblk_t * mp)8587c478bd9Sstevel@tonic-gate gld_fastpath_ib(gld_t *gld, mblk_t *mp)
8597c478bd9Sstevel@tonic-gate {
8607c478bd9Sstevel@tonic-gate gld_mac_info_t *macinfo = gld->gld_mac_info;
8617c478bd9Sstevel@tonic-gate dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_cont->b_rptr;
8627c478bd9Sstevel@tonic-gate ipoib_ptxhdr_t *gldp = IPOIBDLSAP(dlp, dlp->dl_dest_addr_offset);
8637c478bd9Sstevel@tonic-gate unsigned short type;
8647c478bd9Sstevel@tonic-gate mblk_t *nmp;
8657c478bd9Sstevel@tonic-gate ipoib_ptxhdr_t *tgldp;
8667c478bd9Sstevel@tonic-gate int hdrlen;
8677c478bd9Sstevel@tonic-gate
8687c478bd9Sstevel@tonic-gate ASSERT(macinfo != NULL);
8697c478bd9Sstevel@tonic-gate
8707c478bd9Sstevel@tonic-gate /* look in the unitdata request for a sap, else use bound one */
8717c478bd9Sstevel@tonic-gate if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
8727c478bd9Sstevel@tonic-gate REF_HOST_USHORT(gldp->ipoib_rhdr.ipoib_type) != 0)
8737c478bd9Sstevel@tonic-gate type = REF_HOST_USHORT(gldp->ipoib_rhdr.ipoib_type);
8747c478bd9Sstevel@tonic-gate else
8757c478bd9Sstevel@tonic-gate type = gld->gld_sap;
8767c478bd9Sstevel@tonic-gate
8777c478bd9Sstevel@tonic-gate hdrlen = sizeof (ipoib_ptxhdr_t);
8787c478bd9Sstevel@tonic-gate
8797c478bd9Sstevel@tonic-gate if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
8807c478bd9Sstevel@tonic-gate return (NULL);
8817c478bd9Sstevel@tonic-gate
8827c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
8837c478bd9Sstevel@tonic-gate
8847c478bd9Sstevel@tonic-gate /* Got the space, now copy in the header components */
8857c478bd9Sstevel@tonic-gate
8867c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (ipoib_ptxhdr_t);
8877c478bd9Sstevel@tonic-gate tgldp = (ipoib_ptxhdr_t *)nmp->b_rptr;
8887c478bd9Sstevel@tonic-gate tgldp->ipoib_rhdr.ipoib_type = htons(type);
8897c478bd9Sstevel@tonic-gate tgldp->ipoib_rhdr.ipoib_mbz = 0;
8907c478bd9Sstevel@tonic-gate mac_copy(&gldp->ipoib_dest, &tgldp->ipoib_dest, IPOIB_ADDRL);
8917c478bd9Sstevel@tonic-gate
8927c478bd9Sstevel@tonic-gate return (nmp);
8937c478bd9Sstevel@tonic-gate }
8947c478bd9Sstevel@tonic-gate
8957c478bd9Sstevel@tonic-gate /* ==== */
8967c478bd9Sstevel@tonic-gate /* FDDI */
8977c478bd9Sstevel@tonic-gate /* ==== */
8987c478bd9Sstevel@tonic-gate
8997c478bd9Sstevel@tonic-gate void
gld_init_fddi(gld_mac_info_t * macinfo)9007c478bd9Sstevel@tonic-gate gld_init_fddi(gld_mac_info_t *macinfo)
9017c478bd9Sstevel@tonic-gate {
9027c478bd9Sstevel@tonic-gate struct gldkstats *sp =
9037c478bd9Sstevel@tonic-gate ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->kstatp->ks_data;
9047c478bd9Sstevel@tonic-gate
9057c478bd9Sstevel@tonic-gate /* Assumptions we make for this medium */
9067c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_type == DL_FDDI);
9077c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_addrlen == 6);
9087c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_saplen == -2);
9097c478bd9Sstevel@tonic-gate #ifndef lint
9107c478bd9Sstevel@tonic-gate ASSERT(sizeof (struct fddi_mac_frm) == 13);
9117c478bd9Sstevel@tonic-gate ASSERT(sizeof (mac_addr_t) == 6);
9127c478bd9Sstevel@tonic-gate #endif
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gate /* Wire address format is bit reversed from canonical format */
9157c478bd9Sstevel@tonic-gate macinfo->gldm_options |= GLDOPT_CANONICAL_ADDR;
9167c478bd9Sstevel@tonic-gate
9177c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_fddi_mac_error,
9187c478bd9Sstevel@tonic-gate "mac_errors", KSTAT_DATA_UINT32);
9197c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_fddi_mac_lost,
9207c478bd9Sstevel@tonic-gate "mac_lost_errors", KSTAT_DATA_UINT32);
9217c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_fddi_mac_token,
9227c478bd9Sstevel@tonic-gate "mac_tokens", KSTAT_DATA_UINT32);
9237c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_fddi_mac_tvx_expired,
9247c478bd9Sstevel@tonic-gate "mac_tvx_expired", KSTAT_DATA_UINT32);
9257c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_fddi_mac_late,
9267c478bd9Sstevel@tonic-gate "mac_late", KSTAT_DATA_UINT32);
9277c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_fddi_mac_ring_op,
9287c478bd9Sstevel@tonic-gate "mac_ring_ops", KSTAT_DATA_UINT32);
9297c478bd9Sstevel@tonic-gate }
9307c478bd9Sstevel@tonic-gate
9317c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9327c478bd9Sstevel@tonic-gate void
gld_uninit_fddi(gld_mac_info_t * macinfo)9337c478bd9Sstevel@tonic-gate gld_uninit_fddi(gld_mac_info_t *macinfo)
9347c478bd9Sstevel@tonic-gate {
9357c478bd9Sstevel@tonic-gate }
9367c478bd9Sstevel@tonic-gate
9377c478bd9Sstevel@tonic-gate int
gld_interpret_fddi(gld_mac_info_t * macinfo,mblk_t * mp,pktinfo_t * pktinfo,packet_flag_t flags)9387c478bd9Sstevel@tonic-gate gld_interpret_fddi(gld_mac_info_t *macinfo, mblk_t *mp, pktinfo_t *pktinfo,
9397c478bd9Sstevel@tonic-gate packet_flag_t flags)
9407c478bd9Sstevel@tonic-gate {
9417c478bd9Sstevel@tonic-gate struct fddi_mac_frm *mh;
9427c478bd9Sstevel@tonic-gate gld_mac_pvt_t *mac_pvt;
9437c478bd9Sstevel@tonic-gate struct llc_snap_hdr *snaphdr;
9447c478bd9Sstevel@tonic-gate mblk_t *pmp = NULL;
9457c478bd9Sstevel@tonic-gate
9467c478bd9Sstevel@tonic-gate /*
9477c478bd9Sstevel@tonic-gate * Quickly handle receive fastpath; FDDI does not support IPQ hack.
9487c478bd9Sstevel@tonic-gate */
9497c478bd9Sstevel@tonic-gate if (flags == GLD_RXQUICK) {
9507c478bd9Sstevel@tonic-gate pktinfo->pktLen = msgdsize(mp);
9517c478bd9Sstevel@tonic-gate return (-1);
9527c478bd9Sstevel@tonic-gate }
9537c478bd9Sstevel@tonic-gate
9547c478bd9Sstevel@tonic-gate bzero((void *)pktinfo, sizeof (*pktinfo));
9557c478bd9Sstevel@tonic-gate
9567c478bd9Sstevel@tonic-gate pktinfo->pktLen = msgdsize(mp);
9577c478bd9Sstevel@tonic-gate
9587c478bd9Sstevel@tonic-gate /* make sure packet has at least a whole mac header */
9597c478bd9Sstevel@tonic-gate if (pktinfo->pktLen < sizeof (struct fddi_mac_frm))
9607c478bd9Sstevel@tonic-gate return (-1);
9617c478bd9Sstevel@tonic-gate
9627c478bd9Sstevel@tonic-gate /* make sure the mac header falls into contiguous memory */
9637c478bd9Sstevel@tonic-gate if (MBLKL(mp) < sizeof (struct fddi_mac_frm)) {
9647c478bd9Sstevel@tonic-gate if ((pmp = msgpullup(mp, -1)) == NULL) {
9657c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
9667c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
9677c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
9687c478bd9Sstevel@tonic-gate "GLD: interpret_fddi cannot msgpullup");
9697c478bd9Sstevel@tonic-gate #endif
9707c478bd9Sstevel@tonic-gate return (-1);
9717c478bd9Sstevel@tonic-gate }
9727c478bd9Sstevel@tonic-gate mp = pmp; /* this mblk contains the whole mac header */
9737c478bd9Sstevel@tonic-gate }
9747c478bd9Sstevel@tonic-gate
9757c478bd9Sstevel@tonic-gate mh = (struct fddi_mac_frm *)mp->b_rptr;
9767c478bd9Sstevel@tonic-gate
9777c478bd9Sstevel@tonic-gate /* Check to see if the mac is a broadcast or multicast address. */
9787c478bd9Sstevel@tonic-gate /* NB we are still in wire format (non canonical) */
9797c478bd9Sstevel@tonic-gate /* mac_eq works because ether_broadcast is the same either way */
9807c478bd9Sstevel@tonic-gate if (mac_eq(mh->fddi_dhost, ether_broadcast, macinfo->gldm_addrlen))
9817c478bd9Sstevel@tonic-gate pktinfo->isBroadcast = 1;
9827c478bd9Sstevel@tonic-gate else if (mh->fddi_dhost[0] & 0x80)
9837c478bd9Sstevel@tonic-gate pktinfo->isMulticast = 1;
9847c478bd9Sstevel@tonic-gate
9857c478bd9Sstevel@tonic-gate if (flags == GLD_TX)
9867c478bd9Sstevel@tonic-gate goto out; /* Got all info we need for xmit case */
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate ASSERT(GLDM_LOCK_HELD(macinfo));
9897c478bd9Sstevel@tonic-gate
9907c478bd9Sstevel@tonic-gate /*
9917c478bd9Sstevel@tonic-gate * Deal with the mac header
9927c478bd9Sstevel@tonic-gate */
9937c478bd9Sstevel@tonic-gate
9947c478bd9Sstevel@tonic-gate cmac_copy(mh->fddi_dhost, pktinfo->dhost,
9957c478bd9Sstevel@tonic-gate macinfo->gldm_addrlen, macinfo);
9967c478bd9Sstevel@tonic-gate cmac_copy(mh->fddi_shost, pktinfo->shost,
9977c478bd9Sstevel@tonic-gate macinfo->gldm_addrlen, macinfo);
9987c478bd9Sstevel@tonic-gate
9997c478bd9Sstevel@tonic-gate mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
10007c478bd9Sstevel@tonic-gate pktinfo->isLooped = mac_eq(pktinfo->shost,
10017c478bd9Sstevel@tonic-gate mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
10027c478bd9Sstevel@tonic-gate pktinfo->isForMe = mac_eq(pktinfo->dhost,
10037c478bd9Sstevel@tonic-gate mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
10047c478bd9Sstevel@tonic-gate
10057c478bd9Sstevel@tonic-gate pktinfo->macLen = sizeof (struct fddi_mac_frm);
10067c478bd9Sstevel@tonic-gate
10077c478bd9Sstevel@tonic-gate /*
10087c478bd9Sstevel@tonic-gate * Before trying to look beyond the MAC header, make sure the LLC
10097c478bd9Sstevel@tonic-gate * header exists, and that both it and any SNAP header are contiguous.
10107c478bd9Sstevel@tonic-gate */
10117c478bd9Sstevel@tonic-gate if (MBLKL(mp) < sizeof (struct fddi_mac_frm) + LLC_SNAP_HDR_LEN &&
10127c478bd9Sstevel@tonic-gate MBLKL(mp) < pktinfo->pktLen) {
10137c478bd9Sstevel@tonic-gate /*
10147c478bd9Sstevel@tonic-gate * we don't have the entire packet within the first mblk (and
10157c478bd9Sstevel@tonic-gate * therefore we didn't do the msgpullup above), AND the first
10167c478bd9Sstevel@tonic-gate * mblk may not contain all the data we need to look at.
10177c478bd9Sstevel@tonic-gate */
10187c478bd9Sstevel@tonic-gate ASSERT(pmp == NULL); /* couldn't have done msgpullup above */
10197c478bd9Sstevel@tonic-gate if ((pmp = msgpullup(mp, -1)) == NULL) {
10207c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
10217c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
10227c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
10237c478bd9Sstevel@tonic-gate "GLD: interpret_fddi cannot msgpullup2");
10247c478bd9Sstevel@tonic-gate #endif
10257c478bd9Sstevel@tonic-gate goto out; /* can't interpret this pkt further */
10267c478bd9Sstevel@tonic-gate }
10277c478bd9Sstevel@tonic-gate mp = pmp; /* this mblk should contain everything needed */
10287c478bd9Sstevel@tonic-gate }
10297c478bd9Sstevel@tonic-gate
10307c478bd9Sstevel@tonic-gate /*
10317c478bd9Sstevel@tonic-gate * Check SAP/SNAP information.
10327c478bd9Sstevel@tonic-gate */
10337c478bd9Sstevel@tonic-gate if ((mh->fddi_fc & 0x70) == 0x50) {
10347c478bd9Sstevel@tonic-gate if (pktinfo->pktLen < pktinfo->macLen + LLC_HDR1_LEN)
10357c478bd9Sstevel@tonic-gate goto out;
10367c478bd9Sstevel@tonic-gate
10377c478bd9Sstevel@tonic-gate pktinfo->isLLC = 1;
10387c478bd9Sstevel@tonic-gate
10397c478bd9Sstevel@tonic-gate if (pktinfo->pktLen < pktinfo->macLen + LLC_SNAP_HDR_LEN)
10407c478bd9Sstevel@tonic-gate goto out;
10417c478bd9Sstevel@tonic-gate
10427c478bd9Sstevel@tonic-gate snaphdr = (struct llc_snap_hdr *)(mp->b_rptr + pktinfo->macLen);
10437c478bd9Sstevel@tonic-gate if (ISETHERTYPE(snaphdr)) {
10447c478bd9Sstevel@tonic-gate pktinfo->ethertype = REF_NET_USHORT(snaphdr->type);
10457c478bd9Sstevel@tonic-gate pktinfo->hdrLen = LLC_SNAP_HDR_LEN;
10467c478bd9Sstevel@tonic-gate }
10477c478bd9Sstevel@tonic-gate }
10487c478bd9Sstevel@tonic-gate out:
10497c478bd9Sstevel@tonic-gate if (pmp != NULL)
10507c478bd9Sstevel@tonic-gate freemsg(pmp);
10517c478bd9Sstevel@tonic-gate
10527c478bd9Sstevel@tonic-gate return (0);
10537c478bd9Sstevel@tonic-gate }
10547c478bd9Sstevel@tonic-gate
10557c478bd9Sstevel@tonic-gate mblk_t *
gld_unitdata_fddi(gld_t * gld,mblk_t * mp)10567c478bd9Sstevel@tonic-gate gld_unitdata_fddi(gld_t *gld, mblk_t *mp)
10577c478bd9Sstevel@tonic-gate {
10587c478bd9Sstevel@tonic-gate gld_mac_info_t *macinfo = gld->gld_mac_info;
10597c478bd9Sstevel@tonic-gate dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_rptr;
10607c478bd9Sstevel@tonic-gate struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
10617c478bd9Sstevel@tonic-gate mac_addr_t dhost;
10627c478bd9Sstevel@tonic-gate unsigned short type;
10637c478bd9Sstevel@tonic-gate mblk_t *nmp;
10647c478bd9Sstevel@tonic-gate struct fddi_mac_frm *mh;
10657c478bd9Sstevel@tonic-gate int hdrlen;
10667c478bd9Sstevel@tonic-gate
10677c478bd9Sstevel@tonic-gate ASSERT(macinfo);
10687c478bd9Sstevel@tonic-gate
10697c478bd9Sstevel@tonic-gate /* extract needed info from the mblk before we maybe reuse it */
10707c478bd9Sstevel@tonic-gate mac_copy(gldp->glda_addr, dhost, macinfo->gldm_addrlen);
10717c478bd9Sstevel@tonic-gate
10727c478bd9Sstevel@tonic-gate /* look in the unitdata request for a sap, else use bound one */
10737c478bd9Sstevel@tonic-gate if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
10747c478bd9Sstevel@tonic-gate REF_HOST_USHORT(gldp->glda_sap) != 0)
10757c478bd9Sstevel@tonic-gate type = REF_HOST_USHORT(gldp->glda_sap);
10767c478bd9Sstevel@tonic-gate else
10777c478bd9Sstevel@tonic-gate type = gld->gld_sap;
10787c478bd9Sstevel@tonic-gate
10797c478bd9Sstevel@tonic-gate
10807c478bd9Sstevel@tonic-gate hdrlen = sizeof (struct fddi_mac_frm);
10817c478bd9Sstevel@tonic-gate
10827c478bd9Sstevel@tonic-gate /*
10837c478bd9Sstevel@tonic-gate * Check whether we need to do EtherType encoding or whether the packet
10847c478bd9Sstevel@tonic-gate * is LLC.
10857c478bd9Sstevel@tonic-gate */
10867c478bd9Sstevel@tonic-gate if (type > GLD_MAX_802_SAP)
10877c478bd9Sstevel@tonic-gate hdrlen += sizeof (struct llc_snap_hdr);
10887c478bd9Sstevel@tonic-gate
10897c478bd9Sstevel@tonic-gate /* need a buffer big enough for the headers */
10907c478bd9Sstevel@tonic-gate nmp = mp->b_cont; /* where the packet payload M_DATA is */
10917c478bd9Sstevel@tonic-gate if (DB_REF(nmp) == 1 && MBLKHEAD(nmp) >= hdrlen) {
10927c478bd9Sstevel@tonic-gate /* it fits at the beginning of the first M_DATA block */
10937c478bd9Sstevel@tonic-gate freeb(mp); /* don't need the M_PROTO anymore */
10947c478bd9Sstevel@tonic-gate } else if (DB_REF(mp) == 1 && MBLKSIZE(mp) >= hdrlen) {
10957c478bd9Sstevel@tonic-gate /* we can reuse the dl_unitdata_req M_PROTO mblk */
10967c478bd9Sstevel@tonic-gate nmp = mp;
10977c478bd9Sstevel@tonic-gate DB_TYPE(nmp) = M_DATA;
10987c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
10997c478bd9Sstevel@tonic-gate } else {
11007c478bd9Sstevel@tonic-gate /* we need to allocate one */
11017c478bd9Sstevel@tonic-gate if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
11027c478bd9Sstevel@tonic-gate return (NULL);
11037c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
11047c478bd9Sstevel@tonic-gate linkb(nmp, mp->b_cont);
11057c478bd9Sstevel@tonic-gate freeb(mp);
11067c478bd9Sstevel@tonic-gate }
11077c478bd9Sstevel@tonic-gate
11087c478bd9Sstevel@tonic-gate
11097c478bd9Sstevel@tonic-gate /* Got the space, now copy in the header components */
11107c478bd9Sstevel@tonic-gate if (type > GLD_MAX_802_SAP) {
11117c478bd9Sstevel@tonic-gate /* create the snap header */
11127c478bd9Sstevel@tonic-gate struct llc_snap_hdr *snap;
11137c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct llc_snap_hdr);
11147c478bd9Sstevel@tonic-gate snap = (struct llc_snap_hdr *)(nmp->b_rptr);
11157c478bd9Sstevel@tonic-gate *snap = llc_snap_def;
11167c478bd9Sstevel@tonic-gate SET_NET_USHORT(snap->type, type);
11177c478bd9Sstevel@tonic-gate }
11187c478bd9Sstevel@tonic-gate
11197c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct fddi_mac_frm);
11207c478bd9Sstevel@tonic-gate
11217c478bd9Sstevel@tonic-gate mh = (struct fddi_mac_frm *)nmp->b_rptr;
11227c478bd9Sstevel@tonic-gate
11237c478bd9Sstevel@tonic-gate mh->fddi_fc = 0x50;
11247c478bd9Sstevel@tonic-gate cmac_copy(dhost, mh->fddi_dhost, macinfo->gldm_addrlen, macinfo);
11257c478bd9Sstevel@tonic-gate
11267c478bd9Sstevel@tonic-gate /*
11277c478bd9Sstevel@tonic-gate * We access the mac address without the mutex to prevent
11287c478bd9Sstevel@tonic-gate * mutex contention (BUG 4211361)
11297c478bd9Sstevel@tonic-gate */
11307c478bd9Sstevel@tonic-gate cmac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
11317c478bd9Sstevel@tonic-gate mh->fddi_shost, macinfo->gldm_addrlen, macinfo);
11327c478bd9Sstevel@tonic-gate return (nmp);
11337c478bd9Sstevel@tonic-gate }
11347c478bd9Sstevel@tonic-gate
11357c478bd9Sstevel@tonic-gate mblk_t *
gld_fastpath_fddi(gld_t * gld,mblk_t * mp)11367c478bd9Sstevel@tonic-gate gld_fastpath_fddi(gld_t *gld, mblk_t *mp)
11377c478bd9Sstevel@tonic-gate {
11387c478bd9Sstevel@tonic-gate gld_mac_info_t *macinfo = gld->gld_mac_info;
11397c478bd9Sstevel@tonic-gate dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_cont->b_rptr;
11407c478bd9Sstevel@tonic-gate struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
11417c478bd9Sstevel@tonic-gate unsigned short type;
11427c478bd9Sstevel@tonic-gate mblk_t *nmp;
11437c478bd9Sstevel@tonic-gate struct fddi_mac_frm *mh;
11447c478bd9Sstevel@tonic-gate int hdrlen;
11457c478bd9Sstevel@tonic-gate
11467c478bd9Sstevel@tonic-gate ASSERT(macinfo);
11477c478bd9Sstevel@tonic-gate
11487c478bd9Sstevel@tonic-gate /* look in the unitdata request for a sap, else use bound one */
11497c478bd9Sstevel@tonic-gate if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
11507c478bd9Sstevel@tonic-gate REF_HOST_USHORT(gldp->glda_sap) != 0)
11517c478bd9Sstevel@tonic-gate type = REF_HOST_USHORT(gldp->glda_sap);
11527c478bd9Sstevel@tonic-gate else
11537c478bd9Sstevel@tonic-gate type = gld->gld_sap;
11547c478bd9Sstevel@tonic-gate
11557c478bd9Sstevel@tonic-gate hdrlen = sizeof (struct fddi_mac_frm);
11567c478bd9Sstevel@tonic-gate
11577c478bd9Sstevel@tonic-gate /*
11587c478bd9Sstevel@tonic-gate * Check whether we need to do EtherType encoding or whether the packet
11597c478bd9Sstevel@tonic-gate * will be LLC.
11607c478bd9Sstevel@tonic-gate */
11617c478bd9Sstevel@tonic-gate if (type > GLD_MAX_802_SAP)
11627c478bd9Sstevel@tonic-gate hdrlen += sizeof (struct llc_snap_hdr);
11637c478bd9Sstevel@tonic-gate
11647c478bd9Sstevel@tonic-gate if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
11657c478bd9Sstevel@tonic-gate return (NULL);
11667c478bd9Sstevel@tonic-gate
11677c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
11687c478bd9Sstevel@tonic-gate
11697c478bd9Sstevel@tonic-gate /* Got the space, now copy in the header components */
11707c478bd9Sstevel@tonic-gate
11717c478bd9Sstevel@tonic-gate if (type > GLD_MAX_802_SAP) {
11727c478bd9Sstevel@tonic-gate /* create the snap header */
11737c478bd9Sstevel@tonic-gate struct llc_snap_hdr *snap;
11747c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct llc_snap_hdr);
11757c478bd9Sstevel@tonic-gate snap = (struct llc_snap_hdr *)(nmp->b_rptr);
11767c478bd9Sstevel@tonic-gate *snap = llc_snap_def;
11777c478bd9Sstevel@tonic-gate snap->type = htons(type); /* we know it's aligned */
11787c478bd9Sstevel@tonic-gate }
11797c478bd9Sstevel@tonic-gate
11807c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct fddi_mac_frm);
11817c478bd9Sstevel@tonic-gate
11827c478bd9Sstevel@tonic-gate mh = (struct fddi_mac_frm *)nmp->b_rptr;
11837c478bd9Sstevel@tonic-gate mh->fddi_fc = 0x50;
11847c478bd9Sstevel@tonic-gate cmac_copy(gldp->glda_addr, mh->fddi_dhost,
11857c478bd9Sstevel@tonic-gate macinfo->gldm_addrlen, macinfo);
11867c478bd9Sstevel@tonic-gate
11877c478bd9Sstevel@tonic-gate GLDM_LOCK(macinfo, RW_WRITER);
11887c478bd9Sstevel@tonic-gate cmac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
11897c478bd9Sstevel@tonic-gate mh->fddi_shost, macinfo->gldm_addrlen, macinfo);
11907c478bd9Sstevel@tonic-gate GLDM_UNLOCK(macinfo);
11917c478bd9Sstevel@tonic-gate
11927c478bd9Sstevel@tonic-gate return (nmp);
11937c478bd9Sstevel@tonic-gate }
11947c478bd9Sstevel@tonic-gate
11957c478bd9Sstevel@tonic-gate /* ========== */
11967c478bd9Sstevel@tonic-gate /* Token Ring */
11977c478bd9Sstevel@tonic-gate /* ========== */
11987c478bd9Sstevel@tonic-gate
11997c478bd9Sstevel@tonic-gate #define GLD_SR_VAR(macinfo) \
12007c478bd9Sstevel@tonic-gate (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->data)
12017c478bd9Sstevel@tonic-gate
12027c478bd9Sstevel@tonic-gate #define GLD_SR_HASH(macinfo) ((struct srtab **)GLD_SR_VAR(macinfo))
12037c478bd9Sstevel@tonic-gate
12047c478bd9Sstevel@tonic-gate #define GLD_SR_MUTEX(macinfo) \
12057c478bd9Sstevel@tonic-gate (&((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->datalock)
12067c478bd9Sstevel@tonic-gate
12077c478bd9Sstevel@tonic-gate static void gld_sr_clear(gld_mac_info_t *);
12087c478bd9Sstevel@tonic-gate static void gld_rcc_receive(gld_mac_info_t *, pktinfo_t *, struct gld_ri *,
12097c478bd9Sstevel@tonic-gate uchar_t *, int);
12107c478bd9Sstevel@tonic-gate static void gld_rcc_send(gld_mac_info_t *, queue_t *, uchar_t *,
12117c478bd9Sstevel@tonic-gate struct gld_ri **, uchar_t *);
12127c478bd9Sstevel@tonic-gate
12137c478bd9Sstevel@tonic-gate static mac_addr_t tokenbroadcastaddr2 = { 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff };
12147c478bd9Sstevel@tonic-gate static struct gld_ri ri_ste_def;
12157c478bd9Sstevel@tonic-gate
12167c478bd9Sstevel@tonic-gate void
gld_init_tr(gld_mac_info_t * macinfo)12177c478bd9Sstevel@tonic-gate gld_init_tr(gld_mac_info_t *macinfo)
12187c478bd9Sstevel@tonic-gate {
12197c478bd9Sstevel@tonic-gate struct gldkstats *sp =
12207c478bd9Sstevel@tonic-gate ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->kstatp->ks_data;
12217c478bd9Sstevel@tonic-gate
12227c478bd9Sstevel@tonic-gate /* avoid endian-dependent code by initializing here instead of static */
12237c478bd9Sstevel@tonic-gate ri_ste_def.len = 2;
12247c478bd9Sstevel@tonic-gate ri_ste_def.rt = RT_STE;
12257c478bd9Sstevel@tonic-gate ri_ste_def.mtu = RT_MTU_MAX;
12267c478bd9Sstevel@tonic-gate ri_ste_def.dir = 0;
12277c478bd9Sstevel@tonic-gate ri_ste_def.res = 0;
12287c478bd9Sstevel@tonic-gate
12297c478bd9Sstevel@tonic-gate /* Assumptions we make for this medium */
12307c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_type == DL_TPR);
12317c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_addrlen == 6);
12327c478bd9Sstevel@tonic-gate ASSERT(macinfo->gldm_saplen == -2);
12337c478bd9Sstevel@tonic-gate #ifndef lint
12347c478bd9Sstevel@tonic-gate ASSERT(sizeof (struct tr_mac_frm_nori) == 14);
12357c478bd9Sstevel@tonic-gate ASSERT(sizeof (mac_addr_t) == 6);
12367c478bd9Sstevel@tonic-gate #endif
12377c478bd9Sstevel@tonic-gate
12387c478bd9Sstevel@tonic-gate mutex_init(GLD_SR_MUTEX(macinfo), NULL, MUTEX_DRIVER, NULL);
12397c478bd9Sstevel@tonic-gate
12407c478bd9Sstevel@tonic-gate GLD_SR_VAR(macinfo) = kmem_zalloc(sizeof (struct srtab *)*SR_HASH_SIZE,
1241*9b664393SGarrett D'Amore KM_SLEEP);
12427c478bd9Sstevel@tonic-gate
12437c478bd9Sstevel@tonic-gate /* Default is RDE enabled for this medium */
12447c478bd9Sstevel@tonic-gate ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_enabled =
12457c478bd9Sstevel@tonic-gate ddi_getprop(DDI_DEV_T_NONE, macinfo->gldm_devinfo, 0,
12467c478bd9Sstevel@tonic-gate "gld_rde_enable", 1);
12477c478bd9Sstevel@tonic-gate
12487c478bd9Sstevel@tonic-gate /*
12497c478bd9Sstevel@tonic-gate * Default is to use STE for unknown paths if RDE is enabled.
12507c478bd9Sstevel@tonic-gate * If RDE is disabled, default is to use NULL RIF fields.
12517c478bd9Sstevel@tonic-gate *
12527c478bd9Sstevel@tonic-gate * It's possible to force use of STE for ALL packets:
12537c478bd9Sstevel@tonic-gate * disable RDE but enable STE. This may be useful for
12547c478bd9Sstevel@tonic-gate * non-transparent bridges, when it is not desired to run
12557c478bd9Sstevel@tonic-gate * the RDE algorithms.
12567c478bd9Sstevel@tonic-gate */
12577c478bd9Sstevel@tonic-gate ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_str_indicator_ste =
12587c478bd9Sstevel@tonic-gate ddi_getprop(DDI_DEV_T_NONE, macinfo->gldm_devinfo, 0,
12597c478bd9Sstevel@tonic-gate "gld_rde_str_indicator_ste",
12607c478bd9Sstevel@tonic-gate ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_enabled);
12617c478bd9Sstevel@tonic-gate
12627c478bd9Sstevel@tonic-gate /* Default 10 second route timeout on lack of activity */
12637c478bd9Sstevel@tonic-gate {
12647c478bd9Sstevel@tonic-gate int t = ddi_getprop(DDI_DEV_T_NONE, macinfo->gldm_devinfo, 0,
12657c478bd9Sstevel@tonic-gate "gld_rde_timeout", 10);
12667c478bd9Sstevel@tonic-gate if (t < 1)
12677c478bd9Sstevel@tonic-gate t = 1; /* Let's be reasonable */
12687c478bd9Sstevel@tonic-gate if (t > 600)
12697c478bd9Sstevel@tonic-gate t = 600; /* Let's be reasonable */
12707c478bd9Sstevel@tonic-gate /* We're using ticks (lbolts) for our timeout -- convert from seconds */
12717c478bd9Sstevel@tonic-gate t = drv_usectohz(1000000 * t);
12727c478bd9Sstevel@tonic-gate ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_timeout = t;
12737c478bd9Sstevel@tonic-gate }
12747c478bd9Sstevel@tonic-gate
12757c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot5_line_error,
12767c478bd9Sstevel@tonic-gate "line_errors", KSTAT_DATA_UINT32);
12777c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot5_burst_error,
12787c478bd9Sstevel@tonic-gate "burst_errors", KSTAT_DATA_UINT32);
12797c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot5_signal_loss,
12807c478bd9Sstevel@tonic-gate "signal_losses", KSTAT_DATA_UINT32);
12817c478bd9Sstevel@tonic-gate
12827c478bd9Sstevel@tonic-gate /*
12837c478bd9Sstevel@tonic-gate * only initialize the new statistics if the driver
12847c478bd9Sstevel@tonic-gate * knows about them.
12857c478bd9Sstevel@tonic-gate */
12867c478bd9Sstevel@tonic-gate if (macinfo->gldm_driver_version != GLD_VERSION_200)
12877c478bd9Sstevel@tonic-gate return;
12887c478bd9Sstevel@tonic-gate
12897c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot5_ace_error,
12907c478bd9Sstevel@tonic-gate "ace_errors", KSTAT_DATA_UINT32);
12917c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot5_internal_error,
12927c478bd9Sstevel@tonic-gate "internal_errors", KSTAT_DATA_UINT32);
12937c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot5_lost_frame_error,
12947c478bd9Sstevel@tonic-gate "lost_frame_errors", KSTAT_DATA_UINT32);
12957c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot5_frame_copied_error,
12967c478bd9Sstevel@tonic-gate "frame_copied_errors", KSTAT_DATA_UINT32);
12977c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot5_token_error,
12987c478bd9Sstevel@tonic-gate "token_errors", KSTAT_DATA_UINT32);
12997c478bd9Sstevel@tonic-gate kstat_named_init(&sp->glds_dot5_freq_error,
13007c478bd9Sstevel@tonic-gate "freq_errors", KSTAT_DATA_UINT32);
13017c478bd9Sstevel@tonic-gate }
13027c478bd9Sstevel@tonic-gate
13037c478bd9Sstevel@tonic-gate void
gld_uninit_tr(gld_mac_info_t * macinfo)13047c478bd9Sstevel@tonic-gate gld_uninit_tr(gld_mac_info_t *macinfo)
13057c478bd9Sstevel@tonic-gate {
13067c478bd9Sstevel@tonic-gate mutex_destroy(GLD_SR_MUTEX(macinfo));
13077c478bd9Sstevel@tonic-gate gld_sr_clear(macinfo);
13087c478bd9Sstevel@tonic-gate kmem_free(GLD_SR_VAR(macinfo), sizeof (struct srtab *) * SR_HASH_SIZE);
13097c478bd9Sstevel@tonic-gate }
13107c478bd9Sstevel@tonic-gate
13117c478bd9Sstevel@tonic-gate int
gld_interpret_tr(gld_mac_info_t * macinfo,mblk_t * mp,pktinfo_t * pktinfo,packet_flag_t flags)13127c478bd9Sstevel@tonic-gate gld_interpret_tr(gld_mac_info_t *macinfo, mblk_t *mp, pktinfo_t *pktinfo,
13137c478bd9Sstevel@tonic-gate packet_flag_t flags)
13147c478bd9Sstevel@tonic-gate {
13157c478bd9Sstevel@tonic-gate struct tr_mac_frm *mh;
13167c478bd9Sstevel@tonic-gate gld_mac_pvt_t *mac_pvt;
13177c478bd9Sstevel@tonic-gate struct llc_snap_hdr *snaphdr;
13187c478bd9Sstevel@tonic-gate mblk_t *pmp = NULL;
13197c478bd9Sstevel@tonic-gate struct gld_ri *rh;
13207c478bd9Sstevel@tonic-gate
13217c478bd9Sstevel@tonic-gate /*
13227c478bd9Sstevel@tonic-gate * Quickly handle receive fastpath; TR does not support IPQ hack.
13237c478bd9Sstevel@tonic-gate */
13247c478bd9Sstevel@tonic-gate if (flags == GLD_RXQUICK) {
13257c478bd9Sstevel@tonic-gate pktinfo->pktLen = msgdsize(mp);
13267c478bd9Sstevel@tonic-gate return (-1);
13277c478bd9Sstevel@tonic-gate }
13287c478bd9Sstevel@tonic-gate
13297c478bd9Sstevel@tonic-gate bzero((void *)pktinfo, sizeof (*pktinfo));
13307c478bd9Sstevel@tonic-gate
13317c478bd9Sstevel@tonic-gate pktinfo->pktLen = msgdsize(mp);
13327c478bd9Sstevel@tonic-gate
13337c478bd9Sstevel@tonic-gate /* make sure packet has at least a whole mac header */
13347c478bd9Sstevel@tonic-gate if (pktinfo->pktLen < sizeof (struct tr_mac_frm_nori))
13357c478bd9Sstevel@tonic-gate return (-1);
13367c478bd9Sstevel@tonic-gate
13377c478bd9Sstevel@tonic-gate /* make sure the mac header falls into contiguous memory */
13387c478bd9Sstevel@tonic-gate if (MBLKL(mp) < sizeof (struct tr_mac_frm_nori)) {
13397c478bd9Sstevel@tonic-gate if ((pmp = msgpullup(mp, -1)) == NULL) {
13407c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
13417c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
13427c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
13437c478bd9Sstevel@tonic-gate "GLD: interpret_tr cannot msgpullup");
13447c478bd9Sstevel@tonic-gate #endif
13457c478bd9Sstevel@tonic-gate return (-1);
13467c478bd9Sstevel@tonic-gate }
13477c478bd9Sstevel@tonic-gate mp = pmp; /* this mblk contains the whole mac header */
13487c478bd9Sstevel@tonic-gate }
13497c478bd9Sstevel@tonic-gate
13507c478bd9Sstevel@tonic-gate mh = (struct tr_mac_frm *)mp->b_rptr;
13517c478bd9Sstevel@tonic-gate
13527c478bd9Sstevel@tonic-gate /* Check to see if the mac is a broadcast or multicast address. */
13537c478bd9Sstevel@tonic-gate if (mac_eq(mh->tr_dhost, ether_broadcast, macinfo->gldm_addrlen) ||
13547c478bd9Sstevel@tonic-gate mac_eq(mh->tr_dhost, tokenbroadcastaddr2, macinfo->gldm_addrlen))
13557c478bd9Sstevel@tonic-gate pktinfo->isBroadcast = 1;
13567c478bd9Sstevel@tonic-gate else if (mh->tr_dhost[0] & 0x80)
13577c478bd9Sstevel@tonic-gate pktinfo->isMulticast = 1;
13587c478bd9Sstevel@tonic-gate
13597c478bd9Sstevel@tonic-gate if (flags == GLD_TX)
13607c478bd9Sstevel@tonic-gate goto out; /* Got all info we need for xmit case */
13617c478bd9Sstevel@tonic-gate
13627c478bd9Sstevel@tonic-gate ASSERT(GLDM_LOCK_HELD(macinfo));
13637c478bd9Sstevel@tonic-gate
13647c478bd9Sstevel@tonic-gate /*
13657c478bd9Sstevel@tonic-gate * Deal with the mac header
13667c478bd9Sstevel@tonic-gate */
13677c478bd9Sstevel@tonic-gate
13687c478bd9Sstevel@tonic-gate mac_copy(mh->tr_dhost, pktinfo->dhost, macinfo->gldm_addrlen);
13697c478bd9Sstevel@tonic-gate mac_copy(mh->tr_shost, pktinfo->shost, macinfo->gldm_addrlen);
13707c478bd9Sstevel@tonic-gate pktinfo->shost[0] &= ~0x80; /* turn off RIF indicator */
13717c478bd9Sstevel@tonic-gate
13727c478bd9Sstevel@tonic-gate mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
13737c478bd9Sstevel@tonic-gate pktinfo->isLooped = mac_eq(pktinfo->shost,
13747c478bd9Sstevel@tonic-gate mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
13757c478bd9Sstevel@tonic-gate pktinfo->isForMe = mac_eq(pktinfo->dhost,
13767c478bd9Sstevel@tonic-gate mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
13777c478bd9Sstevel@tonic-gate
13787c478bd9Sstevel@tonic-gate rh = (struct gld_ri *)NULL;
13797c478bd9Sstevel@tonic-gate pktinfo->macLen = sizeof (struct tr_mac_frm_nori);
13807c478bd9Sstevel@tonic-gate
13817c478bd9Sstevel@tonic-gate /*
13827c478bd9Sstevel@tonic-gate * Before trying to look beyond the MAC header, make sure the data
13837c478bd9Sstevel@tonic-gate * structures are all contiguously where we can conveniently look at
13847c478bd9Sstevel@tonic-gate * them. We'll use a worst-case estimate of how many bytes into the
13857c478bd9Sstevel@tonic-gate * packet data we'll be needing to look. Things will be more efficient
13867c478bd9Sstevel@tonic-gate * if the driver puts at least this much into the first mblk.
13877c478bd9Sstevel@tonic-gate *
13887c478bd9Sstevel@tonic-gate * Even after this, we still will have to do checks against the total
13897c478bd9Sstevel@tonic-gate * length of the packet. A bad incoming packet may not hold all the
13907c478bd9Sstevel@tonic-gate * data structures it says it does.
13917c478bd9Sstevel@tonic-gate */
13927c478bd9Sstevel@tonic-gate if (MBLKL(mp) < sizeof (struct tr_mac_frm) +
13937c478bd9Sstevel@tonic-gate LLC_HDR1_LEN + sizeof (struct rde_pdu) &&
13947c478bd9Sstevel@tonic-gate MBLKL(mp) < pktinfo->pktLen) {
13957c478bd9Sstevel@tonic-gate /*
13967c478bd9Sstevel@tonic-gate * we don't have the entire packet within the first mblk (and
13977c478bd9Sstevel@tonic-gate * therefore we didn't do the msgpullup above), AND the first
13987c478bd9Sstevel@tonic-gate * mblk may not contain all the data we need to look at.
13997c478bd9Sstevel@tonic-gate */
14007c478bd9Sstevel@tonic-gate ASSERT(pmp == NULL); /* couldn't have done msgpullup above */
14017c478bd9Sstevel@tonic-gate if ((pmp = msgpullup(mp, -1)) == NULL) {
14027c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
14037c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
14047c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
14057c478bd9Sstevel@tonic-gate "GLD: interpret_tr cannot msgpullup2");
14067c478bd9Sstevel@tonic-gate #endif
14077c478bd9Sstevel@tonic-gate goto out; /* can't interpret this pkt further */
14087c478bd9Sstevel@tonic-gate }
14097c478bd9Sstevel@tonic-gate mp = pmp; /* this mblk should contain everything needed */
14107c478bd9Sstevel@tonic-gate mh = (struct tr_mac_frm *)mp->b_rptr; /* to look at RIF */
14117c478bd9Sstevel@tonic-gate }
14127c478bd9Sstevel@tonic-gate
14137c478bd9Sstevel@tonic-gate if (mh->tr_shost[0] & 0x80) {
14147c478bd9Sstevel@tonic-gate /* Routing Information Field (RIF) is present */
14157c478bd9Sstevel@tonic-gate if (pktinfo->pktLen < sizeof (struct tr_mac_frm_nori) + 2)
14167c478bd9Sstevel@tonic-gate goto out; /* RIF should have been there! */
14177c478bd9Sstevel@tonic-gate rh = (struct gld_ri *)&mh->tr_ri;
14187c478bd9Sstevel@tonic-gate if ((rh->len & 1) || rh->len < 2) {
14197c478bd9Sstevel@tonic-gate /* Bogus RIF, don't handle this packet */
14207c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
14217c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
14227c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
14237c478bd9Sstevel@tonic-gate "GLD: received TR packet with "
14247c478bd9Sstevel@tonic-gate "bogus RIF length %d",
14257c478bd9Sstevel@tonic-gate rh->len);
14267c478bd9Sstevel@tonic-gate #endif
14277c478bd9Sstevel@tonic-gate goto out;
14287c478bd9Sstevel@tonic-gate }
14297c478bd9Sstevel@tonic-gate if (pktinfo->pktLen < sizeof (struct tr_mac_frm_nori) + rh->len)
14307c478bd9Sstevel@tonic-gate goto out; /* RIF should have been there! */
14317c478bd9Sstevel@tonic-gate pktinfo->macLen += rh->len;
14327c478bd9Sstevel@tonic-gate }
14337c478bd9Sstevel@tonic-gate
14347c478bd9Sstevel@tonic-gate if ((mh->tr_fc & 0xc0) == 0x40) {
14357c478bd9Sstevel@tonic-gate if (pktinfo->pktLen < pktinfo->macLen + LLC_HDR1_LEN)
14367c478bd9Sstevel@tonic-gate goto out;
14377c478bd9Sstevel@tonic-gate
14387c478bd9Sstevel@tonic-gate pktinfo->isLLC = 1;
14397c478bd9Sstevel@tonic-gate
14407c478bd9Sstevel@tonic-gate if (pktinfo->pktLen < pktinfo->macLen + LLC_SNAP_HDR_LEN)
14417c478bd9Sstevel@tonic-gate goto out;
14427c478bd9Sstevel@tonic-gate
14437c478bd9Sstevel@tonic-gate snaphdr = (struct llc_snap_hdr *)(mp->b_rptr + pktinfo->macLen);
14447c478bd9Sstevel@tonic-gate if (ISETHERTYPE(snaphdr)) {
14457c478bd9Sstevel@tonic-gate pktinfo->ethertype = REF_NET_USHORT(snaphdr->type);
14467c478bd9Sstevel@tonic-gate pktinfo->hdrLen = LLC_SNAP_HDR_LEN;
14477c478bd9Sstevel@tonic-gate }
14487c478bd9Sstevel@tonic-gate
14497c478bd9Sstevel@tonic-gate /* Inform the Route Control Component of received LLC frame */
14507c478bd9Sstevel@tonic-gate gld_rcc_receive(macinfo, pktinfo, rh,
14517c478bd9Sstevel@tonic-gate mp->b_rptr + pktinfo->macLen,
14527c478bd9Sstevel@tonic-gate pktinfo->pktLen - pktinfo->macLen);
14537c478bd9Sstevel@tonic-gate }
14547c478bd9Sstevel@tonic-gate out:
14557c478bd9Sstevel@tonic-gate if (pmp != NULL)
14567c478bd9Sstevel@tonic-gate freemsg(pmp);
14577c478bd9Sstevel@tonic-gate
14587c478bd9Sstevel@tonic-gate return (0);
14597c478bd9Sstevel@tonic-gate }
14607c478bd9Sstevel@tonic-gate
14617c478bd9Sstevel@tonic-gate mblk_t *
gld_unitdata_tr(gld_t * gld,mblk_t * mp)14627c478bd9Sstevel@tonic-gate gld_unitdata_tr(gld_t *gld, mblk_t *mp)
14637c478bd9Sstevel@tonic-gate {
14647c478bd9Sstevel@tonic-gate gld_mac_info_t *macinfo = gld->gld_mac_info;
14657c478bd9Sstevel@tonic-gate dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_rptr;
14667c478bd9Sstevel@tonic-gate struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
14677c478bd9Sstevel@tonic-gate mac_addr_t dhost;
14687c478bd9Sstevel@tonic-gate unsigned short type;
14697c478bd9Sstevel@tonic-gate mblk_t *nmp, *llcmp, *pmp = NULL;
14707c478bd9Sstevel@tonic-gate struct tr_mac_frm_nori *mh;
14717c478bd9Sstevel@tonic-gate int hdrlen;
14727c478bd9Sstevel@tonic-gate struct gld_ri *rh;
14737c478bd9Sstevel@tonic-gate
14747c478bd9Sstevel@tonic-gate ASSERT(macinfo);
14757c478bd9Sstevel@tonic-gate
14767c478bd9Sstevel@tonic-gate /* extract needed info from the mblk before we maybe reuse it */
14777c478bd9Sstevel@tonic-gate mac_copy(gldp->glda_addr, dhost, macinfo->gldm_addrlen);
14787c478bd9Sstevel@tonic-gate
14797c478bd9Sstevel@tonic-gate /* look in the unitdata request for a sap, else use bound one */
14807c478bd9Sstevel@tonic-gate if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
14817c478bd9Sstevel@tonic-gate REF_HOST_USHORT(gldp->glda_sap) != 0)
14827c478bd9Sstevel@tonic-gate type = REF_HOST_USHORT(gldp->glda_sap);
14837c478bd9Sstevel@tonic-gate else
14847c478bd9Sstevel@tonic-gate type = gld->gld_sap;
14857c478bd9Sstevel@tonic-gate
14867c478bd9Sstevel@tonic-gate /* includes maximum possible Routing Information Field (RIF) size */
14877c478bd9Sstevel@tonic-gate hdrlen = sizeof (struct tr_mac_frm);
14887c478bd9Sstevel@tonic-gate
14897c478bd9Sstevel@tonic-gate /*
14907c478bd9Sstevel@tonic-gate * Check whether we need to do EtherType encoding or whether the packet
14917c478bd9Sstevel@tonic-gate * is LLC.
14927c478bd9Sstevel@tonic-gate */
14937c478bd9Sstevel@tonic-gate if (type > GLD_MAX_802_SAP)
14947c478bd9Sstevel@tonic-gate hdrlen += sizeof (struct llc_snap_hdr);
14957c478bd9Sstevel@tonic-gate
14967c478bd9Sstevel@tonic-gate /* need a buffer big enough for the headers */
14977c478bd9Sstevel@tonic-gate llcmp = nmp = mp->b_cont; /* where the packet payload M_DATA is */
14987c478bd9Sstevel@tonic-gate
14997c478bd9Sstevel@tonic-gate /*
15007c478bd9Sstevel@tonic-gate * We are going to need to look at the LLC header, so make sure it
15017c478bd9Sstevel@tonic-gate * is contiguously in a single mblk. If we're the ones who create
15027c478bd9Sstevel@tonic-gate * the LLC header (below, in the case where sap > 0xff) then we don't
15037c478bd9Sstevel@tonic-gate * have to worry about it here.
15047c478bd9Sstevel@tonic-gate */
15057c478bd9Sstevel@tonic-gate ASSERT(nmp != NULL); /* gld_unitdata guarantees msgdsize > 0 */
15067c478bd9Sstevel@tonic-gate if (type <= GLD_MAX_802_SAP) {
15077c478bd9Sstevel@tonic-gate if (MBLKL(llcmp) < LLC_HDR1_LEN) {
15087c478bd9Sstevel@tonic-gate llcmp = pmp = msgpullup(nmp, LLC_HDR1_LEN);
15097c478bd9Sstevel@tonic-gate if (pmp == NULL) {
15107c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
15117c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
15127c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
15137c478bd9Sstevel@tonic-gate "GLD: unitdata_tr "
15147c478bd9Sstevel@tonic-gate "cannot msgpullup");
15157c478bd9Sstevel@tonic-gate #endif
15167c478bd9Sstevel@tonic-gate return (NULL);
15177c478bd9Sstevel@tonic-gate }
15187c478bd9Sstevel@tonic-gate }
15197c478bd9Sstevel@tonic-gate }
15207c478bd9Sstevel@tonic-gate
15217c478bd9Sstevel@tonic-gate if (DB_REF(nmp) == 1 && MBLKHEAD(nmp) >= hdrlen) {
15227c478bd9Sstevel@tonic-gate /* it fits at the beginning of the first M_DATA block */
15237c478bd9Sstevel@tonic-gate freeb(mp); /* don't need the M_PROTO anymore */
15247c478bd9Sstevel@tonic-gate } else if (DB_REF(mp) == 1 && MBLKSIZE(mp) >= hdrlen) {
15257c478bd9Sstevel@tonic-gate /* we can reuse the dl_unitdata_req M_PROTO mblk */
15267c478bd9Sstevel@tonic-gate nmp = mp;
15277c478bd9Sstevel@tonic-gate DB_TYPE(nmp) = M_DATA;
15287c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
15297c478bd9Sstevel@tonic-gate } else {
15307c478bd9Sstevel@tonic-gate /* we need to allocate one */
15317c478bd9Sstevel@tonic-gate if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL) {
15327c478bd9Sstevel@tonic-gate if (pmp != NULL)
15337c478bd9Sstevel@tonic-gate freemsg(pmp);
15347c478bd9Sstevel@tonic-gate return (NULL);
15357c478bd9Sstevel@tonic-gate }
15367c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
15377c478bd9Sstevel@tonic-gate linkb(nmp, mp->b_cont);
15387c478bd9Sstevel@tonic-gate freeb(mp);
15397c478bd9Sstevel@tonic-gate }
15407c478bd9Sstevel@tonic-gate
15417c478bd9Sstevel@tonic-gate /* Got the space, now copy in the header components */
15427c478bd9Sstevel@tonic-gate if (type > GLD_MAX_802_SAP) {
15437c478bd9Sstevel@tonic-gate /* create the snap header */
15447c478bd9Sstevel@tonic-gate struct llc_snap_hdr *snap;
15457c478bd9Sstevel@tonic-gate llcmp = nmp; /* LLC header is going to be in this mblk */
15467c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct llc_snap_hdr);
15477c478bd9Sstevel@tonic-gate snap = (struct llc_snap_hdr *)(nmp->b_rptr);
15487c478bd9Sstevel@tonic-gate *snap = llc_snap_def;
15497c478bd9Sstevel@tonic-gate SET_NET_USHORT(snap->type, type);
15507c478bd9Sstevel@tonic-gate }
15517c478bd9Sstevel@tonic-gate
15527c478bd9Sstevel@tonic-gate /* Hold SR tables still while we maybe point at an entry */
15537c478bd9Sstevel@tonic-gate mutex_enter(GLD_SR_MUTEX(macinfo));
15547c478bd9Sstevel@tonic-gate
15557c478bd9Sstevel@tonic-gate gld_rcc_send(macinfo, WR(gld->gld_qptr), dhost, &rh, llcmp->b_rptr);
15567c478bd9Sstevel@tonic-gate
15577c478bd9Sstevel@tonic-gate if (rh != NULL) {
15587c478bd9Sstevel@tonic-gate /* copy in the RIF */
15597c478bd9Sstevel@tonic-gate ASSERT(rh->len <= sizeof (struct gld_ri));
15607c478bd9Sstevel@tonic-gate nmp->b_rptr -= rh->len;
15617c478bd9Sstevel@tonic-gate bcopy((caddr_t)rh, (caddr_t)nmp->b_rptr, rh->len);
15627c478bd9Sstevel@tonic-gate }
15637c478bd9Sstevel@tonic-gate
15647c478bd9Sstevel@tonic-gate mutex_exit(GLD_SR_MUTEX(macinfo));
15657c478bd9Sstevel@tonic-gate
15667c478bd9Sstevel@tonic-gate /* no longer need the pulled-up mblk */
15677c478bd9Sstevel@tonic-gate if (pmp != NULL)
15687c478bd9Sstevel@tonic-gate freemsg(pmp);
15697c478bd9Sstevel@tonic-gate
15707c478bd9Sstevel@tonic-gate /*
15717c478bd9Sstevel@tonic-gate * fill in token ring header
15727c478bd9Sstevel@tonic-gate */
15737c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct tr_mac_frm_nori);
15747c478bd9Sstevel@tonic-gate mh = (struct tr_mac_frm_nori *)nmp->b_rptr;
15757c478bd9Sstevel@tonic-gate mh->tr_ac = 0x10;
15767c478bd9Sstevel@tonic-gate mh->tr_fc = 0x40;
15777c478bd9Sstevel@tonic-gate mac_copy(dhost, mh->tr_dhost, macinfo->gldm_addrlen);
15787c478bd9Sstevel@tonic-gate
15797c478bd9Sstevel@tonic-gate /*
15807c478bd9Sstevel@tonic-gate * We access the mac address without the mutex to prevent
15817c478bd9Sstevel@tonic-gate * mutex contention (BUG 4211361)
15827c478bd9Sstevel@tonic-gate */
15837c478bd9Sstevel@tonic-gate mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
15847c478bd9Sstevel@tonic-gate mh->tr_shost, macinfo->gldm_addrlen);
15857c478bd9Sstevel@tonic-gate
15867c478bd9Sstevel@tonic-gate if (rh != NULL)
15877c478bd9Sstevel@tonic-gate mh->tr_shost[0] |= 0x80;
15887c478bd9Sstevel@tonic-gate else
15897c478bd9Sstevel@tonic-gate mh->tr_shost[0] &= ~0x80;
15907c478bd9Sstevel@tonic-gate
15917c478bd9Sstevel@tonic-gate return (nmp);
15927c478bd9Sstevel@tonic-gate }
15937c478bd9Sstevel@tonic-gate
15947c478bd9Sstevel@tonic-gate /*
15957c478bd9Sstevel@tonic-gate * We cannot have our client sending us "fastpath" M_DATA messages,
159648bbca81SDaniel Hoffman * because to do that we must provide a fixed MAC header to
15977c478bd9Sstevel@tonic-gate * be prepended to each outgoing packet. But with Source Routing
15987c478bd9Sstevel@tonic-gate * media, the length and content of the MAC header changes as the
15997c478bd9Sstevel@tonic-gate * routes change, so there is no fixed header we can provide. So
16007c478bd9Sstevel@tonic-gate * we decline to accept M_DATA messages if Source Routing is enabled.
16017c478bd9Sstevel@tonic-gate */
16027c478bd9Sstevel@tonic-gate mblk_t *
gld_fastpath_tr(gld_t * gld,mblk_t * mp)16037c478bd9Sstevel@tonic-gate gld_fastpath_tr(gld_t *gld, mblk_t *mp)
16047c478bd9Sstevel@tonic-gate {
16057c478bd9Sstevel@tonic-gate gld_mac_info_t *macinfo = gld->gld_mac_info;
16067c478bd9Sstevel@tonic-gate dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_cont->b_rptr;
16077c478bd9Sstevel@tonic-gate struct gld_dlsap *gldp = DLSAP(dlp, dlp->dl_dest_addr_offset);
16087c478bd9Sstevel@tonic-gate unsigned short type;
16097c478bd9Sstevel@tonic-gate mblk_t *nmp;
16107c478bd9Sstevel@tonic-gate struct tr_mac_frm_nori *mh;
16117c478bd9Sstevel@tonic-gate int hdrlen;
16127c478bd9Sstevel@tonic-gate
16137c478bd9Sstevel@tonic-gate ASSERT(macinfo);
16147c478bd9Sstevel@tonic-gate
16157c478bd9Sstevel@tonic-gate /*
16167c478bd9Sstevel@tonic-gate * If we are doing Source Routing, then we cannot provide a fixed
16177c478bd9Sstevel@tonic-gate * MAC header, so fail.
16187c478bd9Sstevel@tonic-gate */
16197c478bd9Sstevel@tonic-gate if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_enabled)
16207c478bd9Sstevel@tonic-gate return (NULL);
16217c478bd9Sstevel@tonic-gate
16227c478bd9Sstevel@tonic-gate /* look in the unitdata request for a sap, else use bound one */
16237c478bd9Sstevel@tonic-gate if (dlp->dl_dest_addr_length >= DLSAPLENGTH(macinfo) &&
16247c478bd9Sstevel@tonic-gate REF_HOST_USHORT(gldp->glda_sap) != 0)
16257c478bd9Sstevel@tonic-gate type = REF_HOST_USHORT(gldp->glda_sap);
16267c478bd9Sstevel@tonic-gate else
16277c478bd9Sstevel@tonic-gate type = gld->gld_sap;
16287c478bd9Sstevel@tonic-gate
16297c478bd9Sstevel@tonic-gate hdrlen = sizeof (struct tr_mac_frm_nori);
16307c478bd9Sstevel@tonic-gate
16317c478bd9Sstevel@tonic-gate if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_str_indicator_ste)
16327c478bd9Sstevel@tonic-gate hdrlen += ri_ste_def.len;
16337c478bd9Sstevel@tonic-gate
16347c478bd9Sstevel@tonic-gate /*
16357c478bd9Sstevel@tonic-gate * Check whether we need to do EtherType encoding or whether the packet
16367c478bd9Sstevel@tonic-gate * will be LLC.
16377c478bd9Sstevel@tonic-gate */
16387c478bd9Sstevel@tonic-gate if (type > GLD_MAX_802_SAP)
16397c478bd9Sstevel@tonic-gate hdrlen += sizeof (struct llc_snap_hdr);
16407c478bd9Sstevel@tonic-gate
16417c478bd9Sstevel@tonic-gate if ((nmp = allocb(hdrlen, BPRI_MED)) == NULL)
16427c478bd9Sstevel@tonic-gate return (NULL);
16437c478bd9Sstevel@tonic-gate
16447c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
16457c478bd9Sstevel@tonic-gate
16467c478bd9Sstevel@tonic-gate /* Got the space, now copy in the header components */
16477c478bd9Sstevel@tonic-gate
16487c478bd9Sstevel@tonic-gate if (type > GLD_MAX_802_SAP) {
16497c478bd9Sstevel@tonic-gate /* create the snap header */
16507c478bd9Sstevel@tonic-gate struct llc_snap_hdr *snap;
16517c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct llc_snap_hdr);
16527c478bd9Sstevel@tonic-gate snap = (struct llc_snap_hdr *)(nmp->b_rptr);
16537c478bd9Sstevel@tonic-gate *snap = llc_snap_def;
16547c478bd9Sstevel@tonic-gate snap->type = htons(type); /* we know it's aligned */
16557c478bd9Sstevel@tonic-gate }
16567c478bd9Sstevel@tonic-gate
16577c478bd9Sstevel@tonic-gate /* RDE is disabled, use NULL RIF, or STE RIF */
16587c478bd9Sstevel@tonic-gate if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_str_indicator_ste) {
16597c478bd9Sstevel@tonic-gate nmp->b_rptr -= ri_ste_def.len;
16607c478bd9Sstevel@tonic-gate bcopy((caddr_t)&ri_ste_def, (caddr_t)nmp->b_rptr,
16617c478bd9Sstevel@tonic-gate ri_ste_def.len);
16627c478bd9Sstevel@tonic-gate }
16637c478bd9Sstevel@tonic-gate
16647c478bd9Sstevel@tonic-gate /*
16657c478bd9Sstevel@tonic-gate * fill in token ring header
16667c478bd9Sstevel@tonic-gate */
16677c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct tr_mac_frm_nori);
16687c478bd9Sstevel@tonic-gate mh = (struct tr_mac_frm_nori *)nmp->b_rptr;
16697c478bd9Sstevel@tonic-gate mh->tr_ac = 0x10;
16707c478bd9Sstevel@tonic-gate mh->tr_fc = 0x40;
16717c478bd9Sstevel@tonic-gate mac_copy(gldp->glda_addr, mh->tr_dhost, macinfo->gldm_addrlen);
16727c478bd9Sstevel@tonic-gate
16737c478bd9Sstevel@tonic-gate GLDM_LOCK(macinfo, RW_WRITER);
16747c478bd9Sstevel@tonic-gate mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
16757c478bd9Sstevel@tonic-gate mh->tr_shost, macinfo->gldm_addrlen);
16767c478bd9Sstevel@tonic-gate GLDM_UNLOCK(macinfo);
16777c478bd9Sstevel@tonic-gate
16787c478bd9Sstevel@tonic-gate if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_str_indicator_ste)
16797c478bd9Sstevel@tonic-gate mh->tr_shost[0] |= 0x80;
16807c478bd9Sstevel@tonic-gate else
16817c478bd9Sstevel@tonic-gate mh->tr_shost[0] &= ~0x80;
16827c478bd9Sstevel@tonic-gate
16837c478bd9Sstevel@tonic-gate return (nmp);
16847c478bd9Sstevel@tonic-gate }
16857c478bd9Sstevel@tonic-gate
16867c478bd9Sstevel@tonic-gate /*
16877c478bd9Sstevel@tonic-gate * Route Determination Entity (ISO 8802-2 / IEEE 802.2 : 1994, Section 9)
16887c478bd9Sstevel@tonic-gate *
16897c478bd9Sstevel@tonic-gate * RDE is an LLC layer entity. GLD is a MAC layer entity. The proper
16907c478bd9Sstevel@tonic-gate * solution to this architectural anomaly is to move RDE support out of GLD
16917c478bd9Sstevel@tonic-gate * and into LLC where it belongs. In particular, only LLC has the knowledge
16927c478bd9Sstevel@tonic-gate * necessary to reply to XID and TEST packets. If and when it comes time to
16937c478bd9Sstevel@tonic-gate * move RDE out of GLD to LLC, the LLC-to-GLD interface should be modified
16947c478bd9Sstevel@tonic-gate * to use MA_UNITDATA structures rather than DL_UNITDATA structures. Of
16957c478bd9Sstevel@tonic-gate * course, GLD will still have to continue to also support the DL_ structures
16967c478bd9Sstevel@tonic-gate * as long as IP is not layered over LLC. Another, perhaps better, idea
16977c478bd9Sstevel@tonic-gate * would be to make RDE an autopush module on top of the token ring drivers:
16987c478bd9Sstevel@tonic-gate * RDE would sit between LLC and GLD. It would then also sit between IP and
16997c478bd9Sstevel@tonic-gate * GLD, providing services to all clients of GLD/tokenring. In that case,
17007c478bd9Sstevel@tonic-gate * GLD would still have to continue to support the DL_ interface for non-
17017c478bd9Sstevel@tonic-gate * Token Ring interfaces, using the MA_ interface only for media supporting
17027c478bd9Sstevel@tonic-gate * Source Routing media.
17037c478bd9Sstevel@tonic-gate *
17047c478bd9Sstevel@tonic-gate * At present, Token Ring is the only source routing medium we support.
17057c478bd9Sstevel@tonic-gate * Since Token Ring is not at this time a strategic network medium for Sun,
17067c478bd9Sstevel@tonic-gate * rather than devote a large amount of resources to creating a proper
17077c478bd9Sstevel@tonic-gate * architecture and implementation of RDE, we do the minimum necessary to
17087c478bd9Sstevel@tonic-gate * get it to work. The interface between the above token ring code and the
17097c478bd9Sstevel@tonic-gate * below RDE code is designed to make it relatively easy to change to an
17107c478bd9Sstevel@tonic-gate * MA_UNITDATA model later should this ever become a priority.
17117c478bd9Sstevel@tonic-gate */
17127c478bd9Sstevel@tonic-gate
17137c478bd9Sstevel@tonic-gate static void gld_send_rqr(gld_mac_info_t *, uchar_t *, struct gld_ri *,
17147c478bd9Sstevel@tonic-gate struct rde_pdu *, int);
17157c478bd9Sstevel@tonic-gate static void gld_rde_pdu_req(gld_mac_info_t *, queue_t *, uchar_t *,
17167c478bd9Sstevel@tonic-gate struct gld_ri *, uchar_t, uchar_t, uchar_t);
17177c478bd9Sstevel@tonic-gate static void gld_get_route(gld_mac_info_t *, queue_t *, uchar_t *,
17187c478bd9Sstevel@tonic-gate struct gld_ri **, uchar_t, uchar_t);
17197c478bd9Sstevel@tonic-gate static void gld_reset_route(gld_mac_info_t *, queue_t *,
17207c478bd9Sstevel@tonic-gate uchar_t *, uchar_t, uchar_t);
17217c478bd9Sstevel@tonic-gate static void gld_rde_pdu_ind(gld_mac_info_t *, struct gld_ri *, struct rde_pdu *,
17227c478bd9Sstevel@tonic-gate int);
17237c478bd9Sstevel@tonic-gate static void gld_rif_ind(gld_mac_info_t *, struct gld_ri *, uchar_t *,
17247c478bd9Sstevel@tonic-gate uchar_t, uchar_t);
17257c478bd9Sstevel@tonic-gate static struct srtab **gld_sr_hash(struct srtab **, uchar_t *, int);
17267c478bd9Sstevel@tonic-gate static struct srtab *gld_sr_lookup_entry(gld_mac_info_t *, uchar_t *);
17277c478bd9Sstevel@tonic-gate static struct srtab *gld_sr_create_entry(gld_mac_info_t *, uchar_t *);
17287c478bd9Sstevel@tonic-gate
17297c478bd9Sstevel@tonic-gate /*
17307c478bd9Sstevel@tonic-gate * This routine implements a modified subset of the 802.2 RDE RCC receive
17317c478bd9Sstevel@tonic-gate * actions:
17327c478bd9Sstevel@tonic-gate * we implement RCC receive events 3 to 12 (ISO 8802-2:1994 9.6.3.4);
17337c478bd9Sstevel@tonic-gate * we omit special handling for the NULL SAP;
17347c478bd9Sstevel@tonic-gate * we omit XID/TEST handling;
17357c478bd9Sstevel@tonic-gate * we pass all packets (including RDE) upstream to LLC.
17367c478bd9Sstevel@tonic-gate */
17377c478bd9Sstevel@tonic-gate static void
gld_rcc_receive(gld_mac_info_t * macinfo,pktinfo_t * pktinfo,struct gld_ri * rh,uchar_t * llcpkt,int llcpktlen)17387c478bd9Sstevel@tonic-gate gld_rcc_receive(gld_mac_info_t *macinfo, pktinfo_t *pktinfo, struct gld_ri *rh,
17397c478bd9Sstevel@tonic-gate uchar_t *llcpkt, int llcpktlen)
17407c478bd9Sstevel@tonic-gate {
17417c478bd9Sstevel@tonic-gate struct llc_snap_hdr *snaphdr = (struct llc_snap_hdr *)(llcpkt);
17427c478bd9Sstevel@tonic-gate
17437c478bd9Sstevel@tonic-gate if (!((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_enabled)
17447c478bd9Sstevel@tonic-gate return;
17457c478bd9Sstevel@tonic-gate
17467c478bd9Sstevel@tonic-gate /*
17477c478bd9Sstevel@tonic-gate * First, ensure this packet wasn't something we received just
17487c478bd9Sstevel@tonic-gate * because we were in promiscuous mode. Since none of the below
17497c478bd9Sstevel@tonic-gate * code wants to see group addressed packets anyway, we can do
17507c478bd9Sstevel@tonic-gate * this check up front. Since we're doing that, we can omit the
17517c478bd9Sstevel@tonic-gate * checks for group addressed packets below.
17527c478bd9Sstevel@tonic-gate */
17537c478bd9Sstevel@tonic-gate if (!pktinfo->isForMe)
17547c478bd9Sstevel@tonic-gate return; /* Event 6 */
17557c478bd9Sstevel@tonic-gate
17567c478bd9Sstevel@tonic-gate /* Process a subset of Route Determination Entity (RDE) packets */
17577c478bd9Sstevel@tonic-gate if (snaphdr->d_lsap == LSAP_RDE) {
17587c478bd9Sstevel@tonic-gate struct rde_pdu *pdu = (struct rde_pdu *)(llcpkt + LLC_HDR1_LEN);
17597c478bd9Sstevel@tonic-gate int pdulen = llcpktlen - LLC_HDR1_LEN;
17607c478bd9Sstevel@tonic-gate
17617c478bd9Sstevel@tonic-gate /* sanity check the PDU */
17627c478bd9Sstevel@tonic-gate if ((pdulen < sizeof (struct rde_pdu)) ||
17637c478bd9Sstevel@tonic-gate (snaphdr->s_lsap != LSAP_RDE))
17647c478bd9Sstevel@tonic-gate return;
17657c478bd9Sstevel@tonic-gate
17667c478bd9Sstevel@tonic-gate /* we only handle route discovery PDUs, not XID/TEST/other */
17677c478bd9Sstevel@tonic-gate if (snaphdr->control != CNTL_LLC_UI)
17687c478bd9Sstevel@tonic-gate return;
17697c478bd9Sstevel@tonic-gate
17707c478bd9Sstevel@tonic-gate switch (pdu->rde_ptype) {
17717c478bd9Sstevel@tonic-gate case RDE_RQC: /* Route Query Command; Events 8 - 11 */
17727c478bd9Sstevel@tonic-gate gld_send_rqr(macinfo, pktinfo->shost, rh, pdu, pdulen);
17737c478bd9Sstevel@tonic-gate /* FALLTHROUGH */
17747c478bd9Sstevel@tonic-gate case RDE_RQR: /* Route Query Response; Event 12 */
17757c478bd9Sstevel@tonic-gate case RDE_RS: /* Route Selected; Event 7 */
17767c478bd9Sstevel@tonic-gate gld_rde_pdu_ind(macinfo, rh, pdu, pdulen);
17777c478bd9Sstevel@tonic-gate break;
17787c478bd9Sstevel@tonic-gate default: /* ignore if unrecognized ptype */
17797c478bd9Sstevel@tonic-gate return;
17807c478bd9Sstevel@tonic-gate }
17817c478bd9Sstevel@tonic-gate
17827c478bd9Sstevel@tonic-gate return;
17837c478bd9Sstevel@tonic-gate }
17847c478bd9Sstevel@tonic-gate
17857c478bd9Sstevel@tonic-gate /* Consider routes seen in other IA SRF packets */
17867c478bd9Sstevel@tonic-gate
17877c478bd9Sstevel@tonic-gate if (rh == NULL)
17887c478bd9Sstevel@tonic-gate return; /* no RIF; Event 3 */
17897c478bd9Sstevel@tonic-gate
17907c478bd9Sstevel@tonic-gate if ((rh->rt & 0x04) != 0)
17917c478bd9Sstevel@tonic-gate return; /* not SRF; Event 5 */
17927c478bd9Sstevel@tonic-gate
17937c478bd9Sstevel@tonic-gate gld_rif_ind(macinfo, rh, pktinfo->shost, snaphdr->s_lsap,
17947c478bd9Sstevel@tonic-gate snaphdr->d_lsap); /* Event 4 */
17957c478bd9Sstevel@tonic-gate }
17967c478bd9Sstevel@tonic-gate
17977c478bd9Sstevel@tonic-gate /*
17987c478bd9Sstevel@tonic-gate * Send RQR: 802.2 9.6.3.4.2(9) RCC Receive Events 8-11
17997c478bd9Sstevel@tonic-gate *
18007c478bd9Sstevel@tonic-gate * The routing processing really doesn't belong here; it should be handled in
18017c478bd9Sstevel@tonic-gate * the LLC layer above. If that were the case then RDE could just send down
18027c478bd9Sstevel@tonic-gate * an extra MA_UNITDATA_REQ with the info needed to construct the packet. But
18037c478bd9Sstevel@tonic-gate * at the time we get control here, it's not a particularly good time to be
18047c478bd9Sstevel@tonic-gate * constructing packets and trying to send them. Specifically, at this layer
18057c478bd9Sstevel@tonic-gate * we need to construct the full media packet, which means the below routine
18067c478bd9Sstevel@tonic-gate * knows that it is dealing with Token Ring media. If this were instead done
18077c478bd9Sstevel@tonic-gate * via a proper MA_UNITDATA interface, the RDE stuff could all be completely
18087c478bd9Sstevel@tonic-gate * media independent. But since TR is the only source routing medium we
18097c478bd9Sstevel@tonic-gate * support, this works even though it is not clean.
18107c478bd9Sstevel@tonic-gate *
18117c478bd9Sstevel@tonic-gate * We "know" that the only time we can get here is from the "interpret"
18127c478bd9Sstevel@tonic-gate * routine, and only when it was called at receive time.
18137c478bd9Sstevel@tonic-gate */
18147c478bd9Sstevel@tonic-gate static void
gld_send_rqr(gld_mac_info_t * macinfo,uchar_t * shost,struct gld_ri * rh,struct rde_pdu * pdu,int pdulen)18157c478bd9Sstevel@tonic-gate gld_send_rqr(gld_mac_info_t *macinfo, uchar_t *shost, struct gld_ri *rh,
18167c478bd9Sstevel@tonic-gate struct rde_pdu *pdu, int pdulen)
18177c478bd9Sstevel@tonic-gate {
18187c478bd9Sstevel@tonic-gate mblk_t *nmp;
18197c478bd9Sstevel@tonic-gate int nlen;
18207c478bd9Sstevel@tonic-gate struct tr_mac_frm_nori *nmh;
18217c478bd9Sstevel@tonic-gate struct gld_ri *nrh;
18227c478bd9Sstevel@tonic-gate struct llc_snap_hdr *nsnaphdr;
18237c478bd9Sstevel@tonic-gate struct rde_pdu *npdu;
18247c478bd9Sstevel@tonic-gate
18257c478bd9Sstevel@tonic-gate /* We know and assume we're on the receive path */
18267c478bd9Sstevel@tonic-gate ASSERT(GLDM_LOCK_HELD(macinfo));
18277c478bd9Sstevel@tonic-gate
18287c478bd9Sstevel@tonic-gate if (pdulen < sizeof (struct rde_pdu))
18297c478bd9Sstevel@tonic-gate return; /* Bad incoming PDU */
18307c478bd9Sstevel@tonic-gate
18317c478bd9Sstevel@tonic-gate nlen = sizeof (struct tr_mac_frm) + LLC_HDR1_LEN +
18327c478bd9Sstevel@tonic-gate sizeof (struct rde_pdu);
18337c478bd9Sstevel@tonic-gate
18347c478bd9Sstevel@tonic-gate if ((nmp = allocb(nlen, BPRI_MED)) == NULL)
18357c478bd9Sstevel@tonic-gate return;
18367c478bd9Sstevel@tonic-gate
18377c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
18387c478bd9Sstevel@tonic-gate
18397c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct rde_pdu);
18407c478bd9Sstevel@tonic-gate npdu = (struct rde_pdu *)(nmp->b_rptr);
18417c478bd9Sstevel@tonic-gate *npdu = *pdu; /* copy orig/target macaddr/saps */
18427c478bd9Sstevel@tonic-gate npdu->rde_ver = 1;
18437c478bd9Sstevel@tonic-gate npdu->rde_ptype = RDE_RQR;
18447c478bd9Sstevel@tonic-gate mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
18457c478bd9Sstevel@tonic-gate npdu->rde_target_mac, macinfo->gldm_addrlen);
18467c478bd9Sstevel@tonic-gate
18477c478bd9Sstevel@tonic-gate nmp->b_rptr -= LLC_HDR1_LEN;
18487c478bd9Sstevel@tonic-gate nsnaphdr = (struct llc_snap_hdr *)(nmp->b_rptr);
18497c478bd9Sstevel@tonic-gate nsnaphdr->s_lsap = nsnaphdr->d_lsap = LSAP_RDE;
18507c478bd9Sstevel@tonic-gate nsnaphdr->control = CNTL_LLC_UI;
18517c478bd9Sstevel@tonic-gate
18527c478bd9Sstevel@tonic-gate if (rh == NULL || (rh->rt & 0x06) == 0x06 ||
18537c478bd9Sstevel@tonic-gate rh->len > sizeof (struct gld_ri)) {
18547c478bd9Sstevel@tonic-gate /* no RIF (Event 8), or RIF type STE (Event 9): send ARE RQR */
18557c478bd9Sstevel@tonic-gate nmp->b_rptr -= 2;
18567c478bd9Sstevel@tonic-gate nrh = (struct gld_ri *)(nmp->b_rptr);
18577c478bd9Sstevel@tonic-gate nrh->len = 2;
18587c478bd9Sstevel@tonic-gate nrh->rt = RT_ARE;
18597c478bd9Sstevel@tonic-gate nrh->dir = 0;
18607c478bd9Sstevel@tonic-gate nrh->res = 0;
18617c478bd9Sstevel@tonic-gate nrh->mtu = RT_MTU_MAX;
18627c478bd9Sstevel@tonic-gate } else {
18637c478bd9Sstevel@tonic-gate /*
18647c478bd9Sstevel@tonic-gate * RIF must be ARE (Event 10) or SRF (Event 11):
18657c478bd9Sstevel@tonic-gate * send SRF (reverse) RQR
18667c478bd9Sstevel@tonic-gate */
18677c478bd9Sstevel@tonic-gate ASSERT(rh->len <= sizeof (struct gld_ri));
18687c478bd9Sstevel@tonic-gate nmp->b_rptr -= rh->len;
18697c478bd9Sstevel@tonic-gate nrh = (struct gld_ri *)(nmp->b_rptr);
18707c478bd9Sstevel@tonic-gate bcopy(rh, nrh, rh->len); /* copy incoming RIF */
18717c478bd9Sstevel@tonic-gate nrh->rt = RT_SRF; /* make it SRF */
18727c478bd9Sstevel@tonic-gate nrh->dir ^= 1; /* reverse direction */
18737c478bd9Sstevel@tonic-gate }
18747c478bd9Sstevel@tonic-gate
18757c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct tr_mac_frm_nori);
18767c478bd9Sstevel@tonic-gate nmh = (struct tr_mac_frm_nori *)(nmp->b_rptr);
18777c478bd9Sstevel@tonic-gate nmh->tr_ac = 0x10;
18787c478bd9Sstevel@tonic-gate nmh->tr_fc = 0x40;
18797c478bd9Sstevel@tonic-gate mac_copy(shost, nmh->tr_dhost, macinfo->gldm_addrlen);
18807c478bd9Sstevel@tonic-gate mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
18817c478bd9Sstevel@tonic-gate nmh->tr_shost, macinfo->gldm_addrlen);
18827c478bd9Sstevel@tonic-gate nmh->tr_shost[0] |= 0x80; /* indicate RIF present */
18837c478bd9Sstevel@tonic-gate
18847c478bd9Sstevel@tonic-gate /*
18857c478bd9Sstevel@tonic-gate * Packet assembled; send it.
18867c478bd9Sstevel@tonic-gate *
18877c478bd9Sstevel@tonic-gate * As noted before, this is not really a good time to be trying to
18887c478bd9Sstevel@tonic-gate * send out packets. We have no obvious queue to use if the packet
18897c478bd9Sstevel@tonic-gate * can't be sent right away. We pick one arbitrarily.
18907c478bd9Sstevel@tonic-gate */
18917c478bd9Sstevel@tonic-gate {
18927c478bd9Sstevel@tonic-gate gld_vlan_t *vlan;
18937c478bd9Sstevel@tonic-gate queue_t *q;
18947c478bd9Sstevel@tonic-gate
18957c478bd9Sstevel@tonic-gate if ((vlan = gld_find_vlan(macinfo, VLAN_VID_NONE)) == NULL) {
18967c478bd9Sstevel@tonic-gate /* oops, no vlan on the list for this macinfo! */
18977c478bd9Sstevel@tonic-gate /* this should not happen */
18987c478bd9Sstevel@tonic-gate freeb(nmp);
18997c478bd9Sstevel@tonic-gate return;
19007c478bd9Sstevel@tonic-gate }
19017c478bd9Sstevel@tonic-gate q = vlan->gldv_str_next->gld_qptr;
19027c478bd9Sstevel@tonic-gate
19037c478bd9Sstevel@tonic-gate /*
19047c478bd9Sstevel@tonic-gate * Queue the packet and let gld_wsrv
19057c478bd9Sstevel@tonic-gate * handle it, thus preventing a panic
19067c478bd9Sstevel@tonic-gate * caused by v2 TR in promiscuous mode
19077c478bd9Sstevel@tonic-gate * where it attempts to get the mutex
19087c478bd9Sstevel@tonic-gate * in this thread while already holding
19097c478bd9Sstevel@tonic-gate * it.
19107c478bd9Sstevel@tonic-gate */
19117c478bd9Sstevel@tonic-gate (void) putbq(WR(q), nmp);
19127c478bd9Sstevel@tonic-gate qenable(WR(q));
19137c478bd9Sstevel@tonic-gate }
19147c478bd9Sstevel@tonic-gate }
19157c478bd9Sstevel@tonic-gate
19167c478bd9Sstevel@tonic-gate /*
19177c478bd9Sstevel@tonic-gate * This routine implements a modified subset of the 802.2 RDE RCC send actions:
19187c478bd9Sstevel@tonic-gate * we implement RCC send events 5 to 10 (ISO 8802-2:1994 9.6.3.5);
19197c478bd9Sstevel@tonic-gate * we omit special handling for the NULL SAP;
19207c478bd9Sstevel@tonic-gate * events 11 to 12 are handled by gld_rde_pdu_req below;
19217c478bd9Sstevel@tonic-gate * we require an immediate response to our GET_ROUTE_REQUEST.
19227c478bd9Sstevel@tonic-gate */
19237c478bd9Sstevel@tonic-gate static void
gld_rcc_send(gld_mac_info_t * macinfo,queue_t * q,uchar_t * dhost,struct gld_ri ** rhp,uchar_t * llcpkt)19247c478bd9Sstevel@tonic-gate gld_rcc_send(gld_mac_info_t *macinfo, queue_t *q, uchar_t *dhost,
19257c478bd9Sstevel@tonic-gate struct gld_ri **rhp, uchar_t *llcpkt)
19267c478bd9Sstevel@tonic-gate {
19277c478bd9Sstevel@tonic-gate struct llc_snap_hdr *snaphdr = (struct llc_snap_hdr *)(llcpkt);
19287c478bd9Sstevel@tonic-gate
19297c478bd9Sstevel@tonic-gate /*
19307c478bd9Sstevel@tonic-gate * Our caller has to take the mutex because: to avoid an extra bcopy
19317c478bd9Sstevel@tonic-gate * of the RIF on every transmit, we pass back a pointer to our sr
193248bbca81SDaniel Hoffman * table entry via rhp. The caller has to keep the mutex until it has a
19337c478bd9Sstevel@tonic-gate * chance to copy the RIF out into the outgoing packet, so that we
193448bbca81SDaniel Hoffman * don't modify the entry while it's being copied. This is a
19357c478bd9Sstevel@tonic-gate * little ugly, but saves the extra bcopy.
19367c478bd9Sstevel@tonic-gate */
19377c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo)));
19387c478bd9Sstevel@tonic-gate
19397c478bd9Sstevel@tonic-gate *rhp = (struct gld_ri *)NULL; /* start off clean (no RIF) */
19407c478bd9Sstevel@tonic-gate
19417c478bd9Sstevel@tonic-gate if (!((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_enabled) {
19427c478bd9Sstevel@tonic-gate /* RDE is disabled -- use NULL or STE always */
19437c478bd9Sstevel@tonic-gate if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->
19447c478bd9Sstevel@tonic-gate rde_str_indicator_ste)
19457c478bd9Sstevel@tonic-gate *rhp = &ri_ste_def; /* STE option */
19467c478bd9Sstevel@tonic-gate return;
19477c478bd9Sstevel@tonic-gate }
19487c478bd9Sstevel@tonic-gate
19497c478bd9Sstevel@tonic-gate if (!(dhost[0] & 0x80)) {
19507c478bd9Sstevel@tonic-gate /* individual address; Events 7 - 10 */
19517c478bd9Sstevel@tonic-gate if ((snaphdr->control & 0xef) == 0xe3) {
19527c478bd9Sstevel@tonic-gate /* TEST command, reset the route */
19537c478bd9Sstevel@tonic-gate gld_reset_route(macinfo, q,
19547c478bd9Sstevel@tonic-gate dhost, snaphdr->d_lsap, snaphdr->s_lsap);
19557c478bd9Sstevel@tonic-gate }
19567c478bd9Sstevel@tonic-gate gld_get_route(macinfo, q,
19577c478bd9Sstevel@tonic-gate dhost, rhp, snaphdr->d_lsap, snaphdr->s_lsap);
19587c478bd9Sstevel@tonic-gate }
19597c478bd9Sstevel@tonic-gate
19607c478bd9Sstevel@tonic-gate if (*rhp == NULL) {
19617c478bd9Sstevel@tonic-gate /*
19627c478bd9Sstevel@tonic-gate * group address (Events 5 - 6),
19637c478bd9Sstevel@tonic-gate * or no route available (Events 8 - 9):
19647c478bd9Sstevel@tonic-gate * Need to send NSR or STE, as configured.
19657c478bd9Sstevel@tonic-gate */
19667c478bd9Sstevel@tonic-gate if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->
19677c478bd9Sstevel@tonic-gate rde_str_indicator_ste)
19687c478bd9Sstevel@tonic-gate *rhp = &ri_ste_def; /* STE option */
19697c478bd9Sstevel@tonic-gate }
19707c478bd9Sstevel@tonic-gate }
19717c478bd9Sstevel@tonic-gate
19727c478bd9Sstevel@tonic-gate /*
19737c478bd9Sstevel@tonic-gate * RCC send events 11 - 12
19747c478bd9Sstevel@tonic-gate *
19757c478bd9Sstevel@tonic-gate * At present we only handle the RQC ptype.
19767c478bd9Sstevel@tonic-gate *
19777c478bd9Sstevel@tonic-gate * We "know" that the only time we can get here is from the "unitdata"
19787c478bd9Sstevel@tonic-gate * routine, called at wsrv time.
19797c478bd9Sstevel@tonic-gate *
19807c478bd9Sstevel@tonic-gate * If we ever implement the RS ptype (Event 13), this may no longer be true!
19817c478bd9Sstevel@tonic-gate */
19827c478bd9Sstevel@tonic-gate static void
gld_rde_pdu_req(gld_mac_info_t * macinfo,queue_t * q,uchar_t * dhost,struct gld_ri * rh,uchar_t dsap,uchar_t ssap,uchar_t ptype)19837c478bd9Sstevel@tonic-gate gld_rde_pdu_req(gld_mac_info_t *macinfo, queue_t *q, uchar_t *dhost,
19847c478bd9Sstevel@tonic-gate struct gld_ri *rh, uchar_t dsap, uchar_t ssap, uchar_t ptype)
19857c478bd9Sstevel@tonic-gate {
19867c478bd9Sstevel@tonic-gate mblk_t *nmp;
19877c478bd9Sstevel@tonic-gate int nlen;
19887c478bd9Sstevel@tonic-gate struct tr_mac_frm_nori *nmh;
19897c478bd9Sstevel@tonic-gate struct gld_ri *nrh;
19907c478bd9Sstevel@tonic-gate struct llc_snap_hdr *nsnaphdr;
19917c478bd9Sstevel@tonic-gate struct rde_pdu *npdu;
19927c478bd9Sstevel@tonic-gate int srpresent = 0;
19937c478bd9Sstevel@tonic-gate
19947c478bd9Sstevel@tonic-gate /* if you change this to process other types, review all code below */
19957c478bd9Sstevel@tonic-gate ASSERT(ptype == RDE_RQC);
19967c478bd9Sstevel@tonic-gate ASSERT(rh == NULL); /* RQC never uses SRF */
19977c478bd9Sstevel@tonic-gate
19987c478bd9Sstevel@tonic-gate nlen = sizeof (struct tr_mac_frm) + LLC_HDR1_LEN +
19997c478bd9Sstevel@tonic-gate sizeof (struct rde_pdu);
20007c478bd9Sstevel@tonic-gate
20017c478bd9Sstevel@tonic-gate if ((nmp = allocb(nlen, BPRI_MED)) == NULL)
20027c478bd9Sstevel@tonic-gate return;
20037c478bd9Sstevel@tonic-gate
20047c478bd9Sstevel@tonic-gate nmp->b_rptr = nmp->b_wptr = DB_LIM(nmp);
20057c478bd9Sstevel@tonic-gate
20067c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct rde_pdu);
20077c478bd9Sstevel@tonic-gate npdu = (struct rde_pdu *)(nmp->b_rptr);
20087c478bd9Sstevel@tonic-gate npdu->rde_ver = 1;
20097c478bd9Sstevel@tonic-gate npdu->rde_ptype = ptype;
20107c478bd9Sstevel@tonic-gate mac_copy(dhost, &npdu->rde_target_mac, 6);
20117c478bd9Sstevel@tonic-gate
20127c478bd9Sstevel@tonic-gate /*
20137c478bd9Sstevel@tonic-gate * access the mac address without a mutex - take a risk -
20147c478bd9Sstevel@tonic-gate * to prevent mutex contention (BUG 4211361)
20157c478bd9Sstevel@tonic-gate */
20167c478bd9Sstevel@tonic-gate mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
20177c478bd9Sstevel@tonic-gate &npdu->rde_orig_mac, 6);
20187c478bd9Sstevel@tonic-gate npdu->rde_target_sap = dsap;
20197c478bd9Sstevel@tonic-gate npdu->rde_orig_sap = ssap;
20207c478bd9Sstevel@tonic-gate
20217c478bd9Sstevel@tonic-gate nmp->b_rptr -= LLC_HDR1_LEN;
20227c478bd9Sstevel@tonic-gate nsnaphdr = (struct llc_snap_hdr *)(nmp->b_rptr);
20237c478bd9Sstevel@tonic-gate nsnaphdr->s_lsap = nsnaphdr->d_lsap = LSAP_RDE;
20247c478bd9Sstevel@tonic-gate nsnaphdr->control = CNTL_LLC_UI;
20257c478bd9Sstevel@tonic-gate
20267c478bd9Sstevel@tonic-gate #if 0 /* we don't need this for now */
20277c478bd9Sstevel@tonic-gate if (rh != NULL) {
20287c478bd9Sstevel@tonic-gate /* send an SRF frame with specified RIF */
20297c478bd9Sstevel@tonic-gate ASSERT(rh->len <= sizeof (struct gld_ri));
20307c478bd9Sstevel@tonic-gate nmp->b_rptr -= rh->len;
20317c478bd9Sstevel@tonic-gate nrh = (struct gld_ri *)(nmp->b_rptr);
20327c478bd9Sstevel@tonic-gate bcopy(rh, nrh, rh->len);
20337c478bd9Sstevel@tonic-gate ASSERT(nrh->rt == RT_SRF);
20347c478bd9Sstevel@tonic-gate srpresent = 1;
20357c478bd9Sstevel@tonic-gate } else
20367c478bd9Sstevel@tonic-gate #endif
20377c478bd9Sstevel@tonic-gate
20387c478bd9Sstevel@tonic-gate /* Need to send NSR or STE, as configured. */
20397c478bd9Sstevel@tonic-gate if (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_str_indicator_ste) {
20407c478bd9Sstevel@tonic-gate /* send an STE frame */
20417c478bd9Sstevel@tonic-gate nmp->b_rptr -= 2;
20427c478bd9Sstevel@tonic-gate nrh = (struct gld_ri *)(nmp->b_rptr);
20437c478bd9Sstevel@tonic-gate nrh->len = 2;
20447c478bd9Sstevel@tonic-gate nrh->rt = RT_STE;
20457c478bd9Sstevel@tonic-gate nrh->dir = 0;
20467c478bd9Sstevel@tonic-gate nrh->res = 0;
20477c478bd9Sstevel@tonic-gate nrh->mtu = RT_MTU_MAX;
20487c478bd9Sstevel@tonic-gate srpresent = 1;
20497c478bd9Sstevel@tonic-gate } /* else send an NSR frame */
20507c478bd9Sstevel@tonic-gate
20517c478bd9Sstevel@tonic-gate nmp->b_rptr -= sizeof (struct tr_mac_frm_nori);
20527c478bd9Sstevel@tonic-gate nmh = (struct tr_mac_frm_nori *)(nmp->b_rptr);
20537c478bd9Sstevel@tonic-gate nmh->tr_ac = 0x10;
20547c478bd9Sstevel@tonic-gate nmh->tr_fc = 0x40;
20557c478bd9Sstevel@tonic-gate mac_copy(dhost, nmh->tr_dhost, macinfo->gldm_addrlen);
20567c478bd9Sstevel@tonic-gate /*
20577c478bd9Sstevel@tonic-gate * access the mac address without a mutex - take a risk -
20587c478bd9Sstevel@tonic-gate * to prevent mutex contention - BUG 4211361
20597c478bd9Sstevel@tonic-gate */
20607c478bd9Sstevel@tonic-gate mac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
20617c478bd9Sstevel@tonic-gate nmh->tr_shost, macinfo->gldm_addrlen);
20627c478bd9Sstevel@tonic-gate
20637c478bd9Sstevel@tonic-gate if (srpresent)
20647c478bd9Sstevel@tonic-gate nmh->tr_shost[0] |= 0x80;
20657c478bd9Sstevel@tonic-gate else
20667c478bd9Sstevel@tonic-gate nmh->tr_shost[0] &= ~0x80;
20677c478bd9Sstevel@tonic-gate
20687c478bd9Sstevel@tonic-gate /*
20697c478bd9Sstevel@tonic-gate * Packet assembled; send it.
20707c478bd9Sstevel@tonic-gate *
20717c478bd9Sstevel@tonic-gate * Since we own the SR_MUTEX, we don't want to take the maclock
20727c478bd9Sstevel@tonic-gate * mutex (since they are acquired in the opposite order on the
20737c478bd9Sstevel@tonic-gate * receive path, so deadlock could occur). We could rearrange
20747c478bd9Sstevel@tonic-gate * the code in gld_get_route() and drop the SR_MUTEX around the
20757c478bd9Sstevel@tonic-gate * call to gld_rde_pdu_req(), but that's kind of ugly. Rather,
20767c478bd9Sstevel@tonic-gate * we just refrain from calling gld_start() from here, and
20777c478bd9Sstevel@tonic-gate * instead just queue the packet for wsrv to send next. Besides,
20787c478bd9Sstevel@tonic-gate * it's more important to get the packet we're working on out
20797c478bd9Sstevel@tonic-gate * quickly than this RQC.
20807c478bd9Sstevel@tonic-gate */
20817c478bd9Sstevel@tonic-gate (void) putbq(WR(q), nmp);
20827c478bd9Sstevel@tonic-gate qenable(WR(q));
20837c478bd9Sstevel@tonic-gate }
20847c478bd9Sstevel@tonic-gate
20857c478bd9Sstevel@tonic-gate /*
20867c478bd9Sstevel@tonic-gate * Route Determination Component (RDC)
20877c478bd9Sstevel@tonic-gate *
20887c478bd9Sstevel@tonic-gate * We do not implement separate routes for each SAP, as specified by
20897c478bd9Sstevel@tonic-gate * ISO 8802-2; instead we implement only one route per remote mac address.
20907c478bd9Sstevel@tonic-gate */
20917c478bd9Sstevel@tonic-gate static void
gld_get_route(gld_mac_info_t * macinfo,queue_t * q,uchar_t * dhost,struct gld_ri ** rhp,uchar_t dsap,uchar_t ssap)20927c478bd9Sstevel@tonic-gate gld_get_route(gld_mac_info_t *macinfo, queue_t *q, uchar_t *dhost,
20937c478bd9Sstevel@tonic-gate struct gld_ri **rhp, uchar_t dsap, uchar_t ssap)
20947c478bd9Sstevel@tonic-gate {
20957c478bd9Sstevel@tonic-gate struct srtab *sr;
20967c478bd9Sstevel@tonic-gate clock_t t = ddi_get_lbolt();
20977c478bd9Sstevel@tonic-gate
20987c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo)));
20997c478bd9Sstevel@tonic-gate
21007c478bd9Sstevel@tonic-gate sr = gld_sr_lookup_entry(macinfo, dhost);
21017c478bd9Sstevel@tonic-gate
21027c478bd9Sstevel@tonic-gate if (sr == NULL) {
21037c478bd9Sstevel@tonic-gate /*
21047c478bd9Sstevel@tonic-gate * we have no entry -- never heard of this address:
21057c478bd9Sstevel@tonic-gate * create an empty entry and initiate RQC
21067c478bd9Sstevel@tonic-gate */
21077c478bd9Sstevel@tonic-gate sr = gld_sr_create_entry(macinfo, dhost);
21087c478bd9Sstevel@tonic-gate gld_rde_pdu_req(macinfo, q, dhost, (struct gld_ri *)NULL,
21097c478bd9Sstevel@tonic-gate dsap, ssap, RDE_RQC);
21107c478bd9Sstevel@tonic-gate if (sr)
21117c478bd9Sstevel@tonic-gate sr->sr_timer = t;
21127c478bd9Sstevel@tonic-gate *rhp = NULL; /* we have no route yet */
21137c478bd9Sstevel@tonic-gate return;
21147c478bd9Sstevel@tonic-gate }
21157c478bd9Sstevel@tonic-gate
21167c478bd9Sstevel@tonic-gate /* we have an entry; see if we know a route yet */
21177c478bd9Sstevel@tonic-gate
21187c478bd9Sstevel@tonic-gate if (sr->sr_ri.len == 0) {
21197c478bd9Sstevel@tonic-gate /* Have asked RQC, but no reply (yet) */
21207c478bd9Sstevel@tonic-gate if (t - sr->sr_timer >
21217c478bd9Sstevel@tonic-gate ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_timeout) {
21227c478bd9Sstevel@tonic-gate /* RQR overdue, resend RQC */
21237c478bd9Sstevel@tonic-gate gld_rde_pdu_req(macinfo, q, dhost,
21247c478bd9Sstevel@tonic-gate (struct gld_ri *)NULL, dsap, ssap, RDE_RQC);
21257c478bd9Sstevel@tonic-gate sr->sr_timer = t;
21267c478bd9Sstevel@tonic-gate }
21277c478bd9Sstevel@tonic-gate *rhp = NULL; /* we have no route yet */
21287c478bd9Sstevel@tonic-gate return;
21297c478bd9Sstevel@tonic-gate }
21307c478bd9Sstevel@tonic-gate
21317c478bd9Sstevel@tonic-gate /* we know a route, or it's local */
21327c478bd9Sstevel@tonic-gate
21337c478bd9Sstevel@tonic-gate /* if it might be stale, reset and get a new one */
21347c478bd9Sstevel@tonic-gate if (t - sr->sr_timer >
21357c478bd9Sstevel@tonic-gate ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->rde_timeout) {
21367c478bd9Sstevel@tonic-gate gld_rde_pdu_req(macinfo, q, dhost,
21377c478bd9Sstevel@tonic-gate (struct gld_ri *)NULL, dsap, ssap, RDE_RQC);
21387c478bd9Sstevel@tonic-gate sr->sr_ri.len = 0;
21397c478bd9Sstevel@tonic-gate sr->sr_timer = t;
21407c478bd9Sstevel@tonic-gate *rhp = NULL; /* we have no route */
21417c478bd9Sstevel@tonic-gate return;
21427c478bd9Sstevel@tonic-gate }
21437c478bd9Sstevel@tonic-gate
21447c478bd9Sstevel@tonic-gate if (sr->sr_ri.len == 2) {
21457c478bd9Sstevel@tonic-gate /* the remote site is on our local ring -- no route needed */
21467c478bd9Sstevel@tonic-gate *rhp = NULL;
21477c478bd9Sstevel@tonic-gate return;
21487c478bd9Sstevel@tonic-gate }
21497c478bd9Sstevel@tonic-gate
21507c478bd9Sstevel@tonic-gate *rhp = &sr->sr_ri; /* we have a route, return it */
21517c478bd9Sstevel@tonic-gate }
21527c478bd9Sstevel@tonic-gate
21537c478bd9Sstevel@tonic-gate /*
21547c478bd9Sstevel@tonic-gate * zap the specified entry and reinitiate RQC
21557c478bd9Sstevel@tonic-gate */
21567c478bd9Sstevel@tonic-gate static void
gld_reset_route(gld_mac_info_t * macinfo,queue_t * q,uchar_t * dhost,uchar_t dsap,uchar_t ssap)21577c478bd9Sstevel@tonic-gate gld_reset_route(gld_mac_info_t *macinfo, queue_t *q,
21587c478bd9Sstevel@tonic-gate uchar_t *dhost, uchar_t dsap, uchar_t ssap)
21597c478bd9Sstevel@tonic-gate {
21607c478bd9Sstevel@tonic-gate struct srtab *sr;
21617c478bd9Sstevel@tonic-gate
21627c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo)));
21637c478bd9Sstevel@tonic-gate
21647c478bd9Sstevel@tonic-gate sr = gld_sr_create_entry(macinfo, dhost);
21657c478bd9Sstevel@tonic-gate gld_rde_pdu_req(macinfo, q, dhost, (struct gld_ri *)NULL,
21667c478bd9Sstevel@tonic-gate dsap, ssap, RDE_RQC);
21677c478bd9Sstevel@tonic-gate if (sr == NULL)
21687c478bd9Sstevel@tonic-gate return;
21697c478bd9Sstevel@tonic-gate
21707c478bd9Sstevel@tonic-gate sr->sr_ri.len = 0;
21717c478bd9Sstevel@tonic-gate sr->sr_timer = ddi_get_lbolt();
21727c478bd9Sstevel@tonic-gate }
21737c478bd9Sstevel@tonic-gate
21747c478bd9Sstevel@tonic-gate /*
21757c478bd9Sstevel@tonic-gate * This routine is called when an RDE PDU is received from our peer.
21767c478bd9Sstevel@tonic-gate * If it is an RS (Route Selected) PDU, we adopt the specified route.
21777c478bd9Sstevel@tonic-gate * If it is an RQR (reply to our previous RQC), we evaluate the
21787c478bd9Sstevel@tonic-gate * specified route in comparison with our current known route, if any,
21797c478bd9Sstevel@tonic-gate * and we keep the "better" of the two routes.
21807c478bd9Sstevel@tonic-gate */
21817c478bd9Sstevel@tonic-gate static void
gld_rde_pdu_ind(gld_mac_info_t * macinfo,struct gld_ri * rh,struct rde_pdu * pdu,int pdulen)21827c478bd9Sstevel@tonic-gate gld_rde_pdu_ind(gld_mac_info_t *macinfo, struct gld_ri *rh, struct rde_pdu *pdu,
21837c478bd9Sstevel@tonic-gate int pdulen)
21847c478bd9Sstevel@tonic-gate {
21857c478bd9Sstevel@tonic-gate struct srtab *sr;
21867c478bd9Sstevel@tonic-gate uchar_t *otherhost;
21877c478bd9Sstevel@tonic-gate
21887c478bd9Sstevel@tonic-gate if (pdulen < sizeof (struct rde_pdu))
21897c478bd9Sstevel@tonic-gate return; /* Bad incoming PDU */
21907c478bd9Sstevel@tonic-gate
21917c478bd9Sstevel@tonic-gate if (pdu->rde_ptype == RDE_RQC)
21927c478bd9Sstevel@tonic-gate return; /* ignore RQC */
21937c478bd9Sstevel@tonic-gate
21947c478bd9Sstevel@tonic-gate if (pdu->rde_ptype != RDE_RQR && pdu->rde_ptype != RDE_RS) {
21957c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
21967c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
21977c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "gld: bogus RDE ptype 0x%x received",
21987c478bd9Sstevel@tonic-gate pdu->rde_ptype);
21997c478bd9Sstevel@tonic-gate #endif
22007c478bd9Sstevel@tonic-gate return;
22017c478bd9Sstevel@tonic-gate }
22027c478bd9Sstevel@tonic-gate
22037c478bd9Sstevel@tonic-gate if (rh == NULL) {
22047c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
22057c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
22067c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
22077c478bd9Sstevel@tonic-gate "gld: bogus NULL RIF, ptype 0x%x received",
22087c478bd9Sstevel@tonic-gate pdu->rde_ptype);
22097c478bd9Sstevel@tonic-gate #endif
22107c478bd9Sstevel@tonic-gate return;
22117c478bd9Sstevel@tonic-gate }
22127c478bd9Sstevel@tonic-gate
22137c478bd9Sstevel@tonic-gate ASSERT(rh->len >= 2);
22147c478bd9Sstevel@tonic-gate ASSERT(rh->len <= sizeof (struct gld_ri));
22157c478bd9Sstevel@tonic-gate ASSERT((rh->len & 1) == 0);
22167c478bd9Sstevel@tonic-gate
22177c478bd9Sstevel@tonic-gate if (pdu->rde_ptype == RDE_RQR) {
221848bbca81SDaniel Hoffman /* A reply to our RQC has its address as target mac */
22197c478bd9Sstevel@tonic-gate otherhost = pdu->rde_target_mac;
22207c478bd9Sstevel@tonic-gate } else {
22217c478bd9Sstevel@tonic-gate ASSERT(pdu->rde_ptype == RDE_RS);
222248bbca81SDaniel Hoffman /* An RS has its address as orig mac */
22237c478bd9Sstevel@tonic-gate otherhost = pdu->rde_orig_mac;
22247c478bd9Sstevel@tonic-gate }
22257c478bd9Sstevel@tonic-gate
22267c478bd9Sstevel@tonic-gate mutex_enter(GLD_SR_MUTEX(macinfo));
22277c478bd9Sstevel@tonic-gate
22287c478bd9Sstevel@tonic-gate if ((sr = gld_sr_create_entry(macinfo, otherhost)) == NULL) {
22297c478bd9Sstevel@tonic-gate mutex_exit(GLD_SR_MUTEX(macinfo));
22307c478bd9Sstevel@tonic-gate return; /* oh well, out of memory */
22317c478bd9Sstevel@tonic-gate }
22327c478bd9Sstevel@tonic-gate
22337c478bd9Sstevel@tonic-gate if (pdu->rde_ptype == RDE_RQR) {
22347c478bd9Sstevel@tonic-gate /* see if new route is better than what we may already have */
22357c478bd9Sstevel@tonic-gate if (sr->sr_ri.len != 0 &&
22367c478bd9Sstevel@tonic-gate sr->sr_ri.len <= rh->len) {
22377c478bd9Sstevel@tonic-gate mutex_exit(GLD_SR_MUTEX(macinfo));
22387c478bd9Sstevel@tonic-gate return; /* we have one, and new one is no shorter */
22397c478bd9Sstevel@tonic-gate }
22407c478bd9Sstevel@tonic-gate }
22417c478bd9Sstevel@tonic-gate
22427c478bd9Sstevel@tonic-gate /* adopt the new route */
22437c478bd9Sstevel@tonic-gate bcopy((caddr_t)rh, (caddr_t)&sr->sr_ri, rh->len); /* copy incom RIF */
22447c478bd9Sstevel@tonic-gate sr->sr_ri.rt = RT_SRF; /* make it a clean SRF */
22457c478bd9Sstevel@tonic-gate sr->sr_ri.dir ^= 1; /* reverse direction */
22467c478bd9Sstevel@tonic-gate sr->sr_timer = ddi_get_lbolt();
22477c478bd9Sstevel@tonic-gate
22487c478bd9Sstevel@tonic-gate mutex_exit(GLD_SR_MUTEX(macinfo));
22497c478bd9Sstevel@tonic-gate }
22507c478bd9Sstevel@tonic-gate
22517c478bd9Sstevel@tonic-gate /*
22527c478bd9Sstevel@tonic-gate * This routine is called when a packet with a RIF is received. Our
22537c478bd9Sstevel@tonic-gate * policy is to adopt the route.
22547c478bd9Sstevel@tonic-gate */
22557c478bd9Sstevel@tonic-gate /* ARGSUSED3 */
22567c478bd9Sstevel@tonic-gate static void
gld_rif_ind(gld_mac_info_t * macinfo,struct gld_ri * rh,uchar_t * shost,uchar_t ssap,uchar_t dsap)22577c478bd9Sstevel@tonic-gate gld_rif_ind(gld_mac_info_t *macinfo, struct gld_ri *rh, uchar_t *shost,
22587c478bd9Sstevel@tonic-gate uchar_t ssap, uchar_t dsap)
22597c478bd9Sstevel@tonic-gate {
22607c478bd9Sstevel@tonic-gate struct srtab *sr;
22617c478bd9Sstevel@tonic-gate
22627c478bd9Sstevel@tonic-gate ASSERT(rh != NULL); /* ensure RIF */
22637c478bd9Sstevel@tonic-gate ASSERT((rh->rt & 0x04) == 0); /* ensure SRF */
22647c478bd9Sstevel@tonic-gate ASSERT(rh->len >= 2);
22657c478bd9Sstevel@tonic-gate ASSERT(rh->len <= sizeof (struct gld_ri));
22667c478bd9Sstevel@tonic-gate ASSERT((rh->len & 1) == 0);
22677c478bd9Sstevel@tonic-gate
22687c478bd9Sstevel@tonic-gate mutex_enter(GLD_SR_MUTEX(macinfo));
22697c478bd9Sstevel@tonic-gate
22707c478bd9Sstevel@tonic-gate if ((sr = gld_sr_create_entry(macinfo, shost)) == NULL) {
22717c478bd9Sstevel@tonic-gate mutex_exit(GLD_SR_MUTEX(macinfo));
22727c478bd9Sstevel@tonic-gate return; /* oh well, out of memory */
22737c478bd9Sstevel@tonic-gate }
22747c478bd9Sstevel@tonic-gate
22757c478bd9Sstevel@tonic-gate /* we have an entry; fill it in */
22767c478bd9Sstevel@tonic-gate bcopy((caddr_t)rh, (caddr_t)&sr->sr_ri, rh->len); /* copy incom RIF */
22777c478bd9Sstevel@tonic-gate sr->sr_ri.rt = RT_SRF; /* make it a clean SRF */
22787c478bd9Sstevel@tonic-gate sr->sr_ri.dir ^= 1; /* reverse direction */
22797c478bd9Sstevel@tonic-gate sr->sr_timer = ddi_get_lbolt();
22807c478bd9Sstevel@tonic-gate
22817c478bd9Sstevel@tonic-gate mutex_exit(GLD_SR_MUTEX(macinfo));
22827c478bd9Sstevel@tonic-gate }
22837c478bd9Sstevel@tonic-gate
22847c478bd9Sstevel@tonic-gate static struct srtab **
gld_sr_hash(struct srtab ** sr_hash_tbl,uchar_t * addr,int addr_length)22857c478bd9Sstevel@tonic-gate gld_sr_hash(struct srtab **sr_hash_tbl, uchar_t *addr, int addr_length)
22867c478bd9Sstevel@tonic-gate {
22877c478bd9Sstevel@tonic-gate uint_t hashval = 0;
22887c478bd9Sstevel@tonic-gate
22897c478bd9Sstevel@tonic-gate while (--addr_length >= 0)
22907c478bd9Sstevel@tonic-gate hashval ^= *addr++;
22917c478bd9Sstevel@tonic-gate
22927c478bd9Sstevel@tonic-gate return (&sr_hash_tbl[hashval % SR_HASH_SIZE]);
22937c478bd9Sstevel@tonic-gate }
22947c478bd9Sstevel@tonic-gate
22957c478bd9Sstevel@tonic-gate static struct srtab *
gld_sr_lookup_entry(gld_mac_info_t * macinfo,uchar_t * macaddr)22967c478bd9Sstevel@tonic-gate gld_sr_lookup_entry(gld_mac_info_t *macinfo, uchar_t *macaddr)
22977c478bd9Sstevel@tonic-gate {
22987c478bd9Sstevel@tonic-gate struct srtab *sr;
22997c478bd9Sstevel@tonic-gate
23007c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo)));
23017c478bd9Sstevel@tonic-gate
23027c478bd9Sstevel@tonic-gate for (sr = *gld_sr_hash(GLD_SR_HASH(macinfo), macaddr,
23037c478bd9Sstevel@tonic-gate macinfo->gldm_addrlen); sr; sr = sr->sr_next)
23047c478bd9Sstevel@tonic-gate if (mac_eq(macaddr, sr->sr_mac, macinfo->gldm_addrlen))
23057c478bd9Sstevel@tonic-gate return (sr);
23067c478bd9Sstevel@tonic-gate
23077c478bd9Sstevel@tonic-gate return ((struct srtab *)0);
23087c478bd9Sstevel@tonic-gate }
23097c478bd9Sstevel@tonic-gate
23107c478bd9Sstevel@tonic-gate static struct srtab *
gld_sr_create_entry(gld_mac_info_t * macinfo,uchar_t * macaddr)23117c478bd9Sstevel@tonic-gate gld_sr_create_entry(gld_mac_info_t *macinfo, uchar_t *macaddr)
23127c478bd9Sstevel@tonic-gate {
23137c478bd9Sstevel@tonic-gate struct srtab *sr;
23147c478bd9Sstevel@tonic-gate struct srtab **srp;
23157c478bd9Sstevel@tonic-gate
23167c478bd9Sstevel@tonic-gate ASSERT(!(macaddr[0] & 0x80)); /* no group addresses here */
23177c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo)));
23187c478bd9Sstevel@tonic-gate
23197c478bd9Sstevel@tonic-gate srp = gld_sr_hash(GLD_SR_HASH(macinfo), macaddr, macinfo->gldm_addrlen);
23207c478bd9Sstevel@tonic-gate
23217c478bd9Sstevel@tonic-gate for (sr = *srp; sr; sr = sr->sr_next)
23227c478bd9Sstevel@tonic-gate if (mac_eq(macaddr, sr->sr_mac, macinfo->gldm_addrlen))
23237c478bd9Sstevel@tonic-gate return (sr);
23247c478bd9Sstevel@tonic-gate
23257c478bd9Sstevel@tonic-gate if (!(sr = kmem_zalloc(sizeof (struct srtab), KM_NOSLEEP))) {
23267c478bd9Sstevel@tonic-gate #ifdef GLD_DEBUG
23277c478bd9Sstevel@tonic-gate if (gld_debug & GLDERRS)
23287c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
23297c478bd9Sstevel@tonic-gate "gld: gld_sr_create_entry kmem_alloc failed");
23307c478bd9Sstevel@tonic-gate #endif
23317c478bd9Sstevel@tonic-gate return ((struct srtab *)0);
23327c478bd9Sstevel@tonic-gate }
23337c478bd9Sstevel@tonic-gate
23347c478bd9Sstevel@tonic-gate bcopy((caddr_t)macaddr, (caddr_t)sr->sr_mac, macinfo->gldm_addrlen);
23357c478bd9Sstevel@tonic-gate
23367c478bd9Sstevel@tonic-gate sr->sr_next = *srp;
23377c478bd9Sstevel@tonic-gate *srp = sr;
23387c478bd9Sstevel@tonic-gate return (sr);
23397c478bd9Sstevel@tonic-gate }
23407c478bd9Sstevel@tonic-gate
23417c478bd9Sstevel@tonic-gate static void
gld_sr_clear(gld_mac_info_t * macinfo)23427c478bd9Sstevel@tonic-gate gld_sr_clear(gld_mac_info_t *macinfo)
23437c478bd9Sstevel@tonic-gate {
23447c478bd9Sstevel@tonic-gate int i;
23457c478bd9Sstevel@tonic-gate struct srtab **sr_hash_tbl = GLD_SR_HASH(macinfo);
23467c478bd9Sstevel@tonic-gate struct srtab **srp, *sr;
23477c478bd9Sstevel@tonic-gate
23487c478bd9Sstevel@tonic-gate /*
23497c478bd9Sstevel@tonic-gate * Walk through the table, deleting all entries.
23507c478bd9Sstevel@tonic-gate *
23517c478bd9Sstevel@tonic-gate * Only called from uninit, so don't need the mutex.
23527c478bd9Sstevel@tonic-gate */
23537c478bd9Sstevel@tonic-gate for (i = 0; i < SR_HASH_SIZE; i++) {
23547c478bd9Sstevel@tonic-gate for (srp = &sr_hash_tbl[i]; (sr = *srp) != NULL; ) {
23557c478bd9Sstevel@tonic-gate *srp = sr->sr_next;
23567c478bd9Sstevel@tonic-gate kmem_free((char *)sr, sizeof (struct srtab));
23577c478bd9Sstevel@tonic-gate }
23587c478bd9Sstevel@tonic-gate }
23597c478bd9Sstevel@tonic-gate }
23607c478bd9Sstevel@tonic-gate
23617c478bd9Sstevel@tonic-gate #ifdef DEBUG
23627c478bd9Sstevel@tonic-gate void
gld_sr_dump(gld_mac_info_t * macinfo)23637c478bd9Sstevel@tonic-gate gld_sr_dump(gld_mac_info_t *macinfo)
23647c478bd9Sstevel@tonic-gate {
23657c478bd9Sstevel@tonic-gate int i, j;
23667c478bd9Sstevel@tonic-gate struct srtab **sr_hash_tbl;
23677c478bd9Sstevel@tonic-gate struct srtab *sr;
23687c478bd9Sstevel@tonic-gate
23697c478bd9Sstevel@tonic-gate sr_hash_tbl = GLD_SR_HASH(macinfo);
23707c478bd9Sstevel@tonic-gate if (sr_hash_tbl == NULL)
23717c478bd9Sstevel@tonic-gate return;
23727c478bd9Sstevel@tonic-gate
23737c478bd9Sstevel@tonic-gate mutex_enter(GLD_SR_MUTEX(macinfo));
23747c478bd9Sstevel@tonic-gate
23757c478bd9Sstevel@tonic-gate /*
23767c478bd9Sstevel@tonic-gate * Walk through the table, printing all entries
23777c478bd9Sstevel@tonic-gate */
23787c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "GLD Source Routing Table (0x%p):", (void *)macinfo);
23797c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "Addr len,rt,dir,mtu,res rng,brg0 rng,brg1...\n");
23807c478bd9Sstevel@tonic-gate for (i = 0; i < SR_HASH_SIZE; i++) {
23817c478bd9Sstevel@tonic-gate for (sr = sr_hash_tbl[i]; sr; sr = sr->sr_next) {
23827c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
23837c478bd9Sstevel@tonic-gate "%x:%x:%x:%x:%x:%x %d,%x,%x,%x,%x ",
23847c478bd9Sstevel@tonic-gate sr->sr_mac[0], sr->sr_mac[1], sr->sr_mac[2],
23857c478bd9Sstevel@tonic-gate sr->sr_mac[3], sr->sr_mac[4], sr->sr_mac[5],
23867c478bd9Sstevel@tonic-gate sr->sr_ri.len, sr->sr_ri.rt, sr->sr_ri.dir,
23877c478bd9Sstevel@tonic-gate sr->sr_ri.mtu, sr->sr_ri.res);
23887c478bd9Sstevel@tonic-gate if (sr->sr_ri.len)
23897c478bd9Sstevel@tonic-gate for (j = 0; j < (sr->sr_ri.len - 2) / 2; j++)
23907c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%x ",
23917c478bd9Sstevel@tonic-gate REF_NET_USHORT(*(unsigned short *)
23927c478bd9Sstevel@tonic-gate &sr->sr_ri.rd[j]));
23937c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "\n");
23947c478bd9Sstevel@tonic-gate }
23957c478bd9Sstevel@tonic-gate }
23967c478bd9Sstevel@tonic-gate
23977c478bd9Sstevel@tonic-gate mutex_exit(GLD_SR_MUTEX(macinfo));
23987c478bd9Sstevel@tonic-gate }
23997c478bd9Sstevel@tonic-gate #endif
2400