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

net: dsa: microchip: look for phy-mode in port nodes

Documentation/devicetree/bindings/net/dsa/dsa.txt says that the phy-mode
property should be specified on port nodes. However, the microchip
drivers read it from the switch node.

Let the driver use the per-port property and fall back to the old
location with a warning.

Fix in-tree users.

Signed-off-by: Helmut Grohne <helmut.grohne@intenta.de>
Link: https://lore.kernel.org/netdev/20200617082235.GA1523@laureti-dev/
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Helmut Grohne and committed by
David S. Miller
edecfa98 f612eb76

+47 -18
+1 -1
arch/arm/boot/dts/at91-sama5d2_icp.dts
··· 116 116 switch0: ksz8563@0 { 117 117 compatible = "microchip,ksz8563"; 118 118 reg = <0>; 119 - phy-mode = "mii"; 120 119 reset-gpios = <&pioA PIN_PD4 GPIO_ACTIVE_LOW>; 121 120 122 121 spi-max-frequency = <500000>; ··· 139 140 reg = <2>; 140 141 label = "cpu"; 141 142 ethernet = <&macb0>; 143 + phy-mode = "mii"; 142 144 fixed-link { 143 145 speed = <100>; 144 146 full-duplex;
+13 -5
drivers/net/dsa/microchip/ksz8795.c
··· 932 932 ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_802_1P_ENABLE, true); 933 933 934 934 if (cpu_port) { 935 + if (!p->interface && dev->compat_interface) { 936 + dev_warn(dev->dev, 937 + "Using legacy switch \"phy-mode\" property, because it is missing on port %d node. " 938 + "Please update your device tree.\n", 939 + port); 940 + p->interface = dev->compat_interface; 941 + } 942 + 935 943 /* Configure MII interface for proper network communication. */ 936 944 ksz_read8(dev, REG_PORT_5_CTRL_6, &data8); 937 945 data8 &= ~PORT_INTERFACE_TYPE; 938 946 data8 &= ~PORT_GMII_1GPS_MODE; 939 - switch (dev->interface) { 947 + switch (p->interface) { 940 948 case PHY_INTERFACE_MODE_MII: 941 949 p->phydev.speed = SPEED_100; 942 950 break; ··· 960 952 default: 961 953 data8 &= ~PORT_RGMII_ID_IN_ENABLE; 962 954 data8 &= ~PORT_RGMII_ID_OUT_ENABLE; 963 - if (dev->interface == PHY_INTERFACE_MODE_RGMII_ID || 964 - dev->interface == PHY_INTERFACE_MODE_RGMII_RXID) 955 + if (p->interface == PHY_INTERFACE_MODE_RGMII_ID || 956 + p->interface == PHY_INTERFACE_MODE_RGMII_RXID) 965 957 data8 |= PORT_RGMII_ID_IN_ENABLE; 966 - if (dev->interface == PHY_INTERFACE_MODE_RGMII_ID || 967 - dev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 958 + if (p->interface == PHY_INTERFACE_MODE_RGMII_ID || 959 + p->interface == PHY_INTERFACE_MODE_RGMII_TXID) 968 960 data8 |= PORT_RGMII_ID_OUT_ENABLE; 969 961 data8 |= PORT_GMII_1GPS_MODE; 970 962 data8 |= PORT_INTERFACE_RGMII;
+19 -10
drivers/net/dsa/microchip/ksz9477.c
··· 1208 1208 1209 1209 /* configure MAC to 1G & RGMII mode */ 1210 1210 ksz_pread8(dev, port, REG_PORT_XMII_CTRL_1, &data8); 1211 - switch (dev->interface) { 1211 + switch (p->interface) { 1212 1212 case PHY_INTERFACE_MODE_MII: 1213 1213 ksz9477_set_xmii(dev, 0, &data8); 1214 1214 ksz9477_set_gbit(dev, false, &data8); ··· 1229 1229 ksz9477_set_gbit(dev, true, &data8); 1230 1230 data8 &= ~PORT_RGMII_ID_IG_ENABLE; 1231 1231 data8 &= ~PORT_RGMII_ID_EG_ENABLE; 1232 - if (dev->interface == PHY_INTERFACE_MODE_RGMII_ID || 1233 - dev->interface == PHY_INTERFACE_MODE_RGMII_RXID) 1232 + if (p->interface == PHY_INTERFACE_MODE_RGMII_ID || 1233 + p->interface == PHY_INTERFACE_MODE_RGMII_RXID) 1234 1234 data8 |= PORT_RGMII_ID_IG_ENABLE; 1235 - if (dev->interface == PHY_INTERFACE_MODE_RGMII_ID || 1236 - dev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 1235 + if (p->interface == PHY_INTERFACE_MODE_RGMII_ID || 1236 + p->interface == PHY_INTERFACE_MODE_RGMII_TXID) 1237 1237 data8 |= PORT_RGMII_ID_EG_ENABLE; 1238 1238 p->phydev.speed = SPEED_1000; 1239 1239 break; ··· 1269 1269 dev->cpu_port = i; 1270 1270 dev->host_mask = (1 << dev->cpu_port); 1271 1271 dev->port_mask |= dev->host_mask; 1272 + p = &dev->ports[i]; 1272 1273 1273 1274 /* Read from XMII register to determine host port 1274 1275 * interface. If set specifically in device tree 1275 1276 * note the difference to help debugging. 1276 1277 */ 1277 1278 interface = ksz9477_get_interface(dev, i); 1278 - if (!dev->interface) 1279 - dev->interface = interface; 1280 - if (interface && interface != dev->interface) 1279 + if (!p->interface) { 1280 + if (dev->compat_interface) { 1281 + dev_warn(dev->dev, 1282 + "Using legacy switch \"phy-mode\" property, because it is missing on port %d node. " 1283 + "Please update your device tree.\n", 1284 + i); 1285 + p->interface = dev->compat_interface; 1286 + } else { 1287 + p->interface = interface; 1288 + } 1289 + } 1290 + if (interface && interface != p->interface) 1281 1291 dev_info(dev->dev, 1282 1292 "use %s instead of %s\n", 1283 - phy_modes(dev->interface), 1293 + phy_modes(p->interface), 1284 1294 phy_modes(interface)); 1285 1295 1286 1296 /* enable cpu port */ 1287 1297 ksz9477_port_setup(dev, i, true); 1288 - p = &dev->ports[dev->cpu_port]; 1289 1298 p->vid_member = dev->port_mask; 1290 1299 p->on = 1; 1291 1300 }
+12 -1
drivers/net/dsa/microchip/ksz_common.c
··· 388 388 const struct ksz_dev_ops *ops) 389 389 { 390 390 phy_interface_t interface; 391 + struct device_node *port; 392 + unsigned int port_num; 391 393 int ret; 392 394 393 395 if (dev->pdata) ··· 423 421 /* Host port interface will be self detected, or specifically set in 424 422 * device tree. 425 423 */ 424 + for (port_num = 0; port_num < dev->port_cnt; ++port_num) 425 + dev->ports[port_num].interface = PHY_INTERFACE_MODE_NA; 426 426 if (dev->dev->of_node) { 427 427 ret = of_get_phy_mode(dev->dev->of_node, &interface); 428 428 if (ret == 0) 429 - dev->interface = interface; 429 + dev->compat_interface = interface; 430 + for_each_available_child_of_node(dev->dev->of_node, port) { 431 + if (of_property_read_u32(port, "reg", &port_num)) 432 + continue; 433 + if (port_num >= dev->port_cnt) 434 + return -EINVAL; 435 + of_get_phy_mode(port, &dev->ports[port_num].interface); 436 + } 430 437 dev->synclko_125 = of_property_read_bool(dev->dev->of_node, 431 438 "microchip,synclko-125"); 432 439 }
+2 -1
drivers/net/dsa/microchip/ksz_common.h
··· 39 39 u32 freeze:1; /* MIB counter freeze is enabled */ 40 40 41 41 struct ksz_port_mib mib; 42 + phy_interface_t interface; 42 43 }; 43 44 44 45 struct ksz_device { ··· 73 72 int mib_cnt; 74 73 int mib_port_cnt; 75 74 int last_port; /* ports after that not used */ 76 - phy_interface_t interface; 75 + phy_interface_t compat_interface; 77 76 u32 regs_size; 78 77 bool phy_errata_9477; 79 78 bool synclko_125;