xhci-debugfs.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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 <[email protected]>
  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, "%pad: %s\n", &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. int i;
  183. struct xhci_ring *ring = *(struct xhci_ring **)s->private;
  184. struct xhci_segment *seg = ring->first_seg;
  185. for (i = 0; i < ring->num_segs; i++) {
  186. xhci_ring_dump_segment(s, seg);
  187. seg = seg->next;
  188. }
  189. return 0;
  190. }
  191. static struct xhci_file_map ring_files[] = {
  192. {"enqueue", xhci_ring_enqueue_show, },
  193. {"dequeue", xhci_ring_dequeue_show, },
  194. {"cycle", xhci_ring_cycle_show, },
  195. {"trbs", xhci_ring_trb_show, },
  196. };
  197. static int xhci_ring_open(struct inode *inode, struct file *file)
  198. {
  199. int i;
  200. struct xhci_file_map *f_map;
  201. const char *file_name = file_dentry(file)->d_iname;
  202. for (i = 0; i < ARRAY_SIZE(ring_files); i++) {
  203. f_map = &ring_files[i];
  204. if (strcmp(f_map->name, file_name) == 0)
  205. break;
  206. }
  207. return single_open(file, f_map->show, inode->i_private);
  208. }
  209. static const struct file_operations xhci_ring_fops = {
  210. .open = xhci_ring_open,
  211. .read = seq_read,
  212. .llseek = seq_lseek,
  213. .release = single_release,
  214. };
  215. static int xhci_slot_context_show(struct seq_file *s, void *unused)
  216. {
  217. struct xhci_hcd *xhci;
  218. struct xhci_slot_ctx *slot_ctx;
  219. struct xhci_slot_priv *priv = s->private;
  220. struct xhci_virt_device *dev = priv->dev;
  221. char str[XHCI_MSG_MAX];
  222. xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus));
  223. slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx);
  224. seq_printf(s, "%pad: %s\n", &dev->out_ctx->dma,
  225. xhci_decode_slot_context(str,
  226. le32_to_cpu(slot_ctx->dev_info),
  227. le32_to_cpu(slot_ctx->dev_info2),
  228. le32_to_cpu(slot_ctx->tt_info),
  229. le32_to_cpu(slot_ctx->dev_state)));
  230. return 0;
  231. }
  232. static int xhci_endpoint_context_show(struct seq_file *s, void *unused)
  233. {
  234. int ep_index;
  235. dma_addr_t dma;
  236. struct xhci_hcd *xhci;
  237. struct xhci_ep_ctx *ep_ctx;
  238. struct xhci_slot_priv *priv = s->private;
  239. struct xhci_virt_device *dev = priv->dev;
  240. char str[XHCI_MSG_MAX];
  241. xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus));
  242. for (ep_index = 0; ep_index < 31; ep_index++) {
  243. ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
  244. dma = dev->out_ctx->dma + (ep_index + 1) * CTX_SIZE(xhci->hcc_params);
  245. seq_printf(s, "%pad: %s\n", &dma,
  246. xhci_decode_ep_context(str,
  247. le32_to_cpu(ep_ctx->ep_info),
  248. le32_to_cpu(ep_ctx->ep_info2),
  249. le64_to_cpu(ep_ctx->deq),
  250. le32_to_cpu(ep_ctx->tx_info)));
  251. }
  252. return 0;
  253. }
  254. static int xhci_device_name_show(struct seq_file *s, void *unused)
  255. {
  256. struct xhci_slot_priv *priv = s->private;
  257. struct xhci_virt_device *dev = priv->dev;
  258. seq_printf(s, "%s\n", dev_name(&dev->udev->dev));
  259. return 0;
  260. }
  261. static struct xhci_file_map context_files[] = {
  262. {"name", xhci_device_name_show, },
  263. {"slot-context", xhci_slot_context_show, },
  264. {"ep-context", xhci_endpoint_context_show, },
  265. };
  266. static int xhci_context_open(struct inode *inode, struct file *file)
  267. {
  268. int i;
  269. struct xhci_file_map *f_map;
  270. const char *file_name = file_dentry(file)->d_iname;
  271. for (i = 0; i < ARRAY_SIZE(context_files); i++) {
  272. f_map = &context_files[i];
  273. if (strcmp(f_map->name, file_name) == 0)
  274. break;
  275. }
  276. return single_open(file, f_map->show, inode->i_private);
  277. }
  278. static const struct file_operations xhci_context_fops = {
  279. .open = xhci_context_open,
  280. .read = seq_read,
  281. .llseek = seq_lseek,
  282. .release = single_release,
  283. };
  284. static int xhci_portsc_show(struct seq_file *s, void *unused)
  285. {
  286. struct xhci_port *port = s->private;
  287. u32 portsc;
  288. char str[XHCI_MSG_MAX];
  289. portsc = readl(port->addr);
  290. seq_printf(s, "%s\n", xhci_decode_portsc(str, portsc));
  291. return 0;
  292. }
  293. static int xhci_port_open(struct inode *inode, struct file *file)
  294. {
  295. return single_open(file, xhci_portsc_show, inode->i_private);
  296. }
  297. static ssize_t xhci_port_write(struct file *file, const char __user *ubuf,
  298. size_t count, loff_t *ppos)
  299. {
  300. struct seq_file *s = file->private_data;
  301. struct xhci_port *port = s->private;
  302. struct xhci_hcd *xhci = hcd_to_xhci(port->rhub->hcd);
  303. char buf[32];
  304. u32 portsc;
  305. unsigned long flags;
  306. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  307. return -EFAULT;
  308. if (!strncmp(buf, "compliance", 10)) {
  309. /* If CTC is clear, compliance is enabled by default */
  310. if (!HCC2_CTC(xhci->hcc_params2))
  311. return count;
  312. spin_lock_irqsave(&xhci->lock, flags);
  313. /* compliance mode can only be enabled on ports in RxDetect */
  314. portsc = readl(port->addr);
  315. if ((portsc & PORT_PLS_MASK) != XDEV_RXDETECT) {
  316. spin_unlock_irqrestore(&xhci->lock, flags);
  317. return -EPERM;
  318. }
  319. portsc = xhci_port_state_to_neutral(portsc);
  320. portsc &= ~PORT_PLS_MASK;
  321. portsc |= PORT_LINK_STROBE | XDEV_COMP_MODE;
  322. writel(portsc, port->addr);
  323. spin_unlock_irqrestore(&xhci->lock, flags);
  324. } else {
  325. return -EINVAL;
  326. }
  327. return count;
  328. }
  329. static const struct file_operations port_fops = {
  330. .open = xhci_port_open,
  331. .write = xhci_port_write,
  332. .read = seq_read,
  333. .llseek = seq_lseek,
  334. .release = single_release,
  335. };
  336. static void xhci_debugfs_create_files(struct xhci_hcd *xhci,
  337. struct xhci_file_map *files,
  338. size_t nentries, void *data,
  339. struct dentry *parent,
  340. const struct file_operations *fops)
  341. {
  342. int i;
  343. for (i = 0; i < nentries; i++)
  344. debugfs_create_file(files[i].name, 0444, parent, data, fops);
  345. }
  346. static struct dentry *xhci_debugfs_create_ring_dir(struct xhci_hcd *xhci,
  347. struct xhci_ring **ring,
  348. const char *name,
  349. struct dentry *parent)
  350. {
  351. struct dentry *dir;
  352. dir = debugfs_create_dir(name, parent);
  353. xhci_debugfs_create_files(xhci, ring_files, ARRAY_SIZE(ring_files),
  354. ring, dir, &xhci_ring_fops);
  355. return dir;
  356. }
  357. static void xhci_debugfs_create_context_files(struct xhci_hcd *xhci,
  358. struct dentry *parent,
  359. int slot_id)
  360. {
  361. struct xhci_virt_device *dev = xhci->devs[slot_id];
  362. xhci_debugfs_create_files(xhci, context_files,
  363. ARRAY_SIZE(context_files),
  364. dev->debugfs_private,
  365. parent, &xhci_context_fops);
  366. }
  367. void xhci_debugfs_create_endpoint(struct xhci_hcd *xhci,
  368. struct xhci_virt_device *dev,
  369. int ep_index)
  370. {
  371. struct xhci_ep_priv *epriv;
  372. struct xhci_slot_priv *spriv = dev->debugfs_private;
  373. if (!spriv)
  374. return;
  375. if (spriv->eps[ep_index])
  376. return;
  377. epriv = kzalloc(sizeof(*epriv), GFP_KERNEL);
  378. if (!epriv)
  379. return;
  380. epriv->show_ring = dev->eps[ep_index].ring;
  381. snprintf(epriv->name, sizeof(epriv->name), "ep%02d", ep_index);
  382. epriv->root = xhci_debugfs_create_ring_dir(xhci,
  383. &epriv->show_ring,
  384. epriv->name,
  385. spriv->root);
  386. spriv->eps[ep_index] = epriv;
  387. }
  388. void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci,
  389. struct xhci_virt_device *dev,
  390. int ep_index)
  391. {
  392. struct xhci_ep_priv *epriv;
  393. struct xhci_slot_priv *spriv = dev->debugfs_private;
  394. if (!spriv || !spriv->eps[ep_index])
  395. return;
  396. epriv = spriv->eps[ep_index];
  397. debugfs_remove_recursive(epriv->root);
  398. spriv->eps[ep_index] = NULL;
  399. kfree(epriv);
  400. }
  401. static int xhci_stream_id_show(struct seq_file *s, void *unused)
  402. {
  403. struct xhci_ep_priv *epriv = s->private;
  404. if (!epriv->stream_info)
  405. return -EPERM;
  406. seq_printf(s, "Show stream ID %d trb ring, supported [1 - %d]\n",
  407. epriv->stream_id, epriv->stream_info->num_streams - 1);
  408. return 0;
  409. }
  410. static int xhci_stream_id_open(struct inode *inode, struct file *file)
  411. {
  412. return single_open(file, xhci_stream_id_show, inode->i_private);
  413. }
  414. static ssize_t xhci_stream_id_write(struct file *file, const char __user *ubuf,
  415. size_t count, loff_t *ppos)
  416. {
  417. struct seq_file *s = file->private_data;
  418. struct xhci_ep_priv *epriv = s->private;
  419. int ret;
  420. u16 stream_id; /* MaxPStreams + 1 <= 16 */
  421. if (!epriv->stream_info)
  422. return -EPERM;
  423. /* Decimal number */
  424. ret = kstrtou16_from_user(ubuf, count, 10, &stream_id);
  425. if (ret)
  426. return ret;
  427. if (stream_id == 0 || stream_id >= epriv->stream_info->num_streams)
  428. return -EINVAL;
  429. epriv->stream_id = stream_id;
  430. epriv->show_ring = epriv->stream_info->stream_rings[stream_id];
  431. return count;
  432. }
  433. static const struct file_operations stream_id_fops = {
  434. .open = xhci_stream_id_open,
  435. .write = xhci_stream_id_write,
  436. .read = seq_read,
  437. .llseek = seq_lseek,
  438. .release = single_release,
  439. };
  440. static int xhci_stream_context_array_show(struct seq_file *s, void *unused)
  441. {
  442. struct xhci_ep_priv *epriv = s->private;
  443. struct xhci_stream_ctx *stream_ctx;
  444. dma_addr_t dma;
  445. int id;
  446. if (!epriv->stream_info)
  447. return -EPERM;
  448. seq_printf(s, "Allocated %d streams and %d stream context array entries\n",
  449. epriv->stream_info->num_streams,
  450. epriv->stream_info->num_stream_ctxs);
  451. for (id = 0; id < epriv->stream_info->num_stream_ctxs; id++) {
  452. stream_ctx = epriv->stream_info->stream_ctx_array + id;
  453. dma = epriv->stream_info->ctx_array_dma + id * 16;
  454. if (id < epriv->stream_info->num_streams)
  455. seq_printf(s, "%pad stream id %d deq %016llx\n", &dma,
  456. id, le64_to_cpu(stream_ctx->stream_ring));
  457. else
  458. seq_printf(s, "%pad stream context entry not used deq %016llx\n",
  459. &dma, le64_to_cpu(stream_ctx->stream_ring));
  460. }
  461. return 0;
  462. }
  463. DEFINE_SHOW_ATTRIBUTE(xhci_stream_context_array);
  464. void xhci_debugfs_create_stream_files(struct xhci_hcd *xhci,
  465. struct xhci_virt_device *dev,
  466. int ep_index)
  467. {
  468. struct xhci_slot_priv *spriv = dev->debugfs_private;
  469. struct xhci_ep_priv *epriv;
  470. if (!spriv || !spriv->eps[ep_index] ||
  471. !dev->eps[ep_index].stream_info)
  472. return;
  473. epriv = spriv->eps[ep_index];
  474. epriv->stream_info = dev->eps[ep_index].stream_info;
  475. /* Show trb ring of stream ID 1 by default */
  476. epriv->stream_id = 1;
  477. epriv->show_ring = epriv->stream_info->stream_rings[1];
  478. debugfs_create_file("stream_id", 0644,
  479. epriv->root, epriv,
  480. &stream_id_fops);
  481. debugfs_create_file("stream_context_array", 0444,
  482. epriv->root, epriv,
  483. &xhci_stream_context_array_fops);
  484. }
  485. void xhci_debugfs_create_slot(struct xhci_hcd *xhci, int slot_id)
  486. {
  487. struct xhci_slot_priv *priv;
  488. struct xhci_virt_device *dev = xhci->devs[slot_id];
  489. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  490. if (!priv)
  491. return;
  492. snprintf(priv->name, sizeof(priv->name), "%02d", slot_id);
  493. priv->root = debugfs_create_dir(priv->name, xhci->debugfs_slots);
  494. priv->dev = dev;
  495. dev->debugfs_private = priv;
  496. xhci_debugfs_create_ring_dir(xhci, &dev->eps[0].ring,
  497. "ep00", priv->root);
  498. xhci_debugfs_create_context_files(xhci, priv->root, slot_id);
  499. }
  500. void xhci_debugfs_remove_slot(struct xhci_hcd *xhci, int slot_id)
  501. {
  502. int i;
  503. struct xhci_slot_priv *priv;
  504. struct xhci_virt_device *dev = xhci->devs[slot_id];
  505. if (!dev || !dev->debugfs_private)
  506. return;
  507. priv = dev->debugfs_private;
  508. debugfs_remove_recursive(priv->root);
  509. for (i = 0; i < 31; i++)
  510. kfree(priv->eps[i]);
  511. kfree(priv);
  512. dev->debugfs_private = NULL;
  513. }
  514. static void xhci_debugfs_create_ports(struct xhci_hcd *xhci,
  515. struct dentry *parent)
  516. {
  517. unsigned int num_ports;
  518. char port_name[8];
  519. struct xhci_port *port;
  520. struct dentry *dir;
  521. num_ports = HCS_MAX_PORTS(xhci->hcs_params1);
  522. parent = debugfs_create_dir("ports", parent);
  523. while (num_ports--) {
  524. scnprintf(port_name, sizeof(port_name), "port%02d",
  525. num_ports + 1);
  526. dir = debugfs_create_dir(port_name, parent);
  527. port = &xhci->hw_ports[num_ports];
  528. debugfs_create_file("portsc", 0644, dir, port, &port_fops);
  529. }
  530. }
  531. void xhci_debugfs_init(struct xhci_hcd *xhci)
  532. {
  533. struct device *dev = xhci_to_hcd(xhci)->self.controller;
  534. xhci->debugfs_root = debugfs_create_dir(dev_name(dev),
  535. xhci_debugfs_root);
  536. INIT_LIST_HEAD(&xhci->regset_list);
  537. xhci_debugfs_regset(xhci,
  538. 0,
  539. xhci_cap_regs, ARRAY_SIZE(xhci_cap_regs),
  540. xhci->debugfs_root, "reg-cap");
  541. xhci_debugfs_regset(xhci,
  542. HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)),
  543. xhci_op_regs, ARRAY_SIZE(xhci_op_regs),
  544. xhci->debugfs_root, "reg-op");
  545. xhci_debugfs_regset(xhci,
  546. readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK,
  547. xhci_runtime_regs, ARRAY_SIZE(xhci_runtime_regs),
  548. xhci->debugfs_root, "reg-runtime");
  549. xhci_debugfs_extcap_regset(xhci, XHCI_EXT_CAPS_LEGACY,
  550. xhci_extcap_legsup,
  551. ARRAY_SIZE(xhci_extcap_legsup),
  552. "reg-ext-legsup");
  553. xhci_debugfs_extcap_regset(xhci, XHCI_EXT_CAPS_PROTOCOL,
  554. xhci_extcap_protocol,
  555. ARRAY_SIZE(xhci_extcap_protocol),
  556. "reg-ext-protocol");
  557. xhci_debugfs_extcap_regset(xhci, XHCI_EXT_CAPS_DEBUG,
  558. xhci_extcap_dbc,
  559. ARRAY_SIZE(xhci_extcap_dbc),
  560. "reg-ext-dbc");
  561. xhci_debugfs_create_ring_dir(xhci, &xhci->cmd_ring,
  562. "command-ring",
  563. xhci->debugfs_root);
  564. xhci_debugfs_create_ring_dir(xhci, &xhci->event_ring,
  565. "event-ring",
  566. xhci->debugfs_root);
  567. xhci->debugfs_slots = debugfs_create_dir("devices", xhci->debugfs_root);
  568. xhci_debugfs_create_ports(xhci, xhci->debugfs_root);
  569. }
  570. void xhci_debugfs_exit(struct xhci_hcd *xhci)
  571. {
  572. struct xhci_regset *rgs, *tmp;
  573. debugfs_remove_recursive(xhci->debugfs_root);
  574. xhci->debugfs_root = NULL;
  575. xhci->debugfs_slots = NULL;
  576. list_for_each_entry_safe(rgs, tmp, &xhci->regset_list, list)
  577. xhci_debugfs_free_regset(rgs);
  578. }
  579. void __init xhci_debugfs_create_root(void)
  580. {
  581. xhci_debugfs_root = debugfs_create_dir("xhci", usb_debug_root);
  582. }
  583. void __exit xhci_debugfs_remove_root(void)
  584. {
  585. debugfs_remove_recursive(xhci_debugfs_root);
  586. xhci_debugfs_root = NULL;
  587. }