1 From 90386223f44e2a751d7e9e9ac8f78ea33358a891 Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Wed, 2 Feb 2022 01:03:34 +0100
4 Subject: [PATCH 15/16] net: dsa: qca8k: add support for larger read/write size
7 mgmt Ethernet packet can read/write up to 16byte at times. The len reg
8 is limited to 15 (0xf). The switch actually sends and accepts data in 4
9 different steps of len values.
16 In the alloc skb function we check if the len is 16 and we fix it to a
17 len of 15. It the read/write function interest to extract the real asked
18 data. The tagger handler will always copy the fully 16byte with a READ
19 command. This is useful for some big regs like the fdb reg that are
20 more than 4byte of data. This permits to introduce a bulk function that
21 will send and request the entire entry in one go.
22 Write function is changed and it does now require to pass the pointer to
23 val to also handle array val.
25 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
26 Signed-off-by: David S. Miller <davem@davemloft.net>
28 drivers/net/dsa/qca8k.c | 61 +++++++++++++++++++++++++++--------------
29 1 file changed, 41 insertions(+), 20 deletions(-)
31 --- a/drivers/net/dsa/qca8k.c
32 +++ b/drivers/net/dsa/qca8k.c
33 @@ -222,7 +222,9 @@ static void qca8k_rw_reg_ack_handler(str
34 if (cmd == MDIO_READ) {
35 mgmt_eth_data->data[0] = mgmt_ethhdr->mdio_data;
37 - /* Get the rest of the 12 byte of data */
38 + /* Get the rest of the 12 byte of data.
39 + * The read/write function will extract the requested data.
41 if (len > QCA_HDR_MGMT_DATA1_LEN)
42 memcpy(mgmt_eth_data->data + 1, skb->data,
43 QCA_HDR_MGMT_DATA2_LEN);
44 @@ -232,16 +234,30 @@ static void qca8k_rw_reg_ack_handler(str
47 static struct sk_buff *qca8k_alloc_mdio_header(enum mdio_cmd cmd, u32 reg, u32 *val,
49 + int priority, unsigned int len)
51 struct qca_mgmt_ethhdr *mgmt_ethhdr;
52 + unsigned int real_len;
57 skb = dev_alloc_skb(QCA_HDR_MGMT_PKT_LEN);
61 + /* Max value for len reg is 15 (0xf) but the switch actually return 16 byte
62 + * Actually for some reason the steps are:
65 + * 5-6: first 12 byte
73 skb_reset_mac_header(skb);
74 skb_set_network_header(skb, skb->len);
76 @@ -254,7 +270,7 @@ static struct sk_buff *qca8k_alloc_mdio_
77 hdr |= FIELD_PREP(QCA_HDR_XMIT_CONTROL, QCA_HDR_XMIT_TYPE_RW_REG);
79 mgmt_ethhdr->command = FIELD_PREP(QCA_HDR_MGMT_ADDR, reg);
80 - mgmt_ethhdr->command |= FIELD_PREP(QCA_HDR_MGMT_LENGTH, 4);
81 + mgmt_ethhdr->command |= FIELD_PREP(QCA_HDR_MGMT_LENGTH, real_len);
82 mgmt_ethhdr->command |= FIELD_PREP(QCA_HDR_MGMT_CMD, cmd);
83 mgmt_ethhdr->command |= FIELD_PREP(QCA_HDR_MGMT_CHECK_CODE,
84 QCA_HDR_MGMT_CHECK_CODE_VAL);
85 @@ -264,7 +280,9 @@ static struct sk_buff *qca8k_alloc_mdio_
87 mgmt_ethhdr->hdr = htons(hdr);
89 - skb_put_zero(skb, QCA_HDR_MGMT_DATA2_LEN + QCA_HDR_MGMT_PADDING_LEN);
90 + data2 = skb_put_zero(skb, QCA_HDR_MGMT_DATA2_LEN + QCA_HDR_MGMT_PADDING_LEN);
91 + if (cmd == MDIO_WRITE && len > QCA_HDR_MGMT_DATA1_LEN)
92 + memcpy(data2, val + 1, len - QCA_HDR_MGMT_DATA1_LEN);
96 @@ -277,7 +295,7 @@ static void qca8k_mdio_header_fill_seq_n
97 mgmt_ethhdr->seq = FIELD_PREP(QCA_HDR_MGMT_SEQ_NUM, seq_num);
100 -static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val)
101 +static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
103 struct qca8k_mgmt_eth_data *mgmt_eth_data = &priv->mgmt_eth_data;
105 @@ -285,7 +303,7 @@ static int qca8k_read_eth(struct qca8k_p
108 skb = qca8k_alloc_mdio_header(MDIO_READ, reg, NULL,
109 - QCA8K_ETHERNET_MDIO_PRIORITY);
110 + QCA8K_ETHERNET_MDIO_PRIORITY, len);
114 @@ -313,6 +331,9 @@ static int qca8k_read_eth(struct qca8k_p
115 msecs_to_jiffies(QCA8K_ETHERNET_TIMEOUT));
117 *val = mgmt_eth_data->data[0];
118 + if (len > QCA_HDR_MGMT_DATA1_LEN)
119 + memcpy(val + 1, mgmt_eth_data->data + 1, len - QCA_HDR_MGMT_DATA1_LEN);
121 ack = mgmt_eth_data->ack;
123 mutex_unlock(&mgmt_eth_data->mutex);
124 @@ -326,15 +347,15 @@ static int qca8k_read_eth(struct qca8k_p
128 -static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 val)
129 +static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
131 struct qca8k_mgmt_eth_data *mgmt_eth_data = &priv->mgmt_eth_data;
136 - skb = qca8k_alloc_mdio_header(MDIO_WRITE, reg, &val,
137 - QCA8K_ETHERNET_MDIO_PRIORITY);
138 + skb = qca8k_alloc_mdio_header(MDIO_WRITE, reg, val,
139 + QCA8K_ETHERNET_MDIO_PRIORITY, len);
143 @@ -380,14 +401,14 @@ qca8k_regmap_update_bits_eth(struct qca8
147 - ret = qca8k_read_eth(priv, reg, &val);
148 + ret = qca8k_read_eth(priv, reg, &val, sizeof(val));
155 - return qca8k_write_eth(priv, reg, val);
156 + return qca8k_write_eth(priv, reg, &val, sizeof(val));
160 @@ -398,7 +419,7 @@ qca8k_regmap_read(void *ctx, uint32_t re
164 - if (!qca8k_read_eth(priv, reg, val))
165 + if (!qca8k_read_eth(priv, reg, val, sizeof(val)))
168 qca8k_split_addr(reg, &r1, &r2, &page);
169 @@ -424,7 +445,7 @@ qca8k_regmap_write(void *ctx, uint32_t r
173 - if (!qca8k_write_eth(priv, reg, val))
174 + if (!qca8k_write_eth(priv, reg, &val, sizeof(val)))
177 qca8k_split_addr(reg, &r1, &r2, &page);
178 @@ -959,21 +980,21 @@ qca8k_phy_eth_command(struct qca8k_priv
181 /* Prealloc all the needed skb before the lock */
182 - write_skb = qca8k_alloc_mdio_header(MDIO_WRITE, QCA8K_MDIO_MASTER_CTRL,
183 - &write_val, QCA8K_ETHERNET_PHY_PRIORITY);
184 + write_skb = qca8k_alloc_mdio_header(MDIO_WRITE, QCA8K_MDIO_MASTER_CTRL, &write_val,
185 + QCA8K_ETHERNET_PHY_PRIORITY, sizeof(write_val));
189 - clear_skb = qca8k_alloc_mdio_header(MDIO_WRITE, QCA8K_MDIO_MASTER_CTRL,
190 - &clear_val, QCA8K_ETHERNET_PHY_PRIORITY);
191 + clear_skb = qca8k_alloc_mdio_header(MDIO_WRITE, QCA8K_MDIO_MASTER_CTRL, &clear_val,
192 + QCA8K_ETHERNET_PHY_PRIORITY, sizeof(clear_val));
198 - read_skb = qca8k_alloc_mdio_header(MDIO_READ, QCA8K_MDIO_MASTER_CTRL,
199 - &clear_val, QCA8K_ETHERNET_PHY_PRIORITY);
201 + read_skb = qca8k_alloc_mdio_header(MDIO_READ, QCA8K_MDIO_MASTER_CTRL, &clear_val,
202 + QCA8K_ETHERNET_PHY_PRIORITY, sizeof(clear_val));