DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
To: Robin Zhang <robinx.zhang@intel.com>, dev@dpdk.org
Cc: qiming.yang@intel.com, qi.z.zhang@intel.com,
	stevex.yang@intel.com, thomas@monjalon.net,
	bruce.richardson@intel.com, david.marchand@redhat.com
Subject: Re: [PATCH v3 1/5] ethdev: add telemetry command for module EEPROM
Date: Wed, 20 Apr 2022 12:16:21 +0300	[thread overview]
Message-ID: <61bb171e-ecc7-c250-19af-d98b78fa60e2@oktetlabs.ru> (raw)
In-Reply-To: <20220420070017.119739-2-robinx.zhang@intel.com>

On 4/20/22 10:00, Robin Zhang wrote:
> Add a new telemetry command /ethdev/module_eeprom to dump the module
> EEPROM of each port. The format of module EEPROM information follows
> the SFF(Small Form Factor) Committee specifications.
> 
> Current the format support SFP(Small Formfactor Pluggable)/SFP+/
> QSFP+(Quad Small Formfactor Pluggable)/QSFP28 with specs SFF-8079/
> SFF-8472/SFF-8024/SFF-8636.
> 
> Signed-off-by: Robin Zhang <robinx.zhang@intel.com>
> ---
>   lib/ethdev/ethdev_sff_telemetry.c | 135 ++++++++++++++++++++++++++++++
>   lib/ethdev/ethdev_sff_telemetry.h |  42 ++++++++++
>   lib/ethdev/meson.build            |   5 ++
>   lib/ethdev/rte_ethdev.c           |   3 +
>   4 files changed, 185 insertions(+)
>   create mode 100644 lib/ethdev/ethdev_sff_telemetry.c
>   create mode 100644 lib/ethdev/ethdev_sff_telemetry.h
> 
> diff --git a/lib/ethdev/ethdev_sff_telemetry.c b/lib/ethdev/ethdev_sff_telemetry.c
> new file mode 100644
> index 0000000000..60dc19c206
> --- /dev/null
> +++ b/lib/ethdev/ethdev_sff_telemetry.c
> @@ -0,0 +1,135 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2018 Cavium, Inc

I'm wondering why the patch comes from intel.com, but has
Cavium copyright dated by 2018.

