4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
21 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22 * Use is subject to license terms.
25 #pragma ident "%Z%%M% %I% %E% SMI"
28 * gld - Generic LAN Driver
29 * media dependent routines
32 #include <sys/types.h>
33 #include <sys/errno.h>
34 #include <sys/stropts.h>
35 #include <sys/stream.h>
38 #include <sys/modctl.h>
39 #include <sys/kstat.h>
40 #include <sys/debug.h>
42 #include <sys/byteorder.h>
43 #include <sys/strsun.h>
45 #include <sys/ethernet.h>
46 #include <sys/multidata.h>
48 #include <sys/gldpriv.h>
50 #include <sys/sunddi.h>
51 #include <sys/sysmacros.h>
52 #include <sys/ib/clients/ibd/ibd.h>
53 #include <sys/pattr.h>
55 #define DLSAPLENGTH(macinfo) \
56 ((macinfo)->gldm_addrlen + ABS((macinfo)->gldm_saplen))
62 extern void gld_bitrevcopy(caddr_t src
, caddr_t target
, size_t n
);
63 extern char *gld_macaddr_sprintf(char *, unsigned char *, int);
64 extern gld_vlan_t
*gld_find_vlan(gld_mac_info_t
*, uint32_t);
65 extern uint32_t gld_global_options
;
67 static struct llc_snap_hdr llc_snap_def
= {
68 LSAP_SNAP
, /* DLSAP 0xaa */
69 LSAP_SNAP
, /* SLSAP 0xaa */
70 CNTL_LLC_UI
, /* Control 0x03 */
71 0x00, 0x00, 0x00, /* Org[3] */
75 #define ISETHERTYPE(snaphdr) \
76 (snaphdr->d_lsap == LSAP_SNAP && \
77 snaphdr->s_lsap == LSAP_SNAP && \
78 snaphdr->control == CNTL_LLC_UI && \
79 snaphdr->org[0] == 0 && \
80 snaphdr->org[1] == 0 && \
87 static mac_addr_t ether_broadcast
= {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
90 gld_init_ether(gld_mac_info_t
*macinfo
)
92 struct gldkstats
*sp
=
93 ((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->kstatp
->ks_data
;
95 /* Assumptions we make for this medium */
96 ASSERT(macinfo
->gldm_type
== DL_ETHER
);
97 ASSERT(macinfo
->gldm_addrlen
== 6);
98 ASSERT(macinfo
->gldm_saplen
== -2);
100 ASSERT(sizeof (struct ether_header
) == 14);
101 ASSERT(sizeof (mac_addr_t
) == 6);
104 kstat_named_init(&sp
->glds_frame
, "align_errors", KSTAT_DATA_ULONG
);
105 kstat_named_init(&sp
->glds_crc
, "fcs_errors", KSTAT_DATA_ULONG
);
106 kstat_named_init(&sp
->glds_collisions
, "collisions", KSTAT_DATA_ULONG
);
107 kstat_named_init(&sp
->glds_nocarrier
, "carrier_errors",
109 kstat_named_init(&sp
->glds_defer
, "defer_xmts", KSTAT_DATA_ULONG
);
110 kstat_named_init(&sp
->glds_xmtlatecoll
, "tx_late_collisions",
112 kstat_named_init(&sp
->glds_short
, "runt_errors", KSTAT_DATA_ULONG
);
113 kstat_named_init(&sp
->glds_excoll
, "ex_collisions", KSTAT_DATA_ULONG
);
116 * only initialize the new statistics if the driver
119 if (macinfo
->gldm_driver_version
!= GLD_VERSION_200
)
122 kstat_named_init(&sp
->glds_dot3_first_coll
,
123 "first_collisions", KSTAT_DATA_UINT32
);
124 kstat_named_init(&sp
->glds_dot3_multi_coll
,
125 "multi_collisions", KSTAT_DATA_UINT32
);
126 kstat_named_init(&sp
->glds_dot3_sqe_error
,
127 "sqe_errors", KSTAT_DATA_UINT32
);
128 kstat_named_init(&sp
->glds_dot3_mac_xmt_error
,
129 "macxmt_errors", KSTAT_DATA_UINT32
);
130 kstat_named_init(&sp
->glds_dot3_mac_rcv_error
,
131 "macrcv_errors", KSTAT_DATA_UINT32
);
132 kstat_named_init(&sp
->glds_dot3_frame_too_long
,
133 "toolong_errors", KSTAT_DATA_UINT32
);
134 kstat_named_init(&sp
->glds_duplex
, "duplex", KSTAT_DATA_CHAR
);
139 gld_uninit_ether(gld_mac_info_t
*macinfo
)
144 gld_interpret_ether(gld_mac_info_t
*macinfo
, mblk_t
*mp
, pktinfo_t
*pktinfo
,
147 struct ether_header
*mh
;
148 gld_mac_pvt_t
*mac_pvt
= (gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
;
149 struct llc_snap_hdr
*snaphdr
;
150 mblk_t
*pmp
= NULL
, *savemp
= mp
;
151 unsigned short typelen
;
155 * Quickly handle receive fastpath for IPQ hack.
157 if (flags
== GLD_RXQUICK
) {
158 pktinfo
->pktLen
= msgdsize(mp
);
160 * Check whether the header is contiguous, which
161 * also implicitly makes sure the packet is big enough.
163 if (MBLKL(mp
) < sizeof (struct ether_header
))
165 mh
= (struct ether_header
*)mp
->b_rptr
;
166 pktinfo
->ethertype
= REF_NET_USHORT(mh
->ether_type
);
167 pktinfo
->isForMe
= mac_eq(&mh
->ether_dhost
,
168 mac_pvt
->curr_macaddr
, macinfo
->gldm_addrlen
);
169 pktinfo
->macLen
= sizeof (struct ether_header
);
174 bzero((void *)pktinfo
, sizeof (*pktinfo
));
176 pktinfo
->pktLen
= msgdsize(mp
);
178 /* make sure packet has at least a whole mac header */
179 if (pktinfo
->pktLen
< sizeof (struct ether_header
))
182 /* make sure the mac header falls into contiguous memory */
183 if (MBLKL(mp
) < sizeof (struct ether_header
)) {
184 if ((pmp
= msgpullup(mp
, -1)) == NULL
) {
186 if (gld_debug
& GLDERRS
)
188 "GLD: interpret_ether cannot msgpullup");
192 mp
= pmp
; /* this mblk contains the whole mac header */
195 mh
= (struct ether_header
*)mp
->b_rptr
;
197 /* Check to see if the mac is a broadcast or multicast address. */
198 if (mac_eq(&mh
->ether_dhost
, ether_broadcast
, macinfo
->gldm_addrlen
))
199 pktinfo
->isBroadcast
= 1;
200 else if (mh
->ether_dhost
.ether_addr_octet
[0] & 1)
201 pktinfo
->isMulticast
= 1;
203 typelen
= REF_NET_USHORT(mh
->ether_type
);
205 * If the hardware is capable of VLAN tag insertion
206 * strip out the VLAN tag info. Knowing hardware is
207 * capable of VLAN can be established by the presance
208 * of non null 'macinfo->gldm_send_tagged'.
210 if (flags
== GLD_TX
) {
211 if ((typelen
== ETHERTYPE_VLAN
) &&
212 (macinfo
->gldm_send_tagged
!= NULL
)) {
213 struct ether_vlan_header
*evhp
;
216 if ((MBLKL(mp
) < sizeof (struct ether_vlan_header
)) &&
217 (pullupmsg(mp
, sizeof (struct ether_vlan_header
))
222 evhp
= (struct ether_vlan_header
*)mp
->b_rptr
;
223 tci
= REF_NET_USHORT(evhp
->ether_tci
);
226 * We don't allow the VID and priority are both zero.
228 if ((GLD_VTAG_PRI((int32_t)tci
) == 0 &&
229 GLD_VTAG_VID((int32_t)tci
) == VLAN_VID_NONE
) ||
230 (GLD_VTAG_CFI((uint32_t)tci
)) != VLAN_CFI_ETHER
) {
236 * Remember the VTAG info in order to reinsert it,
237 * Then strip the tag. This is required because some
238 * drivers do not allow the size of message (passed
239 * by the gldm_send_tagged() function) to be greater
242 GLD_SAVE_MBLK_VTAG(savemp
, GLD_TCI2VTAG(tci
));
243 ovbcopy(mp
->b_rptr
, mp
->b_rptr
+ VTAG_SIZE
,
245 mp
->b_rptr
+= VTAG_SIZE
;
247 goto out
; /* Got all info we need for xmit case */
250 ASSERT(GLDM_LOCK_HELD(macinfo
));
253 * Deal with the mac header
256 mac_copy(&mh
->ether_dhost
, pktinfo
->dhost
, macinfo
->gldm_addrlen
);
257 mac_copy(&mh
->ether_shost
, pktinfo
->shost
, macinfo
->gldm_addrlen
);
259 pktinfo
->isLooped
= mac_eq(pktinfo
->shost
,
260 mac_pvt
->curr_macaddr
, macinfo
->gldm_addrlen
);
261 pktinfo
->isForMe
= mac_eq(pktinfo
->dhost
,
262 mac_pvt
->curr_macaddr
, macinfo
->gldm_addrlen
);
264 pktinfo
->macLen
= sizeof (struct ether_header
);
266 if (typelen
> ETHERMTU
) {
267 pktinfo
->ethertype
= typelen
; /* use type interpretation */
272 * Packet is 802.3 so the ether type/length field
273 * specifies the number of bytes that should be present
274 * in the data field. Additional bytes are padding, and
278 int delta
= pktinfo
->pktLen
-
279 (sizeof (struct ether_header
) + typelen
);
281 if (delta
> 0 && adjmsg(mp
, -delta
))
282 pktinfo
->pktLen
-= delta
;
286 * Before trying to look beyond the MAC header, make sure the LLC
287 * header exists, and that both it and any SNAP header are contiguous.
289 if (pktinfo
->pktLen
< pktinfo
->macLen
+ LLC_HDR1_LEN
)
290 goto out
; /* LLC hdr should have been there! */
294 if (gld_global_options
& GLD_OPT_NO_ETHRXSNAP
||
295 pktinfo
->pktLen
< pktinfo
->macLen
+ LLC_SNAP_HDR_LEN
)
298 if (MBLKL(mp
) < sizeof (struct ether_header
) + LLC_SNAP_HDR_LEN
&&
299 MBLKL(mp
) < pktinfo
->pktLen
) {
301 * we don't have the entire packet within the first mblk (and
302 * therefore we didn't do the msgpullup above), AND the first
303 * mblk may not contain all the data we need to look at.
305 ASSERT(pmp
== NULL
); /* couldn't have done msgpullup above */
306 if ((pmp
= msgpullup(mp
, -1)) == NULL
) {
308 if (gld_debug
& GLDERRS
)
310 "GLD: interpret_ether cannot msgpullup2");
312 goto out
; /* can't interpret this pkt further */
314 mp
= pmp
; /* this mblk should contain everything needed */
318 * Check SAP/SNAP information for EtherType.
321 snaphdr
= (struct llc_snap_hdr
*)(mp
->b_rptr
+ pktinfo
->macLen
);
322 if (ISETHERTYPE(snaphdr
)) {
323 pktinfo
->ethertype
= REF_NET_USHORT(snaphdr
->type
);
324 pktinfo
->hdrLen
= LLC_SNAP_HDR_LEN
;
334 gld_unitdata_ether(gld_t
*gld
, mblk_t
*mp
)
336 gld_mac_info_t
*macinfo
= gld
->gld_mac_info
;
337 dl_unitdata_req_t
*dlp
= (dl_unitdata_req_t
*)mp
->b_rptr
;
338 struct gld_dlsap
*gldp
= DLSAP(dlp
, dlp
->dl_dest_addr_offset
);
340 unsigned short typelen
;
342 struct ether_header
*mh
;
345 gld_vlan_t
*gld_vlan
;
349 /* extract needed info from the mblk before we maybe reuse it */
350 mac_copy(gldp
->glda_addr
, dhost
, macinfo
->gldm_addrlen
);
352 /* look in the unitdata request for a sap, else use bound one */
353 if (dlp
->dl_dest_addr_length
>= DLSAPLENGTH(macinfo
) &&
354 REF_HOST_USHORT(gldp
->glda_sap
) != 0)
355 typelen
= REF_HOST_USHORT(gldp
->glda_sap
);
357 typelen
= gld
->gld_sap
;
360 * We take values less than or equal to ETHERMTU to mean that the
361 * packet should not have an encoded EtherType and so we use the
362 * IEEE 802.3 length interpretation of the type/length field.
364 if (typelen
<= ETHERMTU
)
365 typelen
= msgdsize(mp
);
367 hdrlen
= sizeof (struct ether_header
);
370 * Check to see if VLAN is enabled on this stream
371 * if so then make the header bigger to hold a clone
374 gld_vlan
= (gld_vlan_t
*)gld
->gld_vlan
;
375 if (gld_vlan
&& (gld_vlan
->gldv_id
!= VLAN_VID_NONE
)) {
377 vptag
= gld_vlan
->gldv_ptag
;
380 /* need a buffer big enough for the headers */
381 nmp
= mp
->b_cont
; /* where the packet payload M_DATA is */
382 if (DB_REF(nmp
) == 1 && MBLKHEAD(nmp
) >= hdrlen
) {
383 /* it fits at the beginning of the first M_DATA block */
384 freeb(mp
); /* don't need the M_PROTO anymore */
385 } else if (DB_REF(mp
) == 1 && MBLKSIZE(mp
) >= hdrlen
) {
386 /* we can reuse the dl_unitdata_req M_PROTO mblk */
388 DB_TYPE(nmp
) = M_DATA
;
389 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
391 /* we need to allocate one */
392 if ((nmp
= allocb(hdrlen
, BPRI_MED
)) == NULL
)
394 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
395 linkb(nmp
, mp
->b_cont
);
399 /* Got the space, now copy in the header components */
401 nmp
->b_rptr
-= sizeof (typelen
);
402 SET_NET_USHORT(*(uint16_t *)nmp
->b_rptr
, typelen
);
403 if (hdrlen
> sizeof (struct ether_header
)) {
404 nmp
->b_rptr
-= sizeof (uint16_t);
405 SET_NET_USHORT(*(uint16_t *)nmp
->b_rptr
, vptag
);
407 nmp
->b_rptr
-= sizeof (uint16_t);
408 SET_NET_USHORT(*(uint16_t *)nmp
->b_rptr
, vptag
);
410 nmp
->b_rptr
-= (ETHERADDRL
* 2);
411 mh
= (struct ether_header
*)nmp
->b_rptr
;
412 mac_copy(dhost
, &mh
->ether_dhost
, macinfo
->gldm_addrlen
);
415 * We access the mac address without the mutex to prevent
416 * mutex contention (BUG 4211361)
418 mac_copy(((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->curr_macaddr
,
419 &mh
->ether_shost
, macinfo
->gldm_addrlen
);
425 * Insert the VLAN tag into the packet. The packet now is an Ethernet header
426 * without VLAN tag information.
429 gld_insert_vtag_ether(mblk_t
*mp
, uint32_t vtag
)
431 struct ether_vlan_header
*evhp
;
432 struct ether_header
*ehp
;
435 if (vtag
== VLAN_VID_NONE
)
438 if (DB_REF(mp
) == 1 && MBLKHEAD(mp
) >= VTAG_SIZE
) {
439 /* it fits at the beginning of the message block */
441 ovbcopy(nmp
->b_rptr
, nmp
->b_rptr
- VTAG_SIZE
, 2 * ETHERADDRL
);
442 nmp
->b_rptr
-= VTAG_SIZE
;
443 evhp
= (struct ether_vlan_header
*)nmp
->b_rptr
;
445 /* we need to allocate one */
446 if ((nmp
= allocb(sizeof (struct ether_vlan_header
),
447 BPRI_MED
)) == NULL
) {
450 nmp
->b_wptr
+= sizeof (struct ether_vlan_header
);
452 /* transfer the ether_header fields */
453 evhp
= (struct ether_vlan_header
*)nmp
->b_rptr
;
454 ehp
= (struct ether_header
*)mp
->b_rptr
;
455 mac_copy(&ehp
->ether_dhost
, &evhp
->ether_dhost
, ETHERADDRL
);
456 mac_copy(&ehp
->ether_shost
, &evhp
->ether_shost
, ETHERADDRL
);
457 bcopy(&ehp
->ether_type
, &evhp
->ether_type
, sizeof (uint16_t));
459 /* offset the mp of the MAC header length. */
460 mp
->b_rptr
+= sizeof (struct ether_header
);
461 if (MBLKL(mp
) == 0) {
462 nmp
->b_cont
= mp
->b_cont
;
469 SET_NET_USHORT(evhp
->ether_tci
, vtag
);
471 SET_NET_USHORT(evhp
->ether_tpid
, vtag
);
476 gld_fastpath_ether(gld_t
*gld
, mblk_t
*mp
)
478 gld_mac_info_t
*macinfo
= gld
->gld_mac_info
;
479 dl_unitdata_req_t
*dlp
= (dl_unitdata_req_t
*)mp
->b_cont
->b_rptr
;
480 struct gld_dlsap
*gldp
= DLSAP(dlp
, dlp
->dl_dest_addr_offset
);
481 unsigned short typelen
;
483 struct ether_header
*mh
;
486 gld_vlan_t
*gld_vlan
;
490 /* look in the unitdata request for a sap, else use bound one */
491 if (dlp
->dl_dest_addr_length
>= DLSAPLENGTH(macinfo
) &&
492 REF_HOST_USHORT(gldp
->glda_sap
) != 0)
493 typelen
= REF_HOST_USHORT(gldp
->glda_sap
);
495 typelen
= gld
->gld_sap
;
498 * We only do fast-path for EtherType encoding because this is the only
499 * case where the media header will be consistent from packet to packet.
501 if (typelen
<= ETHERMTU
)
505 * Initialize the fast path header to include the
506 * basic source address information and type field.
508 hdrlen
= sizeof (struct ether_header
);
511 * Check to see if VLAN is enabled on this stream
512 * if so then make the header bigger to hold a clone
515 gld_vlan
= (gld_vlan_t
*)gld
->gld_vlan
;
516 if (gld_vlan
&& (gld_vlan
->gldv_id
!= VLAN_VID_NONE
)) {
518 vptag
= gld_vlan
->gldv_ptag
;
521 if ((nmp
= allocb(hdrlen
, BPRI_MED
)) == NULL
)
524 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
526 /* Got the space, now copy in the header components */
528 nmp
->b_rptr
-= sizeof (typelen
);
529 SET_NET_USHORT(*(uint16_t *)nmp
->b_rptr
, typelen
);
532 * If the header is for a VLAN stream, then add
533 * in the VLAN tag to the clone header.
535 if (hdrlen
> sizeof (struct ether_header
)) {
536 nmp
->b_rptr
-= sizeof (uint16_t);
537 SET_NET_USHORT(*(uint16_t *)nmp
->b_rptr
, vptag
);
539 nmp
->b_rptr
-= sizeof (uint16_t);
540 SET_NET_USHORT(*(uint16_t *)nmp
->b_rptr
, vptag
);
542 nmp
->b_rptr
-= (ETHERADDRL
* 2);
543 mh
= (struct ether_header
*)nmp
->b_rptr
;
544 mac_copy(gldp
->glda_addr
, &mh
->ether_dhost
, macinfo
->gldm_addrlen
);
546 GLDM_LOCK(macinfo
, RW_WRITER
);
547 mac_copy(((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->curr_macaddr
,
548 &mh
->ether_shost
, macinfo
->gldm_addrlen
);
549 GLDM_UNLOCK(macinfo
);
559 gld_init_ib(gld_mac_info_t
*macinfo
)
562 * Currently, the generic stats maintained by GLD is
563 * sufficient for IPoIB.
566 /* Assumptions we make for this medium */
567 ASSERT(macinfo
->gldm_type
== DL_IB
);
568 ASSERT(macinfo
->gldm_addrlen
== IPOIB_ADDRL
);
569 ASSERT(macinfo
->gldm_saplen
== -2);
574 gld_uninit_ib(gld_mac_info_t
*macinfo
)
579 * The packet format sent to the driver is:
580 * IPOIB_ADDRL bytes dest addr :: 2b sap :: 2b 0s :: data
581 * The packet format received from the driver is:
582 * IPOIB_GRH_SIZE bytes pseudo GRH :: 2b sap :: 2b 0s :: data.
585 gld_interpret_ib(gld_mac_info_t
*macinfo
, mblk_t
*mp
, pktinfo_t
*pktinfo
,
589 ipoib_ptxhdr_t
*gldp
;
591 gld_mac_pvt_t
*mac_pvt
= (gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
;
594 * Quickly handle receive fastpath for IPQ hack.
596 if (flags
== GLD_RXQUICK
) {
597 pktinfo
->pktLen
= msgdsize(mp
) - IPOIB_GRH_SIZE
;
600 * Check whether the header is contiguous, which
601 * also implicitly makes sure the packet is big enough.
603 if (MBLKL(mp
) < (IPOIB_GRH_SIZE
+ IPOIB_HDRSIZE
))
607 * Almost all times, unicast will not have
608 * a valid pgrh; quickly identify and ask for
609 * IPQ hack optimization only in that case.
611 grh
= (ipoib_pgrh_t
*)mp
->b_rptr
;
612 if (grh
->ipoib_vertcflow
== 0) {
613 struct ipoib_header
*ihp
= (struct ipoib_header
*)
614 (mp
->b_rptr
+ IPOIB_GRH_SIZE
);
616 pktinfo
->isForMe
= 1;
617 pktinfo
->ethertype
= REF_NET_USHORT(ihp
->ipoib_type
);
618 pktinfo
->macLen
= IPOIB_GRH_SIZE
+ IPOIB_HDRSIZE
;
626 * Handle the GLD_TX, GLD_RX, GLD_RXLOOP cases now.
628 ASSERT(flags
!= GLD_RXQUICK
);
629 bzero((void *)pktinfo
, sizeof (*pktinfo
));
631 if (flags
!= GLD_RX
) {
633 * GLD_TX and GLD_RXLOOP cases.
635 gldp
= (ipoib_ptxhdr_t
*)mp
->b_rptr
;
636 pktinfo
->pktLen
= msgdsize(mp
);
638 /* make sure packet has at least a pseudo header */
639 if (pktinfo
->pktLen
< sizeof (ipoib_ptxhdr_t
))
642 /* make sure the mac header falls into contiguous memory */
643 if (MBLKL(mp
) < sizeof (ipoib_ptxhdr_t
)) {
644 if ((pmp
= msgpullup(mp
, -1)) == NULL
) {
646 if (gld_debug
& GLDERRS
)
653 /* this mblk contains the whole mac header */
658 * Check if mac is broadcast or multicast address; all these
659 * types of address have the top 4 bytes as 0x00FFFFFF.
661 if (mac_eq(&gldp
->ipoib_dest
, macinfo
->gldm_broadcast_addr
,
662 sizeof (uint32_t))) {
663 if (mac_eq(&gldp
->ipoib_dest
,
664 macinfo
->gldm_broadcast_addr
, IPOIB_ADDRL
))
665 pktinfo
->isBroadcast
= 1;
667 pktinfo
->isMulticast
= 1;
671 * Only count bytes we will be sending over the wire
674 pktinfo
->pktLen
-= IPOIB_ADDRL
;
676 goto out
; /* Got all info we need for xmit case */
679 * Loopback case: this is a dup'ed message.
681 mp
->b_rptr
+= IPOIB_ADDRL
;
682 mac_copy(&gldp
->ipoib_dest
, pktinfo
->dhost
, IPOIB_ADDRL
);
683 mac_copy(mac_pvt
->curr_macaddr
, pktinfo
->shost
, IPOIB_ADDRL
);
686 * GLD_RX case; process packet sent from driver.
688 ipoib_mac_t
*mact
, *tact
;
691 pktinfo
->pktLen
= msgdsize(mp
);
692 /* make sure packet has at least pgrh and mac header */
693 if (pktinfo
->pktLen
< (IPOIB_GRH_SIZE
+ IPOIB_HDRSIZE
))
696 /* make sure the header falls into contiguous memory */
697 if (MBLKL(mp
) < (IPOIB_GRH_SIZE
+ IPOIB_HDRSIZE
)) {
698 if ((pmp
= msgpullup(mp
, -1)) == NULL
) {
700 if (gld_debug
& GLDERRS
)
703 "cannot msgpullup2");
707 /* this mblk contains the whole mac header */
711 grh
= (ipoib_pgrh_t
*)mp
->b_rptr
;
712 mp
->b_rptr
+= IPOIB_GRH_SIZE
;
713 pktinfo
->pktLen
-= IPOIB_GRH_SIZE
;
714 if (grh
->ipoib_vertcflow
) {
716 * First, copy source address from grh.
718 mact
= (ipoib_mac_t
*)pktinfo
->shost
;
719 mac_copy(&grh
->ipoib_sqpn
, &mact
->ipoib_qpn
,
723 * Then copy destination address from grh;
724 * first, the 16 bytes of GID.
726 mact
= (ipoib_mac_t
*)pktinfo
->dhost
;
727 mac_copy(&grh
->ipoib_dgid_pref
,
728 &mact
->ipoib_gidpref
, IPOIB_ADDRL
-
729 sizeof (mact
->ipoib_qpn
));
730 tact
= (ipoib_mac_t
*)mac_pvt
->curr_macaddr
;
732 /* Is this a multicast address */
733 if (*(uchar_t
*)(grh
->ipoib_dgid_pref
) == 0xFF) {
735 * Only check for hardware looping in
736 * multicast case. It is assumed higher
737 * layer code (IP) will stop unicast loops;
738 * ie will prevent a transmit to self.
740 if (bcmp(&grh
->ipoib_sqpn
, tact
,
742 pktinfo
->isLooped
= 1;
744 tact
= (ipoib_mac_t
*)macinfo
->
746 if (mac_eq(tact
->ipoib_gidpref
,
747 grh
->ipoib_dgid_pref
,
748 IPOIB_ADDRL
- sizeof (tact
->ipoib_qpn
)))
749 pktinfo
->isBroadcast
= 1;
751 pktinfo
->isMulticast
= 1;
753 * Now copy the 4 bytes QPN part of the
754 * destination address.
756 dqpn
= htonl(IB_MC_QPN
);
757 mac_copy(&dqpn
, &mact
->ipoib_qpn
,
758 sizeof (mact
->ipoib_qpn
));
761 * Now copy the 4 bytes QPN part of the
762 * destination address.
764 mac_copy(&tact
->ipoib_qpn
, &mact
->ipoib_qpn
,
765 sizeof (mact
->ipoib_qpn
));
767 * Any unicast packets received on IBA are
770 pktinfo
->isForMe
= 1;
774 * It can not be a IBA multicast packet.
775 * Must have been unicast to us. We do not
776 * have shost information, which is used in
777 * gld_addudind(); IP/ARP does not care.
779 pktinfo
->nosource
= 1;
780 mac_copy(mac_pvt
->curr_macaddr
, pktinfo
->dhost
,
783 * Any unicast packets received on IBA are
786 pktinfo
->isForMe
= 1;
790 ASSERT((flags
== GLD_RX
) || (flags
== GLD_RXLOOP
));
791 ASSERT(GLDM_LOCK_HELD(macinfo
));
792 pktinfo
->ethertype
= REF_NET_USHORT(((ipoib_hdr_t
*)
793 (mp
->b_rptr
))->ipoib_type
);
794 pktinfo
->macLen
= IPOIB_HDRSIZE
;
804 * The packet format sent to the driver is: 2b sap :: 2b 0s :: data
807 gld_interpret_mdt_ib(gld_mac_info_t
*macinfo
, mblk_t
*mp
, pdescinfo_t
*pinfo
,
808 pktinfo_t
*pktinfo
, mdt_packet_flag_t flags
)
810 gld_mac_pvt_t
*mac_pvt
;
812 pattrinfo_t attr_info
= { PATTR_DSTADDRSAP
, };
814 ipoib_ptxhdr_t
*dlap
= NULL
;
817 * Per packet formatting.
819 if (flags
== GLD_MDT_TXPKT
) {
823 if (PDESC_HDRL(pinfo
) == 0)
827 * Update packet's link header.
829 pinfo
->hdr_rptr
-= IPOIB_HDRSIZE
;
830 hptr
= (ipoib_hdr_t
*)pinfo
->hdr_rptr
;
831 hptr
->ipoib_mbz
= htons(0);
832 hptr
->ipoib_type
= pktinfo
->ethertype
;
835 * Total #bytes that will be put on wire.
837 pktinfo
->pktLen
= PDESC_HDRL(pinfo
);
838 for (seg
= 0; seg
< pinfo
->pld_cnt
; seg
++)
839 pktinfo
->pktLen
+= PDESC_PLDL(pinfo
, seg
);
845 * The following two cases of GLD_MDT_TX and GLD_MDT_RXLOOP are per
846 * MDT message processing.
848 dlmdp
= mmd_getmultidata(mp
);
849 patr
= mmd_getpattr(dlmdp
, NULL
, &attr_info
);
850 ASSERT(patr
!= NULL
);
851 ASSERT(macinfo
->gldm_saplen
== -2);
853 dlap
= (ipoib_ptxhdr_t
*)((pattr_addr_t
*)attr_info
.buf
)->addr
;
855 if (flags
== GLD_MDT_TX
) {
856 bzero((void *)pktinfo
, sizeof (*pktinfo
));
861 * Check if mac is broadcast or multicast address; all these
862 * types of address have the top 4 bytes as 0x00FFFFFF.
864 if (mac_eq(dlap
, macinfo
->gldm_broadcast_addr
,
865 sizeof (uint32_t))) {
866 if (mac_eq(dlap
, macinfo
->gldm_broadcast_addr
,
868 pktinfo
->isBroadcast
= 1;
870 pktinfo
->isMulticast
= 1;
872 pktinfo
->ethertype
= REF_NET_USHORT(dlap
->
873 ipoib_rhdr
.ipoib_type
);
875 ASSERT(flags
== GLD_MDT_RXLOOP
);
876 pktinfo
->macLen
= IPOIB_HDRSIZE
;
877 mac_pvt
= (gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
;
878 mac_copy(mac_pvt
->curr_macaddr
, pktinfo
->shost
, IPOIB_ADDRL
);
881 mac_copy(&dlap
->ipoib_dest
, pktinfo
->dhost
, IPOIB_ADDRL
);
886 gld_unitdata_ib(gld_t
*gld
, mblk_t
*mp
)
888 gld_mac_info_t
*macinfo
= gld
->gld_mac_info
;
889 dl_unitdata_req_t
*dlp
= (dl_unitdata_req_t
*)mp
->b_rptr
;
890 ipoib_ptxhdr_t
*gldp
= IPOIBDLSAP(dlp
, dlp
->dl_dest_addr_offset
);
896 ASSERT(macinfo
!= NULL
);
898 /* extract needed info from the mblk before we maybe reuse it */
899 mac_copy(&gldp
->ipoib_dest
, &dhost
, IPOIB_ADDRL
);
901 /* look in the unitdata request for a sap, else use bound one */
902 if (dlp
->dl_dest_addr_length
>= DLSAPLENGTH(macinfo
) &&
903 REF_HOST_USHORT(gldp
->ipoib_rhdr
.ipoib_type
) != 0)
904 type
= REF_HOST_USHORT(gldp
->ipoib_rhdr
.ipoib_type
);
908 hdrlen
= sizeof (ipoib_ptxhdr_t
);
910 /* need a buffer big enough for the headers */
911 nmp
= mp
->b_cont
; /* where the packet payload M_DATA is */
912 if (DB_REF(nmp
) == 1 && MBLKHEAD(nmp
) >= hdrlen
) {
913 /* it fits at the beginning of the first M_DATA block */
914 freeb(mp
); /* don't need the M_PROTO anymore */
915 } else if (DB_REF(mp
) == 1 && MBLKSIZE(mp
) >= hdrlen
) {
916 /* we can reuse the dl_unitdata_req M_PROTO mblk */
918 DB_TYPE(nmp
) = M_DATA
;
919 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
921 /* we need to allocate one */
922 if ((nmp
= allocb(hdrlen
, BPRI_MED
)) == NULL
)
924 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
925 linkb(nmp
, mp
->b_cont
);
929 /* Got the space, now copy in the header components */
931 nmp
->b_rptr
-= sizeof (ipoib_ptxhdr_t
);
932 gldp
= (ipoib_ptxhdr_t
*)nmp
->b_rptr
;
933 SET_NET_USHORT(gldp
->ipoib_rhdr
.ipoib_type
, type
);
934 gldp
->ipoib_rhdr
.ipoib_mbz
= 0;
935 mac_copy(&dhost
, &gldp
->ipoib_dest
, IPOIB_ADDRL
);
941 gld_fastpath_ib(gld_t
*gld
, mblk_t
*mp
)
943 gld_mac_info_t
*macinfo
= gld
->gld_mac_info
;
944 dl_unitdata_req_t
*dlp
= (dl_unitdata_req_t
*)mp
->b_cont
->b_rptr
;
945 ipoib_ptxhdr_t
*gldp
= IPOIBDLSAP(dlp
, dlp
->dl_dest_addr_offset
);
948 ipoib_ptxhdr_t
*tgldp
;
951 ASSERT(macinfo
!= NULL
);
953 /* look in the unitdata request for a sap, else use bound one */
954 if (dlp
->dl_dest_addr_length
>= DLSAPLENGTH(macinfo
) &&
955 REF_HOST_USHORT(gldp
->ipoib_rhdr
.ipoib_type
) != 0)
956 type
= REF_HOST_USHORT(gldp
->ipoib_rhdr
.ipoib_type
);
960 hdrlen
= sizeof (ipoib_ptxhdr_t
);
962 if ((nmp
= allocb(hdrlen
, BPRI_MED
)) == NULL
)
965 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
967 /* Got the space, now copy in the header components */
969 nmp
->b_rptr
-= sizeof (ipoib_ptxhdr_t
);
970 tgldp
= (ipoib_ptxhdr_t
*)nmp
->b_rptr
;
971 tgldp
->ipoib_rhdr
.ipoib_type
= htons(type
);
972 tgldp
->ipoib_rhdr
.ipoib_mbz
= 0;
973 mac_copy(&gldp
->ipoib_dest
, &tgldp
->ipoib_dest
, IPOIB_ADDRL
);
983 gld_init_fddi(gld_mac_info_t
*macinfo
)
985 struct gldkstats
*sp
=
986 ((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->kstatp
->ks_data
;
988 /* Assumptions we make for this medium */
989 ASSERT(macinfo
->gldm_type
== DL_FDDI
);
990 ASSERT(macinfo
->gldm_addrlen
== 6);
991 ASSERT(macinfo
->gldm_saplen
== -2);
993 ASSERT(sizeof (struct fddi_mac_frm
) == 13);
994 ASSERT(sizeof (mac_addr_t
) == 6);
997 /* Wire address format is bit reversed from canonical format */
998 macinfo
->gldm_options
|= GLDOPT_CANONICAL_ADDR
;
1000 kstat_named_init(&sp
->glds_fddi_mac_error
,
1001 "mac_errors", KSTAT_DATA_UINT32
);
1002 kstat_named_init(&sp
->glds_fddi_mac_lost
,
1003 "mac_lost_errors", KSTAT_DATA_UINT32
);
1004 kstat_named_init(&sp
->glds_fddi_mac_token
,
1005 "mac_tokens", KSTAT_DATA_UINT32
);
1006 kstat_named_init(&sp
->glds_fddi_mac_tvx_expired
,
1007 "mac_tvx_expired", KSTAT_DATA_UINT32
);
1008 kstat_named_init(&sp
->glds_fddi_mac_late
,
1009 "mac_late", KSTAT_DATA_UINT32
);
1010 kstat_named_init(&sp
->glds_fddi_mac_ring_op
,
1011 "mac_ring_ops", KSTAT_DATA_UINT32
);
1016 gld_uninit_fddi(gld_mac_info_t
*macinfo
)
1021 gld_interpret_fddi(gld_mac_info_t
*macinfo
, mblk_t
*mp
, pktinfo_t
*pktinfo
,
1022 packet_flag_t flags
)
1024 struct fddi_mac_frm
*mh
;
1025 gld_mac_pvt_t
*mac_pvt
;
1026 struct llc_snap_hdr
*snaphdr
;
1030 * Quickly handle receive fastpath; FDDI does not support IPQ hack.
1032 if (flags
== GLD_RXQUICK
) {
1033 pktinfo
->pktLen
= msgdsize(mp
);
1037 bzero((void *)pktinfo
, sizeof (*pktinfo
));
1039 pktinfo
->pktLen
= msgdsize(mp
);
1041 /* make sure packet has at least a whole mac header */
1042 if (pktinfo
->pktLen
< sizeof (struct fddi_mac_frm
))
1045 /* make sure the mac header falls into contiguous memory */
1046 if (MBLKL(mp
) < sizeof (struct fddi_mac_frm
)) {
1047 if ((pmp
= msgpullup(mp
, -1)) == NULL
) {
1049 if (gld_debug
& GLDERRS
)
1051 "GLD: interpret_fddi cannot msgpullup");
1055 mp
= pmp
; /* this mblk contains the whole mac header */
1058 mh
= (struct fddi_mac_frm
*)mp
->b_rptr
;
1060 /* Check to see if the mac is a broadcast or multicast address. */
1061 /* NB we are still in wire format (non canonical) */
1062 /* mac_eq works because ether_broadcast is the same either way */
1063 if (mac_eq(mh
->fddi_dhost
, ether_broadcast
, macinfo
->gldm_addrlen
))
1064 pktinfo
->isBroadcast
= 1;
1065 else if (mh
->fddi_dhost
[0] & 0x80)
1066 pktinfo
->isMulticast
= 1;
1068 if (flags
== GLD_TX
)
1069 goto out
; /* Got all info we need for xmit case */
1071 ASSERT(GLDM_LOCK_HELD(macinfo
));
1074 * Deal with the mac header
1077 cmac_copy(mh
->fddi_dhost
, pktinfo
->dhost
,
1078 macinfo
->gldm_addrlen
, macinfo
);
1079 cmac_copy(mh
->fddi_shost
, pktinfo
->shost
,
1080 macinfo
->gldm_addrlen
, macinfo
);
1082 mac_pvt
= (gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
;
1083 pktinfo
->isLooped
= mac_eq(pktinfo
->shost
,
1084 mac_pvt
->curr_macaddr
, macinfo
->gldm_addrlen
);
1085 pktinfo
->isForMe
= mac_eq(pktinfo
->dhost
,
1086 mac_pvt
->curr_macaddr
, macinfo
->gldm_addrlen
);
1088 pktinfo
->macLen
= sizeof (struct fddi_mac_frm
);
1091 * Before trying to look beyond the MAC header, make sure the LLC
1092 * header exists, and that both it and any SNAP header are contiguous.
1094 if (MBLKL(mp
) < sizeof (struct fddi_mac_frm
) + LLC_SNAP_HDR_LEN
&&
1095 MBLKL(mp
) < pktinfo
->pktLen
) {
1097 * we don't have the entire packet within the first mblk (and
1098 * therefore we didn't do the msgpullup above), AND the first
1099 * mblk may not contain all the data we need to look at.
1101 ASSERT(pmp
== NULL
); /* couldn't have done msgpullup above */
1102 if ((pmp
= msgpullup(mp
, -1)) == NULL
) {
1104 if (gld_debug
& GLDERRS
)
1106 "GLD: interpret_fddi cannot msgpullup2");
1108 goto out
; /* can't interpret this pkt further */
1110 mp
= pmp
; /* this mblk should contain everything needed */
1114 * Check SAP/SNAP information.
1116 if ((mh
->fddi_fc
& 0x70) == 0x50) {
1117 if (pktinfo
->pktLen
< pktinfo
->macLen
+ LLC_HDR1_LEN
)
1122 if (pktinfo
->pktLen
< pktinfo
->macLen
+ LLC_SNAP_HDR_LEN
)
1125 snaphdr
= (struct llc_snap_hdr
*)(mp
->b_rptr
+ pktinfo
->macLen
);
1126 if (ISETHERTYPE(snaphdr
)) {
1127 pktinfo
->ethertype
= REF_NET_USHORT(snaphdr
->type
);
1128 pktinfo
->hdrLen
= LLC_SNAP_HDR_LEN
;
1139 gld_unitdata_fddi(gld_t
*gld
, mblk_t
*mp
)
1141 gld_mac_info_t
*macinfo
= gld
->gld_mac_info
;
1142 dl_unitdata_req_t
*dlp
= (dl_unitdata_req_t
*)mp
->b_rptr
;
1143 struct gld_dlsap
*gldp
= DLSAP(dlp
, dlp
->dl_dest_addr_offset
);
1145 unsigned short type
;
1147 struct fddi_mac_frm
*mh
;
1152 /* extract needed info from the mblk before we maybe reuse it */
1153 mac_copy(gldp
->glda_addr
, dhost
, macinfo
->gldm_addrlen
);
1155 /* look in the unitdata request for a sap, else use bound one */
1156 if (dlp
->dl_dest_addr_length
>= DLSAPLENGTH(macinfo
) &&
1157 REF_HOST_USHORT(gldp
->glda_sap
) != 0)
1158 type
= REF_HOST_USHORT(gldp
->glda_sap
);
1160 type
= gld
->gld_sap
;
1163 hdrlen
= sizeof (struct fddi_mac_frm
);
1166 * Check whether we need to do EtherType encoding or whether the packet
1169 if (type
> GLD_MAX_802_SAP
)
1170 hdrlen
+= sizeof (struct llc_snap_hdr
);
1172 /* need a buffer big enough for the headers */
1173 nmp
= mp
->b_cont
; /* where the packet payload M_DATA is */
1174 if (DB_REF(nmp
) == 1 && MBLKHEAD(nmp
) >= hdrlen
) {
1175 /* it fits at the beginning of the first M_DATA block */
1176 freeb(mp
); /* don't need the M_PROTO anymore */
1177 } else if (DB_REF(mp
) == 1 && MBLKSIZE(mp
) >= hdrlen
) {
1178 /* we can reuse the dl_unitdata_req M_PROTO mblk */
1180 DB_TYPE(nmp
) = M_DATA
;
1181 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
1183 /* we need to allocate one */
1184 if ((nmp
= allocb(hdrlen
, BPRI_MED
)) == NULL
)
1186 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
1187 linkb(nmp
, mp
->b_cont
);
1192 /* Got the space, now copy in the header components */
1193 if (type
> GLD_MAX_802_SAP
) {
1194 /* create the snap header */
1195 struct llc_snap_hdr
*snap
;
1196 nmp
->b_rptr
-= sizeof (struct llc_snap_hdr
);
1197 snap
= (struct llc_snap_hdr
*)(nmp
->b_rptr
);
1198 *snap
= llc_snap_def
;
1199 SET_NET_USHORT(snap
->type
, type
);
1202 nmp
->b_rptr
-= sizeof (struct fddi_mac_frm
);
1204 mh
= (struct fddi_mac_frm
*)nmp
->b_rptr
;
1207 cmac_copy(dhost
, mh
->fddi_dhost
, macinfo
->gldm_addrlen
, macinfo
);
1210 * We access the mac address without the mutex to prevent
1211 * mutex contention (BUG 4211361)
1213 cmac_copy(((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->curr_macaddr
,
1214 mh
->fddi_shost
, macinfo
->gldm_addrlen
, macinfo
);
1219 gld_fastpath_fddi(gld_t
*gld
, mblk_t
*mp
)
1221 gld_mac_info_t
*macinfo
= gld
->gld_mac_info
;
1222 dl_unitdata_req_t
*dlp
= (dl_unitdata_req_t
*)mp
->b_cont
->b_rptr
;
1223 struct gld_dlsap
*gldp
= DLSAP(dlp
, dlp
->dl_dest_addr_offset
);
1224 unsigned short type
;
1226 struct fddi_mac_frm
*mh
;
1231 /* look in the unitdata request for a sap, else use bound one */
1232 if (dlp
->dl_dest_addr_length
>= DLSAPLENGTH(macinfo
) &&
1233 REF_HOST_USHORT(gldp
->glda_sap
) != 0)
1234 type
= REF_HOST_USHORT(gldp
->glda_sap
);
1236 type
= gld
->gld_sap
;
1238 hdrlen
= sizeof (struct fddi_mac_frm
);
1241 * Check whether we need to do EtherType encoding or whether the packet
1244 if (type
> GLD_MAX_802_SAP
)
1245 hdrlen
+= sizeof (struct llc_snap_hdr
);
1247 if ((nmp
= allocb(hdrlen
, BPRI_MED
)) == NULL
)
1250 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
1252 /* Got the space, now copy in the header components */
1254 if (type
> GLD_MAX_802_SAP
) {
1255 /* create the snap header */
1256 struct llc_snap_hdr
*snap
;
1257 nmp
->b_rptr
-= sizeof (struct llc_snap_hdr
);
1258 snap
= (struct llc_snap_hdr
*)(nmp
->b_rptr
);
1259 *snap
= llc_snap_def
;
1260 snap
->type
= htons(type
); /* we know it's aligned */
1263 nmp
->b_rptr
-= sizeof (struct fddi_mac_frm
);
1265 mh
= (struct fddi_mac_frm
*)nmp
->b_rptr
;
1267 cmac_copy(gldp
->glda_addr
, mh
->fddi_dhost
,
1268 macinfo
->gldm_addrlen
, macinfo
);
1270 GLDM_LOCK(macinfo
, RW_WRITER
);
1271 cmac_copy(((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->curr_macaddr
,
1272 mh
->fddi_shost
, macinfo
->gldm_addrlen
, macinfo
);
1273 GLDM_UNLOCK(macinfo
);
1282 #define GLD_SR_VAR(macinfo) \
1283 (((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->data)
1285 #define GLD_SR_HASH(macinfo) ((struct srtab **)GLD_SR_VAR(macinfo))
1287 #define GLD_SR_MUTEX(macinfo) \
1288 (&((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->datalock)
1290 static void gld_sr_clear(gld_mac_info_t
*);
1291 static void gld_rcc_receive(gld_mac_info_t
*, pktinfo_t
*, struct gld_ri
*,
1293 static void gld_rcc_send(gld_mac_info_t
*, queue_t
*, uchar_t
*,
1294 struct gld_ri
**, uchar_t
*);
1296 static mac_addr_t tokenbroadcastaddr2
= { 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff };
1297 static struct gld_ri ri_ste_def
;
1300 gld_init_tr(gld_mac_info_t
*macinfo
)
1302 struct gldkstats
*sp
=
1303 ((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->kstatp
->ks_data
;
1305 /* avoid endian-dependent code by initializing here instead of static */
1307 ri_ste_def
.rt
= RT_STE
;
1308 ri_ste_def
.mtu
= RT_MTU_MAX
;
1312 /* Assumptions we make for this medium */
1313 ASSERT(macinfo
->gldm_type
== DL_TPR
);
1314 ASSERT(macinfo
->gldm_addrlen
== 6);
1315 ASSERT(macinfo
->gldm_saplen
== -2);
1317 ASSERT(sizeof (struct tr_mac_frm_nori
) == 14);
1318 ASSERT(sizeof (mac_addr_t
) == 6);
1321 mutex_init(GLD_SR_MUTEX(macinfo
), NULL
, MUTEX_DRIVER
, NULL
);
1323 GLD_SR_VAR(macinfo
) = kmem_zalloc(sizeof (struct srtab
*)*SR_HASH_SIZE
,
1326 /* Default is RDE enabled for this medium */
1327 ((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_enabled
=
1328 ddi_getprop(DDI_DEV_T_NONE
, macinfo
->gldm_devinfo
, 0,
1329 "gld_rde_enable", 1);
1332 * Default is to use STE for unknown paths if RDE is enabled.
1333 * If RDE is disabled, default is to use NULL RIF fields.
1335 * It's possible to force use of STE for ALL packets:
1336 * disable RDE but enable STE. This may be useful for
1337 * non-transparent bridges, when it is not desired to run
1338 * the RDE algorithms.
1340 ((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_str_indicator_ste
=
1341 ddi_getprop(DDI_DEV_T_NONE
, macinfo
->gldm_devinfo
, 0,
1342 "gld_rde_str_indicator_ste",
1343 ((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_enabled
);
1345 /* Default 10 second route timeout on lack of activity */
1347 int t
= ddi_getprop(DDI_DEV_T_NONE
, macinfo
->gldm_devinfo
, 0,
1348 "gld_rde_timeout", 10);
1350 t
= 1; /* Let's be reasonable */
1352 t
= 600; /* Let's be reasonable */
1353 /* We're using ticks (lbolts) for our timeout -- convert from seconds */
1354 t
= drv_usectohz(1000000 * t
);
1355 ((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_timeout
= t
;
1358 kstat_named_init(&sp
->glds_dot5_line_error
,
1359 "line_errors", KSTAT_DATA_UINT32
);
1360 kstat_named_init(&sp
->glds_dot5_burst_error
,
1361 "burst_errors", KSTAT_DATA_UINT32
);
1362 kstat_named_init(&sp
->glds_dot5_signal_loss
,
1363 "signal_losses", KSTAT_DATA_UINT32
);
1366 * only initialize the new statistics if the driver
1369 if (macinfo
->gldm_driver_version
!= GLD_VERSION_200
)
1372 kstat_named_init(&sp
->glds_dot5_ace_error
,
1373 "ace_errors", KSTAT_DATA_UINT32
);
1374 kstat_named_init(&sp
->glds_dot5_internal_error
,
1375 "internal_errors", KSTAT_DATA_UINT32
);
1376 kstat_named_init(&sp
->glds_dot5_lost_frame_error
,
1377 "lost_frame_errors", KSTAT_DATA_UINT32
);
1378 kstat_named_init(&sp
->glds_dot5_frame_copied_error
,
1379 "frame_copied_errors", KSTAT_DATA_UINT32
);
1380 kstat_named_init(&sp
->glds_dot5_token_error
,
1381 "token_errors", KSTAT_DATA_UINT32
);
1382 kstat_named_init(&sp
->glds_dot5_freq_error
,
1383 "freq_errors", KSTAT_DATA_UINT32
);
1387 gld_uninit_tr(gld_mac_info_t
*macinfo
)
1389 mutex_destroy(GLD_SR_MUTEX(macinfo
));
1390 gld_sr_clear(macinfo
);
1391 kmem_free(GLD_SR_VAR(macinfo
), sizeof (struct srtab
*) * SR_HASH_SIZE
);
1395 gld_interpret_tr(gld_mac_info_t
*macinfo
, mblk_t
*mp
, pktinfo_t
*pktinfo
,
1396 packet_flag_t flags
)
1398 struct tr_mac_frm
*mh
;
1399 gld_mac_pvt_t
*mac_pvt
;
1400 struct llc_snap_hdr
*snaphdr
;
1405 * Quickly handle receive fastpath; TR does not support IPQ hack.
1407 if (flags
== GLD_RXQUICK
) {
1408 pktinfo
->pktLen
= msgdsize(mp
);
1412 bzero((void *)pktinfo
, sizeof (*pktinfo
));
1414 pktinfo
->pktLen
= msgdsize(mp
);
1416 /* make sure packet has at least a whole mac header */
1417 if (pktinfo
->pktLen
< sizeof (struct tr_mac_frm_nori
))
1420 /* make sure the mac header falls into contiguous memory */
1421 if (MBLKL(mp
) < sizeof (struct tr_mac_frm_nori
)) {
1422 if ((pmp
= msgpullup(mp
, -1)) == NULL
) {
1424 if (gld_debug
& GLDERRS
)
1426 "GLD: interpret_tr cannot msgpullup");
1430 mp
= pmp
; /* this mblk contains the whole mac header */
1433 mh
= (struct tr_mac_frm
*)mp
->b_rptr
;
1435 /* Check to see if the mac is a broadcast or multicast address. */
1436 if (mac_eq(mh
->tr_dhost
, ether_broadcast
, macinfo
->gldm_addrlen
) ||
1437 mac_eq(mh
->tr_dhost
, tokenbroadcastaddr2
, macinfo
->gldm_addrlen
))
1438 pktinfo
->isBroadcast
= 1;
1439 else if (mh
->tr_dhost
[0] & 0x80)
1440 pktinfo
->isMulticast
= 1;
1442 if (flags
== GLD_TX
)
1443 goto out
; /* Got all info we need for xmit case */
1445 ASSERT(GLDM_LOCK_HELD(macinfo
));
1448 * Deal with the mac header
1451 mac_copy(mh
->tr_dhost
, pktinfo
->dhost
, macinfo
->gldm_addrlen
);
1452 mac_copy(mh
->tr_shost
, pktinfo
->shost
, macinfo
->gldm_addrlen
);
1453 pktinfo
->shost
[0] &= ~0x80; /* turn off RIF indicator */
1455 mac_pvt
= (gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
;
1456 pktinfo
->isLooped
= mac_eq(pktinfo
->shost
,
1457 mac_pvt
->curr_macaddr
, macinfo
->gldm_addrlen
);
1458 pktinfo
->isForMe
= mac_eq(pktinfo
->dhost
,
1459 mac_pvt
->curr_macaddr
, macinfo
->gldm_addrlen
);
1461 rh
= (struct gld_ri
*)NULL
;
1462 pktinfo
->macLen
= sizeof (struct tr_mac_frm_nori
);
1465 * Before trying to look beyond the MAC header, make sure the data
1466 * structures are all contiguously where we can conveniently look at
1467 * them. We'll use a worst-case estimate of how many bytes into the
1468 * packet data we'll be needing to look. Things will be more efficient
1469 * if the driver puts at least this much into the first mblk.
1471 * Even after this, we still will have to do checks against the total
1472 * length of the packet. A bad incoming packet may not hold all the
1473 * data structures it says it does.
1475 if (MBLKL(mp
) < sizeof (struct tr_mac_frm
) +
1476 LLC_HDR1_LEN
+ sizeof (struct rde_pdu
) &&
1477 MBLKL(mp
) < pktinfo
->pktLen
) {
1479 * we don't have the entire packet within the first mblk (and
1480 * therefore we didn't do the msgpullup above), AND the first
1481 * mblk may not contain all the data we need to look at.
1483 ASSERT(pmp
== NULL
); /* couldn't have done msgpullup above */
1484 if ((pmp
= msgpullup(mp
, -1)) == NULL
) {
1486 if (gld_debug
& GLDERRS
)
1488 "GLD: interpret_tr cannot msgpullup2");
1490 goto out
; /* can't interpret this pkt further */
1492 mp
= pmp
; /* this mblk should contain everything needed */
1493 mh
= (struct tr_mac_frm
*)mp
->b_rptr
; /* to look at RIF */
1496 if (mh
->tr_shost
[0] & 0x80) {
1497 /* Routing Information Field (RIF) is present */
1498 if (pktinfo
->pktLen
< sizeof (struct tr_mac_frm_nori
) + 2)
1499 goto out
; /* RIF should have been there! */
1500 rh
= (struct gld_ri
*)&mh
->tr_ri
;
1501 if ((rh
->len
& 1) || rh
->len
< 2) {
1502 /* Bogus RIF, don't handle this packet */
1504 if (gld_debug
& GLDERRS
)
1506 "GLD: received TR packet with "
1507 "bogus RIF length %d",
1512 if (pktinfo
->pktLen
< sizeof (struct tr_mac_frm_nori
) + rh
->len
)
1513 goto out
; /* RIF should have been there! */
1514 pktinfo
->macLen
+= rh
->len
;
1517 if ((mh
->tr_fc
& 0xc0) == 0x40) {
1518 if (pktinfo
->pktLen
< pktinfo
->macLen
+ LLC_HDR1_LEN
)
1523 if (pktinfo
->pktLen
< pktinfo
->macLen
+ LLC_SNAP_HDR_LEN
)
1526 snaphdr
= (struct llc_snap_hdr
*)(mp
->b_rptr
+ pktinfo
->macLen
);
1527 if (ISETHERTYPE(snaphdr
)) {
1528 pktinfo
->ethertype
= REF_NET_USHORT(snaphdr
->type
);
1529 pktinfo
->hdrLen
= LLC_SNAP_HDR_LEN
;
1532 /* Inform the Route Control Component of received LLC frame */
1533 gld_rcc_receive(macinfo
, pktinfo
, rh
,
1534 mp
->b_rptr
+ pktinfo
->macLen
,
1535 pktinfo
->pktLen
- pktinfo
->macLen
);
1545 gld_unitdata_tr(gld_t
*gld
, mblk_t
*mp
)
1547 gld_mac_info_t
*macinfo
= gld
->gld_mac_info
;
1548 dl_unitdata_req_t
*dlp
= (dl_unitdata_req_t
*)mp
->b_rptr
;
1549 struct gld_dlsap
*gldp
= DLSAP(dlp
, dlp
->dl_dest_addr_offset
);
1551 unsigned short type
;
1552 mblk_t
*nmp
, *llcmp
, *pmp
= NULL
;
1553 struct tr_mac_frm_nori
*mh
;
1559 /* extract needed info from the mblk before we maybe reuse it */
1560 mac_copy(gldp
->glda_addr
, dhost
, macinfo
->gldm_addrlen
);
1562 /* look in the unitdata request for a sap, else use bound one */
1563 if (dlp
->dl_dest_addr_length
>= DLSAPLENGTH(macinfo
) &&
1564 REF_HOST_USHORT(gldp
->glda_sap
) != 0)
1565 type
= REF_HOST_USHORT(gldp
->glda_sap
);
1567 type
= gld
->gld_sap
;
1569 /* includes maximum possible Routing Information Field (RIF) size */
1570 hdrlen
= sizeof (struct tr_mac_frm
);
1573 * Check whether we need to do EtherType encoding or whether the packet
1576 if (type
> GLD_MAX_802_SAP
)
1577 hdrlen
+= sizeof (struct llc_snap_hdr
);
1579 /* need a buffer big enough for the headers */
1580 llcmp
= nmp
= mp
->b_cont
; /* where the packet payload M_DATA is */
1583 * We are going to need to look at the LLC header, so make sure it
1584 * is contiguously in a single mblk. If we're the ones who create
1585 * the LLC header (below, in the case where sap > 0xff) then we don't
1586 * have to worry about it here.
1588 ASSERT(nmp
!= NULL
); /* gld_unitdata guarantees msgdsize > 0 */
1589 if (type
<= GLD_MAX_802_SAP
) {
1590 if (MBLKL(llcmp
) < LLC_HDR1_LEN
) {
1591 llcmp
= pmp
= msgpullup(nmp
, LLC_HDR1_LEN
);
1594 if (gld_debug
& GLDERRS
)
1597 "cannot msgpullup");
1604 if (DB_REF(nmp
) == 1 && MBLKHEAD(nmp
) >= hdrlen
) {
1605 /* it fits at the beginning of the first M_DATA block */
1606 freeb(mp
); /* don't need the M_PROTO anymore */
1607 } else if (DB_REF(mp
) == 1 && MBLKSIZE(mp
) >= hdrlen
) {
1608 /* we can reuse the dl_unitdata_req M_PROTO mblk */
1610 DB_TYPE(nmp
) = M_DATA
;
1611 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
1613 /* we need to allocate one */
1614 if ((nmp
= allocb(hdrlen
, BPRI_MED
)) == NULL
) {
1619 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
1620 linkb(nmp
, mp
->b_cont
);
1624 /* Got the space, now copy in the header components */
1625 if (type
> GLD_MAX_802_SAP
) {
1626 /* create the snap header */
1627 struct llc_snap_hdr
*snap
;
1628 llcmp
= nmp
; /* LLC header is going to be in this mblk */
1629 nmp
->b_rptr
-= sizeof (struct llc_snap_hdr
);
1630 snap
= (struct llc_snap_hdr
*)(nmp
->b_rptr
);
1631 *snap
= llc_snap_def
;
1632 SET_NET_USHORT(snap
->type
, type
);
1635 /* Hold SR tables still while we maybe point at an entry */
1636 mutex_enter(GLD_SR_MUTEX(macinfo
));
1638 gld_rcc_send(macinfo
, WR(gld
->gld_qptr
), dhost
, &rh
, llcmp
->b_rptr
);
1641 /* copy in the RIF */
1642 ASSERT(rh
->len
<= sizeof (struct gld_ri
));
1643 nmp
->b_rptr
-= rh
->len
;
1644 bcopy((caddr_t
)rh
, (caddr_t
)nmp
->b_rptr
, rh
->len
);
1647 mutex_exit(GLD_SR_MUTEX(macinfo
));
1649 /* no longer need the pulled-up mblk */
1654 * fill in token ring header
1656 nmp
->b_rptr
-= sizeof (struct tr_mac_frm_nori
);
1657 mh
= (struct tr_mac_frm_nori
*)nmp
->b_rptr
;
1660 mac_copy(dhost
, mh
->tr_dhost
, macinfo
->gldm_addrlen
);
1663 * We access the mac address without the mutex to prevent
1664 * mutex contention (BUG 4211361)
1666 mac_copy(((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->curr_macaddr
,
1667 mh
->tr_shost
, macinfo
->gldm_addrlen
);
1670 mh
->tr_shost
[0] |= 0x80;
1672 mh
->tr_shost
[0] &= ~0x80;
1678 * We cannot have our client sending us "fastpath" M_DATA messages,
1679 * because to do that we must provide to him a fixed MAC header to
1680 * be prepended to each outgoing packet. But with Source Routing
1681 * media, the length and content of the MAC header changes as the
1682 * routes change, so there is no fixed header we can provide. So
1683 * we decline to accept M_DATA messages if Source Routing is enabled.
1686 gld_fastpath_tr(gld_t
*gld
, mblk_t
*mp
)
1688 gld_mac_info_t
*macinfo
= gld
->gld_mac_info
;
1689 dl_unitdata_req_t
*dlp
= (dl_unitdata_req_t
*)mp
->b_cont
->b_rptr
;
1690 struct gld_dlsap
*gldp
= DLSAP(dlp
, dlp
->dl_dest_addr_offset
);
1691 unsigned short type
;
1693 struct tr_mac_frm_nori
*mh
;
1699 * If we are doing Source Routing, then we cannot provide a fixed
1700 * MAC header, so fail.
1702 if (((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_enabled
)
1705 /* look in the unitdata request for a sap, else use bound one */
1706 if (dlp
->dl_dest_addr_length
>= DLSAPLENGTH(macinfo
) &&
1707 REF_HOST_USHORT(gldp
->glda_sap
) != 0)
1708 type
= REF_HOST_USHORT(gldp
->glda_sap
);
1710 type
= gld
->gld_sap
;
1712 hdrlen
= sizeof (struct tr_mac_frm_nori
);
1714 if (((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_str_indicator_ste
)
1715 hdrlen
+= ri_ste_def
.len
;
1718 * Check whether we need to do EtherType encoding or whether the packet
1721 if (type
> GLD_MAX_802_SAP
)
1722 hdrlen
+= sizeof (struct llc_snap_hdr
);
1724 if ((nmp
= allocb(hdrlen
, BPRI_MED
)) == NULL
)
1727 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
1729 /* Got the space, now copy in the header components */
1731 if (type
> GLD_MAX_802_SAP
) {
1732 /* create the snap header */
1733 struct llc_snap_hdr
*snap
;
1734 nmp
->b_rptr
-= sizeof (struct llc_snap_hdr
);
1735 snap
= (struct llc_snap_hdr
*)(nmp
->b_rptr
);
1736 *snap
= llc_snap_def
;
1737 snap
->type
= htons(type
); /* we know it's aligned */
1740 /* RDE is disabled, use NULL RIF, or STE RIF */
1741 if (((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_str_indicator_ste
) {
1742 nmp
->b_rptr
-= ri_ste_def
.len
;
1743 bcopy((caddr_t
)&ri_ste_def
, (caddr_t
)nmp
->b_rptr
,
1748 * fill in token ring header
1750 nmp
->b_rptr
-= sizeof (struct tr_mac_frm_nori
);
1751 mh
= (struct tr_mac_frm_nori
*)nmp
->b_rptr
;
1754 mac_copy(gldp
->glda_addr
, mh
->tr_dhost
, macinfo
->gldm_addrlen
);
1756 GLDM_LOCK(macinfo
, RW_WRITER
);
1757 mac_copy(((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->curr_macaddr
,
1758 mh
->tr_shost
, macinfo
->gldm_addrlen
);
1759 GLDM_UNLOCK(macinfo
);
1761 if (((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_str_indicator_ste
)
1762 mh
->tr_shost
[0] |= 0x80;
1764 mh
->tr_shost
[0] &= ~0x80;
1770 * Route Determination Entity (ISO 8802-2 / IEEE 802.2 : 1994, Section 9)
1772 * RDE is an LLC layer entity. GLD is a MAC layer entity. The proper
1773 * solution to this architectural anomaly is to move RDE support out of GLD
1774 * and into LLC where it belongs. In particular, only LLC has the knowledge
1775 * necessary to reply to XID and TEST packets. If and when it comes time to
1776 * move RDE out of GLD to LLC, the LLC-to-GLD interface should be modified
1777 * to use MA_UNITDATA structures rather than DL_UNITDATA structures. Of
1778 * course, GLD will still have to continue to also support the DL_ structures
1779 * as long as IP is not layered over LLC. Another, perhaps better, idea
1780 * would be to make RDE an autopush module on top of the token ring drivers:
1781 * RDE would sit between LLC and GLD. It would then also sit between IP and
1782 * GLD, providing services to all clients of GLD/tokenring. In that case,
1783 * GLD would still have to continue to support the DL_ interface for non-
1784 * Token Ring interfaces, using the MA_ interface only for media supporting
1785 * Source Routing media.
1787 * At present, Token Ring is the only source routing medium we support.
1788 * Since Token Ring is not at this time a strategic network medium for Sun,
1789 * rather than devote a large amount of resources to creating a proper
1790 * architecture and implementation of RDE, we do the minimum necessary to
1791 * get it to work. The interface between the above token ring code and the
1792 * below RDE code is designed to make it relatively easy to change to an
1793 * MA_UNITDATA model later should this ever become a priority.
1796 static void gld_send_rqr(gld_mac_info_t
*, uchar_t
*, struct gld_ri
*,
1797 struct rde_pdu
*, int);
1798 static void gld_rde_pdu_req(gld_mac_info_t
*, queue_t
*, uchar_t
*,
1799 struct gld_ri
*, uchar_t
, uchar_t
, uchar_t
);
1800 static void gld_get_route(gld_mac_info_t
*, queue_t
*, uchar_t
*,
1801 struct gld_ri
**, uchar_t
, uchar_t
);
1802 static void gld_reset_route(gld_mac_info_t
*, queue_t
*,
1803 uchar_t
*, uchar_t
, uchar_t
);
1804 static void gld_rde_pdu_ind(gld_mac_info_t
*, struct gld_ri
*, struct rde_pdu
*,
1806 static void gld_rif_ind(gld_mac_info_t
*, struct gld_ri
*, uchar_t
*,
1808 static struct srtab
**gld_sr_hash(struct srtab
**, uchar_t
*, int);
1809 static struct srtab
*gld_sr_lookup_entry(gld_mac_info_t
*, uchar_t
*);
1810 static struct srtab
*gld_sr_create_entry(gld_mac_info_t
*, uchar_t
*);
1813 * This routine implements a modified subset of the 802.2 RDE RCC receive
1815 * we implement RCC receive events 3 to 12 (ISO 8802-2:1994 9.6.3.4);
1816 * we omit special handling for the NULL SAP;
1817 * we omit XID/TEST handling;
1818 * we pass all packets (including RDE) upstream to LLC.
1821 gld_rcc_receive(gld_mac_info_t
*macinfo
, pktinfo_t
*pktinfo
, struct gld_ri
*rh
,
1822 uchar_t
*llcpkt
, int llcpktlen
)
1824 struct llc_snap_hdr
*snaphdr
= (struct llc_snap_hdr
*)(llcpkt
);
1826 if (!((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_enabled
)
1830 * First, ensure this packet wasn't something we received just
1831 * because we were in promiscuous mode. Since none of the below
1832 * code wants to see group addressed packets anyway, we can do
1833 * this check up front. Since we're doing that, we can omit the
1834 * checks for group addressed packets below.
1836 if (!pktinfo
->isForMe
)
1837 return; /* Event 6 */
1839 /* Process a subset of Route Determination Entity (RDE) packets */
1840 if (snaphdr
->d_lsap
== LSAP_RDE
) {
1841 struct rde_pdu
*pdu
= (struct rde_pdu
*)(llcpkt
+ LLC_HDR1_LEN
);
1842 int pdulen
= llcpktlen
- LLC_HDR1_LEN
;
1844 /* sanity check the PDU */
1845 if ((pdulen
< sizeof (struct rde_pdu
)) ||
1846 (snaphdr
->s_lsap
!= LSAP_RDE
))
1849 /* we only handle route discovery PDUs, not XID/TEST/other */
1850 if (snaphdr
->control
!= CNTL_LLC_UI
)
1853 switch (pdu
->rde_ptype
) {
1854 case RDE_RQC
: /* Route Query Command; Events 8 - 11 */
1855 gld_send_rqr(macinfo
, pktinfo
->shost
, rh
, pdu
, pdulen
);
1857 case RDE_RQR
: /* Route Query Response; Event 12 */
1858 case RDE_RS
: /* Route Selected; Event 7 */
1859 gld_rde_pdu_ind(macinfo
, rh
, pdu
, pdulen
);
1861 default: /* ignore if unrecognized ptype */
1868 /* Consider routes seen in other IA SRF packets */
1871 return; /* no RIF; Event 3 */
1873 if ((rh
->rt
& 0x04) != 0)
1874 return; /* not SRF; Event 5 */
1876 gld_rif_ind(macinfo
, rh
, pktinfo
->shost
, snaphdr
->s_lsap
,
1877 snaphdr
->d_lsap
); /* Event 4 */
1881 * Send RQR: 802.2 9.6.3.4.2(9) RCC Receive Events 8-11
1883 * The routing processing really doesn't belong here; it should be handled in
1884 * the LLC layer above. If that were the case then RDE could just send down
1885 * an extra MA_UNITDATA_REQ with the info needed to construct the packet. But
1886 * at the time we get control here, it's not a particularly good time to be
1887 * constructing packets and trying to send them. Specifically, at this layer
1888 * we need to construct the full media packet, which means the below routine
1889 * knows that it is dealing with Token Ring media. If this were instead done
1890 * via a proper MA_UNITDATA interface, the RDE stuff could all be completely
1891 * media independent. But since TR is the only source routing medium we
1892 * support, this works even though it is not clean.
1894 * We "know" that the only time we can get here is from the "interpret"
1895 * routine, and only when it was called at receive time.
1898 gld_send_rqr(gld_mac_info_t
*macinfo
, uchar_t
*shost
, struct gld_ri
*rh
,
1899 struct rde_pdu
*pdu
, int pdulen
)
1903 struct tr_mac_frm_nori
*nmh
;
1905 struct llc_snap_hdr
*nsnaphdr
;
1906 struct rde_pdu
*npdu
;
1908 /* We know and assume we're on the receive path */
1909 ASSERT(GLDM_LOCK_HELD(macinfo
));
1911 if (pdulen
< sizeof (struct rde_pdu
))
1912 return; /* Bad incoming PDU */
1914 nlen
= sizeof (struct tr_mac_frm
) + LLC_HDR1_LEN
+
1915 sizeof (struct rde_pdu
);
1917 if ((nmp
= allocb(nlen
, BPRI_MED
)) == NULL
)
1920 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
1922 nmp
->b_rptr
-= sizeof (struct rde_pdu
);
1923 npdu
= (struct rde_pdu
*)(nmp
->b_rptr
);
1924 *npdu
= *pdu
; /* copy orig/target macaddr/saps */
1926 npdu
->rde_ptype
= RDE_RQR
;
1927 mac_copy(((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->curr_macaddr
,
1928 npdu
->rde_target_mac
, macinfo
->gldm_addrlen
);
1930 nmp
->b_rptr
-= LLC_HDR1_LEN
;
1931 nsnaphdr
= (struct llc_snap_hdr
*)(nmp
->b_rptr
);
1932 nsnaphdr
->s_lsap
= nsnaphdr
->d_lsap
= LSAP_RDE
;
1933 nsnaphdr
->control
= CNTL_LLC_UI
;
1935 if (rh
== NULL
|| (rh
->rt
& 0x06) == 0x06 ||
1936 rh
->len
> sizeof (struct gld_ri
)) {
1937 /* no RIF (Event 8), or RIF type STE (Event 9): send ARE RQR */
1939 nrh
= (struct gld_ri
*)(nmp
->b_rptr
);
1944 nrh
->mtu
= RT_MTU_MAX
;
1947 * RIF must be ARE (Event 10) or SRF (Event 11):
1948 * send SRF (reverse) RQR
1950 ASSERT(rh
->len
<= sizeof (struct gld_ri
));
1951 nmp
->b_rptr
-= rh
->len
;
1952 nrh
= (struct gld_ri
*)(nmp
->b_rptr
);
1953 bcopy(rh
, nrh
, rh
->len
); /* copy incoming RIF */
1954 nrh
->rt
= RT_SRF
; /* make it SRF */
1955 nrh
->dir
^= 1; /* reverse direction */
1958 nmp
->b_rptr
-= sizeof (struct tr_mac_frm_nori
);
1959 nmh
= (struct tr_mac_frm_nori
*)(nmp
->b_rptr
);
1962 mac_copy(shost
, nmh
->tr_dhost
, macinfo
->gldm_addrlen
);
1963 mac_copy(((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->curr_macaddr
,
1964 nmh
->tr_shost
, macinfo
->gldm_addrlen
);
1965 nmh
->tr_shost
[0] |= 0x80; /* indicate RIF present */
1968 * Packet assembled; send it.
1970 * As noted before, this is not really a good time to be trying to
1971 * send out packets. We have no obvious queue to use if the packet
1972 * can't be sent right away. We pick one arbitrarily.
1978 if ((vlan
= gld_find_vlan(macinfo
, VLAN_VID_NONE
)) == NULL
) {
1979 /* oops, no vlan on the list for this macinfo! */
1980 /* this should not happen */
1984 q
= vlan
->gldv_str_next
->gld_qptr
;
1987 * Queue the packet and let gld_wsrv
1988 * handle it, thus preventing a panic
1989 * caused by v2 TR in promiscuous mode
1990 * where it attempts to get the mutex
1991 * in this thread while already holding
1994 (void) putbq(WR(q
), nmp
);
2000 * This routine implements a modified subset of the 802.2 RDE RCC send actions:
2001 * we implement RCC send events 5 to 10 (ISO 8802-2:1994 9.6.3.5);
2002 * we omit special handling for the NULL SAP;
2003 * events 11 to 12 are handled by gld_rde_pdu_req below;
2004 * we require an immediate response to our GET_ROUTE_REQUEST.
2007 gld_rcc_send(gld_mac_info_t
*macinfo
, queue_t
*q
, uchar_t
*dhost
,
2008 struct gld_ri
**rhp
, uchar_t
*llcpkt
)
2010 struct llc_snap_hdr
*snaphdr
= (struct llc_snap_hdr
*)(llcpkt
);
2013 * Our caller has to take the mutex because: to avoid an extra bcopy
2014 * of the RIF on every transmit, we pass back a pointer to our sr
2015 * table entry via rhp. He has to keep the mutex until he has a
2016 * chance to copy the RIF out into the outgoing packet, so that we
2017 * don't modify the entry while he's trying to copy it. This is a
2018 * little ugly, but saves the extra bcopy.
2020 ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo
)));
2022 *rhp
= (struct gld_ri
*)NULL
; /* start off clean (no RIF) */
2024 if (!((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_enabled
) {
2025 /* RDE is disabled -- use NULL or STE always */
2026 if (((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->
2027 rde_str_indicator_ste
)
2028 *rhp
= &ri_ste_def
; /* STE option */
2032 if (!(dhost
[0] & 0x80)) {
2033 /* individual address; Events 7 - 10 */
2034 if ((snaphdr
->control
& 0xef) == 0xe3) {
2035 /* TEST command, reset the route */
2036 gld_reset_route(macinfo
, q
,
2037 dhost
, snaphdr
->d_lsap
, snaphdr
->s_lsap
);
2039 gld_get_route(macinfo
, q
,
2040 dhost
, rhp
, snaphdr
->d_lsap
, snaphdr
->s_lsap
);
2045 * group address (Events 5 - 6),
2046 * or no route available (Events 8 - 9):
2047 * Need to send NSR or STE, as configured.
2049 if (((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->
2050 rde_str_indicator_ste
)
2051 *rhp
= &ri_ste_def
; /* STE option */
2056 * RCC send events 11 - 12
2058 * At present we only handle the RQC ptype.
2060 * We "know" that the only time we can get here is from the "unitdata"
2061 * routine, called at wsrv time.
2063 * If we ever implement the RS ptype (Event 13), this may no longer be true!
2066 gld_rde_pdu_req(gld_mac_info_t
*macinfo
, queue_t
*q
, uchar_t
*dhost
,
2067 struct gld_ri
*rh
, uchar_t dsap
, uchar_t ssap
, uchar_t ptype
)
2071 struct tr_mac_frm_nori
*nmh
;
2073 struct llc_snap_hdr
*nsnaphdr
;
2074 struct rde_pdu
*npdu
;
2077 /* if you change this to process other types, review all code below */
2078 ASSERT(ptype
== RDE_RQC
);
2079 ASSERT(rh
== NULL
); /* RQC never uses SRF */
2081 nlen
= sizeof (struct tr_mac_frm
) + LLC_HDR1_LEN
+
2082 sizeof (struct rde_pdu
);
2084 if ((nmp
= allocb(nlen
, BPRI_MED
)) == NULL
)
2087 nmp
->b_rptr
= nmp
->b_wptr
= DB_LIM(nmp
);
2089 nmp
->b_rptr
-= sizeof (struct rde_pdu
);
2090 npdu
= (struct rde_pdu
*)(nmp
->b_rptr
);
2092 npdu
->rde_ptype
= ptype
;
2093 mac_copy(dhost
, &npdu
->rde_target_mac
, 6);
2096 * access the mac address without a mutex - take a risk -
2097 * to prevent mutex contention (BUG 4211361)
2099 mac_copy(((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->curr_macaddr
,
2100 &npdu
->rde_orig_mac
, 6);
2101 npdu
->rde_target_sap
= dsap
;
2102 npdu
->rde_orig_sap
= ssap
;
2104 nmp
->b_rptr
-= LLC_HDR1_LEN
;
2105 nsnaphdr
= (struct llc_snap_hdr
*)(nmp
->b_rptr
);
2106 nsnaphdr
->s_lsap
= nsnaphdr
->d_lsap
= LSAP_RDE
;
2107 nsnaphdr
->control
= CNTL_LLC_UI
;
2109 #if 0 /* we don't need this for now */
2111 /* send an SRF frame with specified RIF */
2112 ASSERT(rh
->len
<= sizeof (struct gld_ri
));
2113 nmp
->b_rptr
-= rh
->len
;
2114 nrh
= (struct gld_ri
*)(nmp
->b_rptr
);
2115 bcopy(rh
, nrh
, rh
->len
);
2116 ASSERT(nrh
->rt
== RT_SRF
);
2121 /* Need to send NSR or STE, as configured. */
2122 if (((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_str_indicator_ste
) {
2123 /* send an STE frame */
2125 nrh
= (struct gld_ri
*)(nmp
->b_rptr
);
2130 nrh
->mtu
= RT_MTU_MAX
;
2132 } /* else send an NSR frame */
2134 nmp
->b_rptr
-= sizeof (struct tr_mac_frm_nori
);
2135 nmh
= (struct tr_mac_frm_nori
*)(nmp
->b_rptr
);
2138 mac_copy(dhost
, nmh
->tr_dhost
, macinfo
->gldm_addrlen
);
2140 * access the mac address without a mutex - take a risk -
2141 * to prevent mutex contention - BUG 4211361
2143 mac_copy(((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->curr_macaddr
,
2144 nmh
->tr_shost
, macinfo
->gldm_addrlen
);
2147 nmh
->tr_shost
[0] |= 0x80;
2149 nmh
->tr_shost
[0] &= ~0x80;
2152 * Packet assembled; send it.
2154 * Since we own the SR_MUTEX, we don't want to take the maclock
2155 * mutex (since they are acquired in the opposite order on the
2156 * receive path, so deadlock could occur). We could rearrange
2157 * the code in gld_get_route() and drop the SR_MUTEX around the
2158 * call to gld_rde_pdu_req(), but that's kind of ugly. Rather,
2159 * we just refrain from calling gld_start() from here, and
2160 * instead just queue the packet for wsrv to send next. Besides,
2161 * it's more important to get the packet we're working on out
2162 * quickly than this RQC.
2164 (void) putbq(WR(q
), nmp
);
2169 * Route Determination Component (RDC)
2171 * We do not implement separate routes for each SAP, as specified by
2172 * ISO 8802-2; instead we implement only one route per remote mac address.
2175 gld_get_route(gld_mac_info_t
*macinfo
, queue_t
*q
, uchar_t
*dhost
,
2176 struct gld_ri
**rhp
, uchar_t dsap
, uchar_t ssap
)
2179 clock_t t
= ddi_get_lbolt();
2181 ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo
)));
2183 sr
= gld_sr_lookup_entry(macinfo
, dhost
);
2187 * we have no entry -- never heard of this address:
2188 * create an empty entry and initiate RQC
2190 sr
= gld_sr_create_entry(macinfo
, dhost
);
2191 gld_rde_pdu_req(macinfo
, q
, dhost
, (struct gld_ri
*)NULL
,
2192 dsap
, ssap
, RDE_RQC
);
2195 *rhp
= NULL
; /* we have no route yet */
2199 /* we have an entry; see if we know a route yet */
2201 if (sr
->sr_ri
.len
== 0) {
2202 /* Have asked RQC, but no reply (yet) */
2203 if (t
- sr
->sr_timer
>
2204 ((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_timeout
) {
2205 /* RQR overdue, resend RQC */
2206 gld_rde_pdu_req(macinfo
, q
, dhost
,
2207 (struct gld_ri
*)NULL
, dsap
, ssap
, RDE_RQC
);
2210 *rhp
= NULL
; /* we have no route yet */
2214 /* we know a route, or it's local */
2216 /* if it might be stale, reset and get a new one */
2217 if (t
- sr
->sr_timer
>
2218 ((gld_mac_pvt_t
*)macinfo
->gldm_mac_pvt
)->rde_timeout
) {
2219 gld_rde_pdu_req(macinfo
, q
, dhost
,
2220 (struct gld_ri
*)NULL
, dsap
, ssap
, RDE_RQC
);
2223 *rhp
= NULL
; /* we have no route */
2227 if (sr
->sr_ri
.len
== 2) {
2228 /* the remote site is on our local ring -- no route needed */
2233 *rhp
= &sr
->sr_ri
; /* we have a route, return it */
2237 * zap the specified entry and reinitiate RQC
2240 gld_reset_route(gld_mac_info_t
*macinfo
, queue_t
*q
,
2241 uchar_t
*dhost
, uchar_t dsap
, uchar_t ssap
)
2245 ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo
)));
2247 sr
= gld_sr_create_entry(macinfo
, dhost
);
2248 gld_rde_pdu_req(macinfo
, q
, dhost
, (struct gld_ri
*)NULL
,
2249 dsap
, ssap
, RDE_RQC
);
2254 sr
->sr_timer
= ddi_get_lbolt();
2258 * This routine is called when an RDE PDU is received from our peer.
2259 * If it is an RS (Route Selected) PDU, we adopt the specified route.
2260 * If it is an RQR (reply to our previous RQC), we evaluate the
2261 * specified route in comparison with our current known route, if any,
2262 * and we keep the "better" of the two routes.
2265 gld_rde_pdu_ind(gld_mac_info_t
*macinfo
, struct gld_ri
*rh
, struct rde_pdu
*pdu
,
2271 if (pdulen
< sizeof (struct rde_pdu
))
2272 return; /* Bad incoming PDU */
2274 if (pdu
->rde_ptype
== RDE_RQC
)
2275 return; /* ignore RQC */
2277 if (pdu
->rde_ptype
!= RDE_RQR
&& pdu
->rde_ptype
!= RDE_RS
) {
2279 if (gld_debug
& GLDERRS
)
2280 cmn_err(CE_WARN
, "gld: bogus RDE ptype 0x%x received",
2288 if (gld_debug
& GLDERRS
)
2290 "gld: bogus NULL RIF, ptype 0x%x received",
2296 ASSERT(rh
->len
>= 2);
2297 ASSERT(rh
->len
<= sizeof (struct gld_ri
));
2298 ASSERT((rh
->len
& 1) == 0);
2300 if (pdu
->rde_ptype
== RDE_RQR
) {
2301 /* A reply to our RQC has his address as target mac */
2302 otherhost
= pdu
->rde_target_mac
;
2304 ASSERT(pdu
->rde_ptype
== RDE_RS
);
2305 /* An RS has his address as orig mac */
2306 otherhost
= pdu
->rde_orig_mac
;
2309 mutex_enter(GLD_SR_MUTEX(macinfo
));
2311 if ((sr
= gld_sr_create_entry(macinfo
, otherhost
)) == NULL
) {
2312 mutex_exit(GLD_SR_MUTEX(macinfo
));
2313 return; /* oh well, out of memory */
2316 if (pdu
->rde_ptype
== RDE_RQR
) {
2317 /* see if new route is better than what we may already have */
2318 if (sr
->sr_ri
.len
!= 0 &&
2319 sr
->sr_ri
.len
<= rh
->len
) {
2320 mutex_exit(GLD_SR_MUTEX(macinfo
));
2321 return; /* we have one, and new one is no shorter */
2325 /* adopt the new route */
2326 bcopy((caddr_t
)rh
, (caddr_t
)&sr
->sr_ri
, rh
->len
); /* copy incom RIF */
2327 sr
->sr_ri
.rt
= RT_SRF
; /* make it a clean SRF */
2328 sr
->sr_ri
.dir
^= 1; /* reverse direction */
2329 sr
->sr_timer
= ddi_get_lbolt();
2331 mutex_exit(GLD_SR_MUTEX(macinfo
));
2335 * This routine is called when a packet with a RIF is received. Our
2336 * policy is to adopt the route.
2340 gld_rif_ind(gld_mac_info_t
*macinfo
, struct gld_ri
*rh
, uchar_t
*shost
,
2341 uchar_t ssap
, uchar_t dsap
)
2345 ASSERT(rh
!= NULL
); /* ensure RIF */
2346 ASSERT((rh
->rt
& 0x04) == 0); /* ensure SRF */
2347 ASSERT(rh
->len
>= 2);
2348 ASSERT(rh
->len
<= sizeof (struct gld_ri
));
2349 ASSERT((rh
->len
& 1) == 0);
2351 mutex_enter(GLD_SR_MUTEX(macinfo
));
2353 if ((sr
= gld_sr_create_entry(macinfo
, shost
)) == NULL
) {
2354 mutex_exit(GLD_SR_MUTEX(macinfo
));
2355 return; /* oh well, out of memory */
2358 /* we have an entry; fill it in */
2359 bcopy((caddr_t
)rh
, (caddr_t
)&sr
->sr_ri
, rh
->len
); /* copy incom RIF */
2360 sr
->sr_ri
.rt
= RT_SRF
; /* make it a clean SRF */
2361 sr
->sr_ri
.dir
^= 1; /* reverse direction */
2362 sr
->sr_timer
= ddi_get_lbolt();
2364 mutex_exit(GLD_SR_MUTEX(macinfo
));
2367 static struct srtab
**
2368 gld_sr_hash(struct srtab
**sr_hash_tbl
, uchar_t
*addr
, int addr_length
)
2372 while (--addr_length
>= 0)
2375 return (&sr_hash_tbl
[hashval
% SR_HASH_SIZE
]);
2378 static struct srtab
*
2379 gld_sr_lookup_entry(gld_mac_info_t
*macinfo
, uchar_t
*macaddr
)
2383 ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo
)));
2385 for (sr
= *gld_sr_hash(GLD_SR_HASH(macinfo
), macaddr
,
2386 macinfo
->gldm_addrlen
); sr
; sr
= sr
->sr_next
)
2387 if (mac_eq(macaddr
, sr
->sr_mac
, macinfo
->gldm_addrlen
))
2390 return ((struct srtab
*)0);
2393 static struct srtab
*
2394 gld_sr_create_entry(gld_mac_info_t
*macinfo
, uchar_t
*macaddr
)
2399 ASSERT(!(macaddr
[0] & 0x80)); /* no group addresses here */
2400 ASSERT(mutex_owned(GLD_SR_MUTEX(macinfo
)));
2402 srp
= gld_sr_hash(GLD_SR_HASH(macinfo
), macaddr
, macinfo
->gldm_addrlen
);
2404 for (sr
= *srp
; sr
; sr
= sr
->sr_next
)
2405 if (mac_eq(macaddr
, sr
->sr_mac
, macinfo
->gldm_addrlen
))
2408 if (!(sr
= kmem_zalloc(sizeof (struct srtab
), KM_NOSLEEP
))) {
2410 if (gld_debug
& GLDERRS
)
2412 "gld: gld_sr_create_entry kmem_alloc failed");
2414 return ((struct srtab
*)0);
2417 bcopy((caddr_t
)macaddr
, (caddr_t
)sr
->sr_mac
, macinfo
->gldm_addrlen
);
2425 gld_sr_clear(gld_mac_info_t
*macinfo
)
2428 struct srtab
**sr_hash_tbl
= GLD_SR_HASH(macinfo
);
2429 struct srtab
**srp
, *sr
;
2432 * Walk through the table, deleting all entries.
2434 * Only called from uninit, so don't need the mutex.
2436 for (i
= 0; i
< SR_HASH_SIZE
; i
++) {
2437 for (srp
= &sr_hash_tbl
[i
]; (sr
= *srp
) != NULL
; ) {
2439 kmem_free((char *)sr
, sizeof (struct srtab
));
2446 gld_sr_dump(gld_mac_info_t
*macinfo
)
2449 struct srtab
**sr_hash_tbl
;
2452 sr_hash_tbl
= GLD_SR_HASH(macinfo
);
2453 if (sr_hash_tbl
== NULL
)
2456 mutex_enter(GLD_SR_MUTEX(macinfo
));
2459 * Walk through the table, printing all entries
2461 cmn_err(CE_NOTE
, "GLD Source Routing Table (0x%p):", (void *)macinfo
);
2462 cmn_err(CE_CONT
, "Addr len,rt,dir,mtu,res rng,brg0 rng,brg1...\n");
2463 for (i
= 0; i
< SR_HASH_SIZE
; i
++) {
2464 for (sr
= sr_hash_tbl
[i
]; sr
; sr
= sr
->sr_next
) {
2466 "%x:%x:%x:%x:%x:%x %d,%x,%x,%x,%x ",
2467 sr
->sr_mac
[0], sr
->sr_mac
[1], sr
->sr_mac
[2],
2468 sr
->sr_mac
[3], sr
->sr_mac
[4], sr
->sr_mac
[5],
2469 sr
->sr_ri
.len
, sr
->sr_ri
.rt
, sr
->sr_ri
.dir
,
2470 sr
->sr_ri
.mtu
, sr
->sr_ri
.res
);
2472 for (j
= 0; j
< (sr
->sr_ri
.len
- 2) / 2; j
++)
2473 cmn_err(CE_CONT
, "%x ",
2474 REF_NET_USHORT(*(unsigned short *)
2476 cmn_err(CE_CONT
, "\n");
2480 mutex_exit(GLD_SR_MUTEX(macinfo
));