ethernet: ti: cpts: Use generic helper function
authorKurt Kanzenbach <kurt@linutronix.de>
Tue, 18 Aug 2020 10:32:48 +0000 (12:32 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 19 Aug 2020 23:09:19 +0000 (16:09 -0700)
In order to reduce code duplication between ptp drivers, generic helper
functions were introduced. Use them.

Suggested-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/ti/cpts.c

index 7c55d395de2ce799366181ba01833e23fb8c8ea6..d1fc7955d422743065f22a8857dcd9259c100824 100644 (file)
@@ -446,41 +446,22 @@ static const struct ptp_clock_info cpts_info = {
 static int cpts_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid)
 {
        unsigned int ptp_class = ptp_classify_raw(skb);
-       u8 *msgtype, *data = skb->data;
-       unsigned int offset = 0;
-       u16 *seqid;
+       struct ptp_header *hdr;
+       u8 msgtype;
+       u16 seqid;
 
        if (ptp_class == PTP_CLASS_NONE)
                return 0;
 
-       if (ptp_class & PTP_CLASS_VLAN)
-               offset += VLAN_HLEN;
-
-       switch (ptp_class & PTP_CLASS_PMASK) {
-       case PTP_CLASS_IPV4:
-               offset += ETH_HLEN + IPV4_HLEN(data + offset) + UDP_HLEN;
-               break;
-       case PTP_CLASS_IPV6:
-               offset += ETH_HLEN + IP6_HLEN + UDP_HLEN;
-               break;
-       case PTP_CLASS_L2:
-               offset += ETH_HLEN;
-               break;
-       default:
-               return 0;
-       }
-
-       if (skb->len + ETH_HLEN < offset + OFF_PTP_SEQUENCE_ID + sizeof(*seqid))
+       hdr = ptp_parse_header(skb, ptp_class);
+       if (!hdr)
                return 0;
 
-       if (unlikely(ptp_class & PTP_CLASS_V1))
-               msgtype = data + offset + OFF_PTP_CONTROL;
-       else
-               msgtype = data + offset;
+       msgtype = ptp_get_msgtype(hdr, ptp_class);
+       seqid   = ntohs(hdr->sequence_id);
 
-       seqid = (u16 *)(data + offset + OFF_PTP_SEQUENCE_ID);
-       *mtype_seqid = (*msgtype & MESSAGE_TYPE_MASK) << MESSAGE_TYPE_SHIFT;
-       *mtype_seqid |= (ntohs(*seqid) & SEQUENCE_ID_MASK) << SEQUENCE_ID_SHIFT;
+       *mtype_seqid  = (msgtype & MESSAGE_TYPE_MASK) << MESSAGE_TYPE_SHIFT;
+       *mtype_seqid |= (seqid & SEQUENCE_ID_MASK) << SEQUENCE_ID_SHIFT;
 
        return 1;
 }
@@ -528,6 +509,11 @@ void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb)
        int ret;
        u64 ns;
 
+       /* cpts_rx_timestamp() is called before eth_type_trans(), so
+        * skb MAC Hdr properties are not configured yet. Hence need to
+        * reset skb MAC header here
+        */
+       skb_reset_mac_header(skb);
        ret = cpts_skb_get_mtype_seqid(skb, &skb_cb->skb_mtype_seqid);
        if (!ret)
                return;