> + */
> +
> +#include <rte_ethdev.h>
> +#include <rte_common.h>
> +#include "ethdev_sff_telemetry.h"
> +
> +static void
> +sff_port_module_eeprom_display(uint16_t port_id, sff_item *items)
> +{
> +	struct rte_eth_dev_module_info minfo;
> +	struct rte_dev_eeprom_info einfo;
> +	int ret;
> +
> +	ret = rte_eth_dev_get_module_info(port_id, &minfo);
> +	if (ret != 0) {
> +		switch (ret) {
> +		case -ENODEV:
> +			fprintf(stderr, "port index %d invalid\n", port_id);

Why is it go to stderr directly? Shouldn't DPDK logging be
used?

> +			break;
> +		case -ENOTSUP:
> +			fprintf(stderr, "operation not supported by device\n");
> +			break;
> +		case -EIO:
> +			fprintf(stderr, "device is removed\n");
> +			break;
> +		default:
> +			fprintf(stderr, "Unable to get module EEPROM: %d\n",
> +				ret);
> +			break;
> +		}
> +		return;
> +	}
> +
> +	einfo.offset = 0;
> +	einfo.length = minfo.eeprom_len;
> +	einfo.data = calloc(1, minfo.eeprom_len);
> +	if (!einfo.data) {

Compare vs NULL

> +		fprintf(stderr,
> +			"Allocation of port %u eeprom data failed\n",
> +			port_id);
> +		return;
> +	}
> +
> +	ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
> +	if (ret != 0) {
> +		switch (ret) {
> +		case -ENODEV:
> +			fprintf(stderr, "port index %d invalid\n", port_id);
> +			break;
> +		case -ENOTSUP:
> +			fprintf(stderr, "operation not supported by device\n");
> +			break;
> +		case -EIO:
> +			fprintf(stderr, "device is removed\n");
> +			break;
> +		default:
> +			fprintf(stderr, "Unable to get module EEPROM: %d\n",
> +				ret);
> +			break;
> +		}

It looks like a duplicate of above switch.

> +		free(einfo.data);
> +		return;
> +	}
> +
> +	switch (minfo.type) {
> +	case RTE_ETH_MODULE_SFF_8079:
> +		sff_8079_show_all(einfo.data, items);

I guess the build is broken after the patch since the function
is not defined. It is added in follow up patches.
I think corresponding cases should be added in follow up
patches which add corresponding spec support.

> +		break;
> +	case RTE_ETH_MODULE_SFF_8472:
> +		sff_8079_show_all(einfo.data, items);
> +		sff_8472_show_all(einfo.data, items);

same here

> +		break;
> +	case RTE_ETH_MODULE_SFF_8436:
> +	case RTE_ETH_MODULE_SFF_8636:
> +		sff_8636_show_all(einfo.data, einfo.length, items);

same here

> +		break;
> +	default:

Don't we need some logging to help user to understand
that eeprom type is not supported?

> +		break;
> +	}
> +	printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
> +	free(einfo.data);
> +}
> +
> +void
> +add_item_string(sff_item *items, const char *name_str, const char *value_str)
> +{
> +	/* append different values for same keys */
> +	if (sff_item_count > 0 &&
> +	    (strcmp(items[sff_item_count - 1].name, name_str) == 0)) {
> +		strcat(items[sff_item_count - 1].value, "; ");
> +		strcat(items[sff_item_count - 1].value, value_str);
> +		return;
> +	}
> +
> +	sprintf(items[sff_item_count].name, "%s", name_str);
> +	sprintf(items[sff_item_count].value, "%s", value_str);

strcat() and sprintf() are terribly unsafe and should be
avoided. Use strlcat() and snprintf() instead.

> +	sff_item_count++;
> +}
> +
> +int
> +eth_dev_handle_port_module_eeprom(const char *cmd __rte_unused, const char *params,
> +				  struct rte_tel_data *d)
> +{
> +	char *end_param;
> +	int port_id, i;
> +	sff_item *items;
> +	sff_item_count = 0;
> +
> +	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
> +		return -1;
> +
> +	port_id = strtoul(params, &end_param, 0);

Strictly speaking we need to care about about overflow here,
since if input string is a long long string of digits,
end_param will point to \0, but errno will be set to ERANGE.

'man strtoul' recommends to reset errno to 0 and check it after
the call.

> +	if (*end_param != '\0')
> +		RTE_ETHDEV_LOG(NOTICE,
> +			"Extra parameters passed to ethdev telemetry command, ignoring");
> +
> +	items = (sff_item *)malloc(SFF_ITEM_SIZE * SFF_ITEM_MAX_COUNT);

Since we allocate an array here with specified element size and
number of elements, calloc() should be used.
Type cast from 'void *' is not required in C.

> +	if (items == NULL) {
> +		printf("Error allocating memory of items\n");

Why is RTE_ETHDEV_LOG used above, but not here?
Why above error logging uses fprintf(stderr, ...), but
error logs are sent to stdout here?

I think that RTE_ETHDEV_LOG should be used everywhere.

> +		free(items);

What's the point to free items, if it is known to be NULL?

> +		return -1;
> +	}
> +
> +	sff_port_module_eeprom_display(port_id, items);
> +
> +	rte_tel_data_start_dict(d);
> +	for (i = 0; i < sff_item_count; i++)
> +		rte_tel_data_add_dict_string(d, items[i].name, items[i].value);
> +
> +	free(items);
> +	return 0;
> +}
> +
> diff --git a/lib/ethdev/ethdev_sff_telemetry.h b/lib/ethdev/ethdev_sff_telemetry.h
> new file mode 100644
> index 0000000000..fd032407c8
> --- /dev/null
> +++ b/lib/ethdev/ethdev_sff_telemetry.h
> @@ -0,0 +1,42 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2018 Cavium, Inc
> + */
> +
> +#ifndef ETHDEV_SFF_H_
> +#define ETHDEV_SFF_H_

Header guard names should follow file name, i.e.
ETHDEV_SFF_TELEMETRY_H_.

(It is still open question to have some prefix,
leading understand etc since various approaches
are present in DPDK headers).

> +
> +#include <rte_ethdev.h>

It looks like the include is not actually used in the
header.

