Skip to content

Commit 54494aa

Browse files
sgoutham-marvelldavem330
authored andcommitted
octeontx2-af: Add Marvell OcteonTX2 RVU AF driver
This patch adds basic template for Marvell OcteonTX2's resource virtualization unit (RVU) admin function (AF) driver. Just the driver registration and probe. Signed-off-by: Sunil Goutham <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e40a826 commit 54494aa

File tree

7 files changed

+188
-0
lines changed

7 files changed

+188
-0
lines changed

drivers/net/ethernet/marvell/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,7 @@ config SKY2_DEBUG
167167

168168
If unsure, say N.
169169

170+
171+
source "drivers/net/ethernet/marvell/octeontx2/Kconfig"
172+
170173
endif # NET_VENDOR_MARVELL

drivers/net/ethernet/marvell/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ obj-$(CONFIG_MVPP2) += mvpp2/
1111
obj-$(CONFIG_PXA168_ETH) += pxa168_eth.o
1212
obj-$(CONFIG_SKGE) += skge.o
1313
obj-$(CONFIG_SKY2) += sky2.o
14+
obj-y += octeontx2/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Marvell OcteonTX2 drivers configuration
3+
#
4+
5+
config OCTEONTX2_AF
6+
tristate "Marvell OcteonTX2 RVU Admin Function driver"
7+
depends on (64BIT && COMPILE_TEST) || ARM64
8+
depends on PCI
9+
help
10+
This driver supports Marvell's OcteonTX2 Resource Virtualization
11+
Unit's admin function manager which manages all RVU HW resources
12+
and provides a medium to other PF/VFs to configure HW. Should be
13+
enabled for other RVU device drivers to work.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# Makefile for Marvell OcteonTX2 device drivers.
4+
#
5+
6+
obj-$(CONFIG_OCTEONTX2_AF) += af/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# Makefile for Marvell's OcteonTX2 RVU Admin Function driver
4+
#
5+
6+
obj-$(CONFIG_OCTEONTX2_AF) += octeontx2_af.o
7+
8+
octeontx2_af-y := rvu.o
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Marvell OcteonTx2 RVU Admin Function driver
3+
*
4+
* Copyright (C) 2018 Marvell International Ltd.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*/
10+
11+
#include <linux/module.h>
12+
#include <linux/interrupt.h>
13+
#include <linux/delay.h>
14+
#include <linux/irq.h>
15+
#include <linux/pci.h>
16+
#include <linux/sysfs.h>
17+
18+
#include "rvu.h"
19+
20+
#define DRV_NAME "octeontx2-af"
21+
#define DRV_STRING "Marvell OcteonTX2 RVU Admin Function Driver"
22+
#define DRV_VERSION "1.0"
23+
24+
/* Supported devices */
25+
static const struct pci_device_id rvu_id_table[] = {
26+
{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_RVU_AF) },
27+
{ 0, } /* end of table */
28+
};
29+
30+
MODULE_AUTHOR("Marvell International Ltd.");
31+
MODULE_DESCRIPTION(DRV_STRING);
32+
MODULE_LICENSE("GPL v2");
33+
MODULE_VERSION(DRV_VERSION);
34+
MODULE_DEVICE_TABLE(pci, rvu_id_table);
35+
36+
static int rvu_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37+
{
38+
struct device *dev = &pdev->dev;
39+
struct rvu *rvu;
40+
int err;
41+
42+
rvu = devm_kzalloc(dev, sizeof(*rvu), GFP_KERNEL);
43+
if (!rvu)
44+
return -ENOMEM;
45+
46+
pci_set_drvdata(pdev, rvu);
47+
rvu->pdev = pdev;
48+
rvu->dev = &pdev->dev;
49+
50+
err = pci_enable_device(pdev);
51+
if (err) {
52+
dev_err(dev, "Failed to enable PCI device\n");
53+
goto err_freemem;
54+
}
55+
56+
err = pci_request_regions(pdev, DRV_NAME);
57+
if (err) {
58+
dev_err(dev, "PCI request regions failed 0x%x\n", err);
59+
goto err_disable_device;
60+
}
61+
62+
err = pci_set_dma_mask(pdev, DMA_BIT_MASK(48));
63+
if (err) {
64+
dev_err(dev, "Unable to set DMA mask\n");
65+
goto err_release_regions;
66+
}
67+
68+
err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(48));
69+
if (err) {
70+
dev_err(dev, "Unable to set consistent DMA mask\n");
71+
goto err_release_regions;
72+
}
73+
74+
/* Map Admin function CSRs */
75+
rvu->afreg_base = pcim_iomap(pdev, PCI_AF_REG_BAR_NUM, 0);
76+
rvu->pfreg_base = pcim_iomap(pdev, PCI_PF_REG_BAR_NUM, 0);
77+
if (!rvu->afreg_base || !rvu->pfreg_base) {
78+
dev_err(dev, "Unable to map admin function CSRs, aborting\n");
79+
err = -ENOMEM;
80+
goto err_release_regions;
81+
}
82+
83+
return 0;
84+
85+
err_release_regions:
86+
pci_release_regions(pdev);
87+
err_disable_device:
88+
pci_disable_device(pdev);
89+
err_freemem:
90+
pci_set_drvdata(pdev, NULL);
91+
devm_kfree(dev, rvu);
92+
return err;
93+
}
94+
95+
static void rvu_remove(struct pci_dev *pdev)
96+
{
97+
struct rvu *rvu = pci_get_drvdata(pdev);
98+
99+
pci_release_regions(pdev);
100+
pci_disable_device(pdev);
101+
pci_set_drvdata(pdev, NULL);
102+
103+
devm_kfree(&pdev->dev, rvu);
104+
}
105+
106+
static struct pci_driver rvu_driver = {
107+
.name = DRV_NAME,
108+
.id_table = rvu_id_table,
109+
.probe = rvu_probe,
110+
.remove = rvu_remove,
111+
};
112+
113+
static int __init rvu_init_module(void)
114+
{
115+
pr_info("%s: %s\n", DRV_NAME, DRV_STRING);
116+
117+
return pci_register_driver(&rvu_driver);
118+
}
119+
120+
static void __exit rvu_cleanup_module(void)
121+
{
122+
pci_unregister_driver(&rvu_driver);
123+
}
124+
125+
module_init(rvu_init_module);
126+
module_exit(rvu_cleanup_module);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* SPDX-License-Identifier: GPL-2.0
2+
* Marvell OcteonTx2 RVU Admin Function driver
3+
*
4+
* Copyright (C) 2018 Marvell International Ltd.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*/
10+
11+
#ifndef RVU_H
12+
#define RVU_H
13+
14+
/* PCI device IDs */
15+
#define PCI_DEVID_OCTEONTX2_RVU_AF 0xA065
16+
17+
/* PCI BAR nos */
18+
#define PCI_AF_REG_BAR_NUM 0
19+
#define PCI_PF_REG_BAR_NUM 2
20+
#define PCI_MBOX_BAR_NUM 4
21+
22+
#define NAME_SIZE 32
23+
24+
struct rvu {
25+
void __iomem *afreg_base;
26+
void __iomem *pfreg_base;
27+
struct pci_dev *pdev;
28+
struct device *dev;
29+
};
30+
31+
#endif /* RVU_H */

0 commit comments

Comments
 (0)