Skip to contentSkip to conversation

qmi/discovery: remove useless code

PATCH Superseded Alexander Couzens 2 participants 6 messages Sep 7, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 qmi/discovery: remove useless code

---
 drivers/qmimodem/qmi.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/qmimodem/qmi.c +0 -5
index c538cb978393..1af86aaccb08 100644
@@ -1162,11 +1162,6 @@ static void discover_callback(uint16_t message, uint16_t length,
 
 	service_list = ptr + *((uint8_t *) ptr) + 1;
 
-	for (i = 0; i < service_list->count; i++) {
-		if (service_list->services[i].type == QMI_SERVICE_CONTROL)
-			continue;
-	}
-
 done:
 	device->version_list = list;
 	device->version_count = count;
Signature · 1 line
2.14.1
#1 lore raw

PATCH 2/3 qmi/discovery: include control service into service list

There is no need to exclude it. It helps debugging because the service is now logged.

---
 drivers/qmimodem/qmi.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/qmimodem/qmi.c +6 -7
index 1af86aaccb08..7ea22992f8f0 100644
@@ -1136,15 +1136,12 @@ static void discover_callback(uint16_t message, uint16_t length,
 		if (type == QMI_SERVICE_CONTROL) {
 			device->control_major = major;
 			device->control_minor = minor;
-			continue;
 		}
 
-		list[count].type = type;
-		list[count].major = major;
-		list[count].minor = minor;
-		list[count].name = name;
-
-		count++;
+		list[i].type = type;
+		list[i].major = major;
+		list[i].minor = minor;
+		list[i].name = name;
 
 		if (name)
 			__debug_device(device, "found service [%s %d.%d]",
@@ -1154,6 +1151,8 @@ static void discover_callback(uint16_t message, uint16_t length,
 							type, major, minor);
 	}
 
+	count = service_list->count;
+
 	ptr = tlv_get(buffer, length, 0x10, &len);
 	if (!ptr)
 		goto done;
Signature · 1 line
2.14.1
#3 lore raw

PATCH 3/3 qmi/discovery: sync the qmi state with the modem

In reply to Alexander Couzens

The qmi sync call release all previous resources.
Only call sync when the CTL service is >= 1.5

---
 drivers/qmimodem/qmi.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/qmimodem/qmi.h |  5 ++++-
 plugins/gobi.c         | 24 ++++++++++++++++++++++--
 3 files changed, 73 insertions(+), 3 deletions(-)
drivers/qmimodem/qmi.c +47 -0
index 7ea22992f8f0..fedfb9666c08 100644
@@ -1317,6 +1317,53 @@ 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 qmi_control_hdr *hdr;
+	struct sync_data *func_data;
+
+	if (!device)
+		return false;
+
+	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, QMI_CONTROL_HDR_SIZE,
+			NULL, 0,
+			qmi_device_sync_callback, func_data, (void **) &hdr);
+
+	if (device->next_control_tid < 1)
+		device->next_control_tid = 1;
+
+	hdr->type = 0x00;
+	hdr->transaction = device->next_control_tid++;
+
+	__request_submit(device, req, hdr->transaction);
+
+	return true;
+}
+
 static bool get_device_file_name(struct qmi_device *device,
 					char *file_name, int size)
 {
drivers/qmimodem/qmi.h +4 -1
index b4955b40b1fb..8a348876edb9 100644
@@ -76,7 +76,7 @@ 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)(uint8_t count,
 			const struct qmi_version *list, void *user_data);
@@ -96,6 +96,9 @@ bool qmi_device_discover(struct qmi_device *device, qmi_discover_func_t func,
 bool qmi_device_shutdown(struct qmi_device *device, qmi_shutdown_func_t func,
 				void *user_data, qmi_destroy_func_t destroy);
 
+bool qmi_device_sync(struct qmi_device *device,
+		     qmi_sync_func_t func, void *user_data);
+
 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,
plugins/gobi.c +22 -2
index a49859901f2f..40eefdfc867b 100644
@@ -252,6 +252,15 @@ error:
 	shutdown_device(modem);
 }
 
