forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/usb/host/xhci-debugfs.c
....@@ -110,6 +110,7 @@
110110 kfree(regset);
111111 }
112112
113
+__printf(6, 7)
113114 static void xhci_debugfs_regset(struct xhci_hcd *xhci, u32 base,
114115 const struct debugfs_reg32 *regs,
115116 size_t nregs, struct dentry *parent,
....@@ -132,6 +133,7 @@
132133 regset->regs = regs;
133134 regset->nregs = nregs;
134135 regset->base = hcd->regs + base;
136
+ regset->dev = hcd->self.controller;
135137
136138 debugfs_create_regset32((const char *)rgs->name, 0444, parent, regset);
137139 }
....@@ -197,12 +199,13 @@
197199 int i;
198200 dma_addr_t dma;
199201 union xhci_trb *trb;
202
+ char str[XHCI_MSG_MAX];
200203
201204 for (i = 0; i < TRBS_PER_SEGMENT; i++) {
202205 trb = &seg->trbs[i];
203206 dma = seg->dma + i * sizeof(*trb);
204207 seq_printf(s, "%pad: %s\n", &dma,
205
- xhci_decode_trb(le32_to_cpu(trb->generic.field[0]),
208
+ xhci_decode_trb(str, XHCI_MSG_MAX, le32_to_cpu(trb->generic.field[0]),
206209 le32_to_cpu(trb->generic.field[1]),
207210 le32_to_cpu(trb->generic.field[2]),
208211 le32_to_cpu(trb->generic.field[3])));
....@@ -259,11 +262,13 @@
259262 struct xhci_slot_ctx *slot_ctx;
260263 struct xhci_slot_priv *priv = s->private;
261264 struct xhci_virt_device *dev = priv->dev;
265
+ char str[XHCI_MSG_MAX];
262266
263267 xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus));
264268 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx);
265269 seq_printf(s, "%pad: %s\n", &dev->out_ctx->dma,
266
- xhci_decode_slot_context(le32_to_cpu(slot_ctx->dev_info),
270
+ xhci_decode_slot_context(str,
271
+ le32_to_cpu(slot_ctx->dev_info),
267272 le32_to_cpu(slot_ctx->dev_info2),
268273 le32_to_cpu(slot_ctx->tt_info),
269274 le32_to_cpu(slot_ctx->dev_state)));
....@@ -279,6 +284,7 @@
279284 struct xhci_ep_ctx *ep_ctx;
280285 struct xhci_slot_priv *priv = s->private;
281286 struct xhci_virt_device *dev = priv->dev;
287
+ char str[XHCI_MSG_MAX];
282288
283289 xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus));
284290
....@@ -286,7 +292,8 @@
286292 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
287293 dma = dev->out_ctx->dma + (ep_index + 1) * CTX_SIZE(xhci->hcc_params);
288294 seq_printf(s, "%pad: %s\n", &dma,
289
- xhci_decode_ep_context(le32_to_cpu(ep_ctx->ep_info),
295
+ xhci_decode_ep_context(str,
296
+ le32_to_cpu(ep_ctx->ep_info),
290297 le32_to_cpu(ep_ctx->ep_info2),
291298 le64_to_cpu(ep_ctx->deq),
292299 le32_to_cpu(ep_ctx->tx_info)));
....@@ -340,9 +347,10 @@
340347 {
341348 struct xhci_port *port = s->private;
342349 u32 portsc;
350
+ char str[XHCI_MSG_MAX];
343351
344352 portsc = readl(port->addr);
345
- seq_printf(s, "%s\n", xhci_decode_portsc(portsc));
353
+ seq_printf(s, "%s\n", xhci_decode_portsc(str, portsc));
346354
347355 return 0;
348356 }
....@@ -450,9 +458,11 @@
450458 if (!epriv)
451459 return;
452460
461
+ epriv->show_ring = dev->eps[ep_index].ring;
462
+
453463 snprintf(epriv->name, sizeof(epriv->name), "ep%02d", ep_index);
454464 epriv->root = xhci_debugfs_create_ring_dir(xhci,
455
- &dev->eps[ep_index].ring,
465
+ &epriv->show_ring,
456466 epriv->name,
457467 spriv->root);
458468 spriv->eps[ep_index] = epriv;
....@@ -474,6 +484,111 @@
474484 kfree(epriv);
475485 }
476486
487
+static int xhci_stream_id_show(struct seq_file *s, void *unused)
488
+{
489
+ struct xhci_ep_priv *epriv = s->private;
490
+
491
+ if (!epriv->stream_info)
492
+ return -EPERM;
493
+
494
+ seq_printf(s, "Show stream ID %d trb ring, supported [1 - %d]\n",
495
+ epriv->stream_id, epriv->stream_info->num_streams - 1);
496
+
497
+ return 0;
498
+}
499
+
500
+static int xhci_stream_id_open(struct inode *inode, struct file *file)
501
+{
502
+ return single_open(file, xhci_stream_id_show, inode->i_private);
503
+}
504
+
505
+static ssize_t xhci_stream_id_write(struct file *file, const char __user *ubuf,
506
+ size_t count, loff_t *ppos)
507
+{
508
+ struct seq_file *s = file->private_data;
509
+ struct xhci_ep_priv *epriv = s->private;
510
+ int ret;
511
+ u16 stream_id; /* MaxPStreams + 1 <= 16 */
512
+
513
+ if (!epriv->stream_info)
514
+ return -EPERM;
515
+
516
+ /* Decimal number */
517
+ ret = kstrtou16_from_user(ubuf, count, 10, &stream_id);
518
+ if (ret)
519
+ return ret;
520
+
521
+ if (stream_id == 0 || stream_id >= epriv->stream_info->num_streams)
522
+ return -EINVAL;
523
+
524
+ epriv->stream_id = stream_id;
525
+ epriv->show_ring = epriv->stream_info->stream_rings[stream_id];
526
+
527
+ return count;
528
+}
529
+
530
+static const struct file_operations stream_id_fops = {
531
+ .open = xhci_stream_id_open,
532
+ .write = xhci_stream_id_write,
533
+ .read = seq_read,
534
+ .llseek = seq_lseek,
535
+ .release = single_release,
536
+};
537
+
538
+static int xhci_stream_context_array_show(struct seq_file *s, void *unused)
539
+{
540
+ struct xhci_ep_priv *epriv = s->private;
541
+ struct xhci_stream_ctx *stream_ctx;
542
+ dma_addr_t dma;
543
+ int id;
544
+
545
+ if (!epriv->stream_info)
546
+ return -EPERM;
547
+
548
+ seq_printf(s, "Allocated %d streams and %d stream context array entries\n",
549
+ epriv->stream_info->num_streams,
550
+ epriv->stream_info->num_stream_ctxs);
551
+
552
+ for (id = 0; id < epriv->stream_info->num_stream_ctxs; id++) {
553
+ stream_ctx = epriv->stream_info->stream_ctx_array + id;
554
+ dma = epriv->stream_info->ctx_array_dma + id * 16;
555
+ if (id < epriv->stream_info->num_streams)
556
+ seq_printf(s, "%pad stream id %d deq %016llx\n", &dma,
557
+ id, le64_to_cpu(stream_ctx->stream_ring));
558
+ else
559
+ seq_printf(s, "%pad stream context entry not used deq %016llx\n",
560
+ &dma, le64_to_cpu(stream_ctx->stream_ring));
561
+ }
562
+
563
+ return 0;
564
+}
565
+DEFINE_SHOW_ATTRIBUTE(xhci_stream_context_array);
566
+
567
+void xhci_debugfs_create_stream_files(struct xhci_hcd *xhci,
568
+ struct xhci_virt_device *dev,
569
+ int ep_index)
570
+{
571
+ struct xhci_slot_priv *spriv = dev->debugfs_private;
572
+ struct xhci_ep_priv *epriv;
573
+
574
+ if (!spriv || !spriv->eps[ep_index] ||
575
+ !dev->eps[ep_index].stream_info)
576
+ return;
577
+
578
+ epriv = spriv->eps[ep_index];
579
+ epriv->stream_info = dev->eps[ep_index].stream_info;
580
+
581
+ /* Show trb ring of stream ID 1 by default */
582
+ epriv->stream_id = 1;
583
+ epriv->show_ring = epriv->stream_info->stream_rings[1];
584
+ debugfs_create_file("stream_id", 0644,
585
+ epriv->root, epriv,
586
+ &stream_id_fops);
587
+ debugfs_create_file("stream_context_array", 0444,
588
+ epriv->root, epriv,
589
+ &xhci_stream_context_array_fops);
590
+}
591
+
477592 void xhci_debugfs_create_slot(struct xhci_hcd *xhci, int slot_id)
478593 {
479594 struct xhci_slot_priv *priv;