Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Sep 2013 06:39:34 GMT
From:      syuu@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r257395 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve: . usb usb/gpl usb/include usb/include/hw
Message-ID:  <201309160639.r8G6dYPI041742@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: syuu
Date: Mon Sep 16 06:39:34 2013
New Revision: 257395
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257395

Log:
  import iov.[ch], import trace_* functions, enable usb_device_* calls, testing bootup GuestOS with uhci & usb-serial

Added:
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/hexdump.c
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/iov.c
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/iov.h
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/trace.h
Modified:
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/core.c
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.c
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/host-libusb.c
  soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h

Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile
==============================================================================
--- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile	Mon Sep 16 02:01:36 2013	(r257394)
+++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile	Mon Sep 16 06:39:34 2013	(r257395)
@@ -19,7 +19,7 @@
 CFLAGS+=-I${.CURDIR}/usb/include -I${.CURDIR} 
 SRCS+=	core.c hcd-uhci.c host-libusb.c dev-hub.c
 .PATH: ${.CURDIR}/usb/gpl
-SRCS+=	desc.c dev-serial.c bus.c
+SRCS+=	desc.c dev-serial.c bus.c iov.c hexdump.c
 
 NO_MAN=
 

Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/core.c
==============================================================================
--- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/core.c	Mon Sep 16 02:01:36 2013	(r257394)
+++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/core.c	Mon Sep 16 06:39:34 2013	(r257395)
@@ -27,31 +27,29 @@
 #include <stdlib.h>
 #include <sys/socket.h>
 #include "hw/usb.h"
