Leif's API fixes
This commit is contained in:
parent
bb9f92b9b1
commit
b385e0723b
11 changed files with 217 additions and 387 deletions
|
@ -19,6 +19,7 @@
|
|||
#include <grub/net/netbuff.h>
|
||||
#include <grub/uboot/disk.h>
|
||||
#include <grub/uboot/uboot.h>
|
||||
#include <grub/uboot/api_public.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/net.h>
|
||||
#include <grub/time.h>
|
||||
|
@ -26,19 +27,12 @@
|
|||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct ubootnet_data
|
||||
{
|
||||
void *cookie;
|
||||
int handle;
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
card_open (struct grub_net_card *dev)
|
||||
{
|
||||
int status;
|
||||
struct ubootnet_data *data = dev->data;
|
||||
|
||||
status = uboot_dev_open (data->handle);
|
||||
status = grub_uboot_dev_open (dev->data);
|
||||
if (status)
|
||||
return grub_error (GRUB_ERR_IO, "Couldn't open network card.");
|
||||
|
||||
|
@ -48,16 +42,13 @@ card_open (struct grub_net_card *dev)
|
|||
static void
|
||||
card_close (struct grub_net_card *dev)
|
||||
{
|
||||
struct ubootnet_data *data = dev->data;
|
||||
|
||||
uboot_dev_close (data->handle);
|
||||
grub_uboot_dev_close (dev->data);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack)
|
||||
{
|
||||
int status;
|
||||
struct ubootnet_data *data = dev->data;
|
||||
grub_size_t len;
|
||||
|
||||
len = (pack->tail - pack->data);
|
||||
|
@ -65,8 +56,7 @@ send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack)
|
|||
len = dev->mtu;
|
||||
|
||||
grub_memcpy (dev->txbuf, pack->data, len);
|
||||
status = uboot_dev_send (data->handle, dev->txbuf,
|
||||
len);
|
||||
status = grub_uboot_dev_send (dev->data, dev->txbuf, len);
|
||||
|
||||
if (status)
|
||||
return grub_error (GRUB_ERR_IO, N_("couldn't send network packet"));
|
||||
|
@ -77,7 +67,6 @@ static struct grub_net_buff *
|
|||
get_card_packet (struct grub_net_card *dev)
|
||||
{
|
||||
int rc;
|
||||
struct ubootnet_data *data = dev->data;
|
||||
grub_uint64_t start_time;
|
||||
struct grub_net_buff *nb;
|
||||
int actual;
|
||||
|
@ -92,7 +81,7 @@ get_card_packet (struct grub_net_card *dev)
|
|||
start_time = grub_get_time_ms ();
|
||||
do
|
||||
{
|
||||
rc = uboot_dev_recv (data->handle, nb->data, dev->mtu + 64, &actual);
|
||||
rc = grub_uboot_dev_recv (dev->data, nb->data, dev->mtu + 64, &actual);
|
||||
grub_dprintf ("net", "rc=%d, actual=%d, time=%lld\n", rc, actual,
|
||||
grub_get_time_ms () - start_time);
|
||||
}
|
||||
|
@ -120,34 +109,23 @@ GRUB_MOD_INIT (ubootnet)
|
|||
int devcount, i;
|
||||
int nfound = 0;
|
||||
|
||||
devcount = uboot_dev_enum ();
|
||||
devcount = grub_uboot_dev_enum ();
|
||||
|
||||
for (i = 0; i < devcount; i++)
|
||||
{
|
||||
struct device_info *devinfo = uboot_dev_get (i);
|
||||
struct ubootnet_data *ubdata;
|
||||
struct device_info *devinfo = grub_uboot_dev_get (i);
|
||||
struct grub_net_card *card;
|
||||
|
||||
if (!(devinfo->type & DEV_TYP_NET))
|
||||
continue;
|
||||
|
||||
ubdata = grub_malloc (sizeof (struct ubootnet_data));
|
||||
if (!ubdata)
|
||||
{
|
||||
grub_print_error ();
|
||||
return;
|
||||
}
|
||||
|
||||
card = grub_zalloc (sizeof (struct grub_net_card));
|
||||
if (!card)
|
||||
{
|
||||
grub_free (ubdata);
|
||||
grub_print_error ();
|
||||
return;
|
||||
}
|
||||
|
||||
ubdata->handle = i;
|
||||
ubdata->cookie = devinfo->cookie;
|
||||
|
||||
/* FIXME: Any way to check this? */
|
||||
card->mtu = 1500;
|
||||
|
||||
|
@ -158,13 +136,12 @@ GRUB_MOD_INIT (ubootnet)
|
|||
card->txbuf = grub_zalloc (card->txbufsize);
|
||||
if (!card->txbuf)
|
||||
{
|
||||
grub_free (ubdata);
|
||||
grub_free (card);
|
||||
grub_print_error ();
|
||||
continue;
|
||||
}
|
||||
|
||||
card->data = ubdata;
|
||||
card->data = devinfo;
|
||||
card->flags = 0;
|
||||
card->name = grub_xasprintf ("ubnet_%d", ++nfound);
|
||||
card->idle_poll_delay_ms = 10;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue