1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * IEEE 802.3ad Link Aggregation. 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <sys/types.h> 34*0Sstevel@tonic-gate #include <sys/sysmacros.h> 35*0Sstevel@tonic-gate #include <sys/conf.h> 36*0Sstevel@tonic-gate #include <sys/cmn_err.h> 37*0Sstevel@tonic-gate #include <sys/list.h> 38*0Sstevel@tonic-gate #include <sys/ksynch.h> 39*0Sstevel@tonic-gate #include <sys/kmem.h> 40*0Sstevel@tonic-gate #include <sys/stream.h> 41*0Sstevel@tonic-gate #include <sys/modctl.h> 42*0Sstevel@tonic-gate #include <sys/ddi.h> 43*0Sstevel@tonic-gate #include <sys/sunddi.h> 44*0Sstevel@tonic-gate #include <sys/atomic.h> 45*0Sstevel@tonic-gate #include <sys/stat.h> 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate #include <sys/aggr.h> 48*0Sstevel@tonic-gate #include <sys/aggr_impl.h> 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate /* module description */ 51*0Sstevel@tonic-gate #define AGGR_LINKINFO "Link Aggregation MAC" 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate /* device info ptr, only one for instance 0 */ 54*0Sstevel@tonic-gate dev_info_t *aggr_dip; 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate static void aggr_dev_init(void); 57*0Sstevel@tonic-gate static int aggr_dev_fini(void); 58*0Sstevel@tonic-gate static int aggr_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **); 59*0Sstevel@tonic-gate static int aggr_attach(dev_info_t *, ddi_attach_cmd_t); 60*0Sstevel@tonic-gate static int aggr_detach(dev_info_t *, ddi_detach_cmd_t); 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate static struct cb_ops aggr_cb_ops = { 63*0Sstevel@tonic-gate aggr_open, /* open */ 64*0Sstevel@tonic-gate aggr_close, /* close */ 65*0Sstevel@tonic-gate nulldev, /* strategy */ 66*0Sstevel@tonic-gate nulldev, /* print */ 67*0Sstevel@tonic-gate nodev, /* dump */ 68*0Sstevel@tonic-gate nodev, /* read */ 69*0Sstevel@tonic-gate nodev, /* write */ 70*0Sstevel@tonic-gate aggr_ioctl, /* ioctl */ 71*0Sstevel@tonic-gate nodev, /* devmap */ 72*0Sstevel@tonic-gate nodev, /* mmap */ 73*0Sstevel@tonic-gate nodev, /* segmap */ 74*0Sstevel@tonic-gate nochpoll, /* poll */ 75*0Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 76*0Sstevel@tonic-gate 0, /* streamtab */ 77*0Sstevel@tonic-gate D_NEW | D_MP /* driver compatibility flag */ 78*0Sstevel@tonic-gate }; 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate static struct dev_ops aggr_ops = { 81*0Sstevel@tonic-gate DEVO_REV, /* devo_rev */ 82*0Sstevel@tonic-gate 0, /* refcnt */ 83*0Sstevel@tonic-gate aggr_getinfo, /* getinfo */ 84*0Sstevel@tonic-gate nulldev, /* identify */ 85*0Sstevel@tonic-gate nulldev, /* probe */ 86*0Sstevel@tonic-gate aggr_attach, /* attach */ 87*0Sstevel@tonic-gate aggr_detach, /* detach */ 88*0Sstevel@tonic-gate nodev, /* reset */ 89*0Sstevel@tonic-gate &aggr_cb_ops, /* driver operations */ 90*0Sstevel@tonic-gate NULL, /* bus operations */ 91*0Sstevel@tonic-gate nodev /* dev power */ 92*0Sstevel@tonic-gate }; 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate static struct modldrv modldrv = { 95*0Sstevel@tonic-gate &mod_driverops, 96*0Sstevel@tonic-gate AGGR_LINKINFO, 97*0Sstevel@tonic-gate &aggr_ops 98*0Sstevel@tonic-gate }; 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate static struct modlinkage modlinkage = { 101*0Sstevel@tonic-gate MODREV_1, 102*0Sstevel@tonic-gate &modldrv, 103*0Sstevel@tonic-gate NULL 104*0Sstevel@tonic-gate }; 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate int 107*0Sstevel@tonic-gate _init(void) 108*0Sstevel@tonic-gate { 109*0Sstevel@tonic-gate int err; 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate aggr_dev_init(); 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate if ((err = mod_install(&modlinkage)) != 0) { 114*0Sstevel@tonic-gate (void) aggr_dev_fini(); 115*0Sstevel@tonic-gate return (err); 116*0Sstevel@tonic-gate } 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate aggr_dip = NULL; 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate return (0); 121*0Sstevel@tonic-gate } 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate int 124*0Sstevel@tonic-gate _fini(void) 125*0Sstevel@tonic-gate { 126*0Sstevel@tonic-gate int err; 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate if ((err = aggr_dev_fini()) != 0) 129*0Sstevel@tonic-gate return (err); 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate if ((err = mod_remove(&modlinkage)) != 0) { 132*0Sstevel@tonic-gate aggr_dev_init(); 133*0Sstevel@tonic-gate return (err); 134*0Sstevel@tonic-gate } 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate return (0); 137*0Sstevel@tonic-gate } 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate int 140*0Sstevel@tonic-gate _info(struct modinfo *modinfop) 141*0Sstevel@tonic-gate { 142*0Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 143*0Sstevel@tonic-gate } 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate static void 146*0Sstevel@tonic-gate aggr_dev_init(void) 147*0Sstevel@tonic-gate { 148*0Sstevel@tonic-gate aggr_port_init(); 149*0Sstevel@tonic-gate aggr_grp_init(); 150*0Sstevel@tonic-gate } 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate static int 153*0Sstevel@tonic-gate aggr_dev_fini(void) 154*0Sstevel@tonic-gate { 155*0Sstevel@tonic-gate int err; 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate if ((err = aggr_grp_fini()) != 0) 158*0Sstevel@tonic-gate return (err); 159*0Sstevel@tonic-gate if ((err = aggr_port_fini()) != 0) { 160*0Sstevel@tonic-gate /* 161*0Sstevel@tonic-gate * re-initialize the groups to keep a consistent 162*0Sstevel@tonic-gate * state. 163*0Sstevel@tonic-gate */ 164*0Sstevel@tonic-gate aggr_grp_init(); 165*0Sstevel@tonic-gate } 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate return (err); 168*0Sstevel@tonic-gate } 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate /*ARGSUSED*/ 171*0Sstevel@tonic-gate static int 172*0Sstevel@tonic-gate aggr_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, 173*0Sstevel@tonic-gate void **result) 174*0Sstevel@tonic-gate { 175*0Sstevel@tonic-gate switch (infocmd) { 176*0Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 177*0Sstevel@tonic-gate *result = aggr_dip; 178*0Sstevel@tonic-gate return (DDI_SUCCESS); 179*0Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 180*0Sstevel@tonic-gate *result = NULL; 181*0Sstevel@tonic-gate return (DDI_SUCCESS); 182*0Sstevel@tonic-gate } 183*0Sstevel@tonic-gate return (DDI_FAILURE); 184*0Sstevel@tonic-gate } 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate static int 187*0Sstevel@tonic-gate aggr_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 188*0Sstevel@tonic-gate { 189*0Sstevel@tonic-gate switch (cmd) { 190*0Sstevel@tonic-gate case DDI_ATTACH: 191*0Sstevel@tonic-gate if (ddi_get_instance(dip) != 0) { 192*0Sstevel@tonic-gate /* we only allow instance 0 to attach */ 193*0Sstevel@tonic-gate return (DDI_FAILURE); 194*0Sstevel@tonic-gate } 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate /* create minor node for control interface */ 197*0Sstevel@tonic-gate if (ddi_create_minor_node(dip, AGGR_DEVNAME_CTL, S_IFCHR, 198*0Sstevel@tonic-gate AGGR_MINOR_CTL, DDI_PSEUDO, 0) != DDI_SUCCESS) { 199*0Sstevel@tonic-gate return (DDI_FAILURE); 200*0Sstevel@tonic-gate } 201*0Sstevel@tonic-gate 202*0Sstevel@tonic-gate aggr_dip = dip; 203*0Sstevel@tonic-gate return (DDI_SUCCESS); 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gate case DDI_RESUME: 206*0Sstevel@tonic-gate return (DDI_SUCCESS); 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate default: 209*0Sstevel@tonic-gate return (DDI_FAILURE); 210*0Sstevel@tonic-gate } 211*0Sstevel@tonic-gate } 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate /*ARGSUSED*/ 214*0Sstevel@tonic-gate static int 215*0Sstevel@tonic-gate aggr_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 216*0Sstevel@tonic-gate { 217*0Sstevel@tonic-gate switch (cmd) { 218*0Sstevel@tonic-gate case DDI_DETACH: 219*0Sstevel@tonic-gate aggr_dip = NULL; 220*0Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 221*0Sstevel@tonic-gate 222*0Sstevel@tonic-gate return (DDI_SUCCESS); 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate case DDI_SUSPEND: 225*0Sstevel@tonic-gate return (DDI_SUCCESS); 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate default: 228*0Sstevel@tonic-gate return (DDI_FAILURE); 229*0Sstevel@tonic-gate } 230*0Sstevel@tonic-gate } 231