xref: /onnv-gate/usr/src/uts/common/io/nxge/nxge_virtual.c (revision 6835:07c6485129d0)
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 /*
226003Sml29623  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
233859Sml29623  * Use is subject to license terms.
243859Sml29623  */
253859Sml29623 
263859Sml29623 #pragma ident	"%Z%%M%	%I%	%E% SMI"
273859Sml29623 
283859Sml29623 #include <sys/nxge/nxge_impl.h>
293859Sml29623 #include <sys/nxge/nxge_mac.h>
306495Sspeer #include <sys/nxge/nxge_hio.h>
313859Sml29623 
323859Sml29623 static void nxge_get_niu_property(dev_info_t *, niu_type_t *);
333859Sml29623 static nxge_status_t nxge_get_mac_addr_properties(p_nxge_t);
343859Sml29623 static nxge_status_t nxge_use_cfg_n2niu_properties(p_nxge_t);
353859Sml29623 static void nxge_use_cfg_neptune_properties(p_nxge_t);
363859Sml29623 static void nxge_use_cfg_dma_config(p_nxge_t);
373859Sml29623 static void nxge_use_cfg_vlan_class_config(p_nxge_t);
383859Sml29623 static void nxge_use_cfg_mac_class_config(p_nxge_t);
393859Sml29623 static void nxge_use_cfg_class_config(p_nxge_t);
403859Sml29623 static void nxge_use_cfg_link_cfg(p_nxge_t);
413859Sml29623 static void nxge_set_hw_dma_config(p_nxge_t);
423859Sml29623 static void nxge_set_hw_vlan_class_config(p_nxge_t);
433859Sml29623 static void nxge_set_hw_mac_class_config(p_nxge_t);
443859Sml29623 static void nxge_set_hw_class_config(p_nxge_t);
453859Sml29623 static nxge_status_t nxge_use_default_dma_config_n2(p_nxge_t);
463859Sml29623 static void nxge_ldgv_setup(p_nxge_ldg_t *, p_nxge_ldv_t *, uint8_t,
473859Sml29623 	uint8_t, int *);
484732Sdavemq static void nxge_init_mmac(p_nxge_t, boolean_t);
496495Sspeer static void nxge_set_rdc_intr_property(p_nxge_t);
503859Sml29623 
513859Sml29623 uint32_t nxge_use_hw_property = 1;
523859Sml29623 uint32_t nxge_groups_per_port = 2;
533859Sml29623 
543859Sml29623 extern uint32_t nxge_use_partition;
553859Sml29623 extern uint32_t nxge_dma_obp_props_only;
563859Sml29623 
573859Sml29623 extern uint16_t nxge_rcr_timeout;
583859Sml29623 extern uint16_t nxge_rcr_threshold;
593859Sml29623 
603859Sml29623 extern uint_t nxge_rx_intr(void *, void *);
613859Sml29623 extern uint_t nxge_tx_intr(void *, void *);
623859Sml29623 extern uint_t nxge_mif_intr(void *, void *);
633859Sml29623 extern uint_t nxge_mac_intr(void *, void *);
643859Sml29623 extern uint_t nxge_syserr_intr(void *, void *);
653859Sml29623 extern void *nxge_list;
663859Sml29623 
673859Sml29623 #define	NXGE_SHARED_REG_SW_SIM
683859Sml29623 
693859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
703859Sml29623 uint64_t global_dev_ctrl = 0;
713859Sml29623 #endif
723859Sml29623 
733859Sml29623 #define	MAX_SIBLINGS	NXGE_MAX_PORTS
743859Sml29623 
753859Sml29623 extern uint32_t nxge_rbr_size;
763859Sml29623 extern uint32_t nxge_rcr_size;
773859Sml29623 extern uint32_t nxge_tx_ring_size;
783859Sml29623 extern uint32_t nxge_rbr_spare_size;
793859Sml29623 
803859Sml29623 extern npi_status_t npi_mac_altaddr_disable(npi_handle_t, uint8_t, uint8_t);
813859Sml29623 
823859Sml29623 static uint8_t p2_tx_fair[2] = {12, 12};
833859Sml29623 static uint8_t p2_tx_equal[2] = {12, 12};
843859Sml29623 static uint8_t p4_tx_fair[4] = {6, 6, 6, 6};
853859Sml29623 static uint8_t p4_tx_equal[4] = {6, 6, 6, 6};
863859Sml29623 static uint8_t p2_rx_fair[2] = {8, 8};
873859Sml29623 static uint8_t p2_rx_equal[2] = {8, 8};
883859Sml29623 static uint8_t p4_rx_fair[4] = {4, 4, 4, 4};
893859Sml29623 static uint8_t p4_rx_equal[4] = {4, 4, 4, 4};
903859Sml29623 
913859Sml29623 static uint8_t p2_rdcgrp_fair[2] = {4, 4};
923859Sml29623 static uint8_t p2_rdcgrp_equal[2] = {4, 4};
933859Sml29623 static uint8_t p4_rdcgrp_fair[4] = {2, 2, 1, 1};
943859Sml29623 static uint8_t p4_rdcgrp_equal[4] = {2, 2, 2, 2};
953859Sml29623 static uint8_t p2_rdcgrp_cls[2] = {1, 1};
963859Sml29623 static uint8_t p4_rdcgrp_cls[4] = {1, 1, 1, 1};
973859Sml29623 
984732Sdavemq static uint8_t rx_4_1G[4] = {4, 4, 4, 4};
994732Sdavemq static uint8_t rx_2_10G[2] = {8, 8};
1004732Sdavemq static uint8_t rx_2_10G_2_1G[4] = {6, 6, 2, 2};
1014732Sdavemq static uint8_t rx_1_10G_3_1G[4] = {10, 2, 2, 2};
1024732Sdavemq static uint8_t rx_1_1G_1_10G_2_1G[4] = {2, 10, 2, 2};
1034732Sdavemq 
1044732Sdavemq static uint8_t tx_4_1G[4] = {6, 6, 6, 6};
1054732Sdavemq static uint8_t tx_2_10G[2] = {12, 12};
1064732Sdavemq static uint8_t tx_2_10G_2_1G[4] = {10, 10, 2, 2};
1074732Sdavemq static uint8_t tx_1_10G_3_1G[4] = {12, 4, 4, 4};
1084732Sdavemq static uint8_t tx_1_1G_1_10G_2_1G[4] = {4, 12, 4, 4};
1094732Sdavemq 
1103859Sml29623 typedef enum {
1113859Sml29623 	DEFAULT = 0,
1123859Sml29623 	EQUAL,
1133859Sml29623 	FAIR,
1143859Sml29623 	CUSTOM,
1153859Sml29623 	CLASSIFY,
1163859Sml29623 	L2_CLASSIFY,
1173859Sml29623 	L3_DISTRIBUTE,
1183859Sml29623 	L3_CLASSIFY,
1193859Sml29623 	L3_TCAM,
1203859Sml29623 	CONFIG_TOKEN_NONE
1213859Sml29623 } config_token_t;
1223859Sml29623 
1233859Sml29623 static char *token_names[] = {
1243859Sml29623 	"default",
1253859Sml29623 	"equal",
1263859Sml29623 	"fair",
1273859Sml29623 	"custom",
1283859Sml29623 	"classify",
1293859Sml29623 	"l2_classify",
1303859Sml29623 	"l3_distribute",
1313859Sml29623 	"l3_classify",
1323859Sml29623 	"l3_tcam",
1333859Sml29623 	"none",
1343859Sml29623 };
1353859Sml29623 
1363859Sml29623 void nxge_virint_regs_dump(p_nxge_t nxgep);
1373859Sml29623 
1383859Sml29623 void
1393859Sml29623 nxge_virint_regs_dump(p_nxge_t nxgep)
1403859Sml29623 {
1413859Sml29623 	npi_handle_t handle;
1423859Sml29623 
1433859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_virint_regs_dump"));
1443859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
1453859Sml29623 	(void) npi_vir_dump_pio_fzc_regs_one(handle);
1463859Sml29623 	(void) npi_vir_dump_ldgnum(handle);
1473859Sml29623 	(void) npi_vir_dump_ldsv(handle);
1483859Sml29623 	(void) npi_vir_dump_imask0(handle);
1493859Sml29623 	(void) npi_vir_dump_sid(handle);
1503859Sml29623 	(void) npi_mac_dump_regs(handle, nxgep->function_num);
1513859Sml29623 	(void) npi_ipp_dump_regs(handle, nxgep->function_num);
1523859Sml29623 	(void) npi_fflp_dump_regs(handle);
1533859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_virint_regs_dump"));
1543859Sml29623 }
1553859Sml29623 
1563859Sml29623 /*
1573859Sml29623  * For now: we hard coded the DMA configurations.
1583859Sml29623  *	    and assume for one partition only.
1593859Sml29623  *
1603859Sml29623  *       OBP. Then OBP will pass this partition's
1613859Sml29623  *	 Neptune configurations to fcode to create
1623859Sml29623  *	 properties for them.
1633859Sml29623  *
1643859Sml29623  *	Since Neptune(PCI-E) and NIU (Niagara-2) has
1653859Sml29623  *	different bus interfaces, the driver needs
1663859Sml29623  *	to know which bus it is connected to.
1673859Sml29623  *  	Ravinder suggested: create a device property.
1683859Sml29623  *	In partitioning environment, we cannot
1693859Sml29623  *	use .conf file (need to check). If conf changes,
1703859Sml29623  *	need to reboot the system.
1713859Sml29623  *	The following function assumes that we will
1723859Sml29623  *	retrieve its properties from a virtualized nexus driver.
1733859Sml29623  */
1743859Sml29623 
1753859Sml29623 nxge_status_t
1763859Sml29623 nxge_cntlops(dev_info_t *dip, nxge_ctl_enum_t ctlop, void *arg, void *result)
1773859Sml29623 {
1783859Sml29623 	nxge_status_t status = NXGE_OK;
1793859Sml29623 	int instance;
1803859Sml29623 	p_nxge_t nxgep;
1813859Sml29623 
1823859Sml29623 #ifndef NXGE_SHARED_REG_SW_SIM
1833859Sml29623 	npi_handle_t handle;
1843859Sml29623 	uint16_t sr16, cr16;
1853859Sml29623 #endif
1863859Sml29623 	instance = ddi_get_instance(dip);
1873859Sml29623 	NXGE_DEBUG_MSG((NULL, VIR_CTL, "Instance %d ", instance));
1883859Sml29623 
1893859Sml29623 	if (nxge_list == NULL) {
1903859Sml29623 		NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
1913859Sml29623 				"nxge_cntlops: nxge_list null"));
1923859Sml29623 		return (NXGE_ERROR);
1933859Sml29623 	}
1943859Sml29623 	nxgep = (p_nxge_t)ddi_get_soft_state(nxge_list, instance);
1953859Sml29623 	if (nxgep == NULL) {
1963859Sml29623 		NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
1973859Sml29623 				"nxge_cntlops: nxgep null"));
1983859Sml29623 		return (NXGE_ERROR);
1993859Sml29623 	}
2003859Sml29623 #ifndef NXGE_SHARED_REG_SW_SIM
2013859Sml29623 	handle = nxgep->npi_reg_handle;
2023859Sml29623 #endif
2033859Sml29623 	switch (ctlop) {
2043859Sml29623 	case NXGE_CTLOPS_NIUTYPE:
2053859Sml29623 		nxge_get_niu_property(dip, (niu_type_t *)result);
2063859Sml29623 		return (status);
2073859Sml29623 
2083859Sml29623 	case NXGE_CTLOPS_GET_SHARED_REG:
2093859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2103859Sml29623 		*(uint64_t *)result = global_dev_ctrl;
2113859Sml29623 		return (0);
2123859Sml29623 #else
2133859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2143859Sml29623 		*(uint16_t *)result = sr16;
2153859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2163859Sml29623 			"nxge_cntlops: NXGE_CTLOPS_GET_SHARED_REG"));
2173859Sml29623 		return (0);
2183859Sml29623 #endif
2193859Sml29623 
2203859Sml29623 	case NXGE_CTLOPS_SET_SHARED_REG_LOCK:
2213859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2223859Sml29623 		global_dev_ctrl = *(uint64_t *)arg;
2233859Sml29623 		return (0);
2243859Sml29623 #else
2253859Sml29623 		status = NPI_FAILURE;
2263859Sml29623 		while (status != NPI_SUCCESS)
2273859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
2283859Sml29623 
2293859Sml29623 		sr16 = *(uint16_t *)arg;
2303859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2313859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
2323859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2333859Sml29623 			"nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2343859Sml29623 		return (0);
2353859Sml29623 #endif
2363859Sml29623 
2373859Sml29623 	case NXGE_CTLOPS_UPDATE_SHARED_REG:
2383859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2393859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2403859Sml29623 		return (0);
2413859Sml29623 #else
2423859Sml29623 		status = NPI_FAILURE;
2433859Sml29623 		while (status != NPI_SUCCESS)
2443859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
2453859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2463859Sml29623 		sr16 |= *(uint16_t *)arg;
2473859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2483859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
2493859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2503859Sml29623 			"nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2513859Sml29623 		return (0);
2523859Sml29623 #endif
2533859Sml29623 
2543859Sml29623 	case NXGE_CTLOPS_CLEAR_BIT_SHARED_REG_UL:
2553859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2563859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2573859Sml29623 		return (0);
2583859Sml29623 #else
2593859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2603859Sml29623 		cr16 = *(uint16_t *)arg;
2613859Sml29623 		sr16 &= ~cr16;
2623859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2633859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2643859Sml29623 			"nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2653859Sml29623 		return (0);
2663859Sml29623 #endif
2673859Sml29623 
2683859Sml29623 	case NXGE_CTLOPS_CLEAR_BIT_SHARED_REG:
2693859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2703859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2713859Sml29623 		return (0);
2723859Sml29623 #else
2733859Sml29623 		status = NPI_FAILURE;
2743859Sml29623 		while (status != NPI_SUCCESS)
2753859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
2763859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2773859Sml29623 		cr16 = *(uint16_t *)arg;
2783859Sml29623 		sr16 &= ~cr16;
2793859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2803859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
2813859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2823859Sml29623 			"nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2833859Sml29623 		return (0);
2843859Sml29623 #endif
2853859Sml29623 
2863859Sml29623 	case NXGE_CTLOPS_GET_LOCK_BLOCK:
2873859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2883859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2893859Sml29623 		return (0);
2903859Sml29623 #else
2913859Sml29623 		status = NPI_FAILURE;
2923859Sml29623 		while (status != NPI_SUCCESS)
2933859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
2943859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2953859Sml29623 			"nxge_cntlops: NXGE_CTLOPS_GET_LOCK_BLOCK"));
2963859Sml29623 		return (0);
2973859Sml29623 #endif
2983859Sml29623 	case NXGE_CTLOPS_GET_LOCK_TRY:
2993859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
3003859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
3013859Sml29623 		return (0);
3023859Sml29623 #else
3033859Sml29623 		status = npi_dev_func_sr_lock_enter(handle);
3043859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
3053859Sml29623 			"nxge_cntlops: NXGE_CTLOPS_GET_LOCK_TRY"));
3063859Sml29623 		if (status == NPI_SUCCESS)
3073859Sml29623 			return (NXGE_OK);
3083859Sml29623 		else
3093859Sml29623 			return (NXGE_ERROR);
3103859Sml29623 #endif
3113859Sml29623 	case NXGE_CTLOPS_FREE_LOCK:
3123859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
3133859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
3143859Sml29623 		return (0);
3153859Sml29623 #else
3163859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
3173859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
3183859Sml29623 			"nxge_cntlops: NXGE_CTLOPS_GET_LOCK_FREE"));
3193859Sml29623 		if (status == NPI_SUCCESS)
3203859Sml29623 			return (NXGE_OK);
3213859Sml29623 		else
3223859Sml29623 			return (NXGE_ERROR);
3233859Sml29623 #endif
3243859Sml29623 
3253859Sml29623 	default:
3263859Sml29623 		status = NXGE_ERROR;
3273859Sml29623 	}
3283859Sml29623 
3293859Sml29623 	return (status);
3303859Sml29623 }
3313859Sml29623 
3323859Sml29623 void
3333859Sml29623 nxge_common_lock_get(p_nxge_t nxgep)
3343859Sml29623 {
3353859Sml29623 	uint32_t status = NPI_FAILURE;
3363859Sml29623 	npi_handle_t handle;
3373859Sml29623 
3383859Sml29623 #if	defined(NXGE_SHARE_REG_SW_SIM)
3393859Sml29623 	return;
3403859Sml29623 #endif
3413859Sml29623 	handle = nxgep->npi_reg_handle;
3423859Sml29623 	while (status != NPI_SUCCESS)
3433859Sml29623 		status = npi_dev_func_sr_lock_enter(handle);
3443859Sml29623 }
3453859Sml29623 
3463859Sml29623 void
3473859Sml29623 nxge_common_lock_free(p_nxge_t nxgep)
3483859Sml29623 {
3493859Sml29623 	npi_handle_t handle;
3503859Sml29623 
3513859Sml29623 #if	defined(NXGE_SHARE_REG_SW_SIM)
3523859Sml29623 	return;
3533859Sml29623 #endif
3543859Sml29623 	handle = nxgep->npi_reg_handle;
3553859Sml29623 	(void) npi_dev_func_sr_lock_free(handle);
3563859Sml29623 }
3573859Sml29623 
3584185Sspeer 
3593859Sml29623 static void
3603859Sml29623 nxge_get_niu_property(dev_info_t *dip, niu_type_t *niu_type)
3613859Sml29623 {
3623859Sml29623 	uchar_t *prop_val;
3633859Sml29623 	uint_t prop_len;
3643859Sml29623 
3654732Sdavemq 	*niu_type = NIU_TYPE_NONE;
3663859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0,
3673859Sml29623 			"niu-type", (uchar_t **)&prop_val,
3683859Sml29623 			&prop_len) == DDI_PROP_SUCCESS) {
3693859Sml29623 		if (strncmp("niu", (caddr_t)prop_val, (size_t)prop_len) == 0) {
3703859Sml29623 			*niu_type = N2_NIU;
3713859Sml29623 		}
3723859Sml29623 		ddi_prop_free(prop_val);
3733859Sml29623 	}
3743859Sml29623 }
3753859Sml29623 
3763859Sml29623 static config_token_t
3773859Sml29623 nxge_get_config_token(char *prop)
3783859Sml29623 {
3793859Sml29623 	config_token_t token = DEFAULT;
3803859Sml29623 
3813859Sml29623 	while (token < CONFIG_TOKEN_NONE) {
3823859Sml29623 		if (strncmp(prop, token_names[token], 4) == 0)
3833859Sml29623 			break;
3843859Sml29623 		token++;
3853859Sml29623 	}
3863859Sml29623 	return (token);
3873859Sml29623 }
3883859Sml29623 
3893859Sml29623 /* per port */
3903859Sml29623 
3913859Sml29623 static nxge_status_t
3923859Sml29623 nxge_update_rxdma_grp_properties(p_nxge_t nxgep, config_token_t token,
3933859Sml29623 	dev_info_t *s_dip[])
3943859Sml29623 {
3953859Sml29623 	nxge_status_t status = NXGE_OK;
3963859Sml29623 	int ddi_status;
3973859Sml29623 	int num_ports = nxgep->nports;
3983859Sml29623 	int port, bits, j;
3993859Sml29623 	uint8_t start_grp = 0, num_grps = 0;
4003859Sml29623 	p_nxge_param_t param_arr;
4013859Sml29623 	uint32_t grp_bitmap[MAX_SIBLINGS];
4023859Sml29623 	int custom_start_grp[MAX_SIBLINGS];
4033859Sml29623 	int custom_num_grp[MAX_SIBLINGS];
4043859Sml29623 	uint8_t bad_config = B_FALSE;
4053859Sml29623 	char *start_prop, *num_prop, *cfg_prop;
4063859Sml29623 
4073859Sml29623 	start_grp = 0;
4083859Sml29623 	param_arr = nxgep->param_arr;
4093859Sml29623 	start_prop = param_arr[param_rdc_grps_start].fcode_name;
4103859Sml29623 	num_prop = param_arr[param_rx_rdc_grps].fcode_name;
4113859Sml29623 
4123859Sml29623 	switch (token) {
4133859Sml29623 	case FAIR:
4143859Sml29623 		cfg_prop = "fair";
4153859Sml29623 		for (port = 0; port < num_ports; port++) {
4163859Sml29623 			custom_num_grp[port] =
4173859Sml29623 				(num_ports == 4) ?
4183859Sml29623 				p4_rdcgrp_fair[port] :
4193859Sml29623 				p2_rdcgrp_fair[port];
4203859Sml29623 			custom_start_grp[port] = start_grp;
4213859Sml29623 			start_grp += custom_num_grp[port];
4223859Sml29623 		}
4233859Sml29623 		break;
4243859Sml29623 
4253859Sml29623 	case EQUAL:
4263859Sml29623 		cfg_prop = "equal";
4273859Sml29623 		for (port = 0; port < num_ports; port++) {
4283859Sml29623 			custom_num_grp[port] =
4293859Sml29623 				(num_ports == 4) ?
4303859Sml29623 				p4_rdcgrp_equal[port] :
4313859Sml29623 				p2_rdcgrp_equal[port];
4323859Sml29623 			custom_start_grp[port] = start_grp;
4333859Sml29623 			start_grp += custom_num_grp[port];
4343859Sml29623 		}
4353859Sml29623 		break;
4363859Sml29623 
4373859Sml29623 
4383859Sml29623 	case CLASSIFY:
4393859Sml29623 		cfg_prop = "classify";
4403859Sml29623 		for (port = 0; port < num_ports; port++) {
4413859Sml29623 			custom_num_grp[port] = (num_ports == 4) ?
4423859Sml29623 				p4_rdcgrp_cls[port] : p2_rdcgrp_cls[port];
4433859Sml29623 			custom_start_grp[port] = start_grp;
4443859Sml29623 			start_grp += custom_num_grp[port];
4453859Sml29623 		}
4463859Sml29623 		break;
4473859Sml29623 
4483859Sml29623 	case CUSTOM:
4493859Sml29623 		cfg_prop = "custom";
4503859Sml29623 		/* See if it is good config */
4513859Sml29623 		num_grps = 0;
4523859Sml29623 		for (port = 0; port < num_ports; port++) {
4533859Sml29623 			custom_start_grp[port] =
4543859Sml29623 				ddi_prop_get_int(DDI_DEV_T_NONE, s_dip[port],
4553859Sml29623 				DDI_PROP_DONTPASS, start_prop, -1);
4563859Sml29623 			if ((custom_start_grp[port] == -1) ||
4573859Sml29623 				(custom_start_grp[port] >=
4583859Sml29623 					NXGE_MAX_RDC_GRPS)) {
4593859Sml29623 				bad_config = B_TRUE;
4603859Sml29623 				break;
4613859Sml29623 			}
4623859Sml29623 			custom_num_grp[port] = ddi_prop_get_int(
4633859Sml29623 				DDI_DEV_T_NONE,
4643859Sml29623 				s_dip[port],
4653859Sml29623 				DDI_PROP_DONTPASS,
4663859Sml29623 				num_prop, -1);
4673859Sml29623 
4683859Sml29623 			if ((custom_num_grp[port] == -1) ||
4693859Sml29623 				(custom_num_grp[port] >
4703859Sml29623 					NXGE_MAX_RDC_GRPS) ||
4713859Sml29623 				((custom_num_grp[port] +
4723859Sml29623 						custom_start_grp[port]) >=
4733859Sml29623 					NXGE_MAX_RDC_GRPS)) {
4743859Sml29623 				bad_config = B_TRUE;
4753859Sml29623 				break;
4763859Sml29623 			}
4773859Sml29623 			num_grps += custom_num_grp[port];
4783859Sml29623 			if (num_grps > NXGE_MAX_RDC_GRPS) {
4793859Sml29623 				bad_config = B_TRUE;
4803859Sml29623 				break;
4813859Sml29623 			}
4823859Sml29623 			grp_bitmap[port] = 0;
4833859Sml29623 			for (bits = 0;
4843859Sml29623 				bits < custom_num_grp[port];
4853859Sml29623 				bits++) {
4863859Sml29623 				grp_bitmap[port] |=
4873859Sml29623 					(1 << (bits + custom_start_grp[port]));
4883859Sml29623 			}
4893859Sml29623 
4903859Sml29623 		}
4913859Sml29623 
4923859Sml29623 		if (bad_config == B_FALSE) {
4933859Sml29623 			/* check for overlap */
4943859Sml29623 			for (port = 0; port < num_ports - 1; port++) {
4953859Sml29623 				for (j = port + 1; j < num_ports; j++) {
4963859Sml29623 					if (grp_bitmap[port] &
4973859Sml29623 						grp_bitmap[j]) {
4983859Sml29623 						bad_config = B_TRUE;
4993859Sml29623 						break;
5003859Sml29623 					}
5013859Sml29623 				}
5023859Sml29623 				if (bad_config == B_TRUE)
5033859Sml29623 					break;
5043859Sml29623 			}
5053859Sml29623 		}
5063859Sml29623 		if (bad_config == B_TRUE) {
5073859Sml29623 			/* use default config */
5083859Sml29623 			for (port = 0; port < num_ports; port++) {
5093859Sml29623 				custom_num_grp[port] =
5103859Sml29623 					(num_ports == 4) ?
5113859Sml29623 					p4_rx_fair[port] : p2_rx_fair[port];
5123859Sml29623 				custom_start_grp[port] = start_grp;
5133859Sml29623 				start_grp += custom_num_grp[port];
5143859Sml29623 			}
5153859Sml29623 		}
5163859Sml29623 		break;
5173859Sml29623 
5183859Sml29623 	default:
5193859Sml29623 		/* use default config */
5203859Sml29623 		cfg_prop = "fair";
5213859Sml29623 		for (port = 0; port < num_ports; port++) {
5223859Sml29623 			custom_num_grp[port] = (num_ports == 4) ?
5233859Sml29623 				p4_rx_fair[port] : p2_rx_fair[port];
5243859Sml29623 			custom_start_grp[port] = start_grp;
5253859Sml29623 			start_grp += custom_num_grp[port];
5263859Sml29623 		}
5273859Sml29623 		break;
5283859Sml29623 	}
5293859Sml29623 
5303859Sml29623 	/* Now Update the rx properties */
5313859Sml29623 	for (port = 0; port < num_ports; port++) {
5323859Sml29623 		ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
5333859Sml29623 			"rxdma-grp-cfg", cfg_prop);
5343859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
5353859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
5363859Sml29623 					" property %s not updating",
5373859Sml29623 					cfg_prop));
5383859Sml29623 			status |= NXGE_DDI_FAILED;
5393859Sml29623 		}
5403859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
5413859Sml29623 			num_prop, custom_num_grp[port]);
5423859Sml29623 
5433859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
5443859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
5453859Sml29623 					" property %s not updating",
5463859Sml29623 					num_prop));
5473859Sml29623 			status |= NXGE_DDI_FAILED;
5483859Sml29623 		}
5493859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
5503859Sml29623 			start_prop, custom_start_grp[port]);
5513859Sml29623 
5523859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
5533859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
5543859Sml29623 					" property %s not updating",
5553859Sml29623 					start_prop));
5563859Sml29623 			status |= NXGE_DDI_FAILED;
5573859Sml29623 		}
5583859Sml29623 	}
5593859Sml29623 	if (status & NXGE_DDI_FAILED)
5603859Sml29623 		status |= NXGE_ERROR;
5613859Sml29623 
5623859Sml29623 	return (status);
5633859Sml29623 }
5643859Sml29623 
5653859Sml29623 static nxge_status_t
5663859Sml29623 nxge_update_rxdma_properties(p_nxge_t nxgep, config_token_t token,
5673859Sml29623 	dev_info_t *s_dip[])
5683859Sml29623 {
5693859Sml29623 	nxge_status_t status = NXGE_OK;
5703859Sml29623 	int ddi_status;
5713859Sml29623 	int num_ports = nxgep->nports;
5723859Sml29623 	int port, bits, j;
5733859Sml29623 	uint8_t start_rdc = 0, num_rdc = 0;
5743859Sml29623 	p_nxge_param_t param_arr;
5753859Sml29623 	uint32_t rdc_bitmap[MAX_SIBLINGS];
5763859Sml29623 	int custom_start_rdc[MAX_SIBLINGS];
5773859Sml29623 	int custom_num_rdc[MAX_SIBLINGS];
5783859Sml29623 	uint8_t bad_config = B_FALSE;
5793859Sml29623 	int *prop_val;
5803859Sml29623 	uint_t prop_len;
5813859Sml29623 	char *start_rdc_prop, *num_rdc_prop, *cfg_prop;
5823859Sml29623 
5833859Sml29623 	start_rdc = 0;
5843859Sml29623 	param_arr = nxgep->param_arr;
5853859Sml29623 	start_rdc_prop = param_arr[param_rxdma_channels_begin].fcode_name;
5863859Sml29623 	num_rdc_prop = param_arr[param_rxdma_channels].fcode_name;
5873859Sml29623 
5883859Sml29623 	switch (token) {
5893859Sml29623 	case FAIR:
5903859Sml29623 		cfg_prop = "fair";
5913859Sml29623 		for (port = 0; port < num_ports; port++) {
5923859Sml29623 			custom_num_rdc[port] = (num_ports == 4) ?
5933859Sml29623 				p4_rx_fair[port] : p2_rx_fair[port];
5943859Sml29623 			custom_start_rdc[port] = start_rdc;
5953859Sml29623 			start_rdc += custom_num_rdc[port];
5963859Sml29623 		}
5973859Sml29623 		break;
5983859Sml29623 
5993859Sml29623 	case EQUAL:
6003859Sml29623 		cfg_prop = "equal";
6013859Sml29623 		for (port = 0; port < num_ports; port++) {
6023859Sml29623 			custom_num_rdc[port] = (num_ports == 4) ?
6033859Sml29623 				p4_rx_equal[port] :
6043859Sml29623 				p2_rx_equal[port];
6053859Sml29623 			custom_start_rdc[port] = start_rdc;
6063859Sml29623 			start_rdc += custom_num_rdc[port];
6073859Sml29623 		}
6083859Sml29623 		break;
6093859Sml29623 
6103859Sml29623 	case CUSTOM:
6113859Sml29623 		cfg_prop = "custom";
6123859Sml29623 		/* See if it is good config */
6133859Sml29623 		num_rdc = 0;
6143859Sml29623 		for (port = 0; port < num_ports; port++) {
6153859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
6163859Sml29623 				DDI_DEV_T_ANY,
6173859Sml29623 				s_dip[port], 0,
6183859Sml29623 				start_rdc_prop,
6193859Sml29623 				&prop_val,
6203859Sml29623 				&prop_len);
6213859Sml29623 			if (ddi_status == DDI_SUCCESS)
6223859Sml29623 				custom_start_rdc[port] = *prop_val;
6233859Sml29623 			else {
6243859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6253859Sml29623 						" %s custom start port %d"
6263859Sml29623 						" read failed ",
6273859Sml29623 						" rxdma-cfg", port));
6283859Sml29623 				bad_config = B_TRUE;
6293859Sml29623 				status |= NXGE_DDI_FAILED;
6303859Sml29623 			}
6313859Sml29623 			if ((custom_start_rdc[port] == -1) ||
6323859Sml29623 				(custom_start_rdc[port] >=
6333859Sml29623 					NXGE_MAX_RDCS)) {
6343859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6353859Sml29623 						" %s custom start %d"
6363859Sml29623 						" out of range %x ",
6373859Sml29623 						" rxdma-cfg",
6383859Sml29623 						port,
6393859Sml29623 						custom_start_rdc[port]));
6403859Sml29623 				bad_config = B_TRUE;
6413859Sml29623 				break;
6423859Sml29623 			}
6433859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
6443859Sml29623 				DDI_DEV_T_ANY,
6453859Sml29623 				s_dip[port],
6463859Sml29623 				0,
6473859Sml29623 				num_rdc_prop,
6483859Sml29623 				&prop_val,
6493859Sml29623 				&prop_len);
6503859Sml29623 
6513859Sml29623 			if (ddi_status == DDI_SUCCESS)
6523859Sml29623 				custom_num_rdc[port] = *prop_val;
6533859Sml29623 			else {
6543859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6553859Sml29623 					" %s custom num port %d"
6563859Sml29623 					" read failed ",
6573859Sml29623 					"rxdma-cfg", port));
6583859Sml29623 				bad_config = B_TRUE;
6593859Sml29623 				status |= NXGE_DDI_FAILED;
6603859Sml29623 			}
6613859Sml29623 
6623859Sml29623 			if ((custom_num_rdc[port] == -1) ||
6633859Sml29623 					(custom_num_rdc[port] >
6643859Sml29623 						NXGE_MAX_RDCS) ||
6653859Sml29623 					((custom_num_rdc[port] +
6663859Sml29623 						custom_start_rdc[port]) >
6673859Sml29623 					NXGE_MAX_RDCS)) {
6683859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6693859Sml29623 					" %s custom num %d"
6703859Sml29623 					" out of range %x ",
6713859Sml29623 					" rxdma-cfg",
6723859Sml29623 					port, custom_num_rdc[port]));
6733859Sml29623 				bad_config = B_TRUE;
6743859Sml29623 				break;
6753859Sml29623 			}
6763859Sml29623 			num_rdc += custom_num_rdc[port];
6773859Sml29623 			if (num_rdc > NXGE_MAX_RDCS) {
6783859Sml29623 				bad_config = B_TRUE;
6793859Sml29623 				break;
6803859Sml29623 			}
6813859Sml29623 			rdc_bitmap[port] = 0;
6823859Sml29623 			for (bits = 0;
6833859Sml29623 				bits < custom_num_rdc[port]; bits++) {
6843859Sml29623 				rdc_bitmap[port] |=
6853859Sml29623 					(1 << (bits + custom_start_rdc[port]));
6863859Sml29623 			}
6873859Sml29623 		}
6883859Sml29623 
6893859Sml29623 		if (bad_config == B_FALSE) {
6903859Sml29623 			/* check for overlap */
6913859Sml29623 			for (port = 0; port < num_ports - 1; port++) {
6923859Sml29623 				for (j = port + 1; j < num_ports; j++) {
6933859Sml29623 					if (rdc_bitmap[port] &
6943859Sml29623 						rdc_bitmap[j]) {
6953859Sml29623 						NXGE_DEBUG_MSG((nxgep,
6963859Sml29623 							CFG_CTL,
6973859Sml29623 							" rxdma-cfg"
6983859Sml29623 							" property custom"
6993859Sml29623 							" bit overlap"
7003859Sml29623 							" %d %d ",
7013859Sml29623 							port, j));
7023859Sml29623 						bad_config = B_TRUE;
7033859Sml29623 						break;
7043859Sml29623 					}
7053859Sml29623 				}
7063859Sml29623 				if (bad_config == B_TRUE)
7073859Sml29623 					break;
7083859Sml29623 			}
7093859Sml29623 		}
7103859Sml29623 		if (bad_config == B_TRUE) {
7113859Sml29623 			/* use default config */
7123859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
7133859Sml29623 				" rxdma-cfg property:"
7143859Sml29623 				" bad custom config:"
7153859Sml29623 				" use default"));
7163859Sml29623 			for (port = 0; port < num_ports; port++) {
7173859Sml29623 				custom_num_rdc[port] =
7183859Sml29623 					(num_ports == 4) ?
7193859Sml29623 					p4_rx_fair[port] :
7203859Sml29623 					p2_rx_fair[port];
7213859Sml29623 				custom_start_rdc[port] = start_rdc;
7223859Sml29623 				start_rdc += custom_num_rdc[port];
7233859Sml29623 			}
7243859Sml29623 		}
7253859Sml29623 		break;
7263859Sml29623 
7273859Sml29623 	default:
7283859Sml29623 		/* use default config */
7293859Sml29623 		cfg_prop = "fair";
7303859Sml29623 		for (port = 0; port < num_ports; port++) {
7313859Sml29623 			custom_num_rdc[port] = (num_ports == 4) ?
7323859Sml29623 				p4_rx_fair[port] : p2_rx_fair[port];
7333859Sml29623 			custom_start_rdc[port] = start_rdc;
7343859Sml29623 			start_rdc += custom_num_rdc[port];
7353859Sml29623 		}
7363859Sml29623 		break;
7373859Sml29623 	}
7383859Sml29623 
7393859Sml29623 	/* Now Update the rx properties */
7403859Sml29623 	for (port = 0; port < num_ports; port++) {
7413859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
7423859Sml29623 			" update property rxdma-cfg with %s ", cfg_prop));
7433859Sml29623 		ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
7443859Sml29623 			"rxdma-cfg", cfg_prop);
7453859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
7463859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
7473859Sml29623 				" property rxdma-cfg is not updating to %s",
7483859Sml29623 				cfg_prop));
7493859Sml29623 			status |= NXGE_DDI_FAILED;
7503859Sml29623 		}
7513859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
7523859Sml29623 			num_rdc_prop, custom_num_rdc[port]));
7533859Sml29623 
7543859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
7553859Sml29623 			num_rdc_prop, custom_num_rdc[port]);
7563859Sml29623 
7573859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
7583859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
7593859Sml29623 				" property %s not updating with %d",
7603859Sml29623 				num_rdc_prop, custom_num_rdc[port]));
7613859Sml29623 			status |= NXGE_DDI_FAILED;
7623859Sml29623 		}
7633859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
7643859Sml29623 			start_rdc_prop, custom_start_rdc[port]));
7653859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
7663859Sml29623 			start_rdc_prop, custom_start_rdc[port]);
7673859Sml29623 
7683859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
7693859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
7703859Sml29623 				" property %s not updating with %d ",
7713859Sml29623 				start_rdc_prop, custom_start_rdc[port]));
7723859Sml29623 			status |= NXGE_DDI_FAILED;
7733859Sml29623 		}
7743859Sml29623 	}
7753859Sml29623 	if (status & NXGE_DDI_FAILED)
7763859Sml29623 		status |= NXGE_ERROR;
7773859Sml29623 	return (status);
7783859Sml29623 }
7793859Sml29623 
7803859Sml29623 static nxge_status_t
7813859Sml29623 nxge_update_txdma_properties(p_nxge_t nxgep, config_token_t token,
7823859Sml29623 	dev_info_t *s_dip[])
7833859Sml29623 {
7843859Sml29623 	nxge_status_t status = NXGE_OK;
7853859Sml29623 	int ddi_status = DDI_SUCCESS;
7863859Sml29623 	int num_ports = nxgep->nports;
7873859Sml29623 	int port, bits, j;
7883859Sml29623 	uint8_t start_tdc = 0, num_tdc = 0;
7893859Sml29623 	p_nxge_param_t param_arr;
7903859Sml29623 	uint32_t tdc_bitmap[MAX_SIBLINGS];
7913859Sml29623 	int custom_start_tdc[MAX_SIBLINGS];
7923859Sml29623 	int custom_num_tdc[MAX_SIBLINGS];
7933859Sml29623 	uint8_t bad_config = B_FALSE;
7943859Sml29623 	int *prop_val;
7953859Sml29623 	uint_t prop_len;
7963859Sml29623 	char *start_tdc_prop, *num_tdc_prop, *cfg_prop;
7973859Sml29623 
7983859Sml29623 	start_tdc = 0;
7993859Sml29623 	param_arr = nxgep->param_arr;
8003859Sml29623 	start_tdc_prop = param_arr[param_txdma_channels_begin].fcode_name;
8013859Sml29623 	num_tdc_prop = param_arr[param_txdma_channels].fcode_name;
8023859Sml29623 
8033859Sml29623 	switch (token) {
8043859Sml29623 	case FAIR:
8053859Sml29623 		cfg_prop = "fair";
8063859Sml29623 		for (port = 0; port < num_ports; port++) {
8073859Sml29623 			custom_num_tdc[port] = (num_ports == 4) ?
8083859Sml29623 				p4_tx_fair[port] : p2_tx_fair[port];
8093859Sml29623 			custom_start_tdc[port] = start_tdc;
8103859Sml29623 			start_tdc += custom_num_tdc[port];
8113859Sml29623 		}
8123859Sml29623 		break;
8133859Sml29623 
8143859Sml29623 	case EQUAL:
8153859Sml29623 		cfg_prop = "equal";
8163859Sml29623 		for (port = 0; port < num_ports; port++) {
8173859Sml29623 			custom_num_tdc[port] = (num_ports == 4) ?
8183859Sml29623 				p4_tx_equal[port] : p2_tx_equal[port];
8193859Sml29623 			custom_start_tdc[port] = start_tdc;
8203859Sml29623 			start_tdc += custom_num_tdc[port];
8213859Sml29623 		}
8223859Sml29623 		break;
8233859Sml29623 
8243859Sml29623 	case CUSTOM:
8253859Sml29623 		cfg_prop = "custom";
8263859Sml29623 		/* See if it is good config */
8273859Sml29623 		num_tdc = 0;
8283859Sml29623 		for (port = 0; port < num_ports; port++) {
8293859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
8303859Sml29623 				DDI_DEV_T_ANY, s_dip[port], 0, start_tdc_prop,
8313859Sml29623 				&prop_val, &prop_len);
8323859Sml29623 			if (ddi_status == DDI_SUCCESS)
8333859Sml29623 				custom_start_tdc[port] = *prop_val;
8343859Sml29623 			else {
8353859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8363859Sml29623 					" %s custom start port %d"
8373859Sml29623 					" read failed ", " txdma-cfg", port));
8383859Sml29623 				bad_config = B_TRUE;
8393859Sml29623 				status |= NXGE_DDI_FAILED;
8403859Sml29623 			}
8413859Sml29623 
8423859Sml29623 			if ((custom_start_tdc[port] == -1) ||
8433859Sml29623 					(custom_start_tdc[port] >=
8443859Sml29623 					NXGE_MAX_RDCS)) {
8453859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8463859Sml29623 					" %s custom start %d"
8473859Sml29623 					" out of range %x ", " txdma-cfg",
8483859Sml29623 					port, custom_start_tdc[port]));
8493859Sml29623 				bad_config = B_TRUE;
8503859Sml29623 				break;
8513859Sml29623 			}
8523859Sml29623 
8533859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
8543859Sml29623 				DDI_DEV_T_ANY, s_dip[port], 0, num_tdc_prop,
8553859Sml29623 				&prop_val, &prop_len);
8563859Sml29623 			if (ddi_status == DDI_SUCCESS)
8573859Sml29623 				custom_num_tdc[port] = *prop_val;
8583859Sml29623 			else {
8593859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8603859Sml29623 					" %s custom num port %d"
8613859Sml29623 					" read failed ", " txdma-cfg", port));
8623859Sml29623 				bad_config = B_TRUE;
8633859Sml29623 				status |= NXGE_DDI_FAILED;
8643859Sml29623 			}
8653859Sml29623 
8663859Sml29623 			if ((custom_num_tdc[port] == -1) ||
8673859Sml29623 					(custom_num_tdc[port] >
8683859Sml29623 						NXGE_MAX_TDCS) ||
8693859Sml29623 					((custom_num_tdc[port] +
8703859Sml29623 						custom_start_tdc[port]) >
8713859Sml29623 					NXGE_MAX_TDCS)) {
8723859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8733859Sml29623 					" %s custom num %d"
8743859Sml29623 					" out of range %x ", " rxdma-cfg",
8753859Sml29623 					port, custom_num_tdc[port]));
8763859Sml29623 				bad_config = B_TRUE;
8773859Sml29623 				break;
8783859Sml29623 			}
8793859Sml29623 			num_tdc += custom_num_tdc[port];
8803859Sml29623 			if (num_tdc > NXGE_MAX_TDCS) {
8813859Sml29623 				bad_config = B_TRUE;
8823859Sml29623 				break;
8833859Sml29623 			}
8843859Sml29623 			tdc_bitmap[port] = 0;
8853859Sml29623 			for (bits = 0;
8863859Sml29623 				bits < custom_num_tdc[port]; bits++) {
8873859Sml29623 				tdc_bitmap[port] |=
8883859Sml29623 					(1 <<
8893859Sml29623 					(bits + custom_start_tdc[port]));
8903859Sml29623 			}
8913859Sml29623 
8923859Sml29623 		}
8933859Sml29623 
8943859Sml29623 		if (bad_config == B_FALSE) {
8953859Sml29623 			/* check for overlap */
8963859Sml29623 			for (port = 0; port < num_ports - 1; port++) {
8973859Sml29623 				for (j = port + 1; j < num_ports; j++) {
8983859Sml29623 					if (tdc_bitmap[port] &
8993859Sml29623 						tdc_bitmap[j]) {
9003859Sml29623 						NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9013859Sml29623 							" rxdma-cfg"
9023859Sml29623 							" property custom"
9033859Sml29623 							" bit overlap"
9043859Sml29623 							" %d %d ",
9053859Sml29623 							port, j));
9063859Sml29623 						bad_config = B_TRUE;
9073859Sml29623 						break;
9083859Sml29623 					}
9093859Sml29623 				}
9103859Sml29623 				if (bad_config == B_TRUE)
9113859Sml29623 					break;
9123859Sml29623 			}
9133859Sml29623 		}
9143859Sml29623 		if (bad_config == B_TRUE) {
9153859Sml29623 			/* use default config */
9163859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9173859Sml29623 				" txdma-cfg property:"
9183859Sml29623 				" bad custom config:" " use default"));
9193859Sml29623 
9203859Sml29623 			for (port = 0; port < num_ports; port++) {
9213859Sml29623 				custom_num_tdc[port] = (num_ports == 4) ?
9223859Sml29623 					p4_tx_fair[port] : p2_tx_fair[port];
9233859Sml29623 				custom_start_tdc[port] = start_tdc;
9243859Sml29623 				start_tdc += custom_num_tdc[port];
9253859Sml29623 			}
9263859Sml29623 		}
9273859Sml29623 		break;
9283859Sml29623 
9293859Sml29623 	default:
9303859Sml29623 		/* use default config */
9313859Sml29623 		cfg_prop = "fair";
9323859Sml29623 		for (port = 0; port < num_ports; port++) {
9333859Sml29623 			custom_num_tdc[port] = (num_ports == 4) ?
9343859Sml29623 				p4_tx_fair[port] : p2_tx_fair[port];
9353859Sml29623 			custom_start_tdc[port] = start_tdc;
9363859Sml29623 			start_tdc += custom_num_tdc[port];
9373859Sml29623 		}
9383859Sml29623 		break;
9393859Sml29623 	}
9403859Sml29623 
9413859Sml29623 	/* Now Update the tx properties */
9423859Sml29623 	for (port = 0; port < num_ports; port++) {
9433859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9443859Sml29623 			" update property txdma-cfg with %s ", cfg_prop));
9453859Sml29623 		ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
9463859Sml29623 			"txdma-cfg", cfg_prop);
9473859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
9483859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9493859Sml29623 				" property txdma-cfg is not updating to %s",
9503859Sml29623 				cfg_prop));
9513859Sml29623 			status |= NXGE_DDI_FAILED;
9523859Sml29623 		}
9533859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
9543859Sml29623 			num_tdc_prop, custom_num_tdc[port]));
9553859Sml29623 
9563859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
9573859Sml29623 			num_tdc_prop, custom_num_tdc[port]);
9583859Sml29623 
9593859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
9603859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
9613859Sml29623 				" property %s not updating with %d",
9623859Sml29623 				num_tdc_prop,
9633859Sml29623 				custom_num_tdc[port]));
9643859Sml29623 			status |= NXGE_DDI_FAILED;
9653859Sml29623 		}
9663859Sml29623 
9673859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
9683859Sml29623 			start_tdc_prop, custom_start_tdc[port]));
9693859Sml29623 
9703859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
9713859Sml29623 			start_tdc_prop, custom_start_tdc[port]);
9723859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
9733859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
9743859Sml29623 				" property %s not updating with %d ",
9753859Sml29623 				start_tdc_prop, custom_start_tdc[port]));
9763859Sml29623 			status |= NXGE_DDI_FAILED;
9773859Sml29623 		}
9783859Sml29623 	}
9793859Sml29623 	if (status & NXGE_DDI_FAILED)
9803859Sml29623 		status |= NXGE_ERROR;
9813859Sml29623 	return (status);
9823859Sml29623 }
9833859Sml29623 
9843859Sml29623 static nxge_status_t
9853859Sml29623 nxge_update_cfg_properties(p_nxge_t nxgep, uint32_t flags,
9863859Sml29623 	config_token_t token, dev_info_t *s_dip[])
9873859Sml29623 {
9883859Sml29623 	nxge_status_t status = NXGE_OK;
9893859Sml29623 
9903859Sml29623 	switch (flags) {
9913859Sml29623 	case COMMON_TXDMA_CFG:
9923859Sml29623 		if (nxge_dma_obp_props_only == 0)
9933859Sml29623 			status = nxge_update_txdma_properties(nxgep,
9943859Sml29623 				token, s_dip);
9953859Sml29623 		break;
9963859Sml29623 	case COMMON_RXDMA_CFG:
9973859Sml29623 		if (nxge_dma_obp_props_only == 0)
9983859Sml29623 			status = nxge_update_rxdma_properties(nxgep,
9993859Sml29623 				token, s_dip);
10003859Sml29623 
10013859Sml29623 		break;
10023859Sml29623 	case COMMON_RXDMA_GRP_CFG:
10033859Sml29623 		status = nxge_update_rxdma_grp_properties(nxgep,
10043859Sml29623 			token, s_dip);
10053859Sml29623 		break;
10063859Sml29623 	default:
10073859Sml29623 		return (NXGE_ERROR);
10083859Sml29623 	}
10093859Sml29623 	return (status);
10103859Sml29623 }
10113859Sml29623 
10123859Sml29623 /*
10133859Sml29623  * verify consistence.
10143859Sml29623  * (May require publishing the properties on all the ports.
10153859Sml29623  *
10163859Sml29623  * What if properties are published on function 0 device only?
10173859Sml29623  *
10183859Sml29623  *
10193859Sml29623  * rxdma-cfg, txdma-cfg, rxdma-grp-cfg (required )
10203859Sml29623  * What about class configs?
10213859Sml29623  *
10223859Sml29623  * If consistent, update the property on all the siblings.
10233859Sml29623  * set  a flag on hardware shared register
10243859Sml29623  * The rest of the siblings will check the flag
10253859Sml29623  * if the flag is set, they will use the updated property
10263859Sml29623  * without doing any validation.
10273859Sml29623  */
10283859Sml29623 
10293859Sml29623 nxge_status_t
10303859Sml29623 nxge_cfg_verify_set_classify_prop(p_nxge_t nxgep, char *prop,
10313859Sml29623 	uint64_t known_cfg, uint32_t override, dev_info_t *c_dip[])
10323859Sml29623 {
10333859Sml29623 	nxge_status_t status = NXGE_OK;
10343859Sml29623 	int ddi_status = DDI_SUCCESS;
10353859Sml29623 	int i = 0, found = 0, update_prop = B_TRUE;
10363859Sml29623 	int *cfg_val;
10373859Sml29623 	uint_t new_value, cfg_value[MAX_SIBLINGS];
10383859Sml29623 	uint_t prop_len;
10393859Sml29623 	uint_t known_cfg_value;
10403859Sml29623 
10413859Sml29623 	known_cfg_value = (uint_t)known_cfg;
10423859Sml29623 
10433859Sml29623 	if (override == B_TRUE) {
10443859Sml29623 		new_value = known_cfg_value;
10453859Sml29623 		for (i = 0; i < nxgep->nports; i++) {
10463859Sml29623 			ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE,
10473859Sml29623 				c_dip[i], prop, new_value);
10483859Sml29623 #ifdef NXGE_DEBUG_ERROR
10493859Sml29623 			if (ddi_status != DDI_PROP_SUCCESS)
10503859Sml29623 				NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
10513859Sml29623 					" property %s failed update ", prop));
10523859Sml29623 #endif
10533859Sml29623 		}
10543859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS)
10553859Sml29623 			return (NXGE_ERROR | NXGE_DDI_FAILED);
10563859Sml29623 	}
10573859Sml29623 	for (i = 0; i < nxgep->nports; i++) {
10583859Sml29623 		cfg_value[i] = known_cfg_value;
10593859Sml29623 		if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, c_dip[i], 0,
10603859Sml29623 				prop, &cfg_val,
10613859Sml29623 				&prop_len) == DDI_PROP_SUCCESS) {
10623859Sml29623 			cfg_value[i] = *cfg_val;
10633859Sml29623 			ddi_prop_free(cfg_val);
10643859Sml29623 			found++;
10653859Sml29623 		}
10663859Sml29623 	}
10673859Sml29623 
10683859Sml29623 	if (found != i) {
10693859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10703859Sml29623 			" property %s not specified on all ports", prop));
10713859Sml29623 		if (found == 0) {
10723859Sml29623 			/* not specified: Use default */
10733859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10743859Sml29623 				" property %s not specified on any port:"
10753859Sml29623 				" Using default", prop));
10763859Sml29623 			new_value = known_cfg_value;
10773859Sml29623 		} else {
10783859Sml29623 			/* specified on some */
10793859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10803859Sml29623 				" property %s not specified"
10813859Sml29623 				" on some ports: Using default", prop));
10823859Sml29623 			/* ? use p0 value instead ? */
10833859Sml29623 			new_value = known_cfg_value;
10843859Sml29623 		}
10853859Sml29623 	} else {
10863859Sml29623 		/* check type and consistence */
10873859Sml29623 		/* found on all devices */
10883859Sml29623 		for (i = 1; i < found; i++) {
10893859Sml29623 			if (cfg_value[i] != cfg_value[i - 1]) {
10903859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10913859Sml29623 					" property %s inconsistent:"
10923859Sml29623 					" Using default", prop));
10933859Sml29623 				new_value = known_cfg_value;
10943859Sml29623 				break;
10953859Sml29623 			}
10963859Sml29623 			/*
10973859Sml29623 			 * Found on all the ports and consistent. Nothing to
10983859Sml29623 			 * do.
10993859Sml29623 			 */
11003859Sml29623 			update_prop = B_FALSE;
11013859Sml29623 		}
11023859Sml29623 	}
11033859Sml29623 
11043859Sml29623 	if (update_prop == B_TRUE) {
11053859Sml29623 		for (i = 0; i < nxgep->nports; i++) {
11063859Sml29623 			ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE,
11073859Sml29623 				c_dip[i], prop, new_value);
11083859Sml29623 #ifdef NXGE_DEBUG_ERROR
11093859Sml29623 			if (ddi_status != DDI_SUCCESS)
11103859Sml29623 				NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
11113859Sml29623 					" property %s not updating with %d"
11123859Sml29623 					" Using default",
11133859Sml29623 					prop, new_value));
11143859Sml29623 #endif
11153859Sml29623 			if (ddi_status != DDI_PROP_SUCCESS)
11163859Sml29623 				status |= NXGE_DDI_FAILED;
11173859Sml29623 		}
11183859Sml29623 	}
11193859Sml29623 	if (status & NXGE_DDI_FAILED)
11203859Sml29623 		status |= NXGE_ERROR;
11213859Sml29623 
11223859Sml29623 	return (status);
11233859Sml29623 }
11243859Sml29623 
11253859Sml29623 static uint64_t
11263859Sml29623 nxge_class_get_known_cfg(p_nxge_t nxgep, int class_prop, int rx_quick_cfg)
11273859Sml29623 {
11283859Sml29623 	int start_prop;
11293859Sml29623 	uint64_t cfg_value;
11303859Sml29623 	p_nxge_param_t param_arr;
11313859Sml29623 
11323859Sml29623 	param_arr = nxgep->param_arr;
11333859Sml29623 	cfg_value = param_arr[class_prop].value;
11343859Sml29623 	start_prop = param_h1_init_value;
11353859Sml29623 
11363859Sml29623 	/* update the properties per quick config */
11373859Sml29623 	switch (rx_quick_cfg) {
11383859Sml29623 	case CFG_L3_WEB:
11393859Sml29623 	case CFG_L3_DISTRIBUTE:
11403859Sml29623 		cfg_value = nxge_classify_get_cfg_value(nxgep,
11413859Sml29623 			rx_quick_cfg, class_prop - start_prop);
11423859Sml29623 		break;
11433859Sml29623 	default:
11443859Sml29623 		cfg_value = param_arr[class_prop].value;
11453859Sml29623 		break;
11463859Sml29623 	}
11473859Sml29623 	return (cfg_value);
11483859Sml29623 }
11493859Sml29623 
11503859Sml29623 static nxge_status_t
11513859Sml29623 nxge_cfg_verify_set_classify(p_nxge_t nxgep, dev_info_t *c_dip[])
11523859Sml29623 {
11533859Sml29623 	nxge_status_t status = NXGE_OK;
11543859Sml29623 	int rx_quick_cfg, class_prop, start_prop, end_prop;
11553859Sml29623 	char *prop_name;
11563859Sml29623 	int override = B_TRUE;
11573859Sml29623 	uint64_t cfg_value;
11583859Sml29623 	p_nxge_param_t param_arr;
11593859Sml29623 
11603859Sml29623 	param_arr = nxgep->param_arr;
11613859Sml29623 	rx_quick_cfg = param_arr[param_rx_quick_cfg].value;
11623859Sml29623 	start_prop = param_h1_init_value;
11633859Sml29623 	end_prop = param_class_opt_ipv6_sctp;
11643859Sml29623 
11653859Sml29623 	/* update the properties per quick config */
11663859Sml29623 	if (rx_quick_cfg == CFG_NOT_SPECIFIED)
11673859Sml29623 		override = B_FALSE;
11683859Sml29623 
11693859Sml29623 	/*
11703859Sml29623 	 * these parameter affect the classification outcome.
11713859Sml29623 	 * these parameters are used to configure the Flow key and
11723859Sml29623 	 * the TCAM key for each of the IP classes.
11733859Sml29623 	 * Included here are also the H1 and H2 initial values
11743859Sml29623 	 * which affect the distribution as well as final hash value
11753859Sml29623 	 * (hence the offset into RDC table and FCRAM bucket location)
11763859Sml29623 	 *
11773859Sml29623 	 */
11783859Sml29623 	for (class_prop = start_prop; class_prop <= end_prop; class_prop++) {
11793859Sml29623 		prop_name = param_arr[class_prop].fcode_name;
11803859Sml29623 		cfg_value = nxge_class_get_known_cfg(nxgep,
11813859Sml29623 			class_prop, rx_quick_cfg);
11823859Sml29623 		status = nxge_cfg_verify_set_classify_prop(nxgep, prop_name,
11833859Sml29623 			cfg_value, override, c_dip);
11843859Sml29623 	}
11853859Sml29623 
11863859Sml29623 	/*
11873859Sml29623 	 * these properties do not affect the actual classification outcome.
11883859Sml29623 	 * used to enable/disable or tune the fflp hardware
11893859Sml29623 	 *
11903859Sml29623 	 * fcram_access_ratio, tcam_access_ratio, tcam_enable, llc_snap_enable
11913859Sml29623 	 *
11923859Sml29623 	 */
11933859Sml29623 	override = B_FALSE;
11943859Sml29623 	for (class_prop = param_fcram_access_ratio;
11953859Sml29623 			class_prop <= param_llc_snap_enable; class_prop++) {
11963859Sml29623 		prop_name = param_arr[class_prop].fcode_name;
11973859Sml29623 		cfg_value = param_arr[class_prop].value;
11983859Sml29623 		status = nxge_cfg_verify_set_classify_prop(nxgep, prop_name,
11993859Sml29623 			cfg_value, override, c_dip);
12003859Sml29623 	}
12013859Sml29623 
12023859Sml29623 	return (status);
12033859Sml29623 }
12043859Sml29623 
12053859Sml29623 nxge_status_t
12063859Sml29623 nxge_cfg_verify_set(p_nxge_t nxgep, uint32_t flag)
12073859Sml29623 {
12083859Sml29623 	nxge_status_t status = NXGE_OK;
12093859Sml29623 	int i = 0, found = 0;
12103859Sml29623 	int num_siblings;
12113859Sml29623 	dev_info_t *c_dip[MAX_SIBLINGS + 1];
12123859Sml29623 	char *prop_val[MAX_SIBLINGS];
12133859Sml29623 	config_token_t c_token[MAX_SIBLINGS];
12143859Sml29623 	char *prop;
12153859Sml29623 
12163859Sml29623 	if (nxge_dma_obp_props_only)
12173859Sml29623 		return (NXGE_OK);
12183859Sml29623 
12193859Sml29623 	num_siblings = 0;
12203859Sml29623 	c_dip[num_siblings] = ddi_get_child(nxgep->p_dip);
12213859Sml29623 	while (c_dip[num_siblings]) {
12223859Sml29623 		c_dip[num_siblings + 1] =
12233859Sml29623 			ddi_get_next_sibling(c_dip[num_siblings]);
12243859Sml29623 		num_siblings++;
12253859Sml29623 	}
12263859Sml29623 
12273859Sml29623 	switch (flag) {
12283859Sml29623 	case COMMON_TXDMA_CFG:
12293859Sml29623 		prop = "txdma-cfg";
12303859Sml29623 		break;
12313859Sml29623 	case COMMON_RXDMA_CFG:
12323859Sml29623 		prop = "rxdma-cfg";
12333859Sml29623 		break;
12343859Sml29623 	case COMMON_RXDMA_GRP_CFG:
12353859Sml29623 		prop = "rxdma-grp-cfg";
12363859Sml29623 		break;
12373859Sml29623 	case COMMON_CLASS_CFG:
12383859Sml29623 		status = nxge_cfg_verify_set_classify(nxgep, c_dip);
12393859Sml29623 		return (status);
12403859Sml29623 	default:
12413859Sml29623 		return (NXGE_ERROR);
12423859Sml29623 	}
12433859Sml29623 
12443859Sml29623 	i = 0;
12453859Sml29623 	while (i < num_siblings) {
12463859Sml29623 		if (ddi_prop_lookup_string(DDI_DEV_T_ANY, c_dip[i], 0, prop,
12473859Sml29623 				(char **)&prop_val[i]) == DDI_PROP_SUCCESS) {
12483859Sml29623 			c_token[i] = nxge_get_config_token(prop_val[i]);
12493859Sml29623 			ddi_prop_free(prop_val[i]);
12503859Sml29623 			found++;
12513859Sml29623 		} else
12523859Sml29623 			c_token[i] = CONFIG_TOKEN_NONE;
12533859Sml29623 		i++;
12543859Sml29623 	}
12553859Sml29623 
12563859Sml29623 	if (found != i) {
12573859Sml29623 		if (found == 0) {
12583859Sml29623 			/* not specified: Use default */
12593859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
12603859Sml29623 				" property %s not specified on any port:"
12613859Sml29623 					" Using default", prop));
12623859Sml29623 
12633859Sml29623 			status = nxge_update_cfg_properties(nxgep,
12643859Sml29623 				flag, FAIR, c_dip);
12653859Sml29623 			return (status);
12663859Sml29623 		} else {
12673859Sml29623 			/*
12683859Sml29623 			 * if  the convention is to use function 0 device then
12693859Sml29623 			 * populate the other devices with this configuration.
12703859Sml29623 			 *
12713859Sml29623 			 * The other alternative is to use the default config.
12723859Sml29623 			 */
12733859Sml29623 			/* not specified: Use default */
12743859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
12753859Sml29623 				" property %s not specified on some ports:"
12763859Sml29623 				" Using default", prop));
12773859Sml29623 			status = nxge_update_cfg_properties(nxgep,
12783859Sml29623 				flag, FAIR, c_dip);
12793859Sml29623 			return (status);
12803859Sml29623 		}
12813859Sml29623 	}
12823859Sml29623 
12833859Sml29623 	/* check type and consistence */
12843859Sml29623 	/* found on all devices */
12853859Sml29623 	for (i = 1; i < found; i++) {
12863859Sml29623 		if (c_token[i] != c_token[i - 1]) {
12873859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
12883859Sml29623 				" property %s inconsistent:"
12893859Sml29623 				" Using default", prop));
12903859Sml29623 			status = nxge_update_cfg_properties(nxgep,
12913859Sml29623 				flag, FAIR, c_dip);
12923859Sml29623 			return (status);
12933859Sml29623 		}
12943859Sml29623 	}
12953859Sml29623 
12963859Sml29623 	/*
12973859Sml29623 	 * Found on all the ports check if it is custom configuration. if
12983859Sml29623 	 * custom, then verify consistence
12993859Sml29623 	 *
13003859Sml29623 	 * finally create soft properties
13013859Sml29623 	 */
13023859Sml29623 	status = nxge_update_cfg_properties(nxgep, flag, c_token[0], c_dip);
13033859Sml29623 	return (status);
13043859Sml29623 }
13053859Sml29623 
13063859Sml29623 nxge_status_t
13073859Sml29623 nxge_cfg_verify_set_quick_config(p_nxge_t nxgep)
13083859Sml29623 {
13093859Sml29623 	nxge_status_t status = NXGE_OK;
13103859Sml29623 	int ddi_status = DDI_SUCCESS;
13113859Sml29623 	char *prop_val;
13123859Sml29623 	char *rx_prop;
13133859Sml29623 	char *prop;
13143859Sml29623 	uint32_t cfg_value = CFG_NOT_SPECIFIED;
13153859Sml29623 	p_nxge_param_t param_arr;
13163859Sml29623 
13173859Sml29623 	param_arr = nxgep->param_arr;
13183859Sml29623 	rx_prop = param_arr[param_rx_quick_cfg].fcode_name;
13193859Sml29623 
13203859Sml29623 	prop = "rx-quick-cfg";
13213859Sml29623 
13223859Sml29623 	/*
13233859Sml29623 	 * good value are
13243859Sml29623 	 *
13253859Sml29623 	 * "web-server" "generic-server" "l3-classify" "flow-classify"
13263859Sml29623 	 */
13273859Sml29623 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, nxgep->dip, 0,
13283859Sml29623 			prop, (char **)&prop_val) != DDI_PROP_SUCCESS) {
13293859Sml29623 		NXGE_DEBUG_MSG((nxgep, VPD_CTL,
13303859Sml29623 			" property %s not specified: using default ", prop));
13313859Sml29623 		cfg_value = CFG_NOT_SPECIFIED;
13323859Sml29623 	} else {
13333859Sml29623 		cfg_value = CFG_L3_DISTRIBUTE;
13343859Sml29623 		if (strncmp("web-server", (caddr_t)prop_val, 8) == 0) {
13353859Sml29623 			cfg_value = CFG_L3_WEB;
13363859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
13373859Sml29623 				" %s: web server ", prop));
13383859Sml29623 		}
13393859Sml29623 		if (strncmp("generic-server", (caddr_t)prop_val, 8) == 0) {
13403859Sml29623 			cfg_value = CFG_L3_DISTRIBUTE;
13413859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
13423859Sml29623 				" %s: distribute ", prop));
13433859Sml29623 		}
13443859Sml29623 		/* more */
13453859Sml29623 		ddi_prop_free(prop_val);
13463859Sml29623 	}
13473859Sml29623 
13483859Sml29623 	ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
13493859Sml29623 		rx_prop, cfg_value);
13503859Sml29623 	if (ddi_status != DDI_PROP_SUCCESS)
13513859Sml29623 		status |= NXGE_DDI_FAILED;
13523859Sml29623 
13533859Sml29623 	/* now handle specified cases: */
13543859Sml29623 	if (status & NXGE_DDI_FAILED)
13553859Sml29623 		status |= NXGE_ERROR;
13563859Sml29623 	return (status);
13573859Sml29623 }
13583859Sml29623 
1359*6835Syc148097 /*
1360*6835Syc148097  * Device properties adv-autoneg-cap etc are defined by FWARC
1361*6835Syc148097  * http://sac.sfbay/FWARC/2002/345/20020610_asif.haswarey
1362*6835Syc148097  */
13633859Sml29623 static void
13643859Sml29623 nxge_use_cfg_link_cfg(p_nxge_t nxgep)
13653859Sml29623 {
13663859Sml29623 	int *prop_val;
13673859Sml29623 	uint_t prop_len;
13683859Sml29623 	dev_info_t *dip;
13693859Sml29623 	int speed;
13703859Sml29623 	int duplex;
13713859Sml29623 	int adv_autoneg_cap;
13723859Sml29623 	int adv_10gfdx_cap;
13733859Sml29623 	int adv_10ghdx_cap;
13743859Sml29623 	int adv_1000fdx_cap;
13753859Sml29623 	int adv_1000hdx_cap;
13763859Sml29623 	int adv_100fdx_cap;
13773859Sml29623 	int adv_100hdx_cap;
13783859Sml29623 	int adv_10fdx_cap;
13793859Sml29623 	int adv_10hdx_cap;
13803859Sml29623 	int status = DDI_SUCCESS;
13813859Sml29623 
13823859Sml29623 	dip = nxgep->dip;
13833859Sml29623 
13843859Sml29623 	/*
13853859Sml29623 	 * first find out the card type and the supported link speeds and
13863859Sml29623 	 * features
13873859Sml29623 	 */
13883859Sml29623 	/* add code for card type */
13893859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-autoneg-cap",
13903859Sml29623 			&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
13913859Sml29623 		ddi_prop_free(prop_val);
13923859Sml29623 		return;
13933859Sml29623 	}
13943859Sml29623 
13953859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10gfdx-cap",
13963859Sml29623 			&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-1000hdx-cap",
14023859Sml29623 			&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-1000fdx-cap",
14083859Sml29623 			&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-100fdx-cap",
14143859Sml29623 			&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-100hdx-cap",
14203859Sml29623 			&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-10fdx-cap",
14263859Sml29623 			&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-10hdx-cap",
14323859Sml29623 			&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14333859Sml29623 		ddi_prop_free(prop_val);
14343859Sml29623 		return;
14353859Sml29623 	}
14363859Sml29623 
14373859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0, "speed",
14383859Sml29623 			(uchar_t **)&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14393859Sml29623 		if (strncmp("10000", (caddr_t)prop_val,
14403859Sml29623 				(size_t)prop_len) == 0) {
14413859Sml29623 			speed = 10000;
14423859Sml29623 		} else if (strncmp("1000", (caddr_t)prop_val,
14433859Sml29623 				(size_t)prop_len) == 0) {
14443859Sml29623 			speed = 1000;
14453859Sml29623 		} else if (strncmp("100", (caddr_t)prop_val,
14463859Sml29623 				(size_t)prop_len) == 0) {
14473859Sml29623 			speed = 100;
14483859Sml29623 		} else if (strncmp("10", (caddr_t)prop_val,
14493859Sml29623 				(size_t)prop_len) == 0) {
14503859Sml29623 			speed = 10;
14513859Sml29623 		} else if (strncmp("auto", (caddr_t)prop_val,
14523859Sml29623 				(size_t)prop_len) == 0) {
14533859Sml29623 			speed = 0;
14543859Sml29623 		} else {
14553859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_NOTE,
14563859Sml29623 				"speed property is invalid reverting to auto"));
14573859Sml29623 			speed = 0;
14583859Sml29623 		}
14593859Sml29623 		ddi_prop_free(prop_val);
14603859Sml29623 	} else
14613859Sml29623 		speed = 0;
14623859Sml29623 
14633859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0, "duplex",
14643859Sml29623 			(uchar_t **)&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14653859Sml29623 		if (strncmp("full", (caddr_t)prop_val,
14663859Sml29623 				(size_t)prop_len) == 0) {
14673859Sml29623 			duplex = 2;
14683859Sml29623 		} else if (strncmp("half", (caddr_t)prop_val,
14693859Sml29623 				(size_t)prop_len) == 0) {
14703859Sml29623 			duplex = 1;
14713859Sml29623 		} else if (strncmp("auto", (caddr_t)prop_val,
14723859Sml29623 				(size_t)prop_len) == 0) {
14733859Sml29623 			duplex = 0;
14743859Sml29623 		} else {
14753859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_NOTE,
14763859Sml29623 				"duplex property is invalid"
14773859Sml29623 				" reverting to auto"));
14783859Sml29623 			duplex = 0;
14793859Sml29623 		}
14803859Sml29623 		ddi_prop_free(prop_val);
14813859Sml29623 	} else
14823859Sml29623 		duplex = 0;
14833859Sml29623 
1484*6835Syc148097 	/* speed == 0 or duplex == 0 means auto negotiation. */
14853859Sml29623 	adv_autoneg_cap = (speed == 0) || (duplex == 0);
14863859Sml29623 	if (adv_autoneg_cap == 0) {
14873859Sml29623 		adv_10gfdx_cap = ((speed == 10000) && (duplex == 2));
14883859Sml29623 		adv_10ghdx_cap = adv_10gfdx_cap;
14893859Sml29623 		adv_10ghdx_cap |= ((speed == 10000) && (duplex == 1));
14903859Sml29623 		adv_1000fdx_cap = adv_10ghdx_cap;
14913859Sml29623 		adv_1000fdx_cap |= ((speed == 1000) && (duplex == 2));
14923859Sml29623 		adv_1000hdx_cap = adv_1000fdx_cap;
14933859Sml29623 		adv_1000hdx_cap |= ((speed == 1000) && (duplex == 1));
14943859Sml29623 		adv_100fdx_cap = adv_1000hdx_cap;
14953859Sml29623 		adv_100fdx_cap |= ((speed == 100) && (duplex == 2));
14963859Sml29623 		adv_100hdx_cap = adv_100fdx_cap;
14973859Sml29623 		adv_100hdx_cap |= ((speed == 100) && (duplex == 1));
14983859Sml29623 		adv_10fdx_cap = adv_100hdx_cap;
14993859Sml29623 		adv_10fdx_cap |= ((speed == 10) && (duplex == 2));
15003859Sml29623 		adv_10hdx_cap = adv_10fdx_cap;
15013859Sml29623 		adv_10hdx_cap |= ((speed == 10) && (duplex == 1));
15023859Sml29623 	} else if (speed == 0) {
15033859Sml29623 		adv_10gfdx_cap = (duplex == 2);
15043859Sml29623 		adv_10ghdx_cap = (duplex == 1);
15053859Sml29623 		adv_1000fdx_cap = (duplex == 2);
15063859Sml29623 		adv_1000hdx_cap = (duplex == 1);
15073859Sml29623 		adv_100fdx_cap = (duplex == 2);
15083859Sml29623 		adv_100hdx_cap = (duplex == 1);
15093859Sml29623 		adv_10fdx_cap = (duplex == 2);
15103859Sml29623 		adv_10hdx_cap = (duplex == 1);
15113859Sml29623 	}
15123859Sml29623 	if (duplex == 0) {
15133859Sml29623 		adv_10gfdx_cap = (speed == 0);
15143859Sml29623 		adv_10gfdx_cap |= (speed == 10000);
15153859Sml29623 		adv_10ghdx_cap = adv_10gfdx_cap;
15163859Sml29623 		adv_10ghdx_cap |= (speed == 10000);
15173859Sml29623 		adv_1000fdx_cap = adv_10ghdx_cap;
15183859Sml29623 		adv_1000fdx_cap |= (speed == 1000);
15193859Sml29623 		adv_1000hdx_cap = adv_1000fdx_cap;
15203859Sml29623 		adv_1000hdx_cap |= (speed == 1000);
15213859Sml29623 		adv_100fdx_cap = adv_1000hdx_cap;
15223859Sml29623 		adv_100fdx_cap |= (speed == 100);
15233859Sml29623 		adv_100hdx_cap = adv_100fdx_cap;
15243859Sml29623 		adv_100hdx_cap |= (speed == 100);
15253859Sml29623 		adv_10fdx_cap = adv_100hdx_cap;
15263859Sml29623 		adv_10fdx_cap |= (speed == 10);
15273859Sml29623 		adv_10hdx_cap = adv_10fdx_cap;
15283859Sml29623 		adv_10hdx_cap |= (speed == 10);
15293859Sml29623 	}
15303859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15313859Sml29623 		"adv-autoneg-cap", &adv_autoneg_cap, 1);
15323859Sml29623 	if (status)
15333859Sml29623 		return;
15343859Sml29623 
15353859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15363859Sml29623 		"adv-10gfdx-cap", &adv_10gfdx_cap, 1);
15373859Sml29623 	if (status)
15383859Sml29623 		goto nxge_map_myargs_to_gmii_fail1;
15393859Sml29623 
15403859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15413859Sml29623 		"adv-10ghdx-cap", &adv_10ghdx_cap, 1);
15423859Sml29623 	if (status)
15433859Sml29623 		goto nxge_map_myargs_to_gmii_fail2;
15443859Sml29623 
15453859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15463859Sml29623 		"adv-1000fdx-cap", &adv_1000fdx_cap, 1);
15473859Sml29623 	if (status)
15483859Sml29623 		goto nxge_map_myargs_to_gmii_fail3;
15493859Sml29623 
15503859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15513859Sml29623 		"adv-1000hdx-cap", &adv_1000hdx_cap, 1);
15523859Sml29623 	if (status)
15533859Sml29623 		goto nxge_map_myargs_to_gmii_fail4;
15543859Sml29623 
15553859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15563859Sml29623 		"adv-100fdx-cap", &adv_100fdx_cap, 1);
15573859Sml29623 	if (status)
15583859Sml29623 		goto nxge_map_myargs_to_gmii_fail5;
15593859Sml29623 
15603859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15613859Sml29623 		"adv-100hdx-cap", &adv_100hdx_cap, 1);
15623859Sml29623 	if (status)
15633859Sml29623 		goto nxge_map_myargs_to_gmii_fail6;
15643859Sml29623 
15653859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15663859Sml29623 		"adv-10fdx-cap", &adv_10fdx_cap, 1);
15673859Sml29623 	if (status)
15683859Sml29623 		goto nxge_map_myargs_to_gmii_fail7;
15693859Sml29623 
15703859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15713859Sml29623 		"adv-10hdx-cap", &adv_10hdx_cap, 1);
15723859Sml29623 	if (status)
15733859Sml29623 		goto nxge_map_myargs_to_gmii_fail8;
15743859Sml29623 
15753859Sml29623 	return;
15763859Sml29623 
15773859Sml29623 nxge_map_myargs_to_gmii_fail9:
15783859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10hdx-cap");
15793859Sml29623 
15803859Sml29623 nxge_map_myargs_to_gmii_fail8:
15813859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10fdx-cap");
15823859Sml29623 
15833859Sml29623 nxge_map_myargs_to_gmii_fail7:
15843859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-100hdx-cap");
15853859Sml29623 
15863859Sml29623 nxge_map_myargs_to_gmii_fail6:
15873859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-100fdx-cap");
15883859Sml29623 
15893859Sml29623 nxge_map_myargs_to_gmii_fail5:
15903859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-1000hdx-cap");
15913859Sml29623 
15923859Sml29623 nxge_map_myargs_to_gmii_fail4:
15933859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-1000fdx-cap");
15943859Sml29623 
15953859Sml29623 nxge_map_myargs_to_gmii_fail3:
15963859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10ghdx-cap");
15973859Sml29623 
15983859Sml29623 nxge_map_myargs_to_gmii_fail2:
15993859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10gfdx-cap");
16003859Sml29623 
16013859Sml29623 nxge_map_myargs_to_gmii_fail1:
16023859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-autoneg-cap");
16033859Sml29623 }
16043859Sml29623 
16053859Sml29623 nxge_status_t
16063859Sml29623 nxge_get_config_properties(p_nxge_t nxgep)
16073859Sml29623 {
16083859Sml29623 	nxge_status_t status = NXGE_OK;
16093859Sml29623 	p_nxge_hw_list_t hw_p;
16103859Sml29623 
16113859Sml29623 	NXGE_DEBUG_MSG((nxgep, VPD_CTL, " ==> nxge_get_config_properties"));
16123859Sml29623 
16133859Sml29623 	if ((hw_p = nxgep->nxge_hw_p) == NULL) {
16143859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
16153859Sml29623 			" nxge_get_config_properties:"
16163859Sml29623 			" common hardware not set", nxgep->niu_type));
16173859Sml29623 		return (NXGE_ERROR);
16183859Sml29623 	}
16193859Sml29623 
16203859Sml29623 	/*
16213859Sml29623 	 * Get info on how many ports Neptune card has.
16223859Sml29623 	 */
16234977Sraghus 	nxgep->nports = nxge_get_nports(nxgep);
16244732Sdavemq 	if (nxgep->nports <= 0) {
16254732Sdavemq 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
16264732Sdavemq 		    "<==nxge_get_config_properties: Invalid Neptune type 0x%x",
16274732Sdavemq 		    nxgep->niu_type));
16284732Sdavemq 		return (NXGE_ERROR);
16294732Sdavemq 	}
16304732Sdavemq 	nxgep->classifier.tcam_size = TCAM_NIU_TCAM_MAX_ENTRY;
16314977Sraghus 	if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
16324977Sraghus 		nxgep->classifier.tcam_size = TCAM_NXGE_TCAM_MAX_ENTRY;
16334977Sraghus 	}
16344732Sdavemq 	if (nxgep->function_num >= nxgep->nports) {
16354732Sdavemq 		return (NXGE_ERROR);
16363859Sml29623 	}
16373859Sml29623 
16383859Sml29623 	status = nxge_get_mac_addr_properties(nxgep);
16393859Sml29623 	if (status != NXGE_OK)
16403859Sml29623 		return (NXGE_ERROR);
16413859Sml29623 
16423859Sml29623 	/*
16433859Sml29623 	 * read the configuration type. If none is specified, used default.
16443859Sml29623 	 * Config types: equal: (default) DMA channels, RDC groups, TCAM, FCRAM
16453859Sml29623 	 * are shared equally across all the ports.
16463859Sml29623 	 *
16473859Sml29623 	 * Fair: DMA channels, RDC groups, TCAM, FCRAM are shared proportional
16483859Sml29623 	 * to the port speed.
16493859Sml29623 	 *
16503859Sml29623 	 *
16513859Sml29623 	 * custom: DMA channels, RDC groups, TCAM, FCRAM partition is
16523859Sml29623 	 * specified in nxge.conf. Need to read each parameter and set
16533859Sml29623 	 * up the parameters in nxge structures.
16543859Sml29623 	 *
16553859Sml29623 	 */
16563859Sml29623 	switch (nxgep->niu_type) {
16573859Sml29623 	case N2_NIU:
16583859Sml29623 		NXGE_DEBUG_MSG((nxgep, VPD_CTL,
16593859Sml29623 			" ==> nxge_get_config_properties: N2"));
16603859Sml29623 		MUTEX_ENTER(&hw_p->nxge_cfg_lock);
16613859Sml29623 		if ((hw_p->flags & COMMON_CFG_VALID) !=
16623859Sml29623 			COMMON_CFG_VALID) {
16633859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16643859Sml29623 				COMMON_RXDMA_GRP_CFG);
16653859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16663859Sml29623 				COMMON_CLASS_CFG);
16673859Sml29623 			hw_p->flags |= COMMON_CFG_VALID;
16683859Sml29623 		}
16693859Sml29623 		MUTEX_EXIT(&hw_p->nxge_cfg_lock);
16703859Sml29623 		status = nxge_use_cfg_n2niu_properties(nxgep);
16713859Sml29623 		break;
16724732Sdavemq 	default:
16734977Sraghus 		if (!NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
16744732Sdavemq 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
16754732Sdavemq 			    " nxge_get_config_properties:"
16764732Sdavemq 			    " unknown NIU type 0x%x", nxgep->niu_type));
16774732Sdavemq 			return (NXGE_ERROR);
16784732Sdavemq 		}
16794732Sdavemq 
16803859Sml29623 		NXGE_DEBUG_MSG((nxgep, VPD_CTL,
16813859Sml29623 			" ==> nxge_get_config_properties: Neptune"));
16823859Sml29623 		status = nxge_cfg_verify_set_quick_config(nxgep);
16833859Sml29623 		MUTEX_ENTER(&hw_p->nxge_cfg_lock);
16843859Sml29623 		if ((hw_p->flags & COMMON_CFG_VALID) !=
16853859Sml29623 			COMMON_CFG_VALID) {
16863859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16873859Sml29623 				COMMON_TXDMA_CFG);
16883859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16893859Sml29623 				COMMON_RXDMA_CFG);
16903859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16913859Sml29623 				COMMON_RXDMA_GRP_CFG);
16923859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16933859Sml29623 				COMMON_CLASS_CFG);
16943859Sml29623 			hw_p->flags |= COMMON_CFG_VALID;
16953859Sml29623 		}
16963859Sml29623 		MUTEX_EXIT(&hw_p->nxge_cfg_lock);
16973859Sml29623 		nxge_use_cfg_neptune_properties(nxgep);
16983859Sml29623 		status = NXGE_OK;
16993859Sml29623 		break;
17003859Sml29623 	}
17013859Sml29623 
17026003Sml29623 	/*
17036003Sml29623 	 * Get the software LSO enable flag property from the
17046003Sml29623 	 * driver configuration file (nxge.conf).
17056003Sml29623 	 * This flag will be set to disable (0) if this property
17066003Sml29623 	 * does not exist.
17076003Sml29623 	 */
17086003Sml29623 	nxgep->soft_lso_enable = ddi_prop_get_int(DDI_DEV_T_ANY, nxgep->dip,
17096003Sml29623 	    DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "soft-lso-enable", 0);
17106003Sml29623 	NXGE_DEBUG_MSG((nxgep, VPD_CTL,
17116003Sml29623 	    "nxge_get_config_properties: software lso %d\n",
17126003Sml29623 	    nxgep->soft_lso_enable));
17136003Sml29623 
17143859Sml29623 	NXGE_DEBUG_MSG((nxgep, VPD_CTL, " <== nxge_get_config_properties"));
17153859Sml29623 	return (status);
17163859Sml29623 }
17173859Sml29623 
17183859Sml29623 static nxge_status_t
17193859Sml29623 nxge_use_cfg_n2niu_properties(p_nxge_t nxgep)
17203859Sml29623 {
17213859Sml29623 	nxge_status_t status = NXGE_OK;
17223859Sml29623 
17233859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_n2niu_properties"));
17243859Sml29623 
17253859Sml29623 	status = nxge_use_default_dma_config_n2(nxgep);
17263859Sml29623 	if (status != NXGE_OK) {
17273859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
17283859Sml29623 			" ==> nxge_use_cfg_n2niu_properties (err 0x%x)",
17293859Sml29623 			status));
17303859Sml29623 		return (status | NXGE_ERROR);
17313859Sml29623 	}
17323859Sml29623 
17333859Sml29623 	(void) nxge_use_cfg_vlan_class_config(nxgep);
17343859Sml29623 	(void) nxge_use_cfg_mac_class_config(nxgep);
17353859Sml29623 	(void) nxge_use_cfg_class_config(nxgep);
17363859Sml29623 	(void) nxge_use_cfg_link_cfg(nxgep);
17373859Sml29623 
17383859Sml29623 	/*
17393859Sml29623 	 * Read in the hardware (fcode) properties. Use the ndd array to read
17403859Sml29623 	 * each property.
17413859Sml29623 	 */
17423859Sml29623 	(void) nxge_get_param_soft_properties(nxgep);
17433859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_n2niu_properties"));
17443859Sml29623 
17453859Sml29623 	return (status);
17463859Sml29623 }
17473859Sml29623 
17483859Sml29623 static void
17493859Sml29623 nxge_use_cfg_neptune_properties(p_nxge_t nxgep)
17503859Sml29623 {
17513859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_neptune_properties"));
17523859Sml29623 
17533859Sml29623 	(void) nxge_use_cfg_dma_config(nxgep);
17543859Sml29623 	(void) nxge_use_cfg_vlan_class_config(nxgep);
17553859Sml29623 	(void) nxge_use_cfg_mac_class_config(nxgep);
17563859Sml29623 	(void) nxge_use_cfg_class_config(nxgep);
17573859Sml29623 	(void) nxge_use_cfg_link_cfg(nxgep);
17583859Sml29623 
17593859Sml29623 	/*
17603859Sml29623 	 * Read in the hardware (fcode) properties. Use the ndd array to read
17613859Sml29623 	 * each property.
17623859Sml29623 	 */
17633859Sml29623 	(void) nxge_get_param_soft_properties(nxgep);
17643859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_neptune_properties"));
17653859Sml29623 }
17663859Sml29623 
17673859Sml29623 /*
17683859Sml29623  * FWARC 2006/556
17693859Sml29623  */
17703859Sml29623 
17713859Sml29623 static nxge_status_t
17723859Sml29623 nxge_use_default_dma_config_n2(p_nxge_t nxgep)
17733859Sml29623 {
17743859Sml29623 	int ndmas;
17753859Sml29623 	uint8_t func;
17763859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
17773859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
17783859Sml29623 	int *prop_val;
17793859Sml29623 	uint_t prop_len;
17803859Sml29623 	int i;
17813859Sml29623 	nxge_status_t status = NXGE_OK;
17823859Sml29623 
17833859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2"));
17843859Sml29623 
17853859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
17863859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
17873859Sml29623 
17883859Sml29623 	func = nxgep->function_num;
17893859Sml29623 	p_cfgp->function_number = func;
17903859Sml29623 	ndmas = NXGE_TDMA_PER_NIU_PORT;
17913859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
17923859Sml29623 			"tx-dma-channels", (int **)&prop_val,
17933859Sml29623 			&prop_len) == DDI_PROP_SUCCESS) {
17946495Sspeer 		p_cfgp->tdc.start = prop_val[0];
17953859Sml29623 		NXGE_DEBUG_MSG((nxgep, OBP_CTL,
17963859Sml29623 			"==> nxge_use_default_dma_config_n2: tdc starts %d "
17976495Sspeer 			"(#%d)", p_cfgp->tdc.start, prop_len));
17983859Sml29623 
17993859Sml29623 		ndmas = prop_val[1];
18003859Sml29623 		NXGE_DEBUG_MSG((nxgep, OBP_CTL,
18013859Sml29623 			"==> nxge_use_default_dma_config_n2: #tdc %d (#%d)",
18023859Sml29623 			ndmas, prop_len));
18033859Sml29623 		ddi_prop_free(prop_val);
18043859Sml29623 	} else {
18053859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
18063859Sml29623 			"==> nxge_use_default_dma_config_n2: "
18073859Sml29623 			"get tx-dma-channels failed"));
18083859Sml29623 		return (NXGE_DDI_FAILED);
18093859Sml29623 	}
18103859Sml29623 
18116495Sspeer 	p_cfgp->tdc.count = nxgep->max_tdcs = ndmas;
18126495Sspeer 	p_cfgp->tdc.owned = p_cfgp->tdc.count;
18133859Sml29623 
18143859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
18153859Sml29623 		"p_cfgp 0x%llx max_tdcs %d nxgep->max_tdcs %d start %d",
18166495Sspeer 		p_cfgp, p_cfgp->tdc.count, nxgep->max_tdcs, p_cfgp->tdc.start));
18173859Sml29623 
18183859Sml29623 	/* Receive DMA */
18193859Sml29623 	ndmas = NXGE_RDMA_PER_NIU_PORT;
18203859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
18213859Sml29623 			"rx-dma-channels", (int **)&prop_val,
18223859Sml29623 			&prop_len) == DDI_PROP_SUCCESS) {
18233859Sml29623 		p_cfgp->start_rdc = prop_val[0];
18243859Sml29623 		NXGE_DEBUG_MSG((nxgep, OBP_CTL,
18253859Sml29623 			"==> nxge_use_default_dma_config_n2(obp): rdc start %d"
18263859Sml29623 			" (#%d)", p_cfgp->start_rdc, prop_len));
18273859Sml29623 		ndmas = prop_val[1];
18283859Sml29623 		NXGE_DEBUG_MSG((nxgep, OBP_CTL,
18293859Sml29623 			"==> nxge_use_default_dma_config_n2(obp):#rdc %d (#%d)",
18303859Sml29623 			ndmas, prop_len));
18313859Sml29623 		ddi_prop_free(prop_val);
18323859Sml29623 	} else {
18333859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
18343859Sml29623 			"==> nxge_use_default_dma_config_n2: "
18353859Sml29623 			"get rx-dma-channel failed"));
18363859Sml29623 		return (NXGE_DDI_FAILED);
18373859Sml29623 	}
18383859Sml29623 
18393859Sml29623 	p_cfgp->max_rdcs = nxgep->max_rdcs = ndmas;
18403859Sml29623 	nxgep->rdc_mask = (ndmas - 1);
18413859Sml29623 
18423859Sml29623 	/* Hypervisor: rdc # and group # use the same # !! */
18436495Sspeer 	p_cfgp->max_grpids = p_cfgp->max_rdcs + p_cfgp->tdc.owned;
18443859Sml29623 	p_cfgp->start_grpid = 0;
18453859Sml29623 	p_cfgp->mif_ldvid = p_cfgp->mac_ldvid = p_cfgp->ser_ldvid = 0;
18463859Sml29623 
18473859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
18483859Sml29623 			"interrupts", (int **)&prop_val,
18493859Sml29623 			&prop_len) == DDI_PROP_SUCCESS) {
18503859Sml29623 		/*
18513859Sml29623 		 * For each device assigned, the content of each interrupts
18523859Sml29623 		 * property is its logical device group.
18533859Sml29623 		 *
18543859Sml29623 		 * Assignment of interrupts property is in the the following
18553859Sml29623 		 * order:
18563859Sml29623 		 *
18573859Sml29623 		 * MAC MIF (if configured) SYSTEM ERROR (if configured) first
18583859Sml29623 		 * receive channel next channel...... last receive channel
18593859Sml29623 		 * first transmit channel next channel...... last transmit
18603859Sml29623 		 * channel
18613859Sml29623 		 *
18623859Sml29623 		 * prop_len should be at least for one mac and total # of rx and
18633859Sml29623 		 * tx channels. Function 0 owns MIF and ERROR
18643859Sml29623 		 */
18653859Sml29623 		NXGE_DEBUG_MSG((nxgep, OBP_CTL,
18663859Sml29623 			"==> nxge_use_default_dma_config_n2(obp): "
18673859Sml29623 			"# interrupts %d", prop_len));
18683859Sml29623 
18693859Sml29623 		switch (func) {
18703859Sml29623 		case 0:
18713859Sml29623 			p_cfgp->ldg_chn_start = 3;
18723859Sml29623 			p_cfgp->mac_ldvid = NXGE_MAC_LD_PORT0;
18733859Sml29623 			p_cfgp->mif_ldvid = NXGE_MIF_LD;
18743859Sml29623 			p_cfgp->ser_ldvid = NXGE_SYS_ERROR_LD;
18753859Sml29623 
18763859Sml29623 			break;
18773859Sml29623 		case 1:
18783859Sml29623 			p_cfgp->ldg_chn_start = 1;
18793859Sml29623 			p_cfgp->mac_ldvid = NXGE_MAC_LD_PORT1;
18803859Sml29623 
18813859Sml29623 			break;
18823859Sml29623 		default:
18833859Sml29623 			status = NXGE_DDI_FAILED;
18843859Sml29623 			break;
18853859Sml29623 		}
18863859Sml29623 
18873859Sml29623 		if (status != NXGE_OK)
18883859Sml29623 			return (status);
18893859Sml29623 
18903859Sml29623 		for (i = 0; i < prop_len; i++) {
18913859Sml29623 			p_cfgp->ldg[i] = prop_val[i];
18923859Sml29623 			NXGE_DEBUG_MSG((nxgep, OBP_CTL,
18933859Sml29623 				"==> nxge_use_default_dma_config_n2(obp): "
18946495Sspeer 				"F%d: interrupt #%d, ldg %d",
18956495Sspeer 				nxgep->function_num, i, p_cfgp->ldg[i]));
18963859Sml29623 		}
18973859Sml29623 
18983859Sml29623 		p_cfgp->max_grpids = prop_len;
18993859Sml29623 		NXGE_DEBUG_MSG((nxgep, OBP_CTL,
19003859Sml29623 			"==> nxge_use_default_dma_config_n2(obp): %d "
19013859Sml29623 			"(#%d) maxgrpids %d channel starts %d",
19023859Sml29623 			p_cfgp->mac_ldvid, i, p_cfgp->max_grpids,
19033859Sml29623 			p_cfgp->ldg_chn_start));
19043859Sml29623 		ddi_prop_free(prop_val);
19053859Sml29623 	} else {
19063859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
19073859Sml29623 			"==> nxge_use_default_dma_config_n2: "
19083859Sml29623 			"get interrupts failed"));
19093859Sml29623 		return (NXGE_DDI_FAILED);
19103859Sml29623 	}
19113859Sml29623 
19123859Sml29623 	p_cfgp->max_ldgs = p_cfgp->max_grpids;
19133859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL,
19143859Sml29623 		"==> nxge_use_default_dma_config_n2: "
19153859Sml29623 		"p_cfgp 0x%llx max_rdcs %d nxgep->max_rdcs %d max_grpids %d"
19163859Sml29623 		"start_grpid %d macid %d mifid %d serrid %d",
19173859Sml29623 		p_cfgp, p_cfgp->max_rdcs, nxgep->max_rdcs, p_cfgp->max_grpids,
19183859Sml29623 		p_cfgp->start_grpid,
19193859Sml29623 		p_cfgp->mac_ldvid, p_cfgp->mif_ldvid, p_cfgp->ser_ldvid));
19203859Sml29623 
19213859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
19223859Sml29623 		"p_cfgp p%p start_ldg %d nxgep->max_ldgs %d",
19233859Sml29623 		p_cfgp, p_cfgp->start_ldg, p_cfgp->max_ldgs));
19243859Sml29623 
19253859Sml29623 	/*
19263859Sml29623 	 * RDC groups and the beginning RDC group assigned to this function.
19273859Sml29623 	 */
19286495Sspeer 	p_cfgp->max_rdc_grpids = 1;
19296495Sspeer 	p_cfgp->def_mac_rxdma_grpid = (nxgep->function_num * 1);
19306495Sspeer 
19316495Sspeer 	if ((p_cfgp->def_mac_rxdma_grpid = nxge_fzc_rdc_tbl_bind
19326495Sspeer 		(nxgep, p_cfgp->def_mac_rxdma_grpid, B_TRUE))
19336495Sspeer 	    >= NXGE_MAX_RDC_GRPS) {
19346495Sspeer 		NXGE_ERROR_MSG((nxgep, CFG_CTL,
19356495Sspeer 		    "nxge_use_default_dma_config_n2(): "
19366495Sspeer 		    "nxge_fzc_rdc_tbl_bind failed"));
19376495Sspeer 		return (NXGE_DDI_FAILED);
19386495Sspeer 	}
19393859Sml29623 
19403859Sml29623 	status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
19416495Sspeer 	    "rx-rdc-grps", p_cfgp->max_rdc_grpids);
19423859Sml29623 	if (status) {
19433859Sml29623 		return (NXGE_DDI_FAILED);
19443859Sml29623 	}
19453859Sml29623 	status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
19466495Sspeer 		"rx-rdc-grps-begin", p_cfgp->def_mac_rxdma_grpid);
19473859Sml29623 	if (status) {
19483859Sml29623 		(void) ddi_prop_remove(DDI_DEV_T_NONE, nxgep->dip,
19493859Sml29623 			"rx-rdc-grps");
19503859Sml29623 		return (NXGE_DDI_FAILED);
19513859Sml29623 	}
19523859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
19533859Sml29623 		"p_cfgp $%p # rdc groups %d start rdc group id %d",
19543859Sml29623 		p_cfgp, p_cfgp->max_rdc_grpids,
19556495Sspeer 		p_cfgp->def_mac_rxdma_grpid));
19563859Sml29623 
19573859Sml29623 	nxge_set_hw_dma_config(nxgep);
19583859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "<== nxge_use_default_dma_config_n2"));
19593859Sml29623 	return (status);
19603859Sml29623 }
19613859Sml29623 
19623859Sml29623 static void
19633859Sml29623 nxge_use_cfg_dma_config(p_nxge_t nxgep)
19643859Sml29623 {
19654732Sdavemq 	int tx_ndmas, rx_ndmas, nrxgp, st_txdma, st_rxdma;
19663859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
19673859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
19683859Sml29623 	dev_info_t *dip;
19693859Sml29623 	p_nxge_param_t param_arr;
19703859Sml29623 	char *prop;
19713859Sml29623 	int *prop_val;
19723859Sml29623 	uint_t prop_len;
19734732Sdavemq 	int i;
19744732Sdavemq 	uint8_t *ch_arr_p;
19753859Sml29623 
19763859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_dma_config"));
19773859Sml29623 	param_arr = nxgep->param_arr;
19783859Sml29623 
19793859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
19803859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
19813859Sml29623 	dip = nxgep->dip;
19823859Sml29623 	p_cfgp->function_number = nxgep->function_num;
19833859Sml29623 	prop = param_arr[param_txdma_channels_begin].fcode_name;
19843859Sml29623 
19853859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
19863859Sml29623 			&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
19876495Sspeer 		p_cfgp->tdc.start = *prop_val;
19883859Sml29623 		ddi_prop_free(prop_val);
19893859Sml29623 	} else {
19904732Sdavemq 		switch (nxgep->niu_type) {
19914732Sdavemq 		case NEPTUNE_4_1GC:
19924732Sdavemq 			ch_arr_p = &tx_4_1G[0];
19934732Sdavemq 			break;
19944732Sdavemq 		case NEPTUNE_2_10GF:
19954732Sdavemq 			ch_arr_p = &tx_2_10G[0];
19964732Sdavemq 			break;
19974732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
19986261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
19994732Sdavemq 			ch_arr_p = &tx_2_10G_2_1G[0];
20004732Sdavemq 			break;
20014732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
20024732Sdavemq 			ch_arr_p = &tx_1_10G_3_1G[0];
20034732Sdavemq 			break;
20044732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
20054732Sdavemq 			ch_arr_p = &tx_1_1G_1_10G_2_1G[0];
20064732Sdavemq 			break;
20074732Sdavemq 		default:
20085196Ssbehera 			switch (nxgep->platform_type) {
20095196Ssbehera 			case P_NEPTUNE_ALONSO:
20105196Ssbehera 				ch_arr_p = &tx_2_10G_2_1G[0];
20115196Ssbehera 				break;
20125196Ssbehera 			default:
20135196Ssbehera 				ch_arr_p = &p4_tx_equal[0];
20145196Ssbehera 				break;
20155196Ssbehera 			}
20164732Sdavemq 			break;
20173859Sml29623 		}
20184732Sdavemq 		st_txdma = 0;
20194732Sdavemq 		for (i = 0; i < nxgep->function_num; i++, ch_arr_p++)
20204732Sdavemq 			st_txdma += *ch_arr_p;
20214732Sdavemq 
20223859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
20234732Sdavemq 		    prop, st_txdma);
20246495Sspeer 		p_cfgp->tdc.start = st_txdma;
20253859Sml29623 	}
20263859Sml29623 
20273859Sml29623 	prop = param_arr[param_txdma_channels].fcode_name;
20283859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
20293859Sml29623 			&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
20303859Sml29623 		tx_ndmas = *prop_val;
20313859Sml29623 		ddi_prop_free(prop_val);
20323859Sml29623 	} else {
20334732Sdavemq 		switch (nxgep->niu_type) {
20344732Sdavemq 		case NEPTUNE_4_1GC:
20354732Sdavemq 			tx_ndmas = tx_4_1G[nxgep->function_num];
20364732Sdavemq 			break;
20374732Sdavemq 		case NEPTUNE_2_10GF:
20384732Sdavemq 			tx_ndmas = tx_2_10G[nxgep->function_num];
20394732Sdavemq 			break;
20404732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
20416261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
20424732Sdavemq 			tx_ndmas = tx_2_10G_2_1G[nxgep->function_num];
20434732Sdavemq 			break;
20444732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
20454732Sdavemq 			tx_ndmas = tx_1_10G_3_1G[nxgep->function_num];
20464732Sdavemq 			break;
20474732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
20484732Sdavemq 			tx_ndmas = tx_1_1G_1_10G_2_1G[nxgep->function_num];
20494732Sdavemq 			break;
20504732Sdavemq 		default:
20515196Ssbehera 			switch (nxgep->platform_type) {
20525196Ssbehera 			case P_NEPTUNE_ALONSO:
20535196Ssbehera 				tx_ndmas = tx_2_10G_2_1G[nxgep->function_num];
20545196Ssbehera 				break;
20555196Ssbehera 			default:
20565196Ssbehera 				tx_ndmas = p4_tx_equal[nxgep->function_num];
20575196Ssbehera 				break;
20585196Ssbehera 			}
20594732Sdavemq 			break;
20603859Sml29623 		}
20613859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
20623859Sml29623 			prop, tx_ndmas);
20633859Sml29623 	}
20643859Sml29623 
20656495Sspeer 	p_cfgp->tdc.count = nxgep->max_tdcs = tx_ndmas;
20666495Sspeer 	p_cfgp->tdc.owned = p_cfgp->tdc.count;
20673859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_dma_config: "
20683859Sml29623 		"p_cfgp 0x%llx max_tdcs %d nxgep->max_tdcs %d",
20696495Sspeer 		p_cfgp, p_cfgp->tdc.count, nxgep->max_tdcs));
20703859Sml29623 
20713859Sml29623 	prop = param_arr[param_rxdma_channels_begin].fcode_name;
20723859Sml29623 
20733859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
20743859Sml29623 			&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
20753859Sml29623 		p_cfgp->start_rdc = *prop_val;
20763859Sml29623 		ddi_prop_free(prop_val);
20773859Sml29623 	} else {
20784732Sdavemq 		switch (nxgep->niu_type) {
20794732Sdavemq 		case NEPTUNE_4_1GC:
20804732Sdavemq 			ch_arr_p = &rx_4_1G[0];
20814732Sdavemq 			break;
20824732Sdavemq 		case NEPTUNE_2_10GF:
20834732Sdavemq 			ch_arr_p = &rx_2_10G[0];
20844732Sdavemq 			break;
20854732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
20866261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
20874732Sdavemq 			ch_arr_p = &rx_2_10G_2_1G[0];
20884732Sdavemq 			break;
20894732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
20904732Sdavemq 			ch_arr_p = &rx_1_10G_3_1G[0];
20914732Sdavemq 			break;
20924732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
20934732Sdavemq 			ch_arr_p = &rx_1_1G_1_10G_2_1G[0];
20944732Sdavemq 			break;
20954732Sdavemq 		default:
20965196Ssbehera 			switch (nxgep->platform_type) {
20975196Ssbehera 			case P_NEPTUNE_ALONSO:
20985196Ssbehera 				ch_arr_p = &rx_2_10G_2_1G[0];
20995196Ssbehera 				break;
21005196Ssbehera 			default:
21015196Ssbehera 				ch_arr_p = &p4_rx_equal[0];
21025196Ssbehera 				break;
21035196Ssbehera 			}
21044732Sdavemq 			break;
21053859Sml29623 		}
21064732Sdavemq 		st_rxdma = 0;
21074732Sdavemq 		for (i = 0; i < nxgep->function_num; i++, ch_arr_p++)
21084732Sdavemq 			st_rxdma += *ch_arr_p;
21094732Sdavemq 
21103859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
21114732Sdavemq 		    prop, st_rxdma);
21124732Sdavemq 		p_cfgp->start_rdc = st_rxdma;
21133859Sml29623 	}
21143859Sml29623 
21153859Sml29623 	prop = param_arr[param_rxdma_channels].fcode_name;
21163859Sml29623 
21173859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
21183859Sml29623 			&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
21193859Sml29623 		rx_ndmas = *prop_val;
21203859Sml29623 		ddi_prop_free(prop_val);
21213859Sml29623 	} else {
21224732Sdavemq 		switch (nxgep->niu_type) {
21234732Sdavemq 		case NEPTUNE_4_1GC:
21244732Sdavemq 			rx_ndmas = rx_4_1G[nxgep->function_num];
21254732Sdavemq 			break;
21264732Sdavemq 		case NEPTUNE_2_10GF:
21274732Sdavemq 			rx_ndmas = rx_2_10G[nxgep->function_num];
21284732Sdavemq 			break;
21294732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
21306261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
21314732Sdavemq 			rx_ndmas = rx_2_10G_2_1G[nxgep->function_num];
21324732Sdavemq 			break;
21334732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
21344732Sdavemq 			rx_ndmas = rx_1_10G_3_1G[nxgep->function_num];
21354732Sdavemq 			break;
21364732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
21374732Sdavemq 			rx_ndmas = rx_1_1G_1_10G_2_1G[nxgep->function_num];
21384732Sdavemq 			break;
21394732Sdavemq 		default:
21405196Ssbehera 			switch (nxgep->platform_type) {
21415196Ssbehera 			case P_NEPTUNE_ALONSO:
21425196Ssbehera 				rx_ndmas = rx_2_10G_2_1G[nxgep->function_num];
21435196Ssbehera 				break;
21445196Ssbehera 			default:
21455196Ssbehera 				rx_ndmas = p4_rx_equal[nxgep->function_num];
21465196Ssbehera 				break;
21475196Ssbehera 			}
21484732Sdavemq 			break;
21493859Sml29623 		}
21503859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
21513859Sml29623 			prop, rx_ndmas);
21523859Sml29623 	}
21533859Sml29623 
21543859Sml29623 	p_cfgp->max_rdcs = nxgep->max_rdcs = rx_ndmas;
21553859Sml29623 
21563859Sml29623 	prop = param_arr[param_rdc_grps_start].fcode_name;
21573859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
21583859Sml29623 			&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
21596495Sspeer 		p_cfgp->def_mac_rxdma_grpid = *prop_val;
21603859Sml29623 		ddi_prop_free(prop_val);
21616495Sspeer 		if ((p_cfgp->def_mac_rxdma_grpid = nxge_fzc_rdc_tbl_bind
21626495Sspeer 			(nxgep, p_cfgp->def_mac_rxdma_grpid, B_TRUE))
21636495Sspeer 		    >= NXGE_MAX_RDC_GRPS) {
21646495Sspeer 			NXGE_ERROR_MSG((nxgep, CFG_CTL,
21656495Sspeer 			    "nxge_use_cfg_dma_config(): "
21666495Sspeer 			    "nxge_fzc_rdc_tbl_bind failed"));
21676495Sspeer 			cmn_err(CE_CONT, "nxge%d: group not available!\n",
21686495Sspeer 			    nxgep->instance);
21696495Sspeer 			goto nxge_use_cfg_dma_config_exit;
21706495Sspeer 		}
21716495Sspeer 
21723859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
21736495Sspeer 		    "==> nxge_use_default_dma_config: "
21746495Sspeer 		    "use property " "start_grpid %d ",
21753859Sml29623 			p_cfgp->start_grpid));
21763859Sml29623 	} else {
21776495Sspeer 		p_cfgp->def_mac_rxdma_grpid = nxgep->function_num;
21786495Sspeer 		if ((p_cfgp->def_mac_rxdma_grpid = nxge_fzc_rdc_tbl_bind(
21796495Sspeer 		    nxgep, p_cfgp->def_mac_rxdma_grpid, B_TRUE)) >=
21806495Sspeer 		    NXGE_MAX_RDC_GRPS) {
21816495Sspeer 			cmn_err(CE_CONT, "nxge%d: group not available!\n",
21826495Sspeer 			    nxgep->instance);
21836495Sspeer 			goto nxge_use_cfg_dma_config_exit;
21846495Sspeer 		}
21853859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
21866495Sspeer 			prop, p_cfgp->def_mac_rxdma_grpid);
21873859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
21883859Sml29623 			"==> nxge_use_default_dma_config: "
21893859Sml29623 			"use default "
21903859Sml29623 			"start_grpid %d (same as function #)",
21913859Sml29623 			p_cfgp->start_grpid));
21923859Sml29623 	}
21933859Sml29623 
21943859Sml29623 	prop = param_arr[param_rx_rdc_grps].fcode_name;
21953859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
21963859Sml29623 			&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
21973859Sml29623 		nrxgp = *prop_val;
21983859Sml29623 		ddi_prop_free(prop_val);
21993859Sml29623 	} else {
22003859Sml29623 		nrxgp = 1;
22013859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
22023859Sml29623 			prop, nrxgp);
22033859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
22043859Sml29623 			"==> nxge_use_default_dma_config: "
22053859Sml29623 			"num_rdc_grpid not found: use def:# of "
22063859Sml29623 			"rdc groups %d\n", nrxgp));
22073859Sml29623 	}
22083859Sml29623 
22093859Sml29623 	p_cfgp->max_rdc_grpids = nrxgp;
22103859Sml29623 
22113859Sml29623 	/*
22123859Sml29623 	 * 2/4 ports have the same hard-wired logical groups assigned.
22133859Sml29623 	 */
22143859Sml29623 	p_cfgp->start_ldg = nxgep->function_num * NXGE_LDGRP_PER_4PORTS;
22153859Sml29623 	p_cfgp->max_ldgs = NXGE_LDGRP_PER_4PORTS;
22163859Sml29623 
22173859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_default_dma_config: "
22183859Sml29623 		"p_cfgp 0x%llx max_rdcs %d nxgep->max_rdcs %d max_grpids %d"
22193859Sml29623 		"start_grpid %d",
22203859Sml29623 		p_cfgp, p_cfgp->max_rdcs, nxgep->max_rdcs, p_cfgp->max_grpids,
22213859Sml29623 		p_cfgp->start_grpid));
22223859Sml29623 
22233859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_dma_config: "
22243859Sml29623 		"p_cfgp 0x%016llx start_ldg %d nxgep->max_ldgs %d "
22256495Sspeer 		"def_mac_rxdma_grpid %d",
22263859Sml29623 		p_cfgp, p_cfgp->start_ldg, p_cfgp->max_ldgs,
22276495Sspeer 		p_cfgp->def_mac_rxdma_grpid));
22283859Sml29623 
22293859Sml29623 	prop = param_arr[param_rxdma_intr_time].fcode_name;
22303859Sml29623 
22313859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
22323859Sml29623 			&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
22333859Sml29623 		if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
22343859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
22353859Sml29623 				nxgep->dip, prop, prop_val, prop_len);
22363859Sml29623 		}
22373859Sml29623 		ddi_prop_free(prop_val);
22383859Sml29623 	}
22393859Sml29623 	prop = param_arr[param_rxdma_intr_pkts].fcode_name;
22403859Sml29623 
22413859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
22423859Sml29623 			&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
22433859Sml29623 		if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
22443859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
22453859Sml29623 				nxgep->dip, prop, prop_val, prop_len);
22463859Sml29623 		}
22473859Sml29623 		ddi_prop_free(prop_val);
22483859Sml29623 	}
22493859Sml29623 	nxge_set_hw_dma_config(nxgep);
22503859Sml29623 
22514732Sdavemq 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_dma_config: "
22524732Sdavemq 	    "sTDC[%d] nTDC[%d] sRDC[%d] nRDC[%d]",
22536495Sspeer 	    p_cfgp->tdc.start, p_cfgp->tdc.count,
22544732Sdavemq 	    p_cfgp->start_rdc, p_cfgp->max_rdcs));
22554732Sdavemq 
22566495Sspeer nxge_use_cfg_dma_config_exit:
22573859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_dma_config"));
22583859Sml29623 }
22593859Sml29623 
22606495Sspeer void
22616495Sspeer nxge_get_logical_props(p_nxge_t nxgep)
22626495Sspeer {
22636495Sspeer 	nxge_dma_pt_cfg_t *port = &nxgep->pt_config;
22646495Sspeer 	nxge_hw_pt_cfg_t *hardware;
22656495Sspeer 	nxge_rdc_grp_t *group;
22666495Sspeer 
22676495Sspeer 	(void) memset(port, 0, sizeof (*port));
22686495Sspeer 
22696495Sspeer 	port->mac_port = 0;	/* := function number */
22706495Sspeer 
22716495Sspeer 	/*
22726495Sspeer 	 * alloc_buf_size:
22736495Sspeer 	 * dead variables.
22746495Sspeer 	 */
22756495Sspeer 	port->rbr_size = nxge_rbr_size;
22766495Sspeer 	port->rcr_size = nxge_rcr_size;
22776495Sspeer 
22786495Sspeer 	port->tx_dma_map = 0;	/* Transmit DMA channel bit map */
22796495Sspeer 
22806495Sspeer 	nxge_set_rdc_intr_property(nxgep);
22816495Sspeer 
22826495Sspeer 	port->rcr_full_header = NXGE_RCR_FULL_HEADER;
22836495Sspeer 	port->rx_drr_weight = PT_DRR_WT_DEFAULT_10G;
22846495Sspeer 
22856495Sspeer 	/* ----------------------------------------------------- */
22866495Sspeer 	hardware = &port->hw_config;
22876495Sspeer 
22886495Sspeer 	(void) memset(hardware, 0, sizeof (*hardware));
22896495Sspeer 
22906495Sspeer 	/*
22916495Sspeer 	 * partition_id, read_write_mode:
22926495Sspeer 	 * dead variables.
22936495Sspeer 	 */
22946495Sspeer 
22956495Sspeer 	/*
22966495Sspeer 	 * drr_wt, rx_full_header, *_ldg?, start_mac_entry,
22976495Sspeer 	 * mac_pref, def_mac_rxdma_grpid, start_vlan, max_vlans,
22986495Sspeer 	 * start_ldgs, max_ldgs, max_ldvs,
22996495Sspeer 	 * vlan_pref, def_vlan_rxdma_grpid are meaningful only
23006495Sspeer 	 * in the service domain.
23016495Sspeer 	 */
23026495Sspeer 
23036495Sspeer 	group = &port->rdc_grps[0];
23046495Sspeer 
23056495Sspeer 	group->flag = 1;	/* configured */
23066495Sspeer 	group->config_method = RDC_TABLE_ENTRY_METHOD_REP;
23076495Sspeer 
23086495Sspeer 	/* HIO futures: this is still an open question. */
23096495Sspeer 	hardware->max_macs = 1;
23106495Sspeer }
23116495Sspeer 
23123859Sml29623 static void
23133859Sml29623 nxge_use_cfg_vlan_class_config(p_nxge_t nxgep)
23143859Sml29623 {
23153859Sml29623 	uint_t vlan_cnt;
23163859Sml29623 	int *vlan_cfg_val;
23173859Sml29623 	int status;
23183859Sml29623 	p_nxge_param_t param_arr;
23193859Sml29623 	char *prop;
23203859Sml29623 
23213859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_vlan_config"));
23223859Sml29623 	param_arr = nxgep->param_arr;
23233859Sml29623 	prop = param_arr[param_vlan_2rdc_grp].fcode_name;
23243859Sml29623 
23253859Sml29623 	status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
23263859Sml29623 		&vlan_cfg_val, &vlan_cnt);
23273859Sml29623 	if (status == DDI_PROP_SUCCESS) {
23283859Sml29623 		status = ddi_prop_update_int_array(DDI_DEV_T_NONE,
23293859Sml29623 			nxgep->dip, prop, vlan_cfg_val, vlan_cnt);
23303859Sml29623 		ddi_prop_free(vlan_cfg_val);
23313859Sml29623 	}
23323859Sml29623 	nxge_set_hw_vlan_class_config(nxgep);
23333859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_vlan_config"));
23343859Sml29623 }
23353859Sml29623 
23363859Sml29623 static void
23373859Sml29623 nxge_use_cfg_mac_class_config(p_nxge_t nxgep)
23383859Sml29623 {
23393859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
23403859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
23413859Sml29623 	uint_t mac_cnt;
23423859Sml29623 	int *mac_cfg_val;
23433859Sml29623 	int status;
23443859Sml29623 	p_nxge_param_t param_arr;
23453859Sml29623 	char *prop;
23463859Sml29623 
23473859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_mac_class_config"));
23483859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
23493859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
23503859Sml29623 	p_cfgp->start_mac_entry = 0;
23513859Sml29623 	param_arr = nxgep->param_arr;
23523859Sml29623 	prop = param_arr[param_mac_2rdc_grp].fcode_name;
23533859Sml29623 
23543859Sml29623 	switch (nxgep->function_num) {
23553859Sml29623 	case 0:
23563859Sml29623 	case 1:
23573859Sml29623 		/* 10G ports */
23583859Sml29623 		p_cfgp->max_macs = NXGE_MAX_MACS_XMACS;
23593859Sml29623 		break;
23603859Sml29623 	case 2:
23613859Sml29623 	case 3:
23623859Sml29623 		/* 1G ports */
23633859Sml29623 	default:
23643859Sml29623 		p_cfgp->max_macs = NXGE_MAX_MACS_BMACS;
23653859Sml29623 		break;
23663859Sml29623 	}
23673859Sml29623 
23683859Sml29623 	p_cfgp->mac_pref = 1;
23693859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL,
23703859Sml29623 		"== nxge_use_cfg_mac_class_config: "
23713859Sml29623 		" mac_pref bit set def_mac_rxdma_grpid %d",
23723859Sml29623 		p_cfgp->def_mac_rxdma_grpid));
23733859Sml29623 
23743859Sml29623 	status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
23753859Sml29623 		&mac_cfg_val, &mac_cnt);
23763859Sml29623 	if (status == DDI_PROP_SUCCESS) {
23773859Sml29623 		if (mac_cnt <= p_cfgp->max_macs)
23783859Sml29623 			status = ddi_prop_update_int_array(DDI_DEV_T_NONE,
23793859Sml29623 				nxgep->dip, prop, mac_cfg_val, mac_cnt);
23803859Sml29623 		ddi_prop_free(mac_cfg_val);
23813859Sml29623 	}
23823859Sml29623 	nxge_set_hw_mac_class_config(nxgep);
23833859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_mac_class_config"));
23843859Sml29623 }
23853859Sml29623 
23863859Sml29623 static void
23873859Sml29623 nxge_use_cfg_class_config(p_nxge_t nxgep)
23883859Sml29623 {
23893859Sml29623 	nxge_set_hw_class_config(nxgep);
23903859Sml29623 }
23913859Sml29623 
23923859Sml29623 static void
23933859Sml29623 nxge_set_rdc_intr_property(p_nxge_t nxgep)
23943859Sml29623 {
23953859Sml29623 	int i;
23963859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
23973859Sml29623 
23983859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_rdc_intr_property"));
23993859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
24003859Sml29623 
24013859Sml29623 	for (i = 0; i < NXGE_MAX_RDCS; i++) {
24023859Sml29623 		p_dma_cfgp->rcr_timeout[i] = nxge_rcr_timeout;
24033859Sml29623 		p_dma_cfgp->rcr_threshold[i] = nxge_rcr_threshold;
24043859Sml29623 	}
24053859Sml29623 
24063859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_rdc_intr_property"));
24073859Sml29623 }
24083859Sml29623 
24093859Sml29623 static void
24103859Sml29623 nxge_set_hw_dma_config(p_nxge_t nxgep)
24113859Sml29623 {
24126495Sspeer 	int i, ndmas, ngrps, bitmap, end, st_rdc;
24133859Sml29623 	int32_t status;
24143859Sml29623 	uint8_t rdcs_per_grp;
24153859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
24163859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
24173859Sml29623 	p_nxge_rdc_grp_t rdc_grp_p;
24183859Sml29623 	int rdcgrp_cfg = CFG_NOT_SPECIFIED, rx_quick_cfg;
24193859Sml29623 	char *prop, *prop_val;
24203859Sml29623 	p_nxge_param_t param_arr;
24213859Sml29623 	config_token_t token;
24226495Sspeer 	nxge_grp_t *group;
24233859Sml29623 
24243859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_set_hw_dma_config"));
24253859Sml29623 
24263859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
24273859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
24283859Sml29623 	rdc_grp_p = p_dma_cfgp->rdc_grps;
24293859Sml29623 
24303859Sml29623 	bitmap = 0;
24316495Sspeer 	end = p_cfgp->tdc.start + p_cfgp->tdc.owned;
24323859Sml29623 	p_dma_cfgp->tx_dma_map = 0;
24336495Sspeer 	for (i = p_cfgp->tdc.start; i < end; i++) {
24343859Sml29623 		bitmap |= (1 << i);
24353859Sml29623 	}
24363859Sml29623 
24376495Sspeer 	nxgep->tx_set.owned.map |= bitmap; /* Owned, & not shared. */
24386495Sspeer 
24396495Sspeer 	group = (nxge_grp_t *)nxge_grp_add(nxgep, NXGE_TRANSMIT_GROUP);
24406495Sspeer 	group->map = bitmap;
24416495Sspeer 
24423859Sml29623 	p_dma_cfgp->tx_dma_map = bitmap;
24433859Sml29623 	param_arr = nxgep->param_arr;
24443859Sml29623 
24453859Sml29623 	/* Assume RDCs are evenly distributed */
24463859Sml29623 	rx_quick_cfg = param_arr[param_rx_quick_cfg].value;
24473859Sml29623 	switch (rx_quick_cfg) {
24483859Sml29623 	case CFG_NOT_SPECIFIED:
24493859Sml29623 		prop = "rxdma-grp-cfg";
24503859Sml29623 		status = ddi_prop_lookup_string(DDI_DEV_T_NONE,
24513859Sml29623 			nxgep->dip, 0, prop, (char **)&prop_val);
24523859Sml29623 		if (status != DDI_PROP_SUCCESS) {
24533859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
24543859Sml29623 				" property %s not found", prop));
24553859Sml29623 			rdcgrp_cfg = CFG_L3_DISTRIBUTE;
24563859Sml29623 		} else {
24573859Sml29623 			token = nxge_get_config_token(prop_val);
24583859Sml29623 			switch (token) {
24593859Sml29623 			case L2_CLASSIFY:
24603859Sml29623 				break;
24613859Sml29623 			case CLASSIFY:
24623859Sml29623 			case L3_CLASSIFY:
24633859Sml29623 			case L3_DISTRIBUTE:
24643859Sml29623 			case L3_TCAM:
24653859Sml29623 				rdcgrp_cfg = CFG_L3_DISTRIBUTE;
24663859Sml29623 				break;
24673859Sml29623 			default:
24683859Sml29623 				rdcgrp_cfg = CFG_L3_DISTRIBUTE;
24693859Sml29623 				break;
24703859Sml29623 			}
24713859Sml29623 			ddi_prop_free(prop_val);
24723859Sml29623 		}
24733859Sml29623 		break;
24743859Sml29623 	case CFG_L3_WEB:
24753859Sml29623 	case CFG_L3_DISTRIBUTE:
24763859Sml29623 	case CFG_L2_CLASSIFY:
24773859Sml29623 	case CFG_L3_TCAM:
24783859Sml29623 		rdcgrp_cfg = rx_quick_cfg;
24793859Sml29623 		break;
24803859Sml29623 	default:
24813859Sml29623 		rdcgrp_cfg = CFG_L3_DISTRIBUTE;
24823859Sml29623 		break;
24833859Sml29623 	}
24843859Sml29623 
24853859Sml29623 	st_rdc = p_cfgp->start_rdc;
24863859Sml29623 
24873859Sml29623 	switch (rdcgrp_cfg) {
24883859Sml29623 	case CFG_L3_DISTRIBUTE:
24893859Sml29623 	case CFG_L3_WEB:
24903859Sml29623 	case CFG_L3_TCAM:
24913859Sml29623 		ndmas = p_cfgp->max_rdcs;
24923859Sml29623 		ngrps = 1;
24933859Sml29623 		rdcs_per_grp = ndmas / ngrps;
24943859Sml29623 		break;
24953859Sml29623 	case CFG_L2_CLASSIFY:
24963859Sml29623 		ndmas = p_cfgp->max_rdcs / 2;
24973859Sml29623 		if (p_cfgp->max_rdcs < 2)
24983859Sml29623 			ndmas = 1;
24993859Sml29623 		ngrps = 1;
25003859Sml29623 		rdcs_per_grp = ndmas / ngrps;
25013859Sml29623 		break;
25023859Sml29623 	default:
25033859Sml29623 		ngrps = p_cfgp->max_rdc_grpids;
25043859Sml29623 		ndmas = p_cfgp->max_rdcs;
25053859Sml29623 		rdcs_per_grp = ndmas / ngrps;
25063859Sml29623 		break;
25073859Sml29623 	}
25083859Sml29623 
25093859Sml29623 	for (i = 0; i < ngrps; i++) {
25106495Sspeer 		uint8_t count = rdcs_per_grp;
25116495Sspeer 		dc_map_t map = 0;
25126495Sspeer 
25136495Sspeer 		rdc_grp_p = &p_dma_cfgp->rdc_grps[
25146495Sspeer 			p_cfgp->def_mac_rxdma_grpid + i];
25153859Sml29623 		rdc_grp_p->start_rdc = st_rdc + i * rdcs_per_grp;
25163859Sml29623 		rdc_grp_p->max_rdcs = rdcs_per_grp;
25176495Sspeer 		rdc_grp_p->def_rdc = rdc_grp_p->start_rdc;
25183859Sml29623 
25193859Sml29623 		/* default to: 0, 1, 2, 3, ...., 0, 1, 2, 3.... */
25206495Sspeer 		while (count) {
25216495Sspeer 			map |= (1 << count);
25226495Sspeer 			count--;
25236495Sspeer 		}
25246495Sspeer 		map >>= 1;	/* In case <start_rdc> is zero (0) */
25256495Sspeer 		map <<= rdc_grp_p->start_rdc;
25266495Sspeer 		rdc_grp_p->map = map;
25276495Sspeer 
25286495Sspeer 		nxgep->rx_set.owned.map |= map; /* Owned, & not shared. */
25296495Sspeer 
25306495Sspeer 		group = (nxge_grp_t *)nxge_grp_add(nxgep, NXGE_RECEIVE_GROUP);
25316495Sspeer 		group->map = rdc_grp_p->map;
25326495Sspeer 
25333859Sml29623 		rdc_grp_p->config_method = RDC_TABLE_ENTRY_METHOD_SEQ;
25346495Sspeer 		rdc_grp_p->flag = 1; /* This group has been configured. */
25353859Sml29623 	}
25363859Sml29623 
25376495Sspeer 
25383859Sml29623 	/* default RDC */
25393859Sml29623 	p_cfgp->def_rdc = p_cfgp->start_rdc;
25403859Sml29623 	nxgep->def_rdc = p_cfgp->start_rdc;
25413859Sml29623 
25423859Sml29623 	/* full 18 byte header ? */
25433859Sml29623 	p_dma_cfgp->rcr_full_header = NXGE_RCR_FULL_HEADER;
25443859Sml29623 	p_dma_cfgp->rx_drr_weight = PT_DRR_WT_DEFAULT_10G;
25453859Sml29623 	if (nxgep->function_num > 1)
25463859Sml29623 		p_dma_cfgp->rx_drr_weight = PT_DRR_WT_DEFAULT_1G;
25473859Sml29623 	p_dma_cfgp->rbr_size = nxge_rbr_size;
25483859Sml29623 	p_dma_cfgp->rcr_size = nxge_rcr_size;
25493859Sml29623 
25503859Sml29623 	nxge_set_rdc_intr_property(nxgep);
25513859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_hw_dma_config"));
25523859Sml29623 }
25533859Sml29623 
25543859Sml29623 boolean_t
25553859Sml29623 nxge_check_rxdma_port_member(p_nxge_t nxgep, uint8_t rdc)
25563859Sml29623 {
25573859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
25583859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
25593859Sml29623 	int status = B_TRUE;
25603859Sml29623 
25613859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_rxdma_port_member"));
25623859Sml29623 
25633859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
25643859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
25653859Sml29623 
25663859Sml29623 	/* Receive DMA Channels */
25673859Sml29623 	if (rdc < p_cfgp->max_rdcs)
25683859Sml29623 		status = B_TRUE;
25693859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_rxdma_port_member"));
25703859Sml29623 	return (status);
25713859Sml29623 }
25723859Sml29623 
25733859Sml29623 boolean_t
25743859Sml29623 nxge_check_txdma_port_member(p_nxge_t nxgep, uint8_t tdc)
25753859Sml29623 {
25763859Sml29623 	int status = B_FALSE;
25773859Sml29623 
25786495Sspeer 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_txdma_port_member"));
25796495Sspeer 
25806495Sspeer 	if (tdc >= nxgep->pt_config.hw_config.tdc.start &&
25816495Sspeer 	    tdc < nxgep->pt_config.hw_config.tdc.count)
25823859Sml29623 		status = B_TRUE;
25836495Sspeer 
25846495Sspeer 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_txdma_port_member"));
25853859Sml29623 	return (status);
25863859Sml29623 }
25873859Sml29623 
25883859Sml29623 boolean_t
25893859Sml29623 nxge_check_rxdma_rdcgrp_member(p_nxge_t nxgep, uint8_t rdc_grp, uint8_t rdc)
25903859Sml29623 {
25913859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
25923859Sml29623 	int status = B_TRUE;
25933859Sml29623 	p_nxge_rdc_grp_t rdc_grp_p;
25943859Sml29623 
25953859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
25963859Sml29623 		" ==> nxge_check_rxdma_rdcgrp_member"));
25973859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "  nxge_check_rxdma_rdcgrp_member"
25983859Sml29623 		" rdc  %d group %d", rdc, rdc_grp));
25993859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
26003859Sml29623 
26013859Sml29623 	rdc_grp_p = &p_dma_cfgp->rdc_grps[rdc_grp];
26023859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "  max  %d ", rdc_grp_p->max_rdcs));
26033859Sml29623 	if (rdc >= rdc_grp_p->max_rdcs) {
26043859Sml29623 		status = B_FALSE;
26053859Sml29623 	}
26063859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
26073859Sml29623 		" <== nxge_check_rxdma_rdcgrp_member"));
26083859Sml29623 	return (status);
26093859Sml29623 }
26103859Sml29623 
26113859Sml29623 boolean_t
26123859Sml29623 nxge_check_rdcgrp_port_member(p_nxge_t nxgep, uint8_t rdc_grp)
26133859Sml29623 {
26143859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
26153859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
26163859Sml29623 	int status = B_TRUE;
26173859Sml29623 
26183859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_rdcgrp_port_member"));
26193859Sml29623 
26203859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
26213859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
26223859Sml29623 
26233859Sml29623 	if (rdc_grp >= p_cfgp->max_rdc_grpids)
26243859Sml29623 		status = B_FALSE;
26253859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_rdcgrp_port_member"));
26263859Sml29623 	return (status);
26273859Sml29623 }
26283859Sml29623 
26293859Sml29623 static void
26303859Sml29623 nxge_set_hw_vlan_class_config(p_nxge_t nxgep)
26313859Sml29623 {
26323859Sml29623 	int i;
26333859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
26343859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
26353859Sml29623 	p_nxge_param_t param_arr;
26363859Sml29623 	uint_t vlan_cnt;
26373859Sml29623 	int *vlan_cfg_val;
26383859Sml29623 	nxge_param_map_t *vmap;
26393859Sml29623 	char *prop;
26403859Sml29623 	p_nxge_class_pt_cfg_t p_class_cfgp;
26413859Sml29623 	uint32_t good_cfg[32];
26423859Sml29623 	int good_count = 0;
26433859Sml29623 	nxge_mv_cfg_t *vlan_tbl;
26443859Sml29623 
26453859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_hw_vlan_config"));
26463859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
26473859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
26483859Sml29623 	p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
26493859Sml29623 
26503859Sml29623 	param_arr = nxgep->param_arr;
26513859Sml29623 	prop = param_arr[param_vlan_2rdc_grp].fcode_name;
26523859Sml29623 
26533859Sml29623 	/*
26543859Sml29623 	 * By default, VLAN to RDC group mapping is disabled Need to read HW or
26553859Sml29623 	 * .conf properties to find out if mapping is required
26563859Sml29623 	 *
26573859Sml29623 	 * Format
26583859Sml29623 	 *
26593859Sml29623 	 * uint32_t array, each array entry specifying the VLAN id and the
26603859Sml29623 	 * mapping
26613859Sml29623 	 *
26623859Sml29623 	 * bit[30] = add bit[29] = remove bit[28]  = preference bits[23-16] =
26633859Sml29623 	 * rdcgrp bits[15-0] = VLAN ID ( )
26643859Sml29623 	 */
26653859Sml29623 
26663859Sml29623 	for (i = 0; i < NXGE_MAX_VLANS; i++) {
26673859Sml29623 		p_class_cfgp->vlan_tbl[i].flag = 0;
26683859Sml29623 	}
26693859Sml29623 
26703859Sml29623 	vlan_tbl = (nxge_mv_cfg_t *)&p_class_cfgp->vlan_tbl[0];
26713859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
26723859Sml29623 			&vlan_cfg_val, &vlan_cnt) == DDI_PROP_SUCCESS) {
26733859Sml29623 		for (i = 0; i < vlan_cnt; i++) {
26743859Sml29623 			vmap = (nxge_param_map_t *)&vlan_cfg_val[i];
26753859Sml29623 			if ((vmap->param_id) &&
26763859Sml29623 					(vmap->param_id < NXGE_MAX_VLANS) &&
26773859Sml29623 					(vmap->map_to <
26783859Sml29623 						p_cfgp->max_rdc_grpids) &&
26793859Sml29623 					(vmap->map_to >= (uint8_t)0)) {
26803859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
26813859Sml29623 					" nxge_vlan_config mapping"
26823859Sml29623 					" id %d grp %d",
26833859Sml29623 					vmap->param_id, vmap->map_to));
26843859Sml29623 				good_cfg[good_count] = vlan_cfg_val[i];
26853859Sml29623 				if (vlan_tbl[vmap->param_id].flag == 0)
26863859Sml29623 					good_count++;
26873859Sml29623 				vlan_tbl[vmap->param_id].flag = 1;
26883859Sml29623 				vlan_tbl[vmap->param_id].rdctbl =
26896495Sspeer 				    vmap->map_to + p_cfgp->def_mac_rxdma_grpid;
26903859Sml29623 				vlan_tbl[vmap->param_id].mpr_npr = vmap->pref;
26913859Sml29623 			}
26923859Sml29623 		}
26933859Sml29623 		ddi_prop_free(vlan_cfg_val);
26943859Sml29623 		if (good_count != vlan_cnt) {
26953859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
26963859Sml29623 				nxgep->dip, prop, (int *)good_cfg, good_count);
26973859Sml29623 		}
26983859Sml29623 	}
26993859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_set_hw_vlan_config"));
27003859Sml29623 }
27013859Sml29623 
27023859Sml29623 static void
27033859Sml29623 nxge_set_hw_mac_class_config(p_nxge_t nxgep)
27043859Sml29623 {
27053859Sml29623 	int i;
27063859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
27073859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
27083859Sml29623 	p_nxge_param_t param_arr;
27093859Sml29623 	uint_t mac_cnt;
27103859Sml29623 	int *mac_cfg_val;
27113859Sml29623 	nxge_param_map_t *mac_map;
27123859Sml29623 	char *prop;
27133859Sml29623 	p_nxge_class_pt_cfg_t p_class_cfgp;
27143859Sml29623 	int good_count = 0;
27153859Sml29623 	int good_cfg[NXGE_MAX_MACS];
27163859Sml29623 	nxge_mv_cfg_t *mac_host_info;
27173859Sml29623 
27183859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_set_hw_mac_config"));
27193859Sml29623 
27203859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
27213859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
27223859Sml29623 	p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
27233859Sml29623 	mac_host_info = (nxge_mv_cfg_t *)&p_class_cfgp->mac_host_info[0];
27243859Sml29623 
27253859Sml29623 	param_arr = nxgep->param_arr;
27263859Sml29623 	prop = param_arr[param_mac_2rdc_grp].fcode_name;
27273859Sml29623 
27283859Sml29623 	for (i = 0; i < NXGE_MAX_MACS; i++) {
27293859Sml29623 		p_class_cfgp->mac_host_info[i].flag = 0;
27304484Sspeer 		p_class_cfgp->mac_host_info[i].rdctbl =
27314484Sspeer 		    p_cfgp->def_mac_rxdma_grpid;
27323859Sml29623 	}
27333859Sml29623 
27343859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
27353859Sml29623 			&mac_cfg_val, &mac_cnt) == DDI_PROP_SUCCESS) {
27363859Sml29623 		for (i = 0; i < mac_cnt; i++) {
27373859Sml29623 			mac_map = (nxge_param_map_t *)&mac_cfg_val[i];
27383859Sml29623 			if ((mac_map->param_id < p_cfgp->max_macs) &&
27393859Sml29623 					(mac_map->map_to <
27403859Sml29623 						p_cfgp->max_rdc_grpids) &&
27413859Sml29623 					(mac_map->map_to >= (uint8_t)0)) {
27423859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
27433859Sml29623 					" nxge_mac_config mapping"
27443859Sml29623 					" id %d grp %d",
27453859Sml29623 					mac_map->param_id, mac_map->map_to));
27463859Sml29623 				mac_host_info[mac_map->param_id].mpr_npr =
27473859Sml29623 					mac_map->pref;
27483859Sml29623 				mac_host_info[mac_map->param_id].rdctbl =
27493859Sml29623 					mac_map->map_to +
27506495Sspeer 					p_cfgp->def_mac_rxdma_grpid;
27513859Sml29623 				good_cfg[good_count] = mac_cfg_val[i];
27523859Sml29623 				if (mac_host_info[mac_map->param_id].flag == 0)
27533859Sml29623 					good_count++;
27543859Sml29623 				mac_host_info[mac_map->param_id].flag = 1;
27553859Sml29623 			}
27563859Sml29623 		}
27573859Sml29623 		ddi_prop_free(mac_cfg_val);
27583859Sml29623 		if (good_count != mac_cnt) {
27593859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
27603859Sml29623 				nxgep->dip, prop, good_cfg, good_count);
27613859Sml29623 		}
27623859Sml29623 	}
27633859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_set_hw_mac_config"));
27643859Sml29623 }
27653859Sml29623 
27663859Sml29623 static void
27673859Sml29623 nxge_set_hw_class_config(p_nxge_t nxgep)
27683859Sml29623 {
27693859Sml29623 	int i;
27703859Sml29623 	p_nxge_param_t param_arr;
27713859Sml29623 	int *int_prop_val;
27723859Sml29623 	uint32_t cfg_value;
27733859Sml29623 	char *prop;
27743859Sml29623 	p_nxge_class_pt_cfg_t p_class_cfgp;
27753859Sml29623 	int start_prop, end_prop;
27763859Sml29623 	uint_t prop_cnt;
27773859Sml29623 
27783859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_hw_class_config"));
27793859Sml29623 
27803859Sml29623 	p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
27813859Sml29623 	param_arr = nxgep->param_arr;
27823859Sml29623 	start_prop = param_class_opt_ip_usr4;
27833859Sml29623 	end_prop = param_class_opt_ipv6_sctp;
27843859Sml29623 
27853859Sml29623 	for (i = start_prop; i <= end_prop; i++) {
27863859Sml29623 		prop = param_arr[i].fcode_name;
27873859Sml29623 		if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip,
27883859Sml29623 				0, prop, &int_prop_val,
27893859Sml29623 				&prop_cnt) == DDI_PROP_SUCCESS) {
27903859Sml29623 			cfg_value = (uint32_t)*int_prop_val;
27913859Sml29623 			ddi_prop_free(int_prop_val);
27923859Sml29623 		} else {
27933859Sml29623 			cfg_value = (uint32_t)param_arr[i].value;
27943859Sml29623 		}
27953859Sml29623 		p_class_cfgp->class_cfg[i - start_prop] = cfg_value;
27963859Sml29623 	}
27973859Sml29623 
27983859Sml29623 	prop = param_arr[param_h1_init_value].fcode_name;
27993859Sml29623 
28003859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
28013859Sml29623 			&int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
28023859Sml29623 		cfg_value = (uint32_t)*int_prop_val;
28033859Sml29623 		ddi_prop_free(int_prop_val);
28043859Sml29623 	} else {
28053859Sml29623 		cfg_value = (uint32_t)param_arr[param_h1_init_value].value;
28063859Sml29623 	}
28073859Sml29623 
28083859Sml29623 	p_class_cfgp->init_h1 = (uint32_t)cfg_value;
28093859Sml29623 	prop = param_arr[param_h2_init_value].fcode_name;
28103859Sml29623 
28113859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
28123859Sml29623 			&int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
28133859Sml29623 		cfg_value = (uint32_t)*int_prop_val;
28143859Sml29623 		ddi_prop_free(int_prop_val);
28153859Sml29623 	} else {
28163859Sml29623 		cfg_value = (uint32_t)param_arr[param_h2_init_value].value;
28173859Sml29623 	}
28183859Sml29623 
28193859Sml29623 	p_class_cfgp->init_h2 = (uint16_t)cfg_value;
28203859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_hw_class_config"));
28213859Sml29623 }
28223859Sml29623 
28233859Sml29623 nxge_status_t
28243859Sml29623 nxge_ldgv_init_n2(p_nxge_t nxgep, int *navail_p, int *nrequired_p)
28253859Sml29623 {
28266495Sspeer 	int i, maxldvs, maxldgs, nldvs;
28273859Sml29623 	int ldv, endldg;
28283859Sml29623 	uint8_t func;
28293859Sml29623 	uint8_t channel;
28303859Sml29623 	uint8_t chn_start;
28313859Sml29623 	boolean_t own_sys_err = B_FALSE, own_fzc = B_FALSE;
28323859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
28333859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
28343859Sml29623 	p_nxge_ldgv_t ldgvp;
28353859Sml29623 	p_nxge_ldg_t ldgp, ptr;
28363859Sml29623 	p_nxge_ldv_t ldvp;
28373859Sml29623 	nxge_status_t status = NXGE_OK;
28386495Sspeer 	nxge_grp_set_t *set;
28393859Sml29623 
28403859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2"));
28413859Sml29623 	if (!*navail_p) {
28423859Sml29623 		*nrequired_p = 0;
28433859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
28443859Sml29623 			"<== nxge_ldgv_init:no avail"));
28453859Sml29623 		return (NXGE_ERROR);
28463859Sml29623 	}
28473859Sml29623 	/*
28483859Sml29623 	 * N2/NIU: one logical device owns one logical group. and each
28493859Sml29623 	 * device/group will be assigned one vector by Hypervisor.
28503859Sml29623 	 */
28513859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
28523859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
28533859Sml29623 	maxldgs = p_cfgp->max_ldgs;
28543859Sml29623 	if (!maxldgs) {
28553859Sml29623 		/* No devices configured. */
28563859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_init_n2: "
28573859Sml29623 			"no logical groups configured."));
28583859Sml29623 		return (NXGE_ERROR);
28593859Sml29623 	} else {
28603859Sml29623 		maxldvs = maxldgs + 1;
28613859Sml29623 	}
28623859Sml29623 
28633859Sml29623 	/*
28643859Sml29623 	 * If function zero instance, it needs to handle the system and MIF
28653859Sml29623 	 * error interrupts. MIF interrupt may not be needed for N2/NIU.
28663859Sml29623 	 */
28673859Sml29623 	func = nxgep->function_num;
28683859Sml29623 	if (func == 0) {
28693859Sml29623 		own_sys_err = B_TRUE;
28703859Sml29623 		if (!p_cfgp->ser_ldvid) {
28713859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
28723859Sml29623 				"nxge_ldgv_init_n2: func 0, ERR ID not set!"));
28733859Sml29623 		}
28743859Sml29623 		/* MIF interrupt */
28753859Sml29623 		if (!p_cfgp->mif_ldvid) {
28763859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
28773859Sml29623 				"nxge_ldgv_init_n2: func 0, MIF ID not set!"));
28783859Sml29623 		}
28793859Sml29623 	}
28803859Sml29623 
28813859Sml29623 	/*
28823859Sml29623 	 * Assume single partition, each function owns mac.
28833859Sml29623 	 */
28843859Sml29623 	if (!nxge_use_partition)
28853859Sml29623 		own_fzc = B_TRUE;
28863859Sml29623 
28873859Sml29623 	ldgvp = nxgep->ldgvp;
28883859Sml29623 	if (ldgvp == NULL) {
28893859Sml29623 		ldgvp = KMEM_ZALLOC(sizeof (nxge_ldgv_t), KM_SLEEP);
28903859Sml29623 		nxgep->ldgvp = ldgvp;
28913859Sml29623 		ldgvp->maxldgs = (uint8_t)maxldgs;
28923859Sml29623 		ldgvp->maxldvs = (uint8_t)maxldvs;
28936495Sspeer 		ldgp = ldgvp->ldgp = KMEM_ZALLOC(
28946495Sspeer 			sizeof (nxge_ldg_t) * maxldgs, KM_SLEEP);
28956495Sspeer 		ldvp = ldgvp->ldvp = KMEM_ZALLOC(
28966495Sspeer 			sizeof (nxge_ldv_t) * maxldvs, KM_SLEEP);
28973859Sml29623 	} else {
28983859Sml29623 		ldgp = ldgvp->ldgp;
28993859Sml29623 		ldvp = ldgvp->ldvp;
29003859Sml29623 	}
29013859Sml29623 
29026495Sspeer 	ldgvp->ndma_ldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
29033859Sml29623 	ldgvp->tmres = NXGE_TIMER_RESO;
29043859Sml29623 
29053859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
29063859Sml29623 		"==> nxge_ldgv_init_n2: maxldvs %d maxldgs %d",
29073859Sml29623 		maxldvs, maxldgs));
29083859Sml29623 
29093859Sml29623 	/* logical start_ldg is ldv */
29103859Sml29623 	ptr = ldgp;
29113859Sml29623 	for (i = 0; i < maxldgs; i++) {
29123859Sml29623 		ptr->func = func;
29133859Sml29623 		ptr->arm = B_TRUE;
29143859Sml29623 		ptr->vldg_index = (uint8_t)i;
29153859Sml29623 		ptr->ldg_timer = NXGE_TIMER_LDG;
29163859Sml29623 		ptr->ldg = p_cfgp->ldg[i];
29173859Sml29623 		ptr->sys_intr_handler = nxge_intr;
29183859Sml29623 		ptr->nldvs = 0;
29193859Sml29623 		ptr->ldvp = NULL;
29203859Sml29623 		ptr->nxgep = nxgep;
29213859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
29223859Sml29623 			"==> nxge_ldgv_init_n2: maxldvs %d maxldgs %d "
29233859Sml29623 			"ldg %d ldgptr $%p",
29243859Sml29623 			maxldvs, maxldgs, ptr->ldg, ptr));
29253859Sml29623 		ptr++;
29263859Sml29623 	}
29273859Sml29623 
29283859Sml29623 	endldg = NXGE_INT_MAX_LDG;
29293859Sml29623 	nldvs = 0;
29303859Sml29623 	ldgvp->nldvs = 0;
29313859Sml29623 	ldgp->ldvp = NULL;
29323859Sml29623 	*nrequired_p = 0;
29333859Sml29623 
29343859Sml29623 	/*
29353859Sml29623 	 * logical device group table is organized in the following order (same
29363859Sml29623 	 * as what interrupt property has). function 0: owns MAC, MIF, error,
29373859Sml29623 	 * rx, tx. function 1: owns MAC, rx, tx.
29383859Sml29623 	 */
29393859Sml29623 
29403859Sml29623 	if (own_fzc && p_cfgp->mac_ldvid) {
29413859Sml29623 		/* Each function should own MAC interrupt */
29423859Sml29623 		ldv = p_cfgp->mac_ldvid;
29433859Sml29623 		ldvp->ldv = (uint8_t)ldv;
29443859Sml29623 		ldvp->is_mac = B_TRUE;
29453859Sml29623 		ldvp->ldv_intr_handler = nxge_mac_intr;
29463859Sml29623 		ldvp->ldv_ldf_masks = 0;
29473859Sml29623 		ldvp->nxgep = nxgep;
29483859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
29493859Sml29623 			"==> nxge_ldgv_init_n2(mac): maxldvs %d ldv %d "
29503859Sml29623 			"ldg %d ldgptr $%p ldvptr $%p",
29513859Sml29623 			maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
29523859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
29533859Sml29623 		nldvs++;
29543859Sml29623 	}
29553859Sml29623 
29563859Sml29623 	if (own_fzc && p_cfgp->mif_ldvid) {
29573859Sml29623 		ldv = p_cfgp->mif_ldvid;
29583859Sml29623 		ldvp->ldv = (uint8_t)ldv;
29593859Sml29623 		ldvp->is_mif = B_TRUE;
29603859Sml29623 		ldvp->ldv_intr_handler = nxge_mif_intr;
29613859Sml29623 		ldvp->ldv_ldf_masks = 0;
29623859Sml29623 		ldvp->nxgep = nxgep;
29633859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
29643859Sml29623 			"==> nxge_ldgv_init_n2(mif): maxldvs %d ldv %d "
29653859Sml29623 			"ldg %d ldgptr $%p ldvptr $%p",
29663859Sml29623 			maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
29673859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
29683859Sml29623 		nldvs++;
29693859Sml29623 	}
29703859Sml29623 
29713859Sml29623 	ldv = NXGE_SYS_ERROR_LD;
29723859Sml29623 	ldvp->use_timer = B_TRUE;
29733859Sml29623 	if (own_sys_err && p_cfgp->ser_ldvid) {
29743859Sml29623 		ldv = p_cfgp->ser_ldvid;
29753859Sml29623 		/*
29763859Sml29623 		 * Unmask the system interrupt states.
29773859Sml29623 		 */
29783859Sml29623 		(void) nxge_fzc_sys_err_mask_set(nxgep, SYS_ERR_SMX_MASK |
29793859Sml29623 			SYS_ERR_IPP_MASK | SYS_ERR_TXC_MASK |
29803859Sml29623 			SYS_ERR_ZCP_MASK);
29813859Sml29623 	}
29823859Sml29623 	ldvp->ldv = (uint8_t)ldv;
29833859Sml29623 	ldvp->is_syserr = B_TRUE;
29843859Sml29623 	ldvp->ldv_intr_handler = nxge_syserr_intr;
29853859Sml29623 	ldvp->ldv_ldf_masks = 0;
29863859Sml29623 	ldvp->nxgep = nxgep;
29873859Sml29623 	ldgvp->ldvp_syserr = ldvp;
29883859Sml29623 
29893859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
29903859Sml29623 		"==> nxge_ldgv_init_n2(syserr): maxldvs %d ldv %d "
29913859Sml29623 		"ldg %d ldgptr $%p ldvptr p%p",
29923859Sml29623 		maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
29933859Sml29623 
29943859Sml29623 	if (own_sys_err && p_cfgp->ser_ldvid) {
29953859Sml29623 		(void) nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
29963859Sml29623 	} else {
29973859Sml29623 		ldvp++;
29983859Sml29623 	}
29993859Sml29623 
30003859Sml29623 	nldvs++;
30013859Sml29623 
30023859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
30033859Sml29623 		"(before rx) func %d nldvs %d navail %d nrequired %d",
30043859Sml29623 		func, nldvs, *navail_p, *nrequired_p));
30053859Sml29623 
30063859Sml29623 	/*
30073859Sml29623 	 * Start with RDC to configure logical devices for each group.
30083859Sml29623 	 */
30096495Sspeer 	chn_start = p_cfgp->ldg_chn_start;
30106495Sspeer 	set = &nxgep->rx_set;
30116495Sspeer 	for (channel = 0; channel < NXGE_MAX_RDCS; channel++) {
30126495Sspeer 		if ((1 << channel) & set->owned.map) {
30136495Sspeer 			ldvp->is_rxdma = B_TRUE;
30146495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_RDMA_LD_START;
30156495Sspeer 			ldvp->channel = channel;
30166495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
30176495Sspeer 			ldvp->ldv_intr_handler = nxge_rx_intr;
30186495Sspeer 			ldvp->ldv_ldf_masks = 0;
30196495Sspeer 			ldvp->nxgep = nxgep;
30206495Sspeer 			ldgp->ldg = p_cfgp->ldg[chn_start];
30216495Sspeer 
30226495Sspeer 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
30236495Sspeer 			    "==> nxge_ldgv_init_n2(rx%d): maxldvs %d ldv %d "
30246495Sspeer 			    "ldg %d ldgptr 0x%016llx ldvptr 0x%016llx",
30256495Sspeer 			    i, maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
30266495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
30276495Sspeer 			    endldg, nrequired_p);
30286495Sspeer 			nldvs++;
30296495Sspeer 			chn_start++;
30306495Sspeer 		}
30313859Sml29623 	}
30323859Sml29623 
30333859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
30343859Sml29623 		"func %d nldvs %d navail %d nrequired %d",
30353859Sml29623 		func, nldvs, *navail_p, *nrequired_p));
30363859Sml29623 
30373859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
30383859Sml29623 		"func %d nldvs %d navail %d nrequired %d ldgp 0x%llx "
30393859Sml29623 		"ldvp 0x%llx",
30403859Sml29623 		func, nldvs, *navail_p, *nrequired_p, ldgp, ldvp));
30413859Sml29623 	/*
30423859Sml29623 	 * Transmit DMA channels.
30433859Sml29623 	 */
30446495Sspeer 	chn_start = p_cfgp->ldg_chn_start + 8;
30456495Sspeer 	set = &nxgep->tx_set;
30466495Sspeer 	for (channel = 0; channel < NXGE_MAX_TDCS; channel++) {
30476495Sspeer 		if ((1 << channel) & set->owned.map) {
30486495Sspeer 			ldvp->is_txdma = B_TRUE;
30496495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_TDMA_LD_START;
30506495Sspeer 			ldvp->channel = channel;
30516495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
30526495Sspeer 			ldvp->ldv_intr_handler = nxge_tx_intr;
30536495Sspeer 			ldvp->ldv_ldf_masks = 0;
30546495Sspeer 			ldgp->ldg = p_cfgp->ldg[chn_start];
30556495Sspeer 			ldvp->nxgep = nxgep;
30566495Sspeer 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
30576495Sspeer 			    "==> nxge_ldgv_init_n2(tx%d): maxldvs %d ldv %d "
30586495Sspeer 			    "ldg %d ldgptr %p ldvptr %p",
30596495Sspeer 			    channel, maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
30606495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
30616495Sspeer 			    endldg, nrequired_p);
30626495Sspeer 			nldvs++;
30636495Sspeer 			chn_start++;
30646495Sspeer 		}
30653859Sml29623 	}
30663859Sml29623 
30673859Sml29623 	ldgvp->ldg_intrs = *nrequired_p;
30683859Sml29623 	ldgvp->nldvs = (uint8_t)nldvs;
30693859Sml29623 
30703859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
30713859Sml29623 		"func %d nldvs %d maxgrps %d navail %d nrequired %d",
30723859Sml29623 		func, nldvs, maxldgs, *navail_p, *nrequired_p));
30733859Sml29623 
30743859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_init_n2"));
30753859Sml29623 	return (status);
30763859Sml29623 }
30773859Sml29623 
30783859Sml29623 /*
30793859Sml29623  * Interrupts related interface functions.
30803859Sml29623  */
30813859Sml29623 
30823859Sml29623 nxge_status_t
30833859Sml29623 nxge_ldgv_init(p_nxge_t nxgep, int *navail_p, int *nrequired_p)
30843859Sml29623 {
30856495Sspeer 	int i, maxldvs, maxldgs, nldvs;
30863859Sml29623 	int ldv, ldg, endldg, ngrps;
30873859Sml29623 	uint8_t func;
30883859Sml29623 	uint8_t channel;
30893859Sml29623 	boolean_t own_sys_err = B_FALSE, own_fzc = B_FALSE;
30903859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
30913859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
30923859Sml29623 	p_nxge_ldgv_t ldgvp;
30933859Sml29623 	p_nxge_ldg_t ldgp, ptr;
30943859Sml29623 	p_nxge_ldv_t ldvp;
30956495Sspeer 	nxge_grp_set_t *set;
30966495Sspeer 
30973859Sml29623 	nxge_status_t status = NXGE_OK;
30983859Sml29623 
30993859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init"));
31003859Sml29623 	if (!*navail_p) {
31013859Sml29623 		*nrequired_p = 0;
31023859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
31033859Sml29623 			"<== nxge_ldgv_init:no avail"));
31043859Sml29623 		return (NXGE_ERROR);
31053859Sml29623 	}
31063859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
31073859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
31083859Sml29623 
31096495Sspeer 	nldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
31103859Sml29623 
31113859Sml29623 	/*
31123859Sml29623 	 * If function zero instance, it needs to handle the system error
31133859Sml29623 	 * interrupts.
31143859Sml29623 	 */
31153859Sml29623 	func = nxgep->function_num;
31163859Sml29623 	if (func == 0) {
31173859Sml29623 		nldvs++;
31183859Sml29623 		own_sys_err = B_TRUE;
31193859Sml29623 	} else {
31203859Sml29623 		/* use timer */
31213859Sml29623 		nldvs++;
31223859Sml29623 	}
31233859Sml29623 
31243859Sml29623 	/*
31253859Sml29623 	 * Assume single partition, each function owns mac.
31263859Sml29623 	 */
31273859Sml29623 	if (!nxge_use_partition) {
31283859Sml29623 		/* mac */
31293859Sml29623 		nldvs++;
31303859Sml29623 		/* MIF */
31313859Sml29623 		nldvs++;
31323859Sml29623 		own_fzc = B_TRUE;
31333859Sml29623 	}
31343859Sml29623 	maxldvs = nldvs;
31353859Sml29623 	maxldgs = p_cfgp->max_ldgs;
31363859Sml29623 	if (!maxldvs || !maxldgs) {
31373859Sml29623 		/* No devices configured. */
31383859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_init: "
31393859Sml29623 			"no logical devices or groups configured."));
31403859Sml29623 		return (NXGE_ERROR);
31413859Sml29623 	}
31423859Sml29623 	ldgvp = nxgep->ldgvp;
31433859Sml29623 	if (ldgvp == NULL) {
31443859Sml29623 		ldgvp = KMEM_ZALLOC(sizeof (nxge_ldgv_t), KM_SLEEP);
31453859Sml29623 		nxgep->ldgvp = ldgvp;
31463859Sml29623 		ldgvp->maxldgs = (uint8_t)maxldgs;
31473859Sml29623 		ldgvp->maxldvs = (uint8_t)maxldvs;
31483859Sml29623 		ldgp = ldgvp->ldgp = KMEM_ZALLOC(sizeof (nxge_ldg_t) * maxldgs,
31493859Sml29623 			KM_SLEEP);
31503859Sml29623 		ldvp = ldgvp->ldvp = KMEM_ZALLOC(sizeof (nxge_ldv_t) * maxldvs,
31513859Sml29623 			KM_SLEEP);
31523859Sml29623 	}
31536495Sspeer 	ldgvp->ndma_ldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
31543859Sml29623 	ldgvp->tmres = NXGE_TIMER_RESO;
31553859Sml29623 
31563859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
31573859Sml29623 		"==> nxge_ldgv_init: maxldvs %d maxldgs %d nldvs %d",
31583859Sml29623 		maxldvs, maxldgs, nldvs));
31593859Sml29623 	ldg = p_cfgp->start_ldg;
31603859Sml29623 	ptr = ldgp;
31613859Sml29623 	for (i = 0; i < maxldgs; i++) {
31623859Sml29623 		ptr->func = func;
31633859Sml29623 		ptr->arm = B_TRUE;
31643859Sml29623 		ptr->vldg_index = (uint8_t)i;
31653859Sml29623 		ptr->ldg_timer = NXGE_TIMER_LDG;
31663859Sml29623 		ptr->ldg = ldg++;
31673859Sml29623 		ptr->sys_intr_handler = nxge_intr;
31683859Sml29623 		ptr->nldvs = 0;
31693859Sml29623 		ptr->nxgep = nxgep;
31703859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
31713859Sml29623 			"==> nxge_ldgv_init: maxldvs %d maxldgs %d ldg %d",
31723859Sml29623 			maxldvs, maxldgs, ptr->ldg));
31733859Sml29623 		ptr++;
31743859Sml29623 	}
31753859Sml29623 
31763859Sml29623 	ldg = p_cfgp->start_ldg;
31773859Sml29623 	if (maxldgs > *navail_p) {
31783859Sml29623 		ngrps = *navail_p;
31793859Sml29623 	} else {
31803859Sml29623 		ngrps = maxldgs;
31813859Sml29623 	}
31823859Sml29623 	endldg = ldg + ngrps;
31833859Sml29623 
31843859Sml29623 	/*
31853859Sml29623 	 * Receive DMA channels.
31863859Sml29623 	 */
31873859Sml29623 	nldvs = 0;
31883859Sml29623 	ldgvp->nldvs = 0;
31893859Sml29623 	ldgp->ldvp = NULL;
31903859Sml29623 	*nrequired_p = 0;
31913859Sml29623 
31923859Sml29623 	/*
31933859Sml29623 	 * Start with RDC to configure logical devices for each group.
31943859Sml29623 	 */
31956495Sspeer 	set = &nxgep->rx_set;
31966495Sspeer 	for (channel = 0; channel < NXGE_MAX_RDCS; channel++) {
31976495Sspeer 		if ((1 << channel) & set->owned.map) {
31986495Sspeer 			/* For now, <channel & <vdma_index> are the same. */
31996495Sspeer 			ldvp->is_rxdma = B_TRUE;
32006495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_RDMA_LD_START;
32016495Sspeer 			ldvp->channel = channel;
32026495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
32036495Sspeer 			ldvp->ldv_intr_handler = nxge_rx_intr;
32046495Sspeer 			ldvp->ldv_ldf_masks = 0;
32056495Sspeer 			ldvp->use_timer = B_FALSE;
32066495Sspeer 			ldvp->nxgep = nxgep;
32076495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
32086495Sspeer 			    endldg, nrequired_p);
32096495Sspeer 			nldvs++;
32106495Sspeer 		}
32113859Sml29623 	}
32123859Sml29623 
32133859Sml29623 	/*
32143859Sml29623 	 * Transmit DMA channels.
32153859Sml29623 	 */
32166495Sspeer 	set = &nxgep->tx_set;
32176495Sspeer 	for (channel = 0; channel < NXGE_MAX_TDCS; channel++) {
32186495Sspeer 		if ((1 << channel) & set->owned.map) {
32196495Sspeer 			/* For now, <channel & <vdma_index> are the same. */
32206495Sspeer 			ldvp->is_txdma = B_TRUE;
32216495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_TDMA_LD_START;
32226495Sspeer 			ldvp->channel = channel;
32236495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
32246495Sspeer 			ldvp->ldv_intr_handler = nxge_tx_intr;
32256495Sspeer 			ldvp->ldv_ldf_masks = 0;
32266495Sspeer 			ldvp->use_timer = B_FALSE;
32276495Sspeer 			ldvp->nxgep = nxgep;
32286495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
32296495Sspeer 			    endldg, nrequired_p);
32306495Sspeer 			nldvs++;
32316495Sspeer 		}
32323859Sml29623 	}
32333859Sml29623 
32343859Sml29623 	if (own_fzc) {
32353859Sml29623 		ldv = NXGE_MIF_LD;
32363859Sml29623 		ldvp->ldv = (uint8_t)ldv;
32373859Sml29623 		ldvp->is_mif = B_TRUE;
32383859Sml29623 		ldvp->ldv_intr_handler = nxge_mif_intr;
32393859Sml29623 		ldvp->ldv_ldf_masks = 0;
32403859Sml29623 		ldvp->use_timer = B_FALSE;
32413859Sml29623 		ldvp->nxgep = nxgep;
32423859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
32433859Sml29623 		nldvs++;
32443859Sml29623 	}
32453859Sml29623 	/*
32463859Sml29623 	 * MAC port (function zero control)
32473859Sml29623 	 */
32483859Sml29623 	if (own_fzc) {
32493859Sml29623 		ldvp->is_mac = B_TRUE;
32503859Sml29623 		ldvp->ldv_intr_handler = nxge_mac_intr;
32513859Sml29623 		ldvp->ldv_ldf_masks = 0;
32523859Sml29623 		ldv = func + NXGE_MAC_LD_START;
32533859Sml29623 		ldvp->ldv = (uint8_t)ldv;
32543859Sml29623 		ldvp->use_timer = B_FALSE;
32553859Sml29623 		ldvp->nxgep = nxgep;
32563859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
32573859Sml29623 		nldvs++;
32583859Sml29623 	}
32593859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init: "
32603859Sml29623 		"func %d nldvs %d navail %d nrequired %d",
32613859Sml29623 		func, nldvs, *navail_p, *nrequired_p));
32623859Sml29623 	/*
32633859Sml29623 	 * Function 0 owns system error interrupts.
32643859Sml29623 	 */
32653859Sml29623 	ldvp->use_timer = B_TRUE;
32663859Sml29623 	if (own_sys_err) {
32673859Sml29623 		ldv = NXGE_SYS_ERROR_LD;
32683859Sml29623 		ldvp->ldv = (uint8_t)ldv;
32693859Sml29623 		ldvp->is_syserr = B_TRUE;
32703859Sml29623 		ldvp->ldv_intr_handler = nxge_syserr_intr;
32713859Sml29623 		ldvp->ldv_ldf_masks = 0;
32723859Sml29623 		ldvp->nxgep = nxgep;
32733859Sml29623 		ldgvp->ldvp_syserr = ldvp;
32743859Sml29623 		/*
32753859Sml29623 		 * Unmask the system interrupt states.
32763859Sml29623 		 */
32773859Sml29623 		(void) nxge_fzc_sys_err_mask_set(nxgep, SYS_ERR_SMX_MASK |
32783859Sml29623 			SYS_ERR_IPP_MASK | SYS_ERR_TXC_MASK |
32793859Sml29623 			SYS_ERR_ZCP_MASK);
32803859Sml29623 
32813859Sml29623 		(void) nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
32823859Sml29623 		nldvs++;
32833859Sml29623 	} else {
32843859Sml29623 		ldv = NXGE_SYS_ERROR_LD;
32853859Sml29623 		ldvp->ldv = (uint8_t)ldv;
32863859Sml29623 		ldvp->is_syserr = B_TRUE;
32873859Sml29623 		ldvp->ldv_intr_handler = nxge_syserr_intr;
32883859Sml29623 		ldvp->nxgep = nxgep;
32893859Sml29623 		ldvp->ldv_ldf_masks = 0;
32903859Sml29623 		ldgvp->ldvp_syserr = ldvp;
32913859Sml29623 	}
32923859Sml29623 
32933859Sml29623 	ldgvp->ldg_intrs = *nrequired_p;
32943859Sml29623 
32953859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init: "
32963859Sml29623 		"func %d nldvs %d navail %d nrequired %d",
32973859Sml29623 		func, nldvs, *navail_p, *nrequired_p));
32983859Sml29623 
32993859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_init"));
33003859Sml29623 	return (status);
33013859Sml29623 }
33023859Sml29623 
33033859Sml29623 nxge_status_t
33043859Sml29623 nxge_ldgv_uninit(p_nxge_t nxgep)
33053859Sml29623 {
33063859Sml29623 	p_nxge_ldgv_t ldgvp;
33073859Sml29623 
33083859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_uninit"));
33093859Sml29623 	ldgvp = nxgep->ldgvp;
33103859Sml29623 	if (ldgvp == NULL) {
33113859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_uninit: "
33123859Sml29623 				"no logical group configured."));
33133859Sml29623 		return (NXGE_OK);
33143859Sml29623 	}
33153859Sml29623 	if (ldgvp->ldgp) {
33163859Sml29623 		KMEM_FREE(ldgvp->ldgp, sizeof (nxge_ldg_t) * ldgvp->maxldgs);
33173859Sml29623 	}
33183859Sml29623 	if (ldgvp->ldvp) {
33193859Sml29623 		KMEM_FREE(ldgvp->ldvp, sizeof (nxge_ldv_t) * ldgvp->maxldvs);
33203859Sml29623 	}
33213859Sml29623 	KMEM_FREE(ldgvp, sizeof (nxge_ldgv_t));
33223859Sml29623 	nxgep->ldgvp = NULL;
33233859Sml29623 
33243859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_uninit"));
33253859Sml29623 	return (NXGE_OK);
33263859Sml29623 }
33273859Sml29623 
33283859Sml29623 nxge_status_t
33293859Sml29623 nxge_intr_ldgv_init(p_nxge_t nxgep)
33303859Sml29623 {
33313859Sml29623 	nxge_status_t status = NXGE_OK;
33323859Sml29623 
33333859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_ldgv_init"));
33343859Sml29623 	/*
33353859Sml29623 	 * Configure the logical device group numbers, state vectors and
33363859Sml29623 	 * interrupt masks for each logical device.
33373859Sml29623 	 */
33383859Sml29623 	status = nxge_fzc_intr_init(nxgep);
33393859Sml29623 
33403859Sml29623 	/*
33413859Sml29623 	 * Configure logical device masks and timers.
33423859Sml29623 	 */
33433859Sml29623 	status = nxge_intr_mask_mgmt(nxgep);
33443859Sml29623 
33453859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_ldgv_init"));
33463859Sml29623 	return (status);
33473859Sml29623 }
33483859Sml29623 
33493859Sml29623 nxge_status_t
33503859Sml29623 nxge_intr_mask_mgmt(p_nxge_t nxgep)
33513859Sml29623 {
33523859Sml29623 	p_nxge_ldgv_t ldgvp;
33533859Sml29623 	p_nxge_ldg_t ldgp;
33543859Sml29623 	p_nxge_ldv_t ldvp;
33553859Sml29623 	npi_handle_t handle;
33563859Sml29623 	int i, j;
33573859Sml29623 	npi_status_t rs = NPI_SUCCESS;
33583859Sml29623 
33593859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_mask_mgmt"));
33603859Sml29623 
33613859Sml29623 	if ((ldgvp = nxgep->ldgvp) == NULL) {
33623859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
33633859Sml29623 			"<== nxge_intr_mask_mgmt: Null ldgvp"));
33643859Sml29623 		return (NXGE_ERROR);
33653859Sml29623 	}
33663859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
33673859Sml29623 	ldgp = ldgvp->ldgp;
33683859Sml29623 	ldvp = ldgvp->ldvp;
33693859Sml29623 	if (ldgp == NULL || ldvp == NULL) {
33703859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
33713859Sml29623 			"<== nxge_intr_mask_mgmt: Null ldgp or ldvp"));
33723859Sml29623 		return (NXGE_ERROR);
33733859Sml29623 	}
33743859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
33753859Sml29623 		"==> nxge_intr_mask_mgmt: # of intrs %d ", ldgvp->ldg_intrs));
33763859Sml29623 	/* Initialize masks. */
33773859Sml29623 	if (nxgep->niu_type != N2_NIU) {
33783859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
33793859Sml29623 			"==> nxge_intr_mask_mgmt(Neptune): # intrs %d ",
33803859Sml29623 			ldgvp->ldg_intrs));
33813859Sml29623 		for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
33823859Sml29623 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
33833859Sml29623 				"==> nxge_intr_mask_mgmt(Neptune): # ldv %d "
33843859Sml29623 				"in group %d", ldgp->nldvs, ldgp->ldg));
33853859Sml29623 			for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
33863859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
33873859Sml29623 					"==> nxge_intr_mask_mgmt: set ldv # %d "
33883859Sml29623 					"for ldg %d", ldvp->ldv, ldgp->ldg));
33893859Sml29623 				rs = npi_intr_mask_set(handle, ldvp->ldv,
33903859Sml29623 					ldvp->ldv_ldf_masks);
33913859Sml29623 				if (rs != NPI_SUCCESS) {
33923859Sml29623 					NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
33933859Sml29623 						"<== nxge_intr_mask_mgmt: "
33943859Sml29623 						"set mask failed "
33953859Sml29623 						" rs 0x%x ldv %d mask 0x%x",
33963859Sml29623 						rs, ldvp->ldv,
33973859Sml29623 						ldvp->ldv_ldf_masks));
33983859Sml29623 					return (NXGE_ERROR | rs);
33993859Sml29623 				}
34003859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
34013859Sml29623 					"==> nxge_intr_mask_mgmt: "
34023859Sml29623 					"set mask OK "
34033859Sml29623 					" rs 0x%x ldv %d mask 0x%x",
34043859Sml29623 					rs, ldvp->ldv,
34053859Sml29623 					ldvp->ldv_ldf_masks));
34063859Sml29623 			}
34073859Sml29623 		}
34083859Sml29623 	}
34093859Sml29623 	ldgp = ldgvp->ldgp;
34103859Sml29623 	/* Configure timer and arm bit */
34113859Sml29623 	for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
34123859Sml29623 		rs = npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
34133859Sml29623 			ldgp->arm, ldgp->ldg_timer);
34143859Sml29623 		if (rs != NPI_SUCCESS) {
34153859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
34163859Sml29623 				"<== nxge_intr_mask_mgmt: "
34173859Sml29623 				"set timer failed "
34183859Sml29623 				" rs 0x%x dg %d timer 0x%x",
34193859Sml29623 				rs, ldgp->ldg, ldgp->ldg_timer));
34203859Sml29623 			return (NXGE_ERROR | rs);
34213859Sml29623 		}
34223859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
34233859Sml29623 			"==> nxge_intr_mask_mgmt: "
34243859Sml29623 			"set timer OK "
34253859Sml29623 			" rs 0x%x ldg %d timer 0x%x",
34263859Sml29623 			rs, ldgp->ldg, ldgp->ldg_timer));
34273859Sml29623 	}
34283859Sml29623 
34293859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_fzc_intr_mask_mgmt"));
34303859Sml29623 	return (NXGE_OK);
34313859Sml29623 }
34323859Sml29623 
34333859Sml29623 nxge_status_t
34343859Sml29623 nxge_intr_mask_mgmt_set(p_nxge_t nxgep, boolean_t on)
34353859Sml29623 {
34363859Sml29623 	p_nxge_ldgv_t ldgvp;
34373859Sml29623 	p_nxge_ldg_t ldgp;
34383859Sml29623 	p_nxge_ldv_t ldvp;
34393859Sml29623 	npi_handle_t handle;
34403859Sml29623 	int i, j;
34413859Sml29623 	npi_status_t rs = NPI_SUCCESS;
34423859Sml29623 
34433859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
34443859Sml29623 		"==> nxge_intr_mask_mgmt_set (%d)", on));
34453859Sml29623 
34463859Sml29623 	if (nxgep->niu_type == N2_NIU) {
34473859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
34483859Sml29623 			"<== nxge_intr_mask_mgmt_set (%d) not set (N2/NIU)",
34493859Sml29623 			on));
34503859Sml29623 		return (NXGE_ERROR);
34513859Sml29623 	}
34523859Sml29623 
34533859Sml29623 	if ((ldgvp = nxgep->ldgvp) == NULL) {
34543859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
34553859Sml29623 			"==> nxge_intr_mask_mgmt_set: Null ldgvp"));
34563859Sml29623 		return (NXGE_ERROR);
34573859Sml29623 	}
34583859Sml29623 
34593859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
34603859Sml29623 	ldgp = ldgvp->ldgp;
34613859Sml29623 	ldvp = ldgvp->ldvp;
34623859Sml29623 	if (ldgp == NULL || ldvp == NULL) {
34633859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
34643859Sml29623 			"<== nxge_intr_mask_mgmt_set: Null ldgp or ldvp"));
34653859Sml29623 		return (NXGE_ERROR);
34663859Sml29623 	}
34673859Sml29623 	/* set masks. */
34683859Sml29623 	for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
34693859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
34703859Sml29623 			"==> nxge_intr_mask_mgmt_set: flag %d ldg %d"
34713859Sml29623 			"set mask nldvs %d", on, ldgp->ldg, ldgp->nldvs));
34723859Sml29623 		for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
34733859Sml29623 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
34743859Sml29623 				"==> nxge_intr_mask_mgmt_set: "
34753859Sml29623 				"for %d %d flag %d", i, j, on));
34763859Sml29623 			if (on) {
34773859Sml29623 				ldvp->ldv_ldf_masks = 0;
34783859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
34793859Sml29623 					"==> nxge_intr_mask_mgmt_set: "
34803859Sml29623 					"ON mask off"));
34813859Sml29623 			} else if (!on) {
34823859Sml29623 				ldvp->ldv_ldf_masks = (uint8_t)LD_IM1_MASK;
34833859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
34843859Sml29623 					"==> nxge_intr_mask_mgmt_set:mask on"));
34853859Sml29623 			}
34863859Sml29623 			rs = npi_intr_mask_set(handle, ldvp->ldv,
34873859Sml29623 				ldvp->ldv_ldf_masks);
34883859Sml29623 			if (rs != NPI_SUCCESS) {
34893859Sml29623 				NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
34903859Sml29623 					"==> nxge_intr_mask_mgmt_set: "
34913859Sml29623 					"set mask failed "
34923859Sml29623 					" rs 0x%x ldv %d mask 0x%x",
34933859Sml29623 					rs, ldvp->ldv, ldvp->ldv_ldf_masks));
34943859Sml29623 				return (NXGE_ERROR | rs);
34953859Sml29623 			}
34963859Sml29623 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
34973859Sml29623 				"==> nxge_intr_mask_mgmt_set: flag %d"
34983859Sml29623 				"set mask OK "
34993859Sml29623 				" ldv %d mask 0x%x",
35003859Sml29623 				on, ldvp->ldv, ldvp->ldv_ldf_masks));
35013859Sml29623 		}
35023859Sml29623 	}
35033859Sml29623 
35043859Sml29623 	ldgp = ldgvp->ldgp;
35053859Sml29623 	/* set the arm bit */
35063859Sml29623 	for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
35073859Sml29623 		if (on && !ldgp->arm) {
35083859Sml29623 			ldgp->arm = B_TRUE;
35093859Sml29623 		} else if (!on && ldgp->arm) {
35103859Sml29623 			ldgp->arm = B_FALSE;
35113859Sml29623 		}
35123859Sml29623 		rs = npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
35133859Sml29623 			ldgp->arm, ldgp->ldg_timer);
35143859Sml29623 		if (rs != NPI_SUCCESS) {
35153859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
35163859Sml29623 				"<== nxge_intr_mask_mgmt_set: "
35173859Sml29623 				"set timer failed "
35183859Sml29623 				" rs 0x%x ldg %d timer 0x%x",
35193859Sml29623 				rs, ldgp->ldg, ldgp->ldg_timer));
35203859Sml29623 			return (NXGE_ERROR | rs);
35213859Sml29623 		}
35223859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
35233859Sml29623 			"==> nxge_intr_mask_mgmt_set: OK (flag %d) "
35243859Sml29623 			"set timer "
35253859Sml29623 			" ldg %d timer 0x%x",
35263859Sml29623 			on, ldgp->ldg, ldgp->ldg_timer));
35273859Sml29623 	}
35283859Sml29623 
35293859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_mask_mgmt_set"));
35303859Sml29623 	return (NXGE_OK);
35313859Sml29623 }
35323859Sml29623 
35333859Sml29623 static nxge_status_t
35343859Sml29623 nxge_get_mac_addr_properties(p_nxge_t nxgep)
35353859Sml29623 {
35364732Sdavemq #if defined(_BIG_ENDIAN)
35373859Sml29623 	uchar_t *prop_val;
35383859Sml29623 	uint_t prop_len;
35394732Sdavemq 	uint_t j;
35404732Sdavemq #endif
35413859Sml29623 	uint_t i;
35423859Sml29623 	uint8_t func_num;
35434732Sdavemq 	boolean_t compute_macs = B_TRUE;
35443859Sml29623 
35453859Sml29623 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_get_mac_addr_properties "));
35463859Sml29623 
35473859Sml29623 #if defined(_BIG_ENDIAN)
35483859Sml29623 	/*
35493859Sml29623 	 * Get the ethernet address.
35503859Sml29623 	 */
35513859Sml29623 	(void) localetheraddr((struct ether_addr *)NULL, &nxgep->ouraddr);
35523859Sml29623 
35533859Sml29623 	/*
35543859Sml29623 	 * Check if it is an adapter with its own local mac address If it is
35553859Sml29623 	 * present, override the system mac address.
35563859Sml29623 	 */
35573859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
35583859Sml29623 			"local-mac-address", &prop_val,
35593859Sml29623 			&prop_len) == DDI_PROP_SUCCESS) {
35603859Sml29623 		if (prop_len == ETHERADDRL) {
35613859Sml29623 			nxgep->factaddr = *(p_ether_addr_t)prop_val;
35623859Sml29623 			NXGE_DEBUG_MSG((nxgep, DDI_CTL, "Local mac address = "
35633859Sml29623 				"%02x:%02x:%02x:%02x:%02x:%02x",
35643859Sml29623 				prop_val[0], prop_val[1], prop_val[2],
35653859Sml29623 				prop_val[3], prop_val[4], prop_val[5]));
35663859Sml29623 		}
35673859Sml29623 		ddi_prop_free(prop_val);
35683859Sml29623 	}
35693859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
35703859Sml29623 			"local-mac-address?", &prop_val,
35713859Sml29623 			&prop_len) == DDI_PROP_SUCCESS) {
35723859Sml29623 		if (strncmp("true", (caddr_t)prop_val, (size_t)prop_len) == 0) {
35733859Sml29623 			nxgep->ouraddr = nxgep->factaddr;
35743859Sml29623 			NXGE_DEBUG_MSG((nxgep, DDI_CTL,
35753859Sml29623 				"Using local MAC address"));
35763859Sml29623 		}
35773859Sml29623 		ddi_prop_free(prop_val);
35783859Sml29623 	} else {
35793859Sml29623 		nxgep->ouraddr = nxgep->factaddr;
35803859Sml29623 	}
35814185Sspeer 
35824977Sraghus 	if ((!nxgep->vpd_info.present) ||
35834732Sdavemq 	    (nxge_is_valid_local_mac(nxgep->factaddr)))
35844185Sspeer 		goto got_mac_addr;
35854185Sspeer 
35864185Sspeer 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "nxge_get_mac_addr_properties: "
35874185Sspeer 	    "MAC address from properties is not valid...reading from PROM"));
35884185Sspeer 
35894185Sspeer #endif
35904185Sspeer 	if (!nxgep->vpd_info.ver_valid) {
35914185Sspeer 		(void) nxge_espc_mac_addrs_get(nxgep);
35924185Sspeer 		if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
35934977Sraghus 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Failed to get "
35944977Sraghus 			    "MAC address"));
35954185Sspeer 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "EEPROM version "
35964185Sspeer 			    "[%s] invalid...please update",
35974185Sspeer 			    nxgep->vpd_info.ver));
35984185Sspeer 			return (NXGE_ERROR);
35994185Sspeer 		}
36004185Sspeer 		nxgep->ouraddr = nxgep->factaddr;
36014185Sspeer 		goto got_mac_addr;
36024185Sspeer 	}
36034185Sspeer 	/*
36044185Sspeer 	 * First get the MAC address from the info in the VPD data read
36054185Sspeer 	 * from the EEPROM.
36064185Sspeer 	 */
36074185Sspeer 	nxge_espc_get_next_mac_addr(nxgep->vpd_info.mac_addr,
36084732Sdavemq 	    nxgep->function_num, &nxgep->factaddr);
36094185Sspeer 
36104185Sspeer 	if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
36114185Sspeer 		NXGE_DEBUG_MSG((nxgep, DDI_CTL,
36124185Sspeer 		    "nxge_get_mac_addr_properties: "
36134185Sspeer 		    "MAC address in EEPROM VPD data not valid"
36144185Sspeer 		    "...reading from NCR registers"));
36154185Sspeer 		(void) nxge_espc_mac_addrs_get(nxgep);
36164185Sspeer 		if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
36174977Sraghus 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Failed to get "
36184977Sraghus 			    "MAC address"));
36194185Sspeer 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "EEPROM version "
36204185Sspeer 			    "[%s] invalid...please update",
36214185Sspeer 			    nxgep->vpd_info.ver));
36224185Sspeer 			return (NXGE_ERROR);
36234185Sspeer 		}
36244185Sspeer 	}
36254185Sspeer 
36263859Sml29623 	nxgep->ouraddr = nxgep->factaddr;
36274185Sspeer 
36284185Sspeer got_mac_addr:
36293859Sml29623 	func_num = nxgep->function_num;
36303859Sml29623 
36313859Sml29623 	/*
36324732Sdavemq 	 * Note: mac-addresses property is the list of mac addresses for a
36334732Sdavemq 	 * port. NXGE_MAX_MMAC_ADDRS is the total number of MAC addresses
36344732Sdavemq 	 * allocated for a board.
36353859Sml29623 	 */
36364732Sdavemq 	nxgep->nxge_mmac_info.total_factory_macs = NXGE_MAX_MMAC_ADDRS;
36374732Sdavemq 
36384732Sdavemq #if defined(_BIG_ENDIAN)
36394732Sdavemq 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
36404732Sdavemq 	    "mac-addresses", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
36413859Sml29623 		/*
36424732Sdavemq 		 * XAUI may have up to 18 MACs, more than the XMAC can
36434732Sdavemq 		 * use (1 unique MAC plus 16 alternate MACs)
36443859Sml29623 		 */
36454732Sdavemq 		nxgep->nxge_mmac_info.num_factory_mmac =
36464732Sdavemq 		    prop_len / ETHERADDRL - 1;
36474732Sdavemq 		if (nxgep->nxge_mmac_info.num_factory_mmac >
36484732Sdavemq 		    XMAC_MAX_ALT_ADDR_ENTRY) {
36494185Sspeer 			nxgep->nxge_mmac_info.num_factory_mmac =
36504732Sdavemq 			    XMAC_MAX_ALT_ADDR_ENTRY;
36514732Sdavemq 		}
36524732Sdavemq 
36534732Sdavemq 		for (i = 1; i <= nxgep->nxge_mmac_info.num_factory_mmac; i++) {
36544732Sdavemq 			for (j = 0; j < ETHERADDRL; j++) {
36554732Sdavemq 				nxgep->nxge_mmac_info.factory_mac_pool[i][j] =
36564732Sdavemq 				    *(prop_val + (i * ETHERADDRL) + j);
36574732Sdavemq 			}
36584732Sdavemq 			NXGE_DEBUG_MSG((nxgep, DDI_CTL,
36594732Sdavemq 			    "nxge_get_mac_addr_properties: Alt mac[%d] from "
36604732Sdavemq 			    "mac-addresses property[%2x:%2x:%2x:%2x:%2x:%2x]",
36614732Sdavemq 			    i, nxgep->nxge_mmac_info.factory_mac_pool[i][0],
36624732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][1],
36634732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][2],
36644732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][3],
36654732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][4],
36664732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][5]));
36674185Sspeer 		}
36684732Sdavemq 
36694732Sdavemq 		compute_macs = B_FALSE;
36704732Sdavemq 		ddi_prop_free(prop_val);
36714732Sdavemq 		goto got_mmac_info;
36723859Sml29623 	}
36734732Sdavemq #endif
36744732Sdavemq 	/*
36754732Sdavemq 	 * total_factory_macs = 32
36764732Sdavemq 	 * num_factory_mmac = (32 >> (nports/2)) - 1
36774732Sdavemq 	 * So if nports = 4, then num_factory_mmac =  7
36784732Sdavemq 	 *    if nports = 2, then num_factory_mmac = 15
36794732Sdavemq 	 */
36804732Sdavemq 	nxgep->nxge_mmac_info.num_factory_mmac =
36814732Sdavemq 	    ((nxgep->nxge_mmac_info.total_factory_macs >>
36824732Sdavemq 	    (nxgep->nports >> 1))) - 1;
36834732Sdavemq 
36844732Sdavemq got_mmac_info:
36854732Sdavemq 
36864732Sdavemq 	if ((nxgep->function_num < 2) &&
36874732Sdavemq 	    (nxgep->nxge_mmac_info.num_factory_mmac >
36884732Sdavemq 	    XMAC_MAX_ALT_ADDR_ENTRY)) {
36894732Sdavemq 		nxgep->nxge_mmac_info.num_factory_mmac =
36904732Sdavemq 		    XMAC_MAX_ALT_ADDR_ENTRY;
36914732Sdavemq 	} else if ((nxgep->function_num > 1) &&
36924732Sdavemq 	    (nxgep->nxge_mmac_info.num_factory_mmac >
36934732Sdavemq 	    BMAC_MAX_ALT_ADDR_ENTRY)) {
36944732Sdavemq 		nxgep->nxge_mmac_info.num_factory_mmac =
36954732Sdavemq 		    BMAC_MAX_ALT_ADDR_ENTRY;
36964185Sspeer 	}
36974185Sspeer 
36983859Sml29623 	for (i = 0; i <= nxgep->nxge_mmac_info.num_mmac; i++) {
36993859Sml29623 		(void) npi_mac_altaddr_disable(nxgep->npi_handle,
37003859Sml29623 			NXGE_GET_PORT_NUM(func_num), i);
37013859Sml29623 	}
37023859Sml29623 
37034732Sdavemq 	(void) nxge_init_mmac(nxgep, compute_macs);
37043859Sml29623 	return (NXGE_OK);
37053859Sml29623 }
37063859Sml29623 
37073859Sml29623 void
37083859Sml29623 nxge_get_xcvr_properties(p_nxge_t nxgep)
37093859Sml29623 {
37103859Sml29623 	uchar_t *prop_val;
37113859Sml29623 	uint_t prop_len;
37123859Sml29623 
37133859Sml29623 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_get_xcvr_properties"));
37143859Sml29623 
37153859Sml29623 	/*
37163859Sml29623 	 * Read the type of physical layer interface being used.
37173859Sml29623 	 */
37183859Sml29623 	nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
37193859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
37203859Sml29623 			"phy-type", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
37213859Sml29623 		if (strncmp("pcs", (caddr_t)prop_val,
37223859Sml29623 				(size_t)prop_len) == 0) {
37233859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = PCS_XCVR;
37243859Sml29623 		} else {
37253859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
37263859Sml29623 		}
37273859Sml29623 		ddi_prop_free(prop_val);
37283859Sml29623 	} else if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
37293859Sml29623 			"phy-interface", &prop_val,
37303859Sml29623 			&prop_len) == DDI_PROP_SUCCESS) {
37313859Sml29623 		if (strncmp("pcs", (caddr_t)prop_val, (size_t)prop_len) == 0) {
37323859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = PCS_XCVR;
37333859Sml29623 		} else {
37343859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
37353859Sml29623 		}
37363859Sml29623 		ddi_prop_free(prop_val);
37373859Sml29623 	}
37383859Sml29623 }
37393859Sml29623 
37403859Sml29623 /*
37413859Sml29623  * Static functions start here.
37423859Sml29623  */
37433859Sml29623 
37443859Sml29623 static void
37453859Sml29623 nxge_ldgv_setup(p_nxge_ldg_t *ldgp, p_nxge_ldv_t *ldvp, uint8_t ldv,
37463859Sml29623 	uint8_t endldg, int *ngrps)
37473859Sml29623 {
37483859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup"));
37493859Sml29623 	/* Assign the group number for each device. */
37503859Sml29623 	(*ldvp)->ldg_assigned = (*ldgp)->ldg;
37513859Sml29623 	(*ldvp)->ldgp = *ldgp;
37523859Sml29623 	(*ldvp)->ldv = ldv;
37533859Sml29623 
37543859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup: "
37553859Sml29623 		"ldv %d endldg %d ldg %d, ldvp $%p",
37563859Sml29623 		ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
37573859Sml29623 
37583859Sml29623 	(*ldgp)->nldvs++;
37593859Sml29623 	if ((*ldgp)->ldg == (endldg - 1)) {
37603859Sml29623 		if ((*ldgp)->ldvp == NULL) {
37613859Sml29623 			(*ldgp)->ldvp = *ldvp;
37623859Sml29623 			*ngrps += 1;
37633859Sml29623 			NXGE_DEBUG_MSG((NULL, INT_CTL,
37643859Sml29623 				"==> nxge_ldgv_setup: ngrps %d", *ngrps));
37653859Sml29623 		}
37663859Sml29623 		NXGE_DEBUG_MSG((NULL, INT_CTL,
37673859Sml29623 			"==> nxge_ldgv_setup: ldvp $%p ngrps %d",
37683859Sml29623 			*ldvp, *ngrps));
37693859Sml29623 		++*ldvp;
37703859Sml29623 	} else {
37713859Sml29623 		(*ldgp)->ldvp = *ldvp;
37723859Sml29623 		*ngrps += 1;
37733859Sml29623 		NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup(done): "
37743859Sml29623 			"ldv %d endldg %d ldg %d, ldvp $%p",
37753859Sml29623 			ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
37763859Sml29623 		(*ldvp) = ++*ldvp;
37773859Sml29623 		(*ldgp) = ++*ldgp;
37783859Sml29623 		NXGE_DEBUG_MSG((NULL, INT_CTL,
37793859Sml29623 			"==> nxge_ldgv_setup: new ngrps %d", *ngrps));
37803859Sml29623 	}
37813859Sml29623 
37823859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup: "
37833859Sml29623 		"ldv %d ldvp $%p endldg %d ngrps %d",
37843859Sml29623 		ldv, ldvp, endldg, *ngrps));
37853859Sml29623 
37863859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "<== nxge_ldgv_setup"));
37873859Sml29623 }
37883859Sml29623 
37893859Sml29623 /*
37903859Sml29623  * Note: This function assumes the following distribution of mac
37913859Sml29623  * addresses among 4 ports in neptune:
37923859Sml29623  *
37933859Sml29623  *      -------------
37943859Sml29623  *    0|            |0 - local-mac-address for fn 0
37953859Sml29623  *      -------------
37963859Sml29623  *    1|            |1 - local-mac-address for fn 1
37973859Sml29623  *      -------------
37983859Sml29623  *    2|            |2 - local-mac-address for fn 2
37993859Sml29623  *      -------------
38003859Sml29623  *    3|            |3 - local-mac-address for fn 3
38013859Sml29623  *      -------------
38023859Sml29623  *     |            |4 - Start of alt. mac addr. for fn 0
38033859Sml29623  *     |            |
38043859Sml29623  *     |            |
38053859Sml29623  *     |            |10
38063859Sml29623  *     --------------
38073859Sml29623  *     |            |11 - Start of alt. mac addr. for fn 1
38083859Sml29623  *     |            |
38093859Sml29623  *     |            |
38103859Sml29623  *     |            |17
38113859Sml29623  *     --------------
38123859Sml29623  *     |            |18 - Start of alt. mac addr. for fn 2
38133859Sml29623  *     |            |
38143859Sml29623  *     |            |
38153859Sml29623  *     |            |24
38163859Sml29623  *     --------------
38173859Sml29623  *     |            |25 - Start of alt. mac addr. for fn 3
38183859Sml29623  *     |            |
38193859Sml29623  *     |            |
38203859Sml29623  *     |            |31
38213859Sml29623  *     --------------
38223859Sml29623  *
38233859Sml29623  * For N2/NIU the mac addresses is from XAUI card.
38244732Sdavemq  *
38254732Sdavemq  * When 'compute_addrs' is true, the alternate mac addresses are computed
38264732Sdavemq  * using the unique mac address as base. Otherwise the alternate addresses
38274732Sdavemq  * are assigned from the list read off the 'mac-addresses' property.
38283859Sml29623  */
38293859Sml29623 
38303859Sml29623 static void
38314732Sdavemq nxge_init_mmac(p_nxge_t nxgep, boolean_t compute_addrs)
38323859Sml29623 {
38333859Sml29623 	int slot;
38343859Sml29623 	uint8_t func_num;
38353859Sml29623 	uint16_t *base_mmac_addr;
38363859Sml29623 	uint32_t alt_mac_ls4b;
38373859Sml29623 	uint16_t *mmac_addr;
38383859Sml29623 	uint32_t base_mac_ls4b; /* least significant 4 bytes */
38393859Sml29623 	nxge_mmac_t *mmac_info;
38403859Sml29623 	npi_mac_addr_t mac_addr;
38413859Sml29623 
38423859Sml29623 	func_num = nxgep->function_num;
38433859Sml29623 	base_mmac_addr = (uint16_t *)&nxgep->factaddr;
38443859Sml29623 	mmac_info = (nxge_mmac_t *)&nxgep->nxge_mmac_info;
38453859Sml29623 
38464732Sdavemq 	if (compute_addrs) {
38474732Sdavemq 		base_mac_ls4b = ((uint32_t)base_mmac_addr[1]) << 16 |
38484732Sdavemq 		    base_mmac_addr[2];
38494732Sdavemq 
38504732Sdavemq 		if (nxgep->niu_type == N2_NIU) {
38514732Sdavemq 			/* ls4b of 1st altmac */
38524732Sdavemq 			alt_mac_ls4b = base_mac_ls4b + 1;
38534732Sdavemq 		} else {			/* Neptune */
38544732Sdavemq 			alt_mac_ls4b = base_mac_ls4b +
38554732Sdavemq 			    (nxgep->nports - func_num) +
38564732Sdavemq 			    (func_num * (mmac_info->num_factory_mmac));
38574732Sdavemq 		}
38583859Sml29623 	}
38593859Sml29623 
38603859Sml29623 	/* Set flags for unique MAC */
38613859Sml29623 	mmac_info->mac_pool[0].flags |= MMAC_SLOT_USED | MMAC_VENDOR_ADDR;
38623859Sml29623 
38633859Sml29623 	/* Clear flags of all alternate MAC slots */
38643859Sml29623 	for (slot = 1; slot <= mmac_info->num_mmac; slot++) {
38653859Sml29623 		if (slot <= mmac_info->num_factory_mmac)
38663859Sml29623 			mmac_info->mac_pool[slot].flags = MMAC_VENDOR_ADDR;
38673859Sml29623 		else
38683859Sml29623 			mmac_info->mac_pool[slot].flags = 0;
38693859Sml29623 	}
38703859Sml29623 
38713859Sml29623 	/* Generate and store factory alternate MACs */
38723859Sml29623 	for (slot = 1; slot <= mmac_info->num_factory_mmac; slot++) {
38733859Sml29623 		mmac_addr = (uint16_t *)&mmac_info->factory_mac_pool[slot];
38744732Sdavemq 		if (compute_addrs) {
38754732Sdavemq 			mmac_addr[0] = base_mmac_addr[0];
38764732Sdavemq 			mac_addr.w2 = mmac_addr[0];
38774732Sdavemq 
38784732Sdavemq 			mmac_addr[1] = (alt_mac_ls4b >> 16) & 0x0FFFF;
38794732Sdavemq 			mac_addr.w1 = mmac_addr[1];
38804732Sdavemq 
38814732Sdavemq 			mmac_addr[2] = alt_mac_ls4b & 0x0FFFF;
38824732Sdavemq 			mac_addr.w0 = mmac_addr[2];
38834732Sdavemq 
38844732Sdavemq 			alt_mac_ls4b++;
38854732Sdavemq 		} else {
38864732Sdavemq 			mac_addr.w2 = mmac_addr[0];
38874732Sdavemq 			mac_addr.w1 = mmac_addr[1];
38884732Sdavemq 			mac_addr.w0 = mmac_addr[2];
38894732Sdavemq 		}
38904732Sdavemq 
38914732Sdavemq 		NXGE_DEBUG_MSG((nxgep, DDI_CTL,
38924732Sdavemq 		    "mac_pool_addr[%2x:%2x:%2x:%2x:%2x:%2x] npi_addr[%x%x%x]",
38934732Sdavemq 		    mmac_info->factory_mac_pool[slot][0],
38944732Sdavemq 		    mmac_info->factory_mac_pool[slot][1],
38954732Sdavemq 		    mmac_info->factory_mac_pool[slot][2],
38964732Sdavemq 		    mmac_info->factory_mac_pool[slot][3],
38974732Sdavemq 		    mmac_info->factory_mac_pool[slot][4],
38984732Sdavemq 		    mmac_info->factory_mac_pool[slot][5],
38994732Sdavemq 		    mac_addr.w0, mac_addr.w1, mac_addr.w2));
39003859Sml29623 		/*
39014732Sdavemq 		 * slot minus 1 because npi_mac_altaddr_entry expects 0
39023859Sml29623 		 * for the first alternate mac address.
39033859Sml29623 		 */
39043859Sml29623 		(void) npi_mac_altaddr_entry(nxgep->npi_handle, OP_SET,
39053859Sml29623 			NXGE_GET_PORT_NUM(func_num), slot - 1, &mac_addr);
39063859Sml29623 	}
39073859Sml29623 	/* Initialize the first two parameters for mmac kstat */
39083859Sml29623 	nxgep->statsp->mmac_stats.mmac_max_cnt = mmac_info->num_mmac;
39093859Sml29623 	nxgep->statsp->mmac_stats.mmac_avail_cnt = mmac_info->num_mmac;
39103859Sml29623 }
3911