Skip to contentSkip to conversation

Ancillary bus implementation and SOF multi-client support

PATCH Superseded Dave Ertman 9 participants 72 messages Oct 5, 2020 – Oct 13, 2020

Subsystems (8)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Ancillary bus implementation and SOF multi-client support

Version 2 of this patchset is being pushed out when there are still some issues up in the air. This push, along with the changes in the change log below, is to fix the broken distribution among mailing lists and individuals of the first version submission.

At least two items still under discussion are:
Final name for the bus
Documentation of sysfs directories

Brief history of Ancillary Bus
==============================
The ancillary bus code was originally submitted upstream as virtual bus, and was submitted through the netdev tree.  This process generated up to v4.  This discussion can be found here:
https://lore.kernel.org/netdev/[email protected]/#t

At this point, GregKH requested that we take the review and revision process to an internal mailing list and garner the buy-in of a respected kernel contributor.

The ancillary bus (then known as virtual bus) was originally submitted along with implementation code for the ice driver and irdma drive, causing the complication of also having dependencies in the rdma tree. This new submission is utilizing an ancillary bus consumer in only the sound driver tree to create the initial implementation and a single user.

Since implementation work has started on this patch set, there have been multiple inquiries about the time frame of its completion. It appears that there will be numerous consumers of this functionality.

The process of internal review and implementation using the sound drivers generated 19 internal versions.  The changes, including the name change from virtual bus to ancillary bus, from these versions can be summarized as the following:

- Fixed compilation and checkpatch errors
- Improved documentation to address the motivation for virtual bus.
- Renamed virtual bus to ancillary bus
- increased maximum device name size
- Correct order in Kconfig and Makefile
- removed the mid-layer adev->release layer for device unregister
- pushed adev->id management to parent driver
- all error paths out of ancillary_device_register return error code
- all error paths out of ancillary_device_register use put_device
- added adev->name element
- modname in register cannot be NULL
- added KBUILD_MODNAME as prefix for match_name
- push adev->id responsibility to registering driver
- uevent now parses adev->dev name
- match_id function now parses adev->dev name
- changed drivers probe function to also take an ancillary_device_id param
- split ancillary_device_register into device_initialize and device_add
- adjusted what is done in device_initialize and device_add
- change adev to ancildev and adrv to ancildrv
- change adev to ancildev in documentation

==========================

Introduces the ancillary bus implementation along with the example usage in the Sound Open Firmware(SOF) audio driver.

In some subsystems, the functionality of the core device (PCI/ACPI/other) may be too complex for a single device to be managed as a monolithic block or a part of the functionality might need to be exposed to a different subsystem. Splitting the functionality into smaller orthogonal devices makes it easier to manage data, power management and domain-specific communication with the hardware. Also, common ancillary_device functionality across primary devices can be handled by a common ancillary_device. A key requirement for such a split is that there is no dependency on a physical bus, device, register accesses or regmap support. These individual devices split from the core cannot live on the platform bus as they are not physical devices that are controlled by DT/ACPI. The same argument applies for not using MFD in this scenario as it relies on individual function devices being physical devices that are DT enumerated.

An example for this kind of requirement is the audio subsystem where a single IP handles multiple entities such as HDMI, Soundwire, local devices such as mics/speakers etc. The split for the core's functionality can be arbitrary or be defined by the DSP firmware topology and include hooks for test/debug. This allows for the audio core device to be minimal and tightly coupled with handling the hardware-specific logic and communication.

The ancillary bus is intended to be minimal, generic and avoid domain-specific assumptions. Each ancillary bus device represents a part of its parent functionality. The generic behavior can be extended and specialized as needed by encapsulating an ancillary bus device within other domain-specific structures and the use of .ops callbacks.

The SOF driver adopts the ancillary bus for implementing the multi-client support. A client in the context of the SOF driver represents a part of the core device's functionality. It is not a physical device but rather an ancillary device that needs to communicate with the DSP via IPCs. With multi-client support,the sound card can be separated into multiple orthogonal ancillary devices for local devices (mic/speakers etc), HDMI, sensing, probes, debug etc. In this series, we demonstrate the usage of the ancillary bus with the help of the IPC test client which is used for testing the serialization of IPCs when multiple clients talk to the DSP at the same time.

v2 changes:
defined pr_fmt for kernel messages
replaced WARN_ON calls in registration with pr_err calls adding kernel-doc function comments for device_initialize and device_add fix typo in documentation
removed inaccurate line in documentation
fixed formatting in drivers/bus/Makefile
changed unwind path for sof_client_dev_alloc()
improved comments for client list and mem freeing during client unreg removed debugfs entries in sof_ipc_test_client_drv during remove changed the signature of sof_debug_ipc_flood_test()
fix a looping error in ancillary_match_id
updated error value in sof_client_dev_register()
mutex held while traversing client list when unregistering clients updated includes in sof-client.h

Dave Ertman (1):
Add ancillary bus support

Fred Oh (1):
ASoC: SOF: debug: Remove IPC flood test support in SOF core

Ranjani Sridharan (4):
ASoC: SOF: Introduce descriptors for SOF client
ASoC: SOF: Create client driver for IPC test
ASoC: SOF: ops: Add ops for client registration
ASoC: SOF: Intel: Define ops for client registration

 Documentation/driver-api/ancillary_bus.rst | 229 ++++++++++++++
 Documentation/driver-api/index.rst         |   1 +
 drivers/bus/Kconfig                        |   3 +
 drivers/bus/Makefile                       |   3 +
 drivers/bus/ancillary.c                    | 225 ++++++++++++++
 include/linux/ancillary_bus.h              |  69 +++++
 include/linux/mod_devicetable.h            |   8 +
 scripts/mod/devicetable-offsets.c          |   3 +
 scripts/mod/file2alias.c                   |   8 +
 sound/soc/sof/Kconfig                      |  29 +-
 sound/soc/sof/Makefile                     |   7 +
 sound/soc/sof/core.c                       |  12 +
 sound/soc/sof/debug.c                      | 230 --------------
 sound/soc/sof/intel/Kconfig                |   9 +
 sound/soc/sof/intel/Makefile               |   3 +
 sound/soc/sof/intel/apl.c                  |  18 ++
 sound/soc/sof/intel/bdw.c                  |  18 ++
 sound/soc/sof/intel/byt.c                  |  22 ++
 sound/soc/sof/intel/cnl.c                  |  18 ++
 sound/soc/sof/intel/intel-client.c         |  53 ++++
 sound/soc/sof/intel/intel-client.h         |  26 ++
 sound/soc/sof/ops.h                        |  14 +
 sound/soc/sof/sof-client.c                 | 119 ++++++++
 sound/soc/sof/sof-client.h                 |  69 +++++
 sound/soc/sof/sof-ipc-test-client.c        | 332 +++++++++++++++++++++
 sound/soc/sof/sof-priv.h                   |  19 +-
 26 files changed, 1308 insertions(+), 239 deletions(-)
 create mode 100644 Documentation/driver-api/ancillary_bus.rst
 create mode 100644 drivers/bus/ancillary.c
 create mode 100644 include/linux/ancillary_bus.h
 create mode 100644 sound/soc/sof/intel/intel-client.c
 create mode 100644 sound/soc/sof/intel/intel-client.h
 create mode 100644 sound/soc/sof/sof-client.c
 create mode 100644 sound/soc/sof/sof-client.h
 create mode 100644 sound/soc/sof/sof-ipc-test-client.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/6 Add ancillary bus support

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

The bus supports probe/remove shutdown and suspend/resume callbacks. Each ancillary_device has a unique string based id; driver binds to an ancillary_device based on this id through the bus.

---
 Documentation/driver-api/ancillary_bus.rst | 229 +++++++++++++++++++++
 Documentation/driver-api/index.rst         |   1 +
 drivers/bus/Kconfig                        |   3 +
 drivers/bus/Makefile                       |   3 +
 drivers/bus/ancillary.c                    | 225 ++++++++++++++++++++
 include/linux/ancillary_bus.h              |  69 +++++++
 include/linux/mod_devicetable.h            |   8 +
 scripts/mod/devicetable-offsets.c          |   3 +
 scripts/mod/file2alias.c                   |   8 +
 9 files changed, 549 insertions(+)
 create mode 100644 Documentation/driver-api/ancillary_bus.rst
 create mode 100644 drivers/bus/ancillary.c
 create mode 100644 include/linux/ancillary_bus.h
Documentation/driver-api/ancillary_bus.rst new file +229 -0
new file mode 100644
index 000000000000..66f986e8672f
@@ -0,0 +1,229 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+=============
+Ancillary Bus
+=============
+
+In some subsystems, the functionality of the core device (PCI/ACPI/other) is
+too complex for a single device to be managed as a monolithic block or a part of
+the functionality needs to be exposed to a different subsystem.  Splitting the
+functionality into smaller orthogonal devices would make it easier to manage
+data, power management and domain-specific interaction with the hardware. A key
+requirement for such a split is that there is no dependency on a physical bus,
+device, register accesses or regmap support. These individual devices split from
+the core cannot live on the platform bus as they are not physical devices that
+are controlled by DT/ACPI. The same argument applies for not using MFD in this
+scenario as MFD relies on individual function devices being physical devices.
+
+An example for this kind of requirement is the audio subsystem where a single
+IP is handling multiple entities such as HDMI, Soundwire, local devices such as
+mics/speakers etc. The split for the core's functionality can be arbitrary or
+be defined by the DSP firmware topology and include hooks for test/debug. This
+allows for the audio core device to be minimal and focused on hardware-specific
+control and communication.
+
+The ancillary bus is intended to be minimal, generic and avoid domain-specific
+assumptions. Each ancillary_device represents a part of its parent
+functionality. The generic behavior can be extended and specialized as needed
+by encapsulating an ancillary_device within other domain-specific structures and
+the use of .ops callbacks. Devices on the ancillary bus do not share any
+structures and the use of a communication channel with the parent is
+domain-specific.
+
+When Should the Ancillary Bus Be Used
+=====================================
+
+The ancillary bus is to be used when a driver and one or more kernel modules,
+who share a common header file with the driver, need a mechanism to connect and
+provide access to a shared object allocated by the ancillary_device's
+registering driver.  The registering driver for the ancillary_device(s) and the
+kernel module(s) registering ancillary_drivers can be from the same subsystem,
+or from multiple subsystems.
+
+The emphasis here is on a common generic interface that keeps subsystem
+customization out of the bus infrastructure.
+
+One example could be a multi-port PCI network device that is rdma-capable and
+needs to export this functionality and attach to an rdma driver in another
+subsystem.  The PCI driver will allocate and register an ancillary_device for
+each physical function on the NIC.  The rdma driver will register an
+ancillary_driver that will be matched with and probed for each of these
+ancillary_devices.  This will give the rdma driver access to the shared data/ops
+in the PCI drivers shared object to establish a connection with the PCI driver.
+
+Another use case is for the PCI device to be split out into multiple sub
+functions.  For each sub function an ancillary_device will be created.  A PCI
+sub function driver will bind to such devices that will create its own one or
+more class devices.  A PCI sub function ancillary device will likely be
+contained in a struct with additional attributes such as user defined sub
+function number and optional attributes such as resources and a link to the
+parent device.  These attributes could be used by systemd/udev; and hence should
+be initialized before a driver binds to an ancillary_device.
+
+Ancillary Device
+================
+
+An ancillary_device is created and registered to represent a part of its parent
+device's functionality. It is given a name that, combined with the registering
+drivers KBUILD_MODNAME, creates a match_name that is used for driver binding,
+and an id that combined with the match_name provide a unique name to register
+with the bus subsystem.
+
+Registering an ancillary_device is a two-step process.  First you must call
+ancillary_device_initialize(), which will check several aspects of the
+ancillary_device struct and perform a device_initialize().  After this step
+completes, any error state must have a call to put_device() in its resolution
+path.  The second step in registering an ancillary_device is to perform a call
+to ancillary_device_add(), which will set the name of the device and add the
+device to the bus.
+
+To unregister an ancillary_device, just a call to ancillary_device_unregister()
+is used.  This will perform both a device_del() and a put_device().
+
+.. code-block:: c
+
+	struct ancillary_device {
+		struct device dev;
+                const char *name;
+		u32 id;
+	};
+
+If two ancillary_devices both with a match_name "mod.foo" are registered onto
+the bus, they must have unique id values (e.g. "x" and "y") so that the
+registered devices names will be "mod.foo.x" and "mod.foo.y".  If match_name +
+id are not unique, then the device_add will fail and generate an error message.
+
+The ancillary_device.dev.type.release or ancillary_device.dev.release must be
+populated with a non-NULL pointer to successfully register the ancillary_device.
+
+The ancillary_device.dev.parent must also be populated.
+
+Ancillary Device Memory Model and Lifespan
+------------------------------------------
+
+When a kernel driver registers an ancillary_device on the ancillary bus, we will
+use the nomenclature to refer to this kernel driver as a registering driver.  It
+is the entity that will allocate memory for the ancillary_device and register it
+on the ancillary bus.  It is important to note that, as opposed to the platform
+bus, the registering driver is wholly responsible for the management for the
+memory used for the driver object.
+
+A parent object, defined in the shared header file, will contain the
+ancillary_device.  It will also contain a pointer to the shared object(s), which
+will also be defined in the shared header.  Both the parent object and the
+shared object(s) will be allocated by the registering driver.  This layout
+allows the ancillary_driver's registering module to perform a container_of()
+call to go from the pointer to the ancillary_device, that is passed during the
+call to the ancillary_driver's probe function, up to the parent object, and then
+have access to the shared object(s).
+
+The memory for the ancillary_device will be freed only in its release()
+callback flow as defined by its registering driver.
+
+The memory for the shared object(s) must have a lifespan equal to, or greater
+than, the lifespan of the memory for the ancillary_device.  The ancillary_driver
+should only consider that this shared object is valid as long as the
+ancillary_device is still registered on the ancillary bus.  It is up to the
+registering driver to manage (e.g. free or keep available) the memory for the
+shared object beyond the life of the ancillary_device.
+
+Registering driver must unregister all ancillary devices before its registering
+parent device's remove() is completed.
+
+Ancillary Drivers
+=================
+
+Ancillary drivers follow the standard driver model convention, where
+discovery/enumeration is handled by the core, and drivers
+provide probe() and remove() methods. They support power management
+and shutdown notifications using the standard conventions.
+
+.. code-block:: c
+
+	struct ancillary_driver {
+		int (*probe)(struct ancillary_device *,
+                             const struct ancillary_device_id *id);
+		int (*remove)(struct ancillary_device *);
+		void (*shutdown)(struct ancillary_device *);
+		int (*suspend)(struct ancillary_device *, pm_message_t);
+		int (*resume)(struct ancillary_device *);
+		struct device_driver driver;
+		const struct ancillary_device_id *id_table;
+	};
+
+Ancillary drivers register themselves with the bus by calling
+ancillary_driver_register(). The id_table contains the match_names of ancillary
+devices that a driver can bind with.
+
+Example Usage
+=============
+
+Ancillary devices are created and registered by a subsystem-level core device
+that needs to break up its functionality into smaller fragments. One way to
+extend the scope of an ancillary_device would be to encapsulate it within a
+domain-specific structure defined by the parent device. This structure contains
+the ancillary_device and any associated shared data/callbacks needed to
+establish the connection with the parent.
+
+An example would be:
+
+.. code-block:: c
+
+        struct foo {
+		struct ancillary_device ancildev;
+		void (*connect)(struct ancillary_device *ancildev);
+		void (*disconnect)(struct ancillary_device *ancildev);
+		void *data;
+        };
+
+The parent device would then register the ancillary_device by calling
+ancillary_device_initialize(), and then ancillary_device_add(), with the pointer
+to the ancildev member of the above structure. The parent would provide a name
+for the ancillary_device that, combined with the parent's KBUILD_MODNAME, will
+create a match_name that will be used for matching and binding with a driver.
+
+Whenever an ancillary_driver is registered, based on the match_name, the
+ancillary_driver's probe() is invoked for the matching devices.  The
+ancillary_driver can also be encapsulated inside custom drivers that make the
+core device's functionality extensible by adding additional domain-specific ops
+as follows:
+
+.. code-block:: c
+
+	struct my_ops {
+		void (*send)(struct ancillary_device *ancildev);
+		void (*receive)(struct ancillary_device *ancildev);
+	};
+
+
+	struct my_driver {
+		struct ancillary_driver ancillary_drv;
+		const struct my_ops ops;
+	};
+
+An example of this type of usage would be:
+
+.. code-block:: c
+
+	const struct ancillary_device_id my_ancillary_id_table[] = {
+		{ .name = "foo_mod.foo_dev" },
+		{ },
+	};
+
+	const struct my_ops my_custom_ops = {
+		.send = my_tx,
+		.receive = my_rx,
+	};
+
+	const struct my_driver my_drv = {
+		.ancillary_drv = {
+			.driver = {
+				.name = "myancillarydrv",
+			},
+			.id_table = my_ancillary_id_table,
+			.probe = my_probe,
+			.remove = my_remove,
+			.shutdown = my_shutdown,
+		},
+		.ops = my_custom_ops,
+	};
Documentation/driver-api/index.rst +1 -0
index 5ef2cfe3a16b..9584ac2ed1f5 100644
@@ -74,6 +74,7 @@ available subsections can be seen below.
    thermal/index
    fpga/index
    acpi/index
+   ancillary_bus
    backlight/lp855x-driver.rst
    connector
    console
drivers/bus/Kconfig +3 -0
index 0c262c2aeaf2..ba82a045b847 100644
@@ -5,6 +5,9 @@
 
 menu "Bus devices"
 
+config ANCILLARY_BUS
+       tristate
+
 config ARM_CCI
 	bool
 
drivers/bus/Makefile +3 -0
index 397e35392bff..7c217eb1dbb7 100644
@@ -3,6 +3,9 @@
 # Makefile for the bus drivers.
 #
 
+# Ancillary bus driver
+obj-$(CONFIG_ANCILLARY_BUS)	+= ancillary.o
+
 # Interconnect bus drivers for ARM platforms
 obj-$(CONFIG_ARM_CCI)		+= arm-cci.o
 obj-$(CONFIG_ARM_INTEGRATOR_LM)	+= arm-integrator-lm.o
drivers/bus/ancillary.c new file +225 -0

225 lines not on this page · raw message

include/linux/ancillary_bus.h new file +69 -0

69 lines not on this page · raw message

include/linux/mod_devicetable.h +8 -0
index 5b08a473cdba..7d596dc30833 100644
@@ -838,4 +838,12 @@ struct mhi_device_id {
 	kernel_ulong_t driver_data;
 };
 
+#define ANCILLARY_NAME_SIZE 32
+#define ANCILLARY_MODULE_PREFIX "ancillary:"
+
+struct ancillary_device_id {
+	char name[ANCILLARY_NAME_SIZE];
+	kernel_ulong_t driver_data;
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
scripts/mod/devicetable-offsets.c +3 -0
index 27007c18e754..79e37c4c25b3 100644
@@ -243,5 +243,8 @@ int main(void)
 	DEVID(mhi_device_id);
 	DEVID_FIELD(mhi_device_id, chan);
 
+	DEVID(ancillary_device_id);
+	DEVID_FIELD(ancillary_device_id, name);
+
 	return 0;
 }
scripts/mod/file2alias.c +8 -0
index 2417dd1dee33..99c4fcd82bf3 100644
@@ -1364,6 +1364,13 @@ static int do_mhi_entry(const char *filename, void *symval, char *alias)
 {
 	DEF_FIELD_ADDR(symval, mhi_device_id, chan);
 	sprintf(alias, MHI_DEVICE_MODALIAS_FMT, *chan);
+	return 1;
+}
+
+static int do_ancillary_entry(const char *filename, void *symval, char *alias)
+{
+	DEF_FIELD_ADDR(symval, ancillary_device_id, name);
+	sprintf(alias, ANCILLARY_MODULE_PREFIX "%s", *name);
 
 	return 1;
 }
