You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
75 enum dma_data_direction sc_data_direction;<br />
76 enum dma_data_direction sc_old_data_direction;<br />
这些被用来表征数据阶段数据传输的方向.DMA_TO_DEVICE 表示从主存到设<br />
备,DMA_FROM_DEVICE 表示从设备到主存.坊间有传闻说,DMA_NONE 则只被用于调试,一般不能使<br />
用<br />
否则将有可能导致内核崩溃.不过更准确一点是,usb mass storage 协议里边规定了双向传输是非法的,<br />
而<br />
一个命令传输零数据是合法的,比如TEST_UNIT_READY 命令就不用传输数据.DMA_BIDIRECTIONAL<br />
表示两个方向都有可能,换言之也就是不知道究竟是哪个方向.就比如您找某位半仙算命,而当您想考考他,<br />
问他您是什么时候生的,他却对您说,您不是上半年生的就是下半年生的.这样只能说明他什么都不知道.同<br />
理,338 行看到srb 的sc_data_direction 是DMA_BIDIRECTIONAL 的时候,自然就当作出错了.因为<br />
不<br />
确定方向的话也就没法传输数据了嘛不是.<br />
346 行, US_FL_SCM_MULT_TARG 这个flag,表示设备支持多个target,这里的意思很明显,对于那些<br />
不支持多个target 的设备,其us->srb->device->id 必须为0,否则就有问题了.struct us_data 结构体<br />
中的成员struct scsi_cmnd * srb,struct scsi_cmnd 结构体中有一成员struct scsi_device * device,<br />
而struct scsi_device 顾名思义,描述一个scsi device,就像过去的struct usb_device 用来描述usb<br />
device 一样,这些写Linux 代码的哥们儿也没别的技巧,就这几招.不用看也知道,struct scsi_device 又<br />
是<br />
一个变态的数据结构,还是那句话,仿佛不写一些变态数据结构来不足以体现Linus 这帮子人是腕儿.具体<br />
来<br />
看,她_________来自include/scsi/scsi_device.h 中:<br />
38 struct scsi_device {<br />
39 struct <strong>Scsi</strong>_Host *host;<br />
40 struct request_queue *request_queue;<br />
41<br />
42 /* the next two are protected by the host->host_lock */<br />
43 struct list_head siblings; /* list <strong>of</strong> all devices on this host */<br />
44 struct list_head same_target_siblings; /* just the devices sharing same<br />
target id */<br />
45<br />
46 volatile unsigned short device_busy; /* commands actually active on<br />
low-level */<br />
47 spinlock_t sdev_lock; /* also the request queue_lock */<br />
48 spinlock_t list_lock;<br />
49 struct list_head cmd_list; /* queue <strong>of</strong> in use SCSI Command structures<br />
*/<br />
50 struct list_head starved_entry;<br />
51 struct scsi_cmnd *current_cmnd; /* currently active command */<br />
52 unsigned short queue_depth; /* How deep <strong>of</strong> a queue we want */<br />
125<br />
53 unsigned short last_queue_full_depth; /* These two are used by */<br />
54 unsigned short last_queue_full_count; /* scsi_track_queue_full() */<br />
55 unsigned long last_queue_full_time;/* don't let QUEUE_FULLs on the same