Lines Matching +full:srp +full:- +full:capable
2 * ether.c -- Ethernet gadget driver, with CDC and non-CDC options
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
8 * SPDX-License-Identifier: GPL-2.0+
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
94 /* CDC and RNDIS support the same host-chosen outgoing packet filters. */
102 /*-------------------------------------------------------------------------*/
138 * This version autoconfigures as much as possible at run-time.
140 * It also ASSUMES a self-powered device, without remote wakeup,
144 /*-------------------------------------------------------------------------*/
158 /*-------------------------------------------------------------------------*/
168 return dev->cdc; /* depends on what hardware we found */ in is_cdc()
176 return dev->rndis; in rndis_active()
187 /* peak bulk transfer bits-per-second */
200 /* for dual-speed hardware, use deeper queues at highspeed */
202 (DEFAULT_QLEN*((gadget->speed == USB_SPEED_HIGH) ? qmult : 1))
206 return (g->speed == USB_SPEED_HIGH) ? HS_BPS : FS_BPS; in BITRATE()
223 /*-------------------------------------------------------------------------*/
226 * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
227 * Instead: allocate your own, using normal USB-IF procedures.
235 #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */
239 * ARM Linux has used for ethernet-over-usb, both with sa1100 and
240 * with pxa250. We're protocol-compatible, if the host-side drivers
242 * drivers that need to hard-wire endpoint numbers have a hook.
246 * RNDIS (like SA-1100, with no interrupt endpoint, or anything that
247 * doesn't handle control-OUT).
250 #define SIMPLE_PRODUCT_NUM 0x505a /* Linux-USB "CDC Subset" Device */
256 * the non-RNDIS configuration.
264 * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
276 static char *iManufacturer = "U-Boot";
289 /*-------------------------------------------------------------------------*/
294 * also optional class-specific notification interrupt transfer.
327 * an RNDIS-only configuration.
329 * FIXME define some higher-powered configurations to make it easier
396 * RNDIS shares a lot with CDC-Ethernet, since it's a variant of the
397 * CDC-ACM (modem) spec. Unfortunately MSFT's RNDIS driver is buggy; it
542 * some drivers (like Linux 2.4 cdc-ether!) "need" it to exist even
545 * encapsulated commands (vendor-specific, using control-OUT).
624 * "Simple" CDC-subset option is a simple vendor-neutral model that most
827 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) in ep_desc()
832 /*-------------------------------------------------------------------------*/
834 /* descriptors that are built on-demand */
843 /* static strings, in UTF-8 */
865 .language = 0x0409, /* en-us */
891 hs = (g->speed == USB_SPEED_HIGH); in config_buf()
898 return -EINVAL; in config_buf()
915 /* for now, don't advertise srp-only devices */ in config_buf()
922 ((struct usb_config_descriptor *) buf)->bDescriptorType = type; in config_buf()
926 /*-------------------------------------------------------------------------*/
935 struct usb_gadget *gadget = dev->gadget; in set_ether_config()
939 if (!subset_active(dev) && dev->status_ep) { in set_ether_config()
940 dev->status = ep_desc(gadget, &hs_status_desc, in set_ether_config()
942 dev->status_ep->driver_data = dev; in set_ether_config()
944 result = usb_ep_enable(dev->status_ep, dev->status); in set_ether_config()
946 debug("enable %s --> %d\n", in set_ether_config()
947 dev->status_ep->name, result); in set_ether_config()
953 dev->in = ep_desc(gadget, &hs_source_desc, &fs_source_desc); in set_ether_config()
954 dev->in_ep->driver_data = dev; in set_ether_config()
956 dev->out = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc); in set_ether_config()
957 dev->out_ep->driver_data = dev; in set_ether_config()
969 result = usb_ep_enable(dev->in_ep, dev->in); in set_ether_config()
971 debug("enable %s --> %d\n", in set_ether_config()
972 dev->in_ep->name, result); in set_ether_config()
976 result = usb_ep_enable(dev->out_ep, dev->out); in set_ether_config()
978 debug("enable %s --> %d\n", in set_ether_config()
979 dev->out_ep->name, result); in set_ether_config()
990 if (!subset_active(dev) && dev->status_ep) in set_ether_config()
991 (void) usb_ep_disable(dev->status_ep); in set_ether_config()
992 dev->status = NULL; in set_ether_config()
993 (void) usb_ep_disable(dev->in_ep); in set_ether_config()
994 (void) usb_ep_disable(dev->out_ep); in set_ether_config()
995 dev->in = NULL; in set_ether_config()
996 dev->out = NULL; in set_ether_config()
999 * activate non-CDC configs right away in set_ether_config()
1011 if (dev->config == 0) in eth_reset_config()
1016 rndis_uninit(dev->rndis_config); in eth_reset_config()
1023 if (dev->in) { in eth_reset_config()
1024 usb_ep_disable(dev->in_ep); in eth_reset_config()
1025 if (dev->tx_req) { in eth_reset_config()
1026 usb_ep_free_request(dev->in_ep, dev->tx_req); in eth_reset_config()
1027 dev->tx_req = NULL; in eth_reset_config()
1030 if (dev->out) { in eth_reset_config()
1031 usb_ep_disable(dev->out_ep); in eth_reset_config()
1032 if (dev->rx_req) { in eth_reset_config()
1033 usb_ep_free_request(dev->out_ep, dev->rx_req); in eth_reset_config()
1034 dev->rx_req = NULL; in eth_reset_config()
1037 if (dev->status) in eth_reset_config()
1038 usb_ep_disable(dev->status_ep); in eth_reset_config()
1040 dev->rndis = 0; in eth_reset_config()
1041 dev->cdc_filter = 0; in eth_reset_config()
1042 dev->config = 0; in eth_reset_config()
1053 struct usb_gadget *gadget = dev->gadget; in eth_set_config()
1056 && dev->config in eth_set_config()
1057 && dev->tx_qlen != 0) { in eth_set_config()
1060 return -ESPIPE; in eth_set_config()
1070 dev->rndis = 1; in eth_set_config()
1075 result = -EINVAL; in eth_set_config()
1084 usb_gadget_vbus_draw(dev->gadget, in eth_set_config()
1085 gadget_is_otg(dev->gadget) ? 8 : 100); in eth_set_config()
1091 usb_gadget_vbus_draw(dev->gadget, power); in eth_set_config()
1093 switch (gadget->speed) { in eth_set_config()
1104 dev->config = number; in eth_set_config()
1116 /*-------------------------------------------------------------------------*/
1124 * we want this CDC Ethernet code to be vendor-neutral, we don't use that
1129 struct usb_cdc_notification *event = req->buf; in eth_status_complete()
1130 int value = req->status; in eth_status_complete()
1131 struct eth_dev *dev = ep->driver_data; in eth_status_complete()
1134 if (event->bNotificationType == USB_CDC_NOTIFY_NETWORK_CONNECTION in eth_status_complete()
1136 __le32 *data = req->buf + sizeof *event; in eth_status_complete()
1138 event->bmRequestType = 0xA1; in eth_status_complete()
1139 event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE; in eth_status_complete()
1140 event->wValue = __constant_cpu_to_le16(0); in eth_status_complete()
1141 event->wIndex = __constant_cpu_to_le16(1); in eth_status_complete()
1142 event->wLength = __constant_cpu_to_le16(8); in eth_status_complete()
1145 data[0] = data[1] = cpu_to_le32(BITRATE(dev->gadget)); in eth_status_complete()
1147 req->length = STATUS_BYTECOUNT; in eth_status_complete()
1149 debug("send SPEED_CHANGE --> %d\n", value); in eth_status_complete()
1152 } else if (value != -ECONNRESET) { in eth_status_complete()
1153 debug("event %02x --> %d\n", in eth_status_complete()
1154 event->bNotificationType, value); in eth_status_complete()
1155 if (event->bNotificationType == in eth_status_complete()
1157 dev->network_started = 1; in eth_status_complete()
1161 req->context = NULL; in eth_status_complete()
1166 struct usb_request *req = dev->stat_req; in issue_start_status()
1175 * unlink-one primitive has way too many error modes. in issue_start_status()
1178 * FIXME iff req->context != null just dequeue it in issue_start_status()
1180 usb_ep_disable(dev->status_ep); in issue_start_status()
1181 usb_ep_enable(dev->status_ep, dev->status); in issue_start_status()
1187 event = req->buf; in issue_start_status()
1188 event->bmRequestType = 0xA1; in issue_start_status()
1189 event->bNotificationType = USB_CDC_NOTIFY_NETWORK_CONNECTION; in issue_start_status()
1190 event->wValue = __constant_cpu_to_le16(1); /* connected */ in issue_start_status()
1191 event->wIndex = __constant_cpu_to_le16(1); in issue_start_status()
1192 event->wLength = 0; in issue_start_status()
1194 req->length = sizeof *event; in issue_start_status()
1195 req->complete = eth_status_complete; in issue_start_status()
1196 req->context = dev; in issue_start_status()
1198 value = usb_ep_queue(dev->status_ep, req, GFP_ATOMIC); in issue_start_status()
1200 debug("status buf queue --> %d\n", value); in issue_start_status()
1205 /*-------------------------------------------------------------------------*/
1209 if (req->status || req->actual != req->length) in eth_setup_complete()
1210 debug("setup complete --> %d, %d/%d\n", in eth_setup_complete()
1211 req->status, req->actual, req->length); in eth_setup_complete()
1218 if (req->status || req->actual != req->length) in rndis_response_complete()
1219 debug("rndis response complete --> %d, %d/%d\n", in rndis_response_complete()
1220 req->status, req->actual, req->length); in rndis_response_complete()
1227 struct eth_dev *dev = ep->driver_data; in rndis_command_complete()
1231 status = rndis_msg_parser(dev->rndis_config, (u8 *) req->buf); in rndis_command_complete()
1240 * handled lower down. CDC has a number of less-common features:
1242 * - two interfaces: control, and ethernet data
1243 * - Ethernet data interface has two altsettings: default, and active
1244 * - class-specific descriptors for the control interface
1245 * - class-specific control requests
1251 struct usb_request *req = dev->req; in eth_setup()
1252 int value = -EOPNOTSUPP; in eth_setup()
1253 u16 wIndex = le16_to_cpu(ctrl->wIndex); in eth_setup()
1254 u16 wValue = le16_to_cpu(ctrl->wValue); in eth_setup()
1255 u16 wLength = le16_to_cpu(ctrl->wLength); in eth_setup()
1258 * descriptors just go into the pre-allocated ep0 buffer, in eth_setup()
1264 req->complete = eth_setup_complete; in eth_setup()
1265 switch (ctrl->bRequest) { in eth_setup()
1268 if (ctrl->bRequestType != USB_DIR_IN) in eth_setup()
1273 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; in eth_setup()
1275 memcpy(req->buf, &device_desc, value); in eth_setup()
1281 memcpy(req->buf, &dev_qualifier, value); in eth_setup()
1289 value = config_buf(gadget, req->buf, in eth_setup()
1299 wValue & 0xff, req->buf); in eth_setup()
1309 if (ctrl->bRequestType != 0) in eth_setup()
1311 if (gadget->a_hnp_support) in eth_setup()
1313 else if (gadget->a_alt_hnp_support) in eth_setup()
1318 if (ctrl->bRequestType != USB_DIR_IN) in eth_setup()
1320 *(u8 *)req->buf = dev->config; in eth_setup()
1325 if (ctrl->bRequestType != USB_RECIP_INTERFACE in eth_setup()
1326 || !dev->config in eth_setup()
1340 * PXA25x driver use non-CDC ethernet gadget. in eth_setup()
1345 dev->network_started = 1; in eth_setup()
1355 if (dev->status) { in eth_setup()
1356 usb_ep_disable(dev->status_ep); in eth_setup()
1357 usb_ep_enable(dev->status_ep, dev->status); in eth_setup()
1365 usb_ep_disable(dev->in_ep); in eth_setup()
1366 usb_ep_disable(dev->out_ep); in eth_setup()
1371 * the non-default interface resets filters etc. in eth_setup()
1376 usb_ep_enable(dev->in_ep, dev->in); in eth_setup()
1377 usb_ep_enable(dev->out_ep, dev->out); in eth_setup()
1378 dev->cdc_filter = DEFAULT_FILTER; in eth_setup()
1379 if (dev->status) in eth_setup()
1389 * all non-PXA hardware talks real CDC ... in eth_setup()
1397 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE) in eth_setup()
1398 || !dev->config in eth_setup()
1406 *(u8 *)req->buf = 0; in eth_setup()
1408 /* *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0; */ in eth_setup()
1410 *(u8 *)req->buf = 1 ; in eth_setup()
1421 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) in eth_setup()
1427 dev->cdc_filter = wValue; in eth_setup()
1447 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) in eth_setup()
1456 req->complete = rndis_command_complete; in eth_setup()
1462 == ctrl->bRequestType in eth_setup()
1472 buf = rndis_get_next_response(dev->rndis_config, &n); in eth_setup()
1474 memcpy(req->buf, buf, n); in eth_setup()
1475 req->complete = rndis_response_complete; in eth_setup()
1476 rndis_free_response(dev->rndis_config, buf); in eth_setup()
1486 ctrl->bRequestType, ctrl->bRequest, in eth_setup()
1493 req->length = value; in eth_setup()
1494 req->zero = value < wLength in eth_setup()
1495 && (value % gadget->ep0->maxpacket) == 0; in eth_setup()
1496 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); in eth_setup()
1498 debug("ep_queue --> %d\n", value); in eth_setup()
1499 req->status = 0; in eth_setup()
1500 eth_setup_complete(gadget->ep0, req); in eth_setup()
1508 /*-------------------------------------------------------------------------*/
1515 int retval = -ENOMEM; in rx_submit()
1527 * pad to end-of-packet. That's potentially nice for speed, in rx_submit()
1533 return -EINVAL; in rx_submit()
1535 size = (ETHER_HDR_SIZE + dev->mtu + RX_EXTRA); in rx_submit()
1536 size += dev->out_ep->maxpacket - 1; in rx_submit()
1539 size -= size % dev->out_ep->maxpacket; in rx_submit()
1547 req->buf = (u8 *)net_rx_packets[0]; in rx_submit()
1548 req->length = size; in rx_submit()
1549 req->complete = rx_complete; in rx_submit()
1551 retval = usb_ep_queue(dev->out_ep, req, gfp_flags); in rx_submit()
1554 pr_err("rx submit --> %d", retval); in rx_submit()
1561 struct eth_dev *dev = ep->driver_data; in rx_complete()
1563 debug("%s: status %d\n", __func__, req->status); in rx_complete()
1564 switch (req->status) { in rx_complete()
1569 int length = rndis_rm_hdr(req->buf, req->actual); in rx_complete()
1572 req->length -= length; in rx_complete()
1573 req->actual -= length; in rx_complete()
1575 if (req->actual < ETH_HLEN || ETH_FRAME_LEN < req->actual) { in rx_complete()
1577 dev->stats.rx_errors++; in rx_complete()
1578 dev->stats.rx_length_errors++; in rx_complete()
1579 debug("rx length %d\n", req->length); in rx_complete()
1583 dev->stats.rx_packets++; in rx_complete()
1584 dev->stats.rx_bytes += req->length; in rx_complete()
1587 /* software-driven interface shutdown */ in rx_complete()
1588 case -ECONNRESET: /* unlink */ in rx_complete()
1589 case -ESHUTDOWN: /* disconnect etc */ in rx_complete()
1591 case -ECONNABORTED: /* endpoint reset */ in rx_complete()
1595 case -EOVERFLOW: in rx_complete()
1596 dev->stats.rx_over_errors++; in rx_complete()
1599 dev->stats.rx_errors++; in rx_complete()
1609 dev->tx_req = usb_ep_alloc_request(dev->in_ep, 0); in alloc_requests()
1611 if (!dev->tx_req) in alloc_requests()
1614 dev->rx_req = usb_ep_alloc_request(dev->out_ep, 0); in alloc_requests()
1616 if (!dev->rx_req) in alloc_requests()
1622 usb_ep_free_request(dev->in_ep, dev->tx_req); in alloc_requests()
1625 return -1; in alloc_requests()
1630 struct eth_dev *dev = ep->driver_data; in tx_complete()
1632 debug("%s: status %s\n", __func__, (req->status) ? "failed" : "ok"); in tx_complete()
1633 switch (req->status) { in tx_complete()
1635 dev->stats.tx_errors++; in tx_complete()
1636 debug("tx err %d\n", req->status); in tx_complete()
1638 case -ECONNRESET: /* unlink */ in tx_complete()
1639 case -ESHUTDOWN: /* disconnect etc */ in tx_complete()
1642 dev->stats.tx_bytes += req->length; in tx_complete()
1644 dev->stats.tx_packets++; in tx_complete()
1654 return dev->cdc_filter & USB_CDC_PACKET_TYPE_PROMISCUOUS; in eth_is_promisc()
1661 int length = skb->len;
1668 u8 *dest = skb->data;
1680 if (!(dev->cdc_filter & type)) {
1688 spin_lock_irqsave(&dev->req_lock, flags);
1694 if (list_empty(&dev->tx_reqs)) {
1695 spin_unlock_irqrestore(&dev->req_lock, flags);
1699 req = container_of (dev->tx_reqs.next, struct usb_request, list);
1700 list_del (&req->list);
1703 if (list_empty (&dev->tx_reqs))
1705 spin_unlock_irqrestore(&dev->req_lock, flags);
1722 length = skb->len;
1724 req->buf = skb->data;
1725 req->context = skb;
1726 req->complete = tx_complete;
1728 /* use zlp framing on tx for strict CDC-Ether conformance,
1732 req->zero = 1;
1733 if (!dev->zlp && (length % dev->in_ep->maxpacket) == 0)
1736 req->length = length;
1739 if (gadget_is_dualspeed(dev->gadget))
1740 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH)
1741 ? ((atomic_read(&dev->tx_qlen) % qmult) != 0)
1744 retval = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC);
1750 net->trans_start = jiffies;
1751 atomic_inc (&dev->tx_qlen);
1756 dev->stats.tx_dropped++;
1758 spin_lock_irqsave(&dev->req_lock, flags);
1759 if (list_empty (&dev->tx_reqs))
1761 list_add (&req->list, &dev->tx_reqs);
1762 spin_unlock_irqrestore(&dev->req_lock, flags);
1767 /*-------------------------------------------------------------------------*/
1775 rndis_deregister(dev->rndis_config); in eth_unbind()
1779 if (dev->req) { in eth_unbind()
1780 usb_ep_free_request(gadget->ep0, dev->req); in eth_unbind()
1781 dev->req = NULL; in eth_unbind()
1783 if (dev->stat_req) { in eth_unbind()
1784 usb_ep_free_request(dev->status_ep, dev->stat_req); in eth_unbind()
1785 dev->stat_req = NULL; in eth_unbind()
1788 if (dev->tx_req) { in eth_unbind()
1789 usb_ep_free_request(dev->in_ep, dev->tx_req); in eth_unbind()
1790 dev->tx_req = NULL; in eth_unbind()
1793 if (dev->rx_req) { in eth_unbind()
1794 usb_ep_free_request(dev->out_ep, dev->rx_req); in eth_unbind()
1795 dev->rx_req = NULL; in eth_unbind()
1798 /* unregister_netdev (dev->net);*/ in eth_unbind()
1799 /* free_netdev(dev->net);*/ in eth_unbind()
1801 dev->gadget = NULL; in eth_unbind()
1821 /*-------------------------------------------------------------------------*/
1838 struct eth_dev *dev = ep->driver_data; in rndis_control_ack_complete()
1841 if (req->status || req->actual != req->length) in rndis_control_ack_complete()
1842 debug("rndis control ack complete --> %d, %d/%d\n", in rndis_control_ack_complete()
1843 req->status, req->actual, req->length); in rndis_control_ack_complete()
1845 if (!dev->network_started) { in rndis_control_ack_complete()
1846 if (rndis_get_state(dev->rndis_config) in rndis_control_ack_complete()
1848 dev->network_started = 1; in rndis_control_ack_complete()
1853 req->context = NULL; in rndis_control_ack_complete()
1855 if (req != dev->stat_req) in rndis_control_ack_complete()
1867 struct ether_priv *priv = (struct ether_priv *)net->priv; in rndis_control_ack()
1868 struct eth_dev *dev = &priv->ethdev; in rndis_control_ack()
1870 struct usb_request *resp = dev->stat_req; in rndis_control_ack()
1873 if (!dev->status) { in rndis_control_ack()
1875 return -ENODEV; in rndis_control_ack()
1879 if (resp->context) { in rndis_control_ack()
1880 resp = usb_ep_alloc_request(dev->status_ep, GFP_ATOMIC); in rndis_control_ack()
1882 return -ENOMEM; in rndis_control_ack()
1883 resp->buf = rndis_resp_buf; in rndis_control_ack()
1890 resp->length = 8; in rndis_control_ack()
1891 resp->complete = rndis_control_ack_complete; in rndis_control_ack()
1892 resp->context = dev; in rndis_control_ack()
1894 *((__le32 *) resp->buf) = __constant_cpu_to_le32(1); in rndis_control_ack()
1895 *((__le32 *) (resp->buf + 4)) = __constant_cpu_to_le32(0); in rndis_control_ack()
1897 length = usb_ep_queue(dev->status_ep, resp, GFP_ATOMIC); in rndis_control_ack()
1899 resp->status = 0; in rndis_control_ack()
1900 rndis_control_ack_complete(dev->status_ep, resp); in rndis_control_ack()
1915 rndis_set_param_medium(dev->rndis_config, in eth_start()
1917 BITRATE(dev->gadget)/100); in eth_start()
1918 rndis_signal_connect(dev->rndis_config); in eth_start()
1930 rndis_set_param_medium(dev->rndis_config, NDIS_MEDIUM_802_3, 0); in eth_stop()
1931 rndis_signal_disconnect(dev->rndis_config); in eth_stop()
1940 rndis_uninit(dev->rndis_config); in eth_stop()
1941 dev->rndis = 0; in eth_stop()
1947 /*-------------------------------------------------------------------------*/
1965 if ((q - p) != 2 || *q++ != term) in is_eth_addr_valid()
1980 return c - '0'; in nibble()
1983 return 10 + c - 'A'; in nibble()
2009 struct eth_dev *dev = &l_priv->ethdev; in eth_bind()
2012 int status = -ENOMEM; in eth_bind()
2016 struct eth_pdata *pdata = dev_get_platdata(l_priv->netdev); in eth_bind()
2046 * non-CDC to be compatible with ARM Linux-2.4 "usb-eth". in eth_bind()
2057 * anything less functional on CDC-capable hardware, in eth_bind()
2061 gadget->name); in eth_bind()
2062 return -ENODEV; in eth_bind()
2122 gadget->name); in eth_bind()
2123 return -ENODEV; in eth_bind()
2125 in_ep->driver_data = in_ep; /* claim */ in eth_bind()
2130 out_ep->driver_data = out_ep; /* claim */ in eth_bind()
2140 status_ep->driver_data = status_ep; /* claim */ in eth_bind()
2142 pr_err("can't run RNDIS on %s", gadget->name); in eth_bind()
2143 return -ENODEV; in eth_bind()
2181 /* and that all endpoints are dual-speed */ in eth_bind()
2206 dev->net = &l_priv->netdev; in eth_bind()
2208 dev->net = l_priv->netdev; in eth_bind()
2211 dev->cdc = cdc; in eth_bind()
2212 dev->zlp = zlp; in eth_bind()
2214 dev->in_ep = in_ep; in eth_bind()
2215 dev->out_ep = out_ep; in eth_bind()
2216 dev->status_ep = status_ep; in eth_bind()
2223 * host side code for the SAFE thing cares -- its original BLAN in eth_bind()
2227 get_ether_addr(dev_addr, dev->net->enetaddr); in eth_bind()
2228 memcpy(tmp, dev->net->enetaddr, sizeof(dev->net->enetaddr)); in eth_bind()
2230 get_ether_addr(dev_addr, pdata->enetaddr); in eth_bind()
2231 memcpy(tmp, pdata->enetaddr, sizeof(pdata->enetaddr)); in eth_bind()
2234 get_ether_addr(host_addr, dev->host_mac); in eth_bind()
2237 dev->host_mac[0], dev->host_mac[1], in eth_bind()
2238 dev->host_mac[2], dev->host_mac[3], in eth_bind()
2239 dev->host_mac[4], dev->host_mac[5]); in eth_bind()
2250 * use PKTSIZE (or aligned... from u-boot) and set in eth_bind()
2253 dev->mtu = PKTSIZE_ALIGN; /* RNDIS does not like this, only 1514, TODO*/ in eth_bind()
2256 dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); in eth_bind()
2257 if (!dev->req) in eth_bind()
2259 dev->req->buf = control_req; in eth_bind()
2260 dev->req->complete = eth_setup_complete; in eth_bind()
2264 if (dev->status_ep) { in eth_bind()
2265 dev->stat_req = usb_ep_alloc_request(dev->status_ep, in eth_bind()
2267 if (!dev->stat_req) { in eth_bind()
2268 usb_ep_free_request(dev->status_ep, dev->req); in eth_bind()
2272 dev->stat_req->buf = status_req; in eth_bind()
2273 dev->stat_req->context = NULL; in eth_bind()
2278 dev->gadget = gadget; in eth_bind()
2280 gadget->ep0->driver_data = dev; in eth_bind()
2283 * two kinds of host-initiated state changes: in eth_bind()
2284 * - iff DATA transfer is active, carrier is "on" in eth_bind()
2285 * - tx queueing enabled if open *and* carrier is "on" in eth_bind()
2288 printf("using %s, OUT %s IN %s%s%s\n", gadget->name, in eth_bind()
2289 out_ep->name, in_ep->name, in eth_bind()
2291 status_ep ? status_ep->name : "" in eth_bind()
2294 printf("MAC %pM\n", dev->net->enetaddr); in eth_bind()
2296 printf("MAC %pM\n", pdata->enetaddr); in eth_bind()
2301 dev->host_mac[0], dev->host_mac[1], in eth_bind()
2302 dev->host_mac[2], dev->host_mac[3], in eth_bind()
2303 dev->host_mac[4], dev->host_mac[5]); in eth_bind()
2310 dev->rndis_config = rndis_register(rndis_control_ack); in eth_bind()
2311 if (dev->rndis_config < 0) { in eth_bind()
2315 status = -ENODEV; in eth_bind()
2320 rndis_set_host_mac(dev->rndis_config, dev->host_mac); in eth_bind()
2321 if (rndis_set_param_dev(dev->rndis_config, dev->net, dev->mtu, in eth_bind()
2322 &dev->stats, &dev->cdc_filter)) in eth_bind()
2324 if (rndis_set_param_vendor(dev->rndis_config, vendorID, in eth_bind()
2327 if (rndis_set_param_medium(dev->rndis_config, in eth_bind()
2340 /*-------------------------------------------------------------------------*/
2345 struct eth_dev *dev = &priv->ethdev; in _usb_eth_init()
2355 /* Configure default mac-addresses for the USB ethernet device */ in _usb_eth_init()
2380 priv->eth_driver.speed = DEVSPEED; in _usb_eth_init()
2381 priv->eth_driver.bind = eth_bind; in _usb_eth_init()
2382 priv->eth_driver.unbind = eth_unbind; in _usb_eth_init()
2383 priv->eth_driver.setup = eth_setup; in _usb_eth_init()
2384 priv->eth_driver.reset = eth_disconnect; in _usb_eth_init()
2385 priv->eth_driver.disconnect = eth_disconnect; in _usb_eth_init()
2386 priv->eth_driver.suspend = eth_suspend; in _usb_eth_init()
2387 priv->eth_driver.resume = eth_resume; in _usb_eth_init()
2388 if (usb_gadget_register_driver(&priv->eth_driver) < 0) in _usb_eth_init()
2391 dev->network_started = 0; in _usb_eth_init()
2396 gadget = dev->gadget; in _usb_eth_init()
2403 while (!dev->network_started) { in _usb_eth_init()
2404 /* Handle control-c and timeouts */ in _usb_eth_init()
2413 rx_submit(dev, dev->rx_req, 0); in _usb_eth_init()
2417 return -1; in _usb_eth_init()
2424 struct eth_dev *dev = &priv->ethdev; in _usb_eth_send()
2425 struct usb_request *req = dev->tx_req; in _usb_eth_send()
2445 req->buf = packet; in _usb_eth_send()
2446 req->context = NULL; in _usb_eth_send()
2447 req->complete = tx_complete; in _usb_eth_send()
2450 * use zlp framing on tx for strict CDC-Ether conformance, in _usb_eth_send()
2454 req->zero = 1; in _usb_eth_send()
2455 if (!dev->zlp && (length % dev->in_ep->maxpacket) == 0) in _usb_eth_send()
2458 req->length = length; in _usb_eth_send()
2461 if (gadget_is_dualspeed(dev->gadget)) in _usb_eth_send()
2462 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH) in _usb_eth_send()
2463 ? ((dev->tx_qlen % qmult) != 0) : 0; in _usb_eth_send()
2465 dev->tx_qlen = 1; in _usb_eth_send()
2469 retval = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC); in _usb_eth_send()
2476 return -1; in _usb_eth_send()
2485 dev->stats.tx_dropped++; in _usb_eth_send()
2486 return -ENOMEM; in _usb_eth_send()
2498 struct eth_dev *dev = &priv->ethdev; in _usb_eth_halt()
2501 if (!dev->gadget) in _usb_eth_halt()
2506 * before dropping pull-up (also due to hardware issues). in _usb_eth_halt()
2517 usb_gadget_disconnect(dev->gadget); in _usb_eth_halt()
2520 if (dev->network_started) { in _usb_eth_halt()
2522 dev->network_started = 0; in _usb_eth_halt()
2525 usb_gadget_unregister_driver(&priv->eth_driver); in _usb_eth_halt()
2532 struct ether_priv *priv = (struct ether_priv *)netdev->priv; in usb_eth_init()
2539 struct ether_priv *priv = (struct ether_priv *)netdev->priv; in usb_eth_send()
2546 struct ether_priv *priv = (struct ether_priv *)netdev->priv; in usb_eth_recv()
2547 struct eth_dev *dev = &priv->ethdev; in usb_eth_recv()
2559 if (dev->rx_req) { in usb_eth_recv()
2561 dev->rx_req->length); in usb_eth_recv()
2563 pr_err("dev->rx_req invalid"); in usb_eth_recv()
2566 rx_submit(dev, dev->rx_req, 0); in usb_eth_recv()
2573 struct ether_priv *priv = (struct ether_priv *)netdev->priv; in usb_eth_halt()
2580 struct eth_device *netdev = &l_priv->netdev; in usb_eth_initialize()
2582 strlcpy(netdev->name, USB_NET_NAME, sizeof(netdev->name)); in usb_eth_initialize()
2584 netdev->init = usb_eth_init; in usb_eth_initialize()
2585 netdev->send = usb_eth_send; in usb_eth_initialize()
2586 netdev->recv = usb_eth_recv; in usb_eth_initialize()
2587 netdev->halt = usb_eth_halt; in usb_eth_initialize()
2588 netdev->priv = l_priv; in usb_eth_initialize()
2614 struct eth_dev *ethdev = &priv->ethdev; in usb_eth_recv()
2624 if (ethdev->rx_req) { in usb_eth_recv()
2626 return ethdev->rx_req->length; in usb_eth_recv()
2628 pr_err("dev->rx_req invalid"); in usb_eth_recv()
2629 return -EFAULT; in usb_eth_recv()
2633 return -EAGAIN; in usb_eth_recv()
2640 struct eth_dev *ethdev = &priv->ethdev; in usb_eth_free_pkt()
2644 return rx_submit(ethdev, ethdev->rx_req, 0); in usb_eth_free_pkt()
2659 priv->netdev = dev; in usb_eth_probe()
2662 get_ether_addr(CONFIG_USBNET_DEVADDR, pdata->enetaddr); in usb_eth_probe()
2663 eth_env_set_enetaddr("usbnet_devaddr", pdata->enetaddr); in usb_eth_probe()
2690 pr_err("usb - not able to bind usb_ether device\n"); in usb_ether_init()