generic: 5.15: backport mdio improvement patch for qca8k
[openwrt/staging/mkresin.git] / target / linux / generic / backport-5.15 / 766-03-net-dsa-tag_qca-convert-to-FIELD-macro.patch
1 From 6b0458299297ca4ab6fb295800e29a4e501d50c1 Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Wed, 2 Feb 2022 01:03:22 +0100
4 Subject: [PATCH 03/16] net: dsa: tag_qca: convert to FIELD macro
5
6 Convert driver to FIELD macro to drop redundant define.
7
8 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
9 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
10 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
12 ---
13 net/dsa/tag_qca.c | 34 +++++++++++++++-------------------
14 1 file changed, 15 insertions(+), 19 deletions(-)
15
16 diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
17 index 1ea9401b8ace..55fa6b96b4eb 100644
18 --- a/net/dsa/tag_qca.c
19 +++ b/net/dsa/tag_qca.c
20 @@ -4,29 +4,24 @@
21 */
22
23 #include <linux/etherdevice.h>
24 +#include <linux/bitfield.h>
25
26 #include "dsa_priv.h"
27
28 #define QCA_HDR_LEN 2
29 #define QCA_HDR_VERSION 0x2
30
31 -#define QCA_HDR_RECV_VERSION_MASK GENMASK(15, 14)
32 -#define QCA_HDR_RECV_VERSION_S 14
33 -#define QCA_HDR_RECV_PRIORITY_MASK GENMASK(13, 11)
34 -#define QCA_HDR_RECV_PRIORITY_S 11
35 -#define QCA_HDR_RECV_TYPE_MASK GENMASK(10, 6)
36 -#define QCA_HDR_RECV_TYPE_S 6
37 +#define QCA_HDR_RECV_VERSION GENMASK(15, 14)
38 +#define QCA_HDR_RECV_PRIORITY GENMASK(13, 11)
39 +#define QCA_HDR_RECV_TYPE GENMASK(10, 6)
40 #define QCA_HDR_RECV_FRAME_IS_TAGGED BIT(3)
41 -#define QCA_HDR_RECV_SOURCE_PORT_MASK GENMASK(2, 0)
42 -
43 -#define QCA_HDR_XMIT_VERSION_MASK GENMASK(15, 14)
44 -#define QCA_HDR_XMIT_VERSION_S 14
45 -#define QCA_HDR_XMIT_PRIORITY_MASK GENMASK(13, 11)
46 -#define QCA_HDR_XMIT_PRIORITY_S 11
47 -#define QCA_HDR_XMIT_CONTROL_MASK GENMASK(10, 8)
48 -#define QCA_HDR_XMIT_CONTROL_S 8
49 +#define QCA_HDR_RECV_SOURCE_PORT GENMASK(2, 0)
50 +
51 +#define QCA_HDR_XMIT_VERSION GENMASK(15, 14)
52 +#define QCA_HDR_XMIT_PRIORITY GENMASK(13, 11)
53 +#define QCA_HDR_XMIT_CONTROL GENMASK(10, 8)
54 #define QCA_HDR_XMIT_FROM_CPU BIT(7)
55 -#define QCA_HDR_XMIT_DP_BIT_MASK GENMASK(6, 0)
56 +#define QCA_HDR_XMIT_DP_BIT GENMASK(6, 0)
57
58 static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
59 {
60 @@ -40,8 +35,9 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
61 phdr = dsa_etype_header_pos_tx(skb);
62
63 /* Set the version field, and set destination port information */
64 - hdr = QCA_HDR_VERSION << QCA_HDR_XMIT_VERSION_S |
65 - QCA_HDR_XMIT_FROM_CPU | BIT(dp->index);
66 + hdr = FIELD_PREP(QCA_HDR_XMIT_VERSION, QCA_HDR_VERSION);
67 + hdr |= QCA_HDR_XMIT_FROM_CPU;
68 + hdr |= FIELD_PREP(QCA_HDR_XMIT_DP_BIT, BIT(dp->index));
69
70 *phdr = htons(hdr);
71
72 @@ -62,7 +58,7 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
73 hdr = ntohs(*phdr);
74
75 /* Make sure the version is correct */
76 - ver = (hdr & QCA_HDR_RECV_VERSION_MASK) >> QCA_HDR_RECV_VERSION_S;
77 + ver = FIELD_GET(QCA_HDR_RECV_VERSION, hdr);
78 if (unlikely(ver != QCA_HDR_VERSION))
79 return NULL;
80
81 @@ -71,7 +67,7 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
82 dsa_strip_etype_header(skb, QCA_HDR_LEN);
83
84 /* Get source port information */
85 - port = (hdr & QCA_HDR_RECV_SOURCE_PORT_MASK);
86 + port = FIELD_GET(QCA_HDR_RECV_SOURCE_PORT, hdr);
87
88 skb->dev = dsa_master_find_slave(dev, 0, port);
89 if (!skb->dev)
90 --
91 2.34.1
92