drivers/bus: Freescale Management Complex bus driver patch series
v2 cover drivers/bus: Freescale Management Complex bus driver patch series
This patch series introduces Linux support for the Freescale Management Complex (fsl-mc) hardware. This patch series is dependent on the patch series "ARM64: Add support for FSL's LS2085A SoC"
(http://thread.gmane.org/gmane.linux.ports.arm.kernel/351829)
The fsl-mc is a hardware resource manager that manages specialized hardware objects used in network-oriented packet processing applications. After the fsl-mc block is enabled, pools of hardware resources are available, such as queues, buffer poools, I/O interfaces. These resources are building blocks that can be used to create functional hardware objects such as network interfaces, crypto accelerator instances, or L2 switches.
All the fsl-mc managed hardware resources/objects are represented in a physical grouping mechanism called a 'container' or DPRC (data path resource container).
Quoted 1 line
From the point of view of an OS, a DPRC functions similar to a plug
and play bus. Using fsl-mc commands software can enumerate the contents of the DPRC discovering the hardware objects present and binding them to drivers. Hardware objects can be created and removed dynamically, providing hot pluggability of the hardware objects.
Software contexts interact with the fsl-mc by sending commands through a memory mapped hardware interface called an "MC portal". Every fsl-mc object type has a command set to manage the objects. Key DPRC commands include:
-create/destroy a DPRC
-enumerate objects and resource pools in the DPRC, including
identifying mappable regions and the number of IRQs an object may have
-IRQ configuration
-move objects/resources between DPRCs
-connecting objects (e.g. connecting a network interface to
an L2 switch port)
-reset
Patch 1 contains a minimal set of low level functions to send an d receive commands to the fsl-mc. It includes support for basic management commands and commands to manipulate DPRC objects.
Patch 2 contains a platform device driver that sets up and registers the basic bus infrastructure including support for adding/removing devices, register/unregister of drivers, and bus match support to bind devices to drivers.
Patch 3 contains an driver that manages DPRC objects (the container that holds the hardware resources). This driver functions as a bus controller and handles enumeration of the objects in the container and hotplug events.
CHANGE HISTORY
Issues pending resolution not addressed by v2:
- What to do with Doxygen comments in patch 1
- Whether to move or not FSL-specific header files added in include/linux, by this patch series, to another location
- Whether to change or not the wording of the licenses used in some source files
- Checkpatch warnings:
* WARNING: DT compatible string "fsl,qoriq-mc" appears un-documented
This warning will go away once the prerequisite patch series is
accepted upstream.
* WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
This warning still happens even after adding MAINTAINERS file entries in
the same patch where new files were added
- Sparse warning:
* drivers/bus/fsl-mc/fsl_mc_sys.c:193:9: warning: context imbalance in 'mc_send_command' - different lock contexts for basic block This warning is caused by conditionally acquiring/releasing a lock in function mc_send_command().
Not clear how to solve this warning, as we need to be able to decide at
run time based on a flag whether to acquire the lock or not.
Changes in v2:
- Added reference to the patch series this patch is dependent on for device tree and device tree bindings changes. (See above).
- Removed patch 4 (update to the MAINTAINERS file), as this is done now in patch 1
- Addressed comments from Joe Perches, Kim Phillips, Alex Graf and Scott Wood. Details in each patch.
Changes in v1:
- No changes since RFC v4
Changes in RFC v4:
- Fixed parameter mismatch for device_find_child() call in fsl_mc_dprc.c
- Added back the dma_mask field to struct fsl_mc_device as it is needed by some MC child device drivers. However, the default DMA mask now does not have the 32-bit limitation of the original patch series (v1).
Changes in RFC v3:
Rework to address comments from Arnd Bergmann:
- Removed per-bus list of children, and instead use device_for_each_child()
- Use the same structure (struct fsl_mc_device) to represent both bus devices and their children.
http://www.mail-archive.com/linux-kernel%40vger.kernel.org/msg711301.html
Changes in RFC v2:
Rework to address comments from Arnd Bergmann:
- Removed fsl_mc_bus structure and global variable
- Removed the 'magic' fields from all structs
- Removed NULL initializers
- Replaced all occurrences of EXPORT_SYMBOL() with EXPORT_SYMBOL_GPL()
- Removed function dprc_parse_dt_node(), and replaced its call by a direct call to of_address_to_resource()
- Removed struct fsl_mc_device_region and use standard 'struct resource' instead.
- Removed dma_mask field from 'struct fsl_mc_device' as it is not currently being used.
- Removed redundant 'driver' field from struct fsl_mc_device
- Removed the container field. We can get the parent DPRC of a given dev, from its dev.parent field.
http://www.mail-archive.com/linux-kernel%40vger.kernel.org/msg708858.html
PATCH v2 1/3 drivers/bus: Added Freescale Management Complex APIs
From: "J. German Rivera" <[email protected]>
APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.
---
Changes in v2:
- Addressed comment from Joe Perches:
* Refactored logic to actively fail on err and proceed at the same indent level on success, for all functions in dprc.c and dpmng.c.
- Addressed comments from Kim Phillips:
* Fixed warning in mc_send_command
* Changed serialization logic in mc_send_command() to only use spinlock_irqsave() when both threads and interrupt handlers concurrently access the same portal.
* Changed switch to lookup table in mc_status_to_error()
* Removed macros iowrite64(), ioread64(), ENOTSUP from fsl_mc_sys.h
* Removed #ifdef side for FSL_MC_FIRMWARE in fsl_mc_cmd.h
* Changed non-devm_ API calls to devm_ API calls and refactored fsl_create_mc_io()/fsl_destroy_mc_io() to simplify cleanup logic.
- Addressed comments from Scott Wood:
* Return -ENXIO instead of -EFAULT when ioremap_nocache() fails
- Addressed comments from Alex Graf:
* Added MAINTAINERS file entries for new files
* Added dev param to fsl_create_mc_io(), to enable the use of devm_ APIs in this function and fsl_destroy_mc_io().
* Changed the value of the timeout for MC command completion to be a function of HZ instead of a hard-coded jiffies value.
MAINTAINERS | 8 + drivers/bus/fsl-mc/dpmng.c | 95 +++++ drivers/bus/fsl-mc/dprc.c | 520 ++++++++++++++++++++++++ drivers/bus/fsl-mc/fsl_dpmng_cmd.h | 83 ++++ drivers/bus/fsl-mc/fsl_dprc_cmd.h | 545 +++++++++++++++++++++++++ drivers/bus/fsl-mc/fsl_mc_sys.c | 195 +++++++++ include/linux/fsl_dpmng.h | 120 ++++++ include/linux/fsl_dprc.h | 790 ++++++++++++++++++++++++++++++++++++ include/linux/fsl_mc_cmd.h | 168 ++++++++ include/linux/fsl_mc_sys.h | 89 ++++ 10 files changed, 2613 insertions(+) create mode 100644 drivers/bus/fsl-mc/dpmng.c create mode 100644 drivers/bus/fsl-mc/dprc.c create mode 100644 drivers/bus/fsl-mc/fsl_dpmng_cmd.h create mode 100644 drivers/bus/fsl-mc/fsl_dprc_cmd.h create mode 100644 drivers/bus/fsl-mc/fsl_mc_sys.c create mode 100644 include/linux/fsl_dpmng.h create mode 100644 include/linux/fsl_dprc.h create mode 100644 include/linux/fsl_mc_cmd.h create mode 100644 include/linux/fsl_mc_sys.h
MAINTAINERS +8 -0
@@ -3875,6 +3875,14 @@ F: sound/soc/fsl/fsl* F: sound/soc/fsl/imx* F: sound/soc/fsl/mpc8610_hpcd.c +FREESCALE QORIQ MANAGEMENT COMPLEX DRIVER +M: J. German Rivera <[email protected]> +L: [email protected] +S: Maintained +F: include/linux/fsl_mc* +F: include/linux/fsl_dp* +F: drivers/bus/fsl-mc/* + FREEVXFS FILESYSTEM M: Christoph Hellwig <[email protected]> W: ftp://ftp.openlinux.org/pub/people/hch/vxfs
drivers/bus/fsl-mc/dpmng.c new file +95 -0
95 lines not on this page · raw message
drivers/bus/fsl-mc/dprc.c new file +520 -0
520 lines not on this page · raw message
drivers/bus/fsl-mc/fsl_dpmng_cmd.h new file +83 -0
83 lines not on this page · raw message
drivers/bus/fsl-mc/fsl_dprc_cmd.h new file +545 -0
545 lines not on this page · raw message
drivers/bus/fsl-mc/fsl_mc_sys.c new file +195 -0
195 lines not on this page · raw message
include/linux/fsl_dpmng.h new file +120 -0
120 lines not on this page · raw message
include/linux/fsl_dprc.h new file +790 -0
790 lines not on this page · raw message
include/linux/fsl_mc_cmd.h new file +168 -0
168 lines not on this page · raw message
include/linux/fsl_mc_sys.h new file +89 -0
89 lines not on this page · raw message
--
1.7.9.7
Re: [PATCH 1/3 v2] drivers/bus: Added Freescale Management Complex APIs
Quoted 1 line · On Fri, 19 Sep 2014 17:49:39 -0500 "J. German Rivera"…
+int
mc_get_version(struct fsl_mc_io *mc_io, struct mc_version *mc_ver_info)
...
drivers/bus/fsl-mc/dpmng.c line 50
Quoted 5 lines
drivers/bus/fsl-mc/dpmng.c new file +5
-0+ err =mc_send_command (mc_io, &cmd); +if (err) +return err; + +DPMNG_RSP_GET_VERSION (cmd, mc_ver_info);
alignment
drivers/bus/fsl-mc/dpmng.c line 72
Quoted 5 lines
drivers/bus/fsl-mc/dpmng.c new file +5
-0+int dpmng_load_aiop (struct fsl_mc_io *mc_io, +int aiop_tile_id,uint8_t *img_addr,int img_size) +{ +struct mc_command cmd = {0 }; +uint64_t img_paddr =virt_to_phys (img_addr);
Direct use of virt_to_phys by drivers is deprecated; this code needs to map the i/o space via the DMA API. This is in order to handle situations where e.g., the device sitting behind an IOMMU. See Documentation/DMA-API* for more info.
Quoted 15 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +15
-0+/** +* Delay in microseconds between polling iterations while +* waiting for MC command completion +*/ +#define MC_CMD_COMPLETION_POLLING_INTERVAL_USECS 500/* 0.5 ms */ + +int __must_check fsl_create_mc_io (struct device *dev, +phys_addr_t mc_portal_phys_addr, +uint32_t mc_portal_size, +uint32_t flags,struct fsl_mc_io **new_mc_io) +{ +struct fsl_mc_io *mc_io; +void __iomem *mc_portal_virt_addr; +struct resource *res; +
drivers/bus/fsl-mc/fsl_mc_sys.c line 67
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+ mc_io =devm_kzalloc (dev,sizeof (*mc_io),GFP_KERNEL ); +if (mc_io ==NULL ) +return -ENOMEM ; + + mc_io->dev = dev; + mc_io->flags = flags; + mc_io->portal_phys_addr = mc_portal_phys_addr; + mc_io->portal_size = mc_portal_size; +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS ) +spin_lock_init (&mc_io->spinlock);
I'm confused - this patseries doesn't register an interrupt handler, so this can't be true (or it's premature if it will, in which case it should be left out for now).
However, if somehow users of this code register an IRQ handler for the portal (I don't see any users to tell how they get the IRQ line either?), then it's up to them to establish mutual exclusion rules for access, among themselves. Unless you think they will be calling mc_send_command from h/w IRQ context, in which case I'd reconsider that assumption because send_command looks like it'd take too long to get an answer from the h/w - IRQ handlers should just ack the h/w IRQ, and notify the scheduler that the driver has work to do (in s/w IRQ context perhaps).
drivers/bus/fsl-mc/fsl_mc_sys.c line 69
Quoted 2 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +2
-0+else if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) +mutex_init (&mc_io->mutex);
I'd assume SHARED_BY_THREADS to always be true in linux.
Quoted 21 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +21
-0+ res =devm_request_mem_region (dev, + mc_portal_phys_addr, + mc_portal_size, +"mc_portal" ); +if (res ==NULL ) { +dev_err (dev, +"devm_request_mem_region failed for MC portal %#llx\n" , + mc_portal_phys_addr); +return -EBUSY ; + } + + mc_portal_virt_addr =devm_ioremap_nocache (dev, + mc_portal_phys_addr, + mc_portal_size); +if (mc_portal_virt_addr ==NULL ) { +dev_err (dev, +"devm_ioremap_nocache failed for MC portal %#llx\n" , + mc_portal_phys_addr); +return -ENXIO ; + } +
drivers/bus/fsl-mc/fsl_mc_sys.c line 101
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+ mc_io->portal_virt_addr = mc_portal_virt_addr; + *new_mc_io = mc_io; +return 0 ; +} +EXPORT_SYMBOL_GPL (fsl_create_mc_io); + +void fsl_destroy_mc_io (struct fsl_mc_io *mc_io) +{ +if (WARN_ON (mc_io->portal_virt_addr ==NULL )) +return ;
this is unnecessary - you'll get the stack trace anyway, and users calling destroy on a not successfully created mc_io object should not get the luxury of maybe being able to continue after the stack trace, after possibly leaking memory.
drivers/bus/fsl-mc/fsl_mc_sys.c line 109
Quoted 2 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +2
-0+ mc_io->portal_virt_addr =NULL ; +devm_kfree (mc_io->dev, mc_io);
like I said before, there's really no point in clearing something out right before it's freed.
Quoted 13 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +13
-0+} +EXPORT_SYMBOL_GPL (fsl_destroy_mc_io); + +static int mc_status_to_error (enum mc_cmd_status status) +{ +static const int mc_status_to_error_map[] = { + [MC_CMD_STATUS_OK ] =0 , + [MC_CMD_STATUS_AUTH_ERR ] = -EACCES , + [MC_CMD_STATUS_NO_PRIVILEGE ] = -EPERM , + [MC_CMD_STATUS_DMA_ERR ] = -EIO , + [MC_CMD_STATUS_CONFIG_ERR ] = -ENXIO , + [MC_CMD_STATUS_TIMEOUT ] = -ETIMEDOUT , + [MC_CMD_STATUS_NO_RESOURCE ] = -ENAVAIL ,
drivers/bus/fsl-mc/fsl_mc_sys.c line 133
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+ [MC_CMD_STATUS_NO_MEMORY] = -ENOMEM, + [MC_CMD_STATUS_BUSY] = -EBUSY, + [MC_CMD_STATUS_UNSUPPORTED_OP] = -ENOTSUPP, + [MC_CMD_STATUS_INVALID_STATE] = -ENODEV, + }; + +if (WARN_ON (status >=ARRAY_SIZE (mc_status_to_error_map))) +return -EINVAL ; +return mc_status_to_error_map[status]; +}
great - CONFIG_ERR is now -ENXIO instead of -EINVAL, so at least it's now mutually exclusive, but it doesn't handle MC_CMD_STATUS_READY - should it?
Quoted 9 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +9
-0+int mc_send_command (struct fsl_mc_io *mc_io,struct mc_command *cmd) +{ +enum mc_cmd_status status; +int error; +unsigned long irqsave_flags =0 ; +unsigned long jiffies_until_timeout = + jiffies +MC_CMD_COMPLETION_TIMEOUT_JIFFIES ; + +/*
drivers/bus/fsl-mc/fsl_mc_sys.c line 153
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+* Acquire lock depending on mc_io flags: +*/ +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS ) { +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) +spin_lock_irqsave (&mc_io->spinlock, irqsave_flags); +else +spin_lock (&mc_io->spinlock); + }else if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) { +mutex_lock (&mc_io->mutex); + }
again, I think we need to drop the coming from h/w IRQ context here (SHARED_BY_INT_HANDLERS); there's no IRQ handlers in this patchseries, and calling this function from an IRQ handler would be prohibitively wasteful, guessing by the udelay and timeout values below.
Can we just mutex_lock for now, and unconditionally (no SHARED_BY_THREADS check), to protect from nesting?
drivers/bus/fsl-mc/fsl_mc_sys.c line 172
Quoted 13 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +13
-0+/* +* Wait for response from the MC hardware: +*/ +for (;;) { + status =mc_read_response (mc_io->portal_virt_addr, cmd); +if (status !=MC_CMD_STATUS_READY ) +break ; + +/* +* TODO: When MC command completion interrupts are supported +* call wait function here instead of udelay() +*/ +udelay (MC_CMD_COMPLETION_POLLING_INTERVAL_USECS );
this pauses any caller for 0.5ms on every successful command write. Can the next submission of the patchseries wait until completion IRQs are indeed supported, since both that and the above locking needs to be resolved?
Kim
Re: [PATCH 1/3 v2] drivers/bus: Added Freescale Management Complex APIs
Quoted 13 lines · Kim Phillips
Quoted 1 line · On Fri, 19 Sep 2014 17:49:39 -0500 "J. German Rivera"…
+int
mc_get_version(struct fsl_mc_io *mc_io, struct mc_version *mc_ver_info)...
drivers/bus/fsl-mc/dpmng.c line 50
Quoted 5 lines
drivers/bus/fsl-mc/dpmng.c new file +5
-0+ err =mc_send_command (mc_io, &cmd); +if (err) +return err; + +DPMNG_RSP_GET_VERSION (cmd, mc_ver_info);alignment
Quoted 11 lines
drivers/bus/fsl-mc/dpmng.c line 72
Quoted 5 lines
drivers/bus/fsl-mc/dpmng.c new file +5
-0+int dpmng_load_aiop (struct fsl_mc_io *mc_io, +int aiop_tile_id,uint8_t *img_addr,int img_size) +{ +struct mc_command cmd = {0 }; +uint64_t img_paddr =virt_to_phys (img_addr);Direct use of
virt_to_physby drivers is deprecated; this code needs to map the i/o space via the DMA API. This is in order to handle situations where e.g., the device sitting behind an IOMMU. SeeDocumentation/DMA-API*for more info.
Ok, we will make this change in the v3 respin.
Quoted 30 lines
Quoted 15 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +15
-0+/** +* Delay in microseconds between polling iterations while +* waiting for MC command completion +*/ +#define MC_CMD_COMPLETION_POLLING_INTERVAL_USECS 500/* 0.5 ms */ + +int __must_check fsl_create_mc_io (struct device *dev, +phys_addr_t mc_portal_phys_addr, +uint32_t mc_portal_size, +uint32_t flags,struct fsl_mc_io **new_mc_io) +{ +struct fsl_mc_io *mc_io; +void __iomem *mc_portal_virt_addr; +struct resource *res; +drivers/bus/fsl-mc/fsl_mc_sys.c line 67
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+ mc_io =devm_kzalloc (dev,sizeof (*mc_io),GFP_KERNEL ); +if (mc_io ==NULL ) +return -ENOMEM ; + + mc_io->dev = dev; + mc_io->flags = flags; + mc_io->portal_phys_addr = mc_portal_phys_addr; + mc_io->portal_size = mc_portal_size; +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS ) +spin_lock_init (&mc_io->spinlock);I'm confused - this patseries doesn't register an interrupt handler, so this can't be true (or it's premature if it will, in which case it should be left out for now).
Quoted 10 lines
However, if somehow users of this code register an IRQ handler for the portal (I don't see any users to tell how they get the IRQ line either?), then it's up to them to establish mutual exclusion rules for access, among themselves. Unless you think they will be calling
mc_send_commandfrom h/w IRQ context, in which case I'd reconsider that assumption becausesend_commandlooks like it'd take too long to get an answer from the h/w - IRQ handlers should just ack the h/w IRQ, and notify the scheduler that the driver has work to do (in s/w IRQ context perhaps).
Although not included in this patch series, there are cases in subsequent patch series, in which mc_send_command() will need to be called from interrupt context.
For example, the dprc_get_irq_status() needs to be called from the DPRC ISR to determine the actual cause of the interrupt. Also, to clear the interrupt the dprc_clear_irq_status() needs to be called from the ISR. Both od these functions call mc_send_command():
int dprc_get_irq_status(struct fsl_mc_io *mc_io, uint16_t dprc_handle,
uint8_t irq_index, uint32_t *status)
{
struct mc_command cmd = { 0 };
int err;
cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
DPRC_CMDSZ_GET_IRQ_STATUS,
MC_CMD_PRI_LOW, dprc_handle);
DPRC_CMD_GET_IRQ_STATUS(cmd, irq_index);
err = mc_send_command(mc_io, &cmd);
if (!err)
DPRC_RSP_GET_IRQ_STATUS(cmd, *status);
return err;
}int dprc_clear_irq_status(struct fsl_mc_io *mc_io, uint16_t dprc_handle,
uint8_t irq_index, uint32_t status)
{
struct mc_command cmd = { 0 };
cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
DPRC_CMDSZ_CLEAR_IRQ_STATUS,
MC_CMD_PRI_LOW, dprc_handle);
DPRC_CMD_CLEAR_IRQ_STATUS(cmd, status, irq_index);
return mc_send_command(mc_io, &cmd);
}Quoted 5 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 69
Quoted 2 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +2
-0+else if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) +mutex_init (&mc_io->mutex);I'd assume
SHARED_BY_THREADSto always be true in linux.
Not, if mc_send_command() is called from interrupt context, as explained above. However, since this patch series does not include any interrupt handlers, we can remove the FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS flag and the associated spinlock, from this patch series.
Quoted 28 lines
Quoted 28 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +28
-0+ res =devm_request_mem_region (dev, + mc_portal_phys_addr, + mc_portal_size, +"mc_portal" ); +if (res ==NULL ) { +dev_err (dev, +"devm_request_mem_region failed for MC portal %#llx\n" , + mc_portal_phys_addr); +return -EBUSY ; + } + + mc_portal_virt_addr =devm_ioremap_nocache (dev, + mc_portal_phys_addr, + mc_portal_size); +if (mc_portal_virt_addr ==NULL ) { +dev_err (dev, +"devm_ioremap_nocache failed for MC portal %#llx\n" , + mc_portal_phys_addr); +return -ENXIO ; + } + + mc_io->portal_virt_addr = mc_portal_virt_addr; + *new_mc_io = mc_io; +return 0 ; +} +EXPORT_SYMBOL_GPL (fsl_create_mc_io); + +void fsl_destroy_mc_io (struct fsl_mc_io *mc_io)
Quoted 8 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 101
Quoted 3 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +3
-0+{ +if (WARN_ON (mc_io->portal_virt_addr ==NULL )) +return ;this is unnecessary - you'll get the stack trace anyway, and users calling destroy on a not successfully created
mc_ioobject should not get the luxury of maybe being able to continue after the stack trace, after possibly leaking memory.
Ok, I'ĺl remove this WARN_ON in the v3 respin.
Quoted 7 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 109
Quoted 3 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +2
-0+ mc_io->portal_virt_addr =NULL ; +devm_kfree (mc_io->dev, mc_io);like I said before, there's really no point in clearing something out right before it's freed.
I disagree. This can help detect cases of double-freeing.
Quoted 19 lines
Quoted 19 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +19
-0+} +EXPORT_SYMBOL_GPL (fsl_destroy_mc_io); + +static int mc_status_to_error (enum mc_cmd_status status) +{ +static const int mc_status_to_error_map[] = { + [MC_CMD_STATUS_OK ] =0 , + [MC_CMD_STATUS_AUTH_ERR ] = -EACCES , + [MC_CMD_STATUS_NO_PRIVILEGE ] = -EPERM , + [MC_CMD_STATUS_DMA_ERR ] = -EIO , + [MC_CMD_STATUS_CONFIG_ERR ] = -ENXIO , + [MC_CMD_STATUS_TIMEOUT ] = -ETIMEDOUT , + [MC_CMD_STATUS_NO_RESOURCE ] = -ENAVAIL , + [MC_CMD_STATUS_NO_MEMORY ] = -ENOMEM , + [MC_CMD_STATUS_BUSY ] = -EBUSY , + [MC_CMD_STATUS_UNSUPPORTED_OP ] = -ENOTSUPP , + [MC_CMD_STATUS_INVALID_STATE ] = -ENODEV , + }; +
Quoted 9 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 133
Quoted 4 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +4
-0+if (WARN_ON (status >=ARRAY_SIZE (mc_status_to_error_map))) +return -EINVAL ; +return mc_status_to_error_map[status]; +}great -
CONFIG_ERRis now-ENXIOinstead of-EINVAL, so at least it's now mutually exclusive, but it doesn't handleMC_CMD_STATUS_READY- should it?
No. MC_CMD_STATUS_READY does not need to be seen by mc_send_command() callers. It is only used to know when to stop polling the MC for command completion.
Quoted 26 lines
Quoted 9 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +9
-0+int mc_send_command (struct fsl_mc_io *mc_io,struct mc_command *cmd) +{ +enum mc_cmd_status status; +int error; +unsigned long irqsave_flags =0 ; +unsigned long jiffies_until_timeout = + jiffies +MC_CMD_COMPLETION_TIMEOUT_JIFFIES ; + +/* drivers/bus/fsl-mc/fsl_mc_sys.c line 153
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+* Acquire lock depending on mc_io flags: +*/ +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS ) { +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) +spin_lock_irqsave (&mc_io->spinlock, irqsave_flags); +else +spin_lock (&mc_io->spinlock); + }else if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) { +mutex_lock (&mc_io->mutex); + }again, I think we need to drop the coming from h/w IRQ context here (
SHARED_BY_INT_HANDLERS); there's no IRQ handlers in this patchseries, and calling this function from an IRQ handler would be prohibitively wasteful, guessing by the udelay and timeout values below.
Quoted 3 lines
Can we just
mutex_lockfor now, and unconditionally (noSHARED_BY_THREADScheck), to protect from nesting?
I would still prefer to keep the SHARED_BY_THREADS flag, to give option of not doing any locking, in cases where the portal used in mc_send_command() is not shared among concurrent callers
What do you mean by nesting in this case?
Quoted 10 lines
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+/* +* Wait for response from the MC hardware: +*/ +for (;;) { + status =mc_read_response (mc_io->portal_virt_addr, cmd); +if (status !=MC_CMD_STATUS_READY ) +break ; + +/* +* TODO: When MC command completion interrupts are supported
Quoted 9 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 172
Quoted 3 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +3
-0+* call wait function here instead of udelay() +*/ +udelay (MC_CMD_COMPLETION_POLLING_INTERVAL_USECS );this pauses any caller for 0.5ms on every successful command write. Can the next submission of the patchseries wait until completion IRQs are indeed supported, since both that and the above locking needs to be resolved?
No. Interrupt handlers will come in a later patch series as they are not needed for using the basic MC functionality.
Quoted 2 lines
Kim
Re: [PATCH 1/3 v2] drivers/bus: Added Freescale Management Complex APIs
Quoted 43 lines · On Wed, 24 Sep 2014 21:23:59 -0500 German Rivera <[email protected]>…
Quoted 32 lines · Kim Phillips
Quoted 14 lines · On Fri, 19 Sep 2014 17:49:39 -0500 "J. German Rivera"…
+ * Delay in microseconds between polling iterations while
+ * waiting for MC command completion
+ */drivers/bus/fsl-mc/fsl_mc_sys.c new file +11
-0+#define MC_CMD_COMPLETION_POLLING_INTERVAL_USECS 500/* 0.5 ms */ + +int __must_check fsl_create_mc_io (struct device *dev, +phys_addr_t mc_portal_phys_addr, +uint32_t mc_portal_size, +uint32_t flags,struct fsl_mc_io **new_mc_io) +{ +struct fsl_mc_io *mc_io; +void __iomem *mc_portal_virt_addr; +struct resource *res; +drivers/bus/fsl-mc/fsl_mc_sys.c line 67
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+ mc_io =devm_kzalloc (dev,sizeof (*mc_io),GFP_KERNEL ); +if (mc_io ==NULL ) +return -ENOMEM ; + + mc_io->dev = dev; + mc_io->flags = flags; + mc_io->portal_phys_addr = mc_portal_phys_addr; + mc_io->portal_size = mc_portal_size; +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS ) +spin_lock_init (&mc_io->spinlock);I'm confused - this patseries doesn't register an interrupt handler, so this can't be true (or it's premature if it will, in which case it should be left out for now).
Quoted 10 lines
However, if somehow users of this code register an IRQ handler for the portal (I don't see any users to tell how they get the IRQ line either?), then it's up to them to establish mutual exclusion rules for access, among themselves. Unless you think they will be calling
mc_send_commandfrom h/w IRQ context, in which case I'd reconsider that assumption becausesend_commandlooks like it'd take too long to get an answer from the h/w - IRQ handlers should just ack the h/w IRQ, and notify the scheduler that the driver has work to do (in s/w IRQ context perhaps).
Quoted 8 lines
Although not included in this patch series, there are cases in subsequent patch series, in which
mc_send_command()will need to be called from interrupt context.For example, the
dprc_get_irq_status()needs to be called from the DPRC ISR to determine the actual cause of the interrupt. Also, to clear the interrupt thedprc_clear_irq_status()needs to be called from the ISR. Both od these functions callmc_send_command():
yet mc_send_command itself has the capability to trigger a h/w IRQ, no? So how is that expected to work, given h/w IRQ handlers run with IRQs turned off?
Quoted 47 lines
Quoted 5 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 69
Quoted 2 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +2
-0+else if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) +mutex_init (&mc_io->mutex);I'd assume
SHARED_BY_THREADSto always be true in linux.Not, if
mc_send_command()is called from interrupt context, as explained above. However, since this patch series does not include any interrupt handlers, we can remove theFSL_MC_PORTAL_SHARED_BY_INT_HANDLERSflag and the associated spinlock, from this patch series.Quoted 28 lines
Quoted 28 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +28
-0+ res =devm_request_mem_region (dev, + mc_portal_phys_addr, + mc_portal_size, +"mc_portal" ); +if (res ==NULL ) { +dev_err (dev, +"devm_request_mem_region failed for MC portal %#llx\n" , + mc_portal_phys_addr); +return -EBUSY ; + } + + mc_portal_virt_addr =devm_ioremap_nocache (dev, + mc_portal_phys_addr, + mc_portal_size); +if (mc_portal_virt_addr ==NULL ) { +dev_err (dev, +"devm_ioremap_nocache failed for MC portal %#llx\n" , + mc_portal_phys_addr); +return -ENXIO ; + } + + mc_io->portal_virt_addr = mc_portal_virt_addr; + *new_mc_io = mc_io; +return 0 ; +} +EXPORT_SYMBOL_GPL (fsl_create_mc_io); + +void fsl_destroy_mc_io (struct fsl_mc_io *mc_io)Quoted 8 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 101
Quoted 3 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +3
-0+{ +if (WARN_ON (mc_io->portal_virt_addr ==NULL )) +return ;this is unnecessary - you'll get the stack trace anyway, and users calling destroy on a not successfully created
mc_ioobject should not get the luxury of maybe being able to continue after the stack trace, after possibly leaking memory.
Quoted 1 line
Ok, I'ĺl remove this
WARN_ONin the v3 respin.
subsequent code will cause a stack trace when dereferencing portal_virt_addr anyway, so the if statement isn't needed at all.
Quoted 7 lines
Quoted 6 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 109
Quoted 2 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +2
-0+ mc_io->portal_virt_addr =NULL ; +devm_kfree (mc_io->dev, mc_io);like I said before, there's really no point in clearing something out right before it's freed.
I disagree. This can help detect cases of double-freeing.
? freeing NULL does nothing - it just returns - which doesn't help detect anything. What's more, the kernel has a memory debugging infrastructure that detects double freeing of the same object.
Quoted 26 lines
Quoted 26 lines
Quoted 9 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +9
-0+int mc_send_command (struct fsl_mc_io *mc_io,struct mc_command *cmd) +{ +enum mc_cmd_status status; +int error; +unsigned long irqsave_flags =0 ; +unsigned long jiffies_until_timeout = + jiffies +MC_CMD_COMPLETION_TIMEOUT_JIFFIES ; + +/* drivers/bus/fsl-mc/fsl_mc_sys.c line 153
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+* Acquire lock depending on mc_io flags: +*/ +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS ) { +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) +spin_lock_irqsave (&mc_io->spinlock, irqsave_flags); +else +spin_lock (&mc_io->spinlock); + }else if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) { +mutex_lock (&mc_io->mutex); + }again, I think we need to drop the coming from h/w IRQ context here (
SHARED_BY_INT_HANDLERS); there's no IRQ handlers in this patchseries, and calling this function from an IRQ handler would be prohibitively wasteful, guessing by the udelay and timeout values below.
Quoted 6 lines
Quoted 3 lines
Can we just
mutex_lockfor now, and unconditionally (noSHARED_BY_THREADScheck), to protect from nesting?I would still prefer to keep the
SHARED_BY_THREADSflag, to give option of not doing any locking, in cases where the portal used inmc_send_command()is not shared among concurrent callers
how can you guarantee there won't be concurrent callers? The linux kernel is multithreaded.
Quoted 1 line
What do you mean by nesting in this case?
when a thread gets interrupted by another thread, and/or another
IRQ: this would cause an unrecoverable race condition.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+/* +* Wait for response from the MC hardware: +*/ +for (;;) { + status =mc_read_response (mc_io->portal_virt_addr, cmd); +if (status !=MC_CMD_STATUS_READY ) +break ; + +/* +* TODO: When MC command completion interrupts are supported Quoted 9 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 172
Quoted 3 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +3
-0+* call wait function here instead of udelay() +*/ +udelay (MC_CMD_COMPLETION_POLLING_INTERVAL_USECS );this pauses any caller for 0.5ms on every successful command write. Can the next submission of the patchseries wait until completion IRQs are indeed supported, since both that and the above locking needs to be resolved?
Quoted 2 lines
No. Interrupt handlers will come in a later patch series as they are not needed for using the basic MC functionality.
meanwhile unnecessarily udelaying kernel threads for .5ms upsets basic kernel functionality :) Would using the kernel's wait_for_completion API be a good compromise here? See include/linux/completion.h.
Kim
Re: [PATCH 1/3 v2] drivers/bus: Added Freescale Management Complex APIs
Quoted 50 lines · Kim Phillips
Quoted 47 lines · On Wed, 24 Sep 2014 21:23:59 -0500 German Rivera <[email protected]>…
Quoted 32 lines · Kim Phillips
Quoted 14 lines · On Fri, 19 Sep 2014 17:49:39 -0500 "J. German Rivera"…
+ * Delay in microseconds between polling iterations while
+ * waiting for MC command completion
+ */drivers/bus/fsl-mc/fsl_mc_sys.c new file +11
-0+#define MC_CMD_COMPLETION_POLLING_INTERVAL_USECS 500/* 0.5 ms */ + +int __must_check fsl_create_mc_io (struct device *dev, +phys_addr_t mc_portal_phys_addr, +uint32_t mc_portal_size, +uint32_t flags,struct fsl_mc_io **new_mc_io) +{ +struct fsl_mc_io *mc_io; +void __iomem *mc_portal_virt_addr; +struct resource *res; +drivers/bus/fsl-mc/fsl_mc_sys.c line 67
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+ mc_io =devm_kzalloc (dev,sizeof (*mc_io),GFP_KERNEL ); +if (mc_io ==NULL ) +return -ENOMEM ; + + mc_io->dev = dev; + mc_io->flags = flags; + mc_io->portal_phys_addr = mc_portal_phys_addr; + mc_io->portal_size = mc_portal_size; +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS ) +spin_lock_init (&mc_io->spinlock);I'm confused - this patseries doesn't register an interrupt handler, so this can't be true (or it's premature if it will, in which case it should be left out for now).
Quoted 10 lines
However, if somehow users of this code register an IRQ handler for the portal (I don't see any users to tell how they get the IRQ line either?), then it's up to them to establish mutual exclusion rules for access, among themselves. Unless you think they will be calling
mc_send_commandfrom h/w IRQ context, in which case I'd reconsider that assumption becausesend_commandlooks like it'd take too long to get an answer from the h/w - IRQ handlers should just ack the h/w IRQ, and notify the scheduler that the driver has work to do (in s/w IRQ context perhaps).Although not included in this patch series, there are cases in subsequent patch series, in which
mc_send_command()will need to be called from interrupt context.
Quoted 9 lines
Quoted 4 lines
For example, the
dprc_get_irq_status()needs to be called from the DPRC ISR to determine the actual cause of the interrupt. Also, to clear the interrupt thedprc_clear_irq_status()needs to be called from the ISR. Both od these functions callmc_send_command():yet
mc_send_commanditself has the capability to trigger a h/w IRQ, no? So how is that expected to work, given h/w IRQ handlers run with IRQs turned off?
"MC command completion" interrupts has not been implemented in the MC firmware, so sending a command to the MC does not currently trigger an interrupt by itself. I imagine that when "MC completion interrupts" get implemented, a flag will be available in the MC command header to indicate whether or not a "completion interrupt" is wanted. Different MC commands have different latencies. So, enabling generation
of completion interrupts, is something that should be done only
for long-latency MC commands. For low-latency MC commands commands,
(including those that can be called in interrupt context) such as inspecting interrupt status or clearing interrupts, polling for completion would be a more efficient choice.
Quoted 47 lines
Quoted 47 lines
Quoted 5 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 69
Quoted 2 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +2
-0+else if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) +mutex_init (&mc_io->mutex);I'd assume
SHARED_BY_THREADSto always be true in linux.Not, if
mc_send_command()is called from interrupt context, as explained above. However, since this patch series does not include any interrupt handlers, we can remove theFSL_MC_PORTAL_SHARED_BY_INT_HANDLERSflag and the associated spinlock, from this patch series.Quoted 36 lines
Quoted 21 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +21
-0+ res =devm_request_mem_region (dev, + mc_portal_phys_addr, + mc_portal_size, +"mc_portal" ); +if (res ==NULL ) { +dev_err (dev, +"devm_request_mem_region failed for MC portal %#llx\n" , + mc_portal_phys_addr); +return -EBUSY ; + } + + mc_portal_virt_addr =devm_ioremap_nocache (dev, + mc_portal_phys_addr, + mc_portal_size); +if (mc_portal_virt_addr ==NULL ) { +dev_err (dev, +"devm_ioremap_nocache failed for MC portal %#llx\n" , + mc_portal_phys_addr); +return -ENXIO ; + } +drivers/bus/fsl-mc/fsl_mc_sys.c line 101
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+ mc_io->portal_virt_addr = mc_portal_virt_addr; + *new_mc_io = mc_io; +return 0 ; +} +EXPORT_SYMBOL_GPL (fsl_create_mc_io); + +void fsl_destroy_mc_io (struct fsl_mc_io *mc_io) +{ +if (WARN_ON (mc_io->portal_virt_addr ==NULL )) +return ;this is unnecessary - you'll get the stack trace anyway, and users calling destroy on a not successfully created
mc_ioobject should not get the luxury of maybe being able to continue after the stack trace, after possibly leaking memory.
Quoted 5 lines
Quoted 1 line
Ok, I'ĺl remove this
WARN_ONin the v3 respin.subsequent code will cause a stack trace when dereferencing
portal_virt_addranyway, so the if statement isn't needed at all.
I meant to remove both the 'if' and the WARN_ON, as obviously keeping the 'if' without the WARN_ON is bad as it would silently hide a bug.
Quoted 11 lines
Quoted 7 lines
Quoted 6 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 109
Quoted 2 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +2
-0+ mc_io->portal_virt_addr =NULL ; +devm_kfree (mc_io->dev, mc_io);like I said before, there's really no point in clearing something out right before it's freed.
I disagree. This can help detect cases of double-freeing.
? freeing NULL does nothing - it just returns - which doesn't help detect anything. What's more, the kernel has a memory debugging infrastructure that detects double freeing of the same object.
I know that, but silently doing nothing when freeing NULL is a bad practice in general, because it hides a bug. Is the memory debugging infrastructure enabled by default? If so, then I would agree with you. If not, we would need to be able to reproduce the bug while having memory debugging enabled. This assumes that the bug is easy to
reproduce. What if it is not easy to reproduce?
Having "first-failure data capture" checks is useful for helping
diagnose bugs that are not easy to reproduce.
In this case, if due to some bug, fsl_destroy_mc_io() is called twice for the same mc_io object, the combination of doing "mc_io->portal_virt_addr = NULL" and the original "if (WARN_ON", that you want removed, would have helped catch the bug on "first failure".
Even removing the "if (WARN_ON)" but keeping the "mc_io->portal_virt_addr = NULL" would still help catch the bug on "first failure", assuming that the system crashes when calling "devm_iounmap(mc_io->dev, NULL);" or at least prints a stack trace.
Quoted 78 lines
Quoted 78 lines
Quoted 30 lines
Quoted 15 lines
+ * Delay in microseconds between polling iterations while
+ * waiting for MC command completion
+ */drivers/bus/fsl-mc/fsl_mc_sys.c new file +11
-0+#define MC_CMD_COMPLETION_POLLING_INTERVAL_USECS 500/* 0.5 ms */ + +int __must_check fsl_create_mc_io (struct device *dev, +phys_addr_t mc_portal_phys_addr, +uint32_t mc_portal_size, +uint32_t flags,struct fsl_mc_io **new_mc_io) +{ +struct fsl_mc_io *mc_io; +void __iomem *mc_portal_virt_addr; +struct resource *res; +drivers/bus/fsl-mc/fsl_mc_sys.c line 67
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+ mc_io =devm_kzalloc (dev,sizeof (*mc_io),GFP_KERNEL ); +if (mc_io ==NULL ) +return -ENOMEM ; + + mc_io->dev = dev; + mc_io->flags = flags; + mc_io->portal_phys_addr = mc_portal_phys_addr; + mc_io->portal_size = mc_portal_size; +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS ) +spin_lock_init (&mc_io->spinlock);I'm confused - this patseries doesn't register an interrupt handler, so this can't be true (or it's premature if it will, in which case it should be left out for now).
Quoted 10 lines
However, if somehow users of this code register an IRQ handler for the portal (I don't see any users to tell how they get the IRQ line either?), then it's up to them to establish mutual exclusion rules for access, among themselves. Unless you think they will be calling
mc_send_commandfrom h/w IRQ context, in which case I'd reconsider that assumption becausesend_commandlooks like it'd take too long to get an answer from the h/w - IRQ handlers should just ack the h/w IRQ, and notify the scheduler that the driver has work to do (in s/w IRQ context perhaps).Although not included in this patch series, there are cases in subsequent patch series, in which
mc_send_command()will need to be called from interrupt context.For example, the
dprc_get_irq_status()needs to be called from the DPRC ISR to determine the actual cause of the interrupt. Also, to clear the interrupt thedprc_clear_irq_status()needs to be called from the ISR. Both od these functions callmc_send_command():Quoted 29 lines
Quoted 9 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +9
-0+int mc_send_command (struct fsl_mc_io *mc_io,struct mc_command *cmd) +{ +enum mc_cmd_status status; +int error; +unsigned long irqsave_flags =0 ; +unsigned long jiffies_until_timeout = + jiffies +MC_CMD_COMPLETION_TIMEOUT_JIFFIES ; + +/* drivers/bus/fsl-mc/fsl_mc_sys.c line 153
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+* Acquire lock depending on mc_io flags: +*/ +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS ) { +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) +spin_lock_irqsave (&mc_io->spinlock, irqsave_flags); +else +spin_lock (&mc_io->spinlock); + }else if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) { +mutex_lock (&mc_io->mutex); + }again, I think we need to drop the coming from h/w IRQ context here (
SHARED_BY_INT_HANDLERS); there's no IRQ handlers in this patchseries, and calling this function from an IRQ handler would be prohibitively wasteful, guessing by the udelay and timeout values below.Can we just
mutex_lockfor now, and unconditionally (noSHARED_BY_THREADScheck), to protect from nesting?
Quoted 7 lines
Quoted 3 lines
I would still prefer to keep the
SHARED_BY_THREADSflag, to give option of not doing any locking, in cases where the portal used inmc_send_command()is not shared among concurrent callershow can you guarantee there won't be concurrent callers? The linux kernel is multithreaded.
The owner of the portal should know if his/her code can be invoked using the same portal, from multiple threads or not.
Quoted 24 lines
Quoted 1 line
What do you mean by nesting in this case?
when a thread gets interrupted by another thread, and/or another
IRQ: this would cause an unrecoverable race condition.Quoted 19 lines
Quoted 19 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 172
Quoted 13 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +13
-0+/* +* Wait for response from the MC hardware: +*/ +for (;;) { + status =mc_read_response (mc_io->portal_virt_addr, cmd); +if (status !=MC_CMD_STATUS_READY ) +break ; + +/* +* TODO: When MC command completion interrupts are supported +* call wait function here instead of udelay() +*/ +udelay (MC_CMD_COMPLETION_POLLING_INTERVAL_USECS );this pauses any caller for 0.5ms on every successful command write. Can the next submission of the patchseries wait until completion IRQs are indeed supported, since both that and the above locking needs to be resolved?
Quoted 8 lines
Quoted 2 lines
No. Interrupt handlers will come in a later patch series as they are not needed for using the basic MC functionality.
meanwhile unnecessarily udelaying kernel threads for .5ms upsets basic kernel functionality :) Would using the kernel's
wait_for_completionAPI be a good compromise here? Seeinclude/linux/completion.h.
The intent of doing the udelay() in the middle of the polling loop was to throttle down the frequency of I/Os done while polling for the completion of the command. Can you elaborate on why ".5ms udelay upsets
basic kernel functionality"?
Would it be better to just use "plain delay loop", instead of the udelay call, such as the following?
for (i = 0; i < 1000; i++)
;
I can see that in the cases where we use "completion interrupts", the ISR can signal the completion, and the polling loop can be replaced by waiting on the completion. However, I don't see how using a completion can help make a polling loop more efficient, if you don't have a "completion interrupt" to signal the completion.
Thanks,
German
Quoted 2 lines
Kim
Re: [PATCH 1/3 v2] drivers/bus: Added Freescale Management Complex APIs
Quoted 14 lines · German Rivera
Quoted 12 lines · Kim Phillips
Quoted 9 lines · On Wed, 24 Sep 2014 21:23:59 -0500 German Rivera <[email protected]>…
Quoted 8 lines · Kim Phillips
drivers/bus/fsl-mc/fsl_mc_sys.c line 109
Quoted 2 lines · On Fri, 19 Sep 2014 17:49:39 -0500 "J. German Rivera"…
drivers/bus/fsl-mc/fsl_mc_sys.c new file +2
-0+ mc_io->portal_virt_addr =NULL ; +devm_kfree (mc_io->dev, mc_io);like I said before, there's really no point in clearing something out right before it's freed.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
I disagree. This can help detect cases of double-freeing.
? freeing NULL does nothing - it just returns - which doesn't help detect anything. What's more, the kernel has a memory debugging infrastructure that detects double freeing of the same object.
I know that, but silently doing nothing when freeing NULL is a bad practice in general, because it hides a bug.
It doesn't hide a bug "in general". I'm not sure what the relevance is here, though -- this seems to be about reusing portal_virt_addr as a debug flag rather than anything to do with actually calling free() on portal_virt_addr.
Quoted 7 lines
Is the memory debugging infrastructure enabled by default? If so, then I would agree with you. If not, we would need to be able to reproduce the bug while having memory debugging enabled. This assumes that the bug is easy to reproduce. What if it is not easy to reproduce? Having "first-failure data capture" checks is useful for helping diagnose bugs that are not easy to reproduce.
Quoted 9 lines
In this case, if due to some bug,
fsl_destroy_mc_io()is called twice for the samemc_ioobject, the combination of doing "mc_io->portal_virt_addr= NULL" and the original "if (WARN_ON", that you want removed, would have helped catch the bug on "first failure".
Even removing the "if (WARN_ON)" but keeping the "mc_io->portal_virt_addr= NULL" would still help catch the bug on "first failure", assuming that the system crashes when calling "devm_iounmap(mc_io->dev, NULL);" or at least prints a stack trace.
iounmap of NULL will not crash or print a stack trace. It is a no-op.
Quoted 33 lines
Quoted 33 lines
Quoted 32 lines
Quoted 26 lines
Quoted 9 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +9
-0+int mc_send_command (struct fsl_mc_io *mc_io,struct mc_command *cmd) +{ +enum mc_cmd_status status; +int error; +unsigned long irqsave_flags =0 ; +unsigned long jiffies_until_timeout = + jiffies +MC_CMD_COMPLETION_TIMEOUT_JIFFIES ; + +/* drivers/bus/fsl-mc/fsl_mc_sys.c line 153
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+* Acquire lock depending on mc_io flags: +*/ +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS ) { +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) +spin_lock_irqsave (&mc_io->spinlock, irqsave_flags); +else +spin_lock (&mc_io->spinlock); + }else if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) { +mutex_lock (&mc_io->mutex); + }again, I think we need to drop the coming from h/w IRQ context here (
SHARED_BY_INT_HANDLERS); there's no IRQ handlers in this patchseries, and calling this function from an IRQ handler would be prohibitively wasteful, guessing by the udelay and timeout values below.Quoted 3 lines
Can we just
mutex_lockfor now, and unconditionally (noSHARED_BY_THREADScheck), to protect from nesting?I would still prefer to keep the
SHARED_BY_THREADSflag, to give option of not doing any locking, in cases where the portal used inmc_send_command()is not shared among concurrent callers
Quoted 5 lines
Quoted 3 lines
how can you guarantee there won't be concurrent callers? The linux kernel is multithreaded.
The owner of the portal should know if his/her code can be invoked using the same portal, from multiple threads or not.
Or more generally, whether the caller is responsible for synchronization.
Would it make sense to simplify by saying the caller is always responsible for synchronization?
Then again, the management complex is not supposed to be on the performance critical path, so why not simplify by just always do the locking here?
Quoted 27 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 172
Quoted 13 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +13
-0+/* +* Wait for response from the MC hardware: +*/ +for (;;) { + status =mc_read_response (mc_io->portal_virt_addr, cmd); +if (status !=MC_CMD_STATUS_READY ) +break ; + +/* +* TODO: When MC command completion interrupts are supported +* call wait function here instead of udelay() +*/ +udelay (MC_CMD_COMPLETION_POLLING_INTERVAL_USECS );this pauses any caller for 0.5ms on every successful command write. Can the next submission of the patchseries wait until completion IRQs are indeed supported, since both that and the above locking needs to be resolved?
Quoted 8 lines
Quoted 2 lines
No. Interrupt handlers will come in a later patch series as they are not needed for using the basic MC functionality.
meanwhile unnecessarily udelaying kernel threads for .5ms upsets basic kernel functionality :) Would using the kernel's
wait_for_completionAPI be a good compromise here? Seeinclude/linux/completion.h.
Quoted 4 lines
The intent of doing the
udelay()in the middle of the polling loop was to throttle down the frequency of I/Os done while polling for the completion of the command. Can you elaborate on why ".5ms udelay upsets basic kernel functionality"?
It introduces latency, especially since it's possible for it to happen with interrupts disabled. And you're actually potentially blocking for more than that, since 500us is just one iteration of the loop.
The jiffies test for exiting the loop is 500ms, which is *way* too long to spend in a critical section.
Quoted 5 lines
Would it be better to just use "plain delay loop", instead of the udelay call, such as the following?
for (i = 0; i < 1000; i++)
;
No, never do that. You have no idea how long it will actually take. GCC might even optimize it out entirely.
Quoted 5 lines
I can see that in the cases where we use "completion interrupts", the ISR can signal the completion, and the polling loop can be replaced by waiting on the completion. However, I don't see how using a completion can help make a polling loop more efficient, if you don't have a "completion interrupt" to signal the completion.
It's not about making it more efficient. It's about not causing problems for other things going on in the system.
-Scott
Re: [PATCH 1/3 v2] drivers/bus: Added Freescale Management Complex APIs
Quoted 45 lines · Scott Wood
Quoted 14 lines · German Rivera
Quoted 12 lines · Kim Phillips
Quoted 9 lines · On Wed, 24 Sep 2014 21:23:59 -0500 German Rivera <[email protected]>…
Quoted 8 lines · Kim Phillips
drivers/bus/fsl-mc/fsl_mc_sys.c line 109
Quoted 2 lines · On Fri, 19 Sep 2014 17:49:39 -0500 "J. German Rivera"…
drivers/bus/fsl-mc/fsl_mc_sys.c new file +2
-0+ mc_io->portal_virt_addr =NULL ; +devm_kfree (mc_io->dev, mc_io);like I said before, there's really no point in clearing something out right before it's freed.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
I disagree. This can help detect cases of double-freeing.
? freeing NULL does nothing - it just returns - which doesn't help detect anything. What's more, the kernel has a memory debugging infrastructure that detects double freeing of the same object.
I know that, but silently doing nothing when freeing NULL is a bad practice in general, because it hides a bug.
It doesn't hide a bug "in general". I'm not sure what the relevance is here, though -- this seems to be about reusing
portal_virt_addras a debug flag rather than anything to do with actually callingfree()onportal_virt_addr.Quoted 7 lines
Is the memory debugging infrastructure enabled by default? If so, then I would agree with you. If not, we would need to be able to reproduce the bug while having memory debugging enabled. This assumes that the bug is easy to reproduce. What if it is not easy to reproduce? Having "first-failure data capture" checks is useful for helping diagnose bugs that are not easy to reproduce.
Quoted 9 lines
In this case, if due to some bug,
fsl_destroy_mc_io()is called twice for the samemc_ioobject, the combination of doing "mc_io->portal_virt_addr= NULL" and the original "if (WARN_ON", that you want removed, would have helped catch the bug on "first failure".
Even removing the "if (WARN_ON)" but keeping the "mc_io->portal_virt_addr= NULL" would still help catch the bug on "first failure", assuming that the system crashes when calling "devm_iounmap(mc_io->dev, NULL);" or at least prints a stack trace.
Quoted 2 lines
iounmap of NULL will not crash or print a stack trace. It is a no-op.
Ok, so if iounmap silently does nothing for NULL, and free silently does
nothing for NULL, that means we may not be be able to easily catch "destroy double-call" bugs on first-failure, in this case. If that is not an issue, then I'll remove the "mc_io->portal_virt_addr = NULL" as well.
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 26 lines
Quoted 26 lines
Quoted 9 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +9
-0+int mc_send_command (struct fsl_mc_io *mc_io,struct mc_command *cmd) +{ +enum mc_cmd_status status; +int error; +unsigned long irqsave_flags =0 ; +unsigned long jiffies_until_timeout = + jiffies +MC_CMD_COMPLETION_TIMEOUT_JIFFIES ; + +/* drivers/bus/fsl-mc/fsl_mc_sys.c line 153
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +10
-0+* Acquire lock depending on mc_io flags: +*/ +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_INT_HANDLERS ) { +if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) +spin_lock_irqsave (&mc_io->spinlock, irqsave_flags); +else +spin_lock (&mc_io->spinlock); + }else if (mc_io->flags &FSL_MC_PORTAL_SHARED_BY_THREADS ) { +mutex_lock (&mc_io->mutex); + }again, I think we need to drop the coming from h/w IRQ context here (
SHARED_BY_INT_HANDLERS); there's no IRQ handlers in this patchseries, and calling this function from an IRQ handler would be prohibitively wasteful, guessing by the udelay and timeout values below.Quoted 6 lines
Quoted 3 lines
Can we just
mutex_lockfor now, and unconditionally (noSHARED_BY_THREADScheck), to protect from nesting?I would still prefer to keep the
SHARED_BY_THREADSflag, to give option of not doing any locking, in cases where the portal used inmc_send_command()is not shared among concurrent callershow can you guarantee there won't be concurrent callers? The linux kernel is multithreaded.
Quoted 9 lines
Quoted 2 lines
The owner of the portal should know if his/her code can be invoked using the same portal, from multiple threads or not.
Or more generally, whether the caller is responsible for synchronization.
Would it make sense to simplify by saying the caller is always responsible for synchronization?
Certainly this will simplify mc_send_command() but it will put the additional burden on all the callers of MC commands. If there is no objection, we can remove locking entirely from mc_send_command() and the the callers of MC commands deal with that.
Quoted 4 lines
Then again, the management complex is not supposed to be on the performance critical path, so why not simplify by just always do the locking here?
But about the few MC commands that need to run on interrupt context (such as to inspect or clear MC interrupts)?
Quoted 32 lines
Quoted 27 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
drivers/bus/fsl-mc/fsl_mc_sys.c line 172
Quoted 13 lines
drivers/bus/fsl-mc/fsl_mc_sys.c new file +13
-0+/* +* Wait for response from the MC hardware: +*/ +for (;;) { + status =mc_read_response (mc_io->portal_virt_addr, cmd); +if (status !=MC_CMD_STATUS_READY ) +break ; + +/* +* TODO: When MC command completion interrupts are supported +* call wait function here instead of udelay() +*/ +udelay (MC_CMD_COMPLETION_POLLING_INTERVAL_USECS );this pauses any caller for 0.5ms on every successful command write. Can the next submission of the patchseries wait until completion IRQs are indeed supported, since both that and the above locking needs to be resolved?
Quoted 8 lines
Quoted 2 lines
No. Interrupt handlers will come in a later patch series as they are not needed for using the basic MC functionality.
meanwhile unnecessarily udelaying kernel threads for .5ms upsets basic kernel functionality :) Would using the kernel's
wait_for_completionAPI be a good compromise here? Seeinclude/linux/completion.h.Quoted 4 lines
The intent of doing the
udelay()in the middle of the polling loop was to throttle down the frequency of I/Os done while polling for the completion of the command. Can you elaborate on why ".5ms udelay upsets basic kernel functionality"?
Quoted 7 lines
It introduces latency, especially since it's possible for it to happen with interrupts disabled. And you're actually potentially blocking for more than that, since 500us is just one iteration of the loop.
The jiffies test for exiting the loop is 500ms, which is *way* too long to spend in a critical section.
But that would be a worst case, since that is a timeout check. What timeout value do you think would be more appropriate in this case?
Quoted 9 lines
Quoted 5 lines
Would it be better to just use "plain delay loop", instead of the udelay call, such as the following?
for (i = 0; i < 1000; i++)
;No, never do that. You have no idea how long it will actually take. GCC might even optimize it out entirely.
Ok, so udelay is not good here, a plain vanilla delay loop is not good either. Are there other alternatives or we just don't worry about throttling down the frequency of I/Os done in the polling loop?
(Given the fact that MC commands are not expected to be executed that frequently, to frequently cause a lot of I/O traffic with this polling loop)
Quoted 9 lines
Quoted 5 lines
I can see that in the cases where we use "completion interrupts", the ISR can signal the completion, and the polling loop can be replaced by waiting on the completion. However, I don't see how using a completion can help make a polling loop more efficient, if you don't have a "completion interrupt" to signal the completion.
It's not about making it more efficient. It's about not causing problems for other things going on in the system.
But still I don't see how a completion can help here, unless you can signal the completion from an ISR.
-German
Re: [PATCH 1/3 v2] drivers/bus: Added Freescale Management Complex APIs
Quoted 7 lines · German Rivera
Quoted 4 lines · Scott Wood
Then again, the management complex is not supposed to be on the performance critical path, so why not simplify by just always do the locking here?
But about the few MC commands that need to run on interrupt context (such as to inspect or clear MC interrupts)?
I think that should be disallowed. Unless you can guarantee that the MC firmware will respond in a very short time, have those interrupts move their work into a workqueue, with the MC interrupt masked until completion. We do similar things for interrupts from i2c devices, etc.
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
The intent of doing the
udelay()in the middle of the polling loop was to throttle down the frequency of I/Os done while polling for the completion of the command. Can you elaborate on why ".5ms udelay upsets basic kernel functionality"?It introduces latency, especially since it's possible for it to happen with interrupts disabled. And you're actually potentially blocking for more than that, since 500us is just one iteration of the loop.
Quoted 5 lines
Quoted 3 lines
The jiffies test for exiting the loop is 500ms, which is *way* too long to spend in a critical section.
But that would be a worst case, since that is a timeout check. What timeout value do you think would be more appropriate in this case?
Worst case latency matters. Some workloads would be bothered by an occasional 500us. Even normal interactive use would notice 500ms.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Would it be better to just use "plain delay loop", instead of the udelay call, such as the following?
for (i = 0; i < 1000; i++)
;
Quoted 6 lines
Quoted 3 lines
No, never do that. You have no idea how long it will actually take. GCC might even optimize it out entirely.
Ok, so udelay is not good here, a plain vanilla delay loop is not good either. Are there other alternatives or we just don't worry about throttling down the frequency of I/Os done in the polling loop?
udelay is OK for this purpose, but not for so long, and find some way to make the kernel preemptible between loop iterations.
Quoted 9 lines
(Given the fact that MC commands are not expected to be executed that frequently, to frequently cause a lot of I/O traffic with this polling loop)
Quoted 6 lines
Quoted 5 lines
I can see that in the cases where we use "completion interrupts", the ISR can signal the completion, and the polling loop can be replaced by waiting on the completion. However, I don't see how using a completion can help make a polling loop more efficient, if you don't have a "completion interrupt" to signal the completion.
Quoted 5 lines
Quoted 3 lines
It's not about making it more efficient. It's about not causing problems for other things going on in the system.
But still I don't see how a completion can help here, unless you can signal the completion from an ISR.
Right, but you can still sleep on a timer instead of busy waiting if you need such a long timeout.
-Scott
PATCH v2 2/3 drivers/bus: Freescale Management Complex (fsl-mc) bus driver
In reply to J. German RiveraFrom: "J. German Rivera" <[email protected]>
Platform device driver that sets up the basic bus infrastructure for the fsl-mc bus type, including support for adding/removing fsl-mc devices, register/unregister of fsl-mc drivers, and bus match support to bind devices to drivers.
---
Changes in v2:
- Addressed comment from Joe Perches:
* Changed pr_debug to dev_dbg in fsl_mc_bus_match
- Addressed comments from Kim Phillips and Alex Graf:
* Changed version check to allow the driver to run with MC firmware that has major version number greater than or equal to the driver's major version number.
* Removed minor version check
- Removed unused variable parent_dev in fsl_mc_device_remove
drivers/bus/Kconfig | 3 + drivers/bus/Makefile | 3 + drivers/bus/fsl-mc/Kconfig | 13 + drivers/bus/fsl-mc/Makefile | 14 + drivers/bus/fsl-mc/fsl_mc_bus.c | 595 +++++++++++++++++++++++++++++++++++++++ include/linux/fsl_mc.h | 137 +++++++++ include/linux/fsl_mc_private.h | 33 +++ 7 files changed, 798 insertions(+) create mode 100644 drivers/bus/fsl-mc/Kconfig create mode 100644 drivers/bus/fsl-mc/Makefile create mode 100644 drivers/bus/fsl-mc/fsl_mc_bus.c create mode 100644 include/linux/fsl_mc.h create mode 100644 include/linux/fsl_mc_private.h
drivers/bus/Kconfig +3 -0
@@ -67,4 +67,7 @@ config VEXPRESS_CONFIG help Platform configuration infrastructure for the ARM Ltd. Versatile Express. + +source "drivers/bus/fsl-mc/Kconfig" + endmenu
drivers/bus/Makefile +3 -0
@@ -15,3 +15,6 @@ obj-$(CONFIG_ARM_CCI) += arm-cci.o obj-$(CONFIG_ARM_CCN) += arm-ccn.o obj-$(CONFIG_VEXPRESS_CONFIG) += vexpress-config.o + +# Freescale Management Complex (MC) bus drivers +obj-$(CONFIG_FSL_MC_BUS) += fsl-mc/
drivers/bus/fsl-mc/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ +# +# Freescale Management Complex (MC) bus drivers +# +# Copyright (C) 2014 Freescale Semiconductor, Inc. +# +# This file is released under the GPLv2 +# + +config FSL_MC_BUS + tristate "Freescale Management Complex (MC) bus driver" + help + Driver to enable the bus infrastructure for the Freescale + QorIQ Management Complex.
drivers/bus/fsl-mc/Makefile new file +14 -0
@@ -0,0 +1,14 @@ +# +# Freescale Management Complex (MC) bus drivers +# +# Copyright (C) 2014 Freescale Semiconductor, Inc. +# +# This file is released under the GPLv2 +# +obj-$(CONFIG_FSL_MC_BUS) += fsl_mc_bus_driver.o + +fsl_mc_bus_driver-objs := fsl_mc_bus.o \ + fsl_mc_sys.o \ + dprc.o \ + dpmng.o +
drivers/bus/fsl-mc/fsl_mc_bus.c new file +595 -0
595 lines not on this page · raw message
include/linux/fsl_mc.h new file +137 -0
137 lines not on this page · raw message
include/linux/fsl_mc_private.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Freescale Management Complex (MC) bus private declarations +* +* Copyright (C) 2014 Freescale Semiconductor, Inc. +* Author: German Rivera <[email protected]> +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ +#ifndef _FSL_MC_PRIVATE_H_ +#define _FSL_MC_PRIVATE_H_ + +#include <linux/fsl_mc.h> +#include <linux/mutex.h> +#include <linux/stringify.h> + +#define FSL_MC_DEVICE_MATCH (_mc_dev, _obj_desc) \ + (strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \ + (_mc_dev)->obj_desc.id == (_obj_desc)->id) + +#define FSL_MC_IS_ALLOCATABLE (_obj_type) \ + (strcmp(_obj_type, "dpbp") == 0 || \ + strcmp(_obj_type, "dpcon") == 0) + +int __must_check fsl_mc_device_add (struct dprc_obj_desc *obj_desc, +struct fsl_mc_io *mc_io, +struct device *parent_dev, +struct fsl_mc_device **new_mc_dev); + +void fsl_mc_device_remove (struct fsl_mc_device *mc_dev); + +#endif /* _FSL_MC_PRIVATE_H_ */
--
1.7.9.7
PATCH v2 3/3 drivers/bus: Device driver for FSL-MC DPRC devices
In reply to J. German RiveraFrom: "J. German Rivera" <[email protected]>
A DPRC (Data Path Resource Container) is an isolation device that contains a set of DPAA networking devices to be assigned to an isolation domain (e.g., a virtual machine).
---
Changes in v2:
- Addressed comments from Kim Phillips:
* Fix warning in drivers/bus/fsl-mc/fsl_mc_dprc.c:173
* Fixed linker errors when MC bus driver built as module
drivers/bus/fsl-mc/Makefile | 11 +- drivers/bus/fsl-mc/fsl_mc_bus.c | 10 + drivers/bus/fsl-mc/fsl_mc_dprc.c | 402 ++++++++++++++++++++++++++++++++++++++ include/linux/fsl_mc_private.h | 10 + 4 files changed, 428 insertions(+), 5 deletions(-) create mode 100644 drivers/bus/fsl-mc/fsl_mc_dprc.c
drivers/bus/fsl-mc/Makefile +6 -5
@@ -5,10 +5,11 @@ # # This file is released under the GPLv2 # -obj-$(CONFIG_FSL_MC_BUS) += fsl_mc_bus_driver.o +obj-$(CONFIG_FSL_MC_BUS) += fsl_mc_bus_driver.o \ -fsl_mc_bus_driver-objs := fsl_mc_bus.o \ - fsl_mc_sys.o \ - dprc.o \ - dpmng.o +fsl_mc_bus_driver-objs := fsl_mc_bus.o \ + fsl_mc_sys.o \ + dprc.o \ + dpmng.o \ + fsl_mc_dprc.o
drivers/bus/fsl-mc/fsl_mc_bus.c +10 -0
@@ -539,6 +539,7 @@ static int __init fsl_mc_bus_driver_init(void) {int error = -EINVAL ;bool bus_registered = false; +bool platform_driver_registered = false; mc_dev_cache = kmem_cache_create("fsl_mc_device", sizeof(struct fsl_mc_device), 0, 0,
@@ -564,8 +565,16 @@ static int __init fsl_mc_bus_driver_init(void) goto error; } + platform_driver_registered = true; + error =dprc_driver_init (); +if (error <0 ) + goto error; +return 0 ; error: +if (platform_driver_registered) +platform_driver_unregister (&fsl_mc_bus_driver); +if (bus_registered)bus_unregister (&fsl_mc_bus_type);
@@ -582,6 +591,7 @@ static void __exit fsl_mc_bus_driver_exit(void)if (WARN_ON (mc_dev_cache ==NULL ))return ; +dprc_driver_exit ();platform_driver_unregister (&fsl_mc_bus_driver);bus_unregister (&fsl_mc_bus_type);kmem_cache_destroy (mc_dev_cache);
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +402 -0
402 lines not on this page · raw message
include/linux/fsl_mc_private.h +10 -0
@@ -15,6 +15,8 @@#include <linux/mutex.h> #include <linux/stringify.h> +#define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc" +#define FSL_MC_DEVICE_MATCH (_mc_dev, _obj_desc) \ (strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \ (_mc_dev)->obj_desc.id == (_obj_desc)->id)
@@ -30,4 +32,12 @@ int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,void fsl_mc_device_remove (struct fsl_mc_device *mc_dev); +int __must_check dprc_scan_container (struct fsl_mc_device *mc_bus_dev); + +int __must_check dprc_scan_objects (struct fsl_mc_device *mc_bus_dev); + +int __init dprc_driver_init (void ); + +void __exit dprc_driver_exit(void); +#endif /* _FSL_MC_PRIVATE_H_ */
--
1.7.9.7
Re: [PATCH 3/3 v2] drivers/bus: Device driver for FSL-MC DPRC devices
drivers/bus/fsl-mc/fsl_mc_dprc.c line 51
Quoted 4 lines · J. German Rivera
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +4
-0+static int __fsl_mc_device_remove (struct device *dev,void *data) +{ +WARN_ON (dev ==NULL ); +WARN_ON (data !=NULL );
I see a lot of direct comparisons with NULL and 0. You don't need to be so explicit:
WARN_ON(!dev);WARN_ON(!data);
"!= 0" and "!= NULL" is almost always unnecessary, and you can delete them.
Quoted 11 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +11
-0+fsl_mc_device_remove (to_fsl_mc_device (dev)); +return 0 ; +} + +/** +* dprc_remove_devices - Removes devices for objects removed from a DPRC +* +* @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object +* @obj_desc_array: array of object descriptors for child objects currently +* present in the DPRC in the MC. +* @num_child_objects_in_mc: number of entries in obj_desc_array
drivers/bus/fsl-mc/fsl_mc_dprc.c line 72
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+* +* Synchronizes the state of the Linux bus driver with the actual state of +* the MC by removing devices that represent MC objects that have +* been dynamically removed in the physical DPRC. +*/ +static void dprc_remove_devices (struct fsl_mc_device *mc_bus_dev, +struct dprc_obj_desc *obj_desc_array, +int num_child_objects_in_mc) +{ +if (num_child_objects_in_mc !=0 ) {
Like here. Just do "if (num_child_objects_in_mc) {"
Quoted 29 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +29
-0+/* +* Remove child objects that are in the DPRC in Linux, +* but not in the MC: +*/ +struct dprc_child_objs objs; + + objs.child_count = num_child_objects_in_mc; + objs.child_array = obj_desc_array; +device_for_each_child (&mc_bus_dev->dev, &objs, + __fsl_mc_device_remove_if_not_in_mc); + }else { +/* +* There are no child objects for this DPRC in the MC. +* So, remove all the child devices from Linux: +*/ +device_for_each_child (&mc_bus_dev->dev,NULL , + __fsl_mc_device_remove); + } +} + +static int __fsl_mc_device_match (struct device *dev,void *data) +{ +struct dprc_obj_desc *obj_desc = data; +struct fsl_mc_device *mc_dev =to_fsl_mc_device (dev); + +return FSL_MC_DEVICE_MATCH (mc_dev, obj_desc); +} + +static struct fsl_mc_device *fsl_mc_device_lookup(struct dprc_obj_desc
drivers/bus/fsl-mc/fsl_mc_dprc.c line 111
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+ *obj_desc, +struct fsl_mc_device + *mc_bus_dev) +{ +struct device *dev; + + dev =device_find_child (&mc_bus_dev->dev, obj_desc, + __fsl_mc_device_match); + +return (dev !=NULL ) ?to_fsl_mc_device (dev) :NULL ;
return dev ? to_fsl_mc_device(dev) : NULL;
Quoted 27 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +27
-0+} + +/** +* dprc_add_new_devices - Adds devices to the logical bus for a DPRC +* +* @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object +* @obj_desc_array: array of device descriptors for child devices currently +* present in the physical DPRC. +* @num_child_objects_in_mc: number of entries in obj_desc_array +* +* Synchronizes the state of the Linux bus driver with the actual +* state of the MC by adding objects that have been newly discovered +* in the physical DPRC. +*/ +static void dprc_add_new_devices (struct fsl_mc_device *mc_bus_dev, +struct dprc_obj_desc *obj_desc_array, +int num_child_objects_in_mc) +{ +int error; +int i; + +for (i =0 ; i < num_child_objects_in_mc; i++) { +struct dprc_region_desc region_desc; +struct fsl_mc_device *child_dev; +struct fsl_mc_io *mc_io =NULL ; +struct dprc_obj_desc *obj_desc = &obj_desc_array[i]; +
drivers/bus/fsl-mc/fsl_mc_dprc.c line 148
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+if (strlen (obj_desc->type) ==0 ) +continue ; +/* +* Check if device is already known to Linux: +*/ + child_dev =fsl_mc_device_lookup (obj_desc, mc_bus_dev); +if (child_dev !=NULL ) +continue ; + +if (strcmp (obj_desc->type,"dprc" ) ==0 ) {
As for the !=0 thing, I make an exception for strcmp(), however, since its meaning is not intuitive.
Quoted 122 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +122
-0+/* +* Get the MC portal physical address for the device +* (specified in the device's first MMIO region): +*/ +if (WARN_ON (obj_desc->region_count ==0 )) +continue ; + + error =dprc_get_obj_region (mc_bus_dev->mc_io, + mc_bus_dev->mc_handle, + obj_desc->type, + obj_desc->id, +0 , ®ion_desc); +if (error <0 ) { +dev_err (&mc_bus_dev->dev, +"dprc_get_obj_region() failed: %d\n" , + error); +continue ; + } + +if (region_desc.size != + mc_bus_dev->mc_io->portal_size) { + error = -EINVAL ; +dev_err (&mc_bus_dev->dev, +"Invalid MC portal size: %u\n" , + region_desc.size); +continue ; + } + + error =fsl_create_mc_io (&mc_bus_dev->dev, + region_desc.base_paddr, + region_desc.size,0 , &mc_io); +if (error <0 ) +continue ; + } + + error =fsl_mc_device_add (obj_desc, mc_io, &mc_bus_dev->dev, + &child_dev); +if (error <0 ) { +if (mc_io !=NULL ) +fsl_destroy_mc_io (mc_io); + +continue ; + } + } +} + +/** +* dprc_scan_objects - Discover objects in a DPRC +* +* @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object +* +* Detects objects added and removed from a DPRC and synchronizes the +* state of the Linux bus driver, MC by adding and removing +* devices accordingly. +*/ +int dprc_scan_objects (struct fsl_mc_device *mc_bus_dev) +{ +int num_child_objects; +int dprc_get_obj_failures; +int error = -EINVAL ; +struct dprc_obj_desc *child_obj_desc_array =NULL ; + + error =dprc_get_obj_count (mc_bus_dev->mc_io, + mc_bus_dev->mc_handle, + &num_child_objects); +if (error <0 ) { +dev_err (&mc_bus_dev->dev,"dprc_get_obj_count() failed: %d\n" , + error); + goto out; + } + +if (num_child_objects !=0 ) { +int i; + + child_obj_desc_array = +devm_kmalloc_array (&mc_bus_dev->dev, num_child_objects, +sizeof (*child_obj_desc_array), +GFP_KERNEL ); +if (child_obj_desc_array ==NULL ) { + error = -ENOMEM ; +dev_err (&mc_bus_dev->dev, +"No memory to allocate obj_desc array\n" ); + goto out; + } + +/* +* Discover objects currently present in the physical DPRC: +*/ + dprc_get_obj_failures =0 ; +for (i =0 ; i < num_child_objects; i++) { +struct dprc_obj_desc *obj_desc = + &child_obj_desc_array[i]; + + error =dprc_get_obj (mc_bus_dev->mc_io, + mc_bus_dev->mc_handle, + i, obj_desc); +if (error <0 ) { +dev_err (&mc_bus_dev->dev, +"dprc_get_obj(i=%d) failed: %d\n" , + i, error); +/* +* Mark the obj entry as "invalid", by using the +* empty string as obj type: +*/ + obj_desc->type[0 ] ='\0' ; + obj_desc->id = error; + dprc_get_obj_failures++; +continue ; + } + +dev_info (&mc_bus_dev->dev, +"Discovered object: type %s, id %d\n" , + obj_desc->type, obj_desc->id); + } + +if (dprc_get_obj_failures !=0 ) { +dev_err (&mc_bus_dev->dev, +"%d out of %d devices could not be retrieved\n" , + dprc_get_obj_failures, num_child_objects); + } + } +
drivers/bus/fsl-mc/fsl_mc_dprc.c line 280
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+dprc_remove_devices (mc_bus_dev, child_obj_desc_array, + num_child_objects); + +dprc_add_new_devices (mc_bus_dev, child_obj_desc_array, + num_child_objects); + + error =0 ; +out: +if (child_obj_desc_array !=NULL ) +devm_kfree (&mc_bus_dev->dev, child_obj_desc_array);
The whole point behind the devm_ functions is that you shoudn't need to manually release the resources.
Quoted 16 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +16
-0+ +return error; +} +EXPORT_SYMBOL_GPL (dprc_scan_objects); + +/** +* dprc_scan_container - Scans a physical DPRC and synchronizes Linux bus state +* +* @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object +* +* Scans the physical DPRC and synchronizes the state of the Linux +* bus driver with the actual state of the MC by adding and removing +* devices as appropriate. +*/ +int dprc_scan_container (struct fsl_mc_device *mc_bus_dev) +{
drivers/bus/fsl-mc/fsl_mc_dprc.c line 306
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+int error = -EINVAL ; + + error =dprc_scan_objects (mc_bus_dev); +if (error <0 ) + goto error; + +return 0 ; +error: +return error; +}
This is silly.
int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
{
return dprc_scan_objects(mc_bus_dev);
}Quoted 7 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +7
-0+EXPORT_SYMBOL_GPL (dprc_scan_container); + +/** +* dprc_probe - callback invoked when a DPRC is being bound to this driver +* +* @mc_dev: Pointer to fsl-mc device representing a DPRC +*
drivers/bus/fsl-mc/fsl_mc_dprc.c line 323
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+* It opens the physical DPRC in the MC. +* It scans the DPRC to discover the MC objects contained in it. +*/ +static int dprc_probe (struct fsl_mc_device *mc_dev) +{ +int error = -EINVAL ; +bool dprc_opened = false; + +if (WARN_ON (strcmp (mc_dev->obj_desc.type,"dprc" ) !=0 )) + goto error;
Just 'return' here. And if you're creative, I think you can get rid
of dprc_opened. You can have multiple exit labels for gotos. Try to avoid using booleans to tell you at the end of the function whether you succeeded. That's not how kernel code is normally written.
Quoted 39 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +39
-0+ + error =dprc_open (mc_dev->mc_io, mc_dev->obj_desc.id, + &mc_dev->mc_handle); +if (error <0 ) { +dev_err (&mc_dev->dev,"dprc_open() failed: %d\n" , error); + goto error; + } + + dprc_opened = true; + error =dprc_scan_container (mc_dev); +if (error <0 ) + goto error; + +dev_info (&mc_dev->dev,"DPRC device bound to driver" ); +return 0 ; +error: +if (dprc_opened) + (void )dprc_close (mc_dev->mc_io, mc_dev->mc_handle); + +return error; +} + +/** +* dprc_remove - callback invoked when a DPRC is being unbound from this driver +* +* @mc_dev: Pointer to fsl-mc device representing the DPRC +* +* It removes the DPRC's child objects from Linux (not from the MC) and +* closes the DPRC device in the MC. +*/ +static int dprc_remove (struct fsl_mc_device *mc_dev) +{ +int error = -EINVAL ; + +if (WARN_ON (strcmp (mc_dev->obj_desc.type,"dprc" ) !=0 )) + goto error; +if (WARN_ON (mc_dev->mc_io ==NULL )) + goto error; +
drivers/bus/fsl-mc/fsl_mc_dprc.c line 372
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+device_for_each_child (&mc_dev->dev,NULL , __fsl_mc_device_remove); + error =dprc_close (mc_dev->mc_io, mc_dev->mc_handle); +if (error <0 ) +dev_err (&mc_dev->dev,"dprc_close() failed: %d\n" , error); + +dev_info (&mc_dev->dev,"DPRC device unbound from driver" ); +return 0 ; +error: +return error; +}
Try this:
static int dprc_remove(struct fsl_mc_device *mc_dev)
{
int error;
if (WARN_ON(strcmp(mc_dev->obj_desc.type, "dprc") != 0))
return -EINVAL;
if (WARN_ON(mc_dev->mc_io == NULL))
return -EINVAL;
device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove);
error = dprc_close(mc_dev->mc_io, mc_dev->mc_handle);
if (error < 0) {
dev_err(&mc_dev->dev, "dprc_close() failed: %d\n", error);
return error;
}
dev_dbg(&mc_dev->dev, "DPRC device unbound from driver");
return 0;
}Quoted 44 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +30
-0+ +static const struct fsl_mc_device_match_id match_id_table[] = { + { + .vendor =FSL_MC_VENDOR_FREESCALE , + .obj_type ="dprc" , + .ver_major =DPRC_VER_MAJOR , + .ver_minor =DPRC_VER_MINOR }, + {.vendor =0x0 }, +}; + +static struct fsl_mc_driver dprc_driver = { + .driver = { + .name =FSL_MC_DPRC_DRIVER_NAME , + .owner =THIS_MODULE , + .pm =NULL , + }, + .match_id_table = match_id_table, + .probe = dprc_probe, + .remove = dprc_remove, +}; + +int __init dprc_driver_init (void ) +{ +return fsl_mc_driver_register (&dprc_driver); +} + +void __exit dprc_driver_exit(void) +{ +fsl_mc_driver_unregister (&dprc_driver); +}include/linux/fsl_mc_private.h +2
-0@@ -15,6 +15,8 @@#include <linux/mutex.h> #include <linux/stringify.h> +#define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc" +#define FSL_MC_DEVICE_MATCH (_mc_dev, _obj_desc) \ (strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \ (_mc_dev)->obj_desc.id == (_obj_desc)->id)
include/linux/fsl_mc_private.h int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc, · line 37
Quoted 6 lines
include/linux/fsl_mc_private.h +3
-0@@ -30,4 +32,12 @@ int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,void fsl_mc_device_remove (struct fsl_mc_device *mc_dev); +int __must_check dprc_scan_container (struct fsl_mc_device *mc_bus_dev); + +int __must_check dprc_scan_objects (struct fsl_mc_device *mc_bus_dev);
__must_check? Really?
Re: [PATCH 3/3 v2] drivers/bus: Device driver for FSL-MC DPRC devices
Quoted 13 lines · Timur Tabi
Quoted 11 lines · J. German Rivera
+/**
+ *dprc_remove_devices- Removes devices for objects removed from a DPRC
+ *
+ * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
+ * @obj_desc_array: array of object descriptors for child objects currently
+ * present in the DPRC in the MC.
+ * @num_child_objects_in_mc: number of entries inobj_desc_array
+ *
+ * Synchronizes the state of the Linux bus driver with the actual state of
+ * the MC by removing devices that represent MC objects that have
+ * been dynamically removed in the physical DPRC.
Quoted 8 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c line 72
Quoted 6 lines
+ */
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +5
-0+static void dprc_remove_devices (struct fsl_mc_device *mc_bus_dev, +struct dprc_obj_desc *obj_desc_array, +int num_child_objects_in_mc) +{ +if (num_child_objects_in_mc !=0 ) {Like here. Just do "if (
num_child_objects_in_mc) {"
This seems to be a place that is testing for zero as a value rather than as a stand-in for NULL, so I'd argue it's better style to leave it as is.
-Scott
Re: [PATCH 3/3 v2] drivers/bus: Device driver for FSL-MC DPRC devices
Quoted 7 lines · Scott Wood
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
+ if (
num_child_objects_in_mc!= 0) {Like here. Just do "if (
num_child_objects_in_mc) {"This seems to be a place that is testing for zero as a value rather than as a stand-in for NULL, so I'd argue it's better style to leave it as is.
But in this case, zero means "none left", so this is a perfectly valid use-case for omitting the !=.
strcmp() is the only time I can think of to put an explicit != 0, because this:
if (!strcmp(s1, s2))
is counter-intuitive.
Re: [PATCH 3/3 v2] drivers/bus: Device driver for FSL-MC DPRC devices
In reply to Timur TabiQuoted 11 lines · Timur Tabi
drivers/bus/fsl-mc/fsl_mc_dprc.c line 51
Quoted 4 lines · J. German Rivera
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +4
-0+static int __fsl_mc_device_remove (struct device *dev,void *data) +{ +WARN_ON (dev ==NULL ); +WARN_ON (data !=NULL );I see a lot of direct comparisons with NULL and 0. You don't need to be so explicit:
Quoted 5 lines
WARN_ON(!dev);WARN_ON(!data);"!= 0" and "!= NULL" is almost always unnecessary, and you can delete them.
I know that this is not necessary from the point of view of C boolean semantics, but doing explicit comparison improves readability IMHO. Anyway, this is subjective and largely a matter of preference. Besides, "Documentation/CodingStyle" does not seem to advocate one way or the other.
Also, I there is evidence that explicit comparisons are allowed in
the kernel source tree:
$ git grep '== NULL' | wc -l 22173 $ git grep '!= NULL' | wc -l 9987 $ git grep '!= 0' | wc -l 22993 $ git grep '== 0' | wc -l 46060
So, unless Greg Kroah-Hartman or Arnd Bergmann feel strongly that I need to make this change, I will not make it.
Quoted 235 lines
Quoted 12 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +11
-0+fsl_mc_device_remove (to_fsl_mc_device (dev)); +return 0 ; +} + +/** +* dprc_remove_devices - Removes devices for objects removed from a DPRC +* +* @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object +* @obj_desc_array: array of object descriptors for child objects currently +* present in the DPRC in the MC. +* @num_child_objects_in_mc: number of entries in obj_desc_array drivers/bus/fsl-mc/fsl_mc_dprc.c line 72
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+* +* Synchronizes the state of the Linux bus driver with the actual state of +* the MC by removing devices that represent MC objects that have +* been dynamically removed in the physical DPRC. +*/ +static void dprc_remove_devices (struct fsl_mc_device *mc_bus_dev, +struct dprc_obj_desc *obj_desc_array, +int num_child_objects_in_mc) +{ +if (num_child_objects_in_mc !=0 ) {Like here. Just do "if (
num_child_objects_in_mc) {"Quoted 29 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +29
-0+/* +* Remove child objects that are in the DPRC in Linux, +* but not in the MC: +*/ +struct dprc_child_objs objs; + + objs.child_count = num_child_objects_in_mc; + objs.child_array = obj_desc_array; +device_for_each_child (&mc_bus_dev->dev, &objs, + __fsl_mc_device_remove_if_not_in_mc); + }else { +/* +* There are no child objects for this DPRC in the MC. +* So, remove all the child devices from Linux: +*/ +device_for_each_child (&mc_bus_dev->dev,NULL , + __fsl_mc_device_remove); + } +} + +static int __fsl_mc_device_match (struct device *dev,void *data) +{ +struct dprc_obj_desc *obj_desc = data; +struct fsl_mc_device *mc_dev =to_fsl_mc_device (dev); + +return FSL_MC_DEVICE_MATCH (mc_dev, obj_desc); +} + +static struct fsl_mc_device *fsl_mc_device_lookup(struct dprc_obj_descdrivers/bus/fsl-mc/fsl_mc_dprc.c line 111
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+ *obj_desc, +struct fsl_mc_device + *mc_bus_dev) +{ +struct device *dev; + + dev =device_find_child (&mc_bus_dev->dev, obj_desc, + __fsl_mc_device_match); + +return (dev !=NULL ) ?to_fsl_mc_device (dev) :NULL ;return dev ?
to_fsl_mc_device(dev): NULL;Quoted 27 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +27
-0+} + +/** +* dprc_add_new_devices - Adds devices to the logical bus for a DPRC +* +* @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object +* @obj_desc_array: array of device descriptors for child devices currently +* present in the physical DPRC. +* @num_child_objects_in_mc: number of entries in obj_desc_array +* +* Synchronizes the state of the Linux bus driver with the actual +* state of the MC by adding objects that have been newly discovered +* in the physical DPRC. +*/ +static void dprc_add_new_devices (struct fsl_mc_device *mc_bus_dev, +struct dprc_obj_desc *obj_desc_array, +int num_child_objects_in_mc) +{ +int error; +int i; + +for (i =0 ; i < num_child_objects_in_mc; i++) { +struct dprc_region_desc region_desc; +struct fsl_mc_device *child_dev; +struct fsl_mc_io *mc_io =NULL ; +struct dprc_obj_desc *obj_desc = &obj_desc_array[i]; +drivers/bus/fsl-mc/fsl_mc_dprc.c line 148
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+if (strlen (obj_desc->type) ==0 ) +continue ; +/* +* Check if device is already known to Linux: +*/ + child_dev =fsl_mc_device_lookup (obj_desc, mc_bus_dev); +if (child_dev !=NULL ) +continue ; + +if (strcmp (obj_desc->type,"dprc" ) ==0 ) {As for the !=0 thing, I make an exception for
strcmp(), however, since its meaning is not intuitive.Quoted 127 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +127
-0+/* +* Get the MC portal physical address for the device +* (specified in the device's first MMIO region): +*/ +if (WARN_ON (obj_desc->region_count ==0 )) +continue ; + + error =dprc_get_obj_region (mc_bus_dev->mc_io, + mc_bus_dev->mc_handle, + obj_desc->type, + obj_desc->id, +0 , ®ion_desc); +if (error <0 ) { +dev_err (&mc_bus_dev->dev, +"dprc_get_obj_region() failed: %d\n" , + error); +continue ; + } + +if (region_desc.size != + mc_bus_dev->mc_io->portal_size) { + error = -EINVAL ; +dev_err (&mc_bus_dev->dev, +"Invalid MC portal size: %u\n" , + region_desc.size); +continue ; + } + + error =fsl_create_mc_io (&mc_bus_dev->dev, + region_desc.base_paddr, + region_desc.size,0 , &mc_io); +if (error <0 ) +continue ; + } + + error =fsl_mc_device_add (obj_desc, mc_io, &mc_bus_dev->dev, + &child_dev); +if (error <0 ) { +if (mc_io !=NULL ) +fsl_destroy_mc_io (mc_io); + +continue ; + } + } +} + +/** +* dprc_scan_objects - Discover objects in a DPRC +* +* @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object +* +* Detects objects added and removed from a DPRC and synchronizes the +* state of the Linux bus driver, MC by adding and removing +* devices accordingly. +*/ +int dprc_scan_objects (struct fsl_mc_device *mc_bus_dev) +{ +int num_child_objects; +int dprc_get_obj_failures; +int error = -EINVAL ; +struct dprc_obj_desc *child_obj_desc_array =NULL ; + + error =dprc_get_obj_count (mc_bus_dev->mc_io, + mc_bus_dev->mc_handle, + &num_child_objects); +if (error <0 ) { +dev_err (&mc_bus_dev->dev,"dprc_get_obj_count() failed: %d\n" , + error); + goto out; + } + +if (num_child_objects !=0 ) { +int i; + + child_obj_desc_array = +devm_kmalloc_array (&mc_bus_dev->dev, num_child_objects, +sizeof (*child_obj_desc_array), +GFP_KERNEL ); +if (child_obj_desc_array ==NULL ) { + error = -ENOMEM ; +dev_err (&mc_bus_dev->dev, +"No memory to allocate obj_desc array\n" ); + goto out; + } + +/* +* Discover objects currently present in the physical DPRC: +*/ + dprc_get_obj_failures =0 ; +for (i =0 ; i < num_child_objects; i++) { +struct dprc_obj_desc *obj_desc = + &child_obj_desc_array[i]; + + error =dprc_get_obj (mc_bus_dev->mc_io, + mc_bus_dev->mc_handle, + i, obj_desc); +if (error <0 ) { +dev_err (&mc_bus_dev->dev, +"dprc_get_obj(i=%d) failed: %d\n" , + i, error); +/* +* Mark the obj entry as "invalid", by using the +* empty string as obj type: +*/ + obj_desc->type[0 ] ='\0' ; + obj_desc->id = error; + dprc_get_obj_failures++; +continue ; + } + +dev_info (&mc_bus_dev->dev, +"Discovered object: type %s, id %d\n" , + obj_desc->type, obj_desc->id); + } + +if (dprc_get_obj_failures !=0 ) { +dev_err (&mc_bus_dev->dev, +"%d out of %d devices could not be retrieved\n" , + dprc_get_obj_failures, num_child_objects); + } + } + +dprc_remove_devices (mc_bus_dev, child_obj_desc_array, + num_child_objects); + +dprc_add_new_devices (mc_bus_dev, child_obj_desc_array, + num_child_objects);
Quoted 9 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c line 280
Quoted 5 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +5
-0+ + error =0 ; +out: +if (child_obj_desc_array !=NULL ) +devm_kfree (&mc_bus_dev->dev, child_obj_desc_array);The whole point behind the
devm_functions is that you shoudn't need to manually release the resources.
Yes, but wouldn't the implicit/automatic freeing only happens when the device itself is removed?
The function above may get invoked many times before the device gets removed. So, we would just keep accumulating wasted memory in the meantime.
Quoted 29 lines
Quoted 16 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +16
-0+ +return error; +} +EXPORT_SYMBOL_GPL (dprc_scan_objects); + +/** +* dprc_scan_container - Scans a physical DPRC and synchronizes Linux bus state +* +* @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object +* +* Scans the physical DPRC and synchronizes the state of the Linux +* bus driver with the actual state of the MC by adding and removing +* devices as appropriate. +*/ +int dprc_scan_container (struct fsl_mc_device *mc_bus_dev) +{drivers/bus/fsl-mc/fsl_mc_dprc.c line 306
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+int error = -EINVAL ; + + error =dprc_scan_objects (mc_bus_dev); +if (error <0 ) + goto error; + +return 0 ; +error: +return error; +}This is silly.
Quoted 5 lines
int
dprc_scan_container(struct fsl_mc_device *mc_bus_dev){ return dprc_scan_objects(mc_bus_dev); }
Agreed. I'll simplify this.
Quoted 15 lines
Quoted 15 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +14
-0+EXPORT_SYMBOL_GPL (dprc_scan_container); + +/** +* dprc_probe - callback invoked when a DPRC is being bound to this driver +* +* @mc_dev: Pointer to fsl-mc device representing a DPRC +* +* It opens the physical DPRC in the MC. +* It scans the DPRC to discover the MC objects contained in it. +*/ +static int dprc_probe (struct fsl_mc_device *mc_dev) +{ +int error = -EINVAL ; +bool dprc_opened = false;
Quoted 9 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c line 323
Quoted 3 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +3
-0+ +if (WARN_ON (strcmp (mc_dev->obj_desc.type,"dprc" ) !=0 )) + goto error;Just 'return' here. And if you're creative, I think you can get rid
ofdprc_opened. You can have multiple exit labels for gotos. Try to avoid using booleans to tell you at the end of the function whether you succeeded. That's not how kernel code is normally written.
OK, I will make this change.
Quoted 65 lines
Quoted 39 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +39
-0+ + error =dprc_open (mc_dev->mc_io, mc_dev->obj_desc.id, + &mc_dev->mc_handle); +if (error <0 ) { +dev_err (&mc_dev->dev,"dprc_open() failed: %d\n" , error); + goto error; + } + + dprc_opened = true; + error =dprc_scan_container (mc_dev); +if (error <0 ) + goto error; + +dev_info (&mc_dev->dev,"DPRC device bound to driver" ); +return 0 ; +error: +if (dprc_opened) + (void )dprc_close (mc_dev->mc_io, mc_dev->mc_handle); + +return error; +} + +/** +* dprc_remove - callback invoked when a DPRC is being unbound from this driver +* +* @mc_dev: Pointer to fsl-mc device representing the DPRC +* +* It removes the DPRC's child objects from Linux (not from the MC) and +* closes the DPRC device in the MC. +*/ +static int dprc_remove (struct fsl_mc_device *mc_dev) +{ +int error = -EINVAL ; + +if (WARN_ON (strcmp (mc_dev->obj_desc.type,"dprc" ) !=0 )) + goto error; +if (WARN_ON (mc_dev->mc_io ==NULL )) + goto error; +drivers/bus/fsl-mc/fsl_mc_dprc.c line 372
Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +10
-0+device_for_each_child (&mc_dev->dev,NULL , __fsl_mc_device_remove); + error =dprc_close (mc_dev->mc_io, mc_dev->mc_handle); +if (error <0 ) +dev_err (&mc_dev->dev,"dprc_close() failed: %d\n" , error); + +dev_info (&mc_dev->dev,"DPRC device unbound from driver" ); +return 0 ; +error: +return error; +}Try this:
static int
dprc_remove(struct fsl_mc_device *mc_dev){ int error; if (WARN_ON(strcmp(mc_dev->obj_desc.type, "dprc") != 0)) return -EINVAL; if (WARN_ON(mc_dev->mc_io == NULL)) return -EINVAL; device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove); error = dprc_close(mc_dev->mc_io, mc_dev->mc_handle);
Quoted 9 lines
if (error < 0) {
dev_err(&mc_dev->dev, "dprc_close() failed: %d\n", error);
return error;
}
dev_dbg(&mc_dev->dev, "DPRC device unbound from driver");
return 0;
}OK, I will make this change, as there is no common cleanup to do in this case.
Quoted 46 lines
Quoted 46 lines
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +30
-0+ +static const struct fsl_mc_device_match_id match_id_table[] = { + { + .vendor =FSL_MC_VENDOR_FREESCALE , + .obj_type ="dprc" , + .ver_major =DPRC_VER_MAJOR , + .ver_minor =DPRC_VER_MINOR }, + {.vendor =0x0 }, +}; + +static struct fsl_mc_driver dprc_driver = { + .driver = { + .name =FSL_MC_DPRC_DRIVER_NAME , + .owner =THIS_MODULE , + .pm =NULL , + }, + .match_id_table = match_id_table, + .probe = dprc_probe, + .remove = dprc_remove, +}; + +int __init dprc_driver_init (void ) +{ +return fsl_mc_driver_register (&dprc_driver); +} + +void __exit dprc_driver_exit(void) +{ +fsl_mc_driver_unregister (&dprc_driver); +}include/linux/fsl_mc_private.h +2
-0@@ -15,6 +15,8 @@#include <linux/mutex.h> #include <linux/stringify.h> +#define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc" +#define FSL_MC_DEVICE_MATCH (_mc_dev, _obj_desc) \ (strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \ (_mc_dev)->obj_desc.id == (_obj_desc)->id)@@ -30,4 +32,12 @@ int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
Quoted 7 lines
include/linux/fsl_mc_private.h int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc, · line 37
Quoted 5 lines
include/linux/fsl_mc_private.h +3
-0void fsl_mc_device_remove (struct fsl_mc_device *mc_dev); +int __must_check dprc_scan_container (struct fsl_mc_device *mc_bus_dev); + +int __must_check dprc_scan_objects (struct fsl_mc_device *mc_bus_dev);
__must_check? Really?
Yes, to ensure that callers that are not checking the return code from dprc_scan_objects() are caught at compile-time (CHECK time).
Thanks,
German
Quoted 1 line
Re: [PATCH 3/3 v2] drivers/bus: Device driver for FSL-MC DPRC devices
Quoted 3 lines · German Rivera
Quoted 1 line
I know that this is not necessary from the point of view of C boolean semantics, but doing explicit comparison improves readability IMHO.
I guess we'll have to agree to disagree. I think it makes the code less readable.
Quoted 3 lines
Anyway, this is subjective and largely a matter of preference. Besides, "
Documentation/CodingStyle" does not seem to advocate one way or the other.
CodingStyle is a starting point, not the final word. If I had a dime whenever someone insisted a code snippet is okay because it's not covered by CodingStyle, I could retire.
Quoted 2 lines
Also, I there is evidence that explicit comparisons are allowed in the kernel source tree:
Allowed != preferred. Besides, there are tons of examples of almost every style mistake in the kernel today. Some code is really old, or it was accepted by lazy maintainers and never fixed. You can't really use that as a basis for a decision.
Quoted 8 lines
Quoted 5 lines
include/linux/fsl_mc_private.h int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc, · line 37
Quoted 3 lines
include/linux/fsl_mc_private.h +3
-0+int __must_check dprc_scan_container (struct fsl_mc_device *mc_bus_dev); + +int __must_check dprc_scan_objects (struct fsl_mc_device *mc_bus_dev);
__must_check? Really?Yes, to ensure that callers that are not checking the return code from
dprc_scan_objects()are caught at compile-time (CHECK time).
I know what __must_check is for. I'm just saying that you kinda need to justify using it. It's like using likely() on non-time-critical code. Overuse is worse than not using it at all, and I don't see what's so special about these functions that they need __must_check.
(on a side note, you're supposed to bcc: [email protected], not cc: it.)
Quoted 4 lines · On Fri, 19 Sep 2014 17:49:38 -0500 "J. German Rivera"…
CHANGE HISTORY
Issues pending resolution not addressed by v2:
- What to do with Doxygen comments in patch 1
It's clear they should be removed.
Quoted 2 lines
- Whether to move or not FSL-specific header files added in
include/linux, by this patch series, to another location
there wasn't a valid objection against moving them under fsl/ and changing them to use dashes instead of underscores, was there?
Quoted 2 lines
- Whether to change or not the wording of the licenses used in some source files
I agree with Alex to use the existing kernel versions, to be on the safe side, but IANAL - did you want to go to the source of the change (presumably a lawyer?) and find out why the contributors clause was omitted and how they think that's appropriate in an upstream submission? If not, please resubmit after converting all files to use the existing common kernel license text.
Thanks,
Kim
Quoted 18 lines
-----Original Message-----
From: Kim Phillips [mailto:[email protected]]
Sent: Monday, September 22, 2014 11:53 AM
To: Rivera Jose-B46482
Cc: [email protected]; [email protected]; [email protected]; Yoder Stuart-B08248; Wood Scott- B07421; [email protected]; [email protected]
Subject: Re: [PATCH 0/3 v2]drivers/bus: Freescale Management Complex bus driver patch seriesQuoted 4 lines · On Fri, 19 Sep 2014 17:49:38 -0500 "J. German Rivera"…
CHANGE HISTORY
Issues pending resolution not addressed by v2:
- What to do with Doxygen comments in patch 1
Quoted 7 lines
It's clear they should be removed.
Quoted 2 lines
- Whether to move or not FSL-specific header files added in
include/linux, by this patch series, to another locationthere wasn't a valid objection against moving them under fsl/ and changing them to use dashes instead of underscores, was there?
There was no objection, but here is the observation. The current convention seems to be that under include/linux are 'subsystem' types--
include/linux/mmc
include/linux/spi
include/linux/raid
etc
There is no other "company" that has an include/linux/[company-name] that I can
see. Freescale seems to be the only one. And there is only a single driver
in there. So it looks like a complete anomaly.
Why is that?
I guess we could try moving our stuff to incluce/linux/fsl and see if there is any negative feedback on it.
Stuart
Quoted 27 lines · On Mon, 22 Sep 2014 12:59:21 -0500 Yoder Stuart-B08248…
Quoted 11 lines
From: Kim Phillips [mailto:[email protected]]
Sent: Monday, September 22, 2014 11:53 AMQuoted 4 lines · On Fri, 19 Sep 2014 17:49:38 -0500 "J. German Rivera"…
CHANGE HISTORY
Issues pending resolution not addressed by v2:
- What to do with Doxygen comments in patch 1Quoted 7 lines
It's clear they should be removed.
Quoted 2 lines
- Whether to move or not FSL-specific header files added in
include/linux, by this patch series, to another locationthere wasn't a valid objection against moving them under fsl/ and changing them to use dashes instead of underscores, was there?
There was no objection, but here is the observation. The current convention seems to be that under
include/linuxare 'subsystem' types--
include/linux/mmc
include/linux/spi
include/linux/raid
etc
Quoted 8 lines
There is no other "company" that has an include/linux/[company-name] that I can
see. Freescale seems to be the only one. And there is only a single driver
in there. So it looks like a complete anomaly.Why is that?
I guess we could try moving our stuff to incluce/linux/fsl and see if there is any negative feedback on it.
these two commits:
commit 9a32299 "powerpc, dma: move bestcomm driver from arch/powerpc/sysdev to drivers/dma"
commit 3946860 "mxs-dma : move the mxs dma.h to a more common place"
create/update files in include/linux/fsl for the same reason as this patchseries wants, i.e., in order to support multiple drivers including the files, and in an arch- (and mach-) independent manner.
hth,
Kim
Quoted 34 lines · On 09/22/2014 12:59 PM, Yoder Stuart-B08248 wrote:
Quoted 18 lines
-----Original Message-----
From: Kim Phillips [mailto:[email protected]]
Sent: Monday, September 22, 2014 11:53 AM
To: Rivera Jose-B46482
Cc: [email protected]; [email protected]; [email protected]; Yoder Stuart-B08248; Wood Scott- B07421; [email protected]; [email protected]
Subject: Re: [PATCH 0/3 v2]drivers/bus: Freescale Management Complex bus driver patch seriesQuoted 4 lines · On Fri, 19 Sep 2014 17:49:38 -0500 "J. German Rivera"…
CHANGE HISTORY
Issues pending resolution not addressed by v2:
- What to do with Doxygen comments in patch 1Quoted 7 lines
It's clear they should be removed.
Quoted 2 lines
- Whether to move or not FSL-specific header files added in
include/linux, by this patch series, to another locationthere wasn't a valid objection against moving them under fsl/ and changing them to use dashes instead of underscores, was there?
There was no objection, but here is the observation. The current convention seems to be that under
include/linuxare 'subsystem' types--
include/linux/mmc
include/linux/spi
include/linux/raid
etc
Quoted 9 lines
There is no other "company" that has an include/linux/[company-name] that I can
see. Freescale seems to be the only one. And there is only a single driver
in there. So it looks like a complete anomaly.Why is that?
I guess we could try moving our stuff to incluce/linux/fsl and see if there is any negative feedback on it.
Ok, unless there is any objection, we will do the following file renamings:
Patch 1/3drivers/bus/fsl-mc/fsl_dpmng_cmd.h -> drivers/bus/fsl-mc/dpmng-cmd.h drivers/bus/fsl-mc/fsl_dprc_cmd.h -> drivers/bus/fsl-mc/dprc-cmd.h drivers/bus/fsl-mc/fsl_mc_sys.c -> drivers/bus/fsl-mc/mc-sys.c include/linux/fsl_dpmng.h -> include/linux/fsl/dpmng.h include/linux/fsl_dprc.h -> include/linux/fsl/dprc.h include/linux/fsl_mc_cmd.h -> include/linux/fsl/mc-cmd.h include/linux/fsl_mc_sys.h -> include/linux/fsl/mc-sys.h
Patch 2/3drivers/bus/fsl-mc/fsl_mc_bus.c -> drivers/bus/fsl-mc/mc-bus.c include/linux/fsl_mc.h -> include/linux/fsl/mc.h include/linux/fsl_mc_private.h -> include/linux/fsl/mc-private.h
Patch 3/3drivers/bus/fsl-mc/fsl_mc_dprc.c -> drivers/bus/fsl-mc/dprc-driver.c (there is a file already named drivers/bus/fsl-mc/dprc.c)
Quoted 2 lines
Stuart