Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2001-2002 by David Brownell |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the |
| 6 | * Free Software Foundation; either version 2 of the License, or (at your |
| 7 | * option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software Foundation, |
| 16 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 17 | */ |
| 18 | |
| 19 | /* this file is part of ehci-hcd.c */ |
| 20 | |
Oliver Neukum | 1c20163 | 2013-11-18 13:23:16 +0100 | [diff] [blame] | 21 | #ifdef CONFIG_DYNAMIC_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | /* check the values in the HCSPARAMS register |
| 24 | * (host controller _Structural_ parameters) |
| 25 | * see EHCI spec, Table 2-4 for each value |
| 26 | */ |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 27 | static void dbg_hcs_params(struct ehci_hcd *ehci, char *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 29 | u32 params = ehci_readl(ehci, &ehci->caps->hcs_params); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 31 | ehci_dbg(ehci, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n", |
| 33 | label, params, |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 34 | HCS_DEBUG_PORT(params), |
| 35 | HCS_INDICATOR(params) ? " ind" : "", |
| 36 | HCS_N_CC(params), |
| 37 | HCS_N_PCC(params), |
| 38 | HCS_PORTROUTED(params) ? "" : " ordered", |
| 39 | HCS_PPC(params) ? "" : " !ppc", |
| 40 | HCS_N_PORTS(params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | ); |
| 42 | /* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */ |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 43 | if (HCS_PORTROUTED(params)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | int i; |
| 45 | char buf [46], tmp [7], byte; |
| 46 | |
| 47 | buf[0] = 0; |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 48 | for (i = 0; i < HCS_N_PORTS(params); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | // FIXME MIPS won't readb() ... |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 50 | byte = readb(&ehci->caps->portroute[(i >> 1)]); |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 51 | sprintf(tmp, "%d ", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf))); |
| 53 | strcat(buf, tmp); |
| 54 | } |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 55 | ehci_dbg(ehci, "%s portroute %s\n", label, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | #else |
| 59 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 60 | static inline void dbg_hcs_params(struct ehci_hcd *ehci, char *label) {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #endif |
| 63 | |
Oliver Neukum | 1c20163 | 2013-11-18 13:23:16 +0100 | [diff] [blame] | 64 | #ifdef CONFIG_DYNAMIC_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | /* check the values in the HCCPARAMS register |
| 67 | * (host controller _Capability_ parameters) |
| 68 | * see EHCI Spec, Table 2-5 for each value |
| 69 | * */ |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 70 | static void dbg_hcc_params(struct ehci_hcd *ehci, char *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 72 | u32 params = ehci_readl(ehci, &ehci->caps->hcc_params); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 74 | if (HCC_ISOC_CACHE(params)) { |
| 75 | ehci_dbg(ehci, |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 76 | "%s hcc_params %04x caching frame %s%s%s\n", |
| 77 | label, params, |
| 78 | HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", |
| 79 | HCC_CANPARK(params) ? " park" : "", |
| 80 | HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } else { |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 82 | ehci_dbg(ehci, |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 83 | "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n", |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 84 | label, |
| 85 | params, |
| 86 | HCC_ISOC_THRES(params), |
| 87 | HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", |
| 88 | HCC_CANPARK(params) ? " park" : "", |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 89 | HCC_64BIT_ADDR(params) ? " 64 bit addr" : "", |
| 90 | HCC_LPM(params) ? " LPM" : "", |
| 91 | HCC_PER_PORT_CHANGE_EVENT(params) ? " ppce" : "", |
| 92 | HCC_HW_PREFETCH(params) ? " hw prefetch" : "", |
| 93 | HCC_32FRAME_PERIODIC_LIST(params) ? |
Masanari Iida | 855ef45 | 2012-02-17 23:06:47 +0900 | [diff] [blame] | 94 | " 32 periodic list" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | #else |
| 98 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 99 | static inline void dbg_hcc_params(struct ehci_hcd *ehci, char *label) {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | #endif |
| 102 | |
Oliver Neukum | 1c20163 | 2013-11-18 13:23:16 +0100 | [diff] [blame] | 103 | #ifdef CONFIG_DYNAMIC_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 105 | static void __maybe_unused |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 106 | dbg_qtd(const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 108 | ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd, |
| 109 | hc32_to_cpup(ehci, &qtd->hw_next), |
| 110 | hc32_to_cpup(ehci, &qtd->hw_alt_next), |
| 111 | hc32_to_cpup(ehci, &qtd->hw_token), |
| 112 | hc32_to_cpup(ehci, &qtd->hw_buf [0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | if (qtd->hw_buf [1]) |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 114 | ehci_dbg(ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n", |
| 115 | hc32_to_cpup(ehci, &qtd->hw_buf[1]), |
| 116 | hc32_to_cpup(ehci, &qtd->hw_buf[2]), |
| 117 | hc32_to_cpup(ehci, &qtd->hw_buf[3]), |
| 118 | hc32_to_cpup(ehci, &qtd->hw_buf[4])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 121 | static void __maybe_unused |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 122 | dbg_qh(const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 124 | struct ehci_qh_hw *hw = qh->hw; |
| 125 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 126 | ehci_dbg(ehci, "%s qh %p n%08x info %x %x qtd %x\n", label, |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 127 | qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current); |
| 128 | dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 131 | static void __maybe_unused |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 132 | dbg_itd(const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 134 | ehci_dbg(ehci, "%s [%d] itd %p, next %08x, urb %p\n", |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 135 | label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next), |
| 136 | itd->urb); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 137 | ehci_dbg(ehci, |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 138 | " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n", |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 139 | hc32_to_cpu(ehci, itd->hw_transaction[0]), |
| 140 | hc32_to_cpu(ehci, itd->hw_transaction[1]), |
| 141 | hc32_to_cpu(ehci, itd->hw_transaction[2]), |
| 142 | hc32_to_cpu(ehci, itd->hw_transaction[3]), |
| 143 | hc32_to_cpu(ehci, itd->hw_transaction[4]), |
| 144 | hc32_to_cpu(ehci, itd->hw_transaction[5]), |
| 145 | hc32_to_cpu(ehci, itd->hw_transaction[6]), |
| 146 | hc32_to_cpu(ehci, itd->hw_transaction[7])); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 147 | ehci_dbg(ehci, |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 148 | " buf: %08x %08x %08x %08x %08x %08x %08x\n", |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 149 | hc32_to_cpu(ehci, itd->hw_bufp[0]), |
| 150 | hc32_to_cpu(ehci, itd->hw_bufp[1]), |
| 151 | hc32_to_cpu(ehci, itd->hw_bufp[2]), |
| 152 | hc32_to_cpu(ehci, itd->hw_bufp[3]), |
| 153 | hc32_to_cpu(ehci, itd->hw_bufp[4]), |
| 154 | hc32_to_cpu(ehci, itd->hw_bufp[5]), |
| 155 | hc32_to_cpu(ehci, itd->hw_bufp[6])); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 156 | ehci_dbg(ehci, " index: %d %d %d %d %d %d %d %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | itd->index[0], itd->index[1], itd->index[2], |
| 158 | itd->index[3], itd->index[4], itd->index[5], |
| 159 | itd->index[6], itd->index[7]); |
| 160 | } |
| 161 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 162 | static void __maybe_unused |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 163 | dbg_sitd(const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 165 | ehci_dbg(ehci, "%s [%d] sitd %p, next %08x, urb %p\n", |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 166 | label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next), |
| 167 | sitd->urb); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 168 | ehci_dbg(ehci, |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 169 | " addr %08x sched %04x result %08x buf %08x %08x\n", |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 170 | hc32_to_cpu(ehci, sitd->hw_fullspeed_ep), |
| 171 | hc32_to_cpu(ehci, sitd->hw_uframe), |
| 172 | hc32_to_cpu(ehci, sitd->hw_results), |
| 173 | hc32_to_cpu(ehci, sitd->hw_buf[0]), |
| 174 | hc32_to_cpu(ehci, sitd->hw_buf[1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 177 | static int __maybe_unused |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 178 | dbg_status_buf(char *buf, unsigned len, const char *label, u32 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | { |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 180 | return scnprintf(buf, len, |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 181 | "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | label, label [0] ? " " : "", status, |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 183 | (status & STS_PPCE_MASK) ? " PPCE" : "", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | (status & STS_ASS) ? " Async" : "", |
| 185 | (status & STS_PSS) ? " Periodic" : "", |
| 186 | (status & STS_RECL) ? " Recl" : "", |
| 187 | (status & STS_HALT) ? " Halt" : "", |
| 188 | (status & STS_IAA) ? " IAA" : "", |
| 189 | (status & STS_FATAL) ? " FATAL" : "", |
| 190 | (status & STS_FLR) ? " FLR" : "", |
| 191 | (status & STS_PCD) ? " PCD" : "", |
| 192 | (status & STS_ERR) ? " ERR" : "", |
| 193 | (status & STS_INT) ? " INT" : "" |
| 194 | ); |
| 195 | } |
| 196 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 197 | static int __maybe_unused |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 198 | dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 200 | return scnprintf(buf, len, |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 201 | "%s%sintrenable %02x%s%s%s%s%s%s%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | label, label [0] ? " " : "", enable, |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 203 | (enable & STS_PPCE_MASK) ? " PPCE" : "", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | (enable & STS_IAA) ? " IAA" : "", |
| 205 | (enable & STS_FATAL) ? " FATAL" : "", |
| 206 | (enable & STS_FLR) ? " FLR" : "", |
| 207 | (enable & STS_PCD) ? " PCD" : "", |
| 208 | (enable & STS_ERR) ? " ERR" : "", |
| 209 | (enable & STS_INT) ? " INT" : "" |
| 210 | ); |
| 211 | } |
| 212 | |
| 213 | static const char *const fls_strings [] = |
| 214 | { "1024", "512", "256", "??" }; |
| 215 | |
| 216 | static int |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 217 | dbg_command_buf(char *buf, unsigned len, const char *label, u32 command) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 219 | return scnprintf(buf, len, |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 220 | "%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s " |
| 221 | "period=%s%s %s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | label, label [0] ? " " : "", command, |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 223 | (command & CMD_HIRD) ? " HIRD" : "", |
| 224 | (command & CMD_PPCEE) ? " PPCEE" : "", |
| 225 | (command & CMD_FSP) ? " FSP" : "", |
| 226 | (command & CMD_ASPE) ? " ASPE" : "", |
| 227 | (command & CMD_PSPE) ? " PSPE" : "", |
| 228 | (command & CMD_PARK) ? " park" : "(park)", |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 229 | CMD_PARK_CNT(command), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | (command >> 16) & 0x3f, |
| 231 | (command & CMD_LRESET) ? " LReset" : "", |
| 232 | (command & CMD_IAAD) ? " IAAD" : "", |
| 233 | (command & CMD_ASE) ? " Async" : "", |
| 234 | (command & CMD_PSE) ? " Periodic" : "", |
| 235 | fls_strings [(command >> 2) & 0x3], |
| 236 | (command & CMD_RESET) ? " Reset" : "", |
| 237 | (command & CMD_RUN) ? "RUN" : "HALT" |
| 238 | ); |
| 239 | } |
| 240 | |
| 241 | static int |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 242 | dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
| 244 | char *sig; |
| 245 | |
| 246 | /* signaling state */ |
| 247 | switch (status & (3 << 10)) { |
| 248 | case 0 << 10: sig = "se0"; break; |
| 249 | case 1 << 10: sig = "k"; break; /* low speed */ |
| 250 | case 2 << 10: sig = "j"; break; |
| 251 | default: sig = "?"; break; |
| 252 | } |
| 253 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 254 | return scnprintf(buf, len, |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 255 | "%s%sport:%d status %06x %d %s%s%s%s%s%s " |
| 256 | "sig=%s%s%s%s%s%s%s%s%s%s%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | label, label [0] ? " " : "", port, status, |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 258 | status>>25,/*device address */ |
| 259 | (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ACK ? |
| 260 | " ACK" : "", |
| 261 | (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_NYET ? |
| 262 | " NYET" : "", |
| 263 | (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_STALL ? |
| 264 | " STALL" : "", |
| 265 | (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ERR ? |
| 266 | " ERR" : "", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | (status & PORT_POWER) ? " POWER" : "", |
| 268 | (status & PORT_OWNER) ? " OWNER" : "", |
| 269 | sig, |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 270 | (status & PORT_LPM) ? " LPM" : "", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | (status & PORT_RESET) ? " RESET" : "", |
| 272 | (status & PORT_SUSPEND) ? " SUSPEND" : "", |
| 273 | (status & PORT_RESUME) ? " RESUME" : "", |
| 274 | (status & PORT_OCC) ? " OCC" : "", |
| 275 | (status & PORT_OC) ? " OC" : "", |
| 276 | (status & PORT_PEC) ? " PEC" : "", |
| 277 | (status & PORT_PE) ? " PE" : "", |
| 278 | (status & PORT_CSC) ? " CSC" : "", |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 279 | (status & PORT_CONNECT) ? " CONNECT" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | #else |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 283 | static inline void __maybe_unused |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 284 | dbg_qh(char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | {} |
| 286 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 287 | static inline int __maybe_unused |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 288 | dbg_status_buf(char *buf, unsigned len, const char *label, u32 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | { return 0; } |
| 290 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 291 | static inline int __maybe_unused |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 292 | dbg_command_buf(char *buf, unsigned len, const char *label, u32 command) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { return 0; } |
| 294 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 295 | static inline int __maybe_unused |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 296 | dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { return 0; } |
| 298 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 299 | static inline int __maybe_unused |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 300 | dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | { return 0; } |
| 302 | |
Oliver Neukum | 1c20163 | 2013-11-18 13:23:16 +0100 | [diff] [blame] | 303 | #endif /* CONFIG_DYNAMIC_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | /* functions have the "wrong" filename when they're output... */ |
| 306 | #define dbg_status(ehci, label, status) { \ |
| 307 | char _buf [80]; \ |
| 308 | dbg_status_buf (_buf, sizeof _buf, label, status); \ |
| 309 | ehci_dbg (ehci, "%s\n", _buf); \ |
| 310 | } |
| 311 | |
| 312 | #define dbg_cmd(ehci, label, command) { \ |
| 313 | char _buf [80]; \ |
| 314 | dbg_command_buf (_buf, sizeof _buf, label, command); \ |
| 315 | ehci_dbg (ehci, "%s\n", _buf); \ |
| 316 | } |
| 317 | |
| 318 | #define dbg_port(ehci, label, port, status) { \ |
| 319 | char _buf [80]; \ |
| 320 | dbg_port_buf (_buf, sizeof _buf, label, port, status); \ |
| 321 | ehci_dbg (ehci, "%s\n", _buf); \ |
| 322 | } |
| 323 | |
| 324 | /*-------------------------------------------------------------------------*/ |
| 325 | |
| 326 | #ifdef STUB_DEBUG_FILES |
| 327 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 328 | static inline void create_debug_files(struct ehci_hcd *bus) { } |
| 329 | static inline void remove_debug_files(struct ehci_hcd *bus) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | #else |
| 332 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 333 | /* troubleshooting help: expose state in debugfs */ |
| 334 | |
| 335 | static int debug_async_open(struct inode *, struct file *); |
Alan Stern | d0ce5c6 | 2013-10-11 11:29:13 -0400 | [diff] [blame] | 336 | static int debug_bandwidth_open(struct inode *, struct file *); |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 337 | static int debug_periodic_open(struct inode *, struct file *); |
| 338 | static int debug_registers_open(struct inode *, struct file *); |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 339 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 340 | static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*); |
| 341 | static int debug_close(struct inode *, struct file *); |
| 342 | |
| 343 | static const struct file_operations debug_async_fops = { |
| 344 | .owner = THIS_MODULE, |
| 345 | .open = debug_async_open, |
| 346 | .read = debug_output, |
| 347 | .release = debug_close, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 348 | .llseek = default_llseek, |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 349 | }; |
Alan Stern | d0ce5c6 | 2013-10-11 11:29:13 -0400 | [diff] [blame] | 350 | static const struct file_operations debug_bandwidth_fops = { |
| 351 | .owner = THIS_MODULE, |
| 352 | .open = debug_bandwidth_open, |
| 353 | .read = debug_output, |
| 354 | .release = debug_close, |
| 355 | .llseek = default_llseek, |
| 356 | }; |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 357 | static const struct file_operations debug_periodic_fops = { |
| 358 | .owner = THIS_MODULE, |
| 359 | .open = debug_periodic_open, |
| 360 | .read = debug_output, |
| 361 | .release = debug_close, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 362 | .llseek = default_llseek, |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 363 | }; |
| 364 | static const struct file_operations debug_registers_fops = { |
| 365 | .owner = THIS_MODULE, |
| 366 | .open = debug_registers_open, |
| 367 | .read = debug_output, |
| 368 | .release = debug_close, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 369 | .llseek = default_llseek, |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 370 | }; |
| 371 | |
| 372 | static struct dentry *ehci_debug_root; |
| 373 | |
| 374 | struct debug_buffer { |
| 375 | ssize_t (*fill_func)(struct debug_buffer *); /* fill method */ |
| 376 | struct usb_bus *bus; |
| 377 | struct mutex mutex; /* protect filling of buffer */ |
| 378 | size_t count; /* number of characters filled into buffer */ |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 379 | char *output_buf; |
| 380 | size_t alloc_size; |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 381 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | #define speed_char(info1) ({ char tmp; \ |
| 384 | switch (info1 & (3 << 12)) { \ |
Alan Stern | 4c53de7 | 2012-07-11 11:21:32 -0400 | [diff] [blame] | 385 | case QH_FULL_SPEED: tmp = 'f'; break; \ |
| 386 | case QH_LOW_SPEED: tmp = 'l'; break; \ |
| 387 | case QH_HIGH_SPEED: tmp = 'h'; break; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | default: tmp = '?'; break; \ |
Joe Perches | 2b84f92 | 2013-10-08 16:01:37 -0700 | [diff] [blame] | 389 | } tmp; }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 391 | static inline char token_mark(struct ehci_hcd *ehci, __hc32 token) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | { |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 393 | __u32 v = hc32_to_cpu(ehci, token); |
| 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | if (v & QTD_STS_ACTIVE) |
| 396 | return '*'; |
| 397 | if (v & QTD_STS_HALT) |
| 398 | return '-'; |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 399 | if (!IS_SHORT_READ(v)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | return ' '; |
| 401 | /* tries to advance through hw_alt_next */ |
| 402 | return '/'; |
| 403 | } |
| 404 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 405 | static void qh_lines( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | struct ehci_hcd *ehci, |
| 407 | struct ehci_qh *qh, |
| 408 | char **nextp, |
| 409 | unsigned *sizep |
| 410 | ) |
| 411 | { |
| 412 | u32 scratch; |
| 413 | u32 hw_curr; |
| 414 | struct list_head *entry; |
| 415 | struct ehci_qtd *td; |
| 416 | unsigned temp; |
| 417 | unsigned size = *sizep; |
| 418 | char *next = *nextp; |
| 419 | char mark; |
Al Viro | fd05e72 | 2008-04-28 07:00:16 +0100 | [diff] [blame] | 420 | __le32 list_end = EHCI_LIST_END(ehci); |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 421 | struct ehci_qh_hw *hw = qh->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 423 | if (hw->hw_qtd_next == list_end) /* NEC does this */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | mark = '@'; |
| 425 | else |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 426 | mark = token_mark(ehci, hw->hw_token); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | if (mark == '/') { /* qh_alt_next controls qh advance? */ |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 428 | if ((hw->hw_alt_next & QTD_MASK(ehci)) |
| 429 | == ehci->async->hw->hw_alt_next) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | mark = '#'; /* blocked */ |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 431 | else if (hw->hw_alt_next == list_end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | mark = '.'; /* use hw_qtd_next */ |
| 433 | /* else alt_next points to some other qtd */ |
| 434 | } |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 435 | scratch = hc32_to_cpup(ehci, &hw->hw_info1); |
| 436 | hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0; |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 437 | temp = scnprintf(next, size, |
Alan Stern | 8ee10d6 | 2015-11-20 13:53:45 -0500 | [diff] [blame] | 438 | "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)" |
| 439 | " [cur %08x next %08x buf[0] %08x]", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | qh, scratch & 0x007f, |
| 441 | speed_char (scratch), |
| 442 | (scratch >> 8) & 0x000f, |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 443 | scratch, hc32_to_cpup(ehci, &hw->hw_info2), |
| 444 | hc32_to_cpup(ehci, &hw->hw_token), mark, |
| 445 | (cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | ? "data1" : "data0", |
Alan Stern | 8ee10d6 | 2015-11-20 13:53:45 -0500 | [diff] [blame] | 447 | (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f, |
| 448 | hc32_to_cpup(ehci, &hw->hw_current), |
| 449 | hc32_to_cpup(ehci, &hw->hw_qtd_next), |
| 450 | hc32_to_cpup(ehci, &hw->hw_buf[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | size -= temp; |
| 452 | next += temp; |
| 453 | |
| 454 | /* hc may be modifying the list as we read it ... */ |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 455 | list_for_each(entry, &qh->qtd_list) { |
| 456 | td = list_entry(entry, struct ehci_qtd, qtd_list); |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 457 | scratch = hc32_to_cpup(ehci, &td->hw_token); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | mark = ' '; |
| 459 | if (hw_curr == td->qtd_dma) |
| 460 | mark = '*'; |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 461 | else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | mark = '+'; |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 463 | else if (QTD_LENGTH(scratch)) { |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 464 | if (td->hw_alt_next == ehci->async->hw->hw_alt_next) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | mark = '#'; |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 466 | else if (td->hw_alt_next != list_end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | mark = '/'; |
| 468 | } |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 469 | temp = snprintf(next, size, |
Alan Stern | 8ee10d6 | 2015-11-20 13:53:45 -0500 | [diff] [blame] | 470 | "\n\t%p%c%s len=%d %08x urb %p" |
| 471 | " [td %08x buf[0] %08x]", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | td, mark, ({ char *tmp; |
| 473 | switch ((scratch>>8)&0x03) { |
| 474 | case 0: tmp = "out"; break; |
| 475 | case 1: tmp = "in"; break; |
| 476 | case 2: tmp = "setup"; break; |
| 477 | default: tmp = "?"; break; |
| 478 | } tmp;}), |
| 479 | (scratch >> 16) & 0x7fff, |
| 480 | scratch, |
Alan Stern | 8ee10d6 | 2015-11-20 13:53:45 -0500 | [diff] [blame] | 481 | td->urb, |
| 482 | (u32) td->qtd_dma, |
| 483 | hc32_to_cpup(ehci, &td->hw_buf[0])); |
roel kluin | e64a521 | 2008-10-21 00:47:23 -0400 | [diff] [blame] | 484 | if (size < temp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | temp = size; |
| 486 | size -= temp; |
| 487 | next += temp; |
| 488 | if (temp == size) |
| 489 | goto done; |
| 490 | } |
| 491 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 492 | temp = snprintf(next, size, "\n"); |
roel kluin | e64a521 | 2008-10-21 00:47:23 -0400 | [diff] [blame] | 493 | if (size < temp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | temp = size; |
| 495 | size -= temp; |
| 496 | next += temp; |
| 497 | |
| 498 | done: |
| 499 | *sizep = size; |
| 500 | *nextp = next; |
| 501 | } |
| 502 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 503 | static ssize_t fill_async_buffer(struct debug_buffer *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | struct usb_hcd *hcd; |
| 506 | struct ehci_hcd *ehci; |
| 507 | unsigned long flags; |
| 508 | unsigned temp, size; |
| 509 | char *next; |
| 510 | struct ehci_qh *qh; |
| 511 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 512 | hcd = bus_to_hcd(buf->bus); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 513 | ehci = hcd_to_ehci(hcd); |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 514 | next = buf->output_buf; |
| 515 | size = buf->alloc_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 517 | *next = 0; |
| 518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | /* dumps a snapshot of the async schedule. |
| 520 | * usually empty except for long-term bulk reads, or head. |
| 521 | * one QH per line, and TDs we know about |
| 522 | */ |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 523 | spin_lock_irqsave(&ehci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh) |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 525 | qh_lines(ehci, qh, &next, &size); |
Alan Stern | 6e01875 | 2013-03-22 13:31:45 -0400 | [diff] [blame] | 526 | if (!list_empty(&ehci->async_unlink) && size > 0) { |
Alan Stern | 99ac5b1 | 2012-07-11 11:21:38 -0400 | [diff] [blame] | 527 | temp = scnprintf(next, size, "\nunlink =\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | size -= temp; |
| 529 | next += temp; |
| 530 | |
Alan Stern | 6e01875 | 2013-03-22 13:31:45 -0400 | [diff] [blame] | 531 | list_for_each_entry(qh, &ehci->async_unlink, unlink_node) { |
| 532 | if (size <= 0) |
| 533 | break; |
| 534 | qh_lines(ehci, qh, &next, &size); |
| 535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | } |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 537 | spin_unlock_irqrestore(&ehci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 539 | return strlen(buf->output_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Alan Stern | d0ce5c6 | 2013-10-11 11:29:13 -0400 | [diff] [blame] | 542 | static ssize_t fill_bandwidth_buffer(struct debug_buffer *buf) |
| 543 | { |
| 544 | struct ehci_hcd *ehci; |
Alan Stern | b35c500 | 2013-10-11 22:16:21 -0400 | [diff] [blame] | 545 | struct ehci_tt *tt; |
| 546 | struct ehci_per_sched *ps; |
Alan Stern | d0ce5c6 | 2013-10-11 11:29:13 -0400 | [diff] [blame] | 547 | unsigned temp, size; |
| 548 | char *next; |
| 549 | unsigned i; |
| 550 | u8 *bw; |
Alan Stern | b35c500 | 2013-10-11 22:16:21 -0400 | [diff] [blame] | 551 | u16 *bf; |
| 552 | u8 budget[EHCI_BANDWIDTH_SIZE]; |
Alan Stern | d0ce5c6 | 2013-10-11 11:29:13 -0400 | [diff] [blame] | 553 | |
| 554 | ehci = hcd_to_ehci(bus_to_hcd(buf->bus)); |
| 555 | next = buf->output_buf; |
| 556 | size = buf->alloc_size; |
| 557 | |
| 558 | *next = 0; |
| 559 | |
| 560 | spin_lock_irq(&ehci->lock); |
| 561 | |
| 562 | /* Dump the HS bandwidth table */ |
| 563 | temp = scnprintf(next, size, |
| 564 | "HS bandwidth allocation (us per microframe)\n"); |
| 565 | size -= temp; |
| 566 | next += temp; |
| 567 | for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) { |
| 568 | bw = &ehci->bandwidth[i]; |
| 569 | temp = scnprintf(next, size, |
| 570 | "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n", |
| 571 | i, bw[0], bw[1], bw[2], bw[3], |
| 572 | bw[4], bw[5], bw[6], bw[7]); |
| 573 | size -= temp; |
| 574 | next += temp; |
| 575 | } |
Alan Stern | b35c500 | 2013-10-11 22:16:21 -0400 | [diff] [blame] | 576 | |
| 577 | /* Dump all the FS/LS tables */ |
| 578 | list_for_each_entry(tt, &ehci->tt_list, tt_list) { |
| 579 | temp = scnprintf(next, size, |
| 580 | "\nTT %s port %d FS/LS bandwidth allocation (us per frame)\n", |
| 581 | dev_name(&tt->usb_tt->hub->dev), |
| 582 | tt->tt_port + !!tt->usb_tt->multi); |
| 583 | size -= temp; |
| 584 | next += temp; |
| 585 | |
| 586 | bf = tt->bandwidth; |
| 587 | temp = scnprintf(next, size, |
| 588 | " %5u%5u%5u%5u%5u%5u%5u%5u\n", |
| 589 | bf[0], bf[1], bf[2], bf[3], |
| 590 | bf[4], bf[5], bf[6], bf[7]); |
| 591 | size -= temp; |
| 592 | next += temp; |
| 593 | |
| 594 | temp = scnprintf(next, size, |
| 595 | "FS/LS budget (us per microframe)\n"); |
| 596 | size -= temp; |
| 597 | next += temp; |
| 598 | compute_tt_budget(budget, tt); |
| 599 | for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) { |
| 600 | bw = &budget[i]; |
| 601 | temp = scnprintf(next, size, |
| 602 | "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n", |
| 603 | i, bw[0], bw[1], bw[2], bw[3], |
| 604 | bw[4], bw[5], bw[6], bw[7]); |
| 605 | size -= temp; |
| 606 | next += temp; |
| 607 | } |
| 608 | list_for_each_entry(ps, &tt->ps_list, ps_list) { |
| 609 | temp = scnprintf(next, size, |
| 610 | "%s ep %02x: %4u @ %2u.%u+%u mask %04x\n", |
| 611 | dev_name(&ps->udev->dev), |
| 612 | ps->ep->desc.bEndpointAddress, |
| 613 | ps->tt_usecs, |
| 614 | ps->bw_phase, ps->phase_uf, |
| 615 | ps->bw_period, ps->cs_mask); |
| 616 | size -= temp; |
| 617 | next += temp; |
| 618 | } |
| 619 | } |
Alan Stern | d0ce5c6 | 2013-10-11 11:29:13 -0400 | [diff] [blame] | 620 | spin_unlock_irq(&ehci->lock); |
| 621 | |
| 622 | return next - buf->output_buf; |
| 623 | } |
| 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | #define DBG_SCHED_LIMIT 64 |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 626 | static ssize_t fill_periodic_buffer(struct debug_buffer *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | struct usb_hcd *hcd; |
| 629 | struct ehci_hcd *ehci; |
| 630 | unsigned long flags; |
| 631 | union ehci_shadow p, *seen; |
| 632 | unsigned temp, size, seen_count; |
| 633 | char *next; |
| 634 | unsigned i; |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 635 | __hc32 tag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Greg Kroah-Hartman | 911fdb6 | 2015-04-30 11:32:50 +0200 | [diff] [blame] | 637 | seen = kmalloc(DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC); |
| 638 | if (!seen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | return 0; |
| 640 | seen_count = 0; |
| 641 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 642 | hcd = bus_to_hcd(buf->bus); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 643 | ehci = hcd_to_ehci(hcd); |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 644 | next = buf->output_buf; |
| 645 | size = buf->alloc_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 647 | temp = scnprintf(next, size, "size = %d\n", ehci->periodic_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | size -= temp; |
| 649 | next += temp; |
| 650 | |
| 651 | /* dump a snapshot of the periodic schedule. |
| 652 | * iso changes, interrupt usually doesn't. |
| 653 | */ |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 654 | spin_lock_irqsave(&ehci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | for (i = 0; i < ehci->periodic_size; i++) { |
| 656 | p = ehci->pshadow [i]; |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 657 | if (likely(!p.ptr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | continue; |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 659 | tag = Q_NEXT_TYPE(ehci, ehci->periodic [i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 661 | temp = scnprintf(next, size, "%4d: ", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | size -= temp; |
| 663 | next += temp; |
| 664 | |
| 665 | do { |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 666 | struct ehci_qh_hw *hw; |
| 667 | |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 668 | switch (hc32_to_cpu(ehci, tag)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | case Q_TYPE_QH: |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 670 | hw = p.qh->hw; |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 671 | temp = scnprintf(next, size, " qh%d-%04x/%p", |
Alan Stern | ffa0248 | 2013-10-11 11:29:03 -0400 | [diff] [blame] | 672 | p.qh->ps.period, |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 673 | hc32_to_cpup(ehci, |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 674 | &hw->hw_info2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | /* uframe masks */ |
David Brownell | 7dedacf | 2005-08-04 18:06:41 -0700 | [diff] [blame] | 676 | & (QH_CMASK | QH_SMASK), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | p.qh); |
| 678 | size -= temp; |
| 679 | next += temp; |
| 680 | /* don't repeat what follows this qh */ |
| 681 | for (temp = 0; temp < seen_count; temp++) { |
| 682 | if (seen [temp].ptr != p.ptr) |
| 683 | continue; |
Ming Lei | 3c4bb71 | 2008-09-18 23:06:38 +0800 | [diff] [blame] | 684 | if (p.qh->qh_next.ptr) { |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 685 | temp = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | " ..."); |
Ming Lei | 3c4bb71 | 2008-09-18 23:06:38 +0800 | [diff] [blame] | 687 | size -= temp; |
| 688 | next += temp; |
| 689 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | break; |
| 691 | } |
| 692 | /* show more info the first time around */ |
Ming Lei | 3c4bb71 | 2008-09-18 23:06:38 +0800 | [diff] [blame] | 693 | if (temp == seen_count) { |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 694 | u32 scratch = hc32_to_cpup(ehci, |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 695 | &hw->hw_info1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | struct ehci_qtd *qtd; |
| 697 | char *type = ""; |
| 698 | |
| 699 | /* count tds, get ep direction */ |
| 700 | temp = 0; |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 701 | list_for_each_entry(qtd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | &p.qh->qtd_list, |
| 703 | qtd_list) { |
| 704 | temp++; |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 705 | switch (0x03 & (hc32_to_cpu( |
| 706 | ehci, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | qtd->hw_token) >> 8)) { |
| 708 | case 0: type = "out"; continue; |
| 709 | case 1: type = "in"; continue; |
| 710 | } |
| 711 | } |
| 712 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 713 | temp = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | " (%c%d ep%d%s " |
| 715 | "[%d/%d] q%d p%d)", |
| 716 | speed_char (scratch), |
| 717 | scratch & 0x007f, |
| 718 | (scratch >> 8) & 0x000f, type, |
Alan Stern | ffa0248 | 2013-10-11 11:29:03 -0400 | [diff] [blame] | 719 | p.qh->ps.usecs, |
| 720 | p.qh->ps.c_usecs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | temp, |
| 722 | 0x7ff & (scratch >> 16)); |
| 723 | |
| 724 | if (seen_count < DBG_SCHED_LIMIT) |
| 725 | seen [seen_count++].qh = p.qh; |
| 726 | } else |
| 727 | temp = 0; |
Alan Stern | 17dcfc9 | 2012-09-19 17:00:55 -0400 | [diff] [blame] | 728 | tag = Q_NEXT_TYPE(ehci, hw->hw_next); |
| 729 | p = p.qh->qh_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | break; |
| 731 | case Q_TYPE_FSTN: |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 732 | temp = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | " fstn-%8x/%p", p.fstn->hw_prev, |
| 734 | p.fstn); |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 735 | tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | p = p.fstn->fstn_next; |
| 737 | break; |
| 738 | case Q_TYPE_ITD: |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 739 | temp = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | " itd/%p", p.itd); |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 741 | tag = Q_NEXT_TYPE(ehci, p.itd->hw_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | p = p.itd->itd_next; |
| 743 | break; |
| 744 | case Q_TYPE_SITD: |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 745 | temp = scnprintf(next, size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | " sitd%d-%04x/%p", |
Alan Stern | ffa0248 | 2013-10-11 11:29:03 -0400 | [diff] [blame] | 747 | p.sitd->stream->ps.period, |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 748 | hc32_to_cpup(ehci, &p.sitd->hw_uframe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | & 0x0000ffff, |
| 750 | p.sitd); |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 751 | tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | p = p.sitd->sitd_next; |
| 753 | break; |
| 754 | } |
| 755 | size -= temp; |
| 756 | next += temp; |
| 757 | } while (p.ptr); |
| 758 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 759 | temp = scnprintf(next, size, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | size -= temp; |
| 761 | next += temp; |
| 762 | } |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 763 | spin_unlock_irqrestore(&ehci->lock, flags); |
| 764 | kfree(seen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 766 | return buf->alloc_size - size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | #undef DBG_SCHED_LIMIT |
| 769 | |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 770 | static const char *rh_state_string(struct ehci_hcd *ehci) |
| 771 | { |
| 772 | switch (ehci->rh_state) { |
| 773 | case EHCI_RH_HALTED: |
| 774 | return "halted"; |
| 775 | case EHCI_RH_SUSPENDED: |
| 776 | return "suspended"; |
| 777 | case EHCI_RH_RUNNING: |
| 778 | return "running"; |
Alan Stern | c0c53db | 2012-07-11 11:21:48 -0400 | [diff] [blame] | 779 | case EHCI_RH_STOPPING: |
| 780 | return "stopping"; |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 781 | } |
| 782 | return "?"; |
| 783 | } |
| 784 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 785 | static ssize_t fill_registers_buffer(struct debug_buffer *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | struct usb_hcd *hcd; |
| 788 | struct ehci_hcd *ehci; |
| 789 | unsigned long flags; |
| 790 | unsigned temp, size, i; |
| 791 | char *next, scratch [80]; |
| 792 | static char fmt [] = "%*s\n"; |
| 793 | static char label [] = ""; |
| 794 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 795 | hcd = bus_to_hcd(buf->bus); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 796 | ehci = hcd_to_ehci(hcd); |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 797 | next = buf->output_buf; |
| 798 | size = buf->alloc_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 800 | spin_lock_irqsave(&ehci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
Alan Stern | 541c7d4 | 2010-06-22 16:39:10 -0400 | [diff] [blame] | 802 | if (!HCD_HW_ACCESSIBLE(hcd)) { |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 803 | size = scnprintf(next, size, |
Alan Stern | 2b70f07 | 2008-10-02 11:47:15 -0400 | [diff] [blame] | 804 | "bus %s, device %s\n" |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 805 | "%s\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | "SUSPENDED (no register access)\n", |
| 807 | hcd->self.controller->bus->name, |
Kay Sievers | 7071a3c | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 808 | dev_name(hcd->self.controller), |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 809 | hcd->product_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | goto done; |
| 811 | } |
| 812 | |
| 813 | /* Capability Registers */ |
Jan Andersson | c430131 | 2011-05-03 20:11:57 +0200 | [diff] [blame] | 814 | i = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 815 | temp = scnprintf(next, size, |
Alan Stern | 2b70f07 | 2008-10-02 11:47:15 -0400 | [diff] [blame] | 816 | "bus %s, device %s\n" |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 817 | "%s\n" |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 818 | "EHCI %x.%02x, rh state %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | hcd->self.controller->bus->name, |
Kay Sievers | 7071a3c | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 820 | dev_name(hcd->self.controller), |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 821 | hcd->product_desc, |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 822 | i >> 8, i & 0x0ff, rh_state_string(ehci)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | size -= temp; |
| 824 | next += temp; |
| 825 | |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 826 | #ifdef CONFIG_PCI |
| 827 | /* EHCI 0.96 and later may have "extended capabilities" */ |
Yijing Wang | e10e6f4 | 2013-12-05 19:21:32 +0800 | [diff] [blame] | 828 | if (dev_is_pci(hcd->self.controller)) { |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 829 | struct pci_dev *pdev; |
| 830 | u32 offset, cap, cap2; |
| 831 | unsigned count = 256/4; |
| 832 | |
| 833 | pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller); |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 834 | offset = HCC_EXT_CAPS(ehci_readl(ehci, |
| 835 | &ehci->caps->hcc_params)); |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 836 | while (offset && count--) { |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 837 | pci_read_config_dword(pdev, offset, &cap); |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 838 | switch (cap & 0xff) { |
| 839 | case 1: |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 840 | temp = scnprintf(next, size, |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 841 | "ownership %08x%s%s\n", cap, |
| 842 | (cap & (1 << 24)) ? " linux" : "", |
| 843 | (cap & (1 << 16)) ? " firmware" : ""); |
| 844 | size -= temp; |
| 845 | next += temp; |
| 846 | |
| 847 | offset += 4; |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 848 | pci_read_config_dword(pdev, offset, &cap2); |
| 849 | temp = scnprintf(next, size, |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 850 | "SMI sts/enable 0x%08x\n", cap2); |
| 851 | size -= temp; |
| 852 | next += temp; |
| 853 | break; |
| 854 | case 0: /* illegal reserved capability */ |
| 855 | cap = 0; |
| 856 | /* FALLTHROUGH */ |
| 857 | default: /* unknown */ |
| 858 | break; |
| 859 | } |
| 860 | temp = (cap >> 8) & 0xff; |
| 861 | } |
| 862 | } |
| 863 | #endif |
| 864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | // FIXME interpret both types of params |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 866 | i = ehci_readl(ehci, &ehci->caps->hcs_params); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 867 | temp = scnprintf(next, size, "structural params 0x%08x\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | size -= temp; |
| 869 | next += temp; |
| 870 | |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 871 | i = ehci_readl(ehci, &ehci->caps->hcc_params); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 872 | temp = scnprintf(next, size, "capability params 0x%08x\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | size -= temp; |
| 874 | next += temp; |
| 875 | |
| 876 | /* Operational Registers */ |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 877 | temp = dbg_status_buf(scratch, sizeof(scratch), label, |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 878 | ehci_readl(ehci, &ehci->regs->status)); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 879 | temp = scnprintf(next, size, fmt, temp, scratch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | size -= temp; |
| 881 | next += temp; |
| 882 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 883 | temp = dbg_command_buf(scratch, sizeof(scratch), label, |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 884 | ehci_readl(ehci, &ehci->regs->command)); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 885 | temp = scnprintf(next, size, fmt, temp, scratch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | size -= temp; |
| 887 | next += temp; |
| 888 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 889 | temp = dbg_intr_buf(scratch, sizeof(scratch), label, |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 890 | ehci_readl(ehci, &ehci->regs->intr_enable)); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 891 | temp = scnprintf(next, size, fmt, temp, scratch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | size -= temp; |
| 893 | next += temp; |
| 894 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 895 | temp = scnprintf(next, size, "uframe %04x\n", |
Alan Stern | 68aa95d | 2011-10-12 10:39:14 -0400 | [diff] [blame] | 896 | ehci_read_frame_index(ehci)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | size -= temp; |
| 898 | next += temp; |
| 899 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 900 | for (i = 1; i <= HCS_N_PORTS(ehci->hcs_params); i++) { |
| 901 | temp = dbg_port_buf(scratch, sizeof(scratch), label, i, |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 902 | ehci_readl(ehci, |
| 903 | &ehci->regs->port_status[i - 1])); |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 904 | temp = scnprintf(next, size, fmt, temp, scratch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | size -= temp; |
| 906 | next += temp; |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 907 | if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) { |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 908 | temp = scnprintf(next, size, |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 909 | " debug control %08x\n", |
Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 910 | ehci_readl(ehci, |
| 911 | &ehci->debug->control)); |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 912 | size -= temp; |
| 913 | next += temp; |
| 914 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Alan Stern | 6e01875 | 2013-03-22 13:31:45 -0400 | [diff] [blame] | 917 | if (!list_empty(&ehci->async_unlink)) { |
Alan Stern | 99ac5b1 | 2012-07-11 11:21:38 -0400 | [diff] [blame] | 918 | temp = scnprintf(next, size, "async unlink qh %p\n", |
Alan Stern | 6e01875 | 2013-03-22 13:31:45 -0400 | [diff] [blame] | 919 | list_first_entry(&ehci->async_unlink, |
| 920 | struct ehci_qh, unlink_node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | size -= temp; |
| 922 | next += temp; |
| 923 | } |
| 924 | |
| 925 | #ifdef EHCI_STATS |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 926 | temp = scnprintf(next, size, |
Alan Stern | 99ac5b1 | 2012-07-11 11:21:38 -0400 | [diff] [blame] | 927 | "irq normal %ld err %ld iaa %ld (lost %ld)\n", |
| 928 | ehci->stats.normal, ehci->stats.error, ehci->stats.iaa, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | ehci->stats.lost_iaa); |
| 930 | size -= temp; |
| 931 | next += temp; |
| 932 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 933 | temp = scnprintf(next, size, "complete %ld unlink %ld\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | ehci->stats.complete, ehci->stats.unlink); |
| 935 | size -= temp; |
| 936 | next += temp; |
| 937 | #endif |
| 938 | |
| 939 | done: |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 940 | spin_unlock_irqrestore(&ehci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 942 | return buf->alloc_size - size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | } |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 944 | |
| 945 | static struct debug_buffer *alloc_buffer(struct usb_bus *bus, |
| 946 | ssize_t (*fill_func)(struct debug_buffer *)) |
| 947 | { |
| 948 | struct debug_buffer *buf; |
| 949 | |
| 950 | buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL); |
| 951 | |
| 952 | if (buf) { |
| 953 | buf->bus = bus; |
| 954 | buf->fill_func = fill_func; |
| 955 | mutex_init(&buf->mutex); |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 956 | buf->alloc_size = PAGE_SIZE; |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | return buf; |
| 960 | } |
| 961 | |
| 962 | static int fill_buffer(struct debug_buffer *buf) |
| 963 | { |
| 964 | int ret = 0; |
| 965 | |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 966 | if (!buf->output_buf) |
Jesper Juhl | 73f35c6 | 2010-11-09 00:10:52 +0100 | [diff] [blame] | 967 | buf->output_buf = vmalloc(buf->alloc_size); |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 968 | |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 969 | if (!buf->output_buf) { |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 970 | ret = -ENOMEM; |
| 971 | goto out; |
| 972 | } |
| 973 | |
| 974 | ret = buf->fill_func(buf); |
| 975 | |
| 976 | if (ret >= 0) { |
| 977 | buf->count = ret; |
| 978 | ret = 0; |
| 979 | } |
| 980 | |
| 981 | out: |
| 982 | return ret; |
| 983 | } |
| 984 | |
| 985 | static ssize_t debug_output(struct file *file, char __user *user_buf, |
| 986 | size_t len, loff_t *offset) |
| 987 | { |
| 988 | struct debug_buffer *buf = file->private_data; |
| 989 | int ret = 0; |
| 990 | |
| 991 | mutex_lock(&buf->mutex); |
| 992 | if (buf->count == 0) { |
| 993 | ret = fill_buffer(buf); |
| 994 | if (ret != 0) { |
| 995 | mutex_unlock(&buf->mutex); |
| 996 | goto out; |
| 997 | } |
| 998 | } |
| 999 | mutex_unlock(&buf->mutex); |
| 1000 | |
| 1001 | ret = simple_read_from_buffer(user_buf, len, offset, |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 1002 | buf->output_buf, buf->count); |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1003 | |
| 1004 | out: |
| 1005 | return ret; |
| 1006 | |
| 1007 | } |
| 1008 | |
| 1009 | static int debug_close(struct inode *inode, struct file *file) |
| 1010 | { |
| 1011 | struct debug_buffer *buf = file->private_data; |
| 1012 | |
| 1013 | if (buf) { |
Figo.zhang | f8086a0 | 2009-06-06 20:31:49 +0800 | [diff] [blame] | 1014 | vfree(buf->output_buf); |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1015 | kfree(buf); |
| 1016 | } |
| 1017 | |
| 1018 | return 0; |
| 1019 | } |
Alan Stern | d0ce5c6 | 2013-10-11 11:29:13 -0400 | [diff] [blame] | 1020 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1021 | static int debug_async_open(struct inode *inode, struct file *file) |
| 1022 | { |
| 1023 | file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); |
| 1024 | |
| 1025 | return file->private_data ? 0 : -ENOMEM; |
| 1026 | } |
| 1027 | |
Alan Stern | d0ce5c6 | 2013-10-11 11:29:13 -0400 | [diff] [blame] | 1028 | static int debug_bandwidth_open(struct inode *inode, struct file *file) |
| 1029 | { |
| 1030 | file->private_data = alloc_buffer(inode->i_private, |
| 1031 | fill_bandwidth_buffer); |
| 1032 | |
| 1033 | return file->private_data ? 0 : -ENOMEM; |
| 1034 | } |
| 1035 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1036 | static int debug_periodic_open(struct inode *inode, struct file *file) |
| 1037 | { |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 1038 | struct debug_buffer *buf; |
| 1039 | buf = alloc_buffer(inode->i_private, fill_periodic_buffer); |
| 1040 | if (!buf) |
| 1041 | return -ENOMEM; |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1042 | |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 1043 | buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE; |
| 1044 | file->private_data = buf; |
| 1045 | return 0; |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | static int debug_registers_open(struct inode *inode, struct file *file) |
| 1049 | { |
| 1050 | file->private_data = alloc_buffer(inode->i_private, |
| 1051 | fill_registers_buffer); |
| 1052 | |
| 1053 | return file->private_data ? 0 : -ENOMEM; |
| 1054 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 1056 | static inline void create_debug_files(struct ehci_hcd *ehci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | { |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1058 | struct usb_bus *bus = &ehci_to_hcd(ehci)->self; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1060 | ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root); |
| 1061 | if (!ehci->debug_dir) |
Ming Lei | 185c9bc | 2010-07-28 22:33:28 +0800 | [diff] [blame] | 1062 | return; |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1063 | |
Ming Lei | 185c9bc | 2010-07-28 22:33:28 +0800 | [diff] [blame] | 1064 | if (!debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus, |
| 1065 | &debug_async_fops)) |
| 1066 | goto file_error; |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1067 | |
Alan Stern | d0ce5c6 | 2013-10-11 11:29:13 -0400 | [diff] [blame] | 1068 | if (!debugfs_create_file("bandwidth", S_IRUGO, ehci->debug_dir, bus, |
| 1069 | &debug_bandwidth_fops)) |
| 1070 | goto file_error; |
| 1071 | |
Ming Lei | 185c9bc | 2010-07-28 22:33:28 +0800 | [diff] [blame] | 1072 | if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus, |
| 1073 | &debug_periodic_fops)) |
| 1074 | goto file_error; |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1075 | |
Ming Lei | 185c9bc | 2010-07-28 22:33:28 +0800 | [diff] [blame] | 1076 | if (!debugfs_create_file("registers", S_IRUGO, ehci->debug_dir, bus, |
| 1077 | &debug_registers_fops)) |
| 1078 | goto file_error; |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 1079 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1080 | return; |
| 1081 | |
Ming Lei | 185c9bc | 2010-07-28 22:33:28 +0800 | [diff] [blame] | 1082 | file_error: |
| 1083 | debugfs_remove_recursive(ehci->debug_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
Geyslan G. Bem | 668ab0d | 2016-01-25 22:44:53 -0300 | [diff] [blame^] | 1086 | static inline void remove_debug_files(struct ehci_hcd *ehci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | { |
Ming Lei | 185c9bc | 2010-07-28 22:33:28 +0800 | [diff] [blame] | 1088 | debugfs_remove_recursive(ehci->debug_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | #endif /* STUB_DEBUG_FILES */ |