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 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 236349Sqs148142 * Use is subject to license terms. 246349Sqs148142 */ 256349Sqs148142 266349Sqs148142 #pragma ident "%Z%%M% %I% %E% SMI" 276349Sqs148142 28*6864Sqs148142 #include <hxge_impl.h> 296349Sqs148142 #include <hpi_vmac.h> 306349Sqs148142 316349Sqs148142 #define HXGE_VMAC_RX_STAT_CLEAR 0x1ffULL 326349Sqs148142 #define HXGE_VMAC_TX_STAT_CLEAR 0x7ULL 336349Sqs148142 #define HXGE_VMAC_RX_MASK_OVERFLOW 0x1fe 346349Sqs148142 #define HXGE_VMAC_RX_MASK_FRAME 0x1 356349Sqs148142 366349Sqs148142 hpi_status_t 376349Sqs148142 hpi_tx_vmac_reset(hpi_handle_t handle) 386349Sqs148142 { 396349Sqs148142 vmac_rst_t reset; 406349Sqs148142 416349Sqs148142 HXGE_REG_RD64(handle, VMAC_RST, &(reset.value)); 426349Sqs148142 436349Sqs148142 reset.bits.tx_reset = 1; 446349Sqs148142 456349Sqs148142 HXGE_REG_WR64(handle, VMAC_RST, reset.value); 466349Sqs148142 476349Sqs148142 return (HPI_SUCCESS); 486349Sqs148142 } 496349Sqs148142 506349Sqs148142 hpi_status_t 516349Sqs148142 hpi_rx_vmac_reset(hpi_handle_t handle) 526349Sqs148142 { 536349Sqs148142 vmac_rst_t reset; 546349Sqs148142 556349Sqs148142 HXGE_REG_RD64(handle, VMAC_RST, &(reset.value)); 566349Sqs148142 576349Sqs148142 reset.bits.rx_reset = 1; 586349Sqs148142 596349Sqs148142 HXGE_REG_WR64(handle, VMAC_RST, reset.value); 606349Sqs148142 616349Sqs148142 return (HPI_SUCCESS); 626349Sqs148142 } 636349Sqs148142 646349Sqs148142 656349Sqs148142 hpi_status_t 666349Sqs148142 hpi_vmac_tx_config(hpi_handle_t handle, config_op_t op, uint64_t config, 676349Sqs148142 uint16_t max_frame_length) 686349Sqs148142 { 696349Sqs148142 vmac_tx_cfg_t cfg; 706349Sqs148142 716349Sqs148142 if (config == 0) { 726349Sqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL, 736349Sqs148142 " hpi_vmac_tx_config Invalid Input: config <0x%x>", 746349Sqs148142 config)); 756349Sqs148142 return (HPI_FAILURE); 766349Sqs148142 } 776349Sqs148142 786349Sqs148142 HXGE_REG_RD64(handle, VMAC_TX_CFG, &cfg.value); 796349Sqs148142 806349Sqs148142 switch (op) { 816349Sqs148142 case ENABLE: 826349Sqs148142 if (config & CFG_VMAC_TX_EN) 836349Sqs148142 cfg.bits.tx_en = 1; 846349Sqs148142 if (config & CFG_VMAC_TX_CRC_INSERT) 856349Sqs148142 cfg.bits.crc_insert = 1; 866349Sqs148142 if (config & CFG_VMAC_TX_PAD) 876349Sqs148142 cfg.bits.tx_pad = 1; 886349Sqs148142 if (max_frame_length) 896349Sqs148142 cfg.bits.tx_max_frame_length = max_frame_length; 906349Sqs148142 break; 916349Sqs148142 case DISABLE: 926349Sqs148142 if (config & CFG_VMAC_TX_EN) 936349Sqs148142 cfg.bits.tx_en = 0; 946349Sqs148142 if (config & CFG_VMAC_TX_CRC_INSERT) 956349Sqs148142 cfg.bits.crc_insert = 0; 966349Sqs148142 if (config & CFG_VMAC_TX_PAD) 976349Sqs148142 cfg.bits.tx_pad = 0; 986349Sqs148142 break; 996349Sqs148142 case INIT: 1006349Sqs148142 if (config & CFG_VMAC_TX_EN) 1016349Sqs148142 cfg.bits.tx_en = 1; 1026349Sqs148142 else 1036349Sqs148142 cfg.bits.tx_en = 0; 1046349Sqs148142 1056349Sqs148142 if (config & CFG_VMAC_TX_CRC_INSERT) 1066349Sqs148142 cfg.bits.crc_insert = 1; 1076349Sqs148142 else 1086349Sqs148142 cfg.bits.crc_insert = 0; 1096349Sqs148142 1106349Sqs148142 if (config & CFG_VMAC_TX_PAD) 1116349Sqs148142 cfg.bits.tx_pad = 1; 1126349Sqs148142 else 1136349Sqs148142 cfg.bits.tx_pad = 0; 1146349Sqs148142 1156349Sqs148142 if (max_frame_length) 1166349Sqs148142 cfg.bits.tx_max_frame_length = max_frame_length; 1176349Sqs148142 1186349Sqs148142 break; 1196349Sqs148142 default: 1206349Sqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL, 1216349Sqs148142 " hpi_vmac_tx_config Invalid Input: op <0x%x>", op)); 1226349Sqs148142 return (HPI_FAILURE); 1236349Sqs148142 } 1246349Sqs148142 1256349Sqs148142 HXGE_REG_WR64(handle, VMAC_TX_CFG, cfg.value); 1266349Sqs148142 1276349Sqs148142 return (HPI_SUCCESS); 1286349Sqs148142 } 1296349Sqs148142 1306349Sqs148142 hpi_status_t 1316349Sqs148142 hpi_vmac_rx_config(hpi_handle_t handle, config_op_t op, uint64_t config, 1326349Sqs148142 uint16_t max_frame_length) 1336349Sqs148142 { 1346349Sqs148142 vmac_rx_cfg_t cfg; 1356349Sqs148142 1366349Sqs148142 if (config == 0) { 1376349Sqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL, 1386349Sqs148142 " hpi_vmac_rx_config Invalid Input: config <0x%x>", 1396349Sqs148142 config)); 1406349Sqs148142 return (HPI_FAILURE); 1416349Sqs148142 } 1426349Sqs148142 1436349Sqs148142 HXGE_REG_RD64(handle, VMAC_RX_CFG, &cfg.value); 1446349Sqs148142 1456349Sqs148142 switch (op) { 1466349Sqs148142 case ENABLE: 1476349Sqs148142 if (config & CFG_VMAC_RX_EN) 1486349Sqs148142 cfg.bits.rx_en = 1; 1496349Sqs148142 if (config & CFG_VMAC_RX_CRC_CHECK_DISABLE) 1506349Sqs148142 cfg.bits.crc_check_disable = 1; 1516349Sqs148142 if (config & CFG_VMAC_RX_STRIP_CRC) 1526349Sqs148142 cfg.bits.strip_crc = 1; 1536349Sqs148142 if (config & CFG_VMAC_RX_PASS_FLOW_CTRL_FR) 1546349Sqs148142 cfg.bits.pass_flow_ctrl_fr = 1; 1556349Sqs148142 if (config & CFG_VMAC_RX_PROMIXCUOUS_GROUP) 1566349Sqs148142 cfg.bits.promiscuous_group = 1; 1576349Sqs148142 if (config & CFG_VMAC_RX_PROMISCUOUS_MODE) 1586349Sqs148142 cfg.bits.promiscuous_mode = 1; 1596349Sqs148142 if (config & CFG_VMAC_RX_LOOP_BACK) 1606349Sqs148142 cfg.bits.loopback = 1; 1616349Sqs148142 break; 1626349Sqs148142 case DISABLE: 1636349Sqs148142 if (config & CFG_VMAC_RX_EN) 1646349Sqs148142 cfg.bits.rx_en = 0; 1656349Sqs148142 if (config & CFG_VMAC_RX_CRC_CHECK_DISABLE) 1666349Sqs148142 cfg.bits.crc_check_disable = 0; 1676349Sqs148142 if (config & CFG_VMAC_RX_STRIP_CRC) 1686349Sqs148142 cfg.bits.strip_crc = 0; 1696349Sqs148142 if (config & CFG_VMAC_RX_PASS_FLOW_CTRL_FR) 1706349Sqs148142 cfg.bits.pass_flow_ctrl_fr = 0; 1716349Sqs148142 if (config & CFG_VMAC_RX_PROMIXCUOUS_GROUP) 1726349Sqs148142 cfg.bits.promiscuous_group = 0; 1736349Sqs148142 if (config & CFG_VMAC_RX_PROMISCUOUS_MODE) 1746349Sqs148142 cfg.bits.promiscuous_mode = 0; 1756349Sqs148142 if (config & CFG_VMAC_RX_LOOP_BACK) 1766349Sqs148142 cfg.bits.loopback = 0; 1776349Sqs148142 break; 1786349Sqs148142 case INIT: 1796349Sqs148142 if (config & CFG_VMAC_RX_EN) 1806349Sqs148142 cfg.bits.rx_en = 1; 1816349Sqs148142 else 1826349Sqs148142 cfg.bits.rx_en = 0; 1836349Sqs148142 if (config & CFG_VMAC_RX_CRC_CHECK_DISABLE) 1846349Sqs148142 cfg.bits.crc_check_disable = 1; 1856349Sqs148142 else 1866349Sqs148142 cfg.bits.crc_check_disable = 0; 1876349Sqs148142 if (config & CFG_VMAC_RX_STRIP_CRC) 1886349Sqs148142 cfg.bits.strip_crc = 1; 1896349Sqs148142 else 1906349Sqs148142 cfg.bits.strip_crc = 0; 1916349Sqs148142 if (config & CFG_VMAC_RX_PASS_FLOW_CTRL_FR) 1926349Sqs148142 cfg.bits.pass_flow_ctrl_fr = 1; 1936349Sqs148142 else 1946349Sqs148142 cfg.bits.pass_flow_ctrl_fr = 0; 1956349Sqs148142 if (config & CFG_VMAC_RX_PROMIXCUOUS_GROUP) 1966349Sqs148142 cfg.bits.promiscuous_group = 1; 1976349Sqs148142 else 1986349Sqs148142 cfg.bits.promiscuous_group = 0; 1996349Sqs148142 if (config & CFG_VMAC_RX_PROMISCUOUS_MODE) 2006349Sqs148142 cfg.bits.promiscuous_mode = 1; 2016349Sqs148142 else 2026349Sqs148142 cfg.bits.promiscuous_mode = 0; 2036349Sqs148142 if (config & CFG_VMAC_RX_LOOP_BACK) 2046349Sqs148142 cfg.bits.loopback = 1; 2056349Sqs148142 else 2066349Sqs148142 cfg.bits.loopback = 0; 2076349Sqs148142 2086349Sqs148142 break; 2096349Sqs148142 default: 2106349Sqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL, 2116349Sqs148142 " hpi_vmac_rx_config Invalid Input: op <0x%x>", op)); 2126349Sqs148142 return (HPI_FAILURE); 2136349Sqs148142 } 2146349Sqs148142 2156349Sqs148142 if (max_frame_length) 2166349Sqs148142 cfg.bits.rx_max_frame_length = max_frame_length; 2176349Sqs148142 2186349Sqs148142 HXGE_REG_WR64(handle, VMAC_RX_CFG, cfg.value); 2196349Sqs148142 2206349Sqs148142 return (HPI_SUCCESS); 2216349Sqs148142 } 2226349Sqs148142 2236349Sqs148142 hpi_status_t 2246349Sqs148142 hpi_vmac_clear_rx_int_stat(hpi_handle_t handle) 2256349Sqs148142 { 2266349Sqs148142 uint64_t offset; 2276349Sqs148142 2286349Sqs148142 offset = VMAC_RX_STAT; 2296349Sqs148142 REG_PIO_WRITE64(handle, offset, HXGE_VMAC_RX_STAT_CLEAR); 2306349Sqs148142 2316349Sqs148142 return (HPI_SUCCESS); 2326349Sqs148142 } 2336349Sqs148142 2346349Sqs148142 hpi_status_t 2356349Sqs148142 hpi_vmac_clear_tx_int_stat(hpi_handle_t handle) 2366349Sqs148142 { 2376349Sqs148142 uint64_t offset; 2386349Sqs148142 2396349Sqs148142 offset = VMAC_TX_STAT; 2406349Sqs148142 REG_PIO_WRITE64(handle, offset, HXGE_VMAC_TX_STAT_CLEAR); 2416349Sqs148142 2426349Sqs148142 return (HPI_SUCCESS); 2436349Sqs148142 } 2446349Sqs148142 2456349Sqs148142 hpi_status_t 2466349Sqs148142 hpi_pfc_set_rx_int_stat_mask(hpi_handle_t handle, boolean_t overflow_cnt, 2476349Sqs148142 boolean_t frame_cnt) 2486349Sqs148142 { 2496349Sqs148142 uint64_t offset; 2506349Sqs148142 uint64_t value = 0; 2516349Sqs148142 2526349Sqs148142 if (overflow_cnt) 2536349Sqs148142 value |= HXGE_VMAC_RX_MASK_OVERFLOW; 2546349Sqs148142 2556349Sqs148142 if (frame_cnt) 2566349Sqs148142 value |= HXGE_VMAC_RX_MASK_FRAME; 2576349Sqs148142 2586349Sqs148142 offset = VMAC_RX_MSK; 2596349Sqs148142 REG_PIO_WRITE64(handle, offset, value); 2606349Sqs148142 2616349Sqs148142 return (HPI_SUCCESS); 2626349Sqs148142 } 2636349Sqs148142 2646349Sqs148142 hpi_status_t 2656349Sqs148142 hpi_pfc_set_tx_int_stat_mask(hpi_handle_t handle, boolean_t overflow_cnt, 2666349Sqs148142 boolean_t frame_cnt) 2676349Sqs148142 { 2686349Sqs148142 uint64_t offset; 2696349Sqs148142 uint64_t value = 0; 2706349Sqs148142 uint64_t overflow_mask = 0x6; 2716349Sqs148142 uint64_t frame_mask = 0x1; 2726349Sqs148142 2736349Sqs148142 if (overflow_cnt) 2746349Sqs148142 value |= overflow_mask; 2756349Sqs148142 2766349Sqs148142 if (frame_cnt) 2776349Sqs148142 value |= frame_mask; 2786349Sqs148142 2796349Sqs148142 offset = VMAC_TX_MSK; 2806349Sqs148142 REG_PIO_WRITE64(handle, offset, value); 2816349Sqs148142 2826349Sqs148142 return (HPI_SUCCESS); 2836349Sqs148142 } 284