1 // SPDX-License-Identifier: GPL-2.0 2 /** 3 * debugfs.c - DesignWare USB3 DRD Controller DebugFS file 4 * 5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 6 * 7 * Authors: Felipe Balbi <balbi@ti.com>, 8 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 9 */ 10 11 #include <linux/kernel.h> 12 #include <linux/slab.h> 13 #include <linux/ptrace.h> 14 #include <linux/types.h> 15 #include <linux/spinlock.h> 16 #include <linux/debugfs.h> 17 #include <linux/seq_file.h> 18 #include <linux/delay.h> 19 #include <linux/uaccess.h> 20 21 #include <linux/usb/ch9.h> 22 23 #include "core.h" 24 #include "gadget.h" 25 #include "io.h" 26 #include "debug.h" 27 28 #define dump_register(nm) \ 29 { \ 30 .name = __stringify(nm), \ 31 .offset = DWC3_ ##nm, \ 32 } 33 34 #define dump_ep_register_set(n) \ 35 { \ 36 .name = "DEPCMDPAR2("__stringify(n)")", \ 37 .offset = DWC3_DEP_BASE(n) + \ 38 DWC3_DEPCMDPAR2, \ 39 }, \ 40 { \ 41 .name = "DEPCMDPAR1("__stringify(n)")", \ 42 .offset = DWC3_DEP_BASE(n) + \ 43 DWC3_DEPCMDPAR1, \ 44 }, \ 45 { \ 46 .name = "DEPCMDPAR0("__stringify(n)")", \ 47 .offset = DWC3_DEP_BASE(n) + \ 48 DWC3_DEPCMDPAR0, \ 49 }, \ 50 { \ 51 .name = "DEPCMD("__stringify(n)")", \ 52 .offset = DWC3_DEP_BASE(n) + \ 53 DWC3_DEPCMD, \ 54 } 55 56 57 static const struct debugfs_reg32 dwc3_regs[] = { 58 dump_register(GSBUSCFG0), 59 dump_register(GSBUSCFG1), 60 dump_register(GTXTHRCFG), 61 dump_register(GRXTHRCFG), 62 dump_register(GCTL), 63 dump_register(GEVTEN), 64 dump_register(GSTS), 65 dump_register(GUCTL1), 66 dump_register(GSNPSID), 67 dump_register(GGPIO), 68 dump_register(GUID), 69 dump_register(GUCTL), 70 dump_register(GBUSERRADDR0), 71 dump_register(GBUSERRADDR1), 72 dump_register(GPRTBIMAP0), 73 dump_register(GPRTBIMAP1), 74 dump_register(GHWPARAMS0), 75 dump_register(GHWPARAMS1), 76 dump_register(GHWPARAMS2), 77 dump_register(GHWPARAMS3), 78 dump_register(GHWPARAMS4), 79 dump_register(GHWPARAMS5), 80 dump_register(GHWPARAMS6), 81 dump_register(GHWPARAMS7), 82 dump_register(GDBGFIFOSPACE), 83 dump_register(GDBGLTSSM), 84 dump_register(GPRTBIMAP_HS0), 85 dump_register(GPRTBIMAP_HS1), 86 dump_register(GPRTBIMAP_FS0), 87 dump_register(GPRTBIMAP_FS1), 88 89 dump_register(GUSB2PHYCFG(0)), 90 dump_register(GUSB2PHYCFG(1)), 91 dump_register(GUSB2PHYCFG(2)), 92 dump_register(GUSB2PHYCFG(3)), 93 dump_register(GUSB2PHYCFG(4)), 94 dump_register(GUSB2PHYCFG(5)), 95 dump_register(GUSB2PHYCFG(6)), 96 dump_register(GUSB2PHYCFG(7)), 97 dump_register(GUSB2PHYCFG(8)), 98 dump_register(GUSB2PHYCFG(9)), 99 dump_register(GUSB2PHYCFG(10)), 100 dump_register(GUSB2PHYCFG(11)), 101 dump_register(GUSB2PHYCFG(12)), 102 dump_register(GUSB2PHYCFG(13)), 103 dump_register(GUSB2PHYCFG(14)), 104 dump_register(GUSB2PHYCFG(15)), 105 106 dump_register(GUSB2I2CCTL(0)), 107 dump_register(GUSB2I2CCTL(1)), 108 dump_register(GUSB2I2CCTL(2)), 109 dump_register(GUSB2I2CCTL(3)), 110 dump_register(GUSB2I2CCTL(4)), 111 dump_register(GUSB2I2CCTL(5)), 112 dump_register(GUSB2I2CCTL(6)), 113 dump_register(GUSB2I2CCTL(7)), 114 dump_register(GUSB2I2CCTL(8)), 115 dump_register(GUSB2I2CCTL(9)), 116 dump_register(GUSB2I2CCTL(10)), 117 dump_register(GUSB2I2CCTL(11)), 118 dump_register(GUSB2I2CCTL(12)), 119 dump_register(GUSB2I2CCTL(13)), 120 dump_register(GUSB2I2CCTL(14)), 121 dump_register(GUSB2I2CCTL(15)), 122 123 dump_register(GUSB2PHYACC(0)), 124 dump_register(GUSB2PHYACC(1)), 125 dump_register(GUSB2PHYACC(2)), 126 dump_register(GUSB2PHYACC(3)), 127 dump_register(GUSB2PHYACC(4)), 128 dump_register(GUSB2PHYACC(5)), 129 dump_register(GUSB2PHYACC(6)), 130 dump_register(GUSB2PHYACC(7)), 131 dump_register(GUSB2PHYACC(8)), 132 dump_register(GUSB2PHYACC(9)), 133 dump_register(GUSB2PHYACC(10)), 134 dump_register(GUSB2PHYACC(11)), 135 dump_register(GUSB2PHYACC(12)), 136 dump_register(GUSB2PHYACC(13)), 137 dump_register(GUSB2PHYACC(14)), 138 dump_register(GUSB2PHYACC(15)), 139 140 dump_register(GUSB3PIPECTL(0)), 141 dump_register(GUSB3PIPECTL(1)), 142 dump_register(GUSB3PIPECTL(2)), 143 dump_register(GUSB3PIPECTL(3)), 144 dump_register(GUSB3PIPECTL(4)), 145 dump_register(GUSB3PIPECTL(5)), 146 dump_register(GUSB3PIPECTL(6)), 147 dump_register(GUSB3PIPECTL(7)), 148 dump_register(GUSB3PIPECTL(8)), 149 dump_register(GUSB3PIPECTL(9)), 150 dump_register(GUSB3PIPECTL(10)), 151 dump_register(GUSB3PIPECTL(11)), 152 dump_register(GUSB3PIPECTL(12)), 153 dump_register(GUSB3PIPECTL(13)), 154 dump_register(GUSB3PIPECTL(14)), 155 dump_register(GUSB3PIPECTL(15)), 156 157 dump_register(GTXFIFOSIZ(0)), 158 dump_register(GTXFIFOSIZ(1)), 159 dump_register(GTXFIFOSIZ(2)), 160 dump_register(GTXFIFOSIZ(3)), 161 dump_register(GTXFIFOSIZ(4)), 162 dump_register(GTXFIFOSIZ(5)), 163 dump_register(GTXFIFOSIZ(6)), 164 dump_register(GTXFIFOSIZ(7)), 165 dump_register(GTXFIFOSIZ(8)), 166 dump_register(GTXFIFOSIZ(9)), 167 dump_register(GTXFIFOSIZ(10)), 168 dump_register(GTXFIFOSIZ(11)), 169 dump_register(GTXFIFOSIZ(12)), 170 dump_register(GTXFIFOSIZ(13)), 171 dump_register(GTXFIFOSIZ(14)), 172 dump_register(GTXFIFOSIZ(15)), 173 dump_register(GTXFIFOSIZ(16)), 174 dump_register(GTXFIFOSIZ(17)), 175 dump_register(GTXFIFOSIZ(18)), 176 dump_register(GTXFIFOSIZ(19)), 177 dump_register(GTXFIFOSIZ(20)), 178 dump_register(GTXFIFOSIZ(21)), 179 dump_register(GTXFIFOSIZ(22)), 180 dump_register(GTXFIFOSIZ(23)), 181 dump_register(GTXFIFOSIZ(24)), 182 dump_register(GTXFIFOSIZ(25)), 183 dump_register(GTXFIFOSIZ(26)), 184 dump_register(GTXFIFOSIZ(27)), 185 dump_register(GTXFIFOSIZ(28)), 186 dump_register(GTXFIFOSIZ(29)), 187 dump_register(GTXFIFOSIZ(30)), 188 dump_register(GTXFIFOSIZ(31)), 189 190 dump_register(GRXFIFOSIZ(0)), 191 dump_register(GRXFIFOSIZ(1)), 192 dump_register(GRXFIFOSIZ(2)), 193 dump_register(GRXFIFOSIZ(3)), 194 dump_register(GRXFIFOSIZ(4)), 195 dump_register(GRXFIFOSIZ(5)), 196 dump_register(GRXFIFOSIZ(6)), 197 dump_register(GRXFIFOSIZ(7)), 198 dump_register(GRXFIFOSIZ(8)), 199 dump_register(GRXFIFOSIZ(9)), 200 dump_register(GRXFIFOSIZ(10)), 201 dump_register(GRXFIFOSIZ(11)), 202 dump_register(GRXFIFOSIZ(12)), 203 dump_register(GRXFIFOSIZ(13)), 204 dump_register(GRXFIFOSIZ(14)), 205 dump_register(GRXFIFOSIZ(15)), 206 dump_register(GRXFIFOSIZ(16)), 207 dump_register(GRXFIFOSIZ(17)), 208 dump_register(GRXFIFOSIZ(18)), 209 dump_register(GRXFIFOSIZ(19)), 210 dump_register(GRXFIFOSIZ(20)), 211 dump_register(GRXFIFOSIZ(21)), 212 dump_register(GRXFIFOSIZ(22)), 213 dump_register(GRXFIFOSIZ(23)), 214 dump_register(GRXFIFOSIZ(24)), 215 dump_register(GRXFIFOSIZ(25)), 216 dump_register(GRXFIFOSIZ(26)), 217 dump_register(GRXFIFOSIZ(27)), 218 dump_register(GRXFIFOSIZ(28)), 219 dump_register(GRXFIFOSIZ(29)), 220 dump_register(GRXFIFOSIZ(30)), 221 dump_register(GRXFIFOSIZ(31)), 222 223 dump_register(GEVNTADRLO(0)), 224 dump_register(GEVNTADRHI(0)), 225 dump_register(GEVNTSIZ(0)), 226 dump_register(GEVNTCOUNT(0)), 227 228 dump_register(GHWPARAMS8), 229 dump_register(DCFG), 230 dump_register(DCTL), 231 dump_register(DEVTEN), 232 dump_register(DSTS), 233 dump_register(DGCMDPAR), 234 dump_register(DGCMD), 235 dump_register(DALEPENA), 236 237 dump_ep_register_set(0), 238 dump_ep_register_set(1), 239 dump_ep_register_set(2), 240 dump_ep_register_set(3), 241 dump_ep_register_set(4), 242 dump_ep_register_set(5), 243 dump_ep_register_set(6), 244 dump_ep_register_set(7), 245 dump_ep_register_set(8), 246 dump_ep_register_set(9), 247 dump_ep_register_set(10), 248 dump_ep_register_set(11), 249 dump_ep_register_set(12), 250 dump_ep_register_set(13), 251 dump_ep_register_set(14), 252 dump_ep_register_set(15), 253 dump_ep_register_set(16), 254 dump_ep_register_set(17), 255 dump_ep_register_set(18), 256 dump_ep_register_set(19), 257 dump_ep_register_set(20), 258 dump_ep_register_set(21), 259 dump_ep_register_set(22), 260 dump_ep_register_set(23), 261 dump_ep_register_set(24), 262 dump_ep_register_set(25), 263 dump_ep_register_set(26), 264 dump_ep_register_set(27), 265 dump_ep_register_set(28), 266 dump_ep_register_set(29), 267 dump_ep_register_set(30), 268 dump_ep_register_set(31), 269 270 dump_register(OCFG), 271 dump_register(OCTL), 272 dump_register(OEVT), 273 dump_register(OEVTEN), 274 dump_register(OSTS), 275 }; 276 277 static int dwc3_mode_show(struct seq_file *s, void *unused) 278 { 279 struct dwc3 *dwc = s->private; 280 unsigned long flags; 281 u32 reg; 282 283 spin_lock_irqsave(&dwc->lock, flags); 284 reg = dwc3_readl(dwc->regs, DWC3_GCTL); 285 spin_unlock_irqrestore(&dwc->lock, flags); 286 287 switch (DWC3_GCTL_PRTCAP(reg)) { 288 case DWC3_GCTL_PRTCAP_HOST: 289 seq_printf(s, "host\n"); 290 break; 291 case DWC3_GCTL_PRTCAP_DEVICE: 292 seq_printf(s, "device\n"); 293 break; 294 case DWC3_GCTL_PRTCAP_OTG: 295 seq_printf(s, "otg\n"); 296 break; 297 default: 298 seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg)); 299 } 300 301 return 0; 302 } 303 304 static int dwc3_mode_open(struct inode *inode, struct file *file) 305 { 306 return single_open(file, dwc3_mode_show, inode->i_private); 307 } 308 309 static ssize_t dwc3_mode_write(struct file *file, 310 const char __user *ubuf, size_t count, loff_t *ppos) 311 { 312 struct seq_file *s = file->private_data; 313 struct dwc3 *dwc = s->private; 314 u32 mode = 0; 315 char buf[32]; 316 317 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 318 return -EFAULT; 319 320 if (!strncmp(buf, "host", 4)) 321 mode = DWC3_GCTL_PRTCAP_HOST; 322 323 if (!strncmp(buf, "device", 6)) 324 mode = DWC3_GCTL_PRTCAP_DEVICE; 325 326 if (!strncmp(buf, "otg", 3)) 327 mode = DWC3_GCTL_PRTCAP_OTG; 328 329 dwc3_set_mode(dwc, mode); 330 331 return count; 332 } 333 334 static const struct file_operations dwc3_mode_fops = { 335 .open = dwc3_mode_open, 336 .write = dwc3_mode_write, 337 .read = seq_read, 338 .llseek = seq_lseek, 339 .release = single_release, 340 }; 341 342 static int dwc3_testmode_show(struct seq_file *s, void *unused) 343 { 344 struct dwc3 *dwc = s->private; 345 unsigned long flags; 346 u32 reg; 347 348 spin_lock_irqsave(&dwc->lock, flags); 349 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 350 reg &= DWC3_DCTL_TSTCTRL_MASK; 351 reg >>= 1; 352 spin_unlock_irqrestore(&dwc->lock, flags); 353 354 switch (reg) { 355 case 0: 356 seq_printf(s, "no test\n"); 357 break; 358 case TEST_J: 359 seq_printf(s, "test_j\n"); 360 break; 361 case TEST_K: 362 seq_printf(s, "test_k\n"); 363 break; 364 case TEST_SE0_NAK: 365 seq_printf(s, "test_se0_nak\n"); 366 break; 367 case TEST_PACKET: 368 seq_printf(s, "test_packet\n"); 369 break; 370 case TEST_FORCE_EN: 371 seq_printf(s, "test_force_enable\n"); 372 break; 373 default: 374 seq_printf(s, "UNKNOWN %d\n", reg); 375 } 376 377 return 0; 378 } 379 380 static int dwc3_testmode_open(struct inode *inode, struct file *file) 381 { 382 return single_open(file, dwc3_testmode_show, inode->i_private); 383 } 384 385 static ssize_t dwc3_testmode_write(struct file *file, 386 const char __user *ubuf, size_t count, loff_t *ppos) 387 { 388 struct seq_file *s = file->private_data; 389 struct dwc3 *dwc = s->private; 390 unsigned long flags; 391 u32 testmode = 0; 392 char buf[32]; 393 394 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 395 return -EFAULT; 396 397 if (!strncmp(buf, "test_j", 6)) 398 testmode = TEST_J; 399 else if (!strncmp(buf, "test_k", 6)) 400 testmode = TEST_K; 401 else if (!strncmp(buf, "test_se0_nak", 12)) 402 testmode = TEST_SE0_NAK; 403 else if (!strncmp(buf, "test_packet", 11)) 404 testmode = TEST_PACKET; 405 else if (!strncmp(buf, "test_force_enable", 17)) 406 testmode = TEST_FORCE_EN; 407 else 408 testmode = 0; 409 410 spin_lock_irqsave(&dwc->lock, flags); 411 dwc3_gadget_set_test_mode(dwc, testmode); 412 spin_unlock_irqrestore(&dwc->lock, flags); 413 414 return count; 415 } 416 417 static const struct file_operations dwc3_testmode_fops = { 418 .open = dwc3_testmode_open, 419 .write = dwc3_testmode_write, 420 .read = seq_read, 421 .llseek = seq_lseek, 422 .release = single_release, 423 }; 424 425 static int dwc3_link_state_show(struct seq_file *s, void *unused) 426 { 427 struct dwc3 *dwc = s->private; 428 unsigned long flags; 429 enum dwc3_link_state state; 430 u32 reg; 431 432 spin_lock_irqsave(&dwc->lock, flags); 433 reg = dwc3_readl(dwc->regs, DWC3_DSTS); 434 state = DWC3_DSTS_USBLNKST(reg); 435 spin_unlock_irqrestore(&dwc->lock, flags); 436 437 seq_printf(s, "%s\n", dwc3_gadget_link_string(state)); 438 439 return 0; 440 } 441 442 static int dwc3_link_state_open(struct inode *inode, struct file *file) 443 { 444 return single_open(file, dwc3_link_state_show, inode->i_private); 445 } 446 447 static ssize_t dwc3_link_state_write(struct file *file, 448 const char __user *ubuf, size_t count, loff_t *ppos) 449 { 450 struct seq_file *s = file->private_data; 451 struct dwc3 *dwc = s->private; 452 unsigned long flags; 453 enum dwc3_link_state state = 0; 454 char buf[32]; 455 456 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 457 return -EFAULT; 458 459 if (!strncmp(buf, "SS.Disabled", 11)) 460 state = DWC3_LINK_STATE_SS_DIS; 461 else if (!strncmp(buf, "Rx.Detect", 9)) 462 state = DWC3_LINK_STATE_RX_DET; 463 else if (!strncmp(buf, "SS.Inactive", 11)) 464 state = DWC3_LINK_STATE_SS_INACT; 465 else if (!strncmp(buf, "Recovery", 8)) 466 state = DWC3_LINK_STATE_RECOV; 467 else if (!strncmp(buf, "Compliance", 10)) 468 state = DWC3_LINK_STATE_CMPLY; 469 else if (!strncmp(buf, "Loopback", 8)) 470 state = DWC3_LINK_STATE_LPBK; 471 else 472 return -EINVAL; 473 474 spin_lock_irqsave(&dwc->lock, flags); 475 dwc3_gadget_set_link_state(dwc, state); 476 spin_unlock_irqrestore(&dwc->lock, flags); 477 478 return count; 479 } 480 481 static const struct file_operations dwc3_link_state_fops = { 482 .open = dwc3_link_state_open, 483 .write = dwc3_link_state_write, 484 .read = seq_read, 485 .llseek = seq_lseek, 486 .release = single_release, 487 }; 488 489 struct dwc3_ep_file_map { 490 char name[25]; 491 int (*show)(struct seq_file *s, void *unused); 492 }; 493 494 static int dwc3_tx_fifo_queue_show(struct seq_file *s, void *unused) 495 { 496 struct dwc3_ep *dep = s->private; 497 struct dwc3 *dwc = dep->dwc; 498 unsigned long flags; 499 u32 val; 500 501 spin_lock_irqsave(&dwc->lock, flags); 502 val = dwc3_core_fifo_space(dep, DWC3_TXFIFOQ); 503 seq_printf(s, "%u\n", val); 504 spin_unlock_irqrestore(&dwc->lock, flags); 505 506 return 0; 507 } 508 509 static int dwc3_rx_fifo_queue_show(struct seq_file *s, void *unused) 510 { 511 struct dwc3_ep *dep = s->private; 512 struct dwc3 *dwc = dep->dwc; 513 unsigned long flags; 514 u32 val; 515 516 spin_lock_irqsave(&dwc->lock, flags); 517 val = dwc3_core_fifo_space(dep, DWC3_RXFIFOQ); 518 seq_printf(s, "%u\n", val); 519 spin_unlock_irqrestore(&dwc->lock, flags); 520 521 return 0; 522 } 523 524 static int dwc3_tx_request_queue_show(struct seq_file *s, void *unused) 525 { 526 struct dwc3_ep *dep = s->private; 527 struct dwc3 *dwc = dep->dwc; 528 unsigned long flags; 529 u32 val; 530 531 spin_lock_irqsave(&dwc->lock, flags); 532 val = dwc3_core_fifo_space(dep, DWC3_TXREQQ); 533 seq_printf(s, "%u\n", val); 534 spin_unlock_irqrestore(&dwc->lock, flags); 535 536 return 0; 537 } 538 539 static int dwc3_rx_request_queue_show(struct seq_file *s, void *unused) 540 { 541 struct dwc3_ep *dep = s->private; 542 struct dwc3 *dwc = dep->dwc; 543 unsigned long flags; 544 u32 val; 545 546 spin_lock_irqsave(&dwc->lock, flags); 547 val = dwc3_core_fifo_space(dep, DWC3_RXREQQ); 548 seq_printf(s, "%u\n", val); 549 spin_unlock_irqrestore(&dwc->lock, flags); 550 551 return 0; 552 } 553 554 static int dwc3_rx_info_queue_show(struct seq_file *s, void *unused) 555 { 556 struct dwc3_ep *dep = s->private; 557 struct dwc3 *dwc = dep->dwc; 558 unsigned long flags; 559 u32 val; 560 561 spin_lock_irqsave(&dwc->lock, flags); 562 val = dwc3_core_fifo_space(dep, DWC3_RXINFOQ); 563 seq_printf(s, "%u\n", val); 564 spin_unlock_irqrestore(&dwc->lock, flags); 565 566 return 0; 567 } 568 569 static int dwc3_descriptor_fetch_queue_show(struct seq_file *s, void *unused) 570 { 571 struct dwc3_ep *dep = s->private; 572 struct dwc3 *dwc = dep->dwc; 573 unsigned long flags; 574 u32 val; 575 576 spin_lock_irqsave(&dwc->lock, flags); 577 val = dwc3_core_fifo_space(dep, DWC3_DESCFETCHQ); 578 seq_printf(s, "%u\n", val); 579 spin_unlock_irqrestore(&dwc->lock, flags); 580 581 return 0; 582 } 583 584 static int dwc3_event_queue_show(struct seq_file *s, void *unused) 585 { 586 struct dwc3_ep *dep = s->private; 587 struct dwc3 *dwc = dep->dwc; 588 unsigned long flags; 589 u32 val; 590 591 spin_lock_irqsave(&dwc->lock, flags); 592 val = dwc3_core_fifo_space(dep, DWC3_EVENTQ); 593 seq_printf(s, "%u\n", val); 594 spin_unlock_irqrestore(&dwc->lock, flags); 595 596 return 0; 597 } 598 599 static int dwc3_ep_transfer_type_show(struct seq_file *s, void *unused) 600 { 601 struct dwc3_ep *dep = s->private; 602 struct dwc3 *dwc = dep->dwc; 603 unsigned long flags; 604 605 spin_lock_irqsave(&dwc->lock, flags); 606 if (!(dep->flags & DWC3_EP_ENABLED) || 607 !dep->endpoint.desc) { 608 seq_printf(s, "--\n"); 609 goto out; 610 } 611 612 switch (usb_endpoint_type(dep->endpoint.desc)) { 613 case USB_ENDPOINT_XFER_CONTROL: 614 seq_printf(s, "control\n"); 615 break; 616 case USB_ENDPOINT_XFER_ISOC: 617 seq_printf(s, "isochronous\n"); 618 break; 619 case USB_ENDPOINT_XFER_BULK: 620 seq_printf(s, "bulk\n"); 621 break; 622 case USB_ENDPOINT_XFER_INT: 623 seq_printf(s, "interrupt\n"); 624 break; 625 default: 626 seq_printf(s, "--\n"); 627 } 628 629 out: 630 spin_unlock_irqrestore(&dwc->lock, flags); 631 632 return 0; 633 } 634 635 static int dwc3_ep_trb_ring_show(struct seq_file *s, void *unused) 636 { 637 struct dwc3_ep *dep = s->private; 638 struct dwc3 *dwc = dep->dwc; 639 unsigned long flags; 640 int i; 641 642 spin_lock_irqsave(&dwc->lock, flags); 643 if (dep->number <= 1) { 644 seq_printf(s, "--\n"); 645 goto out; 646 } 647 648 seq_printf(s, "buffer_addr,size,type,ioc,isp_imi,csp,chn,lst,hwo\n"); 649 650 for (i = 0; i < DWC3_TRB_NUM; i++) { 651 struct dwc3_trb *trb = &dep->trb_pool[i]; 652 unsigned int type = DWC3_TRBCTL_TYPE(trb->ctrl); 653 654 seq_printf(s, "%08x%08x,%d,%s,%d,%d,%d,%d,%d,%d %c%c\n", 655 trb->bph, trb->bpl, trb->size, 656 dwc3_trb_type_string(type), 657 !!(trb->ctrl & DWC3_TRB_CTRL_IOC), 658 !!(trb->ctrl & DWC3_TRB_CTRL_ISP_IMI), 659 !!(trb->ctrl & DWC3_TRB_CTRL_CSP), 660 !!(trb->ctrl & DWC3_TRB_CTRL_CHN), 661 !!(trb->ctrl & DWC3_TRB_CTRL_LST), 662 !!(trb->ctrl & DWC3_TRB_CTRL_HWO), 663 dep->trb_enqueue == i ? 'E' : ' ', 664 dep->trb_dequeue == i ? 'D' : ' '); 665 } 666 667 out: 668 spin_unlock_irqrestore(&dwc->lock, flags); 669 670 return 0; 671 } 672 673 static struct dwc3_ep_file_map map[] = { 674 { "tx_fifo_queue", dwc3_tx_fifo_queue_show, }, 675 { "rx_fifo_queue", dwc3_rx_fifo_queue_show, }, 676 { "tx_request_queue", dwc3_tx_request_queue_show, }, 677 { "rx_request_queue", dwc3_rx_request_queue_show, }, 678 { "rx_info_queue", dwc3_rx_info_queue_show, }, 679 { "descriptor_fetch_queue", dwc3_descriptor_fetch_queue_show, }, 680 { "event_queue", dwc3_event_queue_show, }, 681 { "transfer_type", dwc3_ep_transfer_type_show, }, 682 { "trb_ring", dwc3_ep_trb_ring_show, }, 683 }; 684 685 static int dwc3_endpoint_open(struct inode *inode, struct file *file) 686 { 687 const char *file_name = file_dentry(file)->d_iname; 688 struct dwc3_ep_file_map *f_map; 689 int i; 690 691 for (i = 0; i < ARRAY_SIZE(map); i++) { 692 f_map = &map[i]; 693 694 if (strcmp(f_map->name, file_name) == 0) 695 break; 696 } 697 698 return single_open(file, f_map->show, inode->i_private); 699 } 700 701 static const struct file_operations dwc3_endpoint_fops = { 702 .open = dwc3_endpoint_open, 703 .read = seq_read, 704 .llseek = seq_lseek, 705 .release = single_release, 706 }; 707 708 static void dwc3_debugfs_create_endpoint_file(struct dwc3_ep *dep, 709 struct dentry *parent, int type) 710 { 711 struct dentry *file; 712 struct dwc3_ep_file_map *ep_file = &map[type]; 713 714 file = debugfs_create_file(ep_file->name, S_IRUGO, parent, dep, 715 &dwc3_endpoint_fops); 716 } 717 718 static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep, 719 struct dentry *parent) 720 { 721 int i; 722 723 for (i = 0; i < ARRAY_SIZE(map); i++) 724 dwc3_debugfs_create_endpoint_file(dep, parent, i); 725 } 726 727 static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep, 728 struct dentry *parent) 729 { 730 struct dentry *dir; 731 732 dir = debugfs_create_dir(dep->name, parent); 733 if (IS_ERR_OR_NULL(dir)) 734 return; 735 736 dwc3_debugfs_create_endpoint_files(dep, dir); 737 } 738 739 static void dwc3_debugfs_create_endpoint_dirs(struct dwc3 *dwc, 740 struct dentry *parent) 741 { 742 int i; 743 744 for (i = 0; i < dwc->num_eps; i++) { 745 struct dwc3_ep *dep = dwc->eps[i]; 746 747 if (!dep) 748 continue; 749 750 dwc3_debugfs_create_endpoint_dir(dep, parent); 751 } 752 } 753 754 void dwc3_debugfs_init(struct dwc3 *dwc) 755 { 756 struct dentry *root; 757 struct dentry *file; 758 759 root = debugfs_create_dir(dev_name(dwc->dev), NULL); 760 if (IS_ERR_OR_NULL(root)) { 761 if (!root) 762 dev_err(dwc->dev, "Can't create debugfs root\n"); 763 return; 764 } 765 dwc->root = root; 766 767 dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL); 768 if (!dwc->regset) { 769 debugfs_remove_recursive(root); 770 return; 771 } 772 773 dwc->regset->regs = dwc3_regs; 774 dwc->regset->nregs = ARRAY_SIZE(dwc3_regs); 775 dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START; 776 777 file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset); 778 if (!file) 779 dev_dbg(dwc->dev, "Can't create debugfs regdump\n"); 780 781 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) { 782 file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root, 783 dwc, &dwc3_mode_fops); 784 if (!file) 785 dev_dbg(dwc->dev, "Can't create debugfs mode\n"); 786 } 787 788 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) || 789 IS_ENABLED(CONFIG_USB_DWC3_GADGET)) { 790 file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root, 791 dwc, &dwc3_testmode_fops); 792 if (!file) 793 dev_dbg(dwc->dev, "Can't create debugfs testmode\n"); 794 795 file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, 796 root, dwc, &dwc3_link_state_fops); 797 if (!file) 798 dev_dbg(dwc->dev, "Can't create debugfs link_state\n"); 799 800 dwc3_debugfs_create_endpoint_dirs(dwc, root); 801 } 802 } 803 804 void dwc3_debugfs_exit(struct dwc3 *dwc) 805 { 806 debugfs_remove_recursive(dwc->root); 807 kfree(dwc->regset); 808 } 809