]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
nfp: abm: create project-specific vNIC structure
authorJakub Kicinski <jakub.kicinski@netronome.com>
Tue, 22 May 2018 05:12:48 +0000 (22:12 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 23 May 2018 18:26:18 +0000 (14:26 -0400)
ABM NIC requires more complex vNIC handling, allocate
per-vNIC structure.  Find out RX queue base and PCI PF id.
There will be multiple PFs sharing the same MAC port, therefore
the MAC address assigned to the vNIC must be looked up in the
HWInfo database.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/Makefile
drivers/net/ethernet/netronome/nfp/abm/ctrl.c [new file with mode: 0644]
drivers/net/ethernet/netronome/nfp/abm/main.c
drivers/net/ethernet/netronome/nfp/abm/main.h
drivers/net/ethernet/netronome/nfp/nfp_app.h
drivers/net/ethernet/netronome/nfp/nfp_app_nic.c

index 3d79b709d77ace4849b7a066d9801bef1d15d917..6373f56205fdafe86c3ad82093dea0a9ea97e803 100644 (file)
@@ -55,6 +55,7 @@ endif
 
 ifeq ($(CONFIG_NFP_APP_ABM_NIC),y)
 nfp-objs += \
+           abm/ctrl.o \
            abm/main.o
 endif
 
diff --git a/drivers/net/ethernet/netronome/nfp/abm/ctrl.c b/drivers/net/ethernet/netronome/nfp/abm/ctrl.c
new file mode 100644 (file)
index 0000000..e40f6f0
--- /dev/null
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+/*
+ * Copyright (C) 2018 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/kernel.h>
+
+#include "../nfpcore/nfp_cpp.h"
+#include "../nfp_app.h"
+#include "../nfp_main.h"
+#include "../nfp_net.h"
+#include "main.h"
+
+void nfp_abm_ctrl_read_params(struct nfp_abm_link *alink)
+{
+       alink->queue_base = nn_readl(alink->vnic, NFP_NET_CFG_START_RXQ);
+       alink->queue_base /= alink->vnic->stride_rx;
+}
+
+int nfp_abm_ctrl_find_addrs(struct nfp_abm *abm)
+{
+       struct nfp_pf *pf = abm->app->pf;
+       unsigned int pf_id;
+
+       pf_id = nfp_cppcore_pcie_unit(pf->cpp);
+       abm->pf_id = pf_id;
+
+       return 0;
+}
index 7a0a807bea4a5403e59c29476cf53f600001d060..1985e58ab0db0a0a1c9a67b6663cfc2554e99bd9 100644 (file)
  * SOFTWARE.
  */
 
+#include <linux/etherdevice.h>
+
+#include "../nfpcore/nfp.h"
 #include "../nfpcore/nfp_cpp.h"
 #include "../nfpcore/nfp_nsp.h"
 #include "../nfp_app.h"
 #include "../nfp_main.h"
+#include "../nfp_net.h"
+#include "../nfp_port.h"
 #include "main.h"
 
+static void
+nfp_abm_vnic_set_mac(struct nfp_pf *pf, struct nfp_abm *abm, struct nfp_net *nn,
+                    unsigned int id)
+{
+       struct nfp_eth_table_port *eth_port = &pf->eth_tbl->ports[id];
+       u8 mac_addr[ETH_ALEN];
+       const char *mac_str;
+       char name[32];
+
+       if (id > pf->eth_tbl->count) {
+               nfp_warn(pf->cpp, "No entry for persistent MAC address\n");
+               eth_hw_addr_random(nn->dp.netdev);
+               return;
+       }
+
+       snprintf(name, sizeof(name), "eth%u.mac.pf%u",
+                eth_port->eth_index, abm->pf_id);
+
+       mac_str = nfp_hwinfo_lookup(pf->hwinfo, name);
+       if (!mac_str) {
+               nfp_warn(pf->cpp, "Can't lookup persistent MAC address (%s)\n",
+                        name);
+               eth_hw_addr_random(nn->dp.netdev);
+               return;
+       }
+
+       if (sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
+                  &mac_addr[0], &mac_addr[1], &mac_addr[2],
+                  &mac_addr[3], &mac_addr[4], &mac_addr[5]) != 6) {
+               nfp_warn(pf->cpp, "Can't parse persistent MAC address (%s)\n",
+                        mac_str);
+               eth_hw_addr_random(nn->dp.netdev);
+               return;
+       }
+
+       ether_addr_copy(nn->dp.netdev->dev_addr, mac_addr);
+       ether_addr_copy(nn->dp.netdev->perm_addr, mac_addr);
+}
+
+static int
+nfp_abm_vnic_alloc(struct nfp_app *app, struct nfp_net *nn, unsigned int id)
+{
+       struct nfp_abm *abm = app->priv;
+       struct nfp_abm_link *alink;
+       int err;
+
+       alink = kzalloc(sizeof(*alink), GFP_KERNEL);
+       if (!alink)
+               return -ENOMEM;
+       nn->app_priv = alink;
+       alink->abm = abm;
+       alink->vnic = nn;
+       alink->id = id;
+
+       nn->port = nfp_port_alloc(app, NFP_PORT_PHYS_PORT, nn->dp.netdev);
+       if (IS_ERR(nn->port)) {
+               err = PTR_ERR(nn->port);
+               goto err_free_alink;
+       }
+
+       err = nfp_app_nic_vnic_init_phy_port(app->pf, app, nn, id);
+       if (err < 0)
+               goto err_free_port;
+       if (nn->port->type == NFP_PORT_INVALID)
+               /* core will kill this vNIC */
+               return 0;
+
+       nfp_abm_vnic_set_mac(app->pf, abm, nn, id);
+       nfp_abm_ctrl_read_params(alink);
+
+       return 0;
+
+err_free_port:
+       nfp_port_free(nn->port);
+err_free_alink:
+       kfree(alink);
+       return err;
+}
+
+static void nfp_abm_vnic_free(struct nfp_app *app, struct nfp_net *nn)
+{
+       struct nfp_abm_link *alink = nn->app_priv;
+
+       kfree(alink);
+}
+
 static int nfp_abm_init(struct nfp_app *app)
 {
        struct nfp_pf *pf = app->pf;
        struct nfp_abm *abm;
+       int err;
 
        if (!pf->eth_tbl) {
                nfp_err(pf->cpp, "ABM NIC requires ETH table\n");
@@ -63,7 +155,16 @@ static int nfp_abm_init(struct nfp_app *app)
        app->priv = abm;
        abm->app = app;
 
+       err = nfp_abm_ctrl_find_addrs(abm);
+       if (err)
+               goto err_free_abm;
+
        return 0;
+
+err_free_abm:
+       kfree(abm);
+       app->priv = NULL;
+       return err;
 }
 
 static void nfp_abm_clean(struct nfp_app *app)
@@ -81,5 +182,6 @@ const struct nfp_app_type app_abm = {
        .init           = nfp_abm_init,
        .clean          = nfp_abm_clean,
 
-       .vnic_alloc     = nfp_app_nic_vnic_alloc,
+       .vnic_alloc     = nfp_abm_vnic_alloc,
+       .vnic_free      = nfp_abm_vnic_free,
 };
index e54b6f64ee10eeff0d7a2249e9cd18f87912046c..3c5a01c96ecd6afeac1c803b956e4a7c7a779256 100644 (file)
 #define __NFP_ABM_H__ 1
 
 struct nfp_app;
+struct nfp_net;
 
 /**
  * struct nfp_abm - ABM NIC app structure
  * @app:       back pointer to nfp_app
+ * @pf_id:     ID of our PF link
  */
 struct nfp_abm {
        struct nfp_app *app;
+       unsigned int pf_id;
 };
+
+/**
+ * struct nfp_abm_link - port tuple of a ABM NIC
+ * @abm:       back pointer to nfp_abm
+ * @vnic:      data vNIC
+ * @id:                id of the data vNIC
+ * @queue_base:        id of base to host queue within PCIe (not QC idx)
+ */
+struct nfp_abm_link {
+       struct nfp_abm *abm;
+       struct nfp_net *vnic;
+       unsigned int id;
+       unsigned int queue_base;
+};
+
+void nfp_abm_ctrl_read_params(struct nfp_abm_link *alink);
+int nfp_abm_ctrl_find_addrs(struct nfp_abm *abm);
 #endif
index 654cabd95ee4aa20128e7e74a0f2e02e702eec9c..fdf2593ae1517a43508066ce923b3945099f09cd 100644 (file)
@@ -412,5 +412,7 @@ void nfp_app_free(struct nfp_app *app);
 
 int nfp_app_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
                           unsigned int id);
+int nfp_app_nic_vnic_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
+                                  struct nfp_net *nn, unsigned int id);
 
 #endif
index b9618c37403f9abe70c2835b338e8ddc7a6a500c..e2dfe4f168bba36d816ba6ab0b537ea9edb2affa 100644 (file)
@@ -38,9 +38,8 @@
 #include "nfp_net.h"
 #include "nfp_port.h"
 
-static int
-nfp_app_nic_vnic_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
-                              struct nfp_net *nn, unsigned int id)
+int nfp_app_nic_vnic_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
+                                  struct nfp_net *nn, unsigned int id)
 {
        int err;