Enable conditional use of ETHTOOL features in the NIC driver

The retrieval of the NIC speed, duplex, and autonegotiation
capabilities using the ETHTOOL driver extensions is not supported in
every NIC.

Depending on the driver, the use of the ETHTOOL_GSET command may
result in undesirable messages being printed by the kernel. In order
to avoid these kernel messages a compile time switch is added.  By
default the switch disables the use of the ETHTOOL features. Enable
the ETHTOOL feature by adding:
  EXTRA_OECONF_append = " --enable-nic-ethtool=yes"
to the phosphor-network bbappend file.

Tested:
Compiled the source without changing the bbappend file. The code
compiled as is, and after code was added that would cause a compile
time failure.
Loaded the code, and performed a Redfish read of the NIC.  The
SpeedMbps field was confirmed to be set to 0.

Enabled compiling the code by adding the EXTRA_OECONF entry to the
bbappend file. The code compiled as is, and failed to compile after
adding invalid code to the protected blocks.
Loaded the code, and performed a Redfish read of the NIC.  The
SpeedMbps reported the correct link speed.

Change-Id: If03e7d473d439ebb4a01b5d3f45e37ede2a5a84f
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/Makefile.am b/Makefile.am
index 79db184..3bb5e7b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -99,6 +99,10 @@
 		$(PHOSPHOR_LOGGING_CFLAGS) \
 		-flto
 
+if FEATURE_NIC_ETHTOOL
+phosphor_network_manager_CXXFLAGS += -DNIC_SUPPORTS_ETHTOOL
+endif
+
 xyz/openbmc_project/Network/VLAN/Create/server.cpp: xyz/openbmc_project/Network/VLAN/Create.interface.yaml xyz/openbmc_project/Network/VLAN/Create/server.hpp
 	@mkdir -p `dirname $@`
 	$(SDBUSPLUSPLUS) -r $(srcdir) interface server-cpp xyz.openbmc_project.Network.VLAN.Create > $@
diff --git a/configure.ac b/configure.ac
index 8870fcd..12d6caa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -113,6 +113,16 @@
 AC_ARG_VAR(SYSTEMD_TARGET, "Target for starting this service")
 AS_IF([test "x$SYSTEMD_TARGET" == "x"], [SYSTEMD_TARGET="multi-user.target"])
 
+AC_ARG_ENABLE([nic_ethtool],
+    [  --enable-nic-ethtool  Enable/disable the use of ETHTOOL features in the NIC driver],
+    [case "${enableval}" in
+      yes) nic_ethtool=true ;;
+      no) nic_ethtool=false ;;
+      *) AC_MSG_ERROR([bad value ${nic_ethtool} for --enable-nic-ethtool]) ;;
+      esac],[nic_ethtool=false]
+      )
+AM_CONDITIONAL([FEATURE_NIC_ETHTOOL], [test x$nic_ethtool = xtrue])
+
 # Create configured output.
 AC_CONFIG_FILES([Makefile test/Makefile])
 AC_CONFIG_FILES([xyz.openbmc_project.Network.service])
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index c00e4f4..ed1e1ba 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -79,11 +79,13 @@
     }
     EthernetInterfaceIntf::nTPServers(getNTPServersFromConf());
     EthernetInterfaceIntf::nameservers(getNameServerFromConf());
+#if NIC_SUPPORTS_ETHTOOL
     InterfaceInfo ifInfo = EthernetInterface::getInterfaceInfo();
 
     EthernetInterfaceIntf::autoNeg(std::get<2>(ifInfo));
     EthernetInterfaceIntf::speed(std::get<0>(ifInfo));
     EthernetInterfaceIntf::linkUp(std::get<3>(ifInfo));
+#endif
 
     // Emit deferred signal.
     if (emitSignal)
@@ -246,13 +248,13 @@
     return objectPath;
 }
 
+#if NIC_SUPPORTS_ETHTOOL
 /*
-Note: We don't have support for  ethtool now
-will enable this code once we bring the ethtool
-in the image.
-TODO: https://github.com/openbmc/openbmc/issues/1484
+  Enable this code if your NIC driver supports the ETHTOOL features.
+  Do this by adding the following to your phosphor-network*.bbappend file.
+     EXTRA_OECONF_append = " --enable-nic-ethtool=yes"
+  The default compile mode is to omit getInterfaceInfo()
 */
-
 InterfaceInfo EthernetInterface::getInterfaceInfo() const
 {
     ifreq ifr{0};
@@ -283,6 +285,7 @@
 
     return std::make_tuple(speed, duplex, autoneg, linkState);
 }
+#endif
 
 /** @brief get the mac address of the interface.
  *  @return macaddress on success