@@ -1442,6 +1449,7 @@ static const struct devtable devtable[] = {
 	{"tee", SIZE_tee_client_device_id, do_tee_entry},
 	{"wmi", SIZE_wmi_device_id, do_wmi_entry},
 	{"mhi", SIZE_mhi_device_id, do_mhi_entry},
+	{"ancillary", SIZE_ancillary_device_id, do_ancillary_entry},
 };
 
 /* Create MODULE_ALIAS() statements.
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 3 lines · Dave Ertman

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

Quoted 248 lines

The bus supports probe/remove shutdown and suspend/resume callbacks. Each ancillary_device has a unique string based id; driver binds to an ancillary_device based on this id through the bus.

---
 Documentation/driver-api/ancillary_bus.rst | 229 +++++++++++++++++++++
 Documentation/driver-api/index.rst         |   1 +
 drivers/bus/Kconfig                        |   3 +
 drivers/bus/Makefile                       |   3 +
 drivers/bus/ancillary.c                    | 225 ++++++++++++++++++++
 include/linux/ancillary_bus.h              |  69 +++++++
 include/linux/mod_devicetable.h            |   8 +
 scripts/mod/devicetable-offsets.c          |   3 +
 scripts/mod/file2alias.c                   |   8 +
 9 files changed, 549 insertions(+)
 create mode 100644 Documentation/driver-api/ancillary_bus.rst
 create mode 100644 drivers/bus/ancillary.c
 create mode 100644 include/linux/ancillary_bus.h
Documentation/driver-api/ancillary_bus.rst new file +211 -0
new file mode 100644
index 000000000000..66f986e8672f
@@ -0,0 +1,229 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+=============
+Ancillary Bus
+=============
+
+In some subsystems, the functionality of the core device (PCI/ACPI/other) is
+too complex for a single device to be managed as a monolithic block or a part of
+the functionality needs to be exposed to a different subsystem.  Splitting the
+functionality into smaller orthogonal devices would make it easier to manage
+data, power management and domain-specific interaction with the hardware. A key
+requirement for such a split is that there is no dependency on a physical bus,
+device, register accesses or regmap support. These individual devices split from
+the core cannot live on the platform bus as they are not physical devices that
+are controlled by DT/ACPI. The same argument applies for not using MFD in this
+scenario as MFD relies on individual function devices being physical devices.
+
+An example for this kind of requirement is the audio subsystem where a single
+IP is handling multiple entities such as HDMI, Soundwire, local devices such as
+mics/speakers etc. The split for the core's functionality can be arbitrary or
+be defined by the DSP firmware topology and include hooks for test/debug. This
+allows for the audio core device to be minimal and focused on hardware-specific
+control and communication.
+
+The ancillary bus is intended to be minimal, generic and avoid domain-specific
+assumptions. Each ancillary_device represents a part of its parent
+functionality. The generic behavior can be extended and specialized as needed
+by encapsulating an ancillary_device within other domain-specific structures and
+the use of .ops callbacks. Devices on the ancillary bus do not share any
+structures and the use of a communication channel with the parent is
+domain-specific.
+
+When Should the Ancillary Bus Be Used
+=====================================
+
+The ancillary bus is to be used when a driver and one or more kernel modules,
+who share a common header file with the driver, need a mechanism to connect and
+provide access to a shared object allocated by the ancillary_device's
+registering driver.  The registering driver for the ancillary_device(s) and the
+kernel module(s) registering ancillary_drivers can be from the same subsystem,
+or from multiple subsystems.
+
+The emphasis here is on a common generic interface that keeps subsystem
+customization out of the bus infrastructure.
+
+One example could be a multi-port PCI network device that is rdma-capable and
+needs to export this functionality and attach to an rdma driver in another
+subsystem.  The PCI driver will allocate and register an ancillary_device for
+each physical function on the NIC.  The rdma driver will register an
+ancillary_driver that will be matched with and probed for each of these
+ancillary_devices.  This will give the rdma driver access to the shared data/ops
+in the PCI drivers shared object to establish a connection with the PCI driver.
+
+Another use case is for the PCI device to be split out into multiple sub
+functions.  For each sub function an ancillary_device will be created.  A PCI
+sub function driver will bind to such devices that will create its own one or
+more class devices.  A PCI sub function ancillary device will likely be
+contained in a struct with additional attributes such as user defined sub
+function number and optional attributes such as resources and a link to the
+parent device.  These attributes could be used by systemd/udev; and hence should
+be initialized before a driver binds to an ancillary_device.
+
+Ancillary Device
+================
+
+An ancillary_device is created and registered to represent a part of its parent
+device's functionality. It is given a name that, combined with the registering
+drivers KBUILD_MODNAME, creates a match_name that is used for driver binding,
+and an id that combined with the match_name provide a unique name to register
+with the bus subsystem.
+
+Registering an ancillary_device is a two-step process.  First you must call
+ancillary_device_initialize(), which will check several aspects of the
+ancillary_device struct and perform a device_initialize().  After this step
+completes, any error state must have a call to put_device() in its resolution
+path.  The second step in registering an ancillary_device is to perform a call
+to ancillary_device_add(), which will set the name of the device and add the
+device to the bus.
+
+To unregister an ancillary_device, just a call to ancillary_device_unregister()
+is used.  This will perform both a device_del() and a put_device().
+
+.. code-block:: c
+
+	struct ancillary_device {
+		struct device dev;
+                const char *name;
+		u32 id;
+	};
+
+If two ancillary_devices both with a match_name "mod.foo" are registered onto
+the bus, they must have unique id values (e.g. "x" and "y") so that the
+registered devices names will be "mod.foo.x" and "mod.foo.y".  If match_name +
+id are not unique, then the device_add will fail and generate an error message.
+
+The ancillary_device.dev.type.release or ancillary_device.dev.release must be
+populated with a non-NULL pointer to successfully register the ancillary_device.
+
+The ancillary_device.dev.parent must also be populated.
+
+Ancillary Device Memory Model and Lifespan
+------------------------------------------
+
+When a kernel driver registers an ancillary_device on the ancillary bus, we will
+use the nomenclature to refer to this kernel driver as a registering driver.  It
+is the entity that will allocate memory for the ancillary_device and register it
+on the ancillary bus.  It is important to note that, as opposed to the platform
+bus, the registering driver is wholly responsible for the management for the
+memory used for the driver object.
+
+A parent object, defined in the shared header file, will contain the
+ancillary_device.  It will also contain a pointer to the shared object(s), which
+will also be defined in the shared header.  Both the parent object and the
+shared object(s) will be allocated by the registering driver.  This layout
+allows the ancillary_driver's registering module to perform a container_of()
+call to go from the pointer to the ancillary_device, that is passed during the
+call to the ancillary_driver's probe function, up to the parent object, and then
+have access to the shared object(s).
+
+The memory for the ancillary_device will be freed only in its release()
+callback flow as defined by its registering driver.
+
+The memory for the shared object(s) must have a lifespan equal to, or greater
+than, the lifespan of the memory for the ancillary_device.  The ancillary_driver
+should only consider that this shared object is valid as long as the
+ancillary_device is still registered on the ancillary bus.  It is up to the
+registering driver to manage (e.g. free or keep available) the memory for the
+shared object beyond the life of the ancillary_device.
+
+Registering driver must unregister all ancillary devices before its registering
+parent device's remove() is completed.
+
+Ancillary Drivers
+=================
+
+Ancillary drivers follow the standard driver model convention, where
+discovery/enumeration is handled by the core, and drivers
+provide probe() and remove() methods. They support power management
+and shutdown notifications using the standard conventions.
+
+.. code-block:: c
+
+	struct ancillary_driver {
+		int (*probe)(struct ancillary_device *,
+                             const struct ancillary_device_id *id);
+		int (*remove)(struct ancillary_device *);
+		void (*shutdown)(struct ancillary_device *);
+		int (*suspend)(struct ancillary_device *, pm_message_t);
+		int (*resume)(struct ancillary_device *);
+		struct device_driver driver;
+		const struct ancillary_device_id *id_table;
+	};
+
+Ancillary drivers register themselves with the bus by calling
+ancillary_driver_register(). The id_table contains the match_names of ancillary
+devices that a driver can bind with.
+
+Example Usage
+=============
+
+Ancillary devices are created and registered by a subsystem-level core device
+that needs to break up its functionality into smaller fragments. One way to
+extend the scope of an ancillary_device would be to encapsulate it within a
+domain-specific structure defined by the parent device. This structure contains
+the ancillary_device and any associated shared data/callbacks needed to
+establish the connection with the parent.
+
+An example would be:
+
+.. code-block:: c
+
+        struct foo {
+		struct ancillary_device ancildev;
+		void (*connect)(struct ancillary_device *ancildev);
+		void (*disconnect)(struct ancillary_device *ancildev);
+		void *data;
+        };
+
+The parent device would then register the ancillary_device by calling
+ancillary_device_initialize(), and then ancillary_device_add(), with the pointer
+to the ancildev member of the above structure. The parent would provide a name
+for the ancillary_device that, combined with the parent's KBUILD_MODNAME, will
+create a match_name that will be used for matching and binding with a driver.
+
+Whenever an ancillary_driver is registered, based on the match_name, the
+ancillary_driver's probe() is invoked for the matching devices.  The
+ancillary_driver can also be encapsulated inside custom drivers that make the
+core device's functionality extensible by adding additional domain-specific ops
+as follows:
+
+.. code-block:: c
+
+	struct my_ops {
+		void (*send)(struct ancillary_device *ancildev);
+		void (*receive)(struct ancillary_device *ancildev);
+	};
+
+
+	struct my_driver {
+		struct ancillary_driver ancillary_drv;
+		const struct my_ops ops;
+	};
+
+An example of this type of usage would be:
+
+.. code-block:: c
+
+	const struct ancillary_device_id my_ancillary_id_table[] = {
+		{ .name = "foo_mod.foo_dev" },
+		{ },
+	};

Documentation/driver-api/ancillary_bus.rst line 221

Quoted 10 lines
Documentation/driver-api/ancillary_bus.rst new file +10 -0
+
+	const struct my_ops my_custom_ops = {
+		.send = my_tx,
+		.receive = my_rx,
+	};
+
+	const struct my_driver my_drv = {
+		.ancillary_drv = {
+			.driver = {
+				.name = "myancillarydrv",

Why do we need to give control over driver name to the driver authors? It can be problematic if author puts name that already exists.

Quoted 190 lines
Documentation/driver-api/ancillary_bus.rst new file +8 -0
+			},
+			.id_table = my_ancillary_id_table,
+			.probe = my_probe,
+			.remove = my_remove,
+			.shutdown = my_shutdown,
+		},
+		.ops = my_custom_ops,
+	};
Documentation/driver-api/index.rst +1 -0
index 5ef2cfe3a16b..9584ac2ed1f5 100644
@@ -74,6 +74,7 @@ available subsections can be seen below.
    thermal/index
    fpga/index
    acpi/index
+   ancillary_bus
    backlight/lp855x-driver.rst
    connector
    console
drivers/bus/Kconfig +3 -0
index 0c262c2aeaf2..ba82a045b847 100644
@@ -5,6 +5,9 @@
 
 menu "Bus devices"
 
+config ANCILLARY_BUS
+       tristate
+
 config ARM_CCI
 	bool
 
drivers/bus/Makefile +3 -0
index 397e35392bff..7c217eb1dbb7 100644
@@ -3,6 +3,9 @@
 # Makefile for the bus drivers.
 #
 
+# Ancillary bus driver
+obj-$(CONFIG_ANCILLARY_BUS)	+= ancillary.o
+
 # Interconnect bus drivers for ARM platforms
 obj-$(CONFIG_ARM_CCI)		+= arm-cci.o
 obj-$(CONFIG_ARM_INTEGRATOR_LM)	+= arm-integrator-lm.o
drivers/bus/ancillary.c new file +136 -0
new file mode 100644
index 000000000000..93888ca36fb1
@@ -0,0 +1,225 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Software based bus for Ancillary devices
+ *
+ * Copyright (c) 2019-2020 Intel Corporation
+ *
+ * Please see Documentation/driver-api/ancillary_bus.rst for more information.
+ */
+
+#define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__
+
+#include <linux/device.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
+#include <linux/string.h>
+#include <linux/ancillary_bus.h>
+
+static const struct ancillary_device_id *ancillary_match_id(const struct ancillary_device_id *id,
+							    const struct ancillary_device *ancildev)
+{
+	while (id->name[0]) {
+		const char *p = strrchr(dev_name(&ancildev->dev), '.');
+		int match_size;
+
+		if (!p) {
+			id++;
+			continue;
+		}
+		match_size = p - dev_name(&ancildev->dev);
+
+		/* use dev_name(&ancildev->dev) prefix before last '.' char to match to */
+		if (!strncmp(dev_name(&ancildev->dev), id->name, match_size))
+			return id;
+		id++;
+	}
+	return NULL;
+}
+
+static int ancillary_match(struct device *dev, struct device_driver *drv)
+{
+	struct ancillary_device *ancildev = to_ancillary_dev(dev);
+	struct ancillary_driver *ancildrv = to_ancillary_drv(drv);
+
+	return !!ancillary_match_id(ancildrv->id_table, ancildev);
+}
+
+static int ancillary_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+	const char *name, *p;
+
+	name = dev_name(dev);
+	p = strrchr(name, '.');
+
+	return add_uevent_var(env, "MODALIAS=%s%.*s", ANCILLARY_MODULE_PREFIX, (int)(p - name),
+			      name);
+}
+
+static const struct dev_pm_ops ancillary_dev_pm_ops = {
+	SET_RUNTIME_PM_OPS(pm_generic_runtime_suspend, pm_generic_runtime_resume, NULL)
+	SET_SYSTEM_SLEEP_PM_OPS(pm_generic_suspend, pm_generic_resume)
+};
+
+struct bus_type ancillary_bus_type = {
+	.name = "ancillary",
+	.match = ancillary_match,
+	.uevent = ancillary_uevent,
+	.pm = &ancillary_dev_pm_ops,
+};
+
+/**
+ * ancillary_device_initialize - check ancillary_device and initialize
+ * @ancildev: ancillary device struct
+ *
+ * This is the first step in the two-step process to register an ancillary_device.
+ *
+ * When this function returns an error code, then the device_initialize will *not* have
+ * been performed, and the caller will be responsible to free any memory allocated for the
+ * ancillary_device in the error path directly.
+ *
+ * It returns 0 on success.  On success, the device_initialize has been performed.
+ * After this point any error unwinding will need to include a call to put_device().
+ * In this post-initialize error scenario, a call to the device's .release callback will be
+ * triggered by put_device(), and all memory clean-up is expected to be handled there.
+ */
+int ancillary_device_initialize(struct ancillary_device *ancildev)
+{
+	struct device *dev = &ancildev->dev;
+
+	dev->bus = &ancillary_bus_type;
+
+	if (!dev->parent) {
+		pr_err("ancillary_device has a NULL dev->parent\n");
+		return -EINVAL;
+	}
+
+	if (!ancildev->name) {
+		pr_err("acillary_device has a NULL name\n");
+		return -EINVAL;
+	}
+
+	if (!(dev->type && dev->type->release) && !dev->release) {
+		pr_err("ancillary_device does not have a release callback defined\n");
+		return -EINVAL;
+	}
+
+	device_initialize(&ancildev->dev);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(ancillary_device_initialize);
+
+/**
+ * __ancillary_device_add - add an ancillary bus device
+ * @ancildev: ancillary bus device to add to the bus
+ * @modname: name of the parent device's driver module
+ *
+ * This is the second step in the two-step process to register an ancillary_device.
+ *
+ * This function must be called after a successful call to ancillary_device_initialize(), which
+ * will perform the device_initialize.  This means that if this returns an error code, then a
+ * put_device must be performed so that the .release callback will be triggered to free the
+ * memory associated with the ancillary_device.
+ */
+int __ancillary_device_add(struct ancillary_device *ancildev, const char *modname)
+{
+	struct device *dev = &ancildev->dev;
+	int ret;
+
+	if (!modname) {
+		pr_err("ancillary device modname is NULL\n");
+		return -EINVAL;
+	}
+
+	ret = dev_set_name(dev, "%s.%s.%d", modname, ancildev->name, ancildev->id);
+	if (ret) {

drivers/bus/ancillary.c line 146

Quoted 10 lines
drivers/bus/ancillary.c new file +10 -0
+		pr_err("ancillary device dev_set_name failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = device_add(dev);
+	if (ret)
+		dev_err(dev, "adding ancillary device failed!: %d\n", ret);
+
+	return ret;
+}

Sorry, but this is very strange API that requires users to put internal call to "dev" that is buried inside "struct ancillary_device".

For example in your next patch, you write this "put_device(&cdev->ancildev.dev);"

I'm pretty sure that the amount of bugs in error unwind will be astonishing, so if you are doing wrappers over core code, better do not pass complexity to the users.

Quoted 5 lines
drivers/bus/ancillary.c new file +5 -0
+EXPORT_SYMBOL_GPL(__ancillary_device_add);
+
+static int ancillary_probe_driver(struct device *dev)
+{
+	struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);

drivers/bus/ancillary.c line 161

Quoted 10 lines
drivers/bus/ancillary.c new file +10 -0
+	struct ancillary_device *ancildev = to_ancillary_dev(dev);
+	int ret;
+
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret) {
+		dev_warn(dev, "Failed to attach to PM Domain : %d\n", ret);
+		return ret;
+	}
+
+	ret = ancildrv->probe(ancildev, ancillary_match_id(ancildrv->id_table, ancildev));

I don't think that you need to call ->probe() if ancillary_match_id() returned NULL and probably that check should be done before dev_pm_domain_attach().

Quoted 6 lines
drivers/bus/ancillary.c new file +6 -0
+	if (ret)
+		dev_pm_domain_detach(dev, true);
+
+	return ret;
+}
+

drivers/bus/ancillary.c line 177

Quoted 10 lines
drivers/bus/ancillary.c new file +10 -0
+static int ancillary_remove_driver(struct device *dev)
+{
+	struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
+	struct ancillary_device *ancildev = to_ancillary_dev(dev);
+	int ret;
+
+	ret = ancildrv->remove(ancildev);
+	dev_pm_domain_detach(dev, true);
+
+	return ret;

You returned an error to user and detached from PM, what will user do with this information? Should user ignore it? retry?

Quoted 128 lines
drivers/bus/ancillary.c new file +48 -0
+}
+
+static void ancillary_shutdown_driver(struct device *dev)
+{
+	struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
+	struct ancillary_device *ancildev = to_ancillary_dev(dev);
+
+	ancildrv->shutdown(ancildev);
+}
+
+/**
+ * __ancillary_driver_register - register a driver for ancillary bus devices
+ * @ancildrv: ancillary_driver structure
+ * @owner: owning module/driver
+ */
+int __ancillary_driver_register(struct ancillary_driver *ancildrv, struct module *owner)
+{
+	if (WARN_ON(!ancildrv->probe) || WARN_ON(!ancildrv->remove) ||
+	    WARN_ON(!ancildrv->shutdown) || WARN_ON(!ancildrv->id_table))
+		return -EINVAL;
+
+	ancildrv->driver.owner = owner;
+	ancildrv->driver.bus = &ancillary_bus_type;
+	ancildrv->driver.probe = ancillary_probe_driver;
+	ancildrv->driver.remove = ancillary_remove_driver;
+	ancildrv->driver.shutdown = ancillary_shutdown_driver;
+
+	return driver_register(&ancildrv->driver);
+}
+EXPORT_SYMBOL_GPL(__ancillary_driver_register);
+
+static int __init ancillary_bus_init(void)
+{
+	return bus_register(&ancillary_bus_type);
+}
+
+static void __exit ancillary_bus_exit(void)
+{
+	bus_unregister(&ancillary_bus_type);
+}
+
+module_init(ancillary_bus_init);
+module_exit(ancillary_bus_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Ancillary Bus");
+MODULE_AUTHOR("David Ertman <[email protected]>");
+MODULE_AUTHOR("Kiran Patil <[email protected]>");
include/linux/ancillary_bus.h new file +69 -0
new file mode 100644
index 000000000000..72169c8a5dfe
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2019-2020 Intel Corporation
+ *
+ * Please see Documentation/driver-api/ancillary_bus.rst for more information.
+ */
+
+#ifndef _ANCILLARY_BUS_H_
+#define _ANCILLARY_BUS_H_
+
+#include <linux/device.h>
+#include <linux/mod_devicetable.h>
+#include <linux/slab.h>
+
+struct ancillary_device {
+	struct device dev;
+	const char *name;
+	u32 id;
+};
+
+struct ancillary_driver {
+	int (*probe)(struct ancillary_device *ancildev, const struct ancillary_device_id *id);
+	int (*remove)(struct ancillary_device *ancildev);
+	void (*shutdown)(struct ancillary_device *ancildev);
+	int (*suspend)(struct ancillary_device *ancildev, pm_message_t state);
+	int (*resume)(struct ancillary_device *ancildev);
+	struct device_driver driver;
+	const struct ancillary_device_id *id_table;
+};
+
+static inline struct ancillary_device *to_ancillary_dev(struct device *dev)
+{
+	return container_of(dev, struct ancillary_device, dev);
+}
+
+static inline struct ancillary_driver *to_ancillary_drv(struct device_driver *drv)
+{
+	return container_of(drv, struct ancillary_driver, driver);
+}
+
+int ancillary_device_initialize(struct ancillary_device *ancildev);
+int __ancillary_device_add(struct ancillary_device *ancildev, const char *modname);
+#define ancillary_device_add(ancildev) __ancillary_device_add(ancildev, KBUILD_MODNAME)
+
+static inline void ancillary_device_unregister(struct ancillary_device *ancildev)
+{
+	device_unregister(&ancildev->dev);
+}
+
+int __ancillary_driver_register(struct ancillary_driver *ancildrv, struct module *owner);
+#define ancillary_driver_register(ancildrv) __ancillary_driver_register(ancildrv, THIS_MODULE)
+
+static inline void ancillary_driver_unregister(struct ancillary_driver *ancildrv)
+{
+	driver_unregister(&ancildrv->driver);
+}
+
+/**
+ * module_ancillary_driver() - Helper macro for registering an ancillary driver
+ * @__ancillary_driver: ancillary driver struct
+ *
+ * Helper macro for ancillary drivers which do not do anything special in
+ * module init/exit. This eliminates a lot of boilerplate. Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */
+#define module_ancillary_driver(__ancillary_driver) \
+	module_driver(__ancillary_driver, ancillary_driver_register, ancillary_driver_unregister)
+
+#endif /* _ANCILLARY_BUS_H_ */
include/linux/mod_devicetable.h +0 -0
index 5b08a473cdba..7d596dc30833 100644

include/linux/mod_devicetable.h struct mhi_device_id { · line 845

Quoted 8 lines
include/linux/mod_devicetable.h +5 -0
@@ -838,4 +838,12 @@ struct mhi_device_id {
 	kernel_ulong_t driver_data;
 };
 
+#define ANCILLARY_NAME_SIZE 32
+#define ANCILLARY_MODULE_PREFIX "ancillary:"
+
+struct ancillary_device_id {
+	char name[ANCILLARY_NAME_SIZE];

I hope that this be enough.

Quoted 46 lines
include/linux/mod_devicetable.h +3 -0
+	kernel_ulong_t driver_data;
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
scripts/mod/devicetable-offsets.c +3 -0
index 27007c18e754..79e37c4c25b3 100644
@@ -243,5 +243,8 @@ int main(void)
 	DEVID(mhi_device_id);
 	DEVID_FIELD(mhi_device_id, chan);
 
+	DEVID(ancillary_device_id);
+	DEVID_FIELD(ancillary_device_id, name);
+
 	return 0;
 }
scripts/mod/file2alias.c +8 -1
index 2417dd1dee33..99c4fcd82bf3 100644
@@ -1364,6 +1364,13 @@ static int do_mhi_entry(const char *filename, void *symval, char *alias)
 {
 	DEF_FIELD_ADDR(symval, mhi_device_id, chan);
 	sprintf(alias, MHI_DEVICE_MODALIAS_FMT, *chan);
+	return 1;
+}
+
+static int do_ancillary_entry(const char *filename, void *symval, char *alias)
+{
+	DEF_FIELD_ADDR(symval, ancillary_device_id, name);
+	sprintf(alias, ANCILLARY_MODULE_PREFIX "%s", *name);
 
 	return 1;
 }
@@ -1442,6 +1449,7 @@ static const struct devtable devtable[] = {
 	{"tee", SIZE_tee_client_device_id, do_tee_entry},
 	{"wmi", SIZE_wmi_device_id, do_wmi_entry},
 	{"mhi", SIZE_mhi_device_id, do_mhi_entry},
+	{"ancillary", SIZE_ancillary_device_id, do_ancillary_entry},
 };
 
 /* Create MODULE_ALIAS() statements.
--

2.26.2

#3 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Thanks for the review Leon.

Quoted 5 lines
Quoted 3 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

[...]

Quoted 7 lines

Documentation/driver-api/ancillary_bus.rst line 221

Quoted 4 lines
Documentation/driver-api/ancillary_bus.rst new file +4 -0
+	const struct my_driver my_drv = {
+		.ancillary_drv = {
+			.driver = {
+				.name = "myancillarydrv",

Why do we need to give control over driver name to the driver authors? It can be problematic if author puts name that already exists.

Good point. When I used the ancillary_devices for my own SoundWire test, the driver name didn't seem specifically meaningful but needed to be set to something, what mattered was the id_table. Just thinking aloud, maybe we can add prefixing with KMOD_BUILD, as we've done already to avoid collisions between device names?

[...]

Quoted 26 lines
Quoted 12 lines
drivers/bus/ancillary.c new file +12 -0
+int __ancillary_device_add(struct ancillary_device *ancildev, const char *modname)
+{
+	struct device *dev = &ancildev->dev;
+	int ret;
+
+	if (!modname) {
+		pr_err("ancillary device modname is NULL\n");
+		return -EINVAL;
+	}
+
+	ret = dev_set_name(dev, "%s.%s.%d", modname, ancildev->name, ancildev->id);
+	if (ret) {

drivers/bus/ancillary.c line 146

Quoted 10 lines
drivers/bus/ancillary.c new file +10 -0
+		pr_err("ancillary device dev_set_name failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = device_add(dev);
+	if (ret)
+		dev_err(dev, "adding ancillary device failed!: %d\n", ret);
+
+	return ret;
+}

Sorry, but this is very strange API that requires users to put internal call to "dev" that is buried inside "struct ancillary_device".

Quoted 5 lines

For example in your next patch, you write this "put_device(&cdev->ancildev.dev);"

I'm pretty sure that the amount of bugs in error unwind will be astonishing, so if you are doing wrappers over core code, better do not pass complexity to the users.

In initial reviews, there was pushback on adding wrappers that don't do anything except for a pointer indirection.

Others had concerns that the API wasn't balanced and blurring layers.

Both points have merits IMHO. Do we want wrappers for everything and completely hide the low-level device?

Quoted 12 lines
Quoted 12 lines
drivers/bus/ancillary.c new file +11 -0
+EXPORT_SYMBOL_GPL(__ancillary_device_add);
+
+static int ancillary_probe_driver(struct device *dev)
+{
+	struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
+	struct ancillary_device *ancildev = to_ancillary_dev(dev);
+	int ret;
+
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret) {
+		dev_warn(dev, "Failed to attach to PM Domain : %d\n", ret);
Quoted 8 lines

drivers/bus/ancillary.c line 161

Quoted 4 lines
drivers/bus/ancillary.c new file +4 -0
+		return ret;
+	}
+
+	ret = ancildrv->probe(ancildev, ancillary_match_id(ancildrv->id_table, ancildev));

I don't think that you need to call ->probe() if ancillary_match_id() returned NULL and probably that check should be done before dev_pm_domain_attach().

we'll look into this.

Quoted 12 lines
Quoted 12 lines
drivers/bus/ancillary.c new file +11 -0
+	if (ret)
+		dev_pm_domain_detach(dev, true);
+
+	return ret;
+}
+
+static int ancillary_remove_driver(struct device *dev)
+{
+	struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
+	struct ancillary_device *ancildev = to_ancillary_dev(dev);
+	int ret;
Quoted 8 lines

drivers/bus/ancillary.c line 177

Quoted 5 lines
drivers/bus/ancillary.c new file +5 -0
+
+	ret = ancildrv->remove(ancildev);
+	dev_pm_domain_detach(dev, true);
+
+	return ret;

You returned an error to user and detached from PM, what will user do with this information? Should user ignore it? retry?

That comment was also provided in earlier reviews. In practice the error is typically ignored so there was a suggestion to move the return type to void, that could be done if this was desired by the majority.

[...]

Quoted 8 lines
Quoted 8 lines
include/linux/mod_devicetable.h +0 -0
index 5b08a473cdba..7d596dc30833 100644
@@ -838,4 +838,12 @@ struct mhi_device_id {
  	kernel_ulong_t driver_data;
  };
 
Quoted 7 lines

include/linux/mod_devicetable.h struct mhi_device_id { · line 845

Quoted 5 lines
include/linux/mod_devicetable.h +5 -0
+#define ANCILLARY_NAME_SIZE 32
+#define ANCILLARY_MODULE_PREFIX "ancillary:"
+
+struct ancillary_device_id {
+	char name[ANCILLARY_NAME_SIZE];

I hope that this be enough.

Are you suggesting a different value to allow for a longer string?

#4 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 9 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 5 lines
Quoted 3 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Quoted 11 lines

[...]

Quoted 7 lines

Documentation/driver-api/ancillary_bus.rst line 221

Quoted 4 lines
Documentation/driver-api/ancillary_bus.rst new file +4 -0
+	const struct my_driver my_drv = {
+		.ancillary_drv = {
+			.driver = {
+				.name = "myancillarydrv",

Why do we need to give control over driver name to the driver authors? It can be problematic if author puts name that already exists.

Quoted 5 lines

Good point. When I used the ancillary_devices for my own SoundWire test, the driver name didn't seem specifically meaningful but needed to be set to something, what mattered was the id_table. Just thinking aloud, maybe we can add prefixing with KMOD_BUILD, as we've done already to avoid collisions between device names?

IMHO, it shouldn't be controlled by the drivers at all and need to have kernel module name hardwired. Users will use it later for various bind/unbind/autoprobe tricks and it will give predictability for them.

Quoted 31 lines

[...]

Quoted 28 lines
Quoted 12 lines
drivers/bus/ancillary.c new file +12 -0
+int __ancillary_device_add(struct ancillary_device *ancildev, const char *modname)
+{
+	struct device *dev = &ancildev->dev;
+	int ret;
+
+	if (!modname) {
+		pr_err("ancillary device modname is NULL\n");
+		return -EINVAL;
+	}
+
+	ret = dev_set_name(dev, "%s.%s.%d", modname, ancildev->name, ancildev->id);
+	if (ret) {

drivers/bus/ancillary.c line 146

Quoted 10 lines
drivers/bus/ancillary.c new file +10 -0
+		pr_err("ancillary device dev_set_name failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = device_add(dev);
+	if (ret)
+		dev_err(dev, "adding ancillary device failed!: %d\n", ret);
+
+	return ret;
+}

Sorry, but this is very strange API that requires users to put internal call to "dev" that is buried inside "struct ancillary_device".

For example in your next patch, you write this "put_device(&cdev->ancildev.dev);"

Quoted 8 lines
Quoted 3 lines

I'm pretty sure that the amount of bugs in error unwind will be astonishing, so if you are doing wrappers over core code, better do not pass complexity to the users.

In initial reviews, there was pushback on adding wrappers that don't do anything except for a pointer indirection.

Others had concerns that the API wasn't balanced and blurring layers.

Are you talking about internal review or public?
If it is public, can I get a link to it?

Quoted 3 lines

Both points have merits IMHO. Do we want wrappers for everything and completely hide the low-level device?

This API is partially obscures low level driver-core code and needs to provide clear and proper abstractions without need to remember about put_device. There is already _add() interface why don't you do put_device() in it?

Quoted 45 lines
Quoted 13 lines
Quoted 13 lines
drivers/bus/ancillary.c new file +11 -0
+EXPORT_SYMBOL_GPL(__ancillary_device_add);
+
+static int ancillary_probe_driver(struct device *dev)
+{
+	struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
+	struct ancillary_device *ancildev = to_ancillary_dev(dev);
+	int ret;
+
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret) {
+		dev_warn(dev, "Failed to attach to PM Domain : %d\n", ret);
Quoted 8 lines

drivers/bus/ancillary.c line 161

Quoted 4 lines
drivers/bus/ancillary.c new file +4 -0
+		return ret;
+	}
+
+	ret = ancildrv->probe(ancildev, ancillary_match_id(ancildrv->id_table, ancildev));

I don't think that you need to call ->probe() if ancillary_match_id() returned NULL and probably that check should be done before dev_pm_domain_attach().

we'll look into this.

Quoted 12 lines
Quoted 12 lines
drivers/bus/ancillary.c new file +11 -0
+	if (ret)
+		dev_pm_domain_detach(dev, true);
+
+	return ret;
+}
+
+static int ancillary_remove_driver(struct device *dev)
+{
+	struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
+	struct ancillary_device *ancildev = to_ancillary_dev(dev);
+	int ret;
Quoted 8 lines

drivers/bus/ancillary.c line 177

Quoted 5 lines
drivers/bus/ancillary.c new file +5 -0
+
+	ret = ancildrv->remove(ancildev);
+	dev_pm_domain_detach(dev, true);
+
+	return ret;

You returned an error to user and detached from PM, what will user do with this information? Should user ignore it? retry?

Quoted 3 lines

That comment was also provided in earlier reviews. In practice the error is typically ignored so there was a suggestion to move the return type to void, that could be done if this was desired by the majority.

+1 from me.

Quoted 19 lines

[...]

Quoted 8 lines
Quoted 8 lines
include/linux/mod_devicetable.h +0 -0
index 5b08a473cdba..7d596dc30833 100644
@@ -838,4 +838,12 @@ struct mhi_device_id {
  	kernel_ulong_t driver_data;
  };
 
Quoted 7 lines

include/linux/mod_devicetable.h struct mhi_device_id { · line 845

Quoted 5 lines
include/linux/mod_devicetable.h +5 -0
+#define ANCILLARY_NAME_SIZE 32
+#define ANCILLARY_MODULE_PREFIX "ancillary:"
+
+struct ancillary_device_id {
+	char name[ANCILLARY_NAME_SIZE];

I hope that this be enough.

Quoted 1 line

Are you suggesting a different value to allow for a longer string?

I have no idea, but worried that there were no checks at all if name is more than 32. Maybe compiler warn about it?

Thanks

#5 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 11 lines

From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:33 PM

Quoted 6 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 4 lines
Quoted 3 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Since the intended use of this bus is to
(a) create sub devices that represent 'functional separation' and
(b) second use case for subfunctions from a pci device,

I proposed below names in v1 of this patchset.

(a) subdev_bus
(b) subfunction_bus

#6 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 17 lines · Parav Pandit
Quoted 11 lines

From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:33 PM

Quoted 6 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 4 lines
Quoted 3 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Quoted 7 lines

Since the intended use of this bus is to
(a) create sub devices that represent 'functional separation' and
(b) second use case for subfunctions from a pci device,

I proposed below names in v1 of this patchset.

(a) subdev_bus

It sounds good, just can we avoid "_" in the name and call it subdev?

Quoted 1 line

(b) subfunction_bus

#7 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 24 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 21 lines · Parav Pandit
Quoted 11 lines

From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:33 PM

Quoted 6 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 4 lines
Quoted 3 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Since the intended use of this bus is to
(a) create sub devices that represent 'functional separation' and
(b) second use case for subfunctions from a pci device,

Quoted 6 lines
Quoted 3 lines

I proposed below names in v1 of this patchset.

(a) subdev_bus

It sounds good, just can we avoid "_" in the name and call it subdev?

What is wrong with naming the bus 'ancillary bus'? I feel it's a fitting name.
An ancillary software bus for ancillary devices carved off a parent device registered on a primary bus.

#8 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 26 lines · Shiraz
Quoted 26 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 23 lines · Parav Pandit
Quoted 11 lines

From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:33 PM

Quoted 6 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 4 lines
Quoted 3 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Since the intended use of this bus is to
(a) create sub devices that represent 'functional separation' and
(b) second use case for subfunctions from a pci device,

I proposed below names in v1 of this patchset.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

(a) subdev_bus

It sounds good, just can we avoid "_" in the name and call it subdev?

What is wrong with naming the bus 'ancillary bus'? I feel it's a fitting name.
An ancillary software bus for ancillary devices carved off a parent device registered on a primary bus.

Greg summarized it very well, every internal conversation about this patch with my colleagues (non-english speakers) starts with the question:
"What does ancillary mean?"
https://lore.kernel.org/alsa-devel/[email protected]/

"For non-native english speakers this is going to be rough, given that I as a native english speaker had to go look up the word in a dictionary to fully understand what you are trying to do with that name."

Thanks

Quoted 3 lines
#9 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 41 lines · Leon Romanovsky
Quoted 26 lines · Shiraz
Quoted 26 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 23 lines · Parav Pandit
Quoted 11 lines

From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:33 PM

Quoted 6 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 4 lines
Quoted 3 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Since the intended use of this bus is to
(a) create sub devices that represent 'functional separation' and
(b) second use case for subfunctions from a pci device,

I proposed below names in v1 of this patchset.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

(a) subdev_bus

It sounds good, just can we avoid "_" in the name and call it subdev?

What is wrong with naming the bus 'ancillary bus'? I feel it's a fitting name.
An ancillary software bus for ancillary devices carved off a parent device registered on a primary bus.

Greg summarized it very well, every internal conversation about this patch with my colleagues (non-english speakers) starts with the question:
"What does ancillary mean?"
https://lore.kernel.org/alsa-devel/[email protected]/

Quoted 4 lines

"For non-native english speakers this is going to be rough, given that I as a native english speaker had to go look up the word in a dictionary to fully understand what you are trying to do with that name."

I suggested "auxiliary" in another splintered thread on this question. In terms of what the kernel is already using:

$ git grep auxiliary | wc -l
507
$ git grep ancillary | wc -l
153

Empirically, "auxiliary" is more common and closely matches the intended function of these devices relative to their parent device.

#10 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 55 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 6 lines · Leon Romanovsky
Quoted 4 lines · Shiraz
Quoted 4 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 1 line · Parav Pandit
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:33 PM

Quoted 3 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 1 line
Quoted 1 line

Add support for the Ancillary Bus, ancillary_device and

ancillary_driver.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Since the intended use of this bus is to
(a) create sub devices that represent 'functional separation' and
(b) second use case for subfunctions from a pci device,

I proposed below names in v1 of this patchset.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

(a) subdev_bus

It sounds good, just can we avoid "_" in the name and call it subdev?

What is wrong with naming the bus 'ancillary bus'? I feel it's a fitting name. An ancillary software bus for ancillary devices carved off a parent device

registered on a primary bus.

Quoted 10 lines

Greg summarized it very well, every internal conversation about this patch with my colleagues (non-english speakers) starts with the question:
"What does ancillary mean?"
https://lore.kernel.org/alsa-devel/[email protected]/

"For non-native english speakers this is going to be rough, given that I as a native english speaker had to go look up the word in a dictionary to fully understand what you are trying to do with that name."

I suggested "auxiliary" in another splintered thread on this question. In terms of what the kernel is already using:

Quoted 7 lines
$ git grep auxiliary | wc -l
507
$ git grep ancillary | wc -l
153

Empirically, "auxiliary" is more common and closely matches the intended function of these devices relative to their parent device.

auxiliary bus is a befitting name as well.

#11 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 60 lines · Shiraz
Quoted 60 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 6 lines · Leon Romanovsky
Quoted 4 lines · Shiraz
Quoted 4 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 1 line · Parav Pandit
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:33 PM

Quoted 3 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 1 line
Quoted 1 line

Add support for the Ancillary Bus, ancillary_device and

ancillary_driver.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Since the intended use of this bus is to
(a) create sub devices that represent 'functional separation' and
(b) second use case for subfunctions from a pci device,

I proposed below names in v1 of this patchset.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

(a) subdev_bus

It sounds good, just can we avoid "_" in the name and call it subdev?

What is wrong with naming the bus 'ancillary bus'? I feel it's a fitting name. An ancillary software bus for ancillary devices carved off a parent device

registered on a primary bus.

Quoted 10 lines

Greg summarized it very well, every internal conversation about this patch with my colleagues (non-english speakers) starts with the question:
"What does ancillary mean?"
https://lore.kernel.org/alsa-devel/[email protected]/

"For non-native english speakers this is going to be rough, given that I as a native english speaker had to go look up the word in a dictionary to fully understand what you are trying to do with that name."

I suggested "auxiliary" in another splintered thread on this question. In terms of what the kernel is already using:

$ git grep auxiliary | wc -l
507
$ git grep ancillary | wc -l
153
Quoted 4 lines
Quoted 2 lines

Empirically, "auxiliary" is more common and closely matches the intended function of these devices relative to their parent device.

auxiliary bus is a befitting name as well.

Let's share all options and decide later.
I don't want to find us bikeshedding about it.

Thanks

#12 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 62 lines · Leon Romanovsky
Quoted 60 lines · Shiraz
Quoted 60 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 6 lines · Leon Romanovsky
Quoted 4 lines · Shiraz
Quoted 4 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 1 line · Parav Pandit
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:33 PM

Quoted 3 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 1 line
Quoted 1 line

Add support for the Ancillary Bus, ancillary_device and

ancillary_driver.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Since the intended use of this bus is to
(a) create sub devices that represent 'functional separation' and
(b) second use case for subfunctions from a pci device,

I proposed below names in v1 of this patchset.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

(a) subdev_bus

It sounds good, just can we avoid "_" in the name and call it subdev?

What is wrong with naming the bus 'ancillary bus'? I feel it's a fitting name. An ancillary software bus for ancillary devices carved off a parent device

registered on a primary bus.

Quoted 10 lines

Greg summarized it very well, every internal conversation about this patch with my colleagues (non-english speakers) starts with the question:
"What does ancillary mean?"
https://lore.kernel.org/alsa-devel/[email protected]/

"For non-native english speakers this is going to be rough, given that I as a native english speaker had to go look up the word in a dictionary to fully understand what you are trying to do with that name."

I suggested "auxiliary" in another splintered thread on this question. In terms of what the kernel is already using:

$ git grep auxiliary | wc -l
507
$ git grep ancillary | wc -l
153
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Empirically, "auxiliary" is more common and closely matches the intended function of these devices relative to their parent device.

auxiliary bus is a befitting name as well.

Let's share all options and decide later.
I don't want to find us bikeshedding about it.

Too late we are deep into bikeshedding at this point... it continued over here [1] for a bit, but let's try to bring the discussion back to this thread.

[1]: http://lore.kernel.org/r/[email protected]

#13 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 97 lines

-----Original Message-----
From: Dan Williams <[email protected]>
Sent: Wednesday, October 7, 2020 11:56 AM
To: Leon Romanovsky <[email protected]>
Cc: Saleem, Shiraz <[email protected]>; Parav Pandit <[email protected]>; Pierre-Louis Bossart <pierre- [email protected]>; Ertman, David M <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 5 lines · Leon Romanovsky
Quoted 3 lines · Shiraz
Quoted 3 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

On Tue, Oct 6, 2020 at 12:21 PM Leon Romanovsky <[email protected]>

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines · Shiraz
Quoted 8 lines
Quoted 8 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 5 lines · Parav Pandit
Quoted 5 lines

From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:33 PM

On Tue, Oct 06, 2020 at 10:18:07AM -0500, Pierre-Louis Bossart

Quoted 8 lines · wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Thanks for the review Leon.

Quoted 1 line
Quoted 1 line

Add support for the Ancillary Bus, ancillary_device and

ancillary_driver.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be

changed.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Since the intended use of this bus is to
(a) create sub devices that represent 'functional separation' and
(b) second use case for subfunctions from a pci device,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

I proposed below names in v1 of this patchset.

(a) subdev_bus

It sounds good, just can we avoid "_" in the name and call it

subdev?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

What is wrong with naming the bus 'ancillary bus'? I feel it's a fitting

name.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

An ancillary software bus for ancillary devices carved off a parent

device

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

registered on a primary bus.

Quoted 3 lines

Greg summarized it very well, every internal conversation about this patch with my colleagues (non-english speakers) starts with the

question:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"What does ancillary mean?"
https://lore.kernel.org/alsa-

devel/[email protected]/

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

"For non-native english speakers this is going to be rough, given that I as a native english speaker had to go look up the word in a dictionary to fully understand what you are trying to do with that name."

I suggested "auxiliary" in another splintered thread on this question. In terms of what the kernel is already using:

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
$ git grep auxiliary | wc -l
507
$ git grep ancillary | wc -l
153

Empirically, "auxiliary" is more common and closely matches the

intended function

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

of these devices relative to their parent device.

auxiliary bus is a befitting name as well.

Let's share all options and decide later.
I don't want to find us bikeshedding about it.

Quoted 6 lines

Too late we are deep into bikeshedding at this point... it continued over here [1] for a bit, but let's try to bring the discussion back to this thread.

[1]: http://lore.kernel.org/r/10048d4d-038c-c2b7-2ed7-
[email protected]

Out of all of the suggestions put forward so far that do not have real objections to them ...

I would put my vote behind aux - short, simple, meaningful

-DaveE

#14 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

In reply to Leon Romanovsky
Quoted 24 lines · Leon Romanovsky
Quoted 23 lines · Parav Pandit
Quoted 13 lines

From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:33 PM

Quoted 8 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 6 lines
Quoted 5 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver.
It enables drivers to create an ancillary_device and bind an
ancillary_driver to it.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Since the intended use of this bus is to
(a) create sub devices that represent 'functional separation' and
(b) second use case for subfunctions from a pci device,

Quoted 7 lines
Quoted 3 lines

I proposed below names in v1 of this patchset.

(a) subdev_bus

It sounds good, just can we avoid "_" in the name and call it subdev?

Quoted 1 line

(b) subfunction_bus

While we're still discussing names, may I also suggest simply "software bus" instead?

Thanks,Ranjani

#15 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

In reply to Leon Romanovsky
Quoted 33 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 9 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 5 lines
Quoted 3 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Quoted 11 lines

[...]

Quoted 7 lines

Documentation/driver-api/ancillary_bus.rst line 221

Quoted 4 lines
Documentation/driver-api/ancillary_bus.rst new file +4 -0
+	const struct my_driver my_drv = {
+		.ancillary_drv = {
+			.driver = {
+				.name = "myancillarydrv",

Why do we need to give control over driver name to the driver authors? It can be problematic if author puts name that already exists.

Quoted 5 lines

Good point. When I used the ancillary_devices for my own SoundWire test, the driver name didn't seem specifically meaningful but needed to be set to something, what mattered was the id_table. Just thinking aloud, maybe we can add prefixing with KMOD_BUILD, as we've done already to avoid collisions between device names?

Quoted 4 lines

IMHO, it shouldn't be controlled by the drivers at all and need to have kernel module name hardwired. Users will use it later for various bind/unbind/autoprobe tricks and it will give predictability for them.

+1. This name is not used in the match. Having the bus hardwire the modname sounds like a good idea.

Shiraz

#16 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

In reply to Leon Romanovsky
Quoted 98 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:03 AM
To: Pierre-Louis Bossart <[email protected]>
Cc: Ertman, David M <[email protected]>; alsa-devel@alsa- project.org; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 9 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 5 lines
Quoted 3 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Quoted 11 lines

[...]

Quoted 7 lines

Documentation/driver-api/ancillary_bus.rst line 221

Quoted 4 lines
Documentation/driver-api/ancillary_bus.rst new file +4 -0
+	const struct my_driver my_drv = {
+		.ancillary_drv = {
+			.driver = {
+				.name = "myancillarydrv",

Why do we need to give control over driver name to the driver authors? It can be problematic if author puts name that already exists.

Quoted 1 line

Good point. When I used the ancillary_devices for my own SoundWire test,

the

Quoted 2 lines

driver name didn't seem specifically meaningful but needed to be set to something, what mattered was the id_table. Just thinking aloud, maybe we

can

Quoted 2 lines

add prefixing with KMOD_BUILD, as we've done already to avoid collisions between device names?

IMHO, it shouldn't be controlled by the drivers at all and need to have kernel module name hardwired. Users will use it later for various bind/unbind/autoprobe tricks and it will give predictability for them.

Quoted 4 lines

[...]

Quoted 1 line
Quoted 1 line

+int __ancillary_device_add(struct ancillary_device *ancildev, const

char *modname)

Quoted 10 lines
Quoted 10 lines

drivers/bus/ancillary.c

Quoted 10 lines
drivers/bus/ancillary.c new file +10 -0
+{
+	struct device *dev = &ancildev->dev;
+	int ret;
+
+	if (!modname) {
+		pr_err("ancillary device modname is NULL\n");
+		return -EINVAL;
+	}
+
+	ret = dev_set_name(dev, "%s.%s.%d", modname, ancildev->name,

ancildev->id);

Quoted 18 lines
Quoted 15 lines

drivers/bus/ancillary.c line 146

Quoted 11 lines
drivers/bus/ancillary.c new file +11 -0
+	if (ret) {
+		pr_err("ancillary device dev_set_name failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = device_add(dev);
+	if (ret)
+		dev_err(dev, "adding ancillary device failed!: %d\n", ret);
+
+	return ret;
+}

Sorry, but this is very strange API that requires users to put internal call to "dev" that is buried inside "struct ancillary_device".

Quoted 1 line

For example in your next patch, you write this "put_device(&cdev-

ancildev.dev);"

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

I'm pretty sure that the amount of bugs in error unwind will be astonishing, so if you are doing wrappers over core code, better do not pass complexity to the users.

In initial reviews, there was pushback on adding wrappers that don't do anything except for a pointer indirection.

Others had concerns that the API wasn't balanced and blurring layers.

Are you talking about internal review or public?
If it is public, can I get a link to it?

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Both points have merits IMHO. Do we want wrappers for everything and completely hide the low-level device?

This API is partially obscures low level driver-core code and needs to provide clear and proper abstractions without need to remember about put_device. There is already _add() interface why don't you do put_device() in it?

The pushback Pierre is referring to was during our mid-tier internal review. It was primarily a concern of Parav as I recall, so he can speak to his reasoning.

What we originally had was a single API call (ancillary_device_register) that started with a call to device_initialize(), and every error path out of the function performed a put_device().

Is this the model you have in mind?

-DaveE

Quoted 78 lines
Quoted 46 lines
Quoted 17 lines
Quoted 7 lines
drivers/bus/ancillary.c new file +5 -0
+EXPORT_SYMBOL_GPL(__ancillary_device_add);
+
+static int ancillary_probe_driver(struct device *dev)
+{
+	struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);

drivers/bus/ancillary.c

Quoted 10 lines
drivers/bus/ancillary.c new file +10 -0
+	struct ancillary_device *ancildev = to_ancillary_dev(dev);
+	int ret;
+
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret) {
+		dev_warn(dev, "Failed to attach to PM Domain : %d\n", ret);
+		return ret;
+	}
+
+	ret = ancildrv->probe(ancildev, ancillary_match_id(ancildrv-

id_table, ancildev));

Quoted 4 lines

I don't think that you need to call ->probe() if ancillary_match_id() returned NULL and probably that check should be done before dev_pm_domain_attach().

we'll look into this.

Quoted 12 lines
Quoted 12 lines
drivers/bus/ancillary.c new file +11 -0
+	if (ret)
+		dev_pm_domain_detach(dev, true);
+
+	return ret;
+}
+
+static int ancillary_remove_driver(struct device *dev)
+{
+	struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
+	struct ancillary_device *ancildev = to_ancillary_dev(dev);
+	int ret;
Quoted 8 lines

drivers/bus/ancillary.c line 177

Quoted 5 lines
drivers/bus/ancillary.c new file +5 -0
+
+	ret = ancildrv->remove(ancildev);
+	dev_pm_domain_detach(dev, true);
+
+	return ret;

You returned an error to user and detached from PM, what will user do with this information? Should user ignore it? retry?

Quoted 3 lines

That comment was also provided in earlier reviews. In practice the error is typically ignored so there was a suggestion to move the return type to void, that could be done if this was desired by the majority.

+1 from me.

Quoted 4 lines

[...]

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/include/linux/mod_devicetable.h

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines

index 5b08a473cdba..7d596dc30833 100644

include/linux/mod_devicetable.h +0 -0
@@ -838,4 +838,12 @@ struct mhi_device_id {
  	kernel_ulong_t driver_data;
  };
 
Quoted 7 lines

include/linux/mod_devicetable.h struct mhi_device_id { · line 845

Quoted 5 lines
include/linux/mod_devicetable.h +5 -0
+#define ANCILLARY_NAME_SIZE 32
+#define ANCILLARY_MODULE_PREFIX "ancillary:"
+
+struct ancillary_device_id {
+	char name[ANCILLARY_NAME_SIZE];

I hope that this be enough.

Quoted 1 line

Are you suggesting a different value to allow for a longer string?

I have no idea, but worried that there were no checks at all if name is more than 32. Maybe compiler warn about it?

Thanks

#17 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 107 lines · David M
Quoted 98 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:03 AM
To: Pierre-Louis Bossart <[email protected]>
Cc: Ertman, David M <[email protected]>; alsa-devel@alsa- project.org; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 9 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 5 lines
Quoted 3 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Quoted 11 lines

[...]

Quoted 7 lines

Documentation/driver-api/ancillary_bus.rst line 221

Quoted 4 lines
Documentation/driver-api/ancillary_bus.rst new file +4 -0
+	const struct my_driver my_drv = {
+		.ancillary_drv = {
+			.driver = {
+				.name = "myancillarydrv",

Why do we need to give control over driver name to the driver authors? It can be problematic if author puts name that already exists.

Quoted 1 line

Good point. When I used the ancillary_devices for my own SoundWire test,

the

Quoted 2 lines

driver name didn't seem specifically meaningful but needed to be set to something, what mattered was the id_table. Just thinking aloud, maybe we

can

Quoted 2 lines

add prefixing with KMOD_BUILD, as we've done already to avoid collisions between device names?

IMHO, it shouldn't be controlled by the drivers at all and need to have kernel module name hardwired. Users will use it later for various bind/unbind/autoprobe tricks and it will give predictability for them.

Quoted 4 lines

[...]

Quoted 1 line
Quoted 1 line

+int __ancillary_device_add(struct ancillary_device *ancildev, const

char *modname)

Quoted 10 lines
Quoted 10 lines

drivers/bus/ancillary.c

Quoted 10 lines
drivers/bus/ancillary.c new file +10 -0
+{
+	struct device *dev = &ancildev->dev;
+	int ret;
+
+	if (!modname) {
+		pr_err("ancillary device modname is NULL\n");
+		return -EINVAL;
+	}
+
+	ret = dev_set_name(dev, "%s.%s.%d", modname, ancildev->name,

ancildev->id);

Quoted 18 lines
Quoted 15 lines

drivers/bus/ancillary.c line 146

Quoted 11 lines
drivers/bus/ancillary.c new file +11 -0
+	if (ret) {
+		pr_err("ancillary device dev_set_name failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = device_add(dev);
+	if (ret)
+		dev_err(dev, "adding ancillary device failed!: %d\n", ret);
+
+	return ret;
+}

Sorry, but this is very strange API that requires users to put internal call to "dev" that is buried inside "struct ancillary_device".

Quoted 1 line

For example in your next patch, you write this "put_device(&cdev-

ancildev.dev);"

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

I'm pretty sure that the amount of bugs in error unwind will be astonishing, so if you are doing wrappers over core code, better do not pass complexity to the users.

In initial reviews, there was pushback on adding wrappers that don't do anything except for a pointer indirection.

Others had concerns that the API wasn't balanced and blurring layers.

Are you talking about internal review or public?
If it is public, can I get a link to it?

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Both points have merits IMHO. Do we want wrappers for everything and completely hide the low-level device?

This API is partially obscures low level driver-core code and needs to provide clear and proper abstractions without need to remember about put_device. There is already _add() interface why don't you do put_device() in it?

Quoted 8 lines

The pushback Pierre is referring to was during our mid-tier internal review. It was primarily a concern of Parav as I recall, so he can speak to his reasoning.

What we originally had was a single API call (ancillary_device_register) that started with a call to device_initialize(), and every error path out of the function performed a put_device().

Is this the model you have in mind?

I don't like this flow:
ancillary_device_initialize()
if (ancillary_ancillary_device_add()) {
put_device(....)
ancillary_device_unregister()
return err;
}

And prefer this flow:
ancillary_device_initialize()
if (ancillary_device_add()) {
ancillary_device_unregister()
return err;
}

In this way, the ancillary users won't need to do non-intuitive put_device();

Thanks

#18 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 155 lines

-----Original Message-----
From: Alsa-devel <[email protected]> On Behalf Of Leon Romanovsky
Sent: Wednesday, October 7, 2020 12:26 PM
To: Ertman, David M <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Pierre-Louis Bossart <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 6 lines · David M
Quoted 6 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:03 AM
To: Pierre-Louis Bossart <[email protected]>
Cc: Ertman, David M <[email protected]>; alsa-devel@alsa- project.org; [email protected]; [email protected];

[email protected];

Quoted 3 lines
Quoted 3 lines

[email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

Williams,

Quoted 9 lines
Quoted 9 lines

Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 3 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 1 line
Quoted 1 line

Add support for the Ancillary Bus, ancillary_device and

ancillary_driver.

Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Quoted 1 line
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[...]

Quoted 6 lines

Documentation/driver-api/ancillary_bus.rst line 221

Quoted 4 lines
Documentation/driver-api/ancillary_bus.rst new file +4 -0
+	const struct my_driver my_drv = {
+		.ancillary_drv = {
+			.driver = {
+				.name = "myancillarydrv",

Why do we need to give control over driver name to the driver

authors?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

It can be problematic if author puts name that already exists.

Good point. When I used the ancillary_devices for my own SoundWire

test,

Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines

driver name didn't seem specifically meaningful but needed to be set to something, what mattered was the id_table. Just thinking aloud, maybe

we

Quoted 2 lines
Quoted 2 lines

can

Quoted 1 line

add prefixing with KMOD_BUILD, as we've done already to avoid

collisions

Quoted 22 lines
Quoted 11 lines
Quoted 1 line

between device names?

IMHO, it shouldn't be controlled by the drivers at all and need to have kernel module name hardwired. Users will use it later for various bind/unbind/autoprobe tricks and it will give predictability for them.

Quoted 4 lines

[...]

Quoted 1 line
Quoted 1 line

+int __ancillary_device_add(struct ancillary_device *ancildev, const

char *modname)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/bus/ancillary.c

Quoted 10 lines
drivers/bus/ancillary.c new file +10 -0
+{
+	struct device *dev = &ancildev->dev;
+	int ret;
+
+	if (!modname) {
+		pr_err("ancillary device modname is NULL\n");
+		return -EINVAL;
+	}
+
+	ret = dev_set_name(dev, "%s.%s.%d", modname, ancildev-

name,

Quoted 3 lines
Quoted 3 lines

ancildev->id);

Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (ret) {
+		pr_err("ancillary device dev_set_name failed: %d\n",

ret);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/bus/ancillary.c

Quoted 6 lines
drivers/bus/ancillary.c new file +6 -0
+		return ret;
+	}
+
+	ret = device_add(dev);
+	if (ret)
+		dev_err(dev, "adding ancillary device failed!: %d\n",

ret);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/bus/ancillary.c line 139

Quoted 3 lines
drivers/bus/ancillary.c new file +3 -0
+
+	return ret;
+}

Sorry, but this is very strange API that requires users to put internal call to "dev" that is buried inside "struct ancillary_device".

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

For example in your next patch, you write this "put_device(&cdev-

ancildev.dev);"

Quoted 3 lines

I'm pretty sure that the amount of bugs in error unwind will be astonishing, so if you are doing wrappers over core code, better do

not

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

pass complexity to the users.

In initial reviews, there was pushback on adding wrappers that don't do anything except for a pointer indirection.

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

Others had concerns that the API wasn't balanced and blurring layers.

Are you talking about internal review or public?
If it is public, can I get a link to it?

Quoted 2 lines

Both points have merits IMHO. Do we want wrappers for everything

and

Quoted 9 lines
Quoted 7 lines
Quoted 1 line

completely hide the low-level device?

This API is partially obscures low level driver-core code and needs to provide clear and proper abstractions without need to remember about put_device. There is already _add() interface why don't you do put_device() in it?

The pushback Pierre is referring to was during our mid-tier internal review.

It was

Quoted 3 lines

primarily a concern of Parav as I recall, so he can speak to his reasoning.

What we originally had was a single API call (ancillary_device_register) that

started

Quoted 1 line

with a call to device_initialize(), and every error path out of the function

performed

Quoted 3 lines

a put_device().

Is this the model you have in mind?

I don't like this flow:
ancillary_device_initialize()
if (ancillary_ancillary_device_add()) {
put_device(....)
ancillary_device_unregister()
return err;
}

Quoted 8 lines

And prefer this flow:
ancillary_device_initialize()
if (ancillary_device_add()) {
ancillary_device_unregister()
return err;
}

In this way, the ancillary users won't need to do non-intuitive put_device();

Isn't there a problem calling device_unregister() if device_add() fails? device_unregister() does a device_del() and if the device_add() failed there is nothing to delete?

-DaveE

Quoted 2 lines

Thanks

#19 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 184 lines

-----Original Message-----
From: Ertman, David M
Sent: Wednesday, October 7, 2020 12:54 PM
To: 'Leon Romanovsky' <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Pierre-Louis Bossart <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 2 lines

-----Original Message-----
From: Alsa-devel <[email protected]> On Behalf Of

Leon

Quoted 48 lines

Romanovsky
Sent: Wednesday, October 7, 2020 12:26 PM
To: Ertman, David M <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Pierre-Louis Bossart <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 6 lines · David M
Quoted 6 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:03 AM
To: Pierre-Louis Bossart <[email protected]>
Cc: Ertman, David M <[email protected]>; alsa-devel@alsa- project.org; [email protected]; [email protected];

[email protected];

Quoted 3 lines
Quoted 3 lines

[email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

Williams,

Quoted 9 lines
Quoted 9 lines

Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 3 lines · Pierre-Louis Bossart

Thanks for the review Leon.

Quoted 1 line
Quoted 1 line

Add support for the Ancillary Bus, ancillary_device and

ancillary_driver.

Quoted 13 lines
Quoted 13 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

ok, so what are the variants?
system bus (sysbus), sbsystem bus (subbus), crossbus ?

Quoted 3 lines

[...]

Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+	const struct my_driver my_drv = {
+		.ancillary_drv = {
+			.driver = {
+				.name = "myancillarydrv",

Why do we need to give control over driver name to the driver

authors?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

It can be problematic if author puts name that already exists.

Good point. When I used the ancillary_devices for my own

SoundWire

Quoted 3 lines

test,

Quoted 2 lines
Quoted 2 lines

the

Quoted 1 line

driver name didn't seem specifically meaningful but needed to be set

to

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

something, what mattered was the id_table. Just thinking aloud,

maybe

Quoted 14 lines

we

Quoted 2 lines
Quoted 2 lines

can

Quoted 1 line

add prefixing with KMOD_BUILD, as we've done already to avoid

collisions

Quoted 10 lines
Quoted 10 lines
Quoted 1 line

between device names?

IMHO, it shouldn't be controlled by the drivers at all and need to have kernel module name hardwired. Users will use it later for various bind/unbind/autoprobe tricks and it will give predictability for them.

Quoted 4 lines

[...]

Quoted 1 line
Quoted 1 line

+int __ancillary_device_add(struct ancillary_device *ancildev,

const

Quoted 30 lines
Quoted 12 lines
Quoted 11 lines

char *modname)

Quoted 10 lines
Quoted 10 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+{
+	struct device *dev = &ancildev->dev;
+	int ret;
+
+	if (!modname) {
+		pr_err("ancillary device modname is NULL\n");
+		return -EINVAL;
+	}
+
+	ret = dev_set_name(dev, "%s.%s.%d", modname, ancildev-

name,

Quoted 3 lines
Quoted 3 lines

ancildev->id);

Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (ret) {
+		pr_err("ancillary device dev_set_name failed: %d\n",

ret);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+		return ret;
+	}
+
+	ret = device_add(dev);
+	if (ret)
+		dev_err(dev, "adding ancillary device failed!: %d\n",

ret);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+
+	return ret;
+}

Sorry, but this is very strange API that requires users to put internal call to "dev" that is buried inside "struct ancillary_device".

Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

For example in your next patch, you write this "put_device(&cdev-

ancildev.dev);"

Quoted 3 lines

I'm pretty sure that the amount of bugs in error unwind will be astonishing, so if you are doing wrappers over core code, better do

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

pass complexity to the users.

In initial reviews, there was pushback on adding wrappers that don't

do

Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

anything except for a pointer indirection.

Others had concerns that the API wasn't balanced and blurring layers.

Are you talking about internal review or public?
If it is public, can I get a link to it?

Quoted 2 lines

Both points have merits IMHO. Do we want wrappers for everything

and

Quoted 9 lines
Quoted 7 lines
Quoted 1 line

completely hide the low-level device?

This API is partially obscures low level driver-core code and needs to provide clear and proper abstractions without need to remember about put_device. There is already _add() interface why don't you do put_device() in it?

The pushback Pierre is referring to was during our mid-tier internal

review.

Quoted 4 lines

It was

Quoted 3 lines

primarily a concern of Parav as I recall, so he can speak to his reasoning.

What we originally had was a single API call (ancillary_device_register)

that

Quoted 22 lines

started

Quoted 1 line

with a call to device_initialize(), and every error path out of the function

performed

Quoted 3 lines

a put_device().

Is this the model you have in mind?

I don't like this flow:
ancillary_device_initialize()
if (ancillary_ancillary_device_add()) {
put_device(....)
ancillary_device_unregister()
return err;
}

And prefer this flow:
ancillary_device_initialize()
if (ancillary_device_add()) {
ancillary_device_unregister()
return err;
}

Quoted 6 lines
Quoted 1 line

In this way, the ancillary users won't need to do non-intuitive put_device();

Isn't there a problem calling device_unregister() if device_add() fails? device_unregister() does a device_del() and if the device_add() failed there is
nothing to delete?

Sorry, hit send there unintentionally.

So, would it be best to split the unregister API into two calls as well.

ancillary_device_del()
ancillary_device_put()
?
-DaveE

Quoted 5 lines

-DaveE

Quoted 2 lines

Thanks

#20 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

In reply to Leon Romanovsky
Quoted 19 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 12:56 AM

Quoted 8 lines
Quoted 5 lines

This API is partially obscures low level driver-core code and needs to provide clear and proper abstractions without need to remember about put_device. There is already _add() interface why don't you do put_device() in it?

The pushback Pierre is referring to was during our mid-tier internal review. It was primarily a concern of Parav as I recall, so he can speak to his

reasoning.

Quoted 4 lines

What we originally had was a single API call (ancillary_device_register) that started with a call to device_initialize(), and every error path out of the function performed a

put_device().

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Is this the model you have in mind?

I don't like this flow:
ancillary_device_initialize()
if (ancillary_ancillary_device_add()) {
put_device(....)
ancillary_device_unregister()

Calling device_unregister() is incorrect, because add() wasn't successful. Only put_device() or a wrapper ancillary_device_put() is necessary.

Quoted 7 lines

return err;
}

And prefer this flow:
ancillary_device_initialize()
if (ancillary_device_add()) {
ancillary_device_unregister()

This is incorrect and a clear deviation from the current core APIs that adds the confusion.

Quoted 4 lines

return err;
}

In this way, the ancillary users won't need to do non-intuitive put_device();

Below is most simple, intuitive and matching with core APIs for name and design pattern wise. init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as ancillary_device_unregister().
	 * This will match with core device_unregister() that has precise documentation.
	 * but given fact that init() code need proper error unwinding, like above,
	 * it make sense to have two APIs, and no need to export another symbol for unregister().
	 * This pattern is very easy to audit and code.
	 */
}
#21 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 97 lines

-----Original Message-----
From: Parav Pandit <[email protected]>
Sent: Wednesday, October 7, 2020 1:17 PM
To: Leon Romanovsky <[email protected]>; Ertman, David M <[email protected]>
Cc: Pierre-Louis Bossart <[email protected]>; alsa- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 11 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 12:56 AM

Quoted 8 lines
Quoted 5 lines

This API is partially obscures low level driver-core code and needs to provide clear and proper abstractions without need to remember about put_device. There is already _add() interface why don't you do put_device() in it?

The pushback Pierre is referring to was during our mid-tier internal review. It was primarily a concern of Parav as I recall, so he can speak to

his

Quoted 7 lines

reasoning.

Quoted 4 lines

What we originally had was a single API call (ancillary_device_register) that started with a call to device_initialize(), and every error path out of the function performed a

put_device().

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Is this the model you have in mind?

I don't like this flow:
ancillary_device_initialize()
if (ancillary_ancillary_device_add()) {
put_device(....)
ancillary_device_unregister()

Calling device_unregister() is incorrect, because add() wasn't successful. Only put_device() or a wrapper ancillary_device_put() is necessary.

Quoted 7 lines

return err;
}

And prefer this flow:
ancillary_device_initialize()
if (ancillary_device_add()) {
ancillary_device_unregister()

This is incorrect and a clear deviation from the current core APIs that adds the confusion.

Quoted 4 lines

return err;
}

In this way, the ancillary users won't need to do non-intuitive put_device();

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has precise
documentation.
* but given fact that init() code need proper error unwinding, like
above,
* it make sense to have two APIs, and no need to export another
symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

At that point, do we need wrappers on the primitives init, add, del, and put?

-DaveE

#22 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 42 lines
Quoted 38 lines

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has precise
documentation.
* but given fact that init() code need proper error unwinding, like
above,
* it make sense to have two APIs, and no need to export another
symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}
Quoted 6 lines

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

Quoted 6 lines

At that point, do we need wrappers on the primitives init, add, del, and put?

-DaveE

#23 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 64 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Wednesday, October 7, 2020 1:59 PM
To: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Leon Romanovsky <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 40 lines
Quoted 36 lines

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has precise
documentation.
* but given fact that init() code need proper error unwinding, like
above,
* it make sense to have two APIs, and no need to export another
symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}
Quoted 6 lines

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Quoted 9 lines

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

