nfp: add very basic access to NSP logs
authorJakub Kicinski <jakub.kicinski@netronome.com>
Sun, 19 Feb 2017 19:58:12 +0000 (11:58 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 20 Feb 2017 16:18:49 +0000 (11:18 -0500)
Allow dumping "arm.diag" resource with ethtool -w.  This resource
should contain a text log of the NSP (control processor) application.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/nfp_net.h
drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
drivers/net/ethernet/netronome/nfp/nfpcore/nfp.h

index 5a0fc09dd6ea2c6e95a96a2263c4f1f1240d9d7c..e614a376b595280148494e8a1029fb2328057ca4 100644 (file)
@@ -492,6 +492,7 @@ struct nfp_stat_pair {
  * @tx_bar:             Pointer to mapped TX queues
  * @rx_bar:             Pointer to mapped FL/RX queues
  * @debugfs_dir:       Device directory in debugfs
+ * @ethtool_dump_flag: Ethtool dump flag
  * @port_list:         Entry on device port list
  * @cpp:               CPP device handle if available
  */
@@ -579,6 +580,7 @@ struct nfp_net {
        u8 __iomem *rx_bar;
 
        struct dentry *debugfs_dir;
+       u32 ethtool_dump_flag;
 
        struct list_head port_list;
 
index 48f623f685988f474020dd1ddbae1575a80b9b84..2649f7523c81f11ddbb9c0b9bdba78dd220d7c6a 100644 (file)
 #include "nfp_net_ctrl.h"
 #include "nfp_net.h"
 
+enum nfp_dump_diag {
+       NFP_DUMP_NSP_DIAG = 0,
+};
+
 /* Support for stats. Returns netdev, driver, and device stats */
 enum { NETDEV_ET_STATS, NFP_NET_DRV_ET_STATS, NFP_NET_DEV_ET_STATS };
 struct _nfp_net_et_stats {
@@ -579,6 +583,75 @@ static int nfp_net_get_coalesce(struct net_device *netdev,
        return 0;
 }
 
+/* Other debug dumps
+ */
+static int
+nfp_dump_nsp_diag(struct nfp_net *nn, struct ethtool_dump *dump, void *buffer)
+{
+       struct nfp_resource *res;
+       int ret;
+
+       if (!nn->cpp)
+               return -EOPNOTSUPP;
+
+       dump->version = 1;
+       dump->flag = NFP_DUMP_NSP_DIAG;
+
+       res = nfp_resource_acquire(nn->cpp, NFP_RESOURCE_NSP_DIAG);
+       if (IS_ERR(res))
+               return PTR_ERR(res);
+
+       if (buffer) {
+               if (dump->len != nfp_resource_size(res)) {
+                       ret = -EINVAL;
+                       goto exit_release;
+               }
+
+               ret = nfp_cpp_read(nn->cpp, nfp_resource_cpp_id(res),
+                                  nfp_resource_address(res),
+                                  buffer, dump->len);
+               if (ret != dump->len)
+                       ret = ret < 0 ? ret : -EIO;
+               else
+                       ret = 0;
+       } else {
+               dump->len = nfp_resource_size(res);
+               ret = 0;
+       }
+exit_release:
+       nfp_resource_release(res);
+
+       return ret;
+}
+
+static int nfp_net_set_dump(struct net_device *netdev, struct ethtool_dump *val)
+{
+       struct nfp_net *nn = netdev_priv(netdev);
+
+       if (!nn->cpp)
+               return -EOPNOTSUPP;
+
+       if (val->flag != NFP_DUMP_NSP_DIAG)
+               return -EINVAL;
+
+       nn->ethtool_dump_flag = val->flag;
+
+       return 0;
+}
+
+static int
+nfp_net_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
+{
+       return nfp_dump_nsp_diag(netdev_priv(netdev), dump, NULL);
+}
+
+static int
+nfp_net_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
+                     void *buffer)
+{
+       return nfp_dump_nsp_diag(netdev_priv(netdev), dump, buffer);
+}
+
 static int nfp_net_set_coalesce(struct net_device *netdev,
                                struct ethtool_coalesce *ec)
 {
@@ -743,6 +816,9 @@ static const struct ethtool_ops nfp_net_ethtool_ops = {
        .set_rxfh               = nfp_net_set_rxfh,
        .get_regs_len           = nfp_net_get_regs_len,
        .get_regs               = nfp_net_get_regs,
+       .set_dump               = nfp_net_set_dump,
+       .get_dump_flag          = nfp_net_get_dump_flag,
+       .get_dump_data          = nfp_net_get_dump_data,
        .get_coalesce           = nfp_net_get_coalesce,
        .set_coalesce           = nfp_net_set_coalesce,
        .get_channels           = nfp_net_get_channels,
index 540027973a74e9765f2c445b2c903804f0d46490..42cb720b696d17b6dfb580a145237245a8217412 100644 (file)
@@ -86,6 +86,7 @@ int nfp_nsp_write_eth_table(struct nfp_nsp *state,
 
 /* Service Processor */
 #define NFP_RESOURCE_NSP               "nfp.sp"
+#define NFP_RESOURCE_NSP_DIAG          "arm.diag"
 
 /* Netronone Flow Firmware Table */
 #define NFP_RESOURCE_NFP_NFFW          "nfp.nffw"