softmac_main.c revision 050fb0165f0d6a5cc81c5509d8375f2340d96f73
/*
* 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"
/*
* The softmac driver is used to "unify" non-GLDv3 drivers to the GLDv3
* framework. It also creates the kernel datalink structure for each
* physical network device.
*
* Specifically, a softmac will be created for each physical network device
* (dip) during the device's post-attach process. When this softmac is
* created, the following will also be done:
* - create the device's <link name, linkid> mapping;
* - register the mac if this is a non-GLDv3 device and the media type is
* supported by the GLDv3 framework;
* - create the kernel data-link structure for this physical device;
*
* This softmac will be destroyed during the device's pre-detach process,
* and all the above will be undone.
*/
#include <sys/sysmacros.h>
#include <sys/softmac_impl.h>
/*
* Softmac hash table including softmacs for both style-2 and style-1 devices.
*/
static krwlock_t softmac_hash_lock;
static mod_hash_t *softmac_hash;
#define SOFTMAC_HASHSZ 64
static void softmac_mac_register(void *);
static int softmac_create_datalink(softmac_t *);
static int softmac_m_start(void *);
static void softmac_m_stop(void *);
static int softmac_m_open(void *);
static void softmac_m_close(void *);
#define SOFTMAC_M_CALLBACK_FLAGS \
static mac_callbacks_t softmac_m_callbacks = {
};
void
{
}
void
{
}
/* ARGSUSED */
static uint_t
{
return (MH_WALK_TERMINATE);
}
{
return (exist);
}
/*
* This function is called for each minor node during the post-attach of
* each DDI_NT_NET device instance. Note that it is possible that a device
* instance has two minor nodes (DLPI style-1 and style-2), so that for that
* specific device, softmac_create() could be called twice.
*
* A softmac_t is used to track each DDI_NT_NET device, and a softmac_dev_t
* is created to track each minor node.
*
* For each minor node of a legacy device, a taskq is started to finish
* softmac_mac_register(), which will finish the rest of work (see comments
* above softmac_mac_register()).
*/
int
{
char devname[MAXNAMELEN];
int index;
/*
* Force the softmac driver to be attached.
*/
return (ENXIO);
}
/*
* We expect legacy devices have at most two minor nodes - one style-1
* and one style-2.
*/
devname);
return (ENOTSUP);
}
/*
* Check whether the softmac for the specified device already exists
*/
(mod_hash_val_t *)&softmac)) != 0) {
/*
* Insert the softmac into the hash table.
*/
}
if (softmac->smac_attachok_cnt == 0) {
/*
* Initialize the softmac if this is the post-attach of the
* first minor node.
*/
softmac->smac_flags = 0;
/*
* Note that for GLDv3 devices, we create devfs minor nodes
* for VLANs as well. Assume a GLDv3 driver on which only
* a VLAN is created. During the detachment of this device
* instance, the following would happen:
* a. the pre-detach callback softmac_destroy() succeeds.
* Because the physical link itself is not in use,
* softmac_destroy() succeeds and destroys softmac_t;
* b. the device detach fails in mac_unregister() because
* this MAC is still used by a VLAN.
* c. the post-attach callback is then called which leads
* us here. Note that ddi_minor_node_count() returns 3
* (including the minior node of the VLAN). In that case,
* we must correct the minor node count to 2 as that is
* the count of minor nodes that go through post-attach.
*/
} else {
}
}
/*
* This is possible if the post_attach() is called:
*
* a. after pre_detach() fails.
*
* b. for a new round of reattachment. Note that DACF will not
* call pre_detach() for successfully post_attached minor
* nodes even when the post-attach failed after all.
*
* Both seem to be defects in the DACF framework. To work
* around it and only clear the SOFTMAC_ATTACH_DONE flag for
* the b case, a smac_attached_left field is used to tell
* the two cases apart.
*/
if (softmac->smac_attached_left != 0)
/* case a */
/* case b */
}
return (0);
}
/*
* Inform dlmgmtd of this link so that softmac_hold_device() is able
* to know the existence of this link. This could fail if dlmgmtd
* is not yet started.
*/
/*
* No lock is needed for access this softmac pointer, as pre-detach and
* post-attach won't happen at the same time.
*/
/*
* Continue to register the mac and create the datalink only when all
* the minor nodes are attached.
*/
return (0);
}
/*
* Note that this function could be called as a result of
* a open() system call, and spec_open() already locked the
* snode (SLOCKED is set). Therefore, we must start a
* taskq to finish the rest of work to sidestep the risk
* that our ldi_open_by_dev() call would again try to hold
* the same lock.
*
* If all the minor nodes have been attached, start the taskq
* to finish the rest of the work.
*/
return (0);
}
goto done;
/*
* We can safely release the reference on the mac because
* this mac will only be unregistered and destroyed when
* the device detaches, and the softmac will be destroyed
* before then (in the pre-detach routine of the device).
*/
/*
* Create the GLDv3 datalink for this mac.
*/
done:
if (err != 0) {
}
return (err);
}
static boolean_t
{
return (B_FALSE);
switch (cap) {
case MAC_CAPAB_HCKSUM: {
break;
}
case MAC_CAPAB_LEGACY: {
break;
}
/*
* For the capabilities below, there's nothing for us to fill in;
* simply return B_TRUE if we support it.
*/
case MAC_CAPAB_NO_ZCOPY:
case MAC_CAPAB_POLL:
case MAC_CAPAB_NO_NATIVEVLAN:
default:
break;
}
return (B_TRUE);
}
static int
{
int err;
}
/*
* There is a link name conflict. Either:
*
* - An existing link with the same device name with a
* different media type from of the given type.
* Mark this link back to persistent only; or
*
* - We cannot assign the "suggested" name because
* GLDv3 and therefore vanity naming is not supported
* for this link type. Delete this link's <link name,
* linkid> mapping.
*/
"existing %s device %s.",
} else {
}
}
return (err);
}
/*
* This function:
* 1. provides the link's media type to dlmgmtd.
* 2. creates the GLDv3 datalink if the media type is supported by GLDv3.
*/
static int
{
int err;
/*
* First provide the media type of the physical link to dlmgmtd.
*
* If the new <linkname, linkid> mapping operation failed with EBADF
* or ENOENT, it might because the dlmgmtd was not started in time
* (e.g., diskless boot); ignore the failure and continue. The
* mapping will be recreated once the daemon has started.
*/
return (err);
}
/*
* Create the GLDv3 datalink.
*/
return (err);
}
if (linkid == DATALINK_INVALID_LINKID)
return (0);
}
/*
* This function is only called for legacy devices. It:
* 1. registers the MAC for the legacy devices whose media type is supported
* by the GLDv3 framework.
* 2. creates the GLDv3 datalink if the media type is supported by GLDv3.
*/
static void
softmac_mac_register(void *arg)
{
int index;
int err;
/*
* Note that we do not need any locks to access this softmac pointer,
* as softmac_destroy() will wait until this function is called.
*/
goto done;
}
/*
* Determine whether this legacy device support VLANs by opening
* the style-2 device node (if it exists) and attaching to a VLAN
* PPA (1000 + ppa).
*/
if (err == 0) {
}
int rval;
continue;
li) != 0) {
continue;
}
/*
* Pop all the intermediate modules in order to negotiate
* capabilities correctly.
*/
;
/* DLPI style-1 or DLPI style-2? */
"DL_ERROR_ACK to DL_INFO_ACK; "
"DLPI errno 0x%x, UNIX errno %d",
}
continue;
}
/*
* Currently only DL_ETHER has GLDv3 mac plugin support.
* For media types that GLDv3 does not support, create a
* link id for it.
*/
err = 0;
break;
}
continue;
}
"DL_ERROR_ACK to DL_BIND_ACK; "
"DLPI errno 0x%x, UNIX errno %d",
}
continue;
}
/*
* Call dl_info() after dl_bind() because some drivers only
* provide correct information (e.g. MAC address) once bound.
*/
"DL_ERROR_ACK to DL_INFO_ACK; "
"DLPI errno 0x%x, UNIX errno %d",
}
continue;
}
(dlia.dl_brdcst_addr_offset == 0)) {
continue;
}
/*
* Check other DLPI capabilities. Note that this must be after
* dl_bind() because some drivers return DL_ERROR_ACK if the
* stream is not bound. It is also before mac_register(), so
* we don't need any lock protection here.
*
* Softmac always supports POLL.
*/
/*
* Check the margin of the underlying driver.
*/
margin = 0;
softmac->smac_margin = 0;
&rval) == 0) {
}
/*
* If the legacy driver doesn't support DLIOCMARGININFO, but
* it can support native VLAN, correct its margin value to 4.
*/
if (native_vlan) {
if (softmac->smac_margin == 0)
} else {
}
/*
* Not all drivers support DL_NOTIFY_REQ, so ignore ENOTSUP.
*/
softmac->smac_notifications = 0;
case 0:
break;
case ENOTSUP:
break;
default:
continue;
}
err = 0;
break;
}
if (err != 0)
goto done;
/*
* Finally, we're ready to register ourselves with the MAC layer
* interface; if this succeeds, we're all ready to start()
*/
goto done;
}
if (err != 0) {
goto done;
}
}
/*
* Try to create the datalink for this softmac.
*/
}
}
done:
}
int
{
char devname[MAXNAMELEN];
int index;
(mod_hash_val_t *)&softmac);
/*
* Fail the predetach routine if this softmac is in-use.
*/
if (softmac->smac_hold_cnt != 0) {
return (EBUSY);
}
/*
* Even if the predetach of one minor node has already failed
* (smac_attached_left is not 0), the DACF framework will continue
* to call the predetach routines of the other minor nodes,
* so we fail these calls here.
*/
if (softmac->smac_attached_left != 0) {
return (EBUSY);
}
goto done;
/*
* This is the detach for the first minor node. Wait until all the
* minor nodes are attached.
*/
&linkid)) != 0) {
goto done;
}
}
/*
* If softmac_mac_register() succeeds in registering the mac
* of the legacy device, unregister it.
*/
linkid);
goto done;
}
}
}
done:
if (err == 0) {
/*
* Free softmac_dev
*/
if (--softmac->smac_attachok_cnt == 0) {
(mod_hash_val_t *)&hashval);
return (0);
}
} else {
}
return (err);
}
/*
* This function is called as the result of a newly started dlmgmtd daemon.
*
* We walk through every softmac that was created but failed to notify
* dlmgmtd about it (whose SOFTMAC_NEED_RECREATE flag is set). This occurs
* when softmacs are created before dlmgmtd is ready. For example, during
* diskless boot, a network device is used (and therefore attached) before
* the datalink-management service starts dlmgmtd.
*/
/* ARGSUSED */
static uint_t
{
int err;
/*
* Wait for softmac_create() and softmac_mac_register() to exit.
*/
if ((softmac->smac_attacherr != 0) ||
return (MH_WALK_CONTINUE);
}
return (MH_WALK_CONTINUE);
}
return (MH_WALK_CONTINUE);
}
/*
* Create a link for this MAC. The link name will be the same
* as the MAC name.
*/
if (err != 0) {
"%s (linkid %d) failed (%d)",
}
}
return (MH_WALK_CONTINUE);
}
/*
* See comments above softmac_mac_recreate().
*/
void
{
/*
* Walk through the softmac_hash table. Request to create the
* [link name, linkid] mapping if we failed to do so.
*/
}
/* ARGSUSED */
static int
softmac_m_start(void *arg)
{
return (0);
}
/* ARGSUSED */
static void
softmac_m_stop(void *arg)
{
}
/*
* Set up the lower stream above the legacy device which is shared by
* GLDv3 MAC clients. Put the lower stream into DLIOCRAW mode to send
* and receive the raw data. Further, put the lower stream into
* DL_PROMISC_SAP mode to receive all packets of interest.
*/
static int
{
return (err);
if (err != 0)
goto done;
/*
* Pop all the intermediate modules. The autopushed modules will
* be pushed when the softmac node is opened.
*/
;
goto done;
}
/*
*/
goto done;
/*
* Then push the softmac shim layer atop the lower stream.
*/
goto done;
}
/*
* Send the ioctl to get the slp pointer.
*/
goto done;
}
/*
* Bind to SAP 2 on token ring, 0 on other interface types.
* (SAP 0 has special significance on token ring).
* Note that the receive-side packets could come anytime after bind.
*/
else
if (err != 0)
goto done;
/*
* Put the lower stream into DL_PROMISC_SAP mode to receive all
* packets of interest.
*
* Some drivers (e.g. the old legacy eri driver) incorrectly pass up
* packets to DL_PROMISC_SAP stream when the lower stream is not bound,
* so we send DL_PROMISON_REQ after DL_BIND_REQ.
*/
goto done;
/*
* Enable the capabilities the underlying driver claims to support.
* Some drivers require this to be called after the stream is bound.
*/
goto done;
/*
* Send the DL_NOTIFY_REQ to enable certain DL_NOTIFY_IND.
* We don't have to wait for the ack.
*/
(void) softmac_send_notify_req(slp,
done:
if (err != 0)
return (err);
}
static int
softmac_m_open(void *arg)
{
int err;
goto done;
return (err);
done:
return (0);
}
static void
softmac_m_close(void *arg)
{
/*
* Note that slp is destroyed when lh is closed.
*/
}
int
{
char devname[MAXNAMELEN];
return (ENOENT);
/*
* First try to hold this device instance to force the MAC
* to be registered.
*/
return (ENOENT);
return (ENOENT);
}
/*
* This is a network device; wait for its softmac to be registered.
*/
(mod_hash_val_t *)&softmac) != 0) {
/*
* This is rare but possible. It could happen when pre-detach
* routine of the device succeeds. But the softmac will then
* be recreated when device fails to detach (as this device
* is held).
*/
goto again;
}
/*
* Bump smac_hold_cnt to prevent device detach.
*/
softmac->smac_hold_cnt++;
/*
* Wait till the device is fully attached.
*/
softmac->smac_hold_cnt--;
else
return (err);
}
void
{
return;
softmac->smac_hold_cnt--;
}