]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
eth: fbnic: Add ethtool support for fbnic
authorMohsin Bashir <mohsin.bashr@gmail.com>
Mon, 2 Sep 2024 17:39:06 +0000 (10:39 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 4 Sep 2024 12:13:12 +0000 (13:13 +0100)
Add ethtool ops support and enable 'get_drvinfo' for fbnic. The driver
provides firmware version information while the driver name and bus
information is provided by ethtool_get_drvinfo().

Signed-off-by: Mohsin Bashir <mohsin.bashr@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/meta/fbnic/Makefile
drivers/net/ethernet/meta/fbnic/fbnic.h
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c [new file with mode: 0644]
drivers/net/ethernet/meta/fbnic/fbnic_fw.c
drivers/net/ethernet/meta/fbnic/fbnic_fw.h
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c
drivers/net/ethernet/meta/fbnic/fbnic_netdev.h

index 9373b558fdc92718f9910c9c03fa6e6f95394057..37cfc34a5118f7c2d70cc9f9a1275761f6f942cb 100644 (file)
@@ -8,6 +8,7 @@
 obj-$(CONFIG_FBNIC) += fbnic.o
 
 fbnic-y := fbnic_devlink.o \
+          fbnic_ethtool.o \
           fbnic_fw.o \
           fbnic_irq.o \
           fbnic_mac.o \
index ad2689bfd6cb8d67f93a50db05bf191e8bc3aa11..28d970f81bfc9cdc57f1465709aa2245bf69e922 100644 (file)
@@ -132,6 +132,9 @@ void fbnic_free_irq(struct fbnic_dev *dev, int nr, void *data);
 void fbnic_free_irqs(struct fbnic_dev *fbd);
 int fbnic_alloc_irqs(struct fbnic_dev *fbd);
 
+void fbnic_get_fw_ver_commit_str(struct fbnic_dev *fbd, char *fw_version,
+                                const size_t str_sz);
+
 enum fbnic_boards {
        fbnic_board_asic
 };
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c
new file mode 100644 (file)
index 0000000..7064dfc
--- /dev/null
@@ -0,0 +1,26 @@
+#include <linux/ethtool.h>
+#include <linux/netdevice.h>
+#include <linux/pci.h>
+
+#include "fbnic.h"
+#include "fbnic_netdev.h"
+#include "fbnic_tlv.h"
+
+static void
+fbnic_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
+{
+       struct fbnic_net *fbn = netdev_priv(netdev);
+       struct fbnic_dev *fbd = fbn->fbd;
+
+       fbnic_get_fw_ver_commit_str(fbd, drvinfo->fw_version,
+                                   sizeof(drvinfo->fw_version));
+}
+
+static const struct ethtool_ops fbnic_ethtool_ops = {
+       .get_drvinfo            = fbnic_get_drvinfo,
+};
+
+void fbnic_set_ethtool_ops(struct net_device *dev)
+{
+       dev->ethtool_ops = &fbnic_ethtool_ops;
+}
index 0c6e1b4c119b62ca8e46941b4ff1c35c5a894b4f..8f7a2a19ddf8024e70670532dd908159101781b7 100644 (file)
@@ -789,3 +789,16 @@ void fbnic_mbx_flush_tx(struct fbnic_dev *fbd)
                count += (tx_mbx->head - head) % FBNIC_IPC_MBX_DESC_LEN;
        } while (count < FBNIC_IPC_MBX_DESC_LEN && --attempts);
 }
+
+void fbnic_get_fw_ver_commit_str(struct fbnic_dev *fbd, char *fw_version,
+                                const size_t str_sz)
+{
+       struct fbnic_fw_ver *mgmt = &fbd->fw_cap.running.mgmt;
+       const char *delim = "";
+
+       if (mgmt->commit[0])
+               delim = "_";
+
+       fbnic_mk_full_fw_ver_str(mgmt->version, delim, mgmt->commit,
+                                fw_version, str_sz);
+}
index c65bca613665af006b532970a9ed34693b8cd359..221faf8c67566c083ab250d73ef6a5151838842a 100644 (file)
@@ -53,10 +53,10 @@ int fbnic_fw_xmit_ownership_msg(struct fbnic_dev *fbd, bool take_ownership);
 int fbnic_fw_init_heartbeat(struct fbnic_dev *fbd, bool poll);
 void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd);
 
-#define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str)       \
+#define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str, _str_sz) \
 do {                                                                   \
        const u32 __rev_id = _rev_id;                                   \
-       snprintf(_str, sizeof(_str), "%02lu.%02lu.%02lu-%03lu%s%s",     \
+       snprintf(_str, _str_sz, "%02lu.%02lu.%02lu-%03lu%s%s",  \
                 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_MAJOR, __rev_id),  \
                 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_MINOR, __rev_id),  \
                 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_PATCH, __rev_id),  \
@@ -65,7 +65,7 @@ do {                                                                  \
 } while (0)
 
 #define fbnic_mk_fw_ver_str(_rev_id, _str) \
-       fbnic_mk_full_fw_ver_str(_rev_id, "", "", _str)
+       fbnic_mk_full_fw_ver_str(_rev_id, "", "", _str, sizeof(_str))
 
 #define FW_HEARTBEAT_PERIOD            (10 * HZ)
 
index 57137436125991ec5fc3f3d836b729ecc0a735ad..a400616a24d4167dd8843e2e715d458056769877 100644 (file)
@@ -521,6 +521,8 @@ struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd)
        netdev->netdev_ops = &fbnic_netdev_ops;
        netdev->stat_ops = &fbnic_stat_ops;
 
+       fbnic_set_ethtool_ops(netdev);
+
        fbn = netdev_priv(netdev);
 
        fbn->netdev = netdev;
index 60199e634468d885f3dc8ba3bf69803590ffece0..6c27da09a6122b6bad8af9cdd38a09ba41f306a8 100644 (file)
@@ -58,6 +58,7 @@ int fbnic_netdev_register(struct net_device *netdev);
 void fbnic_netdev_unregister(struct net_device *netdev);
 void fbnic_reset_queues(struct fbnic_net *fbn,
                        unsigned int tx, unsigned int rx);
+void fbnic_set_ethtool_ops(struct net_device *dev);
 
 void __fbnic_set_rx_mode(struct net_device *netdev);
 void fbnic_clear_rx_mode(struct net_device *netdev);