Skip to contentSkip to conversation

gemalto: USB ethernet data path for ELS81x

RFC PATCH Superseded Sergey Matyukevich 3 participants 11 messages Aug 15, 2020 – Aug 18, 2020 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover gemalto: USB ethernet data path for ELS81x

Hi Denis and all,

This patch series suggests several updates and fixes for gemalto modems, in particular for ELS81x device. Major change enables data path via USB ethernet interface for modems supporting this feature.

Before submitting this patch series, I figured out that similar changes have been already submitted to ofono mailing list back in 2017. At that time they were aimed at PLS8 device:

https://lists.syncevolution.org/hyperkitty/list/ofono(a)ofono.org/thread/CHQZ2LY6D7J75MLYENACM6JDFHNN5GJ5/#3JB3RF5WVW2U6R65UHA6POSRROUNV6ET

It looks like not all the pieces from the original patches finally landed in the ofono code base. I am not sure why they were not merged, so I marked this series as RFC.

Regards,
Sergey

Sergey Matyukevich (4):
drivers: gemalto: add gprs-context driver
plugins: udevng: detect gemalto network interfaces
plugins: gemalto: add optional gprs-context driver
plugins: gemalto: fix incomplete at-chat shutdown

 Makefile.am                         |   3 +-
 drivers/gemaltomodem/gemaltomodem.c |   4 +-
 drivers/gemaltomodem/gemaltomodem.h |   3 +
 drivers/gemaltomodem/gprs-context.c | 280 ++++++++++++++++++++++++++++
 plugins/gemalto.c                   |  20 +-
 plugins/udevng.c                    |  14 +-
 6 files changed, 318 insertions(+), 6 deletions(-)
 create mode 100644 drivers/gemaltomodem/gprs-context.c
Signature · 1 line
2.28.0
#1 lore raw

RFC PATCH 1/4 drivers: gemalto: add gprs-context driver

Some gemalto modems provide USB ethernet interfaces for data path. Implement gprs-context driver for such modems to send data via USB ethernet rather than fallback to PPP.

---
 Makefile.am                         |   3 +-
 drivers/gemaltomodem/gemaltomodem.c |   4 +-
 drivers/gemaltomodem/gemaltomodem.h |   3 +
 drivers/gemaltomodem/gprs-context.c | 280 ++++++++++++++++++++++++++++
 4 files changed, 288 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gemaltomodem/gprs-context.c
Makefile.am +2 -1
index fbb0eff4..67c3bcbf 100644
@@ -482,7 +482,8 @@ builtin_sources += drivers/atmodem/atutil.h \
 			drivers/gemaltomodem/gemaltomodem.h \
 			drivers/gemaltomodem/gemaltomodem.c \
 			drivers/gemaltomodem/location-reporting.c \
-			drivers/gemaltomodem/voicecall.c
+			drivers/gemaltomodem/voicecall.c \
+			drivers/gemaltomodem/gprs-context.c
 
 builtin_modules += xmm7modem
 builtin_sources += drivers/atmodem/atutil.h \
