Skip to contentSkip to conversation

Introduce features and debugfs/sysfs entries for MHI

PATCH Superseded Bhaumik Bhatt 3 participants 17 messages Jul 23, 2020 – Jul 28, 2020

Subsystems (2)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#1 lore raw

PATCH v5 1/10 bus: mhi: core: Remove double occurrence for mhi_ctrl_ev_task() declaration

In reply to Bhaumik Bhatt

mhi_ctrl_ev_task() in the internal header file occurred twice. Remove one of the occurrences for clean-up.

---
 drivers/bus/mhi/core/internal.h | 1 -
 1 file changed, 1 deletion(-)
drivers/bus/mhi/core/internal.h +0 -1
index b1f640b..bcfa7b6 100644
@@ -592,7 +592,6 @@ void mhi_pm_st_worker(struct work_struct *work);
 void mhi_pm_sys_err_handler(struct mhi_controller *mhi_cntrl);
 void mhi_fw_load_worker(struct work_struct *work);
 int mhi_ready_state_transition(struct mhi_controller *mhi_cntrl);
-void mhi_ctrl_ev_task(unsigned long data);
 int mhi_pm_m0_transition(struct mhi_controller *mhi_cntrl);
 void mhi_pm_m1_transition(struct mhi_controller *mhi_cntrl);
 int mhi_pm_m3_transition(struct mhi_controller *mhi_cntrl);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#7 lore raw

PATCH v5 6/10 bus: mhi: core: Introduce helper function to check device state

In reply to Bhaumik Bhatt

Introduce a helper function to determine whether the device is in a powered ON state and resides in one of the active MHI states. This will allow for some use cases where access can be pre-determined.

---
 drivers/bus/mhi/core/internal.h | 5 +++++
 1 file changed, 5 insertions(+)
drivers/bus/mhi/core/internal.h +5 -0
index 1bbd6e9..5a81a42 100644
@@ -598,6 +598,11 @@ int mhi_pm_m3_transition(struct mhi_controller *mhi_cntrl);
 int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl);
 int mhi_send_cmd(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
 		 enum mhi_cmd_type cmd);
+static inline bool mhi_is_active(struct mhi_controller *mhi_cntrl)
+{
+	return (mhi_cntrl->dev_state >= MHI_STATE_M0 &&
+		mhi_cntrl->dev_state <= MHI_STATE_M3_FAST);
+}
 
 static inline void mhi_trigger_resume(struct mhi_controller *mhi_cntrl)
 {
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#3 lore raw

PATCH v5 3/10 bus: mhi: core: Use helper API to trigger a non-blocking host resume

In reply to Bhaumik Bhatt

Autonomous low power mode support requires the MHI host to resume from multiple places and post a wakeup source to exit system suspend. This needs to be done in a non-blocking manner. Introduce a helper API to trigger the host resume for data transfers and other non-blocking use cases while supporting implementation of autonomous low power modes.

---
 drivers/bus/mhi/core/internal.h |  7 +++++++
 drivers/bus/mhi/core/main.c     | 21 +++++++--------------
 drivers/bus/mhi/core/pm.c       | 13 ++++---------
 3 files changed, 18 insertions(+), 23 deletions(-)
drivers/bus/mhi/core/internal.h +7 -0
index bcfa7b6..1bbd6e9 100644
@@ -599,6 +599,13 @@ int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl);
 int mhi_send_cmd(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
 		 enum mhi_cmd_type cmd);
 
+static inline void mhi_trigger_resume(struct mhi_controller *mhi_cntrl)
+{
+	pm_wakeup_event(&mhi_cntrl->mhi_dev->dev, 0);
+	mhi_cntrl->runtime_get(mhi_cntrl);
+	mhi_cntrl->runtime_put(mhi_cntrl);
+}
+
 /* Register access methods */
 void mhi_db_brstmode(struct mhi_controller *mhi_cntrl, struct db_cfg *db_cfg,
 		     void __iomem *db_addr, dma_addr_t db_val);
drivers/bus/mhi/core/main.c +7 -14
index 1f622ce..79be18e 100644
@@ -909,8 +909,7 @@ void mhi_ctrl_ev_task(unsigned long data)
 		 * process it since we are probably in a suspended state,
 		 * so trigger a resume.
 		 */
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
+		mhi_trigger_resume(mhi_cntrl);
 
 		return;
 	}
@@ -971,10 +970,8 @@ int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir,
 	}
 
 	/* we're in M3 or transitioning to M3 */
-	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
-	}
+	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+		mhi_trigger_resume(mhi_cntrl);
 
 	/* Toggle wake to exit out of M2 */
 	mhi_cntrl->wake_toggle(mhi_cntrl);
@@ -1032,10 +1029,8 @@ int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir,
 	}
 
 	/* we're in M3 or transitioning to M3 */
-	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
-	}
+	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+		mhi_trigger_resume(mhi_cntrl);
 
 	/* Toggle wake to exit out of M2 */
 	mhi_cntrl->wake_toggle(mhi_cntrl);
@@ -1147,10 +1142,8 @@ int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir,
 	read_lock_irqsave(&mhi_cntrl->pm_lock, flags);
 
 	/* we're in M3 or transitioning to M3 */
-	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
-	}
+	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+		mhi_trigger_resume(mhi_cntrl);
 
 	/* Toggle wake to exit out of M2 */
 	mhi_cntrl->wake_toggle(mhi_cntrl);
drivers/bus/mhi/core/pm.c +4 -9
index 661d704..b227d41 100644
@@ -824,11 +824,8 @@ int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl)
 	/* Wake up the device */
 	read_lock_bh(&mhi_cntrl->pm_lock);
 	mhi_cntrl->wake_get(mhi_cntrl, true);
-	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-		pm_wakeup_event(&mhi_cntrl->mhi_dev->dev, 0);
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
-	}
+	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+		mhi_trigger_resume(mhi_cntrl);
 	read_unlock_bh(&mhi_cntrl->pm_lock);
 
 	ret = wait_event_timeout(mhi_cntrl->state_event,
@@ -1139,10 +1136,8 @@ void mhi_device_put(struct mhi_device *mhi_dev)
 
 	mhi_dev->dev_wake--;
 	read_lock_bh(&mhi_cntrl->pm_lock);
-	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
-	}
+	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+		mhi_trigger_resume(mhi_cntrl);
 
 	mhi_cntrl->wake_put(mhi_cntrl, false);
 	read_unlock_bh(&mhi_cntrl->pm_lock);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#6 lore raw

PATCH v5 5/10 bus: mhi: core: Use generic name field for an MHI device

In reply to Bhaumik Bhatt

An MHI device is not necessarily associated with only channels as we can have one associated with the controller itself. Hence, the chan_name field within the mhi_device structure should instead be replaced with a generic name to accurately reflect any type of MHI device.

---
 drivers/bus/mhi/core/init.c | 5 +++--
 drivers/bus/mhi/core/main.c | 6 +++---
 include/linux/mhi.h         | 8 ++++----
 3 files changed, 10 insertions(+), 9 deletions(-)
