xref: /openbmc/linux/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c (revision 642436a1ad34a28c45bbc2bdc131640a73782356)
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 		priv->plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
25546682cb8SVoon Weifeng 		priv->plat->mdio_bus_data->xpcs_an_inband = true;
25646682cb8SVoon Weifeng 	}
25746682cb8SVoon Weifeng }
25846682cb8SVoon Weifeng 
25976da35dcSWong, Vee Khee /* Program PTP Clock Frequency for different variant of
26076da35dcSWong, Vee Khee  * Intel mGBE that has slightly different GPO mapping
26176da35dcSWong, Vee Khee  */
26276da35dcSWong, Vee Khee static void intel_mgbe_ptp_clk_freq_config(void *npriv)
26376da35dcSWong, Vee Khee {
26476da35dcSWong, Vee Khee 	struct stmmac_priv *priv = (struct stmmac_priv *)npriv;
26576da35dcSWong, Vee Khee 	struct intel_priv_data *intel_priv;
26676da35dcSWong, Vee Khee 	u32 gpio_value;
26776da35dcSWong, Vee Khee 
26876da35dcSWong, Vee Khee 	intel_priv = (struct intel_priv_data *)priv->plat->bsp_priv;
26976da35dcSWong, Vee Khee 
27076da35dcSWong, Vee Khee 	gpio_value = readl(priv->ioaddr + GMAC_GPIO_STATUS);
27176da35dcSWong, Vee Khee 
27276da35dcSWong, Vee Khee 	if (intel_priv->is_pse) {
27376da35dcSWong, Vee Khee 		/* For PSE GbE, use 200MHz */
27476da35dcSWong, Vee Khee 		gpio_value &= ~PSE_PTP_CLK_FREQ_MASK;
27576da35dcSWong, Vee Khee 		gpio_value |= PSE_PTP_CLK_FREQ_200MHZ;
27676da35dcSWong, Vee Khee 	} else {
27776da35dcSWong, Vee Khee 		/* For PCH GbE, use 200MHz */
27876da35dcSWong, Vee Khee 		gpio_value &= ~PCH_PTP_CLK_FREQ_MASK;
27976da35dcSWong, Vee Khee 		gpio_value |= PCH_PTP_CLK_FREQ_200MHZ;
28076da35dcSWong, Vee Khee 	}
28176da35dcSWong, Vee Khee 
28276da35dcSWong, Vee Khee 	writel(gpio_value, priv->ioaddr + GMAC_GPIO_STATUS);
28376da35dcSWong, Vee Khee }
28476da35dcSWong, Vee Khee 
285341f67e4STan Tee Min static void get_arttime(struct mii_bus *mii, int intel_adhoc_addr,
286341f67e4STan Tee Min 			u64 *art_time)
287341f67e4STan Tee Min {
288341f67e4STan Tee Min 	u64 ns;
289341f67e4STan Tee Min 
290341f67e4STan Tee Min 	ns = mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE3);
291341f67e4STan Tee Min 	ns <<= GMAC4_ART_TIME_SHIFT;
292341f67e4STan Tee Min 	ns |= mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE2);
293341f67e4STan Tee Min 	ns <<= GMAC4_ART_TIME_SHIFT;
294341f67e4STan Tee Min 	ns |= mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE1);
295341f67e4STan Tee Min 	ns <<= GMAC4_ART_TIME_SHIFT;
296341f67e4STan Tee Min 	ns |= mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE0);
297341f67e4STan Tee Min 
298341f67e4STan Tee Min 	*art_time = ns;
299341f67e4STan Tee Min }
300341f67e4STan Tee Min 
301341f67e4STan Tee Min static int intel_crosststamp(ktime_t *device,
302341f67e4STan Tee Min 			     struct system_counterval_t *system,
303341f67e4STan Tee Min 			     void *ctx)
304341f67e4STan Tee Min {
305341f67e4STan Tee Min 	struct intel_priv_data *intel_priv;
306341f67e4STan Tee Min 
307341f67e4STan Tee Min 	struct stmmac_priv *priv = (struct stmmac_priv *)ctx;
308341f67e4STan Tee Min 	void __iomem *ptpaddr = priv->ptpaddr;
309341f67e4STan Tee Min 	void __iomem *ioaddr = priv->hw->pcsr;
310341f67e4STan Tee Min 	unsigned long flags;
311341f67e4STan Tee Min 	u64 art_time = 0;
312341f67e4STan Tee Min 	u64 ptp_time = 0;
313341f67e4STan Tee Min 	u32 num_snapshot;
314341f67e4STan Tee Min 	u32 gpio_value;
315341f67e4STan Tee Min 	u32 acr_value;
316341f67e4STan Tee Min 	int ret;
317341f67e4STan Tee Min 	u32 v;
318341f67e4STan Tee Min 	int i;
319341f67e4STan Tee Min 
320341f67e4STan Tee Min 	if (!boot_cpu_has(X86_FEATURE_ART))
321341f67e4STan Tee Min 		return -EOPNOTSUPP;
322341f67e4STan Tee Min 
323341f67e4STan Tee Min 	intel_priv = priv->plat->bsp_priv;
324341f67e4STan Tee Min 
325f4da5652STan Tee Min 	/* Both internal crosstimestamping and external triggered event
326f4da5652STan Tee Min 	 * timestamping cannot be run concurrently.
327f4da5652STan Tee Min 	 */
328f4da5652STan Tee Min 	if (priv->plat->ext_snapshot_en)
329f4da5652STan Tee Min 		return -EBUSY;
330f4da5652STan Tee Min 
331f4da5652STan Tee Min 	mutex_lock(&priv->aux_ts_lock);
332341f67e4STan Tee Min 	/* Enable Internal snapshot trigger */
333341f67e4STan Tee Min 	acr_value = readl(ptpaddr + PTP_ACR);
334341f67e4STan Tee Min 	acr_value &= ~PTP_ACR_MASK;
335341f67e4STan Tee Min 	switch (priv->plat->int_snapshot_num) {
336341f67e4STan Tee Min 	case AUX_SNAPSHOT0:
337341f67e4STan Tee Min 		acr_value |= PTP_ACR_ATSEN0;
338341f67e4STan Tee Min 		break;
339341f67e4STan Tee Min 	case AUX_SNAPSHOT1:
340341f67e4STan Tee Min 		acr_value |= PTP_ACR_ATSEN1;
341341f67e4STan Tee Min 		break;
342341f67e4STan Tee Min 	case AUX_SNAPSHOT2:
343341f67e4STan Tee Min 		acr_value |= PTP_ACR_ATSEN2;
344341f67e4STan Tee Min 		break;
345341f67e4STan Tee Min 	case AUX_SNAPSHOT3:
346341f67e4STan Tee Min 		acr_value |= PTP_ACR_ATSEN3;
347341f67e4STan Tee Min 		break;
348341f67e4STan Tee Min 	default:
34953e35ebbSDan Carpenter 		mutex_unlock(&priv->aux_ts_lock);
350341f67e4STan Tee Min 		return -EINVAL;
351341f67e4STan Tee Min 	}
352341f67e4STan Tee Min 	writel(acr_value, ptpaddr + PTP_ACR);
353341f67e4STan Tee Min 
354341f67e4STan Tee Min 	/* Clear FIFO */
355341f67e4STan Tee Min 	acr_value = readl(ptpaddr + PTP_ACR);
356341f67e4STan Tee Min 	acr_value |= PTP_ACR_ATSFC;
357341f67e4STan Tee Min 	writel(acr_value, ptpaddr + PTP_ACR);
358f4da5652STan Tee Min 	/* Release the mutex */
359f4da5652STan Tee Min 	mutex_unlock(&priv->aux_ts_lock);
360341f67e4STan Tee Min 
361341f67e4STan Tee Min 	/* Trigger Internal snapshot signal
362341f67e4STan Tee Min 	 * Create a rising edge by just toggle the GPO1 to low
363341f67e4STan Tee Min 	 * and back to high.
364341f67e4STan Tee Min 	 */
365341f67e4STan Tee Min 	gpio_value = readl(ioaddr + GMAC_GPIO_STATUS);
366341f67e4STan Tee Min 	gpio_value &= ~GMAC_GPO1;
367341f67e4STan Tee Min 	writel(gpio_value, ioaddr + GMAC_GPIO_STATUS);
368341f67e4STan Tee Min 	gpio_value |= GMAC_GPO1;
369341f67e4STan Tee Min 	writel(gpio_value, ioaddr + GMAC_GPIO_STATUS);
370341f67e4STan Tee Min 
371341f67e4STan Tee Min 	/* Poll for time sync operation done */
372341f67e4STan Tee Min 	ret = readl_poll_timeout(priv->ioaddr + GMAC_INT_STATUS, v,
373341f67e4STan Tee Min 				 (v & GMAC_INT_TSIE), 100, 10000);
374341f67e4STan Tee Min 
375341f67e4STan Tee Min 	if (ret == -ETIMEDOUT) {
376341f67e4STan Tee Min 		pr_err("%s: Wait for time sync operation timeout\n", __func__);
377341f67e4STan Tee Min 		return ret;
378341f67e4STan Tee Min 	}
379341f67e4STan Tee Min 
380341f67e4STan Tee Min 	num_snapshot = (readl(ioaddr + GMAC_TIMESTAMP_STATUS) &
381341f67e4STan Tee Min 			GMAC_TIMESTAMP_ATSNS_MASK) >>
382341f67e4STan Tee Min 			GMAC_TIMESTAMP_ATSNS_SHIFT;
383341f67e4STan Tee Min 
384341f67e4STan Tee Min 	/* Repeat until the timestamps are from the FIFO last segment */
385341f67e4STan Tee Min 	for (i = 0; i < num_snapshot; i++) {
386*642436a1SYannick Vignon 		read_lock_irqsave(&priv->ptp_lock, flags);
387341f67e4STan Tee Min 		stmmac_get_ptptime(priv, ptpaddr, &ptp_time);
388341f67e4STan Tee Min 		*device = ns_to_ktime(ptp_time);
389*642436a1SYannick Vignon 		read_unlock_irqrestore(&priv->ptp_lock, flags);
390341f67e4STan Tee Min 		get_arttime(priv->mii, intel_priv->mdio_adhoc_addr, &art_time);
391341f67e4STan Tee Min 		*system = convert_art_to_tsc(art_time);
392341f67e4STan Tee Min 	}
393341f67e4STan Tee Min 
3941c137d47SWong Vee Khee 	system->cycles *= intel_priv->crossts_adj;
3951c137d47SWong Vee Khee 
396341f67e4STan Tee Min 	return 0;
397341f67e4STan Tee Min }
398341f67e4STan Tee Min 
3991c137d47SWong Vee Khee static void intel_mgbe_pse_crossts_adj(struct intel_priv_data *intel_priv,
4001c137d47SWong Vee Khee 				       int base)
4011c137d47SWong Vee Khee {
4021c137d47SWong Vee Khee 	if (boot_cpu_has(X86_FEATURE_ART)) {
4031c137d47SWong Vee Khee 		unsigned int art_freq;
4041c137d47SWong Vee Khee 
4051c137d47SWong Vee Khee 		/* On systems that support ART, ART frequency can be obtained
4061c137d47SWong Vee Khee 		 * from ECX register of CPUID leaf (0x15).
4071c137d47SWong Vee Khee 		 */
4081c137d47SWong Vee Khee 		art_freq = cpuid_ecx(ART_CPUID_LEAF);
4091c137d47SWong Vee Khee 		do_div(art_freq, base);
4101c137d47SWong Vee Khee 		intel_priv->crossts_adj = art_freq;
4111c137d47SWong Vee Khee 	}
4121c137d47SWong Vee Khee }
4131c137d47SWong Vee Khee 
41458da0cfaSVoon Weifeng static void common_default_data(struct plat_stmmacenet_data *plat)
41558da0cfaSVoon Weifeng {
41658da0cfaSVoon Weifeng 	plat->clk_csr = 2;	/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
41758da0cfaSVoon Weifeng 	plat->has_gmac = 1;
41858da0cfaSVoon Weifeng 	plat->force_sf_dma_mode = 1;
41958da0cfaSVoon Weifeng 
42058da0cfaSVoon Weifeng 	plat->mdio_bus_data->needs_reset = true;
42158da0cfaSVoon Weifeng 
42258da0cfaSVoon Weifeng 	/* Set default value for multicast hash bins */
42358da0cfaSVoon Weifeng 	plat->multicast_filter_bins = HASH_TABLE_SIZE;
42458da0cfaSVoon Weifeng 
42558da0cfaSVoon Weifeng 	/* Set default value for unicast filter entries */
42658da0cfaSVoon Weifeng 	plat->unicast_filter_entries = 1;
42758da0cfaSVoon Weifeng 
42858da0cfaSVoon Weifeng 	/* Set the maxmtu to a default of JUMBO_LEN */
42958da0cfaSVoon Weifeng 	plat->maxmtu = JUMBO_LEN;
43058da0cfaSVoon Weifeng 
43158da0cfaSVoon Weifeng 	/* Set default number of RX and TX queues to use */
43258da0cfaSVoon Weifeng 	plat->tx_queues_to_use = 1;
43358da0cfaSVoon Weifeng 	plat->rx_queues_to_use = 1;
43458da0cfaSVoon Weifeng 
43558da0cfaSVoon Weifeng 	/* Disable Priority config by default */
43658da0cfaSVoon Weifeng 	plat->tx_queues_cfg[0].use_prio = false;
43758da0cfaSVoon Weifeng 	plat->rx_queues_cfg[0].use_prio = false;
43858da0cfaSVoon Weifeng 
43958da0cfaSVoon Weifeng 	/* Disable RX queues routing by default */
44058da0cfaSVoon Weifeng 	plat->rx_queues_cfg[0].pkt_route = 0x0;
44158da0cfaSVoon Weifeng }
44258da0cfaSVoon Weifeng 
44358da0cfaSVoon Weifeng static int intel_mgbe_common_data(struct pci_dev *pdev,
44458da0cfaSVoon Weifeng 				  struct plat_stmmacenet_data *plat)
44558da0cfaSVoon Weifeng {
4468eb37ab7SWong Vee Khee 	char clk_name[20];
44709f012e6SAndy Shevchenko 	int ret;
44858da0cfaSVoon Weifeng 	int i;
44958da0cfaSVoon Weifeng 
45020e07e2cSWong Vee Khee 	plat->pdev = pdev;
451bff6f1dbSVoon Weifeng 	plat->phy_addr = -1;
45258da0cfaSVoon Weifeng 	plat->clk_csr = 5;
45358da0cfaSVoon Weifeng 	plat->has_gmac = 0;
45458da0cfaSVoon Weifeng 	plat->has_gmac4 = 1;
45558da0cfaSVoon Weifeng 	plat->force_sf_dma_mode = 0;
45658da0cfaSVoon Weifeng 	plat->tso_en = 1;
45758da0cfaSVoon Weifeng 
458e80fe71bSMichael Sit Wei Hong 	/* Multiplying factor to the clk_eee_i clock time
459e80fe71bSMichael Sit Wei Hong 	 * period to make it closer to 100 ns. This value
460e80fe71bSMichael Sit Wei Hong 	 * should be programmed such that the clk_eee_time_period *
461e80fe71bSMichael Sit Wei Hong 	 * (MULT_FACT_100NS + 1) should be within 80 ns to 120 ns
462e80fe71bSMichael Sit Wei Hong 	 * clk_eee frequency is 19.2Mhz
463e80fe71bSMichael Sit Wei Hong 	 * clk_eee_time_period is 52ns
464e80fe71bSMichael Sit Wei Hong 	 * 52ns * (1 + 1) = 104ns
465e80fe71bSMichael Sit Wei Hong 	 * MULT_FACT_100NS = 1
466e80fe71bSMichael Sit Wei Hong 	 */
467e80fe71bSMichael Sit Wei Hong 	plat->mult_fact_100ns = 1;
468e80fe71bSMichael Sit Wei Hong 
46958da0cfaSVoon Weifeng 	plat->rx_sched_algorithm = MTL_RX_ALGORITHM_SP;
47058da0cfaSVoon Weifeng 
47158da0cfaSVoon Weifeng 	for (i = 0; i < plat->rx_queues_to_use; i++) {
47258da0cfaSVoon Weifeng 		plat->rx_queues_cfg[i].mode_to_use = MTL_QUEUE_DCB;
47358da0cfaSVoon Weifeng 		plat->rx_queues_cfg[i].chan = i;
47458da0cfaSVoon Weifeng 
47558da0cfaSVoon Weifeng 		/* Disable Priority config by default */
47658da0cfaSVoon Weifeng 		plat->rx_queues_cfg[i].use_prio = false;
47758da0cfaSVoon Weifeng 
47858da0cfaSVoon Weifeng 		/* Disable RX queues routing by default */
47958da0cfaSVoon Weifeng 		plat->rx_queues_cfg[i].pkt_route = 0x0;
48058da0cfaSVoon Weifeng 	}
48158da0cfaSVoon Weifeng 
48258da0cfaSVoon Weifeng 	for (i = 0; i < plat->tx_queues_to_use; i++) {
48358da0cfaSVoon Weifeng 		plat->tx_queues_cfg[i].mode_to_use = MTL_QUEUE_DCB;
48458da0cfaSVoon Weifeng 
48558da0cfaSVoon Weifeng 		/* Disable Priority config by default */
48658da0cfaSVoon Weifeng 		plat->tx_queues_cfg[i].use_prio = false;
48717cb0070SOng Boon Leong 		/* Default TX Q0 to use TSO and rest TXQ for TBS */
48817cb0070SOng Boon Leong 		if (i > 0)
48917cb0070SOng Boon Leong 			plat->tx_queues_cfg[i].tbs_en = 1;
49058da0cfaSVoon Weifeng 	}
49158da0cfaSVoon Weifeng 
49258da0cfaSVoon Weifeng 	/* FIFO size is 4096 bytes for 1 tx/rx queue */
49358da0cfaSVoon Weifeng 	plat->tx_fifo_size = plat->tx_queues_to_use * 4096;
49458da0cfaSVoon Weifeng 	plat->rx_fifo_size = plat->rx_queues_to_use * 4096;
49558da0cfaSVoon Weifeng 
49658da0cfaSVoon Weifeng 	plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WRR;
49758da0cfaSVoon Weifeng 	plat->tx_queues_cfg[0].weight = 0x09;
49858da0cfaSVoon Weifeng 	plat->tx_queues_cfg[1].weight = 0x0A;
49958da0cfaSVoon Weifeng 	plat->tx_queues_cfg[2].weight = 0x0B;
50058da0cfaSVoon Weifeng 	plat->tx_queues_cfg[3].weight = 0x0C;
50158da0cfaSVoon Weifeng 	plat->tx_queues_cfg[4].weight = 0x0D;
50258da0cfaSVoon Weifeng 	plat->tx_queues_cfg[5].weight = 0x0E;
50358da0cfaSVoon Weifeng 	plat->tx_queues_cfg[6].weight = 0x0F;
50458da0cfaSVoon Weifeng 	plat->tx_queues_cfg[7].weight = 0x10;
50558da0cfaSVoon Weifeng 
50658da0cfaSVoon Weifeng 	plat->dma_cfg->pbl = 32;
50758da0cfaSVoon Weifeng 	plat->dma_cfg->pblx8 = true;
50858da0cfaSVoon Weifeng 	plat->dma_cfg->fixed_burst = 0;
50958da0cfaSVoon Weifeng 	plat->dma_cfg->mixed_burst = 0;
51058da0cfaSVoon Weifeng 	plat->dma_cfg->aal = 0;
511676b7ec6SMohammad Athari Bin Ismail 	plat->dma_cfg->dche = true;
51258da0cfaSVoon Weifeng 
51358da0cfaSVoon Weifeng 	plat->axi = devm_kzalloc(&pdev->dev, sizeof(*plat->axi),
51458da0cfaSVoon Weifeng 				 GFP_KERNEL);
51558da0cfaSVoon Weifeng 	if (!plat->axi)
51658da0cfaSVoon Weifeng 		return -ENOMEM;
51758da0cfaSVoon Weifeng 
51858da0cfaSVoon Weifeng 	plat->axi->axi_lpi_en = 0;
51958da0cfaSVoon Weifeng 	plat->axi->axi_xit_frm = 0;
52058da0cfaSVoon Weifeng 	plat->axi->axi_wr_osr_lmt = 1;
52158da0cfaSVoon Weifeng 	plat->axi->axi_rd_osr_lmt = 1;
52258da0cfaSVoon Weifeng 	plat->axi->axi_blen[0] = 4;
52358da0cfaSVoon Weifeng 	plat->axi->axi_blen[1] = 8;
52458da0cfaSVoon Weifeng 	plat->axi->axi_blen[2] = 16;
52558da0cfaSVoon Weifeng 
52658da0cfaSVoon Weifeng 	plat->ptp_max_adj = plat->clk_ptp_rate;
527b4c5f83aSRusaimi Amira Ruslan 	plat->eee_usecs_rate = plat->clk_ptp_rate;
52858da0cfaSVoon Weifeng 
52958da0cfaSVoon Weifeng 	/* Set system clock */
5308eb37ab7SWong Vee Khee 	sprintf(clk_name, "%s-%s", "stmmac", pci_name(pdev));
5318eb37ab7SWong Vee Khee 
53258da0cfaSVoon Weifeng 	plat->stmmac_clk = clk_register_fixed_rate(&pdev->dev,
5338eb37ab7SWong Vee Khee 						   clk_name, NULL, 0,
53458da0cfaSVoon Weifeng 						   plat->clk_ptp_rate);
53558da0cfaSVoon Weifeng 
53658da0cfaSVoon Weifeng 	if (IS_ERR(plat->stmmac_clk)) {
53758da0cfaSVoon Weifeng 		dev_warn(&pdev->dev, "Fail to register stmmac-clk\n");
53858da0cfaSVoon Weifeng 		plat->stmmac_clk = NULL;
53958da0cfaSVoon Weifeng 	}
54009f012e6SAndy Shevchenko 
54109f012e6SAndy Shevchenko 	ret = clk_prepare_enable(plat->stmmac_clk);
54209f012e6SAndy Shevchenko 	if (ret) {
54309f012e6SAndy Shevchenko 		clk_unregister_fixed_rate(plat->stmmac_clk);
54409f012e6SAndy Shevchenko 		return ret;
54509f012e6SAndy Shevchenko 	}
54658da0cfaSVoon Weifeng 
54776da35dcSWong, Vee Khee 	plat->ptp_clk_freq_config = intel_mgbe_ptp_clk_freq_config;
54876da35dcSWong, Vee Khee 
54958da0cfaSVoon Weifeng 	/* Set default value for multicast hash bins */
55058da0cfaSVoon Weifeng 	plat->multicast_filter_bins = HASH_TABLE_SIZE;
55158da0cfaSVoon Weifeng 
55258da0cfaSVoon Weifeng 	/* Set default value for unicast filter entries */
55358da0cfaSVoon Weifeng 	plat->unicast_filter_entries = 1;
55458da0cfaSVoon Weifeng 
55558da0cfaSVoon Weifeng 	/* Set the maxmtu to a default of JUMBO_LEN */
55658da0cfaSVoon Weifeng 	plat->maxmtu = JUMBO_LEN;
55758da0cfaSVoon Weifeng 
558e0f9956aSChuah, Kim Tatt 	plat->vlan_fail_q_en = true;
559e0f9956aSChuah, Kim Tatt 
560e0f9956aSChuah, Kim Tatt 	/* Use the last Rx queue */
561e0f9956aSChuah, Kim Tatt 	plat->vlan_fail_q = plat->rx_queues_to_use - 1;
562e0f9956aSChuah, Kim Tatt 
5637310fe53SOng Boon Leong 	/* Intel mgbe SGMII interface uses pcs-xcps */
5647310fe53SOng Boon Leong 	if (plat->phy_interface == PHY_INTERFACE_MODE_SGMII) {
5657310fe53SOng Boon Leong 		plat->mdio_bus_data->has_xpcs = true;
5667310fe53SOng Boon Leong 		plat->mdio_bus_data->xpcs_an_inband = true;
5677310fe53SOng Boon Leong 	}
5687310fe53SOng Boon Leong 
5697310fe53SOng Boon Leong 	/* Ensure mdio bus scan skips intel serdes and pcs-xpcs */
5707310fe53SOng Boon Leong 	plat->mdio_bus_data->phy_mask = 1 << INTEL_MGBE_ADHOC_ADDR;
5717310fe53SOng Boon Leong 	plat->mdio_bus_data->phy_mask |= 1 << INTEL_MGBE_XPCS_ADDR;
5727310fe53SOng Boon Leong 
573341f67e4STan Tee Min 	plat->int_snapshot_num = AUX_SNAPSHOT1;
574f4da5652STan Tee Min 	plat->ext_snapshot_num = AUX_SNAPSHOT0;
575341f67e4STan Tee Min 
576341f67e4STan Tee Min 	plat->has_crossts = true;
577341f67e4STan Tee Min 	plat->crosststamp = intel_crosststamp;
578341f67e4STan Tee Min 
579b42446b9SOng Boon Leong 	/* Setup MSI vector offset specific to Intel mGbE controller */
580b42446b9SOng Boon Leong 	plat->msi_mac_vec = 29;
581b42446b9SOng Boon Leong 	plat->msi_lpi_vec = 28;
582b42446b9SOng Boon Leong 	plat->msi_sfty_ce_vec = 27;
583b42446b9SOng Boon Leong 	plat->msi_sfty_ue_vec = 26;
584b42446b9SOng Boon Leong 	plat->msi_rx_base_vec = 0;
585b42446b9SOng Boon Leong 	plat->msi_tx_base_vec = 1;
586b42446b9SOng Boon Leong 
58758da0cfaSVoon Weifeng 	return 0;
58858da0cfaSVoon Weifeng }
58958da0cfaSVoon Weifeng 
59058da0cfaSVoon Weifeng static int ehl_common_data(struct pci_dev *pdev,
59158da0cfaSVoon Weifeng 			   struct plat_stmmacenet_data *plat)
59258da0cfaSVoon Weifeng {
59358da0cfaSVoon Weifeng 	plat->rx_queues_to_use = 8;
59458da0cfaSVoon Weifeng 	plat->tx_queues_to_use = 8;
59558da0cfaSVoon Weifeng 	plat->clk_ptp_rate = 200000000;
596945beb75SLing Pei Lee 	plat->use_phy_wol = 1;
59758da0cfaSVoon Weifeng 
5985ac712dcSWong Vee Khee 	plat->safety_feat_cfg->tsoee = 1;
5995ac712dcSWong Vee Khee 	plat->safety_feat_cfg->mrxpee = 1;
6005ac712dcSWong Vee Khee 	plat->safety_feat_cfg->mestee = 1;
6015ac712dcSWong Vee Khee 	plat->safety_feat_cfg->mrxee = 1;
6025ac712dcSWong Vee Khee 	plat->safety_feat_cfg->mtxee = 1;
6035ac712dcSWong Vee Khee 	plat->safety_feat_cfg->epsi = 0;
6045ac712dcSWong Vee Khee 	plat->safety_feat_cfg->edpp = 0;
6055ac712dcSWong Vee Khee 	plat->safety_feat_cfg->prtyen = 0;
6065ac712dcSWong Vee Khee 	plat->safety_feat_cfg->tmouten = 0;
6075ac712dcSWong Vee Khee 
608d5383b03SAndy Shevchenko 	return intel_mgbe_common_data(pdev, plat);
60958da0cfaSVoon Weifeng }
61058da0cfaSVoon Weifeng 
61158da0cfaSVoon Weifeng static int ehl_sgmii_data(struct pci_dev *pdev,
61258da0cfaSVoon Weifeng 			  struct plat_stmmacenet_data *plat)
61358da0cfaSVoon Weifeng {
61458da0cfaSVoon Weifeng 	plat->bus_id = 1;
61558da0cfaSVoon Weifeng 	plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
61646682cb8SVoon Weifeng 	plat->speed_mode_2500 = intel_speed_mode_2500;
617b9663b7cSVoon Weifeng 	plat->serdes_powerup = intel_serdes_powerup;
618b9663b7cSVoon Weifeng 	plat->serdes_powerdown = intel_serdes_powerdown;
619b9663b7cSVoon Weifeng 
62058da0cfaSVoon Weifeng 	return ehl_common_data(pdev, plat);
62158da0cfaSVoon Weifeng }
62258da0cfaSVoon Weifeng 
623ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_sgmii1g_info = {
62458da0cfaSVoon Weifeng 	.setup = ehl_sgmii_data,
62558da0cfaSVoon Weifeng };
62658da0cfaSVoon Weifeng 
62758da0cfaSVoon Weifeng static int ehl_rgmii_data(struct pci_dev *pdev,
62858da0cfaSVoon Weifeng 			  struct plat_stmmacenet_data *plat)
62958da0cfaSVoon Weifeng {
63058da0cfaSVoon Weifeng 	plat->bus_id = 1;
63158da0cfaSVoon Weifeng 	plat->phy_interface = PHY_INTERFACE_MODE_RGMII;
63258da0cfaSVoon Weifeng 
63358da0cfaSVoon Weifeng 	return ehl_common_data(pdev, plat);
63458da0cfaSVoon Weifeng }
63558da0cfaSVoon Weifeng 
636ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_rgmii1g_info = {
63758da0cfaSVoon Weifeng 	.setup = ehl_rgmii_data,
63858da0cfaSVoon Weifeng };
63958da0cfaSVoon Weifeng 
64067c08ac4SVoon Weifeng static int ehl_pse0_common_data(struct pci_dev *pdev,
64167c08ac4SVoon Weifeng 				struct plat_stmmacenet_data *plat)
64267c08ac4SVoon Weifeng {
64376da35dcSWong, Vee Khee 	struct intel_priv_data *intel_priv = plat->bsp_priv;
64476da35dcSWong, Vee Khee 
64576da35dcSWong, Vee Khee 	intel_priv->is_pse = true;
64667c08ac4SVoon Weifeng 	plat->bus_id = 2;
6477cfc4486SVoon Weifeng 	plat->addr64 = 32;
64876da35dcSWong, Vee Khee 
6491c137d47SWong Vee Khee 	intel_mgbe_pse_crossts_adj(intel_priv, EHL_PSE_ART_MHZ);
6501c137d47SWong Vee Khee 
65167c08ac4SVoon Weifeng 	return ehl_common_data(pdev, plat);
65267c08ac4SVoon Weifeng }
65367c08ac4SVoon Weifeng 
65467c08ac4SVoon Weifeng static int ehl_pse0_rgmii1g_data(struct pci_dev *pdev,
65567c08ac4SVoon Weifeng 				 struct plat_stmmacenet_data *plat)
65667c08ac4SVoon Weifeng {
65767c08ac4SVoon Weifeng 	plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;
65867c08ac4SVoon Weifeng 	return ehl_pse0_common_data(pdev, plat);
65967c08ac4SVoon Weifeng }
66067c08ac4SVoon Weifeng 
661ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_pse0_rgmii1g_info = {
66267c08ac4SVoon Weifeng 	.setup = ehl_pse0_rgmii1g_data,
66367c08ac4SVoon Weifeng };
66467c08ac4SVoon Weifeng 
66567c08ac4SVoon Weifeng static int ehl_pse0_sgmii1g_data(struct pci_dev *pdev,
66667c08ac4SVoon Weifeng 				 struct plat_stmmacenet_data *plat)
66767c08ac4SVoon Weifeng {
66867c08ac4SVoon Weifeng 	plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
66946682cb8SVoon Weifeng 	plat->speed_mode_2500 = intel_speed_mode_2500;
670b9663b7cSVoon Weifeng 	plat->serdes_powerup = intel_serdes_powerup;
671b9663b7cSVoon Weifeng 	plat->serdes_powerdown = intel_serdes_powerdown;
67267c08ac4SVoon Weifeng 	return ehl_pse0_common_data(pdev, plat);
67367c08ac4SVoon Weifeng }
67467c08ac4SVoon Weifeng 
675ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_pse0_sgmii1g_info = {
67667c08ac4SVoon Weifeng 	.setup = ehl_pse0_sgmii1g_data,
67767c08ac4SVoon Weifeng };
67867c08ac4SVoon Weifeng 
67967c08ac4SVoon Weifeng static int ehl_pse1_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 = 3;
6867cfc4486SVoon Weifeng 	plat->addr64 = 32;
68776da35dcSWong, Vee Khee 
6881c137d47SWong Vee Khee 	intel_mgbe_pse_crossts_adj(intel_priv, EHL_PSE_ART_MHZ);
6891c137d47SWong Vee Khee 
69067c08ac4SVoon Weifeng 	return ehl_common_data(pdev, plat);
69167c08ac4SVoon Weifeng }
69267c08ac4SVoon Weifeng 
69367c08ac4SVoon Weifeng static int ehl_pse1_rgmii1g_data(struct pci_dev *pdev,
69467c08ac4SVoon Weifeng 				 struct plat_stmmacenet_data *plat)
69567c08ac4SVoon Weifeng {
69667c08ac4SVoon Weifeng 	plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;
69767c08ac4SVoon Weifeng 	return ehl_pse1_common_data(pdev, plat);
69867c08ac4SVoon Weifeng }
69967c08ac4SVoon Weifeng 
700ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_pse1_rgmii1g_info = {
70167c08ac4SVoon Weifeng 	.setup = ehl_pse1_rgmii1g_data,
70267c08ac4SVoon Weifeng };
70367c08ac4SVoon Weifeng 
70467c08ac4SVoon Weifeng static int ehl_pse1_sgmii1g_data(struct pci_dev *pdev,
70567c08ac4SVoon Weifeng 				 struct plat_stmmacenet_data *plat)
70667c08ac4SVoon Weifeng {
70767c08ac4SVoon Weifeng 	plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
70846682cb8SVoon Weifeng 	plat->speed_mode_2500 = intel_speed_mode_2500;
709b9663b7cSVoon Weifeng 	plat->serdes_powerup = intel_serdes_powerup;
710b9663b7cSVoon Weifeng 	plat->serdes_powerdown = intel_serdes_powerdown;
71167c08ac4SVoon Weifeng 	return ehl_pse1_common_data(pdev, plat);
71267c08ac4SVoon Weifeng }
71367c08ac4SVoon Weifeng 
714ccacb703SAndy Shevchenko static struct stmmac_pci_info ehl_pse1_sgmii1g_info = {
71567c08ac4SVoon Weifeng 	.setup = ehl_pse1_sgmii1g_data,
71667c08ac4SVoon Weifeng };
71767c08ac4SVoon Weifeng 
71858da0cfaSVoon Weifeng static int tgl_common_data(struct pci_dev *pdev,
71958da0cfaSVoon Weifeng 			   struct plat_stmmacenet_data *plat)
72058da0cfaSVoon Weifeng {
72158da0cfaSVoon Weifeng 	plat->rx_queues_to_use = 6;
72258da0cfaSVoon Weifeng 	plat->tx_queues_to_use = 4;
72358da0cfaSVoon Weifeng 	plat->clk_ptp_rate = 200000000;
72458da0cfaSVoon Weifeng 
7255ac712dcSWong Vee Khee 	plat->safety_feat_cfg->tsoee = 1;
7265ac712dcSWong Vee Khee 	plat->safety_feat_cfg->mrxpee = 0;
7275ac712dcSWong Vee Khee 	plat->safety_feat_cfg->mestee = 1;
7285ac712dcSWong Vee Khee 	plat->safety_feat_cfg->mrxee = 1;
7295ac712dcSWong Vee Khee 	plat->safety_feat_cfg->mtxee = 1;
7305ac712dcSWong Vee Khee 	plat->safety_feat_cfg->epsi = 0;
7315ac712dcSWong Vee Khee 	plat->safety_feat_cfg->edpp = 0;
7325ac712dcSWong Vee Khee 	plat->safety_feat_cfg->prtyen = 0;
7335ac712dcSWong Vee Khee 	plat->safety_feat_cfg->tmouten = 0;
7345ac712dcSWong Vee Khee 
735d5383b03SAndy Shevchenko 	return intel_mgbe_common_data(pdev, plat);
73658da0cfaSVoon Weifeng }
73758da0cfaSVoon Weifeng 
738fa706dceSWong Vee Khee static int tgl_sgmii_phy0_data(struct pci_dev *pdev,
73958da0cfaSVoon Weifeng 			       struct plat_stmmacenet_data *plat)
74058da0cfaSVoon Weifeng {
74158da0cfaSVoon Weifeng 	plat->bus_id = 1;
74258da0cfaSVoon Weifeng 	plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
74346682cb8SVoon Weifeng 	plat->speed_mode_2500 = intel_speed_mode_2500;
744b9663b7cSVoon Weifeng 	plat->serdes_powerup = intel_serdes_powerup;
745b9663b7cSVoon Weifeng 	plat->serdes_powerdown = intel_serdes_powerdown;
74658da0cfaSVoon Weifeng 	return tgl_common_data(pdev, plat);
74758da0cfaSVoon Weifeng }
74858da0cfaSVoon Weifeng 
749fa706dceSWong Vee Khee static struct stmmac_pci_info tgl_sgmii1g_phy0_info = {
750fa706dceSWong Vee Khee 	.setup = tgl_sgmii_phy0_data,
75158da0cfaSVoon Weifeng };
75258da0cfaSVoon Weifeng 
753fa706dceSWong Vee Khee static int tgl_sgmii_phy1_data(struct pci_dev *pdev,
754fa706dceSWong Vee Khee 			       struct plat_stmmacenet_data *plat)
755fa706dceSWong Vee Khee {
756fa706dceSWong Vee Khee 	plat->bus_id = 2;
757fa706dceSWong Vee Khee 	plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
75846682cb8SVoon Weifeng 	plat->speed_mode_2500 = intel_speed_mode_2500;
759fa706dceSWong Vee Khee 	plat->serdes_powerup = intel_serdes_powerup;
760fa706dceSWong Vee Khee 	plat->serdes_powerdown = intel_serdes_powerdown;
761fa706dceSWong Vee Khee 	return tgl_common_data(pdev, plat);
762fa706dceSWong Vee Khee }
763fa706dceSWong Vee Khee 
764fa706dceSWong Vee Khee static struct stmmac_pci_info tgl_sgmii1g_phy1_info = {
765fa706dceSWong Vee Khee 	.setup = tgl_sgmii_phy1_data,
766fa706dceSWong Vee Khee };
767fa706dceSWong Vee Khee 
768fa706dceSWong Vee Khee static int adls_sgmii_phy0_data(struct pci_dev *pdev,
76988af9bd4SWong, Vee Khee 				struct plat_stmmacenet_data *plat)
77088af9bd4SWong, Vee Khee {
77188af9bd4SWong, Vee Khee 	plat->bus_id = 1;
77288af9bd4SWong, Vee Khee 	plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
77388af9bd4SWong, Vee Khee 
77488af9bd4SWong, Vee Khee 	/* SerDes power up and power down are done in BIOS for ADL */
77588af9bd4SWong, Vee Khee 
77688af9bd4SWong, Vee Khee 	return tgl_common_data(pdev, plat);
77788af9bd4SWong, Vee Khee }
77888af9bd4SWong, Vee Khee 
779fa706dceSWong Vee Khee static struct stmmac_pci_info adls_sgmii1g_phy0_info = {
780fa706dceSWong Vee Khee 	.setup = adls_sgmii_phy0_data,
78188af9bd4SWong, Vee Khee };
78288af9bd4SWong, Vee Khee 
783fa706dceSWong Vee Khee static int adls_sgmii_phy1_data(struct pci_dev *pdev,
784fa706dceSWong Vee Khee 				struct plat_stmmacenet_data *plat)
785fa706dceSWong Vee Khee {
786fa706dceSWong Vee Khee 	plat->bus_id = 2;
787fa706dceSWong Vee Khee 	plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
788fa706dceSWong Vee Khee 
789fa706dceSWong Vee Khee 	/* SerDes power up and power down are done in BIOS for ADL */
790fa706dceSWong Vee Khee 
791fa706dceSWong Vee Khee 	return tgl_common_data(pdev, plat);
792fa706dceSWong Vee Khee }
793fa706dceSWong Vee Khee 
794fa706dceSWong Vee Khee static struct stmmac_pci_info adls_sgmii1g_phy1_info = {
795fa706dceSWong Vee Khee 	.setup = adls_sgmii_phy1_data,
796fa706dceSWong Vee Khee };
79758da0cfaSVoon Weifeng static const struct stmmac_pci_func_data galileo_stmmac_func_data[] = {
79858da0cfaSVoon Weifeng 	{
79958da0cfaSVoon Weifeng 		.func = 6,
80058da0cfaSVoon Weifeng 		.phy_addr = 1,
80158da0cfaSVoon Weifeng 	},
80258da0cfaSVoon Weifeng };
80358da0cfaSVoon Weifeng 
80458da0cfaSVoon Weifeng static const struct stmmac_pci_dmi_data galileo_stmmac_dmi_data = {
80558da0cfaSVoon Weifeng 	.func = galileo_stmmac_func_data,
80658da0cfaSVoon Weifeng 	.nfuncs = ARRAY_SIZE(galileo_stmmac_func_data),
80758da0cfaSVoon Weifeng };
80858da0cfaSVoon Weifeng 
80958da0cfaSVoon Weifeng static const struct stmmac_pci_func_data iot2040_stmmac_func_data[] = {
81058da0cfaSVoon Weifeng 	{
81158da0cfaSVoon Weifeng 		.func = 6,
81258da0cfaSVoon Weifeng 		.phy_addr = 1,
81358da0cfaSVoon Weifeng 	},
81458da0cfaSVoon Weifeng 	{
81558da0cfaSVoon Weifeng 		.func = 7,
81658da0cfaSVoon Weifeng 		.phy_addr = 1,
81758da0cfaSVoon Weifeng 	},
81858da0cfaSVoon Weifeng };
81958da0cfaSVoon Weifeng 
82058da0cfaSVoon Weifeng static const struct stmmac_pci_dmi_data iot2040_stmmac_dmi_data = {
82158da0cfaSVoon Weifeng 	.func = iot2040_stmmac_func_data,
82258da0cfaSVoon Weifeng 	.nfuncs = ARRAY_SIZE(iot2040_stmmac_func_data),
82358da0cfaSVoon Weifeng };
82458da0cfaSVoon Weifeng 
82558da0cfaSVoon Weifeng static const struct dmi_system_id quark_pci_dmi[] = {
82658da0cfaSVoon Weifeng 	{
82758da0cfaSVoon Weifeng 		.matches = {
82858da0cfaSVoon Weifeng 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "Galileo"),
82958da0cfaSVoon Weifeng 		},
83058da0cfaSVoon Weifeng 		.driver_data = (void *)&galileo_stmmac_dmi_data,
83158da0cfaSVoon Weifeng 	},
83258da0cfaSVoon Weifeng 	{
83358da0cfaSVoon Weifeng 		.matches = {
83458da0cfaSVoon Weifeng 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "GalileoGen2"),
83558da0cfaSVoon Weifeng 		},
83658da0cfaSVoon Weifeng 		.driver_data = (void *)&galileo_stmmac_dmi_data,
83758da0cfaSVoon Weifeng 	},
83858da0cfaSVoon Weifeng 	/* There are 2 types of SIMATIC IOT2000: IOT2020 and IOT2040.
83958da0cfaSVoon Weifeng 	 * The asset tag "6ES7647-0AA00-0YA2" is only for IOT2020 which
84058da0cfaSVoon Weifeng 	 * has only one pci network device while other asset tags are
84158da0cfaSVoon Weifeng 	 * for IOT2040 which has two.
84258da0cfaSVoon Weifeng 	 */
84358da0cfaSVoon Weifeng 	{
84458da0cfaSVoon Weifeng 		.matches = {
84558da0cfaSVoon Weifeng 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"),
84658da0cfaSVoon Weifeng 			DMI_EXACT_MATCH(DMI_BOARD_ASSET_TAG,
84758da0cfaSVoon Weifeng 					"6ES7647-0AA00-0YA2"),
84858da0cfaSVoon Weifeng 		},
84958da0cfaSVoon Weifeng 		.driver_data = (void *)&galileo_stmmac_dmi_data,
85058da0cfaSVoon Weifeng 	},
85158da0cfaSVoon Weifeng 	{
85258da0cfaSVoon Weifeng 		.matches = {
85358da0cfaSVoon Weifeng 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"),
85458da0cfaSVoon Weifeng 		},
85558da0cfaSVoon Weifeng 		.driver_data = (void *)&iot2040_stmmac_dmi_data,
85658da0cfaSVoon Weifeng 	},
85758da0cfaSVoon Weifeng 	{}
85858da0cfaSVoon Weifeng };
85958da0cfaSVoon Weifeng 
86058da0cfaSVoon Weifeng static int quark_default_data(struct pci_dev *pdev,
86158da0cfaSVoon Weifeng 			      struct plat_stmmacenet_data *plat)
86258da0cfaSVoon Weifeng {
86358da0cfaSVoon Weifeng 	int ret;
86458da0cfaSVoon Weifeng 
86558da0cfaSVoon Weifeng 	/* Set common default data first */
86658da0cfaSVoon Weifeng 	common_default_data(plat);
86758da0cfaSVoon Weifeng 
86858da0cfaSVoon Weifeng 	/* Refuse to load the driver and register net device if MAC controller
86958da0cfaSVoon Weifeng 	 * does not connect to any PHY interface.
87058da0cfaSVoon Weifeng 	 */
87158da0cfaSVoon Weifeng 	ret = stmmac_pci_find_phy_addr(pdev, quark_pci_dmi);
87258da0cfaSVoon Weifeng 	if (ret < 0) {
87358da0cfaSVoon Weifeng 		/* Return error to the caller on DMI enabled boards. */
87458da0cfaSVoon Weifeng 		if (dmi_get_system_info(DMI_BOARD_NAME))
87558da0cfaSVoon Weifeng 			return ret;
87658da0cfaSVoon Weifeng 
87758da0cfaSVoon Weifeng 		/* Galileo boards with old firmware don't support DMI. We always
87858da0cfaSVoon Weifeng 		 * use 1 here as PHY address, so at least the first found MAC
87958da0cfaSVoon Weifeng 		 * controller would be probed.
88058da0cfaSVoon Weifeng 		 */
88158da0cfaSVoon Weifeng 		ret = 1;
88258da0cfaSVoon Weifeng 	}
88358da0cfaSVoon Weifeng 
88458da0cfaSVoon Weifeng 	plat->bus_id = pci_dev_id(pdev);
88558da0cfaSVoon Weifeng 	plat->phy_addr = ret;
88658da0cfaSVoon Weifeng 	plat->phy_interface = PHY_INTERFACE_MODE_RMII;
88758da0cfaSVoon Weifeng 
88858da0cfaSVoon Weifeng 	plat->dma_cfg->pbl = 16;
88958da0cfaSVoon Weifeng 	plat->dma_cfg->pblx8 = true;
89058da0cfaSVoon Weifeng 	plat->dma_cfg->fixed_burst = 1;
89158da0cfaSVoon Weifeng 	/* AXI (TODO) */
89258da0cfaSVoon Weifeng 
89358da0cfaSVoon Weifeng 	return 0;
89458da0cfaSVoon Weifeng }
89558da0cfaSVoon Weifeng 
896ccacb703SAndy Shevchenko static const struct stmmac_pci_info quark_info = {
89758da0cfaSVoon Weifeng 	.setup = quark_default_data,
89858da0cfaSVoon Weifeng };
89958da0cfaSVoon Weifeng 
900b42446b9SOng Boon Leong static int stmmac_config_single_msi(struct pci_dev *pdev,
901b42446b9SOng Boon Leong 				    struct plat_stmmacenet_data *plat,
902b42446b9SOng Boon Leong 				    struct stmmac_resources *res)
903b42446b9SOng Boon Leong {
904b42446b9SOng Boon Leong 	int ret;
905b42446b9SOng Boon Leong 
906b42446b9SOng Boon Leong 	ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
907b42446b9SOng Boon Leong 	if (ret < 0) {
908b42446b9SOng Boon Leong 		dev_info(&pdev->dev, "%s: Single IRQ enablement failed\n",
909b42446b9SOng Boon Leong 			 __func__);
910b42446b9SOng Boon Leong 		return ret;
911b42446b9SOng Boon Leong 	}
912b42446b9SOng Boon Leong 
913b42446b9SOng Boon Leong 	res->irq = pci_irq_vector(pdev, 0);
914b42446b9SOng Boon Leong 	res->wol_irq = res->irq;
915b42446b9SOng Boon Leong 	plat->multi_msi_en = 0;
916b42446b9SOng Boon Leong 	dev_info(&pdev->dev, "%s: Single IRQ enablement successful\n",
917b42446b9SOng Boon Leong 		 __func__);
918b42446b9SOng Boon Leong 
919b42446b9SOng Boon Leong 	return 0;
920b42446b9SOng Boon Leong }
921b42446b9SOng Boon Leong 
922b42446b9SOng Boon Leong static int stmmac_config_multi_msi(struct pci_dev *pdev,
923b42446b9SOng Boon Leong 				   struct plat_stmmacenet_data *plat,
924b42446b9SOng Boon Leong 				   struct stmmac_resources *res)
925b42446b9SOng Boon Leong {
926b42446b9SOng Boon Leong 	int ret;
927b42446b9SOng Boon Leong 	int i;
928b42446b9SOng Boon Leong 
929b42446b9SOng Boon Leong 	if (plat->msi_rx_base_vec >= STMMAC_MSI_VEC_MAX ||
930b42446b9SOng Boon Leong 	    plat->msi_tx_base_vec >= STMMAC_MSI_VEC_MAX) {
931b42446b9SOng Boon Leong 		dev_info(&pdev->dev, "%s: Invalid RX & TX vector defined\n",
932b42446b9SOng Boon Leong 			 __func__);
933b42446b9SOng Boon Leong 		return -1;
934b42446b9SOng Boon Leong 	}
935b42446b9SOng Boon Leong 
936b42446b9SOng Boon Leong 	ret = pci_alloc_irq_vectors(pdev, 2, STMMAC_MSI_VEC_MAX,
937b42446b9SOng Boon Leong 				    PCI_IRQ_MSI | PCI_IRQ_MSIX);
938b42446b9SOng Boon Leong 	if (ret < 0) {
939b42446b9SOng Boon Leong 		dev_info(&pdev->dev, "%s: multi MSI enablement failed\n",
940b42446b9SOng Boon Leong 			 __func__);
941b42446b9SOng Boon Leong 		return ret;
942b42446b9SOng Boon Leong 	}
943b42446b9SOng Boon Leong 
944b42446b9SOng Boon Leong 	/* For RX MSI */
945b42446b9SOng Boon Leong 	for (i = 0; i < plat->rx_queues_to_use; i++) {
946b42446b9SOng Boon Leong 		res->rx_irq[i] = pci_irq_vector(pdev,
947b42446b9SOng Boon Leong 						plat->msi_rx_base_vec + i * 2);
948b42446b9SOng Boon Leong 	}
949b42446b9SOng Boon Leong 
950b42446b9SOng Boon Leong 	/* For TX MSI */
951b42446b9SOng Boon Leong 	for (i = 0; i < plat->tx_queues_to_use; i++) {
952b42446b9SOng Boon Leong 		res->tx_irq[i] = pci_irq_vector(pdev,
953b42446b9SOng Boon Leong 						plat->msi_tx_base_vec + i * 2);
954b42446b9SOng Boon Leong 	}
955b42446b9SOng Boon Leong 
956b42446b9SOng Boon Leong 	if (plat->msi_mac_vec < STMMAC_MSI_VEC_MAX)
957b42446b9SOng Boon Leong 		res->irq = pci_irq_vector(pdev, plat->msi_mac_vec);
958b42446b9SOng Boon Leong 	if (plat->msi_wol_vec < STMMAC_MSI_VEC_MAX)
959b42446b9SOng Boon Leong 		res->wol_irq = pci_irq_vector(pdev, plat->msi_wol_vec);
960b42446b9SOng Boon Leong 	if (plat->msi_lpi_vec < STMMAC_MSI_VEC_MAX)
961b42446b9SOng Boon Leong 		res->lpi_irq = pci_irq_vector(pdev, plat->msi_lpi_vec);
962b42446b9SOng Boon Leong 	if (plat->msi_sfty_ce_vec < STMMAC_MSI_VEC_MAX)
963b42446b9SOng Boon Leong 		res->sfty_ce_irq = pci_irq_vector(pdev, plat->msi_sfty_ce_vec);
964b42446b9SOng Boon Leong 	if (plat->msi_sfty_ue_vec < STMMAC_MSI_VEC_MAX)
965b42446b9SOng Boon Leong 		res->sfty_ue_irq = pci_irq_vector(pdev, plat->msi_sfty_ue_vec);
966b42446b9SOng Boon Leong 
967b42446b9SOng Boon Leong 	plat->multi_msi_en = 1;
968b42446b9SOng Boon Leong 	dev_info(&pdev->dev, "%s: multi MSI enablement successful\n", __func__);
969b42446b9SOng Boon Leong 
970b42446b9SOng Boon Leong 	return 0;
971b42446b9SOng Boon Leong }
972b42446b9SOng Boon Leong 
97358da0cfaSVoon Weifeng /**
97458da0cfaSVoon Weifeng  * intel_eth_pci_probe
97558da0cfaSVoon Weifeng  *
97658da0cfaSVoon Weifeng  * @pdev: pci device pointer
97758da0cfaSVoon Weifeng  * @id: pointer to table of device id/id's.
97858da0cfaSVoon Weifeng  *
97958da0cfaSVoon Weifeng  * Description: This probing function gets called for all PCI devices which
98058da0cfaSVoon Weifeng  * match the ID table and are not "owned" by other driver yet. This function
98158da0cfaSVoon Weifeng  * gets passed a "struct pci_dev *" for each device whose entry in the ID table
98258da0cfaSVoon Weifeng  * matches the device. The probe functions returns zero when the driver choose
98358da0cfaSVoon Weifeng  * to take "ownership" of the device or an error code(-ve no) otherwise.
98458da0cfaSVoon Weifeng  */
98558da0cfaSVoon Weifeng static int intel_eth_pci_probe(struct pci_dev *pdev,
98658da0cfaSVoon Weifeng 			       const struct pci_device_id *id)
98758da0cfaSVoon Weifeng {
98858da0cfaSVoon Weifeng 	struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
989b9663b7cSVoon Weifeng 	struct intel_priv_data *intel_priv;
99058da0cfaSVoon Weifeng 	struct plat_stmmacenet_data *plat;
99158da0cfaSVoon Weifeng 	struct stmmac_resources res;
99258da0cfaSVoon Weifeng 	int ret;
99358da0cfaSVoon Weifeng 
994ccacb703SAndy Shevchenko 	intel_priv = devm_kzalloc(&pdev->dev, sizeof(*intel_priv), GFP_KERNEL);
995b9663b7cSVoon Weifeng 	if (!intel_priv)
996b9663b7cSVoon Weifeng 		return -ENOMEM;
997b9663b7cSVoon Weifeng 
99858da0cfaSVoon Weifeng 	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
99958da0cfaSVoon Weifeng 	if (!plat)
100058da0cfaSVoon Weifeng 		return -ENOMEM;
100158da0cfaSVoon Weifeng 
100258da0cfaSVoon Weifeng 	plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
100358da0cfaSVoon Weifeng 					   sizeof(*plat->mdio_bus_data),
100458da0cfaSVoon Weifeng 					   GFP_KERNEL);
100558da0cfaSVoon Weifeng 	if (!plat->mdio_bus_data)
100658da0cfaSVoon Weifeng 		return -ENOMEM;
100758da0cfaSVoon Weifeng 
100858da0cfaSVoon Weifeng 	plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
100958da0cfaSVoon Weifeng 				     GFP_KERNEL);
101058da0cfaSVoon Weifeng 	if (!plat->dma_cfg)
101158da0cfaSVoon Weifeng 		return -ENOMEM;
101258da0cfaSVoon Weifeng 
10135ac712dcSWong Vee Khee 	plat->safety_feat_cfg = devm_kzalloc(&pdev->dev,
10145ac712dcSWong Vee Khee 					     sizeof(*plat->safety_feat_cfg),
10155ac712dcSWong Vee Khee 					     GFP_KERNEL);
10165ac712dcSWong Vee Khee 	if (!plat->safety_feat_cfg)
10175ac712dcSWong Vee Khee 		return -ENOMEM;
10185ac712dcSWong Vee Khee 
101958da0cfaSVoon Weifeng 	/* Enable pci device */
10208accc467SWong Vee Khee 	ret = pcim_enable_device(pdev);
102158da0cfaSVoon Weifeng 	if (ret) {
102258da0cfaSVoon Weifeng 		dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
102358da0cfaSVoon Weifeng 			__func__);
102458da0cfaSVoon Weifeng 		return ret;
102558da0cfaSVoon Weifeng 	}
102658da0cfaSVoon Weifeng 
1027e578f043SAndy Shevchenko 	ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
102858da0cfaSVoon Weifeng 	if (ret)
102958da0cfaSVoon Weifeng 		return ret;
103058da0cfaSVoon Weifeng 
103158da0cfaSVoon Weifeng 	pci_set_master(pdev);
103258da0cfaSVoon Weifeng 
1033b9663b7cSVoon Weifeng 	plat->bsp_priv = intel_priv;
10347310fe53SOng Boon Leong 	intel_priv->mdio_adhoc_addr = INTEL_MGBE_ADHOC_ADDR;
10351c137d47SWong Vee Khee 	intel_priv->crossts_adj = 1;
1036b9663b7cSVoon Weifeng 
1037b42446b9SOng Boon Leong 	/* Initialize all MSI vectors to invalid so that it can be set
1038b42446b9SOng Boon Leong 	 * according to platform data settings below.
1039b42446b9SOng Boon Leong 	 * Note: MSI vector takes value from 0 upto 31 (STMMAC_MSI_VEC_MAX)
1040b42446b9SOng Boon Leong 	 */
1041b42446b9SOng Boon Leong 	plat->msi_mac_vec = STMMAC_MSI_VEC_MAX;
1042b42446b9SOng Boon Leong 	plat->msi_wol_vec = STMMAC_MSI_VEC_MAX;
1043b42446b9SOng Boon Leong 	plat->msi_lpi_vec = STMMAC_MSI_VEC_MAX;
1044b42446b9SOng Boon Leong 	plat->msi_sfty_ce_vec = STMMAC_MSI_VEC_MAX;
1045b42446b9SOng Boon Leong 	plat->msi_sfty_ue_vec = STMMAC_MSI_VEC_MAX;
1046b42446b9SOng Boon Leong 	plat->msi_rx_base_vec = STMMAC_MSI_VEC_MAX;
1047b42446b9SOng Boon Leong 	plat->msi_tx_base_vec = STMMAC_MSI_VEC_MAX;
1048b42446b9SOng Boon Leong 
104958da0cfaSVoon Weifeng 	ret = info->setup(pdev, plat);
105058da0cfaSVoon Weifeng 	if (ret)
105158da0cfaSVoon Weifeng 		return ret;
105258da0cfaSVoon Weifeng 
105358da0cfaSVoon Weifeng 	memset(&res, 0, sizeof(res));
1054e578f043SAndy Shevchenko 	res.addr = pcim_iomap_table(pdev)[0];
105558da0cfaSVoon Weifeng 
1056785ff20bSWong Vee Khee 	if (plat->eee_usecs_rate > 0) {
1057785ff20bSWong Vee Khee 		u32 tx_lpi_usec;
1058785ff20bSWong Vee Khee 
1059785ff20bSWong Vee Khee 		tx_lpi_usec = (plat->eee_usecs_rate / 1000000) - 1;
1060785ff20bSWong Vee Khee 		writel(tx_lpi_usec, res.addr + GMAC_1US_TIC_COUNTER);
1061785ff20bSWong Vee Khee 	}
1062785ff20bSWong Vee Khee 
1063b42446b9SOng Boon Leong 	ret = stmmac_config_multi_msi(pdev, plat, &res);
106409f012e6SAndy Shevchenko 	if (ret) {
1065b42446b9SOng Boon Leong 		ret = stmmac_config_single_msi(pdev, plat, &res);
1066b42446b9SOng Boon Leong 		if (ret) {
1067b42446b9SOng Boon Leong 			dev_err(&pdev->dev, "%s: ERROR: failed to enable IRQ\n",
1068b42446b9SOng Boon Leong 				__func__);
1069b42446b9SOng Boon Leong 			goto err_alloc_irq;
1070b42446b9SOng Boon Leong 		}
107109f012e6SAndy Shevchenko 	}
107209f012e6SAndy Shevchenko 
1073b42446b9SOng Boon Leong 	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
1074b42446b9SOng Boon Leong 	if (ret) {
1075b42446b9SOng Boon Leong 		goto err_dvr_probe;
1076b42446b9SOng Boon Leong 	}
1077b42446b9SOng Boon Leong 
1078b42446b9SOng Boon Leong 	return 0;
1079b42446b9SOng Boon Leong 
1080b42446b9SOng Boon Leong err_dvr_probe:
1081b42446b9SOng Boon Leong 	pci_free_irq_vectors(pdev);
1082b42446b9SOng Boon Leong err_alloc_irq:
1083b42446b9SOng Boon Leong 	clk_disable_unprepare(plat->stmmac_clk);
1084b42446b9SOng Boon Leong 	clk_unregister_fixed_rate(plat->stmmac_clk);
108509f012e6SAndy Shevchenko 	return ret;
108658da0cfaSVoon Weifeng }
108758da0cfaSVoon Weifeng 
108858da0cfaSVoon Weifeng /**
108958da0cfaSVoon Weifeng  * intel_eth_pci_remove
109058da0cfaSVoon Weifeng  *
10913c3ea630SWong Vee Khee  * @pdev: pci device pointer
109258da0cfaSVoon Weifeng  * Description: this function calls the main to free the net resources
109358da0cfaSVoon Weifeng  * and releases the PCI resources.
109458da0cfaSVoon Weifeng  */
109558da0cfaSVoon Weifeng static void intel_eth_pci_remove(struct pci_dev *pdev)
109658da0cfaSVoon Weifeng {
109758da0cfaSVoon Weifeng 	struct net_device *ndev = dev_get_drvdata(&pdev->dev);
109858da0cfaSVoon Weifeng 	struct stmmac_priv *priv = netdev_priv(ndev);
109958da0cfaSVoon Weifeng 
110058da0cfaSVoon Weifeng 	stmmac_dvr_remove(&pdev->dev);
110158da0cfaSVoon Weifeng 
110258da0cfaSVoon Weifeng 	clk_unregister_fixed_rate(priv->plat->stmmac_clk);
110358da0cfaSVoon Weifeng 
1104e578f043SAndy Shevchenko 	pcim_iounmap_regions(pdev, BIT(0));
110558da0cfaSVoon Weifeng }
110658da0cfaSVoon Weifeng 
110758da0cfaSVoon Weifeng static int __maybe_unused intel_eth_pci_suspend(struct device *dev)
110858da0cfaSVoon Weifeng {
110958da0cfaSVoon Weifeng 	struct pci_dev *pdev = to_pci_dev(dev);
111058da0cfaSVoon Weifeng 	int ret;
111158da0cfaSVoon Weifeng 
111258da0cfaSVoon Weifeng 	ret = stmmac_suspend(dev);
111358da0cfaSVoon Weifeng 	if (ret)
111458da0cfaSVoon Weifeng 		return ret;
111558da0cfaSVoon Weifeng 
111658da0cfaSVoon Weifeng 	ret = pci_save_state(pdev);
111758da0cfaSVoon Weifeng 	if (ret)
111858da0cfaSVoon Weifeng 		return ret;
111958da0cfaSVoon Weifeng 
112058da0cfaSVoon Weifeng 	pci_wake_from_d3(pdev, true);
11211dd53a61SVoon Weifeng 	pci_set_power_state(pdev, PCI_D3hot);
112258da0cfaSVoon Weifeng 	return 0;
112358da0cfaSVoon Weifeng }
112458da0cfaSVoon Weifeng 
112558da0cfaSVoon Weifeng static int __maybe_unused intel_eth_pci_resume(struct device *dev)
112658da0cfaSVoon Weifeng {
112758da0cfaSVoon Weifeng 	struct pci_dev *pdev = to_pci_dev(dev);
112858da0cfaSVoon Weifeng 	int ret;
112958da0cfaSVoon Weifeng 
113058da0cfaSVoon Weifeng 	pci_restore_state(pdev);
113158da0cfaSVoon Weifeng 	pci_set_power_state(pdev, PCI_D0);
113258da0cfaSVoon Weifeng 
11338accc467SWong Vee Khee 	ret = pcim_enable_device(pdev);
113458da0cfaSVoon Weifeng 	if (ret)
113558da0cfaSVoon Weifeng 		return ret;
113658da0cfaSVoon Weifeng 
113758da0cfaSVoon Weifeng 	pci_set_master(pdev);
113858da0cfaSVoon Weifeng 
113958da0cfaSVoon Weifeng 	return stmmac_resume(dev);
114058da0cfaSVoon Weifeng }
114158da0cfaSVoon Weifeng 
114258da0cfaSVoon Weifeng static SIMPLE_DEV_PM_OPS(intel_eth_pm_ops, intel_eth_pci_suspend,
114358da0cfaSVoon Weifeng 			 intel_eth_pci_resume);
114458da0cfaSVoon Weifeng 
11453036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_QUARK		0x0937
11463036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_RGMII1G		0x4b30
11473036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_SGMII1G		0x4b31
11483036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_SGMII2G5	0x4b32
114967c08ac4SVoon Weifeng /* Intel(R) Programmable Services Engine (Intel(R) PSE) consist of 2 MAC
115067c08ac4SVoon Weifeng  * which are named PSE0 and PSE1
115167c08ac4SVoon Weifeng  */
11523036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE0_RGMII1G	0x4ba0
11533036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE0_SGMII1G	0x4ba1
11543036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE0_SGMII2G5	0x4ba2
11553036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE1_RGMII1G	0x4bb0
11563036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE1_SGMII1G	0x4bb1
11573036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_EHL_PSE1_SGMII2G5	0x4bb2
11583036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_TGLH_SGMII1G_0	0x43ac
11593036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_TGLH_SGMII1G_1	0x43a2
11603036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_TGL_SGMII1G		0xa0ac
11613036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_ADLS_SGMII1G_0	0x7aac
11623036ec03SAndy Shevchenko #define PCI_DEVICE_ID_INTEL_ADLS_SGMII1G_1	0x7aad
116358da0cfaSVoon Weifeng 
116458da0cfaSVoon Weifeng static const struct pci_device_id intel_eth_pci_id_table[] = {
11653036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, QUARK, &quark_info) },
11663036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, EHL_RGMII1G, &ehl_rgmii1g_info) },
11673036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, EHL_SGMII1G, &ehl_sgmii1g_info) },
11683036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, EHL_SGMII2G5, &ehl_sgmii1g_info) },
11693036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, EHL_PSE0_RGMII1G, &ehl_pse0_rgmii1g_info) },
11703036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, EHL_PSE0_SGMII1G, &ehl_pse0_sgmii1g_info) },
11713036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, EHL_PSE0_SGMII2G5, &ehl_pse0_sgmii1g_info) },
11723036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, EHL_PSE1_RGMII1G, &ehl_pse1_rgmii1g_info) },
11733036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, EHL_PSE1_SGMII1G, &ehl_pse1_sgmii1g_info) },
11743036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, EHL_PSE1_SGMII2G5, &ehl_pse1_sgmii1g_info) },
11753036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, TGL_SGMII1G, &tgl_sgmii1g_phy0_info) },
11763036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, TGLH_SGMII1G_0, &tgl_sgmii1g_phy0_info) },
11773036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, TGLH_SGMII1G_1, &tgl_sgmii1g_phy1_info) },
11783036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, ADLS_SGMII1G_0, &adls_sgmii1g_phy0_info) },
11793036ec03SAndy Shevchenko 	{ PCI_DEVICE_DATA(INTEL, ADLS_SGMII1G_1, &adls_sgmii1g_phy1_info) },
118058da0cfaSVoon Weifeng 	{}
118158da0cfaSVoon Weifeng };
118258da0cfaSVoon Weifeng MODULE_DEVICE_TABLE(pci, intel_eth_pci_id_table);
118358da0cfaSVoon Weifeng 
118458da0cfaSVoon Weifeng static struct pci_driver intel_eth_pci_driver = {
118558da0cfaSVoon Weifeng 	.name = "intel-eth-pci",
118658da0cfaSVoon Weifeng 	.id_table = intel_eth_pci_id_table,
118758da0cfaSVoon Weifeng 	.probe = intel_eth_pci_probe,
118858da0cfaSVoon Weifeng 	.remove = intel_eth_pci_remove,
118958da0cfaSVoon Weifeng 	.driver         = {
119058da0cfaSVoon Weifeng 		.pm     = &intel_eth_pm_ops,
119158da0cfaSVoon Weifeng 	},
119258da0cfaSVoon Weifeng };
119358da0cfaSVoon Weifeng 
119458da0cfaSVoon Weifeng module_pci_driver(intel_eth_pci_driver);
119558da0cfaSVoon Weifeng 
119658da0cfaSVoon Weifeng MODULE_DESCRIPTION("INTEL 10/100/1000 Ethernet PCI driver");
119758da0cfaSVoon Weifeng MODULE_AUTHOR("Voon Weifeng <weifeng.voon@intel.com>");
119858da0cfaSVoon Weifeng MODULE_LICENSE("GPL v2");
1199