drivers/gemaltomodem/gemaltomodem.c +3 -1
index 4818ac66..4b20dd1b 100644
@@ -36,6 +36,7 @@
 static int gemaltomodem_init(void)
 {
 	gemalto_location_reporting_init();
+	gemalto_gprs_context_init();
 	gemalto_voicecall_init();
 
 	return 0;
@@ -43,8 +44,9 @@ static int gemaltomodem_init(void)
 
 static void gemaltomodem_exit(void)
 {
-	gemalto_voicecall_exit();
 	gemalto_location_reporting_exit();
+	gemalto_gprs_context_exit();
+	gemalto_voicecall_exit();
 }
 
 OFONO_PLUGIN_DEFINE(gemaltomodem, "Gemalto modem driver", VERSION,
drivers/gemaltomodem/gemaltomodem.h +3 -0
index 27b1460e..dc0d346b 100644
@@ -27,3 +27,6 @@ extern void gemalto_location_reporting_exit();
 
 extern void gemalto_voicecall_init();
 extern void gemalto_voicecall_exit();
+
+extern void gemalto_gprs_context_init();
+extern void gemalto_gprs_context_exit();
drivers/gemaltomodem/gprs-context.c new file +280 -0

280 lines not on this page · raw message

Signature · 1 line
2.28.0
#2 lore raw

Re: [RFC PATCH 1/4] drivers: gemalto: add gprs-context driver

Hi Sergey,

Quoted 4 lines · Sergey Matyukevich

Some gemalto modems provide USB ethernet interfaces for data path. Implement gprs-context driver for such modems to send data via USB ethernet rather than fallback to PPP.

Quoted 9 lines
---
  Makefile.am                         |   3 +-
  drivers/gemaltomodem/gemaltomodem.c |   4 +-
  drivers/gemaltomodem/gemaltomodem.h |   3 +
  drivers/gemaltomodem/gprs-context.c | 280 ++++++++++++++++++++++++++++
  4 files changed, 288 insertions(+), 2 deletions(-)

create mode 100644 drivers/gemaltomodem/gprs-context.c

This looks fine to me. My only 2 nitpicks are:

1. We do not use S-o-B, so feel free to drop those in the future or I will just drop them when applying.

drivers/gemaltomodem/gprs-context.c line 244

Quoted 13 lines
drivers/gemaltomodem/gprs-context.c new file +13 -0
+
+static int gemalto_gprs_context_probe(struct ofono_gprs_context *gc,
+					unsigned int vendor, void *data)
+{
+	GAtChat *chat = data;
+	struct gprs_context_data *gcd;
+
+	DBG("");
+
+	gcd = g_try_new0(struct gprs_context_data, 1);
+	if (gcd == NULL)
+		return -ENOMEM;
+

2. We now prefer to use g_new0 for small structure allocations as these can't really fail on Linux userspace in practice. Keeps the code shorter as well.

drivers/gemaltomodem/gprs-context.c line 246

Quoted 2 lines
drivers/gemaltomodem/gprs-context.c new file +2 -0
+	gcd->chat = g_at_chat_clone(chat);
+

Regards,
-Denis

#3 lore raw

RFC PATCH 2/4 plugins: udevng: detect gemalto network interfaces

In reply to Sergey Matyukevich

Some gemalto modems, including ELS81x, may provide more than one USB ethernet interface. Detect and save both network interfaces rather than the last one.

---
 plugins/udevng.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
plugins/udevng.c +11 -3
index 7e6a3ab7..839fabdb 100644
@@ -1162,7 +1162,7 @@ static gboolean setup_ublox(struct modem_info *modem)
 static gboolean setup_gemalto(struct modem_info* modem)
 {
 	const char *app = NULL, *gps = NULL, *mdm = NULL,
-		*net = NULL, *qmi = NULL;
+		*net = NULL, *qmi = NULL, *net2 = NULL;
 
 	GSList *list;
 
@@ -1197,9 +1197,14 @@ static gboolean setup_gemalto(struct modem_info* modem)
 			else if (g_strcmp0(info->number, "04") == 0)
 				gps = info->devnode;
 		}
+
 		if (g_strcmp0(info->interface, "2/6/0") == 0) {
-			if (g_strcmp0(info->subsystem, "net") == 0)
-				net = info->devnode;
+			if (g_strcmp0(info->subsystem, "net") == 0) {
+				if (g_strcmp0(info->number, "0a") == 0)
+					net = info->devnode;
+				if (g_strcmp0(info->number, "0c") == 0)
+					net2 = info->devnode;
+			}
 		}
 	}
 
@@ -1216,6 +1221,9 @@ static gboolean setup_gemalto(struct modem_info* modem)
 	ofono_modem_set_string(modem->modem, "Model", modem->model);
 	ofono_modem_set_string(modem->modem, "NetworkInterface", net);
 
+	if (net2)
+		ofono_modem_set_string(modem->modem, "NetworkInterface2", net2);
+
 	return TRUE;
 }
 
Signature · 1 line
2.28.0
#4 lore raw

RFC PATCH 3/4 plugins: gemalto: add optional gprs-context driver

In reply to Sergey Matyukevich

Setup custom gprs context driver for modems that provide USB ethernet interfaces for data path.

---
 plugins/gemalto.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
plugins/gemalto.c +11 -1
index 13950742..238c7cc4 100644
@@ -588,6 +588,8 @@ static void gemalto_post_sim(struct ofono_modem *modem)
 	struct ofono_gprs *gprs;
 	struct ofono_gprs_context *gc;
 	const char *model = ofono_modem_get_string(modem, "Model");
+	const char *driver = NULL;
+	const char *iface = NULL;
 
 	DBG("%p", modem);
 
@@ -596,7 +598,15 @@ static void gemalto_post_sim(struct ofono_modem *modem)
 	ofono_sms_create(modem, OFONO_VENDOR_GEMALTO, "atmodem", data->app);
 
 	gprs = ofono_gprs_create(modem, 0, "atmodem", data->app);
-	gc = ofono_gprs_context_create(modem, 0, "atmodem", data->mdm);
+
+	iface = ofono_modem_get_string(modem, "NetworkInterface");
+	if (iface) {
+		driver = "gemaltomodem";
+	} else {
+		driver = "atmodem";
+	}
+
+	gc = ofono_gprs_context_create(modem, 0, driver, data->mdm);
 
 	if (gprs && gc)
 		ofono_gprs_add_context(gprs, gc);
Signature · 1 line
2.28.0
#5 lore raw

RFC PATCH 4/4 plugins: gemalto: fix incomplete at-chat shutdown

In reply to Sergey Matyukevich

Function gemalto_modem_ready attempts to restart AT chat data->app after incomplete shutdown. As a result, new AT chat does not work as expected loosing AT commands.

---
 plugins/gemalto.c | 8 ++++++++
 1 file changed, 8 insertions(+)
plugins/gemalto.c +8 -0
index 238c7cc4..321c8c1b 100644
@@ -222,6 +222,8 @@ static void sim_state_cb(gboolean present, gpointer user_data)
 	struct ofono_modem *modem = user_data;
 	struct gemalto_data *data = ofono_modem_get_data(modem);
 
+	DBG("");
+
 	at_util_sim_state_query_free(data->sim_state_query);
 	data->sim_state_query = NULL;
 
@@ -241,6 +243,8 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 	struct ofono_modem *modem = user_data;
 	struct gemalto_data *data = ofono_modem_get_data(modem);
 
+	DBG("");
+
 	if (!ok) {
 		g_at_chat_unref(data->app);
 		data->app = NULL;
@@ -451,6 +455,8 @@ static void gemalto_modem_ready(GAtResult *result, gpointer user_data)
 	data->modem_ready_id = 0;
 	data->trial_cmd_id = 0;
 
+	g_at_chat_cancel_all(data->app);
+	g_at_chat_unregister_all(data->app);
 	g_at_chat_unref(data->app);
 
 	data->app = open_device(app);
@@ -466,6 +472,8 @@ static void gemalto_at_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	struct ofono_modem *modem = user_data;
 	struct gemalto_data *data = ofono_modem_get_data(modem);
 
+	DBG("");
+
 	g_at_chat_unregister(data->app, data->modem_ready_id);
 	data->modem_ready_id = 0;
 
Signature · 1 line
2.28.0
#6 lore raw

Re: [RFC PATCH 4/4] plugins: gemalto: fix incomplete at-chat shutdown

Quoted 13 lines

Function gemalto_modem_ready attempts to restart AT chat data->app after incomplete shutdown. As a result, new AT chat does not work as expected loosing AT commands.

---
 plugins/gemalto.c | 8 ++++++++
 1 file changed, 8 insertions(+)
plugins/gemalto.c +0 -0
index 238c7cc4..321c8c1b 100644

...

plugins/gemalto.c static void gemalto_modem_ready(GAtResult *result, gpointer user_data) · line 462

Quoted 9 lines
plugins/gemalto.c +2 -0
@@ -451,6 +455,8 @@ static void gemalto_modem_ready(GAtResult *result, gpointer user_data)
 	data->modem_ready_id = 0;
 	data->trial_cmd_id = 0;
 
+	g_at_chat_cancel_all(data->app);
+	g_at_chat_unregister_all(data->app);
 	g_at_chat_unref(data->app);
 
 	data->app = open_device(app);

Please disregard this patch in the series. This change does not resolve the root cause. It looks like when gemalto_modem_ready is called on ^SYSSTART, occasionally modem is not ready to process AT commands. As a result, the upcoming gemalto_initialize function fails due to timed out AT commands.

It turns out that the approach implemented in ublox plugin (repeated probe AT command) provides more reliable results, in particular in power-off tests. I will do more testing and update this patch in the next revision of the patch set.

Regards,
Sergey

#7 lore raw

Re: [RFC PATCH 4/4] plugins: gemalto: fix incomplete at-chat shutdown

In reply to Sergey Matyukevich

Hi Sergey,

Quoted 8 lines · Sergey Matyukevich

Function gemalto_modem_ready attempts to restart AT chat data->app after incomplete shutdown. As a result, new AT chat does not work as expected loosing AT commands.

---
  plugins/gemalto.c | 8 ++++++++
  1 file changed, 8 insertions(+)

Patch 2, 3 look good to me.

For this one, what is it trying to do actually?

Quoted 24 lines
plugins/gemalto.c +4 -0
index 238c7cc4..321c8c1b 100644
@@ -222,6 +222,8 @@ static void sim_state_cb(gboolean present, gpointer user_data)
  	struct ofono_modem *modem = user_data;
  	struct gemalto_data *data = ofono_modem_get_data(modem);
 
+	DBG("");
+
  	at_util_sim_state_query_free(data->sim_state_query);
  	data->sim_state_query = NULL;
 
@@ -241,6 +243,8 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
  	struct ofono_modem *modem = user_data;
  	struct gemalto_data *data = ofono_modem_get_data(modem);
 
+	DBG("");
+
  	if (!ok) {
  		g_at_chat_unref(data->app);
  		data->app = NULL;

plugins/gemalto.c static void gemalto_modem_ready(GAtResult *result, gpointer user_data) · line 459

Quoted 5 lines
plugins/gemalto.c +2 -0
@@ -451,6 +455,8 @@ static void gemalto_modem_ready(GAtResult *result, gpointer user_data)
  	data->modem_ready_id = 0;
  	data->trial_cmd_id = 0;
 
+	g_at_chat_cancel_all(data->app);
+	g_at_chat_unregister_all(data->app);

These get called automatically on unref below, assuming this is the last (it should be) reference.

plugins/gemalto.c static void gemalto_modem_ready(GAtResult *result, gpointer user_data) · line 460

Quoted 1 line
plugins/gemalto.c +0 -0
  	g_at_chat_unref(data->app);

Instead of this dance of opening / closing the chat in order to force-cancel the 'AT' command queued in gemalto_enable(), maybe there should be something in GAtChat itself to handle this case. Either a 'force cancel the top of the queue because I know the modem is broken' or maybe some form of 'send this on the port until it responds properly'. Alternatively, you could simply use GAtIO and a timer to write stuff to the port until it responds and only create the chat at that time.

There's already something a bit similar in the form of g_at_chat_set_wakeup_command(). It was used on the old Neo Freerunner modem which would go to 'sleep' after several seconds of inactivity. So the subsequent AT command would get eaten. You basically had to poke it with an empty command, have it timeout / return OK and then you could go on with submitting AT commands again. But I don't think it is a good fit for this particular case.

plugins/gemalto.c static void gemalto_at_cb(gboolean ok, GAtResult *result, gpointer user_data) · line 479

Quoted 12 lines
plugins/gemalto.c +2 -0
  	data->app = open_device(app);
@@ -466,6 +472,8 @@ static void gemalto_at_cb(gboolean ok, GAtResult *result, gpointer user_data)
  	struct ofono_modem *modem = user_data;
  	struct gemalto_data *data = ofono_modem_get_data(modem);
 
+	DBG("");
+
  	g_at_chat_unregister(data->app, data->modem_ready_id);
  	data->modem_ready_id = 0;
 

Regards,
-Denis

#8 lore raw

Re: [RFC PATCH 4/4] plugins: gemalto: fix incomplete at-chat shutdown

Hello Denis,

Quoted 4 lines
Quoted 4 lines

Function gemalto_modem_ready attempts to restart AT chat data->app after incomplete shutdown. As a result, new AT chat does not work as expected loosing AT commands.

Quoted 9 lines
Quoted 4 lines
---
  plugins/gemalto.c | 8 ++++++++
  1 file changed, 8 insertions(+)

Patch 2, 3 look good to me.

For this one, what is it trying to do actually?

Thanks for review. I will re-send second revision of the patches 1-3 with minor changes according to review comments.

Concerning the 4th patch, I thought the problem was in the incomplete cleanup on data->app re-open in gemalto_modem_ready function. However this is not the case. Sometimes, in particular on cold start, modem is not really ready even after it sends ^SYSSTART. As a result, subsequent AT+CFUN=4 command never completes. I have been experimenting with the same approach as in ublox plugin with much better results. So I will complete my experiments and send new fix in a separate patch.

Regards,
Sergey

#9 lore raw

Re: [RFC PATCH 4/4] plugins: gemalto: fix incomplete at-chat shutdown

In reply to Denis Kenzior

Hi Denis and Sergey,

Quoted 42 lines · Denis Kenzior
Quoted 22 lines
plugins/gemalto.c +4 -0
index 238c7cc4..321c8c1b 100644
@@ -222,6 +222,8 @@ static void sim_state_cb(gboolean present, 
 gpointer user_data)
       struct ofono_modem *modem = user_data;
       struct gemalto_data *data = ofono_modem_get_data(modem);
+    DBG("");
+
       at_util_sim_state_query_free(data->sim_state_query);
       data->sim_state_query = NULL;
@@ -241,6 +243,8 @@ static void cfun_enable(gboolean ok, GAtResult 
 *result, gpointer user_data)
       struct ofono_modem *modem = user_data;
       struct gemalto_data *data = ofono_modem_get_data(modem);
+    DBG("");
+
       if (!ok) {
           g_at_chat_unref(data->app);
           data->app = NULL;

plugins/gemalto.c static void gemalto_modem_ready(GAtResult *result, · line 459

Quoted 5 lines
plugins/gemalto.c +2 -0
@@ -451,6 +455,8 @@ static void gemalto_modem_ready(GAtResult *result, 
 gpointer user_data)
       data->modem_ready_id = 0;
       data->trial_cmd_id = 0;
+    g_at_chat_cancel_all(data->app);
+    g_at_chat_unregister_all(data->app);

These get called automatically on unref below, assuming  this is the last (it should be) reference.

plugins/gemalto.c static void gemalto_modem_ready(GAtResult *result, · line 460

Quoted 1 line
plugins/gemalto.c +0 -0
       g_at_chat_unref(data->app);

Instead of this dance of opening / closing the chat in order to force-cancel the 'AT' command queued in gemalto_enable(), maybe there should be something in GAtChat itself to handle this case.  Either a 'force cancel the top of the queue because I know the modem is broken' or maybe some form of 'send this on the port until it responds properly'.  Alternatively, you could simply use GAtIO and a timer to write stuff to the port until it responds and only create the chat at that time.

Quoted 7 lines

There's already something a bit similar in the form of g_at_chat_set_wakeup_command().  It was used on the old Neo Freerunner modem which would go to 'sleep' after several seconds of inactivity.  So the subsequent AT command would get eaten.  You basically had to poke it with an empty command, have it timeout / return OK and then you could go on with submitting AT commands again.  But I don't think it is a good fit for this particular case.

There's also the retry logic used on quectel modems with auto-detection of baud rates:
https://git.kernel.org/pub/scm/network/ofono/ofono.git/tree/plugins/quectel.c#n1082

// Martin

#10 lore raw

Re: [RFC PATCH 4/4] plugins: gemalto: fix incomplete at-chat shutdown

Hi Martin,

Quoted 3 lines
Quoted 3 lines

Instead of this dance of opening / closing the chat in order to force-cancel the 'AT' command queued in gemalto_enable(), maybe there should be something in GAtChat itself to handle this case.

<snip>

Quoted 5 lines

There's also the retry logic used on quectel modems with auto-detection of baud rates:
https://git.kernel.org/pub/scm/network/ofono/ofono.git/tree/plugins/quectel.c#n1082

Ah right, I completely forgot about g_at_chat_retry that you added for exactly the use case I outlined above. Thanks for the reminder.

Maybe we should just add this modem poking logic into drivers/atmodem/atutil.[ch] or something if it will be used across multiple drivers.

Regards,
-Denis