Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
面讲过,她是一个等待队列头,在storage_probe()中被初始化,而以后在讲storage_disconnect()时会<br />
讲到,有这么一句,wake_up(&us->dev_reset_wait),她唤醒的正是这里进入睡眠的进程,这里1141 行,<br />
会进入睡眠,进入睡眠之前先判断US_FLIDX_DISCONNECTING 这个flag 有没有设置,要是设了就没有<br />
必要睡眠了,直接退出吧.1144 行,再判断一次,是真的设了这个flag 那么直接goto Done,返回rc,rc 就是<br />
初值FAILED.返回之前先清除US_FLIDX_RESETTING flag. 关于<br />
wait_event_interruptible_timeout()这个函数,我们当初在分析usb_stor_scan_thread()的时候已<br />
经详细的讲过了,所以这里不需要再浪费你我的青春去多讲了.<br />
188<br />
当然,如果US_FLIDX_DISCONNECTING 并没有设置,那么6s 钟时间到了,睡到自然醒,1150 行<br />
1153 行,usb_stor_clear_halt(),又是一个很亲切的函数,表忘了当前我们在讲GET MAX LUN 的时候<br />
就<br />
专门介绍了这个函数,而且那时候我们就已经说过,有一种情况下我们要调用这个函数,说的正是我们这里的<br />
情况,即当设备reset 之后,需要清楚halt 这个feature,然后端点才能正常工作.对于我们的两个bulk 端<br />
点,<br />
只要有一个清halt feature 失败了,那么整个这个负责reset 的函数usb_stor_reset_common 就算失<br />
败了,并且因此会返回FAILED,而且在返回之前先把US_FLIDX_RESETTING 这个flag 给去掉.<br />
然后到了这里,usb_stor_reset_commond 该返回了,然后我们惊讶的发现, usb_stor_Bulk_reset()<br />
也该返回了,再然后我们又惊讶的发现,device_reset()也该返回了.就这样,我们走完了device_reset()这<br />
么一个函数.之所以简单是因为它的使命本身就很简单,其实就是给设备发送一个reset 的request,然后<br />
clear 掉halt feature,保证设备的端点没有停止.就这些,这就够了.<br />
有多少爱可以胡来?(二)<br />
device_reset()完了之后我们来看bus_reset().同样来自drivers/usb/storage/scsiglue.c 中.<br />
265 /* This resets the device's USB port. */<br />
266 /* It refuses to work if there's more than one interface in<br />
267 * the device, so that other users are not affected. */<br />
268 /* This is always called with scsi_lock(srb->host) held */<br />
269 static int bus_reset(struct scsi_cmnd *srb)<br />
270 {<br />
271 struct us_data *us = (struct us_data *)srb->device->host->hostdata[0];<br />
272 int result, rc;<br />
273<br />
274 US_DEBUGP("%s called\n", __FUNCTION__);<br />
275<br />
276 scsi_unlock(srb->device->host);<br />
277<br />
278 /* The USB subsystem doesn't handle synchronisation between<br />
279 * a device's several drivers. Therefore we reset only devices<br />
280 * with just one interface, which we <strong>of</strong> course own. */<br />
281<br />
282 down(&(us->dev_semaphore));<br />
283 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {<br />
284 result = -EIO;