18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * AMD 10Gb Ethernet driver 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * This file is available to you under your choice of the following two 58c2ecf20Sopenharmony_ci * licenses: 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * License 1: GPLv2 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * This file is free software; you may copy, redistribute and/or modify 128c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by 138c2ecf20Sopenharmony_ci * the Free Software Foundation, either version 2 of the License, or (at 148c2ecf20Sopenharmony_ci * your option) any later version. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * This file is distributed in the hope that it will be useful, but 178c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 188c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 198c2ecf20Sopenharmony_ci * General Public License for more details. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License 228c2ecf20Sopenharmony_ci * along with this program. If not, see <http://www.gnu.org/licenses/>. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * This file incorporates work covered by the following copyright and 258c2ecf20Sopenharmony_ci * permission notice: 268c2ecf20Sopenharmony_ci * The Synopsys DWC ETHER XGMAC Software Driver and documentation 278c2ecf20Sopenharmony_ci * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 288c2ecf20Sopenharmony_ci * Inc. unless otherwise expressly agreed to in writing between Synopsys 298c2ecf20Sopenharmony_ci * and you. 308c2ecf20Sopenharmony_ci * 318c2ecf20Sopenharmony_ci * The Software IS NOT an item of Licensed Software or Licensed Product 328c2ecf20Sopenharmony_ci * under any End User Software License Agreement or Agreement for Licensed 338c2ecf20Sopenharmony_ci * Product with Synopsys or any supplement thereto. Permission is hereby 348c2ecf20Sopenharmony_ci * granted, free of charge, to any person obtaining a copy of this software 358c2ecf20Sopenharmony_ci * annotated with this license and the Software, to deal in the Software 368c2ecf20Sopenharmony_ci * without restriction, including without limitation the rights to use, 378c2ecf20Sopenharmony_ci * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 388c2ecf20Sopenharmony_ci * of the Software, and to permit persons to whom the Software is furnished 398c2ecf20Sopenharmony_ci * to do so, subject to the following conditions: 408c2ecf20Sopenharmony_ci * 418c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included 428c2ecf20Sopenharmony_ci * in all copies or substantial portions of the Software. 438c2ecf20Sopenharmony_ci * 448c2ecf20Sopenharmony_ci * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 458c2ecf20Sopenharmony_ci * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 468c2ecf20Sopenharmony_ci * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 478c2ecf20Sopenharmony_ci * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 488c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 498c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 508c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 518c2ecf20Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 528c2ecf20Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 538c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 548c2ecf20Sopenharmony_ci * THE POSSIBILITY OF SUCH DAMAGE. 558c2ecf20Sopenharmony_ci * 568c2ecf20Sopenharmony_ci * 578c2ecf20Sopenharmony_ci * License 2: Modified BSD 588c2ecf20Sopenharmony_ci * 598c2ecf20Sopenharmony_ci * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 608c2ecf20Sopenharmony_ci * All rights reserved. 618c2ecf20Sopenharmony_ci * 628c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 638c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 648c2ecf20Sopenharmony_ci * * Redistributions of source code must retain the above copyright 658c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 668c2ecf20Sopenharmony_ci * * Redistributions in binary form must reproduce the above copyright 678c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 688c2ecf20Sopenharmony_ci * documentation and/or other materials provided with the distribution. 698c2ecf20Sopenharmony_ci * * Neither the name of Advanced Micro Devices, Inc. nor the 708c2ecf20Sopenharmony_ci * names of its contributors may be used to endorse or promote products 718c2ecf20Sopenharmony_ci * derived from this software without specific prior written permission. 728c2ecf20Sopenharmony_ci * 738c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 748c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 758c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 768c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 778c2ecf20Sopenharmony_ci * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 788c2ecf20Sopenharmony_ci * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 798c2ecf20Sopenharmony_ci * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 808c2ecf20Sopenharmony_ci * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 818c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 828c2ecf20Sopenharmony_ci * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 838c2ecf20Sopenharmony_ci * 848c2ecf20Sopenharmony_ci * This file incorporates work covered by the following copyright and 858c2ecf20Sopenharmony_ci * permission notice: 868c2ecf20Sopenharmony_ci * The Synopsys DWC ETHER XGMAC Software Driver and documentation 878c2ecf20Sopenharmony_ci * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 888c2ecf20Sopenharmony_ci * Inc. unless otherwise expressly agreed to in writing between Synopsys 898c2ecf20Sopenharmony_ci * and you. 908c2ecf20Sopenharmony_ci * 918c2ecf20Sopenharmony_ci * The Software IS NOT an item of Licensed Software or Licensed Product 928c2ecf20Sopenharmony_ci * under any End User Software License Agreement or Agreement for Licensed 938c2ecf20Sopenharmony_ci * Product with Synopsys or any supplement thereto. Permission is hereby 948c2ecf20Sopenharmony_ci * granted, free of charge, to any person obtaining a copy of this software 958c2ecf20Sopenharmony_ci * annotated with this license and the Software, to deal in the Software 968c2ecf20Sopenharmony_ci * without restriction, including without limitation the rights to use, 978c2ecf20Sopenharmony_ci * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 988c2ecf20Sopenharmony_ci * of the Software, and to permit persons to whom the Software is furnished 998c2ecf20Sopenharmony_ci * to do so, subject to the following conditions: 1008c2ecf20Sopenharmony_ci * 1018c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included 1028c2ecf20Sopenharmony_ci * in all copies or substantial portions of the Software. 1038c2ecf20Sopenharmony_ci * 1048c2ecf20Sopenharmony_ci * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 1058c2ecf20Sopenharmony_ci * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1068c2ecf20Sopenharmony_ci * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 1078c2ecf20Sopenharmony_ci * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 1088c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1098c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1108c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1118c2ecf20Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1128c2ecf20Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1138c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 1148c2ecf20Sopenharmony_ci * THE POSSIBILITY OF SUCH DAMAGE. 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#include <linux/phy.h> 1188c2ecf20Sopenharmony_ci#include <linux/mdio.h> 1198c2ecf20Sopenharmony_ci#include <linux/clk.h> 1208c2ecf20Sopenharmony_ci#include <linux/bitrev.h> 1218c2ecf20Sopenharmony_ci#include <linux/crc32.h> 1228c2ecf20Sopenharmony_ci#include <linux/crc32poly.h> 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci#include "xgbe.h" 1258c2ecf20Sopenharmony_ci#include "xgbe-common.h" 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistatic inline unsigned int xgbe_get_max_frame(struct xgbe_prv_data *pdata) 1288c2ecf20Sopenharmony_ci{ 1298c2ecf20Sopenharmony_ci return pdata->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; 1308c2ecf20Sopenharmony_ci} 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_cistatic unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata, 1338c2ecf20Sopenharmony_ci unsigned int usec) 1348c2ecf20Sopenharmony_ci{ 1358c2ecf20Sopenharmony_ci unsigned long rate; 1368c2ecf20Sopenharmony_ci unsigned int ret; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci DBGPR("-->xgbe_usec_to_riwt\n"); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci rate = pdata->sysclk_rate; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci /* 1438c2ecf20Sopenharmony_ci * Convert the input usec value to the watchdog timer value. Each 1448c2ecf20Sopenharmony_ci * watchdog timer value is equivalent to 256 clock cycles. 1458c2ecf20Sopenharmony_ci * Calculate the required value as: 1468c2ecf20Sopenharmony_ci * ( usec * ( system_clock_mhz / 10^6 ) / 256 1478c2ecf20Sopenharmony_ci */ 1488c2ecf20Sopenharmony_ci ret = (usec * (rate / 1000000)) / 256; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci DBGPR("<--xgbe_usec_to_riwt\n"); 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci return ret; 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata, 1568c2ecf20Sopenharmony_ci unsigned int riwt) 1578c2ecf20Sopenharmony_ci{ 1588c2ecf20Sopenharmony_ci unsigned long rate; 1598c2ecf20Sopenharmony_ci unsigned int ret; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci DBGPR("-->xgbe_riwt_to_usec\n"); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci rate = pdata->sysclk_rate; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci /* 1668c2ecf20Sopenharmony_ci * Convert the input watchdog timer value to the usec value. Each 1678c2ecf20Sopenharmony_ci * watchdog timer value is equivalent to 256 clock cycles. 1688c2ecf20Sopenharmony_ci * Calculate the required value as: 1698c2ecf20Sopenharmony_ci * ( riwt * 256 ) / ( system_clock_mhz / 10^6 ) 1708c2ecf20Sopenharmony_ci */ 1718c2ecf20Sopenharmony_ci ret = (riwt * 256) / (rate / 1000000); 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci DBGPR("<--xgbe_riwt_to_usec\n"); 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci return ret; 1768c2ecf20Sopenharmony_ci} 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_cistatic int xgbe_config_pbl_val(struct xgbe_prv_data *pdata) 1798c2ecf20Sopenharmony_ci{ 1808c2ecf20Sopenharmony_ci unsigned int pblx8, pbl; 1818c2ecf20Sopenharmony_ci unsigned int i; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci pblx8 = DMA_PBL_X8_DISABLE; 1848c2ecf20Sopenharmony_ci pbl = pdata->pbl; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci if (pdata->pbl > 32) { 1878c2ecf20Sopenharmony_ci pblx8 = DMA_PBL_X8_ENABLE; 1888c2ecf20Sopenharmony_ci pbl >>= 3; 1898c2ecf20Sopenharmony_ci } 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 1928c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_CR, PBLX8, 1938c2ecf20Sopenharmony_ci pblx8); 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci if (pdata->channel[i]->tx_ring) 1968c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, 1978c2ecf20Sopenharmony_ci PBL, pbl); 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci if (pdata->channel[i]->rx_ring) 2008c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, 2018c2ecf20Sopenharmony_ci PBL, pbl); 2028c2ecf20Sopenharmony_ci } 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci return 0; 2058c2ecf20Sopenharmony_ci} 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_cistatic int xgbe_config_osp_mode(struct xgbe_prv_data *pdata) 2088c2ecf20Sopenharmony_ci{ 2098c2ecf20Sopenharmony_ci unsigned int i; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 2128c2ecf20Sopenharmony_ci if (!pdata->channel[i]->tx_ring) 2138c2ecf20Sopenharmony_ci break; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, OSP, 2168c2ecf20Sopenharmony_ci pdata->tx_osp_mode); 2178c2ecf20Sopenharmony_ci } 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci return 0; 2208c2ecf20Sopenharmony_ci} 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_cistatic int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val) 2238c2ecf20Sopenharmony_ci{ 2248c2ecf20Sopenharmony_ci unsigned int i; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci for (i = 0; i < pdata->rx_q_count; i++) 2278c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val); 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci return 0; 2308c2ecf20Sopenharmony_ci} 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cistatic int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val) 2338c2ecf20Sopenharmony_ci{ 2348c2ecf20Sopenharmony_ci unsigned int i; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci for (i = 0; i < pdata->tx_q_count; i++) 2378c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci return 0; 2408c2ecf20Sopenharmony_ci} 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cistatic int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata, 2438c2ecf20Sopenharmony_ci unsigned int val) 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci unsigned int i; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci for (i = 0; i < pdata->rx_q_count; i++) 2488c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val); 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci return 0; 2518c2ecf20Sopenharmony_ci} 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_cistatic int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata, 2548c2ecf20Sopenharmony_ci unsigned int val) 2558c2ecf20Sopenharmony_ci{ 2568c2ecf20Sopenharmony_ci unsigned int i; 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci for (i = 0; i < pdata->tx_q_count; i++) 2598c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val); 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci return 0; 2628c2ecf20Sopenharmony_ci} 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cistatic int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata) 2658c2ecf20Sopenharmony_ci{ 2668c2ecf20Sopenharmony_ci unsigned int i; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 2698c2ecf20Sopenharmony_ci if (!pdata->channel[i]->rx_ring) 2708c2ecf20Sopenharmony_ci break; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RIWT, RWT, 2738c2ecf20Sopenharmony_ci pdata->rx_riwt); 2748c2ecf20Sopenharmony_ci } 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci return 0; 2778c2ecf20Sopenharmony_ci} 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_cistatic int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata) 2808c2ecf20Sopenharmony_ci{ 2818c2ecf20Sopenharmony_ci return 0; 2828c2ecf20Sopenharmony_ci} 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_cistatic void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata) 2858c2ecf20Sopenharmony_ci{ 2868c2ecf20Sopenharmony_ci unsigned int i; 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 2898c2ecf20Sopenharmony_ci if (!pdata->channel[i]->rx_ring) 2908c2ecf20Sopenharmony_ci break; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, RBSZ, 2938c2ecf20Sopenharmony_ci pdata->rx_buf_size); 2948c2ecf20Sopenharmony_ci } 2958c2ecf20Sopenharmony_ci} 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_cistatic void xgbe_config_tso_mode(struct xgbe_prv_data *pdata) 2988c2ecf20Sopenharmony_ci{ 2998c2ecf20Sopenharmony_ci unsigned int i; 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 3028c2ecf20Sopenharmony_ci if (!pdata->channel[i]->tx_ring) 3038c2ecf20Sopenharmony_ci break; 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, TSE, 1); 3068c2ecf20Sopenharmony_ci } 3078c2ecf20Sopenharmony_ci} 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_cistatic void xgbe_config_sph_mode(struct xgbe_prv_data *pdata) 3108c2ecf20Sopenharmony_ci{ 3118c2ecf20Sopenharmony_ci unsigned int i; 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 3148c2ecf20Sopenharmony_ci if (!pdata->channel[i]->rx_ring) 3158c2ecf20Sopenharmony_ci break; 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_CR, SPH, 1); 3188c2ecf20Sopenharmony_ci } 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, HDSMS, XGBE_SPH_HDSMS_SIZE); 3218c2ecf20Sopenharmony_ci} 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_cistatic int xgbe_write_rss_reg(struct xgbe_prv_data *pdata, unsigned int type, 3248c2ecf20Sopenharmony_ci unsigned int index, unsigned int val) 3258c2ecf20Sopenharmony_ci{ 3268c2ecf20Sopenharmony_ci unsigned int wait; 3278c2ecf20Sopenharmony_ci int ret = 0; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci mutex_lock(&pdata->rss_mutex); 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci if (XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB)) { 3328c2ecf20Sopenharmony_ci ret = -EBUSY; 3338c2ecf20Sopenharmony_ci goto unlock; 3348c2ecf20Sopenharmony_ci } 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_RSSDR, val); 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, RSSIA, index); 3398c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, ADDRT, type); 3408c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, CT, 0); 3418c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, OB, 1); 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci wait = 1000; 3448c2ecf20Sopenharmony_ci while (wait--) { 3458c2ecf20Sopenharmony_ci if (!XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB)) 3468c2ecf20Sopenharmony_ci goto unlock; 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci usleep_range(1000, 1500); 3498c2ecf20Sopenharmony_ci } 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci ret = -EBUSY; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ciunlock: 3548c2ecf20Sopenharmony_ci mutex_unlock(&pdata->rss_mutex); 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci return ret; 3578c2ecf20Sopenharmony_ci} 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_cistatic int xgbe_write_rss_hash_key(struct xgbe_prv_data *pdata) 3608c2ecf20Sopenharmony_ci{ 3618c2ecf20Sopenharmony_ci unsigned int key_regs = sizeof(pdata->rss_key) / sizeof(u32); 3628c2ecf20Sopenharmony_ci unsigned int *key = (unsigned int *)&pdata->rss_key; 3638c2ecf20Sopenharmony_ci int ret; 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci while (key_regs--) { 3668c2ecf20Sopenharmony_ci ret = xgbe_write_rss_reg(pdata, XGBE_RSS_HASH_KEY_TYPE, 3678c2ecf20Sopenharmony_ci key_regs, *key++); 3688c2ecf20Sopenharmony_ci if (ret) 3698c2ecf20Sopenharmony_ci return ret; 3708c2ecf20Sopenharmony_ci } 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci return 0; 3738c2ecf20Sopenharmony_ci} 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_cistatic int xgbe_write_rss_lookup_table(struct xgbe_prv_data *pdata) 3768c2ecf20Sopenharmony_ci{ 3778c2ecf20Sopenharmony_ci unsigned int i; 3788c2ecf20Sopenharmony_ci int ret; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) { 3818c2ecf20Sopenharmony_ci ret = xgbe_write_rss_reg(pdata, 3828c2ecf20Sopenharmony_ci XGBE_RSS_LOOKUP_TABLE_TYPE, i, 3838c2ecf20Sopenharmony_ci pdata->rss_table[i]); 3848c2ecf20Sopenharmony_ci if (ret) 3858c2ecf20Sopenharmony_ci return ret; 3868c2ecf20Sopenharmony_ci } 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci return 0; 3898c2ecf20Sopenharmony_ci} 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_cistatic int xgbe_set_rss_hash_key(struct xgbe_prv_data *pdata, const u8 *key) 3928c2ecf20Sopenharmony_ci{ 3938c2ecf20Sopenharmony_ci memcpy(pdata->rss_key, key, sizeof(pdata->rss_key)); 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci return xgbe_write_rss_hash_key(pdata); 3968c2ecf20Sopenharmony_ci} 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_cistatic int xgbe_set_rss_lookup_table(struct xgbe_prv_data *pdata, 3998c2ecf20Sopenharmony_ci const u32 *table) 4008c2ecf20Sopenharmony_ci{ 4018c2ecf20Sopenharmony_ci unsigned int i; 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) 4048c2ecf20Sopenharmony_ci XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH, table[i]); 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci return xgbe_write_rss_lookup_table(pdata); 4078c2ecf20Sopenharmony_ci} 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_cistatic int xgbe_enable_rss(struct xgbe_prv_data *pdata) 4108c2ecf20Sopenharmony_ci{ 4118c2ecf20Sopenharmony_ci int ret; 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci if (!pdata->hw_feat.rss) 4148c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci /* Program the hash key */ 4178c2ecf20Sopenharmony_ci ret = xgbe_write_rss_hash_key(pdata); 4188c2ecf20Sopenharmony_ci if (ret) 4198c2ecf20Sopenharmony_ci return ret; 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci /* Program the lookup table */ 4228c2ecf20Sopenharmony_ci ret = xgbe_write_rss_lookup_table(pdata); 4238c2ecf20Sopenharmony_ci if (ret) 4248c2ecf20Sopenharmony_ci return ret; 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci /* Set the RSS options */ 4278c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_RSSCR, pdata->rss_options); 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci /* Enable RSS */ 4308c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 1); 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci return 0; 4338c2ecf20Sopenharmony_ci} 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_cistatic int xgbe_disable_rss(struct xgbe_prv_data *pdata) 4368c2ecf20Sopenharmony_ci{ 4378c2ecf20Sopenharmony_ci if (!pdata->hw_feat.rss) 4388c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 0); 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci return 0; 4438c2ecf20Sopenharmony_ci} 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_cistatic void xgbe_config_rss(struct xgbe_prv_data *pdata) 4468c2ecf20Sopenharmony_ci{ 4478c2ecf20Sopenharmony_ci int ret; 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_ci if (!pdata->hw_feat.rss) 4508c2ecf20Sopenharmony_ci return; 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci if (pdata->netdev->features & NETIF_F_RXHASH) 4538c2ecf20Sopenharmony_ci ret = xgbe_enable_rss(pdata); 4548c2ecf20Sopenharmony_ci else 4558c2ecf20Sopenharmony_ci ret = xgbe_disable_rss(pdata); 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci if (ret) 4588c2ecf20Sopenharmony_ci netdev_err(pdata->netdev, 4598c2ecf20Sopenharmony_ci "error configuring RSS, RSS disabled\n"); 4608c2ecf20Sopenharmony_ci} 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_cistatic bool xgbe_is_pfc_queue(struct xgbe_prv_data *pdata, 4638c2ecf20Sopenharmony_ci unsigned int queue) 4648c2ecf20Sopenharmony_ci{ 4658c2ecf20Sopenharmony_ci unsigned int prio, tc; 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) { 4688c2ecf20Sopenharmony_ci /* Does this queue handle the priority? */ 4698c2ecf20Sopenharmony_ci if (pdata->prio2q_map[prio] != queue) 4708c2ecf20Sopenharmony_ci continue; 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci /* Get the Traffic Class for this priority */ 4738c2ecf20Sopenharmony_ci tc = pdata->ets->prio_tc[prio]; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci /* Check if PFC is enabled for this traffic class */ 4768c2ecf20Sopenharmony_ci if (pdata->pfc->pfc_en & (1 << tc)) 4778c2ecf20Sopenharmony_ci return true; 4788c2ecf20Sopenharmony_ci } 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci return false; 4818c2ecf20Sopenharmony_ci} 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_cistatic void xgbe_set_vxlan_id(struct xgbe_prv_data *pdata) 4848c2ecf20Sopenharmony_ci{ 4858c2ecf20Sopenharmony_ci /* Program the VXLAN port */ 4868c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TIR, TNID, pdata->vxlan_port); 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, "VXLAN tunnel id set to %hx\n", 4898c2ecf20Sopenharmony_ci pdata->vxlan_port); 4908c2ecf20Sopenharmony_ci} 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_cistatic void xgbe_enable_vxlan(struct xgbe_prv_data *pdata) 4938c2ecf20Sopenharmony_ci{ 4948c2ecf20Sopenharmony_ci if (!pdata->hw_feat.vxn) 4958c2ecf20Sopenharmony_ci return; 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci /* Program the VXLAN port */ 4988c2ecf20Sopenharmony_ci xgbe_set_vxlan_id(pdata); 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci /* Allow for IPv6/UDP zero-checksum VXLAN packets */ 5018c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VUCC, 1); 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci /* Enable VXLAN tunneling mode */ 5048c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TCR, VNM, 0); 5058c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TCR, VNE, 1); 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, "VXLAN acceleration enabled\n"); 5088c2ecf20Sopenharmony_ci} 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_cistatic void xgbe_disable_vxlan(struct xgbe_prv_data *pdata) 5118c2ecf20Sopenharmony_ci{ 5128c2ecf20Sopenharmony_ci if (!pdata->hw_feat.vxn) 5138c2ecf20Sopenharmony_ci return; 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci /* Disable tunneling mode */ 5168c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TCR, VNE, 0); 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci /* Clear IPv6/UDP zero-checksum VXLAN packets setting */ 5198c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VUCC, 0); 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci /* Clear the VXLAN port */ 5228c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TIR, TNID, 0); 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, "VXLAN acceleration disabled\n"); 5258c2ecf20Sopenharmony_ci} 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_cistatic unsigned int xgbe_get_fc_queue_count(struct xgbe_prv_data *pdata) 5288c2ecf20Sopenharmony_ci{ 5298c2ecf20Sopenharmony_ci unsigned int max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES; 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci /* From MAC ver 30H the TFCR is per priority, instead of per queue */ 5328c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) >= 0x30) 5338c2ecf20Sopenharmony_ci return max_q_count; 5348c2ecf20Sopenharmony_ci else 5358c2ecf20Sopenharmony_ci return min_t(unsigned int, pdata->tx_q_count, max_q_count); 5368c2ecf20Sopenharmony_ci} 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_cistatic int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata) 5398c2ecf20Sopenharmony_ci{ 5408c2ecf20Sopenharmony_ci unsigned int reg, reg_val; 5418c2ecf20Sopenharmony_ci unsigned int i, q_count; 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci /* Clear MTL flow control */ 5448c2ecf20Sopenharmony_ci for (i = 0; i < pdata->rx_q_count; i++) 5458c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0); 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci /* Clear MAC flow control */ 5488c2ecf20Sopenharmony_ci q_count = xgbe_get_fc_queue_count(pdata); 5498c2ecf20Sopenharmony_ci reg = MAC_Q0TFCR; 5508c2ecf20Sopenharmony_ci for (i = 0; i < q_count; i++) { 5518c2ecf20Sopenharmony_ci reg_val = XGMAC_IOREAD(pdata, reg); 5528c2ecf20Sopenharmony_ci XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0); 5538c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, reg, reg_val); 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci reg += MAC_QTFCR_INC; 5568c2ecf20Sopenharmony_ci } 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci return 0; 5598c2ecf20Sopenharmony_ci} 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_cistatic int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata) 5628c2ecf20Sopenharmony_ci{ 5638c2ecf20Sopenharmony_ci struct ieee_pfc *pfc = pdata->pfc; 5648c2ecf20Sopenharmony_ci struct ieee_ets *ets = pdata->ets; 5658c2ecf20Sopenharmony_ci unsigned int reg, reg_val; 5668c2ecf20Sopenharmony_ci unsigned int i, q_count; 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ci /* Set MTL flow control */ 5698c2ecf20Sopenharmony_ci for (i = 0; i < pdata->rx_q_count; i++) { 5708c2ecf20Sopenharmony_ci unsigned int ehfc = 0; 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci if (pdata->rx_rfd[i]) { 5738c2ecf20Sopenharmony_ci /* Flow control thresholds are established */ 5748c2ecf20Sopenharmony_ci if (pfc && ets) { 5758c2ecf20Sopenharmony_ci if (xgbe_is_pfc_queue(pdata, i)) 5768c2ecf20Sopenharmony_ci ehfc = 1; 5778c2ecf20Sopenharmony_ci } else { 5788c2ecf20Sopenharmony_ci ehfc = 1; 5798c2ecf20Sopenharmony_ci } 5808c2ecf20Sopenharmony_ci } 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, ehfc); 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, 5858c2ecf20Sopenharmony_ci "flow control %s for RXq%u\n", 5868c2ecf20Sopenharmony_ci ehfc ? "enabled" : "disabled", i); 5878c2ecf20Sopenharmony_ci } 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci /* Set MAC flow control */ 5908c2ecf20Sopenharmony_ci q_count = xgbe_get_fc_queue_count(pdata); 5918c2ecf20Sopenharmony_ci reg = MAC_Q0TFCR; 5928c2ecf20Sopenharmony_ci for (i = 0; i < q_count; i++) { 5938c2ecf20Sopenharmony_ci reg_val = XGMAC_IOREAD(pdata, reg); 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci /* Enable transmit flow control */ 5968c2ecf20Sopenharmony_ci XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1); 5978c2ecf20Sopenharmony_ci /* Set pause time */ 5988c2ecf20Sopenharmony_ci XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff); 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, reg, reg_val); 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci reg += MAC_QTFCR_INC; 6038c2ecf20Sopenharmony_ci } 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci return 0; 6068c2ecf20Sopenharmony_ci} 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_cistatic int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata) 6098c2ecf20Sopenharmony_ci{ 6108c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0); 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_ci return 0; 6138c2ecf20Sopenharmony_ci} 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_cistatic int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata) 6168c2ecf20Sopenharmony_ci{ 6178c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1); 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci return 0; 6208c2ecf20Sopenharmony_ci} 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_cistatic int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata) 6238c2ecf20Sopenharmony_ci{ 6248c2ecf20Sopenharmony_ci struct ieee_pfc *pfc = pdata->pfc; 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci if (pdata->tx_pause || (pfc && pfc->pfc_en)) 6278c2ecf20Sopenharmony_ci xgbe_enable_tx_flow_control(pdata); 6288c2ecf20Sopenharmony_ci else 6298c2ecf20Sopenharmony_ci xgbe_disable_tx_flow_control(pdata); 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci return 0; 6328c2ecf20Sopenharmony_ci} 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_cistatic int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata) 6358c2ecf20Sopenharmony_ci{ 6368c2ecf20Sopenharmony_ci struct ieee_pfc *pfc = pdata->pfc; 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci if (pdata->rx_pause || (pfc && pfc->pfc_en)) 6398c2ecf20Sopenharmony_ci xgbe_enable_rx_flow_control(pdata); 6408c2ecf20Sopenharmony_ci else 6418c2ecf20Sopenharmony_ci xgbe_disable_rx_flow_control(pdata); 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci return 0; 6448c2ecf20Sopenharmony_ci} 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_cistatic void xgbe_config_flow_control(struct xgbe_prv_data *pdata) 6478c2ecf20Sopenharmony_ci{ 6488c2ecf20Sopenharmony_ci struct ieee_pfc *pfc = pdata->pfc; 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci xgbe_config_tx_flow_control(pdata); 6518c2ecf20Sopenharmony_ci xgbe_config_rx_flow_control(pdata); 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 6548c2ecf20Sopenharmony_ci (pfc && pfc->pfc_en) ? 1 : 0); 6558c2ecf20Sopenharmony_ci} 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_cistatic void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata) 6588c2ecf20Sopenharmony_ci{ 6598c2ecf20Sopenharmony_ci struct xgbe_channel *channel; 6608c2ecf20Sopenharmony_ci unsigned int i, ver; 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci /* Set the interrupt mode if supported */ 6638c2ecf20Sopenharmony_ci if (pdata->channel_irq_mode) 6648c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, DMA_MR, INTM, 6658c2ecf20Sopenharmony_ci pdata->channel_irq_mode); 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci ver = XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER); 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 6708c2ecf20Sopenharmony_ci channel = pdata->channel[i]; 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_ci /* Clear all the interrupts which are set */ 6738c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, 6748c2ecf20Sopenharmony_ci XGMAC_DMA_IOREAD(channel, DMA_CH_SR)); 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci /* Clear all interrupt enable bits */ 6778c2ecf20Sopenharmony_ci channel->curr_ier = 0; 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci /* Enable following interrupts 6808c2ecf20Sopenharmony_ci * NIE - Normal Interrupt Summary Enable 6818c2ecf20Sopenharmony_ci * AIE - Abnormal Interrupt Summary Enable 6828c2ecf20Sopenharmony_ci * FBEE - Fatal Bus Error Enable 6838c2ecf20Sopenharmony_ci */ 6848c2ecf20Sopenharmony_ci if (ver < 0x21) { 6858c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, NIE20, 1); 6868c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, AIE20, 1); 6878c2ecf20Sopenharmony_ci } else { 6888c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, NIE, 1); 6898c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, AIE, 1); 6908c2ecf20Sopenharmony_ci } 6918c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, FBEE, 1); 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci if (channel->tx_ring) { 6948c2ecf20Sopenharmony_ci /* Enable the following Tx interrupts 6958c2ecf20Sopenharmony_ci * TIE - Transmit Interrupt Enable (unless using 6968c2ecf20Sopenharmony_ci * per channel interrupts in edge triggered 6978c2ecf20Sopenharmony_ci * mode) 6988c2ecf20Sopenharmony_ci */ 6998c2ecf20Sopenharmony_ci if (!pdata->per_channel_irq || pdata->channel_irq_mode) 7008c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, 7018c2ecf20Sopenharmony_ci DMA_CH_IER, TIE, 1); 7028c2ecf20Sopenharmony_ci } 7038c2ecf20Sopenharmony_ci if (channel->rx_ring) { 7048c2ecf20Sopenharmony_ci /* Enable following Rx interrupts 7058c2ecf20Sopenharmony_ci * RBUE - Receive Buffer Unavailable Enable 7068c2ecf20Sopenharmony_ci * RIE - Receive Interrupt Enable (unless using 7078c2ecf20Sopenharmony_ci * per channel interrupts in edge triggered 7088c2ecf20Sopenharmony_ci * mode) 7098c2ecf20Sopenharmony_ci */ 7108c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RBUE, 1); 7118c2ecf20Sopenharmony_ci if (!pdata->per_channel_irq || pdata->channel_irq_mode) 7128c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, 7138c2ecf20Sopenharmony_ci DMA_CH_IER, RIE, 1); 7148c2ecf20Sopenharmony_ci } 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, channel->curr_ier); 7178c2ecf20Sopenharmony_ci } 7188c2ecf20Sopenharmony_ci} 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_cistatic void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata) 7218c2ecf20Sopenharmony_ci{ 7228c2ecf20Sopenharmony_ci unsigned int mtl_q_isr; 7238c2ecf20Sopenharmony_ci unsigned int q_count, i; 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ci q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt); 7268c2ecf20Sopenharmony_ci for (i = 0; i < q_count; i++) { 7278c2ecf20Sopenharmony_ci /* Clear all the interrupts which are set */ 7288c2ecf20Sopenharmony_ci mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR); 7298c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr); 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci /* No MTL interrupts to be enabled */ 7328c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0); 7338c2ecf20Sopenharmony_ci } 7348c2ecf20Sopenharmony_ci} 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_cistatic void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata) 7378c2ecf20Sopenharmony_ci{ 7388c2ecf20Sopenharmony_ci unsigned int mac_ier = 0; 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci /* Enable Timestamp interrupt */ 7418c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1); 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_IER, mac_ier); 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ci /* Enable all counter interrupts */ 7468c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff); 7478c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff); 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_ci /* Enable MDIO single command completion interrupt */ 7508c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_MDIOIER, SNGLCOMPIE, 1); 7518c2ecf20Sopenharmony_ci} 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_cistatic void xgbe_enable_ecc_interrupts(struct xgbe_prv_data *pdata) 7548c2ecf20Sopenharmony_ci{ 7558c2ecf20Sopenharmony_ci unsigned int ecc_isr, ecc_ier = 0; 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_ci if (!pdata->vdata->ecc_support) 7588c2ecf20Sopenharmony_ci return; 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ci /* Clear all the interrupts which are set */ 7618c2ecf20Sopenharmony_ci ecc_isr = XP_IOREAD(pdata, XP_ECC_ISR); 7628c2ecf20Sopenharmony_ci XP_IOWRITE(pdata, XP_ECC_ISR, ecc_isr); 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci /* Enable ECC interrupts */ 7658c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_DED, 1); 7668c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_SEC, 1); 7678c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_DED, 1); 7688c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_SEC, 1); 7698c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_DED, 1); 7708c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_SEC, 1); 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier); 7738c2ecf20Sopenharmony_ci} 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_cistatic void xgbe_disable_ecc_ded(struct xgbe_prv_data *pdata) 7768c2ecf20Sopenharmony_ci{ 7778c2ecf20Sopenharmony_ci unsigned int ecc_ier; 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci ecc_ier = XP_IOREAD(pdata, XP_ECC_IER); 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_ci /* Disable ECC DED interrupts */ 7828c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_DED, 0); 7838c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_DED, 0); 7848c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_DED, 0); 7858c2ecf20Sopenharmony_ci 7868c2ecf20Sopenharmony_ci XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier); 7878c2ecf20Sopenharmony_ci} 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_cistatic void xgbe_disable_ecc_sec(struct xgbe_prv_data *pdata, 7908c2ecf20Sopenharmony_ci enum xgbe_ecc_sec sec) 7918c2ecf20Sopenharmony_ci{ 7928c2ecf20Sopenharmony_ci unsigned int ecc_ier; 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci ecc_ier = XP_IOREAD(pdata, XP_ECC_IER); 7958c2ecf20Sopenharmony_ci 7968c2ecf20Sopenharmony_ci /* Disable ECC SEC interrupt */ 7978c2ecf20Sopenharmony_ci switch (sec) { 7988c2ecf20Sopenharmony_ci case XGBE_ECC_SEC_TX: 7998c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_SEC, 0); 8008c2ecf20Sopenharmony_ci break; 8018c2ecf20Sopenharmony_ci case XGBE_ECC_SEC_RX: 8028c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_SEC, 0); 8038c2ecf20Sopenharmony_ci break; 8048c2ecf20Sopenharmony_ci case XGBE_ECC_SEC_DESC: 8058c2ecf20Sopenharmony_ci XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_SEC, 0); 8068c2ecf20Sopenharmony_ci break; 8078c2ecf20Sopenharmony_ci } 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_ci XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier); 8108c2ecf20Sopenharmony_ci} 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_cistatic int xgbe_set_speed(struct xgbe_prv_data *pdata, int speed) 8138c2ecf20Sopenharmony_ci{ 8148c2ecf20Sopenharmony_ci unsigned int ss; 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci switch (speed) { 8178c2ecf20Sopenharmony_ci case SPEED_1000: 8188c2ecf20Sopenharmony_ci ss = 0x03; 8198c2ecf20Sopenharmony_ci break; 8208c2ecf20Sopenharmony_ci case SPEED_2500: 8218c2ecf20Sopenharmony_ci ss = 0x02; 8228c2ecf20Sopenharmony_ci break; 8238c2ecf20Sopenharmony_ci case SPEED_10000: 8248c2ecf20Sopenharmony_ci ss = 0x00; 8258c2ecf20Sopenharmony_ci break; 8268c2ecf20Sopenharmony_ci default: 8278c2ecf20Sopenharmony_ci return -EINVAL; 8288c2ecf20Sopenharmony_ci } 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) != ss) 8318c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, ss); 8328c2ecf20Sopenharmony_ci 8338c2ecf20Sopenharmony_ci return 0; 8348c2ecf20Sopenharmony_ci} 8358c2ecf20Sopenharmony_ci 8368c2ecf20Sopenharmony_cistatic int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata) 8378c2ecf20Sopenharmony_ci{ 8388c2ecf20Sopenharmony_ci /* Put the VLAN tag in the Rx descriptor */ 8398c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1); 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci /* Don't check the VLAN type */ 8428c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1); 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci /* Check only C-TAG (0x8100) packets */ 8458c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0); 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ci /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */ 8488c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0); 8498c2ecf20Sopenharmony_ci 8508c2ecf20Sopenharmony_ci /* Enable VLAN tag stripping */ 8518c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3); 8528c2ecf20Sopenharmony_ci 8538c2ecf20Sopenharmony_ci return 0; 8548c2ecf20Sopenharmony_ci} 8558c2ecf20Sopenharmony_ci 8568c2ecf20Sopenharmony_cistatic int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata) 8578c2ecf20Sopenharmony_ci{ 8588c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0); 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ci return 0; 8618c2ecf20Sopenharmony_ci} 8628c2ecf20Sopenharmony_ci 8638c2ecf20Sopenharmony_cistatic int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata) 8648c2ecf20Sopenharmony_ci{ 8658c2ecf20Sopenharmony_ci /* Enable VLAN filtering */ 8668c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1); 8678c2ecf20Sopenharmony_ci 8688c2ecf20Sopenharmony_ci /* Enable VLAN Hash Table filtering */ 8698c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1); 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci /* Disable VLAN tag inverse matching */ 8728c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0); 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci /* Only filter on the lower 12-bits of the VLAN tag */ 8758c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1); 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci /* In order for the VLAN Hash Table filtering to be effective, 8788c2ecf20Sopenharmony_ci * the VLAN tag identifier in the VLAN Tag Register must not 8798c2ecf20Sopenharmony_ci * be zero. Set the VLAN tag identifier to "1" to enable the 8808c2ecf20Sopenharmony_ci * VLAN Hash Table filtering. This implies that a VLAN tag of 8818c2ecf20Sopenharmony_ci * 1 will always pass filtering. 8828c2ecf20Sopenharmony_ci */ 8838c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1); 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci return 0; 8868c2ecf20Sopenharmony_ci} 8878c2ecf20Sopenharmony_ci 8888c2ecf20Sopenharmony_cistatic int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata) 8898c2ecf20Sopenharmony_ci{ 8908c2ecf20Sopenharmony_ci /* Disable VLAN filtering */ 8918c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0); 8928c2ecf20Sopenharmony_ci 8938c2ecf20Sopenharmony_ci return 0; 8948c2ecf20Sopenharmony_ci} 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_cistatic u32 xgbe_vid_crc32_le(__le16 vid_le) 8978c2ecf20Sopenharmony_ci{ 8988c2ecf20Sopenharmony_ci u32 crc = ~0; 8998c2ecf20Sopenharmony_ci u32 temp = 0; 9008c2ecf20Sopenharmony_ci unsigned char *data = (unsigned char *)&vid_le; 9018c2ecf20Sopenharmony_ci unsigned char data_byte = 0; 9028c2ecf20Sopenharmony_ci int i, bits; 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_ci bits = get_bitmask_order(VLAN_VID_MASK); 9058c2ecf20Sopenharmony_ci for (i = 0; i < bits; i++) { 9068c2ecf20Sopenharmony_ci if ((i % 8) == 0) 9078c2ecf20Sopenharmony_ci data_byte = data[i / 8]; 9088c2ecf20Sopenharmony_ci 9098c2ecf20Sopenharmony_ci temp = ((crc & 1) ^ data_byte) & 1; 9108c2ecf20Sopenharmony_ci crc >>= 1; 9118c2ecf20Sopenharmony_ci data_byte >>= 1; 9128c2ecf20Sopenharmony_ci 9138c2ecf20Sopenharmony_ci if (temp) 9148c2ecf20Sopenharmony_ci crc ^= CRC32_POLY_LE; 9158c2ecf20Sopenharmony_ci } 9168c2ecf20Sopenharmony_ci 9178c2ecf20Sopenharmony_ci return crc; 9188c2ecf20Sopenharmony_ci} 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_cistatic int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata) 9218c2ecf20Sopenharmony_ci{ 9228c2ecf20Sopenharmony_ci u32 crc; 9238c2ecf20Sopenharmony_ci u16 vid; 9248c2ecf20Sopenharmony_ci __le16 vid_le; 9258c2ecf20Sopenharmony_ci u16 vlan_hash_table = 0; 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci /* Generate the VLAN Hash Table value */ 9288c2ecf20Sopenharmony_ci for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) { 9298c2ecf20Sopenharmony_ci /* Get the CRC32 value of the VLAN ID */ 9308c2ecf20Sopenharmony_ci vid_le = cpu_to_le16(vid); 9318c2ecf20Sopenharmony_ci crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28; 9328c2ecf20Sopenharmony_ci 9338c2ecf20Sopenharmony_ci vlan_hash_table |= (1 << crc); 9348c2ecf20Sopenharmony_ci } 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci /* Set the VLAN Hash Table filtering register */ 9378c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table); 9388c2ecf20Sopenharmony_ci 9398c2ecf20Sopenharmony_ci return 0; 9408c2ecf20Sopenharmony_ci} 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_cistatic int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata, 9438c2ecf20Sopenharmony_ci unsigned int enable) 9448c2ecf20Sopenharmony_ci{ 9458c2ecf20Sopenharmony_ci unsigned int val = enable ? 1 : 0; 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val) 9488c2ecf20Sopenharmony_ci return 0; 9498c2ecf20Sopenharmony_ci 9508c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, "%s promiscuous mode\n", 9518c2ecf20Sopenharmony_ci enable ? "entering" : "leaving"); 9528c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val); 9538c2ecf20Sopenharmony_ci 9548c2ecf20Sopenharmony_ci /* Hardware will still perform VLAN filtering in promiscuous mode */ 9558c2ecf20Sopenharmony_ci if (enable) { 9568c2ecf20Sopenharmony_ci xgbe_disable_rx_vlan_filtering(pdata); 9578c2ecf20Sopenharmony_ci } else { 9588c2ecf20Sopenharmony_ci if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER) 9598c2ecf20Sopenharmony_ci xgbe_enable_rx_vlan_filtering(pdata); 9608c2ecf20Sopenharmony_ci } 9618c2ecf20Sopenharmony_ci 9628c2ecf20Sopenharmony_ci return 0; 9638c2ecf20Sopenharmony_ci} 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_cistatic int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata, 9668c2ecf20Sopenharmony_ci unsigned int enable) 9678c2ecf20Sopenharmony_ci{ 9688c2ecf20Sopenharmony_ci unsigned int val = enable ? 1 : 0; 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_ci if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val) 9718c2ecf20Sopenharmony_ci return 0; 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, "%s allmulti mode\n", 9748c2ecf20Sopenharmony_ci enable ? "entering" : "leaving"); 9758c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val); 9768c2ecf20Sopenharmony_ci 9778c2ecf20Sopenharmony_ci return 0; 9788c2ecf20Sopenharmony_ci} 9798c2ecf20Sopenharmony_ci 9808c2ecf20Sopenharmony_cistatic void xgbe_set_mac_reg(struct xgbe_prv_data *pdata, 9818c2ecf20Sopenharmony_ci struct netdev_hw_addr *ha, unsigned int *mac_reg) 9828c2ecf20Sopenharmony_ci{ 9838c2ecf20Sopenharmony_ci unsigned int mac_addr_hi, mac_addr_lo; 9848c2ecf20Sopenharmony_ci u8 *mac_addr; 9858c2ecf20Sopenharmony_ci 9868c2ecf20Sopenharmony_ci mac_addr_lo = 0; 9878c2ecf20Sopenharmony_ci mac_addr_hi = 0; 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_ci if (ha) { 9908c2ecf20Sopenharmony_ci mac_addr = (u8 *)&mac_addr_lo; 9918c2ecf20Sopenharmony_ci mac_addr[0] = ha->addr[0]; 9928c2ecf20Sopenharmony_ci mac_addr[1] = ha->addr[1]; 9938c2ecf20Sopenharmony_ci mac_addr[2] = ha->addr[2]; 9948c2ecf20Sopenharmony_ci mac_addr[3] = ha->addr[3]; 9958c2ecf20Sopenharmony_ci mac_addr = (u8 *)&mac_addr_hi; 9968c2ecf20Sopenharmony_ci mac_addr[0] = ha->addr[4]; 9978c2ecf20Sopenharmony_ci mac_addr[1] = ha->addr[5]; 9988c2ecf20Sopenharmony_ci 9998c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, 10008c2ecf20Sopenharmony_ci "adding mac address %pM at %#x\n", 10018c2ecf20Sopenharmony_ci ha->addr, *mac_reg); 10028c2ecf20Sopenharmony_ci 10038c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1); 10048c2ecf20Sopenharmony_ci } 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi); 10078c2ecf20Sopenharmony_ci *mac_reg += MAC_MACA_INC; 10088c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo); 10098c2ecf20Sopenharmony_ci *mac_reg += MAC_MACA_INC; 10108c2ecf20Sopenharmony_ci} 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_cistatic void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata) 10138c2ecf20Sopenharmony_ci{ 10148c2ecf20Sopenharmony_ci struct net_device *netdev = pdata->netdev; 10158c2ecf20Sopenharmony_ci struct netdev_hw_addr *ha; 10168c2ecf20Sopenharmony_ci unsigned int mac_reg; 10178c2ecf20Sopenharmony_ci unsigned int addn_macs; 10188c2ecf20Sopenharmony_ci 10198c2ecf20Sopenharmony_ci mac_reg = MAC_MACA1HR; 10208c2ecf20Sopenharmony_ci addn_macs = pdata->hw_feat.addn_mac; 10218c2ecf20Sopenharmony_ci 10228c2ecf20Sopenharmony_ci if (netdev_uc_count(netdev) > addn_macs) { 10238c2ecf20Sopenharmony_ci xgbe_set_promiscuous_mode(pdata, 1); 10248c2ecf20Sopenharmony_ci } else { 10258c2ecf20Sopenharmony_ci netdev_for_each_uc_addr(ha, netdev) { 10268c2ecf20Sopenharmony_ci xgbe_set_mac_reg(pdata, ha, &mac_reg); 10278c2ecf20Sopenharmony_ci addn_macs--; 10288c2ecf20Sopenharmony_ci } 10298c2ecf20Sopenharmony_ci 10308c2ecf20Sopenharmony_ci if (netdev_mc_count(netdev) > addn_macs) { 10318c2ecf20Sopenharmony_ci xgbe_set_all_multicast_mode(pdata, 1); 10328c2ecf20Sopenharmony_ci } else { 10338c2ecf20Sopenharmony_ci netdev_for_each_mc_addr(ha, netdev) { 10348c2ecf20Sopenharmony_ci xgbe_set_mac_reg(pdata, ha, &mac_reg); 10358c2ecf20Sopenharmony_ci addn_macs--; 10368c2ecf20Sopenharmony_ci } 10378c2ecf20Sopenharmony_ci } 10388c2ecf20Sopenharmony_ci } 10398c2ecf20Sopenharmony_ci 10408c2ecf20Sopenharmony_ci /* Clear remaining additional MAC address entries */ 10418c2ecf20Sopenharmony_ci while (addn_macs--) 10428c2ecf20Sopenharmony_ci xgbe_set_mac_reg(pdata, NULL, &mac_reg); 10438c2ecf20Sopenharmony_ci} 10448c2ecf20Sopenharmony_ci 10458c2ecf20Sopenharmony_cistatic void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata) 10468c2ecf20Sopenharmony_ci{ 10478c2ecf20Sopenharmony_ci struct net_device *netdev = pdata->netdev; 10488c2ecf20Sopenharmony_ci struct netdev_hw_addr *ha; 10498c2ecf20Sopenharmony_ci unsigned int hash_reg; 10508c2ecf20Sopenharmony_ci unsigned int hash_table_shift, hash_table_count; 10518c2ecf20Sopenharmony_ci u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE]; 10528c2ecf20Sopenharmony_ci u32 crc; 10538c2ecf20Sopenharmony_ci unsigned int i; 10548c2ecf20Sopenharmony_ci 10558c2ecf20Sopenharmony_ci hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7); 10568c2ecf20Sopenharmony_ci hash_table_count = pdata->hw_feat.hash_table_size / 32; 10578c2ecf20Sopenharmony_ci memset(hash_table, 0, sizeof(hash_table)); 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_ci /* Build the MAC Hash Table register values */ 10608c2ecf20Sopenharmony_ci netdev_for_each_uc_addr(ha, netdev) { 10618c2ecf20Sopenharmony_ci crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN)); 10628c2ecf20Sopenharmony_ci crc >>= hash_table_shift; 10638c2ecf20Sopenharmony_ci hash_table[crc >> 5] |= (1 << (crc & 0x1f)); 10648c2ecf20Sopenharmony_ci } 10658c2ecf20Sopenharmony_ci 10668c2ecf20Sopenharmony_ci netdev_for_each_mc_addr(ha, netdev) { 10678c2ecf20Sopenharmony_ci crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN)); 10688c2ecf20Sopenharmony_ci crc >>= hash_table_shift; 10698c2ecf20Sopenharmony_ci hash_table[crc >> 5] |= (1 << (crc & 0x1f)); 10708c2ecf20Sopenharmony_ci } 10718c2ecf20Sopenharmony_ci 10728c2ecf20Sopenharmony_ci /* Set the MAC Hash Table registers */ 10738c2ecf20Sopenharmony_ci hash_reg = MAC_HTR0; 10748c2ecf20Sopenharmony_ci for (i = 0; i < hash_table_count; i++) { 10758c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]); 10768c2ecf20Sopenharmony_ci hash_reg += MAC_HTR_INC; 10778c2ecf20Sopenharmony_ci } 10788c2ecf20Sopenharmony_ci} 10798c2ecf20Sopenharmony_ci 10808c2ecf20Sopenharmony_cistatic int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata) 10818c2ecf20Sopenharmony_ci{ 10828c2ecf20Sopenharmony_ci if (pdata->hw_feat.hash_table_size) 10838c2ecf20Sopenharmony_ci xgbe_set_mac_hash_table(pdata); 10848c2ecf20Sopenharmony_ci else 10858c2ecf20Sopenharmony_ci xgbe_set_mac_addn_addrs(pdata); 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_ci return 0; 10888c2ecf20Sopenharmony_ci} 10898c2ecf20Sopenharmony_ci 10908c2ecf20Sopenharmony_cistatic int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr) 10918c2ecf20Sopenharmony_ci{ 10928c2ecf20Sopenharmony_ci unsigned int mac_addr_hi, mac_addr_lo; 10938c2ecf20Sopenharmony_ci 10948c2ecf20Sopenharmony_ci mac_addr_hi = (addr[5] << 8) | (addr[4] << 0); 10958c2ecf20Sopenharmony_ci mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) | 10968c2ecf20Sopenharmony_ci (addr[1] << 8) | (addr[0] << 0); 10978c2ecf20Sopenharmony_ci 10988c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi); 10998c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo); 11008c2ecf20Sopenharmony_ci 11018c2ecf20Sopenharmony_ci return 0; 11028c2ecf20Sopenharmony_ci} 11038c2ecf20Sopenharmony_ci 11048c2ecf20Sopenharmony_cistatic int xgbe_config_rx_mode(struct xgbe_prv_data *pdata) 11058c2ecf20Sopenharmony_ci{ 11068c2ecf20Sopenharmony_ci struct net_device *netdev = pdata->netdev; 11078c2ecf20Sopenharmony_ci unsigned int pr_mode, am_mode; 11088c2ecf20Sopenharmony_ci 11098c2ecf20Sopenharmony_ci pr_mode = ((netdev->flags & IFF_PROMISC) != 0); 11108c2ecf20Sopenharmony_ci am_mode = ((netdev->flags & IFF_ALLMULTI) != 0); 11118c2ecf20Sopenharmony_ci 11128c2ecf20Sopenharmony_ci xgbe_set_promiscuous_mode(pdata, pr_mode); 11138c2ecf20Sopenharmony_ci xgbe_set_all_multicast_mode(pdata, am_mode); 11148c2ecf20Sopenharmony_ci 11158c2ecf20Sopenharmony_ci xgbe_add_mac_addresses(pdata); 11168c2ecf20Sopenharmony_ci 11178c2ecf20Sopenharmony_ci return 0; 11188c2ecf20Sopenharmony_ci} 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_cistatic int xgbe_clr_gpio(struct xgbe_prv_data *pdata, unsigned int gpio) 11218c2ecf20Sopenharmony_ci{ 11228c2ecf20Sopenharmony_ci unsigned int reg; 11238c2ecf20Sopenharmony_ci 11248c2ecf20Sopenharmony_ci if (gpio > 15) 11258c2ecf20Sopenharmony_ci return -EINVAL; 11268c2ecf20Sopenharmony_ci 11278c2ecf20Sopenharmony_ci reg = XGMAC_IOREAD(pdata, MAC_GPIOSR); 11288c2ecf20Sopenharmony_ci 11298c2ecf20Sopenharmony_ci reg &= ~(1 << (gpio + 16)); 11308c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_GPIOSR, reg); 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_ci return 0; 11338c2ecf20Sopenharmony_ci} 11348c2ecf20Sopenharmony_ci 11358c2ecf20Sopenharmony_cistatic int xgbe_set_gpio(struct xgbe_prv_data *pdata, unsigned int gpio) 11368c2ecf20Sopenharmony_ci{ 11378c2ecf20Sopenharmony_ci unsigned int reg; 11388c2ecf20Sopenharmony_ci 11398c2ecf20Sopenharmony_ci if (gpio > 15) 11408c2ecf20Sopenharmony_ci return -EINVAL; 11418c2ecf20Sopenharmony_ci 11428c2ecf20Sopenharmony_ci reg = XGMAC_IOREAD(pdata, MAC_GPIOSR); 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci reg |= (1 << (gpio + 16)); 11458c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_GPIOSR, reg); 11468c2ecf20Sopenharmony_ci 11478c2ecf20Sopenharmony_ci return 0; 11488c2ecf20Sopenharmony_ci} 11498c2ecf20Sopenharmony_ci 11508c2ecf20Sopenharmony_cistatic int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, 11518c2ecf20Sopenharmony_ci int mmd_reg) 11528c2ecf20Sopenharmony_ci{ 11538c2ecf20Sopenharmony_ci unsigned long flags; 11548c2ecf20Sopenharmony_ci unsigned int mmd_address, index, offset; 11558c2ecf20Sopenharmony_ci int mmd_data; 11568c2ecf20Sopenharmony_ci 11578c2ecf20Sopenharmony_ci if (mmd_reg & MII_ADDR_C45) 11588c2ecf20Sopenharmony_ci mmd_address = mmd_reg & ~MII_ADDR_C45; 11598c2ecf20Sopenharmony_ci else 11608c2ecf20Sopenharmony_ci mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); 11618c2ecf20Sopenharmony_ci 11628c2ecf20Sopenharmony_ci /* The PCS registers are accessed using mmio. The underlying 11638c2ecf20Sopenharmony_ci * management interface uses indirect addressing to access the MMD 11648c2ecf20Sopenharmony_ci * register sets. This requires accessing of the PCS register in two 11658c2ecf20Sopenharmony_ci * phases, an address phase and a data phase. 11668c2ecf20Sopenharmony_ci * 11678c2ecf20Sopenharmony_ci * The mmio interface is based on 16-bit offsets and values. All 11688c2ecf20Sopenharmony_ci * register offsets must therefore be adjusted by left shifting the 11698c2ecf20Sopenharmony_ci * offset 1 bit and reading 16 bits of data. 11708c2ecf20Sopenharmony_ci */ 11718c2ecf20Sopenharmony_ci mmd_address <<= 1; 11728c2ecf20Sopenharmony_ci index = mmd_address & ~pdata->xpcs_window_mask; 11738c2ecf20Sopenharmony_ci offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); 11748c2ecf20Sopenharmony_ci 11758c2ecf20Sopenharmony_ci spin_lock_irqsave(&pdata->xpcs_lock, flags); 11768c2ecf20Sopenharmony_ci XPCS32_IOWRITE(pdata, pdata->xpcs_window_sel_reg, index); 11778c2ecf20Sopenharmony_ci mmd_data = XPCS16_IOREAD(pdata, offset); 11788c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pdata->xpcs_lock, flags); 11798c2ecf20Sopenharmony_ci 11808c2ecf20Sopenharmony_ci return mmd_data; 11818c2ecf20Sopenharmony_ci} 11828c2ecf20Sopenharmony_ci 11838c2ecf20Sopenharmony_cistatic void xgbe_write_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, 11848c2ecf20Sopenharmony_ci int mmd_reg, int mmd_data) 11858c2ecf20Sopenharmony_ci{ 11868c2ecf20Sopenharmony_ci unsigned long flags; 11878c2ecf20Sopenharmony_ci unsigned int mmd_address, index, offset; 11888c2ecf20Sopenharmony_ci 11898c2ecf20Sopenharmony_ci if (mmd_reg & MII_ADDR_C45) 11908c2ecf20Sopenharmony_ci mmd_address = mmd_reg & ~MII_ADDR_C45; 11918c2ecf20Sopenharmony_ci else 11928c2ecf20Sopenharmony_ci mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); 11938c2ecf20Sopenharmony_ci 11948c2ecf20Sopenharmony_ci /* The PCS registers are accessed using mmio. The underlying 11958c2ecf20Sopenharmony_ci * management interface uses indirect addressing to access the MMD 11968c2ecf20Sopenharmony_ci * register sets. This requires accessing of the PCS register in two 11978c2ecf20Sopenharmony_ci * phases, an address phase and a data phase. 11988c2ecf20Sopenharmony_ci * 11998c2ecf20Sopenharmony_ci * The mmio interface is based on 16-bit offsets and values. All 12008c2ecf20Sopenharmony_ci * register offsets must therefore be adjusted by left shifting the 12018c2ecf20Sopenharmony_ci * offset 1 bit and writing 16 bits of data. 12028c2ecf20Sopenharmony_ci */ 12038c2ecf20Sopenharmony_ci mmd_address <<= 1; 12048c2ecf20Sopenharmony_ci index = mmd_address & ~pdata->xpcs_window_mask; 12058c2ecf20Sopenharmony_ci offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); 12068c2ecf20Sopenharmony_ci 12078c2ecf20Sopenharmony_ci spin_lock_irqsave(&pdata->xpcs_lock, flags); 12088c2ecf20Sopenharmony_ci XPCS32_IOWRITE(pdata, pdata->xpcs_window_sel_reg, index); 12098c2ecf20Sopenharmony_ci XPCS16_IOWRITE(pdata, offset, mmd_data); 12108c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pdata->xpcs_lock, flags); 12118c2ecf20Sopenharmony_ci} 12128c2ecf20Sopenharmony_ci 12138c2ecf20Sopenharmony_cistatic int xgbe_read_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad, 12148c2ecf20Sopenharmony_ci int mmd_reg) 12158c2ecf20Sopenharmony_ci{ 12168c2ecf20Sopenharmony_ci unsigned long flags; 12178c2ecf20Sopenharmony_ci unsigned int mmd_address; 12188c2ecf20Sopenharmony_ci int mmd_data; 12198c2ecf20Sopenharmony_ci 12208c2ecf20Sopenharmony_ci if (mmd_reg & MII_ADDR_C45) 12218c2ecf20Sopenharmony_ci mmd_address = mmd_reg & ~MII_ADDR_C45; 12228c2ecf20Sopenharmony_ci else 12238c2ecf20Sopenharmony_ci mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); 12248c2ecf20Sopenharmony_ci 12258c2ecf20Sopenharmony_ci /* The PCS registers are accessed using mmio. The underlying APB3 12268c2ecf20Sopenharmony_ci * management interface uses indirect addressing to access the MMD 12278c2ecf20Sopenharmony_ci * register sets. This requires accessing of the PCS register in two 12288c2ecf20Sopenharmony_ci * phases, an address phase and a data phase. 12298c2ecf20Sopenharmony_ci * 12308c2ecf20Sopenharmony_ci * The mmio interface is based on 32-bit offsets and values. All 12318c2ecf20Sopenharmony_ci * register offsets must therefore be adjusted by left shifting the 12328c2ecf20Sopenharmony_ci * offset 2 bits and reading 32 bits of data. 12338c2ecf20Sopenharmony_ci */ 12348c2ecf20Sopenharmony_ci spin_lock_irqsave(&pdata->xpcs_lock, flags); 12358c2ecf20Sopenharmony_ci XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8); 12368c2ecf20Sopenharmony_ci mmd_data = XPCS32_IOREAD(pdata, (mmd_address & 0xff) << 2); 12378c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pdata->xpcs_lock, flags); 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_ci return mmd_data; 12408c2ecf20Sopenharmony_ci} 12418c2ecf20Sopenharmony_ci 12428c2ecf20Sopenharmony_cistatic void xgbe_write_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad, 12438c2ecf20Sopenharmony_ci int mmd_reg, int mmd_data) 12448c2ecf20Sopenharmony_ci{ 12458c2ecf20Sopenharmony_ci unsigned int mmd_address; 12468c2ecf20Sopenharmony_ci unsigned long flags; 12478c2ecf20Sopenharmony_ci 12488c2ecf20Sopenharmony_ci if (mmd_reg & MII_ADDR_C45) 12498c2ecf20Sopenharmony_ci mmd_address = mmd_reg & ~MII_ADDR_C45; 12508c2ecf20Sopenharmony_ci else 12518c2ecf20Sopenharmony_ci mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); 12528c2ecf20Sopenharmony_ci 12538c2ecf20Sopenharmony_ci /* The PCS registers are accessed using mmio. The underlying APB3 12548c2ecf20Sopenharmony_ci * management interface uses indirect addressing to access the MMD 12558c2ecf20Sopenharmony_ci * register sets. This requires accessing of the PCS register in two 12568c2ecf20Sopenharmony_ci * phases, an address phase and a data phase. 12578c2ecf20Sopenharmony_ci * 12588c2ecf20Sopenharmony_ci * The mmio interface is based on 32-bit offsets and values. All 12598c2ecf20Sopenharmony_ci * register offsets must therefore be adjusted by left shifting the 12608c2ecf20Sopenharmony_ci * offset 2 bits and writing 32 bits of data. 12618c2ecf20Sopenharmony_ci */ 12628c2ecf20Sopenharmony_ci spin_lock_irqsave(&pdata->xpcs_lock, flags); 12638c2ecf20Sopenharmony_ci XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8); 12648c2ecf20Sopenharmony_ci XPCS32_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data); 12658c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pdata->xpcs_lock, flags); 12668c2ecf20Sopenharmony_ci} 12678c2ecf20Sopenharmony_ci 12688c2ecf20Sopenharmony_cistatic int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad, 12698c2ecf20Sopenharmony_ci int mmd_reg) 12708c2ecf20Sopenharmony_ci{ 12718c2ecf20Sopenharmony_ci switch (pdata->vdata->xpcs_access) { 12728c2ecf20Sopenharmony_ci case XGBE_XPCS_ACCESS_V1: 12738c2ecf20Sopenharmony_ci return xgbe_read_mmd_regs_v1(pdata, prtad, mmd_reg); 12748c2ecf20Sopenharmony_ci 12758c2ecf20Sopenharmony_ci case XGBE_XPCS_ACCESS_V2: 12768c2ecf20Sopenharmony_ci default: 12778c2ecf20Sopenharmony_ci return xgbe_read_mmd_regs_v2(pdata, prtad, mmd_reg); 12788c2ecf20Sopenharmony_ci } 12798c2ecf20Sopenharmony_ci} 12808c2ecf20Sopenharmony_ci 12818c2ecf20Sopenharmony_cistatic void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad, 12828c2ecf20Sopenharmony_ci int mmd_reg, int mmd_data) 12838c2ecf20Sopenharmony_ci{ 12848c2ecf20Sopenharmony_ci switch (pdata->vdata->xpcs_access) { 12858c2ecf20Sopenharmony_ci case XGBE_XPCS_ACCESS_V1: 12868c2ecf20Sopenharmony_ci return xgbe_write_mmd_regs_v1(pdata, prtad, mmd_reg, mmd_data); 12878c2ecf20Sopenharmony_ci 12888c2ecf20Sopenharmony_ci case XGBE_XPCS_ACCESS_V2: 12898c2ecf20Sopenharmony_ci default: 12908c2ecf20Sopenharmony_ci return xgbe_write_mmd_regs_v2(pdata, prtad, mmd_reg, mmd_data); 12918c2ecf20Sopenharmony_ci } 12928c2ecf20Sopenharmony_ci} 12938c2ecf20Sopenharmony_ci 12948c2ecf20Sopenharmony_cistatic unsigned int xgbe_create_mdio_sca(int port, int reg) 12958c2ecf20Sopenharmony_ci{ 12968c2ecf20Sopenharmony_ci unsigned int mdio_sca, da; 12978c2ecf20Sopenharmony_ci 12988c2ecf20Sopenharmony_ci da = (reg & MII_ADDR_C45) ? reg >> 16 : 0; 12998c2ecf20Sopenharmony_ci 13008c2ecf20Sopenharmony_ci mdio_sca = 0; 13018c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, RA, reg); 13028c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, PA, port); 13038c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, DA, da); 13048c2ecf20Sopenharmony_ci 13058c2ecf20Sopenharmony_ci return mdio_sca; 13068c2ecf20Sopenharmony_ci} 13078c2ecf20Sopenharmony_ci 13088c2ecf20Sopenharmony_cistatic int xgbe_write_ext_mii_regs(struct xgbe_prv_data *pdata, int addr, 13098c2ecf20Sopenharmony_ci int reg, u16 val) 13108c2ecf20Sopenharmony_ci{ 13118c2ecf20Sopenharmony_ci unsigned int mdio_sca, mdio_sccd; 13128c2ecf20Sopenharmony_ci 13138c2ecf20Sopenharmony_ci reinit_completion(&pdata->mdio_complete); 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_ci mdio_sca = xgbe_create_mdio_sca(addr, reg); 13168c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_MDIOSCAR, mdio_sca); 13178c2ecf20Sopenharmony_ci 13188c2ecf20Sopenharmony_ci mdio_sccd = 0; 13198c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, DATA, val); 13208c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, CMD, 1); 13218c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, BUSY, 1); 13228c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_MDIOSCCDR, mdio_sccd); 13238c2ecf20Sopenharmony_ci 13248c2ecf20Sopenharmony_ci if (!wait_for_completion_timeout(&pdata->mdio_complete, HZ)) { 13258c2ecf20Sopenharmony_ci netdev_err(pdata->netdev, "mdio write operation timed out\n"); 13268c2ecf20Sopenharmony_ci return -ETIMEDOUT; 13278c2ecf20Sopenharmony_ci } 13288c2ecf20Sopenharmony_ci 13298c2ecf20Sopenharmony_ci return 0; 13308c2ecf20Sopenharmony_ci} 13318c2ecf20Sopenharmony_ci 13328c2ecf20Sopenharmony_cistatic int xgbe_read_ext_mii_regs(struct xgbe_prv_data *pdata, int addr, 13338c2ecf20Sopenharmony_ci int reg) 13348c2ecf20Sopenharmony_ci{ 13358c2ecf20Sopenharmony_ci unsigned int mdio_sca, mdio_sccd; 13368c2ecf20Sopenharmony_ci 13378c2ecf20Sopenharmony_ci reinit_completion(&pdata->mdio_complete); 13388c2ecf20Sopenharmony_ci 13398c2ecf20Sopenharmony_ci mdio_sca = xgbe_create_mdio_sca(addr, reg); 13408c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_MDIOSCAR, mdio_sca); 13418c2ecf20Sopenharmony_ci 13428c2ecf20Sopenharmony_ci mdio_sccd = 0; 13438c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, CMD, 3); 13448c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, BUSY, 1); 13458c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_MDIOSCCDR, mdio_sccd); 13468c2ecf20Sopenharmony_ci 13478c2ecf20Sopenharmony_ci if (!wait_for_completion_timeout(&pdata->mdio_complete, HZ)) { 13488c2ecf20Sopenharmony_ci netdev_err(pdata->netdev, "mdio read operation timed out\n"); 13498c2ecf20Sopenharmony_ci return -ETIMEDOUT; 13508c2ecf20Sopenharmony_ci } 13518c2ecf20Sopenharmony_ci 13528c2ecf20Sopenharmony_ci return XGMAC_IOREAD_BITS(pdata, MAC_MDIOSCCDR, DATA); 13538c2ecf20Sopenharmony_ci} 13548c2ecf20Sopenharmony_ci 13558c2ecf20Sopenharmony_cistatic int xgbe_set_ext_mii_mode(struct xgbe_prv_data *pdata, unsigned int port, 13568c2ecf20Sopenharmony_ci enum xgbe_mdio_mode mode) 13578c2ecf20Sopenharmony_ci{ 13588c2ecf20Sopenharmony_ci unsigned int reg_val = XGMAC_IOREAD(pdata, MAC_MDIOCL22R); 13598c2ecf20Sopenharmony_ci 13608c2ecf20Sopenharmony_ci switch (mode) { 13618c2ecf20Sopenharmony_ci case XGBE_MDIO_MODE_CL22: 13628c2ecf20Sopenharmony_ci if (port > XGMAC_MAX_C22_PORT) 13638c2ecf20Sopenharmony_ci return -EINVAL; 13648c2ecf20Sopenharmony_ci reg_val |= (1 << port); 13658c2ecf20Sopenharmony_ci break; 13668c2ecf20Sopenharmony_ci case XGBE_MDIO_MODE_CL45: 13678c2ecf20Sopenharmony_ci break; 13688c2ecf20Sopenharmony_ci default: 13698c2ecf20Sopenharmony_ci return -EINVAL; 13708c2ecf20Sopenharmony_ci } 13718c2ecf20Sopenharmony_ci 13728c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_MDIOCL22R, reg_val); 13738c2ecf20Sopenharmony_ci 13748c2ecf20Sopenharmony_ci return 0; 13758c2ecf20Sopenharmony_ci} 13768c2ecf20Sopenharmony_ci 13778c2ecf20Sopenharmony_cistatic int xgbe_tx_complete(struct xgbe_ring_desc *rdesc) 13788c2ecf20Sopenharmony_ci{ 13798c2ecf20Sopenharmony_ci return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN); 13808c2ecf20Sopenharmony_ci} 13818c2ecf20Sopenharmony_ci 13828c2ecf20Sopenharmony_cistatic int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata) 13838c2ecf20Sopenharmony_ci{ 13848c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0); 13858c2ecf20Sopenharmony_ci 13868c2ecf20Sopenharmony_ci return 0; 13878c2ecf20Sopenharmony_ci} 13888c2ecf20Sopenharmony_ci 13898c2ecf20Sopenharmony_cistatic int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata) 13908c2ecf20Sopenharmony_ci{ 13918c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1); 13928c2ecf20Sopenharmony_ci 13938c2ecf20Sopenharmony_ci return 0; 13948c2ecf20Sopenharmony_ci} 13958c2ecf20Sopenharmony_ci 13968c2ecf20Sopenharmony_cistatic void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata) 13978c2ecf20Sopenharmony_ci{ 13988c2ecf20Sopenharmony_ci struct xgbe_ring_desc *rdesc = rdata->rdesc; 13998c2ecf20Sopenharmony_ci 14008c2ecf20Sopenharmony_ci /* Reset the Tx descriptor 14018c2ecf20Sopenharmony_ci * Set buffer 1 (lo) address to zero 14028c2ecf20Sopenharmony_ci * Set buffer 1 (hi) address to zero 14038c2ecf20Sopenharmony_ci * Reset all other control bits (IC, TTSE, B2L & B1L) 14048c2ecf20Sopenharmony_ci * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc) 14058c2ecf20Sopenharmony_ci */ 14068c2ecf20Sopenharmony_ci rdesc->desc0 = 0; 14078c2ecf20Sopenharmony_ci rdesc->desc1 = 0; 14088c2ecf20Sopenharmony_ci rdesc->desc2 = 0; 14098c2ecf20Sopenharmony_ci rdesc->desc3 = 0; 14108c2ecf20Sopenharmony_ci 14118c2ecf20Sopenharmony_ci /* Make sure ownership is written to the descriptor */ 14128c2ecf20Sopenharmony_ci dma_wmb(); 14138c2ecf20Sopenharmony_ci} 14148c2ecf20Sopenharmony_ci 14158c2ecf20Sopenharmony_cistatic void xgbe_tx_desc_init(struct xgbe_channel *channel) 14168c2ecf20Sopenharmony_ci{ 14178c2ecf20Sopenharmony_ci struct xgbe_ring *ring = channel->tx_ring; 14188c2ecf20Sopenharmony_ci struct xgbe_ring_data *rdata; 14198c2ecf20Sopenharmony_ci int i; 14208c2ecf20Sopenharmony_ci int start_index = ring->cur; 14218c2ecf20Sopenharmony_ci 14228c2ecf20Sopenharmony_ci DBGPR("-->tx_desc_init\n"); 14238c2ecf20Sopenharmony_ci 14248c2ecf20Sopenharmony_ci /* Initialze all descriptors */ 14258c2ecf20Sopenharmony_ci for (i = 0; i < ring->rdesc_count; i++) { 14268c2ecf20Sopenharmony_ci rdata = XGBE_GET_DESC_DATA(ring, i); 14278c2ecf20Sopenharmony_ci 14288c2ecf20Sopenharmony_ci /* Initialize Tx descriptor */ 14298c2ecf20Sopenharmony_ci xgbe_tx_desc_reset(rdata); 14308c2ecf20Sopenharmony_ci } 14318c2ecf20Sopenharmony_ci 14328c2ecf20Sopenharmony_ci /* Update the total number of Tx descriptors */ 14338c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1); 14348c2ecf20Sopenharmony_ci 14358c2ecf20Sopenharmony_ci /* Update the starting address of descriptor ring */ 14368c2ecf20Sopenharmony_ci rdata = XGBE_GET_DESC_DATA(ring, start_index); 14378c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI, 14388c2ecf20Sopenharmony_ci upper_32_bits(rdata->rdesc_dma)); 14398c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO, 14408c2ecf20Sopenharmony_ci lower_32_bits(rdata->rdesc_dma)); 14418c2ecf20Sopenharmony_ci 14428c2ecf20Sopenharmony_ci DBGPR("<--tx_desc_init\n"); 14438c2ecf20Sopenharmony_ci} 14448c2ecf20Sopenharmony_ci 14458c2ecf20Sopenharmony_cistatic void xgbe_rx_desc_reset(struct xgbe_prv_data *pdata, 14468c2ecf20Sopenharmony_ci struct xgbe_ring_data *rdata, unsigned int index) 14478c2ecf20Sopenharmony_ci{ 14488c2ecf20Sopenharmony_ci struct xgbe_ring_desc *rdesc = rdata->rdesc; 14498c2ecf20Sopenharmony_ci unsigned int rx_usecs = pdata->rx_usecs; 14508c2ecf20Sopenharmony_ci unsigned int rx_frames = pdata->rx_frames; 14518c2ecf20Sopenharmony_ci unsigned int inte; 14528c2ecf20Sopenharmony_ci dma_addr_t hdr_dma, buf_dma; 14538c2ecf20Sopenharmony_ci 14548c2ecf20Sopenharmony_ci if (!rx_usecs && !rx_frames) { 14558c2ecf20Sopenharmony_ci /* No coalescing, interrupt for every descriptor */ 14568c2ecf20Sopenharmony_ci inte = 1; 14578c2ecf20Sopenharmony_ci } else { 14588c2ecf20Sopenharmony_ci /* Set interrupt based on Rx frame coalescing setting */ 14598c2ecf20Sopenharmony_ci if (rx_frames && !((index + 1) % rx_frames)) 14608c2ecf20Sopenharmony_ci inte = 1; 14618c2ecf20Sopenharmony_ci else 14628c2ecf20Sopenharmony_ci inte = 0; 14638c2ecf20Sopenharmony_ci } 14648c2ecf20Sopenharmony_ci 14658c2ecf20Sopenharmony_ci /* Reset the Rx descriptor 14668c2ecf20Sopenharmony_ci * Set buffer 1 (lo) address to header dma address (lo) 14678c2ecf20Sopenharmony_ci * Set buffer 1 (hi) address to header dma address (hi) 14688c2ecf20Sopenharmony_ci * Set buffer 2 (lo) address to buffer dma address (lo) 14698c2ecf20Sopenharmony_ci * Set buffer 2 (hi) address to buffer dma address (hi) and 14708c2ecf20Sopenharmony_ci * set control bits OWN and INTE 14718c2ecf20Sopenharmony_ci */ 14728c2ecf20Sopenharmony_ci hdr_dma = rdata->rx.hdr.dma_base + rdata->rx.hdr.dma_off; 14738c2ecf20Sopenharmony_ci buf_dma = rdata->rx.buf.dma_base + rdata->rx.buf.dma_off; 14748c2ecf20Sopenharmony_ci rdesc->desc0 = cpu_to_le32(lower_32_bits(hdr_dma)); 14758c2ecf20Sopenharmony_ci rdesc->desc1 = cpu_to_le32(upper_32_bits(hdr_dma)); 14768c2ecf20Sopenharmony_ci rdesc->desc2 = cpu_to_le32(lower_32_bits(buf_dma)); 14778c2ecf20Sopenharmony_ci rdesc->desc3 = cpu_to_le32(upper_32_bits(buf_dma)); 14788c2ecf20Sopenharmony_ci 14798c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, inte); 14808c2ecf20Sopenharmony_ci 14818c2ecf20Sopenharmony_ci /* Since the Rx DMA engine is likely running, make sure everything 14828c2ecf20Sopenharmony_ci * is written to the descriptor(s) before setting the OWN bit 14838c2ecf20Sopenharmony_ci * for the descriptor 14848c2ecf20Sopenharmony_ci */ 14858c2ecf20Sopenharmony_ci dma_wmb(); 14868c2ecf20Sopenharmony_ci 14878c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1); 14888c2ecf20Sopenharmony_ci 14898c2ecf20Sopenharmony_ci /* Make sure ownership is written to the descriptor */ 14908c2ecf20Sopenharmony_ci dma_wmb(); 14918c2ecf20Sopenharmony_ci} 14928c2ecf20Sopenharmony_ci 14938c2ecf20Sopenharmony_cistatic void xgbe_rx_desc_init(struct xgbe_channel *channel) 14948c2ecf20Sopenharmony_ci{ 14958c2ecf20Sopenharmony_ci struct xgbe_prv_data *pdata = channel->pdata; 14968c2ecf20Sopenharmony_ci struct xgbe_ring *ring = channel->rx_ring; 14978c2ecf20Sopenharmony_ci struct xgbe_ring_data *rdata; 14988c2ecf20Sopenharmony_ci unsigned int start_index = ring->cur; 14998c2ecf20Sopenharmony_ci unsigned int i; 15008c2ecf20Sopenharmony_ci 15018c2ecf20Sopenharmony_ci DBGPR("-->rx_desc_init\n"); 15028c2ecf20Sopenharmony_ci 15038c2ecf20Sopenharmony_ci /* Initialize all descriptors */ 15048c2ecf20Sopenharmony_ci for (i = 0; i < ring->rdesc_count; i++) { 15058c2ecf20Sopenharmony_ci rdata = XGBE_GET_DESC_DATA(ring, i); 15068c2ecf20Sopenharmony_ci 15078c2ecf20Sopenharmony_ci /* Initialize Rx descriptor */ 15088c2ecf20Sopenharmony_ci xgbe_rx_desc_reset(pdata, rdata, i); 15098c2ecf20Sopenharmony_ci } 15108c2ecf20Sopenharmony_ci 15118c2ecf20Sopenharmony_ci /* Update the total number of Rx descriptors */ 15128c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1); 15138c2ecf20Sopenharmony_ci 15148c2ecf20Sopenharmony_ci /* Update the starting address of descriptor ring */ 15158c2ecf20Sopenharmony_ci rdata = XGBE_GET_DESC_DATA(ring, start_index); 15168c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI, 15178c2ecf20Sopenharmony_ci upper_32_bits(rdata->rdesc_dma)); 15188c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO, 15198c2ecf20Sopenharmony_ci lower_32_bits(rdata->rdesc_dma)); 15208c2ecf20Sopenharmony_ci 15218c2ecf20Sopenharmony_ci /* Update the Rx Descriptor Tail Pointer */ 15228c2ecf20Sopenharmony_ci rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1); 15238c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO, 15248c2ecf20Sopenharmony_ci lower_32_bits(rdata->rdesc_dma)); 15258c2ecf20Sopenharmony_ci 15268c2ecf20Sopenharmony_ci DBGPR("<--rx_desc_init\n"); 15278c2ecf20Sopenharmony_ci} 15288c2ecf20Sopenharmony_ci 15298c2ecf20Sopenharmony_cistatic void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata, 15308c2ecf20Sopenharmony_ci unsigned int addend) 15318c2ecf20Sopenharmony_ci{ 15328c2ecf20Sopenharmony_ci unsigned int count = 10000; 15338c2ecf20Sopenharmony_ci 15348c2ecf20Sopenharmony_ci /* Set the addend register value and tell the device */ 15358c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_TSAR, addend); 15368c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1); 15378c2ecf20Sopenharmony_ci 15388c2ecf20Sopenharmony_ci /* Wait for addend update to complete */ 15398c2ecf20Sopenharmony_ci while (--count && XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG)) 15408c2ecf20Sopenharmony_ci udelay(5); 15418c2ecf20Sopenharmony_ci 15428c2ecf20Sopenharmony_ci if (!count) 15438c2ecf20Sopenharmony_ci netdev_err(pdata->netdev, 15448c2ecf20Sopenharmony_ci "timed out updating timestamp addend register\n"); 15458c2ecf20Sopenharmony_ci} 15468c2ecf20Sopenharmony_ci 15478c2ecf20Sopenharmony_cistatic void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec, 15488c2ecf20Sopenharmony_ci unsigned int nsec) 15498c2ecf20Sopenharmony_ci{ 15508c2ecf20Sopenharmony_ci unsigned int count = 10000; 15518c2ecf20Sopenharmony_ci 15528c2ecf20Sopenharmony_ci /* Set the time values and tell the device */ 15538c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_STSUR, sec); 15548c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_STNUR, nsec); 15558c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1); 15568c2ecf20Sopenharmony_ci 15578c2ecf20Sopenharmony_ci /* Wait for time update to complete */ 15588c2ecf20Sopenharmony_ci while (--count && XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT)) 15598c2ecf20Sopenharmony_ci udelay(5); 15608c2ecf20Sopenharmony_ci 15618c2ecf20Sopenharmony_ci if (!count) 15628c2ecf20Sopenharmony_ci netdev_err(pdata->netdev, "timed out initializing timestamp\n"); 15638c2ecf20Sopenharmony_ci} 15648c2ecf20Sopenharmony_ci 15658c2ecf20Sopenharmony_cistatic u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata) 15668c2ecf20Sopenharmony_ci{ 15678c2ecf20Sopenharmony_ci u64 nsec; 15688c2ecf20Sopenharmony_ci 15698c2ecf20Sopenharmony_ci nsec = XGMAC_IOREAD(pdata, MAC_STSR); 15708c2ecf20Sopenharmony_ci nsec *= NSEC_PER_SEC; 15718c2ecf20Sopenharmony_ci nsec += XGMAC_IOREAD(pdata, MAC_STNR); 15728c2ecf20Sopenharmony_ci 15738c2ecf20Sopenharmony_ci return nsec; 15748c2ecf20Sopenharmony_ci} 15758c2ecf20Sopenharmony_ci 15768c2ecf20Sopenharmony_cistatic u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata) 15778c2ecf20Sopenharmony_ci{ 15788c2ecf20Sopenharmony_ci unsigned int tx_snr, tx_ssr; 15798c2ecf20Sopenharmony_ci u64 nsec; 15808c2ecf20Sopenharmony_ci 15818c2ecf20Sopenharmony_ci if (pdata->vdata->tx_tstamp_workaround) { 15828c2ecf20Sopenharmony_ci tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR); 15838c2ecf20Sopenharmony_ci tx_ssr = XGMAC_IOREAD(pdata, MAC_TXSSR); 15848c2ecf20Sopenharmony_ci } else { 15858c2ecf20Sopenharmony_ci tx_ssr = XGMAC_IOREAD(pdata, MAC_TXSSR); 15868c2ecf20Sopenharmony_ci tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR); 15878c2ecf20Sopenharmony_ci } 15888c2ecf20Sopenharmony_ci 15898c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS)) 15908c2ecf20Sopenharmony_ci return 0; 15918c2ecf20Sopenharmony_ci 15928c2ecf20Sopenharmony_ci nsec = tx_ssr; 15938c2ecf20Sopenharmony_ci nsec *= NSEC_PER_SEC; 15948c2ecf20Sopenharmony_ci nsec += tx_snr; 15958c2ecf20Sopenharmony_ci 15968c2ecf20Sopenharmony_ci return nsec; 15978c2ecf20Sopenharmony_ci} 15988c2ecf20Sopenharmony_ci 15998c2ecf20Sopenharmony_cistatic void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet, 16008c2ecf20Sopenharmony_ci struct xgbe_ring_desc *rdesc) 16018c2ecf20Sopenharmony_ci{ 16028c2ecf20Sopenharmony_ci u64 nsec; 16038c2ecf20Sopenharmony_ci 16048c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) && 16058c2ecf20Sopenharmony_ci !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) { 16068c2ecf20Sopenharmony_ci nsec = le32_to_cpu(rdesc->desc1); 16078c2ecf20Sopenharmony_ci nsec <<= 32; 16088c2ecf20Sopenharmony_ci nsec |= le32_to_cpu(rdesc->desc0); 16098c2ecf20Sopenharmony_ci if (nsec != 0xffffffffffffffffULL) { 16108c2ecf20Sopenharmony_ci packet->rx_tstamp = nsec; 16118c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 16128c2ecf20Sopenharmony_ci RX_TSTAMP, 1); 16138c2ecf20Sopenharmony_ci } 16148c2ecf20Sopenharmony_ci } 16158c2ecf20Sopenharmony_ci} 16168c2ecf20Sopenharmony_ci 16178c2ecf20Sopenharmony_cistatic int xgbe_config_tstamp(struct xgbe_prv_data *pdata, 16188c2ecf20Sopenharmony_ci unsigned int mac_tscr) 16198c2ecf20Sopenharmony_ci{ 16208c2ecf20Sopenharmony_ci /* Set one nano-second accuracy */ 16218c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1); 16228c2ecf20Sopenharmony_ci 16238c2ecf20Sopenharmony_ci /* Set fine timestamp update */ 16248c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1); 16258c2ecf20Sopenharmony_ci 16268c2ecf20Sopenharmony_ci /* Overwrite earlier timestamps */ 16278c2ecf20Sopenharmony_ci XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1); 16288c2ecf20Sopenharmony_ci 16298c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr); 16308c2ecf20Sopenharmony_ci 16318c2ecf20Sopenharmony_ci /* Exit if timestamping is not enabled */ 16328c2ecf20Sopenharmony_ci if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA)) 16338c2ecf20Sopenharmony_ci return 0; 16348c2ecf20Sopenharmony_ci 16358c2ecf20Sopenharmony_ci /* Initialize time registers */ 16368c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC); 16378c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC); 16388c2ecf20Sopenharmony_ci xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend); 16398c2ecf20Sopenharmony_ci xgbe_set_tstamp_time(pdata, 0, 0); 16408c2ecf20Sopenharmony_ci 16418c2ecf20Sopenharmony_ci /* Initialize the timecounter */ 16428c2ecf20Sopenharmony_ci timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc, 16438c2ecf20Sopenharmony_ci ktime_to_ns(ktime_get_real())); 16448c2ecf20Sopenharmony_ci 16458c2ecf20Sopenharmony_ci return 0; 16468c2ecf20Sopenharmony_ci} 16478c2ecf20Sopenharmony_ci 16488c2ecf20Sopenharmony_cistatic void xgbe_tx_start_xmit(struct xgbe_channel *channel, 16498c2ecf20Sopenharmony_ci struct xgbe_ring *ring) 16508c2ecf20Sopenharmony_ci{ 16518c2ecf20Sopenharmony_ci struct xgbe_prv_data *pdata = channel->pdata; 16528c2ecf20Sopenharmony_ci struct xgbe_ring_data *rdata; 16538c2ecf20Sopenharmony_ci 16548c2ecf20Sopenharmony_ci /* Make sure everything is written before the register write */ 16558c2ecf20Sopenharmony_ci wmb(); 16568c2ecf20Sopenharmony_ci 16578c2ecf20Sopenharmony_ci /* Issue a poll command to Tx DMA by writing address 16588c2ecf20Sopenharmony_ci * of next immediate free descriptor */ 16598c2ecf20Sopenharmony_ci rdata = XGBE_GET_DESC_DATA(ring, ring->cur); 16608c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO, 16618c2ecf20Sopenharmony_ci lower_32_bits(rdata->rdesc_dma)); 16628c2ecf20Sopenharmony_ci 16638c2ecf20Sopenharmony_ci /* Start the Tx timer */ 16648c2ecf20Sopenharmony_ci if (pdata->tx_usecs && !channel->tx_timer_active) { 16658c2ecf20Sopenharmony_ci channel->tx_timer_active = 1; 16668c2ecf20Sopenharmony_ci mod_timer(&channel->tx_timer, 16678c2ecf20Sopenharmony_ci jiffies + usecs_to_jiffies(pdata->tx_usecs)); 16688c2ecf20Sopenharmony_ci } 16698c2ecf20Sopenharmony_ci 16708c2ecf20Sopenharmony_ci ring->tx.xmit_more = 0; 16718c2ecf20Sopenharmony_ci} 16728c2ecf20Sopenharmony_ci 16738c2ecf20Sopenharmony_cistatic void xgbe_dev_xmit(struct xgbe_channel *channel) 16748c2ecf20Sopenharmony_ci{ 16758c2ecf20Sopenharmony_ci struct xgbe_prv_data *pdata = channel->pdata; 16768c2ecf20Sopenharmony_ci struct xgbe_ring *ring = channel->tx_ring; 16778c2ecf20Sopenharmony_ci struct xgbe_ring_data *rdata; 16788c2ecf20Sopenharmony_ci struct xgbe_ring_desc *rdesc; 16798c2ecf20Sopenharmony_ci struct xgbe_packet_data *packet = &ring->packet_data; 16808c2ecf20Sopenharmony_ci unsigned int tx_packets, tx_bytes; 16818c2ecf20Sopenharmony_ci unsigned int csum, tso, vlan, vxlan; 16828c2ecf20Sopenharmony_ci unsigned int tso_context, vlan_context; 16838c2ecf20Sopenharmony_ci unsigned int tx_set_ic; 16848c2ecf20Sopenharmony_ci int start_index = ring->cur; 16858c2ecf20Sopenharmony_ci int cur_index = ring->cur; 16868c2ecf20Sopenharmony_ci int i; 16878c2ecf20Sopenharmony_ci 16888c2ecf20Sopenharmony_ci DBGPR("-->xgbe_dev_xmit\n"); 16898c2ecf20Sopenharmony_ci 16908c2ecf20Sopenharmony_ci tx_packets = packet->tx_packets; 16918c2ecf20Sopenharmony_ci tx_bytes = packet->tx_bytes; 16928c2ecf20Sopenharmony_ci 16938c2ecf20Sopenharmony_ci csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, 16948c2ecf20Sopenharmony_ci CSUM_ENABLE); 16958c2ecf20Sopenharmony_ci tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, 16968c2ecf20Sopenharmony_ci TSO_ENABLE); 16978c2ecf20Sopenharmony_ci vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, 16988c2ecf20Sopenharmony_ci VLAN_CTAG); 16998c2ecf20Sopenharmony_ci vxlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, 17008c2ecf20Sopenharmony_ci VXLAN); 17018c2ecf20Sopenharmony_ci 17028c2ecf20Sopenharmony_ci if (tso && (packet->mss != ring->tx.cur_mss)) 17038c2ecf20Sopenharmony_ci tso_context = 1; 17048c2ecf20Sopenharmony_ci else 17058c2ecf20Sopenharmony_ci tso_context = 0; 17068c2ecf20Sopenharmony_ci 17078c2ecf20Sopenharmony_ci if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag)) 17088c2ecf20Sopenharmony_ci vlan_context = 1; 17098c2ecf20Sopenharmony_ci else 17108c2ecf20Sopenharmony_ci vlan_context = 0; 17118c2ecf20Sopenharmony_ci 17128c2ecf20Sopenharmony_ci /* Determine if an interrupt should be generated for this Tx: 17138c2ecf20Sopenharmony_ci * Interrupt: 17148c2ecf20Sopenharmony_ci * - Tx frame count exceeds the frame count setting 17158c2ecf20Sopenharmony_ci * - Addition of Tx frame count to the frame count since the 17168c2ecf20Sopenharmony_ci * last interrupt was set exceeds the frame count setting 17178c2ecf20Sopenharmony_ci * No interrupt: 17188c2ecf20Sopenharmony_ci * - No frame count setting specified (ethtool -C ethX tx-frames 0) 17198c2ecf20Sopenharmony_ci * - Addition of Tx frame count to the frame count since the 17208c2ecf20Sopenharmony_ci * last interrupt was set does not exceed the frame count setting 17218c2ecf20Sopenharmony_ci */ 17228c2ecf20Sopenharmony_ci ring->coalesce_count += tx_packets; 17238c2ecf20Sopenharmony_ci if (!pdata->tx_frames) 17248c2ecf20Sopenharmony_ci tx_set_ic = 0; 17258c2ecf20Sopenharmony_ci else if (tx_packets > pdata->tx_frames) 17268c2ecf20Sopenharmony_ci tx_set_ic = 1; 17278c2ecf20Sopenharmony_ci else if ((ring->coalesce_count % pdata->tx_frames) < tx_packets) 17288c2ecf20Sopenharmony_ci tx_set_ic = 1; 17298c2ecf20Sopenharmony_ci else 17308c2ecf20Sopenharmony_ci tx_set_ic = 0; 17318c2ecf20Sopenharmony_ci 17328c2ecf20Sopenharmony_ci rdata = XGBE_GET_DESC_DATA(ring, cur_index); 17338c2ecf20Sopenharmony_ci rdesc = rdata->rdesc; 17348c2ecf20Sopenharmony_ci 17358c2ecf20Sopenharmony_ci /* Create a context descriptor if this is a TSO packet */ 17368c2ecf20Sopenharmony_ci if (tso_context || vlan_context) { 17378c2ecf20Sopenharmony_ci if (tso_context) { 17388c2ecf20Sopenharmony_ci netif_dbg(pdata, tx_queued, pdata->netdev, 17398c2ecf20Sopenharmony_ci "TSO context descriptor, mss=%u\n", 17408c2ecf20Sopenharmony_ci packet->mss); 17418c2ecf20Sopenharmony_ci 17428c2ecf20Sopenharmony_ci /* Set the MSS size */ 17438c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2, 17448c2ecf20Sopenharmony_ci MSS, packet->mss); 17458c2ecf20Sopenharmony_ci 17468c2ecf20Sopenharmony_ci /* Mark it as a CONTEXT descriptor */ 17478c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3, 17488c2ecf20Sopenharmony_ci CTXT, 1); 17498c2ecf20Sopenharmony_ci 17508c2ecf20Sopenharmony_ci /* Indicate this descriptor contains the MSS */ 17518c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3, 17528c2ecf20Sopenharmony_ci TCMSSV, 1); 17538c2ecf20Sopenharmony_ci 17548c2ecf20Sopenharmony_ci ring->tx.cur_mss = packet->mss; 17558c2ecf20Sopenharmony_ci } 17568c2ecf20Sopenharmony_ci 17578c2ecf20Sopenharmony_ci if (vlan_context) { 17588c2ecf20Sopenharmony_ci netif_dbg(pdata, tx_queued, pdata->netdev, 17598c2ecf20Sopenharmony_ci "VLAN context descriptor, ctag=%u\n", 17608c2ecf20Sopenharmony_ci packet->vlan_ctag); 17618c2ecf20Sopenharmony_ci 17628c2ecf20Sopenharmony_ci /* Mark it as a CONTEXT descriptor */ 17638c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3, 17648c2ecf20Sopenharmony_ci CTXT, 1); 17658c2ecf20Sopenharmony_ci 17668c2ecf20Sopenharmony_ci /* Set the VLAN tag */ 17678c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3, 17688c2ecf20Sopenharmony_ci VT, packet->vlan_ctag); 17698c2ecf20Sopenharmony_ci 17708c2ecf20Sopenharmony_ci /* Indicate this descriptor contains the VLAN tag */ 17718c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3, 17728c2ecf20Sopenharmony_ci VLTV, 1); 17738c2ecf20Sopenharmony_ci 17748c2ecf20Sopenharmony_ci ring->tx.cur_vlan_ctag = packet->vlan_ctag; 17758c2ecf20Sopenharmony_ci } 17768c2ecf20Sopenharmony_ci 17778c2ecf20Sopenharmony_ci cur_index++; 17788c2ecf20Sopenharmony_ci rdata = XGBE_GET_DESC_DATA(ring, cur_index); 17798c2ecf20Sopenharmony_ci rdesc = rdata->rdesc; 17808c2ecf20Sopenharmony_ci } 17818c2ecf20Sopenharmony_ci 17828c2ecf20Sopenharmony_ci /* Update buffer address (for TSO this is the header) */ 17838c2ecf20Sopenharmony_ci rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma)); 17848c2ecf20Sopenharmony_ci rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma)); 17858c2ecf20Sopenharmony_ci 17868c2ecf20Sopenharmony_ci /* Update the buffer length */ 17878c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L, 17888c2ecf20Sopenharmony_ci rdata->skb_dma_len); 17898c2ecf20Sopenharmony_ci 17908c2ecf20Sopenharmony_ci /* VLAN tag insertion check */ 17918c2ecf20Sopenharmony_ci if (vlan) 17928c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR, 17938c2ecf20Sopenharmony_ci TX_NORMAL_DESC2_VLAN_INSERT); 17948c2ecf20Sopenharmony_ci 17958c2ecf20Sopenharmony_ci /* Timestamp enablement check */ 17968c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP)) 17978c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1); 17988c2ecf20Sopenharmony_ci 17998c2ecf20Sopenharmony_ci /* Mark it as First Descriptor */ 18008c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1); 18018c2ecf20Sopenharmony_ci 18028c2ecf20Sopenharmony_ci /* Mark it as a NORMAL descriptor */ 18038c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0); 18048c2ecf20Sopenharmony_ci 18058c2ecf20Sopenharmony_ci /* Set OWN bit if not the first descriptor */ 18068c2ecf20Sopenharmony_ci if (cur_index != start_index) 18078c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1); 18088c2ecf20Sopenharmony_ci 18098c2ecf20Sopenharmony_ci if (tso) { 18108c2ecf20Sopenharmony_ci /* Enable TSO */ 18118c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1); 18128c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL, 18138c2ecf20Sopenharmony_ci packet->tcp_payload_len); 18148c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN, 18158c2ecf20Sopenharmony_ci packet->tcp_header_len / 4); 18168c2ecf20Sopenharmony_ci 18178c2ecf20Sopenharmony_ci pdata->ext_stats.tx_tso_packets += tx_packets; 18188c2ecf20Sopenharmony_ci } else { 18198c2ecf20Sopenharmony_ci /* Enable CRC and Pad Insertion */ 18208c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0); 18218c2ecf20Sopenharmony_ci 18228c2ecf20Sopenharmony_ci /* Enable HW CSUM */ 18238c2ecf20Sopenharmony_ci if (csum) 18248c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, 18258c2ecf20Sopenharmony_ci CIC, 0x3); 18268c2ecf20Sopenharmony_ci 18278c2ecf20Sopenharmony_ci /* Set the total length to be transmitted */ 18288c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL, 18298c2ecf20Sopenharmony_ci packet->length); 18308c2ecf20Sopenharmony_ci } 18318c2ecf20Sopenharmony_ci 18328c2ecf20Sopenharmony_ci if (vxlan) { 18338c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, VNP, 18348c2ecf20Sopenharmony_ci TX_NORMAL_DESC3_VXLAN_PACKET); 18358c2ecf20Sopenharmony_ci 18368c2ecf20Sopenharmony_ci pdata->ext_stats.tx_vxlan_packets += packet->tx_packets; 18378c2ecf20Sopenharmony_ci } 18388c2ecf20Sopenharmony_ci 18398c2ecf20Sopenharmony_ci for (i = cur_index - start_index + 1; i < packet->rdesc_count; i++) { 18408c2ecf20Sopenharmony_ci cur_index++; 18418c2ecf20Sopenharmony_ci rdata = XGBE_GET_DESC_DATA(ring, cur_index); 18428c2ecf20Sopenharmony_ci rdesc = rdata->rdesc; 18438c2ecf20Sopenharmony_ci 18448c2ecf20Sopenharmony_ci /* Update buffer address */ 18458c2ecf20Sopenharmony_ci rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma)); 18468c2ecf20Sopenharmony_ci rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma)); 18478c2ecf20Sopenharmony_ci 18488c2ecf20Sopenharmony_ci /* Update the buffer length */ 18498c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L, 18508c2ecf20Sopenharmony_ci rdata->skb_dma_len); 18518c2ecf20Sopenharmony_ci 18528c2ecf20Sopenharmony_ci /* Set OWN bit */ 18538c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1); 18548c2ecf20Sopenharmony_ci 18558c2ecf20Sopenharmony_ci /* Mark it as NORMAL descriptor */ 18568c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0); 18578c2ecf20Sopenharmony_ci 18588c2ecf20Sopenharmony_ci /* Enable HW CSUM */ 18598c2ecf20Sopenharmony_ci if (csum) 18608c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, 18618c2ecf20Sopenharmony_ci CIC, 0x3); 18628c2ecf20Sopenharmony_ci } 18638c2ecf20Sopenharmony_ci 18648c2ecf20Sopenharmony_ci /* Set LAST bit for the last descriptor */ 18658c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1); 18668c2ecf20Sopenharmony_ci 18678c2ecf20Sopenharmony_ci /* Set IC bit based on Tx coalescing settings */ 18688c2ecf20Sopenharmony_ci if (tx_set_ic) 18698c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1); 18708c2ecf20Sopenharmony_ci 18718c2ecf20Sopenharmony_ci /* Save the Tx info to report back during cleanup */ 18728c2ecf20Sopenharmony_ci rdata->tx.packets = tx_packets; 18738c2ecf20Sopenharmony_ci rdata->tx.bytes = tx_bytes; 18748c2ecf20Sopenharmony_ci 18758c2ecf20Sopenharmony_ci pdata->ext_stats.txq_packets[channel->queue_index] += tx_packets; 18768c2ecf20Sopenharmony_ci pdata->ext_stats.txq_bytes[channel->queue_index] += tx_bytes; 18778c2ecf20Sopenharmony_ci 18788c2ecf20Sopenharmony_ci /* In case the Tx DMA engine is running, make sure everything 18798c2ecf20Sopenharmony_ci * is written to the descriptor(s) before setting the OWN bit 18808c2ecf20Sopenharmony_ci * for the first descriptor 18818c2ecf20Sopenharmony_ci */ 18828c2ecf20Sopenharmony_ci dma_wmb(); 18838c2ecf20Sopenharmony_ci 18848c2ecf20Sopenharmony_ci /* Set OWN bit for the first descriptor */ 18858c2ecf20Sopenharmony_ci rdata = XGBE_GET_DESC_DATA(ring, start_index); 18868c2ecf20Sopenharmony_ci rdesc = rdata->rdesc; 18878c2ecf20Sopenharmony_ci XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1); 18888c2ecf20Sopenharmony_ci 18898c2ecf20Sopenharmony_ci if (netif_msg_tx_queued(pdata)) 18908c2ecf20Sopenharmony_ci xgbe_dump_tx_desc(pdata, ring, start_index, 18918c2ecf20Sopenharmony_ci packet->rdesc_count, 1); 18928c2ecf20Sopenharmony_ci 18938c2ecf20Sopenharmony_ci /* Make sure ownership is written to the descriptor */ 18948c2ecf20Sopenharmony_ci smp_wmb(); 18958c2ecf20Sopenharmony_ci 18968c2ecf20Sopenharmony_ci ring->cur = cur_index + 1; 18978c2ecf20Sopenharmony_ci if (!netdev_xmit_more() || 18988c2ecf20Sopenharmony_ci netif_xmit_stopped(netdev_get_tx_queue(pdata->netdev, 18998c2ecf20Sopenharmony_ci channel->queue_index))) 19008c2ecf20Sopenharmony_ci xgbe_tx_start_xmit(channel, ring); 19018c2ecf20Sopenharmony_ci else 19028c2ecf20Sopenharmony_ci ring->tx.xmit_more = 1; 19038c2ecf20Sopenharmony_ci 19048c2ecf20Sopenharmony_ci DBGPR(" %s: descriptors %u to %u written\n", 19058c2ecf20Sopenharmony_ci channel->name, start_index & (ring->rdesc_count - 1), 19068c2ecf20Sopenharmony_ci (ring->cur - 1) & (ring->rdesc_count - 1)); 19078c2ecf20Sopenharmony_ci 19088c2ecf20Sopenharmony_ci DBGPR("<--xgbe_dev_xmit\n"); 19098c2ecf20Sopenharmony_ci} 19108c2ecf20Sopenharmony_ci 19118c2ecf20Sopenharmony_cistatic int xgbe_dev_read(struct xgbe_channel *channel) 19128c2ecf20Sopenharmony_ci{ 19138c2ecf20Sopenharmony_ci struct xgbe_prv_data *pdata = channel->pdata; 19148c2ecf20Sopenharmony_ci struct xgbe_ring *ring = channel->rx_ring; 19158c2ecf20Sopenharmony_ci struct xgbe_ring_data *rdata; 19168c2ecf20Sopenharmony_ci struct xgbe_ring_desc *rdesc; 19178c2ecf20Sopenharmony_ci struct xgbe_packet_data *packet = &ring->packet_data; 19188c2ecf20Sopenharmony_ci struct net_device *netdev = pdata->netdev; 19198c2ecf20Sopenharmony_ci unsigned int err, etlt, l34t; 19208c2ecf20Sopenharmony_ci 19218c2ecf20Sopenharmony_ci DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur); 19228c2ecf20Sopenharmony_ci 19238c2ecf20Sopenharmony_ci rdata = XGBE_GET_DESC_DATA(ring, ring->cur); 19248c2ecf20Sopenharmony_ci rdesc = rdata->rdesc; 19258c2ecf20Sopenharmony_ci 19268c2ecf20Sopenharmony_ci /* Check for data availability */ 19278c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN)) 19288c2ecf20Sopenharmony_ci return 1; 19298c2ecf20Sopenharmony_ci 19308c2ecf20Sopenharmony_ci /* Make sure descriptor fields are read after reading the OWN bit */ 19318c2ecf20Sopenharmony_ci dma_rmb(); 19328c2ecf20Sopenharmony_ci 19338c2ecf20Sopenharmony_ci if (netif_msg_rx_status(pdata)) 19348c2ecf20Sopenharmony_ci xgbe_dump_rx_desc(pdata, ring, ring->cur); 19358c2ecf20Sopenharmony_ci 19368c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) { 19378c2ecf20Sopenharmony_ci /* Timestamp Context Descriptor */ 19388c2ecf20Sopenharmony_ci xgbe_get_rx_tstamp(packet, rdesc); 19398c2ecf20Sopenharmony_ci 19408c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 19418c2ecf20Sopenharmony_ci CONTEXT, 1); 19428c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 19438c2ecf20Sopenharmony_ci CONTEXT_NEXT, 0); 19448c2ecf20Sopenharmony_ci return 0; 19458c2ecf20Sopenharmony_ci } 19468c2ecf20Sopenharmony_ci 19478c2ecf20Sopenharmony_ci /* Normal Descriptor, be sure Context Descriptor bit is off */ 19488c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0); 19498c2ecf20Sopenharmony_ci 19508c2ecf20Sopenharmony_ci /* Indicate if a Context Descriptor is next */ 19518c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA)) 19528c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 19538c2ecf20Sopenharmony_ci CONTEXT_NEXT, 1); 19548c2ecf20Sopenharmony_ci 19558c2ecf20Sopenharmony_ci /* Get the header length */ 19568c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, FD)) { 19578c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 19588c2ecf20Sopenharmony_ci FIRST, 1); 19598c2ecf20Sopenharmony_ci rdata->rx.hdr_len = XGMAC_GET_BITS_LE(rdesc->desc2, 19608c2ecf20Sopenharmony_ci RX_NORMAL_DESC2, HL); 19618c2ecf20Sopenharmony_ci if (rdata->rx.hdr_len) 19628c2ecf20Sopenharmony_ci pdata->ext_stats.rx_split_header_packets++; 19638c2ecf20Sopenharmony_ci } else { 19648c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 19658c2ecf20Sopenharmony_ci FIRST, 0); 19668c2ecf20Sopenharmony_ci } 19678c2ecf20Sopenharmony_ci 19688c2ecf20Sopenharmony_ci /* Get the RSS hash */ 19698c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, RSV)) { 19708c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 19718c2ecf20Sopenharmony_ci RSS_HASH, 1); 19728c2ecf20Sopenharmony_ci 19738c2ecf20Sopenharmony_ci packet->rss_hash = le32_to_cpu(rdesc->desc1); 19748c2ecf20Sopenharmony_ci 19758c2ecf20Sopenharmony_ci l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T); 19768c2ecf20Sopenharmony_ci switch (l34t) { 19778c2ecf20Sopenharmony_ci case RX_DESC3_L34T_IPV4_TCP: 19788c2ecf20Sopenharmony_ci case RX_DESC3_L34T_IPV4_UDP: 19798c2ecf20Sopenharmony_ci case RX_DESC3_L34T_IPV6_TCP: 19808c2ecf20Sopenharmony_ci case RX_DESC3_L34T_IPV6_UDP: 19818c2ecf20Sopenharmony_ci packet->rss_hash_type = PKT_HASH_TYPE_L4; 19828c2ecf20Sopenharmony_ci break; 19838c2ecf20Sopenharmony_ci default: 19848c2ecf20Sopenharmony_ci packet->rss_hash_type = PKT_HASH_TYPE_L3; 19858c2ecf20Sopenharmony_ci } 19868c2ecf20Sopenharmony_ci } 19878c2ecf20Sopenharmony_ci 19888c2ecf20Sopenharmony_ci /* Not all the data has been transferred for this packet */ 19898c2ecf20Sopenharmony_ci if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) 19908c2ecf20Sopenharmony_ci return 0; 19918c2ecf20Sopenharmony_ci 19928c2ecf20Sopenharmony_ci /* This is the last of the data for this packet */ 19938c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 19948c2ecf20Sopenharmony_ci LAST, 1); 19958c2ecf20Sopenharmony_ci 19968c2ecf20Sopenharmony_ci /* Get the packet length */ 19978c2ecf20Sopenharmony_ci rdata->rx.len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL); 19988c2ecf20Sopenharmony_ci 19998c2ecf20Sopenharmony_ci /* Set checksum done indicator as appropriate */ 20008c2ecf20Sopenharmony_ci if (netdev->features & NETIF_F_RXCSUM) { 20018c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 20028c2ecf20Sopenharmony_ci CSUM_DONE, 1); 20038c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 20048c2ecf20Sopenharmony_ci TNPCSUM_DONE, 1); 20058c2ecf20Sopenharmony_ci } 20068c2ecf20Sopenharmony_ci 20078c2ecf20Sopenharmony_ci /* Set the tunneled packet indicator */ 20088c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS_LE(rdesc->desc2, RX_NORMAL_DESC2, TNP)) { 20098c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 20108c2ecf20Sopenharmony_ci TNP, 1); 20118c2ecf20Sopenharmony_ci pdata->ext_stats.rx_vxlan_packets++; 20128c2ecf20Sopenharmony_ci 20138c2ecf20Sopenharmony_ci l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T); 20148c2ecf20Sopenharmony_ci switch (l34t) { 20158c2ecf20Sopenharmony_ci case RX_DESC3_L34T_IPV4_UNKNOWN: 20168c2ecf20Sopenharmony_ci case RX_DESC3_L34T_IPV6_UNKNOWN: 20178c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 20188c2ecf20Sopenharmony_ci TNPCSUM_DONE, 0); 20198c2ecf20Sopenharmony_ci break; 20208c2ecf20Sopenharmony_ci } 20218c2ecf20Sopenharmony_ci } 20228c2ecf20Sopenharmony_ci 20238c2ecf20Sopenharmony_ci /* Check for errors (only valid in last descriptor) */ 20248c2ecf20Sopenharmony_ci err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES); 20258c2ecf20Sopenharmony_ci etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT); 20268c2ecf20Sopenharmony_ci netif_dbg(pdata, rx_status, netdev, "err=%u, etlt=%#x\n", err, etlt); 20278c2ecf20Sopenharmony_ci 20288c2ecf20Sopenharmony_ci if (!err || !etlt) { 20298c2ecf20Sopenharmony_ci /* No error if err is 0 or etlt is 0 */ 20308c2ecf20Sopenharmony_ci if ((etlt == 0x09) && 20318c2ecf20Sopenharmony_ci (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) { 20328c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 20338c2ecf20Sopenharmony_ci VLAN_CTAG, 1); 20348c2ecf20Sopenharmony_ci packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0, 20358c2ecf20Sopenharmony_ci RX_NORMAL_DESC0, 20368c2ecf20Sopenharmony_ci OVT); 20378c2ecf20Sopenharmony_ci netif_dbg(pdata, rx_status, netdev, "vlan-ctag=%#06x\n", 20388c2ecf20Sopenharmony_ci packet->vlan_ctag); 20398c2ecf20Sopenharmony_ci } 20408c2ecf20Sopenharmony_ci } else { 20418c2ecf20Sopenharmony_ci unsigned int tnp = XGMAC_GET_BITS(packet->attributes, 20428c2ecf20Sopenharmony_ci RX_PACKET_ATTRIBUTES, TNP); 20438c2ecf20Sopenharmony_ci 20448c2ecf20Sopenharmony_ci if ((etlt == 0x05) || (etlt == 0x06)) { 20458c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 20468c2ecf20Sopenharmony_ci CSUM_DONE, 0); 20478c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 20488c2ecf20Sopenharmony_ci TNPCSUM_DONE, 0); 20498c2ecf20Sopenharmony_ci pdata->ext_stats.rx_csum_errors++; 20508c2ecf20Sopenharmony_ci } else if (tnp && ((etlt == 0x09) || (etlt == 0x0a))) { 20518c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 20528c2ecf20Sopenharmony_ci CSUM_DONE, 0); 20538c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, 20548c2ecf20Sopenharmony_ci TNPCSUM_DONE, 0); 20558c2ecf20Sopenharmony_ci pdata->ext_stats.rx_vxlan_csum_errors++; 20568c2ecf20Sopenharmony_ci } else { 20578c2ecf20Sopenharmony_ci XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS, 20588c2ecf20Sopenharmony_ci FRAME, 1); 20598c2ecf20Sopenharmony_ci } 20608c2ecf20Sopenharmony_ci } 20618c2ecf20Sopenharmony_ci 20628c2ecf20Sopenharmony_ci pdata->ext_stats.rxq_packets[channel->queue_index]++; 20638c2ecf20Sopenharmony_ci pdata->ext_stats.rxq_bytes[channel->queue_index] += rdata->rx.len; 20648c2ecf20Sopenharmony_ci 20658c2ecf20Sopenharmony_ci DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name, 20668c2ecf20Sopenharmony_ci ring->cur & (ring->rdesc_count - 1), ring->cur); 20678c2ecf20Sopenharmony_ci 20688c2ecf20Sopenharmony_ci return 0; 20698c2ecf20Sopenharmony_ci} 20708c2ecf20Sopenharmony_ci 20718c2ecf20Sopenharmony_cistatic int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc) 20728c2ecf20Sopenharmony_ci{ 20738c2ecf20Sopenharmony_ci /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */ 20748c2ecf20Sopenharmony_ci return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT); 20758c2ecf20Sopenharmony_ci} 20768c2ecf20Sopenharmony_ci 20778c2ecf20Sopenharmony_cistatic int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc) 20788c2ecf20Sopenharmony_ci{ 20798c2ecf20Sopenharmony_ci /* Rx and Tx share LD bit, so check TDES3.LD bit */ 20808c2ecf20Sopenharmony_ci return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD); 20818c2ecf20Sopenharmony_ci} 20828c2ecf20Sopenharmony_ci 20838c2ecf20Sopenharmony_cistatic int xgbe_enable_int(struct xgbe_channel *channel, 20848c2ecf20Sopenharmony_ci enum xgbe_int int_id) 20858c2ecf20Sopenharmony_ci{ 20868c2ecf20Sopenharmony_ci switch (int_id) { 20878c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_TI: 20888c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 1); 20898c2ecf20Sopenharmony_ci break; 20908c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_TPS: 20918c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TXSE, 1); 20928c2ecf20Sopenharmony_ci break; 20938c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_TBU: 20948c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TBUE, 1); 20958c2ecf20Sopenharmony_ci break; 20968c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_RI: 20978c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 1); 20988c2ecf20Sopenharmony_ci break; 20998c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_RBU: 21008c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RBUE, 1); 21018c2ecf20Sopenharmony_ci break; 21028c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_RPS: 21038c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RSE, 1); 21048c2ecf20Sopenharmony_ci break; 21058c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_TI_RI: 21068c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 1); 21078c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 1); 21088c2ecf20Sopenharmony_ci break; 21098c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_FBE: 21108c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, FBEE, 1); 21118c2ecf20Sopenharmony_ci break; 21128c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_ALL: 21138c2ecf20Sopenharmony_ci channel->curr_ier |= channel->saved_ier; 21148c2ecf20Sopenharmony_ci break; 21158c2ecf20Sopenharmony_ci default: 21168c2ecf20Sopenharmony_ci return -1; 21178c2ecf20Sopenharmony_ci } 21188c2ecf20Sopenharmony_ci 21198c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, channel->curr_ier); 21208c2ecf20Sopenharmony_ci 21218c2ecf20Sopenharmony_ci return 0; 21228c2ecf20Sopenharmony_ci} 21238c2ecf20Sopenharmony_ci 21248c2ecf20Sopenharmony_cistatic int xgbe_disable_int(struct xgbe_channel *channel, 21258c2ecf20Sopenharmony_ci enum xgbe_int int_id) 21268c2ecf20Sopenharmony_ci{ 21278c2ecf20Sopenharmony_ci switch (int_id) { 21288c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_TI: 21298c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 0); 21308c2ecf20Sopenharmony_ci break; 21318c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_TPS: 21328c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TXSE, 0); 21338c2ecf20Sopenharmony_ci break; 21348c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_TBU: 21358c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TBUE, 0); 21368c2ecf20Sopenharmony_ci break; 21378c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_RI: 21388c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 0); 21398c2ecf20Sopenharmony_ci break; 21408c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_RBU: 21418c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RBUE, 0); 21428c2ecf20Sopenharmony_ci break; 21438c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_RPS: 21448c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RSE, 0); 21458c2ecf20Sopenharmony_ci break; 21468c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_TI_RI: 21478c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 0); 21488c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 0); 21498c2ecf20Sopenharmony_ci break; 21508c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_CH_SR_FBE: 21518c2ecf20Sopenharmony_ci XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, FBEE, 0); 21528c2ecf20Sopenharmony_ci break; 21538c2ecf20Sopenharmony_ci case XGMAC_INT_DMA_ALL: 21548c2ecf20Sopenharmony_ci channel->saved_ier = channel->curr_ier; 21558c2ecf20Sopenharmony_ci channel->curr_ier = 0; 21568c2ecf20Sopenharmony_ci break; 21578c2ecf20Sopenharmony_ci default: 21588c2ecf20Sopenharmony_ci return -1; 21598c2ecf20Sopenharmony_ci } 21608c2ecf20Sopenharmony_ci 21618c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, channel->curr_ier); 21628c2ecf20Sopenharmony_ci 21638c2ecf20Sopenharmony_ci return 0; 21648c2ecf20Sopenharmony_ci} 21658c2ecf20Sopenharmony_ci 21668c2ecf20Sopenharmony_cistatic int __xgbe_exit(struct xgbe_prv_data *pdata) 21678c2ecf20Sopenharmony_ci{ 21688c2ecf20Sopenharmony_ci unsigned int count = 2000; 21698c2ecf20Sopenharmony_ci 21708c2ecf20Sopenharmony_ci DBGPR("-->xgbe_exit\n"); 21718c2ecf20Sopenharmony_ci 21728c2ecf20Sopenharmony_ci /* Issue a software reset */ 21738c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1); 21748c2ecf20Sopenharmony_ci usleep_range(10, 15); 21758c2ecf20Sopenharmony_ci 21768c2ecf20Sopenharmony_ci /* Poll Until Poll Condition */ 21778c2ecf20Sopenharmony_ci while (--count && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR)) 21788c2ecf20Sopenharmony_ci usleep_range(500, 600); 21798c2ecf20Sopenharmony_ci 21808c2ecf20Sopenharmony_ci if (!count) 21818c2ecf20Sopenharmony_ci return -EBUSY; 21828c2ecf20Sopenharmony_ci 21838c2ecf20Sopenharmony_ci DBGPR("<--xgbe_exit\n"); 21848c2ecf20Sopenharmony_ci 21858c2ecf20Sopenharmony_ci return 0; 21868c2ecf20Sopenharmony_ci} 21878c2ecf20Sopenharmony_ci 21888c2ecf20Sopenharmony_cistatic int xgbe_exit(struct xgbe_prv_data *pdata) 21898c2ecf20Sopenharmony_ci{ 21908c2ecf20Sopenharmony_ci int ret; 21918c2ecf20Sopenharmony_ci 21928c2ecf20Sopenharmony_ci /* To guard against possible incorrectly generated interrupts, 21938c2ecf20Sopenharmony_ci * issue the software reset twice. 21948c2ecf20Sopenharmony_ci */ 21958c2ecf20Sopenharmony_ci ret = __xgbe_exit(pdata); 21968c2ecf20Sopenharmony_ci if (ret) 21978c2ecf20Sopenharmony_ci return ret; 21988c2ecf20Sopenharmony_ci 21998c2ecf20Sopenharmony_ci return __xgbe_exit(pdata); 22008c2ecf20Sopenharmony_ci} 22018c2ecf20Sopenharmony_ci 22028c2ecf20Sopenharmony_cistatic int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata) 22038c2ecf20Sopenharmony_ci{ 22048c2ecf20Sopenharmony_ci unsigned int i, count; 22058c2ecf20Sopenharmony_ci 22068c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21) 22078c2ecf20Sopenharmony_ci return 0; 22088c2ecf20Sopenharmony_ci 22098c2ecf20Sopenharmony_ci for (i = 0; i < pdata->tx_q_count; i++) 22108c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1); 22118c2ecf20Sopenharmony_ci 22128c2ecf20Sopenharmony_ci /* Poll Until Poll Condition */ 22138c2ecf20Sopenharmony_ci for (i = 0; i < pdata->tx_q_count; i++) { 22148c2ecf20Sopenharmony_ci count = 2000; 22158c2ecf20Sopenharmony_ci while (--count && XGMAC_MTL_IOREAD_BITS(pdata, i, 22168c2ecf20Sopenharmony_ci MTL_Q_TQOMR, FTQ)) 22178c2ecf20Sopenharmony_ci usleep_range(500, 600); 22188c2ecf20Sopenharmony_ci 22198c2ecf20Sopenharmony_ci if (!count) 22208c2ecf20Sopenharmony_ci return -EBUSY; 22218c2ecf20Sopenharmony_ci } 22228c2ecf20Sopenharmony_ci 22238c2ecf20Sopenharmony_ci return 0; 22248c2ecf20Sopenharmony_ci} 22258c2ecf20Sopenharmony_ci 22268c2ecf20Sopenharmony_cistatic void xgbe_config_dma_bus(struct xgbe_prv_data *pdata) 22278c2ecf20Sopenharmony_ci{ 22288c2ecf20Sopenharmony_ci unsigned int sbmr; 22298c2ecf20Sopenharmony_ci 22308c2ecf20Sopenharmony_ci sbmr = XGMAC_IOREAD(pdata, DMA_SBMR); 22318c2ecf20Sopenharmony_ci 22328c2ecf20Sopenharmony_ci /* Set enhanced addressing mode */ 22338c2ecf20Sopenharmony_ci XGMAC_SET_BITS(sbmr, DMA_SBMR, EAME, 1); 22348c2ecf20Sopenharmony_ci 22358c2ecf20Sopenharmony_ci /* Set the System Bus mode */ 22368c2ecf20Sopenharmony_ci XGMAC_SET_BITS(sbmr, DMA_SBMR, UNDEF, 1); 22378c2ecf20Sopenharmony_ci XGMAC_SET_BITS(sbmr, DMA_SBMR, BLEN, pdata->blen >> 2); 22388c2ecf20Sopenharmony_ci XGMAC_SET_BITS(sbmr, DMA_SBMR, AAL, pdata->aal); 22398c2ecf20Sopenharmony_ci XGMAC_SET_BITS(sbmr, DMA_SBMR, RD_OSR_LMT, pdata->rd_osr_limit - 1); 22408c2ecf20Sopenharmony_ci XGMAC_SET_BITS(sbmr, DMA_SBMR, WR_OSR_LMT, pdata->wr_osr_limit - 1); 22418c2ecf20Sopenharmony_ci 22428c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, DMA_SBMR, sbmr); 22438c2ecf20Sopenharmony_ci 22448c2ecf20Sopenharmony_ci /* Set descriptor fetching threshold */ 22458c2ecf20Sopenharmony_ci if (pdata->vdata->tx_desc_prefetch) 22468c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, DMA_TXEDMACR, TDPS, 22478c2ecf20Sopenharmony_ci pdata->vdata->tx_desc_prefetch); 22488c2ecf20Sopenharmony_ci 22498c2ecf20Sopenharmony_ci if (pdata->vdata->rx_desc_prefetch) 22508c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, DMA_RXEDMACR, RDPS, 22518c2ecf20Sopenharmony_ci pdata->vdata->rx_desc_prefetch); 22528c2ecf20Sopenharmony_ci} 22538c2ecf20Sopenharmony_ci 22548c2ecf20Sopenharmony_cistatic void xgbe_config_dma_cache(struct xgbe_prv_data *pdata) 22558c2ecf20Sopenharmony_ci{ 22568c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, DMA_AXIARCR, pdata->arcr); 22578c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, DMA_AXIAWCR, pdata->awcr); 22588c2ecf20Sopenharmony_ci if (pdata->awarcr) 22598c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, DMA_AXIAWARCR, pdata->awarcr); 22608c2ecf20Sopenharmony_ci} 22618c2ecf20Sopenharmony_ci 22628c2ecf20Sopenharmony_cistatic void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata) 22638c2ecf20Sopenharmony_ci{ 22648c2ecf20Sopenharmony_ci unsigned int i; 22658c2ecf20Sopenharmony_ci 22668c2ecf20Sopenharmony_ci /* Set Tx to weighted round robin scheduling algorithm */ 22678c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR); 22688c2ecf20Sopenharmony_ci 22698c2ecf20Sopenharmony_ci /* Set Tx traffic classes to use WRR algorithm with equal weights */ 22708c2ecf20Sopenharmony_ci for (i = 0; i < pdata->hw_feat.tc_cnt; i++) { 22718c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA, 22728c2ecf20Sopenharmony_ci MTL_TSA_ETS); 22738c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1); 22748c2ecf20Sopenharmony_ci } 22758c2ecf20Sopenharmony_ci 22768c2ecf20Sopenharmony_ci /* Set Rx to strict priority algorithm */ 22778c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP); 22788c2ecf20Sopenharmony_ci} 22798c2ecf20Sopenharmony_ci 22808c2ecf20Sopenharmony_cistatic void xgbe_queue_flow_control_threshold(struct xgbe_prv_data *pdata, 22818c2ecf20Sopenharmony_ci unsigned int queue, 22828c2ecf20Sopenharmony_ci unsigned int q_fifo_size) 22838c2ecf20Sopenharmony_ci{ 22848c2ecf20Sopenharmony_ci unsigned int frame_fifo_size; 22858c2ecf20Sopenharmony_ci unsigned int rfa, rfd; 22868c2ecf20Sopenharmony_ci 22878c2ecf20Sopenharmony_ci frame_fifo_size = XGMAC_FLOW_CONTROL_ALIGN(xgbe_get_max_frame(pdata)); 22888c2ecf20Sopenharmony_ci 22898c2ecf20Sopenharmony_ci if (pdata->pfcq[queue] && (q_fifo_size > pdata->pfc_rfa)) { 22908c2ecf20Sopenharmony_ci /* PFC is active for this queue */ 22918c2ecf20Sopenharmony_ci rfa = pdata->pfc_rfa; 22928c2ecf20Sopenharmony_ci rfd = rfa + frame_fifo_size; 22938c2ecf20Sopenharmony_ci if (rfd > XGMAC_FLOW_CONTROL_MAX) 22948c2ecf20Sopenharmony_ci rfd = XGMAC_FLOW_CONTROL_MAX; 22958c2ecf20Sopenharmony_ci if (rfa >= XGMAC_FLOW_CONTROL_MAX) 22968c2ecf20Sopenharmony_ci rfa = XGMAC_FLOW_CONTROL_MAX - XGMAC_FLOW_CONTROL_UNIT; 22978c2ecf20Sopenharmony_ci } else { 22988c2ecf20Sopenharmony_ci /* This path deals with just maximum frame sizes which are 22998c2ecf20Sopenharmony_ci * limited to a jumbo frame of 9,000 (plus headers, etc.) 23008c2ecf20Sopenharmony_ci * so we can never exceed the maximum allowable RFA/RFD 23018c2ecf20Sopenharmony_ci * values. 23028c2ecf20Sopenharmony_ci */ 23038c2ecf20Sopenharmony_ci if (q_fifo_size <= 2048) { 23048c2ecf20Sopenharmony_ci /* rx_rfd to zero to signal no flow control */ 23058c2ecf20Sopenharmony_ci pdata->rx_rfa[queue] = 0; 23068c2ecf20Sopenharmony_ci pdata->rx_rfd[queue] = 0; 23078c2ecf20Sopenharmony_ci return; 23088c2ecf20Sopenharmony_ci } 23098c2ecf20Sopenharmony_ci 23108c2ecf20Sopenharmony_ci if (q_fifo_size <= 4096) { 23118c2ecf20Sopenharmony_ci /* Between 2048 and 4096 */ 23128c2ecf20Sopenharmony_ci pdata->rx_rfa[queue] = 0; /* Full - 1024 bytes */ 23138c2ecf20Sopenharmony_ci pdata->rx_rfd[queue] = 1; /* Full - 1536 bytes */ 23148c2ecf20Sopenharmony_ci return; 23158c2ecf20Sopenharmony_ci } 23168c2ecf20Sopenharmony_ci 23178c2ecf20Sopenharmony_ci if (q_fifo_size <= frame_fifo_size) { 23188c2ecf20Sopenharmony_ci /* Between 4096 and max-frame */ 23198c2ecf20Sopenharmony_ci pdata->rx_rfa[queue] = 2; /* Full - 2048 bytes */ 23208c2ecf20Sopenharmony_ci pdata->rx_rfd[queue] = 5; /* Full - 3584 bytes */ 23218c2ecf20Sopenharmony_ci return; 23228c2ecf20Sopenharmony_ci } 23238c2ecf20Sopenharmony_ci 23248c2ecf20Sopenharmony_ci if (q_fifo_size <= (frame_fifo_size * 3)) { 23258c2ecf20Sopenharmony_ci /* Between max-frame and 3 max-frames, 23268c2ecf20Sopenharmony_ci * trigger if we get just over a frame of data and 23278c2ecf20Sopenharmony_ci * resume when we have just under half a frame left. 23288c2ecf20Sopenharmony_ci */ 23298c2ecf20Sopenharmony_ci rfa = q_fifo_size - frame_fifo_size; 23308c2ecf20Sopenharmony_ci rfd = rfa + (frame_fifo_size / 2); 23318c2ecf20Sopenharmony_ci } else { 23328c2ecf20Sopenharmony_ci /* Above 3 max-frames - trigger when just over 23338c2ecf20Sopenharmony_ci * 2 frames of space available 23348c2ecf20Sopenharmony_ci */ 23358c2ecf20Sopenharmony_ci rfa = frame_fifo_size * 2; 23368c2ecf20Sopenharmony_ci rfa += XGMAC_FLOW_CONTROL_UNIT; 23378c2ecf20Sopenharmony_ci rfd = rfa + frame_fifo_size; 23388c2ecf20Sopenharmony_ci } 23398c2ecf20Sopenharmony_ci } 23408c2ecf20Sopenharmony_ci 23418c2ecf20Sopenharmony_ci pdata->rx_rfa[queue] = XGMAC_FLOW_CONTROL_VALUE(rfa); 23428c2ecf20Sopenharmony_ci pdata->rx_rfd[queue] = XGMAC_FLOW_CONTROL_VALUE(rfd); 23438c2ecf20Sopenharmony_ci} 23448c2ecf20Sopenharmony_ci 23458c2ecf20Sopenharmony_cistatic void xgbe_calculate_flow_control_threshold(struct xgbe_prv_data *pdata, 23468c2ecf20Sopenharmony_ci unsigned int *fifo) 23478c2ecf20Sopenharmony_ci{ 23488c2ecf20Sopenharmony_ci unsigned int q_fifo_size; 23498c2ecf20Sopenharmony_ci unsigned int i; 23508c2ecf20Sopenharmony_ci 23518c2ecf20Sopenharmony_ci for (i = 0; i < pdata->rx_q_count; i++) { 23528c2ecf20Sopenharmony_ci q_fifo_size = (fifo[i] + 1) * XGMAC_FIFO_UNIT; 23538c2ecf20Sopenharmony_ci 23548c2ecf20Sopenharmony_ci xgbe_queue_flow_control_threshold(pdata, i, q_fifo_size); 23558c2ecf20Sopenharmony_ci } 23568c2ecf20Sopenharmony_ci} 23578c2ecf20Sopenharmony_ci 23588c2ecf20Sopenharmony_cistatic void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata) 23598c2ecf20Sopenharmony_ci{ 23608c2ecf20Sopenharmony_ci unsigned int i; 23618c2ecf20Sopenharmony_ci 23628c2ecf20Sopenharmony_ci for (i = 0; i < pdata->rx_q_count; i++) { 23638c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFA, 23648c2ecf20Sopenharmony_ci pdata->rx_rfa[i]); 23658c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFD, 23668c2ecf20Sopenharmony_ci pdata->rx_rfd[i]); 23678c2ecf20Sopenharmony_ci } 23688c2ecf20Sopenharmony_ci} 23698c2ecf20Sopenharmony_ci 23708c2ecf20Sopenharmony_cistatic unsigned int xgbe_get_tx_fifo_size(struct xgbe_prv_data *pdata) 23718c2ecf20Sopenharmony_ci{ 23728c2ecf20Sopenharmony_ci /* The configured value may not be the actual amount of fifo RAM */ 23738c2ecf20Sopenharmony_ci return min_t(unsigned int, pdata->tx_max_fifo_size, 23748c2ecf20Sopenharmony_ci pdata->hw_feat.tx_fifo_size); 23758c2ecf20Sopenharmony_ci} 23768c2ecf20Sopenharmony_ci 23778c2ecf20Sopenharmony_cistatic unsigned int xgbe_get_rx_fifo_size(struct xgbe_prv_data *pdata) 23788c2ecf20Sopenharmony_ci{ 23798c2ecf20Sopenharmony_ci /* The configured value may not be the actual amount of fifo RAM */ 23808c2ecf20Sopenharmony_ci return min_t(unsigned int, pdata->rx_max_fifo_size, 23818c2ecf20Sopenharmony_ci pdata->hw_feat.rx_fifo_size); 23828c2ecf20Sopenharmony_ci} 23838c2ecf20Sopenharmony_ci 23848c2ecf20Sopenharmony_cistatic void xgbe_calculate_equal_fifo(unsigned int fifo_size, 23858c2ecf20Sopenharmony_ci unsigned int queue_count, 23868c2ecf20Sopenharmony_ci unsigned int *fifo) 23878c2ecf20Sopenharmony_ci{ 23888c2ecf20Sopenharmony_ci unsigned int q_fifo_size; 23898c2ecf20Sopenharmony_ci unsigned int p_fifo; 23908c2ecf20Sopenharmony_ci unsigned int i; 23918c2ecf20Sopenharmony_ci 23928c2ecf20Sopenharmony_ci q_fifo_size = fifo_size / queue_count; 23938c2ecf20Sopenharmony_ci 23948c2ecf20Sopenharmony_ci /* Calculate the fifo setting by dividing the queue's fifo size 23958c2ecf20Sopenharmony_ci * by the fifo allocation increment (with 0 representing the 23968c2ecf20Sopenharmony_ci * base allocation increment so decrement the result by 1). 23978c2ecf20Sopenharmony_ci */ 23988c2ecf20Sopenharmony_ci p_fifo = q_fifo_size / XGMAC_FIFO_UNIT; 23998c2ecf20Sopenharmony_ci if (p_fifo) 24008c2ecf20Sopenharmony_ci p_fifo--; 24018c2ecf20Sopenharmony_ci 24028c2ecf20Sopenharmony_ci /* Distribute the fifo equally amongst the queues */ 24038c2ecf20Sopenharmony_ci for (i = 0; i < queue_count; i++) 24048c2ecf20Sopenharmony_ci fifo[i] = p_fifo; 24058c2ecf20Sopenharmony_ci} 24068c2ecf20Sopenharmony_ci 24078c2ecf20Sopenharmony_cistatic unsigned int xgbe_set_nonprio_fifos(unsigned int fifo_size, 24088c2ecf20Sopenharmony_ci unsigned int queue_count, 24098c2ecf20Sopenharmony_ci unsigned int *fifo) 24108c2ecf20Sopenharmony_ci{ 24118c2ecf20Sopenharmony_ci unsigned int i; 24128c2ecf20Sopenharmony_ci 24138c2ecf20Sopenharmony_ci BUILD_BUG_ON_NOT_POWER_OF_2(XGMAC_FIFO_MIN_ALLOC); 24148c2ecf20Sopenharmony_ci 24158c2ecf20Sopenharmony_ci if (queue_count <= IEEE_8021QAZ_MAX_TCS) 24168c2ecf20Sopenharmony_ci return fifo_size; 24178c2ecf20Sopenharmony_ci 24188c2ecf20Sopenharmony_ci /* Rx queues 9 and up are for specialized packets, 24198c2ecf20Sopenharmony_ci * such as PTP or DCB control packets, etc. and 24208c2ecf20Sopenharmony_ci * don't require a large fifo 24218c2ecf20Sopenharmony_ci */ 24228c2ecf20Sopenharmony_ci for (i = IEEE_8021QAZ_MAX_TCS; i < queue_count; i++) { 24238c2ecf20Sopenharmony_ci fifo[i] = (XGMAC_FIFO_MIN_ALLOC / XGMAC_FIFO_UNIT) - 1; 24248c2ecf20Sopenharmony_ci fifo_size -= XGMAC_FIFO_MIN_ALLOC; 24258c2ecf20Sopenharmony_ci } 24268c2ecf20Sopenharmony_ci 24278c2ecf20Sopenharmony_ci return fifo_size; 24288c2ecf20Sopenharmony_ci} 24298c2ecf20Sopenharmony_ci 24308c2ecf20Sopenharmony_cistatic unsigned int xgbe_get_pfc_delay(struct xgbe_prv_data *pdata) 24318c2ecf20Sopenharmony_ci{ 24328c2ecf20Sopenharmony_ci unsigned int delay; 24338c2ecf20Sopenharmony_ci 24348c2ecf20Sopenharmony_ci /* If a delay has been provided, use that */ 24358c2ecf20Sopenharmony_ci if (pdata->pfc->delay) 24368c2ecf20Sopenharmony_ci return pdata->pfc->delay / 8; 24378c2ecf20Sopenharmony_ci 24388c2ecf20Sopenharmony_ci /* Allow for two maximum size frames */ 24398c2ecf20Sopenharmony_ci delay = xgbe_get_max_frame(pdata); 24408c2ecf20Sopenharmony_ci delay += XGMAC_ETH_PREAMBLE; 24418c2ecf20Sopenharmony_ci delay *= 2; 24428c2ecf20Sopenharmony_ci 24438c2ecf20Sopenharmony_ci /* Allow for PFC frame */ 24448c2ecf20Sopenharmony_ci delay += XGMAC_PFC_DATA_LEN; 24458c2ecf20Sopenharmony_ci delay += ETH_HLEN + ETH_FCS_LEN; 24468c2ecf20Sopenharmony_ci delay += XGMAC_ETH_PREAMBLE; 24478c2ecf20Sopenharmony_ci 24488c2ecf20Sopenharmony_ci /* Allow for miscellaneous delays (LPI exit, cable, etc.) */ 24498c2ecf20Sopenharmony_ci delay += XGMAC_PFC_DELAYS; 24508c2ecf20Sopenharmony_ci 24518c2ecf20Sopenharmony_ci return delay; 24528c2ecf20Sopenharmony_ci} 24538c2ecf20Sopenharmony_ci 24548c2ecf20Sopenharmony_cistatic unsigned int xgbe_get_pfc_queues(struct xgbe_prv_data *pdata) 24558c2ecf20Sopenharmony_ci{ 24568c2ecf20Sopenharmony_ci unsigned int count, prio_queues; 24578c2ecf20Sopenharmony_ci unsigned int i; 24588c2ecf20Sopenharmony_ci 24598c2ecf20Sopenharmony_ci if (!pdata->pfc->pfc_en) 24608c2ecf20Sopenharmony_ci return 0; 24618c2ecf20Sopenharmony_ci 24628c2ecf20Sopenharmony_ci count = 0; 24638c2ecf20Sopenharmony_ci prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count); 24648c2ecf20Sopenharmony_ci for (i = 0; i < prio_queues; i++) { 24658c2ecf20Sopenharmony_ci if (!xgbe_is_pfc_queue(pdata, i)) 24668c2ecf20Sopenharmony_ci continue; 24678c2ecf20Sopenharmony_ci 24688c2ecf20Sopenharmony_ci pdata->pfcq[i] = 1; 24698c2ecf20Sopenharmony_ci count++; 24708c2ecf20Sopenharmony_ci } 24718c2ecf20Sopenharmony_ci 24728c2ecf20Sopenharmony_ci return count; 24738c2ecf20Sopenharmony_ci} 24748c2ecf20Sopenharmony_ci 24758c2ecf20Sopenharmony_cistatic void xgbe_calculate_dcb_fifo(struct xgbe_prv_data *pdata, 24768c2ecf20Sopenharmony_ci unsigned int fifo_size, 24778c2ecf20Sopenharmony_ci unsigned int *fifo) 24788c2ecf20Sopenharmony_ci{ 24798c2ecf20Sopenharmony_ci unsigned int q_fifo_size, rem_fifo, addn_fifo; 24808c2ecf20Sopenharmony_ci unsigned int prio_queues; 24818c2ecf20Sopenharmony_ci unsigned int pfc_count; 24828c2ecf20Sopenharmony_ci unsigned int i; 24838c2ecf20Sopenharmony_ci 24848c2ecf20Sopenharmony_ci q_fifo_size = XGMAC_FIFO_ALIGN(xgbe_get_max_frame(pdata)); 24858c2ecf20Sopenharmony_ci prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count); 24868c2ecf20Sopenharmony_ci pfc_count = xgbe_get_pfc_queues(pdata); 24878c2ecf20Sopenharmony_ci 24888c2ecf20Sopenharmony_ci if (!pfc_count || ((q_fifo_size * prio_queues) > fifo_size)) { 24898c2ecf20Sopenharmony_ci /* No traffic classes with PFC enabled or can't do lossless */ 24908c2ecf20Sopenharmony_ci xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo); 24918c2ecf20Sopenharmony_ci return; 24928c2ecf20Sopenharmony_ci } 24938c2ecf20Sopenharmony_ci 24948c2ecf20Sopenharmony_ci /* Calculate how much fifo we have to play with */ 24958c2ecf20Sopenharmony_ci rem_fifo = fifo_size - (q_fifo_size * prio_queues); 24968c2ecf20Sopenharmony_ci 24978c2ecf20Sopenharmony_ci /* Calculate how much more than base fifo PFC needs, which also 24988c2ecf20Sopenharmony_ci * becomes the threshold activation point (RFA) 24998c2ecf20Sopenharmony_ci */ 25008c2ecf20Sopenharmony_ci pdata->pfc_rfa = xgbe_get_pfc_delay(pdata); 25018c2ecf20Sopenharmony_ci pdata->pfc_rfa = XGMAC_FLOW_CONTROL_ALIGN(pdata->pfc_rfa); 25028c2ecf20Sopenharmony_ci 25038c2ecf20Sopenharmony_ci if (pdata->pfc_rfa > q_fifo_size) { 25048c2ecf20Sopenharmony_ci addn_fifo = pdata->pfc_rfa - q_fifo_size; 25058c2ecf20Sopenharmony_ci addn_fifo = XGMAC_FIFO_ALIGN(addn_fifo); 25068c2ecf20Sopenharmony_ci } else { 25078c2ecf20Sopenharmony_ci addn_fifo = 0; 25088c2ecf20Sopenharmony_ci } 25098c2ecf20Sopenharmony_ci 25108c2ecf20Sopenharmony_ci /* Calculate DCB fifo settings: 25118c2ecf20Sopenharmony_ci * - distribute remaining fifo between the VLAN priority 25128c2ecf20Sopenharmony_ci * queues based on traffic class PFC enablement and overall 25138c2ecf20Sopenharmony_ci * priority (0 is lowest priority, so start at highest) 25148c2ecf20Sopenharmony_ci */ 25158c2ecf20Sopenharmony_ci i = prio_queues; 25168c2ecf20Sopenharmony_ci while (i > 0) { 25178c2ecf20Sopenharmony_ci i--; 25188c2ecf20Sopenharmony_ci 25198c2ecf20Sopenharmony_ci fifo[i] = (q_fifo_size / XGMAC_FIFO_UNIT) - 1; 25208c2ecf20Sopenharmony_ci 25218c2ecf20Sopenharmony_ci if (!pdata->pfcq[i] || !addn_fifo) 25228c2ecf20Sopenharmony_ci continue; 25238c2ecf20Sopenharmony_ci 25248c2ecf20Sopenharmony_ci if (addn_fifo > rem_fifo) { 25258c2ecf20Sopenharmony_ci netdev_warn(pdata->netdev, 25268c2ecf20Sopenharmony_ci "RXq%u cannot set needed fifo size\n", i); 25278c2ecf20Sopenharmony_ci if (!rem_fifo) 25288c2ecf20Sopenharmony_ci continue; 25298c2ecf20Sopenharmony_ci 25308c2ecf20Sopenharmony_ci addn_fifo = rem_fifo; 25318c2ecf20Sopenharmony_ci } 25328c2ecf20Sopenharmony_ci 25338c2ecf20Sopenharmony_ci fifo[i] += (addn_fifo / XGMAC_FIFO_UNIT); 25348c2ecf20Sopenharmony_ci rem_fifo -= addn_fifo; 25358c2ecf20Sopenharmony_ci } 25368c2ecf20Sopenharmony_ci 25378c2ecf20Sopenharmony_ci if (rem_fifo) { 25388c2ecf20Sopenharmony_ci unsigned int inc_fifo = rem_fifo / prio_queues; 25398c2ecf20Sopenharmony_ci 25408c2ecf20Sopenharmony_ci /* Distribute remaining fifo across queues */ 25418c2ecf20Sopenharmony_ci for (i = 0; i < prio_queues; i++) 25428c2ecf20Sopenharmony_ci fifo[i] += (inc_fifo / XGMAC_FIFO_UNIT); 25438c2ecf20Sopenharmony_ci } 25448c2ecf20Sopenharmony_ci} 25458c2ecf20Sopenharmony_ci 25468c2ecf20Sopenharmony_cistatic void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata) 25478c2ecf20Sopenharmony_ci{ 25488c2ecf20Sopenharmony_ci unsigned int fifo_size; 25498c2ecf20Sopenharmony_ci unsigned int fifo[XGBE_MAX_QUEUES]; 25508c2ecf20Sopenharmony_ci unsigned int i; 25518c2ecf20Sopenharmony_ci 25528c2ecf20Sopenharmony_ci fifo_size = xgbe_get_tx_fifo_size(pdata); 25538c2ecf20Sopenharmony_ci 25548c2ecf20Sopenharmony_ci xgbe_calculate_equal_fifo(fifo_size, pdata->tx_q_count, fifo); 25558c2ecf20Sopenharmony_ci 25568c2ecf20Sopenharmony_ci for (i = 0; i < pdata->tx_q_count; i++) 25578c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo[i]); 25588c2ecf20Sopenharmony_ci 25598c2ecf20Sopenharmony_ci netif_info(pdata, drv, pdata->netdev, 25608c2ecf20Sopenharmony_ci "%d Tx hardware queues, %d byte fifo per queue\n", 25618c2ecf20Sopenharmony_ci pdata->tx_q_count, ((fifo[0] + 1) * XGMAC_FIFO_UNIT)); 25628c2ecf20Sopenharmony_ci} 25638c2ecf20Sopenharmony_ci 25648c2ecf20Sopenharmony_cistatic void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata) 25658c2ecf20Sopenharmony_ci{ 25668c2ecf20Sopenharmony_ci unsigned int fifo_size; 25678c2ecf20Sopenharmony_ci unsigned int fifo[XGBE_MAX_QUEUES]; 25688c2ecf20Sopenharmony_ci unsigned int prio_queues; 25698c2ecf20Sopenharmony_ci unsigned int i; 25708c2ecf20Sopenharmony_ci 25718c2ecf20Sopenharmony_ci /* Clear any DCB related fifo/queue information */ 25728c2ecf20Sopenharmony_ci memset(pdata->pfcq, 0, sizeof(pdata->pfcq)); 25738c2ecf20Sopenharmony_ci pdata->pfc_rfa = 0; 25748c2ecf20Sopenharmony_ci 25758c2ecf20Sopenharmony_ci fifo_size = xgbe_get_rx_fifo_size(pdata); 25768c2ecf20Sopenharmony_ci prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count); 25778c2ecf20Sopenharmony_ci 25788c2ecf20Sopenharmony_ci /* Assign a minimum fifo to the non-VLAN priority queues */ 25798c2ecf20Sopenharmony_ci fifo_size = xgbe_set_nonprio_fifos(fifo_size, pdata->rx_q_count, fifo); 25808c2ecf20Sopenharmony_ci 25818c2ecf20Sopenharmony_ci if (pdata->pfc && pdata->ets) 25828c2ecf20Sopenharmony_ci xgbe_calculate_dcb_fifo(pdata, fifo_size, fifo); 25838c2ecf20Sopenharmony_ci else 25848c2ecf20Sopenharmony_ci xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo); 25858c2ecf20Sopenharmony_ci 25868c2ecf20Sopenharmony_ci for (i = 0; i < pdata->rx_q_count; i++) 25878c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo[i]); 25888c2ecf20Sopenharmony_ci 25898c2ecf20Sopenharmony_ci xgbe_calculate_flow_control_threshold(pdata, fifo); 25908c2ecf20Sopenharmony_ci xgbe_config_flow_control_threshold(pdata); 25918c2ecf20Sopenharmony_ci 25928c2ecf20Sopenharmony_ci if (pdata->pfc && pdata->ets && pdata->pfc->pfc_en) { 25938c2ecf20Sopenharmony_ci netif_info(pdata, drv, pdata->netdev, 25948c2ecf20Sopenharmony_ci "%u Rx hardware queues\n", pdata->rx_q_count); 25958c2ecf20Sopenharmony_ci for (i = 0; i < pdata->rx_q_count; i++) 25968c2ecf20Sopenharmony_ci netif_info(pdata, drv, pdata->netdev, 25978c2ecf20Sopenharmony_ci "RxQ%u, %u byte fifo queue\n", i, 25988c2ecf20Sopenharmony_ci ((fifo[i] + 1) * XGMAC_FIFO_UNIT)); 25998c2ecf20Sopenharmony_ci } else { 26008c2ecf20Sopenharmony_ci netif_info(pdata, drv, pdata->netdev, 26018c2ecf20Sopenharmony_ci "%u Rx hardware queues, %u byte fifo per queue\n", 26028c2ecf20Sopenharmony_ci pdata->rx_q_count, 26038c2ecf20Sopenharmony_ci ((fifo[0] + 1) * XGMAC_FIFO_UNIT)); 26048c2ecf20Sopenharmony_ci } 26058c2ecf20Sopenharmony_ci} 26068c2ecf20Sopenharmony_ci 26078c2ecf20Sopenharmony_cistatic void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata) 26088c2ecf20Sopenharmony_ci{ 26098c2ecf20Sopenharmony_ci unsigned int qptc, qptc_extra, queue; 26108c2ecf20Sopenharmony_ci unsigned int prio_queues; 26118c2ecf20Sopenharmony_ci unsigned int ppq, ppq_extra, prio; 26128c2ecf20Sopenharmony_ci unsigned int mask; 26138c2ecf20Sopenharmony_ci unsigned int i, j, reg, reg_val; 26148c2ecf20Sopenharmony_ci 26158c2ecf20Sopenharmony_ci /* Map the MTL Tx Queues to Traffic Classes 26168c2ecf20Sopenharmony_ci * Note: Tx Queues >= Traffic Classes 26178c2ecf20Sopenharmony_ci */ 26188c2ecf20Sopenharmony_ci qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt; 26198c2ecf20Sopenharmony_ci qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt; 26208c2ecf20Sopenharmony_ci 26218c2ecf20Sopenharmony_ci for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) { 26228c2ecf20Sopenharmony_ci for (j = 0; j < qptc; j++) { 26238c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, 26248c2ecf20Sopenharmony_ci "TXq%u mapped to TC%u\n", queue, i); 26258c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR, 26268c2ecf20Sopenharmony_ci Q2TCMAP, i); 26278c2ecf20Sopenharmony_ci pdata->q2tc_map[queue++] = i; 26288c2ecf20Sopenharmony_ci } 26298c2ecf20Sopenharmony_ci 26308c2ecf20Sopenharmony_ci if (i < qptc_extra) { 26318c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, 26328c2ecf20Sopenharmony_ci "TXq%u mapped to TC%u\n", queue, i); 26338c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR, 26348c2ecf20Sopenharmony_ci Q2TCMAP, i); 26358c2ecf20Sopenharmony_ci pdata->q2tc_map[queue++] = i; 26368c2ecf20Sopenharmony_ci } 26378c2ecf20Sopenharmony_ci } 26388c2ecf20Sopenharmony_ci 26398c2ecf20Sopenharmony_ci /* Map the 8 VLAN priority values to available MTL Rx queues */ 26408c2ecf20Sopenharmony_ci prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count); 26418c2ecf20Sopenharmony_ci ppq = IEEE_8021QAZ_MAX_TCS / prio_queues; 26428c2ecf20Sopenharmony_ci ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues; 26438c2ecf20Sopenharmony_ci 26448c2ecf20Sopenharmony_ci reg = MAC_RQC2R; 26458c2ecf20Sopenharmony_ci reg_val = 0; 26468c2ecf20Sopenharmony_ci for (i = 0, prio = 0; i < prio_queues;) { 26478c2ecf20Sopenharmony_ci mask = 0; 26488c2ecf20Sopenharmony_ci for (j = 0; j < ppq; j++) { 26498c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, 26508c2ecf20Sopenharmony_ci "PRIO%u mapped to RXq%u\n", prio, i); 26518c2ecf20Sopenharmony_ci mask |= (1 << prio); 26528c2ecf20Sopenharmony_ci pdata->prio2q_map[prio++] = i; 26538c2ecf20Sopenharmony_ci } 26548c2ecf20Sopenharmony_ci 26558c2ecf20Sopenharmony_ci if (i < ppq_extra) { 26568c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, 26578c2ecf20Sopenharmony_ci "PRIO%u mapped to RXq%u\n", prio, i); 26588c2ecf20Sopenharmony_ci mask |= (1 << prio); 26598c2ecf20Sopenharmony_ci pdata->prio2q_map[prio++] = i; 26608c2ecf20Sopenharmony_ci } 26618c2ecf20Sopenharmony_ci 26628c2ecf20Sopenharmony_ci reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3)); 26638c2ecf20Sopenharmony_ci 26648c2ecf20Sopenharmony_ci if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues)) 26658c2ecf20Sopenharmony_ci continue; 26668c2ecf20Sopenharmony_ci 26678c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, reg, reg_val); 26688c2ecf20Sopenharmony_ci reg += MAC_RQC2_INC; 26698c2ecf20Sopenharmony_ci reg_val = 0; 26708c2ecf20Sopenharmony_ci } 26718c2ecf20Sopenharmony_ci 26728c2ecf20Sopenharmony_ci /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */ 26738c2ecf20Sopenharmony_ci reg = MTL_RQDCM0R; 26748c2ecf20Sopenharmony_ci reg_val = 0; 26758c2ecf20Sopenharmony_ci for (i = 0; i < pdata->rx_q_count;) { 26768c2ecf20Sopenharmony_ci reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3)); 26778c2ecf20Sopenharmony_ci 26788c2ecf20Sopenharmony_ci if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count)) 26798c2ecf20Sopenharmony_ci continue; 26808c2ecf20Sopenharmony_ci 26818c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, reg, reg_val); 26828c2ecf20Sopenharmony_ci 26838c2ecf20Sopenharmony_ci reg += MTL_RQDCM_INC; 26848c2ecf20Sopenharmony_ci reg_val = 0; 26858c2ecf20Sopenharmony_ci } 26868c2ecf20Sopenharmony_ci} 26878c2ecf20Sopenharmony_ci 26888c2ecf20Sopenharmony_cistatic void xgbe_config_tc(struct xgbe_prv_data *pdata) 26898c2ecf20Sopenharmony_ci{ 26908c2ecf20Sopenharmony_ci unsigned int offset, queue, prio; 26918c2ecf20Sopenharmony_ci u8 i; 26928c2ecf20Sopenharmony_ci 26938c2ecf20Sopenharmony_ci netdev_reset_tc(pdata->netdev); 26948c2ecf20Sopenharmony_ci if (!pdata->num_tcs) 26958c2ecf20Sopenharmony_ci return; 26968c2ecf20Sopenharmony_ci 26978c2ecf20Sopenharmony_ci netdev_set_num_tc(pdata->netdev, pdata->num_tcs); 26988c2ecf20Sopenharmony_ci 26998c2ecf20Sopenharmony_ci for (i = 0, queue = 0, offset = 0; i < pdata->num_tcs; i++) { 27008c2ecf20Sopenharmony_ci while ((queue < pdata->tx_q_count) && 27018c2ecf20Sopenharmony_ci (pdata->q2tc_map[queue] == i)) 27028c2ecf20Sopenharmony_ci queue++; 27038c2ecf20Sopenharmony_ci 27048c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, "TC%u using TXq%u-%u\n", 27058c2ecf20Sopenharmony_ci i, offset, queue - 1); 27068c2ecf20Sopenharmony_ci netdev_set_tc_queue(pdata->netdev, i, queue - offset, offset); 27078c2ecf20Sopenharmony_ci offset = queue; 27088c2ecf20Sopenharmony_ci } 27098c2ecf20Sopenharmony_ci 27108c2ecf20Sopenharmony_ci if (!pdata->ets) 27118c2ecf20Sopenharmony_ci return; 27128c2ecf20Sopenharmony_ci 27138c2ecf20Sopenharmony_ci for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) 27148c2ecf20Sopenharmony_ci netdev_set_prio_tc_map(pdata->netdev, prio, 27158c2ecf20Sopenharmony_ci pdata->ets->prio_tc[prio]); 27168c2ecf20Sopenharmony_ci} 27178c2ecf20Sopenharmony_ci 27188c2ecf20Sopenharmony_cistatic void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata) 27198c2ecf20Sopenharmony_ci{ 27208c2ecf20Sopenharmony_ci struct ieee_ets *ets = pdata->ets; 27218c2ecf20Sopenharmony_ci unsigned int total_weight, min_weight, weight; 27228c2ecf20Sopenharmony_ci unsigned int mask, reg, reg_val; 27238c2ecf20Sopenharmony_ci unsigned int i, prio; 27248c2ecf20Sopenharmony_ci 27258c2ecf20Sopenharmony_ci if (!ets) 27268c2ecf20Sopenharmony_ci return; 27278c2ecf20Sopenharmony_ci 27288c2ecf20Sopenharmony_ci /* Set Tx to deficit weighted round robin scheduling algorithm (when 27298c2ecf20Sopenharmony_ci * traffic class is using ETS algorithm) 27308c2ecf20Sopenharmony_ci */ 27318c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR); 27328c2ecf20Sopenharmony_ci 27338c2ecf20Sopenharmony_ci /* Set Traffic Class algorithms */ 27348c2ecf20Sopenharmony_ci total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt; 27358c2ecf20Sopenharmony_ci min_weight = total_weight / 100; 27368c2ecf20Sopenharmony_ci if (!min_weight) 27378c2ecf20Sopenharmony_ci min_weight = 1; 27388c2ecf20Sopenharmony_ci 27398c2ecf20Sopenharmony_ci for (i = 0; i < pdata->hw_feat.tc_cnt; i++) { 27408c2ecf20Sopenharmony_ci /* Map the priorities to the traffic class */ 27418c2ecf20Sopenharmony_ci mask = 0; 27428c2ecf20Sopenharmony_ci for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) { 27438c2ecf20Sopenharmony_ci if (ets->prio_tc[prio] == i) 27448c2ecf20Sopenharmony_ci mask |= (1 << prio); 27458c2ecf20Sopenharmony_ci } 27468c2ecf20Sopenharmony_ci mask &= 0xff; 27478c2ecf20Sopenharmony_ci 27488c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, "TC%u PRIO mask=%#x\n", 27498c2ecf20Sopenharmony_ci i, mask); 27508c2ecf20Sopenharmony_ci reg = MTL_TCPM0R + (MTL_TCPM_INC * (i / MTL_TCPM_TC_PER_REG)); 27518c2ecf20Sopenharmony_ci reg_val = XGMAC_IOREAD(pdata, reg); 27528c2ecf20Sopenharmony_ci 27538c2ecf20Sopenharmony_ci reg_val &= ~(0xff << ((i % MTL_TCPM_TC_PER_REG) << 3)); 27548c2ecf20Sopenharmony_ci reg_val |= (mask << ((i % MTL_TCPM_TC_PER_REG) << 3)); 27558c2ecf20Sopenharmony_ci 27568c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, reg, reg_val); 27578c2ecf20Sopenharmony_ci 27588c2ecf20Sopenharmony_ci /* Set the traffic class algorithm */ 27598c2ecf20Sopenharmony_ci switch (ets->tc_tsa[i]) { 27608c2ecf20Sopenharmony_ci case IEEE_8021QAZ_TSA_STRICT: 27618c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, 27628c2ecf20Sopenharmony_ci "TC%u using SP\n", i); 27638c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA, 27648c2ecf20Sopenharmony_ci MTL_TSA_SP); 27658c2ecf20Sopenharmony_ci break; 27668c2ecf20Sopenharmony_ci case IEEE_8021QAZ_TSA_ETS: 27678c2ecf20Sopenharmony_ci weight = total_weight * ets->tc_tx_bw[i] / 100; 27688c2ecf20Sopenharmony_ci weight = clamp(weight, min_weight, total_weight); 27698c2ecf20Sopenharmony_ci 27708c2ecf20Sopenharmony_ci netif_dbg(pdata, drv, pdata->netdev, 27718c2ecf20Sopenharmony_ci "TC%u using DWRR (weight %u)\n", i, weight); 27728c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA, 27738c2ecf20Sopenharmony_ci MTL_TSA_ETS); 27748c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 27758c2ecf20Sopenharmony_ci weight); 27768c2ecf20Sopenharmony_ci break; 27778c2ecf20Sopenharmony_ci } 27788c2ecf20Sopenharmony_ci } 27798c2ecf20Sopenharmony_ci 27808c2ecf20Sopenharmony_ci xgbe_config_tc(pdata); 27818c2ecf20Sopenharmony_ci} 27828c2ecf20Sopenharmony_ci 27838c2ecf20Sopenharmony_cistatic void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata) 27848c2ecf20Sopenharmony_ci{ 27858c2ecf20Sopenharmony_ci if (!test_bit(XGBE_DOWN, &pdata->dev_state)) { 27868c2ecf20Sopenharmony_ci /* Just stop the Tx queues while Rx fifo is changed */ 27878c2ecf20Sopenharmony_ci netif_tx_stop_all_queues(pdata->netdev); 27888c2ecf20Sopenharmony_ci 27898c2ecf20Sopenharmony_ci /* Suspend Rx so that fifo's can be adjusted */ 27908c2ecf20Sopenharmony_ci pdata->hw_if.disable_rx(pdata); 27918c2ecf20Sopenharmony_ci } 27928c2ecf20Sopenharmony_ci 27938c2ecf20Sopenharmony_ci xgbe_config_rx_fifo_size(pdata); 27948c2ecf20Sopenharmony_ci xgbe_config_flow_control(pdata); 27958c2ecf20Sopenharmony_ci 27968c2ecf20Sopenharmony_ci if (!test_bit(XGBE_DOWN, &pdata->dev_state)) { 27978c2ecf20Sopenharmony_ci /* Resume Rx */ 27988c2ecf20Sopenharmony_ci pdata->hw_if.enable_rx(pdata); 27998c2ecf20Sopenharmony_ci 28008c2ecf20Sopenharmony_ci /* Resume Tx queues */ 28018c2ecf20Sopenharmony_ci netif_tx_start_all_queues(pdata->netdev); 28028c2ecf20Sopenharmony_ci } 28038c2ecf20Sopenharmony_ci} 28048c2ecf20Sopenharmony_ci 28058c2ecf20Sopenharmony_cistatic void xgbe_config_mac_address(struct xgbe_prv_data *pdata) 28068c2ecf20Sopenharmony_ci{ 28078c2ecf20Sopenharmony_ci xgbe_set_mac_address(pdata, pdata->netdev->dev_addr); 28088c2ecf20Sopenharmony_ci 28098c2ecf20Sopenharmony_ci /* Filtering is done using perfect filtering and hash filtering */ 28108c2ecf20Sopenharmony_ci if (pdata->hw_feat.hash_table_size) { 28118c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1); 28128c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1); 28138c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1); 28148c2ecf20Sopenharmony_ci } 28158c2ecf20Sopenharmony_ci} 28168c2ecf20Sopenharmony_ci 28178c2ecf20Sopenharmony_cistatic void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata) 28188c2ecf20Sopenharmony_ci{ 28198c2ecf20Sopenharmony_ci unsigned int val; 28208c2ecf20Sopenharmony_ci 28218c2ecf20Sopenharmony_ci val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0; 28228c2ecf20Sopenharmony_ci 28238c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val); 28248c2ecf20Sopenharmony_ci} 28258c2ecf20Sopenharmony_ci 28268c2ecf20Sopenharmony_cistatic void xgbe_config_mac_speed(struct xgbe_prv_data *pdata) 28278c2ecf20Sopenharmony_ci{ 28288c2ecf20Sopenharmony_ci xgbe_set_speed(pdata, pdata->phy_speed); 28298c2ecf20Sopenharmony_ci} 28308c2ecf20Sopenharmony_ci 28318c2ecf20Sopenharmony_cistatic void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata) 28328c2ecf20Sopenharmony_ci{ 28338c2ecf20Sopenharmony_ci if (pdata->netdev->features & NETIF_F_RXCSUM) 28348c2ecf20Sopenharmony_ci xgbe_enable_rx_csum(pdata); 28358c2ecf20Sopenharmony_ci else 28368c2ecf20Sopenharmony_ci xgbe_disable_rx_csum(pdata); 28378c2ecf20Sopenharmony_ci} 28388c2ecf20Sopenharmony_ci 28398c2ecf20Sopenharmony_cistatic void xgbe_config_vlan_support(struct xgbe_prv_data *pdata) 28408c2ecf20Sopenharmony_ci{ 28418c2ecf20Sopenharmony_ci /* Indicate that VLAN Tx CTAGs come from context descriptors */ 28428c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0); 28438c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1); 28448c2ecf20Sopenharmony_ci 28458c2ecf20Sopenharmony_ci /* Set the current VLAN Hash Table register value */ 28468c2ecf20Sopenharmony_ci xgbe_update_vlan_hash_table(pdata); 28478c2ecf20Sopenharmony_ci 28488c2ecf20Sopenharmony_ci if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER) 28498c2ecf20Sopenharmony_ci xgbe_enable_rx_vlan_filtering(pdata); 28508c2ecf20Sopenharmony_ci else 28518c2ecf20Sopenharmony_ci xgbe_disable_rx_vlan_filtering(pdata); 28528c2ecf20Sopenharmony_ci 28538c2ecf20Sopenharmony_ci if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX) 28548c2ecf20Sopenharmony_ci xgbe_enable_rx_vlan_stripping(pdata); 28558c2ecf20Sopenharmony_ci else 28568c2ecf20Sopenharmony_ci xgbe_disable_rx_vlan_stripping(pdata); 28578c2ecf20Sopenharmony_ci} 28588c2ecf20Sopenharmony_ci 28598c2ecf20Sopenharmony_cistatic u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo) 28608c2ecf20Sopenharmony_ci{ 28618c2ecf20Sopenharmony_ci bool read_hi; 28628c2ecf20Sopenharmony_ci u64 val; 28638c2ecf20Sopenharmony_ci 28648c2ecf20Sopenharmony_ci if (pdata->vdata->mmc_64bit) { 28658c2ecf20Sopenharmony_ci switch (reg_lo) { 28668c2ecf20Sopenharmony_ci /* These registers are always 32 bit */ 28678c2ecf20Sopenharmony_ci case MMC_RXRUNTERROR: 28688c2ecf20Sopenharmony_ci case MMC_RXJABBERERROR: 28698c2ecf20Sopenharmony_ci case MMC_RXUNDERSIZE_G: 28708c2ecf20Sopenharmony_ci case MMC_RXOVERSIZE_G: 28718c2ecf20Sopenharmony_ci case MMC_RXWATCHDOGERROR: 28728c2ecf20Sopenharmony_ci read_hi = false; 28738c2ecf20Sopenharmony_ci break; 28748c2ecf20Sopenharmony_ci 28758c2ecf20Sopenharmony_ci default: 28768c2ecf20Sopenharmony_ci read_hi = true; 28778c2ecf20Sopenharmony_ci } 28788c2ecf20Sopenharmony_ci } else { 28798c2ecf20Sopenharmony_ci switch (reg_lo) { 28808c2ecf20Sopenharmony_ci /* These registers are always 64 bit */ 28818c2ecf20Sopenharmony_ci case MMC_TXOCTETCOUNT_GB_LO: 28828c2ecf20Sopenharmony_ci case MMC_TXOCTETCOUNT_G_LO: 28838c2ecf20Sopenharmony_ci case MMC_RXOCTETCOUNT_GB_LO: 28848c2ecf20Sopenharmony_ci case MMC_RXOCTETCOUNT_G_LO: 28858c2ecf20Sopenharmony_ci read_hi = true; 28868c2ecf20Sopenharmony_ci break; 28878c2ecf20Sopenharmony_ci 28888c2ecf20Sopenharmony_ci default: 28898c2ecf20Sopenharmony_ci read_hi = false; 28908c2ecf20Sopenharmony_ci } 28918c2ecf20Sopenharmony_ci } 28928c2ecf20Sopenharmony_ci 28938c2ecf20Sopenharmony_ci val = XGMAC_IOREAD(pdata, reg_lo); 28948c2ecf20Sopenharmony_ci 28958c2ecf20Sopenharmony_ci if (read_hi) 28968c2ecf20Sopenharmony_ci val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32); 28978c2ecf20Sopenharmony_ci 28988c2ecf20Sopenharmony_ci return val; 28998c2ecf20Sopenharmony_ci} 29008c2ecf20Sopenharmony_ci 29018c2ecf20Sopenharmony_cistatic void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata) 29028c2ecf20Sopenharmony_ci{ 29038c2ecf20Sopenharmony_ci struct xgbe_mmc_stats *stats = &pdata->mmc_stats; 29048c2ecf20Sopenharmony_ci unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR); 29058c2ecf20Sopenharmony_ci 29068c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB)) 29078c2ecf20Sopenharmony_ci stats->txoctetcount_gb += 29088c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO); 29098c2ecf20Sopenharmony_ci 29108c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB)) 29118c2ecf20Sopenharmony_ci stats->txframecount_gb += 29128c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO); 29138c2ecf20Sopenharmony_ci 29148c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G)) 29158c2ecf20Sopenharmony_ci stats->txbroadcastframes_g += 29168c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO); 29178c2ecf20Sopenharmony_ci 29188c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G)) 29198c2ecf20Sopenharmony_ci stats->txmulticastframes_g += 29208c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO); 29218c2ecf20Sopenharmony_ci 29228c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB)) 29238c2ecf20Sopenharmony_ci stats->tx64octets_gb += 29248c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO); 29258c2ecf20Sopenharmony_ci 29268c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB)) 29278c2ecf20Sopenharmony_ci stats->tx65to127octets_gb += 29288c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO); 29298c2ecf20Sopenharmony_ci 29308c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB)) 29318c2ecf20Sopenharmony_ci stats->tx128to255octets_gb += 29328c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO); 29338c2ecf20Sopenharmony_ci 29348c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB)) 29358c2ecf20Sopenharmony_ci stats->tx256to511octets_gb += 29368c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO); 29378c2ecf20Sopenharmony_ci 29388c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB)) 29398c2ecf20Sopenharmony_ci stats->tx512to1023octets_gb += 29408c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO); 29418c2ecf20Sopenharmony_ci 29428c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB)) 29438c2ecf20Sopenharmony_ci stats->tx1024tomaxoctets_gb += 29448c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO); 29458c2ecf20Sopenharmony_ci 29468c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB)) 29478c2ecf20Sopenharmony_ci stats->txunicastframes_gb += 29488c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO); 29498c2ecf20Sopenharmony_ci 29508c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB)) 29518c2ecf20Sopenharmony_ci stats->txmulticastframes_gb += 29528c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO); 29538c2ecf20Sopenharmony_ci 29548c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB)) 29558c2ecf20Sopenharmony_ci stats->txbroadcastframes_g += 29568c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO); 29578c2ecf20Sopenharmony_ci 29588c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR)) 29598c2ecf20Sopenharmony_ci stats->txunderflowerror += 29608c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO); 29618c2ecf20Sopenharmony_ci 29628c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G)) 29638c2ecf20Sopenharmony_ci stats->txoctetcount_g += 29648c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO); 29658c2ecf20Sopenharmony_ci 29668c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G)) 29678c2ecf20Sopenharmony_ci stats->txframecount_g += 29688c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO); 29698c2ecf20Sopenharmony_ci 29708c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES)) 29718c2ecf20Sopenharmony_ci stats->txpauseframes += 29728c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO); 29738c2ecf20Sopenharmony_ci 29748c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G)) 29758c2ecf20Sopenharmony_ci stats->txvlanframes_g += 29768c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO); 29778c2ecf20Sopenharmony_ci} 29788c2ecf20Sopenharmony_ci 29798c2ecf20Sopenharmony_cistatic void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata) 29808c2ecf20Sopenharmony_ci{ 29818c2ecf20Sopenharmony_ci struct xgbe_mmc_stats *stats = &pdata->mmc_stats; 29828c2ecf20Sopenharmony_ci unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR); 29838c2ecf20Sopenharmony_ci 29848c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB)) 29858c2ecf20Sopenharmony_ci stats->rxframecount_gb += 29868c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO); 29878c2ecf20Sopenharmony_ci 29888c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB)) 29898c2ecf20Sopenharmony_ci stats->rxoctetcount_gb += 29908c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO); 29918c2ecf20Sopenharmony_ci 29928c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G)) 29938c2ecf20Sopenharmony_ci stats->rxoctetcount_g += 29948c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO); 29958c2ecf20Sopenharmony_ci 29968c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G)) 29978c2ecf20Sopenharmony_ci stats->rxbroadcastframes_g += 29988c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO); 29998c2ecf20Sopenharmony_ci 30008c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G)) 30018c2ecf20Sopenharmony_ci stats->rxmulticastframes_g += 30028c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO); 30038c2ecf20Sopenharmony_ci 30048c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR)) 30058c2ecf20Sopenharmony_ci stats->rxcrcerror += 30068c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO); 30078c2ecf20Sopenharmony_ci 30088c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR)) 30098c2ecf20Sopenharmony_ci stats->rxrunterror += 30108c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXRUNTERROR); 30118c2ecf20Sopenharmony_ci 30128c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR)) 30138c2ecf20Sopenharmony_ci stats->rxjabbererror += 30148c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXJABBERERROR); 30158c2ecf20Sopenharmony_ci 30168c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G)) 30178c2ecf20Sopenharmony_ci stats->rxundersize_g += 30188c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G); 30198c2ecf20Sopenharmony_ci 30208c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G)) 30218c2ecf20Sopenharmony_ci stats->rxoversize_g += 30228c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G); 30238c2ecf20Sopenharmony_ci 30248c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB)) 30258c2ecf20Sopenharmony_ci stats->rx64octets_gb += 30268c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO); 30278c2ecf20Sopenharmony_ci 30288c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB)) 30298c2ecf20Sopenharmony_ci stats->rx65to127octets_gb += 30308c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO); 30318c2ecf20Sopenharmony_ci 30328c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB)) 30338c2ecf20Sopenharmony_ci stats->rx128to255octets_gb += 30348c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO); 30358c2ecf20Sopenharmony_ci 30368c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB)) 30378c2ecf20Sopenharmony_ci stats->rx256to511octets_gb += 30388c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO); 30398c2ecf20Sopenharmony_ci 30408c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB)) 30418c2ecf20Sopenharmony_ci stats->rx512to1023octets_gb += 30428c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO); 30438c2ecf20Sopenharmony_ci 30448c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB)) 30458c2ecf20Sopenharmony_ci stats->rx1024tomaxoctets_gb += 30468c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO); 30478c2ecf20Sopenharmony_ci 30488c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G)) 30498c2ecf20Sopenharmony_ci stats->rxunicastframes_g += 30508c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO); 30518c2ecf20Sopenharmony_ci 30528c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR)) 30538c2ecf20Sopenharmony_ci stats->rxlengtherror += 30548c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO); 30558c2ecf20Sopenharmony_ci 30568c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE)) 30578c2ecf20Sopenharmony_ci stats->rxoutofrangetype += 30588c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO); 30598c2ecf20Sopenharmony_ci 30608c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES)) 30618c2ecf20Sopenharmony_ci stats->rxpauseframes += 30628c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO); 30638c2ecf20Sopenharmony_ci 30648c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW)) 30658c2ecf20Sopenharmony_ci stats->rxfifooverflow += 30668c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO); 30678c2ecf20Sopenharmony_ci 30688c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB)) 30698c2ecf20Sopenharmony_ci stats->rxvlanframes_gb += 30708c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO); 30718c2ecf20Sopenharmony_ci 30728c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR)) 30738c2ecf20Sopenharmony_ci stats->rxwatchdogerror += 30748c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR); 30758c2ecf20Sopenharmony_ci} 30768c2ecf20Sopenharmony_ci 30778c2ecf20Sopenharmony_cistatic void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata) 30788c2ecf20Sopenharmony_ci{ 30798c2ecf20Sopenharmony_ci struct xgbe_mmc_stats *stats = &pdata->mmc_stats; 30808c2ecf20Sopenharmony_ci 30818c2ecf20Sopenharmony_ci /* Freeze counters */ 30828c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1); 30838c2ecf20Sopenharmony_ci 30848c2ecf20Sopenharmony_ci stats->txoctetcount_gb += 30858c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO); 30868c2ecf20Sopenharmony_ci 30878c2ecf20Sopenharmony_ci stats->txframecount_gb += 30888c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO); 30898c2ecf20Sopenharmony_ci 30908c2ecf20Sopenharmony_ci stats->txbroadcastframes_g += 30918c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO); 30928c2ecf20Sopenharmony_ci 30938c2ecf20Sopenharmony_ci stats->txmulticastframes_g += 30948c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO); 30958c2ecf20Sopenharmony_ci 30968c2ecf20Sopenharmony_ci stats->tx64octets_gb += 30978c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO); 30988c2ecf20Sopenharmony_ci 30998c2ecf20Sopenharmony_ci stats->tx65to127octets_gb += 31008c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO); 31018c2ecf20Sopenharmony_ci 31028c2ecf20Sopenharmony_ci stats->tx128to255octets_gb += 31038c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO); 31048c2ecf20Sopenharmony_ci 31058c2ecf20Sopenharmony_ci stats->tx256to511octets_gb += 31068c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO); 31078c2ecf20Sopenharmony_ci 31088c2ecf20Sopenharmony_ci stats->tx512to1023octets_gb += 31098c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO); 31108c2ecf20Sopenharmony_ci 31118c2ecf20Sopenharmony_ci stats->tx1024tomaxoctets_gb += 31128c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO); 31138c2ecf20Sopenharmony_ci 31148c2ecf20Sopenharmony_ci stats->txunicastframes_gb += 31158c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO); 31168c2ecf20Sopenharmony_ci 31178c2ecf20Sopenharmony_ci stats->txmulticastframes_gb += 31188c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO); 31198c2ecf20Sopenharmony_ci 31208c2ecf20Sopenharmony_ci stats->txbroadcastframes_g += 31218c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO); 31228c2ecf20Sopenharmony_ci 31238c2ecf20Sopenharmony_ci stats->txunderflowerror += 31248c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO); 31258c2ecf20Sopenharmony_ci 31268c2ecf20Sopenharmony_ci stats->txoctetcount_g += 31278c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO); 31288c2ecf20Sopenharmony_ci 31298c2ecf20Sopenharmony_ci stats->txframecount_g += 31308c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO); 31318c2ecf20Sopenharmony_ci 31328c2ecf20Sopenharmony_ci stats->txpauseframes += 31338c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO); 31348c2ecf20Sopenharmony_ci 31358c2ecf20Sopenharmony_ci stats->txvlanframes_g += 31368c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO); 31378c2ecf20Sopenharmony_ci 31388c2ecf20Sopenharmony_ci stats->rxframecount_gb += 31398c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO); 31408c2ecf20Sopenharmony_ci 31418c2ecf20Sopenharmony_ci stats->rxoctetcount_gb += 31428c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO); 31438c2ecf20Sopenharmony_ci 31448c2ecf20Sopenharmony_ci stats->rxoctetcount_g += 31458c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO); 31468c2ecf20Sopenharmony_ci 31478c2ecf20Sopenharmony_ci stats->rxbroadcastframes_g += 31488c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO); 31498c2ecf20Sopenharmony_ci 31508c2ecf20Sopenharmony_ci stats->rxmulticastframes_g += 31518c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO); 31528c2ecf20Sopenharmony_ci 31538c2ecf20Sopenharmony_ci stats->rxcrcerror += 31548c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO); 31558c2ecf20Sopenharmony_ci 31568c2ecf20Sopenharmony_ci stats->rxrunterror += 31578c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXRUNTERROR); 31588c2ecf20Sopenharmony_ci 31598c2ecf20Sopenharmony_ci stats->rxjabbererror += 31608c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXJABBERERROR); 31618c2ecf20Sopenharmony_ci 31628c2ecf20Sopenharmony_ci stats->rxundersize_g += 31638c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G); 31648c2ecf20Sopenharmony_ci 31658c2ecf20Sopenharmony_ci stats->rxoversize_g += 31668c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G); 31678c2ecf20Sopenharmony_ci 31688c2ecf20Sopenharmony_ci stats->rx64octets_gb += 31698c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO); 31708c2ecf20Sopenharmony_ci 31718c2ecf20Sopenharmony_ci stats->rx65to127octets_gb += 31728c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO); 31738c2ecf20Sopenharmony_ci 31748c2ecf20Sopenharmony_ci stats->rx128to255octets_gb += 31758c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO); 31768c2ecf20Sopenharmony_ci 31778c2ecf20Sopenharmony_ci stats->rx256to511octets_gb += 31788c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO); 31798c2ecf20Sopenharmony_ci 31808c2ecf20Sopenharmony_ci stats->rx512to1023octets_gb += 31818c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO); 31828c2ecf20Sopenharmony_ci 31838c2ecf20Sopenharmony_ci stats->rx1024tomaxoctets_gb += 31848c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO); 31858c2ecf20Sopenharmony_ci 31868c2ecf20Sopenharmony_ci stats->rxunicastframes_g += 31878c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO); 31888c2ecf20Sopenharmony_ci 31898c2ecf20Sopenharmony_ci stats->rxlengtherror += 31908c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO); 31918c2ecf20Sopenharmony_ci 31928c2ecf20Sopenharmony_ci stats->rxoutofrangetype += 31938c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO); 31948c2ecf20Sopenharmony_ci 31958c2ecf20Sopenharmony_ci stats->rxpauseframes += 31968c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO); 31978c2ecf20Sopenharmony_ci 31988c2ecf20Sopenharmony_ci stats->rxfifooverflow += 31998c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO); 32008c2ecf20Sopenharmony_ci 32018c2ecf20Sopenharmony_ci stats->rxvlanframes_gb += 32028c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO); 32038c2ecf20Sopenharmony_ci 32048c2ecf20Sopenharmony_ci stats->rxwatchdogerror += 32058c2ecf20Sopenharmony_ci xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR); 32068c2ecf20Sopenharmony_ci 32078c2ecf20Sopenharmony_ci /* Un-freeze counters */ 32088c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0); 32098c2ecf20Sopenharmony_ci} 32108c2ecf20Sopenharmony_ci 32118c2ecf20Sopenharmony_cistatic void xgbe_config_mmc(struct xgbe_prv_data *pdata) 32128c2ecf20Sopenharmony_ci{ 32138c2ecf20Sopenharmony_ci /* Set counters to reset on read */ 32148c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1); 32158c2ecf20Sopenharmony_ci 32168c2ecf20Sopenharmony_ci /* Reset the counters */ 32178c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1); 32188c2ecf20Sopenharmony_ci} 32198c2ecf20Sopenharmony_ci 32208c2ecf20Sopenharmony_cistatic void xgbe_txq_prepare_tx_stop(struct xgbe_prv_data *pdata, 32218c2ecf20Sopenharmony_ci unsigned int queue) 32228c2ecf20Sopenharmony_ci{ 32238c2ecf20Sopenharmony_ci unsigned int tx_status; 32248c2ecf20Sopenharmony_ci unsigned long tx_timeout; 32258c2ecf20Sopenharmony_ci 32268c2ecf20Sopenharmony_ci /* The Tx engine cannot be stopped if it is actively processing 32278c2ecf20Sopenharmony_ci * packets. Wait for the Tx queue to empty the Tx fifo. Don't 32288c2ecf20Sopenharmony_ci * wait forever though... 32298c2ecf20Sopenharmony_ci */ 32308c2ecf20Sopenharmony_ci tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ); 32318c2ecf20Sopenharmony_ci while (time_before(jiffies, tx_timeout)) { 32328c2ecf20Sopenharmony_ci tx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_TQDR); 32338c2ecf20Sopenharmony_ci if ((XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TRCSTS) != 1) && 32348c2ecf20Sopenharmony_ci (XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TXQSTS) == 0)) 32358c2ecf20Sopenharmony_ci break; 32368c2ecf20Sopenharmony_ci 32378c2ecf20Sopenharmony_ci usleep_range(500, 1000); 32388c2ecf20Sopenharmony_ci } 32398c2ecf20Sopenharmony_ci 32408c2ecf20Sopenharmony_ci if (!time_before(jiffies, tx_timeout)) 32418c2ecf20Sopenharmony_ci netdev_info(pdata->netdev, 32428c2ecf20Sopenharmony_ci "timed out waiting for Tx queue %u to empty\n", 32438c2ecf20Sopenharmony_ci queue); 32448c2ecf20Sopenharmony_ci} 32458c2ecf20Sopenharmony_ci 32468c2ecf20Sopenharmony_cistatic void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata, 32478c2ecf20Sopenharmony_ci unsigned int queue) 32488c2ecf20Sopenharmony_ci{ 32498c2ecf20Sopenharmony_ci unsigned int tx_dsr, tx_pos, tx_qidx; 32508c2ecf20Sopenharmony_ci unsigned int tx_status; 32518c2ecf20Sopenharmony_ci unsigned long tx_timeout; 32528c2ecf20Sopenharmony_ci 32538c2ecf20Sopenharmony_ci if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) > 0x20) 32548c2ecf20Sopenharmony_ci return xgbe_txq_prepare_tx_stop(pdata, queue); 32558c2ecf20Sopenharmony_ci 32568c2ecf20Sopenharmony_ci /* Calculate the status register to read and the position within */ 32578c2ecf20Sopenharmony_ci if (queue < DMA_DSRX_FIRST_QUEUE) { 32588c2ecf20Sopenharmony_ci tx_dsr = DMA_DSR0; 32598c2ecf20Sopenharmony_ci tx_pos = (queue * DMA_DSR_Q_WIDTH) + DMA_DSR0_TPS_START; 32608c2ecf20Sopenharmony_ci } else { 32618c2ecf20Sopenharmony_ci tx_qidx = queue - DMA_DSRX_FIRST_QUEUE; 32628c2ecf20Sopenharmony_ci 32638c2ecf20Sopenharmony_ci tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC); 32648c2ecf20Sopenharmony_ci tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) + 32658c2ecf20Sopenharmony_ci DMA_DSRX_TPS_START; 32668c2ecf20Sopenharmony_ci } 32678c2ecf20Sopenharmony_ci 32688c2ecf20Sopenharmony_ci /* The Tx engine cannot be stopped if it is actively processing 32698c2ecf20Sopenharmony_ci * descriptors. Wait for the Tx engine to enter the stopped or 32708c2ecf20Sopenharmony_ci * suspended state. Don't wait forever though... 32718c2ecf20Sopenharmony_ci */ 32728c2ecf20Sopenharmony_ci tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ); 32738c2ecf20Sopenharmony_ci while (time_before(jiffies, tx_timeout)) { 32748c2ecf20Sopenharmony_ci tx_status = XGMAC_IOREAD(pdata, tx_dsr); 32758c2ecf20Sopenharmony_ci tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH); 32768c2ecf20Sopenharmony_ci if ((tx_status == DMA_TPS_STOPPED) || 32778c2ecf20Sopenharmony_ci (tx_status == DMA_TPS_SUSPENDED)) 32788c2ecf20Sopenharmony_ci break; 32798c2ecf20Sopenharmony_ci 32808c2ecf20Sopenharmony_ci usleep_range(500, 1000); 32818c2ecf20Sopenharmony_ci } 32828c2ecf20Sopenharmony_ci 32838c2ecf20Sopenharmony_ci if (!time_before(jiffies, tx_timeout)) 32848c2ecf20Sopenharmony_ci netdev_info(pdata->netdev, 32858c2ecf20Sopenharmony_ci "timed out waiting for Tx DMA channel %u to stop\n", 32868c2ecf20Sopenharmony_ci queue); 32878c2ecf20Sopenharmony_ci} 32888c2ecf20Sopenharmony_ci 32898c2ecf20Sopenharmony_cistatic void xgbe_enable_tx(struct xgbe_prv_data *pdata) 32908c2ecf20Sopenharmony_ci{ 32918c2ecf20Sopenharmony_ci unsigned int i; 32928c2ecf20Sopenharmony_ci 32938c2ecf20Sopenharmony_ci /* Enable each Tx DMA channel */ 32948c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 32958c2ecf20Sopenharmony_ci if (!pdata->channel[i]->tx_ring) 32968c2ecf20Sopenharmony_ci break; 32978c2ecf20Sopenharmony_ci 32988c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 1); 32998c2ecf20Sopenharmony_ci } 33008c2ecf20Sopenharmony_ci 33018c2ecf20Sopenharmony_ci /* Enable each Tx queue */ 33028c2ecf20Sopenharmony_ci for (i = 0; i < pdata->tx_q_count; i++) 33038c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 33048c2ecf20Sopenharmony_ci MTL_Q_ENABLED); 33058c2ecf20Sopenharmony_ci 33068c2ecf20Sopenharmony_ci /* Enable MAC Tx */ 33078c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1); 33088c2ecf20Sopenharmony_ci} 33098c2ecf20Sopenharmony_ci 33108c2ecf20Sopenharmony_cistatic void xgbe_disable_tx(struct xgbe_prv_data *pdata) 33118c2ecf20Sopenharmony_ci{ 33128c2ecf20Sopenharmony_ci unsigned int i; 33138c2ecf20Sopenharmony_ci 33148c2ecf20Sopenharmony_ci /* Prepare for Tx DMA channel stop */ 33158c2ecf20Sopenharmony_ci for (i = 0; i < pdata->tx_q_count; i++) 33168c2ecf20Sopenharmony_ci xgbe_prepare_tx_stop(pdata, i); 33178c2ecf20Sopenharmony_ci 33188c2ecf20Sopenharmony_ci /* Disable MAC Tx */ 33198c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0); 33208c2ecf20Sopenharmony_ci 33218c2ecf20Sopenharmony_ci /* Disable each Tx queue */ 33228c2ecf20Sopenharmony_ci for (i = 0; i < pdata->tx_q_count; i++) 33238c2ecf20Sopenharmony_ci XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0); 33248c2ecf20Sopenharmony_ci 33258c2ecf20Sopenharmony_ci /* Disable each Tx DMA channel */ 33268c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 33278c2ecf20Sopenharmony_ci if (!pdata->channel[i]->tx_ring) 33288c2ecf20Sopenharmony_ci break; 33298c2ecf20Sopenharmony_ci 33308c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 0); 33318c2ecf20Sopenharmony_ci } 33328c2ecf20Sopenharmony_ci} 33338c2ecf20Sopenharmony_ci 33348c2ecf20Sopenharmony_cistatic void xgbe_prepare_rx_stop(struct xgbe_prv_data *pdata, 33358c2ecf20Sopenharmony_ci unsigned int queue) 33368c2ecf20Sopenharmony_ci{ 33378c2ecf20Sopenharmony_ci unsigned int rx_status; 33388c2ecf20Sopenharmony_ci unsigned long rx_timeout; 33398c2ecf20Sopenharmony_ci 33408c2ecf20Sopenharmony_ci /* The Rx engine cannot be stopped if it is actively processing 33418c2ecf20Sopenharmony_ci * packets. Wait for the Rx queue to empty the Rx fifo. Don't 33428c2ecf20Sopenharmony_ci * wait forever though... 33438c2ecf20Sopenharmony_ci */ 33448c2ecf20Sopenharmony_ci rx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ); 33458c2ecf20Sopenharmony_ci while (time_before(jiffies, rx_timeout)) { 33468c2ecf20Sopenharmony_ci rx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_RQDR); 33478c2ecf20Sopenharmony_ci if ((XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, PRXQ) == 0) && 33488c2ecf20Sopenharmony_ci (XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, RXQSTS) == 0)) 33498c2ecf20Sopenharmony_ci break; 33508c2ecf20Sopenharmony_ci 33518c2ecf20Sopenharmony_ci usleep_range(500, 1000); 33528c2ecf20Sopenharmony_ci } 33538c2ecf20Sopenharmony_ci 33548c2ecf20Sopenharmony_ci if (!time_before(jiffies, rx_timeout)) 33558c2ecf20Sopenharmony_ci netdev_info(pdata->netdev, 33568c2ecf20Sopenharmony_ci "timed out waiting for Rx queue %u to empty\n", 33578c2ecf20Sopenharmony_ci queue); 33588c2ecf20Sopenharmony_ci} 33598c2ecf20Sopenharmony_ci 33608c2ecf20Sopenharmony_cistatic void xgbe_enable_rx(struct xgbe_prv_data *pdata) 33618c2ecf20Sopenharmony_ci{ 33628c2ecf20Sopenharmony_ci unsigned int reg_val, i; 33638c2ecf20Sopenharmony_ci 33648c2ecf20Sopenharmony_ci /* Enable each Rx DMA channel */ 33658c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 33668c2ecf20Sopenharmony_ci if (!pdata->channel[i]->rx_ring) 33678c2ecf20Sopenharmony_ci break; 33688c2ecf20Sopenharmony_ci 33698c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 1); 33708c2ecf20Sopenharmony_ci } 33718c2ecf20Sopenharmony_ci 33728c2ecf20Sopenharmony_ci /* Enable each Rx queue */ 33738c2ecf20Sopenharmony_ci reg_val = 0; 33748c2ecf20Sopenharmony_ci for (i = 0; i < pdata->rx_q_count; i++) 33758c2ecf20Sopenharmony_ci reg_val |= (0x02 << (i << 1)); 33768c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val); 33778c2ecf20Sopenharmony_ci 33788c2ecf20Sopenharmony_ci /* Enable MAC Rx */ 33798c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1); 33808c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1); 33818c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1); 33828c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1); 33838c2ecf20Sopenharmony_ci} 33848c2ecf20Sopenharmony_ci 33858c2ecf20Sopenharmony_cistatic void xgbe_disable_rx(struct xgbe_prv_data *pdata) 33868c2ecf20Sopenharmony_ci{ 33878c2ecf20Sopenharmony_ci unsigned int i; 33888c2ecf20Sopenharmony_ci 33898c2ecf20Sopenharmony_ci /* Disable MAC Rx */ 33908c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0); 33918c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0); 33928c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0); 33938c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0); 33948c2ecf20Sopenharmony_ci 33958c2ecf20Sopenharmony_ci /* Prepare for Rx DMA channel stop */ 33968c2ecf20Sopenharmony_ci for (i = 0; i < pdata->rx_q_count; i++) 33978c2ecf20Sopenharmony_ci xgbe_prepare_rx_stop(pdata, i); 33988c2ecf20Sopenharmony_ci 33998c2ecf20Sopenharmony_ci /* Disable each Rx queue */ 34008c2ecf20Sopenharmony_ci XGMAC_IOWRITE(pdata, MAC_RQC0R, 0); 34018c2ecf20Sopenharmony_ci 34028c2ecf20Sopenharmony_ci /* Disable each Rx DMA channel */ 34038c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 34048c2ecf20Sopenharmony_ci if (!pdata->channel[i]->rx_ring) 34058c2ecf20Sopenharmony_ci break; 34068c2ecf20Sopenharmony_ci 34078c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 0); 34088c2ecf20Sopenharmony_ci } 34098c2ecf20Sopenharmony_ci} 34108c2ecf20Sopenharmony_ci 34118c2ecf20Sopenharmony_cistatic void xgbe_powerup_tx(struct xgbe_prv_data *pdata) 34128c2ecf20Sopenharmony_ci{ 34138c2ecf20Sopenharmony_ci unsigned int i; 34148c2ecf20Sopenharmony_ci 34158c2ecf20Sopenharmony_ci /* Enable each Tx DMA channel */ 34168c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 34178c2ecf20Sopenharmony_ci if (!pdata->channel[i]->tx_ring) 34188c2ecf20Sopenharmony_ci break; 34198c2ecf20Sopenharmony_ci 34208c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 1); 34218c2ecf20Sopenharmony_ci } 34228c2ecf20Sopenharmony_ci 34238c2ecf20Sopenharmony_ci /* Enable MAC Tx */ 34248c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1); 34258c2ecf20Sopenharmony_ci} 34268c2ecf20Sopenharmony_ci 34278c2ecf20Sopenharmony_cistatic void xgbe_powerdown_tx(struct xgbe_prv_data *pdata) 34288c2ecf20Sopenharmony_ci{ 34298c2ecf20Sopenharmony_ci unsigned int i; 34308c2ecf20Sopenharmony_ci 34318c2ecf20Sopenharmony_ci /* Prepare for Tx DMA channel stop */ 34328c2ecf20Sopenharmony_ci for (i = 0; i < pdata->tx_q_count; i++) 34338c2ecf20Sopenharmony_ci xgbe_prepare_tx_stop(pdata, i); 34348c2ecf20Sopenharmony_ci 34358c2ecf20Sopenharmony_ci /* Disable MAC Tx */ 34368c2ecf20Sopenharmony_ci XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0); 34378c2ecf20Sopenharmony_ci 34388c2ecf20Sopenharmony_ci /* Disable each Tx DMA channel */ 34398c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 34408c2ecf20Sopenharmony_ci if (!pdata->channel[i]->tx_ring) 34418c2ecf20Sopenharmony_ci break; 34428c2ecf20Sopenharmony_ci 34438c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 0); 34448c2ecf20Sopenharmony_ci } 34458c2ecf20Sopenharmony_ci} 34468c2ecf20Sopenharmony_ci 34478c2ecf20Sopenharmony_cistatic void xgbe_powerup_rx(struct xgbe_prv_data *pdata) 34488c2ecf20Sopenharmony_ci{ 34498c2ecf20Sopenharmony_ci unsigned int i; 34508c2ecf20Sopenharmony_ci 34518c2ecf20Sopenharmony_ci /* Enable each Rx DMA channel */ 34528c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 34538c2ecf20Sopenharmony_ci if (!pdata->channel[i]->rx_ring) 34548c2ecf20Sopenharmony_ci break; 34558c2ecf20Sopenharmony_ci 34568c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 1); 34578c2ecf20Sopenharmony_ci } 34588c2ecf20Sopenharmony_ci} 34598c2ecf20Sopenharmony_ci 34608c2ecf20Sopenharmony_cistatic void xgbe_powerdown_rx(struct xgbe_prv_data *pdata) 34618c2ecf20Sopenharmony_ci{ 34628c2ecf20Sopenharmony_ci unsigned int i; 34638c2ecf20Sopenharmony_ci 34648c2ecf20Sopenharmony_ci /* Disable each Rx DMA channel */ 34658c2ecf20Sopenharmony_ci for (i = 0; i < pdata->channel_count; i++) { 34668c2ecf20Sopenharmony_ci if (!pdata->channel[i]->rx_ring) 34678c2ecf20Sopenharmony_ci break; 34688c2ecf20Sopenharmony_ci 34698c2ecf20Sopenharmony_ci XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 0); 34708c2ecf20Sopenharmony_ci } 34718c2ecf20Sopenharmony_ci} 34728c2ecf20Sopenharmony_ci 34738c2ecf20Sopenharmony_cistatic int xgbe_init(struct xgbe_prv_data *pdata) 34748c2ecf20Sopenharmony_ci{ 34758c2ecf20Sopenharmony_ci struct xgbe_desc_if *desc_if = &pdata->desc_if; 34768c2ecf20Sopenharmony_ci int ret; 34778c2ecf20Sopenharmony_ci 34788c2ecf20Sopenharmony_ci DBGPR("-->xgbe_init\n"); 34798c2ecf20Sopenharmony_ci 34808c2ecf20Sopenharmony_ci /* Flush Tx queues */ 34818c2ecf20Sopenharmony_ci ret = xgbe_flush_tx_queues(pdata); 34828c2ecf20Sopenharmony_ci if (ret) { 34838c2ecf20Sopenharmony_ci netdev_err(pdata->netdev, "error flushing TX queues\n"); 34848c2ecf20Sopenharmony_ci return ret; 34858c2ecf20Sopenharmony_ci } 34868c2ecf20Sopenharmony_ci 34878c2ecf20Sopenharmony_ci /* 34888c2ecf20Sopenharmony_ci * Initialize DMA related features 34898c2ecf20Sopenharmony_ci */ 34908c2ecf20Sopenharmony_ci xgbe_config_dma_bus(pdata); 34918c2ecf20Sopenharmony_ci xgbe_config_dma_cache(pdata); 34928c2ecf20Sopenharmony_ci xgbe_config_osp_mode(pdata); 34938c2ecf20Sopenharmony_ci xgbe_config_pbl_val(pdata); 34948c2ecf20Sopenharmony_ci xgbe_config_rx_coalesce(pdata); 34958c2ecf20Sopenharmony_ci xgbe_config_tx_coalesce(pdata); 34968c2ecf20Sopenharmony_ci xgbe_config_rx_buffer_size(pdata); 34978c2ecf20Sopenharmony_ci xgbe_config_tso_mode(pdata); 34988c2ecf20Sopenharmony_ci xgbe_config_sph_mode(pdata); 34998c2ecf20Sopenharmony_ci xgbe_config_rss(pdata); 35008c2ecf20Sopenharmony_ci desc_if->wrapper_tx_desc_init(pdata); 35018c2ecf20Sopenharmony_ci desc_if->wrapper_rx_desc_init(pdata); 35028c2ecf20Sopenharmony_ci xgbe_enable_dma_interrupts(pdata); 35038c2ecf20Sopenharmony_ci 35048c2ecf20Sopenharmony_ci /* 35058c2ecf20Sopenharmony_ci * Initialize MTL related features 35068c2ecf20Sopenharmony_ci */ 35078c2ecf20Sopenharmony_ci xgbe_config_mtl_mode(pdata); 35088c2ecf20Sopenharmony_ci xgbe_config_queue_mapping(pdata); 35098c2ecf20Sopenharmony_ci xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode); 35108c2ecf20Sopenharmony_ci xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode); 35118c2ecf20Sopenharmony_ci xgbe_config_tx_threshold(pdata, pdata->tx_threshold); 35128c2ecf20Sopenharmony_ci xgbe_config_rx_threshold(pdata, pdata->rx_threshold); 35138c2ecf20Sopenharmony_ci xgbe_config_tx_fifo_size(pdata); 35148c2ecf20Sopenharmony_ci xgbe_config_rx_fifo_size(pdata); 35158c2ecf20Sopenharmony_ci /*TODO: Error Packet and undersized good Packet forwarding enable 35168c2ecf20Sopenharmony_ci (FEP and FUP) 35178c2ecf20Sopenharmony_ci */ 35188c2ecf20Sopenharmony_ci xgbe_config_dcb_tc(pdata); 35198c2ecf20Sopenharmony_ci xgbe_enable_mtl_interrupts(pdata); 35208c2ecf20Sopenharmony_ci 35218c2ecf20Sopenharmony_ci /* 35228c2ecf20Sopenharmony_ci * Initialize MAC related features 35238c2ecf20Sopenharmony_ci */ 35248c2ecf20Sopenharmony_ci xgbe_config_mac_address(pdata); 35258c2ecf20Sopenharmony_ci xgbe_config_rx_mode(pdata); 35268c2ecf20Sopenharmony_ci xgbe_config_jumbo_enable(pdata); 35278c2ecf20Sopenharmony_ci xgbe_config_flow_control(pdata); 35288c2ecf20Sopenharmony_ci xgbe_config_mac_speed(pdata); 35298c2ecf20Sopenharmony_ci xgbe_config_checksum_offload(pdata); 35308c2ecf20Sopenharmony_ci xgbe_config_vlan_support(pdata); 35318c2ecf20Sopenharmony_ci xgbe_config_mmc(pdata); 35328c2ecf20Sopenharmony_ci xgbe_enable_mac_interrupts(pdata); 35338c2ecf20Sopenharmony_ci 35348c2ecf20Sopenharmony_ci /* 35358c2ecf20Sopenharmony_ci * Initialize ECC related features 35368c2ecf20Sopenharmony_ci */ 35378c2ecf20Sopenharmony_ci xgbe_enable_ecc_interrupts(pdata); 35388c2ecf20Sopenharmony_ci 35398c2ecf20Sopenharmony_ci DBGPR("<--xgbe_init\n"); 35408c2ecf20Sopenharmony_ci 35418c2ecf20Sopenharmony_ci return 0; 35428c2ecf20Sopenharmony_ci} 35438c2ecf20Sopenharmony_ci 35448c2ecf20Sopenharmony_civoid xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if) 35458c2ecf20Sopenharmony_ci{ 35468c2ecf20Sopenharmony_ci DBGPR("-->xgbe_init_function_ptrs\n"); 35478c2ecf20Sopenharmony_ci 35488c2ecf20Sopenharmony_ci hw_if->tx_complete = xgbe_tx_complete; 35498c2ecf20Sopenharmony_ci 35508c2ecf20Sopenharmony_ci hw_if->set_mac_address = xgbe_set_mac_address; 35518c2ecf20Sopenharmony_ci hw_if->config_rx_mode = xgbe_config_rx_mode; 35528c2ecf20Sopenharmony_ci 35538c2ecf20Sopenharmony_ci hw_if->enable_rx_csum = xgbe_enable_rx_csum; 35548c2ecf20Sopenharmony_ci hw_if->disable_rx_csum = xgbe_disable_rx_csum; 35558c2ecf20Sopenharmony_ci 35568c2ecf20Sopenharmony_ci hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping; 35578c2ecf20Sopenharmony_ci hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping; 35588c2ecf20Sopenharmony_ci hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering; 35598c2ecf20Sopenharmony_ci hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering; 35608c2ecf20Sopenharmony_ci hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table; 35618c2ecf20Sopenharmony_ci 35628c2ecf20Sopenharmony_ci hw_if->read_mmd_regs = xgbe_read_mmd_regs; 35638c2ecf20Sopenharmony_ci hw_if->write_mmd_regs = xgbe_write_mmd_regs; 35648c2ecf20Sopenharmony_ci 35658c2ecf20Sopenharmony_ci hw_if->set_speed = xgbe_set_speed; 35668c2ecf20Sopenharmony_ci 35678c2ecf20Sopenharmony_ci hw_if->set_ext_mii_mode = xgbe_set_ext_mii_mode; 35688c2ecf20Sopenharmony_ci hw_if->read_ext_mii_regs = xgbe_read_ext_mii_regs; 35698c2ecf20Sopenharmony_ci hw_if->write_ext_mii_regs = xgbe_write_ext_mii_regs; 35708c2ecf20Sopenharmony_ci 35718c2ecf20Sopenharmony_ci hw_if->set_gpio = xgbe_set_gpio; 35728c2ecf20Sopenharmony_ci hw_if->clr_gpio = xgbe_clr_gpio; 35738c2ecf20Sopenharmony_ci 35748c2ecf20Sopenharmony_ci hw_if->enable_tx = xgbe_enable_tx; 35758c2ecf20Sopenharmony_ci hw_if->disable_tx = xgbe_disable_tx; 35768c2ecf20Sopenharmony_ci hw_if->enable_rx = xgbe_enable_rx; 35778c2ecf20Sopenharmony_ci hw_if->disable_rx = xgbe_disable_rx; 35788c2ecf20Sopenharmony_ci 35798c2ecf20Sopenharmony_ci hw_if->powerup_tx = xgbe_powerup_tx; 35808c2ecf20Sopenharmony_ci hw_if->powerdown_tx = xgbe_powerdown_tx; 35818c2ecf20Sopenharmony_ci hw_if->powerup_rx = xgbe_powerup_rx; 35828c2ecf20Sopenharmony_ci hw_if->powerdown_rx = xgbe_powerdown_rx; 35838c2ecf20Sopenharmony_ci 35848c2ecf20Sopenharmony_ci hw_if->dev_xmit = xgbe_dev_xmit; 35858c2ecf20Sopenharmony_ci hw_if->dev_read = xgbe_dev_read; 35868c2ecf20Sopenharmony_ci hw_if->enable_int = xgbe_enable_int; 35878c2ecf20Sopenharmony_ci hw_if->disable_int = xgbe_disable_int; 35888c2ecf20Sopenharmony_ci hw_if->init = xgbe_init; 35898c2ecf20Sopenharmony_ci hw_if->exit = xgbe_exit; 35908c2ecf20Sopenharmony_ci 35918c2ecf20Sopenharmony_ci /* Descriptor related Sequences have to be initialized here */ 35928c2ecf20Sopenharmony_ci hw_if->tx_desc_init = xgbe_tx_desc_init; 35938c2ecf20Sopenharmony_ci hw_if->rx_desc_init = xgbe_rx_desc_init; 35948c2ecf20Sopenharmony_ci hw_if->tx_desc_reset = xgbe_tx_desc_reset; 35958c2ecf20Sopenharmony_ci hw_if->rx_desc_reset = xgbe_rx_desc_reset; 35968c2ecf20Sopenharmony_ci hw_if->is_last_desc = xgbe_is_last_desc; 35978c2ecf20Sopenharmony_ci hw_if->is_context_desc = xgbe_is_context_desc; 35988c2ecf20Sopenharmony_ci hw_if->tx_start_xmit = xgbe_tx_start_xmit; 35998c2ecf20Sopenharmony_ci 36008c2ecf20Sopenharmony_ci /* For FLOW ctrl */ 36018c2ecf20Sopenharmony_ci hw_if->config_tx_flow_control = xgbe_config_tx_flow_control; 36028c2ecf20Sopenharmony_ci hw_if->config_rx_flow_control = xgbe_config_rx_flow_control; 36038c2ecf20Sopenharmony_ci 36048c2ecf20Sopenharmony_ci /* For RX coalescing */ 36058c2ecf20Sopenharmony_ci hw_if->config_rx_coalesce = xgbe_config_rx_coalesce; 36068c2ecf20Sopenharmony_ci hw_if->config_tx_coalesce = xgbe_config_tx_coalesce; 36078c2ecf20Sopenharmony_ci hw_if->usec_to_riwt = xgbe_usec_to_riwt; 36088c2ecf20Sopenharmony_ci hw_if->riwt_to_usec = xgbe_riwt_to_usec; 36098c2ecf20Sopenharmony_ci 36108c2ecf20Sopenharmony_ci /* For RX and TX threshold config */ 36118c2ecf20Sopenharmony_ci hw_if->config_rx_threshold = xgbe_config_rx_threshold; 36128c2ecf20Sopenharmony_ci hw_if->config_tx_threshold = xgbe_config_tx_threshold; 36138c2ecf20Sopenharmony_ci 36148c2ecf20Sopenharmony_ci /* For RX and TX Store and Forward Mode config */ 36158c2ecf20Sopenharmony_ci hw_if->config_rsf_mode = xgbe_config_rsf_mode; 36168c2ecf20Sopenharmony_ci hw_if->config_tsf_mode = xgbe_config_tsf_mode; 36178c2ecf20Sopenharmony_ci 36188c2ecf20Sopenharmony_ci /* For TX DMA Operating on Second Frame config */ 36198c2ecf20Sopenharmony_ci hw_if->config_osp_mode = xgbe_config_osp_mode; 36208c2ecf20Sopenharmony_ci 36218c2ecf20Sopenharmony_ci /* For MMC statistics support */ 36228c2ecf20Sopenharmony_ci hw_if->tx_mmc_int = xgbe_tx_mmc_int; 36238c2ecf20Sopenharmony_ci hw_if->rx_mmc_int = xgbe_rx_mmc_int; 36248c2ecf20Sopenharmony_ci hw_if->read_mmc_stats = xgbe_read_mmc_stats; 36258c2ecf20Sopenharmony_ci 36268c2ecf20Sopenharmony_ci /* For PTP config */ 36278c2ecf20Sopenharmony_ci hw_if->config_tstamp = xgbe_config_tstamp; 36288c2ecf20Sopenharmony_ci hw_if->update_tstamp_addend = xgbe_update_tstamp_addend; 36298c2ecf20Sopenharmony_ci hw_if->set_tstamp_time = xgbe_set_tstamp_time; 36308c2ecf20Sopenharmony_ci hw_if->get_tstamp_time = xgbe_get_tstamp_time; 36318c2ecf20Sopenharmony_ci hw_if->get_tx_tstamp = xgbe_get_tx_tstamp; 36328c2ecf20Sopenharmony_ci 36338c2ecf20Sopenharmony_ci /* For Data Center Bridging config */ 36348c2ecf20Sopenharmony_ci hw_if->config_tc = xgbe_config_tc; 36358c2ecf20Sopenharmony_ci hw_if->config_dcb_tc = xgbe_config_dcb_tc; 36368c2ecf20Sopenharmony_ci hw_if->config_dcb_pfc = xgbe_config_dcb_pfc; 36378c2ecf20Sopenharmony_ci 36388c2ecf20Sopenharmony_ci /* For Receive Side Scaling */ 36398c2ecf20Sopenharmony_ci hw_if->enable_rss = xgbe_enable_rss; 36408c2ecf20Sopenharmony_ci hw_if->disable_rss = xgbe_disable_rss; 36418c2ecf20Sopenharmony_ci hw_if->set_rss_hash_key = xgbe_set_rss_hash_key; 36428c2ecf20Sopenharmony_ci hw_if->set_rss_lookup_table = xgbe_set_rss_lookup_table; 36438c2ecf20Sopenharmony_ci 36448c2ecf20Sopenharmony_ci /* For ECC */ 36458c2ecf20Sopenharmony_ci hw_if->disable_ecc_ded = xgbe_disable_ecc_ded; 36468c2ecf20Sopenharmony_ci hw_if->disable_ecc_sec = xgbe_disable_ecc_sec; 36478c2ecf20Sopenharmony_ci 36488c2ecf20Sopenharmony_ci /* For VXLAN */ 36498c2ecf20Sopenharmony_ci hw_if->enable_vxlan = xgbe_enable_vxlan; 36508c2ecf20Sopenharmony_ci hw_if->disable_vxlan = xgbe_disable_vxlan; 36518c2ecf20Sopenharmony_ci hw_if->set_vxlan_id = xgbe_set_vxlan_id; 36528c2ecf20Sopenharmony_ci 36538c2ecf20Sopenharmony_ci DBGPR("<--xgbe_init_function_ptrs\n"); 36548c2ecf20Sopenharmony_ci} 3655