drivers/bus/mhi/core/init.c +3 -2
index e43a190..e2011ec 100644
@@ -904,6 +904,7 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl,
 	mhi_dev->dev_type = MHI_DEVICE_CONTROLLER;
 	mhi_dev->mhi_cntrl = mhi_cntrl;
 	dev_set_name(&mhi_dev->dev, "%s", dev_name(mhi_cntrl->cntrl_dev));
+	mhi_dev->name = dev_name(mhi_cntrl->cntrl_dev);
 
 	/* Init wakeup source */
 	device_init_wakeup(&mhi_dev->dev, true);
@@ -1249,7 +1250,7 @@ static int mhi_uevent(struct device *dev, struct kobj_uevent_env *env)
 	struct mhi_device *mhi_dev = to_mhi_device(dev);
 
 	return add_uevent_var(env, "MODALIAS=" MHI_DEVICE_MODALIAS_FMT,
-					mhi_dev->chan_name);
+					mhi_dev->name);
 }
 
 static int mhi_match(struct device *dev, struct device_driver *drv)
@@ -1266,7 +1267,7 @@ static int mhi_match(struct device *dev, struct device_driver *drv)
 		return 0;
 
 	for (id = mhi_drv->id_table; id->chan[0]; id++)
-		if (!strcmp(mhi_dev->chan_name, id->chan)) {
+		if (!strcmp(mhi_dev->name, id->chan)) {
 			mhi_dev->id = id;
 			return 1;
 		}
drivers/bus/mhi/core/main.c +3 -3
index 79be18e..2cff5dd 100644
@@ -249,7 +249,7 @@ int mhi_destroy_device(struct device *dev, void *data)
 		put_device(&mhi_dev->dl_chan->mhi_dev->dev);
 
 	dev_dbg(&mhi_cntrl->mhi_dev->dev, "destroy device for chan:%s\n",
-		 mhi_dev->chan_name);
+		 mhi_dev->name);
 
 	/* Notify the client and remove the device from MHI bus */
 	device_del(dev);
@@ -327,10 +327,10 @@ void mhi_create_devices(struct mhi_controller *mhi_cntrl)
 		}
 
 		/* Channel name is same for both UL and DL */
-		mhi_dev->chan_name = mhi_chan->name;
+		mhi_dev->name = mhi_chan->name;
 		dev_set_name(&mhi_dev->dev, "%s_%s",
 			     dev_name(mhi_cntrl->cntrl_dev),
-			     mhi_dev->chan_name);
+			     mhi_dev->name);
 
 		/* Init wakeup source if available */
 		if (mhi_dev->dl_chan && mhi_dev->dl_chan->wake_capable)
include/linux/mhi.h +4 -4
index b008914..7ed785e 100644
@@ -436,10 +436,10 @@ struct mhi_controller {
 };
 
 /**
- * struct mhi_device - Structure representing a MHI device which binds
- *                     to channels
+ * struct mhi_device - Structure representing an MHI device which binds
+ *                     to channels or is associated with controllers
  * @id: Pointer to MHI device ID struct
- * @chan_name: Name of the channel to which the device binds
+ * @name: Name of the associated MHI device
  * @mhi_cntrl: Controller the device belongs to
  * @ul_chan: UL channel for the device
  * @dl_chan: DL channel for the device
@@ -451,7 +451,7 @@ struct mhi_controller {
  */
 struct mhi_device {
 	const struct mhi_device_id *id;
-	const char *chan_name;
+	const char *name;
 	struct mhi_controller *mhi_cntrl;
 	struct mhi_chan *ul_chan;
 	struct mhi_chan *dl_chan;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#0 lore raw

v5 cover Introduce features and debugfs/sysfs entries for MHI

Save hardware information from BHI.
Allow reading and modifying some MHI variables for debug, test, and informational purposes using debugfs.
Read values for device specific hardware information to be used by OEMs in factory testing such as serial number and PK hash using sysfs.

This set of patches was tested on arm64 and x86.

v5:
-Removed the debug entry to trigger reset and will be addressed in a seperate patch
-Added patch bus: mhi: core: Use counters to track MHI device state transitions -Updated helper API to trigger a non-blocking host resume
-Minor nitpicks also fixed

v4:
-Removed bus: mhi: core: Introduce independent voting mechanism patch -Removed bus vote function from debugfs due to independent voting removal -Added helper resume APIs to aid consolidation of spread out code -Added a clean-up patch and a missing host resume in voting API

v3:
-Add patch to check for pending packets in suspend as a dependency for the independent voting mechanism introduction
-Include register dump entry for debugfs to dump MHI, BHI, and BHIe registers -Update commit message for the debugfs patch
-Updated Documentation/ABI with the required info for sysfs -Updated debugfs patch to include a new KConfig entry and dependencies -Updated reviewed-by for some patches

v2:
-Added a new debugfs.c file for specific debugfs entries and code -Updated commit text and addressed some comments for voting change -Made sure sysfs is only used for serial number and OEM PK hash usage

Bhaumik Bhatt (10):
bus: mhi: core: Remove double occurrence for mhi_ctrl_ev_task()
declaration
bus: mhi: core: Abort suspends due to outgoing pending packets
bus: mhi: core: Use helper API to trigger a non-blocking host resume
bus: mhi: core: Trigger host resume if suspended during
mhi_device_get()
bus: mhi: core: Use generic name field for an MHI device
bus: mhi: core: Introduce helper function to check device state
bus: mhi: core: Introduce debugfs entries for MHI
bus: mhi: core: Use counters to track MHI device state transitions
bus: mhi: core: Read and save device hardware information from BHI
bus: mhi: core: Introduce sysfs entries for MHI

 Documentation/ABI/stable/sysfs-bus-mhi |  25 ++
 MAINTAINERS                            |   1 +
 drivers/bus/mhi/Kconfig                |   8 +
 drivers/bus/mhi/core/Makefile          |   5 +-
 drivers/bus/mhi/core/boot.c            |  17 +-
 drivers/bus/mhi/core/debugfs.c         | 409 +++++++++++++++++++++++++++++++++
 drivers/bus/mhi/core/init.c            |  65 +++++-
 drivers/bus/mhi/core/internal.h        |  37 ++-
 drivers/bus/mhi/core/main.c            |  27 +--
 drivers/bus/mhi/core/pm.c              |  26 ++-
 include/linux/mhi.h                    |  18 +-
 11 files changed, 599 insertions(+), 39 deletions(-)
 create mode 100644 Documentation/ABI/stable/sysfs-bus-mhi
 create mode 100644 drivers/bus/mhi/core/debugfs.c
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#8 lore raw

PATCH v5 7/10 bus: mhi: core: Introduce debugfs entries for MHI

Introduce debugfs entries to show state, register, channel, device, and event rings information. Allow the host to dump registers, issue device wake, and change the MHI timeout to help in debug.

---
 drivers/bus/mhi/Kconfig         |   8 +
 drivers/bus/mhi/core/Makefile   |   5 +-
 drivers/bus/mhi/core/debugfs.c  | 409 ++++++++++++++++++++++++++++++++++++++++
 drivers/bus/mhi/core/init.c     |   7 +
 drivers/bus/mhi/core/internal.h |  24 +++
 include/linux/mhi.h             |   4 +
 6 files changed, 454 insertions(+), 3 deletions(-)
 create mode 100644 drivers/bus/mhi/core/debugfs.c
drivers/bus/mhi/Kconfig +8 -0
index a8bd9bd..6a217ff 100644
@@ -12,3 +12,11 @@ config MHI_BUS
 	 communication protocol used by the host processors to control
 	 and communicate with modem devices over a high speed peripheral
 	 bus or shared memory.
+
+config MHI_BUS_DEBUG
+	bool "Debugfs support for the MHI bus"
+	depends on MHI_BUS && DEBUG_FS
+	help
+	 Enable debugfs support for use with the MHI transport. Allows
+	 reading and/or modifying some values within the MHI controller
+	 for debug and test purposes.
drivers/bus/mhi/core/Makefile +2 -3
index 66e2700..460a548 100644
@@ -1,3 +1,2 @@
-obj-$(CONFIG_MHI_BUS) := mhi.o
-
-mhi-y := init.o main.o pm.o boot.o
+obj-$(CONFIG_MHI_BUS) := init.o main.o pm.o boot.o
+obj-$(CONFIG_MHI_BUS_DEBUG) += debugfs.o
drivers/bus/mhi/core/debugfs.c new file +409 -0

409 lines not on this page · raw message

drivers/bus/mhi/core/init.c +7 -0
index e2011ec..d2c0f6e 100644
@@ -4,6 +4,7 @@
  *
  */
 
+#include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/dma-direction.h>
 #include <linux/dma-mapping.h>
@@ -915,6 +916,8 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl,
 
 	mhi_cntrl->mhi_dev = mhi_dev;
 
+	mhi_create_debugfs(mhi_cntrl);
+
 	return 0;
 
 error_add_dev:
@@ -937,6 +940,8 @@ void mhi_unregister_controller(struct mhi_controller *mhi_cntrl)
 	struct mhi_chan *mhi_chan = mhi_cntrl->mhi_chan;
 	unsigned int i;
 
+	mhi_destroy_debugfs(mhi_cntrl);
+
 	kfree(mhi_cntrl->mhi_cmd);
 	kfree(mhi_cntrl->mhi_event);
 
@@ -1284,11 +1289,13 @@ struct bus_type mhi_bus_type = {
 
 static int __init mhi_init(void)
 {
+	mhi_debugfs_init();
 	return bus_register(&mhi_bus_type);
 }
 
 static void __exit mhi_exit(void)
 {
+	mhi_debugfs_exit();
 	bus_unregister(&mhi_bus_type);
 }
 
drivers/bus/mhi/core/internal.h +24 -0
index 5a81a42..7989269 100644
@@ -570,6 +570,30 @@ struct mhi_chan {
 /* Default MHI timeout */
 #define MHI_TIMEOUT_MS (1000)
 
+/* debugfs related functions */
+#ifdef CONFIG_MHI_BUS_DEBUG
+void mhi_create_debugfs(struct mhi_controller *mhi_cntrl);
+void mhi_destroy_debugfs(struct mhi_controller *mhi_cntrl);
+void mhi_debugfs_init(void);
+void mhi_debugfs_exit(void);
+#else
+static inline void mhi_create_debugfs(struct mhi_controller *mhi_cntrl)
+{
+}
+
+static inline void mhi_destroy_debugfs(struct mhi_controller *mhi_cntrl)
+{
+}
+
+static inline void mhi_debugfs_init(void)
+{
+}
+
+static inline void mhi_debugfs_exit(void)
+{
+}
+#endif
+
 struct mhi_device *mhi_alloc_device(struct mhi_controller *mhi_cntrl);
 
 int mhi_destroy_device(struct device *dev, void *data);
include/linux/mhi.h +4 -0
index 7ed785e..b1e8b4f 100644
@@ -288,6 +288,7 @@ struct mhi_controller_config {
  * @cntrl_dev: Pointer to the struct device of physical bus acting as the MHI
  *            controller (required)
  * @mhi_dev: MHI device instance for the controller
+ * @debugfs_dentry: MHI controller debugfs directory
  * @regs: Base address of MHI MMIO register space (required)
  * @bhi: Points to base of MHI BHI register space
  * @bhie: Points to base of MHI BHIe register space
@@ -326,6 +327,7 @@ struct mhi_controller_config {
  * @dev_state: MHI device state
  * @dev_wake: Device wakeup count
  * @pending_pkts: Pending packets for the controller
+ * @M0, M2, M3, M3_fast: Counters to track number of device MHI state changes
  * @transition_list: List of MHI state transitions
  * @transition_lock: Lock for protecting MHI state transition list
  * @wlock: Lock for protecting device wakeup
@@ -364,6 +366,7 @@ struct mhi_controller_config {
 struct mhi_controller {
 	struct device *cntrl_dev;
 	struct mhi_device *mhi_dev;
+	struct dentry *debugfs_dentry;
 	void __iomem *regs;
 	void __iomem *bhi;
 	void __iomem *bhie;
@@ -405,6 +408,7 @@ struct mhi_controller {
 	enum mhi_state dev_state;
 	atomic_t dev_wake;
 	atomic_t pending_pkts;
+	u32 M0, M2, M3, M3_fast;
 	struct list_head transition_list;
 	spinlock_t transition_lock;
 	spinlock_t wlock;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#13 lore raw

PATCH v5 9/10 bus: mhi: core: Read and save device hardware information from BHI

In reply to Bhaumik Bhatt

Device hardware specific information such as serial number and the OEM PK hash can be read using BHI and saved on host to identify the endpoint.

---
 drivers/bus/mhi/core/boot.c | 17 ++++++++++++++++-
 include/linux/mhi.h         |  6 ++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
drivers/bus/mhi/core/boot.c +16 -1
index 0b38014..24422f5 100644
@@ -392,13 +392,28 @@ void mhi_fw_load_handler(struct mhi_controller *mhi_cntrl)
 	void *buf;
 	dma_addr_t dma_addr;
 	size_t size;
-	int ret;
+	int i, ret;
 
 	if (MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) {
 		dev_err(dev, "Device MHI is not in valid state\n");
 		return;
 	}
 
+	/* save hardware info from BHI */
+	ret = mhi_read_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_SERIALNU,
+			   &mhi_cntrl->serial_number);
+	if (ret)
+		dev_err(dev, "Could not capture serial number via BHI\n");
+
+	for (i = 0; i < ARRAY_SIZE(mhi_cntrl->oem_pk_hash); i++) {
+		ret = mhi_read_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_OEMPKHASH(i),
+				   &mhi_cntrl->oem_pk_hash[i]);
+		if (ret) {
+			dev_err(dev, "Could not capture OEM PK HASH via BHI\n");
+			break;
+		}
+	}
+
 	/* If device is in pass through, do reset to ready state transition */
 	if (mhi_cntrl->ee == MHI_EE_PTHRU)
 		goto fw_load_ee_pthru;
include/linux/mhi.h +6 -0
index b1e8b4f..dad6246 100644
@@ -16,6 +16,8 @@
 #include <linux/wait.h>
 #include <linux/workqueue.h>
 
+#define MHI_MAX_OEM_PK_HASH_SEGMENTS 16
+
 struct mhi_chan;
 struct mhi_event;
 struct mhi_ctxt;
@@ -315,6 +317,8 @@ struct mhi_controller_config {
  * @device_number: MHI controller device number
  * @major_version: MHI controller major revision number
  * @minor_version: MHI controller minor revision number
+ * @serial_number: MHI controller serial number obtained from BHI
+ * @oem_pk_hash: MHI controller OEM PK Hash obtained from BHI
  * @mhi_event: MHI event ring configurations table
  * @mhi_cmd: MHI command ring configurations table
  * @mhi_ctxt: MHI device context, shared memory between host and device
@@ -394,6 +398,8 @@ struct mhi_controller {
 	u32 device_number;
 	u32 major_version;
 	u32 minor_version;
+	u32 serial_number;
+	u32 oem_pk_hash[MHI_MAX_OEM_PK_HASH_SEGMENTS];
 
 	struct mhi_event *mhi_event;
 	struct mhi_cmd *mhi_cmd;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#5 lore raw

PATCH v5 4/10 bus: mhi: core: Trigger host resume if suspended during mhi_device_get()

In reply to Bhaumik Bhatt

It is possible that the host may be suspending or suspended and may not allow an outgoing device wake assert immediately if a client has requested for it. Ensure that the host wakes up and allows for it so the client does not have to wait for an external trigger or an outgoing packet to be queued for the host resume to occur.

---
 drivers/bus/mhi/core/pm.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/bus/mhi/core/pm.c +3 -0
index b227d41..27bb471 100644
@@ -1112,6 +1112,9 @@ void mhi_device_get(struct mhi_device *mhi_dev)
 
 	mhi_dev->dev_wake++;
 	read_lock_bh(&mhi_cntrl->pm_lock);
+	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+		mhi_trigger_resume(mhi_cntrl);
+
 	mhi_cntrl->wake_get(mhi_cntrl, true);
 	read_unlock_bh(&mhi_cntrl->pm_lock);
 }
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw

PATCH v5 2/10 bus: mhi: core: Abort suspends due to outgoing pending packets

In reply to Bhaumik Bhatt

Add the missing check to abort suspends if a client driver has pending outgoing packets to send to the device. This allows better utilization of the MHI bus wherein clients on the host are not left waiting for longer suspend or resume cycles to finish for data transfers.

---
 drivers/bus/mhi/core/pm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/bus/mhi/core/pm.c +4 -2
index 7960980..661d704 100644
@@ -686,7 +686,8 @@ int mhi_pm_suspend(struct mhi_controller *mhi_cntrl)
 		return -EIO;
 
 	/* Return busy if there are any pending resources */
-	if (atomic_read(&mhi_cntrl->dev_wake))
+	if (atomic_read(&mhi_cntrl->dev_wake) ||
+	    atomic_read(&mhi_cntrl->pending_pkts))
 		return -EBUSY;
 
 	/* Take MHI out of M2 state */
@@ -712,7 +713,8 @@ int mhi_pm_suspend(struct mhi_controller *mhi_cntrl)
 
 	write_lock_irq(&mhi_cntrl->pm_lock);
 
-	if (atomic_read(&mhi_cntrl->dev_wake)) {
+	if (atomic_read(&mhi_cntrl->dev_wake) ||
+	    atomic_read(&mhi_cntrl->pending_pkts)) {
 		write_unlock_irq(&mhi_cntrl->pm_lock);
 		return -EBUSY;
 	}
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#14 lore raw

PATCH v5 10/10 bus: mhi: core: Introduce sysfs entries for MHI

In reply to Bhaumik Bhatt

Introduce sysfs entries to enable userspace clients the ability to read the serial number and the OEM PK Hash values obtained from BHI. OEMs need to read these device-specific hardware information values through userspace for factory testing purposes and cannot be exposed via degbufs as it may remain disabled for performance reasons. Also, update the documentation for ABI to include these entries.

---
 Documentation/ABI/stable/sysfs-bus-mhi | 25 ++++++++++++++++
 MAINTAINERS                            |  1 +
 drivers/bus/mhi/core/init.c            | 53 ++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-bus-mhi
Documentation/ABI/stable/sysfs-bus-mhi new file +25 -0
new file mode 100644
index 0000000..a4e4bd2
@@ -0,0 +1,25 @@
+What:		/sys/bus/mhi/devices/.../serialnumber
+Date:		July 2020
+KernelVersion:  5.8
+Contact:	Bhaumik Bhatt <[email protected]>
+Description:
+		The file holds the serial number of the client device obtained
+		using a BHI (Boot Host Interface) register read after at least
+		one attempt to power up the device has been done. If read
+		without having the device power on at least once, the file will
+		read all 0's.
+Users:		Any userspace application or clients interested in the device
+		hardware information.
+
+What:		/sys/bus/mhi/devices/.../oem_pk_hash
+Date:		July 2020
+KernelVersion:  5.8
+Contact:	Bhaumik Bhatt <[email protected]>
+Description:
+		The file holds the OEM PK Hash value of the endpoint device
+		obtained using a BHI (Boot Host Interface) register read after
+		at least one attempt to power up the device has been done. If
+		read without having the device power on at least once, the file
+		will read all 0's.
+Users:		Any userspace application or clients interested in the device
+		hardware information.
MAINTAINERS +1 -0
index e64e5db..5e49316 100644
@@ -11018,6 +11018,7 @@ M:	Hemant Kumar <[email protected]>
 L:	[email protected]
 S:	Maintained
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/mani/mhi.git
+F:	Documentation/ABI/stable/sysfs-bus-mhi
 F:	Documentation/mhi/
 F:	drivers/bus/mhi/
 F:	include/linux/mhi.h
drivers/bus/mhi/core/init.c +53 -0

71 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#11 lore raw

PATCH v5 8/10 bus: mhi: core: Use counters to track MHI device state transitions

In reply to Bhaumik Bhatt

Use counters to track MHI device state transitions such as those to M0, M2, or M3 states. This helps in better debug by allowing the user to see the number of transitions to a certain state when queried using the states debugfs entry.

---
 drivers/bus/mhi/core/pm.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/bus/mhi/core/pm.c +4 -0
index 27bb471..ce4d969 100644
@@ -256,6 +256,7 @@ int mhi_pm_m0_transition(struct mhi_controller *mhi_cntrl)
 		dev_err(dev, "Unable to transition to M0 state\n");
 		return -EIO;
 	}
+	mhi_cntrl->M0++;
 
 	/* Wake up the device */
 	read_lock_bh(&mhi_cntrl->pm_lock);
@@ -326,6 +327,8 @@ void mhi_pm_m1_transition(struct mhi_controller *mhi_cntrl)
 		mhi_cntrl->dev_state = MHI_STATE_M2;
 
 		write_unlock_irq(&mhi_cntrl->pm_lock);
+
+		mhi_cntrl->M2++;
 		wake_up_all(&mhi_cntrl->state_event);
 
 		/* If there are any pending resources, exit M2 immediately */
@@ -362,6 +365,7 @@ int mhi_pm_m3_transition(struct mhi_controller *mhi_cntrl)
 		return -EIO;
 	}
 
+	mhi_cntrl->M3++;
 	wake_up_all(&mhi_cntrl->state_event);
 
 	return 0;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#9 lore raw

Re: [PATCH v5 07/10] bus: mhi: core: Introduce debugfs entries for MHI

In reply to Bhaumik Bhatt
Thank you for the patch! Perhaps something to improve:

Hi Bhaumik,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.8-rc6 next-20200723]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Bhaumik-Bhatt/Introduce-features-and-debugfs-sysfs-entries-for-MHI/20200724-063954
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git d15be546031cf65a0fc34879beca02fd90fe7ac7
config: csky-allyesconfig (attached as .config)
compiler: csky-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=csky

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

drivers/bus/mhi/core/debugfs.c: In function 'mhi_debugfs_events_show':

>> drivers/bus/mhi/core/debugfs.c:73:51: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
      73 |   seq_printf(m, " local rp: 0x%llx db: 0x%llx\n", (u64)ring->rp,
         |                                                   ^
>> drivers/bus/mhi/core/debugfs.c:73:45: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 4 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
      73 |   seq_printf(m, " local rp: 0x%llx db: 0x%llx\n", (u64)ring->rp,
         |                                          ~~~^
         |                                             |
         |                                             long long unsigned int
         |                                          %x
      74 |       mhi_event->db_cfg.db_val);
         |       ~~~~~~~~~~~~~~~~~~~~~~~~               
         |                        |
         |                        dma_addr_t {aka unsigned int}
   drivers/bus/mhi/core/debugfs.c: In function 'mhi_debugfs_channels_show':
   drivers/bus/mhi/core/debugfs.c:121:7: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     121 |       (u64)ring->rp, (u64)ring->wp,
         |       ^
   drivers/bus/mhi/core/debugfs.c:121:22: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     121 |       (u64)ring->rp, (u64)ring->wp,
         |                      ^
   drivers/bus/mhi/core/debugfs.c:120:62: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 5 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
     120 |   seq_printf(m, " local rp: 0x%llx local wp: 0x%llx db: 0x%llx\n",
         |                                                           ~~~^
         |                                                              |
         |                                                              long long unsigned int
         |                                                           %x
     121 |       (u64)ring->rp, (u64)ring->wp,
     122 |       mhi_chan->db_cfg.db_val);
         |       ~~~~~~~~~~~~~~~~~~~~~~~                                 
         |                       |
         |                       dma_addr_t {aka unsigned int}

vim +73 drivers/bus/mhi/core/debugfs.c

    36	
    37	static int mhi_debugfs_events_show(struct seq_file *m, void *d)
    38	{
    39		struct mhi_controller *mhi_cntrl = m->private;
    40		struct mhi_event *mhi_event;
    41		struct mhi_event_ctxt *er_ctxt;
    42		int i;
    43	
    44		if (!mhi_is_active(mhi_cntrl)) {
    45			seq_puts(m, "Device not ready\n");
    46			return -ENODEV;
    47		}
    48	
    49		er_ctxt = mhi_cntrl->mhi_ctxt->er_ctxt;
    50		mhi_event = mhi_cntrl->mhi_event;
    51		for (i = 0; i < mhi_cntrl->total_ev_rings;
    52							i++, er_ctxt++, mhi_event++) {
    53			struct mhi_ring *ring = &mhi_event->ring;
    54	
    55			if (mhi_event->offload_ev) {
    56				seq_printf(m, "Index: %d is an offload event ring\n",
    57					   i);
    58				continue;
    59			}
    60	
    61			seq_printf(m, "Index: %d intmod count: %lu time: %lu",
    62				   i, (er_ctxt->intmod & EV_CTX_INTMODC_MASK) >>
    63				   EV_CTX_INTMODC_SHIFT,
    64				   (er_ctxt->intmod & EV_CTX_INTMODT_MASK) >>
    65				   EV_CTX_INTMODT_SHIFT);
    66	
    67			seq_printf(m, " base: 0x%0llx len: 0x%llx", er_ctxt->rbase,
    68				   er_ctxt->rlen);
    69	
    70			seq_printf(m, " rp: 0x%llx wp: 0x%llx\n", er_ctxt->rp,
    71				   er_ctxt->wp);
    72	
  > 73			seq_printf(m, " local rp: 0x%llx db: 0x%llx\n", (u64)ring->rp,
    74				   mhi_event->db_cfg.db_val);
    75		}
    76	
    77		return 0;
    78	}
    79	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#12 lore raw

Re: [PATCH v5 08/10] bus: mhi: core: Use counters to track MHI device state transitions

In reply to Bhaumik Bhatt
Quoted 6 lines · Bhaumik Bhatt

Use counters to track MHI device state transitions such as those to M0, M2, or M3 states. This helps in better debug by allowing the user to see the number of transitions to a certain state when queried using the states debugfs entry.

This patch should come before the debugfs patch. Also the header addition should be here.

Thanks,
Mani

Quoted 37 lines
---
 drivers/bus/mhi/core/pm.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/bus/mhi/core/pm.c +4 -0
index 27bb471..ce4d969 100644
@@ -256,6 +256,7 @@ int mhi_pm_m0_transition(struct mhi_controller *mhi_cntrl)
 		dev_err(dev, "Unable to transition to M0 state\n");
 		return -EIO;
 	}
+	mhi_cntrl->M0++;
 
 	/* Wake up the device */
 	read_lock_bh(&mhi_cntrl->pm_lock);
@@ -326,6 +327,8 @@ void mhi_pm_m1_transition(struct mhi_controller *mhi_cntrl)
 		mhi_cntrl->dev_state = MHI_STATE_M2;
 
 		write_unlock_irq(&mhi_cntrl->pm_lock);
+
+		mhi_cntrl->M2++;
 		wake_up_all(&mhi_cntrl->state_event);
 
 		/* If there are any pending resources, exit M2 immediately */
@@ -362,6 +365,7 @@ int mhi_pm_m3_transition(struct mhi_controller *mhi_cntrl)
 		return -EIO;
 	}
 
+	mhi_cntrl->M3++;
 	wake_up_all(&mhi_cntrl->state_event);
 
 	return 0;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#15 lore raw

Re: [PATCH v5 10/10] bus: mhi: core: Introduce sysfs entries for MHI

In reply to Bhaumik Bhatt
Quoted 23 lines · Bhaumik Bhatt

Introduce sysfs entries to enable userspace clients the ability to read the serial number and the OEM PK Hash values obtained from BHI. OEMs need to read these device-specific hardware information values through userspace for factory testing purposes and cannot be exposed via degbufs as it may remain disabled for performance reasons. Also, update the documentation for ABI to include these entries.

---
 Documentation/ABI/stable/sysfs-bus-mhi | 25 ++++++++++++++++
 MAINTAINERS                            |  1 +
 drivers/bus/mhi/core/init.c            | 53 ++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-bus-mhi
Documentation/ABI/stable/sysfs-bus-mhi new file +2 -0
new file mode 100644
index 0000000..a4e4bd2
@@ -0,0 +1,25 @@
+What:		/sys/bus/mhi/devices/.../serialnumber
+Date:		July 2020

Documentation/ABI/stable/sysfs-bus-mhi line 12

Quoted 10 lines
Documentation/ABI/stable/sysfs-bus-mhi new file +10 -0
+KernelVersion:  5.8
+Contact:	Bhaumik Bhatt <[email protected]>
+Description:
+		The file holds the serial number of the client device obtained
+		using a BHI (Boot Host Interface) register read after at least
+		one attempt to power up the device has been done. If read
+		without having the device power on at least once, the file will
+		read all 0's.
+Users:		Any userspace application or clients interested in the device
+		hardware information.

Please align all the fields onto a single starting point. Have a look at other ABI documentation like, Documentation/ABI/stable/sysfs-bus-vmbus.

Quoted 30 lines
Documentation/ABI/stable/sysfs-bus-mhi new file +13 -0
+
+What:		/sys/bus/mhi/devices/.../oem_pk_hash
+Date:		July 2020
+KernelVersion:  5.8
+Contact:	Bhaumik Bhatt <[email protected]>
+Description:
+		The file holds the OEM PK Hash value of the endpoint device
+		obtained using a BHI (Boot Host Interface) register read after
+		at least one attempt to power up the device has been done. If
+		read without having the device power on at least once, the file
+		will read all 0's.
+Users:		Any userspace application or clients interested in the device
+		hardware information.
MAINTAINERS +1 -0
index e64e5db..5e49316 100644
@@ -11018,6 +11018,7 @@ M:	Hemant Kumar <[email protected]>
 L:	[email protected]
 S:	Maintained
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/mani/mhi.git
+F:	Documentation/ABI/stable/sysfs-bus-mhi
 F:	Documentation/mhi/
 F:	drivers/bus/mhi/
 F:	include/linux/mhi.h
drivers/bus/mhi/core/init.c +0 -0
index d2c0f6e..a7b0d76 100644

drivers/bus/mhi/core/init.c const char *to_mhi_pm_state_str(enum mhi_pm_state state) · line 81

Quoted 6 lines
drivers/bus/mhi/core/init.c +3 -0
@@ -76,6 +76,56 @@ const char *to_mhi_pm_state_str(enum mhi_pm_state state)
 	return mhi_pm_state_str[index];
 }
 
+static ssize_t serial_number_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)

We haven't followed this before but it is good to align the function parameters with respect to '('.

drivers/bus/mhi/core/init.c const char *to_mhi_pm_state_str(enum mhi_pm_state state) · line 87

Quoted 6 lines
drivers/bus/mhi/core/init.c +6 -0
+{
+	struct mhi_device *mhi_dev = to_mhi_device(dev);
+	struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
+
+	return snprintf(buf, PAGE_SIZE, "Serial Number: %u\n",
+			mhi_cntrl->serial_number);

We need to think about what happens if the mhi_cntrl structure is not zero initialized by the controller driver. All throughout the stack we assume that the mhi_cntrl struct is zero initialized but things can go awry if it was not the case!

There was one API in the downstream (mhi_alloc_controller()) for this purpose but I removed it since we ended up with just a kzalloc(). Does it make sense to introduce it now?

Thanks,
Mani

Quoted 65 lines
drivers/bus/mhi/core/init.c +44 -0
+}
+static DEVICE_ATTR_RO(serial_number);
+
+static ssize_t oem_pk_hash_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct mhi_device *mhi_dev = to_mhi_device(dev);
+	struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
+	int i, cnt = 0;
+
+	for (i = 0; i < ARRAY_SIZE(mhi_cntrl->oem_pk_hash); i++)
+		cnt += snprintf(buf + cnt, PAGE_SIZE - cnt,
+				"OEMPKHASH[%d]: 0x%x\n", i,
+				mhi_cntrl->oem_pk_hash[i]);
+
+	return cnt;
+}
+static DEVICE_ATTR_RO(oem_pk_hash);
+
+static struct attribute *mhi_sysfs_attrs[] = {
+	&dev_attr_serial_number.attr,
+	&dev_attr_oem_pk_hash.attr,
+	NULL,
+};
+
+static const struct attribute_group mhi_sysfs_group = {
+	.attrs = mhi_sysfs_attrs,
+};
+
+static int mhi_create_sysfs(struct mhi_controller *mhi_cntrl)
+{
+	return sysfs_create_group(&mhi_cntrl->mhi_dev->dev.kobj,
+				  &mhi_sysfs_group);
+}
+
+static void mhi_destroy_sysfs(struct mhi_controller *mhi_cntrl)
+{
+	sysfs_remove_group(&mhi_cntrl->mhi_dev->dev.kobj, &mhi_sysfs_group);
+}
+
 /* MHI protocol requires the transfer ring to be aligned with ring length */
 static int mhi_alloc_aligned_ring(struct mhi_controller *mhi_cntrl,
 				  struct mhi_ring *ring,
@@ -917,6 +967,8 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl,
 	mhi_cntrl->mhi_dev = mhi_dev;
 
 	mhi_create_debugfs(mhi_cntrl);
+	if (mhi_create_sysfs(mhi_cntrl))
+		dev_err(mhi_cntrl->cntrl_dev, "Failed to create sysfs entries\n");
 
 	return 0;
 
@@ -940,6 +992,7 @@ void mhi_unregister_controller(struct mhi_controller *mhi_cntrl)
 	struct mhi_chan *mhi_chan = mhi_cntrl->mhi_chan;
 	unsigned int i;
 
+	mhi_destroy_sysfs(mhi_cntrl);
 	mhi_destroy_debugfs(mhi_cntrl);
 
 	kfree(mhi_cntrl->mhi_cmd);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
Reviewed-by on v5 3/10
#4 lore raw

Re: [PATCH v5 03/10] bus: mhi: core: Use helper API to trigger a non-blocking host resume

In reply to Bhaumik Bhatt
Quoted 7 lines · Bhaumik Bhatt

Autonomous low power mode support requires the MHI host to resume from multiple places and post a wakeup source to exit system suspend. This needs to be done in a non-blocking manner. Introduce a helper API to trigger the host resume for data transfers and other non-blocking use cases while supporting implementation of autonomous low power modes.

Thanks,
Mani

Quoted 112 lines
---
 drivers/bus/mhi/core/internal.h |  7 +++++++
 drivers/bus/mhi/core/main.c     | 21 +++++++--------------
 drivers/bus/mhi/core/pm.c       | 13 ++++---------
 3 files changed, 18 insertions(+), 23 deletions(-)
drivers/bus/mhi/core/internal.h +7 -0
index bcfa7b6..1bbd6e9 100644
@@ -599,6 +599,13 @@ int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl);
 int mhi_send_cmd(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
 		 enum mhi_cmd_type cmd);
 
+static inline void mhi_trigger_resume(struct mhi_controller *mhi_cntrl)
+{
+	pm_wakeup_event(&mhi_cntrl->mhi_dev->dev, 0);
+	mhi_cntrl->runtime_get(mhi_cntrl);
+	mhi_cntrl->runtime_put(mhi_cntrl);
+}
+
 /* Register access methods */
 void mhi_db_brstmode(struct mhi_controller *mhi_cntrl, struct db_cfg *db_cfg,
 		     void __iomem *db_addr, dma_addr_t db_val);
drivers/bus/mhi/core/main.c +7 -14
index 1f622ce..79be18e 100644
@@ -909,8 +909,7 @@ void mhi_ctrl_ev_task(unsigned long data)
 		 * process it since we are probably in a suspended state,
 		 * so trigger a resume.
 		 */
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
+		mhi_trigger_resume(mhi_cntrl);
 
 		return;
 	}
@@ -971,10 +970,8 @@ int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir,
 	}
 
 	/* we're in M3 or transitioning to M3 */
