Commit ff6ac4d0 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: dsa: make dsa_port_supports_hwtstamp() construct a fake ifreq

dsa_master_ioctl() is in the process of getting converted to a different
API, where we won't have access to a struct ifreq * anymore, but rather,
to a struct kernel_hwtstamp_config.

Since ds->ops->port_hwtstamp_get() still uses struct ifreq *, this
creates a difficult situation where we have to make up such a dummy
pointer.

The conversion is a bit messy, because it forces a "good" implementation
of ds->ops->port_hwtstamp_get() to return -EFAULT in copy_to_user()
because of the NULL ifr->ifr_data pointer. However, it works, and it is
only a transient step until ds->ops->port_hwtstamp_get() gets converted
to the new API which passes struct kernel_hwtstamp_config and does not
call copy_to_user().
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c4bffeaa
...@@ -212,7 +212,7 @@ static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) ...@@ -212,7 +212,7 @@ static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
* switch in the tree that is PTP capable. * switch in the tree that is PTP capable.
*/ */
list_for_each_entry(dp, &dst->ports, list) list_for_each_entry(dp, &dst->ports, list)
if (dsa_port_supports_hwtstamp(dp, ifr)) if (dsa_port_supports_hwtstamp(dp))
return -EBUSY; return -EBUSY;
break; break;
} }
......
...@@ -114,19 +114,21 @@ static bool dsa_port_can_configure_learning(struct dsa_port *dp) ...@@ -114,19 +114,21 @@ static bool dsa_port_can_configure_learning(struct dsa_port *dp)
return !err; return !err;
} }
bool dsa_port_supports_hwtstamp(struct dsa_port *dp, struct ifreq *ifr) bool dsa_port_supports_hwtstamp(struct dsa_port *dp)
{ {
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
struct ifreq ifr = {};
int err; int err;
if (!ds->ops->port_hwtstamp_get || !ds->ops->port_hwtstamp_set) if (!ds->ops->port_hwtstamp_get || !ds->ops->port_hwtstamp_set)
return false; return false;
/* "See through" shim implementations of the "get" method. /* "See through" shim implementations of the "get" method.
* This will clobber the ifreq structure, but we will either return an * Since we can't cook up a complete ioctl request structure, this will
* error, or the master will overwrite it with proper values. * fail in copy_to_user() with -EFAULT, which hopefully is enough to
* detect a valid implementation.
*/ */
err = ds->ops->port_hwtstamp_get(ds, dp->index, ifr); err = ds->ops->port_hwtstamp_get(ds, dp->index, &ifr);
return err != -EOPNOTSUPP; return err != -EOPNOTSUPP;
} }
......
...@@ -15,7 +15,7 @@ struct switchdev_obj_port_mdb; ...@@ -15,7 +15,7 @@ struct switchdev_obj_port_mdb;
struct switchdev_vlan_msti; struct switchdev_vlan_msti;
struct phy_device; struct phy_device;
bool dsa_port_supports_hwtstamp(struct dsa_port *dp, struct ifreq *ifr); bool dsa_port_supports_hwtstamp(struct dsa_port *dp);
void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp, void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp,
const struct dsa_device_ops *tag_ops); const struct dsa_device_ops *tag_ops);
int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age); int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment