Skip to contentSkip to conversation

Introduce features and debugfs/sysfs entries for MHI

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

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 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.

v6:
-Introduced APIs for allocating and freeing the MHI controller so as to ensure that it is always zero-initialized.
-Moved gerrits around for counter introduction.
-Fixed documentation for sysfs.

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 (11):
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 counters to track MHI device state
transitions
bus: mhi: core: Introduce debugfs entries for MHI
bus: mhi: core: Read and save device hardware information from BHI
bus: mhi: core: Introduce APIs to allocate and free the MHI controller
bus: mhi: core: Introduce sysfs entries for MHI

 Documentation/ABI/stable/sysfs-bus-mhi |  21 ++
 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            |  81 ++++++-
 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                    |  30 ++-
 11 files changed, 623 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
#1 lore raw

PATCH v6 1/11 bus: mhi: core: Remove double occurrence for mhi_ctrl_ev_task() declaration

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
#2 lore raw

PATCH v6 2/11 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
#3 lore raw

PATCH v6 3/11 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
#4 lore raw

PATCH v6 4/11 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
#5 lore raw

PATCH v6 5/11 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 96a5a4a..a8379b3 100644
@@ -438,10 +438,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
@@ -453,7 +453,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
#6 lore raw

PATCH v6 6/11 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
#7 lore raw

PATCH v6 7/11 bus: mhi: core: Introduce 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 can help in better debug, allowing the user to see the number of transitions to a certain MHI state when queried using debugfs entries or via other mechanisms.

---
 drivers/bus/mhi/core/pm.c | 4 ++++
 include/linux/mhi.h       | 2 ++
 2 files changed, 6 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;
include/linux/mhi.h +2 -0
index a8379b3..e38de6d 100644
@@ -328,6 +328,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
@@ -407,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
Reviewed-by on v6 7/11
#8 lore raw

Re: [PATCH v6 07/11] bus: mhi: core: Introduce counters to track MHI device state transitions

Quoted 6 lines · Bhaumik Bhatt

Use counters to track MHI device state transitions such as those to M0, M2, or M3 states. This can help in better debug, allowing the user to see the number of transitions to a certain MHI state when queried using debugfs entries or via other mechanisms.

A minor nit below...

Quoted 47 lines
---
 drivers/bus/mhi/core/pm.c | 4 ++++
 include/linux/mhi.h       | 2 ++
 2 files changed, 6 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;
include/linux/mhi.h +1 -0
index a8379b3..e38de6d 100644
@@ -328,6 +328,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

include/linux/mhi.h struct mhi_controller { · line 411

Quoted 4 lines
include/linux/mhi.h +1 -0
@@ -407,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;

Are you using M3_fast anywhere in current series? If not, please drop it for now.

Thanks,
Mani

Quoted 7 lines
include/linux/mhi.h +0 -0
 	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
#9 lore raw

PATCH v6 8/11 bus: mhi: core: Introduce debugfs entries for MHI

In reply to Bhaumik Bhatt

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             |   2 +
 6 files changed, 452 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 +2 -0
index e38de6d..a6e6634 100644
@@ -290,6 +290,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
@@ -367,6 +368,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;
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 v6 08/11] bus: mhi: core: Introduce debugfs entries for MHI

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-rc7 next-20200731]
[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/20200728-100824
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 92ed301919932f777713b9172e525674157e983d
config: i386-randconfig-a015-20200731 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-14) 9.3.0
reproduce (this is a W=1 build):
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

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" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_write_reg" [drivers/bus/mhi/core/boot.ko] undefined!
ERROR: modpost: "to_mhi_pm_state_str" [drivers/bus/mhi/core/boot.ko] undefined!
ERROR: modpost: "mhi_state_str" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_ee_str" [drivers/bus/mhi/core/boot.ko] undefined!
>> ERROR: modpost: "mhi_read_reg_field" [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: "dev_state_tran_str" [drivers/bus/mhi/core/pm.ko] undefined!
>> ERROR: modpost: "mhi_fw_load_handler" [drivers/bus/mhi/core/pm.ko] undefined!
>> ERROR: modpost: "mhi_create_devices" [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_destroy_device" [drivers/bus/mhi/core/pm.ko] undefined!
ERROR: modpost: "mhi_write_reg" [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_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_queue_state_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_ee_str" [drivers/bus/mhi/core/main.ko] undefined!
ERROR: modpost: "mhi_state_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_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_ctrl_ev_task" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_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" [drivers/bus/mhi/core/init.ko] undefined!
ERROR: modpost: "mhi_db_brstmode_disable" [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!

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

#11 lore raw

PATCH v6 9/11 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 a6e6634..d15e9ce 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;
@@ -317,6 +319,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
@@ -396,6 +400,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
#12 lore raw

PATCH v6 10/11 bus: mhi: core: Introduce APIs to allocate and free the MHI controller

In reply to Bhaumik Bhatt

Client devices should use the APIs provided to allocate and free the MHI controller structure. This will help ensure that the structure is zero-initialized and there are no false positives with respect to reading any values such as the serial number or the OEM PK hash.

---
 drivers/bus/mhi/core/init.c | 16 ++++++++++++++++
 include/linux/mhi.h         | 12 ++++++++++++
 2 files changed, 28 insertions(+)
drivers/bus/mhi/core/init.c +16 -0
index d2c0f6e..972dbf0 100644
@@ -959,6 +959,22 @@ void mhi_unregister_controller(struct mhi_controller *mhi_cntrl)
 }
 EXPORT_SYMBOL_GPL(mhi_unregister_controller);
 
+struct mhi_controller *mhi_alloc_controller(void)
+{
+	struct mhi_controller *mhi_cntrl;
+
+	mhi_cntrl = kzalloc(sizeof(*mhi_cntrl), GFP_KERNEL);
+
+	return mhi_cntrl;
+}
+EXPORT_SYMBOL_GPL(mhi_alloc_controller);
+
+void mhi_free_controller(struct mhi_controller *mhi_cntrl)
+{
+	kfree(mhi_cntrl);
+}
+EXPORT_SYMBOL_GPL(mhi_free_controller);
+
 int mhi_prepare_for_power_up(struct mhi_controller *mhi_cntrl)
 {
 	struct device *dev = &mhi_cntrl->mhi_dev->dev;
include/linux/mhi.h +12 -0
index d15e9ce..a35d876 100644
@@ -530,6 +530,18 @@ struct mhi_driver {
 #define to_mhi_device(dev) container_of(dev, struct mhi_device, dev)
 
 /**
+ * mhi_alloc_controller - Allocate the MHI Controller structure
+ * Allocate the mhi_controller structure using zero initialized memory
+ */
+struct mhi_controller *mhi_alloc_controller(void);
+
+/**
+ * mhi_free_controller - Free the MHI Controller structure
+ * Free the mhi_controller structure which was previously allocated
+ */
+void mhi_free_controller(struct mhi_controller *mhi_cntrl);
+
+/**
  * mhi_register_controller - Register MHI controller
  * @mhi_cntrl: MHI controller to register
  * @config: Configuration to use for the controller
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
Reviewed-by on v6 10/11
#13 lore raw

Re: [PATCH v6 10/11] bus: mhi: core: Introduce APIs to allocate and free the MHI controller

Quoted 7 lines · Bhaumik Bhatt

Client devices should use the APIs provided to allocate and free the MHI controller structure. This will help ensure that the structure is zero-initialized and there are no false positives with respect to reading any values such as the serial number or the OEM PK hash.

Can you please also add the Suggested-by tag?

Thanks,
Mani

Quoted 59 lines
---
 drivers/bus/mhi/core/init.c | 16 ++++++++++++++++
 include/linux/mhi.h         | 12 ++++++++++++
 2 files changed, 28 insertions(+)
drivers/bus/mhi/core/init.c +16 -0
index d2c0f6e..972dbf0 100644
@@ -959,6 +959,22 @@ void mhi_unregister_controller(struct mhi_controller *mhi_cntrl)
 }
 EXPORT_SYMBOL_GPL(mhi_unregister_controller);
 
+struct mhi_controller *mhi_alloc_controller(void)
+{
+	struct mhi_controller *mhi_cntrl;
+
+	mhi_cntrl = kzalloc(sizeof(*mhi_cntrl), GFP_KERNEL);
+
+	return mhi_cntrl;
+}
+EXPORT_SYMBOL_GPL(mhi_alloc_controller);
+
+void mhi_free_controller(struct mhi_controller *mhi_cntrl)
+{
+	kfree(mhi_cntrl);
+}
+EXPORT_SYMBOL_GPL(mhi_free_controller);
+
 int mhi_prepare_for_power_up(struct mhi_controller *mhi_cntrl)
 {
 	struct device *dev = &mhi_cntrl->mhi_dev->dev;
include/linux/mhi.h +12 -0
index d15e9ce..a35d876 100644
@@ -530,6 +530,18 @@ struct mhi_driver {
 #define to_mhi_device(dev) container_of(dev, struct mhi_device, dev)
 
 /**
+ * mhi_alloc_controller - Allocate the MHI Controller structure
+ * Allocate the mhi_controller structure using zero initialized memory
+ */
+struct mhi_controller *mhi_alloc_controller(void);
+
+/**
+ * mhi_free_controller - Free the MHI Controller structure
+ * Free the mhi_controller structure which was previously allocated
+ */
+void mhi_free_controller(struct mhi_controller *mhi_cntrl);
+
+/**
  * mhi_register_controller - Register MHI controller
  * @mhi_cntrl: MHI controller to register
  * @config: Configuration to use for the controller
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 v6 11/11 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 | 21 ++++++++++++++
 MAINTAINERS                            |  1 +
 drivers/bus/mhi/core/init.c            | 53 ++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-bus-mhi
Documentation/ABI/stable/sysfs-bus-mhi new file +21 -0
new file mode 100644
index 0000000..1d5d0d6
@@ -0,0 +1,21 @@
+What:		/sys/bus/mhi/devices/.../serialnumber
+Date:		Jul 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 device info.
+
+What:		/sys/bus/mhi/devices/.../oem_pk_hash
+Date:		Jul 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 device info.
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
#15 lore raw

Re: [PATCH v6 11/11] bus: mhi: core: Introduce sysfs entries for MHI

Quoted 21 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 | 21 ++++++++++++++
 MAINTAINERS                            |  1 +
 drivers/bus/mhi/core/init.c            | 53 ++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-bus-mhi
Documentation/ABI/stable/sysfs-bus-mhi new file +0 -0
new file mode 100644
index 0000000..1d5d0d6

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

Quoted 10 lines
Documentation/ABI/stable/sysfs-bus-mhi new file +10 -0
@@ -0,0 +1,21 @@
+What:		/sys/bus/mhi/devices/.../serialnumber
+Date:		Jul 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 device info.

I think you're not using tabs here and that's why it is showing mangled. Please use tabs as like other files.

Thanks,
Mani

Quoted 105 lines
Documentation/ABI/stable/sysfs-bus-mhi new file +11 -0
+
+What:		/sys/bus/mhi/devices/.../oem_pk_hash
+Date:		Jul 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 device info.
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
index 972dbf0..c086ef2 100644
@@ -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)
+{
+	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);
+}
+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
#16 lore raw

Re: [PATCH v6 11/11] bus: mhi: core: Introduce sysfs entries for MHI

Quoted 39 lines · Manivannan Sadhasivam
Quoted 33 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 | 21 ++++++++++++++
 MAINTAINERS                            |  1 +
 drivers/bus/mhi/core/init.c            | 53 
++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-bus-mhi
Documentation/ABI/stable/sysfs-bus-mhi new file +5 -0
new file mode 100644
index 0000000..1d5d0d6
@@ -0,0 +1,21 @@
+What:		/sys/bus/mhi/devices/.../serialnumber
+Date:		Jul 2020
+KernelVersion:	5.8
+Contact:	Bhaumik Bhatt <[email protected]>
+Description:	The file holds the serial number of the client device 

obtained

Documentation/ABI/stable/sysfs-bus-mhi new file +5 -0
+		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 device 
Quoted 1 line

info.

I think you're not using tabs here and that's why it is showing mangled. Please use tabs as like other files.

Quoted 3 lines

Thanks,
Mani

Hi Mani,

I am using tabs actually. I, in fact, copied another file (sysfs-bus-vmbus) and only modified the required entries and did a diff to confirm.

I doubt there is more I can do.

Please let me know if the next patch is acceptable soon.

Quoted 111 lines
Quoted 111 lines
Documentation/ABI/stable/sysfs-bus-mhi new file +6 -0
+
+What:		/sys/bus/mhi/devices/.../oem_pk_hash
+Date:		Jul 2020
+KernelVersion:	5.8
+Contact:	Bhaumik Bhatt <[email protected]>
+Description:	The file holds the OEM PK Hash value of the endpoint 

device

Documentation/ABI/stable/sysfs-bus-mhi new file +5 -0
+		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 device 

info.

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 +50 -0
index 972dbf0..c086ef2 100644
@@ -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)
+{
+	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);
+}
+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