sfc: add sysfs entry to control MCDI tracing
[linux-drm-fsl-dcu.git] / drivers / net / ethernet / sfc / efx.c
index 9eafa39d0e7fa1125cb844ac00fe9464eb324e64..2d4853c032c396b834c682757f60f111d8656942 100644 (file)
@@ -2326,6 +2326,28 @@ show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
 }
 static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
 
+#ifdef CONFIG_SFC_MCDI_LOGGING
+static ssize_t show_mcdi_log(struct device *dev, struct device_attribute *attr,
+                            char *buf)
+{
+       struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
+       struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
+
+       return scnprintf(buf, PAGE_SIZE, "%d\n", mcdi->logging_enabled);
+}
+static ssize_t set_mcdi_log(struct device *dev, struct device_attribute *attr,
+                           const char *buf, size_t count)
+{
+       struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
+       struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
+       bool enable = count > 0 && *buf != '0';
+
+       mcdi->logging_enabled = enable;
+       return count;
+}
+static DEVICE_ATTR(mcdi_logging, 0644, show_mcdi_log, set_mcdi_log);
+#endif
+
 static int efx_register_netdev(struct efx_nic *efx)
 {
        struct net_device *net_dev = efx->net_dev;
@@ -2383,9 +2405,21 @@ static int efx_register_netdev(struct efx_nic *efx)
                          "failed to init net dev attributes\n");
                goto fail_registered;
        }
+#ifdef CONFIG_SFC_MCDI_LOGGING
+       rc = device_create_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
+       if (rc) {
+               netif_err(efx, drv, efx->net_dev,
+                         "failed to init net dev attributes\n");
+               goto fail_attr_mcdi_logging;
+       }
+#endif
 
        return 0;
 
+#ifdef CONFIG_SFC_MCDI_LOGGING
+fail_attr_mcdi_logging:
+       device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
+#endif
 fail_registered:
        rtnl_lock();
        efx_dissociate(efx);
@@ -2404,13 +2438,14 @@ static void efx_unregister_netdev(struct efx_nic *efx)
 
        BUG_ON(netdev_priv(efx->net_dev) != efx);
 
-       strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
-       device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
-
-       rtnl_lock();
-       unregister_netdevice(efx->net_dev);
-       efx->state = STATE_UNINIT;
-       rtnl_unlock();
+       if (efx_dev_registered(efx)) {
+               strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
+#ifdef CONFIG_SFC_MCDI_LOGGING
+               device_remove_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
+#endif
+               device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
+               unregister_netdev(efx->net_dev);
+       }
 }
 
 /**************************************************************************