📄 usbd-bus.c
字号:
/* * linux/drivers/usbd/usbd-bus.c - USB Device Prototype * * Copyright (c) 2000, 2001, 2002 Lineo * Copyright (c) 2001 Hewlett Packard * * By: * Stuart Lynne <sl@lineo.com>, * Tom Rushworth <tbr@lineo.com>, * Bruce Balden <balden@lineo.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */#include <linux/config.h>#define USBD_CONFIG_NOWAIT_DEREGISTER_DEVICE 1#include <linux/module.h>#include <linux/init.h>#include <linux/kernel.h>#include <linux/list.h>#include <asm/uaccess.h>#include <linux/netdevice.h>#include <linux/skbuff.h>#include <linux/etherdevice.h>#include <net/arp.h>#include <linux/rtnetlink.h>#include <linux/smp_lock.h>#include <linux/ctype.h>#include <linux/timer.h>#include <linux/string.h>#include <linux/atmdev.h>#include <linux/pkt_sched.h>#include "usbd.h"#include "usbd-debug.h"#include "usbd-func.h"#include "usbd-bus.h"#include "usbd-inline.h"extern int usb_devices;extern struct usb_function_driver ep0_driver;extern int registered_functions;extern struct list_head function_drivers;extern struct list_head devices; static __inline__ struct usb_function_driver *list_entry_func(const struct list_head *le){ return list_entry(le, struct usb_function_driver, drivers);}static __inline__ struct usb_device_instance *list_entry_device(const struct list_head *le){ return list_entry(le, struct usb_device_instance, devices);}// Debug stuff - dbgflg_usbdbi_init must be defined in the main part of the bus driver (e.g. *_bi/init.c)extern int dbgflg_usbdbi_init;#define dbg_init(lvl,fmt,args...) dbgPRINT(dbgflg_usbdbi_init,lvl,fmt,##args)extern int registered_functions;extern int registered_devices;/** * usbd_fill_rcv - fill the rx recyle queue with empty urbs * @endpoint: * * Fill the recycle queue so that receive has some empty urbs to use. */void usbd_fill_rcv(struct usb_device_instance *device, struct usb_endpoint_instance *endpoint, int num){ int i; unsigned buffersize; dbg_init(1, "endpoint: %d", endpoint->endpoint_address); if (endpoint->rcv_packetSize) { // we need to allocate URBs with enough room for the endpoints transfersize plus one rounded // up to the next packetsize buffersize = ((endpoint->rcv_transferSize + endpoint->rcv_packetSize) / endpoint->rcv_packetSize) * endpoint->rcv_packetSize; dbg_init(1, "endpoint: %d packetSize: %d transferSize: %d buffersize: %d", endpoint->endpoint_address, endpoint->rcv_packetSize, endpoint->rcv_transferSize, buffersize); for (i = 0; i < num; i++) { usbd_recycle_urb(usbd_alloc_urb(device, device->function_instance_array, endpoint->endpoint_address, buffersize)); } } else { dbg_init(0, "endpoint: %d packetSize is Zero!", endpoint->endpoint_address); }}/** * usbd_flush_rcv - flush rcv * @endpoint: * * Iterate across the rx list and dispose of any urbs. */void usbd_flush_rcv(struct usb_endpoint_instance *endpoint){ struct usbd_urb *rcv_urb = NULL; unsigned long flags; if (endpoint) { local_irq_save(flags); if ((rcv_urb = endpoint->rcv_urb)) { endpoint->rcv_urb = NULL; usbd_dealloc_urb(rcv_urb); } while ((rcv_urb = first_urb_detached(&endpoint->rdy))) { usbd_dealloc_urb(rcv_urb); } local_irq_restore(flags); }}/** * usbd_flush_tx - flush tx urbs from endpoint * @endpoint: * * Iterate across the tx list and cancel any outstanding urbs. */void usbd_flush_tx(struct usb_endpoint_instance *endpoint){ struct usbd_urb *send_urb = NULL; unsigned long flags; if (endpoint) { local_irq_save(flags); if ((send_urb = endpoint->tx_urb)) { endpoint->tx_urb = NULL; usbd_urb_sent_irq(send_urb, SEND_FINISHED_ERROR); } while ((send_urb = first_urb_detached(&endpoint->tx))) { usbd_urb_sent_irq(send_urb, SEND_FINISHED_ERROR); } local_irq_restore(flags); }}/** * usbd_flush_ep - flush urbs from endpoint * @endpoint: * * Iterate across the approrpiate tx or rcv list and cancel any outstanding urbs. */void usbd_flush_ep(struct usb_endpoint_instance *endpoint){ if (endpoint) { if (endpoint->endpoint_address & 0x7f) { usbd_flush_tx(endpoint); } else { usbd_flush_rcv(endpoint); } }}/** * usbd_device_bh - * @data: * * Bottom half handler to process sent or received urbs. */ void usbd_device_bh(void *data){ struct usb_device_instance *device = data; int i; for (i = 0; i < device->bus->driver->max_endpoints; i++) { struct usb_endpoint_instance *endpoint = device->bus->endpoint_array + i; // process received urbs if (endpoint->endpoint_address && (endpoint->endpoint_address & USB_REQ_DIRECTION_MASK) == USB_REQ_HOST2DEVICE) { struct usbd_urb *urb; while ((urb = first_urb_detached(&endpoint->rcv))) { if ( !urb->function_instance || !urb->function_instance->function_driver->ops->recv_urb) { printk("usbd_device_bh: no recv_urb function\n"); usbd_recycle_urb(urb); } else if (urb->function_instance->function_driver->ops->recv_urb(urb)) { // XXX printk(KERN_ERR"usbd_device_bh: recv_urb failed\n"); usbd_recycle_urb(urb); } } } // process sent urbs if (endpoint->endpoint_address && (endpoint->endpoint_address & USB_REQ_DIRECTION_MASK) == USB_REQ_DEVICE2HOST) { struct usbd_urb *urb; while ((urb = first_urb_detached(&endpoint->done))) { if ( !urb->function_instance || !urb->function_instance->function_driver->ops->urb_sent || urb->function_instance->function_driver->ops->urb_sent(urb, urb->status)) { printk(KERN_ERR"usbd_device_bh: no urb_sent function\n"); usbd_dealloc_urb(urb); } } } }#if defined(CONFIG_SA1100_COLLIE) && defined(CONFIG_PM) { // Please clear autoPowerCancel flag during the transmission and the reception. // XXX XXX extern int autoPowerCancel; autoPowerCancel = 0; // Auto Power Off Cancel }#endif#if defined(CONFIG_SA1110_CALYPSO) && defined(CONFIG_PM) // Shouldn't need to make this atomic, all we need is a change indicator device->usbd_rxtx_timestamp = jiffies;#endif //MOD_DEC_USE_COUNT; //printk(KERN_DEBUG"usbd_device_bh: USE: %d\n", GET_USE_COUNT(THIS_MODULE)); return;}/** * usbd_function_bh - * @data: * * Bottom half handler to process events for functions. */ void usbd_function_bh(void *data){ struct usb_device_instance *device;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -