07.06.2013 Views

Scsi - Index of

Scsi - Index of

Scsi - Index of

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

191 init_timer(&to_timer);<br />

192 to_timer.expires = jiffies + timeout;<br />

193 to_timer.function = timeout_handler;<br />

194 to_timer.data = (unsigned long) us;<br />

195 add_timer(&to_timer);<br />

196 }<br />

197<br />

198 /* wait for the completion <strong>of</strong> the URB */<br />

199 wait_for_completion(&urb_done);<br />

200 clear_bit(US_FLIDX_URB_ACTIVE, &us->flags);<br />

201<br />

202 /* clean up the timeout timer */<br />

203 if (timeout > 0)<br />

204 del_timer_sync(&to_timer);<br />

205<br />

206 /* return the URB status */<br />

207 return us->current_urb->status;<br />

208 }<br />

76<br />

好了,代码贴完了,现在让我们一点一点去认识这段代码.记住我们最终就是为了看清楚<br />

usb_stor_Bulk_max_lun()这个函数究竟是怎么获得max lun 的.<br />

第一次亲密接触(二)<br />

对于设备驱动程序而言,控制传输要做的事情很简单,向usb core 提交一个urb,这个urb 中间包含了一<br />

个命令,或者说控制请求,因为命令更适合于我们后来要讲的某个重要的概念.这里我们要发送的就是GET<br />

MAX LUN.我们调用了一个函数, usb_stor_control_msg,其作用从名字上也可以看出,发送控制信息,即<br />

控制请求.做一件事情要遵守一件事情的规矩,发送控制信息必须按照一定的格式,发出去了人家才能看得<br />

懂.<br />

就像你要给远方的恋人寄一封信,你要在信封上按基本格式填写一些东西,你的信才能被寄出去对吗.<br />

我们结合usb_stor_control_msg 函数本身以及我们调用它的时候其具体上下文包括实际传递给它的<br />

参数来读这段代码,看看这个格式究竟是如何的.首先第一个参数us,这个不用多说了吧.星星还是那个星星,<br />

月亮也还是那个月亮,山也还是那座山,梁也还是那到梁,us 自然总还是那个us.而us 中有一个成员,叫做<br />

cr,<br />

见struct us_data 的定义:<br />

149 struct usb_ctrlrequest *cr; /* control requests */<br />

她是struct usb_ctrlrequest 结构指针, usb 规范规定了一个控制请求的格式为一个8个字节的数据包,<br />

而struct usb_ctrlrequest 正是专门为此而准备的8 个字节的一个变量,所以控制传输中总会用到她.她<br />

的<br />

定义在include/linux/usb_ch9.h 中:<br />

86 /**<br />

87 * struct usb_ctrlrequest - SETUP data for a USB device control request<br />

88 * @bRequestType: matches the USB bmRequestType field<br />

89 * @bRequest: matches the USB bRequest field

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!