mac_client.c revision 10a404923096d60a26c785c3cee15a5c364d51c0
/*
* 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 (c) 2014, Joyent, Inc. All rights reserved.
*/
/*
* - General Introduction:
*
* This file contains the implementation of the MAC client kernel
* API and related code. The MAC client API allows a kernel module
* to gain access to a MAC instance (physical NIC, link aggregation, etc).
* It allows a MAC client to associate itself with a MAC address,
* VLANs, callback functions for data traffic and for promiscuous mode.
* The MAC client API is also used to specify the properties associated
* with a MAC client, such as bandwidth limits, priority, CPUS, etc.
* These properties are further used to determine the hardware resources
* to allocate to the various MAC clients.
*
* - Primary MAC clients:
*
* The MAC client API refers to "primary MAC clients". A primary MAC
* client is a client which "owns" the primary MAC address of
* the underlying MAC instance. The primary MAC address is called out
* since it is associated with specific semantics: the primary MAC
* address is the MAC address which is assigned to the IP interface
* when it is plumbed, and the primary MAC address is assigned
* to VLAN data-links. The primary address of a MAC instance can
* also change dynamically from under the MAC client, for example
* as a result of a change of state of a link aggregation. In that
* case the MAC layer automatically updates all data-structures which
* refer to the current value of the primary MAC address. Typical
* primary MAC clients are dls, aggr, and xnb. A typical non-primary
* MAC client is the vnic driver.
*
* - Virtual Switching:
*
* The MAC layer implements a virtual switch between the MAC clients
* (primary and non-primary) defined on top of the same underlying
* NIC (physical, link aggregation, etc). The virtual switch is
* VLAN-aware, i.e. it allows multiple MAC clients to be member
* of one or more VLANs, and the virtual switch will distribute
* multicast tagged packets only to the member of the corresponding
* VLANs.
*
* - Upper vs Lower MAC:
*
* Creating a VNIC on top of a MAC instance effectively causes
* two MAC instances to be layered on top of each other, one for
* the VNIC(s), one for the underlying MAC instance (physical NIC,
* link aggregation, etc). In the code below we refer to the
* underlying NIC as the "lower MAC", and we refer to VNICs as
* the "upper MAC".
*
* - Pass-through for VNICs:
*
* When VNICs are created on top of an underlying MAC, this causes
* a layering of two MAC instances. Since the lower MAC already
* does the switching and demultiplexing to its MAC clients, the
* upper MAC would simply have to pass packets to the layer below
* or above it, which would introduce overhead. In order to avoid
* this overhead, the MAC layer implements a pass-through mechanism
* for VNICs. When a VNIC opens the lower MAC instance, it saves
* the MAC client handle it optains from the MAC layer. When a MAC
* client opens a VNIC (upper MAC), the MAC layer detects that
* the MAC being opened is a VNIC, and gets the MAC client handle
* that the VNIC driver obtained from the lower MAC. This exchange
* is done through a private capability between the MAC layer
* and the VNIC driver. The upper MAC then returns that handle
* directly to its MAC client. Any operation done by the upper
* MAC client is now done on the lower MAC client handle, which
* allows the VNIC driver to be completely bypassed for the
* performance sensitive data-path.
*
* - Secondary MACs for VNICs:
*
* VNICs support multiple upper mac clients to enable support for
* multiple MAC addresses on the VNIC. When the VNIC is created the
* initial mac client is the primary upper mac. Any additional mac
* clients are secondary macs. These are kept in sync with the primary
* (for things such as the rx function and resource control settings)
* using the same private capability interface between the MAC layer
* and the VNIC layer.
*
*/
#include <sys/id_space.h>
#include <sys/mac_impl.h>
#include <sys/mac_client_impl.h>
#include <sys/mac_soft_ring.h>
#include <sys/mac_stat.h>
#include <sys/mac_flow.h>
#include <sys/ddi_intr_impl.h>
#include <sys/vnic_impl.h>
#include <sys/exacct_impl.h>
#include <sys/ethernet.h>
static void mac_client_remove_flow_from_list(mac_client_impl_t *,
flow_entry_t *);
static void mac_rename_flow_names(mac_client_impl_t *, const char *);
static void mac_virtual_link_update(mac_impl_t *);
static void mac_client_datapath_teardown(mac_client_handle_t,
mac_unicast_impl_t *, flow_entry_t *);
/* ARGSUSED */
static int
{
int i;
ASSERT(mac_tx_percpu_cnt >= 0);
for (i = 0; i <= mac_tx_percpu_cnt; i++) {
MUTEX_DRIVER, NULL);
}
return (0);
}
/* ARGSUSED */
static void
{
int i;
ASSERT(mac_tx_percpu_cnt >= 0);
for (i = 0; i <= mac_tx_percpu_cnt; i++) {
}
}
/* ARGSUSED */
static int
{
return (0);
}
/* ARGSUSED */
static void
{
}
void
mac_client_init(void)
{
ASSERT(mac_tx_percpu_cnt >= 0);
sizeof (mac_promisc_impl_t), 0, i_mac_promisc_impl_ctor,
}
void
mac_client_fini(void)
{
}
/*
* Return the lower MAC client handle from the VNIC driver for the
* specified VNIC MAC instance.
*/
{
return (mcip);
}
/*
* Update the secondary macs
*/
void
{
}
/*
* Return the MAC client handle of the primary MAC client for the
* specified MAC instance, or NULL otherwise.
*/
{
return (mac_vnic_lower(mip));
return (mcip);
}
return (NULL);
}
/*
* Open a MAC specified by its MAC name.
*/
int
{
int err;
/*
* Look up its entry in the global hash table.
*/
return (err);
/*
* Hold the dip associated to the MAC to prevent it from being
* detached. For a softmac, its underlying dip is held by the
* mi_open() callback.
*
* This is done to be more tolerant with some defective drivers,
* which incorrectly handle mac_unregister() failure in their
* xxx_detach() routine. For example, some drivers ignore the
* failure of mac_unregister() and free all resources that
* that are needed for data transmition.
*/
return (0);
}
/*
* The mac perimeter is used in both mac_open and mac_close by the
*/
return (0);
}
return (err);
}
/*
* Open a MAC specified by its linkid.
*/
int
{
int err;
return (err);
return (err);
}
/*
* Open a MAC specified by its link name.
*/
int
{
int err;
return (err);
}
/*
* Close the specified MAC.
*/
void
{
/*
* The mac perimeter is used in both mac_open and mac_close by the
*/
}
}
}
/*
* Misc utility functions to retrieve various information about a MAC
* instance or a MAC client.
*/
const mac_info_t *
{
}
{
}
void *
{
}
const char *
{
}
int
{
}
int
{
}
char *
{
}
{
}
/*
* Return the VID associated with a MAC client. This function should
* be called for clients which are associated with only one VID.
*/
{
if (mcip->mci_nflents == 0)
return (vid);
return (vid);
}
/*
* Return whether the specified MAC client corresponds to a VLAN VNIC.
*/
{
}
/*
* Return the link speed associated with the specified MAC client.
*
* The link speed of a MAC client is equal to the smallest value of
* 1) the current link speed of the underlying NIC, or
* 2) the bandwidth limit set for the MAC client.
*
* Note that the bandwidth limit can be higher than the speed
* of the underlying NIC. This is allowed to avoid spurious
* administration action failures or artifically lowering the
* bandwidth limit of a link that may have temporarily lowered
* its link speed due to hardware problem or administrator action.
*/
static uint64_t
{
if (nic_speed == 0) {
return (0);
} else {
}
}
/*
* Return the link state of the specified client. If here are more
* than one clients of the underying mac_impl_t, the link state
* will always be UP regardless of the link state of the underlying
* mac_impl_t. This is needed to allow the MAC clients to continue
* to communicate with each other even when the physical link of
* their mac_impl_t is down.
*/
static uint64_t
{
/*
* Returns LINK_STATE_UP if there are other MAC clients defined on
* mac_impl_t which share same VLAN ID as that of mcip. Note that
* if 'mcip' has more than one VID's then we match ANY one of the
* VID's with other MAC client's VID's and return LINK_STATE_UP.
*/
continue;
mui_next) {
return (LINK_STATE_UP);
}
}
}
}
}
/*
* These statistics are consumed by dladm show-link -s <vnic>,
* dladm show-vnic -s and netstat. With the introduction of dlstat,
* dladm show-link -s and dladm show-vnic -s witll be EOL'ed while
* netstat will consume from kstats introduced for dlstat. This code
* will be removed at that time.
*/
/*
* Return the statistics of a MAC client. These statistics are different
* then the statistics of the underlying MAC which are returned by
* mac_stat_get().
*
* Note that for things based on the tx and rx stats, mac will end up clobbering
* those stats when the underlying set of rings in the srs changes. As such, we
* need to source not only the current set, but also the historical set when
* returning to the client, lest our counters appear to go backwards.
*/
{
int i;
switch (stat) {
case MAC_STAT_LINK_STATE:
break;
case MAC_STAT_LINK_UP:
break;
case MAC_STAT_PROMISC:
break;
case MAC_STAT_LOWLINK_STATE:
break;
case MAC_STAT_IFSPEED:
break;
case MAC_STAT_MULTIRCV:
break;
case MAC_STAT_BRDCSTRCV:
break;
case MAC_STAT_MULTIXMT:
break;
case MAC_STAT_BRDCSTXMT:
break;
case MAC_STAT_OBYTES:
break;
case MAC_STAT_OPACKETS:
break;
case MAC_STAT_OERRORS:
break;
case MAC_STAT_IPACKETS:
for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
}
break;
case MAC_STAT_RBYTES:
for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
}
break;
case MAC_STAT_IERRORS:
for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
}
break;
default:
break;
}
return (val);
}
/*
* Return the statistics of the specified MAC instance.
*/
{
int ret;
/*
* The range of stat determines where it is maintained. Stat
* values from 0 up to (but not including) MAC_STAT_MIN are
* mainteined by the mac module itself. Everything else is
* maintained by the driver.
*
* If the mac_impl_t being queried corresponds to a VNIC,
* the stats need to be queried from the lower MAC client
* corresponding to the VNIC. (The mac_link_update()
* invoked by the driver to the lower MAC causes the *lower
* MAC* to update its mi_linkstate, and send a notification
* to its MAC clients. Due to the VNIC passthrough,
* these notifications are sent to the upper MAC clients
* of the VNIC directly, and the upper mac_impl_t of the VNIC
* does not have a valid mi_linkstate.
*/
/* these stats are maintained by the mac module itself */
switch (stat) {
case MAC_STAT_LINK_STATE:
return (mip->mi_linkstate);
case MAC_STAT_LINK_UP:
case MAC_STAT_PROMISC:
return (mip->mi_devpromisc != 0);
case MAC_STAT_LOWLINK_STATE:
return (mip->mi_lowlinkstate);
default:
}
}
/*
* Call the driver to get the given statistic.
*/
if (ret != 0) {
/*
* The driver doesn't support this statistic. Get the
* statistic's default value.
*/
}
return (val);
}
/*
* Query hardware rx ring corresponding to the pseudo ring.
*/
{
}
/*
* Query hardware tx ring corresponding to the pseudo ring.
*/
{
}
/*
* Utility function which returns the VID associated with a flow entry.
*/
{
return (VLAN_ID_NONE);
}
/*
* Verify the validity of the specified unicast MAC address. Returns B_TRUE
* if the address is valid, B_FALSE otherwise (multicast address, or incorrect
* length.
*/
{
/*
* Verify the address. No lock is needed since mi_type and plugin
* details don't change after mac_register().
*/
return (B_FALSE);
} else {
return (B_TRUE);
}
}
void
{
}
void
{
if (multicast_sdu != NULL)
}
/*
* Update the MAC unicast address of the specified client's flows. Currently
* only one unicast MAC unicast address is allowed per client.
*/
static void
{
/*
* The v6 local and SLAAC addrs (used by mac protection) need to be
* regenerated because our mac address has changed.
*/
/*
* A MAC client could have one MAC address but multiple
* VLANs. In that case update the flow entries corresponding
* to all VLANs of the MAC client.
*/
continue;
}
}
/*
* Update all clients that share the same unicast address.
*/
void
{
/*
* Find all clients that share the same unicast MAC address and update
* them appropriately.
*/
/*
* Ignore clients that don't share this MAC address.
*/
continue;
/*
* Update those clients with same old unicast MAC address.
*/
}
}
/*
* Update the unicast MAC address of the specified VNIC MAC client.
*
* Check whether the operation is valid. Any of following cases should fail:
*
* 1. It's a VLAN type of VNIC.
* 2. The new value is current "primary" MAC address.
* 3. The current MAC address is shared with other clients.
* 4. The new MAC address has been used. This case will be valid when
* client migration is fully supported.
*/
int
{
int err;
/*
* If this is a VLAN type of VNIC, it's using "primary" MAC address
* of the underlying interface. Must fail here. Refer to case 1 above.
*/
return (ENOTSUP);
}
/*
* If the new address is the "primary" one, must fail. Refer to
* case 2 above.
*/
return (EACCES);
}
/*
* If the address is shared by multiple clients, must fail. Refer
* to case 3 above.
*/
if (mac_check_macaddr_shared(map)) {
return (EBUSY);
}
/*
* If the new address has been used, must fail for now. Refer to
* case 4 above.
*/
return (ENOTSUP);
}
/*
* Update the MAC address.
*/
if (err != 0) {
return (err);
}
/*
* Update all flows of this MAC client.
*/
return (0);
}
/*
* Program the new primary unicast address of the specified MAC.
*
* Function mac_update_macaddr() takes care different types of underlying
* MAC. If the underlying MAC is VNIC, the VNIC driver must have registerd
* mi_unicst() entry point, that indirectly calls mac_vnic_unicast_set()
* which will take care of updating the MAC address of the corresponding
* MAC client.
*
* This is the only interface that allow the client to update the "primary"
* MAC address of the underlying MAC. The new value must have not been
* used by other clients.
*/
int
{
int err;
/* verify the address validity */
return (EINVAL);
/*
* If the new value is the same as the current primary address value,
* there's nothing to do.
*/
return (0);
}
return (EBUSY);
}
/*
* Update the MAC address.
*/
/*
* If the mac is an aggregation, other than the unicast
* addresses programming, aggr must be informed about this
* primary unicst address change to change its mac address
* policy to be user-specified.
*/
if (err == 0)
} else {
}
if (err != 0) {
return (err);
}
/*
* Save the new primary MAC address in mac_impl_t.
*/
if (err == 0)
return (err);
}
/*
* Return the current primary MAC address of the specified MAC.
*/
void
{
}
/*
* Return the secondary MAC address for the specified handle
*/
void
{
}
/*
* Return information about the use of the primary MAC address of the
* specified MAC instance:
*
* - if client_name is non-NULL, it must point to a string of at
* least MAXNAMELEN bytes, and will be set to the name of the MAC
* client which uses the primary MAC address.
*
* - if in_use is non-NULL, used to return whether the primary MAC
* address is currently in use.
*/
void
{
if (client_name != NULL)
/*
* The mi_rw_lock is used to protect threads that don't hold the
* mac perimeter to get a consistent view of the mi_clients_list.
* Threads that modify the list must hold both the mac perimeter and
* mi_rw_lock(RW_WRITER)
*/
if (mac_is_primary_client(cur_client) ||
if (client_name != NULL) {
}
return;
}
}
}
/*
* Return the current destination MAC address of the specified MAC.
*/
{
if (mip->mi_dstaddr_set)
return (mip->mi_dstaddr_set);
}
/*
* Add the specified MAC client to the list of clients which opened
* the specified MAC.
*/
static void
{
/* add VNIC to the front of the list */
mip->mi_nclients++;
}
/*
* Remove the specified MAC client from the list of clients which opened
* the specified MAC.
*/
static void
{
}
mip->mi_nclients--;
}
static mac_unicast_impl_t *
{
return (muip);
}
/*
* Return whether the specified (MAC address, VID) tuple is already used by
* one of the MAC clients associated with the specified MAC.
*/
static boolean_t
{
/*
* Ignore clients that don't have unicast address.
*/
continue;
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* Generate a random MAC address. The MAC address prefix is
* stored in the array pointed to by mac_addr, and its length, in bytes,
* is specified by prefix_len. The least significant bits
* after prefix_len bytes are generated, and stored after the prefix
* in the mac_addr array.
*/
int
{
if (prefix_len >= addr_len) {
return (EINVAL);
}
/* check the prefix value */
if (prefix_len > 0) {
addr_len)) {
return (EINVAL);
}
}
/* generate the MAC address */
if (prefix_len < addr_len) {
(void) random_get_pseudo_bytes(mac_addr +
}
*diag = 0;
return (0);
}
/*
* Set the priority range for this MAC client. This will be used to
* determine the absolute priority for the threads created for this
* MAC client using the specified "low", "medium" and "high" level.
* This will also be used for any subflows on this MAC client.
*/
MAXCLSYSPRI, (pri)); \
}
/*
* MAC client open entry point. Return a new MAC client handle. Each
* MAC client is associated with a name, specified through the 'name'
* argument.
*/
int
{
int err = 0;
/*
* The underlying MAC is a VNIC. Return the MAC client
* handle of the lower MAC which was obtained by
* the VNIC driver when it did its mac_client_open().
*/
/*
* Note that multiple mac clients share the same mcip in
* this case.
*/
if (flags & MAC_OPEN_FLAGS_EXCLUSIVE)
return (err);
}
if ((flags & MAC_OPEN_FLAGS_IS_VNIC) != 0)
if ((flags & MAC_OPEN_FLAGS_EXCLUSIVE) != 0)
if ((flags & MAC_OPEN_FLAGS_IS_AGGR_PORT) != 0)
if ((flags & MAC_OPEN_FLAGS_USE_DATALINK_NAME) != 0) {
&linkid)) != 0) {
goto done;
}
/*
* Use mac name if dlmgmtd is not available.
*/
err = 0;
} else {
goto done;
}
}
} else {
goto done;
}
}
/* the subflow table will be created dynamically */
/* Create an initial flow */
if (err != 0)
goto done;
/*
* Place initial creation reference on the flow. This reference
* is released in the corresponding delete action viz.
* mac_unicast_remove after waiting for all transient refs to
* to go away. The wait happens in mac_flow_wait.
*/
/*
* Do this ahead of the mac_bcast_add() below so that the mi_nclients
* will have the right value for mac_rx_srs_setup().
*/
if (share_desired)
/*
* We will do mimimal datapath setup to allow a MAC client to
* transmit or receive non-unicast packets without waiting
* for mac_unicast_add.
*/
goto done;
}
}
return (0);
done:
mcip->mci_state_flags = 0;
mcip->mci_tx_flag = 0;
return (err);
}
/*
* Close the specified MAC client handle.
*/
void
{
if (flags & MAC_CLOSE_FLAGS_EXCLUSIVE)
!(flags & MAC_CLOSE_FLAGS_IS_VNIC)) {
/*
* This is an upper VNIC client initiated operation.
* The lower MAC client will be closed by the VNIC driver
* when the VNIC is deleted.
*/
return;
}
/* If we have only setup up minimal datapth setup, tear it down */
}
/*
* Remove the flent associated with the MAC client
*/
/*
* MAC clients must remove the unicast addresses and promisc callbacks
* they added before issuing a mac_client_close().
*/
mcip->mci_state_flags = 0;
mcip->mci_tx_flag = 0;
}
/*
* Set the rx bypass receive callback.
*/
{
/*
* If the mac_client is a VLAN, we should not do DLS bypass and
* instead let the packets come up via mac_rx_deliver so the vlan
* header can be stripped.
*/
return (B_FALSE);
/*
* These are not accessed directly in the data path, and hence
* don't need any protection
*/
return (B_TRUE);
}
/*
*/
void
{
}
void
{
}
/*
* Set the receive callback for the specified MAC client. There can be
* at most one such callback per MAC client.
*/
void
{
/*
* Instead of adding an extra set of locks and refcnts in
* the datapath at the mac client boundary, we temporarily quiesce
* the SRS and related entities. We then change the receive function
* without interference from any receive data thread and then reenable
* the data flow subsequently.
*/
/*
* If we're changing the rx function on the primary mac of a vnic,
* make sure any secondary macs on the vnic are updated as well.
*/
}
}
/*
* Reset the receive callback for the specified MAC client.
*/
void
{
}
void
{
/* This should only be called to setup secondary macs */
/*
* Duplicate the primary mac resources to the secondary.
* Since we already validated the resource controls when setting
* them on the primary, we can ignore errors here.
*/
}
/*
* Called when removing a secondary MAC. Currently only clears the promisc_list
* since we share the primary mac's promisc_list.
*/
void
{
/* This should only be called for secondary macs */
}
/*
* Walk the MAC client subflow table and updates their priority values.
*/
static int
{
return (0);
}
void
{
}
/*
* Modify the TX or RX ring properties. We could either just move around
* client to move from hardware based to software or the other way around.
* If we want to reset this property, then we clear the mask, additionally
* if the client was given a non-default group we remove all rings except
* for 1 and give it back to the default group.
*/
int
{
int err = 0;
return (EINVAL);
/*
* No resulting change. If we are resetting on a client on
* which there was no rx rings property. For dynamic group
* if we are setting the same number of rings already set.
* For static group if we are requesting a group again.
*/
return (0);
} else {
if (unspec) {
return (0);
} else if (mip->mi_rx_group_type ==
return (0);
}
}
}
/* Resetting the prop */
/*
* We will just keep one ring and give others back if
* we are not the primary. For the primary we give
* all the rings in the default group except the
* default ring. If it is a static group, then
* we don't do anything, but clear the MRP_RX_RINGS
* flag.
*/
if (mip->mi_rx_group_type ==
/*
* This group has reserved rings
* that need to be released now,
* so does the group.
*/
FLOW_PRIMARY_MAC) != 0) {
if (mip->mi_nactiveclients ==
1) {
(void)
defgrp);
return (0);
} else {
cmrp->mrp_nrxrings =
group->
defgrp->
mrg_cur_count - 1;
}
} else {
}
(void) mac_group_ring_modify(mcip,
} else {
/*
* If this is a static group, we
* need to release the group. The
* client will remain in the same
* group till some other client
* needs this group.
*/
}
/* Let check if we can give this an excl group */
B_TRUE);
/* Couldn't give it a group, that's fine */
return (0);
/* Switch to H/W */
0) {
return (0);
}
}
/*
* If the client is in the default group, we will
* just clear the MRP_RX_RINGS and leave it as
* it rather than look for an exclusive group
* for it.
*/
return (0);
}
return (ENOSPC);
/* Switch to H/W */
return (ENOSPC);
}
mrp->mrp_nrxrings == 0) {
/* Switch to S/W */
return (ENOSPC);
if (mip->mi_rx_group_type ==
}
}
if (err != 0)
return (err);
/*
* Update the accounting. If this group
* already had explicitly reserved rings,
* we need to update the rings based on
* the new ring count. If this group
* had not explicitly reserved rings,
* then we just reserve the rings asked for
* and reserve the group.
*/
} else {
}
} else {
}
}
}
/*
* For static groups we only allow rings=0 or resetting the
* rings property.
*/
if (mrp->mrp_ntxrings > 0 &&
return (ENOTSUP);
}
return (0);
} else {
if (unspec) {
return (0);
} else if (mip->mi_tx_group_type ==
return (0);
}
}
}
/* Resetting the prop */
if (mip->mi_tx_group_type ==
FLOW_PRIMARY_MAC) != 0) {
mcip);
mcip);
ringcnt);
return (0);
}
(void) mac_group_ring_modify(mcip,
/*
* This group has reserved rings
* that need to be released now.
*/
}
/*
* If this is a static group, we
* need to release the group. The
* client will remain in the same
* group till some other client
* needs this group.
*/
return (0);
}
/*
* If the client is in the default group, we will
* just clear the MRP_TX_RINGS and leave it as
* it rather than look for an exclusive group
* for it.
*/
return (0);
}
/* Switch to H/W */
return (ENOSPC);
/* Switch to S/W */
mrp->mrp_ntxrings == 0) {
/* Switch to S/W */
if (mip->mi_tx_group_type ==
}
}
if (err != 0)
return (err);
/*
* Update the accounting. If this group
* already had explicitly reserved rings,
* we need to update the rings based on
* the new ring count. If this group
* had not explicitly reserved rings,
* then we just reserve the rings asked for
* and reserve the group.
*/
} else {
}
} else {
}
}
}
return (0);
}
/*
* When the MAC client is being brought up (i.e. we do a unicast_add) we need
* to initialize the cpu and resource control structure in the
* mac_client_impl_t from the mac_impl_t (i.e if there are any cached
* properties before the flow entry for the unicast address was created).
*/
static int
{
int err = 0;
if (err != 0)
return (err);
/*
* Copy over the existing properties since mac_update_resources
* will modify the client's mrp. Currently, the saved property
* is used to determine the difference between existing and
* modified rings property.
*/
if (MCIP_DATAPATH_SETUP(mcip)) {
/*
* We support rings only for primary client when there are
* multiple clients sharing the same MAC address (e.g. VLAN).
*/
omrp)) != 0) {
} else {
nmrp->mrp_nrxrings = 0;
}
} else {
nmrp->mrp_ntxrings = 0;
}
else
else
return (err);
}
/*
* If we modified the rings property of the primary
* we need to update the property fields of its
* VLANs as they inherit the primary's properites.
*/
if (mac_is_primary_client(mcip)) {
}
}
/*
* We have to set this prior to calling mac_flow_modify.
*/
} else {
mrp->mrp_priority);
}
}
/* Apply these resource settings to any secondary macs */
}
}
return (0);
}
static int
{
char flowname[MAXFLOWNAMELEN];
int err;
/*
* First unicast address being added, create a new flow
* for that MAC client.
*/
}
if (vid != 0) {
}
/*
* XXX-nicolas. For now I'm keeping the FLOW_PRIMARY_MAC
* and FLOW_VNIC. Even though they're a hack inherited
* from the SRS code, we'll keep them for now. They're currently
* consumed by mac_datapath_setup() to create the SRS.
* That code should be eventually moved out of
* mac_datapath_setup() and moved to a mac_srs_create()
* function of some sort to keep things clean.
*
* Also, there's no reason why the SRS for the primary MAC
* client should be different than any other MAC client. Until
* this is cleaned-up, we support only one MAC unicast address
* per client.
*
* We set FLOW_PRIMARY_MAC for the primary MAC address,
* FLOW_VNIC for everything else.
*/
if (is_primary)
else
/*
* For the first flow we use the mac client's name - mci_name, for
* subsequent ones we just create a name with the vid. This is
* so that we can add these flows to the same flow table. This is
* fine as the flow name (except for the one with the mac client's
* name) is not visible. When the first flow is removed, we just replace
* its fdesc with another from the list, so we will still retain the
* flent with the MAC client's flow name.
*/
if (first_flow) {
} else {
}
flent_flags, flent)) != 0)
return (err);
/*
* Place initial creation reference on the flow. This reference
* is released in the corresponding delete action viz.
* mac_unicast_remove after waiting for all transient refs to
* to go away. The wait happens in mac_flow_wait.
* We have already held the reference in mac_client_open().
*/
if (!first_flow)
return (0);
}
/* Refresh the multicast grouping for this VID. */
int
{
/*
* We don't call mac_multicast_add()/mac_multicast_remove() as
*/
if (add) {
} else {
return (0);
}
}
static void
{
/*
* Find the one active MAC client from the list of MAC
* clients. The active MAC client has at least one
* unicast address.
*/
break;
}
}
/*
* lock, which allows mac_rx() to check the value of that pointer
* as a reader.
*/
}
/*
* Set up the data path. Called from i_mac_unicast_add after having
* done all the validations including making sure this is an active
* client (i.e that is ready to process packets.)
*/
static int
{
int err = 0;
goto bail;
/* add the MAC client to the broadcast address group by default */
if (err != 0)
goto bail;
}
/*
* If this is the first unicast address addition for this
* client, reuse the pre-allocated larval flow entry associated with
* the MAC client.
*/
/* We are configuring the unicast flow now */
if (!MCIP_DATAPATH_SETUP(mcip)) {
}
goto bail;
mip->mi_nactiveclients++;
/*
* This will allocate the RX ring group if possible for the
* flow and program the software classifier as needed.
*/
goto bail;
if (no_unicast)
goto done_setup;
/*
* The unicast MAC address must have been added successfully.
*/
/*
* Push down the sub-flows that were defined on this link
* hitherto. The flows are added to the active flow table
* and SRS, softrings etc. are created as needed.
*/
} else {
ASSERT(!no_unicast);
/*
* A unicast flow already exists for that MAC client,
* this flow must be the same mac address but with
* different VID. It has been checked by mac_addr_in_use().
*
* We will use the SRS etc. from the mci_flent. Note that
* We don't need to create kstat for this as except for
* the fdesc, everything will be used from in the 1st flent.
*/
goto bail;
}
goto bail;
}
goto bail;
}
/* update the multicast group for this vid */
}
/* populate the shared MAC address */
/*
* First add the flent to the flow list of this mcip. Then set
* the mip's mi_single_active_client if needed. The Rx path assumes
* that mip->mi_single_active_client will always have an associated
* flent.
*/
if (nactiveclients_added)
/*
* Trigger a renegotiation of the capabilities when the number of
* active clients changes from 1 to 2, since some of the capabilities
* might have to be disabled. Also send a MAC_NOTE_LINK notification
* to all the MAC clients whenever physical link is DOWN.
*/
}
/*
* Now that the setup is complete, clear the INCIPIENT flag.
* The flag was set to avoid incoming packets seeing inconsistent
* structures while the setup was in progress. Clear the mci_tx_flag
* by calling mac_tx_client_block. It is possible that
* mac_unicast_remove was called prior to this mac_unicast_add which
* could have set the MCI_TX_QUIESCE flag.
*/
return (0);
bail:
if (bcast_added)
if (nactiveclients_added)
mip->mi_nactiveclients--;
if (mac_started)
return (err);
}
/*
* Return the passive primary MAC client, if present. The passive client is
* a stand-by client that has the same unicast address as another that is
* currenly active. Once the active client goes away, the passive client
* becomes active.
*/
static mac_client_impl_t *
{
if (mac_is_primary_client(mcip) &&
return (mcip);
}
}
return (NULL);
}
/*
* Add a new unicast address to the MAC client.
*
* The MAC address can be specified either by value, or the MAC client
* can specify that it wants to use the primary MAC address of the
* underlying MAC. See the introductory comments at the beginning
* of this file for more more information on primary MAC addresses.
*
* Note also the tuple (MAC address, VID) must be unique
* for the MAC clients defined on top of the same underlying MAC
* instance, unless the MAC_UNICAST_NODUPCHECK is specified.
*
* In no case can a client use the PVID for the MAC, if the MAC has one set.
*/
int
{
int err;
/* when VID is non-zero, the underlying MAC can not be VNIC */
/*
* Can't unicast add if the client asked only for minimal datapath
* setup.
*/
return (ENOTSUP);
/*
* Check for an attempted use of the current Port VLAN ID, if enabled.
* No client may use it.
*/
return (EBUSY);
/*
* Check whether it's the primary client and flag it.
*/
/*
* is_vnic_primary is true when we come here as a VLAN VNIC
* which uses the primary mac client's address but with a non-zero
* VID. In this case the MAC address is not specified by an upper
* MAC client.
*/
!is_vnic_primary) {
/*
* The address is being set by the upper MAC client
* of a VNIC. The MAC address was already set by the
* VNIC driver during VNIC creation.
*
* Note: a VNIC has only one MAC address. We return
* the MAC unicast address handle of the lower MAC client
* corresponding to the VNIC. We allocate a new entry
* which is flagged appropriately, so that mac_unicast_remove()
* doesn't attempt to free the original entry that
* was allocated by the VNIC driver.
*/
/* Check for VLAN flags, if present */
if ((flags & MAC_UNICAST_TAG_DISABLE) != 0)
if ((flags & MAC_UNICAST_STRIP_DISABLE) != 0)
if ((flags & MAC_UNICAST_DISABLE_TX_VID_CHECK) != 0)
/*
* Ensure that the primary unicast address of the VNIC
* is added only once unless we have the
* MAC_CLIENT_FLAGS_MULTI_PRIMARY set (and this is not
* a passive MAC client).
*/
MAC_CLIENT_FLAGS_MULTI_PRIMARY) == 0 ||
MAC_CLIENT_FLAGS_PASSIVE_PRIMARY) != 0) {
return (EBUSY);
}
}
/*
* Create a handle for vid 0.
*/
/*
* This will be used by the caller to defer setting the
* rx functions.
*/
if (passive_client)
return (EAGAIN);
return (0);
}
/* primary MAC clients cannot be opened on top of anchor VNICs */
if ((is_vnic_primary || is_primary) &&
return (ENXIO);
}
/*
*/
if (err != 0)
return (err);
}
/*
* Return EBUSY if:
* - there is an exclusively active mac client exists.
* - this is an exclusive active mac client but
* a. there is already active mac clients exist, or
* b. fastpath streams are already plumbed on this legacy device
* - the mac creator has disallowed active mac clients.
*/
if (fastpath_disabled)
return (EBUSY);
}
if (mip->mi_nactiveclients != 0)
return (EBUSY);
return (EBUSY);
}
}
MCIS_IS_AGGR_PORT))) {
/*
* Apply the property cached in the mac_impl_t to the primary
* mac client. If the mac client is a VNIC or an aggregation
* port, its property should be set in the mcip when the
*/
/*
* This is a primary VLAN client, we don't support
* specifying rings property for this as it inherits the
* rings property from its MAC.
*/
if (is_vnic_primary) {
if (fastpath_disabled)
return (ENOTSUP);
}
/*
* Additionally we also need to inherit any
* rings property from the MAC.
*/
}
}
}
}
if (is_primary || is_vnic_primary) {
} else {
/*
* Verify the validity of the specified MAC addresses value.
*/
goto bail_out;
}
/*
* Make sure that the specified MAC address is different
* than the unicast MAC address of the underlying NIC.
*/
goto bail_out;
}
}
/*
* Set the flags here so that if this is a passive client, we
* can return and set it when we call mac_client_datapath_setup
* when this becomes the active client. If we defer to using these
* flags to mac_client_datapath_setup, then for a passive client,
* we'd have to store the flags somewhere (probably fe_flags)
* and then use it.
*/
if (!MCIP_DATAPATH_SETUP(mcip)) {
if (is_unicast_hw) {
/*
* The client requires a hardware MAC address slot
* for that unicast address. Since we support only
* one unicast MAC address per client, flag the
* MAC client itself.
*/
}
/* Check for VLAN flags, if present */
if ((flags & MAC_UNICAST_TAG_DISABLE) != 0)
if ((flags & MAC_UNICAST_STRIP_DISABLE) != 0)
if ((flags & MAC_UNICAST_DISABLE_TX_VID_CHECK) != 0)
} else {
/*
* Assert that the specified flags are consistent with the
* flags specified by previous calls to mac_unicast_add().
*/
((flags & MAC_UNICAST_TAG_DISABLE) == 0 &&
((flags & MAC_UNICAST_STRIP_DISABLE) == 0 &&
((flags & MAC_UNICAST_DISABLE_TX_VID_CHECK) == 0 &&
/*
* Make sure the client is consistent about its requests
* for MAC addresses. I.e. all requests from the clients
* must have the MAC_UNICAST_HW flag set or clear.
*/
!is_unicast_hw ||
goto bail_out;
}
}
/*
* Make sure the MAC address is not already used by
* another MAC client defined on top of the same
* underlying NIC. Unless we have MAC_CLIENT_FLAGS_MULTI_PRIMARY
* set when we allow a passive client to be present which will
* be activated when the currently active client goes away - this
* works only with primary addresses.
*/
/*
* Must have set the multiple primary address flag when
* we did a mac_client_open AND this should be a primary
* MAC client AND there should not already be a passive
* primary. If all is true then we let this succeed
* even if the address is a dup.
*/
goto bail_out;
}
MAC_CLIENT_FLAGS_PASSIVE_PRIMARY) == 0);
/*
* Stash the unicast address handle, we will use it when
* we set up the passive client.
*/
return (0);
}
if (err != 0)
goto bail_out;
return (0);
if (fastpath_disabled)
}
}
return (err);
}
/*
* Wrapper function to mac_unicast_add when we want to have the same mac
* client open for two instances, one that is currently active and another
* that will become active when the current one is removed. In this case
* mac_unicast_add will return EGAIN and we will save the rx function and
* arg which will be used when we activate the passive client in
* mac_unicast_remove.
*/
int
{
return (err);
}
return (0);
}
return (err);
}
int
{
return (err);
}
static void
{
/*
* If we have not added a unicast address for this MAC client, just
* teardown the datapath.
*/
if (!no_unicast) {
/*
* We would have initialized subflows etc. only if we brought
* up the primary client and set the unicast unicast address
* etc. Deactivate the flows. The flow entry will be removed
* from the active flow tables, and the associated SRS,
* softrings etc will be deleted. But the flow entry itself
* won't be destroyed, instead it will continue to be archived
* off the the global flow hash list, for a possible future
* activation when say IP is plumbed again.
*/
}
mip->mi_nactiveclients--;
/* Tear down the data path */
/*
* Prevent any future access to the flow entry through the mci_flent
* pointer by setting the mci_flent to NULL. Access to mci_flent in
* mac_bcast_send is also under mi_rw_lock.
*/
/*
* This is the last unicast address being removed and there shouldn't
* be any outbound data threads at this point coming down from mac
* clients. We have waited for the data threads to finish before
* starting dld_str_detach. Non-data threads must access TX SRS
* under mi_rw_lock.
*/
/*
* Don't use FLOW_MARK with FE_MC_NO_DATAPATH, as the flow might
* contain other flags, such as FE_CONDEMNED, which we need to
* cleared. We don't call mac_flow_cleanup() for this unicast
* flow as we have a already cleaned up SRSs etc. (via the teadown
* path). We just clear the stats and reset the initial callback
* function, the rest will be set when we call mac_flow_create,
* if at all.
*/
/* Initialize the receiver function to a safe routine */
}
}
}
/*
* Disable fastpath if this is a VNIC or a VLAN.
*/
}
/*
* Remove a MAC address which was previously added by mac_unicast_add().
*/
int
{
/*
* Called made by the upper MAC client of a VNIC.
* There's nothing much to do, the unicast address will
* be removed by the VNIC driver when the VNIC is deleted,
* but let's ensure that all our transmit is done before
* the client does a mac_client_stop lest it trigger an
* assert in the driver.
*/
mcip->mci_rx_p_arg);
}
return (0);
}
return (0);
}
/*
* We are removing a passive client, we haven't setup the datapath
* for this yet, so nothing much to do.
*/
return (0);
}
/*
* Remove the VID from the list of client's VIDs.
*/
} else {
}
if (!mac_client_single_rcvr(mcip)) {
/*
* This MAC client is shared by more than one unicast
* addresses, so we will just remove the flent
* corresponding to the address being removed. We don't invoke
* mac_rx_classify_flow_rem() since the additional flow is
* not associated with its own separate set of SRS and rings,
* and these constructs are still needed for the remaining
* flows.
*/
/*
* The first one is disappearing, need to make sure
* we replace it with another from the list of
* shared clients.
*/
/*
* The multicast groups that were added by the client so
* far must be removed from the brodcast domain corresponding
* to the VID being removed.
*/
}
/*
* Enable fastpath if this is a VNIC or a VLAN.
*/
return (0);
}
} else {
return (0);
}
/*
* If we are removing the primary, check if we have a passive primary
* client that we need to activate now.
*/
/*
* Apply the property cached in the mac_impl_t to the
* primary mac client.
*/
mcip->mci_rx_p_arg);
}
} else {
}
}
return (0);
}
/*
* Multicast add function invoked by MAC clients.
*/
int
{
int err = 0;
/* Verify the address is a valid multicast address */
return (err);
if (err != 0)
break;
}
/*
* If we failed adding, then undo all, rather than partial
* success.
*/
}
}
return (err);
}
/*
* Multicast delete function invoked by MAC clients.
*/
void
{
}
}
/*
* When a MAC client desires to capture packets on an interface,
* it registers a promiscuous call back with mac_promisc_add().
* There are three types of promiscuous callbacks:
*
* * MAC_CLIENT_PROMISC_ALL
* Captures all packets sent and received by the MAC client,
* the physical interface, as well as all other MAC clients
* defined on top of the same MAC.
*
* * MAC_CLIENT_PROMISC_FILTERED
* Captures all packets sent and received by the MAC client,
* plus all multicast traffic sent and received by the phyisical
* interface and the other MAC clients.
*
* * MAC_CLIENT_PROMISC_MULTI
* Captures all broadcast and multicast packets sent and
* received by the MAC clients as well as the physical interface.
*
* In all cases, the underlying MAC is put in promiscuous mode.
*/
int
{
int rc;
return (rc);
}
type == MAC_CLIENT_PROMISC_ALL &&
/*
* The function is being invoked by the upper MAC client
* of a VNIC. The VNIC should only see the traffic
* it is entitled to.
*/
}
/*
* Turn on promiscuous mode for the underlying NIC.
* This is needed even for filtered callbacks which
* expect to receive all multicast traffic on the wire.
*
* Physical promiscuous mode should not be turned on if
* MAC_PROMISC_FLAGS_NO_PHYS is set.
*/
if ((flags & MAC_PROMISC_FLAGS_NO_PHYS) == 0) {
return (rc);
}
}
((flags & MAC_PROMISC_FLAGS_VLAN_TAG_STRIP) != 0);
&mpip->mpi_mci_link);
&mpip->mpi_mi_link);
}
return (0);
}
/*
* Remove a multicast address previously aded through mac_promisc_add().
*/
void
{
int rv;
/*
* Even if the device can't be reset into normal mode, we still
* need to clear the client promisc callbacks. The client may want
* to close the mac end point and we can't have stale callbacks.
*/
if (!(mpip->mpi_no_phys)) {
}
}
&mpip->mpi_mi_link)) {
} else {
}
}
}
/*
* Reference count the number of active Tx threads. MCI_TX_QUIESCE indicates
* that a control operation wants to quiesce the Tx data flow in which case
* we return an error. Holding any of the per cpu locks ensures that the
* mci_tx_flag won't change.
*
* 'CPU' must be accessed just once and used to compute the index into the
* percpu array, and that index must be used for the entire duration of the
* packet send operation. Note that the thread may be preempted and run on
* another cpu any time and so we can't use 'CPU' more than once for the
* operation.
*/
{ \
(error) = 0; \
(mytx)->pcpu_tx_refcnt++; \
} else { \
(error) = -1; \
} \
}
/*
* Release the reference. If needed, signal any control operation waiting
* for Tx quiescence. The wait and signal are always done using the
* mci_tx_pcpu[0]'s lock
*/
if (--(mytx)->pcpu_tx_refcnt == 0 && \
} else { \
} \
}
/*
* Send function invoked by MAC clients.
*/
{
int error;
/*
* Check whether the active Tx threads count is bumped already.
*/
if (!(flag & MAC_TX_NO_HOLD)) {
if (error != 0) {
return (NULL);
}
}
/*
* If mac protection is enabled, only the permissible packets will be
* returned by mac_protect_check().
*/
goto done;
FLOW_OUTBOUND, &flent) == 0) {
/*
* The main assumption here is that if in the event
* we get a chain, all the packets will be classified
* reason, the following logic should change as well.
* I suppose the fanout_hint also assumes this .
*/
is_subflow = B_TRUE;
} else {
}
/*
* This is to avoid panics with PF_PACKET that can call mac_tx()
* against an interface that is not capable of sending. A rewrite
* of the mac datapath is required to remove this limitation.
*/
goto done;
}
/*
* Since dls always opens the underlying MAC, nclients equals
* to 1 means that the only active client is dls itself acting
* as a primary client of the MAC instance. Since dls will not
* send tagged packets in that case, and dls is trusted to send
* packets for its allowed VLAN(s), the VLAN tag insertion and
* check is required only if nclients is greater than 1.
*/
if (MAC_VID_CHECK_NEEDED(mcip)) {
int err = 0;
if (err != 0) {
goto done;
}
}
if (MAC_TAG_NEEDED(mcip)) {
goto done;
}
}
}
} else {
}
} else {
}
done:
if (is_subflow)
if (!(flag & MAC_TX_NO_HOLD))
return (cookie);
}
/*
* mac_tx_is_blocked
*
* Given a cookie, it returns if the ring identified by the cookie is
* flow-controlled or not. If NULL is passed in place of a cookie,
* then it finds out if any of the underlying rings belonging to the
* SRS is flow controlled or not and returns that status.
*/
/* ARGSUSED */
{
int err;
int i;
/*
* Bump the reference count so that mac_srs won't be deleted.
* If the client is currently quiesced and we failed to bump
* the reference, return B_TRUE so that flow control stays
* as enabled.
*
* Flow control will then be disabled once the client is no
* longer quiesced.
*/
if (err != 0)
return (B_TRUE);
return (B_FALSE);
}
/*
* Only in the case of TX_FANOUT and TX_AGGR, the underlying
* softring (s_ring_state) will have the HIWAT set. This is
* the multiple Tx ring flow control case. For all other
* case, SRS (srs_state) will store the condition.
*/
} else {
for (i = 0; i < mac_srs->srs_tx_ring_count; i++) {
break;
}
}
}
} else {
}
return (blocked);
}
/*
* Check if the MAC client is the primary MAC client.
*/
{
}
void
{
/*
* If ndd props were registered, call them.
* Note that ndd ioctls are Obsolete
*/
return;
}
/*
* Call the driver to handle the ioctl. The driver may not support
* any ioctls, in which case we reply with a NAK on its behalf.
*/
else
}
/*
* Return the link state of the specified MAC instance.
*/
{
}
/*
* Add a mac client specified notification callback. Please see the comments
* above mac_callback_add() for general information about mac callback
*/
{
/*
* Allocate a notify callback structure, fill in the details and
* use the mac callback list manipulation functions to chain into
* the list of callbacks.
*/
return ((mac_notify_handle_t)mncb);
}
void
{
}
/*
* Remove a mac client specified notification callback
*/
int
{
int err = 0;
/*
* If there aren't any list walkers, the remove would succeed
* inline, else we wait for the deferred remove to complete
*/
} else {
}
/*
* If we failed to remove the notification callback and "wait" is set
* to be B_TRUE, wait for the callback to finish after we exit the
* mac perimeter.
*/
return (0);
}
return (err);
}
/*
* Associate resource management callbacks with the specified MAC
* clients.
*/
void
void *arg)
{
}
void
{
/* update the 'resource_add' callback */
}
/*
* Sets up the client resources and enable the polling interface over all the
* SRS's and the soft rings of the client
*/
void
{
int i;
for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
}
}
/*
* Tears down the client resources and disable the polling interface over all
* the SRS's and the soft rings of the client
*/
void
{
int i;
for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
}
}
/*
* Associate the CPUs specified by the given property with a MAC client.
*/
int
{
int err = 0;
return (err);
}
if (MCIP_DATAPATH_SETUP(mcip))
return (0);
}
/*
* Apply the specified properties to the specified MAC client.
*/
int
{
int err = 0;
if (err != 0)
goto done;
}
if (err != 0)
goto done;
}
if (err != 0)
goto done;
}
done:
return (err);
}
/*
* Return the properties currently associated with the specified MAC client.
*/
void
{
}
/*
* Return the effective properties currently associated with the specified
* MAC client.
*/
void
{
}
/*
* Pass a copy of the specified packet to the promiscuous callbacks
* of the specified MAC.
*
* If sender is NULL, the function is being invoked for a packet chain
* received from the wire. If sender is non-NULL, it points to
* the MAC client from which the packet is being sent.
*
* The packets are distributed to the promiscuous callbacks as follows:
*
* - all packets are sent to the MAC_CLIENT_PROMISC_ALL callbacks
* - all broadcast and multicast packets are sent to the
* MAC_CLIENT_PROMISC_FILTER and MAC_CLIENT_PROMISC_MULTI.
*
* The unicast packets of MAC_CLIENT_PROMISC_FILTER callbacks are dispatched
* after classification by mac_rx_deliver().
*/
static void
{
return;
if (mpip->mpi_strip_vlan_tag) {
return;
}
} else {
}
}
/*
* Return the VID of a packet. Zero if the packet is not tagged.
*/
static uint16_t
{
struct ether_vlan_header *t_evhp =
}
return (0);
}
/*
* Return whether the specified packet contains a multicast or broadcast
* destination MAC address.
*/
static boolean_t
{
return (B_FALSE);
}
/*
* Send a copy of an mblk chain to the MAC clients of the specified MAC.
* "sender" points to the sender MAC client for outbound packets, and
* is set to NULL for inbound packets.
*/
void
{
/* send packet to interested callbacks */
/*
* The sender doesn't want to receive
* copies of the packets it sends.
*/
continue;
/* this client doesn't need any packets (bridge) */
continue;
/*
* For an ethernet MAC, don't displatch a multicast
* packet to a non-PROMISC_ALL callbacks unless the VID
* of the packet matches the VID of the client.
*/
if (is_mcast &&
mac_ether_vid(mp)))
continue;
if (is_sender ||
}
}
}
void
{
/*
* The unicast packets for the MAC client still
* need to be delivered to the MAC_CLIENT_PROMISC_FILTERED
* promiscuous callbacks. The broadcast and multicast
* packets were delivered from mac_rx().
*/
!is_mcast) {
}
}
}
}
/*
* Return the margin value currently assigned to the specified MAC instance.
*/
void
{
}
/*
* mac_info_get() is used for retrieving the mac_info when a DL_INFO_REQ is
* issued before a DL_ATTACH_REQ. we walk the i_mac_impl_hash table and find
* the first mac_impl_t with a matching driver name; then we copy its mac_info_t
* to the caller. we do all this with i_mac_impl_lock held so the mac_impl_t
* cannot disappear while we are accessing it.
*/
typedef struct i_mac_info_state_s {
const char *mi_name;
/*ARGSUSED*/
static uint_t
{
return (MH_WALK_CONTINUE);
return (MH_WALK_CONTINUE);
return (MH_WALK_TERMINATE);
}
{
return (B_FALSE);
}
return (B_TRUE);
}
/*
* To get the capabilities that MAC layer cares about, such as rings, factory
* mac address, vnic or not, it should directly invoke this function. If the
* link is part of a bridge, then the only "capability" it has is the inability
* to do zero copy.
*/
{
return (cap == MAC_CAPAB_NO_ZCOPY);
else
return (B_FALSE);
}
/*
* Capability query function. If number of active mac clients is greater than
* 1, only limited capabilities can be advertised to the caller no matter the
* driver has certain capability or not. Else, we query the driver to get the
* capability.
*/
{
/*
* if mi_nactiveclients > 1, only MAC_CAPAB_LEGACY, MAC_CAPAB_HCKSUM,
* MAC_CAPAB_NO_NATIVEVLAN and MAC_CAPAB_NO_ZCOPY can be advertised.
*/
switch (cap) {
case MAC_CAPAB_NO_ZCOPY:
return (B_TRUE);
case MAC_CAPAB_LEGACY:
case MAC_CAPAB_HCKSUM:
case MAC_CAPAB_NO_NATIVEVLAN:
break;
default:
return (B_FALSE);
}
}
/* else get capab from driver */
}
{
}
mblk_t *
{
/*
* If the MAC is point-to-point with a fixed destination address, then
* we must always use that destination in the MAC header.
*/
}
int
{
mhip));
}
int
{
int err = 0;
/*
* Packets should always be at least 16 bit aligned.
*/
return (err);
/*
* If this is a VLAN-tagged Ethernet packet, then the SAP in the
* mac_header_info_t as returned by mac_header_info() is
* ETHERTYPE_VLAN. We need to grab the ethertype from the VLAN header.
*/
struct ether_vlan_header *evhp;
size = sizeof (struct ether_vlan_header);
/*
* Pullup the message in order to get the MAC header
* infomation. Note that this is a read-only function,
* we keep the input packet intact.
*/
return (EINVAL);
}
return (EINVAL);
} else {
}
return (0);
}
mblk_t *
{
return (NULL);
}
}
return (mp);
}
mblk_t *
{
return (NULL);
}
}
return (mp);
}
{
}
/* True if a MAC is a VNIC */
{
}
{
}
{
}
void
{
if (is_user_flow) {
cmrp->mrp_priority =
} else {
}
} else {
}
}
} else {
}
}
} else {
}
}
/*
* Update the rings specified.
*/
cmrp->mrp_nrxrings = 0;
} else {
}
}
cmrp->mrp_ntxrings = 0;
} else {
}
}
}
}
/*
* i_mac_set_resources:
*
* This routine associates properties with the primary MAC client of
* the specified MAC instance.
* - Cache the properties in mac_impl_t
* - Apply the properties to the primary MAC client if exists
*/
int
{
int err = 0;
if (err != 0)
return (err);
if (resmask == 0 && newresmask != 0) {
/*
* Bandwidth, priority, cpu or pool link properties configured,
* must disable fastpath.
*/
return (err);
}
}
/*
* Since bind_cpu may be modified by mac_client_set_resources()
* we use a copy of bind_cpu and finally cache bind_cpu in mip.
* This allows us to cache only user edits in mip.
*/
/*
* If the primary is not up, we need to check if there
* are any VLANs on this primary. If there are then
* we need to set this property on the VLANs since
* VLANs follow the primary they are based on. Just
* look for the first VLAN and change its properties,
* all the other VLANs should be in the same group.
*/
VLAN_ID_NONE) {
break;
}
}
/*
* We dont' call mac_update_resources since we
* want to take only the ring properties and
* not all the properties that may have changed.
*/
}
vmrp->mrp_nrxrings = 0;
} else {
}
}
}
vmrp->mrp_ntxrings = 0;
} else {
}
}
omrp)) != 0) {
sizeof (*omrp));
} else {
}
}
}
/* Only update the values if mac_client_set_resources succeeded */
if (err == 0) {
/*
* If bandwidth, priority or cpu link properties cleared,
* renable fastpath.
*/
if (resmask != 0 && newresmask == 0)
} else if (resmask == 0 && newresmask != 0) {
}
return (err);
}
int
{
int err;
return (err);
}
/*
* Get the properties cached for the specified MAC instance.
*/
void
{
return;
}
}
/*
* Get the effective properties from the primary client of the
* specified MAC instance.
*/
void
{
mrp);
return;
}
}
int
{
if (pvid != 0) {
return (EBUSY);
}
}
}
}
return (0);
}
{
}
{
}
{
}
/*
* Rename a mac client, its flow, and the kstat.
*/
int
{
/*
* VNICs: we need to change the sys flow name and
* the associated flow kstat.
*/
goto done;
}
/*
* This mac may itself be an aggr link, or it may have some client
* which is an aggr port. For both cases, we need to change the
* aggr port's mac client name, its flow name and the associated flow
* kstat.
*/
(void *)(&aggr_cap));
/*
* The aggr's client name and kstat flow name will be
* updated below, i.e. via mac_rename_flow_names.
*/
}
}
break;
break;
}
}
/* Recreate kstats associated with aggr pseudo rings */
done:
return (0);
}
/*
* Rename the MAC client's flow names
*/
static void
{
char flowname[MAXFLOWNAMELEN];
/*
* Use mi_rw_lock to ensure that threads not in the mac perimeter
* see a self-consistent value for mci_name
*/
return;
/*
* We have to rename all the others too, no stats to destroy for
* these.
*/
}
}
}
/*
* defined for the specified MAC client.
*/
static void
{
/*
* The promisc Rx data path walks the mci_flent_list. Protect by
* using mi_rw_lock
*/
/* Add it to the head */
mcip->mci_nflents++;
/*
* Keep track of the number of non-zero VIDs addresses per MAC
* client to avoid figuring it out in the data-path.
*/
}
/*
* Remove a flow entry from the MAC client's list.
*/
static void
{
/*
* The promisc Rx data path walks the mci_flent_list. Protect by
* using mci_rw_lock
*/
}
/* Deleting the first node */
} else {
}
mcip->mci_nflents--;
}
/*
* Check if the given VID belongs to this MAC client.
*/
{
/*
* In hopes of not having to touch the mci_rw_lock, check to see if
* this vid matches our cached result.
*/
/* The mci_flent_list is protected by mci_rw_lock */
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* Get the flow entry for the specified <MAC addr, VID> tuple.
*/
static flow_entry_t *
{
return (NULL);
return (flent);
}
}
return (NULL);
}
/*
* Since mci_flent has the SRSs, when we want to remove it, we replace
* the flow_desc_t in mci_flent with that of an existing flent and then
* remove that flent instead of mci_flent.
*/
static flow_entry_t *
{
char fl_name[MAXFLOWNAMELEN];
int err;
/* get the next flent following the primary flent */
/*
* Remove the flent from the flow table before updating the
* flow descriptor as the hash depends on the flow descriptor.
* This also helps incoming packet classification avoid having
* to grab fe_lock. Access to fe_flow_desc of a flent not in the
* flow table is done under the fe_lock so that log or stat functions
* see a self-consistent fe_flow_desc. The name and desc are specific
* to a flow, the rest are shared by all the clients, including
* resource control etc.
*/
/* update the primary flow entry */
sizeof (flow_desc_t));
/* update the flow entry that is to be freed */
/* now reinsert the flow entries in the table */
return (flent1);
}
/*
* Return whether there is only one flow entry associated with this
* MAC client.
*/
static boolean_t
{
}
int
{
return (0);
return (EINVAL);
}
return (EINVAL);
}
int i, j;
return (EINVAL);
if (i != j &&
return (EINVAL);
}
}
}
int rv;
else
rv = 0;
if (rv == 0)
return (EINVAL);
}
return (EINVAL);
}
if (err != 0)
return (err);
}
return (0);
}
/*
* mip will be null when we come from mac_flow_create or
* mac_link_flow_modify. In the latter case it is a user flow,
* for which we don't support rings. In the former we would
* have validated the props beforehand (i_mac_unicast_add ->
* mac_client_set_resources -> validate for the primary and
* vnic_dev_create -> mac_client_set_resources -> validate for
* a vnic.
*/
return (0);
/*
* We don't support setting rings property for a VNIC that is using a
* primary address (VLAN)
*/
return (ENOTSUP);
}
/*
* The rings property should be validated against the NICs
* resources
*/
/*
* If groups are not supported, return error.
*/
return (EINVAL);
}
/*
* If we are just resetting, there is no validation needed.
*/
if (reset)
return (0);
/*
* We just want to check if the number of additional
* rings requested is available.
*/
/* Just check for the additional rings */
else
/* We are not asking for additional rings */
rings_needed = 0;
}
} else {
/* Similarly for the TX rings */
/* Just check for the additional rings */
else
/* We are not asking for additional rings */
rings_needed = 0;
}
}
/* Error if the group is dynamic .. */
if (gtype == MAC_GROUP_TYPE_DYNAMIC) {
/*
* .. and rings specified are more than available.
*/
if (rings_needed > rings_avail)
return (EINVAL);
} else {
/*
* OR group is static and we have specified some rings.
*/
if (rings_needed > 0)
return (EINVAL);
}
return (0);
}
/*
* Send a MAC_NOTE_LINK notification to all the MAC clients whenever the
* underlying physical link is down. This is to allow MAC clients to
* communicate with other clients.
*/
void
{
}
/*
* For clients that have a pass-thru MAC, e.g. VNIC, we set the VNIC's
* mac handle in the client.
*/
void
{
/* If there are any properties, copy it over too */
sizeof (mac_resource_props_t));
}
}
/*
* Mark the mac as being used exclusively by the single mac client that is
* doing some control operation on this mac. No further opens of this mac
* will be allowed until this client calls mac_unmark_exclusive. The mac
* client calling this function must already be in the mac perimeter
*/
int
{
/*
* Look up its entry in the global hash table.
*/
return (ENOENT);
}
/*
* A reference to mac is held even if the link is not plumbed.
* In i_dls_link_create() we open the MAC interface and hold the
* reference. There is an additional reference for the mac_open
* done in acquiring the mac perimeter
*/
return (EBUSY);
}
return (0);
}
void
{
/* 1 for the creation and another for the perimeter */
}
/*
* Set the MTU for the specified MAC.
*/
int
{
int rv = 0;
goto bail;
}
goto bail;
}
goto bail;
}
if (rv != 0)
goto bail;
}
bail:
*old_mtu_arg = old_mtu;
return (rv);
}
/*
* Return the RX h/w information for the group indexed by grp_num.
*/
void
char *clnts_name)
{
/* Revisit when we implement fully dynamic group allocation */
index++) {
}
/* Assuming the 1st is the default group */
index = 0;
if (grp_index == 0) {
}
/*
* MAXCLIENTNAMELEN is the buffer size reserved for client
* names.
* XXXX Formating the client name string needs to be moved
* to user land when fixing the size of dhi_clnts in
* dld_hwgrpinfo_t. We should use n_clients * client_name for
* dhi_clntsin instead of MAXCLIENTNAMELEN
*/
break;
}
name_len);
i++;
}
/* Get rid of the last , */
if (index > 0)
*n_clnts = i;
}
/*
* Return the TX h/w information for the group indexed by grp_num.
*/
void
char *clnts_name)
{
/* Revisit when we implement fully dynamic group allocation */
index++) {
}
index = 0;
/* Default group has an index of -1 */
}
/*
* MAXCLIENTNAMELEN is the buffer size reserved for client
* names.
* XXXX Formating the client name string needs to be moved
* to user land when fixing the size of dhi_clnts in
* dld_hwgrpinfo_t. We should use n_clients * client_name for
* dhi_clntsin instead of MAXCLIENTNAMELEN
*/
break;
}
name_len);
i++;
}
/* Get rid of the last , */
if (index > 0)
*n_clnts = i;
}
/*
* Return the group count for RX or TX.
*/
{
/*
* Return the Rx and Tx group count; for the Tx we need to
* include the default too.
*/
}
/*
* The total number of free TX rings for this MAC.
*/
{
return (mip->mi_txrings_avail);
}
/*
* The total number of free RX rings for this MAC.
*/
{
return (mip->mi_rxrings_avail);
}
/*
* The total number of reserved RX rings on this MAC.
*/
{
return (mip->mi_rxrings_rsvd);
}
/*
* The total number of reserved TX rings on this MAC.
*/
{
return (mip->mi_txrings_rsvd);
}
/*
* Total number of free RX groups on this MAC.
*/
{
return (mip->mi_rxhwclnt_avail);
}
/*
* Total number of RX groups reserved on this MAC.
*/
{
return (mip->mi_rxhwclnt_used);
}
/*
* Total number of free TX groups on this MAC.
*/
{
return (mip->mi_txhwclnt_avail);
}
/*
* Total number of TX groups reserved on this MAC.
*/
{
return (mip->mi_txhwclnt_used);
}
/*
* Initialize the rings property for a mac client. A non-0 value for
* rxring or txring specifies the number of rings required, a value
* of MAC_RXRINGS_NONE/MAC_TXRINGS_NONE specifies that it doesn't need
* any RX/TX rings and a value of MAC_RXRINGS_DONTCARE/MAC_TXRINGS_DONTCARE
* means the system can decide whether it can give any rings or not.
*/
void
{
if (rxrings != MAC_RXRINGS_DONTCARE) {
}
if (txrings != MAC_TXRINGS_DONTCARE) {
}
}
{
}
void
{
if (enable)
else
}