diff options
author | Ioana Ciornei <ioana.ciornei@nxp.com> | 2019-05-28 13:38:15 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-05-30 00:48:53 -0400 |
commit | 77373d49de22e836cf58ddbe7689d6b4b5046539 (patch) | |
tree | 238625363ff83589cfbcd0080b4ba38c932cd0c1 /net/dsa | |
parent | 17091180b1521ee9b4455d75ab61b35bc0b216ff (diff) |
net: dsa: Move the phylink driver calls into port.c
In order to have a common handling of PHYLINK for the slave and non-user
ports, the DSA core glue logic (between PHYLINK and the driver) must use
an API that does not rely on a struct net_device.
These will also be called by the CPU-port-handling code in a further
patch.
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Vladimir Oltean <olteanv@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa')
-rw-r--r-- | net/dsa/dsa_priv.h | 17 | ||||
-rw-r--r-- | net/dsa/port.c | 100 | ||||
-rw-r--r-- | net/dsa/slave.c | 96 |
3 files changed, 118 insertions, 95 deletions
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 8f1222324646..418490bda3a4 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h | |||
@@ -163,6 +163,23 @@ int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags); | |||
163 | int dsa_port_vid_del(struct dsa_port *dp, u16 vid); | 163 | int dsa_port_vid_del(struct dsa_port *dp, u16 vid); |
164 | int dsa_port_link_register_of(struct dsa_port *dp); | 164 | int dsa_port_link_register_of(struct dsa_port *dp); |
165 | void dsa_port_link_unregister_of(struct dsa_port *dp); | 165 | void dsa_port_link_unregister_of(struct dsa_port *dp); |
166 | void dsa_port_phylink_validate(struct phylink_config *config, | ||
167 | unsigned long *supported, | ||
168 | struct phylink_link_state *state); | ||
169 | int dsa_port_phylink_mac_link_state(struct phylink_config *config, | ||
170 | struct phylink_link_state *state); | ||
171 | void dsa_port_phylink_mac_config(struct phylink_config *config, | ||
172 | unsigned int mode, | ||
173 | const struct phylink_link_state *state); | ||
174 | void dsa_port_phylink_mac_an_restart(struct phylink_config *config); | ||
175 | void dsa_port_phylink_mac_link_down(struct phylink_config *config, | ||
176 | unsigned int mode, | ||
177 | phy_interface_t interface); | ||
178 | void dsa_port_phylink_mac_link_up(struct phylink_config *config, | ||
179 | unsigned int mode, | ||
180 | phy_interface_t interface, | ||
181 | struct phy_device *phydev); | ||
182 | extern const struct phylink_mac_ops dsa_port_phylink_mac_ops; | ||
166 | 183 | ||
167 | /* slave.c */ | 184 | /* slave.c */ |
168 | extern const struct dsa_device_ops notag_netdev_ops; | 185 | extern const struct dsa_device_ops notag_netdev_ops; |
diff --git a/net/dsa/port.c b/net/dsa/port.c index ed8ba9daa3ba..0051f5006248 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c | |||
@@ -422,6 +422,106 @@ static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp) | |||
422 | return phydev; | 422 | return phydev; |
423 | } | 423 | } |
424 | 424 | ||
425 | void dsa_port_phylink_validate(struct phylink_config *config, | ||
426 | unsigned long *supported, | ||
427 | struct phylink_link_state *state) | ||
428 | { | ||
429 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
430 | struct dsa_switch *ds = dp->ds; | ||
431 | |||
432 | if (!ds->ops->phylink_validate) | ||
433 | return; | ||
434 | |||
435 | ds->ops->phylink_validate(ds, dp->index, supported, state); | ||
436 | } | ||
437 | EXPORT_SYMBOL_GPL(dsa_port_phylink_validate); | ||
438 | |||
439 | int dsa_port_phylink_mac_link_state(struct phylink_config *config, | ||
440 | struct phylink_link_state *state) | ||
441 | { | ||
442 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
443 | struct dsa_switch *ds = dp->ds; | ||
444 | |||
445 | /* Only called for SGMII and 802.3z */ | ||
446 | if (!ds->ops->phylink_mac_link_state) | ||
447 | return -EOPNOTSUPP; | ||
448 | |||
449 | return ds->ops->phylink_mac_link_state(ds, dp->index, state); | ||
450 | } | ||
451 | EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_link_state); | ||
452 | |||
453 | void dsa_port_phylink_mac_config(struct phylink_config *config, | ||
454 | unsigned int mode, | ||
455 | const struct phylink_link_state *state) | ||
456 | { | ||
457 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
458 | struct dsa_switch *ds = dp->ds; | ||
459 | |||
460 | if (!ds->ops->phylink_mac_config) | ||
461 | return; | ||
462 | |||
463 | ds->ops->phylink_mac_config(ds, dp->index, mode, state); | ||
464 | } | ||
465 | EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_config); | ||
466 | |||
467 | void dsa_port_phylink_mac_an_restart(struct phylink_config *config) | ||
468 | { | ||
469 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
470 | struct dsa_switch *ds = dp->ds; | ||
471 | |||
472 | if (!ds->ops->phylink_mac_an_restart) | ||
473 | return; | ||
474 | |||
475 | ds->ops->phylink_mac_an_restart(ds, dp->index); | ||
476 | } | ||
477 | EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_an_restart); | ||
478 | |||
479 | void dsa_port_phylink_mac_link_down(struct phylink_config *config, | ||
480 | unsigned int mode, | ||
481 | phy_interface_t interface) | ||
482 | { | ||
483 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
484 | struct net_device *dev = dp->slave; | ||
485 | struct dsa_switch *ds = dp->ds; | ||
486 | |||
487 | if (!ds->ops->phylink_mac_link_down) { | ||
488 | if (ds->ops->adjust_link && dev->phydev) | ||
489 | ds->ops->adjust_link(ds, dp->index, dev->phydev); | ||
490 | return; | ||
491 | } | ||
492 | |||
493 | ds->ops->phylink_mac_link_down(ds, dp->index, mode, interface); | ||
494 | } | ||
495 | EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_link_down); | ||
496 | |||
497 | void dsa_port_phylink_mac_link_up(struct phylink_config *config, | ||
498 | unsigned int mode, | ||
499 | phy_interface_t interface, | ||
500 | struct phy_device *phydev) | ||
501 | { | ||
502 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
503 | struct net_device *dev = dp->slave; | ||
504 | struct dsa_switch *ds = dp->ds; | ||
505 | |||
506 | if (!ds->ops->phylink_mac_link_up) { | ||
507 | if (ds->ops->adjust_link && dev->phydev) | ||
508 | ds->ops->adjust_link(ds, dp->index, dev->phydev); | ||
509 | return; | ||
510 | } | ||
511 | |||
512 | ds->ops->phylink_mac_link_up(ds, dp->index, mode, interface, phydev); | ||
513 | } | ||
514 | EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_link_up); | ||
515 | |||
516 | const struct phylink_mac_ops dsa_port_phylink_mac_ops = { | ||
517 | .validate = dsa_port_phylink_validate, | ||
518 | .mac_link_state = dsa_port_phylink_mac_link_state, | ||
519 | .mac_config = dsa_port_phylink_mac_config, | ||
520 | .mac_an_restart = dsa_port_phylink_mac_an_restart, | ||
521 | .mac_link_down = dsa_port_phylink_mac_link_down, | ||
522 | .mac_link_up = dsa_port_phylink_mac_link_up, | ||
523 | }; | ||
524 | |||
425 | static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable) | 525 | static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable) |
426 | { | 526 | { |
427 | struct dsa_switch *ds = dp->ds; | 527 | struct dsa_switch *ds = dp->ds; |
diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 48e017637d4f..1e2ae9d59b88 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c | |||
@@ -1164,100 +1164,6 @@ static struct device_type dsa_type = { | |||
1164 | .name = "dsa", | 1164 | .name = "dsa", |
1165 | }; | 1165 | }; |
1166 | 1166 | ||
1167 | static void dsa_slave_phylink_validate(struct phylink_config *config, | ||
1168 | unsigned long *supported, | ||
1169 | struct phylink_link_state *state) | ||
1170 | { | ||
1171 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
1172 | struct dsa_switch *ds = dp->ds; | ||
1173 | |||
1174 | if (!ds->ops->phylink_validate) | ||
1175 | return; | ||
1176 | |||
1177 | ds->ops->phylink_validate(ds, dp->index, supported, state); | ||
1178 | } | ||
1179 | |||
1180 | static int dsa_slave_phylink_mac_link_state(struct phylink_config *config, | ||
1181 | struct phylink_link_state *state) | ||
1182 | { | ||
1183 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
1184 | struct dsa_switch *ds = dp->ds; | ||
1185 | |||
1186 | /* Only called for SGMII and 802.3z */ | ||
1187 | if (!ds->ops->phylink_mac_link_state) | ||
1188 | return -EOPNOTSUPP; | ||
1189 | |||
1190 | return ds->ops->phylink_mac_link_state(ds, dp->index, state); | ||
1191 | } | ||
1192 | |||
1193 | static void dsa_slave_phylink_mac_config(struct phylink_config *config, | ||
1194 | unsigned int mode, | ||
1195 | const struct phylink_link_state *state) | ||
1196 | { | ||
1197 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
1198 | struct dsa_switch *ds = dp->ds; | ||
1199 | |||
1200 | if (!ds->ops->phylink_mac_config) | ||
1201 | return; | ||
1202 | |||
1203 | ds->ops->phylink_mac_config(ds, dp->index, mode, state); | ||
1204 | } | ||
1205 | |||
1206 | static void dsa_slave_phylink_mac_an_restart(struct phylink_config *config) | ||
1207 | { | ||
1208 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
1209 | struct dsa_switch *ds = dp->ds; | ||
1210 | |||
1211 | if (!ds->ops->phylink_mac_an_restart) | ||
1212 | return; | ||
1213 | |||
1214 | ds->ops->phylink_mac_an_restart(ds, dp->index); | ||
1215 | } | ||
1216 | |||
1217 | static void dsa_slave_phylink_mac_link_down(struct phylink_config *config, | ||
1218 | unsigned int mode, | ||
1219 | phy_interface_t interface) | ||
1220 | { | ||
1221 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
1222 | struct net_device *dev = dp->slave; | ||
1223 | struct dsa_switch *ds = dp->ds; | ||
1224 | |||
1225 | if (!ds->ops->phylink_mac_link_down) { | ||
1226 | if (ds->ops->adjust_link && dev->phydev) | ||
1227 | ds->ops->adjust_link(ds, dp->index, dev->phydev); | ||
1228 | return; | ||
1229 | } | ||
1230 | |||
1231 | ds->ops->phylink_mac_link_down(ds, dp->index, mode, interface); | ||
1232 | } | ||
1233 | |||
1234 | static void dsa_slave_phylink_mac_link_up(struct phylink_config *config, | ||
1235 | unsigned int mode, | ||
1236 | phy_interface_t interface, | ||
1237 | struct phy_device *phydev) | ||
1238 | { | ||
1239 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); | ||
1240 | struct net_device *dev = dp->slave; | ||
1241 | struct dsa_switch *ds = dp->ds; | ||
1242 | |||
1243 | if (!ds->ops->phylink_mac_link_up) { | ||
1244 | if (ds->ops->adjust_link && dev->phydev) | ||
1245 | ds->ops->adjust_link(ds, dp->index, dev->phydev); | ||
1246 | return; | ||
1247 | } | ||
1248 | |||
1249 | ds->ops->phylink_mac_link_up(ds, dp->index, mode, interface, phydev); | ||
1250 | } | ||
1251 | |||
1252 | static const struct phylink_mac_ops dsa_slave_phylink_mac_ops = { | ||
1253 | .validate = dsa_slave_phylink_validate, | ||
1254 | .mac_link_state = dsa_slave_phylink_mac_link_state, | ||
1255 | .mac_config = dsa_slave_phylink_mac_config, | ||
1256 | .mac_an_restart = dsa_slave_phylink_mac_an_restart, | ||
1257 | .mac_link_down = dsa_slave_phylink_mac_link_down, | ||
1258 | .mac_link_up = dsa_slave_phylink_mac_link_up, | ||
1259 | }; | ||
1260 | |||
1261 | void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up) | 1167 | void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up) |
1262 | { | 1168 | { |
1263 | const struct dsa_port *dp = dsa_to_port(ds, port); | 1169 | const struct dsa_port *dp = dsa_to_port(ds, port); |
@@ -1309,7 +1215,7 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) | |||
1309 | dp->pl_config.type = PHYLINK_NETDEV; | 1215 | dp->pl_config.type = PHYLINK_NETDEV; |
1310 | 1216 | ||
1311 | dp->pl = phylink_create(&dp->pl_config, of_fwnode_handle(port_dn), mode, | 1217 | dp->pl = phylink_create(&dp->pl_config, of_fwnode_handle(port_dn), mode, |
1312 | &dsa_slave_phylink_mac_ops); | 1218 | &dsa_port_phylink_mac_ops); |
1313 | if (IS_ERR(dp->pl)) { | 1219 | if (IS_ERR(dp->pl)) { |
1314 | netdev_err(slave_dev, | 1220 | netdev_err(slave_dev, |
1315 | "error creating PHYLINK: %ld\n", PTR_ERR(dp->pl)); | 1221 | "error creating PHYLINK: %ld\n", PTR_ERR(dp->pl)); |