xhci-debugfs.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * xhci-debugfs.c - xHCI debugfs interface
  4. *
  5. * Copyright (C) 2017 Intel Corporation
  6. *
  7. * Author: Lu Baolu <baolu.lu@linux.intel.com>
  8. */
  9. #include <linux/slab.h>
  10. #include <linux/uaccess.h>
  11. #include "xhci.h"
  12. #include "xhci-debugfs.h"
  13. static const struct debugfs_reg32 xhci_cap_regs[] = {
  14. dump_register(CAPLENGTH),
  15. dump_register(HCSPARAMS1),
  16. dump_register(HCSPARAMS2),
  17. dump_register(HCSPARAMS3),
  18. dump_register(HCCPARAMS1),
  19. dump_register(DOORBELLOFF),
  20. dump_register(RUNTIMEOFF),
  21. dump_register(HCCPARAMS2),
  22. };
  23. static const struct debugfs_reg32 xhci_op_regs[] = {
  24. dump_register(USBCMD),
  25. dump_register(USBSTS),
  26. dump_register(PAGESIZE),
  27. dump_register(DNCTRL),
  28. dump_register(CRCR),
  29. dump_register(DCBAAP_LOW),
  30. dump_register(DCBAAP_HIGH),
  31. dump_register(CONFIG),
  32. };
  33. static const struct debugfs_reg32 xhci_runtime_regs[] = {
  34. dump_register(MFINDEX),
  35. dump_register(IR0_IMAN),
  36. dump_register(IR0_IMOD),
  37. dump_register(IR0_ERSTSZ),
  38. dump_register(IR0_ERSTBA_LOW),
  39. dump_register(IR0_ERSTBA_HIGH),
  40. dump_register(IR0_ERDP_LOW),
  41. dump_register(IR0_ERDP_HIGH),
  42. };
  43. static const struct debugfs_reg32 xhci_extcap_legsup[] = {
  44. dump_register(EXTCAP_USBLEGSUP),
  45. dump_register(EXTCAP_USBLEGCTLSTS),
  46. };
  47. static const struct debugfs_reg32 xhci_extcap_protocol[] = {
  48. dump_register(EXTCAP_REVISION),
  49. dump_register(EXTCAP_NAME),
  50. dump_register(EXTCAP_PORTINFO),
  51. dump_register(EXTCAP_PORTTYPE),
  52. dump_register(EXTCAP_MANTISSA1),
  53. dump_register(EXTCAP_MANTISSA2),
  54. dump_register(EXTCAP_MANTISSA3),
  55. dump_register(EXTCAP_MANTISSA4),
  56. dump_register(EXTCAP_MANTISSA5),
  57. dump_register(EXTCAP_MANTISSA6),
  58. };
  59. static const struct debugfs_reg32 xhci_extcap_dbc[] = {
  60. dump_register(EXTCAP_DBC_CAPABILITY),
  61. dump_register(EXTCAP_DBC_DOORBELL),
  62. dump_register(EXTCAP_DBC_ERSTSIZE),
  63. dump_register(EXTCAP_DBC_ERST_LOW),
  64. dump_register(EXTCAP_DBC_ERST_HIGH),
  65. dump_register(EXTCAP_DBC_ERDP_LOW),
  66. dump_register(EXTCAP_DBC_ERDP_HIGH),
  67. dump_register(EXTCAP_DBC_CONTROL),
  68. dump_register(EXTCAP_DBC_STATUS),
  69. dump_register(EXTCAP_DBC_PORTSC),
  70. dump_register(EXTCAP_DBC_CONT_LOW),
  71. dump_register(EXTCAP_DBC_CONT_HIGH),
  72. dump_register(EXTCAP_DBC_DEVINFO1),
  73. dump_register(EXTCAP_DBC_DEVINFO2),
  74. };
  75. static struct dentry *xhci_debugfs_root;
  76. static struct xhci_regset *xhci_debugfs_alloc_regset(struct xhci_hcd *xhci)
  77. {
  78. struct xhci_regset *regset;
  79. regset = kzalloc(sizeof(*regset), GFP_KERNEL);
  80. if (!regset)
  81. return NULL;
  82. /*
  83. * The allocation and free of regset are executed in order.
  84. * We needn't a lock here.
  85. */
  86. INIT_LIST_HEAD(&regset->list);
  87. list_add_tail(&regset->list, &xhci->regset_list);
  88. return regset;
  89. }
  90. static void xhci_debugfs_free_regset(struct xhci_regset *regset)
  91. {
  92. if (!regset)
  93. return;
  94. list_del(&regset->list);
  95. kfree(regset);
  96. }
  97. __printf(6, 7)
  98. static void xhci_debugfs_regset(struct xhci_hcd *xhci, u32 base,
  99. const struct debugfs_reg32 *regs,
  100. size_t nregs, struct dentry *parent,
  101. const char *fmt, ...)
  102. {
  103. struct xhci_regset *rgs;
  104. va_list args;
  105. struct debugfs_regset32 *regset;
  106. struct usb_hcd *hcd = xhci_to_hcd(xhci);
  107. rgs = xhci_debugfs_alloc_regset(xhci);
  108. if (!rgs)
  109. return;
  110. va_start(args, fmt);
  111. vsnprintf(rgs->name, sizeof(rgs->name), fmt, args);
  112. va_end(args);
  113. regset = &rgs->regset;
  114. regset->regs = regs;
  115. regset->nregs = nregs;
  116. regset->base = hcd->regs + base;
  117. regset->dev = hcd->self.controller;
  118. debugfs_create_regset32((const char *)rgs->name, 0444, parent, regset);
  119. }
  120. static void xhci_debugfs_extcap_regset(struct xhci_hcd *xhci, int cap_id,
  121. const struct debugfs_reg32 *regs,
  122. size_t n, const char *cap_name)
  123. {
  124. u32 offset;
  125. int index = 0;
  126. size_t psic, nregs = n;
  127. void __iomem *base = &xhci->cap_regs->hc_capbase;
  128. offset = xhci_find_next_ext_cap(base, 0, cap_id);
  129. while (offset) {
  130. if (cap_id == XHCI_EXT_CAPS_PROTOCOL) {
  131. psic = XHCI_EXT_PORT_PSIC(readl(base + offset + 8));
  132. nregs = min(4 + psic, n);
  133. }
  134. xhci_debugfs_regset(xhci, offset, regs, nregs,
  135. xhci->debugfs_root, "%s:%02d",
  136. cap_name, index);
  137. offset = xhci_find_next_ext_cap(base, offset, cap_id);
  138. index++;
  139. }
  140. }
  141. static int xhci_ring_enqueue_show(struct seq_file *s, void *unused)
  142. {
  143. dma_addr_t dma;
  144. struct xhci_ring *ring = *(struct xhci_ring **)s->private;
  145. dma = xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue);
  146. seq_printf(s, "%pad\n", &dma);
  147. return 0;
  148. }
  149. static int xhci_ring_dequeue_show(struct seq_file *s, void *unused)
  150. {
  151. dma_addr_t dma;
  152. struct xhci_ring *ring = *(struct xhci_ring **)s->private;
  153. dma = xhci_trb_virt_to_dma(ring->deq_seg, ring->dequeue);
  154. seq_printf(s, "%pad\n", &dma);
  155. return 0;
  156. }
  157. static int xhci_ring_cycle_show(struct seq_file *s, void *unused)
  158. {
  159. struct xhci_ring *ring = *(struct xhci_ring **)s->private;
  160. seq_printf(s, "%d\n", ring->cycle_state);
  161. return 0;
  162. }
  163. static void xhci_ring_dump_segment(struct seq_file *s,
  164. struct xhci_segment *seg)
  165. {
  166. int i;
  167. dma_addr_t dma;
  168. union xhci_trb *trb;
  169. char str[XHCI_MSG_MAX];
  170. for (i = 0; i < TRBS_PER_SEGMENT; i++) {
  171. trb = &seg->trbs[i];
  172. dma = seg->dma + i * sizeof(*trb);
  173. seq_printf(s, "%2u %pad: %s\n", seg->num, &dma,
  174. xhci_decode_trb(str, XHCI_MSG_MAX, le32_to_cpu(trb->generic.field[0]),
  175. le32_to_cpu(trb->generic.field[1]),
  176. le32_to_cpu(trb->generic.field[2]),
  177. le32_to_cpu(trb->generic.field[3])));
  178. }
  179. }
  180. static int xhci_ring_trb_show(struct seq_file *s, void *unused)
  181. {
  182. struct xhci_ring *ring = *(struct xhci_ring **)s->private;
  183. struct xhci_segment *seg = ring->first_seg;
  184. xhci_for_each_ring_seg(ring->first_seg, seg)
  185. xhci_ring_dump_segment(s, seg);
  186. return 0;
  187. }
  188. static struct xhci_file_map ring_files[] = {
  189. {"enqueue", xhci_ring_enqueue_show, },
  190. {"dequeue", xhci_ring_dequeue_show, },
  191. {"cycle", xhci_ring_cycle_show, },
  192. {"trbs", xhci_ring_trb_show, },
  193. };
  194. static int xhci_ring_open(struct inode *inode, struct file *file)
  195. {
  196. int i;
  197. struct xhci_file_map *f_map;
  198. const char *file_name = file_dentry(file)->d_iname;
  199. for (i = 0; i < ARRAY_SIZE(ring_files); i++) {
  200. f_map = &ring_files[i];
  201. if (strcmp(f_map->name, file_name) == 0)
  202. break;
  203. }
  204. return single_open(file, f_map->show, inode->i_private);
  205. }
  206. static const struct file_operations xhci_ring_fops = {
  207. .open = xhci_ring_open,
  208. .read = seq_read,
  209. .llseek = seq_lseek,
  210. .release = single_release,
  211. };
  212. static int xhci_slot_context_show(struct seq_file *s, void *unused)
  213. {
  214. struct xhci_hcd *xhci;
  215. struct xhci_slot_ctx *slot_ctx;
  216. struct xhci_slot_priv *priv = s->private;
  217. struct xhci_virt_device *dev = priv->dev;
  218. char str[XHCI_MSG_MAX];
  219. xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus));
  220. slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx);
  221. seq_printf(s, "%pad: %s\n", &dev->out_ctx->dma,
  222. xhci_decode_slot_context(str,
  223. le32_to_cpu(slot_ctx->dev_info),
  224. le32_to_cpu(slot_ctx->dev_info2),
  225. le32_to_cpu(slot_ctx->tt_info),
  226. le32_to_cpu(slot_ctx->dev_state)));
  227. return 0;
  228. }
  229. static int xhci_endpoint_context_show(struct seq_file *s, void *unused)
  230. {
  231. int ep_index;
  232. dma_addr_t dma;
  233. struct xhci_hcd *xhci;
  234. struct xhci_ep_ctx *ep_ctx;
  235. struct xhci_slot_priv *priv = s->private;
  236. struct xhci_virt_device *dev = priv->dev;
  237. char str[XHCI_MSG_MAX];
  238. xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus));
  239. for (ep_index = 0; ep_index < 31; ep_index++) {
  240. ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
  241. dma = dev->out_ctx->dma + (ep_index + 1) * CTX_SIZE(xhci->hcc_params);
  242. seq_printf(s, "%pad: %s\n", &dma,
  243. xhci_decode_ep_context(str,
  244. le32_to_cpu(ep_ctx->ep_info),
  245. le32_to_cpu(ep_ctx->ep_info2),
  246. le64_to_cpu(ep_ctx->deq),
  247. le32_to_cpu(ep_ctx->tx_info)));
  248. }
  249. return 0;
  250. }
  251. static int xhci_device_name_show(struct seq_file *s, void *unused)
  252. {
  253. struct xhci_slot_priv *priv = s->private;
  254. struct xhci_virt_device *dev = priv->dev;
  255. seq_printf(s, "%s\n", dev_name(&dev->udev->dev));
  256. return 0;
  257. }
  258. static struct xhci_file_map context_files[] = {
  259. {"name", xhci_device_name_show, },
  260. {"slot-context", xhci_slot_context_show, },
  261. {"ep-context", xhci_endpoint_context_show, },
  262. };
  263. static int xhci_context_open(struct inode *inode, struct file *file)
  264. {
  265. int i;
  266. struct xhci_file_map *f_map;
  267. const char *file_name = file_dentry(file)->d_iname;
  268. for (i = 0; i < ARRAY_SIZE(context_files); i++) {
  269. f_map = &context_files[i];
  270. if (strcmp(f_map->name, file_name) == 0)
  271. break;
  272. }
  273. return single_open(file, f_map->show, inode->i_private);
  274. }
  275. static const struct file_operations xhci_context_fops = {
  276. .open = xhci_context_open,
  277. .read = seq_read,
  278. .llseek = seq_lseek,
  279. .release = single_release,
  280. };
  281. static int xhci_portsc_show(struct seq_file *s, void *unused)
  282. {
  283. struct xhci_port *port = s->private;
  284. u32 portsc;
  285. char str[XHCI_MSG_MAX];
  286. portsc = readl(port->addr);
  287. seq_printf(s, "%s\n", xhci_decode_portsc(str, portsc));
  288. return 0;
  289. }
  290. static int xhci_port_open(struct inode *inode, struct file *file)
  291. {
  292. return single_open(file, xhci_portsc_show, inode->i_private);
  293. }
  294. static ssize_t xhci_port_write(struct file *file, const char __user *ubuf,
  295. size_t count, loff_t *ppos)
  296. {
  297. struct seq_file *s = file->private_data;
  298. struct xhci_port *port = s->private;
  299. struct xhci_hcd *xhci = hcd_to_xhci(port->rhub->hcd);
  300. char buf[32];
  301. u32 portsc;
  302. unsigned long flags;
  303. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  304. return -EFAULT;
  305. if (!strncmp(buf, "compliance", 10)) {
  306. /* If CTC is clear, compliance is enabled by default */
  307. if (!HCC2_CTC(xhci->hcc_params2))
  308. return count;
  309. spin_lock_irqsave(&xhci->lock, flags);
  310. /* compliance mode can only be enabled on ports in RxDetect */
  311. portsc = readl(port->addr);
  312. if ((portsc & PORT_PLS_MASK) != XDEV_RXDETECT) {
  313. spin_unlock_irqrestore(&xhci->lock, flags);
  314. return -EPERM;
  315. }
  316. portsc = xhci_port_state_to_neutral(portsc);
  317. portsc &= ~PORT_PLS_MASK;
  318. portsc |= PORT_LINK_STROBE | XDEV_COMP_MODE;
  319. writel(portsc, port->addr);
  320. spin_unlock_irqrestore(&xhci->lock, flags);
  321. } else {
  322. return -EINVAL;
  323. }
  324. return count;
  325. }
  326. static const struct file_operations port_fops = {
  327. .open = xhci_port_open,
  328. .write = xhci_port_write,
  329. .read = seq_read,
  330. .llseek = seq_lseek,
  331. .release = single_release,
  332. };
  333. static void xhci_debugfs_create_files(struct xhci_hcd *xhci,
  334. struct xhci_file_map *files,
  335. size_t nentries, void *data,
  336. struct dentry *parent,
  337. const struct file_operations *fops)
  338. {
  339. int i;
  340. for (i = 0; i < nentries; i++)
  341. debugfs_create_file(files[i].name, 0444, parent, data, fops);
  342. }
  343. static struct dentry *xhci_debugfs_create_ring_dir(struct xhci_hcd *xhci,
  344. struct xhci_ring **ring,
  345. const char *name,
  346. struct dentry *parent)
  347. {
  348. struct dentry *dir;
  349. dir = debugfs_create_dir(name, parent);
  350. xhci_debugfs_create_files(xhci, ring_files, ARRAY_SIZE(ring_files),
  351. ring, dir, &xhci_ring_fops);
  352. return dir;
  353. }
  354. static void xhci_debugfs_create_context_files(struct xhci_hcd *xhci,
  355. struct dentry *parent,
  356. int slot_id)
  357. {
  358. struct xhci_virt_device *dev = xhci->devs[slot_id];
  359. xhci_debugfs_create_files(xhci, context_files,
  360. ARRAY_SIZE(context_files),
  361. dev->debugfs_private,
  362. parent, &xhci_context_fops);
  363. }
  364. void xhci_debugfs_create_endpoint(struct xhci_hcd *xhci,
  365. struct xhci_virt_device *dev,
  366. int ep_index)
  367. {
  368. struct xhci_ep_priv *epriv;
  369. struct xhci_slot_priv *spriv = dev->debugfs_private;
  370. if (!spriv)
  371. return;
  372. if (spriv->eps[ep_index])
  373. return;
  374. epriv = kzalloc(sizeof(*epriv), GFP_KERNEL);
  375. if (!epriv)
  376. return;
  377. epriv->show_ring = dev->eps[ep_index].ring;
  378. snprintf(epriv->name, sizeof(epriv->name), "ep%02d", ep_index);
  379. epriv->root = xhci_debugfs_create_ring_dir(xhci,
  380. &epriv->show_ring,
  381. epriv->name,
  382. spriv->root);
  383. spriv->eps[ep_index] = epriv;
  384. }
  385. void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci,
  386. struct xhci_virt_device *dev,
  387. int ep_index)
  388. {
  389. struct xhci_ep_priv *epriv;
  390. struct xhci_slot_priv *spriv = dev->debugfs_private;
  391. if (!spriv || !spriv->eps[ep_index])
  392. return;
  393. epriv = spriv->eps[ep_index];
  394. debugfs_remove_recursive(epriv->root);
  395. spriv->eps[ep_index] = NULL;
  396. kfree(epriv);
  397. }
  398. static int xhci_stream_id_show(struct seq_file *s, void *unused)
  399. {
  400. struct xhci_ep_priv *epriv = s->private;
  401. if (!epriv->stream_info)
  402. return -EPERM;
  403. seq_printf(s, "Show stream ID %d trb ring, supported [1 - %d]\n",
  404. epriv->stream_id, epriv->stream_info->num_streams - 1);
  405. return 0;
  406. }
  407. static int xhci_stream_id_open(struct inode *inode, struct file *file)
  408. {
  409. return single_open(file, xhci_stream_id_show, inode->i_private);
  410. }
  411. static ssize_t xhci_stream_id_write(struct file *file, const char __user *ubuf,
  412. size_t count, loff_t *ppos)
  413. {
  414. struct seq_file *s = file->private_data;
  415. struct xhci_ep_priv *epriv = s->private;
  416. int ret;
  417. u16 stream_id; /* MaxPStreams + 1 <= 16 */
  418. if (!epriv->stream_info)
  419. return -EPERM;
  420. /* Decimal number */
  421. ret = kstrtou16_from_user(ubuf, count, 10, &stream_id);
  422. if (ret)
  423. return ret;
  424. if (stream_id == 0 || stream_id >= epriv->stream_info->num_streams)
  425. return -EINVAL;
  426. epriv->stream_id = stream_id;
  427. epriv->show_ring = epriv->stream_info->stream_rings[stream_id];
  428. return count;
  429. }
  430. static const struct file_operations stream_id_fops = {
  431. .open = xhci_stream_id_open,
  432. .write = xhci_stream_id_write,
  433. .read = seq_read,
  434. .llseek = seq_lseek,
  435. .release = single_release,
  436. };
  437. static int xhci_stream_context_array_show(struct seq_file *s, void *unused)
  438. {
  439. struct xhci_ep_priv *epriv = s->private;
  440. struct xhci_stream_ctx *stream_ctx;
  441. dma_addr_t dma;
  442. int id;
  443. if (!epriv->stream_info)
  444. return -EPERM;
  445. seq_printf(s, "Allocated %d streams and %d stream context array entries\n",
  446. epriv->stream_info->num_streams,
  447. epriv->stream_info->num_stream_ctxs);
  448. for (id = 0; id < epriv->stream_info->num_stream_ctxs; id++) {
  449. stream_ctx = epriv->stream_info->stream_ctx_array + id;
  450. dma = epriv->stream_info->ctx_array_dma + id * 16;
  451. if (id < epriv->stream_info->num_streams)
  452. seq_printf(s, "%pad stream id %d deq %016llx\n", &dma,
  453. id, le64_to_cpu(stream_ctx->stream_ring));
  454. else
  455. seq_printf(s, "%pad stream context entry not used deq %016llx\n",
  456. &dma, le64_to_cpu(stream_ctx->stream_ring));
  457. }
  458. return 0;
  459. }
  460. DEFINE_SHOW_ATTRIBUTE(xhci_stream_context_array);
  461. void xhci_debugfs_create_stream_files(struct xhci_hcd *xhci,
  462. struct xhci_virt_device *dev,
  463. int ep_index)
  464. {
  465. struct xhci_slot_priv *spriv = dev->debugfs_private;
  466. struct xhci_ep_priv *epriv;
  467. if (!spriv || !spriv->eps[ep_index] ||
  468. !dev->eps[ep_index].stream_info)
  469. return;
  470. epriv = spriv->eps[ep_index];
  471. epriv->stream_info = dev->eps[ep_index].stream_info;
  472. /* Show trb ring of stream ID 1 by default */
  473. epriv->stream_id = 1;
  474. epriv->show_ring = epriv->stream_info->stream_rings[1];
  475. debugfs_create_file("stream_id", 0644,
  476. epriv->root, epriv,
  477. &stream_id_fops);
  478. debugfs_create_file("stream_context_array", 0444,
  479. epriv->root, epriv,
  480. &xhci_stream_context_array_fops);
  481. }
  482. void xhci_debugfs_create_slot(struct xhci_hcd *xhci, int slot_id)
  483. {
  484. struct xhci_slot_priv *priv;
  485. struct xhci_virt_device *dev = xhci->devs[slot_id];
  486. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  487. if (!priv)
  488. return;
  489. snprintf(priv->name, sizeof(priv->name), "%02d", slot_id);
  490. priv->root = debugfs_create_dir(priv->name, xhci->debugfs_slots);
  491. priv->dev = dev;
  492. dev->debugfs_private = priv;
  493. xhci_debugfs_create_ring_dir(xhci, &dev->eps[0].ring,
  494. "ep00", priv->root);
  495. xhci_debugfs_create_context_files(xhci, priv->root, slot_id);
  496. }
  497. void xhci_debugfs_remove_slot(struct xhci_hcd *xhci, int slot_id)
  498. {
  499. int i;
  500. struct xhci_slot_priv *priv;
  501. struct xhci_virt_device *dev = xhci->devs[slot_id];
  502. if (!dev || !dev->debugfs_private)
  503. return;
  504. priv = dev->debugfs_private;
  505. debugfs_remove_recursive(priv->root);
  506. for (i = 0; i < 31; i++)
  507. kfree(priv->eps[i]);
  508. kfree(priv);
  509. dev->debugfs_private = NULL;
  510. }
  511. static void xhci_debugfs_create_ports(struct xhci_hcd *xhci,
  512. struct dentry *parent)
  513. {
  514. unsigned int num_ports;
  515. char port_name[8];
  516. struct xhci_port *port;
  517. struct dentry *dir;
  518. num_ports = HCS_MAX_PORTS(xhci->hcs_params1);
  519. parent = debugfs_create_dir("ports", parent);
  520. while (num_ports--) {
  521. scnprintf(port_name, sizeof(port_name), "port%02d",
  522. num_ports + 1);
  523. dir = debugfs_create_dir(port_name, parent);
  524. port = &xhci->hw_ports[num_ports];
  525. debugfs_create_file("portsc", 0644, dir, port, &port_fops);
  526. }
  527. }
  528. void xhci_debugfs_init(struct xhci_hcd *xhci)
  529. {
  530. struct device *dev = xhci_to_hcd(xhci)->self.controller;
  531. xhci->debugfs_root = debugfs_create_dir(dev_name(dev),
  532. xhci_debugfs_root);
  533. INIT_LIST_HEAD(&xhci->regset_list);
  534. xhci_debugfs_regset(xhci,
  535. 0,
  536. xhci_cap_regs, ARRAY_SIZE(xhci_cap_regs),
  537. xhci->debugfs_root, "reg-cap");
  538. xhci_debugfs_regset(xhci,
  539. HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)),
  540. xhci_op_regs, ARRAY_SIZE(xhci_op_regs),
  541. xhci->debugfs_root, "reg-op");
  542. xhci_debugfs_regset(xhci,
  543. readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK,
  544. xhci_runtime_regs, ARRAY_SIZE(xhci_runtime_regs),
  545. xhci->debugfs_root, "reg-runtime");
  546. xhci_debugfs_extcap_regset(xhci, XHCI_EXT_CAPS_LEGACY,
  547. xhci_extcap_legsup,
  548. ARRAY_SIZE(xhci_extcap_legsup),
  549. "reg-ext-legsup");
  550. xhci_debugfs_extcap_regset(xhci, XHCI_EXT_CAPS_PROTOCOL,
  551. xhci_extcap_protocol,
  552. ARRAY_SIZE(xhci_extcap_protocol),
  553. "reg-ext-protocol");
  554. xhci_debugfs_extcap_regset(xhci, XHCI_EXT_CAPS_DEBUG,
  555. xhci_extcap_dbc,
  556. ARRAY_SIZE(xhci_extcap_dbc),
  557. "reg-ext-dbc");
  558. xhci_debugfs_create_ring_dir(xhci, &xhci->cmd_ring,
  559. "command-ring",
  560. xhci->debugfs_root);
  561. xhci_debugfs_create_ring_dir(xhci, &xhci->interrupters[0]->event_ring,
  562. "event-ring",
  563. xhci->debugfs_root);
  564. xhci->debugfs_slots = debugfs_create_dir("devices", xhci->debugfs_root);
  565. xhci_debugfs_create_ports(xhci, xhci->debugfs_root);
  566. }
  567. void xhci_debugfs_exit(struct xhci_hcd *xhci)
  568. {
  569. struct xhci_regset *rgs, *tmp;
  570. debugfs_remove_recursive(xhci->debugfs_root);
  571. xhci->debugfs_root = NULL;
  572. xhci->debugfs_slots = NULL;
  573. list_for_each_entry_safe(rgs, tmp, &xhci->regset_list, list)
  574. xhci_debugfs_free_regset(rgs);
  575. }
  576. void __init xhci_debugfs_create_root(void)
  577. {
  578. xhci_debugfs_root = debugfs_create_dir("xhci", usb_debug_root);
  579. }
  580. void __exit xhci_debugfs_remove_root(void)
  581. {
  582. debugfs_remove_recursive(xhci_debugfs_root);
  583. xhci_debugfs_root = NULL;
  584. }