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
266864Sqs148142 #include <hxge_impl.h>
276349Sqs148142 #include <hpi_vmac.h>
286349Sqs148142
296349Sqs148142 #define HXGE_VMAC_RX_STAT_CLEAR 0x1ffULL
306349Sqs148142 #define HXGE_VMAC_TX_STAT_CLEAR 0x7ULL
316349Sqs148142 #define HXGE_VMAC_RX_MASK_OVERFLOW 0x1fe
326349Sqs148142 #define HXGE_VMAC_RX_MASK_FRAME 0x1
336349Sqs148142
346349Sqs148142 hpi_status_t
hpi_tx_vmac_reset(hpi_handle_t handle)356349Sqs148142 hpi_tx_vmac_reset(hpi_handle_t handle)
366349Sqs148142 {
376349Sqs148142 vmac_rst_t reset;
386349Sqs148142
396349Sqs148142 HXGE_REG_RD64(handle, VMAC_RST, &(reset.value));
406349Sqs148142
416349Sqs148142 reset.bits.tx_reset = 1;
426349Sqs148142
436349Sqs148142 HXGE_REG_WR64(handle, VMAC_RST, reset.value);
446349Sqs148142
456349Sqs148142 return (HPI_SUCCESS);
466349Sqs148142 }
476349Sqs148142
486349Sqs148142 hpi_status_t
hpi_rx_vmac_reset(hpi_handle_t handle)496349Sqs148142 hpi_rx_vmac_reset(hpi_handle_t handle)
506349Sqs148142 {
516349Sqs148142 vmac_rst_t reset;
526349Sqs148142
536349Sqs148142 HXGE_REG_RD64(handle, VMAC_RST, &(reset.value));
546349Sqs148142
556349Sqs148142 reset.bits.rx_reset = 1;
566349Sqs148142
576349Sqs148142 HXGE_REG_WR64(handle, VMAC_RST, reset.value);
586349Sqs148142
596349Sqs148142 return (HPI_SUCCESS);
606349Sqs148142 }
616349Sqs148142
626349Sqs148142
636349Sqs148142 hpi_status_t
hpi_vmac_tx_config(hpi_handle_t handle,config_op_t op,uint64_t config,uint16_t max_frame_length)646349Sqs148142 hpi_vmac_tx_config(hpi_handle_t handle, config_op_t op, uint64_t config,
656349Sqs148142 uint16_t max_frame_length)
666349Sqs148142 {
676349Sqs148142 vmac_tx_cfg_t cfg;
686349Sqs148142
696349Sqs148142 if (config == 0) {
706349Sqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL,
716349Sqs148142 " hpi_vmac_tx_config Invalid Input: config <0x%x>",
726349Sqs148142 config));
736349Sqs148142 return (HPI_FAILURE);
746349Sqs148142 }
756349Sqs148142
766349Sqs148142 HXGE_REG_RD64(handle, VMAC_TX_CFG, &cfg.value);
776349Sqs148142
786349Sqs148142 switch (op) {
796349Sqs148142 case ENABLE:
806349Sqs148142 if (config & CFG_VMAC_TX_EN)
816349Sqs148142 cfg.bits.tx_en = 1;
826349Sqs148142 if (config & CFG_VMAC_TX_CRC_INSERT)
836349Sqs148142 cfg.bits.crc_insert = 1;
846349Sqs148142 if (config & CFG_VMAC_TX_PAD)
856349Sqs148142 cfg.bits.tx_pad = 1;
866349Sqs148142 if (max_frame_length)
876349Sqs148142 cfg.bits.tx_max_frame_length = max_frame_length;
886349Sqs148142 break;
896349Sqs148142 case DISABLE:
906349Sqs148142 if (config & CFG_VMAC_TX_EN)
916349Sqs148142 cfg.bits.tx_en = 0;
926349Sqs148142 if (config & CFG_VMAC_TX_CRC_INSERT)
936349Sqs148142 cfg.bits.crc_insert = 0;
946349Sqs148142 if (config & CFG_VMAC_TX_PAD)
956349Sqs148142 cfg.bits.tx_pad = 0;
966349Sqs148142 break;
976349Sqs148142 case INIT:
986349Sqs148142 if (config & CFG_VMAC_TX_EN)
996349Sqs148142 cfg.bits.tx_en = 1;
1006349Sqs148142 else
1016349Sqs148142 cfg.bits.tx_en = 0;
1026349Sqs148142
1036349Sqs148142 if (config & CFG_VMAC_TX_CRC_INSERT)
1046349Sqs148142 cfg.bits.crc_insert = 1;
1056349Sqs148142 else
1066349Sqs148142 cfg.bits.crc_insert = 0;
1076349Sqs148142
1086349Sqs148142 if (config & CFG_VMAC_TX_PAD)
1096349Sqs148142 cfg.bits.tx_pad = 1;
1106349Sqs148142 else
1116349Sqs148142 cfg.bits.tx_pad = 0;
1126349Sqs148142
1136349Sqs148142 if (max_frame_length)
1146349Sqs148142 cfg.bits.tx_max_frame_length = max_frame_length;
1156349Sqs148142
1166349Sqs148142 break;
1176349Sqs148142 default:
1186349Sqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL,
1196349Sqs148142 " hpi_vmac_tx_config Invalid Input: op <0x%x>", op));
1206349Sqs148142 return (HPI_FAILURE);
1216349Sqs148142 }
1226349Sqs148142
1236349Sqs148142 HXGE_REG_WR64(handle, VMAC_TX_CFG, cfg.value);
1246349Sqs148142
1256349Sqs148142 return (HPI_SUCCESS);
1266349Sqs148142 }
1276349Sqs148142
1286349Sqs148142 hpi_status_t
hpi_vmac_rx_set_framesize(hpi_handle_t handle,uint16_t max_frame_length)129*8141SMichael.Speer@Sun.COM hpi_vmac_rx_set_framesize(hpi_handle_t handle, uint16_t max_frame_length)
130*8141SMichael.Speer@Sun.COM {
131*8141SMichael.Speer@Sun.COM vmac_rx_cfg_t cfg;
132*8141SMichael.Speer@Sun.COM uint16_t fsize;
133*8141SMichael.Speer@Sun.COM
134*8141SMichael.Speer@Sun.COM HXGE_REG_RD64(handle, VMAC_RX_CFG, &cfg.value);
135*8141SMichael.Speer@Sun.COM
136*8141SMichael.Speer@Sun.COM /*
137*8141SMichael.Speer@Sun.COM * HW team not sure setting framesize to 0 is problematic
138*8141SMichael.Speer@Sun.COM * or not.
139*8141SMichael.Speer@Sun.COM */
140*8141SMichael.Speer@Sun.COM if (max_frame_length == 0)
141*8141SMichael.Speer@Sun.COM fsize = 1;
142*8141SMichael.Speer@Sun.COM else
143*8141SMichael.Speer@Sun.COM fsize = max_frame_length;
144*8141SMichael.Speer@Sun.COM
145*8141SMichael.Speer@Sun.COM cfg.bits.rx_max_frame_length = fsize;
146*8141SMichael.Speer@Sun.COM
147*8141SMichael.Speer@Sun.COM HXGE_REG_WR64(handle, VMAC_RX_CFG, cfg.value);
148*8141SMichael.Speer@Sun.COM
149*8141SMichael.Speer@Sun.COM return (HPI_SUCCESS);
150*8141SMichael.Speer@Sun.COM }
151*8141SMichael.Speer@Sun.COM
152*8141SMichael.Speer@Sun.COM hpi_status_t
hpi_vmac_rx_config(hpi_handle_t handle,config_op_t op,uint64_t config,uint16_t max_frame_length)1536349Sqs148142 hpi_vmac_rx_config(hpi_handle_t handle, config_op_t op, uint64_t config,
1546349Sqs148142 uint16_t max_frame_length)
1556349Sqs148142 {
1566349Sqs148142 vmac_rx_cfg_t cfg;
1576349Sqs148142
1586349Sqs148142 if (config == 0) {
1596349Sqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL,
1606349Sqs148142 " hpi_vmac_rx_config Invalid Input: config <0x%x>",
1616349Sqs148142 config));
1626349Sqs148142 return (HPI_FAILURE);
1636349Sqs148142 }
1646349Sqs148142
1656349Sqs148142 HXGE_REG_RD64(handle, VMAC_RX_CFG, &cfg.value);
1666349Sqs148142
1676349Sqs148142 switch (op) {
1686349Sqs148142 case ENABLE:
1696349Sqs148142 if (config & CFG_VMAC_RX_EN)
1706349Sqs148142 cfg.bits.rx_en = 1;
1716349Sqs148142 if (config & CFG_VMAC_RX_CRC_CHECK_DISABLE)
1726349Sqs148142 cfg.bits.crc_check_disable = 1;
1736349Sqs148142 if (config & CFG_VMAC_RX_STRIP_CRC)
1746349Sqs148142 cfg.bits.strip_crc = 1;
1756349Sqs148142 if (config & CFG_VMAC_RX_PASS_FLOW_CTRL_FR)
1766349Sqs148142 cfg.bits.pass_flow_ctrl_fr = 1;
1776349Sqs148142 if (config & CFG_VMAC_RX_PROMIXCUOUS_GROUP)
1786349Sqs148142 cfg.bits.promiscuous_group = 1;
1796349Sqs148142 if (config & CFG_VMAC_RX_PROMISCUOUS_MODE)
1806349Sqs148142 cfg.bits.promiscuous_mode = 1;
1816349Sqs148142 if (config & CFG_VMAC_RX_LOOP_BACK)
1826349Sqs148142 cfg.bits.loopback = 1;
1836349Sqs148142 break;
1846349Sqs148142 case DISABLE:
1856349Sqs148142 if (config & CFG_VMAC_RX_EN)
1866349Sqs148142 cfg.bits.rx_en = 0;
1876349Sqs148142 if (config & CFG_VMAC_RX_CRC_CHECK_DISABLE)
1886349Sqs148142 cfg.bits.crc_check_disable = 0;
1896349Sqs148142 if (config & CFG_VMAC_RX_STRIP_CRC)
1906349Sqs148142 cfg.bits.strip_crc = 0;
1916349Sqs148142 if (config & CFG_VMAC_RX_PASS_FLOW_CTRL_FR)
1926349Sqs148142 cfg.bits.pass_flow_ctrl_fr = 0;
1936349Sqs148142 if (config & CFG_VMAC_RX_PROMIXCUOUS_GROUP)
1946349Sqs148142 cfg.bits.promiscuous_group = 0;
1956349Sqs148142 if (config & CFG_VMAC_RX_PROMISCUOUS_MODE)
1966349Sqs148142 cfg.bits.promiscuous_mode = 0;
1976349Sqs148142 if (config & CFG_VMAC_RX_LOOP_BACK)
1986349Sqs148142 cfg.bits.loopback = 0;
1996349Sqs148142 break;
2006349Sqs148142 case INIT:
2016349Sqs148142 if (config & CFG_VMAC_RX_EN)
2026349Sqs148142 cfg.bits.rx_en = 1;
2036349Sqs148142 else
2046349Sqs148142 cfg.bits.rx_en = 0;
2056349Sqs148142 if (config & CFG_VMAC_RX_CRC_CHECK_DISABLE)
2066349Sqs148142 cfg.bits.crc_check_disable = 1;
2076349Sqs148142 else
2086349Sqs148142 cfg.bits.crc_check_disable = 0;
2096349Sqs148142 if (config & CFG_VMAC_RX_STRIP_CRC)
2106349Sqs148142 cfg.bits.strip_crc = 1;
2116349Sqs148142 else
2126349Sqs148142 cfg.bits.strip_crc = 0;
2136349Sqs148142 if (config & CFG_VMAC_RX_PASS_FLOW_CTRL_FR)
2146349Sqs148142 cfg.bits.pass_flow_ctrl_fr = 1;
2156349Sqs148142 else
2166349Sqs148142 cfg.bits.pass_flow_ctrl_fr = 0;
2176349Sqs148142 if (config & CFG_VMAC_RX_PROMIXCUOUS_GROUP)
2186349Sqs148142 cfg.bits.promiscuous_group = 1;
2196349Sqs148142 else
2206349Sqs148142 cfg.bits.promiscuous_group = 0;
2216349Sqs148142 if (config & CFG_VMAC_RX_PROMISCUOUS_MODE)
2226349Sqs148142 cfg.bits.promiscuous_mode = 1;
2236349Sqs148142 else
2246349Sqs148142 cfg.bits.promiscuous_mode = 0;
2256349Sqs148142 if (config & CFG_VMAC_RX_LOOP_BACK)
2266349Sqs148142 cfg.bits.loopback = 1;
2276349Sqs148142 else
2286349Sqs148142 cfg.bits.loopback = 0;
2296349Sqs148142
2306349Sqs148142 break;
2316349Sqs148142 default:
2326349Sqs148142 HPI_ERROR_MSG((handle.function, HPI_ERR_CTL,
2336349Sqs148142 " hpi_vmac_rx_config Invalid Input: op <0x%x>", op));
2346349Sqs148142 return (HPI_FAILURE);
2356349Sqs148142 }
2366349Sqs148142
2376349Sqs148142 if (max_frame_length)
2386349Sqs148142 cfg.bits.rx_max_frame_length = max_frame_length;
2396349Sqs148142
2406349Sqs148142 HXGE_REG_WR64(handle, VMAC_RX_CFG, cfg.value);
2416349Sqs148142
2426349Sqs148142 return (HPI_SUCCESS);
2436349Sqs148142 }
2446349Sqs148142
2456349Sqs148142 hpi_status_t
hpi_vmac_clear_rx_int_stat(hpi_handle_t handle)2466349Sqs148142 hpi_vmac_clear_rx_int_stat(hpi_handle_t handle)
2476349Sqs148142 {
2486349Sqs148142 uint64_t offset;
2496349Sqs148142
2506349Sqs148142 offset = VMAC_RX_STAT;
2516349Sqs148142 REG_PIO_WRITE64(handle, offset, HXGE_VMAC_RX_STAT_CLEAR);
2526349Sqs148142
2536349Sqs148142 return (HPI_SUCCESS);
2546349Sqs148142 }
2556349Sqs148142
2566349Sqs148142 hpi_status_t
hpi_vmac_clear_tx_int_stat(hpi_handle_t handle)2576349Sqs148142 hpi_vmac_clear_tx_int_stat(hpi_handle_t handle)
2586349Sqs148142 {
2596349Sqs148142 uint64_t offset;
2606349Sqs148142
2616349Sqs148142 offset = VMAC_TX_STAT;
2626349Sqs148142 REG_PIO_WRITE64(handle, offset, HXGE_VMAC_TX_STAT_CLEAR);
2636349Sqs148142
2646349Sqs148142 return (HPI_SUCCESS);
2656349Sqs148142 }
2666349Sqs148142
2676349Sqs148142 hpi_status_t
hpi_pfc_set_rx_int_stat_mask(hpi_handle_t handle,boolean_t overflow_cnt,boolean_t frame_cnt)2686349Sqs148142 hpi_pfc_set_rx_int_stat_mask(hpi_handle_t handle, boolean_t overflow_cnt,
2696349Sqs148142 boolean_t frame_cnt)
2706349Sqs148142 {
2716349Sqs148142 uint64_t offset;
2726349Sqs148142 uint64_t value = 0;
2736349Sqs148142
2746349Sqs148142 if (overflow_cnt)
2756349Sqs148142 value |= HXGE_VMAC_RX_MASK_OVERFLOW;
2766349Sqs148142
2776349Sqs148142 if (frame_cnt)
2786349Sqs148142 value |= HXGE_VMAC_RX_MASK_FRAME;
2796349Sqs148142
2806349Sqs148142 offset = VMAC_RX_MSK;
2816349Sqs148142 REG_PIO_WRITE64(handle, offset, value);
2826349Sqs148142
2836349Sqs148142 return (HPI_SUCCESS);
2846349Sqs148142 }
2856349Sqs148142
2866349Sqs148142 hpi_status_t
hpi_pfc_set_tx_int_stat_mask(hpi_handle_t handle,boolean_t overflow_cnt,boolean_t frame_cnt)2876349Sqs148142 hpi_pfc_set_tx_int_stat_mask(hpi_handle_t handle, boolean_t overflow_cnt,
2886349Sqs148142 boolean_t frame_cnt)
2896349Sqs148142 {
2906349Sqs148142 uint64_t offset;
2916349Sqs148142 uint64_t value = 0;
2926349Sqs148142 uint64_t overflow_mask = 0x6;
2936349Sqs148142 uint64_t frame_mask = 0x1;
2946349Sqs148142
2956349Sqs148142 if (overflow_cnt)
2966349Sqs148142 value |= overflow_mask;
2976349Sqs148142
2986349Sqs148142 if (frame_cnt)
2996349Sqs148142 value |= frame_mask;
3006349Sqs148142
3016349Sqs148142 offset = VMAC_TX_MSK;
3026349Sqs148142 REG_PIO_WRITE64(handle, offset, value);
3036349Sqs148142
3046349Sqs148142 return (HPI_SUCCESS);
3056349Sqs148142 }
306