]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/usb/gadget/ether.c
Move console definitions into a new console.h file
[people/ms/u-boot.git] / drivers / usb / gadget / ether.c
index de880ffeb8a6e9c1821ce88ada68134f214fa410..cfe9a24e24fbb8584bdb24887794bf7361b1bb20 100644 (file)
@@ -5,29 +5,20 @@
  * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
  * Copyright (C) 2008 Nokia Corporation
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
+#include <console.h>
 #include <asm/errno.h>
 #include <linux/netdevice.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/cdc.h>
 #include <linux/usb/gadget.h>
 #include <net.h>
+#include <usb.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <linux/ctype.h>
 
 #include "gadget_chips.h"
 
 #define atomic_read
 extern struct platform_data brd;
-#define spin_lock(x)
-#define spin_unlock(x)
 
 
 unsigned packet_received, packet_sent;
 
-#define GFP_ATOMIC ((gfp_t) 0)
-#define GFP_KERNEL ((gfp_t) 0)
-
 /*
  * Ethernet gadget driver -- with CDC and non-CDC options
  * Builds on hardware support for a full duplex link.
@@ -85,7 +71,6 @@ unsigned packet_received, packet_sent;
 #define ETH_ZLEN       60              /* Min. octets in frame sans FCS */
 #define ETH_DATA_LEN   1500            /* Max. octets in payload        */
 #define ETH_FRAME_LEN  PKTSIZE_ALIGN   /* Max. octets in frame sans FCS */
-#define ETH_FCS_LEN    4               /* Octets in the FCS             */
 
 #define DRIVER_DESC            "Ethernet Gadget"
 /* Based on linux 2.6.27 version */
@@ -647,6 +632,7 @@ fs_source_desc = {
 
        .bEndpointAddress =     USB_DIR_IN,
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
+       .wMaxPacketSize =       __constant_cpu_to_le16(64),
 };
 
 static struct usb_endpoint_descriptor
@@ -656,6 +642,7 @@ fs_sink_desc = {
 
        .bEndpointAddress =     USB_DIR_OUT,
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
+       .wMaxPacketSize =       __constant_cpu_to_le16(64),
 };
 
 static const struct usb_descriptor_header *fs_eth_function[11] = {
@@ -861,35 +848,12 @@ static struct usb_gadget_strings  stringtab = {
 };
 
 /*============================================================================*/
-static u8 control_req[USB_BUFSIZ];
+DEFINE_CACHE_ALIGN_BUFFER(u8, control_req, USB_BUFSIZ);
+
 #if defined(CONFIG_USB_ETH_CDC) || defined(CONFIG_USB_ETH_RNDIS)
-static u8 status_req[STATUS_BYTECOUNT] __attribute__ ((aligned(4)));
+DEFINE_CACHE_ALIGN_BUFFER(u8, status_req, STATUS_BYTECOUNT);
 #endif
 
-
-/**
- * strlcpy - Copy a %NUL terminated string into a sized buffer
- * @dest: Where to copy the string to
- * @src: Where to copy the string from
- * @size: size of destination buffer
- *
- * Compatible with *BSD: the result is always a valid
- * NUL-terminated string that fits in the buffer (unless,
- * of course, the buffer size is zero). It does not pad
- * out the result like strncpy() does.
- */
-size_t strlcpy(char *dest, const char *src, size_t size)
-{
-       size_t ret = strlen(src);
-
-       if (size) {
-               size_t len = (ret >= size) ? size - 1 : ret;
-               memcpy(dest, src, len);
-               dest[len] = '\0';
-       }
-       return ret;
-}
-
 /*============================================================================*/
 
 /*
@@ -1287,6 +1251,7 @@ eth_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                switch (wValue >> 8) {
 
                case USB_DT_DEVICE:
+                       device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
                        value = min(wLength, (u16) sizeof device_desc);
                        memcpy(req->buf, &device_desc, value);
                        break;
@@ -1545,6 +1510,8 @@ static int rx_submit(struct eth_dev *dev, struct usb_request *req,
         */
 
        debug("%s\n", __func__);
+       if (!req)
+               return -EINVAL;
 
        size = (ETHER_HDR_SIZE + dev->mtu + RX_EXTRA);
        size += dev->out_ep->maxpacket - 1;
@@ -1558,7 +1525,7 @@ static int rx_submit(struct eth_dev *dev, struct usb_request *req,
         * RNDIS headers involve variable numbers of LE32 values.
         */
 
-       req->buf = (u8 *) NetRxPackets[0];
+       req->buf = (u8 *)net_rx_packets[0];
        req->length = size;
        req->complete = rx_complete;
 
@@ -1681,13 +1648,13 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
        if (!eth_is_promisc (dev)) {
                u8              *dest = skb->data;
 
-               if (is_multicast_ether_addr(dest)) {
+               if (is_multicast_ethaddr(dest)) {
                        u16     type;
 
                        /* ignores USB_CDC_PACKET_TYPE_MULTICAST and host
                         * SET_ETHERNET_MULTICAST_FILTERS requests
                         */
-                       if (is_broadcast_ether_addr(dest))
+                       if (is_broadcast_ethaddr(dest))
                                type = USB_CDC_PACKET_TYPE_BROADCAST;
                        else
                                type = USB_CDC_PACKET_TYPE_ALL_MULTICAST;
@@ -1943,7 +1910,7 @@ static int eth_stop(struct eth_dev *dev)
                /* Wait until host receives OID_GEN_MEDIA_CONNECT_STATUS */
                ts = get_timer(0);
                while (get_timer(ts) < timeout)
-                       usb_gadget_handle_interrupts();
+                       usb_gadget_handle_interrupts(0);
 #endif
 
                rndis_uninit(dev->rndis_config);
@@ -1978,7 +1945,7 @@ static int is_eth_addr_valid(char *str)
                }
 
                /* Now check the contents. */
-               return is_valid_ether_addr(ea);
+               return is_valid_ethaddr(ea);
        }
        return 0;
 }
@@ -2007,7 +1974,7 @@ static int get_ether_addr(const char *str, u8 *dev_addr)
                        num |= (nibble(*str++));
                        dev_addr[i] = num;
                }
-               if (is_valid_ether_addr(dev_addr))
+               if (is_valid_ethaddr(dev_addr))
                        return 0;
        }
        return 1;
