Message ID | 1350427518-7230-5-git-send-email-mugunthanvnm@ti.com |
---|---|
State | Deferred, archived |
Delegated to: | David Miller |
Headers | show |
On Wed, 2012-10-17 at 04:15 +0530, Mugunthan V N wrote: > Cc: Richard Cochran <richardcochran@gmail.com> > Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com> > --- > 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); This assumes the skb is linear. Use skb_header_pointer() to allow for fragmented skbs. Ben. > + *evt_seqid = ntohs(*seqid); > + *evt_msgtype = *msgtype & 0xf; > + > + return 0; > +} > + > #endif
On Wed, Oct 17, 2012 at 04:15:16AM +0530, Mugunthan V N wrote: > Cc: Richard Cochran <richardcochran@gmail.com> > Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com> > --- > include/linux/ptp_classify.h | 42 ++++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 42 insertions(+), 0 deletions(-) Sorry, but nak on this one. It is a bit way too long for a static inline. Also, this driver-specific code, and it doesn't belong here. Thanks, Richard > 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 > -- > 1.7.0.4 > -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
> -----Original Message----- > From: Richard Cochran [mailto:richardcochran@gmail.com] > Sent: Thursday, October 18, 2012 8:25 AM > To: N, Mugunthan V > Cc: netdev@vger.kernel.org; davem@davemloft.net > Subject: Re: [PATCH 4/6] ptp: add api to get ptp seq id and event type > from skb > > On Wed, Oct 17, 2012 at 04:15:16AM +0530, Mugunthan V N wrote: > > Cc: Richard Cochran <richardcochran@gmail.com> > > Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com> > > --- > > include/linux/ptp_classify.h | 42 > ++++++++++++++++++++++++++++++++++++++++++ > > 1 files changed, 42 insertions(+), 0 deletions(-) > > Sorry, but nak on this one. It is a bit way too long for a static > inline. Also, this driver-specific code, and it doesn't belong here. > Yeah agreed on static function too long, but this can be kept inside PTP frame work as every driver needs to use this API to parse the PTP events from the skb. Regards Mugunthan V N -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, Oct 22, 2012 at 10:46:50AM +0000, N, Mugunthan V wrote: > > Yeah agreed on static function too long, but this can be kept inside PTP > frame work as every driver needs to use this API to parse the PTP events > from the skb. No, not every driver need this code. Otherwise it would already exist in every driver. Although some of the hardware does provide packet metadata for matching time stamps to payloads, each hardware that I know of has its own subtle differences in this regard. Thanks, Richard -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
> -----Original Message----- > From: Richard Cochran [mailto:richardcochran@gmail.com] > Sent: Monday, October 22, 2012 5:06 PM > To: N, Mugunthan V > Cc: netdev@vger.kernel.org; davem@davemloft.net > Subject: Re: [PATCH 4/6] ptp: add api to get ptp seq id and event type > from skb > > On Mon, Oct 22, 2012 at 10:46:50AM +0000, N, Mugunthan V wrote: > > > > Yeah agreed on static function too long, but this can be kept inside > PTP > > frame work as every driver needs to use this API to parse the PTP > events > > from the skb. > > No, not every driver need this code. Otherwise it would already exist > in every driver. > > Although some of the hardware does provide packet metadata for > matching time stamps to payloads, each hardware that I know of has its > own subtle differences in this regard. > Ok, will move this code to CPTS driver itself. Regards Mugunthan V N -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, Oct 22, 2012 at 12:32:20PM +0000, N, Mugunthan V wrote: > > Ok, will move this code to CPTS driver itself. No need to fix this, since, as I already told you, I am going ahead with my own CPTS driver. BTW, maybe you could take a closer look at it and see what could be improved? Thanks, Richard -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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
Cc: Richard Cochran <richardcochran@gmail.com> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com> --- include/linux/ptp_classify.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-)