migrate from req_ctx to msgb

We now generalize the USB communiction and abandon the 'req_ctx'
structure inherited from openpcd.  Instead we use the libosmocore 'msgb'
structure to handle incoming and outgoing USB tranfers.  We also use
linuxlist-based msgb-queues for each endpoint.
diff --git a/firmware/libcommon/include/card_emu.h b/firmware/libcommon/include/card_emu.h
index df23ce4..43279f8 100644
--- a/firmware/libcommon/include/card_emu.h
+++ b/firmware/libcommon/include/card_emu.h
@@ -10,7 +10,8 @@
 	CARD_IO_CLK,
 };
 
-struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan);
+struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan,
+				  uint8_t in_ep, uint8_t irq_ep);
 
 /* process a single byte received from the reader */
 void card_emu_process_rx_byte(struct card_handle *ch, uint8_t byte);
@@ -25,7 +26,6 @@
 int card_emu_set_atr(struct card_handle *ch, const uint8_t *atr, uint8_t len);
 
 struct llist_head *card_emu_get_uart_tx_queue(struct card_handle *ch);
-struct llist_head *card_emu_get_usb_tx_queue(struct card_handle *ch);
 void card_emu_have_new_uart_tx(struct card_handle *ch);
 void card_emu_report_status(struct card_handle *ch);
 
diff --git a/firmware/libcommon/include/simtrace.h b/firmware/libcommon/include/simtrace.h
index 2a54d76..b9589f3 100644
--- a/firmware/libcommon/include/simtrace.h
+++ b/firmware/libcommon/include/simtrace.h
@@ -113,8 +113,4 @@
 void Timer_Init( void );
 void TC0_Counter_Reset( void );
 
-struct llist_head;
-int usb_refill_to_host(struct llist_head *queue, uint32_t ep);
-int usb_refill_from_host(struct llist_head *queue, int ep);
-
 #endif  /*  SIMTRACE_H  */
diff --git a/firmware/libcommon/include/talloc.h b/firmware/libcommon/include/talloc.h
new file mode 100644
index 0000000..f2d9666
--- /dev/null
+++ b/firmware/libcommon/include/talloc.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <stdlib.h>
+#include <stdarg.h>
+
+/* minimalistic emulation of core talloc API functions used by msgb.c */
+
+#define __TALLOC_STRING_LINE1__(s)    #s
+#define __TALLOC_STRING_LINE2__(s)   __TALLOC_STRING_LINE1__(s)
+#define __TALLOC_STRING_LINE3__  __TALLOC_STRING_LINE2__(__LINE__)
+#define __location__ __FILE__ ":" __TALLOC_STRING_LINE3__
+
+#define talloc_zero(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
+#define talloc_zero_size(ctx, size) _talloc_zero(ctx, size, __location__)
+void *_talloc_zero(const void *ctx, size_t size, const char *name);
+
+#define talloc_free(ctx) _talloc_free(ctx, __location__)
+int _talloc_free(void *ptr, const char *location);
+
+/* Unsupported! */
+#define talloc_size(ctx, size) talloc_named_const(ctx, size, __location__)
+void *talloc_named_const(const void *context, size_t size, const char *name);
+void talloc_set_name_const(const void *ptr, const char *name);
+char *talloc_strdup(const void *t, const char *p);
+void *talloc_pool(const void *context, size_t size);
diff --git a/firmware/libcommon/include/usb_buf.h b/firmware/libcommon/include/usb_buf.h
new file mode 100644
index 0000000..dd16531
--- /dev/null
+++ b/firmware/libcommon/include/usb_buf.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "osmocom/core/linuxlist.h"
+#include "osmocom/core/msgb.h"
+
+/* buffered USB endpoint (with queue of msgb) */
+struct usb_buffered_ep {
+	/* endpoint number */
+	uint8_t ep;
+	/* OUT endpoint (1) or IN/IRQ (0)? */
+	uint8_t out_from_host;
+	/* currently any transfer in progress? */
+	volatile uint32_t in_progress;
+	/* Tx queue (IN) / Rx queue (OUT) */
+	struct llist_head queue;
+};
+
+struct msgb *usb_buf_alloc(uint8_t ep);
+void usb_buf_free(struct msgb *msg);
+int usb_buf_submit(struct msgb *msg);
+struct llist_head *usb_get_queue(uint8_t ep);
+int usb_drain_queue(uint8_t ep);
+
+void usb_buf_init(void);
+struct usb_buffered_ep *usb_get_buf_ep(uint8_t ep);
+
+int usb_refill_to_host(uint8_t ep);
+int usb_refill_from_host(uint8_t ep);