xref: /onnv-gate/usr/src/uts/common/io/hxge/hpi_pfc.c (revision 8514:82402025d8c6)
16349Sqs148142 /*
26349Sqs148142  * CDDL HEADER START
36349Sqs148142  *
46349Sqs148142  * The contents of this file are subject to the terms of the
56349Sqs148142  * Common Development and Distribution License (the "License").
66349Sqs148142  * You may not use this file except in compliance with the License.
76349Sqs148142  *
86349Sqs148142  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96349Sqs148142  * or http://www.opensolaris.org/os/licensing.
106349Sqs148142  * See the License for the specific language governing permissions
116349Sqs148142  * and limitations under the License.
126349Sqs148142  *
136349Sqs148142  * When distributing Covered Code, include this CDDL HEADER in each
146349Sqs148142  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156349Sqs148142  * If applicable, add the following below this CDDL HEADER, with the
166349Sqs148142  * fields enclosed by brackets "[]" replaced with your own identifying
176349Sqs148142  * information: Portions Copyright [yyyy] [name of copyright owner]
186349Sqs148142  *
196349Sqs148142  * CDDL HEADER END
206349Sqs148142  */
216349Sqs148142 
226349Sqs148142 /*
23*8514SQiyan.Sun@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
246349Sqs148142  * Use is subject to license terms.
256349Sqs148142  */
266349Sqs148142 
276349Sqs148142 #include <hxge_impl.h>
286349Sqs148142 #include <hpi_pfc.h>
296349Sqs148142 
306349Sqs148142 #define	TCAM_COMPLETION_TRY_COUNT	10
316349Sqs148142 #define	HXGE_VLAN_TABLE_ENTRIES		128
326349Sqs148142 #define	HXGE_PFC_INT_STATUS_CLEAR	0x7ULL
336349Sqs148142 
346349Sqs148142 static uint64_t
hpi_pfc_tcam_check_completion(hpi_handle_t handle,tcam_op_t op_type)356349Sqs148142 hpi_pfc_tcam_check_completion(hpi_handle_t handle, tcam_op_t op_type)
366349Sqs148142 {
376349Sqs148142 	uint32_t	try_counter, tcam_delay = 10;
386349Sqs148142 	pfc_tcam_ctrl_t	tctl;
396349Sqs148142 
406349Sqs148142 	try_counter = TCAM_COMPLETION_TRY_COUNT;
416349Sqs148142 
426349Sqs148142 	switch (op_type) {
436349Sqs148142 	case TCAM_RWC_STAT:
446349Sqs148142 		READ_TCAM_REG_CTL(handle, &tctl.value);
456349Sqs148142 		while ((try_counter) &&
466349Sqs148142 		    (tctl.bits.status != TCAM_CTL_RWC_RWC_STAT)) {
476349Sqs148142 			try_counter--;
486349Sqs148142 			HXGE_DELAY(tcam_delay);
496349Sqs148142 			READ_TCAM_REG_CTL(handle, &tctl.value);
506349Sqs148142 		}
516349Sqs148142 
526349Sqs148142 		if (!try_counter) {
536349Sqs148142 			HPI_ERROR_MSG((handle.function, HPI_ERR_CTL,
546349Sqs148142 			    " TCAM RWC_STAT operation"
556349Sqs148142 			    " failed to complete \n"));
566349Sqs148142 			return (HPI_PFC_TCAM_HW_ERROR);
576349Sqs148142 		}
586349Sqs148142 
596349Sqs148142 		tctl.value = 0;
606349Sqs148142 		break;
616349Sqs148142 	case TCAM_RWC_MATCH:
626349Sqs148142 		READ_TCAM_REG_CTL(handle, &tctl.value);
636349Sqs148142 
646349Sqs148142 		while ((try_counter) &&
656349Sqs148142 		    (tctl.bits.match != TCAM_CTL_RWC_RWC_MATCH)) {
666349Sqs148142 			try_counter--;
676349Sqs148142 			HXGE_DELAY(tcam_delay);
686349Sqs148142 			READ_TCAM_REG_CTL(handle, &tctl.value);
696349Sqs148142 		}
706349Sqs148142 
716349Sqs148142 		if (!try_counter) {
726349Sqs148142 			HPI_ERROR_MSG((handle.function, HPI_ERR_CTL,
736349Sqs148142 			    " TCAM Match operationfailed to find match \n"));
746349Sqs148142 		}
756349Sqs148142 
766349Sqs148142 		break;
776349Sqs148142 	default:
786349Sqs148142 		HPI_ERROR_MSG((handle.function, HPI_ERR_CTL,
796349Sqs148142 		    " Invalid TCAM completion Request \n"));
806349Sqs148142 		return (HPI_PFC_ERROR | HPI_TCAM_ERROR | OPCODE_INVALID);
816349Sqs148142 	}
826349Sqs148142 
836349Sqs148142 	return (tctl.value);
846349Sqs148142 }
856349Sqs148142 
866349Sqs148142 hpi_status_t
hpi_pfc_tcam_entry_read(hpi_handle_t handle,uint32_t location,hxge_tcam_entry_t * tcam_ptr)876349Sqs148142 hpi_pfc_tcam_entry_read(hpi_handle_t handle, uint32_t location,
886349Sqs148142     hxge_tcam_entry_t *tcam_ptr)
896349Sqs148142 {
906349Sqs148142 	pfc_tcam_ctrl_t tctl;
916349Sqs148142 	pfc_tcam_ctrl_t tctl_rv;
926349Sqs148142 
936349Sqs148142 	/*
946349Sqs148142 	 * Hydra doesn't allow to read TCAM entries. Use compare instead.
956349Sqs148142 	 */
966349Sqs148142 	WRITE_TCAM_REG_MASK0(handle, tcam_ptr->mask0);
976349Sqs148142 	WRITE_TCAM_REG_MASK1(handle, tcam_ptr->mask1);
986349Sqs148142 
996349Sqs148142 	WRITE_TCAM_REG_KEY0(handle, tcam_ptr->key0);
1006349Sqs148142 	WRITE_TCAM_REG_KEY1(handle, tcam_ptr->key1);
1016349Sqs148142 
1026349Sqs148142 	tctl.value = 0;
1036349Sqs148142 	tctl.bits.addr = location;
1046349Sqs148142 	tctl.bits.cmd = TCAM_CTL_RWC_TCAM_CMP;
1056349Sqs148142 
1066349Sqs148142 	WRITE_TCAM_REG_CTL(handle, tctl.value);
1076349Sqs148142 
1086349Sqs148142 	tctl_rv.value = hpi_pfc_tcam_check_completion(handle, TCAM_RWC_MATCH);
1096349Sqs148142 
1106349Sqs148142 	if (tctl_rv.bits.match)
1116349Sqs148142 		return (HPI_SUCCESS);
1126349Sqs148142 	else
1136349Sqs148142 		return (HPI_FAILURE);
1146349Sqs148142 }
1156349Sqs148142 
1166349Sqs148142 hpi_status_t
hpi_pfc_tcam_asc_ram_entry_read(hpi_handle_t handle,uint32_t location,uint64_t * ram_data)1176349Sqs148142 hpi_pfc_tcam_asc_ram_entry_read(hpi_handle_t handle,
1186349Sqs148142     uint32_t location, uint64_t *ram_data)
1196349Sqs148142 {
1206349Sqs148142 	uint64_t tcam_stat;
1216349Sqs148142 	pfc_tcam_ctrl_t tctl;
1226349Sqs148142 
1236349Sqs148142 	tctl.value = 0;
1246349Sqs148142 	tctl.bits.addr = location;
1256349Sqs148142 	tctl.bits.cmd = TCAM_CTL_RWC_RAM_RD;
1266349Sqs148142 
1276349Sqs148142 	WRITE_TCAM_REG_CTL(handle, tctl.value);
1286349Sqs148142 
1296349Sqs148142 	tcam_stat = hpi_pfc_tcam_check_completion(handle, TCAM_RWC_STAT);
1306349Sqs148142 
1316349Sqs148142 	if (tcam_stat & HPI_FAILURE) {
1326349Sqs148142 		HPI_ERROR_MSG((handle.function, HPI_ERR_CTL,
1336349Sqs148142 		    "TCAM RAM read failed loc %d \n", location));
1346349Sqs148142 		return (HPI_PFC_ASC_RAM_RD_ERROR);
1356349Sqs148142 	}
1366349Sqs148142 
1376349Sqs148142 	READ_TCAM_REG_KEY0(handle, ram_data);
1386349Sqs148142 
1396349Sqs148142 	return (HPI_SUCCESS);
1406349Sqs148142 }
1416349Sqs148142 
1426349Sqs148142 hpi_status_t
hpi_pfc_tcam_asc_ram_entry_write(hpi_handle_t handle,uint32_t location,uint64_t ram_data)1436349Sqs148142 hpi_pfc_tcam_asc_ram_entry_write(hpi_handle_t handle, uint32_t location,
1446349Sqs148142     uint64_t ram_data)
1456349Sqs148142 {
1466349Sqs148142 	uint64_t	tcam_stat = 0;
1476349Sqs148142 	pfc_tcam_ctrl_t	tctl;
1486349Sqs148142 
1496349Sqs148142 	WRITE_TCAM_REG_KEY0(handle, ram_data);
1506349Sqs148142 
1516349Sqs148142 	tctl.value = 0;
1526349Sqs148142 	tctl.bits.addr = location;
1536349Sqs148142 	tctl.bits.cmd = TCAM_CTL_RWC_RAM_WR;
1546349Sqs148142 
1556349Sqs148142 	HPI_DEBUG_MSG((handle.function, HPI_PFC_CTL,
1566349Sqs148142 	    " tcam ascr write: location %x data %llx ctl value %llx \n",
1576349Sqs148142 	    location, ram_data, tctl.value));
1586349Sqs148142 	WRITE_TCAM_REG_CTL(handle, tctl.value);
1596349Sqs148142 	tcam_stat = hpi_pfc_tcam_check_completion(handle, TCAM_RWC_STAT);
1606349Sqs148142 
1616349Sqs148142 	if (tcam_stat & HPI_FAILURE) {
1626349Sqs148142 		HPI_ERROR_MSG((handle.function, HPI_ERR_CTL,
1636349Sqs148142 		    "TCAM RAM write failed loc %d \n", location));
1646349Sqs148142 		return (HPI_PFC_ASC_RAM_WR_ERROR);
1656349Sqs148142 	}
1666349Sqs148142 
1676349Sqs148142 	return (HPI_SUCCESS);
1686349Sqs148142 }
1696349Sqs148142 
1706349Sqs148142 static hpi_status_t
hpi_pfc_set_config(hpi_handle_t handle,pfc_config_t config)1716349Sqs148142 hpi_pfc_set_config(hpi_handle_t handle, pfc_config_t config)
1726349Sqs148142 {
1736349Sqs148142 	uint64_t offset;
1746349Sqs148142 
1756349Sqs148142 	offset = PFC_CONFIG;
1766349Sqs148142 	REG_PIO_WRITE64(handle, offset, config.value);
1776349Sqs148142 
1786349Sqs148142 	return (HPI_SUCCESS);
1796349Sqs148142 }
1806349Sqs148142 
1816349Sqs148142 static hpi_status_t
hpi_pfc_get_config(hpi_handle_t handle,pfc_config_t * configp)1826349Sqs148142 hpi_pfc_get_config(hpi_handle_t handle, pfc_config_t *configp)
1836349Sqs148142 {
1846349Sqs148142 	uint64_t offset;
1856349Sqs148142 
1866349Sqs148142 	offset = PFC_CONFIG;
1876349Sqs148142 	REG_PIO_READ64(handle, offset, &configp->value);
1886349Sqs148142 
1896349Sqs148142 	return (HPI_SUCCESS);
1906349Sqs148142 }
1916349Sqs148142 
1926349Sqs148142 hpi_status_t
hpi_pfc_set_tcam_enable(hpi_handle_t handle,boolean_t tcam)1936349Sqs148142 hpi_pfc_set_tcam_enable(hpi_handle_t handle, boolean_t tcam)
1946349Sqs148142 {
1956349Sqs148142 	pfc_config_t	config;
1966349Sqs148142 
1976349Sqs148142 	/*
1986349Sqs148142 	 * Read the register first.
1996349Sqs148142 	 */
2006349Sqs148142 	(void) hpi_pfc_get_config(handle, &config);
2016349Sqs148142 
2026349Sqs148142 	if (tcam)
2036349Sqs148142 		config.bits.tcam_en = 1;
2046349Sqs148142 	else
2056349Sqs148142 		config.bits.tcam_en = 0;
2066349Sqs148142 
2076349Sqs148142 	return (hpi_pfc_set_config(handle, config));
2086349Sqs148142 }
2096349Sqs148142 
2106349Sqs148142 hpi_status_t
hpi_pfc_set_l2_hash(hpi_handle_t handle,boolean_t l2_hash)2116349Sqs148142 hpi_pfc_set_l2_hash(hpi_handle_t handle, boolean_t l2_hash)
2126349Sqs148142 {
2136349Sqs148142 	pfc_config_t	config;
2146349Sqs148142 
2156349Sqs148142 	/*
2166349Sqs148142 	 * Read the register first.
2176349Sqs148142 	 */
2186349Sqs148142 	(void) hpi_pfc_get_config(handle, &config);
2196349Sqs148142 
2206349Sqs148142 	if (l2_hash)
2216349Sqs148142 		config.bits.l2_hash_en = 1;
2226349Sqs148142 	else
2236349Sqs148142 		config.bits.l2_hash_en = 0;
2246349Sqs148142 
2256349Sqs148142 	return (hpi_pfc_set_config(handle, config));
2266349Sqs148142 }
2276349Sqs148142 
2286349Sqs148142 hpi_status_t
hpi_pfc_set_tcp_cksum(hpi_handle_t handle,boolean_t cksum)2296349Sqs148142 hpi_pfc_set_tcp_cksum(hpi_handle_t handle, boolean_t cksum)
2306349Sqs148142 {
2316349Sqs148142 	pfc_config_t	config;
2326349Sqs148142 
2336349Sqs148142 	/*
2346349Sqs148142 	 * Read the register first.
2356349Sqs148142 	 */
2366349Sqs148142 	(void) hpi_pfc_get_config(handle, &config);
2376349Sqs148142 
2386349Sqs148142 	if (cksum)
2396349Sqs148142 		config.bits.tcp_cs_en = 1;
2406349Sqs148142 	else
2416349Sqs148142 		config.bits.tcp_cs_en = 0;
2426349Sqs148142 
2436349Sqs148142 	return (hpi_pfc_set_config(handle, config));
2446349Sqs148142 }
2456349Sqs148142 
2466349Sqs148142 hpi_status_t
hpi_pfc_set_default_dma(hpi_handle_t handle,uint32_t dma_channel_no)2476349Sqs148142 hpi_pfc_set_default_dma(hpi_handle_t handle, uint32_t dma_channel_no)
2486349Sqs148142 {
2496349Sqs148142 	pfc_config_t	config;
2506349Sqs148142 
2516349Sqs148142 	(void) hpi_pfc_get_config(handle, &config);
2526349Sqs148142 
2536349Sqs148142 	if (dma_channel_no > PFC_MAX_DMA_CHANNELS)
2546349Sqs148142 		return (HPI_FAILURE);
2556349Sqs148142 
2566349Sqs148142 	config.bits.default_dma = dma_channel_no;
2576349Sqs148142 
2586349Sqs148142 	return (hpi_pfc_set_config(handle, config));
2596349Sqs148142 }
2606349Sqs148142 
2616349Sqs148142 hpi_status_t
hpi_pfc_mac_addr_enable(hpi_handle_t handle,uint32_t slot)2626349Sqs148142 hpi_pfc_mac_addr_enable(hpi_handle_t handle, uint32_t slot)
2636349Sqs148142 {
2646349Sqs148142 	pfc_config_t	config;
2656349Sqs148142 	uint32_t	bit;
2666349Sqs148142 
2676349Sqs148142 	if (slot >= PFC_N_MAC_ADDRESSES) {
2686349Sqs148142 		return (HPI_FAILURE);
2696349Sqs148142 	}
2706349Sqs148142 
2716349Sqs148142 	(void) hpi_pfc_get_config(handle, &config);
2726349Sqs148142 
2736864Sqs148142 	if (slot < 24) {
2746864Sqs148142 		bit = 1 << slot;
2756864Sqs148142 		config.bits.mac_addr_en_l = config.bits.mac_addr_en_l | bit;
2766864Sqs148142 	} else {
2776864Sqs148142 		bit = 1 << (slot - 24);
2786864Sqs148142 		config.bits.mac_addr_en = config.bits.mac_addr_en | bit;
2796864Sqs148142 	}
2806349Sqs148142 
2816349Sqs148142 	return (hpi_pfc_set_config(handle, config));
2826349Sqs148142 }
2836349Sqs148142 
2846349Sqs148142 hpi_status_t
hpi_pfc_mac_addr_disable(hpi_handle_t handle,uint32_t slot)2856349Sqs148142 hpi_pfc_mac_addr_disable(hpi_handle_t handle, uint32_t slot)
2866349Sqs148142 {
2876349Sqs148142 	pfc_config_t	config;
2886349Sqs148142 	uint32_t	bit;
2896349Sqs148142 
2906349Sqs148142 	if (slot >= PFC_N_MAC_ADDRESSES) {
2916349Sqs148142 		return (HPI_FAILURE);
2926349Sqs148142 	}
2936349Sqs148142 
2946349Sqs148142 	(void) hpi_pfc_get_config(handle, &config);
2956349Sqs148142 
2966864Sqs148142 	if (slot < 24) {
2976864Sqs148142 		bit = 1 << slot;
2986864Sqs148142 		config.bits.mac_addr_en_l = config.bits.mac_addr_en_l & ~bit;
2996864Sqs148142 	} else {
3006864Sqs148142 		bit = 1 << (slot - 24);
3016864Sqs148142 		config.bits.mac_addr_en = config.bits.mac_addr_en & ~bit;
3026864Sqs148142 	}
3036349Sqs148142 
3046349Sqs148142 	return (hpi_pfc_set_config(handle, config));
3056349Sqs148142 }
3066349Sqs148142 
3076349Sqs148142 hpi_status_t
hpi_pfc_set_force_csum(hpi_handle_t handle,boolean_t force)3086349Sqs148142 hpi_pfc_set_force_csum(hpi_handle_t handle, boolean_t force)
3096349Sqs148142 {
3106349Sqs148142 	pfc_config_t	config;
3116349Sqs148142 
3126349Sqs148142 	(void) hpi_pfc_get_config(handle, &config);
3136349Sqs148142 
3146349Sqs148142 	if (force)
3156349Sqs148142 		config.bits.force_cs_en = 1;
3166349Sqs148142 	else
3176349Sqs148142 		config.bits.force_cs_en = 0;
3186349Sqs148142 
3196349Sqs148142 	return (hpi_pfc_set_config(handle, config));
3206349Sqs148142 }
3216349Sqs148142 
3226349Sqs148142 hpi_status_t
hpi_pfc_cfg_vlan_table_clear(hpi_handle_t handle)3236349Sqs148142 hpi_pfc_cfg_vlan_table_clear(hpi_handle_t handle)
3246349Sqs148142 {
3256349Sqs148142 	int			i;
3266349Sqs148142 	int			offset;
3276349Sqs148142 	int			step = 8;
3286349Sqs148142 	pfc_vlan_table_t	table_entry;
3296349Sqs148142 
3306349Sqs148142 	table_entry.value = 0;
3316349Sqs148142 	for (i = 0; i < HXGE_VLAN_TABLE_ENTRIES; i++) {
3326349Sqs148142 		table_entry.bits.member = 0;
3336349Sqs148142 		offset = PFC_VLAN_TABLE + i * step;
3346349Sqs148142 		REG_PIO_WRITE64(handle, offset, table_entry.value);
3356349Sqs148142 	}
3366349Sqs148142 
3376349Sqs148142 	return (HPI_SUCCESS);
3386349Sqs148142 }
3396349Sqs148142 
3406349Sqs148142 hpi_status_t
hpi_pfc_cfg_vlan_table_entry_clear(hpi_handle_t handle,vlan_id_t vlan_id)3416349Sqs148142 hpi_pfc_cfg_vlan_table_entry_clear(hpi_handle_t handle, vlan_id_t vlan_id)
3426349Sqs148142 {
3436349Sqs148142 	uint64_t		offset;
3446349Sqs148142 	pfc_vlan_table_t	vlan_tbl_entry;
3456349Sqs148142 	uint64_t		bit;
3466349Sqs148142 
3476349Sqs148142 	/*
3486349Sqs148142 	 * Assumes that the hardware will generate the new parity
3496349Sqs148142 	 * data.
3506349Sqs148142 	 */
3516349Sqs148142 	offset = PFC_VLAN_REG_OFFSET(vlan_id);
3526349Sqs148142 	REG_PIO_READ64(handle, offset, (uint64_t *)&vlan_tbl_entry.value);
3536349Sqs148142 
3546349Sqs148142 	bit = PFC_VLAN_BIT_OFFSET(vlan_id);
3556349Sqs148142 	bit = 1 << bit;
3566349Sqs148142 	vlan_tbl_entry.bits.member = vlan_tbl_entry.bits.member & ~bit;
3576349Sqs148142 
3586349Sqs148142 	REG_PIO_WRITE64(handle, offset, vlan_tbl_entry.value);
3596349Sqs148142 
3606349Sqs148142 	return (HPI_SUCCESS);
3616349Sqs148142 }
3626349Sqs148142 
3636349Sqs148142 hpi_status_t
hpi_pfc_cfg_vlan_table_entry_set(hpi_handle_t handle,vlan_id_t vlan_id)3646349Sqs148142 hpi_pfc_cfg_vlan_table_entry_set(hpi_handle_t handle, vlan_id_t vlan_id)
3656349Sqs148142 {
3666349Sqs148142 	uint64_t		offset;
3676349Sqs148142 	pfc_vlan_table_t	vlan_tbl_entry;
3686349Sqs148142 	uint64_t		bit;
3696349Sqs148142 
3706349Sqs148142 	/*
3716349Sqs148142 	 * Assumes that the hardware will generate the new parity
3726349Sqs148142 	 * data.
3736349Sqs148142 	 */
3746349Sqs148142 	offset = PFC_VLAN_REG_OFFSET(vlan_id);
3756349Sqs148142 	REG_PIO_READ64(handle, offset, (uint64_t *)&vlan_tbl_entry.value);
3766349Sqs148142 
3776349Sqs148142 	bit = PFC_VLAN_BIT_OFFSET(vlan_id);
3786349Sqs148142 	bit = 1 << bit;
3796349Sqs148142 	vlan_tbl_entry.bits.member = vlan_tbl_entry.bits.member | bit;
3806349Sqs148142 
3816349Sqs148142 	REG_PIO_WRITE64(handle, offset, vlan_tbl_entry.value);
3826349Sqs148142 
3836349Sqs148142 	return (HPI_SUCCESS);
3846349Sqs148142 }
3856349Sqs148142 
3866349Sqs148142 hpi_status_t
hpi_pfc_cfg_vlan_control_set(hpi_handle_t handle,boolean_t parity,boolean_t valid,vlan_id_t vlan_id)3876349Sqs148142 hpi_pfc_cfg_vlan_control_set(hpi_handle_t handle, boolean_t parity,
3886349Sqs148142     boolean_t valid, vlan_id_t vlan_id)
3896349Sqs148142 {
3906349Sqs148142 	pfc_vlan_ctrl_t	vlan_control;
3916349Sqs148142 
3926349Sqs148142 	vlan_control.value = 0;
3936349Sqs148142 
3946349Sqs148142 	if (parity)
3956349Sqs148142 		vlan_control.bits.par_en = 1;
3966349Sqs148142 	else
3976349Sqs148142 		vlan_control.bits.par_en = 0;
3986349Sqs148142 
3996349Sqs148142 	if (valid)
4006349Sqs148142 		vlan_control.bits.valid = 1;
4016349Sqs148142 	else
4026349Sqs148142 		vlan_control.bits.valid = 0;
4036349Sqs148142 
4046349Sqs148142 	vlan_control.bits.id = vlan_id;
4056349Sqs148142 
4066349Sqs148142 	REG_PIO_WRITE64(handle, PFC_VLAN_CTRL, vlan_control.value);
4076349Sqs148142 
4086349Sqs148142 	return (HPI_SUCCESS);
4096349Sqs148142 }
4106349Sqs148142 
4116349Sqs148142 hpi_status_t
hpi_pfc_get_vlan_parity_log(hpi_handle_t handle,pfc_vlan_par_err_log_t * logp)4126349Sqs148142 hpi_pfc_get_vlan_parity_log(hpi_handle_t handle, pfc_vlan_par_err_log_t *logp)
4136349Sqs148142 {
4146349Sqs148142 	uint64_t offset;
4156349Sqs148142 
4166349Sqs148142 	offset = PFC_VLAN_PAR_ERR_LOG;
4176349Sqs148142 	REG_PIO_READ64(handle, offset, &logp->value);
4186349Sqs148142 
4196349Sqs148142 	return (HPI_SUCCESS);
4206349Sqs148142 }
4216349Sqs148142 
4226349Sqs148142 hpi_status_t
hpi_pfc_set_mac_address(hpi_handle_t handle,uint32_t slot,uint64_t address)4236349Sqs148142 hpi_pfc_set_mac_address(hpi_handle_t handle, uint32_t slot, uint64_t address)
4246349Sqs148142 {
4256349Sqs148142 	uint64_t		offset;
4266349Sqs148142 	uint64_t		moffset;
4276349Sqs148142 	pfc_mac_addr_mask_t	mask;
4286349Sqs148142 	pfc_mac_addr_t		addr;
4296349Sqs148142 
4306349Sqs148142 	if (slot >= PFC_N_MAC_ADDRESSES)
4316349Sqs148142 		return (HPI_FAILURE);
4326349Sqs148142 
4336349Sqs148142 	offset = PFC_MAC_ADDRESS(slot);
4346349Sqs148142 	moffset = PFC_MAC_ADDRESS_MASK(slot);
4356349Sqs148142 
4366864Sqs148142 	addr.bits.addr = address >> 32;
4376864Sqs148142 	addr.bits.addr_l = address & 0xffffffff;
4386349Sqs148142 	mask.bits.mask = 0x0;
4396864Sqs148142 	mask.bits.mask_l = 0x0;
4406349Sqs148142 
4416349Sqs148142 	REG_PIO_WRITE64(handle, offset, addr.value);
4426349Sqs148142 	REG_PIO_WRITE64(handle, moffset, mask.value);
4436349Sqs148142 
4446349Sqs148142 	return (hpi_pfc_mac_addr_enable(handle, slot));
4456349Sqs148142 }
4466349Sqs148142 
4476349Sqs148142 hpi_status_t
hpi_pfc_clear_mac_address(hpi_handle_t handle,uint32_t slot)4486349Sqs148142 hpi_pfc_clear_mac_address(hpi_handle_t handle, uint32_t slot)
4496349Sqs148142 {
4506349Sqs148142 	uint64_t offset, moffset;
4516349Sqs148142 	uint64_t zaddr = 0x0ULL;
4526349Sqs148142 	uint64_t zmask = 0x0ULL;
4536349Sqs148142 
4546349Sqs148142 	if (slot >= PFC_N_MAC_ADDRESSES)
4556349Sqs148142 		return (HPI_FAILURE);
4566349Sqs148142 
4576349Sqs148142 	(void) hpi_pfc_mac_addr_disable(handle, slot);
4586349Sqs148142 
4596349Sqs148142 	offset = PFC_MAC_ADDRESS(slot);
4606349Sqs148142 	moffset = PFC_MAC_ADDRESS_MASK(slot);
4616349Sqs148142 
4626349Sqs148142 	REG_PIO_WRITE64(handle, offset, zaddr);
4636349Sqs148142 	REG_PIO_WRITE64(handle, moffset, zmask);
4646349Sqs148142 
4656349Sqs148142 	return (HPI_SUCCESS);
4666349Sqs148142 }
4676349Sqs148142 
4686349Sqs148142 hpi_status_t
hpi_pfc_clear_multicast_hash_table(hpi_handle_t handle,uint32_t slot)4696349Sqs148142 hpi_pfc_clear_multicast_hash_table(hpi_handle_t handle, uint32_t slot)
4706349Sqs148142 {
4716349Sqs148142 	uint64_t offset;
4726349Sqs148142 
4736349Sqs148142 	if (slot >= PFC_N_MAC_ADDRESSES)
4746349Sqs148142 		return (HPI_FAILURE);
4756349Sqs148142 
4766349Sqs148142 	offset = PFC_HASH_ADDR(slot);
4776349Sqs148142 	REG_PIO_WRITE64(handle, offset, 0ULL);
4786349Sqs148142 
4796349Sqs148142 	return (HPI_SUCCESS);
4806349Sqs148142 }
4816349Sqs148142 
4826349Sqs148142 hpi_status_t
hpi_pfc_set_multicast_hash_table(hpi_handle_t handle,uint32_t slot,uint64_t address)4836349Sqs148142 hpi_pfc_set_multicast_hash_table(hpi_handle_t handle, uint32_t slot,
4846349Sqs148142 	uint64_t address)
4856349Sqs148142 {
4866349Sqs148142 	uint64_t offset;
4876349Sqs148142 
4886349Sqs148142 	if (slot >= PFC_N_MAC_ADDRESSES)
4896349Sqs148142 		return (HPI_FAILURE);
4906349Sqs148142 
4916349Sqs148142 	offset = PFC_HASH_ADDR(slot);
4926349Sqs148142 	REG_PIO_WRITE64(handle, offset, address);
4936349Sqs148142 
4946349Sqs148142 	return (HPI_SUCCESS);
4956349Sqs148142 }
4966349Sqs148142 
4976349Sqs148142 hpi_status_t
hpi_pfc_set_l2_class_slot(hpi_handle_t handle,uint16_t etype,boolean_t valid,int slot)4986349Sqs148142 hpi_pfc_set_l2_class_slot(hpi_handle_t handle, uint16_t etype, boolean_t valid,
4996349Sqs148142     int slot)
5006349Sqs148142 {
5016349Sqs148142 	pfc_l2_class_config_t	l2_config;
5026349Sqs148142 	uint64_t		offset;
5036349Sqs148142 
5046349Sqs148142 	if (slot >= PFC_N_MAC_ADDRESSES)
5056349Sqs148142 		return (HPI_FAILURE);
5066349Sqs148142 
5076349Sqs148142 	l2_config.value = 0;
5086349Sqs148142 
5096349Sqs148142 	if (valid)
5106349Sqs148142 		l2_config.bits.valid = 1;
5116349Sqs148142 	else
5126349Sqs148142 		l2_config.bits.valid = 0;
5136349Sqs148142 
5146349Sqs148142 	l2_config.bits.etype = etype;
5156349Sqs148142 	l2_config.bits.rsrvd = 0;
5166349Sqs148142 
5176349Sqs148142 	offset = PFC_L2_CONFIG(slot);
5186349Sqs148142 	REG_PIO_WRITE64(handle, offset, l2_config.value);
5196349Sqs148142 
5206349Sqs148142 	return (HPI_SUCCESS);
5216349Sqs148142 }
5226349Sqs148142 
5236349Sqs148142 hpi_status_t
hpi_pfc_set_l3_class_config(hpi_handle_t handle,tcam_class_t slot,tcam_key_cfg_t cfg)5246349Sqs148142 hpi_pfc_set_l3_class_config(hpi_handle_t handle, tcam_class_t slot,
5256349Sqs148142     tcam_key_cfg_t cfg)
5266349Sqs148142 {
5276349Sqs148142 	pfc_l3_class_config_t	l3_config;
5286349Sqs148142 	uint64_t		offset;
5296349Sqs148142 
5306349Sqs148142 	if (slot >= PFC_N_MAC_ADDRESSES)
5316349Sqs148142 		return (HPI_FAILURE);
5326349Sqs148142 
5336349Sqs148142 	l3_config.value = 0;
5346349Sqs148142 
5356349Sqs148142 	if (cfg.lookup_enable)
5366349Sqs148142 		l3_config.bits.tsel = 1;
5376349Sqs148142 	else
5386349Sqs148142 		l3_config.bits.tsel = 0;
5396349Sqs148142 
5406349Sqs148142 	if (cfg.discard)
5416349Sqs148142 		l3_config.bits.discard = 1;
5426349Sqs148142 	else
5436349Sqs148142 		l3_config.bits.discard = 0;
5446349Sqs148142 
5456349Sqs148142 	offset = PFC_L3_CONFIG(slot);
5466349Sqs148142 	REG_PIO_WRITE64(handle, offset, l3_config.value);
5476349Sqs148142 
5486349Sqs148142 	return (HPI_SUCCESS);
5496349Sqs148142 }
5506349Sqs148142 
5516349Sqs148142 hpi_status_t
hpi_pfc_get_l3_class_config(hpi_handle_t handle,tcam_class_t slot,tcam_key_cfg_t * cfg)5526349Sqs148142 hpi_pfc_get_l3_class_config(hpi_handle_t handle, tcam_class_t slot,
5536349Sqs148142     tcam_key_cfg_t *cfg)
5546349Sqs148142 {
5556349Sqs148142 	pfc_l3_class_config_t	l3_config;
5566349Sqs148142 	uint64_t		offset;
5576349Sqs148142 
5586349Sqs148142 	if (slot >= PFC_N_MAC_ADDRESSES)
5596349Sqs148142 		return (HPI_FAILURE);
5606349Sqs148142 
5616349Sqs148142 	offset = PFC_L3_CONFIG(slot);
5626349Sqs148142 	REG_PIO_READ64(handle, offset, &l3_config.value);
5636349Sqs148142 
5646349Sqs148142 	if (l3_config.bits.tsel)
5656349Sqs148142 		cfg->lookup_enable = 1;
5666349Sqs148142 	else
5676349Sqs148142 		cfg->lookup_enable = 0;
5686349Sqs148142 
5696349Sqs148142 	if (l3_config.bits.discard)
5706349Sqs148142 		cfg->discard = 1;
5716349Sqs148142 	else
5726349Sqs148142 		cfg->discard = 0;
5736349Sqs148142 
5746349Sqs148142 	return (HPI_SUCCESS);
5756349Sqs148142 }
5766349Sqs148142 
5776349Sqs148142 static hpi_status_t
hpi_pfc_set_tcam_control(hpi_handle_t handle,pfc_tcam_ctrl_t * tcontrolp)5786349Sqs148142 hpi_pfc_set_tcam_control(hpi_handle_t handle, pfc_tcam_ctrl_t *tcontrolp)
5796349Sqs148142 {
5806349Sqs148142 	uint64_t offset;
5816349Sqs148142 
5826349Sqs148142 	offset = PFC_TCAM_CTRL;
5836349Sqs148142 	REG_PIO_WRITE64(handle, offset, tcontrolp->value);
5846349Sqs148142 
5856349Sqs148142 	return (HPI_SUCCESS);
5866349Sqs148142 }
5876349Sqs148142 
5886349Sqs148142 hpi_status_t
hpi_pfc_tcam_entry_invalidate(hpi_handle_t handle,uint32_t location)5896349Sqs148142 hpi_pfc_tcam_entry_invalidate(hpi_handle_t handle, uint32_t location)
5906349Sqs148142 {
5916349Sqs148142 	hxge_tcam_entry_t	tcam_ptr;
5926349Sqs148142 
5936349Sqs148142 	(void) memset(&tcam_ptr, 0, sizeof (hxge_tcam_entry_t));
5946349Sqs148142 	(void) hpi_pfc_tcam_entry_write(handle, location, &tcam_ptr);
5956349Sqs148142 
5966349Sqs148142 	return (HPI_SUCCESS);
5976349Sqs148142 }
5986349Sqs148142 
5996349Sqs148142 hpi_status_t
hpi_pfc_tcam_invalidate_all(hpi_handle_t handle)6006349Sqs148142 hpi_pfc_tcam_invalidate_all(hpi_handle_t handle)
6016349Sqs148142 {
6026349Sqs148142 	int		i;
6036349Sqs148142 	pfc_tcam_ctrl_t	tcontrol;
6046349Sqs148142 
6056349Sqs148142 	tcontrol.value = 0;
6066349Sqs148142 	for (i = 0; i < PFC_N_TCAM_ENTRIES; i++) {
6076349Sqs148142 		(void) hpi_pfc_set_tcam_control(handle, &tcontrol);
6086349Sqs148142 		(void) hpi_pfc_tcam_entry_invalidate(handle, i);
6096349Sqs148142 	}
6106349Sqs148142 
6116349Sqs148142 	return (HPI_SUCCESS);
6126349Sqs148142 }
6136349Sqs148142 
6146349Sqs148142 hpi_status_t
hpi_pfc_tcam_entry_write(hpi_handle_t handle,uint32_t location,hxge_tcam_entry_t * tcam_ptr)6156349Sqs148142 hpi_pfc_tcam_entry_write(hpi_handle_t handle, uint32_t location,
6166349Sqs148142     hxge_tcam_entry_t *tcam_ptr)
6176349Sqs148142 {
6186349Sqs148142 	uint64_t	tcam_stat;
6196349Sqs148142 	pfc_tcam_ctrl_t	tctl;
6206349Sqs148142 
6216349Sqs148142 	WRITE_TCAM_REG_MASK0(handle, tcam_ptr->mask0);
6226349Sqs148142 	WRITE_TCAM_REG_MASK1(handle, tcam_ptr->mask1);
6236349Sqs148142 
6246349Sqs148142 	WRITE_TCAM_REG_KEY0(handle, tcam_ptr->key0);
6256349Sqs148142 	WRITE_TCAM_REG_KEY1(handle, tcam_ptr->key1);
6266349Sqs148142 
6276349Sqs148142 	HPI_DEBUG_MSG((handle.function, HPI_PFC_CTL,
6286349Sqs148142 	    " tcam write: location %x\n key:  %llx %llx\n mask: %llx %llx\n",
6296349Sqs148142 	    location, tcam_ptr->key0, tcam_ptr->key1,
6306349Sqs148142 	    tcam_ptr->mask0, tcam_ptr->mask1));
6316349Sqs148142 
6326349Sqs148142 	tctl.value = 0;
6336349Sqs148142 	tctl.bits.addr = location;
6346349Sqs148142 	tctl.bits.cmd = TCAM_CTL_RWC_TCAM_WR;
6356349Sqs148142 
6366349Sqs148142 	HPI_DEBUG_MSG((handle.function, HPI_PFC_CTL,
6376349Sqs148142 	    " tcam write: ctl value %llx \n", tctl.value));
6386349Sqs148142 
6396349Sqs148142 	WRITE_TCAM_REG_CTL(handle, tctl.value);
6406349Sqs148142 
6416349Sqs148142 	tcam_stat = hpi_pfc_tcam_check_completion(handle, TCAM_RWC_STAT);
6426349Sqs148142 
6436349Sqs148142 	if (tcam_stat & HPI_FAILURE) {
6446349Sqs148142 		HPI_ERROR_MSG((handle.function, HPI_ERR_CTL,
6456349Sqs148142 		    "TCAM Write failed loc %d \n", location));
6466349Sqs148142 		return (HPI_PFC_TCAM_WR_ERROR);
6476349Sqs148142 	}
6486349Sqs148142 
6496349Sqs148142 	return (HPI_SUCCESS);
6506349Sqs148142 }
6516349Sqs148142 
6526349Sqs148142 hpi_status_t
hpi_pfc_get_tcam_parity_log(hpi_handle_t handle,pfc_tcam_par_err_log_t * logp)6536349Sqs148142 hpi_pfc_get_tcam_parity_log(hpi_handle_t handle, pfc_tcam_par_err_log_t *logp)
6546349Sqs148142 {
6556349Sqs148142 	uint64_t offset;
6566349Sqs148142 
6576349Sqs148142 	offset = PFC_TCAM_PAR_ERR_LOG;
6586349Sqs148142 	REG_PIO_READ64(handle, offset, &logp->value);
6596349Sqs148142 
6606349Sqs148142 	return (HPI_SUCCESS);
6616349Sqs148142 }
6626349Sqs148142 
6636349Sqs148142 hpi_status_t
hpi_pfc_get_tcam_auto_init(hpi_handle_t handle,pfc_auto_init_t * autoinitp)6646349Sqs148142 hpi_pfc_get_tcam_auto_init(hpi_handle_t handle, pfc_auto_init_t *autoinitp)
6656349Sqs148142 {
6666349Sqs148142 	uint64_t offset;
6676349Sqs148142 
6686349Sqs148142 	offset = PFC_AUTO_INIT;
6696349Sqs148142 	REG_PIO_READ64(handle, offset, &autoinitp->value);
6706349Sqs148142 
6716349Sqs148142 	return (HPI_SUCCESS);
6726349Sqs148142 }
6736349Sqs148142 
6746349Sqs148142 hpi_status_t
hpi_pfc_set_tcp_control_discard(hpi_handle_t handle,boolean_t discard)6756349Sqs148142 hpi_pfc_set_tcp_control_discard(hpi_handle_t handle, boolean_t discard)
6766349Sqs148142 {
6776349Sqs148142 	uint64_t	offset;
6786349Sqs148142 	tcp_ctrl_mask_t	tcp;
6796349Sqs148142 
6806349Sqs148142 	tcp.value = 0;
6816349Sqs148142 
6826349Sqs148142 	offset = TCP_CTRL_MASK;
6836349Sqs148142 	REG_PIO_READ64(handle, offset, &tcp.value);
6846349Sqs148142 
6856349Sqs148142 	if (discard)
6866349Sqs148142 		tcp.bits.discard = 1;
6876349Sqs148142 	else
6886349Sqs148142 		tcp.bits.discard = 0;
6896349Sqs148142 
6906349Sqs148142 	REG_PIO_WRITE64(handle, offset, tcp.value);
6916349Sqs148142 
6926349Sqs148142 	return (HPI_SUCCESS);
6936349Sqs148142 }
6946349Sqs148142 
6956349Sqs148142 hpi_status_t
hpi_pfc_set_tcp_control_fin(hpi_handle_t handle,boolean_t fin)6966349Sqs148142 hpi_pfc_set_tcp_control_fin(hpi_handle_t handle, boolean_t fin)
6976349Sqs148142 {
6986349Sqs148142 	uint64_t	offset;
6996349Sqs148142 	tcp_ctrl_mask_t	tcp;
7006349Sqs148142 
7016349Sqs148142 	tcp.value = 0;
7026349Sqs148142 
7036349Sqs148142 	offset = TCP_CTRL_MASK;
7046349Sqs148142 	REG_PIO_READ64(handle, offset, &tcp.value);
7056349Sqs148142 
7066349Sqs148142 	if (fin)
7076349Sqs148142 		tcp.bits.fin = 1;
7086349Sqs148142 	else
7096349Sqs148142 		tcp.bits.fin = 0;
7106349Sqs148142 
7116349Sqs148142 	REG_PIO_WRITE64(handle, offset, tcp.value);
7126349Sqs148142 	return (HPI_SUCCESS);
7136349Sqs148142 }
7146349Sqs148142 
7156349Sqs148142 hpi_status_t
hpi_pfc_set_tcp_control_syn(hpi_handle_t handle,boolean_t syn)7166349Sqs148142 hpi_pfc_set_tcp_control_syn(hpi_handle_t handle, boolean_t syn)
7176349Sqs148142 {
7186349Sqs148142 	uint64_t	offset;
7196349Sqs148142 	tcp_ctrl_mask_t	tcp;
7206349Sqs148142 
7216349Sqs148142 	tcp.value = 0;
7226349Sqs148142 
7236349Sqs148142 	offset = TCP_CTRL_MASK;
7246349Sqs148142 	REG_PIO_READ64(handle, offset, &tcp.value);
7256349Sqs148142 
7266349Sqs148142 	if (syn)
7276349Sqs148142 		tcp.bits.syn = 1;
7286349Sqs148142 	else
7296349Sqs148142 		tcp.bits.syn = 0;
7306349Sqs148142 
7316349Sqs148142 	REG_PIO_WRITE64(handle, offset, tcp.value);
7326349Sqs148142 	return (HPI_SUCCESS);
7336349Sqs148142 }
7346349Sqs148142 
7356349Sqs148142 hpi_status_t
hpi_pfc_set_tcp_control_rst(hpi_handle_t handle,boolean_t rst)7366349Sqs148142 hpi_pfc_set_tcp_control_rst(hpi_handle_t handle, boolean_t rst)
7376349Sqs148142 {
7386349Sqs148142 	uint64_t	offset;
7396349Sqs148142 	tcp_ctrl_mask_t	tcp;
7406349Sqs148142 
7416349Sqs148142 	tcp.value = 0;
7426349Sqs148142 
7436349Sqs148142 	offset = TCP_CTRL_MASK;
7446349Sqs148142 	REG_PIO_READ64(handle, offset, &tcp.value);
7456349Sqs148142 
7466349Sqs148142 	if (rst)
7476349Sqs148142 		tcp.bits.rst = 1;
7486349Sqs148142 	else
7496349Sqs148142 		tcp.bits.rst = 0;
7506349Sqs148142 
7516349Sqs148142 	REG_PIO_WRITE64(handle, offset, tcp.value);
7526349Sqs148142 	return (HPI_SUCCESS);
7536349Sqs148142 }
7546349Sqs148142 
7556349Sqs148142 hpi_status_t
hpi_pfc_set_tcp_control_psh(hpi_handle_t handle,boolean_t push)7566349Sqs148142 hpi_pfc_set_tcp_control_psh(hpi_handle_t handle, boolean_t push)
7576349Sqs148142 {
7586349Sqs148142 	uint64_t	offset;
7596349Sqs148142 	tcp_ctrl_mask_t	tcp;
7606349Sqs148142 
7616349Sqs148142 	tcp.value = 0;
7626349Sqs148142 
7636349Sqs148142 	offset = TCP_CTRL_MASK;
7646349Sqs148142 	REG_PIO_READ64(handle, offset, &tcp.value);
7656349Sqs148142 
7666349Sqs148142 	if (push)
7676349Sqs148142 		tcp.bits.psh = 1;
7686349Sqs148142 	else
7696349Sqs148142 		tcp.bits.psh = 0;
7706349Sqs148142 
7716349Sqs148142 	REG_PIO_WRITE64(handle, offset, tcp.value);
7726349Sqs148142 	return (HPI_SUCCESS);
7736349Sqs148142 }
7746349Sqs148142 
7756349Sqs148142 hpi_status_t
hpi_pfc_set_tcp_control_ack(hpi_handle_t handle,boolean_t ack)7766349Sqs148142 hpi_pfc_set_tcp_control_ack(hpi_handle_t handle, boolean_t ack)
7776349Sqs148142 {
7786349Sqs148142 	uint64_t	offset;
7796349Sqs148142 	tcp_ctrl_mask_t	tcp;
7806349Sqs148142 
7816349Sqs148142 	tcp.value = 0;
7826349Sqs148142 
7836349Sqs148142 	offset = TCP_CTRL_MASK;
7846349Sqs148142 	REG_PIO_READ64(handle, offset, &tcp.value);
7856349Sqs148142 
7866349Sqs148142 	if (ack)
7876349Sqs148142 		tcp.bits.ack = 1;
7886349Sqs148142 	else
7896349Sqs148142 		tcp.bits.ack = 0;
7906349Sqs148142 
7916349Sqs148142 	REG_PIO_WRITE64(handle, offset, tcp.value);
7926349Sqs148142 	return (HPI_SUCCESS);
7936349Sqs148142 }
7946349Sqs148142 
7956349Sqs148142 hpi_status_t
hpi_pfc_set_hash_seed_value(hpi_handle_t handle,uint32_t seed)7966349Sqs148142 hpi_pfc_set_hash_seed_value(hpi_handle_t handle, uint32_t seed)
7976349Sqs148142 {
7986349Sqs148142 	uint64_t	offset;
7996349Sqs148142 	src_hash_val_t	src_hash_seed;
8006349Sqs148142 
8016349Sqs148142 	src_hash_seed.value = 0;
8026349Sqs148142 	src_hash_seed.bits.seed = seed;
8036349Sqs148142 
8046349Sqs148142 	offset = SRC_HASH_VAL;
8056349Sqs148142 	REG_PIO_WRITE64(handle, offset, src_hash_seed.value);
8066349Sqs148142 
8076349Sqs148142 	return (HPI_SUCCESS);
8086349Sqs148142 }
8096349Sqs148142 
8106349Sqs148142 hpi_status_t
hpi_pfc_get_interrupt_status(hpi_handle_t handle,pfc_int_status_t * statusp)8116349Sqs148142 hpi_pfc_get_interrupt_status(hpi_handle_t handle, pfc_int_status_t *statusp)
8126349Sqs148142 {
8136349Sqs148142 	uint64_t offset;
8146349Sqs148142 
8156349Sqs148142 	offset = PFC_INT_STATUS;
8166349Sqs148142 	REG_PIO_READ64(handle, offset, &statusp->value);
8176349Sqs148142 
8186349Sqs148142 	return (HPI_SUCCESS);
8196349Sqs148142 }
8206349Sqs148142 
8216349Sqs148142 hpi_status_t
hpi_pfc_clear_interrupt_status(hpi_handle_t handle)8226349Sqs148142 hpi_pfc_clear_interrupt_status(hpi_handle_t handle)
8236349Sqs148142 {
8246349Sqs148142 	uint64_t offset;
8256349Sqs148142 
8266349Sqs148142 	offset = PFC_INT_STATUS;
8276349Sqs148142 	REG_PIO_WRITE64(handle, offset, HXGE_PFC_INT_STATUS_CLEAR);
8286349Sqs148142 
8296349Sqs148142 	return (HPI_SUCCESS);
8306349Sqs148142 }
8316349Sqs148142 
8326349Sqs148142 hpi_status_t
hpi_pfc_set_interrupt_mask(hpi_handle_t handle,boolean_t drop,boolean_t tcam_parity_error,boolean_t vlan_parity_error)8336349Sqs148142 hpi_pfc_set_interrupt_mask(hpi_handle_t handle, boolean_t drop,
8346349Sqs148142 	boolean_t tcam_parity_error, boolean_t vlan_parity_error)
8356349Sqs148142 {
8366349Sqs148142 	pfc_int_mask_t	mask;
8376349Sqs148142 	uint64_t	offset;
8386349Sqs148142 
8396349Sqs148142 	mask.value = 0;
8406349Sqs148142 
8416349Sqs148142 	if (drop)
8426349Sqs148142 		mask.bits.pkt_drop_mask = 1;
8436349Sqs148142 	else
8446349Sqs148142 		mask.bits.pkt_drop_mask = 0;
8456349Sqs148142 
8466349Sqs148142 	if (tcam_parity_error)
8476349Sqs148142 		mask.bits.tcam_parity_err_mask = 1;
8486349Sqs148142 	else
8496349Sqs148142 		mask.bits.tcam_parity_err_mask = 0;
8506349Sqs148142 
8516349Sqs148142 	if (vlan_parity_error)
8526349Sqs148142 		mask.bits.vlan_parity_err_mask = 1;
8536349Sqs148142 	else
8546349Sqs148142 		mask.bits.vlan_parity_err_mask = 0;
8556349Sqs148142 
8566349Sqs148142 	offset = PFC_INT_MASK;
8576349Sqs148142 	REG_PIO_WRITE64(handle, offset, mask.value);
8586349Sqs148142 
8596349Sqs148142 	return (HPI_SUCCESS);
8606349Sqs148142 }
8616349Sqs148142 
8626349Sqs148142 hpi_status_t
hpi_pfc_get_drop_log(hpi_handle_t handle,pfc_drop_log_t * logp)8636349Sqs148142 hpi_pfc_get_drop_log(hpi_handle_t handle, pfc_drop_log_t *logp)
8646349Sqs148142 {
8656349Sqs148142 	uint64_t offset;
8666349Sqs148142 
8676349Sqs148142 	offset = PFC_DROP_LOG;
8686349Sqs148142 	REG_PIO_READ64(handle, offset, &logp->value);
8696349Sqs148142 
8706349Sqs148142 	return (HPI_SUCCESS);
8716349Sqs148142 }
8726349Sqs148142 
8736349Sqs148142 hpi_status_t
hpi_pfc_set_drop_log_mask(hpi_handle_t handle,boolean_t vlan_drop,boolean_t tcam_drop,boolean_t class_code_drop,boolean_t l2_addr_drop,boolean_t tcp_ctrl_drop)8746349Sqs148142 hpi_pfc_set_drop_log_mask(hpi_handle_t handle, boolean_t vlan_drop,
8756349Sqs148142     boolean_t tcam_drop, boolean_t class_code_drop, boolean_t l2_addr_drop,
8766349Sqs148142     boolean_t tcp_ctrl_drop)
8776349Sqs148142 {
8786349Sqs148142 	uint64_t		offset;
8796349Sqs148142 	pfc_drop_log_mask_t	log;
8806349Sqs148142 
8816349Sqs148142 	log.value = 0;
8826349Sqs148142 
8836349Sqs148142 	if (vlan_drop)
8846349Sqs148142 		log.bits.vlan_drop_mask = 1;
8856349Sqs148142 	if (tcam_drop)
8866349Sqs148142 		log.bits.tcam_drop_mask = 1;
8876349Sqs148142 	if (class_code_drop)
8886349Sqs148142 		log.bits.class_code_drop_mask = 1;
8896349Sqs148142 	if (l2_addr_drop)
8906349Sqs148142 		log.bits.l2_addr_drop_mask = 1;
8916349Sqs148142 	if (tcp_ctrl_drop)
8926349Sqs148142 		log.bits.tcp_ctrl_drop_mask = 1;
8936349Sqs148142 
8946349Sqs148142 	offset = PFC_DROP_LOG_MASK;
8956349Sqs148142 	REG_PIO_WRITE64(handle, offset, log.value);
8966349Sqs148142 
8976349Sqs148142 	return (HPI_SUCCESS);
8986349Sqs148142 }
8996349Sqs148142 
9006349Sqs148142 hpi_status_t
hpi_pfc_get_bad_csum_counter(hpi_handle_t handle,uint64_t * countp)9016349Sqs148142 hpi_pfc_get_bad_csum_counter(hpi_handle_t handle, uint64_t *countp)
9026349Sqs148142 {
9036349Sqs148142 	uint64_t offset;
9046349Sqs148142 
9056349Sqs148142 	offset = PFC_BAD_CS_COUNTER;
9066349Sqs148142 	REG_PIO_READ64(handle, offset, countp);
9076349Sqs148142 
9086349Sqs148142 	return (HPI_SUCCESS);
9096349Sqs148142 }
9106349Sqs148142 
9116349Sqs148142 hpi_status_t
hpi_pfc_get_drop_counter(hpi_handle_t handle,uint64_t * countp)9126349Sqs148142 hpi_pfc_get_drop_counter(hpi_handle_t handle, uint64_t *countp)
9136349Sqs148142 {
9146349Sqs148142 	uint64_t offset;
9156349Sqs148142 
9166349Sqs148142 	offset = PFC_DROP_COUNTER;
9176349Sqs148142 	REG_PIO_READ64(handle, offset, countp);
9186349Sqs148142 
9196349Sqs148142 	return (HPI_SUCCESS);
9206349Sqs148142 }
9216349Sqs148142 
9226349Sqs148142 hpi_status_t
hpi_pfc_get_number_mac_addrs(hpi_handle_t handle,uint32_t * n_of_addrs)9236349Sqs148142 hpi_pfc_get_number_mac_addrs(hpi_handle_t handle, uint32_t *n_of_addrs)
9246349Sqs148142 {
9256349Sqs148142 	HXGE_REG_RD32(handle, HCR_REG + HCR_N_MAC_ADDRS, n_of_addrs);
9266349Sqs148142 	return (HPI_SUCCESS);
9276349Sqs148142 }
9286349Sqs148142 
9296349Sqs148142 hpi_status_t
hpi_pfc_mac_addr_get_i(hpi_handle_t handle,uint8_t * data,int slot)9306349Sqs148142 hpi_pfc_mac_addr_get_i(hpi_handle_t handle, uint8_t *data, int slot)
9316349Sqs148142 {
9326349Sqs148142 	uint32_t step = sizeof (uint32_t);
9336349Sqs148142 	uint32_t addr_hi = 0, addr_lo = 0;
9346349Sqs148142 
9356349Sqs148142 	if (slot >= PFC_N_MAC_ADDRESSES)
9366349Sqs148142 		return (HPI_FAILURE);
9376349Sqs148142 
9386349Sqs148142 	/*
9396349Sqs148142 	 * Read the MAC address out of the SPROM at the blade's
9406349Sqs148142 	 * specific location.
9416349Sqs148142 	 */
9426349Sqs148142 	HXGE_REG_RD32(handle, HCR_REG + HCR_ADDR_LO + slot * step, &addr_lo);
9436349Sqs148142 	HXGE_REG_RD32(handle, HCR_REG + HCR_ADDR_HI + slot * step, &addr_hi);
9446349Sqs148142 
9456349Sqs148142 	data[0] = addr_lo & 0x000000ff;
9466349Sqs148142 	data[1] = (addr_lo & 0x0000ff00) >> 8;
9476349Sqs148142 	data[2] = (addr_lo & 0x00ff0000) >> 16;
9486349Sqs148142 	data[3] = (addr_lo & 0xff000000) >> 24;
949*8514SQiyan.Sun@Sun.COM 	data[4] = (addr_hi & 0x0000000ff);
950*8514SQiyan.Sun@Sun.COM 	data[5] = (addr_hi & 0x00000ff00) >> 8;
9516349Sqs148142 
9526349Sqs148142 	return (HPI_SUCCESS);
9536349Sqs148142 }
9546349Sqs148142 
9556349Sqs148142 hpi_status_t
hpi_pfc_num_macs_get(hpi_handle_t handle,uint8_t * data)9566349Sqs148142 hpi_pfc_num_macs_get(hpi_handle_t handle, uint8_t *data)
9576349Sqs148142 {
9586349Sqs148142 	uint8_t	addr[6];
9596349Sqs148142 	uint8_t	num = 0;
9606349Sqs148142 	int	i;
9616349Sqs148142 
9626349Sqs148142 	for (i = 0; i < 16; i++) {
9636349Sqs148142 		(void) hpi_pfc_mac_addr_get_i(handle, addr, i);
9646349Sqs148142 		if (addr[0] || addr[1] || addr[2] ||
9656349Sqs148142 		    addr[3] || addr[4] || addr[5])
9666349Sqs148142 			num++;
9676349Sqs148142 	}
9686349Sqs148142 
9696349Sqs148142 	*data = num;
9706349Sqs148142 
9716349Sqs148142 	return (HPI_SUCCESS);
9726349Sqs148142 }
973