^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Freescale data path resource container (DPRC) driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2019-2020 NXP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: German Rivera <German.Rivera@freescale.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/msi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/fsl/mc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "fsl-mc-private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct fsl_mc_child_objs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int child_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct fsl_mc_obj_desc *child_array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static bool fsl_mc_device_match(struct fsl_mc_device *mc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct fsl_mc_obj_desc *obj_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return mc_dev->obj_desc.id == obj_desc->id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) strcmp(mc_dev->obj_desc.type, obj_desc->type) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static bool fsl_mc_obj_desc_is_allocatable(struct fsl_mc_obj_desc *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (strcmp(obj->type, "dpmcp") == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) strcmp(obj->type, "dpcon") == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) strcmp(obj->type, "dpbp") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int __fsl_mc_device_remove_if_not_in_mc(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct fsl_mc_child_objs *objs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct fsl_mc_device *mc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) objs = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) for (i = 0; i < objs->child_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct fsl_mc_obj_desc *obj_desc = &objs->child_array[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (strlen(obj_desc->type) != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) fsl_mc_device_match(mc_dev, obj_desc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (i == objs->child_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) fsl_mc_device_remove(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static int __fsl_mc_device_remove(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) fsl_mc_device_remove(to_fsl_mc_device(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * dprc_remove_devices - Removes devices for objects removed from a DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * @obj_desc_array: array of object descriptors for child objects currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * present in the DPRC in the MC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * @num_child_objects_in_mc: number of entries in obj_desc_array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * Synchronizes the state of the Linux bus driver with the actual state of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * the MC by removing devices that represent MC objects that have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * been dynamically removed in the physical DPRC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) void dprc_remove_devices(struct fsl_mc_device *mc_bus_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct fsl_mc_obj_desc *obj_desc_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int num_child_objects_in_mc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (num_child_objects_in_mc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * Remove child objects that are in the DPRC in Linux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * but not in the MC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct fsl_mc_child_objs objs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) objs.child_count = num_child_objects_in_mc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) objs.child_array = obj_desc_array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) device_for_each_child(&mc_bus_dev->dev, &objs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) __fsl_mc_device_remove_if_not_in_mc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * There are no child objects for this DPRC in the MC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * So, remove all the child devices from Linux:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) device_for_each_child(&mc_bus_dev->dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) __fsl_mc_device_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) EXPORT_SYMBOL_GPL(dprc_remove_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static int __fsl_mc_device_match(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct fsl_mc_obj_desc *obj_desc = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return fsl_mc_device_match(mc_dev, obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct fsl_mc_device *fsl_mc_device_lookup(struct fsl_mc_obj_desc *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct fsl_mc_device *mc_bus_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) dev = device_find_child(&mc_bus_dev->dev, obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) __fsl_mc_device_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return dev ? to_fsl_mc_device(dev) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * check_plugged_state_change - Check change in an MC object's plugged state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * @mc_dev: pointer to the fsl-mc device for a given MC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * @obj_desc: pointer to the MC object's descriptor in the MC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * If the plugged state has changed from unplugged to plugged, the fsl-mc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * device is bound to the corresponding device driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * If the plugged state has changed from plugged to unplugged, the fsl-mc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * device is unbound from the corresponding device driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static void check_plugged_state_change(struct fsl_mc_device *mc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct fsl_mc_obj_desc *obj_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) u32 plugged_flag_at_mc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) obj_desc->state & FSL_MC_OBJ_STATE_PLUGGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (plugged_flag_at_mc !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) (mc_dev->obj_desc.state & FSL_MC_OBJ_STATE_PLUGGED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (plugged_flag_at_mc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) mc_dev->obj_desc.state |= FSL_MC_OBJ_STATE_PLUGGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) error = device_attach(&mc_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) dev_err(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) "device_attach() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) mc_dev->obj_desc.state &= ~FSL_MC_OBJ_STATE_PLUGGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) device_release_driver(&mc_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static void fsl_mc_obj_device_add(struct fsl_mc_device *mc_bus_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct fsl_mc_obj_desc *obj_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct fsl_mc_device *child_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * Check if device is already known to Linux:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) child_dev = fsl_mc_device_lookup(obj_desc, mc_bus_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (child_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) check_plugged_state_change(child_dev, obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) put_device(&child_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) error = fsl_mc_device_add(obj_desc, NULL, &mc_bus_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) &child_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * dprc_add_new_devices - Adds devices to the logical bus for a DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * @obj_desc_array: array of device descriptors for child devices currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * present in the physical DPRC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * @num_child_objects_in_mc: number of entries in obj_desc_array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * Synchronizes the state of the Linux bus driver with the actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * state of the MC by adding objects that have been newly discovered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * in the physical DPRC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct fsl_mc_obj_desc *obj_desc_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) int num_child_objects_in_mc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /* probe the allocable objects first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) for (i = 0; i < num_child_objects_in_mc; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct fsl_mc_obj_desc *obj_desc = &obj_desc_array[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (strlen(obj_desc->type) > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) fsl_mc_obj_desc_is_allocatable(obj_desc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) fsl_mc_obj_device_add(mc_bus_dev, obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) for (i = 0; i < num_child_objects_in_mc; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct fsl_mc_obj_desc *obj_desc = &obj_desc_array[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (strlen(obj_desc->type) > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) !fsl_mc_obj_desc_is_allocatable(obj_desc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) fsl_mc_obj_device_add(mc_bus_dev, obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * dprc_scan_objects - Discover objects in a DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * @alloc_interrupts: if true the function allocates the interrupt pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * otherwise the interrupt allocation is delayed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * Detects objects added and removed from a DPRC and synchronizes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * state of the Linux bus driver, MC by adding and removing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * devices accordingly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * Two types of devices can be found in a DPRC: allocatable objects (e.g.,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * dpbp, dpmcp) and non-allocatable devices (e.g., dprc, dpni).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * All allocatable devices needed to be probed before all non-allocatable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * devices, to ensure that device drivers for non-allocatable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * devices can allocate any type of allocatable devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * That is, we need to ensure that the corresponding resource pools are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * populated before they can get allocation requests from probe callbacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * of the device drivers for the non-allocatable devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) bool alloc_interrupts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int num_child_objects;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int dprc_get_obj_failures;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) unsigned int irq_count = mc_bus_dev->obj_desc.irq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct fsl_mc_obj_desc *child_obj_desc_array = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) error = dprc_get_obj_count(mc_bus_dev->mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) mc_bus_dev->mc_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) &num_child_objects);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) dev_err(&mc_bus_dev->dev, "dprc_get_obj_count() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (num_child_objects != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) child_obj_desc_array =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) devm_kmalloc_array(&mc_bus_dev->dev, num_child_objects,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) sizeof(*child_obj_desc_array),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (!child_obj_desc_array)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * Discover objects currently present in the physical DPRC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) dprc_get_obj_failures = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) for (i = 0; i < num_child_objects; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct fsl_mc_obj_desc *obj_desc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) &child_obj_desc_array[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) error = dprc_get_obj(mc_bus_dev->mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) mc_bus_dev->mc_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) i, obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) dev_err(&mc_bus_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) "dprc_get_obj(i=%d) failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) i, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * Mark the obj entry as "invalid", by using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * empty string as obj type:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) obj_desc->type[0] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) obj_desc->id = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) dprc_get_obj_failures++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * add a quirk for all versions of dpsec < 4.0...none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * are coherent regardless of what the MC reports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if ((strcmp(obj_desc->type, "dpseci") == 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) (obj_desc->ver_major < 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) obj_desc->flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) FSL_MC_OBJ_FLAG_NO_MEM_SHAREABILITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) irq_count += obj_desc->irq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) dev_dbg(&mc_bus_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) "Discovered object: type %s, id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) obj_desc->type, obj_desc->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (dprc_get_obj_failures != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) dev_err(&mc_bus_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) "%d out of %d devices could not be retrieved\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) dprc_get_obj_failures, num_child_objects);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * Allocate IRQ's before binding the scanned devices with their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * respective drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (dev_get_msi_domain(&mc_bus_dev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) dev_warn(&mc_bus_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) "IRQs needed (%u) exceed IRQs preallocated (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (alloc_interrupts && !mc_bus->irq_resources) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) error = fsl_mc_populate_irq_pool(mc_bus_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) dprc_remove_devices(mc_bus_dev, child_obj_desc_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) num_child_objects);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) dprc_add_new_devices(mc_bus_dev, child_obj_desc_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) num_child_objects);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (child_obj_desc_array)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) devm_kfree(&mc_bus_dev->dev, child_obj_desc_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * dprc_scan_container - Scans a physical DPRC and synchronizes Linux bus state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * Scans the physical DPRC and synchronizes the state of the Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * bus driver with the actual state of the MC by adding and removing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * devices as appropriate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) int dprc_scan_container(struct fsl_mc_device *mc_bus_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) bool alloc_interrupts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) fsl_mc_init_all_resource_pools(mc_bus_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * Discover objects in the DPRC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) mutex_lock(&mc_bus->scan_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) error = dprc_scan_objects(mc_bus_dev, alloc_interrupts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) mutex_unlock(&mc_bus->scan_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) EXPORT_SYMBOL_GPL(dprc_scan_container);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * dprc_irq0_handler - Regular ISR for DPRC interrupt 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * @irq: IRQ number of the interrupt being handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * @arg: Pointer to device structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static irqreturn_t dprc_irq0_handler(int irq_num, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return IRQ_WAKE_THREAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * dprc_irq0_handler_thread - Handler thread function for DPRC interrupt 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) * @irq: IRQ number of the interrupt being handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * @arg: Pointer to device structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static irqreturn_t dprc_irq0_handler_thread(int irq_num, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) u32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct device *dev = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct fsl_mc_io *mc_io = mc_dev->mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct msi_desc *msi_desc = mc_dev->irqs[0]->msi_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) dev_dbg(dev, "DPRC IRQ %d triggered on CPU %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) irq_num, smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (!(mc_dev->flags & FSL_MC_IS_DPRC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) mutex_lock(&mc_bus->scan_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (!msi_desc || msi_desc->irq != (u32)irq_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) error = dprc_get_irq_status(mc_io, 0, mc_dev->mc_handle, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) "dprc_get_irq_status() failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) error = dprc_clear_irq_status(mc_io, 0, mc_dev->mc_handle, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) "dprc_clear_irq_status() failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (status & (DPRC_IRQ_EVENT_OBJ_ADDED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) DPRC_IRQ_EVENT_OBJ_REMOVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) DPRC_IRQ_EVENT_CONTAINER_DESTROYED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) DPRC_IRQ_EVENT_OBJ_DESTROYED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) DPRC_IRQ_EVENT_OBJ_CREATED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) error = dprc_scan_objects(mc_dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * If the error is -ENXIO, we ignore it, as it indicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * that the object scan was aborted, as we detected that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * an object was removed from the DPRC in the MC, while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * we were scanning the DPRC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (error != -ENXIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) dev_err(dev, "dprc_scan_objects() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) mutex_unlock(&mc_bus->scan_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * Disable and clear interrupt for a given DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static int disable_dprc_irq(struct fsl_mc_device *mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct fsl_mc_io *mc_io = mc_dev->mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * Disable generation of interrupt, while we configure it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) error = dprc_set_irq_enable(mc_io, 0, mc_dev->mc_handle, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) dev_err(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) "Disabling DPRC IRQ failed: dprc_set_irq_enable() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) * Disable all interrupt causes for the interrupt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) error = dprc_set_irq_mask(mc_io, 0, mc_dev->mc_handle, 0, 0x0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) dev_err(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) "Disabling DPRC IRQ failed: dprc_set_irq_mask() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * Clear any leftover interrupts:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) error = dprc_clear_irq_status(mc_io, 0, mc_dev->mc_handle, 0, ~0x0U);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) dev_err(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) "Disabling DPRC IRQ failed: dprc_clear_irq_status() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static int register_dprc_irq_handler(struct fsl_mc_device *mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) struct fsl_mc_device_irq *irq = mc_dev->irqs[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * NOTE: devm_request_threaded_irq() invokes the device-specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * function that programs the MSI physically in the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) error = devm_request_threaded_irq(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) irq->msi_desc->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) dprc_irq0_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) dprc_irq0_handler_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) IRQF_NO_SUSPEND | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) dev_name(&mc_dev->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) &mc_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) dev_err(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) "devm_request_threaded_irq() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static int enable_dprc_irq(struct fsl_mc_device *mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * Enable all interrupt causes for the interrupt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) error = dprc_set_irq_mask(mc_dev->mc_io, 0, mc_dev->mc_handle, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) ~0x0u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) dev_err(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) "Enabling DPRC IRQ failed: dprc_set_irq_mask() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * Enable generation of the interrupt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) error = dprc_set_irq_enable(mc_dev->mc_io, 0, mc_dev->mc_handle, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) dev_err(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) "Enabling DPRC IRQ failed: dprc_set_irq_enable() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * Setup interrupt for a given DPRC device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) static int dprc_setup_irq(struct fsl_mc_device *mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) error = fsl_mc_allocate_irqs(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) error = disable_dprc_irq(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) goto error_free_irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) error = register_dprc_irq_handler(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) goto error_free_irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) error = enable_dprc_irq(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) goto error_free_irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) error_free_irqs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) fsl_mc_free_irqs(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) * dprc_setup - opens and creates a mc_io for DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) * @mc_dev: Pointer to fsl-mc device representing a DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * It opens the physical DPRC in the MC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * It configures the DPRC portal used to communicate with MC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) int dprc_setup(struct fsl_mc_device *mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) struct device *parent_dev = mc_dev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) struct irq_domain *mc_msi_domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) bool mc_io_created = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) bool msi_domain_set = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) u16 major_ver, minor_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) size_t region_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (!is_fsl_mc_bus_dprc(mc_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (dev_get_msi_domain(&mc_dev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (!mc_dev->mc_io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * This is a child DPRC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (!dev_is_fsl_mc(parent_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (mc_dev->obj_desc.region_count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) region_size = resource_size(mc_dev->regions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) error = fsl_create_mc_io(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) mc_dev->regions[0].start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) region_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) FSL_MC_IO_ATOMIC_CONTEXT_PORTAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) &mc_dev->mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) mc_io_created = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) mc_msi_domain = fsl_mc_find_msi_domain(&mc_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (!mc_msi_domain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) dev_warn(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) "WARNING: MC bus without interrupt support\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) dev_set_msi_domain(&mc_dev->dev, mc_msi_domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) msi_domain_set = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) error = dprc_open(mc_dev->mc_io, 0, mc_dev->obj_desc.id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) &mc_dev->mc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) dev_err(&mc_dev->dev, "dprc_open() failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) goto error_cleanup_msi_domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) error = dprc_get_attributes(mc_dev->mc_io, 0, mc_dev->mc_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) &mc_bus->dprc_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) dev_err(&mc_dev->dev, "dprc_get_attributes() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) goto error_cleanup_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) error = dprc_get_api_version(mc_dev->mc_io, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) &major_ver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) &minor_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) dev_err(&mc_dev->dev, "dprc_get_api_version() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) goto error_cleanup_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (major_ver < DPRC_MIN_VER_MAJOR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) (major_ver == DPRC_MIN_VER_MAJOR &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) minor_ver < DPRC_MIN_VER_MINOR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) dev_err(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) "ERROR: DPRC version %d.%d not supported\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) major_ver, minor_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) error = -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) goto error_cleanup_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) error_cleanup_open:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) (void)dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) error_cleanup_msi_domain:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (msi_domain_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) dev_set_msi_domain(&mc_dev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (mc_io_created) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) fsl_destroy_mc_io(mc_dev->mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) mc_dev->mc_io = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) EXPORT_SYMBOL_GPL(dprc_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) * dprc_probe - callback invoked when a DPRC is being bound to this driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * @mc_dev: Pointer to fsl-mc device representing a DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) * It opens the physical DPRC in the MC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) * It scans the DPRC to discover the MC objects contained in it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) * It creates the interrupt pool for the MC bus associated with the DPRC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) * It configures the interrupts for the DPRC device itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) static int dprc_probe(struct fsl_mc_device *mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) error = dprc_setup(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) * Discover MC objects in DPRC object:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) error = dprc_scan_container(mc_dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) goto dprc_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) * Configure interrupt for the DPRC object associated with this MC bus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) error = dprc_setup_irq(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) goto scan_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) dev_info(&mc_dev->dev, "DPRC device bound to driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) scan_cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) dprc_cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) dprc_cleanup(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) * Tear down interrupt for a given DPRC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) static void dprc_teardown_irq(struct fsl_mc_device *mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) struct fsl_mc_device_irq *irq = mc_dev->irqs[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) (void)disable_dprc_irq(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) devm_free_irq(&mc_dev->dev, irq->msi_desc->irq, &mc_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) fsl_mc_free_irqs(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) * dprc_cleanup - function that cleanups a DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * @mc_dev: Pointer to fsl-mc device representing the DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) * It closes the DPRC device in the MC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) * It destroys the interrupt pool associated with this MC bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) int dprc_cleanup(struct fsl_mc_device *mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) /* this function should be called only for DPRCs, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) * is an error to call it for regular objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) if (!is_fsl_mc_bus_dprc(mc_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) if (dev_get_msi_domain(&mc_dev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) fsl_mc_cleanup_irq_pool(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) dev_set_msi_domain(&mc_dev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) fsl_mc_cleanup_all_resource_pools(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) /* if this step fails we cannot go further with cleanup as there is no way of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) * communicating with the firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) if (!mc_dev->mc_io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) dev_err(&mc_dev->dev, "mc_io is NULL, tear down cannot be performed in firmware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) error = dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) dev_err(&mc_dev->dev, "dprc_close() failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (!fsl_mc_is_root_dprc(&mc_dev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) fsl_destroy_mc_io(mc_dev->mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) mc_dev->mc_io = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) EXPORT_SYMBOL_GPL(dprc_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) * dprc_remove - callback invoked when a DPRC is being unbound from this driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * @mc_dev: Pointer to fsl-mc device representing the DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * It removes the DPRC's child objects from Linux (not from the MC) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * closes the DPRC device in the MC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * It tears down the interrupts that were configured for the DPRC device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) * It destroys the interrupt pool associated with this MC bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) static int dprc_remove(struct fsl_mc_device *mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (!is_fsl_mc_bus_dprc(mc_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if (!mc_bus->irq_resources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if (dev_get_msi_domain(&mc_dev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) dprc_teardown_irq(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) dprc_cleanup(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) dev_info(&mc_dev->dev, "DPRC device unbound from driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) static const struct fsl_mc_device_id match_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) .vendor = FSL_MC_VENDOR_FREESCALE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) .obj_type = "dprc"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) {.vendor = 0x0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) static struct fsl_mc_driver dprc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) .name = FSL_MC_DPRC_DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) .pm = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) .match_id_table = match_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) .probe = dprc_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) .remove = dprc_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) int __init dprc_driver_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) return fsl_mc_driver_register(&dprc_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) void dprc_driver_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) fsl_mc_driver_unregister(&dprc_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }