forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
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,
....@@ -197,12 +198,13 @@
197198 int i;
198199 dma_addr_t dma;
199200 union xhci_trb *trb;
201
+ char str[XHCI_MSG_MAX];
200202
201203 for (i = 0; i < TRBS_PER_SEGMENT; i++) {
202204 trb = &seg->trbs[i];
203205 dma = seg->dma + i * sizeof(*trb);
204206 seq_printf(s, "%pad: %s\n", &dma,
205
- xhci_decode_trb(le32_to_cpu(trb->generic.field[0]),
207
+ xhci_decode_trb(str, XHCI_MSG_MAX, le32_to_cpu(trb->generic.field[0]),
206208 le32_to_cpu(trb->generic.field[1]),
207209 le32_to_cpu(trb->generic.field[2]),
208210 le32_to_cpu(trb->generic.field[3])));
....@@ -259,11 +261,13 @@
259261 struct xhci_slot_ctx *slot_ctx;
260262 struct xhci_slot_priv *priv = s->private;
261263 struct xhci_virt_device *dev = priv->dev;
264
+ char str[XHCI_MSG_MAX];
262265
263266 xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus));
264267 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx);
265268 seq_printf(s, "%pad: %s\n", &dev->out_ctx->dma,
266
- xhci_decode_slot_context(le32_to_cpu(slot_ctx->dev_info),
269
+ xhci_decode_slot_context(str,
270
+ le32_to_cpu(slot_ctx->dev_info),
267271 le32_to_cpu(slot_ctx->dev_info2),
268272 le32_to_cpu(slot_ctx->tt_info),
269273 le32_to_cpu(slot_ctx->dev_state)));
....@@ -279,6 +283,7 @@
279283 struct xhci_ep_ctx *ep_ctx;
280284 struct xhci_slot_priv *priv = s->private;
281285 struct xhci_virt_device *dev = priv->dev;
286
+ char str[XHCI_MSG_MAX];
282287
283288 xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus));
284289
....@@ -286,7 +291,8 @@
286291 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
287292 dma = dev->out_ctx->dma + (ep_index + 1) * CTX_SIZE(xhci->hcc_params);
288293 seq_printf(s, "%pad: %s\n", &dma,
289
- xhci_decode_ep_context(le32_to_cpu(ep_ctx->ep_info),
294
+ xhci_decode_ep_context(str,
295
+ le32_to_cpu(ep_ctx->ep_info),
290296 le32_to_cpu(ep_ctx->ep_info2),
291297 le64_to_cpu(ep_ctx->deq),
292298 le32_to_cpu(ep_ctx->tx_info)));
....@@ -340,9 +346,10 @@
340346 {
341347 struct xhci_port *port = s->private;
342348 u32 portsc;
349
+ char str[XHCI_MSG_MAX];
343350
344351 portsc = readl(port->addr);
345
- seq_printf(s, "%s\n", xhci_decode_portsc(portsc));
352
+ seq_printf(s, "%s\n", xhci_decode_portsc(str, portsc));
346353
347354 return 0;
348355 }
....@@ -450,9 +457,11 @@
450457 if (!epriv)
451458 return;
452459
460
+ epriv->show_ring = dev->eps[ep_index].ring;
461
+
453462 snprintf(epriv->name, sizeof(epriv->name), "ep%02d", ep_index);
454463 epriv->root = xhci_debugfs_create_ring_dir(xhci,
455
- &dev->eps[ep_index].ring,
464
+ &epriv->show_ring,
456465 epriv->name,
457466 spriv->root);
458467 spriv->eps[ep_index] = epriv;
....@@ -474,6 +483,111 @@
474483 kfree(epriv);
475484 }
476485
486
+static int xhci_stream_id_show(struct seq_file *s, void *unused)
487
+{
488
+ struct xhci_ep_priv *epriv = s->private;
489
+
490
+ if (!epriv->stream_info)
491
+ return -EPERM;
492
+
493
+ seq_printf(s, "Show stream ID %d trb ring, supported [1 - %d]\n",
494
+ epriv->stream_id, epriv->stream_info->num_streams - 1);
495
+
496
+ return 0;
497
+}
498
+
499
+static int xhci_stream_id_open(struct inode *inode, struct file *file)
500
+{
501
+ return single_open(file, xhci_stream_id_show, inode->i_private);
502
+}
503
+
504
+static ssize_t xhci_stream_id_write(struct file *file, const char __user *ubuf,
505
+ size_t count, loff_t *ppos)
506
+{
507
+ struct seq_file *s = file->private_data;
508
+ struct xhci_ep_priv *epriv = s->private;
509
+ int ret;
510
+ u16 stream_id; /* MaxPStreams + 1 <= 16 */
511
+
512
+ if (!epriv->stream_info)
513
+ return -EPERM;
514
+
515
+ /* Decimal number */
516
+ ret = kstrtou16_from_user(ubuf, count, 10, &stream_id);
517
+ if (ret)
518
+ return ret;
519
+
520
+ if (stream_id == 0 || stream_id >= epriv->stream_info->num_streams)
521
+ return -EINVAL;
522
+
523
+ epriv->stream_id = stream_id;
524
+ epriv->show_ring = epriv->stream_info->stream_rings[stream_id];
525
+
526
+ return count;
527
+}
528
+
529
+static const struct file_operations stream_id_fops = {
530
+ .open = xhci_stream_id_open,
531
+ .write = xhci_stream_id_write,
532
+ .read = seq_read,
533
+ .llseek = seq_lseek,
534
+ .release = single_release,
535
+};
536
+
537
+static int xhci_stream_context_array_show(struct seq_file *s, void *unused)
538
+{
539
+ struct xhci_ep_priv *epriv = s->private;
540
+ struct xhci_stream_ctx *stream_ctx;
541
+ dma_addr_t dma;
542
+ int id;
543
+
544
+ if (!epriv->stream_info)
545
+ return -EPERM;
546
+
547
+ seq_printf(s, "Allocated %d streams and %d stream context array entries\n",
548
+ epriv->stream_info->num_streams,
549
+ epriv->stream_info->num_stream_ctxs);
550
+
551
+ for (id = 0; id < epriv->stream_info->num_stream_ctxs; id++) {
552
+ stream_ctx = epriv->stream_info->stream_ctx_array + id;
553
+ dma = epriv->stream_info->ctx_array_dma + id * 16;
554
+ if (id < epriv->stream_info->num_streams)
555
+ seq_printf(s, "%pad stream id %d deq %016llx\n", &dma,
556
+ id, le64_to_cpu(stream_ctx->stream_ring));
557
+ else
558
+ seq_printf(s, "%pad stream context entry not used deq %016llx\n",
559
+ &dma, le64_to_cpu(stream_ctx->stream_ring));
560
+ }
561
+
562
+ return 0;
563
+}
564
+DEFINE_SHOW_ATTRIBUTE(xhci_stream_context_array);
565
+
566
+void xhci_debugfs_create_stream_files(struct xhci_hcd *xhci,
567
+ struct xhci_virt_device *dev,
568
+ int ep_index)
569
+{
570
+ struct xhci_slot_priv *spriv = dev->debugfs_private;
571
+ struct xhci_ep_priv *epriv;
572
+
573
+ if (!spriv || !spriv->eps[ep_index] ||
574
+ !dev->eps[ep_index].stream_info)
575
+ return;
576
+
577
+ epriv = spriv->eps[ep_index];
578
+ epriv->stream_info = dev->eps[ep_index].stream_info;
579
+
580
+ /* Show trb ring of stream ID 1 by default */
581
+ epriv->stream_id = 1;
582
+ epriv->show_ring = epriv->stream_info->stream_rings[1];
583
+ debugfs_create_file("stream_id", 0644,
584
+ epriv->root, epriv,
585
+ &stream_id_fops);
586
+ debugfs_create_file("stream_context_array", 0444,
587
+ epriv->root, epriv,
588
+ &xhci_stream_context_array_fops);
589
+}
590
+
477591 void xhci_debugfs_create_slot(struct xhci_hcd *xhci, int slot_id)
478592 {
479593 struct xhci_slot_priv *priv;