Subject: Re: [PATCH v1 0/2] ptp: Add generic header parsing function

From: Kurt Kanzenbach <[email-masked]>
Date: Fri, 24 Jul 2020 08:25:59 +0200

On Thu Jul 23 2020, Richard Cochran wrote:
> Kurt,
>
> On Thu, Jul 23, 2020 at 09:49:44AM +0200, Kurt Kanzenbach wrote:
>> in order to reduce code duplication in the ptp code of DSA drivers, move the
>> header parsing function to ptp_classify. This way the Marvell and the hellcreek
>> drivers can share the same implementation. And probably more drivers can benefit
>> from it. Implemented as discussed [1] [2].
>
> This looks good.  I made a list of drivers that can possibily use this helper.
>
> Finding symbol: PTP_CLASS_PMASK
>
> *** drivers/net/dsa/mv88e6xxx/hwtstamp.c:
> parse_ptp_header[223]          switch (type & PTP_CLASS_PMASK) {

Sure, done already (see patch 2).

>
> *** drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c:
> mlxsw_sp_ptp_parse[335]        switch (ptp_class & PTP_CLASS_PMASK) {

Works ootb.

>
> *** drivers/net/ethernet/ti/am65-cpts.c:
> am65_skb_get_mtype_seqid[761]  switch (ptp_class & PTP_CLASS_PMASK) {
>
> *** drivers/net/ethernet/ti/cpts.c:
> cpts_skb_get_mtype_seqid[459]  switch (ptp_class & PTP_CLASS_PMASK) {
>
> *** drivers/net/phy/dp83640.c:
> match[815]                     switch (type & PTP_CLASS_PMASK) {
> is_sync[990]                   switch (type & PTP_CLASS_PMASK) {

These three drivers also deal with ptp v1 and they need access to the
message type. However, the message type is located at a different offset
depending on the ptp version. They all do:

|if (unlikely(ptp_class & PTP_CLASS_V1))
|	msgtype = data + offset + OFF_PTP_CONTROL;
|else
|	msgtype = data + offset;

Maybe we can put that in a helper function, too?

|static inline u8 ptp_get_msgtype(const struct ptp_header *hdr, unsigned int type)
|{
|	u8 msg;
|
|	if (unlikely(type & PTP_CLASS_V1))
|		/* msg type is located @ offset 20 for ptp v1 */ 
|		msg = hdr->source_port_identity.clock_identity.id[0];
|	else
|		msg = hdr->tsmt & 0x0f;
|
|	return msg;
|}

What do you think about it?

>
> *** drivers/ptp/ptp_ines.c:
> ines_match[457]                switch (ptp_class & PTP_CLASS_PMASK) {
> is_sync_pdelay_resp[703]       switch (type & PTP_CLASS_PMASK) {

Works ootb.

>
>> @DSA maintainers: Please, have a look the Marvell code. I don't have hardware to
>> test it. I've tested this series only on the Hirschmann switch.
>
> I'll test the marvell switch with your change and let you know...

Great.

Thanks,
Kurt