From patchwork Tue Dec 7 14:59:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12662039 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D83DC433F5 for ; Tue, 7 Dec 2021 15:00:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238445AbhLGPDb (ORCPT ); Tue, 7 Dec 2021 10:03:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238420AbhLGPD2 (ORCPT ); Tue, 7 Dec 2021 10:03:28 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 723F3C061746; Tue, 7 Dec 2021 06:59:57 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id r11so57792843edd.9; Tue, 07 Dec 2021 06:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XMNmsVbZ++MHzR0SNpTs4rnf9cjrjDzn4muZEXZ4TMk=; b=BBOE+8v2JgPlmc9NmwyI892BKiNEtdR3mPvH3HVG/2O4AtM9xyolgA+91P7Wfnbuol Cm7yJLO/6l2Ly874Ta85OaRC1R93PEVICZgo5xoV4OxbHDGZsKNHNXOm3H8rEhbWSRKc +E9h60qnAwBA9KJztBmXy4M77DF63pKV5pA76g/enGeTR8uKq5zk+4idWdypLwIXXivc KfNyCPa4gQNqpnYA20FIVlJ+DJFq1pwbhAFWBhyuqDQjMXXmKYbUtutneElW6TV+Ia3/ 5Ea9wGjSFFbKBGrG2Zi/Txezcxvu4/RyQbD4N+t9fM0AQeuZVXlhYsLlzKC0sG64y9gc i0xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XMNmsVbZ++MHzR0SNpTs4rnf9cjrjDzn4muZEXZ4TMk=; b=G/Hjk5wCzCK9VusVIjg6mdGhhzA8X7BjhJLqZCjhPbrsM3a3dO6XQWL9Dv81iG8O59 UPUwZADZ0ZlXD190LMNayrG/4j4ySYwW9Nq4O7aXifxrWS/W6u+SuKXvM3TEPCTbpIyZ mhABdJaqq+1eufumoWFP/ieuUtCPclzMm/SuFVtBykD38h3PysXX92nGXGmSk4gF4kkq 5PvcrJghMP7vgavBK9AV7nivhCmb0n+JT24NG2uNAnfWF1wKu/Cu+rWvP56YACFLKZTg pIJRAK3S3u+DGO9an8oQC+Ncc6V/Oy/zgdXn2nM0CL6yDKh9sRb7kwYWT0J+5Cougie/ 2+0Q== X-Gm-Message-State: AOAM533rxjOJ2KrRg1qhNrpWAsr5s4Q26mC3x+3hAxWyY62Kzq43/WLJ fgNiWEy2wTacq8du1s4ZAqMPj93uCp4= X-Google-Smtp-Source: ABdhPJyWcbV9kFRcsSqPbDbh1k6/XEFPxHM34EJ8F0P4S+DZiMWPqDw1W9A4pr+eERTxHWPtn8IrDA== X-Received: by 2002:a05:6402:4302:: with SMTP id m2mr9660540edc.349.1638889195902; Tue, 07 Dec 2021 06:59:55 -0800 (PST) Received: from localhost.localdomain (93-42-71-246.ip85.fastwebnet.it. [93.42.71.246]) by smtp.googlemail.com with ESMTPSA id i10sm9131821ejw.48.2021.12.07.06.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 06:59:55 -0800 (PST) From: Ansuel Smith To: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Ansuel Smith Subject: [net-next RFC PATCH 3/6] net: dsa: tag_qca: add define for mdio read/write in ethernet packet Date: Tue, 7 Dec 2021 15:59:39 +0100 Message-Id: <20211207145942.7444-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211207145942.7444-1-ansuelsmth@gmail.com> References: <20211207145942.7444-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add all the required define to prepare support for mdio read/write in Ethernet packet. Any packet of this type has to be dropped as the only use of these special packet is receive ack for an mdio write request or receive data for an mdio read request. A struct is used that emulates the Ethernet header but is used for a different purpose. Signed-off-by: Ansuel Smith --- include/linux/dsa/tag_qca.h | 41 +++++++++++++++++++++++++++++++++++++ net/dsa/tag_qca.c | 13 +++++++++--- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/include/linux/dsa/tag_qca.h b/include/linux/dsa/tag_qca.h index c02d2d39ff4a..578a4aeafd92 100644 --- a/include/linux/dsa/tag_qca.h +++ b/include/linux/dsa/tag_qca.h @@ -12,10 +12,51 @@ #define QCA_HDR_RECV_FRAME_IS_TAGGED BIT(3) #define QCA_HDR_RECV_SOURCE_PORT GENMASK(2, 0) +/* Packet type for recv */ +#define QCA_HDR_RECV_TYPE_NORMAL 0x0 +#define QCA_HDR_RECV_TYPE_MIB 0x1 +#define QCA_HDR_RECV_TYPE_RW_REG_ACK 0x2 + #define QCA_HDR_XMIT_VERSION GENMASK(15, 14) #define QCA_HDR_XMIT_PRIORITY GENMASK(13, 11) #define QCA_HDR_XMIT_CONTROL GENMASK(10, 8) #define QCA_HDR_XMIT_FROM_CPU BIT(7) #define QCA_HDR_XMIT_DP_BIT GENMASK(6, 0) +/* Packet type for xmit */ +#define QCA_HDR_XMIT_TYPE_NORMAL 0x0 +#define QCA_HDR_XMIT_TYPE_RW_REG 0x1 + +#define MDIO_CHECK_CODE_VAL 0x5 + +/* Specific define for in-band MDIO read/write with Ethernet packet */ +#define QCA_HDR_MDIO_SEQ_LEN 4 /* 4 byte for the seq */ +#define QCA_HDR_MDIO_COMMAND_LEN 4 /* 4 byte for the command */ +#define QCA_HDR_MDIO_DATA1_LEN 4 /* First 4 byte for the mdio data */ +#define QCA_HDR_MDIO_HEADER_LEN (QCA_HDR_MDIO_SEQ_LEN + \ + QCA_HDR_MDIO_COMMAND_LEN + \ + QCA_HDR_MDIO_DATA1_LEN) + +#define QCA_HDR_MDIO_DATA2_LEN 12 /* Other 12 byte for the mdio data */ +#define QCA_HDR_MDIO_PADDING_LEN 34 /* Padding to reach the min Ethernet packet */ + +#define QCA_HDR_MDIO_PKG_LEN (QCA_HDR_MDIO_HEADER_LEN + \ + QCA_HDR_LEN + \ + QCA_HDR_MDIO_DATA2_LEN + \ + QCA_HDR_MDIO_PADDING_LEN) + +#define QCA_HDR_MDIO_SEQ_NUM GENMASK(31, 0) /* 63, 32 */ +#define QCA_HDR_MDIO_CHECK_CODE GENMASK(31, 29) /* 31, 29 */ +#define QCA_HDR_MDIO_CMD BIT(28) /* 28 */ +#define QCA_HDR_MDIO_LENGTH GENMASK(23, 20) /* 23, 20 */ +#define QCA_HDR_MDIO_ADDR GENMASK(18, 0) /* 18, 0 */ + +/* Special struct emulating a Ethernet header */ +struct mdio_ethhdr { + u32 command; /* command bit 31:0 */ + u32 seq; /* seq 63:32 */ + u32 mdio_data; /* first 4byte mdio */ + u16 hdr; /* qca hdr */ +} __packed; + #endif /* __TAG_QCA_H */ diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c index 34e565e00ece..b8b05d54a74c 100644 --- a/net/dsa/tag_qca.c +++ b/net/dsa/tag_qca.c @@ -32,10 +32,10 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev) static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev) { - u8 ver; - u16 hdr; - int port; + u16 hdr, pk_type; __be16 *phdr; + int port; + u8 ver; if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN))) return NULL; @@ -48,6 +48,13 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev) if (unlikely(ver != QCA_HDR_VERSION)) return NULL; + /* Get pk type */ + pk_type = FIELD_GET(QCA_HDR_RECV_TYPE, hdr); + + /* MDIO read/write packet */ + if (pk_type == QCA_HDR_RECV_TYPE_RW_REG_ACK) + return NULL; + /* Remove QCA tag and recalculate checksum */ skb_pull_rcsum(skb, QCA_HDR_LEN); dsa_strip_etype_header(skb, QCA_HDR_LEN);