-	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
-	}
+	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+		mhi_trigger_resume(mhi_cntrl);
 
 	/* Toggle wake to exit out of M2 */
 	mhi_cntrl->wake_toggle(mhi_cntrl);
@@ -1032,10 +1029,8 @@ int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir,
 	}
 
 	/* we're in M3 or transitioning to M3 */
-	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
-	}
+	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+		mhi_trigger_resume(mhi_cntrl);
 
 	/* Toggle wake to exit out of M2 */
 	mhi_cntrl->wake_toggle(mhi_cntrl);
@@ -1147,10 +1142,8 @@ int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir,
 	read_lock_irqsave(&mhi_cntrl->pm_lock, flags);
 
 	/* we're in M3 or transitioning to M3 */
-	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
-	}
+	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+		mhi_trigger_resume(mhi_cntrl);
 
 	/* Toggle wake to exit out of M2 */
 	mhi_cntrl->wake_toggle(mhi_cntrl);
drivers/bus/mhi/core/pm.c +4 -9
index 661d704..b227d41 100644
@@ -824,11 +824,8 @@ int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl)
 	/* Wake up the device */
 	read_lock_bh(&mhi_cntrl->pm_lock);
 	mhi_cntrl->wake_get(mhi_cntrl, true);
-	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-		pm_wakeup_event(&mhi_cntrl->mhi_dev->dev, 0);
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
-	}
+	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+		mhi_trigger_resume(mhi_cntrl);
 	read_unlock_bh(&mhi_cntrl->pm_lock);
 
 	ret = wait_event_timeout(mhi_cntrl->state_event,
@@ -1139,10 +1136,8 @@ void mhi_device_put(struct mhi_device *mhi_dev)
 
 	mhi_dev->dev_wake--;
 	read_lock_bh(&mhi_cntrl->pm_lock);
-	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-		mhi_cntrl->runtime_get(mhi_cntrl);
-		mhi_cntrl->runtime_put(mhi_cntrl);
-	}
+	if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+		mhi_trigger_resume(mhi_cntrl);
 
 	mhi_cntrl->wake_put(mhi_cntrl, false);
 	read_unlock_bh(&mhi_cntrl->pm_lock);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#10 lore raw

