drivers/bus/mhi/host/internal.h | 1 + drivers/bus/mhi/host/main.c | 1 + drivers/bus/mhi/host/pm.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+)
From: Vivek Pernamitta <quic_vpernami@quicinc.com>
Notify the MHI device's Execution Environment (EE) state via uevent,
enabling applications to receive real-time updates and take appropriate
actions based on the current state of MHI.
Signed-off-by: Vivek Pernamitta <quic_vpernami@quicinc.com>
---
Notify the MHI device's Execution Environment (EE) state via uevent,
enabling applications to receive real-time updates and take appropriate
actions based on the current state.
Signed-off-by:
---
Usage:
Enabling 16 virtual fucntions for SRIOV device QDU100 once device reached
mission mode from systemd service file
SUBSYSTEM=="mhi", ENV{EXEC_ENV}=="MISSION MODE", SUBSYSTEMS=="pci", ATTRS{device}=="0x0601",ATTR{../sriov_numvfs}="16"
---
---
Changes in v2:
- Fix memory leak in uevent notifier.
- Link to v1: https://lore.kernel.org/r/20250822-uevent_vdev_next-20250821-v1-1-9ed3a8162194@quicinc.com
---
---
drivers/bus/mhi/host/internal.h | 1 +
drivers/bus/mhi/host/main.c | 1 +
drivers/bus/mhi/host/pm.c | 29 +++++++++++++++++++++++++++++
3 files changed, 31 insertions(+)
diff --git a/drivers/bus/mhi/host/internal.h b/drivers/bus/mhi/host/internal.h
index 034be33565b78eff9bdefd93faa4f3ce93825bad..d455f0bf00133775fa23882a727782275640e43b 100644
--- a/drivers/bus/mhi/host/internal.h
+++ b/drivers/bus/mhi/host/internal.h
@@ -403,6 +403,7 @@ int mhi_process_data_event_ring(struct mhi_controller *mhi_cntrl,
struct mhi_event *mhi_event, u32 event_quota);
int mhi_process_ctrl_ev_ring(struct mhi_controller *mhi_cntrl,
struct mhi_event *mhi_event, u32 event_quota);
+void mhi_uevent_notify(struct mhi_controller *mhi_cntrl, enum mhi_ee_type ee);
/* ISR handlers */
irqreturn_t mhi_irq_handler(int irq_number, void *dev);
diff --git a/drivers/bus/mhi/host/main.c b/drivers/bus/mhi/host/main.c
index 52bef663e182de157e50f64c1764a52545c70865..8615512743199a59a58c3756d9cc3407079cee7e 100644
--- a/drivers/bus/mhi/host/main.c
+++ b/drivers/bus/mhi/host/main.c
@@ -512,6 +512,7 @@ irqreturn_t mhi_intvec_threaded_handler(int irq_number, void *priv)
if (mhi_cntrl->rddm_image && mhi_is_active(mhi_cntrl)) {
mhi_cntrl->status_cb(mhi_cntrl, MHI_CB_EE_RDDM);
mhi_cntrl->ee = ee;
+ mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee);
wake_up_all(&mhi_cntrl->state_event);
}
break;
diff --git a/drivers/bus/mhi/host/pm.c b/drivers/bus/mhi/host/pm.c
index 33d92bf2fc3ed48db5f7fe80e4f0ef9fe2d2f2ab..331f65921a979adce60a32fb62e2c9b712f21c87 100644
--- a/drivers/bus/mhi/host/pm.c
+++ b/drivers/bus/mhi/host/pm.c
@@ -418,6 +418,7 @@ static int mhi_pm_mission_mode_transition(struct mhi_controller *mhi_cntrl)
device_for_each_child(&mhi_cntrl->mhi_dev->dev, ¤t_ee,
mhi_destroy_device);
mhi_cntrl->status_cb(mhi_cntrl, MHI_CB_EE_MISSION_MODE);
+ mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee);
/* Force MHI to be in M0 state before continuing */
ret = __mhi_device_get_sync(mhi_cntrl);
@@ -631,6 +632,8 @@ static void mhi_pm_sys_error_transition(struct mhi_controller *mhi_cntrl)
/* Wake up threads waiting for state transition */
wake_up_all(&mhi_cntrl->state_event);
+ mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee);
+
if (MHI_REG_ACCESS_VALID(prev_state)) {
/*
* If the device is in PBL or SBL, it will only respond to
@@ -829,6 +832,8 @@ void mhi_pm_st_worker(struct work_struct *work)
mhi_create_devices(mhi_cntrl);
if (mhi_cntrl->fbc_download)
mhi_download_amss_image(mhi_cntrl);
+
+ mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee);
break;
case DEV_ST_TRANSITION_MISSION_MODE:
mhi_pm_mission_mode_transition(mhi_cntrl);
@@ -838,6 +843,7 @@ void mhi_pm_st_worker(struct work_struct *work)
mhi_cntrl->ee = MHI_EE_FP;
write_unlock_irq(&mhi_cntrl->pm_lock);
mhi_create_devices(mhi_cntrl);
+ mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee);
break;
case DEV_ST_TRANSITION_READY:
mhi_ready_state_transition(mhi_cntrl);
@@ -1240,6 +1246,8 @@ static void __mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful,
write_unlock_irq(&mhi_cntrl->pm_lock);
mutex_unlock(&mhi_cntrl->pm_mutex);
+ mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee);
+
if (destroy_device)
mhi_queue_state_transition(mhi_cntrl,
DEV_ST_TRANSITION_DISABLE_DESTROY_DEVICE);
@@ -1338,3 +1346,24 @@ void mhi_device_put(struct mhi_device *mhi_dev)
read_unlock_bh(&mhi_cntrl->pm_lock);
}
EXPORT_SYMBOL_GPL(mhi_device_put);
+
+void mhi_uevent_notify(struct mhi_controller *mhi_cntrl, enum mhi_ee_type ee)
+{
+ struct device *dev = &mhi_cntrl->mhi_dev->dev;
+ char *buf[2];
+ int ret;
+
+ buf[0] = kasprintf(GFP_KERNEL, "EXEC_ENV=%s", TO_MHI_EXEC_STR(ee));
+ buf[1] = NULL;
+
+ if (!buf[0]) {
+ dev_dbg(dev, "Failed to allocate memory for uevent");
+ return;
+ }
+
+ ret = kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, buf);
+ if (ret)
+ dev_err(dev, "Failed to send %s uevent\n", TO_MHI_EXEC_STR(ee));
+
+ kfree(buf[0]);
+}
---
base-commit: 8f21d9da46702c4d6951ba60ca8a05f42870fe8f
change-id: 20250912-b4-uevent_vdev_next-20250911-fc41e38f1d5b
Best regards,
--
Vivek Pernamitta <<quic_vpernami@quicinc.com>>
On Fri, Sep 12, 2025 at 10:29:16AM GMT, Vivek.Pernamitta@quicinc.com wrote: > From: Vivek Pernamitta <quic_vpernami@quicinc.com> > > Notify the MHI device's Execution Environment (EE) state via uevent, > enabling applications to receive real-time updates and take appropriate > actions based on the current state of MHI. > > Signed-off-by: Vivek Pernamitta <quic_vpernami@quicinc.com> > --- > Notify the MHI device's Execution Environment (EE) state via uevent, > enabling applications to receive real-time updates and take appropriate > actions based on the current state. > > Signed-off-by: Duplicate? > --- > Usage: > > Enabling 16 virtual fucntions for SRIOV device QDU100 once device reached > mission mode from systemd service file > > SUBSYSTEM=="mhi", ENV{EXEC_ENV}=="MISSION MODE", SUBSYSTEMS=="pci", ATTRS{device}=="0x0601",ATTR{../sriov_numvfs}="16" > --- > > --- > Changes in v2: > - Fix memory leak in uevent notifier. > - Link to v1: https://lore.kernel.org/r/20250822-uevent_vdev_next-20250821-v1-1-9ed3a8162194@quicinc.com > --- > > --- > drivers/bus/mhi/host/internal.h | 1 + > drivers/bus/mhi/host/main.c | 1 + > drivers/bus/mhi/host/pm.c | 29 +++++++++++++++++++++++++++++ > 3 files changed, 31 insertions(+) > > diff --git a/drivers/bus/mhi/host/internal.h b/drivers/bus/mhi/host/internal.h > index 034be33565b78eff9bdefd93faa4f3ce93825bad..d455f0bf00133775fa23882a727782275640e43b 100644 > --- a/drivers/bus/mhi/host/internal.h > +++ b/drivers/bus/mhi/host/internal.h > @@ -403,6 +403,7 @@ int mhi_process_data_event_ring(struct mhi_controller *mhi_cntrl, > struct mhi_event *mhi_event, u32 event_quota); > int mhi_process_ctrl_ev_ring(struct mhi_controller *mhi_cntrl, > struct mhi_event *mhi_event, u32 event_quota); > +void mhi_uevent_notify(struct mhi_controller *mhi_cntrl, enum mhi_ee_type ee); > > /* ISR handlers */ > irqreturn_t mhi_irq_handler(int irq_number, void *dev); > diff --git a/drivers/bus/mhi/host/main.c b/drivers/bus/mhi/host/main.c > index 52bef663e182de157e50f64c1764a52545c70865..8615512743199a59a58c3756d9cc3407079cee7e 100644 > --- a/drivers/bus/mhi/host/main.c > +++ b/drivers/bus/mhi/host/main.c > @@ -512,6 +512,7 @@ irqreturn_t mhi_intvec_threaded_handler(int irq_number, void *priv) > if (mhi_cntrl->rddm_image && mhi_is_active(mhi_cntrl)) { > mhi_cntrl->status_cb(mhi_cntrl, MHI_CB_EE_RDDM); > mhi_cntrl->ee = ee; > + mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee); > wake_up_all(&mhi_cntrl->state_event); > } > break; > diff --git a/drivers/bus/mhi/host/pm.c b/drivers/bus/mhi/host/pm.c > index 33d92bf2fc3ed48db5f7fe80e4f0ef9fe2d2f2ab..331f65921a979adce60a32fb62e2c9b712f21c87 100644 > --- a/drivers/bus/mhi/host/pm.c > +++ b/drivers/bus/mhi/host/pm.c > @@ -418,6 +418,7 @@ static int mhi_pm_mission_mode_transition(struct mhi_controller *mhi_cntrl) > device_for_each_child(&mhi_cntrl->mhi_dev->dev, ¤t_ee, > mhi_destroy_device); > mhi_cntrl->status_cb(mhi_cntrl, MHI_CB_EE_MISSION_MODE); > + mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee); > > /* Force MHI to be in M0 state before continuing */ > ret = __mhi_device_get_sync(mhi_cntrl); > @@ -631,6 +632,8 @@ static void mhi_pm_sys_error_transition(struct mhi_controller *mhi_cntrl) > /* Wake up threads waiting for state transition */ > wake_up_all(&mhi_cntrl->state_event); > > + mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee); > + > if (MHI_REG_ACCESS_VALID(prev_state)) { > /* > * If the device is in PBL or SBL, it will only respond to > @@ -829,6 +832,8 @@ void mhi_pm_st_worker(struct work_struct *work) > mhi_create_devices(mhi_cntrl); > if (mhi_cntrl->fbc_download) > mhi_download_amss_image(mhi_cntrl); > + > + mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee); > break; > case DEV_ST_TRANSITION_MISSION_MODE: > mhi_pm_mission_mode_transition(mhi_cntrl); > @@ -838,6 +843,7 @@ void mhi_pm_st_worker(struct work_struct *work) > mhi_cntrl->ee = MHI_EE_FP; > write_unlock_irq(&mhi_cntrl->pm_lock); > mhi_create_devices(mhi_cntrl); > + mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee); > break; > case DEV_ST_TRANSITION_READY: > mhi_ready_state_transition(mhi_cntrl); > @@ -1240,6 +1246,8 @@ static void __mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful, > write_unlock_irq(&mhi_cntrl->pm_lock); > mutex_unlock(&mhi_cntrl->pm_mutex); > > + mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee); > + > if (destroy_device) > mhi_queue_state_transition(mhi_cntrl, > DEV_ST_TRANSITION_DISABLE_DESTROY_DEVICE); > @@ -1338,3 +1346,24 @@ void mhi_device_put(struct mhi_device *mhi_dev) > read_unlock_bh(&mhi_cntrl->pm_lock); > } > EXPORT_SYMBOL_GPL(mhi_device_put); > + > +void mhi_uevent_notify(struct mhi_controller *mhi_cntrl, enum mhi_ee_type ee) > +{ > + struct device *dev = &mhi_cntrl->mhi_dev->dev; > + char *buf[2]; > + int ret; > + > + buf[0] = kasprintf(GFP_KERNEL, "EXEC_ENV=%s", TO_MHI_EXEC_STR(ee)); > + buf[1] = NULL; > + > + if (!buf[0]) { > + dev_dbg(dev, "Failed to allocate memory for uevent"); > + return; > + } > + > + ret = kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, buf); > + if (ret) > + dev_err(dev, "Failed to send %s uevent\n", TO_MHI_EXEC_STR(ee)); > + > + kfree(buf[0]); Weird indentation. I'll fix it and also drop the redundant debug log while applying. - Mani -- மணிவண்ணன் சதாசிவம்
On Fri, 12 Sep 2025 10:29:16 +0530, Vivek.Pernamitta@quicinc.com wrote: > Notify the MHI device's Execution Environment (EE) state via uevent, > enabling applications to receive real-time updates and take appropriate > actions based on the current state of MHI. > > Applied, thanks! [1/1] bus: mhi: host: Add uevent support in MHI driver commit: f7fda4b0bd9ca6be97658bd187ac49c6cdcc0010 Best regards, -- Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
© 2016 - 2025 Red Hat, Inc.