#include "gadget_chips.h"
-#define USB_NET_NAME "usb0"
+#define USB_NET_NAME "usb_ether"
#define atomic_read
extern struct platform_data brd;
debug("%s: status %d\n", __func__, req->status);
packet_received = 1;
-
- if (req)
- dev->rx_req = req;
}
static int alloc_requests(struct eth_dev *dev, unsigned n, gfp_t gfp_flags)
dev->tx_req = usb_ep_alloc_request(dev->in_ep, 0);
if (!dev->tx_req)
- goto fail;
+ goto fail1;
dev->rx_req = usb_ep_alloc_request(dev->out_ep, 0);
if (!dev->rx_req)
- goto fail;
+ goto fail2;
return 0;
-fail:
+fail2:
+ usb_ep_free_request(dev->in_ep, dev->tx_req);
+fail1:
error("can't alloc requests");
return -1;
}
/* unregister_netdev (dev->net);*/
/* free_netdev(dev->net);*/
+ dev->gadget = NULL;
set_gadget_data(gadget, NULL);
}
}
dev->net = &l_netdev;
- strcpy(dev->net->name, USB_NET_NAME);
dev->cdc = cdc;
dev->zlp = zlp;
goto fail;
}
+ /* Configure default mac-addresses for the USB ethernet device */
+#ifdef CONFIG_USBNET_DEV_ADDR
+ strlcpy(dev_addr, CONFIG_USBNET_DEV_ADDR, sizeof(dev_addr));
+#endif
+#ifdef CONFIG_USBNET_HOST_ADDR
+ strlcpy(host_addr, CONFIG_USBNET_HOST_ADDR, sizeof(host_addr));
+#endif
+ /* Check if the user overruled the MAC addresses */
+ if (getenv("usbnet_devaddr"))
+ strlcpy(dev_addr, getenv("usbnet_devaddr"),
+ sizeof(dev_addr));
+
+ if (getenv("usbnet_hostaddr"))
+ strlcpy(host_addr, getenv("usbnet_hostaddr"),
+ sizeof(host_addr));
+
+ if (!is_eth_addr_valid(dev_addr)) {
+ error("Need valid 'usbnet_devaddr' to be set");
+ goto fail;
+ }
+ if (!is_eth_addr_valid(host_addr)) {
+ error("Need valid 'usbnet_hostaddr' to be set");
+ goto fail;
+ }
+
+ if (usb_gadget_register_driver(ð_driver) < 0)
+ goto fail;
+
dev->network_started = 0;
- dev->tx_req = NULL;
- dev->rx_req = NULL;
packet_received = 0;
packet_sent = 0;
usb_gadget_handle_interrupts();
}
+ packet_received = 0;
rx_submit(dev, dev->rx_req, 0);
return 0;
fail:
volatile void *packet, int length)
{
int retval;
- struct usb_request *req = NULL;
struct eth_dev *dev = &l_ethdev;
+ struct usb_request *req = dev->tx_req;
unsigned long ts;
unsigned long timeout = USB_CONNECT_TIMEOUT;
debug("%s:...\n", __func__);
- req = dev->tx_req;
-
req->buf = (void *)packet;
req->context = NULL;
req->complete = tx_complete;
NetReceive(NetRxPackets[0], dev->rx_req->length);
packet_received = 0;
- if (dev->rx_req)
- rx_submit(dev, dev->rx_req, 0);
+ rx_submit(dev, dev->rx_req, 0);
} else
error("dev->rx_req invalid");
}
return;
}
+ /* If the gadget not registered, simple return */
+ if (!dev->gadget)
+ return;
+
usb_gadget_disconnect(dev->gadget);
+ usb_gadget_unregister_driver(ð_driver);
}
static struct usb_gadget_driver eth_driver = {
int usb_eth_initialize(bd_t *bi)
{
- int status = 0;
struct eth_device *netdev = &l_netdev;
- sprintf(netdev->name, "usb_ether");
+ strlcpy(netdev->name, USB_NET_NAME, sizeof(netdev->name));
netdev->init = usb_eth_init;
netdev->send = usb_eth_send;
#ifdef CONFIG_MCAST_TFTP
#error not supported
#endif
- /* Configure default mac-addresses for the USB ethernet device */
-#ifdef CONFIG_USBNET_DEV_ADDR
- strncpy(dev_addr, CONFIG_USBNET_DEV_ADDR, sizeof(dev_addr));
-#endif
-#ifdef CONFIG_USBNET_HOST_ADDR
- strncpy(host_addr, CONFIG_USBNET_HOST_ADDR, sizeof(host_addr));
-#endif
- /* Check if the user overruled the MAC addresses */
- if (getenv("usbnet_devaddr"))
- strncpy(dev_addr, getenv("usbnet_devaddr"),
- sizeof(dev_addr));
-
- if (getenv("usbnet_hostaddr"))
- strncpy(host_addr, getenv("usbnet_hostaddr"),
- sizeof(host_addr));
-
- /* Make sure both strings are terminated */
- dev_addr[sizeof(dev_addr)-1] = '\0';
- host_addr[sizeof(host_addr)-1] = '\0';
-
- if (!is_eth_addr_valid(dev_addr)) {
- error("Need valid 'usbnet_devaddr' to be set");
- status = -1;
- }
- if (!is_eth_addr_valid(host_addr)) {
- error("Need valid 'usbnet_hostaddr' to be set");
- status = -1;
- }
- if (status)
- goto fail;
-
- status = usb_gadget_register_driver(ð_driver);
- if (status < 0)
- goto fail;
-
eth_register(netdev);
return 0;
-
-fail:
- error("%s failed. error = %d", __func__, status);
- return status;
}
-