Re: [PATCH v5 07/10] bus: mhi: core: Introduce debugfs entries for MHI

In reply to Bhaumik Bhatt
Thank you for the patch! Yet something to improve:

Hi Bhaumik,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.8-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Bhaumik-Bhatt/Introduce-features-and-debugfs-sysfs-entries-for-MHI/20200724-063954
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git d15be546031cf65a0fc34879beca02fd90fe7ac7
config: parisc-allmodconfig (attached as .config)
compiler: hppa-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=parisc

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

WARNING: modpost: missing MODULE_LICENSE() in drivers/bus/mhi/core/main.o
WARNING: modpost: missing MODULE_LICENSE() in drivers/bus/mhi/core/pm.o
WARNING: modpost: missing MODULE_LICENSE() in drivers/bus/mhi/core/boot.o

>> ERROR: modpost: "mhi_ready_state_transition" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_write_reg_field" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_read_reg_field" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_read_reg" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_write_reg" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_set_mhi_state" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_get_exec_env" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_ee_str" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_state_str" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "to_mhi_pm_state_str" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_create_devices" [drivers/bus/mhi/core/pm.ko] undefined!
>> ERROR: modpost: "mhi_fw_load_handler" [drivers/bus/mhi/core/pm.ko] undefined!
>> ERROR: modpost: "dev_state_tran_str" [drivers/bus/mhi/core/pm.ko] undefined!
>> ERROR: modpost: "mhi_free_bhie_table" [drivers/bus/mhi/core/pm.ko] undefined!
>> ERROR: modpost: "mhi_deinit_dev_ctxt" [drivers/bus/mhi/core/pm.ko] undefined!
>> ERROR: modpost: "mhi_deinit_free_irq" [drivers/bus/mhi/core/pm.ko] undefined!
>> ERROR: modpost: "mhi_get_mhi_state" [drivers/bus/mhi/core/pm.ko] undefined!
>> ERROR: modpost: "mhi_get_exec_env" [drivers/bus/mhi/core/pm.ko] undefined!
>> ERROR: modpost: "mhi_read_reg" [drivers/bus/mhi/core/pm.ko] undefined!
>> ERROR: modpost: "mhi_init_dev_ctxt" [drivers/bus/mhi/core/pm.ko] undefined!

