kernel-device: device-specific properties in either port or physdev

There are 2 main types of udev properties: device-specific and
port-specific.

The port-specific properties are set independently per port (e.g. port
type hints set per interface number for a given vid:pid).

The device-specific properties apply to all ports in the device. Some
of these properties are currently expected in the physical device
(e.g. ID_MM_PLATFORM_DRIVER_PROBE) while some others are expected in
each port (e.g. the plugin udev tag filters).

This patch tries to simplify the logic and just assume that the device
specific tags may be given in either the physical device or the port
device, by providing separate APIs to retrieve port-specific or
device-specific (global) properties. If the same tag is given in both
the device and the port, the one in the device takes preference.

For the generic backend, these new APIs are really useless, as all
device-specific and port-specific properties are always stored in the
port object themselves (there is no 'tree' of devices in the generic
backend, no 'physdev' device).

For the udev backend, though, there really is a difference, as the
tags may be set in port or device.

https://bugs.freedesktop.org/show_bug.cgi?id=100156
This commit is contained in:
Aleksander Morgado
2017-03-06 12:01:56 +01:00
parent 230e732a24
commit 00fb9e98f6
11 changed files with 213 additions and 39 deletions

View File

@@ -342,7 +342,7 @@ dell_custom_init (MMPortProbe *probe,
/* Dell-branded Telit modems always answer to +GMI
* Avoid +CGMI and ATI sending for minimizing port probing time */
if (mm_kernel_device_get_property_as_boolean (port_device, "ID_MM_TELIT_PORTS_TAGGED")) {
if (mm_kernel_device_get_global_property_as_boolean (port_device, "ID_MM_TELIT_PORTS_TAGGED")) {
ctx->cgmi_retries = 0;
ctx->ati_retries = 0;
}

View File

@@ -2367,7 +2367,7 @@ ensure_ndisdup_support_checked (MMBroadbandModemHuawei *self,
/* First, check for devices which support NDISDUP on any AT port. These
* devices are tagged by udev */
if (mm_kernel_device_get_property_as_boolean (mm_port_peek_kernel_device (port), "ID_MM_HUAWEI_NDISDUP_SUPPORTED")) {
if (mm_kernel_device_get_global_property_as_boolean (mm_port_peek_kernel_device (port), "ID_MM_HUAWEI_NDISDUP_SUPPORTED")) {
mm_dbg ("This device (%s) can support ndisdup feature", mm_port_get_device (port));
self->priv->ndisdup_support = FEATURE_SUPPORTED;
}

View File

@@ -292,7 +292,7 @@ huawei_custom_init_step (HuaweiCustomInitContext *ctx)
/* Try to get a port map from the modem */
port = mm_port_probe_peek_port (ctx->probe);
if (!ctx->getportmode_done && !mm_kernel_device_get_property_as_boolean (port, "ID_MM_HUAWEI_DISABLE_GETPORTMODE")) {
if (!ctx->getportmode_done && !mm_kernel_device_get_global_property_as_boolean (port, "ID_MM_HUAWEI_DISABLE_GETPORTMODE")) {
if (ctx->getportmode_retries == 0) {
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
huawei_custom_init_context_complete_and_free (ctx);

View File

@@ -98,7 +98,7 @@ grab_port (MMPlugin *self,
* to show up with more than two AT-capable ports.
*/
if (pflags == MM_PORT_SERIAL_AT_FLAG_NONE &&
mm_kernel_device_get_property_as_boolean (port, "ID_MM_SIMTECH_TAGGED"))
mm_kernel_device_get_global_property_as_boolean (port, "ID_MM_SIMTECH_TAGGED"))
ptype = MM_PORT_TYPE_IGNORED;
}

View File

@@ -330,7 +330,7 @@ telit_custom_init (MMPortProbe *probe,
ctx->getportcfg_retries = 3;
/* If the device is tagged for supporting #PORTCFG do the custom init */
if (mm_kernel_device_get_property_as_boolean (port_device, "ID_MM_TELIT_PORTS_TAGGED")) {
if (mm_kernel_device_get_global_property_as_boolean (port_device, "ID_MM_TELIT_PORTS_TAGGED")) {
telit_custom_init_step (ctx);
return;
}

View File

@@ -141,7 +141,7 @@ grab_port (MMPlugin *self,
}
}
if (mm_kernel_device_get_property_as_boolean (port, "ID_MM_ZTE_ICERA_DHCP")) {
if (mm_kernel_device_get_global_property_as_boolean (port, "ID_MM_ZTE_ICERA_DHCP")) {
mm_dbg ("ZTE: Icera-based modem will use DHCP");
g_object_set (modem,
MM_BROADBAND_MODEM_ICERA_DEFAULT_IP_METHOD, MM_BEARER_IP_METHOD_DHCP,

View File

@@ -1067,6 +1067,13 @@ mm_kernel_device_generic_class_init (MMKernelDeviceGenericClass *klass)
kernel_device_class->get_property_as_int = kernel_device_get_property_as_int;
kernel_device_class->get_property_as_int_hex = kernel_device_get_property_as_int_hex;
/* Device-wide properties are stored per-port in the generic backend */
kernel_device_class->has_global_property = kernel_device_has_property;
kernel_device_class->get_global_property = kernel_device_get_property;
kernel_device_class->get_global_property_as_boolean = kernel_device_get_property_as_boolean;
kernel_device_class->get_global_property_as_int = kernel_device_get_property_as_int;
kernel_device_class->get_global_property_as_int_hex = kernel_device_get_property_as_int_hex;
properties[PROP_PROPERTIES] =
g_param_spec_object ("properties",
"Properties",

View File

@@ -352,16 +352,13 @@ kernel_device_get_physdev_uid (MMKernelDevice *_self)
return uid;
}
ensure_physdev (self);
if (self->priv->physdev) {
/* Try to load from properties set on the physical device */
if ((uid = g_udev_device_get_property (self->priv->physdev, "ID_MM_PHYSDEV_UID")) != NULL)
if ((uid = mm_kernel_device_get_global_property (MM_KERNEL_DEVICE (self), "ID_MM_PHYSDEV_UID")) != NULL)
return uid;
/* Use physical device sysfs path, if any */
if ((uid = g_udev_device_get_sysfs_path (self->priv->physdev)) != NULL)
if (self->priv->physdev && (uid = g_udev_device_get_sysfs_path (self->priv->physdev)) != NULL)
return uid;
}
/* If there is no physical device sysfs path, use the device sysfs itself */
g_assert (self->priv->device);
@@ -436,9 +433,9 @@ kernel_device_is_candidate (MMKernelDevice *_self,
* the device to a specific ModemManager driver, we need to ensure that all
* rules have been processed before handling a device.
*
* The udev tag applies to each port in a device. In other words, the flag
* This udev tag applies to each port in a device. In other words, the flag
* may be set in some ports, but not in others */
if (!g_udev_device_get_property_as_boolean (self->priv->device, "ID_MM_CANDIDATE"))
if (!mm_kernel_device_get_property_as_boolean (MM_KERNEL_DEVICE (self), "ID_MM_CANDIDATE"))
return FALSE;
/* Load physical device. If there is no physical device, we don't process
@@ -457,16 +454,15 @@ kernel_device_is_candidate (MMKernelDevice *_self,
return FALSE;
}
/* The blacklist applies to the device as a whole, and therefore the flag
* will be applied always in the physical device, not in each port. */
if (g_udev_device_get_property_as_boolean (self->priv->physdev, "ID_MM_DEVICE_IGNORE")) {
/* Ignore blacklisted devices. */
if (mm_kernel_device_get_global_property_as_boolean (MM_KERNEL_DEVICE (self), "ID_MM_DEVICE_IGNORE")) {
mm_dbg ("(%s/%s): device is blacklisted", subsys, name);
return FALSE;
}
/* Is the device in the manual-only greylist? If so, return if this is an
* automatic scan. */
if (!manual_scan && g_udev_device_get_property_as_boolean (self->priv->physdev, "ID_MM_DEVICE_MANUAL_SCAN_ONLY")) {
if (!manual_scan && mm_kernel_device_get_global_property_as_boolean (MM_KERNEL_DEVICE (self), "ID_MM_DEVICE_MANUAL_SCAN_ONLY")) {
mm_dbg ("(%s/%s): device probed only in manual scan", subsys, name);
return FALSE;
}
@@ -474,7 +470,7 @@ kernel_device_is_candidate (MMKernelDevice *_self,
/* If the physdev is a 'platform' or 'pnp' device that's not whitelisted, ignore it */
physdev_subsys = g_udev_device_get_subsystem (self->priv->physdev);
if ((!g_strcmp0 (physdev_subsys, "platform") || !g_strcmp0 (physdev_subsys, "pnp")) &&
(!g_udev_device_get_property_as_boolean (self->priv->physdev, "ID_MM_PLATFORM_DRIVER_PROBE"))) {
(!mm_kernel_device_get_global_property_as_boolean (MM_KERNEL_DEVICE (self), "ID_MM_PLATFORM_DRIVER_PROBE"))) {
mm_dbg ("(%s/%s): port's parent platform driver is not whitelisted", subsys, name);
return FALSE;
}
@@ -596,6 +592,103 @@ kernel_device_get_property_as_int_hex (MMKernelDevice *_self,
return ((s && mm_get_uint_from_hex_str (s, &out)) ? out : 0);
}
static gboolean
kernel_device_has_global_property (MMKernelDevice *_self,
const gchar *property)
{
MMKernelDeviceUdev *self;
g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), FALSE);
self = MM_KERNEL_DEVICE_UDEV (_self);
ensure_physdev (self);
if (self->priv->physdev && g_udev_device_has_property (self->priv->physdev, property))
return TRUE;
return kernel_device_has_property (_self, property);
}
static const gchar *
kernel_device_get_global_property (MMKernelDevice *_self,
const gchar *property)
{
MMKernelDeviceUdev *self;
const gchar *str;
g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), NULL);
self = MM_KERNEL_DEVICE_UDEV (_self);
ensure_physdev (self);
if (self->priv->physdev &&
g_udev_device_has_property (self->priv->physdev, property) &&
(str = g_udev_device_get_property (self->priv->physdev, property)) != NULL)
return str;
return kernel_device_get_property (_self, property);
}
static gboolean
kernel_device_get_global_property_as_boolean (MMKernelDevice *_self,
const gchar *property)
{
MMKernelDeviceUdev *self;
g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), FALSE);
self = MM_KERNEL_DEVICE_UDEV (_self);
ensure_physdev (self);
if (self->priv->physdev &&
g_udev_device_has_property (self->priv->physdev, property) &&
g_udev_device_get_property (self->priv->physdev, property))
return TRUE;
return kernel_device_get_property_as_boolean (_self, property);
}
static gint
kernel_device_get_global_property_as_int (MMKernelDevice *_self,
const gchar *property)
{
MMKernelDeviceUdev *self;
gint value;
g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), -1);
self = MM_KERNEL_DEVICE_UDEV (_self);
ensure_physdev (self);
if (self->priv->physdev &&
g_udev_device_has_property (self->priv->physdev, property) &&
(value = g_udev_device_get_property_as_int (self->priv->physdev, property)) >= 0)
return value;
return kernel_device_get_property_as_int (_self, property);
}
static guint
kernel_device_get_global_property_as_int_hex (MMKernelDevice *_self,
const gchar *property)
{
MMKernelDeviceUdev *self;
const gchar *s;
guint out = 0;
g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), G_MAXUINT);
self = MM_KERNEL_DEVICE_UDEV (_self);
ensure_physdev (self);
if (self->priv->physdev &&
g_udev_device_has_property (self->priv->physdev, property) &&
(s = g_udev_device_get_property (self->priv->physdev, property)) != NULL)
return ((s && mm_get_uint_from_hex_str (s, &out)) ? out : 0);
return kernel_device_get_property_as_int_hex (_self, property);
}
/*****************************************************************************/
MMKernelDevice *
@@ -785,6 +878,11 @@ mm_kernel_device_udev_class_init (MMKernelDeviceUdevClass *klass)
kernel_device_class->get_property_as_boolean = kernel_device_get_property_as_boolean;
kernel_device_class->get_property_as_int = kernel_device_get_property_as_int;
kernel_device_class->get_property_as_int_hex = kernel_device_get_property_as_int_hex;
kernel_device_class->has_global_property = kernel_device_has_global_property;
kernel_device_class->get_global_property = kernel_device_get_global_property;
kernel_device_class->get_global_property_as_boolean = kernel_device_get_global_property_as_boolean;
kernel_device_class->get_global_property_as_int = kernel_device_get_global_property_as_int;
kernel_device_class->get_global_property_as_int_hex = kernel_device_get_global_property_as_int_hex;
properties[PROP_UDEV_DEVICE] =
g_param_spec_object ("udev-device",

View File

@@ -177,6 +177,61 @@ mm_kernel_device_get_property_as_int_hex (MMKernelDevice *self,
0);
}
gboolean
mm_kernel_device_has_global_property (MMKernelDevice *self,
const gchar *property)
{
g_return_val_if_fail (MM_IS_KERNEL_DEVICE (self), FALSE);
return (MM_KERNEL_DEVICE_GET_CLASS (self)->has_global_property ?
MM_KERNEL_DEVICE_GET_CLASS (self)->has_global_property (self, property) :
FALSE);
}
const gchar *
mm_kernel_device_get_global_property (MMKernelDevice *self,
const gchar *property)
{
g_return_val_if_fail (MM_IS_KERNEL_DEVICE (self), NULL);
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property ?
MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property (self, property) :
NULL);
}
gboolean
mm_kernel_device_get_global_property_as_boolean (MMKernelDevice *self,
const gchar *property)
{
g_return_val_if_fail (MM_IS_KERNEL_DEVICE (self), FALSE);
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_boolean ?
MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_boolean (self, property) :
FALSE);
}
gint
mm_kernel_device_get_global_property_as_int (MMKernelDevice *self,
const gchar *property)
{
g_return_val_if_fail (MM_IS_KERNEL_DEVICE (self), -1);
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_int ?
MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_int (self, property) :
-1);
}
guint
mm_kernel_device_get_global_property_as_int_hex (MMKernelDevice *self,
const gchar *property)
{
g_return_val_if_fail (MM_IS_KERNEL_DEVICE (self), 0);
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_int_hex ?
MM_KERNEL_DEVICE_GET_CLASS (self)->get_global_property_as_int_hex (self, property) :
0);
}
/*****************************************************************************/
static void

