Lines Matching +full:gen +full:- +full:2

1 // SPDX-License-Identifier: GPL-2.0
28 #include "../pci-bridge-emul.h"
35 #define PCIE_CORE_CMD_MEM_IO_REQ_EN BIT(2)
44 #define PCIE_CORE_INT_B_ASSERT_ENABLE 2
57 #define PIO_COMPLETION_STATUS_CRS 2
76 #define SPEED_GEN_3 2
78 #define IS_RC_SHIFT 2
83 #define LANE_COUNT_4 (2 << LANE_CNT_SHIFT)
176 #define PIO_RETRY_DELAY 2 /* 2 us*/
207 writel(val, pcie->base + reg); in advk_writel()
212 return readl(pcie->base + reg); in advk_readl()
241 return -ETIMEDOUT; in advk_pcie_wait_for_link()
259 if (!pcie->reset_gpio) in advk_pcie_issue_perst()
268 dev_info(&pcie->pdev->dev, "issuing PERST via reset GPIO for 10ms\n"); in advk_pcie_issue_perst()
269 gpiod_set_value_cansleep(pcie->reset_gpio, 1); in advk_pcie_issue_perst()
271 gpiod_set_value_cansleep(pcie->reset_gpio, 0); in advk_pcie_issue_perst()
274 static int advk_pcie_train_at_gen(struct advk_pcie *pcie, int gen) in advk_pcie_train_at_gen() argument
282 if (gen == 3) in advk_pcie_train_at_gen()
284 else if (gen == 2) in advk_pcie_train_at_gen()
318 struct device *dev = &pcie->pdev->dev; in advk_pcie_train_link()
319 int neg_gen = -1, gen; in advk_pcie_train_link() local
323 * during link training when they are in some non-initial state. in advk_pcie_train_link()
337 * Try link training at link gen specified by device tree property in advk_pcie_train_link()
338 * 'max-link-speed'. If this fails, iteratively train at lower gen. in advk_pcie_train_link()
340 for (gen = pcie->link_gen; gen > 0; --gen) { in advk_pcie_train_link()
341 neg_gen = advk_pcie_train_at_gen(pcie, gen); in advk_pcie_train_link()
350 * After successful training if negotiated gen is lower than requested, in advk_pcie_train_link()
351 * train again on negotiated gen. This solves some stability issues for in advk_pcie_train_link()
354 if (neg_gen < gen) { in advk_pcie_train_link()
355 gen = neg_gen; in advk_pcie_train_link()
356 neg_gen = advk_pcie_train_at_gen(pcie, gen); in advk_pcie_train_link()
359 if (neg_gen == gen) { in advk_pcie_train_link()
360 dev_info(dev, "link up at gen %i\n", gen); in advk_pcie_train_link()
404 /* Program PCIe Control 2 to disable strict ordering */ in advk_pcie_setup_hw()
466 struct device *dev = &pcie->pdev->dev; in advk_pcie_check_pio_status()
494 str_posted = "Non-posted"; in advk_pcie_check_pio_status()
504 struct device *dev = &pcie->pdev->dev; in advk_pcie_wait_pio()
518 return -ETIMEDOUT; in advk_pcie_wait_pio()
526 struct advk_pcie *pcie = bridge->data; in advk_pci_bridge_emul_pcie_conf_read()
573 struct advk_pcie *pcie = bridge->data; in advk_pci_bridge_emul_pcie_conf_write()
612 * Initialize the configuration space of the PCI-to-PCI bridge
617 struct pci_bridge_emul *bridge = &pcie->bridge; in advk_sw_pci_bridge_init()
619 bridge->conf.vendor = in advk_sw_pci_bridge_init()
621 bridge->conf.device = in advk_sw_pci_bridge_init()
623 bridge->conf.class_revision = in advk_sw_pci_bridge_init()
627 bridge->conf.iobase = PCI_IO_RANGE_TYPE_32; in advk_sw_pci_bridge_init()
628 bridge->conf.iolimit = PCI_IO_RANGE_TYPE_32; in advk_sw_pci_bridge_init()
631 bridge->conf.pref_mem_base = cpu_to_le16(PCI_PREF_RANGE_TYPE_64); in advk_sw_pci_bridge_init()
632 bridge->conf.pref_mem_limit = cpu_to_le16(PCI_PREF_RANGE_TYPE_64); in advk_sw_pci_bridge_init()
635 bridge->conf.intpin = PCIE_CORE_INT_A_ASSERT_ENABLE; in advk_sw_pci_bridge_init()
637 bridge->has_pcie = true; in advk_sw_pci_bridge_init()
638 bridge->data = pcie; in advk_sw_pci_bridge_init()
639 bridge->ops = &advk_pci_bridge_emul_ops; in advk_sw_pci_bridge_init()
651 * If the link goes down after we check for link-up, nothing bad in advk_pcie_valid_device()
663 struct advk_pcie *pcie = bus->sysdata; in advk_pcie_rd_conf()
673 return pci_bridge_emul_conf_read(&pcie->bridge, where, in advk_pcie_rd_conf()
683 if (pci_is_root_bus(bus->parent)) in advk_pcie_rd_conf()
690 reg = PCIE_CONF_ADDR(bus->number, devfn, where); in advk_pcie_rd_conf()
712 else if (size == 2) in advk_pcie_rd_conf()
721 struct advk_pcie *pcie = bus->sysdata; in advk_pcie_wr_conf()
731 return pci_bridge_emul_conf_write(&pcie->bridge, where, in advk_pcie_wr_conf()
744 if (pci_is_root_bus(bus->parent)) in advk_pcie_wr_conf()
751 reg = PCIE_CONF_ADDR(bus->number, devfn, where); in advk_pcie_wr_conf()
758 data_strobe = GENMASK(size - 1, 0) << offset; in advk_pcie_wr_conf()
787 phys_addr_t msi_msg = virt_to_phys(&pcie->msi_msg); in advk_msi_irq_compose_msi_msg()
789 msg->address_lo = lower_32_bits(msi_msg); in advk_msi_irq_compose_msi_msg()
790 msg->address_hi = upper_32_bits(msi_msg); in advk_msi_irq_compose_msi_msg()
791 msg->data = data->irq; in advk_msi_irq_compose_msi_msg()
797 return -EINVAL; in advk_msi_set_affinity()
804 struct advk_pcie *pcie = domain->host_data; in advk_msi_irq_domain_alloc()
807 mutex_lock(&pcie->msi_used_lock); in advk_msi_irq_domain_alloc()
808 hwirq = bitmap_find_next_zero_area(pcie->msi_used, MSI_IRQ_NUM, in advk_msi_irq_domain_alloc()
811 mutex_unlock(&pcie->msi_used_lock); in advk_msi_irq_domain_alloc()
812 return -ENOSPC; in advk_msi_irq_domain_alloc()
815 bitmap_set(pcie->msi_used, hwirq, nr_irqs); in advk_msi_irq_domain_alloc()
816 mutex_unlock(&pcie->msi_used_lock); in advk_msi_irq_domain_alloc()
820 &pcie->msi_bottom_irq_chip, in advk_msi_irq_domain_alloc()
821 domain->host_data, handle_simple_irq, in advk_msi_irq_domain_alloc()
831 struct advk_pcie *pcie = domain->host_data; in advk_msi_irq_domain_free()
833 mutex_lock(&pcie->msi_used_lock); in advk_msi_irq_domain_free()
834 bitmap_clear(pcie->msi_used, d->hwirq, nr_irqs); in advk_msi_irq_domain_free()
835 mutex_unlock(&pcie->msi_used_lock); in advk_msi_irq_domain_free()
845 struct advk_pcie *pcie = d->domain->host_data; in advk_pcie_irq_mask()
856 struct advk_pcie *pcie = d->domain->host_data; in advk_pcie_irq_unmask()
868 struct advk_pcie *pcie = h->host_data; in advk_pcie_irq_map()
872 irq_set_chip_and_handler(virq, &pcie->irq_chip, in advk_pcie_irq_map()
886 struct device *dev = &pcie->pdev->dev; in advk_pcie_init_msi_irq_domain()
887 struct device_node *node = dev->of_node; in advk_pcie_init_msi_irq_domain()
892 mutex_init(&pcie->msi_used_lock); in advk_pcie_init_msi_irq_domain()
894 bottom_ic = &pcie->msi_bottom_irq_chip; in advk_pcie_init_msi_irq_domain()
896 bottom_ic->name = "MSI"; in advk_pcie_init_msi_irq_domain()
897 bottom_ic->irq_compose_msi_msg = advk_msi_irq_compose_msi_msg; in advk_pcie_init_msi_irq_domain()
898 bottom_ic->irq_set_affinity = advk_msi_set_affinity; in advk_pcie_init_msi_irq_domain()
900 msi_ic = &pcie->msi_irq_chip; in advk_pcie_init_msi_irq_domain()
901 msi_ic->name = "advk-MSI"; in advk_pcie_init_msi_irq_domain()
903 msi_di = &pcie->msi_domain_info; in advk_pcie_init_msi_irq_domain()
904 msi_di->flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | in advk_pcie_init_msi_irq_domain()
906 msi_di->chip = msi_ic; in advk_pcie_init_msi_irq_domain()
908 msi_msg_phys = virt_to_phys(&pcie->msi_msg); in advk_pcie_init_msi_irq_domain()
915 pcie->msi_inner_domain = in advk_pcie_init_msi_irq_domain()
918 if (!pcie->msi_inner_domain) in advk_pcie_init_msi_irq_domain()
919 return -ENOMEM; in advk_pcie_init_msi_irq_domain()
921 pcie->msi_domain = in advk_pcie_init_msi_irq_domain()
923 msi_di, pcie->msi_inner_domain); in advk_pcie_init_msi_irq_domain()
924 if (!pcie->msi_domain) { in advk_pcie_init_msi_irq_domain()
925 irq_domain_remove(pcie->msi_inner_domain); in advk_pcie_init_msi_irq_domain()
926 return -ENOMEM; in advk_pcie_init_msi_irq_domain()
934 irq_domain_remove(pcie->msi_domain); in advk_pcie_remove_msi_irq_domain()
935 irq_domain_remove(pcie->msi_inner_domain); in advk_pcie_remove_msi_irq_domain()
940 struct device *dev = &pcie->pdev->dev; in advk_pcie_init_irq_domain()
941 struct device_node *node = dev->of_node; in advk_pcie_init_irq_domain()
949 return -ENODEV; in advk_pcie_init_irq_domain()
952 irq_chip = &pcie->irq_chip; in advk_pcie_init_irq_domain()
954 irq_chip->name = devm_kasprintf(dev, GFP_KERNEL, "%s-irq", in advk_pcie_init_irq_domain()
956 if (!irq_chip->name) { in advk_pcie_init_irq_domain()
957 ret = -ENOMEM; in advk_pcie_init_irq_domain()
961 irq_chip->irq_mask = advk_pcie_irq_mask; in advk_pcie_init_irq_domain()
962 irq_chip->irq_mask_ack = advk_pcie_irq_mask; in advk_pcie_init_irq_domain()
963 irq_chip->irq_unmask = advk_pcie_irq_unmask; in advk_pcie_init_irq_domain()
965 pcie->irq_domain = in advk_pcie_init_irq_domain()
968 if (!pcie->irq_domain) { in advk_pcie_init_irq_domain()
970 ret = -ENOMEM; in advk_pcie_init_irq_domain()
981 irq_domain_remove(pcie->irq_domain); in advk_pcie_remove_irq_domain()
1038 virq = irq_find_mapping(pcie->irq_domain, i); in advk_pcie_handle_int()
1062 phy_power_off(pcie->phy); in advk_pcie_disable_phy()
1063 phy_exit(pcie->phy); in advk_pcie_disable_phy()
1070 if (!pcie->phy) in advk_pcie_enable_phy()
1073 ret = phy_init(pcie->phy); in advk_pcie_enable_phy()
1077 ret = phy_set_mode(pcie->phy, PHY_MODE_PCIE); in advk_pcie_enable_phy()
1079 phy_exit(pcie->phy); in advk_pcie_enable_phy()
1083 ret = phy_power_on(pcie->phy); in advk_pcie_enable_phy()
1084 if (ret == -EOPNOTSUPP) { in advk_pcie_enable_phy()
1085 dev_warn(&pcie->pdev->dev, "PHY unsupported by firmware\n"); in advk_pcie_enable_phy()
1087 phy_exit(pcie->phy); in advk_pcie_enable_phy()
1096 struct device *dev = &pcie->pdev->dev; in advk_pcie_setup_phy()
1097 struct device_node *node = dev->of_node; in advk_pcie_setup_phy()
1100 pcie->phy = devm_of_phy_get(dev, node, NULL); in advk_pcie_setup_phy()
1101 if (IS_ERR(pcie->phy) && (PTR_ERR(pcie->phy) == -EPROBE_DEFER)) in advk_pcie_setup_phy()
1102 return PTR_ERR(pcie->phy); in advk_pcie_setup_phy()
1105 if (IS_ERR(pcie->phy)) { in advk_pcie_setup_phy()
1106 dev_warn(dev, "PHY unavailable (%ld)\n", PTR_ERR(pcie->phy)); in advk_pcie_setup_phy()
1107 pcie->phy = NULL; in advk_pcie_setup_phy()
1120 struct device *dev = &pdev->dev; in advk_pcie_probe()
1127 return -ENOMEM; in advk_pcie_probe()
1130 pcie->pdev = pdev; in advk_pcie_probe()
1133 pcie->base = devm_platform_ioremap_resource(pdev, 0); in advk_pcie_probe()
1134 if (IS_ERR(pcie->base)) in advk_pcie_probe()
1135 return PTR_ERR(pcie->base); in advk_pcie_probe()
1142 IRQF_SHARED | IRQF_NO_THREAD, "advk-pcie", in advk_pcie_probe()
1149 pcie->reset_gpio = devm_gpiod_get_from_of_node(dev, dev->of_node, in advk_pcie_probe()
1150 "reset-gpios", 0, in advk_pcie_probe()
1152 "pcie1-reset"); in advk_pcie_probe()
1153 ret = PTR_ERR_OR_ZERO(pcie->reset_gpio); in advk_pcie_probe()
1155 if (ret == -ENOENT) { in advk_pcie_probe()
1156 pcie->reset_gpio = NULL; in advk_pcie_probe()
1158 if (ret != -EPROBE_DEFER) in advk_pcie_probe()
1159 dev_err(dev, "Failed to get reset-gpio: %i\n", in advk_pcie_probe()
1165 ret = of_pci_get_max_link_speed(dev->of_node); in advk_pcie_probe()
1167 pcie->link_gen = 3; in advk_pcie_probe()
1169 pcie->link_gen = ret; in advk_pcie_probe()
1196 bridge->sysdata = pcie; in advk_pcie_probe()
1197 bridge->ops = &advk_pcie_ops; in advk_pcie_probe()
1215 pci_stop_root_bus(bridge->bus); in advk_pcie_remove()
1216 pci_remove_root_bus(bridge->bus); in advk_pcie_remove()
1226 { .compatible = "marvell,armada-3700-pcie", },
1233 .name = "advk-pcie",