-
-#define trace_usb_packet_state_fault(busnr, path, nr, p, state, expected) \
-    fprintf(stderr, "%s:%d trace_usb_packet_state_fault busnr=%d path=%s nr=%d p=%p state=%s expected=%s\n", \
-	__func__, __LINE__, busnr, path, nr, p, state, expected)
-#define trace_usb_packet_state_change(busnr, path, nr, p, state, expected) \
-    fprintf(stderr, "%s:%d trace_usb_packet_state_change busnr=%d path=%s nr=%d p=%p state=%s expected=%s\n", \
-	__func__, __LINE__, busnr, path, nr, p, state, expected)
-
+#include "usb/gpl/iov.h"
+#include "trace.h"
 
 void usb_attach(USBPort *port)
 {
     USBDevice *dev = port->dev;
 
+//    fprintf(usblog, "%s:%d dev=%p port=%p\n",
+//		__func__, __LINE__, dev, port);
     assert(dev != NULL);
     assert(dev->attached);
     assert(dev->state == USB_STATE_NOTATTACHED);
     port->ops->attach(port);
     dev->state = USB_STATE_ATTACHED;
-//    usb_device_handle_attach(dev);
+    usb_device_handle_attach(dev);
 }
 
 void usb_detach(USBPort *port)
 {
     USBDevice *dev = port->dev;
 
+//    fprintf(usblog, "%s:%d dev=%p port=%p\n",
+//		__func__, __LINE__, dev, port);
     assert(dev != NULL);
     assert(dev->state != USB_STATE_NOTATTACHED);
     port->ops->detach(port);
@@ -62,6 +60,8 @@
 {
     USBDevice *dev = port->dev;
 
+//    fprintf(usblog, "%s:%d dev=%p port=%p\n",
+//		__func__, __LINE__, dev, port);
     assert(dev != NULL);
     usb_detach(port);
     usb_attach(port);
@@ -73,10 +73,12 @@
     if (dev == NULL || !dev->attached) {
         return;
     }
+//    fprintf(usblog, "%s:%d dev=%p\n",
+//		__func__, __LINE__, dev);
     dev->remote_wakeup = 0;
     dev->addr = 0;
     dev->state = USB_STATE_DEFAULT;
-//    usb_device_handle_reset(dev);
+    usb_device_handle_reset(dev);
 }
 
 void usb_wakeup(USBEndpoint *ep, unsigned int stream)
@@ -84,6 +86,8 @@
     USBDevice *dev = ep->dev;
     USBBus *bus = usb_bus_from_device(dev);
 
+//    fprintf(usblog, "%s:%d dev=%p bus=%p ep=%p stream=%x\n",
+//		__func__, __LINE__, dev, bus, ep, stream);
     if (dev->remote_wakeup && dev->port && dev->port->ops->wakeup) {
         dev->port->ops->wakeup(dev->port);
     }
@@ -109,6 +113,8 @@
 {
     int request, value, index;
 
+    fprintf(usblog, "%s:%d s=%p p=%p\n",
+		__func__, __LINE__, s, p);
     if (p->iov.size != 8) {
         p->status = USB_RET_STALL;
         return;
@@ -124,8 +130,8 @@
     index   = (s->setup_buf[5] << 8) | s->setup_buf[4];
 
     if (s->setup_buf[0] & USB_DIR_IN) {
-//        usb_device_handle_control(s, p, request, value, index,
-//                                  s->setup_len, s->data_buf);
+        usb_device_handle_control(s, p, request, value, index,
+                                  s->setup_len, s->data_buf);
         if (p->status == USB_RET_ASYNC) {
             s->setup_state = SETUP_STATE_SETUP;
         }
@@ -158,6 +164,8 @@
 {
     int request, value, index;
 
+    fprintf(usblog, "%s:%d s=%p p=%p\n",
+		__func__, __LINE__, s, p);
     assert(p->ep->nr == 0);
 
     request = (s->setup_buf[0] << 8) | s->setup_buf[1];
@@ -166,9 +174,11 @@
  
     switch(s->setup_state) {
     case SETUP_STATE_ACK:
+        fprintf(usblog, "%s:%d setup_state=SETUP_STATE_ACK\n",
+		 __func__, __LINE__);
         if (!(s->setup_buf[0] & USB_DIR_IN)) {
-//            usb_device_handle_control(s, p, request, value, index,
-//                                      s->setup_len, s->data_buf);
+            usb_device_handle_control(s, p, request, value, index,
+                                      s->setup_len, s->data_buf);
             if (p->status == USB_RET_ASYNC) {
                 return;
             }
@@ -178,6 +188,8 @@
         break;
 
     case SETUP_STATE_DATA:
+        fprintf(usblog, "%s:%d setup_state=SETUP_STATE_DATA\n",
+		__func__, __LINE__);
         if (s->setup_buf[0] & USB_DIR_IN) {
             int len = s->setup_len - s->setup_index;
             if (len > p->iov.size) {
@@ -195,6 +207,8 @@
         break;
 
     default:
+        fprintf(usblog, "%s:%d setup_state=default\n",
+		__func__, __LINE__);
         p->status = USB_RET_STALL;
     }
 }
@@ -203,8 +217,12 @@
 {
     assert(p->ep->nr == 0);
 
+    fprintf(usblog, "%s:%d s=%p p=%p\n",
+		__func__, __LINE__, s, p);
     switch(s->setup_state) {
     case SETUP_STATE_ACK:
+        fprintf(usblog, "%s:%d setup_state=SETUP_STATE_ACK\n",
+		 __func__, __LINE__);
         if (s->setup_buf[0] & USB_DIR_IN) {
             s->setup_state = SETUP_STATE_IDLE;
             /* transfer OK */
@@ -214,6 +232,8 @@
         break;
 
     case SETUP_STATE_DATA:
+        fprintf(usblog, "%s:%d setup_state=SETUP_STATE_DATA\n",
+		 __func__, __LINE__);
         if (!(s->setup_buf[0] & USB_DIR_IN)) {
             int len = s->setup_len - s->setup_index;
             if (len > p->iov.size) {
@@ -231,6 +251,8 @@
         break;
 
     default:
+        fprintf(usblog, "%s:%d setup_state=default\n",
+		__func__, __LINE__);
         p->status = USB_RET_STALL;
     }
 }
@@ -239,6 +261,8 @@
 {
     int i, request, value, index;
 
+//    fprintf(usblog, "%s:%d s=%p p=%p\n",
+//		__func__, __LINE__, s, p);
     for (i = 0; i < 8; i++) {
         s->setup_buf[i] = p->parameter >> (i*8);
     }
@@ -263,8 +287,8 @@
         usb_packet_copy(p, s->data_buf, s->setup_len);
     }
 
-//    usb_device_handle_control(s, p, request, value, index,
-//                              s->setup_len, s->data_buf);
+    usb_device_handle_control(s, p, request, value, index,
+                              s->setup_len, s->data_buf);
     if (p->status == USB_RET_ASYNC) {
         return;
     }
@@ -288,6 +312,8 @@
         s->setup_state = SETUP_STATE_IDLE;
     }
 
+//    fprintf(usblog, "%s:%d s=%p p=%p\n",
+//		__func__, __LINE__, s, p);
     switch (s->setup_state) {
     case SETUP_STATE_SETUP:
         if (p->actual_length < s->setup_len) {
@@ -340,20 +366,23 @@
 {
     USBDevice *dev = port->dev;
 
+//    fprintf(usblog, "%s:%d port=%p addr=%x\n",
+//		__func__, __LINE__, port, addr);
     if (dev == NULL || !dev->attached || dev->state != USB_STATE_DEFAULT) {
         return NULL;
     }
     if (dev->addr == addr) {
         return dev;
     }
-//    return usb_device_find_device(dev, addr);
-    return 0;
+    return usb_device_find_device(dev, addr);
 }
 
 static void usb_process_one(USBPacket *p)
 {
     USBDevice *dev = p->ep->dev;
 
+    fprintf(usblog, "%s:%d p=%p dev=%p\n",
+		__func__, __LINE__, p, dev);
     /*
      * Handlers expect status to be initialized to USB_RET_SUCCESS, but it
      * can be USB_RET_NAK here from a previous usb_process_one() call,
@@ -369,25 +398,37 @@
         }
         switch (p->pid) {
         case USB_TOKEN_SETUP:
+            fprintf(usblog, "%s:%d pid=USB_TOKEN_SETUP\n",
+		__func__, __LINE__);
             do_token_setup(dev, p);
             break;
         case USB_TOKEN_IN:
+            fprintf(usblog, "%s:%d pid=USB_TOKEN_IN\n",
+		__func__, __LINE__);
             do_token_in(dev, p);
             break;
         case USB_TOKEN_OUT:
+            fprintf(usblog, "%s:%d pid=USB_TOKEN_OUT\n",
+		__func__, __LINE__);
             do_token_out(dev, p);
             break;
         default:
+            fprintf(usblog, "%s:%d pid=default\n",
+		__func__, __LINE__);
             p->status = USB_RET_STALL;
         }
     } else {
+        fprintf(usblog, "%s:%d nr != 0\n",
+	    __func__, __LINE__);
         /* data pipe */
-//        usb_device_handle_data(dev, p);
+        usb_device_handle_data(dev, p);
     }
 }
 
 static void usb_queue_one(USBPacket *p)
 {
+//    fprintf(usblog, "%s:%d p=%p\n",
+//		__func__, __LINE__, p);
     usb_packet_set_state(p, USB_PACKET_QUEUED);
     QTAILQ_INSERT_TAIL(&p->ep->queue, p, queue);
     p->status = USB_RET_ASYNC;
@@ -398,6 +439,8 @@
    driver will call usb_packet_complete() when done processing it. */
 void usb_handle_packet(USBDevice *dev, USBPacket *p)
 {
+    fprintf(usblog, "%s:%d dev=%p p=%p\n",
+		__func__, __LINE__, dev, p);
     if (dev == NULL) {
         p->status = USB_RET_NODEV;
         return;
@@ -444,6 +487,8 @@
 {
     USBEndpoint *ep = p->ep;
 
+//    fprintf(usblog, "%s:%d dev=%p p=%p ep=%p\n",
+//		__func__, __LINE__, dev, p, ep);
     assert(QTAILQ_FIRST(&ep->queue) == p);
     assert(p->status != USB_RET_ASYNC && p->status != USB_RET_NAK);
 
@@ -463,6 +508,8 @@
 {
     USBEndpoint *ep = p->ep;
 
+//    fprintf(usblog, "%s:%d dev=%p p=%p ep=%p\n",
+//		__func__, __LINE__, dev, p, ep);
     usb_packet_check_state(p, USB_PACKET_ASYNC);
     usb_packet_complete_one(dev, p);
 
@@ -493,20 +540,20 @@
 void usb_cancel_packet(USBPacket * p)
 {
     bool callback = (p->state == USB_PACKET_ASYNC);
+//    fprintf(usblog, "%s:%d p=%p callback=%d\n",
+//		__func__, __LINE__, p, callback);
     assert(usb_packet_is_inflight(p));
     usb_packet_set_state(p, USB_PACKET_CANCELED);
     QTAILQ_REMOVE(&p->ep->queue, p, queue);
     if (callback) {
-//        usb_device_cancel_packet(p->ep->dev, p);
+        usb_device_cancel_packet(p->ep->dev, p);
     }
 }
 
 
 void usb_packet_init(USBPacket *p)
 {
-	p->iov.iov = (struct iovec *)calloc(sizeof(struct iovec), 1);
-	p->iov.niov = p->iov.size = 0;
-	p->iov.nalloc = 1;
+    qemu_iovec_init(&p->iov, 1);
 }
 
 static const char *usb_packet_state_name(USBPacketState state)
@@ -543,6 +590,8 @@
 
 void usb_packet_set_state(USBPacket *p, USBPacketState state)
 {
+//    fprintf(usblog, "%s:%d p=%p state=%d\n",
+//		__func__, __LINE__, p, state);
     if (p->ep) {
         USBDevice *dev = p->ep->dev;
         USBBus *bus = usb_bus_from_device(dev);
@@ -561,6 +610,8 @@
                       USBEndpoint *ep, unsigned int stream,
                       uint64_t id, bool short_not_ok, bool int_req)
 {
+//    fprintf(usblog, "%s:%d p=%p pid=%d ep=%p stream=%x id=%lx short_not_ok=%d int_req=%d\n",
+//		__func__, __LINE__, p, pid, ep, stream, id, short_not_ok, int_req);
     assert(!usb_packet_is_inflight(p));
     assert(p->iov.iov != NULL);
     p->id = id;
@@ -573,39 +624,37 @@
     p->short_not_ok = short_not_ok;
     p->int_req = int_req;
     p->combined = NULL;
-    assert(p->iov.nalloc != -1);
-    p->iov.niov = 0;
-    p->iov.size = 0;
+    qemu_iovec_reset(&p->iov);
     usb_packet_set_state(p, USB_PACKET_SETUP);
 }
 
 void usb_packet_addbuf(USBPacket *p, void *ptr, size_t len)
 {
-	assert(p->iov.nalloc != -1);
-
-	if (p->iov.niov == p->iov.nalloc) {
-		p->iov.nalloc = 2 * p->iov.nalloc + 1;
-		p->iov.iov = (struct iovec *)realloc(p->iov.iov, sizeof(struct iovec) * p->iov.nalloc);
-	}
-	p->iov.iov[p->iov.niov].iov_base = ptr;
-	p->iov.iov[p->iov.niov].iov_len = len;
-	p->iov.size += len;
-	++p->iov.niov;
+//   fprintf(usblog, "%s:%d p=%p ptr=%p len=%zu\n",
+//	__func__, __LINE__, p, ptr, len);
+    qemu_iovec_add(&p->iov, ptr, len);
 }
 
 void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes)
 {
     IOVector *iov = p->combined ? &p->combined->iov : &p->iov;
+//    fprintf(usblog, "%s:%d p=%p ptr=%p bytes=%zu\n",
+//		__func__, __LINE__, p, ptr, bytes);
 
     assert(p->actual_length >= 0);
     assert(p->actual_length + bytes <= iov->size);
     switch (p->pid) {
     case USB_TOKEN_SETUP:
     case USB_TOKEN_OUT:
-//        iov_to_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes);
+//	fprintf(usblog, "%s:%d pid:%s\n", 
+//		__func__, __LINE__,
+//		p->pid == USB_TOKEN_SETUP ? "USB_TOKEN_SETUP" : "USB_TOKEN_OUT");
+        iov_to_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes);
         break;
     case USB_TOKEN_IN:
-//        iov_from_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes);
+//	fprintf(usblog, "%s:%d pid:USB_TOKEN_IN\n", 
+//		__func__, __LINE__);
+        iov_from_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes);
         break;
     default:
         fprintf(stderr, "%s: invalid pid: %x\n", __func__, p->pid);
@@ -617,34 +666,37 @@
 void usb_packet_skip(USBPacket *p, size_t bytes)
 {
     IOVector *iov = p->combined ? &p->combined->iov : &p->iov;
+//    fprintf(usblog, "%s:%d p=%p bytes=%zu\n",
+//		__func__, __LINE__, p, bytes);
 
     assert(p->actual_length >= 0);
     assert(p->actual_length + bytes <= iov->size);
     if (p->pid == USB_TOKEN_IN) {
-//        iov_memset(iov->iov, iov->niov, p->actual_length, 0, bytes);
+        iov_memset(iov->iov, iov->niov, p->actual_length, 0, bytes);
     }
     p->actual_length += bytes;
 }
 
 size_t usb_packet_size(USBPacket *p)
 {
+//    fprintf(usblog, "%s:%d p=%p\n",
+//		__func__, __LINE__, p);
     return p->combined ? p->combined->iov.size : p->iov.size;
 }
 
 void usb_packet_cleanup(USBPacket *p)
 {
-    assert(!usb_packet_is_inflight(p));
-    assert(p->iov.nalloc != -1);
-
-    free(p->iov.iov);
-    p->iov.size = p->iov.niov = p->iov.nalloc = 0;
-    p->iov.iov = NULL;
+//    fprintf(usblog, "%s:%d p=%p\n",
+//		__func__, __LINE__, p);
+    qemu_iovec_destroy(&p->iov);
 }
 
 void usb_ep_reset(USBDevice *dev)
 {
     int ep;
 
+//    fprintf(usblog, "%s:%d dev=%p\n",
+//		__func__, __LINE__, dev);
     dev->ep_ctl.nr = 0;
     dev->ep_ctl.type = USB_ENDPOINT_XFER_CONTROL;
     dev->ep_ctl.ifnum = 0;
@@ -670,6 +722,8 @@
 {
     int ep;
 
+//    fprintf(usblog, "%s:%d dev=%p\n",
+//		__func__, __LINE__, dev);
     usb_ep_reset(dev);
     QTAILQ_INIT(&dev->ep_ctl.queue);
     for (ep = 0; ep < USB_MAX_ENDPOINTS; ep++) {
@@ -724,6 +778,8 @@
 {
     struct USBEndpoint *eps;
 
+//    fprintf(usblog, "%s:%d dev=%p pid=%d ep=%d\n",
+//		__func__, __LINE__, dev, pid, ep);
     if (dev == NULL) {
         return NULL;
     }

Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c
==============================================================================
--- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c	Mon Sep 16 02:01:36 2013	(r257394)
+++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c	Mon Sep 16 06:39:34 2013	(r257395)
@@ -22,19 +22,13 @@
  * THE SOFTWARE.
  */
 //#include "qemu-common.h"
-//#include "trace.h"
+#include "trace.h"
 #include "hw/usb.h"
 #include "usb/gpl/desc.h"
 //#include "qemu/error-report.h"
 #include <string.h>
 
-#define trace_usb_hub_attach(a,b)
-#define trace_usb_hub_detach(a,b)
-#define trace_usb_hub_reset(a)
-#define trace_usb_hub_control(a,b,c,d,e)
-#define trace_usb_hub_get_port_status(a,b,c,d)
-#define trace_usb_hub_set_port_feature(a,b,c)
-#define trace_usb_hub_clear_port_feature(a,b,c)
+extern FILE *usblog;
 
 #if 0
 #define NUM_PORTS 8
@@ -222,6 +216,8 @@
 static void usb_hub_complete(USBPort *port, USBPacket *packet)
 {
     USBHubState *s = port->opaque;
+//    fprintf(usblog, "%s:%d port=%p packet=%p\n",
+//		__func__, __LINE__, port, packet);
 
     /*
      * Just pass it along upstream for now.
@@ -243,6 +239,8 @@
     USBDevice *downstream;
     int i;
 
+//    fprintf(usblog, "%s:%d dev=%p addr=%x\n",
+//		__func__, __LINE__, dev, addr);
     for (i = 0; i < NUM_PORTS; i++) {
         port = &s->ports[i];
         if (!(port->wPortStatus & PORT_STAT_ENABLE)) {

Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c
==============================================================================
--- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c	Mon Sep 16 02:01:36 2013	(r257394)
+++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c	Mon Sep 16 06:39:34 2013	(r257395)
@@ -6,12 +6,7 @@
 //#include "hw/qdev.h"
 //#include "sysemu/sysemu.h"
 //#include "monitor/monitor.h"
-//#include "trace.h"
-
-#define trace_usb_port_claim(a, b)
-#define trace_usb_port_attach(a,b,c,d)
-#define trace_usb_port_detach(a,b)
-#define trace_usb_port_release(a,b)
+#include "trace.h"
 
 void pstrcpy(char *buf, int buf_size, const char *str)
 {
@@ -128,35 +123,40 @@
 static int usb_device_init(USBDevice *dev)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p klass=%p\n",
+//		__func__, __LINE__, dev, klass);
     if (klass->init) {
         return klass->init(dev);
     }
     return 0;
 }
 
-#if 0
 USBDevice *usb_device_find_device(USBDevice *dev, uint8_t addr)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p addr=%x klass=%p\n",
+//		__func__, __LINE__, dev, addr, klass);
     if (klass->find_device) {
         return klass->find_device(dev, addr);
     }
     return NULL;
 }
-#endif
 
 static void usb_device_handle_destroy(USBDevice *dev)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p klass=%p\n",
+//		__func__, __LINE__, dev, klass);
     if (klass->handle_destroy) {
         klass->handle_destroy(dev);
     }
 }
 
-#if 0
 void usb_device_cancel_packet(USBDevice *dev, USBPacket *p)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p p=%p klass=%p\n",
+//		__func__, __LINE__, dev, p, klass);
     if (klass->cancel_packet) {
         klass->cancel_packet(dev, p);
     }
@@ -165,6 +165,8 @@
 void usb_device_handle_attach(USBDevice *dev)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p klass=%p\n",
+//		__func__, __LINE__, dev, klass);
     if (klass->handle_attach) {
         klass->handle_attach(dev);
     }
@@ -173,6 +175,8 @@
 void usb_device_handle_reset(USBDevice *dev)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p klass=%p\n",
+//		__func__, __LINE__, dev, klass);
     if (klass->handle_reset) {
         klass->handle_reset(dev);
     }
@@ -182,6 +186,8 @@
                                int value, int index, int length, uint8_t *data)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p p=%p request=%d value=%d index=%d length=%d data=%p klass=%p\n",
+//		__func__, __LINE__, dev, p, request, value, index, length, data, klass);
     if (klass->handle_control) {
         klass->handle_control(dev, p, request, value, index, length, data);
     }
@@ -190,21 +196,26 @@
 void usb_device_handle_data(USBDevice *dev, USBPacket *p)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p p=%p klass=%p\n",
+//		__func__, __LINE__, dev, p, klass);
     if (klass->handle_data) {
         klass->handle_data(dev, p);
     }
 }
-#endif
 
 const char *usb_device_get_product_desc(USBDevice *dev)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p klass=%p\n",
+//		__func__, __LINE__, dev, klass);
     return klass->product_desc;
 }
 
 const USBDesc *usb_device_get_usb_desc(USBDevice *dev)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p klass=%p\n",
+//		__func__, __LINE__, dev, klass);
     if (dev->usb_desc) {
         return dev->usb_desc;
     }
@@ -225,6 +236,8 @@
 void usb_device_flush_ep_queue(USBDevice *dev, USBEndpoint *ep)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p ep=%p klass=%p\n",
+//		__func__, __LINE__, dev, ep, klass);
     if (klass->flush_ep_queue) {
         klass->flush_ep_queue(dev, ep);
     }
@@ -233,6 +246,8 @@
 void usb_device_ep_stopped(USBDevice *dev, USBEndpoint *ep)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+//    fprintf(usblog, "%s:%d dev=%p ep=%p klass=%p\n",
+//		__func__, __LINE__, dev, ep, klass);
     if (klass->ep_stopped) {
         klass->ep_stopped(dev, ep);
     }
@@ -348,6 +363,8 @@
     USBBus *bus;
     int i;
 
+//    fprintf(usblog, "%s:%d masterbus:%s ports:%p portcount:%d firstport:%d opaqueue:%p ops:%p speedmask:%x\n",
+//		__func__, __LINE__, masterbus, ports, portcount, firstport, opaque, ops, speedmask);
     QTAILQ_FOREACH(bus, &busses, next) {
         if (strcmp(bus->name, masterbus) == 0) {
             break;
@@ -374,6 +391,8 @@
 
 void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
 {
+//    fprintf(usblog, "%s:%d downstream:%p upstream:%p portnr:%d\n",
+//		__func__, __LINE__, downstream, upstream, portnr);
     if (upstream) {
         snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
                  upstream->path, portnr);
@@ -505,7 +524,7 @@
 
 int usb_device_detach(USBDevice *dev)
 {
-//    USBBus *bus = usb_bus_from_device(dev);
+    USBBus *bus = usb_bus_from_device(dev);
     USBPort *port = dev->port;
 
     assert(port != NULL);

Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.c
==============================================================================
--- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.c	Mon Sep 16 02:01:36 2013	(r257394)
+++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.c	Mon Sep 16 06:39:34 2013	(r257395)
@@ -5,18 +5,7 @@
 
 #include "hw/usb.h"
 #include "desc.h"
-
-#define trace_usb_desc_device(a,b,c)
-#define trace_usb_desc_config(a,b,c,d)
-#define trace_usb_desc_string(a,b,c,d)
-#define trace_usb_desc_device_qualifier(a,b,c)
-#define trace_usb_desc_other_speed_config(a,b,c,d)
-#define trace_usb_set_addr(a)
-#define trace_usb_set_config(a,b,c)
-#define trace_usb_clear_device_feature(a,b,c)
-#define trace_usb_set_device_feature(a,b,c)
-#define trace_usb_set_interface(a,b,c,d)
-#define trace_usb_desc_bos(a,b,c)
+#include "trace.h"
 
 void usb_device_set_interface(USBDevice *dev, int interface,
                               int alt_old, int alt_new)

Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c
==============================================================================
--- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c	Mon Sep 16 02:01:36 2013	(r257394)
+++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c	Mon Sep 16 06:39:34 2013	(r257395)
@@ -39,11 +39,12 @@
 }
 
 
-//#define DEBUG_Serial
+#define DEBUG_Serial
 
 #ifdef DEBUG_Serial
+extern FILE *usblog;
 #define DPRINTF(fmt, ...) \
-do { printf("usb-serial: " fmt , ## __VA_ARGS__); } while (0)
+do { fprintf(usblog, "usb-serial: " fmt , ## __VA_ARGS__); } while (0)
 #else
 #define DPRINTF(fmt, ...) do {} while(0)
 #endif

Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/hexdump.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/hexdump.c	Mon Sep 16 06:39:34 2013	(r257395)
@@ -0,0 +1,37 @@
+/*
+ * Helper to hexdump a buffer
+ *
+ * Copyright (c) 2013 Red Hat, Inc.
+ * Copyright (c) 2013 Gerd Hoffmann <kraxel@redhat.com>
+ * Copyright (c) 2013 Peter Crosthwaite <peter.crosthwaite@xilinx.com>
+ * Copyright (c) 2013 Xilinx, Inc
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#include <stdio.h>
+
+void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
+{
+    unsigned int b;
+
+    for (b = 0; b < size; b++) {
+        if ((b % 16) == 0) {
+            fprintf(fp, "%s: %04x:", prefix, b);
+        }
+        if ((b % 4) == 0) {
+            fprintf(fp, " ");
+        }
+        fprintf(fp, " %02x", (unsigned char)buf[b]);
+        if ((b % 16) == 15) {
+            fprintf(fp, "\n");
+        }
+    }
+    if ((b % 16) != 0) {
+        fprintf(fp, "\n");
+    }
+}

Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/iov.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/iov.c	Mon Sep 16 06:39:34 2013	(r257395)
@@ -0,0 +1,439 @@
+/*
+ * Helpers for getting linearized buffers from iov / filling buffers into iovs
+ *
+ * Copyright IBM, Corp. 2007, 2008
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * Author(s):
+ *  Anthony Liguori <aliguori@us.ibm.com>
+ *  Amit Shah <amit.shah@redhat.com>
+ *  Michael Tokarev <mjt@tls.msk.ru>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#include "usb/gpl/iov.h"
+#include "hw/usb.h"
+
+#ifdef _WIN32
+# include <windows.h>
+# include <winsock2.h>
+#else
+# include <sys/types.h>
+# include <sys/socket.h>
+#endif
+#include <errno.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <malloc_np.h>
+#include <sys/param.h>
+
+size_t iov_from_buf(const struct iovec *iov, unsigned int iov_cnt,
+                    size_t offset, const void *buf, size_t bytes)
+{
+    size_t done;
+    unsigned int i;
+    for (i = 0, done = 0; (offset || done < bytes) && i < iov_cnt; i++) {
+        if (offset < iov[i].iov_len) {
+            size_t len = MIN(iov[i].iov_len - offset, bytes - done);
+            memcpy(iov[i].iov_base + offset, buf + done, len);
+            done += len;
+            offset = 0;
+        } else {
+            offset -= iov[i].iov_len;
+        }
+    }
+    assert(offset == 0);
+    return done;
+}
+
+size_t iov_to_buf(const struct iovec *iov, const unsigned int iov_cnt,
+                  size_t offset, void *buf, size_t bytes)
+{
+    size_t done;
+    unsigned int i;
+    for (i = 0, done = 0; (offset || done < bytes) && i < iov_cnt; i++) {
+        if (offset < iov[i].iov_len) {
+            size_t len = MIN(iov[i].iov_len - offset, bytes - done);
+            memcpy(buf + done, iov[i].iov_base + offset, len);
+            done += len;
+            offset = 0;
+        } else {
+            offset -= iov[i].iov_len;
+        }
+    }
+    assert(offset == 0);
+    return done;
+}
+
+size_t iov_memset(const struct iovec *iov, const unsigned int iov_cnt,
+                  size_t offset, int fillc, size_t bytes)
+{
+    size_t done;
+    unsigned int i;
+    for (i = 0, done = 0; (offset || done < bytes) && i < iov_cnt; i++) {
+        if (offset < iov[i].iov_len) {
+            size_t len = MIN(iov[i].iov_len - offset, bytes - done);
+            memset(iov[i].iov_base + offset, fillc, len);
+            done += len;
+            offset = 0;
+        } else {
+            offset -= iov[i].iov_len;
+        }
+    }
+    assert(offset == 0);
+    return done;
+}
+
+size_t iov_size(const struct iovec *iov, const unsigned int iov_cnt)
+{
+    size_t len;
+    unsigned int i;
+
+    len = 0;
+    for (i = 0; i < iov_cnt; i++) {
+        len += iov[i].iov_len;
+    }
+    return len;
+}
+
+/* helper function for iov_send_recv() */
+static ssize_t
+do_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, bool do_send)
+{
+#ifdef CONFIG_POSIX
+    ssize_t ret;
+    struct msghdr msg;
+    memset(&msg, 0, sizeof(msg));
+    msg.msg_iov = iov;
+    msg.msg_iovlen = iov_cnt;
+    do {
+        ret = do_send
+            ? sendmsg(sockfd, &msg, 0)
+            : recvmsg(sockfd, &msg, 0);
+    } while (ret < 0 && errno == EINTR);
+    return ret;
+#else
+    /* else send piece-by-piece */
+    /*XXX Note: windows has WSASend() and WSARecv() */
+    unsigned i = 0;
+    ssize_t ret = 0;
+    while (i < iov_cnt) {
+        ssize_t r = do_send
+            ? send(sockfd, iov[i].iov_base, iov[i].iov_len, 0)
+            : recv(sockfd, iov[i].iov_base, iov[i].iov_len, 0);
+        if (r > 0) {
+            ret += r;
+        } else if (!r) {
+            break;
+        } else if (errno == EINTR) {
+            continue;
+        } else {
+            /* else it is some "other" error,
+             * only return if there was no data processed. */
+            if (ret == 0) {
+                ret = -1;
+            }
+            break;
+        }
+        i++;
+    }
+    return ret;
+#endif
+}
+
+ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
+                      size_t offset, size_t bytes,
+                      bool do_send)
+{
+    ssize_t total = 0;
+    ssize_t ret;
+    size_t orig_len, tail;
+    unsigned niov;
+
+    while (bytes > 0) {
+        /* Find the start position, skipping `offset' bytes:
+         * first, skip all full-sized vector elements, */
+        for (niov = 0; niov < iov_cnt && offset >= iov[niov].iov_len; ++niov) {
+            offset -= iov[niov].iov_len;
+        }
+
+        /* niov == iov_cnt would only be valid if bytes == 0, which
+         * we already ruled out in the loop condition.  */
+        assert(niov < iov_cnt);
+        iov += niov;
+        iov_cnt -= niov;
+
+        if (offset) {
+            /* second, skip `offset' bytes from the (now) first element,
+             * undo it on exit */
+            iov[0].iov_base += offset;
+            iov[0].iov_len -= offset;
+        }
+        /* Find the end position skipping `bytes' bytes: */
+        /* first, skip all full-sized elements */
+        tail = bytes;
+        for (niov = 0; niov < iov_cnt && iov[niov].iov_len <= tail; ++niov) {
+            tail -= iov[niov].iov_len;
+        }
+        if (tail) {
+            /* second, fixup the last element, and remember the original
+             * length */
+            assert(niov < iov_cnt);
+            assert(iov[niov].iov_len > tail);
+            orig_len = iov[niov].iov_len;
+            iov[niov++].iov_len = tail;
+        }
+
+        ret = do_send_recv(sockfd, iov, niov, do_send);
+
+        /* Undo the changes above before checking for errors */
+        if (tail) {
+            iov[niov-1].iov_len = orig_len;
+        }
+        if (offset) {
+            iov[0].iov_base -= offset;
+            iov[0].iov_len += offset;
+        }
+
+        if (ret < 0) {
+            assert(errno != EINTR);
+            if (errno == EAGAIN && total > 0) {
+                return total;
+            }
+            return -1;
+        }
+
+        if (ret == 0 && !do_send) {
+            /* recv returns 0 when the peer has performed an orderly
+             * shutdown. */
+            break;
+        }
+
+        /* Prepare for the next iteration */
+        offset += ret;
+        total += ret;
+        bytes -= ret;
+    }
+
+    return total;
+}
+
+
+void iov_hexdump(const struct iovec *iov, const unsigned int iov_cnt,
+                 FILE *fp, const char *prefix, size_t limit)
+{
+    int v;
+    size_t size = 0;
+    char *buf;
+
+    for (v = 0; v < iov_cnt; v++) {
+        size += iov[v].iov_len;
+    }
+    size = size > limit ? limit : size;
+    buf = malloc(size);
+    iov_to_buf(iov, iov_cnt, 0, buf, size);
+    qemu_hexdump(buf, fp, prefix, size);
+    free(buf);
+}
+
+unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt,
+                 const struct iovec *iov, unsigned int iov_cnt,
+                 size_t offset, size_t bytes)
+{
+    size_t len;
+    unsigned int i, j;
+    for (i = 0, j = 0; i < iov_cnt && j < dst_iov_cnt && bytes; i++) {
+        if (offset >= iov[i].iov_len) {
+            offset -= iov[i].iov_len;
+            continue;
+        }
+        len = MIN(bytes, iov[i].iov_len - offset);
+
+        dst_iov[j].iov_base = iov[i].iov_base + offset;
+        dst_iov[j].iov_len = len;
+        j++;

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201309160639.r8G6dYPI041742>