Date: Thu, 12 Sep 2013 08:06:19 GMT From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r257234 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb: . gpl include/hw Message-ID: <201309120806.r8C86JLw083964@socsvn.freebsd.org>
index | next in thread | raw e-mail
Author: syuu Date: Thu Sep 12 08:06:19 2013 New Revision: 257234 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257234 Log: USBBus handling fix, initializer for dev-hub Modified: 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/include/hw/usb.h Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c Thu Sep 12 02:31:32 2013 (r257233) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c Thu Sep 12 08:06:19 2013 (r257234) @@ -605,3 +605,21 @@ type_init(usb_hub_register_types) */ + +USBDevice *usb_hub_init(USBBus *bus) +{ + USBDevice *dev; + char label[32]; + static int index; + + snprintf(label, sizeof(label), "usbhub%d", index++); + + dev = usb_create(bus, "usb-hub", sizeof(USBHubState)); + if (!dev) { + return NULL; + } + + return dev; +} + + Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c Thu Sep 12 02:31:32 2013 (r257233) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c Thu Sep 12 08:06:19 2013 (r257234) @@ -10,6 +10,8 @@ #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) void pstrcpy(char *buf, int buf_size, const char *str) { @@ -192,6 +194,7 @@ klass->handle_data(dev, p); } } +#endif const char *usb_device_get_product_desc(USBDevice *dev) { @@ -208,6 +211,7 @@ return klass->usb_desc; } +#if 0 void usb_device_set_interface(USBDevice *dev, int interface, int alt_old, int alt_new) { @@ -234,7 +238,7 @@ } } -static int usb_qdev_init(USBDevice *dev) +int usb_qdev_init(USBDevice *dev) { int rc; @@ -303,6 +307,7 @@ USBDevice *dev; dev = (USBDevice *)calloc(1, len); + dev->bus = bus; strncpy(dev->name, name, sizeof(dev->name)); return dev; } @@ -430,7 +435,6 @@ return 0; } -#if 0 void usb_release_port(USBDevice *dev) { USBBus *bus = usb_bus_from_device(dev); @@ -448,7 +452,6 @@ QTAILQ_INSERT_TAIL(&bus->free, port, next); bus->nfree++; } -#endif static void usb_mask_to_str(char *dest, size_t size, unsigned int speedmask) @@ -500,10 +503,9 @@ return 0; } -#if 0 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); @@ -515,6 +517,7 @@ return 0; } +#if 0 int usb_device_delete_addr(int busnr, int addr) { USBBus *bus; Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.c Thu Sep 12 02:31:32 2013 (r257233) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.c Thu Sep 12 08:06:19 2013 (r257234) @@ -18,11 +18,6 @@ #define trace_usb_set_interface(a,b,c,d) #define trace_usb_desc_bos(a,b,c) -const USBDesc *usb_device_get_usb_desc(USBDevice *dev) -{ - return NULL; -} - void usb_device_set_interface(USBDevice *dev, int interface, int alt_old, int alt_new) { @@ -587,9 +582,9 @@ // DeviceState *hcd = dev->qdev.parent_bus->parent; const USBDesc *desc = usb_device_get_usb_desc(dev); int index = desc->id.iSerialNumber; - char serial[64]; - char *path = NULL; - int dst; +// char serial[64]; +// char *path = NULL; +// int dst; if (dev->serial) { /* 'serial' usb bus property has priority if present */ @@ -598,6 +593,7 @@ } assert(index != 0 && desc->str[index] != NULL); +#if 0 dst = snprintf(serial, sizeof(serial), "%s", desc->str[index]); // path = qdev_get_dev_path(hcd); if (path) { @@ -605,6 +601,7 @@ } dst += snprintf(serial+dst, sizeof(serial)-dst, "-%s", dev->port->path); usb_desc_set_string(dev, index, serial); +#endif } const char *usb_desc_get_string(USBDevice *dev, uint8_t index) 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 Thu Sep 12 02:31:32 2013 (r257233) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c Thu Sep 12 08:06:19 2013 (r257234) @@ -498,7 +498,7 @@ } } -int usb_serial_initfn(USBDevice *dev) +static int usb_serial_initfn(USBDevice *dev) { USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev); @@ -611,7 +611,7 @@ }; #endif -static void usb_serial_class_initfn(USBDeviceClass *uc, void *data) +void usb_serial_class_initfn(USBDeviceClass *uc, void *data) { uc->init = usb_serial_initfn; uc->product_desc = "QEMU USB Serial"; Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Thu Sep 12 02:31:32 2013 (r257233) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Thu Sep 12 08:06:19 2013 (r257234) @@ -361,6 +361,8 @@ struct timespec ts; ts.tv_sec = ns / SECINNS; ts.tv_nsec = ns % SECINNS; + fprintf(usblog, "%s:%d tv_sec:%lu tv_nsec:%lu\n", + __func__, __LINE__, ts.tv_sec, ts.tv_nsec); return ts; } @@ -397,7 +399,8 @@ timer->se.sigev_notify_function = timer_handler; timer->func = func; timer->arg = arg; - if (timer_create(CLOCK_REALTIME, &timer->se, &timer->timerid)) { + fprintf(usblog, "%s:%d timer:%p\n", __func__, __LINE__, timer); + if (timer_create(CLOCK_MONOTONIC, &timer->se, &timer->timerid)) { perror("timer_create"); exit(1); } @@ -408,6 +411,7 @@ { struct itimerspec its; + fprintf(usblog, "%s:%d timer:%p ns:%ld\n", __func__, __LINE__, timer, ns); its.it_value = its.it_interval = ns_to_timerspec(ns); timer_settime(timer->timerid, 0, &its, 0); } @@ -418,6 +422,7 @@ memset(&its, 0, sizeof(its)); timer_settime(timer->timerid, 0, &its, 0); + fprintf(usblog, "%s:%d timer:%p\n", __func__, __LINE__, timer); } static inline int32_t uhci_queue_token(UHCI_TD *td) @@ -667,6 +672,7 @@ if (version_id < 2) { s->expire_time = get_clock_ns() + (get_ticks_per_sec() / FRAME_TIMER_FREQ); + fprintf(usblog, "%s s->expire_time:%ld\n", __func__, s->expire_time); } return 0; } @@ -713,7 +719,9 @@ trace_usb_uhci_schedule_start(); s->expire_time = get_clock_ns() + (get_ticks_per_sec() / FRAME_TIMER_FREQ); - mod_timer(s->frame_timer, s->expire_time); + fprintf(usblog, "%s s->expire_time:%ld\n", __func__, s->expire_time); +// mod_timer(s->frame_timer, s->expire_time); + mod_timer(s->frame_timer, get_ticks_per_sec() / FRAME_TIMER_FREQ); s->status &= ~UHCI_STS_HCHALTED; fprintf(usblog, "%s status &= ~UHCI_STS_HCHALTED\n", __func__); fprintf(usblog, "%s status = %x\n", __func__, s->status); @@ -975,28 +983,41 @@ switch (status) { case USB_RET_NAK: + fprintf(usblog, "%s:%d USB_RET_NAK\n", __func__, __LINE__); td->ctrl |= TD_CTRL_NAK; + fprintf(usblog, "%s:%d TD_RESULT_NEXT_QH\n", __func__, __LINE__); return TD_RESULT_NEXT_QH; case USB_RET_STALL: + fprintf(usblog, "%s:%d USB_RET_STALL\n", __func__, __LINE__); td->ctrl |= TD_CTRL_STALL; trace_usb_uhci_packet_complete_stall(queue_token, td_addr); + fprintf(usblog, "%s:%d TD_RESULT_NEXT_QH\n", __func__, __LINE__); ret = TD_RESULT_NEXT_QH; break; case USB_RET_BABBLE: + fprintf(usblog, "%s:%d USB_RET_BABBLE\n", __func__, __LINE__); td->ctrl |= TD_CTRL_BABBLE | TD_CTRL_STALL; /* frame interrupted */ trace_usb_uhci_packet_complete_babble(queue_token, td_addr); + fprintf(usblog, "%s:%d TD_RESULT_STOP_FRAME\n", __func__, __LINE__); ret = TD_RESULT_STOP_FRAME; break; case USB_RET_IOERROR: case USB_RET_NODEV: default: + if (status == USB_RET_IOERROR) + fprintf(usblog, "%s:%d USB_RET_IOERROR\n", __func__, __LINE__); + else if (status == USB_RET_NODEV) + fprintf(usblog, "%s:%d USB_RET_NODEV\n", __func__, __LINE__); + else + fprintf(usblog, "%s:%d invalid\n", __func__, __LINE__); td->ctrl |= TD_CTRL_TIMEOUT; td->ctrl &= ~(3 << TD_CTRL_ERROR_SHIFT); trace_usb_uhci_packet_complete_error(queue_token, td_addr); + fprintf(usblog, "%s:%d TD_RESULT_NEXT_QH\n", __func__, __LINE__); ret = TD_RESULT_NEXT_QH; break; } @@ -1045,6 +1066,7 @@ /* short packet: do not update QH */ trace_usb_uhci_packet_complete_shortxfer(async->queue->token, async->td_addr); + fprintf(usblog, "%s:%d TD_RESULT_NEXT_QH\n", __func__, __LINE__); return TD_RESULT_NEXT_QH; } } @@ -1052,6 +1074,7 @@ /* success */ trace_usb_uhci_packet_complete_success(async->queue->token, async->td_addr); + fprintf(usblog, "%s:%d TD_RESULT_COMPLETE\n", __func__, __LINE__); return TD_RESULT_COMPLETE; } @@ -1099,6 +1122,7 @@ if (td->ctrl & TD_CTRL_IOC) { *int_mask |= 0x01; } + fprintf(usblog, "%s:%d TD_RESULT_NEXT_QH\n", __func__, __LINE__); return TD_RESULT_NEXT_QH; } @@ -1107,6 +1131,7 @@ /* we are busy filling the queue, we are not prepared to consume completed packages then, just leave them in async state */ + fprintf(usblog, "%s:%d TD_RESULT_ASYNC_CONT\n", __func__, __LINE__); return TD_RESULT_ASYNC_CONT; } if (!async->done) { @@ -1120,6 +1145,7 @@ uhci_read_td(s, &last_td, last->td_addr); uhci_queue_fill(async->queue, &last_td); + fprintf(usblog, "%s:%d TD_RESULT_ASYNC_CONT\n", __func__, __LINE__); return TD_RESULT_ASYNC_CONT; } uhci_async_unlink(async); @@ -1127,6 +1153,7 @@ } if (s->completions_only) { + fprintf(usblog, "%s:%d TD_RESULT_ASYNC_CONT\n", __func__, __LINE__); return TD_RESULT_ASYNC_CONT; } @@ -1157,6 +1184,7 @@ switch(pid) { case USB_TOKEN_OUT: case USB_TOKEN_SETUP: + fprintf(usblog, "%s:%d %s\n", __func__, __LINE__, pid == USB_TOKEN_OUT ? "USB_TOKEN_OUT" : "USB_TOKEN_SETUP"); pci_dma_read(STATE_TO_SC(s), td->buffer, async->buf, max_len); usb_handle_packet(q->ep->dev, &async->packet); if (async->packet.status == USB_RET_SUCCESS) { @@ -1165,16 +1193,19 @@ break; case USB_TOKEN_IN: + fprintf(usblog, "%s:%d USB_TOKEN_IN\n", __func__, __LINE__); usb_handle_packet(q->ep->dev, &async->packet); break; default: + fprintf(usblog, "%s:%d invalid\n", __func__, __LINE__); /* invalid pid : frame interrupted */ uhci_async_free(async); s->status |= UHCI_STS_HCPERR; fprintf(usblog, "%s s->status |= UHCI_STS_USBERR\n", __func__); fprintf(usblog, "%s s->status = %x\n", __func__, s->status); uhci_update_irq(s); + fprintf(usblog, "%s:%d TD_RESULT_STOP_FRAME\n", __func__, __LINE__); return TD_RESULT_STOP_FRAME; } @@ -1183,6 +1214,7 @@ if (!queuing) { uhci_queue_fill(q, td); } + fprintf(usblog, "%s:%d TD_RESULT_ASYNC_START\n", __func__, __LINE__); return TD_RESULT_ASYNC_START; } @@ -1287,6 +1319,7 @@ UHCI_QH qh; QhDb qhdb; + fprintf(usblog, "%s:%d s:%p\n", __func__, __LINE__, s); frame_addr = s->fl_base_addr + ((s->frnum & 0x3ff) << 2); pci_dma_read(STATE_TO_SC(s), frame_addr, &link, 4); @@ -1298,6 +1331,7 @@ qhdb_reset(&qhdb); for (cnt = FRAME_MAX_LOOPS; is_valid(link) && cnt; cnt--) { + fprintf(usblog, "%s:%d cnt:%d is_valid(link):%d is_qh(link):%d\n", __func__, __LINE__, cnt, is_valid(link), is_qh(link)); if (!s->completions_only && s->frame_bytes >= s->frame_bandwidth) { /* We've reached the usb 1.1 bandwidth, which is 1280 bytes/frame, stop processing */ @@ -1357,20 +1391,24 @@ switch (ret) { case TD_RESULT_STOP_FRAME: /* interrupted frame */ + fprintf(usblog, "%s:%d TD_RESULT_STOP_FRAME\n", __func__, __LINE__); goto out; case TD_RESULT_NEXT_QH: case TD_RESULT_ASYNC_CONT: + fprintf(usblog, "%s:%d %s\n", __func__, __LINE__, ret == TD_RESULT_NEXT_QH ? "TD_RESULT_NEXT_QH" : "TD_RESULT_ASYNC_CONT"); trace_usb_uhci_td_nextqh(curr_qh & ~0xf, link & ~0xf); link = curr_qh ? qh.link : td.link; continue; case TD_RESULT_ASYNC_START: + fprintf(usblog, "%s:%d TD_RESULT_ASYNC_START\n", __func__, __LINE__); trace_usb_uhci_td_async(curr_qh & ~0xf, link & ~0xf); link = curr_qh ? qh.link : td.link; continue; case TD_RESULT_COMPLETE: + fprintf(usblog, "%s:%d TD_RESULT_COMPLETE\n", __func__, __LINE__); trace_usb_uhci_td_complete(curr_qh & ~0xf, link & ~0xf); link = td.link; td_count++; @@ -1435,9 +1473,11 @@ /* Process up to MAX_FRAMES_PER_TICK frames */ frames = (t_now - t_last_run) / frame_t; + fprintf(usblog, "%s:%d frame_t:%ld s->expire_time:%ld t_last_run:%ld t_now:%ld frames:%d\n", __func__, __LINE__, frame_t, s->expire_time, t_last_run, t_now, frames); if (frames > s->maxframes) { int skipped = frames - s->maxframes; s->expire_time += skipped * frame_t; + fprintf(usblog, "%s s->expire_time:%ld\n", __func__, s->expire_time); s->frnum = (s->frnum + skipped) & 0x7ff; frames -= skipped; } @@ -1446,6 +1486,7 @@ } for (i = 0; i < frames; i++) { + fprintf(usblog, "%s:%d %d\n", __func__, __LINE__, i); s->frame_bytes = 0; trace_usb_uhci_frame_start(s->frnum); uhci_async_validate_begin(s); @@ -1455,6 +1496,7 @@ * the guest must look at frnum - 1 on interrupt, so inc frnum now */ s->frnum = (s->frnum + 1) & 0x7ff; s->expire_time += frame_t; + fprintf(usblog, "%s s->expire_time:%ld\n", __func__, s->expire_time); } /* Complete the previous frame(s) */ @@ -1467,7 +1509,7 @@ } s->pending_int_mask = 0; - mod_timer(s->frame_timer, t_now + frame_t); +// mod_timer(s->frame_timer, t_now + frame_t); } /* @@ -1702,8 +1744,11 @@ return (value); } +extern int usb_qdev_init(USBDevice *dev); extern USBDevice *usb_serial_init(USBBus *bus /*, const char *filename */); -extern int usb_serial_initfn(USBDevice *dev); +extern void usb_serial_class_initfn(USBDeviceClass *uc, void *data); +extern USBDevice *usb_hub_init(USBBus *bus); +void usb_hub_class_initfn(USBDeviceClass *uc, void *data); static int pci_uhci_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) { @@ -1764,8 +1809,14 @@ pci_emul_alloc_bar(pi, 4, PCIBAR_IO, 0x20); { + USBDevice *dev = usb_hub_init(&sc->sc_st.bus); + usb_hub_class_initfn(&dev->klass, NULL); + usb_qdev_init(dev); + } + { USBDevice *dev = usb_serial_init(&sc->sc_st.bus); - usb_serial_initfn(dev); + usb_serial_class_initfn(&dev->klass, NULL); + usb_qdev_init(dev); } return (0); Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Thu Sep 12 02:31:32 2013 (r257233) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Thu Sep 12 08:06:19 2013 (r257234) @@ -294,6 +294,7 @@ /* definition of a USB device */ struct USBDevice { + USBBus *bus; // DeviceState qdev; USBDeviceClass klass; USBPort *port; @@ -546,7 +547,7 @@ static inline USBBus *usb_bus_from_device(USBDevice *d) { // return DO_UPCAST(USBBus, qbus, d->qdev.parent_bus); - return NULL; + return d->bus; } //extern const VMStateDescription vmstate_usb_device;help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201309120806.r8C86JLw083964>
