mac.c revision 0591ddd0694c4d7ab3ad339419da215a732587f8
/*
* 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
*/
/*
*/
/*
* MAC Services Module
*
* The GLDv3 framework locking - The MAC layer
* --------------------------------------------
*
* The MAC layer is central to the GLD framework and can provide the locking
* framework needed for itself and for the use of MAC clients. MAC end points
* are fairly disjoint and don't share a lot of state. So a coarse grained
* type of control operations on a per mac end point while allowing data threads
* concurrently.
*
* Control operations (set) that modify a mac end point are always serialized on
* a per mac end point basis, We have at most 1 such thread per mac end point
* at a time.
*
* All other operations that are not serialized are essentially multi-threaded.
* For example a control operation (get) like getting statistics which may not
* care about reading values atomically or data threads sending or receiving
* data. Mostly these type of operations don't modify the control state. Any
* state these operations care about are protected using traditional locks.
*
* The perimeter only serializes serial operations. It does not imply there
* aren't any other concurrent operations. However a serialized operation may
* sometimes need to make sure it is the only thread. In this case it needs
* to use reference counting mechanisms to cv_wait until any current data
* threads are done.
*
* The mac layer itself does not hold any locks across a call to another layer.
* The perimeter is however held across a down call to the driver to make the
* whole control operation atomic with respect to other control operations.
* Also the data path and get type control operations may proceed concurrently.
* These operations synchronize with the single serial operation on a given mac
* end point using regular locks. The perimeter ensures that conflicting
* operations like say a mac_multicast_add and a mac_multicast_remove on the
* same mac end point don't interfere with each other and also ensures that the
* changes in the mac layer and the call to the underlying driver to say add a
* multicast address are done atomically without interference from a thread
* trying to delete the same address.
*
* For example, consider
* mac_multicst_add()
* {
* mac_perimeter_enter(); serialize all control operations
*
* grab list lock protect against access by data threads
* add to list
* drop list lock
*
* call driver's mi_multicst
*
* mac_perimeter_exit();
* }
*
* To lessen the number of serialization locks and simplify the lock hierarchy,
* we serialize all the control operations on a per mac end point by using a
* single serialization lock called the perimeter. We allow recursive entry into
* the perimeter to facilitate use of this mechanism by both the mac client and
* the MAC layer itself.
*
* MAC client means an entity that does an operation on a mac handle
* obtained from a mac_open/mac_client_open. Similarly MAC driver means
* an entity that does an operation on a mac handle obtained from a
* mac_register. An entity could be both client and driver but on different
* handles eg. aggr. and should only make the corresponding mac interface calls
* i.e. mac driver interface or mac client interface as appropriate for that
* mac handle.
*
* General rules.
* -------------
*
* R1. The lock order of upcall threads is natually opposite to downcall
* threads. Hence upcalls must not hold any locks across layers for fear of
* recursive lock enter and lock order violation. This applies to all layers.
*
* R2. The perimeter is just another lock. Since it is held in the down
* direction, acquiring the perimeter in an upcall is prohibited as it would
* cause a deadlock. This applies to all layers.
*
* Note that upcalls that need to grab the mac perimeter (for example
* mac_notify upcalls) can still achieve that by posting the request to a
* thread, which can then grab all the required perimeters and locks in the
* right global order. Note that in the above example the mac layer iself
* won't grab the mac perimeter in the mac_notify upcall, instead the upcall
* to the client must do that. Please see the aggr code for an example.
*
* MAC client rules
* ----------------
*
* R3. A MAC client may use the MAC provided perimeter facility to serialize
* control operations on a per mac end point. It does this by by acquring
* and holding the perimeter across a sequence of calls to the mac layer.
* This ensures atomicity across the entire block of mac calls. In this
* model the MAC client must not hold any client locks across the calls to
* the mac layer. This model is the preferred solution.
*
* R4. However if a MAC client has a lot of global state across all mac end
* points the per mac end point serialization may not be sufficient. In this
* case the client may choose to use global locks or use its own serialization.
* To avoid deadlocks, these client layer locks held across the mac calls
* in the control path must never be acquired by the data path for the reason
* mentioned below.
*
* (Assume that a control operation that holds a client lock blocks in the
* mac layer waiting for upcall reference counts to drop to zero. If an upcall
* data thread that holds this reference count, tries to acquire the same
* client lock subsequently it will deadlock).
*
* A MAC client may follow either the R3 model or the R4 model, but can't
* mix both. In the former, the hierarchy is Perim -> client locks, but in
* the latter it is client locks -> Perim.
*
* R5. MAC clients must make MAC calls (excluding data calls) in a cv_wait'able
* context since they may block while trying to acquire the perimeter.
* In addition some calls may block waiting for upcall refcnts to come down to
* zero.
*
* R6. MAC clients must make sure that they are single threaded and all threads
* from the top (in particular data threads) have finished before calling
* mac_client_close. The MAC framework does not track the number of client
* threads using the mac client handle. Also mac clients must make sure
* they have undone all the control operations before calling mac_client_close.
* For example mac_unicast_remove/mac_multicast_remove to undo the corresponding
*
* MAC framework rules
* -------------------
*
* R7. The mac layer itself must not hold any mac layer locks (except the mac
* perimeter) across a call to any other layer from the mac layer. The call to
* any other layer could be via mi_* entry points, classifier entry points into
* the driver or via upcall pointers into layers above. The mac perimeter may
* be acquired or held only in the down direction, for e.g. when calling into
* a mi_* driver enty point to provide atomicity of the operation.
*
* R8. Since it is not guaranteed (see R14) that drivers won't hold locks across
* mac driver interfaces, the MAC layer must provide a cut out for control
* interfaces like upcall notifications and start them in a separate thread.
*
* R9. Note that locking order also implies a plumbing order. For example
* VNICs are allowed to be created over aggrs, but not vice-versa. An attempt
* to plumb in any other order must be failed at mac_open time, otherwise it
* could lead to deadlocks due to inverse locking order.
*
* R10. MAC driver interfaces must not block since the driver could call them
* in interrupt context.
*
* R11. Walkers must preferably not hold any locks while calling walker
* callbacks. Instead these can operate on reference counts. In simple
* callbacks it may be ok to hold a lock and call the callbacks, but this is
* harder to maintain in the general case of arbitrary callbacks.
*
* R12. The MAC layer must protect upcall notification callbacks using reference
* counts rather than holding locks across the callbacks.
*
* R13. Given the variety of drivers, it is preferable if the MAC layer can make
* sure that any pointers (such as mac ring pointers) it passes to the driver
* remain valid until mac unregister time. Currently the mac layer achieves
* this by using generation numbers for rings and freeing the mac rings only
* at unregister time. The MAC layer must provide a layer of indirection and
* must not expose underlying driver rings or driver data structures/pointers
* directly to MAC clients.
*
* MAC driver rules
* ----------------
*
* R14. It would be preferable if MAC drivers don't hold any locks across any
* mac call. However at a minimum they must not hold any locks across data
* upcalls. They must also make sure that all references to mac data structures
* are cleaned up and that it is single threaded at mac_unregister time.
*
* R15. MAC driver interfaces don't block and so the action may be done
* asynchronously in a separate thread as for example handling notifications.
* The driver must not assume that the action is complete when the call
* returns.
*
* R16. Drivers must maintain a generation number per Rx ring, and pass it
* back to mac_rx_ring(); They are expected to increment the generation
* number whenever the ring's stop routine is invoked.
* See comments in mac_rx_ring();
*
* R17 Similarly mi_stop is another synchronization point and the driver must
* ensure that all upcalls are done and there won't be any future upcall
* before returning from mi_stop.
*
* the mi_* entry points are single threaded on a per mac end point.
*
* Lock and Perimeter hierarchy scenarios
* ---------------------------------------
*
* i_mac_impl_lock -> mi_rw_lock -> srs_lock -> s_ring_lock[i_mac_tx_srs_notify]
*
* ft_lock -> fe_lock [mac_flow_lookup]
*
* mi_rw_lock -> fe_lock [mac_bcast_send]
*
* srs_lock -> mac_bw_lock [mac_rx_srs_drain_bw]
*
* cpu_lock -> mac_srs_g_lock -> srs_lock -> s_ring_lock [mac_walk_srs_and_bind]
*
* i_dls_devnet_lock -> mac layer locks [dls_devnet_rename]
*
* Perimeters are ordered P1 -> P2 -> P3 from top to bottom in order of mac
* client to driver. In the case of clients that explictly use the mac provided
* perimeter mechanism for its serialization, the hierarchy is
* Perimeter -> mac layer locks, since the client never holds any locks across
* the mac calls. In the case of clients that use its own locks the hierarchy
* is Client locks -> Mac Perim -> Mac layer locks. The client never explicitly
* calls mac_perim_enter/exit in this case.
*
* Subflow creation rules
* ---------------------------
* o In case of a user specified cpulist present on underlying link and flows,
* the flows cpulist must be a subset of the underlying link.
* o In case of a user specified fanout mode present on link and flow, the
* subflow fanout count has to be less than or equal to that of the
* underlying link. The cpu-bindings for the subflows will be a subset of
* the underlying link.
* o In case if no cpulist specified on both underlying link and flow, the
* underlying link relies on a MAC tunable to provide out of box fanout.
* The subflow will have no cpulist (the subflow will be unbound)
* o In case if no cpulist is specified on the underlying link, a subflow can
* carry either a user-specified cpulist or fanout count. The cpu-bindings
* for the subflow will not adhere to restriction that they need to be subset
* of the underlying link.
* o In case where the underlying link is carrying either a user specified
* cpulist or fanout mode and for a unspecified subflow, the subflow will be
* created unbound.
* o While creating unbound subflows, bandwidth mode changes attempt to
* figure a right fanout count. In such cases the fanout count will override
* the unbound cpu-binding behavior.
* o In addition to this, while cycling between flow and link properties, we
* impose a restriction that if a link property has a subflow with
* user-specified attributes, we will not allow changing the link property.
* The administrator needs to reset all the user specified properties for the
* subflows before attempting a link property change.
* Some of the above rules can be overridden by specifying additional command
* line options while creating or modifying link or subflow properties.
*/
#include <sys/id_space.h>
#include <sys/mac_provider.h>
#include <sys/mac_client_impl.h>
#include <sys/mac_soft_ring.h>
#include <sys/mac_stat.h>
#include <sys/mac_impl.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>
#include <sys/pool_pset.h>
#include <inet/wifi_ioctl.h>
static kmem_cache_t *mac_ring_cache;
static id_space_t *minor_ids;
static uint32_t minor_count;
static pool_event_cb_t mac_pool_event_reg;
/*
* Logging stuff. Perhaps mac_logging_interval could be broken into
* mac_flow_log_interval and mac_link_log_interval if we want to be
* able to schedule them differently.
*/
/* for debugging, see MAC_DBG_PRT() in mac_impl.h */
int mac_dbg = 0;
#define MACTYPE_KMODDIR "mac"
#define MACTYPE_HASHSZ 67
static mod_hash_t *i_mactype_hash;
/*
* i_mactype_lock synchronizes threads that obtain references to mactype_t
* structures through i_mactype_getplugin().
*/
static kmutex_t i_mactype_lock;
/*
* mac_tx_percpu_cnt
*
* Number of per cpu locks per mac_client_impl_t. Used by the transmit side
* in mac_tx to reduce lock contention. This is sized at boot time in mac_init.
* Per cpu locks may be disabled by setting mac_tx_percpu_cnt_max to 1.
*/
int mac_tx_percpu_cnt;
int mac_tx_percpu_cnt_max = 128;
/*
* Call back functions for the bridge module. These are guaranteed to be valid
* when holding a reference on a link or when holding mip->mi_bridge_lock and
* mi_bridge_link is non-NULL.
*/
static int i_mac_constructor(void *, void *, int);
static void i_mac_destructor(void *, void *);
static int i_mac_ring_ctor(void *, void *, int);
static void i_mac_ring_dtor(void *, void *);
void mac_tx_client_flush(mac_client_impl_t *);
void mac_tx_client_block(mac_client_impl_t *);
static int mac_start_group_and_rings(mac_group_t *);
static void mac_stop_group_and_rings(mac_group_t *);
static void mac_pool_event_cb(pool_event_t, int, void *);
/*
* Module initialization functions.
*/
void
mac_init(void)
{
/* Upper bound is mac_tx_percpu_cnt_max */
if (mac_tx_percpu_cnt < 1) {
/* Someone set max_tx_percpu_cnt_max to 0 or less */
mac_tx_percpu_cnt = 1;
}
/*
* Make it of the form 2**N - 1 in the range
* [0 .. mac_tx_percpu_cnt_max - 1]
*/
i_mac_impl_count = 0;
/*
* Allocate an id space to manage minor numbers. The range of the
* space will be from MAC_MAX_MINOR+1 to MAC_PRIVATE_MINOR-1. This
* leaves half of the 32-bit minors available for driver private use.
*/
minor_count = 0;
/* Let's default to 20 seconds */
mac_logging_interval = 20;
mac_logging_timer = 0;
/* Register to be notified of noteworthy pools events */
}
int
mac_fini(void)
{
if (i_mac_impl_count > 0 || minor_count > 0)
return (EBUSY);
return (0);
}
/*
* Initialize a GLDv3 driver's device ops. A driver that manages its own ops
* (e.g. softmac) may pass in a NULL ops argument.
*/
void
{
/*
* By returning on error below, we are not letting the driver continue
* in an undefined context. The mac_register() function will faill if
* DN_GLDV3_DRIVER isn't set.
*/
if (major == DDI_MAJOR_T_NONE)
return;
}
void
{
}
/*ARGSUSED*/
static int
{
return (0);
}
/*ARGSUSED*/
static void
{
}
/* ARGSUSED */
static int
{
return (0);
}
/* ARGSUSED */
static void
{
}
/*
* Common functions to do mac callback addition and deletion. Currently this is
* used by promisc callbacks and notify callbacks. List addition and deletion
* need to take care of list walkers. List walkers in general, can't hold list
* locks and make upcall callbacks due to potential lock order and recursive
* reentry issues. Instead list walkers increment the list walker count to mark
* the presence of a walker thread. Addition can be carefully done to ensure
* that the list walker always sees either the old list or the new list.
* However the deletion can't be done while the walker is active, instead the
* deleting thread simply marks the entry as logically deleted. The last walker
* physically deletes and frees up the logically deleted entries when the walk
* is complete.
*/
void
{
mac_cb_t *p;
/* Verify it is not already in the list */
if (p == mcb_elem)
break;
}
/*
* Add it to the head of the callback list. The membar ensures that
* the following list pointer manipulations reach global visibility
* in exactly the program order below.
*/
}
/*
* Mark the entry as logically deleted. If there aren't any walkers unlink
* from the list. In either case return the corresponding status.
*/
{
mac_cb_t *p;
/*
* Search the callback list for the entry to be removed
*/
if (p == mcb_elem)
break;
}
/*
* If there are walkers just mark it as deleted and the last walker
* will remove from the list and free it.
*/
if (mcbi->mcbi_walker_cnt != 0) {
p->mcb_flags |= MCB_CONDEMNED;
mcbi->mcbi_del_cnt++;
return (B_FALSE);
}
return (B_TRUE);
}
/*
* Wait for all pending callback removals to be completed
*/
void
{
while (mcbi->mcbi_del_cnt != 0) {
}
}
/*
* The last mac callback walker does the cleanup. Walk the list and unlik
* all the logically deleted entries and construct a temporary list of
* removed entries. Return the list of removed entries to the caller.
*/
mac_cb_t *
{
mac_cb_t *p;
int cnt = 0;
p = *pp;
rmlist = p;
cnt++;
continue;
}
}
mcbi->mcbi_del_cnt = 0;
return (rmlist);
}
{
/* Verify it is not already in the list */
return (B_TRUE);
}
return (B_FALSE);
}
{
return (found);
}
/* Free the list of removed callbacks */
void
{
}
}
/*
* The promisc callbacks are in 2 lists, one off the 'mip' and another off the
* 'mcip' threaded by mpi_mi_link and mpi_mci_link respectively. However there
* is only a single shared total walker count, and an entry can't be physically
* unlinked if a walker is active on either list. The last walker does this
* cleanup of logically deleted entries.
*/
void
{
/*
* Construct a temporary list of deleted callbacks by walking the
* the mi_promisc_list. Then for each entry in the temporary list,
* remove it from the mci_promisc_list and free the entry.
*/
&mip->mi_promisc_list);
}
}
void
{
/*
* Signal the notify thread even after mi_ref has become zero and
* mi_disabled is set. The synchronization with the notify thread
* happens in mac_unregister and that implies the driver must make
* sure it is single-threaded (with respect to mac calls) and that
* all pending mac calls have returned before it calls mac_unregister
*/
goto exit;
/*
* Guard against incorrect notifications. (Running a newer
* mac client against an older implementation?)
*/
goto exit;
exit:
}
/*
* Mac serialization primitives. Please see the block comment at the
* top of the file.
*/
void
{
/*
* This is a VNIC. Return the lower mac since that is what
* we want to serialize on.
*/
}
mip->mi_perim_ocnt++;
return;
}
mip->mi_perim_ocnt++;
#ifdef DEBUG
#endif
}
int
{
/*
* The vnic is a special case, since the serialization is done based
* on the lower mac. If the lower mac is busy, it does not imply the
* vnic can't be unregistered. But in the case of other drivers,
* a busy perimeter or open mac handles implies that the mac is busy
* and can't be unregistered.
*/
return (0);
}
return (EBUSY);
}
mip->mi_perim_ocnt++;
return (0);
}
void
{
/*
* This is a VNIC. Return the lower mac since that is what
* we want to serialize on.
*/
}
if (--mip->mi_perim_ocnt == 0) {
}
}
/*
* Returns whether the current thread holds the mac perimeter. Used in making
* assertions.
*/
{
/*
* This is a VNIC. Return the lower mac since that is what
* we want to serialize on.
*/
}
}
/*
* mac client interfaces to enter the mac perimeter of a mac end point, given
* its mac handle, or macname or linkid.
*/
void
{
/*
* The mac_perim_handle_t returned encodes the 'mip' and whether a
* mac_open has been done internally while entering the perimeter.
* This information is used in mac_perim_exit
*/
}
int
{
int err;
return (err);
return (0);
}
int
{
int err;
return (err);
return (0);
}
void
{
if (need_close)
}
int
{
int err;
/*
* Check the device name length to make sure it won't overflow our
* buffer.
*/
return (EINVAL);
/*
* Look up its entry in the global hash table.
*/
(mod_hash_val_t *)&mip);
if (err != 0) {
return (ENOENT);
}
return (ENOENT);
}
return (EBUSY);
}
return (0);
}
void
{
}
}
/*
* Private GLDv3 function to start a MAC instance.
*/
int
{
int err = 0;
/*
* Check whether the device is already started.
*/
/*
* Start the device.
*/
if (err != 0) {
return (err);
}
/*
* Start the default tx ring.
*/
if (err != 0) {
return (err);
}
}
}
/*
* Start the default ring, since it will be needed
* to receive broadcast and multicast traffic for
* both primary and non-primary MAC clients.
*/
if (err != 0) {
return (err);
}
}
}
return (err);
}
/*
* Private GLDv3 function to stop a MAC instance.
*/
void
{
/*
* Check whether the device is still needed.
*/
/*
* There should be no more active clients since the
* MAC is being stopped. Stop the default RX group
* and transition it back to registered state.
*
* When clients are torn down, the groups
* are release via mac_release_rx_group which
* knows the the default group is always in
* started mode since broadcast uses it. So
* we can assert that their are no clients
* (since mac_bcast_add doesn't register itself
* as a client) and group is in SHARED state.
*/
mip->mi_nactiveclients == 0);
}
}
}
/*
* Stop the device.
*/
}
}
int
{
int err = 0;
if (on) {
/*
* Enable promiscuous mode on the device if not yet enabled.
*/
if (mip->mi_devpromisc++ == 0) {
if (err != 0) {
mip->mi_devpromisc--;
return (err);
}
}
} else {
if (mip->mi_devpromisc == 0)
return (EPROTO);
/*
* Disable promiscuous mode on the device if this is the last
* enabling.
*/
if (--mip->mi_devpromisc == 0) {
if (err != 0) {
mip->mi_devpromisc++;
return (err);
}
}
}
return (0);
}
/*
* The promiscuity state can change any time. If the caller needs to take
* actions that are atomic with the promiscuity state, then the caller needs
* to bracket the entire sequence with mac_perim_enter/exit
*/
{
/*
* Return the current promiscuity.
*/
return (mip->mi_devpromisc != 0);
}
/*
* Invoked at MAC instance attach time to initialize the list
* of factory MAC addresses supported by a MAC instance. This function
* builds a local cache in the mac_impl_t for the MAC addresses
* supported by the underlying hardware. The MAC clients themselves
* use the mac_addr_factory*() functions to query and reserve
* factory MAC addresses.
*/
void
{
int i;
/*
* First round to see how many factory MAC addresses are available.
*/
/*
* The MAC instance doesn't support multiple factory
* MAC addresses, we're done here.
*/
return;
}
/*
* Allocate the space and get all the factory addresses.
*/
sizeof (mac_factory_addr_t), KM_SLEEP);
}
}
void
{
return;
}
sizeof (mac_factory_addr_t));
mip->mi_factory_addr_num = 0;
}
/*
* Reserve a factory MAC address. If *slot is set to -1, the function
* attempts to reserve any of the available factory MAC addresses and
* returns the reserved slot id. If no slots are available, the function
* returns ENOSPC. If *slot is not set to -1, the function reserves
* the specified slot if it is available, or returns EBUSY is the slot
* is already used. Returns ENOTSUP if the underlying MAC does not
* support multiple factory addresses. If the slot number is not -1 but
* is invalid, returns EINVAL.
*/
int
{
int i, ret = 0;
/*
* Protect against concurrent readers that may need a self-consistent
* view of the factory addresses
*/
if (mip->mi_factory_addr_num == 0) {
goto bail;
}
if (*slot != -1) {
/* check the specified slot */
goto bail;
}
goto bail;
}
} else {
/* pick the next available slot */
for (i = 0; i < mip->mi_factory_addr_num; i++) {
break;
}
if (i == mip->mi_factory_addr_num) {
goto bail;
}
*slot = i+1;
}
bail:
return (ret);
}
/*
* Release the specified factory MAC address slot.
*/
void
{
/*
* Protect against concurrent readers that may need a self-consistent
* view of the factory addresses
*/
}
/*
* Stores in mac_addr the value of the specified MAC address. Returns
* 0 on success, or EINVAL if the slot number is not valid for the MAC.
* The caller must provide a string of at least MAXNAMELEN bytes.
*/
void
{
/*
* Readers need to hold mi_rw_lock. Writers need to hold mac perimeter
* and mi_rw_lock
*/
}
if (in_use_arg != NULL)
*in_use_arg = in_use;
}
/*
* Returns the number of factory MAC addresses (in addition to the
* primary MAC address), 0 if the underlying MAC doesn't support
* that feature.
*/
{
return (mip->mi_factory_addr_num);
}
void
{
}
/*
* The following mac_hwrings_xxx() functions are private mac client functions
* used by the aggr driver to access and control the underlying HW Rx group
* and rings. In this case, the aggr driver has exclusive control of the
* addresses, or set up the Rx callback.
*/
/* ARGSUSED */
static void
{
void *arg1;
}
/*
* This function is called to get the list of HW rings that are reserved by
* an exclusive mac client.
*
* Return value: the number of HW rings.
*/
int
{
int cnt = 0;
if (rtype == MAC_RING_TYPE_RX) {
} else if (rtype == MAC_RING_TYPE_TX) {
} else {
return (-1);
}
/*
* The mac client did not reserve any RX group, return directly.
* This is probably because the underlying MAC does not support
* any groups.
*/
return (0);
/*
* This group must be reserved by this mac client.
*/
}
return (cnt);
}
/*
*
* Return value: returns uint_t which will have various bits set
* that indicates different properties of the ring.
*/
{
}
/*
* Export ddi interrupt handles from the HW ring to the pseudo ring and
* setup the RX callback of the mac client which exclusively controls
* HW ring.
*/
void
{
/* Export the ddi handles to pseudo ring */
/*
* Save a pointer to pseudo ring in the hw ring. If
* interrupt handle changes, the hw ring will be
* notified of the change (see mac_ring_intr_set())
* and the appropriate change has to be made to
* the pseudo ring that has exported the ddi handle.
*/
}
}
}
void
{
return;
}
}
int
{
}
int
{
}
int
{
return (0);
}
void
{
}
mblk_t *
{
}
/*
* Send packets through a selected tx ring.
*/
mblk_t *
{
}
/*
*/
int
{
}
/*
* Private function that is only used by aggr to send packets through
* that does not expose Tx rings, aggr_ring_tx() entry point needs
* access to mac_impl_t to send packets through m_tx() entry point.
* It accomplishes this by calling mac_hwring_send_priv() function.
*/
mblk_t *
{
return (mp);
}
int
{
}
int
{
}
/*
*/
void
{
/*
* If there is no change in the group state, just return.
*/
return;
switch (state) {
case MAC_GROUP_STATE_RESERVED:
/*
* Successfully reserved the group.
*
* Given that there is an exclusive client controlling this
* group, we enable the group level polling when available,
* assigned to.
*/
}
break;
case MAC_GROUP_STATE_SHARED:
/*
* Set all rings of this group to software classified.
* If the group has an overriding interrupt, then re-enable it.
*/
}
/* The ring is not available for reservations any more */
break;
/* Also callable from mac_register, perim is not held */
break;
default:
break;
}
}
/*
* Quiesce future hardware classified packets for the specified Rx ring
*/
static void
{
}
/*
* Please see mac_tx for details about the per cpu locking scheme
*/
static void
{
int i;
for (i = 0; i <= mac_tx_percpu_cnt; i++)
}
static void
{
int i;
for (i = mac_tx_percpu_cnt; i >= 0; i--)
}
static void
{
int i;
for (i = mac_tx_percpu_cnt; i > 0; i--)
}
static int
{
int i;
int refcnt = 0;
for (i = 0; i <= mac_tx_percpu_cnt; i++)
return (refcnt);
}
/*
* Stop future Tx packets coming down from the client in preparation for
* quiescing the Tx side. This is needed for dynamic reclaim and reassignment
* of rings between clients
*/
void
{
while (mac_tx_sum_refcnt(mcip) != 0) {
}
}
void
{
/*
* We may fail to disable flow control for the last MAC_NOTE_TX
* notification because the MAC client is quiesced. Send the
* notification again.
*/
}
/*
* Wait for an SRS to quiesce. The SRS worker will signal us when the
* quiesce is done.
*/
static void
{
}
/*
* Quiescing an Rx SRS is achieved by the following sequence. The protocol
* works bottom up by cutting off packet flow from the bottommost point in the
* mac, then the SRS, and then the soft rings. There are 2 use cases of this
* mechanism. One is a temporary quiesce of the SRS, such as say while changing
* the Rx callbacks. Another use case is Rx SRS teardown. In the former case
* for the SRS and MR flags. In the former case the threads pause waiting for
* a restart, while in the latter case the threads exit. The Tx SRS teardown
* is also mostly similar to the above.
*
* 1. Stop future hardware classified packets at the lowest level in the mac.
* Remove any hardware classification rule (CONDEMNED case) and mark the
* rings as CONDEMNED or QUIESCE as appropriate. This prevents the mr_refcnt
* from increasing. Upcalls from the driver that come through hardware
* classification will be dropped in mac_rx from now on. Then we wait for
* the mr_refcnt to drop to zero. When the mr_refcnt reaches zero we are
* sure there aren't any upcall threads from the driver through hardware
* classification. In the case of SRS teardown we also remove the
* classification rule in the driver.
*
* 2. Stop future software classified packets by marking the flow entry with
* FE_QUIESCE or FE_CONDEMNED as appropriate which prevents the refcnt from
* increasing. We also remove the flow entry from the table in the latter
* case. Then wait for the fe_refcnt to reach an appropriate quiescent value
* that indicates there aren't any active threads using that flow entry.
*
* 3. Quiesce the SRS and softrings by signaling the SRS. The SRS poll thread,
* SRS worker thread, and the soft ring threads are quiesced in sequence
* with the SRS worker thread serving as a master controller. This
* mechansim is explained in mac_srs_worker_quiesce().
*
* The restart mechanism to reactivate the SRS and softrings is explained
* in mac_srs_worker_restart(). Here we just signal the SRS worker to start the
* restart sequence.
*/
void
{
if (srs_quiesce_flag == SRS_CONDEMNED) {
} else {
}
} else {
/*
* SRS is driven by software classification. In case
* of CONDEMNED, the top level teardown functions will
* deal with flow removal.
*/
if (srs_quiesce_flag != SRS_CONDEMNED) {
}
}
/*
* Signal the SRS to quiesce itself, and then cv_wait for the
* SRS quiesce to complete. The SRS worker thread will wake us
* up when the quiesce is complete
*/
}
/*
* Remove an SRS.
*/
void
{
int i;
/*
* Locate and remove our entry in the fe_rx_srs[] array, and
* adjust the fe_rx_srs array entries and array count by
* moving the last entry into the vacated spot.
*/
for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
break;
}
}
flent->fe_rx_srs_cnt--;
}
static void
{
}
void
{
mac_ring_t *mr;
/*
* This handles a change in the number of SRSs between the quiesce and
* and restart operation of a flow.
*/
if (!SRS_QUIESCED(srs))
return;
/*
* Signal the SRS to restart itself. Wait for the restart to complete
* Note that we only restart the SRS if it is not marked as
* permanently quiesced.
*/
if (!SRS_QUIESCED_PERMANENT(srs)) {
}
/* Finally clear the flags to let the packets in */
/* In case the ring was stopped, safely restart it */
(void) mac_start_ring(mr);
} else {
}
}
/*
* Temporary quiesce of a flow and associated Rx SRS.
* Please see block comment above mac_rx_classify_flow_rem.
*/
/* ARGSUSED */
int
{
int i;
for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
}
return (0);
}
/*
* Restart a flow and associated Rx SRS that has been quiesced temporarily
* Please see block comment above mac_rx_classify_flow_rem
*/
/* ARGSUSED */
int
{
int i;
for (i = 0; i < flent->fe_rx_srs_cnt; i++)
return (0);
}
void
{
int i;
return;
for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
if (on)
else
}
}
void
{
if (MCIP_DATAPATH_SETUP(mcip)) {
NULL);
}
}
void
{
if (MCIP_DATAPATH_SETUP(mcip)) {
}
}
/*
* This function only quiesces the Tx SRS and softring worker threads. Callers
* need to make sure that there aren't any mac client threads doing current or
* future transmits in the mac before calling this function.
*/
void
{
/*
* Signal the SRS to quiesce itself, and then cv_wait for the
* SRS quiesce to complete. The SRS worker thread will wake us
* up when the quiesce is complete
*/
}
void
{
/*
* Resizing the fanout could result in creation of new SRSs.
* They may not necessarily be in the quiesced state in which
* case it need be restarted
*/
if (!SRS_QUIESCED(srs))
return;
}
/*
* Temporary quiesce of a flow and associated Rx SRS.
* Please see block comment above mac_rx_srs_quiesce
*/
/* ARGSUSED */
int
{
/*
* The fe_tx_srs is null for a subflow on an interface that is
* not plumbed
*/
return (0);
}
/* ARGSUSED */
int
{
/*
* The fe_tx_srs is null for a subflow on an interface that is
* not plumbed
*/
return (0);
}
static void
{
}
}
void
{
}
void
{
}
void
{
}
}
void
{
}
void
{
}
void
{
}
/*
* Allocate a minor number.
*/
{
/*
* Grab a value from the arena.
*/
if (sleep)
else
if (minor == 0) {
return (0);
}
return (minor);
}
/*
* Release a previously allocated minor number.
*/
void
{
/*
* Return the value to the arena.
*/
}
{
}
/*
* Prevent any new opens of this mac in preparation for unregister
*/
int
{
/* Already disabled, return success */
return (0);
}
/*
* See if there are any other references to this mac_t (e.g., VLAN's).
* If so return failure. If all the other checks below pass, then
* set mi_disabled atomically under the i_mac_impl_lock to prevent
* any new VLAN's from being created or new mac client opens of this
* mac end point.
*/
return (EBUSY);
}
/*
* mac clients must delete all multicast groups they join before
* closing. bcast groups are reference counted, the last client
* to delete the group will wait till the group is physically
* deleted. Since all clients have closed this mac end point
* mi_bcast_ngrps must be zero at this point
*/
/*
* Don't let go of this if it has some flows.
* All other code guarantees no flows are added to a disabled
* mac, therefore it is sufficient to check for the flow table
* only here.
*/
return (ENOTEMPTY);
}
return (0);
}
int
{
int err;
return (err);
return (err);
}
int
{
int err;
/*
* Clean up notification thread and wait for it to exit.
*/
if (err == 0)
return (err);
}
/*
* Called when the MAC instance has a non empty flow table, to de-multiplex
* incoming packets to the right flow.
* The MAC's rw lock is assumed held as a READER.
*/
/* ARGSUSED */
static mblk_t *
{
int err;
/*
* If the mac is a port of an aggregation, pass FLOW_IGNORE_VLAN
* to mac_flow_lookup() so that the VLAN packets can be successfully
* passed to the non-VLAN aggregation flows.
*
* Note that there is possibly a race between this and
* mac_unicast_remove/add() and VLAN packets could be incorrectly
* classified to non-VLAN flows of non-aggregation mac clients. These
* VLAN packets will be then filtered out by the mac module.
*/
if (err != 0) {
/* no registered receive function */
return (mp);
} else {
/*
* This flent might just be an additional one on the MAC client,
* i.e. for classification purposes (different fdesc), however
* the resources, SRS et. al., are in the mci_flent, so if
* this isn't the mci_flent, we need to get it.
*/
if (err != 0)
return (mp);
}
B_FALSE);
}
return (NULL);
}
mblk_t *
{
/*
* We walk the chain and attempt to classify each packet.
* The packets that couldn't be classified will be returned
* back to the caller.
*/
}
}
return (list);
}
static int
{
return (0);
}
void
{
/*
* After grabbing the mi_rw_lock, the list of clients can't change.
* If there are any clients mi_disabled must be B_FALSE and can't
* get set since there are clients. If there aren't any clients we
* don't do anything. In any case the mip has to be valid. The driver
* must make sure that it goes single threaded (with respect to mac
* calls) and wait for all pending mac calls to finish before calling
* mac_unregister.
*/
return;
}
/*
* Get MAC tx srs from walking mac_client_handle list.
*/
} else {
/*
* Aggr opens underlying ports in exclusive mode
* and registers flow control callbacks using
* mac_tx_client_notify(). When opened in
* exclusive mode, Tx SRS won't be created
* during mac_unicast_add().
*/
}
}
}
}
/* ARGSUSED */
void
{
/*
* If no specific refresh function was given then default to the
* driver's m_multicst entry point.
*/
}
}
void
{
/*
* If no specific refresh function was given then default to the
* driver's m_promisc entry point.
*/
}
/*
* Call the refresh function with the current promiscuity.
*/
}
/*
* The mac client requests that the mac not to change its margin size to
* be less than the specified value. If "current" is B_TRUE, then the client
* requests the mac not to change its margin size to be smaller than the
* current size. Further, return the current margin size value in this case.
*
* We keep every requested size in an ordered list from largest to smallest.
*/
int
{
mac_margin_req_t **pp, *p;
int err = 0;
if (current)
/*
* If the current margin value cannot satisfy the margin requested,
* return ENOTSUP directly.
*/
goto done;
}
/*
* Check whether the given margin is already in the list. If so,
* bump the reference count.
*/
if (p->mmr_margin == *marginp) {
/*
* The margin requested is already in the list,
* so just bump the reference count.
*/
p->mmr_ref++;
goto done;
}
if (p->mmr_margin < *marginp)
break;
}
p->mmr_margin = *marginp;
p->mmr_ref++;
*pp = p;
done:
return (err);
}
/*
* The mac client requests to cancel its previous mac_margin_add() request.
* We remove the requested margin size from the list.
*/
int
{
mac_margin_req_t **pp, *p;
int err = 0;
/*
* Find the entry in the list for the given margin.
*/
if (p->mmr_margin == margin) {
if (--p->mmr_ref == 0)
break;
/*
* There is still a reference to this address so
* there's nothing more to do.
*/
goto done;
}
}
/*
* We did not find an entry for the given margin.
*/
if (p == NULL) {
goto done;
}
/*
* Remove it from the list.
*/
kmem_free(p, sizeof (mac_margin_req_t));
done:
return (err);
}
{
uint32_t margin_needed = 0;
if (margin_needed <= margin)
if (margin_needed <= margin)
return (margin_needed <= margin);
}
/*
* MAC Type Plugin functions.
*/
mactype_getplugin(const char *pname)
{
(mod_hash_val_t *)&mtype) != 0) {
if (!tried_modload) {
/*
* If the plugin has not yet been loaded, then
* attempt to load it now. If modload() succeeds,
* the plugin should have registered using
* mactype_register(), in which case we can go back
* and attempt to find it again.
*/
goto find_registered_mactype;
}
}
} else {
/*
* Note that there's no danger that the plugin we've loaded
* could be unloaded between the modload() step and the
* reference count bump here, as we're holding
* i_mactype_lock, which mactype_unregister() also holds.
*/
}
return (mtype);
}
{
/*
* Make sure there isn't a version mismatch between the plugin and
* the framework. In the future, if multiple versions are
* supported, this check could become more sophisticated.
*/
if (mactype_version != MACTYPE_VERSION)
return (NULL);
return (mtrp);
}
void
{
}
int
{
/* Do some sanity checking before we register this MAC type. */
return (EINVAL);
/*
* Verify that all mandatory callbacks are set in the ops
* vector.
*/
return (EINVAL);
}
mtrp->mtr_addrlen);
}
return (EEXIST);
}
return (0);
}
int
mactype_unregister(const char *ident)
{
int err;
/*
* Let's not allow MAC drivers to use this plugin while we're
* trying to unregister it. Holding i_mactype_lock also prevents a
* plugin from unregistering while a MAC driver is attempting to
* hold a reference to it in i_mactype_getplugin().
*/
(mod_hash_val_t *)&mtp)) != 0) {
/* A plugin is trying to unregister, but it never registered. */
goto done;
}
goto done;
}
if (err != 0) {
/* This should never happen, thus the ASSERT() above. */
goto done;
}
done:
return (err);
}
/*
* Checks the size of the value size specified for a property as
* part of a property operation. Returns B_TRUE if the size is
* correct, B_FALSE otherwise.
*/
{
if (is_range)
return (valsize >= sizeof (mac_propval_range_t));
switch (id) {
case MAC_PROP_ZONE:
minsize = sizeof (dld_ioc_zid_t);
break;
case MAC_PROP_AUTOPUSH:
if (valsize != 0)
minsize = sizeof (struct dlautopush);
break;
case MAC_PROP_TAGMODE:
minsize = sizeof (link_tagmode_t);
break;
case MAC_PROP_RESOURCE:
case MAC_PROP_RESOURCE_EFF:
minsize = sizeof (mac_resource_props_t);
break;
case MAC_PROP_DUPLEX:
minsize = sizeof (link_duplex_t);
break;
case MAC_PROP_SPEED:
break;
case MAC_PROP_STATUS:
minsize = sizeof (link_state_t);
break;
case MAC_PROP_AUTONEG:
case MAC_PROP_EN_AUTONEG:
break;
case MAC_PROP_MTU:
case MAC_PROP_LLIMIT:
case MAC_PROP_LDECAY:
break;
case MAC_PROP_FLOWCTRL:
minsize = sizeof (link_flowctrl_t);
break;
case MAC_PROP_ADV_10GFDX_CAP:
case MAC_PROP_EN_10GFDX_CAP:
case MAC_PROP_ADV_1000HDX_CAP:
case MAC_PROP_EN_1000HDX_CAP:
case MAC_PROP_ADV_100FDX_CAP:
case MAC_PROP_EN_100FDX_CAP:
case MAC_PROP_ADV_100HDX_CAP:
case MAC_PROP_EN_100HDX_CAP:
case MAC_PROP_ADV_10FDX_CAP:
case MAC_PROP_EN_10FDX_CAP:
case MAC_PROP_ADV_10HDX_CAP:
case MAC_PROP_EN_10HDX_CAP:
case MAC_PROP_ADV_100T4_CAP:
case MAC_PROP_EN_100T4_CAP:
break;
case MAC_PROP_PVID:
break;
case MAC_PROP_IPTUN_HOPLIMIT:
break;
break;
break;
case MAC_PROP_WL_ESSID:
minsize = sizeof (wl_linkstatus_t);
break;
case MAC_PROP_WL_BSSID:
minsize = sizeof (wl_bssid_t);
break;
case MAC_PROP_WL_BSSTYPE:
minsize = sizeof (wl_bss_type_t);
break;
case MAC_PROP_WL_LINKSTATUS:
minsize = sizeof (wl_linkstatus_t);
break;
minsize = sizeof (wl_rates_t);
break;
minsize = sizeof (wl_rates_t);
break;
case MAC_PROP_WL_AUTH_MODE:
minsize = sizeof (wl_authmode_t);
break;
case MAC_PROP_WL_ENCRYPTION:
minsize = sizeof (wl_encryption_t);
break;
case MAC_PROP_WL_RSSI:
break;
case MAC_PROP_WL_PHY_CONFIG:
minsize = sizeof (wl_phy_conf_t);
break;
case MAC_PROP_WL_CAPABILITY:
minsize = sizeof (wl_capability_t);
break;
case MAC_PROP_WL_WPA:
break;
case MAC_PROP_WL_SCANRESULTS:
minsize = sizeof (wl_wpa_ess_t);
break;
case MAC_PROP_WL_POWER_MODE:
minsize = sizeof (wl_ps_mode_t);
break;
case MAC_PROP_WL_RADIO:
minsize = sizeof (wl_radio_t);
break;
case MAC_PROP_WL_ESS_LIST:
minsize = sizeof (wl_ess_list_t);
break;
case MAC_PROP_WL_KEY_TAB:
minsize = sizeof (wl_wep_key_tab_t);
break;
case MAC_PROP_WL_CREATE_IBSS:
minsize = sizeof (wl_create_ibss_t);
break;
case MAC_PROP_WL_SETOPTIE:
minsize = sizeof (wl_wpa_ie_t);
break;
case MAC_PROP_WL_DELKEY:
minsize = sizeof (wl_del_key_t);
break;
case MAC_PROP_WL_KEY:
break;
case MAC_PROP_WL_MLME:
break;
}
}
/*
* mac_set_prop() sets MAC or hardware driver properties:
*
* - MAC-managed properties such as resource properties include maxbw,
* priority, and cpu binding list, as well as the default port VID
* used by bridging. These properties are consumed by the MAC layer
* itself and not passed down to the driver. For resource control
* properties, this function invokes mac_set_resources() which will
* cache the property value in mac_impl_t and may call
* mac_client_set_resource() to update property value of the primary
* mac client, if it exists.
*
* - Properties which act on the hardware and must be passed to the
* driver, such as MTU, through the driver's mc_setprop() entry point.
*/
int
{
switch (id) {
case MAC_PROP_RESOURCE: {
/* call mac_set_resources() for MAC properties */
break;
}
case MAC_PROP_PVID:
return (EINVAL);
break;
case MAC_PROP_MTU: {
break;
}
case MAC_PROP_LLIMIT:
case MAC_PROP_LDECAY: {
return (EINVAL);
return (EINVAL);
if (id == MAC_PROP_LLIMIT)
else
err = 0;
break;
}
default:
/* For other driver properties, call driver's callback */
}
}
return (err);
}
/*
* mac_get_prop() gets MAC or device driver properties.
*
* If the property is a driver property, mac_get_prop() calls driver's callback
* entry point to get it.
* If the property is a MAC property, mac_get_prop() invokes mac_get_resources()
* which returns the cached value in mac_impl_t.
*/
int
{
switch (id) {
case MAC_PROP_RESOURCE: {
/* If mac property, read from cache */
return (0);
}
case MAC_PROP_RESOURCE_EFF: {
/* If mac effective property, read from client */
return (0);
}
case MAC_PROP_PVID:
return (EINVAL);
return (0);
case MAC_PROP_LLIMIT:
case MAC_PROP_LDECAY:
return (EINVAL);
if (id == MAC_PROP_LLIMIT)
else
return (0);
case MAC_PROP_MTU: {
return (0);
}
case MAC_PROP_STATUS: {
if (valsize < sizeof (link_state))
return (EINVAL);
return (0);
}
return (0);
return (0);
case MAC_PROP_RXRINGSRANGE:
case MAC_PROP_TXRINGSRANGE:
/*
* The value for these properties are returned through
* the MAC_PROP_RESOURCE property.
*/
return (0);
default:
break;
}
/* If driver property, request from driver */
}
return (err);
}
/*
* Helper function to initialize the range structure for use in
* mac_get_prop. If the type can be other than uint32, we can
* pass that as an arg.
*/
static void
{
}
/*
* Returns information about the specified property, such as default
* values or permissions.
*/
int
{
/*
* otherwise.
*/
*perm = MAC_PROP_PERM_RW;
if (default_val != NULL)
/*
* First, handle framework properties for which we don't need to
* involve the driver.
*/
switch (id) {
case MAC_PROP_RESOURCE:
case MAC_PROP_PVID:
case MAC_PROP_LLIMIT:
case MAC_PROP_LDECAY:
return (0);
return (0);
case MAC_PROP_RXRINGSRANGE:
case MAC_PROP_TXRINGSRANGE:
/*
* Currently, we support range for RX and TX rings properties.
* When we extend this support to maxbw, cpus and priority,
* we should move this to mac_get_resources.
* There is no default value for RX or TX rings.
*/
/*
* We don't support setting rings for a VLAN
* data link because it shares its ring with the
* primary MAC client.
*/
if ((id == MAC_PROP_RXRINGSRANGE &&
(id == MAC_PROP_TXRINGSRANGE &&
if (id == MAC_PROP_RXRINGSRANGE) {
if ((mac_rxhwlnksavail_get(mh) +
/*
* doesn't support groups or
* rings
*/
} else {
/*
* supports specifying groups,
* but not rings
*/
_mac_set_range(range, 0, 0);
}
} else {
if ((mac_txhwlnksavail_get(mh) +
/*
* doesn't support groups or
* rings
*/
} else {
/*
* supports specifying groups,
* but not rings
*/
_mac_set_range(range, 0, 0);
}
}
} else {
if (max <= 1) {
/*
* doesn't support groups or
* rings
*/
} else {
/*
* -1 because we have to leave out the
* default ring.
*/
}
}
}
return (0);
case MAC_PROP_STATUS:
return (0);
}
/*
* Get the property info from the driver if it implements the
* property info entry point.
*/
/*
* The caller specifies the maximum number of ranges
* it can accomodate using mpr_count. We don't touch
* this value until the driver returns from its
* mc_propinfo() callback, and ensure we don't exceed
* this number of range as the driver defines
* supported range from its mc_propinfo().
*
* pr_range_cur_count keeps track of how many ranges
* were defined by the driver from its mc_propinfo()
* entry point.
*
* On exit, the user-specified range mpr_count returns
* the number of ranges specified by the driver on
* success, or the number of ranges it wanted to
* define if that number of ranges could not be
* accomodated by the specified range structure. In
* the latter case, the caller will be able to
* allocate a larger range structure, and query the
* property again.
*/
state.pr_range_cur_count = 0;
/*
* The operation could fail if the buffer supplied by
* the user was too small for the range or default
* value of the property.
*/
}
/*
* The MAC layer may want to provide default values or allowed
* ranges for properties if the driver does not provide a
* property info entry point, or that entry point exists, but
* it did not provide a default value or allowed ranges for
* that property.
*/
switch (id) {
case MAC_PROP_MTU: {
/* MTU range */
}
/* default MTU value */
}
}
}
return (0);
}
int
{
return (0);
}
void
{
return;
}
void
{
if (priv_props == NULL)
return;
nprops = 0;
nprops++;
if (nprops == 0)
return;
for (i = 0; i < nprops; i++) {
}
}
void
{
uint_t i;
if (mip->mi_priv_prop_count == 0) {
return;
}
for (i = 0; i < mip->mi_priv_prop_count; i++)
sizeof (char *));
mip->mi_priv_prop_count = 0;
}
/*
* mac_ring_t 'mr' macros. Some rogue drivers may access ring structure
* (by invoking mac_rx()) even after processing mac_stop_ring(). In such
* cases if MAC free's the ring structure after mac_stop_ring(), any
* illegal access to the ring structure coming from the driver will panic
* the system. In order to protect the system from such inadverent access,
* we maintain a cache of rings in the mac_impl_t after they get free'd up.
* When packets are received on free'd up rings, MAC (through the generation
* count mechanism) will drop such packets.
*/
static mac_ring_t *
{
} else {
}
return (ring);
}
static void
{
}
static void
{
}
}
int
{
int rv = 0;
if (rv != 0)
return (rv);
}
return (rv);
}
void
{
/*
* Increment the ring generation number for this ring.
*/
ring->mr_gen_num++;
}
int
{
int rv = 0;
return (rv);
}
void
{
}
/*
* Called from mac_start() on the default Rx group. Broadcast and multicast
* packets are received only on the default group. Hence the default group
* needs to be up even if the primary client is not up, for the other groups
* to be functional. We do this by calling this function at mac_start time
* itself. However the broadcast packets that are received can't make their
* way beyond mac_rx until a mac client creates a broadcast flow.
*/
static int
{
int rv = 0;
return (rv);
goto error;
}
return (0);
return (rv);
}
/* Called from mac_stop on the default Rx group */
static void
{
}
}
}
static mac_ring_t *
{
/* Prepare basic information of ring */
/*
* Ring index is numbered to be unique across a particular device.
* Ring index computation makes following assumptions:
* - For drivers with static grouping (e.g. ixgbe, bge),
* ring index exchanged with the driver (e.g. during mr_rget)
* is unique only across the group the ring belongs to.
* - Drivers with dynamic grouping (e.g. nxge), start
* with single group (mrg_index = 0).
*/
/* Insert the new ring to the list. */
/* Zero to reuse the info data structure */
/* Query ring information from driver */
/*
* The interrupt handle could be shared among multiple rings.
* Thus if there is a bunch of rings that are sharing an
* interrupt, then only one ring among the bunch will be made
* available for interrupt re-targeting; the rest will have
* ddi_shared flag set to TRUE and would not be available for
* be interrupt re-targeting.
*/
ddi_handle) {
/*
* If default ring (mr_index == 0) is part
* of a group of rings sharing an
* interrupt, then set ddi_shared flag for
* the default ring and give another ring
* the chance to be re-targeted.
*/
} else {
}
break;
}
}
/*
* If rnext is NULL, then no matching ddi_handle was found.
* Rx rings get registered first. So if this is a Tx ring,
* then go through all the Rx rings and see if there is a
* matching ddi handle.
*/
}
}
/* Update ring's status */
/* Update the ring count of the group */
group->mrg_cur_count++;
/* Create per ring kstats */
}
return (ring);
}
/*
* Rings are chained together for easy regrouping.
*/
static void
{
int index;
/*
* Initialize all ring members of this group. Size of zero will not
* enter the loop, so it's safe for initializing an empty group.
*/
}
int
{
uint_t group_free = 0;
int g;
int err = 0;
switch (rtype) {
case MAC_RING_TYPE_RX:
break;
case MAC_RING_TYPE_TX:
break;
default:
}
return (0);
/*
* If we have multiple TX rings, but only one TX group, we can
* create pseudo TX groups (one per TX ring) in the MAC layer,
* except for an aggr. For an aggr currently we maintain only
* one group with all the rings (for all its ports), going
* forwards we might change this.
*/
if (rtype == MAC_RING_TYPE_TX &&
/*
* The -1 here is because we create a default TX group
* with all the rings in it.
*/
}
/*
* Allocate a contiguous buffer for all groups.
*/
/*
* Get all ring groups if any, and get their ring members
* if any.
*/
for (g = 0; g < grpcnt; g++) {
/* Prepare basic information of the group */
/* Zero to reuse the info data structure */
if (pseudo_txgrp) {
/*
* This is a pseudo group that we created, apart
* from setting the state there is nothing to be
* done.
*/
group_free++;
continue;
}
/* Query group information from driver */
switch (cap_rings->mr_group_type) {
case MAC_GROUP_TYPE_DYNAMIC:
goto bail;
}
switch (rtype) {
case MAC_RING_TYPE_RX:
/*
* The first RX group must have non-zero
* rings, and the following groups must
* have zero rings.
*/
if (g == 0 && group_info.mgi_count == 0) {
goto bail;
}
if (g > 0 && group_info.mgi_count != 0) {
int, g, int, group_info.mgi_count);
goto bail;
}
break;
case MAC_RING_TYPE_TX:
/*
* All TX ring groups must have zero rings.
*/
if (group_info.mgi_count != 0) {
int, g, int, group_info.mgi_count);
goto bail;
}
break;
}
break;
case MAC_GROUP_TYPE_STATIC:
/*
* Note that an empty group is allowed, e.g., an aggr
* would start with an empty group.
*/
break;
default:
/* unknown group type */
int, cap_rings->mr_group_type);
goto bail;
}
/*
* Driver must register group->mgi_addmac/remmac() for rx groups
* to support multiple MAC addresses.
*/
if (rtype == MAC_RING_TYPE_RX) {
goto bail;
}
}
/* Cache driver-supplied information */
/* Update the group's status and group count. */
group_free++;
group->mrg_cur_count = 0;
/* The current group size should be equal to default value */
}
/* Build up a dummy group for free resources as a pool */
/* Prepare basic information of the group */
/*
* If there are ungrouped rings, allocate a continuous buffer for
* remaining resources.
*/
if (ring_left != 0) {
group->mrg_cur_count = 0;
/* The current group size should be equal to ring_left */
ring_left = 0;
/* Update this group's status */
} else
bail:
/* Cache other important information to finalize the initialization */
switch (rtype) {
case MAC_RING_TYPE_RX:
/*
* The default ring is reserved since it is
* used for sending the broadcast etc. packets.
*/
}
/*
* The default group cannot be reserved. It is used by
* all the clients that do not have an exclusive group.
*/
break;
case MAC_RING_TYPE_TX:
/*
* The ring can be NULL in the case of aggr. Aggr will
* have an empty Tx group which will get populated
* later when pseudo Tx rings are added after
* mac_register() is done.
*/
/*
* pass the group to aggr so it can add Tx
* rings to the group later.
*/
/*
* Even though there are no rings at this time
* (rings will come later), set the group
* state to registered.
*/
} else {
/*
* Ring 0 is used as the default one and it could be
* assigned to a client as well.
*/
}
/*
* The default ring cannot be reserved.
*/
/*
* The default group cannot be reserved. It will be shared
* by clients that do not have an exclusive group.
*/
break;
default:
}
if (err != 0)
return (err);
}
/*
* The ddi interrupt handle could be shared amoung rings. If so, compare
* the new ring's ddi handle with the existing ones and set ddi_shared
* flag.
*/
void
{
int g;
for (g = 0; g < grpcnt; g++) {
continue;
ddi_handle) {
} else {
}
return;
}
}
}
}
/*
* Called to free all groups of particular type (RX or TX). It's assumed that
* no clients are using these groups.
*/
void
{
switch (rtype) {
case MAC_RING_TYPE_RX:
return;
mip->mi_rx_group_count = 0;
break;
case MAC_RING_TYPE_TX:
return;
mip->mi_tx_group_count = 0;
mip->mi_tx_group_free = 0;
break;
default:
}
if (group->mrg_cur_count == 0)
continue;
}
}
/* Free all the cached rings */
/* Free the block of group data strutures */
}
/*
* Associate a MAC address with a receive group.
*
* The return value of this function should always be checked properly, because
* any type of failure could cause unexpected results. A group can be added
* or removed with a MAC address only after it has been reserved. Ideally,
* a successful reservation always leads to calling mac_group_addmac() to
* steer desired traffic. Failure of adding an unicast MAC address doesn't
* always imply that the group is functioning abnormally.
*
* Currently this function is called everywhere, and it reflects assumptions
* about MAC addresses in the implementation. CR 6735196.
*/
int
{
}
/*
* Remove the association between MAC address and receive group.
*/
int
{
}
/*
* This is the entry point for packets transmitted through the bridging code.
* If no bridge is in place, MAC_RING_TX transmits using tx ring. The 'rh'
* pointer may be NULL to select the default ring.
*/
mblk_t *
{
/*
* Once we take a reference on the bridge link, the bridge
* module itself can't unload, so the callback pointers are
* stable.
*/
} else {
}
return (mp);
}
/*
* Find a ring from its index.
*/
{
break;
return ((mac_ring_handle_t)ring);
}
/*
* Add a ring to an existing group.
*
* The ring must be either passed directly (for example if the ring
* movement is initiated by the framework), or specified through a driver
* index (for example when the ring is added by the driver.
*
* The caller needs to call mac_perim_enter() before calling this function.
*/
int
{
int ret = 0;
case MAC_RING_TYPE_RX:
break;
case MAC_RING_TYPE_TX:
break;
default:
}
/*
* There should be no ring with the same ring index in the target
* group.
*/
if (driver_call) {
/*
* The function is called as a result of a request from
* a driver to add a ring to an existing group, for example
* from the aggregation driver. Allocate a new mac_ring_t
* for that ring.
*/
} else {
/*
* The function is called as a result of a MAC layer request
* to add a ring to an existing group. In this case the
* ring is being moved between groups, which requires
* the underlying driver to support dynamic grouping,
* and the mac_ring_t already exists.
*/
}
/*
* At this point the ring should not be in use, and it should be
* of the right for the target group.
*/
if (!driver_call) {
/*
* Add the driver level hardware ring if the process was not
* initiated by the driver, and the target group is not the
* group.
*/
}
/*
* Insert the ring ahead existing rings.
*/
group->mrg_cur_count++;
}
/*
* If the group has not been actively used, we're done.
*/
return (0);
/*
* Start the ring if needed. Failure causes to undo the grouping action.
*/
if (!driver_call) {
}
group->mrg_cur_count--;
if (driver_call)
return (ret);
}
}
/*
*/
case MAC_RING_TYPE_RX:
/*
* Setup SRS on top of the new ring if the group is
* reserved for someones exclusive use.
*/
/*
* Even though this group is reserved we migth still
* have multiple clients, i.e a VLAN shares the
* group with the primary mac client.
*/
} else {
}
}
break;
case MAC_RING_TYPE_TX:
{
if (MAC_GROUP_NO_CLIENT(group)) {
break;
}
/*
* If the rings are being moved to a group that has
* clients using it, then add the new rings to the
* clients SRS.
*/
/*
* If we are growing from 1 to multiple rings.
*/
} else {
}
}
}
break;
}
default:
}
/*
* For aggr, the default ring will be NULL to begin with. If it
* is NULL, then pick the first ring that gets added as the
* default ring. Any ring in an aggregation can be removed at
* any time (by the user action of removing a link) and if the
* current default ring gets removed, then a new one gets
* picked (see i_mac_group_rem_ring()).
*/
}
return (0);
}
/*
* Remove a ring from it's current group. MAC internal function for dynamic
* grouping.
*
* The caller needs to call mac_perim_enter() before calling this function.
*/
void
{
case MAC_RING_TYPE_RX:
/*
* Only hardware classified packets hold a reference to the
* ring all the way up the Rx path. mac_rx_srs_remove()
* will take care of quiescing the Rx path and removing the
* SRS. The software classified path neither holds a reference
* nor any association with the ring in mac_rx.
*/
}
break;
case MAC_RING_TYPE_TX:
{
/*
* For TX this function is invoked in three
* cases:
*
* 1) In the case of a failure during the
* initial creation of a group when a share is
* associated with a MAC client. So the SRS is not
* yet setup, and will be setup later after the
* group has been reserved and populated.
*
* 2) From mac_release_tx_group() when freeing
* a TX SRS.
*
* 3) In the case of aggr, when a port gets removed,
* the pseudo Tx rings that it exposed gets removed.
*
* In the first two cases the SRS and its soft
* rings are already quiesced.
*/
if (driver_call) {
/* pick a new default Tx ring */
}
/* Presently only aggr case comes here */
break;
/*
* Wakeup any callers blocked on this
* Tx ring due to flow control.
*/
break;
}
/*
* See if we need to take it out of the MAC clients using
* this group
*/
if (MAC_GROUP_NO_CLIENT(group))
break;
/*
* If we are here when removing rings from the
* defgroup, mac_reserve_tx_ring would have
* already deleted the ring from the MAC
* clients in the group.
*/
}
/*
* Additionally, if we are left with only
* one ring in the group after this, we need
* to modify the mode etc. to. (We haven't
* yet taken the ring out, so we check with 2).
*/
else
rem_ring));
(void) mac_start_ring(rem_ring);
}
/*
* We are shrinking from multiple
* to 1 ring.
*/
} else if (mac_tx_serialize ||
(ring_info & MAC_RING_TX_SERIALIZE)) {
} else {
}
}
}
break;
}
default:
}
/*
* Remove the ring from the group.
*/
else {
}
group->mrg_cur_count--;
if (!driver_call) {
/*
* Remove the driver level hardware ring.
*/
}
}
if (driver_call)
else
}
/*
* Move a ring to the target group. If needed, remove the ring from the group
* that it currently belongs to.
*
* The caller need to enter MAC's perimeter by calling mac_perim_enter().
*/
static int
{
int rv;
return (0);
/*
* Remove it from current group first.
*/
/*
* Add it to the new group.
*/
if (rv != 0) {
/*
* Failed to add ring back to source group. If
* that fails, the ring is stuck in limbo, log message.
*/
}
}
return (rv);
}
/*
* Find a MAC address according to its value.
*/
{
break;
}
return (map);
}
/*
* Check whether the MAC address is shared by multiple clients.
*/
{
}
/*
* Remove the specified MAC address from the MAC address list and free it.
*/
static void
{
} else {
}
}
/*
* Add a MAC address reference for a client. If the desired MAC address
* exists, add a reference to it. Otherwise, add the new address by adding
* it to a reserved group or setting promiscuous mode. Won't try different
* group is the group is non-NULL, so the caller must explictly share
* default group when needed.
*
* Note, the primary MAC address is initialized at registration time, so
* to add it to default group only need to activate it if its reference
* count is still zero. Also, some drivers may not have advertised RINGS
* capability.
*/
int
{
int err = 0;
/*
* If the new MAC address has not been added. Allocate a new one
* and set it up.
*/
/* add the new MAC address to the head of the address list */
}
/*
* If the MAC address is already in use, simply account for the
* new client.
*/
return (0);
/*
* Activate this MAC address by adding it to the reserved group.
*/
if (err == 0) {
return (0);
}
}
/*
* The MAC address addition failed. If the client requires a
* hardware classified MAC address, fail the operation.
*/
if (use_hw) {
goto bail;
}
/*
* Try promiscuous mode.
*
* For drivers that don't advertise RINGS capability, do
* nothing for the primary address.
*/
return (0);
}
/*
* Enable promiscuous mode in order to receive traffic
* to the new MAC address.
*/
return (0);
}
/*
* Free the MAC address that could not be added. Don't free
* a pre-existing address, it could have been the entry
* for the primary MAC address which was pre-allocated by
* mac_init_macaddr(), and which must remain on the list.
*/
bail:
if (allocated_map)
return (err);
}
/*
* Remove a reference to a MAC address. This may cause to remove the MAC
* address from an associated group or to turn off promiscuous mode.
* The caller needs to handle the failure properly.
*/
int
{
int err = 0;
/*
* If it's not the last client using this MAC address, only update
* the MAC clients count.
*/
return (0);
/*
* The MAC address is no longer used by any MAC client, so remove
* it from its associated group, or turn off promiscuous mode
* if it was enabled for the MAC address.
*/
/*
* Don't free the preset primary address for drivers that
* don't advertise RINGS capability.
*/
return (0);
if (err == 0)
break;
break;
default:
}
if (err != 0)
return (err);
/*
* We created MAC address for the primary one at registration, so we
* won't free it here. mac_fini_macaddr() will take care of it.
*/
return (0);
}
/*
* Update an existing MAC address. The caller need to make sure that the new
* value has not been used.
*/
int
{
int err = 0;
/*
* Update the primary address for drivers that are not
* RINGS capable.
*/
mac_addr);
if (err != 0)
return (err);
break;
}
/*
* If this MAC address is not currently in use,
* simply break out and update the value.
*/
break;
/*
* Need to replace the MAC address associated with a group.
*/
if (err != 0)
return (err);
/*
* Failure hints hardware error. The MAC layer needs to
* have error notification facility to handle this.
* Now, simply try to restore the value.
*/
if (err != 0)
break;
/*
* Need to do nothing more if in promiscuous mode.
*/
break;
default:
}
/*
* Successfully replaced the MAC address.
*/
if (err == 0)
return (err);
}
/*
* Freshen the MAC address with new value. Its caller must have updated the
* hardware MAC address before calling this function.
* This funcitons is supposed to be used to handle the MAC address change
* notification from underlying drivers.
*/
void
{
/*
* Freshen the MAC address with new value.
*/
/*
* Update all MAC clients that share this MAC address.
*/
}
/*
* Set up the primary MAC address.
*/
void
{
/*
* The reference count is initialized to zero, until it's really
* activated.
*/
/*
* If driver advertises RINGS capability, it shouldn't have initialized
* its primary MAC address. For other drivers, including VNIC, the
* primary address must work after registration.
*/
}
/*
* Clean up the primary MAC address. Note, only one primary MAC address
* is allowed. All other MAC addresses must have been freed appropriately.
*/
void
{
return;
/*
* If mi_addresses is initialized, there should be exactly one
* entry left on the list with no users.
*/
}
/*
* Logging related functions.
*
* Note that Kernel statistics have been extended to maintain fine
* granularity of statistics viz. hardware lane, software lane, fanout
* stats etc. However, extended accounting continues to support only
* aggregate statistics like before.
*/
/* Write the Flow description to the log file */
int
{
/*
* Grab the fe_lock to see a self-consistent fe_flow_desc.
* Updates to the fe_flow_desc are done under the fe_lock
*/
} else {
}
}
/* Write the Flow statistics to the log file */
int
{
int i;
for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
}
}
}
/* Write the Link Description to the log file */
int
{
/*
* Grab the fe_lock to see a self-consistent fe_flow_desc.
* Updates to the fe_flow_desc are done under the fe_lock
* after removing the flent from the flow table.
*/
}
/* Write the Link statistics to the log file */
int
{
int i;
for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
}
}
}
}
/*
* For a given flow, if the descrition has not been logged before, do it now.
* If it is a VNIC, then we have collected information about it from the MAC
* table, so skip it.
*/
/*ARGSUSED*/
static int
{
return (0);
/*
* If the name starts with "vnic", and fe_user_generated is true (to
* exclude the mcast and active flow entries created implicitly for
* a vnic, it is a VNIC flow. i.e. vnic1 is a vnic flow,
*/
return (0);
}
if (!flent->fe_desc_logged) {
/*
* We don't return error because we want to continu the
* walk in case this is the last walk which means we
* need to reset fe_desc_logged in all the flows.
*/
return (0);
}
/*
* Regardless of the error, we want to proceed in case we have to
* reset fe_desc_logged.
*/
(void) mac_write_flow_stats(flent);
return (0);
}
typedef struct i_mac_log_state_s {
int mi_fenable;
int mi_lenable;
/*
* Walk the mac_impl_ts and log the description for each mac client of this mac,
* if it hasn't already been done. Additionally, log statistics for the link as
* well. Walk the flow table and log information for each flow as well.
* If it is the last walk (mci_last), then we turn off mci_desc_logged (and
* also fe_desc_logged, if flow logging is on) since we want to log the
* description if and when logging is restarted.
*/
/*ARGSUSED*/
static uint_t
{
int ret;
/*
* Only walk the client list for NIC and etherstub
*/
return (MH_WALK_CONTINUE);
if (!MCIP_DATAPATH_SETUP(mcip))
continue;
if (lstate->mi_lenable) {
if (ret != 0) {
/*
* We can't terminate it if this is the last
* walk, else there might be some links with
* mi_desc_logged set to true, which means
* their description won't be logged the next
* time logging is started (similarly for the
* flows within such links). We can continue
* without walking the flow table (i.e. to
* set fe_desc_logged to false) because we
* won't have written any flow stuff for this
* link as we haven't logged the link itself.
*/
return (MH_WALK_CONTINUE);
else
return (MH_WALK_TERMINATE);
}
}
}
return (MH_WALK_TERMINATE);
if (lstate->mi_fenable) {
}
}
}
return (MH_WALK_CONTINUE);
}
/*
* The timer thread that runs every mac_logging_interval seconds and logs
*/
/* ARGSUSED */
void
mac_log_linkinfo(void *arg)
{
if (!mac_flow_log_enable && !mac_link_log_enable) {
return;
}
if (mac_flow_log_enable || mac_link_log_enable) {
}
}
typedef struct i_mac_fastpath_state_s {
int mf_err;
/*ARGSUSED*/
static uint_t
void *arg)
{
if (state->mf_disable)
else
}
/*
* Start the logging timer.
*/
int
{
int err;
switch (type) {
case MAC_LOGTYPE_FLOW:
if (mac_flow_log_enable) {
return (0);
}
/* FALLTHRU */
case MAC_LOGTYPE_LINK:
if (mac_link_log_enable) {
return (0);
}
break;
default:
ASSERT(0);
}
/* Disable fastpath */
/* Reenable fastpath */
return (err);
}
switch (type) {
case MAC_LOGTYPE_FLOW:
/* FALLTHRU */
case MAC_LOGTYPE_LINK:
break;
}
return (0);
}
/*
* Stop the logging timer if both Link and Flow logging are turned off.
*/
void
{
/* Last walk */
switch (type) {
case MAC_LOGTYPE_FLOW:
if (lstate.mi_fenable) {
break;
}
/* FALLTHRU */
case MAC_LOGTYPE_LINK:
return;
}
break;
default:
ASSERT(0);
}
/* Reenable fastpath */
(void) untimeout(mac_logging_timer);
mac_logging_timer = 0;
/* Last walk */
}
/*
*/
void
{
int count;
if (flent->fe_rx_srs_cnt <= 0)
return;
SRST_FLOW) {
} else {
}
}
/*
* If we have a Tx SRS, we need to modify all the threads associated
* with it.
*/
}
/*
* RX and TX rings are reserved according to different semantics depending
* on the requests from the MAC clients and type of rings:
*
* On the Tx side, by default we reserve individual rings, independently from
* the groups.
*
* On the Rx side, the reservation is at the granularity of the group
* of rings, and used for v12n level 1 only. It has a special case for the
* primary client.
*
* If a share is allocated to a MAC client, we allocate a TX group and an
* RX group to the client, and assign TX rings and RX rings to these
* groups according to information gathered from the driver through
* the share capability.
*
* The foreseable evolution of Rx rings will handle v12n level 2 and higher
* to allocate individual rings out of a group and program the hw classifier
* based on IP address or higher level criteria.
*/
/*
* mac_reserve_tx_ring()
* Reserve a unused ring by marking it with MR_INUSE state.
* As reserved, the ring is ready to function.
*
* Notes for Hybrid I/O:
*
* If a specific ring is needed, it is specified through the desired_ring
* argument. Otherwise that argument is set to NULL.
* If the desired ring was previous allocated to another client, this
* function swaps it with a new ring from the group of unassigned rings.
*/
{
/*
* Find an available ring and start it before changing its status.
* The unassigned rings are at the end of the mi_tx_groups
* array.
*/
/* Can't take the default ring out of the default group */
if (mac_start_ring(desired_ring) != 0)
return (NULL);
return (desired_ring);
}
/*
* There are clients using this ring, so let's move the clients
* away from using this ring.
*/
desired_ring));
}
return (desired_ring);
}
/*
* For a reserved group with multiple clients, return the primary client.
*/
static mac_client_impl_t *
{
return (mcip);
}
return (NULL);
}
/*
* Hybrid I/O specifies the ring that should be given to a share.
* If the ring is already used by clients, then we need to release
* the ring back to the default group so that we can give it to
* the share. This means the clients using this ring now get a
* replacement ring. If there aren't any replacement rings, this
* function returns a failure.
*/
static int
{
int i;
int j;
if (ring_type == MAC_RING_TYPE_RX) {
/* Need to put this mac client in the default group */
return (ENOSPC);
} else {
/*
* Switch this ring with some other ring from
* the default group.
*/
continue;
for (j = 0; j < nrings; j++) {
break;
}
if (j >= nrings)
break;
}
return (ENOSPC);
return (ENOSPC);
return (ENOSPC);
}
}
return (0);
}
/*
* See if we can get a spare ring to replace the default
* ring.
*/
/*
* Need to get a ring from another client, see if
* there are any clients that can be moved to
* the default group, thereby freeing some rings.
*/
for (i = 0; i < mip->mi_tx_group_count; i++) {
continue;
}
/*
* If this ring is part of the
* rings asked by the share we cannot
* use it as the default ring.
*/
for (j = 0; j < nrings; j++) {
break;
}
if (j < nrings)
continue;
defgrp);
break;
}
}
/*
* All the rings are reserved, can't give up the
* default ring.
*/
return (ENOSPC);
}
/*
* Swap the default ring with another.
*/
/*
* If this ring is part of the rings asked by the
* share we cannot use it as the default ring.
*/
for (j = 0; j < nrings; j++) {
break;
}
if (j >= nrings)
break;
}
return (0);
}
/*
* The Tx ring is with a group reserved by a MAC client. See if
* we can swap it.
*/
/* Put this mac client in the default group */
} else {
/*
* Switch this ring with some other ring from
* the default group.
*/
continue;
/*
* If this ring is part of the rings asked by the
* share we cannot use it for swapping.
*/
for (j = 0; j < nrings; j++) {
break;
}
if (j >= nrings)
break;
}
return (ENOSPC);
}
return (ENOSPC);
}
return (ENOSPC);
}
}
return (0);
}
/*
* Populate a zero-ring group with rings. If the share is non-NULL,
* the rings are chosen according to that share.
* Invoked after allocating a new RX or TX group through
* mac_reserve_rx_group() or mac_reserve_tx_group(), respectively.
* Returns zero on success, an errno otherwise.
*/
int
{
int rv = 0, i = 0, j;
(ring_type == MAC_RING_TYPE_TX &&
/*
* First find the rings to allocate to the group.
*/
/* get rings through ms_squery() */
KM_SLEEP);
for (i = 0; i < nrings; i++) {
/*
* If we have given this ring to a non-default
* group, we need to check if we can get this
* ring.
*/
goto bail;
}
}
}
} else {
/*
* Pick one ring from default group.
*
* for now pick the second ring which requires the first ring
* at index 0 to stay in the default group, since it is the
* ring which carries the multicast traffic.
* We need a better way for a driver to indicate this,
* for example a per-ring flag.
*/
KM_SLEEP);
if (ring_type == MAC_RING_TYPE_RX &&
continue;
}
if (ring_type == MAC_RING_TYPE_TX &&
continue;
}
if (i == ringcnt)
break;
}
nrings = i;
/* Not enough rings as required */
goto bail;
}
}
switch (ring_type) {
case MAC_RING_TYPE_RX:
/* we ran out of rings */
goto bail;
}
/* move receive rings to new group */
for (i = 0; i < nrings; i++) {
if (rv != 0) {
/* move rings back on failure */
for (j = 0; j < i; j++) {
(void) mac_group_mov_ring(mip,
}
goto bail;
}
}
break;
case MAC_RING_TYPE_TX: {
/* move the TX rings to the new group */
for (i = 0; i < nrings; i++) {
/* get the desired ring */
goto bail;
}
if (rv != 0) {
/* cleanup on failure */
for (j = 0; j < i; j++) {
(void) mac_group_mov_ring(mip,
rings[j]);
}
goto bail;
}
}
break;
}
}
/* add group to share */
bail:
/* free temporary array of rings */
return (rv);
}
void
{
break;
}
}
void
{
break;
}
}
/*
* mac_reserve_rx_group()
*
* Finds an available group and exclusively reserves it for a client.
* The group is chosen to suit the flow's resource controls (bandwidth and
* fanout requirements) and the address type.
* If the requestor is the pimary MAC then return the group with the
* largest number of rings, otherwise the default ring when available.
*/
{
int i;
int err = 0;
int nrings;
int donor_grp_rcnt;
int need_rings = 0;
/*
* Check if a group already has this mac address (case of VLANs)
* unless we are moving this MAC client from one group to another.
*/
}
return (NULL);
/*
* If exclusive open, return NULL which will enable the
* caller to use the default group.
*/
return (NULL);
/* For dynamic groups default unspecified to 1 */
}
/*
* For static grouping we allow only specifying rings=0 and
* unspecified
*/
return (NULL);
}
if (rxhw) {
/*
* We have explicitly asked for a group (with nrxrings,
* if unspec).
*/
} else if (mrp->mrp_nrxrings == 0) {
/*
* We have asked for a software group.
*/
return (NULL);
}
/*
* If the primary is the only active client on this
* mip and we have not asked for any rings, we give
* it the default group so that the primary gets to
* use all the rings.
*/
return (NULL);
}
/* The group that can donate rings */
/*
* The number of rings that the default group can donate.
* We need to leave at least one ring.
*/
/*
* Try to exclusively reserve a RX group.
*
* For flows requiring HW_DEFAULT_RING (unicast flow of the primary
* client), try to reserve the a non-default RX group and give
* it all the rings from the donor group, except the default ring
*
* For flows requiring HW_RING (unicast flow of other clients), try
* to reserve non-default RX group with the specified number of
* rings, if available.
*
* For flows that have not asked for software or hardware ring,
* try to reserve a non-default group with 1 ring, if available.
*/
/*
* Check if this group could be a candidate group for
* eviction if we need a group for this MAC client,
* but there aren't any. A candidate group is one
* that didn't ask for an exclusive group, but got
* one and it has enough rings (combined with what
* the donor group can donate) for the new MAC
* client
*/
/*
* group, don't bother looking for a candidate group.
* If we don't have enough rings we will check
* if the primary group can be vacated.
*/
if (candidate_grp == NULL &&
(unspec ||
need_rings))) {
candidate_grp = grp;
}
}
continue;
}
/*
* This group could already be SHARED by other multicast
* flows on this client. In that case, the group would
* be shared and has already been started.
*/
(mac_start_group(grp) != 0)) {
continue;
}
break;
/*
* Populate the group. Rings should be taken
* from the donor group.
*/
/*
* If the donor group can't donate, let's just walk and
* see if someone can vacate a group, so that we have
* enough rings for this, unless we already have
* identified a candiate group..
*/
if (nrings <= donor_grp_rcnt) {
if (err == 0) {
/*
* For a share i_mac_group_allocate_rings gets
* the rings from the driver, let's populate
* the property for the client now.
*/
}
break;
}
}
/*
* It's a dynamic group but the grouping operation
* failed.
*/
}
/* We didn't find an exclusive group for this MAC client */
if (i >= mip->mi_rx_group_count) {
if (!need_exclgrp)
return (NULL);
/*
* If we found a candidate group then we switch the
* MAC client from the candidate_group to the default
* group and give the group to this MAC client. If
* we didn't find a candidate_group, check if the
* primary is in its own group and if it can make way
* for this MAC client.
*/
if (candidate_grp == NULL &&
}
if (candidate_grp != NULL) {
/*
* Switch the MAC client from the candidate group
* to the default group.. If this group was the
* donor group, then after the switch we need
* to update the donor group too.
*/
grp = candidate_grp;
MAC_DEFAULT_RX_GROUP(mip)) != 0) {
return (NULL);
}
if (prim_grp) {
}
/*
* Now give this group with the required rings
* to this MAC client.
*/
if (mac_start_group(grp) != 0)
return (NULL);
return (grp);
if (err == 0) {
/*
* For a share i_mac_group_allocate_rings gets
* the rings from the driver, let's populate
* the property for the client now.
*/
}
return (grp);
}
}
return (NULL);
}
return (grp);
}
/*
* mac_rx_release_group()
*
* This is called when there are no clients left for the group.
* The group is stopped and marked MAC_GROUP_STATE_REGISTERED,
* and if it is a non default group, the shares are removed and
* all rings are assigned back to default group.
*/
void
{
/*
* This is the case where there are no clients left. Any
* SRS etc on this group have also be quiesced.
*/
/*
* Remove the SRS associated with the HW ring.
* As a result, polling will be disabled.
*/
}
}
}
/* remove group from share */
group->mrg_driver);
}
/*
* Rings were dynamically allocated to group.
* Move rings back to default group.
*/
ring);
}
}
/*
* Possible improvement: See if we can assign the group just released
* to a another client of the mip
*/
}
/*
* When we move the primary's mac address between groups, we need to also
* take all the clients sharing the same mac address along with it (VLANs)
* We remove the mac address for such clients from the group after quiescing
* them. When we add the mac address we restart the client. Note that
* the primary's mac address is removed from the group after all the
* other clients sharing the address are removed. Similarly, the primary's
* mac address is added before all the other client's mac address are
* added. While grp is the group where the clients reside, tgrp is
* the group where the addresses have to be added.
*/
static void
{
/*
* If the clients are in a non-default group, we just have to
* walk the group's client list. If it is in the default group
* (which will be shared by other clients as well, we need to
* check if the unicast address matches mcip's unicast.
*/
if (!add) {
} else {
}
}
}
}
/*
* Move the MAC address from fgrp to tgrp. If this is the primary client,
* we need to take any VLANs etc. together too.
*/
static int
{
int err = 0;
}
if (err != 0) {
if (multiclnt) {
B_TRUE);
}
return (err);
}
/*
* Program the H/W Classifier first, if this fails we need
* not proceed with the other stuff.
*/
/* Revert back the H/W Classifier */
/*
* This should not fail now since it worked earlier,
* should we panic?
*/
"mac_rx_switch_group: switching %p back"
" to group %p failed!!", (void *)mcip,
(void *)fgrp);
}
if (multiclnt) {
B_TRUE);
}
return (err);
}
if (multiclnt)
return (err);
}
/*
* Switch the MAC client from one group to another. This means we need
* to remove the MAC address from the group, remove the MAC client,
* teardown the SRSs and revert the group state. Then, we add the client
* to the destination group, set the SRSs, and add the MAC address to the
* group.
*/
int
{
int err;
return (err);
/*
* The group might be reserved, but SRSs may not be set up, e.g.
* primary and its vlans using a reserved group.
*/
}
}
} else {
/*
* If there are other clients (VLANs) sharing this address
* we should be here only for the primary.
*/
/*
* We need to move all the clients that are using
* this h/w address.
*/
tgrp;
}
}
}
/*
* The default group will still take the multicast,
* broadcast traffic etc., so it won't go to
* MAC_GROUP_STATE_REGISTERED.
*/
}
/*
* If the destination group is reserved, setup the SRSs etc.
*/
NULL);
} else {
}
return (0);
}
/*
* Reserves a TX group for the specified share. Invoked by mac_tx_srs_setup()
* when a share was allocated to the client.
*/
{
int rv;
int i;
int err;
int nrings;
int defnrings;
int need_rings = 0;
/*
* When we come here for a VLAN on the primary (dladm create-vlan),
* we need to pair it along with the primary (to keep it consistent
* with the RX side). So, we check if the primary is already assigned
* to a group and return the group if so. The other way is also
* true, i.e. the VLAN is already created and now we are plumbing
* the primary.
*/
}
}
}
return (NULL);
/* For dynamic groups, default unspec to 1 */
}
/*
* For static grouping we allow only specifying rings=0 and
* unspecified
*/
return (NULL);
}
if (txhw) {
/*
* We have explicitly asked for a group (with ntxrings,
* if unspec).
*/
} else if (mrp->mrp_ntxrings == 0) {
/*
* We have asked for a software group.
*/
return (NULL);
}
}
/*
* The number of rings that the default group can donate.
* We need to leave at least one ring - the default ring - in
* this group.
*/
/*
* Primary gets default group unless explicitly told not
* to (i.e. rings > 0).
*/
if (isprimary && !need_exclgrp)
return (NULL);
for (i = 0; i < mip->mi_tx_group_count; i++) {
/*
* Select a candidate for replacement if we don't
* get an exclusive group. A candidate group is one
* that didn't ask for an exclusive group, but got
* one and it has enough rings (combined with what
* the default group can donate) for the new MAC
* client.
*/
candidate_grp == NULL) {
(unspec ||
need_rings)) {
candidate_grp = grp;
}
}
continue;
}
/*
* If the default can't donate let's just walk and
* see if someone can vacate a group, so that we have
* enough rings for this.
*/
}
break;
}
}
/* The default group */
if (i >= mip->mi_tx_group_count) {
/*
* If we need an exclusive group and have identified a
* candidate group we switch the MAC client from the
* candidate group to the default group and give the
* candidate group to this client.
*/
/*
* Switch the MAC client from the candidate group
* to the default group.
*/
grp = candidate_grp;
/*
* Give the candidate group with the specified number
* of rings to this MAC client.
*/
return (grp);
if (err == 0) {
/*
* For a share i_mac_group_allocate_rings gets
* the rings from the driver, let's populate
* the property for the client now.
*/
grp->mrg_cur_count);
}
mip->mi_tx_group_free--;
return (grp);
}
}
return (NULL);
}
/*
* We got an exclusive group, but it is not dynamic.
*/
mip->mi_tx_group_free--;
return (grp);
}
if (rv != 0) {
return (NULL);
}
/*
* For a share i_mac_group_allocate_rings gets the rings from the
* driver, let's populate the property for the client now.
*/
grp->mrg_cur_count);
}
mip->mi_tx_group_free--;
return (grp);
}
void
{
if (srs->srs_soft_ring_count > 0) {
}
} else {
}
}
/* move the ring back to the pool */
}
mip->mi_tx_group_free++;
}
/*
* Disassociate a MAC client from a group, i.e go through the rings in the
* group and delete all the soft rings tied to them.
*/
static void
{
/* Single ring case we haven't created any soft rings */
/* Fanout case, where we have to dismantle the soft rings */
} else {
ring));
}
}
}
/*
* Switch the MAC client from one group to another. This means we need
* to remove the MAC client, teardown the SRSs and revert the group state.
* Then, we add the client to the destination roup, set the SRSs etc.
*/
void
{
/*
* If this is the primary we need to find any VLANs on
* the primary and move them too.
*/
continue;
/* We could directly set this to SHARED */
}
}
if (MAC_GROUP_NO_CLIENT(fgrp)) {
int cnt;
int ringcnt;
/*
* Additionally, we also need to stop all
* the rings in the default group, except
* the default ring. The reason being
* this group won't be released since it is
* the default group, so the rings won't
* be stopped otherwise.
*/
ring !=
}
}
} else {
}
} else {
/*
* We could have VLANs sharing the non-default group with
* the primary.
*/
continue;
/* We could directly set this to SHARED */
}
}
/* Add it to the tgroup */
}
/*
* This is a 1-time control path activity initiated by the client (IP).
* The mac perimeter protects against other simultaneous control activities,
* for example an ioctl that attempts to change the degree of fanout and
* increase or decrease the number of softrings associated with this Tx SRS.
*/
static mac_tx_notify_cb_t *
{
return (mtnfp);
}
static void
{
"mac_client_tx_notify_remove: callback not "
return;
}
else
}
/*
* mac_client_tx_notify():
* call to add and remove flow control callback routine.
*/
void *ptr)
{
if (callb_func != NULL) {
/* Add a notify callback */
} else {
}
return ((mac_tx_notify_handle_t)mtnfp);
}
void
{
}
int
{
int retv;
retv = 0;
} else {
}
if (retv == 0) {
}
return (retv);
}
/*
* Disable bridging on the indicated link.
*/
void
{
}
void
{
}
/*
* Walk the primary VLAN clients whenever the primary's rings property
* changes and update the mac_resource_props_t for the VLAN's client.
* We need to do this since we don't support setting these properties
* on the primary's VLAN clients, but the VLAN clients have to
* follow the primary w.r.t the rings property;
*/
void
{
VLAN_ID_NONE) {
continue;
}
else
else
}
}
/*
* We are adding or removing ring(s) from a group. The source for taking
* rings is the default group. The destination for giving rings back is
* the default group.
*/
int
{
int count;
mac_ring_t **rings;
int i = 0;
int start;
int end;
int j;
int rv = 0;
/*
* If we are asked for just a group, we give 1 ring, else
* the specified number of rings.
*/
if (rx_group) {
} else {
}
/* don't allow modifying rings for a share for now. */
return (0);
if (rx_group) {
} else {
}
}
KM_SLEEP);
j = 0;
if (rv != 0) {
/* cleanup on failure */
for (j = 0; j < count; j++) {
rings[j]);
}
break;
}
}
return (rv);
}
if (ringcnt >= MAX_RINGS_PER_GROUP)
return (EINVAL);
if (rx_group) {
else
/*
* This is the donor group with all the remaining
* rings. Default group now gets to be the donor
*/
start = 1;
} else {
start = 0;
}
/*
* If the default doesn't have any rings, lets see if we can
* take rings given to an h/w client that doesn't need it.
* For now, we just see if there is any one client that can donate
* all the required rings.
*/
if (rx_group) {
continue;
}
continue;
if ((tgrp->mrg_cur_count +
continue;
}
defgrp) != 0) {
return (ENOSPC);
}
} else {
continue;
}
continue;
if ((tgrp->mrg_cur_count +
continue;
}
/* OK, we can switch this to s/w */
}
}
return (ENOSPC);
}
return (rv);
}
return (0);
}
/*
* Given the poolname in mac_resource_props, find the cpupart
* that is associated with this pool. The cpupart will be used
* later for finding the cpus to be bound to the networking threads.
*
* use_default is set B_TRUE if pools are enabled and pool_default
* is returned. This avoids a 2nd lookup to set the poolname
* for pool-effective.
*
* returns:
*
* NULL - pools are disabled or if the 'cpus' property is set.
* cpupart of pool_default - pools are enabled and the pool
* is not available or poolname is blank
* cpupart of named pool - pools are enabled and the pool
* is available.
*/
{
*use_default = B_FALSE;
/* CPUs property is set */
return (NULL);
ASSERT(pool_lock_held());
/* Pools are disabled, no pset */
if (pool_state == POOL_DISABLED)
return (NULL);
/* Pools property is set */
/* Pool not found */
DTRACE_PROBE1(mac_pset_find_no_pool, char *,
*use_default = B_TRUE;
pool = pool_default;
}
/* Pools property is not set */
} else {
*use_default = B_TRUE;
pool = pool_default;
}
/* Find the CPU pset that corresponds to the pool */
}
return (cpupart);
}
void
{
ASSERT(pool_lock_held());
if (use_default) {
"pool_default");
} else {
}
} else {
}
}
struct mac_pool_arg {
char mpa_poolname[MAXPATHLEN];
};
/*ARGSUSED*/
static uint_t
{
/*
* When pools are enabled
*/
}
/*
* When pools are disabled
*/
pool_clear = B_TRUE;
}
/*
* Look for links with the pool property set and the poolname
* matching the one which is changing.
*/
/*
* The pool associated with the link has changed.
*/
}
}
/*
* This link is associated with pool_default and
* pool_default has changed.
*/
}
/*
* Get new list of cpus for the pool, bind network
* threads to new list of cpus and update resources.
*/
if (pool_update) {
if (MCIP_DATAPATH_SETUP(mcip)) {
pool_lock();
pool_unlock();
}
B_FALSE);
}
/*
* Clear the effective pool and bind network threads
* to any available CPU.
*/
if (pool_clear) {
if (MCIP_DATAPATH_SETUP(mcip)) {
}
B_FALSE);
}
}
return (MH_WALK_CONTINUE);
}
static void
mac_pool_update(void *arg)
{
}
/*
* Callback function to be executed when a noteworthy pool event
* takes place.
*/
/* ARGSUSED */
static void
{
struct mac_pool_arg *mpa;
pool_lock();
switch (what) {
case POOL_E_ENABLE:
case POOL_E_DISABLE:
break;
case POOL_E_CHANGE:
pool_unlock();
return;
}
sizeof (mpa->mpa_poolname));
break;
default:
pool_unlock();
return;
}
pool_unlock();
}
/*
* Set effective rings property. This could be called from datapath_setup/
* datapath_teardown or set-linkprop.
* If the group is reserved we just go ahead and set the effective rings.
* some rings, so if the default group is reserved, we need to adjust the
* effective rings for the default group clients. For RX, if we are working
* with the non-default group, we just need * to reset the effective props
* for the default group clients.
*/
void
{
/*
* If we have reserved a group, set the effective rings
* to the ring count in the group.
*/
}
/*
* We go through the clients in the shared group and
* reset the effective properties. It is possible this
* might have already been done for some client (i.e.
* if some client is being moved to a group that is
* already shared). The case where the default group is
* RESERVED is taken care of above (note in the RX side if
* there is a non-default group, the default group is always
* SHARED).
*/
else
emrp->mrp_nrxrings = 0;
}
}
}
}
/* Now the TX side */
emrp->mrp_ntxrings = 0;
}
}
}
/*
* If the group is not the default group and the default
* group is reserved, the ring count in the default group
* might have changed, update it.
*/
}
}
}
/*
* Check if the primary is in the default group. If so, see if we
* can give it a an exclusive group now that another client is
* being configured. We take the primary out of the default group
* will land in the default ring in the default group which means
* any client in the default group, even if it is the only on in
* the group, will lose exclusive access to the rings, hence
* polling.
*/
{
/*
* Check if the primary is in the default group, if not
* or if it is explicitly configured to be in the default
* group OR set the RX rings property, return.
*/
return (NULL);
/*
* If the new client needs an exclusive group and we
* don't have another for the primary, return.
*/
return (NULL);
/*
* We call this when we are setting up the datapath for
* the first non-primary.
*/
/*
* OK, now we have the primary that needs to be relocated.
*/
return (NULL);
return (NULL);
}
return (mcip);
}