|
@@ -0,0 +1,97 @@
|
|
|
+// SPDX-License-Identifier: GPL-2.0
|
|
|
+/* Marvell OcteonTx2 CGX driver
|
|
|
+ *
|
|
|
+ * Copyright (C) 2018 Marvell International Ltd.
|
|
|
+ *
|
|
|
+ * This program is free software; you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License version 2 as
|
|
|
+ * published by the Free Software Foundation.
|
|
|
+ */
|
|
|
+
|
|
|
+#include <linux/acpi.h>
|
|
|
+#include <linux/module.h>
|
|
|
+#include <linux/interrupt.h>
|
|
|
+#include <linux/pci.h>
|
|
|
+#include <linux/netdevice.h>
|
|
|
+#include <linux/etherdevice.h>
|
|
|
+#include <linux/phy.h>
|
|
|
+#include <linux/of.h>
|
|
|
+#include <linux/of_mdio.h>
|
|
|
+#include <linux/of_net.h>
|
|
|
+
|
|
|
+#include "cgx.h"
|
|
|
+
|
|
|
+#define DRV_NAME "octeontx2-cgx"
|
|
|
+#define DRV_STRING "Marvell OcteonTX2 CGX/MAC Driver"
|
|
|
+
|
|
|
+struct cgx {
|
|
|
+ void __iomem *reg_base;
|
|
|
+ struct pci_dev *pdev;
|
|
|
+ u8 cgx_id;
|
|
|
+};
|
|
|
+
|
|
|
+/* Supported devices */
|
|
|
+static const struct pci_device_id cgx_id_table[] = {
|
|
|
+ { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_CGX) },
|
|
|
+ { 0, } /* end of table */
|
|
|
+};
|
|
|
+
|
|
|
+MODULE_DEVICE_TABLE(pci, cgx_id_table);
|
|
|
+
|
|
|
+static int cgx_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
|
|
+{
|
|
|
+ struct device *dev = &pdev->dev;
|
|
|
+ struct cgx *cgx;
|
|
|
+ int err;
|
|
|
+
|
|
|
+ cgx = devm_kzalloc(dev, sizeof(*cgx), GFP_KERNEL);
|
|
|
+ if (!cgx)
|
|
|
+ return -ENOMEM;
|
|
|
+ cgx->pdev = pdev;
|
|
|
+
|
|
|
+ pci_set_drvdata(pdev, cgx);
|
|
|
+
|
|
|
+ err = pci_enable_device(pdev);
|
|
|
+ if (err) {
|
|
|
+ dev_err(dev, "Failed to enable PCI device\n");
|
|
|
+ pci_set_drvdata(pdev, NULL);
|
|
|
+ return err;
|
|
|
+ }
|
|
|
+
|
|
|
+ err = pci_request_regions(pdev, DRV_NAME);
|
|
|
+ if (err) {
|
|
|
+ dev_err(dev, "PCI request regions failed 0x%x\n", err);
|
|
|
+ goto err_disable_device;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* MAP configuration registers */
|
|
|
+ cgx->reg_base = pcim_iomap(pdev, PCI_CFG_REG_BAR_NUM, 0);
|
|
|
+ if (!cgx->reg_base) {
|
|
|
+ dev_err(dev, "CGX: Cannot map CSR memory space, aborting\n");
|
|
|
+ err = -ENOMEM;
|
|
|
+ goto err_release_regions;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+
|
|
|
+err_release_regions:
|
|
|
+ pci_release_regions(pdev);
|
|
|
+err_disable_device:
|
|
|
+ pci_disable_device(pdev);
|
|
|
+ pci_set_drvdata(pdev, NULL);
|
|
|
+ return err;
|
|
|
+}
|
|
|
+
|
|
|
+static void cgx_remove(struct pci_dev *pdev)
|
|
|
+{
|
|
|
+ pci_release_regions(pdev);
|
|
|
+ pci_disable_device(pdev);
|
|
|
+ pci_set_drvdata(pdev, NULL);
|
|
|
+}
|
|
|
+
|
|
|
+struct pci_driver cgx_driver = {
|
|
|
+ .name = DRV_NAME,
|
|
|
+ .id_table = cgx_id_table,
|
|
|
+ .probe = cgx_probe,
|
|
|
+ .remove = cgx_remove,
|
|
|
+};
|