Re: [PATCH 6/7] bnxt: Move generic devlink code to new file

2017-10-18 Thread Steve Lin
On Wed, Oct 18, 2017 at 3:33 AM, Jiri Pirko  wrote:
> Tue, Oct 17, 2017 at 10:44:28PM CEST, steven.l...@broadcom.com wrote:
>>Moving generic devlink code (registration) out of VR-R code
>>into new bnxt_devlink file.
>
> You can send this patch separatelly and let it be applied before the
> patchset.

Ok, will do.  Thanks again for all the feedback, Jiri.

Steve


Re: [PATCH 6/7] bnxt: Move generic devlink code to new file

2017-10-18 Thread Jiri Pirko
Tue, Oct 17, 2017 at 10:44:28PM CEST, steven.l...@broadcom.com wrote:
>Moving generic devlink code (registration) out of VR-R code
>into new bnxt_devlink file.

You can send this patch separatelly and let it be applied before the
patchset.


[PATCH 6/7] bnxt: Move generic devlink code to new file

2017-10-17 Thread Steve Lin
Moving generic devlink code (registration) out of VR-R code
into new bnxt_devlink file.

Signed-off-by: Steve Lin 
Acked-by: Andy Gospodarek 
---
 drivers/net/ethernet/broadcom/bnxt/Makefile   |  2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.c |  1 +
 drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 65 +++
 drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h | 39 ++
 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c | 53 ++
 drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.h | 37 ++---
 6 files changed, 112 insertions(+), 85 deletions(-)
 create mode 100644 drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
 create mode 100644 drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h

diff --git a/drivers/net/ethernet/broadcom/bnxt/Makefile 
b/drivers/net/ethernet/broadcom/bnxt/Makefile
index 457201f..59c8ec9 100644
--- a/drivers/net/ethernet/broadcom/bnxt/Makefile
+++ b/drivers/net/ethernet/broadcom/bnxt/Makefile
@@ -1,4 +1,4 @@
 obj-$(CONFIG_BNXT) += bnxt_en.o
 
-bnxt_en-y := bnxt.o bnxt_sriov.o bnxt_ethtool.o bnxt_dcb.o bnxt_ulp.o 
bnxt_xdp.o bnxt_vfr.o
+bnxt_en-y := bnxt.o bnxt_sriov.o bnxt_ethtool.o bnxt_dcb.o bnxt_ulp.o 
bnxt_xdp.o bnxt_vfr.o bnxt_devlink.o
 bnxt_en-$(CONFIG_BNXT_FLOWER_OFFLOAD) += bnxt_tc.o
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c 
b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 5ba4993..52cc38d 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -61,6 +61,7 @@
 #include "bnxt_xdp.h"
 #include "bnxt_vfr.h"
 #include "bnxt_tc.h"
+#include "bnxt_devlink.h"
 
 #define BNXT_TX_TIMEOUT(5 * HZ)
 
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c 
b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
new file mode 100644
index 000..f3f6aa8
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
@@ -0,0 +1,65 @@
+/* Broadcom NetXtreme-C/E network driver.
+ *
+ * Copyright (c) 2017 Broadcom Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include "bnxt_hsi.h"
+#include "bnxt.h"
+#include "bnxt_vfr.h"
+#include "bnxt_devlink.h"
+
+static const struct devlink_ops bnxt_dl_ops = {
+#ifdef CONFIG_BNXT_SRIOV
+   .eswitch_mode_set = bnxt_dl_eswitch_mode_set,
+   .eswitch_mode_get = bnxt_dl_eswitch_mode_get,
+#endif /* CONFIG_BNXT_SRIOV */
+};
+
+int bnxt_dl_register(struct bnxt *bp)
+{
+   struct devlink *dl;
+   int rc;
+
+   if (!pci_find_ext_capability(bp->pdev, PCI_EXT_CAP_ID_SRIOV))
+   return 0;
+
+   if (bp->hwrm_spec_code < 0x10800) {
+   netdev_warn(bp->dev, "Firmware does not support SR-IOV E-Switch 
SWITCHDEV mode.\n");
+   return -ENOTSUPP;
+   }
+
+   dl = devlink_alloc(_dl_ops, sizeof(struct bnxt_dl));
+   if (!dl) {
+   netdev_warn(bp->dev, "devlink_alloc failed");
+   return -ENOMEM;
+   }
+
+   bnxt_link_bp_to_dl(bp, dl);
+   bp->eswitch_mode = DEVLINK_ESWITCH_MODE_LEGACY;
+   rc = devlink_register(dl, >pdev->dev);
+   if (rc) {
+   bnxt_link_bp_to_dl(bp, NULL);
+   devlink_free(dl);
+   netdev_warn(bp->dev, "devlink_register failed. rc=%d", rc);
+   return rc;
+   }
+
+   return 0;
+}
+
+void bnxt_dl_unregister(struct bnxt *bp)
+{
+   struct devlink *dl = bp->dl;
+
+   if (!dl)
+   return;
+
+   devlink_unregister(dl);
+   devlink_free(dl);
+}
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h 
b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h
new file mode 100644
index 000..e92a35d
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h
@@ -0,0 +1,39 @@
+/* Broadcom NetXtreme-C/E network driver.
+ *
+ * Copyright (c) 2017 Broadcom Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation.
+ */
+
+#ifndef BNXT_DEVLINK_H
+#define BNXT_DEVLINK_H
+
+/* Struct to hold housekeeping info needed by devlink interface */
+struct bnxt_dl {
+   struct bnxt *bp;/* back ptr to the controlling dev */
+};
+
+static inline struct bnxt *bnxt_get_bp_from_dl(struct devlink *dl)
+{
+   return ((struct bnxt_dl *)devlink_priv(dl))->bp;
+}
+
+/* To clear devlink pointer from bp, pass NULL dl */
+static inline void bnxt_link_bp_to_dl(struct bnxt *bp, struct devlink *dl)
+{
+   bp->dl = dl;
+
+   /* add a back pointer in dl to bp */
+   if (dl) {
+   struct bnxt_dl *bp_dl = devlink_priv(dl);
+
+   bp_dl->bp = bp;
+   }
+}
+
+int bnxt_dl_register(struct bnxt *bp);
+void bnxt_dl_unregister(struct bnxt *bp);