1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
/*
* Copyright 2025 NVIDIA Corporation & Affiliates
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "config.h"
#include "fu-devlink-component.h"
#include "fu-devlink-device.h"
/**
* FU_DEVLINK_DEVICE_FLAG_OMIT_COMPONENT_NAME:
*
* Do not set the DEVLINK_ATTR_FLASH_UPDATE_COMPONENT attribute when flashing firmware.
* This allows for firmware updates without specifying a specific component name.
*
* Since: 2.0.15
*/
#define FU_DEVLINK_DEVICE_FLAG_OMIT_COMPONENT_NAME "omit-component-name"
struct _FuDevlinkComponent {
FuDevice parent_instance;
GPtrArray *instance_keys;
};
G_DEFINE_TYPE(FuDevlinkComponent, fu_devlink_component, FU_TYPE_DEVICE)
static gboolean
fu_devlink_component_write_firmware(FuDevice *device,
FuFirmware *firmware,
FuProgress *progress,
FwupdInstallFlags flags,
GError **error)
{
FuDevlinkComponent *self = FU_DEVLINK_COMPONENT(device);
FuDevice *proxy;
gboolean omit_component_name =
fu_device_has_private_flag(FU_DEVICE(self), FU_DEVLINK_DEVICE_FLAG_OMIT_COMPONENT_NAME);
proxy = fu_device_get_proxy(device, error);
if (proxy == NULL)
return FALSE;
return fu_devlink_device_write_firmware_component(FU_DEVLINK_DEVICE(proxy),
fu_device_get_logical_id(device),
omit_component_name,
firmware,
progress,
flags,
error);
}
void
fu_devlink_component_add_instance_keys(FuDevlinkComponent *self, gchar **keys)
{
if (self->instance_keys == NULL)
self->instance_keys = g_ptr_array_new_with_free_func((GDestroyNotify)g_strfreev);
g_ptr_array_add(self->instance_keys, keys);
}
static gboolean
fu_devlink_component_probe(FuDevice *device, GError **error)
{
FuDevlinkComponent *self = FU_DEVLINK_COMPONENT(device);
FuDevice *proxy;
g_autofree gchar *subsystem = NULL;
g_autoptr(GStrvBuilder) basekeys_builder = NULL;
g_auto(GStrv) basekeys = NULL;
/* declare all variables at the beginning */
proxy = fu_device_get_proxy(device, error);
if (proxy == NULL)
return FALSE;
subsystem = g_ascii_strup(fu_devlink_device_get_bus_name(FU_DEVLINK_DEVICE(proxy)), -1);
basekeys_builder = g_strv_builder_new();
if (fu_device_get_instance_str(device, "VEN") != NULL &&
fu_device_get_instance_str(device, "DEV") != NULL) {
g_strv_builder_add(basekeys_builder, "VEN");
g_strv_builder_add(basekeys_builder, "DEV");
}
g_strv_builder_add(basekeys_builder, "COMPONENT");
basekeys = g_strv_builder_end(basekeys_builder);
/* build instance id just for component name */
if (!fu_device_build_instance_id_strv(device, subsystem, basekeys, error))
return FALSE;
if (self->instance_keys == NULL)
return TRUE;
/* Build instance id for each fixed versions array from quirk file for which
kernel provides all fixed version values. */
for (guint i = 0; i < self->instance_keys->len; i++) {
GStrv instance_keys = g_ptr_array_index(self->instance_keys, i);
guint j;
g_autoptr(GStrvBuilder) keys_builder = g_strv_builder_new();
g_auto(GStrv) keys = NULL;
/* future optimization: use g_strv_builder_addv() when available */
for (j = 0; basekeys[j] != NULL; j++)
g_strv_builder_add(keys_builder, basekeys[j]);
for (j = 0; instance_keys[j] != NULL; j++)
g_strv_builder_add(keys_builder, instance_keys[j]);
keys = g_strv_builder_end(keys_builder);
if (!fu_device_build_instance_id_strv(device, subsystem, keys, error))
return FALSE;
}
return TRUE;
}
static gboolean
fu_devlink_component_reload(FuDevice *device, GError **error)
{
FuDevice *proxy = fu_device_get_proxy(device, error);
if (proxy == NULL)
return FALSE;
return fu_device_reload(proxy, error);
}
static gboolean
fu_devlink_component_activate(FuDevice *device, FuProgress *progress, GError **error)
{
FuDevice *proxy = fu_device_get_proxy(device, error);
if (proxy == NULL)
return FALSE;
return fu_device_activate(proxy, progress, error);
}
static gboolean
fu_devlink_component_prepare(FuDevice *device,
FuProgress *progress,
FwupdInstallFlags flags,
GError **error)
{
FuDevice *proxy = fu_device_get_proxy(device, error);
if (proxy == NULL)
return FALSE;
return fu_device_prepare(proxy, progress, flags, error);
}
static gboolean
fu_devlink_component_cleanup(FuDevice *device,
FuProgress *progress,
FwupdInstallFlags flags,
GError **error)
{
FuDevice *proxy = fu_device_get_proxy(device, error);
if (proxy == NULL)
return FALSE;
return fu_device_cleanup(proxy, progress, flags, error);
}
static void
fu_devlink_component_set_progress(FuDevice *device, FuProgress *progress)
{
fu_progress_set_id(progress, G_STRLOC);
fu_progress_add_flag(progress, FU_PROGRESS_FLAG_GUESSED);
fu_progress_add_step(progress, FWUPD_STATUS_DECOMPRESSING, 0, "prepare-fw");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_RESTART, 0, "detach");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 57, "write");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_RESTART, 0, "attach");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_BUSY, 43, "reload");
}
FuDevlinkComponent *
fu_devlink_component_new(FuDevice *proxy, const gchar *logical_id)
{
g_autoptr(FuDevlinkComponent) self = NULL;
g_return_val_if_fail(logical_id != NULL, NULL);
self =
g_object_new(FU_TYPE_DEVLINK_COMPONENT, "proxy", proxy, "logical-id", logical_id, NULL);
fu_device_add_instance_str(FU_DEVICE(self), "COMPONENT", logical_id);
return g_steal_pointer(&self);
}
static void
fu_devlink_component_init(FuDevlinkComponent *self)
{
fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_UPDATABLE);
fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_SIGNED_PAYLOAD);
fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_INTERNAL);
fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_REQUIRE_AC);
fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_DUAL_IMAGE);
fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_USABLE_DURING_UPDATE);
fu_device_add_protocol(FU_DEVICE(self), "org.kernel.devlink");
fu_device_add_private_flag(FU_DEVICE(self), FU_DEVICE_PRIVATE_FLAG_MD_SET_FLAGS);
fu_device_add_private_flag(FU_DEVICE(self), FU_DEVICE_PRIVATE_FLAG_REFCOUNTED_PROXY);
fu_device_add_private_flag(FU_DEVICE(self), FU_DEVICE_PRIVATE_FLAG_USE_PROXY_FALLBACK);
fu_device_add_private_flag(FU_DEVICE(self), FU_DEVICE_PRIVATE_FLAG_PARENT_NAME_PREFIX);
fu_device_set_proxy_gtype(FU_DEVICE(self), FU_TYPE_DEVLINK_DEVICE);
fu_device_register_private_flag(FU_DEVICE(self),
FU_DEVLINK_DEVICE_FLAG_OMIT_COMPONENT_NAME);
}
static void
fu_devlink_component_finalize(GObject *object)
{
FuDevlinkComponent *self = FU_DEVLINK_COMPONENT(object);
if (self->instance_keys != NULL)
g_ptr_array_unref(self->instance_keys);
G_OBJECT_CLASS(fu_devlink_component_parent_class)->finalize(object);
}
static void
fu_devlink_component_class_init(FuDevlinkComponentClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
FuDeviceClass *device_class = FU_DEVICE_CLASS(klass);
object_class->finalize = fu_devlink_component_finalize;
device_class->write_firmware = fu_devlink_component_write_firmware;
device_class->set_progress = fu_devlink_component_set_progress;
device_class->probe = fu_devlink_component_probe;
device_class->reload = fu_devlink_component_reload;
device_class->activate = fu_devlink_component_activate;
device_class->prepare = fu_devlink_component_prepare;
device_class->cleanup = fu_devlink_component_cleanup;
}
|