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

📄 irda-usb.c

📁 h内核
💻 C
📖 第 1 页 / 共 4 页
字号:
			/* Init : no endpoints */	self->bulk_in_ep = 0;	self->bulk_out_ep = 0;	self->bulk_int_ep = 0;	/* Let's look at all those endpoints */	for(i = 0; i < ennum; i++) {		/* All those variables will get optimised by the compiler,		 * so let's aim for clarity... - Jean II */		__u8 ep;	/* Endpoint address */		__u8 dir;	/* Endpoint direction */		__u8 attr;	/* Endpoint attribute */		__u16 psize;	/* Endpoint max packet size in bytes */		/* Get endpoint address, direction and attribute */		ep = endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;		dir = endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_DIR_MASK;		attr = endpoint[i].desc.bmAttributes;		psize = le16_to_cpu(endpoint[i].desc.wMaxPacketSize);		/* Is it a bulk endpoint ??? */		if(attr == USB_ENDPOINT_XFER_BULK) {			/* We need to find an IN and an OUT */			if(dir == USB_DIR_IN) {				/* This is our Rx endpoint */				self->bulk_in_ep = ep;			} else {				/* This is our Tx endpoint */				self->bulk_out_ep = ep;				self->bulk_out_mtu = psize;			}		} else {			if((attr == USB_ENDPOINT_XFER_INT) &&			   (dir == USB_DIR_IN)) {				/* This is our interrupt endpoint */				self->bulk_int_ep = ep;			} else {				ERROR("%s(), Unrecognised endpoint %02X.\n", __FUNCTION__, ep);			}		}	}	IRDA_DEBUG(0, "%s(), And our endpoints are : in=%02X, out=%02X (%d), int=%02X\n",		__FUNCTION__, self->bulk_in_ep, self->bulk_out_ep, self->bulk_out_mtu, self->bulk_int_ep);	/* Should be 8, 16, 32 or 64 bytes */	ASSERT(self->bulk_out_mtu == 64, ;);	return((self->bulk_in_ep != 0) && (self->bulk_out_ep != 0));}#ifdef IU_DUMP_CLASS_DESC/*------------------------------------------------------------------*//* * Function usb_irda_dump_class_desc(desc) * *    Prints out the contents of the IrDA class descriptor * */static inline void irda_usb_dump_class_desc(struct irda_class_desc *desc){	/* Values are little endian */	printk("bLength=%x\n", desc->bLength);	printk("bDescriptorType=%x\n", desc->bDescriptorType);	printk("bcdSpecRevision=%x\n", le16_to_cpu(desc->bcdSpecRevision)); 	printk("bmDataSize=%x\n", desc->bmDataSize);	printk("bmWindowSize=%x\n", desc->bmWindowSize);	printk("bmMinTurnaroundTime=%d\n", desc->bmMinTurnaroundTime);	printk("wBaudRate=%x\n", le16_to_cpu(desc->wBaudRate));	printk("bmAdditionalBOFs=%x\n", desc->bmAdditionalBOFs);	printk("bIrdaRateSniff=%x\n", desc->bIrdaRateSniff);	printk("bMaxUnicastList=%x\n", desc->bMaxUnicastList);}#endif /* IU_DUMP_CLASS_DESC *//*------------------------------------------------------------------*//* * Function irda_usb_find_class_desc(intf) * *    Returns instance of IrDA class descriptor, or NULL if not found * * The class descriptor is some extra info that IrDA USB devices will * offer to us, describing their IrDA characteristics. We will use that in * irda_usb_init_qos() */static inline struct irda_class_desc *irda_usb_find_class_desc(struct usb_interface *intf){	struct usb_device *dev = interface_to_usbdev (intf);	struct irda_class_desc *desc;	int ret;	desc = kmalloc(sizeof (*desc), GFP_KERNEL);	if (desc == NULL) 		return NULL;	memset(desc, 0, sizeof(*desc));	/* USB-IrDA class spec 1.0:	 *	6.1.3: Standard "Get Descriptor" Device Request is not	 *	       appropriate to retrieve class-specific descriptor	 *	6.2.5: Class Specific "Get Class Descriptor" Interface Request	 *	       is mandatory and returns the USB-IrDA class descriptor	 */	ret = usb_control_msg(dev, usb_rcvctrlpipe(dev,0),		IU_REQ_GET_CLASS_DESC,		USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,		0, intf->altsetting->desc.bInterfaceNumber, desc,		sizeof(*desc), msecs_to_jiffies(500));		IRDA_DEBUG(1, "%s(), ret=%d\n", __FUNCTION__, ret);	if (ret < sizeof(*desc)) {		WARNING("usb-irda: class_descriptor read %s (%d)\n",			(ret<0) ? "failed" : "too short", ret);	}	else if (desc->bDescriptorType != USB_DT_IRDA) {		WARNING("usb-irda: bad class_descriptor type\n");	}	else {#ifdef IU_DUMP_CLASS_DESC		irda_usb_dump_class_desc(desc);#endif	/* IU_DUMP_CLASS_DESC */		return desc;	}	kfree(desc);	return NULL;}/*********************** USB DEVICE CALLBACKS ***********************//* * Main calls from the USB subsystem. * Mostly registering a new irda-usb device and removing it.... *//*------------------------------------------------------------------*//* * This routine is called by the USB subsystem for each new device * in the system. We need to check if the device is ours, and in * this case start handling it. * The USB layer protect us from reentrancy (via BKL), so we don't need * to spinlock in there... Jean II */static int irda_usb_probe(struct usb_interface *intf,			  const struct usb_device_id *id){	struct net_device *net;	struct usb_device *dev = interface_to_usbdev(intf);	struct irda_usb_cb *self = NULL;	struct usb_host_interface *interface;	struct irda_class_desc *irda_desc;	int ret = -ENOMEM;	int i;		/* Driver instance index / Rx URB index */	/* Note : the probe make sure to call us only for devices that	 * matches the list of dongle (top of the file). So, we	 * don't need to check if the dongle is really ours.	 * Jean II */	MESSAGE("IRDA-USB found at address %d, Vendor: %x, Product: %x\n",		dev->devnum, le16_to_cpu(dev->descriptor.idVendor),		le16_to_cpu(dev->descriptor.idProduct));	net = alloc_irdadev(sizeof(*self));	if (!net) 		goto err_out;	self = net->priv;	self->netdev = net;	spin_lock_init(&self->lock);	SET_MODULE_OWNER(net);	/* Create all of the needed urbs */	for (i = 0; i < IU_MAX_RX_URBS; i++) {		self->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);		if (!self->rx_urb[i]) {			goto err_out_1;		}	}	self->tx_urb = usb_alloc_urb(0, GFP_KERNEL);	if (!self->tx_urb) {		goto err_out_1;	}	self->speed_urb = usb_alloc_urb(0, GFP_KERNEL);	if (!self->speed_urb) {		goto err_out_2;	}	/* Is this really necessary? (no, except maybe for broken devices) */	if (usb_reset_configuration (dev) < 0) {		err("reset_configuration failed");		ret = -EIO;		goto err_out_3;	}	/* Is this really necessary? */	/* Note : some driver do hardcode the interface number, some others	 * specify an alternate, but very few driver do like this.	 * Jean II */	ret = usb_set_interface(dev, intf->altsetting->desc.bInterfaceNumber, 0);	IRDA_DEBUG(1, "usb-irda: set interface %d result %d\n", intf->altsetting->desc.bInterfaceNumber, ret);	switch (ret) {		case 0:			break;		case -EPIPE:		/* -EPIPE = -32 */			/* Martin Diehl says if we get a -EPIPE we should			 * be fine and we don't need to do a usb_clear_halt().			 * - Jean II */			IRDA_DEBUG(0, "%s(), Received -EPIPE, ignoring...\n", __FUNCTION__);			break;		default:			IRDA_DEBUG(0, "%s(), Unknown error %d\n", __FUNCTION__, ret);			ret = -EIO;			goto err_out_3;	}	/* Find our endpoints */	interface = intf->cur_altsetting;	if(!irda_usb_parse_endpoints(self, interface->endpoint,				     interface->desc.bNumEndpoints)) {		ERROR("%s(), Bogus endpoints...\n", __FUNCTION__);		ret = -EIO;		goto err_out_3;	}	/* Find IrDA class descriptor */	irda_desc = irda_usb_find_class_desc(intf);	ret = -ENODEV;	if (irda_desc == NULL)		goto err_out_3;	self->irda_desc =  irda_desc;	self->present = 1;	self->netopen = 0;	self->capability = id->driver_info;	self->usbdev = dev;	self->usbintf = intf;	/* Allocate the buffer for speed changes */	/* Don't change this buffer size and allocation without doing	 * some heavy and complete testing. Don't ask why :-(	 * Jean II */	self->speed_buff = (char *) kmalloc(IRDA_USB_SPEED_MTU, GFP_KERNEL);	if (self->speed_buff == NULL) 		goto err_out_3;	memset(self->speed_buff, 0, IRDA_USB_SPEED_MTU);	ret = irda_usb_open(self);	if (ret) 		goto err_out_4;	MESSAGE("IrDA: Registered device %s\n", net->name);	usb_set_intfdata(intf, self);	return 0;err_out_4:	kfree(self->speed_buff);err_out_3:	/* Free all urbs that we may have created */	usb_free_urb(self->speed_urb);err_out_2:	usb_free_urb(self->tx_urb);err_out_1:	for (i = 0; i < IU_MAX_RX_URBS; i++) {		if (self->rx_urb[i])			usb_free_urb(self->rx_urb[i]);	}	free_netdev(net);err_out:	return ret;}/*------------------------------------------------------------------*//* * The current irda-usb device is removed, the USB layer tell us * to shut it down... * One of the constraints is that when we exit this function, * we cannot use the usb_device no more. Gone. Destroyed. kfree(). * Most other subsystem allow you to destroy the instance at a time * when it's convenient to you, to postpone it to a later date, but * not the USB subsystem. * So, we must make bloody sure that everything gets deactivated. * Jean II */static void irda_usb_disconnect(struct usb_interface *intf){	unsigned long flags;	struct irda_usb_cb *self = usb_get_intfdata(intf);	int i;	IRDA_DEBUG(1, "%s()\n", __FUNCTION__);	usb_set_intfdata(intf, NULL);	if (!self)		return;	/* Make sure that the Tx path is not executing. - Jean II */	spin_lock_irqsave(&self->lock, flags);	/* Oups ! We are not there any more.	 * This will stop/desactivate the Tx path. - Jean II */	self->present = 0;	/* We need to have irq enabled to unlink the URBs. That's OK,	 * at this point the Tx path is gone - Jean II */	spin_unlock_irqrestore(&self->lock, flags);	/* Hum... Check if networking is still active (avoid races) */	if((self->netopen) || (self->irlap)) {		/* Accept no more transmissions */		/*netif_device_detach(self->netdev);*/		netif_stop_queue(self->netdev);		/* Stop all the receive URBs */		for (i = 0; i < IU_MAX_RX_URBS; i++)			usb_unlink_urb(self->rx_urb[i]);		/* Cancel Tx and speed URB.		 * Toggle flags to make sure it's synchronous. */		self->tx_urb->transfer_flags &= ~URB_ASYNC_UNLINK;		usb_kill_urb(self->tx_urb);		self->speed_urb->transfer_flags &= ~URB_ASYNC_UNLINK;		usb_kill_urb(self->speed_urb);	}	/* Cleanup the device stuff */	irda_usb_close(self);	/* No longer attached to USB bus */	self->usbdev = NULL;	self->usbintf = NULL;	/* Clean up our urbs */	for (i = 0; i < IU_MAX_RX_URBS; i++)		usb_free_urb(self->rx_urb[i]);	/* Clean up Tx and speed URB */	usb_free_urb(self->tx_urb);	usb_free_urb(self->speed_urb);	/* Free self and network device */	free_netdev(self->netdev);	IRDA_DEBUG(0, "%s(), USB IrDA Disconnected\n", __FUNCTION__);}/*------------------------------------------------------------------*//* * USB device callbacks */static struct usb_driver irda_driver = {	.owner		= THIS_MODULE,	.name		= "irda-usb",	.probe		= irda_usb_probe,	.disconnect	= irda_usb_disconnect,	.id_table	= dongles,};/************************* MODULE CALLBACKS *************************//* * Deal with module insertion/removal * Mostly tell USB about our existence *//*------------------------------------------------------------------*//* * Module insertion */static int __init usb_irda_init(void){	int	ret;	ret = usb_register(&irda_driver);	if (ret < 0)		return ret;	MESSAGE("USB IrDA support registered\n");	return 0;}module_init(usb_irda_init);/*------------------------------------------------------------------*//* * Module removal */static void __exit usb_irda_cleanup(void){	/* Deregister the driver and remove all pending instances */	usb_deregister(&irda_driver);}module_exit(usb_irda_cleanup);/*------------------------------------------------------------------*//* * Module parameters */module_param(qos_mtt_bits, int, 0);MODULE_PARM_DESC(qos_mtt_bits, "Minimum Turn Time");MODULE_AUTHOR("Roman Weissgaerber <weissg@vienna.at>, Dag Brattli <dag@brattli.net> and Jean Tourrilhes <jt@hpl.hp.com>");MODULE_DESCRIPTION("IrDA-USB Dongle Driver"); MODULE_LICENSE("GPL");

⌨️ 快捷键说明

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