core: new 'rpmsg' subsystem

Most older Qualcomm SoCs (e.g. MSM8916, MSM8974, ...) communicate with
the integrated modem via shared memory (SMD channels). This is similar
to QRTR on newer SoCs, but without the "network" layer. In fact, the
older SoCs also have QRTR, but the modem QMI services are not exposed
there.

The mainline Linux kernel exposes SMD channels via the "remote processor
messaging bus" (rpmsg). Through special IOCTL calls it is possible to
create a char device for a rpmsg/SMD channel. We can then use these to
send QMI/AT messages to the modem, much like the ordinary serial char
devices when using a Qualcomm modem through USB.

This commit introduces support for the new 'rpmsg' subsystem, which
allows exporting QMI-capable and AT-capable ports.

By default NO rpmsg port is flagged as candidate, it is assumed that
the plugin adding support for the rpmsg subsystem will add specific
rules to do so (e.g. so that non-modem ports are explicitly not
flagged as candidate).

All rpmsg ports will be probed for AT or QMI capabilities, unless
explicit port type hints (e.g. ID_MM_PORT_TYPE_QMI or
ID_MM_PORT_TYPE_AT_PRIMARY) are set.

These changes are highly based on the initial integration work done by
Stephan Gerhold <stephan@gerhold.net> in postmarketOS, see:
  https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/363
This commit is contained in:
Aleksander Morgado
2020-10-25 14:23:29 +01:00
parent 3d12272d18
commit cab4b54ad1
7 changed files with 62 additions and 23 deletions

View File

