]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
nfp: introduce very minimal nfp_app
authorJakub Kicinski <jakub.kicinski@netronome.com>
Mon, 22 May 2017 17:59:26 +0000 (10:59 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 22 May 2017 18:59:04 +0000 (14:59 -0400)
Introduce a concept of an application.  For now it's just grouping
pointers and serving as a layer of indirection.  It will help us
weaken the dependency on nfp_net in ethtool code.  Later series
will flesh out support for different apps in the driver.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/Makefile
drivers/net/ethernet/netronome/nfp/nfp_app.c [new file with mode: 0644]
drivers/net/ethernet/netronome/nfp/nfp_app.h [new file with mode: 0644]
drivers/net/ethernet/netronome/nfp/nfp_main.h
drivers/net/ethernet/netronome/nfp/nfp_net.h
drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
drivers/net/ethernet/netronome/nfp/nfp_net_main.c

index 4b15f0f496aa7e65385509e774428d57442197b6..a6b9c4dcbe126526808e26918b0e4bae2f177b46 100644 (file)
@@ -14,6 +14,7 @@ nfp-objs := \
            nfpcore/nfp_resource.o \
            nfpcore/nfp_rtsym.o \
            nfpcore/nfp_target.o \
+           nfp_app.o \
            nfp_main.o \
            nfp_net_common.o \
            nfp_net_ethtool.o \
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_app.c b/drivers/net/ethernet/netronome/nfp/nfp_app.c
new file mode 100644 (file)
index 0000000..59be638
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2017 Netronome Systems, Inc.
+ *
+ * This software is dual licensed under the GNU General License Version 2,
+ * June 1991 as shown in the file COPYING in the top-level directory of this
+ * source tree or the BSD 2-Clause License provided below.  You have the
+ * option to license this software under the complete terms of either license.
+ *
+ * The BSD 2-Clause License:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      1. Redistributions of source code must retain the above
+ *         copyright notice, this list of conditions and the following
+ *         disclaimer.
+ *
+ *      2. Redistributions in binary form must reproduce the above
+ *         copyright notice, this list of conditions and the following
+ *         disclaimer in the documentation and/or other materials
+ *         provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <linux/slab.h>
+
+#include "nfp_app.h"
+#include "nfp_main.h"
+
+struct nfp_app *nfp_app_alloc(struct nfp_pf *pf)
+{
+       struct nfp_app *app;
+
+       app = kzalloc(sizeof(*app), GFP_KERNEL);
+       if (!app)
+               return ERR_PTR(-ENOMEM);
+
+       app->pf = pf;
+       app->cpp = pf->cpp;
+       app->pdev = pf->pdev;
+
+       return app;
+}
+
+void nfp_app_free(struct nfp_app *app)
+{
+       kfree(app);
+}
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_app.h b/drivers/net/ethernet/netronome/nfp/nfp_app.h
new file mode 100644 (file)
index 0000000..e63425c
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2017 Netronome Systems, Inc.
+ *
+ * This software is dual licensed under the GNU General License Version 2,
+ * June 1991 as shown in the file COPYING in the top-level directory of this
+ * source tree or the BSD 2-Clause License provided below.  You have the
+ * option to license this software under the complete terms of either license.
+ *
+ * The BSD 2-Clause License:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      1. Redistributions of source code must retain the above
+ *         copyright notice, this list of conditions and the following
+ *         disclaimer.
+ *
+ *      2. Redistributions in binary form must reproduce the above
+ *         copyright notice, this list of conditions and the following
+ *         disclaimer in the documentation and/or other materials
+ *         provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef _NFP_APP_H
+#define _NFP_APP_H 1
+
+struct pci_dev;
+struct nfp_cpp;
+struct nfp_pf;
+
+/**
+ * struct nfp_app - NFP application container
+ * @pdev:      backpointer to PCI device
+ * @pf:                backpointer to NFP PF structure
+ * @cpp:       pointer to the CPP handle
+ */
+struct nfp_app {
+       struct pci_dev *pdev;
+       struct nfp_pf *pf;
+       struct nfp_cpp *cpp;
+};
+
+struct nfp_app *nfp_app_alloc(struct nfp_pf *pf);
+void nfp_app_free(struct nfp_app *app);
+
+#endif
index 1ca1c61450c1ab9b076e63045189e1113d1eaf32..3716ef6b8599e26dc3bb16e4fe783f4728c4c7b1 100644 (file)
@@ -57,6 +57,7 @@ struct nfp_eth_table;
  * struct nfp_pf - NFP PF-specific device structure
  * @pdev:              Backpointer to PCI device
  * @cpp:               Pointer to the CPP handle
+ * @app:               Pointer to the APP handle
  * @data_vnic_bar:     Pointer to the CPP area for the data vNICs' BARs
  * @tx_area:           Pointer to the CPP area for the TX queues
  * @rx_area:           Pointer to the CPP area for the FL/RX queues
@@ -77,6 +78,8 @@ struct nfp_pf {
 
        struct nfp_cpp *cpp;
 
+       struct nfp_app *app;
+
        struct nfp_cpp_area *data_vnic_bar;
        struct nfp_cpp_area *tx_area;
        struct nfp_cpp_area *rx_area;
index 1d41be9b23094562d80d02f7a1a74ac585e95970..d8edd61a5ad1c83598cadcfe69fbb8139815d755 100644 (file)
@@ -557,7 +557,7 @@ struct nfp_net_dp {
  * @ethtool_dump_flag: Ethtool dump flag
  * @vnic_list:         Entry on device vNIC list
  * @pdev:              Backpointer to PCI device
- * @cpp:               CPP device handle if available
+ * @app:               APP handle if available
  * @eth_port:          Translated ETH Table port entry
  */
 struct nfp_net {
@@ -628,7 +628,7 @@ struct nfp_net {
        struct list_head vnic_list;
 
        struct pci_dev *pdev;
-       struct nfp_cpp *cpp;
+       struct nfp_app *app;
 
        struct nfp_eth_table_port *eth_port;
 };
index 70bb0a0152b9add15fb646d408ccca4bbaf41347..b9a70659530d3dafdc30d14cface842ede61e79b 100644 (file)
@@ -50,6 +50,7 @@
 
 #include "nfpcore/nfp.h"
 #include "nfpcore/nfp_nsp.h"
+#include "nfp_app.h"
 #include "nfp_net_ctrl.h"
 #include "nfp_net.h"
 
@@ -134,14 +135,14 @@ static const struct _nfp_net_et_stats nfp_net_et_stats[] = {
 #define NN_ET_STATS_LEN (NN_ET_GLOBAL_STATS_LEN + NN_ET_RVEC_GATHER_STATS + \
                         NN_ET_RVEC_STATS_LEN + NN_ET_QUEUE_STATS_LEN)
 
-static void nfp_net_get_nspinfo(struct nfp_net *nn, char *version)
+static void nfp_net_get_nspinfo(struct nfp_app *app, char *version)
 {
        struct nfp_nsp *nsp;
 
-       if (!nn->cpp)
+       if (!app)
                return;
 
-       nsp = nfp_nsp_open(nn->cpp);
+       nsp = nfp_nsp_open(app->cpp);
        if (IS_ERR(nsp))
                return;
 
@@ -162,7 +163,7 @@ static void nfp_net_get_drvinfo(struct net_device *netdev,
                sizeof(drvinfo->driver));
        strlcpy(drvinfo->version, nfp_driver_version, sizeof(drvinfo->version));
 
-       nfp_net_get_nspinfo(nn, nsp_version);
+       nfp_net_get_nspinfo(nn->app, nsp_version);
        snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
                 "%d.%d.%d.%d %s",
                 nn->fw_ver.resv, nn->fw_ver.class,
@@ -258,7 +259,7 @@ nfp_net_set_link_ksettings(struct net_device *netdev,
                return -EBUSY;
        }
 
-       nsp = nfp_eth_config_start(nn->cpp, nn->eth_port->index);
+       nsp = nfp_eth_config_start(nn->app->cpp, nn->eth_port->index);
        if (IS_ERR(nsp))
                return PTR_ERR(nsp);
 
@@ -706,13 +707,13 @@ nfp_dump_nsp_diag(struct nfp_net *nn, struct ethtool_dump *dump, void *buffer)
        struct nfp_resource *res;
        int ret;
 
-       if (!nn->cpp)
+       if (!nn->app)
                return -EOPNOTSUPP;
 
        dump->version = 1;
        dump->flag = NFP_DUMP_NSP_DIAG;
 
-       res = nfp_resource_acquire(nn->cpp, NFP_RESOURCE_NSP_DIAG);
+       res = nfp_resource_acquire(nn->app->cpp, NFP_RESOURCE_NSP_DIAG);
        if (IS_ERR(res))
                return PTR_ERR(res);
 
@@ -722,7 +723,7 @@ nfp_dump_nsp_diag(struct nfp_net *nn, struct ethtool_dump *dump, void *buffer)
                        goto exit_release;
                }
 
-               ret = nfp_cpp_read(nn->cpp, nfp_resource_cpp_id(res),
+               ret = nfp_cpp_read(nn->app->cpp, nfp_resource_cpp_id(res),
                                   nfp_resource_address(res),
                                   buffer, dump->len);
                if (ret != dump->len)
@@ -743,7 +744,7 @@ static int nfp_net_set_dump(struct net_device *netdev, struct ethtool_dump *val)
 {
        struct nfp_net *nn = netdev_priv(netdev);
 
-       if (!nn->cpp)
+       if (!nn->app)
                return -EOPNOTSUPP;
 
        if (val->flag != NFP_DUMP_NSP_DIAG)
index 5f0c58a561821ba4b5fffa4a3c725af4a8a5e39e..1281e9019e9288809d4883ecc362e9d41f297e3f 100644 (file)
@@ -54,7 +54,7 @@
 #include "nfpcore/nfp_nffw.h"
 #include "nfpcore/nfp_nsp.h"
 #include "nfpcore/nfp6000_pcie.h"
-
+#include "nfp_app.h"
 #include "nfp_net_ctrl.h"
 #include "nfp_net.h"
 #include "nfp_main.h"
@@ -302,7 +302,7 @@ nfp_net_pf_alloc_vnic(struct nfp_pf *pf, void __iomem *ctrl_bar,
        if (IS_ERR(nn))
                return nn;
 
-       nn->cpp = pf->cpp;
+       nn->app = pf->app;
        nn->fw_ver = *fw_ver;
        nn->dp.ctrl_bar = ctrl_bar;
        nn->tx_bar = tx_bar;
@@ -463,6 +463,18 @@ err_nn_free:
        return err;
 }
 
+static int nfp_net_pf_app_init(struct nfp_pf *pf)
+{
+       pf->app = nfp_app_alloc(pf);
+
+       return PTR_ERR_OR_ZERO(pf->app);
+}
+
+static void nfp_net_pf_app_clean(struct nfp_pf *pf)
+{
+       nfp_app_free(pf->app);
+}
+
 static void nfp_net_pci_remove_finish(struct nfp_pf *pf)
 {
        nfp_net_debugfs_dir_clean(&pf->ddir);
@@ -470,6 +482,8 @@ static void nfp_net_pci_remove_finish(struct nfp_pf *pf)
        nfp_net_irqs_disable(pf->pdev);
        kfree(pf->irq_entries);
 
+       nfp_net_pf_app_clean(pf);
+
        nfp_cpp_area_release_free(pf->rx_area);
        nfp_cpp_area_release_free(pf->tx_area);
        nfp_cpp_area_release_free(pf->data_vnic_bar);
@@ -543,7 +557,7 @@ int nfp_net_refresh_eth_port(struct nfp_net *nn)
        struct nfp_eth_table_port *eth_port;
        struct nfp_eth_table *eth_table;
 
-       eth_table = nfp_eth_read_ports(nn->cpp);
+       eth_table = nfp_eth_read_ports(nn->app->cpp);
        if (!eth_table) {
                nn_err(nn, "Error refreshing port state table!\n");
                return -EIO;
@@ -659,6 +673,10 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
                goto err_unmap_tx;
        }
 
+       err = nfp_net_pf_app_init(pf);
+       if (err)
+               goto err_unmap_rx;
+
        pf->ddir = nfp_net_debugfs_device_add(pf->pdev);
 
        err = nfp_net_pf_spawn_vnics(pf, ctrl_bar, tx_bar, rx_bar,
@@ -672,6 +690,8 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
 
 err_clean_ddir:
        nfp_net_debugfs_dir_clean(&pf->ddir);
+       nfp_net_pf_app_clean(pf);
+err_unmap_rx:
        nfp_cpp_area_release_free(pf->rx_area);
 err_unmap_tx:
        nfp_cpp_area_release_free(pf->tx_area);