ERROR: modpost: "mhi_init_irq_setup" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_ring_chan_db" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_ring_cmd_db" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_write_reg" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_destroy_device" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_ring_er_db" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_init_mmio" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_read_reg_field" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_state_str" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "to_mhi_pm_state_str" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_write_reg_field" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_write_db" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_init_chan_ctxt" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_deinit_chan_ctxt" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_queue_state_transition" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_pm_m3_transition" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_pm_m1_transition" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_pm_m0_transition" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "to_mhi_pm_state_str" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_pm_sys_err_handler" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_tryset_pm_state" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_state_str" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_ee_str" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_alloc_device" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_bus_type" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_debugfs_exit" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_debugfs_init" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_create_debugfs" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_unmap_single_no_bb" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_map_single_no_bb" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_unmap_single_use_bb" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_map_single_use_bb" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_ev_task" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_ctrl_ev_task" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_pm_st_worker" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_process_ctrl_ev_ring" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_process_data_event_ring" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_db_brstmode_disable" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_db_brstmode" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_reset_chan" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_write_reg_field" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_write_reg" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_read_reg_field" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_rddm_prepare" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_read_reg" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_alloc_bhie_table" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_free_bhie_table" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_irq_handler" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_intvec_handler" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_intvec_threaded_handler" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_prepare_channel" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_destroy_debugfs" [drivers/bus/mhi/core/init.ko] undefined!

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#16 lore raw

