History

net: phylink: add pcs_validate() method

Add a hook for PCS to validate the link parameters. This avoids MAC drivers having to have knowledge of their PCS in their validate() method, thereby allowing several MAC drivers to be simplfied.

Russell King (Oracle) committed 4 years ago

Commit 0d22d4b1 parent d1e86322 files · +51 −0Browse files

Unified · Split

2 files
  1. drivers/net/phy/phylink.c +31 −0
  2. include/linux/phylink.h +20 −0
drivers/net/phy/phylink.c+31−0
@@ -424,13 +424,44 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl, · 423 unmodified lines
424424 struct phylink_link_state *state)
425425 {
426426 struct phylink_pcs *pcs;
427+ int ret;
427428
429+ /* Get the PCS for this interface mode */
428430 if (pl->mac_ops->mac_select_pcs) {
429431 pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
430432 if (IS_ERR(pcs))
431433 return PTR_ERR(pcs);
434+ } else {
435+ pcs = pl->pcs;
436+ }
437+
438+ if (pcs) {
439+ /* The PCS, if present, must be setup before phylink_create()
440+ * has been called. If the ops is not initialised, print an
441+ * error and backtrace rather than oopsing the kernel.
442+ */
443+ if (!pcs->ops) {
444+ phylink_err(pl, "interface %s: uninitialised PCS\n",
445+ phy_modes(state->interface));
446+ dump_stack();
447+ return -EINVAL;
448+ }
449+
450+ /* Validate the link parameters with the PCS */
451+ if (pcs->ops->pcs_validate) {
452+ ret = pcs->ops->pcs_validate(pcs, supported, state);
453+ if (ret < 0 || phylink_is_empty_linkmode(supported))
454+ return -EINVAL;
455+
456+ /* Ensure the advertising mask is a subset of the
457+ * supported mask.
458+ */
459+ linkmode_and(state->advertising, state->advertising,
460+ supported);
461+ }
432462 }
433463
464+ /* Then validate the link parameters with the MAC */
434465 pl->mac_ops->validate(pl->config, supported, state);
435466
436467 return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
include/linux/phylink.h+20−0
@@ -416,6 +416,7 @@ struct phylink_pcs { · 415 unmodified lines
416416
417417 /**
418418 * struct phylink_pcs_ops - MAC PCS operations structure.
419+ * @pcs_validate: validate the link configuration.
419420 * @pcs_get_state: read the current MAC PCS link state from the hardware.
420421 * @pcs_config: configure the MAC PCS for the selected mode and state.
421422 * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
@@ -423,6 +424,8 @@ struct phylink_pcs { · 1 unmodified line
423424 * (where necessary).
424425 */
425426 struct phylink_pcs_ops {
427+ int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
428+ const struct phylink_link_state *state);
426429 void (*pcs_get_state)(struct phylink_pcs *pcs,
427430 struct phylink_link_state *state);
428431 int (*pcs_config)(struct phylink_pcs *pcs, unsigned int mode,
@@ -435,6 +438,23 @@ struct phylink_pcs_ops { · 6 unmodified lines
435438 };
436439
437440 #if 0 /* For kernel-doc purposes only. */
441+/**
442+ * pcs_validate() - validate the link configuration.
443+ * @pcs: a pointer to a &struct phylink_pcs.
444+ * @supported: ethtool bitmask for supported link modes.
445+ * @state: a const pointer to a &struct phylink_link_state.
446+ *
447+ * Validate the interface mode, and advertising's autoneg bit, removing any
448+ * media ethtool link modes that would not be supportable from the supported
449+ * mask. Phylink will propagate the changes to the advertising mask. See the
450+ * &struct phylink_mac_ops validate() method.
451+ *
452+ * Returns -EINVAL if the interface mode/autoneg mode is not supported.
453+ * Returns non-zero positive if the link state can be supported.
454+ */
455+int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
456+ const struct phylink_link_state *state);
457+
438458 /**
439459 * pcs_get_state() - Read the current inband link state from the hardware
440460 * @pcs: a pointer to a &struct phylink_pcs.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t