The dpio irqs must be registered when you can actually receive interrupts, ie when the dpios are created. Kernel goes through NULL pointer dereference errors followed by kernel panic [1] because the dpio irqs are enabled before the dpio is created. [1] Unable to handle kernel NULL pointer dereference at virtual address 0040 fsl_mc_dpio dpio.14: probed fsl_mc_dpio dpio.13: Adding to iommu group 11 ISV = 0, ISS = 0x00000004 Unable to handle kernel NULL pointer dereference at virtual address 0040 Mem abort info: ESR = 0x96000004 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000004 CM = 0, WnR = 0 [0000000000000040] user address but active_mm is swapper Internal error: Oops: 96000004 [#1] PREEMPT SMP Modules linked in: CPU: 2 PID: 151 Comm: kworker/2:1 Not tainted 5.6.0-rc4-next-20200304 #1 Hardware name: NXP Layerscape LX2160ARDB (DT) Workqueue: events deferred_probe_work_func pstate: 00000085 (nzcv daIf -PAN -UAO) pc : dpaa2_io_irq+0x18/0xe0 lr : dpio_irq_handler+0x1c/0x28 sp : ffff800010013e20 x29: ffff800010013e20 x28: ffff0026d9b4c140 x27: ffffa1d38a142018 x26: ffff0026d2953400 x25: ffffa1d38a142018 x24: ffffa1d38a7ba1d8 x23: ffff800010013f24 x22: 0000000000000000 x21: 0000000000000072 x20: ffff0026d2953400 x19: ffff0026d2a68b80 x18: 0000000000000001 x17: 000000002fb37f3d x16: 0000000035eafadd x15: ffff0026d9b4c5b8 x14: ffffffffffffffff x13: ff00000000000000 x12: 0000000000000038 x11: 0101010101010101 x10: 0000000000000040 x9 : ffffa1d388db11e4 x8 : ffffa1d38a7e40f0 x7 : ffff0026da414f38 x6 : 0000000000000000 x5 : ffff0026da414d80 x4 : ffff5e5353d0c000 x3 : ffff800010013f60 x2 : ffffa1d388db11c8 x1 : ffff0026d2a67c00 x0 : 0000000000000000 Call trace: dpaa2_io_irq+0x18/0xe0 dpio_irq_handler+0x1c/0x28 __handle_irq_event_percpu+0x78/0x2c0 handle_irq_event_percpu+0x38/0x90 handle_irq_event+0x4c/0xd0 handle_fasteoi_irq+0xbc/0x168 generic_handle_irq+0x2c/0x40 __handle_domain_irq+0x68/0xc0 gic_handle_irq+0x64/0x150 el1_irq+0xb8/0x180 _raw_spin_unlock_irqrestore+0x14/0x48 irq_set_affinity_hint+0x6c/0xa0 dpaa2_dpio_probe+0x2a4/0x518 fsl_mc_driver_probe+0x28/0x70 really_probe+0xdc/0x320 driver_probe_device+0x5c/0xf0 __device_attach_driver+0x88/0xc0 bus_for_each_drv+0x7c/0xc8 __device_attach+0xe4/0x140 device_initial_probe+0x18/0x20 bus_probe_device+0x98/0xa0 device_add+0x41c/0x758 fsl_mc_device_add+0x184/0x530 dprc_scan_objects+0x280/0x370 dprc_probe+0x124/0x3b0 fsl_mc_driver_probe+0x28/0x70 really_probe+0xdc/0x320 driver_probe_device+0x5c/0xf0 __device_attach_driver+0x88/0xc0 bus_for_each_drv+0x7c/0xc8 __device_attach+0xe4/0x140 device_initial_probe+0x18/0x20 bus_probe_device+0x98/0xa0 deferred_probe_work_func+0x74/0xa8 process_one_work+0x1c8/0x470 worker_thread+0x1f8/0x428 kthread+0x124/0x128 ret_from_fork+0x10/0x18 Code: a9bc7bfd 910003fd a9025bf5 a90363f7 (f9402015) ---[ end trace 38298e1a29e7a570 ]--- Kernel panic - not syncing: Fatal exception in interrupt SMP: stopping secondary CPUs Mem abort info: ESR = 0x96000004 CM = 0, WnR = 0 EC = 0x25: DABT (current EL), IL = 32 bits [0000000000000040] user address but active_mm is swapper SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000004 CM = 0, WnR = 0 [0000000000000040] user address but active_mm is swapper SMP: failed to stop secondary CPUs 0-2 Kernel Offset: 0x21d378600000 from 0xffff800010000000 PHYS_OFFSET: 0xffffe92180000000 CPU features: 0x10002,21806008 Memory Limit: none ---[ end Kernel panic - not syncing: Fatal exception in interrupt ]--- Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com> Signed-off-by: Grigore Popescu <grigore.popescu@nxp.com> Signed-off-by: Li Yang <leoyang.li@nxp.com>
347 lines
8.1 KiB
C
347 lines
8.1 KiB
C
// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
|
|
/*
|
|
* Copyright 2014-2016 Freescale Semiconductor Inc.
|
|
* Copyright NXP 2016
|
|
*
|
|
*/
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/msi.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/io.h>
|
|
#include <linux/sys_soc.h>
|
|
|
|
#include <linux/fsl/mc.h>
|
|
#include <soc/fsl/dpaa2-io.h>
|
|
|
|
#include "qbman-portal.h"
|
|
#include "dpio.h"
|
|
#include "dpio-cmd.h"
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
MODULE_AUTHOR("Freescale Semiconductor, Inc");
|
|
MODULE_DESCRIPTION("DPIO Driver");
|
|
|
|
struct dpio_priv {
|
|
struct dpaa2_io *io;
|
|
};
|
|
|
|
static cpumask_var_t cpus_unused_mask;
|
|
|
|
static const struct soc_device_attribute ls1088a_soc[] = {
|
|
{.family = "QorIQ LS1088A"},
|
|
{ /* sentinel */ }
|
|
};
|
|
|
|
static const struct soc_device_attribute ls2080a_soc[] = {
|
|
{.family = "QorIQ LS2080A"},
|
|
{ /* sentinel */ }
|
|
};
|
|
|
|
static const struct soc_device_attribute ls2088a_soc[] = {
|
|
{.family = "QorIQ LS2088A"},
|
|
{ /* sentinel */ }
|
|
};
|
|
|
|
static const struct soc_device_attribute lx2160a_soc[] = {
|
|
{.family = "QorIQ LX2160A"},
|
|
{ /* sentinel */ }
|
|
};
|
|
|
|
static int dpaa2_dpio_get_cluster_sdest(struct fsl_mc_device *dpio_dev, int cpu)
|
|
{
|
|
int cluster_base, cluster_size;
|
|
|
|
if (soc_device_match(ls1088a_soc)) {
|
|
cluster_base = 2;
|
|
cluster_size = 4;
|
|
} else if (soc_device_match(ls2080a_soc) ||
|
|
soc_device_match(ls2088a_soc) ||
|
|
soc_device_match(lx2160a_soc)) {
|
|
cluster_base = 0;
|
|
cluster_size = 2;
|
|
} else {
|
|
dev_err(&dpio_dev->dev, "unknown SoC version\n");
|
|
return -1;
|
|
}
|
|
|
|
return cluster_base + cpu / cluster_size;
|
|
}
|
|
|
|
static irqreturn_t dpio_irq_handler(int irq_num, void *arg)
|
|
{
|
|
struct device *dev = (struct device *)arg;
|
|
struct dpio_priv *priv = dev_get_drvdata(dev);
|
|
|
|
return dpaa2_io_irq(priv->io);
|
|
}
|
|
|
|
static void unregister_dpio_irq_handlers(struct fsl_mc_device *dpio_dev)
|
|
{
|
|
struct fsl_mc_device_irq *irq;
|
|
|
|
irq = dpio_dev->irqs[0];
|
|
|
|
/* clear the affinity hint */
|
|
irq_set_affinity_hint(irq->msi_desc->irq, NULL);
|
|
}
|
|
|
|
static int register_dpio_irq_handlers(struct fsl_mc_device *dpio_dev, int cpu)
|
|
{
|
|
int error;
|
|
struct fsl_mc_device_irq *irq;
|
|
cpumask_t mask;
|
|
|
|
irq = dpio_dev->irqs[0];
|
|
error = devm_request_irq(&dpio_dev->dev,
|
|
irq->msi_desc->irq,
|
|
dpio_irq_handler,
|
|
0,
|
|
dev_name(&dpio_dev->dev),
|
|
&dpio_dev->dev);
|
|
if (error < 0) {
|
|
dev_err(&dpio_dev->dev,
|
|
"devm_request_irq() failed: %d\n",
|
|
error);
|
|
return error;
|
|
}
|
|
|
|
/* set the affinity hint */
|
|
cpumask_clear(&mask);
|
|
cpumask_set_cpu(cpu, &mask);
|
|
if (irq_set_affinity_hint(irq->msi_desc->irq, &mask))
|
|
dev_err(&dpio_dev->dev,
|
|
"irq_set_affinity failed irq %d cpu %d\n",
|
|
irq->msi_desc->irq, cpu);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev)
|
|
{
|
|
struct dpio_attr dpio_attrs;
|
|
struct dpaa2_io_desc desc;
|
|
struct dpio_priv *priv;
|
|
int err = -ENOMEM;
|
|
struct device *dev = &dpio_dev->dev;
|
|
int possible_next_cpu;
|
|
int sdest;
|
|
|
|
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
|
if (!priv)
|
|
goto err_priv_alloc;
|
|
|
|
dev_set_drvdata(dev, priv);
|
|
|
|
err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io);
|
|
if (err) {
|
|
dev_dbg(dev, "MC portal allocation failed\n");
|
|
err = -EPROBE_DEFER;
|
|
goto err_priv_alloc;
|
|
}
|
|
|
|
err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id,
|
|
&dpio_dev->mc_handle);
|
|
if (err) {
|
|
dev_err(dev, "dpio_open() failed\n");
|
|
goto err_open;
|
|
}
|
|
|
|
err = dpio_reset(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
|
|
if (err) {
|
|
dev_err(dev, "dpio_reset() failed\n");
|
|
goto err_reset;
|
|
}
|
|
|
|
err = dpio_get_attributes(dpio_dev->mc_io, 0, dpio_dev->mc_handle,
|
|
&dpio_attrs);
|
|
if (err) {
|
|
dev_err(dev, "dpio_get_attributes() failed %d\n", err);
|
|
goto err_get_attr;
|
|
}
|
|
desc.qman_version = dpio_attrs.qbman_version;
|
|
|
|
err = dpio_enable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
|
|
if (err) {
|
|
dev_err(dev, "dpio_enable() failed %d\n", err);
|
|
goto err_get_attr;
|
|
}
|
|
|
|
/* initialize DPIO descriptor */
|
|
desc.receives_notifications = dpio_attrs.num_priorities ? 1 : 0;
|
|
desc.has_8prio = dpio_attrs.num_priorities == 8 ? 1 : 0;
|
|
desc.dpio_id = dpio_dev->obj_desc.id;
|
|
|
|
/* get the cpu to use for the affinity hint */
|
|
possible_next_cpu = cpumask_first(cpus_unused_mask);
|
|
if (possible_next_cpu >= nr_cpu_ids) {
|
|
dev_err(dev, "probe failed. Number of DPIOs exceeds NR_CPUS.\n");
|
|
err = -ERANGE;
|
|
goto err_allocate_irqs;
|
|
}
|
|
desc.cpu = possible_next_cpu;
|
|
cpumask_clear_cpu(possible_next_cpu, cpus_unused_mask);
|
|
|
|
sdest = dpaa2_dpio_get_cluster_sdest(dpio_dev, desc.cpu);
|
|
if (sdest >= 0) {
|
|
err = dpio_set_stashing_destination(dpio_dev->mc_io, 0,
|
|
dpio_dev->mc_handle,
|
|
sdest);
|
|
if (err)
|
|
dev_err(dev, "dpio_set_stashing_destination failed for cpu%d\n",
|
|
desc.cpu);
|
|
}
|
|
|
|
if (dpio_dev->obj_desc.region_count < 3) {
|
|
/* No support for DDR backed portals, use classic mapping */
|
|
/*
|
|
* Set the CENA regs to be the cache inhibited area of the
|
|
* portal to avoid coherency issues if a user migrates to
|
|
* another core.
|
|
*/
|
|
desc.regs_cena = devm_memremap(dev, dpio_dev->regions[1].start,
|
|
resource_size(&dpio_dev->regions[1]),
|
|
MEMREMAP_WC);
|
|
} else {
|
|
desc.regs_cena = devm_memremap(dev, dpio_dev->regions[2].start,
|
|
resource_size(&dpio_dev->regions[2]),
|
|
MEMREMAP_WB);
|
|
}
|
|
|
|
if (IS_ERR(desc.regs_cena)) {
|
|
dev_err(dev, "devm_memremap failed\n");
|
|
err = PTR_ERR(desc.regs_cena);
|
|
goto err_allocate_irqs;
|
|
}
|
|
|
|
desc.regs_cinh = devm_ioremap(dev, dpio_dev->regions[1].start,
|
|
resource_size(&dpio_dev->regions[1]));
|
|
if (!desc.regs_cinh) {
|
|
err = -ENOMEM;
|
|
dev_err(dev, "devm_ioremap failed\n");
|
|
goto err_allocate_irqs;
|
|
}
|
|
|
|
err = fsl_mc_allocate_irqs(dpio_dev);
|
|
if (err) {
|
|
dev_err(dev, "fsl_mc_allocate_irqs failed. err=%d\n", err);
|
|
goto err_allocate_irqs;
|
|
}
|
|
|
|
priv->io = dpaa2_io_create(&desc, dev);
|
|
if (!priv->io) {
|
|
dev_err(dev, "dpaa2_io_create failed\n");
|
|
err = -ENOMEM;
|
|
goto err_dpaa2_io_create;
|
|
}
|
|
|
|
err = register_dpio_irq_handlers(dpio_dev, desc.cpu);
|
|
if (err)
|
|
goto err_register_dpio_irq;
|
|
|
|
dev_info(dev, "probed\n");
|
|
dev_dbg(dev, " receives_notifications = %d\n",
|
|
desc.receives_notifications);
|
|
dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
|
|
|
|
return 0;
|
|
|
|
err_dpaa2_io_create:
|
|
unregister_dpio_irq_handlers(dpio_dev);
|
|
err_register_dpio_irq:
|
|
fsl_mc_free_irqs(dpio_dev);
|
|
err_allocate_irqs:
|
|
dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
|
|
err_get_attr:
|
|
err_reset:
|
|
dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
|
|
err_open:
|
|
fsl_mc_portal_free(dpio_dev->mc_io);
|
|
err_priv_alloc:
|
|
return err;
|
|
}
|
|
|
|
/* Tear down interrupts for a given DPIO object */
|
|
static void dpio_teardown_irqs(struct fsl_mc_device *dpio_dev)
|
|
{
|
|
unregister_dpio_irq_handlers(dpio_dev);
|
|
fsl_mc_free_irqs(dpio_dev);
|
|
}
|
|
|
|
static int dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev)
|
|
{
|
|
struct device *dev;
|
|
struct dpio_priv *priv;
|
|
int err = 0, cpu;
|
|
|
|
dev = &dpio_dev->dev;
|
|
priv = dev_get_drvdata(dev);
|
|
cpu = dpaa2_io_get_cpu(priv->io);
|
|
|
|
dpaa2_io_down(priv->io);
|
|
|
|
dpio_teardown_irqs(dpio_dev);
|
|
|
|
cpumask_set_cpu(cpu, cpus_unused_mask);
|
|
|
|
err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id,
|
|
&dpio_dev->mc_handle);
|
|
if (err) {
|
|
dev_err(dev, "dpio_open() failed\n");
|
|
goto err_open;
|
|
}
|
|
|
|
dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
|
|
|
|
dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
|
|
|
|
fsl_mc_portal_free(dpio_dev->mc_io);
|
|
|
|
return 0;
|
|
|
|
err_open:
|
|
fsl_mc_portal_free(dpio_dev->mc_io);
|
|
|
|
return err;
|
|
}
|
|
|
|
static const struct fsl_mc_device_id dpaa2_dpio_match_id_table[] = {
|
|
{
|
|
.vendor = FSL_MC_VENDOR_FREESCALE,
|
|
.obj_type = "dpio",
|
|
},
|
|
{ .vendor = 0x0 }
|
|
};
|
|
|
|
static struct fsl_mc_driver dpaa2_dpio_driver = {
|
|
.driver = {
|
|
.name = KBUILD_MODNAME,
|
|
.owner = THIS_MODULE,
|
|
},
|
|
.probe = dpaa2_dpio_probe,
|
|
.remove = dpaa2_dpio_remove,
|
|
.match_id_table = dpaa2_dpio_match_id_table
|
|
};
|
|
|
|
static int dpio_driver_init(void)
|
|
{
|
|
if (!zalloc_cpumask_var(&cpus_unused_mask, GFP_KERNEL))
|
|
return -ENOMEM;
|
|
cpumask_copy(cpus_unused_mask, cpu_online_mask);
|
|
|
|
return fsl_mc_driver_register(&dpaa2_dpio_driver);
|
|
}
|
|
|
|
static void dpio_driver_exit(void)
|
|
{
|
|
free_cpumask_var(cpus_unused_mask);
|
|
fsl_mc_driver_unregister(&dpaa2_dpio_driver);
|
|
}
|
|
module_init(dpio_driver_init);
|
|
module_exit(dpio_driver_exit);
|