Re: [PATCH v5 10/10] bus: mhi: core: Introduce sysfs entries for MHI

In reply to Manivannan Sadhasivam
Quoted 30 lines · Manivannan Sadhasivam
Quoted 29 lines · Bhaumik Bhatt

Introduce sysfs entries to enable userspace clients the ability to read the serial number and the OEM PK Hash values obtained from BHI. OEMs need to read these device-specific hardware information values through userspace for factory testing purposes and cannot be exposed via degbufs as it may remain disabled for performance reasons. Also, update the documentation for ABI to include these entries.

---
 Documentation/ABI/stable/sysfs-bus-mhi | 25 ++++++++++++++++
 MAINTAINERS                            |  1 +
 drivers/bus/mhi/core/init.c            | 53 
++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-bus-mhi
Documentation/ABI/stable/sysfs-bus-mhi new file +7 -0
new file mode 100644
index 0000000..a4e4bd2
@@ -0,0 +1,25 @@
+What:		/sys/bus/mhi/devices/.../serialnumber
+Date:		July 2020
+KernelVersion:  5.8
+Contact:	Bhaumik Bhatt <[email protected]>
+Description:
+		The file holds the serial number of the client device obtained
+		using a BHI (Boot Host Interface) register read after at least
Quoted 9 lines

