From: Andrew Lunn <andrew@lunn.ch>
To: Kory Maincent <kory.maincent@bootlin.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Jonathan Corbet <corbet@lwn.net>,
Luis Chamberlain <mcgrof@kernel.org>,
Russ Weight <russ.weight@linux.dev>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH net-next 9/9] net: pse-pd: Add PD692x0 PSE controller driver
Date: Sat, 18 Nov 2023 19:54:30 +0100 [thread overview]
Message-ID: <45694d77-bcf8-4377-9aa0-046796de8d74@lunn.ch> (raw)
In-Reply-To: <20231116-feature_poe-v1-9-be48044bf249@bootlin.com>
> +struct pd692x0_priv {
> + struct i2c_client *client;
> + struct pse_controller_dev pcdev;
> +
> + enum pd692x0_fw_state fw_state;
> + struct fw_upload *fwl;
> + bool cancel_request:1;
> +
> + u8 msg_id;
> + bool last_cmd_key:1;
Does a bool bit field of size 1 make any sense? I would also put the
two bitfields next to each other, and the compiler might then pack
them into the same word. The base type of a u8 would allow the compile
to put it next to the msg_id without any padding.
> + unsigned long last_cmd_key_time;
> +
> + enum ethtool_pse_admin_state admin_state[PD692X0_MAX_LOGICAL_PORTS];
> +};
> +
> +/* Template list of the fixed bytes of the communication messages */
> +static const struct pd692x0_msg pd692x0_msg_template_list[PD692X0_MSG_CNT] = {
> + [PD692X0_MSG_RESET] = {
> + .content = {
> + .key = PD692X0_KEY_CMD,
> + .sub = {0x07, 0x55, 0x00},
> + .data = {0x55, 0x00, 0x55, 0x4e,
> + 0x4e, 0x4e, 0x4e, 0x4e},
> + },
> + },
Is there any documentation about what all these magic number mean?
> +/* Implementation of the i2c communication in particular when there is
> + * a communication loss. See the "Synchronization During Communication Loss"
> + * paragraph of the Communication Protocol document.
> + */
Is this document public?
> +static int pd692x0_recv_msg(struct pd692x0_priv *priv,
> + struct pd692x0_msg *msg,
> + struct pd692x0_msg_content *buf)
> +{
> + const struct i2c_client *client = priv->client;
> + int ret;
> +
> + memset(buf, 0, sizeof(*buf));
> + if (msg->delay_recv)
> + msleep(msg->delay_recv);
> + else
> + msleep(30);
> +
> + i2c_master_recv(client, (u8 *)buf, sizeof(*buf));
> + if (buf->key)
> + goto out;
This is the first attempt to receive the message. I assume buf->key
not being 0 indicates something has been received?
> +
> + msleep(100);
> +
> + i2c_master_recv(client, (u8 *)buf, sizeof(*buf));
> + if (buf->key)
> + goto out;
So this is a second attempt. Should there be another memset? Could the
first failed transfer fill the buffer with random junk in the higher
bytes, and a successful read here could be a partial read and the end
of the buffer still contains the junk.
> +
> + ret = pd692x0_send_msg(priv, msg);
> + if (ret)
> + return ret;
So now we are re-transmitting the request.
> +
> + if (msg->delay_recv)
> + msleep(msg->delay_recv);
> + else
> + msleep(30);
> +
> + i2c_master_recv(client, (u8 *)buf, sizeof(*buf));
> + if (buf->key)
> + goto out;
> +
> + msleep(100);
> +
> + i2c_master_recv(client, (u8 *)buf, sizeof(*buf));
> + if (buf->key)
> + goto out;
> +
> + msleep(10000);
And two more attemps to receive it.
> +
> + ret = pd692x0_send_msg(priv, msg);
> + if (ret)
> + return ret;
> +
> + if (msg->delay_recv)
> + msleep(msg->delay_recv);
> + else
> + msleep(30);
> +
> + i2c_master_recv(client, (u8 *)buf, sizeof(*buf));
> + if (buf->key)
> + goto out;
> +
> + msleep(100);
> +
> + i2c_master_recv(client, (u8 *)buf, sizeof(*buf));
> + if (buf->key)
> + goto out;
Another resend and two more attempts to receive.
Is there a reason to not uses for loops here? And maybe put
send/receive/receive into a helper? And maybe make the first send part
of this, rather then separate? I think the code will be more readable
when restructured.
> +static int pd692x0_ethtool_set_config(struct pse_controller_dev *pcdev,
> + unsigned long id,
> + struct netlink_ext_ack *extack,
> + const struct pse_control_config *config)
> +{
> + struct pd692x0_priv *priv = to_pd692x0_priv(pcdev);
> + struct pd692x0_msg_content buf = {0};
> + struct pd692x0_msg msg;
> + int ret;
> +
> + ret = pd692x0_fw_unavailable(priv);
> + if (ret)
> + return ret;
It seems a bit late to check if the device has any firmware. I would
of expected probe to check that, and maybe attempt to download
firmware. If that fails, fail the probe, since the PSE is a brick.
> +static struct pd692x0_msg_ver pd692x0_get_sw_version(struct pd692x0_priv *priv)
> +{
> + struct pd692x0_msg msg = pd692x0_msg_template_list[PD692X0_MSG_GET_SW_VER];
> + struct device *dev = &priv->client->dev;
> + struct pd692x0_msg_content buf = {0};
> + struct pd692x0_msg_ver ver = {0};
> + int ret;
> +
> + ret = pd692x0_sendrecv_msg(priv, &msg, &buf);
> + if (ret < 0) {
> + dev_err(dev, "Failed to get PSE version (%pe)\n", ERR_PTR(ret));
> + return ver;
I _think_ that return is wrong ???
> +static enum fw_upload_err pd692x0_fw_write(struct fw_upload *fwl,
> + const u8 *data, u32 offset,
> + u32 size, u32 *written)
> +{
> + struct pd692x0_priv *priv = fwl->dd_handle;
> + char line[PD692X0_FW_LINE_MAX_SZ];
> + const struct i2c_client *client;
> + int ret, i;
> + char cmd;
> +
> + client = priv->client;
> + priv->fw_state = PD692X0_FW_WRITE;
> +
> + /* Erase */
> + cmd = 'E';
> + ret = i2c_master_send(client, &cmd, 1);
> + if (ret < 0) {
> + dev_err(&client->dev,
> + "Failed to boot programming mode (%pe)\n",
> + ERR_PTR(ret));
> + return FW_UPLOAD_ERR_RW_ERROR;
> + }
> +
> + ret = pd692x0_fw_recv_resp(client, 100, "TOE\r\n", sizeof("TOE\r\n") - 1);
> + if (ret)
> + return ret;
> +
> + ret = pd692x0_fw_recv_resp(client, 5000, "TE\r\n", sizeof("TE\r\n") - 1);
> + if (ret)
> + dev_warn(&client->dev,
> + "Failed to erase internal memory, however still try to write Firmware\n");
> +
> + ret = pd692x0_fw_recv_resp(client, 100, "TPE\r\n", sizeof("TPE\r\n") - 1);
> + if (ret)
> + dev_warn(&client->dev,
> + "Failed to erase internal memory, however still try to write Firmware\n");
> +
> + if (priv->cancel_request)
> + return FW_UPLOAD_ERR_CANCELED;
> +
> + /* Program */
> + cmd = 'P';
> + ret = i2c_master_send(client, &cmd, sizeof(char));
> + if (ret < 0) {
> + dev_err(&client->dev,
> + "Failed to boot programming mode (%pe)\n",
> + ERR_PTR(ret));
> + return ret;
> + }
> +
> + ret = pd692x0_fw_recv_resp(client, 100, "TOP\r\n", sizeof("TOP\r\n") - 1);
> + if (ret)
> + return ret;
> +
> + i = 0;
> + while (i < size) {
> + ret = pd692x0_fw_get_next_line(data, line, size - i);
> + if (!ret) {
> + ret = FW_UPLOAD_ERR_FW_INVALID;
> + goto err;
> + }
> +
> + i += ret;
> + data += ret;
> + if (line[0] == 'S' && line[1] == '0') {
> + continue;
> + } else if (line[0] == 'S' && line[1] == '7') {
> + ret = pd692x0_fw_write_line(client, line, true);
> + if (ret)
> + goto err;
Is the firmware in Motorola SREC format? I thought the kernel had a
helper for that, but a quick search did not find it. So maybe i'm
remembering wrongly. But it seems silly for every driver to implement
an SREC parser.
Andrew
next prev parent reply other threads:[~2023-11-18 18:57 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-16 14:01 [PATCH net-next 0/9] net: Add support for Power over Ethernet (PoE) Kory Maincent
2023-11-16 14:01 ` [PATCH net-next 1/9] net: pse-pd: Rectify and adapt the naming of admin_cotrol member of struct pse_control_config Kory Maincent
2023-11-16 14:01 ` [PATCH net-next 2/9] ethtool: Expand Ethernet Power Equipment with PoE alongside PoDL Kory Maincent
2023-11-18 17:38 ` Andrew Lunn
2023-11-20 10:09 ` Köry Maincent
2023-11-20 11:10 ` Oleksij Rempel
2023-11-20 18:00 ` Andrew Lunn
2023-11-20 20:42 ` Oleksij Rempel
2023-11-20 22:14 ` Andrew Lunn
2023-11-21 5:12 ` Oleksij Rempel
2023-11-21 10:02 ` Köry Maincent
2023-11-21 14:19 ` Andrew Lunn
2023-11-21 14:56 ` Köry Maincent
2023-11-16 14:01 ` [PATCH net-next 3/9] net: pse-pd: Introduce PSE types enumeration Kory Maincent
2023-11-24 16:35 ` Simon Horman
2023-11-16 14:01 ` [PATCH net-next 4/9] net: ethtool: pse-pd: Expand pse commands with the PSE PoE interface Kory Maincent
2023-11-16 14:01 ` [PATCH net-next 5/9] netlink: specs: Modify pse attribute prefix Kory Maincent
2023-11-18 23:57 ` Jakub Kicinski
2023-11-20 10:19 ` Köry Maincent
2023-11-20 16:53 ` Jakub Kicinski
2023-11-16 14:01 ` [PATCH net-next 6/9] netlink: specs: Expand the pse netlink command with PoE interface Kory Maincent
2023-11-19 0:01 ` Jakub Kicinski
2023-11-20 10:13 ` Köry Maincent
2023-11-16 14:01 ` [PATCH net-next 7/9] firmware_loader: Expand Firmware upload error codes Kory Maincent
2023-11-16 16:30 ` Luis Chamberlain
2023-11-16 16:37 ` Greg Kroah-Hartman
2023-11-16 17:44 ` Conor Dooley
2023-11-16 21:56 ` Andrew Lunn
2023-11-17 8:56 ` Köry Maincent
2023-11-16 14:01 ` [PATCH net-next 8/9] dt-bindings: net: pse-pd: Add bindings for PD692x0 PSE controller Kory Maincent
2023-11-16 14:31 ` Krzysztof Kozlowski
2023-11-18 17:47 ` Andrew Lunn
2023-11-16 14:01 ` [PATCH net-next 9/9] net: pse-pd: Add PD692x0 PSE controller driver Kory Maincent
2023-11-16 14:29 ` Krzysztof Kozlowski
2023-11-16 14:59 ` Köry Maincent
2023-11-16 22:38 ` Andrew Lunn
2023-11-17 11:15 ` Köry Maincent
2023-11-16 22:41 ` Andrew Lunn
2023-11-17 11:22 ` Köry Maincent
2023-11-17 14:50 ` Andrew Lunn
2023-11-16 22:54 ` Andrew Lunn
2023-11-22 16:11 ` Köry Maincent
2023-11-22 16:54 ` Andrew Lunn
2023-11-22 17:16 ` Köry Maincent
2023-11-22 17:49 ` Andrew Lunn
2023-11-18 18:54 ` Andrew Lunn [this message]
2023-11-22 16:48 ` Köry Maincent
2023-11-22 17:11 ` Andrew Lunn
2023-11-27 17:28 ` Köry Maincent
2023-11-24 16:30 ` Simon Horman
2023-11-18 23:59 ` [PATCH net-next 0/9] net: Add support for Power over Ethernet (PoE) Jakub Kicinski
2023-11-20 9:22 ` Köry Maincent
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=45694d77-bcf8-4377-9aa0-046796de8d74@lunn.ch \
--to=andrew@lunn.ch \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=kory.maincent@bootlin.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
--cc=russ.weight@linux.dev \
--cc=thomas.petazzoni@bootlin.com \
/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
all inboxes | Powered by JetHome®