1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2017 Broadcom
7 * This driver provides reset support for Broadcom FlexRM ring manager
11 #include <linux/delay.h>
12 #include <linux/device.h>
13 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
18 #include "../vfio_platform_private.h"
20 /* FlexRM configuration */
21 #define RING_REGS_SIZE 0x10000
22 #define RING_VER_MAGIC 0x76303031
24 /* Per-Ring register offsets */
25 #define RING_VER 0x000
26 #define RING_CONTROL 0x034
27 #define RING_FLUSH_DONE 0x038
29 /* Register RING_CONTROL fields */
30 #define CONTROL_FLUSH_SHIFT 5
32 /* Register RING_FLUSH_DONE fields */
33 #define FLUSH_DONE_MASK 0x1
35 static int vfio_platform_bcmflexrm_shutdown(void __iomem *ring)
39 /* Disable/inactivate ring */
40 writel_relaxed(0x0, ring + RING_CONTROL);
42 /* Set ring flush state */
43 timeout = 1000; /* timeout of 1s */
44 writel_relaxed(BIT(CONTROL_FLUSH_SHIFT), ring + RING_CONTROL);
46 if (readl_relaxed(ring + RING_FLUSH_DONE) &
54 /* Clear ring flush state */
55 timeout = 1000; /* timeout of 1s */
56 writel_relaxed(0x0, ring + RING_CONTROL);
58 if (!(readl_relaxed(ring + RING_FLUSH_DONE) &
69 static int vfio_platform_bcmflexrm_reset(struct vfio_platform_device *vdev)
72 int rc = 0, ret = 0, ring_num = 0;
73 struct vfio_platform_region *reg = &vdev->regions[0];
75 /* Map FlexRM ring registers if not mapped */
77 reg->ioaddr = ioremap(reg->addr, reg->size);
82 /* Discover and shutdown each FlexRM ring */
83 for (ring = reg->ioaddr;
84 ring < (reg->ioaddr + reg->size); ring += RING_REGS_SIZE) {
85 if (readl_relaxed(ring + RING_VER) == RING_VER_MAGIC) {
86 rc = vfio_platform_bcmflexrm_shutdown(ring);
88 dev_warn(vdev->device,
89 "FlexRM ring%d shutdown error %d\n",
100 module_vfio_reset_handler("brcm,iproc-flexrm-mbox",
101 vfio_platform_bcmflexrm_reset);
103 MODULE_LICENSE("GPL v2");
104 MODULE_AUTHOR("Anup Patel <anup.patel@broadcom.com>");
105 MODULE_DESCRIPTION("Reset support for Broadcom FlexRM VFIO platform device");