Documentation/ABI/stable/sysfs-bus-mhi line 12

Quoted 5 lines
Documentation/ABI/stable/sysfs-bus-mhi new file +5 -0
+		one attempt to power up the device has been done. If read
+		without having the device power on at least once, the file will
+		read all 0's.
+Users:		Any userspace application or clients interested in the device
+		hardware information.

Please align all the fields onto a single starting point. Have a look at other ABI documentation like, Documentation/ABI/stable/sysfs-bus-vmbus.

Alignment was updated. Seems OK to me actually, I am unsure why the patch shows up as slightly different on email.

Quoted 34 lines
Quoted 34 lines
Documentation/ABI/stable/sysfs-bus-mhi new file +13 -0
+
+What:		/sys/bus/mhi/devices/.../oem_pk_hash
+Date:		July 2020
+KernelVersion:  5.8
+Contact:	Bhaumik Bhatt <[email protected]>
+Description:
+		The file holds the OEM PK Hash value of the endpoint device
+		obtained using a BHI (Boot Host Interface) register read after
+		at least one attempt to power up the device has been done. If
+		read without having the device power on at least once, the file
+		will read all 0's.
+Users:		Any userspace application or clients interested in the device
+		hardware information.
MAINTAINERS +1 -0
index e64e5db..5e49316 100644
@@ -11018,6 +11018,7 @@ M:	Hemant Kumar <[email protected]>
 L:	[email protected]
 S:	Maintained
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/mani/mhi.git
+F:	Documentation/ABI/stable/sysfs-bus-mhi
 F:	Documentation/mhi/
 F:	drivers/bus/mhi/
 F:	include/linux/mhi.h
drivers/bus/mhi/core/init.c +0 -0
index d2c0f6e..a7b0d76 100644
@@ -76,6 +76,56 @@ const char *to_mhi_pm_state_str(enum mhi_pm_state 
 state)
 	return mhi_pm_state_str[index];
 }
 
Quoted 7 lines

drivers/bus/mhi/core/init.c const char *to_mhi_pm_state_str(enum mhi_pm_state state) · line 81

Quoted 3 lines
drivers/bus/mhi/core/init.c +3 -0
+static ssize_t serial_number_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)

We haven't followed this before but it is good to align the function parameters with respect to '('.

This one too, I have made sure it is aligned with the '('. Maybe a re-upload should clear it up.

Quoted 12 lines

drivers/bus/mhi/core/init.c const char *to_mhi_pm_state_str(enum mhi_pm_state state) · line 87

Quoted 6 lines
drivers/bus/mhi/core/init.c +6 -0
+{
+	struct mhi_device *mhi_dev = to_mhi_device(dev);
+	struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
+
+	return snprintf(buf, PAGE_SIZE, "Serial Number: %u\n",
+			mhi_cntrl->serial_number);

We need to think about what happens if the mhi_cntrl structure is not zero initialized by the controller driver. All throughout the stack we assume that the mhi_cntrl struct is zero initialized but things can go awry if it was not the case!

Quoted 4 lines

There was one API in the downstream (mhi_alloc_controller()) for this purpose but I removed it since we ended up with just a kzalloc(). Does it make sense to introduce it now?

Thanks for pointing out. I realize this could have potential consequences and have added the patch to introduce the API as a dependency.

Quoted 71 lines

Thanks,
Mani

Quoted 68 lines
drivers/bus/mhi/core/init.c +41 -0
+}
+static DEVICE_ATTR_RO(serial_number);
+
+static ssize_t oem_pk_hash_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct mhi_device *mhi_dev = to_mhi_device(dev);
+	struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
+	int i, cnt = 0;
+
+	for (i = 0; i < ARRAY_SIZE(mhi_cntrl->oem_pk_hash); i++)
+		cnt += snprintf(buf + cnt, PAGE_SIZE - cnt,
+				"OEMPKHASH[%d]: 0x%x\n", i,
+				mhi_cntrl->oem_pk_hash[i]);
+
+	return cnt;
+}
+static DEVICE_ATTR_RO(oem_pk_hash);
+
+static struct attribute *mhi_sysfs_attrs[] = {
+	&dev_attr_serial_number.attr,
+	&dev_attr_oem_pk_hash.attr,
+	NULL,
+};
+
+static const struct attribute_group mhi_sysfs_group = {
+	.attrs = mhi_sysfs_attrs,
+};
+
+static int mhi_create_sysfs(struct mhi_controller *mhi_cntrl)
+{
+	return sysfs_create_group(&mhi_cntrl->mhi_dev->dev.kobj,
+				  &mhi_sysfs_group);
+}
+
+static void mhi_destroy_sysfs(struct mhi_controller *mhi_cntrl)
+{
+	sysfs_remove_group(&mhi_cntrl->mhi_dev->dev.kobj, &mhi_sysfs_group);
+}
+
 /* MHI protocol requires the transfer ring to be aligned with ring 

length */
static int mhi_alloc_aligned_ring(struct mhi_controller *mhi_cntrl,

drivers/bus/mhi/core/init.c +3 -0
 				  struct mhi_ring *ring,
@@ -917,6 +967,8 @@ int mhi_register_controller(struct mhi_controller 
 *mhi_cntrl,
 	mhi_cntrl->mhi_dev = mhi_dev;
 
 	mhi_create_debugfs(mhi_cntrl);
+	if (mhi_create_sysfs(mhi_cntrl))
+		dev_err(mhi_cntrl->cntrl_dev, "Failed to create sysfs entries\n");
 
 	return 0;
@@ -940,6 +992,7 @@ void mhi_unregister_controller(struct 
 mhi_controller *mhi_cntrl)
 	struct mhi_chan *mhi_chan = mhi_cntrl->mhi_chan;
 	unsigned int i;
 
+	mhi_destroy_sysfs(mhi_cntrl);
 	mhi_destroy_debugfs(mhi_cntrl);
 

kfree(mhi_cntrl->mhi_cmd);
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project