Add QMI Device Service Request Rate-limit Option
v3 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 | 45 +++++++++++++++++++++++++++++++++++++++++- drivers/qmimodem/qmi.h | 40 ++++++++++++++++++++++++++++++++++++- plugins/gobi.c | 22 ++++++++++++++++++++- plugins/udevng.c | 14 +++++++++++++ 4 files changed, 118 insertions(+), 3 deletions(-)
Signature · 1 line
2.45.0
PATCH v3 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 v3 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 v3 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 v3 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 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/qmimodem/qmi.c +32 -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,25 @@ 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 =0 ; +uint64_t delta;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 && transport->last_req_sent_time_us !=0 ) { + now =l_time_now (); + 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 +694,9 @@ static bool can_write_data(struct l_io *io, void *user_data)return false; } +if (throttle_enabled) + transport->last_req_sent_time_us = now; +if (l_queue_length (transport->req_queue) >0 )return true;
Signature · 1 line
2.45.0
PATCH v3 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
@@ -1611,6 +1611,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 v3 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 v3 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
Re: [PATCH v3 4/7] qmi: Implement QMI service request rate limiting in 'can_write_data'.
In reply to Grant EricksonHi Grant,
drivers/qmimodem/qmi.c static bool can_write_data(struct l_io *io, void *user_data) · line 669
Quoted 7 lines
struct qmi_qmux_device {drivers/qmimodem/qmi.c +2
-0@@ -653,8 +665,25 @@ 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 =0 ;
I think this is still wrong? There's a reason why we have doc/coding-style.txt item M7.
drivers/qmimodem/qmi.c static bool can_write_data(struct l_io *io, void *user_data) · line 679
Quoted 10 lines
drivers/qmimodem/qmi.c +8
-0+uint64_t delta;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 && transport->last_req_sent_time_us !=0 ) {
Consider the starting condition:
- last_req_sent_time_us -> zero
- throttle_enabled -> true
We don't enter into this if(), 'now' is still zero.
Quoted 11 lines
drivers/qmimodem/qmi.c +7
-0+ now =l_time_now (); + 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;
drivers/qmimodem/qmi.c static bool can_write_data(struct l_io *io, void *user_data) · line 699
Quoted 6 lines
drivers/qmimodem/qmi.c +3
-0@@ -665,6 +694,9 @@ static bool can_write_data(struct l_io *io, void *user_data)return false; } +if (throttle_enabled) + transport->last_req_sent_time_us = now; +
throttle_enabled is true, we set last_req_sent_time_us to 0. In effect your throttling doesn't work...?
drivers/qmimodem/qmi.c static bool can_write_data(struct l_io *io, void *user_data) · line 702
Quoted 3 lines
drivers/qmimodem/qmi.c +0
-0if (l_queue_length (transport->req_queue) >0 )return true;
Regards,
-Denis
Re: [PATCH v3 4/7] qmi: Implement QMI service request rate limiting in 'can_write_data'.
Quoted 41 lines · Denis Kenzior
Hi Grant,
drivers/qmimodem/qmi.c static bool can_write_data(struct l_io *io, void *user_data) · line 669
Quoted 7 lines
struct qmi_qmux_device {drivers/qmimodem/qmi.c +2
-0@@ -653,8 +665,25 @@ 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 =0 ;I think this is still wrong? There's a reason why we have
doc/coding-style.txtitem M7.drivers/qmimodem/qmi.c static bool can_write_data(struct l_io *io, void *user_data) · line 679
Quoted 9 lines
drivers/qmimodem/qmi.c +7
-0+uint64_t delta;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 && transport->last_req_sent_time_us != 0) {Consider the starting condition:
-
last_req_sent_time_us-> zero
-throttle_enabled-> trueWe don't enter into this
if(), 'now' is still zero.Quoted 10 lines
drivers/qmimodem/qmi.c +7
-0+ now =l_time_now (); + 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;
Quoted 8 lines
drivers/qmimodem/qmi.c static bool can_write_data(struct l_io *io, void *user_data) · line 698
Quoted 6 lines
drivers/qmimodem/qmi.c +2
-0@@ -665,6 +694,9 @@ static bool can_write_data(struct l_io *io, void *user_data)return false; } + if (throttle_enabled) + transport->last_req_sent_time_us = now; +
throttle_enabledis true, we setlast_req_sent_time_usto 0. In effect your throttling doesn't work...?
Confirmed, thanks. v4 submitted.
I’ve noted that the default ofono warning flags do not highlight the potential conditional issue with ’now’ on arm, aarch64, or x86_64 with gcc or clang. If I dial up warnings with -Wall -Wextra -Weverything, then I get the warning.
With that in mind, do you want ’now’ to follow M7 with the default warning flag set or to not follow M7 but ensuring the warning is addressed using default initialization with a non-default set of warning flags?
Best,
Grant
Signature · 5 lines
Principal Nuovations [email protected] https://www.nuovations.com/
Re: [PATCH v3 4/7] qmi: Implement QMI service request rate limiting in 'can_write_data'.
Hi Grant,
Quoted 2 lines
I’ve noted that the default ofono warning flags do not highlight the potential conditional issue with ’now’ on arm, aarch64, or
x86_64with gcc or clang. If I dial up warnings with -Wall -Wextra -Weverything, then I get the warning.
This sometimes depends on the version of gcc as well.
Quoted 2 lines
With that in mind, do you want ’now’ to follow M7 with the default warning flag set or to not follow M7 but ensuring the warning is addressed using default initialization with a non-default set of warning flags?
M7 should be followed, and if the warning is known to be spurious, then a pragma may be added. See ell for examples of this (grep for _Pragma). However, _Pragma is not always followed. Easiest may be to give the compiler a chance of misinterpreting the intent :)
Regards,
-Denis