158da0cfaSVoon Weifeng // SPDX-License-Identifier: GPL-2.0 258da0cfaSVoon Weifeng /* Copyright (c) 2020, Intel Corporation 358da0cfaSVoon Weifeng */ 458da0cfaSVoon Weifeng 558da0cfaSVoon Weifeng #include <linux/clk-provider.h> 658da0cfaSVoon Weifeng #include <linux/pci.h> 758da0cfaSVoon Weifeng #include <linux/dmi.h> 8b9663b7cSVoon Weifeng #include "dwmac-intel.h" 9b4c5f83aSRusaimi Amira Ruslan #include "dwmac4.h" 1058da0cfaSVoon Weifeng #include "stmmac.h" 11341f67e4STan Tee Min #include "stmmac_ptp.h" 1258da0cfaSVoon Weifeng 13b9663b7cSVoon Weifeng struct intel_priv_data { 14b9663b7cSVoon Weifeng int mdio_adhoc_addr; /* mdio address for serdes & etc */ 151c137d47SWong Vee Khee unsigned long crossts_adj; 1676da35dcSWong, Vee Khee bool is_pse; 17b9663b7cSVoon Weifeng }; 18b9663b7cSVoon Weifeng 1958da0cfaSVoon Weifeng /* This struct is used to associate PCI Function of MAC controller on a board, 2058da0cfaSVoon Weifeng * discovered via DMI, with the address of PHY connected to the MAC. The 2158da0cfaSVoon Weifeng * negative value of the address means that MAC controller is not connected 2258da0cfaSVoon Weifeng * with PHY. 2358da0cfaSVoon Weifeng */ 2458da0cfaSVoon Weifeng struct stmmac_pci_func_data { 2558da0cfaSVoon Weifeng unsigned int func; 2658da0cfaSVoon Weifeng int phy_addr; 2758da0cfaSVoon Weifeng }; 2858da0cfaSVoon Weifeng 2958da0cfaSVoon Weifeng struct stmmac_pci_dmi_data { 3058da0cfaSVoon Weifeng const struct stmmac_pci_func_data *func; 3158da0cfaSVoon Weifeng size_t nfuncs; 3258da0cfaSVoon Weifeng }; 3358da0cfaSVoon Weifeng 3458da0cfaSVoon Weifeng struct stmmac_pci_info { 3558da0cfaSVoon Weifeng int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat); 3658da0cfaSVoon Weifeng }; 3758da0cfaSVoon Weifeng 3858da0cfaSVoon Weifeng static int stmmac_pci_find_phy_addr(struct pci_dev *pdev, 3958da0cfaSVoon Weifeng const struct dmi_system_id *dmi_list) 4058da0cfaSVoon Weifeng { 4158da0cfaSVoon Weifeng const struct stmmac_pci_func_data *func_data; 4258da0cfaSVoon Weifeng const struct stmmac_pci_dmi_data *dmi_data; 4358da0cfaSVoon Weifeng const struct dmi_system_id *dmi_id; 4458da0cfaSVoon Weifeng int func = PCI_FUNC(pdev->devfn); 4558da0cfaSVoon Weifeng size_t n; 4658da0cfaSVoon Weifeng 4758da0cfaSVoon Weifeng dmi_id = dmi_first_match(dmi_list); 4858da0cfaSVoon Weifeng if (!dmi_id) 4958da0cfaSVoon Weifeng return -ENODEV; 5058da0cfaSVoon Weifeng 5158da0cfaSVoon Weifeng dmi_data = dmi_id->driver_data; 5258da0cfaSVoon Weifeng func_data = dmi_data->func; 5358da0cfaSVoon Weifeng 5458da0cfaSVoon Weifeng for (n = 0; n < dmi_data->nfuncs; n++, func_data++) 5558da0cfaSVoon Weifeng if (func_data->func == func) 5658da0cfaSVoon Weifeng return func_data->phy_addr; 5758da0cfaSVoon Weifeng 5858da0cfaSVoon Weifeng return -ENODEV; 5958da0cfaSVoon Weifeng } 6058da0cfaSVoon Weifeng 61b9663b7cSVoon Weifeng static int serdes_status_poll(struct stmmac_priv *priv, int phyaddr, 62b9663b7cSVoon Weifeng int phyreg, u32 mask, u32 val) 63b9663b7cSVoon Weifeng { 64b9663b7cSVoon Weifeng unsigned int retries = 10; 65b9663b7cSVoon Weifeng int val_rd; 66b9663b7cSVoon Weifeng 67b9663b7cSVoon Weifeng do { 68b9663b7cSVoon Weifeng val_rd = mdiobus_read(priv->mii, phyaddr, phyreg); 69b9663b7cSVoon Weifeng if ((val_rd & mask) == (val & mask)) 70b9663b7cSVoon Weifeng return 0; 71b9663b7cSVoon Weifeng udelay(POLL_DELAY_US); 72b9663b7cSVoon Weifeng } while (--retries); 73b9663b7cSVoon Weifeng 74b9663b7cSVoon Weifeng return -ETIMEDOUT; 75b9663b7cSVoon Weifeng } 76b9663b7cSVoon Weifeng 77b9663b7cSVoon Weifeng static int intel_serdes_powerup(struct net_device *ndev, void *priv_data) 78b9663b7cSVoon Weifeng { 79b9663b7cSVoon Weifeng struct intel_priv_data *intel_priv = priv_data; 80b9663b7cSVoon Weifeng struct stmmac_priv *priv = netdev_priv(ndev); 81b9663b7cSVoon Weifeng int serdes_phy_addr = 0; 82b9663b7cSVoon Weifeng u32 data = 0; 83b9663b7cSVoon Weifeng 84b9663b7cSVoon Weifeng if (!intel_priv->mdio_adhoc_addr) 85b9663b7cSVoon Weifeng return 0; 86b9663b7cSVoon Weifeng 87b9663b7cSVoon Weifeng serdes_phy_addr = intel_priv->mdio_adhoc_addr; 88b9663b7cSVoon Weifeng 8946682cb8SVoon Weifeng /* Set the serdes rate and the PCLK rate */ 9046682cb8SVoon Weifeng data = mdiobus_read(priv->mii, serdes_phy_addr, 9146682cb8SVoon Weifeng SERDES_GCR0); 9246682cb8SVoon Weifeng 9346682cb8SVoon Weifeng data &= ~SERDES_RATE_MASK; 9446682cb8SVoon Weifeng data &= ~SERDES_PCLK_MASK; 9546682cb8SVoon Weifeng 9646682cb8SVoon Weifeng if (priv->plat->max_speed == 2500) 9746682cb8SVoon Weifeng data |= SERDES_RATE_PCIE_GEN2 << SERDES_RATE_PCIE_SHIFT | 9846682cb8SVoon Weifeng SERDES_PCLK_37p5MHZ << SERDES_PCLK_SHIFT; 9946682cb8SVoon Weifeng else 10046682cb8SVoon Weifeng data |= SERDES_RATE_PCIE_GEN1 << SERDES_RATE_PCIE_SHIFT | 10146682cb8SVoon Weifeng SERDES_PCLK_70MHZ << SERDES_PCLK_SHIFT; 10246682cb8SVoon Weifeng 10346682cb8SVoon Weifeng mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data); 10446682cb8SVoon Weifeng 105b9663b7cSVoon Weifeng /* assert clk_req */ 106ccacb703SAndy Shevchenko data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0); 107b9663b7cSVoon Weifeng data |= SERDES_PLL_CLK; 108ccacb703SAndy Shevchenko mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data); 109b9663b7cSVoon Weifeng 110b9663b7cSVoon Weifeng /* check for clk_ack assertion */ 111b9663b7cSVoon Weifeng data = serdes_status_poll(priv, serdes_phy_addr, 112b9663b7cSVoon Weifeng SERDES_GSR0, 113b9663b7cSVoon Weifeng SERDES_PLL_CLK, 114b9663b7cSVoon Weifeng SERDES_PLL_CLK); 115b9663b7cSVoon Weifeng 116b9663b7cSVoon Weifeng if (data) { 117b9663b7cSVoon Weifeng dev_err(priv->device, "Serdes PLL clk request timeout\n"); 118b9663b7cSVoon Weifeng return data; 119b9663b7cSVoon Weifeng } 120b9663b7cSVoon Weifeng 121b9663b7cSVoon Weifeng /* assert lane reset */ 122ccacb703SAndy Shevchenko data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0); 123b9663b7cSVoon Weifeng data |= SERDES_RST; 124ccacb703SAndy Shevchenko mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data); 125b9663b7cSVoon Weifeng 126b9663b7cSVoon Weifeng /* check for assert lane reset reflection */ 127b9663b7cSVoon Weifeng data = serdes_status_poll(priv, serdes_phy_addr, 128b9663b7cSVoon Weifeng SERDES_GSR0, 129b9663b7cSVoon Weifeng SERDES_RST, 130b9663b7cSVoon Weifeng SERDES_RST); 131b9663b7cSVoon Weifeng 132b9663b7cSVoon Weifeng if (data) { 133b9663b7cSVoon Weifeng dev_err(priv->device, "Serdes assert lane reset timeout\n"); 134b9663b7cSVoon Weifeng return data; 135b9663b7cSVoon Weifeng } 136b9663b7cSVoon Weifeng 137b9663b7cSVoon Weifeng /* move power state to P0 */ 138ccacb703SAndy Shevchenko data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0); 139b9663b7cSVoon Weifeng 140b9663b7cSVoon Weifeng data &= ~SERDES_PWR_ST_MASK; 141b9663b7cSVoon Weifeng data |= SERDES_PWR_ST_P0 << SERDES_PWR_ST_SHIFT; 142b9663b7cSVoon Weifeng 143ccacb703SAndy Shevchenko mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data); 144b9663b7cSVoon Weifeng 145b9663b7cSVoon Weifeng /* Check for P0 state */ 146b9663b7cSVoon Weifeng data = serdes_status_poll(priv, serdes_phy_addr, 147b9663b7cSVoon Weifeng SERDES_GSR0, 148b9663b7cSVoon Weifeng SERDES_PWR_ST_MASK, 149b9663b7cSVoon Weifeng SERDES_PWR_ST_P0 << SERDES_PWR_ST_SHIFT); 150b9663b7cSVoon Weifeng 151b9663b7cSVoon Weifeng if (data) { 152b9663b7cSVoon Weifeng dev_err(priv->device, "Serdes power state P0 timeout.\n"); 153b9663b7cSVoon Weifeng return data; 154b9663b7cSVoon Weifeng } 155b9663b7cSVoon Weifeng 156017d6250SVoon Weifeng /* PSE only - ungate SGMII PHY Rx Clock */ 157017d6250SVoon Weifeng if (intel_priv->is_pse) 158017d6250SVoon Weifeng mdiobus_modify(priv->mii, serdes_phy_addr, SERDES_GCR0, 159017d6250SVoon Weifeng 0, SERDES_PHY_RX_CLK); 160017d6250SVoon Weifeng 161b9663b7cSVoon Weifeng return 0; 162b9663b7cSVoon Weifeng } 163b9663b7cSVoon Weifeng 164b9663b7cSVoon Weifeng static void intel_serdes_powerdown(struct net_device *ndev, void *intel_data) 165b9663b7cSVoon Weifeng { 166b9663b7cSVoon Weifeng struct intel_priv_data *intel_priv = intel_data; 167b9663b7cSVoon Weifeng struct stmmac_priv *priv = netdev_priv(ndev); 168b9663b7cSVoon Weifeng int serdes_phy_addr = 0; 169b9663b7cSVoon Weifeng u32 data = 0; 170b9663b7cSVoon Weifeng 171b9663b7cSVoon Weifeng if (!intel_priv->mdio_adhoc_addr) 172b9663b7cSVoon Weifeng return; 173b9663b7cSVoon Weifeng 174b9663b7cSVoon Weifeng serdes_phy_addr = intel_priv->mdio_adhoc_addr; 175b9663b7cSVoon Weifeng 176017d6250SVoon Weifeng /* PSE only - gate SGMII PHY Rx Clock */ 177017d6250SVoon Weifeng if (intel_priv->is_pse) 178017d6250SVoon Weifeng mdiobus_modify(priv->mii, serdes_phy_addr, SERDES_GCR0, 179017d6250SVoon Weifeng SERDES_PHY_RX_CLK, 0); 180017d6250SVoon Weifeng 181b9663b7cSVoon Weifeng /* move power state to P3 */ 182ccacb703SAndy Shevchenko data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0); 183b9663b7cSVoon Weifeng 184b9663b7cSVoon Weifeng data &= ~SERDES_PWR_ST_MASK; 185b9663b7cSVoon Weifeng data |= SERDES_PWR_ST_P3 << SERDES_PWR_ST_SHIFT; 186b9663b7cSVoon Weifeng 187ccacb703SAndy Shevchenko mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data); 188b9663b7cSVoon Weifeng 189b9663b7cSVoon Weifeng /* Check for P3 state */ 190b9663b7cSVoon Weifeng data = serdes_status_poll(priv, serdes_phy_addr, 191b9663b7cSVoon Weifeng SERDES_GSR0, 192b9663b7cSVoon Weifeng SERDES_PWR_ST_MASK, 193b9663b7cSVoon Weifeng SERDES_PWR_ST_P3 << SERDES_PWR_ST_SHIFT); 194b9663b7cSVoon Weifeng 195b9663b7cSVoon Weifeng if (data) { 196b9663b7cSVoon Weifeng dev_err(priv->device, "Serdes power state P3 timeout\n"); 197b9663b7cSVoon Weifeng return; 198b9663b7cSVoon Weifeng } 199b9663b7cSVoon Weifeng 200b9663b7cSVoon Weifeng /* de-assert clk_req */ 201ccacb703SAndy Shevchenko data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0); 202b9663b7cSVoon Weifeng data &= ~SERDES_PLL_CLK; 203ccacb703SAndy Shevchenko mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data); 204b9663b7cSVoon Weifeng 205b9663b7cSVoon Weifeng /* check for clk_ack de-assert */ 206b9663b7cSVoon Weifeng data = serdes_status_poll(priv, serdes_phy_addr, 207b9663b7cSVoon Weifeng SERDES_GSR0, 208b9663b7cSVoon Weifeng SERDES_PLL_CLK, 209b9663b7cSVoon Weifeng (u32)~SERDES_PLL_CLK); 210b9663b7cSVoon Weifeng 211b9663b7cSVoon Weifeng if (data) { 212b9663b7cSVoon Weifeng dev_err(priv->device, "Serdes PLL clk de-assert timeout\n"); 213b9663b7cSVoon Weifeng return; 214b9663b7cSVoon Weifeng } 215b9663b7cSVoon Weifeng 216b9663b7cSVoon Weifeng /* de-assert lane reset */ 217ccacb703SAndy Shevchenko data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0); 218b9663b7cSVoon Weifeng data &= ~SERDES_RST; 219ccacb703SAndy Shevchenko mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data); 220b9663b7cSVoon Weifeng 221b9663b7cSVoon Weifeng /* check for de-assert lane reset reflection */ 222b9663b7cSVoon Weifeng data = serdes_status_poll(priv, serdes_phy_addr, 223b9663b7cSVoon Weifeng SERDES_GSR0, 224b9663b7cSVoon Weifeng SERDES_RST, 225b9663b7cSVoon Weifeng (u32)~SERDES_RST); 226b9663b7cSVoon Weifeng 227b9663b7cSVoon Weifeng if (data) { 228b9663b7cSVoon Weifeng dev_err(priv->device, "Serdes de-assert lane reset timeout\n"); 229b9663b7cSVoon Weifeng return; 230b9663b7cSVoon Weifeng } 231b9663b7cSVoon Weifeng } 232b9663b7cSVoon Weifeng 23346682cb8SVoon Weifeng static void intel_speed_mode_2500(struct net_device *ndev, void *intel_data) 23446682cb8SVoon Weifeng { 23546682cb8SVoon Weifeng struct intel_priv_data *intel_priv = intel_data; 23646682cb8SVoon Weifeng struct stmmac_priv *priv = netdev_priv(ndev); 23746682cb8SVoon Weifeng int serdes_phy_addr = 0; 23846682cb8SVoon Weifeng u32 data = 0; 23946682cb8SVoon Weifeng 24046682cb8SVoon Weifeng serdes_phy_addr = intel_priv->mdio_adhoc_addr; 24146682cb8SVoon Weifeng 24246682cb8SVoon Weifeng /* Determine the link speed mode: 2.5Gbps/1Gbps */ 24346682cb8SVoon Weifeng data = mdiobus_read(priv->mii, serdes_phy_addr, 24446682cb8SVoon Weifeng SERDES_GCR); 24546682cb8SVoon Weifeng 24646682cb8SVoon Weifeng if (((data & SERDES_LINK_MODE_MASK) >> SERDES_LINK_MODE_SHIFT) == 24746682cb8SVoon Weifeng SERDES_LINK_MODE_2G5) { 24846682cb8SVoon Weifeng dev_info(priv->device, "Link Speed Mode: 2.5Gbps\n"); 24946682cb8SVoon Weifeng priv->plat->max_speed = 2500; 25046682cb8SVoon Weifeng priv->plat->phy_interface = PHY_INTERFACE_MODE_2500BASEX; 25146682cb8SVoon Weifeng priv->plat->mdio_bus_data->xpcs_an_inband = false; 25246682cb8SVoon Weifeng } else { 25346682cb8SVoon Weifeng priv->plat->max_speed = 1000; 25446682cb8SVoon Weifeng } 25546682cb8SVoon Weifeng } 25646682cb8SVoon Weifeng 25776da35dcSWong, Vee Khee /* Program PTP Clock Frequency for different variant of 25876da35dcSWong, Vee Khee * Intel mGBE that has slightly different GPO mapping 25976da35dcSWong, Vee Khee */ 26076da35dcSWong, Vee Khee static void intel_mgbe_ptp_clk_freq_config(void *npriv) 26176da35dcSWong, Vee Khee { 26276da35dcSWong, Vee Khee struct stmmac_priv *priv = (struct stmmac_priv *)npriv; 26376da35dcSWong, Vee Khee struct intel_priv_data *intel_priv; 26476da35dcSWong, Vee Khee u32 gpio_value; 26576da35dcSWong, Vee Khee 26676da35dcSWong, Vee Khee intel_priv = (struct intel_priv_data *)priv->plat->bsp_priv; 26776da35dcSWong, Vee Khee 26876da35dcSWong, Vee Khee gpio_value = readl(priv->ioaddr + GMAC_GPIO_STATUS); 26976da35dcSWong, Vee Khee 27076da35dcSWong, Vee Khee if (intel_priv->is_pse) { 27176da35dcSWong, Vee Khee /* For PSE GbE, use 200MHz */ 27276da35dcSWong, Vee Khee gpio_value &= ~PSE_PTP_CLK_FREQ_MASK; 27376da35dcSWong, Vee Khee gpio_value |= PSE_PTP_CLK_FREQ_200MHZ; 27476da35dcSWong, Vee Khee } else { 27576da35dcSWong, Vee Khee /* For PCH GbE, use 200MHz */ 27676da35dcSWong, Vee Khee gpio_value &= ~PCH_PTP_CLK_FREQ_MASK; 27776da35dcSWong, Vee Khee gpio_value |= PCH_PTP_CLK_FREQ_200MHZ; 27876da35dcSWong, Vee Khee } 27976da35dcSWong, Vee Khee 28076da35dcSWong, Vee Khee writel(gpio_value, priv->ioaddr + GMAC_GPIO_STATUS); 28176da35dcSWong, Vee Khee } 28276da35dcSWong, Vee Khee 283341f67e4STan Tee Min static void get_arttime(struct mii_bus *mii, int intel_adhoc_addr, 284341f67e4STan Tee Min u64 *art_time) 285341f67e4STan Tee Min { 286341f67e4STan Tee Min u64 ns; 287341f67e4STan Tee Min 288341f67e4STan Tee Min ns = mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE3); 289341f67e4STan Tee Min ns <<= GMAC4_ART_TIME_SHIFT; 290341f67e4STan Tee Min ns |= mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE2); 291341f67e4STan Tee Min ns <<= GMAC4_ART_TIME_SHIFT; 292341f67e4STan Tee Min ns |= mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE1); 293341f67e4STan Tee Min ns <<= GMAC4_ART_TIME_SHIFT; 294341f67e4STan Tee Min ns |= mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE0); 295341f67e4STan Tee Min 296341f67e4STan Tee Min *art_time = ns; 297341f67e4STan Tee Min } 298341f67e4STan Tee Min 29976c16d3eSWong Vee Khee static int stmmac_cross_ts_isr(struct stmmac_priv *priv) 30076c16d3eSWong Vee Khee { 30176c16d3eSWong Vee Khee return (readl(priv->ioaddr + GMAC_INT_STATUS) & GMAC_INT_TSIE); 30276c16d3eSWong Vee Khee } 30376c16d3eSWong Vee Khee 304341f67e4STan Tee Min static int intel_crosststamp(ktime_t *device, 305341f67e4STan Tee Min struct system_counterval_t *system, 306341f67e4STan Tee Min void *ctx) 307341f67e4STan Tee Min { 308341f67e4STan Tee Min struct intel_priv_data *intel_priv; 309341f67e4STan Tee Min 310341f67e4STan Tee Min struct stmmac_priv *priv = (struct stmmac_priv *)ctx; 311341f67e4STan Tee Min void __iomem *ptpaddr = priv->ptpaddr; 312341f67e4STan Tee Min void __iomem *ioaddr = priv->hw->pcsr; 313341f67e4STan Tee Min unsigned long flags; 314341f67e4STan Tee Min u64 art_time = 0; 315341f67e4STan Tee Min u64 ptp_time = 0; 316341f67e4STan Tee Min u32 num_snapshot; 317341f67e4STan Tee Min u32 gpio_value; 318341f67e4STan Tee Min u32 acr_value; 319341f67e4STan Tee Min int i; 320341f67e4STan Tee Min 321341f67e4STan Tee Min if (!boot_cpu_has(X86_FEATURE_ART)) 322341f67e4STan Tee Min return -EOPNOTSUPP; 323341f67e4STan Tee Min 324341f67e4STan Tee Min intel_priv = priv->plat->bsp_priv; 325341f67e4STan Tee Min 326f4da5652STan Tee Min /* Both internal crosstimestamping and external triggered event 327f4da5652STan Tee Min * timestamping cannot be run concurrently. 328f4da5652STan Tee Min */ 329f4da5652STan Tee Min if (priv->plat->ext_snapshot_en) 330f4da5652STan Tee Min return -EBUSY; 331f4da5652STan Tee Min 33276c16d3eSWong Vee Khee priv->plat->int_snapshot_en = 1; 33376c16d3eSWong Vee Khee 334f4da5652STan Tee Min mutex_lock(&priv->aux_ts_lock); 335341f67e4STan Tee Min /* Enable Internal snapshot trigger */ 336341f67e4STan Tee Min acr_value = readl(ptpaddr + PTP_ACR); 337341f67e4STan Tee Min acr_value &= ~PTP_ACR_MASK; 338341f67e4STan Tee Min switch (priv->plat->int_snapshot_num) { 339341f67e4STan Tee Min case AUX_SNAPSHOT0: 340341f67e4STan Tee Min acr_value |= PTP_ACR_ATSEN0; 341341f67e4STan Tee Min break; 342341f67e4STan Tee Min case AUX_SNAPSHOT1: 343341f67e4STan Tee Min acr_value |= PTP_ACR_ATSEN1; 344341f67e4STan Tee Min break; 345341f67e4STan Tee Min case AUX_SNAPSHOT2: 346341f67e4STan Tee Min acr_value |= PTP_ACR_ATSEN2; 347341f67e4STan Tee Min break; 348341f67e4STan Tee Min case AUX_SNAPSHOT3: 349341f67e4STan Tee Min acr_value |= PTP_ACR_ATSEN3; 350341f67e4STan Tee Min break; 351341f67e4STan Tee Min default: 35253e35ebbSDan Carpenter mutex_unlock(&priv->aux_ts_lock); 35376c16d3eSWong Vee Khee priv->plat->int_snapshot_en = 0; 354341f67e4STan Tee Min return -EINVAL; 355341f67e4STan Tee Min } 356341f67e4STan Tee Min writel(acr_value, ptpaddr + PTP_ACR); 357341f67e4STan Tee Min 358341f67e4STan Tee Min /* Clear FIFO */ 359341f67e4STan Tee Min acr_value = readl(ptpaddr + PTP_ACR); 360341f67e4STan Tee Min acr_value |= PTP_ACR_ATSFC; 361341f67e4STan Tee Min writel(acr_value, ptpaddr + PTP_ACR); 362f4da5652STan Tee Min /* Release the mutex */ 363f4da5652STan Tee Min mutex_unlock(&priv->aux_ts_lock); 364341f67e4STan Tee Min 365341f67e4STan Tee Min /* Trigger Internal snapshot signal 366341f67e4STan Tee Min * Create a rising edge by just toggle the GPO1 to low 367341f67e4STan Tee Min * and back to high. 368341f67e4STan Tee Min */ 369341f67e4STan Tee Min gpio_value = readl(ioaddr + GMAC_GPIO_STATUS); 370341f67e4STan Tee Min gpio_value &= ~GMAC_GPO1; 371341f67e4STan Tee Min writel(gpio_value, ioaddr + GMAC_GPIO_STATUS); 372341f67e4STan Tee Min gpio_value |= GMAC_GPO1; 373341f67e4STan Tee Min writel(gpio_value, ioaddr + GMAC_GPIO_STATUS); 374341f67e4STan Tee Min 37576c16d3eSWong Vee Khee /* Time sync done Indication - Interrupt method */ 37676c16d3eSWong Vee Khee if (!wait_event_interruptible_timeout(priv->tstamp_busy_wait, 37776c16d3eSWong Vee Khee stmmac_cross_ts_isr(priv), 37876c16d3eSWong Vee Khee HZ / 100)) { 37976c16d3eSWong Vee Khee priv->plat->int_snapshot_en = 0; 38076c16d3eSWong Vee Khee return -ETIMEDOUT; 381341f67e4STan Tee Min } 382341f67e4STan Tee Min 383341f67e4STan Tee Min num_snapshot = (readl(ioaddr + GMAC_TIMESTAMP_STATUS) & 384341f67e4STan Tee Min GMAC_TIMESTAMP_ATSNS_MASK) >> 385341f67e4STan Tee Min GMAC_TIMESTAMP_ATSNS_SHIFT; 386341f67e4STan Tee Min 387341f67e4STan Tee Min /* Repeat until the timestamps are from the FIFO last segment */ 388341f67e4STan Tee Min for (i = 0; i < num_snapshot; i++) { 389642436a1SYannick Vignon read_lock_irqsave(&priv->ptp_lock, flags); 390341f67e4STan Tee Min stmmac_get_ptptime(priv, ptpaddr, &ptp_time); 391341f67e4STan Tee Min *device = ns_to_ktime(ptp_time); 392642436a1SYannick Vignon read_unlock_irqrestore(&priv->ptp_lock, flags); 393341f67e4STan Tee Min get_arttime(priv->mii, intel_priv->mdio_adhoc_addr, &art_time); 394341f67e4STan Tee Min *system = convert_art_to_tsc(art_time); 395341f67e4STan Tee Min } 396341f67e4STan Tee Min 3971c137d47SWong Vee Khee system->cycles *= intel_priv->crossts_adj; 39876c16d3eSWong Vee Khee priv->plat->int_snapshot_en = 0; 3991c137d47SWong Vee Khee 400341f67e4STan Tee Min return 0; 401341f67e4STan Tee Min } 402341f67e4STan Tee Min 4031c137d47SWong Vee Khee static void intel_mgbe_pse_crossts_adj(struct intel_priv_data *intel_priv, 4041c137d47SWong Vee Khee int base) 4051c137d47SWong Vee Khee { 4061c137d47SWong Vee Khee if (boot_cpu_has(X86_FEATURE_ART)) { 4071c137d47SWong Vee Khee unsigned int art_freq; 4081c137d47SWong Vee Khee 4091c137d47SWong Vee Khee /* On systems that support ART, ART frequency can be obtained 4101c137d47SWong Vee Khee * from ECX register of CPUID leaf (0x15). 4111c137d47SWong Vee Khee */ 4121c137d47SWong Vee Khee art_freq = cpuid_ecx(ART_CPUID_LEAF); 4131c137d47SWong Vee Khee do_div(art_freq, base); 4141c137d47SWong Vee Khee intel_priv->crossts_adj = art_freq; 4151c137d47SWong Vee Khee } 4161c137d47SWong Vee Khee } 4171c137d47SWong Vee Khee 41858da0cfaSVoon Weifeng static void common_default_data(struct plat_stmmacenet_data *plat) 41958da0cfaSVoon Weifeng { 42058da0cfaSVoon Weifeng plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */ 42158da0cfaSVoon Weifeng plat->has_gmac = 1; 42258da0cfaSVoon Weifeng plat->force_sf_dma_mode = 1; 42358da0cfaSVoon Weifeng 42458da0cfaSVoon Weifeng plat->mdio_bus_data->needs_reset = true; 42558da0cfaSVoon Weifeng 42658da0cfaSVoon Weifeng /* Set default value for multicast hash bins */ 42758da0cfaSVoon Weifeng plat->multicast_filter_bins = HASH_TABLE_SIZE; 42858da0cfaSVoon Weifeng 42958da0cfaSVoon Weifeng /* Set default value for unicast filter entries */ 43058da0cfaSVoon Weifeng plat->unicast_filter_entries = 1; 43158da0cfaSVoon Weifeng 43258da0cfaSVoon Weifeng /* Set the maxmtu to a default of JUMBO_LEN */ 43358da0cfaSVoon Weifeng plat->maxmtu = JUMBO_LEN; 43458da0cfaSVoon Weifeng 43558da0cfaSVoon Weifeng /* Set default number of RX and TX queues to use */ 43658da0cfaSVoon Weifeng plat->tx_queues_to_use = 1; 43758da0cfaSVoon Weifeng plat->rx_queues_to_use = 1; 43858da0cfaSVoon Weifeng 43958da0cfaSVoon Weifeng /* Disable Priority config by default */ 44058da0cfaSVoon Weifeng plat->tx_queues_cfg[0].use_prio = false; 44158da0cfaSVoon Weifeng plat->rx_queues_cfg[0].use_prio = false; 44258da0cfaSVoon Weifeng 44358da0cfaSVoon Weifeng /* Disable RX queues routing by default */ 44458da0cfaSVoon Weifeng plat->rx_queues_cfg[0].pkt_route = 0x0; 44558da0cfaSVoon Weifeng } 44658da0cfaSVoon Weifeng 44758da0cfaSVoon Weifeng static int intel_mgbe_common_data(struct pci_dev *pdev, 44858da0cfaSVoon Weifeng struct plat_stmmacenet_data *plat) 44958da0cfaSVoon Weifeng { 45072edaf39SOng Boon Leong struct fwnode_handle *fwnode; 4518eb37ab7SWong Vee Khee char clk_name[20]; 45209f012e6SAndy Shevchenko int ret; 45358da0cfaSVoon Weifeng int i; 45458da0cfaSVoon Weifeng 45520e07e2cSWong Vee Khee plat->pdev = pdev; 456bff6f1dbSVoon Weifeng plat->phy_addr = -1; 45758da0cfaSVoon Weifeng plat->clk_csr = 5; 45858da0cfaSVoon Weifeng plat->has_gmac = 0; 45958da0cfaSVoon Weifeng plat->has_gmac4 = 1; 46058da0cfaSVoon Weifeng plat->force_sf_dma_mode = 0; 46158da0cfaSVoon Weifeng plat->tso_en = 1; 462309efe6eSBartosz Golaszewski plat->flags |= STMMAC_FLAG_SPH_DISABLE; 46358da0cfaSVoon Weifeng 464e80fe71bSMichael Sit Wei Hong /* Multiplying factor to the clk_eee_i clock time 465e80fe71bSMichael Sit Wei Hong * period to make it closer to 100 ns. This value 466e80fe71bSMichael Sit Wei Hong * should be programmed such that the clk_eee_time_period * 467e80fe71bSMichael Sit Wei Hong * (MULT_FACT_100NS + 1) should be within 80 ns to 120 ns 468e80fe71bSMichael Sit Wei Hong * clk_eee frequency is 19.2Mhz 469e80fe71bSMichael Sit Wei Hong * clk_eee_time_period is 52ns 470e80fe71bSMichael Sit Wei Hong * 52ns * (1 + 1) = 104ns 471e80fe71bSMichael Sit Wei Hong * MULT_FACT_100NS = 1 472e80fe71bSMichael Sit Wei Hong */ 473e80fe71bSMichael Sit Wei Hong plat->mult_fact_100ns = 1; 474e80fe71bSMichael Sit Wei Hong 47558da0cfaSVoon Weifeng plat->rx_sched_algorithm = MTL_RX_ALGORITHM_SP; 47658da0cfaSVoon Weifeng 47758da0cfaSVoon Weifeng for (i = 0; i < plat->rx_queues_to_use; i++) { 47858da0cfaSVoon Weifeng plat->rx_queues_cfg[i].mode_to_use = MTL_QUEUE_DCB; 47958da0cfaSVoon Weifeng plat->rx_queues_cfg[i].chan = i; 48058da0cfaSVoon Weifeng 48158da0cfaSVoon Weifeng /* Disable Priority config by default */ 48258da0cfaSVoon Weifeng plat->rx_queues_cfg[i].use_prio = false; 48358da0cfaSVoon Weifeng 48458da0cfaSVoon Weifeng /* Disable RX queues routing by default */ 48558da0cfaSVoon Weifeng plat->rx_queues_cfg[i].pkt_route = 0x0; 48658da0cfaSVoon Weifeng } 48758da0cfaSVoon Weifeng 48858da0cfaSVoon Weifeng for (i = 0; i < plat->tx_queues_to_use; i++) { 48958da0cfaSVoon Weifeng plat->tx_queues_cfg[i].mode_to_use = MTL_QUEUE_DCB; 49058da0cfaSVoon Weifeng 49158da0cfaSVoon Weifeng /* Disable Priority config by default */ 49258da0cfaSVoon Weifeng plat->tx_queues_cfg[i].use_prio = false; 49317cb0070SOng Boon Leong /* Default TX Q0 to use TSO and rest TXQ for TBS */ 49417cb0070SOng Boon Leong if (i > 0) 49517cb0070SOng Boon Leong plat->tx_queues_cfg[i].tbs_en = 1; 49658da0cfaSVoon Weifeng } 49758da0cfaSVoon Weifeng 49858da0cfaSVoon Weifeng /* FIFO size is 4096 bytes for 1 tx/rx queue */ 49958da0cfaSVoon Weifeng plat->tx_fifo_size = plat->tx_queues_to_use * 4096; 50058da0cfaSVoon Weifeng plat->rx_fifo_size = plat->rx_queues_to_use * 4096; 50158da0cfaSVoon Weifeng 50258da0cfaSVoon Weifeng plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WRR; 50358da0cfaSVoon Weifeng plat->tx_queues_cfg[0].weight = 0x09; 50458da0cfaSVoon Weifeng plat->tx_queues_cfg[1].weight = 0x0A; 50558da0cfaSVoon Weifeng plat->tx_queues_cfg[2].weight = 0x0B; 50658da0cfaSVoon Weifeng plat->tx_queues_cfg[3].weight = 0x0C; 50758da0cfaSVoon Weifeng plat->tx_queues_cfg[4].weight = 0x0D; 50858da0cfaSVoon Weifeng plat->tx_queues_cfg[5].weight = 0x0E; 50958da0cfaSVoon Weifeng plat->tx_queues_cfg[6].weight = 0x0F; 51058da0cfaSVoon Weifeng plat->tx_queues_cfg[7].weight = 0x10; 51158da0cfaSVoon Weifeng 51258da0cfaSVoon Weifeng plat->dma_cfg->pbl = 32; 51358da0cfaSVoon Weifeng plat->dma_cfg->pblx8 = true; 51458da0cfaSVoon Weifeng plat->dma_cfg->fixed_burst = 0; 51558da0cfaSVoon Weifeng plat->dma_cfg->mixed_burst = 0; 51658da0cfaSVoon Weifeng plat->dma_cfg->aal = 0; 517676b7ec6SMohammad Athari Bin Ismail plat->dma_cfg->dche = true; 51858da0cfaSVoon Weifeng 51958da0cfaSVoon Weifeng plat->axi = devm_kzalloc(&pdev->dev, sizeof(*plat->axi), 52058da0cfaSVoon Weifeng GFP_KERNEL); 52158da0cfaSVoon Weifeng if (!plat->axi) 52258da0cfaSVoon Weifeng return -ENOMEM; 52358da0cfaSVoon Weifeng 52458da0cfaSVoon Weifeng plat->axi->axi_lpi_en = 0; 52558da0cfaSVoon Weifeng plat->axi->axi_xit_frm = 0; 52658da0cfaSVoon Weifeng plat->axi->axi_wr_osr_lmt = 1; 52758da0cfaSVoon Weifeng plat->axi->axi_rd_osr_lmt = 1; 52858da0cfaSVoon Weifeng plat->axi->axi_blen[0] = 4; 52958da0cfaSVoon Weifeng plat->axi->axi_blen[1] = 8; 53058da0cfaSVoon Weifeng plat->axi->axi_blen[2] = 16; 53158da0cfaSVoon Weifeng 53258da0cfaSVoon Weifeng plat->ptp_max_adj = plat->clk_ptp_rate; 533b4c5f83aSRusaimi Amira Ruslan plat->eee_usecs_rate = plat->clk_ptp_rate; 53458da0cfaSVoon Weifeng 53558da0cfaSVoon Weifeng /* Set system clock */ 5368eb37ab7SWong Vee Khee sprintf(clk_name, "%s-%s", "stmmac", pci_name(pdev)); 5378eb37ab7SWong Vee Khee 53858da0cfaSVoon Weifeng plat->stmmac_clk = clk_register_fixed_rate(&pdev->dev, 5398eb37ab7SWong Vee Khee clk_name, NULL, 0, 54058da0cfaSVoon Weifeng plat->clk_ptp_rate); 54158da0cfaSVoon Weifeng 54258da0cfaSVoon Weifeng if (IS_ERR(plat->stmmac_clk)) { 54358da0cfaSVoon Weifeng dev_warn(&pdev->dev, "Fail to register stmmac-clk\n"); 54458da0cfaSVoon Weifeng plat->stmmac_clk = NULL; 54558da0cfaSVoon Weifeng } 54609f012e6SAndy Shevchenko 54709f012e6SAndy Shevchenko ret = clk_prepare_enable(plat->stmmac_clk); 54809f012e6SAndy Shevchenko if (ret) { 54909f012e6SAndy Shevchenko clk_unregister_fixed_rate(plat->stmmac_clk); 55009f012e6SAndy Shevchenko return ret; 55109f012e6SAndy Shevchenko } 55258da0cfaSVoon Weifeng 55376da35dcSWong, Vee Khee plat->ptp_clk_freq_config = intel_mgbe_ptp_clk_freq_config; 55476da35dcSWong, Vee Khee 55558da0cfaSVoon Weifeng /* Set default value for multicast hash bins */ 55658da0cfaSVoon Weifeng plat->multicast_filter_bins = HASH_TABLE_SIZE; 55758da0cfaSVoon Weifeng 55858da0cfaSVoon Weifeng /* Set default value for unicast filter entries */ 55958da0cfaSVoon Weifeng plat->unicast_filter_entries = 1; 56058da0cfaSVoon Weifeng 56158da0cfaSVoon Weifeng /* Set the maxmtu to a default of JUMBO_LEN */ 56258da0cfaSVoon Weifeng plat->maxmtu = JUMBO_LEN; 56358da0cfaSVoon Weifeng 564e0f9956aSChuah, Kim Tatt plat->vlan_fail_q_en = true; 565e0f9956aSChuah, Kim Tatt 566e0f9956aSChuah, Kim Tatt /* Use the last Rx queue */ 567e0f9956aSChuah, Kim Tatt plat->vlan_fail_q = plat->rx_queues_to_use - 1; 568e0f9956aSChuah, Kim Tatt 56972edaf39SOng Boon Leong /* For fixed-link setup, we allow phy-mode setting */ 57072edaf39SOng Boon Leong fwnode = dev_fwnode(&pdev->dev); 57172edaf39SOng Boon Leong if (fwnode) { 57272edaf39SOng Boon Leong int phy_mode; 57372edaf39SOng Boon Leong 57472edaf39SOng Boon Leong /* "phy-mode" setting is optional. If it is set, 57572edaf39SOng Boon Leong * we allow either sgmii or 1000base-x for now. 57672edaf39SOng Boon Leong */ 57772edaf39SOng Boon Leong phy_mode = fwnode_get_phy_mode(fwnode); 57872edaf39SOng Boon Leong if (phy_mode >= 0) { 57972edaf39SOng Boon Leong if (phy_mode == PHY_INTERFACE_MODE_SGMII || 58072edaf39SOng Boon Leong phy_mode == PHY_INTERFACE_MODE_1000BASEX) 58172edaf39SOng Boon Leong plat->phy_interface = phy_mode; 58272edaf39SOng Boon Leong else 58372edaf39SOng Boon Leong dev_warn(&pdev->dev, "Invalid phy-mode\n"); 58472edaf39SOng Boon Leong } 58572edaf39SOng Boon Leong } 58672edaf39SOng Boon Leong 5877310fe53SOng Boon Leong /* Intel mgbe SGMII interface uses pcs-xcps */ 588c8238631SOng Boon Leong if (plat->phy_interface == PHY_INTERFACE_MODE_SGMII || 589c8238631SOng Boon Leong plat->phy_interface == PHY_INTERFACE_MODE_1000BASEX) { 5907310fe53SOng Boon Leong plat->mdio_bus_data->has_xpcs = true; 5917310fe53SOng Boon Leong plat->mdio_bus_data->xpcs_an_inband = true; 5927310fe53SOng Boon Leong } 5937310fe53SOng Boon Leong 59472edaf39SOng Boon Leong /* For fixed-link setup, we clear xpcs_an_inband */ 59572edaf39SOng Boon Leong if (fwnode) { 59672edaf39SOng Boon Leong struct fwnode_handle *fixed_node; 59772edaf39SOng Boon Leong 59872edaf39SOng Boon Leong fixed_node = fwnode_get_named_child_node(fwnode, "fixed-link"); 59972edaf39SOng Boon Leong if (fixed_node) 60072edaf39SOng Boon Leong plat->mdio_bus_data->xpcs_an_inband = false; 60172edaf39SOng Boon Leong 60272edaf39SOng Boon Leong fwnode_handle_put(fixed_node); 60372edaf39SOng Boon Leong } 60472edaf39SOng Boon Leong 6057310fe53SOng Boon Leong /* Ensure mdio bus scan skips intel serdes and pcs-xpcs */ 6067310fe53SOng Boon Leong plat->mdio_bus_data->phy_mask = 1 << INTEL_MGBE_ADHOC_ADDR; 6077310fe53SOng Boon Leong plat->mdio_bus_data->phy_mask |= 1 << INTEL_MGBE_XPCS_ADDR; 6087310fe53SOng Boon Leong 609341f67e4STan Tee Min plat->int_snapshot_num = AUX_SNAPSHOT1; 610f4da5652STan Tee Min plat->ext_snapshot_num = AUX_SNAPSHOT0; 611341f67e4STan Tee Min 612341f67e4STan Tee Min plat->crosststamp = intel_crosststamp; 61376c16d3eSWong Vee Khee plat->int_snapshot_en = 0; 614341f67e4STan Tee Min 615b42446b9SOng Boon Leong /* Setup MSI vector offset specific to Intel mGbE controller */ 616b42446b9SOng Boon Leong plat->msi_mac_vec = 29; 617b42446b9SOng Boon Leong plat->msi_lpi_vec = 28; 618b42446b9SOng Boon Leong plat->msi_sfty_ce_vec = 27; 619b42446b9SOng Boon Leong plat->msi_sfty_ue_vec = 26; 620b42446b9SOng Boon Leong plat->msi_rx_base_vec = 0; 621b42446b9SOng Boon Leong plat->msi_tx_base_vec = 1; 622b42446b9SOng Boon Leong 62358da0cfaSVoon Weifeng return 0; 62458da0cfaSVoon Weifeng } 62558da0cfaSVoon Weifeng 62658da0cfaSVoon Weifeng static int ehl_common_data(struct pci_dev *pdev, 62758da0cfaSVoon Weifeng struct plat_stmmacenet_data *plat) 62858da0cfaSVoon Weifeng { 62958da0cfaSVoon Weifeng plat->rx_queues_to_use = 8; 63058da0cfaSVoon Weifeng plat->tx_queues_to_use = 8; 631*fd1d62d8SBartosz Golaszewski plat->flags |= STMMAC_FLAG_USE_PHY_WOL; 63258da0cfaSVoon Weifeng 6335ac712dcSWong Vee Khee plat->safety_feat_cfg->tsoee = 1; 6345ac712dcSWong Vee Khee plat->safety_feat_cfg->mrxpee = 1; 6355ac712dcSWong Vee Khee plat->safety_feat_cfg->mestee = 1; 6365ac712dcSWong Vee Khee plat->safety_feat_cfg->mrxee = 1; 6375ac712dcSWong Vee Khee plat->safety_feat_cfg->mtxee = 1; 6385ac712dcSWong Vee Khee plat->safety_feat_cfg->epsi = 0; 6395ac712dcSWong Vee Khee plat->safety_feat_cfg->edpp = 0; 6405ac712dcSWong Vee Khee plat->safety_feat_cfg->prtyen = 0; 6415ac712dcSWong Vee Khee plat->safety_feat_cfg->tmouten = 0; 6425ac712dcSWong Vee Khee 643d5383b03SAndy Shevchenko return intel_mgbe_common_data(pdev, plat); 64458da0cfaSVoon Weifeng } 64558da0cfaSVoon Weifeng 64658da0cfaSVoon Weifeng static int ehl_sgmii_data(struct pci_dev *pdev, 64758da0cfaSVoon Weifeng struct plat_stmmacenet_data *plat) 64858da0cfaSVoon Weifeng { 64958da0cfaSVoon Weifeng plat->bus_id = 1; 65058da0cfaSVoon Weifeng plat->phy_interface = PHY_INTERFACE_MODE_SGMII; 65146682cb8SVoon Weifeng plat->speed_mode_2500 = intel_speed_mode_2500; 652b9663b7cSVoon Weifeng plat->serdes_powerup = intel_serdes_powerup; 653b9663b7cSVoon Weifeng plat->serdes_powerdown = intel_serdes_powerdown; 654b9663b7cSVoon Weifeng 655dcea1a81STan, Tee Min plat->clk_ptp_rate = 204800000; 656dcea1a81STan, Tee Min 65758da0cfaSVoon Weifeng return ehl_common_data(pdev, plat); 65858da0cfaSVoon Weifeng } 65958da0cfaSVoon Weifeng 660ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_sgmii1g_info = { 66158da0cfaSVoon Weifeng .setup = ehl_sgmii_data, 66258da0cfaSVoon Weifeng }; 66358da0cfaSVoon Weifeng 66458da0cfaSVoon Weifeng static int ehl_rgmii_data(struct pci_dev *pdev, 66558da0cfaSVoon Weifeng struct plat_stmmacenet_data *plat) 66658da0cfaSVoon Weifeng { 66758da0cfaSVoon Weifeng plat->bus_id = 1; 66858da0cfaSVoon Weifeng plat->phy_interface = PHY_INTERFACE_MODE_RGMII; 66958da0cfaSVoon Weifeng 670dcea1a81STan, Tee Min plat->clk_ptp_rate = 204800000; 671dcea1a81STan, Tee Min 67258da0cfaSVoon Weifeng return ehl_common_data(pdev, plat); 67358da0cfaSVoon Weifeng } 67458da0cfaSVoon Weifeng 675ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_rgmii1g_info = { 67658da0cfaSVoon Weifeng .setup = ehl_rgmii_data, 67758da0cfaSVoon Weifeng }; 67858da0cfaSVoon Weifeng 67967c08ac4SVoon Weifeng static int ehl_pse0_common_data(struct pci_dev *pdev, 68067c08ac4SVoon Weifeng struct plat_stmmacenet_data *plat) 68167c08ac4SVoon Weifeng { 68276da35dcSWong, Vee Khee struct intel_priv_data *intel_priv = plat->bsp_priv; 68376da35dcSWong, Vee Khee 68476da35dcSWong, Vee Khee intel_priv->is_pse = true; 68567c08ac4SVoon Weifeng plat->bus_id = 2; 686070246e4SJochen Henneberg plat->host_dma_width = 32; 68776da35dcSWong, Vee Khee 688dcea1a81STan, Tee Min plat->clk_ptp_rate = 200000000; 689dcea1a81STan, Tee Min 6901c137d47SWong Vee Khee intel_mgbe_pse_crossts_adj(intel_priv, EHL_PSE_ART_MHZ); 6911c137d47SWong Vee Khee 69267c08ac4SVoon Weifeng return ehl_common_data(pdev, plat); 69367c08ac4SVoon Weifeng } 69467c08ac4SVoon Weifeng 69567c08ac4SVoon Weifeng static int ehl_pse0_rgmii1g_data(struct pci_dev *pdev, 69667c08ac4SVoon Weifeng struct plat_stmmacenet_data *plat) 69767c08ac4SVoon Weifeng { 69867c08ac4SVoon Weifeng plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID; 69967c08ac4SVoon Weifeng return ehl_pse0_common_data(pdev, plat); 70067c08ac4SVoon Weifeng } 70167c08ac4SVoon Weifeng 702ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_pse0_rgmii1g_info = { 70367c08ac4SVoon Weifeng .setup = ehl_pse0_rgmii1g_data, 70467c08ac4SVoon Weifeng }; 70567c08ac4SVoon Weifeng 70667c08ac4SVoon Weifeng static int ehl_pse0_sgmii1g_data(struct pci_dev *pdev, 70767c08ac4SVoon Weifeng struct plat_stmmacenet_data *plat) 70867c08ac4SVoon Weifeng { 70967c08ac4SVoon Weifeng plat->phy_interface = PHY_INTERFACE_MODE_SGMII; 71046682cb8SVoon Weifeng plat->speed_mode_2500 = intel_speed_mode_2500; 711b9663b7cSVoon Weifeng plat->serdes_powerup = intel_serdes_powerup; 712b9663b7cSVoon Weifeng plat->serdes_powerdown = intel_serdes_powerdown; 71367c08ac4SVoon Weifeng return ehl_pse0_common_data(pdev, plat); 71467c08ac4SVoon Weifeng } 71567c08ac4SVoon Weifeng 716ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_pse0_sgmii1g_info = { 71767c08ac4SVoon Weifeng .setup = ehl_pse0_sgmii1g_data, 71867c08ac4SVoon Weifeng }; 71967c08ac4SVoon Weifeng 72067c08ac4SVoon Weifeng static int ehl_pse1_common_data(struct pci_dev *pdev, 72167c08ac4SVoon Weifeng struct plat_stmmacenet_data *plat) 72267c08ac4SVoon Weifeng { 72376da35dcSWong, Vee Khee struct intel_priv_data *intel_priv = plat->bsp_priv; 72476da35dcSWong, Vee Khee 72576da35dcSWong, Vee Khee intel_priv->is_pse = true; 72667c08ac4SVoon Weifeng plat->bus_id = 3; 727070246e4SJochen Henneberg plat->host_dma_width = 32; 72876da35dcSWong, Vee Khee 729dcea1a81STan, Tee Min plat->clk_ptp_rate = 200000000; 730dcea1a81STan, Tee Min 7311c137d47SWong Vee Khee intel_mgbe_pse_crossts_adj(intel_priv, EHL_PSE_ART_MHZ); 7321c137d47SWong Vee Khee 73367c08ac4SVoon Weifeng return ehl_common_data(pdev, plat); 73467c08ac4SVoon Weifeng } 73567c08ac4SVoon Weifeng 73667c08ac4SVoon Weifeng static int ehl_pse1_rgmii1g_data(struct pci_dev *pdev, 73767c08ac4SVoon Weifeng struct plat_stmmacenet_data *plat) 73867c08ac4SVoon Weifeng { 73967c08ac4SVoon Weifeng plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID; 74067c08ac4SVoon Weifeng return ehl_pse1_common_data(pdev, plat); 74167c08ac4SVoon Weifeng } 74267c08ac4SVoon Weifeng 743ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_pse1_rgmii1g_info = { 74467c08ac4SVoon Weifeng .setup = ehl_pse1_rgmii1g_data, 74567c08ac4SVoon Weifeng }; 74667c08ac4SVoon Weifeng 74767c08ac4SVoon Weifeng static int ehl_pse1_sgmii1g_data(struct pci_dev *pdev, 74867c08ac4SVoon Weifeng struct plat_stmmacenet_data *plat) 74967c08ac4SVoon Weifeng { 75067c08ac4SVoon Weifeng plat->phy_interface = PHY_INTERFACE_MODE_SGMII; 75146682cb8SVoon Weifeng plat->speed_mode_2500 = intel_speed_mode_2500; 752b9663b7cSVoon Weifeng plat->serdes_powerup = intel_serdes_powerup; 753b9663b7cSVoon Weifeng plat->serdes_powerdown = intel_serdes_powerdown; 75467c08ac4SVoon Weifeng return ehl_pse1_common_data(pdev, plat); 75567c08ac4SVoon Weifeng } 75667c08ac4SVoon Weifeng 757ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_pse1_sgmii1g_info = { 75867c08ac4SVoon Weifeng .setup = ehl_pse1_sgmii1g_data, 75967c08ac4SVoon Weifeng }; 76067c08ac4SVoon Weifeng 76158da0cfaSVoon Weifeng static int tgl_common_data(struct pci_dev *pdev, 76258da0cfaSVoon Weifeng struct plat_stmmacenet_data *plat) 76358da0cfaSVoon Weifeng { 76458da0cfaSVoon Weifeng plat->rx_queues_to_use = 6; 76558da0cfaSVoon Weifeng plat->tx_queues_to_use = 4; 766dcea1a81STan, Tee Min plat->clk_ptp_rate = 204800000; 76723d74330SWong Vee Khee plat->speed_mode_2500 = intel_speed_mode_2500; 76858da0cfaSVoon Weifeng 7695ac712dcSWong Vee Khee plat->safety_feat_cfg->tsoee = 1; 7705ac712dcSWong Vee Khee plat->safety_feat_cfg->mrxpee = 0; 7715ac712dcSWong Vee Khee plat->safety_feat_cfg->mestee = 1; 7725ac712dcSWong Vee Khee plat->safety_feat_cfg->mrxee = 1; 7735ac712dcSWong Vee Khee plat->safety_feat_cfg->mtxee = 1; 7745ac712dcSWong Vee Khee plat->safety_feat_cfg->epsi = 0; 7755ac712dcSWong Vee Khee plat->safety_feat_cfg->edpp = 0; 7765ac712dcSWong Vee Khee plat->safety_feat_cfg->prtyen = 0; 7775ac712dcSWong Vee Khee plat->safety_feat_cfg->tmouten = 0; 7785ac712dcSWong Vee Khee 779d5383b03SAndy Shevchenko return intel_mgbe_common_data(pdev, plat); 78058da0cfaSVoon Weifeng } 78158da0cfaSVoon Weifeng 782fa706dceSWong Vee Khee static int tgl_sgmii_phy0_data(struct pci_dev *pdev, 78358da0cfaSVoon Weifeng struct plat_stmmacenet_data *plat) 78458da0cfaSVoon Weifeng { 78558da0cfaSVoon Weifeng plat->bus_id = 1; 78658da0cfaSVoon Weifeng plat->phy_interface = PHY_INTERFACE_MODE_SGMII; 787b9663b7cSVoon Weifeng plat->serdes_powerup = intel_serdes_powerup; 788b9663b7cSVoon Weifeng plat->serdes_powerdown = intel_serdes_powerdown; 78958da0cfaSVoon Weifeng return tgl_common_data(pdev, plat); 79058da0cfaSVoon Weifeng } 79158da0cfaSVoon Weifeng 792fa706dceSWong Vee Khee static struct stmmac_pci_info tgl_sgmii1g_phy0_info = { 793fa706dceSWong Vee Khee .setup = tgl_sgmii_phy0_data, 79458da0cfaSVoon Weifeng }; 79558da0cfaSVoon Weifeng 796fa706dceSWong Vee Khee static int tgl_sgmii_phy1_data(struct pci_dev *pdev, 797fa706dceSWong Vee Khee struct plat_stmmacenet_data *plat) 798fa706dceSWong Vee Khee { 799fa706dceSWong Vee Khee plat->bus_id = 2; 800fa706dceSWong Vee Khee plat->phy_interface = PHY_INTERFACE_MODE_SGMII; 801fa706dceSWong Vee Khee plat->serdes_powerup = intel_serdes_powerup; 802fa706dceSWong Vee Khee plat->serdes_powerdown = intel_serdes_powerdown; 803fa706dceSWong Vee Khee return tgl_common_data(pdev, plat); 804fa706dceSWong Vee Khee } 805fa706dceSWong Vee Khee 806fa706dceSWong Vee Khee static struct stmmac_pci_info tgl_sgmii1g_phy1_info = { 807fa706dceSWong Vee Khee .setup = tgl_sgmii_phy1_data, 808fa706dceSWong Vee Khee }; 809fa706dceSWong Vee Khee 810fa706dceSWong Vee Khee static int adls_sgmii_phy0_data(struct pci_dev *pdev, 81188af9bd4SWong, Vee Khee struct plat_stmmacenet_data *plat) 81288af9bd4SWong, Vee Khee { 81388af9bd4SWong, Vee Khee plat->bus_id = 1; 81488af9bd4SWong, Vee Khee plat->phy_interface = PHY_INTERFACE_MODE_SGMII; 81588af9bd4SWong, Vee Khee 81688af9bd4SWong, Vee Khee /* SerDes power up and power down are done in BIOS for ADL */ 81788af9bd4SWong, Vee Khee 81888af9bd4SWong, Vee Khee return tgl_common_data(pdev, plat); 81988af9bd4SWong, Vee Khee } 82088af9bd4SWong, Vee Khee 821fa706dceSWong Vee Khee static struct stmmac_pci_info adls_sgmii1g_phy0_info = { 822fa706dceSWong Vee Khee .setup = adls_sgmii_phy0_data, 82388af9bd4SWong, Vee Khee }; 82488af9bd4SWong, Vee Khee 825fa706dceSWong Vee Khee static int adls_sgmii_phy1_data(struct pci_dev *pdev, 826fa706dceSWong Vee Khee struct plat_stmmacenet_data *plat) 827fa706dceSWong Vee Khee { 828fa706dceSWong Vee Khee plat->bus_id = 2; 829fa706dceSWong Vee Khee plat->phy_interface = PHY_INTERFACE_MODE_SGMII; 830fa706dceSWong Vee Khee 831fa706dceSWong Vee Khee /* SerDes power up and power down are done in BIOS for ADL */ 832fa706dceSWong Vee Khee 833fa706dceSWong Vee Khee return tgl_common_data(pdev, plat); 834fa706dceSWong Vee Khee } 835fa706dceSWong Vee Khee 836fa706dceSWong Vee Khee static struct stmmac_pci_info adls_sgmii1g_phy1_info = { 837fa706dceSWong Vee Khee .setup = adls_sgmii_phy1_data, 838fa706dceSWong Vee Khee }; 83958da0cfaSVoon Weifeng static const struct stmmac_pci_func_data galileo_stmmac_func_data[] = { 84058da0cfaSVoon Weifeng { 84158da0cfaSVoon Weifeng .func = 6, 84258da0cfaSVoon Weifeng .phy_addr = 1, 84358da0cfaSVoon Weifeng }, 84458da0cfaSVoon Weifeng }; 84558da0cfaSVoon Weifeng 84658da0cfaSVoon Weifeng static const struct stmmac_pci_dmi_data galileo_stmmac_dmi_data = { 84758da0cfaSVoon Weifeng .func = galileo_stmmac_func_data, 84858da0cfaSVoon Weifeng .nfuncs = ARRAY_SIZE(galileo_stmmac_func_data), 84958da0cfaSVoon Weifeng }; 85058da0cfaSVoon Weifeng 85158da0cfaSVoon Weifeng static const struct stmmac_pci_func_data iot2040_stmmac_func_data[] = { 85258da0cfaSVoon Weifeng { 85358da0cfaSVoon Weifeng .func = 6, 85458da0cfaSVoon Weifeng .phy_addr = 1, 85558da0cfaSVoon Weifeng }, 85658da0cfaSVoon Weifeng { 85758da0cfaSVoon Weifeng .func = 7, 85858da0cfaSVoon Weifeng .phy_addr = 1, 85958da0cfaSVoon Weifeng }, 86058da0cfaSVoon Weifeng }; 86158da0cfaSVoon Weifeng 86258da0cfaSVoon Weifeng static const struct stmmac_pci_dmi_data iot2040_stmmac_dmi_data = { 86358da0cfaSVoon Weifeng .func = iot2040_stmmac_func_data, 86458da0cfaSVoon Weifeng .nfuncs = ARRAY_SIZE(iot2040_stmmac_func_data), 86558da0cfaSVoon Weifeng }; 86658da0cfaSVoon Weifeng 86758da0cfaSVoon Weifeng static const struct dmi_system_id quark_pci_dmi[] = { 86858da0cfaSVoon Weifeng { 86958da0cfaSVoon Weifeng .matches = { 87058da0cfaSVoon Weifeng DMI_EXACT_MATCH(DMI_BOARD_NAME, "Galileo"), 87158da0cfaSVoon Weifeng }, 87258da0cfaSVoon Weifeng .driver_data = (void *)&galileo_stmmac_dmi_data, 87358da0cfaSVoon Weifeng }, 87458da0cfaSVoon Weifeng { 87558da0cfaSVoon Weifeng .matches = { 87658da0cfaSVoon Weifeng DMI_EXACT_MATCH(DMI_BOARD_NAME, "GalileoGen2"), 87758da0cfaSVoon Weifeng }, 87858da0cfaSVoon Weifeng .driver_data = (void *)&galileo_stmmac_dmi_data, 87958da0cfaSVoon Weifeng }, 88058da0cfaSVoon Weifeng /* There are 2 types of SIMATIC IOT2000: IOT2020 and IOT2040. 88158da0cfaSVoon Weifeng * The asset tag "6ES7647-0AA00-0YA2" is only for IOT2020 which 88258da0cfaSVoon Weifeng * has only one pci network device while other asset tags are 88358da0cfaSVoon Weifeng * for IOT2040 which has two. 88458da0cfaSVoon Weifeng */ 88558da0cfaSVoon Weifeng { 88658da0cfaSVoon Weifeng .matches = { 88758da0cfaSVoon Weifeng DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"), 88858da0cfaSVoon Weifeng DMI_EXACT_MATCH(DMI_BOARD_ASSET_TAG, 88958da0cfaSVoon Weifeng "6ES7647-0AA00-0YA2"), 89058da0cfaSVoon Weifeng }, 89158da0cfaSVoon Weifeng .driver_data = (void *)&galileo_stmmac_dmi_data, 89258da0cfaSVoon Weifeng }, 89358da0cfaSVoon Weifeng { 89458da0cfaSVoon Weifeng .matches = { 89558da0cfaSVoon Weifeng DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"), 89658da0cfaSVoon Weifeng }, 89758da0cfaSVoon Weifeng .driver_data = (void *)&iot2040_stmmac_dmi_data, 89858da0cfaSVoon Weifeng }, 89958da0cfaSVoon Weifeng {} 90058da0cfaSVoon Weifeng }; 90158da0cfaSVoon Weifeng 90258da0cfaSVoon Weifeng static int quark_default_data(struct pci_dev *pdev, 90358da0cfaSVoon Weifeng struct plat_stmmacenet_data *plat) 90458da0cfaSVoon Weifeng { 90558da0cfaSVoon Weifeng int ret; 90658da0cfaSVoon Weifeng 90758da0cfaSVoon Weifeng /* Set common default data first */ 90858da0cfaSVoon Weifeng common_default_data(plat); 90958da0cfaSVoon Weifeng 91058da0cfaSVoon Weifeng /* Refuse to load the driver and register net device if MAC controller 91158da0cfaSVoon Weifeng * does not connect to any PHY interface. 91258da0cfaSVoon Weifeng */ 91358da0cfaSVoon Weifeng ret = stmmac_pci_find_phy_addr(pdev, quark_pci_dmi); 91458da0cfaSVoon Weifeng if (ret < 0) { 91558da0cfaSVoon Weifeng /* Return error to the caller on DMI enabled boards. */ 91658da0cfaSVoon Weifeng if (dmi_get_system_info(DMI_BOARD_NAME)) 91758da0cfaSVoon Weifeng return ret; 91858da0cfaSVoon Weifeng 91958da0cfaSVoon Weifeng /* Galileo boards with old firmware don't support DMI. We always 92058da0cfaSVoon Weifeng * use 1 here as PHY address, so at least the first found MAC 92158da0cfaSVoon Weifeng * controller would be probed. 92258da0cfaSVoon Weifeng */ 92358da0cfaSVoon Weifeng ret = 1; 92458da0cfaSVoon Weifeng } 92558da0cfaSVoon Weifeng 92658da0cfaSVoon Weifeng plat->bus_id = pci_dev_id(pdev); 92758da0cfaSVoon Weifeng plat->phy_addr = ret; 92858da0cfaSVoon Weifeng plat->phy_interface = PHY_INTERFACE_MODE_RMII; 92958da0cfaSVoon Weifeng 93058da0cfaSVoon Weifeng plat->dma_cfg->pbl = 16; 93158da0cfaSVoon Weifeng plat->dma_cfg->pblx8 = true; 93258da0cfaSVoon Weifeng plat->dma_cfg->fixed_burst = 1; 93358da0cfaSVoon Weifeng /* AXI (TODO) */ 93458da0cfaSVoon Weifeng 93558da0cfaSVoon Weifeng return 0; 93658da0cfaSVoon Weifeng } 93758da0cfaSVoon Weifeng 938ccacb703SAndy Shevchenko static const struct stmmac_pci_info quark_info = { 93958da0cfaSVoon Weifeng .setup = quark_default_data, 94058da0cfaSVoon Weifeng }; 94158da0cfaSVoon Weifeng 942b42446b9SOng Boon Leong static int stmmac_config_single_msi(struct pci_dev *pdev, 943b42446b9SOng Boon Leong struct plat_stmmacenet_data *plat, 944b42446b9SOng Boon Leong struct stmmac_resources *res) 945b42446b9SOng Boon Leong { 946b42446b9SOng Boon Leong int ret; 947b42446b9SOng Boon Leong 948b42446b9SOng Boon Leong ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES); 949b42446b9SOng Boon Leong if (ret < 0) { 950b42446b9SOng Boon Leong dev_info(&pdev->dev, "%s: Single IRQ enablement failed\n", 951b42446b9SOng Boon Leong __func__); 952b42446b9SOng Boon Leong return ret; 953b42446b9SOng Boon Leong } 954b42446b9SOng Boon Leong 955b42446b9SOng Boon Leong res->irq = pci_irq_vector(pdev, 0); 956b42446b9SOng Boon Leong res->wol_irq = res->irq; 957b42446b9SOng Boon Leong plat->multi_msi_en = 0; 958b42446b9SOng Boon Leong dev_info(&pdev->dev, "%s: Single IRQ enablement successful\n", 959b42446b9SOng Boon Leong __func__); 960b42446b9SOng Boon Leong 961b42446b9SOng Boon Leong return 0; 962b42446b9SOng Boon Leong } 963b42446b9SOng Boon Leong 964b42446b9SOng Boon Leong static int stmmac_config_multi_msi(struct pci_dev *pdev, 965b42446b9SOng Boon Leong struct plat_stmmacenet_data *plat, 966b42446b9SOng Boon Leong struct stmmac_resources *res) 967b42446b9SOng Boon Leong { 968b42446b9SOng Boon Leong int ret; 969b42446b9SOng Boon Leong int i; 970b42446b9SOng Boon Leong 971b42446b9SOng Boon Leong if (plat->msi_rx_base_vec >= STMMAC_MSI_VEC_MAX || 972b42446b9SOng Boon Leong plat->msi_tx_base_vec >= STMMAC_MSI_VEC_MAX) { 973b42446b9SOng Boon Leong dev_info(&pdev->dev, "%s: Invalid RX & TX vector defined\n", 974b42446b9SOng Boon Leong __func__); 975b42446b9SOng Boon Leong return -1; 976b42446b9SOng Boon Leong } 977b42446b9SOng Boon Leong 978b42446b9SOng Boon Leong ret = pci_alloc_irq_vectors(pdev, 2, STMMAC_MSI_VEC_MAX, 979b42446b9SOng Boon Leong PCI_IRQ_MSI | PCI_IRQ_MSIX); 980b42446b9SOng Boon Leong if (ret < 0) { 981b42446b9SOng Boon Leong dev_info(&pdev->dev, "%s: multi MSI enablement failed\n", 982b42446b9SOng Boon Leong __func__); 983b42446b9SOng Boon Leong return ret; 984b42446b9SOng Boon Leong } 985b42446b9SOng Boon Leong 986b42446b9SOng Boon Leong /* For RX MSI */ 987b42446b9SOng Boon Leong for (i = 0; i < plat->rx_queues_to_use; i++) { 988b42446b9SOng Boon Leong res->rx_irq[i] = pci_irq_vector(pdev, 989b42446b9SOng Boon Leong plat->msi_rx_base_vec + i * 2); 990b42446b9SOng Boon Leong } 991b42446b9SOng Boon Leong 992b42446b9SOng Boon Leong /* For TX MSI */ 993b42446b9SOng Boon Leong for (i = 0; i < plat->tx_queues_to_use; i++) { 994b42446b9SOng Boon Leong res->tx_irq[i] = pci_irq_vector(pdev, 995b42446b9SOng Boon Leong plat->msi_tx_base_vec + i * 2); 996b42446b9SOng Boon Leong } 997b42446b9SOng Boon Leong 998b42446b9SOng Boon Leong if (plat->msi_mac_vec < STMMAC_MSI_VEC_MAX) 999b42446b9SOng Boon Leong res->irq = pci_irq_vector(pdev, plat->msi_mac_vec); 1000b42446b9SOng Boon Leong if (plat->msi_wol_vec < STMMAC_MSI_VEC_MAX) 1001b42446b9SOng Boon Leong res->wol_irq = pci_irq_vector(pdev, plat->msi_wol_vec); 1002b42446b9SOng Boon Leong if (plat->msi_lpi_vec < STMMAC_MSI_VEC_MAX) 1003b42446b9SOng Boon Leong res->lpi_irq = pci_irq_vector(pdev, plat->msi_lpi_vec); 1004b42446b9SOng Boon Leong if (plat->msi_sfty_ce_vec < STMMAC_MSI_VEC_MAX) 1005b42446b9SOng Boon Leong res->sfty_ce_irq = pci_irq_vector(pdev, plat->msi_sfty_ce_vec); 1006b42446b9SOng Boon Leong if (plat->msi_sfty_ue_vec < STMMAC_MSI_VEC_MAX) 1007b42446b9SOng Boon Leong res->sfty_ue_irq = pci_irq_vector(pdev, plat->msi_sfty_ue_vec); 1008b42446b9SOng Boon Leong 1009b42446b9SOng Boon Leong plat->multi_msi_en = 1; 1010b42446b9SOng Boon Leong dev_info(&pdev->dev, "%s: multi MSI enablement successful\n", __func__); 1011b42446b9SOng Boon Leong 1012b42446b9SOng Boon Leong return 0; 1013b42446b9SOng Boon Leong } 1014b42446b9SOng Boon Leong 101558da0cfaSVoon Weifeng /** 101658da0cfaSVoon Weifeng * intel_eth_pci_probe 101758da0cfaSVoon Weifeng * 101858da0cfaSVoon Weifeng * @pdev: pci device pointer 101958da0cfaSVoon Weifeng * @id: pointer to table of device id/id's. 102058da0cfaSVoon Weifeng * 102158da0cfaSVoon Weifeng * Description: This probing function gets called for all PCI devices which 102258da0cfaSVoon Weifeng * match the ID table and are not "owned" by other driver yet. This function 102358da0cfaSVoon Weifeng * gets passed a "struct pci_dev *" for each device whose entry in the ID table 102458da0cfaSVoon Weifeng * matches the device. The probe functions returns zero when the driver choose 102558da0cfaSVoon Weifeng * to take "ownership" of the device or an error code(-ve no) otherwise. 102658da0cfaSVoon Weifeng */ 102758da0cfaSVoon Weifeng static int intel_eth_pci_probe(struct pci_dev *pdev, 102858da0cfaSVoon Weifeng const struct pci_device_id *id) 102958da0cfaSVoon Weifeng { 103058da0cfaSVoon Weifeng struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data; 1031b9663b7cSVoon Weifeng struct intel_priv_data *intel_priv; 103258da0cfaSVoon Weifeng struct plat_stmmacenet_data *plat; 103358da0cfaSVoon Weifeng struct stmmac_resources res; 103458da0cfaSVoon Weifeng int ret; 103558da0cfaSVoon Weifeng 1036ccacb703SAndy Shevchenko intel_priv = devm_kzalloc(&pdev->dev, sizeof(*intel_priv), GFP_KERNEL); 1037b9663b7cSVoon Weifeng if (!intel_priv) 1038b9663b7cSVoon Weifeng return -ENOMEM; 1039b9663b7cSVoon Weifeng 104058da0cfaSVoon Weifeng plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL); 104158da0cfaSVoon Weifeng if (!plat) 104258da0cfaSVoon Weifeng return -ENOMEM; 104358da0cfaSVoon Weifeng 104458da0cfaSVoon Weifeng plat->mdio_bus_data = devm_kzalloc(&pdev->dev, 104558da0cfaSVoon Weifeng sizeof(*plat->mdio_bus_data), 104658da0cfaSVoon Weifeng GFP_KERNEL); 104758da0cfaSVoon Weifeng if (!plat->mdio_bus_data) 104858da0cfaSVoon Weifeng return -ENOMEM; 104958da0cfaSVoon Weifeng 105058da0cfaSVoon Weifeng plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg), 105158da0cfaSVoon Weifeng GFP_KERNEL); 105258da0cfaSVoon Weifeng if (!plat->dma_cfg) 105358da0cfaSVoon Weifeng return -ENOMEM; 105458da0cfaSVoon Weifeng 10555ac712dcSWong Vee Khee plat->safety_feat_cfg = devm_kzalloc(&pdev->dev, 10565ac712dcSWong Vee Khee sizeof(*plat->safety_feat_cfg), 10575ac712dcSWong Vee Khee GFP_KERNEL); 10585ac712dcSWong Vee Khee if (!plat->safety_feat_cfg) 10595ac712dcSWong Vee Khee return -ENOMEM; 10605ac712dcSWong Vee Khee 106158da0cfaSVoon Weifeng /* Enable pci device */ 10628accc467SWong Vee Khee ret = pcim_enable_device(pdev); 106358da0cfaSVoon Weifeng if (ret) { 106458da0cfaSVoon Weifeng dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n", 106558da0cfaSVoon Weifeng __func__); 106658da0cfaSVoon Weifeng return ret; 106758da0cfaSVoon Weifeng } 106858da0cfaSVoon Weifeng 1069e578f043SAndy Shevchenko ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev)); 107058da0cfaSVoon Weifeng if (ret) 107158da0cfaSVoon Weifeng return ret; 107258da0cfaSVoon Weifeng 107358da0cfaSVoon Weifeng pci_set_master(pdev); 107458da0cfaSVoon Weifeng 1075b9663b7cSVoon Weifeng plat->bsp_priv = intel_priv; 10767310fe53SOng Boon Leong intel_priv->mdio_adhoc_addr = INTEL_MGBE_ADHOC_ADDR; 10771c137d47SWong Vee Khee intel_priv->crossts_adj = 1; 1078b9663b7cSVoon Weifeng 1079b42446b9SOng Boon Leong /* Initialize all MSI vectors to invalid so that it can be set 1080b42446b9SOng Boon Leong * according to platform data settings below. 1081b42446b9SOng Boon Leong * Note: MSI vector takes value from 0 upto 31 (STMMAC_MSI_VEC_MAX) 1082b42446b9SOng Boon Leong */ 1083b42446b9SOng Boon Leong plat->msi_mac_vec = STMMAC_MSI_VEC_MAX; 1084b42446b9SOng Boon Leong plat->msi_wol_vec = STMMAC_MSI_VEC_MAX; 1085b42446b9SOng Boon Leong plat->msi_lpi_vec = STMMAC_MSI_VEC_MAX; 1086b42446b9SOng Boon Leong plat->msi_sfty_ce_vec = STMMAC_MSI_VEC_MAX; 1087b42446b9SOng Boon Leong plat->msi_sfty_ue_vec = STMMAC_MSI_VEC_MAX; 1088b42446b9SOng Boon Leong plat->msi_rx_base_vec = STMMAC_MSI_VEC_MAX; 1089b42446b9SOng Boon Leong plat->msi_tx_base_vec = STMMAC_MSI_VEC_MAX; 1090b42446b9SOng Boon Leong 109158da0cfaSVoon Weifeng ret = info->setup(pdev, plat); 109258da0cfaSVoon Weifeng if (ret) 109358da0cfaSVoon Weifeng return ret; 109458da0cfaSVoon Weifeng 109558da0cfaSVoon Weifeng memset(&res, 0, sizeof(res)); 1096e578f043SAndy Shevchenko res.addr = pcim_iomap_table(pdev)[0]; 109758da0cfaSVoon Weifeng 1098785ff20bSWong Vee Khee if (plat->eee_usecs_rate > 0) { 1099785ff20bSWong Vee Khee u32 tx_lpi_usec; 1100785ff20bSWong Vee Khee 1101785ff20bSWong Vee Khee tx_lpi_usec = (plat->eee_usecs_rate / 1000000) - 1; 1102785ff20bSWong Vee Khee writel(tx_lpi_usec, res.addr + GMAC_1US_TIC_COUNTER); 1103785ff20bSWong Vee Khee } 1104785ff20bSWong Vee Khee 1105b42446b9SOng Boon Leong ret = stmmac_config_multi_msi(pdev, plat, &res); 110609f012e6SAndy Shevchenko if (ret) { 1107b42446b9SOng Boon Leong ret = stmmac_config_single_msi(pdev, plat, &res); 1108b42446b9SOng Boon Leong if (ret) { 1109b42446b9SOng Boon Leong dev_err(&pdev->dev, "%s: ERROR: failed to enable IRQ\n", 1110b42446b9SOng Boon Leong __func__); 1111b42446b9SOng Boon Leong goto err_alloc_irq; 1112b42446b9SOng Boon Leong } 111309f012e6SAndy Shevchenko } 111409f012e6SAndy Shevchenko 1115b42446b9SOng Boon Leong ret = stmmac_dvr_probe(&pdev->dev, plat, &res); 1116b42446b9SOng Boon Leong if (ret) { 11175e74a4b3SChristophe JAILLET goto err_alloc_irq; 1118b42446b9SOng Boon Leong } 1119b42446b9SOng Boon Leong 1120b42446b9SOng Boon Leong return 0; 1121b42446b9SOng Boon Leong 1122b42446b9SOng Boon Leong err_alloc_irq: 1123b42446b9SOng Boon Leong clk_disable_unprepare(plat->stmmac_clk); 1124b42446b9SOng Boon Leong clk_unregister_fixed_rate(plat->stmmac_clk); 112509f012e6SAndy Shevchenko return ret; 112658da0cfaSVoon Weifeng } 112758da0cfaSVoon Weifeng 112858da0cfaSVoon Weifeng /** 112958da0cfaSVoon Weifeng * intel_eth_pci_remove 113058da0cfaSVoon Weifeng * 11313c3ea630SWong Vee Khee * @pdev: pci device pointer 113258da0cfaSVoon Weifeng * Description: this function calls the main to free the net resources 113358da0cfaSVoon Weifeng * and releases the PCI resources. 113458da0cfaSVoon Weifeng */ 113558da0cfaSVoon Weifeng static void intel_eth_pci_remove(struct pci_dev *pdev) 113658da0cfaSVoon Weifeng { 113758da0cfaSVoon Weifeng struct net_device *ndev = dev_get_drvdata(&pdev->dev); 113858da0cfaSVoon Weifeng struct stmmac_priv *priv = netdev_priv(ndev); 113958da0cfaSVoon Weifeng 114058da0cfaSVoon Weifeng stmmac_dvr_remove(&pdev->dev); 114158da0cfaSVoon Weifeng 11425c23d6b7SChristophe JAILLET clk_disable_unprepare(priv->plat->stmmac_clk); 114358da0cfaSVoon Weifeng clk_unregister_fixed_rate(priv->plat->stmmac_clk); 114458da0cfaSVoon Weifeng } 114558da0cfaSVoon Weifeng 114658da0cfaSVoon Weifeng static int __maybe_unused intel_eth_pci_suspend(struct device *dev) 114758da0cfaSVoon Weifeng { 114858da0cfaSVoon Weifeng struct pci_dev *pdev = to_pci_dev(dev); 114958da0cfaSVoon Weifeng int ret; 115058da0cfaSVoon Weifeng 115158da0cfaSVoon Weifeng ret = stmmac_suspend(dev); 115258da0cfaSVoon Weifeng if (ret) 115358da0cfaSVoon Weifeng return ret; 115458da0cfaSVoon Weifeng 115558da0cfaSVoon Weifeng ret = pci_save_state(pdev); 115658da0cfaSVoon Weifeng if (ret) 115758da0cfaSVoon Weifeng return ret; 115858da0cfaSVoon Weifeng 115958da0cfaSVoon Weifeng pci_wake_from_d3(pdev, true); 11601dd53a61SVoon Weifeng pci_set_power_state(pdev, PCI_D3hot); 116158da0cfaSVoon Weifeng return 0; 116258da0cfaSVoon Weifeng } 116358da0cfaSVoon Weifeng 116458da0cfaSVoon Weifeng static int __maybe_unused intel_eth_pci_resume(struct device *dev) 116558da0cfaSVoon Weifeng { 116658da0cfaSVoon Weifeng struct pci_dev *pdev = to_pci_dev(dev); 116758da0cfaSVoon Weifeng int ret; 116858da0cfaSVoon Weifeng 116958da0cfaSVoon Weifeng pci_restore_state(pdev); 117058da0cfaSVoon Weifeng pci_set_power_state(pdev, PCI_D0); 117158da0cfaSVoon Weifeng 11728accc467SWong Vee Khee ret = pcim_enable_device(pdev); 117358da0cfaSVoon Weifeng if (ret) 117458da0cfaSVoon Weifeng return ret; 117558da0cfaSVoon Weifeng 117658da0cfaSVoon Weifeng pci_set_master(pdev); 117758da0cfaSVoon Weifeng 117858da0cfaSVoon Weifeng return stmmac_resume(dev); 117958da0cfaSVoon Weifeng } 118058da0cfaSVoon Weifeng 118158da0cfaSVoon Weifeng static SIMPLE_DEV_PM_OPS(intel_eth_pm_ops, intel_eth_pci_suspend, 118258da0cfaSVoon Weifeng intel_eth_pci_resume); 118358da0cfaSVoon Weifeng 11843036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_QUARK 0x0937 11853036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_RGMII1G 0x4b30 11863036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_SGMII1G 0x4b31 11873036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_SGMII2G5 0x4b32 118867c08ac4SVoon Weifeng /* Intel(R) Programmable Services Engine (Intel(R) PSE) consist of 2 MAC 118967c08ac4SVoon Weifeng * which are named PSE0 and PSE1 119067c08ac4SVoon Weifeng */ 11913036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE0_RGMII1G 0x4ba0 11923036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE0_SGMII1G 0x4ba1 11933036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE0_SGMII2G5 0x4ba2 11943036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE1_RGMII1G 0x4bb0 11953036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE1_SGMII1G 0x4bb1 11963036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE1_SGMII2G5 0x4bb2 11973036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_TGLH_SGMII1G_0 0x43ac 11983036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_TGLH_SGMII1G_1 0x43a2 11993036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_TGL_SGMII1G 0xa0ac 12003036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_ADLS_SGMII1G_0 0x7aac 12013036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_ADLS_SGMII1G_1 0x7aad 120230c5601fSMichael Sit Wei Hong #define PCI_DEVICE_ID_INTEL_ADLN_SGMII1G 0x54ac 120383450bbaSMichael Sit Wei Hong #define PCI_DEVICE_ID_INTEL_RPLP_SGMII1G 0x51ac 120458da0cfaSVoon Weifeng 120558da0cfaSVoon Weifeng static const struct pci_device_id intel_eth_pci_id_table[] = { 12063036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, QUARK, &quark_info) }, 12073036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, EHL_RGMII1G, &ehl_rgmii1g_info) }, 12083036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, EHL_SGMII1G, &ehl_sgmii1g_info) }, 12093036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, EHL_SGMII2G5, &ehl_sgmii1g_info) }, 12103036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, EHL_PSE0_RGMII1G, &ehl_pse0_rgmii1g_info) }, 12113036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, EHL_PSE0_SGMII1G, &ehl_pse0_sgmii1g_info) }, 12123036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, EHL_PSE0_SGMII2G5, &ehl_pse0_sgmii1g_info) }, 12133036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, EHL_PSE1_RGMII1G, &ehl_pse1_rgmii1g_info) }, 12143036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, EHL_PSE1_SGMII1G, &ehl_pse1_sgmii1g_info) }, 12153036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, EHL_PSE1_SGMII2G5, &ehl_pse1_sgmii1g_info) }, 12163036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, TGL_SGMII1G, &tgl_sgmii1g_phy0_info) }, 12173036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, TGLH_SGMII1G_0, &tgl_sgmii1g_phy0_info) }, 12183036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, TGLH_SGMII1G_1, &tgl_sgmii1g_phy1_info) }, 12193036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, ADLS_SGMII1G_0, &adls_sgmii1g_phy0_info) }, 12203036ec03SAndy Shevchenko { PCI_DEVICE_DATA(INTEL, ADLS_SGMII1G_1, &adls_sgmii1g_phy1_info) }, 122130c5601fSMichael Sit Wei Hong { PCI_DEVICE_DATA(INTEL, ADLN_SGMII1G, &tgl_sgmii1g_phy0_info) }, 122283450bbaSMichael Sit Wei Hong { PCI_DEVICE_DATA(INTEL, RPLP_SGMII1G, &tgl_sgmii1g_phy0_info) }, 122358da0cfaSVoon Weifeng {} 122458da0cfaSVoon Weifeng }; 122558da0cfaSVoon Weifeng MODULE_DEVICE_TABLE(pci, intel_eth_pci_id_table); 122658da0cfaSVoon Weifeng 122758da0cfaSVoon Weifeng static struct pci_driver intel_eth_pci_driver = { 122858da0cfaSVoon Weifeng .name = "intel-eth-pci", 122958da0cfaSVoon Weifeng .id_table = intel_eth_pci_id_table, 123058da0cfaSVoon Weifeng .probe = intel_eth_pci_probe, 123158da0cfaSVoon Weifeng .remove = intel_eth_pci_remove, 123258da0cfaSVoon Weifeng .driver = { 123358da0cfaSVoon Weifeng .pm = &intel_eth_pm_ops, 123458da0cfaSVoon Weifeng }, 123558da0cfaSVoon Weifeng }; 123658da0cfaSVoon Weifeng 123758da0cfaSVoon Weifeng module_pci_driver(intel_eth_pci_driver); 123858da0cfaSVoon Weifeng 123958da0cfaSVoon Weifeng MODULE_DESCRIPTION("INTEL 10/100/1000 Ethernet PCI driver"); 124058da0cfaSVoon Weifeng MODULE_AUTHOR("Voon Weifeng <weifeng.voon@intel.com>"); 124158da0cfaSVoon Weifeng MODULE_LICENSE("GPL v2"); 1242