1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020, Intel Corporation
5 #include <linux/clk-provider.h>
8 #include "dwmac-intel.h"
11 #include "stmmac_ptp.h"
13 struct intel_priv_data {
14 int mdio_adhoc_addr; /* mdio address for serdes & etc */
15 unsigned long crossts_adj;
19 /* This struct is used to associate PCI Function of MAC controller on a board,
20 * discovered via DMI, with the address of PHY connected to the MAC. The
21 * negative value of the address means that MAC controller is not connected
24 struct stmmac_pci_func_data {
29 struct stmmac_pci_dmi_data {
30 const struct stmmac_pci_func_data *func;
34 struct stmmac_pci_info {
35 int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
38 static int stmmac_pci_find_phy_addr(struct pci_dev *pdev,
39 const struct dmi_system_id *dmi_list)
41 const struct stmmac_pci_func_data *func_data;
42 const struct stmmac_pci_dmi_data *dmi_data;
43 const struct dmi_system_id *dmi_id;
44 int func = PCI_FUNC(pdev->devfn);
47 dmi_id = dmi_first_match(dmi_list);
51 dmi_data = dmi_id->driver_data;
52 func_data = dmi_data->func;
54 for (n = 0; n < dmi_data->nfuncs; n++, func_data++)
55 if (func_data->func == func)
56 return func_data->phy_addr;
61 static int serdes_status_poll(struct stmmac_priv *priv, int phyaddr,
62 int phyreg, u32 mask, u32 val)
64 unsigned int retries = 10;
68 val_rd = mdiobus_read(priv->mii, phyaddr, phyreg);
69 if ((val_rd & mask) == (val & mask))
71 udelay(POLL_DELAY_US);
77 static int intel_serdes_powerup(struct net_device *ndev, void *priv_data)
79 struct intel_priv_data *intel_priv = priv_data;
80 struct stmmac_priv *priv = netdev_priv(ndev);
81 int serdes_phy_addr = 0;
84 if (!intel_priv->mdio_adhoc_addr)
87 serdes_phy_addr = intel_priv->mdio_adhoc_addr;
89 /* Set the serdes rate and the PCLK rate */
90 data = mdiobus_read(priv->mii, serdes_phy_addr,
93 data &= ~SERDES_RATE_MASK;
94 data &= ~SERDES_PCLK_MASK;
96 if (priv->plat->max_speed == 2500)
97 data |= SERDES_RATE_PCIE_GEN2 << SERDES_RATE_PCIE_SHIFT |
98 SERDES_PCLK_37p5MHZ << SERDES_PCLK_SHIFT;
100 data |= SERDES_RATE_PCIE_GEN1 << SERDES_RATE_PCIE_SHIFT |
101 SERDES_PCLK_70MHZ << SERDES_PCLK_SHIFT;
103 mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data);
106 data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0);
107 data |= SERDES_PLL_CLK;
108 mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data);
110 /* check for clk_ack assertion */
111 data = serdes_status_poll(priv, serdes_phy_addr,
117 dev_err(priv->device, "Serdes PLL clk request timeout\n");
121 /* assert lane reset */
122 data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0);
124 mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data);
126 /* check for assert lane reset reflection */
127 data = serdes_status_poll(priv, serdes_phy_addr,
133 dev_err(priv->device, "Serdes assert lane reset timeout\n");
137 /* move power state to P0 */
138 data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0);
140 data &= ~SERDES_PWR_ST_MASK;
141 data |= SERDES_PWR_ST_P0 << SERDES_PWR_ST_SHIFT;
143 mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data);
145 /* Check for P0 state */
146 data = serdes_status_poll(priv, serdes_phy_addr,
149 SERDES_PWR_ST_P0 << SERDES_PWR_ST_SHIFT);
152 dev_err(priv->device, "Serdes power state P0 timeout.\n");
156 /* PSE only - ungate SGMII PHY Rx Clock */
157 if (intel_priv->is_pse)
158 mdiobus_modify(priv->mii, serdes_phy_addr, SERDES_GCR0,
159 0, SERDES_PHY_RX_CLK);
164 static void intel_serdes_powerdown(struct net_device *ndev, void *intel_data)
166 struct intel_priv_data *intel_priv = intel_data;
167 struct stmmac_priv *priv = netdev_priv(ndev);
168 int serdes_phy_addr = 0;
171 if (!intel_priv->mdio_adhoc_addr)
174 serdes_phy_addr = intel_priv->mdio_adhoc_addr;
176 /* PSE only - gate SGMII PHY Rx Clock */
177 if (intel_priv->is_pse)
178 mdiobus_modify(priv->mii, serdes_phy_addr, SERDES_GCR0,
179 SERDES_PHY_RX_CLK, 0);
181 /* move power state to P3 */
182 data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0);
184 data &= ~SERDES_PWR_ST_MASK;
185 data |= SERDES_PWR_ST_P3 << SERDES_PWR_ST_SHIFT;
187 mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data);
189 /* Check for P3 state */
190 data = serdes_status_poll(priv, serdes_phy_addr,
193 SERDES_PWR_ST_P3 << SERDES_PWR_ST_SHIFT);
196 dev_err(priv->device, "Serdes power state P3 timeout\n");
200 /* de-assert clk_req */
201 data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0);
202 data &= ~SERDES_PLL_CLK;
203 mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data);
205 /* check for clk_ack de-assert */
206 data = serdes_status_poll(priv, serdes_phy_addr,
209 (u32)~SERDES_PLL_CLK);
212 dev_err(priv->device, "Serdes PLL clk de-assert timeout\n");
216 /* de-assert lane reset */
217 data = mdiobus_read(priv->mii, serdes_phy_addr, SERDES_GCR0);
219 mdiobus_write(priv->mii, serdes_phy_addr, SERDES_GCR0, data);
221 /* check for de-assert lane reset reflection */
222 data = serdes_status_poll(priv, serdes_phy_addr,
228 dev_err(priv->device, "Serdes de-assert lane reset timeout\n");
233 static void intel_speed_mode_2500(struct net_device *ndev, void *intel_data)
235 struct intel_priv_data *intel_priv = intel_data;
236 struct stmmac_priv *priv = netdev_priv(ndev);
237 int serdes_phy_addr = 0;
240 serdes_phy_addr = intel_priv->mdio_adhoc_addr;
242 /* Determine the link speed mode: 2.5Gbps/1Gbps */
243 data = mdiobus_read(priv->mii, serdes_phy_addr,
246 if (((data & SERDES_LINK_MODE_MASK) >> SERDES_LINK_MODE_SHIFT) ==
247 SERDES_LINK_MODE_2G5) {
248 dev_info(priv->device, "Link Speed Mode: 2.5Gbps\n");
249 priv->plat->max_speed = 2500;
250 priv->plat->phy_interface = PHY_INTERFACE_MODE_2500BASEX;
251 priv->plat->mdio_bus_data->xpcs_an_inband = false;
253 priv->plat->max_speed = 1000;
254 priv->plat->mdio_bus_data->xpcs_an_inband = true;
258 /* Program PTP Clock Frequency for different variant of
259 * Intel mGBE that has slightly different GPO mapping
261 static void intel_mgbe_ptp_clk_freq_config(void *npriv)
263 struct stmmac_priv *priv = (struct stmmac_priv *)npriv;
264 struct intel_priv_data *intel_priv;
267 intel_priv = (struct intel_priv_data *)priv->plat->bsp_priv;
269 gpio_value = readl(priv->ioaddr + GMAC_GPIO_STATUS);
271 if (intel_priv->is_pse) {
272 /* For PSE GbE, use 200MHz */
273 gpio_value &= ~PSE_PTP_CLK_FREQ_MASK;
274 gpio_value |= PSE_PTP_CLK_FREQ_200MHZ;
276 /* For PCH GbE, use 200MHz */
277 gpio_value &= ~PCH_PTP_CLK_FREQ_MASK;
278 gpio_value |= PCH_PTP_CLK_FREQ_200MHZ;
281 writel(gpio_value, priv->ioaddr + GMAC_GPIO_STATUS);
284 static void get_arttime(struct mii_bus *mii, int intel_adhoc_addr,
289 ns = mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE3);
290 ns <<= GMAC4_ART_TIME_SHIFT;
291 ns |= mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE2);
292 ns <<= GMAC4_ART_TIME_SHIFT;
293 ns |= mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE1);
294 ns <<= GMAC4_ART_TIME_SHIFT;
295 ns |= mdiobus_read(mii, intel_adhoc_addr, PMC_ART_VALUE0);
300 static int stmmac_cross_ts_isr(struct stmmac_priv *priv)
302 return (readl(priv->ioaddr + GMAC_INT_STATUS) & GMAC_INT_TSIE);
305 static int intel_crosststamp(ktime_t *device,
306 struct system_counterval_t *system,
309 struct intel_priv_data *intel_priv;
311 struct stmmac_priv *priv = (struct stmmac_priv *)ctx;
312 void __iomem *ptpaddr = priv->ptpaddr;
313 void __iomem *ioaddr = priv->hw->pcsr;
322 if (!boot_cpu_has(X86_FEATURE_ART))
325 intel_priv = priv->plat->bsp_priv;
327 /* Both internal crosstimestamping and external triggered event
328 * timestamping cannot be run concurrently.
330 if (priv->plat->ext_snapshot_en)
333 priv->plat->int_snapshot_en = 1;
335 mutex_lock(&priv->aux_ts_lock);
336 /* Enable Internal snapshot trigger */
337 acr_value = readl(ptpaddr + PTP_ACR);
338 acr_value &= ~PTP_ACR_MASK;
339 switch (priv->plat->int_snapshot_num) {
341 acr_value |= PTP_ACR_ATSEN0;
344 acr_value |= PTP_ACR_ATSEN1;
347 acr_value |= PTP_ACR_ATSEN2;
350 acr_value |= PTP_ACR_ATSEN3;
353 mutex_unlock(&priv->aux_ts_lock);
354 priv->plat->int_snapshot_en = 0;
357 writel(acr_value, ptpaddr + PTP_ACR);
360 acr_value = readl(ptpaddr + PTP_ACR);
361 acr_value |= PTP_ACR_ATSFC;
362 writel(acr_value, ptpaddr + PTP_ACR);
363 /* Release the mutex */
364 mutex_unlock(&priv->aux_ts_lock);
366 /* Trigger Internal snapshot signal
367 * Create a rising edge by just toggle the GPO1 to low
370 gpio_value = readl(ioaddr + GMAC_GPIO_STATUS);
371 gpio_value &= ~GMAC_GPO1;
372 writel(gpio_value, ioaddr + GMAC_GPIO_STATUS);
373 gpio_value |= GMAC_GPO1;
374 writel(gpio_value, ioaddr + GMAC_GPIO_STATUS);
376 /* Time sync done Indication - Interrupt method */
377 if (!wait_event_interruptible_timeout(priv->tstamp_busy_wait,
378 stmmac_cross_ts_isr(priv),
380 priv->plat->int_snapshot_en = 0;
384 num_snapshot = (readl(ioaddr + GMAC_TIMESTAMP_STATUS) &
385 GMAC_TIMESTAMP_ATSNS_MASK) >>
386 GMAC_TIMESTAMP_ATSNS_SHIFT;
388 /* Repeat until the timestamps are from the FIFO last segment */
389 for (i = 0; i < num_snapshot; i++) {
390 read_lock_irqsave(&priv->ptp_lock, flags);
391 stmmac_get_ptptime(priv, ptpaddr, &ptp_time);
392 *device = ns_to_ktime(ptp_time);
393 read_unlock_irqrestore(&priv->ptp_lock, flags);
394 get_arttime(priv->mii, intel_priv->mdio_adhoc_addr, &art_time);
395 *system = convert_art_to_tsc(art_time);
398 system->cycles *= intel_priv->crossts_adj;
399 priv->plat->int_snapshot_en = 0;
404 static void intel_mgbe_pse_crossts_adj(struct intel_priv_data *intel_priv,
407 if (boot_cpu_has(X86_FEATURE_ART)) {
408 unsigned int art_freq;
410 /* On systems that support ART, ART frequency can be obtained
411 * from ECX register of CPUID leaf (0x15).
413 art_freq = cpuid_ecx(ART_CPUID_LEAF);
414 do_div(art_freq, base);
415 intel_priv->crossts_adj = art_freq;
419 static void common_default_data(struct plat_stmmacenet_data *plat)
421 plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
423 plat->force_sf_dma_mode = 1;
425 plat->mdio_bus_data->needs_reset = true;
427 /* Set default value for multicast hash bins */
428 plat->multicast_filter_bins = HASH_TABLE_SIZE;
430 /* Set default value for unicast filter entries */
431 plat->unicast_filter_entries = 1;
433 /* Set the maxmtu to a default of JUMBO_LEN */
434 plat->maxmtu = JUMBO_LEN;
436 /* Set default number of RX and TX queues to use */
437 plat->tx_queues_to_use = 1;
438 plat->rx_queues_to_use = 1;
440 /* Disable Priority config by default */
441 plat->tx_queues_cfg[0].use_prio = false;
442 plat->rx_queues_cfg[0].use_prio = false;
444 /* Disable RX queues routing by default */
445 plat->rx_queues_cfg[0].pkt_route = 0x0;
448 static int intel_mgbe_common_data(struct pci_dev *pdev,
449 struct plat_stmmacenet_data *plat)
451 struct fwnode_handle *fwnode;
461 plat->force_sf_dma_mode = 0;
463 plat->sph_disable = 1;
465 /* Multiplying factor to the clk_eee_i clock time
466 * period to make it closer to 100 ns. This value
467 * should be programmed such that the clk_eee_time_period *
468 * (MULT_FACT_100NS + 1) should be within 80 ns to 120 ns
469 * clk_eee frequency is 19.2Mhz
470 * clk_eee_time_period is 52ns
471 * 52ns * (1 + 1) = 104ns
472 * MULT_FACT_100NS = 1
474 plat->mult_fact_100ns = 1;
476 plat->rx_sched_algorithm = MTL_RX_ALGORITHM_SP;
478 for (i = 0; i < plat->rx_queues_to_use; i++) {
479 plat->rx_queues_cfg[i].mode_to_use = MTL_QUEUE_DCB;
480 plat->rx_queues_cfg[i].chan = i;
482 /* Disable Priority config by default */
483 plat->rx_queues_cfg[i].use_prio = false;
485 /* Disable RX queues routing by default */
486 plat->rx_queues_cfg[i].pkt_route = 0x0;
489 for (i = 0; i < plat->tx_queues_to_use; i++) {
490 plat->tx_queues_cfg[i].mode_to_use = MTL_QUEUE_DCB;
492 /* Disable Priority config by default */
493 plat->tx_queues_cfg[i].use_prio = false;
494 /* Default TX Q0 to use TSO and rest TXQ for TBS */
496 plat->tx_queues_cfg[i].tbs_en = 1;
499 /* FIFO size is 4096 bytes for 1 tx/rx queue */
500 plat->tx_fifo_size = plat->tx_queues_to_use * 4096;
501 plat->rx_fifo_size = plat->rx_queues_to_use * 4096;
503 plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WRR;
504 plat->tx_queues_cfg[0].weight = 0x09;
505 plat->tx_queues_cfg[1].weight = 0x0A;
506 plat->tx_queues_cfg[2].weight = 0x0B;
507 plat->tx_queues_cfg[3].weight = 0x0C;
508 plat->tx_queues_cfg[4].weight = 0x0D;
509 plat->tx_queues_cfg[5].weight = 0x0E;
510 plat->tx_queues_cfg[6].weight = 0x0F;
511 plat->tx_queues_cfg[7].weight = 0x10;
513 plat->dma_cfg->pbl = 32;
514 plat->dma_cfg->pblx8 = true;
515 plat->dma_cfg->fixed_burst = 0;
516 plat->dma_cfg->mixed_burst = 0;
517 plat->dma_cfg->aal = 0;
518 plat->dma_cfg->dche = true;
520 plat->axi = devm_kzalloc(&pdev->dev, sizeof(*plat->axi),
525 plat->axi->axi_lpi_en = 0;
526 plat->axi->axi_xit_frm = 0;
527 plat->axi->axi_wr_osr_lmt = 1;
528 plat->axi->axi_rd_osr_lmt = 1;
529 plat->axi->axi_blen[0] = 4;
530 plat->axi->axi_blen[1] = 8;
531 plat->axi->axi_blen[2] = 16;
533 plat->ptp_max_adj = plat->clk_ptp_rate;
534 plat->eee_usecs_rate = plat->clk_ptp_rate;
536 /* Set system clock */
537 sprintf(clk_name, "%s-%s", "stmmac", pci_name(pdev));
539 plat->stmmac_clk = clk_register_fixed_rate(&pdev->dev,
543 if (IS_ERR(plat->stmmac_clk)) {
544 dev_warn(&pdev->dev, "Fail to register stmmac-clk\n");
545 plat->stmmac_clk = NULL;
548 ret = clk_prepare_enable(plat->stmmac_clk);
550 clk_unregister_fixed_rate(plat->stmmac_clk);
554 plat->ptp_clk_freq_config = intel_mgbe_ptp_clk_freq_config;
556 /* Set default value for multicast hash bins */
557 plat->multicast_filter_bins = HASH_TABLE_SIZE;
559 /* Set default value for unicast filter entries */
560 plat->unicast_filter_entries = 1;
562 /* Set the maxmtu to a default of JUMBO_LEN */
563 plat->maxmtu = JUMBO_LEN;
565 plat->vlan_fail_q_en = true;
567 /* Use the last Rx queue */
568 plat->vlan_fail_q = plat->rx_queues_to_use - 1;
570 /* For fixed-link setup, we allow phy-mode setting */
571 fwnode = dev_fwnode(&pdev->dev);
575 /* "phy-mode" setting is optional. If it is set,
576 * we allow either sgmii or 1000base-x for now.
578 phy_mode = fwnode_get_phy_mode(fwnode);
580 if (phy_mode == PHY_INTERFACE_MODE_SGMII ||
581 phy_mode == PHY_INTERFACE_MODE_1000BASEX)
582 plat->phy_interface = phy_mode;
584 dev_warn(&pdev->dev, "Invalid phy-mode\n");
588 /* Intel mgbe SGMII interface uses pcs-xcps */
589 if (plat->phy_interface == PHY_INTERFACE_MODE_SGMII ||
590 plat->phy_interface == PHY_INTERFACE_MODE_1000BASEX) {
591 plat->mdio_bus_data->has_xpcs = true;
592 plat->mdio_bus_data->xpcs_an_inband = true;
595 /* For fixed-link setup, we clear xpcs_an_inband */
597 struct fwnode_handle *fixed_node;
599 fixed_node = fwnode_get_named_child_node(fwnode, "fixed-link");
601 plat->mdio_bus_data->xpcs_an_inband = false;
603 fwnode_handle_put(fixed_node);
606 /* Ensure mdio bus scan skips intel serdes and pcs-xpcs */
607 plat->mdio_bus_data->phy_mask = 1 << INTEL_MGBE_ADHOC_ADDR;
608 plat->mdio_bus_data->phy_mask |= 1 << INTEL_MGBE_XPCS_ADDR;
610 plat->int_snapshot_num = AUX_SNAPSHOT1;
611 plat->ext_snapshot_num = AUX_SNAPSHOT0;
613 plat->has_crossts = true;
614 plat->crosststamp = intel_crosststamp;
615 plat->int_snapshot_en = 0;
617 /* Setup MSI vector offset specific to Intel mGbE controller */
618 plat->msi_mac_vec = 29;
619 plat->msi_lpi_vec = 28;
620 plat->msi_sfty_ce_vec = 27;
621 plat->msi_sfty_ue_vec = 26;
622 plat->msi_rx_base_vec = 0;
623 plat->msi_tx_base_vec = 1;
628 static int ehl_common_data(struct pci_dev *pdev,
629 struct plat_stmmacenet_data *plat)
631 plat->rx_queues_to_use = 8;
632 plat->tx_queues_to_use = 8;
633 plat->clk_ptp_rate = 200000000;
634 plat->use_phy_wol = 1;
636 plat->safety_feat_cfg->tsoee = 1;
637 plat->safety_feat_cfg->mrxpee = 1;
638 plat->safety_feat_cfg->mestee = 1;
639 plat->safety_feat_cfg->mrxee = 1;
640 plat->safety_feat_cfg->mtxee = 1;
641 plat->safety_feat_cfg->epsi = 0;
642 plat->safety_feat_cfg->edpp = 0;
643 plat->safety_feat_cfg->prtyen = 0;
644 plat->safety_feat_cfg->tmouten = 0;
646 return intel_mgbe_common_data(pdev, plat);
649 static int ehl_sgmii_data(struct pci_dev *pdev,
650 struct plat_stmmacenet_data *plat)
653 plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
654 plat->speed_mode_2500 = intel_speed_mode_2500;
655 plat->serdes_powerup = intel_serdes_powerup;
656 plat->serdes_powerdown = intel_serdes_powerdown;
658 return ehl_common_data(pdev, plat);
661 static struct stmmac_pci_info ehl_sgmii1g_info = {
662 .setup = ehl_sgmii_data,
665 static int ehl_rgmii_data(struct pci_dev *pdev,
666 struct plat_stmmacenet_data *plat)
669 plat->phy_interface = PHY_INTERFACE_MODE_RGMII;
671 return ehl_common_data(pdev, plat);
674 static struct stmmac_pci_info ehl_rgmii1g_info = {
675 .setup = ehl_rgmii_data,
678 static int ehl_pse0_common_data(struct pci_dev *pdev,
679 struct plat_stmmacenet_data *plat)
681 struct intel_priv_data *intel_priv = plat->bsp_priv;
683 intel_priv->is_pse = true;
687 intel_mgbe_pse_crossts_adj(intel_priv, EHL_PSE_ART_MHZ);
689 return ehl_common_data(pdev, plat);
692 static int ehl_pse0_rgmii1g_data(struct pci_dev *pdev,
693 struct plat_stmmacenet_data *plat)
695 plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;
696 return ehl_pse0_common_data(pdev, plat);
699 static struct stmmac_pci_info ehl_pse0_rgmii1g_info = {
700 .setup = ehl_pse0_rgmii1g_data,
703 static int ehl_pse0_sgmii1g_data(struct pci_dev *pdev,
704 struct plat_stmmacenet_data *plat)
706 plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
707 plat->speed_mode_2500 = intel_speed_mode_2500;
708 plat->serdes_powerup = intel_serdes_powerup;
709 plat->serdes_powerdown = intel_serdes_powerdown;
710 return ehl_pse0_common_data(pdev, plat);
713 static struct stmmac_pci_info ehl_pse0_sgmii1g_info = {
714 .setup = ehl_pse0_sgmii1g_data,
717 static int ehl_pse1_common_data(struct pci_dev *pdev,
718 struct plat_stmmacenet_data *plat)
720 struct intel_priv_data *intel_priv = plat->bsp_priv;
722 intel_priv->is_pse = true;
726 intel_mgbe_pse_crossts_adj(intel_priv, EHL_PSE_ART_MHZ);
728 return ehl_common_data(pdev, plat);
731 static int ehl_pse1_rgmii1g_data(struct pci_dev *pdev,
732 struct plat_stmmacenet_data *plat)
734 plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;
735 return ehl_pse1_common_data(pdev, plat);
738 static struct stmmac_pci_info ehl_pse1_rgmii1g_info = {
739 .setup = ehl_pse1_rgmii1g_data,
742 static int ehl_pse1_sgmii1g_data(struct pci_dev *pdev,
743 struct plat_stmmacenet_data *plat)
745 plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
746 plat->speed_mode_2500 = intel_speed_mode_2500;
747 plat->serdes_powerup = intel_serdes_powerup;
748 plat->serdes_powerdown = intel_serdes_powerdown;
749 return ehl_pse1_common_data(pdev, plat);
752 static struct stmmac_pci_info ehl_pse1_sgmii1g_info = {
753 .setup = ehl_pse1_sgmii1g_data,
756 static int tgl_common_data(struct pci_dev *pdev,
757 struct plat_stmmacenet_data *plat)
759 plat->rx_queues_to_use = 6;
760 plat->tx_queues_to_use = 4;
761 plat->clk_ptp_rate = 200000000;
762 plat->speed_mode_2500 = intel_speed_mode_2500;
764 plat->safety_feat_cfg->tsoee = 1;
765 plat->safety_feat_cfg->mrxpee = 0;
766 plat->safety_feat_cfg->mestee = 1;
767 plat->safety_feat_cfg->mrxee = 1;
768 plat->safety_feat_cfg->mtxee = 1;
769 plat->safety_feat_cfg->epsi = 0;
770 plat->safety_feat_cfg->edpp = 0;
771 plat->safety_feat_cfg->prtyen = 0;
772 plat->safety_feat_cfg->tmouten = 0;
774 return intel_mgbe_common_data(pdev, plat);
777 static int tgl_sgmii_phy0_data(struct pci_dev *pdev,
778 struct plat_stmmacenet_data *plat)
781 plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
782 plat->serdes_powerup = intel_serdes_powerup;
783 plat->serdes_powerdown = intel_serdes_powerdown;
784 return tgl_common_data(pdev, plat);
787 static struct stmmac_pci_info tgl_sgmii1g_phy0_info = {
788 .setup = tgl_sgmii_phy0_data,
791 static int tgl_sgmii_phy1_data(struct pci_dev *pdev,
792 struct plat_stmmacenet_data *plat)
795 plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
796 plat->serdes_powerup = intel_serdes_powerup;
797 plat->serdes_powerdown = intel_serdes_powerdown;
798 return tgl_common_data(pdev, plat);
801 static struct stmmac_pci_info tgl_sgmii1g_phy1_info = {
802 .setup = tgl_sgmii_phy1_data,
805 static int adls_sgmii_phy0_data(struct pci_dev *pdev,
806 struct plat_stmmacenet_data *plat)
809 plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
811 /* SerDes power up and power down are done in BIOS for ADL */
813 return tgl_common_data(pdev, plat);
816 static struct stmmac_pci_info adls_sgmii1g_phy0_info = {
817 .setup = adls_sgmii_phy0_data,
820 static int adls_sgmii_phy1_data(struct pci_dev *pdev,
821 struct plat_stmmacenet_data *plat)
824 plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
826 /* SerDes power up and power down are done in BIOS for ADL */
828 return tgl_common_data(pdev, plat);
831 static struct stmmac_pci_info adls_sgmii1g_phy1_info = {
832 .setup = adls_sgmii_phy1_data,
834 static const struct stmmac_pci_func_data galileo_stmmac_func_data[] = {
841 static const struct stmmac_pci_dmi_data galileo_stmmac_dmi_data = {
842 .func = galileo_stmmac_func_data,
843 .nfuncs = ARRAY_SIZE(galileo_stmmac_func_data),
846 static const struct stmmac_pci_func_data iot2040_stmmac_func_data[] = {
857 static const struct stmmac_pci_dmi_data iot2040_stmmac_dmi_data = {
858 .func = iot2040_stmmac_func_data,
859 .nfuncs = ARRAY_SIZE(iot2040_stmmac_func_data),
862 static const struct dmi_system_id quark_pci_dmi[] = {
865 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Galileo"),
867 .driver_data = (void *)&galileo_stmmac_dmi_data,
871 DMI_EXACT_MATCH(DMI_BOARD_NAME, "GalileoGen2"),
873 .driver_data = (void *)&galileo_stmmac_dmi_data,
875 /* There are 2 types of SIMATIC IOT2000: IOT2020 and IOT2040.
876 * The asset tag "6ES7647-0AA00-0YA2" is only for IOT2020 which
877 * has only one pci network device while other asset tags are
878 * for IOT2040 which has two.
882 DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"),
883 DMI_EXACT_MATCH(DMI_BOARD_ASSET_TAG,
884 "6ES7647-0AA00-0YA2"),
886 .driver_data = (void *)&galileo_stmmac_dmi_data,
890 DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"),
892 .driver_data = (void *)&iot2040_stmmac_dmi_data,
897 static int quark_default_data(struct pci_dev *pdev,
898 struct plat_stmmacenet_data *plat)
902 /* Set common default data first */
903 common_default_data(plat);
905 /* Refuse to load the driver and register net device if MAC controller
906 * does not connect to any PHY interface.
908 ret = stmmac_pci_find_phy_addr(pdev, quark_pci_dmi);
910 /* Return error to the caller on DMI enabled boards. */
911 if (dmi_get_system_info(DMI_BOARD_NAME))
914 /* Galileo boards with old firmware don't support DMI. We always
915 * use 1 here as PHY address, so at least the first found MAC
916 * controller would be probed.
921 plat->bus_id = pci_dev_id(pdev);
922 plat->phy_addr = ret;
923 plat->phy_interface = PHY_INTERFACE_MODE_RMII;
925 plat->dma_cfg->pbl = 16;
926 plat->dma_cfg->pblx8 = true;
927 plat->dma_cfg->fixed_burst = 1;
933 static const struct stmmac_pci_info quark_info = {
934 .setup = quark_default_data,
937 static int stmmac_config_single_msi(struct pci_dev *pdev,
938 struct plat_stmmacenet_data *plat,
939 struct stmmac_resources *res)
943 ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
945 dev_info(&pdev->dev, "%s: Single IRQ enablement failed\n",
950 res->irq = pci_irq_vector(pdev, 0);
951 res->wol_irq = res->irq;
952 plat->multi_msi_en = 0;
953 dev_info(&pdev->dev, "%s: Single IRQ enablement successful\n",
959 static int stmmac_config_multi_msi(struct pci_dev *pdev,
960 struct plat_stmmacenet_data *plat,
961 struct stmmac_resources *res)
966 if (plat->msi_rx_base_vec >= STMMAC_MSI_VEC_MAX ||
967 plat->msi_tx_base_vec >= STMMAC_MSI_VEC_MAX) {
968 dev_info(&pdev->dev, "%s: Invalid RX & TX vector defined\n",
973 ret = pci_alloc_irq_vectors(pdev, 2, STMMAC_MSI_VEC_MAX,
974 PCI_IRQ_MSI | PCI_IRQ_MSIX);
976 dev_info(&pdev->dev, "%s: multi MSI enablement failed\n",
982 for (i = 0; i < plat->rx_queues_to_use; i++) {
983 res->rx_irq[i] = pci_irq_vector(pdev,
984 plat->msi_rx_base_vec + i * 2);
988 for (i = 0; i < plat->tx_queues_to_use; i++) {
989 res->tx_irq[i] = pci_irq_vector(pdev,
990 plat->msi_tx_base_vec + i * 2);
993 if (plat->msi_mac_vec < STMMAC_MSI_VEC_MAX)
994 res->irq = pci_irq_vector(pdev, plat->msi_mac_vec);
995 if (plat->msi_wol_vec < STMMAC_MSI_VEC_MAX)
996 res->wol_irq = pci_irq_vector(pdev, plat->msi_wol_vec);
997 if (plat->msi_lpi_vec < STMMAC_MSI_VEC_MAX)
998 res->lpi_irq = pci_irq_vector(pdev, plat->msi_lpi_vec);
999 if (plat->msi_sfty_ce_vec < STMMAC_MSI_VEC_MAX)
1000 res->sfty_ce_irq = pci_irq_vector(pdev, plat->msi_sfty_ce_vec);
1001 if (plat->msi_sfty_ue_vec < STMMAC_MSI_VEC_MAX)
1002 res->sfty_ue_irq = pci_irq_vector(pdev, plat->msi_sfty_ue_vec);
1004 plat->multi_msi_en = 1;
1005 dev_info(&pdev->dev, "%s: multi MSI enablement successful\n", __func__);
1011 * intel_eth_pci_probe
1013 * @pdev: pci device pointer
1014 * @id: pointer to table of device id/id's.
1016 * Description: This probing function gets called for all PCI devices which
1017 * match the ID table and are not "owned" by other driver yet. This function
1018 * gets passed a "struct pci_dev *" for each device whose entry in the ID table
1019 * matches the device. The probe functions returns zero when the driver choose
1020 * to take "ownership" of the device or an error code(-ve no) otherwise.
1022 static int intel_eth_pci_probe(struct pci_dev *pdev,
1023 const struct pci_device_id *id)
1025 struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
1026 struct intel_priv_data *intel_priv;
1027 struct plat_stmmacenet_data *plat;
1028 struct stmmac_resources res;
1031 intel_priv = devm_kzalloc(&pdev->dev, sizeof(*intel_priv), GFP_KERNEL);
1035 plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
1039 plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
1040 sizeof(*plat->mdio_bus_data),
1042 if (!plat->mdio_bus_data)
1045 plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
1050 plat->safety_feat_cfg = devm_kzalloc(&pdev->dev,
1051 sizeof(*plat->safety_feat_cfg),
1053 if (!plat->safety_feat_cfg)
1056 /* Enable pci device */
1057 ret = pcim_enable_device(pdev);
1059 dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
1064 ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
1068 pci_set_master(pdev);
1070 plat->bsp_priv = intel_priv;
1071 intel_priv->mdio_adhoc_addr = INTEL_MGBE_ADHOC_ADDR;
1072 intel_priv->crossts_adj = 1;
1074 /* Initialize all MSI vectors to invalid so that it can be set
1075 * according to platform data settings below.
1076 * Note: MSI vector takes value from 0 upto 31 (STMMAC_MSI_VEC_MAX)
1078 plat->msi_mac_vec = STMMAC_MSI_VEC_MAX;
1079 plat->msi_wol_vec = STMMAC_MSI_VEC_MAX;
1080 plat->msi_lpi_vec = STMMAC_MSI_VEC_MAX;
1081 plat->msi_sfty_ce_vec = STMMAC_MSI_VEC_MAX;
1082 plat->msi_sfty_ue_vec = STMMAC_MSI_VEC_MAX;
1083 plat->msi_rx_base_vec = STMMAC_MSI_VEC_MAX;
1084 plat->msi_tx_base_vec = STMMAC_MSI_VEC_MAX;
1086 ret = info->setup(pdev, plat);
1090 memset(&res, 0, sizeof(res));
1091 res.addr = pcim_iomap_table(pdev)[0];
1093 if (plat->eee_usecs_rate > 0) {
1096 tx_lpi_usec = (plat->eee_usecs_rate / 1000000) - 1;
1097 writel(tx_lpi_usec, res.addr + GMAC_1US_TIC_COUNTER);
1100 ret = stmmac_config_multi_msi(pdev, plat, &res);
1102 ret = stmmac_config_single_msi(pdev, plat, &res);
1104 dev_err(&pdev->dev, "%s: ERROR: failed to enable IRQ\n",
1110 ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
1118 clk_disable_unprepare(plat->stmmac_clk);
1119 clk_unregister_fixed_rate(plat->stmmac_clk);
1124 * intel_eth_pci_remove
1126 * @pdev: pci device pointer
1127 * Description: this function calls the main to free the net resources
1128 * and releases the PCI resources.
1130 static void intel_eth_pci_remove(struct pci_dev *pdev)
1132 struct net_device *ndev = dev_get_drvdata(&pdev->dev);
1133 struct stmmac_priv *priv = netdev_priv(ndev);
1135 stmmac_dvr_remove(&pdev->dev);
1137 clk_disable_unprepare(priv->plat->stmmac_clk);
1138 clk_unregister_fixed_rate(priv->plat->stmmac_clk);
1140 pcim_iounmap_regions(pdev, BIT(0));
1143 static int __maybe_unused intel_eth_pci_suspend(struct device *dev)
1145 struct pci_dev *pdev = to_pci_dev(dev);
1148 ret = stmmac_suspend(dev);
1152 ret = pci_save_state(pdev);
1156 pci_wake_from_d3(pdev, true);
1157 pci_set_power_state(pdev, PCI_D3hot);
1161 static int __maybe_unused intel_eth_pci_resume(struct device *dev)
1163 struct pci_dev *pdev = to_pci_dev(dev);
1166 pci_restore_state(pdev);
1167 pci_set_power_state(pdev, PCI_D0);
1169 ret = pcim_enable_device(pdev);
1173 pci_set_master(pdev);
1175 return stmmac_resume(dev);
1178 static SIMPLE_DEV_PM_OPS(intel_eth_pm_ops, intel_eth_pci_suspend,
1179 intel_eth_pci_resume);
1181 #define PCI_DEVICE_ID_INTEL_QUARK 0x0937
1182 #define PCI_DEVICE_ID_INTEL_EHL_RGMII1G 0x4b30
1183 #define PCI_DEVICE_ID_INTEL_EHL_SGMII1G 0x4b31
1184 #define PCI_DEVICE_ID_INTEL_EHL_SGMII2G5 0x4b32
1185 /* Intel(R) Programmable Services Engine (Intel(R) PSE) consist of 2 MAC
1186 * which are named PSE0 and PSE1
1188 #define PCI_DEVICE_ID_INTEL_EHL_PSE0_RGMII1G 0x4ba0
1189 #define PCI_DEVICE_ID_INTEL_EHL_PSE0_SGMII1G 0x4ba1
1190 #define PCI_DEVICE_ID_INTEL_EHL_PSE0_SGMII2G5 0x4ba2
1191 #define PCI_DEVICE_ID_INTEL_EHL_PSE1_RGMII1G 0x4bb0
1192 #define PCI_DEVICE_ID_INTEL_EHL_PSE1_SGMII1G 0x4bb1
1193 #define PCI_DEVICE_ID_INTEL_EHL_PSE1_SGMII2G5 0x4bb2
1194 #define PCI_DEVICE_ID_INTEL_TGLH_SGMII1G_0 0x43ac
1195 #define PCI_DEVICE_ID_INTEL_TGLH_SGMII1G_1 0x43a2
1196 #define PCI_DEVICE_ID_INTEL_TGL_SGMII1G 0xa0ac
1197 #define PCI_DEVICE_ID_INTEL_ADLS_SGMII1G_0 0x7aac
1198 #define PCI_DEVICE_ID_INTEL_ADLS_SGMII1G_1 0x7aad
1199 #define PCI_DEVICE_ID_INTEL_ADLN_SGMII1G 0x54ac
1200 #define PCI_DEVICE_ID_INTEL_RPLP_SGMII1G 0x51ac
1202 static const struct pci_device_id intel_eth_pci_id_table[] = {
1203 { PCI_DEVICE_DATA(INTEL, QUARK, &quark_info) },
1204 { PCI_DEVICE_DATA(INTEL, EHL_RGMII1G, &ehl_rgmii1g_info) },
1205 { PCI_DEVICE_DATA(INTEL, EHL_SGMII1G, &ehl_sgmii1g_info) },
1206 { PCI_DEVICE_DATA(INTEL, EHL_SGMII2G5, &ehl_sgmii1g_info) },
1207 { PCI_DEVICE_DATA(INTEL, EHL_PSE0_RGMII1G, &ehl_pse0_rgmii1g_info) },
1208 { PCI_DEVICE_DATA(INTEL, EHL_PSE0_SGMII1G, &ehl_pse0_sgmii1g_info) },
1209 { PCI_DEVICE_DATA(INTEL, EHL_PSE0_SGMII2G5, &ehl_pse0_sgmii1g_info) },
1210 { PCI_DEVICE_DATA(INTEL, EHL_PSE1_RGMII1G, &ehl_pse1_rgmii1g_info) },
1211 { PCI_DEVICE_DATA(INTEL, EHL_PSE1_SGMII1G, &ehl_pse1_sgmii1g_info) },
1212 { PCI_DEVICE_DATA(INTEL, EHL_PSE1_SGMII2G5, &ehl_pse1_sgmii1g_info) },
1213 { PCI_DEVICE_DATA(INTEL, TGL_SGMII1G, &tgl_sgmii1g_phy0_info) },
1214 { PCI_DEVICE_DATA(INTEL, TGLH_SGMII1G_0, &tgl_sgmii1g_phy0_info) },
1215 { PCI_DEVICE_DATA(INTEL, TGLH_SGMII1G_1, &tgl_sgmii1g_phy1_info) },
1216 { PCI_DEVICE_DATA(INTEL, ADLS_SGMII1G_0, &adls_sgmii1g_phy0_info) },
1217 { PCI_DEVICE_DATA(INTEL, ADLS_SGMII1G_1, &adls_sgmii1g_phy1_info) },
1218 { PCI_DEVICE_DATA(INTEL, ADLN_SGMII1G, &tgl_sgmii1g_phy0_info) },
1219 { PCI_DEVICE_DATA(INTEL, RPLP_SGMII1G, &tgl_sgmii1g_phy0_info) },
1222 MODULE_DEVICE_TABLE(pci, intel_eth_pci_id_table);
1224 static struct pci_driver intel_eth_pci_driver = {
1225 .name = "intel-eth-pci",
1226 .id_table = intel_eth_pci_id_table,
1227 .probe = intel_eth_pci_probe,
1228 .remove = intel_eth_pci_remove,
1230 .pm = &intel_eth_pm_ops,
1234 module_pci_driver(intel_eth_pci_driver);
1236 MODULE_DESCRIPTION("INTEL 10/100/1000 Ethernet PCI driver");
1237 MODULE_AUTHOR("Voon Weifeng <weifeng.voon@intel.com>");
1238 MODULE_LICENSE("GPL v2");