__create_pipe(dev,endpoint)) 1117 #define usb_rcvintpipe(dev,endpoint) ((PIPE_INTERRUPT
1079 #define PIPE_ISOCHRONOUS 0 1080 #define PIPE_INTERRUPT 1 1081 #define PIPE_CONTROL 2 1082 #define PIPE_BULK 3 咱们知道usb 有四种传输方式,等时传输,中断传输,控制传输,批量传输.一个设备能支持这四种传输中的 哪一种或者哪几种是设备本身的属性,在硬件设计的时候就确定了,比如一个纯粹的u 盘,她肯定是支持 Bulk 传输和Control 传输的.不同的传输要求有不同的端点,所以对于u 盘来说,她一定会有Bulk 端点和 Control 端点,于是就得使用相应的pipe 来跟不同的端点联系.在这里我们看到了四个宏,其 中,PIPE_ISOCHRONOUS 就是标志等时通道,PIPE_INTERRUPT 就是中断通道,PIPE_CONTROL 就 是 控制通道,PIPE_BULK 就是BULK 通道. 另外__create_pipe 也是一个宏,由上面她的定义可以看出她为构造一个宏提供了设备号和端点号.在内 核里使用一个unsigned int 类型的变量来表征一个pipe,其中8~14 位是设备号,即devnum,15~18 位 是端点号,即endpoint.而咱们还看到有这么一个宏,USB_DIR_IN,她是用来在pipe 里面标志数据传输方 向的,一个管道要么是只能输入要么是只能输出,鱼和熊掌不可兼得也.在include/linux/usb_ch9.h 中有 的: 24 25 /* 26 * USB directions 27 * 28 * This bit flag is used in endpoint descriptors' bEndpointAddress field. 29 * It's also one <strong>of</strong> three fields in control requests bRequestType. 30 */ 31 #define USB_DIR_OUT 0 /* to device */ 32 #define USB_DIR_IN 0x80 /* to host */ 在pipe 里面,第7 位(bit 7)是表征方向的.所以这里0x80 也就是说让bit 7 为1,这就表示传输方向是 由设备向主机的,也就是所谓的in,而如果这一位是0,就表示传输方向是由主机向设备的,也就是所谓的out. 而正是因为USB_DIR_OUT 是0,而USB_DIR_IN 是1,所以我们看到定义管道的时候只有用到了 USB_DIR_IN,而没有用到USB_DIR_OUT,因为她是0,任何数和0 相或都没有意义. 61 这样,咱们就知道了,get_pipes 函数里741,742 行就是为us 的控制输入和控制输出管道赋了值,管道是 单向的,但是有一个例外,那就是控制端点,控制端点是双向的,比如你36号楼201这个端点既可以是往外寄 东西,也可以是别人给你寄东西而作为收件人地址.而usb 规范规定了,每一个usb 设备至少得有一个控制 端点,其端点号为0.其它端点有没有得看具体设备而定,但这个端点是放之四海而皆准的,不管你是什么设 备,只要你是usb 这条道上的,那你就得遵守这么一个规矩,没得商量.所以我们看到741,742 行里传递的 endpoint 变量值为0.显然其构造的两个管道就是对应这个0 号控制端点的.而接下来几行,就是构造bulk 管道和中断管道(如果有中断端点的话). 对于bulk 端点和中断端点(如果有的话),在她们的端点描述符里有这么一个字段,bEndpointAddress, 这个字段共八位,但是她包含了挺多信息的,比如这个端点是输入端点还是输出端点,比如这个端点的地 址,(总线枚举的时候给她分配的),以及这个端点的端点号,不过要取得她的端点号得用一个掩码 USB_ENDPOINT_NUMBER_MASK,让bEndpointAddress 和USB_ENDPOINT_NUMBER_MASK相 与就能得到她的端点号.(就好比一份藏头诗,你得按着特定的方法才能读懂她,而这里特定的方法就是和 USB_ENDPOINT_NUMBER_MASK 这个掩码相与就行了.) 750 行,对于中断端点,您还得使用端点描述符中的bInterval 字段,表示端点的中断请求间隔时间.
- Page 1 and 2:
摘要 ............................
- Page 3 and 4:
迷雾重重的Bulk 传输(二)....
- Page 5 and 6:
引子 也许是在复旦养成了
- Page 7 and 8:
usb.h datafab.h dpcm.h initializers
- Page 9 and 10:
的Linux 内核划分为许许多
- Page 11 and 12: 目录下执行make 了.Ok,make 之
- Page 13 and 14: 只 是一个usb 接口.这些口
- Page 15 and 16: 中也定义了这么一些数据
- Page 17 and 18: 511 * @driver: the driver model cor
- Page 19 and 20: 233 .owner = THIS_MODULE, 234 .name
- Page 21 and 22: 91 * construct these entries. Each
- Page 23 and 24: 324 struct usb_host_config *actconf
- Page 25 and 26: 22 88 * @class_dev: driver model's
- Page 27 and 28: 必须给各个地方取名,完了
- Page 29 and 30: 26 136 trans_cmnd transport; /* tra
- Page 31 and 32: 944 init_MUTEX_LOCKED(&(us->sema));
- Page 33 and 34: 147 #if !defined(CONFIG_BLK_DEV_UB)
- Page 35 and 36: 124 #define USB_DEVICE_ID_MATCH_DEV
- Page 37 and 38: intf 来代替. us 之所以重要,
- Page 39 and 40: 睡眠,那就得用GPF_ATOMIC,这
- Page 41 and 42: 504 if (msg >= 0 && !(unusual_dev->
- Page 43 and 44: 179 } 180 181 static struct us_unus
- Page 45 and 46: 711 /* Submitted by Hartmut Wahl */
- Page 47 and 48: 3. useProtocol 为US_SC_DEVICE, use
- Page 49 and 50: Bus 004 Device 001: ID 0000:0000 Bu
- Page 51 and 52: 993 result = get_pipes(us); 994 if
- Page 53 and 54: 631 us->transport_reset = usb_stor_
- Page 55 and 56: 659 us->max_lun = 0; 660 break; 661
- Page 57 and 58: 740 /* Calculate and store the pipe
- Page 59 and 60: storage 会有两个bulk 端点,用
- Page 61: 比如说,复旦大学,有一个主
- Page 65 and 66: 782 us->unusual_dev->initFunction(u
- Page 67 and 68: 630 * each frame is in the fields o
- Page 69 and 70: 716 * Bulk URBs may 717 * use the U
- Page 71 and 72: 802 int number_of_packets; /* (in)
- Page 73 and 74: 先说互斥锁.它诞生于这样
- Page 75 and 76: 920 US_DEBUGP("GetMaxLUN command re
- Page 77 and 78: 148 /* set up data structures for t
- Page 79 and 80: 90 * @wValue: matches the USB wValu
- Page 81 and 82: 830 void *transfer_buffer, 831 int
- Page 83 and 84: 25 { 26 x->done = 0; 27 init_waitqu
- Page 85 and 86: 都会过期,我开始怀疑,在这
- Page 87 and 88: 是实际长度,要么就是不成
- Page 89 and 90: 87 258 行,usb_pipeendpoint,定义
- Page 91 and 92: 对爱你的人掘了一条无法
- Page 93 and 94: Type: Direct-Access ANSI SCSI revis
- Page 95 and 96: 416 /* 417 * this defines our host
- Page 97 and 98: 69 * Ioctl interface 70 * 71 * Stat
- Page 99 and 100: 155 * "is this a new device" checks
- Page 101 and 102: 241 char *proc_name; 242 243 /* 244
- Page 103 and 104: 328 * True if the low-level driver
- Page 105 and 106: 可以看到这个函数的参数
- Page 107 and 108: 451 short unsigned int max_sectors;
- Page 109 and 110: 地 说明了为啥咱们要显式
- Page 111 and 112: usb_stor_acquire_resources()函数
- Page 113 and 114:
341 } 342 343 /* reject if target !
- Page 115 and 116:
内核的核心位置,kernel/exit.c
- Page 117 and 118:
1023 dissociate_dev(us); 1024 retur
- Page 119 and 120:
917 行,再次判断设备有没有
- Page 121 and 122:
181 182 /* fail the command if we a
- Page 123 and 124:
83 struct timer_list eh_timeout; /*
- Page 125 and 126:
123 两个scsi_done,一个是struct
- Page 127 and 128:
56 jiffie count on our counter, the
- Page 129 and 130:
中 看到如下的定义: UNUSUAL_
- Page 131 and 132:
269 memcpy(data+16, us->unusual_dev
- Page 133 and 134:
一切准备好了之后,我们就
- Page 135 and 136:
238 (sg->offset + *offset) & (PAGE_
- Page 137 and 138:
所以对于那些不能相应INQUI
- Page 139 and 140:
239 行对unsigned int sglen 赋值
- Page 141 and 142:
请求,所以这里就判断abort
- Page 143 and 144:
112 case GPCMD_READ_HEADER: what =
- Page 145 and 146:
到北京,每每只有在夜深人
- Page 147 and 148:
580 /* 581 * If we have a failure,
- Page 149 and 150:
666 memcpy(srb->cmnd, old_cmnd, MAX
- Page 151 and 152:
950 struct bulk_cb_wrap *bcb = (str
- Page 153 and 154:
1034 /* get the status again */ 103
- Page 155 and 156:
426 /* store the actual length of t
- Page 157 and 158:
后她会给host 返回一个CSW.CB
- Page 159 and 160:
296 } 297 298 US_DEBUGP("-- transfe
- Page 161 and 162:
491 * scatter-gather or not, and ac
- Page 163 and 164:
迷雾重重的 Bulk 传输(五) us
- Page 165 and 166:
然后把她赋给了result.而us->
- Page 167 and 168:
而bcs->Status,标志命令执行
- Page 169 and 170:
就必须设置US_FL_IGNORE_RESIDUE
- Page 171 and 172:
485 }; 486 这是一个字符数组
- Page 173 and 174:
srb->sense_buffer 里边的东西.S
- Page 175 and 176:
一个类似的函数,名叫usb_sto
- Page 177 and 178:
这种命令应该由mid level 来
- Page 179 and 180:
Disk /dev/sda: 146.1 GB, 1461631057
- Page 181 and 182:
through to the most significant bit
- Page 183 and 184:
1192 USB_TYPE_CLASS | USB_RECIP_INT
- Page 185 and 186:
315 行,scsi_report_device_reset(),
- Page 187 and 188:
285 US_DEBUGP("No reset during disc
- Page 189 and 190:
229 /* Wait for the aborted command
- Page 191 and 192:
两个函数中需要判断它,一
- Page 193 and 194:
associate_dev()相对应.我们来
- Page 195 and 196:
束for 死循环,从而usb_stor_con
- Page 197 and 198:
317 for (i = 1; i < us->host->max_i