1 /*
2 *******************************************************************************
3 *                                              usb host module
4 *
5 *                             Copyright(C), 2006-2008, SoftWinners Co., Ltd.
6 *                                                  All Rights Reserved
7 *
8 * File Name :
9 *
10 * Author : GLHuang(HoLiGun)
11 *
12 * Version : 1.0
13 *
14 * Date : 2008.05.xx
15 *
16 * Description :
17 *
18 * History :
19 ********************************************************************************************************************
20 */
21 #ifndef __USB_HOST_COMMON_H__
22 #define __USB_HOST_COMMON_H__
23 
24 #include "usb_os_platform.h"
25 #include "ch9.h"
26 //#include "sunxi_drv_list.h"
27 #include <aw_list.h>
28 #include "usb_list.h"
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <log.h>
33 #include <hal_osal.h>
34 
35 /* This is arbitrary.
36  * From USB 2.0 spec Table 11-13, offset 7, a hub can
37  * have up to 255 ports. The most yet reported is 10.
38  */
39 #define USB_MAXCHILDREN     (31)
40 
41 #define USB_MAX_VIRT_SUB_DEV_NR     16      //一个物理设备支持的最大的子设备
42 //既复合设备的interface数目
43 
44 
45 /*
46  * timeouts, in milliseconds, used for sending/receiving control messages
47  * they typically complete within a few frames (msec) after they're issued
48  * USB identifies 5 second timeouts, maybe more in a few cases, and a few
49  * slow devices (like some MGE Ellipse UPSes) actually push that limit.
50  */
51 #define USB_CTRL_GET_TIMEOUT    5000
52 #define USB_CTRL_SET_TIMEOUT    5000
53 
54 
55 //usb_device_id
56 struct usb_drv_dev_match_table
57 {
58     /* which fields to match against? */
59     uint16_t     match_flags;
60 
61     /* Used for product specific matches; range is inclusive */
62     uint16_t     idVendor;
63     uint16_t     idProduct;
64     uint16_t     bcdDevice_lo;
65     uint16_t     bcdDevice_hi;
66 
67     /* Used for device class matches */
68     uint8_t      bDeviceClass;
69     uint8_t      bDeviceSubClass;
70     uint8_t      bDeviceProtocol;
71 
72     /* Used for interface class matches */
73     uint8_t      bInterfaceClass;
74     uint8_t      bInterfaceSubClass;
75     uint8_t      bInterfaceProtocol;
76 
77     /* not matched against */
78     uint32_t             driver_info;
79 };
80 
81 /* Some useful macros to use to create struct usb_device_id */
82 #define USB_DEVICE_ID_MATCH_VENDOR          0x0001
83 #define USB_DEVICE_ID_MATCH_PRODUCT         0x0002
84 #define USB_DEVICE_ID_MATCH_DEV_LO          0x0004
85 #define USB_DEVICE_ID_MATCH_DEV_HI          0x0008
86 #define USB_DEVICE_ID_MATCH_DEV_CLASS       0x0010
87 #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS    0x0020
88 #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL    0x0040
89 #define USB_DEVICE_ID_MATCH_INT_CLASS       0x0080
90 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS    0x0100
91 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL    0x0200
92 
93 #define USB_DEVICE_ID_MATCH_INT_INFO \
94     (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS | USB_DEVICE_ID_MATCH_INT_PROTOCOL)
95 #define USB_DEVICE_ID_MATCH_DEVICE \
96             (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
97 
98 
99 struct usb_host_virt_dev;
100 
101 /* 一个usb设备的ep的抽象,用来描述usb设备的一个ep的属性 */
102 struct usb_host_virt_endpoint
103 {
104     struct usb_endpoint_descriptor  desc;
105     // struct usb_list_head urb_list;
106     struct list_head urb_list;
107     void *hcpriv;   //具体hc的priv的ep结构,如ep_priv
108     unsigned char *extra;   /* Extra descriptors */
109     int extralen;
110 };
111 
112 /* USB device number allocation bitmap */
113 struct usb_devmap
114 {
115     uint32_t devicemap[128 / (8 * sizeof(unsigned long))];
116 };
117 
118 struct usb_host_func_drv;
119 
120 /* 总线 */
121 struct usb_virt_bus
122 {
123     struct usb_list_head  dev_list;     //设备list
124     struct usb_list_head  drv_list;     //驱动list
125 
126     struct hc_gen_dev *point_gen_hcd;   //指向hc_gen_dev
127 
128     int busnum;                     /* bus的编号,只要不冲突即可 */
129     const char *bus_name;           /* bus的名字,既"usb_bus" */
130     uint8_t otg_port;                    /* otg端口数目 */
131 
132     uint8_t is_b_host;               /* true during some HNP roleswitches  */
133     uint8_t b_hnp_enable;            /* OTG: did A-Host enable HNP */
134 
135     uint32_t devnum_next;            /* 下一个dev的地址 */
136 
137     struct usb_devmap devmap;   /* 地址占用bitmap */
138 
139     struct usb_host_virt_dev *root_hub; /* 总线上的root hub */
140 
141     void *hcpriv;               /* 其实是指向usb_hcd,hc_gen_dev */
142 
143     unsigned resuming_ports;    /* bit array: resuming root-hub ports */
144 
145     int32_t bandwidth_allocated;
146 
147     int32_t bandwidth_int_reqs;     /* number of Interrupt requests */
148     int32_t bandwidth_isoc_reqs;    /* number of Isoc. requests */
149 
150     int32_t(*bus_match)(struct usb_host_virt_dev *dev, struct usb_host_func_drv *drv);
151     int32_t(*bus_hotplug)(struct usb_host_virt_dev *dev, char *buffer, int buffer_size);
152     int32_t(*bus_suspend)(struct usb_host_virt_dev *dev);
153     int32_t(*bus_resume)(struct usb_host_virt_dev *dev);
154 
155     hal_sem_t BusLock;
156     // USB_OS_KERNEL_EVENT *BusLock;
157     //struct metux bus_metux;
158 };
159 
160 /* 是连接usb_host_virt_dev和usb_interface的桥梁
161  * 在usb_set_configuration()的时候被使用
162  *
163  * 可以看做是一个lun
164  */
165 struct usb_host_virt_sub_dev
166 {
167     struct usb_host_func_drv *func_drv;     //指向功能驱动
168     //USB_OS_KERNEL_EVENT    *usb_virt_sub_dev_semi;
169     hal_sem_t    usb_virt_sub_dev_semi;
170 
171     struct usb_host_virt_dev *father_dev;       //指向其father
172     struct usb_interface *sub_dev_interface;        //指向其下游,既interface
173 
174     void *drv_pirv_data;                        //存储临时数据
175 };
176 
177 /* 对应一个物理设备 */
178 struct usb_host_virt_dev
179 {
180     struct usb_host_virt_sub_dev virt_sub_dev_array[USB_MAX_VIRT_SUB_DEV_NR];
181 
182     //USB_OS_KERNEL_EVENT    *usb_virt_dev_semi;
183     hal_sem_t    usb_virt_dev_semi;
184 
185     int devnum;                     /* Address on USB bus */
186     enum usb_device_state   state;  /* 设备当前的state,configured, not attached */
187     enum usb_device_speed   speed;  /* 设备的当前速度 */
188     int     ttport;                 /* device port on that tt hub  */
189 
190     unsigned int toggle[2];         /* 该设备的各个ep的toggle */
191     /* one bit for each endpoint ([0] = IN, [1] = OUT) */
192 
193     struct usb_host_virt_dev *parent;   /* 设备连接的那个hub, root hub 除外 */
194     struct usb_virt_bus *bus;           /* 设备连接的那条总线 */
195     uint32_t  hub_port;                    /* 设备所在hun的port */
196 
197     struct usb_device_descriptor descriptor;    /* 设备描述符 */
198     struct usb_host_virt_config *config;        /* 设备配置 */
199     struct usb_host_virt_config *actconfig;     /* 被挑选用来配置的那个配置描述符 */
200 
201     struct usb_host_virt_endpoint ep0;
202     struct usb_host_virt_endpoint *ep_in[16];   /* 找到ep的快速通道 */
203     struct usb_host_virt_endpoint *ep_out[16];  /* 找到ep的快速通道 */
204 
205     u8 **rawdescriptors;    /* 存放各个物理config(包括下游的)入口, 既这是个索引数组 */
206     int have_langid;        /* whether string_langid is valid yet */
207     int string_langid;      /* language ID for strings  */
208     char *manufacturer;     /*  */
209     char *product;          /*  */
210     char *serial;           /*  */
211 
212     int maxchild;       /* 该hub的port数目  */
213     struct usb_host_virt_dev *children[USB_MAXCHILDREN];
214 };
215 
216 
217 struct usb_host_func_drv_ext
218 {
219     int32_t (*probe_ext)(struct usb_host_virt_sub_dev *dev);    //对usb_host_func_drv{}的probe的extend
220     //目前为_usb_core_func_drv_probe_interface()
221     int32_t (*disconnect_ext)(struct usb_host_virt_sub_dev *dev);   /* 指向真实的drv */
222 };
223 
224 #define USB_HOST_FUNC_DRV_PROBE_SUCCESS    0x11
225 #define USB_HOST_FUNC_DRV_PROBE_FAIL       0x22
226 
227 /* usb总线上的驱动,功能驱动 */
228 struct usb_host_func_drv
229 {
230     struct usb_list_head  virt_dev_list;  /* 与本驱动关联的virt_dev */
231     const char *func_drv_name;                  //驱动名
232     const char *func_drv_auther;      /* 作者   */
233 
234     int32_t(*probe)(struct usb_interface *intf, const struct usb_drv_dev_match_table *id);
235     void (*disconnect)(struct usb_interface *intf);     //在unmatch的时候调用
236     int(*ioctl)(struct usb_interface *intf, unsigned int code, void *buf);
237     int32_t(*suspend)(struct usb_interface *intf);
238     int(*resume)(struct usb_interface *intf);
239 
240     const struct usb_drv_dev_match_table *match_table;  //支持设备列表
241 
242     //===========================================================
243     //==下面部分是usb core会处理,func drv的编写者不用关心===
244     //===========================================================
245     struct usb_host_func_drv_ext  func_drv_ext;
246 };
247 
248 
249 
250 /*
251  * urb->transfer_flags:
252  */
253 #define URB_SHORT_NOT_OK    0x0001  /* report short reads as errors */
254 #define URB_ISO_ASAP        0x0002  /* iso-only, urb->start_frame ignored */
255 #define URB_NO_TRANSFER_DMA_MAP 0x0004  /* urb->transfer_dma valid on submit */
256 #define URB_NO_SETUP_DMA_MAP    0x0008  /* urb->setup_dma valid on submit */
257 #define URB_ASYNC_UNLINK    0x0010  /* usb_unlink_urb() returns asap */
258 #define URB_NO_FSBR     0x0020  /* UHCI-specific */
259 #define URB_ZERO_PACKET     0x0040  /* Finish bulk OUTs with short packet */
260 #define URB_NO_INTERRUPT    0x0080  /* HINT: no non-error interrupt needed */
261 
262 
263 struct usb_iso_packet_descriptor
264 {
265     unsigned int offset;
266     unsigned int length;        /* expected length */
267     unsigned int actual_length;
268     int status;
269 };
270 
271 typedef struct urb URB;
272 
273 typedef void (*usb_complete_t)(URB *my_urb);
274 
275 struct urb
276 {
277     hal_spinlock_t lock_urb;                     // lock for the URB
278     //USB_OS_KERNEL_SOFT_TIMER *wait_urb_timer;   //本urb的timerout timer
279     osal_timer_t wait_urb_timer;
280     void *hcpriv;                               //其实是指向hcd的私有数据
281     int32_t bandwidth;                              //bandwidth for INT/ISO request
282     uint32_t use_count;                              //concurrent submissions counter
283     uint8_t reject;                                  //submissions will fail
284     int unlinked;                               //unlink error code
285 
286     struct usb_host_virt_dev *dev;              //目标dev
287 
288     uint32_t pipe;                                   //目标dev上的pipe
289     int32_t status;                                 //(return) non-ISO status
290     uint32_t transfer_flags;                         // (in) URB_SHORT_NOT_OK | ...
291 
292     struct usb_host_virt_endpoint *ep;      /* (internal) pointer to endpoint */
293     void *transfer_buffer;                      //要发送的data 的buff
294 
295     unsigned long transfer_dma;                           //dma addr,不支持的时候为0
296     int32_t transfer_buffer_length;                 //要发送的长度
297     int32_t actual_length;                          //actual transfer length
298 
299     uint8_t *setup_packet;                           //setup packet (control only)
300     unsigned long setup_dma;                              //dma addr for setup_packet, 不支持的时候为0
301     int32_t start_frame;                            //start frame (ISO)
302     int32_t number_of_packets;                      //number of ISO packets */
303     int32_t interval;                               //transfer interval (INT/ISO)
304     int32_t error_count;                            //number of ISO errors
305     void *context;                              //context for completion, 一般为USB_OS_KERNEL_EVENT
306     usb_complete_t complete;                    //completion routine
307 
308     //struct usb_iso_packet_descriptor iso_frame_desc[0];   //ISO ONLY
309     // struct usb_list_head *wrapper_urb;              //指向本结构的wrapper,
310     struct list_head urb_list;              //指向本结构的wrapper,
311 
312     uint32_t urb_sn;                                 //urb sn ,just for debug
313 
314     uint32_t is_busy;                                /* flag. urb是否正在被hcd处理, urb dequeue时有用 */
315     uint32_t need_dispose;                           /* flag. urb是否需要被hcd处理, urb dequeue时有用 */
316     struct usb_iso_packet_descriptor iso_frame_desc[0];
317 };
318 
319 /**
320  * usb_fill_control_urb - initializes a control urb
321  * @urb: pointer to the urb to initialize.
322  * @dev: pointer to the struct usb_device for this urb.
323  * @pipe: the endpoint pipe
324  * @setup_packet: pointer to the setup_packet buffer
325  * @transfer_buffer: pointer to the transfer buffer
326  * @buffer_length: length of the transfer buffer
327  * @complete: pointer to the usb_complete_t function
328  * @context: what to set the urb context to.
329  *
330  * Initializes a control urb with the proper information needed to submit
331  * it to a device.
332  */
usb_fill_control_urb(struct urb * urb,struct usb_host_virt_dev * dev,unsigned int pipe,unsigned char * setup_packet,void * transfer_buffer,int buffer_length,usb_complete_t complete,void * context)333 static inline void usb_fill_control_urb(struct urb *urb,
334                                         struct usb_host_virt_dev *dev,
335                                         unsigned int pipe,
336                                         unsigned char *setup_packet,
337                                         void *transfer_buffer,
338                                         int buffer_length,
339                                         usb_complete_t complete,
340                                         void *context)
341 {
342     urb->lock_urb               = 0;
343     urb->dev                    = dev;
344     urb->pipe                   = pipe;
345     urb->setup_packet           = setup_packet;
346     urb->transfer_buffer        = transfer_buffer;
347     urb->transfer_buffer_length = buffer_length;
348     urb->complete               = complete;
349     urb->context                = context;
350 }
351 
352 /**
353  * usb_fill_bulk_urb - macro to help initialize a bulk urb
354  * @urb: pointer to the urb to initialize.
355  * @dev: pointer to the struct usb_device for this urb.
356  * @pipe: the endpoint pipe
357  * @transfer_buffer: pointer to the transfer buffer
358  * @buffer_length: length of the transfer buffer
359  * @complete: pointer to the usb_complete_t function
360  * @context: what to set the urb context to.
361  *
362  * Initializes a bulk urb with the proper information needed to submit it
363  * to a device.
364  */
usb_fill_bulk_urb(struct urb * urb,struct usb_host_virt_dev * dev,unsigned int pipe,void * transfer_buffer,int buffer_length,usb_complete_t complete,void * context)365 static void usb_fill_bulk_urb(struct urb *urb,
366                               struct usb_host_virt_dev *dev,
367                               unsigned int pipe,
368                               void *transfer_buffer,
369                               int buffer_length,
370                               usb_complete_t complete,
371                               void *context)
372 {
373     uint32_t cpu_sr = 0;
374     //USB_OS_ENTER_CRITICAL(cpu_sr);
375     urb->lock_urb               = 0;
376     urb->dev                    = dev;
377     urb->pipe                   = pipe;
378     urb->transfer_buffer        = transfer_buffer;
379     urb->transfer_buffer_length = buffer_length;
380     urb->complete               = complete;
381     urb->context                = context;
382     //USB_OS_EXIT_CRITICAL(cpu_sr);
383 }
384 
385 /**
386  * usb_fill_int_urb - macro to help initialize a interrupt urb
387  * @urb: pointer to the urb to initialize.
388  * @dev: pointer to the struct usb_device for this urb.
389  * @pipe: the endpoint pipe
390  * @transfer_buffer: pointer to the transfer buffer
391  * @buffer_length: length of the transfer buffer
392  * @complete: pointer to the usb_complete_t function
393  * @context: what to set the urb context to.
394  * @interval: what to set the urb interval to, encoded like
395  *  the endpoint descriptor's bInterval value.
396  *
397  * Initializes a interrupt urb with the proper information needed to submit
398  * it to a device.
399  * Note that high speed interrupt endpoints use a logarithmic encoding of
400  * the endpoint interval, and express polling intervals in microframes
401  * (eight per millisecond) rather than in frames (one per millisecond).
402  */
usb_fill_int_urb(struct urb * urb,struct usb_host_virt_dev * dev,unsigned int pipe,void * transfer_buffer,int buffer_length,usb_complete_t complete,void * context,int interval)403 static inline void usb_fill_int_urb(struct urb *urb,
404                                     struct usb_host_virt_dev *dev,
405                                     unsigned int pipe,
406                                     void *transfer_buffer,
407                                     int buffer_length,
408                                     usb_complete_t complete,
409                                     void *context,
410                                     int interval)
411 {
412     urb->lock_urb               = 0;
413     urb->dev                    = dev;
414     urb->pipe                   = pipe;
415     urb->transfer_buffer        = transfer_buffer;
416     urb->transfer_buffer_length = buffer_length;
417     urb->complete               = complete;
418     urb->context                = context;
419 
420     if (dev->speed == USB_SPEED_HIGH)
421     {
422         urb->interval = 1 << (interval - 1);
423     }
424     else
425     {
426         urb->interval = interval;
427     }
428 
429     urb->start_frame = -1;
430 }
431 
432 
433 /* this maximum is arbitrary */
434 //#define USB_MAXINTERFACES 32
435 #define USB_MAXINTERFACES   16
436 
437 /* host端的config */
438 struct usb_host_virt_config
439 {
440     struct usb_config_descriptor desc;      //物理config desc 自身,不包括下游
441 
442     char *string;
443 
444     /* the interfaces associated with this configuration,
445      * stored in no particular order */
446     struct usb_interface *interfac[USB_MAXINTERFACES];  //是后期set config时候创建与物理desc无关
447 
448     /* Interface information available even when this is not the
449      * active configuration */
450     struct usb_interface_cache *intf_cache[USB_MAXINTERFACES];  //指向各个interface
451     unsigned char *extra;
452     int extralen;
453 };
454 
455 
456 
457 /* host-side wrapper for one interface setting's parsed descriptors */
458 struct usb_host_virt_interface
459 {
460     struct usb_interface_descriptor desc;
461 
462     /* array of desc.bNumEndpoint endpoints associated with this
463      * interface setting.  these will be in no particular order.
464      */
465     struct usb_host_virt_endpoint *endpoint;    //有desc.bNumEndpoint个
466 
467     char *string;               /* iInterface string, if present */
468     unsigned char *extra;       /* Extra descriptors */
469     int extralen;
470 };
471 
472 
473 enum usb_interface_condition
474 {
475     USB_INTERFACE_UNBOUND = 0,
476     USB_INTERFACE_BINDING,
477     USB_INTERFACE_BOUND,
478     USB_INTERFACE_UNBINDING
479 };
480 
481 /* 主机端interface,一个interface对应一个逻辑device */
482 struct usb_interface
483 {
484     struct usb_host_virt_sub_dev *virt_sub_dev;     //指向virt_sub_dev
485 
486     /* array of alternate settings for this interface,
487      * stored in no particular order */
488     struct usb_host_virt_interface *altsetting;     //指向usb_interface_cache->
489     struct usb_host_virt_interface *cur_altsetting; // the currently active alternate setting
490     uint32_t num_altsetting; /* number of alternate settings */
491     int32_t minor;              /* minor number this interface is bound to */
492     enum usb_interface_condition condition;     /* state of binding */
493 
494 };
495 
496 
497 
498 
499 /**
500  * struct usb_interface_cache - long-term representation of a device interface
501  * @num_altsetting: number of altsettings defined.
502  * @ref: reference counter.
503  * @altsetting: variable-length array of interface structures, one for
504  *  each alternate setting that may be selected.  Each one includes a
505  *  set of endpoint configurations.  They will be in no particular order.
506  *
507  * These structures persist for the lifetime of a usb_device, unlike
508  * struct usb_interface (which persists only as long as its configuration
509  * is installed).  The altsetting arrays can be accessed through these
510  * structures at any time, permitting comparison of configurations and
511  * providing support for the /proc/bus/usb/devices pseudo-file.
512  */
513 //用来描述一个interface,包括其下的AlternateSetting
514 struct usb_interface_cache
515 {
516     uint8_t num_altsetting;  //number of alternate settings
517     struct usb_host_virt_interface *altsetting_array;   //指向usb_host_virt_interface[],其有效长度为
518 };
519 
520 /* -------------------------------------------------------------------------- */
521 
522 /*
523  * For various legacy reasons, Linux has a small cookie that's paired with
524  * a struct usb_device to identify an endpoint queue.  Queue characteristics
525  * are defined by the endpoint's descriptor.  This cookie is called a "pipe",
526  * an unsigned int encoded as:
527  *
528  *  - direction:    bit 7       (0 = Host-to-Device [Out],
529  *                   1 = Device-to-Host [In] ...
530  *                  like endpoint bEndpointAddress)
531  *  - device address:   bits 8-14       ... bit positions known to uhci-hcd
532  *  - endpoint:     bits 15-18      ... bit positions known to uhci-hcd
533  *  - pipe type:    bits 30-31  (00 = isochronous, 01 = interrupt,
534  *                   10 = control, 11 = bulk)
535  *
536  * Given the device address and endpoint descriptor, pipes are redundant.
537  */
538 
539 /* NOTE:  these are not the standard USB_ENDPOINT_XFER_* values!! */
540 /* (yet ... they're the values used by usbfs) */
541 #define PIPE_ISOCHRONOUS        0u
542 #define PIPE_INTERRUPT          1u
543 #define PIPE_CONTROL            2u
544 #define PIPE_BULK               3u
545 
546 #define usb_pipein(pipe)        ((pipe) & USB_DIR_IN)
547 #define usb_pipeout(pipe)       (!usb_pipein(pipe))
548 
549 #define usb_pipedevice(pipe)    (((pipe) >> 8) & 0x7f)
550 #define usb_pipeendpoint(pipe)  (((pipe) >> 15) & 0xf)
551 
552 #define usb_pipetype(pipe)      (((pipe) >> 30) & 3)
553 
554 #define usb_pipeisoc(pipe)      (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
555 #define usb_pipeint(pipe)       (usb_pipetype((pipe)) == PIPE_INTERRUPT)
556 #define usb_pipecontrol(pipe)   (usb_pipetype((pipe)) == PIPE_CONTROL)
557 #define usb_pipebulk(pipe)      (usb_pipetype((pipe)) == PIPE_BULK)
558 
559 /* The D0/D1 toggle bits ... USE WITH CAUTION (they're almost hcd-internal) */
560 #define usb_gettoggle(dev, ep, out)         (((dev)->toggle[out] >> (ep)) & 1)
561 #define usb_dotoggle(dev, ep, out)          ((dev)->toggle[out] ^= (1 << (ep)))
562 #define usb_settoggle(dev, ep, out, bit)    ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << (ep))) | ((bit) << (ep)))
563 
564 
__create_pipe(struct usb_host_virt_dev * dev,unsigned int endpoint)565 static inline unsigned int __create_pipe(struct usb_host_virt_dev *dev, unsigned int endpoint)
566 {
567     return (dev->devnum << 8) | (endpoint << 15);
568 }
569 
570 /* Create various pipes... */
571 #define usb_sndctrlpipe(dev,endpoint)   ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))
572 #define usb_rcvctrlpipe(dev,endpoint)   ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
573 #define usb_sndisocpipe(dev,endpoint)   ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))
574 #define usb_rcvisocpipe(dev,endpoint)   ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
575 #define usb_sndbulkpipe(dev,endpoint)   ((PIPE_BULK << 30) | __create_pipe(dev,endpoint))
576 #define usb_rcvbulkpipe(dev,endpoint)   ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
577 #define usb_sndintpipe(dev,endpoint)    ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint))
578 #define usb_rcvintpipe(dev,endpoint)    ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
579 
580 
581 
usb_maxpacket(struct usb_host_virt_dev * udev,int pipe,int is_out)582 static uint16_t usb_maxpacket(struct usb_host_virt_dev *udev, int pipe, int is_out)
583 {
584     struct usb_host_virt_endpoint   *ep;
585     unsigned            epnum = usb_pipeendpoint(pipe);
586 
587     if (is_out)
588     {
589         ep = udev->ep_out[epnum];
590     }
591     else
592     {
593         ep = udev->ep_in[epnum];
594     }
595 
596     if (!ep)
597     {
598         __err("PANIC : usb_maxpacket() not found ep\n");
599         return 0;
600     }
601 
602     /* NOTE:  only 0x07ff bits are for packet size... */
603     return le16_to_cpu(ep->desc.wMaxPacketSize);
604 }
605 
606 
607 #endif
608 
609 
610 
611 
612