From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id C9B37235 for ; Fri, 30 Jun 2017 18:52:11 +0200 (CEST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jun 2017 09:52:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,287,1496127600"; d="scan'208";a="103233387" Received: from silpixa00372839.ir.intel.com (HELO silpixa00372839.ger.corp.intel.com) ([10.237.222.154]) by orsmga004.jf.intel.com with ESMTP; 30 Jun 2017 09:52:10 -0700 From: Ferruh Yigit To: dev@dpdk.org Cc: Ferruh Yigit , Stephen Hemminger , Bruce Richardson , Anatoly Burakov Date: Fri, 30 Jun 2017 17:51:38 +0100 Message-Id: <20170630165140.59594-19-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170630165140.59594-1-ferruh.yigit@intel.com> References: <20170621110651.75299-1-ferruh.yigit@intel.com> <20170630165140.59594-1-ferruh.yigit@intel.com> Subject: [dpdk-dev] [PATCH v9 18/20] ctrl_if: process ethtool messages X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jun 2017 16:52:12 -0000 Process ethtool messages and rend response back to kernel. Signed-off-by: Ferruh Yigit --- lib/librte_ctrl_if/rte_ctrl_process.c | 223 ++++++++++++++++++++++++++++++++++ lib/librte_ctrl_if/rte_ctrl_process.h | 4 + lib/librte_ctrl_if/rte_nl.c | 4 + 3 files changed, 231 insertions(+) diff --git a/lib/librte_ctrl_if/rte_ctrl_process.c b/lib/librte_ctrl_if/rte_ctrl_process.c index cfb243f64..55fd54351 100644 --- a/lib/librte_ctrl_if/rte_ctrl_process.c +++ b/lib/librte_ctrl_if/rte_ctrl_process.c @@ -38,8 +38,231 @@ #include #include +#include #include "rte_ctrl_process.h" +#define ETHTOOL_GEEPROM_LEN 99 +#define ETHTOOL_GREGS_LEN 98 +#define ETHTOOL_GSSET_COUNT 97 + +static int +get_settings(uint8_t port_id __rte_unused, void *data, size_t *data_len) +{ + struct ethtool_cmd *ecmd = data; + + /* No PMD equivalent, added to make get pauseparam work */ + memset(ecmd, 0, sizeof(struct ethtool_cmd)); + + *data_len = sizeof(struct ethtool_cmd); + return 0; +} + +static int +get_drvinfo(uint8_t port_id, void *data, size_t *data_len) +{ + struct ethtool_drvinfo *info = data; + int ret; + + ret = rte_ethtool_get_drvinfo(port_id, info); + if (ret < 0) + return ret; + + *data_len = sizeof(struct ethtool_drvinfo); + + return 0; +} + +static int +get_reg_len(uint8_t port_id, void *data, size_t *data_len) +{ + int reg_length = 0; + + reg_length = rte_ethtool_get_regs_len(port_id); + if (reg_length < 0) + return reg_length; + + *(int *)data = reg_length; + *data_len = sizeof(int); + + return 0; +} + +static int +get_reg_len_internal(uint8_t port_id, size_t *reg_length) +{ + size_t reg_length_out_len; + + return get_reg_len(port_id, reg_length, ®_length_out_len); +} + +static int +get_reg(uint8_t port_id, void *in_data, void *out_data, size_t *out_data_len) +{ + size_t reg_length; + struct ethtool_regs *ethtool_regs = in_data; + int ret; + + ret = get_reg_len_internal(port_id, ®_length); + /* not enough space in out data buffer */ + if (ret < 0 || reg_length > ethtool_regs->len) + return -1; + + ret = rte_ethtool_get_regs(port_id, ethtool_regs, out_data); + if (ret < 0) + return ret; + + *out_data_len = reg_length; + + return 0; +} + +static int +get_link(uint8_t port_id, void *data, size_t *data_len) +{ + int ret; + + ret = rte_ethtool_get_link(port_id); + + *(int *)data = ret; + *data_len = sizeof(size_t); + + return 0; +} + +static int +get_eeprom_length(uint8_t port_id, void *data, size_t *data_len) +{ + int eeprom_length = 0; + + eeprom_length = rte_ethtool_get_eeprom_len(port_id); + if (eeprom_length < 0) + return eeprom_length; + + *(int *)data = eeprom_length; + *data_len = sizeof(int); + + return 0; +} + +static int +get_eeprom(uint8_t port_id, void *in_data, void *out_data, + size_t *out_data_len) +{ + struct ethtool_eeprom *eeprom = in_data; + int ret; + + ret = rte_ethtool_get_eeprom(port_id, eeprom, out_data); + if (ret < 0) + return ret; + + *out_data_len = eeprom->len; + + return 0; +} + +static int +set_eeprom(uint8_t port_id, void *in_data) +{ + struct ethtool_eeprom *eeprom = in_data; + int ret; + + ret = rte_ethtool_set_eeprom(port_id, eeprom, eeprom->data); + if (ret != 0) + return -1; + + return 0; +} + +static int +get_ringparam(uint8_t port_id, void *data, size_t *data_len) +{ + struct ethtool_ringparam *ringparam = data; + int ret; + + ret = rte_ethtool_get_ringparam(port_id, ringparam); + if (ret < 0) + return ret; + + *data_len = sizeof(struct ethtool_ringparam); + + return 0; +} + +static int +set_ringparam(uint8_t port_id, void *data) +{ + struct ethtool_ringparam *ringparam = data; + int ret; + + ret = rte_ethtool_set_ringparam(port_id, ringparam); + if (ret != 0) + return -1; + + return 0; +} + +static int +get_pauseparam(uint8_t port_id, void *data, size_t *data_len) +{ + struct ethtool_pauseparam *pauseparam = data; + int ret; + + ret = rte_ethtool_get_pauseparam(port_id, pauseparam); + if (ret < 0) + return ret; + + *data_len = sizeof(struct ethtool_pauseparam); + + return 0; +} + +static int +set_pauseparam(uint8_t port_id, void *data) +{ + struct ethtool_pauseparam *pauseparam = data; + + return rte_ethtool_set_pauseparam(port_id, pauseparam); +} + +int +rte_eth_dev_ethtool_process(uint32_t cmd_id, uint8_t port_id, void *in_data, + void *out_data, size_t *out_data_len) +{ + if (!rte_eth_dev_is_valid_port(port_id)) + return -ENODEV; + + switch (cmd_id) { + case ETHTOOL_GSET: + return get_settings(port_id, out_data, out_data_len); + case ETHTOOL_GDRVINFO: + return get_drvinfo(port_id, out_data, out_data_len); + case ETHTOOL_GREGS_LEN: + return get_reg_len(port_id, out_data, out_data_len); + case ETHTOOL_GREGS: + return get_reg(port_id, in_data, out_data, out_data_len); + case ETHTOOL_GLINK: + return get_link(port_id, out_data, out_data_len); + case ETHTOOL_GEEPROM_LEN: + return get_eeprom_length(port_id, out_data, out_data_len); + case ETHTOOL_GEEPROM: + return get_eeprom(port_id, in_data, out_data, out_data_len); + case ETHTOOL_SEEPROM: + return set_eeprom(port_id, in_data); + case ETHTOOL_GRINGPARAM: + return get_ringparam(port_id, out_data, out_data_len); + case ETHTOOL_SRINGPARAM: + return set_ringparam(port_id, in_data); + case ETHTOOL_GPAUSEPARAM: + return get_pauseparam(port_id, out_data, out_data_len); + case ETHTOOL_SPAUSEPARAM: + return set_pauseparam(port_id, in_data); + default: + return -EOPNOTSUPP; + } + + return 0; +} + static int set_mtu(uint8_t port_id, void *in_data) { diff --git a/lib/librte_ctrl_if/rte_ctrl_process.h b/lib/librte_ctrl_if/rte_ctrl_process.h index f67c60107..caa4f15f3 100644 --- a/lib/librte_ctrl_if/rte_ctrl_process.h +++ b/lib/librte_ctrl_if/rte_ctrl_process.h @@ -38,8 +38,12 @@ extern "C" { #endif +#include + #include +int rte_eth_dev_ethtool_process(uint32_t cmd_id, uint8_t port_id, void *in_data, + void *out_data, size_t *out_data_len); int rte_eth_dev_control_process(uint32_t cmd_id, uint8_t port_id, void *in_data, void *out_data, size_t *out_data_len); diff --git a/lib/librte_ctrl_if/rte_nl.c b/lib/librte_ctrl_if/rte_nl.c index 920d123a9..d00a242d2 100644 --- a/lib/librte_ctrl_if/rte_nl.c +++ b/lib/librte_ctrl_if/rte_nl.c @@ -123,6 +123,10 @@ process_msg(struct unci_nl_msg *msg) msg->err = rte_eth_dev_control_process(msg->cmd_id, msg->port_id, msg->input_buffer, msg->output_buffer, &msg->output_buffer_len); + } else { + msg->err = rte_eth_dev_ethtool_process(msg->cmd_id, + msg->port_id, msg->input_buffer, + msg->output_buffer, &msg->output_buffer_len); } if (msg->err) -- 2.13.0