mhi: pci_generic: Parametrable element count for events
Subsystems (2)
PATCH v2 1/6 mhi: pci_generic: Parametrable element count for events
Not all hardwares need to use the same number of event ring elements. This change makes this parametrable.
---
v2: no change
drivers/bus/mhi/pci_generic.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/bus/mhi/pci_generic.c +10 -10
@@ -71,9 +71,9 @@ struct mhi_pci_dev_info { .doorbell_mode_switch = false, \ } -#define MHI_EVENT_CONFIG_CTRL (ev_ring) \ +#define MHI_EVENT_CONFIG_CTRL (ev_ring, el_count) \ { \ - .num_elements = 64, \ + .num_elements = el_count, \ .irq_moderation_ms = 0, \ .irq = (ev_ring) + 1, \ .priority = 1, \
@@ -114,9 +114,9 @@ struct mhi_pci_dev_info { .doorbell_mode_switch = true, \ } -#define MHI_EVENT_CONFIG_DATA (ev_ring) \ +#define MHI_EVENT_CONFIG_DATA (ev_ring, el_count) \ { \ - .num_elements = 128, \ + .num_elements = el_count, \ .irq_moderation_ms = 5, \ .irq = (ev_ring) + 1, \ .priority = 1, \
@@ -127,9 +127,9 @@ struct mhi_pci_dev_info { .offload_channel = false, \ } -#define MHI_EVENT_CONFIG_HW_DATA (ev_ring, ch_num) \ +#define MHI_EVENT_CONFIG_HW_DATA (ev_ring, el_count, ch_num) \ { \ - .num_elements = 2048, \ + .num_elements = el_count, \ .irq_moderation_ms = 1, \ .irq = (ev_ring) + 1, \ .priority = 1, \
@@ -156,12 +156,12 @@ static const struct mhi_channel_config modem_qcom_v1_mhi_channels[] = {static struct mhi_event_config modem_qcom_v1_mhi_events[] = {/* first ring is control+data ring */ -MHI_EVENT_CONFIG_CTRL (0 ), +MHI_EVENT_CONFIG_CTRL (0 ,64 ),/* DIAG dedicated event ring */ -MHI_EVENT_CONFIG_DATA (1 ), +MHI_EVENT_CONFIG_DATA (1 ,128 ),/* Hardware channels request dedicated hardware event rings */ -MHI_EVENT_CONFIG_HW_DATA (2 ,100 ), -MHI_EVENT_CONFIG_HW_DATA (3 ,101 ) +MHI_EVENT_CONFIG_HW_DATA (2 ,1024 ,100 ), +MHI_EVENT_CONFIG_HW_DATA (3 ,2048 ,101 ) };static struct mhi_controller_config modem_qcom_v1_mhiv_config = {
Signature · 1 line
2.7.4
PATCH v2 2/6 mhi: pci_generic: Introduce quectel EM1XXGR-L support
Add support for EM1XXGR-L modems, this modem series is based on SDX24 qcom chip. The modem is mainly based on MBIM protocol for both the data and control path. The drivers for these channels (mhi-net-mbim and mhi_uci) are not yet part of the kernel but will be integrated by different series.
---
v2: update timeout_ms according real modem boot time
drivers/bus/mhi/pci_generic.c | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
drivers/bus/mhi/pci_generic.c +73 -0
@@ -114,6 +114,36 @@ struct mhi_pci_dev_info { .doorbell_mode_switch = true, \ } +#define MHI_CHANNEL_CONFIG_UL_SBL (ch_num, ch_name, el_count, ev_ring) \ + { \ + .num = ch_num, \ + .name = ch_name, \ + .num_elements = el_count, \ + .event_ring = ev_ring, \ + .dir = DMA_TO_DEVICE, \ + .ee_mask = BIT(MHI_EE_SBL), \ + .pollcfg = 0, \ + .doorbell = MHI_DB_BRST_DISABLE, \ + .lpm_notify = false, \ + .offload_channel = false, \ + .doorbell_mode_switch = false, \ + } \ + +#define MHI_CHANNEL_CONFIG_DL_SBL (ch_num, ch_name, el_count, ev_ring) \ + { \ + .num = ch_num, \ + .name = ch_name, \ + .num_elements = el_count, \ + .event_ring = ev_ring, \ + .dir = DMA_FROM_DEVICE, \ + .ee_mask = BIT(MHI_EE_SBL), \ + .pollcfg = 0, \ + .doorbell = MHI_DB_BRST_DISABLE, \ + .lpm_notify = false, \ + .offload_channel = false, \ + .doorbell_mode_switch = false, \ + } +#define MHI_EVENT_CONFIG_DATA (ev_ring, el_count) \ { \ .num_elements = el_count, \
@@ -182,9 +212,52 @@ static const struct mhi_pci_dev_info mhi_qcom_sdx55_info = { .dma_data_width = 32 }; +static const struct mhi_channel_config mhi_quectel_em1xx_channels[] = { +MHI_CHANNEL_CONFIG_UL (0 ,"NMEA" ,32 ,0 ), +MHI_CHANNEL_CONFIG_DL (1 ,"NMEA" ,32 ,0 ), +MHI_CHANNEL_CONFIG_UL_SBL (2 ,"SAHARA" ,32 ,0 ), +MHI_CHANNEL_CONFIG_DL_SBL (3 ,"SAHARA" ,32 ,0 ), +MHI_CHANNEL_CONFIG_UL (4 ,"DIAG" ,32 ,1 ), +MHI_CHANNEL_CONFIG_DL (5 ,"DIAG" ,32 ,1 ), +MHI_CHANNEL_CONFIG_UL (12 ,"MBIM" ,32 ,0 ), +MHI_CHANNEL_CONFIG_DL (13 ,"MBIM" ,32 ,0 ), +MHI_CHANNEL_CONFIG_UL (32 ,"DUN" ,32 ,0 ), +MHI_CHANNEL_CONFIG_DL (33 ,"DUN" ,32 ,0 ), +MHI_CHANNEL_CONFIG_HW_UL (100 ,"IP_HW0_MBIM" ,128 ,2 ), +MHI_CHANNEL_CONFIG_HW_DL (101 ,"IP_HW0_MBIM" ,128 ,3 ), +}; + +static struct mhi_event_config mhi_quectel_em1xx_events[] = { +MHI_EVENT_CONFIG_CTRL (0 ,128 ), +MHI_EVENT_CONFIG_DATA (1 ,128 ), +MHI_EVENT_CONFIG_HW_DATA (2 ,1024 ,100 ), +MHI_EVENT_CONFIG_HW_DATA (3 ,1024 ,101 ) +}; + +static struct mhi_controller_config modem_quectel_em1xx_config = { + .max_channels =128 , + .timeout_ms =20000 , + .num_channels =ARRAY_SIZE (mhi_quectel_em1xx_channels), + .ch_cfg = mhi_quectel_em1xx_channels, + .num_events =ARRAY_SIZE (mhi_quectel_em1xx_events), + .event_cfg = mhi_quectel_em1xx_events, +}; + +static const struct mhi_pci_dev_info mhi_quectel_em1xx_info = { + .name ="quectel-em1xx" , + .edl ="qcom/prog_firehose_sdx24.mbn" , + .config = &modem_quectel_em1xx_config, + .bar_num =MHI_PCI_DEFAULT_BAR_NUM , + .dma_data_width =32 +}; +static const struct pci_device_id mhi_pci_id_table[] = { {PCI_DEVICE (PCI_VENDOR_ID_QCOM ,0x0306 ), .driver_data = (kernel_ulong_t) &mhi_qcom_sdx55_info }, + {PCI_DEVICE (0x1eac ,0x1001 ),/* EM120R-GL (sdx24) */ + .driver_data = (kernel_ulong_t) &mhi_quectel_em1xx_info }, + {PCI_DEVICE (0x1eac ,0x1002 ),/* EM160R-GL (sdx24) */ + .driver_data = (kernel_ulong_t) &mhi_quectel_em1xx_info }, { } };MODULE_DEVICE_TABLE (pci, mhi_pci_id_table);
Signature · 1 line
2.7.4
PATCH v2 3/6 mhi: pci_generic: Add SDX24 based modem support
In reply to Loic PoulainAdd generic info for SDX24 based modems. Also add the FIREHOSE channels used by the flash-programmer firmware loaded in EDL mode.
---
v2: no change
drivers/bus/mhi/pci_generic.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/bus/mhi/pci_generic.c +10 -0
@@ -212,6 +212,14 @@ static const struct mhi_pci_dev_info mhi_qcom_sdx55_info = { .dma_data_width = 32 }; +static const struct mhi_pci_dev_info mhi_qcom_sdx24_info = { + .name ="qcom-sdx24" , + .edl ="qcom/prog_firehose_sdx24.mbn" , + .config = &modem_qcom_v1_mhiv_config, + .bar_num =MHI_PCI_DEFAULT_BAR_NUM , + .dma_data_width =32 +}; +static const struct mhi_channel_config mhi_quectel_em1xx_channels[] = {MHI_CHANNEL_CONFIG_UL (0 ,"NMEA" ,32 ,0 ),MHI_CHANNEL_CONFIG_DL (1 ,"NMEA" ,32 ,0 ),
@@ -254,6 +262,8 @@ static const struct mhi_pci_dev_info mhi_quectel_em1xx_info = {static const struct pci_device_id mhi_pci_id_table[] = { {PCI_DEVICE (PCI_VENDOR_ID_QCOM ,0x0306 ), .driver_data = (kernel_ulong_t) &mhi_qcom_sdx55_info }, + {PCI_DEVICE (PCI_VENDOR_ID_QCOM ,0x0304 ), + .driver_data = (kernel_ulong_t) &mhi_qcom_sdx24_info }, {PCI_DEVICE (0x1eac ,0x1001 ),/* EM120R-GL (sdx24) */ .driver_data = (kernel_ulong_t) &mhi_quectel_em1xx_info }, {PCI_DEVICE (0x1eac ,0x1002 ),/* EM160R-GL (sdx24) */
Signature · 1 line
2.7.4
PATCH v2 4/6 mhi: pci_generic: No-Op for device_wake operations
In reply to Loic PoulainThe wake_db register presence is highly speculative and can fuze MHI devices. Indeed, currently the wake_db register address is defined at entry 127 of the 'Channel doorbell array', thus writing to this address is equivalent to ringing the doorbell for channel 127, causing trouble with some devics (e.g. SDX24 based modems) that get an unexpected channel 127 doorbell interrupt.
This change fixes that issue by setting wake get/put as no-op for pci_generic devices. The wake device sideband mechanism seems really specific to each device, and is AFAIK not defined by the MHI spec.
It also removes zeroing initialization of wake_db register during MMIO initialization, the register being set via wake_get/put accessors few cycles later during M0 transition.
---
v2: reword commit message
drivers/bus/mhi/core/init.c | 2 -- drivers/bus/mhi/pci_generic.c | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)
drivers/bus/mhi/core/init.c +0 -2
@@ -510,8 +510,6 @@ int mhi_init_mmio(struct mhi_controller *mhi_cntrl)/* Setup wake db */ mhi_cntrl->wake_db = base + val + (8 *MHI_DEV_WAKE_DB ); -mhi_write_reg (mhi_cntrl, mhi_cntrl->wake_db,4 ,0 ); -mhi_write_reg (mhi_cntrl, mhi_cntrl->wake_db,0 ,0 ); mhi_cntrl->wake_set = false;/* Setup channel db address for each channel in tre_ring */
drivers/bus/mhi/pci_generic.c +18 -0
@@ -312,6 +312,21 @@ static void mhi_pci_status_cb(struct mhi_controller *mhi_cntrl, } } +static void mhi_pci_wake_get_nop (struct mhi_controller *mhi_cntrl,bool force) +{ +/* no-op */ +} + +static void mhi_pci_wake_put_nop (struct mhi_controller *mhi_cntrl,bool override) +{ +/* no-op */ +} + +static void mhi_pci_wake_toggle_nop (struct mhi_controller *mhi_cntrl) +{ +/* no-op */ +} +static bool mhi_pci_is_alive (struct mhi_controller *mhi_cntrl) {struct pci_dev *pdev =to_pci_dev (mhi_cntrl->cntrl_dev);
@@ -515,6 +530,9 @@ static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) mhi_cntrl->status_cb = mhi_pci_status_cb; mhi_cntrl->runtime_get = mhi_pci_runtime_get; mhi_cntrl->runtime_put = mhi_pci_runtime_put; + mhi_cntrl->wake_get = mhi_pci_wake_get_nop; + mhi_cntrl->wake_put = mhi_pci_wake_put_nop; + mhi_cntrl->wake_toggle = mhi_pci_wake_toggle_nop; err =mhi_pci_claim (mhi_cntrl, info->bar_num,DMA_BIT_MASK (info->dma_data_width));if (err)
Signature · 1 line
2.7.4
Re: [PATCH v2 4/6] mhi: pci_generic: No-Op for device_wake operations
Quoted 11 lines · Loic Poulain
The
wake_dbregister presence is highly speculative and can fuze MHI devices. Indeed, currently thewake_dbregister address is defined at entry 127 of the 'Channel doorbell array', thus writing to this address is equivalent to ringing the doorbell for channel 127, causing trouble with some devics (e.g. SDX24 based modems) that get an unexpected channel 127 doorbell interrupt.This change fixes that issue by setting wake get/put as no-op for
pci_genericdevices. The wake device sideband mechanism seems really specific to each device, and is AFAIK not defined by the MHI spec.
Quoted 5 lines
It also removes zeroing initialization of
wake_dbregister during MMIO initialization, the register being set via wake_get/put accessors few cycles later during M0 transition.Signed-off-by Loic Poulain <[email protected]>
Thanks,
Mani
Quoted 59 lines
---
v2: reword commit messagedrivers/bus/mhi/core/init.c | 2 -- drivers/bus/mhi/pci_generic.c | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)drivers/bus/mhi/core/init.c +0
-2@@ -510,8 +510,6 @@ int mhi_init_mmio(struct mhi_controller *mhi_cntrl)/* Setup wake db */ mhi_cntrl->wake_db = base + val + (8 *MHI_DEV_WAKE_DB ); -mhi_write_reg (mhi_cntrl, mhi_cntrl->wake_db,4 ,0 ); -mhi_write_reg (mhi_cntrl, mhi_cntrl->wake_db,0 ,0 ); mhi_cntrl->wake_set = false;/* Setup channel db address for each channel in tre_ring */ drivers/bus/mhi/pci_generic.c +18
-0@@ -312,6 +312,21 @@ static void mhi_pci_status_cb(struct mhi_controller *mhi_cntrl, } } +static void mhi_pci_wake_get_nop (struct mhi_controller *mhi_cntrl,bool force) +{ +/* no-op */ +} + +static void mhi_pci_wake_put_nop (struct mhi_controller *mhi_cntrl,bool override) +{ +/* no-op */ +} + +static void mhi_pci_wake_toggle_nop (struct mhi_controller *mhi_cntrl) +{ +/* no-op */ +} +static bool mhi_pci_is_alive (struct mhi_controller *mhi_cntrl) {struct pci_dev *pdev =to_pci_dev (mhi_cntrl->cntrl_dev);@@ -515,6 +530,9 @@ static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) mhi_cntrl->status_cb = mhi_pci_status_cb; mhi_cntrl->runtime_get = mhi_pci_runtime_get; mhi_cntrl->runtime_put = mhi_pci_runtime_put; + mhi_cntrl->wake_get = mhi_pci_wake_get_nop; + mhi_cntrl->wake_put = mhi_pci_wake_put_nop; + mhi_cntrl->wake_toggle = mhi_pci_wake_toggle_nop; err =mhi_pci_claim (mhi_cntrl, info->bar_num,DMA_BIT_MASK (info->dma_data_width));if (err)Signature · 1 line
2.7.4
Manivannan Sadhasivam
AppliedRe: [PATCH v2 4/6] mhi: pci_generic: No-Op for device_wake operations
In reply to Loic PoulainQuoted 11 lines · Loic Poulain
The
wake_dbregister presence is highly speculative and can fuze MHI devices. Indeed, currently thewake_dbregister address is defined at entry 127 of the 'Channel doorbell array', thus writing to this address is equivalent to ringing the doorbell for channel 127, causing trouble with some devics (e.g. SDX24 based modems) that get an unexpected channel 127 doorbell interrupt.This change fixes that issue by setting wake get/put as no-op for
pci_genericdevices. The wake device sideband mechanism seems really specific to each device, and is AFAIK not defined by the MHI spec.
Quoted 5 lines
It also removes zeroing initialization of
wake_dbregister during MMIO initialization, the register being set via wake_get/put accessors few cycles later during M0 transition.Signed-off-by Loic Poulain <[email protected]>
Applied to mhi-next!
Thanks,
Mani
Quoted 59 lines
---
v2: reword commit messagedrivers/bus/mhi/core/init.c | 2 -- drivers/bus/mhi/pci_generic.c | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)drivers/bus/mhi/core/init.c +0
-2@@ -510,8 +510,6 @@ int mhi_init_mmio(struct mhi_controller *mhi_cntrl)/* Setup wake db */ mhi_cntrl->wake_db = base + val + (8 *MHI_DEV_WAKE_DB ); -mhi_write_reg (mhi_cntrl, mhi_cntrl->wake_db,4 ,0 ); -mhi_write_reg (mhi_cntrl, mhi_cntrl->wake_db,0 ,0 ); mhi_cntrl->wake_set = false;/* Setup channel db address for each channel in tre_ring */ drivers/bus/mhi/pci_generic.c +18
-0@@ -312,6 +312,21 @@ static void mhi_pci_status_cb(struct mhi_controller *mhi_cntrl, } } +static void mhi_pci_wake_get_nop (struct mhi_controller *mhi_cntrl,bool force) +{ +/* no-op */ +} + +static void mhi_pci_wake_put_nop (struct mhi_controller *mhi_cntrl,bool override) +{ +/* no-op */ +} + +static void mhi_pci_wake_toggle_nop (struct mhi_controller *mhi_cntrl) +{ +/* no-op */ +} +static bool mhi_pci_is_alive (struct mhi_controller *mhi_cntrl) {struct pci_dev *pdev =to_pci_dev (mhi_cntrl->cntrl_dev);@@ -515,6 +530,9 @@ static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) mhi_cntrl->status_cb = mhi_pci_status_cb; mhi_cntrl->runtime_get = mhi_pci_runtime_get; mhi_cntrl->runtime_put = mhi_pci_runtime_put; + mhi_cntrl->wake_get = mhi_pci_wake_get_nop; + mhi_cntrl->wake_put = mhi_pci_wake_put_nop; + mhi_cntrl->wake_toggle = mhi_pci_wake_toggle_nop; err =mhi_pci_claim (mhi_cntrl, info->bar_num,DMA_BIT_MASK (info->dma_data_width));if (err)Signature · 1 line
2.7.4
PATCH v2 5/6 mhi: pci_generic: Use generic PCI power management
In reply to Loic PoulainThe PCI core can take care of proper PCI suspend/resume operations, but this is discarded when the driver saves PCI state by its own. This currently prevents the PCI core to enable PME (for modem initiated D3 exit) which is requested for proper runtime pm support.
This change deletes explicit PCI state-saving and state-set from suspend callback, letting the PCI doing the appropriate work.
---
v2: no change
drivers/bus/mhi/pci_generic.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/bus/mhi/pci_generic.c +7 -7
@@ -544,9 +544,12 @@ static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)pci_set_drvdata (pdev, mhi_pdev); -/* Have stored pci confspace at hand for restore in sudden PCI error */ +/* Have stored pci confspace at hand for restore in sudden PCI error. +* cache the state locally and discard the PCI core one. +*/ pci_save_state (pdev); mhi_pdev->pci_state =pci_store_saved_state (pdev); +pci_load_saved_state (pdev,NULL );pci_enable_pcie_error_reporting (pdev);
@@ -717,10 +720,8 @@ static int __maybe_unused mhi_pci_suspend(struct device *dev)/* Transition to M3 state */ mhi_pm_suspend (mhi_cntrl); -pci_save_state (pdev);pci_disable_device (pdev);pci_wake_from_d3 (pdev, true); -pci_set_power_state (pdev, PCI_D3hot);return 0 ; }
@@ -732,14 +733,13 @@ static int __maybe_unused mhi_pci_resume(struct device *dev)struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;int err; -pci_set_power_state (pdev,PCI_D0 ); -pci_restore_state (pdev); -pci_set_master (pdev); - err =pci_enable_device (pdev);if (err) goto err_recovery; +pci_set_master (pdev); +pci_wake_from_d3 (pdev, false); +/* Exit M3, transition to M0 state */ err =mhi_pm_resume (mhi_cntrl);if (err) {
Signature · 1 line
2.7.4
Re: [PATCH v2 5/6] mhi: pci_generic: Use generic PCI power management
Quoted 9 lines · Loic Poulain
The PCI core can take care of proper PCI suspend/resume operations, but this is discarded when the driver saves PCI state by its own. This currently prevents the PCI core to enable PME (for modem initiated D3 exit) which is requested for proper runtime pm support.
This change deletes explicit PCI state-saving and state-set from suspend callback, letting the PCI doing the appropriate work.
Signed-off-by Loic Poulain <[email protected]>
Thanks,
Mani
Quoted 56 lines
---
v2: no changedrivers/bus/mhi/pci_generic.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)drivers/bus/mhi/pci_generic.c +7
-7@@ -544,9 +544,12 @@ static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)pci_set_drvdata (pdev, mhi_pdev); -/* Have stored pci confspace at hand for restore in sudden PCI error */ +/* Have stored pci confspace at hand for restore in sudden PCI error. +* cache the state locally and discard the PCI core one. +*/ pci_save_state (pdev); mhi_pdev->pci_state =pci_store_saved_state (pdev); +pci_load_saved_state (pdev,NULL );pci_enable_pcie_error_reporting (pdev);@@ -717,10 +720,8 @@ static int __maybe_unused mhi_pci_suspend(struct device *dev)/* Transition to M3 state */ mhi_pm_suspend (mhi_cntrl); -pci_save_state (pdev);pci_disable_device (pdev);pci_wake_from_d3 (pdev, true); -pci_set_power_state (pdev, PCI_D3hot);return 0 ; }@@ -732,14 +733,13 @@ static int __maybe_unused mhi_pci_resume(struct device *dev)struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;int err; -pci_set_power_state (pdev,PCI_D0 ); -pci_restore_state (pdev); -pci_set_master (pdev); - err =pci_enable_device (pdev);if (err) goto err_recovery; +pci_set_master (pdev); +pci_wake_from_d3 (pdev, false); +/* Exit M3, transition to M0 state */ err =mhi_pm_resume (mhi_cntrl);if (err) {Signature · 1 line
2.7.4
PATCH v2 6/6 mhi: pci_generic: Add support for runtime PM
In reply to Loic PoulainWhen the device is idle it is possible to move it into the lowest MHI PM state (M3). In that mode, all MHI operations are suspended and the PCI device can be safely put into PCI D3 state.
The device is then resumed from D3/M3 either because of host initiated MHI operation (e.g. buffer TX) or because the device (modem) has triggered wake-up via PME feature (e.g. on incoming data).
Same procedures can be used for system wide or runtime suspend/resume.
---
v2: replace force_runtime_suspend/resume via local function to ensure
device is always resumed during system resume whatever its runtime pm state.
drivers/bus/mhi/pci_generic.c | 95 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 9 deletions(-)
drivers/bus/mhi/pci_generic.c +86 -9
@@ -14,6 +14,7 @@#include <linux/mhi.h> #include <linux/module.h> #include <linux/pci.h> +#include <linux/pm_runtime.h> #include <linux/timer.h> #include <linux/workqueue.h>
@@ -274,6 +275,7 @@ MODULE_DEVICE_TABLE(pci, mhi_pci_id_table);enum mhi_pci_device_status {MHI_PCI_DEV_STARTED , +MHI_PCI_DEV_SUSPENDED , };struct mhi_pci_device {
@@ -306,6 +308,11 @@ static void mhi_pci_status_cb(struct mhi_controller *mhi_cntrl,case MHI_CB_FATAL_ERROR :case MHI_CB_SYS_ERROR :dev_warn (&pdev->dev,"firmware crashed (%u)\n" , cb); +pm_runtime_forbid (&pdev->dev); +break ; +case MHI_CB_EE_MISSION_MODE : +pm_runtime_mark_last_busy (&pdev->dev); +pm_runtime_allow (&pdev->dev);break ;default :break ;
@@ -427,13 +434,19 @@ static int mhi_pci_get_irqs(struct mhi_controller *mhi_cntrl,static int mhi_pci_runtime_get (struct mhi_controller *mhi_cntrl) { -/* no PM for now */ -return 0 ; +/* The runtime_get() MHI callback means: +* Do whatever is requested to leave M3. +*/ +return pm_runtime_get (mhi_cntrl->cntrl_dev); }static void mhi_pci_runtime_put (struct mhi_controller *mhi_cntrl) { -/* no PM for now */ +/* The runtime_put() MHI callback means: +* Device can be moved in M3 state. +*/ +pm_runtime_mark_last_busy (mhi_cntrl->cntrl_dev); +pm_runtime_put (mhi_cntrl->cntrl_dev); }static void mhi_pci_recovery_work (struct work_struct *work)
@@ -447,6 +460,7 @@ static void mhi_pci_recovery_work(struct work_struct *work)dev_warn (&pdev->dev,"device recovery started\n" );del_timer (&mhi_pdev->health_check_timer); +pm_runtime_forbid (&pdev->dev);/* Clean up MHI state */ if (test_and_clear_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status)) {
@@ -454,7 +468,6 @@ static void mhi_pci_recovery_work(struct work_struct *work)mhi_unprepare_after_power_down (mhi_cntrl); } -/* Check if we can recover without full reset */ pci_set_power_state (pdev,PCI_D0 );pci_load_saved_state (pdev, mhi_pdev->pci_state);pci_restore_state (pdev);
@@ -488,6 +501,10 @@ static void health_check(struct timer_list *t)struct mhi_pci_device *mhi_pdev =from_timer (mhi_pdev, t, health_check_timer);struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl; +if (!test_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status) || +test_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status)) +return ; +if (!mhi_pci_is_alive (mhi_cntrl)) {dev_err (mhi_cntrl->cntrl_dev,"Device died\n" );queue_work (system_long_wq, &mhi_pdev->recovery_work);
@@ -575,6 +592,14 @@ static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)/* start health check */ mod_timer (&mhi_pdev->health_check_timer, jiffies +HEALTH_CHECK_PERIOD ); +/* Only allow runtime-suspend if PME capable (for wakeup) */ +if (pci_pme_capable (pdev, PCI_D3hot)) { +pm_runtime_set_autosuspend_delay (&pdev->dev,2000 ); +pm_runtime_use_autosuspend (&pdev->dev); +pm_runtime_mark_last_busy (&pdev->dev); +pm_runtime_put_noidle (&pdev->dev); + } +return 0 ; err_unprepare:
@@ -598,6 +623,10 @@ static void mhi_pci_remove(struct pci_dev *pdev)mhi_unprepare_after_power_down (mhi_cntrl); } +/* balancing probe put_noidle */ +if (pci_pme_capable (pdev, PCI_D3hot)) +pm_runtime_get_noresume (&pdev->dev); +mhi_unregister_controller (mhi_cntrl); }
@@ -708,31 +737,48 @@ static const struct pci_error_handlers mhi_pci_err_handler = { .reset_done = mhi_pci_reset_done, }; -static int __maybe_unused mhi_pci_suspend (struct device *dev) +static int __maybe_unused mhi_pci_runtime_suspend (struct device *dev) {struct pci_dev *pdev =to_pci_dev (dev);struct mhi_pci_device *mhi_pdev =dev_get_drvdata (dev);struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl; +int err; + +if (test_and_set_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status)) +return 0 ;del_timer (&mhi_pdev->health_check_timer);cancel_work_sync (&mhi_pdev->recovery_work); +if (!test_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status) || + mhi_cntrl->ee !=MHI_EE_AMSS ) + goto pci_suspend;/* Nothing to do at MHI level */ +/* Transition to M3 state */ -mhi_pm_suspend (mhi_cntrl); + err =mhi_pm_suspend (mhi_cntrl); +if (err) { +dev_err (&pdev->dev,"failed to suspend device: %d;\n" , err); +clear_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status); +return -EBUSY ; + } +pci_suspend:pci_disable_device (pdev);pci_wake_from_d3 (pdev, true);return 0 ; } -static int __maybe_unused mhi_pci_resume (struct device *dev) +static int __maybe_unused mhi_pci_runtime_resume (struct device *dev) {struct pci_dev *pdev =to_pci_dev (dev);struct mhi_pci_device *mhi_pdev =dev_get_drvdata (dev);struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;int err; +if (!test_and_clear_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status)) +return 0 ; + err =pci_enable_device (pdev);if (err) goto err_recovery;
@@ -740,6 +786,13 @@ static int __maybe_unused mhi_pci_resume(struct device *dev)pci_set_master (pdev);pci_wake_from_d3 (pdev, false); +/* It can be a remote wakeup (no mhi runtime_get), update access time */ +pm_runtime_mark_last_busy (dev); + +if (!test_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status) || + mhi_cntrl->ee !=MHI_EE_AMSS ) +return 0 ;/* Nothing to do at MHI level */ +/* Exit M3, transition to M0 state */ err =mhi_pm_resume (mhi_cntrl);if (err) {
@@ -753,13 +806,37 @@ static int __maybe_unused mhi_pci_resume(struct device *dev)return 0 ; err_recovery: -/* The device may have loose power or crashed, try recovering it */ +/* Do not fail to not mess up our PCI device state, the device likely +* lost power (d3cold) and we simply need to reset it from the recovery +* procedure, trigger the recovery asynchronously to prevent system +* suspend exit delaying. +*/ queue_work (system_long_wq, &mhi_pdev->recovery_work); -return err; +return 0 ; +} + +static int __maybe_unused mhi_pci_suspend (struct device *dev) +{ +pm_runtime_disable (dev); +return mhi_pci_runtime_suspend (dev); +} + +static int __maybe_unused mhi_pci_resume (struct device *dev) +{ +int ret; + +/* Depending the platform, device may have lost power (d3cold), we need +* to resume it now to check its state and recover when necessary. +*/ + ret =mhi_pci_runtime_resume (dev); +pm_runtime_enable (dev); + +return ret; }static const struct dev_pm_ops mhi_pci_pm_ops = { + SET_RUNTIME_PM_OPS(mhi_pci_runtime_suspend, mhi_pci_runtime_resume, NULL)SET_SYSTEM_SLEEP_PM_OPS (mhi_pci_suspend, mhi_pci_resume) };
Signature · 1 line
2.7.4
Re: [PATCH v2 6/6] mhi: pci_generic: Add support for runtime PM
Quoted 40 lines · Loic Poulain
When the device is idle it is possible to move it into the lowest MHI PM state (M3). In that mode, all MHI operations are suspended and the PCI device can be safely put into PCI D3 state.
The device is then resumed from D3/M3 either because of host initiated MHI operation (e.g. buffer TX) or because the device (modem) has triggered wake-up via PME feature (e.g. on incoming data).
Same procedures can be used for system wide or runtime suspend/resume.
Signed-off-by Loic Poulain <[email protected]>---
v2: replace force_runtime_suspend/resume via local function to ensure
device is always resumed during system resume whatever its runtime pm state.drivers/bus/mhi/pci_generic.c | 95 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 9 deletions(-)drivers/bus/mhi/pci_generic.c +2
-0@@ -14,6 +14,7 @@#include <linux/mhi.h> #include <linux/module.h> #include <linux/pci.h> +#include <linux/pm_runtime.h> #include <linux/timer.h> #include <linux/workqueue.h> @@ -274,6 +275,7 @@ MODULE_DEVICE_TABLE(pci, mhi_pci_id_table);enum mhi_pci_device_status {MHI_PCI_DEV_STARTED , +MHI_PCI_DEV_SUSPENDED , };struct mhi_pci_device {
drivers/bus/mhi/pci_generic.c static void mhi_pci_status_cb(struct mhi_controller *mhi_cntrl, · line 314
Quoted 7 lines
drivers/bus/mhi/pci_generic.c +4
-0@@ -306,6 +308,11 @@ static void mhi_pci_status_cb(struct mhi_controller *mhi_cntrl,case MHI_CB_FATAL_ERROR :case MHI_CB_SYS_ERROR :dev_warn (&pdev->dev,"firmware crashed (%u)\n" , cb); +pm_runtime_forbid (&pdev->dev); +break ; +case MHI_CB_EE_MISSION_MODE : +pm_runtime_mark_last_busy (&pdev->dev);
Do you really need to update the last_busy time here? You're already updating it before each runtime_put() call and those will overwrite this value.
Quoted 5 lines
drivers/bus/mhi/pci_generic.c +1
-0+pm_runtime_allow (&pdev->dev);break ;default :break ;@@ -427,13 +434,19 @@ static int mhi_pci_get_irqs(struct mhi_controller *mhi_cntrl,
[...]
Quoted 13 lines
drivers/bus/mhi/pci_generic.c +5
-1-static int __maybe_unused mhi_pci_suspend (struct device *dev) +static int __maybe_unused mhi_pci_runtime_suspend (struct device *dev) {struct pci_dev *pdev =to_pci_dev (dev);struct mhi_pci_device *mhi_pdev =dev_get_drvdata (dev);struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl; +int err; + +if (test_and_set_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status)) +return 0 ;del_timer (&mhi_pdev->health_check_timer);cancel_work_sync (&mhi_pdev->recovery_work);
drivers/bus/mhi/pci_generic.c static const struct pci_error_handlers mhi_pci_err_handler = { · line 760
Quoted 10 lines
drivers/bus/mhi/pci_generic.c +7
-1+if (!test_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status) || + mhi_cntrl->ee !=MHI_EE_AMSS ) + goto pci_suspend;/* Nothing to do at MHI level */ +/* Transition to M3 state */ -mhi_pm_suspend (mhi_cntrl); + err =mhi_pm_suspend (mhi_cntrl); +if (err) { +dev_err (&pdev->dev,"failed to suspend device: %d;\n" , err);
Remove the semicolon after "%d"
Quoted 26 lines
drivers/bus/mhi/pci_generic.c +8
-1+clear_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status); +return -EBUSY ; + } +pci_suspend:pci_disable_device (pdev);pci_wake_from_d3 (pdev, true);return 0 ; } -static int __maybe_unused mhi_pci_resume (struct device *dev) +static int __maybe_unused mhi_pci_runtime_resume (struct device *dev) {struct pci_dev *pdev =to_pci_dev (dev);struct mhi_pci_device *mhi_pdev =dev_get_drvdata (dev);struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;int err; +if (!test_and_clear_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status)) +return 0 ; + err =pci_enable_device (pdev);if (err) goto err_recovery;
drivers/bus/mhi/pci_generic.c static int __maybe_unused mhi_pci_resume(struct device *dev) · line 790
Quoted 5 lines
drivers/bus/mhi/pci_generic.c +2
-0@@ -740,6 +786,13 @@ static int __maybe_unused mhi_pci_resume(struct device *dev)pci_set_master (pdev);pci_wake_from_d3 (pdev, false); +/* It can be a remote wakeup (no mhi runtime_get), update access time */ +pm_runtime_mark_last_busy (dev);
I think this should be moved after mhi_pm_resume().
Thanks,
Mani
Re: [PATCH v2 6/6] mhi: pci_generic: Add support for runtime PM
Hi Mani,
Quoted 40 lines · Manivannan Sadhasivam
Quoted 38 lines · Loic Poulain
When the device is idle it is possible to move it into the lowest MHI PM state (M3). In that mode, all MHI operations are suspended and the PCI device can be safely put into PCI D3 state.
The device is then resumed from D3/M3 either because of host initiated MHI operation (e.g. buffer TX) or because the device (modem) has triggered wake-up via PME feature (e.g. on incoming data).
Same procedures can be used for system wide or runtime suspend/resume.
Signed-off-by Loic Poulain <[email protected]>---
v2: replace force_runtime_suspend/resume via local function to ensure
device is always resumed during system resume whatever its runtime pm state.drivers/bus/mhi/pci_generic.c | 95 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 9 deletions(-)drivers/bus/mhi/pci_generic.c +2
-0@@ -14,6 +14,7 @@#include <linux/mhi.h> #include <linux/module.h> #include <linux/pci.h> +#include <linux/pm_runtime.h> #include <linux/timer.h> #include <linux/workqueue.h> @@ -274,6 +275,7 @@ MODULE_DEVICE_TABLE(pci, mhi_pci_id_table);enum mhi_pci_device_status {MHI_PCI_DEV_STARTED , +MHI_PCI_DEV_SUSPENDED , };
Quoted 12 lines
drivers/bus/mhi/pci_generic.c static void mhi_pci_status_cb(struct mhi_controller *mhi_cntrl, · line 314
Quoted 9 lines
drivers/bus/mhi/pci_generic.c +4
-0struct mhi_pci_device {@@ -306,6 +308,11 @@ static void mhi_pci_status_cb(struct mhi_controller *mhi_cntrl,case MHI_CB_FATAL_ERROR :case MHI_CB_SYS_ERROR :dev_warn (&pdev->dev,"firmware crashed (%u)\n" , cb); +pm_runtime_forbid (&pdev->dev); +break ; +case MHI_CB_EE_MISSION_MODE : +pm_runtime_mark_last_busy (&pdev->dev);Do you really need to update the
last_busytime here? You're already updating it before eachruntime_put()call and those will overwrite this value.
Right, it is not strictly necessary.
Quoted 23 lines
Quoted 6 lines
drivers/bus/mhi/pci_generic.c +1
-0+pm_runtime_allow (&pdev->dev);break ;default :break ;@@ -427,13 +434,19 @@ static int mhi_pci_get_irqs(struct mhi_controller *mhi_cntrl,[...]
Quoted 14 lines
drivers/bus/mhi/pci_generic.c +5
-1-static int __maybe_unused mhi_pci_suspend (struct device *dev) +static int __maybe_unused mhi_pci_runtime_suspend (struct device *dev) {struct pci_dev *pdev =to_pci_dev (dev);struct mhi_pci_device *mhi_pdev =dev_get_drvdata (dev);struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl; +int err; + +if (test_and_set_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status)) +return 0 ;del_timer (&mhi_pdev->health_check_timer);cancel_work_sync (&mhi_pdev->recovery_work);
Quoted 11 lines
drivers/bus/mhi/pci_generic.c static const struct pci_error_handlers mhi_pci_err_handler = { · line 760
Quoted 9 lines
drivers/bus/mhi/pci_generic.c +7
-1+if (!test_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status) || + mhi_cntrl->ee !=MHI_EE_AMSS ) + goto pci_suspend;/* Nothing to do at MHI level */ +/* Transition to M3 state */ -mhi_pm_suspend (mhi_cntrl); + err =mhi_pm_suspend (mhi_cntrl); +if (err) { +dev_err (&pdev->dev,"failed to suspend device: %d;\n" , err);Remove the semicolon after "%d"
OK.
Quoted 30 lines
Quoted 30 lines
drivers/bus/mhi/pci_generic.c +8
-1+clear_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status); +return -EBUSY ; + } +pci_suspend:pci_disable_device (pdev);pci_wake_from_d3 (pdev, true);return 0 ; } -static int __maybe_unused mhi_pci_resume (struct device *dev) +static int __maybe_unused mhi_pci_runtime_resume (struct device *dev) {struct pci_dev *pdev =to_pci_dev (dev);struct mhi_pci_device *mhi_pdev =dev_get_drvdata (dev);struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;int err; +if (!test_and_clear_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status)) +return 0 ; + err =pci_enable_device (pdev);if (err) goto err_recovery;@@ -740,6 +786,13 @@ static int __maybe_unused mhi_pci_resume(struct device *dev)pci_set_master (pdev);pci_wake_from_d3 (pdev, false);
Quoted 4 lines
drivers/bus/mhi/pci_generic.c static int __maybe_unused mhi_pci_resume(struct device *dev) · line 790
Quoted 2 lines
drivers/bus/mhi/pci_generic.c +2
-0+/* It can be a remote wakeup (no mhi runtime_get), update access time */ +pm_runtime_mark_last_busy (dev);I think this should be moved after
mhi_pm_resume().
you're right.
Loic
Quoted 3 lines
Thanks,
Mani