summaryrefslogtreecommitdiffstats
path: root/include/linux/ptp_classify.h
diff options
context:
space:
mode:
authorKurt Kanzenbach <kurt@linutronix.de>2020-08-18 12:32:44 +0200
committerDavid S. Miller <davem@davemloft.net>2020-08-19 16:07:49 -0700
commit036c508ba95e573f53bd5bbb79b0c4d71003b319 (patch)
treeb09208c59aaca9fa858cdae2e4070a269bdca702 /include/linux/ptp_classify.h
parentbdfbb63c314a6fb7d27dddd62f5a3e4f062b92bb (diff)
downloadlinux-stable-036c508ba95e573f53bd5bbb79b0c4d71003b319.tar.gz
linux-stable-036c508ba95e573f53bd5bbb79b0c4d71003b319.tar.bz2
linux-stable-036c508ba95e573f53bd5bbb79b0c4d71003b319.zip
ptp: Add generic ptp message type function
The message type is located at different offsets within the ptp header depending on the ptp version (v1 or v2). Therefore, drivers which also deal with ptp v1 have some code for it. Extract this into a helper function for drivers to be used. Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de> Reviewed-by: Richard Cochran <richardcochran@gmail.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/ptp_classify.h')
-rw-r--r--include/linux/ptp_classify.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h
index 0a9cc0eb0801..cfc6d9152f69 100644
--- a/include/linux/ptp_classify.h
+++ b/include/linux/ptp_classify.h
@@ -96,6 +96,31 @@ unsigned int ptp_classify_raw(const struct sk_buff *skb);
*/
struct ptp_header *ptp_parse_header(struct sk_buff *skb, unsigned int type);
+/**
+ * ptp_get_msgtype - Extract ptp message type from given header
+ * @hdr: ptp header
+ * @type: type of the packet (see ptp_classify_raw())
+ *
+ * This function returns the message type for a given ptp header. It takes care
+ * of the different ptp header versions (v1 or v2).
+ *
+ * Return: The message type
+ */
+static inline u8 ptp_get_msgtype(const struct ptp_header *hdr,
+ unsigned int type)
+{
+ u8 msgtype;
+
+ if (unlikely(type & PTP_CLASS_V1)) {
+ /* msg type is located at the control field for ptp v1 */
+ msgtype = hdr->control;
+ } else {
+ msgtype = hdr->tsmt & 0x0f;
+ }
+
+ return msgtype;
+}
+
void __init ptp_classifier_init(void);
#else
static inline void ptp_classifier_init(void)