+static void create_shared_dms(void *user_data)
+{
+	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);
+}
+
 static void discover_cb(uint8_t count, const struct qmi_version *list,
 							void *user_data)
 {
@@ -266,6 +275,15 @@ static void discover_cb(uint8_t count, const struct qmi_version *list,
 				list[i].type);
 
 		switch (list[i].type) {
+		case QMI_SERVICE_CONTROL:
+			/* sync command resets the QMI state */
+			if (list[i].major > 1 ||
+					(list[i].major == 1 &&
+					 list[i].minor >= 5))
+				ofono_modem_set_boolean(modem,
+							"SupportQMISync",
+							TRUE);
+			break;
 		case QMI_SERVICE_DMS:
 			data->features |= GOBI_DMS;
 			break;
@@ -314,8 +332,10 @@ static void discover_cb(uint8_t count, const struct qmi_version *list,
 		return;
 	}
 
-	qmi_service_create_shared(data->device, QMI_SERVICE_DMS,
-						create_dms_cb, modem, NULL);
+	if (ofono_modem_get_boolean(modem, "SupportQMISync") == TRUE)
+		qmi_device_sync(data->device, create_shared_dms, modem);
+	else
+		create_shared_dms(modem);
 }
 
 static int gobi_enable(struct ofono_modem *modem)
Signature · 1 line
2.14.1
#5 lore raw
In reply to Alexander Couzens

Hi Alexander,

drivers/qmimodem/qmi.c static void discover_callback(uint16_t message, uint16_t length, · line 1164

Quoted 12 lines · Alexander Couzens
---
  drivers/qmimodem/qmi.c | 5 -----
  1 file changed, 5 deletions(-)
drivers/qmimodem/qmi.c +0 -0
index c538cb978393..1af86aaccb08 100644
@@ -1162,11 +1162,6 @@ static void discover_callback(uint16_t message, uint16_t length,
 
  	service_list = ptr + *((uint8_t *) ptr) + 1;
 

Why don't you also take out that service_list assignment as well?

drivers/qmimodem/qmi.c static void discover_callback(uint16_t message, uint16_t length, · line 1167

Quoted 9 lines
drivers/qmimodem/qmi.c +0 -5
-	for (i = 0; i < service_list->count; i++) {
-		if (service_list->services[i].type == QMI_SERVICE_CONTROL)
-			continue;
-	}
-
  done:
  	device->version_list = list;
  	device->version_count = count;

Regards,
-Denis

#2 lore raw

Re: [PATCH 2/3] qmi/discovery: include control service into service list

In reply to Alexander Couzens

Hi Alexander,

Quoted 18 lines · Alexander Couzens

There is no need to exclude it. It helps debugging because the service is now logged.

---
  drivers/qmimodem/qmi.c | 13 ++++++-------
  1 file changed, 6 insertions(+), 7 deletions(-)
drivers/qmimodem/qmi.c +0 -2
index 1af86aaccb08..7ea22992f8f0 100644
@@ -1136,15 +1136,12 @@ static void discover_callback(uint16_t message, uint16_t length,
  		if (type == QMI_SERVICE_CONTROL) {
  			device->control_major = major;
  			device->control_minor = minor;
-			continue;
  		}
 
-		list[count].type = type;

drivers/qmimodem/qmi.c static void discover_callback(uint16_t message, uint16_t length, · line 1145

Quoted 10 lines
drivers/qmimodem/qmi.c +4 -5
-		list[count].major = major;
-		list[count].minor = minor;
-		list[count].name = name;
-
-		count++;
+		list[i].type = type;
+		list[i].major = major;
+		list[i].minor = minor;
+		list[i].name = name;
 

We store the CONTROL service minor and major numbers and generally treat it specially. If you care about logging it, why not just add an extra debug statement?

drivers/qmimodem/qmi.c static void discover_callback(uint16_t message, uint16_t length, · line 1158

Quoted 12 lines
drivers/qmimodem/qmi.c +2 -0
  		if (name)
  			__debug_device(device, "found service [%s %d.%d]",
@@ -1154,6 +1151,8 @@ static void discover_callback(uint16_t message, uint16_t length,
  							type, major, minor);
  	}
 
+	count = service_list->count;
+
  	ptr = tlv_get(buffer, length, 0x10, &len);
  	if (!ptr)
  		goto done;

Regards,
-Denis

#4 lore raw

Re: [PATCH 3/3] qmi/discovery: sync the qmi state with the modem

In reply to Alexander Couzens

Hi Alexander,

Quoted 8 lines · Alexander Couzens

The qmi sync call release all previous resources.
Only call sync when the CTL service is >= 1.5

---
  drivers/qmimodem/qmi.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
  drivers/qmimodem/qmi.h |  5 ++++-
  plugins/gobi.c         | 24 ++++++++++++++++++++++--
  3 files changed, 73 insertions(+), 3 deletions(-)

Please see HACKING, Submitting Patches section

Quoted 104 lines
drivers/qmimodem/qmi.c +47 -0
index 7ea22992f8f0..fedfb9666c08 100644
@@ -1317,6 +1317,53 @@ 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 qmi_control_hdr *hdr;
+	struct sync_data *func_data;
+
+	if (!device)
+		return false;
+
+	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, QMI_CONTROL_HDR_SIZE,
+			NULL, 0,
+			qmi_device_sync_callback, func_data, (void **) &hdr);
+
+	if (device->next_control_tid < 1)
+		device->next_control_tid = 1;
+
+	hdr->type = 0x00;
+	hdr->transaction = device->next_control_tid++;
+
+	__request_submit(device, req, hdr->transaction);
+
+	return true;
+}
+
  static bool get_device_file_name(struct qmi_device *device,
  					char *file_name, int size)
  {
drivers/qmimodem/qmi.h +4 -1
index b4955b40b1fb..8a348876edb9 100644
@@ -76,7 +76,7 @@ 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)(uint8_t count,
  			const struct qmi_version *list, void *user_data);
@@ -96,6 +96,9 @@ bool qmi_device_discover(struct qmi_device *device, qmi_discover_func_t func,
  bool qmi_device_shutdown(struct qmi_device *device, qmi_shutdown_func_t func,
  				void *user_data, qmi_destroy_func_t destroy);
 
+bool qmi_device_sync(struct qmi_device *device,
+		     qmi_sync_func_t func, void *user_data);
+
  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,
plugins/gobi.c +9 -0
index a49859901f2f..40eefdfc867b 100644
@@ -252,6 +252,15 @@ error:
  	shutdown_device(modem);
  }
 
+static void create_shared_dms(void *user_data)
+{
+	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);
+}
+
  static void discover_cb(uint8_t count, const struct qmi_version *list,
  							void *user_data)
  {
@@ -266,6 +275,15 @@ static void discover_cb(uint8_t count, const struct qmi_version *list,
  				list[i].type);
 

plugins/gobi.c static void discover_cb(uint8_t count, const struct qmi_version *list, · line 286

Quoted 10 lines
plugins/gobi.c +9 -0
  		switch (list[i].type) {
+		case QMI_SERVICE_CONTROL:
+			/* sync command resets the QMI state */
+			if (list[i].major > 1 ||
+					(list[i].major == 1 &&
+					 list[i].minor >= 5))
+				ofono_modem_set_boolean(modem,
+							"SupportQMISync",
+							TRUE);
+			break;

This really belongs as an API on qmi_device and not some property on the modem.

E.g. qmi_device_get_control_version or qmi_device_is_sync_supported

Quoted 7 lines
plugins/gobi.c +0 -0
  		case QMI_SERVICE_DMS:
  			data->features |= GOBI_DMS;
  			break;
@@ -314,8 +332,10 @@ static void discover_cb(uint8_t count, const struct qmi_version *list,
  		return;
  	}

plugins/gobi.c static void discover_cb(uint8_t count, const struct qmi_version *list, · line 341

Quoted 10 lines
plugins/gobi.c +4 -2
 
-	qmi_service_create_shared(data->device, QMI_SERVICE_DMS,
-						create_dms_cb, modem, NULL);
+	if (ofono_modem_get_boolean(modem, "SupportQMISync") == TRUE)
+		qmi_device_sync(data->device, create_shared_dms, modem);
+	else
+		create_shared_dms(modem);
  }
 
  static int gobi_enable(struct ofono_modem *modem)

Regards,
-Denis