From: <Parthiban.Veerasooran@microchip.com>
To: <andrew@lunn.ch>
Cc: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<pabeni@redhat.com>, <robh+dt@kernel.org>,
<krzysztof.kozlowski+dt@linaro.org>, <conor+dt@kernel.org>,
<corbet@lwn.net>, <Steen.Hegelund@microchip.com>,
<rdunlap@infradead.org>, <horms@kernel.org>,
<casper.casan@gmail.com>, <netdev@vger.kernel.org>,
<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-doc@vger.kernel.org>, <Horatiu.Vultur@microchip.com>,
<Woojung.Huh@microchip.com>, <Nicolas.Ferre@microchip.com>,
<UNGLinuxDriver@microchip.com>,
<Thorsten.Kummermehr@microchip.com>
Subject: Re: [RFC PATCH net-next 1/6] net: ethernet: implement OPEN Alliance control transaction interface
Date: Tue, 19 Sep 2023 11:38:33 +0000 [thread overview]
Message-ID: <14c089d7-4d34-9cd5-7f77-55c80815e003@microchip.com> (raw)
In-Reply-To: <f23997c1-7507-41c6-8bb3-47d6a353beb8@lunn.ch>
Hi Andrew,
On 13/09/23 7:41 am, Andrew Lunn wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
>> +static bool oa_tc6_get_parity(u32 p)
>> +{
>> + bool parity = true;
>> +
>> + /* This function returns an odd parity bit */
>> + while (p) {
>> + parity = !parity;
>> + p = p & (p - 1);
>> + }
>> + return parity;
>
> Please take a look around and see if you can find another
> implementation in the kernel which can be used. If not, you could copy/paste:
>
> https://elixir.bootlin.com/linux/latest/source/lib/bch.c#L348
>
> which is probably more efficient.
Sure, will check out it.
>
>> +static void oa_tc6_prepare_ctrl_buf(struct oa_tc6 *tc6, u32 addr, u32 val[],
>> + u8 len, bool wnr, u8 *buf, bool ctrl_prot)
>> +{
>> + u32 hdr;
>> +
>> + /* Prepare the control header with the required details */
>> + hdr = FIELD_PREP(CTRL_HDR_DNC, 0) |
>> + FIELD_PREP(CTRL_HDR_WNR, wnr) |
>> + FIELD_PREP(CTRL_HDR_AID, 0) |
>> + FIELD_PREP(CTRL_HDR_MMS, addr >> 16) |
>> + FIELD_PREP(CTRL_HDR_ADDR, addr) |
>> + FIELD_PREP(CTRL_HDR_LEN, len - 1);
>> + hdr |= FIELD_PREP(CTRL_HDR_P, oa_tc6_get_parity(hdr));
>> + *(u32 *)buf = cpu_to_be32(hdr);
>> +
>> + if (wnr) {
>
> What does wnr mean? Maybe give it a more meaningful name, unless it is
> actually something in the standard. Kerneldoc would also help.
Ah, it is "write not read". Shall I name it as "write_not_read" ?
>
>> +static int oa_tc6_check_control(struct oa_tc6 *tc6, u8 *ptx, u8 *prx, u8 len,
>> + bool wnr, bool ctrl_prot)
>> +{
>> + /* 1st 4 bytes of rx chunk data can be discarded */
>> + u32 rx_hdr = *(u32 *)&prx[TC6_HDR_SIZE];
>> + u32 tx_hdr = *(u32 *)ptx;
>> + u32 rx_data_complement;
>> + u32 tx_data;
>> + u32 rx_data;
>> + u16 pos1;
>> + u16 pos2;
>> +
>> + /* If tx hdr and echoed hdr are not equal then there might be an issue
>> + * with the connection between SPI host and MAC-PHY. Here this case is
>> + * considered as MAC-PHY is not connected.
>
> I could understand ENODEV on the first transaction during probe. But
> after that -EIO seems more appropriate. I've also seen USB use -EPROTO
> to indicate a protocol error, which a corrupt message would be.
Ah ok, then in this case I will consider -EIO.
>
>> +int oa_tc6_perform_ctrl(struct oa_tc6 *tc6, u32 addr, u32 val[], u8 len,
>> + bool wnr, bool ctrl_prot)
>> +{
>> + u8 *tx_buf;
>> + u8 *rx_buf;
>> + u16 size;
>> + u16 pos;
>> + int ret;
>> +
>> + if (ctrl_prot)
>> + size = (TC6_HDR_SIZE * 2) + (len * (TC6_HDR_SIZE * 2));
>> + else
>> + size = (TC6_HDR_SIZE * 2) + (len * TC6_HDR_SIZE);
>
> Do you have an idea how big the biggest control message is? Rather
> than allocate these buffers for every transaction, maybe allocate
> maximum size buffers one at startup and keep them in tc6? That will
> reduce overhead and simplify the code.
Ok, as per OA spec, up to 128 consecutive registers read or write can be
possible. So the maximum possible size would be 1032. As you suggested
will allocate this size of memory in the startup.
>
>> +struct oa_tc6 *oa_tc6_init(struct spi_device *spi)
>> +{
>> + struct oa_tc6 *tc6;
>> +
>> + if (!spi)
>> + return NULL;
>
> This is defensive programming which is generally not liked. You cannot
> do anything without an SPI device, so just assume it is passed, and if
> not, let is explode later and the driver write will quickly fix there
> broken code.
Ah yes, will remove this check.
>
>> +
>> + tc6 = kzalloc(sizeof(*tc6), GFP_KERNEL);
>> + if (!tc6)
>> + return NULL;
>> +
>> + tc6->spi = spi;
>> +
>> + return tc6;
>> +}
>> +EXPORT_SYMBOL_GPL(oa_tc6_init);
>> +
>> +void oa_tc6_deinit(struct oa_tc6 *tc6)
>> +{
>> + kfree(tc6);
>> +}
>> +EXPORT_SYMBOL_GPL(oa_tc6_deinit);
>
> Maybe consider a devm_ API to make the MAC driver simpler.
Sorry I don't get your point. Could you please explain bit more?
Best Regards,
Parthiban V
>
> Andrew
>
next prev parent reply other threads:[~2023-09-19 11:39 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-08 14:29 [RFC PATCH net-next 0/6] Add support for OPEN Alliance 10BASE-T1x MACPHY Serial Interface Parthiban Veerasooran
2023-09-08 14:29 ` [RFC PATCH net-next 1/6] net: ethernet: implement OPEN Alliance control transaction interface Parthiban Veerasooran
2023-09-09 13:33 ` Andrew Lunn
2023-09-12 13:03 ` Parthiban.Veerasooran
2023-09-13 1:32 ` Andrew Lunn
2023-09-21 12:27 ` Parthiban.Veerasooran
2023-09-21 19:16 ` Andrew Lunn
2023-09-22 4:31 ` Parthiban.Veerasooran
2023-09-13 1:36 ` Andrew Lunn
2023-09-19 11:40 ` Parthiban.Veerasooran
2023-09-13 2:11 ` Andrew Lunn
2023-09-19 11:38 ` Parthiban.Veerasooran [this message]
2023-09-19 15:13 ` Andrew Lunn
2023-09-20 12:40 ` Parthiban.Veerasooran
2023-09-20 13:37 ` Andrew Lunn
2023-09-21 9:15 ` Parthiban.Veerasooran
2023-09-13 2:16 ` Andrew Lunn
2023-09-19 11:13 ` Parthiban.Veerasooran
2023-09-19 12:58 ` Andrew Lunn
2023-09-21 12:36 ` Parthiban.Veerasooran
2023-09-21 19:19 ` Andrew Lunn
2023-09-22 4:39 ` Parthiban.Veerasooran
2023-09-26 12:54 ` Fwd: " Parthiban.Veerasooran
2023-09-08 14:29 ` [RFC PATCH net-next 2/6] net: ethernet: add mac-phy interrupt support with reset complete handling Parthiban Veerasooran
2023-09-09 13:39 ` Andrew Lunn
2023-09-12 12:44 ` Parthiban.Veerasooran
2023-09-13 2:19 ` Andrew Lunn
2023-09-19 11:04 ` Parthiban.Veerasooran
2023-09-11 12:51 ` Ziyang Xuan (William)
2023-09-12 12:10 ` Andrew Lunn
2023-09-12 12:28 ` Parthiban.Veerasooran
2023-09-13 2:39 ` Andrew Lunn
2023-09-19 13:07 ` Parthiban.Veerasooran
2023-09-19 13:21 ` Lukasz Majewski
2023-09-13 8:44 ` Lukasz Majewski
2023-09-13 12:36 ` Andrew Lunn
2023-09-13 13:26 ` Lukasz Majewski
2023-09-19 13:40 ` Parthiban.Veerasooran
2023-09-19 13:51 ` Lukasz Majewski
2023-09-08 14:29 ` [RFC PATCH net-next 3/6] net: ethernet: implement OA TC6 configuration function Parthiban Veerasooran
2023-09-14 0:46 ` Andrew Lunn
2023-09-19 10:57 ` Parthiban.Veerasooran
2023-09-19 12:54 ` Andrew Lunn
2023-09-20 12:42 ` Parthiban.Veerasooran
2023-09-08 14:29 ` [RFC PATCH net-next 4/6] net: ethernet: implement data transaction interface Parthiban Veerasooran
2023-09-10 17:58 ` Simon Horman
2023-09-12 13:47 ` Parthiban.Veerasooran
2023-09-11 12:59 ` Ziyang Xuan (William)
2023-09-12 10:32 ` Parthiban.Veerasooran
2023-09-14 1:18 ` Andrew Lunn
2023-09-18 10:02 ` Parthiban.Veerasooran
2023-09-18 13:01 ` Andrew Lunn
2023-09-19 10:12 ` Parthiban.Veerasooran
2023-09-08 14:29 ` [RFC PATCH net-next 5/6] microchip: lan865x: add driver support for Microchip's LAN865X MACPHY Parthiban Veerasooran
2023-09-10 17:44 ` Simon Horman
2023-09-12 10:53 ` Parthiban.Veerasooran
2023-09-11 13:17 ` Ziyang Xuan (William)
2023-09-12 11:41 ` Parthiban.Veerasooran
2023-09-14 1:51 ` Andrew Lunn
2023-09-19 9:18 ` Parthiban.Veerasooran
2023-09-19 12:50 ` Andrew Lunn
2023-09-20 12:53 ` Parthiban.Veerasooran
2023-09-14 1:55 ` Andrew Lunn
2023-09-18 11:23 ` Parthiban.Veerasooran
2023-09-15 13:01 ` David Wretman
2023-09-18 11:22 ` Parthiban.Veerasooran
2023-09-08 14:29 ` [RFC PATCH net-next 6/6] microchip: lan865x: add device-tree " Parthiban Veerasooran
2023-09-10 10:55 ` Krzysztof Kozlowski
2023-09-12 12:15 ` Parthiban.Veerasooran
2023-09-12 13:17 ` Krzysztof Kozlowski
2023-09-19 10:51 ` Parthiban.Veerasooran
2023-09-14 2:07 ` Andrew Lunn
2023-09-19 10:40 ` Parthiban.Veerasooran
2023-09-10 10:55 ` [RFC PATCH net-next 0/6] Add support for OPEN Alliance 10BASE-T1x MACPHY Serial Interface Krzysztof Kozlowski
[not found] ` <fab8908e-ce74-eff0-8e67-6259b3ad5e1e@microchip.com>
2023-09-13 15:45 ` Krzysztof Kozlowski
2023-09-18 9:23 ` Parthiban.Veerasooran
2023-09-15 13:56 ` Alexander Dahl
2023-09-15 14:22 ` Andrew Lunn
2023-09-18 6:16 ` Parthiban.Veerasooran
2023-09-18 6:12 ` Parthiban.Veerasooran
2023-09-18 9:02 ` Fwd: " Parthiban.Veerasooran
2023-09-19 9:03 ` Parthiban.Veerasooran
2023-09-19 16:23 ` Jay Monkman
2023-09-19 18:09 ` Hennerich, Michael
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=14c089d7-4d34-9cd5-7f77-55c80815e003@microchip.com \
--to=parthiban.veerasooran@microchip.com \
--cc=Horatiu.Vultur@microchip.com \
--cc=Nicolas.Ferre@microchip.com \
--cc=Steen.Hegelund@microchip.com \
--cc=Thorsten.Kummermehr@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=Woojung.Huh@microchip.com \
--cc=andrew@lunn.ch \
--cc=casper.casan@gmail.com \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).