4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include <linux/list.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <linux/slab.h>
22 #include <linux/usb.h>
23 #include <linux/usb/hcd.h>
27 *** HARDWARE LIMITATION ***
29 * 1) renesas_usbhs has a limited number of controllable devices.
30 * it can control only 9 devices in generally.
31 * see DEVADDn / DCPMAXP / PIPEMAXP.
33 * 2) renesas_usbhs pipe number is limited.
34 * the pipe will be re-used for each devices.
35 * so, software should control DATA0/1 sequence of each devices.
43 * | udev 0 | --> it is used when set address
46 * +--------+ pipes are reused for each uep.
47 * | udev 1 |-+- [uep 0 (dcp) ] --+ pipe will be switched when
48 * +--------+ | | other device requested
49 * +- [uep 1 (bulk)] --|---+ +--------------+
50 * | +--------------> | pipe0 (dcp) |
51 * +- [uep 2 (bulk)] -@ | +--------------+
53 * +--------+ | +--------------+
54 * | udev 2 |-+- [uep 0 (dcp) ] -@ +----------> | pipe2 (bulk) |
55 * +--------+ | +--------------+
56 * +- [uep 1 (int) ] ----+ +------> | pipe3 (bulk) |
57 * | | +--------------+
58 * +--------+ +-----|------> | pipe4 (int) |
59 * | udev 3 |-+- [uep 0 (dcp) ] -@ | +--------------+
60 * +--------+ | | | .... |
61 * +- [uep 1 (bulk)] -@ | | .... |
63 * +- [uep 2 (bulk)]-----------+
65 * @ : uep requested free pipe, but all have been used.
66 * now it is waiting for free pipe
73 struct usbhsh_request
{
78 struct usbhsh_device
{
79 struct usb_device
*usbv
;
80 struct list_head ep_list_head
; /* list of usbhsh_ep */
84 struct usbhs_pipe
*pipe
; /* attached pipe */
85 struct usbhsh_device
*udev
; /* attached udev */
86 struct usb_host_endpoint
*ep
;
87 struct list_head ep_list
; /* list to usbhsh_device */
88 unsigned int counter
; /* pipe attach counter */
91 #define USBHSH_DEVICE_MAX 10 /* see DEVADDn / DCPMAXP / PIPEMAXP */
92 #define USBHSH_PORT_MAX 7 /* see DEVADDn :: HUBPORT */
95 struct usbhs_pipe
*dcp
;
97 struct usbhsh_device udev
[USBHSH_DEVICE_MAX
];
99 u32 port_stat
; /* USB_PORT_STAT_xxx */
101 struct completion setup_ack_done
;
105 static const char usbhsh_hcd_name
[] = "renesas_usbhs host";
110 #define usbhsh_priv_to_hpriv(priv) \
111 container_of(usbhs_mod_get(priv, USBHS_HOST), struct usbhsh_hpriv, mod)
113 #define __usbhsh_for_each_udev(start, pos, h, i) \
115 ((i) < USBHSH_DEVICE_MAX) && ((pos) = (h)->udev + (i)); \
118 #define usbhsh_for_each_udev(pos, hpriv, i) \
119 __usbhsh_for_each_udev(1, pos, hpriv, i)
121 #define usbhsh_for_each_udev_with_dev0(pos, hpriv, i) \
122 __usbhsh_for_each_udev(0, pos, hpriv, i)
124 #define usbhsh_hcd_to_hpriv(h) (struct usbhsh_hpriv *)((h)->hcd_priv)
125 #define usbhsh_hcd_to_dev(h) ((h)->self.controller)
127 #define usbhsh_hpriv_to_priv(h) ((h)->mod.priv)
128 #define usbhsh_hpriv_to_dcp(h) ((h)->dcp)
129 #define usbhsh_hpriv_to_hcd(h) \
130 container_of((void *)h, struct usb_hcd, hcd_priv)
132 #define usbhsh_ep_to_uep(u) ((u)->hcpriv)
133 #define usbhsh_uep_to_pipe(u) ((u)->pipe)
134 #define usbhsh_uep_to_udev(u) ((u)->udev)
135 #define usbhsh_uep_to_ep(u) ((u)->ep)
137 #define usbhsh_urb_to_ureq(u) ((u)->hcpriv)
138 #define usbhsh_urb_to_usbv(u) ((u)->dev)
140 #define usbhsh_usbv_to_udev(d) dev_get_drvdata(&(d)->dev)
142 #define usbhsh_udev_to_usbv(h) ((h)->usbv)
143 #define usbhsh_udev_is_used(h) usbhsh_udev_to_usbv(h)
145 #define usbhsh_pipe_to_uep(p) ((p)->mod_private)
147 #define usbhsh_device_parent(d) (usbhsh_usbv_to_udev((d)->usbv->parent))
148 #define usbhsh_device_hubport(d) ((d)->usbv->portnum)
149 #define usbhsh_device_number(h, d) ((int)((d) - (h)->udev))
150 #define usbhsh_device_nth(h, d) ((h)->udev + d)
151 #define usbhsh_device0(h) usbhsh_device_nth(h, 0)
153 #define usbhsh_port_stat_init(h) ((h)->port_stat = 0)
154 #define usbhsh_port_stat_set(h, s) ((h)->port_stat |= (s))
155 #define usbhsh_port_stat_clear(h, s) ((h)->port_stat &= ~(s))
156 #define usbhsh_port_stat_get(h) ((h)->port_stat)
158 #define usbhsh_pkt_to_ureq(p) \
159 container_of((void *)p, struct usbhsh_request, pkt)
164 static struct usbhsh_request
*usbhsh_ureq_alloc(struct usbhsh_hpriv
*hpriv
,
168 struct usbhsh_request
*ureq
;
169 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
170 struct device
*dev
= usbhs_priv_to_dev(priv
);
172 ureq
= kzalloc(sizeof(struct usbhsh_request
), mem_flags
);
174 dev_err(dev
, "ureq alloc fail\n");
178 usbhs_pkt_init(&ureq
->pkt
);
180 usbhsh_urb_to_ureq(urb
) = ureq
;
185 static void usbhsh_ureq_free(struct usbhsh_hpriv
*hpriv
,
186 struct usbhsh_request
*ureq
)
188 usbhsh_urb_to_ureq(ureq
->urb
) = NULL
;
197 static int usbhsh_is_running(struct usbhsh_hpriv
*hpriv
)
200 * we can decide some device is attached or not
201 * by checking mod.irq_attch
206 return (hpriv
->mod
.irq_attch
== NULL
);
212 static void usbhsh_endpoint_sequence_save(struct usbhsh_hpriv
*hpriv
,
214 struct usbhs_pkt
*pkt
)
216 int len
= urb
->actual_length
;
217 int maxp
= usb_endpoint_maxp(&urb
->ep
->desc
);
220 /* DCP is out of sequence control */
221 if (usb_pipecontrol(urb
->pipe
))
225 * renesas_usbhs pipe has a limitation in a number.
226 * So, driver should re-use the limited pipe for each device/endpoint.
227 * DATA0/1 sequence should be saved for it.
228 * see [image of mod_host]
229 * [HARDWARE LIMITATION]
233 * next sequence depends on actual_length
235 * ex) actual_length = 1147, maxp = 512
239 * data1 is the next sequence
249 usb_dotoggle(urb
->dev
,
250 usb_pipeendpoint(urb
->pipe
),
251 usb_pipeout(urb
->pipe
));
254 static struct usbhsh_device
*usbhsh_device_get(struct usbhsh_hpriv
*hpriv
,
257 static int usbhsh_pipe_attach(struct usbhsh_hpriv
*hpriv
,
260 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
261 struct usbhsh_ep
*uep
= usbhsh_ep_to_uep(urb
->ep
);
262 struct usbhsh_device
*udev
= usbhsh_device_get(hpriv
, urb
);
263 struct usbhs_pipe
*pipe
;
264 struct usb_endpoint_descriptor
*desc
= &urb
->ep
->desc
;
265 struct device
*dev
= usbhs_priv_to_dev(priv
);
267 int dir_in_req
= !!usb_pipein(urb
->pipe
);
268 int is_dcp
= usb_endpoint_xfer_control(desc
);
272 /******************** spin lock ********************/
273 usbhs_lock(priv
, flags
);
276 * if uep has been attached to pipe,
279 if (usbhsh_uep_to_pipe(uep
)) {
281 goto usbhsh_pipe_attach_done
;
284 usbhs_for_each_pipe_with_dcp(pipe
, priv
, i
) {
286 /* check pipe type */
287 if (!usbhs_pipe_type_is(pipe
, usb_endpoint_type(desc
)))
290 /* check pipe direction if normal pipe */
292 dir_in
= !!usbhs_pipe_is_dir_in(pipe
);
293 if (0 != (dir_in
- dir_in_req
))
297 /* check pipe is free */
298 if (usbhsh_pipe_to_uep(pipe
))
304 * usbhs_pipe_config_update() should be called after
305 * usbhs_set_device_config()
309 usbhsh_uep_to_pipe(uep
) = pipe
;
310 usbhsh_pipe_to_uep(pipe
) = uep
;
312 usbhs_pipe_config_update(pipe
,
313 usbhsh_device_number(hpriv
, udev
),
314 usb_endpoint_num(desc
),
315 usb_endpoint_maxp(desc
));
317 dev_dbg(dev
, "%s [%d-%d(%s:%s)]\n", __func__
,
318 usbhsh_device_number(hpriv
, udev
),
319 usb_endpoint_num(desc
),
320 usbhs_pipe_name(pipe
),
321 dir_in_req
? "in" : "out");
327 usbhsh_pipe_attach_done
:
331 usbhs_unlock(priv
, flags
);
332 /******************** spin unlock ******************/
337 static void usbhsh_pipe_detach(struct usbhsh_hpriv
*hpriv
,
338 struct usbhsh_ep
*uep
)
340 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
341 struct usbhs_pipe
*pipe
;
342 struct device
*dev
= usbhs_priv_to_dev(priv
);
345 if (unlikely(!uep
)) {
346 dev_err(dev
, "no uep\n");
350 /******************** spin lock ********************/
351 usbhs_lock(priv
, flags
);
353 pipe
= usbhsh_uep_to_pipe(uep
);
355 if (unlikely(!pipe
)) {
356 dev_err(dev
, "uep doens't have pipe\n");
357 } else if (1 == uep
->counter
--) { /* last user */
358 struct usb_host_endpoint
*ep
= usbhsh_uep_to_ep(uep
);
359 struct usbhsh_device
*udev
= usbhsh_uep_to_udev(uep
);
361 /* detach pipe from uep */
362 usbhsh_uep_to_pipe(uep
) = NULL
;
363 usbhsh_pipe_to_uep(pipe
) = NULL
;
365 dev_dbg(dev
, "%s [%d-%d(%s)]\n", __func__
,
366 usbhsh_device_number(hpriv
, udev
),
367 usb_endpoint_num(&ep
->desc
),
368 usbhs_pipe_name(pipe
));
371 usbhs_unlock(priv
, flags
);
372 /******************** spin unlock ******************/
378 static int usbhsh_endpoint_attach(struct usbhsh_hpriv
*hpriv
,
382 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
383 struct usbhsh_device
*udev
= usbhsh_device_get(hpriv
, urb
);
384 struct usb_host_endpoint
*ep
= urb
->ep
;
385 struct usbhsh_ep
*uep
;
386 struct device
*dev
= usbhs_priv_to_dev(priv
);
387 struct usb_endpoint_descriptor
*desc
= &ep
->desc
;
390 uep
= kzalloc(sizeof(struct usbhsh_ep
), mem_flags
);
392 dev_err(dev
, "usbhsh_ep alloc fail\n");
396 /******************** spin lock ********************/
397 usbhs_lock(priv
, flags
);
403 INIT_LIST_HEAD(&uep
->ep_list
);
404 list_add_tail(&uep
->ep_list
, &udev
->ep_list_head
);
406 usbhsh_uep_to_udev(uep
) = udev
;
407 usbhsh_uep_to_ep(uep
) = ep
;
408 usbhsh_ep_to_uep(ep
) = uep
;
410 usbhs_unlock(priv
, flags
);
411 /******************** spin unlock ******************/
413 dev_dbg(dev
, "%s [%d-%d]\n", __func__
,
414 usbhsh_device_number(hpriv
, udev
),
415 usb_endpoint_num(desc
));
420 static void usbhsh_endpoint_detach(struct usbhsh_hpriv
*hpriv
,
421 struct usb_host_endpoint
*ep
)
423 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
424 struct device
*dev
= usbhs_priv_to_dev(priv
);
425 struct usbhsh_ep
*uep
= usbhsh_ep_to_uep(ep
);
431 dev_dbg(dev
, "%s [%d-%d]\n", __func__
,
432 usbhsh_device_number(hpriv
, usbhsh_uep_to_udev(uep
)),
433 usb_endpoint_num(&ep
->desc
));
435 if (usbhsh_uep_to_pipe(uep
))
436 usbhsh_pipe_detach(hpriv
, uep
);
438 /******************** spin lock ********************/
439 usbhs_lock(priv
, flags
);
441 /* remove this endpoint from udev */
442 list_del_init(&uep
->ep_list
);
444 usbhsh_uep_to_udev(uep
) = NULL
;
445 usbhsh_uep_to_ep(uep
) = NULL
;
446 usbhsh_ep_to_uep(ep
) = NULL
;
448 usbhs_unlock(priv
, flags
);
449 /******************** spin unlock ******************/
454 static void usbhsh_endpoint_detach_all(struct usbhsh_hpriv
*hpriv
,
455 struct usbhsh_device
*udev
)
457 struct usbhsh_ep
*uep
, *next
;
459 list_for_each_entry_safe(uep
, next
, &udev
->ep_list_head
, ep_list
)
460 usbhsh_endpoint_detach(hpriv
, usbhsh_uep_to_ep(uep
));
466 static int usbhsh_connected_to_rhdev(struct usb_hcd
*hcd
,
467 struct usbhsh_device
*udev
)
469 struct usb_device
*usbv
= usbhsh_udev_to_usbv(udev
);
471 return hcd
->self
.root_hub
== usbv
->parent
;
474 static int usbhsh_device_has_endpoint(struct usbhsh_device
*udev
)
476 return !list_empty(&udev
->ep_list_head
);
479 static struct usbhsh_device
*usbhsh_device_get(struct usbhsh_hpriv
*hpriv
,
482 struct usb_device
*usbv
= usbhsh_urb_to_usbv(urb
);
483 struct usbhsh_device
*udev
= usbhsh_usbv_to_udev(usbv
);
485 /* usbhsh_device_attach() is still not called */
489 /* if it is device0, return it */
490 if (0 == usb_pipedevice(urb
->pipe
))
491 return usbhsh_device0(hpriv
);
493 /* return attached device */
497 static struct usbhsh_device
*usbhsh_device_attach(struct usbhsh_hpriv
*hpriv
,
500 struct usbhsh_device
*udev
= NULL
;
501 struct usbhsh_device
*udev0
= usbhsh_device0(hpriv
);
502 struct usbhsh_device
*pos
;
503 struct usb_hcd
*hcd
= usbhsh_hpriv_to_hcd(hpriv
);
504 struct device
*dev
= usbhsh_hcd_to_dev(hcd
);
505 struct usb_device
*usbv
= usbhsh_urb_to_usbv(urb
);
506 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
512 * This function should be called only while urb is pointing to device0.
513 * It will attach unused usbhsh_device to urb (usbv),
514 * and initialize device0.
515 * You can use usbhsh_device_get() to get "current" udev,
516 * and usbhsh_usbv_to_udev() is for "attached" udev.
518 if (0 != usb_pipedevice(urb
->pipe
)) {
519 dev_err(dev
, "%s fail: urb isn't pointing device0\n", __func__
);
523 /******************** spin lock ********************/
524 usbhs_lock(priv
, flags
);
529 usbhsh_for_each_udev(pos
, hpriv
, i
) {
530 if (usbhsh_udev_is_used(pos
))
538 * usbhsh_usbv_to_udev()
539 * usbhsh_udev_to_usbv()
542 dev_set_drvdata(&usbv
->dev
, udev
);
546 usbhs_unlock(priv
, flags
);
547 /******************** spin unlock ******************/
550 dev_err(dev
, "no free usbhsh_device\n");
554 if (usbhsh_device_has_endpoint(udev
)) {
555 dev_warn(dev
, "udev have old endpoint\n");
556 usbhsh_endpoint_detach_all(hpriv
, udev
);
559 if (usbhsh_device_has_endpoint(udev0
)) {
560 dev_warn(dev
, "udev0 have old endpoint\n");
561 usbhsh_endpoint_detach_all(hpriv
, udev0
);
564 /* uep will be attached */
565 INIT_LIST_HEAD(&udev0
->ep_list_head
);
566 INIT_LIST_HEAD(&udev
->ep_list_head
);
571 usbhs_set_device_config(priv
,
572 0, 0, 0, usbv
->speed
);
575 * set new device config
579 if (!usbhsh_connected_to_rhdev(hcd
, udev
)) {
580 /* if udev is not connected to rhdev, it means parent is Hub */
581 struct usbhsh_device
*parent
= usbhsh_device_parent(udev
);
583 upphub
= usbhsh_device_number(hpriv
, parent
);
584 hubport
= usbhsh_device_hubport(udev
);
586 dev_dbg(dev
, "%s connecte to Hub [%d:%d](%p)\n", __func__
,
587 upphub
, hubport
, parent
);
590 usbhs_set_device_config(priv
,
591 usbhsh_device_number(hpriv
, udev
),
592 upphub
, hubport
, usbv
->speed
);
594 dev_dbg(dev
, "%s [%d](%p)\n", __func__
,
595 usbhsh_device_number(hpriv
, udev
), udev
);
600 static void usbhsh_device_detach(struct usbhsh_hpriv
*hpriv
,
601 struct usbhsh_device
*udev
)
603 struct usb_hcd
*hcd
= usbhsh_hpriv_to_hcd(hpriv
);
604 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
605 struct device
*dev
= usbhsh_hcd_to_dev(hcd
);
606 struct usb_device
*usbv
= usbhsh_udev_to_usbv(udev
);
609 dev_dbg(dev
, "%s [%d](%p)\n", __func__
,
610 usbhsh_device_number(hpriv
, udev
), udev
);
612 if (usbhsh_device_has_endpoint(udev
)) {
613 dev_warn(dev
, "udev still have endpoint\n");
614 usbhsh_endpoint_detach_all(hpriv
, udev
);
618 * There is nothing to do if it is device0.
620 * usbhsh_device_attach()
621 * usbhsh_device_get()
623 if (0 == usbhsh_device_number(hpriv
, udev
))
626 /******************** spin lock ********************/
627 usbhs_lock(priv
, flags
);
630 * usbhsh_usbv_to_udev()
631 * usbhsh_udev_to_usbv()
634 dev_set_drvdata(&usbv
->dev
, NULL
);
637 usbhs_unlock(priv
, flags
);
638 /******************** spin unlock ******************/
644 static void usbhsh_queue_done(struct usbhs_priv
*priv
, struct usbhs_pkt
*pkt
)
646 struct usbhsh_request
*ureq
= usbhsh_pkt_to_ureq(pkt
);
647 struct usbhsh_hpriv
*hpriv
= usbhsh_priv_to_hpriv(priv
);
648 struct usb_hcd
*hcd
= usbhsh_hpriv_to_hcd(hpriv
);
649 struct urb
*urb
= ureq
->urb
;
650 struct device
*dev
= usbhs_priv_to_dev(priv
);
653 dev_dbg(dev
, "%s\n", __func__
);
656 dev_warn(dev
, "pkt doesn't have urb\n");
660 if (!usbhsh_is_running(hpriv
))
663 urb
->actual_length
= pkt
->actual
;
665 usbhsh_endpoint_sequence_save(hpriv
, urb
, pkt
);
666 usbhsh_ureq_free(hpriv
, ureq
);
668 usbhsh_pipe_detach(hpriv
, usbhsh_ep_to_uep(urb
->ep
));
670 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
671 usb_hcd_giveback_urb(hcd
, urb
, status
);
674 static int usbhsh_queue_push(struct usb_hcd
*hcd
,
678 struct usbhsh_hpriv
*hpriv
= usbhsh_hcd_to_hpriv(hcd
);
679 struct usbhsh_ep
*uep
= usbhsh_ep_to_uep(urb
->ep
);
680 struct usbhs_pipe
*pipe
= usbhsh_uep_to_pipe(uep
);
681 struct device
*dev
= usbhsh_hcd_to_dev(hcd
);
682 struct usbhsh_request
*ureq
;
686 if (usb_pipeisoc(urb
->pipe
)) {
687 dev_err(dev
, "pipe iso is not supported now\n");
691 /* this ureq will be freed on usbhsh_queue_done() */
692 ureq
= usbhsh_ureq_alloc(hpriv
, urb
, mem_flags
);
693 if (unlikely(!ureq
)) {
694 dev_err(dev
, "ureq alloc fail\n");
698 if (usb_pipein(urb
->pipe
))
699 pipe
->handler
= &usbhs_fifo_dma_pop_handler
;
701 pipe
->handler
= &usbhs_fifo_dma_push_handler
;
703 buf
= (void *)(urb
->transfer_buffer
+ urb
->actual_length
);
704 len
= urb
->transfer_buffer_length
- urb
->actual_length
;
706 sequence
= usb_gettoggle(urb
->dev
,
707 usb_pipeendpoint(urb
->pipe
),
708 usb_pipeout(urb
->pipe
));
710 dev_dbg(dev
, "%s\n", __func__
);
711 usbhs_pkt_push(pipe
, &ureq
->pkt
, usbhsh_queue_done
,
712 buf
, len
, (urb
->transfer_flags
& URB_ZERO_PACKET
),
715 usbhs_pkt_start(pipe
);
720 static void usbhsh_queue_force_pop(struct usbhs_priv
*priv
,
721 struct usbhs_pipe
*pipe
)
723 struct usbhs_pkt
*pkt
;
726 pkt
= usbhs_pkt_pop(pipe
, NULL
);
731 * if all packet are gone, usbhsh_endpoint_disable()
733 * then, attached device/endpoint/pipe will be detached
735 usbhsh_queue_done(priv
, pkt
);
739 static void usbhsh_queue_force_pop_all(struct usbhs_priv
*priv
)
741 struct usbhs_pipe
*pos
;
744 usbhs_for_each_pipe_with_dcp(pos
, priv
, i
)
745 usbhsh_queue_force_pop(priv
, pos
);
751 static int usbhsh_is_request_address(struct urb
*urb
)
753 struct usb_ctrlrequest
*req
;
755 req
= (struct usb_ctrlrequest
*)urb
->setup_packet
;
757 if ((DeviceOutRequest
== req
->bRequestType
<< 8) &&
758 (USB_REQ_SET_ADDRESS
== req
->bRequest
))
764 static void usbhsh_setup_stage_packet_push(struct usbhsh_hpriv
*hpriv
,
766 struct usbhs_pipe
*pipe
)
768 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
769 struct usb_ctrlrequest req
;
770 struct device
*dev
= usbhs_priv_to_dev(priv
);
773 * wait setup packet ACK
775 * usbhsh_irq_setup_ack()
776 * usbhsh_irq_setup_err()
778 init_completion(&hpriv
->setup_ack_done
);
780 /* copy original request */
781 memcpy(&req
, urb
->setup_packet
, sizeof(struct usb_ctrlrequest
));
784 * renesas_usbhs can not use original usb address.
785 * see HARDWARE LIMITATION.
786 * modify usb address here to use attached device.
787 * see usbhsh_device_attach()
789 if (usbhsh_is_request_address(urb
)) {
790 struct usb_device
*usbv
= usbhsh_urb_to_usbv(urb
);
791 struct usbhsh_device
*udev
= usbhsh_usbv_to_udev(usbv
);
793 /* udev is a attached device */
794 req
.wValue
= usbhsh_device_number(hpriv
, udev
);
795 dev_dbg(dev
, "create new address - %d\n", req
.wValue
);
799 usbhs_usbreq_set_val(priv
, &req
);
802 * wait setup packet ACK
804 wait_for_completion(&hpriv
->setup_ack_done
);
806 dev_dbg(dev
, "%s done\n", __func__
);
812 static void usbhsh_data_stage_packet_done(struct usbhs_priv
*priv
,
813 struct usbhs_pkt
*pkt
)
815 struct usbhsh_request
*ureq
= usbhsh_pkt_to_ureq(pkt
);
816 struct usbhsh_hpriv
*hpriv
= usbhsh_priv_to_hpriv(priv
);
818 /* this ureq was connected to urb when usbhsh_urb_enqueue() */
820 usbhsh_ureq_free(hpriv
, ureq
);
823 static int usbhsh_data_stage_packet_push(struct usbhsh_hpriv
*hpriv
,
825 struct usbhs_pipe
*pipe
,
829 struct usbhsh_request
*ureq
;
831 /* this ureq will be freed on usbhsh_data_stage_packet_done() */
832 ureq
= usbhsh_ureq_alloc(hpriv
, urb
, mem_flags
);
836 if (usb_pipein(urb
->pipe
))
837 pipe
->handler
= &usbhs_dcp_data_stage_in_handler
;
839 pipe
->handler
= &usbhs_dcp_data_stage_out_handler
;
841 usbhs_pkt_push(pipe
, &ureq
->pkt
,
842 usbhsh_data_stage_packet_done
,
843 urb
->transfer_buffer
,
844 urb
->transfer_buffer_length
,
845 (urb
->transfer_flags
& URB_ZERO_PACKET
),
854 static int usbhsh_status_stage_packet_push(struct usbhsh_hpriv
*hpriv
,
856 struct usbhs_pipe
*pipe
,
859 struct usbhsh_request
*ureq
;
861 /* This ureq will be freed on usbhsh_queue_done() */
862 ureq
= usbhsh_ureq_alloc(hpriv
, urb
, mem_flags
);
866 if (usb_pipein(urb
->pipe
))
867 pipe
->handler
= &usbhs_dcp_status_stage_in_handler
;
869 pipe
->handler
= &usbhs_dcp_status_stage_out_handler
;
871 usbhs_pkt_push(pipe
, &ureq
->pkt
,
874 urb
->transfer_buffer_length
,
880 static int usbhsh_dcp_queue_push(struct usb_hcd
*hcd
,
884 struct usbhsh_hpriv
*hpriv
= usbhsh_hcd_to_hpriv(hcd
);
885 struct usbhsh_ep
*uep
= usbhsh_ep_to_uep(urb
->ep
);
886 struct usbhs_pipe
*pipe
= usbhsh_uep_to_pipe(uep
);
887 struct device
*dev
= usbhsh_hcd_to_dev(hcd
);
890 dev_dbg(dev
, "%s\n", __func__
);
895 * usbhsh_send_setup_stage_packet() wait SACK/SIGN
897 usbhsh_setup_stage_packet_push(hpriv
, urb
, pipe
);
902 * It is pushed only when urb has buffer.
904 if (urb
->transfer_buffer_length
) {
905 ret
= usbhsh_data_stage_packet_push(hpriv
, urb
, pipe
, mflags
);
907 dev_err(dev
, "data stage failed\n");
915 ret
= usbhsh_status_stage_packet_push(hpriv
, urb
, pipe
, mflags
);
917 dev_err(dev
, "status stage failed\n");
922 * start pushed packets
924 usbhs_pkt_start(pipe
);
932 static int usbhsh_dma_map_ctrl(struct device
*dma_dev
, struct usbhs_pkt
*pkt
,
936 struct usbhsh_request
*ureq
= usbhsh_pkt_to_ureq(pkt
);
937 struct urb
*urb
= ureq
->urb
;
939 /* it can not use scatter/gather */
943 pkt
->dma
= urb
->transfer_dma
;
954 static int usbhsh_host_start(struct usb_hcd
*hcd
)
959 static void usbhsh_host_stop(struct usb_hcd
*hcd
)
963 static int usbhsh_urb_enqueue(struct usb_hcd
*hcd
,
967 struct usbhsh_hpriv
*hpriv
= usbhsh_hcd_to_hpriv(hcd
);
968 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
969 struct device
*dev
= usbhs_priv_to_dev(priv
);
970 struct usb_host_endpoint
*ep
= urb
->ep
;
971 struct usbhsh_device
*new_udev
= NULL
;
972 int is_dir_in
= usb_pipein(urb
->pipe
);
975 dev_dbg(dev
, "%s (%s)\n", __func__
, is_dir_in
? "in" : "out");
977 if (!usbhsh_is_running(hpriv
)) {
979 dev_err(dev
, "host is not running\n");
980 goto usbhsh_urb_enqueue_error_not_linked
;
983 ret
= usb_hcd_link_urb_to_ep(hcd
, urb
);
985 dev_err(dev
, "urb link failed\n");
986 goto usbhsh_urb_enqueue_error_not_linked
;
990 * attach udev if needed
991 * see [image of mod_host]
993 if (!usbhsh_device_get(hpriv
, urb
)) {
994 new_udev
= usbhsh_device_attach(hpriv
, urb
);
997 dev_err(dev
, "device attach failed\n");
998 goto usbhsh_urb_enqueue_error_not_linked
;
1003 * attach endpoint if needed
1004 * see [image of mod_host]
1006 if (!usbhsh_ep_to_uep(ep
)) {
1007 ret
= usbhsh_endpoint_attach(hpriv
, urb
, mem_flags
);
1009 dev_err(dev
, "endpoint attach failed\n");
1010 goto usbhsh_urb_enqueue_error_free_device
;
1015 * attach pipe to endpoint
1016 * see [image of mod_host]
1018 ret
= usbhsh_pipe_attach(hpriv
, urb
);
1020 dev_err(dev
, "pipe attach failed\n");
1021 goto usbhsh_urb_enqueue_error_free_endpoint
;
1027 if (usb_pipecontrol(urb
->pipe
))
1028 ret
= usbhsh_dcp_queue_push(hcd
, urb
, mem_flags
);
1030 ret
= usbhsh_queue_push(hcd
, urb
, mem_flags
);
1034 usbhsh_urb_enqueue_error_free_endpoint
:
1035 usbhsh_endpoint_detach(hpriv
, ep
);
1036 usbhsh_urb_enqueue_error_free_device
:
1038 usbhsh_device_detach(hpriv
, new_udev
);
1039 usbhsh_urb_enqueue_error_not_linked
:
1041 dev_dbg(dev
, "%s error\n", __func__
);
1046 static int usbhsh_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
, int status
)
1048 struct usbhsh_hpriv
*hpriv
= usbhsh_hcd_to_hpriv(hcd
);
1049 struct usbhsh_request
*ureq
= usbhsh_urb_to_ureq(urb
);
1052 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
1053 struct usbhs_pkt
*pkt
= &ureq
->pkt
;
1055 usbhs_pkt_pop(pkt
->pipe
, pkt
);
1056 usbhsh_queue_done(priv
, pkt
);
1062 static void usbhsh_endpoint_disable(struct usb_hcd
*hcd
,
1063 struct usb_host_endpoint
*ep
)
1065 struct usbhsh_ep
*uep
= usbhsh_ep_to_uep(ep
);
1066 struct usbhsh_device
*udev
;
1067 struct usbhsh_hpriv
*hpriv
;
1070 * this function might be called manytimes by same hcd/ep
1071 * in-endpoint == out-endpoint if ep == dcp.
1076 udev
= usbhsh_uep_to_udev(uep
);
1077 hpriv
= usbhsh_hcd_to_hpriv(hcd
);
1079 usbhsh_endpoint_detach(hpriv
, ep
);
1082 * if there is no endpoint,
1085 if (!usbhsh_device_has_endpoint(udev
))
1086 usbhsh_device_detach(hpriv
, udev
);
1089 static int usbhsh_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
1091 struct usbhsh_hpriv
*hpriv
= usbhsh_hcd_to_hpriv(hcd
);
1092 int roothub_id
= 1; /* only 1 root hub */
1095 * does port stat was changed ?
1096 * check USB_PORT_STAT_C_xxx << 16
1098 if (usbhsh_port_stat_get(hpriv
) & 0xFFFF0000)
1099 *buf
= (1 << roothub_id
);
1106 static int __usbhsh_hub_hub_feature(struct usbhsh_hpriv
*hpriv
,
1107 u16 typeReq
, u16 wValue
,
1108 u16 wIndex
, char *buf
, u16 wLength
)
1110 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
1111 struct device
*dev
= usbhs_priv_to_dev(priv
);
1114 case C_HUB_OVER_CURRENT
:
1115 case C_HUB_LOCAL_POWER
:
1116 dev_dbg(dev
, "%s :: C_HUB_xx\n", __func__
);
1123 static int __usbhsh_hub_port_feature(struct usbhsh_hpriv
*hpriv
,
1124 u16 typeReq
, u16 wValue
,
1125 u16 wIndex
, char *buf
, u16 wLength
)
1127 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
1128 struct device
*dev
= usbhs_priv_to_dev(priv
);
1129 int enable
= (typeReq
== SetPortFeature
);
1130 int speed
, i
, timeout
= 128;
1131 int roothub_id
= 1; /* only 1 root hub */
1134 if (wIndex
> roothub_id
|| wLength
!= 0)
1139 case USB_PORT_FEAT_POWER
:
1140 usbhs_vbus_ctrl(priv
, enable
);
1141 dev_dbg(dev
, "%s :: USB_PORT_FEAT_POWER\n", __func__
);
1144 case USB_PORT_FEAT_ENABLE
:
1145 case USB_PORT_FEAT_SUSPEND
:
1146 case USB_PORT_FEAT_C_ENABLE
:
1147 case USB_PORT_FEAT_C_SUSPEND
:
1148 case USB_PORT_FEAT_C_CONNECTION
:
1149 case USB_PORT_FEAT_C_OVER_CURRENT
:
1150 case USB_PORT_FEAT_C_RESET
:
1151 dev_dbg(dev
, "%s :: USB_PORT_FEAT_xxx\n", __func__
);
1154 case USB_PORT_FEAT_RESET
:
1158 usbhsh_port_stat_clear(hpriv
,
1159 USB_PORT_STAT_HIGH_SPEED
|
1160 USB_PORT_STAT_LOW_SPEED
);
1162 usbhsh_queue_force_pop_all(priv
);
1164 usbhs_bus_send_reset(priv
);
1166 usbhs_bus_send_sof_enable(priv
);
1168 for (i
= 0; i
< timeout
; i
++) {
1169 switch (usbhs_bus_get_speed(priv
)) {
1171 speed
= USB_PORT_STAT_LOW_SPEED
;
1172 goto got_usb_bus_speed
;
1173 case USB_SPEED_HIGH
:
1174 speed
= USB_PORT_STAT_HIGH_SPEED
;
1175 goto got_usb_bus_speed
;
1176 case USB_SPEED_FULL
:
1178 goto got_usb_bus_speed
;
1186 usbhsh_port_stat_set(hpriv
, speed
);
1187 usbhsh_port_stat_set(hpriv
, USB_PORT_STAT_ENABLE
);
1189 dev_dbg(dev
, "%s :: USB_PORT_FEAT_RESET (speed = %d)\n",
1192 /* status change is not needed */
1199 /* set/clear status */
1201 usbhsh_port_stat_set(hpriv
, (1 << wValue
));
1203 usbhsh_port_stat_clear(hpriv
, (1 << wValue
));
1208 static int __usbhsh_hub_get_status(struct usbhsh_hpriv
*hpriv
,
1209 u16 typeReq
, u16 wValue
,
1210 u16 wIndex
, char *buf
, u16 wLength
)
1212 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
1213 struct usb_hub_descriptor
*desc
= (struct usb_hub_descriptor
*)buf
;
1214 struct device
*dev
= usbhs_priv_to_dev(priv
);
1215 int roothub_id
= 1; /* only 1 root hub */
1219 dev_dbg(dev
, "%s :: GetHubStatus\n", __func__
);
1225 if (wIndex
!= roothub_id
)
1228 dev_dbg(dev
, "%s :: GetPortStatus\n", __func__
);
1229 *(__le32
*)buf
= cpu_to_le32(usbhsh_port_stat_get(hpriv
));
1232 case GetHubDescriptor
:
1233 desc
->bDescriptorType
= USB_DT_HUB
;
1234 desc
->bHubContrCurrent
= 0;
1235 desc
->bNbrPorts
= roothub_id
;
1236 desc
->bDescLength
= 9;
1237 desc
->bPwrOn2PwrGood
= 0;
1238 desc
->wHubCharacteristics
=
1239 cpu_to_le16(HUB_CHAR_INDV_PORT_LPSM
| HUB_CHAR_NO_OCPM
);
1240 desc
->u
.hs
.DeviceRemovable
[0] = (roothub_id
<< 1);
1241 desc
->u
.hs
.DeviceRemovable
[1] = ~0;
1242 dev_dbg(dev
, "%s :: GetHubDescriptor\n", __func__
);
1249 static int usbhsh_hub_control(struct usb_hcd
*hcd
, u16 typeReq
, u16 wValue
,
1250 u16 wIndex
, char *buf
, u16 wLength
)
1252 struct usbhsh_hpriv
*hpriv
= usbhsh_hcd_to_hpriv(hcd
);
1253 struct usbhs_priv
*priv
= usbhsh_hpriv_to_priv(hpriv
);
1254 struct device
*dev
= usbhs_priv_to_dev(priv
);
1260 case ClearHubFeature
:
1262 ret
= __usbhsh_hub_hub_feature(hpriv
, typeReq
,
1263 wValue
, wIndex
, buf
, wLength
);
1267 case SetPortFeature
:
1268 case ClearPortFeature
:
1269 ret
= __usbhsh_hub_port_feature(hpriv
, typeReq
,
1270 wValue
, wIndex
, buf
, wLength
);
1276 case GetHubDescriptor
:
1277 ret
= __usbhsh_hub_get_status(hpriv
, typeReq
,
1278 wValue
, wIndex
, buf
, wLength
);
1282 dev_dbg(dev
, "typeReq = %x, ret = %d, port_stat = %x\n",
1283 typeReq
, ret
, usbhsh_port_stat_get(hpriv
));
1288 static int usbhsh_bus_nop(struct usb_hcd
*hcd
)
1294 static struct hc_driver usbhsh_driver
= {
1295 .description
= usbhsh_hcd_name
,
1296 .hcd_priv_size
= sizeof(struct usbhsh_hpriv
),
1299 * generic hardware linkage
1303 .start
= usbhsh_host_start
,
1304 .stop
= usbhsh_host_stop
,
1307 * managing i/o requests and associated device resources
1309 .urb_enqueue
= usbhsh_urb_enqueue
,
1310 .urb_dequeue
= usbhsh_urb_dequeue
,
1311 .endpoint_disable
= usbhsh_endpoint_disable
,
1316 .hub_status_data
= usbhsh_hub_status_data
,
1317 .hub_control
= usbhsh_hub_control
,
1318 .bus_suspend
= usbhsh_bus_nop
,
1319 .bus_resume
= usbhsh_bus_nop
,
1323 * interrupt functions
1325 static int usbhsh_irq_attch(struct usbhs_priv
*priv
,
1326 struct usbhs_irq_state
*irq_state
)
1328 struct usbhsh_hpriv
*hpriv
= usbhsh_priv_to_hpriv(priv
);
1329 struct device
*dev
= usbhs_priv_to_dev(priv
);
1331 dev_dbg(dev
, "device attached\n");
1333 usbhsh_port_stat_set(hpriv
, USB_PORT_STAT_CONNECTION
);
1334 usbhsh_port_stat_set(hpriv
, USB_PORT_STAT_C_CONNECTION
<< 16);
1337 * attch interrupt might happen infinitely on some device
1338 * (on self power USB hub ?)
1341 * usbhsh_is_running() becomes effective
1342 * according to this process.
1344 * usbhsh_is_running()
1345 * usbhsh_urb_enqueue()
1347 hpriv
->mod
.irq_attch
= NULL
;
1348 usbhs_irq_callback_update(priv
, &hpriv
->mod
);
1353 static int usbhsh_irq_dtch(struct usbhs_priv
*priv
,
1354 struct usbhs_irq_state
*irq_state
)
1356 struct usbhsh_hpriv
*hpriv
= usbhsh_priv_to_hpriv(priv
);
1357 struct device
*dev
= usbhs_priv_to_dev(priv
);
1359 dev_dbg(dev
, "device detached\n");
1361 usbhsh_port_stat_clear(hpriv
, USB_PORT_STAT_CONNECTION
);
1362 usbhsh_port_stat_set(hpriv
, USB_PORT_STAT_C_CONNECTION
<< 16);
1365 * enable attch interrupt again
1367 * usbhsh_is_running() becomes invalid
1368 * according to this process.
1370 * usbhsh_is_running()
1371 * usbhsh_urb_enqueue()
1373 hpriv
->mod
.irq_attch
= usbhsh_irq_attch
;
1374 usbhs_irq_callback_update(priv
, &hpriv
->mod
);
1377 * usbhsh_queue_force_pop_all() should be called
1378 * after usbhsh_is_running() becomes invalid.
1380 usbhsh_queue_force_pop_all(priv
);
1385 static int usbhsh_irq_setup_ack(struct usbhs_priv
*priv
,
1386 struct usbhs_irq_state
*irq_state
)
1388 struct usbhsh_hpriv
*hpriv
= usbhsh_priv_to_hpriv(priv
);
1389 struct device
*dev
= usbhs_priv_to_dev(priv
);
1391 dev_dbg(dev
, "setup packet OK\n");
1393 complete(&hpriv
->setup_ack_done
); /* see usbhsh_urb_enqueue() */
1398 static int usbhsh_irq_setup_err(struct usbhs_priv
*priv
,
1399 struct usbhs_irq_state
*irq_state
)
1401 struct usbhsh_hpriv
*hpriv
= usbhsh_priv_to_hpriv(priv
);
1402 struct device
*dev
= usbhs_priv_to_dev(priv
);
1404 dev_dbg(dev
, "setup packet Err\n");
1406 complete(&hpriv
->setup_ack_done
); /* see usbhsh_urb_enqueue() */
1414 static void usbhsh_pipe_init_for_host(struct usbhs_priv
*priv
)
1416 struct usbhsh_hpriv
*hpriv
= usbhsh_priv_to_hpriv(priv
);
1417 struct usbhs_pipe
*pipe
;
1418 struct renesas_usbhs_driver_pipe_config
*pipe_configs
=
1419 usbhs_get_dparam(priv
, pipe_configs
);
1420 int pipe_size
= usbhs_get_dparam(priv
, pipe_size
);
1421 int old_type
, dir_in
, i
;
1424 old_type
= USB_ENDPOINT_XFER_CONTROL
;
1425 for (i
= 0; i
< pipe_size
; i
++) {
1428 * data "output" will be finished as soon as possible,
1429 * but there is no guaranty at data "input" case.
1431 * "input" needs "standby" pipe.
1432 * So, "input" direction pipe > "output" direction pipe
1435 * 1st USB_ENDPOINT_XFER_xxx will be output direction,
1436 * and the other will be input direction here.
1440 * USB_ENDPOINT_XFER_ISOC -> dir out
1441 * USB_ENDPOINT_XFER_ISOC -> dir in
1442 * USB_ENDPOINT_XFER_BULK -> dir out
1443 * USB_ENDPOINT_XFER_BULK -> dir in
1444 * USB_ENDPOINT_XFER_BULK -> dir in
1447 dir_in
= (pipe_configs
[i
].type
== old_type
);
1448 old_type
= pipe_configs
[i
].type
;
1450 if (USB_ENDPOINT_XFER_CONTROL
== pipe_configs
[i
].type
) {
1451 pipe
= usbhs_dcp_malloc(priv
);
1452 usbhsh_hpriv_to_dcp(hpriv
) = pipe
;
1454 pipe
= usbhs_pipe_malloc(priv
,
1455 pipe_configs
[i
].type
,
1459 pipe
->mod_private
= NULL
;
1463 static int usbhsh_start(struct usbhs_priv
*priv
)
1465 struct usbhsh_hpriv
*hpriv
= usbhsh_priv_to_hpriv(priv
);
1466 struct usb_hcd
*hcd
= usbhsh_hpriv_to_hcd(hpriv
);
1467 struct usbhs_mod
*mod
= usbhs_mod_get_current(priv
);
1468 struct device
*dev
= usbhs_priv_to_dev(priv
);
1472 ret
= usb_add_hcd(hcd
, 0, 0);
1475 device_wakeup_enable(hcd
->self
.controller
);
1478 * pipe initialize and enable DCP
1480 usbhs_fifo_init(priv
);
1481 usbhs_pipe_init(priv
,
1482 usbhsh_dma_map_ctrl
);
1483 usbhsh_pipe_init_for_host(priv
);
1486 * system config enble
1491 usbhs_sys_host_ctrl(priv
, 1);
1494 * enable irq callback
1496 mod
->irq_attch
= usbhsh_irq_attch
;
1497 mod
->irq_dtch
= usbhsh_irq_dtch
;
1498 mod
->irq_sack
= usbhsh_irq_setup_ack
;
1499 mod
->irq_sign
= usbhsh_irq_setup_err
;
1500 usbhs_irq_callback_update(priv
, mod
);
1502 dev_dbg(dev
, "start host\n");
1507 static int usbhsh_stop(struct usbhs_priv
*priv
)
1509 struct usbhsh_hpriv
*hpriv
= usbhsh_priv_to_hpriv(priv
);
1510 struct usb_hcd
*hcd
= usbhsh_hpriv_to_hcd(hpriv
);
1511 struct usbhs_mod
*mod
= usbhs_mod_get_current(priv
);
1512 struct device
*dev
= usbhs_priv_to_dev(priv
);
1515 * disable irq callback
1517 mod
->irq_attch
= NULL
;
1518 mod
->irq_dtch
= NULL
;
1519 mod
->irq_sack
= NULL
;
1520 mod
->irq_sign
= NULL
;
1521 usbhs_irq_callback_update(priv
, mod
);
1523 usb_remove_hcd(hcd
);
1526 usbhs_sys_host_ctrl(priv
, 0);
1528 dev_dbg(dev
, "quit host\n");
1533 int usbhs_mod_host_probe(struct usbhs_priv
*priv
)
1535 struct usbhsh_hpriv
*hpriv
;
1536 struct usb_hcd
*hcd
;
1537 struct usbhsh_device
*udev
;
1538 struct device
*dev
= usbhs_priv_to_dev(priv
);
1541 /* initialize hcd */
1542 hcd
= usb_create_hcd(&usbhsh_driver
, dev
, usbhsh_hcd_name
);
1544 dev_err(dev
, "Failed to create hcd\n");
1547 hcd
->has_tt
= 1; /* for low/full speed */
1552 * There is no guarantee that it is possible to access usb module here.
1553 * Don't accesses to it.
1554 * The accesse will be enable after "usbhsh_start"
1557 hpriv
= usbhsh_hcd_to_hpriv(hcd
);
1562 usbhs_mod_register(priv
, &hpriv
->mod
, USBHS_HOST
);
1565 hpriv
->mod
.name
= "host";
1566 hpriv
->mod
.start
= usbhsh_start
;
1567 hpriv
->mod
.stop
= usbhsh_stop
;
1568 usbhsh_port_stat_init(hpriv
);
1570 /* init all device */
1571 usbhsh_for_each_udev_with_dev0(udev
, hpriv
, i
) {
1573 INIT_LIST_HEAD(&udev
->ep_list_head
);
1576 dev_info(dev
, "host probed\n");
1581 int usbhs_mod_host_remove(struct usbhs_priv
*priv
)
1583 struct usbhsh_hpriv
*hpriv
= usbhsh_priv_to_hpriv(priv
);
1584 struct usb_hcd
*hcd
= usbhsh_hpriv_to_hcd(hpriv
);