xref: /onnv-gate/usr/src/uts/common/io/aggr/aggr_recv.c (revision 8275:7c223a798022)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51537Snd99603  * Common Development and Distribution License (the "License").
61537Snd99603  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
225895Syz147064  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * IEEE 802.3ad Link Aggregation - Receive
280Sstevel@tonic-gate  *
290Sstevel@tonic-gate  * Implements the collector function.
300Sstevel@tonic-gate  * Manages the RX resources exposed by a link aggregation group.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <sys/sysmacros.h>
340Sstevel@tonic-gate #include <sys/ddi.h>
350Sstevel@tonic-gate #include <sys/sunddi.h>
360Sstevel@tonic-gate #include <sys/strsun.h>
370Sstevel@tonic-gate #include <sys/strsubr.h>
380Sstevel@tonic-gate #include <sys/byteorder.h>
390Sstevel@tonic-gate #include <sys/aggr.h>
400Sstevel@tonic-gate #include <sys/aggr_impl.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate static void
aggr_mac_rx(mac_handle_t lg_mh,mac_resource_handle_t mrh,mblk_t * mp)43*8275SEric Cheng aggr_mac_rx(mac_handle_t lg_mh, mac_resource_handle_t mrh, mblk_t *mp)
44*8275SEric Cheng {
45*8275SEric Cheng 	if (mrh == NULL) {
46*8275SEric Cheng 		mac_rx(lg_mh, mrh, mp);
47*8275SEric Cheng 	} else {
48*8275SEric Cheng 		aggr_pseudo_rx_ring_t	*ring = (aggr_pseudo_rx_ring_t *)mrh;
49*8275SEric Cheng 		mac_rx_ring(lg_mh, ring->arr_rh, mp, ring->arr_gen);
50*8275SEric Cheng 	}
51*8275SEric Cheng }
52*8275SEric Cheng 
53*8275SEric Cheng void
aggr_recv_lacp(aggr_port_t * port,mac_resource_handle_t mrh,mblk_t * mp)54*8275SEric Cheng aggr_recv_lacp(aggr_port_t *port, mac_resource_handle_t mrh, mblk_t *mp)
550Sstevel@tonic-gate {
560Sstevel@tonic-gate 	aggr_grp_t *grp = port->lp_grp;
570Sstevel@tonic-gate 
585895Syz147064 	/* in promiscuous mode, send copy of packet up */
590Sstevel@tonic-gate 	if (grp->lg_promisc) {
600Sstevel@tonic-gate 		mblk_t *nmp = copymsg(mp);
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 		if (nmp != NULL)
63*8275SEric Cheng 			aggr_mac_rx(grp->lg_mh, mrh, nmp);
640Sstevel@tonic-gate 	}
650Sstevel@tonic-gate 
66*8275SEric Cheng 	aggr_lacp_rx_enqueue(port, mp);
670Sstevel@tonic-gate }
680Sstevel@tonic-gate 
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate  * Callback function invoked by MAC service module when packets are
710Sstevel@tonic-gate  * made available by a MAC port.
720Sstevel@tonic-gate  */
73*8275SEric Cheng /* ARGSUSED */
740Sstevel@tonic-gate void
aggr_recv_cb(void * arg,mac_resource_handle_t mrh,mblk_t * mp,boolean_t loopback)75*8275SEric Cheng aggr_recv_cb(void *arg, mac_resource_handle_t mrh, mblk_t *mp,
76*8275SEric Cheng     boolean_t loopback)
770Sstevel@tonic-gate {
780Sstevel@tonic-gate 	aggr_port_t *port = (aggr_port_t *)arg;
790Sstevel@tonic-gate 	aggr_grp_t *grp = port->lp_grp;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	if (grp->lg_lacp_mode == AGGR_LACP_OFF) {
82*8275SEric Cheng 		aggr_mac_rx(grp->lg_mh, mrh, mp);
830Sstevel@tonic-gate 	} else {
840Sstevel@tonic-gate 		mblk_t *cmp, *last, *head;
850Sstevel@tonic-gate 		struct ether_header *ehp;
860Sstevel@tonic-gate 		uint16_t sap;
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 		/* filter out slow protocol packets (LACP & Marker) */
890Sstevel@tonic-gate 		last = NULL;
900Sstevel@tonic-gate 		head = cmp = mp;
910Sstevel@tonic-gate 		while (cmp != NULL) {
920Sstevel@tonic-gate 			if (MBLKL(cmp) < sizeof (struct ether_header)) {
930Sstevel@tonic-gate 				/* packet too short */
940Sstevel@tonic-gate 				if (head == cmp) {
950Sstevel@tonic-gate 					/* no packets accumulated */
960Sstevel@tonic-gate 					head = cmp->b_next;
970Sstevel@tonic-gate 					cmp->b_next = NULL;
980Sstevel@tonic-gate 					freemsg(cmp);
990Sstevel@tonic-gate 					cmp = head;
1000Sstevel@tonic-gate 				} else {
1010Sstevel@tonic-gate 					/* send up accumulated packets */
1020Sstevel@tonic-gate 					last->b_next = NULL;
103*8275SEric Cheng 					if (port->lp_collector_enabled) {
104*8275SEric Cheng 						aggr_mac_rx(grp->lg_mh, mrh,
105*8275SEric Cheng 						    head);
106*8275SEric Cheng 					} else {
1071537Snd99603 						freemsgchain(head);
108*8275SEric Cheng 					}
1090Sstevel@tonic-gate 					head = cmp->b_next;
1100Sstevel@tonic-gate 					cmp->b_next = NULL;
1110Sstevel@tonic-gate 					freemsg(cmp);
1120Sstevel@tonic-gate 					cmp = head;
1130Sstevel@tonic-gate 					last = NULL;
1140Sstevel@tonic-gate 				}
1150Sstevel@tonic-gate 				continue;
1160Sstevel@tonic-gate 			}
1170Sstevel@tonic-gate 			ehp = (struct ether_header *)cmp->b_rptr;
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 			sap = ntohs(ehp->ether_type);
1200Sstevel@tonic-gate 			if (sap == ETHERTYPE_SLOW) {
1210Sstevel@tonic-gate 				/*
1220Sstevel@tonic-gate 				 * LACP or Marker packet. Send up pending
1230Sstevel@tonic-gate 				 * chain, and send LACP/Marker packet
1240Sstevel@tonic-gate 				 * to LACP subsystem.
1250Sstevel@tonic-gate 				 */
1260Sstevel@tonic-gate 				if (head == cmp) {
1270Sstevel@tonic-gate 					/* first packet of chain */
1280Sstevel@tonic-gate 					ASSERT(last == NULL);
1290Sstevel@tonic-gate 					head = cmp->b_next;
1300Sstevel@tonic-gate 					cmp->b_next = NULL;
131*8275SEric Cheng 					aggr_recv_lacp(port, mrh, cmp);
1320Sstevel@tonic-gate 					cmp = head;
1330Sstevel@tonic-gate 				} else {
1340Sstevel@tonic-gate 					/* previously accumulated packets */
1350Sstevel@tonic-gate 					ASSERT(last != NULL);
1360Sstevel@tonic-gate 					/* send up non-LACP packets */
1370Sstevel@tonic-gate 					last->b_next = NULL;
138*8275SEric Cheng 					if (port->lp_collector_enabled) {
139*8275SEric Cheng 						aggr_mac_rx(grp->lg_mh, mrh,
140*8275SEric Cheng 						    head);
141*8275SEric Cheng 					} else {
1421537Snd99603 						freemsgchain(head);
143*8275SEric Cheng 					}
1440Sstevel@tonic-gate 					/* unlink and pass up LACP packets */
1450Sstevel@tonic-gate 					head = cmp->b_next;
1460Sstevel@tonic-gate 					cmp->b_next = NULL;
147*8275SEric Cheng 					aggr_recv_lacp(port, mrh, cmp);
1480Sstevel@tonic-gate 					cmp = head;
1490Sstevel@tonic-gate 					last = NULL;
1500Sstevel@tonic-gate 				}
1510Sstevel@tonic-gate 			} else {
1520Sstevel@tonic-gate 				last = cmp;
1530Sstevel@tonic-gate 				cmp = cmp->b_next;
1540Sstevel@tonic-gate 			}
1550Sstevel@tonic-gate 		}
1560Sstevel@tonic-gate 		if (head != NULL) {
1570Sstevel@tonic-gate 			if (port->lp_collector_enabled)
158*8275SEric Cheng 				aggr_mac_rx(grp->lg_mh, mrh, head);
1590Sstevel@tonic-gate 			else
1601537Snd99603 				freemsgchain(head);
1610Sstevel@tonic-gate 		}
1620Sstevel@tonic-gate 	}
1630Sstevel@tonic-gate }
164