USB: gadget: ethernet gadget cleanups, shrinkage
Clean up the ethernet gadget, using newer APIs and conventions: - gadget_is_dualspeed() and gadget_is_otg() ... #ifdef removal - Remove many now-needless #includes - Use the VERBOSE_DEBUG convention - Minor whitespace fixes. - Fix a warning from "sparse". Surprisingly, this saved about 2K of code (16%) on a fullspeed-only ARMv4 platform. I'm bit puzzled by that (it's so much!), but approve of the result. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
a4e3ef5597
commit
0cf4f2de0a
|
@ -19,41 +19,19 @@
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* #define VERBOSE_DEBUG */
|
||||||
|
|
||||||
// #define DEBUG 1
|
|
||||||
// #define VERBOSE
|
|
||||||
|
|
||||||
#include <linux/module.h>
|
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/delay.h>
|
|
||||||
#include <linux/ioport.h>
|
|
||||||
#include <linux/slab.h>
|
|
||||||
#include <linux/errno.h>
|
|
||||||
#include <linux/init.h>
|
|
||||||
#include <linux/timer.h>
|
|
||||||
#include <linux/list.h>
|
|
||||||
#include <linux/interrupt.h>
|
|
||||||
#include <linux/utsname.h>
|
#include <linux/utsname.h>
|
||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include <linux/moduleparam.h>
|
|
||||||
#include <linux/ctype.h>
|
#include <linux/ctype.h>
|
||||||
|
#include <linux/etherdevice.h>
|
||||||
#include <asm/byteorder.h>
|
#include <linux/ethtool.h>
|
||||||
#include <asm/io.h>
|
|
||||||
#include <asm/irq.h>
|
|
||||||
#include <asm/system.h>
|
|
||||||
#include <asm/uaccess.h>
|
|
||||||
#include <asm/unaligned.h>
|
|
||||||
|
|
||||||
#include <linux/usb/ch9.h>
|
#include <linux/usb/ch9.h>
|
||||||
#include <linux/usb/cdc.h>
|
#include <linux/usb/cdc.h>
|
||||||
#include <linux/usb_gadget.h>
|
#include <linux/usb_gadget.h>
|
||||||
|
|
||||||
#include <linux/random.h>
|
|
||||||
#include <linux/netdevice.h>
|
|
||||||
#include <linux/etherdevice.h>
|
|
||||||
#include <linux/ethtool.h>
|
|
||||||
|
|
||||||
#include "gadget_chips.h"
|
#include "gadget_chips.h"
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
@ -356,15 +334,15 @@ module_param (qmult, uint, S_IRUGO|S_IWUSR);
|
||||||
#define qlen(gadget) \
|
#define qlen(gadget) \
|
||||||
(DEFAULT_QLEN*((gadget->speed == USB_SPEED_HIGH) ? qmult : 1))
|
(DEFAULT_QLEN*((gadget->speed == USB_SPEED_HIGH) ? qmult : 1))
|
||||||
|
|
||||||
/* also defer IRQs on highspeed TX */
|
|
||||||
#define TX_DELAY qmult
|
|
||||||
|
|
||||||
static inline int BITRATE(struct usb_gadget *g)
|
static inline int BITRATE(struct usb_gadget *g)
|
||||||
{
|
{
|
||||||
return (g->speed == USB_SPEED_HIGH) ? HS_BPS : FS_BPS;
|
return (g->speed == USB_SPEED_HIGH) ? HS_BPS : FS_BPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* full speed (low speed doesn't do bulk) */
|
#else /* full speed (low speed doesn't do bulk) */
|
||||||
|
|
||||||
|
#define qmult 1
|
||||||
|
|
||||||
#define DEVSPEED USB_SPEED_FULL
|
#define DEVSPEED USB_SPEED_FULL
|
||||||
|
|
||||||
#define qlen(gadget) DEFAULT_QLEN
|
#define qlen(gadget) DEFAULT_QLEN
|
||||||
|
@ -390,7 +368,7 @@ static inline int BITRATE(struct usb_gadget *g)
|
||||||
do { } while (0)
|
do { } while (0)
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE_DEBUG
|
||||||
#define VDEBUG DEBUG
|
#define VDEBUG DEBUG
|
||||||
#else
|
#else
|
||||||
#define VDEBUG(dev,fmt,args...) \
|
#define VDEBUG(dev,fmt,args...) \
|
||||||
|
@ -830,8 +808,6 @@ static const struct usb_descriptor_header *fs_rndis_function [] = {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_USB_GADGET_DUALSPEED
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* usb 2.0 devices need to expose both high speed and full speed
|
* usb 2.0 devices need to expose both high speed and full speed
|
||||||
* descriptors, unless they only run at full speed.
|
* descriptors, unless they only run at full speed.
|
||||||
|
@ -934,18 +910,15 @@ static const struct usb_descriptor_header *hs_rndis_function [] = {
|
||||||
|
|
||||||
|
|
||||||
/* maxpacket and other transfer characteristics vary by speed. */
|
/* maxpacket and other transfer characteristics vary by speed. */
|
||||||
#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
|
static inline struct usb_endpoint_descriptor *
|
||||||
|
ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
|
||||||
#else
|
struct usb_endpoint_descriptor *fs)
|
||||||
|
|
||||||
/* if there's no high speed support, maxpacket doesn't change. */
|
|
||||||
#define ep_desc(g,hs,fs) (((void)(g)), (fs))
|
|
||||||
|
|
||||||
static inline void __init hs_subset_descriptors(void)
|
|
||||||
{
|
{
|
||||||
|
if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
|
||||||
|
return hs;
|
||||||
|
return fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !CONFIG_USB_GADGET_DUALSPEED */
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -989,22 +962,19 @@ static struct usb_gadget_strings stringtab = {
|
||||||
* complications: class descriptors, and an altsetting.
|
* complications: class descriptors, and an altsetting.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
config_buf (enum usb_device_speed speed,
|
config_buf(struct usb_gadget *g, u8 *buf, u8 type, unsigned index, int is_otg)
|
||||||
u8 *buf, u8 type,
|
|
||||||
unsigned index, int is_otg)
|
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
const struct usb_config_descriptor *config;
|
const struct usb_config_descriptor *config;
|
||||||
const struct usb_descriptor_header **function;
|
const struct usb_descriptor_header **function;
|
||||||
#ifdef CONFIG_USB_GADGET_DUALSPEED
|
int hs = 0;
|
||||||
int hs = (speed == USB_SPEED_HIGH);
|
|
||||||
|
|
||||||
if (type == USB_DT_OTHER_SPEED_CONFIG)
|
if (gadget_is_dualspeed(g)) {
|
||||||
hs = !hs;
|
hs = (g->speed == USB_SPEED_HIGH);
|
||||||
|
if (type == USB_DT_OTHER_SPEED_CONFIG)
|
||||||
|
hs = !hs;
|
||||||
|
}
|
||||||
#define which_fn(t) (hs ? hs_ ## t ## _function : fs_ ## t ## _function)
|
#define which_fn(t) (hs ? hs_ ## t ## _function : fs_ ## t ## _function)
|
||||||
#else
|
|
||||||
#define which_fn(t) (fs_ ## t ## _function)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (index >= device_desc.bNumConfigurations)
|
if (index >= device_desc.bNumConfigurations)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -1217,7 +1187,7 @@ eth_set_config (struct eth_dev *dev, unsigned number, gfp_t gfp_flags)
|
||||||
if (number)
|
if (number)
|
||||||
eth_reset_config (dev);
|
eth_reset_config (dev);
|
||||||
usb_gadget_vbus_draw(dev->gadget,
|
usb_gadget_vbus_draw(dev->gadget,
|
||||||
dev->gadget->is_otg ? 8 : 100);
|
gadget_is_otg(dev->gadget) ? 8 : 100);
|
||||||
} else {
|
} else {
|
||||||
char *speed;
|
char *speed;
|
||||||
unsigned power;
|
unsigned power;
|
||||||
|
@ -1399,24 +1369,22 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
|
||||||
value = min (wLength, (u16) sizeof device_desc);
|
value = min (wLength, (u16) sizeof device_desc);
|
||||||
memcpy (req->buf, &device_desc, value);
|
memcpy (req->buf, &device_desc, value);
|
||||||
break;
|
break;
|
||||||
#ifdef CONFIG_USB_GADGET_DUALSPEED
|
|
||||||
case USB_DT_DEVICE_QUALIFIER:
|
case USB_DT_DEVICE_QUALIFIER:
|
||||||
if (!gadget->is_dualspeed)
|
if (!gadget_is_dualspeed(gadget))
|
||||||
break;
|
break;
|
||||||
value = min (wLength, (u16) sizeof dev_qualifier);
|
value = min (wLength, (u16) sizeof dev_qualifier);
|
||||||
memcpy (req->buf, &dev_qualifier, value);
|
memcpy (req->buf, &dev_qualifier, value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_DT_OTHER_SPEED_CONFIG:
|
case USB_DT_OTHER_SPEED_CONFIG:
|
||||||
if (!gadget->is_dualspeed)
|
if (!gadget_is_dualspeed(gadget))
|
||||||
break;
|
break;
|
||||||
// FALLTHROUGH
|
// FALLTHROUGH
|
||||||
#endif /* CONFIG_USB_GADGET_DUALSPEED */
|
|
||||||
case USB_DT_CONFIG:
|
case USB_DT_CONFIG:
|
||||||
value = config_buf (gadget->speed, req->buf,
|
value = config_buf(gadget, req->buf,
|
||||||
wValue >> 8,
|
wValue >> 8,
|
||||||
wValue & 0xff,
|
wValue & 0xff,
|
||||||
gadget->is_otg);
|
gadget_is_otg(gadget));
|
||||||
if (value >= 0)
|
if (value >= 0)
|
||||||
value = min (wLength, (u16) value);
|
value = min (wLength, (u16) value);
|
||||||
break;
|
break;
|
||||||
|
@ -1585,12 +1553,12 @@ done_set_intf:
|
||||||
&& rndis_control_intf.bInterfaceNumber
|
&& rndis_control_intf.bInterfaceNumber
|
||||||
== wIndex) {
|
== wIndex) {
|
||||||
u8 *buf;
|
u8 *buf;
|
||||||
|
u32 n;
|
||||||
|
|
||||||
/* return the result */
|
/* return the result */
|
||||||
buf = rndis_get_next_response (dev->rndis_config,
|
buf = rndis_get_next_response(dev->rndis_config, &n);
|
||||||
&value);
|
|
||||||
if (buf) {
|
if (buf) {
|
||||||
memcpy (req->buf, buf, value);
|
memcpy(req->buf, buf, n);
|
||||||
req->complete = rndis_response_complete;
|
req->complete = rndis_response_complete;
|
||||||
rndis_free_response(dev->rndis_config, buf);
|
rndis_free_response(dev->rndis_config, buf);
|
||||||
}
|
}
|
||||||
|
@ -2026,12 +1994,11 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
|
||||||
|
|
||||||
req->length = length;
|
req->length = length;
|
||||||
|
|
||||||
#ifdef CONFIG_USB_GADGET_DUALSPEED
|
|
||||||
/* throttle highspeed IRQ rate back slightly */
|
/* throttle highspeed IRQ rate back slightly */
|
||||||
req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH)
|
if (gadget_is_dualspeed(dev->gadget))
|
||||||
? ((atomic_read (&dev->tx_qlen) % TX_DELAY) != 0)
|
req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH)
|
||||||
: 0;
|
? ((atomic_read(&dev->tx_qlen) % qmult) != 0)
|
||||||
#endif
|
: 0;
|
||||||
|
|
||||||
retval = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC);
|
retval = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC);
|
||||||
switch (retval) {
|
switch (retval) {
|
||||||
|
@ -2188,8 +2155,7 @@ static int eth_stop (struct net_device *net)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rndis_active(dev)) {
|
if (rndis_active(dev)) {
|
||||||
rndis_set_param_medium (dev->rndis_config,
|
rndis_set_param_medium(dev->rndis_config, NDIS_MEDIUM_802_3, 0);
|
||||||
NDIS_MEDIUM_802_3, 0);
|
|
||||||
(void) rndis_signal_disconnect (dev->rndis_config);
|
(void) rndis_signal_disconnect (dev->rndis_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2443,26 +2409,28 @@ autoconf_fail:
|
||||||
if (rndis)
|
if (rndis)
|
||||||
device_desc.bNumConfigurations = 2;
|
device_desc.bNumConfigurations = 2;
|
||||||
|
|
||||||
#ifdef CONFIG_USB_GADGET_DUALSPEED
|
if (gadget_is_dualspeed(gadget)) {
|
||||||
if (rndis)
|
if (rndis)
|
||||||
dev_qualifier.bNumConfigurations = 2;
|
dev_qualifier.bNumConfigurations = 2;
|
||||||
else if (!cdc)
|
else if (!cdc)
|
||||||
dev_qualifier.bDeviceClass = USB_CLASS_VENDOR_SPEC;
|
dev_qualifier.bDeviceClass = USB_CLASS_VENDOR_SPEC;
|
||||||
|
|
||||||
/* assumes ep0 uses the same value for both speeds ... */
|
/* assumes ep0 uses the same value for both speeds ... */
|
||||||
dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
|
dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
|
||||||
|
|
||||||
/* and that all endpoints are dual-speed */
|
/* and that all endpoints are dual-speed */
|
||||||
hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
|
hs_source_desc.bEndpointAddress =
|
||||||
hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
|
fs_source_desc.bEndpointAddress;
|
||||||
|
hs_sink_desc.bEndpointAddress =
|
||||||
|
fs_sink_desc.bEndpointAddress;
|
||||||
#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
|
#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
|
||||||
if (status_ep)
|
if (status_ep)
|
||||||
hs_status_desc.bEndpointAddress =
|
hs_status_desc.bEndpointAddress =
|
||||||
fs_status_desc.bEndpointAddress;
|
fs_status_desc.bEndpointAddress;
|
||||||
#endif
|
#endif
|
||||||
#endif /* DUALSPEED */
|
}
|
||||||
|
|
||||||
if (gadget->is_otg) {
|
if (gadget_is_otg(gadget)) {
|
||||||
otg_descriptor.bmAttributes |= USB_OTG_HNP,
|
otg_descriptor.bmAttributes |= USB_OTG_HNP,
|
||||||
eth_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
|
eth_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
|
||||||
eth_config.bMaxPower = 4;
|
eth_config.bMaxPower = 4;
|
||||||
|
@ -2598,12 +2566,11 @@ fail0:
|
||||||
if (rndis_set_param_dev (dev->rndis_config, dev->net,
|
if (rndis_set_param_dev (dev->rndis_config, dev->net,
|
||||||
&dev->stats, &dev->cdc_filter))
|
&dev->stats, &dev->cdc_filter))
|
||||||
goto fail0;
|
goto fail0;
|
||||||
if (rndis_set_param_vendor (dev->rndis_config, vendorID,
|
if (rndis_set_param_vendor(dev->rndis_config, vendorID,
|
||||||
manufacturer))
|
manufacturer))
|
||||||
goto fail0;
|
goto fail0;
|
||||||
if (rndis_set_param_medium (dev->rndis_config,
|
if (rndis_set_param_medium(dev->rndis_config,
|
||||||
NDIS_MEDIUM_802_3,
|
NDIS_MEDIUM_802_3, 0))
|
||||||
0))
|
|
||||||
goto fail0;
|
goto fail0;
|
||||||
INFO (dev, "RNDIS ready\n");
|
INFO (dev, "RNDIS ready\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue