13dec9fcdSqs148142 /* 23dec9fcdSqs148142 * CDDL HEADER START 33dec9fcdSqs148142 * 43dec9fcdSqs148142 * The contents of this file are subject to the terms of the 53dec9fcdSqs148142 * Common Development and Distribution License (the "License"). 63dec9fcdSqs148142 * You may not use this file except in compliance with the License. 73dec9fcdSqs148142 * 83dec9fcdSqs148142 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 93dec9fcdSqs148142 * or http://www.opensolaris.org/os/licensing. 103dec9fcdSqs148142 * See the License for the specific language governing permissions 113dec9fcdSqs148142 * and limitations under the License. 123dec9fcdSqs148142 * 133dec9fcdSqs148142 * When distributing Covered Code, include this CDDL HEADER in each 143dec9fcdSqs148142 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153dec9fcdSqs148142 * If applicable, add the following below this CDDL HEADER, with the 163dec9fcdSqs148142 * fields enclosed by brackets "[]" replaced with your own identifying 173dec9fcdSqs148142 * information: Portions Copyright [yyyy] [name of copyright owner] 183dec9fcdSqs148142 * 193dec9fcdSqs148142 * CDDL HEADER END 203dec9fcdSqs148142 */ 213dec9fcdSqs148142 /* 223dec9fcdSqs148142 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 233dec9fcdSqs148142 * Use is subject to license terms. 243dec9fcdSqs148142 */ 253dec9fcdSqs148142 26fe930412Sqs148142 #include <hxge_impl.h> 273dec9fcdSqs148142 #include <hpi_vmac.h> 283dec9fcdSqs148142 293dec9fcdSqs148142 #define HXGE_VMAC_RX_STAT_CLEAR 0x1ffULL 303dec9fcdSqs148142 #define HXGE_VMAC_TX_STAT_CLEAR 0x7ULL 313dec9fcdSqs148142 #define HXGE_VMAC_RX_MASK_OVERFLOW 0x1fe 323dec9fcdSqs148142 #define HXGE_VMAC_RX_MASK_FRAME 0x1 333dec9fcdSqs148142 343dec9fcdSqs148142 hpi_status_t 353dec9fcdSqs148142 hpi_tx_vmac_reset(hpi_handle_t handle) 363dec9fcdSqs148142 { 373dec9fcdSqs148142 vmac_rst_t reset; 383dec9fcdSqs148142 393dec9fcdSqs148142 HXGE_REG_RD64(handle, VMAC_RST, &(reset.value)); 403dec9fcdSqs148142 413dec9fcdSqs148142 reset.bits.tx_reset = 1; 423dec9fcdSqs148142 433dec9fcdSqs148142 HXGE_REG_WR64(handle, VMAC_RST, reset.value); 443dec9fcdSqs148142 453dec9fcdSqs148142 return (HPI_SUCCESS); 463dec9fcdSqs148142 } 473dec9fcdSqs148142 483dec9fcdSqs148142 hpi_status_t 493dec9fcdSqs148142 hpi_rx_vmac_reset(hpi_handle_t handle) 503dec9fcdSqs148142 { 513dec9fcdSqs148142 vmac_rst_t reset; 523dec9fcdSqs148142 533dec9fcdSqs148142 HXGE_REG_RD64(handle, VMAC_RST, &(reset.value)); 543dec9fcdSqs148142 553dec9fcdSqs148142 reset.bits.rx_reset = 1; 563dec9fcdSqs148142 573dec9fcdSqs148142 HXGE_REG_WR64(handle, VMAC_RST, reset.value); 583dec9fcdSqs148142 593dec9fcdSqs148142 return (HPI_SUCCESS); 603dec9fcdSqs148142 } 613dec9fcdSqs148142 623dec9fcdSqs148142 633dec9fcdSqs148142 hpi_status_t 643dec9fcdSqs148142 hpi_vmac_tx_config(hpi_handle_t handle, config_op_t op, uint64_t config, 653dec9fcdSqs148142 uint16_t max_frame_length) 663dec9fcdSqs148142 { 673dec9fcdSqs148142 vmac_tx_cfg_t cfg; 683dec9fcdSqs148142 693dec9fcdSqs148142 if (config == 0) { 703dec9fcdSqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL, 713dec9fcdSqs148142 " hpi_vmac_tx_config Invalid Input: config <0x%x>", 723dec9fcdSqs148142 config)); 733dec9fcdSqs148142 return (HPI_FAILURE); 743dec9fcdSqs148142 } 753dec9fcdSqs148142 763dec9fcdSqs148142 HXGE_REG_RD64(handle, VMAC_TX_CFG, &cfg.value); 773dec9fcdSqs148142 783dec9fcdSqs148142 switch (op) { 793dec9fcdSqs148142 case ENABLE: 803dec9fcdSqs148142 if (config & CFG_VMAC_TX_EN) 813dec9fcdSqs148142 cfg.bits.tx_en = 1; 823dec9fcdSqs148142 if (config & CFG_VMAC_TX_CRC_INSERT) 833dec9fcdSqs148142 cfg.bits.crc_insert = 1; 843dec9fcdSqs148142 if (config & CFG_VMAC_TX_PAD) 853dec9fcdSqs148142 cfg.bits.tx_pad = 1; 863dec9fcdSqs148142 if (max_frame_length) 873dec9fcdSqs148142 cfg.bits.tx_max_frame_length = max_frame_length; 883dec9fcdSqs148142 break; 893dec9fcdSqs148142 case DISABLE: 903dec9fcdSqs148142 if (config & CFG_VMAC_TX_EN) 913dec9fcdSqs148142 cfg.bits.tx_en = 0; 923dec9fcdSqs148142 if (config & CFG_VMAC_TX_CRC_INSERT) 933dec9fcdSqs148142 cfg.bits.crc_insert = 0; 943dec9fcdSqs148142 if (config & CFG_VMAC_TX_PAD) 953dec9fcdSqs148142 cfg.bits.tx_pad = 0; 963dec9fcdSqs148142 break; 973dec9fcdSqs148142 case INIT: 983dec9fcdSqs148142 if (config & CFG_VMAC_TX_EN) 993dec9fcdSqs148142 cfg.bits.tx_en = 1; 1003dec9fcdSqs148142 else 1013dec9fcdSqs148142 cfg.bits.tx_en = 0; 1023dec9fcdSqs148142 1033dec9fcdSqs148142 if (config & CFG_VMAC_TX_CRC_INSERT) 1043dec9fcdSqs148142 cfg.bits.crc_insert = 1; 1053dec9fcdSqs148142 else 1063dec9fcdSqs148142 cfg.bits.crc_insert = 0; 1073dec9fcdSqs148142 1083dec9fcdSqs148142 if (config & CFG_VMAC_TX_PAD) 1093dec9fcdSqs148142 cfg.bits.tx_pad = 1; 1103dec9fcdSqs148142 else 1113dec9fcdSqs148142 cfg.bits.tx_pad = 0; 1123dec9fcdSqs148142 1133dec9fcdSqs148142 if (max_frame_length) 1143dec9fcdSqs148142 cfg.bits.tx_max_frame_length = max_frame_length; 1153dec9fcdSqs148142 1163dec9fcdSqs148142 break; 1173dec9fcdSqs148142 default: 1183dec9fcdSqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL, 1193dec9fcdSqs148142 " hpi_vmac_tx_config Invalid Input: op <0x%x>", op)); 1203dec9fcdSqs148142 return (HPI_FAILURE); 1213dec9fcdSqs148142 } 1223dec9fcdSqs148142 1233dec9fcdSqs148142 HXGE_REG_WR64(handle, VMAC_TX_CFG, cfg.value); 1243dec9fcdSqs148142 1253dec9fcdSqs148142 return (HPI_SUCCESS); 1263dec9fcdSqs148142 } 1273dec9fcdSqs148142 1283dec9fcdSqs148142 hpi_status_t 129*b83cd2c3SMichael Speer hpi_vmac_rx_set_framesize(hpi_handle_t handle, uint16_t max_frame_length) 130*b83cd2c3SMichael Speer { 131*b83cd2c3SMichael Speer vmac_rx_cfg_t cfg; 132*b83cd2c3SMichael Speer uint16_t fsize; 133*b83cd2c3SMichael Speer 134*b83cd2c3SMichael Speer HXGE_REG_RD64(handle, VMAC_RX_CFG, &cfg.value); 135*b83cd2c3SMichael Speer 136*b83cd2c3SMichael Speer /* 137*b83cd2c3SMichael Speer * HW team not sure setting framesize to 0 is problematic 138*b83cd2c3SMichael Speer * or not. 139*b83cd2c3SMichael Speer */ 140*b83cd2c3SMichael Speer if (max_frame_length == 0) 141*b83cd2c3SMichael Speer fsize = 1; 142*b83cd2c3SMichael Speer else 143*b83cd2c3SMichael Speer fsize = max_frame_length; 144*b83cd2c3SMichael Speer 145*b83cd2c3SMichael Speer cfg.bits.rx_max_frame_length = fsize; 146*b83cd2c3SMichael Speer 147*b83cd2c3SMichael Speer HXGE_REG_WR64(handle, VMAC_RX_CFG, cfg.value); 148*b83cd2c3SMichael Speer 149*b83cd2c3SMichael Speer return (HPI_SUCCESS); 150*b83cd2c3SMichael Speer } 151*b83cd2c3SMichael Speer 152*b83cd2c3SMichael Speer hpi_status_t 1533dec9fcdSqs148142 hpi_vmac_rx_config(hpi_handle_t handle, config_op_t op, uint64_t config, 1543dec9fcdSqs148142 uint16_t max_frame_length) 1553dec9fcdSqs148142 { 1563dec9fcdSqs148142 vmac_rx_cfg_t cfg; 1573dec9fcdSqs148142 1583dec9fcdSqs148142 if (config == 0) { 1593dec9fcdSqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL, 1603dec9fcdSqs148142 " hpi_vmac_rx_config Invalid Input: config <0x%x>", 1613dec9fcdSqs148142 config)); 1623dec9fcdSqs148142 return (HPI_FAILURE); 1633dec9fcdSqs148142 } 1643dec9fcdSqs148142 1653dec9fcdSqs148142 HXGE_REG_RD64(handle, VMAC_RX_CFG, &cfg.value); 1663dec9fcdSqs148142 1673dec9fcdSqs148142 switch (op) { 1683dec9fcdSqs148142 case ENABLE: 1693dec9fcdSqs148142 if (config & CFG_VMAC_RX_EN) 1703dec9fcdSqs148142 cfg.bits.rx_en = 1; 1713dec9fcdSqs148142 if (config & CFG_VMAC_RX_CRC_CHECK_DISABLE) 1723dec9fcdSqs148142 cfg.bits.crc_check_disable = 1; 1733dec9fcdSqs148142 if (config & CFG_VMAC_RX_STRIP_CRC) 1743dec9fcdSqs148142 cfg.bits.strip_crc = 1; 1753dec9fcdSqs148142 if (config & CFG_VMAC_RX_PASS_FLOW_CTRL_FR) 1763dec9fcdSqs148142 cfg.bits.pass_flow_ctrl_fr = 1; 1773dec9fcdSqs148142 if (config & CFG_VMAC_RX_PROMIXCUOUS_GROUP) 1783dec9fcdSqs148142 cfg.bits.promiscuous_group = 1; 1793dec9fcdSqs148142 if (config & CFG_VMAC_RX_PROMISCUOUS_MODE) 1803dec9fcdSqs148142 cfg.bits.promiscuous_mode = 1; 1813dec9fcdSqs148142 if (config & CFG_VMAC_RX_LOOP_BACK) 1823dec9fcdSqs148142 cfg.bits.loopback = 1; 1833dec9fcdSqs148142 break; 1843dec9fcdSqs148142 case DISABLE: 1853dec9fcdSqs148142 if (config & CFG_VMAC_RX_EN) 1863dec9fcdSqs148142 cfg.bits.rx_en = 0; 1873dec9fcdSqs148142 if (config & CFG_VMAC_RX_CRC_CHECK_DISABLE) 1883dec9fcdSqs148142 cfg.bits.crc_check_disable = 0; 1893dec9fcdSqs148142 if (config & CFG_VMAC_RX_STRIP_CRC) 1903dec9fcdSqs148142 cfg.bits.strip_crc = 0; 1913dec9fcdSqs148142 if (config & CFG_VMAC_RX_PASS_FLOW_CTRL_FR) 1923dec9fcdSqs148142 cfg.bits.pass_flow_ctrl_fr = 0; 1933dec9fcdSqs148142 if (config & CFG_VMAC_RX_PROMIXCUOUS_GROUP) 1943dec9fcdSqs148142 cfg.bits.promiscuous_group = 0; 1953dec9fcdSqs148142 if (config & CFG_VMAC_RX_PROMISCUOUS_MODE) 1963dec9fcdSqs148142 cfg.bits.promiscuous_mode = 0; 1973dec9fcdSqs148142 if (config & CFG_VMAC_RX_LOOP_BACK) 1983dec9fcdSqs148142 cfg.bits.loopback = 0; 1993dec9fcdSqs148142 break; 2003dec9fcdSqs148142 case INIT: 2013dec9fcdSqs148142 if (config & CFG_VMAC_RX_EN) 2023dec9fcdSqs148142 cfg.bits.rx_en = 1; 2033dec9fcdSqs148142 else 2043dec9fcdSqs148142 cfg.bits.rx_en = 0; 2053dec9fcdSqs148142 if (config & CFG_VMAC_RX_CRC_CHECK_DISABLE) 2063dec9fcdSqs148142 cfg.bits.crc_check_disable = 1; 2073dec9fcdSqs148142 else 2083dec9fcdSqs148142 cfg.bits.crc_check_disable = 0; 2093dec9fcdSqs148142 if (config & CFG_VMAC_RX_STRIP_CRC) 2103dec9fcdSqs148142 cfg.bits.strip_crc = 1; 2113dec9fcdSqs148142 else 2123dec9fcdSqs148142 cfg.bits.strip_crc = 0; 2133dec9fcdSqs148142 if (config & CFG_VMAC_RX_PASS_FLOW_CTRL_FR) 2143dec9fcdSqs148142 cfg.bits.pass_flow_ctrl_fr = 1; 2153dec9fcdSqs148142 else 2163dec9fcdSqs148142 cfg.bits.pass_flow_ctrl_fr = 0; 2173dec9fcdSqs148142 if (config & CFG_VMAC_RX_PROMIXCUOUS_GROUP) 2183dec9fcdSqs148142 cfg.bits.promiscuous_group = 1; 2193dec9fcdSqs148142 else 2203dec9fcdSqs148142 cfg.bits.promiscuous_group = 0; 2213dec9fcdSqs148142 if (config & CFG_VMAC_RX_PROMISCUOUS_MODE) 2223dec9fcdSqs148142 cfg.bits.promiscuous_mode = 1; 2233dec9fcdSqs148142 else 2243dec9fcdSqs148142 cfg.bits.promiscuous_mode = 0; 2253dec9fcdSqs148142 if (config & CFG_VMAC_RX_LOOP_BACK) 2263dec9fcdSqs148142 cfg.bits.loopback = 1; 2273dec9fcdSqs148142 else 2283dec9fcdSqs148142 cfg.bits.loopback = 0; 2293dec9fcdSqs148142 2303dec9fcdSqs148142 break; 2313dec9fcdSqs148142 default: 2323dec9fcdSqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL, 2333dec9fcdSqs148142 " hpi_vmac_rx_config Invalid Input: op <0x%x>", op)); 2343dec9fcdSqs148142 return (HPI_FAILURE); 2353dec9fcdSqs148142 } 2363dec9fcdSqs148142 2373dec9fcdSqs148142 if (max_frame_length) 2383dec9fcdSqs148142 cfg.bits.rx_max_frame_length = max_frame_length; 2393dec9fcdSqs148142 2403dec9fcdSqs148142 HXGE_REG_WR64(handle, VMAC_RX_CFG, cfg.value); 2413dec9fcdSqs148142 2423dec9fcdSqs148142 return (HPI_SUCCESS); 2433dec9fcdSqs148142 } 2443dec9fcdSqs148142 2453dec9fcdSqs148142 hpi_status_t 2463dec9fcdSqs148142 hpi_vmac_clear_rx_int_stat(hpi_handle_t handle) 2473dec9fcdSqs148142 { 2483dec9fcdSqs148142 uint64_t offset; 2493dec9fcdSqs148142 2503dec9fcdSqs148142 offset = VMAC_RX_STAT; 2513dec9fcdSqs148142 REG_PIO_WRITE64(handle, offset, HXGE_VMAC_RX_STAT_CLEAR); 2523dec9fcdSqs148142 2533dec9fcdSqs148142 return (HPI_SUCCESS); 2543dec9fcdSqs148142 } 2553dec9fcdSqs148142 2563dec9fcdSqs148142 hpi_status_t 2573dec9fcdSqs148142 hpi_vmac_clear_tx_int_stat(hpi_handle_t handle) 2583dec9fcdSqs148142 { 2593dec9fcdSqs148142 uint64_t offset; 2603dec9fcdSqs148142 2613dec9fcdSqs148142 offset = VMAC_TX_STAT; 2623dec9fcdSqs148142 REG_PIO_WRITE64(handle, offset, HXGE_VMAC_TX_STAT_CLEAR); 2633dec9fcdSqs148142 2643dec9fcdSqs148142 return (HPI_SUCCESS); 2653dec9fcdSqs148142 } 2663dec9fcdSqs148142 2673dec9fcdSqs148142 hpi_status_t 2683dec9fcdSqs148142 hpi_pfc_set_rx_int_stat_mask(hpi_handle_t handle, boolean_t overflow_cnt, 2693dec9fcdSqs148142 boolean_t frame_cnt) 2703dec9fcdSqs148142 { 2713dec9fcdSqs148142 uint64_t offset; 2723dec9fcdSqs148142 uint64_t value = 0; 2733dec9fcdSqs148142 2743dec9fcdSqs148142 if (overflow_cnt) 2753dec9fcdSqs148142 value |= HXGE_VMAC_RX_MASK_OVERFLOW; 2763dec9fcdSqs148142 2773dec9fcdSqs148142 if (frame_cnt) 2783dec9fcdSqs148142 value |= HXGE_VMAC_RX_MASK_FRAME; 2793dec9fcdSqs148142 2803dec9fcdSqs148142 offset = VMAC_RX_MSK; 2813dec9fcdSqs148142 REG_PIO_WRITE64(handle, offset, value); 2823dec9fcdSqs148142 2833dec9fcdSqs148142 return (HPI_SUCCESS); 2843dec9fcdSqs148142 } 2853dec9fcdSqs148142 2863dec9fcdSqs148142 hpi_status_t 2873dec9fcdSqs148142 hpi_pfc_set_tx_int_stat_mask(hpi_handle_t handle, boolean_t overflow_cnt, 2883dec9fcdSqs148142 boolean_t frame_cnt) 2893dec9fcdSqs148142 { 2903dec9fcdSqs148142 uint64_t offset; 2913dec9fcdSqs148142 uint64_t value = 0; 2923dec9fcdSqs148142 uint64_t overflow_mask = 0x6; 2933dec9fcdSqs148142 uint64_t frame_mask = 0x1; 2943dec9fcdSqs148142 2953dec9fcdSqs148142 if (overflow_cnt) 2963dec9fcdSqs148142 value |= overflow_mask; 2973dec9fcdSqs148142 2983dec9fcdSqs148142 if (frame_cnt) 2993dec9fcdSqs148142 value |= frame_mask; 3003dec9fcdSqs148142 3013dec9fcdSqs148142 offset = VMAC_TX_MSK; 3023dec9fcdSqs148142 REG_PIO_WRITE64(handle, offset, value); 3033dec9fcdSqs148142 3043dec9fcdSqs148142 return (HPI_SUCCESS); 3053dec9fcdSqs148142 } 306