Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * UHCI-specific debugging code. Invaluable when something |
| 3 | * goes wrong, but don't get in my face. |
| 4 | * |
Alan Stern | 687f5f3 | 2005-11-30 17:16:19 -0500 | [diff] [blame] | 5 | * Kernel visible pointers are surrounded in []s and bus |
| 6 | * visible pointers are surrounded in ()s |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * (C) Copyright 1999 Linus Torvalds |
| 9 | * (C) Copyright 1999-2001 Johannes Erdfelt |
| 10 | */ |
| 11 | |
| 12 | #include <linux/config.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/debugfs.h> |
| 15 | #include <linux/smp_lock.h> |
| 16 | #include <asm/io.h> |
| 17 | |
| 18 | #include "uhci-hcd.h" |
| 19 | |
| 20 | static struct dentry *uhci_debugfs_root = NULL; |
| 21 | |
Alan Stern | 687f5f3 | 2005-11-30 17:16:19 -0500 | [diff] [blame] | 22 | /* Handle REALLY large printks so we don't overflow buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | static inline void lprintk(char *buf) |
| 24 | { |
| 25 | char *p; |
| 26 | |
| 27 | /* Just write one line at a time */ |
| 28 | while (buf) { |
| 29 | p = strchr(buf, '\n'); |
| 30 | if (p) |
| 31 | *p = 0; |
| 32 | printk(KERN_DEBUG "%s\n", buf); |
| 33 | buf = p; |
| 34 | if (buf) |
| 35 | buf++; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | static int uhci_show_td(struct uhci_td *td, char *buf, int len, int space) |
| 40 | { |
| 41 | char *out = buf; |
| 42 | char *spid; |
| 43 | u32 status, token; |
| 44 | |
| 45 | /* Try to make sure there's enough memory */ |
| 46 | if (len < 160) |
| 47 | return 0; |
| 48 | |
| 49 | status = td_status(td); |
| 50 | out += sprintf(out, "%*s[%p] link (%08x) ", space, "", td, le32_to_cpu(td->link)); |
| 51 | out += sprintf(out, "e%d %s%s%s%s%s%s%s%s%s%sLength=%x ", |
| 52 | ((status >> 27) & 3), |
| 53 | (status & TD_CTRL_SPD) ? "SPD " : "", |
| 54 | (status & TD_CTRL_LS) ? "LS " : "", |
| 55 | (status & TD_CTRL_IOC) ? "IOC " : "", |
| 56 | (status & TD_CTRL_ACTIVE) ? "Active " : "", |
| 57 | (status & TD_CTRL_STALLED) ? "Stalled " : "", |
| 58 | (status & TD_CTRL_DBUFERR) ? "DataBufErr " : "", |
| 59 | (status & TD_CTRL_BABBLE) ? "Babble " : "", |
| 60 | (status & TD_CTRL_NAK) ? "NAK " : "", |
| 61 | (status & TD_CTRL_CRCTIMEO) ? "CRC/Timeo " : "", |
| 62 | (status & TD_CTRL_BITSTUFF) ? "BitStuff " : "", |
| 63 | status & 0x7ff); |
| 64 | |
| 65 | token = td_token(td); |
| 66 | switch (uhci_packetid(token)) { |
| 67 | case USB_PID_SETUP: |
| 68 | spid = "SETUP"; |
| 69 | break; |
| 70 | case USB_PID_OUT: |
| 71 | spid = "OUT"; |
| 72 | break; |
| 73 | case USB_PID_IN: |
| 74 | spid = "IN"; |
| 75 | break; |
| 76 | default: |
| 77 | spid = "?"; |
| 78 | break; |
| 79 | } |
| 80 | |
| 81 | out += sprintf(out, "MaxLen=%x DT%d EndPt=%x Dev=%x, PID=%x(%s) ", |
| 82 | token >> 21, |
| 83 | ((token >> 19) & 1), |
| 84 | (token >> 15) & 15, |
| 85 | (token >> 8) & 127, |
| 86 | (token & 0xff), |
| 87 | spid); |
| 88 | out += sprintf(out, "(buf=%08x)\n", le32_to_cpu(td->buffer)); |
| 89 | |
| 90 | return out - buf; |
| 91 | } |
| 92 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 93 | static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space) |
| 94 | { |
| 95 | char *out = buf; |
| 96 | struct uhci_td *td; |
| 97 | int i, nactive, ninactive; |
| 98 | |
| 99 | if (len < 200) |
| 100 | return 0; |
| 101 | |
| 102 | out += sprintf(out, "urb_priv [%p] ", urbp); |
| 103 | out += sprintf(out, "urb [%p] ", urbp->urb); |
| 104 | out += sprintf(out, "qh [%p] ", urbp->qh); |
| 105 | out += sprintf(out, "Dev=%d ", usb_pipedevice(urbp->urb->pipe)); |
| 106 | out += sprintf(out, "EP=%x(%s) ", usb_pipeendpoint(urbp->urb->pipe), |
| 107 | (usb_pipein(urbp->urb->pipe) ? "IN" : "OUT")); |
| 108 | |
| 109 | switch (usb_pipetype(urbp->urb->pipe)) { |
| 110 | case PIPE_ISOCHRONOUS: out += sprintf(out, "ISO"); break; |
| 111 | case PIPE_INTERRUPT: out += sprintf(out, "INT"); break; |
| 112 | case PIPE_BULK: out += sprintf(out, "BLK"); break; |
| 113 | case PIPE_CONTROL: out += sprintf(out, "CTL"); break; |
| 114 | } |
| 115 | |
| 116 | out += sprintf(out, "%s", (urbp->fsbr ? " FSBR" : "")); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 117 | |
| 118 | if (urbp->urb->status != -EINPROGRESS) |
| 119 | out += sprintf(out, " Status=%d", urbp->urb->status); |
| 120 | out += sprintf(out, "\n"); |
| 121 | |
| 122 | i = nactive = ninactive = 0; |
| 123 | list_for_each_entry(td, &urbp->td_list, list) { |
| 124 | if (++i <= 10 || debug > 2) { |
| 125 | out += sprintf(out, "%*s%d: ", space + 2, "", i); |
| 126 | out += uhci_show_td(td, out, len - (out - buf), 0); |
| 127 | } else { |
| 128 | if (td_status(td) & TD_CTRL_ACTIVE) |
| 129 | ++nactive; |
| 130 | else |
| 131 | ++ninactive; |
| 132 | } |
| 133 | } |
| 134 | if (nactive + ninactive > 0) |
| 135 | out += sprintf(out, "%*s[skipped %d inactive and %d active " |
| 136 | "TDs]\n", |
| 137 | space, "", ninactive, nactive); |
| 138 | |
| 139 | return out - buf; |
| 140 | } |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space) |
| 143 | { |
| 144 | char *out = buf; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 145 | int i, nurbs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | __le32 element = qh_element(qh); |
| 147 | |
| 148 | /* Try to make sure there's enough memory */ |
| 149 | if (len < 80 * 6) |
| 150 | return 0; |
| 151 | |
| 152 | out += sprintf(out, "%*s[%p] link (%08x) element (%08x)\n", space, "", |
| 153 | qh, le32_to_cpu(qh->link), le32_to_cpu(element)); |
| 154 | |
| 155 | if (element & UHCI_PTR_QH) |
| 156 | out += sprintf(out, "%*s Element points to QH (bug?)\n", space, ""); |
| 157 | |
| 158 | if (element & UHCI_PTR_DEPTH) |
| 159 | out += sprintf(out, "%*s Depth traverse\n", space, ""); |
| 160 | |
| 161 | if (element & cpu_to_le32(8)) |
| 162 | out += sprintf(out, "%*s Bit 3 set (bug?)\n", space, ""); |
| 163 | |
| 164 | if (!(element & ~(UHCI_PTR_QH | UHCI_PTR_DEPTH))) |
| 165 | out += sprintf(out, "%*s Element is NULL (bug?)\n", space, ""); |
| 166 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 167 | if (list_empty(&qh->queue)) { |
| 168 | out += sprintf(out, "%*s queue is empty\n", space, ""); |
| 169 | } else { |
| 170 | struct urb_priv *urbp = list_entry(qh->queue.next, |
| 171 | struct urb_priv, node); |
| 172 | struct uhci_td *td = list_entry(urbp->td_list.next, |
| 173 | struct uhci_td, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 175 | if (cpu_to_le32(td->dma_handle) != (element & ~UHCI_PTR_BITS)) |
| 176 | out += sprintf(out, "%*s Element != First TD\n", |
| 177 | space, ""); |
| 178 | i = nurbs = 0; |
| 179 | list_for_each_entry(urbp, &qh->queue, node) { |
| 180 | if (++i <= 10) |
| 181 | out += uhci_show_urbp(urbp, out, |
| 182 | len - (out - buf), space + 2); |
| 183 | else |
| 184 | ++nurbs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 186 | if (nurbs > 0) |
| 187 | out += sprintf(out, "%*s Skipped %d URBs\n", |
| 188 | space, "", nurbs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 191 | if (qh->udev) { |
| 192 | out += sprintf(out, "%*s Dummy TD\n", space, ""); |
| 193 | out += uhci_show_td(qh->dummy_td, out, len - (out - buf), 0); |
| 194 | } |
| 195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | return out - buf; |
| 197 | } |
| 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | #ifdef CONFIG_PROC_FS |
Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 200 | static const char * const qh_names[] = { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 201 | "skel_unlink_qh", "skel_iso_qh", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | "skel_int128_qh", "skel_int64_qh", |
| 203 | "skel_int32_qh", "skel_int16_qh", |
| 204 | "skel_int8_qh", "skel_int4_qh", |
| 205 | "skel_int2_qh", "skel_int1_qh", |
| 206 | "skel_ls_control_qh", "skel_fs_control_qh", |
| 207 | "skel_bulk_qh", "skel_term_qh" |
| 208 | }; |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | static int uhci_show_sc(int port, unsigned short status, char *buf, int len) |
| 211 | { |
| 212 | char *out = buf; |
| 213 | |
| 214 | /* Try to make sure there's enough memory */ |
| 215 | if (len < 160) |
| 216 | return 0; |
| 217 | |
| 218 | out += sprintf(out, " stat%d = %04x %s%s%s%s%s%s%s%s%s%s\n", |
| 219 | port, |
| 220 | status, |
| 221 | (status & USBPORTSC_SUSP) ? " Suspend" : "", |
| 222 | (status & USBPORTSC_OCC) ? " OverCurrentChange" : "", |
| 223 | (status & USBPORTSC_OC) ? " OverCurrent" : "", |
| 224 | (status & USBPORTSC_PR) ? " Reset" : "", |
| 225 | (status & USBPORTSC_LSDA) ? " LowSpeed" : "", |
| 226 | (status & USBPORTSC_RD) ? " ResumeDetect" : "", |
| 227 | (status & USBPORTSC_PEC) ? " EnableChange" : "", |
| 228 | (status & USBPORTSC_PE) ? " Enabled" : "", |
| 229 | (status & USBPORTSC_CSC) ? " ConnectChange" : "", |
| 230 | (status & USBPORTSC_CCS) ? " Connected" : ""); |
| 231 | |
| 232 | return out - buf; |
| 233 | } |
| 234 | |
Alan Stern | c8f4fe4 | 2005-04-09 17:27:32 -0400 | [diff] [blame] | 235 | static int uhci_show_root_hub_state(struct uhci_hcd *uhci, char *buf, int len) |
| 236 | { |
| 237 | char *out = buf; |
| 238 | char *rh_state; |
| 239 | |
| 240 | /* Try to make sure there's enough memory */ |
| 241 | if (len < 60) |
| 242 | return 0; |
| 243 | |
| 244 | switch (uhci->rh_state) { |
| 245 | case UHCI_RH_RESET: |
| 246 | rh_state = "reset"; break; |
| 247 | case UHCI_RH_SUSPENDED: |
| 248 | rh_state = "suspended"; break; |
| 249 | case UHCI_RH_AUTO_STOPPED: |
| 250 | rh_state = "auto-stopped"; break; |
| 251 | case UHCI_RH_RESUMING: |
| 252 | rh_state = "resuming"; break; |
| 253 | case UHCI_RH_SUSPENDING: |
| 254 | rh_state = "suspending"; break; |
| 255 | case UHCI_RH_RUNNING: |
| 256 | rh_state = "running"; break; |
| 257 | case UHCI_RH_RUNNING_NODEVS: |
| 258 | rh_state = "running, no devs"; break; |
| 259 | default: |
| 260 | rh_state = "?"; break; |
| 261 | } |
| 262 | out += sprintf(out, "Root-hub state: %s\n", rh_state); |
| 263 | return out - buf; |
| 264 | } |
| 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len) |
| 267 | { |
| 268 | char *out = buf; |
| 269 | unsigned long io_addr = uhci->io_addr; |
| 270 | unsigned short usbcmd, usbstat, usbint, usbfrnum; |
| 271 | unsigned int flbaseadd; |
| 272 | unsigned char sof; |
| 273 | unsigned short portsc1, portsc2; |
| 274 | |
| 275 | /* Try to make sure there's enough memory */ |
| 276 | if (len < 80 * 6) |
| 277 | return 0; |
| 278 | |
| 279 | usbcmd = inw(io_addr + 0); |
| 280 | usbstat = inw(io_addr + 2); |
| 281 | usbint = inw(io_addr + 4); |
| 282 | usbfrnum = inw(io_addr + 6); |
| 283 | flbaseadd = inl(io_addr + 8); |
| 284 | sof = inb(io_addr + 12); |
| 285 | portsc1 = inw(io_addr + 16); |
| 286 | portsc2 = inw(io_addr + 18); |
| 287 | |
| 288 | out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n", |
| 289 | usbcmd, |
| 290 | (usbcmd & USBCMD_MAXP) ? "Maxp64 " : "Maxp32 ", |
| 291 | (usbcmd & USBCMD_CF) ? "CF " : "", |
| 292 | (usbcmd & USBCMD_SWDBG) ? "SWDBG " : "", |
| 293 | (usbcmd & USBCMD_FGR) ? "FGR " : "", |
| 294 | (usbcmd & USBCMD_EGSM) ? "EGSM " : "", |
| 295 | (usbcmd & USBCMD_GRESET) ? "GRESET " : "", |
| 296 | (usbcmd & USBCMD_HCRESET) ? "HCRESET " : "", |
| 297 | (usbcmd & USBCMD_RS) ? "RS " : ""); |
| 298 | |
| 299 | out += sprintf(out, " usbstat = %04x %s%s%s%s%s%s\n", |
| 300 | usbstat, |
| 301 | (usbstat & USBSTS_HCH) ? "HCHalted " : "", |
| 302 | (usbstat & USBSTS_HCPE) ? "HostControllerProcessError " : "", |
| 303 | (usbstat & USBSTS_HSE) ? "HostSystemError " : "", |
| 304 | (usbstat & USBSTS_RD) ? "ResumeDetect " : "", |
| 305 | (usbstat & USBSTS_ERROR) ? "USBError " : "", |
| 306 | (usbstat & USBSTS_USBINT) ? "USBINT " : ""); |
| 307 | |
| 308 | out += sprintf(out, " usbint = %04x\n", usbint); |
| 309 | out += sprintf(out, " usbfrnum = (%d)%03x\n", (usbfrnum >> 10) & 1, |
| 310 | 0xfff & (4*(unsigned int)usbfrnum)); |
| 311 | out += sprintf(out, " flbaseadd = %08x\n", flbaseadd); |
| 312 | out += sprintf(out, " sof = %02x\n", sof); |
| 313 | out += uhci_show_sc(1, portsc1, out, len - (out - buf)); |
| 314 | out += uhci_show_sc(2, portsc2, out, len - (out - buf)); |
| 315 | |
| 316 | return out - buf; |
| 317 | } |
| 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len) |
| 320 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | char *out = buf; |
| 322 | int i, j; |
| 323 | struct uhci_qh *qh; |
| 324 | struct uhci_td *td; |
| 325 | struct list_head *tmp, *head; |
| 326 | |
Alan Stern | c8f4fe4 | 2005-04-09 17:27:32 -0400 | [diff] [blame] | 327 | out += uhci_show_root_hub_state(uhci, out, len - (out - buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | out += sprintf(out, "HC status\n"); |
| 329 | out += uhci_show_status(uhci, out, len - (out - buf)); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 330 | if (debug <= 1) |
| 331 | return out - buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
| 333 | out += sprintf(out, "Frame List\n"); |
| 334 | for (i = 0; i < UHCI_NUMFRAMES; ++i) { |
Alan Stern | a1d59ce | 2005-09-16 14:22:51 -0400 | [diff] [blame] | 335 | td = uhci->frame_cpu[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | if (!td) |
| 337 | continue; |
| 338 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 339 | out += sprintf(out, "- Frame %d\n", i); \ |
| 340 | if (td->dma_handle != (dma_addr_t)uhci->frame[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | out += sprintf(out, " frame list does not match td->dma_handle!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | head = &td->fl_list; |
| 344 | tmp = head; |
| 345 | do { |
| 346 | td = list_entry(tmp, struct uhci_td, fl_list); |
| 347 | tmp = tmp->next; |
| 348 | out += uhci_show_td(td, out, len - (out - buf), 4); |
| 349 | } while (tmp != head); |
| 350 | } |
| 351 | |
Alan Stern | 687f5f3 | 2005-11-30 17:16:19 -0500 | [diff] [blame] | 352 | out += sprintf(out, "Skeleton QHs\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | for (i = 0; i < UHCI_NUM_SKELQH; ++i) { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 355 | int cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | qh = uhci->skelqh[i]; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 358 | out += sprintf(out, "- %s\n", qh_names[i]); \ |
| 359 | out += uhci_show_qh(qh, out, len - (out - buf), 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
| 361 | /* Last QH is the Terminating QH, it's different */ |
| 362 | if (i == UHCI_NUM_SKELQH - 1) { |
| 363 | if (qh->link != UHCI_PTR_TERM) |
| 364 | out += sprintf(out, " bandwidth reclamation on!\n"); |
| 365 | |
| 366 | if (qh_element(qh) != cpu_to_le32(uhci->term_td->dma_handle)) |
| 367 | out += sprintf(out, " skel_term_qh element is not set to term_td!\n"); |
| 368 | |
| 369 | continue; |
| 370 | } |
| 371 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 372 | j = (i < 9) ? 9 : i+1; /* Next skeleton */ |
| 373 | head = &qh->node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | tmp = head->next; |
| 375 | |
| 376 | while (tmp != head) { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 377 | qh = list_entry(tmp, struct uhci_qh, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | tmp = tmp->next; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 379 | if (++cnt <= 10) |
| 380 | out += uhci_show_qh(qh, out, |
| 381 | len - (out - buf), 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 383 | if ((cnt -= 10) > 0) |
| 384 | out += sprintf(out, " Skipped %d QHs\n", cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 386 | if (i > 1 && i < UHCI_NUM_SKELQH - 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | if (qh->link != |
| 388 | (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH)) |
| 389 | out += sprintf(out, " last QH not linked to next skeleton!\n"); |
| 390 | } |
| 391 | } |
| 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | return out - buf; |
| 394 | } |
| 395 | |
| 396 | #define MAX_OUTPUT (64 * 1024) |
| 397 | |
| 398 | struct uhci_debug { |
| 399 | int size; |
| 400 | char *data; |
| 401 | struct uhci_hcd *uhci; |
| 402 | }; |
| 403 | |
| 404 | static int uhci_debug_open(struct inode *inode, struct file *file) |
| 405 | { |
| 406 | struct uhci_hcd *uhci = inode->u.generic_ip; |
| 407 | struct uhci_debug *up; |
| 408 | int ret = -ENOMEM; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 409 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | lock_kernel(); |
| 412 | up = kmalloc(sizeof(*up), GFP_KERNEL); |
| 413 | if (!up) |
| 414 | goto out; |
| 415 | |
| 416 | up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL); |
| 417 | if (!up->data) { |
| 418 | kfree(up); |
| 419 | goto out; |
| 420 | } |
| 421 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 422 | spin_lock_irqsave(&uhci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | up->size = uhci_sprint_schedule(uhci, up->data, MAX_OUTPUT); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 424 | spin_unlock_irqrestore(&uhci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | file->private_data = up; |
| 427 | |
| 428 | ret = 0; |
| 429 | out: |
| 430 | unlock_kernel(); |
| 431 | return ret; |
| 432 | } |
| 433 | |
| 434 | static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence) |
| 435 | { |
| 436 | struct uhci_debug *up; |
| 437 | loff_t new = -1; |
| 438 | |
| 439 | lock_kernel(); |
| 440 | up = file->private_data; |
| 441 | |
| 442 | switch (whence) { |
| 443 | case 0: |
| 444 | new = off; |
| 445 | break; |
| 446 | case 1: |
| 447 | new = file->f_pos + off; |
| 448 | break; |
| 449 | } |
| 450 | if (new < 0 || new > up->size) { |
| 451 | unlock_kernel(); |
| 452 | return -EINVAL; |
| 453 | } |
| 454 | unlock_kernel(); |
| 455 | return (file->f_pos = new); |
| 456 | } |
| 457 | |
| 458 | static ssize_t uhci_debug_read(struct file *file, char __user *buf, |
| 459 | size_t nbytes, loff_t *ppos) |
| 460 | { |
| 461 | struct uhci_debug *up = file->private_data; |
| 462 | return simple_read_from_buffer(buf, nbytes, ppos, up->data, up->size); |
| 463 | } |
| 464 | |
| 465 | static int uhci_debug_release(struct inode *inode, struct file *file) |
| 466 | { |
| 467 | struct uhci_debug *up = file->private_data; |
| 468 | |
| 469 | kfree(up->data); |
| 470 | kfree(up); |
| 471 | |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | static struct file_operations uhci_debug_operations = { |
| 476 | .open = uhci_debug_open, |
| 477 | .llseek = uhci_debug_lseek, |
| 478 | .read = uhci_debug_read, |
| 479 | .release = uhci_debug_release, |
| 480 | }; |
| 481 | |
| 482 | #else /* CONFIG_DEBUG_FS */ |
| 483 | |
| 484 | #define uhci_debug_operations (* (struct file_operations *) NULL) |
| 485 | |
| 486 | #endif |