> +#include <rte_telemetry.h>
> +
> +#define ARRAY_SIZE(arr) RTE_DIM(arr)
> +
> +#define SFF_ITEM_NAME_SIZE 64
> +#define SFF_ITEM_VALUE_SIZE 256
> +#define SFF_ITEM_MAX_COUNT 256
> +#define TMP_STRING_SIZE 64

This one is really bad define since it does not explain its
indented usage. Is it for value? Or is it to compose name?
So, it is hard to say if specified value is sufficient and
taking into account that you don't check overflow anyway.

> +
> +typedef struct sff_module_info_item {
> +	char name[SFF_ITEM_NAME_SIZE];    /* The item name. */
> +	char value[SFF_ITEM_VALUE_SIZE];  /* The item value. */
> +} sff_item;

Typically DPDK does not use typedefs for structures and
use 'struct sff_item' as is.

> +
> +#define SFF_ITEM_SIZE sizeof(sff_item)

I see no value in introduction of the define.
As far as I can see it is used only once and
sizeof(struct sff_item) would look better there.

> +
> +uint16_t sff_item_count;
> +
> +/* SFF-8079 Optics diagnostics */
> +void sff_8079_show_all(const uint8_t *id, sff_item *items);

What is 'id' above? Is it some kind identifier?
As far as I can see struct rte_dev_eeprom_info.data is passed
there. If so, why is it called 'id' here?
Don't we need to pass length to check inside that we never
have out-of-bounds access (e.g. if something is buggy and
provided information is not terminated properly).


