Add QMI Device Service Request Rate-limit Option
v6 cover Add QMI Device Service Request Rate-limit Option
Certain modems, among them the Quectel Wireless Solutions Co., Ltd. (2c7c) BG96 CAT-M1/NB-IoT modem (0296), have a firmware issue where they can lock up and hang (not responding to subsequent commands) due to high QMI service request arrival rates.
QMI service request rate limiting is achieved by:
1. Adding a new, optional options structure to qmi_qmux_device_new that has its rate-limit "quirk" and minimum request period fields set when the modem "RequestThrottleTimeUs" integer property is set.
2. Adding logic to the QMI driver that, when a minimum request period is set, limits the QMI service request rate accordingly.
(1) and (2) are used by the udevng and gobi plugins such that when the modem vendor and model match 2c7c/0296, then the option to rate limit QMI service requests is set to no more than one every 2,000 us.
Grant Erickson (7):
qmi: Added enumeration for device quirk flags.
qmi: Added structure for device options.
qmi: Added device options parameter to 'qmi_qmux_device_new'.
qmi: Implement QMI service request rate limiting in 'can_write_data'.
qmi: Handle request rate limit option in 'qmi_qmux_device_new'.
udevng: Set the QMI minimum service request period for Quectel BG96
modems.
gobi: Pass QMI qmux device options to 'qmi_qmux_device_new'.
drivers/qmimodem/qmi.c | 51 +++++++++++++++++++++++++++++++++++++++++- drivers/qmimodem/qmi.h | 40 ++++++++++++++++++++++++++++++++- plugins/gobi.c | 22 +++++++++++++++++- plugins/udevng.c | 14 ++++++++++++ 4 files changed, 124 insertions(+), 3 deletions(-)
Signature · 1 line
2.45.0
PATCH v6 1/7 qmi: Added enumeration for device quirk flags.
Defines device-specific "quirks" that may alter the default behavior of the QMI driver for a specific, instantiated device.
--- drivers/qmimodem/qmi.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/qmimodem/qmi.h +18 -0
@@ -56,6 +56,24 @@ enum qmi_error { QMI_ERROR_INVALID_QMI_COMMAND = 71, }; +/** +* This defines device-specific "quirks" that may alter the default +* behavior of the QMI driver for a specific, instantiated device. +*/ +enum qmi_qmux_device_quirk { +/** +* The device has no "quirks". +*/ +QMI_QMUX_DEVICE_QUIRK_NONE =0x00 , + +/** +* The device has a "quirk" where it can lock up and hang (not +* responding to subsequent commands) due to high QMI service +* request arrival rates. +*/ +QMI_QMUX_DEVICE_QUIRK_REQ_RATE_LIMIT =0x01 +}; +typedef void (*qmi_destroy_func_t )(void *user_data);struct qmi_service ;
Signature · 1 line
2.45.0
PATCH v6 2/7 qmi: Added structure for device options.
In reply to Grant EricksonDefines options that may alter the default behavior of the QMI driver for a specific, instantiated device.
--- drivers/qmimodem/qmi.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/qmimodem/qmi.h +19 -0
@@ -74,6 +74,25 @@ enum qmi_qmux_device_quirk { QMI_QMUX_DEVICE_QUIRK_REQ_RATE_LIMIT = 0x01 }; +/** +* Defines options that may alter the default behavior of the QMI +* driver for a specific, instantiated device. +*/ +struct qmi_qmux_device_options { +/** +* Device-specific "quirk". +*/ +enum qmi_qmux_device_quirk quirks; + +/** +* If quirks has #QMI_QMUX_DEVICE_QUIRK_REQ_RATE_LIMIT set, this +* is the minimum period, in microseconds, in which back-to-back +* QMI service requests may be sent to avoid triggering a +* firmware lock up and hang. +*/ +unsigned int min_req_period_us; +}; +typedef void (*qmi_destroy_func_t )(void *user_data);struct qmi_service ;
Signature · 1 line
2.45.0
PATCH v6 3/7 qmi: Added device options parameter to 'qmi_qmux_device_new'.
In reply to Grant EricksonAn optional pointer to immutable device options that may alter the default behavior of the QMI driver for the instantiated device.
--- drivers/qmimodem/qmi.c | 3 ++- drivers/qmimodem/qmi.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/qmimodem/qmi.c +2 -1
@@ -1567,7 +1567,8 @@ static const struct qmi_transport_ops qmux_ops = { .write = qmi_qmux_device_write, }; -struct qmi_qmux_device *qmi_qmux_device_new (const char *device) +struct qmi_qmux_device *qmi_qmux_device_new (const char *device, +const struct qmi_qmux_device_options *options) {struct qmi_qmux_device *qmux;int fd;
drivers/qmimodem/qmi.h +2 -1
@@ -107,7 +107,8 @@ typedef void (*qmi_qrtr_node_lookup_done_func_t)(void *);typedef void (*qmi_service_result_func_t )(struct qmi_result *,void *); -struct qmi_qmux_device *qmi_qmux_device_new (const char *device); +struct qmi_qmux_device *qmi_qmux_device_new (const char *device, +const struct qmi_qmux_device_options *options);void qmi_qmux_device_free (struct qmi_qmux_device *qmux);void qmi_qmux_device_set_debug (struct qmi_qmux_device *qmux,qmi_debug_func_t func,void *user_data);
Signature · 1 line
2.45.0
PATCH v6 4/7 qmi: Implement QMI service request rate limiting in 'can_write_data'.
In reply to Grant EricksonDetermine if we need to rate-limit QMI services requests to a transport-specific minimum request period. If so, return true so that the queue can be retried again later.
Adds the following data members to 'qmi_transport':
* Minimum request period
- The minimum period, in microseconds, for back-to-back QMI service requests.
* Last request time
- Time, in microseconds, when the last QMI service request was sent.
to support the implementation.
--- drivers/qmimodem/qmi.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
drivers/qmimodem/qmi.c +38 -0
@@ -92,6 +92,18 @@ struct qmi_transport {const struct qmi_transport_ops *ops;struct debug_data debug; bool writer_active : 1; + +/** +* If specified via qmi_qmux_device_options, the minimum period +* for back-to-back QMI service requests. +*/ +unsigned int min_req_period_us; + +/** +* The time, in microseconds, when the last QMI service request +* was sent. +*/ +uint64_t last_req_sent_time_us; };struct qmi_qmux_device {
@@ -653,8 +665,28 @@ static bool can_write_data(struct l_io *io, void *user_data) {struct qmi_transport *transport = user_data;struct qmi_request *req; +const bool throttle_enabled = transport->min_req_period_us >0 ; +uint64_t now;int r; +/* +* Determine if we need to rate-limit commands to a +* transport-specific minimum request period. If so, +* return true so that the queue can be retried again +* later. +*/ +if (throttle_enabled) { + now =l_time_now (); + +if (transport->last_req_sent_time_us !=0 ) { +const uint64_t delta =l_time_diff (now, + transport->last_req_sent_time_us); + +if (delta < transport->min_req_period_us) +return true; + } + } + req =l_queue_pop_head (transport->req_queue);if (!req)return false;
@@ -665,6 +697,12 @@ static bool can_write_data(struct l_io *io, void *user_data)return false; } +_Pragma("GCC diagnostic push") +_Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +if (throttle_enabled) + transport->last_req_sent_time_us = now; +_Pragma("GCC diagnostic pop") +if (l_queue_length (transport->req_queue) >0 )return true;
Signature · 1 line
2.45.0
PATCH v6 5/7 qmi: Handle request rate limit option in 'qmi_qmux_device_new'.
In reply to Grant EricksonIf options are specified and QMI_QMUX_DEVICE_QUIRK_REQ_RATE_LIMIT is asserted, set the qmux transport minimum service request period from the specified options.
--- drivers/qmimodem/qmi.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/qmimodem/qmi.c +10 -0
@@ -1617,6 +1617,16 @@ struct qmi_qmux_device *qmi_qmux_device_new(const char *device, qmux = l_new(struct qmi_qmux_device, 1); +if (options !=NULL ) { +if ((options->quirks &QMI_QMUX_DEVICE_QUIRK_REQ_RATE_LIMIT ) + ==QMI_QMUX_DEVICE_QUIRK_REQ_RATE_LIMIT ) { + qmux->transport.min_req_period_us = options->min_req_period_us; + +ofono_info ("QMI minimum service request period %u us" , + qmux->transport.min_req_period_us); + } + } +if (qmi_transport_open (&qmux->transport, fd, &qmux_ops) <0 ) {close (fd);l_free (qmux);
Signature · 1 line
2.45.0
PATCH v6 6/7 udevng: Set the QMI minimum service request period for Quectel BG96 modems.
In reply to Grant EricksonThe Quectel Wireless Solutions Co., Ltd. (2c7c) BG96 CAT-M1/NB-IoT modem (0296) has a firmware issue where it can lock up and hang (not responding to subsequent commands) due to high QMI service request arrival rates. If the vendor and model match those, then rate limit QMI service requests to no more than one every 2,000 us.
--- plugins/udevng.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
plugins/udevng.c +14 -0
@@ -1118,6 +1118,20 @@ static gboolean setup_quectelqmi(struct modem_info *modem)DBG ("%s" , modem->syspath); +/* +* The Quectel Wireless Solutions Co., Ltd. (2c7c) BG96 +* CAT-M1/NB-IoT modem (0296) has a firmware issue where it can +* lock up and hang (not responding to subsequent commands) due to +* high QMI service request arrival rates. If the vendor and model +* match those, then rate limit QMI service requests to no more +* than one every 2,000 us. +*/ +if (l_streq0 (modem->vendor,"2c7c" )) { +if (l_streq0 (modem->model,"0296" )) +ofono_modem_set_integer (modem->modem, +"RequestThrottleTimeUs" ,2000 ); + } +for (list = modem->devices; list; list =g_slist_next (list)) {const struct device_info *info = list->data; const char *subsystem =
Signature · 1 line
2.45.0
PATCH v6 7/7 gobi: Pass QMI qmux device options to 'qmi_qmux_device_new'.
In reply to Grant EricksonIf the QMI minimum service request period property is set on the modem object, then set the appropriate QMI QMUX device option quirk and value.
--- plugins/gobi.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
plugins/gobi.c +21 -1
@@ -842,9 +842,19 @@ error:__shutdown_device (modem); } +/* +* Enable the modem. The following modem properties are optionally set: +* +* RequestThrottleTimeUs +* The minimum period, in microseconds, in which back-to-back * +* modem service requests may be sent. +* +*/ static int gobi_enable (struct ofono_modem *modem) {struct gobi_data *data =ofono_modem_get_data (modem); +struct qmi_qmux_device_options options = {QMI_QMUX_DEVICE_QUIRK_NONE ,0 }; +int min_req_period_us;const char *device;DBG ("%p" , modem);
@@ -853,7 +863,17 @@ static int gobi_enable(struct ofono_modem *modem)if (!device)return -EINVAL ; - data->device =qmi_qmux_device_new (device); +/* +* If the QMI minimum service request period property is set, then +* set the appropriate QMI QMUX device quirk and value. +*/ + min_req_period_us =ofono_modem_get_integer (modem,"RequestThrottleTimeUs" ); +if (min_req_period_us >0 ) { + options.quirks |=QMI_QMUX_DEVICE_QUIRK_REQ_RATE_LIMIT ; + options.min_req_period_us = min_req_period_us; + } + + data->device =qmi_qmux_device_new (device, &options);if (!data->device)return -EIO ;
Signature · 1 line
2.45.0
This series was applied to ofono.git (master) by Denis Kenzior <[email protected]>:
Hello:
This series was applied to ofono.git (master)
by Denis Kenzior <[email protected]>:
Quoted 8 lines · On Wed, 19 Mar 2025 12:22:27 -0700 you wrote:
Certain modems, among them the Quectel Wireless Solutions Co., Ltd. (2c7c) BG96 CAT-M1/NB-IoT modem (0296), have a firmware issue where they can lock up and hang (not responding to subsequent commands) due to high QMI service request arrival rates.
QMI service request rate limiting is achieved by:
[...]
Here is the summary with links:
- [v6,1/7] qmi: Added enumeration for device quirk flags.
https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=3a096f6fc033 - [v6,2/7] qmi: Added structure for device options. https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=869db3348c6b - [v6,3/7] qmi: Added device options parameter to 'qmi_qmux_device_new'. https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=c4b04bbc64e0 - [v6,4/7] qmi: Implement QMI service request rate limiting in 'can_write_data'. https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=fd68bb5082dd - [v6,5/7] qmi: Handle request rate limit option in 'qmi_qmux_device_new'. (no matching commit) - [v6,6/7] udevng: Set the QMI minimum service request period for Quectel BG96 modems. https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=e546475a1816
- [v6,7/7] gobi: Pass QMI qmux device options to 'qmi_qmux_device_new'. (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html