@@ -444,7 +444,7 @@ get_manager_ready (GObject *source,
#if defined WITH_UDEV
if (report_kernel_event_auto_scan) {
const gchar *subsys[] = { "tty", "usbmisc", "net", NULL };
const gchar *subsys[] = { "tty", "usbmisc", "net", "rpmsg", NULL };
guint i;
ctx->udev = g_udev_client_new (subsys);

View File

@@ -237,6 +237,20 @@ base_modem_create_usbmisc_port (MMBaseModem *self,
return NULL;
}
static MMPort *
base_modem_create_rpmsg_port (MMBaseModem *self,
const gchar *name,
MMPortType ptype)
{
#if defined WITH_QMI
if (ptype == MM_PORT_TYPE_QMI)
return MM_PORT (mm_port_qmi_new (name, MM_PORT_SUBSYS_RPMSG));
#endif
if (ptype == MM_PORT_TYPE_AT)
return MM_PORT (mm_port_serial_at_new (name, MM_PORT_SUBSYS_RPMSG));
return NULL;
}
static MMPort *
base_modem_create_virtual_port (MMBaseModem *self,
const gchar *name)
@@ -278,6 +292,8 @@ mm_base_modem_grab_port (MMBaseModem *self,
port = base_modem_create_tty_port (self, name, kernel_device, ptype);
else if (g_str_equal (subsys, "usbmisc"))
port = base_modem_create_usbmisc_port (self, name, ptype);
else if (g_str_equal (subsys, "rpmsg"))
port = base_modem_create_rpmsg_port (self, name, ptype);
else if (g_str_equal (subsys, "virtual"))
port = base_modem_create_virtual_port (self, name);
@@ -327,8 +343,6 @@ mm_base_modem_grab_port (MMBaseModem *self,
return TRUE;
}
/******************************************************************************/
gboolean
mm_base_modem_disable_finish (MMBaseModem *self,
GAsyncResult *res,

View File

@@ -199,6 +199,13 @@ mm_filter_port (MMFilter *self,
return TRUE;
}
/* If this is a rpmsg channel device, we always allow it */
if ((self->priv->enabled_rules & MM_FILTER_RULE_RPMSG) &&
(g_strcmp0 (subsystem, "rpmsg") == 0)) {
mm_obj_dbg (self, "(%s/%s) port allowed: rpmsg device", subsystem, name);
return TRUE;
}
/* If this is a tty device, we may allow it */
if ((self->priv->enabled_rules & MM_FILTER_RULE_TTY) &&
(g_strcmp0 (subsystem, "tty") == 0)) {

View File

@@ -53,15 +53,16 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/
MM_FILTER_RULE_VIRTUAL = 1 << 3,
MM_FILTER_RULE_NET = 1 << 4,
MM_FILTER_RULE_USBMISC = 1 << 5,
MM_FILTER_RULE_TTY = 1 << 6,
MM_FILTER_RULE_TTY_BLACKLIST = 1 << 7,
MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY = 1 << 8,
MM_FILTER_RULE_TTY_PLATFORM_DRIVER = 1 << 9,
MM_FILTER_RULE_TTY_DEFAULT_ALLOWED = 1 << 10,
MM_FILTER_RULE_TTY_DRIVER = 1 << 11,
MM_FILTER_RULE_TTY_ACM_INTERFACE = 1 << 12,
MM_FILTER_RULE_TTY_WITH_NET = 1 << 13,
MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN = 1 << 14,
MM_FILTER_RULE_RPMSG = 1 << 6,
MM_FILTER_RULE_TTY = 1 << 7,
MM_FILTER_RULE_TTY_BLACKLIST = 1 << 8,
MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY = 1 << 9,
MM_FILTER_RULE_TTY_PLATFORM_DRIVER = 1 << 10,
MM_FILTER_RULE_TTY_DEFAULT_ALLOWED = 1 << 11,
MM_FILTER_RULE_TTY_DRIVER = 1 << 12,
MM_FILTER_RULE_TTY_ACM_INTERFACE = 1 << 13,
MM_FILTER_RULE_TTY_WITH_NET = 1 << 14,
MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN = 1 << 15,
} MMFilterRule;
#define MM_FILTER_RULE_ALL \
@@ -71,6 +72,7 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/
MM_FILTER_RULE_VIRTUAL | \
MM_FILTER_RULE_NET | \
MM_FILTER_RULE_USBMISC | \
MM_FILTER_RULE_RPMSG | \
MM_FILTER_RULE_TTY | \
MM_FILTER_RULE_TTY_BLACKLIST | \
MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY | \
@@ -89,6 +91,7 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/
MM_FILTER_RULE_VIRTUAL | \
MM_FILTER_RULE_NET | \
MM_FILTER_RULE_USBMISC | \
MM_FILTER_RULE_RPMSG | \
MM_FILTER_RULE_TTY | \
MM_FILTER_RULE_TTY_BLACKLIST | \
MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY | \
@@ -104,6 +107,7 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/
MM_FILTER_RULE_VIRTUAL | \
MM_FILTER_RULE_NET | \
MM_FILTER_RULE_USBMISC | \
MM_FILTER_RULE_RPMSG | \
MM_FILTER_RULE_TTY | \
MM_FILTER_RULE_TTY_PLATFORM_DRIVER | \
MM_FILTER_RULE_TTY_DRIVER | \
@@ -120,6 +124,7 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/
MM_FILTER_RULE_VIRTUAL | \
MM_FILTER_RULE_NET | \
MM_FILTER_RULE_USBMISC | \
MM_FILTER_RULE_RPMSG | \
MM_FILTER_RULE_TTY | \
MM_FILTER_RULE_TTY_BLACKLIST | \
MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY | \

View File

@@ -781,6 +781,11 @@ mm_plugin_supports_port (MMPlugin *self,
probe_run_flags |= MM_PORT_PROBE_MBIM;
else
probe_run_flags |= MM_PORT_PROBE_AT;
} else if (g_str_equal (mm_kernel_device_get_subsystem (port), "rpmsg")) {
if (self->priv->at)
probe_run_flags |= MM_PORT_PROBE_AT;
if (self->priv->qmi)
probe_run_flags |= MM_PORT_PROBE_QMI;
}
/* For potential AT ports, check for more things */

View File

@@ -491,16 +491,22 @@ wdm_probe_qmi (MMPortProbe *self)
ctx = g_task_get_task_data (self->priv->task);
#if defined WITH_QMI
{
MMPortSubsys subsys = MM_PORT_SUBSYS_USBMISC;
mm_obj_dbg (self, "probing QMI...");
if (g_str_equal (mm_kernel_device_get_subsystem (self->priv->port), "rpmsg"))
subsys = MM_PORT_SUBSYS_RPMSG;
/* Create a port and try to open it */
ctx->port_qmi = mm_port_qmi_new (mm_kernel_device_get_name (self->priv->port),
MM_PORT_SUBSYS_USBMISC);
ctx->port_qmi = mm_port_qmi_new (mm_kernel_device_get_name (self->priv->port), subsys);
mm_port_qmi_open (ctx->port_qmi,
FALSE,
NULL,
(GAsyncReadyCallback) port_qmi_open_ready,
self);
}
#else
/* If not compiled with QMI support, just assume we won't have any QMI port */
mm_port_probe_set_result_qmi (self, FALSE);
@@ -1273,6 +1279,8 @@ serial_open_at (MMPortProbe *self)
if (g_str_equal (mm_kernel_device_get_subsystem (self->priv->port), "usbmisc"))
subsys = MM_PORT_SUBSYS_USBMISC;
else if (g_str_equal (mm_kernel_device_get_subsystem (self->priv->port), "rpmsg"))
subsys = MM_PORT_SUBSYS_RPMSG;
ctx->serial = MM_PORT_SERIAL (mm_port_serial_at_new (mm_kernel_device_get_name (self->priv->port), subsys));
if (!ctx->serial) {

View File

@@ -28,8 +28,8 @@ typedef enum { /*< underscore_name=mm_port_subsys >*/
MM_PORT_SUBSYS_NET,
MM_PORT_SUBSYS_USBMISC,
MM_PORT_SUBSYS_UNIX,
MM_PORT_SUBSYS_LAST = MM_PORT_SUBSYS_UNIX /*< skip >*/
MM_PORT_SUBSYS_RPMSG,
MM_PORT_SUBSYS_LAST = MM_PORT_SUBSYS_RPMSG /*< skip >*/
} MMPortSubsys;
typedef enum { /*< underscore_name=mm_port_type >*/