X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fusb%2Fstorage%2Fusb.c;fp=drivers%2Fusb%2Fstorage%2Fusb.c;h=70644506651f2bf58042ea9f1c5707145c3cb5c9;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=dbcf23980ff13f3f305857b78f297c1838940d69;hpb=76828883507a47dae78837ab5dec5a5b4513c667;p=linux-2.6.git diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index dbcf23980..706445066 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -47,14 +47,15 @@ * 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include #include #include -#include +#include #include #include #include #include +#include +#include #include #include @@ -97,6 +98,9 @@ #ifdef CONFIG_USB_STORAGE_ALAUDA #include "alauda.h" #endif +#ifdef CONFIG_USB_STORAGE_KARMA +#include "karma.h" +#endif /* Some informational data */ MODULE_AUTHOR("Matthew Dharm "); @@ -188,7 +192,7 @@ static int storage_suspend(struct usb_interface *iface, pm_message_t message) struct us_data *us = usb_get_intfdata(iface); /* Wait until no command is running */ - down(&us->dev_semaphore); + mutex_lock(&us->dev_mutex); US_DEBUGP("%s\n", __FUNCTION__); if (us->suspend_resume_hook) @@ -198,7 +202,7 @@ static int storage_suspend(struct usb_interface *iface, pm_message_t message) /* When runtime PM is working, we'll set a flag to indicate * whether we should autoresume when a SCSI request arrives. */ - up(&us->dev_semaphore); + mutex_unlock(&us->dev_mutex); return 0; } @@ -206,19 +210,50 @@ static int storage_resume(struct usb_interface *iface) { struct us_data *us = usb_get_intfdata(iface); - down(&us->dev_semaphore); + mutex_lock(&us->dev_mutex); US_DEBUGP("%s\n", __FUNCTION__); if (us->suspend_resume_hook) (us->suspend_resume_hook)(us, US_RESUME); iface->dev.power.power_state.event = PM_EVENT_ON; - up(&us->dev_semaphore); + mutex_unlock(&us->dev_mutex); return 0; } #endif /* CONFIG_PM */ +/* + * The next two routines get called just before and just after + * a USB port reset, whether from this driver or a different one. + */ + +static void storage_pre_reset(struct usb_interface *iface) +{ + struct us_data *us = usb_get_intfdata(iface); + + US_DEBUGP("%s\n", __FUNCTION__); + + /* Make sure no command runs during the reset */ + mutex_lock(&us->dev_mutex); +} + +static void storage_post_reset(struct usb_interface *iface) +{ + struct us_data *us = usb_get_intfdata(iface); + + US_DEBUGP("%s\n", __FUNCTION__); + + /* Report the reset to the SCSI core */ + scsi_lock(us_to_host(us)); + usb_stor_report_bus_reset(us); + scsi_unlock(us_to_host(us)); + + /* FIXME: Notify the subdrivers that they need to reinitialize + * the device */ + mutex_unlock(&us->dev_mutex); +} + /* * fill_inquiry_response takes an unsigned char array (which must * be at least 36 characters) and populates the vendor name, @@ -276,12 +311,12 @@ static int usb_stor_control_thread(void * __us) US_DEBUGP("*** thread awakened.\n"); /* lock the device pointers */ - down(&(us->dev_semaphore)); + mutex_lock(&(us->dev_mutex)); /* if the device has disconnected, we are free to exit */ if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { US_DEBUGP("-- exiting\n"); - up(&(us->dev_semaphore)); + mutex_unlock(&us->dev_mutex); break; } @@ -342,8 +377,12 @@ static int usb_stor_control_thread(void * __us) /* lock access to the state */ scsi_lock(host); + /* did the command already complete because of a disconnect? */ + if (!us->srb) + ; /* nothing to do */ + /* indicate that the command is done */ - if (us->srb->result != DID_ABORT << 16) { + else if (us->srb->result != DID_ABORT << 16) { US_DEBUGP("scsi cmd done, result=0x%x\n", us->srb->result); us->srb->scsi_done(us->srb); @@ -370,7 +409,7 @@ SkipForAbort: scsi_unlock(host); /* unlock the device pointers */ - up(&(us->dev_semaphore)); + mutex_unlock(&us->dev_mutex); } /* for (;;) */ scsi_host_put(host); @@ -447,7 +486,7 @@ static struct us_unusual_dev *find_unusual(const struct usb_device_id *id) } /* Get the unusual_devs entries and the string descriptors */ -static void get_device_info(struct us_data *us, const struct usb_device_id *id) +static int get_device_info(struct us_data *us, const struct usb_device_id *id) { struct usb_device *dev = us->pusb_dev; struct usb_interface_descriptor *idesc = @@ -464,6 +503,11 @@ static void get_device_info(struct us_data *us, const struct usb_device_id *id) unusual_dev->useTransport; us->flags = USB_US_ORIG_FLAGS(id->driver_info); + if (us->flags & US_FL_IGNORE_DEVICE) { + printk(KERN_INFO USB_STORAGE "device ignored\n"); + return -ENODEV; + } + /* * This flag is only needed when we're in high-speed, so let's * disable it if we're in full-speed @@ -493,7 +537,8 @@ static void get_device_info(struct us_data *us, const struct usb_device_id *id) if (msg >= 0 && !(us->flags & US_FL_NEED_OVERRIDE)) printk(KERN_NOTICE USB_STORAGE "This device " "(%04x,%04x,%04x S %02x P %02x)" - " has %s in unusual_devs.h\n" + " has %s in unusual_devs.h (kernel" + " %s)\n" " Please send a copy of this message to " "\n", le16_to_cpu(ddesc->idVendor), @@ -501,8 +546,11 @@ static void get_device_info(struct us_data *us, const struct usb_device_id *id) le16_to_cpu(ddesc->bcdDevice), idesc->bInterfaceSubClass, idesc->bInterfaceProtocol, - msgs[msg]); + msgs[msg], + UTS_RELEASE); } + + return 0; } /* Get the transport settings */ @@ -592,6 +640,23 @@ static int get_transport(struct us_data *us) break; #endif +#ifdef CONFIG_USB_STORAGE_ALAUDA + case US_PR_ALAUDA: + us->transport_name = "Alauda Control/Bulk"; + us->transport = alauda_transport; + us->transport_reset = usb_stor_Bulk_reset; + us->max_lun = 1; + break; +#endif + +#ifdef CONFIG_USB_STORAGE_KARMA + case US_PR_KARMA: + us->transport_name = "Rio Karma/Bulk"; + us->transport = rio_karma_transport; + us->transport_reset = usb_stor_Bulk_reset; + break; +#endif + default: return -EIO; } @@ -647,15 +712,6 @@ static int get_protocol(struct us_data *us) break; #endif -#ifdef CONFIG_USB_STORAGE_ALAUDA - case US_PR_ALAUDA: - us->transport_name = "Alauda Control/Bulk"; - us->transport = alauda_transport; - us->transport_reset = usb_stor_Bulk_reset; - us->max_lun = 1; - break; -#endif - default: return -EIO; } @@ -684,18 +740,16 @@ static int get_pipes(struct us_data *us) ep = &altsetting->endpoint[i].desc; /* Is it a BULK endpoint? */ - if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) - == USB_ENDPOINT_XFER_BULK) { + if (usb_endpoint_xfer_bulk(ep)) { /* BULK in or out? */ - if (ep->bEndpointAddress & USB_DIR_IN) + if (usb_endpoint_dir_in(ep)) ep_in = ep; else ep_out = ep; } /* Is it an interrupt endpoint? */ - else if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) - == USB_ENDPOINT_XFER_INT) { + else if (usb_endpoint_xfer_int(ep)) { ep_int = ep; } } @@ -805,32 +859,34 @@ static void dissociate_dev(struct us_data *us) * the host */ static void quiesce_and_remove_host(struct us_data *us) { + struct Scsi_Host *host = us_to_host(us); + /* Prevent new USB transfers, stop the current command, and * interrupt a SCSI-scan or device-reset delay */ + scsi_lock(host); set_bit(US_FLIDX_DISCONNECTING, &us->flags); + scsi_unlock(host); usb_stor_stop_transport(us); wake_up(&us->delay_wait); /* It doesn't matter if the SCSI-scanning thread is still running. * The thread will exit when it sees the DISCONNECTING flag. */ - /* Wait for the current command to finish, then remove the host */ - down(&us->dev_semaphore); - up(&us->dev_semaphore); - /* queuecommand won't accept any new commands and the control * thread won't execute a previously-queued command. If there * is such a command pending, complete it with an error. */ + mutex_lock(&us->dev_mutex); if (us->srb) { us->srb->result = DID_NO_CONNECT << 16; - scsi_lock(us_to_host(us)); + scsi_lock(host); us->srb->scsi_done(us->srb); us->srb = NULL; - scsi_unlock(us_to_host(us)); + scsi_unlock(host); } + mutex_unlock(&us->dev_mutex); /* Now we own no commands so it's safe to remove the SCSI host */ - scsi_remove_host(us_to_host(us)); + scsi_remove_host(host); } /* Second stage of disconnect processing: deallocate all resources */ @@ -870,9 +926,9 @@ retry: /* For bulk-only devices, determine the max LUN value */ if (us->protocol == US_PR_BULK && !(us->flags & US_FL_SINGLE_LUN)) { - down(&us->dev_semaphore); + mutex_lock(&us->dev_mutex); us->max_lun = usb_stor_Bulk_max_lun(us); - up(&us->dev_semaphore); + mutex_unlock(&us->dev_mutex); } scsi_scan_host(us_to_host(us)); printk(KERN_DEBUG "usb-storage: device scan complete\n"); @@ -912,7 +968,7 @@ static int storage_probe(struct usb_interface *intf, us = host_to_us(host); memset(us, 0, sizeof(struct us_data)); - init_MUTEX(&(us->dev_semaphore)); + mutex_init(&(us->dev_mutex)); init_MUTEX_LOCKED(&(us->sema)); init_completion(&(us->notify)); init_waitqueue_head(&us->delay_wait); @@ -929,7 +985,9 @@ static int storage_probe(struct usb_interface *intf, * of the match from the usb_device_id table, so we can find the * corresponding entry in the private table. */ - get_device_info(us, id); + result = get_device_info(us, id); + if (result) + goto BadDevice; /* Get the transport, protocol, and pipe settings */ result = get_transport(us); @@ -1001,6 +1059,8 @@ static struct usb_driver usb_storage_driver = { .suspend = storage_suspend, .resume = storage_resume, #endif + .pre_reset = storage_pre_reset, + .post_reset = storage_post_reset, .id_table = storage_usb_ids, };