xref: /onnv-gate/usr/src/uts/common/io/nxge/nxge_virtual.c (revision 12452:80e5df69a097)
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 /*
22*12452SSantwona.Behera@oracle.COM  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
233859Sml29623  */
243859Sml29623 
253859Sml29623 #include <sys/nxge/nxge_impl.h>
263859Sml29623 #include <sys/nxge/nxge_mac.h>
276495Sspeer #include <sys/nxge/nxge_hio.h>
283859Sml29623 
299015SMichael.Speer@Sun.COM /*
309015SMichael.Speer@Sun.COM  * Local defines for FWARC 2006/556
319015SMichael.Speer@Sun.COM  */
329015SMichael.Speer@Sun.COM #define	NXGE_NIU_TDMA_PROP_LEN		2
339015SMichael.Speer@Sun.COM #define	NXGE_NIU_RDMA_PROP_LEN		2
349015SMichael.Speer@Sun.COM #define	NXGE_NIU_0_INTR_PROP_LEN	19
359015SMichael.Speer@Sun.COM #define	NXGE_NIU_1_INTR_PROP_LEN	17
369015SMichael.Speer@Sun.COM 
379015SMichael.Speer@Sun.COM /*
389015SMichael.Speer@Sun.COM  * Local functions.
399015SMichael.Speer@Sun.COM  */
403859Sml29623 static void nxge_get_niu_property(dev_info_t *, niu_type_t *);
413859Sml29623 static nxge_status_t nxge_get_mac_addr_properties(p_nxge_t);
423859Sml29623 static nxge_status_t nxge_use_cfg_n2niu_properties(p_nxge_t);
433859Sml29623 static void nxge_use_cfg_neptune_properties(p_nxge_t);
443859Sml29623 static void nxge_use_cfg_dma_config(p_nxge_t);
453859Sml29623 static void nxge_use_cfg_vlan_class_config(p_nxge_t);
463859Sml29623 static void nxge_use_cfg_mac_class_config(p_nxge_t);
473859Sml29623 static void nxge_use_cfg_class_config(p_nxge_t);
483859Sml29623 static void nxge_use_cfg_link_cfg(p_nxge_t);
493859Sml29623 static void nxge_set_hw_dma_config(p_nxge_t);
503859Sml29623 static void nxge_set_hw_vlan_class_config(p_nxge_t);
513859Sml29623 static void nxge_set_hw_mac_class_config(p_nxge_t);
523859Sml29623 static void nxge_set_hw_class_config(p_nxge_t);
533859Sml29623 static nxge_status_t nxge_use_default_dma_config_n2(p_nxge_t);
543859Sml29623 static void nxge_ldgv_setup(p_nxge_ldg_t *, p_nxge_ldv_t *, uint8_t,
553859Sml29623 	uint8_t, int *);
564732Sdavemq static void nxge_init_mmac(p_nxge_t, boolean_t);
576495Sspeer static void nxge_set_rdc_intr_property(p_nxge_t);
583859Sml29623 
593859Sml29623 uint32_t nxge_use_hw_property = 1;
603859Sml29623 uint32_t nxge_groups_per_port = 2;
613859Sml29623 
623859Sml29623 extern uint32_t nxge_use_partition;
633859Sml29623 extern uint32_t nxge_dma_obp_props_only;
643859Sml29623 
653859Sml29623 extern uint_t nxge_rx_intr(void *, void *);
663859Sml29623 extern uint_t nxge_tx_intr(void *, void *);
673859Sml29623 extern uint_t nxge_mif_intr(void *, void *);
683859Sml29623 extern uint_t nxge_mac_intr(void *, void *);
693859Sml29623 extern uint_t nxge_syserr_intr(void *, void *);
703859Sml29623 extern void *nxge_list;
713859Sml29623 
723859Sml29623 #define	NXGE_SHARED_REG_SW_SIM
733859Sml29623 
743859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
753859Sml29623 uint64_t global_dev_ctrl = 0;
763859Sml29623 #endif
773859Sml29623 
783859Sml29623 #define	MAX_SIBLINGS	NXGE_MAX_PORTS
793859Sml29623 
803859Sml29623 extern uint32_t nxge_rbr_size;
813859Sml29623 extern uint32_t nxge_rcr_size;
823859Sml29623 extern uint32_t nxge_tx_ring_size;
833859Sml29623 extern uint32_t nxge_rbr_spare_size;
843859Sml29623 
853859Sml29623 extern npi_status_t npi_mac_altaddr_disable(npi_handle_t, uint8_t, uint8_t);
863859Sml29623 
873859Sml29623 static uint8_t p2_tx_fair[2] = {12, 12};
883859Sml29623 static uint8_t p2_tx_equal[2] = {12, 12};
893859Sml29623 static uint8_t p4_tx_fair[4] = {6, 6, 6, 6};
903859Sml29623 static uint8_t p4_tx_equal[4] = {6, 6, 6, 6};
913859Sml29623 static uint8_t p2_rx_fair[2] = {8, 8};
923859Sml29623 static uint8_t p2_rx_equal[2] = {8, 8};
933859Sml29623 static uint8_t p4_rx_fair[4] = {4, 4, 4, 4};
943859Sml29623 static uint8_t p4_rx_equal[4] = {4, 4, 4, 4};
953859Sml29623 
963859Sml29623 static uint8_t p2_rdcgrp_fair[2] = {4, 4};
973859Sml29623 static uint8_t p2_rdcgrp_equal[2] = {4, 4};
983859Sml29623 static uint8_t p4_rdcgrp_fair[4] = {2, 2, 1, 1};
993859Sml29623 static uint8_t p4_rdcgrp_equal[4] = {2, 2, 2, 2};
1003859Sml29623 static uint8_t p2_rdcgrp_cls[2] = {1, 1};
1013859Sml29623 static uint8_t p4_rdcgrp_cls[4] = {1, 1, 1, 1};
1023859Sml29623 
1034732Sdavemq static uint8_t rx_4_1G[4] = {4, 4, 4, 4};
1044732Sdavemq static uint8_t rx_2_10G[2] = {8, 8};
1054732Sdavemq static uint8_t rx_2_10G_2_1G[4] = {6, 6, 2, 2};
1064732Sdavemq static uint8_t rx_1_10G_3_1G[4] = {10, 2, 2, 2};
1074732Sdavemq static uint8_t rx_1_1G_1_10G_2_1G[4] = {2, 10, 2, 2};
1084732Sdavemq 
1094732Sdavemq static uint8_t tx_4_1G[4] = {6, 6, 6, 6};
1104732Sdavemq static uint8_t tx_2_10G[2] = {12, 12};
1114732Sdavemq static uint8_t tx_2_10G_2_1G[4] = {10, 10, 2, 2};
1124732Sdavemq static uint8_t tx_1_10G_3_1G[4] = {12, 4, 4, 4};
1134732Sdavemq static uint8_t tx_1_1G_1_10G_2_1G[4] = {4, 12, 4, 4};
1144732Sdavemq 
1153859Sml29623 typedef enum {
1163859Sml29623 	DEFAULT = 0,
1173859Sml29623 	EQUAL,
1183859Sml29623 	FAIR,
1193859Sml29623 	CUSTOM,
1203859Sml29623 	CLASSIFY,
1213859Sml29623 	L2_CLASSIFY,
1223859Sml29623 	L3_DISTRIBUTE,
1233859Sml29623 	L3_CLASSIFY,
1243859Sml29623 	L3_TCAM,
1253859Sml29623 	CONFIG_TOKEN_NONE
1263859Sml29623 } config_token_t;
1273859Sml29623 
1283859Sml29623 static char *token_names[] = {
1293859Sml29623 	"default",
1303859Sml29623 	"equal",
1313859Sml29623 	"fair",
1323859Sml29623 	"custom",
1333859Sml29623 	"classify",
1343859Sml29623 	"l2_classify",
1353859Sml29623 	"l3_distribute",
1363859Sml29623 	"l3_classify",
1373859Sml29623 	"l3_tcam",
1383859Sml29623 	"none",
1393859Sml29623 };
1403859Sml29623 
1413859Sml29623 void nxge_virint_regs_dump(p_nxge_t nxgep);
1423859Sml29623 
1433859Sml29623 void
nxge_virint_regs_dump(p_nxge_t nxgep)1443859Sml29623 nxge_virint_regs_dump(p_nxge_t nxgep)
1453859Sml29623 {
1463859Sml29623 	npi_handle_t handle;
1473859Sml29623 
1483859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_virint_regs_dump"));
1493859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
1503859Sml29623 	(void) npi_vir_dump_pio_fzc_regs_one(handle);
1513859Sml29623 	(void) npi_vir_dump_ldgnum(handle);
1523859Sml29623 	(void) npi_vir_dump_ldsv(handle);
1533859Sml29623 	(void) npi_vir_dump_imask0(handle);
1543859Sml29623 	(void) npi_vir_dump_sid(handle);
1553859Sml29623 	(void) npi_mac_dump_regs(handle, nxgep->function_num);
1563859Sml29623 	(void) npi_ipp_dump_regs(handle, nxgep->function_num);
1573859Sml29623 	(void) npi_fflp_dump_regs(handle);
1583859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_virint_regs_dump"));
1593859Sml29623 }
1603859Sml29623 
1613859Sml29623 /*
1623859Sml29623  * For now: we hard coded the DMA configurations.
1633859Sml29623  *	    and assume for one partition only.
1643859Sml29623  *
1653859Sml29623  *       OBP. Then OBP will pass this partition's
1663859Sml29623  *	 Neptune configurations to fcode to create
1673859Sml29623  *	 properties for them.
1683859Sml29623  *
1693859Sml29623  *	Since Neptune(PCI-E) and NIU (Niagara-2) has
1703859Sml29623  *	different bus interfaces, the driver needs
1713859Sml29623  *	to know which bus it is connected to.
1723859Sml29623  *  	Ravinder suggested: create a device property.
1733859Sml29623  *	In partitioning environment, we cannot
1743859Sml29623  *	use .conf file (need to check). If conf changes,
1753859Sml29623  *	need to reboot the system.
1763859Sml29623  *	The following function assumes that we will
1773859Sml29623  *	retrieve its properties from a virtualized nexus driver.
1783859Sml29623  */
1793859Sml29623 
1803859Sml29623 nxge_status_t
nxge_cntlops(dev_info_t * dip,nxge_ctl_enum_t ctlop,void * arg,void * result)1813859Sml29623 nxge_cntlops(dev_info_t *dip, nxge_ctl_enum_t ctlop, void *arg, void *result)
1823859Sml29623 {
1833859Sml29623 	nxge_status_t status = NXGE_OK;
1843859Sml29623 	int instance;
1853859Sml29623 	p_nxge_t nxgep;
1863859Sml29623 
1873859Sml29623 #ifndef NXGE_SHARED_REG_SW_SIM
1883859Sml29623 	npi_handle_t handle;
1893859Sml29623 	uint16_t sr16, cr16;
1903859Sml29623 #endif
1913859Sml29623 	instance = ddi_get_instance(dip);
1923859Sml29623 	NXGE_DEBUG_MSG((NULL, VIR_CTL, "Instance %d ", instance));
1933859Sml29623 
1943859Sml29623 	if (nxge_list == NULL) {
1953859Sml29623 		NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
1966929Smisaki 		    "nxge_cntlops: nxge_list null"));
1973859Sml29623 		return (NXGE_ERROR);
1983859Sml29623 	}
1993859Sml29623 	nxgep = (p_nxge_t)ddi_get_soft_state(nxge_list, instance);
2003859Sml29623 	if (nxgep == NULL) {
2013859Sml29623 		NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
2026929Smisaki 		    "nxge_cntlops: nxgep null"));
2033859Sml29623 		return (NXGE_ERROR);
2043859Sml29623 	}
2053859Sml29623 #ifndef NXGE_SHARED_REG_SW_SIM
2063859Sml29623 	handle = nxgep->npi_reg_handle;
2073859Sml29623 #endif
2083859Sml29623 	switch (ctlop) {
2093859Sml29623 	case NXGE_CTLOPS_NIUTYPE:
2103859Sml29623 		nxge_get_niu_property(dip, (niu_type_t *)result);
2113859Sml29623 		return (status);
2123859Sml29623 
2133859Sml29623 	case NXGE_CTLOPS_GET_SHARED_REG:
2143859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2153859Sml29623 		*(uint64_t *)result = global_dev_ctrl;
2163859Sml29623 		return (0);
2173859Sml29623 #else
2183859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2193859Sml29623 		*(uint16_t *)result = sr16;
2203859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2216929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_GET_SHARED_REG"));
2223859Sml29623 		return (0);
2233859Sml29623 #endif
2243859Sml29623 
2253859Sml29623 	case NXGE_CTLOPS_SET_SHARED_REG_LOCK:
2263859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2273859Sml29623 		global_dev_ctrl = *(uint64_t *)arg;
2283859Sml29623 		return (0);
2293859Sml29623 #else
2303859Sml29623 		status = NPI_FAILURE;
2313859Sml29623 		while (status != NPI_SUCCESS)
2323859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
2333859Sml29623 
2343859Sml29623 		sr16 = *(uint16_t *)arg;
2353859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2363859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
2373859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2386929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2393859Sml29623 		return (0);
2403859Sml29623 #endif
2413859Sml29623 
2423859Sml29623 	case NXGE_CTLOPS_UPDATE_SHARED_REG:
2433859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2443859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2453859Sml29623 		return (0);
2463859Sml29623 #else
2473859Sml29623 		status = NPI_FAILURE;
2483859Sml29623 		while (status != NPI_SUCCESS)
2493859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
2503859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2513859Sml29623 		sr16 |= *(uint16_t *)arg;
2523859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2533859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
2543859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2556929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2563859Sml29623 		return (0);
2573859Sml29623 #endif
2583859Sml29623 
2593859Sml29623 	case NXGE_CTLOPS_CLEAR_BIT_SHARED_REG_UL:
2603859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2613859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2623859Sml29623 		return (0);
2633859Sml29623 #else
2643859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2653859Sml29623 		cr16 = *(uint16_t *)arg;
2663859Sml29623 		sr16 &= ~cr16;
2673859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2683859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2696929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2703859Sml29623 		return (0);
2713859Sml29623 #endif
2723859Sml29623 
2733859Sml29623 	case NXGE_CTLOPS_CLEAR_BIT_SHARED_REG:
2743859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2753859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2763859Sml29623 		return (0);
2773859Sml29623 #else
2783859Sml29623 		status = NPI_FAILURE;
2793859Sml29623 		while (status != NPI_SUCCESS)
2803859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
2813859Sml29623 		status = npi_dev_func_sr_sr_get(handle, &sr16);
2823859Sml29623 		cr16 = *(uint16_t *)arg;
2833859Sml29623 		sr16 &= ~cr16;
2843859Sml29623 		status = npi_dev_func_sr_sr_set_only(handle, &sr16);
2853859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
2863859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
2876929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
2883859Sml29623 		return (0);
2893859Sml29623 #endif
2903859Sml29623 
2913859Sml29623 	case NXGE_CTLOPS_GET_LOCK_BLOCK:
2923859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
2933859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
2943859Sml29623 		return (0);
2953859Sml29623 #else
2963859Sml29623 		status = NPI_FAILURE;
2973859Sml29623 		while (status != NPI_SUCCESS)
2983859Sml29623 			status = npi_dev_func_sr_lock_enter(handle);
2993859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
3006929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_GET_LOCK_BLOCK"));
3013859Sml29623 		return (0);
3023859Sml29623 #endif
3033859Sml29623 	case NXGE_CTLOPS_GET_LOCK_TRY:
3043859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
3053859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
3063859Sml29623 		return (0);
3073859Sml29623 #else
3083859Sml29623 		status = npi_dev_func_sr_lock_enter(handle);
3093859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
3106929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_GET_LOCK_TRY"));
3113859Sml29623 		if (status == NPI_SUCCESS)
3123859Sml29623 			return (NXGE_OK);
3133859Sml29623 		else
3143859Sml29623 			return (NXGE_ERROR);
3153859Sml29623 #endif
3163859Sml29623 	case NXGE_CTLOPS_FREE_LOCK:
3173859Sml29623 #ifdef NXGE_SHARED_REG_SW_SIM
3183859Sml29623 		global_dev_ctrl |= *(uint64_t *)arg;
3193859Sml29623 		return (0);
3203859Sml29623 #else
3213859Sml29623 		status = npi_dev_func_sr_lock_free(handle);
3223859Sml29623 		NXGE_DEBUG_MSG((NULL, VIR_CTL,
3236929Smisaki 		    "nxge_cntlops: NXGE_CTLOPS_GET_LOCK_FREE"));
3243859Sml29623 		if (status == NPI_SUCCESS)
3253859Sml29623 			return (NXGE_OK);
3263859Sml29623 		else
3273859Sml29623 			return (NXGE_ERROR);
3283859Sml29623 #endif
3293859Sml29623 
3303859Sml29623 	default:
3313859Sml29623 		status = NXGE_ERROR;
3323859Sml29623 	}
3333859Sml29623 
3343859Sml29623 	return (status);
3353859Sml29623 }
3363859Sml29623 
3373859Sml29623 void
nxge_common_lock_get(p_nxge_t nxgep)3383859Sml29623 nxge_common_lock_get(p_nxge_t nxgep)
3393859Sml29623 {
3403859Sml29623 	uint32_t status = NPI_FAILURE;
3413859Sml29623 	npi_handle_t handle;
3423859Sml29623 
3433859Sml29623 #if	defined(NXGE_SHARE_REG_SW_SIM)
3443859Sml29623 	return;
3453859Sml29623 #endif
3463859Sml29623 	handle = nxgep->npi_reg_handle;
3473859Sml29623 	while (status != NPI_SUCCESS)
3483859Sml29623 		status = npi_dev_func_sr_lock_enter(handle);
3493859Sml29623 }
3503859Sml29623 
3513859Sml29623 void
nxge_common_lock_free(p_nxge_t nxgep)3523859Sml29623 nxge_common_lock_free(p_nxge_t nxgep)
3533859Sml29623 {
3543859Sml29623 	npi_handle_t handle;
3553859Sml29623 
3563859Sml29623 #if	defined(NXGE_SHARE_REG_SW_SIM)
3573859Sml29623 	return;
3583859Sml29623 #endif
3593859Sml29623 	handle = nxgep->npi_reg_handle;
3603859Sml29623 	(void) npi_dev_func_sr_lock_free(handle);
3613859Sml29623 }
3623859Sml29623 
3634185Sspeer 
3643859Sml29623 static void
nxge_get_niu_property(dev_info_t * dip,niu_type_t * niu_type)3653859Sml29623 nxge_get_niu_property(dev_info_t *dip, niu_type_t *niu_type)
3663859Sml29623 {
3673859Sml29623 	uchar_t *prop_val;
3683859Sml29623 	uint_t prop_len;
3693859Sml29623 
3704732Sdavemq 	*niu_type = NIU_TYPE_NONE;
3713859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0,
3726929Smisaki 	    "niu-type", (uchar_t **)&prop_val,
3736929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
3743859Sml29623 		if (strncmp("niu", (caddr_t)prop_val, (size_t)prop_len) == 0) {
3753859Sml29623 			*niu_type = N2_NIU;
3763859Sml29623 		}
3773859Sml29623 		ddi_prop_free(prop_val);
3783859Sml29623 	}
3793859Sml29623 }
3803859Sml29623 
3813859Sml29623 static config_token_t
nxge_get_config_token(char * prop)3823859Sml29623 nxge_get_config_token(char *prop)
3833859Sml29623 {
3843859Sml29623 	config_token_t token = DEFAULT;
3853859Sml29623 
3863859Sml29623 	while (token < CONFIG_TOKEN_NONE) {
3873859Sml29623 		if (strncmp(prop, token_names[token], 4) == 0)
3883859Sml29623 			break;
3893859Sml29623 		token++;
3903859Sml29623 	}
3913859Sml29623 	return (token);
3923859Sml29623 }
3933859Sml29623 
3943859Sml29623 /* per port */
3953859Sml29623 
3963859Sml29623 static nxge_status_t
nxge_update_rxdma_grp_properties(p_nxge_t nxgep,config_token_t token,dev_info_t * s_dip[])3973859Sml29623 nxge_update_rxdma_grp_properties(p_nxge_t nxgep, config_token_t token,
3983859Sml29623 	dev_info_t *s_dip[])
3993859Sml29623 {
4003859Sml29623 	nxge_status_t status = NXGE_OK;
4013859Sml29623 	int ddi_status;
4023859Sml29623 	int num_ports = nxgep->nports;
4033859Sml29623 	int port, bits, j;
4043859Sml29623 	uint8_t start_grp = 0, num_grps = 0;
4053859Sml29623 	p_nxge_param_t param_arr;
4063859Sml29623 	uint32_t grp_bitmap[MAX_SIBLINGS];
4073859Sml29623 	int custom_start_grp[MAX_SIBLINGS];
4083859Sml29623 	int custom_num_grp[MAX_SIBLINGS];
4093859Sml29623 	uint8_t bad_config = B_FALSE;
4103859Sml29623 	char *start_prop, *num_prop, *cfg_prop;
4113859Sml29623 
4123859Sml29623 	start_grp = 0;
4133859Sml29623 	param_arr = nxgep->param_arr;
4143859Sml29623 	start_prop = param_arr[param_rdc_grps_start].fcode_name;
4153859Sml29623 	num_prop = param_arr[param_rx_rdc_grps].fcode_name;
4163859Sml29623 
4173859Sml29623 	switch (token) {
4183859Sml29623 	case FAIR:
4193859Sml29623 		cfg_prop = "fair";
4203859Sml29623 		for (port = 0; port < num_ports; port++) {
4213859Sml29623 			custom_num_grp[port] =
4226929Smisaki 			    (num_ports == 4) ?
4236929Smisaki 			    p4_rdcgrp_fair[port] :
4246929Smisaki 			    p2_rdcgrp_fair[port];
4253859Sml29623 			custom_start_grp[port] = start_grp;
4263859Sml29623 			start_grp += custom_num_grp[port];
4273859Sml29623 		}
4283859Sml29623 		break;
4293859Sml29623 
4303859Sml29623 	case EQUAL:
4313859Sml29623 		cfg_prop = "equal";
4323859Sml29623 		for (port = 0; port < num_ports; port++) {
4333859Sml29623 			custom_num_grp[port] =
4346929Smisaki 			    (num_ports == 4) ?
4356929Smisaki 			    p4_rdcgrp_equal[port] :
4366929Smisaki 			    p2_rdcgrp_equal[port];
4373859Sml29623 			custom_start_grp[port] = start_grp;
4383859Sml29623 			start_grp += custom_num_grp[port];
4393859Sml29623 		}
4403859Sml29623 		break;
4413859Sml29623 
4423859Sml29623 
4433859Sml29623 	case CLASSIFY:
4443859Sml29623 		cfg_prop = "classify";
4453859Sml29623 		for (port = 0; port < num_ports; port++) {
4463859Sml29623 			custom_num_grp[port] = (num_ports == 4) ?
4476929Smisaki 			    p4_rdcgrp_cls[port] : p2_rdcgrp_cls[port];
4483859Sml29623 			custom_start_grp[port] = start_grp;
4493859Sml29623 			start_grp += custom_num_grp[port];
4503859Sml29623 		}
4513859Sml29623 		break;
4523859Sml29623 
4533859Sml29623 	case CUSTOM:
4543859Sml29623 		cfg_prop = "custom";
4553859Sml29623 		/* See if it is good config */
4563859Sml29623 		num_grps = 0;
4573859Sml29623 		for (port = 0; port < num_ports; port++) {
4583859Sml29623 			custom_start_grp[port] =
4596929Smisaki 			    ddi_prop_get_int(DDI_DEV_T_NONE, s_dip[port],
4606929Smisaki 			    DDI_PROP_DONTPASS, start_prop, -1);
4613859Sml29623 			if ((custom_start_grp[port] == -1) ||
4626929Smisaki 			    (custom_start_grp[port] >=
4636929Smisaki 			    NXGE_MAX_RDC_GRPS)) {
4643859Sml29623 				bad_config = B_TRUE;
4653859Sml29623 				break;
4663859Sml29623 			}
4673859Sml29623 			custom_num_grp[port] = ddi_prop_get_int(
4686929Smisaki 			    DDI_DEV_T_NONE,
4696929Smisaki 			    s_dip[port],
4706929Smisaki 			    DDI_PROP_DONTPASS,
4716929Smisaki 			    num_prop, -1);
4723859Sml29623 
4733859Sml29623 			if ((custom_num_grp[port] == -1) ||
4746929Smisaki 			    (custom_num_grp[port] >
4756929Smisaki 			    NXGE_MAX_RDC_GRPS) ||
4766929Smisaki 			    ((custom_num_grp[port] +
4776929Smisaki 			    custom_start_grp[port]) >=
4786929Smisaki 			    NXGE_MAX_RDC_GRPS)) {
4793859Sml29623 				bad_config = B_TRUE;
4803859Sml29623 				break;
4813859Sml29623 			}
4823859Sml29623 			num_grps += custom_num_grp[port];
4833859Sml29623 			if (num_grps > NXGE_MAX_RDC_GRPS) {
4843859Sml29623 				bad_config = B_TRUE;
4853859Sml29623 				break;
4863859Sml29623 			}
4873859Sml29623 			grp_bitmap[port] = 0;
4883859Sml29623 			for (bits = 0;
4896929Smisaki 			    bits < custom_num_grp[port];
4906929Smisaki 			    bits++) {
4913859Sml29623 				grp_bitmap[port] |=
4926929Smisaki 				    (1 << (bits + custom_start_grp[port]));
4933859Sml29623 			}
4943859Sml29623 
4953859Sml29623 		}
4963859Sml29623 
4973859Sml29623 		if (bad_config == B_FALSE) {
4983859Sml29623 			/* check for overlap */
4993859Sml29623 			for (port = 0; port < num_ports - 1; port++) {
5003859Sml29623 				for (j = port + 1; j < num_ports; j++) {
5013859Sml29623 					if (grp_bitmap[port] &
5026929Smisaki 					    grp_bitmap[j]) {
5033859Sml29623 						bad_config = B_TRUE;
5043859Sml29623 						break;
5053859Sml29623 					}
5063859Sml29623 				}
5073859Sml29623 				if (bad_config == B_TRUE)
5083859Sml29623 					break;
5093859Sml29623 			}
5103859Sml29623 		}
5113859Sml29623 		if (bad_config == B_TRUE) {
5123859Sml29623 			/* use default config */
5133859Sml29623 			for (port = 0; port < num_ports; port++) {
5143859Sml29623 				custom_num_grp[port] =
5156929Smisaki 				    (num_ports == 4) ?
5166929Smisaki 				    p4_rx_fair[port] : p2_rx_fair[port];
5173859Sml29623 				custom_start_grp[port] = start_grp;
5183859Sml29623 				start_grp += custom_num_grp[port];
5193859Sml29623 			}
5203859Sml29623 		}
5213859Sml29623 		break;
5223859Sml29623 
5233859Sml29623 	default:
5243859Sml29623 		/* use default config */
5253859Sml29623 		cfg_prop = "fair";
5263859Sml29623 		for (port = 0; port < num_ports; port++) {
5273859Sml29623 			custom_num_grp[port] = (num_ports == 4) ?
5286929Smisaki 			    p4_rx_fair[port] : p2_rx_fair[port];
5293859Sml29623 			custom_start_grp[port] = start_grp;
5303859Sml29623 			start_grp += custom_num_grp[port];
5313859Sml29623 		}
5323859Sml29623 		break;
5333859Sml29623 	}
5343859Sml29623 
5353859Sml29623 	/* Now Update the rx properties */
5363859Sml29623 	for (port = 0; port < num_ports; port++) {
5373859Sml29623 		ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
5386929Smisaki 		    "rxdma-grp-cfg", cfg_prop);
5393859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
5403859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
5416929Smisaki 			    " property %s not updating",
5426929Smisaki 			    cfg_prop));
5433859Sml29623 			status |= NXGE_DDI_FAILED;
5443859Sml29623 		}
5453859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
5466929Smisaki 		    num_prop, custom_num_grp[port]);
5473859Sml29623 
5483859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
5493859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
5506929Smisaki 			    " property %s not updating",
5516929Smisaki 			    num_prop));
5523859Sml29623 			status |= NXGE_DDI_FAILED;
5533859Sml29623 		}
5543859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
5556929Smisaki 		    start_prop, custom_start_grp[port]);
5563859Sml29623 
5573859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
5583859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
5596929Smisaki 			    " property %s not updating",
5606929Smisaki 			    start_prop));
5613859Sml29623 			status |= NXGE_DDI_FAILED;
5623859Sml29623 		}
5633859Sml29623 	}
5643859Sml29623 	if (status & NXGE_DDI_FAILED)
5653859Sml29623 		status |= NXGE_ERROR;
5663859Sml29623 
5673859Sml29623 	return (status);
5683859Sml29623 }
5693859Sml29623 
5703859Sml29623 static nxge_status_t
nxge_update_rxdma_properties(p_nxge_t nxgep,config_token_t token,dev_info_t * s_dip[])5713859Sml29623 nxge_update_rxdma_properties(p_nxge_t nxgep, config_token_t token,
5723859Sml29623 	dev_info_t *s_dip[])
5733859Sml29623 {
5743859Sml29623 	nxge_status_t status = NXGE_OK;
5753859Sml29623 	int ddi_status;
5763859Sml29623 	int num_ports = nxgep->nports;
5773859Sml29623 	int port, bits, j;
5783859Sml29623 	uint8_t start_rdc = 0, num_rdc = 0;
5793859Sml29623 	p_nxge_param_t param_arr;
5803859Sml29623 	uint32_t rdc_bitmap[MAX_SIBLINGS];
5813859Sml29623 	int custom_start_rdc[MAX_SIBLINGS];
5823859Sml29623 	int custom_num_rdc[MAX_SIBLINGS];
5833859Sml29623 	uint8_t bad_config = B_FALSE;
5843859Sml29623 	int *prop_val;
5853859Sml29623 	uint_t prop_len;
5863859Sml29623 	char *start_rdc_prop, *num_rdc_prop, *cfg_prop;
5873859Sml29623 
5883859Sml29623 	start_rdc = 0;
5893859Sml29623 	param_arr = nxgep->param_arr;
5903859Sml29623 	start_rdc_prop = param_arr[param_rxdma_channels_begin].fcode_name;
5913859Sml29623 	num_rdc_prop = param_arr[param_rxdma_channels].fcode_name;
5923859Sml29623 
5933859Sml29623 	switch (token) {
5943859Sml29623 	case FAIR:
5953859Sml29623 		cfg_prop = "fair";
5963859Sml29623 		for (port = 0; port < num_ports; port++) {
5973859Sml29623 			custom_num_rdc[port] = (num_ports == 4) ?
5986929Smisaki 			    p4_rx_fair[port] : p2_rx_fair[port];
5993859Sml29623 			custom_start_rdc[port] = start_rdc;
6003859Sml29623 			start_rdc += custom_num_rdc[port];
6013859Sml29623 		}
6023859Sml29623 		break;
6033859Sml29623 
6043859Sml29623 	case EQUAL:
6053859Sml29623 		cfg_prop = "equal";
6063859Sml29623 		for (port = 0; port < num_ports; port++) {
6073859Sml29623 			custom_num_rdc[port] = (num_ports == 4) ?
6086929Smisaki 			    p4_rx_equal[port] :
6096929Smisaki 			    p2_rx_equal[port];
6103859Sml29623 			custom_start_rdc[port] = start_rdc;
6113859Sml29623 			start_rdc += custom_num_rdc[port];
6123859Sml29623 		}
6133859Sml29623 		break;
6143859Sml29623 
6153859Sml29623 	case CUSTOM:
6163859Sml29623 		cfg_prop = "custom";
6173859Sml29623 		/* See if it is good config */
6183859Sml29623 		num_rdc = 0;
6193859Sml29623 		for (port = 0; port < num_ports; port++) {
6203859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
6216929Smisaki 			    DDI_DEV_T_ANY,
6226929Smisaki 			    s_dip[port], 0,
6236929Smisaki 			    start_rdc_prop,
6246929Smisaki 			    &prop_val,
6256929Smisaki 			    &prop_len);
6263859Sml29623 			if (ddi_status == DDI_SUCCESS)
6273859Sml29623 				custom_start_rdc[port] = *prop_val;
6283859Sml29623 			else {
6293859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6306929Smisaki 				    " %s custom start port %d"
6316929Smisaki 				    " read failed ",
6326929Smisaki 				    " rxdma-cfg", port));
6333859Sml29623 				bad_config = B_TRUE;
6343859Sml29623 				status |= NXGE_DDI_FAILED;
6353859Sml29623 			}
6363859Sml29623 			if ((custom_start_rdc[port] == -1) ||
6376929Smisaki 			    (custom_start_rdc[port] >=
6386929Smisaki 			    NXGE_MAX_RDCS)) {
6393859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6406929Smisaki 				    " %s custom start %d"
6416929Smisaki 				    " out of range %x ",
6426929Smisaki 				    " rxdma-cfg",
6436929Smisaki 				    port,
6446929Smisaki 				    custom_start_rdc[port]));
6453859Sml29623 				bad_config = B_TRUE;
6463859Sml29623 				break;
6473859Sml29623 			}
6483859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
6496929Smisaki 			    DDI_DEV_T_ANY,
6506929Smisaki 			    s_dip[port],
6516929Smisaki 			    0,
6526929Smisaki 			    num_rdc_prop,
6536929Smisaki 			    &prop_val,
6546929Smisaki 			    &prop_len);
6553859Sml29623 
6563859Sml29623 			if (ddi_status == DDI_SUCCESS)
6573859Sml29623 				custom_num_rdc[port] = *prop_val;
6583859Sml29623 			else {
6593859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6606929Smisaki 				    " %s custom num port %d"
6616929Smisaki 				    " read failed ",
6626929Smisaki 				    "rxdma-cfg", port));
6633859Sml29623 				bad_config = B_TRUE;
6643859Sml29623 				status |= NXGE_DDI_FAILED;
6653859Sml29623 			}
6663859Sml29623 
6673859Sml29623 			if ((custom_num_rdc[port] == -1) ||
6686929Smisaki 			    (custom_num_rdc[port] >
6696929Smisaki 			    NXGE_MAX_RDCS) ||
6706929Smisaki 			    ((custom_num_rdc[port] +
6716929Smisaki 			    custom_start_rdc[port]) >
6726929Smisaki 			    NXGE_MAX_RDCS)) {
6733859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
6746929Smisaki 				    " %s custom num %d"
6756929Smisaki 				    " out of range %x ",
6766929Smisaki 				    " rxdma-cfg",
6776929Smisaki 				    port, custom_num_rdc[port]));
6783859Sml29623 				bad_config = B_TRUE;
6793859Sml29623 				break;
6803859Sml29623 			}
6813859Sml29623 			num_rdc += custom_num_rdc[port];
6823859Sml29623 			if (num_rdc > NXGE_MAX_RDCS) {
6833859Sml29623 				bad_config = B_TRUE;
6843859Sml29623 				break;
6853859Sml29623 			}
6863859Sml29623 			rdc_bitmap[port] = 0;
6873859Sml29623 			for (bits = 0;
6886929Smisaki 			    bits < custom_num_rdc[port]; bits++) {
6893859Sml29623 				rdc_bitmap[port] |=
6906929Smisaki 				    (1 << (bits + custom_start_rdc[port]));
6913859Sml29623 			}
6923859Sml29623 		}
6933859Sml29623 
6943859Sml29623 		if (bad_config == B_FALSE) {
6953859Sml29623 			/* check for overlap */
6963859Sml29623 			for (port = 0; port < num_ports - 1; port++) {
6973859Sml29623 				for (j = port + 1; j < num_ports; j++) {
6983859Sml29623 					if (rdc_bitmap[port] &
6996929Smisaki 					    rdc_bitmap[j]) {
7003859Sml29623 						NXGE_DEBUG_MSG((nxgep,
7016929Smisaki 						    CFG_CTL,
7026929Smisaki 						    " rxdma-cfg"
7036929Smisaki 						    " property custom"
7046929Smisaki 						    " bit overlap"
7056929Smisaki 						    " %d %d ",
7066929Smisaki 						    port, j));
7073859Sml29623 						bad_config = B_TRUE;
7083859Sml29623 						break;
7093859Sml29623 					}
7103859Sml29623 				}
7113859Sml29623 				if (bad_config == B_TRUE)
7123859Sml29623 					break;
7133859Sml29623 			}
7143859Sml29623 		}
7153859Sml29623 		if (bad_config == B_TRUE) {
7163859Sml29623 			/* use default config */
7173859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
7186929Smisaki 			    " rxdma-cfg property:"
7196929Smisaki 			    " bad custom config:"
7206929Smisaki 			    " use default"));
7213859Sml29623 			for (port = 0; port < num_ports; port++) {
7223859Sml29623 				custom_num_rdc[port] =
7236929Smisaki 				    (num_ports == 4) ?
7246929Smisaki 				    p4_rx_fair[port] :
7256929Smisaki 				    p2_rx_fair[port];
7263859Sml29623 				custom_start_rdc[port] = start_rdc;
7273859Sml29623 				start_rdc += custom_num_rdc[port];
7283859Sml29623 			}
7293859Sml29623 		}
7303859Sml29623 		break;
7313859Sml29623 
7323859Sml29623 	default:
7333859Sml29623 		/* use default config */
7343859Sml29623 		cfg_prop = "fair";
7353859Sml29623 		for (port = 0; port < num_ports; port++) {
7363859Sml29623 			custom_num_rdc[port] = (num_ports == 4) ?
7376929Smisaki 			    p4_rx_fair[port] : p2_rx_fair[port];
7383859Sml29623 			custom_start_rdc[port] = start_rdc;
7393859Sml29623 			start_rdc += custom_num_rdc[port];
7403859Sml29623 		}
7413859Sml29623 		break;
7423859Sml29623 	}
7433859Sml29623 
7443859Sml29623 	/* Now Update the rx properties */
7453859Sml29623 	for (port = 0; port < num_ports; port++) {
7463859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
7476929Smisaki 		    " update property rxdma-cfg with %s ", cfg_prop));
7483859Sml29623 		ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
7496929Smisaki 		    "rxdma-cfg", cfg_prop);
7503859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
7513859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
7526929Smisaki 			    " property rxdma-cfg is not updating to %s",
7536929Smisaki 			    cfg_prop));
7543859Sml29623 			status |= NXGE_DDI_FAILED;
7553859Sml29623 		}
7563859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
7576929Smisaki 		    num_rdc_prop, custom_num_rdc[port]));
7583859Sml29623 
7593859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
7606929Smisaki 		    num_rdc_prop, custom_num_rdc[port]);
7613859Sml29623 
7623859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
7633859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
7646929Smisaki 			    " property %s not updating with %d",
7656929Smisaki 			    num_rdc_prop, custom_num_rdc[port]));
7663859Sml29623 			status |= NXGE_DDI_FAILED;
7673859Sml29623 		}
7683859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
7696929Smisaki 		    start_rdc_prop, custom_start_rdc[port]));
7703859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
7716929Smisaki 		    start_rdc_prop, custom_start_rdc[port]);
7723859Sml29623 
7733859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
7743859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
7756929Smisaki 			    " property %s not updating with %d ",
7766929Smisaki 			    start_rdc_prop, custom_start_rdc[port]));
7773859Sml29623 			status |= NXGE_DDI_FAILED;
7783859Sml29623 		}
7793859Sml29623 	}
7803859Sml29623 	if (status & NXGE_DDI_FAILED)
7813859Sml29623 		status |= NXGE_ERROR;
7823859Sml29623 	return (status);
7833859Sml29623 }
7843859Sml29623 
7853859Sml29623 static nxge_status_t
nxge_update_txdma_properties(p_nxge_t nxgep,config_token_t token,dev_info_t * s_dip[])7863859Sml29623 nxge_update_txdma_properties(p_nxge_t nxgep, config_token_t token,
7873859Sml29623 	dev_info_t *s_dip[])
7883859Sml29623 {
7893859Sml29623 	nxge_status_t status = NXGE_OK;
7903859Sml29623 	int ddi_status = DDI_SUCCESS;
7913859Sml29623 	int num_ports = nxgep->nports;
7923859Sml29623 	int port, bits, j;
7938275SEric Cheng 	uint8_t  start_tdc, num_tdc = 0;
7943859Sml29623 	p_nxge_param_t param_arr;
7953859Sml29623 	uint32_t tdc_bitmap[MAX_SIBLINGS];
7963859Sml29623 	int custom_start_tdc[MAX_SIBLINGS];
7973859Sml29623 	int custom_num_tdc[MAX_SIBLINGS];
7983859Sml29623 	uint8_t bad_config = B_FALSE;
7993859Sml29623 	int *prop_val;
8003859Sml29623 	uint_t prop_len;
8013859Sml29623 	char *start_tdc_prop, *num_tdc_prop, *cfg_prop;
8023859Sml29623 
8033859Sml29623 	start_tdc = 0;
8043859Sml29623 	param_arr = nxgep->param_arr;
8053859Sml29623 	start_tdc_prop = param_arr[param_txdma_channels_begin].fcode_name;
8063859Sml29623 	num_tdc_prop = param_arr[param_txdma_channels].fcode_name;
8073859Sml29623 
8083859Sml29623 	switch (token) {
8093859Sml29623 	case FAIR:
8103859Sml29623 		cfg_prop = "fair";
8113859Sml29623 		for (port = 0; port < num_ports; port++) {
8123859Sml29623 			custom_num_tdc[port] = (num_ports == 4) ?
8136929Smisaki 			    p4_tx_fair[port] : p2_tx_fair[port];
8143859Sml29623 			custom_start_tdc[port] = start_tdc;
8153859Sml29623 			start_tdc += custom_num_tdc[port];
8163859Sml29623 		}
8173859Sml29623 		break;
8183859Sml29623 
8193859Sml29623 	case EQUAL:
8203859Sml29623 		cfg_prop = "equal";
8213859Sml29623 		for (port = 0; port < num_ports; port++) {
8223859Sml29623 			custom_num_tdc[port] = (num_ports == 4) ?
8236929Smisaki 			    p4_tx_equal[port] : p2_tx_equal[port];
8243859Sml29623 			custom_start_tdc[port] = start_tdc;
8253859Sml29623 			start_tdc += custom_num_tdc[port];
8263859Sml29623 		}
8273859Sml29623 		break;
8283859Sml29623 
8293859Sml29623 	case CUSTOM:
8303859Sml29623 		cfg_prop = "custom";
8313859Sml29623 		/* See if it is good config */
8323859Sml29623 		num_tdc = 0;
8333859Sml29623 		for (port = 0; port < num_ports; port++) {
8343859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
8356929Smisaki 			    DDI_DEV_T_ANY, s_dip[port], 0, start_tdc_prop,
8366929Smisaki 			    &prop_val, &prop_len);
8373859Sml29623 			if (ddi_status == DDI_SUCCESS)
8383859Sml29623 				custom_start_tdc[port] = *prop_val;
8393859Sml29623 			else {
8403859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8416929Smisaki 				    " %s custom start port %d"
8426929Smisaki 				    " read failed ", " txdma-cfg", port));
8433859Sml29623 				bad_config = B_TRUE;
8443859Sml29623 				status |= NXGE_DDI_FAILED;
8453859Sml29623 			}
8463859Sml29623 
8473859Sml29623 			if ((custom_start_tdc[port] == -1) ||
8486929Smisaki 			    (custom_start_tdc[port] >=
8496929Smisaki 			    NXGE_MAX_RDCS)) {
8503859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8516929Smisaki 				    " %s custom start %d"
8526929Smisaki 				    " out of range %x ", " txdma-cfg",
8536929Smisaki 				    port, custom_start_tdc[port]));
8543859Sml29623 				bad_config = B_TRUE;
8553859Sml29623 				break;
8563859Sml29623 			}
8573859Sml29623 
8583859Sml29623 			ddi_status = ddi_prop_lookup_int_array(
8596929Smisaki 			    DDI_DEV_T_ANY, s_dip[port], 0, num_tdc_prop,
8606929Smisaki 			    &prop_val, &prop_len);
8613859Sml29623 			if (ddi_status == DDI_SUCCESS)
8623859Sml29623 				custom_num_tdc[port] = *prop_val;
8633859Sml29623 			else {
8643859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8656929Smisaki 				    " %s custom num port %d"
8666929Smisaki 				    " read failed ", " txdma-cfg", port));
8673859Sml29623 				bad_config = B_TRUE;
8683859Sml29623 				status |= NXGE_DDI_FAILED;
8693859Sml29623 			}
8703859Sml29623 
8713859Sml29623 			if ((custom_num_tdc[port] == -1) ||
8726929Smisaki 			    (custom_num_tdc[port] >
8736929Smisaki 			    NXGE_MAX_TDCS) ||
8746929Smisaki 			    ((custom_num_tdc[port] +
8756929Smisaki 			    custom_start_tdc[port]) >
8766929Smisaki 			    NXGE_MAX_TDCS)) {
8773859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
8786929Smisaki 				    " %s custom num %d"
8796929Smisaki 				    " out of range %x ", " rxdma-cfg",
8806929Smisaki 				    port, custom_num_tdc[port]));
8813859Sml29623 				bad_config = B_TRUE;
8823859Sml29623 				break;
8833859Sml29623 			}
8843859Sml29623 			num_tdc += custom_num_tdc[port];
8853859Sml29623 			if (num_tdc > NXGE_MAX_TDCS) {
8863859Sml29623 				bad_config = B_TRUE;
8873859Sml29623 				break;
8883859Sml29623 			}
8893859Sml29623 			tdc_bitmap[port] = 0;
8903859Sml29623 			for (bits = 0;
8916929Smisaki 			    bits < custom_num_tdc[port]; bits++) {
8923859Sml29623 				tdc_bitmap[port] |=
8936929Smisaki 				    (1 <<
8946929Smisaki 				    (bits + custom_start_tdc[port]));
8953859Sml29623 			}
8963859Sml29623 
8973859Sml29623 		}
8983859Sml29623 
8993859Sml29623 		if (bad_config == B_FALSE) {
9003859Sml29623 			/* check for overlap */
9013859Sml29623 			for (port = 0; port < num_ports - 1; port++) {
9023859Sml29623 				for (j = port + 1; j < num_ports; j++) {
9033859Sml29623 					if (tdc_bitmap[port] &
9046929Smisaki 					    tdc_bitmap[j]) {
9053859Sml29623 						NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9066929Smisaki 						    " rxdma-cfg"
9076929Smisaki 						    " property custom"
9086929Smisaki 						    " bit overlap"
9096929Smisaki 						    " %d %d ",
9106929Smisaki 						    port, j));
9113859Sml29623 						bad_config = B_TRUE;
9123859Sml29623 						break;
9133859Sml29623 					}
9143859Sml29623 				}
9153859Sml29623 				if (bad_config == B_TRUE)
9163859Sml29623 					break;
9173859Sml29623 			}
9183859Sml29623 		}
9193859Sml29623 		if (bad_config == B_TRUE) {
9203859Sml29623 			/* use default config */
9213859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9226929Smisaki 			    " txdma-cfg property:"
9236929Smisaki 			    " bad custom config:" " use default"));
9243859Sml29623 
9253859Sml29623 			for (port = 0; port < num_ports; port++) {
9263859Sml29623 				custom_num_tdc[port] = (num_ports == 4) ?
9276929Smisaki 				    p4_tx_fair[port] : p2_tx_fair[port];
9283859Sml29623 				custom_start_tdc[port] = start_tdc;
9293859Sml29623 				start_tdc += custom_num_tdc[port];
9303859Sml29623 			}
9313859Sml29623 		}
9323859Sml29623 		break;
9333859Sml29623 
9343859Sml29623 	default:
9353859Sml29623 		/* use default config */
9363859Sml29623 		cfg_prop = "fair";
9373859Sml29623 		for (port = 0; port < num_ports; port++) {
9383859Sml29623 			custom_num_tdc[port] = (num_ports == 4) ?
9396929Smisaki 			    p4_tx_fair[port] : p2_tx_fair[port];
9403859Sml29623 			custom_start_tdc[port] = start_tdc;
9413859Sml29623 			start_tdc += custom_num_tdc[port];
9423859Sml29623 		}
9433859Sml29623 		break;
9443859Sml29623 	}
9453859Sml29623 
9463859Sml29623 	/* Now Update the tx properties */
9473859Sml29623 	for (port = 0; port < num_ports; port++) {
9483859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9496929Smisaki 		    " update property txdma-cfg with %s ", cfg_prop));
9503859Sml29623 		ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
9516929Smisaki 		    "txdma-cfg", cfg_prop);
9523859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
9533859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
9546929Smisaki 			    " property txdma-cfg is not updating to %s",
9556929Smisaki 			    cfg_prop));
9563859Sml29623 			status |= NXGE_DDI_FAILED;
9573859Sml29623 		}
9583859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
9596929Smisaki 		    num_tdc_prop, custom_num_tdc[port]));
9603859Sml29623 
9613859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
9626929Smisaki 		    num_tdc_prop, custom_num_tdc[port]);
9633859Sml29623 
9643859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
9653859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
9666929Smisaki 			    " property %s not updating with %d",
9676929Smisaki 			    num_tdc_prop,
9686929Smisaki 			    custom_num_tdc[port]));
9693859Sml29623 			status |= NXGE_DDI_FAILED;
9703859Sml29623 		}
9713859Sml29623 
9723859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
9736929Smisaki 		    start_tdc_prop, custom_start_tdc[port]));
9743859Sml29623 
9753859Sml29623 		ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
9766929Smisaki 		    start_tdc_prop, custom_start_tdc[port]);
9773859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS) {
9783859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
9796929Smisaki 			    " property %s not updating with %d ",
9806929Smisaki 			    start_tdc_prop, custom_start_tdc[port]));
9813859Sml29623 			status |= NXGE_DDI_FAILED;
9823859Sml29623 		}
9833859Sml29623 	}
9843859Sml29623 	if (status & NXGE_DDI_FAILED)
9853859Sml29623 		status |= NXGE_ERROR;
9863859Sml29623 	return (status);
9873859Sml29623 }
9883859Sml29623 
9893859Sml29623 static nxge_status_t
nxge_update_cfg_properties(p_nxge_t nxgep,uint32_t flags,config_token_t token,dev_info_t * s_dip[])9903859Sml29623 nxge_update_cfg_properties(p_nxge_t nxgep, uint32_t flags,
9913859Sml29623 	config_token_t token, dev_info_t *s_dip[])
9923859Sml29623 {
9933859Sml29623 	nxge_status_t status = NXGE_OK;
9943859Sml29623 
9953859Sml29623 	switch (flags) {
9963859Sml29623 	case COMMON_TXDMA_CFG:
9973859Sml29623 		if (nxge_dma_obp_props_only == 0)
9983859Sml29623 			status = nxge_update_txdma_properties(nxgep,
9996929Smisaki 			    token, s_dip);
10003859Sml29623 		break;
10013859Sml29623 	case COMMON_RXDMA_CFG:
10023859Sml29623 		if (nxge_dma_obp_props_only == 0)
10033859Sml29623 			status = nxge_update_rxdma_properties(nxgep,
10046929Smisaki 			    token, s_dip);
10053859Sml29623 
10063859Sml29623 		break;
10073859Sml29623 	case COMMON_RXDMA_GRP_CFG:
10083859Sml29623 		status = nxge_update_rxdma_grp_properties(nxgep,
10096929Smisaki 		    token, s_dip);
10103859Sml29623 		break;
10113859Sml29623 	default:
10123859Sml29623 		return (NXGE_ERROR);
10133859Sml29623 	}
10143859Sml29623 	return (status);
10153859Sml29623 }
10163859Sml29623 
10173859Sml29623 /*
10183859Sml29623  * verify consistence.
10193859Sml29623  * (May require publishing the properties on all the ports.
10203859Sml29623  *
10213859Sml29623  * What if properties are published on function 0 device only?
10223859Sml29623  *
10233859Sml29623  *
10243859Sml29623  * rxdma-cfg, txdma-cfg, rxdma-grp-cfg (required )
10253859Sml29623  * What about class configs?
10263859Sml29623  *
10273859Sml29623  * If consistent, update the property on all the siblings.
10283859Sml29623  * set  a flag on hardware shared register
10293859Sml29623  * The rest of the siblings will check the flag
10303859Sml29623  * if the flag is set, they will use the updated property
10313859Sml29623  * without doing any validation.
10323859Sml29623  */
10333859Sml29623 
10343859Sml29623 nxge_status_t
nxge_cfg_verify_set_classify_prop(p_nxge_t nxgep,char * prop,uint64_t known_cfg,uint32_t override,dev_info_t * c_dip[])10353859Sml29623 nxge_cfg_verify_set_classify_prop(p_nxge_t nxgep, char *prop,
10363859Sml29623 	uint64_t known_cfg, uint32_t override, dev_info_t *c_dip[])
10373859Sml29623 {
10383859Sml29623 	nxge_status_t status = NXGE_OK;
10393859Sml29623 	int ddi_status = DDI_SUCCESS;
10403859Sml29623 	int i = 0, found = 0, update_prop = B_TRUE;
10413859Sml29623 	int *cfg_val;
10423859Sml29623 	uint_t new_value, cfg_value[MAX_SIBLINGS];
10433859Sml29623 	uint_t prop_len;
10443859Sml29623 	uint_t known_cfg_value;
10453859Sml29623 
10463859Sml29623 	known_cfg_value = (uint_t)known_cfg;
10473859Sml29623 
10483859Sml29623 	if (override == B_TRUE) {
10493859Sml29623 		new_value = known_cfg_value;
10503859Sml29623 		for (i = 0; i < nxgep->nports; i++) {
10513859Sml29623 			ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE,
10526929Smisaki 			    c_dip[i], prop, new_value);
10533859Sml29623 #ifdef NXGE_DEBUG_ERROR
10543859Sml29623 			if (ddi_status != DDI_PROP_SUCCESS)
10553859Sml29623 				NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
10566929Smisaki 				    " property %s failed update ", prop));
10573859Sml29623 #endif
10583859Sml29623 		}
10593859Sml29623 		if (ddi_status != DDI_PROP_SUCCESS)
10603859Sml29623 			return (NXGE_ERROR | NXGE_DDI_FAILED);
10613859Sml29623 	}
10623859Sml29623 	for (i = 0; i < nxgep->nports; i++) {
10633859Sml29623 		cfg_value[i] = known_cfg_value;
10643859Sml29623 		if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, c_dip[i], 0,
10656929Smisaki 		    prop, &cfg_val,
10666929Smisaki 		    &prop_len) == DDI_PROP_SUCCESS) {
10673859Sml29623 			cfg_value[i] = *cfg_val;
10683859Sml29623 			ddi_prop_free(cfg_val);
10693859Sml29623 			found++;
10703859Sml29623 		}
10713859Sml29623 	}
10723859Sml29623 
10733859Sml29623 	if (found != i) {
10743859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10756929Smisaki 		    " property %s not specified on all ports", prop));
10763859Sml29623 		if (found == 0) {
10773859Sml29623 			/* not specified: Use default */
10783859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10796929Smisaki 			    " property %s not specified on any port:"
10806929Smisaki 			    " Using default", prop));
10813859Sml29623 			new_value = known_cfg_value;
10823859Sml29623 		} else {
10833859Sml29623 			/* specified on some */
10843859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10856929Smisaki 			    " property %s not specified"
10866929Smisaki 			    " on some ports: Using default", prop));
10873859Sml29623 			/* ? use p0 value instead ? */
10883859Sml29623 			new_value = known_cfg_value;
10893859Sml29623 		}
10903859Sml29623 	} else {
10913859Sml29623 		/* check type and consistence */
10923859Sml29623 		/* found on all devices */
10933859Sml29623 		for (i = 1; i < found; i++) {
10943859Sml29623 			if (cfg_value[i] != cfg_value[i - 1]) {
10953859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG_CTL,
10966929Smisaki 				    " property %s inconsistent:"
10976929Smisaki 				    " Using default", prop));
10983859Sml29623 				new_value = known_cfg_value;
10993859Sml29623 				break;
11003859Sml29623 			}
11013859Sml29623 			/*
11023859Sml29623 			 * Found on all the ports and consistent. Nothing to
11033859Sml29623 			 * do.
11043859Sml29623 			 */
11053859Sml29623 			update_prop = B_FALSE;
11063859Sml29623 		}
11073859Sml29623 	}
11083859Sml29623 
11093859Sml29623 	if (update_prop == B_TRUE) {
11103859Sml29623 		for (i = 0; i < nxgep->nports; i++) {
11113859Sml29623 			ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE,
11126929Smisaki 			    c_dip[i], prop, new_value);
11133859Sml29623 #ifdef NXGE_DEBUG_ERROR
11143859Sml29623 			if (ddi_status != DDI_SUCCESS)
11153859Sml29623 				NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
11166929Smisaki 				    " property %s not updating with %d"
11176929Smisaki 				    " Using default",
11186929Smisaki 				    prop, new_value));
11193859Sml29623 #endif
11203859Sml29623 			if (ddi_status != DDI_PROP_SUCCESS)
11213859Sml29623 				status |= NXGE_DDI_FAILED;
11223859Sml29623 		}
11233859Sml29623 	}
11243859Sml29623 	if (status & NXGE_DDI_FAILED)
11253859Sml29623 		status |= NXGE_ERROR;
11263859Sml29623 
11273859Sml29623 	return (status);
11283859Sml29623 }
11293859Sml29623 
11303859Sml29623 static uint64_t
nxge_class_get_known_cfg(p_nxge_t nxgep,int class_prop,int rx_quick_cfg)11313859Sml29623 nxge_class_get_known_cfg(p_nxge_t nxgep, int class_prop, int rx_quick_cfg)
11323859Sml29623 {
11333859Sml29623 	int start_prop;
11343859Sml29623 	uint64_t cfg_value;
11353859Sml29623 	p_nxge_param_t param_arr;
11363859Sml29623 
11373859Sml29623 	param_arr = nxgep->param_arr;
11383859Sml29623 	cfg_value = param_arr[class_prop].value;
11393859Sml29623 	start_prop = param_h1_init_value;
11403859Sml29623 
11413859Sml29623 	/* update the properties per quick config */
11423859Sml29623 	switch (rx_quick_cfg) {
11433859Sml29623 	case CFG_L3_WEB:
11443859Sml29623 	case CFG_L3_DISTRIBUTE:
11453859Sml29623 		cfg_value = nxge_classify_get_cfg_value(nxgep,
11466929Smisaki 		    rx_quick_cfg, class_prop - start_prop);
11473859Sml29623 		break;
11483859Sml29623 	default:
11493859Sml29623 		cfg_value = param_arr[class_prop].value;
11503859Sml29623 		break;
11513859Sml29623 	}
11523859Sml29623 	return (cfg_value);
11533859Sml29623 }
11543859Sml29623 
11553859Sml29623 static nxge_status_t
nxge_cfg_verify_set_classify(p_nxge_t nxgep,dev_info_t * c_dip[])11563859Sml29623 nxge_cfg_verify_set_classify(p_nxge_t nxgep, dev_info_t *c_dip[])
11573859Sml29623 {
11583859Sml29623 	nxge_status_t status = NXGE_OK;
11593859Sml29623 	int rx_quick_cfg, class_prop, start_prop, end_prop;
11603859Sml29623 	char *prop_name;
11613859Sml29623 	int override = B_TRUE;
11623859Sml29623 	uint64_t cfg_value;
11633859Sml29623 	p_nxge_param_t param_arr;
11643859Sml29623 
11653859Sml29623 	param_arr = nxgep->param_arr;
11663859Sml29623 	rx_quick_cfg = param_arr[param_rx_quick_cfg].value;
11673859Sml29623 	start_prop = param_h1_init_value;
11683859Sml29623 	end_prop = param_class_opt_ipv6_sctp;
11693859Sml29623 
11703859Sml29623 	/* update the properties per quick config */
11713859Sml29623 	if (rx_quick_cfg == CFG_NOT_SPECIFIED)
11723859Sml29623 		override = B_FALSE;
11733859Sml29623 
11743859Sml29623 	/*
11753859Sml29623 	 * these parameter affect the classification outcome.
11763859Sml29623 	 * these parameters are used to configure the Flow key and
11773859Sml29623 	 * the TCAM key for each of the IP classes.
11783859Sml29623 	 * Included here are also the H1 and H2 initial values
11793859Sml29623 	 * which affect the distribution as well as final hash value
11803859Sml29623 	 * (hence the offset into RDC table and FCRAM bucket location)
11813859Sml29623 	 *
11823859Sml29623 	 */
11833859Sml29623 	for (class_prop = start_prop; class_prop <= end_prop; class_prop++) {
11843859Sml29623 		prop_name = param_arr[class_prop].fcode_name;
11853859Sml29623 		cfg_value = nxge_class_get_known_cfg(nxgep,
11866929Smisaki 		    class_prop, rx_quick_cfg);
11873859Sml29623 		status = nxge_cfg_verify_set_classify_prop(nxgep, prop_name,
11886929Smisaki 		    cfg_value, override, c_dip);
11893859Sml29623 	}
11903859Sml29623 
11913859Sml29623 	/*
11923859Sml29623 	 * these properties do not affect the actual classification outcome.
11933859Sml29623 	 * used to enable/disable or tune the fflp hardware
11943859Sml29623 	 *
11953859Sml29623 	 * fcram_access_ratio, tcam_access_ratio, tcam_enable, llc_snap_enable
11963859Sml29623 	 *
11973859Sml29623 	 */
11983859Sml29623 	override = B_FALSE;
11993859Sml29623 	for (class_prop = param_fcram_access_ratio;
12006929Smisaki 	    class_prop <= param_llc_snap_enable; class_prop++) {
12013859Sml29623 		prop_name = param_arr[class_prop].fcode_name;
12023859Sml29623 		cfg_value = param_arr[class_prop].value;
12033859Sml29623 		status = nxge_cfg_verify_set_classify_prop(nxgep, prop_name,
12046929Smisaki 		    cfg_value, override, c_dip);
12053859Sml29623 	}
12063859Sml29623 
12073859Sml29623 	return (status);
12083859Sml29623 }
12093859Sml29623 
12103859Sml29623 nxge_status_t
nxge_cfg_verify_set(p_nxge_t nxgep,uint32_t flag)12113859Sml29623 nxge_cfg_verify_set(p_nxge_t nxgep, uint32_t flag)
12123859Sml29623 {
12133859Sml29623 	nxge_status_t status = NXGE_OK;
12143859Sml29623 	int i = 0, found = 0;
12153859Sml29623 	int num_siblings;
12163859Sml29623 	dev_info_t *c_dip[MAX_SIBLINGS + 1];
12173859Sml29623 	char *prop_val[MAX_SIBLINGS];
12183859Sml29623 	config_token_t c_token[MAX_SIBLINGS];
12193859Sml29623 	char *prop;
12203859Sml29623 
12213859Sml29623 	if (nxge_dma_obp_props_only)
12223859Sml29623 		return (NXGE_OK);
12233859Sml29623 
12243859Sml29623 	num_siblings = 0;
12253859Sml29623 	c_dip[num_siblings] = ddi_get_child(nxgep->p_dip);
12263859Sml29623 	while (c_dip[num_siblings]) {
12273859Sml29623 		c_dip[num_siblings + 1] =
12286929Smisaki 		    ddi_get_next_sibling(c_dip[num_siblings]);
12293859Sml29623 		num_siblings++;
12303859Sml29623 	}
12313859Sml29623 
12323859Sml29623 	switch (flag) {
12333859Sml29623 	case COMMON_TXDMA_CFG:
12343859Sml29623 		prop = "txdma-cfg";
12353859Sml29623 		break;
12363859Sml29623 	case COMMON_RXDMA_CFG:
12373859Sml29623 		prop = "rxdma-cfg";
12383859Sml29623 		break;
12393859Sml29623 	case COMMON_RXDMA_GRP_CFG:
12403859Sml29623 		prop = "rxdma-grp-cfg";
12413859Sml29623 		break;
12423859Sml29623 	case COMMON_CLASS_CFG:
12433859Sml29623 		status = nxge_cfg_verify_set_classify(nxgep, c_dip);
12443859Sml29623 		return (status);
12453859Sml29623 	default:
12463859Sml29623 		return (NXGE_ERROR);
12473859Sml29623 	}
12483859Sml29623 
12493859Sml29623 	i = 0;
12503859Sml29623 	while (i < num_siblings) {
12513859Sml29623 		if (ddi_prop_lookup_string(DDI_DEV_T_ANY, c_dip[i], 0, prop,
12526929Smisaki 		    (char **)&prop_val[i]) == DDI_PROP_SUCCESS) {
12533859Sml29623 			c_token[i] = nxge_get_config_token(prop_val[i]);
12543859Sml29623 			ddi_prop_free(prop_val[i]);
12553859Sml29623 			found++;
12563859Sml29623 		} else
12573859Sml29623 			c_token[i] = CONFIG_TOKEN_NONE;
12583859Sml29623 		i++;
12593859Sml29623 	}
12603859Sml29623 
12613859Sml29623 	if (found != i) {
12623859Sml29623 		if (found == 0) {
12633859Sml29623 			/* not specified: Use default */
12643859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
12656929Smisaki 			    " property %s not specified on any port:"
12666929Smisaki 			    " Using default", prop));
12673859Sml29623 
12683859Sml29623 			status = nxge_update_cfg_properties(nxgep,
12696929Smisaki 			    flag, FAIR, c_dip);
12703859Sml29623 			return (status);
12713859Sml29623 		} else {
12723859Sml29623 			/*
12733859Sml29623 			 * if  the convention is to use function 0 device then
12743859Sml29623 			 * populate the other devices with this configuration.
12753859Sml29623 			 *
12763859Sml29623 			 * The other alternative is to use the default config.
12773859Sml29623 			 */
12783859Sml29623 			/* not specified: Use default */
12793859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
12806929Smisaki 			    " property %s not specified on some ports:"
12816929Smisaki 			    " Using default", prop));
12823859Sml29623 			status = nxge_update_cfg_properties(nxgep,
12836929Smisaki 			    flag, FAIR, c_dip);
12843859Sml29623 			return (status);
12853859Sml29623 		}
12863859Sml29623 	}
12873859Sml29623 
12883859Sml29623 	/* check type and consistence */
12893859Sml29623 	/* found on all devices */
12903859Sml29623 	for (i = 1; i < found; i++) {
12913859Sml29623 		if (c_token[i] != c_token[i - 1]) {
12923859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
12936929Smisaki 			    " property %s inconsistent:"
12946929Smisaki 			    " Using default", prop));
12953859Sml29623 			status = nxge_update_cfg_properties(nxgep,
12966929Smisaki 			    flag, FAIR, c_dip);
12973859Sml29623 			return (status);
12983859Sml29623 		}
12993859Sml29623 	}
13003859Sml29623 
13013859Sml29623 	/*
13023859Sml29623 	 * Found on all the ports check if it is custom configuration. if
13033859Sml29623 	 * custom, then verify consistence
13043859Sml29623 	 *
13053859Sml29623 	 * finally create soft properties
13063859Sml29623 	 */
13073859Sml29623 	status = nxge_update_cfg_properties(nxgep, flag, c_token[0], c_dip);
13083859Sml29623 	return (status);
13093859Sml29623 }
13103859Sml29623 
13113859Sml29623 nxge_status_t
nxge_cfg_verify_set_quick_config(p_nxge_t nxgep)13123859Sml29623 nxge_cfg_verify_set_quick_config(p_nxge_t nxgep)
13133859Sml29623 {
13143859Sml29623 	nxge_status_t status = NXGE_OK;
13153859Sml29623 	int ddi_status = DDI_SUCCESS;
13163859Sml29623 	char *prop_val;
13173859Sml29623 	char *rx_prop;
13183859Sml29623 	char *prop;
13193859Sml29623 	uint32_t cfg_value = CFG_NOT_SPECIFIED;
13203859Sml29623 	p_nxge_param_t param_arr;
13213859Sml29623 
13223859Sml29623 	param_arr = nxgep->param_arr;
13233859Sml29623 	rx_prop = param_arr[param_rx_quick_cfg].fcode_name;
13243859Sml29623 
13253859Sml29623 	prop = "rx-quick-cfg";
13263859Sml29623 
13273859Sml29623 	/*
13283859Sml29623 	 * good value are
13293859Sml29623 	 *
13303859Sml29623 	 * "web-server" "generic-server" "l3-classify" "flow-classify"
13313859Sml29623 	 */
13323859Sml29623 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, nxgep->dip, 0,
13336929Smisaki 	    prop, (char **)&prop_val) != DDI_PROP_SUCCESS) {
13343859Sml29623 		NXGE_DEBUG_MSG((nxgep, VPD_CTL,
13356929Smisaki 		    " property %s not specified: using default ", prop));
13363859Sml29623 		cfg_value = CFG_NOT_SPECIFIED;
13373859Sml29623 	} else {
13383859Sml29623 		cfg_value = CFG_L3_DISTRIBUTE;
13393859Sml29623 		if (strncmp("web-server", (caddr_t)prop_val, 8) == 0) {
13403859Sml29623 			cfg_value = CFG_L3_WEB;
13413859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
13426929Smisaki 			    " %s: web server ", prop));
13433859Sml29623 		}
13443859Sml29623 		if (strncmp("generic-server", (caddr_t)prop_val, 8) == 0) {
13453859Sml29623 			cfg_value = CFG_L3_DISTRIBUTE;
13463859Sml29623 			NXGE_DEBUG_MSG((nxgep, CFG_CTL,
13476929Smisaki 			    " %s: distribute ", prop));
13483859Sml29623 		}
13493859Sml29623 		/* more */
13503859Sml29623 		ddi_prop_free(prop_val);
13513859Sml29623 	}
13523859Sml29623 
13533859Sml29623 	ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
13546929Smisaki 	    rx_prop, cfg_value);
13553859Sml29623 	if (ddi_status != DDI_PROP_SUCCESS)
13563859Sml29623 		status |= NXGE_DDI_FAILED;
13573859Sml29623 
13583859Sml29623 	/* now handle specified cases: */
13593859Sml29623 	if (status & NXGE_DDI_FAILED)
13603859Sml29623 		status |= NXGE_ERROR;
13613859Sml29623 	return (status);
13623859Sml29623 }
13633859Sml29623 
13646835Syc148097 /*
13656835Syc148097  * Device properties adv-autoneg-cap etc are defined by FWARC
13666835Syc148097  * http://sac.sfbay/FWARC/2002/345/20020610_asif.haswarey
13676835Syc148097  */
13683859Sml29623 static void
nxge_use_cfg_link_cfg(p_nxge_t nxgep)13693859Sml29623 nxge_use_cfg_link_cfg(p_nxge_t nxgep)
13703859Sml29623 {
13713859Sml29623 	int *prop_val;
13723859Sml29623 	uint_t prop_len;
13733859Sml29623 	dev_info_t *dip;
13743859Sml29623 	int speed;
13753859Sml29623 	int duplex;
13763859Sml29623 	int adv_autoneg_cap;
13773859Sml29623 	int adv_10gfdx_cap;
13783859Sml29623 	int adv_10ghdx_cap;
13793859Sml29623 	int adv_1000fdx_cap;
13803859Sml29623 	int adv_1000hdx_cap;
13813859Sml29623 	int adv_100fdx_cap;
13823859Sml29623 	int adv_100hdx_cap;
13833859Sml29623 	int adv_10fdx_cap;
13843859Sml29623 	int adv_10hdx_cap;
13853859Sml29623 	int status = DDI_SUCCESS;
13863859Sml29623 
13873859Sml29623 	dip = nxgep->dip;
13883859Sml29623 
13893859Sml29623 	/*
13903859Sml29623 	 * first find out the card type and the supported link speeds and
13913859Sml29623 	 * features
13923859Sml29623 	 */
13933859Sml29623 	/* add code for card type */
13943859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-autoneg-cap",
13956929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
13963859Sml29623 		ddi_prop_free(prop_val);
13973859Sml29623 		return;
13983859Sml29623 	}
13993859Sml29623 
14003859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10gfdx-cap",
14016929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14023859Sml29623 		ddi_prop_free(prop_val);
14033859Sml29623 		return;
14043859Sml29623 	}
14053859Sml29623 
14063859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-1000hdx-cap",
14076929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14083859Sml29623 		ddi_prop_free(prop_val);
14093859Sml29623 		return;
14103859Sml29623 	}
14113859Sml29623 
14123859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-1000fdx-cap",
14136929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14143859Sml29623 		ddi_prop_free(prop_val);
14153859Sml29623 		return;
14163859Sml29623 	}
14173859Sml29623 
14183859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-100fdx-cap",
14196929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14203859Sml29623 		ddi_prop_free(prop_val);
14213859Sml29623 		return;
14223859Sml29623 	}
14233859Sml29623 
14243859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-100hdx-cap",
14256929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14263859Sml29623 		ddi_prop_free(prop_val);
14273859Sml29623 		return;
14283859Sml29623 	}
14293859Sml29623 
14303859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10fdx-cap",
14316929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14323859Sml29623 		ddi_prop_free(prop_val);
14333859Sml29623 		return;
14343859Sml29623 	}
14353859Sml29623 
14363859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10hdx-cap",
14376929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14383859Sml29623 		ddi_prop_free(prop_val);
14393859Sml29623 		return;
14403859Sml29623 	}
14413859Sml29623 
14423859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0, "speed",
14436929Smisaki 	    (uchar_t **)&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14443859Sml29623 		if (strncmp("10000", (caddr_t)prop_val,
14456929Smisaki 		    (size_t)prop_len) == 0) {
14463859Sml29623 			speed = 10000;
14473859Sml29623 		} else if (strncmp("1000", (caddr_t)prop_val,
14486929Smisaki 		    (size_t)prop_len) == 0) {
14493859Sml29623 			speed = 1000;
14503859Sml29623 		} else if (strncmp("100", (caddr_t)prop_val,
14516929Smisaki 		    (size_t)prop_len) == 0) {
14523859Sml29623 			speed = 100;
14533859Sml29623 		} else if (strncmp("10", (caddr_t)prop_val,
14546929Smisaki 		    (size_t)prop_len) == 0) {
14553859Sml29623 			speed = 10;
14563859Sml29623 		} else if (strncmp("auto", (caddr_t)prop_val,
14576929Smisaki 		    (size_t)prop_len) == 0) {
14583859Sml29623 			speed = 0;
14593859Sml29623 		} else {
14603859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_NOTE,
14616929Smisaki 			    "speed property is invalid reverting to auto"));
14623859Sml29623 			speed = 0;
14633859Sml29623 		}
14643859Sml29623 		ddi_prop_free(prop_val);
14653859Sml29623 	} else
14663859Sml29623 		speed = 0;
14673859Sml29623 
14683859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0, "duplex",
14696929Smisaki 	    (uchar_t **)&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
14703859Sml29623 		if (strncmp("full", (caddr_t)prop_val,
14716929Smisaki 		    (size_t)prop_len) == 0) {
14723859Sml29623 			duplex = 2;
14733859Sml29623 		} else if (strncmp("half", (caddr_t)prop_val,
14746929Smisaki 		    (size_t)prop_len) == 0) {
14753859Sml29623 			duplex = 1;
14763859Sml29623 		} else if (strncmp("auto", (caddr_t)prop_val,
14776929Smisaki 		    (size_t)prop_len) == 0) {
14783859Sml29623 			duplex = 0;
14793859Sml29623 		} else {
14803859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_NOTE,
14816929Smisaki 			    "duplex property is invalid"
14826929Smisaki 			    " reverting to auto"));
14833859Sml29623 			duplex = 0;
14843859Sml29623 		}
14853859Sml29623 		ddi_prop_free(prop_val);
14863859Sml29623 	} else
14873859Sml29623 		duplex = 0;
14883859Sml29623 
14896835Syc148097 	/* speed == 0 or duplex == 0 means auto negotiation. */
14903859Sml29623 	adv_autoneg_cap = (speed == 0) || (duplex == 0);
14913859Sml29623 	if (adv_autoneg_cap == 0) {
14923859Sml29623 		adv_10gfdx_cap = ((speed == 10000) && (duplex == 2));
14933859Sml29623 		adv_10ghdx_cap = adv_10gfdx_cap;
14943859Sml29623 		adv_10ghdx_cap |= ((speed == 10000) && (duplex == 1));
14953859Sml29623 		adv_1000fdx_cap = adv_10ghdx_cap;
14963859Sml29623 		adv_1000fdx_cap |= ((speed == 1000) && (duplex == 2));
14973859Sml29623 		adv_1000hdx_cap = adv_1000fdx_cap;
14983859Sml29623 		adv_1000hdx_cap |= ((speed == 1000) && (duplex == 1));
14993859Sml29623 		adv_100fdx_cap = adv_1000hdx_cap;
15003859Sml29623 		adv_100fdx_cap |= ((speed == 100) && (duplex == 2));
15013859Sml29623 		adv_100hdx_cap = adv_100fdx_cap;
15023859Sml29623 		adv_100hdx_cap |= ((speed == 100) && (duplex == 1));
15033859Sml29623 		adv_10fdx_cap = adv_100hdx_cap;
15043859Sml29623 		adv_10fdx_cap |= ((speed == 10) && (duplex == 2));
15053859Sml29623 		adv_10hdx_cap = adv_10fdx_cap;
15063859Sml29623 		adv_10hdx_cap |= ((speed == 10) && (duplex == 1));
15073859Sml29623 	} else if (speed == 0) {
15083859Sml29623 		adv_10gfdx_cap = (duplex == 2);
15093859Sml29623 		adv_10ghdx_cap = (duplex == 1);
15103859Sml29623 		adv_1000fdx_cap = (duplex == 2);
15113859Sml29623 		adv_1000hdx_cap = (duplex == 1);
15123859Sml29623 		adv_100fdx_cap = (duplex == 2);
15133859Sml29623 		adv_100hdx_cap = (duplex == 1);
15143859Sml29623 		adv_10fdx_cap = (duplex == 2);
15153859Sml29623 		adv_10hdx_cap = (duplex == 1);
15163859Sml29623 	}
15173859Sml29623 	if (duplex == 0) {
15183859Sml29623 		adv_10gfdx_cap = (speed == 0);
15193859Sml29623 		adv_10gfdx_cap |= (speed == 10000);
15203859Sml29623 		adv_10ghdx_cap = adv_10gfdx_cap;
15213859Sml29623 		adv_10ghdx_cap |= (speed == 10000);
15223859Sml29623 		adv_1000fdx_cap = adv_10ghdx_cap;
15233859Sml29623 		adv_1000fdx_cap |= (speed == 1000);
15243859Sml29623 		adv_1000hdx_cap = adv_1000fdx_cap;
15253859Sml29623 		adv_1000hdx_cap |= (speed == 1000);
15263859Sml29623 		adv_100fdx_cap = adv_1000hdx_cap;
15273859Sml29623 		adv_100fdx_cap |= (speed == 100);
15283859Sml29623 		adv_100hdx_cap = adv_100fdx_cap;
15293859Sml29623 		adv_100hdx_cap |= (speed == 100);
15303859Sml29623 		adv_10fdx_cap = adv_100hdx_cap;
15313859Sml29623 		adv_10fdx_cap |= (speed == 10);
15323859Sml29623 		adv_10hdx_cap = adv_10fdx_cap;
15333859Sml29623 		adv_10hdx_cap |= (speed == 10);
15343859Sml29623 	}
15353859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15366929Smisaki 	    "adv-autoneg-cap", &adv_autoneg_cap, 1);
15373859Sml29623 	if (status)
15383859Sml29623 		return;
15393859Sml29623 
15403859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15416929Smisaki 	    "adv-10gfdx-cap", &adv_10gfdx_cap, 1);
15423859Sml29623 	if (status)
15433859Sml29623 		goto nxge_map_myargs_to_gmii_fail1;
15443859Sml29623 
15453859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15466929Smisaki 	    "adv-10ghdx-cap", &adv_10ghdx_cap, 1);
15473859Sml29623 	if (status)
15483859Sml29623 		goto nxge_map_myargs_to_gmii_fail2;
15493859Sml29623 
15503859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15516929Smisaki 	    "adv-1000fdx-cap", &adv_1000fdx_cap, 1);
15523859Sml29623 	if (status)
15533859Sml29623 		goto nxge_map_myargs_to_gmii_fail3;
15543859Sml29623 
15553859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15566929Smisaki 	    "adv-1000hdx-cap", &adv_1000hdx_cap, 1);
15573859Sml29623 	if (status)
15583859Sml29623 		goto nxge_map_myargs_to_gmii_fail4;
15593859Sml29623 
15603859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15616929Smisaki 	    "adv-100fdx-cap", &adv_100fdx_cap, 1);
15623859Sml29623 	if (status)
15633859Sml29623 		goto nxge_map_myargs_to_gmii_fail5;
15643859Sml29623 
15653859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15666929Smisaki 	    "adv-100hdx-cap", &adv_100hdx_cap, 1);
15673859Sml29623 	if (status)
15683859Sml29623 		goto nxge_map_myargs_to_gmii_fail6;
15693859Sml29623 
15703859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15716929Smisaki 	    "adv-10fdx-cap", &adv_10fdx_cap, 1);
15723859Sml29623 	if (status)
15733859Sml29623 		goto nxge_map_myargs_to_gmii_fail7;
15743859Sml29623 
15753859Sml29623 	status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
15766929Smisaki 	    "adv-10hdx-cap", &adv_10hdx_cap, 1);
15773859Sml29623 	if (status)
15783859Sml29623 		goto nxge_map_myargs_to_gmii_fail8;
15793859Sml29623 
15803859Sml29623 	return;
15813859Sml29623 
15823859Sml29623 nxge_map_myargs_to_gmii_fail9:
15833859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10hdx-cap");
15843859Sml29623 
15853859Sml29623 nxge_map_myargs_to_gmii_fail8:
15863859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10fdx-cap");
15873859Sml29623 
15883859Sml29623 nxge_map_myargs_to_gmii_fail7:
15893859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-100hdx-cap");
15903859Sml29623 
15913859Sml29623 nxge_map_myargs_to_gmii_fail6:
15923859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-100fdx-cap");
15933859Sml29623 
15943859Sml29623 nxge_map_myargs_to_gmii_fail5:
15953859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-1000hdx-cap");
15963859Sml29623 
15973859Sml29623 nxge_map_myargs_to_gmii_fail4:
15983859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-1000fdx-cap");
15993859Sml29623 
16003859Sml29623 nxge_map_myargs_to_gmii_fail3:
16013859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10ghdx-cap");
16023859Sml29623 
16033859Sml29623 nxge_map_myargs_to_gmii_fail2:
16043859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10gfdx-cap");
16053859Sml29623 
16063859Sml29623 nxge_map_myargs_to_gmii_fail1:
16073859Sml29623 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-autoneg-cap");
16083859Sml29623 }
16093859Sml29623 
16103859Sml29623 nxge_status_t
nxge_get_config_properties(p_nxge_t nxgep)16113859Sml29623 nxge_get_config_properties(p_nxge_t nxgep)
16123859Sml29623 {
16133859Sml29623 	nxge_status_t status = NXGE_OK;
16143859Sml29623 	p_nxge_hw_list_t hw_p;
161511304SJanie.Lu@Sun.COM 	char **prop_val;
161611304SJanie.Lu@Sun.COM 	uint_t prop_len;
161711304SJanie.Lu@Sun.COM 	uint_t i;
16183859Sml29623 
16193859Sml29623 	NXGE_DEBUG_MSG((nxgep, VPD_CTL, " ==> nxge_get_config_properties"));
16203859Sml29623 
16213859Sml29623 	if ((hw_p = nxgep->nxge_hw_p) == NULL) {
16223859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
16236929Smisaki 		    " nxge_get_config_properties:"
16246929Smisaki 		    " common hardware not set", nxgep->niu_type));
16253859Sml29623 		return (NXGE_ERROR);
16263859Sml29623 	}
16273859Sml29623 
16283859Sml29623 	/*
16293859Sml29623 	 * Get info on how many ports Neptune card has.
16303859Sml29623 	 */
16314977Sraghus 	nxgep->nports = nxge_get_nports(nxgep);
16324732Sdavemq 	if (nxgep->nports <= 0) {
16334732Sdavemq 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
16344732Sdavemq 		    "<==nxge_get_config_properties: Invalid Neptune type 0x%x",
16354732Sdavemq 		    nxgep->niu_type));
16364732Sdavemq 		return (NXGE_ERROR);
16374732Sdavemq 	}
16384732Sdavemq 	nxgep->classifier.tcam_size = TCAM_NIU_TCAM_MAX_ENTRY;
16394977Sraghus 	if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
16404977Sraghus 		nxgep->classifier.tcam_size = TCAM_NXGE_TCAM_MAX_ENTRY;
16414977Sraghus 	}
16424732Sdavemq 	if (nxgep->function_num >= nxgep->nports) {
16434732Sdavemq 		return (NXGE_ERROR);
16443859Sml29623 	}
16453859Sml29623 
16463859Sml29623 	status = nxge_get_mac_addr_properties(nxgep);
16473859Sml29623 	if (status != NXGE_OK)
16483859Sml29623 		return (NXGE_ERROR);
16493859Sml29623 
16503859Sml29623 	/*
16513859Sml29623 	 * read the configuration type. If none is specified, used default.
16523859Sml29623 	 * Config types: equal: (default) DMA channels, RDC groups, TCAM, FCRAM
16533859Sml29623 	 * are shared equally across all the ports.
16543859Sml29623 	 *
16553859Sml29623 	 * Fair: DMA channels, RDC groups, TCAM, FCRAM are shared proportional
16563859Sml29623 	 * to the port speed.
16573859Sml29623 	 *
16583859Sml29623 	 *
16593859Sml29623 	 * custom: DMA channels, RDC groups, TCAM, FCRAM partition is
16603859Sml29623 	 * specified in nxge.conf. Need to read each parameter and set
16613859Sml29623 	 * up the parameters in nxge structures.
16623859Sml29623 	 *
16633859Sml29623 	 */
16643859Sml29623 	switch (nxgep->niu_type) {
16653859Sml29623 	case N2_NIU:
16663859Sml29623 		NXGE_DEBUG_MSG((nxgep, VPD_CTL,
16676929Smisaki 		    " ==> nxge_get_config_properties: N2"));
16683859Sml29623 		MUTEX_ENTER(&hw_p->nxge_cfg_lock);
16693859Sml29623 		if ((hw_p->flags & COMMON_CFG_VALID) !=
16706929Smisaki 		    COMMON_CFG_VALID) {
16713859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16726929Smisaki 			    COMMON_RXDMA_GRP_CFG);
16733859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16746929Smisaki 			    COMMON_CLASS_CFG);
16753859Sml29623 			hw_p->flags |= COMMON_CFG_VALID;
16763859Sml29623 		}
16773859Sml29623 		MUTEX_EXIT(&hw_p->nxge_cfg_lock);
16783859Sml29623 		status = nxge_use_cfg_n2niu_properties(nxgep);
16793859Sml29623 		break;
16804732Sdavemq 	default:
16814977Sraghus 		if (!NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
16824732Sdavemq 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
16834732Sdavemq 			    " nxge_get_config_properties:"
16844732Sdavemq 			    " unknown NIU type 0x%x", nxgep->niu_type));
16854732Sdavemq 			return (NXGE_ERROR);
16864732Sdavemq 		}
16874732Sdavemq 
16883859Sml29623 		NXGE_DEBUG_MSG((nxgep, VPD_CTL,
16896929Smisaki 		    " ==> nxge_get_config_properties: Neptune"));
16903859Sml29623 		status = nxge_cfg_verify_set_quick_config(nxgep);
16913859Sml29623 		MUTEX_ENTER(&hw_p->nxge_cfg_lock);
16923859Sml29623 		if ((hw_p->flags & COMMON_CFG_VALID) !=
16936929Smisaki 		    COMMON_CFG_VALID) {
16943859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16956929Smisaki 			    COMMON_TXDMA_CFG);
16963859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16976929Smisaki 			    COMMON_RXDMA_CFG);
16983859Sml29623 			status = nxge_cfg_verify_set(nxgep,
16996929Smisaki 			    COMMON_RXDMA_GRP_CFG);
17003859Sml29623 			status = nxge_cfg_verify_set(nxgep,
17016929Smisaki 			    COMMON_CLASS_CFG);
17023859Sml29623 			hw_p->flags |= COMMON_CFG_VALID;
17033859Sml29623 		}
17043859Sml29623 		MUTEX_EXIT(&hw_p->nxge_cfg_lock);
17053859Sml29623 		nxge_use_cfg_neptune_properties(nxgep);
17063859Sml29623 		status = NXGE_OK;
17073859Sml29623 		break;
17083859Sml29623 	}
17093859Sml29623 
17106003Sml29623 	/*
17116003Sml29623 	 * Get the software LSO enable flag property from the
17126003Sml29623 	 * driver configuration file (nxge.conf).
17136003Sml29623 	 * This flag will be set to disable (0) if this property
17146003Sml29623 	 * does not exist.
17156003Sml29623 	 */
17166003Sml29623 	nxgep->soft_lso_enable = ddi_prop_get_int(DDI_DEV_T_ANY, nxgep->dip,
17176003Sml29623 	    DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "soft-lso-enable", 0);
17186003Sml29623 	NXGE_DEBUG_MSG((nxgep, VPD_CTL,
17196003Sml29623 	    "nxge_get_config_properties: software lso %d\n",
17206003Sml29623 	    nxgep->soft_lso_enable));
17216003Sml29623 
172211304SJanie.Lu@Sun.COM 	nxgep->niu_hw_type = NIU_HW_TYPE_DEFAULT;
172311304SJanie.Lu@Sun.COM 	if (nxgep->niu_type == N2_NIU) {
1724*12452SSantwona.Behera@oracle.COM 
1725*12452SSantwona.Behera@oracle.COM 		uchar_t *s_prop_val;
1726*12452SSantwona.Behera@oracle.COM 
172711304SJanie.Lu@Sun.COM 		/*
172811304SJanie.Lu@Sun.COM 		 * For NIU, the next generation KT has
172911304SJanie.Lu@Sun.COM 		 * a few differences in features that the
173011304SJanie.Lu@Sun.COM 		 * driver needs to handle them
173111304SJanie.Lu@Sun.COM 		 * accordingly.
173211304SJanie.Lu@Sun.COM 		 */
173311304SJanie.Lu@Sun.COM 		if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, nxgep->dip, 0,
173411304SJanie.Lu@Sun.COM 		    "compatible", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
173511304SJanie.Lu@Sun.COM 			for (i = 0; i < prop_len; i++) {
173611304SJanie.Lu@Sun.COM 				if ((strcmp((caddr_t)prop_val[i],
173711304SJanie.Lu@Sun.COM 				    KT_NIU_COMPATIBLE) == 0)) {
173811304SJanie.Lu@Sun.COM 					nxgep->niu_hw_type = NIU_HW_TYPE_RF;
173911304SJanie.Lu@Sun.COM 					NXGE_DEBUG_MSG((nxgep, VPD_CTL,
174011304SJanie.Lu@Sun.COM 					    "NIU type %d", nxgep->niu_hw_type));
174111304SJanie.Lu@Sun.COM 					break;
174211304SJanie.Lu@Sun.COM 				}
174311304SJanie.Lu@Sun.COM 			}
174411304SJanie.Lu@Sun.COM 		}
174511304SJanie.Lu@Sun.COM 
174611304SJanie.Lu@Sun.COM 		ddi_prop_free(prop_val);
1747*12452SSantwona.Behera@oracle.COM 		/*
1748*12452SSantwona.Behera@oracle.COM 		 * Some Serdes and PHY properties may also be provided as OBP
1749*12452SSantwona.Behera@oracle.COM 		 * properties
1750*12452SSantwona.Behera@oracle.COM 		 */
1751*12452SSantwona.Behera@oracle.COM 		if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1752*12452SSantwona.Behera@oracle.COM 		    "tx-cfg-l", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1753*12452SSantwona.Behera@oracle.COM 			nxgep->srds_prop.tx_cfg_l =
1754*12452SSantwona.Behera@oracle.COM 			    (uint16_t)(*(uint32_t *)s_prop_val);
1755*12452SSantwona.Behera@oracle.COM 			NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1756*12452SSantwona.Behera@oracle.COM 			    "nxge_get_config_properties: "
1757*12452SSantwona.Behera@oracle.COM 			    "tx_cfg_l 0x%x, Read from OBP",
1758*12452SSantwona.Behera@oracle.COM 			    nxgep->srds_prop.tx_cfg_l));
1759*12452SSantwona.Behera@oracle.COM 			nxgep->srds_prop.prop_set |= NXGE_SRDS_TXCFGL;
1760*12452SSantwona.Behera@oracle.COM 			ddi_prop_free(s_prop_val);
1761*12452SSantwona.Behera@oracle.COM 		}
1762*12452SSantwona.Behera@oracle.COM 		if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1763*12452SSantwona.Behera@oracle.COM 		    "tx-cfg-h", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1764*12452SSantwona.Behera@oracle.COM 			nxgep->srds_prop.tx_cfg_h =
1765*12452SSantwona.Behera@oracle.COM 			    (uint16_t)(*(uint32_t *)s_prop_val);
1766*12452SSantwona.Behera@oracle.COM 			NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1767*12452SSantwona.Behera@oracle.COM 			    "nxge_get_config_properties: "
1768*12452SSantwona.Behera@oracle.COM 			    "tx_cfg_h 0x%x, Read from OBP",
1769*12452SSantwona.Behera@oracle.COM 			    nxgep->srds_prop.tx_cfg_h));
1770*12452SSantwona.Behera@oracle.COM 			nxgep->srds_prop.prop_set |= NXGE_SRDS_TXCFGH;
1771*12452SSantwona.Behera@oracle.COM 			ddi_prop_free(s_prop_val);
1772*12452SSantwona.Behera@oracle.COM 		}
1773*12452SSantwona.Behera@oracle.COM 		if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1774*12452SSantwona.Behera@oracle.COM 		    "rx-cfg-l", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1775*12452SSantwona.Behera@oracle.COM 			nxgep->srds_prop.rx_cfg_l =
1776*12452SSantwona.Behera@oracle.COM 			    (uint16_t)(*(uint32_t *)s_prop_val);
1777*12452SSantwona.Behera@oracle.COM 			NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1778*12452SSantwona.Behera@oracle.COM 			    "nxge_get_config_properties: "
1779*12452SSantwona.Behera@oracle.COM 			    "rx_cfg_l 0x%x, Read from OBP",
1780*12452SSantwona.Behera@oracle.COM 			    nxgep->srds_prop.rx_cfg_l));
1781*12452SSantwona.Behera@oracle.COM 			nxgep->srds_prop.prop_set |= NXGE_SRDS_RXCFGL;
1782*12452SSantwona.Behera@oracle.COM 			ddi_prop_free(s_prop_val);
1783*12452SSantwona.Behera@oracle.COM 		}
1784*12452SSantwona.Behera@oracle.COM 		if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1785*12452SSantwona.Behera@oracle.COM 		    "rx-cfg-h", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1786*12452SSantwona.Behera@oracle.COM 			nxgep->srds_prop.rx_cfg_h =
1787*12452SSantwona.Behera@oracle.COM 			    (uint16_t)(*(uint32_t *)s_prop_val);
1788*12452SSantwona.Behera@oracle.COM 			NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1789*12452SSantwona.Behera@oracle.COM 			    "nxge_get_config_properties: "
1790*12452SSantwona.Behera@oracle.COM 			    "rx_cfg_h 0x%x, Read from OBP",
1791*12452SSantwona.Behera@oracle.COM 			    nxgep->srds_prop.rx_cfg_h));
1792*12452SSantwona.Behera@oracle.COM 			nxgep->srds_prop.prop_set |= NXGE_SRDS_RXCFGH;
1793*12452SSantwona.Behera@oracle.COM 			ddi_prop_free(s_prop_val);
1794*12452SSantwona.Behera@oracle.COM 		}
1795*12452SSantwona.Behera@oracle.COM 		if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1796*12452SSantwona.Behera@oracle.COM 		    "pll-cfg", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1797*12452SSantwona.Behera@oracle.COM 			nxgep->srds_prop.pll_cfg_l =
1798*12452SSantwona.Behera@oracle.COM 			    (uint16_t)(*(uint32_t *)s_prop_val);
1799*12452SSantwona.Behera@oracle.COM 			NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1800*12452SSantwona.Behera@oracle.COM 			    "nxge_get_config_properties: "
1801*12452SSantwona.Behera@oracle.COM 			    "pll_cfg_l 0x%x, Read from OBP",
1802*12452SSantwona.Behera@oracle.COM 			    nxgep->srds_prop.pll_cfg_l));
1803*12452SSantwona.Behera@oracle.COM 			nxgep->srds_prop.prop_set |= NXGE_SRDS_PLLCFGL;
1804*12452SSantwona.Behera@oracle.COM 			ddi_prop_free(s_prop_val);
1805*12452SSantwona.Behera@oracle.COM 		}
1806*12452SSantwona.Behera@oracle.COM 		if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1807*12452SSantwona.Behera@oracle.COM 		    "phy-reg-values", &s_prop_val, &prop_len) ==
1808*12452SSantwona.Behera@oracle.COM 		    DDI_PROP_SUCCESS) {
1809*12452SSantwona.Behera@oracle.COM 
1810*12452SSantwona.Behera@oracle.COM 			int tun_cnt, i;
1811*12452SSantwona.Behera@oracle.COM 			uchar_t *arr = s_prop_val;
1812*12452SSantwona.Behera@oracle.COM 
1813*12452SSantwona.Behera@oracle.COM 			tun_cnt = prop_len / 6; /* 3 values, 2 bytes each */
1814*12452SSantwona.Behera@oracle.COM 			nxgep->phy_prop.arr =
1815*12452SSantwona.Behera@oracle.COM 			    KMEM_ZALLOC(sizeof (nxge_phy_mdio_val_t) * tun_cnt,
1816*12452SSantwona.Behera@oracle.COM 			    KM_SLEEP);
1817*12452SSantwona.Behera@oracle.COM 			nxgep->phy_prop.cnt = tun_cnt;
1818*12452SSantwona.Behera@oracle.COM 			for (i = 0; i < tun_cnt; i++) {
1819*12452SSantwona.Behera@oracle.COM 				nxgep->phy_prop.arr[i].dev = *(uint16_t *)arr;
1820*12452SSantwona.Behera@oracle.COM 				arr += 2;
1821*12452SSantwona.Behera@oracle.COM 				nxgep->phy_prop.arr[i].reg = *(uint16_t *)arr;
1822*12452SSantwona.Behera@oracle.COM 				arr += 2;
1823*12452SSantwona.Behera@oracle.COM 				nxgep->phy_prop.arr[i].val = *(uint16_t *)arr;
1824*12452SSantwona.Behera@oracle.COM 				arr += 2;
1825*12452SSantwona.Behera@oracle.COM 				NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1826*12452SSantwona.Behera@oracle.COM 				    "nxge_get_config_properties: From OBP, "
1827*12452SSantwona.Behera@oracle.COM 				    "read PHY <dev.reg.val> = "
1828*12452SSantwona.Behera@oracle.COM 				    "<0x%x.0x%x.0x%x>",
1829*12452SSantwona.Behera@oracle.COM 				    nxgep->phy_prop.arr[i].dev,
1830*12452SSantwona.Behera@oracle.COM 				    nxgep->phy_prop.arr[i].reg,
1831*12452SSantwona.Behera@oracle.COM 				    nxgep->phy_prop.arr[i].val));
1832*12452SSantwona.Behera@oracle.COM 			}
1833*12452SSantwona.Behera@oracle.COM 			ddi_prop_free(s_prop_val);
1834*12452SSantwona.Behera@oracle.COM 		}
183511304SJanie.Lu@Sun.COM 	}
183611304SJanie.Lu@Sun.COM 
18373859Sml29623 	NXGE_DEBUG_MSG((nxgep, VPD_CTL, " <== nxge_get_config_properties"));
18383859Sml29623 	return (status);
18393859Sml29623 }
18403859Sml29623 
18413859Sml29623 static nxge_status_t
nxge_use_cfg_n2niu_properties(p_nxge_t nxgep)18423859Sml29623 nxge_use_cfg_n2niu_properties(p_nxge_t nxgep)
18433859Sml29623 {
18443859Sml29623 	nxge_status_t status = NXGE_OK;
18453859Sml29623 
18463859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_n2niu_properties"));
18473859Sml29623 
18483859Sml29623 	status = nxge_use_default_dma_config_n2(nxgep);
18493859Sml29623 	if (status != NXGE_OK) {
18503859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
18516929Smisaki 		    " ==> nxge_use_cfg_n2niu_properties (err 0x%x)",
18526929Smisaki 		    status));
18533859Sml29623 		return (status | NXGE_ERROR);
18543859Sml29623 	}
18553859Sml29623 
18563859Sml29623 	(void) nxge_use_cfg_vlan_class_config(nxgep);
18573859Sml29623 	(void) nxge_use_cfg_mac_class_config(nxgep);
18583859Sml29623 	(void) nxge_use_cfg_class_config(nxgep);
18593859Sml29623 	(void) nxge_use_cfg_link_cfg(nxgep);
18603859Sml29623 
18613859Sml29623 	/*
18623859Sml29623 	 * Read in the hardware (fcode) properties. Use the ndd array to read
18633859Sml29623 	 * each property.
18643859Sml29623 	 */
18653859Sml29623 	(void) nxge_get_param_soft_properties(nxgep);
18663859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_n2niu_properties"));
18673859Sml29623 
18683859Sml29623 	return (status);
18693859Sml29623 }
18703859Sml29623 
18713859Sml29623 static void
nxge_use_cfg_neptune_properties(p_nxge_t nxgep)18723859Sml29623 nxge_use_cfg_neptune_properties(p_nxge_t nxgep)
18733859Sml29623 {
18743859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_neptune_properties"));
18753859Sml29623 
18763859Sml29623 	(void) nxge_use_cfg_dma_config(nxgep);
18773859Sml29623 	(void) nxge_use_cfg_vlan_class_config(nxgep);
18783859Sml29623 	(void) nxge_use_cfg_mac_class_config(nxgep);
18793859Sml29623 	(void) nxge_use_cfg_class_config(nxgep);
18803859Sml29623 	(void) nxge_use_cfg_link_cfg(nxgep);
18813859Sml29623 
18823859Sml29623 	/*
18833859Sml29623 	 * Read in the hardware (fcode) properties. Use the ndd array to read
18843859Sml29623 	 * each property.
18853859Sml29623 	 */
18863859Sml29623 	(void) nxge_get_param_soft_properties(nxgep);
18873859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_neptune_properties"));
18883859Sml29623 }
18893859Sml29623 
18903859Sml29623 /*
18919015SMichael.Speer@Sun.COM  * FWARC 2006/556 for N2 NIU.  Get the properties
18929015SMichael.Speer@Sun.COM  * from the prom.
18933859Sml29623  */
18943859Sml29623 static nxge_status_t
nxge_use_default_dma_config_n2(p_nxge_t nxgep)18953859Sml29623 nxge_use_default_dma_config_n2(p_nxge_t nxgep)
18963859Sml29623 {
18979015SMichael.Speer@Sun.COM 	int			ndmas;
18989015SMichael.Speer@Sun.COM 	uint8_t			func;
18999015SMichael.Speer@Sun.COM 	p_nxge_dma_pt_cfg_t	p_dma_cfgp;
19009015SMichael.Speer@Sun.COM 	p_nxge_hw_pt_cfg_t	p_cfgp;
19019015SMichael.Speer@Sun.COM 	int			*prop_val;
19029015SMichael.Speer@Sun.COM 	uint_t			prop_len;
19039015SMichael.Speer@Sun.COM 	int			i;
19049015SMichael.Speer@Sun.COM 	nxge_status_t		status = NXGE_OK;
19053859Sml29623 
19063859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2"));
19073859Sml29623 
19083859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
19093859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
19103859Sml29623 
19113859Sml29623 	func = nxgep->function_num;
19123859Sml29623 	p_cfgp->function_number = func;
19133859Sml29623 	ndmas = NXGE_TDMA_PER_NIU_PORT;
19143859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
19156929Smisaki 	    "tx-dma-channels", (int **)&prop_val,
19166929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
19179015SMichael.Speer@Sun.COM 		if (prop_len != NXGE_NIU_TDMA_PROP_LEN) {
19189015SMichael.Speer@Sun.COM 			ddi_prop_free(prop_val);
19199015SMichael.Speer@Sun.COM 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
19209015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2: "
192110392SMichael.Speer@Sun.COM 			    "invalid tx-dma-channels property for the NIU, "
192210392SMichael.Speer@Sun.COM 			    "using defaults"));
192310392SMichael.Speer@Sun.COM 			/*
192410392SMichael.Speer@Sun.COM 			 * Just failover to defaults
192510392SMichael.Speer@Sun.COM 			 */
192610392SMichael.Speer@Sun.COM 			p_cfgp->tdc.start = (func * NXGE_TDMA_PER_NIU_PORT);
192710392SMichael.Speer@Sun.COM 			ndmas = NXGE_TDMA_PER_NIU_PORT;
19289015SMichael.Speer@Sun.COM 		} else {
19299015SMichael.Speer@Sun.COM 			p_cfgp->tdc.start = prop_val[0];
19309015SMichael.Speer@Sun.COM 			NXGE_DEBUG_MSG((nxgep, OBP_CTL,
19319015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2: tdc starts %d "
19329015SMichael.Speer@Sun.COM 			    "(#%d)", p_cfgp->tdc.start, prop_len));
19339015SMichael.Speer@Sun.COM 
19349015SMichael.Speer@Sun.COM 			ndmas = prop_val[1];
19359015SMichael.Speer@Sun.COM 			NXGE_DEBUG_MSG((nxgep, OBP_CTL,
19369015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2: #tdc %d (#%d)",
19379015SMichael.Speer@Sun.COM 			    ndmas, prop_len));
19389015SMichael.Speer@Sun.COM 			ddi_prop_free(prop_val);
19399015SMichael.Speer@Sun.COM 		}
19403859Sml29623 	} else {
19413859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
19426929Smisaki 		    "==> nxge_use_default_dma_config_n2: "
19436929Smisaki 		    "get tx-dma-channels failed"));
19443859Sml29623 		return (NXGE_DDI_FAILED);
19453859Sml29623 	}
19463859Sml29623 
19478275SEric Cheng 	p_cfgp->tdc.count = ndmas;
19486495Sspeer 	p_cfgp->tdc.owned = p_cfgp->tdc.count;
19493859Sml29623 
19503859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
19518275SEric Cheng 	    "p_cfgp 0x%llx max_tdcs %d start %d",
19528275SEric Cheng 	    p_cfgp, p_cfgp->tdc.count, p_cfgp->tdc.start));
19533859Sml29623 
19543859Sml29623 	/* Receive DMA */
19553859Sml29623 	ndmas = NXGE_RDMA_PER_NIU_PORT;
19563859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
19576929Smisaki 	    "rx-dma-channels", (int **)&prop_val,
19586929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
195910392SMichael.Speer@Sun.COM 		if (prop_len != NXGE_NIU_RDMA_PROP_LEN) {
19609015SMichael.Speer@Sun.COM 			ddi_prop_free(prop_val);
19619015SMichael.Speer@Sun.COM 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
19629015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2: "
196310392SMichael.Speer@Sun.COM 			    "invalid rx-dma-channels property for the NIU, "
196410392SMichael.Speer@Sun.COM 			    "using defaults"));
196510392SMichael.Speer@Sun.COM 			/*
196610392SMichael.Speer@Sun.COM 			 * Just failover to defaults
196710392SMichael.Speer@Sun.COM 			 */
196810392SMichael.Speer@Sun.COM 			p_cfgp->start_rdc = (func * NXGE_RDMA_PER_NIU_PORT);
196910392SMichael.Speer@Sun.COM 			ndmas = NXGE_RDMA_PER_NIU_PORT;
19709015SMichael.Speer@Sun.COM 		} else {
19719015SMichael.Speer@Sun.COM 			p_cfgp->start_rdc = prop_val[0];
19729015SMichael.Speer@Sun.COM 			NXGE_DEBUG_MSG((nxgep, OBP_CTL,
19739015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2(obp):"
19749015SMichael.Speer@Sun.COM 			    " rdc start %d (#%d)",
19759015SMichael.Speer@Sun.COM 			    p_cfgp->start_rdc, prop_len));
19769015SMichael.Speer@Sun.COM 			ndmas = prop_val[1];
19779015SMichael.Speer@Sun.COM 			NXGE_DEBUG_MSG((nxgep, OBP_CTL,
19789015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2(obp): "
19799015SMichael.Speer@Sun.COM 			    "#rdc %d (#%d)", ndmas, prop_len));
19809015SMichael.Speer@Sun.COM 			ddi_prop_free(prop_val);
19819015SMichael.Speer@Sun.COM 		}
19823859Sml29623 	} else {
19833859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
19846929Smisaki 		    "==> nxge_use_default_dma_config_n2: "
19856929Smisaki 		    "get rx-dma-channel failed"));
19863859Sml29623 		return (NXGE_DDI_FAILED);
19873859Sml29623 	}
19883859Sml29623 
19898275SEric Cheng 	p_cfgp->max_rdcs = ndmas;
19903859Sml29623 	nxgep->rdc_mask = (ndmas - 1);
19913859Sml29623 
19923859Sml29623 	/* Hypervisor: rdc # and group # use the same # !! */
19936495Sspeer 	p_cfgp->max_grpids = p_cfgp->max_rdcs + p_cfgp->tdc.owned;
19943859Sml29623 	p_cfgp->mif_ldvid = p_cfgp->mac_ldvid = p_cfgp->ser_ldvid = 0;
19953859Sml29623 
19963859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
19976929Smisaki 	    "interrupts", (int **)&prop_val,
19986929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
19999015SMichael.Speer@Sun.COM 		if ((prop_len != NXGE_NIU_0_INTR_PROP_LEN) &&
20009015SMichael.Speer@Sun.COM 		    (prop_len != NXGE_NIU_1_INTR_PROP_LEN)) {
20019015SMichael.Speer@Sun.COM 			ddi_prop_free(prop_val);
20029015SMichael.Speer@Sun.COM 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
20039015SMichael.Speer@Sun.COM 			    "==> nxge_use_default_dma_config_n2: "
20049015SMichael.Speer@Sun.COM 			    "get interrupts failed"));
20059015SMichael.Speer@Sun.COM 			return (NXGE_DDI_FAILED);
20069015SMichael.Speer@Sun.COM 		}
20079015SMichael.Speer@Sun.COM 
20083859Sml29623 		/*
20093859Sml29623 		 * For each device assigned, the content of each interrupts
20103859Sml29623 		 * property is its logical device group.
20113859Sml29623 		 *
20123859Sml29623 		 * Assignment of interrupts property is in the the following
20133859Sml29623 		 * order:
20143859Sml29623 		 *
20153859Sml29623 		 * MAC MIF (if configured) SYSTEM ERROR (if configured) first
20163859Sml29623 		 * receive channel next channel...... last receive channel
20173859Sml29623 		 * first transmit channel next channel...... last transmit
20183859Sml29623 		 * channel
20193859Sml29623 		 *
20203859Sml29623 		 * prop_len should be at least for one mac and total # of rx and
20213859Sml29623 		 * tx channels. Function 0 owns MIF and ERROR
20223859Sml29623 		 */
20233859Sml29623 		NXGE_DEBUG_MSG((nxgep, OBP_CTL,
20246929Smisaki 		    "==> nxge_use_default_dma_config_n2(obp): "
20256929Smisaki 		    "# interrupts %d", prop_len));
20263859Sml29623 
20273859Sml29623 		switch (func) {
20283859Sml29623 		case 0:
20293859Sml29623 			p_cfgp->ldg_chn_start = 3;
20303859Sml29623 			p_cfgp->mac_ldvid = NXGE_MAC_LD_PORT0;
20313859Sml29623 			p_cfgp->mif_ldvid = NXGE_MIF_LD;
20323859Sml29623 			p_cfgp->ser_ldvid = NXGE_SYS_ERROR_LD;
20333859Sml29623 
20343859Sml29623 			break;
20353859Sml29623 		case 1:
20363859Sml29623 			p_cfgp->ldg_chn_start = 1;
20373859Sml29623 			p_cfgp->mac_ldvid = NXGE_MAC_LD_PORT1;
20383859Sml29623 
20393859Sml29623 			break;
20403859Sml29623 		default:
20413859Sml29623 			status = NXGE_DDI_FAILED;
20423859Sml29623 			break;
20433859Sml29623 		}
20443859Sml29623 
20453859Sml29623 		if (status != NXGE_OK)
20463859Sml29623 			return (status);
20473859Sml29623 
20483859Sml29623 		for (i = 0; i < prop_len; i++) {
20493859Sml29623 			p_cfgp->ldg[i] = prop_val[i];
20503859Sml29623 			NXGE_DEBUG_MSG((nxgep, OBP_CTL,
20516929Smisaki 			    "==> nxge_use_default_dma_config_n2(obp): "
20526929Smisaki 			    "F%d: interrupt #%d, ldg %d",
20536929Smisaki 			    nxgep->function_num, i, p_cfgp->ldg[i]));
20543859Sml29623 		}
20553859Sml29623 
20563859Sml29623 		p_cfgp->max_grpids = prop_len;
20573859Sml29623 		NXGE_DEBUG_MSG((nxgep, OBP_CTL,
20586929Smisaki 		    "==> nxge_use_default_dma_config_n2(obp): %d "
20596929Smisaki 		    "(#%d) maxgrpids %d channel starts %d",
20606929Smisaki 		    p_cfgp->mac_ldvid, i, p_cfgp->max_grpids,
20616929Smisaki 		    p_cfgp->ldg_chn_start));
20623859Sml29623 		ddi_prop_free(prop_val);
20633859Sml29623 	} else {
20643859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
20656929Smisaki 		    "==> nxge_use_default_dma_config_n2: "
20666929Smisaki 		    "get interrupts failed"));
20673859Sml29623 		return (NXGE_DDI_FAILED);
20683859Sml29623 	}
20693859Sml29623 
20703859Sml29623 	p_cfgp->max_ldgs = p_cfgp->max_grpids;
20713859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL,
20728275SEric Cheng 	    "==> nxge_use_default_dma_config_n2: p_cfgp 0x%llx max_rdcs %d "
20738275SEric Cheng 	    "max_grpids %d macid %d mifid %d serrid %d",
20748275SEric Cheng 	    p_cfgp, p_cfgp->max_rdcs, p_cfgp->max_grpids,
20756929Smisaki 	    p_cfgp->mac_ldvid, p_cfgp->mif_ldvid, p_cfgp->ser_ldvid));
20763859Sml29623 
20778275SEric Cheng 
20783859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
20796929Smisaki 	    "p_cfgp p%p start_ldg %d nxgep->max_ldgs %d",
20806929Smisaki 	    p_cfgp, p_cfgp->start_ldg, p_cfgp->max_ldgs));
20813859Sml29623 
20823859Sml29623 	/*
20833859Sml29623 	 * RDC groups and the beginning RDC group assigned to this function.
20843859Sml29623 	 */
20858275SEric Cheng 	p_cfgp->max_rdc_grpids = NXGE_MAX_RDC_GROUPS / nxgep->nports;
20868275SEric Cheng 	p_cfgp->def_mac_rxdma_grpid =
20878275SEric Cheng 	    nxgep->function_num * NXGE_MAX_RDC_GROUPS / nxgep->nports;
20888275SEric Cheng 	p_cfgp->def_mac_txdma_grpid =
20898275SEric Cheng 	    nxgep->function_num * NXGE_MAX_TDC_GROUPS / nxgep->nports;
20908275SEric Cheng 
20918275SEric Cheng 	if ((p_cfgp->def_mac_rxdma_grpid = nxge_fzc_rdc_tbl_bind(nxgep,
20928275SEric Cheng 	    p_cfgp->def_mac_rxdma_grpid, B_TRUE)) >= NXGE_MAX_RDC_GRPS) {
20936495Sspeer 		NXGE_ERROR_MSG((nxgep, CFG_CTL,
20946495Sspeer 		    "nxge_use_default_dma_config_n2(): "
20956495Sspeer 		    "nxge_fzc_rdc_tbl_bind failed"));
20966495Sspeer 		return (NXGE_DDI_FAILED);
20976495Sspeer 	}
20983859Sml29623 
20993859Sml29623 	status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
21006495Sspeer 	    "rx-rdc-grps", p_cfgp->max_rdc_grpids);
21013859Sml29623 	if (status) {
21023859Sml29623 		return (NXGE_DDI_FAILED);
21033859Sml29623 	}
21043859Sml29623 	status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
21056929Smisaki 	    "rx-rdc-grps-begin", p_cfgp->def_mac_rxdma_grpid);
21063859Sml29623 	if (status) {
21073859Sml29623 		(void) ddi_prop_remove(DDI_DEV_T_NONE, nxgep->dip,
21086929Smisaki 		    "rx-rdc-grps");
21093859Sml29623 		return (NXGE_DDI_FAILED);
21103859Sml29623 	}
21113859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
21126929Smisaki 	    "p_cfgp $%p # rdc groups %d start rdc group id %d",
21136929Smisaki 	    p_cfgp, p_cfgp->max_rdc_grpids,
21146929Smisaki 	    p_cfgp->def_mac_rxdma_grpid));
21153859Sml29623 
21169005SSantwona.Behera@Sun.COM 	nxgep->intr_timeout = NXGE_RDC_RCR_TIMEOUT;
21179005SSantwona.Behera@Sun.COM 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
21189005SSantwona.Behera@Sun.COM 	    "rxdma-intr-time", (int **)&prop_val, &prop_len) ==
21199005SSantwona.Behera@Sun.COM 	    DDI_PROP_SUCCESS) {
21209005SSantwona.Behera@Sun.COM 		if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
21219005SSantwona.Behera@Sun.COM 			nxgep->intr_timeout = prop_val[0];
21229005SSantwona.Behera@Sun.COM 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
21239005SSantwona.Behera@Sun.COM 			    nxgep->dip, "rxdma-intr-time", prop_val, prop_len);
21249005SSantwona.Behera@Sun.COM 		}
21259005SSantwona.Behera@Sun.COM 		ddi_prop_free(prop_val);
21269005SSantwona.Behera@Sun.COM 	}
21279005SSantwona.Behera@Sun.COM 
21289005SSantwona.Behera@Sun.COM 	nxgep->intr_threshold = NXGE_RDC_RCR_THRESHOLD;
21299005SSantwona.Behera@Sun.COM 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
21309005SSantwona.Behera@Sun.COM 	    "rxdma-intr-pkts", (int **)&prop_val, &prop_len) ==
21319005SSantwona.Behera@Sun.COM 	    DDI_PROP_SUCCESS) {
21329005SSantwona.Behera@Sun.COM 		if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
21339005SSantwona.Behera@Sun.COM 			nxgep->intr_threshold = prop_val[0];
21349005SSantwona.Behera@Sun.COM 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
21359005SSantwona.Behera@Sun.COM 			    nxgep->dip, "rxdma-intr-pkts", prop_val, prop_len);
21369005SSantwona.Behera@Sun.COM 		}
21379005SSantwona.Behera@Sun.COM 		ddi_prop_free(prop_val);
21389005SSantwona.Behera@Sun.COM 	}
21399005SSantwona.Behera@Sun.COM 
21403859Sml29623 	nxge_set_hw_dma_config(nxgep);
21413859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "<== nxge_use_default_dma_config_n2"));
21423859Sml29623 	return (status);
21433859Sml29623 }
21443859Sml29623 
21453859Sml29623 static void
nxge_use_cfg_dma_config(p_nxge_t nxgep)21463859Sml29623 nxge_use_cfg_dma_config(p_nxge_t nxgep)
21473859Sml29623 {
21484732Sdavemq 	int tx_ndmas, rx_ndmas, nrxgp, st_txdma, st_rxdma;
21493859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
21503859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
21513859Sml29623 	dev_info_t *dip;
21523859Sml29623 	p_nxge_param_t param_arr;
21533859Sml29623 	char *prop;
21543859Sml29623 	int *prop_val;
21553859Sml29623 	uint_t prop_len;
21564732Sdavemq 	int i;
21574732Sdavemq 	uint8_t *ch_arr_p;
21583859Sml29623 
21593859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_dma_config"));
21603859Sml29623 	param_arr = nxgep->param_arr;
21613859Sml29623 
21623859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
21633859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
21643859Sml29623 	dip = nxgep->dip;
21653859Sml29623 	p_cfgp->function_number = nxgep->function_num;
21663859Sml29623 	prop = param_arr[param_txdma_channels_begin].fcode_name;
21673859Sml29623 
21683859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
21696929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
21706495Sspeer 		p_cfgp->tdc.start = *prop_val;
21713859Sml29623 		ddi_prop_free(prop_val);
21723859Sml29623 	} else {
21734732Sdavemq 		switch (nxgep->niu_type) {
21744732Sdavemq 		case NEPTUNE_4_1GC:
21754732Sdavemq 			ch_arr_p = &tx_4_1G[0];
21764732Sdavemq 			break;
21774732Sdavemq 		case NEPTUNE_2_10GF:
21784732Sdavemq 			ch_arr_p = &tx_2_10G[0];
21794732Sdavemq 			break;
21804732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
21816261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
21824732Sdavemq 			ch_arr_p = &tx_2_10G_2_1G[0];
21834732Sdavemq 			break;
21844732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
21854732Sdavemq 			ch_arr_p = &tx_1_10G_3_1G[0];
21864732Sdavemq 			break;
21874732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
21884732Sdavemq 			ch_arr_p = &tx_1_1G_1_10G_2_1G[0];
21894732Sdavemq 			break;
21904732Sdavemq 		default:
21915196Ssbehera 			switch (nxgep->platform_type) {
21925196Ssbehera 			case P_NEPTUNE_ALONSO:
21935196Ssbehera 				ch_arr_p = &tx_2_10G_2_1G[0];
21945196Ssbehera 				break;
21955196Ssbehera 			default:
21965196Ssbehera 				ch_arr_p = &p4_tx_equal[0];
21975196Ssbehera 				break;
21985196Ssbehera 			}
21994732Sdavemq 			break;
22003859Sml29623 		}
22014732Sdavemq 		st_txdma = 0;
22024732Sdavemq 		for (i = 0; i < nxgep->function_num; i++, ch_arr_p++)
22034732Sdavemq 			st_txdma += *ch_arr_p;
22044732Sdavemq 
22053859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
22064732Sdavemq 		    prop, st_txdma);
22076495Sspeer 		p_cfgp->tdc.start = st_txdma;
22083859Sml29623 	}
22093859Sml29623 
22103859Sml29623 	prop = param_arr[param_txdma_channels].fcode_name;
22113859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
22126929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
22133859Sml29623 		tx_ndmas = *prop_val;
22143859Sml29623 		ddi_prop_free(prop_val);
22153859Sml29623 	} else {
22164732Sdavemq 		switch (nxgep->niu_type) {
22174732Sdavemq 		case NEPTUNE_4_1GC:
22184732Sdavemq 			tx_ndmas = tx_4_1G[nxgep->function_num];
22194732Sdavemq 			break;
22204732Sdavemq 		case NEPTUNE_2_10GF:
22214732Sdavemq 			tx_ndmas = tx_2_10G[nxgep->function_num];
22224732Sdavemq 			break;
22234732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
22246261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
22254732Sdavemq 			tx_ndmas = tx_2_10G_2_1G[nxgep->function_num];
22264732Sdavemq 			break;
22274732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
22284732Sdavemq 			tx_ndmas = tx_1_10G_3_1G[nxgep->function_num];
22294732Sdavemq 			break;
22304732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
22314732Sdavemq 			tx_ndmas = tx_1_1G_1_10G_2_1G[nxgep->function_num];
22324732Sdavemq 			break;
22334732Sdavemq 		default:
22345196Ssbehera 			switch (nxgep->platform_type) {
22355196Ssbehera 			case P_NEPTUNE_ALONSO:
22365196Ssbehera 				tx_ndmas = tx_2_10G_2_1G[nxgep->function_num];
22375196Ssbehera 				break;
22385196Ssbehera 			default:
22395196Ssbehera 				tx_ndmas = p4_tx_equal[nxgep->function_num];
22405196Ssbehera 				break;
22415196Ssbehera 			}
22424732Sdavemq 			break;
22433859Sml29623 		}
22443859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
22456929Smisaki 		    prop, tx_ndmas);
22463859Sml29623 	}
22473859Sml29623 
22488275SEric Cheng 	p_cfgp->tdc.count = tx_ndmas;
22496495Sspeer 	p_cfgp->tdc.owned = p_cfgp->tdc.count;
22503859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_dma_config: "
22518275SEric Cheng 	    "p_cfgp 0x%llx max_tdcs %d", p_cfgp, p_cfgp->tdc.count));
22523859Sml29623 
22533859Sml29623 	prop = param_arr[param_rxdma_channels_begin].fcode_name;
22543859Sml29623 
22553859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
22566929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
22573859Sml29623 		p_cfgp->start_rdc = *prop_val;
22583859Sml29623 		ddi_prop_free(prop_val);
22593859Sml29623 	} else {
22604732Sdavemq 		switch (nxgep->niu_type) {
22614732Sdavemq 		case NEPTUNE_4_1GC:
22624732Sdavemq 			ch_arr_p = &rx_4_1G[0];
22634732Sdavemq 			break;
22644732Sdavemq 		case NEPTUNE_2_10GF:
22654732Sdavemq 			ch_arr_p = &rx_2_10G[0];
22664732Sdavemq 			break;
22674732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
22686261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
22694732Sdavemq 			ch_arr_p = &rx_2_10G_2_1G[0];
22704732Sdavemq 			break;
22714732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
22724732Sdavemq 			ch_arr_p = &rx_1_10G_3_1G[0];
22734732Sdavemq 			break;
22744732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
22754732Sdavemq 			ch_arr_p = &rx_1_1G_1_10G_2_1G[0];
22764732Sdavemq 			break;
22774732Sdavemq 		default:
22785196Ssbehera 			switch (nxgep->platform_type) {
22795196Ssbehera 			case P_NEPTUNE_ALONSO:
22805196Ssbehera 				ch_arr_p = &rx_2_10G_2_1G[0];
22815196Ssbehera 				break;
22825196Ssbehera 			default:
22835196Ssbehera 				ch_arr_p = &p4_rx_equal[0];
22845196Ssbehera 				break;
22855196Ssbehera 			}
22864732Sdavemq 			break;
22873859Sml29623 		}
22884732Sdavemq 		st_rxdma = 0;
22894732Sdavemq 		for (i = 0; i < nxgep->function_num; i++, ch_arr_p++)
22904732Sdavemq 			st_rxdma += *ch_arr_p;
22914732Sdavemq 
22923859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
22934732Sdavemq 		    prop, st_rxdma);
22944732Sdavemq 		p_cfgp->start_rdc = st_rxdma;
22953859Sml29623 	}
22963859Sml29623 
22973859Sml29623 	prop = param_arr[param_rxdma_channels].fcode_name;
22983859Sml29623 
22993859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
23006929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
23013859Sml29623 		rx_ndmas = *prop_val;
23023859Sml29623 		ddi_prop_free(prop_val);
23033859Sml29623 	} else {
23044732Sdavemq 		switch (nxgep->niu_type) {
23054732Sdavemq 		case NEPTUNE_4_1GC:
23064732Sdavemq 			rx_ndmas = rx_4_1G[nxgep->function_num];
23074732Sdavemq 			break;
23084732Sdavemq 		case NEPTUNE_2_10GF:
23094732Sdavemq 			rx_ndmas = rx_2_10G[nxgep->function_num];
23104732Sdavemq 			break;
23114732Sdavemq 		case NEPTUNE_2_10GF_2_1GC:
23126261Sjoycey 		case NEPTUNE_2_10GF_2_1GRF:
23134732Sdavemq 			rx_ndmas = rx_2_10G_2_1G[nxgep->function_num];
23144732Sdavemq 			break;
23154732Sdavemq 		case NEPTUNE_1_10GF_3_1GC:
23164732Sdavemq 			rx_ndmas = rx_1_10G_3_1G[nxgep->function_num];
23174732Sdavemq 			break;
23184732Sdavemq 		case NEPTUNE_1_1GC_1_10GF_2_1GC:
23194732Sdavemq 			rx_ndmas = rx_1_1G_1_10G_2_1G[nxgep->function_num];
23204732Sdavemq 			break;
23214732Sdavemq 		default:
23225196Ssbehera 			switch (nxgep->platform_type) {
23235196Ssbehera 			case P_NEPTUNE_ALONSO:
23245196Ssbehera 				rx_ndmas = rx_2_10G_2_1G[nxgep->function_num];
23255196Ssbehera 				break;
23265196Ssbehera 			default:
23275196Ssbehera 				rx_ndmas = p4_rx_equal[nxgep->function_num];
23285196Ssbehera 				break;
23295196Ssbehera 			}
23304732Sdavemq 			break;
23313859Sml29623 		}
23323859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
23336929Smisaki 		    prop, rx_ndmas);
23343859Sml29623 	}
23353859Sml29623 
23368275SEric Cheng 	p_cfgp->max_rdcs = rx_ndmas;
23378275SEric Cheng 
23388275SEric Cheng 	/*
23398275SEric Cheng 	 * RDC groups and the beginning RDC group assigned to this function.
23408275SEric Cheng 	 * XXX: this may be wrong if prop value is used.
23418275SEric Cheng 	 */
23428275SEric Cheng 	p_cfgp->def_mac_rxdma_grpid =
23438275SEric Cheng 	    nxgep->function_num * NXGE_MAX_RDC_GROUPS / nxgep->nports;
23448275SEric Cheng 	p_cfgp->def_mac_txdma_grpid =
23458275SEric Cheng 	    nxgep->function_num * NXGE_MAX_TDC_GROUPS / nxgep->nports;
23468275SEric Cheng 
23478275SEric Cheng 	if ((p_cfgp->def_mac_rxdma_grpid = nxge_fzc_rdc_tbl_bind(nxgep,
23488275SEric Cheng 	    p_cfgp->def_mac_rxdma_grpid, B_TRUE)) >= NXGE_MAX_RDC_GRPS) {
23498275SEric Cheng 		NXGE_ERROR_MSG((nxgep, CFG_CTL,
23508275SEric Cheng 		    "nxge_use_default_dma_config2(): "
23518275SEric Cheng 		    "nxge_fzc_rdc_tbl_bind failed"));
23528275SEric Cheng 		goto nxge_use_cfg_dma_config_exit;
23533859Sml29623 	}
23543859Sml29623 
23553859Sml29623 	prop = param_arr[param_rx_rdc_grps].fcode_name;
23563859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
23576929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
23583859Sml29623 		nrxgp = *prop_val;
23593859Sml29623 		ddi_prop_free(prop_val);
23603859Sml29623 	} else {
23618275SEric Cheng 		nrxgp = NXGE_MAX_RDC_GRPS / nxgep->nports;
23623859Sml29623 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
23636929Smisaki 		    prop, nrxgp);
23643859Sml29623 		NXGE_DEBUG_MSG((nxgep, CFG_CTL,
23656929Smisaki 		    "==> nxge_use_default_dma_config: "
23666929Smisaki 		    "num_rdc_grpid not found: use def:# of "
23676929Smisaki 		    "rdc groups %d\n", nrxgp));
23683859Sml29623 	}
23693859Sml29623 	p_cfgp->max_rdc_grpids = nrxgp;
23703859Sml29623 
23713859Sml29623 	/*
23723859Sml29623 	 * 2/4 ports have the same hard-wired logical groups assigned.
23733859Sml29623 	 */
23743859Sml29623 	p_cfgp->start_ldg = nxgep->function_num * NXGE_LDGRP_PER_4PORTS;
23753859Sml29623 	p_cfgp->max_ldgs = NXGE_LDGRP_PER_4PORTS;
23763859Sml29623 
23773859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_default_dma_config: "
23788275SEric Cheng 	    "p_cfgp 0x%llx max_rdcs %d max_grpids %d default_grpid %d",
23798275SEric Cheng 	    p_cfgp, p_cfgp->max_rdcs, p_cfgp->max_grpids,
23808275SEric Cheng 	    p_cfgp->def_mac_rxdma_grpid));
23813859Sml29623 
23823859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_dma_config: "
23836929Smisaki 	    "p_cfgp 0x%016llx start_ldg %d nxgep->max_ldgs %d "
23846929Smisaki 	    "def_mac_rxdma_grpid %d",
23856929Smisaki 	    p_cfgp, p_cfgp->start_ldg, p_cfgp->max_ldgs,
23866929Smisaki 	    p_cfgp->def_mac_rxdma_grpid));
23873859Sml29623 
23889005SSantwona.Behera@Sun.COM 	nxgep->intr_timeout = NXGE_RDC_RCR_TIMEOUT;
23893859Sml29623 	prop = param_arr[param_rxdma_intr_time].fcode_name;
23903859Sml29623 
23913859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
23926929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
23933859Sml29623 		if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
23949005SSantwona.Behera@Sun.COM 			nxgep->intr_timeout = prop_val[0];
23953859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
23966929Smisaki 			    nxgep->dip, prop, prop_val, prop_len);
23973859Sml29623 		}
23983859Sml29623 		ddi_prop_free(prop_val);
23993859Sml29623 	}
24009005SSantwona.Behera@Sun.COM 
24019005SSantwona.Behera@Sun.COM 	nxgep->intr_threshold = NXGE_RDC_RCR_THRESHOLD;
24023859Sml29623 	prop = param_arr[param_rxdma_intr_pkts].fcode_name;
24033859Sml29623 
24043859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
24056929Smisaki 	    &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
24063859Sml29623 		if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
24079005SSantwona.Behera@Sun.COM 			nxgep->intr_threshold = prop_val[0];
24083859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
24096929Smisaki 			    nxgep->dip, prop, prop_val, prop_len);
24103859Sml29623 		}
24113859Sml29623 		ddi_prop_free(prop_val);
24123859Sml29623 	}
24133859Sml29623 	nxge_set_hw_dma_config(nxgep);
24143859Sml29623 
24154732Sdavemq 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_dma_config: "
24164732Sdavemq 	    "sTDC[%d] nTDC[%d] sRDC[%d] nRDC[%d]",
24176495Sspeer 	    p_cfgp->tdc.start, p_cfgp->tdc.count,
24184732Sdavemq 	    p_cfgp->start_rdc, p_cfgp->max_rdcs));
24194732Sdavemq 
24206495Sspeer nxge_use_cfg_dma_config_exit:
24213859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_dma_config"));
24223859Sml29623 }
24233859Sml29623 
24246495Sspeer void
nxge_get_logical_props(p_nxge_t nxgep)24256495Sspeer nxge_get_logical_props(p_nxge_t nxgep)
24266495Sspeer {
24276495Sspeer 	nxge_dma_pt_cfg_t *port = &nxgep->pt_config;
24286495Sspeer 	nxge_hw_pt_cfg_t *hardware;
24296495Sspeer 	nxge_rdc_grp_t *group;
24306495Sspeer 
24316495Sspeer 	(void) memset(port, 0, sizeof (*port));
24326495Sspeer 
24338275SEric Cheng 	port->mac_port = nxgep->function_num;	/* := function number */
24346495Sspeer 
24356495Sspeer 	/*
24366495Sspeer 	 * alloc_buf_size:
24376495Sspeer 	 * dead variables.
24386495Sspeer 	 */
24396495Sspeer 	port->rbr_size = nxge_rbr_size;
24406495Sspeer 	port->rcr_size = nxge_rcr_size;
24416495Sspeer 
24426495Sspeer 	port->tx_dma_map = 0;	/* Transmit DMA channel bit map */
24436495Sspeer 
24446495Sspeer 	nxge_set_rdc_intr_property(nxgep);
24456495Sspeer 
24466495Sspeer 	port->rcr_full_header = NXGE_RCR_FULL_HEADER;
24476495Sspeer 	port->rx_drr_weight = PT_DRR_WT_DEFAULT_10G;
24486495Sspeer 
24496495Sspeer 	/* ----------------------------------------------------- */
24506495Sspeer 	hardware = &port->hw_config;
24516495Sspeer 
24526495Sspeer 	(void) memset(hardware, 0, sizeof (*hardware));
24536495Sspeer 
24546495Sspeer 	/*
24556495Sspeer 	 * partition_id, read_write_mode:
24566495Sspeer 	 * dead variables.
24576495Sspeer 	 */
24586495Sspeer 
24596495Sspeer 	/*
24606495Sspeer 	 * drr_wt, rx_full_header, *_ldg?, start_mac_entry,
24616495Sspeer 	 * mac_pref, def_mac_rxdma_grpid, start_vlan, max_vlans,
24626495Sspeer 	 * start_ldgs, max_ldgs, max_ldvs,
24636495Sspeer 	 * vlan_pref, def_vlan_rxdma_grpid are meaningful only
24646495Sspeer 	 * in the service domain.
24656495Sspeer 	 */
24666495Sspeer 
24676495Sspeer 	group = &port->rdc_grps[0];
24686495Sspeer 
24698275SEric Cheng 	group->flag = B_TRUE;	/* configured */
24706495Sspeer 	group->config_method = RDC_TABLE_ENTRY_METHOD_REP;
24718275SEric Cheng 	group->port = NXGE_GET_PORT_NUM(nxgep->function_num);
24726495Sspeer 
24736495Sspeer 	/* HIO futures: this is still an open question. */
24746495Sspeer 	hardware->max_macs = 1;
24756495Sspeer }
24766495Sspeer 
24773859Sml29623 static void
nxge_use_cfg_vlan_class_config(p_nxge_t nxgep)24783859Sml29623 nxge_use_cfg_vlan_class_config(p_nxge_t nxgep)
24793859Sml29623 {
24803859Sml29623 	uint_t vlan_cnt;
24813859Sml29623 	int *vlan_cfg_val;
24823859Sml29623 	int status;
24833859Sml29623 	p_nxge_param_t param_arr;
24843859Sml29623 	char *prop;
24853859Sml29623 
24863859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_vlan_config"));
24873859Sml29623 	param_arr = nxgep->param_arr;
24883859Sml29623 	prop = param_arr[param_vlan_2rdc_grp].fcode_name;
24893859Sml29623 
24903859Sml29623 	status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
24916929Smisaki 	    &vlan_cfg_val, &vlan_cnt);
24923859Sml29623 	if (status == DDI_PROP_SUCCESS) {
24933859Sml29623 		status = ddi_prop_update_int_array(DDI_DEV_T_NONE,
24946929Smisaki 		    nxgep->dip, prop, vlan_cfg_val, vlan_cnt);
24953859Sml29623 		ddi_prop_free(vlan_cfg_val);
24963859Sml29623 	}
24973859Sml29623 	nxge_set_hw_vlan_class_config(nxgep);
24983859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_vlan_config"));
24993859Sml29623 }
25003859Sml29623 
25013859Sml29623 static void
nxge_use_cfg_mac_class_config(p_nxge_t nxgep)25023859Sml29623 nxge_use_cfg_mac_class_config(p_nxge_t nxgep)
25033859Sml29623 {
25043859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
25053859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
25063859Sml29623 	uint_t mac_cnt;
25073859Sml29623 	int *mac_cfg_val;
25083859Sml29623 	int status;
25093859Sml29623 	p_nxge_param_t param_arr;
25103859Sml29623 	char *prop;
25113859Sml29623 
25123859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_mac_class_config"));
25133859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
25143859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
25153859Sml29623 	p_cfgp->start_mac_entry = 0;
25163859Sml29623 	param_arr = nxgep->param_arr;
25173859Sml29623 	prop = param_arr[param_mac_2rdc_grp].fcode_name;
25183859Sml29623 
25193859Sml29623 	switch (nxgep->function_num) {
25203859Sml29623 	case 0:
25213859Sml29623 	case 1:
25223859Sml29623 		/* 10G ports */
25233859Sml29623 		p_cfgp->max_macs = NXGE_MAX_MACS_XMACS;
25243859Sml29623 		break;
25253859Sml29623 	case 2:
25263859Sml29623 	case 3:
25273859Sml29623 		/* 1G ports */
25283859Sml29623 	default:
25293859Sml29623 		p_cfgp->max_macs = NXGE_MAX_MACS_BMACS;
25303859Sml29623 		break;
25313859Sml29623 	}
25323859Sml29623 
25333859Sml29623 	p_cfgp->mac_pref = 1;
25343859Sml29623 	NXGE_DEBUG_MSG((nxgep, OBP_CTL,
25356929Smisaki 	    "== nxge_use_cfg_mac_class_config: "
25366929Smisaki 	    " mac_pref bit set def_mac_rxdma_grpid %d",
25376929Smisaki 	    p_cfgp->def_mac_rxdma_grpid));
25383859Sml29623 
25393859Sml29623 	status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
25406929Smisaki 	    &mac_cfg_val, &mac_cnt);
25413859Sml29623 	if (status == DDI_PROP_SUCCESS) {
25423859Sml29623 		if (mac_cnt <= p_cfgp->max_macs)
25433859Sml29623 			status = ddi_prop_update_int_array(DDI_DEV_T_NONE,
25446929Smisaki 			    nxgep->dip, prop, mac_cfg_val, mac_cnt);
25453859Sml29623 		ddi_prop_free(mac_cfg_val);
25463859Sml29623 	}
25473859Sml29623 	nxge_set_hw_mac_class_config(nxgep);
25483859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_mac_class_config"));
25493859Sml29623 }
25503859Sml29623 
25513859Sml29623 static void
nxge_use_cfg_class_config(p_nxge_t nxgep)25523859Sml29623 nxge_use_cfg_class_config(p_nxge_t nxgep)
25533859Sml29623 {
25543859Sml29623 	nxge_set_hw_class_config(nxgep);
25553859Sml29623 }
25563859Sml29623 
25573859Sml29623 static void
nxge_set_rdc_intr_property(p_nxge_t nxgep)25583859Sml29623 nxge_set_rdc_intr_property(p_nxge_t nxgep)
25593859Sml29623 {
25603859Sml29623 	int i;
25613859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
25623859Sml29623 
25633859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_rdc_intr_property"));
25643859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
25653859Sml29623 
25663859Sml29623 	for (i = 0; i < NXGE_MAX_RDCS; i++) {
25679005SSantwona.Behera@Sun.COM 		p_dma_cfgp->rcr_timeout[i] = nxgep->intr_timeout;
25689005SSantwona.Behera@Sun.COM 		p_dma_cfgp->rcr_threshold[i] = nxgep->intr_threshold;
25693859Sml29623 	}
25703859Sml29623 
25713859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_rdc_intr_property"));
25723859Sml29623 }
25733859Sml29623 
25743859Sml29623 static void
nxge_set_hw_dma_config(p_nxge_t nxgep)25753859Sml29623 nxge_set_hw_dma_config(p_nxge_t nxgep)
25763859Sml29623 {
25778275SEric Cheng 	int			i, j, ngrps, bitmap, end, st_rdc;
25788275SEric Cheng 	p_nxge_dma_pt_cfg_t	p_dma_cfgp;
25798275SEric Cheng 	p_nxge_hw_pt_cfg_t	p_cfgp;
25808275SEric Cheng 	p_nxge_rdc_grp_t	rdc_grp_p;
25818275SEric Cheng 	p_nxge_tdc_grp_t	tdc_grp_p;
25828275SEric Cheng 	nxge_grp_t		*group;
25838275SEric Cheng 	uint8_t			nrdcs;
25848275SEric Cheng 	dc_map_t		map = 0;
25853859Sml29623 
25863859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_set_hw_dma_config"));
25873859Sml29623 
25883859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
25893859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
25908275SEric Cheng 
25918275SEric Cheng 	switch (nxgep->niu_type) {
25928275SEric Cheng 	case NEPTUNE_4_1GC:
25938275SEric Cheng 	case NEPTUNE_2_10GF_2_1GC:
25948275SEric Cheng 	case NEPTUNE_1_10GF_3_1GC:
25958275SEric Cheng 	case NEPTUNE_1_1GC_1_10GF_2_1GC:
25968275SEric Cheng 	case NEPTUNE_2_10GF_2_1GRF:
25978275SEric Cheng 	default:
25988275SEric Cheng 		ngrps = 2;
25998275SEric Cheng 		break;
26008275SEric Cheng 	case NEPTUNE_2_10GF:
26018275SEric Cheng 	case NEPTUNE_2_1GRF:
26028275SEric Cheng 	case N2_NIU:
26038275SEric Cheng 		ngrps = 4;
26048275SEric Cheng 		break;
26058275SEric Cheng 	}
26068275SEric Cheng 
26078275SEric Cheng 	/*
26088275SEric Cheng 	 * Setup TDC groups
26098275SEric Cheng 	 */
26103859Sml29623 	bitmap = 0;
26116495Sspeer 	end = p_cfgp->tdc.start + p_cfgp->tdc.owned;
26126495Sspeer 	for (i = p_cfgp->tdc.start; i < end; i++) {
26133859Sml29623 		bitmap |= (1 << i);
26143859Sml29623 	}
26153859Sml29623 
26166495Sspeer 	nxgep->tx_set.owned.map |= bitmap; /* Owned, & not shared. */
26178275SEric Cheng 	nxgep->tx_set.owned.count = p_cfgp->tdc.owned;
26183859Sml29623 	p_dma_cfgp->tx_dma_map = bitmap;
26198275SEric Cheng 
26208275SEric Cheng 	for (i = 0; i < ngrps; i++) {
26218275SEric Cheng 		group = (nxge_grp_t *)nxge_grp_add(nxgep,
26228275SEric Cheng 		    NXGE_TRANSMIT_GROUP);
26238275SEric Cheng 		tdc_grp_p = &p_dma_cfgp->tdc_grps[
26248275SEric Cheng 		    p_cfgp->def_mac_txdma_grpid + i];
26258275SEric Cheng 		if (i == 0)
26268275SEric Cheng 			tdc_grp_p->map = bitmap;
26278275SEric Cheng 		else
26288275SEric Cheng 			tdc_grp_p->map = 0;
26298275SEric Cheng 		/* no ring is associated with a group initially */
26308275SEric Cheng 		tdc_grp_p->start_tdc = 0;
26318275SEric Cheng 		tdc_grp_p->max_tdcs = 0;
26328275SEric Cheng 		tdc_grp_p->grp_index = group->index;
26338275SEric Cheng 	}
26348275SEric Cheng 
26358275SEric Cheng 	/*
26368275SEric Cheng 	 * Setup RDC groups
26378275SEric Cheng 	 */
26388275SEric Cheng 	st_rdc = p_cfgp->start_rdc;
26398275SEric Cheng 	for (i = 0; i < ngrps; i++) {
26408275SEric Cheng 		/*
26418275SEric Cheng 		 * All rings are associated with the default group initially
26428275SEric Cheng 		 */
26438275SEric Cheng 		if (i == 0) {
26448275SEric Cheng 			/* default group */
26458275SEric Cheng 			switch (nxgep->niu_type) {
26468275SEric Cheng 			case NEPTUNE_4_1GC:
26478275SEric Cheng 				nrdcs = rx_4_1G[nxgep->function_num];
26483859Sml29623 				break;
26498275SEric Cheng 			case N2_NIU:
26508275SEric Cheng 			case NEPTUNE_2_10GF:
26518275SEric Cheng 				nrdcs = rx_2_10G[nxgep->function_num];
26528275SEric Cheng 				break;
26538275SEric Cheng 			case NEPTUNE_2_10GF_2_1GC:
26548275SEric Cheng 				nrdcs = rx_2_10G_2_1G[nxgep->function_num];
26558275SEric Cheng 				break;
26568275SEric Cheng 			case NEPTUNE_1_10GF_3_1GC:
26578275SEric Cheng 				nrdcs = rx_1_10G_3_1G[nxgep->function_num];
26588275SEric Cheng 				break;
26598275SEric Cheng 			case NEPTUNE_1_1GC_1_10GF_2_1GC:
26608275SEric Cheng 				nrdcs = rx_1_1G_1_10G_2_1G[nxgep->function_num];
26613859Sml29623 				break;
26623859Sml29623 			default:
26638275SEric Cheng 				switch (nxgep->platform_type) {
26648275SEric Cheng 				case P_NEPTUNE_ALONSO:
26658275SEric Cheng 					nrdcs =
26668275SEric Cheng 					    rx_2_10G_2_1G[nxgep->function_num];
26678275SEric Cheng 					break;
26688275SEric Cheng 				default:
26698275SEric Cheng 					nrdcs = rx_4_1G[nxgep->function_num];
26708275SEric Cheng 					break;
26718275SEric Cheng 				}
26723859Sml29623 				break;
26733859Sml29623 			}
26748948SMichael.Speer@Sun.COM 
26758948SMichael.Speer@Sun.COM 			if (p_cfgp->max_rdcs < nrdcs)
26768948SMichael.Speer@Sun.COM 				nrdcs = p_cfgp->max_rdcs;
26778275SEric Cheng 		} else {
26788275SEric Cheng 			nrdcs = 0;
26793859Sml29623 		}
26806495Sspeer 
26816495Sspeer 		rdc_grp_p = &p_dma_cfgp->rdc_grps[
26826929Smisaki 		    p_cfgp->def_mac_rxdma_grpid + i];
26838275SEric Cheng 		rdc_grp_p->start_rdc = st_rdc;
26848275SEric Cheng 		rdc_grp_p->max_rdcs = nrdcs;
26856495Sspeer 		rdc_grp_p->def_rdc = rdc_grp_p->start_rdc;
26863859Sml29623 
26873859Sml29623 		/* default to: 0, 1, 2, 3, ...., 0, 1, 2, 3.... */
26888275SEric Cheng 		if (nrdcs != 0) {
26898275SEric Cheng 			for (j = 0; j < nrdcs; j++) {
26908275SEric Cheng 				map |= (1 << j);
26918275SEric Cheng 			}
26928275SEric Cheng 			map <<= rdc_grp_p->start_rdc;
26938275SEric Cheng 		} else
26948275SEric Cheng 			map = 0;
26956495Sspeer 		rdc_grp_p->map = map;
26966495Sspeer 
26976495Sspeer 		nxgep->rx_set.owned.map |= map; /* Owned, & not shared. */
26988275SEric Cheng 		nxgep->rx_set.owned.count = nrdcs;
26996495Sspeer 
27006495Sspeer 		group = (nxge_grp_t *)nxge_grp_add(nxgep, NXGE_RECEIVE_GROUP);
27016495Sspeer 
27023859Sml29623 		rdc_grp_p->config_method = RDC_TABLE_ENTRY_METHOD_SEQ;
27038275SEric Cheng 		rdc_grp_p->flag = B_TRUE; /* This group has been configured. */
27048275SEric Cheng 		rdc_grp_p->grp_index = group->index;
27058275SEric Cheng 		rdc_grp_p->port = NXGE_GET_PORT_NUM(nxgep->function_num);
27068275SEric Cheng 
27078275SEric Cheng 		map = 0;
27083859Sml29623 	}
27093859Sml29623 
27106495Sspeer 
27113859Sml29623 	/* default RDC */
27123859Sml29623 	p_cfgp->def_rdc = p_cfgp->start_rdc;
27133859Sml29623 	nxgep->def_rdc = p_cfgp->start_rdc;
27143859Sml29623 
27153859Sml29623 	/* full 18 byte header ? */
27163859Sml29623 	p_dma_cfgp->rcr_full_header = NXGE_RCR_FULL_HEADER;
27173859Sml29623 	p_dma_cfgp->rx_drr_weight = PT_DRR_WT_DEFAULT_10G;
27183859Sml29623 	if (nxgep->function_num > 1)
27193859Sml29623 		p_dma_cfgp->rx_drr_weight = PT_DRR_WT_DEFAULT_1G;
27203859Sml29623 	p_dma_cfgp->rbr_size = nxge_rbr_size;
27213859Sml29623 	p_dma_cfgp->rcr_size = nxge_rcr_size;
27223859Sml29623 
27233859Sml29623 	nxge_set_rdc_intr_property(nxgep);
27243859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_hw_dma_config"));
27253859Sml29623 }
27263859Sml29623 
27273859Sml29623 boolean_t
nxge_check_rxdma_port_member(p_nxge_t nxgep,uint8_t rdc)27283859Sml29623 nxge_check_rxdma_port_member(p_nxge_t nxgep, uint8_t rdc)
27293859Sml29623 {
27303859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
27313859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
27323859Sml29623 	int status = B_TRUE;
27333859Sml29623 
27343859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_rxdma_port_member"));
27353859Sml29623 
27363859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
27373859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
27383859Sml29623 
27393859Sml29623 	/* Receive DMA Channels */
27403859Sml29623 	if (rdc < p_cfgp->max_rdcs)
27413859Sml29623 		status = B_TRUE;
27423859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_rxdma_port_member"));
27433859Sml29623 	return (status);
27443859Sml29623 }
27453859Sml29623 
27463859Sml29623 boolean_t
nxge_check_txdma_port_member(p_nxge_t nxgep,uint8_t tdc)27473859Sml29623 nxge_check_txdma_port_member(p_nxge_t nxgep, uint8_t tdc)
27483859Sml29623 {
27493859Sml29623 	int status = B_FALSE;
27503859Sml29623 
27516495Sspeer 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_txdma_port_member"));
27526495Sspeer 
27536495Sspeer 	if (tdc >= nxgep->pt_config.hw_config.tdc.start &&
27546495Sspeer 	    tdc < nxgep->pt_config.hw_config.tdc.count)
27553859Sml29623 		status = B_TRUE;
27566495Sspeer 
27576495Sspeer 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_txdma_port_member"));
27583859Sml29623 	return (status);
27593859Sml29623 }
27603859Sml29623 
27613859Sml29623 boolean_t
nxge_check_rxdma_rdcgrp_member(p_nxge_t nxgep,uint8_t rdc_grp,uint8_t rdc)27623859Sml29623 nxge_check_rxdma_rdcgrp_member(p_nxge_t nxgep, uint8_t rdc_grp, uint8_t rdc)
27633859Sml29623 {
27643859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
27653859Sml29623 	int status = B_TRUE;
27663859Sml29623 	p_nxge_rdc_grp_t rdc_grp_p;
27673859Sml29623 
27683859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
27696929Smisaki 	    " ==> nxge_check_rxdma_rdcgrp_member"));
27703859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "  nxge_check_rxdma_rdcgrp_member"
27716929Smisaki 	    " rdc  %d group %d", rdc, rdc_grp));
27723859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
27733859Sml29623 
27743859Sml29623 	rdc_grp_p = &p_dma_cfgp->rdc_grps[rdc_grp];
27753859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "  max  %d ", rdc_grp_p->max_rdcs));
27763859Sml29623 	if (rdc >= rdc_grp_p->max_rdcs) {
27773859Sml29623 		status = B_FALSE;
27783859Sml29623 	}
27793859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
27806929Smisaki 	    " <== nxge_check_rxdma_rdcgrp_member"));
27813859Sml29623 	return (status);
27823859Sml29623 }
27833859Sml29623 
27843859Sml29623 boolean_t
nxge_check_rdcgrp_port_member(p_nxge_t nxgep,uint8_t rdc_grp)27853859Sml29623 nxge_check_rdcgrp_port_member(p_nxge_t nxgep, uint8_t rdc_grp)
27863859Sml29623 {
27873859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
27883859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
27893859Sml29623 	int status = B_TRUE;
27903859Sml29623 
27913859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_rdcgrp_port_member"));
27923859Sml29623 
27933859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
27943859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
27953859Sml29623 
27963859Sml29623 	if (rdc_grp >= p_cfgp->max_rdc_grpids)
27973859Sml29623 		status = B_FALSE;
27983859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_rdcgrp_port_member"));
27993859Sml29623 	return (status);
28003859Sml29623 }
28013859Sml29623 
28023859Sml29623 static void
nxge_set_hw_vlan_class_config(p_nxge_t nxgep)28033859Sml29623 nxge_set_hw_vlan_class_config(p_nxge_t nxgep)
28043859Sml29623 {
28053859Sml29623 	int i;
28063859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
28073859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
28083859Sml29623 	p_nxge_param_t param_arr;
28093859Sml29623 	uint_t vlan_cnt;
28103859Sml29623 	int *vlan_cfg_val;
28113859Sml29623 	nxge_param_map_t *vmap;
28123859Sml29623 	char *prop;
28133859Sml29623 	p_nxge_class_pt_cfg_t p_class_cfgp;
28143859Sml29623 	uint32_t good_cfg[32];
28153859Sml29623 	int good_count = 0;
28163859Sml29623 	nxge_mv_cfg_t *vlan_tbl;
28173859Sml29623 
28183859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_hw_vlan_config"));
28193859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
28203859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
28213859Sml29623 	p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
28223859Sml29623 
28233859Sml29623 	param_arr = nxgep->param_arr;
28243859Sml29623 	prop = param_arr[param_vlan_2rdc_grp].fcode_name;
28253859Sml29623 
28263859Sml29623 	/*
28273859Sml29623 	 * By default, VLAN to RDC group mapping is disabled Need to read HW or
28283859Sml29623 	 * .conf properties to find out if mapping is required
28293859Sml29623 	 *
28303859Sml29623 	 * Format
28313859Sml29623 	 *
28323859Sml29623 	 * uint32_t array, each array entry specifying the VLAN id and the
28333859Sml29623 	 * mapping
28343859Sml29623 	 *
28353859Sml29623 	 * bit[30] = add bit[29] = remove bit[28]  = preference bits[23-16] =
28363859Sml29623 	 * rdcgrp bits[15-0] = VLAN ID ( )
28373859Sml29623 	 */
28383859Sml29623 
28393859Sml29623 	for (i = 0; i < NXGE_MAX_VLANS; i++) {
28403859Sml29623 		p_class_cfgp->vlan_tbl[i].flag = 0;
28413859Sml29623 	}
28423859Sml29623 
28433859Sml29623 	vlan_tbl = (nxge_mv_cfg_t *)&p_class_cfgp->vlan_tbl[0];
28443859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
28456929Smisaki 	    &vlan_cfg_val, &vlan_cnt) == DDI_PROP_SUCCESS) {
28463859Sml29623 		for (i = 0; i < vlan_cnt; i++) {
28473859Sml29623 			vmap = (nxge_param_map_t *)&vlan_cfg_val[i];
28483859Sml29623 			if ((vmap->param_id) &&
28496929Smisaki 			    (vmap->param_id < NXGE_MAX_VLANS) &&
28506929Smisaki 			    (vmap->map_to <
28516929Smisaki 			    p_cfgp->max_rdc_grpids) &&
28526929Smisaki 			    (vmap->map_to >= (uint8_t)0)) {
28533859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
28546929Smisaki 				    " nxge_vlan_config mapping"
28556929Smisaki 				    " id %d grp %d",
28566929Smisaki 				    vmap->param_id, vmap->map_to));
28573859Sml29623 				good_cfg[good_count] = vlan_cfg_val[i];
28583859Sml29623 				if (vlan_tbl[vmap->param_id].flag == 0)
28593859Sml29623 					good_count++;
28603859Sml29623 				vlan_tbl[vmap->param_id].flag = 1;
28613859Sml29623 				vlan_tbl[vmap->param_id].rdctbl =
28626495Sspeer 				    vmap->map_to + p_cfgp->def_mac_rxdma_grpid;
28633859Sml29623 				vlan_tbl[vmap->param_id].mpr_npr = vmap->pref;
28643859Sml29623 			}
28653859Sml29623 		}
28663859Sml29623 		ddi_prop_free(vlan_cfg_val);
28673859Sml29623 		if (good_count != vlan_cnt) {
28683859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
28696929Smisaki 			    nxgep->dip, prop, (int *)good_cfg, good_count);
28703859Sml29623 		}
28713859Sml29623 	}
28723859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_set_hw_vlan_config"));
28733859Sml29623 }
28743859Sml29623 
28753859Sml29623 static void
nxge_set_hw_mac_class_config(p_nxge_t nxgep)28763859Sml29623 nxge_set_hw_mac_class_config(p_nxge_t nxgep)
28773859Sml29623 {
28783859Sml29623 	int i;
28793859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
28803859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
28813859Sml29623 	p_nxge_param_t param_arr;
28823859Sml29623 	uint_t mac_cnt;
28833859Sml29623 	int *mac_cfg_val;
28843859Sml29623 	nxge_param_map_t *mac_map;
28853859Sml29623 	char *prop;
28863859Sml29623 	p_nxge_class_pt_cfg_t p_class_cfgp;
28873859Sml29623 	int good_count = 0;
28883859Sml29623 	int good_cfg[NXGE_MAX_MACS];
28893859Sml29623 	nxge_mv_cfg_t *mac_host_info;
28903859Sml29623 
28913859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_set_hw_mac_config"));
28923859Sml29623 
28933859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
28943859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
28953859Sml29623 	p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
28963859Sml29623 	mac_host_info = (nxge_mv_cfg_t *)&p_class_cfgp->mac_host_info[0];
28973859Sml29623 
28983859Sml29623 	param_arr = nxgep->param_arr;
28993859Sml29623 	prop = param_arr[param_mac_2rdc_grp].fcode_name;
29003859Sml29623 
29013859Sml29623 	for (i = 0; i < NXGE_MAX_MACS; i++) {
29023859Sml29623 		p_class_cfgp->mac_host_info[i].flag = 0;
29034484Sspeer 		p_class_cfgp->mac_host_info[i].rdctbl =
29044484Sspeer 		    p_cfgp->def_mac_rxdma_grpid;
29053859Sml29623 	}
29063859Sml29623 
29073859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
29086929Smisaki 	    &mac_cfg_val, &mac_cnt) == DDI_PROP_SUCCESS) {
29093859Sml29623 		for (i = 0; i < mac_cnt; i++) {
29103859Sml29623 			mac_map = (nxge_param_map_t *)&mac_cfg_val[i];
29113859Sml29623 			if ((mac_map->param_id < p_cfgp->max_macs) &&
29126929Smisaki 			    (mac_map->map_to <
29136929Smisaki 			    p_cfgp->max_rdc_grpids) &&
29146929Smisaki 			    (mac_map->map_to >= (uint8_t)0)) {
29153859Sml29623 				NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
29166929Smisaki 				    " nxge_mac_config mapping"
29176929Smisaki 				    " id %d grp %d",
29186929Smisaki 				    mac_map->param_id, mac_map->map_to));
29193859Sml29623 				mac_host_info[mac_map->param_id].mpr_npr =
29208275SEric Cheng 				    p_cfgp->mac_pref;
29213859Sml29623 				mac_host_info[mac_map->param_id].rdctbl =
29226929Smisaki 				    mac_map->map_to +
29236929Smisaki 				    p_cfgp->def_mac_rxdma_grpid;
29243859Sml29623 				good_cfg[good_count] = mac_cfg_val[i];
29253859Sml29623 				if (mac_host_info[mac_map->param_id].flag == 0)
29263859Sml29623 					good_count++;
29273859Sml29623 				mac_host_info[mac_map->param_id].flag = 1;
29283859Sml29623 			}
29293859Sml29623 		}
29303859Sml29623 		ddi_prop_free(mac_cfg_val);
29313859Sml29623 		if (good_count != mac_cnt) {
29323859Sml29623 			(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
29336929Smisaki 			    nxgep->dip, prop, good_cfg, good_count);
29343859Sml29623 		}
29353859Sml29623 	}
29363859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_set_hw_mac_config"));
29373859Sml29623 }
29383859Sml29623 
29393859Sml29623 static void
nxge_set_hw_class_config(p_nxge_t nxgep)29403859Sml29623 nxge_set_hw_class_config(p_nxge_t nxgep)
29413859Sml29623 {
29423859Sml29623 	int i;
29433859Sml29623 	p_nxge_param_t param_arr;
29443859Sml29623 	int *int_prop_val;
29453859Sml29623 	uint32_t cfg_value;
29463859Sml29623 	char *prop;
29473859Sml29623 	p_nxge_class_pt_cfg_t p_class_cfgp;
29483859Sml29623 	int start_prop, end_prop;
29493859Sml29623 	uint_t prop_cnt;
29509005SSantwona.Behera@Sun.COM 	int start_class, j = 0;
29513859Sml29623 
29523859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_hw_class_config"));
29533859Sml29623 
29543859Sml29623 	p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
29553859Sml29623 	param_arr = nxgep->param_arr;
29569005SSantwona.Behera@Sun.COM 	start_prop = param_class_opt_ipv4_tcp;
29573859Sml29623 	end_prop = param_class_opt_ipv6_sctp;
29589005SSantwona.Behera@Sun.COM 	start_class = TCAM_CLASS_TCP_IPV4;
29599005SSantwona.Behera@Sun.COM 
29609005SSantwona.Behera@Sun.COM 	for (i = start_prop, j = 0; i <= end_prop; i++, j++) {
29613859Sml29623 		prop = param_arr[i].fcode_name;
29623859Sml29623 		if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip,
29636929Smisaki 		    0, prop, &int_prop_val,
29646929Smisaki 		    &prop_cnt) == DDI_PROP_SUCCESS) {
29653859Sml29623 			cfg_value = (uint32_t)*int_prop_val;
29663859Sml29623 			ddi_prop_free(int_prop_val);
29673859Sml29623 		} else {
29683859Sml29623 			cfg_value = (uint32_t)param_arr[i].value;
29693859Sml29623 		}
29709005SSantwona.Behera@Sun.COM 		p_class_cfgp->class_cfg[start_class + j] = cfg_value;
29713859Sml29623 	}
29723859Sml29623 
29733859Sml29623 	prop = param_arr[param_h1_init_value].fcode_name;
29743859Sml29623 
29753859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
29766929Smisaki 	    &int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
29773859Sml29623 		cfg_value = (uint32_t)*int_prop_val;
29783859Sml29623 		ddi_prop_free(int_prop_val);
29793859Sml29623 	} else {
29803859Sml29623 		cfg_value = (uint32_t)param_arr[param_h1_init_value].value;
29813859Sml29623 	}
29823859Sml29623 
29833859Sml29623 	p_class_cfgp->init_h1 = (uint32_t)cfg_value;
29843859Sml29623 	prop = param_arr[param_h2_init_value].fcode_name;
29853859Sml29623 
29863859Sml29623 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
29876929Smisaki 	    &int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
29883859Sml29623 		cfg_value = (uint32_t)*int_prop_val;
29893859Sml29623 		ddi_prop_free(int_prop_val);
29903859Sml29623 	} else {
29913859Sml29623 		cfg_value = (uint32_t)param_arr[param_h2_init_value].value;
29923859Sml29623 	}
29933859Sml29623 
29943859Sml29623 	p_class_cfgp->init_h2 = (uint16_t)cfg_value;
29953859Sml29623 	NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_hw_class_config"));
29963859Sml29623 }
29973859Sml29623 
29983859Sml29623 nxge_status_t
nxge_ldgv_init_n2(p_nxge_t nxgep,int * navail_p,int * nrequired_p)29993859Sml29623 nxge_ldgv_init_n2(p_nxge_t nxgep, int *navail_p, int *nrequired_p)
30003859Sml29623 {
30016495Sspeer 	int i, maxldvs, maxldgs, nldvs;
30023859Sml29623 	int ldv, endldg;
30033859Sml29623 	uint8_t func;
30043859Sml29623 	uint8_t channel;
30053859Sml29623 	uint8_t chn_start;
30063859Sml29623 	boolean_t own_sys_err = B_FALSE, own_fzc = B_FALSE;
30073859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
30083859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
30093859Sml29623 	p_nxge_ldgv_t ldgvp;
30103859Sml29623 	p_nxge_ldg_t ldgp, ptr;
30117466SMisaki.Kataoka@Sun.COM 	p_nxge_ldv_t ldvp, sysldvp;
30123859Sml29623 	nxge_status_t status = NXGE_OK;
30136495Sspeer 	nxge_grp_set_t *set;
30143859Sml29623 
30153859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2"));
30163859Sml29623 	if (!*navail_p) {
30173859Sml29623 		*nrequired_p = 0;
30183859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
30196929Smisaki 		    "<== nxge_ldgv_init:no avail"));
30203859Sml29623 		return (NXGE_ERROR);
30213859Sml29623 	}
30223859Sml29623 	/*
30233859Sml29623 	 * N2/NIU: one logical device owns one logical group. and each
30243859Sml29623 	 * device/group will be assigned one vector by Hypervisor.
30253859Sml29623 	 */
30263859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
30273859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
30283859Sml29623 	maxldgs = p_cfgp->max_ldgs;
30293859Sml29623 	if (!maxldgs) {
30303859Sml29623 		/* No devices configured. */
30313859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_init_n2: "
30326929Smisaki 		    "no logical groups configured."));
30333859Sml29623 		return (NXGE_ERROR);
30343859Sml29623 	} else {
30353859Sml29623 		maxldvs = maxldgs + 1;
30363859Sml29623 	}
30373859Sml29623 
30383859Sml29623 	/*
30393859Sml29623 	 * If function zero instance, it needs to handle the system and MIF
30403859Sml29623 	 * error interrupts. MIF interrupt may not be needed for N2/NIU.
30413859Sml29623 	 */
30423859Sml29623 	func = nxgep->function_num;
30433859Sml29623 	if (func == 0) {
30443859Sml29623 		own_sys_err = B_TRUE;
30453859Sml29623 		if (!p_cfgp->ser_ldvid) {
30463859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
30476929Smisaki 			    "nxge_ldgv_init_n2: func 0, ERR ID not set!"));
30483859Sml29623 		}
30493859Sml29623 		/* MIF interrupt */
30503859Sml29623 		if (!p_cfgp->mif_ldvid) {
30513859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
30526929Smisaki 			    "nxge_ldgv_init_n2: func 0, MIF ID not set!"));
30533859Sml29623 		}
30543859Sml29623 	}
30553859Sml29623 
30563859Sml29623 	/*
30573859Sml29623 	 * Assume single partition, each function owns mac.
30583859Sml29623 	 */
30593859Sml29623 	if (!nxge_use_partition)
30603859Sml29623 		own_fzc = B_TRUE;
30613859Sml29623 
30623859Sml29623 	ldgvp = nxgep->ldgvp;
30633859Sml29623 	if (ldgvp == NULL) {
30643859Sml29623 		ldgvp = KMEM_ZALLOC(sizeof (nxge_ldgv_t), KM_SLEEP);
30653859Sml29623 		nxgep->ldgvp = ldgvp;
30663859Sml29623 		ldgvp->maxldgs = (uint8_t)maxldgs;
30673859Sml29623 		ldgvp->maxldvs = (uint8_t)maxldvs;
30686495Sspeer 		ldgp = ldgvp->ldgp = KMEM_ZALLOC(
30696929Smisaki 		    sizeof (nxge_ldg_t) * maxldgs, KM_SLEEP);
30706495Sspeer 		ldvp = ldgvp->ldvp = KMEM_ZALLOC(
30716929Smisaki 		    sizeof (nxge_ldv_t) * maxldvs, KM_SLEEP);
30723859Sml29623 	} else {
30733859Sml29623 		ldgp = ldgvp->ldgp;
30743859Sml29623 		ldvp = ldgvp->ldvp;
30753859Sml29623 	}
30763859Sml29623 
30776495Sspeer 	ldgvp->ndma_ldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
30783859Sml29623 	ldgvp->tmres = NXGE_TIMER_RESO;
30793859Sml29623 
30803859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
30816929Smisaki 	    "==> nxge_ldgv_init_n2: maxldvs %d maxldgs %d",
30826929Smisaki 	    maxldvs, maxldgs));
30833859Sml29623 
30843859Sml29623 	/* logical start_ldg is ldv */
30853859Sml29623 	ptr = ldgp;
30863859Sml29623 	for (i = 0; i < maxldgs; i++) {
30873859Sml29623 		ptr->func = func;
30883859Sml29623 		ptr->arm = B_TRUE;
30893859Sml29623 		ptr->vldg_index = (uint8_t)i;
30903859Sml29623 		ptr->ldg_timer = NXGE_TIMER_LDG;
30913859Sml29623 		ptr->ldg = p_cfgp->ldg[i];
30923859Sml29623 		ptr->sys_intr_handler = nxge_intr;
30933859Sml29623 		ptr->nldvs = 0;
30943859Sml29623 		ptr->ldvp = NULL;
30953859Sml29623 		ptr->nxgep = nxgep;
30963859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
30976929Smisaki 		    "==> nxge_ldgv_init_n2: maxldvs %d maxldgs %d "
30986929Smisaki 		    "ldg %d ldgptr $%p",
30996929Smisaki 		    maxldvs, maxldgs, ptr->ldg, ptr));
31003859Sml29623 		ptr++;
31013859Sml29623 	}
31023859Sml29623 
31033859Sml29623 	endldg = NXGE_INT_MAX_LDG;
31043859Sml29623 	nldvs = 0;
31053859Sml29623 	ldgvp->nldvs = 0;
31063859Sml29623 	ldgp->ldvp = NULL;
31073859Sml29623 	*nrequired_p = 0;
31083859Sml29623 
31093859Sml29623 	/*
31103859Sml29623 	 * logical device group table is organized in the following order (same
31113859Sml29623 	 * as what interrupt property has). function 0: owns MAC, MIF, error,
31123859Sml29623 	 * rx, tx. function 1: owns MAC, rx, tx.
31133859Sml29623 	 */
31143859Sml29623 
31153859Sml29623 	if (own_fzc && p_cfgp->mac_ldvid) {
31163859Sml29623 		/* Each function should own MAC interrupt */
31173859Sml29623 		ldv = p_cfgp->mac_ldvid;
31183859Sml29623 		ldvp->ldv = (uint8_t)ldv;
31193859Sml29623 		ldvp->is_mac = B_TRUE;
31203859Sml29623 		ldvp->ldv_intr_handler = nxge_mac_intr;
31213859Sml29623 		ldvp->ldv_ldf_masks = 0;
31223859Sml29623 		ldvp->nxgep = nxgep;
31233859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
31246929Smisaki 		    "==> nxge_ldgv_init_n2(mac): maxldvs %d ldv %d "
31256929Smisaki 		    "ldg %d ldgptr $%p ldvptr $%p",
31266929Smisaki 		    maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
31273859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
31283859Sml29623 		nldvs++;
31293859Sml29623 	}
31303859Sml29623 
31313859Sml29623 	if (own_fzc && p_cfgp->mif_ldvid) {
31323859Sml29623 		ldv = p_cfgp->mif_ldvid;
31333859Sml29623 		ldvp->ldv = (uint8_t)ldv;
31343859Sml29623 		ldvp->is_mif = B_TRUE;
31353859Sml29623 		ldvp->ldv_intr_handler = nxge_mif_intr;
31363859Sml29623 		ldvp->ldv_ldf_masks = 0;
31373859Sml29623 		ldvp->nxgep = nxgep;
31383859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
31396929Smisaki 		    "==> nxge_ldgv_init_n2(mif): maxldvs %d ldv %d "
31406929Smisaki 		    "ldg %d ldgptr $%p ldvptr $%p",
31416929Smisaki 		    maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
31423859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
31433859Sml29623 		nldvs++;
31443859Sml29623 	}
31453859Sml29623 
31467466SMisaki.Kataoka@Sun.COM 	/*
31478275SEric Cheng 	 * HW based syserr interrupt for port0, and SW based syserr interrupt
31488275SEric Cheng 	 * for port1
31497466SMisaki.Kataoka@Sun.COM 	 */
31503859Sml29623 	if (own_sys_err && p_cfgp->ser_ldvid) {
31513859Sml29623 		ldv = p_cfgp->ser_ldvid;
31523859Sml29623 		/*
31533859Sml29623 		 * Unmask the system interrupt states.
31543859Sml29623 		 */
31553859Sml29623 		(void) nxge_fzc_sys_err_mask_set(nxgep, SYS_ERR_SMX_MASK |
31566929Smisaki 		    SYS_ERR_IPP_MASK | SYS_ERR_TXC_MASK |
31576929Smisaki 		    SYS_ERR_ZCP_MASK);
31587466SMisaki.Kataoka@Sun.COM 
31597466SMisaki.Kataoka@Sun.COM 		ldvp->use_timer = B_TRUE;
31607466SMisaki.Kataoka@Sun.COM 		ldvp->ldv = (uint8_t)ldv;
31617466SMisaki.Kataoka@Sun.COM 		ldvp->is_syserr = B_TRUE;
31627466SMisaki.Kataoka@Sun.COM 		ldvp->ldv_intr_handler = nxge_syserr_intr;
31637466SMisaki.Kataoka@Sun.COM 		ldvp->ldv_ldf_masks = 0;
31647466SMisaki.Kataoka@Sun.COM 		ldvp->nxgep = nxgep;
31657466SMisaki.Kataoka@Sun.COM 		ldgvp->ldvp_syserr = ldvp;
31667466SMisaki.Kataoka@Sun.COM 
31677466SMisaki.Kataoka@Sun.COM 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
31687466SMisaki.Kataoka@Sun.COM 		    "==> nxge_ldgv_init_n2(syserr): maxldvs %d ldv %d "
31697466SMisaki.Kataoka@Sun.COM 		    "ldg %d ldgptr $%p ldvptr p%p",
31707466SMisaki.Kataoka@Sun.COM 		    maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
31717466SMisaki.Kataoka@Sun.COM 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
31727466SMisaki.Kataoka@Sun.COM 		nldvs++;
31737466SMisaki.Kataoka@Sun.COM 	} else {
31747466SMisaki.Kataoka@Sun.COM 		/*
31758275SEric Cheng 		 * SW based: allocate the ldv for the syserr since the vector
31768275SEric Cheng 		 * should not be consumed for port1
31777466SMisaki.Kataoka@Sun.COM 		 */
31787466SMisaki.Kataoka@Sun.COM 		sysldvp = KMEM_ZALLOC(sizeof (nxge_ldv_t), KM_SLEEP);
31797466SMisaki.Kataoka@Sun.COM 		sysldvp->use_timer = B_TRUE;
31807466SMisaki.Kataoka@Sun.COM 		sysldvp->ldv = NXGE_SYS_ERROR_LD;
31817466SMisaki.Kataoka@Sun.COM 		sysldvp->is_syserr = B_TRUE;
31827466SMisaki.Kataoka@Sun.COM 		sysldvp->ldv_intr_handler = nxge_syserr_intr;
31837466SMisaki.Kataoka@Sun.COM 		sysldvp->ldv_ldf_masks = 0;
31847466SMisaki.Kataoka@Sun.COM 		sysldvp->nxgep = nxgep;
31857466SMisaki.Kataoka@Sun.COM 		ldgvp->ldvp_syserr = sysldvp;
31868275SEric Cheng 		ldgvp->ldvp_syserr_alloced = B_TRUE;
31873859Sml29623 	}
31883859Sml29623 
31898275SEric Cheng 
31903859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
31916929Smisaki 	    "(before rx) func %d nldvs %d navail %d nrequired %d",
31926929Smisaki 	    func, nldvs, *navail_p, *nrequired_p));
31933859Sml29623 
31943859Sml29623 	/*
31953859Sml29623 	 * Start with RDC to configure logical devices for each group.
31963859Sml29623 	 */
31976495Sspeer 	chn_start = p_cfgp->ldg_chn_start;
31986495Sspeer 	set = &nxgep->rx_set;
31996495Sspeer 	for (channel = 0; channel < NXGE_MAX_RDCS; channel++) {
32006495Sspeer 		if ((1 << channel) & set->owned.map) {
32016495Sspeer 			ldvp->is_rxdma = B_TRUE;
32026495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_RDMA_LD_START;
32036495Sspeer 			ldvp->channel = channel;
32046495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
32056495Sspeer 			ldvp->ldv_intr_handler = nxge_rx_intr;
32066495Sspeer 			ldvp->ldv_ldf_masks = 0;
32076495Sspeer 			ldvp->nxgep = nxgep;
32086495Sspeer 			ldgp->ldg = p_cfgp->ldg[chn_start];
32096495Sspeer 
32106495Sspeer 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
32116495Sspeer 			    "==> nxge_ldgv_init_n2(rx%d): maxldvs %d ldv %d "
32126495Sspeer 			    "ldg %d ldgptr 0x%016llx ldvptr 0x%016llx",
32136495Sspeer 			    i, maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
32146495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
32156495Sspeer 			    endldg, nrequired_p);
32166495Sspeer 			nldvs++;
32176495Sspeer 			chn_start++;
32186495Sspeer 		}
32193859Sml29623 	}
32203859Sml29623 
32213859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
32226929Smisaki 	    "func %d nldvs %d navail %d nrequired %d",
32236929Smisaki 	    func, nldvs, *navail_p, *nrequired_p));
32243859Sml29623 
32253859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
32266929Smisaki 	    "func %d nldvs %d navail %d nrequired %d ldgp 0x%llx "
32276929Smisaki 	    "ldvp 0x%llx",
32286929Smisaki 	    func, nldvs, *navail_p, *nrequired_p, ldgp, ldvp));
32293859Sml29623 	/*
32303859Sml29623 	 * Transmit DMA channels.
32313859Sml29623 	 */
32326495Sspeer 	chn_start = p_cfgp->ldg_chn_start + 8;
32336495Sspeer 	set = &nxgep->tx_set;
32346495Sspeer 	for (channel = 0; channel < NXGE_MAX_TDCS; channel++) {
32356495Sspeer 		if ((1 << channel) & set->owned.map) {
32366495Sspeer 			ldvp->is_txdma = B_TRUE;
32376495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_TDMA_LD_START;
32386495Sspeer 			ldvp->channel = channel;
32396495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
32406495Sspeer 			ldvp->ldv_intr_handler = nxge_tx_intr;
32416495Sspeer 			ldvp->ldv_ldf_masks = 0;
32426495Sspeer 			ldgp->ldg = p_cfgp->ldg[chn_start];
32436495Sspeer 			ldvp->nxgep = nxgep;
32446495Sspeer 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
32456495Sspeer 			    "==> nxge_ldgv_init_n2(tx%d): maxldvs %d ldv %d "
32466495Sspeer 			    "ldg %d ldgptr %p ldvptr %p",
32476495Sspeer 			    channel, maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
32486495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
32496495Sspeer 			    endldg, nrequired_p);
32506495Sspeer 			nldvs++;
32516495Sspeer 			chn_start++;
32526495Sspeer 		}
32533859Sml29623 	}
32543859Sml29623 
32553859Sml29623 	ldgvp->ldg_intrs = *nrequired_p;
32563859Sml29623 	ldgvp->nldvs = (uint8_t)nldvs;
32573859Sml29623 
32583859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
32596929Smisaki 	    "func %d nldvs %d maxgrps %d navail %d nrequired %d",
32606929Smisaki 	    func, nldvs, maxldgs, *navail_p, *nrequired_p));
32613859Sml29623 
32623859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_init_n2"));
32633859Sml29623 	return (status);
32643859Sml29623 }
32653859Sml29623 
32663859Sml29623 /*
32673859Sml29623  * Interrupts related interface functions.
32683859Sml29623  */
32693859Sml29623 
32703859Sml29623 nxge_status_t
nxge_ldgv_init(p_nxge_t nxgep,int * navail_p,int * nrequired_p)32713859Sml29623 nxge_ldgv_init(p_nxge_t nxgep, int *navail_p, int *nrequired_p)
32723859Sml29623 {
32736495Sspeer 	int i, maxldvs, maxldgs, nldvs;
32743859Sml29623 	int ldv, ldg, endldg, ngrps;
32753859Sml29623 	uint8_t func;
32763859Sml29623 	uint8_t channel;
32773859Sml29623 	boolean_t own_sys_err = B_FALSE, own_fzc = B_FALSE;
32783859Sml29623 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
32793859Sml29623 	p_nxge_hw_pt_cfg_t p_cfgp;
32803859Sml29623 	p_nxge_ldgv_t ldgvp;
32813859Sml29623 	p_nxge_ldg_t ldgp, ptr;
32823859Sml29623 	p_nxge_ldv_t ldvp;
32836495Sspeer 	nxge_grp_set_t *set;
32846495Sspeer 
32853859Sml29623 	nxge_status_t status = NXGE_OK;
32863859Sml29623 
32873859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init"));
32883859Sml29623 	if (!*navail_p) {
32893859Sml29623 		*nrequired_p = 0;
32903859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
32916929Smisaki 		    "<== nxge_ldgv_init:no avail"));
32923859Sml29623 		return (NXGE_ERROR);
32933859Sml29623 	}
32943859Sml29623 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
32953859Sml29623 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
32963859Sml29623 
32976495Sspeer 	nldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
32983859Sml29623 
32993859Sml29623 	/*
33003859Sml29623 	 * If function zero instance, it needs to handle the system error
33013859Sml29623 	 * interrupts.
33023859Sml29623 	 */
33033859Sml29623 	func = nxgep->function_num;
33043859Sml29623 	if (func == 0) {
33053859Sml29623 		nldvs++;
33063859Sml29623 		own_sys_err = B_TRUE;
33073859Sml29623 	} else {
33083859Sml29623 		/* use timer */
33093859Sml29623 		nldvs++;
33103859Sml29623 	}
33113859Sml29623 
33123859Sml29623 	/*
33133859Sml29623 	 * Assume single partition, each function owns mac.
33143859Sml29623 	 */
33153859Sml29623 	if (!nxge_use_partition) {
33163859Sml29623 		/* mac */
33173859Sml29623 		nldvs++;
33183859Sml29623 		/* MIF */
33193859Sml29623 		nldvs++;
33203859Sml29623 		own_fzc = B_TRUE;
33213859Sml29623 	}
33223859Sml29623 	maxldvs = nldvs;
33233859Sml29623 	maxldgs = p_cfgp->max_ldgs;
33243859Sml29623 	if (!maxldvs || !maxldgs) {
33253859Sml29623 		/* No devices configured. */
33263859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_init: "
33276929Smisaki 		    "no logical devices or groups configured."));
33283859Sml29623 		return (NXGE_ERROR);
33293859Sml29623 	}
33303859Sml29623 	ldgvp = nxgep->ldgvp;
33313859Sml29623 	if (ldgvp == NULL) {
33323859Sml29623 		ldgvp = KMEM_ZALLOC(sizeof (nxge_ldgv_t), KM_SLEEP);
33333859Sml29623 		nxgep->ldgvp = ldgvp;
33343859Sml29623 		ldgvp->maxldgs = (uint8_t)maxldgs;
33353859Sml29623 		ldgvp->maxldvs = (uint8_t)maxldvs;
33363859Sml29623 		ldgp = ldgvp->ldgp = KMEM_ZALLOC(sizeof (nxge_ldg_t) * maxldgs,
33376929Smisaki 		    KM_SLEEP);
33383859Sml29623 		ldvp = ldgvp->ldvp = KMEM_ZALLOC(sizeof (nxge_ldv_t) * maxldvs,
33396929Smisaki 		    KM_SLEEP);
33403859Sml29623 	}
33416495Sspeer 	ldgvp->ndma_ldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
33423859Sml29623 	ldgvp->tmres = NXGE_TIMER_RESO;
33433859Sml29623 
33443859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
33456929Smisaki 	    "==> nxge_ldgv_init: maxldvs %d maxldgs %d nldvs %d",
33466929Smisaki 	    maxldvs, maxldgs, nldvs));
33473859Sml29623 	ldg = p_cfgp->start_ldg;
33483859Sml29623 	ptr = ldgp;
33493859Sml29623 	for (i = 0; i < maxldgs; i++) {
33503859Sml29623 		ptr->func = func;
33513859Sml29623 		ptr->arm = B_TRUE;
33523859Sml29623 		ptr->vldg_index = (uint8_t)i;
33533859Sml29623 		ptr->ldg_timer = NXGE_TIMER_LDG;
33543859Sml29623 		ptr->ldg = ldg++;
33553859Sml29623 		ptr->sys_intr_handler = nxge_intr;
33563859Sml29623 		ptr->nldvs = 0;
33573859Sml29623 		ptr->nxgep = nxgep;
33583859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
33596929Smisaki 		    "==> nxge_ldgv_init: maxldvs %d maxldgs %d ldg %d",
33606929Smisaki 		    maxldvs, maxldgs, ptr->ldg));
33613859Sml29623 		ptr++;
33623859Sml29623 	}
33633859Sml29623 
33643859Sml29623 	ldg = p_cfgp->start_ldg;
33653859Sml29623 	if (maxldgs > *navail_p) {
33663859Sml29623 		ngrps = *navail_p;
33673859Sml29623 	} else {
33683859Sml29623 		ngrps = maxldgs;
33693859Sml29623 	}
33703859Sml29623 	endldg = ldg + ngrps;
33713859Sml29623 
33723859Sml29623 	/*
33733859Sml29623 	 * Receive DMA channels.
33743859Sml29623 	 */
33753859Sml29623 	nldvs = 0;
33763859Sml29623 	ldgvp->nldvs = 0;
33773859Sml29623 	ldgp->ldvp = NULL;
33783859Sml29623 	*nrequired_p = 0;
33793859Sml29623 
33803859Sml29623 	/*
33813859Sml29623 	 * Start with RDC to configure logical devices for each group.
33823859Sml29623 	 */
33836495Sspeer 	set = &nxgep->rx_set;
33846495Sspeer 	for (channel = 0; channel < NXGE_MAX_RDCS; channel++) {
33856495Sspeer 		if ((1 << channel) & set->owned.map) {
33866495Sspeer 			/* For now, <channel & <vdma_index> are the same. */
33876495Sspeer 			ldvp->is_rxdma = B_TRUE;
33886495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_RDMA_LD_START;
33896495Sspeer 			ldvp->channel = channel;
33906495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
33916495Sspeer 			ldvp->ldv_intr_handler = nxge_rx_intr;
33926495Sspeer 			ldvp->ldv_ldf_masks = 0;
33936495Sspeer 			ldvp->use_timer = B_FALSE;
33946495Sspeer 			ldvp->nxgep = nxgep;
33956495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
33966495Sspeer 			    endldg, nrequired_p);
33976495Sspeer 			nldvs++;
33986495Sspeer 		}
33993859Sml29623 	}
34003859Sml29623 
34013859Sml29623 	/*
34023859Sml29623 	 * Transmit DMA channels.
34033859Sml29623 	 */
34046495Sspeer 	set = &nxgep->tx_set;
34056495Sspeer 	for (channel = 0; channel < NXGE_MAX_TDCS; channel++) {
34066495Sspeer 		if ((1 << channel) & set->owned.map) {
34076495Sspeer 			/* For now, <channel & <vdma_index> are the same. */
34086495Sspeer 			ldvp->is_txdma = B_TRUE;
34096495Sspeer 			ldvp->ldv = (uint8_t)channel + NXGE_TDMA_LD_START;
34106495Sspeer 			ldvp->channel = channel;
34116495Sspeer 			ldvp->vdma_index = (uint8_t)channel;
34126495Sspeer 			ldvp->ldv_intr_handler = nxge_tx_intr;
34136495Sspeer 			ldvp->ldv_ldf_masks = 0;
34146495Sspeer 			ldvp->use_timer = B_FALSE;
34156495Sspeer 			ldvp->nxgep = nxgep;
34166495Sspeer 			nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
34176495Sspeer 			    endldg, nrequired_p);
34186495Sspeer 			nldvs++;
34196495Sspeer 		}
34203859Sml29623 	}
34213859Sml29623 
34223859Sml29623 	if (own_fzc) {
34233859Sml29623 		ldv = NXGE_MIF_LD;
34243859Sml29623 		ldvp->ldv = (uint8_t)ldv;
34253859Sml29623 		ldvp->is_mif = B_TRUE;
34263859Sml29623 		ldvp->ldv_intr_handler = nxge_mif_intr;
34273859Sml29623 		ldvp->ldv_ldf_masks = 0;
34283859Sml29623 		ldvp->use_timer = B_FALSE;
34293859Sml29623 		ldvp->nxgep = nxgep;
34303859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
34313859Sml29623 		nldvs++;
34323859Sml29623 	}
34333859Sml29623 	/*
34343859Sml29623 	 * MAC port (function zero control)
34353859Sml29623 	 */
34363859Sml29623 	if (own_fzc) {
34373859Sml29623 		ldvp->is_mac = B_TRUE;
34383859Sml29623 		ldvp->ldv_intr_handler = nxge_mac_intr;
34393859Sml29623 		ldvp->ldv_ldf_masks = 0;
34403859Sml29623 		ldv = func + NXGE_MAC_LD_START;
34413859Sml29623 		ldvp->ldv = (uint8_t)ldv;
34423859Sml29623 		ldvp->use_timer = B_FALSE;
34433859Sml29623 		ldvp->nxgep = nxgep;
34443859Sml29623 		nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
34453859Sml29623 		nldvs++;
34463859Sml29623 	}
34473859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init: "
34486929Smisaki 	    "func %d nldvs %d navail %d nrequired %d",
34496929Smisaki 	    func, nldvs, *navail_p, *nrequired_p));
34503859Sml29623 	/*
34513859Sml29623 	 * Function 0 owns system error interrupts.
34523859Sml29623 	 */
34533859Sml29623 	ldvp->use_timer = B_TRUE;
34543859Sml29623 	if (own_sys_err) {
34553859Sml29623 		ldv = NXGE_SYS_ERROR_LD;
34563859Sml29623 		ldvp->ldv = (uint8_t)ldv;
34573859Sml29623 		ldvp->is_syserr = B_TRUE;
34583859Sml29623 		ldvp->ldv_intr_handler = nxge_syserr_intr;
34593859Sml29623 		ldvp->ldv_ldf_masks = 0;
34603859Sml29623 		ldvp->nxgep = nxgep;
34613859Sml29623 		ldgvp->ldvp_syserr = ldvp;
34623859Sml29623 		/*
34633859Sml29623 		 * Unmask the system interrupt states.
34643859Sml29623 		 */
34653859Sml29623 		(void) nxge_fzc_sys_err_mask_set(nxgep, SYS_ERR_SMX_MASK |
34666929Smisaki 		    SYS_ERR_IPP_MASK | SYS_ERR_TXC_MASK |
34676929Smisaki 		    SYS_ERR_ZCP_MASK);
34683859Sml29623 
34693859Sml29623 		(void) nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
34703859Sml29623 		nldvs++;
34713859Sml29623 	} else {
34723859Sml29623 		ldv = NXGE_SYS_ERROR_LD;
34733859Sml29623 		ldvp->ldv = (uint8_t)ldv;
34743859Sml29623 		ldvp->is_syserr = B_TRUE;
34753859Sml29623 		ldvp->ldv_intr_handler = nxge_syserr_intr;
34763859Sml29623 		ldvp->nxgep = nxgep;
34773859Sml29623 		ldvp->ldv_ldf_masks = 0;
34783859Sml29623 		ldgvp->ldvp_syserr = ldvp;
34793859Sml29623 	}
34803859Sml29623 
34813859Sml29623 	ldgvp->ldg_intrs = *nrequired_p;
34823859Sml29623 
34833859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init: "
34846929Smisaki 	    "func %d nldvs %d navail %d nrequired %d",
34856929Smisaki 	    func, nldvs, *navail_p, *nrequired_p));
34863859Sml29623 
34873859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_init"));
34883859Sml29623 	return (status);
34893859Sml29623 }
34903859Sml29623 
34913859Sml29623 nxge_status_t
nxge_ldgv_uninit(p_nxge_t nxgep)34923859Sml29623 nxge_ldgv_uninit(p_nxge_t nxgep)
34933859Sml29623 {
34943859Sml29623 	p_nxge_ldgv_t ldgvp;
34953859Sml29623 
34963859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_uninit"));
34973859Sml29623 	ldgvp = nxgep->ldgvp;
34983859Sml29623 	if (ldgvp == NULL) {
34993859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_uninit: "
35006929Smisaki 		    "no logical group configured."));
35013859Sml29623 		return (NXGE_OK);
35023859Sml29623 	}
35038275SEric Cheng 	if (ldgvp->ldvp_syserr_alloced == B_TRUE) {
35047466SMisaki.Kataoka@Sun.COM 		KMEM_FREE(ldgvp->ldvp_syserr, sizeof (nxge_ldv_t));
35057466SMisaki.Kataoka@Sun.COM 	}
35063859Sml29623 	if (ldgvp->ldgp) {
35073859Sml29623 		KMEM_FREE(ldgvp->ldgp, sizeof (nxge_ldg_t) * ldgvp->maxldgs);
35083859Sml29623 	}
35093859Sml29623 	if (ldgvp->ldvp) {
35103859Sml29623 		KMEM_FREE(ldgvp->ldvp, sizeof (nxge_ldv_t) * ldgvp->maxldvs);
35113859Sml29623 	}
35123859Sml29623 	KMEM_FREE(ldgvp, sizeof (nxge_ldgv_t));
35133859Sml29623 	nxgep->ldgvp = NULL;
35143859Sml29623 
35153859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_uninit"));
35163859Sml29623 	return (NXGE_OK);
35173859Sml29623 }
35183859Sml29623 
35193859Sml29623 nxge_status_t
nxge_intr_ldgv_init(p_nxge_t nxgep)35203859Sml29623 nxge_intr_ldgv_init(p_nxge_t nxgep)
35213859Sml29623 {
35223859Sml29623 	nxge_status_t status = NXGE_OK;
35233859Sml29623 
35243859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_ldgv_init"));
35253859Sml29623 	/*
35263859Sml29623 	 * Configure the logical device group numbers, state vectors and
35273859Sml29623 	 * interrupt masks for each logical device.
35283859Sml29623 	 */
35293859Sml29623 	status = nxge_fzc_intr_init(nxgep);
35303859Sml29623 
35313859Sml29623 	/*
35323859Sml29623 	 * Configure logical device masks and timers.
35333859Sml29623 	 */
35343859Sml29623 	status = nxge_intr_mask_mgmt(nxgep);
35353859Sml29623 
35363859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_ldgv_init"));
35373859Sml29623 	return (status);
35383859Sml29623 }
35393859Sml29623 
35403859Sml29623 nxge_status_t
nxge_intr_mask_mgmt(p_nxge_t nxgep)35413859Sml29623 nxge_intr_mask_mgmt(p_nxge_t nxgep)
35423859Sml29623 {
35433859Sml29623 	p_nxge_ldgv_t ldgvp;
35443859Sml29623 	p_nxge_ldg_t ldgp;
35453859Sml29623 	p_nxge_ldv_t ldvp;
35463859Sml29623 	npi_handle_t handle;
35473859Sml29623 	int i, j;
35483859Sml29623 	npi_status_t rs = NPI_SUCCESS;
35493859Sml29623 
35503859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_mask_mgmt"));
35513859Sml29623 
35523859Sml29623 	if ((ldgvp = nxgep->ldgvp) == NULL) {
35533859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
35546929Smisaki 		    "<== nxge_intr_mask_mgmt: Null ldgvp"));
35553859Sml29623 		return (NXGE_ERROR);
35563859Sml29623 	}
35573859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
35583859Sml29623 	ldgp = ldgvp->ldgp;
35593859Sml29623 	ldvp = ldgvp->ldvp;
35603859Sml29623 	if (ldgp == NULL || ldvp == NULL) {
35613859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
35626929Smisaki 		    "<== nxge_intr_mask_mgmt: Null ldgp or ldvp"));
35633859Sml29623 		return (NXGE_ERROR);
35643859Sml29623 	}
35653859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
35666929Smisaki 	    "==> nxge_intr_mask_mgmt: # of intrs %d ", ldgvp->ldg_intrs));
35673859Sml29623 	/* Initialize masks. */
35683859Sml29623 	if (nxgep->niu_type != N2_NIU) {
35693859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
35706929Smisaki 		    "==> nxge_intr_mask_mgmt(Neptune): # intrs %d ",
35716929Smisaki 		    ldgvp->ldg_intrs));
35723859Sml29623 		for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
35733859Sml29623 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
35746929Smisaki 			    "==> nxge_intr_mask_mgmt(Neptune): # ldv %d "
35756929Smisaki 			    "in group %d", ldgp->nldvs, ldgp->ldg));
35763859Sml29623 			for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
35773859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
35786929Smisaki 				    "==> nxge_intr_mask_mgmt: set ldv # %d "
35796929Smisaki 				    "for ldg %d", ldvp->ldv, ldgp->ldg));
35803859Sml29623 				rs = npi_intr_mask_set(handle, ldvp->ldv,
35816929Smisaki 				    ldvp->ldv_ldf_masks);
35823859Sml29623 				if (rs != NPI_SUCCESS) {
35833859Sml29623 					NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
35846929Smisaki 					    "<== nxge_intr_mask_mgmt: "
35856929Smisaki 					    "set mask failed "
35866929Smisaki 					    " rs 0x%x ldv %d mask 0x%x",
35876929Smisaki 					    rs, ldvp->ldv,
35886929Smisaki 					    ldvp->ldv_ldf_masks));
35893859Sml29623 					return (NXGE_ERROR | rs);
35903859Sml29623 				}
35913859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
35926929Smisaki 				    "==> nxge_intr_mask_mgmt: "
35936929Smisaki 				    "set mask OK "
35946929Smisaki 				    " rs 0x%x ldv %d mask 0x%x",
35956929Smisaki 				    rs, ldvp->ldv,
35966929Smisaki 				    ldvp->ldv_ldf_masks));
35973859Sml29623 			}
35983859Sml29623 		}
35993859Sml29623 	}
36003859Sml29623 	ldgp = ldgvp->ldgp;
36013859Sml29623 	/* Configure timer and arm bit */
36023859Sml29623 	for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
36033859Sml29623 		rs = npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
36046929Smisaki 		    ldgp->arm, ldgp->ldg_timer);
36053859Sml29623 		if (rs != NPI_SUCCESS) {
36063859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
36076929Smisaki 			    "<== nxge_intr_mask_mgmt: "
36086929Smisaki 			    "set timer failed "
36096929Smisaki 			    " rs 0x%x dg %d timer 0x%x",
36106929Smisaki 			    rs, ldgp->ldg, ldgp->ldg_timer));
36113859Sml29623 			return (NXGE_ERROR | rs);
36123859Sml29623 		}
36133859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
36146929Smisaki 		    "==> nxge_intr_mask_mgmt: "
36156929Smisaki 		    "set timer OK "
36166929Smisaki 		    " rs 0x%x ldg %d timer 0x%x",
36176929Smisaki 		    rs, ldgp->ldg, ldgp->ldg_timer));
36183859Sml29623 	}
36193859Sml29623 
36203859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_fzc_intr_mask_mgmt"));
36213859Sml29623 	return (NXGE_OK);
36223859Sml29623 }
36233859Sml29623 
36243859Sml29623 nxge_status_t
nxge_intr_mask_mgmt_set(p_nxge_t nxgep,boolean_t on)36253859Sml29623 nxge_intr_mask_mgmt_set(p_nxge_t nxgep, boolean_t on)
36263859Sml29623 {
36273859Sml29623 	p_nxge_ldgv_t ldgvp;
36283859Sml29623 	p_nxge_ldg_t ldgp;
36293859Sml29623 	p_nxge_ldv_t ldvp;
36303859Sml29623 	npi_handle_t handle;
36313859Sml29623 	int i, j;
36323859Sml29623 	npi_status_t rs = NPI_SUCCESS;
36333859Sml29623 
36343859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
36356929Smisaki 	    "==> nxge_intr_mask_mgmt_set (%d)", on));
36363859Sml29623 
36373859Sml29623 	if (nxgep->niu_type == N2_NIU) {
36383859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
36396929Smisaki 		    "<== nxge_intr_mask_mgmt_set (%d) not set (N2/NIU)",
36406929Smisaki 		    on));
36413859Sml29623 		return (NXGE_ERROR);
36423859Sml29623 	}
36433859Sml29623 
36443859Sml29623 	if ((ldgvp = nxgep->ldgvp) == NULL) {
36453859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
36466929Smisaki 		    "==> nxge_intr_mask_mgmt_set: Null ldgvp"));
36473859Sml29623 		return (NXGE_ERROR);
36483859Sml29623 	}
36493859Sml29623 
36503859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
36513859Sml29623 	ldgp = ldgvp->ldgp;
36523859Sml29623 	ldvp = ldgvp->ldvp;
36533859Sml29623 	if (ldgp == NULL || ldvp == NULL) {
36543859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
36556929Smisaki 		    "<== nxge_intr_mask_mgmt_set: Null ldgp or ldvp"));
36563859Sml29623 		return (NXGE_ERROR);
36573859Sml29623 	}
36583859Sml29623 	/* set masks. */
36593859Sml29623 	for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
36603859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
36616929Smisaki 		    "==> nxge_intr_mask_mgmt_set: flag %d ldg %d"
36626929Smisaki 		    "set mask nldvs %d", on, ldgp->ldg, ldgp->nldvs));
36633859Sml29623 		for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
36643859Sml29623 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
36656929Smisaki 			    "==> nxge_intr_mask_mgmt_set: "
36666929Smisaki 			    "for %d %d flag %d", i, j, on));
36673859Sml29623 			if (on) {
36683859Sml29623 				ldvp->ldv_ldf_masks = 0;
36693859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
36706929Smisaki 				    "==> nxge_intr_mask_mgmt_set: "
36716929Smisaki 				    "ON mask off"));
36723859Sml29623 			} else if (!on) {
36733859Sml29623 				ldvp->ldv_ldf_masks = (uint8_t)LD_IM1_MASK;
36743859Sml29623 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
36756929Smisaki 				    "==> nxge_intr_mask_mgmt_set:mask on"));
36763859Sml29623 			}
36773859Sml29623 			rs = npi_intr_mask_set(handle, ldvp->ldv,
36786929Smisaki 			    ldvp->ldv_ldf_masks);
36793859Sml29623 			if (rs != NPI_SUCCESS) {
36803859Sml29623 				NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
36816929Smisaki 				    "==> nxge_intr_mask_mgmt_set: "
36826929Smisaki 				    "set mask failed "
36836929Smisaki 				    " rs 0x%x ldv %d mask 0x%x",
36846929Smisaki 				    rs, ldvp->ldv, ldvp->ldv_ldf_masks));
36853859Sml29623 				return (NXGE_ERROR | rs);
36863859Sml29623 			}
36873859Sml29623 			NXGE_DEBUG_MSG((nxgep, INT_CTL,
36886929Smisaki 			    "==> nxge_intr_mask_mgmt_set: flag %d"
36896929Smisaki 			    "set mask OK "
36906929Smisaki 			    " ldv %d mask 0x%x",
36916929Smisaki 			    on, ldvp->ldv, ldvp->ldv_ldf_masks));
36923859Sml29623 		}
36933859Sml29623 	}
36943859Sml29623 
36953859Sml29623 	ldgp = ldgvp->ldgp;
36963859Sml29623 	/* set the arm bit */
36973859Sml29623 	for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
36983859Sml29623 		if (on && !ldgp->arm) {
36993859Sml29623 			ldgp->arm = B_TRUE;
37003859Sml29623 		} else if (!on && ldgp->arm) {
37013859Sml29623 			ldgp->arm = B_FALSE;
37023859Sml29623 		}
37033859Sml29623 		rs = npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
37046929Smisaki 		    ldgp->arm, ldgp->ldg_timer);
37053859Sml29623 		if (rs != NPI_SUCCESS) {
37063859Sml29623 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
37076929Smisaki 			    "<== nxge_intr_mask_mgmt_set: "
37086929Smisaki 			    "set timer failed "
37096929Smisaki 			    " rs 0x%x ldg %d timer 0x%x",
37106929Smisaki 			    rs, ldgp->ldg, ldgp->ldg_timer));
37113859Sml29623 			return (NXGE_ERROR | rs);
37123859Sml29623 		}
37133859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
37146929Smisaki 		    "==> nxge_intr_mask_mgmt_set: OK (flag %d) "
37156929Smisaki 		    "set timer "
37166929Smisaki 		    " ldg %d timer 0x%x",
37176929Smisaki 		    on, ldgp->ldg, ldgp->ldg_timer));
37183859Sml29623 	}
37193859Sml29623 
37203859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_mask_mgmt_set"));
37213859Sml29623 	return (NXGE_OK);
37223859Sml29623 }
37233859Sml29623 
37243859Sml29623 static nxge_status_t
nxge_get_mac_addr_properties(p_nxge_t nxgep)37253859Sml29623 nxge_get_mac_addr_properties(p_nxge_t nxgep)
37263859Sml29623 {
37274732Sdavemq #if defined(_BIG_ENDIAN)
37283859Sml29623 	uchar_t *prop_val;
37293859Sml29623 	uint_t prop_len;
37304732Sdavemq 	uint_t j;
37314732Sdavemq #endif
37323859Sml29623 	uint_t i;
37333859Sml29623 	uint8_t func_num;
37344732Sdavemq 	boolean_t compute_macs = B_TRUE;
37353859Sml29623 
37363859Sml29623 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_get_mac_addr_properties "));
37373859Sml29623 
37383859Sml29623 #if defined(_BIG_ENDIAN)
37393859Sml29623 	/*
37403859Sml29623 	 * Get the ethernet address.
37413859Sml29623 	 */
37423859Sml29623 	(void) localetheraddr((struct ether_addr *)NULL, &nxgep->ouraddr);
37433859Sml29623 
37443859Sml29623 	/*
37453859Sml29623 	 * Check if it is an adapter with its own local mac address If it is
37463859Sml29623 	 * present, override the system mac address.
37473859Sml29623 	 */
37483859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
37496929Smisaki 	    "local-mac-address", &prop_val,
37506929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
37513859Sml29623 		if (prop_len == ETHERADDRL) {
37523859Sml29623 			nxgep->factaddr = *(p_ether_addr_t)prop_val;
37533859Sml29623 			NXGE_DEBUG_MSG((nxgep, DDI_CTL, "Local mac address = "
37546929Smisaki 			    "%02x:%02x:%02x:%02x:%02x:%02x",
37556929Smisaki 			    prop_val[0], prop_val[1], prop_val[2],
37566929Smisaki 			    prop_val[3], prop_val[4], prop_val[5]));
37573859Sml29623 		}
37583859Sml29623 		ddi_prop_free(prop_val);
37593859Sml29623 	}
37603859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
37616929Smisaki 	    "local-mac-address?", &prop_val,
37626929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
37633859Sml29623 		if (strncmp("true", (caddr_t)prop_val, (size_t)prop_len) == 0) {
37643859Sml29623 			nxgep->ouraddr = nxgep->factaddr;
37653859Sml29623 			NXGE_DEBUG_MSG((nxgep, DDI_CTL,
37666929Smisaki 			    "Using local MAC address"));
37673859Sml29623 		}
37683859Sml29623 		ddi_prop_free(prop_val);
37693859Sml29623 	} else {
37703859Sml29623 		nxgep->ouraddr = nxgep->factaddr;
37713859Sml29623 	}
37724185Sspeer 
37734977Sraghus 	if ((!nxgep->vpd_info.present) ||
37744732Sdavemq 	    (nxge_is_valid_local_mac(nxgep->factaddr)))
37754185Sspeer 		goto got_mac_addr;
37764185Sspeer 
37774185Sspeer 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "nxge_get_mac_addr_properties: "
37784185Sspeer 	    "MAC address from properties is not valid...reading from PROM"));
37794185Sspeer 
37804185Sspeer #endif
37814185Sspeer 	if (!nxgep->vpd_info.ver_valid) {
37824185Sspeer 		(void) nxge_espc_mac_addrs_get(nxgep);
37834185Sspeer 		if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
37844977Sraghus 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Failed to get "
37854977Sraghus 			    "MAC address"));
37864185Sspeer 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "EEPROM version "
37874185Sspeer 			    "[%s] invalid...please update",
37884185Sspeer 			    nxgep->vpd_info.ver));
37894185Sspeer 			return (NXGE_ERROR);
37904185Sspeer 		}
37914185Sspeer 		nxgep->ouraddr = nxgep->factaddr;
37924185Sspeer 		goto got_mac_addr;
37934185Sspeer 	}
37944185Sspeer 	/*
37954185Sspeer 	 * First get the MAC address from the info in the VPD data read
37964185Sspeer 	 * from the EEPROM.
37974185Sspeer 	 */
37984185Sspeer 	nxge_espc_get_next_mac_addr(nxgep->vpd_info.mac_addr,
37994732Sdavemq 	    nxgep->function_num, &nxgep->factaddr);
38004185Sspeer 
38014185Sspeer 	if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
38024185Sspeer 		NXGE_DEBUG_MSG((nxgep, DDI_CTL,
38034185Sspeer 		    "nxge_get_mac_addr_properties: "
38044185Sspeer 		    "MAC address in EEPROM VPD data not valid"
38054185Sspeer 		    "...reading from NCR registers"));
38064185Sspeer 		(void) nxge_espc_mac_addrs_get(nxgep);
38074185Sspeer 		if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
38084977Sraghus 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Failed to get "
38094977Sraghus 			    "MAC address"));
38104185Sspeer 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "EEPROM version "
38114185Sspeer 			    "[%s] invalid...please update",
38124185Sspeer 			    nxgep->vpd_info.ver));
38134185Sspeer 			return (NXGE_ERROR);
38144185Sspeer 		}
38154185Sspeer 	}
38164185Sspeer 
38173859Sml29623 	nxgep->ouraddr = nxgep->factaddr;
38184185Sspeer 
38194185Sspeer got_mac_addr:
38203859Sml29623 	func_num = nxgep->function_num;
38213859Sml29623 
38223859Sml29623 	/*
38234732Sdavemq 	 * Note: mac-addresses property is the list of mac addresses for a
38244732Sdavemq 	 * port. NXGE_MAX_MMAC_ADDRS is the total number of MAC addresses
38254732Sdavemq 	 * allocated for a board.
38263859Sml29623 	 */
38274732Sdavemq 	nxgep->nxge_mmac_info.total_factory_macs = NXGE_MAX_MMAC_ADDRS;
38284732Sdavemq 
38294732Sdavemq #if defined(_BIG_ENDIAN)
38304732Sdavemq 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
38314732Sdavemq 	    "mac-addresses", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
38323859Sml29623 		/*
38334732Sdavemq 		 * XAUI may have up to 18 MACs, more than the XMAC can
38344732Sdavemq 		 * use (1 unique MAC plus 16 alternate MACs)
38353859Sml29623 		 */
38364732Sdavemq 		nxgep->nxge_mmac_info.num_factory_mmac =
38374732Sdavemq 		    prop_len / ETHERADDRL - 1;
38384732Sdavemq 		if (nxgep->nxge_mmac_info.num_factory_mmac >
38394732Sdavemq 		    XMAC_MAX_ALT_ADDR_ENTRY) {
38404185Sspeer 			nxgep->nxge_mmac_info.num_factory_mmac =
38414732Sdavemq 			    XMAC_MAX_ALT_ADDR_ENTRY;
38424732Sdavemq 		}
38434732Sdavemq 
38444732Sdavemq 		for (i = 1; i <= nxgep->nxge_mmac_info.num_factory_mmac; i++) {
38454732Sdavemq 			for (j = 0; j < ETHERADDRL; j++) {
38464732Sdavemq 				nxgep->nxge_mmac_info.factory_mac_pool[i][j] =
38474732Sdavemq 				    *(prop_val + (i * ETHERADDRL) + j);
38484732Sdavemq 			}
38494732Sdavemq 			NXGE_DEBUG_MSG((nxgep, DDI_CTL,
38504732Sdavemq 			    "nxge_get_mac_addr_properties: Alt mac[%d] from "
38514732Sdavemq 			    "mac-addresses property[%2x:%2x:%2x:%2x:%2x:%2x]",
38524732Sdavemq 			    i, nxgep->nxge_mmac_info.factory_mac_pool[i][0],
38534732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][1],
38544732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][2],
38554732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][3],
38564732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][4],
38574732Sdavemq 			    nxgep->nxge_mmac_info.factory_mac_pool[i][5]));
38584185Sspeer 		}
38594732Sdavemq 
38604732Sdavemq 		compute_macs = B_FALSE;
38614732Sdavemq 		ddi_prop_free(prop_val);
38624732Sdavemq 		goto got_mmac_info;
38633859Sml29623 	}
38644732Sdavemq #endif
38654732Sdavemq 	/*
38664732Sdavemq 	 * total_factory_macs = 32
38674732Sdavemq 	 * num_factory_mmac = (32 >> (nports/2)) - 1
38684732Sdavemq 	 * So if nports = 4, then num_factory_mmac =  7
38694732Sdavemq 	 *    if nports = 2, then num_factory_mmac = 15
38704732Sdavemq 	 */
38714732Sdavemq 	nxgep->nxge_mmac_info.num_factory_mmac =
38724732Sdavemq 	    ((nxgep->nxge_mmac_info.total_factory_macs >>
38734732Sdavemq 	    (nxgep->nports >> 1))) - 1;
38744732Sdavemq 
38754732Sdavemq got_mmac_info:
38764732Sdavemq 
38774732Sdavemq 	if ((nxgep->function_num < 2) &&
38784732Sdavemq 	    (nxgep->nxge_mmac_info.num_factory_mmac >
38794732Sdavemq 	    XMAC_MAX_ALT_ADDR_ENTRY)) {
38804732Sdavemq 		nxgep->nxge_mmac_info.num_factory_mmac =
38814732Sdavemq 		    XMAC_MAX_ALT_ADDR_ENTRY;
38824732Sdavemq 	} else if ((nxgep->function_num > 1) &&
38834732Sdavemq 	    (nxgep->nxge_mmac_info.num_factory_mmac >
38844732Sdavemq 	    BMAC_MAX_ALT_ADDR_ENTRY)) {
38854732Sdavemq 		nxgep->nxge_mmac_info.num_factory_mmac =
38864732Sdavemq 		    BMAC_MAX_ALT_ADDR_ENTRY;
38874185Sspeer 	}
38884185Sspeer 
38893859Sml29623 	for (i = 0; i <= nxgep->nxge_mmac_info.num_mmac; i++) {
38903859Sml29623 		(void) npi_mac_altaddr_disable(nxgep->npi_handle,
38916929Smisaki 		    NXGE_GET_PORT_NUM(func_num), i);
38923859Sml29623 	}
38933859Sml29623 
38944732Sdavemq 	(void) nxge_init_mmac(nxgep, compute_macs);
38953859Sml29623 	return (NXGE_OK);
38963859Sml29623 }
38973859Sml29623 
38983859Sml29623 void
nxge_get_xcvr_properties(p_nxge_t nxgep)38993859Sml29623 nxge_get_xcvr_properties(p_nxge_t nxgep)
39003859Sml29623 {
39013859Sml29623 	uchar_t *prop_val;
39023859Sml29623 	uint_t prop_len;
39033859Sml29623 
39043859Sml29623 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_get_xcvr_properties"));
39053859Sml29623 
39063859Sml29623 	/*
39073859Sml29623 	 * Read the type of physical layer interface being used.
39083859Sml29623 	 */
39093859Sml29623 	nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
39103859Sml29623 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
39116929Smisaki 	    "phy-type", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
39123859Sml29623 		if (strncmp("pcs", (caddr_t)prop_val,
39136929Smisaki 		    (size_t)prop_len) == 0) {
39143859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = PCS_XCVR;
39153859Sml29623 		} else {
39163859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
39173859Sml29623 		}
39183859Sml29623 		ddi_prop_free(prop_val);
39193859Sml29623 	} else if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
39206929Smisaki 	    "phy-interface", &prop_val,
39216929Smisaki 	    &prop_len) == DDI_PROP_SUCCESS) {
39223859Sml29623 		if (strncmp("pcs", (caddr_t)prop_val, (size_t)prop_len) == 0) {
39233859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = PCS_XCVR;
39243859Sml29623 		} else {
39253859Sml29623 			nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
39263859Sml29623 		}
39273859Sml29623 		ddi_prop_free(prop_val);
39283859Sml29623 	}
39293859Sml29623 }
39303859Sml29623 
39313859Sml29623 /*
39323859Sml29623  * Static functions start here.
39333859Sml29623  */
39343859Sml29623 
39353859Sml29623 static void
nxge_ldgv_setup(p_nxge_ldg_t * ldgp,p_nxge_ldv_t * ldvp,uint8_t ldv,uint8_t endldg,int * ngrps)39363859Sml29623 nxge_ldgv_setup(p_nxge_ldg_t *ldgp, p_nxge_ldv_t *ldvp, uint8_t ldv,
39373859Sml29623 	uint8_t endldg, int *ngrps)
39383859Sml29623 {
39393859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup"));
39403859Sml29623 	/* Assign the group number for each device. */
39413859Sml29623 	(*ldvp)->ldg_assigned = (*ldgp)->ldg;
39423859Sml29623 	(*ldvp)->ldgp = *ldgp;
39433859Sml29623 	(*ldvp)->ldv = ldv;
39443859Sml29623 
39453859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup: "
39466929Smisaki 	    "ldv %d endldg %d ldg %d, ldvp $%p",
39476929Smisaki 	    ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
39483859Sml29623 
39493859Sml29623 	(*ldgp)->nldvs++;
39503859Sml29623 	if ((*ldgp)->ldg == (endldg - 1)) {
39513859Sml29623 		if ((*ldgp)->ldvp == NULL) {
39523859Sml29623 			(*ldgp)->ldvp = *ldvp;
39533859Sml29623 			*ngrps += 1;
39543859Sml29623 			NXGE_DEBUG_MSG((NULL, INT_CTL,
39556929Smisaki 			    "==> nxge_ldgv_setup: ngrps %d", *ngrps));
39563859Sml29623 		}
39573859Sml29623 		NXGE_DEBUG_MSG((NULL, INT_CTL,
39586929Smisaki 		    "==> nxge_ldgv_setup: ldvp $%p ngrps %d",
39596929Smisaki 		    *ldvp, *ngrps));
39603859Sml29623 		++*ldvp;
39613859Sml29623 	} else {
39623859Sml29623 		(*ldgp)->ldvp = *ldvp;
39633859Sml29623 		*ngrps += 1;
39643859Sml29623 		NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup(done): "
39656929Smisaki 		    "ldv %d endldg %d ldg %d, ldvp $%p",
39666929Smisaki 		    ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
39673859Sml29623 		(*ldvp) = ++*ldvp;
39683859Sml29623 		(*ldgp) = ++*ldgp;
39693859Sml29623 		NXGE_DEBUG_MSG((NULL, INT_CTL,
39706929Smisaki 		    "==> nxge_ldgv_setup: new ngrps %d", *ngrps));
39713859Sml29623 	}
39723859Sml29623 
39733859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup: "
39746929Smisaki 	    "ldv %d ldvp $%p endldg %d ngrps %d",
39756929Smisaki 	    ldv, ldvp, endldg, *ngrps));
39763859Sml29623 
39773859Sml29623 	NXGE_DEBUG_MSG((NULL, INT_CTL, "<== nxge_ldgv_setup"));
39783859Sml29623 }
39793859Sml29623 
39803859Sml29623 /*
39813859Sml29623  * Note: This function assumes the following distribution of mac
39823859Sml29623  * addresses among 4 ports in neptune:
39833859Sml29623  *
39843859Sml29623  *      -------------
39853859Sml29623  *    0|            |0 - local-mac-address for fn 0
39863859Sml29623  *      -------------
39873859Sml29623  *    1|            |1 - local-mac-address for fn 1
39883859Sml29623  *      -------------
39893859Sml29623  *    2|            |2 - local-mac-address for fn 2
39903859Sml29623  *      -------------
39913859Sml29623  *    3|            |3 - local-mac-address for fn 3
39923859Sml29623  *      -------------
39933859Sml29623  *     |            |4 - Start of alt. mac addr. for fn 0
39943859Sml29623  *     |            |
39953859Sml29623  *     |            |
39963859Sml29623  *     |            |10
39973859Sml29623  *     --------------
39983859Sml29623  *     |            |11 - Start of alt. mac addr. for fn 1
39993859Sml29623  *     |            |
40003859Sml29623  *     |            |
40013859Sml29623  *     |            |17
40023859Sml29623  *     --------------
40033859Sml29623  *     |            |18 - Start of alt. mac addr. for fn 2
40043859Sml29623  *     |            |
40053859Sml29623  *     |            |
40063859Sml29623  *     |            |24
40073859Sml29623  *     --------------
40083859Sml29623  *     |            |25 - Start of alt. mac addr. for fn 3
40093859Sml29623  *     |            |
40103859Sml29623  *     |            |
40113859Sml29623  *     |            |31
40123859Sml29623  *     --------------
40133859Sml29623  *
40143859Sml29623  * For N2/NIU the mac addresses is from XAUI card.
40154732Sdavemq  *
40164732Sdavemq  * When 'compute_addrs' is true, the alternate mac addresses are computed
40174732Sdavemq  * using the unique mac address as base. Otherwise the alternate addresses
40184732Sdavemq  * are assigned from the list read off the 'mac-addresses' property.
40193859Sml29623  */
40203859Sml29623 
40213859Sml29623 static void
nxge_init_mmac(p_nxge_t nxgep,boolean_t compute_addrs)40224732Sdavemq nxge_init_mmac(p_nxge_t nxgep, boolean_t compute_addrs)
40233859Sml29623 {
40243859Sml29623 	int slot;
40253859Sml29623 	uint8_t func_num;
40263859Sml29623 	uint16_t *base_mmac_addr;
40273859Sml29623 	uint32_t alt_mac_ls4b;
40283859Sml29623 	uint16_t *mmac_addr;
40293859Sml29623 	uint32_t base_mac_ls4b; /* least significant 4 bytes */
40303859Sml29623 	nxge_mmac_t *mmac_info;
40313859Sml29623 	npi_mac_addr_t mac_addr;
40323859Sml29623 
40333859Sml29623 	func_num = nxgep->function_num;
40343859Sml29623 	base_mmac_addr = (uint16_t *)&nxgep->factaddr;
40353859Sml29623 	mmac_info = (nxge_mmac_t *)&nxgep->nxge_mmac_info;
40363859Sml29623 
40374732Sdavemq 	if (compute_addrs) {
40384732Sdavemq 		base_mac_ls4b = ((uint32_t)base_mmac_addr[1]) << 16 |
40394732Sdavemq 		    base_mmac_addr[2];
40404732Sdavemq 
40414732Sdavemq 		if (nxgep->niu_type == N2_NIU) {
40424732Sdavemq 			/* ls4b of 1st altmac */
40434732Sdavemq 			alt_mac_ls4b = base_mac_ls4b + 1;
40444732Sdavemq 		} else {			/* Neptune */
40454732Sdavemq 			alt_mac_ls4b = base_mac_ls4b +
40464732Sdavemq 			    (nxgep->nports - func_num) +
40474732Sdavemq 			    (func_num * (mmac_info->num_factory_mmac));
40484732Sdavemq 		}
40493859Sml29623 	}
40503859Sml29623 
40513859Sml29623 	/* Set flags for unique MAC */
40523859Sml29623 	mmac_info->mac_pool[0].flags |= MMAC_SLOT_USED | MMAC_VENDOR_ADDR;
40533859Sml29623 
40543859Sml29623 	/* Clear flags of all alternate MAC slots */
40553859Sml29623 	for (slot = 1; slot <= mmac_info->num_mmac; slot++) {
40563859Sml29623 		if (slot <= mmac_info->num_factory_mmac)
40573859Sml29623 			mmac_info->mac_pool[slot].flags = MMAC_VENDOR_ADDR;
40583859Sml29623 		else
40593859Sml29623 			mmac_info->mac_pool[slot].flags = 0;
40603859Sml29623 	}
40613859Sml29623 
40623859Sml29623 	/* Generate and store factory alternate MACs */
40633859Sml29623 	for (slot = 1; slot <= mmac_info->num_factory_mmac; slot++) {
40643859Sml29623 		mmac_addr = (uint16_t *)&mmac_info->factory_mac_pool[slot];
40654732Sdavemq 		if (compute_addrs) {
40664732Sdavemq 			mmac_addr[0] = base_mmac_addr[0];
40674732Sdavemq 			mac_addr.w2 = mmac_addr[0];
40684732Sdavemq 
40694732Sdavemq 			mmac_addr[1] = (alt_mac_ls4b >> 16) & 0x0FFFF;
40704732Sdavemq 			mac_addr.w1 = mmac_addr[1];
40714732Sdavemq 
40724732Sdavemq 			mmac_addr[2] = alt_mac_ls4b & 0x0FFFF;
40734732Sdavemq 			mac_addr.w0 = mmac_addr[2];
40744732Sdavemq 
40754732Sdavemq 			alt_mac_ls4b++;
40764732Sdavemq 		} else {
40774732Sdavemq 			mac_addr.w2 = mmac_addr[0];
40784732Sdavemq 			mac_addr.w1 = mmac_addr[1];
40794732Sdavemq 			mac_addr.w0 = mmac_addr[2];
40804732Sdavemq 		}
40814732Sdavemq 
40824732Sdavemq 		NXGE_DEBUG_MSG((nxgep, DDI_CTL,
40834732Sdavemq 		    "mac_pool_addr[%2x:%2x:%2x:%2x:%2x:%2x] npi_addr[%x%x%x]",
40844732Sdavemq 		    mmac_info->factory_mac_pool[slot][0],
40854732Sdavemq 		    mmac_info->factory_mac_pool[slot][1],
40864732Sdavemq 		    mmac_info->factory_mac_pool[slot][2],
40874732Sdavemq 		    mmac_info->factory_mac_pool[slot][3],
40884732Sdavemq 		    mmac_info->factory_mac_pool[slot][4],
40894732Sdavemq 		    mmac_info->factory_mac_pool[slot][5],
40904732Sdavemq 		    mac_addr.w0, mac_addr.w1, mac_addr.w2));
40913859Sml29623 		/*
40924732Sdavemq 		 * slot minus 1 because npi_mac_altaddr_entry expects 0
40933859Sml29623 		 * for the first alternate mac address.
40943859Sml29623 		 */
40953859Sml29623 		(void) npi_mac_altaddr_entry(nxgep->npi_handle, OP_SET,
40966929Smisaki 		    NXGE_GET_PORT_NUM(func_num), slot - 1, &mac_addr);
40973859Sml29623 	}
40983859Sml29623 	/* Initialize the first two parameters for mmac kstat */
40993859Sml29623 	nxgep->statsp->mmac_stats.mmac_max_cnt = mmac_info->num_mmac;
41003859Sml29623 	nxgep->statsp->mmac_stats.mmac_avail_cnt = mmac_info->num_mmac;
41013859Sml29623 }
41028275SEric Cheng 
41038275SEric Cheng /*
41048275SEric Cheng  * Convert an RDC group index into a port ring index.  That is, map
41058275SEric Cheng  * <groupid> to an index into nxgep->rx_ring_handles.
41068275SEric Cheng  * (group ring index -> port ring index)
41078275SEric Cheng  */
41088275SEric Cheng int
nxge_get_rxring_index(p_nxge_t nxgep,int groupid,int ringidx)41098275SEric Cheng nxge_get_rxring_index(p_nxge_t nxgep, int groupid, int ringidx)
41108275SEric Cheng {
41118275SEric Cheng 	int			i;
41128275SEric Cheng 	int			index = 0;
41138275SEric Cheng 	p_nxge_rdc_grp_t	rdc_grp_p;
41148275SEric Cheng 	p_nxge_dma_pt_cfg_t	p_dma_cfgp;
41158275SEric Cheng 	p_nxge_hw_pt_cfg_t	p_cfgp;
41168275SEric Cheng 
41178275SEric Cheng 	p_dma_cfgp = &nxgep->pt_config;
41188275SEric Cheng 	p_cfgp = &p_dma_cfgp->hw_config;
41198275SEric Cheng 
412010309SSriharsha.Basavapatna@Sun.COM 	if (isLDOMguest(nxgep))
412110309SSriharsha.Basavapatna@Sun.COM 		return (ringidx);
412210309SSriharsha.Basavapatna@Sun.COM 
41238275SEric Cheng 	for (i = 0; i < groupid; i++) {
41248275SEric Cheng 		rdc_grp_p =
41258275SEric Cheng 		    &p_dma_cfgp->rdc_grps[p_cfgp->def_mac_rxdma_grpid + i];
41268275SEric Cheng 		index += rdc_grp_p->max_rdcs;
41278275SEric Cheng 	}
41288275SEric Cheng 
41298275SEric Cheng 	return (index + ringidx);
41308275SEric Cheng }
4131