Re: about usb storage driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 6 May 2015, yoma sophian wrote:

> hi alan
> 
> 2015-05-06 2:32 GMT+08:00 Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>:
> > On Wed, 6 May 2015, yoma sophian wrote:
> >
> >> hi all:
> >> below are call back functions of usb_storage_driver:
> >> static struct usb_driver usb_storage_driver = {
> >>         .name =         "usb-storage",
> >>         .probe =        storage_probe,
> >>         .disconnect =   usb_stor_disconnect,
> >>         .suspend =      usb_stor_suspend,
> >>         .resume =       usb_stor_resume,
> >>         .reset_resume = usb_stor_reset_resume,
> >>         .pre_reset =    usb_stor_pre_reset,
> >>         .post_reset =   usb_stor_post_reset,
> >>         .id_table =     usb_storage_usb_ids,
> >>         .supports_autosuspend = 1,
> >>         .soft_unbind =  1,
> >> };
> >>
> >> my questions are:
> >> 1. where we register the us->suspend_resume_hook in usb_stor_suspend?
> >>     I grep the src, but cannot find where the callback is registered.
> >
> > The callback can be registered between the calls to usb_stor_probe1()
> > and usb_stor_probe2().
> I neither find suspend_resume_hook registered in probe1 or probe2.
> in probe1, we do following initialization:
>     mutex_init(&(us->dev_mutex));
>     us_set_lock_class(&us->dev_mutex, intf);
>     init_completion(&us->cmnd_ready);
>     init_completion(&(us->notify));
>     init_waitqueue_head(&us->delay_wait);
>     get_transport(us);
>     get_protocol(us);
> 
> in probe2,  we acquire us_data related resources and register host to
> scsi layer.
>     result = usb_stor_acquire_resources(us);
>     result = scsi_add_host(us_to_host(us), dev);
> 
> it seems we didn't register suspend_resume_hook.

Like I said above, you register the hook _between_ usb_stor_probe1() 
and usb_stor_probe2().  Not _inside_ either one.

For example:

	result = usb_stor_probe1(&us, intf, id, devlist);
	if (result)
		return result;
	us->suspend_resume_hook = hook_fn;
	result = urb_stor_probe2(us);

> >
> >> 2. suppose we are doing the scsi read/write command and system
> >> suddenly store to RAM/DISK, will that scsi command do?
> >> Drop it or keep the unfinished part ?
> >
> > It will wait until the SCSI command is finished and then invoke your
> > callback routine.
> so you mean if we are doing CBW, in/out date and CSW, once hibernate
> happen during the end of CBW, kernel will wait CSW finished then go to
> hibernate?

Yes.

> in the resume case, we will port reset device and re-enumerate storage device.
> if so, shouldn't we free previous resource allocated before hibernate?

What resource are you talking about?

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux