From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 6EAC89E3 for ; Mon, 26 Jun 2017 11:45:35 +0200 (CEST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jun 2017 02:45:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,395,1493708400"; d="scan'208";a="278650110" Received: from silpixa00383879.ir.intel.com (HELO silpixa00383879.ger.corp.intel.com) ([10.237.223.127]) by fmsmga004.fm.intel.com with ESMTP; 26 Jun 2017 02:45:32 -0700 From: Radu Nicolau To: dev@dpdk.org Cc: wenzhuo.lu@intel.com, reshma.pattan@intel.com, michalx.k.jastrzebski@intel.com, deepak.k.jain@intel.com, harry.van.haaren@intel.com, piotrx.t.azarewicz@intel.com, radu.nicolau@intel.com Date: Mon, 26 Jun 2017 10:42:13 +0100 Message-Id: <1498470133-29788-1-git-send-email-radu.nicolau@intel.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <20170522143202.22424-2-michalx.k.jastrzebski@intel.com> References: <20170522143202.22424-2-michalx.k.jastrzebski@intel.com> Subject: [dpdk-dev] [PATCH v2] drivers/net: add support for IF-MIB and EtherLike-MIB for e1000 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: Mon, 26 Jun 2017 09:45:36 -0000 From: Michal Jastrzebski If-MIB xstats: ifNumber ifIndex ifType ifMtu ifSpeed ifPhysAddress ifOperStatus ifLastChange ifHighSpeed ifConnectorPresent ifCounterDiscontinuityTime EtherLike-MIB xstats: dot3PauseOperMode dot3StatsDuplexStatus dot3StatsRateControlAbility dot3StatsRateControlStatus dot3ControlFunctionsSupported -updated in v2: coding style Signed-off-by: Piotr Azarewicz Signed-off-by: Michal Jastrzebski Signed-off-by: Radu Nicolau --- drivers/net/e1000/e1000_ethdev.h | 79 +++++++++-- drivers/net/e1000/igb_ethdev.c | 296 +++++++++++++++++++++++++++++++++++---- 2 files changed, 341 insertions(+), 34 deletions(-) diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h index 9266540..1fc82b4 100644 --- a/drivers/net/e1000/e1000_ethdev.h +++ b/drivers/net/e1000/e1000_ethdev.h @@ -275,20 +275,79 @@ struct e1000_filter_info { uint32_t syn_info; }; +#define E1000_MIB_IF_TYPE_ETHERNETCSMACD 6 + +enum { + E1000_MIB_TRUTH_TRUE = 1, + E1000_MIB_TRUTH_FALSE +}; + +/* IF-MIB statistics */ +struct e1000_if_mib_stats { + uint64_t if_number; /* ifNumber */ + uint64_t if_index; /* ifIndex */ + uint64_t if_type; /* ifType */ + uint64_t if_mtu; /* ifMtu */ + uint64_t if_speed; /* ifSpeed */ + uint64_t if_phys_address; /* ifPhysAddress */ + uint64_t if_oper_status; /* ifOperStatus */ + uint64_t if_last_change; /* ifLastChange */ + uint64_t if_high_speed; /* ifHighSpeed */ + uint64_t if_connector_present; /* ifConnectorPresent */ + uint64_t if_counter_discontinuity_time; /* ifCounterDiscontinuityTime */ +}; + +enum { + E1000_DOT3_PAUSE_DISABLED = 1, + E1000_DOT3_PAUSE_ENABLEDXMIT, + E1000_DOT3_PAUSE_ENABLEDRCV, + E1000_DOT3_PAUSE_ENABLEDXMITANDRCV +}; + +enum { + E1000_DOT3_DUPLEX_UNKNOWN = 1, + E1000_DOT3_DUPLEX_HALFDUPLEX, + E1000_DOT3_DUPLEX_FULLDUPLEX +}; + +enum { + E1000_DOT3_RATE_CONTROL_OFF = 1, + E1000_DOT3_RATE_CONTROL_ON, + E1000_DOT3_RATE_CONTROL_UNKNOWN +}; + +#define E1000_DOT3_CF_PAUSE (1 << 0) /* PAUSE command implemented */ +#define E1000_DOT3_CF_MPCP (1 << 1) /* MPCP implemented */ +#define E1000_DOT3_CF_PFC (1 << 2) /* PFC implemented */ + +/* Ethernet-like-MIB statistics */ +struct e1000_ether_like_mib_stats { + uint64_t dot3_pause_oper_mode; /* dot3PauseOperMode */ + uint64_t dot3_stats_duplex_status; /* dot3StatsDuplexStatus */ + uint64_t dot3_stats_rate_control_ability; + /* dot3StatsRateControlAbility */ + uint64_t dot3_stats_rate_control_status;/* dot3StatsRateControlStatus */ + uint64_t dot3_control_functions_supported; + /* dot3ControlFunctionsSupported */ +}; + /* * Structure to store private data for each driver instance (for each port). */ struct e1000_adapter { - struct e1000_hw hw; - struct e1000_hw_stats stats; - struct e1000_interrupt intr; - struct e1000_vfta shadow_vfta; - struct e1000_vf_info *vfdata; - struct e1000_filter_info filter; - bool stopped; - struct rte_timecounter systime_tc; - struct rte_timecounter rx_tstamp_tc; - struct rte_timecounter tx_tstamp_tc; + struct e1000_hw hw; + struct e1000_hw_stats stats; + struct e1000_interrupt intr; + struct e1000_vfta shadow_vfta; + struct e1000_vf_info *vfdata; + struct e1000_filter_info filter; + bool stopped; + struct rte_timecounter systime_tc; + struct rte_timecounter rx_tstamp_tc; + struct rte_timecounter tx_tstamp_tc; + uint64_t sys_up_time_start; + uint64_t if_last_change; + uint64_t if_counter_discontinuity_time; }; #define E1000_DEV_PRIVATE(adapter) \ diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c index a0da9d5..1f6fcdb 100644 --- a/drivers/net/e1000/igb_ethdev.c +++ b/drivers/net/e1000/igb_ethdev.c @@ -549,6 +549,45 @@ static const struct rte_igb_xstats_name_off rte_igbvf_stats_strings[] = { #define IGBVF_NB_XSTATS (sizeof(rte_igbvf_stats_strings) / \ sizeof(rte_igbvf_stats_strings[0])) +static const struct rte_igb_xstats_name_off igb_if_mib_strings[] = { + {"ifNumber", offsetof(struct e1000_if_mib_stats, if_number)}, + {"ifIndex", offsetof(struct e1000_if_mib_stats, if_index)}, + {"ifType", offsetof(struct e1000_if_mib_stats, if_type)}, + {"ifMtu", offsetof(struct e1000_if_mib_stats, if_mtu)}, + {"ifSpeed", offsetof(struct e1000_if_mib_stats, if_speed)}, + {"ifPhysAddress", offsetof(struct e1000_if_mib_stats, if_phys_address)}, + {"ifOperStatus", offsetof(struct e1000_if_mib_stats, if_oper_status)}, + {"ifLastChange", offsetof(struct e1000_if_mib_stats, if_last_change)}, + {"ifHighSpeed", offsetof(struct e1000_if_mib_stats, if_high_speed)}, + {"ifConnectorPresent", offsetof(struct e1000_if_mib_stats, + if_connector_present)}, + {"ifCounterDiscontinuityTime", offsetof(struct e1000_if_mib_stats, + if_counter_discontinuity_time)}, +}; + +#define IGB_NB_IF_MIB_XSTATS (sizeof(igb_if_mib_strings) / \ + sizeof(igb_if_mib_strings[0])) + +static const struct rte_igb_xstats_name_off igb_ether_like_mib_strings[] = { + {"dot3PauseOperMode", offsetof(struct e1000_ether_like_mib_stats, + dot3_pause_oper_mode)}, + {"dot3StatsDuplexStatus", offsetof(struct e1000_ether_like_mib_stats, + dot3_stats_duplex_status)}, + {"dot3StatsRateControlAbility", offsetof( + struct e1000_ether_like_mib_stats, + dot3_stats_rate_control_ability)}, + {"dot3StatsRateControlStatus", offsetof( + struct e1000_ether_like_mib_stats, + dot3_stats_rate_control_status)}, + {"dot3ControlFunctionsSupported", offsetof( + struct e1000_ether_like_mib_stats, + dot3_control_functions_supported)}, +}; + +#define IGB_NB_ETHER_LIKE_MIB_XSTATS \ + (sizeof(igb_ether_like_mib_strings) / \ + sizeof(igb_ether_like_mib_strings[0])) + /** * Atomically reads the link status information from global * structure rte_eth_dev. @@ -925,6 +964,11 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev) eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id); + /* indicate sysUpTime start */ + adapter->sys_up_time_start = rte_rdtsc(); + adapter->if_last_change = 0; + adapter->if_counter_discontinuity_time = 0; + rte_intr_callback_register(&pci_dev->intr_handle, eth_igb_interrupt_handler, (void *)eth_dev); @@ -1114,6 +1158,11 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev) eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id, "igb_mac_82576_vf"); + /* indicate sysUpTime start */ + adapter->sys_up_time_start = rte_rdtsc(); + adapter->if_last_change = 0; + adapter->if_counter_discontinuity_time = 0; + intr_handle = &pci_dev->intr_handle; rte_intr_callback_register(intr_handle, eth_igbvf_interrupt_handler, eth_dev); @@ -1858,12 +1907,17 @@ eth_igb_stats_reset(struct rte_eth_dev *dev) { struct e1000_hw_stats *hw_stats = E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private); + struct e1000_adapter *adapter = + E1000_DEV_PRIVATE(dev->data->dev_private); /* HW registers are cleared on read */ eth_igb_stats_get(dev, NULL); /* Reset software totals */ memset(hw_stats, 0, sizeof(*hw_stats)); + + adapter->if_counter_discontinuity_time = + rte_rdtsc() - adapter->sys_up_time_start; } static void @@ -1871,31 +1925,138 @@ eth_igb_xstats_reset(struct rte_eth_dev *dev) { struct e1000_hw_stats *stats = E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private); + struct e1000_adapter *adapter = + E1000_DEV_PRIVATE(dev->data->dev_private); /* HW registers are cleared on read */ eth_igb_xstats_get(dev, NULL, IGB_NB_XSTATS); /* Reset software totals */ memset(stats, 0, sizeof(*stats)); + + adapter->if_counter_discontinuity_time = + rte_rdtsc() - adapter->sys_up_time_start; +} + +static unsigned int +igb_xstats_calc_num(void) +{ + return IGB_NB_XSTATS + IGB_NB_IF_MIB_XSTATS + + IGB_NB_ETHER_LIKE_MIB_XSTATS; } static int eth_igb_xstats_get_names(__rte_unused struct rte_eth_dev *dev, struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned int size) { - unsigned i; + unsigned int i, count = 0; if (xstats_names == NULL) - return IGB_NB_XSTATS; + return igb_xstats_calc_num(); /* Note: limit checked in rte_eth_xstats_names() */ for (i = 0; i < IGB_NB_XSTATS; i++) { - snprintf(xstats_names[i].name, sizeof(xstats_names[i].name), + snprintf(xstats_names[count].name, + sizeof(xstats_names[count].name), "%s", rte_igb_stats_strings[i].name); + count++; + } + + /* Get stats from IF-MIB objects */ + for (i = 0; i < IGB_NB_IF_MIB_XSTATS; i++) { + snprintf(xstats_names[count].name, + sizeof(xstats_names[count].name), + "%s", igb_if_mib_strings[i].name); + count++; + } + + /* Get stats from Ethernet-like-MIB objects */ + for (i = 0; i < IGB_NB_ETHER_LIKE_MIB_XSTATS; i++) { + snprintf(xstats_names[count].name, + sizeof(xstats_names[count].name), + "%s", igb_ether_like_mib_strings[i].name); + count++; } - return IGB_NB_XSTATS; + return count; +} + +static void +igb_read_if_mib(struct rte_eth_dev *dev, struct e1000_if_mib_stats *stats) +{ + struct rte_eth_dev_data *data = dev->data; + struct rte_device *device = dev->device; + struct e1000_adapter *adapter = + E1000_DEV_PRIVATE(dev->data->dev_private); + + stats->if_number = rte_eth_dev_count(); + stats->if_index = data->port_id + 1; + stats->if_type = E1000_MIB_IF_TYPE_ETHERNETCSMACD; + stats->if_mtu = data->mtu; + stats->if_speed = (data->dev_link.link_speed < (UINT32_MAX / 1000000)) ? + (data->dev_link.link_speed * 1000000) : UINT32_MAX; + stats->if_phys_address = 0; + ether_addr_copy(data->mac_addrs, + (struct ether_addr *)&stats->if_phys_address); + stats->if_oper_status = data->dev_link.link_status ? + E1000_MIB_TRUTH_TRUE : E1000_MIB_TRUTH_FALSE; + stats->if_last_change = adapter->if_last_change / + (rte_get_tsc_hz() * 100); + stats->if_high_speed = data->dev_link.link_speed; + if (device->devargs) + stats->if_connector_present = + (device->devargs->type == RTE_DEVTYPE_VIRTUAL) ? + E1000_MIB_TRUTH_FALSE : + E1000_MIB_TRUTH_TRUE; + else + stats->if_connector_present = 0; + stats->if_counter_discontinuity_time = + adapter->if_counter_discontinuity_time / + (rte_get_tsc_hz() * 100); +} + +static void +igb_read_ether_like_mib(struct rte_eth_dev *dev, + struct e1000_ether_like_mib_stats *stats) +{ + struct rte_eth_dev_data *data = dev->data; + struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private); + + switch (hw->fc.current_mode) { + case e1000_fc_none: + stats->dot3_pause_oper_mode = E1000_DOT3_PAUSE_DISABLED; + break; + case e1000_fc_rx_pause: + stats->dot3_pause_oper_mode = E1000_DOT3_PAUSE_ENABLEDRCV; + break; + case e1000_fc_tx_pause: + stats->dot3_pause_oper_mode = E1000_DOT3_PAUSE_ENABLEDXMIT; + break; + case e1000_fc_full: + stats->dot3_pause_oper_mode = + E1000_DOT3_PAUSE_ENABLEDXMITANDRCV; + break; + default: + stats->dot3_pause_oper_mode = 0; + break; + } + + switch (data->dev_link.link_duplex) { + case ETH_LINK_FULL_DUPLEX: + stats->dot3_stats_duplex_status = E1000_DOT3_DUPLEX_FULLDUPLEX; + break; + case ETH_LINK_HALF_DUPLEX: + stats->dot3_stats_duplex_status = E1000_DOT3_DUPLEX_HALFDUPLEX; + break; + default: + stats->dot3_stats_duplex_status = E1000_DOT3_DUPLEX_UNKNOWN; + break; + } + + stats->dot3_stats_rate_control_ability = E1000_MIB_TRUTH_FALSE; + stats->dot3_stats_rate_control_status = E1000_DOT3_RATE_CONTROL_OFF; + stats->dot3_control_functions_supported = E1000_DOT3_CF_PAUSE; } static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev, @@ -1940,27 +2101,53 @@ eth_igb_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private); struct e1000_hw_stats *hw_stats = E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private); - unsigned i; + struct e1000_if_mib_stats if_mib_stats; + struct e1000_ether_like_mib_stats ether_like_mib_stats; + unsigned int i, count; - if (n < IGB_NB_XSTATS) - return IGB_NB_XSTATS; + count = igb_xstats_calc_num(); + if (n < count) + return count; igb_read_stats_registers(hw, hw_stats); + igb_read_if_mib(dev, &if_mib_stats); + igb_read_ether_like_mib(dev, ðer_like_mib_stats); + /* If this is a reset xstats is NULL, and we have cleared the * registers by reading them. */ if (!xstats) return 0; + count = 0; + /* Extended stats */ for (i = 0; i < IGB_NB_XSTATS; i++) { - xstats[i].id = i; - xstats[i].value = *(uint64_t *)(((char *)hw_stats) + + xstats[count].id = count; + xstats[count].value = *(uint64_t *)(((char *)hw_stats) + rte_igb_stats_strings[i].offset); + count++; + } + + /* Get stats from IF-MIB objects */ + for (i = 0; i < IGB_NB_IF_MIB_XSTATS; i++) { + xstats[count].value = *(uint64_t *)(((char *)&if_mib_stats) + + igb_if_mib_strings[i].offset); + xstats[count].id = count; + count++; } - return IGB_NB_XSTATS; + /* Get stats from Ethernet-like-MIB objects */ + for (i = 0; i < IGB_NB_ETHER_LIKE_MIB_XSTATS; i++) { + xstats[count].value = + *(uint64_t *)(((char *)ðer_like_mib_stats) + + igb_ether_like_mib_strings[i].offset); + xstats[count].id = count; + count++; + } + + return count; } static int @@ -2050,19 +2237,46 @@ igbvf_read_stats_registers(struct e1000_hw *hw, struct e1000_vf_stats *hw_stats) hw_stats->last_gotlbc, hw_stats->gotlbc); } +static unsigned int +igbvf_xstats_calc_num(void) +{ + return IGBVF_NB_XSTATS + IGB_NB_IF_MIB_XSTATS + + IGB_NB_ETHER_LIKE_MIB_XSTATS; +} + static int eth_igbvf_xstats_get_names(__rte_unused struct rte_eth_dev *dev, struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit) { - unsigned i; + unsigned int i, count = 0; - if (xstats_names != NULL) - for (i = 0; i < IGBVF_NB_XSTATS; i++) { - snprintf(xstats_names[i].name, - sizeof(xstats_names[i].name), "%s", - rte_igbvf_stats_strings[i].name); - } - return IGBVF_NB_XSTATS; + if (xstats_names == NULL) + return igbvf_xstats_calc_num(); + + for (i = 0; i < IGBVF_NB_XSTATS; i++) { + snprintf(xstats_names[count].name, + sizeof(xstats_names[count].name), "%s", + rte_igbvf_stats_strings[i].name); + count++; + } + + /* Get stats from IF-MIB objects */ + for (i = 0; i < IGB_NB_IF_MIB_XSTATS; i++) { + snprintf(xstats_names[count].name, + sizeof(xstats_names[count].name), + "%s", igb_if_mib_strings[i].name); + count++; + } + + /* Get stats from Ethernet-like-MIB objects */ + for (i = 0; i < IGB_NB_ETHER_LIKE_MIB_XSTATS; i++) { + snprintf(xstats_names[count].name, + sizeof(xstats_names[count].name), + "%s", igb_ether_like_mib_strings[i].name); + count++; + } + + return count; } static int @@ -2072,23 +2286,49 @@ eth_igbvf_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private); struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *) E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private); - unsigned i; + struct e1000_if_mib_stats if_mib_stats; + struct e1000_ether_like_mib_stats ether_like_mib_stats; + unsigned int i, count; - if (n < IGBVF_NB_XSTATS) - return IGBVF_NB_XSTATS; + count = igbvf_xstats_calc_num(); + if (n < count) + return count; igbvf_read_stats_registers(hw, hw_stats); + igb_read_if_mib(dev, &if_mib_stats); + igb_read_ether_like_mib(dev, ðer_like_mib_stats); + if (!xstats) return 0; + count = 0; + for (i = 0; i < IGBVF_NB_XSTATS; i++) { - xstats[i].id = i; - xstats[i].value = *(uint64_t *)(((char *)hw_stats) + + xstats[count].id = count; + xstats[count].value = *(uint64_t *)(((char *)hw_stats) + rte_igbvf_stats_strings[i].offset); + count++; } - return IGBVF_NB_XSTATS; + /* Get stats from IF-MIB objects */ + for (i = 0; i < IGB_NB_IF_MIB_XSTATS; i++) { + xstats[count].value = *(uint64_t *)(((char *)&if_mib_stats) + + igb_if_mib_strings[i].offset); + xstats[count].id = count; + count++; + } + + /* Get stats from Ethernet-like-MIB objects */ + for (i = 0; i < IGB_NB_ETHER_LIKE_MIB_XSTATS; i++) { + xstats[count].value = + *(uint64_t *)(((char *)ðer_like_mib_stats) + + igb_ether_like_mib_strings[i].offset); + xstats[count].id = count; + count++; + } + + return count; } static void @@ -2114,6 +2354,8 @@ eth_igbvf_stats_reset(struct rte_eth_dev *dev) { struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*) E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private); + struct e1000_adapter *adapter = + E1000_DEV_PRIVATE(dev->data->dev_private); /* Sync HW register to the last stats */ eth_igbvf_stats_get(dev, NULL); @@ -2121,6 +2363,9 @@ eth_igbvf_stats_reset(struct rte_eth_dev *dev) /* reset HW current stats*/ memset(&hw_stats->gprc, 0, sizeof(*hw_stats) - offsetof(struct e1000_vf_stats, gprc)); + + adapter->if_counter_discontinuity_time = + rte_rdtsc() - adapter->sys_up_time_start; } static int @@ -2366,6 +2611,8 @@ eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete) { struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct e1000_adapter *adapter = + E1000_DEV_PRIVATE(dev->data->dev_private); struct rte_eth_link link, old; int link_check, count; @@ -2434,6 +2681,7 @@ eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete) return -1; /* changed */ + adapter->if_last_change = rte_rdtsc() - adapter->sys_up_time_start; return 0; } -- 2.7.5