Merge remote-tracking branch 'kraxel/usb.88' into staging
authorAnthony Liguori <anthony@codemonkey.ws>
Tue, 3 Sep 2013 17:31:30 +0000 (12:31 -0500)
committerAnthony Liguori <anthony@codemonkey.ws>
Tue, 3 Sep 2013 17:31:30 +0000 (12:31 -0500)
# By Gerd Hoffmann (10) and Marcel Apfelbaum (1)
# Via Gerd Hoffmann
* kraxel/usb.88:
  usb/dev-hid: Modified usb-tablet category from Misc to Input
  Revert "usb-hub: report status changes only once"
  usb-hub: add tracepoint for status reports
  usb: parallelize usb3 streams
  uas: add property for request logging
  xhci: reset port when disabling slot
  xhci: emulate intr endpoint intervals correctly
  xhci: fix endpoint interval calculation
  xhci: add port to slot_address tracepoint
  xhci: add tracepoint for endpoint state changes
  xhci: remove leftover debug printf

Message-id: 1378117055-29620-1-git-send-email-kraxel@redhat.com
Signed-off-by: Anthony Liguori <anthony@codemonkey.ws>
1  2 
hw/usb/dev-uas.c
hw/usb/hcd-xhci.c
trace-events

diff --combined hw/usb/dev-uas.c
@@@ -113,6 -113,9 +113,9 @@@ struct UASDevice 
      QTAILQ_HEAD(, UASStatus)  results;
      QTAILQ_HEAD(, UASRequest) requests;
  
+     /* properties */
+     uint32_t                  requestlog;
      /* usb 2.0 only */
      USBPacket                 *status2;
      UASRequest                *datain2;
@@@ -692,9 -695,9 +695,9 @@@ static void usb_uas_command(UASDevice *
      req->req = scsi_req_new(req->dev, req->tag,
                              usb_uas_get_lun(req->lun),
                              ui->command.cdb, req);
- #if 1
-     scsi_req_print(req->req);
- #endif
+     if (uas->requestlog) {
+         scsi_req_print(req->req);
+     }
      len = scsi_req_enqueue(req->req);
      if (len) {
          req->data_size = len;
@@@ -888,8 -891,7 +891,8 @@@ static int usb_uas_init(USBDevice *dev
      QTAILQ_INIT(&uas->requests);
      uas->status_bh = qemu_bh_new(usb_uas_send_status_bh, uas);
  
 -    scsi_bus_new(&uas->bus, &uas->dev.qdev, &usb_uas_scsi_info, NULL);
 +    scsi_bus_new(&uas->bus, sizeof(uas->bus), DEVICE(dev),
 +                 &usb_uas_scsi_info, NULL);
  
      return 0;
  }
@@@ -903,6 -905,11 +906,11 @@@ static const VMStateDescription vmstate
      }
  };
  
+ static Property uas_properties[] = {
+     DEFINE_PROP_UINT32("log-scsi-req", UASDevice, requestlog, 0),
+     DEFINE_PROP_END_OF_LIST(),
+ };
  static void usb_uas_class_initfn(ObjectClass *klass, void *data)
  {
      DeviceClass *dc = DEVICE_CLASS(klass);
      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
      dc->fw_name = "storage";
      dc->vmsd = &vmstate_usb_uas;
+     dc->props = uas_properties;
  }
  
  static const TypeInfo uas_info = {
diff --combined hw/usb/hcd-xhci.c
@@@ -355,6 -355,7 +355,7 @@@ typedef struct XHCITransfer 
      unsigned int streamid;
      bool in_xfer;
      bool iso_xfer;
+     bool timed_xfer;
  
      unsigned int trb_count;
      unsigned int trb_alloced;
@@@ -586,6 -587,14 +587,14 @@@ static const char *TRBCCode_names[] = 
      [CC_SPLIT_TRANSACTION_ERROR]       = "CC_SPLIT_TRANSACTION_ERROR",
  };
  
