examples/ethtool: add a new command module-eeprom
authorZijie Pan <zijie.pan@6wind.com>
Wed, 25 Apr 2018 14:02:03 +0000 (16:02 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 27 Apr 2018 17:00:53 +0000 (18:00 +0100)
Add a new command "module-eeprom" to get the data of plugin
module EEPROM.

Signed-off-by: Zijie Pan <zijie.pan@6wind.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Remy Horton <remy.horton@intel.com>
doc/guides/sample_app_ug/ethtool.rst
examples/ethtool/ethtool-app/ethapp.c
examples/ethtool/lib/Makefile
examples/ethtool/lib/rte_ethtool.c
examples/ethtool/lib/rte_ethtool.h

index 1b79aca..47e09f6 100644 (file)
@@ -44,6 +44,7 @@ they do as as follows:
 
 * ``drvinfo``: Print driver info
 * ``eeprom``: Dump EEPROM to file
+* ``module-eeprom``: Dump plugin module EEPROM to file
 * ``link``: Print port link states
 * ``macaddr``: Gets/sets MAC address
 * ``mtu``: Set NIC MTU
@@ -97,6 +98,8 @@ the following functions:
 - ``rte_ethtool_get_eeprom_len()``
 - ``rte_ethtool_get_eeprom()``
 - ``rte_ethtool_set_eeprom()``
+- ``rte_ethtool_get_module_info()``
+- ``rte_ethtool_get_module_eeprom()``
 - ``rte_ethtool_get_pauseparam()``
 - ``rte_ethtool_set_pauseparam()``
 - ``rte_ethtool_net_open()``
index 4d62f4c..a4e64b3 100644 (file)
@@ -75,6 +75,9 @@ cmdline_parse_token_num_t pcmd_int_token_port =
 /* Commands taking port id and string */
 cmdline_parse_token_string_t pcmd_eeprom_token_cmd =
        TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "eeprom");
+cmdline_parse_token_string_t pcmd_module_eeprom_token_cmd =
+       TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd,
+                                "module-eeprom");
 cmdline_parse_token_string_t pcmd_mtu_token_cmd =
        TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "mtu");
 cmdline_parse_token_string_t pcmd_regs_token_cmd =
@@ -297,6 +300,54 @@ pcmd_eeprom_callback(void *ptr_params,
 }
 
 
+static void
+pcmd_module_eeprom_callback(void *ptr_params,
+       __rte_unused struct cmdline *ctx,
+       __rte_unused void *ptr_data)
+{
+       struct pcmd_intstr_params *params = ptr_params;
+       struct ethtool_eeprom info_eeprom;
+       uint32_t module_info[2];
+       int stat;
+       unsigned char bytes_eeprom[EEPROM_DUMP_CHUNKSIZE];
+       FILE *fp_eeprom;
+
+       if (!rte_eth_dev_is_valid_port(params->port)) {
+               printf("Error: Invalid port number %i\n", params->port);
+               return;
+       }
+
+       stat = rte_ethtool_get_module_info(params->port, module_info);
+       if (stat != 0) {
+               printf("Module EEPROM information read error %i\n", stat);
+               return;
+       }
+
+       info_eeprom.len = module_info[1];
+       info_eeprom.offset = 0;
+
+       stat = rte_ethtool_get_module_eeprom(params->port,
+                                            &info_eeprom, bytes_eeprom);
+       if (stat != 0) {
+               printf("Module EEPROM read error %i\n", stat);
+               return;
+       }
+
+       fp_eeprom = fopen(params->opt, "wb");
+       if (fp_eeprom == NULL) {
+               printf("Error opening '%s' for writing\n", params->opt);
+               return;
+       }
+       printf("Total plugin module EEPROM length: %i bytes\n",
+              info_eeprom.len);
+       if (fwrite(bytes_eeprom, 1, info_eeprom.len,
+                  fp_eeprom) != info_eeprom.len) {
+               printf("Error writing '%s'\n", params->opt);
+       }
+       fclose(fp_eeprom);
+}
+
+
 static void
 pcmd_pause_callback(void *ptr_params,
        __rte_unused struct cmdline *ctx,
@@ -664,6 +715,18 @@ cmdline_parse_inst_t pcmd_eeprom = {
                NULL
        },
 };
+cmdline_parse_inst_t pcmd_module_eeprom = {
+       .f = pcmd_module_eeprom_callback,
+       .data = NULL,
+       .help_str = "module-eeprom <port_id> <filename>\n"
+               "     Dump plugin module EEPROM to file",
+       .tokens = {
+               (void *)&pcmd_module_eeprom_token_cmd,
+               (void *)&pcmd_intstr_token_port,
+               (void *)&pcmd_intstr_token_opt,
+               NULL
+       },
+};
 cmdline_parse_inst_t pcmd_pause_noopt = {
        .f = pcmd_pause_callback,
        .data = (void *)0x01,
@@ -816,6 +879,7 @@ cmdline_parse_inst_t pcmd_vlan = {
 cmdline_parse_ctx_t list_prompt_commands[] = {
        (cmdline_parse_inst_t *)&pcmd_drvinfo,
        (cmdline_parse_inst_t *)&pcmd_eeprom,
+       (cmdline_parse_inst_t *)&pcmd_module_eeprom,
        (cmdline_parse_inst_t *)&pcmd_link,
        (cmdline_parse_inst_t *)&pcmd_macaddr_get,
        (cmdline_parse_inst_t *)&pcmd_macaddr,
index fbafa6d..2576910 100644 (file)
@@ -25,6 +25,7 @@ SRCS-y := rte_ethtool.c
 
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y)
 ifeq ($(CONFIG_RTE_LIBRTE_IXGBE_PMD),y)
index d519a50..e6a2e88 100644 (file)
@@ -177,6 +177,36 @@ rte_ethtool_set_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
        return 0;
 }
 
+int
+rte_ethtool_get_module_info(uint16_t port_id, uint32_t *modinfo)
+{
+       struct rte_eth_dev_module_info *info;
+
+       info = (struct rte_eth_dev_module_info *)modinfo;
+       return rte_eth_dev_get_module_info(port_id, info);
+}
+
+int
+rte_ethtool_get_module_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
+       void *words)
+{
+       struct rte_dev_eeprom_info eeprom_info;
+       int status;
+
+       if (eeprom == NULL || words == NULL)
+               return -EINVAL;
+
+       eeprom_info.offset = eeprom->offset;
+       eeprom_info.length = eeprom->len;
+       eeprom_info.data = words;
+
+       status = rte_eth_dev_get_module_eeprom(port_id, &eeprom_info);
+       if (status)
+               return status;
+
+       return 0;
+}
+
 int
 rte_ethtool_get_pauseparam(uint16_t port_id,
        struct ethtool_pauseparam *pause_param)
index c962396..43adc97 100644 (file)
@@ -153,6 +153,40 @@ int rte_ethtool_get_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
 int rte_ethtool_set_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
                              void *words);
 
+/**
+ * Retrieve the type and size of plugin module EEPROM
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param modinfo
+ *      The pointer that provides the type and size of plugin module EEPROM.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_get_module_info(uint16_t port_id, uint32_t *modinfo);
+
+/**
+ * Retrieve the data of plugin module EEPROM
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param eeprom
+ *      The pointer of ethtool_eeprom that provides plugin module eeprom
+ *   offset and length
+ * @param words
+ *      A buffer that holds data read from plugin module eeprom
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_get_module_eeprom(uint16_t port_id,
+                                 struct ethtool_eeprom *eeprom, void *words);
+
 /**
  * Retrieve the Ethernet device pause frame configuration according to
  * parameter attributes desribed by ethtool data structure,