[PATCH 06/16] efi_loader: efi_net: Manage EFI net objects with efi_[dis]connect_controller
Adriano Cordova
adrianox at gmail.com
Tue Mar 11 17:47:48 CET 2025
For U-Boot devices connect_controller gets called in efi_netobj_init
Signed-off-by: Adriano Cordova <adriano.cordova at canonical.com>
---
include/efi_loader.h | 2 +-
lib/efi_driver/efi_net_device.c | 4 +---
lib/efi_loader/efi_net.c | 30 ++++++++++++++++++++++++------
3 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 9c5ddc12cea..38ea0c5c672 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -660,7 +660,7 @@ efi_status_t efi_gop_register(void);
int efi_net_register(void *ctx, struct event *event);
/* Called to unregister an EFI network device */
int efi_net_unregister(void *ctx, struct event *event);
-/* Called to initialized registered network devices */
+/* Called to initialized registered EFI network devices */
efi_status_t efi_net_init(void);
efi_status_t efi_net_do_start(void);
/* Called by efi_net_register to make the ip4 config2 protocol available */
diff --git a/lib/efi_driver/efi_net_device.c b/lib/efi_driver/efi_net_device.c
index f2167485ab9..90d695da2b1 100644
--- a/lib/efi_driver/efi_net_device.c
+++ b/lib/efi_driver/efi_net_device.c
@@ -24,11 +24,9 @@ static efi_status_t efi_net_bind_drv(
struct efi_driver_binding_extended_protocol *this,
efi_handle_t handle, void *interface)
{
-
EFI_PRINT("%s: handle %p, interface %p\n", __func__, handle, interface);
-
- return EFI_UNSUPPORTED;
+ return EFI_SUCCESS;
}
/**
diff --git a/lib/efi_loader/efi_net.c b/lib/efi_loader/efi_net.c
index a14ecf3d182..fd43eec4c03 100644
--- a/lib/efi_loader/efi_net.c
+++ b/lib/efi_loader/efi_net.c
@@ -1127,7 +1127,7 @@ efi_status_t efi_net_do_start(void)
int i, r;
for (i = 0; i < MAX_EFI_NET_OBJS; i++) {
- if (net_objs[i]) {
+ if (net_objs[i] && net_objs[i]->dev) {
r = efi_netobj_start(net_objs[i]);
if (r)
return EFI_DEVICE_ERROR;
@@ -1200,7 +1200,7 @@ static int efi_netobj_init(struct efi_net_obj *netobj)
/* Fill in object data */
r = efi_add_protocol(netobj->handle, &efi_net_guid,
- netobj->net);
+ netobj->net);
if (r != EFI_SUCCESS)
goto failure_to_add_protocol;
@@ -1248,12 +1248,16 @@ static int efi_netobj_init(struct efi_net_obj *netobj)
netobj->pxe.set_packets = efi_pxe_base_code_set_packets;
netobj->pxe.mode = &netobj->pxe_mode;
+ r = EFI_CALL(efi_connect_controller(netobj->handle, NULL, NULL, 0));
+ if (r != EFI_SUCCESS)
+ return -1;
+
/*
* Scan dhcp entries for one corresponding
* to this udevice, from newest to oldest
*/
i = (next_dhcp_entry + MAX_NUM_DHCP_ENTRIES - 1) % MAX_NUM_DHCP_ENTRIES;
- for (j = 0; dhcp_cache[i].is_valid && j < MAX_NUM_DHCP_ENTRIES;
+ for (j = 0; dev && dhcp_cache[i].is_valid && j < MAX_NUM_DHCP_ENTRIES;
i = (i + MAX_NUM_DHCP_ENTRIES - 1) % MAX_NUM_DHCP_ENTRIES, j++) {
if (dev == dhcp_cache[i].dev) {
netobj->pxe_mode.dhcp_ack = *dhcp_cache[i].dhcp_ack;
@@ -1305,7 +1309,6 @@ static int efi_netobj_init(struct efi_net_obj *netobj)
if (r != EFI_SUCCESS)
goto failure_to_add_protocol;
#endif
- printf("efi_net init device number %d\n", netobj->efi_seq_num);
return 0;
failure_to_add_protocol:
printf("ERROR: Failure to add protocol\n");
@@ -1426,7 +1429,8 @@ int efi_net_register(void *ctx, struct event *event)
{
struct udevice *dev;
enum uclass_id id;
- int i;
+ struct efi_net_obj *netobj;
+ int i, r;
dev = event->data.dm.dev;
if (!dev) {
@@ -1445,9 +1449,19 @@ int efi_net_register(void *ctx, struct event *event)
}
}
- if (!efi_netobj_alloc(NULL, NULL, dev))
+ netobj = efi_netobj_alloc(NULL, NULL, dev);
+
+ if (!netobj)
return -1;
+ if (efi_obj_list_initialized == EFI_SUCCESS) {
+ if (!efi_netobj_is_active(netobj)) {
+ r = efi_netobj_init(netobj);
+ if (r)
+ return -1;
+ }
+ }
+
return 0;
}
@@ -1491,6 +1505,10 @@ int efi_net_unregister(void *ctx, struct event *event)
return 0;
if (efi_netobj_is_active(netobj)) {
+ ret = EFI_CALL(efi_disconnect_controller(netobj->handle, NULL, NULL));
+ if (ret != EFI_SUCCESS)
+ return -1;
+
ret = EFI_CALL(efi_close_event(netobj->wait_for_packet));
if (ret != EFI_SUCCESS)
return -1;
--
2.48.1
More information about the U-Boot
mailing list