Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-dsa-microchip-ksz9477-enable-interrupt-for-internal-phy-link-detection'

Arun Ramadoss says:

====================
net: dsa: microchip: ksz9477: enable interrupt for internal phy link detection

This patch series implements the common interrupt handling for ksz9477 based
switches and lan937x. The ksz9477 and lan937x has similar interrupt registers
except ksz9477 has 4 port based interrupts whereas lan937x has 6 interrupts.
The patch moves the phy interrupt hanler implemented in lan937x_main.c to
ksz_common.c, along with the mdio_register functionality.
====================

Link: https://lore.kernel.org/r/20220922071028.18012-1-arun.ramadoss@microchip.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+336 -428
+320
drivers/net/dsa/microchip/ksz_common.c
··· 14 14 #include <linux/phy.h> 15 15 #include <linux/etherdevice.h> 16 16 #include <linux/if_bridge.h> 17 + #include <linux/irq.h> 18 + #include <linux/irqdomain.h> 19 + #include <linux/of_mdio.h> 17 20 #include <linux/of_device.h> 18 21 #include <linux/of_net.h> 19 22 #include <linux/micrel_phy.h> ··· 1171 1168 .num_statics = 16, 1172 1169 .cpu_ports = 0x7F, /* can be configured as cpu port */ 1173 1170 .port_cnt = 7, /* total physical port count */ 1171 + .port_nirqs = 4, 1174 1172 .ops = &ksz9477_dev_ops, 1175 1173 .phy_errata_9477 = true, 1176 1174 .mib_names = ksz9477_mib_names, ··· 1203 1199 .num_statics = 16, 1204 1200 .cpu_ports = 0x3F, /* can be configured as cpu port */ 1205 1201 .port_cnt = 6, /* total physical port count */ 1202 + .port_nirqs = 2, 1206 1203 .ops = &ksz9477_dev_ops, 1207 1204 .phy_errata_9477 = true, 1208 1205 .mib_names = ksz9477_mib_names, ··· 1235 1230 .num_statics = 16, 1236 1231 .cpu_ports = 0x7F, /* can be configured as cpu port */ 1237 1232 .port_cnt = 7, /* total physical port count */ 1233 + .port_nirqs = 2, 1238 1234 .ops = &ksz9477_dev_ops, 1239 1235 .phy_errata_9477 = true, 1240 1236 .mib_names = ksz9477_mib_names, ··· 1265 1259 .num_statics = 16, 1266 1260 .cpu_ports = 0x07, /* can be configured as cpu port */ 1267 1261 .port_cnt = 3, /* total port count */ 1262 + .port_nirqs = 2, 1268 1263 .ops = &ksz9477_dev_ops, 1269 1264 .mib_names = ksz9477_mib_names, 1270 1265 .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), ··· 1290 1283 .num_statics = 16, 1291 1284 .cpu_ports = 0x7F, /* can be configured as cpu port */ 1292 1285 .port_cnt = 7, /* total physical port count */ 1286 + .port_nirqs = 3, 1293 1287 .ops = &ksz9477_dev_ops, 1294 1288 .phy_errata_9477 = true, 1295 1289 .mib_names = ksz9477_mib_names, ··· 1320 1312 .num_statics = 256, 1321 1313 .cpu_ports = 0x10, /* can be configured as cpu port */ 1322 1314 .port_cnt = 5, /* total physical port count */ 1315 + .port_nirqs = 6, 1323 1316 .ops = &lan937x_dev_ops, 1324 1317 .mib_names = ksz9477_mib_names, 1325 1318 .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), ··· 1344 1335 .num_statics = 256, 1345 1336 .cpu_ports = 0x30, /* can be configured as cpu port */ 1346 1337 .port_cnt = 6, /* total physical port count */ 1338 + .port_nirqs = 6, 1347 1339 .ops = &lan937x_dev_ops, 1348 1340 .mib_names = ksz9477_mib_names, 1349 1341 .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), ··· 1368 1358 .num_statics = 256, 1369 1359 .cpu_ports = 0x30, /* can be configured as cpu port */ 1370 1360 .port_cnt = 8, /* total physical port count */ 1361 + .port_nirqs = 6, 1371 1362 .ops = &lan937x_dev_ops, 1372 1363 .mib_names = ksz9477_mib_names, 1373 1364 .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), ··· 1396 1385 .num_statics = 256, 1397 1386 .cpu_ports = 0x38, /* can be configured as cpu port */ 1398 1387 .port_cnt = 5, /* total physical port count */ 1388 + .port_nirqs = 6, 1399 1389 .ops = &lan937x_dev_ops, 1400 1390 .mib_names = ksz9477_mib_names, 1401 1391 .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), ··· 1424 1412 .num_statics = 256, 1425 1413 .cpu_ports = 0x30, /* can be configured as cpu port */ 1426 1414 .port_cnt = 8, /* total physical port count */ 1415 + .port_nirqs = 6, 1427 1416 .ops = &lan937x_dev_ops, 1428 1417 .mib_names = ksz9477_mib_names, 1429 1418 .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), ··· 1656 1643 dev->dev_ops->cfg_port_member(dev, port, port_member | cpu_port); 1657 1644 } 1658 1645 1646 + static int ksz_sw_mdio_read(struct mii_bus *bus, int addr, int regnum) 1647 + { 1648 + struct ksz_device *dev = bus->priv; 1649 + u16 val; 1650 + int ret; 1651 + 1652 + if (regnum & MII_ADDR_C45) 1653 + return -EOPNOTSUPP; 1654 + 1655 + ret = dev->dev_ops->r_phy(dev, addr, regnum, &val); 1656 + if (ret < 0) 1657 + return ret; 1658 + 1659 + return val; 1660 + } 1661 + 1662 + static int ksz_sw_mdio_write(struct mii_bus *bus, int addr, int regnum, 1663 + u16 val) 1664 + { 1665 + struct ksz_device *dev = bus->priv; 1666 + 1667 + if (regnum & MII_ADDR_C45) 1668 + return -EOPNOTSUPP; 1669 + 1670 + return dev->dev_ops->w_phy(dev, addr, regnum, val); 1671 + } 1672 + 1673 + static int ksz_irq_phy_setup(struct ksz_device *dev) 1674 + { 1675 + struct dsa_switch *ds = dev->ds; 1676 + int phy; 1677 + int irq; 1678 + int ret; 1679 + 1680 + for (phy = 0; phy < KSZ_MAX_NUM_PORTS; phy++) { 1681 + if (BIT(phy) & ds->phys_mii_mask) { 1682 + irq = irq_find_mapping(dev->ports[phy].pirq.domain, 1683 + PORT_SRC_PHY_INT); 1684 + if (irq < 0) { 1685 + ret = irq; 1686 + goto out; 1687 + } 1688 + ds->slave_mii_bus->irq[phy] = irq; 1689 + } 1690 + } 1691 + return 0; 1692 + out: 1693 + while (phy--) 1694 + if (BIT(phy) & ds->phys_mii_mask) 1695 + irq_dispose_mapping(ds->slave_mii_bus->irq[phy]); 1696 + 1697 + return ret; 1698 + } 1699 + 1700 + static void ksz_irq_phy_free(struct ksz_device *dev) 1701 + { 1702 + struct dsa_switch *ds = dev->ds; 1703 + int phy; 1704 + 1705 + for (phy = 0; phy < KSZ_MAX_NUM_PORTS; phy++) 1706 + if (BIT(phy) & ds->phys_mii_mask) 1707 + irq_dispose_mapping(ds->slave_mii_bus->irq[phy]); 1708 + } 1709 + 1710 + static int ksz_mdio_register(struct ksz_device *dev) 1711 + { 1712 + struct dsa_switch *ds = dev->ds; 1713 + struct device_node *mdio_np; 1714 + struct mii_bus *bus; 1715 + int ret; 1716 + 1717 + mdio_np = of_get_child_by_name(dev->dev->of_node, "mdio"); 1718 + if (!mdio_np) 1719 + return 0; 1720 + 1721 + bus = devm_mdiobus_alloc(ds->dev); 1722 + if (!bus) { 1723 + of_node_put(mdio_np); 1724 + return -ENOMEM; 1725 + } 1726 + 1727 + bus->priv = dev; 1728 + bus->read = ksz_sw_mdio_read; 1729 + bus->write = ksz_sw_mdio_write; 1730 + bus->name = "ksz slave smi"; 1731 + snprintf(bus->id, MII_BUS_ID_SIZE, "SMI-%d", ds->index); 1732 + bus->parent = ds->dev; 1733 + bus->phy_mask = ~ds->phys_mii_mask; 1734 + 1735 + ds->slave_mii_bus = bus; 1736 + 1737 + if (dev->irq > 0) { 1738 + ret = ksz_irq_phy_setup(dev); 1739 + if (ret) { 1740 + of_node_put(mdio_np); 1741 + return ret; 1742 + } 1743 + } 1744 + 1745 + ret = devm_of_mdiobus_register(ds->dev, bus, mdio_np); 1746 + if (ret) { 1747 + dev_err(ds->dev, "unable to register MDIO bus %s\n", 1748 + bus->id); 1749 + if (dev->irq > 0) 1750 + ksz_irq_phy_free(dev); 1751 + } 1752 + 1753 + of_node_put(mdio_np); 1754 + 1755 + return ret; 1756 + } 1757 + 1758 + static void ksz_irq_mask(struct irq_data *d) 1759 + { 1760 + struct ksz_irq *kirq = irq_data_get_irq_chip_data(d); 1761 + 1762 + kirq->masked |= BIT(d->hwirq); 1763 + } 1764 + 1765 + static void ksz_irq_unmask(struct irq_data *d) 1766 + { 1767 + struct ksz_irq *kirq = irq_data_get_irq_chip_data(d); 1768 + 1769 + kirq->masked &= ~BIT(d->hwirq); 1770 + } 1771 + 1772 + static void ksz_irq_bus_lock(struct irq_data *d) 1773 + { 1774 + struct ksz_irq *kirq = irq_data_get_irq_chip_data(d); 1775 + 1776 + mutex_lock(&kirq->dev->lock_irq); 1777 + } 1778 + 1779 + static void ksz_irq_bus_sync_unlock(struct irq_data *d) 1780 + { 1781 + struct ksz_irq *kirq = irq_data_get_irq_chip_data(d); 1782 + struct ksz_device *dev = kirq->dev; 1783 + int ret; 1784 + 1785 + ret = ksz_write32(dev, kirq->reg_mask, kirq->masked); 1786 + if (ret) 1787 + dev_err(dev->dev, "failed to change IRQ mask\n"); 1788 + 1789 + mutex_unlock(&dev->lock_irq); 1790 + } 1791 + 1792 + static const struct irq_chip ksz_irq_chip = { 1793 + .name = "ksz-irq", 1794 + .irq_mask = ksz_irq_mask, 1795 + .irq_unmask = ksz_irq_unmask, 1796 + .irq_bus_lock = ksz_irq_bus_lock, 1797 + .irq_bus_sync_unlock = ksz_irq_bus_sync_unlock, 1798 + }; 1799 + 1800 + static int ksz_irq_domain_map(struct irq_domain *d, 1801 + unsigned int irq, irq_hw_number_t hwirq) 1802 + { 1803 + irq_set_chip_data(irq, d->host_data); 1804 + irq_set_chip_and_handler(irq, &ksz_irq_chip, handle_level_irq); 1805 + irq_set_noprobe(irq); 1806 + 1807 + return 0; 1808 + } 1809 + 1810 + static const struct irq_domain_ops ksz_irq_domain_ops = { 1811 + .map = ksz_irq_domain_map, 1812 + .xlate = irq_domain_xlate_twocell, 1813 + }; 1814 + 1815 + static void ksz_irq_free(struct ksz_irq *kirq) 1816 + { 1817 + int irq, virq; 1818 + 1819 + free_irq(kirq->irq_num, kirq); 1820 + 1821 + for (irq = 0; irq < kirq->nirqs; irq++) { 1822 + virq = irq_find_mapping(kirq->domain, irq); 1823 + irq_dispose_mapping(virq); 1824 + } 1825 + 1826 + irq_domain_remove(kirq->domain); 1827 + } 1828 + 1829 + static irqreturn_t ksz_irq_thread_fn(int irq, void *dev_id) 1830 + { 1831 + struct ksz_irq *kirq = dev_id; 1832 + unsigned int nhandled = 0; 1833 + struct ksz_device *dev; 1834 + unsigned int sub_irq; 1835 + u8 data; 1836 + int ret; 1837 + u8 n; 1838 + 1839 + dev = kirq->dev; 1840 + 1841 + /* Read interrupt status register */ 1842 + ret = ksz_read8(dev, kirq->reg_status, &data); 1843 + if (ret) 1844 + goto out; 1845 + 1846 + for (n = 0; n < kirq->nirqs; ++n) { 1847 + if (data & BIT(n)) { 1848 + sub_irq = irq_find_mapping(kirq->domain, n); 1849 + handle_nested_irq(sub_irq); 1850 + ++nhandled; 1851 + } 1852 + } 1853 + out: 1854 + return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE); 1855 + } 1856 + 1857 + static int ksz_irq_common_setup(struct ksz_device *dev, struct ksz_irq *kirq) 1858 + { 1859 + int ret, n; 1860 + 1861 + kirq->dev = dev; 1862 + kirq->masked = ~0; 1863 + 1864 + kirq->domain = irq_domain_add_simple(dev->dev->of_node, kirq->nirqs, 0, 1865 + &ksz_irq_domain_ops, kirq); 1866 + if (!kirq->domain) 1867 + return -ENOMEM; 1868 + 1869 + for (n = 0; n < kirq->nirqs; n++) 1870 + irq_create_mapping(kirq->domain, n); 1871 + 1872 + ret = request_threaded_irq(kirq->irq_num, NULL, ksz_irq_thread_fn, 1873 + IRQF_ONESHOT | IRQF_TRIGGER_FALLING, 1874 + kirq->name, kirq); 1875 + if (ret) 1876 + goto out; 1877 + 1878 + return 0; 1879 + 1880 + out: 1881 + ksz_irq_free(kirq); 1882 + 1883 + return ret; 1884 + } 1885 + 1886 + static int ksz_girq_setup(struct ksz_device *dev) 1887 + { 1888 + struct ksz_irq *girq = &dev->girq; 1889 + 1890 + girq->nirqs = dev->info->port_cnt; 1891 + girq->reg_mask = REG_SW_PORT_INT_MASK__1; 1892 + girq->reg_status = REG_SW_PORT_INT_STATUS__1; 1893 + snprintf(girq->name, sizeof(girq->name), "global_port_irq"); 1894 + 1895 + girq->irq_num = dev->irq; 1896 + 1897 + return ksz_irq_common_setup(dev, girq); 1898 + } 1899 + 1900 + static int ksz_pirq_setup(struct ksz_device *dev, u8 p) 1901 + { 1902 + struct ksz_irq *pirq = &dev->ports[p].pirq; 1903 + 1904 + pirq->nirqs = dev->info->port_nirqs; 1905 + pirq->reg_mask = dev->dev_ops->get_port_addr(p, REG_PORT_INT_MASK); 1906 + pirq->reg_status = dev->dev_ops->get_port_addr(p, REG_PORT_INT_STATUS); 1907 + snprintf(pirq->name, sizeof(pirq->name), "port_irq-%d", p); 1908 + 1909 + pirq->irq_num = irq_find_mapping(dev->girq.domain, p); 1910 + if (pirq->irq_num < 0) 1911 + return pirq->irq_num; 1912 + 1913 + return ksz_irq_common_setup(dev, pirq); 1914 + } 1915 + 1659 1916 static int ksz_setup(struct dsa_switch *ds) 1660 1917 { 1661 1918 struct ksz_device *dev = ds->priv; 1919 + struct dsa_port *dp; 1662 1920 struct ksz_port *p; 1663 1921 const u16 *regs; 1664 1922 int ret; ··· 1978 1694 p = &dev->ports[dev->cpu_port]; 1979 1695 p->learning = true; 1980 1696 1697 + if (dev->irq > 0) { 1698 + ret = ksz_girq_setup(dev); 1699 + if (ret) 1700 + return ret; 1701 + 1702 + dsa_switch_for_each_user_port(dp, dev->ds) { 1703 + ret = ksz_pirq_setup(dev, dp->index); 1704 + if (ret) 1705 + goto out_girq; 1706 + } 1707 + } 1708 + 1709 + ret = ksz_mdio_register(dev); 1710 + if (ret < 0) { 1711 + dev_err(dev->dev, "failed to register the mdio"); 1712 + goto out_pirq; 1713 + } 1714 + 1981 1715 /* start switch */ 1982 1716 regmap_update_bits(dev->regmap[0], regs[S_START_CTRL], 1983 1717 SW_START, SW_START); 1984 1718 1985 1719 return 0; 1720 + 1721 + out_pirq: 1722 + if (dev->irq > 0) 1723 + dsa_switch_for_each_user_port(dp, dev->ds) 1724 + ksz_irq_free(&dev->ports[dp->index].pirq); 1725 + out_girq: 1726 + if (dev->irq > 0) 1727 + ksz_irq_free(&dev->girq); 1728 + 1729 + return ret; 1986 1730 } 1987 1731 1988 1732 static void ksz_teardown(struct dsa_switch *ds) 1989 1733 { 1990 1734 struct ksz_device *dev = ds->priv; 1735 + struct dsa_port *dp; 1736 + 1737 + if (dev->irq > 0) { 1738 + dsa_switch_for_each_user_port(dp, dev->ds) 1739 + ksz_irq_free(&dev->ports[dp->index].pirq); 1740 + 1741 + ksz_irq_free(&dev->girq); 1742 + } 1991 1743 1992 1744 if (dev->dev_ops->teardown) 1993 1745 dev->dev_ops->teardown(ds);
+14 -1
drivers/net/dsa/microchip/ksz_common.h
··· 45 45 int num_statics; 46 46 int cpu_ports; 47 47 int port_cnt; 48 + u8 port_nirqs; 48 49 const struct ksz_dev_ops *ops; 49 50 bool phy_errata_9477; 50 51 bool ksz87xx_eee_link_erratum; ··· 72 71 73 72 struct ksz_irq { 74 73 u16 masked; 75 - struct irq_chip chip; 74 + u16 reg_mask; 75 + u16 reg_status; 76 76 struct irq_domain *domain; 77 77 int nirqs; 78 + int irq_num; 78 79 char name[16]; 80 + struct ksz_device *dev; 79 81 }; 80 82 81 83 struct ksz_port { ··· 575 571 #define P_RGMII_ID_EG_ENABLE BIT(3) 576 572 #define P_MII_MAC_MODE BIT(2) 577 573 #define P_MII_SEL_M 0x3 574 + 575 + /* Interrupt */ 576 + #define REG_SW_PORT_INT_STATUS__1 0x001B 577 + #define REG_SW_PORT_INT_MASK__1 0x001F 578 + 579 + #define REG_PORT_INT_STATUS 0x001B 580 + #define REG_PORT_INT_MASK 0x001F 581 + 582 + #define PORT_SRC_PHY_INT 1 578 583 579 584 /* Regmap tables generation */ 580 585 #define KSZ_SPI_OP_RD 3
-427
drivers/net/dsa/microchip/lan937x_main.c
··· 7 7 #include <linux/iopoll.h> 8 8 #include <linux/phy.h> 9 9 #include <linux/of_net.h> 10 - #include <linux/of_mdio.h> 11 10 #include <linux/if_bridge.h> 12 11 #include <linux/if_vlan.h> 13 - #include <linux/irq.h> 14 - #include <linux/irqdomain.h> 15 12 #include <linux/math.h> 16 13 #include <net/dsa.h> 17 14 #include <net/switchdev.h> ··· 16 19 #include "lan937x_reg.h" 17 20 #include "ksz_common.h" 18 21 #include "lan937x.h" 19 - 20 - #define LAN937x_PNIRQS 6 21 22 22 23 static int lan937x_cfg(struct ksz_device *dev, u32 addr, u8 bits, bool set) 23 24 { ··· 135 140 int lan937x_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val) 136 141 { 137 142 return lan937x_internal_phy_write(dev, addr, reg, val); 138 - } 139 - 140 - static int lan937x_sw_mdio_read(struct mii_bus *bus, int addr, int regnum) 141 - { 142 - struct ksz_device *dev = bus->priv; 143 - u16 val; 144 - int ret; 145 - 146 - if (regnum & MII_ADDR_C45) 147 - return -EOPNOTSUPP; 148 - 149 - ret = lan937x_internal_phy_read(dev, addr, regnum, &val); 150 - if (ret < 0) 151 - return ret; 152 - 153 - return val; 154 - } 155 - 156 - static int lan937x_sw_mdio_write(struct mii_bus *bus, int addr, int regnum, 157 - u16 val) 158 - { 159 - struct ksz_device *dev = bus->priv; 160 - 161 - if (regnum & MII_ADDR_C45) 162 - return -EOPNOTSUPP; 163 - 164 - return lan937x_internal_phy_write(dev, addr, regnum, val); 165 - } 166 - 167 - static int lan937x_irq_phy_setup(struct ksz_device *dev) 168 - { 169 - struct dsa_switch *ds = dev->ds; 170 - int phy, err_phy; 171 - int irq; 172 - int ret; 173 - 174 - for (phy = 0; phy < KSZ_MAX_NUM_PORTS; phy++) { 175 - if (BIT(phy) & ds->phys_mii_mask) { 176 - irq = irq_find_mapping(dev->ports[phy].pirq.domain, 177 - PORT_SRC_PHY_INT); 178 - if (irq < 0) { 179 - ret = irq; 180 - goto out; 181 - } 182 - ds->slave_mii_bus->irq[phy] = irq; 183 - } 184 - } 185 - return 0; 186 - out: 187 - err_phy = phy; 188 - 189 - for (phy = 0; phy < err_phy; phy++) 190 - if (BIT(phy) & ds->phys_mii_mask) 191 - irq_dispose_mapping(ds->slave_mii_bus->irq[phy]); 192 - 193 - return ret; 194 - } 195 - 196 - static void lan937x_irq_phy_free(struct ksz_device *dev) 197 - { 198 - struct dsa_switch *ds = dev->ds; 199 - int phy; 200 - 201 - for (phy = 0; phy < KSZ_MAX_NUM_PORTS; phy++) 202 - if (BIT(phy) & ds->phys_mii_mask) 203 - irq_dispose_mapping(ds->slave_mii_bus->irq[phy]); 204 - } 205 - 206 - static int lan937x_mdio_register(struct ksz_device *dev) 207 - { 208 - struct dsa_switch *ds = dev->ds; 209 - struct device_node *mdio_np; 210 - struct mii_bus *bus; 211 - int ret; 212 - 213 - mdio_np = of_get_child_by_name(dev->dev->of_node, "mdio"); 214 - if (!mdio_np) { 215 - dev_err(ds->dev, "no MDIO bus node\n"); 216 - return -ENODEV; 217 - } 218 - 219 - bus = devm_mdiobus_alloc(ds->dev); 220 - if (!bus) { 221 - of_node_put(mdio_np); 222 - return -ENOMEM; 223 - } 224 - 225 - bus->priv = dev; 226 - bus->read = lan937x_sw_mdio_read; 227 - bus->write = lan937x_sw_mdio_write; 228 - bus->name = "lan937x slave smi"; 229 - snprintf(bus->id, MII_BUS_ID_SIZE, "SMI-%d", ds->index); 230 - bus->parent = ds->dev; 231 - bus->phy_mask = ~ds->phys_mii_mask; 232 - 233 - ds->slave_mii_bus = bus; 234 - 235 - ret = lan937x_irq_phy_setup(dev); 236 - if (ret) { 237 - of_node_put(mdio_np); 238 - return ret; 239 - } 240 - 241 - ret = devm_of_mdiobus_register(ds->dev, bus, mdio_np); 242 - if (ret) { 243 - dev_err(ds->dev, "unable to register MDIO bus %s\n", 244 - bus->id); 245 - lan937x_irq_phy_free(dev); 246 - } 247 - 248 - of_node_put(mdio_np); 249 - 250 - return ret; 251 143 } 252 144 253 145 int lan937x_reset_switch(struct ksz_device *dev) ··· 339 457 return 0; 340 458 } 341 459 342 - static void lan937x_girq_mask(struct irq_data *d) 343 - { 344 - struct ksz_device *dev = irq_data_get_irq_chip_data(d); 345 - unsigned int n = d->hwirq; 346 - 347 - dev->girq.masked |= (1 << n); 348 - } 349 - 350 - static void lan937x_girq_unmask(struct irq_data *d) 351 - { 352 - struct ksz_device *dev = irq_data_get_irq_chip_data(d); 353 - unsigned int n = d->hwirq; 354 - 355 - dev->girq.masked &= ~(1 << n); 356 - } 357 - 358 - static void lan937x_girq_bus_lock(struct irq_data *d) 359 - { 360 - struct ksz_device *dev = irq_data_get_irq_chip_data(d); 361 - 362 - mutex_lock(&dev->lock_irq); 363 - } 364 - 365 - static void lan937x_girq_bus_sync_unlock(struct irq_data *d) 366 - { 367 - struct ksz_device *dev = irq_data_get_irq_chip_data(d); 368 - int ret; 369 - 370 - ret = ksz_write32(dev, REG_SW_PORT_INT_MASK__4, dev->girq.masked); 371 - if (ret) 372 - dev_err(dev->dev, "failed to change IRQ mask\n"); 373 - 374 - mutex_unlock(&dev->lock_irq); 375 - } 376 - 377 - static const struct irq_chip lan937x_girq_chip = { 378 - .name = "lan937x-global", 379 - .irq_mask = lan937x_girq_mask, 380 - .irq_unmask = lan937x_girq_unmask, 381 - .irq_bus_lock = lan937x_girq_bus_lock, 382 - .irq_bus_sync_unlock = lan937x_girq_bus_sync_unlock, 383 - }; 384 - 385 - static int lan937x_girq_domain_map(struct irq_domain *d, 386 - unsigned int irq, irq_hw_number_t hwirq) 387 - { 388 - struct ksz_device *dev = d->host_data; 389 - 390 - irq_set_chip_data(irq, d->host_data); 391 - irq_set_chip_and_handler(irq, &dev->girq.chip, handle_level_irq); 392 - irq_set_noprobe(irq); 393 - 394 - return 0; 395 - } 396 - 397 - static const struct irq_domain_ops lan937x_girq_domain_ops = { 398 - .map = lan937x_girq_domain_map, 399 - .xlate = irq_domain_xlate_twocell, 400 - }; 401 - 402 - static void lan937x_girq_free(struct ksz_device *dev) 403 - { 404 - int irq, virq; 405 - 406 - free_irq(dev->irq, dev); 407 - 408 - for (irq = 0; irq < dev->girq.nirqs; irq++) { 409 - virq = irq_find_mapping(dev->girq.domain, irq); 410 - irq_dispose_mapping(virq); 411 - } 412 - 413 - irq_domain_remove(dev->girq.domain); 414 - } 415 - 416 - static irqreturn_t lan937x_girq_thread_fn(int irq, void *dev_id) 417 - { 418 - struct ksz_device *dev = dev_id; 419 - unsigned int nhandled = 0; 420 - unsigned int sub_irq; 421 - unsigned int n; 422 - u32 data; 423 - int ret; 424 - 425 - /* Read global interrupt status register */ 426 - ret = ksz_read32(dev, REG_SW_PORT_INT_STATUS__4, &data); 427 - if (ret) 428 - goto out; 429 - 430 - for (n = 0; n < dev->girq.nirqs; ++n) { 431 - if (data & (1 << n)) { 432 - sub_irq = irq_find_mapping(dev->girq.domain, n); 433 - handle_nested_irq(sub_irq); 434 - ++nhandled; 435 - } 436 - } 437 - out: 438 - return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE); 439 - } 440 - 441 - static int lan937x_girq_setup(struct ksz_device *dev) 442 - { 443 - int ret, irq; 444 - 445 - dev->girq.nirqs = dev->info->port_cnt; 446 - dev->girq.domain = irq_domain_add_simple(NULL, dev->girq.nirqs, 0, 447 - &lan937x_girq_domain_ops, dev); 448 - if (!dev->girq.domain) 449 - return -ENOMEM; 450 - 451 - for (irq = 0; irq < dev->girq.nirqs; irq++) 452 - irq_create_mapping(dev->girq.domain, irq); 453 - 454 - dev->girq.chip = lan937x_girq_chip; 455 - dev->girq.masked = ~0; 456 - 457 - ret = request_threaded_irq(dev->irq, NULL, lan937x_girq_thread_fn, 458 - IRQF_ONESHOT | IRQF_TRIGGER_FALLING, 459 - dev_name(dev->dev), dev); 460 - if (ret) 461 - goto out; 462 - 463 - return 0; 464 - 465 - out: 466 - lan937x_girq_free(dev); 467 - 468 - return ret; 469 - } 470 - 471 - static void lan937x_pirq_mask(struct irq_data *d) 472 - { 473 - struct ksz_port *port = irq_data_get_irq_chip_data(d); 474 - unsigned int n = d->hwirq; 475 - 476 - port->pirq.masked |= (1 << n); 477 - } 478 - 479 - static void lan937x_pirq_unmask(struct irq_data *d) 480 - { 481 - struct ksz_port *port = irq_data_get_irq_chip_data(d); 482 - unsigned int n = d->hwirq; 483 - 484 - port->pirq.masked &= ~(1 << n); 485 - } 486 - 487 - static void lan937x_pirq_bus_lock(struct irq_data *d) 488 - { 489 - struct ksz_port *port = irq_data_get_irq_chip_data(d); 490 - struct ksz_device *dev = port->ksz_dev; 491 - 492 - mutex_lock(&dev->lock_irq); 493 - } 494 - 495 - static void lan937x_pirq_bus_sync_unlock(struct irq_data *d) 496 - { 497 - struct ksz_port *port = irq_data_get_irq_chip_data(d); 498 - struct ksz_device *dev = port->ksz_dev; 499 - 500 - ksz_pwrite8(dev, port->num, REG_PORT_INT_MASK, port->pirq.masked); 501 - mutex_unlock(&dev->lock_irq); 502 - } 503 - 504 - static const struct irq_chip lan937x_pirq_chip = { 505 - .name = "lan937x-port", 506 - .irq_mask = lan937x_pirq_mask, 507 - .irq_unmask = lan937x_pirq_unmask, 508 - .irq_bus_lock = lan937x_pirq_bus_lock, 509 - .irq_bus_sync_unlock = lan937x_pirq_bus_sync_unlock, 510 - }; 511 - 512 - static int lan937x_pirq_domain_map(struct irq_domain *d, unsigned int irq, 513 - irq_hw_number_t hwirq) 514 - { 515 - struct ksz_port *port = d->host_data; 516 - 517 - irq_set_chip_data(irq, d->host_data); 518 - irq_set_chip_and_handler(irq, &port->pirq.chip, handle_level_irq); 519 - irq_set_noprobe(irq); 520 - 521 - return 0; 522 - } 523 - 524 - static const struct irq_domain_ops lan937x_pirq_domain_ops = { 525 - .map = lan937x_pirq_domain_map, 526 - .xlate = irq_domain_xlate_twocell, 527 - }; 528 - 529 - static void lan937x_pirq_free(struct ksz_device *dev, u8 p) 530 - { 531 - struct ksz_port *port = &dev->ports[p]; 532 - int irq, virq; 533 - int irq_num; 534 - 535 - irq_num = irq_find_mapping(dev->girq.domain, p); 536 - if (irq_num < 0) 537 - return; 538 - 539 - free_irq(irq_num, port); 540 - 541 - for (irq = 0; irq < port->pirq.nirqs; irq++) { 542 - virq = irq_find_mapping(port->pirq.domain, irq); 543 - irq_dispose_mapping(virq); 544 - } 545 - 546 - irq_domain_remove(port->pirq.domain); 547 - } 548 - 549 - static irqreturn_t lan937x_pirq_thread_fn(int irq, void *dev_id) 550 - { 551 - struct ksz_port *port = dev_id; 552 - unsigned int nhandled = 0; 553 - struct ksz_device *dev; 554 - unsigned int sub_irq; 555 - unsigned int n; 556 - u8 data; 557 - 558 - dev = port->ksz_dev; 559 - 560 - /* Read port interrupt status register */ 561 - ksz_pread8(dev, port->num, REG_PORT_INT_STATUS, &data); 562 - 563 - for (n = 0; n < port->pirq.nirqs; ++n) { 564 - if (data & (1 << n)) { 565 - sub_irq = irq_find_mapping(port->pirq.domain, n); 566 - handle_nested_irq(sub_irq); 567 - ++nhandled; 568 - } 569 - } 570 - 571 - return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE); 572 - } 573 - 574 - static int lan937x_pirq_setup(struct ksz_device *dev, u8 p) 575 - { 576 - struct ksz_port *port = &dev->ports[p]; 577 - int ret, irq; 578 - int irq_num; 579 - 580 - port->pirq.nirqs = LAN937x_PNIRQS; 581 - port->pirq.domain = irq_domain_add_simple(dev->dev->of_node, 582 - port->pirq.nirqs, 0, 583 - &lan937x_pirq_domain_ops, 584 - port); 585 - if (!port->pirq.domain) 586 - return -ENOMEM; 587 - 588 - for (irq = 0; irq < port->pirq.nirqs; irq++) 589 - irq_create_mapping(port->pirq.domain, irq); 590 - 591 - port->pirq.chip = lan937x_pirq_chip; 592 - port->pirq.masked = ~0; 593 - 594 - irq_num = irq_find_mapping(dev->girq.domain, p); 595 - if (irq_num < 0) 596 - return irq_num; 597 - 598 - snprintf(port->pirq.name, sizeof(port->pirq.name), "port_irq-%d", p); 599 - 600 - ret = request_threaded_irq(irq_num, NULL, lan937x_pirq_thread_fn, 601 - IRQF_ONESHOT | IRQF_TRIGGER_FALLING, 602 - port->pirq.name, port); 603 - if (ret) 604 - goto out; 605 - 606 - return 0; 607 - 608 - out: 609 - lan937x_pirq_free(dev, p); 610 - 611 - return ret; 612 - } 613 - 614 460 int lan937x_setup(struct dsa_switch *ds) 615 461 { 616 462 struct ksz_device *dev = ds->priv; 617 - struct dsa_port *dp; 618 463 int ret; 619 464 620 465 /* enable Indirect Access from SPI to the VPHY registers */ ··· 349 740 if (ret < 0) { 350 741 dev_err(dev->dev, "failed to enable spi indirect access"); 351 742 return ret; 352 - } 353 - 354 - if (dev->irq > 0) { 355 - ret = lan937x_girq_setup(dev); 356 - if (ret) 357 - return ret; 358 - 359 - dsa_switch_for_each_user_port(dp, dev->ds) { 360 - ret = lan937x_pirq_setup(dev, dp->index); 361 - if (ret) 362 - goto out_girq; 363 - } 364 - } 365 - 366 - ret = lan937x_mdio_register(dev); 367 - if (ret < 0) { 368 - dev_err(dev->dev, "failed to register the mdio"); 369 - goto out_pirq; 370 743 } 371 744 372 745 /* The VLAN aware is a global setting. Mixed vlan ··· 374 783 (SW_CLK125_ENB | SW_CLK25_ENB), true); 375 784 376 785 return 0; 377 - 378 - out_pirq: 379 - if (dev->irq > 0) 380 - dsa_switch_for_each_user_port(dp, dev->ds) 381 - lan937x_pirq_free(dev, dp->index); 382 - out_girq: 383 - if (dev->irq > 0) 384 - lan937x_girq_free(dev); 385 - 386 - return ret; 387 786 } 388 787 389 788 void lan937x_teardown(struct dsa_switch *ds) 390 789 { 391 - struct ksz_device *dev = ds->priv; 392 - struct dsa_port *dp; 393 790 394 - if (dev->irq > 0) { 395 - dsa_switch_for_each_user_port(dp, dev->ds) 396 - lan937x_pirq_free(dev, dp->index); 397 - 398 - lan937x_girq_free(dev); 399 - } 400 791 } 401 792 402 793 void lan937x_switch_exit(struct ksz_device *dev)
+2
drivers/net/phy/micrel.c
··· 3348 3348 .name = "Microchip KSZ9477", 3349 3349 /* PHY_GBIT_FEATURES */ 3350 3350 .config_init = kszphy_config_init, 3351 + .config_intr = kszphy_config_intr, 3352 + .handle_interrupt = kszphy_handle_interrupt, 3351 3353 .suspend = genphy_suspend, 3352 3354 .resume = genphy_resume, 3353 3355 } };