+ static const char *ep_state_names[] = {
+     [EP_DISABLED] = "disabled",
+     [EP_RUNNING]  = "running",
+     [EP_HALTED]   = "halted",
+     [EP_STOPPED]  = "stopped",
+     [EP_ERROR]    = "error",
+ };
  static const char *lookup_name(uint32_t index, const char **list, uint32_t llen)
  {
      if (index >= llen || list[index] == NULL) {
@@@ -606,6 -615,12 +615,12 @@@ static const char *event_name(XHCIEven
                         ARRAY_SIZE(TRBCCode_names));
  }
  
+ static const char *ep_state_name(uint32_t state)
+ {
+     return lookup_name(state, ep_state_names,
+                        ARRAY_SIZE(ep_state_names));
+ }
  static uint64_t xhci_mfindex_get(XHCIState *xhci)
  {
      int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
@@@ -1164,8 -1179,6 +1179,6 @@@ static XHCIStreamContext *xhci_find_str
  
      if (sctx->sct == -1) {
          xhci_dma_read_u32s(epctx->xhci, sctx->pctx, ctx, sizeof(ctx));
-         fprintf(stderr, "%s: init sctx #%d @ " DMA_ADDR_FMT ": %08x %08x\n",
-                 __func__, streamid, sctx->pctx, ctx[0], ctx[1]);
          sct = (ctx[0] >> 1) & 0x07;
          if (epctx->lsa && sct != 1) {
              *cc_error = CC_INVALID_STREAM_TYPE_ERROR;
@@@ -1205,6 -1218,11 +1218,11 @@@ static void xhci_set_ep_state(XHCIStat
      }
  
      xhci_dma_write_u32s(xhci, epctx->pctx, ctx, sizeof(ctx));
+     if (epctx->state != state) {
+         trace_usb_xhci_ep_state(epctx->slotid, epctx->epid,
+                                 ep_state_name(epctx->state),
+                                 ep_state_name(state));
+     }
      epctx->state = state;
  }
  
@@@ -1257,7 -1275,7 +1275,7 @@@ static void xhci_init_epctx(XHCIEPConte
          epctx->ring.ccs = ctx[2] & 1;
      }
  
-     epctx->interval = 1 << (ctx[0] >> 16) & 0xff;
+     epctx->interval = 1 << ((ctx[0] >> 16) & 0xff);
  }
  
  static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid,
@@@ -1803,6 -1821,7 +1821,7 @@@ static int xhci_fire_ctl_transfer(XHCIS
  
      xfer->in_xfer = bmRequestType & USB_DIR_IN;
      xfer->iso_xfer = false;
+     xfer->timed_xfer = false;
  
      if (xhci_setup_packet(xfer) < 0) {
          return -1;
      return 0;
  }
  
+ static void xhci_calc_intr_kick(XHCIState *xhci, XHCITransfer *xfer,
+                                 XHCIEPContext *epctx, uint64_t mfindex)
+ {
+     uint64_t asap = ((mfindex + epctx->interval - 1) &
+                      ~(epctx->interval-1));
+     uint64_t kick = epctx->mfindex_last + epctx->interval;
+     assert(epctx->interval != 0);
+     xfer->mfindex_kick = MAX(asap, kick);
+ }
  static void xhci_calc_iso_kick(XHCIState *xhci, XHCITransfer *xfer,
                                 XHCIEPContext *epctx, uint64_t mfindex)
  {
      }
  }
  
- static void xhci_check_iso_kick(XHCIState *xhci, XHCITransfer *xfer,
-                                 XHCIEPContext *epctx, uint64_t mfindex)
+ static void xhci_check_intr_iso_kick(XHCIState *xhci, XHCITransfer *xfer,
+                                      XHCIEPContext *epctx, uint64_t mfindex)
  {
      if (xfer->mfindex_kick > mfindex) {
          timer_mod(epctx->kick_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
@@@ -1866,18 -1896,30 +1896,30 @@@ static int xhci_submit(XHCIState *xhci
      switch(epctx->type) {
      case ET_INTR_OUT:
      case ET_INTR_IN:
+         xfer->pkts = 0;
+         xfer->iso_xfer = false;
+         xfer->timed_xfer = true;
+         mfindex = xhci_mfindex_get(xhci);
+         xhci_calc_intr_kick(xhci, xfer, epctx, mfindex);
+         xhci_check_intr_iso_kick(xhci, xfer, epctx, mfindex);
+         if (xfer->running_retry) {
+             return -1;
+         }
+         break;
      case ET_BULK_OUT:
      case ET_BULK_IN:
          xfer->pkts = 0;
          xfer->iso_xfer = false;
+         xfer->timed_xfer = false;
          break;
      case ET_ISO_OUT:
      case ET_ISO_IN:
          xfer->pkts = 1;
          xfer->iso_xfer = true;
+         xfer->timed_xfer = true;
          mfindex = xhci_mfindex_get(xhci);
          xhci_calc_iso_kick(xhci, xfer, epctx, mfindex);
-         xhci_check_iso_kick(xhci, xfer, epctx, mfindex);
+         xhci_check_intr_iso_kick(xhci, xfer, epctx, mfindex);
          if (xfer->running_retry) {
              return -1;
          }
@@@ -1938,13 -1980,18 +1980,18 @@@ static void xhci_kick_ep(XHCIState *xhc
  
          trace_usb_xhci_xfer_retry(xfer);
          assert(xfer->running_retry);
-         if (xfer->iso_xfer) {
-             /* retry delayed iso transfer */
+         if (xfer->timed_xfer) {
+             /* time to kick the transfer? */
              mfindex = xhci_mfindex_get(xhci);
-             xhci_check_iso_kick(xhci, xfer, epctx, mfindex);
+             xhci_check_intr_iso_kick(xhci, xfer, epctx, mfindex);
              if (xfer->running_retry) {
                  return;
              }
+             xfer->timed_xfer = 0;
+             xfer->running_retry = 1;
+         }
+         if (xfer->iso_xfer) {
+             /* retry iso transfer */
              if (xhci_setup_packet(xfer) < 0) {
                  return;
              }
                  epctx->next_xfer = (epctx->next_xfer + 1) % TD_QUEUE;
                  ep = xfer->packet.ep;
              } else {
-                 if (!xfer->iso_xfer) {
+                 if (!xfer->timed_xfer) {
                      fprintf(stderr, "xhci: error firing data transfer\n");
                  }
              }
@@@ -2076,6 -2123,7 +2123,7 @@@ static TRBCCode xhci_disable_slot(XHCIS
  
      xhci->slots[slotid-1].enabled = 0;
      xhci->slots[slotid-1].addressed = 0;
+     xhci->slots[slotid-1].uport = NULL;
      return CC_SUCCESS;
  }
  
@@@ -2118,7 -2166,6 +2166,6 @@@ static TRBCCode xhci_address_slot(XHCIS
      int i;
      TRBCCode res;
  
-     trace_usb_xhci_slot_address(slotid);
      assert(slotid >= 1 && slotid <= xhci->numslots);
  
      dcbaap = xhci_addr64(xhci->dcbaap_low, xhci->dcbaap_high);
          fprintf(stderr, "xhci: port not found\n");
          return CC_TRB_ERROR;
      }
+     trace_usb_xhci_slot_address(slotid, uport->path);
  
      dev = uport->dev;
      if (!dev) {
@@@ -3309,7 -3357,7 +3357,7 @@@ static void usb_xhci_init(XHCIState *xh
      usbports = MAX(xhci->numports_2, xhci->numports_3);
      xhci->numports = xhci->numports_2 + xhci->numports_3;
  
 -    usb_bus_new(&xhci->bus, &xhci_bus_ops, dev);
 +    usb_bus_new(&xhci->bus, sizeof(xhci->bus), &xhci_bus_ops, dev);
  
      for (i = 0; i < usbports; i++) {
          speedmask = 0;
diff --combined trace-events
@@@ -371,7 -371,7 +371,7 @@@ usb_xhci_port_link(uint32_t port, uint3
  usb_xhci_port_notify(uint32_t port, uint32_t pls) "port %d, bits %x"
  usb_xhci_slot_enable(uint32_t slotid) "slotid %d"
  usb_xhci_slot_disable(uint32_t slotid) "slotid %d"
- usb_xhci_slot_address(uint32_t slotid) "slotid %d"
+ usb_xhci_slot_address(uint32_t slotid, const char *port) "slotid %d, port %s"
  usb_xhci_slot_configure(uint32_t slotid) "slotid %d"
  usb_xhci_slot_evaluate(uint32_t slotid) "slotid %d"
  usb_xhci_slot_reset(uint32_t slotid) "slotid %d"
@@@ -381,6 -381,7 +381,7 @@@ usb_xhci_ep_set_dequeue(uint32_t slotid
  usb_xhci_ep_kick(uint32_t slotid, uint32_t epid, uint32_t streamid) "slotid %d, epid %d, streamid %d"
  usb_xhci_ep_stop(uint32_t slotid, uint32_t epid) "slotid %d, epid %d"
  usb_xhci_ep_reset(uint32_t slotid, uint32_t epid) "slotid %d, epid %d"
+ usb_xhci_ep_state(uint32_t slotid, uint32_t epid, const char *os, const char *ns) "slotid %d, epid %d, %s -> %s"
  usb_xhci_xfer_start(void *xfer, uint32_t slotid, uint32_t epid, uint32_t streamid) "%p: slotid %d, epid %d, streamid %d"
  usb_xhci_xfer_async(void *xfer) "%p"
  usb_xhci_xfer_nak(void *xfer) "%p"
@@@ -410,6 -411,7 +411,7 @@@ usb_hub_set_port_feature(int addr, int 
  usb_hub_clear_port_feature(int addr, int nr, const char *f) "dev %d, port %d, feature %s"
  usb_hub_attach(int addr, int nr) "dev %d, port %d"
  usb_hub_detach(int addr, int nr) "dev %d, port %d"
+ usb_hub_status_report(int addr, int status) "dev %d, status 0x%x"
  
  # hw/usb/dev-uas.c
  usb_uas_reset(int addr) "dev %d"
@@@ -1133,11 -1135,6 +1135,11 @@@ xics_ics_write_xive(int nr, int srcno, 
  xics_ics_reject(int nr, int srcno) "reject irq %#x [src %d]"
  xics_ics_eoi(int nr) "ics_eoi: irq %#x"
  
 +# hw/ppc/spapr_iommu.c
 +spapr_iommu_put(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t ret) "liobn=%"PRIx64" ioba=0x%"PRIx64" tce=0x%"PRIx64" ret=%"PRId64
 +spapr_iommu_xlate(uint64_t liobn, uint64_t ioba, uint64_t tce, unsigned perm, unsigned pgsize) "liobn=%"PRIx64" 0x%"PRIx64" -> 0x%"PRIx64" perm=%u mask=%x"
 +spapr_iommu_new_table(uint64_t liobn, void *tcet, void *table, int fd) "liobn=%"PRIx64" tcet=%p table=%p fd=%d"
 +
  # util/hbitmap.c
  hbitmap_iter_skip_words(const void *hb, void *hbi, uint64_t pos, unsigned long cur) "hb %p hbi %p pos %"PRId64" cur 0x%lx"
  hbitmap_reset(void *hb, uint64_t start, uint64_t count, uint64_t sbit, uint64_t ebit) "hb %p items %"PRIu64",%"PRIu64" bits %"PRIu64"..%"PRIu64
@@@ -1181,7 -1178,3 +1183,7 @@@ object_class_dynamic_cast_assert(const 
  # hw/xen/xen_pvdevice.c
  xen_pv_mmio_read(uint64_t addr) "WARNING: read from Xen PV Device MMIO space (address %"PRIx64")"
  xen_pv_mmio_write(uint64_t addr) "WARNING: write to Xen PV Device MMIO space (address %"PRIx64")"
 +
 +# hw/pci/pci_host.c
 +pci_cfg_read(const char *dev, unsigned devid, unsigned fnid, unsigned offs, unsigned val) "%s %02u:%u @0x%x -> 0x%x"
 +pci_cfg_write(const char *dev, unsigned devid, unsigned fnid, unsigned offs, unsigned val) "%s %02u:%u @0x%x <- 0x%x"