diff mbox series

[1/7] qmi: Remove qmi_device_sync

Message ID 20240220224115.1254853-1-denkenz@gmail.com (mailing list archive)
State Superseded
Headers show
Series [1/7] qmi: Remove qmi_device_sync | expand

Commit Message

Denis Kenzior Feb. 20, 2024, 10:40 p.m. UTC
This is an implementation detail of the QMUX/CTL interface.  Since the
only caller always invokes SYNC after discovery if supported, simplify
the SYNC operation to be part of the discovery procedure and remove the
relevant APIs from qmi_device.
---
 drivers/qmimodem/qmi.c | 88 +++++++++++++++++-------------------------
 drivers/qmimodem/qmi.h |  5 ---
 plugins/gobi.c         | 10 ++---
 3 files changed, 39 insertions(+), 64 deletions(-)
diff mbox series

Patch

diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c
index c9c809757427..ee51a7db2368 100644
--- a/drivers/qmimodem/qmi.c
+++ b/drivers/qmimodem/qmi.c
@@ -1176,6 +1176,35 @@  static void discover_data_free(gpointer user_data)
 	g_free(data);
 }
 
+static void qmi_device_sync_callback(uint16_t message, uint16_t length,
+					const void *buffer, void *user_data)
+{
+	struct discover_data *data = user_data;
+
+	if (data->func)
+		data->func(data->user_data);
+
+	__qmi_device_discovery_complete(data->device, &data->super);
+}
+
+/* sync will release all previous clients */
+static bool qmi_device_sync(struct qmi_device *device,
+				struct discover_data *data)
+{
+	struct qmi_request *req;
+
+	__debug_device(device, "Sending sync to reset QMI");
+
+	req = __request_alloc(QMI_SERVICE_CONTROL, 0x00,
+				QMI_CTL_SYNC, NULL, 0,
+				qmi_device_sync_callback, data);
+
+	__request_submit(device, req);
+
+	return true;
+}
+
+
 static void discover_callback(uint16_t message, uint16_t length,
 					const void *buffer, void *user_data)
 {
@@ -1249,6 +1278,13 @@  done:
 	device->version_list = list;
 	device->version_count = count;
 
+	/* if the device support the QMI call SYNC over the CTL interface */
+	if ((device->control_major == 1 && device->control_minor >= 5) ||
+			device->control_major > 1) {
+		qmi_device_sync(data->device, data);
+		return;
+	}
+
 	if (data->func)
 		data->func(data->user_data);
 
@@ -1414,58 +1450,6 @@  bool qmi_device_shutdown(struct qmi_device *device, qmi_shutdown_func_t func,
 	return true;
 }
 
-struct sync_data {
-	qmi_sync_func_t func;
-	void *user_data;
-};
-
-static void qmi_device_sync_callback(uint16_t message, uint16_t length,
-				     const void *buffer, void *user_data)
-{
-	struct sync_data *data = user_data;
-
-	if (data->func)
-		data->func(data->user_data);
-
-	g_free(data);
-}
-
-/* sync will release all previous clients */
-bool qmi_device_sync(struct qmi_device *device,
-		     qmi_sync_func_t func, void *user_data)
-{
-	struct qmi_request *req;
-	struct sync_data *func_data;
-
-	if (!device)
-		return false;
-
-	__debug_device(device, "Sending sync to reset QMI");
-
-	func_data = g_new0(struct sync_data, 1);
-	func_data->func = func;
-	func_data->user_data = user_data;
-
-	req = __request_alloc(QMI_SERVICE_CONTROL, 0x00,
-			QMI_CTL_SYNC,
-			NULL, 0,
-			qmi_device_sync_callback, func_data);
-
-	__request_submit(device, req);
-
-	return true;
-}
-
-/* if the device support the QMI call SYNC over the CTL interface */
-bool qmi_device_is_sync_supported(struct qmi_device *device)
-{
-	if (device == NULL)
-		return false;
-
-	return (device->control_major > 1 ||
-		(device->control_major == 1 && device->control_minor >= 5));
-}
-
 static bool get_device_file_name(struct qmi_device *device,
 					char *file_name, int size)
 {
diff --git a/drivers/qmimodem/qmi.h b/drivers/qmimodem/qmi.h
index 21537a76c64e..fc2a309578c4 100644
--- a/drivers/qmimodem/qmi.h
+++ b/drivers/qmimodem/qmi.h
@@ -78,7 +78,6 @@  typedef void (*qmi_destroy_func_t)(void *user_data);
 struct qmi_device;
 
 typedef void (*qmi_debug_func_t)(const char *str, void *user_data);
-typedef void (*qmi_sync_func_t)(void *user_data);
 typedef void (*qmi_shutdown_func_t)(void *user_data);
 typedef void (*qmi_discover_func_t)(void *user_data);
 
@@ -101,10 +100,6 @@  bool qmi_device_has_service(struct qmi_device *device, uint16_t type);
 bool qmi_device_get_service_version(struct qmi_device *device, uint16_t type,
 					uint16_t *major, uint16_t *minor);
 
-bool qmi_device_sync(struct qmi_device *device,
-		     qmi_sync_func_t func, void *user_data);
-bool qmi_device_is_sync_supported(struct qmi_device *device);
-
 enum qmi_device_expected_data_format qmi_device_get_expected_data_format(
 						struct qmi_device *device);
 bool qmi_device_set_expected_data_format(struct qmi_device *device,
diff --git a/plugins/gobi.c b/plugins/gobi.c
index 76c9d68d2df5..020d6ba2685e 100644
--- a/plugins/gobi.c
+++ b/plugins/gobi.c
@@ -364,13 +364,12 @@  error:
 	shutdown_device(modem);
 }
 
-static void create_shared_dms(void *user_data)
+static void create_shared_dms(struct ofono_modem *modem)
 {
-	struct ofono_modem *modem = user_data;
 	struct gobi_data *data = ofono_modem_get_data(modem);
 
 	qmi_service_create_shared(data->device, QMI_SERVICE_DMS,
-				  create_dms_cb, modem, NULL);
+						create_dms_cb, modem, NULL);
 }
 
 static void discover_cb(void *user_data)
@@ -417,10 +416,7 @@  static void discover_cb(void *user_data)
 		return;
 	}
 
-	if (qmi_device_is_sync_supported(data->device))
-		qmi_device_sync(data->device, create_shared_dms, modem);
-	else
-		create_shared_dms(modem);
+	create_shared_dms(modem);
 }
 
 static int gobi_enable(struct ofono_modem *modem)