]> git.sur5r.net Git - u-boot/blobdiff - lib/efi_loader/efi_net.c
efi_loader: completely initialize network
[u-boot] / lib / efi_loader / efi_net.c
index e7fed79450205343e6af80c4e5fe7b33d77a6774..9afe76cdb31de77783e68338705f97b3f67a6686 100644 (file)
@@ -54,14 +54,46 @@ static efi_status_t EFIAPI efi_net_stop(struct efi_simple_network *this)
        return EFI_EXIT(EFI_SUCCESS);
 }
 
+/*
+ * Initialize network adapter and allocate transmit and receive buffers.
+ *
+ * This function implements the Initialize service of the
+ * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface
+ * (UEFI) specification for details.
+ *
+ * @this:      pointer to the protocol instance
+ * @extra_rx:  extra receive buffer to be allocated
+ * @extra_tx:  extra transmit buffer to be allocated
+ * @return:    status code
+ */
 static efi_status_t EFIAPI efi_net_initialize(struct efi_simple_network *this,
                                              ulong extra_rx, ulong extra_tx)
 {
+       int ret;
+       efi_status_t r = EFI_SUCCESS;
+
        EFI_ENTRY("%p, %lx, %lx", this, extra_rx, extra_tx);
 
-       eth_init();
+       if (!this) {
+               r = EFI_INVALID_PARAMETER;
+               goto error;
+       }
 
-       return EFI_EXIT(EFI_SUCCESS);
+       /* Setup packet buffers */
+       net_init();
+       /* Disable hardware and put it into the reset state */
+       eth_halt();
+       /* Set current device according to environment variables */
+       eth_set_current();
+       /* Get hardware ready for send and receive operations */
+       ret = eth_init();
+       if (ret < 0) {
+               eth_halt();
+               r = EFI_DEVICE_ERROR;
+       }
+
+error:
+       return EFI_EXIT(r);
 }
 
 static efi_status_t EFIAPI efi_net_reset(struct efi_simple_network *this,
@@ -341,7 +373,7 @@ efi_status_t efi_net_register(void)
         * Create WaitForPacket event.
         */
        r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK,
-                            efi_network_timer_notify, NULL,
+                            efi_network_timer_notify, NULL, NULL,
                             &wait_for_packet);
        if (r != EFI_SUCCESS) {
                printf("ERROR: Failed to register network event\n");
@@ -353,9 +385,11 @@ efi_status_t efi_net_register(void)
         *
         * The notification function is used to check if a new network packet
         * has been received.
+        *
+        * iPXE is running at TPL_CALLBACK most of the time. Use a higher TPL.
         */
-       r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
-                            efi_network_timer_notify, NULL,
+       r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
+                            efi_network_timer_notify, NULL, NULL,
                             &network_timer_event);
        if (r != EFI_SUCCESS) {
                printf("ERROR: Failed to register network event\n");