> +
> +/* SFF-8472 Optics diagnostics */
> +void sff_8472_show_all(const uint8_t *id, sff_item *items);
> +
> +/* SFF-8636 Optics diagnostics */
> +void sff_8636_show_all(const uint8_t *id, uint32_t eeprom_len, sff_item *items);
> +
> +int eth_dev_handle_port_module_eeprom(const char *cmd __rte_unused,
> +				      const char *params,
> +				      struct rte_tel_data *d);
> +
> +void add_item_string(sff_item *items, const char *name_str, const char *value_str);
> +
> +#endif /* ETHDEV_SFF_H_ */
> diff --git a/lib/ethdev/meson.build b/lib/ethdev/meson.build
> index a094585bf7..88ceeb12b9 100644
> --- a/lib/ethdev/meson.build
> +++ b/lib/ethdev/meson.build
> @@ -11,6 +11,11 @@ sources = files(
>           'rte_flow.c',
>           'rte_mtr.c',
>           'rte_tm.c',
> +        'ethdev_sff_telemetry.c',
> +        'sff_common.c',
> +        'sff_8079.c',
> +        'sff_8472.c',
> +        'sff_8636.c',

Is it a mail client glitch or alignment above really differs:
TABs vs spaces?

>   )
>   
>   headers = files(

[snip]

  reply	other threads:[~2022-04-20  9:16 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-15 10:18 [PATCH] app/testpmd: format dump information of " Robin Zhang
2022-02-15 13:28 ` Ferruh Yigit
2022-02-15 15:07   ` Thomas Monjalon
2022-02-16  2:26     ` Zhang, RobinX
2022-02-16  8:03       ` David Marchand
2022-02-16  8:45         ` Thomas Monjalon
2022-02-16  9:30           ` Bruce Richardson
2022-02-16  9:41             ` David Marchand
2022-02-16 10:02               ` Bruce Richardson
2022-02-16 10:15                 ` David Marchand
2022-04-08 10:23 ` [PATCH v2] common/sff_module: add telemetry command to dump " Robin Zhang
2022-04-08 10:33   ` Bruce Richardson
2022-04-08 10:55     ` Zhang, RobinX
2022-04-08 11:00       ` Bruce Richardson
2022-04-08 11:20         ` Zhang, RobinX
2022-04-08 11:26           ` Bruce Richardson
2022-04-11  8:13             ` Zhang, RobinX
2022-04-11  9:13               ` Bruce Richardson
2022-04-13 12:13                 ` Thomas Monjalon
2022-04-14  7:41                   ` David Marchand
2022-04-20  7:00 ` [PATCH v3 0/5] add telemetry command for show " Robin Zhang
2022-04-20  7:00   ` [PATCH v3 1/5] ethdev: add telemetry command for " Robin Zhang
2022-04-20  9:16     ` Andrew Rybchenko [this message]
2022-04-20  7:00   ` [PATCH v3 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-04-20  7:00   ` [PATCH v3 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-04-20  7:00   ` [PATCH v3 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-04-20  7:00   ` [PATCH v3 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-04-20  8:49   ` [PATCH v3 0/5] add telemetry command for show module EEPROM Morten Brørup
2022-04-25  5:34 ` [PATCH v4 " Robin Zhang
2022-04-25  5:34   ` [PATCH v4 1/5] ethdev: add telemetry command for " Robin Zhang
2022-04-25  5:34   ` [PATCH v4 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-04-25  5:34   ` [PATCH v4 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-04-25  5:34   ` [PATCH v4 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-04-25  5:34   ` [PATCH v4 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-04-26  2:43 ` [PATCH v5 0/5] add telemetry command for show module EEPROM Robin Zhang
2022-04-26  2:43   ` [PATCH v5 1/5] ethdev: add telemetry command for " Robin Zhang
2022-05-04 10:16     ` Andrew Rybchenko
2022-04-26  2:43   ` [PATCH v5 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-04-26  2:43   ` [PATCH v5 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-04-26  2:43   ` [PATCH v5 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-04-26  2:43   ` [PATCH v5 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-05-04  8:13   ` [PATCH v5 0/5] add telemetry command for show module EEPROM Andrew Rybchenko
2022-05-11  2:14   ` [PATCH v6 " Robin Zhang
2022-05-11  2:14     ` [PATCH v6 1/5] ethdev: add telemetry command for " Robin Zhang
2022-05-11  2:14     ` [PATCH v6 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-05-11  2:14     ` [PATCH v6 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-05-11  2:14     ` [PATCH v6 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-05-19  8:33       ` Andrew Rybchenko
2022-05-11  2:14     ` [PATCH v6 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-05-24  6:24     ` [PATCH v7 0/5] add telemetry command for show module EEPROM Robin Zhang
2022-05-24  6:24       ` [PATCH v7 1/5] ethdev: add telemetry command for " Robin Zhang
2022-05-24  6:24       ` [PATCH v7 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-05-24  6:24       ` [PATCH v7 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-05-24  6:24       ` [PATCH v7 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-05-24  6:24       ` [PATCH v7 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-05-24  9:03         ` David Marchand
2022-05-25  2:43           ` Zhang, RobinX
2022-05-25  3:14       ` [PATCH v8 0/5] add telemetry command for show module EEPROM Robin Zhang
2022-05-25  3:14         ` [PATCH v8 1/5] ethdev: add telemetry command for " Robin Zhang
2022-05-25  9:24           ` Andrew Rybchenko
2022-05-25  3:14         ` [PATCH v8 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-05-25  8:51           ` Andrew Rybchenko
2022-05-25  9:40           ` Andrew Rybchenko
2022-05-25  3:14         ` [PATCH v8 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-05-25  9:55           ` Andrew Rybchenko
2022-05-25  3:14         ` [PATCH v8 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-05-25 11:58           ` Andrew Rybchenko
2022-05-25  3:14         ` [PATCH v8 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-05-25  9:01           ` Andrew Rybchenko
2022-05-25 12:01           ` Andrew Rybchenko
2022-05-26  7:32         ` [PATCH v9 0/5] add telemetry command for show module EEPROM Robin Zhang
2022-05-26  7:32           ` [PATCH v9 1/5] ethdev: add telemetry command for " Robin Zhang
2022-05-26  7:32           ` [PATCH v9 2/5] ethdev: add common code for different SFF specs Robin Zhang
2022-05-26  7:32           ` [PATCH v9 3/5] ethdev: support SFF-8079 module information telemetry Robin Zhang
2022-05-26  7:32           ` [PATCH v9 4/5] ethdev: support SFF-8472 " Robin Zhang
2022-05-26  7:32           ` [PATCH v9 5/5] ethdev: support SFF-8636 " Robin Zhang
2022-05-31 14:43           ` [PATCH v9 0/5] add telemetry command for show module EEPROM Andrew Rybchenko

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=61bb171e-ecc7-c250-19af-d98b78fa60e2@oktetlabs.ru \
    --to=andrew.rybchenko@oktetlabs.ru \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=qi.z.zhang@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=robinx.zhang@intel.com \
    --cc=stevex.yang@intel.com \
    --cc=thomas@monjalon.net \
    /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).