Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * xhci-debugfs.c - xHCI debugfs interface
0004  *
0005  * Copyright (C) 2017 Intel Corporation
0006  *
0007  * Author: Lu Baolu <baolu.lu@linux.intel.com>
0008  */
0009 
0010 #include <linux/slab.h>
0011 #include <linux/uaccess.h>
0012 
0013 #include "xhci.h"
0014 #include "xhci-debugfs.h"
0015 
0016 static const struct debugfs_reg32 xhci_cap_regs[] = {
0017     dump_register(CAPLENGTH),
0018     dump_register(HCSPARAMS1),
0019     dump_register(HCSPARAMS2),
0020     dump_register(HCSPARAMS3),
0021     dump_register(HCCPARAMS1),
0022     dump_register(DOORBELLOFF),
0023     dump_register(RUNTIMEOFF),
0024     dump_register(HCCPARAMS2),
0025 };
0026 
0027 static const struct debugfs_reg32 xhci_op_regs[] = {
0028     dump_register(USBCMD),
0029     dump_register(USBSTS),
0030     dump_register(PAGESIZE),
0031     dump_register(DNCTRL),
0032     dump_register(CRCR),
0033     dump_register(DCBAAP_LOW),
0034     dump_register(DCBAAP_HIGH),
0035     dump_register(CONFIG),
0036 };
0037 
0038 static const struct debugfs_reg32 xhci_runtime_regs[] = {
0039     dump_register(MFINDEX),
0040     dump_register(IR0_IMAN),
0041     dump_register(IR0_IMOD),
0042     dump_register(IR0_ERSTSZ),
0043     dump_register(IR0_ERSTBA_LOW),
0044     dump_register(IR0_ERSTBA_HIGH),
0045     dump_register(IR0_ERDP_LOW),
0046     dump_register(IR0_ERDP_HIGH),
0047 };
0048 
0049 static const struct debugfs_reg32 xhci_extcap_legsup[] = {
0050     dump_register(EXTCAP_USBLEGSUP),
0051     dump_register(EXTCAP_USBLEGCTLSTS),
0052 };
0053 
0054 static const struct debugfs_reg32 xhci_extcap_protocol[] = {
0055     dump_register(EXTCAP_REVISION),
0056     dump_register(EXTCAP_NAME),
0057     dump_register(EXTCAP_PORTINFO),
0058     dump_register(EXTCAP_PORTTYPE),
0059     dump_register(EXTCAP_MANTISSA1),
0060     dump_register(EXTCAP_MANTISSA2),
0061     dump_register(EXTCAP_MANTISSA3),
0062     dump_register(EXTCAP_MANTISSA4),
0063     dump_register(EXTCAP_MANTISSA5),
0064     dump_register(EXTCAP_MANTISSA6),
0065 };
0066 
0067 static const struct debugfs_reg32 xhci_extcap_dbc[] = {
0068     dump_register(EXTCAP_DBC_CAPABILITY),
0069     dump_register(EXTCAP_DBC_DOORBELL),
0070     dump_register(EXTCAP_DBC_ERSTSIZE),
0071     dump_register(EXTCAP_DBC_ERST_LOW),
0072     dump_register(EXTCAP_DBC_ERST_HIGH),
0073     dump_register(EXTCAP_DBC_ERDP_LOW),
0074     dump_register(EXTCAP_DBC_ERDP_HIGH),
0075     dump_register(EXTCAP_DBC_CONTROL),
0076     dump_register(EXTCAP_DBC_STATUS),
0077     dump_register(EXTCAP_DBC_PORTSC),
0078     dump_register(EXTCAP_DBC_CONT_LOW),
0079     dump_register(EXTCAP_DBC_CONT_HIGH),
0080     dump_register(EXTCAP_DBC_DEVINFO1),
0081     dump_register(EXTCAP_DBC_DEVINFO2),
0082 };
0083 
0084 static struct dentry *xhci_debugfs_root;
0085 
0086 static struct xhci_regset *xhci_debugfs_alloc_regset(struct xhci_hcd *xhci)
0087 {
0088     struct xhci_regset  *regset;
0089 
0090     regset = kzalloc(sizeof(*regset), GFP_KERNEL);
0091     if (!regset)
0092         return NULL;
0093 
0094     /*
0095      * The allocation and free of regset are executed in order.
0096      * We needn't a lock here.
0097      */
0098     INIT_LIST_HEAD(&regset->list);
0099     list_add_tail(&regset->list, &xhci->regset_list);
0100 
0101     return regset;
0102 }
0103 
0104 static void xhci_debugfs_free_regset(struct xhci_regset *regset)
0105 {
0106     if (!regset)
0107         return;
0108 
0109     list_del(&regset->list);
0110     kfree(regset);
0111 }
0112 
0113 __printf(6, 7)
0114 static void xhci_debugfs_regset(struct xhci_hcd *xhci, u32 base,
0115                 const struct debugfs_reg32 *regs,
0116                 size_t nregs, struct dentry *parent,
0117                 const char *fmt, ...)
0118 {
0119     struct xhci_regset  *rgs;
0120     va_list         args;
0121     struct debugfs_regset32 *regset;
0122     struct usb_hcd      *hcd = xhci_to_hcd(xhci);
0123 
0124     rgs = xhci_debugfs_alloc_regset(xhci);
0125     if (!rgs)
0126         return;
0127 
0128     va_start(args, fmt);
0129     vsnprintf(rgs->name, sizeof(rgs->name), fmt, args);
0130     va_end(args);
0131 
0132     regset = &rgs->regset;
0133     regset->regs = regs;
0134     regset->nregs = nregs;
0135     regset->base = hcd->regs + base;
0136 
0137     debugfs_create_regset32((const char *)rgs->name, 0444, parent, regset);
0138 }
0139 
0140 static void xhci_debugfs_extcap_regset(struct xhci_hcd *xhci, int cap_id,
0141                        const struct debugfs_reg32 *regs,
0142                        size_t n, const char *cap_name)
0143 {
0144     u32         offset;
0145     int         index = 0;
0146     size_t          psic, nregs = n;
0147     void __iomem        *base = &xhci->cap_regs->hc_capbase;
0148 
0149     offset = xhci_find_next_ext_cap(base, 0, cap_id);
0150     while (offset) {
0151         if (cap_id == XHCI_EXT_CAPS_PROTOCOL) {
0152             psic = XHCI_EXT_PORT_PSIC(readl(base + offset + 8));
0153             nregs = min(4 + psic, n);
0154         }
0155 
0156         xhci_debugfs_regset(xhci, offset, regs, nregs,
0157                     xhci->debugfs_root, "%s:%02d",
0158                     cap_name, index);
0159         offset = xhci_find_next_ext_cap(base, offset, cap_id);
0160         index++;
0161     }
0162 }
0163 
0164 static int xhci_ring_enqueue_show(struct seq_file *s, void *unused)
0165 {
0166     dma_addr_t      dma;
0167     struct xhci_ring    *ring = *(struct xhci_ring **)s->private;
0168 
0169     dma = xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue);
0170     seq_printf(s, "%pad\n", &dma);
0171 
0172     return 0;
0173 }
0174 
0175 static int xhci_ring_dequeue_show(struct seq_file *s, void *unused)
0176 {
0177     dma_addr_t      dma;
0178     struct xhci_ring    *ring = *(struct xhci_ring **)s->private;
0179 
0180     dma = xhci_trb_virt_to_dma(ring->deq_seg, ring->dequeue);
0181     seq_printf(s, "%pad\n", &dma);
0182 
0183     return 0;
0184 }
0185 
0186 static int xhci_ring_cycle_show(struct seq_file *s, void *unused)
0187 {
0188     struct xhci_ring    *ring = *(struct xhci_ring **)s->private;
0189 
0190     seq_printf(s, "%d\n", ring->cycle_state);
0191 
0192     return 0;
0193 }
0194 
0195 static void xhci_ring_dump_segment(struct seq_file *s,
0196                    struct xhci_segment *seg)
0197 {
0198     int         i;
0199     dma_addr_t      dma;
0200     union xhci_trb      *trb;
0201     char            str[XHCI_MSG_MAX];
0202 
0203     for (i = 0; i < TRBS_PER_SEGMENT; i++) {
0204         trb = &seg->trbs[i];
0205         dma = seg->dma + i * sizeof(*trb);
0206         seq_printf(s, "%pad: %s\n", &dma,
0207                xhci_decode_trb(str, XHCI_MSG_MAX, le32_to_cpu(trb->generic.field[0]),
0208                        le32_to_cpu(trb->generic.field[1]),
0209                        le32_to_cpu(trb->generic.field[2]),
0210                        le32_to_cpu(trb->generic.field[3])));
0211     }
0212 }
0213 
0214 static int xhci_ring_trb_show(struct seq_file *s, void *unused)
0215 {
0216     int         i;
0217     struct xhci_ring    *ring = *(struct xhci_ring **)s->private;
0218     struct xhci_segment *seg = ring->first_seg;
0219 
0220     for (i = 0; i < ring->num_segs; i++) {
0221         xhci_ring_dump_segment(s, seg);
0222         seg = seg->next;
0223     }
0224 
0225     return 0;
0226 }
0227 
0228 static struct xhci_file_map ring_files[] = {
0229     {"enqueue",     xhci_ring_enqueue_show, },
0230     {"dequeue",     xhci_ring_dequeue_show, },
0231     {"cycle",       xhci_ring_cycle_show, },
0232     {"trbs",        xhci_ring_trb_show, },
0233 };
0234 
0235 static int xhci_ring_open(struct inode *inode, struct file *file)
0236 {
0237     int         i;
0238     struct xhci_file_map    *f_map;
0239     const char      *file_name = file_dentry(file)->d_iname;
0240 
0241     for (i = 0; i < ARRAY_SIZE(ring_files); i++) {
0242         f_map = &ring_files[i];
0243 
0244         if (strcmp(f_map->name, file_name) == 0)
0245             break;
0246     }
0247 
0248     return single_open(file, f_map->show, inode->i_private);
0249 }
0250 
0251 static const struct file_operations xhci_ring_fops = {
0252     .open           = xhci_ring_open,
0253     .read           = seq_read,
0254     .llseek         = seq_lseek,
0255     .release        = single_release,
0256 };
0257 
0258 static int xhci_slot_context_show(struct seq_file *s, void *unused)
0259 {
0260     struct xhci_hcd     *xhci;
0261     struct xhci_slot_ctx    *slot_ctx;
0262     struct xhci_slot_priv   *priv = s->private;
0263     struct xhci_virt_device *dev = priv->dev;
0264     char            str[XHCI_MSG_MAX];
0265 
0266     xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus));
0267     slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx);
0268     seq_printf(s, "%pad: %s\n", &dev->out_ctx->dma,
0269            xhci_decode_slot_context(str,
0270                         le32_to_cpu(slot_ctx->dev_info),
0271                         le32_to_cpu(slot_ctx->dev_info2),
0272                         le32_to_cpu(slot_ctx->tt_info),
0273                         le32_to_cpu(slot_ctx->dev_state)));
0274 
0275     return 0;
0276 }
0277 
0278 static int xhci_endpoint_context_show(struct seq_file *s, void *unused)
0279 {
0280     int         ep_index;
0281     dma_addr_t      dma;
0282     struct xhci_hcd     *xhci;
0283     struct xhci_ep_ctx  *ep_ctx;
0284     struct xhci_slot_priv   *priv = s->private;
0285     struct xhci_virt_device *dev = priv->dev;
0286     char            str[XHCI_MSG_MAX];
0287 
0288     xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus));
0289 
0290     for (ep_index = 0; ep_index < 31; ep_index++) {
0291         ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
0292         dma = dev->out_ctx->dma + (ep_index + 1) * CTX_SIZE(xhci->hcc_params);
0293         seq_printf(s, "%pad: %s\n", &dma,
0294                xhci_decode_ep_context(str,
0295                           le32_to_cpu(ep_ctx->ep_info),
0296                           le32_to_cpu(ep_ctx->ep_info2),
0297                           le64_to_cpu(ep_ctx->deq),
0298                           le32_to_cpu(ep_ctx->tx_info)));
0299     }
0300 
0301     return 0;
0302 }
0303 
0304 static int xhci_device_name_show(struct seq_file *s, void *unused)
0305 {
0306     struct xhci_slot_priv   *priv = s->private;
0307     struct xhci_virt_device *dev = priv->dev;
0308 
0309     seq_printf(s, "%s\n", dev_name(&dev->udev->dev));
0310 
0311     return 0;
0312 }
0313 
0314 static struct xhci_file_map context_files[] = {
0315     {"name",        xhci_device_name_show, },
0316     {"slot-context",    xhci_slot_context_show, },
0317     {"ep-context",      xhci_endpoint_context_show, },
0318 };
0319 
0320 static int xhci_context_open(struct inode *inode, struct file *file)
0321 {
0322     int         i;
0323     struct xhci_file_map    *f_map;
0324     const char      *file_name = file_dentry(file)->d_iname;
0325 
0326     for (i = 0; i < ARRAY_SIZE(context_files); i++) {
0327         f_map = &context_files[i];
0328 
0329         if (strcmp(f_map->name, file_name) == 0)
0330             break;
0331     }
0332 
0333     return single_open(file, f_map->show, inode->i_private);
0334 }
0335 
0336 static const struct file_operations xhci_context_fops = {
0337     .open           = xhci_context_open,
0338     .read           = seq_read,
0339     .llseek         = seq_lseek,
0340     .release        = single_release,
0341 };
0342 
0343 
0344 
0345 static int xhci_portsc_show(struct seq_file *s, void *unused)
0346 {
0347     struct xhci_port    *port = s->private;
0348     u32         portsc;
0349     char            str[XHCI_MSG_MAX];
0350 
0351     portsc = readl(port->addr);
0352     seq_printf(s, "%s\n", xhci_decode_portsc(str, portsc));
0353 
0354     return 0;
0355 }
0356 
0357 static int xhci_port_open(struct inode *inode, struct file *file)
0358 {
0359     return single_open(file, xhci_portsc_show, inode->i_private);
0360 }
0361 
0362 static ssize_t xhci_port_write(struct file *file,  const char __user *ubuf,
0363                    size_t count, loff_t *ppos)
0364 {
0365     struct seq_file         *s = file->private_data;
0366     struct xhci_port    *port = s->private;
0367     struct xhci_hcd     *xhci = hcd_to_xhci(port->rhub->hcd);
0368     char                    buf[32];
0369     u32         portsc;
0370     unsigned long       flags;
0371 
0372     if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
0373         return -EFAULT;
0374 
0375     if (!strncmp(buf, "compliance", 10)) {
0376         /* If CTC is clear, compliance is enabled by default */
0377         if (!HCC2_CTC(xhci->hcc_params2))
0378             return count;
0379         spin_lock_irqsave(&xhci->lock, flags);
0380         /* compliance mode can only be enabled on ports in RxDetect */
0381         portsc = readl(port->addr);
0382         if ((portsc & PORT_PLS_MASK) != XDEV_RXDETECT) {
0383             spin_unlock_irqrestore(&xhci->lock, flags);
0384             return -EPERM;
0385         }
0386         portsc = xhci_port_state_to_neutral(portsc);
0387         portsc &= ~PORT_PLS_MASK;
0388         portsc |= PORT_LINK_STROBE | XDEV_COMP_MODE;
0389         writel(portsc, port->addr);
0390         spin_unlock_irqrestore(&xhci->lock, flags);
0391     } else {
0392         return -EINVAL;
0393     }
0394     return count;
0395 }
0396 
0397 static const struct file_operations port_fops = {
0398     .open           = xhci_port_open,
0399     .write                  = xhci_port_write,
0400     .read           = seq_read,
0401     .llseek         = seq_lseek,
0402     .release        = single_release,
0403 };
0404 
0405 static void xhci_debugfs_create_files(struct xhci_hcd *xhci,
0406                       struct xhci_file_map *files,
0407                       size_t nentries, void *data,
0408                       struct dentry *parent,
0409                       const struct file_operations *fops)
0410 {
0411     int         i;
0412 
0413     for (i = 0; i < nentries; i++)
0414         debugfs_create_file(files[i].name, 0444, parent, data, fops);
0415 }
0416 
0417 static struct dentry *xhci_debugfs_create_ring_dir(struct xhci_hcd *xhci,
0418                            struct xhci_ring **ring,
0419                            const char *name,
0420                            struct dentry *parent)
0421 {
0422     struct dentry       *dir;
0423 
0424     dir = debugfs_create_dir(name, parent);
0425     xhci_debugfs_create_files(xhci, ring_files, ARRAY_SIZE(ring_files),
0426                   ring, dir, &xhci_ring_fops);
0427 
0428     return dir;
0429 }
0430 
0431 static void xhci_debugfs_create_context_files(struct xhci_hcd *xhci,
0432                           struct dentry *parent,
0433                           int slot_id)
0434 {
0435     struct xhci_virt_device *dev = xhci->devs[slot_id];
0436 
0437     xhci_debugfs_create_files(xhci, context_files,
0438                   ARRAY_SIZE(context_files),
0439                   dev->debugfs_private,
0440                   parent, &xhci_context_fops);
0441 }
0442 
0443 void xhci_debugfs_create_endpoint(struct xhci_hcd *xhci,
0444                   struct xhci_virt_device *dev,
0445                   int ep_index)
0446 {
0447     struct xhci_ep_priv *epriv;
0448     struct xhci_slot_priv   *spriv = dev->debugfs_private;
0449 
0450     if (!spriv)
0451         return;
0452 
0453     if (spriv->eps[ep_index])
0454         return;
0455 
0456     epriv = kzalloc(sizeof(*epriv), GFP_KERNEL);
0457     if (!epriv)
0458         return;
0459 
0460     epriv->show_ring = dev->eps[ep_index].ring;
0461 
0462     snprintf(epriv->name, sizeof(epriv->name), "ep%02d", ep_index);
0463     epriv->root = xhci_debugfs_create_ring_dir(xhci,
0464                            &epriv->show_ring,
0465                            epriv->name,
0466                            spriv->root);
0467     spriv->eps[ep_index] = epriv;
0468 }
0469 
0470 void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci,
0471                   struct xhci_virt_device *dev,
0472                   int ep_index)
0473 {
0474     struct xhci_ep_priv *epriv;
0475     struct xhci_slot_priv   *spriv = dev->debugfs_private;
0476 
0477     if (!spriv || !spriv->eps[ep_index])
0478         return;
0479 
0480     epriv = spriv->eps[ep_index];
0481     debugfs_remove_recursive(epriv->root);
0482     spriv->eps[ep_index] = NULL;
0483     kfree(epriv);
0484 }
0485 
0486 static int xhci_stream_id_show(struct seq_file *s, void *unused)
0487 {
0488     struct xhci_ep_priv *epriv = s->private;
0489 
0490     if (!epriv->stream_info)
0491         return -EPERM;
0492 
0493     seq_printf(s, "Show stream ID %d trb ring, supported [1 - %d]\n",
0494            epriv->stream_id, epriv->stream_info->num_streams - 1);
0495 
0496     return 0;
0497 }
0498 
0499 static int xhci_stream_id_open(struct inode *inode, struct file *file)
0500 {
0501     return single_open(file, xhci_stream_id_show, inode->i_private);
0502 }
0503 
0504 static ssize_t xhci_stream_id_write(struct file *file,  const char __user *ubuf,
0505                    size_t count, loff_t *ppos)
0506 {
0507     struct seq_file         *s = file->private_data;
0508     struct xhci_ep_priv *epriv = s->private;
0509     int         ret;
0510     u16         stream_id; /* MaxPStreams + 1 <= 16 */
0511 
0512     if (!epriv->stream_info)
0513         return -EPERM;
0514 
0515     /* Decimal number */
0516     ret = kstrtou16_from_user(ubuf, count, 10, &stream_id);
0517     if (ret)
0518         return ret;
0519 
0520     if (stream_id == 0 || stream_id >= epriv->stream_info->num_streams)
0521         return -EINVAL;
0522 
0523     epriv->stream_id = stream_id;
0524     epriv->show_ring = epriv->stream_info->stream_rings[stream_id];
0525 
0526     return count;
0527 }
0528 
0529 static const struct file_operations stream_id_fops = {
0530     .open           = xhci_stream_id_open,
0531     .write                  = xhci_stream_id_write,
0532     .read           = seq_read,
0533     .llseek         = seq_lseek,
0534     .release        = single_release,
0535 };
0536 
0537 static int xhci_stream_context_array_show(struct seq_file *s, void *unused)
0538 {
0539     struct xhci_ep_priv *epriv = s->private;
0540     struct xhci_stream_ctx  *stream_ctx;
0541     dma_addr_t      dma;
0542     int         id;
0543 
0544     if (!epriv->stream_info)
0545         return -EPERM;
0546 
0547     seq_printf(s, "Allocated %d streams and %d stream context array entries\n",
0548             epriv->stream_info->num_streams,
0549             epriv->stream_info->num_stream_ctxs);
0550 
0551     for (id = 0; id < epriv->stream_info->num_stream_ctxs; id++) {
0552         stream_ctx = epriv->stream_info->stream_ctx_array + id;
0553         dma = epriv->stream_info->ctx_array_dma + id * 16;
0554         if (id < epriv->stream_info->num_streams)
0555             seq_printf(s, "%pad stream id %d deq %016llx\n", &dma,
0556                    id, le64_to_cpu(stream_ctx->stream_ring));
0557         else
0558             seq_printf(s, "%pad stream context entry not used deq %016llx\n",
0559                    &dma, le64_to_cpu(stream_ctx->stream_ring));
0560     }
0561 
0562     return 0;
0563 }
0564 DEFINE_SHOW_ATTRIBUTE(xhci_stream_context_array);
0565 
0566 void xhci_debugfs_create_stream_files(struct xhci_hcd *xhci,
0567                       struct xhci_virt_device *dev,
0568                       int ep_index)
0569 {
0570     struct xhci_slot_priv   *spriv = dev->debugfs_private;
0571     struct xhci_ep_priv *epriv;
0572 
0573     if (!spriv || !spriv->eps[ep_index] ||
0574         !dev->eps[ep_index].stream_info)
0575         return;
0576 
0577     epriv = spriv->eps[ep_index];
0578     epriv->stream_info = dev->eps[ep_index].stream_info;
0579 
0580     /* Show trb ring of stream ID 1 by default */
0581     epriv->stream_id = 1;
0582     epriv->show_ring = epriv->stream_info->stream_rings[1];
0583     debugfs_create_file("stream_id", 0644,
0584                 epriv->root, epriv,
0585                 &stream_id_fops);
0586     debugfs_create_file("stream_context_array", 0444,
0587                 epriv->root, epriv,
0588                 &xhci_stream_context_array_fops);
0589 }
0590 
0591 void xhci_debugfs_create_slot(struct xhci_hcd *xhci, int slot_id)
0592 {
0593     struct xhci_slot_priv   *priv;
0594     struct xhci_virt_device *dev = xhci->devs[slot_id];
0595 
0596     priv = kzalloc(sizeof(*priv), GFP_KERNEL);
0597     if (!priv)
0598         return;
0599 
0600     snprintf(priv->name, sizeof(priv->name), "%02d", slot_id);
0601     priv->root = debugfs_create_dir(priv->name, xhci->debugfs_slots);
0602     priv->dev = dev;
0603     dev->debugfs_private = priv;
0604 
0605     xhci_debugfs_create_ring_dir(xhci, &dev->eps[0].ring,
0606                      "ep00", priv->root);
0607 
0608     xhci_debugfs_create_context_files(xhci, priv->root, slot_id);
0609 }
0610 
0611 void xhci_debugfs_remove_slot(struct xhci_hcd *xhci, int slot_id)
0612 {
0613     int         i;
0614     struct xhci_slot_priv   *priv;
0615     struct xhci_virt_device *dev = xhci->devs[slot_id];
0616 
0617     if (!dev || !dev->debugfs_private)
0618         return;
0619 
0620     priv = dev->debugfs_private;
0621 
0622     debugfs_remove_recursive(priv->root);
0623 
0624     for (i = 0; i < 31; i++)
0625         kfree(priv->eps[i]);
0626 
0627     kfree(priv);
0628     dev->debugfs_private = NULL;
0629 }
0630 
0631 static void xhci_debugfs_create_ports(struct xhci_hcd *xhci,
0632                       struct dentry *parent)
0633 {
0634     unsigned int        num_ports;
0635     char            port_name[8];
0636     struct xhci_port    *port;
0637     struct dentry       *dir;
0638 
0639     num_ports = HCS_MAX_PORTS(xhci->hcs_params1);
0640 
0641     parent = debugfs_create_dir("ports", parent);
0642 
0643     while (num_ports--) {
0644         scnprintf(port_name, sizeof(port_name), "port%02d",
0645               num_ports + 1);
0646         dir = debugfs_create_dir(port_name, parent);
0647         port = &xhci->hw_ports[num_ports];
0648         debugfs_create_file("portsc", 0644, dir, port, &port_fops);
0649     }
0650 }
0651 
0652 void xhci_debugfs_init(struct xhci_hcd *xhci)
0653 {
0654     struct device       *dev = xhci_to_hcd(xhci)->self.controller;
0655 
0656     xhci->debugfs_root = debugfs_create_dir(dev_name(dev),
0657                         xhci_debugfs_root);
0658 
0659     INIT_LIST_HEAD(&xhci->regset_list);
0660 
0661     xhci_debugfs_regset(xhci,
0662                 0,
0663                 xhci_cap_regs, ARRAY_SIZE(xhci_cap_regs),
0664                 xhci->debugfs_root, "reg-cap");
0665 
0666     xhci_debugfs_regset(xhci,
0667                 HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)),
0668                 xhci_op_regs, ARRAY_SIZE(xhci_op_regs),
0669                 xhci->debugfs_root, "reg-op");
0670 
0671     xhci_debugfs_regset(xhci,
0672                 readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK,
0673                 xhci_runtime_regs, ARRAY_SIZE(xhci_runtime_regs),
0674                 xhci->debugfs_root, "reg-runtime");
0675 
0676     xhci_debugfs_extcap_regset(xhci, XHCI_EXT_CAPS_LEGACY,
0677                    xhci_extcap_legsup,
0678                    ARRAY_SIZE(xhci_extcap_legsup),
0679                    "reg-ext-legsup");
0680 
0681     xhci_debugfs_extcap_regset(xhci, XHCI_EXT_CAPS_PROTOCOL,
0682                    xhci_extcap_protocol,
0683                    ARRAY_SIZE(xhci_extcap_protocol),
0684                    "reg-ext-protocol");
0685 
0686     xhci_debugfs_extcap_regset(xhci, XHCI_EXT_CAPS_DEBUG,
0687                    xhci_extcap_dbc,
0688                    ARRAY_SIZE(xhci_extcap_dbc),
0689                    "reg-ext-dbc");
0690 
0691     xhci_debugfs_create_ring_dir(xhci, &xhci->cmd_ring,
0692                      "command-ring",
0693                      xhci->debugfs_root);
0694 
0695     xhci_debugfs_create_ring_dir(xhci, &xhci->event_ring,
0696                      "event-ring",
0697                      xhci->debugfs_root);
0698 
0699     xhci->debugfs_slots = debugfs_create_dir("devices", xhci->debugfs_root);
0700 
0701     xhci_debugfs_create_ports(xhci, xhci->debugfs_root);
0702 }
0703 
0704 void xhci_debugfs_exit(struct xhci_hcd *xhci)
0705 {
0706     struct xhci_regset  *rgs, *tmp;
0707 
0708     debugfs_remove_recursive(xhci->debugfs_root);
0709     xhci->debugfs_root = NULL;
0710     xhci->debugfs_slots = NULL;
0711 
0712     list_for_each_entry_safe(rgs, tmp, &xhci->regset_list, list)
0713         xhci_debugfs_free_regset(rgs);
0714 }
0715 
0716 void __init xhci_debugfs_create_root(void)
0717 {
0718     xhci_debugfs_root = debugfs_create_dir("xhci", usb_debug_root);
0719 }
0720 
0721 void __exit xhci_debugfs_remove_root(void)
0722 {
0723     debugfs_remove_recursive(xhci_debugfs_root);
0724     xhci_debugfs_root = NULL;
0725 }