Lines Matching +full:- +full:- +full:disable +full:- +full:malloc +full:- +full:trim

1 // SPDX-License-Identifier: GPL-2.0+
3 * ether.c -- Ethernet gadget driver, with CDC and non-CDC options
5 * Copyright (C) 2003-2005,2008 David Brownell
6 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
20 #include <malloc.h>
29 #include <dm/uclass-internal.h>
30 #include <dm/device-internal.h>
41 * Ethernet gadget driver -- with CDC and non-CDC options
47 * this USB-IF standard as its open-systems interoperability solution;
51 * TLA-soup. "CDC ACM" (Abstract Control Model) is for modems, and a new
55 * implement a "minimalist" vendor-agnostic CDC core: same framing, but
56 * link-level setup only requires activating the configuration. Only the
65 * those MS-Windows drivers. Those added descriptors make it resemble a
89 /* CDC and RNDIS support the same host-chosen outgoing packet filters. */
97 /*-------------------------------------------------------------------------*/
133 * This version autoconfigures as much as possible at run-time.
135 * It also ASSUMES a self-powered device, without remote wakeup,
139 /*-------------------------------------------------------------------------*/
153 /*-------------------------------------------------------------------------*/
163 return dev->cdc; /* depends on what hardware we found */ in is_cdc()
171 return dev->rndis; in rndis_active()
182 /* peak bulk transfer bits-per-second */
195 /* for dual-speed hardware, use deeper queues at highspeed */
197 (DEFAULT_QLEN*((gadget->speed == USB_SPEED_HIGH) ? qmult : 1))
201 return (g->speed == USB_SPEED_HIGH) ? HS_BPS : FS_BPS; in BITRATE()
218 /*-------------------------------------------------------------------------*/
221 * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
222 * Instead: allocate your own, using normal USB-IF procedures.
230 #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */
234 * ARM Linux has used for ethernet-over-usb, both with sa1100 and
235 * with pxa250. We're protocol-compatible, if the host-side drivers
237 * drivers that need to hard-wire endpoint numbers have a hook.
241 * RNDIS (like SA-1100, with no interrupt endpoint, or anything that
242 * doesn't handle control-OUT).
245 #define SIMPLE_PRODUCT_NUM 0x505a /* Linux-USB "CDC Subset" Device */
251 * the non-RNDIS configuration.
259 * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
271 static char *iManufacturer = "U-Boot";
284 /*-------------------------------------------------------------------------*/
289 * also optional class-specific notification interrupt transfer.
322 * an RNDIS-only configuration.
324 * FIXME define some higher-powered configurations to make it easier
391 * RNDIS shares a lot with CDC-Ethernet, since it's a variant of the
392 * CDC-ACM (modem) spec. Unfortunately MSFT's RNDIS driver is buggy; it
537 * some drivers (like Linux 2.4 cdc-ether!) "need" it to exist even
540 * encapsulated commands (vendor-specific, using control-OUT).
619 * "Simple" CDC-subset option is a simple vendor-neutral model that most
822 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) in ep_desc()
827 /*-------------------------------------------------------------------------*/
829 /* descriptors that are built on-demand */
838 /* static strings, in UTF-8 */
860 .language = 0x0409, /* en-us */
886 hs = (g->speed == USB_SPEED_HIGH); in config_buf()
893 return -EINVAL; in config_buf()
910 /* for now, don't advertise srp-only devices */ in config_buf()
917 ((struct usb_config_descriptor *) buf)->bDescriptorType = type; in config_buf()
921 /*-------------------------------------------------------------------------*/
930 struct usb_gadget *gadget = dev->gadget; in set_ether_config()
934 if (!subset_active(dev) && dev->status_ep) { in set_ether_config()
935 dev->status = ep_desc(gadget, &hs_status_desc, in set_ether_config()
937 dev->status_ep->driver_data = dev; in set_ether_config()
939 result = usb_ep_enable(dev->status_ep, dev->status); in set_ether_config()
941 debug("enable %s --> %d\n", in set_ether_config()
942 dev->status_ep->name, result); in set_ether_config()
948 dev->in = ep_desc(gadget, &hs_source_desc, &fs_source_desc); in set_ether_config()
949 dev->in_ep->driver_data = dev; in set_ether_config()
951 dev->out = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc); in set_ether_config()
952 dev->out_ep->driver_data = dev; in set_ether_config()
964 result = usb_ep_enable(dev->in_ep, dev->in); in set_ether_config()
966 debug("enable %s --> %d\n", in set_ether_config()
967 dev->in_ep->name, result); in set_ether_config()
971 result = usb_ep_enable(dev->out_ep, dev->out); in set_ether_config()
973 debug("enable %s --> %d\n", in set_ether_config()
974 dev->out_ep->name, result); in set_ether_config()
983 /* on error, disable any endpoints */ in set_ether_config()
985 if (!subset_active(dev) && dev->status_ep) in set_ether_config()
986 (void) usb_ep_disable(dev->status_ep); in set_ether_config()
987 dev->status = NULL; in set_ether_config()
988 (void) usb_ep_disable(dev->in_ep); in set_ether_config()
989 (void) usb_ep_disable(dev->out_ep); in set_ether_config()
990 dev->in = NULL; in set_ether_config()
991 dev->out = NULL; in set_ether_config()
994 * activate non-CDC configs right away in set_ether_config()
1006 if (dev->config == 0) in eth_reset_config()
1011 rndis_uninit(dev->rndis_config); in eth_reset_config()
1014 * disable endpoints, forcing (synchronous) completion of in eth_reset_config()
1018 if (dev->in) { in eth_reset_config()
1019 usb_ep_disable(dev->in_ep); in eth_reset_config()
1020 if (dev->tx_req) { in eth_reset_config()
1021 usb_ep_free_request(dev->in_ep, dev->tx_req); in eth_reset_config()
1022 dev->tx_req = NULL; in eth_reset_config()
1025 if (dev->out) { in eth_reset_config()
1026 usb_ep_disable(dev->out_ep); in eth_reset_config()
1027 if (dev->rx_req) { in eth_reset_config()
1028 usb_ep_free_request(dev->out_ep, dev->rx_req); in eth_reset_config()
1029 dev->rx_req = NULL; in eth_reset_config()
1032 if (dev->status) in eth_reset_config()
1033 usb_ep_disable(dev->status_ep); in eth_reset_config()
1035 dev->rndis = 0; in eth_reset_config()
1036 dev->cdc_filter = 0; in eth_reset_config()
1037 dev->config = 0; in eth_reset_config()
1048 struct usb_gadget *gadget = dev->gadget; in eth_set_config()
1051 && dev->config in eth_set_config()
1052 && dev->tx_qlen != 0) { in eth_set_config()
1055 return -ESPIPE; in eth_set_config()
1065 dev->rndis = 1; in eth_set_config()
1070 result = -EINVAL; in eth_set_config()
1079 usb_gadget_vbus_draw(dev->gadget, in eth_set_config()
1080 gadget_is_otg(dev->gadget) ? 8 : 100); in eth_set_config()
1086 usb_gadget_vbus_draw(dev->gadget, power); in eth_set_config()
1088 switch (gadget->speed) { in eth_set_config()
1099 dev->config = number; in eth_set_config()
1111 /*-------------------------------------------------------------------------*/
1119 * we want this CDC Ethernet code to be vendor-neutral, we don't use that
1124 struct usb_cdc_notification *event = req->buf; in eth_status_complete()
1125 int value = req->status; in eth_status_complete()
1126 struct eth_dev *dev = ep->driver_data; in eth_status_complete()
1129 if (event->bNotificationType == USB_CDC_NOTIFY_NETWORK_CONNECTION in eth_status_complete()
1131 __le32 *data = req->buf + sizeof *event; in eth_status_complete()
1133 event->bmRequestType = 0xA1; in eth_status_complete()
1134 event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE; in eth_status_complete()
1135 event->wValue = __constant_cpu_to_le16(0); in eth_status_complete()
1136 event->wIndex = __constant_cpu_to_le16(1); in eth_status_complete()
1137 event->wLength = __constant_cpu_to_le16(8); in eth_status_complete()
1140 data[0] = data[1] = cpu_to_le32(BITRATE(dev->gadget)); in eth_status_complete()
1142 req->length = STATUS_BYTECOUNT; in eth_status_complete()
1144 debug("send SPEED_CHANGE --> %d\n", value); in eth_status_complete()
1147 } else if (value != -ECONNRESET) { in eth_status_complete()
1148 debug("event %02x --> %d\n", in eth_status_complete()
1149 event->bNotificationType, value); in eth_status_complete()
1150 if (event->bNotificationType == in eth_status_complete()
1152 dev->network_started = 1; in eth_status_complete()
1156 req->context = NULL; in eth_status_complete()
1161 struct usb_request *req = dev->stat_req; in issue_start_status()
1170 * unlink-one primitive has way too many error modes. in issue_start_status()
1173 * FIXME iff req->context != null just dequeue it in issue_start_status()
1175 usb_ep_disable(dev->status_ep); in issue_start_status()
1176 usb_ep_enable(dev->status_ep, dev->status); in issue_start_status()
1182 event = req->buf; in issue_start_status()
1183 event->bmRequestType = 0xA1; in issue_start_status()
1184 event->bNotificationType = USB_CDC_NOTIFY_NETWORK_CONNECTION; in issue_start_status()
1185 event->wValue = __constant_cpu_to_le16(1); /* connected */ in issue_start_status()
1186 event->wIndex = __constant_cpu_to_le16(1); in issue_start_status()
1187 event->wLength = 0; in issue_start_status()
1189 req->length = sizeof *event; in issue_start_status()
1190 req->complete = eth_status_complete; in issue_start_status()
1191 req->context = dev; in issue_start_status()
1193 value = usb_ep_queue(dev->status_ep, req, GFP_ATOMIC); in issue_start_status()
1195 debug("status buf queue --> %d\n", value); in issue_start_status()
1200 /*-------------------------------------------------------------------------*/
1204 if (req->status || req->actual != req->length) in eth_setup_complete()
1205 debug("setup complete --> %d, %d/%d\n", in eth_setup_complete()
1206 req->status, req->actual, req->length); in eth_setup_complete()
1213 if (req->status || req->actual != req->length) in rndis_response_complete()
1214 debug("rndis response complete --> %d, %d/%d\n", in rndis_response_complete()
1215 req->status, req->actual, req->length); in rndis_response_complete()
1222 struct eth_dev *dev = ep->driver_data; in rndis_command_complete()
1226 status = rndis_msg_parser(dev->rndis_config, (u8 *) req->buf); in rndis_command_complete()
1235 * handled lower down. CDC has a number of less-common features:
1237 * - two interfaces: control, and ethernet data
1238 * - Ethernet data interface has two altsettings: default, and active
1239 * - class-specific descriptors for the control interface
1240 * - class-specific control requests
1246 struct usb_request *req = dev->req; in eth_setup()
1247 int value = -EOPNOTSUPP; in eth_setup()
1248 u16 wIndex = le16_to_cpu(ctrl->wIndex); in eth_setup()
1249 u16 wValue = le16_to_cpu(ctrl->wValue); in eth_setup()
1250 u16 wLength = le16_to_cpu(ctrl->wLength); in eth_setup()
1253 * descriptors just go into the pre-allocated ep0 buffer, in eth_setup()
1259 req->complete = eth_setup_complete; in eth_setup()
1260 switch (ctrl->bRequest) { in eth_setup()
1263 if (ctrl->bRequestType != USB_DIR_IN) in eth_setup()
1268 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; in eth_setup()
1270 memcpy(req->buf, &device_desc, value); in eth_setup()
1276 memcpy(req->buf, &dev_qualifier, value); in eth_setup()
1284 value = config_buf(gadget, req->buf, in eth_setup()
1294 wValue & 0xff, req->buf); in eth_setup()
1304 if (ctrl->bRequestType != 0) in eth_setup()
1306 if (gadget->a_hnp_support) in eth_setup()
1308 else if (gadget->a_alt_hnp_support) in eth_setup()
1313 if (ctrl->bRequestType != USB_DIR_IN) in eth_setup()
1315 *(u8 *)req->buf = dev->config; in eth_setup()
1320 if (ctrl->bRequestType != USB_RECIP_INTERFACE in eth_setup()
1321 || !dev->config in eth_setup()
1335 * PXA25x driver use non-CDC ethernet gadget. in eth_setup()
1340 dev->network_started = 1; in eth_setup()
1350 if (dev->status) { in eth_setup()
1351 usb_ep_disable(dev->status_ep); in eth_setup()
1352 usb_ep_enable(dev->status_ep, dev->status); in eth_setup()
1360 usb_ep_disable(dev->in_ep); in eth_setup()
1361 usb_ep_disable(dev->out_ep); in eth_setup()
1366 * the non-default interface resets filters etc. in eth_setup()
1371 usb_ep_enable(dev->in_ep, dev->in); in eth_setup()
1372 usb_ep_enable(dev->out_ep, dev->out); in eth_setup()
1373 dev->cdc_filter = DEFAULT_FILTER; in eth_setup()
1374 if (dev->status) in eth_setup()
1384 * all non-PXA hardware talks real CDC ... in eth_setup()
1392 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE) in eth_setup()
1393 || !dev->config in eth_setup()
1401 *(u8 *)req->buf = 0; in eth_setup()
1403 /* *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0; */ in eth_setup()
1405 *(u8 *)req->buf = 1 ; in eth_setup()
1416 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) in eth_setup()
1422 dev->cdc_filter = wValue; in eth_setup()
1442 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) in eth_setup()
1451 req->complete = rndis_command_complete; in eth_setup()
1457 == ctrl->bRequestType in eth_setup()
1467 buf = rndis_get_next_response(dev->rndis_config, &n); in eth_setup()
1469 memcpy(req->buf, buf, n); in eth_setup()
1470 req->complete = rndis_response_complete; in eth_setup()
1471 rndis_free_response(dev->rndis_config, buf); in eth_setup()
1481 ctrl->bRequestType, ctrl->bRequest, in eth_setup()
1488 req->length = value; in eth_setup()
1489 req->zero = value < wLength in eth_setup()
1490 && (value % gadget->ep0->maxpacket) == 0; in eth_setup()
1491 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); in eth_setup()
1493 debug("ep_queue --> %d\n", value); in eth_setup()
1494 req->status = 0; in eth_setup()
1495 eth_setup_complete(gadget->ep0, req); in eth_setup()
1503 /*-------------------------------------------------------------------------*/
1510 int retval = -ENOMEM; in rx_submit()
1518 * reads (e.g. DMA must be N*maxpacket), so for now don't trim a in rx_submit()
1522 * pad to end-of-packet. That's potentially nice for speed, in rx_submit()
1528 return -EINVAL; in rx_submit()
1530 size = (ETHER_HDR_SIZE + dev->mtu + RX_EXTRA); in rx_submit()
1531 size += dev->out_ep->maxpacket - 1; in rx_submit()
1534 size -= size % dev->out_ep->maxpacket; in rx_submit()
1542 req->buf = (u8 *)net_rx_packets[0]; in rx_submit()
1543 req->length = size; in rx_submit()
1544 req->complete = rx_complete; in rx_submit()
1546 retval = usb_ep_queue(dev->out_ep, req, gfp_flags); in rx_submit()
1549 pr_err("rx submit --> %d", retval); in rx_submit()
1556 struct eth_dev *dev = ep->driver_data; in rx_complete()
1558 debug("%s: status %d\n", __func__, req->status); in rx_complete()
1559 switch (req->status) { in rx_complete()
1564 int length = rndis_rm_hdr(req->buf, req->actual); in rx_complete()
1567 req->length -= length; in rx_complete()
1568 req->actual -= length; in rx_complete()
1570 if (req->actual < ETH_HLEN || PKTSIZE_ALIGN < req->actual) { in rx_complete()
1572 dev->stats.rx_errors++; in rx_complete()
1573 dev->stats.rx_length_errors++; in rx_complete()
1574 debug("rx length %d\n", req->length); in rx_complete()
1578 dev->stats.rx_packets++; in rx_complete()
1579 dev->stats.rx_bytes += req->length; in rx_complete()
1582 /* software-driven interface shutdown */ in rx_complete()
1583 case -ECONNRESET: /* unlink */ in rx_complete()
1584 case -ESHUTDOWN: /* disconnect etc */ in rx_complete()
1586 case -ECONNABORTED: /* endpoint reset */ in rx_complete()
1590 case -EOVERFLOW: in rx_complete()
1591 dev->stats.rx_over_errors++; in rx_complete()
1594 dev->stats.rx_errors++; in rx_complete()
1604 dev->tx_req = usb_ep_alloc_request(dev->in_ep, 0); in alloc_requests()
1606 if (!dev->tx_req) in alloc_requests()
1609 dev->rx_req = usb_ep_alloc_request(dev->out_ep, 0); in alloc_requests()
1611 if (!dev->rx_req) in alloc_requests()
1617 usb_ep_free_request(dev->in_ep, dev->tx_req); in alloc_requests()
1620 return -1; in alloc_requests()
1625 struct eth_dev *dev = ep->driver_data; in tx_complete()
1627 debug("%s: status %s\n", __func__, (req->status) ? "failed" : "ok"); in tx_complete()
1628 switch (req->status) { in tx_complete()
1630 dev->stats.tx_errors++; in tx_complete()
1631 debug("tx err %d\n", req->status); in tx_complete()
1633 case -ECONNRESET: /* unlink */ in tx_complete()
1634 case -ESHUTDOWN: /* disconnect etc */ in tx_complete()
1637 dev->stats.tx_bytes += req->length; in tx_complete()
1639 dev->stats.tx_packets++; in tx_complete()
1649 return dev->cdc_filter & USB_CDC_PACKET_TYPE_PROMISCUOUS; in eth_is_promisc()
1656 int length = skb->len;
1663 u8 *dest = skb->data;
1675 if (!(dev->cdc_filter & type)) {
1683 spin_lock_irqsave(&dev->req_lock, flags);
1689 if (list_empty(&dev->tx_reqs)) {
1690 spin_unlock_irqrestore(&dev->req_lock, flags);
1694 req = container_of (dev->tx_reqs.next, struct usb_request, list);
1695 list_del (&req->list);
1698 if (list_empty (&dev->tx_reqs))
1700 spin_unlock_irqrestore(&dev->req_lock, flags);
1717 length = skb->len;
1719 req->buf = skb->data;
1720 req->context = skb;
1721 req->complete = tx_complete;
1723 /* use zlp framing on tx for strict CDC-Ether conformance,
1727 req->zero = 1;
1728 if (!dev->zlp && (length % dev->in_ep->maxpacket) == 0)
1731 req->length = length;
1734 if (gadget_is_dualspeed(dev->gadget))
1735 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH)
1736 ? ((atomic_read(&dev->tx_qlen) % qmult) != 0)
1739 retval = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC);
1745 net->trans_start = jiffies;
1746 atomic_inc (&dev->tx_qlen);
1751 dev->stats.tx_dropped++;
1753 spin_lock_irqsave(&dev->req_lock, flags);
1754 if (list_empty (&dev->tx_reqs))
1756 list_add (&req->list, &dev->tx_reqs);
1757 spin_unlock_irqrestore(&dev->req_lock, flags);
1762 /*-------------------------------------------------------------------------*/
1770 rndis_deregister(dev->rndis_config); in eth_unbind()
1774 if (dev->req) { in eth_unbind()
1775 usb_ep_free_request(gadget->ep0, dev->req); in eth_unbind()
1776 dev->req = NULL; in eth_unbind()
1778 if (dev->stat_req) { in eth_unbind()
1779 usb_ep_free_request(dev->status_ep, dev->stat_req); in eth_unbind()
1780 dev->stat_req = NULL; in eth_unbind()
1783 if (dev->tx_req) { in eth_unbind()
1784 usb_ep_free_request(dev->in_ep, dev->tx_req); in eth_unbind()
1785 dev->tx_req = NULL; in eth_unbind()
1788 if (dev->rx_req) { in eth_unbind()
1789 usb_ep_free_request(dev->out_ep, dev->rx_req); in eth_unbind()
1790 dev->rx_req = NULL; in eth_unbind()
1793 /* unregister_netdev (dev->net);*/ in eth_unbind()
1794 /* free_netdev(dev->net);*/ in eth_unbind()
1796 dev->gadget = NULL; in eth_unbind()
1816 /*-------------------------------------------------------------------------*/
1833 struct eth_dev *dev = ep->driver_data; in rndis_control_ack_complete()
1836 if (req->status || req->actual != req->length) in rndis_control_ack_complete()
1837 debug("rndis control ack complete --> %d, %d/%d\n", in rndis_control_ack_complete()
1838 req->status, req->actual, req->length); in rndis_control_ack_complete()
1840 if (!dev->network_started) { in rndis_control_ack_complete()
1841 if (rndis_get_state(dev->rndis_config) in rndis_control_ack_complete()
1843 dev->network_started = 1; in rndis_control_ack_complete()
1848 req->context = NULL; in rndis_control_ack_complete()
1850 if (req != dev->stat_req) in rndis_control_ack_complete()
1862 struct ether_priv *priv = (struct ether_priv *)net->priv; in rndis_control_ack()
1863 struct eth_dev *dev = &priv->ethdev; in rndis_control_ack()
1865 struct usb_request *resp = dev->stat_req; in rndis_control_ack()
1868 if (!dev->status) { in rndis_control_ack()
1870 return -ENODEV; in rndis_control_ack()
1874 if (resp->context) { in rndis_control_ack()
1875 resp = usb_ep_alloc_request(dev->status_ep, GFP_ATOMIC); in rndis_control_ack()
1877 return -ENOMEM; in rndis_control_ack()
1878 resp->buf = rndis_resp_buf; in rndis_control_ack()
1885 resp->length = 8; in rndis_control_ack()
1886 resp->complete = rndis_control_ack_complete; in rndis_control_ack()
1887 resp->context = dev; in rndis_control_ack()
1889 *((__le32 *) resp->buf) = __constant_cpu_to_le32(1); in rndis_control_ack()
1890 *((__le32 *) (resp->buf + 4)) = __constant_cpu_to_le32(0); in rndis_control_ack()
1892 length = usb_ep_queue(dev->status_ep, resp, GFP_ATOMIC); in rndis_control_ack()
1894 resp->status = 0; in rndis_control_ack()
1895 rndis_control_ack_complete(dev->status_ep, resp); in rndis_control_ack()
1910 rndis_set_param_medium(dev->rndis_config, in eth_start()
1912 BITRATE(dev->gadget)/100); in eth_start()
1913 rndis_signal_connect(dev->rndis_config); in eth_start()
1925 rndis_set_param_medium(dev->rndis_config, NDIS_MEDIUM_802_3, 0); in eth_stop()
1926 rndis_signal_disconnect(dev->rndis_config); in eth_stop()
1935 rndis_uninit(dev->rndis_config); in eth_stop()
1936 dev->rndis = 0; in eth_stop()
1942 /*-------------------------------------------------------------------------*/
1960 if ((q - p) != 2 || *q++ != term) in is_eth_addr_valid()
1975 return c - '0'; in nibble()
1978 return 10 + c - 'A'; in nibble()
2004 struct eth_dev *dev = &l_priv->ethdev; in eth_bind()
2007 int status = -ENOMEM; in eth_bind()
2011 struct eth_pdata *pdata = dev_get_platdata(l_priv->netdev); in eth_bind()
2041 * non-CDC to be compatible with ARM Linux-2.4 "usb-eth". in eth_bind()
2052 * anything less functional on CDC-capable hardware, in eth_bind()
2056 gadget->name); in eth_bind()
2057 return -ENODEV; in eth_bind()
2117 gadget->name); in eth_bind()
2118 return -ENODEV; in eth_bind()
2120 in_ep->driver_data = in_ep; /* claim */ in eth_bind()
2125 out_ep->driver_data = out_ep; /* claim */ in eth_bind()
2135 status_ep->driver_data = status_ep; /* claim */ in eth_bind()
2137 pr_err("can't run RNDIS on %s", gadget->name); in eth_bind()
2138 return -ENODEV; in eth_bind()
2176 /* and that all endpoints are dual-speed */ in eth_bind()
2201 dev->net = &l_priv->netdev; in eth_bind()
2203 dev->net = l_priv->netdev; in eth_bind()
2206 dev->cdc = cdc; in eth_bind()
2207 dev->zlp = zlp; in eth_bind()
2209 dev->in_ep = in_ep; in eth_bind()
2210 dev->out_ep = out_ep; in eth_bind()
2211 dev->status_ep = status_ep; in eth_bind()
2218 * host side code for the SAFE thing cares -- its original BLAN in eth_bind()
2222 get_ether_addr(dev_addr, dev->net->enetaddr); in eth_bind()
2223 memcpy(tmp, dev->net->enetaddr, sizeof(dev->net->enetaddr)); in eth_bind()
2225 get_ether_addr(dev_addr, pdata->enetaddr); in eth_bind()
2226 memcpy(tmp, pdata->enetaddr, sizeof(pdata->enetaddr)); in eth_bind()
2229 get_ether_addr(host_addr, dev->host_mac); in eth_bind()
2232 dev->host_mac[0], dev->host_mac[1], in eth_bind()
2233 dev->host_mac[2], dev->host_mac[3], in eth_bind()
2234 dev->host_mac[4], dev->host_mac[5]); in eth_bind()
2245 * use PKTSIZE (or aligned... from u-boot) and set in eth_bind()
2248 dev->mtu = PKTSIZE_ALIGN; /* RNDIS does not like this, only 1514, TODO*/ in eth_bind()
2251 dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); in eth_bind()
2252 if (!dev->req) in eth_bind()
2254 dev->req->buf = control_req; in eth_bind()
2255 dev->req->complete = eth_setup_complete; in eth_bind()
2259 if (dev->status_ep) { in eth_bind()
2260 dev->stat_req = usb_ep_alloc_request(dev->status_ep, in eth_bind()
2262 if (!dev->stat_req) { in eth_bind()
2263 usb_ep_free_request(dev->status_ep, dev->req); in eth_bind()
2267 dev->stat_req->buf = status_req; in eth_bind()
2268 dev->stat_req->context = NULL; in eth_bind()
2273 dev->gadget = gadget; in eth_bind()
2275 gadget->ep0->driver_data = dev; in eth_bind()
2278 * two kinds of host-initiated state changes: in eth_bind()
2279 * - iff DATA transfer is active, carrier is "on" in eth_bind()
2280 * - tx queueing enabled if open *and* carrier is "on" in eth_bind()
2283 printf("using %s, OUT %s IN %s%s%s\n", gadget->name, in eth_bind()
2284 out_ep->name, in_ep->name, in eth_bind()
2286 status_ep ? status_ep->name : "" in eth_bind()
2289 printf("MAC %pM\n", dev->net->enetaddr); in eth_bind()
2291 printf("MAC %pM\n", pdata->enetaddr); in eth_bind()
2296 dev->host_mac[0], dev->host_mac[1], in eth_bind()
2297 dev->host_mac[2], dev->host_mac[3], in eth_bind()
2298 dev->host_mac[4], dev->host_mac[5]); in eth_bind()
2305 dev->rndis_config = rndis_register(rndis_control_ack); in eth_bind()
2306 if (dev->rndis_config < 0) { in eth_bind()
2310 status = -ENODEV; in eth_bind()
2315 rndis_set_host_mac(dev->rndis_config, dev->host_mac); in eth_bind()
2316 if (rndis_set_param_dev(dev->rndis_config, dev->net, dev->mtu, in eth_bind()
2317 &dev->stats, &dev->cdc_filter)) in eth_bind()
2319 if (rndis_set_param_vendor(dev->rndis_config, vendorID, in eth_bind()
2322 if (rndis_set_param_medium(dev->rndis_config, in eth_bind()
2335 /*-------------------------------------------------------------------------*/
2340 struct eth_dev *dev = &priv->ethdev; in _usb_eth_init()
2350 /* Configure default mac-addresses for the USB ethernet device */ in _usb_eth_init()
2375 priv->eth_driver.speed = DEVSPEED; in _usb_eth_init()
2376 priv->eth_driver.bind = eth_bind; in _usb_eth_init()
2377 priv->eth_driver.unbind = eth_unbind; in _usb_eth_init()
2378 priv->eth_driver.setup = eth_setup; in _usb_eth_init()
2379 priv->eth_driver.reset = eth_disconnect; in _usb_eth_init()
2380 priv->eth_driver.disconnect = eth_disconnect; in _usb_eth_init()
2381 priv->eth_driver.suspend = eth_suspend; in _usb_eth_init()
2382 priv->eth_driver.resume = eth_resume; in _usb_eth_init()
2383 if (usb_gadget_register_driver(&priv->eth_driver) < 0) in _usb_eth_init()
2386 dev->network_started = 0; in _usb_eth_init()
2391 gadget = dev->gadget; in _usb_eth_init()
2398 while (!dev->network_started) { in _usb_eth_init()
2399 /* Handle control-c and timeouts */ in _usb_eth_init()
2408 rx_submit(dev, dev->rx_req, 0); in _usb_eth_init()
2412 return -1; in _usb_eth_init()
2419 struct eth_dev *dev = &priv->ethdev; in _usb_eth_send()
2420 struct usb_request *req = dev->tx_req; in _usb_eth_send()
2428 rndis_pkt = malloc(length + in _usb_eth_send()
2440 req->buf = packet; in _usb_eth_send()
2441 req->context = NULL; in _usb_eth_send()
2442 req->complete = tx_complete; in _usb_eth_send()
2445 * use zlp framing on tx for strict CDC-Ether conformance, in _usb_eth_send()
2449 req->zero = 1; in _usb_eth_send()
2450 if (!dev->zlp && (length % dev->in_ep->maxpacket) == 0) in _usb_eth_send()
2453 req->length = length; in _usb_eth_send()
2456 if (gadget_is_dualspeed(dev->gadget)) in _usb_eth_send()
2457 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH) in _usb_eth_send()
2458 ? ((dev->tx_qlen % qmult) != 0) : 0; in _usb_eth_send()
2460 dev->tx_qlen = 1; in _usb_eth_send()
2464 retval = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC); in _usb_eth_send()
2471 return -1; in _usb_eth_send()
2480 dev->stats.tx_dropped++; in _usb_eth_send()
2481 return -ENOMEM; in _usb_eth_send()
2493 struct eth_dev *dev = &priv->ethdev; in _usb_eth_halt()
2496 if (!dev->gadget) in _usb_eth_halt()
2501 * before dropping pull-up (also due to hardware issues). in _usb_eth_halt()
2512 usb_gadget_disconnect(dev->gadget); in _usb_eth_halt()
2515 if (dev->network_started) { in _usb_eth_halt()
2517 dev->network_started = 0; in _usb_eth_halt()
2520 usb_gadget_unregister_driver(&priv->eth_driver); in _usb_eth_halt()
2527 struct ether_priv *priv = (struct ether_priv *)netdev->priv; in usb_eth_init()
2534 struct ether_priv *priv = (struct ether_priv *)netdev->priv; in usb_eth_send()
2541 struct ether_priv *priv = (struct ether_priv *)netdev->priv; in usb_eth_recv()
2542 struct eth_dev *dev = &priv->ethdev; in usb_eth_recv()
2554 if (dev->rx_req) { in usb_eth_recv()
2556 dev->rx_req->length); in usb_eth_recv()
2558 pr_err("dev->rx_req invalid"); in usb_eth_recv()
2561 rx_submit(dev, dev->rx_req, 0); in usb_eth_recv()
2568 struct ether_priv *priv = (struct ether_priv *)netdev->priv; in usb_eth_halt()
2575 struct eth_device *netdev = &l_priv->netdev; in usb_eth_initialize()
2577 strlcpy(netdev->name, USB_NET_NAME, sizeof(netdev->name)); in usb_eth_initialize()
2579 netdev->init = usb_eth_init; in usb_eth_initialize()
2580 netdev->send = usb_eth_send; in usb_eth_initialize()
2581 netdev->recv = usb_eth_recv; in usb_eth_initialize()
2582 netdev->halt = usb_eth_halt; in usb_eth_initialize()
2583 netdev->priv = l_priv; in usb_eth_initialize()
2606 struct eth_dev *ethdev = &priv->ethdev; in usb_eth_recv()
2616 if (ethdev->rx_req) { in usb_eth_recv()
2618 return ethdev->rx_req->length; in usb_eth_recv()
2620 pr_err("dev->rx_req invalid"); in usb_eth_recv()
2621 return -EFAULT; in usb_eth_recv()
2625 return -EAGAIN; in usb_eth_recv()
2632 struct eth_dev *ethdev = &priv->ethdev; in usb_eth_free_pkt()
2636 return rx_submit(ethdev, ethdev->rx_req, 0); in usb_eth_free_pkt()
2651 priv->netdev = dev; in usb_eth_probe()
2654 get_ether_addr(CONFIG_USBNET_DEVADDR, pdata->enetaddr); in usb_eth_probe()
2655 eth_env_set_enetaddr("usbnet_devaddr", pdata->enetaddr); in usb_eth_probe()
2682 pr_err("usb - not able to bind usb_ether device\n"); in usb_ether_init()