dls_vlan.c revision d62bc4badc1c1f1549c961cfb8b420e650e1272b
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Data-Link Services Module
*/
#include <sys/sysmacros.h>
#include <sys/dls_impl.h>
static kmem_cache_t *i_dls_vlan_cachep;
static mod_hash_t *i_dls_vlan_hash;
static mod_hash_t *i_dls_vlan_dev_hash;
static krwlock_t i_dls_vlan_lock;
static uint_t i_dls_vlan_count;
/*
* Private functions.
*/
/*ARGSUSED*/
static int
{
return (0);
}
/*ARGSUSED*/
static void
{
}
/*
* Module initialization functions.
*/
void
dls_vlan_init(void)
{
/*
* Create a kmem_cache of dls_vlan_t structures.
*/
sizeof (dls_vlan_t), 0, i_dls_vlan_constructor,
/*
* Create a hash table, keyed by dv_spa, of dls_vlan_t.
*/
/*
* Create a hash table, keyed by dv_dev, of dls_vlan_t.
*/
i_dls_vlan_count = 0;
}
int
dls_vlan_fini(void)
{
if (i_dls_vlan_count > 0)
return (EBUSY);
/*
* Destroy the hash table
*/
/*
* Destroy the kmem_cache.
*/
return (0);
}
/*
* Exported functions.
*/
/*
* If vid is VLAN_ID_NONE, then the minor_t to access this dls_vlan_t is
* ppa + 1, otherwise, we need to allocate the minor_t in this function.
*
* If ppa is greater than DLS_MAX_PPA, it means that we do not need to create
* the VLAN minor node for this MAC, as this MAC is (a) a legacy device, (b)
* an aggr created without the "key" argument, or (c) a new type of link
* whose ppa is allocated by mac_minor_hold() in mac_register().
*/
int
{
char node[MAXPATHLEN];
char *driver;
int ppa;
int err = 0;
return (err);
/*
* First check whether VLANs are able to be created on this MAC.
*/
if (vid != VLAN_ID_NONE) {
return (EINVAL);
}
if (!force &&
return (err);
}
}
/*
* Get a reference to a dls_link_t representing the MAC. This call
* will create one if necessary.
*/
return (err);
}
/*
* Try to find this VLAN in i_dls_vlan_hash first. The spa
*/
goto fail;
}
if (vid == VLAN_ID_NONE) {
/*
* Derives minor number directly from non-VLAN link's PPA.
*/
/*
* Allocate minor number from minor_arenap for VLANs.
*/
goto fail;
}
/*
* First create its minor node for non-legacy links, including VLANs
* and non-VLANs. This is for /dev nodes backward compatibility.
*/
/* Create a style-1 DLPI device */
DDI_NT_NET, 0) != DDI_SUCCESS) {
goto fail;
}
}
dvp->dv_zone_ref = 0;
/*
* Hold the underlying MAC for VLANs to keep the margin request.
* We cannot hold the mac for non-VLANs, because a reference would
* prevent the device from detaching.
*/
if (vid != VLAN_ID_NONE)
return (0);
fail:
return (err);
}
int
{
int err;
/*
* Try to find this VLAN in i_dls_vlan_hash first. The spa
*/
return (ENOENT);
}
/*
* Check to see if it is referenced by any dls_impl_t.
*/
return (EBUSY);
}
/*
* Remove and destroy the hash table entry.
*/
char node[MAXPATHLEN];
char *driver;
/*
* Remove the minor nodes for this link.
*/
}
ASSERT(i_dls_vlan_count > 0);
if (vid != VLAN_ID_NONE) {
}
}
/*
* Release minor to dls_minor_arenap for VLANs
*/
if (vid != VLAN_ID_NONE)
/*
* Release the dls_link_t. This will destroy the dls_link_t and
* release the MAC if there are no more dls_vlan_t.
*/
return (0);
}
int
{
int err = 0;
return (ENOENT);
}
return (err);
/*
* At this point someone else could do a dls_vlan_hold and
* dls_vlan_rele on this new vlan and causes it to be
* destroyed. This will at worst cause us to spin a few
* times.
*/
goto again;
}
if (vlan_created)
return (err);
}
return (0);
}
int
{
int err;
(mod_hash_val_t *)&dvp)) != 0) {
return (ENOENT);
}
return (err);
}
return (0);
}
/*
* Free the dvp if this is a VLAN and this is the last reference.
*/
void
{
char macname[MAXNAMELEN];
return;
}
}
if (destroy_vlan)
}
int
{
int err;
return (err);
goto done;
}
/*
* Check whether this dvp is used by its own zones, if yes,
* we cannot change its zoneid.
*/
if (dvp->dv_zone_ref != 0) {
goto done;
}
if (zid == GLOBAL_ZONEID) {
/*
* Move the link from the local zone to the global zone,
* and release the reference to this link. At the same time
* reset the link's active state so that an aggregation is
* allowed to be created over it.
*/
goto done;
} else if (old_zid == GLOBAL_ZONEID) {
/*
* Move the link from the global zone to the local zone,
* and hold a reference to this link. Also, set the link
* to the "active" state so that the global zone is
* not able to create an aggregation over this link.
* TODO: revisit once we allow creating aggregations
* within a local zone.
*/
goto done;
}
return (0);
} else {
/*
* Move the link from a local zone to another local zone.
*/
}
done:
return (err);
}
/*
* Find dev_info_t based on the minor node of the link.
*/
{
return (NULL);
return (dip);
}