xref: /onnv-gate/usr/src/uts/common/io/aggr/aggr_dev.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.
280Sstevel@tonic-gate  */
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <sys/conf.h>
310Sstevel@tonic-gate #include <sys/modctl.h>
320Sstevel@tonic-gate #include <sys/aggr.h>
330Sstevel@tonic-gate #include <sys/aggr_impl.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /* module description */
360Sstevel@tonic-gate #define	AGGR_LINKINFO	"Link Aggregation MAC"
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /* device info ptr, only one for instance 0 */
391804Sericheng dev_info_t *aggr_dip = NULL;
400Sstevel@tonic-gate 
410Sstevel@tonic-gate static int aggr_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
420Sstevel@tonic-gate static int aggr_attach(dev_info_t *, ddi_attach_cmd_t);
430Sstevel@tonic-gate static int aggr_detach(dev_info_t *, ddi_detach_cmd_t);
440Sstevel@tonic-gate 
45*8275SEric Cheng DDI_DEFINE_STREAM_OPS(aggr_dev_ops, nulldev, nulldev, aggr_attach, aggr_detach,
46*8275SEric Cheng     nodev, aggr_getinfo, D_MP, NULL, ddi_quiesce_not_supported);
47269Sericheng 
48269Sericheng static struct modldrv aggr_modldrv = {
49269Sericheng 	&mod_driverops,		/* Type of module.  This one is a driver */
50269Sericheng 	AGGR_LINKINFO,		/* short description */
51269Sericheng 	&aggr_dev_ops		/* driver specific ops */
52269Sericheng };
53269Sericheng 
54269Sericheng static struct modlinkage modlinkage = {
55*8275SEric Cheng 	MODREV_1, &aggr_modldrv, NULL
560Sstevel@tonic-gate };
570Sstevel@tonic-gate 
580Sstevel@tonic-gate int
_init(void)590Sstevel@tonic-gate _init(void)
600Sstevel@tonic-gate {
617408SSebastien.Roy@Sun.COM 	int	err;
627408SSebastien.Roy@Sun.COM 
637408SSebastien.Roy@Sun.COM 	mac_init_ops(&aggr_dev_ops, "aggr");
647408SSebastien.Roy@Sun.COM 	if ((err = mod_install(&modlinkage)) != 0)
657408SSebastien.Roy@Sun.COM 		mac_fini_ops(&aggr_dev_ops);
667408SSebastien.Roy@Sun.COM 	return (err);
670Sstevel@tonic-gate }
680Sstevel@tonic-gate 
690Sstevel@tonic-gate int
_fini(void)700Sstevel@tonic-gate _fini(void)
710Sstevel@tonic-gate {
727408SSebastien.Roy@Sun.COM 	int	err;
737408SSebastien.Roy@Sun.COM 
747408SSebastien.Roy@Sun.COM 	if ((err = mod_remove(&modlinkage)) == 0)
757408SSebastien.Roy@Sun.COM 		mac_fini_ops(&aggr_dev_ops);
767408SSebastien.Roy@Sun.COM 	return (err);
770Sstevel@tonic-gate }
780Sstevel@tonic-gate 
790Sstevel@tonic-gate int
_info(struct modinfo * modinfop)800Sstevel@tonic-gate _info(struct modinfo *modinfop)
810Sstevel@tonic-gate {
820Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
830Sstevel@tonic-gate }
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*ARGSUSED*/
860Sstevel@tonic-gate static int
aggr_getinfo(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)870Sstevel@tonic-gate aggr_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
880Sstevel@tonic-gate     void **result)
890Sstevel@tonic-gate {
900Sstevel@tonic-gate 	switch (infocmd) {
910Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
920Sstevel@tonic-gate 		*result = aggr_dip;
930Sstevel@tonic-gate 		return (DDI_SUCCESS);
940Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
957408SSebastien.Roy@Sun.COM 		*result = 0;
960Sstevel@tonic-gate 		return (DDI_SUCCESS);
970Sstevel@tonic-gate 	}
980Sstevel@tonic-gate 	return (DDI_FAILURE);
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate static int
aggr_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)1020Sstevel@tonic-gate aggr_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
1030Sstevel@tonic-gate {
1040Sstevel@tonic-gate 	switch (cmd) {
1050Sstevel@tonic-gate 	case DDI_ATTACH:
1060Sstevel@tonic-gate 		if (ddi_get_instance(dip) != 0) {
1070Sstevel@tonic-gate 			/* we only allow instance 0 to attach */
1080Sstevel@tonic-gate 			return (DDI_FAILURE);
1090Sstevel@tonic-gate 		}
1107408SSebastien.Roy@Sun.COM 		if (aggr_ioc_init() != 0)
1110Sstevel@tonic-gate 			return (DDI_FAILURE);
1120Sstevel@tonic-gate 		aggr_dip = dip;
1131804Sericheng 		aggr_port_init();
1141804Sericheng 		aggr_grp_init();
1151804Sericheng 		aggr_lacp_init();
1160Sstevel@tonic-gate 		return (DDI_SUCCESS);
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 	case DDI_RESUME:
1190Sstevel@tonic-gate 		return (DDI_SUCCESS);
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	default:
1220Sstevel@tonic-gate 		return (DDI_FAILURE);
1230Sstevel@tonic-gate 	}
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /*ARGSUSED*/
1270Sstevel@tonic-gate static int
aggr_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)1280Sstevel@tonic-gate aggr_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
1290Sstevel@tonic-gate {
1300Sstevel@tonic-gate 	switch (cmd) {
1310Sstevel@tonic-gate 	case DDI_DETACH:
132269Sericheng 		if (aggr_grp_count() > 0)
133269Sericheng 			return (DDI_FAILURE);
134269Sericheng 
1350Sstevel@tonic-gate 		aggr_dip = NULL;
1361804Sericheng 		aggr_port_fini();
1371804Sericheng 		aggr_grp_fini();
1381804Sericheng 		aggr_lacp_fini();
1397408SSebastien.Roy@Sun.COM 		aggr_ioc_fini();
1400Sstevel@tonic-gate 		return (DDI_SUCCESS);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	case DDI_SUSPEND:
1430Sstevel@tonic-gate 		return (DDI_SUCCESS);
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 	default:
1460Sstevel@tonic-gate 		return (DDI_FAILURE);
1470Sstevel@tonic-gate 	}
1480Sstevel@tonic-gate }
149