linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Horatiu Vultur <horatiu.vultur@microchip.com>
To: Richard Cochran <richardcochran@gmail.com>
Cc: <netdev@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <davem@davemloft.net>,
	<kuba@kernel.org>, <robh+dt@kernel.org>,
	<UNGLinuxDriver@microchip.com>, <linux@armlinux.org.uk>,
	<f.fainelli@gmail.com>, <vivien.didelot@gmail.com>,
	<vladimir.oltean@nxp.com>, <andrew@lunn.ch>
Subject: Re: [PATCH net-next 4/7] net: lan966x: Implement SIOCSHWTSTAMP and SIOCGHWTSTAMP
Date: Fri, 28 Jan 2022 14:20:08 +0100	[thread overview]
Message-ID: <20220128132008.x4z6ckfmhxnumsqm@soft-dev3-1.localhost> (raw)
In-Reply-To: <20220127215508.GA26514@hoboy.vegasvil.org>

The 01/27/2022 13:55, Richard Cochran wrote:
> 
> On Thu, Jan 27, 2022 at 11:23:30AM +0100, Horatiu Vultur wrote:
> 
> > diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c b/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c
> > index 69d8f43e2b1b..9ff4d3fca5a1 100644
> > --- a/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c
> > +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c
> > @@ -35,6 +35,90 @@ static u64 lan966x_ptp_get_nominal_value(void)
> >       return res;
> >  }
> >
> > +int lan966x_ptp_hwtstamp_set(struct lan966x_port *port, struct ifreq *ifr)
> > +{
> > +     struct lan966x *lan966x = port->lan966x;
> > +     bool l2 = false, l4 = false;
> > +     struct hwtstamp_config cfg;
> > +     struct lan966x_phc *phc;
> > +
> > +     /* For now don't allow to run ptp on ports that are part of a bridge,
> > +      * because in case of transparent clock the HW will still forward the
> > +      * frames, so there would be duplicate frames
> > +      */
> > +     if (lan966x->bridge_mask & BIT(port->chip_port))
> > +             return -EINVAL;
> > +
> > +     if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
> > +             return -EFAULT;
> > +
> > +     switch (cfg.tx_type) {
> > +     case HWTSTAMP_TX_ON:
> > +             port->ptp_cmd = IFH_REW_OP_TWO_STEP_PTP;
> > +             break;
> > +     case HWTSTAMP_TX_ONESTEP_SYNC:
> > +             port->ptp_cmd = IFH_REW_OP_ONE_STEP_PTP;
> > +             break;
> > +     case HWTSTAMP_TX_OFF:
> > +             port->ptp_cmd = IFH_REW_OP_NOOP;
> > +             break;
> > +     default:
> > +             return -ERANGE;
> > +     }
> > +
> > +     mutex_lock(&lan966x->ptp_lock);
> 
> No need to lock stack variables.  Move locking down to ...

Good catch, will do that.

> 
> > +     switch (cfg.rx_filter) {
> > +     case HWTSTAMP_FILTER_NONE:
> > +             break;
> > +     case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
> > +     case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
> > +     case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
> > +             l4 = true;
> > +             break;
> > +     case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
> > +     case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
> > +     case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
> > +             l2 = true;
> > +             break;
> > +     case HWTSTAMP_FILTER_PTP_V2_EVENT:
> > +     case HWTSTAMP_FILTER_PTP_V2_SYNC:
> > +     case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
> > +             l2 = true;
> > +             l4 = true;
> > +             break;
> > +     default:
> > +             mutex_unlock(&lan966x->ptp_lock);
> > +             return -ERANGE;
> > +     }
> > +
> > +     if (l2 && l4)
> > +             cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
> > +     else if (l2)
> > +             cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
> > +     else if (l4)
> > +             cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
> > +     else
> > +             cfg.rx_filter = HWTSTAMP_FILTER_NONE;
> > +
> > +     /* Commit back the result & save it */
> 
> ... here
> 
> > +     phc = &lan966x->phc[LAN966X_PHC_PORT];
> > +     memcpy(&phc->hwtstamp_config, &cfg, sizeof(cfg));
> > +     mutex_unlock(&lan966x->ptp_lock);
> > +
> > +     return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
> > +}
> 
> Thanks,
> Richard

-- 
/Horatiu

  reply	other threads:[~2022-01-28 13:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-27 10:23 [PATCH net-next 0/7] net: lan966x: Add PTP Hardward Clock support Horatiu Vultur
2022-01-27 10:23 ` [PATCH net-next 1/7] dt-bindings: net: lan966x: Extend with the ptp interrupt Horatiu Vultur
2022-01-27 10:23 ` [PATCH net-next 2/7] net: lan966x: Add registers that are use for ptp functionality Horatiu Vultur
2022-01-27 15:18   ` Richard Cochran
2022-01-28 13:15     ` Horatiu Vultur
2022-01-27 10:23 ` [PATCH net-next 3/7] net: lan966x: Add support for ptp clocks Horatiu Vultur
2022-01-27 15:25   ` Richard Cochran
2022-01-27 15:28   ` Richard Cochran
2022-01-28 13:48     ` Horatiu Vultur
2022-01-27 10:23 ` [PATCH net-next 4/7] net: lan966x: Implement SIOCSHWTSTAMP and SIOCGHWTSTAMP Horatiu Vultur
2022-01-27 21:55   ` Richard Cochran
2022-01-28 13:20     ` Horatiu Vultur [this message]
2022-01-27 10:23 ` [PATCH net-next 5/7] net: lan966x: Update extraction/injection for timestamping Horatiu Vultur
2022-01-27 10:23 ` [PATCH net-next 6/7] net: lan966x: Add support for ptp interrupts Horatiu Vultur
2022-01-27 10:23 ` [PATCH net-next 7/7] net: lan966x: Implement get_ts_info Horatiu Vultur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220128132008.x4z6ckfmhxnumsqm@soft-dev3-1.localhost \
    --to=horatiu.vultur@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=vivien.didelot@gmail.com \
    --cc=vladimir.oltean@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).