⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hub.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
📖 第 1 页 / 共 5 页
字号:
		case 0x10:		case 0x18:			dev_dbg(hub_dev, "no over-current protection\n");                        break;	}	spin_lock_init (&hub->tt.lock);	INIT_LIST_HEAD (&hub->tt.clear_list);	INIT_WORK (&hub->tt.kevent, hub_tt_kevent, hub);	switch (hdev->descriptor.bDeviceProtocol) {		case 0:			break;		case 1:			dev_dbg(hub_dev, "Single TT\n");			hub->tt.hub = hdev;			break;		case 2:			ret = usb_set_interface(hdev, 0, 1);			if (ret == 0) {				dev_dbg(hub_dev, "TT per port\n");				hub->tt.multi = 1;			} else				dev_err(hub_dev, "Using single TT (err %d)\n",					ret);			hub->tt.hub = hdev;			break;		default:			dev_dbg(hub_dev, "Unrecognized hub protocol %d\n",				hdev->descriptor.bDeviceProtocol);			break;	}	switch (hub->descriptor->wHubCharacteristics & HUB_CHAR_TTTT) {		case 0x00:			if (hdev->descriptor.bDeviceProtocol != 0)				dev_dbg(hub_dev, "TT requires at most 8 FS bit times\n");			break;		case 0x20:			dev_dbg(hub_dev, "TT requires at most 16 FS bit times\n");			break;		case 0x40:			dev_dbg(hub_dev, "TT requires at most 24 FS bit times\n");			break;		case 0x60:			dev_dbg(hub_dev, "TT requires at most 32 FS bit times\n");			break;	}	/* probe() zeroes hub->indicator[] */	if (hub->descriptor->wHubCharacteristics & HUB_CHAR_PORTIND) {		hub->has_indicators = 1;		dev_dbg(hub_dev, "Port indicators are supported\n");	}	dev_dbg(hub_dev, "power on to power good time: %dms\n",		hub->descriptor->bPwrOn2PwrGood * 2);	/* power budgeting mostly matters with bus-powered hubs,	 * and battery-powered root hubs (may provide just 8 mA).	 */	ret = usb_get_status(hdev, USB_RECIP_DEVICE, 0, &hubstatus);	if (ret < 0) {		message = "can't get hub status";		goto fail;	}	cpu_to_le16s(&hubstatus);	if ((hubstatus & (1 << USB_DEVICE_SELF_POWERED)) == 0) {		dev_dbg(hub_dev, "hub controller current requirement: %dmA\n",			hub->descriptor->bHubContrCurrent);		hub->power_budget = (501 - hub->descriptor->bHubContrCurrent)					/ 2;		dev_dbg(hub_dev, "%dmA bus power budget for children\n",			hub->power_budget * 2);	}	ret = hub_hub_status(hub, &hubstatus, &hubchange);	if (ret < 0) {		message = "can't get hub status";		goto fail;	}	/* local power status reports aren't always correct */	if (hdev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_SELFPOWER)		dev_dbg(hub_dev, "local power source is %s\n",			(hubstatus & HUB_STATUS_LOCAL_POWER)			? "lost (inactive)" : "good");	if ((hub->descriptor->wHubCharacteristics & HUB_CHAR_OCPM) == 0)		dev_dbg(hub_dev, "%sover-current condition exists\n",			(hubstatus & HUB_STATUS_OVERCURRENT) ? "" : "no ");	/* Start the interrupt endpoint */	pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress);	maxp = usb_maxpacket(hdev, pipe, usb_pipeout(pipe));	if (maxp > sizeof(*hub->buffer))		maxp = sizeof(*hub->buffer);	hub->urb = usb_alloc_urb(0, GFP_KERNEL);	if (!hub->urb) {		message = "couldn't allocate interrupt urb";		ret = -ENOMEM;		goto fail;	}	usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq,		hub, endpoint->bInterval);	hub->urb->transfer_dma = hub->buffer_dma;	hub->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	ret = usb_submit_urb(hub->urb, GFP_KERNEL);	if (ret) {		message = "couldn't submit status urb";		goto fail;	}	/* Wake up khubd */	wake_up(&khubd_wait);	/* maybe start cycling the hub leds */	if (hub->has_indicators && blinkenlights) {		set_port_led(hdev, 1, HUB_LED_GREEN);		hub->indicator [0] = INDICATOR_CYCLE;		schedule_delayed_work(&hub->leds, LED_CYCLE_PERIOD);	}	hub_power_on(hub);	return 0;fail:	dev_err (hub_dev, "config failed, %s (err %d)\n",			message, ret);	/* hub_disconnect() frees urb and descriptor */	return ret;}static unsigned highspeed_hubs;static void hub_quiesce(struct usb_hub *hub){	/* stop khubd and related activity */	hub->quiescing = 1;	usb_kill_urb(hub->urb);	if (hub->has_indicators)		cancel_delayed_work(&hub->leds);	if (hub->has_indicators || hub->tt.hub)		flush_scheduled_work();}#ifdef	CONFIG_USB_SUSPENDstatic void hub_reactivate(struct usb_hub *hub){	int	status;	hub->quiescing = 0;	status = usb_submit_urb(hub->urb, GFP_NOIO);	if (status < 0)		dev_err(&hub->intf->dev, "reactivate --> %d\n", status);	if (hub->has_indicators && blinkenlights)		schedule_delayed_work(&hub->leds, LED_CYCLE_PERIOD);}#endifstatic void hub_disconnect(struct usb_interface *intf){	struct usb_hub *hub = usb_get_intfdata (intf);	struct usb_device *hdev;	if (!hub)		return;	hdev = hub->hdev;	if (hdev->speed == USB_SPEED_HIGH)		highspeed_hubs--;	usb_set_intfdata (intf, NULL);	hub_quiesce(hub);	usb_free_urb(hub->urb);	hub->urb = NULL;	spin_lock_irq(&hub_event_lock);	list_del_init(&hub->event_list);	spin_unlock_irq(&hub_event_lock);	if (hub->descriptor) {		kfree(hub->descriptor);		hub->descriptor = NULL;	}	if (hub->status) {		kfree(hub->status);		hub->status = NULL;	}	if (hub->buffer) {		usb_buffer_free(hdev, sizeof(*hub->buffer), hub->buffer,				hub->buffer_dma);		hub->buffer = NULL;	}	/* Free the memory */	kfree(hub);}static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id){	struct usb_host_interface *desc;	struct usb_endpoint_descriptor *endpoint;	struct usb_device *hdev;	struct usb_hub *hub;	struct device *hub_dev;	desc = intf->cur_altsetting;	hdev = interface_to_usbdev(intf);	hub_dev = &intf->dev;	/* Some hubs have a subclass of 1, which AFAICT according to the */	/*  specs is not defined, but it works */	if ((desc->desc.bInterfaceSubClass != 0) &&	    (desc->desc.bInterfaceSubClass != 1)) {descriptor_error:		dev_err (hub_dev, "bad descriptor, ignoring hub\n");		return -EIO;	}	/* Multiple endpoints? What kind of mutant ninja-hub is this? */	if (desc->desc.bNumEndpoints != 1)		goto descriptor_error;	endpoint = &desc->endpoint[0].desc;	/* Output endpoint? Curiouser and curiouser.. */	if (!(endpoint->bEndpointAddress & USB_DIR_IN))		goto descriptor_error;	/* If it's not an interrupt endpoint, we'd better punt! */	if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)			!= USB_ENDPOINT_XFER_INT)		goto descriptor_error;	/* We found a hub */	dev_info (hub_dev, "USB hub found\n");	hub = kmalloc(sizeof(*hub), GFP_KERNEL);	if (!hub) {		dev_dbg (hub_dev, "couldn't kmalloc hub struct\n");		return -ENOMEM;	}	memset(hub, 0, sizeof(*hub));	INIT_LIST_HEAD(&hub->event_list);	hub->intf = intf;	hub->hdev = hdev;	INIT_WORK(&hub->leds, led_work, hub);	usb_set_intfdata (intf, hub);	if (hdev->speed == USB_SPEED_HIGH)		highspeed_hubs++;	if (hub_configure(hub, endpoint) >= 0)		return 0;	hub_disconnect (intf);	return -ENODEV;}static inthub_ioctl(struct usb_interface *intf, unsigned int code, void *user_data){	struct usb_device *hdev = interface_to_usbdev (intf);	/* assert ifno == 0 (part of hub spec) */	switch (code) {	case USBDEVFS_HUB_PORTINFO: {		struct usbdevfs_hub_portinfo *info = user_data;		unsigned long flags;		int i;		spin_lock_irqsave(&hub_event_lock, flags);		if (hdev->devnum <= 0)			info->nports = 0;		else {			info->nports = hdev->maxchild;			for (i = 0; i < info->nports; i++) {				if (hdev->children[i] == NULL)					info->port[i] = 0;				else					info->port[i] =						hdev->children[i]->devnum;			}		}		spin_unlock_irqrestore(&hub_event_lock, flags);		return info->nports + 1;		}	default:		return -ENOSYS;	}}/* caller has locked the hub and must own the device lock */static int hub_reset(struct usb_hub *hub){	struct usb_device *hdev = hub->hdev;	int i;	/* Disconnect any attached devices */	for (i = 0; i < hub->descriptor->bNbrPorts; i++) {		if (hdev->children[i])			usb_disconnect(&hdev->children[i]);	}	/* Attempt to reset the hub */	if (hub->urb)		usb_kill_urb(hub->urb);	else		return -1;	if (__usb_reset_device(hdev))		return -1;	hub->urb->dev = hdev;                                                    	if (usb_submit_urb(hub->urb, GFP_KERNEL))		return -1;	hub_power_on(hub);	return 0;}/* caller has locked the hub *//* FIXME!  This routine should be subsumed into hub_reset */static void hub_start_disconnect(struct usb_device *hdev){	struct usb_device *parent = hdev->parent;	int i;	/* Find the device pointer to disconnect */	if (parent) {		for (i = 0; i < parent->maxchild; i++) {			if (parent->children[i] == hdev) {				usb_disconnect(&parent->children[i]);				return;			}		}	}	dev_err(&hdev->dev, "cannot disconnect hub!\n");}static void recursively_mark_NOTATTACHED(struct usb_device *udev){	int i;	for (i = 0; i < udev->maxchild; ++i) {		if (udev->children[i])			recursively_mark_NOTATTACHED(udev->children[i]);	}	udev->state = USB_STATE_NOTATTACHED;}/* grab device/port lock, returning index of that port (zero based). * protects the upstream link used by this device from concurrent * tree operations like suspend, resume, reset, and disconnect, which * apply to everything downstream of a given port. */static int locktree(struct usb_device *udev){	int			t;	struct usb_device	*hdev;	if (!udev)		return -ENODEV;	/* root hub is always the first lock in the series */	hdev = udev->parent;	if (!hdev) {		down(&udev->serialize);		return 0;	}	/* on the path from root to us, lock everything from	 * top down, dropping parent locks when not needed	 *	 * NOTE: if disconnect were to ignore the locking, we'd need	 * to get extra refcounts to everything since hdev->children	 * and udev->parent could be invalidated while we work...	 */	t = locktree(hdev);	if (t < 0)		return t;	spin_lock_irq(&device_state_lock);	for (t = 0; t < hdev->maxchild; t++) {		if (hdev->children[t] == udev) {			/* everything is fail-fast once disconnect			 * processing starts			 */			if (udev->state == USB_STATE_NOTATTACHED)				break;			/* when everyone grabs locks top->bottom,			 * non-overlapping work may be concurrent			 */			spin_unlock_irq(&device_state_lock);			down(&udev->serialize);			up(&hdev->serialize);			return t;		}	}	spin_unlock_irq(&device_state_lock);	up(&hdev->serialize);	return -ENODEV;}/** * usb_set_device_state - change a device's current state (usbcore-internal) * @udev: pointer to device whose state should be changed * @new_state: new state value to be stored * * udev->state is _not_ protected by the device lock.  This * is so that devices can be marked as disconnected as soon as possible, * without having to wait for the semaphore to be released.  Instead, * changes to the state must be protected by the device_state_lock spinlock. * * Once a device has been added to the device tree, all changes to its state * should be made using this routine.  The state should _not_ be set directly. * * If udev->state is already USB_STATE_NOTATTACHED then no change is made. * Otherwise udev->state is set to new_state, and if new_state is * USB_STATE_NOTATTACHED then all of udev's descendant's states are also set * to USB_STATE_NOTATTACHED. */void usb_set_device_state(struct usb_device *udev,		enum usb_device_state new_state){	unsigned long flags;	spin_lock_irqsave(&device_state_lock, flags);	if (udev->state == USB_STATE_NOTATTACHED)		;	/* do nothing */	else if (new_state != USB_STATE_NOTATTACHED)		udev->state = new_state;	else		recursively_mark_NOTATTACHED(udev);	spin_unlock_irqrestore(&device_state_lock, flags);}static void choose_address(struct usb_device *udev){	int		devnum;	struct usb_bus	*bus = udev->bus;	/* If khubd ever becomes multithreaded, this will need a lock */	/* Try to allocate the next devnum beginning at bus->devnum_next. */	devnum = find_next_zero_bit(bus->devmap.devicemap, 128,			bus->devnum_next);	if (devnum >= 128)		devnum = find_next_zero_bit(bus->devmap.devicemap, 128, 1);	bus->devnum_next = ( devnum >= 127 ? 1 : devnum + 1);	if (devnum < 128) {		set_bit(devnum, bus->devmap.devicemap);		udev->devnum = devnum;	}}static void release_address(struct usb_device *udev){	if (udev->devnum > 0) {		clear_bit(udev->devnum, udev->bus->devmap.devicemap);		udev->devnum = -1;	}}/** * usb_disconnect - disconnect a device (usbcore-internal) * @pdev: pointer to device being disconnected, into a locked hub * Context: !in_interrupt ()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -