net: phy: dp83640: Use generic helper function
In order to reduce code duplication between ptp drivers, generic helper functions were introduced. Use them. Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Tested-by: Richard Cochran <richardcochran@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
17de44c2c7
commit
38fa7d039f
|
@ -798,51 +798,32 @@ static int decode_evnt(struct dp83640_private *dp83640,
|
|||
return parsed;
|
||||
}
|
||||
|
||||
#define DP83640_PACKET_HASH_OFFSET 20
|
||||
#define DP83640_PACKET_HASH_LEN 10
|
||||
|
||||
static int match(struct sk_buff *skb, unsigned int type, struct rxts *rxts)
|
||||
{
|
||||
unsigned int offset = 0;
|
||||
u8 *msgtype, *data = skb_mac_header(skb);
|
||||
__be16 *seqid;
|
||||
struct ptp_header *hdr;
|
||||
u8 msgtype;
|
||||
u16 seqid;
|
||||
u16 hash;
|
||||
|
||||
/* check sequenceID, messageType, 12 bit hash of offset 20-29 */
|
||||
|
||||
if (type & PTP_CLASS_VLAN)
|
||||
offset += VLAN_HLEN;
|
||||
|
||||
switch (type & 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, type);
|
||||
if (!hdr)
|
||||
return 0;
|
||||
|
||||
if (unlikely(type & PTP_CLASS_V1))
|
||||
msgtype = data + offset + OFF_PTP_CONTROL;
|
||||
else
|
||||
msgtype = data + offset;
|
||||
if (rxts->msgtype != (*msgtype & 0xf))
|
||||
msgtype = ptp_get_msgtype(hdr, type);
|
||||
|
||||
if (rxts->msgtype != (msgtype & 0xf))
|
||||
return 0;
|
||||
|
||||
seqid = (__be16 *)(data + offset + OFF_PTP_SEQUENCE_ID);
|
||||
if (rxts->seqid != ntohs(*seqid))
|
||||
seqid = be16_to_cpu(hdr->sequence_id);
|
||||
if (rxts->seqid != seqid)
|
||||
return 0;
|
||||
|
||||
hash = ether_crc(DP83640_PACKET_HASH_LEN,
|
||||
data + offset + DP83640_PACKET_HASH_OFFSET) >> 20;
|
||||
(unsigned char *)&hdr->source_port_identity) >> 20;
|
||||
if (rxts->hash != hash)
|
||||
return 0;
|
||||
|
||||
|
@ -982,35 +963,16 @@ static void decode_status_frame(struct dp83640_private *dp83640,
|
|||
|
||||
static int is_sync(struct sk_buff *skb, int type)
|
||||
{
|
||||
u8 *data = skb->data, *msgtype;
|
||||
unsigned int offset = 0;
|
||||
struct ptp_header *hdr;
|
||||
u8 msgtype;
|
||||
|
||||
if (type & PTP_CLASS_VLAN)
|
||||
offset += VLAN_HLEN;
|
||||
|
||||
switch (type & 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 (type & PTP_CLASS_V1)
|
||||
offset += OFF_PTP_CONTROL;
|
||||
|
||||
if (skb->len < offset + 1)
|
||||
hdr = ptp_parse_header(skb, type);
|
||||
if (!hdr)
|
||||
return 0;
|
||||
|
||||
msgtype = data + offset;
|
||||
msgtype = ptp_get_msgtype(hdr, type);
|
||||
|
||||
return (*msgtype & 0xf) == 0;
|
||||
return (msgtype & 0xf) == 0;
|
||||
}
|
||||
|
||||
static void dp83640_free_clocks(void)
|
||||
|
|
Loading…
Reference in New Issue