/*
* Copyright (c) 2021 Internet Initiative Japan Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* storage size of sc_if is a variable-length,
* should be the last
*/
struct ifnet sc_if;
};
/*
* Locking notes:
* - sc_lock(LAGG_LOCK()) is an adaptive mutex and protects items
* of struct lagg_softc
* - a lock in struct lagg_proto_softc, for example LACP_LOCK(), is
* an adaptive mutex and protects member contained in the struct
* - sc_var is protected by both pselialize (sc_psz) and psref (lv_psref)
* - Updates of sc_var is serialized by sc_lock
* - Items in sc_ports is protected by both psref (lp_psref) and
* pserialize contained in struct lagg_proto_softc
* - details are described in if_laggport.c and if_lagg_lacp.c
* - Updates of items in sc_ports are serialized by sc_lock
* - an instance referenced by lp_proto_ctx in struct lagg_port is
* protected by a lock in struct lagg_proto_softc
*
* Locking order:
* - IFNET_LOCK(sc_if) -> LAGG_LOCK -> ETHER_LOCK(sc_if) -> a lock in
* struct lagg_port_softc
* - IFNET_LOCK(sc_if) -> LAGG_LOCK -> IFNET_LOCK(lp_ifp)
* - IFNET_LOCK(lp_ifp) -> a lock in struct lagg_proto_softc
* - Currently, there is no combination of following locks
* - IFNET_LOCK(lp_ifp) and ETHER_LOCK(sc_if)
*/
#define LAGG_LOCK(_sc) mutex_enter(&(_sc)->sc_lock)
#define LAGG_UNLOCK(_sc) mutex_exit(&(_sc)->sc_lock)
#define LAGG_LOCKED(_sc) mutex_owned(&(_sc)->sc_lock)
#define LAGG_CLLADDR(_sc) CLLADDR((_sc)->sc_if.if_sadl)