The flow as outlined by Parav above does an initialize as the first step, so every error path out of the function has to do a put_device(), so you would never need to manually free the memory in the setup function. It would be freed in the release call.

-DaveE

Quoted 6 lines
Quoted 6 lines

At that point, do we need wrappers on the primitives init, add, del, and put?

-DaveE

#24 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 70 lines · David M
Quoted 70 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Wednesday, October 7, 2020 1:59 PM
To: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Leon Romanovsky <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 40 lines
Quoted 36 lines

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has precise
documentation.
* but given fact that init() code need proper error unwinding, like
above,
* it make sense to have two APIs, and no need to export another
symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}
Quoted 6 lines

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

Quoted 8 lines
Quoted 3 lines

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

The flow as outlined by Parav above does an initialize as the first step, so every error path out of the function has to do a put_device(), so you would never need to manually free the memory in the setup function. It would be freed in the release call.

err = ancillary_device_initialize();
if (err)

	return ret;

where is the put_device() here? if the release function does any sort of kfree, then you'd need to do it manually in this case.

#25 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 85 lines

From: Pierre-Louis Bossart <[email protected]>
Sent: Thursday, October 8, 2020 3:20 AM

Quoted 70 lines · David M
Quoted 70 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Wednesday, October 7, 2020 1:59 PM
To: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Leon Romanovsky <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 40 lines
Quoted 36 lines

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has precise
documentation.
* but given fact that init() code need proper error unwinding,
like above,
* it make sense to have two APIs, and no need to export another
symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}
Quoted 6 lines

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

