u16				w_value = ctrl->wValue; u16				w_length = ctrl->wLength; 
u16				w_value = le16_to_cpu(ctrl->wValue); u16				w_length = le16_to_cpu(ctrl->wLength); 
gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl){	struct dev_data			*dev = get_gadget_data (gadget);	struct usb_request		*req = dev->req;	int				value = -EOPNOTSUPP;	struct usb_gadgetfs_event	*event;	u16				w_value = ctrl->wValue;	u16				w_length = ctrl->wLength;	spin_lock (&dev->lock);	dev->setup_abort = 0;	if (dev->state == STATE_UNCONNECTED) {		struct usb_ep	*ep;		struct ep_data	*data;		dev->state = STATE_CONNECTED;		dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket;#ifdef	HIGHSPEED		if (gadget->speed == USB_SPEED_HIGH && dev->hs_config == 0) {			ERROR (dev, "no high speed config??\n");			return -EINVAL;		}#endif	/* HIGHSPEED */		INFO (dev, "connected\n");		event = next_event (dev, GADGETFS_CONNECT);		event->u.speed = gadget->speed;		ep0_readable (dev);		list_for_each_entry (ep, &gadget->ep_list, ep_list) {			data = ep->driver_data;			/* ... down_trylock (&data->lock) ... */			if (data->state != STATE_EP_DEFER_ENABLE)				continue;#ifdef	HIGHSPEED			if (gadget->speed == USB_SPEED_HIGH)				value = usb_ep_enable (ep, &data->hs_desc);			else#endif	/* HIGHSPEED */				value = usb_ep_enable (ep, &data->desc);			if (value) {				ERROR (dev, "deferred %s enable --> %d\n",					data->name, value);				continue;			}			data->state = STATE_EP_ENABLED;			wake_up (&data->wait);			DBG (dev, "woke up %s waiters\n", data->name);		}	/* host may have given up waiting for response.  we can miss control	 * requests handled lower down (device/endpoint status and features);	 * then ep0_{read,write} will report the wrong status. controller	 * driver will have aborted pending i/o.	 */	} else if (dev->state == STATE_SETUP)		dev->setup_abort = 1;	req->buf = dev->rbuf;	req->dma = DMA_ADDR_INVALID;	req->context = NULL;	value = -EOPNOTSUPP;	switch (ctrl->bRequest) {	case USB_REQ_GET_DESCRIPTOR:		if (ctrl->bRequestType != USB_DIR_IN)			goto unrecognized;		switch (w_value >> 8) {		case USB_DT_DEVICE:			value = min (w_length, (u16) sizeof *dev->dev);			req->buf = dev->dev;			break;#ifdef	HIGHSPEED		case USB_DT_DEVICE_QUALIFIER:			if (!dev->hs_config)				break;			value = min (w_length, (u16)				sizeof (struct usb_qualifier_descriptor));			make_qualifier (dev);			break;		case USB_DT_OTHER_SPEED_CONFIG:			// FALLTHROUGH#endif		case USB_DT_CONFIG:			value = config_buf (dev,					w_value >> 8,					w_value & 0xff);			if (value >= 0)				value = min (w_length, (u16) value);			break;		case USB_DT_STRING:			goto unrecognized;		default:		// all others are errors			break;		}		break;	/* currently one config, two speeds */	case USB_REQ_SET_CONFIGURATION:		if (ctrl->bRequestType != 0)			break;		if (0 == (u8) w_value) {			value = 0;			dev->current_config = 0;			usb_gadget_vbus_draw(gadget, 8 /* mA */ );			// user mode expected to disable endpoints		} else {			u8	config, power;#ifdef	HIGHSPEED			if (gadget->speed == USB_SPEED_HIGH) {				config = dev->hs_config->bConfigurationValue;				power = dev->hs_config->bMaxPower;			} else#endif			{				config = dev->config->bConfigurationValue;				power = dev->config->bMaxPower;			}			if (config == (u8) w_value) {				value = 0;				dev->current_config = config;				usb_gadget_vbus_draw(gadget, 2 * power);			}		}		/* report SET_CONFIGURATION like any other control request,		 * except that usermode may not stall this.  the next		 * request mustn't be allowed start until this finishes:		 * endpoints and threads set up, etc.		 *		 * NOTE:  older PXA hardware (before PXA 255: without UDCCFR)		 * has bad/racey automagic that prevents synchronizing here.		 * even kernel mode drivers often miss them.		 */		if (value == 0) {			INFO (dev, "configuration #%d\n", dev->current_config);			if (dev->usermode_setup) {				dev->setup_can_stall = 0;				goto delegate;			}		}		break;#ifndef	CONFIG_USB_GADGETFS_PXA2XX	/* PXA automagically handles this request too */	case USB_REQ_GET_CONFIGURATION:		if (ctrl->bRequestType != 0x80)			break;		*(u8 *)req->buf = dev->current_config;		value = min (w_length, (u16) 1);		break;#endif	default:unrecognized:		VDEBUG (dev, "%s req%02x.%02x v%04x i%04x l%d\n",			dev->usermode_setup ? "delegate" : "fail",			ctrl->bRequestType, ctrl->bRequest,			w_value, le16_to_cpu(ctrl->wIndex), w_length);		/* if there's an ep0 reader, don't stall */		if (dev->usermode_setup) {			dev->setup_can_stall = 1;delegate:			dev->setup_in = (ctrl->bRequestType & USB_DIR_IN)						? 1 : 0;			dev->setup_out_ready = 0;			dev->setup_out_error = 0;			value = 0;			/* read DATA stage for OUT right away */			if (unlikely (!dev->setup_in && w_length)) {				value = setup_req (gadget->ep0, dev->req,							w_length);				if (value < 0)					break;				value = usb_ep_queue (gadget->ep0, dev->req,							GFP_ATOMIC);				if (value < 0) {					clean_req (gadget->ep0, dev->req);					break;				}				/* we can't currently stall these */				dev->setup_can_stall = 0;			}			/* state changes when reader collects event */			event = next_event (dev, GADGETFS_SETUP);			event->u.setup = *ctrl;			ep0_readable (dev);			spin_unlock (&dev->lock);			return 0;		}	}	/* proceed with data transfer and status phases? */	if (value >= 0 && dev->state != STATE_SETUP) {		req->length = value;		req->zero = value < w_length;		value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);		if (value < 0) {			DBG (dev, "ep_queue --> %d\n", value);			req->status = 0;		}	}	/* device stalls when value < 0 */	spin_unlock (&dev->lock);	return value;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/1bbc169621cbe502b9143a27eb12802a0f1d43a0/inode.c/clean/drivers/usb/gadget/inode.c