From patchwork Thu Jul 30 08:00:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 1338698 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=XmzTcdCL; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=V/H9UZ8Z; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BHNBy1gw0z9sRW for ; Thu, 30 Jul 2020 18:00:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728832AbgG3IA4 (ORCPT ); Thu, 30 Jul 2020 04:00:56 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:48602 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726287AbgG3IAz (ORCPT ); Thu, 30 Jul 2020 04:00:55 -0400 From: Kurt Kanzenbach DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1596096054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1t4y2N6HKjAv6a/LdlcDy0zwrL1j61Kl789tc3VQTG4=; b=XmzTcdCLe+/cRQZ7Q2Vfj5mBalmPZP6IR27wDSWbQ7oAEs367D6NrlQr2nNYIbtiVVZg0W WklkdaBAa1UFvR+9QFgpIpKZGq5+knTKGp5k7q7LAeluvVIxIdnzCLMCjqMS4jgqDVfUyC o+Uqt0poXZrFbSe0jhQ0pyCx512wRdCkic5/ZBanx7VBAh8LbTaXsBBnRoOmvxuL0IWaZk zj8D+L/MjaltzVfUXpxR0zJiSvV+xuUubI0eDwyAumPJcryxhSViZrNTcCiDrwUTLs8fKq l4P/7qd4ImDb+IXiNhMG8a8CFmtYd04YUkwyFUzkr5jyObJF5bnnV95nc+M5KA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1596096054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1t4y2N6HKjAv6a/LdlcDy0zwrL1j61Kl789tc3VQTG4=; b=V/H9UZ8ZSyN1GoOCznaYv7BWWP5YilrlqnZYQTs9I6Nousr4kr6kTCgTEvC7VTJAuHIf+s u+TjM/mBByUEHZBw== To: Richard Cochran Cc: Andrew Lunn , Vivien Didelot , Florian Fainelli , "David S. Miller" , Jakub Kicinski , Jiri Pirko , Ido Schimmel , Heiner Kallweit , Russell King , Grygorii Strashko , Ivan Khoronzhuk , Samuel Zou , netdev@vger.kernel.org, Petr Machata , Kurt Kanzenbach Subject: [PATCH v3 2/9] ptp: Add generic ptp message type function Date: Thu, 30 Jul 2020 10:00:41 +0200 Message-Id: <20200730080048.32553-3-kurt@linutronix.de> In-Reply-To: <20200730080048.32553-1-kurt@linutronix.de> References: <20200730080048.32553-1-kurt@linutronix.de> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Reviewed-by: Richard Cochran Reviewed-by: Florian Fainelli --- include/linux/ptp_classify.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h index 26fd38a4bd67..f4dd42fddc0c 100644 --- a/include/linux/ptp_classify.h +++ b/include/linux/ptp_classify.h @@ -90,6 +90,30 @@ 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)