Quoted 7 lines
Quoted 3 lines

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

The flow as outlined by Parav above does an initialize as the first step, so every error path out of the function has to do a put_device(), so you would never need to manually free the memory in

the setup function.

Quoted 8 lines
Quoted 1 line

It would be freed in the release call.

err = ancillary_device_initialize();
if (err)

	return ret;

where is the put_device() here? if the release function does any sort of kfree, then you'd need to do it manually in this case.

Since device_initialize() failed, put_device() cannot be done here. So yes, pseudo code should have shown,

if (err) {
	kfree(adev);
	return err;
}

If we just want to follow register(), unregister() pattern,

Than,

ancillar_device_register() should be,

/**
* ancillar_device_register() - register an ancillary device
* NOTE: __never directly free @adev after calling this function, even if it returned
* an error. Always use ancillary_device_put() to give up the reference initialized by this function.
* This note matches with the core and caller knows exactly what to be done.
*/
ancillary_device_register()

{
	device_initialize(&adev->dev);
	if (!dev->parent || !adev->name)
		return -EINVAL;
	if (!dev->release && !(dev->type && dev->type->release)) {
		/* core is already capable and throws the warning when release callback is not set.
		 * It is done at drivers/base/core.c:1798.
		 * For NULL release it says, "does not have a release() function, it is broken and must be fixed"
		 */
		return -EINVAL;
	}
	err = dev_set_name(adev...);
	if (err) {
		/* kobject_release() -> kobject_cleanup() are capable to detect if name is set/ not set
		  * and free the const if it was set.
		  */
		return err;
	}
	err = device_add(&adev->dev);
	If (err)
		return err;
}

Caller code:
init()

{
	adev = kzalloc(sizeof(*foo_adev)..);
	if (!adev)
		return -ENOMEM;
	err = ancillary_device_register(&adev);
	if (err)
		goto err;

err:

	ancillary_device_put(&adev);
	return err;
}

cleanup()

{
	ancillary_device_unregister(&adev);
}

Above pattern is fine too matching the core.

If I understand Leon correctly, he prefers simple register(), unregister() pattern. If, so it should be explicit register(), unregister() API.

However I read that Pierre mentioned that SoundWire prefers initialize(), some_data_init(), add() pattern. If SoundWire cannot do register() pattern,
So, whichever first user bundled with the patchset, those APIs should be exported, because we don’t add an API without a user.

Pierre,
Can you please check if SoundWire can follow register() pattern?

Assuming Leon patches and my patches for subfunction arrive after Soundwire series + ancillary bus, we can add the register() and unregister() version in our patchset later.

Greg already said that "it's not carved on stone, we can do incremental additions as the need arise". So I think we should proceed with the wrappers which follow the core convention of either
(a) initialize)(), add() or
(b) register(), unregister().

#26 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 152 lines · Parav Pandit
Quoted 85 lines

From: Pierre-Louis Bossart <[email protected]>
Sent: Thursday, October 8, 2020 3:20 AM

Quoted 70 lines · David M
Quoted 70 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Wednesday, October 7, 2020 1:59 PM
To: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Leon Romanovsky <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 40 lines
Quoted 36 lines

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has precise
documentation.
* but given fact that init() code need proper error unwinding,
like above,
* it make sense to have two APIs, and no need to export another
symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}
Quoted 6 lines

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

Quoted 7 lines
Quoted 3 lines

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

The flow as outlined by Parav above does an initialize as the first step, so every error path out of the function has to do a put_device(), so you would never need to manually free the memory in

the setup function.

Quoted 8 lines
Quoted 1 line

It would be freed in the release call.

err = ancillary_device_initialize();
if (err)

	return ret;

where is the put_device() here? if the release function does any sort of kfree, then you'd need to do it manually in this case.

Since device_initialize() failed, put_device() cannot be done here. So yes, pseudo code should have shown,

if (err) {
	kfree(adev);
	return err;
}

If we just want to follow register(), unregister() pattern,

Than,

ancillar_device_register() should be,

/**
* ancillar_device_register() - register an ancillary device
* NOTE: __never directly free @adev after calling this function, even if it returned
* an error. Always use ancillary_device_put() to give up the reference initialized by this function.
* This note matches with the core and caller knows exactly what to be done.
*/
ancillary_device_register()

{
	device_initialize(&adev->dev);
	if (!dev->parent || !adev->name)
		return -EINVAL;
	if (!dev->release && !(dev->type && dev->type->release)) {
		/* core is already capable and throws the warning when release callback is not set.
		 * It is done at drivers/base/core.c:1798.
		 * For NULL release it says, "does not have a release() function, it is broken and must be fixed"
		 */
		return -EINVAL;
	}
	err = dev_set_name(adev...);
	if (err) {
		/* kobject_release() -> kobject_cleanup() are capable to detect if name is set/ not set
		  * and free the const if it was set.
		  */
		return err;
	}
	err = device_add(&adev->dev);
	If (err)
		return err;
}

Caller code:
init()

{
	adev = kzalloc(sizeof(*foo_adev)..);
	if (!adev)
		return -ENOMEM;
	err = ancillary_device_register(&adev);
	if (err)
		goto err;

err:

	ancillary_device_put(&adev);
	return err;
}

cleanup()

Quoted 8 lines
{
	ancillary_device_unregister(&adev);
}

Above pattern is fine too matching the core.

If I understand Leon correctly, he prefers simple register(), unregister() pattern. If, so it should be explicit register(), unregister() API.

This is my summary
https://lore.kernel.org/linux-rdma/20201008052137.GA13580@unreal
The API should be symmetric.

Thanks

#27 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 170 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 10:56 AM

Quoted 104 lines · Parav Pandit
Quoted 86 lines

From: Pierre-Louis Bossart <[email protected]>
Sent: Thursday, October 8, 2020 3:20 AM

Quoted 71 lines · David M
Quoted 71 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Wednesday, October 7, 2020 1:59 PM
To: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Leon Romanovsky <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 40 lines
Quoted 36 lines

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has
precise documentation.
* but given fact that init() code need proper error
unwinding, like above,
* it make sense to have two APIs, and no need to export
another symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}
Quoted 6 lines

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

Quoted 8 lines
Quoted 3 lines

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

The flow as outlined by Parav above does an initialize as the first step, so every error path out of the function has to do a put_device(), so you would never need to manually free the memory in

Quoted 8 lines

the setup function.

Quoted 1 line

It would be freed in the release call.

err = ancillary_device_initialize(); if (err)

	return ret;

where is the put_device() here? if the release function does any sort of kfree, then you'd need to do it manually in this case.

Since device_initialize() failed, put_device() cannot be done here. So yes, pseudo code should have shown, if (err) {

	kfree(adev);
	return err;
}

If we just want to follow register(), unregister() pattern,

Than,

Quoted 7 lines

ancillar_device_register() should be,

/**
* ancillar_device_register() - register an ancillary device
* NOTE: __never directly free @adev after calling this function, even
if it returned
* an error. Always use ancillary_device_put() to give up the reference

initialized by this function.

Quoted 1 line

* This note matches with the core and caller knows exactly what to be

done.

Quoted 8 lines

*/
ancillary_device_register()

{
	device_initialize(&adev->dev);
	if (!dev->parent || !adev->name)
		return -EINVAL;
	if (!dev->release && !(dev->type && dev->type->release)) {
		/* core is already capable and throws the warning when

release callback is not set.

Quoted 2 lines

* It is done at drivers/base/core.c:1798.
* For NULL release it says, "does not have a release()

function, it is broken and must be fixed"

Quoted 6 lines
		 */
		return -EINVAL;
	}
	err = dev_set_name(adev...);
	if (err) {
		/* kobject_release() -> kobject_cleanup() are capable to

detect if name is set/ not set

Quoted 31 lines
		  * and free the const if it was set.
		  */
		return err;
	}
	err = device_add(&adev->dev);
	If (err)
		return err;
}

Caller code:
init()

{
	adev = kzalloc(sizeof(*foo_adev)..);
	if (!adev)
		return -ENOMEM;
	err = ancillary_device_register(&adev);
	if (err)
		goto err;

err:

	ancillary_device_put(&adev);
	return err;
}

cleanup()

{
	ancillary_device_unregister(&adev);
}

Above pattern is fine too matching the core.

Quoted 8 lines
Quoted 1 line

If I understand Leon correctly, he prefers simple register(), unregister()

pattern.

Quoted 1 line

If, so it should be explicit register(), unregister() API.

This is my summary
https://lore.kernel.org/linux-rdma/20201008052137.GA13580@unreal
The API should be symmetric.

I disagree to your below point.

Quoted 3 lines

1. You are not providing driver/core API but simplification and obfuscation of basic primitives and structures. This is new layer. There is no room for a claim that we must to follow internal API.

If ancillary bus has
ancillary_device_add(), it cannot do device_initialize() and device_add() in both.

I provided two examples and what really matters is a given patchset uses (need to use) which pattern, initialize() + add(), or register() + unregister().

As we all know that API is not added for future. It is the future patch extends it. So lets wait for Pierre to reply if soundwire can follow register(), unregister() sequence. This way same APIs can service both use-cases.

Regarding,

Quoted 2 lines

3. You can't "ask" from users to call internal calls (put_device) over internal fields in ancillary_device.

In that case if should be ancillary_device_put() ancillary_device_release().

Or we should follow the patten of ib_alloc_device [1], ancillary_device_alloc()

    -> kzalloc(adev + dev) with compile time assert check like rdma and vdpa subsystem.
    ->device_initialize()

ancillary_device_add()

ancillar_device_de() <- balances with add
ancillary_device_dealloc() <-- balances with device_alloc(), which does the put_device() + free the memory allocated in alloc().

This approach of [1] also eliminates exposing adev.dev.release = <drivers_release_method_to_free_adev> in drivers. And container_of() benefit also continues..

[1] https://elixir.bootlin.com/linux/v5.9-rc8/source/include/rdma/ib_verbs.h#L2791

#28 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 204 lines · Parav Pandit
Quoted 170 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 10:56 AM

Quoted 104 lines · Parav Pandit
Quoted 86 lines

From: Pierre-Louis Bossart <[email protected]>
Sent: Thursday, October 8, 2020 3:20 AM

Quoted 71 lines · David M
Quoted 71 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Wednesday, October 7, 2020 1:59 PM
To: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Leon Romanovsky <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 40 lines
Quoted 36 lines

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has
precise documentation.
* but given fact that init() code need proper error
unwinding, like above,
* it make sense to have two APIs, and no need to export
another symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}
Quoted 6 lines

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

Quoted 8 lines
Quoted 3 lines

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

The flow as outlined by Parav above does an initialize as the first step, so every error path out of the function has to do a put_device(), so you would never need to manually free the memory in

Quoted 8 lines

the setup function.

Quoted 1 line

It would be freed in the release call.

err = ancillary_device_initialize(); if (err)

	return ret;

where is the put_device() here? if the release function does any sort of kfree, then you'd need to do it manually in this case.

Since device_initialize() failed, put_device() cannot be done here. So yes, pseudo code should have shown, if (err) {

	kfree(adev);
	return err;
}

If we just want to follow register(), unregister() pattern,

Than,

Quoted 7 lines

ancillar_device_register() should be,

/**
* ancillar_device_register() - register an ancillary device
* NOTE: __never directly free @adev after calling this function, even
if it returned
* an error. Always use ancillary_device_put() to give up the reference

initialized by this function.

Quoted 1 line

* This note matches with the core and caller knows exactly what to be

done.

Quoted 8 lines

*/
ancillary_device_register()

{
	device_initialize(&adev->dev);
	if (!dev->parent || !adev->name)
		return -EINVAL;
	if (!dev->release && !(dev->type && dev->type->release)) {
		/* core is already capable and throws the warning when

release callback is not set.

Quoted 2 lines

* It is done at drivers/base/core.c:1798.
* For NULL release it says, "does not have a release()

function, it is broken and must be fixed"

Quoted 6 lines
		 */
		return -EINVAL;
	}
	err = dev_set_name(adev...);
	if (err) {
		/* kobject_release() -> kobject_cleanup() are capable to

detect if name is set/ not set

Quoted 31 lines
		  * and free the const if it was set.
		  */
		return err;
	}
	err = device_add(&adev->dev);
	If (err)
		return err;
}

Caller code:
init()

{
	adev = kzalloc(sizeof(*foo_adev)..);
	if (!adev)
		return -ENOMEM;
	err = ancillary_device_register(&adev);
	if (err)
		goto err;

err:

	ancillary_device_put(&adev);
	return err;
}

cleanup()

{
	ancillary_device_unregister(&adev);
}

Above pattern is fine too matching the core.

Quoted 8 lines
Quoted 1 line

If I understand Leon correctly, he prefers simple register(), unregister()

pattern.

Quoted 1 line

If, so it should be explicit register(), unregister() API.

This is my summary
https://lore.kernel.org/linux-rdma/20201008052137.GA13580@unreal
The API should be symmetric.

I disagree to your below point.

Quoted 3 lines

1. You are not providing driver/core API but simplification and obfuscation of basic primitives and structures. This is new layer. There is no room for a claim that we must to follow internal API.

If ancillary bus has
ancillary_device_add(), it cannot do device_initialize() and device_add() in both.

I provided two examples and what really matters is a given patchset uses (need to use) which pattern, initialize() + add(), or register() + unregister().

As we all know that API is not added for future. It is the future patch extends it. So lets wait for Pierre to reply if soundwire can follow register(), unregister() sequence. This way same APIs can service both use-cases.

Regarding,

Quoted 2 lines

3. You can't "ask" from users to call internal calls (put_device) over internal fields in ancillary_device.

In that case if should be ancillary_device_put() ancillary_device_release().

Or we should follow the patten of ib_alloc_device [1], ancillary_device_alloc()

    -> kzalloc(adev + dev) with compile time assert check like rdma and vdpa subsystem.
    ->device_initialize()

ancillary_device_add()

Quoted 8 lines

ancillar_device_de() <- balances with add
ancillary_device_dealloc() <-- balances with device_alloc(), which does the put_device() + free the memory allocated in alloc().

This approach of [1] also eliminates exposing adev.dev.release = <drivers_release_method_to_free_adev> in drivers. And container_of() benefit also continues..

[1] https://elixir.bootlin.com/linux/v5.9-rc8/source/include/rdma/ib_verbs.h#L2791

My code looks like this, probably yours looks the same.

  247                 priv->adev[i] = kzalloc(sizeof(*priv->adev[i]), GFP_KERNEL);
  248                 if (!priv->adev[i])
  249                         goto init_err;
  250
  251                 adev = &priv->adev[i]->adev;
  252                 adev->id = idx;
  253                 adev->name = mlx5_adev_devices[i].suffix;
  254                 adev->dev.parent = dev->device;
  255                 adev->dev.release = adev_release;
  256                 priv->adev[i]->mdev = dev;
  257
  258                 ret = ancillary_device_initialize(adev);
  259                 if (ret)
  260                         goto init_err;
  261
  262                 ret = ancillary_device_add(adev);
  263                 if (ret) {
  264                         put_device(&adev->dev);
  265                         goto add_err;
  266                 }

Thanks

#29 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 248 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 1:15 PM

Quoted 185 lines · Parav Pandit
Quoted 175 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 10:56 AM

Quoted 107 lines · Parav Pandit
Quoted 89 lines

From: Pierre-Louis Bossart
<[email protected]>
Sent: Thursday, October 8, 2020 3:20 AM

Quoted 73 lines · David M
Quoted 73 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Wednesday, October 7, 2020 1:59 PM
To: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Leon Romanovsky <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 40 lines
Quoted 36 lines

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has
precise documentation.
* but given fact that init() code need proper error
unwinding, like above,
* it make sense to have two APIs, and no need to export
another symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}
Quoted 6 lines

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since
put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

Quoted 8 lines
Quoted 3 lines

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

The flow as outlined by Parav above does an initialize as the first step, so every error path out of the function has to do a put_device(), so you would never need to manually free the memory in

Quoted 8 lines

the setup function.

Quoted 1 line

It would be freed in the release call.

err = ancillary_device_initialize(); if (err)

	return ret;

where is the put_device() here? if the release function does any sort of kfree, then you'd need to do it manually in this case.

Since device_initialize() failed, put_device() cannot be done here. So yes, pseudo code should have shown, if (err) {

	kfree(adev);
	return err;
}

If we just want to follow register(), unregister() pattern,

Than,

Quoted 8 lines

ancillar_device_register() should be,

/**
* ancillar_device_register() - register an ancillary device
* NOTE: __never directly free @adev after calling this function,
even if it returned
* an error. Always use ancillary_device_put() to give up the
reference

initialized by this function.

Quoted 2 lines

* This note matches with the core and caller knows exactly what
to be

done.

Quoted 8 lines

*/
ancillary_device_register()

{
	device_initialize(&adev->dev);
	if (!dev->parent || !adev->name)
		return -EINVAL;
	if (!dev->release && !(dev->type && dev->type->release)) {
		/* core is already capable and throws the warning when

release callback is not set.

Quoted 2 lines

* It is done at drivers/base/core.c:1798.
* For NULL release it says, "does not have a release()

function, it is broken and must be fixed"

Quoted 6 lines
		 */
		return -EINVAL;
	}
	err = dev_set_name(adev...);
	if (err) {
		/* kobject_release() -> kobject_cleanup() are capable to

detect if name is set/ not set

Quoted 31 lines
		  * and free the const if it was set.
		  */
		return err;
	}
	err = device_add(&adev->dev);
	If (err)
		return err;
}

Caller code:
init()

{
	adev = kzalloc(sizeof(*foo_adev)..);
	if (!adev)
		return -ENOMEM;
	err = ancillary_device_register(&adev);
	if (err)
		goto err;

err:

	ancillary_device_put(&adev);
	return err;
}

cleanup()

{
	ancillary_device_unregister(&adev);
}

Above pattern is fine too matching the core.

Quoted 9 lines
Quoted 2 lines

If I understand Leon correctly, he prefers simple register(), unregister()

pattern.

Quoted 1 line

If, so it should be explicit register(), unregister() API.

This is my summary
https://lore.kernel.org/linux-rdma/20201008052137.GA13580@unreal
The API should be symmetric.

Quoted 6 lines

I disagree to your below point.

Quoted 3 lines

1. You are not providing driver/core API but simplification and obfuscation of basic primitives and structures. This is new layer. There is no room for a claim that we must to follow internal API.

If ancillary bus has
ancillary_device_add(), it cannot do device_initialize() and device_add() in

both.

Quoted 6 lines

I provided two examples and what really matters is a given patchset uses (need to use) which pattern,
initialize() + add(), or register() + unregister().

As we all know that API is not added for future. It is the future patch

extends it.

Quoted 1 line

So lets wait for Pierre to reply if soundwire can follow register(),

unregister() sequence.

Quoted 10 lines

This way same APIs can service both use-cases.

Regarding,

Quoted 2 lines

3. You can't "ask" from users to call internal calls (put_device) over internal fields in ancillary_device.

In that case if should be ancillary_device_put() ancillary_device_release().

Or we should follow the patten of ib_alloc_device [1], ancillary_device_alloc()

    -> kzalloc(adev + dev) with compile time assert check like rdma and vdpa

subsystem.

Quoted 5 lines
    ->device_initialize()

ancillary_device_add()

ancillar_device_de() <- balances with add ancillary_device_dealloc() <-- balances with device_alloc(), which does the

put_device() + free the memory allocated in alloc().

Quoted 2 lines

This approach of [1] also eliminates exposing adev.dev.release =

<drivers_release_method_to_free_adev> in drivers.

Quoted 6 lines

And container_of() benefit also continues..

[1]
https://elixir.bootlin.com/linux/v5.9-rc8/source/include/rdma/ib_verbs
.h#L2791

My code looks like this, probably yours looks the same.

  247                 priv->adev[i] = kzalloc(sizeof(*priv->adev[i]), GFP_KERNEL);
  248                 if (!priv->adev[i])
  249                         goto init_err;
  250
  251                 adev = &priv->adev[i]->adev;
  252                 adev->id = idx;
  253                 adev->name = mlx5_adev_devices[i].suffix;
  254                 adev->dev.parent = dev->device;
  255                 adev->dev.release = adev_release;
  256                 priv->adev[i]->mdev = dev;
  257
  258                 ret = ancillary_device_initialize(adev);
Quoted 8 lines
  259                 if (ret)
  260                         goto init_err;
  261
  262                 ret = ancillary_device_add(adev);
  263                 if (ret) {
  264                         put_device(&adev->dev);
  265                         goto add_err;
  266                 }

Yes, subfunction code is also very similar.
You expressed concerned that you didn't like put_device() at [1]. But in above code is touching adev->dev.{parent, release} is ok?

Quoted 2 lines
  254                 adev->dev.parent = dev->device;
  255                 adev->dev.release = adev_release;

If not,

We can make it elegant by doing,

the patten of ib_alloc_device [1],
ancillary_device_alloc()

    -> kzalloc(adev + dev) with compile time assert check like rdma and vdpa subsystem.
    ->device_initialize()

ancillary_device_add()

ancillar_device_de() <- balances with add
ancillary_device_dealloc() <-- balances with device_alloc(), which does the put_device() + free the memory allocated in alloc().

This approach of [2] also eliminates exposing adev.dev.release = <drivers_release_method_to_free_adev> in drivers. And container_of() benefit also continues..

[1] https://lore.kernel.org/linux-rdma/20201007192610.GD3964015@unreal/
[2] https://elixir.bootlin.com/linux/v5.9-rc8/source/include/rdma/ib_verbs.h#L2791

#30 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 257 lines · Parav Pandit
Quoted 248 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 1:15 PM

Quoted 185 lines · Parav Pandit
Quoted 175 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 10:56 AM

Quoted 107 lines · Parav Pandit
Quoted 89 lines

From: Pierre-Louis Bossart
<[email protected]>
Sent: Thursday, October 8, 2020 3:20 AM

Quoted 73 lines · David M
Quoted 73 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Wednesday, October 7, 2020 1:59 PM
To: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Leon Romanovsky <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 40 lines
Quoted 36 lines

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has
precise documentation.
* but given fact that init() code need proper error
unwinding, like above,
* it make sense to have two APIs, and no need to export
another symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}
Quoted 6 lines

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since
put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

Quoted 8 lines
Quoted 3 lines

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

The flow as outlined by Parav above does an initialize as the first step, so every error path out of the function has to do a put_device(), so you would never need to manually free the memory in

Quoted 8 lines

the setup function.

Quoted 1 line

It would be freed in the release call.

err = ancillary_device_initialize(); if (err)

	return ret;

where is the put_device() here? if the release function does any sort of kfree, then you'd need to do it manually in this case.

Since device_initialize() failed, put_device() cannot be done here. So yes, pseudo code should have shown, if (err) {

	kfree(adev);
	return err;
}

If we just want to follow register(), unregister() pattern,

Than,

Quoted 8 lines

ancillar_device_register() should be,

/**
* ancillar_device_register() - register an ancillary device
* NOTE: __never directly free @adev after calling this function,
even if it returned
* an error. Always use ancillary_device_put() to give up the
reference

initialized by this function.

Quoted 2 lines

* This note matches with the core and caller knows exactly what
to be

done.

Quoted 8 lines

*/
ancillary_device_register()

{
	device_initialize(&adev->dev);
	if (!dev->parent || !adev->name)
		return -EINVAL;
	if (!dev->release && !(dev->type && dev->type->release)) {
		/* core is already capable and throws the warning when

release callback is not set.

Quoted 2 lines

* It is done at drivers/base/core.c:1798.
* For NULL release it says, "does not have a release()

function, it is broken and must be fixed"

Quoted 6 lines
		 */
		return -EINVAL;
	}
	err = dev_set_name(adev...);
	if (err) {
		/* kobject_release() -> kobject_cleanup() are capable to

detect if name is set/ not set

Quoted 31 lines
		  * and free the const if it was set.
		  */
		return err;
	}
	err = device_add(&adev->dev);
	If (err)
		return err;
}

