From patchwork Tue Oct 16 22:45:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mugunthan V N X-Patchwork-Id: 191903 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 568022C00A8 for ; Wed, 17 Oct 2012 09:45:39 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755718Ab2JPWpe (ORCPT ); Tue, 16 Oct 2012 18:45:34 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:53360 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755358Ab2JPWpb (ORCPT ); Tue, 16 Oct 2012 18:45:31 -0400 Received: from dbdp20.itg.ti.com ([172.24.170.38]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id q9GMjSGg023308; Tue, 16 Oct 2012 17:45:29 -0500 Received: from DBDE71.ent.ti.com (localhost [127.0.0.1]) by dbdp20.itg.ti.com (8.13.8/8.13.8) with ESMTP id q9GMjPmD006489; Wed, 17 Oct 2012 04:15:27 +0530 (IST) Received: from dbdp32.itg.ti.com (172.24.170.251) by DBDE71.ent.ti.com (172.24.170.149) with Microsoft SMTP Server id 14.1.323.3; Wed, 17 Oct 2012 04:15:26 +0530 Received: from localhost.localdomain (dbdp20.itg.ti.com [172.24.170.38]) by dbdp32.itg.ti.com (8.13.8/8.13.8) with ESMTP id q9GMjMgX003116; Wed, 17 Oct 2012 04:15:26 +0530 From: Mugunthan V N To: CC: , Richard Cochran , Mugunthan V N Subject: [PATCH 4/6] ptp: add api to get ptp seq id and event type from skb Date: Wed, 17 Oct 2012 04:15:16 +0530 Message-ID: <1350427518-7230-5-git-send-email-mugunthanvnm@ti.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1350427518-7230-1-git-send-email-mugunthanvnm@ti.com> References: <1350427518-7230-1-git-send-email-mugunthanvnm@ti.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Cc: Richard Cochran Signed-off-by: Mugunthan V N --- include/linux/ptp_classify.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h index 1dc420b..9b3b55b 100644 --- a/include/linux/ptp_classify.h +++ b/include/linux/ptp_classify.h @@ -137,4 +137,46 @@ static inline int ptp_filter_init(struct sock_filter *f, int len) {OP_RETA, 0, 0, 0 }, /* */ \ /*L6x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, +static inline int ptp_get_skb_event(struct sk_buff *skb, u32 ptp_class, + u16 *evt_seqid, u8 *evt_msgtype) +{ + u16 *seqid; + unsigned int offset; + u8 *msgtype, *data = skb->data; + + switch (ptp_class) { + case PTP_CLASS_V1_IPV4: + case PTP_CLASS_V2_IPV4: + offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN; + break; + case PTP_CLASS_V1_IPV6: + case PTP_CLASS_V2_IPV6: + offset = OFF_PTP6; + break; + case PTP_CLASS_V2_L2: + offset = ETH_HLEN; + break; + case PTP_CLASS_V2_VLAN: + offset = ETH_HLEN + VLAN_HLEN; + break; + default: + return 0; + } + + if (skb->len + ETH_HLEN < offset + OFF_PTP_SEQUENCE_ID + sizeof(*seqid)) + return 0; + + if (unlikely(ptp_class & PTP_CLASS_V1)) + msgtype = data + offset + OFF_PTP_CONTROL; + else + msgtype = data + offset; + + seqid = (u16 *)(data + offset + OFF_PTP_SEQUENCE_ID); + + *evt_seqid = ntohs(*seqid); + *evt_msgtype = *msgtype & 0xf; + + return 0; +} + #endif