xref: /onnv-gate/usr/src/uts/common/io/nxge/nxge_virtual.c (revision 11304:3092d1e303d6)
13859Sml29623 /*
23859Sml29623  * CDDL HEADER START
33859Sml29623  *
43859Sml29623  * The contents of this file are subject to the terms of the
53859Sml29623  * Common Development and Distribution License (the "License").
63859Sml29623  * You may not use this file except in compliance with the License.
73859Sml29623  *
83859Sml29623  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93859Sml29623  * or http://www.opensolaris.org/os/licensing.
103859Sml29623  * See the License for the specific language governing permissions
113859Sml29623  * and limitations under the License.
123859Sml29623  *
133859Sml29623  * When distributing Covered Code, include this CDDL HEADER in each
143859Sml29623  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153859Sml29623  * If applicable, add the following below this CDDL HEADER, with the
163859Sml29623  * fields enclosed by brackets "[]" replaced with your own identifying
173859Sml29623  * information: Portions Copyright [yyyy] [name of copyright owner]
183859Sml29623  *
193859Sml29623  * CDDL HEADER END
203859Sml29623  */
213859Sml29623 /*
228661SSantwona.Behera@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
233859Sml29623  * Use is subject to license terms.
243859Sml29623  */
253859Sml29623 
263859Sml29623 #include <sys/nxge/nxge_impl.h>
273859Sml29623 #include <sys/nxge/nxge_mac.h>
286495Sspeer #include <sys/nxge/nxge_hio.h>
293859Sml29623 
309015SMichael.Speer@Sun.COM /*
319015SMichael.Speer@Sun.COM  * Local defines for FWARC 2006/556
329015SMichael.Speer@Sun.COM  */
339015SMichael.Speer@Sun.COM #define	NXGE_NIU_TDMA_PROP_LEN		2
349015SMichael.Speer@Sun.COM #define	NXGE_NIU_RDMA_PROP_LEN		2
359015SMichael.Speer@Sun.COM #define	NXGE_NIU_0_INTR_PROP_LEN	19
369015SMichael.Speer@Sun.COM #define	NXGE_NIU_1_INTR_PROP_LEN	17
379015SMichael.Speer@Sun.COM 
389015SMichael.Speer@Sun.COM /*
399015SMichael.Speer@Sun.COM  * Local functions.
409015SMichael.Speer@Sun.COM  */
413859Sml29623 static void nxge_get_niu_property(dev_info_t *, niu_type_t *);
423859Sml29623 static nxge_status_t nxge_get_mac_addr_properties(p_nxge_t);
433859Sml29623 static nxge_status_t nxge_use_cfg_n2niu_properties(p_nxge_t);
443859Sml29623 static void nxge_use_cfg_neptune_properties(p_nxge_t);
453859Sml29623 static void nxge_use_cfg_dma_config(p_nxge_t);
463859Sml29623 static void nxge_use_cfg_vlan_class_config(p_nxge_t);
473859Sml29623 static void nxge_use_cfg_mac_class_config(p_nxge_t);
483859Sml29623 static void nxge_use_cfg_class_config(p_nxge_t);
493859Sml29623 static void nxge_use_cfg_link_cfg(p_nxge_t);
503859Sml29623 static void nxge_set_hw_dma_config(p_nxge_t);
513859Sml29623 static void nxge_set_hw_vlan_class_config(p_nxge_t);
523859Sml29623 static void nxge_set_hw_mac_class_config(p_nxge_t);
533859Sml29623 static void nxge_set_hw_class_config(p_nxge_t);
543859Sml29623 static nxge_status_t nxge_use_default_dma_config_n2(p_nxge_t);
553859Sml29623 static void nxge_ldgv_setup(p_nxge_ldg_t *, p_nxge_ldv_t *, uint8_t,
563859Sml29623 	uint8_t, int *);
574732Sdavemq static void nxge_init_mmac(p_nxge_t, boolean_t);
586495Sspeer static void nxge_set_rdc_intr_property(p_nxge_t);
593859Sml29623 
603859Sml29623 uint32_t nxge_use_hw_property = 1;
613859Sml29623 uint32_t nxge_groups_per_port = 2;
623859Sml29623 
633859Sml29623 extern uint32_t nxge_use_partition;
643859Sml29623 extern uint32_t nxge_dma_obp_props_only;
653859Sml29623 
663859Sml29623 extern uint_t nxge_rx_intr(void *, void *);
673859Sml29623 extern uint_t nxge_tx_intr(void *, void *);
683859Sml29623 extern uint_t nxge_mif_intr(void *, void *);
693859Sml29623 extern uint_t nxge_mac_intr(void *, void *);
703859Sml29623 extern uint_t nxge_syserr_intr(void *, void *);
713859Sml29623 extern void *nxge_list;
723859Sml29623 
733859Sml29623 #define	NXGE_SHARED_REG_SW_SIM
743859Sml29623 
753859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
763859Sml29623 uint64_t global_dev_ctrl = 0;
773859Sml29623 #endif
783859Sml29623 
793859Sml29623 #define	MAX_SIBLINGS	NXGE_MAX_PORTS
803859Sml29623 
813859Sml29623 extern uint32_t nxge_rbr_size;
823859Sml29623 extern uint32_t nxge_rcr_size;
833859Sml29623 extern uint32_t nxge_tx_ring_size;
843859Sml29623 extern uint32_t nxge_rbr_spare_size;
853859Sml29623 
863859Sml29623 extern npi_status_t npi_mac_altaddr_disable(npi_handle_t, uint8_t, uint8_t);
873859Sml29623 
883859Sml29623 static uint8_t p2_tx_fair[2] = {12, 12};
893859Sml29623 static uint8_t p2_tx_equal[2] = {12, 12};
903859Sml29623 static uint8_t p4_tx_fair[4] = {6, 6, 6, 6};
913859Sml29623 static uint8_t p4_tx_equal[4] = {6, 6, 6, 6};
923859Sml29623 static uint8_t p2_rx_fair[2] = {8, 8};
933859Sml29623 static uint8_t p2_rx_equal[2] = {8, 8};
943859Sml29623 static uint8_t p4_rx_fair[4] = {4, 4, 4, 4};
953859Sml29623 static uint8_t p4_rx_equal[4] = {4, 4, 4, 4};
963859Sml29623 
973859Sml29623 static uint8_t p2_rdcgrp_fair[2] = {4, 4};
983859Sml29623 static uint8_t p2_rdcgrp_equal[2] = {4, 4};
993859Sml29623 static uint8_t p4_rdcgrp_fair[4] = {2, 2, 1, 1};
1003859Sml29623 static uint8_t p4_rdcgrp_equal[4] = {2, 2, 2, 2};
1013859Sml29623 static uint8_t p2_rdcgrp_cls[2] = {1, 1};
1023859Sml29623 static uint8_t p4_rdcgrp_cls[4] = {1, 1, 1, 1};
1033859Sml29623 
1044732Sdavemq static uint8_t rx_4_1G[4] = {4, 4, 4, 4};
1054732Sdavemq static uint8_t rx_2_10G[2] = {8, 8};
1064732Sdavemq static uint8_t rx_2_10G_2_1G[4] = {6, 6, 2, 2};
1074732Sdavemq static uint8_t rx_1_10G_3_1G[4] = {10, 2, 2, 2};
1084732Sdavemq static uint8_t rx_1_1G_1_10G_2_1G[4] = {2, 10, 2, 2};
1094732Sdavemq 
1104732Sdavemq static uint8_t tx_4_1G[4] = {6, 6, 6, 6};
1114732Sdavemq static uint8_t tx_2_10G[2] = {12, 12};
1124732Sdavemq static uint8_t tx_2_10G_2_1G[4] = {10, 10, 2, 2};
1134732Sdavemq static uint8_t tx_1_10G_3_1G[4] = {12, 4, 4, 4};
1144732Sdavemq static uint8_t tx_1_1G_1_10G_2_1G[4] = {4, 12, 4, 4};
1154732Sdavemq 
1163859Sml29623 typedef enum {
1173859Sml29623 	DEFAULT = 0,
1183859Sml29623 	EQUAL,
1193859Sml29623 	FAIR,
1203859Sml29623 	CUSTOM,
1213859Sml29623 	CLASSIFY,
1223859Sml29623 	L2_CLASSIFY,
1233859Sml29623 	L3_DISTRIBUTE,
1243859Sml29623 	L3_CLASSIFY,
1253859Sml29623 	L3_TCAM,
1263859Sml29623 	CONFIG_TOKEN_NONE
1273859Sml29623 } config_token_t;
1283859Sml29623 
1293859Sml29623 static char *token_names[] = {
1303859Sml29623 	"default",
1313859Sml29623 	"equal",
1323859Sml29623 	"fair",
1333859Sml29623 	"custom",
1343859Sml29623 	"classify",
1353859Sml29623 	"l2_classify",
1363859Sml29623 	"l3_distribute",
1373859Sml29623 	"l3_classify",
1383859Sml29623 	"l3_tcam",
1393859Sml29623 	"none",
1403859Sml29623 };
1413859Sml29623 
1423859Sml29623 void nxge_virint_regs_dump(p_nxge_t nxgep);
1433859Sml29623 
1443859Sml29623 void
1453859Sml29623 nxge_virint_regs_dump(p_nxge_t nxgep)
1463859Sml29623 {
1473859Sml29623 	npi_handle_t handle;
1483859Sml29623 
1493859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_virint_regs_dump"));
1503859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
1513859Sml29623 	(void) npi_vir_dump_pio_fzc_regs_one(handle);
1523859Sml29623 	(void) npi_vir_dump_ldgnum(handle);
1533859Sml29623 	(void) npi_vir_dump_ldsv(handle);
1543859Sml29623 	(void) npi_vir_dump_imask0(handle);
1553859Sml29623 	(void) npi_vir_dump_sid(handle);
1563859Sml29623 	(void) npi_mac_dump_regs(handle, nxgep->function_num);
1573859Sml29623 	(void) npi_ipp_dump_regs(handle, nxgep->function_num);
1583859Sml29623 	(void) npi_fflp_dump_regs(handle);
1593859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_virint_regs_dump"));
1603859Sml29623 }
1613859Sml29623 
1623859Sml29623 /*
1633859Sml29623  * For now: we hard coded the DMA configurations.
1643859Sml29623  *	    and assume for one partition only.
1653859Sml29623  *
1663859Sml29623  *       OBP. Then OBP will pass this partition's
1673859Sml29623  *	 Neptune configurations to fcode to create
1683859Sml29623  *	 properties for them.
1693859Sml29623  *
1703859Sml29623  *	Since Neptune(PCI-E) and NIU (Niagara-2) has
1713859Sml29623  *	different bus interfaces, the driver needs
1723859Sml29623  *	to know which bus it is connected to.
1733859Sml29623  *  	Ravinder suggested: create a device property.
1743859Sml29623  *	In partitioning environment, we cannot
1753859Sml29623  *	use .conf file (need to check). If conf changes,
1763859Sml29623  *	need to reboot the system.
1773859Sml29623  *	The following function assumes that we will
1783859Sml29623  *	retrieve its properties from a virtualized nexus driver.
1793859Sml29623  */
1803859Sml29623 
1813859Sml29623 nxge_status_t
1823859Sml29623 nxge_cntlops(dev_info_t *dip, nxge_ctl_enum_t ctlop, void *arg, void *result)
1833859Sml29623 {
1843859Sml29623 	nxge_status_t status = NXGE_OK;
1853859Sml29623 	int instance;
1863859Sml29623 	p_nxge_t nxgep;
1873859Sml29623 
1883859Sml29623 #ifndef NXGE_SHARED_REG_SW_SIM
1893859Sml29623 	npi_handle_t handle;
1903859Sml29623 	uint16_t sr16, cr16;
1913859Sml29623 #endif
1923859Sml29623 	instance = ddi_get_instance(dip);
1933859Sml29623 	NXGE_DEBUG_MSG((NULL, VIR_CTL, "Instance %d ", instance));
1943859Sml29623 
1953859Sml29623 	if (nxge_list == NULL) {
1963859Sml29623 		NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
1976929Smisaki 		    "nxge_cntlops: nxge_list null"));
1983859Sml29623 		return (NXGE_ERROR);
1993859Sml29623 	}
2003859Sml29623 	nxgep = (p_nxge_t)ddi_get_soft_state(nxge_list, instance);
2013859Sml29623 	if (nxgep == NULL) {
2023859Sml29623 		NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
2036929Smisaki 		    "nxge_cntlops: nxgep null"));
2043859Sml29623 		return (NXGE_ERROR);
2053859Sml29623 	}
2063859Sml29623 #ifndef NXGE_SHARED_REG_SW_SIM
2073859Sml29623 	handle = nxgep->npi_reg_handle;
2083859Sml29623 #endif
2093859Sml29623 	switch (ctlop) {
2103859Sml29623 	case NXGE_CTLOPS_NIUTYPE:
2113859Sml29623 		nxge_get_niu_property(dip, (niu_type_t *)result);
2123859Sml29623 		return (status);
2133859Sml29623 
2143859Sml29623 	case NXGE_CTLOPS_GET_SHARED_REG:
2153859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2163859Sml29623 		*(uint64_t *)result = global_dev_ctrl;
2173859Sml29623 		return (0);
2183859Sml29623 #else
2193859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2203859Sml29623 		*(uint16_t *)result = sr16;
2213859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2226929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_GET_SHARED_REG"));
2233859Sml29623 		return (0);
2243859Sml29623 #endif
2253859Sml29623 
2263859Sml29623 	case NXGE_CTLOPS_SET_SHARED_REG_LOCK:
2273859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2283859Sml29623 		global_dev_ctrl = *(uint64_t *)arg;
2293859Sml29623 		return (0);
2303859Sml29623 #else
2313859Sml29623 		status = NPI_FAILURE;
2323859Sml29623 		while (status != NPI_SUCCESS)
2333859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
2343859Sml29623 
2353859Sml29623 		sr16 = *(uint16_t *)arg;
2363859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2373859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
2383859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2396929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2403859Sml29623 		return (0);
2413859Sml29623 #endif
2423859Sml29623 
2433859Sml29623 	case NXGE_CTLOPS_UPDATE_SHARED_REG:
2443859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2453859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2463859Sml29623 		return (0);
2473859Sml29623 #else
2483859Sml29623 		status = NPI_FAILURE;
2493859Sml29623 		while (status != NPI_SUCCESS)
2503859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
2513859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2523859Sml29623 		sr16 |= *(uint16_t *)arg;
2533859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2543859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
2553859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2566929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2573859Sml29623 		return (0);
2583859Sml29623 #endif
2593859Sml29623 
2603859Sml29623 	case NXGE_CTLOPS_CLEAR_BIT_SHARED_REG_UL:
2613859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2623859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2633859Sml29623 		return (0);
2643859Sml29623 #else
2653859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2663859Sml29623 		cr16 = *(uint16_t *)arg;
2673859Sml29623 		sr16 &= ~cr16;
2683859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2693859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2706929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2713859Sml29623 		return (0);
2723859Sml29623 #endif
2733859Sml29623 
2743859Sml29623 	case NXGE_CTLOPS_CLEAR_BIT_SHARED_REG:
2753859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2763859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2773859Sml29623 		return (0);
2783859Sml29623 #else
2793859Sml29623 		status = NPI_FAILURE;
2803859Sml29623 		while (status != NPI_SUCCESS)
2813859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
2823859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2833859Sml29623 		cr16 = *(uint16_t *)arg;
2843859Sml29623 		sr16 &= ~cr16;
2853859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2863859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
2873859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2886929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2893859Sml29623 		return (0);
2903859Sml29623 #endif
2913859Sml29623 
2923859Sml29623 	case NXGE_CTLOPS_GET_LOCK_BLOCK:
2933859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2943859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2953859Sml29623 		return (0);
2963859Sml29623 #else
2973859Sml29623 		status = NPI_FAILURE;
2983859Sml29623 		while (status != NPI_SUCCESS)
2993859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
3003859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
3016929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_GET_LOCK_BLOCK"));
3023859Sml29623 		return (0);
3033859Sml29623 #endif
3043859Sml29623 	case NXGE_CTLOPS_GET_LOCK_TRY:
3053859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
3063859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
3073859Sml29623 		return (0);
3083859Sml29623 #else
3093859Sml29623 		status = npi_dev_func_sr_lock_enter(handle);
3103859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
3116929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_GET_LOCK_TRY"));
3123859Sml29623 		if (status == NPI_SUCCESS)
3133859Sml29623 			return (NXGE_OK);
3143859Sml29623 		else
3153859Sml29623 			return (NXGE_ERROR);
3163859Sml29623 #endif
3173859Sml29623 	case NXGE_CTLOPS_FREE_LOCK:
3183859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
3193859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
3203859Sml29623 		return (0);
3213859Sml29623 #else
3223859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
3233859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
3246929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_GET_LOCK_FREE"));
3253859Sml29623 		if (status == NPI_SUCCESS)
3263859Sml29623 			return (NXGE_OK);
3273859Sml29623 		else
3283859Sml29623 			return (NXGE_ERROR);
3293859Sml29623 #endif
3303859Sml29623 
3313859Sml29623 	default:
3323859Sml29623 		status = NXGE_ERROR;
3333859Sml29623 	}
3343859Sml29623 
3353859Sml29623 	return (status);
3363859Sml29623 }
3373859Sml29623 
3383859Sml29623 void
3393859Sml29623 nxge_common_lock_get(p_nxge_t nxgep)
3403859Sml29623 {
3413859Sml29623 	uint32_t status = NPI_FAILURE;
3423859Sml29623 	npi_handle_t handle;
3433859Sml29623 
3443859Sml29623 #if	defined(NXGE_SHARE_REG_SW_SIM)
3453859Sml29623 	return;
3463859Sml29623 #endif
3473859Sml29623 	handle = nxgep->npi_reg_handle;
3483859Sml29623 	while (status != NPI_SUCCESS)
3493859Sml29623 		status = npi_dev_func_sr_lock_enter(handle);
3503859Sml29623 }
3513859Sml29623 
3523859Sml29623 void
3533859Sml29623 nxge_common_lock_free(p_nxge_t nxgep)
3543859Sml29623 {
3553859Sml29623 	npi_handle_t handle;
3563859Sml29623 
3573859Sml29623 #if	defined(NXGE_SHARE_REG_SW_SIM)
3583859Sml29623 	return;
3593859Sml29623 #endif
3603859Sml29623 	handle = nxgep->npi_reg_handle;
3613859Sml29623 	(void) npi_dev_func_sr_lock_free(handle);
3623859Sml29623 }
3633859Sml29623 
3644185Sspeer 
3653859Sml29623 static void
3663859Sml29623 nxge_get_niu_property(dev_info_t *dip, niu_type_t *niu_type)
3673859Sml29623 {
3683859Sml29623 	uchar_t *prop_val;
3693859Sml29623 	uint_t prop_len;
3703859Sml29623 
3714732Sdavemq 	*niu_type = NIU_TYPE_NONE;
3723859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0,
3736929Smisaki 	    "niu-type", (uchar_t **)&prop_val,
3746929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
3753859Sml29623 		if (strncmp("niu", (caddr_t)prop_val, (size_t)prop_len) == 0) {
3763859Sml29623 			*niu_type = N2_NIU;
3773859Sml29623 		}
3783859Sml29623 		ddi_prop_free(prop_val);
3793859Sml29623 	}
3803859Sml29623 }
3813859Sml29623 
3823859Sml29623 static config_token_t
3833859Sml29623 nxge_get_config_token(char *prop)
3843859Sml29623 {
3853859Sml29623 	config_token_t token = DEFAULT;
3863859Sml29623 
3873859Sml29623 	while (token < CONFIG_TOKEN_NONE) {
3883859Sml29623 		if (strncmp(prop, token_names[token], 4) == 0)
3893859Sml29623 			break;
3903859Sml29623 		token++;
3913859Sml29623 	}
3923859Sml29623 	return (token);
3933859Sml29623 }
3943859Sml29623 
3953859Sml29623 /* per port */
3963859Sml29623 
3973859Sml29623 static nxge_status_t
3983859Sml29623 nxge_update_rxdma_grp_properties(p_nxge_t nxgep, config_token_t token,
3993859Sml29623 	dev_info_t *s_dip[])
4003859Sml29623 {
4013859Sml29623 	nxge_status_t status = NXGE_OK;
4023859Sml29623 	int ddi_status;
4033859Sml29623 	int num_ports = nxgep->nports;
4043859Sml29623 	int port, bits, j;
4053859Sml29623 	uint8_t start_grp = 0, num_grps = 0;
4063859Sml29623 	p_nxge_param_t param_arr;
4073859Sml29623 	uint32_t grp_bitmap[MAX_SIBLINGS];
4083859Sml29623 	int custom_start_grp[MAX_SIBLINGS];
4093859Sml29623 	int custom_num_grp[MAX_SIBLINGS];
4103859Sml29623 	uint8_t bad_config = B_FALSE;
4113859Sml29623 	char *start_prop, *num_prop, *cfg_prop;
4123859Sml29623 
4133859Sml29623 	start_grp = 0;
4143859Sml29623 	param_arr = nxgep->param_arr;
4153859Sml29623 	start_prop = param_arr[param_rdc_grps_start].fcode_name;
4163859Sml29623 	num_prop = param_arr[param_rx_rdc_grps].fcode_name;
4173859Sml29623 
4183859Sml29623 	switch (token) {
4193859Sml29623 	case FAIR:
4203859Sml29623 		cfg_prop = "fair";
4213859Sml29623 		for (port = 0; port < num_ports; port++) {
4223859Sml29623 			custom_num_grp[port] =
4236929Smisaki 			    (num_ports == 4) ?
4246929Smisaki 			    p4_rdcgrp_fair[port] :
4256929Smisaki 			    p2_rdcgrp_fair[port];
4263859Sml29623 			custom_start_grp[port] = start_grp;
4273859Sml29623 			start_grp += custom_num_grp[port];
4283859Sml29623 		}
4293859Sml29623 		break;
4303859Sml29623 
4313859Sml29623 	case EQUAL:
4323859Sml29623 		cfg_prop = "equal";
4333859Sml29623 		for (port = 0; port < num_ports; port++) {
4343859Sml29623 			custom_num_grp[port] =
4356929Smisaki 			    (num_ports == 4) ?
4366929Smisaki 			    p4_rdcgrp_equal[port] :
4376929Smisaki 			    p2_rdcgrp_equal[port];
4383859Sml29623 			custom_start_grp[port] = start_grp;
4393859Sml29623 			start_grp += custom_num_grp[port];
4403859Sml29623 		}
4413859Sml29623 		break;
4423859Sml29623 
4433859Sml29623 
4443859Sml29623 	case CLASSIFY:
4453859Sml29623 		cfg_prop = "classify";
4463859Sml29623 		for (port = 0; port < num_ports; port++) {
4473859Sml29623 			custom_num_grp[port] = (num_ports == 4) ?
4486929Smisaki 			    p4_rdcgrp_cls[port] : p2_rdcgrp_cls[port];
4493859Sml29623 			custom_start_grp[port] = start_grp;
4503859Sml29623 			start_grp += custom_num_grp[port];
4513859Sml29623 		}
4523859Sml29623 		break;
4533859Sml29623 
4543859Sml29623 	case CUSTOM:
4553859Sml29623 		cfg_prop = "custom";
4563859Sml29623 		/* See if it is good config */
4573859Sml29623 		num_grps = 0;
4583859Sml29623 		for (port = 0; port < num_ports; port++) {
4593859Sml29623 			custom_start_grp[port] =
4606929Smisaki 			    ddi_prop_get_int(DDI_DEV_T_NONE, s_dip[port],
4616929Smisaki 			    DDI_PROP_DONTPASS, start_prop, -1);
4623859Sml29623 			if ((custom_start_grp[port] == -1) ||
4636929Smisaki 			    (custom_start_grp[port] >=
4646929Smisaki 			    NXGE_MAX_RDC_GRPS)) {
4653859Sml29623 				bad_config = B_TRUE;
4663859Sml29623 				break;
4673859Sml29623 			}
4683859Sml29623 			custom_num_grp[port] = ddi_prop_get_int(
4696929Smisaki 			    DDI_DEV_T_NONE,
4706929Smisaki 			    s_dip[port],
4716929Smisaki 			    DDI_PROP_DONTPASS,
4726929Smisaki 			    num_prop, -1);
4733859Sml29623 
4743859Sml29623 			if ((custom_num_grp[port] == -1) ||
4756929Smisaki 			    (custom_num_grp[port] >
4766929Smisaki 			    NXGE_MAX_RDC_GRPS) ||
4776929Smisaki 			    ((custom_num_grp[port] +
4786929Smisaki 			    custom_start_grp[port]) >=
4796929Smisaki 			    NXGE_MAX_RDC_GRPS)) {
4803859Sml29623 				bad_config = B_TRUE;
4813859Sml29623 				break;
4823859Sml29623 			}
4833859Sml29623 			num_grps += custom_num_grp[port];
4843859Sml29623 			if (num_grps > NXGE_MAX_RDC_GRPS) {
4853859Sml29623 				bad_config = B_TRUE;
4863859Sml29623 				break;
4873859Sml29623 			}
4883859Sml29623 			grp_bitmap[port] = 0;
4893859Sml29623 			for (bits = 0;
4906929Smisaki 			    bits < custom_num_grp[port];
4916929Smisaki 			    bits++) {
4923859Sml29623 				grp_bitmap[port] |=
4936929Smisaki 				    (1 << (bits + custom_start_grp[port]));
4943859Sml29623 			}
4953859Sml29623 
4963859Sml29623 		}
4973859Sml29623 
4983859Sml29623 		if (bad_config == B_FALSE) {
4993859Sml29623 			/* check for overlap */
5003859Sml29623 			for (port = 0; port < num_ports - 1; port++) {
5013859Sml29623 				for (j = port + 1; j < num_ports; j++) {
5023859Sml29623 					if (grp_bitmap[port] &
5036929Smisaki 					    grp_bitmap[j]) {
5043859Sml29623 						bad_config = B_TRUE;
5053859Sml29623 						break;
5063859Sml29623 					}
5073859Sml29623 				}
5083859Sml29623 				if (bad_config == B_TRUE)
5093859Sml29623 					break;
5103859Sml29623 			}
5113859Sml29623 		}
5123859Sml29623 		if (bad_config == B_TRUE) {
5133859Sml29623 			/* use default config */
5143859Sml29623 			for (port = 0; port < num_ports; port++) {
5153859Sml29623 				custom_num_grp[port] =
5166929Smisaki 				    (num_ports == 4) ?
5176929Smisaki 				    p4_rx_fair[port] : p2_rx_fair[port];
5183859Sml29623 				custom_start_grp[port] = start_grp;
5193859Sml29623 				start_grp += custom_num_grp[port];
5203859Sml29623 			}
5213859Sml29623 		}
5223859Sml29623 		break;
5233859Sml29623 
5243859Sml29623 	default:
5253859Sml29623 		/* use default config */
5263859Sml29623 		cfg_prop = "fair";
5273859Sml29623 		for (port = 0; port < num_ports; port++) {
5283859Sml29623 			custom_num_grp[port] = (num_ports == 4) ?
5296929Smisaki 			    p4_rx_fair[port] : p2_rx_fair[port];
5303859Sml29623 			custom_start_grp[port] = start_grp;
5313859Sml29623 			start_grp += custom_num_grp[port];
5323859Sml29623 		}
5333859Sml29623 		break;
5343859Sml29623 	}
5353859Sml29623 
5363859Sml29623 	/* Now Update the rx properties */
5373859Sml29623 	for (port = 0; port < num_ports; port++) {
5383859Sml29623 		ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
5396929Smisaki 		    "rxdma-grp-cfg", cfg_prop);
5403859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
5413859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
5426929Smisaki 			    " property %s not updating",
5436929Smisaki 			    cfg_prop));
5443859Sml29623 			status |= NXGE_DDI_FAILED;
5453859Sml29623 		}
5463859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
5476929Smisaki 		    num_prop, custom_num_grp[port]);
5483859Sml29623 
5493859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
5503859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
5516929Smisaki 			    " property %s not updating",
5526929Smisaki 			    num_prop));
5533859Sml29623 			status |= NXGE_DDI_FAILED;
5543859Sml29623 		}
5553859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
5566929Smisaki 		    start_prop, custom_start_grp[port]);
5573859Sml29623 
5583859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
5593859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
5606929Smisaki 			    " property %s not updating",
5616929Smisaki 			    start_prop));
5623859Sml29623 			status |= NXGE_DDI_FAILED;
5633859Sml29623 		}
5643859Sml29623 	}
5653859Sml29623 	if (status & NXGE_DDI_FAILED)
5663859Sml29623 		status |= NXGE_ERROR;
5673859Sml29623 
5683859Sml29623 	return (status);
5693859Sml29623 }
5703859Sml29623 
5713859Sml29623 static nxge_status_t
5723859Sml29623 nxge_update_rxdma_properties(p_nxge_t nxgep, config_token_t token,
5733859Sml29623 	dev_info_t *s_dip[])
5743859Sml29623 {
5753859Sml29623 	nxge_status_t status = NXGE_OK;
5763859Sml29623 	int ddi_status;
5773859Sml29623 	int num_ports = nxgep->nports;
5783859Sml29623 	int port, bits, j;
5793859Sml29623 	uint8_t start_rdc = 0, num_rdc = 0;
5803859Sml29623 	p_nxge_param_t param_arr;
5813859Sml29623 	uint32_t rdc_bitmap[MAX_SIBLINGS];
5823859Sml29623 	int custom_start_rdc[MAX_SIBLINGS];
5833859Sml29623 	int custom_num_rdc[MAX_SIBLINGS];
5843859Sml29623 	uint8_t bad_config = B_FALSE;
5853859Sml29623 	int *prop_val;
5863859Sml29623 	uint_t prop_len;
5873859Sml29623 	char *start_rdc_prop, *num_rdc_prop, *cfg_prop;
5883859Sml29623 
5893859Sml29623 	start_rdc = 0;
5903859Sml29623 	param_arr = nxgep->param_arr;
5913859Sml29623 	start_rdc_prop = param_arr[param_rxdma_channels_begin].fcode_name;
5923859Sml29623 	num_rdc_prop = param_arr[param_rxdma_channels].fcode_name;
5933859Sml29623 
5943859Sml29623 	switch (token) {
5953859Sml29623 	case FAIR:
5963859Sml29623 		cfg_prop = "fair";
5973859Sml29623 		for (port = 0; port < num_ports; port++) {
5983859Sml29623 			custom_num_rdc[port] = (num_ports == 4) ?
5996929Smisaki 			    p4_rx_fair[port] : p2_rx_fair[port];
6003859Sml29623 			custom_start_rdc[port] = start_rdc;
6013859Sml29623 			start_rdc += custom_num_rdc[port];
6023859Sml29623 		}
6033859Sml29623 		break;
6043859Sml29623 
6053859Sml29623 	case EQUAL:
6063859Sml29623 		cfg_prop = "equal";
6073859Sml29623 		for (port = 0; port < num_ports; port++) {
6083859Sml29623 			custom_num_rdc[port] = (num_ports == 4) ?
6096929Smisaki 			    p4_rx_equal[port] :
6106929Smisaki 			    p2_rx_equal[port];
6113859Sml29623 			custom_start_rdc[port] = start_rdc;
6123859Sml29623 			start_rdc += custom_num_rdc[port];
6133859Sml29623 		}
6143859Sml29623 		break;
6153859Sml29623 
6163859Sml29623 	case CUSTOM:
6173859Sml29623 		cfg_prop = "custom";
6183859Sml29623 		/* See if it is good config */
6193859Sml29623 		num_rdc = 0;
6203859Sml29623 		for (port = 0; port < num_ports; port++) {
6213859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
6226929Smisaki 			    DDI_DEV_T_ANY,
6236929Smisaki 			    s_dip[port], 0,
6246929Smisaki 			    start_rdc_prop,
6256929Smisaki 			    &prop_val,
6266929Smisaki 			    &prop_len);
6273859Sml29623 			if (ddi_status == DDI_SUCCESS)
6283859Sml29623 				custom_start_rdc[port] = *prop_val;
6293859Sml29623 			else {
6303859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6316929Smisaki 				    " %s custom start port %d"
6326929Smisaki 				    " read failed ",
6336929Smisaki 				    " rxdma-cfg", port));
6343859Sml29623 				bad_config = B_TRUE;
6353859Sml29623 				status |= NXGE_DDI_FAILED;
6363859Sml29623 			}
6373859Sml29623 			if ((custom_start_rdc[port] == -1) ||
6386929Smisaki 			    (custom_start_rdc[port] >=
6396929Smisaki 			    NXGE_MAX_RDCS)) {
6403859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6416929Smisaki 				    " %s custom start %d"
6426929Smisaki 				    " out of range %x ",
6436929Smisaki 				    " rxdma-cfg",
6446929Smisaki 				    port,
6456929Smisaki 				    custom_start_rdc[port]));
6463859Sml29623 				bad_config = B_TRUE;
6473859Sml29623 				break;
6483859Sml29623 			}
6493859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
6506929Smisaki 			    DDI_DEV_T_ANY,
6516929Smisaki 			    s_dip[port],
6526929Smisaki 			    0,
6536929Smisaki 			    num_rdc_prop,
6546929Smisaki 			    &prop_val,
6556929Smisaki 			    &prop_len);
6563859Sml29623 
6573859Sml29623 			if (ddi_status == DDI_SUCCESS)
6583859Sml29623 				custom_num_rdc[port] = *prop_val;
6593859Sml29623 			else {
6603859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6616929Smisaki 				    " %s custom num port %d"
6626929Smisaki 				    " read failed ",
6636929Smisaki 				    "rxdma-cfg", port));
6643859Sml29623 				bad_config = B_TRUE;
6653859Sml29623 				status |= NXGE_DDI_FAILED;
6663859Sml29623 			}
6673859Sml29623 
6683859Sml29623 			if ((custom_num_rdc[port] == -1) ||
6696929Smisaki 			    (custom_num_rdc[port] >
6706929Smisaki 			    NXGE_MAX_RDCS) ||
6716929Smisaki 			    ((custom_num_rdc[port] +
6726929Smisaki 			    custom_start_rdc[port]) >
6736929Smisaki 			    NXGE_MAX_RDCS)) {
6743859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6756929Smisaki 				    " %s custom num %d"
6766929Smisaki 				    " out of range %x ",
6776929Smisaki 				    " rxdma-cfg",
6786929Smisaki 				    port, custom_num_rdc[port]));
6793859Sml29623 				bad_config = B_TRUE;
6803859Sml29623 				break;
6813859Sml29623 			}
6823859Sml29623 			num_rdc += custom_num_rdc[port];
6833859Sml29623 			if (num_rdc > NXGE_MAX_RDCS) {
6843859Sml29623 				bad_config = B_TRUE;
6853859Sml29623 				break;
6863859Sml29623 			}
6873859Sml29623 			rdc_bitmap[port] = 0;
6883859Sml29623 			for (bits = 0;
6896929Smisaki 			    bits < custom_num_rdc[port]; bits++) {
6903859Sml29623 				rdc_bitmap[port] |=
6916929Smisaki 				    (1 << (bits + custom_start_rdc[port]));
6923859Sml29623 			}
6933859Sml29623 		}
6943859Sml29623 
6953859Sml29623 		if (bad_config == B_FALSE) {
6963859Sml29623 			/* check for overlap */
6973859Sml29623 			for (port = 0; port < num_ports - 1; port++) {
6983859Sml29623 				for (j = port + 1; j < num_ports; j++) {
6993859Sml29623 					if (rdc_bitmap[port] &
7006929Smisaki 					    rdc_bitmap[j]) {
7013859Sml29623 						NXGE_DEBUG_MSG((nxgep,
7026929Smisaki 						    CFG_CTL,
7036929Smisaki 						    " rxdma-cfg"
7046929Smisaki 						    " property custom"
7056929Smisaki 						    " bit overlap"
7066929Smisaki 						    " %d %d ",
7076929Smisaki 						    port, j));
7083859Sml29623 						bad_config = B_TRUE;
7093859Sml29623 						break;
7103859Sml29623 					}
7113859Sml29623 				}
7123859Sml29623 				if (bad_config == B_TRUE)
7133859Sml29623 					break;
7143859Sml29623 			}
7153859Sml29623 		}
7163859Sml29623 		if (bad_config == B_TRUE) {
7173859Sml29623 			/* use default config */
7183859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
7196929Smisaki 			    " rxdma-cfg property:"
7206929Smisaki 			    " bad custom config:"
7216929Smisaki 			    " use default"));
7223859Sml29623 			for (port = 0; port < num_ports; port++) {
7233859Sml29623 				custom_num_rdc[port] =
7246929Smisaki 				    (num_ports == 4) ?
7256929Smisaki 				    p4_rx_fair[port] :
7266929Smisaki 				    p2_rx_fair[port];
7273859Sml29623 				custom_start_rdc[port] = start_rdc;
7283859Sml29623 				start_rdc += custom_num_rdc[port];
7293859Sml29623 			}
7303859Sml29623 		}
7313859Sml29623 		break;
7323859Sml29623 
7333859Sml29623 	default:
7343859Sml29623 		/* use default config */
7353859Sml29623 		cfg_prop = "fair";
7363859Sml29623 		for (port = 0; port < num_ports; port++) {
7373859Sml29623 			custom_num_rdc[port] = (num_ports == 4) ?
7386929Smisaki 			    p4_rx_fair[port] : p2_rx_fair[port];
7393859Sml29623 			custom_start_rdc[port] = start_rdc;
7403859Sml29623 			start_rdc += custom_num_rdc[port];
7413859Sml29623 		}
7423859Sml29623 		break;
7433859Sml29623 	}
7443859Sml29623 
7453859Sml29623 	/* Now Update the rx properties */
7463859Sml29623 	for (port = 0; port < num_ports; port++) {
7473859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
7486929Smisaki 		    " update property rxdma-cfg with %s ", cfg_prop));
7493859Sml29623 		ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
7506929Smisaki 		    "rxdma-cfg", cfg_prop);
7513859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
7523859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
7536929Smisaki 			    " property rxdma-cfg is not updating to %s",
7546929Smisaki 			    cfg_prop));
7553859Sml29623 			status |= NXGE_DDI_FAILED;
7563859Sml29623 		}
7573859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
7586929Smisaki 		    num_rdc_prop, custom_num_rdc[port]));
7593859Sml29623 
7603859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
7616929Smisaki 		    num_rdc_prop, custom_num_rdc[port]);
7623859Sml29623 
7633859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
7643859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
7656929Smisaki 			    " property %s not updating with %d",
7666929Smisaki 			    num_rdc_prop, custom_num_rdc[port]));
7673859Sml29623 			status |= NXGE_DDI_FAILED;
7683859Sml29623 		}
7693859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
7706929Smisaki 		    start_rdc_prop, custom_start_rdc[port]));
7713859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
7726929Smisaki 		    start_rdc_prop, custom_start_rdc[port]);
7733859Sml29623 
7743859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
7753859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
7766929Smisaki 			    " property %s not updating with %d ",
7776929Smisaki 			    start_rdc_prop, custom_start_rdc[port]));
7783859Sml29623 			status |= NXGE_DDI_FAILED;
7793859Sml29623 		}
7803859Sml29623 	}
7813859Sml29623 	if (status & NXGE_DDI_FAILED)
7823859Sml29623 		status |= NXGE_ERROR;
7833859Sml29623 	return (status);
7843859Sml29623 }
7853859Sml29623 
7863859Sml29623 static nxge_status_t
7873859Sml29623 nxge_update_txdma_properties(p_nxge_t nxgep, config_token_t token,
7883859Sml29623 	dev_info_t *s_dip[])
7893859Sml29623 {
7903859Sml29623 	nxge_status_t status = NXGE_OK;
7913859Sml29623 	int ddi_status = DDI_SUCCESS;
7923859Sml29623 	int num_ports = nxgep->nports;
7933859Sml29623 	int port, bits, j;
7948275SEric Cheng 	uint8_t  start_tdc, num_tdc = 0;
7953859Sml29623 	p_nxge_param_t param_arr;
7963859Sml29623 	uint32_t tdc_bitmap[MAX_SIBLINGS];
7973859Sml29623 	int custom_start_tdc[MAX_SIBLINGS];
7983859Sml29623 	int custom_num_tdc[MAX_SIBLINGS];
7993859Sml29623 	uint8_t bad_config = B_FALSE;
8003859Sml29623 	int *prop_val;
8013859Sml29623 	uint_t prop_len;
8023859Sml29623 	char *start_tdc_prop, *num_tdc_prop, *cfg_prop;
8033859Sml29623 
8043859Sml29623 	start_tdc = 0;
8053859Sml29623 	param_arr = nxgep->param_arr;
8063859Sml29623 	start_tdc_prop = param_arr[param_txdma_channels_begin].fcode_name;
8073859Sml29623 	num_tdc_prop = param_arr[param_txdma_channels].fcode_name;
8083859Sml29623 
8093859Sml29623 	switch (token) {
8103859Sml29623 	case FAIR:
8113859Sml29623 		cfg_prop = "fair";
8123859Sml29623 		for (port = 0; port < num_ports; port++) {
8133859Sml29623 			custom_num_tdc[port] = (num_ports == 4) ?
8146929Smisaki 			    p4_tx_fair[port] : p2_tx_fair[port];
8153859Sml29623 			custom_start_tdc[port] = start_tdc;
8163859Sml29623 			start_tdc += custom_num_tdc[port];
8173859Sml29623 		}
8183859Sml29623 		break;
8193859Sml29623 
8203859Sml29623 	case EQUAL:
8213859Sml29623 		cfg_prop = "equal";
8223859Sml29623 		for (port = 0; port < num_ports; port++) {
8233859Sml29623 			custom_num_tdc[port] = (num_ports == 4) ?
8246929Smisaki 			    p4_tx_equal[port] : p2_tx_equal[port];
8253859Sml29623 			custom_start_tdc[port] = start_tdc;
8263859Sml29623 			start_tdc += custom_num_tdc[port];
8273859Sml29623 		}
8283859Sml29623 		break;
8293859Sml29623 
8303859Sml29623 	case CUSTOM:
8313859Sml29623 		cfg_prop = "custom";
8323859Sml29623 		/* See if it is good config */
8333859Sml29623 		num_tdc = 0;
8343859Sml29623 		for (port = 0; port < num_ports; port++) {
8353859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
8366929Smisaki 			    DDI_DEV_T_ANY, s_dip[port], 0, start_tdc_prop,
8376929Smisaki 			    &prop_val, &prop_len);
8383859Sml29623 			if (ddi_status == DDI_SUCCESS)
8393859Sml29623 				custom_start_tdc[port] = *prop_val;
8403859Sml29623 			else {
8413859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8426929Smisaki 				    " %s custom start port %d"
8436929Smisaki 				    " read failed ", " txdma-cfg", port));
8443859Sml29623 				bad_config = B_TRUE;
8453859Sml29623 				status |= NXGE_DDI_FAILED;
8463859Sml29623 			}
8473859Sml29623 
8483859Sml29623 			if ((custom_start_tdc[port] == -1) ||
8496929Smisaki 			    (custom_start_tdc[port] >=
8506929Smisaki 			    NXGE_MAX_RDCS)) {
8513859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8526929Smisaki 				    " %s custom start %d"
8536929Smisaki 				    " out of range %x ", " txdma-cfg",
8546929Smisaki 				    port, custom_start_tdc[port]));
8553859Sml29623 				bad_config = B_TRUE;
8563859Sml29623 				break;
8573859Sml29623 			}
8583859Sml29623 
8593859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
8606929Smisaki 			    DDI_DEV_T_ANY, s_dip[port], 0, num_tdc_prop,
8616929Smisaki 			    &prop_val, &prop_len);
8623859Sml29623 			if (ddi_status == DDI_SUCCESS)
8633859Sml29623 				custom_num_tdc[port] = *prop_val;
8643859Sml29623 			else {
8653859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8666929Smisaki 				    " %s custom num port %d"
8676929Smisaki 				    " read failed ", " txdma-cfg", port));
8683859Sml29623 				bad_config = B_TRUE;
8693859Sml29623 				status |= NXGE_DDI_FAILED;
8703859Sml29623 			}
8713859Sml29623 
8723859Sml29623 			if ((custom_num_tdc[port] == -1) ||
8736929Smisaki 			    (custom_num_tdc[port] >
8746929Smisaki 			    NXGE_MAX_TDCS) ||
8756929Smisaki 			    ((custom_num_tdc[port] +
8766929Smisaki 			    custom_start_tdc[port]) >
8776929Smisaki 			    NXGE_MAX_TDCS)) {
8783859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8796929Smisaki 				    " %s custom num %d"
8806929Smisaki 				    " out of range %x ", " rxdma-cfg",
8816929Smisaki 				    port, custom_num_tdc[port]));
8823859Sml29623 				bad_config = B_TRUE;
8833859Sml29623 				break;
8843859Sml29623 			}
8853859Sml29623 			num_tdc += custom_num_tdc[port];
8863859Sml29623 			if (num_tdc > NXGE_MAX_TDCS) {
8873859Sml29623 				bad_config = B_TRUE;
8883859Sml29623 				break;
8893859Sml29623 			}
8903859Sml29623 			tdc_bitmap[port] = 0;
8913859Sml29623 			for (bits = 0;
8926929Smisaki 			    bits < custom_num_tdc[port]; bits++) {
8933859Sml29623 				tdc_bitmap[port] |=
8946929Smisaki 				    (1 <<
8956929Smisaki 				    (bits + custom_start_tdc[port]));
8963859Sml29623 			}
8973859Sml29623 
8983859Sml29623 		}
8993859Sml29623 
9003859Sml29623 		if (bad_config == B_FALSE) {
9013859Sml29623 			/* check for overlap */
9023859Sml29623 			for (port = 0; port < num_ports - 1; port++) {
9033859Sml29623 				for (j = port + 1; j < num_ports; j++) {
9043859Sml29623 					if (tdc_bitmap[port] &
9056929Smisaki 					    tdc_bitmap[j]) {
9063859Sml29623 						NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9076929Smisaki 						    " rxdma-cfg"
9086929Smisaki 						    " property custom"
9096929Smisaki 						    " bit overlap"
9106929Smisaki 						    " %d %d ",
9116929Smisaki 						    port, j));
9123859Sml29623 						bad_config = B_TRUE;
9133859Sml29623 						break;
9143859Sml29623 					}
9153859Sml29623 				}
9163859Sml29623 				if (bad_config == B_TRUE)
9173859Sml29623 					break;
9183859Sml29623 			}
9193859Sml29623 		}
9203859Sml29623 		if (bad_config == B_TRUE) {
9213859Sml29623 			/* use default config */
9223859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9236929Smisaki 			    " txdma-cfg property:"
9246929Smisaki 			    " bad custom config:" " use default"));
9253859Sml29623 
9263859Sml29623 			for (port = 0; port < num_ports; port++) {
9273859Sml29623 				custom_num_tdc[port] = (num_ports == 4) ?
9286929Smisaki 				    p4_tx_fair[port] : p2_tx_fair[port];
9293859Sml29623 				custom_start_tdc[port] = start_tdc;
9303859Sml29623 				start_tdc += custom_num_tdc[port];
9313859Sml29623 			}
9323859Sml29623 		}
9333859Sml29623 		break;
9343859Sml29623 
9353859Sml29623 	default:
9363859Sml29623 		/* use default config */
9373859Sml29623 		cfg_prop = "fair";
9383859Sml29623 		for (port = 0; port < num_ports; port++) {
9393859Sml29623 			custom_num_tdc[port] = (num_ports == 4) ?
9406929Smisaki 			    p4_tx_fair[port] : p2_tx_fair[port];
9413859Sml29623 			custom_start_tdc[port] = start_tdc;
9423859Sml29623 			start_tdc += custom_num_tdc[port];
9433859Sml29623 		}
9443859Sml29623 		break;
9453859Sml29623 	}
9463859Sml29623 
9473859Sml29623 	/* Now Update the tx properties */
9483859Sml29623 	for (port = 0; port < num_ports; port++) {
9493859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9506929Smisaki 		    " update property txdma-cfg with %s ", cfg_prop));
9513859Sml29623 		ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
9526929Smisaki 		    "txdma-cfg", cfg_prop);
9533859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
9543859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9556929Smisaki 			    " property txdma-cfg is not updating to %s",
9566929Smisaki 			    cfg_prop));
9573859Sml29623 			status |= NXGE_DDI_FAILED;
9583859Sml29623 		}
9593859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
9606929Smisaki 		    num_tdc_prop, custom_num_tdc[port]));
9613859Sml29623 
9623859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
9636929Smisaki 		    num_tdc_prop, custom_num_tdc[port]);
9643859Sml29623 
9653859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
9663859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
9676929Smisaki 			    " property %s not updating with %d",
9686929Smisaki 			    num_tdc_prop,
9696929Smisaki 			    custom_num_tdc[port]));
9703859Sml29623 			status |= NXGE_DDI_FAILED;
9713859Sml29623 		}
9723859Sml29623 
9733859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
9746929Smisaki 		    start_tdc_prop, custom_start_tdc[port]));
9753859Sml29623 
9763859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
9776929Smisaki 		    start_tdc_prop, custom_start_tdc[port]);
9783859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
9793859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
9806929Smisaki 			    " property %s not updating with %d ",
9816929Smisaki 			    start_tdc_prop, custom_start_tdc[port]));
9823859Sml29623 			status |= NXGE_DDI_FAILED;
9833859Sml29623 		}
9843859Sml29623 	}
9853859Sml29623 	if (status & NXGE_DDI_FAILED)
9863859Sml29623 		status |= NXGE_ERROR;
9873859Sml29623 	return (status);
9883859Sml29623 }
9893859Sml29623 
9903859Sml29623 static nxge_status_t
9913859Sml29623 nxge_update_cfg_properties(p_nxge_t nxgep, uint32_t flags,
9923859Sml29623 	config_token_t token, dev_info_t *s_dip[])
9933859Sml29623 {
9943859Sml29623 	nxge_status_t status = NXGE_OK;
9953859Sml29623 
9963859Sml29623 	switch (flags) {
9973859Sml29623 	case COMMON_TXDMA_CFG:
9983859Sml29623 		if (nxge_dma_obp_props_only == 0)
9993859Sml29623 			status = nxge_update_txdma_properties(nxgep,
10006929Smisaki 			    token, s_dip);
10013859Sml29623 		break;
10023859Sml29623 	case COMMON_RXDMA_CFG:
10033859Sml29623 		if (nxge_dma_obp_props_only == 0)
10043859Sml29623 			status = nxge_update_rxdma_properties(nxgep,
10056929Smisaki 			    token, s_dip);
10063859Sml29623 
10073859Sml29623 		break;
10083859Sml29623 	case COMMON_RXDMA_GRP_CFG:
10093859Sml29623 		status = nxge_update_rxdma_grp_properties(nxgep,
10106929Smisaki 		    token, s_dip);
10113859Sml29623 		break;
10123859Sml29623 	default:
10133859Sml29623 		return (NXGE_ERROR);
10143859Sml29623 	}
10153859Sml29623 	return (status);
10163859Sml29623 }
10173859Sml29623 
10183859Sml29623 /*
10193859Sml29623  * verify consistence.
10203859Sml29623  * (May require publishing the properties on all the ports.
10213859Sml29623  *
10223859Sml29623  * What if properties are published on function 0 device only?
10233859Sml29623  *
10243859Sml29623  *
10253859Sml29623  * rxdma-cfg, txdma-cfg, rxdma-grp-cfg (required )
10263859Sml29623  * What about class configs?
10273859Sml29623  *
10283859Sml29623  * If consistent, update the property on all the siblings.
10293859Sml29623  * set  a flag on hardware shared register
10303859Sml29623  * The rest of the siblings will check the flag
10313859Sml29623  * if the flag is set, they will use the updated property
10323859Sml29623  * without doing any validation.
10333859Sml29623  */
10343859Sml29623 
10353859Sml29623 nxge_status_t
10363859Sml29623 nxge_cfg_verify_set_classify_prop(p_nxge_t nxgep, char *prop,
10373859Sml29623 	uint64_t known_cfg, uint32_t override, dev_info_t *c_dip[])
10383859Sml29623 {
10393859Sml29623 	nxge_status_t status = NXGE_OK;
10403859Sml29623 	int ddi_status = DDI_SUCCESS;
10413859Sml29623 	int i = 0, found = 0, update_prop = B_TRUE;
10423859Sml29623 	int *cfg_val;
10433859Sml29623 	uint_t new_value, cfg_value[MAX_SIBLINGS];
10443859Sml29623 	uint_t prop_len;
10453859Sml29623 	uint_t known_cfg_value;
10463859Sml29623 
10473859Sml29623 	known_cfg_value = (uint_t)known_cfg;
10483859Sml29623 
10493859Sml29623 	if (override == B_TRUE) {
10503859Sml29623 		new_value = known_cfg_value;
10513859Sml29623 		for (i = 0; i < nxgep->nports; i++) {
10523859Sml29623 			ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE,
10536929Smisaki 			    c_dip[i], prop, new_value);
10543859Sml29623 #ifdef NXGE_DEBUG_ERROR
10553859Sml29623 			if (ddi_status != DDI_PROP_SUCCESS)
10563859Sml29623 				NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
10576929Smisaki 				    " property %s failed update ", prop));
10583859Sml29623 #endif
10593859Sml29623 		}
10603859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS)
10613859Sml29623 			return (NXGE_ERROR | NXGE_DDI_FAILED);
10623859Sml29623 	}
10633859Sml29623 	for (i = 0; i < nxgep->nports; i++) {
10643859Sml29623 		cfg_value[i] = known_cfg_value;
10653859Sml29623 		if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, c_dip[i], 0,
10666929Smisaki 		    prop, &cfg_val,
10676929Smisaki 		    &prop_len) == DDI_PROP_SUCCESS) {
10683859Sml29623 			cfg_value[i] = *cfg_val;
10693859Sml29623 			ddi_prop_free(cfg_val);
10703859Sml29623 			found++;
10713859Sml29623 		}
10723859Sml29623 	}
10733859Sml29623 
10743859Sml29623 	if (found != i) {
10753859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10766929Smisaki 		    " property %s not specified on all ports", prop));
10773859Sml29623 		if (found == 0) {
10783859Sml29623 			/* not specified: Use default */
10793859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10806929Smisaki 			    " property %s not specified on any port:"
10816929Smisaki 			    " Using default", prop));
10823859Sml29623 			new_value = known_cfg_value;
10833859Sml29623 		} else {
10843859Sml29623 			/* specified on some */
10853859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10866929Smisaki 			    " property %s not specified"
10876929Smisaki 			    " on some ports: Using default", prop));
10883859Sml29623 			/* ? use p0 value instead ? */
10893859Sml29623 			new_value = known_cfg_value;
10903859Sml29623 		}
10913859Sml29623 	} else {
10923859Sml29623 		/* check type and consistence */
10933859Sml29623 		/* found on all devices */
10943859Sml29623 		for (i = 1; i < found; i++) {
10953859Sml29623 			if (cfg_value[i] != cfg_value[i - 1]) {
10963859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10976929Smisaki 				    " property %s inconsistent:"
10986929Smisaki 				    " Using default", prop));
10993859Sml29623 				new_value = known_cfg_value;
11003859Sml29623 				break;
11013859Sml29623 			}
11023859Sml29623 			/*
11033859Sml29623 			 * Found on all the ports and consistent. Nothing to
11043859Sml29623 			 * do.
11053859Sml29623 			 */
11063859Sml29623 			update_prop = B_FALSE;
11073859Sml29623 		}
11083859Sml29623 	}
11093859Sml29623 
11103859Sml29623 	if (update_prop == B_TRUE) {
11113859Sml29623 		for (i = 0; i < nxgep->nports; i++) {
11123859Sml29623 			ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE,
11136929Smisaki 			    c_dip[i], prop, new_value);
11143859Sml29623 #ifdef NXGE_DEBUG_ERROR
11153859Sml29623 			if (ddi_status != DDI_SUCCESS)
11163859Sml29623 				NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
11176929Smisaki 				    " property %s not updating with %d"
11186929Smisaki 				    " Using default",
11196929Smisaki 				    prop, new_value));
11203859Sml29623 #endif
11213859Sml29623 			if (ddi_status != DDI_PROP_SUCCESS)
11223859Sml29623 				status |= NXGE_DDI_FAILED;
11233859Sml29623 		}
11243859Sml29623 	}
11253859Sml29623 	if (status & NXGE_DDI_FAILED)
11263859Sml29623 		status |= NXGE_ERROR;
11273859Sml29623 
11283859Sml29623 	return (status);
11293859Sml29623 }
11303859Sml29623 
11313859Sml29623 static uint64_t
11323859Sml29623 nxge_class_get_known_cfg(p_nxge_t nxgep, int class_prop, int rx_quick_cfg)
11333859Sml29623 {
11343859Sml29623 	int start_prop;
11353859Sml29623 	uint64_t cfg_value;
11363859Sml29623 	p_nxge_param_t param_arr;
11373859Sml29623 
11383859Sml29623 	param_arr = nxgep->param_arr;
11393859Sml29623 	cfg_value = param_arr[class_prop].value;
11403859Sml29623 	start_prop = param_h1_init_value;
11413859Sml29623 
11423859Sml29623 	/* update the properties per quick config */
11433859Sml29623 	switch (rx_quick_cfg) {
11443859Sml29623 	case CFG_L3_WEB:
11453859Sml29623 	case CFG_L3_DISTRIBUTE:
11463859Sml29623 		cfg_value = nxge_classify_get_cfg_value(nxgep,
11476929Smisaki 		    rx_quick_cfg, class_prop - start_prop);
11483859Sml29623 		break;
11493859Sml29623 	default:
11503859Sml29623 		cfg_value = param_arr[class_prop].value;
11513859Sml29623 		break;
11523859Sml29623 	}
11533859Sml29623 	return (cfg_value);
11543859Sml29623 }
11553859Sml29623 
11563859Sml29623 static nxge_status_t
11573859Sml29623 nxge_cfg_verify_set_classify(p_nxge_t nxgep, dev_info_t *c_dip[])
11583859Sml29623 {
11593859Sml29623 	nxge_status_t status = NXGE_OK;
11603859Sml29623 	int rx_quick_cfg, class_prop, start_prop, end_prop;
11613859Sml29623 	char *prop_name;
11623859Sml29623 	int override = B_TRUE;
11633859Sml29623 	uint64_t cfg_value;
11643859Sml29623 	p_nxge_param_t param_arr;
11653859Sml29623 
11663859Sml29623 	param_arr = nxgep->param_arr;
11673859Sml29623 	rx_quick_cfg = param_arr[param_rx_quick_cfg].value;
11683859Sml29623 	start_prop = param_h1_init_value;
11693859Sml29623 	end_prop = param_class_opt_ipv6_sctp;
11703859Sml29623 
11713859Sml29623 	/* update the properties per quick config */
11723859Sml29623 	if (rx_quick_cfg == CFG_NOT_SPECIFIED)
11733859Sml29623 		override = B_FALSE;
11743859Sml29623 
11753859Sml29623 	/*
11763859Sml29623 	 * these parameter affect the classification outcome.
11773859Sml29623 	 * these parameters are used to configure the Flow key and
11783859Sml29623 	 * the TCAM key for each of the IP classes.
11793859Sml29623 	 * Included here are also the H1 and H2 initial values
11803859Sml29623 	 * which affect the distribution as well as final hash value
11813859Sml29623 	 * (hence the offset into RDC table and FCRAM bucket location)
11823859Sml29623 	 *
11833859Sml29623 	 */
11843859Sml29623 	for (class_prop = start_prop; class_prop <= end_prop; class_prop++) {
11853859Sml29623 		prop_name = param_arr[class_prop].fcode_name;
11863859Sml29623 		cfg_value = nxge_class_get_known_cfg(nxgep,
11876929Smisaki 		    class_prop, rx_quick_cfg);
11883859Sml29623 		status = nxge_cfg_verify_set_classify_prop(nxgep, prop_name,
11896929Smisaki 		    cfg_value, override, c_dip);
11903859Sml29623 	}
11913859Sml29623 
11923859Sml29623 	/*
11933859Sml29623 	 * these properties do not affect the actual classification outcome.
11943859Sml29623 	 * used to enable/disable or tune the fflp hardware
11953859Sml29623 	 *
11963859Sml29623 	 * fcram_access_ratio, tcam_access_ratio, tcam_enable, llc_snap_enable
11973859Sml29623 	 *
11983859Sml29623 	 */
11993859Sml29623 	override = B_FALSE;
12003859Sml29623 	for (class_prop = param_fcram_access_ratio;
12016929Smisaki 	    class_prop <= param_llc_snap_enable; class_prop++) {
12023859Sml29623 		prop_name = param_arr[class_prop].fcode_name;
12033859Sml29623 		cfg_value = param_arr[class_prop].value;
12043859Sml29623 		status = nxge_cfg_verify_set_classify_prop(nxgep, prop_name,
12056929Smisaki 		    cfg_value, override, c_dip);
12063859Sml29623 	}
12073859Sml29623 
12083859Sml29623 	return (status);
12093859Sml29623 }
12103859Sml29623 
12113859Sml29623 nxge_status_t
12123859Sml29623 nxge_cfg_verify_set(p_nxge_t nxgep, uint32_t flag)
12133859Sml29623 {
12143859Sml29623 	nxge_status_t status = NXGE_OK;
12153859Sml29623 	int i = 0, found = 0;
12163859Sml29623 	int num_siblings;
12173859Sml29623 	dev_info_t *c_dip[MAX_SIBLINGS + 1];
12183859Sml29623 	char *prop_val[MAX_SIBLINGS];
12193859Sml29623 	config_token_t c_token[MAX_SIBLINGS];
12203859Sml29623 	char *prop;
12213859Sml29623 
12223859Sml29623 	if (nxge_dma_obp_props_only)
12233859Sml29623 		return (NXGE_OK);
12243859Sml29623 
12253859Sml29623 	num_siblings = 0;
12263859Sml29623 	c_dip[num_siblings] = ddi_get_child(nxgep->p_dip);
12273859Sml29623 	while (c_dip[num_siblings]) {
12283859Sml29623 		c_dip[num_siblings + 1] =
12296929Smisaki 		    ddi_get_next_sibling(c_dip[num_siblings]);
12303859Sml29623 		num_siblings++;
12313859Sml29623 	}
12323859Sml29623 
12333859Sml29623 	switch (flag) {
12343859Sml29623 	case COMMON_TXDMA_CFG:
12353859Sml29623 		prop = "txdma-cfg";
12363859Sml29623 		break;
12373859Sml29623 	case COMMON_RXDMA_CFG:
12383859Sml29623 		prop = "rxdma-cfg";
12393859Sml29623 		break;
12403859Sml29623 	case COMMON_RXDMA_GRP_CFG:
12413859Sml29623 		prop = "rxdma-grp-cfg";
12423859Sml29623 		break;
12433859Sml29623 	case COMMON_CLASS_CFG:
12443859Sml29623 		status = nxge_cfg_verify_set_classify(nxgep, c_dip);
12453859Sml29623 		return (status);
12463859Sml29623 	default:
12473859Sml29623 		return (NXGE_ERROR);
12483859Sml29623 	}
12493859Sml29623 
12503859Sml29623 	i = 0;
12513859Sml29623 	while (i < num_siblings) {
12523859Sml29623 		if (ddi_prop_lookup_string(DDI_DEV_T_ANY, c_dip[i], 0, prop,
12536929Smisaki 		    (char **)&prop_val[i]) == DDI_PROP_SUCCESS) {
12543859Sml29623 			c_token[i] = nxge_get_config_token(prop_val[i]);
12553859Sml29623 			ddi_prop_free(prop_val[i]);
12563859Sml29623 			found++;
12573859Sml29623 		} else
12583859Sml29623 			c_token[i] = CONFIG_TOKEN_NONE;
12593859Sml29623 		i++;
12603859Sml29623 	}
12613859Sml29623 
12623859Sml29623 	if (found != i) {
12633859Sml29623 		if (found == 0) {
12643859Sml29623 			/* not specified: Use default */
12653859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
12666929Smisaki 			    " property %s not specified on any port:"
12676929Smisaki 			    " Using default", prop));
12683859Sml29623 
12693859Sml29623 			status = nxge_update_cfg_properties(nxgep,
12706929Smisaki 			    flag, FAIR, c_dip);
12713859Sml29623 			return (status);
12723859Sml29623 		} else {
12733859Sml29623 			/*
12743859Sml29623 			 * if  the convention is to use function 0 device then
12753859Sml29623 			 * populate the other devices with this configuration.
12763859Sml29623 			 *
12773859Sml29623 			 * The other alternative is to use the default config.
12783859Sml29623 			 */
12793859Sml29623 			/* not specified: Use default */
12803859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
12816929Smisaki 			    " property %s not specified on some ports:"
12826929Smisaki 			    " Using default", prop));
12833859Sml29623 			status = nxge_update_cfg_properties(nxgep,
12846929Smisaki 			    flag, FAIR, c_dip);
12853859Sml29623 			return (status);
12863859Sml29623 		}
12873859Sml29623 	}
12883859Sml29623 
12893859Sml29623 	/* check type and consistence */
12903859Sml29623 	/* found on all devices */
12913859Sml29623 	for (i = 1; i < found; i++) {
12923859Sml29623 		if (c_token[i] != c_token[i - 1]) {
12933859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
12946929Smisaki 			    " property %s inconsistent:"
12956929Smisaki 			    " Using default", prop));
12963859Sml29623 			status = nxge_update_cfg_properties(nxgep,
12976929Smisaki 			    flag, FAIR, c_dip);
12983859Sml29623 			return (status);
12993859Sml29623 		}
13003859Sml29623 	}
13013859Sml29623 
13023859Sml29623 	/*
13033859Sml29623 	 * Found on all the ports check if it is custom configuration. if
13043859Sml29623 	 * custom, then verify consistence
13053859Sml29623 	 *
13063859Sml29623 	 * finally create soft properties
13073859Sml29623 	 */
13083859Sml29623 	status = nxge_update_cfg_properties(nxgep, flag, c_token[0], c_dip);
13093859Sml29623 	return (status);
13103859Sml29623 }
13113859Sml29623 
13123859Sml29623 nxge_status_t
13133859Sml29623 nxge_cfg_verify_set_quick_config(p_nxge_t nxgep)
13143859Sml29623 {
13153859Sml29623 	nxge_status_t status = NXGE_OK;
13163859Sml29623 	int ddi_status = DDI_SUCCESS;
13173859Sml29623 	char *prop_val;
13183859Sml29623 	char *rx_prop;
13193859Sml29623 	char *prop;
13203859Sml29623 	uint32_t cfg_value = CFG_NOT_SPECIFIED;
13213859Sml29623 	p_nxge_param_t param_arr;
13223859Sml29623 
13233859Sml29623 	param_arr = nxgep->param_arr;
13243859Sml29623 	rx_prop = param_arr[param_rx_quick_cfg].fcode_name;
13253859Sml29623 
13263859Sml29623 	prop = "rx-quick-cfg";
13273859Sml29623 
13283859Sml29623 	/*
13293859Sml29623 	 * good value are
13303859Sml29623 	 *
13313859Sml29623 	 * "web-server" "generic-server" "l3-classify" "flow-classify"
13323859Sml29623 	 */
13333859Sml29623 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, nxgep->dip, 0,
13346929Smisaki 	    prop, (char **)&prop_val) != DDI_PROP_SUCCESS) {
13353859Sml29623 		NXGE_DEBUG_MSG((nxgep, VPD_CTL,
13366929Smisaki 		    " property %s not specified: using default ", prop));
13373859Sml29623 		cfg_value = CFG_NOT_SPECIFIED;
13383859Sml29623 	} else {
13393859Sml29623 		cfg_value = CFG_L3_DISTRIBUTE;
13403859Sml29623 		if (strncmp("web-server", (caddr_t)prop_val, 8) == 0) {
13413859Sml29623 			cfg_value = CFG_L3_WEB;
13423859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
13436929Smisaki 			    " %s: web server ", prop));
13443859Sml29623 		}
13453859Sml29623 		if (strncmp("generic-server", (caddr_t)prop_val, 8) == 0) {
13463859Sml29623 			cfg_value = CFG_L3_DISTRIBUTE;
13473859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
13486929Smisaki 			    " %s: distribute ", prop));
13493859Sml29623 		}
13503859Sml29623 		/* more */
13513859Sml29623 		ddi_prop_free(prop_val);
13523859Sml29623 	}
13533859Sml29623 
13543859Sml29623 	ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
13556929Smisaki 	    rx_prop, cfg_value);
13563859Sml29623 	if (ddi_status != DDI_PROP_SUCCESS)
13573859Sml29623 		status |= NXGE_DDI_FAILED;
13583859Sml29623 
13593859Sml29623 	/* now handle specified cases: */
13603859Sml29623 	if (status & NXGE_DDI_FAILED)
13613859Sml29623 		status |= NXGE_ERROR;
13623859Sml29623 	return (status);
13633859Sml29623 }
13643859Sml29623 
13656835Syc148097 /*
13666835Syc148097  * Device properties adv-autoneg-cap etc are defined by FWARC
13676835Syc148097  * http://sac.sfbay/FWARC/2002/345/20020610_asif.haswarey
13686835Syc148097  */
13693859Sml29623 static void
13703859Sml29623 nxge_use_cfg_link_cfg(p_nxge_t nxgep)
13713859Sml29623 {
13723859Sml29623 	int *prop_val;
13733859Sml29623 	uint_t prop_len;
13743859Sml29623 	dev_info_t *dip;
13753859Sml29623 	int speed;
13763859Sml29623 	int duplex;
13773859Sml29623 	int adv_autoneg_cap;
13783859Sml29623 	int adv_10gfdx_cap;
13793859Sml29623 	int adv_10ghdx_cap;
13803859Sml29623 	int adv_1000fdx_cap;
13813859Sml29623 	int adv_1000hdx_cap;
13823859Sml29623 	int adv_100fdx_cap;
13833859Sml29623 	int adv_100hdx_cap;
13843859Sml29623 	int adv_10fdx_cap;
13853859Sml29623 	int adv_10hdx_cap;
13863859Sml29623 	int status = DDI_SUCCESS;
13873859Sml29623 
13883859Sml29623 	dip = nxgep->dip;
13893859Sml29623 
13903859Sml29623 	/*
13913859Sml29623 	 * first find out the card type and the supported link speeds and
13923859Sml29623 	 * features
13933859Sml29623 	 */
13943859Sml29623 	/* add code for card type */
13953859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-autoneg-cap",
13966929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
13973859Sml29623 		ddi_prop_free(prop_val);
13983859Sml29623 		return;
13993859Sml29623 	}
14003859Sml29623 
14013859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10gfdx-cap",
14026929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14033859Sml29623 		ddi_prop_free(prop_val);
14043859Sml29623 		return;
14053859Sml29623 	}
14063859Sml29623 
14073859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-1000hdx-cap",
14086929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14093859Sml29623 		ddi_prop_free(prop_val);
14103859Sml29623 		return;
14113859Sml29623 	}
14123859Sml29623 
14133859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-1000fdx-cap",
14146929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14153859Sml29623 		ddi_prop_free(prop_val);
14163859Sml29623 		return;
14173859Sml29623 	}
14183859Sml29623 
14193859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-100fdx-cap",
14206929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14213859Sml29623 		ddi_prop_free(prop_val);
14223859Sml29623 		return;
14233859Sml29623 	}
14243859Sml29623 
14253859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-100hdx-cap",
14266929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14273859Sml29623 		ddi_prop_free(prop_val);
14283859Sml29623 		return;
14293859Sml29623 	}
14303859Sml29623 
14313859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10fdx-cap",
14326929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14333859Sml29623 		ddi_prop_free(prop_val);
14343859Sml29623 		return;
14353859Sml29623 	}
14363859Sml29623 
14373859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10hdx-cap",
14386929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14393859Sml29623 		ddi_prop_free(prop_val);
14403859Sml29623 		return;
14413859Sml29623 	}
14423859Sml29623 
14433859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0, "speed",
14446929Smisaki 	    (uchar_t **)&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14453859Sml29623 		if (strncmp("10000", (caddr_t)prop_val,
14466929Smisaki 		    (size_t)prop_len) == 0) {
14473859Sml29623 			speed = 10000;
14483859Sml29623 		} else if (strncmp("1000", (caddr_t)prop_val,
14496929Smisaki 		    (size_t)prop_len) == 0) {
14503859Sml29623 			speed = 1000;
14513859Sml29623 		} else if (strncmp("100", (caddr_t)prop_val,
14526929Smisaki 		    (size_t)prop_len) == 0) {
14533859Sml29623 			speed = 100;
14543859Sml29623 		} else if (strncmp("10", (caddr_t)prop_val,
14556929Smisaki 		    (size_t)prop_len) == 0) {
14563859Sml29623 			speed = 10;
14573859Sml29623 		} else if (strncmp("auto", (caddr_t)prop_val,
14586929Smisaki 		    (size_t)prop_len) == 0) {
14593859Sml29623 			speed = 0;
14603859Sml29623 		} else {
14613859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_NOTE,
14626929Smisaki 			    "speed property is invalid reverting to auto"));
14633859Sml29623 			speed = 0;
14643859Sml29623 		}
14653859Sml29623 		ddi_prop_free(prop_val);
14663859Sml29623 	} else
14673859Sml29623 		speed = 0;
14683859Sml29623 
14693859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0, "duplex",
14706929Smisaki 	    (uchar_t **)&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14713859Sml29623 		if (strncmp("full", (caddr_t)prop_val,
14726929Smisaki 		    (size_t)prop_len) == 0) {
14733859Sml29623 			duplex = 2;
14743859Sml29623 		} else if (strncmp("half", (caddr_t)prop_val,
14756929Smisaki 		    (size_t)prop_len) == 0) {
14763859Sml29623 			duplex = 1;
14773859Sml29623 		} else if (strncmp("auto", (caddr_t)prop_val,
14786929Smisaki 		    (size_t)prop_len) == 0) {
14793859Sml29623 			duplex = 0;
14803859Sml29623 		} else {
14813859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_NOTE,
14826929Smisaki 			    "duplex property is invalid"
14836929Smisaki 			    " reverting to auto"));
14843859Sml29623 			duplex = 0;
14853859Sml29623 		}
14863859Sml29623 		ddi_prop_free(prop_val);
14873859Sml29623 	} else
14883859Sml29623 		duplex = 0;
14893859Sml29623 
14906835Syc148097 	/* speed == 0 or duplex == 0 means auto negotiation. */
14913859Sml29623 	adv_autoneg_cap = (speed == 0) || (duplex == 0);
14923859Sml29623 	if (adv_autoneg_cap == 0) {
14933859Sml29623 		adv_10gfdx_cap = ((speed == 10000) && (duplex == 2));
14943859Sml29623 		adv_10ghdx_cap = adv_10gfdx_cap;
14953859Sml29623 		adv_10ghdx_cap |= ((speed == 10000) && (duplex == 1));
14963859Sml29623 		adv_1000fdx_cap = adv_10ghdx_cap;
14973859Sml29623 		adv_1000fdx_cap |= ((speed == 1000) && (duplex == 2));
14983859Sml29623 		adv_1000hdx_cap = adv_1000fdx_cap;
14993859Sml29623 		adv_1000hdx_cap |= ((speed == 1000) && (duplex == 1));
15003859Sml29623 		adv_100fdx_cap = adv_1000hdx_cap;
15013859Sml29623 		adv_100fdx_cap |= ((speed == 100) && (duplex == 2));
15023859Sml29623 		adv_100hdx_cap = adv_100fdx_cap;
15033859Sml29623 		adv_100hdx_cap |= ((speed == 100) && (duplex == 1));
15043859Sml29623 		adv_10fdx_cap = adv_100hdx_cap;
15053859Sml29623 		adv_10fdx_cap |= ((speed == 10) && (duplex == 2));
15063859Sml29623 		adv_10hdx_cap = adv_10fdx_cap;
15073859Sml29623 		adv_10hdx_cap |= ((speed == 10) && (duplex == 1));
15083859Sml29623 	} else if (speed == 0) {
15093859Sml29623 		adv_10gfdx_cap = (duplex == 2);
15103859Sml29623 		adv_10ghdx_cap = (duplex == 1);
15113859Sml29623 		adv_1000fdx_cap = (duplex == 2);
15123859Sml29623 		adv_1000hdx_cap = (duplex == 1);
15133859Sml29623 		adv_100fdx_cap = (duplex == 2);
15143859Sml29623 		adv_100hdx_cap = (duplex == 1);
15153859Sml29623 		adv_10fdx_cap = (duplex == 2);
15163859Sml29623 		adv_10hdx_cap = (duplex == 1);
15173859Sml29623 	}
15183859Sml29623 	if (duplex == 0) {
15193859Sml29623 		adv_10gfdx_cap = (speed == 0);
15203859Sml29623 		adv_10gfdx_cap |= (speed == 10000);
15213859Sml29623 		adv_10ghdx_cap = adv_10gfdx_cap;
15223859Sml29623 		adv_10ghdx_cap |= (speed == 10000);
15233859Sml29623 		adv_1000fdx_cap = adv_10ghdx_cap;
15243859Sml29623 		adv_1000fdx_cap |= (speed == 1000);
15253859Sml29623 		adv_1000hdx_cap = adv_1000fdx_cap;
15263859Sml29623 		adv_1000hdx_cap |= (speed == 1000);
15273859Sml29623 		adv_100fdx_cap = adv_1000hdx_cap;
15283859Sml29623 		adv_100fdx_cap |= (speed == 100);
15293859Sml29623 		adv_100hdx_cap = adv_100fdx_cap;
15303859Sml29623 		adv_100hdx_cap |= (speed == 100);
15313859Sml29623 		adv_10fdx_cap = adv_100hdx_cap;
15323859Sml29623 		adv_10fdx_cap |= (speed == 10);
15333859Sml29623 		adv_10hdx_cap = adv_10fdx_cap;
15343859Sml29623 		adv_10hdx_cap |= (speed == 10);
15353859Sml29623 	}
15363859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15376929Smisaki 	    "adv-autoneg-cap", &adv_autoneg_cap, 1);
15383859Sml29623 	if (status)
15393859Sml29623 		return;
15403859Sml29623 
15413859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15426929Smisaki 	    "adv-10gfdx-cap", &adv_10gfdx_cap, 1);
15433859Sml29623 	if (status)
15443859Sml29623 		goto nxge_map_myargs_to_gmii_fail1;
15453859Sml29623 
15463859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15476929Smisaki 	    "adv-10ghdx-cap", &adv_10ghdx_cap, 1);
15483859Sml29623 	if (status)
15493859Sml29623 		goto nxge_map_myargs_to_gmii_fail2;
15503859Sml29623 
15513859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15526929Smisaki 	    "adv-1000fdx-cap", &adv_1000fdx_cap, 1);
15533859Sml29623 	if (status)
15543859Sml29623 		goto nxge_map_myargs_to_gmii_fail3;
15553859Sml29623 
15563859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15576929Smisaki 	    "adv-1000hdx-cap", &adv_1000hdx_cap, 1);
15583859Sml29623 	if (status)
15593859Sml29623 		goto nxge_map_myargs_to_gmii_fail4;
15603859Sml29623 
15613859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15626929Smisaki 	    "adv-100fdx-cap", &adv_100fdx_cap, 1);
15633859Sml29623 	if (status)
15643859Sml29623 		goto nxge_map_myargs_to_gmii_fail5;
15653859Sml29623 
15663859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15676929Smisaki 	    "adv-100hdx-cap", &adv_100hdx_cap, 1);
15683859Sml29623 	if (status)
15693859Sml29623 		goto nxge_map_myargs_to_gmii_fail6;
15703859Sml29623 
15713859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15726929Smisaki 	    "adv-10fdx-cap", &adv_10fdx_cap, 1);
15733859Sml29623 	if (status)
15743859Sml29623 		goto nxge_map_myargs_to_gmii_fail7;
15753859Sml29623 
15763859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15776929Smisaki 	    "adv-10hdx-cap", &adv_10hdx_cap, 1);
15783859Sml29623 	if (status)
15793859Sml29623 		goto nxge_map_myargs_to_gmii_fail8;
15803859Sml29623 
15813859Sml29623 	return;
15823859Sml29623 
15833859Sml29623 nxge_map_myargs_to_gmii_fail9:
15843859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10hdx-cap");
15853859Sml29623 
15863859Sml29623 nxge_map_myargs_to_gmii_fail8:
15873859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10fdx-cap");
15883859Sml29623 
15893859Sml29623 nxge_map_myargs_to_gmii_fail7:
15903859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-100hdx-cap");
15913859Sml29623 
15923859Sml29623 nxge_map_myargs_to_gmii_fail6:
15933859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-100fdx-cap");
15943859Sml29623 
15953859Sml29623 nxge_map_myargs_to_gmii_fail5:
15963859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-1000hdx-cap");
15973859Sml29623 
15983859Sml29623 nxge_map_myargs_to_gmii_fail4:
15993859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-1000fdx-cap");
16003859Sml29623 
16013859Sml29623 nxge_map_myargs_to_gmii_fail3:
16023859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10ghdx-cap");
16033859Sml29623 
16043859Sml29623 nxge_map_myargs_to_gmii_fail2:
16053859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10gfdx-cap");
16063859Sml29623 
16073859Sml29623 nxge_map_myargs_to_gmii_fail1:
16083859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-autoneg-cap");
16093859Sml29623 }
16103859Sml29623 
16113859Sml29623 nxge_status_t
16123859Sml29623 nxge_get_config_properties(p_nxge_t nxgep)
16133859Sml29623 {
16143859Sml29623 	nxge_status_t status = NXGE_OK;
16153859Sml29623 	p_nxge_hw_list_t hw_p;
1616*11304SJanie.Lu@Sun.COM 	char **prop_val;
1617*11304SJanie.Lu@Sun.COM 	uint_t prop_len;
1618*11304SJanie.Lu@Sun.COM 	uint_t i;
16193859Sml29623 
16203859Sml29623 	NXGE_DEBUG_MSG((nxgep, VPD_CTL, " ==> nxge_get_config_properties"));
16213859Sml29623 
16223859Sml29623 	if ((hw_p = nxgep->nxge_hw_p) == NULL) {
16233859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
16246929Smisaki 		    " nxge_get_config_properties:"
16256929Smisaki 		    " common hardware not set", nxgep->niu_type));
16263859Sml29623 		return (NXGE_ERROR);
16273859Sml29623 	}
16283859Sml29623 
16293859Sml29623 	/*
16303859Sml29623 	 * Get info on how many ports Neptune card has.
16313859Sml29623 	 */
16324977Sraghus 	nxgep->nports = nxge_get_nports(nxgep);
16334732Sdavemq 	if (nxgep->nports <= 0) {
16344732Sdavemq 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
16354732Sdavemq 		    "<==nxge_get_config_properties: Invalid Neptune type 0x%x",
16364732Sdavemq 		    nxgep->niu_type));
16374732Sdavemq 		return (NXGE_ERROR);
16384732Sdavemq 	}
16394732Sdavemq 	nxgep->classifier.tcam_size = TCAM_NIU_TCAM_MAX_ENTRY;
16404977Sraghus 	if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
16414977Sraghus 		nxgep->classifier.tcam_size = TCAM_NXGE_TCAM_MAX_ENTRY;
16424977Sraghus 	}
16434732Sdavemq 	if (nxgep->function_num >= nxgep->nports) {
16444732Sdavemq 		return (NXGE_ERROR);
16453859Sml29623 	}
16463859Sml29623 
16473859Sml29623 	status = nxge_get_mac_addr_properties(nxgep);
16483859Sml29623 	if (status != NXGE_OK)
16493859Sml29623 		return (NXGE_ERROR);
16503859Sml29623 
16513859Sml29623 	/*
16523859Sml29623 	 * read the configuration type. If none is specified, used default.
16533859Sml29623 	 * Config types: equal: (default) DMA channels, RDC groups, TCAM, FCRAM
16543859Sml29623 	 * are shared equally across all the ports.
16553859Sml29623 	 *
16563859Sml29623 	 * Fair: DMA channels, RDC groups, TCAM, FCRAM are shared proportional
16573859Sml29623 	 * to the port speed.
16583859Sml29623 	 *
16593859Sml29623 	 *
16603859Sml29623 	 * custom: DMA channels, RDC groups, TCAM, FCRAM partition is
16613859Sml29623 	 * specified in nxge.conf. Need to read each parameter and set
16623859Sml29623 	 * up the parameters in nxge structures.
16633859Sml29623 	 *
16643859Sml29623 	 */
16653859Sml29623 	switch (nxgep->niu_type) {
16663859Sml29623 	case N2_NIU:
16673859Sml29623 		NXGE_DEBUG_MSG((nxgep, VPD_CTL,
16686929Smisaki 		    " ==> nxge_get_config_properties: N2"));
16693859Sml29623 		MUTEX_ENTER(&hw_p->nxge_cfg_lock);
16703859Sml29623 		if ((hw_p->flags & COMMON_CFG_VALID) !=
16716929Smisaki 		    COMMON_CFG_VALID) {
16723859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16736929Smisaki 			    COMMON_RXDMA_GRP_CFG);
16743859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16756929Smisaki 			    COMMON_CLASS_CFG);
16763859Sml29623 			hw_p->flags |= COMMON_CFG_VALID;
16773859Sml29623 		}
16783859Sml29623 		MUTEX_EXIT(&hw_p->nxge_cfg_lock);
16793859Sml29623 		status = nxge_use_cfg_n2niu_properties(nxgep);
16803859Sml29623 		break;
16814732Sdavemq 	default:
16824977Sraghus 		if (!NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
16834732Sdavemq 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
16844732Sdavemq 			    " nxge_get_config_properties:"
16854732Sdavemq 			    " unknown NIU type 0x%x", nxgep->niu_type));
16864732Sdavemq 			return (NXGE_ERROR);
16874732Sdavemq 		}
16884732Sdavemq 
16893859Sml29623 		NXGE_DEBUG_MSG((nxgep, VPD_CTL,
16906929Smisaki 		    " ==> nxge_get_config_properties: Neptune"));
16913859Sml29623 		status = nxge_cfg_verify_set_quick_config(nxgep);
16923859Sml29623 		MUTEX_ENTER(&hw_p->nxge_cfg_lock);
16933859Sml29623 		if ((hw_p->flags & COMMON_CFG_VALID) !=
16946929Smisaki 		    COMMON_CFG_VALID) {
16953859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16966929Smisaki 			    COMMON_TXDMA_CFG);
16973859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16986929Smisaki 			    COMMON_RXDMA_CFG);
16993859Sml29623 			status = nxge_cfg_verify_set(nxgep,
17006929Smisaki 			    COMMON_RXDMA_GRP_CFG);
17013859Sml29623 			status = nxge_cfg_verify_set(nxgep,
17026929Smisaki 			    COMMON_CLASS_CFG);
17033859Sml29623 			hw_p->flags |= COMMON_CFG_VALID;
17043859Sml29623 		}
17053859Sml29623 		MUTEX_EXIT(&hw_p->nxge_cfg_lock);
17063859Sml29623 		nxge_use_cfg_neptune_properties(nxgep);
17073859Sml29623 		status = NXGE_OK;
17083859Sml29623 		break;
17093859Sml29623 	}
17103859Sml29623 
17116003Sml29623 	/*
17126003Sml29623 	 * Get the software LSO enable flag property from the
17136003Sml29623 	 * driver configuration file (nxge.conf).
17146003Sml29623 	 * This flag will be set to disable (0) if this property
17156003Sml29623 	 * does not exist.
17166003Sml29623 	 */
17176003Sml29623 	nxgep->soft_lso_enable = ddi_prop_get_int(DDI_DEV_T_ANY, nxgep->dip,
17186003Sml29623 	    DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "soft-lso-enable", 0);
17196003Sml29623 	NXGE_DEBUG_MSG((nxgep, VPD_CTL,
17206003Sml29623 	    "nxge_get_config_properties: software lso %d\n",
17216003Sml29623 	    nxgep->soft_lso_enable));
17226003Sml29623 
1723*11304SJanie.Lu@Sun.COM 	nxgep->niu_hw_type = NIU_HW_TYPE_DEFAULT;
1724*11304SJanie.Lu@Sun.COM 	if (nxgep->niu_type == N2_NIU) {
1725*11304SJanie.Lu@Sun.COM 		/*
1726*11304SJanie.Lu@Sun.COM 		 * For NIU, the next generation KT has
1727*11304SJanie.Lu@Sun.COM 		 * a few differences in features that the
1728*11304SJanie.Lu@Sun.COM 		 * driver needs to handle them
1729*11304SJanie.Lu@Sun.COM 		 * accordingly.
1730*11304SJanie.Lu@Sun.COM 		 */
1731*11304SJanie.Lu@Sun.COM 		if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1732*11304SJanie.Lu@Sun.COM 		    "compatible", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1733*11304SJanie.Lu@Sun.COM 			for (i = 0; i < prop_len; i++) {
1734*11304SJanie.Lu@Sun.COM 				if ((strcmp((caddr_t)prop_val[i],
1735*11304SJanie.Lu@Sun.COM 				    KT_NIU_COMPATIBLE) == 0)) {
1736*11304SJanie.Lu@Sun.COM 					nxgep->niu_hw_type = NIU_HW_TYPE_RF;
1737*11304SJanie.Lu@Sun.COM 					NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1738*11304SJanie.Lu@Sun.COM 					    "NIU type %d", nxgep->niu_hw_type));
1739*11304SJanie.Lu@Sun.COM 					break;
1740*11304SJanie.Lu@Sun.COM 				}
1741*11304SJanie.Lu@Sun.COM 			}
1742*11304SJanie.Lu@Sun.COM 		}
1743*11304SJanie.Lu@Sun.COM 
1744*11304SJanie.Lu@Sun.COM 		ddi_prop_free(prop_val);
1745*11304SJanie.Lu@Sun.COM 	}
1746*11304SJanie.Lu@Sun.COM 
17473859Sml29623 	NXGE_DEBUG_MSG((nxgep, VPD_CTL, " <== nxge_get_config_properties"));
17483859Sml29623 	return (status);
17493859Sml29623 }
17503859Sml29623 
17513859Sml29623 static nxge_status_t
17523859Sml29623 nxge_use_cfg_n2niu_properties(p_nxge_t nxgep)
17533859Sml29623 {
17543859Sml29623 	nxge_status_t status = NXGE_OK;
17553859Sml29623 
17563859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_n2niu_properties"));
17573859Sml29623 
17583859Sml29623 	status = nxge_use_default_dma_config_n2(nxgep);
17593859Sml29623 	if (status != NXGE_OK) {
17603859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
17616929Smisaki 		    " ==> nxge_use_cfg_n2niu_properties (err 0x%x)",
17626929Smisaki 		    status));
17633859Sml29623 		return (status | NXGE_ERROR);
17643859Sml29623 	}
17653859Sml29623 
17663859Sml29623 	(void) nxge_use_cfg_vlan_class_config(nxgep);
17673859Sml29623 	(void) nxge_use_cfg_mac_class_config(nxgep);
17683859Sml29623 	(void) nxge_use_cfg_class_config(nxgep);
17693859Sml29623 	(void) nxge_use_cfg_link_cfg(nxgep);
17703859Sml29623 
17713859Sml29623 	/*
17723859Sml29623 	 * Read in the hardware (fcode) properties. Use the ndd array to read
17733859Sml29623 	 * each property.
17743859Sml29623 	 */
17753859Sml29623 	(void) nxge_get_param_soft_properties(nxgep);
17763859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_n2niu_properties"));
17773859Sml29623 
17783859Sml29623 	return (status);
17793859Sml29623 }
17803859Sml29623 
17813859Sml29623 static void
17823859Sml29623 nxge_use_cfg_neptune_properties(p_nxge_t nxgep)
17833859Sml29623 {
17843859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_neptune_properties"));
17853859Sml29623 
17863859Sml29623 	(void) nxge_use_cfg_dma_config(nxgep);
17873859Sml29623 	(void) nxge_use_cfg_vlan_class_config(nxgep);
17883859Sml29623 	(void) nxge_use_cfg_mac_class_config(nxgep);
17893859Sml29623 	(void) nxge_use_cfg_class_config(nxgep);
17903859Sml29623 	(void) nxge_use_cfg_link_cfg(nxgep);
17913859Sml29623 
17923859Sml29623 	/*
17933859Sml29623 	 * Read in the hardware (fcode) properties. Use the ndd array to read
17943859Sml29623 	 * each property.
17953859Sml29623 	 */
17963859Sml29623 	(void) nxge_get_param_soft_properties(nxgep);
17973859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_neptune_properties"));
17983859Sml29623 }
17993859Sml29623 
18003859Sml29623 /*
18019015SMichael.Speer@Sun.COM  * FWARC 2006/556 for N2 NIU.  Get the properties
18029015SMichael.Speer@Sun.COM  * from the prom.
18033859Sml29623  */
18043859Sml29623 static nxge_status_t
18053859Sml29623 nxge_use_default_dma_config_n2(p_nxge_t nxgep)
18063859Sml29623 {
18079015SMichael.Speer@Sun.COM 	int			ndmas;
18089015SMichael.Speer@Sun.COM 	uint8_t			func;
18099015SMichael.Speer@Sun.COM 	p_nxge_dma_pt_cfg_t	p_dma_cfgp;
18109015SMichael.Speer@Sun.COM 	p_nxge_hw_pt_cfg_t	p_cfgp;
18119015SMichael.Speer@Sun.COM 	int			*prop_val;
18129015SMichael.Speer@Sun.COM 	uint_t			prop_len;
18139015SMichael.Speer@Sun.COM 	int			i;
18149015SMichael.Speer@Sun.COM 	nxge_status_t		status = NXGE_OK;
18153859Sml29623 
18163859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2"));
18173859Sml29623 
18183859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
18193859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
18203859Sml29623 
18213859Sml29623 	func = nxgep->function_num;
18223859Sml29623 	p_cfgp->function_number = func;
18233859Sml29623 	ndmas = NXGE_TDMA_PER_NIU_PORT;
18243859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
18256929Smisaki 	    "tx-dma-channels", (int **)&prop_val,
18266929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
18279015SMichael.Speer@Sun.COM 		if (prop_len != NXGE_NIU_TDMA_PROP_LEN) {
18289015SMichael.Speer@Sun.COM 			ddi_prop_free(prop_val);
18299015SMichael.Speer@Sun.COM 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
18309015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2: "
183110392SMichael.Speer@Sun.COM 			    "invalid tx-dma-channels property for the NIU, "
183210392SMichael.Speer@Sun.COM 			    "using defaults"));
183310392SMichael.Speer@Sun.COM 			/*
183410392SMichael.Speer@Sun.COM 			 * Just failover to defaults
183510392SMichael.Speer@Sun.COM 			 */
183610392SMichael.Speer@Sun.COM 			p_cfgp->tdc.start = (func * NXGE_TDMA_PER_NIU_PORT);
183710392SMichael.Speer@Sun.COM 			ndmas = NXGE_TDMA_PER_NIU_PORT;
18389015SMichael.Speer@Sun.COM 		} else {
18399015SMichael.Speer@Sun.COM 			p_cfgp->tdc.start = prop_val[0];
18409015SMichael.Speer@Sun.COM 			NXGE_DEBUG_MSG((nxgep, OBP_CTL,
18419015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2: tdc starts %d "
18429015SMichael.Speer@Sun.COM 			    "(#%d)", p_cfgp->tdc.start, prop_len));
18439015SMichael.Speer@Sun.COM 
18449015SMichael.Speer@Sun.COM 			ndmas = prop_val[1];
18459015SMichael.Speer@Sun.COM 			NXGE_DEBUG_MSG((nxgep, OBP_CTL,
18469015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2: #tdc %d (#%d)",
18479015SMichael.Speer@Sun.COM 			    ndmas, prop_len));
18489015SMichael.Speer@Sun.COM 			ddi_prop_free(prop_val);
18499015SMichael.Speer@Sun.COM 		}
18503859Sml29623 	} else {
18513859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
18526929Smisaki 		    "==> nxge_use_default_dma_config_n2: "
18536929Smisaki 		    "get tx-dma-channels failed"));
18543859Sml29623 		return (NXGE_DDI_FAILED);
18553859Sml29623 	}
18563859Sml29623 
18578275SEric Cheng 	p_cfgp->tdc.count = ndmas;
18586495Sspeer 	p_cfgp->tdc.owned = p_cfgp->tdc.count;
18593859Sml29623 
18603859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
18618275SEric Cheng 	    "p_cfgp 0x%llx max_tdcs %d start %d",
18628275SEric Cheng 	    p_cfgp, p_cfgp->tdc.count, p_cfgp->tdc.start));
18633859Sml29623 
18643859Sml29623 	/* Receive DMA */
18653859Sml29623 	ndmas = NXGE_RDMA_PER_NIU_PORT;
18663859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
18676929Smisaki 	    "rx-dma-channels", (int **)&prop_val,
18686929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
186910392SMichael.Speer@Sun.COM 		if (prop_len != NXGE_NIU_RDMA_PROP_LEN) {
18709015SMichael.Speer@Sun.COM 			ddi_prop_free(prop_val);
18719015SMichael.Speer@Sun.COM 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
18729015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2: "
187310392SMichael.Speer@Sun.COM 			    "invalid rx-dma-channels property for the NIU, "
187410392SMichael.Speer@Sun.COM 			    "using defaults"));
187510392SMichael.Speer@Sun.COM 			/*
187610392SMichael.Speer@Sun.COM 			 * Just failover to defaults
187710392SMichael.Speer@Sun.COM 			 */
187810392SMichael.Speer@Sun.COM 			p_cfgp->start_rdc = (func * NXGE_RDMA_PER_NIU_PORT);
187910392SMichael.Speer@Sun.COM 			ndmas = NXGE_RDMA_PER_NIU_PORT;
18809015SMichael.Speer@Sun.COM 		} else {
18819015SMichael.Speer@Sun.COM 			p_cfgp->start_rdc = prop_val[0];
18829015SMichael.Speer@Sun.COM 			NXGE_DEBUG_MSG((nxgep, OBP_CTL,
18839015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2(obp):"
18849015SMichael.Speer@Sun.COM 			    " rdc start %d (#%d)",
18859015SMichael.Speer@Sun.COM 			    p_cfgp->start_rdc, prop_len));
18869015SMichael.Speer@Sun.COM 			ndmas = prop_val[1];
18879015SMichael.Speer@Sun.COM 			NXGE_DEBUG_MSG((nxgep, OBP_CTL,
18889015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2(obp): "
18899015SMichael.Speer@Sun.COM 			    "#rdc %d (#%d)", ndmas, prop_len));
18909015SMichael.Speer@Sun.COM 			ddi_prop_free(prop_val);
18919015SMichael.Speer@Sun.COM 		}
18923859Sml29623 	} else {
18933859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
18946929Smisaki 		    "==> nxge_use_default_dma_config_n2: "
18956929Smisaki 		    "get rx-dma-channel failed"));
18963859Sml29623 		return (NXGE_DDI_FAILED);
18973859Sml29623 	}
18983859Sml29623 
18998275SEric Cheng 	p_cfgp->max_rdcs = ndmas;
19003859Sml29623 	nxgep->rdc_mask = (ndmas - 1);
19013859Sml29623 
19023859Sml29623 	/* Hypervisor: rdc # and group # use the same # !! */
19036495Sspeer 	p_cfgp->max_grpids = p_cfgp->max_rdcs + p_cfgp->tdc.owned;
19043859Sml29623 	p_cfgp->mif_ldvid = p_cfgp->mac_ldvid = p_cfgp->ser_ldvid = 0;
19053859Sml29623 
19063859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
19076929Smisaki 	    "interrupts", (int **)&prop_val,
19086929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
19099015SMichael.Speer@Sun.COM 		if ((prop_len != NXGE_NIU_0_INTR_PROP_LEN) &&
19109015SMichael.Speer@Sun.COM 		    (prop_len != NXGE_NIU_1_INTR_PROP_LEN)) {
19119015SMichael.Speer@Sun.COM 			ddi_prop_free(prop_val);
19129015SMichael.Speer@Sun.COM 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
19139015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2: "
19149015SMichael.Speer@Sun.COM 			    "get interrupts failed"));
19159015SMichael.Speer@Sun.COM 			return (NXGE_DDI_FAILED);
19169015SMichael.Speer@Sun.COM 		}
19179015SMichael.Speer@Sun.COM 
19183859Sml29623 		/*
19193859Sml29623 		 * For each device assigned, the content of each interrupts
19203859Sml29623 		 * property is its logical device group.
19213859Sml29623 		 *
19223859Sml29623 		 * Assignment of interrupts property is in the the following
19233859Sml29623 		 * order:
19243859Sml29623 		 *
19253859Sml29623 		 * MAC MIF (if configured) SYSTEM ERROR (if configured) first
19263859Sml29623 		 * receive channel next channel...... last receive channel
19273859Sml29623 		 * first transmit channel next channel...... last transmit
19283859Sml29623 		 * channel
19293859Sml29623 		 *
19303859Sml29623 		 * prop_len should be at least for one mac and total # of rx and
19313859Sml29623 		 * tx channels. Function 0 owns MIF and ERROR
19323859Sml29623 		 */
19333859Sml29623 		NXGE_DEBUG_MSG((nxgep, OBP_CTL,
19346929Smisaki 		    "==> nxge_use_default_dma_config_n2(obp): "
19356929Smisaki 		    "# interrupts %d", prop_len));
19363859Sml29623 
19373859Sml29623 		switch (func) {
19383859Sml29623 		case 0:
19393859Sml29623 			p_cfgp->ldg_chn_start = 3;
19403859Sml29623 			p_cfgp->mac_ldvid = NXGE_MAC_LD_PORT0;
19413859Sml29623 			p_cfgp->mif_ldvid = NXGE_MIF_LD;
19423859Sml29623 			p_cfgp->ser_ldvid = NXGE_SYS_ERROR_LD;
19433859Sml29623 
19443859Sml29623 			break;
19453859Sml29623 		case 1:
19463859Sml29623 			p_cfgp->ldg_chn_start = 1;
19473859Sml29623 			p_cfgp->mac_ldvid = NXGE_MAC_LD_PORT1;
19483859Sml29623 
19493859Sml29623 			break;
19503859Sml29623 		default:
19513859Sml29623 			status = NXGE_DDI_FAILED;
19523859Sml29623 			break;
19533859Sml29623 		}
19543859Sml29623 
19553859Sml29623 		if (status != NXGE_OK)
19563859Sml29623 			return (status);
19573859Sml29623 
19583859Sml29623 		for (i = 0; i < prop_len; i++) {
19593859Sml29623 			p_cfgp->ldg[i] = prop_val[i];
19603859Sml29623 			NXGE_DEBUG_MSG((nxgep, OBP_CTL,
19616929Smisaki 			    "==> nxge_use_default_dma_config_n2(obp): "
19626929Smisaki 			    "F%d: interrupt #%d, ldg %d",
19636929Smisaki 			    nxgep->function_num, i, p_cfgp->ldg[i]));
19643859Sml29623 		}
19653859Sml29623 
19663859Sml29623 		p_cfgp->max_grpids = prop_len;
19673859Sml29623 		NXGE_DEBUG_MSG((nxgep, OBP_CTL,
19686929Smisaki 		    "==> nxge_use_default_dma_config_n2(obp): %d "
19696929Smisaki 		    "(#%d) maxgrpids %d channel starts %d",
19706929Smisaki 		    p_cfgp->mac_ldvid, i, p_cfgp->max_grpids,
19716929Smisaki 		    p_cfgp->ldg_chn_start));
19723859Sml29623 		ddi_prop_free(prop_val);
19733859Sml29623 	} else {
19743859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
19756929Smisaki 		    "==> nxge_use_default_dma_config_n2: "
19766929Smisaki 		    "get interrupts failed"));
19773859Sml29623 		return (NXGE_DDI_FAILED);
19783859Sml29623 	}
19793859Sml29623 
19803859Sml29623 	p_cfgp->max_ldgs = p_cfgp->max_grpids;
19813859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL,
19828275SEric Cheng 	    "==> nxge_use_default_dma_config_n2: p_cfgp 0x%llx max_rdcs %d "
19838275SEric Cheng 	    "max_grpids %d macid %d mifid %d serrid %d",
19848275SEric Cheng 	    p_cfgp, p_cfgp->max_rdcs, p_cfgp->max_grpids,
19856929Smisaki 	    p_cfgp->mac_ldvid, p_cfgp->mif_ldvid, p_cfgp->ser_ldvid));
19863859Sml29623 
19878275SEric Cheng 
19883859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
19896929Smisaki 	    "p_cfgp p%p start_ldg %d nxgep->max_ldgs %d",
19906929Smisaki 	    p_cfgp, p_cfgp->start_ldg, p_cfgp->max_ldgs));
19913859Sml29623 
19923859Sml29623 	/*
19933859Sml29623 	 * RDC groups and the beginning RDC group assigned to this function.
19943859Sml29623 	 */
19958275SEric Cheng 	p_cfgp->max_rdc_grpids = NXGE_MAX_RDC_GROUPS / nxgep->nports;
19968275SEric Cheng 	p_cfgp->def_mac_rxdma_grpid =
19978275SEric Cheng 	    nxgep->function_num * NXGE_MAX_RDC_GROUPS / nxgep->nports;
19988275SEric Cheng 	p_cfgp->def_mac_txdma_grpid =
19998275SEric Cheng 	    nxgep->function_num * NXGE_MAX_TDC_GROUPS / nxgep->nports;
20008275SEric Cheng 
20018275SEric Cheng 	if ((p_cfgp->def_mac_rxdma_grpid = nxge_fzc_rdc_tbl_bind(nxgep,
20028275SEric Cheng 	    p_cfgp->def_mac_rxdma_grpid, B_TRUE)) >= NXGE_MAX_RDC_GRPS) {
20036495Sspeer 		NXGE_ERROR_MSG((nxgep, CFG_CTL,
20046495Sspeer 		    "nxge_use_default_dma_config_n2(): "
20056495Sspeer 		    "nxge_fzc_rdc_tbl_bind failed"));
20066495Sspeer 		return (NXGE_DDI_FAILED);
20076495Sspeer 	}
20083859Sml29623 
20093859Sml29623 	status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
20106495Sspeer 	    "rx-rdc-grps", p_cfgp->max_rdc_grpids);
20113859Sml29623 	if (status) {
20123859Sml29623 		return (NXGE_DDI_FAILED);
20133859Sml29623 	}
20143859Sml29623 	status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
20156929Smisaki 	    "rx-rdc-grps-begin", p_cfgp->def_mac_rxdma_grpid);
20163859Sml29623 	if (status) {
20173859Sml29623 		(void) ddi_prop_remove(DDI_DEV_T_NONE, nxgep->dip,
20186929Smisaki 		    "rx-rdc-grps");
20193859Sml29623 		return (NXGE_DDI_FAILED);
20203859Sml29623 	}
20213859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
20226929Smisaki 	    "p_cfgp $%p # rdc groups %d start rdc group id %d",
20236929Smisaki 	    p_cfgp, p_cfgp->max_rdc_grpids,
20246929Smisaki 	    p_cfgp->def_mac_rxdma_grpid));
20253859Sml29623 
20269005SSantwona.Behera@Sun.COM 	nxgep->intr_timeout = NXGE_RDC_RCR_TIMEOUT;
20279005SSantwona.Behera@Sun.COM 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
20289005SSantwona.Behera@Sun.COM 	    "rxdma-intr-time", (int **)&prop_val, &prop_len) ==
20299005SSantwona.Behera@Sun.COM 	    DDI_PROP_SUCCESS) {
20309005SSantwona.Behera@Sun.COM 		if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
20319005SSantwona.Behera@Sun.COM 			nxgep->intr_timeout = prop_val[0];
20329005SSantwona.Behera@Sun.COM 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
20339005SSantwona.Behera@Sun.COM 			    nxgep->dip, "rxdma-intr-time", prop_val, prop_len);
20349005SSantwona.Behera@Sun.COM 		}
20359005SSantwona.Behera@Sun.COM 		ddi_prop_free(prop_val);
20369005SSantwona.Behera@Sun.COM 	}
20379005SSantwona.Behera@Sun.COM 
20389005SSantwona.Behera@Sun.COM 	nxgep->intr_threshold = NXGE_RDC_RCR_THRESHOLD;
20399005SSantwona.Behera@Sun.COM 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
20409005SSantwona.Behera@Sun.COM 	    "rxdma-intr-pkts", (int **)&prop_val, &prop_len) ==
20419005SSantwona.Behera@Sun.COM 	    DDI_PROP_SUCCESS) {
20429005SSantwona.Behera@Sun.COM 		if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
20439005SSantwona.Behera@Sun.COM 			nxgep->intr_threshold = prop_val[0];
20449005SSantwona.Behera@Sun.COM 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
20459005SSantwona.Behera@Sun.COM 			    nxgep->dip, "rxdma-intr-pkts", prop_val, prop_len);
20469005SSantwona.Behera@Sun.COM 		}
20479005SSantwona.Behera@Sun.COM 		ddi_prop_free(prop_val);
20489005SSantwona.Behera@Sun.COM 	}
20499005SSantwona.Behera@Sun.COM 
20503859Sml29623 	nxge_set_hw_dma_config(nxgep);
20513859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "<== nxge_use_default_dma_config_n2"));
20523859Sml29623 	return (status);
20533859Sml29623 }
20543859Sml29623 
20553859Sml29623 static void
20563859Sml29623 nxge_use_cfg_dma_config(p_nxge_t nxgep)
20573859Sml29623 {
20584732Sdavemq 	int tx_ndmas, rx_ndmas, nrxgp, st_txdma, st_rxdma;
20593859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
20603859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
20613859Sml29623 	dev_info_t *dip;
20623859Sml29623 	p_nxge_param_t param_arr;
20633859Sml29623 	char *prop;
20643859Sml29623 	int *prop_val;
20653859Sml29623 	uint_t prop_len;
20664732Sdavemq 	int i;
20674732Sdavemq 	uint8_t *ch_arr_p;
20683859Sml29623 
20693859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_dma_config"));
20703859Sml29623 	param_arr = nxgep->param_arr;
20713859Sml29623 
20723859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
20733859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
20743859Sml29623 	dip = nxgep->dip;
20753859Sml29623 	p_cfgp->function_number = nxgep->function_num;
20763859Sml29623 	prop = param_arr[param_txdma_channels_begin].fcode_name;
20773859Sml29623 
20783859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
20796929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
20806495Sspeer 		p_cfgp->tdc.start = *prop_val;
20813859Sml29623 		ddi_prop_free(prop_val);
20823859Sml29623 	} else {
20834732Sdavemq 		switch (nxgep->niu_type) {
20844732Sdavemq 		case NEPTUNE_4_1GC:
20854732Sdavemq 			ch_arr_p = &tx_4_1G[0];
20864732Sdavemq 			break;
20874732Sdavemq 		case NEPTUNE_2_10GF:
20884732Sdavemq 			ch_arr_p = &tx_2_10G[0];
20894732Sdavemq 			break;
20904732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
20916261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
20924732Sdavemq 			ch_arr_p = &tx_2_10G_2_1G[0];
20934732Sdavemq 			break;
20944732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
20954732Sdavemq 			ch_arr_p = &tx_1_10G_3_1G[0];
20964732Sdavemq 			break;
20974732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
20984732Sdavemq 			ch_arr_p = &tx_1_1G_1_10G_2_1G[0];
20994732Sdavemq 			break;
21004732Sdavemq 		default:
21015196Ssbehera 			switch (nxgep->platform_type) {
21025196Ssbehera 			case P_NEPTUNE_ALONSO:
21035196Ssbehera 				ch_arr_p = &tx_2_10G_2_1G[0];
21045196Ssbehera 				break;
21055196Ssbehera 			default:
21065196Ssbehera 				ch_arr_p = &p4_tx_equal[0];
21075196Ssbehera 				break;
21085196Ssbehera 			}
21094732Sdavemq 			break;
21103859Sml29623 		}
21114732Sdavemq 		st_txdma = 0;
21124732Sdavemq 		for (i = 0; i < nxgep->function_num; i++, ch_arr_p++)
21134732Sdavemq 			st_txdma += *ch_arr_p;
21144732Sdavemq 
21153859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
21164732Sdavemq 		    prop, st_txdma);
21176495Sspeer 		p_cfgp->tdc.start = st_txdma;
21183859Sml29623 	}
21193859Sml29623 
21203859Sml29623 	prop = param_arr[param_txdma_channels].fcode_name;
21213859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
21226929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
21233859Sml29623 		tx_ndmas = *prop_val;
21243859Sml29623 		ddi_prop_free(prop_val);
21253859Sml29623 	} else {
21264732Sdavemq 		switch (nxgep->niu_type) {
21274732Sdavemq 		case NEPTUNE_4_1GC:
21284732Sdavemq 			tx_ndmas = tx_4_1G[nxgep->function_num];
21294732Sdavemq 			break;
21304732Sdavemq 		case NEPTUNE_2_10GF:
21314732Sdavemq 			tx_ndmas = tx_2_10G[nxgep->function_num];
21324732Sdavemq 			break;
21334732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
21346261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
21354732Sdavemq 			tx_ndmas = tx_2_10G_2_1G[nxgep->function_num];
21364732Sdavemq 			break;
21374732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
21384732Sdavemq 			tx_ndmas = tx_1_10G_3_1G[nxgep->function_num];
21394732Sdavemq 			break;
21404732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
21414732Sdavemq 			tx_ndmas = tx_1_1G_1_10G_2_1G[nxgep->function_num];
21424732Sdavemq 			break;
21434732Sdavemq 		default:
21445196Ssbehera 			switch (nxgep->platform_type) {
21455196Ssbehera 			case P_NEPTUNE_ALONSO:
21465196Ssbehera 				tx_ndmas = tx_2_10G_2_1G[nxgep->function_num];
21475196Ssbehera 				break;
21485196Ssbehera 			default:
21495196Ssbehera 				tx_ndmas = p4_tx_equal[nxgep->function_num];
21505196Ssbehera 				break;
21515196Ssbehera 			}
21524732Sdavemq 			break;
21533859Sml29623 		}
21543859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
21556929Smisaki 		    prop, tx_ndmas);
21563859Sml29623 	}
21573859Sml29623 
21588275SEric Cheng 	p_cfgp->tdc.count = tx_ndmas;
21596495Sspeer 	p_cfgp->tdc.owned = p_cfgp->tdc.count;
21603859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_dma_config: "
21618275SEric Cheng 	    "p_cfgp 0x%llx max_tdcs %d", p_cfgp, p_cfgp->tdc.count));
21623859Sml29623 
21633859Sml29623 	prop = param_arr[param_rxdma_channels_begin].fcode_name;
21643859Sml29623 
21653859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
21666929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
21673859Sml29623 		p_cfgp->start_rdc = *prop_val;
21683859Sml29623 		ddi_prop_free(prop_val);
21693859Sml29623 	} else {
21704732Sdavemq 		switch (nxgep->niu_type) {
21714732Sdavemq 		case NEPTUNE_4_1GC:
21724732Sdavemq 			ch_arr_p = &rx_4_1G[0];
21734732Sdavemq 			break;
21744732Sdavemq 		case NEPTUNE_2_10GF:
21754732Sdavemq 			ch_arr_p = &rx_2_10G[0];
21764732Sdavemq 			break;
21774732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
21786261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
21794732Sdavemq 			ch_arr_p = &rx_2_10G_2_1G[0];
21804732Sdavemq 			break;
21814732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
21824732Sdavemq 			ch_arr_p = &rx_1_10G_3_1G[0];
21834732Sdavemq 			break;
21844732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
21854732Sdavemq 			ch_arr_p = &rx_1_1G_1_10G_2_1G[0];
21864732Sdavemq 			break;
21874732Sdavemq 		default:
21885196Ssbehera 			switch (nxgep->platform_type) {
21895196Ssbehera 			case P_NEPTUNE_ALONSO:
21905196Ssbehera 				ch_arr_p = &rx_2_10G_2_1G[0];
21915196Ssbehera 				break;
21925196Ssbehera 			default:
21935196Ssbehera 				ch_arr_p = &p4_rx_equal[0];
21945196Ssbehera 				break;
21955196Ssbehera 			}
21964732Sdavemq 			break;
21973859Sml29623 		}
21984732Sdavemq 		st_rxdma = 0;
21994732Sdavemq 		for (i = 0; i < nxgep->function_num; i++, ch_arr_p++)
22004732Sdavemq 			st_rxdma += *ch_arr_p;
22014732Sdavemq 
22023859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
22034732Sdavemq 		    prop, st_rxdma);
22044732Sdavemq 		p_cfgp->start_rdc = st_rxdma;
22053859Sml29623 	}
22063859Sml29623 
22073859Sml29623 	prop = param_arr[param_rxdma_channels].fcode_name;
22083859Sml29623 
22093859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
22106929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
22113859Sml29623 		rx_ndmas = *prop_val;
22123859Sml29623 		ddi_prop_free(prop_val);
22133859Sml29623 	} else {
22144732Sdavemq 		switch (nxgep->niu_type) {
22154732Sdavemq 		case NEPTUNE_4_1GC:
22164732Sdavemq 			rx_ndmas = rx_4_1G[nxgep->function_num];
22174732Sdavemq 			break;
22184732Sdavemq 		case NEPTUNE_2_10GF:
22194732Sdavemq 			rx_ndmas = rx_2_10G[nxgep->function_num];
22204732Sdavemq 			break;
22214732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
22226261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
22234732Sdavemq 			rx_ndmas = rx_2_10G_2_1G[nxgep->function_num];
22244732Sdavemq 			break;
22254732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
22264732Sdavemq 			rx_ndmas = rx_1_10G_3_1G[nxgep->function_num];
22274732Sdavemq 			break;
22284732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
22294732Sdavemq 			rx_ndmas = rx_1_1G_1_10G_2_1G[nxgep->function_num];
22304732Sdavemq 			break;
22314732Sdavemq 		default:
22325196Ssbehera 			switch (nxgep->platform_type) {
22335196Ssbehera 			case P_NEPTUNE_ALONSO:
22345196Ssbehera 				rx_ndmas = rx_2_10G_2_1G[nxgep->function_num];
22355196Ssbehera 				break;
22365196Ssbehera 			default:
22375196Ssbehera 				rx_ndmas = p4_rx_equal[nxgep->function_num];
22385196Ssbehera 				break;
22395196Ssbehera 			}
22404732Sdavemq 			break;
22413859Sml29623 		}
22423859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
22436929Smisaki 		    prop, rx_ndmas);
22443859Sml29623 	}
22453859Sml29623 
22468275SEric Cheng 	p_cfgp->max_rdcs = rx_ndmas;
22478275SEric Cheng 
22488275SEric Cheng 	/*
22498275SEric Cheng 	 * RDC groups and the beginning RDC group assigned to this function.
22508275SEric Cheng 	 * XXX: this may be wrong if prop value is used.
22518275SEric Cheng 	 */
22528275SEric Cheng 	p_cfgp->def_mac_rxdma_grpid =
22538275SEric Cheng 	    nxgep->function_num * NXGE_MAX_RDC_GROUPS / nxgep->nports;
22548275SEric Cheng 	p_cfgp->def_mac_txdma_grpid =
22558275SEric Cheng 	    nxgep->function_num * NXGE_MAX_TDC_GROUPS / nxgep->nports;
22568275SEric Cheng 
22578275SEric Cheng 	if ((p_cfgp->def_mac_rxdma_grpid = nxge_fzc_rdc_tbl_bind(nxgep,
22588275SEric Cheng 	    p_cfgp->def_mac_rxdma_grpid, B_TRUE)) >= NXGE_MAX_RDC_GRPS) {
22598275SEric Cheng 		NXGE_ERROR_MSG((nxgep, CFG_CTL,
22608275SEric Cheng 		    "nxge_use_default_dma_config2(): "
22618275SEric Cheng 		    "nxge_fzc_rdc_tbl_bind failed"));
22628275SEric Cheng 		goto nxge_use_cfg_dma_config_exit;
22633859Sml29623 	}
22643859Sml29623 
22653859Sml29623 	prop = param_arr[param_rx_rdc_grps].fcode_name;
22663859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
22676929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
22683859Sml29623 		nrxgp = *prop_val;
22693859Sml29623 		ddi_prop_free(prop_val);
22703859Sml29623 	} else {
22718275SEric Cheng 		nrxgp = NXGE_MAX_RDC_GRPS / nxgep->nports;
22723859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
22736929Smisaki 		    prop, nrxgp);
22743859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
22756929Smisaki 		    "==> nxge_use_default_dma_config: "
22766929Smisaki 		    "num_rdc_grpid not found: use def:# of "
22776929Smisaki 		    "rdc groups %d\n", nrxgp));
22783859Sml29623 	}
22793859Sml29623 	p_cfgp->max_rdc_grpids = nrxgp;
22803859Sml29623 
22813859Sml29623 	/*
22823859Sml29623 	 * 2/4 ports have the same hard-wired logical groups assigned.
22833859Sml29623 	 */
22843859Sml29623 	p_cfgp->start_ldg = nxgep->function_num * NXGE_LDGRP_PER_4PORTS;
22853859Sml29623 	p_cfgp->max_ldgs = NXGE_LDGRP_PER_4PORTS;
22863859Sml29623 
22873859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_default_dma_config: "
22888275SEric Cheng 	    "p_cfgp 0x%llx max_rdcs %d max_grpids %d default_grpid %d",
22898275SEric Cheng 	    p_cfgp, p_cfgp->max_rdcs, p_cfgp->max_grpids,
22908275SEric Cheng 	    p_cfgp->def_mac_rxdma_grpid));
22913859Sml29623 
22923859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_dma_config: "
22936929Smisaki 	    "p_cfgp 0x%016llx start_ldg %d nxgep->max_ldgs %d "
22946929Smisaki 	    "def_mac_rxdma_grpid %d",
22956929Smisaki 	    p_cfgp, p_cfgp->start_ldg, p_cfgp->max_ldgs,
22966929Smisaki 	    p_cfgp->def_mac_rxdma_grpid));
22973859Sml29623 
22989005SSantwona.Behera@Sun.COM 	nxgep->intr_timeout = NXGE_RDC_RCR_TIMEOUT;
22993859Sml29623 	prop = param_arr[param_rxdma_intr_time].fcode_name;
23003859Sml29623 
23013859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
23026929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
23033859Sml29623 		if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
23049005SSantwona.Behera@Sun.COM 			nxgep->intr_timeout = prop_val[0];
23053859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
23066929Smisaki 			    nxgep->dip, prop, prop_val, prop_len);
23073859Sml29623 		}
23083859Sml29623 		ddi_prop_free(prop_val);
23093859Sml29623 	}
23109005SSantwona.Behera@Sun.COM 
23119005SSantwona.Behera@Sun.COM 	nxgep->intr_threshold = NXGE_RDC_RCR_THRESHOLD;
23123859Sml29623 	prop = param_arr[param_rxdma_intr_pkts].fcode_name;
23133859Sml29623 
23143859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
23156929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
23163859Sml29623 		if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
23179005SSantwona.Behera@Sun.COM 			nxgep->intr_threshold = prop_val[0];
23183859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
23196929Smisaki 			    nxgep->dip, prop, prop_val, prop_len);
23203859Sml29623 		}
23213859Sml29623 		ddi_prop_free(prop_val);
23223859Sml29623 	}
23233859Sml29623 	nxge_set_hw_dma_config(nxgep);
23243859Sml29623 
23254732Sdavemq 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_dma_config: "
23264732Sdavemq 	    "sTDC[%d] nTDC[%d] sRDC[%d] nRDC[%d]",
23276495Sspeer 	    p_cfgp->tdc.start, p_cfgp->tdc.count,
23284732Sdavemq 	    p_cfgp->start_rdc, p_cfgp->max_rdcs));
23294732Sdavemq 
23306495Sspeer nxge_use_cfg_dma_config_exit:
23313859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_dma_config"));
23323859Sml29623 }
23333859Sml29623 
23346495Sspeer void
23356495Sspeer nxge_get_logical_props(p_nxge_t nxgep)
23366495Sspeer {
23376495Sspeer 	nxge_dma_pt_cfg_t *port = &nxgep->pt_config;
23386495Sspeer 	nxge_hw_pt_cfg_t *hardware;
23396495Sspeer 	nxge_rdc_grp_t *group;
23406495Sspeer 
23416495Sspeer 	(void) memset(port, 0, sizeof (*port));
23426495Sspeer 
23438275SEric Cheng 	port->mac_port = nxgep->function_num;	/* := function number */
23446495Sspeer 
23456495Sspeer 	/*
23466495Sspeer 	 * alloc_buf_size:
23476495Sspeer 	 * dead variables.
23486495Sspeer 	 */
23496495Sspeer 	port->rbr_size = nxge_rbr_size;
23506495Sspeer 	port->rcr_size = nxge_rcr_size;
23516495Sspeer 
23526495Sspeer 	port->tx_dma_map = 0;	/* Transmit DMA channel bit map */
23536495Sspeer 
23546495Sspeer 	nxge_set_rdc_intr_property(nxgep);
23556495Sspeer 
23566495Sspeer 	port->rcr_full_header = NXGE_RCR_FULL_HEADER;
23576495Sspeer 	port->rx_drr_weight = PT_DRR_WT_DEFAULT_10G;
23586495Sspeer 
23596495Sspeer 	/* ----------------------------------------------------- */
23606495Sspeer 	hardware = &port->hw_config;
23616495Sspeer 
23626495Sspeer 	(void) memset(hardware, 0, sizeof (*hardware));
23636495Sspeer 
23646495Sspeer 	/*
23656495Sspeer 	 * partition_id, read_write_mode:
23666495Sspeer 	 * dead variables.
23676495Sspeer 	 */
23686495Sspeer 
23696495Sspeer 	/*
23706495Sspeer 	 * drr_wt, rx_full_header, *_ldg?, start_mac_entry,
23716495Sspeer 	 * mac_pref, def_mac_rxdma_grpid, start_vlan, max_vlans,
23726495Sspeer 	 * start_ldgs, max_ldgs, max_ldvs,
23736495Sspeer 	 * vlan_pref, def_vlan_rxdma_grpid are meaningful only
23746495Sspeer 	 * in the service domain.
23756495Sspeer 	 */
23766495Sspeer 
23776495Sspeer 	group = &port->rdc_grps[0];
23786495Sspeer 
23798275SEric Cheng 	group->flag = B_TRUE;	/* configured */
23806495Sspeer 	group->config_method = RDC_TABLE_ENTRY_METHOD_REP;
23818275SEric Cheng 	group->port = NXGE_GET_PORT_NUM(nxgep->function_num);
23826495Sspeer 
23836495Sspeer 	/* HIO futures: this is still an open question. */
23846495Sspeer 	hardware->max_macs = 1;
23856495Sspeer }
23866495Sspeer 
23873859Sml29623 static void
23883859Sml29623 nxge_use_cfg_vlan_class_config(p_nxge_t nxgep)
23893859Sml29623 {
23903859Sml29623 	uint_t vlan_cnt;
23913859Sml29623 	int *vlan_cfg_val;
23923859Sml29623 	int status;
23933859Sml29623 	p_nxge_param_t param_arr;
23943859Sml29623 	char *prop;
23953859Sml29623 
23963859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_vlan_config"));
23973859Sml29623 	param_arr = nxgep->param_arr;
23983859Sml29623 	prop = param_arr[param_vlan_2rdc_grp].fcode_name;
23993859Sml29623 
24003859Sml29623 	status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
24016929Smisaki 	    &vlan_cfg_val, &vlan_cnt);
24023859Sml29623 	if (status == DDI_PROP_SUCCESS) {
24033859Sml29623 		status = ddi_prop_update_int_array(DDI_DEV_T_NONE,
24046929Smisaki 		    nxgep->dip, prop, vlan_cfg_val, vlan_cnt);
24053859Sml29623 		ddi_prop_free(vlan_cfg_val);
24063859Sml29623 	}
24073859Sml29623 	nxge_set_hw_vlan_class_config(nxgep);
24083859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_vlan_config"));
24093859Sml29623 }
24103859Sml29623 
24113859Sml29623 static void
24123859Sml29623 nxge_use_cfg_mac_class_config(p_nxge_t nxgep)
24133859Sml29623 {
24143859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
24153859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
24163859Sml29623 	uint_t mac_cnt;
24173859Sml29623 	int *mac_cfg_val;
24183859Sml29623 	int status;
24193859Sml29623 	p_nxge_param_t param_arr;
24203859Sml29623 	char *prop;
24213859Sml29623 
24223859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_mac_class_config"));
24233859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
24243859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
24253859Sml29623 	p_cfgp->start_mac_entry = 0;
24263859Sml29623 	param_arr = nxgep->param_arr;
24273859Sml29623 	prop = param_arr[param_mac_2rdc_grp].fcode_name;
24283859Sml29623 
24293859Sml29623 	switch (nxgep->function_num) {
24303859Sml29623 	case 0:
24313859Sml29623 	case 1:
24323859Sml29623 		/* 10G ports */
24333859Sml29623 		p_cfgp->max_macs = NXGE_MAX_MACS_XMACS;
24343859Sml29623 		break;
24353859Sml29623 	case 2:
24363859Sml29623 	case 3:
24373859Sml29623 		/* 1G ports */
24383859Sml29623 	default:
24393859Sml29623 		p_cfgp->max_macs = NXGE_MAX_MACS_BMACS;
24403859Sml29623 		break;
24413859Sml29623 	}
24423859Sml29623 
24433859Sml29623 	p_cfgp->mac_pref = 1;
24443859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL,
24456929Smisaki 	    "== nxge_use_cfg_mac_class_config: "
24466929Smisaki 	    " mac_pref bit set def_mac_rxdma_grpid %d",
24476929Smisaki 	    p_cfgp->def_mac_rxdma_grpid));
24483859Sml29623 
24493859Sml29623 	status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
24506929Smisaki 	    &mac_cfg_val, &mac_cnt);
24513859Sml29623 	if (status == DDI_PROP_SUCCESS) {
24523859Sml29623 		if (mac_cnt <= p_cfgp->max_macs)
24533859Sml29623 			status = ddi_prop_update_int_array(DDI_DEV_T_NONE,
24546929Smisaki 			    nxgep->dip, prop, mac_cfg_val, mac_cnt);
24553859Sml29623 		ddi_prop_free(mac_cfg_val);
24563859Sml29623 	}
24573859Sml29623 	nxge_set_hw_mac_class_config(nxgep);
24583859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_mac_class_config"));
24593859Sml29623 }
24603859Sml29623 
24613859Sml29623 static void
24623859Sml29623 nxge_use_cfg_class_config(p_nxge_t nxgep)
24633859Sml29623 {
24643859Sml29623 	nxge_set_hw_class_config(nxgep);
24653859Sml29623 }
24663859Sml29623 
24673859Sml29623 static void
24683859Sml29623 nxge_set_rdc_intr_property(p_nxge_t nxgep)
24693859Sml29623 {
24703859Sml29623 	int i;
24713859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
24723859Sml29623 
24733859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_rdc_intr_property"));
24743859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
24753859Sml29623 
24763859Sml29623 	for (i = 0; i < NXGE_MAX_RDCS; i++) {
24779005SSantwona.Behera@Sun.COM 		p_dma_cfgp->rcr_timeout[i] = nxgep->intr_timeout;
24789005SSantwona.Behera@Sun.COM 		p_dma_cfgp->rcr_threshold[i] = nxgep->intr_threshold;
24793859Sml29623 	}
24803859Sml29623 
24813859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_rdc_intr_property"));
24823859Sml29623 }
24833859Sml29623 
24843859Sml29623 static void
24853859Sml29623 nxge_set_hw_dma_config(p_nxge_t nxgep)
24863859Sml29623 {
24878275SEric Cheng 	int			i, j, ngrps, bitmap, end, st_rdc;
24888275SEric Cheng 	p_nxge_dma_pt_cfg_t	p_dma_cfgp;
24898275SEric Cheng 	p_nxge_hw_pt_cfg_t	p_cfgp;
24908275SEric Cheng 	p_nxge_rdc_grp_t	rdc_grp_p;
24918275SEric Cheng 	p_nxge_tdc_grp_t	tdc_grp_p;
24928275SEric Cheng 	nxge_grp_t		*group;
24938275SEric Cheng 	uint8_t			nrdcs;
24948275SEric Cheng 	dc_map_t		map = 0;
24953859Sml29623 
24963859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_set_hw_dma_config"));
24973859Sml29623 
24983859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
24993859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
25008275SEric Cheng 
25018275SEric Cheng 	switch (nxgep->niu_type) {
25028275SEric Cheng 	case NEPTUNE_4_1GC:
25038275SEric Cheng 	case NEPTUNE_2_10GF_2_1GC:
25048275SEric Cheng 	case NEPTUNE_1_10GF_3_1GC:
25058275SEric Cheng 	case NEPTUNE_1_1GC_1_10GF_2_1GC:
25068275SEric Cheng 	case NEPTUNE_2_10GF_2_1GRF:
25078275SEric Cheng 	default:
25088275SEric Cheng 		ngrps = 2;
25098275SEric Cheng 		break;
25108275SEric Cheng 	case NEPTUNE_2_10GF:
25118275SEric Cheng 	case NEPTUNE_2_1GRF:
25128275SEric Cheng 	case N2_NIU:
25138275SEric Cheng 		ngrps = 4;
25148275SEric Cheng 		break;
25158275SEric Cheng 	}
25168275SEric Cheng 
25178275SEric Cheng 	/*
25188275SEric Cheng 	 * Setup TDC groups
25198275SEric Cheng 	 */
25203859Sml29623 	bitmap = 0;
25216495Sspeer 	end = p_cfgp->tdc.start + p_cfgp->tdc.owned;
25226495Sspeer 	for (i = p_cfgp->tdc.start; i < end; i++) {
25233859Sml29623 		bitmap |= (1 << i);
25243859Sml29623 	}
25253859Sml29623 
25266495Sspeer 	nxgep->tx_set.owned.map |= bitmap; /* Owned, & not shared. */
25278275SEric Cheng 	nxgep->tx_set.owned.count = p_cfgp->tdc.owned;
25283859Sml29623 	p_dma_cfgp->tx_dma_map = bitmap;
25298275SEric Cheng 
25308275SEric Cheng 	for (i = 0; i < ngrps; i++) {
25318275SEric Cheng 		group = (nxge_grp_t *)nxge_grp_add(nxgep,
25328275SEric Cheng 		    NXGE_TRANSMIT_GROUP);
25338275SEric Cheng 		tdc_grp_p = &p_dma_cfgp->tdc_grps[
25348275SEric Cheng 		    p_cfgp->def_mac_txdma_grpid + i];
25358275SEric Cheng 		if (i == 0)
25368275SEric Cheng 			tdc_grp_p->map = bitmap;
25378275SEric Cheng 		else
25388275SEric Cheng 			tdc_grp_p->map = 0;
25398275SEric Cheng 		/* no ring is associated with a group initially */
25408275SEric Cheng 		tdc_grp_p->start_tdc = 0;
25418275SEric Cheng 		tdc_grp_p->max_tdcs = 0;
25428275SEric Cheng 		tdc_grp_p->grp_index = group->index;
25438275SEric Cheng 	}
25448275SEric Cheng 
25458275SEric Cheng 	for (i = 0; i < NXGE_MAX_RDCS; i++) {
25468275SEric Cheng 		nxgep->rx_channel_started[i] = B_FALSE;
25478275SEric Cheng 	}
25488275SEric Cheng 
25498275SEric Cheng 	/*
25508275SEric Cheng 	 * Setup RDC groups
25518275SEric Cheng 	 */
25528275SEric Cheng 	st_rdc = p_cfgp->start_rdc;
25538275SEric Cheng 	for (i = 0; i < ngrps; i++) {
25548275SEric Cheng 		/*
25558275SEric Cheng 		 * All rings are associated with the default group initially
25568275SEric Cheng 		 */
25578275SEric Cheng 		if (i == 0) {
25588275SEric Cheng 			/* default group */
25598275SEric Cheng 			switch (nxgep->niu_type) {
25608275SEric Cheng 			case NEPTUNE_4_1GC:
25618275SEric Cheng 				nrdcs = rx_4_1G[nxgep->function_num];
25623859Sml29623 				break;
25638275SEric Cheng 			case N2_NIU:
25648275SEric Cheng 			case NEPTUNE_2_10GF:
25658275SEric Cheng 				nrdcs = rx_2_10G[nxgep->function_num];
25668275SEric Cheng 				break;
25678275SEric Cheng 			case NEPTUNE_2_10GF_2_1GC:
25688275SEric Cheng 				nrdcs = rx_2_10G_2_1G[nxgep->function_num];
25698275SEric Cheng 				break;
25708275SEric Cheng 			case NEPTUNE_1_10GF_3_1GC:
25718275SEric Cheng 				nrdcs = rx_1_10G_3_1G[nxgep->function_num];
25728275SEric Cheng 				break;
25738275SEric Cheng 			case NEPTUNE_1_1GC_1_10GF_2_1GC:
25748275SEric Cheng 				nrdcs = rx_1_1G_1_10G_2_1G[nxgep->function_num];
25753859Sml29623 				break;
25763859Sml29623 			default:
25778275SEric Cheng 				switch (nxgep->platform_type) {
25788275SEric Cheng 				case P_NEPTUNE_ALONSO:
25798275SEric Cheng 					nrdcs =
25808275SEric Cheng 					    rx_2_10G_2_1G[nxgep->function_num];
25818275SEric Cheng 					break;
25828275SEric Cheng 				default:
25838275SEric Cheng 					nrdcs = rx_4_1G[nxgep->function_num];
25848275SEric Cheng 					break;
25858275SEric Cheng 				}
25863859Sml29623 				break;
25873859Sml29623 			}
25888948SMichael.Speer@Sun.COM 
25898948SMichael.Speer@Sun.COM 			if (p_cfgp->max_rdcs < nrdcs)
25908948SMichael.Speer@Sun.COM 				nrdcs = p_cfgp->max_rdcs;
25918275SEric Cheng 		} else {
25928275SEric Cheng 			nrdcs = 0;
25933859Sml29623 		}
25946495Sspeer 
25956495Sspeer 		rdc_grp_p = &p_dma_cfgp->rdc_grps[
25966929Smisaki 		    p_cfgp->def_mac_rxdma_grpid + i];
25978275SEric Cheng 		rdc_grp_p->start_rdc = st_rdc;
25988275SEric Cheng 		rdc_grp_p->max_rdcs = nrdcs;
25996495Sspeer 		rdc_grp_p->def_rdc = rdc_grp_p->start_rdc;
26003859Sml29623 
26013859Sml29623 		/* default to: 0, 1, 2, 3, ...., 0, 1, 2, 3.... */
26028275SEric Cheng 		if (nrdcs != 0) {
26038275SEric Cheng 			for (j = 0; j < nrdcs; j++) {
26048275SEric Cheng 				map |= (1 << j);
26058275SEric Cheng 			}
26068275SEric Cheng 			map <<= rdc_grp_p->start_rdc;
26078275SEric Cheng 		} else
26088275SEric Cheng 			map = 0;
26096495Sspeer 		rdc_grp_p->map = map;
26106495Sspeer 
26116495Sspeer 		nxgep->rx_set.owned.map |= map; /* Owned, & not shared. */
26128275SEric Cheng 		nxgep->rx_set.owned.count = nrdcs;
26136495Sspeer 
26146495Sspeer 		group = (nxge_grp_t *)nxge_grp_add(nxgep, NXGE_RECEIVE_GROUP);
26156495Sspeer 
26163859Sml29623 		rdc_grp_p->config_method = RDC_TABLE_ENTRY_METHOD_SEQ;
26178275SEric Cheng 		rdc_grp_p->flag = B_TRUE; /* This group has been configured. */
26188275SEric Cheng 		rdc_grp_p->grp_index = group->index;
26198275SEric Cheng 		rdc_grp_p->port = NXGE_GET_PORT_NUM(nxgep->function_num);
26208275SEric Cheng 
26218275SEric Cheng 		map = 0;
26223859Sml29623 	}
26233859Sml29623 
26246495Sspeer 
26253859Sml29623 	/* default RDC */
26263859Sml29623 	p_cfgp->def_rdc = p_cfgp->start_rdc;
26273859Sml29623 	nxgep->def_rdc = p_cfgp->start_rdc;
26283859Sml29623 
26293859Sml29623 	/* full 18 byte header ? */
26303859Sml29623 	p_dma_cfgp->rcr_full_header = NXGE_RCR_FULL_HEADER;
26313859Sml29623 	p_dma_cfgp->rx_drr_weight = PT_DRR_WT_DEFAULT_10G;
26323859Sml29623 	if (nxgep->function_num > 1)
26333859Sml29623 		p_dma_cfgp->rx_drr_weight = PT_DRR_WT_DEFAULT_1G;
26343859Sml29623 	p_dma_cfgp->rbr_size = nxge_rbr_size;
26353859Sml29623 	p_dma_cfgp->rcr_size = nxge_rcr_size;
26363859Sml29623 
26373859Sml29623 	nxge_set_rdc_intr_property(nxgep);
26383859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_hw_dma_config"));
26393859Sml29623 }
26403859Sml29623 
26413859Sml29623 boolean_t
26423859Sml29623 nxge_check_rxdma_port_member(p_nxge_t nxgep, uint8_t rdc)
26433859Sml29623 {
26443859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
26453859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
26463859Sml29623 	int status = B_TRUE;
26473859Sml29623 
26483859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_rxdma_port_member"));
26493859Sml29623 
26503859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
26513859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
26523859Sml29623 
26533859Sml29623 	/* Receive DMA Channels */
26543859Sml29623 	if (rdc < p_cfgp->max_rdcs)
26553859Sml29623 		status = B_TRUE;
26563859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_rxdma_port_member"));
26573859Sml29623 	return (status);
26583859Sml29623 }
26593859Sml29623 
26603859Sml29623 boolean_t
26613859Sml29623 nxge_check_txdma_port_member(p_nxge_t nxgep, uint8_t tdc)
26623859Sml29623 {
26633859Sml29623 	int status = B_FALSE;
26643859Sml29623 
26656495Sspeer 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_txdma_port_member"));
26666495Sspeer 
26676495Sspeer 	if (tdc >= nxgep->pt_config.hw_config.tdc.start &&
26686495Sspeer 	    tdc < nxgep->pt_config.hw_config.tdc.count)
26693859Sml29623 		status = B_TRUE;
26706495Sspeer 
26716495Sspeer 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_txdma_port_member"));
26723859Sml29623 	return (status);
26733859Sml29623 }
26743859Sml29623 
26753859Sml29623 boolean_t
26763859Sml29623 nxge_check_rxdma_rdcgrp_member(p_nxge_t nxgep, uint8_t rdc_grp, uint8_t rdc)
26773859Sml29623 {
26783859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
26793859Sml29623 	int status = B_TRUE;
26803859Sml29623 	p_nxge_rdc_grp_t rdc_grp_p;
26813859Sml29623 
26823859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
26836929Smisaki 	    " ==> nxge_check_rxdma_rdcgrp_member"));
26843859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "  nxge_check_rxdma_rdcgrp_member"
26856929Smisaki 	    " rdc  %d group %d", rdc, rdc_grp));
26863859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
26873859Sml29623 
26883859Sml29623 	rdc_grp_p = &p_dma_cfgp->rdc_grps[rdc_grp];
26893859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "  max  %d ", rdc_grp_p->max_rdcs));
26903859Sml29623 	if (rdc >= rdc_grp_p->max_rdcs) {
26913859Sml29623 		status = B_FALSE;
26923859Sml29623 	}
26933859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
26946929Smisaki 	    " <== nxge_check_rxdma_rdcgrp_member"));
26953859Sml29623 	return (status);
26963859Sml29623 }
26973859Sml29623 
26983859Sml29623 boolean_t
26993859Sml29623 nxge_check_rdcgrp_port_member(p_nxge_t nxgep, uint8_t rdc_grp)
27003859Sml29623 {
27013859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
27023859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
27033859Sml29623 	int status = B_TRUE;
27043859Sml29623 
27053859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_rdcgrp_port_member"));
27063859Sml29623 
27073859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
27083859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
27093859Sml29623 
27103859Sml29623 	if (rdc_grp >= p_cfgp->max_rdc_grpids)
27113859Sml29623 		status = B_FALSE;
27123859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_rdcgrp_port_member"));
27133859Sml29623 	return (status);
27143859Sml29623 }
27153859Sml29623 
27163859Sml29623 static void
27173859Sml29623 nxge_set_hw_vlan_class_config(p_nxge_t nxgep)
27183859Sml29623 {
27193859Sml29623 	int i;
27203859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
27213859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
27223859Sml29623 	p_nxge_param_t param_arr;
27233859Sml29623 	uint_t vlan_cnt;
27243859Sml29623 	int *vlan_cfg_val;
27253859Sml29623 	nxge_param_map_t *vmap;
27263859Sml29623 	char *prop;
27273859Sml29623 	p_nxge_class_pt_cfg_t p_class_cfgp;
27283859Sml29623 	uint32_t good_cfg[32];
27293859Sml29623 	int good_count = 0;
27303859Sml29623 	nxge_mv_cfg_t *vlan_tbl;
27313859Sml29623 
27323859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_hw_vlan_config"));
27333859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
27343859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
27353859Sml29623 	p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
27363859Sml29623 
27373859Sml29623 	param_arr = nxgep->param_arr;
27383859Sml29623 	prop = param_arr[param_vlan_2rdc_grp].fcode_name;
27393859Sml29623 
27403859Sml29623 	/*
27413859Sml29623 	 * By default, VLAN to RDC group mapping is disabled Need to read HW or
27423859Sml29623 	 * .conf properties to find out if mapping is required
27433859Sml29623 	 *
27443859Sml29623 	 * Format
27453859Sml29623 	 *
27463859Sml29623 	 * uint32_t array, each array entry specifying the VLAN id and the
27473859Sml29623 	 * mapping
27483859Sml29623 	 *
27493859Sml29623 	 * bit[30] = add bit[29] = remove bit[28]  = preference bits[23-16] =
27503859Sml29623 	 * rdcgrp bits[15-0] = VLAN ID ( )
27513859Sml29623 	 */
27523859Sml29623 
27533859Sml29623 	for (i = 0; i < NXGE_MAX_VLANS; i++) {
27543859Sml29623 		p_class_cfgp->vlan_tbl[i].flag = 0;
27553859Sml29623 	}
27563859Sml29623 
27573859Sml29623 	vlan_tbl = (nxge_mv_cfg_t *)&p_class_cfgp->vlan_tbl[0];
27583859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
27596929Smisaki 	    &vlan_cfg_val, &vlan_cnt) == DDI_PROP_SUCCESS) {
27603859Sml29623 		for (i = 0; i < vlan_cnt; i++) {
27613859Sml29623 			vmap = (nxge_param_map_t *)&vlan_cfg_val[i];
27623859Sml29623 			if ((vmap->param_id) &&
27636929Smisaki 			    (vmap->param_id < NXGE_MAX_VLANS) &&
27646929Smisaki 			    (vmap->map_to <
27656929Smisaki 			    p_cfgp->max_rdc_grpids) &&
27666929Smisaki 			    (vmap->map_to >= (uint8_t)0)) {
27673859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
27686929Smisaki 				    " nxge_vlan_config mapping"
27696929Smisaki 				    " id %d grp %d",
27706929Smisaki 				    vmap->param_id, vmap->map_to));
27713859Sml29623 				good_cfg[good_count] = vlan_cfg_val[i];
27723859Sml29623 				if (vlan_tbl[vmap->param_id].flag == 0)
27733859Sml29623 					good_count++;
27743859Sml29623 				vlan_tbl[vmap->param_id].flag = 1;
27753859Sml29623 				vlan_tbl[vmap->param_id].rdctbl =
27766495Sspeer 				    vmap->map_to + p_cfgp->def_mac_rxdma_grpid;
27773859Sml29623 				vlan_tbl[vmap->param_id].mpr_npr = vmap->pref;
27783859Sml29623 			}
27793859Sml29623 		}
27803859Sml29623 		ddi_prop_free(vlan_cfg_val);
27813859Sml29623 		if (good_count != vlan_cnt) {
27823859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
27836929Smisaki 			    nxgep->dip, prop, (int *)good_cfg, good_count);
27843859Sml29623 		}
27853859Sml29623 	}
27863859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_set_hw_vlan_config"));
27873859Sml29623 }
27883859Sml29623 
27893859Sml29623 static void
27903859Sml29623 nxge_set_hw_mac_class_config(p_nxge_t nxgep)
27913859Sml29623 {
27923859Sml29623 	int i;
27933859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
27943859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
27953859Sml29623 	p_nxge_param_t param_arr;
27963859Sml29623 	uint_t mac_cnt;
27973859Sml29623 	int *mac_cfg_val;
27983859Sml29623 	nxge_param_map_t *mac_map;
27993859Sml29623 	char *prop;
28003859Sml29623 	p_nxge_class_pt_cfg_t p_class_cfgp;
28013859Sml29623 	int good_count = 0;
28023859Sml29623 	int good_cfg[NXGE_MAX_MACS];
28033859Sml29623 	nxge_mv_cfg_t *mac_host_info;
28043859Sml29623 
28053859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_set_hw_mac_config"));
28063859Sml29623 
28073859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
28083859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
28093859Sml29623 	p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
28103859Sml29623 	mac_host_info = (nxge_mv_cfg_t *)&p_class_cfgp->mac_host_info[0];
28113859Sml29623 
28123859Sml29623 	param_arr = nxgep->param_arr;
28133859Sml29623 	prop = param_arr[param_mac_2rdc_grp].fcode_name;
28143859Sml29623 
28153859Sml29623 	for (i = 0; i < NXGE_MAX_MACS; i++) {
28163859Sml29623 		p_class_cfgp->mac_host_info[i].flag = 0;
28174484Sspeer 		p_class_cfgp->mac_host_info[i].rdctbl =
28184484Sspeer 		    p_cfgp->def_mac_rxdma_grpid;
28193859Sml29623 	}
28203859Sml29623 
28213859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
28226929Smisaki 	    &mac_cfg_val, &mac_cnt) == DDI_PROP_SUCCESS) {
28233859Sml29623 		for (i = 0; i < mac_cnt; i++) {
28243859Sml29623 			mac_map = (nxge_param_map_t *)&mac_cfg_val[i];
28253859Sml29623 			if ((mac_map->param_id < p_cfgp->max_macs) &&
28266929Smisaki 			    (mac_map->map_to <
28276929Smisaki 			    p_cfgp->max_rdc_grpids) &&
28286929Smisaki 			    (mac_map->map_to >= (uint8_t)0)) {
28293859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
28306929Smisaki 				    " nxge_mac_config mapping"
28316929Smisaki 				    " id %d grp %d",
28326929Smisaki 				    mac_map->param_id, mac_map->map_to));
28333859Sml29623 				mac_host_info[mac_map->param_id].mpr_npr =
28348275SEric Cheng 				    p_cfgp->mac_pref;
28353859Sml29623 				mac_host_info[mac_map->param_id].rdctbl =
28366929Smisaki 				    mac_map->map_to +
28376929Smisaki 				    p_cfgp->def_mac_rxdma_grpid;
28383859Sml29623 				good_cfg[good_count] = mac_cfg_val[i];
28393859Sml29623 				if (mac_host_info[mac_map->param_id].flag == 0)
28403859Sml29623 					good_count++;
28413859Sml29623 				mac_host_info[mac_map->param_id].flag = 1;
28423859Sml29623 			}
28433859Sml29623 		}
28443859Sml29623 		ddi_prop_free(mac_cfg_val);
28453859Sml29623 		if (good_count != mac_cnt) {
28463859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
28476929Smisaki 			    nxgep->dip, prop, good_cfg, good_count);
28483859Sml29623 		}
28493859Sml29623 	}
28503859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_set_hw_mac_config"));
28513859Sml29623 }
28523859Sml29623 
28533859Sml29623 static void
28543859Sml29623 nxge_set_hw_class_config(p_nxge_t nxgep)
28553859Sml29623 {
28563859Sml29623 	int i;
28573859Sml29623 	p_nxge_param_t param_arr;
28583859Sml29623 	int *int_prop_val;
28593859Sml29623 	uint32_t cfg_value;
28603859Sml29623 	char *prop;
28613859Sml29623 	p_nxge_class_pt_cfg_t p_class_cfgp;
28623859Sml29623 	int start_prop, end_prop;
28633859Sml29623 	uint_t prop_cnt;
28649005SSantwona.Behera@Sun.COM 	int start_class, j = 0;
28653859Sml29623 
28663859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_hw_class_config"));
28673859Sml29623 
28683859Sml29623 	p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
28693859Sml29623 	param_arr = nxgep->param_arr;
28709005SSantwona.Behera@Sun.COM 	start_prop = param_class_opt_ipv4_tcp;
28713859Sml29623 	end_prop = param_class_opt_ipv6_sctp;
28729005SSantwona.Behera@Sun.COM 	start_class = TCAM_CLASS_TCP_IPV4;
28739005SSantwona.Behera@Sun.COM 
28749005SSantwona.Behera@Sun.COM 	for (i = start_prop, j = 0; i <= end_prop; i++, j++) {
28753859Sml29623 		prop = param_arr[i].fcode_name;
28763859Sml29623 		if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip,
28776929Smisaki 		    0, prop, &int_prop_val,
28786929Smisaki 		    &prop_cnt) == DDI_PROP_SUCCESS) {
28793859Sml29623 			cfg_value = (uint32_t)*int_prop_val;
28803859Sml29623 			ddi_prop_free(int_prop_val);
28813859Sml29623 		} else {
28823859Sml29623 			cfg_value = (uint32_t)param_arr[i].value;
28833859Sml29623 		}
28849005SSantwona.Behera@Sun.COM 		p_class_cfgp->class_cfg[start_class + j] = cfg_value;
28853859Sml29623 	}
28863859Sml29623 
28873859Sml29623 	prop = param_arr[param_h1_init_value].fcode_name;
28883859Sml29623 
28893859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
28906929Smisaki 	    &int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
28913859Sml29623 		cfg_value = (uint32_t)*int_prop_val;
28923859Sml29623 		ddi_prop_free(int_prop_val);
28933859Sml29623 	} else {
28943859Sml29623 		cfg_value = (uint32_t)param_arr[param_h1_init_value].value;
28953859Sml29623 	}
28963859Sml29623 
28973859Sml29623 	p_class_cfgp->init_h1 = (uint32_t)cfg_value;
28983859Sml29623 	prop = param_arr[param_h2_init_value].fcode_name;
28993859Sml29623 
29003859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
29016929Smisaki 	    &int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
29023859Sml29623 		cfg_value = (uint32_t)*int_prop_val;
29033859Sml29623 		ddi_prop_free(int_prop_val);
29043859Sml29623 	} else {
29053859Sml29623 		cfg_value = (uint32_t)param_arr[param_h2_init_value].value;
29063859Sml29623 	}
29073859Sml29623 
29083859Sml29623 	p_class_cfgp->init_h2 = (uint16_t)cfg_value;
29093859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_hw_class_config"));
29103859Sml29623 }
29113859Sml29623 
29123859Sml29623 nxge_status_t
29133859Sml29623 nxge_ldgv_init_n2(p_nxge_t nxgep, int *navail_p, int *nrequired_p)
29143859Sml29623 {
29156495Sspeer 	int i, maxldvs, maxldgs, nldvs;
29163859Sml29623 	int ldv, endldg;
29173859Sml29623 	uint8_t func;
29183859Sml29623 	uint8_t channel;
29193859Sml29623 	uint8_t chn_start;
29203859Sml29623 	boolean_t own_sys_err = B_FALSE, own_fzc = B_FALSE;
29213859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
29223859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
29233859Sml29623 	p_nxge_ldgv_t ldgvp;
29243859Sml29623 	p_nxge_ldg_t ldgp, ptr;
29257466SMisaki.Kataoka@Sun.COM 	p_nxge_ldv_t ldvp, sysldvp;
29263859Sml29623 	nxge_status_t status = NXGE_OK;
29276495Sspeer 	nxge_grp_set_t *set;
29283859Sml29623 
29293859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2"));
29303859Sml29623 	if (!*navail_p) {
29313859Sml29623 		*nrequired_p = 0;
29323859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
29336929Smisaki 		    "<== nxge_ldgv_init:no avail"));
29343859Sml29623 		return (NXGE_ERROR);
29353859Sml29623 	}
29363859Sml29623 	/*
29373859Sml29623 	 * N2/NIU: one logical device owns one logical group. and each
29383859Sml29623 	 * device/group will be assigned one vector by Hypervisor.
29393859Sml29623 	 */
29403859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
29413859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
29423859Sml29623 	maxldgs = p_cfgp->max_ldgs;
29433859Sml29623 	if (!maxldgs) {
29443859Sml29623 		/* No devices configured. */
29453859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_init_n2: "
29466929Smisaki 		    "no logical groups configured."));
29473859Sml29623 		return (NXGE_ERROR);
29483859Sml29623 	} else {
29493859Sml29623 		maxldvs = maxldgs + 1;
29503859Sml29623 	}
29513859Sml29623 
29523859Sml29623 	/*
29533859Sml29623 	 * If function zero instance, it needs to handle the system and MIF
29543859Sml29623 	 * error interrupts. MIF interrupt may not be needed for N2/NIU.
29553859Sml29623 	 */
29563859Sml29623 	func = nxgep->function_num;
29573859Sml29623 	if (func == 0) {
29583859Sml29623 		own_sys_err = B_TRUE;
29593859Sml29623 		if (!p_cfgp->ser_ldvid) {
29603859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
29616929Smisaki 			    "nxge_ldgv_init_n2: func 0, ERR ID not set!"));
29623859Sml29623 		}
29633859Sml29623 		/* MIF interrupt */
29643859Sml29623 		if (!p_cfgp->mif_ldvid) {
29653859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
29666929Smisaki 			    "nxge_ldgv_init_n2: func 0, MIF ID not set!"));
29673859Sml29623 		}
29683859Sml29623 	}
29693859Sml29623 
29703859Sml29623 	/*
29713859Sml29623 	 * Assume single partition, each function owns mac.
29723859Sml29623 	 */
29733859Sml29623 	if (!nxge_use_partition)
29743859Sml29623 		own_fzc = B_TRUE;
29753859Sml29623 
29763859Sml29623 	ldgvp = nxgep->ldgvp;
29773859Sml29623 	if (ldgvp == NULL) {
29783859Sml29623 		ldgvp = KMEM_ZALLOC(sizeof (nxge_ldgv_t), KM_SLEEP);
29793859Sml29623 		nxgep->ldgvp = ldgvp;
29803859Sml29623 		ldgvp->maxldgs = (uint8_t)maxldgs;
29813859Sml29623 		ldgvp->maxldvs = (uint8_t)maxldvs;
29826495Sspeer 		ldgp = ldgvp->ldgp = KMEM_ZALLOC(
29836929Smisaki 		    sizeof (nxge_ldg_t) * maxldgs, KM_SLEEP);
29846495Sspeer 		ldvp = ldgvp->ldvp = KMEM_ZALLOC(
29856929Smisaki 		    sizeof (nxge_ldv_t) * maxldvs, KM_SLEEP);
29863859Sml29623 	} else {
29873859Sml29623 		ldgp = ldgvp->ldgp;
29883859Sml29623 		ldvp = ldgvp->ldvp;
29893859Sml29623 	}
29903859Sml29623 
29916495Sspeer 	ldgvp->ndma_ldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
29923859Sml29623 	ldgvp->tmres = NXGE_TIMER_RESO;
29933859Sml29623 
29943859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
29956929Smisaki 	    "==> nxge_ldgv_init_n2: maxldvs %d maxldgs %d",
29966929Smisaki 	    maxldvs, maxldgs));
29973859Sml29623 
29983859Sml29623 	/* logical start_ldg is ldv */
29993859Sml29623 	ptr = ldgp;
30003859Sml29623 	for (i = 0; i < maxldgs; i++) {
30013859Sml29623 		ptr->func = func;
30023859Sml29623 		ptr->arm = B_TRUE;
30033859Sml29623 		ptr->vldg_index = (uint8_t)i;
30043859Sml29623 		ptr->ldg_timer = NXGE_TIMER_LDG;
30053859Sml29623 		ptr->ldg = p_cfgp->ldg[i];
30063859Sml29623 		ptr->sys_intr_handler = nxge_intr;
30073859Sml29623 		ptr->nldvs = 0;
30083859Sml29623 		ptr->ldvp = NULL;
30093859Sml29623 		ptr->nxgep = nxgep;
30103859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
30116929Smisaki 		    "==> nxge_ldgv_init_n2: maxldvs %d maxldgs %d "
30126929Smisaki 		    "ldg %d ldgptr $%p",
30136929Smisaki 		    maxldvs, maxldgs, ptr->ldg, ptr));
30143859Sml29623 		ptr++;
30153859Sml29623 	}
30163859Sml29623 
30173859Sml29623 	endldg = NXGE_INT_MAX_LDG;
30183859Sml29623 	nldvs = 0;
30193859Sml29623 	ldgvp->nldvs = 0;
30203859Sml29623 	ldgp->ldvp = NULL;
30213859Sml29623 	*nrequired_p = 0;
30223859Sml29623 
30233859Sml29623 	/*
30243859Sml29623 	 * logical device group table is organized in the following order (same
30253859Sml29623 	 * as what interrupt property has). function 0: owns MAC, MIF, error,
30263859Sml29623 	 * rx, tx. function 1: owns MAC, rx, tx.
30273859Sml29623 	 */
30283859Sml29623 
30293859Sml29623 	if (own_fzc && p_cfgp->mac_ldvid) {
30303859Sml29623 		/* Each function should own MAC interrupt */
30313859Sml29623 		ldv = p_cfgp->mac_ldvid;
30323859Sml29623 		ldvp->ldv = (uint8_t)ldv;
30333859Sml29623 		ldvp->is_mac = B_TRUE;
30343859Sml29623 		ldvp->ldv_intr_handler = nxge_mac_intr;
30353859Sml29623 		ldvp->ldv_ldf_masks = 0;
30363859Sml29623 		ldvp->nxgep = nxgep;
30373859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
30386929Smisaki 		    "==> nxge_ldgv_init_n2(mac): maxldvs %d ldv %d "
30396929Smisaki 		    "ldg %d ldgptr $%p ldvptr $%p",
30406929Smisaki 		    maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
30413859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
30423859Sml29623 		nldvs++;
30433859Sml29623 	}
30443859Sml29623 
30453859Sml29623 	if (own_fzc && p_cfgp->mif_ldvid) {
30463859Sml29623 		ldv = p_cfgp->mif_ldvid;
30473859Sml29623 		ldvp->ldv = (uint8_t)ldv;
30483859Sml29623 		ldvp->is_mif = B_TRUE;
30493859Sml29623 		ldvp->ldv_intr_handler = nxge_mif_intr;
30503859Sml29623 		ldvp->ldv_ldf_masks = 0;
30513859Sml29623 		ldvp->nxgep = nxgep;
30523859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
30536929Smisaki 		    "==> nxge_ldgv_init_n2(mif): maxldvs %d ldv %d "
30546929Smisaki 		    "ldg %d ldgptr $%p ldvptr $%p",
30556929Smisaki 		    maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
30563859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
30573859Sml29623 		nldvs++;
30583859Sml29623 	}
30593859Sml29623 
30607466SMisaki.Kataoka@Sun.COM 	/*
30618275SEric Cheng 	 * HW based syserr interrupt for port0, and SW based syserr interrupt
30628275SEric Cheng 	 * for port1
30637466SMisaki.Kataoka@Sun.COM 	 */
30643859Sml29623 	if (own_sys_err && p_cfgp->ser_ldvid) {
30653859Sml29623 		ldv = p_cfgp->ser_ldvid;
30663859Sml29623 		/*
30673859Sml29623 		 * Unmask the system interrupt states.
30683859Sml29623 		 */
30693859Sml29623 		(void) nxge_fzc_sys_err_mask_set(nxgep, SYS_ERR_SMX_MASK |
30706929Smisaki 		    SYS_ERR_IPP_MASK | SYS_ERR_TXC_MASK |
30716929Smisaki 		    SYS_ERR_ZCP_MASK);
30727466SMisaki.Kataoka@Sun.COM 
30737466SMisaki.Kataoka@Sun.COM 		ldvp->use_timer = B_TRUE;
30747466SMisaki.Kataoka@Sun.COM 		ldvp->ldv = (uint8_t)ldv;
30757466SMisaki.Kataoka@Sun.COM 		ldvp->is_syserr = B_TRUE;
30767466SMisaki.Kataoka@Sun.COM 		ldvp->ldv_intr_handler = nxge_syserr_intr;
30777466SMisaki.Kataoka@Sun.COM 		ldvp->ldv_ldf_masks = 0;
30787466SMisaki.Kataoka@Sun.COM 		ldvp->nxgep = nxgep;
30797466SMisaki.Kataoka@Sun.COM 		ldgvp->ldvp_syserr = ldvp;
30807466SMisaki.Kataoka@Sun.COM 
30817466SMisaki.Kataoka@Sun.COM 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
30827466SMisaki.Kataoka@Sun.COM 		    "==> nxge_ldgv_init_n2(syserr): maxldvs %d ldv %d "
30837466SMisaki.Kataoka@Sun.COM 		    "ldg %d ldgptr $%p ldvptr p%p",
30847466SMisaki.Kataoka@Sun.COM 		    maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
30857466SMisaki.Kataoka@Sun.COM 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
30867466SMisaki.Kataoka@Sun.COM 		nldvs++;
30877466SMisaki.Kataoka@Sun.COM 	} else {
30887466SMisaki.Kataoka@Sun.COM 		/*
30898275SEric Cheng 		 * SW based: allocate the ldv for the syserr since the vector
30908275SEric Cheng 		 * should not be consumed for port1
30917466SMisaki.Kataoka@Sun.COM 		 */
30927466SMisaki.Kataoka@Sun.COM 		sysldvp = KMEM_ZALLOC(sizeof (nxge_ldv_t), KM_SLEEP);
30937466SMisaki.Kataoka@Sun.COM 		sysldvp->use_timer = B_TRUE;
30947466SMisaki.Kataoka@Sun.COM 		sysldvp->ldv = NXGE_SYS_ERROR_LD;
30957466SMisaki.Kataoka@Sun.COM 		sysldvp->is_syserr = B_TRUE;
30967466SMisaki.Kataoka@Sun.COM 		sysldvp->ldv_intr_handler = nxge_syserr_intr;
30977466SMisaki.Kataoka@Sun.COM 		sysldvp->ldv_ldf_masks = 0;
30987466SMisaki.Kataoka@Sun.COM 		sysldvp->nxgep = nxgep;
30997466SMisaki.Kataoka@Sun.COM 		ldgvp->ldvp_syserr = sysldvp;
31008275SEric Cheng 		ldgvp->ldvp_syserr_alloced = B_TRUE;
31013859Sml29623 	}
31023859Sml29623 
31038275SEric Cheng 
31043859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
31056929Smisaki 	    "(before rx) func %d nldvs %d navail %d nrequired %d",
31066929Smisaki 	    func, nldvs, *navail_p, *nrequired_p));
31073859Sml29623 
31083859Sml29623 	/*
31093859Sml29623 	 * Start with RDC to configure logical devices for each group.
31103859Sml29623 	 */
31116495Sspeer 	chn_start = p_cfgp->ldg_chn_start;
31126495Sspeer 	set = &nxgep->rx_set;
31136495Sspeer 	for (channel = 0; channel < NXGE_MAX_RDCS; channel++) {
31146495Sspeer 		if ((1 << channel) & set->owned.map) {
31156495Sspeer 			ldvp->is_rxdma = B_TRUE;
31166495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_RDMA_LD_START;
31176495Sspeer 			ldvp->channel = channel;
31186495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
31196495Sspeer 			ldvp->ldv_intr_handler = nxge_rx_intr;
31206495Sspeer 			ldvp->ldv_ldf_masks = 0;
31216495Sspeer 			ldvp->nxgep = nxgep;
31226495Sspeer 			ldgp->ldg = p_cfgp->ldg[chn_start];
31236495Sspeer 
31246495Sspeer 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
31256495Sspeer 			    "==> nxge_ldgv_init_n2(rx%d): maxldvs %d ldv %d "
31266495Sspeer 			    "ldg %d ldgptr 0x%016llx ldvptr 0x%016llx",
31276495Sspeer 			    i, maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
31286495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
31296495Sspeer 			    endldg, nrequired_p);
31306495Sspeer 			nldvs++;
31316495Sspeer 			chn_start++;
31326495Sspeer 		}
31333859Sml29623 	}
31343859Sml29623 
31353859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
31366929Smisaki 	    "func %d nldvs %d navail %d nrequired %d",
31376929Smisaki 	    func, nldvs, *navail_p, *nrequired_p));
31383859Sml29623 
31393859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
31406929Smisaki 	    "func %d nldvs %d navail %d nrequired %d ldgp 0x%llx "
31416929Smisaki 	    "ldvp 0x%llx",
31426929Smisaki 	    func, nldvs, *navail_p, *nrequired_p, ldgp, ldvp));
31433859Sml29623 	/*
31443859Sml29623 	 * Transmit DMA channels.
31453859Sml29623 	 */
31466495Sspeer 	chn_start = p_cfgp->ldg_chn_start + 8;
31476495Sspeer 	set = &nxgep->tx_set;
31486495Sspeer 	for (channel = 0; channel < NXGE_MAX_TDCS; channel++) {
31496495Sspeer 		if ((1 << channel) & set->owned.map) {
31506495Sspeer 			ldvp->is_txdma = B_TRUE;
31516495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_TDMA_LD_START;
31526495Sspeer 			ldvp->channel = channel;
31536495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
31546495Sspeer 			ldvp->ldv_intr_handler = nxge_tx_intr;
31556495Sspeer 			ldvp->ldv_ldf_masks = 0;
31566495Sspeer 			ldgp->ldg = p_cfgp->ldg[chn_start];
31576495Sspeer 			ldvp->nxgep = nxgep;
31586495Sspeer 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
31596495Sspeer 			    "==> nxge_ldgv_init_n2(tx%d): maxldvs %d ldv %d "
31606495Sspeer 			    "ldg %d ldgptr %p ldvptr %p",
31616495Sspeer 			    channel, maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
31626495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
31636495Sspeer 			    endldg, nrequired_p);
31646495Sspeer 			nldvs++;
31656495Sspeer 			chn_start++;
31666495Sspeer 		}
31673859Sml29623 	}
31683859Sml29623 
31693859Sml29623 	ldgvp->ldg_intrs = *nrequired_p;
31703859Sml29623 	ldgvp->nldvs = (uint8_t)nldvs;
31713859Sml29623 
31723859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
31736929Smisaki 	    "func %d nldvs %d maxgrps %d navail %d nrequired %d",
31746929Smisaki 	    func, nldvs, maxldgs, *navail_p, *nrequired_p));
31753859Sml29623 
31763859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_init_n2"));
31773859Sml29623 	return (status);
31783859Sml29623 }
31793859Sml29623 
31803859Sml29623 /*
31813859Sml29623  * Interrupts related interface functions.
31823859Sml29623  */
31833859Sml29623 
31843859Sml29623 nxge_status_t
31853859Sml29623 nxge_ldgv_init(p_nxge_t nxgep, int *navail_p, int *nrequired_p)
31863859Sml29623 {
31876495Sspeer 	int i, maxldvs, maxldgs, nldvs;
31883859Sml29623 	int ldv, ldg, endldg, ngrps;
31893859Sml29623 	uint8_t func;
31903859Sml29623 	uint8_t channel;
31913859Sml29623 	boolean_t own_sys_err = B_FALSE, own_fzc = B_FALSE;
31923859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
31933859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
31943859Sml29623 	p_nxge_ldgv_t ldgvp;
31953859Sml29623 	p_nxge_ldg_t ldgp, ptr;
31963859Sml29623 	p_nxge_ldv_t ldvp;
31976495Sspeer 	nxge_grp_set_t *set;
31986495Sspeer 
31993859Sml29623 	nxge_status_t status = NXGE_OK;
32003859Sml29623 
32013859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init"));
32023859Sml29623 	if (!*navail_p) {
32033859Sml29623 		*nrequired_p = 0;
32043859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
32056929Smisaki 		    "<== nxge_ldgv_init:no avail"));
32063859Sml29623 		return (NXGE_ERROR);
32073859Sml29623 	}
32083859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
32093859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
32103859Sml29623 
32116495Sspeer 	nldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
32123859Sml29623 
32133859Sml29623 	/*
32143859Sml29623 	 * If function zero instance, it needs to handle the system error
32153859Sml29623 	 * interrupts.
32163859Sml29623 	 */
32173859Sml29623 	func = nxgep->function_num;
32183859Sml29623 	if (func == 0) {
32193859Sml29623 		nldvs++;
32203859Sml29623 		own_sys_err = B_TRUE;
32213859Sml29623 	} else {
32223859Sml29623 		/* use timer */
32233859Sml29623 		nldvs++;
32243859Sml29623 	}
32253859Sml29623 
32263859Sml29623 	/*
32273859Sml29623 	 * Assume single partition, each function owns mac.
32283859Sml29623 	 */
32293859Sml29623 	if (!nxge_use_partition) {
32303859Sml29623 		/* mac */
32313859Sml29623 		nldvs++;
32323859Sml29623 		/* MIF */
32333859Sml29623 		nldvs++;
32343859Sml29623 		own_fzc = B_TRUE;
32353859Sml29623 	}
32363859Sml29623 	maxldvs = nldvs;
32373859Sml29623 	maxldgs = p_cfgp->max_ldgs;
32383859Sml29623 	if (!maxldvs || !maxldgs) {
32393859Sml29623 		/* No devices configured. */
32403859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_init: "
32416929Smisaki 		    "no logical devices or groups configured."));
32423859Sml29623 		return (NXGE_ERROR);
32433859Sml29623 	}
32443859Sml29623 	ldgvp = nxgep->ldgvp;
32453859Sml29623 	if (ldgvp == NULL) {
32463859Sml29623 		ldgvp = KMEM_ZALLOC(sizeof (nxge_ldgv_t), KM_SLEEP);
32473859Sml29623 		nxgep->ldgvp = ldgvp;
32483859Sml29623 		ldgvp->maxldgs = (uint8_t)maxldgs;
32493859Sml29623 		ldgvp->maxldvs = (uint8_t)maxldvs;
32503859Sml29623 		ldgp = ldgvp->ldgp = KMEM_ZALLOC(sizeof (nxge_ldg_t) * maxldgs,
32516929Smisaki 		    KM_SLEEP);
32523859Sml29623 		ldvp = ldgvp->ldvp = KMEM_ZALLOC(sizeof (nxge_ldv_t) * maxldvs,
32536929Smisaki 		    KM_SLEEP);
32543859Sml29623 	}
32556495Sspeer 	ldgvp->ndma_ldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
32563859Sml29623 	ldgvp->tmres = NXGE_TIMER_RESO;
32573859Sml29623 
32583859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
32596929Smisaki 	    "==> nxge_ldgv_init: maxldvs %d maxldgs %d nldvs %d",
32606929Smisaki 	    maxldvs, maxldgs, nldvs));
32613859Sml29623 	ldg = p_cfgp->start_ldg;
32623859Sml29623 	ptr = ldgp;
32633859Sml29623 	for (i = 0; i < maxldgs; i++) {
32643859Sml29623 		ptr->func = func;
32653859Sml29623 		ptr->arm = B_TRUE;
32663859Sml29623 		ptr->vldg_index = (uint8_t)i;
32673859Sml29623 		ptr->ldg_timer = NXGE_TIMER_LDG;
32683859Sml29623 		ptr->ldg = ldg++;
32693859Sml29623 		ptr->sys_intr_handler = nxge_intr;
32703859Sml29623 		ptr->nldvs = 0;
32713859Sml29623 		ptr->nxgep = nxgep;
32723859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
32736929Smisaki 		    "==> nxge_ldgv_init: maxldvs %d maxldgs %d ldg %d",
32746929Smisaki 		    maxldvs, maxldgs, ptr->ldg));
32753859Sml29623 		ptr++;
32763859Sml29623 	}
32773859Sml29623 
32783859Sml29623 	ldg = p_cfgp->start_ldg;
32793859Sml29623 	if (maxldgs > *navail_p) {
32803859Sml29623 		ngrps = *navail_p;
32813859Sml29623 	} else {
32823859Sml29623 		ngrps = maxldgs;
32833859Sml29623 	}
32843859Sml29623 	endldg = ldg + ngrps;
32853859Sml29623 
32863859Sml29623 	/*
32873859Sml29623 	 * Receive DMA channels.
32883859Sml29623 	 */
32893859Sml29623 	nldvs = 0;
32903859Sml29623 	ldgvp->nldvs = 0;
32913859Sml29623 	ldgp->ldvp = NULL;
32923859Sml29623 	*nrequired_p = 0;
32933859Sml29623 
32943859Sml29623 	/*
32953859Sml29623 	 * Start with RDC to configure logical devices for each group.
32963859Sml29623 	 */
32976495Sspeer 	set = &nxgep->rx_set;
32986495Sspeer 	for (channel = 0; channel < NXGE_MAX_RDCS; channel++) {
32996495Sspeer 		if ((1 << channel) & set->owned.map) {
33006495Sspeer 			/* For now, <channel & <vdma_index> are the same. */
33016495Sspeer 			ldvp->is_rxdma = B_TRUE;
33026495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_RDMA_LD_START;
33036495Sspeer 			ldvp->channel = channel;
33046495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
33056495Sspeer 			ldvp->ldv_intr_handler = nxge_rx_intr;
33066495Sspeer 			ldvp->ldv_ldf_masks = 0;
33076495Sspeer 			ldvp->use_timer = B_FALSE;
33086495Sspeer 			ldvp->nxgep = nxgep;
33096495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
33106495Sspeer 			    endldg, nrequired_p);
33116495Sspeer 			nldvs++;
33126495Sspeer 		}
33133859Sml29623 	}
33143859Sml29623 
33153859Sml29623 	/*
33163859Sml29623 	 * Transmit DMA channels.
33173859Sml29623 	 */
33186495Sspeer 	set = &nxgep->tx_set;
33196495Sspeer 	for (channel = 0; channel < NXGE_MAX_TDCS; channel++) {
33206495Sspeer 		if ((1 << channel) & set->owned.map) {
33216495Sspeer 			/* For now, <channel & <vdma_index> are the same. */
33226495Sspeer 			ldvp->is_txdma = B_TRUE;
33236495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_TDMA_LD_START;
33246495Sspeer 			ldvp->channel = channel;
33256495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
33266495Sspeer 			ldvp->ldv_intr_handler = nxge_tx_intr;
33276495Sspeer 			ldvp->ldv_ldf_masks = 0;
33286495Sspeer 			ldvp->use_timer = B_FALSE;
33296495Sspeer 			ldvp->nxgep = nxgep;
33306495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
33316495Sspeer 			    endldg, nrequired_p);
33326495Sspeer 			nldvs++;
33336495Sspeer 		}
33343859Sml29623 	}
33353859Sml29623 
33363859Sml29623 	if (own_fzc) {
33373859Sml29623 		ldv = NXGE_MIF_LD;
33383859Sml29623 		ldvp->ldv = (uint8_t)ldv;
33393859Sml29623 		ldvp->is_mif = B_TRUE;
33403859Sml29623 		ldvp->ldv_intr_handler = nxge_mif_intr;
33413859Sml29623 		ldvp->ldv_ldf_masks = 0;
33423859Sml29623 		ldvp->use_timer = B_FALSE;
33433859Sml29623 		ldvp->nxgep = nxgep;
33443859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
33453859Sml29623 		nldvs++;
33463859Sml29623 	}
33473859Sml29623 	/*
33483859Sml29623 	 * MAC port (function zero control)
33493859Sml29623 	 */
33503859Sml29623 	if (own_fzc) {
33513859Sml29623 		ldvp->is_mac = B_TRUE;
33523859Sml29623 		ldvp->ldv_intr_handler = nxge_mac_intr;
33533859Sml29623 		ldvp->ldv_ldf_masks = 0;
33543859Sml29623 		ldv = func + NXGE_MAC_LD_START;
33553859Sml29623 		ldvp->ldv = (uint8_t)ldv;
33563859Sml29623 		ldvp->use_timer = B_FALSE;
33573859Sml29623 		ldvp->nxgep = nxgep;
33583859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
33593859Sml29623 		nldvs++;
33603859Sml29623 	}
33613859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init: "
33626929Smisaki 	    "func %d nldvs %d navail %d nrequired %d",
33636929Smisaki 	    func, nldvs, *navail_p, *nrequired_p));
33643859Sml29623 	/*
33653859Sml29623 	 * Function 0 owns system error interrupts.
33663859Sml29623 	 */
33673859Sml29623 	ldvp->use_timer = B_TRUE;
33683859Sml29623 	if (own_sys_err) {
33693859Sml29623 		ldv = NXGE_SYS_ERROR_LD;
33703859Sml29623 		ldvp->ldv = (uint8_t)ldv;
33713859Sml29623 		ldvp->is_syserr = B_TRUE;
33723859Sml29623 		ldvp->ldv_intr_handler = nxge_syserr_intr;
33733859Sml29623 		ldvp->ldv_ldf_masks = 0;
33743859Sml29623 		ldvp->nxgep = nxgep;
33753859Sml29623 		ldgvp->ldvp_syserr = ldvp;
33763859Sml29623 		/*
33773859Sml29623 		 * Unmask the system interrupt states.
33783859Sml29623 		 */
33793859Sml29623 		(void) nxge_fzc_sys_err_mask_set(nxgep, SYS_ERR_SMX_MASK |
33806929Smisaki 		    SYS_ERR_IPP_MASK | SYS_ERR_TXC_MASK |
33816929Smisaki 		    SYS_ERR_ZCP_MASK);
33823859Sml29623 
33833859Sml29623 		(void) nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
33843859Sml29623 		nldvs++;
33853859Sml29623 	} else {
33863859Sml29623 		ldv = NXGE_SYS_ERROR_LD;
33873859Sml29623 		ldvp->ldv = (uint8_t)ldv;
33883859Sml29623 		ldvp->is_syserr = B_TRUE;
33893859Sml29623 		ldvp->ldv_intr_handler = nxge_syserr_intr;
33903859Sml29623 		ldvp->nxgep = nxgep;
33913859Sml29623 		ldvp->ldv_ldf_masks = 0;
33923859Sml29623 		ldgvp->ldvp_syserr = ldvp;
33933859Sml29623 	}
33943859Sml29623 
33953859Sml29623 	ldgvp->ldg_intrs = *nrequired_p;
33963859Sml29623 
33973859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init: "
33986929Smisaki 	    "func %d nldvs %d navail %d nrequired %d",
33996929Smisaki 	    func, nldvs, *navail_p, *nrequired_p));
34003859Sml29623 
34013859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_init"));
34023859Sml29623 	return (status);
34033859Sml29623 }
34043859Sml29623 
34053859Sml29623 nxge_status_t
34063859Sml29623 nxge_ldgv_uninit(p_nxge_t nxgep)
34073859Sml29623 {
34083859Sml29623 	p_nxge_ldgv_t ldgvp;
34093859Sml29623 
34103859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_uninit"));
34113859Sml29623 	ldgvp = nxgep->ldgvp;
34123859Sml29623 	if (ldgvp == NULL) {
34133859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_uninit: "
34146929Smisaki 		    "no logical group configured."));
34153859Sml29623 		return (NXGE_OK);
34163859Sml29623 	}
34178275SEric Cheng 	if (ldgvp->ldvp_syserr_alloced == B_TRUE) {
34187466SMisaki.Kataoka@Sun.COM 		KMEM_FREE(ldgvp->ldvp_syserr, sizeof (nxge_ldv_t));
34197466SMisaki.Kataoka@Sun.COM 	}
34203859Sml29623 	if (ldgvp->ldgp) {
34213859Sml29623 		KMEM_FREE(ldgvp->ldgp, sizeof (nxge_ldg_t) * ldgvp->maxldgs);
34223859Sml29623 	}
34233859Sml29623 	if (ldgvp->ldvp) {
34243859Sml29623 		KMEM_FREE(ldgvp->ldvp, sizeof (nxge_ldv_t) * ldgvp->maxldvs);
34253859Sml29623 	}
34263859Sml29623 	KMEM_FREE(ldgvp, sizeof (nxge_ldgv_t));
34273859Sml29623 	nxgep->ldgvp = NULL;
34283859Sml29623 
34293859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_uninit"));
34303859Sml29623 	return (NXGE_OK);
34313859Sml29623 }
34323859Sml29623 
34333859Sml29623 nxge_status_t
34343859Sml29623 nxge_intr_ldgv_init(p_nxge_t nxgep)
34353859Sml29623 {
34363859Sml29623 	nxge_status_t status = NXGE_OK;
34373859Sml29623 
34383859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_ldgv_init"));
34393859Sml29623 	/*
34403859Sml29623 	 * Configure the logical device group numbers, state vectors and
34413859Sml29623 	 * interrupt masks for each logical device.
34423859Sml29623 	 */
34433859Sml29623 	status = nxge_fzc_intr_init(nxgep);
34443859Sml29623 
34453859Sml29623 	/*
34463859Sml29623 	 * Configure logical device masks and timers.
34473859Sml29623 	 */
34483859Sml29623 	status = nxge_intr_mask_mgmt(nxgep);
34493859Sml29623 
34503859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_ldgv_init"));
34513859Sml29623 	return (status);
34523859Sml29623 }
34533859Sml29623 
34543859Sml29623 nxge_status_t
34553859Sml29623 nxge_intr_mask_mgmt(p_nxge_t nxgep)
34563859Sml29623 {
34573859Sml29623 	p_nxge_ldgv_t ldgvp;
34583859Sml29623 	p_nxge_ldg_t ldgp;
34593859Sml29623 	p_nxge_ldv_t ldvp;
34603859Sml29623 	npi_handle_t handle;
34613859Sml29623 	int i, j;
34623859Sml29623 	npi_status_t rs = NPI_SUCCESS;
34633859Sml29623 
34643859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_mask_mgmt"));
34653859Sml29623 
34663859Sml29623 	if ((ldgvp = nxgep->ldgvp) == NULL) {
34673859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
34686929Smisaki 		    "<== nxge_intr_mask_mgmt: Null ldgvp"));
34693859Sml29623 		return (NXGE_ERROR);
34703859Sml29623 	}
34713859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
34723859Sml29623 	ldgp = ldgvp->ldgp;
34733859Sml29623 	ldvp = ldgvp->ldvp;
34743859Sml29623 	if (ldgp == NULL || ldvp == NULL) {
34753859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
34766929Smisaki 		    "<== nxge_intr_mask_mgmt: Null ldgp or ldvp"));
34773859Sml29623 		return (NXGE_ERROR);
34783859Sml29623 	}
34793859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
34806929Smisaki 	    "==> nxge_intr_mask_mgmt: # of intrs %d ", ldgvp->ldg_intrs));
34813859Sml29623 	/* Initialize masks. */
34823859Sml29623 	if (nxgep->niu_type != N2_NIU) {
34833859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
34846929Smisaki 		    "==> nxge_intr_mask_mgmt(Neptune): # intrs %d ",
34856929Smisaki 		    ldgvp->ldg_intrs));
34863859Sml29623 		for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
34873859Sml29623 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
34886929Smisaki 			    "==> nxge_intr_mask_mgmt(Neptune): # ldv %d "
34896929Smisaki 			    "in group %d", ldgp->nldvs, ldgp->ldg));
34903859Sml29623 			for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
34913859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
34926929Smisaki 				    "==> nxge_intr_mask_mgmt: set ldv # %d "
34936929Smisaki 				    "for ldg %d", ldvp->ldv, ldgp->ldg));
34943859Sml29623 				rs = npi_intr_mask_set(handle, ldvp->ldv,
34956929Smisaki 				    ldvp->ldv_ldf_masks);
34963859Sml29623 				if (rs != NPI_SUCCESS) {
34973859Sml29623 					NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
34986929Smisaki 					    "<== nxge_intr_mask_mgmt: "
34996929Smisaki 					    "set mask failed "
35006929Smisaki 					    " rs 0x%x ldv %d mask 0x%x",
35016929Smisaki 					    rs, ldvp->ldv,
35026929Smisaki 					    ldvp->ldv_ldf_masks));
35033859Sml29623 					return (NXGE_ERROR | rs);
35043859Sml29623 				}
35053859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
35066929Smisaki 				    "==> nxge_intr_mask_mgmt: "
35076929Smisaki 				    "set mask OK "
35086929Smisaki 				    " rs 0x%x ldv %d mask 0x%x",
35096929Smisaki 				    rs, ldvp->ldv,
35106929Smisaki 				    ldvp->ldv_ldf_masks));
35113859Sml29623 			}
35123859Sml29623 		}
35133859Sml29623 	}
35143859Sml29623 	ldgp = ldgvp->ldgp;
35153859Sml29623 	/* Configure timer and arm bit */
35163859Sml29623 	for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
35173859Sml29623 		rs = npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
35186929Smisaki 		    ldgp->arm, ldgp->ldg_timer);
35193859Sml29623 		if (rs != NPI_SUCCESS) {
35203859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
35216929Smisaki 			    "<== nxge_intr_mask_mgmt: "
35226929Smisaki 			    "set timer failed "
35236929Smisaki 			    " rs 0x%x dg %d timer 0x%x",
35246929Smisaki 			    rs, ldgp->ldg, ldgp->ldg_timer));
35253859Sml29623 			return (NXGE_ERROR | rs);
35263859Sml29623 		}
35273859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
35286929Smisaki 		    "==> nxge_intr_mask_mgmt: "
35296929Smisaki 		    "set timer OK "
35306929Smisaki 		    " rs 0x%x ldg %d timer 0x%x",
35316929Smisaki 		    rs, ldgp->ldg, ldgp->ldg_timer));
35323859Sml29623 	}
35333859Sml29623 
35343859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_fzc_intr_mask_mgmt"));
35353859Sml29623 	return (NXGE_OK);
35363859Sml29623 }
35373859Sml29623 
35383859Sml29623 nxge_status_t
35393859Sml29623 nxge_intr_mask_mgmt_set(p_nxge_t nxgep, boolean_t on)
35403859Sml29623 {
35413859Sml29623 	p_nxge_ldgv_t ldgvp;
35423859Sml29623 	p_nxge_ldg_t ldgp;
35433859Sml29623 	p_nxge_ldv_t ldvp;
35443859Sml29623 	npi_handle_t handle;
35453859Sml29623 	int i, j;
35463859Sml29623 	npi_status_t rs = NPI_SUCCESS;
35473859Sml29623 
35483859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
35496929Smisaki 	    "==> nxge_intr_mask_mgmt_set (%d)", on));
35503859Sml29623 
35513859Sml29623 	if (nxgep->niu_type == N2_NIU) {
35523859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
35536929Smisaki 		    "<== nxge_intr_mask_mgmt_set (%d) not set (N2/NIU)",
35546929Smisaki 		    on));
35553859Sml29623 		return (NXGE_ERROR);
35563859Sml29623 	}
35573859Sml29623 
35583859Sml29623 	if ((ldgvp = nxgep->ldgvp) == NULL) {
35593859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
35606929Smisaki 		    "==> nxge_intr_mask_mgmt_set: Null ldgvp"));
35613859Sml29623 		return (NXGE_ERROR);
35623859Sml29623 	}
35633859Sml29623 
35643859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
35653859Sml29623 	ldgp = ldgvp->ldgp;
35663859Sml29623 	ldvp = ldgvp->ldvp;
35673859Sml29623 	if (ldgp == NULL || ldvp == NULL) {
35683859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
35696929Smisaki 		    "<== nxge_intr_mask_mgmt_set: Null ldgp or ldvp"));
35703859Sml29623 		return (NXGE_ERROR);
35713859Sml29623 	}
35723859Sml29623 	/* set masks. */
35733859Sml29623 	for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
35743859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
35756929Smisaki 		    "==> nxge_intr_mask_mgmt_set: flag %d ldg %d"
35766929Smisaki 		    "set mask nldvs %d", on, ldgp->ldg, ldgp->nldvs));
35773859Sml29623 		for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
35783859Sml29623 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
35796929Smisaki 			    "==> nxge_intr_mask_mgmt_set: "
35806929Smisaki 			    "for %d %d flag %d", i, j, on));
35813859Sml29623 			if (on) {
35823859Sml29623 				ldvp->ldv_ldf_masks = 0;
35833859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
35846929Smisaki 				    "==> nxge_intr_mask_mgmt_set: "
35856929Smisaki 				    "ON mask off"));
35863859Sml29623 			} else if (!on) {
35873859Sml29623 				ldvp->ldv_ldf_masks = (uint8_t)LD_IM1_MASK;
35883859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
35896929Smisaki 				    "==> nxge_intr_mask_mgmt_set:mask on"));
35903859Sml29623 			}
35913859Sml29623 			rs = npi_intr_mask_set(handle, ldvp->ldv,
35926929Smisaki 			    ldvp->ldv_ldf_masks);
35933859Sml29623 			if (rs != NPI_SUCCESS) {
35943859Sml29623 				NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
35956929Smisaki 				    "==> nxge_intr_mask_mgmt_set: "
35966929Smisaki 				    "set mask failed "
35976929Smisaki 				    " rs 0x%x ldv %d mask 0x%x",
35986929Smisaki 				    rs, ldvp->ldv, ldvp->ldv_ldf_masks));
35993859Sml29623 				return (NXGE_ERROR | rs);
36003859Sml29623 			}
36013859Sml29623 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
36026929Smisaki 			    "==> nxge_intr_mask_mgmt_set: flag %d"
36036929Smisaki 			    "set mask OK "
36046929Smisaki 			    " ldv %d mask 0x%x",
36056929Smisaki 			    on, ldvp->ldv, ldvp->ldv_ldf_masks));
36063859Sml29623 		}
36073859Sml29623 	}
36083859Sml29623 
36093859Sml29623 	ldgp = ldgvp->ldgp;
36103859Sml29623 	/* set the arm bit */
36113859Sml29623 	for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
36123859Sml29623 		if (on && !ldgp->arm) {
36133859Sml29623 			ldgp->arm = B_TRUE;
36143859Sml29623 		} else if (!on && ldgp->arm) {
36153859Sml29623 			ldgp->arm = B_FALSE;
36163859Sml29623 		}
36173859Sml29623 		rs = npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
36186929Smisaki 		    ldgp->arm, ldgp->ldg_timer);
36193859Sml29623 		if (rs != NPI_SUCCESS) {
36203859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
36216929Smisaki 			    "<== nxge_intr_mask_mgmt_set: "
36226929Smisaki 			    "set timer failed "
36236929Smisaki 			    " rs 0x%x ldg %d timer 0x%x",
36246929Smisaki 			    rs, ldgp->ldg, ldgp->ldg_timer));
36253859Sml29623 			return (NXGE_ERROR | rs);
36263859Sml29623 		}
36273859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
36286929Smisaki 		    "==> nxge_intr_mask_mgmt_set: OK (flag %d) "
36296929Smisaki 		    "set timer "
36306929Smisaki 		    " ldg %d timer 0x%x",
36316929Smisaki 		    on, ldgp->ldg, ldgp->ldg_timer));
36323859Sml29623 	}
36333859Sml29623 
36343859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_mask_mgmt_set"));
36353859Sml29623 	return (NXGE_OK);
36363859Sml29623 }
36373859Sml29623 
36383859Sml29623 static nxge_status_t
36393859Sml29623 nxge_get_mac_addr_properties(p_nxge_t nxgep)
36403859Sml29623 {
36414732Sdavemq #if defined(_BIG_ENDIAN)
36423859Sml29623 	uchar_t *prop_val;
36433859Sml29623 	uint_t prop_len;
36444732Sdavemq 	uint_t j;
36454732Sdavemq #endif
36463859Sml29623 	uint_t i;
36473859Sml29623 	uint8_t func_num;
36484732Sdavemq 	boolean_t compute_macs = B_TRUE;
36493859Sml29623 
36503859Sml29623 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_get_mac_addr_properties "));
36513859Sml29623 
36523859Sml29623 #if defined(_BIG_ENDIAN)
36533859Sml29623 	/*
36543859Sml29623 	 * Get the ethernet address.
36553859Sml29623 	 */
36563859Sml29623 	(void) localetheraddr((struct ether_addr *)NULL, &nxgep->ouraddr);
36573859Sml29623 
36583859Sml29623 	/*
36593859Sml29623 	 * Check if it is an adapter with its own local mac address If it is
36603859Sml29623 	 * present, override the system mac address.
36613859Sml29623 	 */
36623859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
36636929Smisaki 	    "local-mac-address", &prop_val,
36646929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
36653859Sml29623 		if (prop_len == ETHERADDRL) {
36663859Sml29623 			nxgep->factaddr = *(p_ether_addr_t)prop_val;
36673859Sml29623 			NXGE_DEBUG_MSG((nxgep, DDI_CTL, "Local mac address = "
36686929Smisaki 			    "%02x:%02x:%02x:%02x:%02x:%02x",
36696929Smisaki 			    prop_val[0], prop_val[1], prop_val[2],
36706929Smisaki 			    prop_val[3], prop_val[4], prop_val[5]));
36713859Sml29623 		}
36723859Sml29623 		ddi_prop_free(prop_val);
36733859Sml29623 	}
36743859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
36756929Smisaki 	    "local-mac-address?", &prop_val,
36766929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
36773859Sml29623 		if (strncmp("true", (caddr_t)prop_val, (size_t)prop_len) == 0) {
36783859Sml29623 			nxgep->ouraddr = nxgep->factaddr;
36793859Sml29623 			NXGE_DEBUG_MSG((nxgep, DDI_CTL,
36806929Smisaki 			    "Using local MAC address"));
36813859Sml29623 		}
36823859Sml29623 		ddi_prop_free(prop_val);
36833859Sml29623 	} else {
36843859Sml29623 		nxgep->ouraddr = nxgep->factaddr;
36853859Sml29623 	}
36864185Sspeer 
36874977Sraghus 	if ((!nxgep->vpd_info.present) ||
36884732Sdavemq 	    (nxge_is_valid_local_mac(nxgep->factaddr)))
36894185Sspeer 		goto got_mac_addr;
36904185Sspeer 
36914185Sspeer 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "nxge_get_mac_addr_properties: "
36924185Sspeer 	    "MAC address from properties is not valid...reading from PROM"));
36934185Sspeer 
36944185Sspeer #endif
36954185Sspeer 	if (!nxgep->vpd_info.ver_valid) {
36964185Sspeer 		(void) nxge_espc_mac_addrs_get(nxgep);
36974185Sspeer 		if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
36984977Sraghus 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Failed to get "
36994977Sraghus 			    "MAC address"));
37004185Sspeer 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "EEPROM version "
37014185Sspeer 			    "[%s] invalid...please update",
37024185Sspeer 			    nxgep->vpd_info.ver));
37034185Sspeer 			return (NXGE_ERROR);
37044185Sspeer 		}
37054185Sspeer 		nxgep->ouraddr = nxgep->factaddr;
37064185Sspeer 		goto got_mac_addr;
37074185Sspeer 	}
37084185Sspeer 	/*
37094185Sspeer 	 * First get the MAC address from the info in the VPD data read
37104185Sspeer 	 * from the EEPROM.
37114185Sspeer 	 */
37124185Sspeer 	nxge_espc_get_next_mac_addr(nxgep->vpd_info.mac_addr,
37134732Sdavemq 	    nxgep->function_num, &nxgep->factaddr);
37144185Sspeer 
37154185Sspeer 	if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
37164185Sspeer 		NXGE_DEBUG_MSG((nxgep, DDI_CTL,
37174185Sspeer 		    "nxge_get_mac_addr_properties: "
37184185Sspeer 		    "MAC address in EEPROM VPD data not valid"
37194185Sspeer 		    "...reading from NCR registers"));
37204185Sspeer 		(void) nxge_espc_mac_addrs_get(nxgep);
37214185Sspeer 		if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
37224977Sraghus 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Failed to get "
37234977Sraghus 			    "MAC address"));
37244185Sspeer 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "EEPROM version "
37254185Sspeer 			    "[%s] invalid...please update",
37264185Sspeer 			    nxgep->vpd_info.ver));
37274185Sspeer 			return (NXGE_ERROR);
37284185Sspeer 		}
37294185Sspeer 	}
37304185Sspeer 
37313859Sml29623 	nxgep->ouraddr = nxgep->factaddr;
37324185Sspeer 
37334185Sspeer got_mac_addr:
37343859Sml29623 	func_num = nxgep->function_num;
37353859Sml29623 
37363859Sml29623 	/*
37374732Sdavemq 	 * Note: mac-addresses property is the list of mac addresses for a
37384732Sdavemq 	 * port. NXGE_MAX_MMAC_ADDRS is the total number of MAC addresses
37394732Sdavemq 	 * allocated for a board.
37403859Sml29623 	 */
37414732Sdavemq 	nxgep->nxge_mmac_info.total_factory_macs = NXGE_MAX_MMAC_ADDRS;
37424732Sdavemq 
37434732Sdavemq #if defined(_BIG_ENDIAN)
37444732Sdavemq 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
37454732Sdavemq 	    "mac-addresses", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
37463859Sml29623 		/*
37474732Sdavemq 		 * XAUI may have up to 18 MACs, more than the XMAC can
37484732Sdavemq 		 * use (1 unique MAC plus 16 alternate MACs)
37493859Sml29623 		 */
37504732Sdavemq 		nxgep->nxge_mmac_info.num_factory_mmac =
37514732Sdavemq 		    prop_len / ETHERADDRL - 1;
37524732Sdavemq 		if (nxgep->nxge_mmac_info.num_factory_mmac >
37534732Sdavemq 		    XMAC_MAX_ALT_ADDR_ENTRY) {
37544185Sspeer 			nxgep->nxge_mmac_info.num_factory_mmac =
37554732Sdavemq 			    XMAC_MAX_ALT_ADDR_ENTRY;
37564732Sdavemq 		}
37574732Sdavemq 
37584732Sdavemq 		for (i = 1; i <= nxgep->nxge_mmac_info.num_factory_mmac; i++) {
37594732Sdavemq 			for (j = 0; j < ETHERADDRL; j++) {
37604732Sdavemq 				nxgep->nxge_mmac_info.factory_mac_pool[i][j] =
37614732Sdavemq 				    *(prop_val + (i * ETHERADDRL) + j);
37624732Sdavemq 			}
37634732Sdavemq 			NXGE_DEBUG_MSG((nxgep, DDI_CTL,
37644732Sdavemq 			    "nxge_get_mac_addr_properties: Alt mac[%d] from "
37654732Sdavemq 			    "mac-addresses property[%2x:%2x:%2x:%2x:%2x:%2x]",
37664732Sdavemq 			    i, nxgep->nxge_mmac_info.factory_mac_pool[i][0],
37674732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][1],
37684732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][2],
37694732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][3],
37704732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][4],
37714732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][5]));
37724185Sspeer 		}
37734732Sdavemq 
37744732Sdavemq 		compute_macs = B_FALSE;
37754732Sdavemq 		ddi_prop_free(prop_val);
37764732Sdavemq 		goto got_mmac_info;
37773859Sml29623 	}
37784732Sdavemq #endif
37794732Sdavemq 	/*
37804732Sdavemq 	 * total_factory_macs = 32
37814732Sdavemq 	 * num_factory_mmac = (32 >> (nports/2)) - 1
37824732Sdavemq 	 * So if nports = 4, then num_factory_mmac =  7
37834732Sdavemq 	 *    if nports = 2, then num_factory_mmac = 15
37844732Sdavemq 	 */
37854732Sdavemq 	nxgep->nxge_mmac_info.num_factory_mmac =
37864732Sdavemq 	    ((nxgep->nxge_mmac_info.total_factory_macs >>
37874732Sdavemq 	    (nxgep->nports >> 1))) - 1;
37884732Sdavemq 
37894732Sdavemq got_mmac_info:
37904732Sdavemq 
37914732Sdavemq 	if ((nxgep->function_num < 2) &&
37924732Sdavemq 	    (nxgep->nxge_mmac_info.num_factory_mmac >
37934732Sdavemq 	    XMAC_MAX_ALT_ADDR_ENTRY)) {
37944732Sdavemq 		nxgep->nxge_mmac_info.num_factory_mmac =
37954732Sdavemq 		    XMAC_MAX_ALT_ADDR_ENTRY;
37964732Sdavemq 	} else if ((nxgep->function_num > 1) &&
37974732Sdavemq 	    (nxgep->nxge_mmac_info.num_factory_mmac >
37984732Sdavemq 	    BMAC_MAX_ALT_ADDR_ENTRY)) {
37994732Sdavemq 		nxgep->nxge_mmac_info.num_factory_mmac =
38004732Sdavemq 		    BMAC_MAX_ALT_ADDR_ENTRY;
38014185Sspeer 	}
38024185Sspeer 
38033859Sml29623 	for (i = 0; i <= nxgep->nxge_mmac_info.num_mmac; i++) {
38043859Sml29623 		(void) npi_mac_altaddr_disable(nxgep->npi_handle,
38056929Smisaki 		    NXGE_GET_PORT_NUM(func_num), i);
38063859Sml29623 	}
38073859Sml29623 
38084732Sdavemq 	(void) nxge_init_mmac(nxgep, compute_macs);
38093859Sml29623 	return (NXGE_OK);
38103859Sml29623 }
38113859Sml29623 
38123859Sml29623 void
38133859Sml29623 nxge_get_xcvr_properties(p_nxge_t nxgep)
38143859Sml29623 {
38153859Sml29623 	uchar_t *prop_val;
38163859Sml29623 	uint_t prop_len;
38173859Sml29623 
38183859Sml29623 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_get_xcvr_properties"));
38193859Sml29623 
38203859Sml29623 	/*
38213859Sml29623 	 * Read the type of physical layer interface being used.
38223859Sml29623 	 */
38233859Sml29623 	nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
38243859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
38256929Smisaki 	    "phy-type", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
38263859Sml29623 		if (strncmp("pcs", (caddr_t)prop_val,
38276929Smisaki 		    (size_t)prop_len) == 0) {
38283859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = PCS_XCVR;
38293859Sml29623 		} else {
38303859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
38313859Sml29623 		}
38323859Sml29623 		ddi_prop_free(prop_val);
38333859Sml29623 	} else if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
38346929Smisaki 	    "phy-interface", &prop_val,
38356929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
38363859Sml29623 		if (strncmp("pcs", (caddr_t)prop_val, (size_t)prop_len) == 0) {
38373859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = PCS_XCVR;
38383859Sml29623 		} else {
38393859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
38403859Sml29623 		}
38413859Sml29623 		ddi_prop_free(prop_val);
38423859Sml29623 	}
38433859Sml29623 }
38443859Sml29623 
38453859Sml29623 /*
38463859Sml29623  * Static functions start here.
38473859Sml29623  */
38483859Sml29623 
38493859Sml29623 static void
38503859Sml29623 nxge_ldgv_setup(p_nxge_ldg_t *ldgp, p_nxge_ldv_t *ldvp, uint8_t ldv,
38513859Sml29623 	uint8_t endldg, int *ngrps)
38523859Sml29623 {
38533859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup"));
38543859Sml29623 	/* Assign the group number for each device. */
38553859Sml29623 	(*ldvp)->ldg_assigned = (*ldgp)->ldg;
38563859Sml29623 	(*ldvp)->ldgp = *ldgp;
38573859Sml29623 	(*ldvp)->ldv = ldv;
38583859Sml29623 
38593859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup: "
38606929Smisaki 	    "ldv %d endldg %d ldg %d, ldvp $%p",
38616929Smisaki 	    ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
38623859Sml29623 
38633859Sml29623 	(*ldgp)->nldvs++;
38643859Sml29623 	if ((*ldgp)->ldg == (endldg - 1)) {
38653859Sml29623 		if ((*ldgp)->ldvp == NULL) {
38663859Sml29623 			(*ldgp)->ldvp = *ldvp;
38673859Sml29623 			*ngrps += 1;
38683859Sml29623 			NXGE_DEBUG_MSG((NULL, INT_CTL,
38696929Smisaki 			    "==> nxge_ldgv_setup: ngrps %d", *ngrps));
38703859Sml29623 		}
38713859Sml29623 		NXGE_DEBUG_MSG((NULL, INT_CTL,
38726929Smisaki 		    "==> nxge_ldgv_setup: ldvp $%p ngrps %d",
38736929Smisaki 		    *ldvp, *ngrps));
38743859Sml29623 		++*ldvp;
38753859Sml29623 	} else {
38763859Sml29623 		(*ldgp)->ldvp = *ldvp;
38773859Sml29623 		*ngrps += 1;
38783859Sml29623 		NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup(done): "
38796929Smisaki 		    "ldv %d endldg %d ldg %d, ldvp $%p",
38806929Smisaki 		    ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
38813859Sml29623 		(*ldvp) = ++*ldvp;
38823859Sml29623 		(*ldgp) = ++*ldgp;
38833859Sml29623 		NXGE_DEBUG_MSG((NULL, INT_CTL,
38846929Smisaki 		    "==> nxge_ldgv_setup: new ngrps %d", *ngrps));
38853859Sml29623 	}
38863859Sml29623 
38873859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup: "
38886929Smisaki 	    "ldv %d ldvp $%p endldg %d ngrps %d",
38896929Smisaki 	    ldv, ldvp, endldg, *ngrps));
38903859Sml29623 
38913859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "<== nxge_ldgv_setup"));
38923859Sml29623 }
38933859Sml29623 
38943859Sml29623 /*
38953859Sml29623  * Note: This function assumes the following distribution of mac
38963859Sml29623  * addresses among 4 ports in neptune:
38973859Sml29623  *
38983859Sml29623  *      -------------
38993859Sml29623  *    0|            |0 - local-mac-address for fn 0
39003859Sml29623  *      -------------
39013859Sml29623  *    1|            |1 - local-mac-address for fn 1
39023859Sml29623  *      -------------
39033859Sml29623  *    2|            |2 - local-mac-address for fn 2
39043859Sml29623  *      -------------
39053859Sml29623  *    3|            |3 - local-mac-address for fn 3
39063859Sml29623  *      -------------
39073859Sml29623  *     |            |4 - Start of alt. mac addr. for fn 0
39083859Sml29623  *     |            |
39093859Sml29623  *     |            |
39103859Sml29623  *     |            |10
39113859Sml29623  *     --------------
39123859Sml29623  *     |            |11 - Start of alt. mac addr. for fn 1
39133859Sml29623  *     |            |
39143859Sml29623  *     |            |
39153859Sml29623  *     |            |17
39163859Sml29623  *     --------------
39173859Sml29623  *     |            |18 - Start of alt. mac addr. for fn 2
39183859Sml29623  *     |            |
39193859Sml29623  *     |            |
39203859Sml29623  *     |            |24
39213859Sml29623  *     --------------
39223859Sml29623  *     |            |25 - Start of alt. mac addr. for fn 3
39233859Sml29623  *     |            |
39243859Sml29623  *     |            |
39253859Sml29623  *     |            |31
39263859Sml29623  *     --------------
39273859Sml29623  *
39283859Sml29623  * For N2/NIU the mac addresses is from XAUI card.
39294732Sdavemq  *
39304732Sdavemq  * When 'compute_addrs' is true, the alternate mac addresses are computed
39314732Sdavemq  * using the unique mac address as base. Otherwise the alternate addresses
39324732Sdavemq  * are assigned from the list read off the 'mac-addresses' property.
39333859Sml29623  */
39343859Sml29623 
39353859Sml29623 static void
39364732Sdavemq nxge_init_mmac(p_nxge_t nxgep, boolean_t compute_addrs)
39373859Sml29623 {
39383859Sml29623 	int slot;
39393859Sml29623 	uint8_t func_num;
39403859Sml29623 	uint16_t *base_mmac_addr;
39413859Sml29623 	uint32_t alt_mac_ls4b;
39423859Sml29623 	uint16_t *mmac_addr;
39433859Sml29623 	uint32_t base_mac_ls4b; /* least significant 4 bytes */
39443859Sml29623 	nxge_mmac_t *mmac_info;
39453859Sml29623 	npi_mac_addr_t mac_addr;
39463859Sml29623 
39473859Sml29623 	func_num = nxgep->function_num;
39483859Sml29623 	base_mmac_addr = (uint16_t *)&nxgep->factaddr;
39493859Sml29623 	mmac_info = (nxge_mmac_t *)&nxgep->nxge_mmac_info;
39503859Sml29623 
39514732Sdavemq 	if (compute_addrs) {
39524732Sdavemq 		base_mac_ls4b = ((uint32_t)base_mmac_addr[1]) << 16 |
39534732Sdavemq 		    base_mmac_addr[2];
39544732Sdavemq 
39554732Sdavemq 		if (nxgep->niu_type == N2_NIU) {
39564732Sdavemq 			/* ls4b of 1st altmac */
39574732Sdavemq 			alt_mac_ls4b = base_mac_ls4b + 1;
39584732Sdavemq 		} else {			/* Neptune */
39594732Sdavemq 			alt_mac_ls4b = base_mac_ls4b +
39604732Sdavemq 			    (nxgep->nports - func_num) +
39614732Sdavemq 			    (func_num * (mmac_info->num_factory_mmac));
39624732Sdavemq 		}
39633859Sml29623 	}
39643859Sml29623 
39653859Sml29623 	/* Set flags for unique MAC */
39663859Sml29623 	mmac_info->mac_pool[0].flags |= MMAC_SLOT_USED | MMAC_VENDOR_ADDR;
39673859Sml29623 
39683859Sml29623 	/* Clear flags of all alternate MAC slots */
39693859Sml29623 	for (slot = 1; slot <= mmac_info->num_mmac; slot++) {
39703859Sml29623 		if (slot <= mmac_info->num_factory_mmac)
39713859Sml29623 			mmac_info->mac_pool[slot].flags = MMAC_VENDOR_ADDR;
39723859Sml29623 		else
39733859Sml29623 			mmac_info->mac_pool[slot].flags = 0;
39743859Sml29623 	}
39753859Sml29623 
39763859Sml29623 	/* Generate and store factory alternate MACs */
39773859Sml29623 	for (slot = 1; slot <= mmac_info->num_factory_mmac; slot++) {
39783859Sml29623 		mmac_addr = (uint16_t *)&mmac_info->factory_mac_pool[slot];
39794732Sdavemq 		if (compute_addrs) {
39804732Sdavemq 			mmac_addr[0] = base_mmac_addr[0];
39814732Sdavemq 			mac_addr.w2 = mmac_addr[0];
39824732Sdavemq 
39834732Sdavemq 			mmac_addr[1] = (alt_mac_ls4b >> 16) & 0x0FFFF;
39844732Sdavemq 			mac_addr.w1 = mmac_addr[1];
39854732Sdavemq 
39864732Sdavemq 			mmac_addr[2] = alt_mac_ls4b & 0x0FFFF;
39874732Sdavemq 			mac_addr.w0 = mmac_addr[2];
39884732Sdavemq 
39894732Sdavemq 			alt_mac_ls4b++;
39904732Sdavemq 		} else {
39914732Sdavemq 			mac_addr.w2 = mmac_addr[0];
39924732Sdavemq 			mac_addr.w1 = mmac_addr[1];
39934732Sdavemq 			mac_addr.w0 = mmac_addr[2];
39944732Sdavemq 		}
39954732Sdavemq 
39964732Sdavemq 		NXGE_DEBUG_MSG((nxgep, DDI_CTL,
39974732Sdavemq 		    "mac_pool_addr[%2x:%2x:%2x:%2x:%2x:%2x] npi_addr[%x%x%x]",
39984732Sdavemq 		    mmac_info->factory_mac_pool[slot][0],
39994732Sdavemq 		    mmac_info->factory_mac_pool[slot][1],
40004732Sdavemq 		    mmac_info->factory_mac_pool[slot][2],
40014732Sdavemq 		    mmac_info->factory_mac_pool[slot][3],
40024732Sdavemq 		    mmac_info->factory_mac_pool[slot][4],
40034732Sdavemq 		    mmac_info->factory_mac_pool[slot][5],
40044732Sdavemq 		    mac_addr.w0, mac_addr.w1, mac_addr.w2));
40053859Sml29623 		/*
40064732Sdavemq 		 * slot minus 1 because npi_mac_altaddr_entry expects 0
40073859Sml29623 		 * for the first alternate mac address.
40083859Sml29623 		 */
40093859Sml29623 		(void) npi_mac_altaddr_entry(nxgep->npi_handle, OP_SET,
40106929Smisaki 		    NXGE_GET_PORT_NUM(func_num), slot - 1, &mac_addr);
40113859Sml29623 	}
40123859Sml29623 	/* Initialize the first two parameters for mmac kstat */
40133859Sml29623 	nxgep->statsp->mmac_stats.mmac_max_cnt = mmac_info->num_mmac;
40143859Sml29623 	nxgep->statsp->mmac_stats.mmac_avail_cnt = mmac_info->num_mmac;
40153859Sml29623 }
40168275SEric Cheng 
40178275SEric Cheng /*
40188275SEric Cheng  * Convert an RDC group index into a port ring index.  That is, map
40198275SEric Cheng  * <groupid> to an index into nxgep->rx_ring_handles.
40208275SEric Cheng  * (group ring index -> port ring index)
40218275SEric Cheng  */
40228275SEric Cheng int
40238275SEric Cheng nxge_get_rxring_index(p_nxge_t nxgep, int groupid, int ringidx)
40248275SEric Cheng {
40258275SEric Cheng 	int			i;
40268275SEric Cheng 	int			index = 0;
40278275SEric Cheng 	p_nxge_rdc_grp_t	rdc_grp_p;
40288275SEric Cheng 	p_nxge_dma_pt_cfg_t	p_dma_cfgp;
40298275SEric Cheng 	p_nxge_hw_pt_cfg_t	p_cfgp;
40308275SEric Cheng 
40318275SEric Cheng 	p_dma_cfgp = &nxgep->pt_config;
40328275SEric Cheng 	p_cfgp = &p_dma_cfgp->hw_config;
40338275SEric Cheng 
403410309SSriharsha.Basavapatna@Sun.COM 	if (isLDOMguest(nxgep))
403510309SSriharsha.Basavapatna@Sun.COM 		return (ringidx);
403610309SSriharsha.Basavapatna@Sun.COM 
40378275SEric Cheng 	for (i = 0; i < groupid; i++) {
40388275SEric Cheng 		rdc_grp_p =
40398275SEric Cheng 		    &p_dma_cfgp->rdc_grps[p_cfgp->def_mac_rxdma_grpid + i];
40408275SEric Cheng 		index += rdc_grp_p->max_rdcs;
40418275SEric Cheng 	}
40428275SEric Cheng 
40438275SEric Cheng 	return (index + ringidx);
40448275SEric Cheng }
4045