/* For CDC-incapable hardware, choose the simple cdc subset.
* Anything that talks bulk (without notable bugs) can do this.
*/
-#ifdef CONFIG_USB_GADGET_PXA
+#ifdef CONFIG_USB_GADGET_PXA2XX
#define DEV_CONFIG_SUBSET
#endif
*
* NOTE: Controllers like superh_udc should probably be able to use
* an RNDIS-only configuration.
+ *
+ * FIXME define some higher-powered configurations to make it easier
+ * to recharge batteries ...
*/
#define DEV_CONFIG_VALUE 1 /* cdc or subset */
.bNumConfigurations = 1,
};
+static struct usb_otg_descriptor
+otg_descriptor = {
+ .bLength = sizeof otg_descriptor,
+ .bDescriptorType = USB_DT_OTG,
+
+ .bmAttributes = USB_OTG_SRP,
+};
+
static struct usb_config_descriptor
eth_config = {
.bLength = sizeof eth_config,
};
#ifdef CONFIG_USB_ETH_RNDIS
-static const struct usb_config_descriptor
+static struct usb_config_descriptor
rndis_config = {
.bLength = sizeof rndis_config,
.bDescriptorType = USB_DT_CONFIG,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
-static const struct usb_descriptor_header *fs_eth_function [10] = {
+static const struct usb_descriptor_header *fs_eth_function [11] = {
+ (struct usb_descriptor_header *) &otg_descriptor,
#ifdef DEV_CONFIG_CDC
/* "cdc" mode descriptors */
(struct usb_descriptor_header *) &control_intf,
(struct usb_descriptor_header *) &data_intf,
(struct usb_descriptor_header *) &fs_source_desc,
(struct usb_descriptor_header *) &fs_sink_desc,
- 0,
+ NULL,
#endif /* DEV_CONFIG_CDC */
};
static inline void __init fs_subset_descriptors(void)
{
#ifdef DEV_CONFIG_SUBSET
- fs_eth_function[0] = (struct usb_descriptor_header *) &subset_data_intf;
- fs_eth_function[1] = (struct usb_descriptor_header *) &fs_source_desc;
- fs_eth_function[2] = (struct usb_descriptor_header *) &fs_sink_desc;
- fs_eth_function[3] = 0;
+ fs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf;
+ fs_eth_function[2] = (struct usb_descriptor_header *) &fs_source_desc;
+ fs_eth_function[3] = (struct usb_descriptor_header *) &fs_sink_desc;
+ fs_eth_function[4] = NULL;
#else
- fs_eth_function[0] = 0;
+ fs_eth_function[1] = NULL;
#endif
}
#ifdef CONFIG_USB_ETH_RNDIS
static const struct usb_descriptor_header *fs_rndis_function [] = {
+ (struct usb_descriptor_header *) &otg_descriptor,
/* control interface matches ACM, not Ethernet */
(struct usb_descriptor_header *) &rndis_control_intf,
(struct usb_descriptor_header *) &header_desc,
(struct usb_descriptor_header *) &rndis_data_intf,
(struct usb_descriptor_header *) &fs_source_desc,
(struct usb_descriptor_header *) &fs_sink_desc,
- 0,
+ NULL,
};
#endif
.bNumConfigurations = 1,
};
-static const struct usb_descriptor_header *hs_eth_function [10] = {
+static const struct usb_descriptor_header *hs_eth_function [11] = {
+ (struct usb_descriptor_header *) &otg_descriptor,
#ifdef DEV_CONFIG_CDC
/* "cdc" mode descriptors */
(struct usb_descriptor_header *) &control_intf,
(struct usb_descriptor_header *) &data_intf,
(struct usb_descriptor_header *) &hs_source_desc,
(struct usb_descriptor_header *) &hs_sink_desc,
- 0,
+ NULL,
#endif /* DEV_CONFIG_CDC */
};
static inline void __init hs_subset_descriptors(void)
{
#ifdef DEV_CONFIG_SUBSET
- hs_eth_function[0] = (struct usb_descriptor_header *) &subset_data_intf;
- hs_eth_function[1] = (struct usb_descriptor_header *) &fs_source_desc;
- hs_eth_function[2] = (struct usb_descriptor_header *) &fs_sink_desc;
- hs_eth_function[3] = 0;
+ hs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf;
+ hs_eth_function[2] = (struct usb_descriptor_header *) &fs_source_desc;
+ hs_eth_function[3] = (struct usb_descriptor_header *) &fs_sink_desc;
+ hs_eth_function[4] = NULL;
#else
- hs_eth_function[0] = 0;
+ hs_eth_function[1] = NULL;
#endif
}
#ifdef CONFIG_USB_ETH_RNDIS
static const struct usb_descriptor_header *hs_rndis_function [] = {
+ (struct usb_descriptor_header *) &otg_descriptor,
/* control interface matches ACM, not Ethernet */
(struct usb_descriptor_header *) &rndis_control_intf,
(struct usb_descriptor_header *) &header_desc,
(struct usb_descriptor_header *) &rndis_data_intf,
(struct usb_descriptor_header *) &hs_source_desc,
(struct usb_descriptor_header *) &hs_sink_desc,
- 0,
+ NULL,
};
#endif
* complications: class descriptors, and an altsetting.
*/
static int
-config_buf (enum usb_device_speed speed, u8 *buf, u8 type, unsigned index)
+config_buf (enum usb_device_speed speed,
+ u8 *buf, u8 type,
+ unsigned index, int is_otg)
{
- int len;
+ int len;
+ const struct usb_config_descriptor *config;
+ const struct usb_descriptor_header **function;
#ifdef CONFIG_USB_GADGET_DUALSPEED
int hs = (speed == USB_SPEED_HIGH);
if (type == USB_DT_OTHER_SPEED_CONFIG)
hs = !hs;
-#define which_config(t) (hs ? & t ## _config : & t ## _config)
#define which_fn(t) (hs ? & hs_ ## t ## _function : & fs_ ## t ## _function)
#else
-#define which_config(t) (& t ## _config)
#define which_fn(t) (& fs_ ## t ## _function)
#endif
/* list the RNDIS config first, to make Microsoft's drivers
* happy. DOCSIS 1.0 needs this too.
*/
- if (device_desc.bNumConfigurations == 2 && index == 0)
- len = usb_gadget_config_buf (which_config (rndis), buf,
- USB_BUFSIZ, (const struct usb_descriptor_header **)
- which_fn (rndis));
- else
+ if (device_desc.bNumConfigurations == 2 && index == 0) {
+ config = &rndis_config;
+ function = (const struct usb_descriptor_header **)
+ which_fn (rndis);
+ } else
#endif
- len = usb_gadget_config_buf (which_config (eth), buf,
- USB_BUFSIZ, (const struct usb_descriptor_header **)
- which_fn (eth));
+ {
+ config = ð_config;
+ function = (const struct usb_descriptor_header **)
+ which_fn (eth);
+ }
+
+ /* for now, don't advertise srp-only devices */
+ if (!is_otg)
+ function++;
+
+ len = usb_gadget_config_buf (config, buf, USB_BUFSIZ, function);
if (len < 0)
return len;
((struct usb_config_descriptor *) buf)->bDescriptorType = type;
if (dev->status_ep)
(void) usb_ep_disable (dev->status_ep);
#endif
- dev->status_ep = 0;
- dev->status = 0;
+ dev->status_ep = NULL;
+ dev->status = NULL;
#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS)
if (dev->rndis || !dev->cdc) {
if (dev->in_ep)
(void) usb_ep_disable (dev->out_ep);
}
#endif
- dev->in_ep = 0;
- dev->in = 0;
- dev->out_ep = 0;
- dev->out = 0;
+ dev->in_ep = NULL;
+ dev->in = NULL;
+ dev->out_ep = NULL;
+ dev->out = NULL;
} else
/* activate non-CDC configs right away
list_del (&req->list);
usb_ep_free_request (dev->in_ep, req);
}
- dev->in_ep = 0;
+ dev->in_ep = NULL;
}
if (dev->out_ep) {
usb_ep_disable (dev->out_ep);
list_del (&req->list);
usb_ep_free_request (dev->out_ep, req);
}
- dev->out_ep = 0;
+ dev->out_ep = NULL;
}
if (dev->status_ep) {
usb_ep_disable (dev->status_ep);
- dev->status_ep = 0;
+ dev->status_ep = NULL;
}
dev->config = 0;
}
/* descriptors just go into the pre-allocated ep0 buffer,
* while config change events may enable network traffic.
*/
+ req->complete = eth_setup_complete;
switch (ctrl->bRequest) {
case USB_REQ_GET_DESCRIPTOR:
case USB_DT_CONFIG:
value = config_buf (gadget->speed, req->buf,
ctrl->wValue >> 8,
- ctrl->wValue & 0xff);
+ ctrl->wValue & 0xff,
+ gadget->is_otg);
if (value >= 0)
value = min (ctrl->wLength, (u16) value);
break;
case USB_REQ_SET_CONFIGURATION:
if (ctrl->bRequestType != 0)
break;
+ if (gadget->a_hnp_support)
+ DEBUG (dev, "HNP available\n");
+ else if (gadget->a_alt_hnp_support)
+ DEBUG (dev, "HNP needs a different root port\n");
spin_lock (&dev->lock);
value = eth_set_config (dev, ctrl->wValue, GFP_ATOMIC);
spin_unlock (&dev->lock);
/* respond with data transfer before status phase? */
if (value >= 0) {
req->length = value;
+ req->zero = value < ctrl->wLength
+ && (value % gadget->ep0->maxpacket) == 0;
value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
if (value < 0) {
DEBUG (dev, "ep_queue --> %d\n", value);
/* Padding up to RX_EXTRA handles minor disagreements with host.
* Normally we use the USB "terminate on short read" convention;
- * so allow up to (N*maxpacket)-1, since that memory is normally
- * already allocated. Major loss of synch means -EOVERFLOW; any
- * obviously corrupted packets will automatically be discarded.
+ * so allow up to (N*maxpacket), since that memory is normally
+ * already allocated. Some hardware doesn't deal well with short
+ * reads (e.g. DMA must be N*maxpacket), so for now don't trim a
+ * byte off the end (to force hardware errors on overflow).
*
* RNDIS uses internal framing, and explicitly allows senders to
* pad to end-of-packet. That's potentially nice for speed,
size += sizeof (struct rndis_packet_msg_type);
#endif
size -= size % dev->out_ep->maxpacket;
-#ifdef CONFIG_USB_ETH_RNDIS
- if (!dev->rndis)
-#endif
- size--;
if ((skb = alloc_skb (size, gfp_flags)) == 0) {
DEBUG (dev, "no rx skb\n");
* use skb buffers.
*/
status = netif_rx (skb);
- skb = 0;
+ skb = NULL;
break;
/* software-driven interface shutdown */
clean:
/* nobody reading rx_reqs, so no dev->lock */
list_add (&req->list, &dev->rx_reqs);
- req = 0;
+ req = NULL;
}
if (req)
rx_submit (dev, req, GFP_ATOMIC);
struct eth_dev *dev = (struct eth_dev *) net->priv;
int length = skb->len;
int retval;
- struct usb_request *req = 0;
+ struct usb_request *req = NULL;
unsigned long flags;
/* FIXME check dev->cdc_filter to decide whether to send this,
dev->req->buf, dev->req->dma,
USB_BUFSIZ);
usb_ep_free_request (gadget->ep0, dev->req);
- dev->req = 0;
+ dev->req = NULL;
}
unregister_netdev (dev->net);
/* assuming we used keventd, it must quiesce too */
flush_scheduled_work ();
- set_gadget_data (gadget, 0);
+ set_gadget_data (gadget, NULL);
}
static u8 __init nibble (unsigned char c)
EP_OUT_NAME = ep->name;
ep->driver_data = ep; /* claim */
+#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
/* CDC Ethernet control interface doesn't require a status endpoint.
* Since some hosts expect one, try to allocate one anyway.
*/
"can't run RNDIS on %s\n",
gadget->name);
return -ENODEV;
-#ifdef DEV_CONFIG_CDC
} else if (cdc) {
control_intf.bNumEndpoints = 0;
/* FIXME remove endpoint from descriptor list */
-#endif
}
}
+#endif
/* one config: cdc, else minimal subset */
if (!cdc) {
device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
usb_gadget_set_selfpowered (gadget);
+ if (gadget->is_otg) {
+ otg_descriptor.bmAttributes |= USB_OTG_HNP,
+ eth_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
+#ifdef CONFIG_USB_ETH_RNDIS
+ rndis_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
+#endif
+ }
+
net = alloc_etherdev (sizeof *dev);
if (!net)
return status;
/* Module params for these addresses should come from ID proms.
* The host side address is used with CDC and RNDIS, and commonly
- * end ups in a persistent config database.
+ * ends up in a persistent config database.
*/
get_ether_addr(dev_addr, net->dev_addr);
if (cdc || rndis) {