Caller code:
init()

{
	adev = kzalloc(sizeof(*foo_adev)..);
	if (!adev)
		return -ENOMEM;
	err = ancillary_device_register(&adev);
	if (err)
		goto err;

err:

	ancillary_device_put(&adev);
	return err;
}

cleanup()

{
	ancillary_device_unregister(&adev);
}

Above pattern is fine too matching the core.

Quoted 9 lines
Quoted 2 lines

If I understand Leon correctly, he prefers simple register(), unregister()

pattern.

Quoted 1 line

If, so it should be explicit register(), unregister() API.

This is my summary
https://lore.kernel.org/linux-rdma/20201008052137.GA13580@unreal
The API should be symmetric.

Quoted 6 lines

I disagree to your below point.

Quoted 3 lines

1. You are not providing driver/core API but simplification and obfuscation of basic primitives and structures. This is new layer. There is no room for a claim that we must to follow internal API.

If ancillary bus has
ancillary_device_add(), it cannot do device_initialize() and device_add() in

both.

Quoted 6 lines

I provided two examples and what really matters is a given patchset uses (need to use) which pattern,
initialize() + add(), or register() + unregister().

As we all know that API is not added for future. It is the future patch

extends it.

Quoted 1 line

So lets wait for Pierre to reply if soundwire can follow register(),

unregister() sequence.

Quoted 10 lines

This way same APIs can service both use-cases.

Regarding,

Quoted 2 lines

3. You can't "ask" from users to call internal calls (put_device) over internal fields in ancillary_device.

In that case if should be ancillary_device_put() ancillary_device_release().

Or we should follow the patten of ib_alloc_device [1], ancillary_device_alloc()

    -> kzalloc(adev + dev) with compile time assert check like rdma and vdpa

subsystem.

Quoted 5 lines
    ->device_initialize()

ancillary_device_add()

ancillar_device_de() <- balances with add ancillary_device_dealloc() <-- balances with device_alloc(), which does the

put_device() + free the memory allocated in alloc().

Quoted 2 lines

This approach of [1] also eliminates exposing adev.dev.release =

<drivers_release_method_to_free_adev> in drivers.

Quoted 6 lines

And container_of() benefit also continues..

[1]
https://elixir.bootlin.com/linux/v5.9-rc8/source/include/rdma/ib_verbs
.h#L2791

My code looks like this, probably yours looks the same.

  247                 priv->adev[i] = kzalloc(sizeof(*priv->adev[i]), GFP_KERNEL);
  248                 if (!priv->adev[i])
  249                         goto init_err;
  250
  251                 adev = &priv->adev[i]->adev;
  252                 adev->id = idx;
  253                 adev->name = mlx5_adev_devices[i].suffix;
  254                 adev->dev.parent = dev->device;
  255                 adev->dev.release = adev_release;
  256                 priv->adev[i]->mdev = dev;
  257
  258                 ret = ancillary_device_initialize(adev);
Quoted 8 lines
  259                 if (ret)
  260                         goto init_err;
  261
  262                 ret = ancillary_device_add(adev);
  263                 if (ret) {
  264                         put_device(&adev->dev);
  265                         goto add_err;
  266                 }
Quoted 3 lines

Yes, subfunction code is also very similar.
You expressed concerned that you didn't like put_device() at [1]. But in above code is touching adev->dev.{parent, release} is ok?

Yes, "adev->dev.{parent, release}" is not ok, but at least it doesn't complicate error unwinding. This is why I didn't say anything about it.

Quoted 6 lines
Quoted 2 lines
  254                 adev->dev.parent = dev->device;
  255                 adev->dev.release = adev_release;

If not,

We can make it elegant by doing,

I like your idea, IMHO it is more clear and less error prone.

Thanks

Quoted 15 lines

the patten of ib_alloc_device [1],
ancillary_device_alloc()

    -> kzalloc(adev + dev) with compile time assert check like rdma and vdpa subsystem.
    ->device_initialize()

ancillary_device_add()

ancillar_device_de() <- balances with add
ancillary_device_dealloc() <-- balances with device_alloc(), which does the put_device() + free the memory allocated in alloc().

This approach of [2] also eliminates exposing adev.dev.release = <drivers_release_method_to_free_adev> in drivers. And container_of() benefit also continues..

[1] https://lore.kernel.org/linux-rdma/20201007192610.GD3964015@unreal/
[2] https://elixir.bootlin.com/linux/v5.9-rc8/source/include/rdma/ib_verbs.h#L2791

#31 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

In reply to Parav Pandit
Quoted 26 lines
Quoted 26 lines
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

Quoted 7 lines
Quoted 3 lines

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

The flow as outlined by Parav above does an initialize as the first step, so every error path out of the function has to do a put_device(), so you would never need to manually free the memory in

the setup function.

Quoted 1 line

It would be freed in the release call.

err = ancillary_device_initialize();
if (err)

	return ret;
Quoted 8 lines
Quoted 2 lines

where is the put_device() here? if the release function does any sort of kfree, then you'd need to do it manually in this case.

Since device_initialize() failed, put_device() cannot be done here. So yes, pseudo code should have shown,

if (err) {
	kfree(adev);
	return err;
}

This doesn't work if the adev is part of a larger structure allocated by the parent, which is pretty much the intent to extent the basic bus and pass additional information which can be accessed with container_of().

Only the parent can do the kfree() explicitly in that case. If the parent relies on devm_kzalloc, this also can make the .release callback with no memory free required at all.

See e.g. the code I cooked for the transition of SoundWire away from platform devices at

https://github.com/thesofproject/linux/pull/2484/commits/d0540ae3744f3a748d49c5fe61469d82ed816981#diff-ac8eb3d3951c024f52b1d463b5317f70R305

The allocation is done on an 'ldev' which contains 'adev'.

I really don't seen how an ancillary_device_register() could model the different ways to allocate memory, for maximum flexibility across different domains it seems more relevant to keep the initialize() and add() APIs separate. I will accept the argument that this puts more responsibility on the parent, but it also provides more flexibility to the parent.

If we go with the suggested solution above, that already prevents SoundWire from using this bus. Not so good.

#32 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 35 lines · Pierre-Louis Bossart
Quoted 26 lines
Quoted 26 lines
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

Quoted 7 lines
Quoted 3 lines

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

The flow as outlined by Parav above does an initialize as the first step, so every error path out of the function has to do a put_device(), so you would never need to manually free the memory in

the setup function.

Quoted 1 line

It would be freed in the release call.

err = ancillary_device_initialize();
if (err)

	return ret;
Quoted 8 lines
Quoted 2 lines

where is the put_device() here? if the release function does any sort of kfree, then you'd need to do it manually in this case.

Since device_initialize() failed, put_device() cannot be done here. So yes, pseudo code should have shown,

if (err) {
	kfree(adev);
	return err;
}
Quoted 3 lines

This doesn't work if the adev is part of a larger structure allocated by the parent, which is pretty much the intent to extent the basic bus and pass additional information which can be accessed with container_of().

Please take a look how ib_alloc_device() is implemented. It does all that you wrote above in very similar manner to netdev_alloc.

In a nutshell, ib_alloc_device receives needed size from the user and requires from the users to extend their structures below "general" one.

Thanks

#33 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

In reply to Parav Pandit
Quoted 139 lines

-----Original Message-----
From: Parav Pandit <[email protected]>
Sent: Wednesday, October 7, 2020 9:56 PM
To: Pierre-Louis Bossart <[email protected]>; Ertman, David M <[email protected]>; Leon Romanovsky <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 83 lines

From: Pierre-Louis Bossart <[email protected]>
Sent: Thursday, October 8, 2020 3:20 AM

Quoted 70 lines · David M
Quoted 70 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Wednesday, October 7, 2020 1:59 PM
To: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Leon Romanovsky <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 40 lines
Quoted 36 lines

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has precise
documentation.
* but given fact that init() code need proper error unwinding,
like above,
* it make sense to have two APIs, and no need to export another
symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}
Quoted 6 lines

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Kind reminder that we introduced the two functions to allow the caller to know if it needed to free memory when initialize() fails, and it didn't need to free memory when add() failed since put_device() takes care of it. If you have a single init() function it's impossible to know which behavior to select on error.

Quoted 7 lines
Quoted 3 lines

I also have a case with SoundWire where it's nice to first initialize, then set some data and then add.

The flow as outlined by Parav above does an initialize as the first step, so every error path out of the function has to do a put_device(), so you would never need to manually free the memory in

the setup function.

Quoted 8 lines
Quoted 1 line

It would be freed in the release call.

err = ancillary_device_initialize();
if (err)

	return ret;

where is the put_device() here? if the release function does any sort of kfree, then you'd need to do it manually in this case.

Since device_initialize() failed, put_device() cannot be done here. So yes, pseudo code should have shown,

if (err) {
	kfree(adev);
	return err;
}

If we just want to follow register(), unregister() pattern,

Than,

ancillar_device_register() should be,

/**
* ancillar_device_register() - register an ancillary device
* NOTE: __never directly free @adev after calling this function, even if it
returned
* an error. Always use ancillary_device_put() to give up the reference
initialized by this function.
* This note matches with the core and caller knows exactly what to be done. */
ancillary_device_register()