View File

@@ -62,6 +62,12 @@ struct _MMKernelDeviceClass {
gboolean (* get_property_as_boolean) (MMKernelDevice *self, const gchar *property);
gint (* get_property_as_int) (MMKernelDevice *self, const gchar *property);
guint (* get_property_as_int_hex) (MMKernelDevice *self, const gchar *property);
gboolean (* has_global_property) (MMKernelDevice *self, const gchar *property);
const gchar * (* get_global_property) (MMKernelDevice *self, const gchar *property);
gboolean (* get_global_property_as_boolean) (MMKernelDevice *self, const gchar *property);
gint (* get_global_property_as_int) (MMKernelDevice *self, const gchar *property);
guint (* get_global_property_as_int_hex) (MMKernelDevice *self, const gchar *property);
};
GType mm_kernel_device_get_type (void);
@@ -82,10 +88,18 @@ guint16 mm_kernel_device_get_physdev_pid (MMKernelDevice *self);
gboolean mm_kernel_device_cmp (MMKernelDevice *a, MMKernelDevice *b);
/* Standard properties are usually associated to single ports */
gboolean mm_kernel_device_has_property (MMKernelDevice *self, const gchar *property);
const gchar *mm_kernel_device_get_property (MMKernelDevice *self, const gchar *property);
gboolean mm_kernel_device_get_property_as_boolean (MMKernelDevice *self, const gchar *property);
gint mm_kernel_device_get_property_as_int (MMKernelDevice *self, const gchar *property);
guint mm_kernel_device_get_property_as_int_hex (MMKernelDevice *self, const gchar *property);
/* Global properties are usually associated to full devices */
gboolean mm_kernel_device_has_global_property (MMKernelDevice *self, const gchar *property);
const gchar *mm_kernel_device_get_global_property (MMKernelDevice *self, const gchar *property);
gboolean mm_kernel_device_get_global_property_as_boolean (MMKernelDevice *self, const gchar *property);
gint mm_kernel_device_get_global_property_as_int (MMKernelDevice *self, const gchar *property);
guint mm_kernel_device_get_global_property_as_int_hex (MMKernelDevice *self, const gchar *property);
#endif /* MM_KERNEL_DEVICE_H */

View File

@@ -417,8 +417,8 @@ apply_pre_probing_filters (MMPlugin *self,
* supported. If that is the case, filter by udev tag */
if (self->priv->udev_tags) {
for (i = 0; self->priv->udev_tags[i]; i++) {
/* Check if the port was tagged */
if (mm_kernel_device_get_property_as_boolean (port, self->priv->udev_tags[i]))
/* Check if the port or device was tagged */
if (mm_kernel_device_get_global_property_as_boolean (port, self->priv->udev_tags[i]))
break;
}