Index: uspace/drv/bus/usb/ehci/Makefile
===================================================================
--- uspace/drv/bus/usb/ehci/Makefile	(revision 07b88773f3991de62f7ff663a1a6e566a7dfe118)
+++ uspace/drv/bus/usb/ehci/Makefile	(revision f9351b1fb2d918b59c7670c408a32770aa4d4c9b)
@@ -45,5 +45,7 @@
 
 SOURCES = \
+	ehci_endpoint.c \
 	ehci_rh.c \
+	endpoint_list.c \
 	hc.c \
 	main.c \
Index: uspace/drv/bus/usb/ehci/ehci_endpoint.c
===================================================================
--- uspace/drv/bus/usb/ehci/ehci_endpoint.c	(revision f9351b1fb2d918b59c7670c408a32770aa4d4c9b)
+++ uspace/drv/bus/usb/ehci/ehci_endpoint.c	(revision f9351b1fb2d918b59c7670c408a32770aa4d4c9b)
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2014 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include "utils/malloc32.h"
+#include "ehci_endpoint.h"
+#include "hc.h"
+
+/** Callback to set toggle on ED.
+ *
+ * @param[in] hcd_ep hcd endpoint structure
+ * @param[in] toggle new value of toggle bit
+ */
+static void ehci_ep_toggle_set(void *ehci_ep, int toggle)
+{
+	ehci_endpoint_t *instance = ehci_ep;
+	assert(instance);
+	assert(instance->qh);
+//	qh_toggle_set(instance->qh, toggle);
+}
+
+/** Callback to get value of toggle bit.
+ *
+ * @param[in] hcd_ep hcd endpoint structure
+ * @return Current value of toggle bit.
+ */
+static int ehci_ep_toggle_get(void *ehci_ep)
+{
+	ehci_endpoint_t *instance = ehci_ep;
+	assert(instance);
+	assert(instance->qh);
+	return 0;
+//	return qh_toggle_get(instance->qh);
+}
+
+/** Creates new hcd endpoint representation.
+ *
+ * @param[in] ep USBD endpoint structure
+ * @return Error code.
+ */
+int ehci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
+{
+	assert(ep);
+	ehci_endpoint_t *ehci_ep = malloc(sizeof(ehci_endpoint_t));
+	if (ehci_ep == NULL)
+		return ENOMEM;
+
+	ehci_ep->qh = malloc32(sizeof(qh_t));
+	if (ehci_ep->qh == NULL) {
+		free(ehci_ep);
+		return ENOMEM;
+	}
+
+//	qh_init(ehci_ep->qh, ep);
+	endpoint_set_hc_data(
+	    ep, ehci_ep, ehci_ep_toggle_get, ehci_ep_toggle_set);
+	hc_enqueue_endpoint(hcd->driver.data, ep);
+	return EOK;
+}
+
+/** Disposes hcd endpoint structure
+ *
+ * @param[in] hcd driver using this instance.
+ * @param[in] ep endpoint structure.
+ */
+void ehci_endpoint_fini(hcd_t *hcd, endpoint_t *ep)
+{
+	assert(hcd);
+	assert(ep);
+	ehci_endpoint_t *instance = ehci_endpoint_get(ep);
+	hc_dequeue_endpoint(hcd->driver.data, ep);
+	if (instance) {
+		free32(instance->qh);
+		free(instance);
+	}
+	endpoint_clear_hc_data(ep);
+}
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/ehci_endpoint.h
===================================================================
--- uspace/drv/bus/usb/ehci/ehci_endpoint.h	(revision f9351b1fb2d918b59c7670c408a32770aa4d4c9b)
+++ uspace/drv/bus/usb/ehci/ehci_endpoint.h	(revision f9351b1fb2d918b59c7670c408a32770aa4d4c9b)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+#ifndef DRV_EHCI_HCD_ENDPOINT_H
+#define DRV_EHCI_HCD_ENDPOINT_H
+
+#include <assert.h>
+#include <adt/list.h>
+#include <usb/host/endpoint.h>
+#include <usb/host/hcd.h>
+
+#include "hw_struct/queue_head.h"
+#include "hw_struct/transfer_descriptor.h"
+
+/** Connector structure linking ED to to prepared TD. */
+typedef struct ehci_endpoint {
+	/** EHCI endpoint descriptor */
+	qh_t *qh;
+	/** Currently enqueued transfer descriptor */
+	td_t *td;
+	/** Linked list used by driver software */
+	link_t link;
+} ehci_endpoint_t;
+
+int ehci_endpoint_init(hcd_t *hcd, endpoint_t *ep);
+void ehci_endpoint_fini(hcd_t *hcd, endpoint_t *ep);
+
+/** Get and convert assigned ehci_endpoint_t structure
+ * @param[in] ep USBD endpoint structure.
+ * @return Pointer to assigned hcd endpoint structure
+ */
+static inline ehci_endpoint_t * ehci_endpoint_get(const endpoint_t *ep)
+{
+	assert(ep);
+	return ep->hc_data.data;
+}
+
+#endif
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/endpoint_list.c
===================================================================
--- uspace/drv/bus/usb/ehci/endpoint_list.c	(revision f9351b1fb2d918b59c7670c408a32770aa4d4c9b)
+++ uspace/drv/bus/usb/ehci/endpoint_list.c	(revision f9351b1fb2d918b59c7670c408a32770aa4d4c9b)
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2014 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver transfer list implementation
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <libarch/barrier.h>
+
+#include <usb/debug.h>
+
+#include "utils/malloc32.h"
+#include "endpoint_list.h"
+
+/** Initialize transfer list structures.
+ *
+ * @param[in] instance Memory place to use.
+ * @param[in] name Name of the new list.
+ * @return Error code
+ *
+ * Allocates memory for internal ed_t structure.
+ */
+int endpoint_list_init(endpoint_list_t *instance, const char *name)
+{
+	assert(instance);
+	instance->name = name;
+	instance->list_head = malloc32(sizeof(qh_t));
+	if (!instance->list_head) {
+		usb_log_error("Failed to allocate list head.\n");
+		return ENOMEM;
+	}
+	instance->list_head_pa = addr_to_phys(instance->list_head);
+	usb_log_debug2("Transfer list %s setup with ED: %p(0x%0" PRIx32 ")).\n",
+	    name, instance->list_head, instance->list_head_pa);
+
+//	qh_init(instance->list_head, NULL, NULL);
+	list_initialize(&instance->endpoint_list);
+	fibril_mutex_initialize(&instance->guard);
+	return EOK;
+}
+
+/** Add endpoint to the list and queue.
+ *
+ * @param[in] instance List to use.
+ * @param[in] endpoint Endpoint to add.
+ *
+ * The endpoint is added to the end of the list and queue.
+ */
+void endpoint_list_add_ep(endpoint_list_t *instance, ehci_endpoint_t *ep)
+{
+	assert(instance);
+	assert(ep);
+	usb_log_debug2("Queue %s: Adding endpoint(%p).\n", instance->name, ep);
+
+	fibril_mutex_lock(&instance->guard);
+
+#if 0
+	//TODO Implement this
+	ed_t *last_ed = NULL;
+	/* Add to the hardware queue. */
+	if (list_empty(&instance->endpoint_list)) {
+		/* There are no active EDs */
+		last_ed = instance->list_head;
+	} else {
+		/* There are active EDs, get the last one */
+		ehci_endpoint_t *last = list_get_instance(
+		    list_last(&instance->endpoint_list), ehci_endpoint_t, link);
+		last_ed = last->ed;
+	}
+	/* Keep link */
+	ep->ed->next = last_ed->next;
+	/* Make sure ED is written to the memory */
+	write_barrier();
+
+	/* Add ed to the hw queue */
+	ed_append_ed(last_ed, ep->ed);
+	/* Make sure ED is updated */
+	write_barrier();
+	/* Add to the sw list */
+	list_append(&ep->link, &instance->endpoint_list);
+
+	ehci_endpoint_t *first = list_get_instance(
+	    list_first(&instance->endpoint_list), ehci_endpoint_t, link);
+	usb_log_debug("HCD EP(%p) added to list %s, first is %p(%p).\n",
+		ep, instance->name, first, first->ed);
+	if (last_ed == instance->list_head) {
+		usb_log_debug2("%s head ED(%p-0x%0" PRIx32 "): %x:%x:%x:%x.\n",
+		    instance->name, last_ed, instance->list_head_pa,
+		    last_ed->status, last_ed->td_tail, last_ed->td_head,
+		    last_ed->next);
+	}
+#endif
+	fibril_mutex_unlock(&instance->guard);
+}
+
+/** Remove endpoint from the list and queue.
+ *
+ * @param[in] instance List to use.
+ * @param[in] endpoint Endpoint to remove.
+ */
+void endpoint_list_remove_ep(endpoint_list_t *instance, ehci_endpoint_t *ep)
+{
+	assert(instance);
+	assert(instance->list_head);
+	assert(ep);
+	assert(ep->qh);
+
+	fibril_mutex_lock(&instance->guard);
+
+	usb_log_debug2("Queue %s: removing endpoint(%p).\n", instance->name, ep);
+
+	const char *qpos = NULL;
+	qh_t *prev_qh;
+	/* Remove from the hardware queue */
+	if (list_first(&instance->endpoint_list) == &ep->link) {
+		/* I'm the first one here */
+		prev_qh = instance->list_head;
+		qpos = "FIRST";
+	} else {
+		ehci_endpoint_t *prev =
+		    list_get_instance(ep->link.prev, ehci_endpoint_t, link);
+		prev_qh = prev->qh;
+		qpos = "NOT FIRST";
+	}
+//	assert(ed_next(prev_qh) == addr_to_phys(ep->eq));
+	prev_qh->next = ep->qh->next;
+	/* Make sure ED is updated */
+	write_barrier();
+
+	usb_log_debug("HCD EP(%p) removed (%s) from %s, next %x.\n",
+	    ep, qpos, instance->name, ep->qh->next);
+
+	/* Remove from the endpoint list */
+	list_remove(&ep->link);
+	fibril_mutex_unlock(&instance->guard);
+}
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/endpoint_list.h
===================================================================
--- uspace/drv/bus/usb/ehci/endpoint_list.h	(revision f9351b1fb2d918b59c7670c408a32770aa4d4c9b)
+++ uspace/drv/bus/usb/ehci/endpoint_list.h	(revision f9351b1fb2d918b59c7670c408a32770aa4d4c9b)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2014 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver transfer list structure
+ */
+#ifndef DRV_EHCI_ENDPOINT_LIST_H
+#define DRV_EHCI_ENDPOINT_LIST_H
+
+#include <adt/list.h>
+#include <assert.h>
+#include <fibril_synch.h>
+#include <sys/types.h>
+
+#include "ehci_endpoint.h"
+#include "hw_struct/queue_head.h"
+#include "utils/malloc32.h"
+
+/** Structure maintains both EHCI queue and software list of active endpoints.*/
+typedef struct endpoint_list {
+	/** Guard against add/remove races */
+	fibril_mutex_t guard;
+	/** EHCI hw structure at the beginning of the queue */
+	qh_t *list_head;
+	/** Physical address of the first(dummy) ED */
+	uint32_t list_head_pa;
+	/** Assigned name, provides nicer debug output */
+	const char *name;
+	/** Sw list of all active EDs */
+	list_t endpoint_list;
+} endpoint_list_t;
+
+/** Dispose transfer list structures.
+ *
+ * @param[in] instance Memory place to use.
+ *
+ * Frees memory of the internal ed_t structure.
+ */
+static inline void endpoint_list_fini(endpoint_list_t *instance)
+{
+	assert(instance);
+	free32(instance->list_head);
+	instance->list_head = NULL;
+}
+
+int endpoint_list_init(endpoint_list_t *instance, const char *name);
+void endpoint_list_set_next(
+    const endpoint_list_t *instance, const endpoint_list_t *next);
+void endpoint_list_add_ep(endpoint_list_t *instance, ehci_endpoint_t *ep);
+void endpoint_list_remove_ep(endpoint_list_t *instance, ehci_endpoint_t *ep);
+#endif
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/hw_struct/queue_head.h
===================================================================
--- uspace/drv/bus/usb/ehci/hw_struct/queue_head.h	(revision 07b88773f3991de62f7ff663a1a6e566a7dfe118)
+++ uspace/drv/bus/usb/ehci/hw_struct/queue_head.h	(revision f9351b1fb2d918b59c7670c408a32770aa4d4c9b)
@@ -118,4 +118,5 @@
 } qh_t;
 
+
 #endif
 /**