{
	device_initialize(&adev->dev);
	if (!dev->parent || !adev->name)
		return -EINVAL;
	if (!dev->release && !(dev->type && dev->type->release)) {
		/* core is already capable and throws the warning when
Quoted 7 lines

release callback is not set.
* It is done at drivers/base/core.c:1798.
* For NULL release it says, "does not have a release()
function, it is broken and must be fixed"

		 */
		return -EINVAL;
	}

That code is in device_release(). Because of this check we will never hit that code.

We either need to leave the error message here, or if we are going to rely on the core to find this condition at the end of the process, then we need to completely remove this check from the registration flow.

-DaveE

#34 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 34 lines

From: Ertman, David M <[email protected]>
Sent: Thursday, October 8, 2020 10:24 PM

Quoted 11 lines

From: Parav Pandit <[email protected]>
Sent: Wednesday, October 7, 2020 9:56 PM

/**
* ancillar_device_register() - register an ancillary device
* NOTE: __never directly free @adev after calling this function, even
if it returned
* an error. Always use ancillary_device_put() to give up the
reference initialized by this function.
* This note matches with the core and caller knows exactly what to be

done.

Quoted 8 lines

*/
ancillary_device_register()

{
	device_initialize(&adev->dev);
	if (!dev->parent || !adev->name)
		return -EINVAL;
	if (!dev->release && !(dev->type && dev->type->release)) {
		/* core is already capable and throws the warning when

release

Quoted 3 lines

callback is not set.
* It is done at drivers/base/core.c:1798.
* For NULL release it says, "does not have a release()

function, it

Quoted 4 lines

is broken and must be fixed"

		 */
		return -EINVAL;
	}
Quoted 7 lines

That code is in device_release(). Because of this check we will never hit that code.

We either need to leave the error message here, or if we are going to rely on the core to find this condition at the end of the process, then we need to completely remove this check from the registration flow.

Yes. Since the core is checking it, ancillary bus doesn't need to check here and release callback check can be removed.

Quoted 1 line

-DaveE

#35 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 54 lines

-----Original Message-----
From: Parav Pandit <[email protected]>
Sent: Thursday, October 8, 2020 10:35 AM
To: Ertman, David M <[email protected]>; Pierre-Louis Bossart <[email protected]>; Leon Romanovsky <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 27 lines

From: Ertman, David M <[email protected]>
Sent: Thursday, October 8, 2020 10:24 PM

Quoted 11 lines

From: Parav Pandit <[email protected]>
Sent: Wednesday, October 7, 2020 9:56 PM

/**
* ancillar_device_register() - register an ancillary device
* NOTE: __never directly free @adev after calling this function, even
if it returned
* an error. Always use ancillary_device_put() to give up the
reference initialized by this function.
* This note matches with the core and caller knows exactly what to be

done.

Quoted 8 lines

*/
ancillary_device_register()

{
	device_initialize(&adev->dev);
	if (!dev->parent || !adev->name)
		return -EINVAL;
	if (!dev->release && !(dev->type && dev->type->release)) {
		/* core is already capable and throws the warning when

release

Quoted 3 lines

callback is not set.
* It is done at drivers/base/core.c:1798.
* For NULL release it says, "does not have a release()

Quoted 6 lines

function, it

Quoted 4 lines

is broken and must be fixed"

		 */
		return -EINVAL;
	}

That code is in device_release(). Because of this check we will never hit

that

Quoted 2 lines

code.

Quoted 7 lines
Quoted 1 line

We either need to leave the error message here, or if we are going to rely

on

Quoted 3 lines

the core to find this condition at the end of the process, then we need to completely remove this check from the registration flow.

Yes. Since the core is checking it, ancillary bus doesn't need to check here and release callback check can be removed.

Will do

Quoted 2 lines
Quoted 2 lines

-DaveE

#36 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

In reply to Ertman, David M
Quoted 103 lines · David M
Quoted 97 lines

-----Original Message-----
From: Parav Pandit <[email protected]>
Sent: Wednesday, October 7, 2020 1:17 PM
To: Leon Romanovsky <[email protected]>; Ertman, David M <[email protected]>
Cc: Pierre-Louis Bossart <[email protected]>; alsa- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 11 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 12:56 AM

Quoted 8 lines
Quoted 5 lines

This API is partially obscures low level driver-core code and needs to provide clear and proper abstractions without need to remember about put_device. There is already _add() interface why don't you do put_device() in it?

The pushback Pierre is referring to was during our mid-tier internal review. It was primarily a concern of Parav as I recall, so he can speak to

his

Quoted 7 lines

reasoning.

Quoted 4 lines

What we originally had was a single API call (ancillary_device_register) that started with a call to device_initialize(), and every error path out of the function performed a

put_device().

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Is this the model you have in mind?

I don't like this flow:
ancillary_device_initialize()
if (ancillary_ancillary_device_add()) {
put_device(....)
ancillary_device_unregister()

Calling device_unregister() is incorrect, because add() wasn't successful. Only put_device() or a wrapper ancillary_device_put() is necessary.

Quoted 7 lines

return err;
}

And prefer this flow:
ancillary_device_initialize()
if (ancillary_device_add()) {
ancillary_device_unregister()

This is incorrect and a clear deviation from the current core APIs that adds the confusion.

Quoted 4 lines

return err;
}

In this way, the ancillary users won't need to do non-intuitive put_device();

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
	err = ancillary_device_initialize();
	if (err)
		return ret;

	err = ancillary_device_add();
	if (ret)
		goto err_unwind;

	err = some_foo();
	if (err)
		goto err_foo;
	return 0;

err_foo:

	ancillary_device_del(adev);
err_unwind:
	ancillary_device_put(adev->dev);
	return err;
}

cleanup()

{
	ancillary_device_de(adev);
	ancillary_device_put(adev);
	/* It is common to have a one wrapper for this as

ancillary_device_unregister().
* This will match with core device_unregister() that has precise
documentation.
* but given fact that init() code need proper error unwinding, like
above,
* it make sense to have two APIs, and no need to export another
symbol for unregister().

Quoted 3 lines
	 * This pattern is very easy to audit and code.
	 */
}

I like this flow +1

Quoted 7 lines

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

At that point, do we need wrappers on the primitives init, add, del, and put?

Let me summarize.
1. You are not providing driver/core API but simplification and obfuscation of basic primitives and structures. This is new layer. There is no room for a claim that we must to follow internal API.
2. API should be symmetric. If you call to _register()/_add(), you will need to call to _unregister()/_del(). Please don't add obscure _put().
3. You can't "ask" from users to call internal calls (put_device) over internal fields in ancillary_device.
4. This API should be clear to drivers authors, "device_add()" call (and semantic) is not used by the drivers (git grep " device_add(" drivers/).

Thanks

Quoted 2 lines

-DaveE

#37 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 110 lines · Leon Romanovsky
Quoted 108 lines · David M
Quoted 90 lines

-----Original Message-----
From: Parav Pandit <[email protected]>
Sent: Wednesday, October 7, 2020 1:17 PM
To: Leon Romanovsky <[email protected]>; Ertman, David M <[email protected]>
Cc: Pierre-Louis Bossart <[email protected]>; alsa- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 11 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 12:56 AM

Quoted 8 lines
Quoted 5 lines

This API is partially obscures low level driver-core code and needs to provide clear and proper abstractions without need to remember about put_device. There is already _add() interface why don't you do put_device() in it?

The pushback Pierre is referring to was during our mid-tier internal review. It was primarily a concern of Parav as I recall, so he can speak to

his

Quoted 7 lines

reasoning.

Quoted 4 lines

What we originally had was a single API call (ancillary_device_register) that started with a call to device_initialize(), and every error path out of the function performed a

put_device().

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Is this the model you have in mind?

I don't like this flow:
ancillary_device_initialize()
if (ancillary_ancillary_device_add()) {
put_device(....)
ancillary_device_unregister()

Calling device_unregister() is incorrect, because add() wasn't successful. Only put_device() or a wrapper ancillary_device_put() is necessary.

Quoted 7 lines

return err;
}

And prefer this flow:
ancillary_device_initialize()
if (ancillary_device_add()) {
ancillary_device_unregister()

This is incorrect and a clear deviation from the current core APIs that adds the confusion.

Quoted 4 lines

return err;
}

In this way, the ancillary users won't need to do non-intuitive put_device();

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
    err = ancillary_device_initialize();
    if (err)
            return ret;

    err = ancillary_device_add();
    if (ret)
            goto err_unwind;

    err = some_foo();
    if (err)
            goto err_foo;
    return 0;

err_foo:

    ancillary_device_del(adev);
err_unwind:
    ancillary_device_put(adev->dev);
    return err;
}

cleanup()

{
    ancillary_device_de(adev);
    ancillary_device_put(adev);
    /* It is common to have a one wrapper for this as
Quoted 10 lines

ancillary_device_unregister().
* This will match with core device_unregister() that has precise
documentation.
* but given fact that init() code need proper error unwinding, like
above,
* it make sense to have two APIs, and no need to export another
symbol for unregister().
* This pattern is very easy to audit and code.
*/
}

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

Quoted 7 lines
Quoted 2 lines

At that point, do we need wrappers on the primitives init, add, del, and put?

Let me summarize.
1. You are not providing driver/core API but simplification and obfuscation of basic primitives and structures. This is new layer. There is no room for a claim that we must to follow internal API.

Yes, this a driver core api, Greg even questioned why it was in drivers/bus instead of drivers/base which I think makes sense.

Quoted 2 lines

2. API should be symmetric. If you call to _register()/_add(), you will need to call to _unregister()/_del(). Please don't add obscure _put().

It's not obscure it's a long standing semantic for how to properly handle device_add() failures. Especially in this case where there is no way to have something like a common auxiliary_device_alloc() that will work for everyone the only other option is require all device destruction to go through the provided release method (put_device()) after a device_add() failure.

Quoted 2 lines

3. You can't "ask" from users to call internal calls (put_device) over internal fields in ancillary_device.

Sure it can. platform_device_add() requires a put_device() on failure, but also note how platform_device_add() *requires* platform_device_alloc() be used to create the device. That inflexibility is something this auxiliary bus is trying to avoid.

Quoted 2 lines

4. This API should be clear to drivers authors, "device_add()" call (and semantic) is not used by the drivers (git grep " device_add(" drivers/).

This shows 141 instances for me, so I'm not sure what you're getting at?

Look, this api is meant to be a replacement for places where platform devices were being abused. The device_initialize() + customize device
+ device_add() organization has the flexibility needed to let users customize naming and other parts of device creation in a way that a device_register() flow, or platform_device_{register,add} in particular, did not.

If the concern is that you'd like to have an auxiliary_device_put() for symmetry that would need to come with the same warning as commented on platform_device_put(), i.e. that's it's really only vanity symmetry to be used in error paths. The semantics of device_add() and device_put() on failure are long established, don't invent new behavior for auxiliary_device_add() and auxiliary_device_put() / put_device().

#38 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 114 lines · Dan Williams
Quoted 113 lines · Leon Romanovsky
Quoted 110 lines · David M
Quoted 90 lines

-----Original Message-----
From: Parav Pandit <[email protected]>
Sent: Wednesday, October 7, 2020 1:17 PM
To: Leon Romanovsky <[email protected]>; Ertman, David M <[email protected]>
Cc: Pierre-Louis Bossart <[email protected]>; alsa- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 11 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 12:56 AM

Quoted 8 lines
Quoted 5 lines

This API is partially obscures low level driver-core code and needs to provide clear and proper abstractions without need to remember about put_device. There is already _add() interface why don't you do put_device() in it?

The pushback Pierre is referring to was during our mid-tier internal review. It was primarily a concern of Parav as I recall, so he can speak to

his

Quoted 7 lines

reasoning.

Quoted 4 lines

What we originally had was a single API call (ancillary_device_register) that started with a call to device_initialize(), and every error path out of the function performed a

put_device().

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Is this the model you have in mind?

I don't like this flow:
ancillary_device_initialize()
if (ancillary_ancillary_device_add()) {
put_device(....)
ancillary_device_unregister()

Calling device_unregister() is incorrect, because add() wasn't successful. Only put_device() or a wrapper ancillary_device_put() is necessary.

Quoted 7 lines

return err;
}

And prefer this flow:
ancillary_device_initialize()
if (ancillary_device_add()) {
ancillary_device_unregister()

This is incorrect and a clear deviation from the current core APIs that adds the confusion.

Quoted 4 lines

return err;
}

In this way, the ancillary users won't need to do non-intuitive put_device();

Below is most simple, intuitive and matching with core APIs for name and design pattern wise.
init()

{
    err = ancillary_device_initialize();
    if (err)
            return ret;

    err = ancillary_device_add();
    if (ret)
            goto err_unwind;

    err = some_foo();
    if (err)
            goto err_foo;
    return 0;

err_foo:

    ancillary_device_del(adev);
err_unwind:
    ancillary_device_put(adev->dev);
    return err;
}

cleanup()

{
    ancillary_device_de(adev);
    ancillary_device_put(adev);
    /* It is common to have a one wrapper for this as
Quoted 10 lines

ancillary_device_unregister().
* This will match with core device_unregister() that has precise
documentation.
* but given fact that init() code need proper error unwinding, like
above,
* it make sense to have two APIs, and no need to export another
symbol for unregister().
* This pattern is very easy to audit and code.
*/
}

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

At that point, do we need wrappers on the primitives init, add, del, and put?

Quoted 7 lines
Quoted 4 lines

Let me summarize.
1. You are not providing driver/core API but simplification and obfuscation of basic primitives and structures. This is new layer. There is no room for a claim that we must to follow internal API.

Yes, this a driver core api, Greg even questioned why it was in drivers/bus instead of drivers/base which I think makes sense.

We can argue till death, but at the end, this is a bus.

Quoted 10 lines
Quoted 3 lines

2. API should be symmetric. If you call to _register()/_add(), you will need to call to _unregister()/_del(). Please don't add obscure _put().

It's not obscure it's a long standing semantic for how to properly handle device_add() failures. Especially in this case where there is no way to have something like a common auxiliary_device_alloc() that will work for everyone the only other option is require all device destruction to go through the provided release method (put_device()) after a device_add() failure.

And this is my main concern, this is not device_add() failure but ancillary_device_add() which hides driver_* logic.

We won't expect to see inside ancillary drivers direct calls to device_*(), why will it be different here with put_device?

Quoted 8 lines
Quoted 3 lines

3. You can't "ask" from users to call internal calls (put_device) over internal fields in ancillary_device.

Sure it can. platform_device_add() requires a put_device() on failure, but also note how platform_device_add() *requires* platform_device_alloc() be used to create the device. That inflexibility is something this auxiliary bus is trying to avoid.

I'm writing below, the rationale behind this bus is RDMA, netdev and other cross-subsystem devices.

Quoted 5 lines
Quoted 3 lines

4. This API should be clear to drivers authors, "device_add()" call (and semantic) is not used by the drivers (git grep " device_add(" drivers/).

This shows 141 instances for me, so I'm not sure what you're getting at?

Did you look at them? I did, most if not all of the calls are in bus/core/generic logic, drivers are not calling to it or at least not supposed to.

Quoted 7 lines

Look, this api is meant to be a replacement for places where platform devices were being abused. The device_initialize() + customize device
+ device_add() organization has the flexibility needed to let users customize naming and other parts of device creation in a way that a device_register() flow, or platform_device_{register,add} in particular, did not.

It is hard me to say if the goal it to replace platform devices or not, but this ancillary_device bus adventure started after request to stop reinvent PCI logic for every new RDMA (RoCE) drivers. This is there full power of this virtbus solution comes into full power by deleting tons of complex code.

Quoted 8 lines

If the concern is that you'd like to have an auxiliary_device_put() for symmetry that would need to come with the same warning as commented on platform_device_put(), i.e. that's it's really only vanity symmetry to be used in error paths. The semantics of device_add() and device_put() on failure are long established, don't invent new behavior for auxiliary_device_add() and auxiliary_device_put() / put_device().

All stated above is my opinion, it can be different from yours.

Thanks

#39 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

On Thu, Oct 8, 2020 at 12:01 AM Leon Romanovsky <[email protected]> wrote:
[..]

Quoted 1 line

All stated above is my opinion, it can be different from yours.

Yes, but we need to converge to move this forward. Jason was involved in the current organization for registration, Greg was angling for this to be core functionality. I have use cases outside of RDMA and netdev. Parav was ok with the current organization. The SOF folks already have a proposed incorporation of it. The argument I am hearing is that "this registration api seems hard for driver writers" when we have several driver writers who have already taken a look and can make it work. If you want to follow on with a simpler wrappers for your use case, great, but I do not yet see anyone concurring with your opinion that the current organization is irretrievably broken or too obscure to use.

#40 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 4 lines · Dan Williams

On Thu, Oct 8, 2020 at 12:01 AM Leon Romanovsky <[email protected]> wrote:
[..]

Quoted 1 line

All stated above is my opinion, it can be different from yours.

Quoted 11 lines

Yes, but we need to converge to move this forward. Jason was involved in the current organization for registration, Greg was angling for this to be core functionality. I have use cases outside of RDMA and netdev. Parav was ok with the current organization. The SOF folks already have a proposed incorporation of it. The argument I am hearing is that "this registration api seems hard for driver writers" when we have several driver writers who have already taken a look and can make it work. If you want to follow on with a simpler wrappers for your use case, great, but I do not yet see anyone concurring with your opinion that the current organization is irretrievably broken or too obscure to use.

That's kind of because I tuned out of this thread a long time ago :)

I do agree with Leon that I think the current patch is not the correct way to do this the easiest, but don't have a competing proposal to show what I mean.

Yet.

Let's see what happens after 5.10-rc1 is out, it's too late now for any of this for this next merge window so we can not worry about it for a few weeks.

thanks,

greg k-h

#41 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 22 lines

From: [email protected] <[email protected]>
Sent: Thursday, October 8, 2020 1:21 PM

Quoted 1 line · Dan Williams

On Thu, Oct 8, 2020 at 12:01 AM Leon Romanovsky <[email protected]>

Quoted 14 lines · wrote:

[..]

Quoted 1 line

All stated above is my opinion, it can be different from yours.

Yes, but we need to converge to move this forward. Jason was involved in the current organization for registration, Greg was angling for this to be core functionality. I have use cases outside of RDMA and netdev. Parav was ok with the current organization. The SOF folks already have a proposed incorporation of it. The argument I am hearing is that "this registration api seems hard for driver writers" when we have several driver writers who have already taken a look and can make it work. If you want to follow on with a simpler wrappers for your use case, great, but I do not yet see anyone concurring with your opinion that the current organization is irretrievably broken or too obscure to use.

Quoted 7 lines

That's kind of because I tuned out of this thread a long time ago :)

I do agree with Leon that I think the current patch is not the correct way to do this the easiest, but don't have a competing proposal to show what I mean.

Yet.

Please consider the approach of ib_alloc_device(), ib_dealloc_device() and ib_register_register()/unregister().
(a) It avoids driver calling put_device() on error unwinding path.
(b) still achieves container_of().

Quoted 4 lines

Let's see what happens after 5.10-rc1 is out, it's too late now for any of this for this next merge window so we can not worry about it for a few weeks.

Ok. INHO giving direction to Dave and others to either refine current APIs or follow ib_alloc_device() approach will be a helpful input.

ancillary bus can do better APIs than the newly (march 2020 !) introduced vdpa bus [1] and its drivers which follows put_device() pattern in [2] and [3] in error unwinding path.

[1] https://elixir.bootlin.com/linux/v5.9-rc8/source/drivers/vdpa/vdpa.c
[2] https://elixir.bootlin.com/linux/v5.9-rc8/source/drivers/vdpa/ifcvf/ifcvf_main.c#L475
[3] https://elixir.bootlin.com/linux/v5.9-rc8/source/drivers/vdpa/mlx5/net/mlx5_vnet.c#L1967

Quoted 3 lines

thanks,

greg k-h

#42 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 60 lines

-----Original Message-----
From: Parav Pandit <[email protected]>
Sent: Thursday, October 8, 2020 4:10 AM
To: [email protected]; Williams, Dan J <[email protected]>
Cc: Leon Romanovsky <[email protected]>; Ertman, David M <[email protected]>; Pierre-Louis Bossart <pierre- [email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 21 lines

From: [email protected] <[email protected]>
Sent: Thursday, October 8, 2020 1:21 PM

Quoted 1 line · Dan Williams

On Thu, Oct 8, 2020 at 12:01 AM Leon Romanovsky <[email protected]>

Quoted 14 lines · wrote:

[..]

Quoted 1 line

All stated above is my opinion, it can be different from yours.

Yes, but we need to converge to move this forward. Jason was involved in the current organization for registration, Greg was angling for this to be core functionality. I have use cases outside of RDMA and netdev. Parav was ok with the current organization. The SOF folks already have a proposed incorporation of it. The argument I am hearing is that "this registration api seems hard for driver writers" when we have several driver writers who have already taken a look and can make it work. If you want to follow on with a simpler wrappers for your use case, great, but I do not yet see anyone concurring with your opinion that the current organization is irretrievably broken or too obscure to use.

Quoted 7 lines

That's kind of because I tuned out of this thread a long time ago :)

I do agree with Leon that I think the current patch is not the correct way to do this the easiest, but don't have a competing proposal to show what I mean.

Yet.

Please consider the approach of ib_alloc_device(), ib_dealloc_device() and ib_register_register()/unregister().
(a) It avoids driver calling put_device() on error unwinding path.
(b) still achieves container_of().

Quoted 4 lines

Let's see what happens after 5.10-rc1 is out, it's too late now for any of this for this next merge window so we can not worry about it for a few weeks.

Ok. INHO giving direction to Dave and others to either refine current APIs or follow ib_alloc_device() approach will be a helpful input.

ancillary bus can do better APIs than the newly (march 2020 !) introduced vdpa bus [1] and its drivers which follows put_device() pattern in [2] and [3] in error unwinding path.

Quoted 9 lines

[1] https://elixir.bootlin.com/linux/v5.9-rc8/source/drivers/vdpa/vdpa.c
[2] https://elixir.bootlin.com/linux/v5.9-
rc8/source/drivers/vdpa/ifcvf/ifcvf_main.c#L475
[3] https://elixir.bootlin.com/linux/v5.9-
rc8/source/drivers/vdpa/mlx5/net/mlx5_vnet.c#L1967

Quoted 3 lines

thanks,

greg k-h

IMHO we need to stay with the two step registration process that we currently have (initialize then add) so that the driver writer knows if they need to explicitly free the memory allocated for auxillary_device. Sound folks have indicated that this really helps their flow also. Greg asked to have these two functions fully commented with kernel-doc headers, which has been done.

Without enforcing an "auxillary_object" that contains just an auxillary_device and a void pointer, we cannot do the allocation of memory in the bus infrastructure without breaking the container_of functionality.

-DaveE

#43 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

In reply to Dan Williams
Quoted 4 lines · Dan Williams

On Thu, Oct 8, 2020 at 12:01 AM Leon Romanovsky <[email protected]> wrote:
[..]

Quoted 1 line

All stated above is my opinion, it can be different from yours.

Quoted 11 lines

Yes, but we need to converge to move this forward. Jason was involved in the current organization for registration, Greg was angling for this to be core functionality. I have use cases outside of RDMA and netdev. Parav was ok with the current organization. The SOF folks already have a proposed incorporation of it. The argument I am hearing is that "this registration api seems hard for driver writers" when we have several driver writers who have already taken a look and can make it work. If you want to follow on with a simpler wrappers for your use case, great, but I do not yet see anyone concurring with your opinion that the current organization is irretrievably broken or too obscure to use.

Can it be that I'm first one to use this bus for very large driver (>120K LOC) that has 5 different ->probe() flows?

For example, this https://lore.kernel.org/linux-rdma/20201006172317.GN1874917@unreal/
hints to me that this bus wasn't used with anything complex as it was initially intended.

And regarding registration, I said many times that init()/add() scheme is ok, the inability to call to uninit() after add() failure is not ok from my point of view.

Thanks

#44 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 18 lines · Leon Romanovsky
Quoted 4 lines · Dan Williams

On Thu, Oct 8, 2020 at 12:01 AM Leon Romanovsky <[email protected]> wrote:
[..]

Quoted 1 line

All stated above is my opinion, it can be different from yours.

Quoted 11 lines

Yes, but we need to converge to move this forward. Jason was involved in the current organization for registration, Greg was angling for this to be core functionality. I have use cases outside of RDMA and netdev. Parav was ok with the current organization. The SOF folks already have a proposed incorporation of it. The argument I am hearing is that "this registration api seems hard for driver writers" when we have several driver writers who have already taken a look and can make it work. If you want to follow on with a simpler wrappers for your use case, great, but I do not yet see anyone concurring with your opinion that the current organization is irretrievably broken or too obscure to use.

Quoted 5 lines

Can it be that I'm first one to use this bus for very large driver (>120K LOC) that has 5 different ->probe() flows?

For example, this https://lore.kernel.org/linux-rdma/20201006172317.GN1874917@unreal/
hints to me that this bus wasn't used with anything complex as it was initially intended.

I missed that. Yes, I agree that's broken.

Quoted 3 lines

And regarding registration, I said many times that init()/add() scheme is ok, the inability to call to uninit() after add() failure is not ok from my point of view.

Ok, I got to the wrong conclusion about your position.

#45 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

In reply to Leon Romanovsky
Quoted 36 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 1:00 AM
To: Williams, Dan J <[email protected]>
Cc: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Pierre-Louis Bossart <pierre- [email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 1 line · Dan Williams

On Thu, Oct 8, 2020 at 12:01 AM Leon Romanovsky <[email protected]>

Quoted 14 lines · wrote:

[..]

Quoted 1 line

All stated above is my opinion, it can be different from yours.

Yes, but we need to converge to move this forward. Jason was involved in the current organization for registration, Greg was angling for this to be core functionality. I have use cases outside of RDMA and netdev. Parav was ok with the current organization. The SOF folks already have a proposed incorporation of it. The argument I am hearing is that "this registration api seems hard for driver writers" when we have several driver writers who have already taken a look and can make it work. If you want to follow on with a simpler wrappers for your use case, great, but I do not yet see anyone concurring with your opinion that the current organization is irretrievably broken or too obscure to use.

Can it be that I'm first one to use this bus for very large driver (>120K LOC) that has 5 different ->probe() flows?

Quoted 8 lines

For example, this https://lore.kernel.org/linux-
rdma/20201006172317.GN1874917@unreal/
hints to me that this bus wasn't used with anything complex as it was initially intended.

And regarding registration, I said many times that init()/add() scheme is ok, the inability
to call to uninit() after add() failure is not ok from my point of view.

So, to address your concern of not being able to call an uninit after a add failure I can break the unregister flow into two steps also. An uninit and a delete to mirror the registration process's init and add.

Would this make the registration and un-registration flow acceptable?

-DaveE

Quoted 2 lines

Thanks

#46 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 45 lines · David M
Quoted 36 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 1:00 AM
To: Williams, Dan J <[email protected]>
Cc: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Pierre-Louis Bossart <pierre- [email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 1 line · Dan Williams

On Thu, Oct 8, 2020 at 12:01 AM Leon Romanovsky <[email protected]>

Quoted 14 lines · wrote:

[..]

Quoted 1 line

All stated above is my opinion, it can be different from yours.

Yes, but we need to converge to move this forward. Jason was involved in the current organization for registration, Greg was angling for this to be core functionality. I have use cases outside of RDMA and netdev. Parav was ok with the current organization. The SOF folks already have a proposed incorporation of it. The argument I am hearing is that "this registration api seems hard for driver writers" when we have several driver writers who have already taken a look and can make it work. If you want to follow on with a simpler wrappers for your use case, great, but I do not yet see anyone concurring with your opinion that the current organization is irretrievably broken or too obscure to use.

Can it be that I'm first one to use this bus for very large driver (>120K LOC) that has 5 different ->probe() flows?

Quoted 8 lines

For example, this https://lore.kernel.org/linux-
rdma/20201006172317.GN1874917@unreal/
hints to me that this bus wasn't used with anything complex as it was initially intended.

And regarding registration, I said many times that init()/add() scheme is ok, the inability
to call to uninit() after add() failure is not ok from my point of view.

Quoted 5 lines

So, to address your concern of not being able to call an uninit after a add failure I can break the unregister flow into two steps also. An uninit and a delete to mirror the registration process's init and add.

Would this make the registration and un-registration flow acceptable?

Yes, sure.

Quoted 7 lines

-DaveE

Quoted 2 lines

Thanks

#47 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

In reply to Dan Williams
Quoted 139 lines

-----Original Message-----
From: Dan Williams <[email protected]>
Sent: Wednesday, October 7, 2020 11:32 PM
To: Leon Romanovsky <[email protected]>
Cc: Ertman, David M <[email protected]>; Parav Pandit <[email protected]>; Pierre-Louis Bossart <pierre- [email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 13 lines · Leon Romanovsky
Quoted 11 lines · David M
Quoted 11 lines

-----Original Message-----
From: Parav Pandit <[email protected]>
Sent: Wednesday, October 7, 2020 1:17 PM
To: Leon Romanovsky <[email protected]>; Ertman, David M <[email protected]>
Cc: Pierre-Louis Bossart <[email protected]>; alsa- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jason Gunthorpe <[email protected]>; [email protected]; [email protected];

Williams,

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 5 lines

From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 12:56 AM

Quoted 2 lines
Quoted 2 lines

This API is partially obscures low level driver-core code and needs to provide clear and proper abstractions without need to

remember

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

about put_device. There is already _add() interface why don't you

do

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

put_device() in it?

The pushback Pierre is referring to was during our mid-tier internal review. It was primarily a concern of Parav as I recall, so he can

speak to

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

his

Quoted 5 lines

reasoning.

Quoted 4 lines

What we originally had was a single API call (ancillary_device_register) that started with a call to device_initialize(), and every error path out of the function

performed a

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

put_device().

Quoted 2 lines

Is this the model you have in mind?

I don't like this flow:
ancillary_device_initialize()
if (ancillary_ancillary_device_add()) {
put_device(....)
ancillary_device_unregister()

Calling device_unregister() is incorrect, because add() wasn't

successful.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Only put_device() or a wrapper ancillary_device_put() is necessary.

Quoted 7 lines

return err;
}

And prefer this flow:
ancillary_device_initialize()
if (ancillary_device_add()) {
ancillary_device_unregister()

This is incorrect and a clear deviation from the current core APIs that

adds the

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

confusion.

Quoted 4 lines

return err;
}

In this way, the ancillary users won't need to do non-intuitive

put_device();

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Below is most simple, intuitive and matching with core APIs for name

and

Quoted 49 lines
Quoted 48 lines
Quoted 28 lines

design pattern wise.
init()

{
    err = ancillary_device_initialize();
    if (err)
            return ret;

    err = ancillary_device_add();
    if (ret)
            goto err_unwind;

    err = some_foo();
    if (err)
            goto err_foo;
    return 0;

err_foo:

    ancillary_device_del(adev);
err_unwind:
    ancillary_device_put(adev->dev);
    return err;
}

cleanup()

{
    ancillary_device_de(adev);
    ancillary_device_put(adev);
    /* It is common to have a one wrapper for this as
Quoted 10 lines

ancillary_device_unregister().
* This will match with core device_unregister() that has precise
documentation.
* but given fact that init() code need proper error unwinding, like
above,
* it make sense to have two APIs, and no need to export another
symbol for unregister().
* This pattern is very easy to audit and code.
*/
}

I like this flow +1

But ... since the init() function is performing both device_init and device_add - it should probably be called ancillary_device_register, and we are back to a single exported API for both register and unregister.

At that point, do we need wrappers on the primitives init, add, del, and put?

Quoted 7 lines
Quoted 4 lines

Let me summarize.
1. You are not providing driver/core API but simplification and obfuscation of basic primitives and structures. This is new layer. There is no room for a claim that we must to follow internal API.

Yes, this a driver core api, Greg even questioned why it was in drivers/bus instead of drivers/base which I think makes sense.

Will move to drivers/base with next patch set.

-DaveE

#48 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

In reply to Leon Romanovsky
Quoted 16 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:03 AM
To: Pierre-Louis Bossart <[email protected]>
Cc: Ertman, David M <[email protected]>; alsa-devel@alsa- project.org; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 1 line · Pierre-Louis Bossart

Thanks for the review Leon.

[...]

Quoted 17 lines
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
drivers/bus/ancillary.c new file +7 -0
+EXPORT_SYMBOL_GPL(__ancillary_device_add);
+
+static int ancillary_probe_driver(struct device *dev)
+{
+	struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
+	struct ancillary_device *ancildev = to_ancillary_dev(dev);
+	int ret;
Quoted 8 lines

drivers/bus/ancillary.c

Quoted 8 lines
drivers/bus/ancillary.c new file +8 -0
+
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret) {
+		dev_warn(dev, "Failed to attach to PM Domain : %d\n", ret);
+		return ret;
+	}
+
+	ret = ancildrv->probe(ancildev, ancillary_match_id(ancildrv-

id_table, ancildev));

Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

I don't think that you need to call ->probe() if ancillary_match_id() returned NULL and probably that check should be done before dev_pm_domain_attach().

we'll look into this.

AKAIK, this callback is only accessed from the bus subsystem after a successful return from ancillary_match().

-DaveE

#49 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

In reply to Pierre-Louis Bossart
Quoted 34 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Tuesday, October 6, 2020 8:18 AM
To: Leon Romanovsky <[email protected]>; Ertman, David M <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Williams, Dan J <[email protected]>; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Thanks for the review Leon.

Quoted 5 lines
Quoted 3 lines

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

I was under impression that this name is going to be changed.

It's part of the opens stated in the cover letter.

[...]

Quoted 7 lines

Documentation/driver-api/ancillary_bus.rst line 221

Quoted 4 lines
Documentation/driver-api/ancillary_bus.rst new file +4 -0
+	const struct my_driver my_drv = {
+		.ancillary_drv = {
+			.driver = {
+				.name = "myancillarydrv",

Why do we need to give control over driver name to the driver authors? It can be problematic if author puts name that already exists.

Quoted 7 lines

Good point. When I used the ancillary_devices for my own SoundWire test, the driver name didn't seem specifically meaningful but needed to be set to something, what mattered was the id_table. Just thinking aloud, maybe we can add prefixing with KMOD_BUILD, as we've done already to avoid collisions between device names?

[...]

Since we have eliminated all IDA type things out of the bus infrastructure, I like the idea of prefixing the driver name with KBUILD_MODNAME through a macro front. Since a parent driver can register more than one ancillary driver, this allow the parent to have an internally meaningful name while still ensuring its uniqueness.

-DaveE

#50 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

In reply to Dave Ertman
Quoted 20 lines · Dave Ertman

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

The bus supports probe/remove shutdown and suspend/resume callbacks. Each ancillary_device has a unique string based id; driver binds to an ancillary_device based on this id through the bus.

---

<...>

drivers/bus/ancillary.c line 197

Quoted 10 lines
drivers/bus/ancillary.c new file +10 -0
+/**
+ * __ancillary_driver_register - register a driver for ancillary bus devices
+ * @ancildrv: ancillary_driver structure
+ * @owner: owning module/driver
+ */
+int __ancillary_driver_register(struct ancillary_driver *ancildrv, struct module *owner)
+{
+	if (WARN_ON(!ancildrv->probe) || WARN_ON(!ancildrv->remove) ||
+	    WARN_ON(!ancildrv->shutdown) || WARN_ON(!ancildrv->id_table))
+		return -EINVAL;

In our driver ->shutdown is empty, it will be best if ancillary bus will do "if (->remove) ..->remove()" pattern.

drivers/bus/ancillary.c line 204

Quoted 7 lines
drivers/bus/ancillary.c new file +7 -0
+
+	ancildrv->driver.owner = owner;
+	ancildrv->driver.bus = &ancillary_bus_type;
+	ancildrv->driver.probe = ancillary_probe_driver;
+	ancildrv->driver.remove = ancillary_remove_driver;
+	ancildrv->driver.shutdown = ancillary_shutdown_driver;
+

I think that this part is wrong, probe/remove/shutdown functions should come from ancillary_bus_type. You are overwriting private device_driver callbacks that makes impossible to make container_of of ancillary_driver to chain operations.

drivers/bus/ancillary.c line 207

Quoted 3 lines
drivers/bus/ancillary.c new file +3 -0
+	return driver_register(&ancildrv->driver);
+}
+EXPORT_SYMBOL_GPL(__ancillary_driver_register);

Thanks

#51 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 27 lines

Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 21 lines · Dave Ertman

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

The bus supports probe/remove shutdown and suspend/resume callbacks. Each ancillary_device has a unique string based id; driver binds to an ancillary_device based on this id through the bus.

<[email protected]>

---

<...>

Quoted 15 lines

drivers/bus/ancillary.c line 197

Quoted 11 lines
drivers/bus/ancillary.c new file +11 -0
+/**
+ * __ancillary_driver_register - register a driver for ancillary bus
+devices
+ * @ancildrv: ancillary_driver structure
+ * @owner: owning module/driver
+ */
+int __ancillary_driver_register(struct ancillary_driver *ancildrv,
+struct module *owner) {
+	if (WARN_ON(!ancildrv->probe) || WARN_ON(!ancildrv->remove) ||
+	    WARN_ON(!ancildrv->shutdown) || WARN_ON(!ancildrv->id_table))
+		return -EINVAL;

In our driver ->shutdown is empty, it will be best if ancillary bus will do "if (-

Quoted 1 line

remove) ..->remove()" pattern.

I prefer that too if its possible. We will look into it.

#52 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

In reply to Leon Romanovsky
Quoted 48 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:23 AM
To: Ertman, David M <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; pierre- [email protected]; [email protected]; [email protected]; Saleem, Shiraz <[email protected]>; Williams, Dan J <[email protected]>; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 20 lines · Dave Ertman

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

The bus supports probe/remove shutdown and suspend/resume callbacks. Each ancillary_device has a unique string based id; driver binds to an ancillary_device based on this id through the bus.

---

<...>

drivers/bus/ancillary.c

Quoted 6 lines
drivers/bus/ancillary.c new file +6 -0
+/**
+ * __ancillary_driver_register - register a driver for ancillary bus devices
+ * @ancildrv: ancillary_driver structure
+ * @owner: owning module/driver
+ */
+int __ancillary_driver_register(struct ancillary_driver *ancildrv, struct

module *owner)

Review

Quoted 2 lines
(quoted diff) +2 -0
+{
+	if (WARN_ON(!ancildrv->probe) || WARN_ON(!ancildrv->remove)
||
> +	    WARN_ON(!ancildrv->shutdown) || WARN_ON(!ancildrv-
Quoted 6 lines

Review

Quoted 2 lines

id_table))

(quoted diff) +1 -0
+		return -EINVAL;

In our driver ->shutdown is empty, it will be best if ancillary bus will do "if (->remove) ..->remove()" pattern.

Yes, looking it over, only the probe needs to mandatory. I will change the others to the conditional model, and adjust the WARN_ONs.

Quoted 10 lines

drivers/bus/ancillary.c line 204

Quoted 7 lines
drivers/bus/ancillary.c new file +7 -0
+
+	ancildrv->driver.owner = owner;
+	ancildrv->driver.bus = &ancillary_bus_type;
+	ancildrv->driver.probe = ancillary_probe_driver;
+	ancildrv->driver.remove = ancillary_remove_driver;
+	ancildrv->driver.shutdown = ancillary_shutdown_driver;
+

I think that this part is wrong, probe/remove/shutdown functions should come from ancillary_bus_type.

From checking other usage cases, this is the model that is used for probe, remove, and shutdown in drivers. Here is the example from Greybus.

int greybus_register_driver(struct greybus_driver *driver, struct module *owner,
const char *mod_name)

{
        int retval;

        if (greybus_disabled())
                return -ENODEV;

        driver->driver.bus = &greybus_bus_type;
        driver->driver.name = driver->name;
        driver->driver.probe = greybus_probe;
        driver->driver.remove = greybus_remove;
        driver->driver.owner = owner;
        driver->driver.mod_name = mod_name;
Quoted 4 lines

You are overwriting private device_driver
callbacks that makes impossible to make container_of of ancillary_driver to chain operations.

I am sorry, you lost me here. you cannot perform container_of on the callbacks because they are pointers, but if you are referring to going from device_driver to the auxiliary_driver, that is what happens in auxiliary_probe_driver in the very beginning.

static int auxiliary_probe_driver(struct device *dev) 145 {
146 struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
147 struct auxiliary_device *auxdev = to_auxiliary_dev(dev);

Did I miss your meaning?

-DaveE

Quoted 5 lines

drivers/bus/ancillary.c line 207

Quoted 3 lines
drivers/bus/ancillary.c new file +3 -0
+	return driver_register(&ancildrv->driver);
+}
+EXPORT_SYMBOL_GPL(__ancillary_driver_register);

Thanks

#53 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 100 lines · David M
Quoted 47 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Tuesday, October 6, 2020 10:23 AM
To: Ertman, David M <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; pierre- [email protected]; [email protected]; [email protected]; Saleem, Shiraz <[email protected]>; Williams, Dan J <[email protected]>; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 20 lines · Dave Ertman

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

The bus supports probe/remove shutdown and suspend/resume callbacks. Each ancillary_device has a unique string based id; driver binds to an ancillary_device based on this id through the bus.

---

<...>

drivers/bus/ancillary.c

Quoted 6 lines
drivers/bus/ancillary.c new file +6 -0
+/**
+ * __ancillary_driver_register - register a driver for ancillary bus devices
+ * @ancildrv: ancillary_driver structure
+ * @owner: owning module/driver
+ */
+int __ancillary_driver_register(struct ancillary_driver *ancildrv, struct

module *owner)

Review

Quoted 2 lines
(quoted diff) +2 -0
+{
+   if (WARN_ON(!ancildrv->probe) || WARN_ON(!ancildrv->remove)
Quoted 8 lines
||
> +       WARN_ON(!ancildrv->shutdown) || WARN_ON(!ancildrv-
Quoted 2 lines

id_table))
+ return -EINVAL;

In our driver ->shutdown is empty, it will be best if ancillary bus will do "if (->remove) ..->remove()" pattern.

Yes, looking it over, only the probe needs to mandatory. I will change the others to the conditional model, and adjust the WARN_ONs.

Quoted 10 lines

drivers/bus/ancillary.c line 204

Quoted 7 lines
drivers/bus/ancillary.c new file +7 -0
+
+   ancildrv->driver.owner = owner;
+   ancildrv->driver.bus = &ancillary_bus_type;
+   ancildrv->driver.probe = ancillary_probe_driver;
+   ancildrv->driver.remove = ancillary_remove_driver;
+   ancildrv->driver.shutdown = ancillary_shutdown_driver;
+

I think that this part is wrong, probe/remove/shutdown functions should come from ancillary_bus_type.

From checking other usage cases, this is the model that is used for probe, remove, and shutdown in drivers. Here is the example from Greybus.

int greybus_register_driver(struct greybus_driver *driver, struct module *owner,
const char *mod_name)

{
        int retval;

        if (greybus_disabled())
                return -ENODEV;

        driver->driver.bus = &greybus_bus_type;
        driver->driver.name = driver->name;
        driver->driver.probe = greybus_probe;
        driver->driver.remove = greybus_remove;
        driver->driver.owner = owner;
        driver->driver.mod_name = mod_name;
Quoted 4 lines

You are overwriting private device_driver
callbacks that makes impossible to make container_of of ancillary_driver to chain operations.

I am sorry, you lost me here. you cannot perform container_of on the callbacks because they are pointers, but if you are referring to going from device_driver to the auxiliary_driver, that is what happens in auxiliary_probe_driver in the very beginning.

Quoted 6 lines

static int auxiliary_probe_driver(struct device *dev) 145 {
146 struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
147 struct auxiliary_device *auxdev = to_auxiliary_dev(dev);

Did I miss your meaning?

I think you're misunderstanding the cases when the bus_type.{probe,remove} is used vs the driver.{probe,remove} callbacks. The bus_type callbacks are to implement a pattern where the 'probe' and 'remove' method are typed to the bus device type. For example 'struct pci_dev *' instead of raw 'struct device *'. See this conversion of dax bus as an example of going from raw 'struct device *' typed probe/remove to dax-device typed probe/remove:

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=75797273189d

#54 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 57 lines
Quoted 42 lines
Quoted 12 lines

drivers/bus/ancillary.c line 204

Quoted 9 lines
drivers/bus/ancillary.c new file +7 -0
+
+   ancildrv->driver.owner = owner;
+   ancildrv->driver.bus = &ancillary_bus_type;
+   ancildrv->driver.probe = ancillary_probe_driver;
+   ancildrv->driver.remove = ancillary_remove_driver;
+   ancildrv->driver.shutdown = ancillary_shutdown_driver;
+

I think that this part is wrong, probe/remove/shutdown functions should come from ancillary_bus_type.

From checking other usage cases, this is the model that is used for probe, remove,
and shutdown in drivers. Here is the example from Greybus.

int greybus_register_driver(struct greybus_driver *driver, struct module *owner,
const char *mod_name)

{
         int retval;

         if (greybus_disabled())
                 return -ENODEV;

         driver->driver.bus = &greybus_bus_type;
         driver->driver.name = driver->name;
         driver->driver.probe = greybus_probe;
         driver->driver.remove = greybus_remove;
         driver->driver.owner = owner;
         driver->driver.mod_name = mod_name;
Quoted 4 lines

You are overwriting private device_driver
callbacks that makes impossible to make container_of of ancillary_driver to chain operations.

I am sorry, you lost me here. you cannot perform container_of on the callbacks because they are pointers, but if you are referring to going from device_driver to the auxiliary_driver, that is what happens in auxiliary_probe_driver in the very beginning.

Quoted 6 lines

static int auxiliary_probe_driver(struct device *dev) 145 {
146 struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
147 struct auxiliary_device *auxdev = to_auxiliary_dev(dev);

Did I miss your meaning?

I think you're misunderstanding the cases when the bus_type.{probe,remove} is used vs the driver.{probe,remove} callbacks. The bus_type callbacks are to implement a pattern where the 'probe' and 'remove' method are typed to the bus device type. For example 'struct pci_dev *' instead of raw 'struct device *'. See this conversion of dax bus as an example of going from raw 'struct device *' typed probe/remove to dax-device typed probe/remove:

Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=75797273189d

Thanks Dan for the reference, very useful. This doesn't look like a a big change to implement, just wondering about the benefits and drawbacks, if any? I am a bit confused here.

First, was the initial pattern wrong as Leon asserted it? Such code exists in multiple examples in the kernel and there's nothing preventing the use of container_of that I can think of. Put differently, if this code was wrong then there are other existing buses that need to be updated.

Second, what additional functionality does this move from driver to bus_type provide? The commit reference just states 'In preparation for introducing seed devices the dax-bus core needs to be able to intercept ->probe() and ->remove() operations", but that doesn't really help me figure out what 'intercept' means. Would you mind elaborating?

And last, the existing probe function does calls dev_pm_domain_attach():

static int ancillary_probe_driver(struct device *dev)

{
	struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
	struct ancillary_device *ancildev = to_ancillary_dev(dev);
	int ret;

	ret = dev_pm_domain_attach(dev, true);

So the need to access the raw device still exists. Is this still legit if the probe() is moved to the bus_type structure?

I have no objection to this change if it preserves the same functionality and possibly extends it, just wanted to better understand the reasons for the change and in which cases the bus probe() makes more sense than a driver probe().

Thanks for enlightening the rest of us!

#55 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 85 lines · Pierre-Louis Bossart
Quoted 58 lines
Quoted 43 lines
Quoted 13 lines

drivers/bus/ancillary.c line 204

Quoted 10 lines
drivers/bus/ancillary.c new file +7 -0
+
+   ancildrv->driver.owner = owner;
+   ancildrv->driver.bus = &ancillary_bus_type;
+   ancildrv->driver.probe = ancillary_probe_driver;
+   ancildrv->driver.remove = ancillary_remove_driver;
+   ancildrv->driver.shutdown = ancillary_shutdown_driver;
+

I think that this part is wrong, probe/remove/shutdown functions should come from ancillary_bus_type.

From checking other usage cases, this is the model that is used for probe, remove,
and shutdown in drivers. Here is the example from Greybus.

int greybus_register_driver(struct greybus_driver *driver, struct module *owner,
const char *mod_name)

{
         int retval;

         if (greybus_disabled())
                 return -ENODEV;

         driver->driver.bus = &greybus_bus_type;
         driver->driver.name = driver->name;
         driver->driver.probe = greybus_probe;
         driver->driver.remove = greybus_remove;
         driver->driver.owner = owner;
         driver->driver.mod_name = mod_name;
Quoted 4 lines

You are overwriting private device_driver
callbacks that makes impossible to make container_of of ancillary_driver to chain operations.

I am sorry, you lost me here. you cannot perform container_of on the callbacks because they are pointers, but if you are referring to going from device_driver to the auxiliary_driver, that is what happens in auxiliary_probe_driver in the very beginning.

Quoted 6 lines

static int auxiliary_probe_driver(struct device *dev) 145 {
146 struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
147 struct auxiliary_device *auxdev = to_auxiliary_dev(dev);

Did I miss your meaning?

I think you're misunderstanding the cases when the bus_type.{probe,remove} is used vs the driver.{probe,remove} callbacks. The bus_type callbacks are to implement a pattern where the 'probe' and 'remove' method are typed to the bus device type. For example 'struct pci_dev *' instead of raw 'struct device *'. See this conversion of dax bus as an example of going from raw 'struct device *' typed probe/remove to dax-device typed probe/remove:

Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=75797273189d

Thanks Dan for the reference, very useful. This doesn't look like a a big change to implement, just wondering about the benefits and drawbacks, if any? I am a bit confused here.

First, was the initial pattern wrong as Leon asserted it? Such code exists in multiple examples in the kernel and there's nothing preventing the use of container_of that I can think of. Put differently, if this code was wrong then there are other existing buses that need to be updated.

Second, what additional functionality does this move from driver to bus_type provide? The commit reference just states 'In preparation for introducing seed devices the dax-bus core needs to be able to intercept ->probe() and ->remove() operations", but that doesn't really help me figure out what 'intercept' means. Would you mind elaborating?

And last, the existing probe function does calls dev_pm_domain_attach():

static int ancillary_probe_driver(struct device *dev)

{
        struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
        struct ancillary_device *ancildev = to_ancillary_dev(dev);
        int ret;

        ret = dev_pm_domain_attach(dev, true);
Quoted 2 lines

So the need to access the raw device still exists. Is this still legit if the probe() is moved to the bus_type structure?

Sure, of course.

Quoted 7 lines

I have no objection to this change if it preserves the same functionality and possibly extends it, just wanted to better understand the reasons for the change and in which cases the bus probe() makes more sense than a driver probe().

Thanks for enlightening the rest of us!

tl;dr: The ops set by the device driver should never be overwritten by the bus, the bus can only wrap them in its own ops.

The reason to use the bus_type is because the bus type is the only agent that knows both how to convert a raw 'struct device *' to the bus's native type, and how to convert a raw 'struct device_driver *' to the bus's native driver type. The driver core does:

        if (dev->bus->probe) {
                ret = dev->bus->probe(dev);
        } else if (drv->probe) {
                ret = drv->probe(dev);
        }

...so that the bus has the first priority for probing a device / wrapping the native driver ops. The bus ->probe, in addition to optionally performing some bus specific pre-work, lets the bus upcast the device to bus-native type.

The bus also knows the types of drivers that will be registered to it, so the bus can upcast the dev->driver to the native type.

So with bus_type based driver ops driver authors can do:

struct auxiliary_device_driver auxdrv {
.probe = fn(struct auxiliary_device *, <any aux bus custom probe arguments>)
};

auxiliary_driver_register(&auxdrv); <-- the core code can hide bus details

Without bus_type the driver author would need to do:

struct auxiliary_device_driver auxdrv {
.drv = {
.probe = fn(struct device *), <-- no opportunity for bus
specific probe args
.bus = &auxilary_bus_type, <-- unnecessary export to device drivers
},
};

driver_register(&auxdrv.drv)

#56 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 136 lines
Quoted 83 lines
Quoted 56 lines
Quoted 41 lines
Quoted 11 lines

drivers/bus/ancillary.c line 204

Quoted 8 lines
drivers/bus/ancillary.c new file +7 -0
+
+   ancildrv->driver.owner = owner;
+   ancildrv->driver.bus = &ancillary_bus_type;
+   ancildrv->driver.probe = ancillary_probe_driver;
+   ancildrv->driver.remove = ancillary_remove_driver;
+   ancildrv->driver.shutdown = ancillary_shutdown_driver;
+

I think that this part is wrong, probe/remove/shutdown functions should come from ancillary_bus_type.

From checking other usage cases, this is the model that is used for probe, remove,
and shutdown in drivers. Here is the example from Greybus.

int greybus_register_driver(struct greybus_driver *driver, struct module *owner,
const char *mod_name)

{
          int retval;

          if (greybus_disabled())
                  return -ENODEV;

          driver->driver.bus = &greybus_bus_type;
          driver->driver.name = driver->name;
          driver->driver.probe = greybus_probe;
          driver->driver.remove = greybus_remove;
          driver->driver.owner = owner;
          driver->driver.mod_name = mod_name;
Quoted 4 lines

You are overwriting private device_driver
callbacks that makes impossible to make container_of of ancillary_driver to chain operations.

I am sorry, you lost me here. you cannot perform container_of on the callbacks because they are pointers, but if you are referring to going from device_driver to the auxiliary_driver, that is what happens in auxiliary_probe_driver in the very beginning.

Quoted 6 lines

static int auxiliary_probe_driver(struct device *dev) 145 {
146 struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
147 struct auxiliary_device *auxdev = to_auxiliary_dev(dev);

Did I miss your meaning?

I think you're misunderstanding the cases when the bus_type.{probe,remove} is used vs the driver.{probe,remove} callbacks. The bus_type callbacks are to implement a pattern where the 'probe' and 'remove' method are typed to the bus device type. For example 'struct pci_dev *' instead of raw 'struct device *'. See this conversion of dax bus as an example of going from raw 'struct device *' typed probe/remove to dax-device typed probe/remove:

Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=75797273189d

Thanks Dan for the reference, very useful. This doesn't look like a a big change to implement, just wondering about the benefits and drawbacks, if any? I am a bit confused here.

First, was the initial pattern wrong as Leon asserted it? Such code exists in multiple examples in the kernel and there's nothing preventing the use of container_of that I can think of. Put differently, if this code was wrong then there are other existing buses that need to be updated.

Second, what additional functionality does this move from driver to bus_type provide? The commit reference just states 'In preparation for introducing seed devices the dax-bus core needs to be able to intercept ->probe() and ->remove() operations", but that doesn't really help me figure out what 'intercept' means. Would you mind elaborating?

And last, the existing probe function does calls dev_pm_domain_attach():

static int ancillary_probe_driver(struct device *dev)

{
         struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
         struct ancillary_device *ancildev = to_ancillary_dev(dev);
         int ret;

         ret = dev_pm_domain_attach(dev, true);
Quoted 2 lines

So the need to access the raw device still exists. Is this still legit if the probe() is moved to the bus_type structure?

Sure, of course.

Quoted 7 lines

I have no objection to this change if it preserves the same functionality and possibly extends it, just wanted to better understand the reasons for the change and in which cases the bus probe() makes more sense than a driver probe().

Thanks for enlightening the rest of us!

tl;dr: The ops set by the device driver should never be overwritten by the bus, the bus can only wrap them in its own ops.

The reason to use the bus_type is because the bus type is the only agent that knows both how to convert a raw 'struct device *' to the bus's native type, and how to convert a raw 'struct device_driver *' to the bus's native driver type. The driver core does:

         if (dev->bus->probe) {
                 ret = dev->bus->probe(dev);
         } else if (drv->probe) {
                 ret = drv->probe(dev);
         }

...so that the bus has the first priority for probing a device / wrapping the native driver ops. The bus ->probe, in addition to optionally performing some bus specific pre-work, lets the bus upcast the device to bus-native type.

The bus also knows the types of drivers that will be registered to it, so the bus can upcast the dev->driver to the native type.

So with bus_type based driver ops driver authors can do:

struct auxiliary_device_driver auxdrv {
.probe = fn(struct auxiliary_device *, <any aux bus custom probe arguments>)
};

auxiliary_driver_register(&auxdrv); <-- the core code can hide bus details

Without bus_type the driver author would need to do:

struct auxiliary_device_driver auxdrv {
.drv = {
.probe = fn(struct device *), <-- no opportunity for bus
specific probe args
.bus = &auxilary_bus_type, <-- unnecessary export to device drivers
},
};

Quoted 1 line

driver_register(&auxdrv.drv)

Thanks Dan, I appreciate the explanation.

I guess the misunderstanding on my side was that in practice the drivers only declare a probe at the auxiliary level:

struct auxiliary_device_driver auxdrv {
.drv = {
.name = "my driver"
<<< .probe not set here.
}
.probe = fn(struct auxiliary_device *, int id),
}

It looks indeed cleaner with your suggestion. DaveE and I were talking about this moments ago and made the change, will be testing later today.

Again thanks for the write-up and have a nice week-end.

#57 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 176 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Friday, October 9, 2020 12:39 PM
To: Williams, Dan J <[email protected]>
Cc: Ertman, David M <[email protected]>; alsa-devel@alsa- project.org; [email protected]; Leon Romanovsky <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Saleem, Shiraz <[email protected]>; [email protected]; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+
+   ancildrv->driver.owner = owner;
+   ancildrv->driver.bus = &ancillary_bus_type;
+   ancildrv->driver.probe = ancillary_probe_driver;
+   ancildrv->driver.remove = ancillary_remove_driver;
+   ancildrv->driver.shutdown = ancillary_shutdown_driver;
+

I think that this part is wrong, probe/remove/shutdown functions

should

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

come from ancillary_bus_type.

From checking other usage cases, this is the model that is used for

probe, remove,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

and shutdown in drivers. Here is the example from Greybus.

int greybus_register_driver(struct greybus_driver *driver, struct

module *owner,

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

const char *mod_name)

{
          int retval;

          if (greybus_disabled())
                  return -ENODEV;

          driver->driver.bus = &greybus_bus_type;
          driver->driver.name = driver->name;
          driver->driver.probe = greybus_probe;
          driver->driver.remove = greybus_remove;
          driver->driver.owner = owner;
          driver->driver.mod_name = mod_name;
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

You are overwriting private device_driver callbacks that makes impossible to make container_of of

ancillary_driver

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

to chain operations.

I am sorry, you lost me here. you cannot perform container_of on the

callbacks

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

because they are pointers, but if you are referring to going from

device_driver

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to the auxiliary_driver, that is what happens in auxiliary_probe_driver

in the

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 8 lines

very beginning.

static int auxiliary_probe_driver(struct device *dev) 145 {
146 struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
147 struct auxiliary_device *auxdev = to_auxiliary_dev(dev);

Did I miss your meaning?

I think you're misunderstanding the cases when the bus_type.{probe,remove} is used vs the driver.{probe,remove} callbacks. The bus_type callbacks are to implement a pattern where the 'probe' and 'remove' method are typed to the bus device type. For example 'struct pci_dev *' instead of raw 'struct device *'. See this conversion of dax bus as an example of going from raw 'struct device *' typed probe/remove to dax-device typed probe/remove:

Quoted 1 line
Quoted 1 line
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-

next.git/commit/?id=75797273189d

Quoted 9 lines
Quoted 9 lines

Thanks Dan for the reference, very useful. This doesn't look like a a big change to implement, just wondering about the benefits and drawbacks, if any? I am a bit confused here.

First, was the initial pattern wrong as Leon asserted it? Such code exists in multiple examples in the kernel and there's nothing preventing the use of container_of that I can think of. Put differently, if this code was wrong then there are other existing buses that need to be

updated.

Quoted 15 lines
Quoted 15 lines

Second, what additional functionality does this move from driver to bus_type provide? The commit reference just states 'In preparation for introducing seed devices the dax-bus core needs to be able to intercept ->probe() and ->remove() operations", but that doesn't really help me figure out what 'intercept' means. Would you mind elaborating?

And last, the existing probe function does calls dev_pm_domain_attach():

static int ancillary_probe_driver(struct device *dev)

{
         struct ancillary_driver *ancildrv = to_ancillary_drv(dev->driver);
         struct ancillary_device *ancildev = to_ancillary_dev(dev);
         int ret;
Quoted 11 lines
Quoted 4 lines
         ret = dev_pm_domain_attach(dev, true);

So the need to access the raw device still exists. Is this still legit if the probe() is moved to the bus_type structure?

Sure, of course.

Quoted 4 lines

I have no objection to this change if it preserves the same functionality and possibly extends it, just wanted to better understand the reasons for the change and in which cases the bus probe() makes

more

Quoted 23 lines
Quoted 3 lines

sense than a driver probe().

Thanks for enlightening the rest of us!

tl;dr: The ops set by the device driver should never be overwritten by the bus, the bus can only wrap them in its own ops.

The reason to use the bus_type is because the bus type is the only agent that knows both how to convert a raw 'struct device *' to the bus's native type, and how to convert a raw 'struct device_driver *' to the bus's native driver type. The driver core does:

         if (dev->bus->probe) {
                 ret = dev->bus->probe(dev);
         } else if (drv->probe) {
                 ret = drv->probe(dev);
         }

...so that the bus has the first priority for probing a device / wrapping the native driver ops. The bus ->probe, in addition to optionally performing some bus specific pre-work, lets the bus upcast the device to bus-native type.

Quoted 7 lines

The bus also knows the types of drivers that will be registered to it, so the bus can upcast the dev->driver to the native type.

So with bus_type based driver ops driver authors can do:

struct auxiliary_device_driver auxdrv {
.probe = fn(struct auxiliary_device *, <any aux bus custom probe

arguments>)

Quoted 14 lines

};

auxiliary_driver_register(&auxdrv); <-- the core code can hide bus details

Without bus_type the driver author would need to do:

struct auxiliary_device_driver auxdrv {
.drv = {
.probe = fn(struct device *), <-- no opportunity for bus
specific probe args
.bus = &auxilary_bus_type, <-- unnecessary export to device drivers
},
};

Quoted 1 line

driver_register(&auxdrv.drv)

Thanks Dan, I appreciate the explanation.

I guess the misunderstanding on my side was that in practice the drivers only declare a probe at the auxiliary level:

struct auxiliary_device_driver auxdrv {
.drv = {
.name = "my driver"
<<< .probe not set here.
}
.probe = fn(struct auxiliary_device *, int id),
}

Quoted 5 lines

It looks indeed cleaner with your suggestion. DaveE and I were talking about this moments ago and made the change, will be testing later today.

Again thanks for the write-up and have a nice week-end.

Like Pierre said, I have already changed the probe, remove, and shutdown callbacks into the bus_type.

But it should be noted that you are not supposed to have these callbacks in both the auxdrv->drv->* and in the bus->*.

in drivers/base/driver.c line 158 it checks for this:

if ((drv->bus->probe && drv->probe) ||

             (drv->bus->remove && drv->remove) ||
             (drv->bus->shutdown && drv->shutdown))
                 pr_warn("Driver '%s' needs updating - please use "
                         "bus_type methods\n", drv->name);

So, changing to the bus_type for these is the right thing to do, but driver writers need to make sure that auxdrv->drv->[probe|remove|shutdown] are NULL.

-DaveE

#58 lore raw

Re: [PATCH v2 1/6] Add ancillary bus support

In reply to Dave Ertman
Quoted 20 lines · Dave Ertman

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

The bus supports probe/remove shutdown and suspend/resume callbacks. Each ancillary_device has a unique string based id; driver binds to an ancillary_device based on this id through the bus.

---

<...>

Quoted 6 lines
(quoted diff) +6 -0
+
+static const struct ancillary_device_id *ancillary_match_id(const struct ancillary_device_id *id,
+							    const struct ancillary_device *ancildev)
+{
+	while (id->name[0]) {
+		const char *p = strrchr(dev_name(&ancildev->dev), '.');

Review

Quoted 10 lines
(quoted diff) +10 -0
+		int match_size;
+
+		if (!p) {
+			id++;
+			continue;
+		}
+		match_size = p - dev_name(&ancildev->dev);
+
+		/* use dev_name(&ancildev->dev) prefix before last '.' char to match to */
+		if (!strncmp(dev_name(&ancildev->dev), id->name, match_size))

This check is wrong, it causes to wrong matching if strlen(id->name) > match_size In my case, the trigger was:

[    5.175848] ancillary:ancillary_match_id: dev mlx5_core.ib.0, id mlx5_core.ib_rep

From cf8f10af72f9e0d57c7ec077d59238cc12b0650f Mon Sep 17 00:00:00 2001
From: Leon Romanovsky <[email protected]>
Date: Thu, 8 Oct 2020 19:40:03 +0300
Subject: [PATCH] fixup! Fixes to ancillary bus

---
 drivers/bus/ancillary.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/bus/ancillary.c +3 -1
index 54858f744ef5..615ce40ef8e4 100644
@@ -31,8 +31,10 @@ static const struct ancillary_device_id *ancillary_match_id(const struct ancilla
 		match_size = p - dev_name(&ancildev->dev);
 
 		/* use dev_name(&ancildev->dev) prefix before last '.' char to match to */
-		if (!strncmp(dev_name(&ancildev->dev), id->name, match_size))
+		if (match_size == strlen(id->name) && !strncmp(dev_name(&ancildev->dev), id->name, match_size)) {
 			return id;
+		}
+
 		id++;
 	}
 	return NULL;

--
2.26.2

Quoted 5 lines
(quoted diff) +5 -0
+			return id;
+		id++;
+	}
+	return NULL;
+}
#59 lore raw

RE: [PATCH v2 1/6] Add ancillary bus support

Quoted 55 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Thursday, October 8, 2020 10:20 AM
To: Ertman, David M <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; pierre- [email protected]; [email protected]; [email protected]; Saleem, Shiraz <[email protected]>; Williams, Dan J <[email protected]>; Patil, Kiran <[email protected]>
Subject: Re: [PATCH v2 1/6] Add ancillary bus support

Quoted 20 lines · Dave Ertman

Add support for the Ancillary Bus, ancillary_device and ancillary_driver. It enables drivers to create an ancillary_device and bind an ancillary_driver to it.

The bus supports probe/remove shutdown and suspend/resume callbacks. Each ancillary_device has a unique string based id; driver binds to an ancillary_device based on this id through the bus.

---

<...>

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+static const struct ancillary_device_id *ancillary_match_id(const struct

ancillary_device_id *id,

Review

Quoted 1 line
(quoted diff) +1 -0
+							    const struct

ancillary_device *ancildev)

Review

Quoted 12 lines
(quoted diff) +12 -0
+{
+	while (id->name[0]) {
+		const char *p = strrchr(dev_name(&ancildev->dev), '.');
+		int match_size;
+
+		if (!p) {
+			id++;
+			continue;
+		}
+		match_size = p - dev_name(&ancildev->dev);
+
+		/* use dev_name(&ancildev->dev) prefix before last '.' char

to match to */

Quoted 8 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		if (!strncmp(dev_name(&ancildev->dev), id->name,

match_size))

This check is wrong, it causes to wrong matching if strlen(id->name) > match_size
In my case, the trigger was:

[    5.175848] ancillary:ancillary_match_id: dev mlx5_core.ib.0, id

mlx5_core.ib_rep

Nice catch , I will look into this.

-DaveE

Quoted 41 lines

From cf8f10af72f9e0d57c7ec077d59238cc12b0650f Mon Sep 17 00:00:00 2001
From: Leon Romanovsky <[email protected]>
Date: Thu, 8 Oct 2020 19:40:03 +0300
Subject: [PATCH] fixup! Fixes to ancillary bus

---
 drivers/bus/ancillary.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/bus/ancillary.c +0 -0
index 54858f744ef5..615ce40ef8e4 100644
@@ -31,8 +31,10 @@ static const struct ancillary_device_id
 *ancillary_match_id(const struct ancilla
 		match_size = p - dev_name(&ancildev->dev);
 
 		/* use dev_name(&ancildev->dev) prefix before last '.' char

to match to */

drivers/bus/ancillary.c +0 -1
-		if (!strncmp(dev_name(&ancildev->dev), id->name,

match_size))

drivers/bus/ancillary.c +1 -0
+		if (match_size == strlen(id->name) &&

!strncmp(dev_name(&ancildev->dev), id->name, match_size)) {

drivers/bus/ancillary.c +2 -1
 			return id;
+		}
+
 		id++;
 	}
 	return NULL;
--

2.26.2

Quoted 5 lines
(quoted diff) +5 -0
+			return id;
+		id++;
+	}
+	return NULL;
+}
#60 lore raw

PATCH v2 2/6 ASoC: SOF: Introduce descriptors for SOF client

In reply to Dave Ertman

From: Ranjani Sridharan <[email protected]>

A client in the SOF (Sound Open Firmware) context is a device that needs to communicate with the DSP via IPC messages. The SOF core is responsible for serializing the IPC messages to the DSP from the different clients. One example of an SOF client would be an IPC test client that floods the DSP with test IPC messages to validate if the serialization works as expected. Multi-client support will also add the ability to split the existing audio cards into multiple ones, so as to e.g. to deal with HDMI with a dedicated client instead of adding HDMI to all cards.

This patch introduces descriptors for SOF client driver and SOF client device along with APIs for registering and unregistering a SOF client driver, sending IPCs from a client device and accessing the SOF core debugfs root entry.

Along with this, add a couple of new members to struct snd_sof_dev that will be used for maintaining the list of clients.

---
 sound/soc/sof/Kconfig      |  19 ++++++
 sound/soc/sof/Makefile     |   3 +
 sound/soc/sof/core.c       |   2 +
 sound/soc/sof/sof-client.c | 119 +++++++++++++++++++++++++++++++++++++
 sound/soc/sof/sof-client.h |  69 +++++++++++++++++++++
 sound/soc/sof/sof-priv.h   |   9 +++
 6 files changed, 221 insertions(+)
 create mode 100644 sound/soc/sof/sof-client.c
 create mode 100644 sound/soc/sof/sof-client.h
sound/soc/sof/Kconfig +19 -0
index 4dda4b62509f..cea7efedafef 100644
@@ -50,6 +50,24 @@ config SND_SOC_SOF_DEBUG_PROBES
 	  Say Y if you want to enable probes.
 	  If unsure, select "N".
 
+config SND_SOC_SOF_CLIENT
+	tristate
+	select ANCILLARY_BUS
+	help
+	  This option is not user-selectable but automagically handled by
+	  'select' statements at a higher level
+
+config SND_SOC_SOF_CLIENT_SUPPORT
+	bool "SOF enable clients"
+	depends on SND_SOC_SOF
+	help
+	  This adds support for ancillary client devices to separate out the debug
+	  functionality for IPC tests, probes etc. into separate devices. This
+	  option would also allow adding client devices based on DSP FW
+	  capabilities and ACPI/OF device information.
+	  Say Y if you want to enable clients with SOF.
+	  If unsure select "N".
+
 config SND_SOC_SOF_DEVELOPER_SUPPORT
 	bool "SOF developer options support"
 	depends on EXPERT
@@ -186,6 +204,7 @@ endif ## SND_SOC_SOF_DEVELOPER_SUPPORT
 
 config SND_SOC_SOF
 	tristate
+	select SND_SOC_SOF_CLIENT if SND_SOC_SOF_CLIENT_SUPPORT
 	select SND_SOC_TOPOLOGY
 	select SND_SOC_SOF_NOCODEC if SND_SOC_SOF_NOCODEC_SUPPORT
 	help
sound/soc/sof/Makefile +3 -0
index 05718dfe6cd2..5e46f25a3851 100644
@@ -2,6 +2,7 @@
 
 snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
 		control.o trace.o utils.o sof-audio.o
+snd-sof-client-objs := sof-client.o
 snd-sof-$(CONFIG_SND_SOC_SOF_DEBUG_PROBES) += probe.o compress.o
 
 snd-sof-pci-objs := sof-pci-dev.o
@@ -18,6 +19,8 @@ obj-$(CONFIG_SND_SOC_SOF_ACPI) += snd-sof-acpi.o
 obj-$(CONFIG_SND_SOC_SOF_OF) += snd-sof-of.o
 obj-$(CONFIG_SND_SOC_SOF_PCI) += snd-sof-pci.o
 
+obj-$(CONFIG_SND_SOC_SOF_CLIENT) += snd-sof-client.o
+
 obj-$(CONFIG_SND_SOC_SOF_INTEL_TOPLEVEL) += intel/
 obj-$(CONFIG_SND_SOC_SOF_IMX_TOPLEVEL) += imx/
 obj-$(CONFIG_SND_SOC_SOF_XTENSA) += xtensa/
sound/soc/sof/core.c +2 -0
index adc7c37145d6..72a97219395f 100644
@@ -314,8 +314,10 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
 	INIT_LIST_HEAD(&sdev->widget_list);
 	INIT_LIST_HEAD(&sdev->dai_list);
 	INIT_LIST_HEAD(&sdev->route_list);
+	INIT_LIST_HEAD(&sdev->client_list);
 	spin_lock_init(&sdev->ipc_lock);
 	spin_lock_init(&sdev->hw_lock);
+	mutex_init(&sdev->client_mutex);
 
 	if (IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE))
 		INIT_WORK(&sdev->probe_work, sof_probe_work);
sound/soc/sof/sof-client.c new file +119 -0

119 lines not on this page · raw message

sound/soc/sof/sof-client.h new file +69 -0

69 lines not on this page · raw message

sound/soc/sof/sof-priv.h +9 -0
index 64f28e082049..8603924e56e3 100644
@@ -438,6 +438,15 @@ struct snd_sof_dev {
 
 	bool msi_enabled;
 
+	/*
+	 * Used to keep track of registered client devices so that they can be removed when the
+	 * parent SOF module is removed.
+	 */
+	struct list_head client_list;
+
+	/* mutex to protect client list */
+	struct mutex client_mutex;
+
 	void *private;			/* core does not touch this */
 };
 
Signature · 1 line
2.26.2
reviewer
#61 lore raw

Re: [PATCH v2 2/6] ASoC: SOF: Introduce descriptors for SOF client

Quoted 7 lines · Dave Ertman
sound/soc/sof/Kconfig +0 -0
index 4dda4b62509f..cea7efedafef 100644
@@ -50,6 +50,24 @@ config SND_SOC_SOF_DEBUG_PROBES
 	  Say Y if you want to enable probes.
 	  If unsure, select "N".

sound/soc/sof/Kconfig config SND_SOC_SOF_DEBUG_PROBES · line 61

Quoted 10 lines
sound/soc/sof/Kconfig +9 -0
 
+config SND_SOC_SOF_CLIENT
+	tristate
+	select ANCILLARY_BUS
+	help
+	  This option is not user-selectable but automagically handled by
+	  'select' statements at a higher level
+
+config SND_SOC_SOF_CLIENT_SUPPORT
+	bool "SOF enable clients"

Tell users what "SOF" means.

sound/soc/sof/Kconfig config SND_SOC_SOF_DEBUG_PROBES · line 66

Quoted 5 lines
sound/soc/sof/Kconfig +5 -0
+	depends on SND_SOC_SOF
+	help
+	  This adds support for ancillary client devices to separate out the debug
+	  functionality for IPC tests, probes etc. into separate devices. This
+	  option would also allow adding client devices based on DSP FW

spell out firmware

Quoted 4 lines
sound/soc/sof/Kconfig +4 -0
+	  capabilities and ACPI/OF device information.
+	  Say Y if you want to enable clients with SOF.
+	  If unsure select "N".
+
Signature · 1 line
~Randy
#62 lore raw

Re: [PATCH v2 2/6] ASoC: SOF: Introduce descriptors for SOF client

Quoted 12 lines

sound/soc/sof/Kconfig config SND_SOC_SOF_DEBUG_PROBES · line 61

Quoted 10 lines
sound/soc/sof/Kconfig +9 -0
+config SND_SOC_SOF_CLIENT
+	tristate
+	select ANCILLARY_BUS
+	help
+	  This option is not user-selectable but automagically handled by
+	  'select' statements at a higher level
+
+config SND_SOC_SOF_CLIENT_SUPPORT
+	bool "SOF enable clients"

Tell users what "SOF" means.

This option can only be reached if the user already selected the topic-level option. From there on the SOF acronym is used. Is this not enough?

config SND_SOC_SOF_TOPLEVEL
bool "Sound Open Firmware Support"
help
This adds support for Sound Open Firmware (SOF). SOF is a free and generic open source audio DSP firmware for multiple devices. Say Y if you have such a device that is supported by SOF.

Quoted 8 lines

sound/soc/sof/Kconfig config SND_SOC_SOF_DEBUG_PROBES · line 66

Quoted 6 lines
sound/soc/sof/Kconfig +5 -0
+	depends on SND_SOC_SOF
+	help
+	  This adds support for ancillary client devices to separate out the debug
+	  functionality for IPC tests, probes etc. into separate devices. This
+	  option would also allow adding client devices based on DSP FW

spell out firmware

agree on this one.

Quoted 7 lines
Quoted 5 lines
sound/soc/sof/Kconfig +4 -0
+	  capabilities and ACPI/OF device information.
+	  Say Y if you want to enable clients with SOF.
+	  If unsure select "N".
+
reviewer
#63 lore raw

Re: [PATCH v2 2/6] ASoC: SOF: Introduce descriptors for SOF client

Quoted 13 lines · Pierre-Louis Bossart
Quoted 12 lines

sound/soc/sof/Kconfig config SND_SOC_SOF_DEBUG_PROBES · line 61

Quoted 10 lines
sound/soc/sof/Kconfig +9 -0
+config SND_SOC_SOF_CLIENT
+    tristate
+    select ANCILLARY_BUS
+    help
+      This option is not user-selectable but automagically handled by
+      'select' statements at a higher level
+
+config SND_SOC_SOF_CLIENT_SUPPORT
+    bool "SOF enable clients"

Tell users what "SOF" means.

Quoted 1 line

This option can only be reached if the user already selected the topic-level option. From there on the SOF acronym is used. Is this not enough?

Yes, that's enough. I didn't see it. Sorry about that.

Quoted 14 lines

config SND_SOC_SOF_TOPLEVEL
    bool "Sound Open Firmware Support"
    help
      This adds support for Sound Open Firmware (SOF). SOF is a free and generic open source audio DSP firmware for multiple devices. Say Y if you have such a device that is supported by SOF.

Quoted 7 lines
Quoted 6 lines

+    depends on SND_SOC_SOF
+    help
+      This adds support for ancillary client devices to separate out the debug +      functionality for IPC tests, probes etc. into separate devices. This +      option would also allow adding client devices based on DSP FW

Quoted 11 lines
Quoted 1 line

spell out firmware

agree on this one.

Quoted 7 lines
Quoted 5 lines

+      capabilities and ACPI/OF device information. +      Say Y if you want to enable clients with SOF. +      If unsure select "N".
+

thanks.

Signature · 1 line
~Randy
reviewer
#64 lore raw

Re: [PATCH v2 2/6] ASoC: SOF: Introduce descriptors for SOF client

Quoted 14 lines · Randy Dunlap
Quoted 13 lines · Pierre-Louis Bossart
Quoted 12 lines

sound/soc/sof/Kconfig config SND_SOC_SOF_DEBUG_PROBES · line 61

Quoted 10 lines
sound/soc/sof/Kconfig +9 -0
+config SND_SOC_SOF_CLIENT
+    tristate
+    select ANCILLARY_BUS
+    help
+      This option is not user-selectable but automagically handled by
+      'select' statements at a higher level
+
+config SND_SOC_SOF_CLIENT_SUPPORT
+    bool "SOF enable clients"

Tell users what "SOF" means.

Quoted 3 lines
Quoted 1 line

This option can only be reached if the user already selected the topic-level option. From there on the SOF acronym is used. Is this not enough?

Yes, that's enough. I didn't see it. Sorry about that.

Huh. I still don't see that Kconfig option.
Which patch is it in?

I only saw patches 1,2,3 on LKML.

Quoted 28 lines
Quoted 14 lines

config SND_SOC_SOF_TOPLEVEL
    bool "Sound Open Firmware Support"
    help
      This adds support for Sound Open Firmware (SOF). SOF is a free and generic open source audio DSP firmware for multiple devices. Say Y if you have such a device that is supported by SOF.

Quoted 7 lines
Quoted 6 lines

+    depends on SND_SOC_SOF
+    help
+      This adds support for ancillary client devices to separate out the debug +      functionality for IPC tests, probes etc. into separate devices. This +      option would also allow adding client devices based on DSP FW

Quoted 11 lines
Quoted 1 line

spell out firmware

agree on this one.

Quoted 7 lines
Quoted 5 lines

+      capabilities and ACPI/OF device information. +      Say Y if you want to enable clients with SOF. +      If unsure select "N".
+

thanks.

Signature · 1 line
~Randy
#65 lore raw

Re: [PATCH v2 2/6] ASoC: SOF: Introduce descriptors for SOF client

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

sound/soc/sof/Kconfig config SND_SOC_SOF_DEBUG_PROBES · line 61

Quoted 11 lines
sound/soc/sof/Kconfig +9 -0
+config SND_SOC_SOF_CLIENT
+    tristate
+    select ANCILLARY_BUS
+    help
+      This option is not user-selectable but automagically handled by
+      'select' statements at a higher level
+
+config SND_SOC_SOF_CLIENT_SUPPORT
+    bool "SOF enable clients"

Tell users what "SOF" means.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

This option can only be reached if the user already selected the topic-level option. From there on the SOF acronym is used. Is this not enough?

Yes, that's enough. I didn't see it. Sorry about that.

Huh. I still don't see that Kconfig option.
Which patch is it in?

I only saw patches 1,2,3 on LKML.

The Sound Open Firmware (SOF) driver is upstream since 2019, see https://elixir.bootlin.com/linux/latest/source/sound/soc/sof/Kconfig

What was shared in these patches is just an evolution to make the driver more modular to handle of 'subfunctions' with the auxiliary bus.

we'd love to hear your feedback if you think the help text can be improved. Thanks!

reviewer
#66 lore raw

Re: [PATCH v2 2/6] ASoC: SOF: Introduce descriptors for SOF client

Quoted 20 lines · Pierre-Louis Bossart
Quoted 20 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

sound/soc/sof/Kconfig config SND_SOC_SOF_DEBUG_PROBES · line 61

Quoted 10 lines
sound/soc/sof/Kconfig +9 -0
+config SND_SOC_SOF_CLIENT
+    tristate
+    select ANCILLARY_BUS
+    help
+      This option is not user-selectable but automagically handled by
+      'select' statements at a higher level
+
+config SND_SOC_SOF_CLIENT_SUPPORT
+    bool "SOF enable clients"

Tell users what "SOF" means.

Quoted 3 lines
Quoted 1 line

This option can only be reached if the user already selected the topic-level option. From there on the SOF acronym is used. Is this not enough?

Yes, that's enough. I didn't see it. Sorry about that.

Huh. I still don't see that Kconfig option.
Which patch is it in?

Quoted 8 lines
Quoted 1 line

I only saw patches 1,2,3 on LKML.

The Sound Open Firmware (SOF) driver is upstream since 2019, see https://elixir.bootlin.com/linux/latest/source/sound/soc/sof/Kconfig

What was shared in these patches is just an evolution to make the driver more modular to handle of 'subfunctions' with the auxiliary bus.

we'd love to hear your feedback if you think the help text can be improved. Thanks!

OK, I looked at the SOF Kconfig files. They are mostly OK except for missing '.' at the end of lots of sentences and a few other typos.

Do you want patches?

Signature · 1 line
~Randy
#67 lore raw

Re: [PATCH v2 2/6] ASoC: SOF: Introduce descriptors for SOF client

Quoted 19 lines
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

+config SND_SOC_SOF_CLIENT_SUPPORT
+    bool "SOF enable clients"

Tell users what "SOF" means.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

This option can only be reached if the user already selected the topic-level option. From there on the SOF acronym is used. Is this not enough?

Yes, that's enough. I didn't see it. Sorry about that.

Huh. I still don't see that Kconfig option.
Which patch is it in?

I only saw patches 1,2,3 on LKML.

The Sound Open Firmware (SOF) driver is upstream since 2019, see https://elixir.bootlin.com/linux/latest/source/sound/soc/sof/Kconfig

What was shared in these patches is just an evolution to make the driver more modular to handle of 'subfunctions' with the auxiliary bus.

Quoted 7 lines
Quoted 2 lines

we'd love to hear your feedback if you think the help text can be improved. Thanks!

OK, I looked at the SOF Kconfig files. They are mostly OK except for missing '.' at the end of lots of sentences and a few other typos.

Do you want patches?

Sure! Thanks in advance.

#68 lore raw

PATCH v2 3/6 ASoC: SOF: Create client driver for IPC test

In reply to Dave Ertman

From: Ranjani Sridharan <[email protected]>

Create an SOF client driver for IPC flood test. This driver is used to set up the debugfs entries and the read/write ops for initiating the IPC flood test that would be used to measure the min/max/avg response times for sending IPCs to the DSP.

---
 sound/soc/sof/Kconfig               |  10 +
 sound/soc/sof/Makefile              |   4 +
 sound/soc/sof/sof-ipc-test-client.c | 332 ++++++++++++++++++++++++++++
 3 files changed, 346 insertions(+)
 create mode 100644 sound/soc/sof/sof-ipc-test-client.c
sound/soc/sof/Kconfig +10 -0
index cea7efedafef..55a2a20c3ec9 100644
@@ -190,6 +190,16 @@ config SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST
 	  Say Y if you want to enable IPC flood test.
 	  If unsure, select "N".
 
+config SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST_CLIENT
+	tristate "SOF enable IPC flood test client"
+	depends on SND_SOC_SOF_CLIENT
+	help
+	  This option enables a separate client device for IPC flood test
+	  which can be used to flood the DSP with test IPCs and gather stats
+	  about response times.
+	  Say Y if you want to enable IPC flood test.
+	  If unsure, select "N".
+
 config SND_SOC_SOF_DEBUG_RETAIN_DSP_CONTEXT
 	bool "SOF retain DSP context on any FW exceptions"
 	help
sound/soc/sof/Makefile +4 -0
index 5e46f25a3851..baa93fe2cc9a 100644
@@ -9,6 +9,8 @@ snd-sof-pci-objs := sof-pci-dev.o
 snd-sof-acpi-objs := sof-acpi-dev.o
 snd-sof-of-objs := sof-of-dev.o
 
+snd-sof-ipc-test-objs := sof-ipc-test-client.o
+
 snd-sof-nocodec-objs := nocodec.o
 
 obj-$(CONFIG_SND_SOC_SOF) += snd-sof.o
@@ -21,6 +23,8 @@ obj-$(CONFIG_SND_SOC_SOF_PCI) += snd-sof-pci.o
 
 obj-$(CONFIG_SND_SOC_SOF_CLIENT) += snd-sof-client.o
 
+obj-$(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST_CLIENT) += snd-sof-ipc-test.o
+
 obj-$(CONFIG_SND_SOC_SOF_INTEL_TOPLEVEL) += intel/
 obj-$(CONFIG_SND_SOC_SOF_IMX_TOPLEVEL) += imx/
 obj-$(CONFIG_SND_SOC_SOF_XTENSA) += xtensa/
sound/soc/sof/sof-ipc-test-client.c new file +332 -0

332 lines not on this page · raw message

Signature · 1 line
2.26.2
#69 lore raw

PATCH v2 4/6 ASoC: SOF: ops: Add ops for client registration

In reply to Dave Ertman

From: Ranjani Sridharan <[email protected]>

Add new ops for registering/unregistering clients based on DSP capabilities and/or DT information.

---
 sound/soc/sof/core.c     | 10 ++++++++++
 sound/soc/sof/ops.h      | 14 ++++++++++++++
 sound/soc/sof/sof-priv.h |  4 ++++
 3 files changed, 28 insertions(+)
sound/soc/sof/core.c +10 -0
index 72a97219395f..ddb9a12d5aac 100644
@@ -246,8 +246,17 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
 	if (plat_data->sof_probe_complete)
 		plat_data->sof_probe_complete(sdev->dev);
 
+	/* If registering certain clients fails, unregister the previously registered clients. */
+	ret = snd_sof_register_clients(sdev);
+	if (ret < 0) {
+		dev_err(sdev->dev, "error: failed to register clients %d\n", ret);
+		goto client_reg_err;
+	}
+
 	return 0;
 
+client_reg_err:
+	snd_sof_unregister_clients(sdev);
 fw_trace_err:
 	snd_sof_free_trace(sdev);
 fw_run_err:
@@ -356,6 +365,7 @@ int snd_sof_device_remove(struct device *dev)
 			dev_warn(dev, "error: %d failed to prepare DSP for device removal",
 				 ret);
 
+		snd_sof_unregister_clients(sdev);
 		snd_sof_fw_unload(sdev);
 		snd_sof_ipc_free(sdev);
 		snd_sof_free_debug(sdev);
sound/soc/sof/ops.h +14 -0
index b21632f5511a..00370f8bcd75 100644
@@ -470,6 +470,20 @@ snd_sof_set_mach_params(const struct snd_soc_acpi_mach *mach,
 		sof_ops(sdev)->set_mach_params(mach, dev);
 }
 
+static inline int snd_sof_register_clients(struct snd_sof_dev *sdev)
+{
+	if (sof_ops(sdev) && sof_ops(sdev)->register_clients)
+		return sof_ops(sdev)->register_clients(sdev);
+
+	return 0;
+}
+
+static inline void snd_sof_unregister_clients(struct snd_sof_dev *sdev)
+{
+	if (sof_ops(sdev) && sof_ops(sdev)->unregister_clients)
+		sof_ops(sdev)->unregister_clients(sdev);
+}
+
 static inline const struct snd_sof_dsp_ops
 *sof_get_ops(const struct sof_dev_desc *d,
 	     const struct sof_ops_table mach_ops[], int asize)
sound/soc/sof/sof-priv.h +4 -0
index 8603924e56e3..1c29199132c5 100644
@@ -249,6 +249,10 @@ struct snd_sof_dsp_ops {
 	void (*set_mach_params)(const struct snd_soc_acpi_mach *mach,
 				struct device *dev); /* optional */
 
+	/* client ops */
+	int (*register_clients)(struct snd_sof_dev *sdev); /* optional */
+	void (*unregister_clients)(struct snd_sof_dev *sdev); /* optional */
+
 	/* DAI ops */
 	struct snd_soc_dai_driver *drv;
 	int num_drv;
Signature · 1 line
2.26.2
#70 lore raw

PATCH v2 5/6 ASoC: SOF: Intel: Define ops for client registration

In reply to Dave Ertman

From: Ranjani Sridharan <[email protected]>

Define client ops for Intel platforms. For now, we only add 2 IPC test clients that will be used for run tandem IPC flood tests for.

For ACPI platforms, change the Kconfig to select SND_SOC_SOF_PROBE_WORK_QUEUE to allow the ancillary driver to probe when the client is registered.

---
 sound/soc/sof/intel/Kconfig        |  9 +++++
 sound/soc/sof/intel/Makefile       |  3 ++
 sound/soc/sof/intel/apl.c          | 18 ++++++++++
 sound/soc/sof/intel/bdw.c          | 18 ++++++++++
 sound/soc/sof/intel/byt.c          | 22 +++++++++++++
 sound/soc/sof/intel/cnl.c          | 18 ++++++++++
 sound/soc/sof/intel/intel-client.c | 53 ++++++++++++++++++++++++++++++
 sound/soc/sof/intel/intel-client.h | 26 +++++++++++++++
 8 files changed, 167 insertions(+)
 create mode 100644 sound/soc/sof/intel/intel-client.c
 create mode 100644 sound/soc/sof/intel/intel-client.h
sound/soc/sof/intel/Kconfig +9 -0
index 3aaf25e4f766..28aba42f4658 100644
@@ -13,6 +13,8 @@ config SND_SOC_SOF_INTEL_ACPI
 	def_tristate SND_SOC_SOF_ACPI
 	select SND_SOC_SOF_BAYTRAIL  if SND_SOC_SOF_BAYTRAIL_SUPPORT
 	select SND_SOC_SOF_BROADWELL if SND_SOC_SOF_BROADWELL_SUPPORT
+	select SND_SOC_SOF_PROBE_WORK_QUEUE if SND_SOC_SOF_CLIENT
+	select SND_SOC_SOF_INTEL_CLIENT if SND_SOC_SOF_CLIENT
 	help
 	  This option is not user-selectable but automagically handled by
 	  'select' statements at a higher level
@@ -29,6 +31,7 @@ config SND_SOC_SOF_INTEL_PCI
 	select SND_SOC_SOF_TIGERLAKE   if SND_SOC_SOF_TIGERLAKE_SUPPORT
 	select SND_SOC_SOF_ELKHARTLAKE if SND_SOC_SOF_ELKHARTLAKE_SUPPORT
 	select SND_SOC_SOF_JASPERLAKE  if SND_SOC_SOF_JASPERLAKE_SUPPORT
+	select SND_SOC_SOF_INTEL_CLIENT if SND_SOC_SOF_CLIENT
 	help
 	  This option is not user-selectable but automagically handled by
 	  'select' statements at a higher level
@@ -57,6 +60,12 @@ config SND_SOC_SOF_INTEL_COMMON
 	  This option is not user-selectable but automagically handled by
 	  'select' statements at a higher level
 
+config SND_SOC_SOF_INTEL_CLIENT
+	tristate
+	help
+	  This option is not user-selectable but automagically handled by
+	  'select' statements at a higher level
+
 if SND_SOC_SOF_INTEL_ACPI
 
 config SND_SOC_SOF_BAYTRAIL_SUPPORT
sound/soc/sof/intel/Makefile +3 -0
index f7e9358f1f06..50e40caaa787 100644
@@ -5,6 +5,8 @@ snd-sof-intel-bdw-objs := bdw.o
 
 snd-sof-intel-ipc-objs := intel-ipc.o
 
+snd-sof-intel-client-objs := intel-client.o
+
 snd-sof-intel-hda-common-objs := hda.o hda-loader.o hda-stream.o hda-trace.o \
 				 hda-dsp.o hda-ipc.o hda-ctrl.o hda-pcm.o \
 				 hda-dai.o hda-bus.o \
@@ -18,3 +20,4 @@ obj-$(CONFIG_SND_SOC_SOF_BROADWELL) += snd-sof-intel-bdw.o
 obj-$(CONFIG_SND_SOC_SOF_INTEL_HIFI_EP_IPC) += snd-sof-intel-ipc.o
 obj-$(CONFIG_SND_SOC_SOF_HDA_COMMON) += snd-sof-intel-hda-common.o
 obj-$(CONFIG_SND_SOC_SOF_HDA) += snd-sof-intel-hda.o
+obj-$(CONFIG_SND_SOC_SOF_INTEL_CLIENT) += snd-sof-intel-client.o
sound/soc/sof/intel/apl.c +18 -0
index 9e29d4fd393a..b31353b1a3ea 100644
@@ -15,9 +15,12 @@
  * Hardware interface for audio DSP on Apollolake and GeminiLake
  */
 
+#include <linux/list.h>
 #include "../sof-priv.h"
 #include "hda.h"
 #include "../sof-audio.h"
+#include "../sof-client.h"
+#include "intel-client.h"
 
 static const struct snd_sof_debugfs_map apl_dsp_debugfs[] = {
 	{"hda", HDA_DSP_HDA_BAR, 0, 0x4000, SOF_DEBUGFS_ACCESS_ALWAYS},
@@ -25,6 +28,16 @@ static const struct snd_sof_debugfs_map apl_dsp_debugfs[] = {
 	{"dsp", HDA_DSP_BAR,  0, 0x10000, SOF_DEBUGFS_ACCESS_ALWAYS},
 };
 
+static int apl_register_clients(struct snd_sof_dev *sdev)
+{
+	return intel_register_ipc_test_clients(sdev);
+}
+
+static void apl_unregister_clients(struct snd_sof_dev *sdev)
+{
+	intel_unregister_ipc_test_clients(sdev);
+}
+
 /* apollolake ops */
 const struct snd_sof_dsp_ops sof_apl_ops = {
 	/* probe and remove */
@@ -101,6 +114,10 @@ const struct snd_sof_dsp_ops sof_apl_ops = {
 	.trace_release = hda_dsp_trace_release,
 	.trace_trigger = hda_dsp_trace_trigger,
 
+	/* client ops */
+	.register_clients = apl_register_clients,
+	.unregister_clients = apl_unregister_clients,
+
 	/* DAI drivers */
 	.drv		= skl_dai,
 	.num_drv	= SOF_SKL_NUM_DAIS,
@@ -140,3 +157,4 @@ const struct sof_intel_dsp_desc apl_chip_info = {
 	.ssp_base_offset = APL_SSP_BASE_OFFSET,
 };
 EXPORT_SYMBOL_NS(apl_chip_info, SND_SOC_SOF_INTEL_HDA_COMMON);
+MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_CLIENT);
sound/soc/sof/intel/bdw.c +18 -0
index 99fd0bd7276e..b14026c5fa97 100644
@@ -12,12 +12,15 @@
  * Hardware interface for audio DSP on Broadwell
  */
 
+#include <linux/list.h>
 #include <linux/module.h>
 #include <sound/sof.h>
 #include <sound/sof/xtensa.h>
 #include "../ops.h"
 #include "shim.h"
 #include "../sof-audio.h"
+#include "../sof-client.h"
+#include "intel-client.h"
 
 /* BARs */
 #define BDW_DSP_BAR 0
@@ -563,6 +566,16 @@ static void bdw_set_mach_params(const struct snd_soc_acpi_mach *mach,
 	mach_params->platform = dev_name(dev);
 }
 
+static int bdw_register_clients(struct snd_sof_dev *sdev)
+{
+	return intel_register_ipc_test_clients(sdev);
+}
+
+static void bdw_unregister_clients(struct snd_sof_dev *sdev)
+{
+	intel_unregister_ipc_test_clients(sdev);
+}
+
 /* Broadwell DAIs */
 static struct snd_soc_dai_driver bdw_dai[] = {
 {
@@ -638,6 +651,10 @@ const struct snd_sof_dsp_ops sof_bdw_ops = {
 	/*Firmware loading */
 	.load_firmware	= snd_sof_load_firmware_memcpy,
 
+	/* client ops */
+	.register_clients = bdw_register_clients,
+	.unregister_clients = bdw_unregister_clients,
+
 	/* DAI drivers */
 	.drv = bdw_dai,
 	.num_drv = ARRAY_SIZE(bdw_dai),
@@ -662,3 +679,4 @@ EXPORT_SYMBOL_NS(bdw_chip_info, SND_SOC_SOF_BROADWELL);
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_HIFI_EP_IPC);
 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
+MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_CLIENT);
sound/soc/sof/intel/byt.c +22 -0
index 49f67f1b94e0..8951f756d078 100644
@@ -12,13 +12,16 @@
  * Hardware interface for audio DSP on Baytrail, Braswell and Cherrytrail.
  */
 
+#include <linux/list.h>
 #include <linux/module.h>
 #include <sound/sof.h>
 #include <sound/sof/xtensa.h>
 #include "../ops.h"
 #include "shim.h"
 #include "../sof-audio.h"
+#include "../sof-client.h"
 #include "../../intel/common/soc-intel-quirks.h"
+#include "intel-client.h"
 
 /* DSP memories */
 #define IRAM_OFFSET		0x0C0000
@@ -821,6 +824,16 @@ static int byt_acpi_probe(struct snd_sof_dev *sdev)
 	return ret;
 }
 
+static int byt_register_clients(struct snd_sof_dev *sdev)
+{
+	return intel_register_ipc_test_clients(sdev);
+}
+
+static void byt_unregister_clients(struct snd_sof_dev *sdev)
+{
+	intel_unregister_ipc_test_clients(sdev);
+}
+
 /* baytrail ops */
 const struct snd_sof_dsp_ops sof_byt_ops = {
 	/* device init */
@@ -879,6 +892,10 @@ const struct snd_sof_dsp_ops sof_byt_ops = {
 	.suspend = byt_suspend,
 	.resume = byt_resume,
 
+	/* client ops */
+	.register_clients = byt_register_clients,
+	.unregister_clients = byt_unregister_clients,
+
 	/* DAI drivers */
 	.drv = byt_dai,
 	.num_drv = 3, /* we have only 3 SSPs on byt*/
@@ -958,6 +975,10 @@ const struct snd_sof_dsp_ops sof_cht_ops = {
 	.suspend = byt_suspend,
 	.resume = byt_resume,
 
+	/* client ops */
+	.register_clients = byt_register_clients,
+	.unregister_clients = byt_unregister_clients,
+
 	/* DAI drivers */
 	.drv = byt_dai,
 	/* all 6 SSPs may be available for cherrytrail */
@@ -985,3 +1006,4 @@ EXPORT_SYMBOL_NS(cht_chip_info, SND_SOC_SOF_BAYTRAIL);
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_HIFI_EP_IPC);
 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
+MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_CLIENT);
sound/soc/sof/intel/cnl.c +18 -0
index 16db0f50d139..5d7c2a667798 100644
@@ -15,10 +15,13 @@
  * Hardware interface for audio DSP on Cannonlake.
  */
 
+#include <linux/list.h>
 #include "../ops.h"
 #include "hda.h"
 #include "hda-ipc.h"
 #include "../sof-audio.h"
+#include "../sof-client.h"
+#include "intel-client.h"
 
 static const struct snd_sof_debugfs_map cnl_dsp_debugfs[] = {
 	{"hda", HDA_DSP_HDA_BAR, 0, 0x4000, SOF_DEBUGFS_ACCESS_ALWAYS},
@@ -231,6 +234,16 @@ static void cnl_ipc_dump(struct snd_sof_dev *sdev)
 		hipcida, hipctdr, hipcctl);
 }
 
+static int cnl_register_clients(struct snd_sof_dev *sdev)
+{
+	return intel_register_ipc_test_clients(sdev);
+}
+
+static void cnl_unregister_clients(struct snd_sof_dev *sdev)
+{
+	intel_unregister_ipc_test_clients(sdev);
+}
+
 /* cannonlake ops */
 const struct snd_sof_dsp_ops sof_cnl_ops = {
 	/* probe and remove */
@@ -307,6 +320,10 @@ const struct snd_sof_dsp_ops sof_cnl_ops = {
 	.trace_release = hda_dsp_trace_release,
 	.trace_trigger = hda_dsp_trace_trigger,
 
+	/* client ops */
+	.register_clients = cnl_register_clients,
+	.unregister_clients = cnl_unregister_clients,
+
 	/* DAI drivers */
 	.drv		= skl_dai,
 	.num_drv	= SOF_SKL_NUM_DAIS,
@@ -417,3 +434,4 @@ const struct sof_intel_dsp_desc jsl_chip_info = {
 	.ssp_base_offset = CNL_SSP_BASE_OFFSET,
 };
 EXPORT_SYMBOL_NS(jsl_chip_info, SND_SOC_SOF_INTEL_HDA_COMMON);
+MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_CLIENT);
sound/soc/sof/intel/intel-client.c new file +53 -0

53 lines not on this page · raw message

sound/soc/sof/intel/intel-client.h new file +26 -0
new file mode 100644
index 000000000000..49b2c6c0dcc4
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
+/*
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * Copyright(c) 2020 Intel Corporation. All rights reserved.
+ *
+ * Author: Ranjani Sridharan <[email protected]>
+ */
+
+#ifndef __INTEL_CLIENT_H
+#define __INTEL_CLIENT_H
+
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST_CLIENT)
+int intel_register_ipc_test_clients(struct snd_sof_dev *sdev);
+void intel_unregister_ipc_test_clients(struct snd_sof_dev *sdev);
+#else
+static inline int intel_register_ipc_test_clients(struct snd_sof_dev *sdev)
+{
+	return 0;
+}
+
+static void intel_unregister_ipc_test_clients(struct snd_sof_dev *sdev) {}
+#endif
+
+#endif
Signature · 1 line
2.26.2
#71 lore raw

PATCH v2 6/6 ASoC: SOF: debug: Remove IPC flood test support in SOF core

In reply to Dave Ertman

From: Fred Oh <[email protected]>

Remove the IPC flood test support in the SOF core as it is now added in the IPC flood test client.

---
 sound/soc/sof/Kconfig    |   8 --
 sound/soc/sof/debug.c    | 230 ---------------------------------------
 sound/soc/sof/sof-priv.h |   6 +-
 3 files changed, 1 insertion(+), 243 deletions(-)
sound/soc/sof/Kconfig +0 -8
index 55a2a20c3ec9..4046e96eed92 100644
@@ -182,14 +182,6 @@ config SND_SOC_SOF_DEBUG_ENABLE_FIRMWARE_TRACE
 	  module parameter (similar to dynamic debug)
 	  If unsure, select "N".
 
-config SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST
-	bool "SOF enable IPC flood test"
-	help
-	  This option enables the IPC flood test which can be used to flood
-	  the DSP with test IPCs and gather stats about response times.
-	  Say Y if you want to enable IPC flood test.
-	  If unsure, select "N".
-
 config SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST_CLIENT
 	tristate "SOF enable IPC flood test client"
 	depends on SND_SOC_SOF_CLIENT
sound/soc/sof/debug.c +0 -230

264 lines not on this page · raw message

sound/soc/sof/sof-priv.h +1 -5
index 1c29199132c5..a20870900a76 100644
@@ -50,10 +50,6 @@ extern int sof_core_debug;
 #define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
 	SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT)
 
-#define ENABLE_DEBUGFS_CACHEBUF \
-	(IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE) || \
-	 IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST))
-
 /* DSP power state */
 enum sof_dsp_power_states {
 	SOF_DSP_PM_D0,
@@ -298,7 +294,7 @@ struct snd_sof_dfsentry {
 	 * or if it is accessible only when the DSP is in D0.
 	 */
 	enum sof_debugfs_access_type access_type;
-#if ENABLE_DEBUGFS_CACHEBUF
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE)
 	char *cache_buf; /* buffer to cache the contents of debugfs memory */
 #endif
 	struct snd_sof_dev *sdev;
Signature · 1 line
2.26.2