18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 10G controller driver for Samsung SoCs 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2013 Samsung Electronics Co., Ltd. 58c2ecf20Sopenharmony_ci * http://www.samsung.com 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Author: Siva Reddy Kallam <siva.kallam@samsung.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/clk.h> 138c2ecf20Sopenharmony_ci#include <linux/crc32.h> 148c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h> 158c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 168c2ecf20Sopenharmony_ci#include <linux/ethtool.h> 178c2ecf20Sopenharmony_ci#include <linux/if.h> 188c2ecf20Sopenharmony_ci#include <linux/if_ether.h> 198c2ecf20Sopenharmony_ci#include <linux/if_vlan.h> 208c2ecf20Sopenharmony_ci#include <linux/init.h> 218c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 228c2ecf20Sopenharmony_ci#include <linux/ip.h> 238c2ecf20Sopenharmony_ci#include <linux/kernel.h> 248c2ecf20Sopenharmony_ci#include <linux/mii.h> 258c2ecf20Sopenharmony_ci#include <linux/module.h> 268c2ecf20Sopenharmony_ci#include <linux/net_tstamp.h> 278c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 288c2ecf20Sopenharmony_ci#include <linux/phy.h> 298c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 308c2ecf20Sopenharmony_ci#include <linux/prefetch.h> 318c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 328c2ecf20Sopenharmony_ci#include <linux/slab.h> 338c2ecf20Sopenharmony_ci#include <linux/tcp.h> 348c2ecf20Sopenharmony_ci#include <linux/sxgbe_platform.h> 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#include "sxgbe_common.h" 378c2ecf20Sopenharmony_ci#include "sxgbe_desc.h" 388c2ecf20Sopenharmony_ci#include "sxgbe_dma.h" 398c2ecf20Sopenharmony_ci#include "sxgbe_mtl.h" 408c2ecf20Sopenharmony_ci#include "sxgbe_reg.h" 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define SXGBE_ALIGN(x) L1_CACHE_ALIGN(x) 438c2ecf20Sopenharmony_ci#define JUMBO_LEN 9000 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* Module parameters */ 468c2ecf20Sopenharmony_ci#define TX_TIMEO 5000 478c2ecf20Sopenharmony_ci#define DMA_TX_SIZE 512 488c2ecf20Sopenharmony_ci#define DMA_RX_SIZE 1024 498c2ecf20Sopenharmony_ci#define TC_DEFAULT 64 508c2ecf20Sopenharmony_ci#define DMA_BUFFER_SIZE BUF_SIZE_2KiB 518c2ecf20Sopenharmony_ci/* The default timer value as per the sxgbe specification 1 sec(1000 ms) */ 528c2ecf20Sopenharmony_ci#define SXGBE_DEFAULT_LPI_TIMER 1000 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic int debug = -1; 558c2ecf20Sopenharmony_cistatic int eee_timer = SXGBE_DEFAULT_LPI_TIMER; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cimodule_param(eee_timer, int, 0644); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cimodule_param(debug, int, 0644); 608c2ecf20Sopenharmony_cistatic const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE | 618c2ecf20Sopenharmony_ci NETIF_MSG_LINK | NETIF_MSG_IFUP | 628c2ecf20Sopenharmony_ci NETIF_MSG_IFDOWN | NETIF_MSG_TIMER); 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistatic irqreturn_t sxgbe_common_interrupt(int irq, void *dev_id); 658c2ecf20Sopenharmony_cistatic irqreturn_t sxgbe_tx_interrupt(int irq, void *dev_id); 668c2ecf20Sopenharmony_cistatic irqreturn_t sxgbe_rx_interrupt(int irq, void *dev_id); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci#define SXGBE_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x)) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define SXGBE_LPI_TIMER(x) (jiffies + msecs_to_jiffies(x)) 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/** 738c2ecf20Sopenharmony_ci * sxgbe_verify_args - verify the driver parameters. 748c2ecf20Sopenharmony_ci * Description: it verifies if some wrong parameter is passed to the driver. 758c2ecf20Sopenharmony_ci * Note that wrong parameters are replaced with the default values. 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_cistatic void sxgbe_verify_args(void) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci if (unlikely(eee_timer < 0)) 808c2ecf20Sopenharmony_ci eee_timer = SXGBE_DEFAULT_LPI_TIMER; 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic void sxgbe_enable_eee_mode(const struct sxgbe_priv_data *priv) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci /* Check and enter in LPI mode */ 868c2ecf20Sopenharmony_ci if (!priv->tx_path_in_lpi_mode) 878c2ecf20Sopenharmony_ci priv->hw->mac->set_eee_mode(priv->ioaddr); 888c2ecf20Sopenharmony_ci} 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_civoid sxgbe_disable_eee_mode(struct sxgbe_priv_data * const priv) 918c2ecf20Sopenharmony_ci{ 928c2ecf20Sopenharmony_ci /* Exit and disable EEE in case of we are are in LPI state. */ 938c2ecf20Sopenharmony_ci priv->hw->mac->reset_eee_mode(priv->ioaddr); 948c2ecf20Sopenharmony_ci del_timer_sync(&priv->eee_ctrl_timer); 958c2ecf20Sopenharmony_ci priv->tx_path_in_lpi_mode = false; 968c2ecf20Sopenharmony_ci} 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci/** 998c2ecf20Sopenharmony_ci * sxgbe_eee_ctrl_timer 1008c2ecf20Sopenharmony_ci * @t: timer list containing a data 1018c2ecf20Sopenharmony_ci * Description: 1028c2ecf20Sopenharmony_ci * If there is no data transfer and if we are not in LPI state, 1038c2ecf20Sopenharmony_ci * then MAC Transmitter can be moved to LPI state. 1048c2ecf20Sopenharmony_ci */ 1058c2ecf20Sopenharmony_cistatic void sxgbe_eee_ctrl_timer(struct timer_list *t) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = from_timer(priv, t, eee_ctrl_timer); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci sxgbe_enable_eee_mode(priv); 1108c2ecf20Sopenharmony_ci mod_timer(&priv->eee_ctrl_timer, SXGBE_LPI_TIMER(eee_timer)); 1118c2ecf20Sopenharmony_ci} 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/** 1148c2ecf20Sopenharmony_ci * sxgbe_eee_init 1158c2ecf20Sopenharmony_ci * @priv: private device pointer 1168c2ecf20Sopenharmony_ci * Description: 1178c2ecf20Sopenharmony_ci * If the EEE support has been enabled while configuring the driver, 1188c2ecf20Sopenharmony_ci * if the GMAC actually supports the EEE (from the HW cap reg) and the 1198c2ecf20Sopenharmony_ci * phy can also manage EEE, so enable the LPI state and start the timer 1208c2ecf20Sopenharmony_ci * to verify if the tx path can enter in LPI state. 1218c2ecf20Sopenharmony_ci */ 1228c2ecf20Sopenharmony_cibool sxgbe_eee_init(struct sxgbe_priv_data * const priv) 1238c2ecf20Sopenharmony_ci{ 1248c2ecf20Sopenharmony_ci struct net_device *ndev = priv->dev; 1258c2ecf20Sopenharmony_ci bool ret = false; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci /* MAC core supports the EEE feature. */ 1288c2ecf20Sopenharmony_ci if (priv->hw_cap.eee) { 1298c2ecf20Sopenharmony_ci /* Check if the PHY supports EEE */ 1308c2ecf20Sopenharmony_ci if (phy_init_eee(ndev->phydev, 1)) 1318c2ecf20Sopenharmony_ci return false; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci priv->eee_active = 1; 1348c2ecf20Sopenharmony_ci timer_setup(&priv->eee_ctrl_timer, sxgbe_eee_ctrl_timer, 0); 1358c2ecf20Sopenharmony_ci priv->eee_ctrl_timer.expires = SXGBE_LPI_TIMER(eee_timer); 1368c2ecf20Sopenharmony_ci add_timer(&priv->eee_ctrl_timer); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci priv->hw->mac->set_eee_timer(priv->ioaddr, 1398c2ecf20Sopenharmony_ci SXGBE_DEFAULT_LPI_TIMER, 1408c2ecf20Sopenharmony_ci priv->tx_lpi_timer); 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci pr_info("Energy-Efficient Ethernet initialized\n"); 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci ret = true; 1458c2ecf20Sopenharmony_ci } 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci return ret; 1488c2ecf20Sopenharmony_ci} 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistatic void sxgbe_eee_adjust(const struct sxgbe_priv_data *priv) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci struct net_device *ndev = priv->dev; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci /* When the EEE has been already initialised we have to 1558c2ecf20Sopenharmony_ci * modify the PLS bit in the LPI ctrl & status reg according 1568c2ecf20Sopenharmony_ci * to the PHY link status. For this reason. 1578c2ecf20Sopenharmony_ci */ 1588c2ecf20Sopenharmony_ci if (priv->eee_enabled) 1598c2ecf20Sopenharmony_ci priv->hw->mac->set_eee_pls(priv->ioaddr, ndev->phydev->link); 1608c2ecf20Sopenharmony_ci} 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci/** 1638c2ecf20Sopenharmony_ci * sxgbe_clk_csr_set - dynamically set the MDC clock 1648c2ecf20Sopenharmony_ci * @priv: driver private structure 1658c2ecf20Sopenharmony_ci * Description: this is to dynamically set the MDC clock according to the csr 1668c2ecf20Sopenharmony_ci * clock input. 1678c2ecf20Sopenharmony_ci */ 1688c2ecf20Sopenharmony_cistatic void sxgbe_clk_csr_set(struct sxgbe_priv_data *priv) 1698c2ecf20Sopenharmony_ci{ 1708c2ecf20Sopenharmony_ci u32 clk_rate = clk_get_rate(priv->sxgbe_clk); 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci /* assign the proper divider, this will be used during 1738c2ecf20Sopenharmony_ci * mdio communication 1748c2ecf20Sopenharmony_ci */ 1758c2ecf20Sopenharmony_ci if (clk_rate < SXGBE_CSR_F_150M) 1768c2ecf20Sopenharmony_ci priv->clk_csr = SXGBE_CSR_100_150M; 1778c2ecf20Sopenharmony_ci else if (clk_rate <= SXGBE_CSR_F_250M) 1788c2ecf20Sopenharmony_ci priv->clk_csr = SXGBE_CSR_150_250M; 1798c2ecf20Sopenharmony_ci else if (clk_rate <= SXGBE_CSR_F_300M) 1808c2ecf20Sopenharmony_ci priv->clk_csr = SXGBE_CSR_250_300M; 1818c2ecf20Sopenharmony_ci else if (clk_rate <= SXGBE_CSR_F_350M) 1828c2ecf20Sopenharmony_ci priv->clk_csr = SXGBE_CSR_300_350M; 1838c2ecf20Sopenharmony_ci else if (clk_rate <= SXGBE_CSR_F_400M) 1848c2ecf20Sopenharmony_ci priv->clk_csr = SXGBE_CSR_350_400M; 1858c2ecf20Sopenharmony_ci else if (clk_rate <= SXGBE_CSR_F_500M) 1868c2ecf20Sopenharmony_ci priv->clk_csr = SXGBE_CSR_400_500M; 1878c2ecf20Sopenharmony_ci} 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci/* minimum number of free TX descriptors required to wake up TX process */ 1908c2ecf20Sopenharmony_ci#define SXGBE_TX_THRESH(x) (x->dma_tx_size/4) 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_cistatic inline u32 sxgbe_tx_avail(struct sxgbe_tx_queue *queue, int tx_qsize) 1938c2ecf20Sopenharmony_ci{ 1948c2ecf20Sopenharmony_ci return queue->dirty_tx + tx_qsize - queue->cur_tx - 1; 1958c2ecf20Sopenharmony_ci} 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci/** 1988c2ecf20Sopenharmony_ci * sxgbe_adjust_link 1998c2ecf20Sopenharmony_ci * @dev: net device structure 2008c2ecf20Sopenharmony_ci * Description: it adjusts the link parameters. 2018c2ecf20Sopenharmony_ci */ 2028c2ecf20Sopenharmony_cistatic void sxgbe_adjust_link(struct net_device *dev) 2038c2ecf20Sopenharmony_ci{ 2048c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 2058c2ecf20Sopenharmony_ci struct phy_device *phydev = dev->phydev; 2068c2ecf20Sopenharmony_ci u8 new_state = 0; 2078c2ecf20Sopenharmony_ci u8 speed = 0xff; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci if (!phydev) 2108c2ecf20Sopenharmony_ci return; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci /* SXGBE is not supporting auto-negotiation and 2138c2ecf20Sopenharmony_ci * half duplex mode. so, not handling duplex change 2148c2ecf20Sopenharmony_ci * in this function. only handling speed and link status 2158c2ecf20Sopenharmony_ci */ 2168c2ecf20Sopenharmony_ci if (phydev->link) { 2178c2ecf20Sopenharmony_ci if (phydev->speed != priv->speed) { 2188c2ecf20Sopenharmony_ci new_state = 1; 2198c2ecf20Sopenharmony_ci switch (phydev->speed) { 2208c2ecf20Sopenharmony_ci case SPEED_10000: 2218c2ecf20Sopenharmony_ci speed = SXGBE_SPEED_10G; 2228c2ecf20Sopenharmony_ci break; 2238c2ecf20Sopenharmony_ci case SPEED_2500: 2248c2ecf20Sopenharmony_ci speed = SXGBE_SPEED_2_5G; 2258c2ecf20Sopenharmony_ci break; 2268c2ecf20Sopenharmony_ci case SPEED_1000: 2278c2ecf20Sopenharmony_ci speed = SXGBE_SPEED_1G; 2288c2ecf20Sopenharmony_ci break; 2298c2ecf20Sopenharmony_ci default: 2308c2ecf20Sopenharmony_ci netif_err(priv, link, dev, 2318c2ecf20Sopenharmony_ci "Speed (%d) not supported\n", 2328c2ecf20Sopenharmony_ci phydev->speed); 2338c2ecf20Sopenharmony_ci } 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci priv->speed = phydev->speed; 2368c2ecf20Sopenharmony_ci priv->hw->mac->set_speed(priv->ioaddr, speed); 2378c2ecf20Sopenharmony_ci } 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci if (!priv->oldlink) { 2408c2ecf20Sopenharmony_ci new_state = 1; 2418c2ecf20Sopenharmony_ci priv->oldlink = 1; 2428c2ecf20Sopenharmony_ci } 2438c2ecf20Sopenharmony_ci } else if (priv->oldlink) { 2448c2ecf20Sopenharmony_ci new_state = 1; 2458c2ecf20Sopenharmony_ci priv->oldlink = 0; 2468c2ecf20Sopenharmony_ci priv->speed = SPEED_UNKNOWN; 2478c2ecf20Sopenharmony_ci } 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci if (new_state & netif_msg_link(priv)) 2508c2ecf20Sopenharmony_ci phy_print_status(phydev); 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci /* Alter the MAC settings for EEE */ 2538c2ecf20Sopenharmony_ci sxgbe_eee_adjust(priv); 2548c2ecf20Sopenharmony_ci} 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci/** 2578c2ecf20Sopenharmony_ci * sxgbe_init_phy - PHY initialization 2588c2ecf20Sopenharmony_ci * @ndev: net device structure 2598c2ecf20Sopenharmony_ci * Description: it initializes the driver's PHY state, and attaches the PHY 2608c2ecf20Sopenharmony_ci * to the mac driver. 2618c2ecf20Sopenharmony_ci * Return value: 2628c2ecf20Sopenharmony_ci * 0 on success 2638c2ecf20Sopenharmony_ci */ 2648c2ecf20Sopenharmony_cistatic int sxgbe_init_phy(struct net_device *ndev) 2658c2ecf20Sopenharmony_ci{ 2668c2ecf20Sopenharmony_ci char phy_id_fmt[MII_BUS_ID_SIZE + 3]; 2678c2ecf20Sopenharmony_ci char bus_id[MII_BUS_ID_SIZE]; 2688c2ecf20Sopenharmony_ci struct phy_device *phydev; 2698c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(ndev); 2708c2ecf20Sopenharmony_ci int phy_iface = priv->plat->interface; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci /* assign default link status */ 2738c2ecf20Sopenharmony_ci priv->oldlink = 0; 2748c2ecf20Sopenharmony_ci priv->speed = SPEED_UNKNOWN; 2758c2ecf20Sopenharmony_ci priv->oldduplex = DUPLEX_UNKNOWN; 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci if (priv->plat->phy_bus_name) 2788c2ecf20Sopenharmony_ci snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x", 2798c2ecf20Sopenharmony_ci priv->plat->phy_bus_name, priv->plat->bus_id); 2808c2ecf20Sopenharmony_ci else 2818c2ecf20Sopenharmony_ci snprintf(bus_id, MII_BUS_ID_SIZE, "sxgbe-%x", 2828c2ecf20Sopenharmony_ci priv->plat->bus_id); 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id, 2858c2ecf20Sopenharmony_ci priv->plat->phy_addr); 2868c2ecf20Sopenharmony_ci netdev_dbg(ndev, "%s: trying to attach to %s\n", __func__, phy_id_fmt); 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci phydev = phy_connect(ndev, phy_id_fmt, &sxgbe_adjust_link, phy_iface); 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci if (IS_ERR(phydev)) { 2918c2ecf20Sopenharmony_ci netdev_err(ndev, "Could not attach to PHY\n"); 2928c2ecf20Sopenharmony_ci return PTR_ERR(phydev); 2938c2ecf20Sopenharmony_ci } 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci /* Stop Advertising 1000BASE Capability if interface is not GMII */ 2968c2ecf20Sopenharmony_ci if ((phy_iface == PHY_INTERFACE_MODE_MII) || 2978c2ecf20Sopenharmony_ci (phy_iface == PHY_INTERFACE_MODE_RMII)) 2988c2ecf20Sopenharmony_ci phy_set_max_speed(phydev, SPEED_1000); 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci if (phydev->phy_id == 0) { 3018c2ecf20Sopenharmony_ci phy_disconnect(phydev); 3028c2ecf20Sopenharmony_ci return -ENODEV; 3038c2ecf20Sopenharmony_ci } 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci netdev_dbg(ndev, "%s: attached to PHY (UID 0x%x) Link = %d\n", 3068c2ecf20Sopenharmony_ci __func__, phydev->phy_id, phydev->link); 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci return 0; 3098c2ecf20Sopenharmony_ci} 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci/** 3128c2ecf20Sopenharmony_ci * sxgbe_clear_descriptors: clear descriptors 3138c2ecf20Sopenharmony_ci * @priv: driver private structure 3148c2ecf20Sopenharmony_ci * Description: this function is called to clear the tx and rx descriptors 3158c2ecf20Sopenharmony_ci * in case of both basic and extended descriptors are used. 3168c2ecf20Sopenharmony_ci */ 3178c2ecf20Sopenharmony_cistatic void sxgbe_clear_descriptors(struct sxgbe_priv_data *priv) 3188c2ecf20Sopenharmony_ci{ 3198c2ecf20Sopenharmony_ci int i, j; 3208c2ecf20Sopenharmony_ci unsigned int txsize = priv->dma_tx_size; 3218c2ecf20Sopenharmony_ci unsigned int rxsize = priv->dma_rx_size; 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci /* Clear the Rx/Tx descriptors */ 3248c2ecf20Sopenharmony_ci for (j = 0; j < SXGBE_RX_QUEUES; j++) { 3258c2ecf20Sopenharmony_ci for (i = 0; i < rxsize; i++) 3268c2ecf20Sopenharmony_ci priv->hw->desc->init_rx_desc(&priv->rxq[j]->dma_rx[i], 3278c2ecf20Sopenharmony_ci priv->use_riwt, priv->mode, 3288c2ecf20Sopenharmony_ci (i == rxsize - 1)); 3298c2ecf20Sopenharmony_ci } 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci for (j = 0; j < SXGBE_TX_QUEUES; j++) { 3328c2ecf20Sopenharmony_ci for (i = 0; i < txsize; i++) 3338c2ecf20Sopenharmony_ci priv->hw->desc->init_tx_desc(&priv->txq[j]->dma_tx[i]); 3348c2ecf20Sopenharmony_ci } 3358c2ecf20Sopenharmony_ci} 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_cistatic int sxgbe_init_rx_buffers(struct net_device *dev, 3388c2ecf20Sopenharmony_ci struct sxgbe_rx_norm_desc *p, int i, 3398c2ecf20Sopenharmony_ci unsigned int dma_buf_sz, 3408c2ecf20Sopenharmony_ci struct sxgbe_rx_queue *rx_ring) 3418c2ecf20Sopenharmony_ci{ 3428c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 3438c2ecf20Sopenharmony_ci struct sk_buff *skb; 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci skb = __netdev_alloc_skb_ip_align(dev, dma_buf_sz, GFP_KERNEL); 3468c2ecf20Sopenharmony_ci if (!skb) 3478c2ecf20Sopenharmony_ci return -ENOMEM; 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci rx_ring->rx_skbuff[i] = skb; 3508c2ecf20Sopenharmony_ci rx_ring->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data, 3518c2ecf20Sopenharmony_ci dma_buf_sz, DMA_FROM_DEVICE); 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci if (dma_mapping_error(priv->device, rx_ring->rx_skbuff_dma[i])) { 3548c2ecf20Sopenharmony_ci netdev_err(dev, "%s: DMA mapping error\n", __func__); 3558c2ecf20Sopenharmony_ci dev_kfree_skb_any(skb); 3568c2ecf20Sopenharmony_ci return -EINVAL; 3578c2ecf20Sopenharmony_ci } 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci p->rdes23.rx_rd_des23.buf2_addr = rx_ring->rx_skbuff_dma[i]; 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci return 0; 3628c2ecf20Sopenharmony_ci} 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci/** 3658c2ecf20Sopenharmony_ci * sxgbe_free_rx_buffers - free what sxgbe_init_rx_buffers() allocated 3668c2ecf20Sopenharmony_ci * @dev: net device structure 3678c2ecf20Sopenharmony_ci * @p: dec pointer 3688c2ecf20Sopenharmony_ci * @i: index 3698c2ecf20Sopenharmony_ci * @dma_buf_sz: size 3708c2ecf20Sopenharmony_ci * @rx_ring: ring to be freed 3718c2ecf20Sopenharmony_ci * 3728c2ecf20Sopenharmony_ci * Description: this function initializes the DMA RX descriptor 3738c2ecf20Sopenharmony_ci */ 3748c2ecf20Sopenharmony_cistatic void sxgbe_free_rx_buffers(struct net_device *dev, 3758c2ecf20Sopenharmony_ci struct sxgbe_rx_norm_desc *p, int i, 3768c2ecf20Sopenharmony_ci unsigned int dma_buf_sz, 3778c2ecf20Sopenharmony_ci struct sxgbe_rx_queue *rx_ring) 3788c2ecf20Sopenharmony_ci{ 3798c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci kfree_skb(rx_ring->rx_skbuff[i]); 3828c2ecf20Sopenharmony_ci dma_unmap_single(priv->device, rx_ring->rx_skbuff_dma[i], 3838c2ecf20Sopenharmony_ci dma_buf_sz, DMA_FROM_DEVICE); 3848c2ecf20Sopenharmony_ci} 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci/** 3878c2ecf20Sopenharmony_ci * init_tx_ring - init the TX descriptor ring 3888c2ecf20Sopenharmony_ci * @dev: net device structure 3898c2ecf20Sopenharmony_ci * @queue_no: queue 3908c2ecf20Sopenharmony_ci * @tx_ring: ring to be initialised 3918c2ecf20Sopenharmony_ci * @tx_rsize: ring size 3928c2ecf20Sopenharmony_ci * Description: this function initializes the DMA TX descriptor 3938c2ecf20Sopenharmony_ci */ 3948c2ecf20Sopenharmony_cistatic int init_tx_ring(struct device *dev, u8 queue_no, 3958c2ecf20Sopenharmony_ci struct sxgbe_tx_queue *tx_ring, int tx_rsize) 3968c2ecf20Sopenharmony_ci{ 3978c2ecf20Sopenharmony_ci /* TX ring is not allcoated */ 3988c2ecf20Sopenharmony_ci if (!tx_ring) { 3998c2ecf20Sopenharmony_ci dev_err(dev, "No memory for TX queue of SXGBE\n"); 4008c2ecf20Sopenharmony_ci return -ENOMEM; 4018c2ecf20Sopenharmony_ci } 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci /* allocate memory for TX descriptors */ 4048c2ecf20Sopenharmony_ci tx_ring->dma_tx = dma_alloc_coherent(dev, 4058c2ecf20Sopenharmony_ci tx_rsize * sizeof(struct sxgbe_tx_norm_desc), 4068c2ecf20Sopenharmony_ci &tx_ring->dma_tx_phy, GFP_KERNEL); 4078c2ecf20Sopenharmony_ci if (!tx_ring->dma_tx) 4088c2ecf20Sopenharmony_ci return -ENOMEM; 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci /* allocate memory for TX skbuff array */ 4118c2ecf20Sopenharmony_ci tx_ring->tx_skbuff_dma = devm_kcalloc(dev, tx_rsize, 4128c2ecf20Sopenharmony_ci sizeof(dma_addr_t), GFP_KERNEL); 4138c2ecf20Sopenharmony_ci if (!tx_ring->tx_skbuff_dma) 4148c2ecf20Sopenharmony_ci goto dmamem_err; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci tx_ring->tx_skbuff = devm_kcalloc(dev, tx_rsize, 4178c2ecf20Sopenharmony_ci sizeof(struct sk_buff *), GFP_KERNEL); 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci if (!tx_ring->tx_skbuff) 4208c2ecf20Sopenharmony_ci goto dmamem_err; 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci /* assign queue number */ 4238c2ecf20Sopenharmony_ci tx_ring->queue_no = queue_no; 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci /* initialise counters */ 4268c2ecf20Sopenharmony_ci tx_ring->dirty_tx = 0; 4278c2ecf20Sopenharmony_ci tx_ring->cur_tx = 0; 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci return 0; 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_cidmamem_err: 4328c2ecf20Sopenharmony_ci dma_free_coherent(dev, tx_rsize * sizeof(struct sxgbe_tx_norm_desc), 4338c2ecf20Sopenharmony_ci tx_ring->dma_tx, tx_ring->dma_tx_phy); 4348c2ecf20Sopenharmony_ci return -ENOMEM; 4358c2ecf20Sopenharmony_ci} 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci/** 4388c2ecf20Sopenharmony_ci * free_rx_ring - free the RX descriptor ring 4398c2ecf20Sopenharmony_ci * @dev: net device structure 4408c2ecf20Sopenharmony_ci * @rx_ring: ring to be initialised 4418c2ecf20Sopenharmony_ci * @rx_rsize: ring size 4428c2ecf20Sopenharmony_ci * Description: this function initializes the DMA RX descriptor 4438c2ecf20Sopenharmony_ci */ 4448c2ecf20Sopenharmony_cistatic void free_rx_ring(struct device *dev, struct sxgbe_rx_queue *rx_ring, 4458c2ecf20Sopenharmony_ci int rx_rsize) 4468c2ecf20Sopenharmony_ci{ 4478c2ecf20Sopenharmony_ci dma_free_coherent(dev, rx_rsize * sizeof(struct sxgbe_rx_norm_desc), 4488c2ecf20Sopenharmony_ci rx_ring->dma_rx, rx_ring->dma_rx_phy); 4498c2ecf20Sopenharmony_ci kfree(rx_ring->rx_skbuff_dma); 4508c2ecf20Sopenharmony_ci kfree(rx_ring->rx_skbuff); 4518c2ecf20Sopenharmony_ci} 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci/** 4548c2ecf20Sopenharmony_ci * init_rx_ring - init the RX descriptor ring 4558c2ecf20Sopenharmony_ci * @dev: net device structure 4568c2ecf20Sopenharmony_ci * @queue_no: queue 4578c2ecf20Sopenharmony_ci * @rx_ring: ring to be initialised 4588c2ecf20Sopenharmony_ci * @rx_rsize: ring size 4598c2ecf20Sopenharmony_ci * Description: this function initializes the DMA RX descriptor 4608c2ecf20Sopenharmony_ci */ 4618c2ecf20Sopenharmony_cistatic int init_rx_ring(struct net_device *dev, u8 queue_no, 4628c2ecf20Sopenharmony_ci struct sxgbe_rx_queue *rx_ring, int rx_rsize) 4638c2ecf20Sopenharmony_ci{ 4648c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 4658c2ecf20Sopenharmony_ci int desc_index; 4668c2ecf20Sopenharmony_ci unsigned int bfsize = 0; 4678c2ecf20Sopenharmony_ci unsigned int ret = 0; 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci /* Set the max buffer size according to the MTU. */ 4708c2ecf20Sopenharmony_ci bfsize = ALIGN(dev->mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN, 8); 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci netif_dbg(priv, probe, dev, "%s: bfsize %d\n", __func__, bfsize); 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci /* RX ring is not allcoated */ 4758c2ecf20Sopenharmony_ci if (rx_ring == NULL) { 4768c2ecf20Sopenharmony_ci netdev_err(dev, "No memory for RX queue\n"); 4778c2ecf20Sopenharmony_ci return -ENOMEM; 4788c2ecf20Sopenharmony_ci } 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci /* assign queue number */ 4818c2ecf20Sopenharmony_ci rx_ring->queue_no = queue_no; 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci /* allocate memory for RX descriptors */ 4848c2ecf20Sopenharmony_ci rx_ring->dma_rx = dma_alloc_coherent(priv->device, 4858c2ecf20Sopenharmony_ci rx_rsize * sizeof(struct sxgbe_rx_norm_desc), 4868c2ecf20Sopenharmony_ci &rx_ring->dma_rx_phy, GFP_KERNEL); 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci if (rx_ring->dma_rx == NULL) 4898c2ecf20Sopenharmony_ci return -ENOMEM; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci /* allocate memory for RX skbuff array */ 4928c2ecf20Sopenharmony_ci rx_ring->rx_skbuff_dma = kmalloc_array(rx_rsize, 4938c2ecf20Sopenharmony_ci sizeof(dma_addr_t), GFP_KERNEL); 4948c2ecf20Sopenharmony_ci if (!rx_ring->rx_skbuff_dma) { 4958c2ecf20Sopenharmony_ci ret = -ENOMEM; 4968c2ecf20Sopenharmony_ci goto err_free_dma_rx; 4978c2ecf20Sopenharmony_ci } 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci rx_ring->rx_skbuff = kmalloc_array(rx_rsize, 5008c2ecf20Sopenharmony_ci sizeof(struct sk_buff *), GFP_KERNEL); 5018c2ecf20Sopenharmony_ci if (!rx_ring->rx_skbuff) { 5028c2ecf20Sopenharmony_ci ret = -ENOMEM; 5038c2ecf20Sopenharmony_ci goto err_free_skbuff_dma; 5048c2ecf20Sopenharmony_ci } 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci /* initialise the buffers */ 5078c2ecf20Sopenharmony_ci for (desc_index = 0; desc_index < rx_rsize; desc_index++) { 5088c2ecf20Sopenharmony_ci struct sxgbe_rx_norm_desc *p; 5098c2ecf20Sopenharmony_ci p = rx_ring->dma_rx + desc_index; 5108c2ecf20Sopenharmony_ci ret = sxgbe_init_rx_buffers(dev, p, desc_index, 5118c2ecf20Sopenharmony_ci bfsize, rx_ring); 5128c2ecf20Sopenharmony_ci if (ret) 5138c2ecf20Sopenharmony_ci goto err_free_rx_buffers; 5148c2ecf20Sopenharmony_ci } 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci /* initialise counters */ 5178c2ecf20Sopenharmony_ci rx_ring->cur_rx = 0; 5188c2ecf20Sopenharmony_ci rx_ring->dirty_rx = (unsigned int)(desc_index - rx_rsize); 5198c2ecf20Sopenharmony_ci priv->dma_buf_sz = bfsize; 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci return 0; 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_cierr_free_rx_buffers: 5248c2ecf20Sopenharmony_ci while (--desc_index >= 0) { 5258c2ecf20Sopenharmony_ci struct sxgbe_rx_norm_desc *p; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci p = rx_ring->dma_rx + desc_index; 5288c2ecf20Sopenharmony_ci sxgbe_free_rx_buffers(dev, p, desc_index, bfsize, rx_ring); 5298c2ecf20Sopenharmony_ci } 5308c2ecf20Sopenharmony_ci kfree(rx_ring->rx_skbuff); 5318c2ecf20Sopenharmony_cierr_free_skbuff_dma: 5328c2ecf20Sopenharmony_ci kfree(rx_ring->rx_skbuff_dma); 5338c2ecf20Sopenharmony_cierr_free_dma_rx: 5348c2ecf20Sopenharmony_ci dma_free_coherent(priv->device, 5358c2ecf20Sopenharmony_ci rx_rsize * sizeof(struct sxgbe_rx_norm_desc), 5368c2ecf20Sopenharmony_ci rx_ring->dma_rx, rx_ring->dma_rx_phy); 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci return ret; 5398c2ecf20Sopenharmony_ci} 5408c2ecf20Sopenharmony_ci/** 5418c2ecf20Sopenharmony_ci * free_tx_ring - free the TX descriptor ring 5428c2ecf20Sopenharmony_ci * @dev: net device structure 5438c2ecf20Sopenharmony_ci * @tx_ring: ring to be initialised 5448c2ecf20Sopenharmony_ci * @tx_rsize: ring size 5458c2ecf20Sopenharmony_ci * Description: this function initializes the DMA TX descriptor 5468c2ecf20Sopenharmony_ci */ 5478c2ecf20Sopenharmony_cistatic void free_tx_ring(struct device *dev, struct sxgbe_tx_queue *tx_ring, 5488c2ecf20Sopenharmony_ci int tx_rsize) 5498c2ecf20Sopenharmony_ci{ 5508c2ecf20Sopenharmony_ci dma_free_coherent(dev, tx_rsize * sizeof(struct sxgbe_tx_norm_desc), 5518c2ecf20Sopenharmony_ci tx_ring->dma_tx, tx_ring->dma_tx_phy); 5528c2ecf20Sopenharmony_ci} 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci/** 5558c2ecf20Sopenharmony_ci * init_dma_desc_rings - init the RX/TX descriptor rings 5568c2ecf20Sopenharmony_ci * @netd: net device structure 5578c2ecf20Sopenharmony_ci * Description: this function initializes the DMA RX/TX descriptors 5588c2ecf20Sopenharmony_ci * and allocates the socket buffers. It suppors the chained and ring 5598c2ecf20Sopenharmony_ci * modes. 5608c2ecf20Sopenharmony_ci */ 5618c2ecf20Sopenharmony_cistatic int init_dma_desc_rings(struct net_device *netd) 5628c2ecf20Sopenharmony_ci{ 5638c2ecf20Sopenharmony_ci int queue_num, ret; 5648c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(netd); 5658c2ecf20Sopenharmony_ci int tx_rsize = priv->dma_tx_size; 5668c2ecf20Sopenharmony_ci int rx_rsize = priv->dma_rx_size; 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ci /* Allocate memory for queue structures and TX descs */ 5698c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) { 5708c2ecf20Sopenharmony_ci ret = init_tx_ring(priv->device, queue_num, 5718c2ecf20Sopenharmony_ci priv->txq[queue_num], tx_rsize); 5728c2ecf20Sopenharmony_ci if (ret) { 5738c2ecf20Sopenharmony_ci dev_err(&netd->dev, "TX DMA ring allocation failed!\n"); 5748c2ecf20Sopenharmony_ci goto txalloc_err; 5758c2ecf20Sopenharmony_ci } 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci /* save private pointer in each ring this 5788c2ecf20Sopenharmony_ci * pointer is needed during cleaing TX queue 5798c2ecf20Sopenharmony_ci */ 5808c2ecf20Sopenharmony_ci priv->txq[queue_num]->priv_ptr = priv; 5818c2ecf20Sopenharmony_ci } 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci /* Allocate memory for queue structures and RX descs */ 5848c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num) { 5858c2ecf20Sopenharmony_ci ret = init_rx_ring(netd, queue_num, 5868c2ecf20Sopenharmony_ci priv->rxq[queue_num], rx_rsize); 5878c2ecf20Sopenharmony_ci if (ret) { 5888c2ecf20Sopenharmony_ci netdev_err(netd, "RX DMA ring allocation failed!!\n"); 5898c2ecf20Sopenharmony_ci goto rxalloc_err; 5908c2ecf20Sopenharmony_ci } 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci /* save private pointer in each ring this 5938c2ecf20Sopenharmony_ci * pointer is needed during cleaing TX queue 5948c2ecf20Sopenharmony_ci */ 5958c2ecf20Sopenharmony_ci priv->rxq[queue_num]->priv_ptr = priv; 5968c2ecf20Sopenharmony_ci } 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci sxgbe_clear_descriptors(priv); 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci return 0; 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_citxalloc_err: 6038c2ecf20Sopenharmony_ci while (queue_num--) 6048c2ecf20Sopenharmony_ci free_tx_ring(priv->device, priv->txq[queue_num], tx_rsize); 6058c2ecf20Sopenharmony_ci return ret; 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_cirxalloc_err: 6088c2ecf20Sopenharmony_ci while (queue_num--) 6098c2ecf20Sopenharmony_ci free_rx_ring(priv->device, priv->rxq[queue_num], rx_rsize); 6108c2ecf20Sopenharmony_ci return ret; 6118c2ecf20Sopenharmony_ci} 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_cistatic void tx_free_ring_skbufs(struct sxgbe_tx_queue *txqueue) 6148c2ecf20Sopenharmony_ci{ 6158c2ecf20Sopenharmony_ci int dma_desc; 6168c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = txqueue->priv_ptr; 6178c2ecf20Sopenharmony_ci int tx_rsize = priv->dma_tx_size; 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci for (dma_desc = 0; dma_desc < tx_rsize; dma_desc++) { 6208c2ecf20Sopenharmony_ci struct sxgbe_tx_norm_desc *tdesc = txqueue->dma_tx + dma_desc; 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci if (txqueue->tx_skbuff_dma[dma_desc]) 6238c2ecf20Sopenharmony_ci dma_unmap_single(priv->device, 6248c2ecf20Sopenharmony_ci txqueue->tx_skbuff_dma[dma_desc], 6258c2ecf20Sopenharmony_ci priv->hw->desc->get_tx_len(tdesc), 6268c2ecf20Sopenharmony_ci DMA_TO_DEVICE); 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_ci dev_kfree_skb_any(txqueue->tx_skbuff[dma_desc]); 6298c2ecf20Sopenharmony_ci txqueue->tx_skbuff[dma_desc] = NULL; 6308c2ecf20Sopenharmony_ci txqueue->tx_skbuff_dma[dma_desc] = 0; 6318c2ecf20Sopenharmony_ci } 6328c2ecf20Sopenharmony_ci} 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_cistatic void dma_free_tx_skbufs(struct sxgbe_priv_data *priv) 6368c2ecf20Sopenharmony_ci{ 6378c2ecf20Sopenharmony_ci int queue_num; 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) { 6408c2ecf20Sopenharmony_ci struct sxgbe_tx_queue *tqueue = priv->txq[queue_num]; 6418c2ecf20Sopenharmony_ci tx_free_ring_skbufs(tqueue); 6428c2ecf20Sopenharmony_ci } 6438c2ecf20Sopenharmony_ci} 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_cistatic void free_dma_desc_resources(struct sxgbe_priv_data *priv) 6468c2ecf20Sopenharmony_ci{ 6478c2ecf20Sopenharmony_ci int queue_num; 6488c2ecf20Sopenharmony_ci int tx_rsize = priv->dma_tx_size; 6498c2ecf20Sopenharmony_ci int rx_rsize = priv->dma_rx_size; 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci /* Release the DMA TX buffers */ 6528c2ecf20Sopenharmony_ci dma_free_tx_skbufs(priv); 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci /* Release the TX ring memory also */ 6558c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) { 6568c2ecf20Sopenharmony_ci free_tx_ring(priv->device, priv->txq[queue_num], tx_rsize); 6578c2ecf20Sopenharmony_ci } 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci /* Release the RX ring memory also */ 6608c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num) { 6618c2ecf20Sopenharmony_ci free_rx_ring(priv->device, priv->rxq[queue_num], rx_rsize); 6628c2ecf20Sopenharmony_ci } 6638c2ecf20Sopenharmony_ci} 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_cistatic int txring_mem_alloc(struct sxgbe_priv_data *priv) 6668c2ecf20Sopenharmony_ci{ 6678c2ecf20Sopenharmony_ci int queue_num; 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) { 6708c2ecf20Sopenharmony_ci priv->txq[queue_num] = devm_kmalloc(priv->device, 6718c2ecf20Sopenharmony_ci sizeof(struct sxgbe_tx_queue), GFP_KERNEL); 6728c2ecf20Sopenharmony_ci if (!priv->txq[queue_num]) 6738c2ecf20Sopenharmony_ci return -ENOMEM; 6748c2ecf20Sopenharmony_ci } 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci return 0; 6778c2ecf20Sopenharmony_ci} 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_cistatic int rxring_mem_alloc(struct sxgbe_priv_data *priv) 6808c2ecf20Sopenharmony_ci{ 6818c2ecf20Sopenharmony_ci int queue_num; 6828c2ecf20Sopenharmony_ci 6838c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num) { 6848c2ecf20Sopenharmony_ci priv->rxq[queue_num] = devm_kmalloc(priv->device, 6858c2ecf20Sopenharmony_ci sizeof(struct sxgbe_rx_queue), GFP_KERNEL); 6868c2ecf20Sopenharmony_ci if (!priv->rxq[queue_num]) 6878c2ecf20Sopenharmony_ci return -ENOMEM; 6888c2ecf20Sopenharmony_ci } 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci return 0; 6918c2ecf20Sopenharmony_ci} 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci/** 6948c2ecf20Sopenharmony_ci * sxgbe_mtl_operation_mode - HW MTL operation mode 6958c2ecf20Sopenharmony_ci * @priv: driver private structure 6968c2ecf20Sopenharmony_ci * Description: it sets the MTL operation mode: tx/rx MTL thresholds 6978c2ecf20Sopenharmony_ci * or Store-And-Forward capability. 6988c2ecf20Sopenharmony_ci */ 6998c2ecf20Sopenharmony_cistatic void sxgbe_mtl_operation_mode(struct sxgbe_priv_data *priv) 7008c2ecf20Sopenharmony_ci{ 7018c2ecf20Sopenharmony_ci int queue_num; 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ci /* TX/RX threshold control */ 7048c2ecf20Sopenharmony_ci if (likely(priv->plat->force_sf_dma_mode)) { 7058c2ecf20Sopenharmony_ci /* set TC mode for TX QUEUES */ 7068c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(priv->hw_cap.tx_mtl_queues, queue_num) 7078c2ecf20Sopenharmony_ci priv->hw->mtl->set_tx_mtl_mode(priv->ioaddr, queue_num, 7088c2ecf20Sopenharmony_ci SXGBE_MTL_SFMODE); 7098c2ecf20Sopenharmony_ci priv->tx_tc = SXGBE_MTL_SFMODE; 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci /* set TC mode for RX QUEUES */ 7128c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(priv->hw_cap.rx_mtl_queues, queue_num) 7138c2ecf20Sopenharmony_ci priv->hw->mtl->set_rx_mtl_mode(priv->ioaddr, queue_num, 7148c2ecf20Sopenharmony_ci SXGBE_MTL_SFMODE); 7158c2ecf20Sopenharmony_ci priv->rx_tc = SXGBE_MTL_SFMODE; 7168c2ecf20Sopenharmony_ci } else if (unlikely(priv->plat->force_thresh_dma_mode)) { 7178c2ecf20Sopenharmony_ci /* set TC mode for TX QUEUES */ 7188c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(priv->hw_cap.tx_mtl_queues, queue_num) 7198c2ecf20Sopenharmony_ci priv->hw->mtl->set_tx_mtl_mode(priv->ioaddr, queue_num, 7208c2ecf20Sopenharmony_ci priv->tx_tc); 7218c2ecf20Sopenharmony_ci /* set TC mode for RX QUEUES */ 7228c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(priv->hw_cap.rx_mtl_queues, queue_num) 7238c2ecf20Sopenharmony_ci priv->hw->mtl->set_rx_mtl_mode(priv->ioaddr, queue_num, 7248c2ecf20Sopenharmony_ci priv->rx_tc); 7258c2ecf20Sopenharmony_ci } else { 7268c2ecf20Sopenharmony_ci pr_err("ERROR: %s: Invalid TX threshold mode\n", __func__); 7278c2ecf20Sopenharmony_ci } 7288c2ecf20Sopenharmony_ci} 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci/** 7318c2ecf20Sopenharmony_ci * sxgbe_tx_queue_clean: 7328c2ecf20Sopenharmony_ci * @tqueue: queue pointer 7338c2ecf20Sopenharmony_ci * Description: it reclaims resources after transmission completes. 7348c2ecf20Sopenharmony_ci */ 7358c2ecf20Sopenharmony_cistatic void sxgbe_tx_queue_clean(struct sxgbe_tx_queue *tqueue) 7368c2ecf20Sopenharmony_ci{ 7378c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = tqueue->priv_ptr; 7388c2ecf20Sopenharmony_ci unsigned int tx_rsize = priv->dma_tx_size; 7398c2ecf20Sopenharmony_ci struct netdev_queue *dev_txq; 7408c2ecf20Sopenharmony_ci u8 queue_no = tqueue->queue_no; 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci dev_txq = netdev_get_tx_queue(priv->dev, queue_no); 7438c2ecf20Sopenharmony_ci 7448c2ecf20Sopenharmony_ci __netif_tx_lock(dev_txq, smp_processor_id()); 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci priv->xstats.tx_clean++; 7478c2ecf20Sopenharmony_ci while (tqueue->dirty_tx != tqueue->cur_tx) { 7488c2ecf20Sopenharmony_ci unsigned int entry = tqueue->dirty_tx % tx_rsize; 7498c2ecf20Sopenharmony_ci struct sk_buff *skb = tqueue->tx_skbuff[entry]; 7508c2ecf20Sopenharmony_ci struct sxgbe_tx_norm_desc *p; 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci p = tqueue->dma_tx + entry; 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ci /* Check if the descriptor is owned by the DMA. */ 7558c2ecf20Sopenharmony_ci if (priv->hw->desc->get_tx_owner(p)) 7568c2ecf20Sopenharmony_ci break; 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_ci if (netif_msg_tx_done(priv)) 7598c2ecf20Sopenharmony_ci pr_debug("%s: curr %d, dirty %d\n", 7608c2ecf20Sopenharmony_ci __func__, tqueue->cur_tx, tqueue->dirty_tx); 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci if (likely(tqueue->tx_skbuff_dma[entry])) { 7638c2ecf20Sopenharmony_ci dma_unmap_single(priv->device, 7648c2ecf20Sopenharmony_ci tqueue->tx_skbuff_dma[entry], 7658c2ecf20Sopenharmony_ci priv->hw->desc->get_tx_len(p), 7668c2ecf20Sopenharmony_ci DMA_TO_DEVICE); 7678c2ecf20Sopenharmony_ci tqueue->tx_skbuff_dma[entry] = 0; 7688c2ecf20Sopenharmony_ci } 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci if (likely(skb)) { 7718c2ecf20Sopenharmony_ci dev_kfree_skb(skb); 7728c2ecf20Sopenharmony_ci tqueue->tx_skbuff[entry] = NULL; 7738c2ecf20Sopenharmony_ci } 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci priv->hw->desc->release_tx_desc(p); 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci tqueue->dirty_tx++; 7788c2ecf20Sopenharmony_ci } 7798c2ecf20Sopenharmony_ci 7808c2ecf20Sopenharmony_ci /* wake up queue */ 7818c2ecf20Sopenharmony_ci if (unlikely(netif_tx_queue_stopped(dev_txq) && 7828c2ecf20Sopenharmony_ci sxgbe_tx_avail(tqueue, tx_rsize) > SXGBE_TX_THRESH(priv))) { 7838c2ecf20Sopenharmony_ci if (netif_msg_tx_done(priv)) 7848c2ecf20Sopenharmony_ci pr_debug("%s: restart transmit\n", __func__); 7858c2ecf20Sopenharmony_ci netif_tx_wake_queue(dev_txq); 7868c2ecf20Sopenharmony_ci } 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ci __netif_tx_unlock(dev_txq); 7898c2ecf20Sopenharmony_ci} 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_ci/** 7928c2ecf20Sopenharmony_ci * sxgbe_tx_clean: 7938c2ecf20Sopenharmony_ci * @priv: driver private structure 7948c2ecf20Sopenharmony_ci * Description: it reclaims resources after transmission completes. 7958c2ecf20Sopenharmony_ci */ 7968c2ecf20Sopenharmony_cistatic void sxgbe_tx_all_clean(struct sxgbe_priv_data * const priv) 7978c2ecf20Sopenharmony_ci{ 7988c2ecf20Sopenharmony_ci u8 queue_num; 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) { 8018c2ecf20Sopenharmony_ci struct sxgbe_tx_queue *tqueue = priv->txq[queue_num]; 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_ci sxgbe_tx_queue_clean(tqueue); 8048c2ecf20Sopenharmony_ci } 8058c2ecf20Sopenharmony_ci 8068c2ecf20Sopenharmony_ci if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) { 8078c2ecf20Sopenharmony_ci sxgbe_enable_eee_mode(priv); 8088c2ecf20Sopenharmony_ci mod_timer(&priv->eee_ctrl_timer, SXGBE_LPI_TIMER(eee_timer)); 8098c2ecf20Sopenharmony_ci } 8108c2ecf20Sopenharmony_ci} 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_ci/** 8138c2ecf20Sopenharmony_ci * sxgbe_restart_tx_queue: irq tx error mng function 8148c2ecf20Sopenharmony_ci * @priv: driver private structure 8158c2ecf20Sopenharmony_ci * @queue_num: queue number 8168c2ecf20Sopenharmony_ci * Description: it cleans the descriptors and restarts the transmission 8178c2ecf20Sopenharmony_ci * in case of errors. 8188c2ecf20Sopenharmony_ci */ 8198c2ecf20Sopenharmony_cistatic void sxgbe_restart_tx_queue(struct sxgbe_priv_data *priv, int queue_num) 8208c2ecf20Sopenharmony_ci{ 8218c2ecf20Sopenharmony_ci struct sxgbe_tx_queue *tx_ring = priv->txq[queue_num]; 8228c2ecf20Sopenharmony_ci struct netdev_queue *dev_txq = netdev_get_tx_queue(priv->dev, 8238c2ecf20Sopenharmony_ci queue_num); 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci /* stop the queue */ 8268c2ecf20Sopenharmony_ci netif_tx_stop_queue(dev_txq); 8278c2ecf20Sopenharmony_ci 8288c2ecf20Sopenharmony_ci /* stop the tx dma */ 8298c2ecf20Sopenharmony_ci priv->hw->dma->stop_tx_queue(priv->ioaddr, queue_num); 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_ci /* free the skbuffs of the ring */ 8328c2ecf20Sopenharmony_ci tx_free_ring_skbufs(tx_ring); 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_ci /* initialise counters */ 8358c2ecf20Sopenharmony_ci tx_ring->cur_tx = 0; 8368c2ecf20Sopenharmony_ci tx_ring->dirty_tx = 0; 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci /* start the tx dma */ 8398c2ecf20Sopenharmony_ci priv->hw->dma->start_tx_queue(priv->ioaddr, queue_num); 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci priv->dev->stats.tx_errors++; 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ci /* wakeup the queue */ 8448c2ecf20Sopenharmony_ci netif_tx_wake_queue(dev_txq); 8458c2ecf20Sopenharmony_ci} 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ci/** 8488c2ecf20Sopenharmony_ci * sxgbe_reset_all_tx_queues: irq tx error mng function 8498c2ecf20Sopenharmony_ci * @priv: driver private structure 8508c2ecf20Sopenharmony_ci * Description: it cleans all the descriptors and 8518c2ecf20Sopenharmony_ci * restarts the transmission on all queues in case of errors. 8528c2ecf20Sopenharmony_ci */ 8538c2ecf20Sopenharmony_cistatic void sxgbe_reset_all_tx_queues(struct sxgbe_priv_data *priv) 8548c2ecf20Sopenharmony_ci{ 8558c2ecf20Sopenharmony_ci int queue_num; 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci /* On TX timeout of net device, resetting of all queues 8588c2ecf20Sopenharmony_ci * may not be proper way, revisit this later if needed 8598c2ecf20Sopenharmony_ci */ 8608c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) 8618c2ecf20Sopenharmony_ci sxgbe_restart_tx_queue(priv, queue_num); 8628c2ecf20Sopenharmony_ci} 8638c2ecf20Sopenharmony_ci 8648c2ecf20Sopenharmony_ci/** 8658c2ecf20Sopenharmony_ci * sxgbe_get_hw_features: get XMAC capabilities from the HW cap. register. 8668c2ecf20Sopenharmony_ci * @priv: driver private structure 8678c2ecf20Sopenharmony_ci * Description: 8688c2ecf20Sopenharmony_ci * new GMAC chip generations have a new register to indicate the 8698c2ecf20Sopenharmony_ci * presence of the optional feature/functions. 8708c2ecf20Sopenharmony_ci * This can be also used to override the value passed through the 8718c2ecf20Sopenharmony_ci * platform and necessary for old MAC10/100 and GMAC chips. 8728c2ecf20Sopenharmony_ci */ 8738c2ecf20Sopenharmony_cistatic int sxgbe_get_hw_features(struct sxgbe_priv_data * const priv) 8748c2ecf20Sopenharmony_ci{ 8758c2ecf20Sopenharmony_ci int rval = 0; 8768c2ecf20Sopenharmony_ci struct sxgbe_hw_features *features = &priv->hw_cap; 8778c2ecf20Sopenharmony_ci 8788c2ecf20Sopenharmony_ci /* Read First Capability Register CAP[0] */ 8798c2ecf20Sopenharmony_ci rval = priv->hw->mac->get_hw_feature(priv->ioaddr, 0); 8808c2ecf20Sopenharmony_ci if (rval) { 8818c2ecf20Sopenharmony_ci features->pmt_remote_wake_up = 8828c2ecf20Sopenharmony_ci SXGBE_HW_FEAT_PMT_TEMOTE_WOP(rval); 8838c2ecf20Sopenharmony_ci features->pmt_magic_frame = SXGBE_HW_FEAT_PMT_MAGIC_PKT(rval); 8848c2ecf20Sopenharmony_ci features->atime_stamp = SXGBE_HW_FEAT_IEEE1500_2008(rval); 8858c2ecf20Sopenharmony_ci features->tx_csum_offload = 8868c2ecf20Sopenharmony_ci SXGBE_HW_FEAT_TX_CSUM_OFFLOAD(rval); 8878c2ecf20Sopenharmony_ci features->rx_csum_offload = 8888c2ecf20Sopenharmony_ci SXGBE_HW_FEAT_RX_CSUM_OFFLOAD(rval); 8898c2ecf20Sopenharmony_ci features->multi_macaddr = SXGBE_HW_FEAT_MACADDR_COUNT(rval); 8908c2ecf20Sopenharmony_ci features->tstamp_srcselect = SXGBE_HW_FEAT_TSTMAP_SRC(rval); 8918c2ecf20Sopenharmony_ci features->sa_vlan_insert = SXGBE_HW_FEAT_SRCADDR_VLAN(rval); 8928c2ecf20Sopenharmony_ci features->eee = SXGBE_HW_FEAT_EEE(rval); 8938c2ecf20Sopenharmony_ci } 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci /* Read First Capability Register CAP[1] */ 8968c2ecf20Sopenharmony_ci rval = priv->hw->mac->get_hw_feature(priv->ioaddr, 1); 8978c2ecf20Sopenharmony_ci if (rval) { 8988c2ecf20Sopenharmony_ci features->rxfifo_size = SXGBE_HW_FEAT_RX_FIFO_SIZE(rval); 8998c2ecf20Sopenharmony_ci features->txfifo_size = SXGBE_HW_FEAT_TX_FIFO_SIZE(rval); 9008c2ecf20Sopenharmony_ci features->atstmap_hword = SXGBE_HW_FEAT_TX_FIFO_SIZE(rval); 9018c2ecf20Sopenharmony_ci features->dcb_enable = SXGBE_HW_FEAT_DCB(rval); 9028c2ecf20Sopenharmony_ci features->splithead_enable = SXGBE_HW_FEAT_SPLIT_HDR(rval); 9038c2ecf20Sopenharmony_ci features->tcpseg_offload = SXGBE_HW_FEAT_TSO(rval); 9048c2ecf20Sopenharmony_ci features->debug_mem = SXGBE_HW_FEAT_DEBUG_MEM_IFACE(rval); 9058c2ecf20Sopenharmony_ci features->rss_enable = SXGBE_HW_FEAT_RSS(rval); 9068c2ecf20Sopenharmony_ci features->hash_tsize = SXGBE_HW_FEAT_HASH_TABLE_SIZE(rval); 9078c2ecf20Sopenharmony_ci features->l3l4_filer_size = SXGBE_HW_FEAT_L3L4_FILTER_NUM(rval); 9088c2ecf20Sopenharmony_ci } 9098c2ecf20Sopenharmony_ci 9108c2ecf20Sopenharmony_ci /* Read First Capability Register CAP[2] */ 9118c2ecf20Sopenharmony_ci rval = priv->hw->mac->get_hw_feature(priv->ioaddr, 2); 9128c2ecf20Sopenharmony_ci if (rval) { 9138c2ecf20Sopenharmony_ci features->rx_mtl_queues = SXGBE_HW_FEAT_RX_MTL_QUEUES(rval); 9148c2ecf20Sopenharmony_ci features->tx_mtl_queues = SXGBE_HW_FEAT_TX_MTL_QUEUES(rval); 9158c2ecf20Sopenharmony_ci features->rx_dma_channels = SXGBE_HW_FEAT_RX_DMA_CHANNELS(rval); 9168c2ecf20Sopenharmony_ci features->tx_dma_channels = SXGBE_HW_FEAT_TX_DMA_CHANNELS(rval); 9178c2ecf20Sopenharmony_ci features->pps_output_count = SXGBE_HW_FEAT_PPS_OUTPUTS(rval); 9188c2ecf20Sopenharmony_ci features->aux_input_count = SXGBE_HW_FEAT_AUX_SNAPSHOTS(rval); 9198c2ecf20Sopenharmony_ci } 9208c2ecf20Sopenharmony_ci 9218c2ecf20Sopenharmony_ci return rval; 9228c2ecf20Sopenharmony_ci} 9238c2ecf20Sopenharmony_ci 9248c2ecf20Sopenharmony_ci/** 9258c2ecf20Sopenharmony_ci * sxgbe_check_ether_addr: check if the MAC addr is valid 9268c2ecf20Sopenharmony_ci * @priv: driver private structure 9278c2ecf20Sopenharmony_ci * Description: 9288c2ecf20Sopenharmony_ci * it is to verify if the MAC address is valid, in case of failures it 9298c2ecf20Sopenharmony_ci * generates a random MAC address 9308c2ecf20Sopenharmony_ci */ 9318c2ecf20Sopenharmony_cistatic void sxgbe_check_ether_addr(struct sxgbe_priv_data *priv) 9328c2ecf20Sopenharmony_ci{ 9338c2ecf20Sopenharmony_ci if (!is_valid_ether_addr(priv->dev->dev_addr)) { 9348c2ecf20Sopenharmony_ci priv->hw->mac->get_umac_addr((void __iomem *) 9358c2ecf20Sopenharmony_ci priv->ioaddr, 9368c2ecf20Sopenharmony_ci priv->dev->dev_addr, 0); 9378c2ecf20Sopenharmony_ci if (!is_valid_ether_addr(priv->dev->dev_addr)) 9388c2ecf20Sopenharmony_ci eth_hw_addr_random(priv->dev); 9398c2ecf20Sopenharmony_ci } 9408c2ecf20Sopenharmony_ci dev_info(priv->device, "device MAC address %pM\n", 9418c2ecf20Sopenharmony_ci priv->dev->dev_addr); 9428c2ecf20Sopenharmony_ci} 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci/** 9458c2ecf20Sopenharmony_ci * sxgbe_init_dma_engine: DMA init. 9468c2ecf20Sopenharmony_ci * @priv: driver private structure 9478c2ecf20Sopenharmony_ci * Description: 9488c2ecf20Sopenharmony_ci * It inits the DMA invoking the specific SXGBE callback. 9498c2ecf20Sopenharmony_ci * Some DMA parameters can be passed from the platform; 9508c2ecf20Sopenharmony_ci * in case of these are not passed a default is kept for the MAC or GMAC. 9518c2ecf20Sopenharmony_ci */ 9528c2ecf20Sopenharmony_cistatic int sxgbe_init_dma_engine(struct sxgbe_priv_data *priv) 9538c2ecf20Sopenharmony_ci{ 9548c2ecf20Sopenharmony_ci int pbl = DEFAULT_DMA_PBL, fixed_burst = 0, burst_map = 0; 9558c2ecf20Sopenharmony_ci int queue_num; 9568c2ecf20Sopenharmony_ci 9578c2ecf20Sopenharmony_ci if (priv->plat->dma_cfg) { 9588c2ecf20Sopenharmony_ci pbl = priv->plat->dma_cfg->pbl; 9598c2ecf20Sopenharmony_ci fixed_burst = priv->plat->dma_cfg->fixed_burst; 9608c2ecf20Sopenharmony_ci burst_map = priv->plat->dma_cfg->burst_map; 9618c2ecf20Sopenharmony_ci } 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) 9648c2ecf20Sopenharmony_ci priv->hw->dma->cha_init(priv->ioaddr, queue_num, 9658c2ecf20Sopenharmony_ci fixed_burst, pbl, 9668c2ecf20Sopenharmony_ci (priv->txq[queue_num])->dma_tx_phy, 9678c2ecf20Sopenharmony_ci (priv->rxq[queue_num])->dma_rx_phy, 9688c2ecf20Sopenharmony_ci priv->dma_tx_size, priv->dma_rx_size); 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_ci return priv->hw->dma->init(priv->ioaddr, fixed_burst, burst_map); 9718c2ecf20Sopenharmony_ci} 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ci/** 9748c2ecf20Sopenharmony_ci * sxgbe_init_mtl_engine: MTL init. 9758c2ecf20Sopenharmony_ci * @priv: driver private structure 9768c2ecf20Sopenharmony_ci * Description: 9778c2ecf20Sopenharmony_ci * It inits the MTL invoking the specific SXGBE callback. 9788c2ecf20Sopenharmony_ci */ 9798c2ecf20Sopenharmony_cistatic void sxgbe_init_mtl_engine(struct sxgbe_priv_data *priv) 9808c2ecf20Sopenharmony_ci{ 9818c2ecf20Sopenharmony_ci int queue_num; 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) { 9848c2ecf20Sopenharmony_ci priv->hw->mtl->mtl_set_txfifosize(priv->ioaddr, queue_num, 9858c2ecf20Sopenharmony_ci priv->hw_cap.tx_mtl_qsize); 9868c2ecf20Sopenharmony_ci priv->hw->mtl->mtl_enable_txqueue(priv->ioaddr, queue_num); 9878c2ecf20Sopenharmony_ci } 9888c2ecf20Sopenharmony_ci} 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci/** 9918c2ecf20Sopenharmony_ci * sxgbe_disable_mtl_engine: MTL disable. 9928c2ecf20Sopenharmony_ci * @priv: driver private structure 9938c2ecf20Sopenharmony_ci * Description: 9948c2ecf20Sopenharmony_ci * It disables the MTL queues by invoking the specific SXGBE callback. 9958c2ecf20Sopenharmony_ci */ 9968c2ecf20Sopenharmony_cistatic void sxgbe_disable_mtl_engine(struct sxgbe_priv_data *priv) 9978c2ecf20Sopenharmony_ci{ 9988c2ecf20Sopenharmony_ci int queue_num; 9998c2ecf20Sopenharmony_ci 10008c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) 10018c2ecf20Sopenharmony_ci priv->hw->mtl->mtl_disable_txqueue(priv->ioaddr, queue_num); 10028c2ecf20Sopenharmony_ci} 10038c2ecf20Sopenharmony_ci 10048c2ecf20Sopenharmony_ci 10058c2ecf20Sopenharmony_ci/** 10068c2ecf20Sopenharmony_ci * sxgbe_tx_timer: mitigation sw timer for tx. 10078c2ecf20Sopenharmony_ci * @t: timer pointer 10088c2ecf20Sopenharmony_ci * Description: 10098c2ecf20Sopenharmony_ci * This is the timer handler to directly invoke the sxgbe_tx_clean. 10108c2ecf20Sopenharmony_ci */ 10118c2ecf20Sopenharmony_cistatic void sxgbe_tx_timer(struct timer_list *t) 10128c2ecf20Sopenharmony_ci{ 10138c2ecf20Sopenharmony_ci struct sxgbe_tx_queue *p = from_timer(p, t, txtimer); 10148c2ecf20Sopenharmony_ci sxgbe_tx_queue_clean(p); 10158c2ecf20Sopenharmony_ci} 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ci/** 10188c2ecf20Sopenharmony_ci * sxgbe_init_tx_coalesce: init tx mitigation options. 10198c2ecf20Sopenharmony_ci * @priv: driver private structure 10208c2ecf20Sopenharmony_ci * Description: 10218c2ecf20Sopenharmony_ci * This inits the transmit coalesce parameters: i.e. timer rate, 10228c2ecf20Sopenharmony_ci * timer handler and default threshold used for enabling the 10238c2ecf20Sopenharmony_ci * interrupt on completion bit. 10248c2ecf20Sopenharmony_ci */ 10258c2ecf20Sopenharmony_cistatic void sxgbe_tx_init_coalesce(struct sxgbe_priv_data *priv) 10268c2ecf20Sopenharmony_ci{ 10278c2ecf20Sopenharmony_ci u8 queue_num; 10288c2ecf20Sopenharmony_ci 10298c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) { 10308c2ecf20Sopenharmony_ci struct sxgbe_tx_queue *p = priv->txq[queue_num]; 10318c2ecf20Sopenharmony_ci p->tx_coal_frames = SXGBE_TX_FRAMES; 10328c2ecf20Sopenharmony_ci p->tx_coal_timer = SXGBE_COAL_TX_TIMER; 10338c2ecf20Sopenharmony_ci timer_setup(&p->txtimer, sxgbe_tx_timer, 0); 10348c2ecf20Sopenharmony_ci p->txtimer.expires = SXGBE_COAL_TIMER(p->tx_coal_timer); 10358c2ecf20Sopenharmony_ci add_timer(&p->txtimer); 10368c2ecf20Sopenharmony_ci } 10378c2ecf20Sopenharmony_ci} 10388c2ecf20Sopenharmony_ci 10398c2ecf20Sopenharmony_cistatic void sxgbe_tx_del_timer(struct sxgbe_priv_data *priv) 10408c2ecf20Sopenharmony_ci{ 10418c2ecf20Sopenharmony_ci u8 queue_num; 10428c2ecf20Sopenharmony_ci 10438c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) { 10448c2ecf20Sopenharmony_ci struct sxgbe_tx_queue *p = priv->txq[queue_num]; 10458c2ecf20Sopenharmony_ci del_timer_sync(&p->txtimer); 10468c2ecf20Sopenharmony_ci } 10478c2ecf20Sopenharmony_ci} 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci/** 10508c2ecf20Sopenharmony_ci * sxgbe_open - open entry point of the driver 10518c2ecf20Sopenharmony_ci * @dev : pointer to the device structure. 10528c2ecf20Sopenharmony_ci * Description: 10538c2ecf20Sopenharmony_ci * This function is the open entry point of the driver. 10548c2ecf20Sopenharmony_ci * Return value: 10558c2ecf20Sopenharmony_ci * 0 on success and an appropriate (-)ve integer as defined in errno.h 10568c2ecf20Sopenharmony_ci * file on failure. 10578c2ecf20Sopenharmony_ci */ 10588c2ecf20Sopenharmony_cistatic int sxgbe_open(struct net_device *dev) 10598c2ecf20Sopenharmony_ci{ 10608c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 10618c2ecf20Sopenharmony_ci int ret, queue_num; 10628c2ecf20Sopenharmony_ci 10638c2ecf20Sopenharmony_ci clk_prepare_enable(priv->sxgbe_clk); 10648c2ecf20Sopenharmony_ci 10658c2ecf20Sopenharmony_ci sxgbe_check_ether_addr(priv); 10668c2ecf20Sopenharmony_ci 10678c2ecf20Sopenharmony_ci /* Init the phy */ 10688c2ecf20Sopenharmony_ci ret = sxgbe_init_phy(dev); 10698c2ecf20Sopenharmony_ci if (ret) { 10708c2ecf20Sopenharmony_ci netdev_err(dev, "%s: Cannot attach to PHY (error: %d)\n", 10718c2ecf20Sopenharmony_ci __func__, ret); 10728c2ecf20Sopenharmony_ci goto phy_error; 10738c2ecf20Sopenharmony_ci } 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_ci /* Create and initialize the TX/RX descriptors chains. */ 10768c2ecf20Sopenharmony_ci priv->dma_tx_size = SXGBE_ALIGN(DMA_TX_SIZE); 10778c2ecf20Sopenharmony_ci priv->dma_rx_size = SXGBE_ALIGN(DMA_RX_SIZE); 10788c2ecf20Sopenharmony_ci priv->dma_buf_sz = SXGBE_ALIGN(DMA_BUFFER_SIZE); 10798c2ecf20Sopenharmony_ci priv->tx_tc = TC_DEFAULT; 10808c2ecf20Sopenharmony_ci priv->rx_tc = TC_DEFAULT; 10818c2ecf20Sopenharmony_ci init_dma_desc_rings(dev); 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_ci /* DMA initialization and SW reset */ 10848c2ecf20Sopenharmony_ci ret = sxgbe_init_dma_engine(priv); 10858c2ecf20Sopenharmony_ci if (ret < 0) { 10868c2ecf20Sopenharmony_ci netdev_err(dev, "%s: DMA initialization failed\n", __func__); 10878c2ecf20Sopenharmony_ci goto init_error; 10888c2ecf20Sopenharmony_ci } 10898c2ecf20Sopenharmony_ci 10908c2ecf20Sopenharmony_ci /* MTL initialization */ 10918c2ecf20Sopenharmony_ci sxgbe_init_mtl_engine(priv); 10928c2ecf20Sopenharmony_ci 10938c2ecf20Sopenharmony_ci /* Copy the MAC addr into the HW */ 10948c2ecf20Sopenharmony_ci priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0); 10958c2ecf20Sopenharmony_ci 10968c2ecf20Sopenharmony_ci /* Initialize the MAC Core */ 10978c2ecf20Sopenharmony_ci priv->hw->mac->core_init(priv->ioaddr); 10988c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num) { 10998c2ecf20Sopenharmony_ci priv->hw->mac->enable_rxqueue(priv->ioaddr, queue_num); 11008c2ecf20Sopenharmony_ci } 11018c2ecf20Sopenharmony_ci 11028c2ecf20Sopenharmony_ci /* Request the IRQ lines */ 11038c2ecf20Sopenharmony_ci ret = devm_request_irq(priv->device, priv->irq, sxgbe_common_interrupt, 11048c2ecf20Sopenharmony_ci IRQF_SHARED, dev->name, dev); 11058c2ecf20Sopenharmony_ci if (unlikely(ret < 0)) { 11068c2ecf20Sopenharmony_ci netdev_err(dev, "%s: ERROR: allocating the IRQ %d (error: %d)\n", 11078c2ecf20Sopenharmony_ci __func__, priv->irq, ret); 11088c2ecf20Sopenharmony_ci goto init_error; 11098c2ecf20Sopenharmony_ci } 11108c2ecf20Sopenharmony_ci 11118c2ecf20Sopenharmony_ci /* If the LPI irq is different from the mac irq 11128c2ecf20Sopenharmony_ci * register a dedicated handler 11138c2ecf20Sopenharmony_ci */ 11148c2ecf20Sopenharmony_ci if (priv->lpi_irq != dev->irq) { 11158c2ecf20Sopenharmony_ci ret = devm_request_irq(priv->device, priv->lpi_irq, 11168c2ecf20Sopenharmony_ci sxgbe_common_interrupt, 11178c2ecf20Sopenharmony_ci IRQF_SHARED, dev->name, dev); 11188c2ecf20Sopenharmony_ci if (unlikely(ret < 0)) { 11198c2ecf20Sopenharmony_ci netdev_err(dev, "%s: ERROR: allocating the LPI IRQ %d (%d)\n", 11208c2ecf20Sopenharmony_ci __func__, priv->lpi_irq, ret); 11218c2ecf20Sopenharmony_ci goto init_error; 11228c2ecf20Sopenharmony_ci } 11238c2ecf20Sopenharmony_ci } 11248c2ecf20Sopenharmony_ci 11258c2ecf20Sopenharmony_ci /* Request TX DMA irq lines */ 11268c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) { 11278c2ecf20Sopenharmony_ci ret = devm_request_irq(priv->device, 11288c2ecf20Sopenharmony_ci (priv->txq[queue_num])->irq_no, 11298c2ecf20Sopenharmony_ci sxgbe_tx_interrupt, 0, 11308c2ecf20Sopenharmony_ci dev->name, priv->txq[queue_num]); 11318c2ecf20Sopenharmony_ci if (unlikely(ret < 0)) { 11328c2ecf20Sopenharmony_ci netdev_err(dev, "%s: ERROR: allocating TX IRQ %d (error: %d)\n", 11338c2ecf20Sopenharmony_ci __func__, priv->irq, ret); 11348c2ecf20Sopenharmony_ci goto init_error; 11358c2ecf20Sopenharmony_ci } 11368c2ecf20Sopenharmony_ci } 11378c2ecf20Sopenharmony_ci 11388c2ecf20Sopenharmony_ci /* Request RX DMA irq lines */ 11398c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num) { 11408c2ecf20Sopenharmony_ci ret = devm_request_irq(priv->device, 11418c2ecf20Sopenharmony_ci (priv->rxq[queue_num])->irq_no, 11428c2ecf20Sopenharmony_ci sxgbe_rx_interrupt, 0, 11438c2ecf20Sopenharmony_ci dev->name, priv->rxq[queue_num]); 11448c2ecf20Sopenharmony_ci if (unlikely(ret < 0)) { 11458c2ecf20Sopenharmony_ci netdev_err(dev, "%s: ERROR: allocating TX IRQ %d (error: %d)\n", 11468c2ecf20Sopenharmony_ci __func__, priv->irq, ret); 11478c2ecf20Sopenharmony_ci goto init_error; 11488c2ecf20Sopenharmony_ci } 11498c2ecf20Sopenharmony_ci } 11508c2ecf20Sopenharmony_ci 11518c2ecf20Sopenharmony_ci /* Enable the MAC Rx/Tx */ 11528c2ecf20Sopenharmony_ci priv->hw->mac->enable_tx(priv->ioaddr, true); 11538c2ecf20Sopenharmony_ci priv->hw->mac->enable_rx(priv->ioaddr, true); 11548c2ecf20Sopenharmony_ci 11558c2ecf20Sopenharmony_ci /* Set the HW DMA mode and the COE */ 11568c2ecf20Sopenharmony_ci sxgbe_mtl_operation_mode(priv); 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci /* Extra statistics */ 11598c2ecf20Sopenharmony_ci memset(&priv->xstats, 0, sizeof(struct sxgbe_extra_stats)); 11608c2ecf20Sopenharmony_ci 11618c2ecf20Sopenharmony_ci priv->xstats.tx_threshold = priv->tx_tc; 11628c2ecf20Sopenharmony_ci priv->xstats.rx_threshold = priv->rx_tc; 11638c2ecf20Sopenharmony_ci 11648c2ecf20Sopenharmony_ci /* Start the ball rolling... */ 11658c2ecf20Sopenharmony_ci netdev_dbg(dev, "DMA RX/TX processes started...\n"); 11668c2ecf20Sopenharmony_ci priv->hw->dma->start_tx(priv->ioaddr, SXGBE_TX_QUEUES); 11678c2ecf20Sopenharmony_ci priv->hw->dma->start_rx(priv->ioaddr, SXGBE_RX_QUEUES); 11688c2ecf20Sopenharmony_ci 11698c2ecf20Sopenharmony_ci if (dev->phydev) 11708c2ecf20Sopenharmony_ci phy_start(dev->phydev); 11718c2ecf20Sopenharmony_ci 11728c2ecf20Sopenharmony_ci /* initialise TX coalesce parameters */ 11738c2ecf20Sopenharmony_ci sxgbe_tx_init_coalesce(priv); 11748c2ecf20Sopenharmony_ci 11758c2ecf20Sopenharmony_ci if ((priv->use_riwt) && (priv->hw->dma->rx_watchdog)) { 11768c2ecf20Sopenharmony_ci priv->rx_riwt = SXGBE_MAX_DMA_RIWT; 11778c2ecf20Sopenharmony_ci priv->hw->dma->rx_watchdog(priv->ioaddr, SXGBE_MAX_DMA_RIWT); 11788c2ecf20Sopenharmony_ci } 11798c2ecf20Sopenharmony_ci 11808c2ecf20Sopenharmony_ci priv->tx_lpi_timer = SXGBE_DEFAULT_LPI_TIMER; 11818c2ecf20Sopenharmony_ci priv->eee_enabled = sxgbe_eee_init(priv); 11828c2ecf20Sopenharmony_ci 11838c2ecf20Sopenharmony_ci napi_enable(&priv->napi); 11848c2ecf20Sopenharmony_ci netif_start_queue(dev); 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_ci return 0; 11878c2ecf20Sopenharmony_ci 11888c2ecf20Sopenharmony_ciinit_error: 11898c2ecf20Sopenharmony_ci free_dma_desc_resources(priv); 11908c2ecf20Sopenharmony_ci if (dev->phydev) 11918c2ecf20Sopenharmony_ci phy_disconnect(dev->phydev); 11928c2ecf20Sopenharmony_ciphy_error: 11938c2ecf20Sopenharmony_ci clk_disable_unprepare(priv->sxgbe_clk); 11948c2ecf20Sopenharmony_ci 11958c2ecf20Sopenharmony_ci return ret; 11968c2ecf20Sopenharmony_ci} 11978c2ecf20Sopenharmony_ci 11988c2ecf20Sopenharmony_ci/** 11998c2ecf20Sopenharmony_ci * sxgbe_release - close entry point of the driver 12008c2ecf20Sopenharmony_ci * @dev : device pointer. 12018c2ecf20Sopenharmony_ci * Description: 12028c2ecf20Sopenharmony_ci * This is the stop entry point of the driver. 12038c2ecf20Sopenharmony_ci */ 12048c2ecf20Sopenharmony_cistatic int sxgbe_release(struct net_device *dev) 12058c2ecf20Sopenharmony_ci{ 12068c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 12078c2ecf20Sopenharmony_ci 12088c2ecf20Sopenharmony_ci if (priv->eee_enabled) 12098c2ecf20Sopenharmony_ci del_timer_sync(&priv->eee_ctrl_timer); 12108c2ecf20Sopenharmony_ci 12118c2ecf20Sopenharmony_ci /* Stop and disconnect the PHY */ 12128c2ecf20Sopenharmony_ci if (dev->phydev) { 12138c2ecf20Sopenharmony_ci phy_stop(dev->phydev); 12148c2ecf20Sopenharmony_ci phy_disconnect(dev->phydev); 12158c2ecf20Sopenharmony_ci } 12168c2ecf20Sopenharmony_ci 12178c2ecf20Sopenharmony_ci netif_tx_stop_all_queues(dev); 12188c2ecf20Sopenharmony_ci 12198c2ecf20Sopenharmony_ci napi_disable(&priv->napi); 12208c2ecf20Sopenharmony_ci 12218c2ecf20Sopenharmony_ci /* delete TX timers */ 12228c2ecf20Sopenharmony_ci sxgbe_tx_del_timer(priv); 12238c2ecf20Sopenharmony_ci 12248c2ecf20Sopenharmony_ci /* Stop TX/RX DMA and clear the descriptors */ 12258c2ecf20Sopenharmony_ci priv->hw->dma->stop_tx(priv->ioaddr, SXGBE_TX_QUEUES); 12268c2ecf20Sopenharmony_ci priv->hw->dma->stop_rx(priv->ioaddr, SXGBE_RX_QUEUES); 12278c2ecf20Sopenharmony_ci 12288c2ecf20Sopenharmony_ci /* disable MTL queue */ 12298c2ecf20Sopenharmony_ci sxgbe_disable_mtl_engine(priv); 12308c2ecf20Sopenharmony_ci 12318c2ecf20Sopenharmony_ci /* Release and free the Rx/Tx resources */ 12328c2ecf20Sopenharmony_ci free_dma_desc_resources(priv); 12338c2ecf20Sopenharmony_ci 12348c2ecf20Sopenharmony_ci /* Disable the MAC Rx/Tx */ 12358c2ecf20Sopenharmony_ci priv->hw->mac->enable_tx(priv->ioaddr, false); 12368c2ecf20Sopenharmony_ci priv->hw->mac->enable_rx(priv->ioaddr, false); 12378c2ecf20Sopenharmony_ci 12388c2ecf20Sopenharmony_ci clk_disable_unprepare(priv->sxgbe_clk); 12398c2ecf20Sopenharmony_ci 12408c2ecf20Sopenharmony_ci return 0; 12418c2ecf20Sopenharmony_ci} 12428c2ecf20Sopenharmony_ci/* Prepare first Tx descriptor for doing TSO operation */ 12438c2ecf20Sopenharmony_cistatic void sxgbe_tso_prepare(struct sxgbe_priv_data *priv, 12448c2ecf20Sopenharmony_ci struct sxgbe_tx_norm_desc *first_desc, 12458c2ecf20Sopenharmony_ci struct sk_buff *skb) 12468c2ecf20Sopenharmony_ci{ 12478c2ecf20Sopenharmony_ci unsigned int total_hdr_len, tcp_hdr_len; 12488c2ecf20Sopenharmony_ci 12498c2ecf20Sopenharmony_ci /* Write first Tx descriptor with appropriate value */ 12508c2ecf20Sopenharmony_ci tcp_hdr_len = tcp_hdrlen(skb); 12518c2ecf20Sopenharmony_ci total_hdr_len = skb_transport_offset(skb) + tcp_hdr_len; 12528c2ecf20Sopenharmony_ci 12538c2ecf20Sopenharmony_ci first_desc->tdes01 = dma_map_single(priv->device, skb->data, 12548c2ecf20Sopenharmony_ci total_hdr_len, DMA_TO_DEVICE); 12558c2ecf20Sopenharmony_ci if (dma_mapping_error(priv->device, first_desc->tdes01)) 12568c2ecf20Sopenharmony_ci pr_err("%s: TX dma mapping failed!!\n", __func__); 12578c2ecf20Sopenharmony_ci 12588c2ecf20Sopenharmony_ci first_desc->tdes23.tx_rd_des23.first_desc = 1; 12598c2ecf20Sopenharmony_ci priv->hw->desc->tx_desc_enable_tse(first_desc, 1, total_hdr_len, 12608c2ecf20Sopenharmony_ci tcp_hdr_len, 12618c2ecf20Sopenharmony_ci skb->len - total_hdr_len); 12628c2ecf20Sopenharmony_ci} 12638c2ecf20Sopenharmony_ci 12648c2ecf20Sopenharmony_ci/** 12658c2ecf20Sopenharmony_ci * sxgbe_xmit: Tx entry point of the driver 12668c2ecf20Sopenharmony_ci * @skb : the socket buffer 12678c2ecf20Sopenharmony_ci * @dev : device pointer 12688c2ecf20Sopenharmony_ci * Description : this is the tx entry point of the driver. 12698c2ecf20Sopenharmony_ci * It programs the chain or the ring and supports oversized frames 12708c2ecf20Sopenharmony_ci * and SG feature. 12718c2ecf20Sopenharmony_ci */ 12728c2ecf20Sopenharmony_cistatic netdev_tx_t sxgbe_xmit(struct sk_buff *skb, struct net_device *dev) 12738c2ecf20Sopenharmony_ci{ 12748c2ecf20Sopenharmony_ci unsigned int entry, frag_num; 12758c2ecf20Sopenharmony_ci int cksum_flag = 0; 12768c2ecf20Sopenharmony_ci struct netdev_queue *dev_txq; 12778c2ecf20Sopenharmony_ci unsigned txq_index = skb_get_queue_mapping(skb); 12788c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 12798c2ecf20Sopenharmony_ci unsigned int tx_rsize = priv->dma_tx_size; 12808c2ecf20Sopenharmony_ci struct sxgbe_tx_queue *tqueue = priv->txq[txq_index]; 12818c2ecf20Sopenharmony_ci struct sxgbe_tx_norm_desc *tx_desc, *first_desc; 12828c2ecf20Sopenharmony_ci struct sxgbe_tx_ctxt_desc *ctxt_desc = NULL; 12838c2ecf20Sopenharmony_ci int nr_frags = skb_shinfo(skb)->nr_frags; 12848c2ecf20Sopenharmony_ci int no_pagedlen = skb_headlen(skb); 12858c2ecf20Sopenharmony_ci int is_jumbo = 0; 12868c2ecf20Sopenharmony_ci u16 cur_mss = skb_shinfo(skb)->gso_size; 12878c2ecf20Sopenharmony_ci u32 ctxt_desc_req = 0; 12888c2ecf20Sopenharmony_ci 12898c2ecf20Sopenharmony_ci /* get the TX queue handle */ 12908c2ecf20Sopenharmony_ci dev_txq = netdev_get_tx_queue(dev, txq_index); 12918c2ecf20Sopenharmony_ci 12928c2ecf20Sopenharmony_ci if (unlikely(skb_is_gso(skb) && tqueue->prev_mss != cur_mss)) 12938c2ecf20Sopenharmony_ci ctxt_desc_req = 1; 12948c2ecf20Sopenharmony_ci 12958c2ecf20Sopenharmony_ci if (unlikely(skb_vlan_tag_present(skb) || 12968c2ecf20Sopenharmony_ci ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && 12978c2ecf20Sopenharmony_ci tqueue->hwts_tx_en))) 12988c2ecf20Sopenharmony_ci ctxt_desc_req = 1; 12998c2ecf20Sopenharmony_ci 13008c2ecf20Sopenharmony_ci if (priv->tx_path_in_lpi_mode) 13018c2ecf20Sopenharmony_ci sxgbe_disable_eee_mode(priv); 13028c2ecf20Sopenharmony_ci 13038c2ecf20Sopenharmony_ci if (unlikely(sxgbe_tx_avail(tqueue, tx_rsize) < nr_frags + 1)) { 13048c2ecf20Sopenharmony_ci if (!netif_tx_queue_stopped(dev_txq)) { 13058c2ecf20Sopenharmony_ci netif_tx_stop_queue(dev_txq); 13068c2ecf20Sopenharmony_ci netdev_err(dev, "%s: Tx Ring is full when %d queue is awake\n", 13078c2ecf20Sopenharmony_ci __func__, txq_index); 13088c2ecf20Sopenharmony_ci } 13098c2ecf20Sopenharmony_ci return NETDEV_TX_BUSY; 13108c2ecf20Sopenharmony_ci } 13118c2ecf20Sopenharmony_ci 13128c2ecf20Sopenharmony_ci entry = tqueue->cur_tx % tx_rsize; 13138c2ecf20Sopenharmony_ci tx_desc = tqueue->dma_tx + entry; 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_ci first_desc = tx_desc; 13168c2ecf20Sopenharmony_ci if (ctxt_desc_req) 13178c2ecf20Sopenharmony_ci ctxt_desc = (struct sxgbe_tx_ctxt_desc *)first_desc; 13188c2ecf20Sopenharmony_ci 13198c2ecf20Sopenharmony_ci /* save the skb address */ 13208c2ecf20Sopenharmony_ci tqueue->tx_skbuff[entry] = skb; 13218c2ecf20Sopenharmony_ci 13228c2ecf20Sopenharmony_ci if (!is_jumbo) { 13238c2ecf20Sopenharmony_ci if (likely(skb_is_gso(skb))) { 13248c2ecf20Sopenharmony_ci /* TSO support */ 13258c2ecf20Sopenharmony_ci if (unlikely(tqueue->prev_mss != cur_mss)) { 13268c2ecf20Sopenharmony_ci priv->hw->desc->tx_ctxt_desc_set_mss( 13278c2ecf20Sopenharmony_ci ctxt_desc, cur_mss); 13288c2ecf20Sopenharmony_ci priv->hw->desc->tx_ctxt_desc_set_tcmssv( 13298c2ecf20Sopenharmony_ci ctxt_desc); 13308c2ecf20Sopenharmony_ci priv->hw->desc->tx_ctxt_desc_reset_ostc( 13318c2ecf20Sopenharmony_ci ctxt_desc); 13328c2ecf20Sopenharmony_ci priv->hw->desc->tx_ctxt_desc_set_ctxt( 13338c2ecf20Sopenharmony_ci ctxt_desc); 13348c2ecf20Sopenharmony_ci priv->hw->desc->tx_ctxt_desc_set_owner( 13358c2ecf20Sopenharmony_ci ctxt_desc); 13368c2ecf20Sopenharmony_ci 13378c2ecf20Sopenharmony_ci entry = (++tqueue->cur_tx) % tx_rsize; 13388c2ecf20Sopenharmony_ci first_desc = tqueue->dma_tx + entry; 13398c2ecf20Sopenharmony_ci 13408c2ecf20Sopenharmony_ci tqueue->prev_mss = cur_mss; 13418c2ecf20Sopenharmony_ci } 13428c2ecf20Sopenharmony_ci sxgbe_tso_prepare(priv, first_desc, skb); 13438c2ecf20Sopenharmony_ci } else { 13448c2ecf20Sopenharmony_ci tx_desc->tdes01 = dma_map_single(priv->device, 13458c2ecf20Sopenharmony_ci skb->data, no_pagedlen, DMA_TO_DEVICE); 13468c2ecf20Sopenharmony_ci if (dma_mapping_error(priv->device, tx_desc->tdes01)) 13478c2ecf20Sopenharmony_ci netdev_err(dev, "%s: TX dma mapping failed!!\n", 13488c2ecf20Sopenharmony_ci __func__); 13498c2ecf20Sopenharmony_ci 13508c2ecf20Sopenharmony_ci priv->hw->desc->prepare_tx_desc(tx_desc, 1, no_pagedlen, 13518c2ecf20Sopenharmony_ci no_pagedlen, cksum_flag); 13528c2ecf20Sopenharmony_ci } 13538c2ecf20Sopenharmony_ci } 13548c2ecf20Sopenharmony_ci 13558c2ecf20Sopenharmony_ci for (frag_num = 0; frag_num < nr_frags; frag_num++) { 13568c2ecf20Sopenharmony_ci const skb_frag_t *frag = &skb_shinfo(skb)->frags[frag_num]; 13578c2ecf20Sopenharmony_ci int len = skb_frag_size(frag); 13588c2ecf20Sopenharmony_ci 13598c2ecf20Sopenharmony_ci entry = (++tqueue->cur_tx) % tx_rsize; 13608c2ecf20Sopenharmony_ci tx_desc = tqueue->dma_tx + entry; 13618c2ecf20Sopenharmony_ci tx_desc->tdes01 = skb_frag_dma_map(priv->device, frag, 0, len, 13628c2ecf20Sopenharmony_ci DMA_TO_DEVICE); 13638c2ecf20Sopenharmony_ci 13648c2ecf20Sopenharmony_ci tqueue->tx_skbuff_dma[entry] = tx_desc->tdes01; 13658c2ecf20Sopenharmony_ci tqueue->tx_skbuff[entry] = NULL; 13668c2ecf20Sopenharmony_ci 13678c2ecf20Sopenharmony_ci /* prepare the descriptor */ 13688c2ecf20Sopenharmony_ci priv->hw->desc->prepare_tx_desc(tx_desc, 0, len, 13698c2ecf20Sopenharmony_ci len, cksum_flag); 13708c2ecf20Sopenharmony_ci /* memory barrier to flush descriptor */ 13718c2ecf20Sopenharmony_ci wmb(); 13728c2ecf20Sopenharmony_ci 13738c2ecf20Sopenharmony_ci /* set the owner */ 13748c2ecf20Sopenharmony_ci priv->hw->desc->set_tx_owner(tx_desc); 13758c2ecf20Sopenharmony_ci } 13768c2ecf20Sopenharmony_ci 13778c2ecf20Sopenharmony_ci /* close the descriptors */ 13788c2ecf20Sopenharmony_ci priv->hw->desc->close_tx_desc(tx_desc); 13798c2ecf20Sopenharmony_ci 13808c2ecf20Sopenharmony_ci /* memory barrier to flush descriptor */ 13818c2ecf20Sopenharmony_ci wmb(); 13828c2ecf20Sopenharmony_ci 13838c2ecf20Sopenharmony_ci tqueue->tx_count_frames += nr_frags + 1; 13848c2ecf20Sopenharmony_ci if (tqueue->tx_count_frames > tqueue->tx_coal_frames) { 13858c2ecf20Sopenharmony_ci priv->hw->desc->clear_tx_ic(tx_desc); 13868c2ecf20Sopenharmony_ci priv->xstats.tx_reset_ic_bit++; 13878c2ecf20Sopenharmony_ci mod_timer(&tqueue->txtimer, 13888c2ecf20Sopenharmony_ci SXGBE_COAL_TIMER(tqueue->tx_coal_timer)); 13898c2ecf20Sopenharmony_ci } else { 13908c2ecf20Sopenharmony_ci tqueue->tx_count_frames = 0; 13918c2ecf20Sopenharmony_ci } 13928c2ecf20Sopenharmony_ci 13938c2ecf20Sopenharmony_ci /* set owner for first desc */ 13948c2ecf20Sopenharmony_ci priv->hw->desc->set_tx_owner(first_desc); 13958c2ecf20Sopenharmony_ci 13968c2ecf20Sopenharmony_ci /* memory barrier to flush descriptor */ 13978c2ecf20Sopenharmony_ci wmb(); 13988c2ecf20Sopenharmony_ci 13998c2ecf20Sopenharmony_ci tqueue->cur_tx++; 14008c2ecf20Sopenharmony_ci 14018c2ecf20Sopenharmony_ci /* display current ring */ 14028c2ecf20Sopenharmony_ci netif_dbg(priv, pktdata, dev, "%s: curr %d dirty=%d entry=%d, first=%p, nfrags=%d\n", 14038c2ecf20Sopenharmony_ci __func__, tqueue->cur_tx % tx_rsize, 14048c2ecf20Sopenharmony_ci tqueue->dirty_tx % tx_rsize, entry, 14058c2ecf20Sopenharmony_ci first_desc, nr_frags); 14068c2ecf20Sopenharmony_ci 14078c2ecf20Sopenharmony_ci if (unlikely(sxgbe_tx_avail(tqueue, tx_rsize) <= (MAX_SKB_FRAGS + 1))) { 14088c2ecf20Sopenharmony_ci netif_dbg(priv, hw, dev, "%s: stop transmitted packets\n", 14098c2ecf20Sopenharmony_ci __func__); 14108c2ecf20Sopenharmony_ci netif_tx_stop_queue(dev_txq); 14118c2ecf20Sopenharmony_ci } 14128c2ecf20Sopenharmony_ci 14138c2ecf20Sopenharmony_ci dev->stats.tx_bytes += skb->len; 14148c2ecf20Sopenharmony_ci 14158c2ecf20Sopenharmony_ci if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && 14168c2ecf20Sopenharmony_ci tqueue->hwts_tx_en)) { 14178c2ecf20Sopenharmony_ci /* declare that device is doing timestamping */ 14188c2ecf20Sopenharmony_ci skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; 14198c2ecf20Sopenharmony_ci priv->hw->desc->tx_enable_tstamp(first_desc); 14208c2ecf20Sopenharmony_ci } 14218c2ecf20Sopenharmony_ci 14228c2ecf20Sopenharmony_ci skb_tx_timestamp(skb); 14238c2ecf20Sopenharmony_ci 14248c2ecf20Sopenharmony_ci priv->hw->dma->enable_dma_transmission(priv->ioaddr, txq_index); 14258c2ecf20Sopenharmony_ci 14268c2ecf20Sopenharmony_ci return NETDEV_TX_OK; 14278c2ecf20Sopenharmony_ci} 14288c2ecf20Sopenharmony_ci 14298c2ecf20Sopenharmony_ci/** 14308c2ecf20Sopenharmony_ci * sxgbe_rx_refill: refill used skb preallocated buffers 14318c2ecf20Sopenharmony_ci * @priv: driver private structure 14328c2ecf20Sopenharmony_ci * Description : this is to reallocate the skb for the reception process 14338c2ecf20Sopenharmony_ci * that is based on zero-copy. 14348c2ecf20Sopenharmony_ci */ 14358c2ecf20Sopenharmony_cistatic void sxgbe_rx_refill(struct sxgbe_priv_data *priv) 14368c2ecf20Sopenharmony_ci{ 14378c2ecf20Sopenharmony_ci unsigned int rxsize = priv->dma_rx_size; 14388c2ecf20Sopenharmony_ci int bfsize = priv->dma_buf_sz; 14398c2ecf20Sopenharmony_ci u8 qnum = priv->cur_rx_qnum; 14408c2ecf20Sopenharmony_ci 14418c2ecf20Sopenharmony_ci for (; priv->rxq[qnum]->cur_rx - priv->rxq[qnum]->dirty_rx > 0; 14428c2ecf20Sopenharmony_ci priv->rxq[qnum]->dirty_rx++) { 14438c2ecf20Sopenharmony_ci unsigned int entry = priv->rxq[qnum]->dirty_rx % rxsize; 14448c2ecf20Sopenharmony_ci struct sxgbe_rx_norm_desc *p; 14458c2ecf20Sopenharmony_ci 14468c2ecf20Sopenharmony_ci p = priv->rxq[qnum]->dma_rx + entry; 14478c2ecf20Sopenharmony_ci 14488c2ecf20Sopenharmony_ci if (likely(priv->rxq[qnum]->rx_skbuff[entry] == NULL)) { 14498c2ecf20Sopenharmony_ci struct sk_buff *skb; 14508c2ecf20Sopenharmony_ci 14518c2ecf20Sopenharmony_ci skb = netdev_alloc_skb_ip_align(priv->dev, bfsize); 14528c2ecf20Sopenharmony_ci 14538c2ecf20Sopenharmony_ci if (unlikely(skb == NULL)) 14548c2ecf20Sopenharmony_ci break; 14558c2ecf20Sopenharmony_ci 14568c2ecf20Sopenharmony_ci priv->rxq[qnum]->rx_skbuff[entry] = skb; 14578c2ecf20Sopenharmony_ci priv->rxq[qnum]->rx_skbuff_dma[entry] = 14588c2ecf20Sopenharmony_ci dma_map_single(priv->device, skb->data, bfsize, 14598c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 14608c2ecf20Sopenharmony_ci 14618c2ecf20Sopenharmony_ci p->rdes23.rx_rd_des23.buf2_addr = 14628c2ecf20Sopenharmony_ci priv->rxq[qnum]->rx_skbuff_dma[entry]; 14638c2ecf20Sopenharmony_ci } 14648c2ecf20Sopenharmony_ci 14658c2ecf20Sopenharmony_ci /* Added memory barrier for RX descriptor modification */ 14668c2ecf20Sopenharmony_ci wmb(); 14678c2ecf20Sopenharmony_ci priv->hw->desc->set_rx_owner(p); 14688c2ecf20Sopenharmony_ci priv->hw->desc->set_rx_int_on_com(p); 14698c2ecf20Sopenharmony_ci /* Added memory barrier for RX descriptor modification */ 14708c2ecf20Sopenharmony_ci wmb(); 14718c2ecf20Sopenharmony_ci } 14728c2ecf20Sopenharmony_ci} 14738c2ecf20Sopenharmony_ci 14748c2ecf20Sopenharmony_ci/** 14758c2ecf20Sopenharmony_ci * sxgbe_rx: receive the frames from the remote host 14768c2ecf20Sopenharmony_ci * @priv: driver private structure 14778c2ecf20Sopenharmony_ci * @limit: napi bugget. 14788c2ecf20Sopenharmony_ci * Description : this the function called by the napi poll method. 14798c2ecf20Sopenharmony_ci * It gets all the frames inside the ring. 14808c2ecf20Sopenharmony_ci */ 14818c2ecf20Sopenharmony_cistatic int sxgbe_rx(struct sxgbe_priv_data *priv, int limit) 14828c2ecf20Sopenharmony_ci{ 14838c2ecf20Sopenharmony_ci u8 qnum = priv->cur_rx_qnum; 14848c2ecf20Sopenharmony_ci unsigned int rxsize = priv->dma_rx_size; 14858c2ecf20Sopenharmony_ci unsigned int entry = priv->rxq[qnum]->cur_rx; 14868c2ecf20Sopenharmony_ci unsigned int next_entry = 0; 14878c2ecf20Sopenharmony_ci unsigned int count = 0; 14888c2ecf20Sopenharmony_ci int checksum; 14898c2ecf20Sopenharmony_ci int status; 14908c2ecf20Sopenharmony_ci 14918c2ecf20Sopenharmony_ci while (count < limit) { 14928c2ecf20Sopenharmony_ci struct sxgbe_rx_norm_desc *p; 14938c2ecf20Sopenharmony_ci struct sk_buff *skb; 14948c2ecf20Sopenharmony_ci int frame_len; 14958c2ecf20Sopenharmony_ci 14968c2ecf20Sopenharmony_ci p = priv->rxq[qnum]->dma_rx + entry; 14978c2ecf20Sopenharmony_ci 14988c2ecf20Sopenharmony_ci if (priv->hw->desc->get_rx_owner(p)) 14998c2ecf20Sopenharmony_ci break; 15008c2ecf20Sopenharmony_ci 15018c2ecf20Sopenharmony_ci count++; 15028c2ecf20Sopenharmony_ci 15038c2ecf20Sopenharmony_ci next_entry = (++priv->rxq[qnum]->cur_rx) % rxsize; 15048c2ecf20Sopenharmony_ci prefetch(priv->rxq[qnum]->dma_rx + next_entry); 15058c2ecf20Sopenharmony_ci 15068c2ecf20Sopenharmony_ci /* Read the status of the incoming frame and also get checksum 15078c2ecf20Sopenharmony_ci * value based on whether it is enabled in SXGBE hardware or 15088c2ecf20Sopenharmony_ci * not. 15098c2ecf20Sopenharmony_ci */ 15108c2ecf20Sopenharmony_ci status = priv->hw->desc->rx_wbstatus(p, &priv->xstats, 15118c2ecf20Sopenharmony_ci &checksum); 15128c2ecf20Sopenharmony_ci if (unlikely(status < 0)) { 15138c2ecf20Sopenharmony_ci entry = next_entry; 15148c2ecf20Sopenharmony_ci continue; 15158c2ecf20Sopenharmony_ci } 15168c2ecf20Sopenharmony_ci if (unlikely(!priv->rxcsum_insertion)) 15178c2ecf20Sopenharmony_ci checksum = CHECKSUM_NONE; 15188c2ecf20Sopenharmony_ci 15198c2ecf20Sopenharmony_ci skb = priv->rxq[qnum]->rx_skbuff[entry]; 15208c2ecf20Sopenharmony_ci 15218c2ecf20Sopenharmony_ci if (unlikely(!skb)) 15228c2ecf20Sopenharmony_ci netdev_err(priv->dev, "rx descriptor is not consistent\n"); 15238c2ecf20Sopenharmony_ci 15248c2ecf20Sopenharmony_ci prefetch(skb->data - NET_IP_ALIGN); 15258c2ecf20Sopenharmony_ci priv->rxq[qnum]->rx_skbuff[entry] = NULL; 15268c2ecf20Sopenharmony_ci 15278c2ecf20Sopenharmony_ci frame_len = priv->hw->desc->get_rx_frame_len(p); 15288c2ecf20Sopenharmony_ci 15298c2ecf20Sopenharmony_ci skb_put(skb, frame_len); 15308c2ecf20Sopenharmony_ci 15318c2ecf20Sopenharmony_ci skb->ip_summed = checksum; 15328c2ecf20Sopenharmony_ci if (checksum == CHECKSUM_NONE) 15338c2ecf20Sopenharmony_ci netif_receive_skb(skb); 15348c2ecf20Sopenharmony_ci else 15358c2ecf20Sopenharmony_ci napi_gro_receive(&priv->napi, skb); 15368c2ecf20Sopenharmony_ci 15378c2ecf20Sopenharmony_ci entry = next_entry; 15388c2ecf20Sopenharmony_ci } 15398c2ecf20Sopenharmony_ci 15408c2ecf20Sopenharmony_ci sxgbe_rx_refill(priv); 15418c2ecf20Sopenharmony_ci 15428c2ecf20Sopenharmony_ci return count; 15438c2ecf20Sopenharmony_ci} 15448c2ecf20Sopenharmony_ci 15458c2ecf20Sopenharmony_ci/** 15468c2ecf20Sopenharmony_ci * sxgbe_poll - sxgbe poll method (NAPI) 15478c2ecf20Sopenharmony_ci * @napi : pointer to the napi structure. 15488c2ecf20Sopenharmony_ci * @budget : maximum number of packets that the current CPU can receive from 15498c2ecf20Sopenharmony_ci * all interfaces. 15508c2ecf20Sopenharmony_ci * Description : 15518c2ecf20Sopenharmony_ci * To look at the incoming frames and clear the tx resources. 15528c2ecf20Sopenharmony_ci */ 15538c2ecf20Sopenharmony_cistatic int sxgbe_poll(struct napi_struct *napi, int budget) 15548c2ecf20Sopenharmony_ci{ 15558c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = container_of(napi, 15568c2ecf20Sopenharmony_ci struct sxgbe_priv_data, napi); 15578c2ecf20Sopenharmony_ci int work_done = 0; 15588c2ecf20Sopenharmony_ci u8 qnum = priv->cur_rx_qnum; 15598c2ecf20Sopenharmony_ci 15608c2ecf20Sopenharmony_ci priv->xstats.napi_poll++; 15618c2ecf20Sopenharmony_ci /* first, clean the tx queues */ 15628c2ecf20Sopenharmony_ci sxgbe_tx_all_clean(priv); 15638c2ecf20Sopenharmony_ci 15648c2ecf20Sopenharmony_ci work_done = sxgbe_rx(priv, budget); 15658c2ecf20Sopenharmony_ci if (work_done < budget) { 15668c2ecf20Sopenharmony_ci napi_complete_done(napi, work_done); 15678c2ecf20Sopenharmony_ci priv->hw->dma->enable_dma_irq(priv->ioaddr, qnum); 15688c2ecf20Sopenharmony_ci } 15698c2ecf20Sopenharmony_ci 15708c2ecf20Sopenharmony_ci return work_done; 15718c2ecf20Sopenharmony_ci} 15728c2ecf20Sopenharmony_ci 15738c2ecf20Sopenharmony_ci/** 15748c2ecf20Sopenharmony_ci * sxgbe_tx_timeout 15758c2ecf20Sopenharmony_ci * @dev : Pointer to net device structure 15768c2ecf20Sopenharmony_ci * @txqueue: index of the hanging queue 15778c2ecf20Sopenharmony_ci * Description: this function is called when a packet transmission fails to 15788c2ecf20Sopenharmony_ci * complete within a reasonable time. The driver will mark the error in the 15798c2ecf20Sopenharmony_ci * netdev structure and arrange for the device to be reset to a sane state 15808c2ecf20Sopenharmony_ci * in order to transmit a new packet. 15818c2ecf20Sopenharmony_ci */ 15828c2ecf20Sopenharmony_cistatic void sxgbe_tx_timeout(struct net_device *dev, unsigned int txqueue) 15838c2ecf20Sopenharmony_ci{ 15848c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 15858c2ecf20Sopenharmony_ci 15868c2ecf20Sopenharmony_ci sxgbe_reset_all_tx_queues(priv); 15878c2ecf20Sopenharmony_ci} 15888c2ecf20Sopenharmony_ci 15898c2ecf20Sopenharmony_ci/** 15908c2ecf20Sopenharmony_ci * sxgbe_common_interrupt - main ISR 15918c2ecf20Sopenharmony_ci * @irq: interrupt number. 15928c2ecf20Sopenharmony_ci * @dev_id: to pass the net device pointer. 15938c2ecf20Sopenharmony_ci * Description: this is the main driver interrupt service routine. 15948c2ecf20Sopenharmony_ci * It calls the DMA ISR and also the core ISR to manage PMT, MMC, LPI 15958c2ecf20Sopenharmony_ci * interrupts. 15968c2ecf20Sopenharmony_ci */ 15978c2ecf20Sopenharmony_cistatic irqreturn_t sxgbe_common_interrupt(int irq, void *dev_id) 15988c2ecf20Sopenharmony_ci{ 15998c2ecf20Sopenharmony_ci struct net_device *netdev = (struct net_device *)dev_id; 16008c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(netdev); 16018c2ecf20Sopenharmony_ci int status; 16028c2ecf20Sopenharmony_ci 16038c2ecf20Sopenharmony_ci status = priv->hw->mac->host_irq_status(priv->ioaddr, &priv->xstats); 16048c2ecf20Sopenharmony_ci /* For LPI we need to save the tx status */ 16058c2ecf20Sopenharmony_ci if (status & TX_ENTRY_LPI_MODE) { 16068c2ecf20Sopenharmony_ci priv->xstats.tx_lpi_entry_n++; 16078c2ecf20Sopenharmony_ci priv->tx_path_in_lpi_mode = true; 16088c2ecf20Sopenharmony_ci } 16098c2ecf20Sopenharmony_ci if (status & TX_EXIT_LPI_MODE) { 16108c2ecf20Sopenharmony_ci priv->xstats.tx_lpi_exit_n++; 16118c2ecf20Sopenharmony_ci priv->tx_path_in_lpi_mode = false; 16128c2ecf20Sopenharmony_ci } 16138c2ecf20Sopenharmony_ci if (status & RX_ENTRY_LPI_MODE) 16148c2ecf20Sopenharmony_ci priv->xstats.rx_lpi_entry_n++; 16158c2ecf20Sopenharmony_ci if (status & RX_EXIT_LPI_MODE) 16168c2ecf20Sopenharmony_ci priv->xstats.rx_lpi_exit_n++; 16178c2ecf20Sopenharmony_ci 16188c2ecf20Sopenharmony_ci return IRQ_HANDLED; 16198c2ecf20Sopenharmony_ci} 16208c2ecf20Sopenharmony_ci 16218c2ecf20Sopenharmony_ci/** 16228c2ecf20Sopenharmony_ci * sxgbe_tx_interrupt - TX DMA ISR 16238c2ecf20Sopenharmony_ci * @irq: interrupt number. 16248c2ecf20Sopenharmony_ci * @dev_id: to pass the net device pointer. 16258c2ecf20Sopenharmony_ci * Description: this is the tx dma interrupt service routine. 16268c2ecf20Sopenharmony_ci */ 16278c2ecf20Sopenharmony_cistatic irqreturn_t sxgbe_tx_interrupt(int irq, void *dev_id) 16288c2ecf20Sopenharmony_ci{ 16298c2ecf20Sopenharmony_ci int status; 16308c2ecf20Sopenharmony_ci struct sxgbe_tx_queue *txq = (struct sxgbe_tx_queue *)dev_id; 16318c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = txq->priv_ptr; 16328c2ecf20Sopenharmony_ci 16338c2ecf20Sopenharmony_ci /* get the channel status */ 16348c2ecf20Sopenharmony_ci status = priv->hw->dma->tx_dma_int_status(priv->ioaddr, txq->queue_no, 16358c2ecf20Sopenharmony_ci &priv->xstats); 16368c2ecf20Sopenharmony_ci /* check for normal path */ 16378c2ecf20Sopenharmony_ci if (likely((status & handle_tx))) 16388c2ecf20Sopenharmony_ci napi_schedule(&priv->napi); 16398c2ecf20Sopenharmony_ci 16408c2ecf20Sopenharmony_ci /* check for unrecoverable error */ 16418c2ecf20Sopenharmony_ci if (unlikely((status & tx_hard_error))) 16428c2ecf20Sopenharmony_ci sxgbe_restart_tx_queue(priv, txq->queue_no); 16438c2ecf20Sopenharmony_ci 16448c2ecf20Sopenharmony_ci /* check for TC configuration change */ 16458c2ecf20Sopenharmony_ci if (unlikely((status & tx_bump_tc) && 16468c2ecf20Sopenharmony_ci (priv->tx_tc != SXGBE_MTL_SFMODE) && 16478c2ecf20Sopenharmony_ci (priv->tx_tc < 512))) { 16488c2ecf20Sopenharmony_ci /* step of TX TC is 32 till 128, otherwise 64 */ 16498c2ecf20Sopenharmony_ci priv->tx_tc += (priv->tx_tc < 128) ? 32 : 64; 16508c2ecf20Sopenharmony_ci priv->hw->mtl->set_tx_mtl_mode(priv->ioaddr, 16518c2ecf20Sopenharmony_ci txq->queue_no, priv->tx_tc); 16528c2ecf20Sopenharmony_ci priv->xstats.tx_threshold = priv->tx_tc; 16538c2ecf20Sopenharmony_ci } 16548c2ecf20Sopenharmony_ci 16558c2ecf20Sopenharmony_ci return IRQ_HANDLED; 16568c2ecf20Sopenharmony_ci} 16578c2ecf20Sopenharmony_ci 16588c2ecf20Sopenharmony_ci/** 16598c2ecf20Sopenharmony_ci * sxgbe_rx_interrupt - RX DMA ISR 16608c2ecf20Sopenharmony_ci * @irq: interrupt number. 16618c2ecf20Sopenharmony_ci * @dev_id: to pass the net device pointer. 16628c2ecf20Sopenharmony_ci * Description: this is the rx dma interrupt service routine. 16638c2ecf20Sopenharmony_ci */ 16648c2ecf20Sopenharmony_cistatic irqreturn_t sxgbe_rx_interrupt(int irq, void *dev_id) 16658c2ecf20Sopenharmony_ci{ 16668c2ecf20Sopenharmony_ci int status; 16678c2ecf20Sopenharmony_ci struct sxgbe_rx_queue *rxq = (struct sxgbe_rx_queue *)dev_id; 16688c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = rxq->priv_ptr; 16698c2ecf20Sopenharmony_ci 16708c2ecf20Sopenharmony_ci /* get the channel status */ 16718c2ecf20Sopenharmony_ci status = priv->hw->dma->rx_dma_int_status(priv->ioaddr, rxq->queue_no, 16728c2ecf20Sopenharmony_ci &priv->xstats); 16738c2ecf20Sopenharmony_ci 16748c2ecf20Sopenharmony_ci if (likely((status & handle_rx) && (napi_schedule_prep(&priv->napi)))) { 16758c2ecf20Sopenharmony_ci priv->hw->dma->disable_dma_irq(priv->ioaddr, rxq->queue_no); 16768c2ecf20Sopenharmony_ci __napi_schedule(&priv->napi); 16778c2ecf20Sopenharmony_ci } 16788c2ecf20Sopenharmony_ci 16798c2ecf20Sopenharmony_ci /* check for TC configuration change */ 16808c2ecf20Sopenharmony_ci if (unlikely((status & rx_bump_tc) && 16818c2ecf20Sopenharmony_ci (priv->rx_tc != SXGBE_MTL_SFMODE) && 16828c2ecf20Sopenharmony_ci (priv->rx_tc < 128))) { 16838c2ecf20Sopenharmony_ci /* step of TC is 32 */ 16848c2ecf20Sopenharmony_ci priv->rx_tc += 32; 16858c2ecf20Sopenharmony_ci priv->hw->mtl->set_rx_mtl_mode(priv->ioaddr, 16868c2ecf20Sopenharmony_ci rxq->queue_no, priv->rx_tc); 16878c2ecf20Sopenharmony_ci priv->xstats.rx_threshold = priv->rx_tc; 16888c2ecf20Sopenharmony_ci } 16898c2ecf20Sopenharmony_ci 16908c2ecf20Sopenharmony_ci return IRQ_HANDLED; 16918c2ecf20Sopenharmony_ci} 16928c2ecf20Sopenharmony_ci 16938c2ecf20Sopenharmony_cistatic inline u64 sxgbe_get_stat64(void __iomem *ioaddr, int reg_lo, int reg_hi) 16948c2ecf20Sopenharmony_ci{ 16958c2ecf20Sopenharmony_ci u64 val = readl(ioaddr + reg_lo); 16968c2ecf20Sopenharmony_ci 16978c2ecf20Sopenharmony_ci val |= ((u64)readl(ioaddr + reg_hi)) << 32; 16988c2ecf20Sopenharmony_ci 16998c2ecf20Sopenharmony_ci return val; 17008c2ecf20Sopenharmony_ci} 17018c2ecf20Sopenharmony_ci 17028c2ecf20Sopenharmony_ci 17038c2ecf20Sopenharmony_ci/* sxgbe_get_stats64 - entry point to see statistical information of device 17048c2ecf20Sopenharmony_ci * @dev : device pointer. 17058c2ecf20Sopenharmony_ci * @stats : pointer to hold all the statistical information of device. 17068c2ecf20Sopenharmony_ci * Description: 17078c2ecf20Sopenharmony_ci * This function is a driver entry point whenever ifconfig command gets 17088c2ecf20Sopenharmony_ci * executed to see device statistics. Statistics are number of 17098c2ecf20Sopenharmony_ci * bytes sent or received, errors occurred etc. 17108c2ecf20Sopenharmony_ci */ 17118c2ecf20Sopenharmony_cistatic void sxgbe_get_stats64(struct net_device *dev, 17128c2ecf20Sopenharmony_ci struct rtnl_link_stats64 *stats) 17138c2ecf20Sopenharmony_ci{ 17148c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 17158c2ecf20Sopenharmony_ci void __iomem *ioaddr = priv->ioaddr; 17168c2ecf20Sopenharmony_ci u64 count; 17178c2ecf20Sopenharmony_ci 17188c2ecf20Sopenharmony_ci spin_lock(&priv->stats_lock); 17198c2ecf20Sopenharmony_ci /* Freeze the counter registers before reading value otherwise it may 17208c2ecf20Sopenharmony_ci * get updated by hardware while we are reading them 17218c2ecf20Sopenharmony_ci */ 17228c2ecf20Sopenharmony_ci writel(SXGBE_MMC_CTRL_CNT_FRZ, ioaddr + SXGBE_MMC_CTL_REG); 17238c2ecf20Sopenharmony_ci 17248c2ecf20Sopenharmony_ci stats->rx_bytes = sxgbe_get_stat64(ioaddr, 17258c2ecf20Sopenharmony_ci SXGBE_MMC_RXOCTETLO_GCNT_REG, 17268c2ecf20Sopenharmony_ci SXGBE_MMC_RXOCTETHI_GCNT_REG); 17278c2ecf20Sopenharmony_ci 17288c2ecf20Sopenharmony_ci stats->rx_packets = sxgbe_get_stat64(ioaddr, 17298c2ecf20Sopenharmony_ci SXGBE_MMC_RXFRAMELO_GBCNT_REG, 17308c2ecf20Sopenharmony_ci SXGBE_MMC_RXFRAMEHI_GBCNT_REG); 17318c2ecf20Sopenharmony_ci 17328c2ecf20Sopenharmony_ci stats->multicast = sxgbe_get_stat64(ioaddr, 17338c2ecf20Sopenharmony_ci SXGBE_MMC_RXMULTILO_GCNT_REG, 17348c2ecf20Sopenharmony_ci SXGBE_MMC_RXMULTIHI_GCNT_REG); 17358c2ecf20Sopenharmony_ci 17368c2ecf20Sopenharmony_ci stats->rx_crc_errors = sxgbe_get_stat64(ioaddr, 17378c2ecf20Sopenharmony_ci SXGBE_MMC_RXCRCERRLO_REG, 17388c2ecf20Sopenharmony_ci SXGBE_MMC_RXCRCERRHI_REG); 17398c2ecf20Sopenharmony_ci 17408c2ecf20Sopenharmony_ci stats->rx_length_errors = sxgbe_get_stat64(ioaddr, 17418c2ecf20Sopenharmony_ci SXGBE_MMC_RXLENERRLO_REG, 17428c2ecf20Sopenharmony_ci SXGBE_MMC_RXLENERRHI_REG); 17438c2ecf20Sopenharmony_ci 17448c2ecf20Sopenharmony_ci stats->rx_missed_errors = sxgbe_get_stat64(ioaddr, 17458c2ecf20Sopenharmony_ci SXGBE_MMC_RXFIFOOVERFLOWLO_GBCNT_REG, 17468c2ecf20Sopenharmony_ci SXGBE_MMC_RXFIFOOVERFLOWHI_GBCNT_REG); 17478c2ecf20Sopenharmony_ci 17488c2ecf20Sopenharmony_ci stats->tx_bytes = sxgbe_get_stat64(ioaddr, 17498c2ecf20Sopenharmony_ci SXGBE_MMC_TXOCTETLO_GCNT_REG, 17508c2ecf20Sopenharmony_ci SXGBE_MMC_TXOCTETHI_GCNT_REG); 17518c2ecf20Sopenharmony_ci 17528c2ecf20Sopenharmony_ci count = sxgbe_get_stat64(ioaddr, SXGBE_MMC_TXFRAMELO_GBCNT_REG, 17538c2ecf20Sopenharmony_ci SXGBE_MMC_TXFRAMEHI_GBCNT_REG); 17548c2ecf20Sopenharmony_ci 17558c2ecf20Sopenharmony_ci stats->tx_errors = sxgbe_get_stat64(ioaddr, SXGBE_MMC_TXFRAMELO_GCNT_REG, 17568c2ecf20Sopenharmony_ci SXGBE_MMC_TXFRAMEHI_GCNT_REG); 17578c2ecf20Sopenharmony_ci stats->tx_errors = count - stats->tx_errors; 17588c2ecf20Sopenharmony_ci stats->tx_packets = count; 17598c2ecf20Sopenharmony_ci stats->tx_fifo_errors = sxgbe_get_stat64(ioaddr, SXGBE_MMC_TXUFLWLO_GBCNT_REG, 17608c2ecf20Sopenharmony_ci SXGBE_MMC_TXUFLWHI_GBCNT_REG); 17618c2ecf20Sopenharmony_ci writel(0, ioaddr + SXGBE_MMC_CTL_REG); 17628c2ecf20Sopenharmony_ci spin_unlock(&priv->stats_lock); 17638c2ecf20Sopenharmony_ci} 17648c2ecf20Sopenharmony_ci 17658c2ecf20Sopenharmony_ci/* sxgbe_set_features - entry point to set offload features of the device. 17668c2ecf20Sopenharmony_ci * @dev : device pointer. 17678c2ecf20Sopenharmony_ci * @features : features which are required to be set. 17688c2ecf20Sopenharmony_ci * Description: 17698c2ecf20Sopenharmony_ci * This function is a driver entry point and called by Linux kernel whenever 17708c2ecf20Sopenharmony_ci * any device features are set or reset by user. 17718c2ecf20Sopenharmony_ci * Return value: 17728c2ecf20Sopenharmony_ci * This function returns 0 after setting or resetting device features. 17738c2ecf20Sopenharmony_ci */ 17748c2ecf20Sopenharmony_cistatic int sxgbe_set_features(struct net_device *dev, 17758c2ecf20Sopenharmony_ci netdev_features_t features) 17768c2ecf20Sopenharmony_ci{ 17778c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 17788c2ecf20Sopenharmony_ci netdev_features_t changed = dev->features ^ features; 17798c2ecf20Sopenharmony_ci 17808c2ecf20Sopenharmony_ci if (changed & NETIF_F_RXCSUM) { 17818c2ecf20Sopenharmony_ci if (features & NETIF_F_RXCSUM) { 17828c2ecf20Sopenharmony_ci priv->hw->mac->enable_rx_csum(priv->ioaddr); 17838c2ecf20Sopenharmony_ci priv->rxcsum_insertion = true; 17848c2ecf20Sopenharmony_ci } else { 17858c2ecf20Sopenharmony_ci priv->hw->mac->disable_rx_csum(priv->ioaddr); 17868c2ecf20Sopenharmony_ci priv->rxcsum_insertion = false; 17878c2ecf20Sopenharmony_ci } 17888c2ecf20Sopenharmony_ci } 17898c2ecf20Sopenharmony_ci 17908c2ecf20Sopenharmony_ci return 0; 17918c2ecf20Sopenharmony_ci} 17928c2ecf20Sopenharmony_ci 17938c2ecf20Sopenharmony_ci/* sxgbe_change_mtu - entry point to change MTU size for the device. 17948c2ecf20Sopenharmony_ci * @dev : device pointer. 17958c2ecf20Sopenharmony_ci * @new_mtu : the new MTU size for the device. 17968c2ecf20Sopenharmony_ci * Description: the Maximum Transfer Unit (MTU) is used by the network layer 17978c2ecf20Sopenharmony_ci * to drive packet transmission. Ethernet has an MTU of 1500 octets 17988c2ecf20Sopenharmony_ci * (ETH_DATA_LEN). This value can be changed with ifconfig. 17998c2ecf20Sopenharmony_ci * Return value: 18008c2ecf20Sopenharmony_ci * 0 on success and an appropriate (-)ve integer as defined in errno.h 18018c2ecf20Sopenharmony_ci * file on failure. 18028c2ecf20Sopenharmony_ci */ 18038c2ecf20Sopenharmony_cistatic int sxgbe_change_mtu(struct net_device *dev, int new_mtu) 18048c2ecf20Sopenharmony_ci{ 18058c2ecf20Sopenharmony_ci dev->mtu = new_mtu; 18068c2ecf20Sopenharmony_ci 18078c2ecf20Sopenharmony_ci if (!netif_running(dev)) 18088c2ecf20Sopenharmony_ci return 0; 18098c2ecf20Sopenharmony_ci 18108c2ecf20Sopenharmony_ci /* Recevice ring buffer size is needed to be set based on MTU. If MTU is 18118c2ecf20Sopenharmony_ci * changed then reinitilisation of the receive ring buffers need to be 18128c2ecf20Sopenharmony_ci * done. Hence bring interface down and bring interface back up 18138c2ecf20Sopenharmony_ci */ 18148c2ecf20Sopenharmony_ci sxgbe_release(dev); 18158c2ecf20Sopenharmony_ci return sxgbe_open(dev); 18168c2ecf20Sopenharmony_ci} 18178c2ecf20Sopenharmony_ci 18188c2ecf20Sopenharmony_cistatic void sxgbe_set_umac_addr(void __iomem *ioaddr, unsigned char *addr, 18198c2ecf20Sopenharmony_ci unsigned int reg_n) 18208c2ecf20Sopenharmony_ci{ 18218c2ecf20Sopenharmony_ci unsigned long data; 18228c2ecf20Sopenharmony_ci 18238c2ecf20Sopenharmony_ci data = (addr[5] << 8) | addr[4]; 18248c2ecf20Sopenharmony_ci /* For MAC Addr registers se have to set the Address Enable (AE) 18258c2ecf20Sopenharmony_ci * bit that has no effect on the High Reg 0 where the bit 31 (MO) 18268c2ecf20Sopenharmony_ci * is RO. 18278c2ecf20Sopenharmony_ci */ 18288c2ecf20Sopenharmony_ci writel(data | SXGBE_HI_REG_AE, ioaddr + SXGBE_ADDR_HIGH(reg_n)); 18298c2ecf20Sopenharmony_ci data = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0]; 18308c2ecf20Sopenharmony_ci writel(data, ioaddr + SXGBE_ADDR_LOW(reg_n)); 18318c2ecf20Sopenharmony_ci} 18328c2ecf20Sopenharmony_ci 18338c2ecf20Sopenharmony_ci/** 18348c2ecf20Sopenharmony_ci * sxgbe_set_rx_mode - entry point for setting different receive mode of 18358c2ecf20Sopenharmony_ci * a device. unicast, multicast addressing 18368c2ecf20Sopenharmony_ci * @dev : pointer to the device structure 18378c2ecf20Sopenharmony_ci * Description: 18388c2ecf20Sopenharmony_ci * This function is a driver entry point which gets called by the kernel 18398c2ecf20Sopenharmony_ci * whenever different receive mode like unicast, multicast and promiscuous 18408c2ecf20Sopenharmony_ci * must be enabled/disabled. 18418c2ecf20Sopenharmony_ci * Return value: 18428c2ecf20Sopenharmony_ci * void. 18438c2ecf20Sopenharmony_ci */ 18448c2ecf20Sopenharmony_cistatic void sxgbe_set_rx_mode(struct net_device *dev) 18458c2ecf20Sopenharmony_ci{ 18468c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 18478c2ecf20Sopenharmony_ci void __iomem *ioaddr = (void __iomem *)priv->ioaddr; 18488c2ecf20Sopenharmony_ci unsigned int value = 0; 18498c2ecf20Sopenharmony_ci u32 mc_filter[2]; 18508c2ecf20Sopenharmony_ci struct netdev_hw_addr *ha; 18518c2ecf20Sopenharmony_ci int reg = 1; 18528c2ecf20Sopenharmony_ci 18538c2ecf20Sopenharmony_ci netdev_dbg(dev, "%s: # mcasts %d, # unicast %d\n", 18548c2ecf20Sopenharmony_ci __func__, netdev_mc_count(dev), netdev_uc_count(dev)); 18558c2ecf20Sopenharmony_ci 18568c2ecf20Sopenharmony_ci if (dev->flags & IFF_PROMISC) { 18578c2ecf20Sopenharmony_ci value = SXGBE_FRAME_FILTER_PR; 18588c2ecf20Sopenharmony_ci 18598c2ecf20Sopenharmony_ci } else if ((netdev_mc_count(dev) > SXGBE_HASH_TABLE_SIZE) || 18608c2ecf20Sopenharmony_ci (dev->flags & IFF_ALLMULTI)) { 18618c2ecf20Sopenharmony_ci value = SXGBE_FRAME_FILTER_PM; /* pass all multi */ 18628c2ecf20Sopenharmony_ci writel(0xffffffff, ioaddr + SXGBE_HASH_HIGH); 18638c2ecf20Sopenharmony_ci writel(0xffffffff, ioaddr + SXGBE_HASH_LOW); 18648c2ecf20Sopenharmony_ci 18658c2ecf20Sopenharmony_ci } else if (!netdev_mc_empty(dev)) { 18668c2ecf20Sopenharmony_ci /* Hash filter for multicast */ 18678c2ecf20Sopenharmony_ci value = SXGBE_FRAME_FILTER_HMC; 18688c2ecf20Sopenharmony_ci 18698c2ecf20Sopenharmony_ci memset(mc_filter, 0, sizeof(mc_filter)); 18708c2ecf20Sopenharmony_ci netdev_for_each_mc_addr(ha, dev) { 18718c2ecf20Sopenharmony_ci /* The upper 6 bits of the calculated CRC are used to 18728c2ecf20Sopenharmony_ci * index the contens of the hash table 18738c2ecf20Sopenharmony_ci */ 18748c2ecf20Sopenharmony_ci int bit_nr = bitrev32(~crc32_le(~0, ha->addr, 6)) >> 26; 18758c2ecf20Sopenharmony_ci 18768c2ecf20Sopenharmony_ci /* The most significant bit determines the register to 18778c2ecf20Sopenharmony_ci * use (H/L) while the other 5 bits determine the bit 18788c2ecf20Sopenharmony_ci * within the register. 18798c2ecf20Sopenharmony_ci */ 18808c2ecf20Sopenharmony_ci mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); 18818c2ecf20Sopenharmony_ci } 18828c2ecf20Sopenharmony_ci writel(mc_filter[0], ioaddr + SXGBE_HASH_LOW); 18838c2ecf20Sopenharmony_ci writel(mc_filter[1], ioaddr + SXGBE_HASH_HIGH); 18848c2ecf20Sopenharmony_ci } 18858c2ecf20Sopenharmony_ci 18868c2ecf20Sopenharmony_ci /* Handle multiple unicast addresses (perfect filtering) */ 18878c2ecf20Sopenharmony_ci if (netdev_uc_count(dev) > SXGBE_MAX_PERFECT_ADDRESSES) 18888c2ecf20Sopenharmony_ci /* Switch to promiscuous mode if more than 16 addrs 18898c2ecf20Sopenharmony_ci * are required 18908c2ecf20Sopenharmony_ci */ 18918c2ecf20Sopenharmony_ci value |= SXGBE_FRAME_FILTER_PR; 18928c2ecf20Sopenharmony_ci else { 18938c2ecf20Sopenharmony_ci netdev_for_each_uc_addr(ha, dev) { 18948c2ecf20Sopenharmony_ci sxgbe_set_umac_addr(ioaddr, ha->addr, reg); 18958c2ecf20Sopenharmony_ci reg++; 18968c2ecf20Sopenharmony_ci } 18978c2ecf20Sopenharmony_ci } 18988c2ecf20Sopenharmony_ci#ifdef FRAME_FILTER_DEBUG 18998c2ecf20Sopenharmony_ci /* Enable Receive all mode (to debug filtering_fail errors) */ 19008c2ecf20Sopenharmony_ci value |= SXGBE_FRAME_FILTER_RA; 19018c2ecf20Sopenharmony_ci#endif 19028c2ecf20Sopenharmony_ci writel(value, ioaddr + SXGBE_FRAME_FILTER); 19038c2ecf20Sopenharmony_ci 19048c2ecf20Sopenharmony_ci netdev_dbg(dev, "Filter: 0x%08x\n\tHash: HI 0x%08x, LO 0x%08x\n", 19058c2ecf20Sopenharmony_ci readl(ioaddr + SXGBE_FRAME_FILTER), 19068c2ecf20Sopenharmony_ci readl(ioaddr + SXGBE_HASH_HIGH), 19078c2ecf20Sopenharmony_ci readl(ioaddr + SXGBE_HASH_LOW)); 19088c2ecf20Sopenharmony_ci} 19098c2ecf20Sopenharmony_ci 19108c2ecf20Sopenharmony_ci#ifdef CONFIG_NET_POLL_CONTROLLER 19118c2ecf20Sopenharmony_ci/** 19128c2ecf20Sopenharmony_ci * sxgbe_poll_controller - entry point for polling receive by device 19138c2ecf20Sopenharmony_ci * @dev : pointer to the device structure 19148c2ecf20Sopenharmony_ci * Description: 19158c2ecf20Sopenharmony_ci * This function is used by NETCONSOLE and other diagnostic tools 19168c2ecf20Sopenharmony_ci * to allow network I/O with interrupts disabled. 19178c2ecf20Sopenharmony_ci * Return value: 19188c2ecf20Sopenharmony_ci * Void. 19198c2ecf20Sopenharmony_ci */ 19208c2ecf20Sopenharmony_cistatic void sxgbe_poll_controller(struct net_device *dev) 19218c2ecf20Sopenharmony_ci{ 19228c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(dev); 19238c2ecf20Sopenharmony_ci 19248c2ecf20Sopenharmony_ci disable_irq(priv->irq); 19258c2ecf20Sopenharmony_ci sxgbe_rx_interrupt(priv->irq, dev); 19268c2ecf20Sopenharmony_ci enable_irq(priv->irq); 19278c2ecf20Sopenharmony_ci} 19288c2ecf20Sopenharmony_ci#endif 19298c2ecf20Sopenharmony_ci 19308c2ecf20Sopenharmony_ci/* sxgbe_ioctl - Entry point for the Ioctl 19318c2ecf20Sopenharmony_ci * @dev: Device pointer. 19328c2ecf20Sopenharmony_ci * @rq: An IOCTL specefic structure, that can contain a pointer to 19338c2ecf20Sopenharmony_ci * a proprietary structure used to pass information to the driver. 19348c2ecf20Sopenharmony_ci * @cmd: IOCTL command 19358c2ecf20Sopenharmony_ci * Description: 19368c2ecf20Sopenharmony_ci * Currently it supports the phy_mii_ioctl(...) and HW time stamping. 19378c2ecf20Sopenharmony_ci */ 19388c2ecf20Sopenharmony_cistatic int sxgbe_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 19398c2ecf20Sopenharmony_ci{ 19408c2ecf20Sopenharmony_ci int ret = -EOPNOTSUPP; 19418c2ecf20Sopenharmony_ci 19428c2ecf20Sopenharmony_ci if (!netif_running(dev)) 19438c2ecf20Sopenharmony_ci return -EINVAL; 19448c2ecf20Sopenharmony_ci 19458c2ecf20Sopenharmony_ci switch (cmd) { 19468c2ecf20Sopenharmony_ci case SIOCGMIIPHY: 19478c2ecf20Sopenharmony_ci case SIOCGMIIREG: 19488c2ecf20Sopenharmony_ci case SIOCSMIIREG: 19498c2ecf20Sopenharmony_ci ret = phy_do_ioctl(dev, rq, cmd); 19508c2ecf20Sopenharmony_ci break; 19518c2ecf20Sopenharmony_ci default: 19528c2ecf20Sopenharmony_ci break; 19538c2ecf20Sopenharmony_ci } 19548c2ecf20Sopenharmony_ci 19558c2ecf20Sopenharmony_ci return ret; 19568c2ecf20Sopenharmony_ci} 19578c2ecf20Sopenharmony_ci 19588c2ecf20Sopenharmony_cistatic const struct net_device_ops sxgbe_netdev_ops = { 19598c2ecf20Sopenharmony_ci .ndo_open = sxgbe_open, 19608c2ecf20Sopenharmony_ci .ndo_start_xmit = sxgbe_xmit, 19618c2ecf20Sopenharmony_ci .ndo_stop = sxgbe_release, 19628c2ecf20Sopenharmony_ci .ndo_get_stats64 = sxgbe_get_stats64, 19638c2ecf20Sopenharmony_ci .ndo_change_mtu = sxgbe_change_mtu, 19648c2ecf20Sopenharmony_ci .ndo_set_features = sxgbe_set_features, 19658c2ecf20Sopenharmony_ci .ndo_set_rx_mode = sxgbe_set_rx_mode, 19668c2ecf20Sopenharmony_ci .ndo_tx_timeout = sxgbe_tx_timeout, 19678c2ecf20Sopenharmony_ci .ndo_do_ioctl = sxgbe_ioctl, 19688c2ecf20Sopenharmony_ci#ifdef CONFIG_NET_POLL_CONTROLLER 19698c2ecf20Sopenharmony_ci .ndo_poll_controller = sxgbe_poll_controller, 19708c2ecf20Sopenharmony_ci#endif 19718c2ecf20Sopenharmony_ci .ndo_set_mac_address = eth_mac_addr, 19728c2ecf20Sopenharmony_ci}; 19738c2ecf20Sopenharmony_ci 19748c2ecf20Sopenharmony_ci/* Get the hardware ops */ 19758c2ecf20Sopenharmony_cistatic void sxgbe_get_ops(struct sxgbe_ops * const ops_ptr) 19768c2ecf20Sopenharmony_ci{ 19778c2ecf20Sopenharmony_ci ops_ptr->mac = sxgbe_get_core_ops(); 19788c2ecf20Sopenharmony_ci ops_ptr->desc = sxgbe_get_desc_ops(); 19798c2ecf20Sopenharmony_ci ops_ptr->dma = sxgbe_get_dma_ops(); 19808c2ecf20Sopenharmony_ci ops_ptr->mtl = sxgbe_get_mtl_ops(); 19818c2ecf20Sopenharmony_ci 19828c2ecf20Sopenharmony_ci /* set the MDIO communication Address/Data regisers */ 19838c2ecf20Sopenharmony_ci ops_ptr->mii.addr = SXGBE_MDIO_SCMD_ADD_REG; 19848c2ecf20Sopenharmony_ci ops_ptr->mii.data = SXGBE_MDIO_SCMD_DATA_REG; 19858c2ecf20Sopenharmony_ci 19868c2ecf20Sopenharmony_ci /* Assigning the default link settings 19878c2ecf20Sopenharmony_ci * no SXGBE defined default values to be set in registers, 19888c2ecf20Sopenharmony_ci * so assigning as 0 for port and duplex 19898c2ecf20Sopenharmony_ci */ 19908c2ecf20Sopenharmony_ci ops_ptr->link.port = 0; 19918c2ecf20Sopenharmony_ci ops_ptr->link.duplex = 0; 19928c2ecf20Sopenharmony_ci ops_ptr->link.speed = SXGBE_SPEED_10G; 19938c2ecf20Sopenharmony_ci} 19948c2ecf20Sopenharmony_ci 19958c2ecf20Sopenharmony_ci/** 19968c2ecf20Sopenharmony_ci * sxgbe_hw_init - Init the GMAC device 19978c2ecf20Sopenharmony_ci * @priv: driver private structure 19988c2ecf20Sopenharmony_ci * Description: this function checks the HW capability 19998c2ecf20Sopenharmony_ci * (if supported) and sets the driver's features. 20008c2ecf20Sopenharmony_ci */ 20018c2ecf20Sopenharmony_cistatic int sxgbe_hw_init(struct sxgbe_priv_data * const priv) 20028c2ecf20Sopenharmony_ci{ 20038c2ecf20Sopenharmony_ci u32 ctrl_ids; 20048c2ecf20Sopenharmony_ci 20058c2ecf20Sopenharmony_ci priv->hw = kmalloc(sizeof(*priv->hw), GFP_KERNEL); 20068c2ecf20Sopenharmony_ci if(!priv->hw) 20078c2ecf20Sopenharmony_ci return -ENOMEM; 20088c2ecf20Sopenharmony_ci 20098c2ecf20Sopenharmony_ci /* get the hardware ops */ 20108c2ecf20Sopenharmony_ci sxgbe_get_ops(priv->hw); 20118c2ecf20Sopenharmony_ci 20128c2ecf20Sopenharmony_ci /* get the controller id */ 20138c2ecf20Sopenharmony_ci ctrl_ids = priv->hw->mac->get_controller_version(priv->ioaddr); 20148c2ecf20Sopenharmony_ci priv->hw->ctrl_uid = (ctrl_ids & 0x00ff0000) >> 16; 20158c2ecf20Sopenharmony_ci priv->hw->ctrl_id = (ctrl_ids & 0x000000ff); 20168c2ecf20Sopenharmony_ci pr_info("user ID: 0x%x, Controller ID: 0x%x\n", 20178c2ecf20Sopenharmony_ci priv->hw->ctrl_uid, priv->hw->ctrl_id); 20188c2ecf20Sopenharmony_ci 20198c2ecf20Sopenharmony_ci /* get the H/W features */ 20208c2ecf20Sopenharmony_ci if (!sxgbe_get_hw_features(priv)) 20218c2ecf20Sopenharmony_ci pr_info("Hardware features not found\n"); 20228c2ecf20Sopenharmony_ci 20238c2ecf20Sopenharmony_ci if (priv->hw_cap.tx_csum_offload) 20248c2ecf20Sopenharmony_ci pr_info("TX Checksum offload supported\n"); 20258c2ecf20Sopenharmony_ci 20268c2ecf20Sopenharmony_ci if (priv->hw_cap.rx_csum_offload) 20278c2ecf20Sopenharmony_ci pr_info("RX Checksum offload supported\n"); 20288c2ecf20Sopenharmony_ci 20298c2ecf20Sopenharmony_ci return 0; 20308c2ecf20Sopenharmony_ci} 20318c2ecf20Sopenharmony_ci 20328c2ecf20Sopenharmony_cistatic int sxgbe_sw_reset(void __iomem *addr) 20338c2ecf20Sopenharmony_ci{ 20348c2ecf20Sopenharmony_ci int retry_count = 10; 20358c2ecf20Sopenharmony_ci 20368c2ecf20Sopenharmony_ci writel(SXGBE_DMA_SOFT_RESET, addr + SXGBE_DMA_MODE_REG); 20378c2ecf20Sopenharmony_ci while (retry_count--) { 20388c2ecf20Sopenharmony_ci if (!(readl(addr + SXGBE_DMA_MODE_REG) & 20398c2ecf20Sopenharmony_ci SXGBE_DMA_SOFT_RESET)) 20408c2ecf20Sopenharmony_ci break; 20418c2ecf20Sopenharmony_ci mdelay(10); 20428c2ecf20Sopenharmony_ci } 20438c2ecf20Sopenharmony_ci 20448c2ecf20Sopenharmony_ci if (retry_count < 0) 20458c2ecf20Sopenharmony_ci return -EBUSY; 20468c2ecf20Sopenharmony_ci 20478c2ecf20Sopenharmony_ci return 0; 20488c2ecf20Sopenharmony_ci} 20498c2ecf20Sopenharmony_ci 20508c2ecf20Sopenharmony_ci/** 20518c2ecf20Sopenharmony_ci * sxgbe_drv_probe 20528c2ecf20Sopenharmony_ci * @device: device pointer 20538c2ecf20Sopenharmony_ci * @plat_dat: platform data pointer 20548c2ecf20Sopenharmony_ci * @addr: iobase memory address 20558c2ecf20Sopenharmony_ci * Description: this is the main probe function used to 20568c2ecf20Sopenharmony_ci * call the alloc_etherdev, allocate the priv structure. 20578c2ecf20Sopenharmony_ci */ 20588c2ecf20Sopenharmony_cistruct sxgbe_priv_data *sxgbe_drv_probe(struct device *device, 20598c2ecf20Sopenharmony_ci struct sxgbe_plat_data *plat_dat, 20608c2ecf20Sopenharmony_ci void __iomem *addr) 20618c2ecf20Sopenharmony_ci{ 20628c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv; 20638c2ecf20Sopenharmony_ci struct net_device *ndev; 20648c2ecf20Sopenharmony_ci int ret; 20658c2ecf20Sopenharmony_ci u8 queue_num; 20668c2ecf20Sopenharmony_ci 20678c2ecf20Sopenharmony_ci ndev = alloc_etherdev_mqs(sizeof(struct sxgbe_priv_data), 20688c2ecf20Sopenharmony_ci SXGBE_TX_QUEUES, SXGBE_RX_QUEUES); 20698c2ecf20Sopenharmony_ci if (!ndev) 20708c2ecf20Sopenharmony_ci return NULL; 20718c2ecf20Sopenharmony_ci 20728c2ecf20Sopenharmony_ci SET_NETDEV_DEV(ndev, device); 20738c2ecf20Sopenharmony_ci 20748c2ecf20Sopenharmony_ci priv = netdev_priv(ndev); 20758c2ecf20Sopenharmony_ci priv->device = device; 20768c2ecf20Sopenharmony_ci priv->dev = ndev; 20778c2ecf20Sopenharmony_ci 20788c2ecf20Sopenharmony_ci sxgbe_set_ethtool_ops(ndev); 20798c2ecf20Sopenharmony_ci priv->plat = plat_dat; 20808c2ecf20Sopenharmony_ci priv->ioaddr = addr; 20818c2ecf20Sopenharmony_ci 20828c2ecf20Sopenharmony_ci ret = sxgbe_sw_reset(priv->ioaddr); 20838c2ecf20Sopenharmony_ci if (ret) 20848c2ecf20Sopenharmony_ci goto error_free_netdev; 20858c2ecf20Sopenharmony_ci 20868c2ecf20Sopenharmony_ci /* Verify driver arguments */ 20878c2ecf20Sopenharmony_ci sxgbe_verify_args(); 20888c2ecf20Sopenharmony_ci 20898c2ecf20Sopenharmony_ci /* Init MAC and get the capabilities */ 20908c2ecf20Sopenharmony_ci ret = sxgbe_hw_init(priv); 20918c2ecf20Sopenharmony_ci if (ret) 20928c2ecf20Sopenharmony_ci goto error_free_netdev; 20938c2ecf20Sopenharmony_ci 20948c2ecf20Sopenharmony_ci /* allocate memory resources for Descriptor rings */ 20958c2ecf20Sopenharmony_ci ret = txring_mem_alloc(priv); 20968c2ecf20Sopenharmony_ci if (ret) 20978c2ecf20Sopenharmony_ci goto error_free_hw; 20988c2ecf20Sopenharmony_ci 20998c2ecf20Sopenharmony_ci ret = rxring_mem_alloc(priv); 21008c2ecf20Sopenharmony_ci if (ret) 21018c2ecf20Sopenharmony_ci goto error_free_hw; 21028c2ecf20Sopenharmony_ci 21038c2ecf20Sopenharmony_ci ndev->netdev_ops = &sxgbe_netdev_ops; 21048c2ecf20Sopenharmony_ci 21058c2ecf20Sopenharmony_ci ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 21068c2ecf20Sopenharmony_ci NETIF_F_RXCSUM | NETIF_F_TSO | NETIF_F_TSO6 | 21078c2ecf20Sopenharmony_ci NETIF_F_GRO; 21088c2ecf20Sopenharmony_ci ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA; 21098c2ecf20Sopenharmony_ci ndev->watchdog_timeo = msecs_to_jiffies(TX_TIMEO); 21108c2ecf20Sopenharmony_ci 21118c2ecf20Sopenharmony_ci /* assign filtering support */ 21128c2ecf20Sopenharmony_ci ndev->priv_flags |= IFF_UNICAST_FLT; 21138c2ecf20Sopenharmony_ci 21148c2ecf20Sopenharmony_ci /* MTU range: 68 - 9000 */ 21158c2ecf20Sopenharmony_ci ndev->min_mtu = MIN_MTU; 21168c2ecf20Sopenharmony_ci ndev->max_mtu = MAX_MTU; 21178c2ecf20Sopenharmony_ci 21188c2ecf20Sopenharmony_ci priv->msg_enable = netif_msg_init(debug, default_msg_level); 21198c2ecf20Sopenharmony_ci 21208c2ecf20Sopenharmony_ci /* Enable TCP segmentation offload for all DMA channels */ 21218c2ecf20Sopenharmony_ci if (priv->hw_cap.tcpseg_offload) { 21228c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) { 21238c2ecf20Sopenharmony_ci priv->hw->dma->enable_tso(priv->ioaddr, queue_num); 21248c2ecf20Sopenharmony_ci } 21258c2ecf20Sopenharmony_ci } 21268c2ecf20Sopenharmony_ci 21278c2ecf20Sopenharmony_ci /* Enable Rx checksum offload */ 21288c2ecf20Sopenharmony_ci if (priv->hw_cap.rx_csum_offload) { 21298c2ecf20Sopenharmony_ci priv->hw->mac->enable_rx_csum(priv->ioaddr); 21308c2ecf20Sopenharmony_ci priv->rxcsum_insertion = true; 21318c2ecf20Sopenharmony_ci } 21328c2ecf20Sopenharmony_ci 21338c2ecf20Sopenharmony_ci /* Initialise pause frame settings */ 21348c2ecf20Sopenharmony_ci priv->rx_pause = 1; 21358c2ecf20Sopenharmony_ci priv->tx_pause = 1; 21368c2ecf20Sopenharmony_ci 21378c2ecf20Sopenharmony_ci /* Rx Watchdog is available, enable depend on platform data */ 21388c2ecf20Sopenharmony_ci if (!priv->plat->riwt_off) { 21398c2ecf20Sopenharmony_ci priv->use_riwt = 1; 21408c2ecf20Sopenharmony_ci pr_info("Enable RX Mitigation via HW Watchdog Timer\n"); 21418c2ecf20Sopenharmony_ci } 21428c2ecf20Sopenharmony_ci 21438c2ecf20Sopenharmony_ci netif_napi_add(ndev, &priv->napi, sxgbe_poll, 64); 21448c2ecf20Sopenharmony_ci 21458c2ecf20Sopenharmony_ci spin_lock_init(&priv->stats_lock); 21468c2ecf20Sopenharmony_ci 21478c2ecf20Sopenharmony_ci priv->sxgbe_clk = clk_get(priv->device, SXGBE_RESOURCE_NAME); 21488c2ecf20Sopenharmony_ci if (IS_ERR(priv->sxgbe_clk)) { 21498c2ecf20Sopenharmony_ci netdev_warn(ndev, "%s: warning: cannot get CSR clock\n", 21508c2ecf20Sopenharmony_ci __func__); 21518c2ecf20Sopenharmony_ci goto error_napi_del; 21528c2ecf20Sopenharmony_ci } 21538c2ecf20Sopenharmony_ci 21548c2ecf20Sopenharmony_ci /* If a specific clk_csr value is passed from the platform 21558c2ecf20Sopenharmony_ci * this means that the CSR Clock Range selection cannot be 21568c2ecf20Sopenharmony_ci * changed at run-time and it is fixed. Viceversa the driver'll try to 21578c2ecf20Sopenharmony_ci * set the MDC clock dynamically according to the csr actual 21588c2ecf20Sopenharmony_ci * clock input. 21598c2ecf20Sopenharmony_ci */ 21608c2ecf20Sopenharmony_ci if (!priv->plat->clk_csr) 21618c2ecf20Sopenharmony_ci sxgbe_clk_csr_set(priv); 21628c2ecf20Sopenharmony_ci else 21638c2ecf20Sopenharmony_ci priv->clk_csr = priv->plat->clk_csr; 21648c2ecf20Sopenharmony_ci 21658c2ecf20Sopenharmony_ci /* MDIO bus Registration */ 21668c2ecf20Sopenharmony_ci ret = sxgbe_mdio_register(ndev); 21678c2ecf20Sopenharmony_ci if (ret < 0) { 21688c2ecf20Sopenharmony_ci netdev_dbg(ndev, "%s: MDIO bus (id: %d) registration failed\n", 21698c2ecf20Sopenharmony_ci __func__, priv->plat->bus_id); 21708c2ecf20Sopenharmony_ci goto error_clk_put; 21718c2ecf20Sopenharmony_ci } 21728c2ecf20Sopenharmony_ci 21738c2ecf20Sopenharmony_ci ret = register_netdev(ndev); 21748c2ecf20Sopenharmony_ci if (ret) { 21758c2ecf20Sopenharmony_ci pr_err("%s: ERROR %i registering the device\n", __func__, ret); 21768c2ecf20Sopenharmony_ci goto error_mdio_unregister; 21778c2ecf20Sopenharmony_ci } 21788c2ecf20Sopenharmony_ci 21798c2ecf20Sopenharmony_ci sxgbe_check_ether_addr(priv); 21808c2ecf20Sopenharmony_ci 21818c2ecf20Sopenharmony_ci return priv; 21828c2ecf20Sopenharmony_ci 21838c2ecf20Sopenharmony_cierror_mdio_unregister: 21848c2ecf20Sopenharmony_ci sxgbe_mdio_unregister(ndev); 21858c2ecf20Sopenharmony_cierror_clk_put: 21868c2ecf20Sopenharmony_ci clk_put(priv->sxgbe_clk); 21878c2ecf20Sopenharmony_cierror_napi_del: 21888c2ecf20Sopenharmony_ci netif_napi_del(&priv->napi); 21898c2ecf20Sopenharmony_cierror_free_hw: 21908c2ecf20Sopenharmony_ci kfree(priv->hw); 21918c2ecf20Sopenharmony_cierror_free_netdev: 21928c2ecf20Sopenharmony_ci free_netdev(ndev); 21938c2ecf20Sopenharmony_ci 21948c2ecf20Sopenharmony_ci return NULL; 21958c2ecf20Sopenharmony_ci} 21968c2ecf20Sopenharmony_ci 21978c2ecf20Sopenharmony_ci/** 21988c2ecf20Sopenharmony_ci * sxgbe_drv_remove 21998c2ecf20Sopenharmony_ci * @ndev: net device pointer 22008c2ecf20Sopenharmony_ci * Description: this function resets the TX/RX processes, disables the MAC RX/TX 22018c2ecf20Sopenharmony_ci * changes the link status, releases the DMA descriptor rings. 22028c2ecf20Sopenharmony_ci */ 22038c2ecf20Sopenharmony_ciint sxgbe_drv_remove(struct net_device *ndev) 22048c2ecf20Sopenharmony_ci{ 22058c2ecf20Sopenharmony_ci struct sxgbe_priv_data *priv = netdev_priv(ndev); 22068c2ecf20Sopenharmony_ci u8 queue_num; 22078c2ecf20Sopenharmony_ci 22088c2ecf20Sopenharmony_ci netdev_info(ndev, "%s: removing driver\n", __func__); 22098c2ecf20Sopenharmony_ci 22108c2ecf20Sopenharmony_ci SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num) { 22118c2ecf20Sopenharmony_ci priv->hw->mac->disable_rxqueue(priv->ioaddr, queue_num); 22128c2ecf20Sopenharmony_ci } 22138c2ecf20Sopenharmony_ci 22148c2ecf20Sopenharmony_ci priv->hw->dma->stop_rx(priv->ioaddr, SXGBE_RX_QUEUES); 22158c2ecf20Sopenharmony_ci priv->hw->dma->stop_tx(priv->ioaddr, SXGBE_TX_QUEUES); 22168c2ecf20Sopenharmony_ci 22178c2ecf20Sopenharmony_ci priv->hw->mac->enable_tx(priv->ioaddr, false); 22188c2ecf20Sopenharmony_ci priv->hw->mac->enable_rx(priv->ioaddr, false); 22198c2ecf20Sopenharmony_ci 22208c2ecf20Sopenharmony_ci unregister_netdev(ndev); 22218c2ecf20Sopenharmony_ci 22228c2ecf20Sopenharmony_ci sxgbe_mdio_unregister(ndev); 22238c2ecf20Sopenharmony_ci 22248c2ecf20Sopenharmony_ci clk_put(priv->sxgbe_clk); 22258c2ecf20Sopenharmony_ci 22268c2ecf20Sopenharmony_ci netif_napi_del(&priv->napi); 22278c2ecf20Sopenharmony_ci 22288c2ecf20Sopenharmony_ci kfree(priv->hw); 22298c2ecf20Sopenharmony_ci 22308c2ecf20Sopenharmony_ci free_netdev(ndev); 22318c2ecf20Sopenharmony_ci 22328c2ecf20Sopenharmony_ci return 0; 22338c2ecf20Sopenharmony_ci} 22348c2ecf20Sopenharmony_ci 22358c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 22368c2ecf20Sopenharmony_ciint sxgbe_suspend(struct net_device *ndev) 22378c2ecf20Sopenharmony_ci{ 22388c2ecf20Sopenharmony_ci return 0; 22398c2ecf20Sopenharmony_ci} 22408c2ecf20Sopenharmony_ci 22418c2ecf20Sopenharmony_ciint sxgbe_resume(struct net_device *ndev) 22428c2ecf20Sopenharmony_ci{ 22438c2ecf20Sopenharmony_ci return 0; 22448c2ecf20Sopenharmony_ci} 22458c2ecf20Sopenharmony_ci 22468c2ecf20Sopenharmony_ciint sxgbe_freeze(struct net_device *ndev) 22478c2ecf20Sopenharmony_ci{ 22488c2ecf20Sopenharmony_ci return -ENOSYS; 22498c2ecf20Sopenharmony_ci} 22508c2ecf20Sopenharmony_ci 22518c2ecf20Sopenharmony_ciint sxgbe_restore(struct net_device *ndev) 22528c2ecf20Sopenharmony_ci{ 22538c2ecf20Sopenharmony_ci return -ENOSYS; 22548c2ecf20Sopenharmony_ci} 22558c2ecf20Sopenharmony_ci#endif /* CONFIG_PM */ 22568c2ecf20Sopenharmony_ci 22578c2ecf20Sopenharmony_ci/* Driver is configured as Platform driver */ 22588c2ecf20Sopenharmony_cistatic int __init sxgbe_init(void) 22598c2ecf20Sopenharmony_ci{ 22608c2ecf20Sopenharmony_ci int ret; 22618c2ecf20Sopenharmony_ci 22628c2ecf20Sopenharmony_ci ret = sxgbe_register_platform(); 22638c2ecf20Sopenharmony_ci if (ret) 22648c2ecf20Sopenharmony_ci goto err; 22658c2ecf20Sopenharmony_ci return 0; 22668c2ecf20Sopenharmony_cierr: 22678c2ecf20Sopenharmony_ci pr_err("driver registration failed\n"); 22688c2ecf20Sopenharmony_ci return ret; 22698c2ecf20Sopenharmony_ci} 22708c2ecf20Sopenharmony_ci 22718c2ecf20Sopenharmony_cistatic void __exit sxgbe_exit(void) 22728c2ecf20Sopenharmony_ci{ 22738c2ecf20Sopenharmony_ci sxgbe_unregister_platform(); 22748c2ecf20Sopenharmony_ci} 22758c2ecf20Sopenharmony_ci 22768c2ecf20Sopenharmony_cimodule_init(sxgbe_init); 22778c2ecf20Sopenharmony_cimodule_exit(sxgbe_exit); 22788c2ecf20Sopenharmony_ci 22798c2ecf20Sopenharmony_ci#ifndef MODULE 22808c2ecf20Sopenharmony_cistatic int __init sxgbe_cmdline_opt(char *str) 22818c2ecf20Sopenharmony_ci{ 22828c2ecf20Sopenharmony_ci char *opt; 22838c2ecf20Sopenharmony_ci 22848c2ecf20Sopenharmony_ci if (!str || !*str) 22858c2ecf20Sopenharmony_ci return 1; 22868c2ecf20Sopenharmony_ci while ((opt = strsep(&str, ",")) != NULL) { 22878c2ecf20Sopenharmony_ci if (!strncmp(opt, "eee_timer:", 10)) { 22888c2ecf20Sopenharmony_ci if (kstrtoint(opt + 10, 0, &eee_timer)) 22898c2ecf20Sopenharmony_ci goto err; 22908c2ecf20Sopenharmony_ci } 22918c2ecf20Sopenharmony_ci } 22928c2ecf20Sopenharmony_ci return 1; 22938c2ecf20Sopenharmony_ci 22948c2ecf20Sopenharmony_cierr: 22958c2ecf20Sopenharmony_ci pr_err("%s: ERROR broken module parameter conversion\n", __func__); 22968c2ecf20Sopenharmony_ci return 1; 22978c2ecf20Sopenharmony_ci} 22988c2ecf20Sopenharmony_ci 22998c2ecf20Sopenharmony_ci__setup("sxgbeeth=", sxgbe_cmdline_opt); 23008c2ecf20Sopenharmony_ci#endif /* MODULE */ 23018c2ecf20Sopenharmony_ci 23028c2ecf20Sopenharmony_ci 23038c2ecf20Sopenharmony_ci 23048c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Samsung 10G/2.5G/1G Ethernet PLATFORM driver"); 23058c2ecf20Sopenharmony_ci 23068c2ecf20Sopenharmony_ciMODULE_PARM_DESC(debug, "Message Level (-1: default, 0: no output, 16: all)"); 23078c2ecf20Sopenharmony_ciMODULE_PARM_DESC(eee_timer, "EEE-LPI Default LS timer value"); 23088c2ecf20Sopenharmony_ci 23098c2ecf20Sopenharmony_ciMODULE_AUTHOR("Siva Reddy Kallam <siva.kallam@samsung.com>"); 23108c2ecf20Sopenharmony_ciMODULE_AUTHOR("ByungHo An <bh74.an@samsung.com>"); 23118c2ecf20Sopenharmony_ciMODULE_AUTHOR("Girish K S <ks.giri@samsung.com>"); 23128c2ecf20Sopenharmony_ciMODULE_AUTHOR("Vipul Pandya <vipul.pandya@samsung.com>"); 23138c2ecf20Sopenharmony_ci 23148c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 2315