07.06.2013 Views

Scsi - Index of

Scsi - Index of

Scsi - Index of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

迷雾重重的 Bulk 传输(五)<br />

usb_stor_bulk_transfer_sglist()这个函数有一定的蛊惑性,我们前面说过,之所以采用sglist,就是为<br />

了提高传输效率.我们更知道,sg 的目的就是让一堆不连续的buffers 一次DMA 操作就都传输出去.其实<br />

在<br />

usb 的故事中,事情并非如此.不过如果你对usb core 里边的行为不关心的话,那就无所谓了.有些事情,你<br />

不知道也好.<br />

446 行,447 行,aborting 了或者disconnecting 了,就不要传递数据了.<br />

然后452 行,usb_sg_init()函数被调用,这个函数来自drivers/usb/core/message.c,也就是说,她是<br />

usb 核心层提供的函数,干嘛用的?初始化sg 请求.其第一个参数是struct usb_sg_request 结构体的指<br />

针.这里咱们传递了us->current_sg 的地址给她,这里us->current_sg 第一次派上用场,所以咱们需要<br />

隆重的介绍一下.在struct us_data 中,定义了这么一个成员,struct usb_sg_request current_sg.<br />

曾几何时咱们见到过current_urb,这里又来了一个current_sg.也许你感觉很困惑,这很正常,色彩容易让<br />

人炫目,文字容易让人迷惑,只有张爱玲对现实的认识是清醒的.其实可以这样理解,之前我们知道struct<br />

urb 表征的是一个usb request,而这里struct usb_sg_request 实际上表示的是一个scatter gather<br />

request,从我们非usb 核心层的人来看,这两个结构体的用法是一样的.对于每次urb 请求,我们所作的只<br />

是申请一个结构体变量或者说申请指针然后申请内存,第二步就是提交urb,即调用usb_submit_urb(),<br />

剩下的事情usb core 就会去帮我们处理了,Linux 中的模块机制酷就酷在这里,每个模块都给别人服务,也<br />

同时享受着别人提供的服务.就像我们常说的,你站在桥上看风景,看风景的人在楼上看你.明月装饰了你的<br />

窗子,你装饰了别人的梦.你要想跟别人协同工作,你只要按照人家提供的函数去调用,把你的指针你的变量<br />

传递给别人,其它的你根本不用管,事成之后你人家自然会通知你.同样对于sg request,usb core 也实现<br />

了<br />

这些,我们只需要申请并初始化一个struct usb_sg_request 的结构体,然后提交,然后usb core 那边自<br />

然<br />

就知道该怎么处理了.闲话少说,先来看struct usb_sg_request 结构体.她来自include/linux/usb.h:<br />

988 /**<br />

989 * struct usb_sg_request - support for scatter/gather I/O<br />

990 * @status: zero indicates success, else negative errno<br />

164<br />

991 * @bytes: counts bytes transferred.<br />

992 *<br />

993 * These requests are initialized using usb_sg_init(), and then are used<br />

994 * as request handles passed to usb_sg_wait() or usb_sg_cancel(). Most<br />

995 * members <strong>of</strong> the request object aren't for driver access.<br />

996 *<br />

997 * The status and bytecount values are valid only after usb_sg_wait()<br />

998 * returns. If the status is zero, then the bytecount matches the total<br />

999 * from the request.<br />

1000 *<br />

1001 * After an error completion, drivers may need to clear a halt condition<br />

1002 * on the endpoint.<br />

1003 */<br />

1004 struct usb_sg_request {<br />

1005 int status;

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

Saved successfully!

Ooh no, something went wrong!