@@ -2169,7 +2136,6 @@ autoconf_fail:
                hs_subset_descriptors();
        }
 
-       device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
        usb_gadget_set_selfpowered(gadget);
 
        /* For now RNDIS is always a second config */
@@ -2349,6 +2315,8 @@ static int usb_eth_init(struct eth_device *netdev, bd_t *bd)
                goto fail;
        }
 
+       board_usb_init(0, USB_INIT_DEVICE);
+
        /* Configure default mac-addresses for the USB ethernet device */
 #ifdef CONFIG_USBNET_DEV_ADDR
        strlcpy(dev_addr, CONFIG_USBNET_DEV_ADDR, sizeof(dev_addr));
@@ -2395,7 +2363,7 @@ static int usb_eth_init(struct eth_device *netdev, bd_t *bd)
                        error("The remote end did not respond in time.");
                        goto fail;
                }
-               usb_gadget_handle_interrupts();
+               usb_gadget_handle_interrupts(0);
        }
 
        packet_received = 0;
@@ -2463,7 +2431,7 @@ static int usb_eth_send(struct eth_device *netdev, void *packet, int length)
                        printf("timeout sending packets to usb ethernet\n");
                        return -1;
                }
-               usb_gadget_handle_interrupts();
+               usb_gadget_handle_interrupts(0);
        }
        if (rndis_pkt)
                free(rndis_pkt);
@@ -2478,12 +2446,13 @@ static int usb_eth_recv(struct eth_device *netdev)
 {
        struct eth_dev *dev = &l_ethdev;
 
-       usb_gadget_handle_interrupts();
+       usb_gadget_handle_interrupts(0);
 
        if (packet_received) {
                debug("%s: packet received\n", __func__);
                if (dev->rx_req) {
-                       NetReceive(NetRxPackets[0], dev->rx_req->length);
+                       net_process_received_packet(net_rx_packets[0],
+                                                   dev->rx_req->length);
                        packet_received = 0;
 
                        rx_submit(dev, dev->rx_req, 0);
@@ -2523,11 +2492,12 @@ void usb_eth_halt(struct eth_device *netdev)
 
        /* Clear pending interrupt */
        if (dev->network_started) {
-               usb_gadget_handle_interrupts();
+               usb_gadget_handle_interrupts(0);
                dev->network_started = 0;
        }
 
        usb_gadget_unregister_driver(&eth_driver);
+       board_usb_cleanup(0, USB_INIT_DEVICE);
 }
 
 static struct usb_gadget_driver eth_driver = {
@@ -2537,6 +2507,7 @@ static struct usb_gadget_driver eth_driver = {
        .unbind         = eth_unbind,
 
        .setup          = eth_setup,
+       .reset          = eth_disconnect,
        .disconnect     = eth_disconnect,
 
        .suspend        = eth_suspend,