18275SEric Cheng /*
28275SEric Cheng * CDDL HEADER START
38275SEric Cheng *
48275SEric Cheng * The contents of this file are subject to the terms of the
58275SEric Cheng * Common Development and Distribution License (the "License").
68275SEric Cheng * You may not use this file except in compliance with the License.
78275SEric Cheng *
88275SEric Cheng * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98275SEric Cheng * or http://www.opensolaris.org/os/licensing.
108275SEric Cheng * See the License for the specific language governing permissions
118275SEric Cheng * and limitations under the License.
128275SEric Cheng *
138275SEric Cheng * When distributing Covered Code, include this CDDL HEADER in each
148275SEric Cheng * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
158275SEric Cheng * If applicable, add the following below this CDDL HEADER, with the
168275SEric Cheng * fields enclosed by brackets "[]" replaced with your own identifying
178275SEric Cheng * information: Portions Copyright [yyyy] [name of copyright owner]
188275SEric Cheng *
198275SEric Cheng * CDDL HEADER END
208275SEric Cheng */
218275SEric Cheng
228275SEric Cheng /*
2312062SRajagopal.Kunhappan@Sun.COM * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
248275SEric Cheng */
258275SEric Cheng
268275SEric Cheng /*
278275SEric Cheng * - General Introduction:
288275SEric Cheng *
298275SEric Cheng * This file contains the implementation of the MAC client kernel
308275SEric Cheng * API and related code. The MAC client API allows a kernel module
318275SEric Cheng * to gain access to a MAC instance (physical NIC, link aggregation, etc).
328275SEric Cheng * It allows a MAC client to associate itself with a MAC address,
338275SEric Cheng * VLANs, callback functions for data traffic and for promiscuous mode.
348275SEric Cheng * The MAC client API is also used to specify the properties associated
358275SEric Cheng * with a MAC client, such as bandwidth limits, priority, CPUS, etc.
368275SEric Cheng * These properties are further used to determine the hardware resources
378275SEric Cheng * to allocate to the various MAC clients.
388275SEric Cheng *
398275SEric Cheng * - Primary MAC clients:
408275SEric Cheng *
418275SEric Cheng * The MAC client API refers to "primary MAC clients". A primary MAC
428275SEric Cheng * client is a client which "owns" the primary MAC address of
438275SEric Cheng * the underlying MAC instance. The primary MAC address is called out
448275SEric Cheng * since it is associated with specific semantics: the primary MAC
458275SEric Cheng * address is the MAC address which is assigned to the IP interface
468275SEric Cheng * when it is plumbed, and the primary MAC address is assigned
478275SEric Cheng * to VLAN data-links. The primary address of a MAC instance can
488275SEric Cheng * also change dynamically from under the MAC client, for example
498275SEric Cheng * as a result of a change of state of a link aggregation. In that
508275SEric Cheng * case the MAC layer automatically updates all data-structures which
518275SEric Cheng * refer to the current value of the primary MAC address. Typical
528275SEric Cheng * primary MAC clients are dls, aggr, and xnb. A typical non-primary
538275SEric Cheng * MAC client is the vnic driver.
548275SEric Cheng *
558275SEric Cheng * - Virtual Switching:
568275SEric Cheng *
578275SEric Cheng * The MAC layer implements a virtual switch between the MAC clients
588275SEric Cheng * (primary and non-primary) defined on top of the same underlying
598275SEric Cheng * NIC (physical, link aggregation, etc). The virtual switch is
608275SEric Cheng * VLAN-aware, i.e. it allows multiple MAC clients to be member
618275SEric Cheng * of one or more VLANs, and the virtual switch will distribute
628275SEric Cheng * multicast tagged packets only to the member of the corresponding
638275SEric Cheng * VLANs.
648275SEric Cheng *
658275SEric Cheng * - Upper vs Lower MAC:
668275SEric Cheng *
678275SEric Cheng * Creating a VNIC on top of a MAC instance effectively causes
688275SEric Cheng * two MAC instances to be layered on top of each other, one for
698275SEric Cheng * the VNIC(s), one for the underlying MAC instance (physical NIC,
708275SEric Cheng * link aggregation, etc). In the code below we refer to the
718275SEric Cheng * underlying NIC as the "lower MAC", and we refer to VNICs as
728275SEric Cheng * the "upper MAC".
738275SEric Cheng *
748275SEric Cheng * - Pass-through for VNICs:
758275SEric Cheng *
768275SEric Cheng * When VNICs are created on top of an underlying MAC, this causes
778275SEric Cheng * a layering of two MAC instances. Since the lower MAC already
788275SEric Cheng * does the switching and demultiplexing to its MAC clients, the
798275SEric Cheng * upper MAC would simply have to pass packets to the layer below
808275SEric Cheng * or above it, which would introduce overhead. In order to avoid
818275SEric Cheng * this overhead, the MAC layer implements a pass-through mechanism
828275SEric Cheng * for VNICs. When a VNIC opens the lower MAC instance, it saves
838275SEric Cheng * the MAC client handle it optains from the MAC layer. When a MAC
848275SEric Cheng * client opens a VNIC (upper MAC), the MAC layer detects that
858275SEric Cheng * the MAC being opened is a VNIC, and gets the MAC client handle
868275SEric Cheng * that the VNIC driver obtained from the lower MAC. This exchange
878275SEric Cheng * is doing through a private capability between the MAC layer
888275SEric Cheng * and the VNIC driver. The upper MAC then returns that handle
898275SEric Cheng * directly to its MAC client. Any operation done by the upper
908275SEric Cheng * MAC client is now done on the lower MAC client handle, which
918275SEric Cheng * allows the VNIC driver to be completely bypassed for the
928275SEric Cheng * performance sensitive data-path.
938275SEric Cheng *
948275SEric Cheng */
958275SEric Cheng
968275SEric Cheng #include <sys/types.h>
978275SEric Cheng #include <sys/conf.h>
988275SEric Cheng #include <sys/id_space.h>
998275SEric Cheng #include <sys/esunddi.h>
1008275SEric Cheng #include <sys/stat.h>
1018275SEric Cheng #include <sys/mkdev.h>
1028275SEric Cheng #include <sys/stream.h>
1038275SEric Cheng #include <sys/strsun.h>
1048275SEric Cheng #include <sys/strsubr.h>
1058275SEric Cheng #include <sys/dlpi.h>
1068275SEric Cheng #include <sys/modhash.h>
1078275SEric Cheng #include <sys/mac_impl.h>
1088275SEric Cheng #include <sys/mac_client_impl.h>
1098275SEric Cheng #include <sys/mac_soft_ring.h>
11011878SVenu.Iyer@Sun.COM #include <sys/mac_stat.h>
1118275SEric Cheng #include <sys/dls.h>
1128275SEric Cheng #include <sys/dld.h>
1138275SEric Cheng #include <sys/modctl.h>
1148275SEric Cheng #include <sys/fs/dv_node.h>
1158275SEric Cheng #include <sys/thread.h>
1168275SEric Cheng #include <sys/proc.h>
1178275SEric Cheng #include <sys/callb.h>
1188275SEric Cheng #include <sys/cpuvar.h>
1198275SEric Cheng #include <sys/atomic.h>
1208275SEric Cheng #include <sys/sdt.h>
1218275SEric Cheng #include <sys/mac_flow.h>
1228275SEric Cheng #include <sys/ddi_intr_impl.h>
1238275SEric Cheng #include <sys/disp.h>
1248275SEric Cheng #include <sys/sdt.h>
1258275SEric Cheng #include <sys/vnic.h>
1268275SEric Cheng #include <sys/vnic_impl.h>
1278275SEric Cheng #include <sys/vlan.h>
1288275SEric Cheng #include <inet/ip.h>
1298275SEric Cheng #include <inet/ip6.h>
1308275SEric Cheng #include <sys/exacct.h>
1318275SEric Cheng #include <sys/exacct_impl.h>
1328275SEric Cheng #include <inet/nd.h>
1338275SEric Cheng #include <sys/ethernet.h>
1348275SEric Cheng
1358275SEric Cheng kmem_cache_t *mac_client_impl_cache;
1368275SEric Cheng kmem_cache_t *mac_promisc_impl_cache;
1378275SEric Cheng
1388275SEric Cheng static boolean_t mac_client_single_rcvr(mac_client_impl_t *);
1398275SEric Cheng static flow_entry_t *mac_client_swap_mciflent(mac_client_impl_t *);
1408275SEric Cheng static flow_entry_t *mac_client_get_flow(mac_client_impl_t *,
1418275SEric Cheng mac_unicast_impl_t *);
1428275SEric Cheng static void mac_client_remove_flow_from_list(mac_client_impl_t *,
1438275SEric Cheng flow_entry_t *);
1448275SEric Cheng static void mac_client_add_to_flow_list(mac_client_impl_t *, flow_entry_t *);
1458275SEric Cheng static void mac_rename_flow_names(mac_client_impl_t *, const char *);
1468275SEric Cheng static void mac_virtual_link_update(mac_impl_t *);
14711878SVenu.Iyer@Sun.COM static int mac_client_datapath_setup(mac_client_impl_t *, uint16_t,
14811878SVenu.Iyer@Sun.COM uint8_t *, mac_resource_props_t *, boolean_t, mac_unicast_impl_t *);
14911878SVenu.Iyer@Sun.COM static void mac_client_datapath_teardown(mac_client_handle_t,
15011878SVenu.Iyer@Sun.COM mac_unicast_impl_t *, flow_entry_t *);
1518275SEric Cheng
1528275SEric Cheng /* ARGSUSED */
1538275SEric Cheng static int
i_mac_client_impl_ctor(void * buf,void * arg,int kmflag)1548275SEric Cheng i_mac_client_impl_ctor(void *buf, void *arg, int kmflag)
1558275SEric Cheng {
1568275SEric Cheng int i;
1578275SEric Cheng mac_client_impl_t *mcip = buf;
1588275SEric Cheng
1598275SEric Cheng bzero(buf, MAC_CLIENT_IMPL_SIZE);
1608275SEric Cheng mutex_init(&mcip->mci_tx_cb_lock, NULL, MUTEX_DRIVER, NULL);
1618275SEric Cheng mcip->mci_tx_notify_cb_info.mcbi_lockp = &mcip->mci_tx_cb_lock;
1628275SEric Cheng
1638275SEric Cheng ASSERT(mac_tx_percpu_cnt >= 0);
1648275SEric Cheng for (i = 0; i <= mac_tx_percpu_cnt; i++) {
1658275SEric Cheng mutex_init(&mcip->mci_tx_pcpu[i].pcpu_tx_lock, NULL,
1668275SEric Cheng MUTEX_DRIVER, NULL);
1678275SEric Cheng }
1688275SEric Cheng cv_init(&mcip->mci_tx_cv, NULL, CV_DRIVER, NULL);
1698275SEric Cheng
1708275SEric Cheng return (0);
1718275SEric Cheng }
1728275SEric Cheng
1738275SEric Cheng /* ARGSUSED */
1748275SEric Cheng static void
i_mac_client_impl_dtor(void * buf,void * arg)1758275SEric Cheng i_mac_client_impl_dtor(void *buf, void *arg)
1768275SEric Cheng {
1778275SEric Cheng int i;
1788275SEric Cheng mac_client_impl_t *mcip = buf;
1798275SEric Cheng
1808275SEric Cheng ASSERT(mcip->mci_promisc_list == NULL);
1818275SEric Cheng ASSERT(mcip->mci_unicast_list == NULL);
1828275SEric Cheng ASSERT(mcip->mci_state_flags == 0);
1838275SEric Cheng ASSERT(mcip->mci_tx_flag == 0);
1848275SEric Cheng
1858275SEric Cheng mutex_destroy(&mcip->mci_tx_cb_lock);
1868275SEric Cheng
1878275SEric Cheng ASSERT(mac_tx_percpu_cnt >= 0);
1888275SEric Cheng for (i = 0; i <= mac_tx_percpu_cnt; i++) {
1898275SEric Cheng ASSERT(mcip->mci_tx_pcpu[i].pcpu_tx_refcnt == 0);
1908275SEric Cheng mutex_destroy(&mcip->mci_tx_pcpu[i].pcpu_tx_lock);
1918275SEric Cheng }
1928275SEric Cheng cv_destroy(&mcip->mci_tx_cv);
1938275SEric Cheng }
1948275SEric Cheng
1958275SEric Cheng /* ARGSUSED */
1968275SEric Cheng static int
i_mac_promisc_impl_ctor(void * buf,void * arg,int kmflag)1978275SEric Cheng i_mac_promisc_impl_ctor(void *buf, void *arg, int kmflag)
1988275SEric Cheng {
1998275SEric Cheng mac_promisc_impl_t *mpip = buf;
2008275SEric Cheng
2018275SEric Cheng bzero(buf, sizeof (mac_promisc_impl_t));
2028275SEric Cheng mpip->mpi_mci_link.mcb_objp = buf;
2038275SEric Cheng mpip->mpi_mci_link.mcb_objsize = sizeof (mac_promisc_impl_t);
2048275SEric Cheng mpip->mpi_mi_link.mcb_objp = buf;
2058275SEric Cheng mpip->mpi_mi_link.mcb_objsize = sizeof (mac_promisc_impl_t);
2068275SEric Cheng return (0);
2078275SEric Cheng }
2088275SEric Cheng
2098275SEric Cheng /* ARGSUSED */
2108275SEric Cheng static void
i_mac_promisc_impl_dtor(void * buf,void * arg)2118275SEric Cheng i_mac_promisc_impl_dtor(void *buf, void *arg)
2128275SEric Cheng {
2138275SEric Cheng mac_promisc_impl_t *mpip = buf;
2148275SEric Cheng
2158275SEric Cheng ASSERT(mpip->mpi_mci_link.mcb_objp != NULL);
2168275SEric Cheng ASSERT(mpip->mpi_mci_link.mcb_objsize == sizeof (mac_promisc_impl_t));
2178275SEric Cheng ASSERT(mpip->mpi_mi_link.mcb_objp == mpip->mpi_mci_link.mcb_objp);
2188275SEric Cheng ASSERT(mpip->mpi_mi_link.mcb_objsize == sizeof (mac_promisc_impl_t));
2198275SEric Cheng
2208275SEric Cheng mpip->mpi_mci_link.mcb_objp = NULL;
2218275SEric Cheng mpip->mpi_mci_link.mcb_objsize = 0;
2228275SEric Cheng mpip->mpi_mi_link.mcb_objp = NULL;
2238275SEric Cheng mpip->mpi_mi_link.mcb_objsize = 0;
2248275SEric Cheng
2258275SEric Cheng ASSERT(mpip->mpi_mci_link.mcb_flags == 0);
2268275SEric Cheng mpip->mpi_mci_link.mcb_objsize = 0;
2278275SEric Cheng }
2288275SEric Cheng
2298275SEric Cheng void
mac_client_init(void)2308275SEric Cheng mac_client_init(void)
2318275SEric Cheng {
2328275SEric Cheng ASSERT(mac_tx_percpu_cnt >= 0);
2338275SEric Cheng
2348275SEric Cheng mac_client_impl_cache = kmem_cache_create("mac_client_impl_cache",
2358275SEric Cheng MAC_CLIENT_IMPL_SIZE, 0, i_mac_client_impl_ctor,
2368275SEric Cheng i_mac_client_impl_dtor, NULL, NULL, NULL, 0);
2378275SEric Cheng ASSERT(mac_client_impl_cache != NULL);
2388275SEric Cheng
2398275SEric Cheng mac_promisc_impl_cache = kmem_cache_create("mac_promisc_impl_cache",
2408275SEric Cheng sizeof (mac_promisc_impl_t), 0, i_mac_promisc_impl_ctor,
2418275SEric Cheng i_mac_promisc_impl_dtor, NULL, NULL, NULL, 0);
2428275SEric Cheng ASSERT(mac_promisc_impl_cache != NULL);
2438275SEric Cheng }
2448275SEric Cheng
2458275SEric Cheng void
mac_client_fini(void)2468275SEric Cheng mac_client_fini(void)
2478275SEric Cheng {
2488275SEric Cheng kmem_cache_destroy(mac_client_impl_cache);
2498275SEric Cheng kmem_cache_destroy(mac_promisc_impl_cache);
2508275SEric Cheng }
2518275SEric Cheng
2528275SEric Cheng /*
2538275SEric Cheng * Return the lower MAC client handle from the VNIC driver for the
2548275SEric Cheng * specified VNIC MAC instance.
2558275SEric Cheng */
2568275SEric Cheng mac_client_impl_t *
mac_vnic_lower(mac_impl_t * mip)2578275SEric Cheng mac_vnic_lower(mac_impl_t *mip)
2588275SEric Cheng {
2598275SEric Cheng mac_capab_vnic_t cap;
2608275SEric Cheng mac_client_impl_t *mcip;
2618275SEric Cheng
2628275SEric Cheng VERIFY(i_mac_capab_get((mac_handle_t)mip, MAC_CAPAB_VNIC, &cap));
2638275SEric Cheng mcip = cap.mcv_mac_client_handle(cap.mcv_arg);
2648275SEric Cheng
2658275SEric Cheng return (mcip);
2668275SEric Cheng }
2678275SEric Cheng
2688275SEric Cheng /*
2698275SEric Cheng * Return the MAC client handle of the primary MAC client for the
2708275SEric Cheng * specified MAC instance, or NULL otherwise.
2718275SEric Cheng */
2728275SEric Cheng mac_client_impl_t *
mac_primary_client_handle(mac_impl_t * mip)2738275SEric Cheng mac_primary_client_handle(mac_impl_t *mip)
2748275SEric Cheng {
2758275SEric Cheng mac_client_impl_t *mcip;
2768275SEric Cheng
2778275SEric Cheng if (mip->mi_state_flags & MIS_IS_VNIC)
2788275SEric Cheng return (mac_vnic_lower(mip));
2798275SEric Cheng
2808275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
2818275SEric Cheng
2828275SEric Cheng for (mcip = mip->mi_clients_list; mcip != NULL;
2838275SEric Cheng mcip = mcip->mci_client_next) {
2848275SEric Cheng if (MCIP_DATAPATH_SETUP(mcip) && mac_is_primary_client(mcip))
2858275SEric Cheng return (mcip);
2868275SEric Cheng }
2878275SEric Cheng return (NULL);
2888275SEric Cheng }
2898275SEric Cheng
2908275SEric Cheng /*
2918275SEric Cheng * Open a MAC specified by its MAC name.
2928275SEric Cheng */
2938275SEric Cheng int
mac_open(const char * macname,mac_handle_t * mhp)2948275SEric Cheng mac_open(const char *macname, mac_handle_t *mhp)
2958275SEric Cheng {
2968275SEric Cheng mac_impl_t *mip;
2978275SEric Cheng int err;
2988275SEric Cheng
2998275SEric Cheng /*
3008275SEric Cheng * Look up its entry in the global hash table.
3018275SEric Cheng */
3028275SEric Cheng if ((err = mac_hold(macname, &mip)) != 0)
3038275SEric Cheng return (err);
3048275SEric Cheng
3058275SEric Cheng /*
3068275SEric Cheng * Hold the dip associated to the MAC to prevent it from being
3078275SEric Cheng * detached. For a softmac, its underlying dip is held by the
3088275SEric Cheng * mi_open() callback.
3098275SEric Cheng *
3108275SEric Cheng * This is done to be more tolerant with some defective drivers,
3118275SEric Cheng * which incorrectly handle mac_unregister() failure in their
3128275SEric Cheng * xxx_detach() routine. For example, some drivers ignore the
3138275SEric Cheng * failure of mac_unregister() and free all resources that
3148275SEric Cheng * that are needed for data transmition.
3158275SEric Cheng */
3168275SEric Cheng e_ddi_hold_devi(mip->mi_dip);
3178275SEric Cheng
3188275SEric Cheng if (!(mip->mi_callbacks->mc_callbacks & MC_OPEN)) {
3198275SEric Cheng *mhp = (mac_handle_t)mip;
3208275SEric Cheng return (0);
3218275SEric Cheng }
3228275SEric Cheng
3238275SEric Cheng /*
3248275SEric Cheng * The mac perimeter is used in both mac_open and mac_close by the
3258275SEric Cheng * framework to single thread the MC_OPEN/MC_CLOSE of drivers.
3268275SEric Cheng */
3278275SEric Cheng i_mac_perim_enter(mip);
3288275SEric Cheng mip->mi_oref++;
3298275SEric Cheng if (mip->mi_oref != 1 || ((err = mip->mi_open(mip->mi_driver)) == 0)) {
3308275SEric Cheng *mhp = (mac_handle_t)mip;
3318275SEric Cheng i_mac_perim_exit(mip);
3328275SEric Cheng return (0);
3338275SEric Cheng }
3348275SEric Cheng mip->mi_oref--;
3358275SEric Cheng ddi_release_devi(mip->mi_dip);
3368275SEric Cheng mac_rele(mip);
3378275SEric Cheng i_mac_perim_exit(mip);
3388275SEric Cheng return (err);
3398275SEric Cheng }
3408275SEric Cheng
3418275SEric Cheng /*
3428275SEric Cheng * Open a MAC specified by its linkid.
3438275SEric Cheng */
3448275SEric Cheng int
mac_open_by_linkid(datalink_id_t linkid,mac_handle_t * mhp)3458275SEric Cheng mac_open_by_linkid(datalink_id_t linkid, mac_handle_t *mhp)
3468275SEric Cheng {
3478275SEric Cheng dls_dl_handle_t dlh;
3488275SEric Cheng int err;
3498275SEric Cheng
3508275SEric Cheng if ((err = dls_devnet_hold_tmp(linkid, &dlh)) != 0)
3518275SEric Cheng return (err);
3528275SEric Cheng
3538275SEric Cheng dls_devnet_prop_task_wait(dlh);
3548275SEric Cheng
3558275SEric Cheng err = mac_open(dls_devnet_mac(dlh), mhp);
3568275SEric Cheng
3578275SEric Cheng dls_devnet_rele_tmp(dlh);
3588275SEric Cheng return (err);
3598275SEric Cheng }
3608275SEric Cheng
3618275SEric Cheng /*
3628275SEric Cheng * Open a MAC specified by its link name.
3638275SEric Cheng */
3648275SEric Cheng int
mac_open_by_linkname(const char * link,mac_handle_t * mhp)3658275SEric Cheng mac_open_by_linkname(const char *link, mac_handle_t *mhp)
3668275SEric Cheng {
3678275SEric Cheng datalink_id_t linkid;
3688275SEric Cheng int err;
3698275SEric Cheng
3708275SEric Cheng if ((err = dls_mgmt_get_linkid(link, &linkid)) != 0)
3718275SEric Cheng return (err);
3728275SEric Cheng return (mac_open_by_linkid(linkid, mhp));
3738275SEric Cheng }
3748275SEric Cheng
3758275SEric Cheng /*
3768275SEric Cheng * Close the specified MAC.
3778275SEric Cheng */
3788275SEric Cheng void
mac_close(mac_handle_t mh)3798275SEric Cheng mac_close(mac_handle_t mh)
3808275SEric Cheng {
3818275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
3828275SEric Cheng
3838275SEric Cheng i_mac_perim_enter(mip);
3848275SEric Cheng /*
3858275SEric Cheng * The mac perimeter is used in both mac_open and mac_close by the
3868275SEric Cheng * framework to single thread the MC_OPEN/MC_CLOSE of drivers.
3878275SEric Cheng */
3888275SEric Cheng if (mip->mi_callbacks->mc_callbacks & MC_OPEN) {
3898275SEric Cheng ASSERT(mip->mi_oref != 0);
3908275SEric Cheng if (--mip->mi_oref == 0) {
3918275SEric Cheng if ((mip->mi_callbacks->mc_callbacks & MC_CLOSE))
3928275SEric Cheng mip->mi_close(mip->mi_driver);
3938275SEric Cheng }
3948275SEric Cheng }
3958275SEric Cheng i_mac_perim_exit(mip);
3968275SEric Cheng ddi_release_devi(mip->mi_dip);
3978275SEric Cheng mac_rele(mip);
3988275SEric Cheng }
3998275SEric Cheng
4008275SEric Cheng /*
4018275SEric Cheng * Misc utility functions to retrieve various information about a MAC
4028275SEric Cheng * instance or a MAC client.
4038275SEric Cheng */
4048275SEric Cheng
4058275SEric Cheng const mac_info_t *
mac_info(mac_handle_t mh)4068275SEric Cheng mac_info(mac_handle_t mh)
4078275SEric Cheng {
4088275SEric Cheng return (&((mac_impl_t *)mh)->mi_info);
4098275SEric Cheng }
4108275SEric Cheng
4118275SEric Cheng dev_info_t *
mac_devinfo_get(mac_handle_t mh)4128275SEric Cheng mac_devinfo_get(mac_handle_t mh)
4138275SEric Cheng {
4148275SEric Cheng return (((mac_impl_t *)mh)->mi_dip);
4158275SEric Cheng }
4168275SEric Cheng
4179073SCathy.Zhou@Sun.COM void *
mac_driver(mac_handle_t mh)4189073SCathy.Zhou@Sun.COM mac_driver(mac_handle_t mh)
4199073SCathy.Zhou@Sun.COM {
4209073SCathy.Zhou@Sun.COM return (((mac_impl_t *)mh)->mi_driver);
4219073SCathy.Zhou@Sun.COM }
4229073SCathy.Zhou@Sun.COM
4238275SEric Cheng const char *
mac_name(mac_handle_t mh)4248275SEric Cheng mac_name(mac_handle_t mh)
4258275SEric Cheng {
4268275SEric Cheng return (((mac_impl_t *)mh)->mi_name);
4278275SEric Cheng }
4288275SEric Cheng
42910639SDarren.Reed@Sun.COM int
mac_type(mac_handle_t mh)43010639SDarren.Reed@Sun.COM mac_type(mac_handle_t mh)
43110639SDarren.Reed@Sun.COM {
43210639SDarren.Reed@Sun.COM return (((mac_impl_t *)mh)->mi_type->mt_type);
43310639SDarren.Reed@Sun.COM }
43410639SDarren.Reed@Sun.COM
43511665SDarren.Reed@Sun.COM int
mac_nativetype(mac_handle_t mh)43611665SDarren.Reed@Sun.COM mac_nativetype(mac_handle_t mh)
43711665SDarren.Reed@Sun.COM {
43811665SDarren.Reed@Sun.COM return (((mac_impl_t *)mh)->mi_type->mt_nativetype);
43911665SDarren.Reed@Sun.COM }
44011665SDarren.Reed@Sun.COM
4418275SEric Cheng char *
mac_client_name(mac_client_handle_t mch)4428275SEric Cheng mac_client_name(mac_client_handle_t mch)
4438275SEric Cheng {
4448275SEric Cheng return (((mac_client_impl_t *)mch)->mci_name);
4458275SEric Cheng }
4468275SEric Cheng
4478275SEric Cheng minor_t
mac_minor(mac_handle_t mh)4488275SEric Cheng mac_minor(mac_handle_t mh)
4498275SEric Cheng {
4508275SEric Cheng return (((mac_impl_t *)mh)->mi_minor);
4518275SEric Cheng }
4528275SEric Cheng
4538275SEric Cheng /*
4548275SEric Cheng * Return the VID associated with a MAC client. This function should
4558275SEric Cheng * be called for clients which are associated with only one VID.
4568275SEric Cheng */
4578275SEric Cheng uint16_t
mac_client_vid(mac_client_handle_t mch)4588275SEric Cheng mac_client_vid(mac_client_handle_t mch)
4598275SEric Cheng {
4608275SEric Cheng uint16_t vid = VLAN_ID_NONE;
4618275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
4628275SEric Cheng flow_desc_t flow_desc;
4638275SEric Cheng
4648275SEric Cheng if (mcip->mci_nflents == 0)
4658275SEric Cheng return (vid);
4668275SEric Cheng
4678275SEric Cheng ASSERT(MCIP_DATAPATH_SETUP(mcip) && mac_client_single_rcvr(mcip));
4688275SEric Cheng
4698275SEric Cheng mac_flow_get_desc(mcip->mci_flent, &flow_desc);
4708275SEric Cheng if ((flow_desc.fd_mask & FLOW_LINK_VID) != 0)
4718275SEric Cheng vid = flow_desc.fd_vid;
4728275SEric Cheng
4738275SEric Cheng return (vid);
4748275SEric Cheng }
4758275SEric Cheng
4768275SEric Cheng /*
4779726SNicolas.Droux@Sun.COM * Return whether the specified MAC client corresponds to a VLAN VNIC.
4789726SNicolas.Droux@Sun.COM */
4799726SNicolas.Droux@Sun.COM boolean_t
mac_client_is_vlan_vnic(mac_client_handle_t mch)4809726SNicolas.Droux@Sun.COM mac_client_is_vlan_vnic(mac_client_handle_t mch)
4819726SNicolas.Droux@Sun.COM {
4829726SNicolas.Droux@Sun.COM mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
4839726SNicolas.Droux@Sun.COM
4849726SNicolas.Droux@Sun.COM return (((mcip->mci_state_flags & MCIS_IS_VNIC) != 0) &&
4859726SNicolas.Droux@Sun.COM ((mcip->mci_flent->fe_type & FLOW_PRIMARY_MAC) != 0));
4869726SNicolas.Droux@Sun.COM }
4879726SNicolas.Droux@Sun.COM
4889726SNicolas.Droux@Sun.COM /*
4898275SEric Cheng * Return the link speed associated with the specified MAC client.
4908275SEric Cheng *
4918275SEric Cheng * The link speed of a MAC client is equal to the smallest value of
4928275SEric Cheng * 1) the current link speed of the underlying NIC, or
4938275SEric Cheng * 2) the bandwidth limit set for the MAC client.
4948275SEric Cheng *
4958275SEric Cheng * Note that the bandwidth limit can be higher than the speed
4968275SEric Cheng * of the underlying NIC. This is allowed to avoid spurious
4978275SEric Cheng * administration action failures or artifically lowering the
4988275SEric Cheng * bandwidth limit of a link that may have temporarily lowered
4998275SEric Cheng * its link speed due to hardware problem or administrator action.
5008275SEric Cheng */
5018275SEric Cheng static uint64_t
mac_client_ifspeed(mac_client_impl_t * mcip)5028275SEric Cheng mac_client_ifspeed(mac_client_impl_t *mcip)
5038275SEric Cheng {
5048275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
5058275SEric Cheng uint64_t nic_speed;
5068275SEric Cheng
5078275SEric Cheng nic_speed = mac_stat_get((mac_handle_t)mip, MAC_STAT_IFSPEED);
5088275SEric Cheng
5098275SEric Cheng if (nic_speed == 0) {
5108275SEric Cheng return (0);
5118275SEric Cheng } else {
5128275SEric Cheng uint64_t policy_limit = (uint64_t)-1;
5138275SEric Cheng
5148275SEric Cheng if (MCIP_RESOURCE_PROPS_MASK(mcip) & MRP_MAXBW)
5158275SEric Cheng policy_limit = MCIP_RESOURCE_PROPS_MAXBW(mcip);
5168275SEric Cheng
5178275SEric Cheng return (MIN(policy_limit, nic_speed));
5188275SEric Cheng }
5198275SEric Cheng }
5208275SEric Cheng
5218275SEric Cheng /*
5228275SEric Cheng * Return the link state of the specified client. If here are more
5238275SEric Cheng * than one clients of the underying mac_impl_t, the link state
5248275SEric Cheng * will always be UP regardless of the link state of the underlying
5258275SEric Cheng * mac_impl_t. This is needed to allow the MAC clients to continue
5268275SEric Cheng * to communicate with each other even when the physical link of
5278275SEric Cheng * their mac_impl_t is down.
5288275SEric Cheng */
5298275SEric Cheng static uint64_t
mac_client_link_state(mac_client_impl_t * mcip)5308275SEric Cheng mac_client_link_state(mac_client_impl_t *mcip)
5318275SEric Cheng {
5328275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
5338275SEric Cheng uint16_t vid;
5348275SEric Cheng mac_client_impl_t *mci_list;
5358275SEric Cheng mac_unicast_impl_t *mui_list, *oth_mui_list;
5368275SEric Cheng
5378275SEric Cheng /*
5388275SEric Cheng * Returns LINK_STATE_UP if there are other MAC clients defined on
5398275SEric Cheng * mac_impl_t which share same VLAN ID as that of mcip. Note that
5408275SEric Cheng * if 'mcip' has more than one VID's then we match ANY one of the
5418275SEric Cheng * VID's with other MAC client's VID's and return LINK_STATE_UP.
5428275SEric Cheng */
5438275SEric Cheng rw_enter(&mcip->mci_rw_lock, RW_READER);
5448275SEric Cheng for (mui_list = mcip->mci_unicast_list; mui_list != NULL;
5458275SEric Cheng mui_list = mui_list->mui_next) {
5468275SEric Cheng vid = mui_list->mui_vid;
5478275SEric Cheng for (mci_list = mip->mi_clients_list; mci_list != NULL;
5488275SEric Cheng mci_list = mci_list->mci_client_next) {
5498275SEric Cheng if (mci_list == mcip)
5508275SEric Cheng continue;
5518275SEric Cheng for (oth_mui_list = mci_list->mci_unicast_list;
5528275SEric Cheng oth_mui_list != NULL; oth_mui_list = oth_mui_list->
5538275SEric Cheng mui_next) {
5548275SEric Cheng if (vid == oth_mui_list->mui_vid) {
5558275SEric Cheng rw_exit(&mcip->mci_rw_lock);
5568275SEric Cheng return (LINK_STATE_UP);
5578275SEric Cheng }
5588275SEric Cheng }
5598275SEric Cheng }
5608275SEric Cheng }
5618275SEric Cheng rw_exit(&mcip->mci_rw_lock);
5628275SEric Cheng
5638275SEric Cheng return (mac_stat_get((mac_handle_t)mip, MAC_STAT_LINK_STATE));
5648275SEric Cheng }
5658275SEric Cheng
5668275SEric Cheng /*
56711878SVenu.Iyer@Sun.COM * These statistics are consumed by dladm show-link -s <vnic>,
56811878SVenu.Iyer@Sun.COM * dladm show-vnic -s and netstat. With the introduction of dlstat,
56911878SVenu.Iyer@Sun.COM * dladm show-link -s and dladm show-vnic -s witll be EOL'ed while
57011878SVenu.Iyer@Sun.COM * netstat will consume from kstats introduced for dlstat. This code
57111878SVenu.Iyer@Sun.COM * will be removed at that time.
57211878SVenu.Iyer@Sun.COM */
57311878SVenu.Iyer@Sun.COM
57411878SVenu.Iyer@Sun.COM /*
5758275SEric Cheng * Return the statistics of a MAC client. These statistics are different
5768275SEric Cheng * then the statistics of the underlying MAC which are returned by
5778275SEric Cheng * mac_stat_get().
5788275SEric Cheng */
5798275SEric Cheng uint64_t
mac_client_stat_get(mac_client_handle_t mch,uint_t stat)5808275SEric Cheng mac_client_stat_get(mac_client_handle_t mch, uint_t stat)
5818275SEric Cheng {
58211878SVenu.Iyer@Sun.COM mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
58311878SVenu.Iyer@Sun.COM mac_impl_t *mip = mcip->mci_mip;
58411878SVenu.Iyer@Sun.COM flow_entry_t *flent = mcip->mci_flent;
58511878SVenu.Iyer@Sun.COM mac_soft_ring_set_t *mac_srs;
58611878SVenu.Iyer@Sun.COM mac_rx_stats_t *mac_rx_stat;
58711878SVenu.Iyer@Sun.COM mac_tx_stats_t *mac_tx_stat;
58811878SVenu.Iyer@Sun.COM int i;
58911878SVenu.Iyer@Sun.COM uint64_t val = 0;
59011878SVenu.Iyer@Sun.COM
59111878SVenu.Iyer@Sun.COM mac_srs = (mac_soft_ring_set_t *)(flent->fe_tx_srs);
59211878SVenu.Iyer@Sun.COM mac_tx_stat = &mac_srs->srs_tx.st_stat;
5938275SEric Cheng
5948275SEric Cheng switch (stat) {
5958275SEric Cheng case MAC_STAT_LINK_STATE:
5968275SEric Cheng val = mac_client_link_state(mcip);
5978275SEric Cheng break;
5988275SEric Cheng case MAC_STAT_LINK_UP:
5998275SEric Cheng val = (mac_client_link_state(mcip) == LINK_STATE_UP);
6008275SEric Cheng break;
6018275SEric Cheng case MAC_STAT_PROMISC:
6028275SEric Cheng val = mac_stat_get((mac_handle_t)mip, MAC_STAT_PROMISC);
6038275SEric Cheng break;
60410491SRishi.Srivatsavai@Sun.COM case MAC_STAT_LOWLINK_STATE:
60510491SRishi.Srivatsavai@Sun.COM val = mac_stat_get((mac_handle_t)mip, MAC_STAT_LOWLINK_STATE);
60610491SRishi.Srivatsavai@Sun.COM break;
6078275SEric Cheng case MAC_STAT_IFSPEED:
6088275SEric Cheng val = mac_client_ifspeed(mcip);
6098275SEric Cheng break;
6108275SEric Cheng case MAC_STAT_MULTIRCV:
61111878SVenu.Iyer@Sun.COM val = mcip->mci_misc_stat.mms_multircv;
6128275SEric Cheng break;
6138275SEric Cheng case MAC_STAT_BRDCSTRCV:
61411878SVenu.Iyer@Sun.COM val = mcip->mci_misc_stat.mms_brdcstrcv;
6158275SEric Cheng break;
6168275SEric Cheng case MAC_STAT_MULTIXMT:
61711878SVenu.Iyer@Sun.COM val = mcip->mci_misc_stat.mms_multixmt;
6188275SEric Cheng break;
6198275SEric Cheng case MAC_STAT_BRDCSTXMT:
62011878SVenu.Iyer@Sun.COM val = mcip->mci_misc_stat.mms_brdcstxmt;
6218275SEric Cheng break;
6228275SEric Cheng case MAC_STAT_OBYTES:
62311878SVenu.Iyer@Sun.COM val = mac_tx_stat->mts_obytes;
6248275SEric Cheng break;
6258275SEric Cheng case MAC_STAT_OPACKETS:
62611878SVenu.Iyer@Sun.COM val = mac_tx_stat->mts_opackets;
6278275SEric Cheng break;
6288275SEric Cheng case MAC_STAT_OERRORS:
62911878SVenu.Iyer@Sun.COM val = mac_tx_stat->mts_oerrors;
6308275SEric Cheng break;
6318275SEric Cheng case MAC_STAT_IPACKETS:
63211878SVenu.Iyer@Sun.COM for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
63311878SVenu.Iyer@Sun.COM mac_srs = (mac_soft_ring_set_t *)flent->fe_rx_srs[i];
63411878SVenu.Iyer@Sun.COM mac_rx_stat = &mac_srs->srs_rx.sr_stat;
63511878SVenu.Iyer@Sun.COM val += mac_rx_stat->mrs_intrcnt +
63611878SVenu.Iyer@Sun.COM mac_rx_stat->mrs_pollcnt + mac_rx_stat->mrs_lclcnt;
63711878SVenu.Iyer@Sun.COM }
6388275SEric Cheng break;
6398275SEric Cheng case MAC_STAT_RBYTES:
64011878SVenu.Iyer@Sun.COM for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
64111878SVenu.Iyer@Sun.COM mac_srs = (mac_soft_ring_set_t *)flent->fe_rx_srs[i];
64211878SVenu.Iyer@Sun.COM mac_rx_stat = &mac_srs->srs_rx.sr_stat;
64311878SVenu.Iyer@Sun.COM val += mac_rx_stat->mrs_intrbytes +
64411878SVenu.Iyer@Sun.COM mac_rx_stat->mrs_pollbytes +
64511878SVenu.Iyer@Sun.COM mac_rx_stat->mrs_lclbytes;
64611878SVenu.Iyer@Sun.COM }
6478275SEric Cheng break;
6488275SEric Cheng case MAC_STAT_IERRORS:
64911878SVenu.Iyer@Sun.COM for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
65011878SVenu.Iyer@Sun.COM mac_srs = (mac_soft_ring_set_t *)flent->fe_rx_srs[i];
65111878SVenu.Iyer@Sun.COM mac_rx_stat = &mac_srs->srs_rx.sr_stat;
65211878SVenu.Iyer@Sun.COM val += mac_rx_stat->mrs_ierrors;
65311878SVenu.Iyer@Sun.COM }
6548275SEric Cheng break;
6558275SEric Cheng default:
65611878SVenu.Iyer@Sun.COM val = mac_driver_stat_default(mip, stat);
6578275SEric Cheng break;
6588275SEric Cheng }
6598275SEric Cheng
6608275SEric Cheng return (val);
6618275SEric Cheng }
6628275SEric Cheng
6638275SEric Cheng /*
6648275SEric Cheng * Return the statistics of the specified MAC instance.
6658275SEric Cheng */
6668275SEric Cheng uint64_t
mac_stat_get(mac_handle_t mh,uint_t stat)6678275SEric Cheng mac_stat_get(mac_handle_t mh, uint_t stat)
6688275SEric Cheng {
6698275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
6708275SEric Cheng uint64_t val;
6718275SEric Cheng int ret;
6728275SEric Cheng
6738275SEric Cheng /*
6748275SEric Cheng * The range of stat determines where it is maintained. Stat
6758275SEric Cheng * values from 0 up to (but not including) MAC_STAT_MIN are
6768275SEric Cheng * mainteined by the mac module itself. Everything else is
6778275SEric Cheng * maintained by the driver.
6788275SEric Cheng *
6798275SEric Cheng * If the mac_impl_t being queried corresponds to a VNIC,
6808275SEric Cheng * the stats need to be queried from the lower MAC client
6818275SEric Cheng * corresponding to the VNIC. (The mac_link_update()
6828275SEric Cheng * invoked by the driver to the lower MAC causes the *lower
6838275SEric Cheng * MAC* to update its mi_linkstate, and send a notification
6848275SEric Cheng * to its MAC clients. Due to the VNIC passthrough,
6858275SEric Cheng * these notifications are sent to the upper MAC clients
6868275SEric Cheng * of the VNIC directly, and the upper mac_impl_t of the VNIC
6878275SEric Cheng * does not have a valid mi_linkstate.
6888275SEric Cheng */
6898275SEric Cheng if (stat < MAC_STAT_MIN && !(mip->mi_state_flags & MIS_IS_VNIC)) {
6908275SEric Cheng /* these stats are maintained by the mac module itself */
6918275SEric Cheng switch (stat) {
6928275SEric Cheng case MAC_STAT_LINK_STATE:
6938275SEric Cheng return (mip->mi_linkstate);
6948275SEric Cheng case MAC_STAT_LINK_UP:
6958275SEric Cheng return (mip->mi_linkstate == LINK_STATE_UP);
6968275SEric Cheng case MAC_STAT_PROMISC:
6978275SEric Cheng return (mip->mi_devpromisc != 0);
69810491SRishi.Srivatsavai@Sun.COM case MAC_STAT_LOWLINK_STATE:
69910491SRishi.Srivatsavai@Sun.COM return (mip->mi_lowlinkstate);
7008275SEric Cheng default:
7018275SEric Cheng ASSERT(B_FALSE);
7028275SEric Cheng }
7038275SEric Cheng }
7048275SEric Cheng
7058275SEric Cheng /*
7068275SEric Cheng * Call the driver to get the given statistic.
7078275SEric Cheng */
7088275SEric Cheng ret = mip->mi_getstat(mip->mi_driver, stat, &val);
7098275SEric Cheng if (ret != 0) {
7108275SEric Cheng /*
7118275SEric Cheng * The driver doesn't support this statistic. Get the
7128275SEric Cheng * statistic's default value.
7138275SEric Cheng */
71411878SVenu.Iyer@Sun.COM val = mac_driver_stat_default(mip, stat);
7158275SEric Cheng }
7168275SEric Cheng return (val);
7178275SEric Cheng }
7188275SEric Cheng
7198275SEric Cheng /*
72011878SVenu.Iyer@Sun.COM * Query hardware rx ring corresponding to the pseudo ring.
72111878SVenu.Iyer@Sun.COM */
72211878SVenu.Iyer@Sun.COM uint64_t
mac_pseudo_rx_ring_stat_get(mac_ring_handle_t handle,uint_t stat)72311878SVenu.Iyer@Sun.COM mac_pseudo_rx_ring_stat_get(mac_ring_handle_t handle, uint_t stat)
72411878SVenu.Iyer@Sun.COM {
72511878SVenu.Iyer@Sun.COM return (mac_rx_ring_stat_get(handle, stat));
72611878SVenu.Iyer@Sun.COM }
72711878SVenu.Iyer@Sun.COM
72811878SVenu.Iyer@Sun.COM /*
72911878SVenu.Iyer@Sun.COM * Query hardware tx ring corresponding to the pseudo ring.
73011878SVenu.Iyer@Sun.COM */
73111878SVenu.Iyer@Sun.COM uint64_t
mac_pseudo_tx_ring_stat_get(mac_ring_handle_t handle,uint_t stat)73211878SVenu.Iyer@Sun.COM mac_pseudo_tx_ring_stat_get(mac_ring_handle_t handle, uint_t stat)
73311878SVenu.Iyer@Sun.COM {
73411878SVenu.Iyer@Sun.COM return (mac_tx_ring_stat_get(handle, stat));
73511878SVenu.Iyer@Sun.COM }
73611878SVenu.Iyer@Sun.COM
73711878SVenu.Iyer@Sun.COM /*
7388275SEric Cheng * Utility function which returns the VID associated with a flow entry.
7398275SEric Cheng */
7408275SEric Cheng uint16_t
i_mac_flow_vid(flow_entry_t * flent)7418275SEric Cheng i_mac_flow_vid(flow_entry_t *flent)
7428275SEric Cheng {
7438275SEric Cheng flow_desc_t flow_desc;
7448275SEric Cheng
7458275SEric Cheng mac_flow_get_desc(flent, &flow_desc);
7468275SEric Cheng
7478275SEric Cheng if ((flow_desc.fd_mask & FLOW_LINK_VID) != 0)
7488275SEric Cheng return (flow_desc.fd_vid);
7498275SEric Cheng return (VLAN_ID_NONE);
7508275SEric Cheng }
7518275SEric Cheng
7528275SEric Cheng /*
7538275SEric Cheng * Verify the validity of the specified unicast MAC address. Returns B_TRUE
7548275SEric Cheng * if the address is valid, B_FALSE otherwise (multicast address, or incorrect
7558275SEric Cheng * length.
7568275SEric Cheng */
7578275SEric Cheng boolean_t
mac_unicst_verify(mac_handle_t mh,const uint8_t * addr,uint_t len)7588275SEric Cheng mac_unicst_verify(mac_handle_t mh, const uint8_t *addr, uint_t len)
7598275SEric Cheng {
7608275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
7618275SEric Cheng
7628275SEric Cheng /*
7638275SEric Cheng * Verify the address. No lock is needed since mi_type and plugin
7648275SEric Cheng * details don't change after mac_register().
7658275SEric Cheng */
7668275SEric Cheng if ((len != mip->mi_type->mt_addr_length) ||
7678275SEric Cheng (mip->mi_type->mt_ops.mtops_unicst_verify(addr,
7688275SEric Cheng mip->mi_pdata)) != 0) {
7698275SEric Cheng return (B_FALSE);
7708275SEric Cheng } else {
7718275SEric Cheng return (B_TRUE);
7728275SEric Cheng }
7738275SEric Cheng }
7748275SEric Cheng
7758275SEric Cheng void
mac_sdu_get(mac_handle_t mh,uint_t * min_sdu,uint_t * max_sdu)7768275SEric Cheng mac_sdu_get(mac_handle_t mh, uint_t *min_sdu, uint_t *max_sdu)
7778275SEric Cheng {
7788275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
7798275SEric Cheng
7808275SEric Cheng if (min_sdu != NULL)
7818275SEric Cheng *min_sdu = mip->mi_sdu_min;
7828275SEric Cheng if (max_sdu != NULL)
7838275SEric Cheng *max_sdu = mip->mi_sdu_max;
7848275SEric Cheng }
7858275SEric Cheng
786*13123SErik.Nordmark@Sun.COM void
mac_sdu_get2(mac_handle_t mh,uint_t * min_sdu,uint_t * max_sdu,uint_t * multicast_sdu)787*13123SErik.Nordmark@Sun.COM mac_sdu_get2(mac_handle_t mh, uint_t *min_sdu, uint_t *max_sdu,
788*13123SErik.Nordmark@Sun.COM uint_t *multicast_sdu)
789*13123SErik.Nordmark@Sun.COM {
790*13123SErik.Nordmark@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
791*13123SErik.Nordmark@Sun.COM
792*13123SErik.Nordmark@Sun.COM if (min_sdu != NULL)
793*13123SErik.Nordmark@Sun.COM *min_sdu = mip->mi_sdu_min;
794*13123SErik.Nordmark@Sun.COM if (max_sdu != NULL)
795*13123SErik.Nordmark@Sun.COM *max_sdu = mip->mi_sdu_max;
796*13123SErik.Nordmark@Sun.COM if (multicast_sdu != NULL)
797*13123SErik.Nordmark@Sun.COM *multicast_sdu = mip->mi_sdu_multicast;
798*13123SErik.Nordmark@Sun.COM }
799*13123SErik.Nordmark@Sun.COM
8008275SEric Cheng /*
8018275SEric Cheng * Update the MAC unicast address of the specified client's flows. Currently
8028275SEric Cheng * only one unicast MAC unicast address is allowed per client.
8038275SEric Cheng */
8048275SEric Cheng static void
mac_unicast_update_client_flow(mac_client_impl_t * mcip)8058275SEric Cheng mac_unicast_update_client_flow(mac_client_impl_t *mcip)
8068275SEric Cheng {
8078275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
8088275SEric Cheng flow_entry_t *flent = mcip->mci_flent;
8098275SEric Cheng mac_address_t *map = mcip->mci_unicast;
8108275SEric Cheng flow_desc_t flow_desc;
8118275SEric Cheng
8128275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
8138275SEric Cheng ASSERT(flent != NULL);
8148275SEric Cheng
8158275SEric Cheng mac_flow_get_desc(flent, &flow_desc);
8168275SEric Cheng ASSERT(flow_desc.fd_mask & FLOW_LINK_DST);
8178275SEric Cheng
8188275SEric Cheng bcopy(map->ma_addr, flow_desc.fd_dst_mac, map->ma_len);
8198275SEric Cheng mac_flow_set_desc(flent, &flow_desc);
8208275SEric Cheng
8218275SEric Cheng /*
82211878SVenu.Iyer@Sun.COM * The v6 local addr (used by mac protection) needs to be
82311878SVenu.Iyer@Sun.COM * regenerated because our mac address has changed.
82411878SVenu.Iyer@Sun.COM */
82511878SVenu.Iyer@Sun.COM mac_protect_update_v6_local_addr(mcip);
82611878SVenu.Iyer@Sun.COM
82711878SVenu.Iyer@Sun.COM /*
8288275SEric Cheng * A MAC client could have one MAC address but multiple
8298275SEric Cheng * VLANs. In that case update the flow entries corresponding
8308275SEric Cheng * to all VLANs of the MAC client.
8318275SEric Cheng */
8328275SEric Cheng for (flent = mcip->mci_flent_list; flent != NULL;
8338275SEric Cheng flent = flent->fe_client_next) {
8348275SEric Cheng mac_flow_get_desc(flent, &flow_desc);
8358275SEric Cheng if (!(flent->fe_type & FLOW_PRIMARY_MAC ||
8368275SEric Cheng flent->fe_type & FLOW_VNIC_MAC))
8378275SEric Cheng continue;
8388275SEric Cheng
8398275SEric Cheng bcopy(map->ma_addr, flow_desc.fd_dst_mac, map->ma_len);
8408275SEric Cheng mac_flow_set_desc(flent, &flow_desc);
8418275SEric Cheng }
8428275SEric Cheng }
8438275SEric Cheng
8448275SEric Cheng /*
8458275SEric Cheng * Update all clients that share the same unicast address.
8468275SEric Cheng */
8478275SEric Cheng void
mac_unicast_update_clients(mac_impl_t * mip,mac_address_t * map)8488275SEric Cheng mac_unicast_update_clients(mac_impl_t *mip, mac_address_t *map)
8498275SEric Cheng {
8508275SEric Cheng mac_client_impl_t *mcip;
8518275SEric Cheng
8528275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
8538275SEric Cheng
8548275SEric Cheng /*
8558275SEric Cheng * Find all clients that share the same unicast MAC address and update
8568275SEric Cheng * them appropriately.
8578275SEric Cheng */
8588275SEric Cheng for (mcip = mip->mi_clients_list; mcip != NULL;
8598275SEric Cheng mcip = mcip->mci_client_next) {
8608275SEric Cheng /*
8618275SEric Cheng * Ignore clients that don't share this MAC address.
8628275SEric Cheng */
8638275SEric Cheng if (map != mcip->mci_unicast)
8648275SEric Cheng continue;
8658275SEric Cheng
8668275SEric Cheng /*
8678275SEric Cheng * Update those clients with same old unicast MAC address.
8688275SEric Cheng */
8698275SEric Cheng mac_unicast_update_client_flow(mcip);
8708275SEric Cheng }
8718275SEric Cheng }
8728275SEric Cheng
8738275SEric Cheng /*
8748275SEric Cheng * Update the unicast MAC address of the specified VNIC MAC client.
8758275SEric Cheng *
8768275SEric Cheng * Check whether the operation is valid. Any of following cases should fail:
8778275SEric Cheng *
8788275SEric Cheng * 1. It's a VLAN type of VNIC.
8798275SEric Cheng * 2. The new value is current "primary" MAC address.
8808275SEric Cheng * 3. The current MAC address is shared with other clients.
8818275SEric Cheng * 4. The new MAC address has been used. This case will be valid when
8828275SEric Cheng * client migration is fully supported.
8838275SEric Cheng */
8848275SEric Cheng int
mac_vnic_unicast_set(mac_client_handle_t mch,const uint8_t * addr)8858275SEric Cheng mac_vnic_unicast_set(mac_client_handle_t mch, const uint8_t *addr)
8868275SEric Cheng {
8878275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
8888275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
8898275SEric Cheng mac_address_t *map = mcip->mci_unicast;
8908275SEric Cheng int err;
8918275SEric Cheng
8928275SEric Cheng ASSERT(!(mip->mi_state_flags & MIS_IS_VNIC));
8938275SEric Cheng ASSERT(mcip->mci_state_flags & MCIS_IS_VNIC);
8948275SEric Cheng ASSERT(mcip->mci_flags != MAC_CLIENT_FLAGS_PRIMARY);
8958275SEric Cheng
8968275SEric Cheng i_mac_perim_enter(mip);
8978275SEric Cheng
8988275SEric Cheng /*
8998275SEric Cheng * If this is a VLAN type of VNIC, it's using "primary" MAC address
9008275SEric Cheng * of the underlying interface. Must fail here. Refer to case 1 above.
9018275SEric Cheng */
9028275SEric Cheng if (bcmp(map->ma_addr, mip->mi_addr, map->ma_len) == 0) {
9038275SEric Cheng i_mac_perim_exit(mip);
9048275SEric Cheng return (ENOTSUP);
9058275SEric Cheng }
9068275SEric Cheng
9078275SEric Cheng /*
9088275SEric Cheng * If the new address is the "primary" one, must fail. Refer to
9098275SEric Cheng * case 2 above.
9108275SEric Cheng */
9118275SEric Cheng if (bcmp(addr, mip->mi_addr, map->ma_len) == 0) {
9128275SEric Cheng i_mac_perim_exit(mip);
9138275SEric Cheng return (EACCES);
9148275SEric Cheng }
9158275SEric Cheng
9168275SEric Cheng /*
9178275SEric Cheng * If the address is shared by multiple clients, must fail. Refer
9188275SEric Cheng * to case 3 above.
9198275SEric Cheng */
9208275SEric Cheng if (mac_check_macaddr_shared(map)) {
9218275SEric Cheng i_mac_perim_exit(mip);
9228275SEric Cheng return (EBUSY);
9238275SEric Cheng }
9248275SEric Cheng
9258275SEric Cheng /*
9268275SEric Cheng * If the new address has been used, must fail for now. Refer to
9278275SEric Cheng * case 4 above.
9288275SEric Cheng */
9298275SEric Cheng if (mac_find_macaddr(mip, (uint8_t *)addr) != NULL) {
9308275SEric Cheng i_mac_perim_exit(mip);
9318275SEric Cheng return (ENOTSUP);
9328275SEric Cheng }
9338275SEric Cheng
9348275SEric Cheng /*
9358275SEric Cheng * Update the MAC address.
9368275SEric Cheng */
9378275SEric Cheng err = mac_update_macaddr(map, (uint8_t *)addr);
9388275SEric Cheng
9398275SEric Cheng if (err != 0) {
9408275SEric Cheng i_mac_perim_exit(mip);
9418275SEric Cheng return (err);
9428275SEric Cheng }
9438275SEric Cheng
9448275SEric Cheng /*
9458275SEric Cheng * Update all flows of this MAC client.
9468275SEric Cheng */
9478275SEric Cheng mac_unicast_update_client_flow(mcip);
9488275SEric Cheng
9498275SEric Cheng i_mac_perim_exit(mip);
9508275SEric Cheng return (0);
9518275SEric Cheng }
9528275SEric Cheng
9538275SEric Cheng /*
9548275SEric Cheng * Program the new primary unicast address of the specified MAC.
9558275SEric Cheng *
9568275SEric Cheng * Function mac_update_macaddr() takes care different types of underlying
9578275SEric Cheng * MAC. If the underlying MAC is VNIC, the VNIC driver must have registerd
9588275SEric Cheng * mi_unicst() entry point, that indirectly calls mac_vnic_unicast_set()
9598275SEric Cheng * which will take care of updating the MAC address of the corresponding
9608275SEric Cheng * MAC client.
9618275SEric Cheng *
9628275SEric Cheng * This is the only interface that allow the client to update the "primary"
9638275SEric Cheng * MAC address of the underlying MAC. The new value must have not been
9648275SEric Cheng * used by other clients.
9658275SEric Cheng */
9668275SEric Cheng int
mac_unicast_primary_set(mac_handle_t mh,const uint8_t * addr)9678275SEric Cheng mac_unicast_primary_set(mac_handle_t mh, const uint8_t *addr)
9688275SEric Cheng {
9698275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
9708275SEric Cheng mac_address_t *map;
9718275SEric Cheng int err;
9728275SEric Cheng
9738275SEric Cheng /* verify the address validity */
9748275SEric Cheng if (!mac_unicst_verify(mh, addr, mip->mi_type->mt_addr_length))
9758275SEric Cheng return (EINVAL);
9768275SEric Cheng
9778275SEric Cheng i_mac_perim_enter(mip);
9788275SEric Cheng
9798275SEric Cheng /*
9808275SEric Cheng * If the new value is the same as the current primary address value,
9818275SEric Cheng * there's nothing to do.
9828275SEric Cheng */
9838275SEric Cheng if (bcmp(addr, mip->mi_addr, mip->mi_type->mt_addr_length) == 0) {
9848275SEric Cheng i_mac_perim_exit(mip);
9858275SEric Cheng return (0);
9868275SEric Cheng }
9878275SEric Cheng
9888275SEric Cheng if (mac_find_macaddr(mip, (uint8_t *)addr) != 0) {
9898275SEric Cheng i_mac_perim_exit(mip);
9908275SEric Cheng return (EBUSY);
9918275SEric Cheng }
9928275SEric Cheng
9938275SEric Cheng map = mac_find_macaddr(mip, mip->mi_addr);
9948275SEric Cheng ASSERT(map != NULL);
9958275SEric Cheng
9968275SEric Cheng /*
9978275SEric Cheng * Update the MAC address.
9988275SEric Cheng */
9998275SEric Cheng if (mip->mi_state_flags & MIS_IS_AGGR) {
10008275SEric Cheng mac_capab_aggr_t aggr_cap;
10018275SEric Cheng
10028275SEric Cheng /*
10038275SEric Cheng * If the mac is an aggregation, other than the unicast
10048275SEric Cheng * addresses programming, aggr must be informed about this
10058275SEric Cheng * primary unicst address change to change its mac address
10068275SEric Cheng * policy to be user-specified.
10078275SEric Cheng */
10088275SEric Cheng ASSERT(map->ma_type == MAC_ADDRESS_TYPE_UNICAST_CLASSIFIED);
10098275SEric Cheng VERIFY(i_mac_capab_get(mh, MAC_CAPAB_AGGR, &aggr_cap));
10108275SEric Cheng err = aggr_cap.mca_unicst(mip->mi_driver, addr);
10118275SEric Cheng if (err == 0)
10128275SEric Cheng bcopy(addr, map->ma_addr, map->ma_len);
10138275SEric Cheng } else {
10148275SEric Cheng err = mac_update_macaddr(map, (uint8_t *)addr);
10158275SEric Cheng }
10168275SEric Cheng
10178275SEric Cheng if (err != 0) {
10188275SEric Cheng i_mac_perim_exit(mip);
10198275SEric Cheng return (err);
10208275SEric Cheng }
10218275SEric Cheng
10228275SEric Cheng mac_unicast_update_clients(mip, map);
10238275SEric Cheng
10248275SEric Cheng /*
10258275SEric Cheng * Save the new primary MAC address in mac_impl_t.
10268275SEric Cheng */
10278275SEric Cheng bcopy(addr, mip->mi_addr, mip->mi_type->mt_addr_length);
10288275SEric Cheng
10298275SEric Cheng i_mac_perim_exit(mip);
10308275SEric Cheng
10318275SEric Cheng if (err == 0)
10328275SEric Cheng i_mac_notify(mip, MAC_NOTE_UNICST);
10338275SEric Cheng
10348275SEric Cheng return (err);
10358275SEric Cheng }
10368275SEric Cheng
10378275SEric Cheng /*
10388275SEric Cheng * Return the current primary MAC address of the specified MAC.
10398275SEric Cheng */
10408275SEric Cheng void
mac_unicast_primary_get(mac_handle_t mh,uint8_t * addr)10418275SEric Cheng mac_unicast_primary_get(mac_handle_t mh, uint8_t *addr)
10428275SEric Cheng {
10438275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
10448275SEric Cheng
10458275SEric Cheng rw_enter(&mip->mi_rw_lock, RW_READER);
10468275SEric Cheng bcopy(mip->mi_addr, addr, mip->mi_type->mt_addr_length);
10478275SEric Cheng rw_exit(&mip->mi_rw_lock);
10488275SEric Cheng }
10498275SEric Cheng
10508275SEric Cheng /*
10518275SEric Cheng * Return information about the use of the primary MAC address of the
10528275SEric Cheng * specified MAC instance:
10538275SEric Cheng *
10548275SEric Cheng * - if client_name is non-NULL, it must point to a string of at
10558275SEric Cheng * least MAXNAMELEN bytes, and will be set to the name of the MAC
10568275SEric Cheng * client which uses the primary MAC address.
10578275SEric Cheng *
10588275SEric Cheng * - if in_use is non-NULL, used to return whether the primary MAC
10598275SEric Cheng * address is currently in use.
10608275SEric Cheng */
10618275SEric Cheng void
mac_unicast_primary_info(mac_handle_t mh,char * client_name,boolean_t * in_use)10628275SEric Cheng mac_unicast_primary_info(mac_handle_t mh, char *client_name, boolean_t *in_use)
10638275SEric Cheng {
10648275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
10658275SEric Cheng mac_client_impl_t *cur_client;
10668275SEric Cheng
10678275SEric Cheng if (in_use != NULL)
10688275SEric Cheng *in_use = B_FALSE;
10698275SEric Cheng if (client_name != NULL)
10708275SEric Cheng bzero(client_name, MAXNAMELEN);
10718275SEric Cheng
10728275SEric Cheng /*
10738275SEric Cheng * The mi_rw_lock is used to protect threads that don't hold the
10748275SEric Cheng * mac perimeter to get a consistent view of the mi_clients_list.
10758275SEric Cheng * Threads that modify the list must hold both the mac perimeter and
10768275SEric Cheng * mi_rw_lock(RW_WRITER)
10778275SEric Cheng */
10788275SEric Cheng rw_enter(&mip->mi_rw_lock, RW_READER);
10798275SEric Cheng for (cur_client = mip->mi_clients_list; cur_client != NULL;
10808275SEric Cheng cur_client = cur_client->mci_client_next) {
10818275SEric Cheng if (mac_is_primary_client(cur_client) ||
10828275SEric Cheng (mip->mi_state_flags & MIS_IS_VNIC)) {
10838275SEric Cheng rw_exit(&mip->mi_rw_lock);
10848275SEric Cheng if (in_use != NULL)
10858275SEric Cheng *in_use = B_TRUE;
10868275SEric Cheng if (client_name != NULL) {
10878275SEric Cheng bcopy(cur_client->mci_name, client_name,
10888275SEric Cheng MAXNAMELEN);
10898275SEric Cheng }
10908275SEric Cheng return;
10918275SEric Cheng }
10928275SEric Cheng }
10938275SEric Cheng rw_exit(&mip->mi_rw_lock);
10948275SEric Cheng }
10958275SEric Cheng
10968275SEric Cheng /*
109710616SSebastien.Roy@Sun.COM * Return the current destination MAC address of the specified MAC.
109810616SSebastien.Roy@Sun.COM */
109910616SSebastien.Roy@Sun.COM boolean_t
mac_dst_get(mac_handle_t mh,uint8_t * addr)110010616SSebastien.Roy@Sun.COM mac_dst_get(mac_handle_t mh, uint8_t *addr)
110110616SSebastien.Roy@Sun.COM {
110210616SSebastien.Roy@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
110310616SSebastien.Roy@Sun.COM
110410616SSebastien.Roy@Sun.COM rw_enter(&mip->mi_rw_lock, RW_READER);
110510616SSebastien.Roy@Sun.COM if (mip->mi_dstaddr_set)
110610616SSebastien.Roy@Sun.COM bcopy(mip->mi_dstaddr, addr, mip->mi_type->mt_addr_length);
110710616SSebastien.Roy@Sun.COM rw_exit(&mip->mi_rw_lock);
110810616SSebastien.Roy@Sun.COM return (mip->mi_dstaddr_set);
110910616SSebastien.Roy@Sun.COM }
111010616SSebastien.Roy@Sun.COM
111110616SSebastien.Roy@Sun.COM /*
11128275SEric Cheng * Add the specified MAC client to the list of clients which opened
11138275SEric Cheng * the specified MAC.
11148275SEric Cheng */
11158275SEric Cheng static void
mac_client_add(mac_client_impl_t * mcip)11168275SEric Cheng mac_client_add(mac_client_impl_t *mcip)
11178275SEric Cheng {
11188275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
11198275SEric Cheng
11208275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
11218275SEric Cheng
11228275SEric Cheng /* add VNIC to the front of the list */
11238275SEric Cheng rw_enter(&mip->mi_rw_lock, RW_WRITER);
11248275SEric Cheng mcip->mci_client_next = mip->mi_clients_list;
11258275SEric Cheng mip->mi_clients_list = mcip;
11268275SEric Cheng mip->mi_nclients++;
11278275SEric Cheng rw_exit(&mip->mi_rw_lock);
11288275SEric Cheng }
11298275SEric Cheng
11308275SEric Cheng /*
11318275SEric Cheng * Remove the specified MAC client from the list of clients which opened
11328275SEric Cheng * the specified MAC.
11338275SEric Cheng */
11348275SEric Cheng static void
mac_client_remove(mac_client_impl_t * mcip)11358275SEric Cheng mac_client_remove(mac_client_impl_t *mcip)
11368275SEric Cheng {
11378275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
11388275SEric Cheng mac_client_impl_t **prev, *cclient;
11398275SEric Cheng
11408275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
11418275SEric Cheng
11428275SEric Cheng rw_enter(&mip->mi_rw_lock, RW_WRITER);
11438275SEric Cheng prev = &mip->mi_clients_list;
11448275SEric Cheng cclient = *prev;
11458275SEric Cheng while (cclient != NULL && cclient != mcip) {
11468275SEric Cheng prev = &cclient->mci_client_next;
11478275SEric Cheng cclient = *prev;
11488275SEric Cheng }
11498275SEric Cheng ASSERT(cclient != NULL);
11508275SEric Cheng *prev = cclient->mci_client_next;
11518275SEric Cheng mip->mi_nclients--;
11528275SEric Cheng rw_exit(&mip->mi_rw_lock);
11538275SEric Cheng }
11548275SEric Cheng
11558275SEric Cheng static mac_unicast_impl_t *
mac_client_find_vid(mac_client_impl_t * mcip,uint16_t vid)11568275SEric Cheng mac_client_find_vid(mac_client_impl_t *mcip, uint16_t vid)
11578275SEric Cheng {
11588275SEric Cheng mac_unicast_impl_t *muip = mcip->mci_unicast_list;
11598275SEric Cheng
11608275SEric Cheng while ((muip != NULL) && (muip->mui_vid != vid))
11618275SEric Cheng muip = muip->mui_next;
11628275SEric Cheng
11638275SEric Cheng return (muip);
11648275SEric Cheng }
11658275SEric Cheng
11668275SEric Cheng /*
11678275SEric Cheng * Return whether the specified (MAC address, VID) tuple is already used by
11688275SEric Cheng * one of the MAC clients associated with the specified MAC.
11698275SEric Cheng */
11708275SEric Cheng static boolean_t
mac_addr_in_use(mac_impl_t * mip,uint8_t * mac_addr,uint16_t vid)11718275SEric Cheng mac_addr_in_use(mac_impl_t *mip, uint8_t *mac_addr, uint16_t vid)
11728275SEric Cheng {
11738275SEric Cheng mac_client_impl_t *client;
11748275SEric Cheng mac_address_t *map;
11758275SEric Cheng
11768275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
11778275SEric Cheng
11788275SEric Cheng for (client = mip->mi_clients_list; client != NULL;
11798275SEric Cheng client = client->mci_client_next) {
11808275SEric Cheng
11818275SEric Cheng /*
11828275SEric Cheng * Ignore clients that don't have unicast address.
11838275SEric Cheng */
11848275SEric Cheng if (client->mci_unicast_list == NULL)
11858275SEric Cheng continue;
11868275SEric Cheng
11878275SEric Cheng map = client->mci_unicast;
11888275SEric Cheng
11898275SEric Cheng if ((bcmp(mac_addr, map->ma_addr, map->ma_len) == 0) &&
11908275SEric Cheng (mac_client_find_vid(client, vid) != NULL)) {
11918275SEric Cheng return (B_TRUE);
11928275SEric Cheng }
11938275SEric Cheng }
11948275SEric Cheng
11958275SEric Cheng return (B_FALSE);
11968275SEric Cheng }
11978275SEric Cheng
11988275SEric Cheng /*
11998275SEric Cheng * Generate a random MAC address. The MAC address prefix is
12008275SEric Cheng * stored in the array pointed to by mac_addr, and its length, in bytes,
12018275SEric Cheng * is specified by prefix_len. The least significant bits
12028275SEric Cheng * after prefix_len bytes are generated, and stored after the prefix
12038275SEric Cheng * in the mac_addr array.
12048275SEric Cheng */
12058275SEric Cheng int
mac_addr_random(mac_client_handle_t mch,uint_t prefix_len,uint8_t * mac_addr,mac_diag_t * diag)12068275SEric Cheng mac_addr_random(mac_client_handle_t mch, uint_t prefix_len,
12078275SEric Cheng uint8_t *mac_addr, mac_diag_t *diag)
12088275SEric Cheng {
12098275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
12108275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
12118275SEric Cheng size_t addr_len = mip->mi_type->mt_addr_length;
12128275SEric Cheng
12138275SEric Cheng if (prefix_len >= addr_len) {
12148275SEric Cheng *diag = MAC_DIAG_MACPREFIXLEN_INVALID;
12158275SEric Cheng return (EINVAL);
12168275SEric Cheng }
12178275SEric Cheng
12188275SEric Cheng /* check the prefix value */
12198275SEric Cheng if (prefix_len > 0) {
12208275SEric Cheng bzero(mac_addr + prefix_len, addr_len - prefix_len);
12218275SEric Cheng if (!mac_unicst_verify((mac_handle_t)mip, mac_addr,
12228275SEric Cheng addr_len)) {
12238275SEric Cheng *diag = MAC_DIAG_MACPREFIX_INVALID;
12248275SEric Cheng return (EINVAL);
12258275SEric Cheng }
12268275SEric Cheng }
12278275SEric Cheng
12288275SEric Cheng /* generate the MAC address */
12298275SEric Cheng if (prefix_len < addr_len) {
12308275SEric Cheng (void) random_get_pseudo_bytes(mac_addr +
12318275SEric Cheng prefix_len, addr_len - prefix_len);
12328275SEric Cheng }
12338275SEric Cheng
12348275SEric Cheng *diag = 0;
12358275SEric Cheng return (0);
12368275SEric Cheng }
12378275SEric Cheng
12388275SEric Cheng /*
12398275SEric Cheng * Set the priority range for this MAC client. This will be used to
12408275SEric Cheng * determine the absolute priority for the threads created for this
12418275SEric Cheng * MAC client using the specified "low", "medium" and "high" level.
12428275SEric Cheng * This will also be used for any subflows on this MAC client.
12438275SEric Cheng */
12448275SEric Cheng #define MAC_CLIENT_SET_PRIORITY_RANGE(mcip, pri) { \
12458275SEric Cheng (mcip)->mci_min_pri = FLOW_MIN_PRIORITY(MINCLSYSPRI, \
12468275SEric Cheng MAXCLSYSPRI, (pri)); \
12478275SEric Cheng (mcip)->mci_max_pri = FLOW_MAX_PRIORITY(MINCLSYSPRI, \
12488275SEric Cheng MAXCLSYSPRI, (mcip)->mci_min_pri); \
12498275SEric Cheng }
12508275SEric Cheng
12518275SEric Cheng /*
12528275SEric Cheng * MAC client open entry point. Return a new MAC client handle. Each
12538275SEric Cheng * MAC client is associated with a name, specified through the 'name'
12548275SEric Cheng * argument.
12558275SEric Cheng */
12568275SEric Cheng int
mac_client_open(mac_handle_t mh,mac_client_handle_t * mchp,char * name,uint16_t flags)12578275SEric Cheng mac_client_open(mac_handle_t mh, mac_client_handle_t *mchp, char *name,
12588275SEric Cheng uint16_t flags)
12598275SEric Cheng {
126011878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
126111878SVenu.Iyer@Sun.COM mac_client_impl_t *mcip;
126211878SVenu.Iyer@Sun.COM int err = 0;
126311878SVenu.Iyer@Sun.COM boolean_t share_desired;
126411878SVenu.Iyer@Sun.COM flow_entry_t *flent = NULL;
126511878SVenu.Iyer@Sun.COM
126611878SVenu.Iyer@Sun.COM share_desired = (flags & MAC_OPEN_FLAGS_SHARES_DESIRED) != 0;
12678275SEric Cheng *mchp = NULL;
12688275SEric Cheng
12698275SEric Cheng i_mac_perim_enter(mip);
12708275SEric Cheng
12718275SEric Cheng if (mip->mi_state_flags & MIS_IS_VNIC) {
12728275SEric Cheng /*
12738275SEric Cheng * The underlying MAC is a VNIC. Return the MAC client
12748275SEric Cheng * handle of the lower MAC which was obtained by
12758275SEric Cheng * the VNIC driver when it did its mac_client_open().
12768275SEric Cheng */
12778275SEric Cheng
12788275SEric Cheng mcip = mac_vnic_lower(mip);
12798275SEric Cheng
12808275SEric Cheng /*
12818275SEric Cheng * Note that multiple mac clients share the same mcip in
12828275SEric Cheng * this case.
12838275SEric Cheng */
12848275SEric Cheng if (flags & MAC_OPEN_FLAGS_EXCLUSIVE)
12858275SEric Cheng mcip->mci_state_flags |= MCIS_EXCLUSIVE;
12868275SEric Cheng
12879473SVenu.Iyer@Sun.COM if (flags & MAC_OPEN_FLAGS_MULTI_PRIMARY)
12889473SVenu.Iyer@Sun.COM mcip->mci_flags |= MAC_CLIENT_FLAGS_MULTI_PRIMARY;
12899473SVenu.Iyer@Sun.COM
12908275SEric Cheng mip->mi_clients_list = mcip;
12918275SEric Cheng i_mac_perim_exit(mip);
12928275SEric Cheng *mchp = (mac_client_handle_t)mcip;
12938275SEric Cheng return (err);
12948275SEric Cheng }
12958275SEric Cheng
12968275SEric Cheng mcip = kmem_cache_alloc(mac_client_impl_cache, KM_SLEEP);
12978275SEric Cheng
12988275SEric Cheng mcip->mci_mip = mip;
12998275SEric Cheng mcip->mci_upper_mip = NULL;
13008275SEric Cheng mcip->mci_rx_fn = mac_pkt_drop;
13018275SEric Cheng mcip->mci_rx_arg = NULL;
13029473SVenu.Iyer@Sun.COM mcip->mci_rx_p_fn = NULL;
13039473SVenu.Iyer@Sun.COM mcip->mci_rx_p_arg = NULL;
13049473SVenu.Iyer@Sun.COM mcip->mci_p_unicast_list = NULL;
13058275SEric Cheng mcip->mci_direct_rx_fn = NULL;
13068275SEric Cheng mcip->mci_direct_rx_arg = NULL;
13078275SEric Cheng
13089473SVenu.Iyer@Sun.COM mcip->mci_unicast_list = NULL;
13099473SVenu.Iyer@Sun.COM
13108275SEric Cheng if ((flags & MAC_OPEN_FLAGS_IS_VNIC) != 0)
13118275SEric Cheng mcip->mci_state_flags |= MCIS_IS_VNIC;
13128275SEric Cheng
13138275SEric Cheng if ((flags & MAC_OPEN_FLAGS_EXCLUSIVE) != 0)
13148275SEric Cheng mcip->mci_state_flags |= MCIS_EXCLUSIVE;
13158275SEric Cheng
13168275SEric Cheng if ((flags & MAC_OPEN_FLAGS_IS_AGGR_PORT) != 0)
13178275SEric Cheng mcip->mci_state_flags |= MCIS_IS_AGGR_PORT;
13188275SEric Cheng
131911878SVenu.Iyer@Sun.COM if (mip->mi_state_flags & MIS_IS_AGGR)
132011878SVenu.Iyer@Sun.COM mcip->mci_state_flags |= MCIS_IS_AGGR;
132111878SVenu.Iyer@Sun.COM
13228275SEric Cheng if ((flags & MAC_OPEN_FLAGS_USE_DATALINK_NAME) != 0) {
13238275SEric Cheng datalink_id_t linkid;
13248275SEric Cheng
13258275SEric Cheng ASSERT(name == NULL);
13268275SEric Cheng if ((err = dls_devnet_macname2linkid(mip->mi_name,
13278275SEric Cheng &linkid)) != 0) {
13288275SEric Cheng goto done;
13298275SEric Cheng }
13308275SEric Cheng if ((err = dls_mgmt_get_linkinfo(linkid, mcip->mci_name, NULL,
13318275SEric Cheng NULL, NULL)) != 0) {
13328275SEric Cheng /*
13338275SEric Cheng * Use mac name if dlmgmtd is not available.
13348275SEric Cheng */
13358275SEric Cheng if (err == EBADF) {
13368275SEric Cheng (void) strlcpy(mcip->mci_name, mip->mi_name,
13378275SEric Cheng sizeof (mcip->mci_name));
13388275SEric Cheng err = 0;
13398275SEric Cheng } else {
13408275SEric Cheng goto done;
13418275SEric Cheng }
13428275SEric Cheng }
13438275SEric Cheng mcip->mci_state_flags |= MCIS_USE_DATALINK_NAME;
13448275SEric Cheng } else {
13458275SEric Cheng ASSERT(name != NULL);
13468275SEric Cheng if (strlen(name) > MAXNAMELEN) {
13478275SEric Cheng err = EINVAL;
13488275SEric Cheng goto done;
13498275SEric Cheng }
13508275SEric Cheng (void) strlcpy(mcip->mci_name, name, sizeof (mcip->mci_name));
13518275SEric Cheng }
13529473SVenu.Iyer@Sun.COM
13539473SVenu.Iyer@Sun.COM if (flags & MAC_OPEN_FLAGS_MULTI_PRIMARY)
13549473SVenu.Iyer@Sun.COM mcip->mci_flags |= MAC_CLIENT_FLAGS_MULTI_PRIMARY;
13559473SVenu.Iyer@Sun.COM
135611878SVenu.Iyer@Sun.COM if (flags & MAC_OPEN_FLAGS_NO_UNICAST_ADDR)
135711878SVenu.Iyer@Sun.COM mcip->mci_state_flags |= MCIS_NO_UNICAST_ADDR;
135811878SVenu.Iyer@Sun.COM
135911878SVenu.Iyer@Sun.COM mac_protect_init(mcip);
136011878SVenu.Iyer@Sun.COM
13618275SEric Cheng /* the subflow table will be created dynamically */
13628275SEric Cheng mcip->mci_subflow_tab = NULL;
136311878SVenu.Iyer@Sun.COM
136411878SVenu.Iyer@Sun.COM mcip->mci_misc_stat.mms_multircv = 0;
136511878SVenu.Iyer@Sun.COM mcip->mci_misc_stat.mms_brdcstrcv = 0;
136611878SVenu.Iyer@Sun.COM mcip->mci_misc_stat.mms_multixmt = 0;
136711878SVenu.Iyer@Sun.COM mcip->mci_misc_stat.mms_brdcstxmt = 0;
13688275SEric Cheng
13698275SEric Cheng /* Create an initial flow */
13708275SEric Cheng
13718275SEric Cheng err = mac_flow_create(NULL, NULL, mcip->mci_name, NULL,
13728275SEric Cheng mcip->mci_state_flags & MCIS_IS_VNIC ? FLOW_VNIC_MAC :
13738275SEric Cheng FLOW_PRIMARY_MAC, &flent);
13748275SEric Cheng if (err != 0)
13758275SEric Cheng goto done;
13768275SEric Cheng mcip->mci_flent = flent;
13778275SEric Cheng FLOW_MARK(flent, FE_MC_NO_DATAPATH);
13788275SEric Cheng flent->fe_mcip = mcip;
13798275SEric Cheng /*
13808275SEric Cheng * Place initial creation reference on the flow. This reference
13818275SEric Cheng * is released in the corresponding delete action viz.
13828275SEric Cheng * mac_unicast_remove after waiting for all transient refs to
13838275SEric Cheng * to go away. The wait happens in mac_flow_wait.
13848275SEric Cheng */
13858275SEric Cheng FLOW_REFHOLD(flent);
13868275SEric Cheng
13878275SEric Cheng /*
13888275SEric Cheng * Do this ahead of the mac_bcast_add() below so that the mi_nclients
13898275SEric Cheng * will have the right value for mac_rx_srs_setup().
13908275SEric Cheng */
13918275SEric Cheng mac_client_add(mcip);
13928275SEric Cheng
13938275SEric Cheng mcip->mci_share = NULL;
139411878SVenu.Iyer@Sun.COM if (share_desired)
13958275SEric Cheng i_mac_share_alloc(mcip);
13968275SEric Cheng
13978275SEric Cheng DTRACE_PROBE2(mac__client__open__allocated, mac_impl_t *,
13988275SEric Cheng mcip->mci_mip, mac_client_impl_t *, mcip);
13998275SEric Cheng *mchp = (mac_client_handle_t)mcip;
14008275SEric Cheng
140111878SVenu.Iyer@Sun.COM /*
140211878SVenu.Iyer@Sun.COM * We will do mimimal datapath setup to allow a MAC client to
140311878SVenu.Iyer@Sun.COM * transmit or receive non-unicast packets without waiting
140411878SVenu.Iyer@Sun.COM * for mac_unicast_add.
140511878SVenu.Iyer@Sun.COM */
140611878SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_NO_UNICAST_ADDR) {
140711878SVenu.Iyer@Sun.COM if ((err = mac_client_datapath_setup(mcip, VLAN_ID_NONE,
140811878SVenu.Iyer@Sun.COM NULL, NULL, B_TRUE, NULL)) != 0) {
140911878SVenu.Iyer@Sun.COM goto done;
141011878SVenu.Iyer@Sun.COM }
141111878SVenu.Iyer@Sun.COM }
14128275SEric Cheng i_mac_perim_exit(mip);
14138275SEric Cheng return (0);
14148275SEric Cheng
14158275SEric Cheng done:
14168275SEric Cheng i_mac_perim_exit(mip);
14178275SEric Cheng mcip->mci_state_flags = 0;
14188275SEric Cheng mcip->mci_tx_flag = 0;
14198275SEric Cheng kmem_cache_free(mac_client_impl_cache, mcip);
14208275SEric Cheng return (err);
14218275SEric Cheng }
14228275SEric Cheng
14238275SEric Cheng /*
14248275SEric Cheng * Close the specified MAC client handle.
14258275SEric Cheng */
14268275SEric Cheng void
mac_client_close(mac_client_handle_t mch,uint16_t flags)14278275SEric Cheng mac_client_close(mac_client_handle_t mch, uint16_t flags)
14288275SEric Cheng {
14298275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
14308275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
14318275SEric Cheng flow_entry_t *flent;
14328275SEric Cheng
14338275SEric Cheng i_mac_perim_enter(mip);
14348275SEric Cheng
14358275SEric Cheng if (flags & MAC_CLOSE_FLAGS_EXCLUSIVE)
14368275SEric Cheng mcip->mci_state_flags &= ~MCIS_EXCLUSIVE;
14378275SEric Cheng
14388275SEric Cheng if ((mcip->mci_state_flags & MCIS_IS_VNIC) &&
14398275SEric Cheng !(flags & MAC_CLOSE_FLAGS_IS_VNIC)) {
14408275SEric Cheng /*
14418275SEric Cheng * This is an upper VNIC client initiated operation.
14428275SEric Cheng * The lower MAC client will be closed by the VNIC driver
14438275SEric Cheng * when the VNIC is deleted.
14448275SEric Cheng */
14458275SEric Cheng
14468275SEric Cheng i_mac_perim_exit(mip);
14478275SEric Cheng return;
14488275SEric Cheng }
14498275SEric Cheng
145011878SVenu.Iyer@Sun.COM /* If we have only setup up minimal datapth setup, tear it down */
145111878SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_NO_UNICAST_ADDR) {
145211878SVenu.Iyer@Sun.COM mac_client_datapath_teardown((mac_client_handle_t)mcip, NULL,
145311878SVenu.Iyer@Sun.COM mcip->mci_flent);
145411878SVenu.Iyer@Sun.COM mcip->mci_state_flags &= ~MCIS_NO_UNICAST_ADDR;
145511878SVenu.Iyer@Sun.COM }
145611878SVenu.Iyer@Sun.COM
14578275SEric Cheng /*
14588275SEric Cheng * Remove the flent associated with the MAC client
14598275SEric Cheng */
14608275SEric Cheng flent = mcip->mci_flent;
14618275SEric Cheng mcip->mci_flent = NULL;
14628275SEric Cheng FLOW_FINAL_REFRELE(flent);
14638275SEric Cheng
14648275SEric Cheng /*
14658275SEric Cheng * MAC clients must remove the unicast addresses and promisc callbacks
14668275SEric Cheng * they added before issuing a mac_client_close().
14678275SEric Cheng */
14688275SEric Cheng ASSERT(mcip->mci_unicast_list == NULL);
14698275SEric Cheng ASSERT(mcip->mci_promisc_list == NULL);
14708275SEric Cheng ASSERT(mcip->mci_tx_notify_cb_list == NULL);
14718275SEric Cheng
14728275SEric Cheng i_mac_share_free(mcip);
147311878SVenu.Iyer@Sun.COM mac_protect_fini(mcip);
14748275SEric Cheng mac_client_remove(mcip);
14758275SEric Cheng
14768275SEric Cheng i_mac_perim_exit(mip);
14778275SEric Cheng mcip->mci_subflow_tab = NULL;
14788275SEric Cheng mcip->mci_state_flags = 0;
14798275SEric Cheng mcip->mci_tx_flag = 0;
14808275SEric Cheng kmem_cache_free(mac_client_impl_cache, mch);
14818275SEric Cheng }
14828275SEric Cheng
14838275SEric Cheng /*
148411021SEric.Cheng@Sun.COM * Set the rx bypass receive callback.
14858275SEric Cheng */
14868275SEric Cheng boolean_t
mac_rx_bypass_set(mac_client_handle_t mch,mac_direct_rx_t rx_fn,void * arg1)14878275SEric Cheng mac_rx_bypass_set(mac_client_handle_t mch, mac_direct_rx_t rx_fn, void *arg1)
14888275SEric Cheng {
14898275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
14908275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
14918275SEric Cheng
14928275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
14938275SEric Cheng
14948275SEric Cheng /*
14958833SVenu.Iyer@Sun.COM * If the mac_client is a VLAN, we should not do DLS bypass and
14968833SVenu.Iyer@Sun.COM * instead let the packets come up via mac_rx_deliver so the vlan
14978833SVenu.Iyer@Sun.COM * header can be stripped.
14988275SEric Cheng */
14998833SVenu.Iyer@Sun.COM if (mcip->mci_nvids > 0)
15008275SEric Cheng return (B_FALSE);
15018275SEric Cheng
15028275SEric Cheng /*
15038275SEric Cheng * These are not accessed directly in the data path, and hence
15048275SEric Cheng * don't need any protection
15058275SEric Cheng */
15068275SEric Cheng mcip->mci_direct_rx_fn = rx_fn;
15078275SEric Cheng mcip->mci_direct_rx_arg = arg1;
15088275SEric Cheng return (B_TRUE);
15098275SEric Cheng }
15108275SEric Cheng
15118275SEric Cheng /*
151211021SEric.Cheng@Sun.COM * Enable/Disable rx bypass. By default, bypass is assumed to be enabled.
151311021SEric.Cheng@Sun.COM */
151411021SEric.Cheng@Sun.COM void
mac_rx_bypass_enable(mac_client_handle_t mch)151511021SEric.Cheng@Sun.COM mac_rx_bypass_enable(mac_client_handle_t mch)
151611021SEric.Cheng@Sun.COM {
151711021SEric.Cheng@Sun.COM ((mac_client_impl_t *)mch)->mci_state_flags &= ~MCIS_RX_BYPASS_DISABLE;
151811021SEric.Cheng@Sun.COM }
151911021SEric.Cheng@Sun.COM
152011021SEric.Cheng@Sun.COM void
mac_rx_bypass_disable(mac_client_handle_t mch)152111021SEric.Cheng@Sun.COM mac_rx_bypass_disable(mac_client_handle_t mch)
152211021SEric.Cheng@Sun.COM {
152311021SEric.Cheng@Sun.COM ((mac_client_impl_t *)mch)->mci_state_flags |= MCIS_RX_BYPASS_DISABLE;
152411021SEric.Cheng@Sun.COM }
152511021SEric.Cheng@Sun.COM
152611021SEric.Cheng@Sun.COM /*
15278275SEric Cheng * Set the receive callback for the specified MAC client. There can be
15288275SEric Cheng * at most one such callback per MAC client.
15298275SEric Cheng */
15308275SEric Cheng void
mac_rx_set(mac_client_handle_t mch,mac_rx_t rx_fn,void * arg)15318275SEric Cheng mac_rx_set(mac_client_handle_t mch, mac_rx_t rx_fn, void *arg)
15328275SEric Cheng {
15338275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
15348275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
15358275SEric Cheng
15368275SEric Cheng /*
15378275SEric Cheng * Instead of adding an extra set of locks and refcnts in
15388275SEric Cheng * the datapath at the mac client boundary, we temporarily quiesce
15398275SEric Cheng * the SRS and related entities. We then change the receive function
15408275SEric Cheng * without interference from any receive data thread and then reenable
15418275SEric Cheng * the data flow subsequently.
15428275SEric Cheng */
15438275SEric Cheng i_mac_perim_enter(mip);
15448275SEric Cheng mac_rx_client_quiesce(mch);
15458275SEric Cheng
15468275SEric Cheng mcip->mci_rx_fn = rx_fn;
15478275SEric Cheng mcip->mci_rx_arg = arg;
15488275SEric Cheng mac_rx_client_restart(mch);
15498275SEric Cheng i_mac_perim_exit(mip);
15508275SEric Cheng }
15518275SEric Cheng
15528275SEric Cheng /*
15538275SEric Cheng * Reset the receive callback for the specified MAC client.
15548275SEric Cheng */
15558275SEric Cheng void
mac_rx_clear(mac_client_handle_t mch)15568275SEric Cheng mac_rx_clear(mac_client_handle_t mch)
15578275SEric Cheng {
15588275SEric Cheng mac_rx_set(mch, mac_pkt_drop, NULL);
15598275SEric Cheng }
15608275SEric Cheng
15618275SEric Cheng /*
15628275SEric Cheng * Walk the MAC client subflow table and updates their priority values.
15638275SEric Cheng */
15648275SEric Cheng static int
mac_update_subflow_priority_cb(flow_entry_t * flent,void * arg)15658275SEric Cheng mac_update_subflow_priority_cb(flow_entry_t *flent, void *arg)
15668275SEric Cheng {
15678275SEric Cheng mac_flow_update_priority(arg, flent);
15688275SEric Cheng return (0);
15698275SEric Cheng }
15708275SEric Cheng
15718275SEric Cheng void
mac_update_subflow_priority(mac_client_impl_t * mcip)15728275SEric Cheng mac_update_subflow_priority(mac_client_impl_t *mcip)
15738275SEric Cheng {
15748275SEric Cheng (void) mac_flow_walk(mcip->mci_subflow_tab,
15758275SEric Cheng mac_update_subflow_priority_cb, mcip);
15768275SEric Cheng }
15778275SEric Cheng
15788275SEric Cheng /*
157911878SVenu.Iyer@Sun.COM * Modify the TX or RX ring properties. We could either just move around
158011878SVenu.Iyer@Sun.COM * rings, i.e add/remove rings given to a client. Or this might cause the
158111878SVenu.Iyer@Sun.COM * client to move from hardware based to software or the other way around.
158211878SVenu.Iyer@Sun.COM * If we want to reset this property, then we clear the mask, additionally
158311878SVenu.Iyer@Sun.COM * if the client was given a non-default group we remove all rings except
158411878SVenu.Iyer@Sun.COM * for 1 and give it back to the default group.
158511878SVenu.Iyer@Sun.COM */
158611878SVenu.Iyer@Sun.COM int
mac_client_set_rings_prop(mac_client_impl_t * mcip,mac_resource_props_t * mrp,mac_resource_props_t * tmrp)158711878SVenu.Iyer@Sun.COM mac_client_set_rings_prop(mac_client_impl_t *mcip, mac_resource_props_t *mrp,
158811878SVenu.Iyer@Sun.COM mac_resource_props_t *tmrp)
158911878SVenu.Iyer@Sun.COM {
159011878SVenu.Iyer@Sun.COM mac_impl_t *mip = mcip->mci_mip;
159111878SVenu.Iyer@Sun.COM flow_entry_t *flent = mcip->mci_flent;
159211878SVenu.Iyer@Sun.COM uint8_t *mac_addr;
159311878SVenu.Iyer@Sun.COM int err = 0;
159411878SVenu.Iyer@Sun.COM mac_group_t *defgrp;
159511878SVenu.Iyer@Sun.COM mac_group_t *group;
159611878SVenu.Iyer@Sun.COM mac_group_t *ngrp;
159711878SVenu.Iyer@Sun.COM mac_resource_props_t *cmrp = MCIP_RESOURCE_PROPS(mcip);
159811878SVenu.Iyer@Sun.COM uint_t ringcnt;
159911878SVenu.Iyer@Sun.COM boolean_t unspec;
160011878SVenu.Iyer@Sun.COM
160111878SVenu.Iyer@Sun.COM if (mcip->mci_share != NULL)
160211878SVenu.Iyer@Sun.COM return (EINVAL);
160311878SVenu.Iyer@Sun.COM
160411878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RX_RINGS) {
160511878SVenu.Iyer@Sun.COM unspec = mrp->mrp_mask & MRP_RXRINGS_UNSPEC;
160611878SVenu.Iyer@Sun.COM group = flent->fe_rx_ring_group;
160711878SVenu.Iyer@Sun.COM defgrp = MAC_DEFAULT_RX_GROUP(mip);
160811878SVenu.Iyer@Sun.COM mac_addr = flent->fe_flow_desc.fd_dst_mac;
160911878SVenu.Iyer@Sun.COM
161011878SVenu.Iyer@Sun.COM /*
161111878SVenu.Iyer@Sun.COM * No resulting change. If we are resetting on a client on
161211878SVenu.Iyer@Sun.COM * which there was no rx rings property. For dynamic group
161311878SVenu.Iyer@Sun.COM * if we are setting the same number of rings already set.
161411878SVenu.Iyer@Sun.COM * For static group if we are requesting a group again.
161511878SVenu.Iyer@Sun.COM */
161611878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RINGS_RESET) {
161711878SVenu.Iyer@Sun.COM if (!(tmrp->mrp_mask & MRP_RX_RINGS))
161811878SVenu.Iyer@Sun.COM return (0);
161911878SVenu.Iyer@Sun.COM } else {
162011878SVenu.Iyer@Sun.COM if (unspec) {
162111878SVenu.Iyer@Sun.COM if (tmrp->mrp_mask & MRP_RXRINGS_UNSPEC)
162211878SVenu.Iyer@Sun.COM return (0);
162311878SVenu.Iyer@Sun.COM } else if (mip->mi_rx_group_type ==
162411878SVenu.Iyer@Sun.COM MAC_GROUP_TYPE_DYNAMIC) {
162511878SVenu.Iyer@Sun.COM if ((tmrp->mrp_mask & MRP_RX_RINGS) &&
162611878SVenu.Iyer@Sun.COM !(tmrp->mrp_mask & MRP_RXRINGS_UNSPEC) &&
162711878SVenu.Iyer@Sun.COM mrp->mrp_nrxrings == tmrp->mrp_nrxrings) {
162811878SVenu.Iyer@Sun.COM return (0);
162911878SVenu.Iyer@Sun.COM }
163011878SVenu.Iyer@Sun.COM }
163111878SVenu.Iyer@Sun.COM }
163211878SVenu.Iyer@Sun.COM /* Resetting the prop */
163311878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RINGS_RESET) {
163411878SVenu.Iyer@Sun.COM /*
163511878SVenu.Iyer@Sun.COM * We will just keep one ring and give others back if
163611878SVenu.Iyer@Sun.COM * we are not the primary. For the primary we give
163711878SVenu.Iyer@Sun.COM * all the rings in the default group except the
163811878SVenu.Iyer@Sun.COM * default ring. If it is a static group, then
163911878SVenu.Iyer@Sun.COM * we don't do anything, but clear the MRP_RX_RINGS
164011878SVenu.Iyer@Sun.COM * flag.
164111878SVenu.Iyer@Sun.COM */
164211878SVenu.Iyer@Sun.COM if (group != defgrp) {
164311878SVenu.Iyer@Sun.COM if (mip->mi_rx_group_type ==
164411878SVenu.Iyer@Sun.COM MAC_GROUP_TYPE_DYNAMIC) {
164511878SVenu.Iyer@Sun.COM /*
164611878SVenu.Iyer@Sun.COM * This group has reserved rings
164711878SVenu.Iyer@Sun.COM * that need to be released now,
164811878SVenu.Iyer@Sun.COM * so does the group.
164911878SVenu.Iyer@Sun.COM */
165011878SVenu.Iyer@Sun.COM MAC_RX_RING_RELEASED(mip,
165111878SVenu.Iyer@Sun.COM group->mrg_cur_count);
165211878SVenu.Iyer@Sun.COM MAC_RX_GRP_RELEASED(mip);
165311878SVenu.Iyer@Sun.COM if ((flent->fe_type &
165411878SVenu.Iyer@Sun.COM FLOW_PRIMARY_MAC) != 0) {
165511878SVenu.Iyer@Sun.COM if (mip->mi_nactiveclients ==
165611878SVenu.Iyer@Sun.COM 1) {
165711878SVenu.Iyer@Sun.COM (void)
165811878SVenu.Iyer@Sun.COM mac_rx_switch_group(
165911878SVenu.Iyer@Sun.COM mcip, group,
166011878SVenu.Iyer@Sun.COM defgrp);
166111878SVenu.Iyer@Sun.COM return (0);
166211878SVenu.Iyer@Sun.COM } else {
166311878SVenu.Iyer@Sun.COM cmrp->mrp_nrxrings =
166411878SVenu.Iyer@Sun.COM group->
166511878SVenu.Iyer@Sun.COM mrg_cur_count +
166611878SVenu.Iyer@Sun.COM defgrp->
166711878SVenu.Iyer@Sun.COM mrg_cur_count - 1;
166811878SVenu.Iyer@Sun.COM }
166911878SVenu.Iyer@Sun.COM } else {
167011878SVenu.Iyer@Sun.COM cmrp->mrp_nrxrings = 1;
167111878SVenu.Iyer@Sun.COM }
167211878SVenu.Iyer@Sun.COM (void) mac_group_ring_modify(mcip,
167311878SVenu.Iyer@Sun.COM group, defgrp);
167411878SVenu.Iyer@Sun.COM } else {
167511878SVenu.Iyer@Sun.COM /*
167611878SVenu.Iyer@Sun.COM * If this is a static group, we
167711878SVenu.Iyer@Sun.COM * need to release the group. The
167811878SVenu.Iyer@Sun.COM * client will remain in the same
167911878SVenu.Iyer@Sun.COM * group till some other client
168011878SVenu.Iyer@Sun.COM * needs this group.
168111878SVenu.Iyer@Sun.COM */
168211878SVenu.Iyer@Sun.COM MAC_RX_GRP_RELEASED(mip);
168311878SVenu.Iyer@Sun.COM }
168411878SVenu.Iyer@Sun.COM /* Let check if we can give this an excl group */
168511878SVenu.Iyer@Sun.COM } else if (group == defgrp) {
168611878SVenu.Iyer@Sun.COM ngrp = mac_reserve_rx_group(mcip, mac_addr,
168711878SVenu.Iyer@Sun.COM B_TRUE);
168811878SVenu.Iyer@Sun.COM /* Couldn't give it a group, that's fine */
168911878SVenu.Iyer@Sun.COM if (ngrp == NULL)
169011878SVenu.Iyer@Sun.COM return (0);
169111878SVenu.Iyer@Sun.COM /* Switch to H/W */
169211878SVenu.Iyer@Sun.COM if (mac_rx_switch_group(mcip, defgrp, ngrp) !=
169311878SVenu.Iyer@Sun.COM 0) {
169411878SVenu.Iyer@Sun.COM mac_stop_group(ngrp);
169511878SVenu.Iyer@Sun.COM return (0);
169611878SVenu.Iyer@Sun.COM }
169711878SVenu.Iyer@Sun.COM }
169811878SVenu.Iyer@Sun.COM /*
169911878SVenu.Iyer@Sun.COM * If the client is in the default group, we will
170011878SVenu.Iyer@Sun.COM * just clear the MRP_RX_RINGS and leave it as
170111878SVenu.Iyer@Sun.COM * it rather than look for an exclusive group
170211878SVenu.Iyer@Sun.COM * for it.
170311878SVenu.Iyer@Sun.COM */
170411878SVenu.Iyer@Sun.COM return (0);
170511878SVenu.Iyer@Sun.COM }
170611878SVenu.Iyer@Sun.COM
170711878SVenu.Iyer@Sun.COM if (group == defgrp && ((mrp->mrp_nrxrings > 0) || unspec)) {
170811878SVenu.Iyer@Sun.COM ngrp = mac_reserve_rx_group(mcip, mac_addr, B_TRUE);
170911878SVenu.Iyer@Sun.COM if (ngrp == NULL)
171011878SVenu.Iyer@Sun.COM return (ENOSPC);
171111878SVenu.Iyer@Sun.COM
171211878SVenu.Iyer@Sun.COM /* Switch to H/W */
171311878SVenu.Iyer@Sun.COM if (mac_rx_switch_group(mcip, defgrp, ngrp) != 0) {
171411878SVenu.Iyer@Sun.COM mac_release_rx_group(mcip, ngrp);
171511878SVenu.Iyer@Sun.COM return (ENOSPC);
171611878SVenu.Iyer@Sun.COM }
171711878SVenu.Iyer@Sun.COM MAC_RX_GRP_RESERVED(mip);
171811878SVenu.Iyer@Sun.COM if (mip->mi_rx_group_type == MAC_GROUP_TYPE_DYNAMIC)
171911878SVenu.Iyer@Sun.COM MAC_RX_RING_RESERVED(mip, ngrp->mrg_cur_count);
172011878SVenu.Iyer@Sun.COM } else if (group != defgrp && !unspec &&
172111878SVenu.Iyer@Sun.COM mrp->mrp_nrxrings == 0) {
172211878SVenu.Iyer@Sun.COM /* Switch to S/W */
172311878SVenu.Iyer@Sun.COM ringcnt = group->mrg_cur_count;
172411878SVenu.Iyer@Sun.COM if (mac_rx_switch_group(mcip, group, defgrp) != 0)
172511878SVenu.Iyer@Sun.COM return (ENOSPC);
172611878SVenu.Iyer@Sun.COM if (tmrp->mrp_mask & MRP_RX_RINGS) {
172711878SVenu.Iyer@Sun.COM MAC_RX_GRP_RELEASED(mip);
172811878SVenu.Iyer@Sun.COM if (mip->mi_rx_group_type ==
172911878SVenu.Iyer@Sun.COM MAC_GROUP_TYPE_DYNAMIC) {
173011878SVenu.Iyer@Sun.COM MAC_RX_RING_RELEASED(mip, ringcnt);
173111878SVenu.Iyer@Sun.COM }
173211878SVenu.Iyer@Sun.COM }
173311878SVenu.Iyer@Sun.COM } else if (group != defgrp && mip->mi_rx_group_type ==
173411878SVenu.Iyer@Sun.COM MAC_GROUP_TYPE_DYNAMIC) {
173511878SVenu.Iyer@Sun.COM ringcnt = group->mrg_cur_count;
173611878SVenu.Iyer@Sun.COM err = mac_group_ring_modify(mcip, group, defgrp);
173711878SVenu.Iyer@Sun.COM if (err != 0)
173811878SVenu.Iyer@Sun.COM return (err);
173911878SVenu.Iyer@Sun.COM /*
174011878SVenu.Iyer@Sun.COM * Update the accounting. If this group
174111878SVenu.Iyer@Sun.COM * already had explicitly reserved rings,
174211878SVenu.Iyer@Sun.COM * we need to update the rings based on
174311878SVenu.Iyer@Sun.COM * the new ring count. If this group
174411878SVenu.Iyer@Sun.COM * had not explicitly reserved rings,
174511878SVenu.Iyer@Sun.COM * then we just reserve the rings asked for
174611878SVenu.Iyer@Sun.COM * and reserve the group.
174711878SVenu.Iyer@Sun.COM */
174811878SVenu.Iyer@Sun.COM if (tmrp->mrp_mask & MRP_RX_RINGS) {
174911878SVenu.Iyer@Sun.COM if (ringcnt > group->mrg_cur_count) {
175011878SVenu.Iyer@Sun.COM MAC_RX_RING_RELEASED(mip,
175111878SVenu.Iyer@Sun.COM ringcnt - group->mrg_cur_count);
175211878SVenu.Iyer@Sun.COM } else {
175311878SVenu.Iyer@Sun.COM MAC_RX_RING_RESERVED(mip,
175411878SVenu.Iyer@Sun.COM group->mrg_cur_count - ringcnt);
175511878SVenu.Iyer@Sun.COM }
175611878SVenu.Iyer@Sun.COM } else {
175711878SVenu.Iyer@Sun.COM MAC_RX_RING_RESERVED(mip, group->mrg_cur_count);
175811878SVenu.Iyer@Sun.COM MAC_RX_GRP_RESERVED(mip);
175911878SVenu.Iyer@Sun.COM }
176011878SVenu.Iyer@Sun.COM }
176111878SVenu.Iyer@Sun.COM }
176211878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_TX_RINGS) {
176311878SVenu.Iyer@Sun.COM unspec = mrp->mrp_mask & MRP_TXRINGS_UNSPEC;
176411878SVenu.Iyer@Sun.COM group = flent->fe_tx_ring_group;
176511878SVenu.Iyer@Sun.COM defgrp = MAC_DEFAULT_TX_GROUP(mip);
176611878SVenu.Iyer@Sun.COM
176711878SVenu.Iyer@Sun.COM /*
176811878SVenu.Iyer@Sun.COM * For static groups we only allow rings=0 or resetting the
176911878SVenu.Iyer@Sun.COM * rings property.
177011878SVenu.Iyer@Sun.COM */
177111878SVenu.Iyer@Sun.COM if (mrp->mrp_ntxrings > 0 &&
177211878SVenu.Iyer@Sun.COM mip->mi_tx_group_type != MAC_GROUP_TYPE_DYNAMIC) {
177311878SVenu.Iyer@Sun.COM return (ENOTSUP);
177411878SVenu.Iyer@Sun.COM }
177511878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RINGS_RESET) {
177611878SVenu.Iyer@Sun.COM if (!(tmrp->mrp_mask & MRP_TX_RINGS))
177711878SVenu.Iyer@Sun.COM return (0);
177811878SVenu.Iyer@Sun.COM } else {
177911878SVenu.Iyer@Sun.COM if (unspec) {
178011878SVenu.Iyer@Sun.COM if (tmrp->mrp_mask & MRP_TXRINGS_UNSPEC)
178111878SVenu.Iyer@Sun.COM return (0);
178211878SVenu.Iyer@Sun.COM } else if (mip->mi_tx_group_type ==
178311878SVenu.Iyer@Sun.COM MAC_GROUP_TYPE_DYNAMIC) {
178411878SVenu.Iyer@Sun.COM if ((tmrp->mrp_mask & MRP_TX_RINGS) &&
178511878SVenu.Iyer@Sun.COM !(tmrp->mrp_mask & MRP_TXRINGS_UNSPEC) &&
178611878SVenu.Iyer@Sun.COM mrp->mrp_ntxrings == tmrp->mrp_ntxrings) {
178711878SVenu.Iyer@Sun.COM return (0);
178811878SVenu.Iyer@Sun.COM }
178911878SVenu.Iyer@Sun.COM }
179011878SVenu.Iyer@Sun.COM }
179111878SVenu.Iyer@Sun.COM /* Resetting the prop */
179211878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RINGS_RESET) {
179311878SVenu.Iyer@Sun.COM if (group != defgrp) {
179411878SVenu.Iyer@Sun.COM if (mip->mi_tx_group_type ==
179511878SVenu.Iyer@Sun.COM MAC_GROUP_TYPE_DYNAMIC) {
179611878SVenu.Iyer@Sun.COM ringcnt = group->mrg_cur_count;
179711878SVenu.Iyer@Sun.COM if ((flent->fe_type &
179811878SVenu.Iyer@Sun.COM FLOW_PRIMARY_MAC) != 0) {
179911878SVenu.Iyer@Sun.COM mac_tx_client_quiesce(
180011878SVenu.Iyer@Sun.COM (mac_client_handle_t)
180111878SVenu.Iyer@Sun.COM mcip);
180211878SVenu.Iyer@Sun.COM mac_tx_switch_group(mcip,
180311878SVenu.Iyer@Sun.COM group, defgrp);
180411878SVenu.Iyer@Sun.COM mac_tx_client_restart(
180511878SVenu.Iyer@Sun.COM (mac_client_handle_t)
180611878SVenu.Iyer@Sun.COM mcip);
180711878SVenu.Iyer@Sun.COM MAC_TX_GRP_RELEASED(mip);
180811878SVenu.Iyer@Sun.COM MAC_TX_RING_RELEASED(mip,
180911878SVenu.Iyer@Sun.COM ringcnt);
181011878SVenu.Iyer@Sun.COM return (0);
181111878SVenu.Iyer@Sun.COM }
181211878SVenu.Iyer@Sun.COM cmrp->mrp_ntxrings = 1;
181311878SVenu.Iyer@Sun.COM (void) mac_group_ring_modify(mcip,
181411878SVenu.Iyer@Sun.COM group, defgrp);
181511878SVenu.Iyer@Sun.COM /*
181611878SVenu.Iyer@Sun.COM * This group has reserved rings
181711878SVenu.Iyer@Sun.COM * that need to be released now.
181811878SVenu.Iyer@Sun.COM */
181911878SVenu.Iyer@Sun.COM MAC_TX_RING_RELEASED(mip, ringcnt);
182011878SVenu.Iyer@Sun.COM }
182111878SVenu.Iyer@Sun.COM /*
182211878SVenu.Iyer@Sun.COM * If this is a static group, we
182311878SVenu.Iyer@Sun.COM * need to release the group. The
182411878SVenu.Iyer@Sun.COM * client will remain in the same
182511878SVenu.Iyer@Sun.COM * group till some other client
182611878SVenu.Iyer@Sun.COM * needs this group.
182711878SVenu.Iyer@Sun.COM */
182811878SVenu.Iyer@Sun.COM MAC_TX_GRP_RELEASED(mip);
182911878SVenu.Iyer@Sun.COM } else if (group == defgrp &&
183011878SVenu.Iyer@Sun.COM (flent->fe_type & FLOW_PRIMARY_MAC) == 0) {
183111878SVenu.Iyer@Sun.COM ngrp = mac_reserve_tx_group(mcip, B_TRUE);
183211878SVenu.Iyer@Sun.COM if (ngrp == NULL)
183311878SVenu.Iyer@Sun.COM return (0);
183411878SVenu.Iyer@Sun.COM mac_tx_client_quiesce(
183511878SVenu.Iyer@Sun.COM (mac_client_handle_t)mcip);
183611878SVenu.Iyer@Sun.COM mac_tx_switch_group(mcip, defgrp, ngrp);
183711878SVenu.Iyer@Sun.COM mac_tx_client_restart(
183811878SVenu.Iyer@Sun.COM (mac_client_handle_t)mcip);
183911878SVenu.Iyer@Sun.COM }
184011878SVenu.Iyer@Sun.COM /*
184111878SVenu.Iyer@Sun.COM * If the client is in the default group, we will
184211878SVenu.Iyer@Sun.COM * just clear the MRP_TX_RINGS and leave it as
184311878SVenu.Iyer@Sun.COM * it rather than look for an exclusive group
184411878SVenu.Iyer@Sun.COM * for it.
184511878SVenu.Iyer@Sun.COM */
184611878SVenu.Iyer@Sun.COM return (0);
184711878SVenu.Iyer@Sun.COM }
184811878SVenu.Iyer@Sun.COM
184911878SVenu.Iyer@Sun.COM /* Switch to H/W */
185011878SVenu.Iyer@Sun.COM if (group == defgrp && ((mrp->mrp_ntxrings > 0) || unspec)) {
185111878SVenu.Iyer@Sun.COM ngrp = mac_reserve_tx_group(mcip, B_TRUE);
185211878SVenu.Iyer@Sun.COM if (ngrp == NULL)
185311878SVenu.Iyer@Sun.COM return (ENOSPC);
185411878SVenu.Iyer@Sun.COM mac_tx_client_quiesce((mac_client_handle_t)mcip);
185511878SVenu.Iyer@Sun.COM mac_tx_switch_group(mcip, defgrp, ngrp);
185611878SVenu.Iyer@Sun.COM mac_tx_client_restart((mac_client_handle_t)mcip);
185711878SVenu.Iyer@Sun.COM MAC_TX_GRP_RESERVED(mip);
185811878SVenu.Iyer@Sun.COM if (mip->mi_tx_group_type == MAC_GROUP_TYPE_DYNAMIC)
185911878SVenu.Iyer@Sun.COM MAC_TX_RING_RESERVED(mip, ngrp->mrg_cur_count);
186011878SVenu.Iyer@Sun.COM /* Switch to S/W */
186111878SVenu.Iyer@Sun.COM } else if (group != defgrp && !unspec &&
186211878SVenu.Iyer@Sun.COM mrp->mrp_ntxrings == 0) {
186311878SVenu.Iyer@Sun.COM /* Switch to S/W */
186411878SVenu.Iyer@Sun.COM ringcnt = group->mrg_cur_count;
186511878SVenu.Iyer@Sun.COM mac_tx_client_quiesce((mac_client_handle_t)mcip);
186611878SVenu.Iyer@Sun.COM mac_tx_switch_group(mcip, group, defgrp);
186711878SVenu.Iyer@Sun.COM mac_tx_client_restart((mac_client_handle_t)mcip);
186811878SVenu.Iyer@Sun.COM if (tmrp->mrp_mask & MRP_TX_RINGS) {
186911878SVenu.Iyer@Sun.COM MAC_TX_GRP_RELEASED(mip);
187011878SVenu.Iyer@Sun.COM if (mip->mi_tx_group_type ==
187111878SVenu.Iyer@Sun.COM MAC_GROUP_TYPE_DYNAMIC) {
187211878SVenu.Iyer@Sun.COM MAC_TX_RING_RELEASED(mip, ringcnt);
187311878SVenu.Iyer@Sun.COM }
187411878SVenu.Iyer@Sun.COM }
187511878SVenu.Iyer@Sun.COM } else if (group != defgrp && mip->mi_tx_group_type ==
187611878SVenu.Iyer@Sun.COM MAC_GROUP_TYPE_DYNAMIC) {
187711878SVenu.Iyer@Sun.COM ringcnt = group->mrg_cur_count;
187811878SVenu.Iyer@Sun.COM err = mac_group_ring_modify(mcip, group, defgrp);
187911878SVenu.Iyer@Sun.COM if (err != 0)
188011878SVenu.Iyer@Sun.COM return (err);
188111878SVenu.Iyer@Sun.COM /*
188211878SVenu.Iyer@Sun.COM * Update the accounting. If this group
188311878SVenu.Iyer@Sun.COM * already had explicitly reserved rings,
188411878SVenu.Iyer@Sun.COM * we need to update the rings based on
188511878SVenu.Iyer@Sun.COM * the new ring count. If this group
188611878SVenu.Iyer@Sun.COM * had not explicitly reserved rings,
188711878SVenu.Iyer@Sun.COM * then we just reserve the rings asked for
188811878SVenu.Iyer@Sun.COM * and reserve the group.
188911878SVenu.Iyer@Sun.COM */
189011878SVenu.Iyer@Sun.COM if (tmrp->mrp_mask & MRP_TX_RINGS) {
189111878SVenu.Iyer@Sun.COM if (ringcnt > group->mrg_cur_count) {
189211878SVenu.Iyer@Sun.COM MAC_TX_RING_RELEASED(mip,
189311878SVenu.Iyer@Sun.COM ringcnt - group->mrg_cur_count);
189411878SVenu.Iyer@Sun.COM } else {
189511878SVenu.Iyer@Sun.COM MAC_TX_RING_RESERVED(mip,
189611878SVenu.Iyer@Sun.COM group->mrg_cur_count - ringcnt);
189711878SVenu.Iyer@Sun.COM }
189811878SVenu.Iyer@Sun.COM } else {
189911878SVenu.Iyer@Sun.COM MAC_TX_RING_RESERVED(mip, group->mrg_cur_count);
190011878SVenu.Iyer@Sun.COM MAC_TX_GRP_RESERVED(mip);
190111878SVenu.Iyer@Sun.COM }
190211878SVenu.Iyer@Sun.COM }
190311878SVenu.Iyer@Sun.COM }
190411878SVenu.Iyer@Sun.COM return (0);
190511878SVenu.Iyer@Sun.COM }
190611878SVenu.Iyer@Sun.COM
190711878SVenu.Iyer@Sun.COM /*
19088275SEric Cheng * When the MAC client is being brought up (i.e. we do a unicast_add) we need
19098275SEric Cheng * to initialize the cpu and resource control structure in the
19108275SEric Cheng * mac_client_impl_t from the mac_impl_t (i.e if there are any cached
19118275SEric Cheng * properties before the flow entry for the unicast address was created).
19128275SEric Cheng */
19138275SEric Cheng int
mac_resource_ctl_set(mac_client_handle_t mch,mac_resource_props_t * mrp)19148275SEric Cheng mac_resource_ctl_set(mac_client_handle_t mch, mac_resource_props_t *mrp)
19158275SEric Cheng {
19168275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
19178275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mcip->mci_mip;
19188275SEric Cheng int err = 0;
191911878SVenu.Iyer@Sun.COM flow_entry_t *flent = mcip->mci_flent;
192011878SVenu.Iyer@Sun.COM mac_resource_props_t *omrp, *nmrp = MCIP_RESOURCE_PROPS(mcip);
19218275SEric Cheng
19228275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
19238275SEric Cheng
192411878SVenu.Iyer@Sun.COM err = mac_validate_props(mcip->mci_state_flags & MCIS_IS_VNIC ?
192511878SVenu.Iyer@Sun.COM mcip->mci_upper_mip : mip, mrp);
19268275SEric Cheng if (err != 0)
19278275SEric Cheng return (err);
19288275SEric Cheng
192911878SVenu.Iyer@Sun.COM /*
193011878SVenu.Iyer@Sun.COM * Copy over the existing properties since mac_update_resources
193111878SVenu.Iyer@Sun.COM * will modify the client's mrp. Currently, the saved property
193211878SVenu.Iyer@Sun.COM * is used to determine the difference between existing and
193311878SVenu.Iyer@Sun.COM * modified rings property.
193411878SVenu.Iyer@Sun.COM */
193511878SVenu.Iyer@Sun.COM omrp = kmem_zalloc(sizeof (*omrp), KM_SLEEP);
193611878SVenu.Iyer@Sun.COM bcopy(nmrp, omrp, sizeof (*omrp));
19378275SEric Cheng mac_update_resources(mrp, MCIP_RESOURCE_PROPS(mcip), B_FALSE);
19388275SEric Cheng if (MCIP_DATAPATH_SETUP(mcip)) {
19398275SEric Cheng /*
194011878SVenu.Iyer@Sun.COM * We support rings only for primary client when there are
194111878SVenu.Iyer@Sun.COM * multiple clients sharing the same MAC address (e.g. VLAN).
194211878SVenu.Iyer@Sun.COM */
194311878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RX_RINGS ||
194411878SVenu.Iyer@Sun.COM mrp->mrp_mask & MRP_TX_RINGS) {
194511878SVenu.Iyer@Sun.COM
194611878SVenu.Iyer@Sun.COM if ((err = mac_client_set_rings_prop(mcip, mrp,
194711878SVenu.Iyer@Sun.COM omrp)) != 0) {
194811878SVenu.Iyer@Sun.COM if (omrp->mrp_mask & MRP_RX_RINGS) {
194911878SVenu.Iyer@Sun.COM nmrp->mrp_mask |= MRP_RX_RINGS;
195011878SVenu.Iyer@Sun.COM nmrp->mrp_nrxrings = omrp->mrp_nrxrings;
195111878SVenu.Iyer@Sun.COM } else {
195211878SVenu.Iyer@Sun.COM nmrp->mrp_mask &= ~MRP_RX_RINGS;
195311878SVenu.Iyer@Sun.COM nmrp->mrp_nrxrings = 0;
195411878SVenu.Iyer@Sun.COM }
195511878SVenu.Iyer@Sun.COM if (omrp->mrp_mask & MRP_TX_RINGS) {
195611878SVenu.Iyer@Sun.COM nmrp->mrp_mask |= MRP_TX_RINGS;
195711878SVenu.Iyer@Sun.COM nmrp->mrp_ntxrings = omrp->mrp_ntxrings;
195811878SVenu.Iyer@Sun.COM } else {
195911878SVenu.Iyer@Sun.COM nmrp->mrp_mask &= ~MRP_TX_RINGS;
196011878SVenu.Iyer@Sun.COM nmrp->mrp_ntxrings = 0;
196111878SVenu.Iyer@Sun.COM }
196211878SVenu.Iyer@Sun.COM if (omrp->mrp_mask & MRP_RXRINGS_UNSPEC)
196311878SVenu.Iyer@Sun.COM omrp->mrp_mask |= MRP_RXRINGS_UNSPEC;
196411878SVenu.Iyer@Sun.COM else
196511878SVenu.Iyer@Sun.COM omrp->mrp_mask &= ~MRP_RXRINGS_UNSPEC;
196611878SVenu.Iyer@Sun.COM
196711878SVenu.Iyer@Sun.COM if (omrp->mrp_mask & MRP_TXRINGS_UNSPEC)
196811878SVenu.Iyer@Sun.COM omrp->mrp_mask |= MRP_TXRINGS_UNSPEC;
196911878SVenu.Iyer@Sun.COM else
197011878SVenu.Iyer@Sun.COM omrp->mrp_mask &= ~MRP_TXRINGS_UNSPEC;
197111878SVenu.Iyer@Sun.COM kmem_free(omrp, sizeof (*omrp));
197211878SVenu.Iyer@Sun.COM return (err);
197311878SVenu.Iyer@Sun.COM }
197411878SVenu.Iyer@Sun.COM
197511878SVenu.Iyer@Sun.COM /*
197611878SVenu.Iyer@Sun.COM * If we modified the rings property of the primary
197711878SVenu.Iyer@Sun.COM * we need to update the property fields of its
197811878SVenu.Iyer@Sun.COM * VLANs as they inherit the primary's properites.
197911878SVenu.Iyer@Sun.COM */
198011878SVenu.Iyer@Sun.COM if (mac_is_primary_client(mcip)) {
198111878SVenu.Iyer@Sun.COM mac_set_prim_vlan_rings(mip,
198211878SVenu.Iyer@Sun.COM MCIP_RESOURCE_PROPS(mcip));
198311878SVenu.Iyer@Sun.COM }
198411878SVenu.Iyer@Sun.COM }
198511878SVenu.Iyer@Sun.COM /*
19868275SEric Cheng * We have to set this prior to calling mac_flow_modify.
19878275SEric Cheng */
19888275SEric Cheng if (mrp->mrp_mask & MRP_PRIORITY) {
19898275SEric Cheng if (mrp->mrp_priority == MPL_RESET) {
19908275SEric Cheng MAC_CLIENT_SET_PRIORITY_RANGE(mcip,
19918275SEric Cheng MPL_LINK_DEFAULT);
19928275SEric Cheng } else {
19938275SEric Cheng MAC_CLIENT_SET_PRIORITY_RANGE(mcip,
19948275SEric Cheng mrp->mrp_priority);
19958275SEric Cheng }
19968275SEric Cheng }
19978275SEric Cheng
199811878SVenu.Iyer@Sun.COM mac_flow_modify(mip->mi_flow_tab, flent, mrp);
19998275SEric Cheng if (mrp->mrp_mask & MRP_PRIORITY)
20008275SEric Cheng mac_update_subflow_priority(mcip);
20018275SEric Cheng }
200211878SVenu.Iyer@Sun.COM kmem_free(omrp, sizeof (*omrp));
20038275SEric Cheng return (0);
20048275SEric Cheng }
20058275SEric Cheng
20068275SEric Cheng void
mac_resource_ctl_get(mac_client_handle_t mch,mac_resource_props_t * mrp)20078275SEric Cheng mac_resource_ctl_get(mac_client_handle_t mch, mac_resource_props_t *mrp)
20088275SEric Cheng {
20098275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
20108275SEric Cheng mac_resource_props_t *mcip_mrp = MCIP_RESOURCE_PROPS(mcip);
20118275SEric Cheng
20128275SEric Cheng bcopy(mcip_mrp, mrp, sizeof (mac_resource_props_t));
20138275SEric Cheng }
20148275SEric Cheng
20158275SEric Cheng static int
mac_unicast_flow_create(mac_client_impl_t * mcip,uint8_t * mac_addr,uint16_t vid,boolean_t is_primary,boolean_t first_flow,flow_entry_t ** flent,mac_resource_props_t * mrp)20168275SEric Cheng mac_unicast_flow_create(mac_client_impl_t *mcip, uint8_t *mac_addr,
20178275SEric Cheng uint16_t vid, boolean_t is_primary, boolean_t first_flow,
20188275SEric Cheng flow_entry_t **flent, mac_resource_props_t *mrp)
20198275SEric Cheng {
20208275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mcip->mci_mip;
20218275SEric Cheng flow_desc_t flow_desc;
20228558SGirish.Moodalbail@Sun.COM char flowname[MAXFLOWNAMELEN];
20238275SEric Cheng int err;
20248275SEric Cheng uint_t flent_flags;
20258275SEric Cheng
20268275SEric Cheng /*
20278275SEric Cheng * First unicast address being added, create a new flow
20288275SEric Cheng * for that MAC client.
20298275SEric Cheng */
20308275SEric Cheng bzero(&flow_desc, sizeof (flow_desc));
20318275SEric Cheng
203211878SVenu.Iyer@Sun.COM ASSERT(mac_addr != NULL ||
203311878SVenu.Iyer@Sun.COM (mcip->mci_state_flags & MCIS_NO_UNICAST_ADDR));
203411878SVenu.Iyer@Sun.COM if (mac_addr != NULL) {
203511878SVenu.Iyer@Sun.COM flow_desc.fd_mac_len = mip->mi_type->mt_addr_length;
203611878SVenu.Iyer@Sun.COM bcopy(mac_addr, flow_desc.fd_dst_mac, flow_desc.fd_mac_len);
203711878SVenu.Iyer@Sun.COM }
20388275SEric Cheng flow_desc.fd_mask = FLOW_LINK_DST;
20398275SEric Cheng if (vid != 0) {
20408275SEric Cheng flow_desc.fd_vid = vid;
20418275SEric Cheng flow_desc.fd_mask |= FLOW_LINK_VID;
20428275SEric Cheng }
20438275SEric Cheng
20448275SEric Cheng /*
20458275SEric Cheng * XXX-nicolas. For now I'm keeping the FLOW_PRIMARY_MAC
20468275SEric Cheng * and FLOW_VNIC. Even though they're a hack inherited
20478275SEric Cheng * from the SRS code, we'll keep them for now. They're currently
20488275SEric Cheng * consumed by mac_datapath_setup() to create the SRS.
20498275SEric Cheng * That code should be eventually moved out of
20508275SEric Cheng * mac_datapath_setup() and moved to a mac_srs_create()
20518275SEric Cheng * function of some sort to keep things clean.
20528275SEric Cheng *
20538275SEric Cheng * Also, there's no reason why the SRS for the primary MAC
20548275SEric Cheng * client should be different than any other MAC client. Until
20558275SEric Cheng * this is cleaned-up, we support only one MAC unicast address
20568275SEric Cheng * per client.
20578275SEric Cheng *
20588275SEric Cheng * We set FLOW_PRIMARY_MAC for the primary MAC address,
20598275SEric Cheng * FLOW_VNIC for everything else.
20608275SEric Cheng */
20618275SEric Cheng if (is_primary)
20628275SEric Cheng flent_flags = FLOW_PRIMARY_MAC;
20638275SEric Cheng else
20648275SEric Cheng flent_flags = FLOW_VNIC_MAC;
20658275SEric Cheng
20668275SEric Cheng /*
20678275SEric Cheng * For the first flow we use the mac client's name - mci_name, for
20688275SEric Cheng * subsequent ones we just create a name with the vid. This is
20698275SEric Cheng * so that we can add these flows to the same flow table. This is
20708275SEric Cheng * fine as the flow name (except for the one with the mac client's
20718275SEric Cheng * name) is not visible. When the first flow is removed, we just replace
20728275SEric Cheng * its fdesc with another from the list, so we will still retain the
20738275SEric Cheng * flent with the MAC client's flow name.
20748275SEric Cheng */
20758275SEric Cheng if (first_flow) {
20768558SGirish.Moodalbail@Sun.COM bcopy(mcip->mci_name, flowname, MAXFLOWNAMELEN);
20778275SEric Cheng } else {
20788275SEric Cheng (void) sprintf(flowname, "%s%u", mcip->mci_name, vid);
20798275SEric Cheng flent_flags = FLOW_NO_STATS;
20808275SEric Cheng }
20818275SEric Cheng
20828275SEric Cheng if ((err = mac_flow_create(&flow_desc, mrp, flowname, NULL,
20838275SEric Cheng flent_flags, flent)) != 0)
20848275SEric Cheng return (err);
20858275SEric Cheng
208611878SVenu.Iyer@Sun.COM mac_misc_stat_create(*flent);
20878275SEric Cheng FLOW_MARK(*flent, FE_INCIPIENT);
20888275SEric Cheng (*flent)->fe_mcip = mcip;
20898275SEric Cheng
20908275SEric Cheng /*
20918275SEric Cheng * Place initial creation reference on the flow. This reference
20928275SEric Cheng * is released in the corresponding delete action viz.
20938275SEric Cheng * mac_unicast_remove after waiting for all transient refs to
20948275SEric Cheng * to go away. The wait happens in mac_flow_wait.
20958275SEric Cheng * We have already held the reference in mac_client_open().
20968275SEric Cheng */
20978275SEric Cheng if (!first_flow)
20988275SEric Cheng FLOW_REFHOLD(*flent);
20998275SEric Cheng return (0);
21008275SEric Cheng }
21018275SEric Cheng
21028275SEric Cheng /* Refresh the multicast grouping for this VID. */
21038275SEric Cheng int
mac_client_update_mcast(void * arg,boolean_t add,const uint8_t * addrp)21048275SEric Cheng mac_client_update_mcast(void *arg, boolean_t add, const uint8_t *addrp)
21058275SEric Cheng {
21068275SEric Cheng flow_entry_t *flent = arg;
21078275SEric Cheng mac_client_impl_t *mcip = flent->fe_mcip;
21088275SEric Cheng uint16_t vid;
21098275SEric Cheng flow_desc_t flow_desc;
21108275SEric Cheng
21118275SEric Cheng mac_flow_get_desc(flent, &flow_desc);
21128275SEric Cheng vid = (flow_desc.fd_mask & FLOW_LINK_VID) != 0 ?
21138275SEric Cheng flow_desc.fd_vid : VLAN_ID_NONE;
21148275SEric Cheng
21158275SEric Cheng /*
21168275SEric Cheng * We don't call mac_multicast_add()/mac_multicast_remove() as
21178275SEric Cheng * we want to add/remove for this specific vid.
21188275SEric Cheng */
21198275SEric Cheng if (add) {
21208275SEric Cheng return (mac_bcast_add(mcip, addrp, vid,
21218275SEric Cheng MAC_ADDRTYPE_MULTICAST));
21228275SEric Cheng } else {
21238275SEric Cheng mac_bcast_delete(mcip, addrp, vid);
21248275SEric Cheng return (0);
21258275SEric Cheng }
21268275SEric Cheng }
21278275SEric Cheng
21288833SVenu.Iyer@Sun.COM static void
mac_update_single_active_client(mac_impl_t * mip)21298833SVenu.Iyer@Sun.COM mac_update_single_active_client(mac_impl_t *mip)
21308833SVenu.Iyer@Sun.COM {
21318833SVenu.Iyer@Sun.COM mac_client_impl_t *client = NULL;
21328833SVenu.Iyer@Sun.COM
21338833SVenu.Iyer@Sun.COM ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
21348833SVenu.Iyer@Sun.COM
21358833SVenu.Iyer@Sun.COM rw_enter(&mip->mi_rw_lock, RW_WRITER);
21368833SVenu.Iyer@Sun.COM if (mip->mi_nactiveclients == 1) {
21378833SVenu.Iyer@Sun.COM /*
21388833SVenu.Iyer@Sun.COM * Find the one active MAC client from the list of MAC
21398833SVenu.Iyer@Sun.COM * clients. The active MAC client has at least one
21408833SVenu.Iyer@Sun.COM * unicast address.
21418833SVenu.Iyer@Sun.COM */
21428833SVenu.Iyer@Sun.COM for (client = mip->mi_clients_list; client != NULL;
21438833SVenu.Iyer@Sun.COM client = client->mci_client_next) {
21448833SVenu.Iyer@Sun.COM if (client->mci_unicast_list != NULL)
21458833SVenu.Iyer@Sun.COM break;
21468833SVenu.Iyer@Sun.COM }
21478833SVenu.Iyer@Sun.COM ASSERT(client != NULL);
21488833SVenu.Iyer@Sun.COM }
21498833SVenu.Iyer@Sun.COM
21508833SVenu.Iyer@Sun.COM /*
21518833SVenu.Iyer@Sun.COM * mi_single_active_client is protected by the MAC impl's read/writer
21528833SVenu.Iyer@Sun.COM * lock, which allows mac_rx() to check the value of that pointer
21538833SVenu.Iyer@Sun.COM * as a reader.
21548833SVenu.Iyer@Sun.COM */
21558833SVenu.Iyer@Sun.COM mip->mi_single_active_client = client;
21568833SVenu.Iyer@Sun.COM rw_exit(&mip->mi_rw_lock);
21578833SVenu.Iyer@Sun.COM }
21588833SVenu.Iyer@Sun.COM
21598275SEric Cheng /*
21609473SVenu.Iyer@Sun.COM * Set up the data path. Called from i_mac_unicast_add after having
21619473SVenu.Iyer@Sun.COM * done all the validations including making sure this is an active
21629473SVenu.Iyer@Sun.COM * client (i.e that is ready to process packets.)
21639473SVenu.Iyer@Sun.COM */
21649473SVenu.Iyer@Sun.COM static int
mac_client_datapath_setup(mac_client_impl_t * mcip,uint16_t vid,uint8_t * mac_addr,mac_resource_props_t * mrp,boolean_t isprimary,mac_unicast_impl_t * muip)21659473SVenu.Iyer@Sun.COM mac_client_datapath_setup(mac_client_impl_t *mcip, uint16_t vid,
21669473SVenu.Iyer@Sun.COM uint8_t *mac_addr, mac_resource_props_t *mrp, boolean_t isprimary,
21679473SVenu.Iyer@Sun.COM mac_unicast_impl_t *muip)
21689473SVenu.Iyer@Sun.COM {
21699473SVenu.Iyer@Sun.COM mac_impl_t *mip = mcip->mci_mip;
21709473SVenu.Iyer@Sun.COM boolean_t mac_started = B_FALSE;
21719473SVenu.Iyer@Sun.COM boolean_t bcast_added = B_FALSE;
21729473SVenu.Iyer@Sun.COM boolean_t nactiveclients_added = B_FALSE;
21739473SVenu.Iyer@Sun.COM flow_entry_t *flent;
21749473SVenu.Iyer@Sun.COM int err = 0;
217511878SVenu.Iyer@Sun.COM boolean_t no_unicast;
217611878SVenu.Iyer@Sun.COM
217711878SVenu.Iyer@Sun.COM no_unicast = mcip->mci_state_flags & MCIS_NO_UNICAST_ADDR;
21789473SVenu.Iyer@Sun.COM
21799473SVenu.Iyer@Sun.COM if ((err = mac_start((mac_handle_t)mip)) != 0)
21809473SVenu.Iyer@Sun.COM goto bail;
21819473SVenu.Iyer@Sun.COM
21829473SVenu.Iyer@Sun.COM mac_started = B_TRUE;
21839473SVenu.Iyer@Sun.COM
21849473SVenu.Iyer@Sun.COM /* add the MAC client to the broadcast address group by default */
21859473SVenu.Iyer@Sun.COM if (mip->mi_type->mt_brdcst_addr != NULL) {
21869473SVenu.Iyer@Sun.COM err = mac_bcast_add(mcip, mip->mi_type->mt_brdcst_addr, vid,
21879473SVenu.Iyer@Sun.COM MAC_ADDRTYPE_BROADCAST);
21889473SVenu.Iyer@Sun.COM if (err != 0)
21899473SVenu.Iyer@Sun.COM goto bail;
21909473SVenu.Iyer@Sun.COM bcast_added = B_TRUE;
21919473SVenu.Iyer@Sun.COM }
21929473SVenu.Iyer@Sun.COM
21939473SVenu.Iyer@Sun.COM /*
21949473SVenu.Iyer@Sun.COM * If this is the first unicast address addition for this
21959473SVenu.Iyer@Sun.COM * client, reuse the pre-allocated larval flow entry associated with
21969473SVenu.Iyer@Sun.COM * the MAC client.
21979473SVenu.Iyer@Sun.COM */
21989473SVenu.Iyer@Sun.COM flent = (mcip->mci_nflents == 0) ? mcip->mci_flent : NULL;
21999473SVenu.Iyer@Sun.COM
22009473SVenu.Iyer@Sun.COM /* We are configuring the unicast flow now */
22019473SVenu.Iyer@Sun.COM if (!MCIP_DATAPATH_SETUP(mcip)) {
22029473SVenu.Iyer@Sun.COM
220311878SVenu.Iyer@Sun.COM if (mrp != NULL) {
220411878SVenu.Iyer@Sun.COM MAC_CLIENT_SET_PRIORITY_RANGE(mcip,
220511878SVenu.Iyer@Sun.COM (mrp->mrp_mask & MRP_PRIORITY) ? mrp->mrp_priority :
220611878SVenu.Iyer@Sun.COM MPL_LINK_DEFAULT);
220711878SVenu.Iyer@Sun.COM }
22089473SVenu.Iyer@Sun.COM if ((err = mac_unicast_flow_create(mcip, mac_addr, vid,
22099473SVenu.Iyer@Sun.COM isprimary, B_TRUE, &flent, mrp)) != 0)
22109473SVenu.Iyer@Sun.COM goto bail;
22119473SVenu.Iyer@Sun.COM
22129473SVenu.Iyer@Sun.COM mip->mi_nactiveclients++;
22139473SVenu.Iyer@Sun.COM nactiveclients_added = B_TRUE;
22149473SVenu.Iyer@Sun.COM
22159473SVenu.Iyer@Sun.COM /*
22169473SVenu.Iyer@Sun.COM * This will allocate the RX ring group if possible for the
22179473SVenu.Iyer@Sun.COM * flow and program the software classifier as needed.
22189473SVenu.Iyer@Sun.COM */
22199473SVenu.Iyer@Sun.COM if ((err = mac_datapath_setup(mcip, flent, SRST_LINK)) != 0)
22209473SVenu.Iyer@Sun.COM goto bail;
22219473SVenu.Iyer@Sun.COM
222211878SVenu.Iyer@Sun.COM if (no_unicast)
222311878SVenu.Iyer@Sun.COM goto done_setup;
22249473SVenu.Iyer@Sun.COM /*
22259473SVenu.Iyer@Sun.COM * The unicast MAC address must have been added successfully.
22269473SVenu.Iyer@Sun.COM */
22279473SVenu.Iyer@Sun.COM ASSERT(mcip->mci_unicast != NULL);
22289473SVenu.Iyer@Sun.COM /*
22299473SVenu.Iyer@Sun.COM * Push down the sub-flows that were defined on this link
22309473SVenu.Iyer@Sun.COM * hitherto. The flows are added to the active flow table
22319473SVenu.Iyer@Sun.COM * and SRS, softrings etc. are created as needed.
22329473SVenu.Iyer@Sun.COM */
22339473SVenu.Iyer@Sun.COM mac_link_init_flows((mac_client_handle_t)mcip);
22349473SVenu.Iyer@Sun.COM } else {
22359473SVenu.Iyer@Sun.COM mac_address_t *map = mcip->mci_unicast;
22369473SVenu.Iyer@Sun.COM
223711878SVenu.Iyer@Sun.COM ASSERT(!no_unicast);
22389473SVenu.Iyer@Sun.COM /*
22399473SVenu.Iyer@Sun.COM * A unicast flow already exists for that MAC client,
22409473SVenu.Iyer@Sun.COM * this flow must be the same mac address but with
22419473SVenu.Iyer@Sun.COM * different VID. It has been checked by mac_addr_in_use().
22429473SVenu.Iyer@Sun.COM *
22439473SVenu.Iyer@Sun.COM * We will use the SRS etc. from the mci_flent. Note that
22449473SVenu.Iyer@Sun.COM * We don't need to create kstat for this as except for
22459473SVenu.Iyer@Sun.COM * the fdesc, everything will be used from in the 1st flent.
22469473SVenu.Iyer@Sun.COM */
22479473SVenu.Iyer@Sun.COM
22489473SVenu.Iyer@Sun.COM if (bcmp(mac_addr, map->ma_addr, map->ma_len) != 0) {
22499473SVenu.Iyer@Sun.COM err = EINVAL;
22509473SVenu.Iyer@Sun.COM goto bail;
22519473SVenu.Iyer@Sun.COM }
22529473SVenu.Iyer@Sun.COM
22539473SVenu.Iyer@Sun.COM if ((err = mac_unicast_flow_create(mcip, mac_addr, vid,
22549473SVenu.Iyer@Sun.COM isprimary, B_FALSE, &flent, NULL)) != 0) {
22559473SVenu.Iyer@Sun.COM goto bail;
22569473SVenu.Iyer@Sun.COM }
22579473SVenu.Iyer@Sun.COM if ((err = mac_flow_add(mip->mi_flow_tab, flent)) != 0) {
22589473SVenu.Iyer@Sun.COM FLOW_FINAL_REFRELE(flent);
22599473SVenu.Iyer@Sun.COM goto bail;
22609473SVenu.Iyer@Sun.COM }
22619473SVenu.Iyer@Sun.COM
22629473SVenu.Iyer@Sun.COM /* update the multicast group for this vid */
22639473SVenu.Iyer@Sun.COM mac_client_bcast_refresh(mcip, mac_client_update_mcast,
22649473SVenu.Iyer@Sun.COM (void *)flent, B_TRUE);
22659473SVenu.Iyer@Sun.COM
22669473SVenu.Iyer@Sun.COM }
22679473SVenu.Iyer@Sun.COM
22689473SVenu.Iyer@Sun.COM /* populate the shared MAC address */
22699473SVenu.Iyer@Sun.COM muip->mui_map = mcip->mci_unicast;
22709473SVenu.Iyer@Sun.COM
22719473SVenu.Iyer@Sun.COM rw_enter(&mcip->mci_rw_lock, RW_WRITER);
22729473SVenu.Iyer@Sun.COM muip->mui_next = mcip->mci_unicast_list;
22739473SVenu.Iyer@Sun.COM mcip->mci_unicast_list = muip;
22749473SVenu.Iyer@Sun.COM rw_exit(&mcip->mci_rw_lock);
22759473SVenu.Iyer@Sun.COM
227611878SVenu.Iyer@Sun.COM done_setup:
22779473SVenu.Iyer@Sun.COM /*
22789473SVenu.Iyer@Sun.COM * First add the flent to the flow list of this mcip. Then set
22799473SVenu.Iyer@Sun.COM * the mip's mi_single_active_client if needed. The Rx path assumes
22809473SVenu.Iyer@Sun.COM * that mip->mi_single_active_client will always have an associated
22819473SVenu.Iyer@Sun.COM * flent.
22829473SVenu.Iyer@Sun.COM */
22839473SVenu.Iyer@Sun.COM mac_client_add_to_flow_list(mcip, flent);
22849473SVenu.Iyer@Sun.COM if (nactiveclients_added)
22859473SVenu.Iyer@Sun.COM mac_update_single_active_client(mip);
22869473SVenu.Iyer@Sun.COM /*
22879473SVenu.Iyer@Sun.COM * Trigger a renegotiation of the capabilities when the number of
22889473SVenu.Iyer@Sun.COM * active clients changes from 1 to 2, since some of the capabilities
22899473SVenu.Iyer@Sun.COM * might have to be disabled. Also send a MAC_NOTE_LINK notification
22909473SVenu.Iyer@Sun.COM * to all the MAC clients whenever physical link is DOWN.
22919473SVenu.Iyer@Sun.COM */
22929473SVenu.Iyer@Sun.COM if (mip->mi_nactiveclients == 2) {
22939473SVenu.Iyer@Sun.COM mac_capab_update((mac_handle_t)mip);
22949473SVenu.Iyer@Sun.COM mac_virtual_link_update(mip);
22959473SVenu.Iyer@Sun.COM }
22969473SVenu.Iyer@Sun.COM /*
22979473SVenu.Iyer@Sun.COM * Now that the setup is complete, clear the INCIPIENT flag.
22989473SVenu.Iyer@Sun.COM * The flag was set to avoid incoming packets seeing inconsistent
22999473SVenu.Iyer@Sun.COM * structures while the setup was in progress. Clear the mci_tx_flag
23009473SVenu.Iyer@Sun.COM * by calling mac_tx_client_block. It is possible that
23019473SVenu.Iyer@Sun.COM * mac_unicast_remove was called prior to this mac_unicast_add which
23029473SVenu.Iyer@Sun.COM * could have set the MCI_TX_QUIESCE flag.
23039473SVenu.Iyer@Sun.COM */
23049473SVenu.Iyer@Sun.COM if (flent->fe_rx_ring_group != NULL)
23059473SVenu.Iyer@Sun.COM mac_rx_group_unmark(flent->fe_rx_ring_group, MR_INCIPIENT);
23069473SVenu.Iyer@Sun.COM FLOW_UNMARK(flent, FE_INCIPIENT);
23079473SVenu.Iyer@Sun.COM FLOW_UNMARK(flent, FE_MC_NO_DATAPATH);
23089473SVenu.Iyer@Sun.COM mac_tx_client_unblock(mcip);
23099473SVenu.Iyer@Sun.COM return (0);
23109473SVenu.Iyer@Sun.COM bail:
23119473SVenu.Iyer@Sun.COM if (bcast_added)
23129473SVenu.Iyer@Sun.COM mac_bcast_delete(mcip, mip->mi_type->mt_brdcst_addr, vid);
23139473SVenu.Iyer@Sun.COM
23149473SVenu.Iyer@Sun.COM if (nactiveclients_added)
23159473SVenu.Iyer@Sun.COM mip->mi_nactiveclients--;
23169473SVenu.Iyer@Sun.COM
231710013SNitin.Hande@Sun.COM if (mac_started)
231810013SNitin.Hande@Sun.COM mac_stop((mac_handle_t)mip);
231910013SNitin.Hande@Sun.COM
23209473SVenu.Iyer@Sun.COM return (err);
23219473SVenu.Iyer@Sun.COM }
23229473SVenu.Iyer@Sun.COM
23239473SVenu.Iyer@Sun.COM /*
23249473SVenu.Iyer@Sun.COM * Return the passive primary MAC client, if present. The passive client is
23259473SVenu.Iyer@Sun.COM * a stand-by client that has the same unicast address as another that is
23269473SVenu.Iyer@Sun.COM * currenly active. Once the active client goes away, the passive client
23279473SVenu.Iyer@Sun.COM * becomes active.
23289473SVenu.Iyer@Sun.COM */
23299473SVenu.Iyer@Sun.COM static mac_client_impl_t *
mac_get_passive_primary_client(mac_impl_t * mip)23309473SVenu.Iyer@Sun.COM mac_get_passive_primary_client(mac_impl_t *mip)
23319473SVenu.Iyer@Sun.COM {
23329473SVenu.Iyer@Sun.COM mac_client_impl_t *mcip;
23339473SVenu.Iyer@Sun.COM
23349473SVenu.Iyer@Sun.COM for (mcip = mip->mi_clients_list; mcip != NULL;
23359473SVenu.Iyer@Sun.COM mcip = mcip->mci_client_next) {
23369473SVenu.Iyer@Sun.COM if (mac_is_primary_client(mcip) &&
23379473SVenu.Iyer@Sun.COM (mcip->mci_flags & MAC_CLIENT_FLAGS_PASSIVE_PRIMARY) != 0) {
23389473SVenu.Iyer@Sun.COM return (mcip);
23399473SVenu.Iyer@Sun.COM }
23409473SVenu.Iyer@Sun.COM }
23419473SVenu.Iyer@Sun.COM return (NULL);
23429473SVenu.Iyer@Sun.COM }
23439473SVenu.Iyer@Sun.COM
23449473SVenu.Iyer@Sun.COM /*
23458275SEric Cheng * Add a new unicast address to the MAC client.
23468275SEric Cheng *
23478275SEric Cheng * The MAC address can be specified either by value, or the MAC client
23488275SEric Cheng * can specify that it wants to use the primary MAC address of the
23498275SEric Cheng * underlying MAC. See the introductory comments at the beginning
23508275SEric Cheng * of this file for more more information on primary MAC addresses.
23518275SEric Cheng *
23528275SEric Cheng * Note also the tuple (MAC address, VID) must be unique
23538275SEric Cheng * for the MAC clients defined on top of the same underlying MAC
23548275SEric Cheng * instance, unless the MAC_UNICAST_NODUPCHECK is specified.
235510491SRishi.Srivatsavai@Sun.COM *
235610491SRishi.Srivatsavai@Sun.COM * In no case can a client use the PVID for the MAC, if the MAC has one set.
23578275SEric Cheng */
23588275SEric Cheng int
i_mac_unicast_add(mac_client_handle_t mch,uint8_t * mac_addr,uint16_t flags,mac_unicast_handle_t * mah,uint16_t vid,mac_diag_t * diag)23598275SEric Cheng i_mac_unicast_add(mac_client_handle_t mch, uint8_t *mac_addr, uint16_t flags,
23608275SEric Cheng mac_unicast_handle_t *mah, uint16_t vid, mac_diag_t *diag)
23618275SEric Cheng {
23629473SVenu.Iyer@Sun.COM mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
23639473SVenu.Iyer@Sun.COM mac_impl_t *mip = mcip->mci_mip;
23649473SVenu.Iyer@Sun.COM int err;
23659473SVenu.Iyer@Sun.COM uint_t mac_len = mip->mi_type->mt_addr_length;
23669473SVenu.Iyer@Sun.COM boolean_t check_dups = !(flags & MAC_UNICAST_NODUPCHECK);
23679473SVenu.Iyer@Sun.COM boolean_t fastpath_disabled = B_FALSE;
23689473SVenu.Iyer@Sun.COM boolean_t is_primary = (flags & MAC_UNICAST_PRIMARY);
23699473SVenu.Iyer@Sun.COM boolean_t is_unicast_hw = (flags & MAC_UNICAST_HW);
237011878SVenu.Iyer@Sun.COM mac_resource_props_t *mrp;
23719473SVenu.Iyer@Sun.COM boolean_t passive_client = B_FALSE;
23729473SVenu.Iyer@Sun.COM mac_unicast_impl_t *muip;
23739473SVenu.Iyer@Sun.COM boolean_t is_vnic_primary =
23749473SVenu.Iyer@Sun.COM (flags & MAC_UNICAST_VNIC_PRIMARY);
23758275SEric Cheng
23768275SEric Cheng /* when VID is non-zero, the underlying MAC can not be VNIC */
23778275SEric Cheng ASSERT(!((mip->mi_state_flags & MIS_IS_VNIC) && (vid != 0)));
23788275SEric Cheng
23798275SEric Cheng /*
238011878SVenu.Iyer@Sun.COM * Can't unicast add if the client asked only for minimal datapath
238111878SVenu.Iyer@Sun.COM * setup.
238211878SVenu.Iyer@Sun.COM */
238311878SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_NO_UNICAST_ADDR)
238411878SVenu.Iyer@Sun.COM return (ENOTSUP);
238511878SVenu.Iyer@Sun.COM
238611878SVenu.Iyer@Sun.COM /*
238710491SRishi.Srivatsavai@Sun.COM * Check for an attempted use of the current Port VLAN ID, if enabled.
238810491SRishi.Srivatsavai@Sun.COM * No client may use it.
238910491SRishi.Srivatsavai@Sun.COM */
239010491SRishi.Srivatsavai@Sun.COM if (mip->mi_pvid != 0 && vid == mip->mi_pvid)
239110491SRishi.Srivatsavai@Sun.COM return (EBUSY);
239210491SRishi.Srivatsavai@Sun.COM
239310491SRishi.Srivatsavai@Sun.COM /*
23948275SEric Cheng * Check whether it's the primary client and flag it.
23958275SEric Cheng */
23968275SEric Cheng if (!(mcip->mci_state_flags & MCIS_IS_VNIC) && is_primary && vid == 0)
23978275SEric Cheng mcip->mci_flags |= MAC_CLIENT_FLAGS_PRIMARY;
23988275SEric Cheng
23998275SEric Cheng /*
24008275SEric Cheng * is_vnic_primary is true when we come here as a VLAN VNIC
24018275SEric Cheng * which uses the primary mac client's address but with a non-zero
24028275SEric Cheng * VID. In this case the MAC address is not specified by an upper
24038275SEric Cheng * MAC client.
24048275SEric Cheng */
24058275SEric Cheng if ((mcip->mci_state_flags & MCIS_IS_VNIC) && is_primary &&
24068275SEric Cheng !is_vnic_primary) {
24078275SEric Cheng /*
24088275SEric Cheng * The address is being set by the upper MAC client
24098275SEric Cheng * of a VNIC. The MAC address was already set by the
24108275SEric Cheng * VNIC driver during VNIC creation.
24118275SEric Cheng *
24128275SEric Cheng * Note: a VNIC has only one MAC address. We return
24138275SEric Cheng * the MAC unicast address handle of the lower MAC client
24148275SEric Cheng * corresponding to the VNIC. We allocate a new entry
24158275SEric Cheng * which is flagged appropriately, so that mac_unicast_remove()
24168275SEric Cheng * doesn't attempt to free the original entry that
24178275SEric Cheng * was allocated by the VNIC driver.
24188275SEric Cheng */
24198275SEric Cheng ASSERT(mcip->mci_unicast != NULL);
24208275SEric Cheng
24219024SVenu.Iyer@Sun.COM /* Check for VLAN flags, if present */
24229024SVenu.Iyer@Sun.COM if ((flags & MAC_UNICAST_TAG_DISABLE) != 0)
24239024SVenu.Iyer@Sun.COM mcip->mci_state_flags |= MCIS_TAG_DISABLE;
24249024SVenu.Iyer@Sun.COM
24259024SVenu.Iyer@Sun.COM if ((flags & MAC_UNICAST_STRIP_DISABLE) != 0)
24269024SVenu.Iyer@Sun.COM mcip->mci_state_flags |= MCIS_STRIP_DISABLE;
24279024SVenu.Iyer@Sun.COM
24289024SVenu.Iyer@Sun.COM if ((flags & MAC_UNICAST_DISABLE_TX_VID_CHECK) != 0)
24299024SVenu.Iyer@Sun.COM mcip->mci_state_flags |= MCIS_DISABLE_TX_VID_CHECK;
24309024SVenu.Iyer@Sun.COM
24318275SEric Cheng /*
24328275SEric Cheng * Ensure that the primary unicast address of the VNIC
24339473SVenu.Iyer@Sun.COM * is added only once unless we have the
24349473SVenu.Iyer@Sun.COM * MAC_CLIENT_FLAGS_MULTI_PRIMARY set (and this is not
24359473SVenu.Iyer@Sun.COM * a passive MAC client).
24368275SEric Cheng */
24379473SVenu.Iyer@Sun.COM if ((mcip->mci_flags & MAC_CLIENT_FLAGS_VNIC_PRIMARY) != 0) {
24389473SVenu.Iyer@Sun.COM if ((mcip->mci_flags &
24399473SVenu.Iyer@Sun.COM MAC_CLIENT_FLAGS_MULTI_PRIMARY) == 0 ||
24409473SVenu.Iyer@Sun.COM (mcip->mci_flags &
24419473SVenu.Iyer@Sun.COM MAC_CLIENT_FLAGS_PASSIVE_PRIMARY) != 0) {
24429473SVenu.Iyer@Sun.COM return (EBUSY);
24439473SVenu.Iyer@Sun.COM }
24449473SVenu.Iyer@Sun.COM mcip->mci_flags |= MAC_CLIENT_FLAGS_PASSIVE_PRIMARY;
24459473SVenu.Iyer@Sun.COM passive_client = B_TRUE;
24469473SVenu.Iyer@Sun.COM }
24478275SEric Cheng
24488275SEric Cheng mcip->mci_flags |= MAC_CLIENT_FLAGS_VNIC_PRIMARY;
24498275SEric Cheng
24508275SEric Cheng /*
24518275SEric Cheng * Create a handle for vid 0.
24528275SEric Cheng */
24538275SEric Cheng ASSERT(vid == 0);
24548275SEric Cheng muip = kmem_zalloc(sizeof (mac_unicast_impl_t), KM_SLEEP);
24558275SEric Cheng muip->mui_vid = vid;
24568275SEric Cheng *mah = (mac_unicast_handle_t)muip;
24579473SVenu.Iyer@Sun.COM /*
24589473SVenu.Iyer@Sun.COM * This will be used by the caller to defer setting the
24599473SVenu.Iyer@Sun.COM * rx functions.
24609473SVenu.Iyer@Sun.COM */
24619473SVenu.Iyer@Sun.COM if (passive_client)
24629473SVenu.Iyer@Sun.COM return (EAGAIN);
24638275SEric Cheng return (0);
24648275SEric Cheng }
24658275SEric Cheng
24668275SEric Cheng /* primary MAC clients cannot be opened on top of anchor VNICs */
24678275SEric Cheng if ((is_vnic_primary || is_primary) &&
24688275SEric Cheng i_mac_capab_get((mac_handle_t)mip, MAC_CAPAB_ANCHOR_VNIC, NULL)) {
24698275SEric Cheng return (ENXIO);
24708275SEric Cheng }
24718275SEric Cheng
24728275SEric Cheng /*
24739073SCathy.Zhou@Sun.COM * If this is a VNIC/VLAN, disable softmac fast-path.
24749073SCathy.Zhou@Sun.COM */
24759073SCathy.Zhou@Sun.COM if (mcip->mci_state_flags & MCIS_IS_VNIC) {
24769073SCathy.Zhou@Sun.COM err = mac_fastpath_disable((mac_handle_t)mip);
24779073SCathy.Zhou@Sun.COM if (err != 0)
24789073SCathy.Zhou@Sun.COM return (err);
24799073SCathy.Zhou@Sun.COM fastpath_disabled = B_TRUE;
24809073SCathy.Zhou@Sun.COM }
24819073SCathy.Zhou@Sun.COM
24829073SCathy.Zhou@Sun.COM /*
24838275SEric Cheng * Return EBUSY if:
24849073SCathy.Zhou@Sun.COM * - there is an exclusively active mac client exists.
24859073SCathy.Zhou@Sun.COM * - this is an exclusive active mac client but
24869073SCathy.Zhou@Sun.COM * a. there is already active mac clients exist, or
24879073SCathy.Zhou@Sun.COM * b. fastpath streams are already plumbed on this legacy device
248810491SRishi.Srivatsavai@Sun.COM * - the mac creator has disallowed active mac clients.
24898275SEric Cheng */
249010491SRishi.Srivatsavai@Sun.COM if (mip->mi_state_flags & (MIS_EXCLUSIVE|MIS_NO_ACTIVE)) {
24919073SCathy.Zhou@Sun.COM if (fastpath_disabled)
24929073SCathy.Zhou@Sun.COM mac_fastpath_enable((mac_handle_t)mip);
24938275SEric Cheng return (EBUSY);
24948275SEric Cheng }
24958275SEric Cheng
24969073SCathy.Zhou@Sun.COM if (mcip->mci_state_flags & MCIS_EXCLUSIVE) {
24979073SCathy.Zhou@Sun.COM ASSERT(!fastpath_disabled);
24989073SCathy.Zhou@Sun.COM if (mip->mi_nactiveclients != 0)
24999073SCathy.Zhou@Sun.COM return (EBUSY);
25009073SCathy.Zhou@Sun.COM
25019073SCathy.Zhou@Sun.COM if ((mip->mi_state_flags & MIS_LEGACY) &&
25029073SCathy.Zhou@Sun.COM !(mip->mi_capab_legacy.ml_active_set(mip->mi_driver))) {
25039073SCathy.Zhou@Sun.COM return (EBUSY);
25049073SCathy.Zhou@Sun.COM }
25058275SEric Cheng mip->mi_state_flags |= MIS_EXCLUSIVE;
25069073SCathy.Zhou@Sun.COM }
25078275SEric Cheng
250811878SVenu.Iyer@Sun.COM mrp = kmem_zalloc(sizeof (*mrp), KM_SLEEP);
25098833SVenu.Iyer@Sun.COM if (is_primary && !(mcip->mci_state_flags & (MCIS_IS_VNIC |
25108833SVenu.Iyer@Sun.COM MCIS_IS_AGGR_PORT))) {
25118275SEric Cheng /*
25128275SEric Cheng * Apply the property cached in the mac_impl_t to the primary
25138833SVenu.Iyer@Sun.COM * mac client. If the mac client is a VNIC or an aggregation
25148833SVenu.Iyer@Sun.COM * port, its property should be set in the mcip when the
25158833SVenu.Iyer@Sun.COM * VNIC/aggr was created.
25168275SEric Cheng */
251711878SVenu.Iyer@Sun.COM mac_get_resources((mac_handle_t)mip, mrp);
251811878SVenu.Iyer@Sun.COM (void) mac_client_set_resources(mch, mrp);
25198275SEric Cheng } else if (mcip->mci_state_flags & MCIS_IS_VNIC) {
252011878SVenu.Iyer@Sun.COM /*
252111878SVenu.Iyer@Sun.COM * This is a primary VLAN client, we don't support
252211878SVenu.Iyer@Sun.COM * specifying rings property for this as it inherits the
252311878SVenu.Iyer@Sun.COM * rings property from its MAC.
252411878SVenu.Iyer@Sun.COM */
252511878SVenu.Iyer@Sun.COM if (is_vnic_primary) {
252611878SVenu.Iyer@Sun.COM mac_resource_props_t *vmrp;
252711878SVenu.Iyer@Sun.COM
252811878SVenu.Iyer@Sun.COM vmrp = MCIP_RESOURCE_PROPS(mcip);
252911878SVenu.Iyer@Sun.COM if (vmrp->mrp_mask & MRP_RX_RINGS ||
253011878SVenu.Iyer@Sun.COM vmrp->mrp_mask & MRP_TX_RINGS) {
253111878SVenu.Iyer@Sun.COM if (fastpath_disabled)
253211878SVenu.Iyer@Sun.COM mac_fastpath_enable((mac_handle_t)mip);
253311878SVenu.Iyer@Sun.COM kmem_free(mrp, sizeof (*mrp));
253411878SVenu.Iyer@Sun.COM return (ENOTSUP);
253511878SVenu.Iyer@Sun.COM }
253611878SVenu.Iyer@Sun.COM /*
253711878SVenu.Iyer@Sun.COM * Additionally we also need to inherit any
253811878SVenu.Iyer@Sun.COM * rings property from the MAC.
253911878SVenu.Iyer@Sun.COM */
254011878SVenu.Iyer@Sun.COM mac_get_resources((mac_handle_t)mip, mrp);
254111878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RX_RINGS) {
254211878SVenu.Iyer@Sun.COM vmrp->mrp_mask |= MRP_RX_RINGS;
254311878SVenu.Iyer@Sun.COM vmrp->mrp_nrxrings = mrp->mrp_nrxrings;
254411878SVenu.Iyer@Sun.COM }
254511878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_TX_RINGS) {
254611878SVenu.Iyer@Sun.COM vmrp->mrp_mask |= MRP_TX_RINGS;
254711878SVenu.Iyer@Sun.COM vmrp->mrp_ntxrings = mrp->mrp_ntxrings;
254811878SVenu.Iyer@Sun.COM }
254911878SVenu.Iyer@Sun.COM }
255011878SVenu.Iyer@Sun.COM bcopy(MCIP_RESOURCE_PROPS(mcip), mrp, sizeof (*mrp));
25518275SEric Cheng }
25528275SEric Cheng
25538275SEric Cheng muip = kmem_zalloc(sizeof (mac_unicast_impl_t), KM_SLEEP);
25548275SEric Cheng muip->mui_vid = vid;
25558275SEric Cheng
25568275SEric Cheng if (is_primary || is_vnic_primary) {
25578275SEric Cheng mac_addr = mip->mi_addr;
25588275SEric Cheng } else {
25598275SEric Cheng
25608275SEric Cheng /*
25618275SEric Cheng * Verify the validity of the specified MAC addresses value.
25628275SEric Cheng */
25638275SEric Cheng if (!mac_unicst_verify((mac_handle_t)mip, mac_addr, mac_len)) {
25648275SEric Cheng *diag = MAC_DIAG_MACADDR_INVALID;
25658275SEric Cheng err = EINVAL;
25669473SVenu.Iyer@Sun.COM goto bail_out;
25678275SEric Cheng }
25688275SEric Cheng
25698275SEric Cheng /*
25708275SEric Cheng * Make sure that the specified MAC address is different
25718275SEric Cheng * than the unicast MAC address of the underlying NIC.
25728275SEric Cheng */
25738275SEric Cheng if (check_dups && bcmp(mip->mi_addr, mac_addr, mac_len) == 0) {
25748275SEric Cheng *diag = MAC_DIAG_MACADDR_NIC;
25758275SEric Cheng err = EINVAL;
25769473SVenu.Iyer@Sun.COM goto bail_out;
25778275SEric Cheng }
25788275SEric Cheng }
25798275SEric Cheng
25808275SEric Cheng /*
25819473SVenu.Iyer@Sun.COM * Set the flags here so that if this is a passive client, we
25829473SVenu.Iyer@Sun.COM * can return and set it when we call mac_client_datapath_setup
25839473SVenu.Iyer@Sun.COM * when this becomes the active client. If we defer to using these
25849473SVenu.Iyer@Sun.COM * flags to mac_client_datapath_setup, then for a passive client,
25859473SVenu.Iyer@Sun.COM * we'd have to store the flags somewhere (probably fe_flags)
25869473SVenu.Iyer@Sun.COM * and then use it.
25878275SEric Cheng */
25888275SEric Cheng if (!MCIP_DATAPATH_SETUP(mcip)) {
25898400SNicolas.Droux@Sun.COM if (is_unicast_hw) {
25908400SNicolas.Droux@Sun.COM /*
25918400SNicolas.Droux@Sun.COM * The client requires a hardware MAC address slot
25928400SNicolas.Droux@Sun.COM * for that unicast address. Since we support only
25938400SNicolas.Droux@Sun.COM * one unicast MAC address per client, flag the
25948400SNicolas.Droux@Sun.COM * MAC client itself.
25958400SNicolas.Droux@Sun.COM */
25968400SNicolas.Droux@Sun.COM mcip->mci_state_flags |= MCIS_UNICAST_HW;
25978400SNicolas.Droux@Sun.COM }
25988275SEric Cheng
25999024SVenu.Iyer@Sun.COM /* Check for VLAN flags, if present */
26009024SVenu.Iyer@Sun.COM if ((flags & MAC_UNICAST_TAG_DISABLE) != 0)
26019024SVenu.Iyer@Sun.COM mcip->mci_state_flags |= MCIS_TAG_DISABLE;
26029024SVenu.Iyer@Sun.COM
26039024SVenu.Iyer@Sun.COM if ((flags & MAC_UNICAST_STRIP_DISABLE) != 0)
26049024SVenu.Iyer@Sun.COM mcip->mci_state_flags |= MCIS_STRIP_DISABLE;
26059024SVenu.Iyer@Sun.COM
26069024SVenu.Iyer@Sun.COM if ((flags & MAC_UNICAST_DISABLE_TX_VID_CHECK) != 0)
26079024SVenu.Iyer@Sun.COM mcip->mci_state_flags |= MCIS_DISABLE_TX_VID_CHECK;
26088275SEric Cheng } else {
26099024SVenu.Iyer@Sun.COM /*
26109024SVenu.Iyer@Sun.COM * Assert that the specified flags are consistent with the
26119024SVenu.Iyer@Sun.COM * flags specified by previous calls to mac_unicast_add().
26129024SVenu.Iyer@Sun.COM */
26139024SVenu.Iyer@Sun.COM ASSERT(((flags & MAC_UNICAST_TAG_DISABLE) != 0 &&
26149024SVenu.Iyer@Sun.COM (mcip->mci_state_flags & MCIS_TAG_DISABLE) != 0) ||
26159024SVenu.Iyer@Sun.COM ((flags & MAC_UNICAST_TAG_DISABLE) == 0 &&
26169024SVenu.Iyer@Sun.COM (mcip->mci_state_flags & MCIS_TAG_DISABLE) == 0));
26179024SVenu.Iyer@Sun.COM
26189024SVenu.Iyer@Sun.COM ASSERT(((flags & MAC_UNICAST_STRIP_DISABLE) != 0 &&
26199024SVenu.Iyer@Sun.COM (mcip->mci_state_flags & MCIS_STRIP_DISABLE) != 0) ||
26209024SVenu.Iyer@Sun.COM ((flags & MAC_UNICAST_STRIP_DISABLE) == 0 &&
26219024SVenu.Iyer@Sun.COM (mcip->mci_state_flags & MCIS_STRIP_DISABLE) == 0));
26229024SVenu.Iyer@Sun.COM
26239024SVenu.Iyer@Sun.COM ASSERT(((flags & MAC_UNICAST_DISABLE_TX_VID_CHECK) != 0 &&
26249024SVenu.Iyer@Sun.COM (mcip->mci_state_flags & MCIS_DISABLE_TX_VID_CHECK) != 0) ||
26259024SVenu.Iyer@Sun.COM ((flags & MAC_UNICAST_DISABLE_TX_VID_CHECK) == 0 &&
26269024SVenu.Iyer@Sun.COM (mcip->mci_state_flags & MCIS_DISABLE_TX_VID_CHECK) == 0));
26279024SVenu.Iyer@Sun.COM
26288400SNicolas.Droux@Sun.COM /*
26298400SNicolas.Droux@Sun.COM * Make sure the client is consistent about its requests
26308400SNicolas.Droux@Sun.COM * for MAC addresses. I.e. all requests from the clients
26318400SNicolas.Droux@Sun.COM * must have the MAC_UNICAST_HW flag set or clear.
26328400SNicolas.Droux@Sun.COM */
26338400SNicolas.Droux@Sun.COM if ((mcip->mci_state_flags & MCIS_UNICAST_HW) != 0 &&
26348400SNicolas.Droux@Sun.COM !is_unicast_hw ||
26358400SNicolas.Droux@Sun.COM (mcip->mci_state_flags & MCIS_UNICAST_HW) == 0 &&
26368400SNicolas.Droux@Sun.COM is_unicast_hw) {
26378400SNicolas.Droux@Sun.COM err = EINVAL;
26389473SVenu.Iyer@Sun.COM goto bail_out;
26398275SEric Cheng }
26408275SEric Cheng }
26418275SEric Cheng /*
26429473SVenu.Iyer@Sun.COM * Make sure the MAC address is not already used by
26439473SVenu.Iyer@Sun.COM * another MAC client defined on top of the same
26449473SVenu.Iyer@Sun.COM * underlying NIC. Unless we have MAC_CLIENT_FLAGS_MULTI_PRIMARY
26459473SVenu.Iyer@Sun.COM * set when we allow a passive client to be present which will
26469473SVenu.Iyer@Sun.COM * be activated when the currently active client goes away - this
26479473SVenu.Iyer@Sun.COM * works only with primary addresses.
26488275SEric Cheng */
26499473SVenu.Iyer@Sun.COM if ((check_dups || is_primary || is_vnic_primary) &&
26509473SVenu.Iyer@Sun.COM mac_addr_in_use(mip, mac_addr, vid)) {
26519473SVenu.Iyer@Sun.COM /*
26529473SVenu.Iyer@Sun.COM * Must have set the multiple primary address flag when
26539473SVenu.Iyer@Sun.COM * we did a mac_client_open AND this should be a primary
26549473SVenu.Iyer@Sun.COM * MAC client AND there should not already be a passive
26559473SVenu.Iyer@Sun.COM * primary. If all is true then we let this succeed
26569473SVenu.Iyer@Sun.COM * even if the address is a dup.
26579473SVenu.Iyer@Sun.COM */
26589473SVenu.Iyer@Sun.COM if ((mcip->mci_flags & MAC_CLIENT_FLAGS_MULTI_PRIMARY) == 0 ||
26599473SVenu.Iyer@Sun.COM (mcip->mci_flags & MAC_CLIENT_FLAGS_PRIMARY) == 0 ||
26609473SVenu.Iyer@Sun.COM mac_get_passive_primary_client(mip) != NULL) {
26619473SVenu.Iyer@Sun.COM *diag = MAC_DIAG_MACADDR_INUSE;
26629473SVenu.Iyer@Sun.COM err = EEXIST;
26639473SVenu.Iyer@Sun.COM goto bail_out;
26649473SVenu.Iyer@Sun.COM }
26659473SVenu.Iyer@Sun.COM ASSERT((mcip->mci_flags &
26669473SVenu.Iyer@Sun.COM MAC_CLIENT_FLAGS_PASSIVE_PRIMARY) == 0);
26679473SVenu.Iyer@Sun.COM mcip->mci_flags |= MAC_CLIENT_FLAGS_PASSIVE_PRIMARY;
266811878SVenu.Iyer@Sun.COM kmem_free(mrp, sizeof (*mrp));
26699473SVenu.Iyer@Sun.COM
26709473SVenu.Iyer@Sun.COM /*
26719473SVenu.Iyer@Sun.COM * Stash the unicast address handle, we will use it when
26729473SVenu.Iyer@Sun.COM * we set up the passive client.
26739473SVenu.Iyer@Sun.COM */
26749473SVenu.Iyer@Sun.COM mcip->mci_p_unicast_list = muip;
26759473SVenu.Iyer@Sun.COM *mah = (mac_unicast_handle_t)muip;
26769473SVenu.Iyer@Sun.COM return (0);
26779473SVenu.Iyer@Sun.COM }
26789473SVenu.Iyer@Sun.COM
267911878SVenu.Iyer@Sun.COM err = mac_client_datapath_setup(mcip, vid, mac_addr, mrp,
26809473SVenu.Iyer@Sun.COM is_primary || is_vnic_primary, muip);
26819473SVenu.Iyer@Sun.COM if (err != 0)
26829473SVenu.Iyer@Sun.COM goto bail_out;
268311878SVenu.Iyer@Sun.COM
268411878SVenu.Iyer@Sun.COM kmem_free(mrp, sizeof (*mrp));
26859473SVenu.Iyer@Sun.COM *mah = (mac_unicast_handle_t)muip;
26868275SEric Cheng return (0);
26879473SVenu.Iyer@Sun.COM
26889473SVenu.Iyer@Sun.COM bail_out:
26899473SVenu.Iyer@Sun.COM if (fastpath_disabled)
26909473SVenu.Iyer@Sun.COM mac_fastpath_enable((mac_handle_t)mip);
26919073SCathy.Zhou@Sun.COM if (mcip->mci_state_flags & MCIS_EXCLUSIVE) {
26928275SEric Cheng mip->mi_state_flags &= ~MIS_EXCLUSIVE;
26939473SVenu.Iyer@Sun.COM if (mip->mi_state_flags & MIS_LEGACY) {
26949473SVenu.Iyer@Sun.COM mip->mi_capab_legacy.ml_active_clear(
26959473SVenu.Iyer@Sun.COM mip->mi_driver);
26969473SVenu.Iyer@Sun.COM }
26979073SCathy.Zhou@Sun.COM }
269811878SVenu.Iyer@Sun.COM kmem_free(mrp, sizeof (*mrp));
26998275SEric Cheng kmem_free(muip, sizeof (mac_unicast_impl_t));
27008275SEric Cheng return (err);
27018275SEric Cheng }
27028275SEric Cheng
27039473SVenu.Iyer@Sun.COM /*
27049473SVenu.Iyer@Sun.COM * Wrapper function to mac_unicast_add when we want to have the same mac
27059473SVenu.Iyer@Sun.COM * client open for two instances, one that is currently active and another
27069473SVenu.Iyer@Sun.COM * that will become active when the current one is removed. In this case
27079473SVenu.Iyer@Sun.COM * mac_unicast_add will return EGAIN and we will save the rx function and
27089473SVenu.Iyer@Sun.COM * arg which will be used when we activate the passive client in
27099473SVenu.Iyer@Sun.COM * mac_unicast_remove.
27109473SVenu.Iyer@Sun.COM */
27119473SVenu.Iyer@Sun.COM int
mac_unicast_add_set_rx(mac_client_handle_t mch,uint8_t * mac_addr,uint16_t flags,mac_unicast_handle_t * mah,uint16_t vid,mac_diag_t * diag,mac_rx_t rx_fn,void * arg)27129473SVenu.Iyer@Sun.COM mac_unicast_add_set_rx(mac_client_handle_t mch, uint8_t *mac_addr,
27139473SVenu.Iyer@Sun.COM uint16_t flags, mac_unicast_handle_t *mah, uint16_t vid, mac_diag_t *diag,
27149473SVenu.Iyer@Sun.COM mac_rx_t rx_fn, void *arg)
27159473SVenu.Iyer@Sun.COM {
27169473SVenu.Iyer@Sun.COM mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
27179473SVenu.Iyer@Sun.COM uint_t err;
27189473SVenu.Iyer@Sun.COM
27199473SVenu.Iyer@Sun.COM err = mac_unicast_add(mch, mac_addr, flags, mah, vid, diag);
27209473SVenu.Iyer@Sun.COM if (err != 0 && err != EAGAIN)
27219473SVenu.Iyer@Sun.COM return (err);
27229473SVenu.Iyer@Sun.COM if (err == EAGAIN) {
27239473SVenu.Iyer@Sun.COM if (rx_fn != NULL) {
27249473SVenu.Iyer@Sun.COM mcip->mci_rx_p_fn = rx_fn;
27259473SVenu.Iyer@Sun.COM mcip->mci_rx_p_arg = arg;
27269473SVenu.Iyer@Sun.COM }
27279473SVenu.Iyer@Sun.COM return (0);
27289473SVenu.Iyer@Sun.COM }
27299473SVenu.Iyer@Sun.COM if (rx_fn != NULL)
27309473SVenu.Iyer@Sun.COM mac_rx_set(mch, rx_fn, arg);
27319473SVenu.Iyer@Sun.COM return (err);
27329473SVenu.Iyer@Sun.COM }
27339473SVenu.Iyer@Sun.COM
27348275SEric Cheng int
mac_unicast_add(mac_client_handle_t mch,uint8_t * mac_addr,uint16_t flags,mac_unicast_handle_t * mah,uint16_t vid,mac_diag_t * diag)27358275SEric Cheng mac_unicast_add(mac_client_handle_t mch, uint8_t *mac_addr, uint16_t flags,
27368275SEric Cheng mac_unicast_handle_t *mah, uint16_t vid, mac_diag_t *diag)
27378275SEric Cheng {
27388275SEric Cheng mac_impl_t *mip = ((mac_client_impl_t *)mch)->mci_mip;
27398275SEric Cheng uint_t err;
27408275SEric Cheng
27418275SEric Cheng i_mac_perim_enter(mip);
27428275SEric Cheng err = i_mac_unicast_add(mch, mac_addr, flags, mah, vid, diag);
27438275SEric Cheng i_mac_perim_exit(mip);
27448275SEric Cheng
27458275SEric Cheng return (err);
27468275SEric Cheng }
27478275SEric Cheng
274811878SVenu.Iyer@Sun.COM static void
mac_client_datapath_teardown(mac_client_handle_t mch,mac_unicast_impl_t * muip,flow_entry_t * flent)27499473SVenu.Iyer@Sun.COM mac_client_datapath_teardown(mac_client_handle_t mch, mac_unicast_impl_t *muip,
27509473SVenu.Iyer@Sun.COM flow_entry_t *flent)
27518275SEric Cheng {
27529473SVenu.Iyer@Sun.COM mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
27539473SVenu.Iyer@Sun.COM mac_impl_t *mip = mcip->mci_mip;
275411878SVenu.Iyer@Sun.COM boolean_t no_unicast;
27558275SEric Cheng
27568833SVenu.Iyer@Sun.COM /*
275711878SVenu.Iyer@Sun.COM * If we have not added a unicast address for this MAC client, just
275811878SVenu.Iyer@Sun.COM * teardown the datapath.
27598833SVenu.Iyer@Sun.COM */
276011878SVenu.Iyer@Sun.COM no_unicast = mcip->mci_state_flags & MCIS_NO_UNICAST_ADDR;
276111878SVenu.Iyer@Sun.COM
276211878SVenu.Iyer@Sun.COM if (!no_unicast) {
276311878SVenu.Iyer@Sun.COM /*
276411878SVenu.Iyer@Sun.COM * We would have initialized subflows etc. only if we brought
276511878SVenu.Iyer@Sun.COM * up the primary client and set the unicast unicast address
276611878SVenu.Iyer@Sun.COM * etc. Deactivate the flows. The flow entry will be removed
276711878SVenu.Iyer@Sun.COM * from the active flow tables, and the associated SRS,
276811878SVenu.Iyer@Sun.COM * softrings etc will be deleted. But the flow entry itself
276911878SVenu.Iyer@Sun.COM * won't be destroyed, instead it will continue to be archived
277011878SVenu.Iyer@Sun.COM * off the the global flow hash list, for a possible future
277111878SVenu.Iyer@Sun.COM * activation when say IP is plumbed again.
277211878SVenu.Iyer@Sun.COM */
277311878SVenu.Iyer@Sun.COM mac_link_release_flows(mch);
277411878SVenu.Iyer@Sun.COM }
27758275SEric Cheng mip->mi_nactiveclients--;
27768833SVenu.Iyer@Sun.COM mac_update_single_active_client(mip);
27778275SEric Cheng
27789473SVenu.Iyer@Sun.COM /* Tear down the data path */
27798275SEric Cheng mac_datapath_teardown(mcip, mcip->mci_flent, SRST_LINK);
27808275SEric Cheng
27818275SEric Cheng /*
27828275SEric Cheng * Prevent any future access to the flow entry through the mci_flent
27838275SEric Cheng * pointer by setting the mci_flent to NULL. Access to mci_flent in
27848275SEric Cheng * mac_bcast_send is also under mi_rw_lock.
27858275SEric Cheng */
27868275SEric Cheng rw_enter(&mip->mi_rw_lock, RW_WRITER);
27878275SEric Cheng flent = mcip->mci_flent;
27888275SEric Cheng mac_client_remove_flow_from_list(mcip, flent);
27898275SEric Cheng
27908275SEric Cheng if (mcip->mci_state_flags & MCIS_DESC_LOGGED)
27918275SEric Cheng mcip->mci_state_flags &= ~MCIS_DESC_LOGGED;
27928275SEric Cheng
27938275SEric Cheng /*
27948275SEric Cheng * This is the last unicast address being removed and there shouldn't
27958275SEric Cheng * be any outbound data threads at this point coming down from mac
27968275SEric Cheng * clients. We have waited for the data threads to finish before
27978275SEric Cheng * starting dld_str_detach. Non-data threads must access TX SRS
27988275SEric Cheng * under mi_rw_lock.
27998275SEric Cheng */
28008275SEric Cheng rw_exit(&mip->mi_rw_lock);
28018275SEric Cheng
28028275SEric Cheng /*
28038275SEric Cheng * Don't use FLOW_MARK with FE_MC_NO_DATAPATH, as the flow might
28048275SEric Cheng * contain other flags, such as FE_CONDEMNED, which we need to
28058275SEric Cheng * cleared. We don't call mac_flow_cleanup() for this unicast
28068275SEric Cheng * flow as we have a already cleaned up SRSs etc. (via the teadown
28078275SEric Cheng * path). We just clear the stats and reset the initial callback
28088275SEric Cheng * function, the rest will be set when we call mac_flow_create,
28098275SEric Cheng * if at all.
28108275SEric Cheng */
28118275SEric Cheng mutex_enter(&flent->fe_lock);
28128275SEric Cheng ASSERT(flent->fe_refcnt == 1 && flent->fe_mbg == NULL &&
28138275SEric Cheng flent->fe_tx_srs == NULL && flent->fe_rx_srs_cnt == 0);
28148275SEric Cheng flent->fe_flags = FE_MC_NO_DATAPATH;
28158275SEric Cheng flow_stat_destroy(flent);
281611878SVenu.Iyer@Sun.COM mac_misc_stat_delete(flent);
28178275SEric Cheng
28188275SEric Cheng /* Initialize the receiver function to a safe routine */
28198275SEric Cheng flent->fe_cb_fn = (flow_fn_t)mac_pkt_drop;
28208275SEric Cheng flent->fe_cb_arg1 = NULL;
28218275SEric Cheng flent->fe_cb_arg2 = NULL;
28228275SEric Cheng
28238275SEric Cheng flent->fe_index = -1;
28248275SEric Cheng mutex_exit(&flent->fe_lock);
28258275SEric Cheng
28268275SEric Cheng if (mip->mi_type->mt_brdcst_addr != NULL) {
282711878SVenu.Iyer@Sun.COM ASSERT(muip != NULL || no_unicast);
28288275SEric Cheng mac_bcast_delete(mcip, mip->mi_type->mt_brdcst_addr,
282911878SVenu.Iyer@Sun.COM muip != NULL ? muip->mui_vid : VLAN_ID_NONE);
28308275SEric Cheng }
28318275SEric Cheng
28328275SEric Cheng if (mip->mi_nactiveclients == 1) {
28338275SEric Cheng mac_capab_update((mac_handle_t)mip);
28348275SEric Cheng mac_virtual_link_update(mip);
28358275SEric Cheng }
28369073SCathy.Zhou@Sun.COM
28379073SCathy.Zhou@Sun.COM if (mcip->mci_state_flags & MCIS_EXCLUSIVE) {
28388275SEric Cheng mip->mi_state_flags &= ~MIS_EXCLUSIVE;
28399073SCathy.Zhou@Sun.COM
28409073SCathy.Zhou@Sun.COM if (mip->mi_state_flags & MIS_LEGACY)
28419073SCathy.Zhou@Sun.COM mip->mi_capab_legacy.ml_active_clear(mip->mi_driver);
28429073SCathy.Zhou@Sun.COM }
28439073SCathy.Zhou@Sun.COM
28448400SNicolas.Droux@Sun.COM mcip->mci_state_flags &= ~MCIS_UNICAST_HW;
28458275SEric Cheng
28469024SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_TAG_DISABLE)
28479024SVenu.Iyer@Sun.COM mcip->mci_state_flags &= ~MCIS_TAG_DISABLE;
28489024SVenu.Iyer@Sun.COM
28499024SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_STRIP_DISABLE)
28509024SVenu.Iyer@Sun.COM mcip->mci_state_flags &= ~MCIS_STRIP_DISABLE;
28519024SVenu.Iyer@Sun.COM
28529024SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_DISABLE_TX_VID_CHECK)
28539024SVenu.Iyer@Sun.COM mcip->mci_state_flags &= ~MCIS_DISABLE_TX_VID_CHECK;
28549024SVenu.Iyer@Sun.COM
285511878SVenu.Iyer@Sun.COM if (muip != NULL)
285611878SVenu.Iyer@Sun.COM kmem_free(muip, sizeof (mac_unicast_impl_t));
285711878SVenu.Iyer@Sun.COM mac_protect_cancel_timer(mcip);
285811878SVenu.Iyer@Sun.COM mac_protect_flush_dhcp(mcip);
285911878SVenu.Iyer@Sun.COM
286011878SVenu.Iyer@Sun.COM bzero(&mcip->mci_misc_stat, sizeof (mcip->mci_misc_stat));
28619073SCathy.Zhou@Sun.COM /*
28629073SCathy.Zhou@Sun.COM * Disable fastpath if this is a VNIC or a VLAN.
28639073SCathy.Zhou@Sun.COM */
28649073SCathy.Zhou@Sun.COM if (mcip->mci_state_flags & MCIS_IS_VNIC)
28659073SCathy.Zhou@Sun.COM mac_fastpath_enable((mac_handle_t)mip);
28668893SMichael.Lim@Sun.COM mac_stop((mac_handle_t)mip);
28679473SVenu.Iyer@Sun.COM }
28689473SVenu.Iyer@Sun.COM
28699473SVenu.Iyer@Sun.COM /*
28709473SVenu.Iyer@Sun.COM * Remove a MAC address which was previously added by mac_unicast_add().
28719473SVenu.Iyer@Sun.COM */
28729473SVenu.Iyer@Sun.COM int
mac_unicast_remove(mac_client_handle_t mch,mac_unicast_handle_t mah)28739473SVenu.Iyer@Sun.COM mac_unicast_remove(mac_client_handle_t mch, mac_unicast_handle_t mah)
28749473SVenu.Iyer@Sun.COM {
28759473SVenu.Iyer@Sun.COM mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
28769473SVenu.Iyer@Sun.COM mac_unicast_impl_t *muip = (mac_unicast_impl_t *)mah;
28779473SVenu.Iyer@Sun.COM mac_unicast_impl_t *pre;
28789473SVenu.Iyer@Sun.COM mac_impl_t *mip = mcip->mci_mip;
28799473SVenu.Iyer@Sun.COM flow_entry_t *flent;
288011878SVenu.Iyer@Sun.COM uint16_t mui_vid;
28819473SVenu.Iyer@Sun.COM
28829473SVenu.Iyer@Sun.COM i_mac_perim_enter(mip);
28839473SVenu.Iyer@Sun.COM if (mcip->mci_flags & MAC_CLIENT_FLAGS_VNIC_PRIMARY) {
28849473SVenu.Iyer@Sun.COM /*
28859473SVenu.Iyer@Sun.COM * Called made by the upper MAC client of a VNIC.
28869473SVenu.Iyer@Sun.COM * There's nothing much to do, the unicast address will
28879473SVenu.Iyer@Sun.COM * be removed by the VNIC driver when the VNIC is deleted,
28889473SVenu.Iyer@Sun.COM * but let's ensure that all our transmit is done before
28899473SVenu.Iyer@Sun.COM * the client does a mac_client_stop lest it trigger an
28909473SVenu.Iyer@Sun.COM * assert in the driver.
28919473SVenu.Iyer@Sun.COM */
28929473SVenu.Iyer@Sun.COM ASSERT(muip->mui_vid == 0);
28939473SVenu.Iyer@Sun.COM
28949473SVenu.Iyer@Sun.COM mac_tx_client_flush(mcip);
28959473SVenu.Iyer@Sun.COM
28969473SVenu.Iyer@Sun.COM if ((mcip->mci_flags & MAC_CLIENT_FLAGS_PASSIVE_PRIMARY) != 0) {
28979473SVenu.Iyer@Sun.COM mcip->mci_flags &= ~MAC_CLIENT_FLAGS_PASSIVE_PRIMARY;
28989473SVenu.Iyer@Sun.COM if (mcip->mci_rx_p_fn != NULL) {
28999473SVenu.Iyer@Sun.COM mac_rx_set(mch, mcip->mci_rx_p_fn,
29009473SVenu.Iyer@Sun.COM mcip->mci_rx_p_arg);
29019473SVenu.Iyer@Sun.COM mcip->mci_rx_p_fn = NULL;
29029473SVenu.Iyer@Sun.COM mcip->mci_rx_p_arg = NULL;
29039473SVenu.Iyer@Sun.COM }
29049473SVenu.Iyer@Sun.COM kmem_free(muip, sizeof (mac_unicast_impl_t));
29059473SVenu.Iyer@Sun.COM i_mac_perim_exit(mip);
29069473SVenu.Iyer@Sun.COM return (0);
29079473SVenu.Iyer@Sun.COM }
29089473SVenu.Iyer@Sun.COM mcip->mci_flags &= ~MAC_CLIENT_FLAGS_VNIC_PRIMARY;
29099473SVenu.Iyer@Sun.COM
29109473SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_TAG_DISABLE)
29119473SVenu.Iyer@Sun.COM mcip->mci_state_flags &= ~MCIS_TAG_DISABLE;
29129473SVenu.Iyer@Sun.COM
29139473SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_STRIP_DISABLE)
29149473SVenu.Iyer@Sun.COM mcip->mci_state_flags &= ~MCIS_STRIP_DISABLE;
29159473SVenu.Iyer@Sun.COM
29169473SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_DISABLE_TX_VID_CHECK)
29179473SVenu.Iyer@Sun.COM mcip->mci_state_flags &= ~MCIS_DISABLE_TX_VID_CHECK;
29189473SVenu.Iyer@Sun.COM
29199473SVenu.Iyer@Sun.COM kmem_free(muip, sizeof (mac_unicast_impl_t));
29209473SVenu.Iyer@Sun.COM i_mac_perim_exit(mip);
29219473SVenu.Iyer@Sun.COM return (0);
29229473SVenu.Iyer@Sun.COM }
29239473SVenu.Iyer@Sun.COM
29249473SVenu.Iyer@Sun.COM ASSERT(muip != NULL);
29259473SVenu.Iyer@Sun.COM
29269473SVenu.Iyer@Sun.COM /*
29279473SVenu.Iyer@Sun.COM * We are removing a passive client, we haven't setup the datapath
29289473SVenu.Iyer@Sun.COM * for this yet, so nothing much to do.
29299473SVenu.Iyer@Sun.COM */
29309614SVenu.Iyer@Sun.COM if ((mcip->mci_flags & MAC_CLIENT_FLAGS_PASSIVE_PRIMARY) != 0) {
29319473SVenu.Iyer@Sun.COM
29329473SVenu.Iyer@Sun.COM ASSERT((mcip->mci_flent->fe_flags & FE_MC_NO_DATAPATH) != 0);
29339473SVenu.Iyer@Sun.COM ASSERT(mcip->mci_p_unicast_list == muip);
29349473SVenu.Iyer@Sun.COM
29359614SVenu.Iyer@Sun.COM mcip->mci_flags &= ~MAC_CLIENT_FLAGS_PASSIVE_PRIMARY;
29369614SVenu.Iyer@Sun.COM
29379473SVenu.Iyer@Sun.COM mcip->mci_p_unicast_list = NULL;
29389473SVenu.Iyer@Sun.COM mcip->mci_rx_p_fn = NULL;
29399473SVenu.Iyer@Sun.COM mcip->mci_rx_p_arg = NULL;
29409473SVenu.Iyer@Sun.COM
29419473SVenu.Iyer@Sun.COM mcip->mci_state_flags &= ~MCIS_UNICAST_HW;
29429473SVenu.Iyer@Sun.COM
29439473SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_TAG_DISABLE)
29449473SVenu.Iyer@Sun.COM mcip->mci_state_flags &= ~MCIS_TAG_DISABLE;
29459473SVenu.Iyer@Sun.COM
29469473SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_STRIP_DISABLE)
29479473SVenu.Iyer@Sun.COM mcip->mci_state_flags &= ~MCIS_STRIP_DISABLE;
29489473SVenu.Iyer@Sun.COM
29499473SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_DISABLE_TX_VID_CHECK)
29509473SVenu.Iyer@Sun.COM mcip->mci_state_flags &= ~MCIS_DISABLE_TX_VID_CHECK;
29519473SVenu.Iyer@Sun.COM
29529473SVenu.Iyer@Sun.COM kmem_free(muip, sizeof (mac_unicast_impl_t));
29539473SVenu.Iyer@Sun.COM i_mac_perim_exit(mip);
29549473SVenu.Iyer@Sun.COM return (0);
29559473SVenu.Iyer@Sun.COM }
29569473SVenu.Iyer@Sun.COM /*
29579473SVenu.Iyer@Sun.COM * Remove the VID from the list of client's VIDs.
29589473SVenu.Iyer@Sun.COM */
29599473SVenu.Iyer@Sun.COM pre = mcip->mci_unicast_list;
29609473SVenu.Iyer@Sun.COM if (muip == pre) {
29619473SVenu.Iyer@Sun.COM mcip->mci_unicast_list = muip->mui_next;
29629473SVenu.Iyer@Sun.COM } else {
29639473SVenu.Iyer@Sun.COM while ((pre->mui_next != NULL) && (pre->mui_next != muip))
29649473SVenu.Iyer@Sun.COM pre = pre->mui_next;
29659473SVenu.Iyer@Sun.COM ASSERT(pre->mui_next == muip);
29669473SVenu.Iyer@Sun.COM rw_enter(&mcip->mci_rw_lock, RW_WRITER);
29679473SVenu.Iyer@Sun.COM pre->mui_next = muip->mui_next;
29689473SVenu.Iyer@Sun.COM rw_exit(&mcip->mci_rw_lock);
29699473SVenu.Iyer@Sun.COM }
29709473SVenu.Iyer@Sun.COM
29719473SVenu.Iyer@Sun.COM if (!mac_client_single_rcvr(mcip)) {
29729473SVenu.Iyer@Sun.COM /*
29739473SVenu.Iyer@Sun.COM * This MAC client is shared by more than one unicast
29749473SVenu.Iyer@Sun.COM * addresses, so we will just remove the flent
29759473SVenu.Iyer@Sun.COM * corresponding to the address being removed. We don't invoke
29769473SVenu.Iyer@Sun.COM * mac_rx_classify_flow_rem() since the additional flow is
29779473SVenu.Iyer@Sun.COM * not associated with its own separate set of SRS and rings,
29789473SVenu.Iyer@Sun.COM * and these constructs are still needed for the remaining
29799473SVenu.Iyer@Sun.COM * flows.
29809473SVenu.Iyer@Sun.COM */
29819473SVenu.Iyer@Sun.COM flent = mac_client_get_flow(mcip, muip);
29829473SVenu.Iyer@Sun.COM ASSERT(flent != NULL);
29839473SVenu.Iyer@Sun.COM
29849473SVenu.Iyer@Sun.COM /*
29859473SVenu.Iyer@Sun.COM * The first one is disappearing, need to make sure
29869473SVenu.Iyer@Sun.COM * we replace it with another from the list of
29879473SVenu.Iyer@Sun.COM * shared clients.
29889473SVenu.Iyer@Sun.COM */
29899473SVenu.Iyer@Sun.COM if (flent == mcip->mci_flent)
29909473SVenu.Iyer@Sun.COM flent = mac_client_swap_mciflent(mcip);
29919473SVenu.Iyer@Sun.COM mac_client_remove_flow_from_list(mcip, flent);
29929473SVenu.Iyer@Sun.COM mac_flow_remove(mip->mi_flow_tab, flent, B_FALSE);
29939473SVenu.Iyer@Sun.COM mac_flow_wait(flent, FLOW_DRIVER_UPCALL);
29949473SVenu.Iyer@Sun.COM
29959473SVenu.Iyer@Sun.COM /*
29969473SVenu.Iyer@Sun.COM * The multicast groups that were added by the client so
29979473SVenu.Iyer@Sun.COM * far must be removed from the brodcast domain corresponding
29989473SVenu.Iyer@Sun.COM * to the VID being removed.
29999473SVenu.Iyer@Sun.COM */
30009473SVenu.Iyer@Sun.COM mac_client_bcast_refresh(mcip, mac_client_update_mcast,
30019473SVenu.Iyer@Sun.COM (void *)flent, B_FALSE);
30029473SVenu.Iyer@Sun.COM
30039473SVenu.Iyer@Sun.COM if (mip->mi_type->mt_brdcst_addr != NULL) {
30049473SVenu.Iyer@Sun.COM mac_bcast_delete(mcip, mip->mi_type->mt_brdcst_addr,
30059473SVenu.Iyer@Sun.COM muip->mui_vid);
30069473SVenu.Iyer@Sun.COM }
30079473SVenu.Iyer@Sun.COM
30089473SVenu.Iyer@Sun.COM FLOW_FINAL_REFRELE(flent);
30099473SVenu.Iyer@Sun.COM ASSERT(!(mcip->mci_state_flags & MCIS_EXCLUSIVE));
30109473SVenu.Iyer@Sun.COM /*
30119473SVenu.Iyer@Sun.COM * Enable fastpath if this is a VNIC or a VLAN.
30129473SVenu.Iyer@Sun.COM */
30139473SVenu.Iyer@Sun.COM if (mcip->mci_state_flags & MCIS_IS_VNIC)
30149473SVenu.Iyer@Sun.COM mac_fastpath_enable((mac_handle_t)mip);
30159473SVenu.Iyer@Sun.COM mac_stop((mac_handle_t)mip);
30169473SVenu.Iyer@Sun.COM i_mac_perim_exit(mip);
30179473SVenu.Iyer@Sun.COM return (0);
30189473SVenu.Iyer@Sun.COM }
30199473SVenu.Iyer@Sun.COM
302011878SVenu.Iyer@Sun.COM mui_vid = muip->mui_vid;
30219473SVenu.Iyer@Sun.COM mac_client_datapath_teardown(mch, muip, flent);
30229473SVenu.Iyer@Sun.COM
302311878SVenu.Iyer@Sun.COM if ((mcip->mci_flags & MAC_CLIENT_FLAGS_PRIMARY) && mui_vid == 0) {
302411878SVenu.Iyer@Sun.COM mcip->mci_flags &= ~MAC_CLIENT_FLAGS_PRIMARY;
302511878SVenu.Iyer@Sun.COM } else {
302611878SVenu.Iyer@Sun.COM i_mac_perim_exit(mip);
302711878SVenu.Iyer@Sun.COM return (0);
302811878SVenu.Iyer@Sun.COM }
302911878SVenu.Iyer@Sun.COM
30309473SVenu.Iyer@Sun.COM /*
30319473SVenu.Iyer@Sun.COM * If we are removing the primary, check if we have a passive primary
30329473SVenu.Iyer@Sun.COM * client that we need to activate now.
30339473SVenu.Iyer@Sun.COM */
30349473SVenu.Iyer@Sun.COM mcip = mac_get_passive_primary_client(mip);
30359473SVenu.Iyer@Sun.COM if (mcip != NULL) {
303611878SVenu.Iyer@Sun.COM mac_resource_props_t *mrp;
30379473SVenu.Iyer@Sun.COM mac_unicast_impl_t *muip;
30389473SVenu.Iyer@Sun.COM
30399473SVenu.Iyer@Sun.COM mcip->mci_flags &= ~MAC_CLIENT_FLAGS_PASSIVE_PRIMARY;
304011878SVenu.Iyer@Sun.COM mrp = kmem_zalloc(sizeof (*mrp), KM_SLEEP);
304111878SVenu.Iyer@Sun.COM
30429473SVenu.Iyer@Sun.COM /*
30439473SVenu.Iyer@Sun.COM * Apply the property cached in the mac_impl_t to the
30449473SVenu.Iyer@Sun.COM * primary mac client.
30459473SVenu.Iyer@Sun.COM */
304611878SVenu.Iyer@Sun.COM mac_get_resources((mac_handle_t)mip, mrp);
304711878SVenu.Iyer@Sun.COM (void) mac_client_set_resources(mch, mrp);
30489473SVenu.Iyer@Sun.COM ASSERT(mcip->mci_p_unicast_list != NULL);
30499473SVenu.Iyer@Sun.COM muip = mcip->mci_p_unicast_list;
30509473SVenu.Iyer@Sun.COM mcip->mci_p_unicast_list = NULL;
30519473SVenu.Iyer@Sun.COM if (mac_client_datapath_setup(mcip, VLAN_ID_NONE,
305211878SVenu.Iyer@Sun.COM mip->mi_addr, mrp, B_TRUE, muip) == 0) {
30539473SVenu.Iyer@Sun.COM if (mcip->mci_rx_p_fn != NULL) {
30549473SVenu.Iyer@Sun.COM mac_rx_set(mch, mcip->mci_rx_p_fn,
30559473SVenu.Iyer@Sun.COM mcip->mci_rx_p_arg);
30569473SVenu.Iyer@Sun.COM mcip->mci_rx_p_fn = NULL;
30579473SVenu.Iyer@Sun.COM mcip->mci_rx_p_arg = NULL;
30589473SVenu.Iyer@Sun.COM }
30599822SVenu.Iyer@Sun.COM } else {
30609822SVenu.Iyer@Sun.COM kmem_free(muip, sizeof (mac_unicast_impl_t));
30619473SVenu.Iyer@Sun.COM }
306211878SVenu.Iyer@Sun.COM kmem_free(mrp, sizeof (*mrp));
30639473SVenu.Iyer@Sun.COM }
30648275SEric Cheng i_mac_perim_exit(mip);
30658275SEric Cheng return (0);
30668275SEric Cheng }
30678275SEric Cheng
30688275SEric Cheng /*
30698275SEric Cheng * Multicast add function invoked by MAC clients.
30708275SEric Cheng */
30718275SEric Cheng int
mac_multicast_add(mac_client_handle_t mch,const uint8_t * addr)30728275SEric Cheng mac_multicast_add(mac_client_handle_t mch, const uint8_t *addr)
30738275SEric Cheng {
30748275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
30758275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
30768275SEric Cheng flow_entry_t *flent = mcip->mci_flent_list;
30778275SEric Cheng flow_entry_t *prev_fe = NULL;
30788275SEric Cheng uint16_t vid;
30798275SEric Cheng int err = 0;
30808275SEric Cheng
30818275SEric Cheng /* Verify the address is a valid multicast address */
30828275SEric Cheng if ((err = mip->mi_type->mt_ops.mtops_multicst_verify(addr,
30838275SEric Cheng mip->mi_pdata)) != 0)
30848275SEric Cheng return (err);
30858275SEric Cheng
30868275SEric Cheng i_mac_perim_enter(mip);
30878275SEric Cheng while (flent != NULL) {
30888275SEric Cheng vid = i_mac_flow_vid(flent);
30898275SEric Cheng
30908275SEric Cheng err = mac_bcast_add((mac_client_impl_t *)mch, addr, vid,
30918275SEric Cheng MAC_ADDRTYPE_MULTICAST);
30928275SEric Cheng if (err != 0)
30938275SEric Cheng break;
30948275SEric Cheng prev_fe = flent;
30958275SEric Cheng flent = flent->fe_client_next;
30968275SEric Cheng }
30978275SEric Cheng
30988275SEric Cheng /*
30998275SEric Cheng * If we failed adding, then undo all, rather than partial
31008275SEric Cheng * success.
31018275SEric Cheng */
31028275SEric Cheng if (flent != NULL && prev_fe != NULL) {
31038275SEric Cheng flent = mcip->mci_flent_list;
31048275SEric Cheng while (flent != prev_fe->fe_client_next) {
31058275SEric Cheng vid = i_mac_flow_vid(flent);
31068275SEric Cheng mac_bcast_delete((mac_client_impl_t *)mch, addr, vid);
31078275SEric Cheng flent = flent->fe_client_next;
31088275SEric Cheng }
31098275SEric Cheng }
31108275SEric Cheng i_mac_perim_exit(mip);
31118275SEric Cheng return (err);
31128275SEric Cheng }
31138275SEric Cheng
31148275SEric Cheng /*
31158275SEric Cheng * Multicast delete function invoked by MAC clients.
31168275SEric Cheng */
31178275SEric Cheng void
mac_multicast_remove(mac_client_handle_t mch,const uint8_t * addr)31188275SEric Cheng mac_multicast_remove(mac_client_handle_t mch, const uint8_t *addr)
31198275SEric Cheng {
31208275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
31218275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
31228275SEric Cheng flow_entry_t *flent;
31238275SEric Cheng uint16_t vid;
31248275SEric Cheng
31258275SEric Cheng i_mac_perim_enter(mip);
31268275SEric Cheng for (flent = mcip->mci_flent_list; flent != NULL;
31278275SEric Cheng flent = flent->fe_client_next) {
31288275SEric Cheng vid = i_mac_flow_vid(flent);
31298275SEric Cheng mac_bcast_delete((mac_client_impl_t *)mch, addr, vid);
31308275SEric Cheng }
31318275SEric Cheng i_mac_perim_exit(mip);
31328275SEric Cheng }
31338275SEric Cheng
31348275SEric Cheng /*
31358275SEric Cheng * When a MAC client desires to capture packets on an interface,
31368275SEric Cheng * it registers a promiscuous call back with mac_promisc_add().
31378275SEric Cheng * There are three types of promiscuous callbacks:
31388275SEric Cheng *
31398275SEric Cheng * * MAC_CLIENT_PROMISC_ALL
31408275SEric Cheng * Captures all packets sent and received by the MAC client,
31418275SEric Cheng * the physical interface, as well as all other MAC clients
31428275SEric Cheng * defined on top of the same MAC.
31438275SEric Cheng *
31448275SEric Cheng * * MAC_CLIENT_PROMISC_FILTERED
31458275SEric Cheng * Captures all packets sent and received by the MAC client,
31468275SEric Cheng * plus all multicast traffic sent and received by the phyisical
31478275SEric Cheng * interface and the other MAC clients.
31488275SEric Cheng *
31498275SEric Cheng * * MAC_CLIENT_PROMISC_MULTI
31508275SEric Cheng * Captures all broadcast and multicast packets sent and
31518275SEric Cheng * received by the MAC clients as well as the physical interface.
31528275SEric Cheng *
31538275SEric Cheng * In all cases, the underlying MAC is put in promiscuous mode.
31548275SEric Cheng */
31558275SEric Cheng int
mac_promisc_add(mac_client_handle_t mch,mac_client_promisc_type_t type,mac_rx_t fn,void * arg,mac_promisc_handle_t * mphp,uint16_t flags)31568275SEric Cheng mac_promisc_add(mac_client_handle_t mch, mac_client_promisc_type_t type,
31578275SEric Cheng mac_rx_t fn, void *arg, mac_promisc_handle_t *mphp, uint16_t flags)
31588275SEric Cheng {
31598275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
31608275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
31618275SEric Cheng mac_promisc_impl_t *mpip;
31628275SEric Cheng mac_cb_info_t *mcbi;
31638275SEric Cheng int rc;
31648275SEric Cheng
31658275SEric Cheng i_mac_perim_enter(mip);
31668275SEric Cheng
31678893SMichael.Lim@Sun.COM if ((rc = mac_start((mac_handle_t)mip)) != 0) {
31688275SEric Cheng i_mac_perim_exit(mip);
31698275SEric Cheng return (rc);
31708275SEric Cheng }
31718275SEric Cheng
31728275SEric Cheng if ((mcip->mci_state_flags & MCIS_IS_VNIC) &&
31738275SEric Cheng type == MAC_CLIENT_PROMISC_ALL) {
31748275SEric Cheng /*
31758275SEric Cheng * The function is being invoked by the upper MAC client
31768275SEric Cheng * of a VNIC. The VNIC should only see the traffic
31778275SEric Cheng * it is entitled to.
31788275SEric Cheng */
31798275SEric Cheng type = MAC_CLIENT_PROMISC_FILTERED;
31808275SEric Cheng }
31818275SEric Cheng
31828275SEric Cheng
31838275SEric Cheng /*
31848275SEric Cheng * Turn on promiscuous mode for the underlying NIC.
31858275SEric Cheng * This is needed even for filtered callbacks which
31868275SEric Cheng * expect to receive all multicast traffic on the wire.
31878275SEric Cheng *
31888275SEric Cheng * Physical promiscuous mode should not be turned on if
31898275SEric Cheng * MAC_PROMISC_FLAGS_NO_PHYS is set.
31908275SEric Cheng */
31918275SEric Cheng if ((flags & MAC_PROMISC_FLAGS_NO_PHYS) == 0) {
31929641SGirish.Moodalbail@Sun.COM if ((rc = i_mac_promisc_set(mip, B_TRUE)) != 0) {
31938893SMichael.Lim@Sun.COM mac_stop((mac_handle_t)mip);
31948275SEric Cheng i_mac_perim_exit(mip);
31958275SEric Cheng return (rc);
31968275SEric Cheng }
31978275SEric Cheng }
31988275SEric Cheng
31998275SEric Cheng mpip = kmem_cache_alloc(mac_promisc_impl_cache, KM_SLEEP);
32008275SEric Cheng
32018275SEric Cheng mpip->mpi_type = type;
32028275SEric Cheng mpip->mpi_fn = fn;
32038275SEric Cheng mpip->mpi_arg = arg;
32048275SEric Cheng mpip->mpi_mcip = mcip;
32058275SEric Cheng mpip->mpi_no_tx_loop = ((flags & MAC_PROMISC_FLAGS_NO_TX_LOOP) != 0);
32068275SEric Cheng mpip->mpi_no_phys = ((flags & MAC_PROMISC_FLAGS_NO_PHYS) != 0);
32078833SVenu.Iyer@Sun.COM mpip->mpi_strip_vlan_tag =
32088833SVenu.Iyer@Sun.COM ((flags & MAC_PROMISC_FLAGS_VLAN_TAG_STRIP) != 0);
320910639SDarren.Reed@Sun.COM mpip->mpi_no_copy = ((flags & MAC_PROMISC_FLAGS_NO_COPY) != 0);
32108275SEric Cheng
32118275SEric Cheng mcbi = &mip->mi_promisc_cb_info;
32128275SEric Cheng mutex_enter(mcbi->mcbi_lockp);
32138275SEric Cheng
32148275SEric Cheng mac_callback_add(&mip->mi_promisc_cb_info, &mcip->mci_promisc_list,
32158275SEric Cheng &mpip->mpi_mci_link);
32168275SEric Cheng mac_callback_add(&mip->mi_promisc_cb_info, &mip->mi_promisc_list,
32178275SEric Cheng &mpip->mpi_mi_link);
32188275SEric Cheng
32198275SEric Cheng mutex_exit(mcbi->mcbi_lockp);
32208275SEric Cheng
32218275SEric Cheng *mphp = (mac_promisc_handle_t)mpip;
32228275SEric Cheng i_mac_perim_exit(mip);
32238275SEric Cheng return (0);
32248275SEric Cheng }
32258275SEric Cheng
32268275SEric Cheng /*
32278275SEric Cheng * Remove a multicast address previously aded through mac_promisc_add().
32288275SEric Cheng */
32299044SGirish.Moodalbail@Sun.COM void
mac_promisc_remove(mac_promisc_handle_t mph)32308275SEric Cheng mac_promisc_remove(mac_promisc_handle_t mph)
32318275SEric Cheng {
32328275SEric Cheng mac_promisc_impl_t *mpip = (mac_promisc_impl_t *)mph;
32338275SEric Cheng mac_client_impl_t *mcip = mpip->mpi_mcip;
32348275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
32358275SEric Cheng mac_cb_info_t *mcbi;
32369641SGirish.Moodalbail@Sun.COM int rv;
32378275SEric Cheng
32388275SEric Cheng i_mac_perim_enter(mip);
32398275SEric Cheng
32408275SEric Cheng /*
32418275SEric Cheng * Even if the device can't be reset into normal mode, we still
32428275SEric Cheng * need to clear the client promisc callbacks. The client may want
32438275SEric Cheng * to close the mac end point and we can't have stale callbacks.
32448275SEric Cheng */
32458275SEric Cheng if (!(mpip->mpi_no_phys)) {
32469641SGirish.Moodalbail@Sun.COM if ((rv = i_mac_promisc_set(mip, B_FALSE)) != 0) {
32479641SGirish.Moodalbail@Sun.COM cmn_err(CE_WARN, "%s: failed to switch OFF promiscuous"
32489641SGirish.Moodalbail@Sun.COM " mode because of error 0x%x", mip->mi_name, rv);
32499641SGirish.Moodalbail@Sun.COM }
32508275SEric Cheng }
32518275SEric Cheng mcbi = &mip->mi_promisc_cb_info;
32528275SEric Cheng mutex_enter(mcbi->mcbi_lockp);
32538275SEric Cheng if (mac_callback_remove(mcbi, &mip->mi_promisc_list,
32548275SEric Cheng &mpip->mpi_mi_link)) {
32558275SEric Cheng VERIFY(mac_callback_remove(&mip->mi_promisc_cb_info,
32568275SEric Cheng &mcip->mci_promisc_list, &mpip->mpi_mci_link));
32578275SEric Cheng kmem_cache_free(mac_promisc_impl_cache, mpip);
32588275SEric Cheng } else {
32598275SEric Cheng mac_callback_remove_wait(&mip->mi_promisc_cb_info);
32608275SEric Cheng }
32618275SEric Cheng mutex_exit(mcbi->mcbi_lockp);
32628893SMichael.Lim@Sun.COM mac_stop((mac_handle_t)mip);
32638275SEric Cheng
32648275SEric Cheng i_mac_perim_exit(mip);
32658275SEric Cheng }
32668275SEric Cheng
32678275SEric Cheng /*
32688275SEric Cheng * Reference count the number of active Tx threads. MCI_TX_QUIESCE indicates
32698275SEric Cheng * that a control operation wants to quiesce the Tx data flow in which case
32708275SEric Cheng * we return an error. Holding any of the per cpu locks ensures that the
32718275SEric Cheng * mci_tx_flag won't change.
32728275SEric Cheng *
32738275SEric Cheng * 'CPU' must be accessed just once and used to compute the index into the
32748275SEric Cheng * percpu array, and that index must be used for the entire duration of the
32758275SEric Cheng * packet send operation. Note that the thread may be preempted and run on
32768275SEric Cheng * another cpu any time and so we can't use 'CPU' more than once for the
32778275SEric Cheng * operation.
32788275SEric Cheng */
32798275SEric Cheng #define MAC_TX_TRY_HOLD(mcip, mytx, error) \
32808275SEric Cheng { \
32818275SEric Cheng (error) = 0; \
32828275SEric Cheng (mytx) = &(mcip)->mci_tx_pcpu[CPU->cpu_seqid & mac_tx_percpu_cnt]; \
32838275SEric Cheng mutex_enter(&(mytx)->pcpu_tx_lock); \
32848275SEric Cheng if (!((mcip)->mci_tx_flag & MCI_TX_QUIESCE)) { \
32858275SEric Cheng (mytx)->pcpu_tx_refcnt++; \
32868275SEric Cheng } else { \
32878275SEric Cheng (error) = -1; \
32888275SEric Cheng } \
32898275SEric Cheng mutex_exit(&(mytx)->pcpu_tx_lock); \
32908275SEric Cheng }
32918275SEric Cheng
32928275SEric Cheng /*
32938275SEric Cheng * Release the reference. If needed, signal any control operation waiting
32948275SEric Cheng * for Tx quiescence. The wait and signal are always done using the
32958275SEric Cheng * mci_tx_pcpu[0]'s lock
32968275SEric Cheng */
32978275SEric Cheng #define MAC_TX_RELE(mcip, mytx) { \
32988275SEric Cheng mutex_enter(&(mytx)->pcpu_tx_lock); \
32998275SEric Cheng if (--(mytx)->pcpu_tx_refcnt == 0 && \
33008275SEric Cheng (mcip)->mci_tx_flag & MCI_TX_QUIESCE) { \
33018275SEric Cheng mutex_exit(&(mytx)->pcpu_tx_lock); \
33028275SEric Cheng mutex_enter(&(mcip)->mci_tx_pcpu[0].pcpu_tx_lock); \
33038275SEric Cheng cv_signal(&(mcip)->mci_tx_cv); \
33048275SEric Cheng mutex_exit(&(mcip)->mci_tx_pcpu[0].pcpu_tx_lock); \
33058275SEric Cheng } else { \
33068275SEric Cheng mutex_exit(&(mytx)->pcpu_tx_lock); \
33078275SEric Cheng } \
33088275SEric Cheng }
33098275SEric Cheng
33108275SEric Cheng /*
33118275SEric Cheng * Send function invoked by MAC clients.
33128275SEric Cheng */
33138275SEric Cheng mac_tx_cookie_t
mac_tx(mac_client_handle_t mch,mblk_t * mp_chain,uintptr_t hint,uint16_t flag,mblk_t ** ret_mp)33148275SEric Cheng mac_tx(mac_client_handle_t mch, mblk_t *mp_chain, uintptr_t hint,
33158275SEric Cheng uint16_t flag, mblk_t **ret_mp)
33168275SEric Cheng {
331710734SEric Cheng mac_tx_cookie_t cookie = NULL;
33188275SEric Cheng int error;
33198275SEric Cheng mac_tx_percpu_t *mytx;
33208275SEric Cheng mac_soft_ring_set_t *srs;
33218275SEric Cheng flow_entry_t *flent;
33228275SEric Cheng boolean_t is_subflow = B_FALSE;
33238275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
33248275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
33258275SEric Cheng mac_srs_tx_t *srs_tx;
33268275SEric Cheng
33278275SEric Cheng /*
33288275SEric Cheng * Check whether the active Tx threads count is bumped already.
33298275SEric Cheng */
33308275SEric Cheng if (!(flag & MAC_TX_NO_HOLD)) {
33318275SEric Cheng MAC_TX_TRY_HOLD(mcip, mytx, error);
33328275SEric Cheng if (error != 0) {
33338275SEric Cheng freemsgchain(mp_chain);
33348275SEric Cheng return (NULL);
33358275SEric Cheng }
33368275SEric Cheng }
33378275SEric Cheng
333810734SEric Cheng /*
333910734SEric Cheng * If mac protection is enabled, only the permissible packets will be
334010734SEric Cheng * returned by mac_protect_check().
334110734SEric Cheng */
334210734SEric Cheng if ((mcip->mci_flent->
334310734SEric Cheng fe_resource_props.mrp_mask & MRP_PROTECT) != 0 &&
334410734SEric Cheng (mp_chain = mac_protect_check(mch, mp_chain)) == NULL)
334510734SEric Cheng goto done;
334610734SEric Cheng
33478275SEric Cheng if (mcip->mci_subflow_tab != NULL &&
33488275SEric Cheng mcip->mci_subflow_tab->ft_flow_count > 0 &&
33498275SEric Cheng mac_flow_lookup(mcip->mci_subflow_tab, mp_chain,
33508275SEric Cheng FLOW_OUTBOUND, &flent) == 0) {
33518275SEric Cheng /*
33528275SEric Cheng * The main assumption here is that if in the event
33538275SEric Cheng * we get a chain, all the packets will be classified
33548275SEric Cheng * to the same Flow/SRS. If this changes for any
33558275SEric Cheng * reason, the following logic should change as well.
33568275SEric Cheng * I suppose the fanout_hint also assumes this .
33578275SEric Cheng */
33588275SEric Cheng ASSERT(flent != NULL);
33598275SEric Cheng is_subflow = B_TRUE;
33608275SEric Cheng } else {
33618275SEric Cheng flent = mcip->mci_flent;
33628275SEric Cheng }
33638275SEric Cheng
33648275SEric Cheng srs = flent->fe_tx_srs;
336510639SDarren.Reed@Sun.COM /*
336610639SDarren.Reed@Sun.COM * This is to avoid panics with PF_PACKET that can call mac_tx()
336710639SDarren.Reed@Sun.COM * against an interface that is not capable of sending. A rewrite
336810639SDarren.Reed@Sun.COM * of the mac datapath is required to remove this limitation.
336910639SDarren.Reed@Sun.COM */
337010639SDarren.Reed@Sun.COM if (srs == NULL) {
337110639SDarren.Reed@Sun.COM freemsgchain(mp_chain);
337210734SEric Cheng goto done;
337310639SDarren.Reed@Sun.COM }
337410734SEric Cheng
33758275SEric Cheng srs_tx = &srs->srs_tx;
33768275SEric Cheng if (srs_tx->st_mode == SRS_TX_DEFAULT &&
33778275SEric Cheng (srs->srs_state & SRS_ENQUEUED) == 0 &&
337811878SVenu.Iyer@Sun.COM mip->mi_nactiveclients == 1 && mp_chain->b_next == NULL) {
33798275SEric Cheng uint64_t obytes;
33808275SEric Cheng
33818275SEric Cheng /*
33828275SEric Cheng * Since dls always opens the underlying MAC, nclients equals
33838275SEric Cheng * to 1 means that the only active client is dls itself acting
33848275SEric Cheng * as a primary client of the MAC instance. Since dls will not
33858275SEric Cheng * send tagged packets in that case, and dls is trusted to send
33868275SEric Cheng * packets for its allowed VLAN(s), the VLAN tag insertion and
33878275SEric Cheng * check is required only if nclients is greater than 1.
33888275SEric Cheng */
33898275SEric Cheng if (mip->mi_nclients > 1) {
33908275SEric Cheng if (MAC_VID_CHECK_NEEDED(mcip)) {
33918275SEric Cheng int err = 0;
33928275SEric Cheng
33938275SEric Cheng MAC_VID_CHECK(mcip, mp_chain, err);
33948275SEric Cheng if (err != 0) {
33958275SEric Cheng freemsg(mp_chain);
339611878SVenu.Iyer@Sun.COM mcip->mci_misc_stat.mms_txerrors++;
33978275SEric Cheng goto done;
33988275SEric Cheng }
33998275SEric Cheng }
34008275SEric Cheng if (MAC_TAG_NEEDED(mcip)) {
34018275SEric Cheng mp_chain = mac_add_vlan_tag(mp_chain, 0,
34028275SEric Cheng mac_client_vid(mch));
34038275SEric Cheng if (mp_chain == NULL) {
340411878SVenu.Iyer@Sun.COM mcip->mci_misc_stat.mms_txerrors++;
34058275SEric Cheng goto done;
34068275SEric Cheng }
34078275SEric Cheng }
34088275SEric Cheng }
34098275SEric Cheng
34108275SEric Cheng obytes = (mp_chain->b_cont == NULL ? MBLKL(mp_chain) :
34118275SEric Cheng msgdsize(mp_chain));
34128275SEric Cheng
341311878SVenu.Iyer@Sun.COM MAC_TX(mip, srs_tx->st_arg2, mp_chain, mcip);
34148275SEric Cheng if (mp_chain == NULL) {
34158275SEric Cheng cookie = NULL;
341611878SVenu.Iyer@Sun.COM SRS_TX_STAT_UPDATE(srs, opackets, 1);
341711878SVenu.Iyer@Sun.COM SRS_TX_STAT_UPDATE(srs, obytes, obytes);
34188275SEric Cheng } else {
34198275SEric Cheng mutex_enter(&srs->srs_lock);
34208275SEric Cheng cookie = mac_tx_srs_no_desc(srs, mp_chain,
34218275SEric Cheng flag, ret_mp);
34228275SEric Cheng mutex_exit(&srs->srs_lock);
34238275SEric Cheng }
34248275SEric Cheng } else {
34258275SEric Cheng cookie = srs_tx->st_func(srs, mp_chain, hint, flag, ret_mp);
34268275SEric Cheng }
34278275SEric Cheng
34288275SEric Cheng done:
34298275SEric Cheng if (is_subflow)
34308275SEric Cheng FLOW_REFRELE(flent);
34318275SEric Cheng
34328275SEric Cheng if (!(flag & MAC_TX_NO_HOLD))
34338275SEric Cheng MAC_TX_RELE(mcip, mytx);
34348275SEric Cheng
34358275SEric Cheng return (cookie);
34368275SEric Cheng }
34378275SEric Cheng
34388275SEric Cheng /*
34398275SEric Cheng * mac_tx_is_blocked
34408275SEric Cheng *
34418275SEric Cheng * Given a cookie, it returns if the ring identified by the cookie is
34428833SVenu.Iyer@Sun.COM * flow-controlled or not. If NULL is passed in place of a cookie,
34438833SVenu.Iyer@Sun.COM * then it finds out if any of the underlying rings belonging to the
34448833SVenu.Iyer@Sun.COM * SRS is flow controlled or not and returns that status.
34458275SEric Cheng */
34468275SEric Cheng /* ARGSUSED */
34478275SEric Cheng boolean_t
mac_tx_is_flow_blocked(mac_client_handle_t mch,mac_tx_cookie_t cookie)34488275SEric Cheng mac_tx_is_flow_blocked(mac_client_handle_t mch, mac_tx_cookie_t cookie)
34498275SEric Cheng {
34508275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
34518833SVenu.Iyer@Sun.COM mac_soft_ring_set_t *mac_srs;
34528275SEric Cheng mac_soft_ring_t *sringp;
34538275SEric Cheng boolean_t blocked = B_FALSE;
34548833SVenu.Iyer@Sun.COM mac_tx_percpu_t *mytx;
34558833SVenu.Iyer@Sun.COM int err;
34568275SEric Cheng int i;
34578275SEric Cheng
34588275SEric Cheng /*
34598833SVenu.Iyer@Sun.COM * Bump the reference count so that mac_srs won't be deleted.
34608833SVenu.Iyer@Sun.COM * If the client is currently quiesced and we failed to bump
34618833SVenu.Iyer@Sun.COM * the reference, return B_TRUE so that flow control stays
34628833SVenu.Iyer@Sun.COM * as enabled.
34638833SVenu.Iyer@Sun.COM *
34648833SVenu.Iyer@Sun.COM * Flow control will then be disabled once the client is no
34658833SVenu.Iyer@Sun.COM * longer quiesced.
34668275SEric Cheng */
34678833SVenu.Iyer@Sun.COM MAC_TX_TRY_HOLD(mcip, mytx, err);
34688833SVenu.Iyer@Sun.COM if (err != 0)
34698833SVenu.Iyer@Sun.COM return (B_TRUE);
34708833SVenu.Iyer@Sun.COM
34718833SVenu.Iyer@Sun.COM if ((mac_srs = MCIP_TX_SRS(mcip)) == NULL) {
34728833SVenu.Iyer@Sun.COM MAC_TX_RELE(mcip, mytx);
34738275SEric Cheng return (B_FALSE);
34748833SVenu.Iyer@Sun.COM }
34758275SEric Cheng
34768275SEric Cheng mutex_enter(&mac_srs->srs_lock);
347711878SVenu.Iyer@Sun.COM /*
347811878SVenu.Iyer@Sun.COM * Only in the case of TX_FANOUT and TX_AGGR, the underlying
347911878SVenu.Iyer@Sun.COM * softring (s_ring_state) will have the HIWAT set. This is
348011878SVenu.Iyer@Sun.COM * the multiple Tx ring flow control case. For all other
348111878SVenu.Iyer@Sun.COM * case, SRS (srs_state) will store the condition.
348211878SVenu.Iyer@Sun.COM */
348311878SVenu.Iyer@Sun.COM if (mac_srs->srs_tx.st_mode == SRS_TX_FANOUT ||
348411878SVenu.Iyer@Sun.COM mac_srs->srs_tx.st_mode == SRS_TX_AGGR) {
34858833SVenu.Iyer@Sun.COM if (cookie != NULL) {
34868833SVenu.Iyer@Sun.COM sringp = (mac_soft_ring_t *)cookie;
34878275SEric Cheng mutex_enter(&sringp->s_ring_lock);
34888833SVenu.Iyer@Sun.COM if (sringp->s_ring_state & S_RING_TX_HIWAT)
34898275SEric Cheng blocked = B_TRUE;
34908833SVenu.Iyer@Sun.COM mutex_exit(&sringp->s_ring_lock);
34918833SVenu.Iyer@Sun.COM } else {
349211878SVenu.Iyer@Sun.COM for (i = 0; i < mac_srs->srs_tx_ring_count; i++) {
349311878SVenu.Iyer@Sun.COM sringp = mac_srs->srs_tx_soft_rings[i];
34948833SVenu.Iyer@Sun.COM mutex_enter(&sringp->s_ring_lock);
34958833SVenu.Iyer@Sun.COM if (sringp->s_ring_state & S_RING_TX_HIWAT) {
34968833SVenu.Iyer@Sun.COM blocked = B_TRUE;
34978833SVenu.Iyer@Sun.COM mutex_exit(&sringp->s_ring_lock);
34988833SVenu.Iyer@Sun.COM break;
34998833SVenu.Iyer@Sun.COM }
35008275SEric Cheng mutex_exit(&sringp->s_ring_lock);
35018275SEric Cheng }
35028275SEric Cheng }
35038275SEric Cheng } else {
35048275SEric Cheng blocked = (mac_srs->srs_state & SRS_TX_HIWAT);
35058275SEric Cheng }
35068275SEric Cheng mutex_exit(&mac_srs->srs_lock);
35078833SVenu.Iyer@Sun.COM MAC_TX_RELE(mcip, mytx);
35088275SEric Cheng return (blocked);
35098275SEric Cheng }
35108275SEric Cheng
35118275SEric Cheng /*
35128275SEric Cheng * Check if the MAC client is the primary MAC client.
35138275SEric Cheng */
35148275SEric Cheng boolean_t
mac_is_primary_client(mac_client_impl_t * mcip)35158275SEric Cheng mac_is_primary_client(mac_client_impl_t *mcip)
35168275SEric Cheng {
35178275SEric Cheng return (mcip->mci_flags & MAC_CLIENT_FLAGS_PRIMARY);
35188275SEric Cheng }
35198275SEric Cheng
35208275SEric Cheng void
mac_ioctl(mac_handle_t mh,queue_t * wq,mblk_t * bp)35218275SEric Cheng mac_ioctl(mac_handle_t mh, queue_t *wq, mblk_t *bp)
35228275SEric Cheng {
35238275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
35248275SEric Cheng int cmd = ((struct iocblk *)bp->b_rptr)->ioc_cmd;
35258275SEric Cheng
35268275SEric Cheng if ((cmd == ND_GET && (mip->mi_callbacks->mc_callbacks & MC_GETPROP)) ||
35278275SEric Cheng (cmd == ND_SET && (mip->mi_callbacks->mc_callbacks & MC_SETPROP))) {
35288275SEric Cheng /*
35298275SEric Cheng * If ndd props were registered, call them.
35308275SEric Cheng * Note that ndd ioctls are Obsolete
35318275SEric Cheng */
35328275SEric Cheng mac_ndd_ioctl(mip, wq, bp);
35338275SEric Cheng return;
35348275SEric Cheng }
35358275SEric Cheng
35368275SEric Cheng /*
35378275SEric Cheng * Call the driver to handle the ioctl. The driver may not support
35388275SEric Cheng * any ioctls, in which case we reply with a NAK on its behalf.
35398275SEric Cheng */
35408275SEric Cheng if (mip->mi_callbacks->mc_callbacks & MC_IOCTL)
35418275SEric Cheng mip->mi_ioctl(mip->mi_driver, wq, bp);
35428275SEric Cheng else
35438275SEric Cheng miocnak(wq, bp, 0, EINVAL);
35448275SEric Cheng }
35458275SEric Cheng
35468275SEric Cheng /*
35478275SEric Cheng * Return the link state of the specified MAC instance.
35488275SEric Cheng */
35498275SEric Cheng link_state_t
mac_link_get(mac_handle_t mh)35508275SEric Cheng mac_link_get(mac_handle_t mh)
35518275SEric Cheng {
35528275SEric Cheng return (((mac_impl_t *)mh)->mi_linkstate);
35538275SEric Cheng }
35548275SEric Cheng
35558275SEric Cheng /*
35568275SEric Cheng * Add a mac client specified notification callback. Please see the comments
35578275SEric Cheng * above mac_callback_add() for general information about mac callback
35588275SEric Cheng * addition/deletion in the presence of mac callback list walkers
35598275SEric Cheng */
35608275SEric Cheng mac_notify_handle_t
mac_notify_add(mac_handle_t mh,mac_notify_t notify_fn,void * arg)35618275SEric Cheng mac_notify_add(mac_handle_t mh, mac_notify_t notify_fn, void *arg)
35628275SEric Cheng {
35638275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
35648275SEric Cheng mac_notify_cb_t *mncb;
35658275SEric Cheng mac_cb_info_t *mcbi;
35668275SEric Cheng
35678275SEric Cheng /*
35688275SEric Cheng * Allocate a notify callback structure, fill in the details and
35698275SEric Cheng * use the mac callback list manipulation functions to chain into
35708275SEric Cheng * the list of callbacks.
35718275SEric Cheng */
35728275SEric Cheng mncb = kmem_zalloc(sizeof (mac_notify_cb_t), KM_SLEEP);
35738275SEric Cheng mncb->mncb_fn = notify_fn;
35748275SEric Cheng mncb->mncb_arg = arg;
35758275SEric Cheng mncb->mncb_mip = mip;
35768275SEric Cheng mncb->mncb_link.mcb_objp = mncb;
35778275SEric Cheng mncb->mncb_link.mcb_objsize = sizeof (mac_notify_cb_t);
35788275SEric Cheng mncb->mncb_link.mcb_flags = MCB_NOTIFY_CB_T;
35798275SEric Cheng
35808275SEric Cheng mcbi = &mip->mi_notify_cb_info;
35818275SEric Cheng
35828275SEric Cheng i_mac_perim_enter(mip);
35838275SEric Cheng mutex_enter(mcbi->mcbi_lockp);
35848275SEric Cheng
35858275SEric Cheng mac_callback_add(&mip->mi_notify_cb_info, &mip->mi_notify_cb_list,
35868275SEric Cheng &mncb->mncb_link);
35878275SEric Cheng
35888275SEric Cheng mutex_exit(mcbi->mcbi_lockp);
35898275SEric Cheng i_mac_perim_exit(mip);
35908275SEric Cheng return ((mac_notify_handle_t)mncb);
35918275SEric Cheng }
35928275SEric Cheng
35938275SEric Cheng void
mac_notify_remove_wait(mac_handle_t mh)35948275SEric Cheng mac_notify_remove_wait(mac_handle_t mh)
35958275SEric Cheng {
35968275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
35978275SEric Cheng mac_cb_info_t *mcbi = &mip->mi_notify_cb_info;
35988275SEric Cheng
35998275SEric Cheng mutex_enter(mcbi->mcbi_lockp);
36008275SEric Cheng mac_callback_remove_wait(&mip->mi_notify_cb_info);
36018275SEric Cheng mutex_exit(mcbi->mcbi_lockp);
36028275SEric Cheng }
36038275SEric Cheng
36048275SEric Cheng /*
36058275SEric Cheng * Remove a mac client specified notification callback
36068275SEric Cheng */
36078275SEric Cheng int
mac_notify_remove(mac_notify_handle_t mnh,boolean_t wait)36088275SEric Cheng mac_notify_remove(mac_notify_handle_t mnh, boolean_t wait)
36098275SEric Cheng {
36108275SEric Cheng mac_notify_cb_t *mncb = (mac_notify_cb_t *)mnh;
36118275SEric Cheng mac_impl_t *mip = mncb->mncb_mip;
36128275SEric Cheng mac_cb_info_t *mcbi;
36138275SEric Cheng int err = 0;
36148275SEric Cheng
36158275SEric Cheng mcbi = &mip->mi_notify_cb_info;
36168275SEric Cheng
36178275SEric Cheng i_mac_perim_enter(mip);
36188275SEric Cheng mutex_enter(mcbi->mcbi_lockp);
36198275SEric Cheng
36208275SEric Cheng ASSERT(mncb->mncb_link.mcb_objp == mncb);
36218275SEric Cheng /*
36228275SEric Cheng * If there aren't any list walkers, the remove would succeed
36238275SEric Cheng * inline, else we wait for the deferred remove to complete
36248275SEric Cheng */
36258275SEric Cheng if (mac_callback_remove(&mip->mi_notify_cb_info,
36268275SEric Cheng &mip->mi_notify_cb_list, &mncb->mncb_link)) {
36278275SEric Cheng kmem_free(mncb, sizeof (mac_notify_cb_t));
36288275SEric Cheng } else {
36298275SEric Cheng err = EBUSY;
36308275SEric Cheng }
36318275SEric Cheng
36328275SEric Cheng mutex_exit(mcbi->mcbi_lockp);
36338275SEric Cheng i_mac_perim_exit(mip);
36348275SEric Cheng
36358275SEric Cheng /*
36368275SEric Cheng * If we failed to remove the notification callback and "wait" is set
36378275SEric Cheng * to be B_TRUE, wait for the callback to finish after we exit the
36388275SEric Cheng * mac perimeter.
36398275SEric Cheng */
36408275SEric Cheng if (err != 0 && wait) {
36418275SEric Cheng mac_notify_remove_wait((mac_handle_t)mip);
36428275SEric Cheng return (0);
36438275SEric Cheng }
36448275SEric Cheng
36458275SEric Cheng return (err);
36468275SEric Cheng }
36478275SEric Cheng
36488275SEric Cheng /*
36498275SEric Cheng * Associate resource management callbacks with the specified MAC
36508275SEric Cheng * clients.
36518275SEric Cheng */
36528275SEric Cheng
36538275SEric Cheng void
mac_resource_set_common(mac_client_handle_t mch,mac_resource_add_t add,mac_resource_remove_t remove,mac_resource_quiesce_t quiesce,mac_resource_restart_t restart,mac_resource_bind_t bind,void * arg)36548275SEric Cheng mac_resource_set_common(mac_client_handle_t mch, mac_resource_add_t add,
36558275SEric Cheng mac_resource_remove_t remove, mac_resource_quiesce_t quiesce,
36568275SEric Cheng mac_resource_restart_t restart, mac_resource_bind_t bind,
36578275SEric Cheng void *arg)
36588275SEric Cheng {
36598275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
36608275SEric Cheng
36618275SEric Cheng mcip->mci_resource_add = add;
36628275SEric Cheng mcip->mci_resource_remove = remove;
36638275SEric Cheng mcip->mci_resource_quiesce = quiesce;
36648275SEric Cheng mcip->mci_resource_restart = restart;
36658275SEric Cheng mcip->mci_resource_bind = bind;
36668275SEric Cheng mcip->mci_resource_arg = arg;
36678275SEric Cheng }
36688275SEric Cheng
36698275SEric Cheng void
mac_resource_set(mac_client_handle_t mch,mac_resource_add_t add,void * arg)36708275SEric Cheng mac_resource_set(mac_client_handle_t mch, mac_resource_add_t add, void *arg)
36718275SEric Cheng {
36728275SEric Cheng /* update the 'resource_add' callback */
36738275SEric Cheng mac_resource_set_common(mch, add, NULL, NULL, NULL, NULL, arg);
36748275SEric Cheng }
36758275SEric Cheng
36768275SEric Cheng /*
36778275SEric Cheng * Sets up the client resources and enable the polling interface over all the
36788275SEric Cheng * SRS's and the soft rings of the client
36798275SEric Cheng */
36808275SEric Cheng void
mac_client_poll_enable(mac_client_handle_t mch)36818275SEric Cheng mac_client_poll_enable(mac_client_handle_t mch)
36828275SEric Cheng {
36838275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
36848275SEric Cheng mac_soft_ring_set_t *mac_srs;
36858275SEric Cheng flow_entry_t *flent;
36868275SEric Cheng int i;
36878275SEric Cheng
36888275SEric Cheng flent = mcip->mci_flent;
36898275SEric Cheng ASSERT(flent != NULL);
36908275SEric Cheng
369111021SEric.Cheng@Sun.COM mcip->mci_state_flags |= MCIS_CLIENT_POLL_CAPABLE;
36928275SEric Cheng for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
36938275SEric Cheng mac_srs = (mac_soft_ring_set_t *)flent->fe_rx_srs[i];
36948275SEric Cheng ASSERT(mac_srs->srs_mcip == mcip);
36958275SEric Cheng mac_srs_client_poll_enable(mcip, mac_srs);
36968275SEric Cheng }
36978275SEric Cheng }
36988275SEric Cheng
36998275SEric Cheng /*
37008275SEric Cheng * Tears down the client resources and disable the polling interface over all
37018275SEric Cheng * the SRS's and the soft rings of the client
37028275SEric Cheng */
37038275SEric Cheng void
mac_client_poll_disable(mac_client_handle_t mch)37048275SEric Cheng mac_client_poll_disable(mac_client_handle_t mch)
37058275SEric Cheng {
37068275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
37078275SEric Cheng mac_soft_ring_set_t *mac_srs;
37088275SEric Cheng flow_entry_t *flent;
37098275SEric Cheng int i;
37108275SEric Cheng
37118275SEric Cheng flent = mcip->mci_flent;
37128275SEric Cheng ASSERT(flent != NULL);
37138275SEric Cheng
371411021SEric.Cheng@Sun.COM mcip->mci_state_flags &= ~MCIS_CLIENT_POLL_CAPABLE;
37158275SEric Cheng for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
37168275SEric Cheng mac_srs = (mac_soft_ring_set_t *)flent->fe_rx_srs[i];
37178275SEric Cheng ASSERT(mac_srs->srs_mcip == mcip);
37188275SEric Cheng mac_srs_client_poll_disable(mcip, mac_srs);
37198275SEric Cheng }
37208275SEric Cheng }
37218275SEric Cheng
37228275SEric Cheng /*
37238275SEric Cheng * Associate the CPUs specified by the given property with a MAC client.
37248275SEric Cheng */
37258275SEric Cheng int
mac_cpu_set(mac_client_handle_t mch,mac_resource_props_t * mrp)37268275SEric Cheng mac_cpu_set(mac_client_handle_t mch, mac_resource_props_t *mrp)
37278275SEric Cheng {
37288275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
37298275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
37308275SEric Cheng int err = 0;
37318275SEric Cheng
37328275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
37338275SEric Cheng
373411878SVenu.Iyer@Sun.COM if ((err = mac_validate_props(mcip->mci_state_flags & MCIS_IS_VNIC ?
373511878SVenu.Iyer@Sun.COM mcip->mci_upper_mip : mip, mrp)) != 0) {
37368275SEric Cheng return (err);
373711878SVenu.Iyer@Sun.COM }
37388275SEric Cheng if (MCIP_DATAPATH_SETUP(mcip))
37398275SEric Cheng mac_flow_modify(mip->mi_flow_tab, mcip->mci_flent, mrp);
37408275SEric Cheng
37418275SEric Cheng mac_update_resources(mrp, MCIP_RESOURCE_PROPS(mcip), B_FALSE);
37428275SEric Cheng return (0);
37438275SEric Cheng }
37448275SEric Cheng
37458275SEric Cheng /*
37468275SEric Cheng * Apply the specified properties to the specified MAC client.
37478275SEric Cheng */
37488275SEric Cheng int
mac_client_set_resources(mac_client_handle_t mch,mac_resource_props_t * mrp)37498275SEric Cheng mac_client_set_resources(mac_client_handle_t mch, mac_resource_props_t *mrp)
37508275SEric Cheng {
37518275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
37528275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
37538275SEric Cheng int err = 0;
37548275SEric Cheng
37558275SEric Cheng i_mac_perim_enter(mip);
37568275SEric Cheng
37578275SEric Cheng if ((mrp->mrp_mask & MRP_MAXBW) || (mrp->mrp_mask & MRP_PRIORITY)) {
37588275SEric Cheng err = mac_resource_ctl_set(mch, mrp);
375910734SEric Cheng if (err != 0)
376010734SEric Cheng goto done;
37618275SEric Cheng }
37628275SEric Cheng
376311878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & (MRP_CPUS|MRP_POOL)) {
37648275SEric Cheng err = mac_cpu_set(mch, mrp);
376510734SEric Cheng if (err != 0)
376610734SEric Cheng goto done;
376710734SEric Cheng }
376810734SEric Cheng
376911878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_PROTECT) {
377010734SEric Cheng err = mac_protect_set(mch, mrp);
377111878SVenu.Iyer@Sun.COM if (err != 0)
377211878SVenu.Iyer@Sun.COM goto done;
377311878SVenu.Iyer@Sun.COM }
377411878SVenu.Iyer@Sun.COM
377511878SVenu.Iyer@Sun.COM if ((mrp->mrp_mask & MRP_RX_RINGS) || (mrp->mrp_mask & MRP_TX_RINGS))
377611878SVenu.Iyer@Sun.COM err = mac_resource_ctl_set(mch, mrp);
377710734SEric Cheng
377810734SEric Cheng done:
37798275SEric Cheng i_mac_perim_exit(mip);
37808275SEric Cheng return (err);
37818275SEric Cheng }
37828275SEric Cheng
37838275SEric Cheng /*
37848275SEric Cheng * Return the properties currently associated with the specified MAC client.
37858275SEric Cheng */
37868275SEric Cheng void
mac_client_get_resources(mac_client_handle_t mch,mac_resource_props_t * mrp)37878275SEric Cheng mac_client_get_resources(mac_client_handle_t mch, mac_resource_props_t *mrp)
37888275SEric Cheng {
37898275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
37908275SEric Cheng mac_resource_props_t *mcip_mrp = MCIP_RESOURCE_PROPS(mcip);
37918275SEric Cheng
37928275SEric Cheng bcopy(mcip_mrp, mrp, sizeof (mac_resource_props_t));
37938275SEric Cheng }
37948275SEric Cheng
37958275SEric Cheng /*
379611878SVenu.Iyer@Sun.COM * Return the effective properties currently associated with the specified
379711878SVenu.Iyer@Sun.COM * MAC client.
379811878SVenu.Iyer@Sun.COM */
379911878SVenu.Iyer@Sun.COM void
mac_client_get_effective_resources(mac_client_handle_t mch,mac_resource_props_t * mrp)380011878SVenu.Iyer@Sun.COM mac_client_get_effective_resources(mac_client_handle_t mch,
380111878SVenu.Iyer@Sun.COM mac_resource_props_t *mrp)
380211878SVenu.Iyer@Sun.COM {
380311878SVenu.Iyer@Sun.COM mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
380411878SVenu.Iyer@Sun.COM mac_resource_props_t *mcip_mrp = MCIP_EFFECTIVE_PROPS(mcip);
380511878SVenu.Iyer@Sun.COM
380611878SVenu.Iyer@Sun.COM bcopy(mcip_mrp, mrp, sizeof (mac_resource_props_t));
380711878SVenu.Iyer@Sun.COM }
380811878SVenu.Iyer@Sun.COM
380911878SVenu.Iyer@Sun.COM /*
38108275SEric Cheng * Pass a copy of the specified packet to the promiscuous callbacks
38118275SEric Cheng * of the specified MAC.
38128275SEric Cheng *
38138275SEric Cheng * If sender is NULL, the function is being invoked for a packet chain
38148275SEric Cheng * received from the wire. If sender is non-NULL, it points to
38158275SEric Cheng * the MAC client from which the packet is being sent.
38168275SEric Cheng *
38178275SEric Cheng * The packets are distributed to the promiscuous callbacks as follows:
38188275SEric Cheng *
38198275SEric Cheng * - all packets are sent to the MAC_CLIENT_PROMISC_ALL callbacks
38208275SEric Cheng * - all broadcast and multicast packets are sent to the
38218275SEric Cheng * MAC_CLIENT_PROMISC_FILTER and MAC_CLIENT_PROMISC_MULTI.
38228275SEric Cheng *
38238275SEric Cheng * The unicast packets of MAC_CLIENT_PROMISC_FILTER callbacks are dispatched
38248275SEric Cheng * after classification by mac_rx_deliver().
38258275SEric Cheng */
38268275SEric Cheng
38278275SEric Cheng static void
mac_promisc_dispatch_one(mac_promisc_impl_t * mpip,mblk_t * mp,boolean_t loopback)38288275SEric Cheng mac_promisc_dispatch_one(mac_promisc_impl_t *mpip, mblk_t *mp,
38298275SEric Cheng boolean_t loopback)
38308275SEric Cheng {
383110639SDarren.Reed@Sun.COM mblk_t *mp_copy, *mp_next;
383210639SDarren.Reed@Sun.COM
383310639SDarren.Reed@Sun.COM if (!mpip->mpi_no_copy || mpip->mpi_strip_vlan_tag) {
383410639SDarren.Reed@Sun.COM mp_copy = copymsg(mp);
383510639SDarren.Reed@Sun.COM if (mp_copy == NULL)
383610639SDarren.Reed@Sun.COM return;
383710639SDarren.Reed@Sun.COM
383810639SDarren.Reed@Sun.COM if (mpip->mpi_strip_vlan_tag) {
383910639SDarren.Reed@Sun.COM mp_copy = mac_strip_vlan_tag_chain(mp_copy);
384010639SDarren.Reed@Sun.COM if (mp_copy == NULL)
384110639SDarren.Reed@Sun.COM return;
384210639SDarren.Reed@Sun.COM }
384310639SDarren.Reed@Sun.COM mp_next = NULL;
384410639SDarren.Reed@Sun.COM } else {
384510639SDarren.Reed@Sun.COM mp_copy = mp;
384610639SDarren.Reed@Sun.COM mp_next = mp->b_next;
384710639SDarren.Reed@Sun.COM }
38488275SEric Cheng mp_copy->b_next = NULL;
38498275SEric Cheng
38508275SEric Cheng mpip->mpi_fn(mpip->mpi_arg, NULL, mp_copy, loopback);
385110639SDarren.Reed@Sun.COM if (mp_copy == mp)
385210639SDarren.Reed@Sun.COM mp->b_next = mp_next;
38538275SEric Cheng }
38548275SEric Cheng
38558275SEric Cheng /*
38568275SEric Cheng * Return the VID of a packet. Zero if the packet is not tagged.
38578275SEric Cheng */
38588275SEric Cheng static uint16_t
mac_ether_vid(mblk_t * mp)38598275SEric Cheng mac_ether_vid(mblk_t *mp)
38608275SEric Cheng {
38618275SEric Cheng struct ether_header *eth = (struct ether_header *)mp->b_rptr;
38628275SEric Cheng
38638275SEric Cheng if (ntohs(eth->ether_type) == ETHERTYPE_VLAN) {
38648275SEric Cheng struct ether_vlan_header *t_evhp =
38658275SEric Cheng (struct ether_vlan_header *)mp->b_rptr;
38668275SEric Cheng return (VLAN_ID(ntohs(t_evhp->ether_tci)));
38678275SEric Cheng }
38688275SEric Cheng
38698275SEric Cheng return (0);
38708275SEric Cheng }
38718275SEric Cheng
38728275SEric Cheng /*
38738275SEric Cheng * Return whether the specified packet contains a multicast or broadcast
38748275SEric Cheng * destination MAC address.
38758275SEric Cheng */
38768275SEric Cheng static boolean_t
mac_is_mcast(mac_impl_t * mip,mblk_t * mp)38778275SEric Cheng mac_is_mcast(mac_impl_t *mip, mblk_t *mp)
38788275SEric Cheng {
38798275SEric Cheng mac_header_info_t hdr_info;
38808275SEric Cheng
38818275SEric Cheng if (mac_header_info((mac_handle_t)mip, mp, &hdr_info) != 0)
38828275SEric Cheng return (B_FALSE);
38838275SEric Cheng return ((hdr_info.mhi_dsttype == MAC_ADDRTYPE_BROADCAST) ||
38848275SEric Cheng (hdr_info.mhi_dsttype == MAC_ADDRTYPE_MULTICAST));
38858275SEric Cheng }
38868275SEric Cheng
38878275SEric Cheng /*
38888275SEric Cheng * Send a copy of an mblk chain to the MAC clients of the specified MAC.
38898275SEric Cheng * "sender" points to the sender MAC client for outbound packets, and
38908275SEric Cheng * is set to NULL for inbound packets.
38918275SEric Cheng */
38928275SEric Cheng void
mac_promisc_dispatch(mac_impl_t * mip,mblk_t * mp_chain,mac_client_impl_t * sender)38938275SEric Cheng mac_promisc_dispatch(mac_impl_t *mip, mblk_t *mp_chain,
38948275SEric Cheng mac_client_impl_t *sender)
38958275SEric Cheng {
38968275SEric Cheng mac_promisc_impl_t *mpip;
38978275SEric Cheng mac_cb_t *mcb;
38988275SEric Cheng mblk_t *mp;
38998275SEric Cheng boolean_t is_mcast, is_sender;
39008275SEric Cheng
39018275SEric Cheng MAC_PROMISC_WALKER_INC(mip);
39028275SEric Cheng for (mp = mp_chain; mp != NULL; mp = mp->b_next) {
39038275SEric Cheng is_mcast = mac_is_mcast(mip, mp);
39048275SEric Cheng /* send packet to interested callbacks */
39058275SEric Cheng for (mcb = mip->mi_promisc_list; mcb != NULL;
39068275SEric Cheng mcb = mcb->mcb_nextp) {
39078275SEric Cheng mpip = (mac_promisc_impl_t *)mcb->mcb_objp;
39088275SEric Cheng is_sender = (mpip->mpi_mcip == sender);
39098275SEric Cheng
39108275SEric Cheng if (is_sender && mpip->mpi_no_tx_loop)
39118275SEric Cheng /*
39128275SEric Cheng * The sender doesn't want to receive
39138275SEric Cheng * copies of the packets it sends.
39148275SEric Cheng */
39158275SEric Cheng continue;
39168275SEric Cheng
391710491SRishi.Srivatsavai@Sun.COM /* this client doesn't need any packets (bridge) */
391810491SRishi.Srivatsavai@Sun.COM if (mpip->mpi_fn == NULL)
391910491SRishi.Srivatsavai@Sun.COM continue;
392010491SRishi.Srivatsavai@Sun.COM
39218275SEric Cheng /*
39228275SEric Cheng * For an ethernet MAC, don't displatch a multicast
39238275SEric Cheng * packet to a non-PROMISC_ALL callbacks unless the VID
39248275SEric Cheng * of the packet matches the VID of the client.
39258275SEric Cheng */
39268275SEric Cheng if (is_mcast &&
39278275SEric Cheng mpip->mpi_type != MAC_CLIENT_PROMISC_ALL &&
39288275SEric Cheng !mac_client_check_flow_vid(mpip->mpi_mcip,
39298275SEric Cheng mac_ether_vid(mp)))
39308275SEric Cheng continue;
39318275SEric Cheng
39328275SEric Cheng if (is_sender ||
39338275SEric Cheng mpip->mpi_type == MAC_CLIENT_PROMISC_ALL ||
39348275SEric Cheng is_mcast)
39358275SEric Cheng mac_promisc_dispatch_one(mpip, mp, is_sender);
39368275SEric Cheng }
39378275SEric Cheng }
39388275SEric Cheng MAC_PROMISC_WALKER_DCR(mip);
39398275SEric Cheng }
39408275SEric Cheng
39418275SEric Cheng void
mac_promisc_client_dispatch(mac_client_impl_t * mcip,mblk_t * mp_chain)39428275SEric Cheng mac_promisc_client_dispatch(mac_client_impl_t *mcip, mblk_t *mp_chain)
39438275SEric Cheng {
39448275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
39458275SEric Cheng mac_promisc_impl_t *mpip;
39468275SEric Cheng boolean_t is_mcast;
39478275SEric Cheng mblk_t *mp;
39488275SEric Cheng mac_cb_t *mcb;
39498275SEric Cheng
39508275SEric Cheng /*
39518275SEric Cheng * The unicast packets for the MAC client still
39528275SEric Cheng * need to be delivered to the MAC_CLIENT_PROMISC_FILTERED
39538275SEric Cheng * promiscuous callbacks. The broadcast and multicast
39548275SEric Cheng * packets were delivered from mac_rx().
39558275SEric Cheng */
39568275SEric Cheng MAC_PROMISC_WALKER_INC(mip);
39578275SEric Cheng for (mp = mp_chain; mp != NULL; mp = mp->b_next) {
39588275SEric Cheng is_mcast = mac_is_mcast(mip, mp);
39598275SEric Cheng for (mcb = mcip->mci_promisc_list; mcb != NULL;
39608275SEric Cheng mcb = mcb->mcb_nextp) {
39618275SEric Cheng mpip = (mac_promisc_impl_t *)mcb->mcb_objp;
39628275SEric Cheng if (mpip->mpi_type == MAC_CLIENT_PROMISC_FILTERED &&
39638275SEric Cheng !is_mcast) {
39648275SEric Cheng mac_promisc_dispatch_one(mpip, mp, B_FALSE);
39658275SEric Cheng }
39668275SEric Cheng }
39678275SEric Cheng }
39688275SEric Cheng MAC_PROMISC_WALKER_DCR(mip);
39698275SEric Cheng }
39708275SEric Cheng
39718275SEric Cheng /*
39728275SEric Cheng * Return the margin value currently assigned to the specified MAC instance.
39738275SEric Cheng */
39748275SEric Cheng void
mac_margin_get(mac_handle_t mh,uint32_t * marginp)39758275SEric Cheng mac_margin_get(mac_handle_t mh, uint32_t *marginp)
39768275SEric Cheng {
39778275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
39788275SEric Cheng
39798275SEric Cheng rw_enter(&(mip->mi_rw_lock), RW_READER);
39808275SEric Cheng *marginp = mip->mi_margin;
39818275SEric Cheng rw_exit(&(mip->mi_rw_lock));
39828275SEric Cheng }
39838275SEric Cheng
39848275SEric Cheng /*
39858275SEric Cheng * mac_info_get() is used for retrieving the mac_info when a DL_INFO_REQ is
39868275SEric Cheng * issued before a DL_ATTACH_REQ. we walk the i_mac_impl_hash table and find
39878275SEric Cheng * the first mac_impl_t with a matching driver name; then we copy its mac_info_t
39888275SEric Cheng * to the caller. we do all this with i_mac_impl_lock held so the mac_impl_t
39898275SEric Cheng * cannot disappear while we are accessing it.
39908275SEric Cheng */
39918275SEric Cheng typedef struct i_mac_info_state_s {
39928275SEric Cheng const char *mi_name;
39938275SEric Cheng mac_info_t *mi_infop;
39948275SEric Cheng } i_mac_info_state_t;
39958275SEric Cheng
39968275SEric Cheng /*ARGSUSED*/
39978275SEric Cheng static uint_t
i_mac_info_walker(mod_hash_key_t key,mod_hash_val_t * val,void * arg)39988275SEric Cheng i_mac_info_walker(mod_hash_key_t key, mod_hash_val_t *val, void *arg)
39998275SEric Cheng {
40008275SEric Cheng i_mac_info_state_t *statep = arg;
40018275SEric Cheng mac_impl_t *mip = (mac_impl_t *)val;
40028275SEric Cheng
40038275SEric Cheng if (mip->mi_state_flags & MIS_DISABLED)
40048275SEric Cheng return (MH_WALK_CONTINUE);
40058275SEric Cheng
40068275SEric Cheng if (strcmp(statep->mi_name,
40078275SEric Cheng ddi_driver_name(mip->mi_dip)) != 0)
40088275SEric Cheng return (MH_WALK_CONTINUE);
40098275SEric Cheng
40108275SEric Cheng statep->mi_infop = &mip->mi_info;
40118275SEric Cheng return (MH_WALK_TERMINATE);
40128275SEric Cheng }
40138275SEric Cheng
40148275SEric Cheng boolean_t
mac_info_get(const char * name,mac_info_t * minfop)40158275SEric Cheng mac_info_get(const char *name, mac_info_t *minfop)
40168275SEric Cheng {
40178275SEric Cheng i_mac_info_state_t state;
40188275SEric Cheng
40198275SEric Cheng rw_enter(&i_mac_impl_lock, RW_READER);
40208275SEric Cheng state.mi_name = name;
40218275SEric Cheng state.mi_infop = NULL;
40228275SEric Cheng mod_hash_walk(i_mac_impl_hash, i_mac_info_walker, &state);
40238275SEric Cheng if (state.mi_infop == NULL) {
40248275SEric Cheng rw_exit(&i_mac_impl_lock);
40258275SEric Cheng return (B_FALSE);
40268275SEric Cheng }
40278275SEric Cheng *minfop = *state.mi_infop;
40288275SEric Cheng rw_exit(&i_mac_impl_lock);
40298275SEric Cheng return (B_TRUE);
40308275SEric Cheng }
40318275SEric Cheng
40328275SEric Cheng /*
40338275SEric Cheng * To get the capabilities that MAC layer cares about, such as rings, factory
403410491SRishi.Srivatsavai@Sun.COM * mac address, vnic or not, it should directly invoke this function. If the
403510491SRishi.Srivatsavai@Sun.COM * link is part of a bridge, then the only "capability" it has is the inability
403610491SRishi.Srivatsavai@Sun.COM * to do zero copy.
40378275SEric Cheng */
40388275SEric Cheng boolean_t
i_mac_capab_get(mac_handle_t mh,mac_capab_t cap,void * cap_data)40398275SEric Cheng i_mac_capab_get(mac_handle_t mh, mac_capab_t cap, void *cap_data)
40408275SEric Cheng {
40418275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
40428275SEric Cheng
404310491SRishi.Srivatsavai@Sun.COM if (mip->mi_bridge_link != NULL)
404410491SRishi.Srivatsavai@Sun.COM return (cap == MAC_CAPAB_NO_ZCOPY);
404510491SRishi.Srivatsavai@Sun.COM else if (mip->mi_callbacks->mc_callbacks & MC_GETCAPAB)
40468275SEric Cheng return (mip->mi_getcapab(mip->mi_driver, cap, cap_data));
40478275SEric Cheng else
40488275SEric Cheng return (B_FALSE);
40498275SEric Cheng }
40508275SEric Cheng
40518275SEric Cheng /*
40528275SEric Cheng * Capability query function. If number of active mac clients is greater than
40538275SEric Cheng * 1, only limited capabilities can be advertised to the caller no matter the
40548275SEric Cheng * driver has certain capability or not. Else, we query the driver to get the
40558275SEric Cheng * capability.
40568275SEric Cheng */
40578275SEric Cheng boolean_t
mac_capab_get(mac_handle_t mh,mac_capab_t cap,void * cap_data)40588275SEric Cheng mac_capab_get(mac_handle_t mh, mac_capab_t cap, void *cap_data)
40598275SEric Cheng {
40608275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
40618275SEric Cheng
40628275SEric Cheng /*
40639073SCathy.Zhou@Sun.COM * if mi_nactiveclients > 1, only MAC_CAPAB_LEGACY, MAC_CAPAB_HCKSUM,
40649073SCathy.Zhou@Sun.COM * MAC_CAPAB_NO_NATIVEVLAN and MAC_CAPAB_NO_ZCOPY can be advertised.
40658275SEric Cheng */
40668275SEric Cheng if (mip->mi_nactiveclients > 1) {
40678275SEric Cheng switch (cap) {
40688275SEric Cheng case MAC_CAPAB_NO_ZCOPY:
40698275SEric Cheng return (B_TRUE);
40709073SCathy.Zhou@Sun.COM case MAC_CAPAB_LEGACY:
40719073SCathy.Zhou@Sun.COM case MAC_CAPAB_HCKSUM:
407212325SCathy.Zhou@Sun.COM case MAC_CAPAB_NO_NATIVEVLAN:
40739073SCathy.Zhou@Sun.COM break;
40748275SEric Cheng default:
40758275SEric Cheng return (B_FALSE);
40768275SEric Cheng }
40778275SEric Cheng }
40788275SEric Cheng
40798275SEric Cheng /* else get capab from driver */
40808275SEric Cheng return (i_mac_capab_get(mh, cap, cap_data));
40818275SEric Cheng }
40828275SEric Cheng
40838275SEric Cheng boolean_t
mac_sap_verify(mac_handle_t mh,uint32_t sap,uint32_t * bind_sap)40848275SEric Cheng mac_sap_verify(mac_handle_t mh, uint32_t sap, uint32_t *bind_sap)
40858275SEric Cheng {
40868275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
40878275SEric Cheng
40888275SEric Cheng return (mip->mi_type->mt_ops.mtops_sap_verify(sap, bind_sap,
40898275SEric Cheng mip->mi_pdata));
40908275SEric Cheng }
40918275SEric Cheng
40928275SEric Cheng mblk_t *
mac_header(mac_handle_t mh,const uint8_t * daddr,uint32_t sap,mblk_t * payload,size_t extra_len)40938275SEric Cheng mac_header(mac_handle_t mh, const uint8_t *daddr, uint32_t sap, mblk_t *payload,
40948275SEric Cheng size_t extra_len)
40958275SEric Cheng {
409610616SSebastien.Roy@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
409710616SSebastien.Roy@Sun.COM const uint8_t *hdr_daddr;
409810616SSebastien.Roy@Sun.COM
409910616SSebastien.Roy@Sun.COM /*
410010616SSebastien.Roy@Sun.COM * If the MAC is point-to-point with a fixed destination address, then
410110616SSebastien.Roy@Sun.COM * we must always use that destination in the MAC header.
410210616SSebastien.Roy@Sun.COM */
410310616SSebastien.Roy@Sun.COM hdr_daddr = (mip->mi_dstaddr_set ? mip->mi_dstaddr : daddr);
410410616SSebastien.Roy@Sun.COM return (mip->mi_type->mt_ops.mtops_header(mip->mi_addr, hdr_daddr, sap,
41058275SEric Cheng mip->mi_pdata, payload, extra_len));
41068275SEric Cheng }
41078275SEric Cheng
41088275SEric Cheng int
mac_header_info(mac_handle_t mh,mblk_t * mp,mac_header_info_t * mhip)41098275SEric Cheng mac_header_info(mac_handle_t mh, mblk_t *mp, mac_header_info_t *mhip)
41108275SEric Cheng {
41118275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
41128275SEric Cheng
41138275SEric Cheng return (mip->mi_type->mt_ops.mtops_header_info(mp, mip->mi_pdata,
41148275SEric Cheng mhip));
41158275SEric Cheng }
41168275SEric Cheng
411710734SEric Cheng int
mac_vlan_header_info(mac_handle_t mh,mblk_t * mp,mac_header_info_t * mhip)411810734SEric Cheng mac_vlan_header_info(mac_handle_t mh, mblk_t *mp, mac_header_info_t *mhip)
411910734SEric Cheng {
412010734SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
412110734SEric Cheng boolean_t is_ethernet = (mip->mi_info.mi_media == DL_ETHER);
412210734SEric Cheng int err = 0;
412310734SEric Cheng
412410734SEric Cheng /*
412510734SEric Cheng * Packets should always be at least 16 bit aligned.
412610734SEric Cheng */
412710734SEric Cheng ASSERT(IS_P2ALIGNED(mp->b_rptr, sizeof (uint16_t)));
412810734SEric Cheng
412910734SEric Cheng if ((err = mac_header_info(mh, mp, mhip)) != 0)
413010734SEric Cheng return (err);
413110734SEric Cheng
413210734SEric Cheng /*
413310734SEric Cheng * If this is a VLAN-tagged Ethernet packet, then the SAP in the
413410734SEric Cheng * mac_header_info_t as returned by mac_header_info() is
413510734SEric Cheng * ETHERTYPE_VLAN. We need to grab the ethertype from the VLAN header.
413610734SEric Cheng */
413710734SEric Cheng if (is_ethernet && (mhip->mhi_bindsap == ETHERTYPE_VLAN)) {
413810734SEric Cheng struct ether_vlan_header *evhp;
413910734SEric Cheng uint16_t sap;
414010734SEric Cheng mblk_t *tmp = NULL;
414110734SEric Cheng size_t size;
414210734SEric Cheng
414310734SEric Cheng size = sizeof (struct ether_vlan_header);
414410734SEric Cheng if (MBLKL(mp) < size) {
414510734SEric Cheng /*
414610734SEric Cheng * Pullup the message in order to get the MAC header
414710734SEric Cheng * infomation. Note that this is a read-only function,
414810734SEric Cheng * we keep the input packet intact.
414910734SEric Cheng */
415010734SEric Cheng if ((tmp = msgpullup(mp, size)) == NULL)
415110734SEric Cheng return (EINVAL);
415210734SEric Cheng
415310734SEric Cheng mp = tmp;
415410734SEric Cheng }
415510734SEric Cheng evhp = (struct ether_vlan_header *)mp->b_rptr;
415610734SEric Cheng sap = ntohs(evhp->ether_type);
415710734SEric Cheng (void) mac_sap_verify(mh, sap, &mhip->mhi_bindsap);
415810734SEric Cheng mhip->mhi_hdrsize = sizeof (struct ether_vlan_header);
415910734SEric Cheng mhip->mhi_tci = ntohs(evhp->ether_tci);
416010734SEric Cheng mhip->mhi_istagged = B_TRUE;
416110734SEric Cheng freemsg(tmp);
416210734SEric Cheng
416310734SEric Cheng if (VLAN_CFI(mhip->mhi_tci) != ETHER_CFI)
416410734SEric Cheng return (EINVAL);
416510734SEric Cheng } else {
416610734SEric Cheng mhip->mhi_istagged = B_FALSE;
416710734SEric Cheng mhip->mhi_tci = 0;
416810734SEric Cheng }
416910734SEric Cheng
417010734SEric Cheng return (0);
417110734SEric Cheng }
417210734SEric Cheng
41738275SEric Cheng mblk_t *
mac_header_cook(mac_handle_t mh,mblk_t * mp)41748275SEric Cheng mac_header_cook(mac_handle_t mh, mblk_t *mp)
41758275SEric Cheng {
41768275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
41778275SEric Cheng
41788275SEric Cheng if (mip->mi_type->mt_ops.mtops_ops & MTOPS_HEADER_COOK) {
41798275SEric Cheng if (DB_REF(mp) > 1) {
41808275SEric Cheng mblk_t *newmp = copymsg(mp);
41818275SEric Cheng if (newmp == NULL)
41828275SEric Cheng return (NULL);
41838275SEric Cheng freemsg(mp);
41848275SEric Cheng mp = newmp;
41858275SEric Cheng }
41868275SEric Cheng return (mip->mi_type->mt_ops.mtops_header_cook(mp,
41878275SEric Cheng mip->mi_pdata));
41888275SEric Cheng }
41898275SEric Cheng return (mp);
41908275SEric Cheng }
41918275SEric Cheng
41928275SEric Cheng mblk_t *
mac_header_uncook(mac_handle_t mh,mblk_t * mp)41938275SEric Cheng mac_header_uncook(mac_handle_t mh, mblk_t *mp)
41948275SEric Cheng {
41958275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
41968275SEric Cheng
41978275SEric Cheng if (mip->mi_type->mt_ops.mtops_ops & MTOPS_HEADER_UNCOOK) {
41988275SEric Cheng if (DB_REF(mp) > 1) {
41998275SEric Cheng mblk_t *newmp = copymsg(mp);
42008275SEric Cheng if (newmp == NULL)
42018275SEric Cheng return (NULL);
42028275SEric Cheng freemsg(mp);
42038275SEric Cheng mp = newmp;
42048275SEric Cheng }
42058275SEric Cheng return (mip->mi_type->mt_ops.mtops_header_uncook(mp,
42068275SEric Cheng mip->mi_pdata));
42078275SEric Cheng }
42088275SEric Cheng return (mp);
42098275SEric Cheng }
42108275SEric Cheng
42118275SEric Cheng uint_t
mac_addr_len(mac_handle_t mh)42128275SEric Cheng mac_addr_len(mac_handle_t mh)
42138275SEric Cheng {
42148275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
42158275SEric Cheng
42168275SEric Cheng return (mip->mi_type->mt_addr_length);
42178275SEric Cheng }
42188275SEric Cheng
42198275SEric Cheng /* True if a MAC is a VNIC */
42208275SEric Cheng boolean_t
mac_is_vnic(mac_handle_t mh)42218275SEric Cheng mac_is_vnic(mac_handle_t mh)
42228275SEric Cheng {
42238275SEric Cheng return (((mac_impl_t *)mh)->mi_state_flags & MIS_IS_VNIC);
42248275SEric Cheng }
42258275SEric Cheng
42268275SEric Cheng mac_handle_t
mac_get_lower_mac_handle(mac_handle_t mh)42278275SEric Cheng mac_get_lower_mac_handle(mac_handle_t mh)
42288275SEric Cheng {
42298275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
42308275SEric Cheng
42318275SEric Cheng ASSERT(mac_is_vnic(mh));
42328275SEric Cheng return (((vnic_t *)mip->mi_driver)->vn_lower_mh);
42338275SEric Cheng }
42348275SEric Cheng
423511878SVenu.Iyer@Sun.COM boolean_t
mac_is_vnic_primary(mac_handle_t mh)423611878SVenu.Iyer@Sun.COM mac_is_vnic_primary(mac_handle_t mh)
423711878SVenu.Iyer@Sun.COM {
423811878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
423911878SVenu.Iyer@Sun.COM
424011878SVenu.Iyer@Sun.COM ASSERT(mac_is_vnic(mh));
424111878SVenu.Iyer@Sun.COM return (((vnic_t *)mip->mi_driver)->vn_addr_type ==
424211878SVenu.Iyer@Sun.COM VNIC_MAC_ADDR_TYPE_PRIMARY);
424311878SVenu.Iyer@Sun.COM }
424411878SVenu.Iyer@Sun.COM
42458275SEric Cheng void
mac_update_resources(mac_resource_props_t * nmrp,mac_resource_props_t * cmrp,boolean_t is_user_flow)42468275SEric Cheng mac_update_resources(mac_resource_props_t *nmrp, mac_resource_props_t *cmrp,
42478275SEric Cheng boolean_t is_user_flow)
42488275SEric Cheng {
42498275SEric Cheng if (nmrp != NULL && cmrp != NULL) {
42508275SEric Cheng if (nmrp->mrp_mask & MRP_PRIORITY) {
42518275SEric Cheng if (nmrp->mrp_priority == MPL_RESET) {
42528275SEric Cheng cmrp->mrp_mask &= ~MRP_PRIORITY;
42538275SEric Cheng if (is_user_flow) {
42548275SEric Cheng cmrp->mrp_priority =
42558275SEric Cheng MPL_SUBFLOW_DEFAULT;
42568275SEric Cheng } else {
42578275SEric Cheng cmrp->mrp_priority = MPL_LINK_DEFAULT;
42588275SEric Cheng }
42598275SEric Cheng } else {
42608275SEric Cheng cmrp->mrp_mask |= MRP_PRIORITY;
42618275SEric Cheng cmrp->mrp_priority = nmrp->mrp_priority;
42628275SEric Cheng }
42638275SEric Cheng }
42648275SEric Cheng if (nmrp->mrp_mask & MRP_MAXBW) {
426511878SVenu.Iyer@Sun.COM if (nmrp->mrp_maxbw == MRP_MAXBW_RESETVAL) {
42668275SEric Cheng cmrp->mrp_mask &= ~MRP_MAXBW;
426711878SVenu.Iyer@Sun.COM cmrp->mrp_maxbw = 0;
426811878SVenu.Iyer@Sun.COM } else {
42698275SEric Cheng cmrp->mrp_mask |= MRP_MAXBW;
427011878SVenu.Iyer@Sun.COM cmrp->mrp_maxbw = nmrp->mrp_maxbw;
427111878SVenu.Iyer@Sun.COM }
42728275SEric Cheng }
42738275SEric Cheng if (nmrp->mrp_mask & MRP_CPUS)
42748275SEric Cheng MAC_COPY_CPUS(nmrp, cmrp);
427510734SEric Cheng
427611878SVenu.Iyer@Sun.COM if (nmrp->mrp_mask & MRP_POOL) {
427711878SVenu.Iyer@Sun.COM if (strlen(nmrp->mrp_pool) == 0) {
427811878SVenu.Iyer@Sun.COM cmrp->mrp_mask &= ~MRP_POOL;
427911878SVenu.Iyer@Sun.COM bzero(cmrp->mrp_pool, sizeof (cmrp->mrp_pool));
428011878SVenu.Iyer@Sun.COM } else {
428111878SVenu.Iyer@Sun.COM cmrp->mrp_mask |= MRP_POOL;
428211878SVenu.Iyer@Sun.COM (void) strncpy(cmrp->mrp_pool, nmrp->mrp_pool,
428311878SVenu.Iyer@Sun.COM sizeof (cmrp->mrp_pool));
428411878SVenu.Iyer@Sun.COM }
428511878SVenu.Iyer@Sun.COM
428611878SVenu.Iyer@Sun.COM }
428711878SVenu.Iyer@Sun.COM
428810734SEric Cheng if (nmrp->mrp_mask & MRP_PROTECT)
428910734SEric Cheng mac_protect_update(nmrp, cmrp);
429011878SVenu.Iyer@Sun.COM
429111878SVenu.Iyer@Sun.COM /*
429211878SVenu.Iyer@Sun.COM * Update the rings specified.
429311878SVenu.Iyer@Sun.COM */
429411878SVenu.Iyer@Sun.COM if (nmrp->mrp_mask & MRP_RX_RINGS) {
429511878SVenu.Iyer@Sun.COM if (nmrp->mrp_mask & MRP_RINGS_RESET) {
429611878SVenu.Iyer@Sun.COM cmrp->mrp_mask &= ~MRP_RX_RINGS;
429711878SVenu.Iyer@Sun.COM if (cmrp->mrp_mask & MRP_RXRINGS_UNSPEC)
429811878SVenu.Iyer@Sun.COM cmrp->mrp_mask &= ~MRP_RXRINGS_UNSPEC;
429911878SVenu.Iyer@Sun.COM cmrp->mrp_nrxrings = 0;
430011878SVenu.Iyer@Sun.COM } else {
430111878SVenu.Iyer@Sun.COM cmrp->mrp_mask |= MRP_RX_RINGS;
430211878SVenu.Iyer@Sun.COM cmrp->mrp_nrxrings = nmrp->mrp_nrxrings;
430311878SVenu.Iyer@Sun.COM }
430411878SVenu.Iyer@Sun.COM }
430511878SVenu.Iyer@Sun.COM if (nmrp->mrp_mask & MRP_TX_RINGS) {
430611878SVenu.Iyer@Sun.COM if (nmrp->mrp_mask & MRP_RINGS_RESET) {
430711878SVenu.Iyer@Sun.COM cmrp->mrp_mask &= ~MRP_TX_RINGS;
430811878SVenu.Iyer@Sun.COM if (cmrp->mrp_mask & MRP_TXRINGS_UNSPEC)
430911878SVenu.Iyer@Sun.COM cmrp->mrp_mask &= ~MRP_TXRINGS_UNSPEC;
431011878SVenu.Iyer@Sun.COM cmrp->mrp_ntxrings = 0;
431111878SVenu.Iyer@Sun.COM } else {
431211878SVenu.Iyer@Sun.COM cmrp->mrp_mask |= MRP_TX_RINGS;
431311878SVenu.Iyer@Sun.COM cmrp->mrp_ntxrings = nmrp->mrp_ntxrings;
431411878SVenu.Iyer@Sun.COM }
431511878SVenu.Iyer@Sun.COM }
431611878SVenu.Iyer@Sun.COM if (nmrp->mrp_mask & MRP_RXRINGS_UNSPEC)
431711878SVenu.Iyer@Sun.COM cmrp->mrp_mask |= MRP_RXRINGS_UNSPEC;
431811878SVenu.Iyer@Sun.COM else if (cmrp->mrp_mask & MRP_RXRINGS_UNSPEC)
431911878SVenu.Iyer@Sun.COM cmrp->mrp_mask &= ~MRP_RXRINGS_UNSPEC;
432011878SVenu.Iyer@Sun.COM
432111878SVenu.Iyer@Sun.COM if (nmrp->mrp_mask & MRP_TXRINGS_UNSPEC)
432211878SVenu.Iyer@Sun.COM cmrp->mrp_mask |= MRP_TXRINGS_UNSPEC;
432311878SVenu.Iyer@Sun.COM else if (cmrp->mrp_mask & MRP_TXRINGS_UNSPEC)
432411878SVenu.Iyer@Sun.COM cmrp->mrp_mask &= ~MRP_TXRINGS_UNSPEC;
43258275SEric Cheng }
43268275SEric Cheng }
43278275SEric Cheng
43288275SEric Cheng /*
43298275SEric Cheng * i_mac_set_resources:
43308275SEric Cheng *
43318275SEric Cheng * This routine associates properties with the primary MAC client of
43328275SEric Cheng * the specified MAC instance.
43338275SEric Cheng * - Cache the properties in mac_impl_t
43348275SEric Cheng * - Apply the properties to the primary MAC client if exists
43358275SEric Cheng */
43368275SEric Cheng int
i_mac_set_resources(mac_handle_t mh,mac_resource_props_t * mrp)43378275SEric Cheng i_mac_set_resources(mac_handle_t mh, mac_resource_props_t *mrp)
43388275SEric Cheng {
43398275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
43408275SEric Cheng mac_client_impl_t *mcip;
43418275SEric Cheng int err = 0;
43429073SCathy.Zhou@Sun.COM uint32_t resmask, newresmask;
434311878SVenu.Iyer@Sun.COM mac_resource_props_t *tmrp, *umrp;
43448275SEric Cheng
43458275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
43468275SEric Cheng
434711878SVenu.Iyer@Sun.COM err = mac_validate_props(mip, mrp);
43488275SEric Cheng if (err != 0)
43498275SEric Cheng return (err);
43508275SEric Cheng
435111878SVenu.Iyer@Sun.COM umrp = kmem_zalloc(sizeof (*umrp), KM_SLEEP);
435211878SVenu.Iyer@Sun.COM bcopy(&mip->mi_resource_props, umrp, sizeof (*umrp));
435311878SVenu.Iyer@Sun.COM resmask = umrp->mrp_mask;
435411878SVenu.Iyer@Sun.COM mac_update_resources(mrp, umrp, B_FALSE);
435511878SVenu.Iyer@Sun.COM newresmask = umrp->mrp_mask;
43569073SCathy.Zhou@Sun.COM
43579073SCathy.Zhou@Sun.COM if (resmask == 0 && newresmask != 0) {
43589073SCathy.Zhou@Sun.COM /*
435911878SVenu.Iyer@Sun.COM * Bandwidth, priority, cpu or pool link properties configured,
43609073SCathy.Zhou@Sun.COM * must disable fastpath.
43619073SCathy.Zhou@Sun.COM */
436211878SVenu.Iyer@Sun.COM if ((err = mac_fastpath_disable((mac_handle_t)mip)) != 0) {
436311878SVenu.Iyer@Sun.COM kmem_free(umrp, sizeof (*umrp));
43649073SCathy.Zhou@Sun.COM return (err);
436511878SVenu.Iyer@Sun.COM }
43669073SCathy.Zhou@Sun.COM }
43679073SCathy.Zhou@Sun.COM
43688275SEric Cheng /*
43698275SEric Cheng * Since bind_cpu may be modified by mac_client_set_resources()
43708275SEric Cheng * we use a copy of bind_cpu and finally cache bind_cpu in mip.
43718275SEric Cheng * This allows us to cache only user edits in mip.
43728275SEric Cheng */
437311878SVenu.Iyer@Sun.COM tmrp = kmem_zalloc(sizeof (*tmrp), KM_SLEEP);
437411878SVenu.Iyer@Sun.COM bcopy(mrp, tmrp, sizeof (*tmrp));
43758275SEric Cheng mcip = mac_primary_client_handle(mip);
43768833SVenu.Iyer@Sun.COM if (mcip != NULL && (mcip->mci_state_flags & MCIS_IS_AGGR_PORT) == 0) {
437711878SVenu.Iyer@Sun.COM err = mac_client_set_resources((mac_client_handle_t)mcip, tmrp);
437811878SVenu.Iyer@Sun.COM } else if ((mrp->mrp_mask & MRP_RX_RINGS ||
437911878SVenu.Iyer@Sun.COM mrp->mrp_mask & MRP_TX_RINGS)) {
438011878SVenu.Iyer@Sun.COM mac_client_impl_t *vmcip;
438111878SVenu.Iyer@Sun.COM
438211878SVenu.Iyer@Sun.COM /*
438311878SVenu.Iyer@Sun.COM * If the primary is not up, we need to check if there
438411878SVenu.Iyer@Sun.COM * are any VLANs on this primary. If there are then
438511878SVenu.Iyer@Sun.COM * we need to set this property on the VLANs since
438611878SVenu.Iyer@Sun.COM * VLANs follow the primary they are based on. Just
438711878SVenu.Iyer@Sun.COM * look for the first VLAN and change its properties,
438811878SVenu.Iyer@Sun.COM * all the other VLANs should be in the same group.
438911878SVenu.Iyer@Sun.COM */
439011878SVenu.Iyer@Sun.COM for (vmcip = mip->mi_clients_list; vmcip != NULL;
439111878SVenu.Iyer@Sun.COM vmcip = vmcip->mci_client_next) {
439211878SVenu.Iyer@Sun.COM if ((vmcip->mci_flent->fe_type & FLOW_PRIMARY_MAC) &&
439311878SVenu.Iyer@Sun.COM mac_client_vid((mac_client_handle_t)vmcip) !=
439411878SVenu.Iyer@Sun.COM VLAN_ID_NONE) {
439511878SVenu.Iyer@Sun.COM break;
439611878SVenu.Iyer@Sun.COM }
439711878SVenu.Iyer@Sun.COM }
439811878SVenu.Iyer@Sun.COM if (vmcip != NULL) {
439911878SVenu.Iyer@Sun.COM mac_resource_props_t *omrp;
440011878SVenu.Iyer@Sun.COM mac_resource_props_t *vmrp;
440111878SVenu.Iyer@Sun.COM
440211878SVenu.Iyer@Sun.COM omrp = kmem_zalloc(sizeof (*omrp), KM_SLEEP);
440311878SVenu.Iyer@Sun.COM bcopy(MCIP_RESOURCE_PROPS(vmcip), omrp, sizeof (*omrp));
440411878SVenu.Iyer@Sun.COM /*
440511878SVenu.Iyer@Sun.COM * We dont' call mac_update_resources since we
440611878SVenu.Iyer@Sun.COM * want to take only the ring properties and
440711878SVenu.Iyer@Sun.COM * not all the properties that may have changed.
440811878SVenu.Iyer@Sun.COM */
440911878SVenu.Iyer@Sun.COM vmrp = MCIP_RESOURCE_PROPS(vmcip);
441011878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RX_RINGS) {
441111878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RINGS_RESET) {
441211878SVenu.Iyer@Sun.COM vmrp->mrp_mask &= ~MRP_RX_RINGS;
441311878SVenu.Iyer@Sun.COM if (vmrp->mrp_mask &
441411878SVenu.Iyer@Sun.COM MRP_RXRINGS_UNSPEC) {
441511878SVenu.Iyer@Sun.COM vmrp->mrp_mask &=
441611878SVenu.Iyer@Sun.COM ~MRP_RXRINGS_UNSPEC;
441711878SVenu.Iyer@Sun.COM }
441811878SVenu.Iyer@Sun.COM vmrp->mrp_nrxrings = 0;
441911878SVenu.Iyer@Sun.COM } else {
442011878SVenu.Iyer@Sun.COM vmrp->mrp_mask |= MRP_RX_RINGS;
442111878SVenu.Iyer@Sun.COM vmrp->mrp_nrxrings = mrp->mrp_nrxrings;
442211878SVenu.Iyer@Sun.COM }
442311878SVenu.Iyer@Sun.COM }
442411878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_TX_RINGS) {
442511878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RINGS_RESET) {
442611878SVenu.Iyer@Sun.COM vmrp->mrp_mask &= ~MRP_TX_RINGS;
442711878SVenu.Iyer@Sun.COM if (vmrp->mrp_mask &
442811878SVenu.Iyer@Sun.COM MRP_TXRINGS_UNSPEC) {
442911878SVenu.Iyer@Sun.COM vmrp->mrp_mask &=
443011878SVenu.Iyer@Sun.COM ~MRP_TXRINGS_UNSPEC;
443111878SVenu.Iyer@Sun.COM }
443211878SVenu.Iyer@Sun.COM vmrp->mrp_ntxrings = 0;
443311878SVenu.Iyer@Sun.COM } else {
443411878SVenu.Iyer@Sun.COM vmrp->mrp_mask |= MRP_TX_RINGS;
443511878SVenu.Iyer@Sun.COM vmrp->mrp_ntxrings = mrp->mrp_ntxrings;
443611878SVenu.Iyer@Sun.COM }
443711878SVenu.Iyer@Sun.COM }
443811878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RXRINGS_UNSPEC)
443911878SVenu.Iyer@Sun.COM vmrp->mrp_mask |= MRP_RXRINGS_UNSPEC;
444011878SVenu.Iyer@Sun.COM
444111878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_TXRINGS_UNSPEC)
444211878SVenu.Iyer@Sun.COM vmrp->mrp_mask |= MRP_TXRINGS_UNSPEC;
444311878SVenu.Iyer@Sun.COM
444411878SVenu.Iyer@Sun.COM if ((err = mac_client_set_rings_prop(vmcip, mrp,
444511878SVenu.Iyer@Sun.COM omrp)) != 0) {
444611878SVenu.Iyer@Sun.COM bcopy(omrp, MCIP_RESOURCE_PROPS(vmcip),
444711878SVenu.Iyer@Sun.COM sizeof (*omrp));
444811878SVenu.Iyer@Sun.COM } else {
444911878SVenu.Iyer@Sun.COM mac_set_prim_vlan_rings(mip, vmrp);
445011878SVenu.Iyer@Sun.COM }
445111878SVenu.Iyer@Sun.COM kmem_free(omrp, sizeof (*omrp));
445211878SVenu.Iyer@Sun.COM }
44538275SEric Cheng }
44549073SCathy.Zhou@Sun.COM
44559073SCathy.Zhou@Sun.COM /* Only update the values if mac_client_set_resources succeeded */
44569073SCathy.Zhou@Sun.COM if (err == 0) {
445711878SVenu.Iyer@Sun.COM bcopy(umrp, &mip->mi_resource_props, sizeof (*umrp));
44589073SCathy.Zhou@Sun.COM /*
445911878SVenu.Iyer@Sun.COM * If bandwidth, priority or cpu link properties cleared,
44609073SCathy.Zhou@Sun.COM * renable fastpath.
44619073SCathy.Zhou@Sun.COM */
44629073SCathy.Zhou@Sun.COM if (resmask != 0 && newresmask == 0)
44639073SCathy.Zhou@Sun.COM mac_fastpath_enable((mac_handle_t)mip);
44649073SCathy.Zhou@Sun.COM } else if (resmask == 0 && newresmask != 0) {
44659073SCathy.Zhou@Sun.COM mac_fastpath_enable((mac_handle_t)mip);
44669073SCathy.Zhou@Sun.COM }
446711878SVenu.Iyer@Sun.COM kmem_free(tmrp, sizeof (*tmrp));
446811878SVenu.Iyer@Sun.COM kmem_free(umrp, sizeof (*umrp));
44698275SEric Cheng return (err);
44708275SEric Cheng }
44718275SEric Cheng
44728275SEric Cheng int
mac_set_resources(mac_handle_t mh,mac_resource_props_t * mrp)44738275SEric Cheng mac_set_resources(mac_handle_t mh, mac_resource_props_t *mrp)
44748275SEric Cheng {
44758275SEric Cheng int err;
44768275SEric Cheng
44778275SEric Cheng i_mac_perim_enter((mac_impl_t *)mh);
44788275SEric Cheng err = i_mac_set_resources(mh, mrp);
44798275SEric Cheng i_mac_perim_exit((mac_impl_t *)mh);
44808275SEric Cheng return (err);
44818275SEric Cheng }
44828275SEric Cheng
44838275SEric Cheng /*
44848275SEric Cheng * Get the properties cached for the specified MAC instance.
44858275SEric Cheng */
44868275SEric Cheng void
mac_get_resources(mac_handle_t mh,mac_resource_props_t * mrp)44878275SEric Cheng mac_get_resources(mac_handle_t mh, mac_resource_props_t *mrp)
44888275SEric Cheng {
44898275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
44908275SEric Cheng mac_client_impl_t *mcip;
44918275SEric Cheng
449211878SVenu.Iyer@Sun.COM mcip = mac_primary_client_handle(mip);
449311878SVenu.Iyer@Sun.COM if (mcip != NULL) {
449411878SVenu.Iyer@Sun.COM mac_client_get_resources((mac_client_handle_t)mcip, mrp);
449511878SVenu.Iyer@Sun.COM return;
44968275SEric Cheng }
44978275SEric Cheng bcopy(&mip->mi_resource_props, mrp, sizeof (mac_resource_props_t));
44988275SEric Cheng }
44998275SEric Cheng
450011878SVenu.Iyer@Sun.COM /*
450111878SVenu.Iyer@Sun.COM * Get the effective properties from the primary client of the
450211878SVenu.Iyer@Sun.COM * specified MAC instance.
450311878SVenu.Iyer@Sun.COM */
450411878SVenu.Iyer@Sun.COM void
mac_get_effective_resources(mac_handle_t mh,mac_resource_props_t * mrp)450511878SVenu.Iyer@Sun.COM mac_get_effective_resources(mac_handle_t mh, mac_resource_props_t *mrp)
450611878SVenu.Iyer@Sun.COM {
450711878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
450811878SVenu.Iyer@Sun.COM mac_client_impl_t *mcip;
450911878SVenu.Iyer@Sun.COM
451011878SVenu.Iyer@Sun.COM mcip = mac_primary_client_handle(mip);
451111878SVenu.Iyer@Sun.COM if (mcip != NULL) {
451211878SVenu.Iyer@Sun.COM mac_client_get_effective_resources((mac_client_handle_t)mcip,
451311878SVenu.Iyer@Sun.COM mrp);
451411878SVenu.Iyer@Sun.COM return;
451511878SVenu.Iyer@Sun.COM }
451611878SVenu.Iyer@Sun.COM bzero(mrp, sizeof (mac_resource_props_t));
451711878SVenu.Iyer@Sun.COM }
451811878SVenu.Iyer@Sun.COM
451910491SRishi.Srivatsavai@Sun.COM int
mac_set_pvid(mac_handle_t mh,uint16_t pvid)452010491SRishi.Srivatsavai@Sun.COM mac_set_pvid(mac_handle_t mh, uint16_t pvid)
452110491SRishi.Srivatsavai@Sun.COM {
452210491SRishi.Srivatsavai@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
452310491SRishi.Srivatsavai@Sun.COM mac_client_impl_t *mcip;
452410491SRishi.Srivatsavai@Sun.COM mac_unicast_impl_t *muip;
452510491SRishi.Srivatsavai@Sun.COM
452610491SRishi.Srivatsavai@Sun.COM i_mac_perim_enter(mip);
452710491SRishi.Srivatsavai@Sun.COM if (pvid != 0) {
452810491SRishi.Srivatsavai@Sun.COM for (mcip = mip->mi_clients_list; mcip != NULL;
452910491SRishi.Srivatsavai@Sun.COM mcip = mcip->mci_client_next) {
453010491SRishi.Srivatsavai@Sun.COM for (muip = mcip->mci_unicast_list; muip != NULL;
453110491SRishi.Srivatsavai@Sun.COM muip = muip->mui_next) {
453210491SRishi.Srivatsavai@Sun.COM if (muip->mui_vid == pvid) {
453310491SRishi.Srivatsavai@Sun.COM i_mac_perim_exit(mip);
453410491SRishi.Srivatsavai@Sun.COM return (EBUSY);
453510491SRishi.Srivatsavai@Sun.COM }
453610491SRishi.Srivatsavai@Sun.COM }
453710491SRishi.Srivatsavai@Sun.COM }
453810491SRishi.Srivatsavai@Sun.COM }
453910491SRishi.Srivatsavai@Sun.COM mip->mi_pvid = pvid;
454010491SRishi.Srivatsavai@Sun.COM i_mac_perim_exit(mip);
454110491SRishi.Srivatsavai@Sun.COM return (0);
454210491SRishi.Srivatsavai@Sun.COM }
454310491SRishi.Srivatsavai@Sun.COM
454410491SRishi.Srivatsavai@Sun.COM uint16_t
mac_get_pvid(mac_handle_t mh)454510491SRishi.Srivatsavai@Sun.COM mac_get_pvid(mac_handle_t mh)
454610491SRishi.Srivatsavai@Sun.COM {
454710491SRishi.Srivatsavai@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
454810491SRishi.Srivatsavai@Sun.COM
454910491SRishi.Srivatsavai@Sun.COM return (mip->mi_pvid);
455010491SRishi.Srivatsavai@Sun.COM }
455110491SRishi.Srivatsavai@Sun.COM
455210491SRishi.Srivatsavai@Sun.COM uint32_t
mac_get_llimit(mac_handle_t mh)455310491SRishi.Srivatsavai@Sun.COM mac_get_llimit(mac_handle_t mh)
455410491SRishi.Srivatsavai@Sun.COM {
455510491SRishi.Srivatsavai@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
455610491SRishi.Srivatsavai@Sun.COM
455710491SRishi.Srivatsavai@Sun.COM return (mip->mi_llimit);
455810491SRishi.Srivatsavai@Sun.COM }
455910491SRishi.Srivatsavai@Sun.COM
456010491SRishi.Srivatsavai@Sun.COM uint32_t
mac_get_ldecay(mac_handle_t mh)456110491SRishi.Srivatsavai@Sun.COM mac_get_ldecay(mac_handle_t mh)
456210491SRishi.Srivatsavai@Sun.COM {
456310491SRishi.Srivatsavai@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
456410491SRishi.Srivatsavai@Sun.COM
456510491SRishi.Srivatsavai@Sun.COM return (mip->mi_ldecay);
456610491SRishi.Srivatsavai@Sun.COM }
456710491SRishi.Srivatsavai@Sun.COM
45688275SEric Cheng /*
45698275SEric Cheng * Rename a mac client, its flow, and the kstat.
45708275SEric Cheng */
45718275SEric Cheng int
mac_rename_primary(mac_handle_t mh,const char * new_name)45728275SEric Cheng mac_rename_primary(mac_handle_t mh, const char *new_name)
45738275SEric Cheng {
45748275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
45758275SEric Cheng mac_client_impl_t *cur_clnt = NULL;
45768275SEric Cheng flow_entry_t *fep;
45778275SEric Cheng
45788275SEric Cheng i_mac_perim_enter(mip);
45798275SEric Cheng
45808275SEric Cheng /*
45818275SEric Cheng * VNICs: we need to change the sys flow name and
45828275SEric Cheng * the associated flow kstat.
45838275SEric Cheng */
45848275SEric Cheng if (mip->mi_state_flags & MIS_IS_VNIC) {
458511878SVenu.Iyer@Sun.COM mac_client_impl_t *mcip = mac_vnic_lower(mip);
45868275SEric Cheng ASSERT(new_name != NULL);
458711878SVenu.Iyer@Sun.COM mac_rename_flow_names(mcip, new_name);
458811878SVenu.Iyer@Sun.COM mac_stat_rename(mcip);
45898275SEric Cheng goto done;
45908275SEric Cheng }
45918275SEric Cheng /*
45928275SEric Cheng * This mac may itself be an aggr link, or it may have some client
45938275SEric Cheng * which is an aggr port. For both cases, we need to change the
45948275SEric Cheng * aggr port's mac client name, its flow name and the associated flow
45958275SEric Cheng * kstat.
45968275SEric Cheng */
45978275SEric Cheng if (mip->mi_state_flags & MIS_IS_AGGR) {
45988275SEric Cheng mac_capab_aggr_t aggr_cap;
45998275SEric Cheng mac_rename_fn_t rename_fn;
46008275SEric Cheng boolean_t ret;
46018275SEric Cheng
46028275SEric Cheng ASSERT(new_name != NULL);
46038275SEric Cheng ret = i_mac_capab_get((mac_handle_t)mip, MAC_CAPAB_AGGR,
46048275SEric Cheng (void *)(&aggr_cap));
46058275SEric Cheng ASSERT(ret == B_TRUE);
46068275SEric Cheng rename_fn = aggr_cap.mca_rename_fn;
46078275SEric Cheng rename_fn(new_name, mip->mi_driver);
46088275SEric Cheng /*
46098275SEric Cheng * The aggr's client name and kstat flow name will be
46108275SEric Cheng * updated below, i.e. via mac_rename_flow_names.
46118275SEric Cheng */
46128275SEric Cheng }
46138275SEric Cheng
46148275SEric Cheng for (cur_clnt = mip->mi_clients_list; cur_clnt != NULL;
46158275SEric Cheng cur_clnt = cur_clnt->mci_client_next) {
46168275SEric Cheng if (cur_clnt->mci_state_flags & MCIS_IS_AGGR_PORT) {
46178275SEric Cheng if (new_name != NULL) {
46188275SEric Cheng char *str_st = cur_clnt->mci_name;
46198275SEric Cheng char *str_del = strchr(str_st, '-');
46208275SEric Cheng
46218275SEric Cheng ASSERT(str_del != NULL);
46228275SEric Cheng bzero(str_del + 1, MAXNAMELEN -
46238275SEric Cheng (str_del - str_st + 1));
46248275SEric Cheng bcopy(new_name, str_del + 1,
46258275SEric Cheng strlen(new_name));
46268275SEric Cheng }
46278275SEric Cheng fep = cur_clnt->mci_flent;
46288275SEric Cheng mac_rename_flow(fep, cur_clnt->mci_name);
46298275SEric Cheng break;
46308275SEric Cheng } else if (new_name != NULL &&
46318275SEric Cheng cur_clnt->mci_state_flags & MCIS_USE_DATALINK_NAME) {
46328275SEric Cheng mac_rename_flow_names(cur_clnt, new_name);
46338275SEric Cheng break;
46348275SEric Cheng }
46358275SEric Cheng }
46368275SEric Cheng
463711878SVenu.Iyer@Sun.COM /* Recreate kstats associated with aggr pseudo rings */
463811878SVenu.Iyer@Sun.COM if (mip->mi_state_flags & MIS_IS_AGGR)
463911878SVenu.Iyer@Sun.COM mac_pseudo_ring_stat_rename(mip);
464011878SVenu.Iyer@Sun.COM
46418275SEric Cheng done:
46428275SEric Cheng i_mac_perim_exit(mip);
46438275SEric Cheng return (0);
46448275SEric Cheng }
46458275SEric Cheng
46468275SEric Cheng /*
46478275SEric Cheng * Rename the MAC client's flow names
46488275SEric Cheng */
46498275SEric Cheng static void
mac_rename_flow_names(mac_client_impl_t * mcip,const char * new_name)46508275SEric Cheng mac_rename_flow_names(mac_client_impl_t *mcip, const char *new_name)
46518275SEric Cheng {
46528275SEric Cheng flow_entry_t *flent;
46538275SEric Cheng uint16_t vid;
46548558SGirish.Moodalbail@Sun.COM char flowname[MAXFLOWNAMELEN];
46558275SEric Cheng mac_impl_t *mip = mcip->mci_mip;
46568275SEric Cheng
46578275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mip));
46588275SEric Cheng
46598275SEric Cheng /*
46608275SEric Cheng * Use mi_rw_lock to ensure that threads not in the mac perimeter
46618275SEric Cheng * see a self-consistent value for mci_name
46628275SEric Cheng */
46638275SEric Cheng rw_enter(&mip->mi_rw_lock, RW_WRITER);
46648275SEric Cheng (void) strlcpy(mcip->mci_name, new_name, sizeof (mcip->mci_name));
46658275SEric Cheng rw_exit(&mip->mi_rw_lock);
46668275SEric Cheng
46678275SEric Cheng mac_rename_flow(mcip->mci_flent, new_name);
46688275SEric Cheng
46698275SEric Cheng if (mcip->mci_nflents == 1)
46708275SEric Cheng return;
46718275SEric Cheng
46728275SEric Cheng /*
46738275SEric Cheng * We have to rename all the others too, no stats to destroy for
46748275SEric Cheng * these.
46758275SEric Cheng */
46768275SEric Cheng for (flent = mcip->mci_flent_list; flent != NULL;
46778275SEric Cheng flent = flent->fe_client_next) {
46788275SEric Cheng if (flent != mcip->mci_flent) {
46798275SEric Cheng vid = i_mac_flow_vid(flent);
46808275SEric Cheng (void) sprintf(flowname, "%s%u", new_name, vid);
46818275SEric Cheng mac_flow_set_name(flent, flowname);
46828275SEric Cheng }
46838275SEric Cheng }
46848275SEric Cheng }
46858275SEric Cheng
46868275SEric Cheng
46878275SEric Cheng /*
46888275SEric Cheng * Add a flow to the MAC client's flow list - i.e list of MAC/VID tuples
46898275SEric Cheng * defined for the specified MAC client.
46908275SEric Cheng */
46918275SEric Cheng static void
mac_client_add_to_flow_list(mac_client_impl_t * mcip,flow_entry_t * flent)46928275SEric Cheng mac_client_add_to_flow_list(mac_client_impl_t *mcip, flow_entry_t *flent)
46938275SEric Cheng {
46948275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mcip->mci_mip));
46958275SEric Cheng /*
46968275SEric Cheng * The promisc Rx data path walks the mci_flent_list. Protect by
46978275SEric Cheng * using mi_rw_lock
46988275SEric Cheng */
46998275SEric Cheng rw_enter(&mcip->mci_rw_lock, RW_WRITER);
47008275SEric Cheng
47018275SEric Cheng /* Add it to the head */
47028275SEric Cheng flent->fe_client_next = mcip->mci_flent_list;
47038275SEric Cheng mcip->mci_flent_list = flent;
47048275SEric Cheng mcip->mci_nflents++;
47058275SEric Cheng
47068275SEric Cheng /*
47078275SEric Cheng * Keep track of the number of non-zero VIDs addresses per MAC
47088275SEric Cheng * client to avoid figuring it out in the data-path.
47098275SEric Cheng */
47108275SEric Cheng if (i_mac_flow_vid(flent) != VLAN_ID_NONE)
47118275SEric Cheng mcip->mci_nvids++;
47128275SEric Cheng
47138275SEric Cheng rw_exit(&mcip->mci_rw_lock);
47148275SEric Cheng }
47158275SEric Cheng
47168275SEric Cheng /*
47178275SEric Cheng * Remove a flow entry from the MAC client's list.
47188275SEric Cheng */
47198275SEric Cheng static void
mac_client_remove_flow_from_list(mac_client_impl_t * mcip,flow_entry_t * flent)47208275SEric Cheng mac_client_remove_flow_from_list(mac_client_impl_t *mcip, flow_entry_t *flent)
47218275SEric Cheng {
47228275SEric Cheng flow_entry_t *fe = mcip->mci_flent_list;
47238275SEric Cheng flow_entry_t *prev_fe = NULL;
47248275SEric Cheng
47258275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mcip->mci_mip));
47268275SEric Cheng /*
47278275SEric Cheng * The promisc Rx data path walks the mci_flent_list. Protect by
47288275SEric Cheng * using mci_rw_lock
47298275SEric Cheng */
47308275SEric Cheng rw_enter(&mcip->mci_rw_lock, RW_WRITER);
47318275SEric Cheng while ((fe != NULL) && (fe != flent)) {
47328275SEric Cheng prev_fe = fe;
47338275SEric Cheng fe = fe->fe_client_next;
47348275SEric Cheng }
47358275SEric Cheng
47368558SGirish.Moodalbail@Sun.COM ASSERT(fe != NULL);
47378558SGirish.Moodalbail@Sun.COM if (prev_fe == NULL) {
47388558SGirish.Moodalbail@Sun.COM /* Deleting the first node */
47398558SGirish.Moodalbail@Sun.COM mcip->mci_flent_list = fe->fe_client_next;
47408558SGirish.Moodalbail@Sun.COM } else {
47418558SGirish.Moodalbail@Sun.COM prev_fe->fe_client_next = fe->fe_client_next;
47428275SEric Cheng }
47438558SGirish.Moodalbail@Sun.COM mcip->mci_nflents--;
47448558SGirish.Moodalbail@Sun.COM
47458558SGirish.Moodalbail@Sun.COM if (i_mac_flow_vid(flent) != VLAN_ID_NONE)
47468558SGirish.Moodalbail@Sun.COM mcip->mci_nvids--;
47478558SGirish.Moodalbail@Sun.COM
47488275SEric Cheng rw_exit(&mcip->mci_rw_lock);
47498275SEric Cheng }
47508275SEric Cheng
47518275SEric Cheng /*
47528275SEric Cheng * Check if the given VID belongs to this MAC client.
47538275SEric Cheng */
47548275SEric Cheng boolean_t
mac_client_check_flow_vid(mac_client_impl_t * mcip,uint16_t vid)47558275SEric Cheng mac_client_check_flow_vid(mac_client_impl_t *mcip, uint16_t vid)
47568275SEric Cheng {
47578275SEric Cheng flow_entry_t *flent;
47588275SEric Cheng uint16_t mci_vid;
47598275SEric Cheng
47608275SEric Cheng /* The mci_flent_list is protected by mci_rw_lock */
47618275SEric Cheng rw_enter(&mcip->mci_rw_lock, RW_WRITER);
47628275SEric Cheng for (flent = mcip->mci_flent_list; flent != NULL;
47638275SEric Cheng flent = flent->fe_client_next) {
47648275SEric Cheng mci_vid = i_mac_flow_vid(flent);
47658275SEric Cheng if (vid == mci_vid) {
47668275SEric Cheng rw_exit(&mcip->mci_rw_lock);
47678275SEric Cheng return (B_TRUE);
47688275SEric Cheng }
47698275SEric Cheng }
47708275SEric Cheng rw_exit(&mcip->mci_rw_lock);
47718275SEric Cheng return (B_FALSE);
47728275SEric Cheng }
47738275SEric Cheng
47748275SEric Cheng /*
47758275SEric Cheng * Get the flow entry for the specified <MAC addr, VID> tuple.
47768275SEric Cheng */
47778275SEric Cheng static flow_entry_t *
mac_client_get_flow(mac_client_impl_t * mcip,mac_unicast_impl_t * muip)47788275SEric Cheng mac_client_get_flow(mac_client_impl_t *mcip, mac_unicast_impl_t *muip)
47798275SEric Cheng {
47808275SEric Cheng mac_address_t *map = mcip->mci_unicast;
47818275SEric Cheng flow_entry_t *flent;
47828275SEric Cheng uint16_t vid;
47838275SEric Cheng flow_desc_t flow_desc;
47848275SEric Cheng
47858275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mcip->mci_mip));
47868275SEric Cheng
47878275SEric Cheng mac_flow_get_desc(mcip->mci_flent, &flow_desc);
47888275SEric Cheng if (bcmp(flow_desc.fd_dst_mac, map->ma_addr, map->ma_len) != 0)
47898275SEric Cheng return (NULL);
47908275SEric Cheng
47918275SEric Cheng for (flent = mcip->mci_flent_list; flent != NULL;
47928275SEric Cheng flent = flent->fe_client_next) {
47938275SEric Cheng vid = i_mac_flow_vid(flent);
47948275SEric Cheng if (vid == muip->mui_vid) {
47958275SEric Cheng return (flent);
47968275SEric Cheng }
47978275SEric Cheng }
47988275SEric Cheng
47998275SEric Cheng return (NULL);
48008275SEric Cheng }
48018275SEric Cheng
48028275SEric Cheng /*
48038275SEric Cheng * Since mci_flent has the SRSs, when we want to remove it, we replace
48048275SEric Cheng * the flow_desc_t in mci_flent with that of an existing flent and then
48058275SEric Cheng * remove that flent instead of mci_flent.
48068275SEric Cheng */
48078275SEric Cheng static flow_entry_t *
mac_client_swap_mciflent(mac_client_impl_t * mcip)48088275SEric Cheng mac_client_swap_mciflent(mac_client_impl_t *mcip)
48098275SEric Cheng {
48108275SEric Cheng flow_entry_t *flent = mcip->mci_flent;
48118275SEric Cheng flow_tab_t *ft = flent->fe_flow_tab;
48128275SEric Cheng flow_entry_t *flent1;
48138275SEric Cheng flow_desc_t fl_desc;
48148558SGirish.Moodalbail@Sun.COM char fl_name[MAXFLOWNAMELEN];
48158275SEric Cheng int err;
48168275SEric Cheng
48178275SEric Cheng ASSERT(MAC_PERIM_HELD((mac_handle_t)mcip->mci_mip));
48188275SEric Cheng ASSERT(mcip->mci_nflents > 1);
48198275SEric Cheng
48208275SEric Cheng /* get the next flent following the primary flent */
48218275SEric Cheng flent1 = mcip->mci_flent_list->fe_client_next;
48228275SEric Cheng ASSERT(flent1 != NULL && flent1->fe_flow_tab == ft);
48238275SEric Cheng
48248275SEric Cheng /*
48258275SEric Cheng * Remove the flent from the flow table before updating the
48268275SEric Cheng * flow descriptor as the hash depends on the flow descriptor.
48278275SEric Cheng * This also helps incoming packet classification avoid having
48288275SEric Cheng * to grab fe_lock. Access to fe_flow_desc of a flent not in the
48298275SEric Cheng * flow table is done under the fe_lock so that log or stat functions
48308275SEric Cheng * see a self-consistent fe_flow_desc. The name and desc are specific
48318275SEric Cheng * to a flow, the rest are shared by all the clients, including
48328275SEric Cheng * resource control etc.
48338275SEric Cheng */
48348275SEric Cheng mac_flow_remove(ft, flent, B_TRUE);
48358275SEric Cheng mac_flow_remove(ft, flent1, B_TRUE);
48368275SEric Cheng
48378275SEric Cheng bcopy(&flent->fe_flow_desc, &fl_desc, sizeof (flow_desc_t));
48388558SGirish.Moodalbail@Sun.COM bcopy(flent->fe_flow_name, fl_name, MAXFLOWNAMELEN);
48398275SEric Cheng
48408275SEric Cheng /* update the primary flow entry */
48418275SEric Cheng mutex_enter(&flent->fe_lock);
48428275SEric Cheng bcopy(&flent1->fe_flow_desc, &flent->fe_flow_desc,
48438275SEric Cheng sizeof (flow_desc_t));
48448558SGirish.Moodalbail@Sun.COM bcopy(&flent1->fe_flow_name, &flent->fe_flow_name, MAXFLOWNAMELEN);
48458275SEric Cheng mutex_exit(&flent->fe_lock);
48468275SEric Cheng
48478275SEric Cheng /* update the flow entry that is to be freed */
48488275SEric Cheng mutex_enter(&flent1->fe_lock);
48498275SEric Cheng bcopy(&fl_desc, &flent1->fe_flow_desc, sizeof (flow_desc_t));
48508558SGirish.Moodalbail@Sun.COM bcopy(fl_name, &flent1->fe_flow_name, MAXFLOWNAMELEN);
48518275SEric Cheng mutex_exit(&flent1->fe_lock);
48528275SEric Cheng
48538275SEric Cheng /* now reinsert the flow entries in the table */
48548275SEric Cheng err = mac_flow_add(ft, flent);
48558275SEric Cheng ASSERT(err == 0);
48568275SEric Cheng
48578275SEric Cheng err = mac_flow_add(ft, flent1);
48588275SEric Cheng ASSERT(err == 0);
48598275SEric Cheng
48608275SEric Cheng return (flent1);
48618275SEric Cheng }
48628275SEric Cheng
48638275SEric Cheng /*
48648275SEric Cheng * Return whether there is only one flow entry associated with this
48658275SEric Cheng * MAC client.
48668275SEric Cheng */
48678275SEric Cheng static boolean_t
mac_client_single_rcvr(mac_client_impl_t * mcip)48688275SEric Cheng mac_client_single_rcvr(mac_client_impl_t *mcip)
48698275SEric Cheng {
48708275SEric Cheng return (mcip->mci_nflents == 1);
48718275SEric Cheng }
48728275SEric Cheng
48738275SEric Cheng int
mac_validate_props(mac_impl_t * mip,mac_resource_props_t * mrp)487411878SVenu.Iyer@Sun.COM mac_validate_props(mac_impl_t *mip, mac_resource_props_t *mrp)
48758275SEric Cheng {
487611878SVenu.Iyer@Sun.COM boolean_t reset;
487711878SVenu.Iyer@Sun.COM uint32_t rings_needed;
487811878SVenu.Iyer@Sun.COM uint32_t rings_avail;
487911878SVenu.Iyer@Sun.COM mac_group_type_t gtype;
488011878SVenu.Iyer@Sun.COM mac_resource_props_t *mip_mrp;
488111878SVenu.Iyer@Sun.COM
48828275SEric Cheng if (mrp == NULL)
48838275SEric Cheng return (0);
48848275SEric Cheng
48858275SEric Cheng if (mrp->mrp_mask & MRP_PRIORITY) {
48868275SEric Cheng mac_priority_level_t pri = mrp->mrp_priority;
48878275SEric Cheng
48888275SEric Cheng if (pri < MPL_LOW || pri > MPL_RESET)
48898275SEric Cheng return (EINVAL);
48908275SEric Cheng }
48918275SEric Cheng
48928275SEric Cheng if (mrp->mrp_mask & MRP_MAXBW) {
48938275SEric Cheng uint64_t maxbw = mrp->mrp_maxbw;
48948275SEric Cheng
48958275SEric Cheng if (maxbw < MRP_MAXBW_MINVAL && maxbw != 0)
48968275SEric Cheng return (EINVAL);
48978275SEric Cheng }
48988275SEric Cheng if (mrp->mrp_mask & MRP_CPUS) {
48999060SNitin.Hande@Sun.COM int i, j;
49008275SEric Cheng mac_cpu_mode_t fanout;
49018275SEric Cheng
490212062SRajagopal.Kunhappan@Sun.COM if (mrp->mrp_ncpus > ncpus)
49038275SEric Cheng return (EINVAL);
49048275SEric Cheng
49058275SEric Cheng for (i = 0; i < mrp->mrp_ncpus; i++) {
49069060SNitin.Hande@Sun.COM for (j = 0; j < mrp->mrp_ncpus; j++) {
49079060SNitin.Hande@Sun.COM if (i != j &&
49089060SNitin.Hande@Sun.COM mrp->mrp_cpu[i] == mrp->mrp_cpu[j]) {
49099060SNitin.Hande@Sun.COM return (EINVAL);
49109060SNitin.Hande@Sun.COM }
49119060SNitin.Hande@Sun.COM }
49129060SNitin.Hande@Sun.COM }
49139060SNitin.Hande@Sun.COM
49149060SNitin.Hande@Sun.COM for (i = 0; i < mrp->mrp_ncpus; i++) {
49158275SEric Cheng cpu_t *cp;
49168275SEric Cheng int rv;
49178275SEric Cheng
49188275SEric Cheng mutex_enter(&cpu_lock);
49198275SEric Cheng cp = cpu_get(mrp->mrp_cpu[i]);
49208275SEric Cheng if (cp != NULL)
49218275SEric Cheng rv = cpu_is_online(cp);
49228275SEric Cheng else
49238275SEric Cheng rv = 0;
49248275SEric Cheng mutex_exit(&cpu_lock);
49258275SEric Cheng if (rv == 0)
49268275SEric Cheng return (EINVAL);
49278275SEric Cheng }
49288275SEric Cheng
49298275SEric Cheng fanout = mrp->mrp_fanout_mode;
49308275SEric Cheng if (fanout < 0 || fanout > MCM_CPUS)
49318275SEric Cheng return (EINVAL);
49328275SEric Cheng }
493310734SEric Cheng
493410734SEric Cheng if (mrp->mrp_mask & MRP_PROTECT) {
493510734SEric Cheng int err = mac_protect_validate(mrp);
493610734SEric Cheng if (err != 0)
493710734SEric Cheng return (err);
493810734SEric Cheng }
493911878SVenu.Iyer@Sun.COM
494011878SVenu.Iyer@Sun.COM if (!(mrp->mrp_mask & MRP_RX_RINGS) &&
494111878SVenu.Iyer@Sun.COM !(mrp->mrp_mask & MRP_TX_RINGS)) {
494211878SVenu.Iyer@Sun.COM return (0);
494311878SVenu.Iyer@Sun.COM }
494411878SVenu.Iyer@Sun.COM
494511878SVenu.Iyer@Sun.COM /*
494611878SVenu.Iyer@Sun.COM * mip will be null when we come from mac_flow_create or
494711878SVenu.Iyer@Sun.COM * mac_link_flow_modify. In the latter case it is a user flow,
494811878SVenu.Iyer@Sun.COM * for which we don't support rings. In the former we would
494911878SVenu.Iyer@Sun.COM * have validated the props beforehand (i_mac_unicast_add ->
495011878SVenu.Iyer@Sun.COM * mac_client_set_resources -> validate for the primary and
495111878SVenu.Iyer@Sun.COM * vnic_dev_create -> mac_client_set_resources -> validate for
495211878SVenu.Iyer@Sun.COM * a vnic.
495311878SVenu.Iyer@Sun.COM */
495411878SVenu.Iyer@Sun.COM if (mip == NULL)
495511878SVenu.Iyer@Sun.COM return (0);
495611878SVenu.Iyer@Sun.COM
495711878SVenu.Iyer@Sun.COM /*
495811878SVenu.Iyer@Sun.COM * We don't support setting rings property for a VNIC that is using a
495911878SVenu.Iyer@Sun.COM * primary address (VLAN)
496011878SVenu.Iyer@Sun.COM */
496111878SVenu.Iyer@Sun.COM if ((mip->mi_state_flags & MIS_IS_VNIC) &&
496211878SVenu.Iyer@Sun.COM mac_is_vnic_primary((mac_handle_t)mip)) {
496311878SVenu.Iyer@Sun.COM return (ENOTSUP);
496411878SVenu.Iyer@Sun.COM }
496511878SVenu.Iyer@Sun.COM
496611878SVenu.Iyer@Sun.COM mip_mrp = &mip->mi_resource_props;
496711878SVenu.Iyer@Sun.COM /*
496811878SVenu.Iyer@Sun.COM * The rings property should be validated against the NICs
496911878SVenu.Iyer@Sun.COM * resources
497011878SVenu.Iyer@Sun.COM */
497111878SVenu.Iyer@Sun.COM if (mip->mi_state_flags & MIS_IS_VNIC)
497211878SVenu.Iyer@Sun.COM mip = (mac_impl_t *)mac_get_lower_mac_handle((mac_handle_t)mip);
497311878SVenu.Iyer@Sun.COM
497411878SVenu.Iyer@Sun.COM reset = mrp->mrp_mask & MRP_RINGS_RESET;
497511878SVenu.Iyer@Sun.COM /*
497611878SVenu.Iyer@Sun.COM * If groups are not supported, return error.
497711878SVenu.Iyer@Sun.COM */
497811878SVenu.Iyer@Sun.COM if (((mrp->mrp_mask & MRP_RX_RINGS) && mip->mi_rx_groups == NULL) ||
497911878SVenu.Iyer@Sun.COM ((mrp->mrp_mask & MRP_TX_RINGS) && mip->mi_tx_groups == NULL)) {
498011878SVenu.Iyer@Sun.COM return (EINVAL);
498111878SVenu.Iyer@Sun.COM }
498211878SVenu.Iyer@Sun.COM /*
498311878SVenu.Iyer@Sun.COM * If we are just resetting, there is no validation needed.
498411878SVenu.Iyer@Sun.COM */
498511878SVenu.Iyer@Sun.COM if (reset)
498611878SVenu.Iyer@Sun.COM return (0);
498711878SVenu.Iyer@Sun.COM
498811878SVenu.Iyer@Sun.COM if (mrp->mrp_mask & MRP_RX_RINGS) {
498911878SVenu.Iyer@Sun.COM rings_needed = mrp->mrp_nrxrings;
499011878SVenu.Iyer@Sun.COM /*
499111878SVenu.Iyer@Sun.COM * We just want to check if the number of additional
499211878SVenu.Iyer@Sun.COM * rings requested is available.
499311878SVenu.Iyer@Sun.COM */
499411878SVenu.Iyer@Sun.COM if (mip_mrp->mrp_mask & MRP_RX_RINGS) {
499511878SVenu.Iyer@Sun.COM if (mrp->mrp_nrxrings > mip_mrp->mrp_nrxrings)
499611878SVenu.Iyer@Sun.COM /* Just check for the additional rings */
499711878SVenu.Iyer@Sun.COM rings_needed -= mip_mrp->mrp_nrxrings;
499811878SVenu.Iyer@Sun.COM else
499911878SVenu.Iyer@Sun.COM /* We are not asking for additional rings */
500011878SVenu.Iyer@Sun.COM rings_needed = 0;
500111878SVenu.Iyer@Sun.COM }
500211878SVenu.Iyer@Sun.COM rings_avail = mip->mi_rxrings_avail;
500311878SVenu.Iyer@Sun.COM gtype = mip->mi_rx_group_type;
500411878SVenu.Iyer@Sun.COM } else {
500511878SVenu.Iyer@Sun.COM rings_needed = mrp->mrp_ntxrings;
500611878SVenu.Iyer@Sun.COM /* Similarly for the TX rings */
500711878SVenu.Iyer@Sun.COM if (mip_mrp->mrp_mask & MRP_TX_RINGS) {
500811878SVenu.Iyer@Sun.COM if (mrp->mrp_ntxrings > mip_mrp->mrp_ntxrings)
500911878SVenu.Iyer@Sun.COM /* Just check for the additional rings */
501011878SVenu.Iyer@Sun.COM rings_needed -= mip_mrp->mrp_ntxrings;
501111878SVenu.Iyer@Sun.COM else
501211878SVenu.Iyer@Sun.COM /* We are not asking for additional rings */
501311878SVenu.Iyer@Sun.COM rings_needed = 0;
501411878SVenu.Iyer@Sun.COM }
501511878SVenu.Iyer@Sun.COM rings_avail = mip->mi_txrings_avail;
501611878SVenu.Iyer@Sun.COM gtype = mip->mi_tx_group_type;
501711878SVenu.Iyer@Sun.COM }
501811878SVenu.Iyer@Sun.COM
501911878SVenu.Iyer@Sun.COM /* Error if the group is dynamic .. */
502011878SVenu.Iyer@Sun.COM if (gtype == MAC_GROUP_TYPE_DYNAMIC) {
502111878SVenu.Iyer@Sun.COM /*
502211878SVenu.Iyer@Sun.COM * .. and rings specified are more than available.
502311878SVenu.Iyer@Sun.COM */
502411878SVenu.Iyer@Sun.COM if (rings_needed > rings_avail)
502511878SVenu.Iyer@Sun.COM return (EINVAL);
502611878SVenu.Iyer@Sun.COM } else {
502711878SVenu.Iyer@Sun.COM /*
502811878SVenu.Iyer@Sun.COM * OR group is static and we have specified some rings.
502911878SVenu.Iyer@Sun.COM */
503011878SVenu.Iyer@Sun.COM if (rings_needed > 0)
503111878SVenu.Iyer@Sun.COM return (EINVAL);
503211878SVenu.Iyer@Sun.COM }
50338275SEric Cheng return (0);
50348275SEric Cheng }
50358275SEric Cheng
50368275SEric Cheng /*
50378275SEric Cheng * Send a MAC_NOTE_LINK notification to all the MAC clients whenever the
50388275SEric Cheng * underlying physical link is down. This is to allow MAC clients to
50398275SEric Cheng * communicate with other clients.
50408275SEric Cheng */
50418275SEric Cheng void
mac_virtual_link_update(mac_impl_t * mip)50428275SEric Cheng mac_virtual_link_update(mac_impl_t *mip)
50438275SEric Cheng {
50448275SEric Cheng if (mip->mi_linkstate != LINK_STATE_UP)
50458275SEric Cheng i_mac_notify(mip, MAC_NOTE_LINK);
50468275SEric Cheng }
50478275SEric Cheng
50488275SEric Cheng /*
50498275SEric Cheng * For clients that have a pass-thru MAC, e.g. VNIC, we set the VNIC's
50508275SEric Cheng * mac handle in the client.
50518275SEric Cheng */
50528275SEric Cheng void
mac_set_upper_mac(mac_client_handle_t mch,mac_handle_t mh,mac_resource_props_t * mrp)505311878SVenu.Iyer@Sun.COM mac_set_upper_mac(mac_client_handle_t mch, mac_handle_t mh,
505411878SVenu.Iyer@Sun.COM mac_resource_props_t *mrp)
50558275SEric Cheng {
50568275SEric Cheng mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
505711878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
505811878SVenu.Iyer@Sun.COM
505911878SVenu.Iyer@Sun.COM mcip->mci_upper_mip = mip;
506011878SVenu.Iyer@Sun.COM /* If there are any properties, copy it over too */
506111878SVenu.Iyer@Sun.COM if (mrp != NULL) {
506211878SVenu.Iyer@Sun.COM bcopy(mrp, &mip->mi_resource_props,
506311878SVenu.Iyer@Sun.COM sizeof (mac_resource_props_t));
506411878SVenu.Iyer@Sun.COM }
50658275SEric Cheng }
50668275SEric Cheng
50678275SEric Cheng /*
50688275SEric Cheng * Mark the mac as being used exclusively by the single mac client that is
50698275SEric Cheng * doing some control operation on this mac. No further opens of this mac
50708275SEric Cheng * will be allowed until this client calls mac_unmark_exclusive. The mac
50718275SEric Cheng * client calling this function must already be in the mac perimeter
50728275SEric Cheng */
50738275SEric Cheng int
mac_mark_exclusive(mac_handle_t mh)50748275SEric Cheng mac_mark_exclusive(mac_handle_t mh)
50758275SEric Cheng {
50768275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
50778275SEric Cheng
50788275SEric Cheng ASSERT(MAC_PERIM_HELD(mh));
50798275SEric Cheng /*
50808275SEric Cheng * Look up its entry in the global hash table.
50818275SEric Cheng */
50828275SEric Cheng rw_enter(&i_mac_impl_lock, RW_WRITER);
50838275SEric Cheng if (mip->mi_state_flags & MIS_DISABLED) {
50848275SEric Cheng rw_exit(&i_mac_impl_lock);
50858275SEric Cheng return (ENOENT);
50868275SEric Cheng }
50878275SEric Cheng
50888275SEric Cheng /*
50898275SEric Cheng * A reference to mac is held even if the link is not plumbed.
50908275SEric Cheng * In i_dls_link_create() we open the MAC interface and hold the
50918275SEric Cheng * reference. There is an additional reference for the mac_open
50928275SEric Cheng * done in acquiring the mac perimeter
50938275SEric Cheng */
50948275SEric Cheng if (mip->mi_ref != 2) {
50958275SEric Cheng rw_exit(&i_mac_impl_lock);
50968275SEric Cheng return (EBUSY);
50978275SEric Cheng }
50988275SEric Cheng
50998275SEric Cheng ASSERT(!(mip->mi_state_flags & MIS_EXCLUSIVE_HELD));
51008275SEric Cheng mip->mi_state_flags |= MIS_EXCLUSIVE_HELD;
51018275SEric Cheng rw_exit(&i_mac_impl_lock);
51028275SEric Cheng return (0);
51038275SEric Cheng }
51048275SEric Cheng
51058275SEric Cheng void
mac_unmark_exclusive(mac_handle_t mh)51068275SEric Cheng mac_unmark_exclusive(mac_handle_t mh)
51078275SEric Cheng {
51088275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
51098275SEric Cheng
51108275SEric Cheng ASSERT(MAC_PERIM_HELD(mh));
51118275SEric Cheng
51128275SEric Cheng rw_enter(&i_mac_impl_lock, RW_WRITER);
51138275SEric Cheng /* 1 for the creation and another for the perimeter */
51148275SEric Cheng ASSERT(mip->mi_ref == 2 && (mip->mi_state_flags & MIS_EXCLUSIVE_HELD));
51158275SEric Cheng mip->mi_state_flags &= ~MIS_EXCLUSIVE_HELD;
51168275SEric Cheng rw_exit(&i_mac_impl_lock);
51178275SEric Cheng }
51188275SEric Cheng
51198275SEric Cheng /*
512011878SVenu.Iyer@Sun.COM * Set the MTU for the specified MAC.
51218275SEric Cheng */
51228275SEric Cheng int
mac_set_mtu(mac_handle_t mh,uint_t new_mtu,uint_t * old_mtu_arg)51238275SEric Cheng mac_set_mtu(mac_handle_t mh, uint_t new_mtu, uint_t *old_mtu_arg)
51248275SEric Cheng {
51258275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
51268275SEric Cheng uint_t old_mtu;
512710674SSebastien.Roy@Sun.COM int rv = 0;
51288275SEric Cheng
51298275SEric Cheng i_mac_perim_enter(mip);
51308275SEric Cheng
513110616SSebastien.Roy@Sun.COM if (!(mip->mi_callbacks->mc_callbacks & (MC_SETPROP|MC_GETPROP))) {
51328275SEric Cheng rv = ENOTSUP;
51338275SEric Cheng goto bail;
51348275SEric Cheng }
51358275SEric Cheng
513610616SSebastien.Roy@Sun.COM old_mtu = mip->mi_sdu_max;
51378275SEric Cheng
513811878SVenu.Iyer@Sun.COM if (new_mtu == 0 || new_mtu < mip->mi_sdu_min) {
513911878SVenu.Iyer@Sun.COM rv = EINVAL;
514011878SVenu.Iyer@Sun.COM goto bail;
514111878SVenu.Iyer@Sun.COM }
514211878SVenu.Iyer@Sun.COM
51438275SEric Cheng if (old_mtu != new_mtu) {
51448275SEric Cheng rv = mip->mi_callbacks->mc_setprop(mip->mi_driver,
51458275SEric Cheng "mtu", MAC_PROP_MTU, sizeof (uint_t), &new_mtu);
514611878SVenu.Iyer@Sun.COM if (rv != 0)
514711878SVenu.Iyer@Sun.COM goto bail;
514811878SVenu.Iyer@Sun.COM rv = mac_maxsdu_update(mh, new_mtu);
514911878SVenu.Iyer@Sun.COM ASSERT(rv == 0);
51508275SEric Cheng }
51518275SEric Cheng
51528275SEric Cheng bail:
51538275SEric Cheng i_mac_perim_exit(mip);
51548275SEric Cheng
51558275SEric Cheng if (rv == 0 && old_mtu_arg != NULL)
51568275SEric Cheng *old_mtu_arg = old_mtu;
51578275SEric Cheng return (rv);
51588275SEric Cheng }
51598275SEric Cheng
516011878SVenu.Iyer@Sun.COM /*
516111878SVenu.Iyer@Sun.COM * Return the RX h/w information for the group indexed by grp_num.
516211878SVenu.Iyer@Sun.COM */
51638275SEric Cheng void
mac_get_hwrxgrp_info(mac_handle_t mh,int grp_index,uint_t * grp_num,uint_t * n_rings,uint_t * rings,uint_t * type,uint_t * n_clnts,char * clnts_name)516411878SVenu.Iyer@Sun.COM mac_get_hwrxgrp_info(mac_handle_t mh, int grp_index, uint_t *grp_num,
516511878SVenu.Iyer@Sun.COM uint_t *n_rings, uint_t *rings, uint_t *type, uint_t *n_clnts,
516611878SVenu.Iyer@Sun.COM char *clnts_name)
51678275SEric Cheng {
51688275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
51698275SEric Cheng mac_grp_client_t *mcip;
51708275SEric Cheng uint_t i = 0, index = 0;
517111878SVenu.Iyer@Sun.COM mac_ring_t *ring;
51728275SEric Cheng
51738275SEric Cheng /* Revisit when we implement fully dynamic group allocation */
51748275SEric Cheng ASSERT(grp_index >= 0 && grp_index < mip->mi_rx_group_count);
51758275SEric Cheng
51768275SEric Cheng rw_enter(&mip->mi_rw_lock, RW_READER);
51778275SEric Cheng *grp_num = mip->mi_rx_groups[grp_index].mrg_index;
51788275SEric Cheng *type = mip->mi_rx_groups[grp_index].mrg_type;
51798275SEric Cheng *n_rings = mip->mi_rx_groups[grp_index].mrg_cur_count;
518011878SVenu.Iyer@Sun.COM ring = mip->mi_rx_groups[grp_index].mrg_rings;
518111878SVenu.Iyer@Sun.COM for (index = 0; index < mip->mi_rx_groups[grp_index].mrg_cur_count;
518211878SVenu.Iyer@Sun.COM index++) {
518311878SVenu.Iyer@Sun.COM rings[index] = ring->mr_index;
518411878SVenu.Iyer@Sun.COM ring = ring->mr_next;
518511878SVenu.Iyer@Sun.COM }
518611878SVenu.Iyer@Sun.COM /* Assuming the 1st is the default group */
518711878SVenu.Iyer@Sun.COM index = 0;
518811878SVenu.Iyer@Sun.COM if (grp_index == 0) {
518911878SVenu.Iyer@Sun.COM (void) strlcpy(clnts_name, "<default,mcast>,",
519011878SVenu.Iyer@Sun.COM MAXCLIENTNAMELEN);
519111878SVenu.Iyer@Sun.COM index += strlen("<default,mcast>,");
519211878SVenu.Iyer@Sun.COM }
51938275SEric Cheng for (mcip = mip->mi_rx_groups[grp_index].mrg_clients; mcip != NULL;
51948275SEric Cheng mcip = mcip->mgc_next) {
51958275SEric Cheng int name_len = strlen(mcip->mgc_client->mci_name);
51968275SEric Cheng
51978275SEric Cheng /*
51988275SEric Cheng * MAXCLIENTNAMELEN is the buffer size reserved for client
51998275SEric Cheng * names.
52008275SEric Cheng * XXXX Formating the client name string needs to be moved
52018275SEric Cheng * to user land when fixing the size of dhi_clnts in
52028275SEric Cheng * dld_hwgrpinfo_t. We should use n_clients * client_name for
52038275SEric Cheng * dhi_clntsin instead of MAXCLIENTNAMELEN
52048275SEric Cheng */
52058275SEric Cheng if (index + name_len >= MAXCLIENTNAMELEN) {
52068275SEric Cheng index = MAXCLIENTNAMELEN;
52078275SEric Cheng break;
52088275SEric Cheng }
52098275SEric Cheng bcopy(mcip->mgc_client->mci_name, &(clnts_name[index]),
52108275SEric Cheng name_len);
52118275SEric Cheng index += name_len;
52128275SEric Cheng clnts_name[index++] = ',';
52138275SEric Cheng i++;
52148275SEric Cheng }
52158275SEric Cheng
52168275SEric Cheng /* Get rid of the last , */
52178275SEric Cheng if (index > 0)
52188275SEric Cheng clnts_name[index - 1] = '\0';
52198275SEric Cheng *n_clnts = i;
52208275SEric Cheng rw_exit(&mip->mi_rw_lock);
52218275SEric Cheng }
52228275SEric Cheng
522311878SVenu.Iyer@Sun.COM /*
522411878SVenu.Iyer@Sun.COM * Return the TX h/w information for the group indexed by grp_num.
522511878SVenu.Iyer@Sun.COM */
522611878SVenu.Iyer@Sun.COM void
mac_get_hwtxgrp_info(mac_handle_t mh,int grp_index,uint_t * grp_num,uint_t * n_rings,uint_t * rings,uint_t * type,uint_t * n_clnts,char * clnts_name)522711878SVenu.Iyer@Sun.COM mac_get_hwtxgrp_info(mac_handle_t mh, int grp_index, uint_t *grp_num,
522811878SVenu.Iyer@Sun.COM uint_t *n_rings, uint_t *rings, uint_t *type, uint_t *n_clnts,
522911878SVenu.Iyer@Sun.COM char *clnts_name)
523011878SVenu.Iyer@Sun.COM {
523111878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
523211878SVenu.Iyer@Sun.COM mac_grp_client_t *mcip;
523311878SVenu.Iyer@Sun.COM uint_t i = 0, index = 0;
523411878SVenu.Iyer@Sun.COM mac_ring_t *ring;
523511878SVenu.Iyer@Sun.COM
523611878SVenu.Iyer@Sun.COM /* Revisit when we implement fully dynamic group allocation */
523711878SVenu.Iyer@Sun.COM ASSERT(grp_index >= 0 && grp_index <= mip->mi_tx_group_count);
523811878SVenu.Iyer@Sun.COM
523911878SVenu.Iyer@Sun.COM rw_enter(&mip->mi_rw_lock, RW_READER);
524011878SVenu.Iyer@Sun.COM *grp_num = mip->mi_tx_groups[grp_index].mrg_index > 0 ?
524111878SVenu.Iyer@Sun.COM mip->mi_tx_groups[grp_index].mrg_index : grp_index;
524211878SVenu.Iyer@Sun.COM *type = mip->mi_tx_groups[grp_index].mrg_type;
524311878SVenu.Iyer@Sun.COM *n_rings = mip->mi_tx_groups[grp_index].mrg_cur_count;
524411878SVenu.Iyer@Sun.COM ring = mip->mi_tx_groups[grp_index].mrg_rings;
524511878SVenu.Iyer@Sun.COM for (index = 0; index < mip->mi_tx_groups[grp_index].mrg_cur_count;
524611878SVenu.Iyer@Sun.COM index++) {
524711878SVenu.Iyer@Sun.COM rings[index] = ring->mr_index;
524811878SVenu.Iyer@Sun.COM ring = ring->mr_next;
524911878SVenu.Iyer@Sun.COM }
525011878SVenu.Iyer@Sun.COM index = 0;
525111878SVenu.Iyer@Sun.COM /* Default group has an index of -1 */
525211878SVenu.Iyer@Sun.COM if (mip->mi_tx_groups[grp_index].mrg_index < 0) {
525311878SVenu.Iyer@Sun.COM (void) strlcpy(clnts_name, "<default>,",
525411878SVenu.Iyer@Sun.COM MAXCLIENTNAMELEN);
525511878SVenu.Iyer@Sun.COM index += strlen("<default>,");
525611878SVenu.Iyer@Sun.COM }
525711878SVenu.Iyer@Sun.COM for (mcip = mip->mi_tx_groups[grp_index].mrg_clients; mcip != NULL;
525811878SVenu.Iyer@Sun.COM mcip = mcip->mgc_next) {
525911878SVenu.Iyer@Sun.COM int name_len = strlen(mcip->mgc_client->mci_name);
526011878SVenu.Iyer@Sun.COM
526111878SVenu.Iyer@Sun.COM /*
526211878SVenu.Iyer@Sun.COM * MAXCLIENTNAMELEN is the buffer size reserved for client
526311878SVenu.Iyer@Sun.COM * names.
526411878SVenu.Iyer@Sun.COM * XXXX Formating the client name string needs to be moved
526511878SVenu.Iyer@Sun.COM * to user land when fixing the size of dhi_clnts in
526611878SVenu.Iyer@Sun.COM * dld_hwgrpinfo_t. We should use n_clients * client_name for
526711878SVenu.Iyer@Sun.COM * dhi_clntsin instead of MAXCLIENTNAMELEN
526811878SVenu.Iyer@Sun.COM */
526911878SVenu.Iyer@Sun.COM if (index + name_len >= MAXCLIENTNAMELEN) {
527011878SVenu.Iyer@Sun.COM index = MAXCLIENTNAMELEN;
527111878SVenu.Iyer@Sun.COM break;
527211878SVenu.Iyer@Sun.COM }
527311878SVenu.Iyer@Sun.COM bcopy(mcip->mgc_client->mci_name, &(clnts_name[index]),
527411878SVenu.Iyer@Sun.COM name_len);
527511878SVenu.Iyer@Sun.COM index += name_len;
527611878SVenu.Iyer@Sun.COM clnts_name[index++] = ',';
527711878SVenu.Iyer@Sun.COM i++;
527811878SVenu.Iyer@Sun.COM }
527911878SVenu.Iyer@Sun.COM
528011878SVenu.Iyer@Sun.COM /* Get rid of the last , */
528111878SVenu.Iyer@Sun.COM if (index > 0)
528211878SVenu.Iyer@Sun.COM clnts_name[index - 1] = '\0';
528311878SVenu.Iyer@Sun.COM *n_clnts = i;
528411878SVenu.Iyer@Sun.COM rw_exit(&mip->mi_rw_lock);
528511878SVenu.Iyer@Sun.COM }
528611878SVenu.Iyer@Sun.COM
528711878SVenu.Iyer@Sun.COM /*
528811878SVenu.Iyer@Sun.COM * Return the group count for RX or TX.
528911878SVenu.Iyer@Sun.COM */
52908275SEric Cheng uint_t
mac_hwgrp_num(mac_handle_t mh,int type)529111878SVenu.Iyer@Sun.COM mac_hwgrp_num(mac_handle_t mh, int type)
52928275SEric Cheng {
52938275SEric Cheng mac_impl_t *mip = (mac_impl_t *)mh;
52948275SEric Cheng
529511878SVenu.Iyer@Sun.COM /*
529611878SVenu.Iyer@Sun.COM * Return the Rx and Tx group count; for the Tx we need to
529711878SVenu.Iyer@Sun.COM * include the default too.
529811878SVenu.Iyer@Sun.COM */
529911878SVenu.Iyer@Sun.COM return (type == MAC_RING_TYPE_RX ? mip->mi_rx_group_count :
530011878SVenu.Iyer@Sun.COM mip->mi_tx_groups != NULL ? mip->mi_tx_group_count + 1 : 0);
530111878SVenu.Iyer@Sun.COM }
530211878SVenu.Iyer@Sun.COM
530311878SVenu.Iyer@Sun.COM /*
530411878SVenu.Iyer@Sun.COM * The total number of free TX rings for this MAC.
530511878SVenu.Iyer@Sun.COM */
530611878SVenu.Iyer@Sun.COM uint_t
mac_txavail_get(mac_handle_t mh)530711878SVenu.Iyer@Sun.COM mac_txavail_get(mac_handle_t mh)
530811878SVenu.Iyer@Sun.COM {
530911878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
531011878SVenu.Iyer@Sun.COM
531111878SVenu.Iyer@Sun.COM return (mip->mi_txrings_avail);
531211878SVenu.Iyer@Sun.COM }
531311878SVenu.Iyer@Sun.COM
531411878SVenu.Iyer@Sun.COM /*
531511878SVenu.Iyer@Sun.COM * The total number of free RX rings for this MAC.
531611878SVenu.Iyer@Sun.COM */
531711878SVenu.Iyer@Sun.COM uint_t
mac_rxavail_get(mac_handle_t mh)531811878SVenu.Iyer@Sun.COM mac_rxavail_get(mac_handle_t mh)
531911878SVenu.Iyer@Sun.COM {
532011878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
532111878SVenu.Iyer@Sun.COM
532211878SVenu.Iyer@Sun.COM return (mip->mi_rxrings_avail);
532311878SVenu.Iyer@Sun.COM }
532411878SVenu.Iyer@Sun.COM
532511878SVenu.Iyer@Sun.COM /*
532611878SVenu.Iyer@Sun.COM * The total number of reserved RX rings on this MAC.
532711878SVenu.Iyer@Sun.COM */
532811878SVenu.Iyer@Sun.COM uint_t
mac_rxrsvd_get(mac_handle_t mh)532911878SVenu.Iyer@Sun.COM mac_rxrsvd_get(mac_handle_t mh)
533011878SVenu.Iyer@Sun.COM {
533111878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
533211878SVenu.Iyer@Sun.COM
533311878SVenu.Iyer@Sun.COM return (mip->mi_rxrings_rsvd);
533411878SVenu.Iyer@Sun.COM }
533511878SVenu.Iyer@Sun.COM
533611878SVenu.Iyer@Sun.COM /*
533711878SVenu.Iyer@Sun.COM * The total number of reserved TX rings on this MAC.
533811878SVenu.Iyer@Sun.COM */
533911878SVenu.Iyer@Sun.COM uint_t
mac_txrsvd_get(mac_handle_t mh)534011878SVenu.Iyer@Sun.COM mac_txrsvd_get(mac_handle_t mh)
534111878SVenu.Iyer@Sun.COM {
534211878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
534311878SVenu.Iyer@Sun.COM
534411878SVenu.Iyer@Sun.COM return (mip->mi_txrings_rsvd);
53458275SEric Cheng }
534611878SVenu.Iyer@Sun.COM
534711878SVenu.Iyer@Sun.COM /*
534811878SVenu.Iyer@Sun.COM * Total number of free RX groups on this MAC.
534911878SVenu.Iyer@Sun.COM */
535011878SVenu.Iyer@Sun.COM uint_t
mac_rxhwlnksavail_get(mac_handle_t mh)535111878SVenu.Iyer@Sun.COM mac_rxhwlnksavail_get(mac_handle_t mh)
535211878SVenu.Iyer@Sun.COM {
535311878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
535411878SVenu.Iyer@Sun.COM
535511878SVenu.Iyer@Sun.COM return (mip->mi_rxhwclnt_avail);
535611878SVenu.Iyer@Sun.COM }
535711878SVenu.Iyer@Sun.COM
535811878SVenu.Iyer@Sun.COM /*
535911878SVenu.Iyer@Sun.COM * Total number of RX groups reserved on this MAC.
536011878SVenu.Iyer@Sun.COM */
536111878SVenu.Iyer@Sun.COM uint_t
mac_rxhwlnksrsvd_get(mac_handle_t mh)536211878SVenu.Iyer@Sun.COM mac_rxhwlnksrsvd_get(mac_handle_t mh)
536311878SVenu.Iyer@Sun.COM {
536411878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
536511878SVenu.Iyer@Sun.COM
536611878SVenu.Iyer@Sun.COM return (mip->mi_rxhwclnt_used);
536711878SVenu.Iyer@Sun.COM }
536811878SVenu.Iyer@Sun.COM
536911878SVenu.Iyer@Sun.COM /*
537011878SVenu.Iyer@Sun.COM * Total number of free TX groups on this MAC.
537111878SVenu.Iyer@Sun.COM */
537211878SVenu.Iyer@Sun.COM uint_t
mac_txhwlnksavail_get(mac_handle_t mh)537311878SVenu.Iyer@Sun.COM mac_txhwlnksavail_get(mac_handle_t mh)
537411878SVenu.Iyer@Sun.COM {
537511878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
537611878SVenu.Iyer@Sun.COM
537711878SVenu.Iyer@Sun.COM return (mip->mi_txhwclnt_avail);
537811878SVenu.Iyer@Sun.COM }
537911878SVenu.Iyer@Sun.COM
538011878SVenu.Iyer@Sun.COM /*
538111878SVenu.Iyer@Sun.COM * Total number of TX groups reserved on this MAC.
538211878SVenu.Iyer@Sun.COM */
538311878SVenu.Iyer@Sun.COM uint_t
mac_txhwlnksrsvd_get(mac_handle_t mh)538411878SVenu.Iyer@Sun.COM mac_txhwlnksrsvd_get(mac_handle_t mh)
538511878SVenu.Iyer@Sun.COM {
538611878SVenu.Iyer@Sun.COM mac_impl_t *mip = (mac_impl_t *)mh;
538711878SVenu.Iyer@Sun.COM
538811878SVenu.Iyer@Sun.COM return (mip->mi_txhwclnt_used);
538911878SVenu.Iyer@Sun.COM }
539011878SVenu.Iyer@Sun.COM
539111878SVenu.Iyer@Sun.COM /*
539211878SVenu.Iyer@Sun.COM * Initialize the rings property for a mac client. A non-0 value for
539311878SVenu.Iyer@Sun.COM * rxring or txring specifies the number of rings required, a value
539411878SVenu.Iyer@Sun.COM * of MAC_RXRINGS_NONE/MAC_TXRINGS_NONE specifies that it doesn't need
539511878SVenu.Iyer@Sun.COM * any RX/TX rings and a value of MAC_RXRINGS_DONTCARE/MAC_TXRINGS_DONTCARE
539611878SVenu.Iyer@Sun.COM * means the system can decide whether it can give any rings or not.
539711878SVenu.Iyer@Sun.COM */
539811878SVenu.Iyer@Sun.COM void
mac_client_set_rings(mac_client_handle_t mch,int rxrings,int txrings)539911878SVenu.Iyer@Sun.COM mac_client_set_rings(mac_client_handle_t mch, int rxrings, int txrings)
540011878SVenu.Iyer@Sun.COM {
540111878SVenu.Iyer@Sun.COM mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
540211878SVenu.Iyer@Sun.COM mac_resource_props_t *mrp = MCIP_RESOURCE_PROPS(mcip);
540311878SVenu.Iyer@Sun.COM
540411878SVenu.Iyer@Sun.COM if (rxrings != MAC_RXRINGS_DONTCARE) {
540511878SVenu.Iyer@Sun.COM mrp->mrp_mask |= MRP_RX_RINGS;
540611878SVenu.Iyer@Sun.COM mrp->mrp_nrxrings = rxrings;
540711878SVenu.Iyer@Sun.COM }
540811878SVenu.Iyer@Sun.COM
540911878SVenu.Iyer@Sun.COM if (txrings != MAC_TXRINGS_DONTCARE) {
541011878SVenu.Iyer@Sun.COM mrp->mrp_mask |= MRP_TX_RINGS;
541111878SVenu.Iyer@Sun.COM mrp->mrp_ntxrings = txrings;
541211878SVenu.Iyer@Sun.COM }
541311878SVenu.Iyer@Sun.COM }
5414