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" : "")); |
| 117 | out += sprintf(out, "%s", (urbp->fsbr_timeout ? " FSBR_TO" : "")); |
| 118 | |
| 119 | if (urbp->urb->status != -EINPROGRESS) |
| 120 | out += sprintf(out, " Status=%d", urbp->urb->status); |
| 121 | out += sprintf(out, "\n"); |
| 122 | |
| 123 | i = nactive = ninactive = 0; |
| 124 | list_for_each_entry(td, &urbp->td_list, list) { |
| 125 | if (++i <= 10 || debug > 2) { |
| 126 | out += sprintf(out, "%*s%d: ", space + 2, "", i); |
| 127 | out += uhci_show_td(td, out, len - (out - buf), 0); |
| 128 | } else { |
| 129 | if (td_status(td) & TD_CTRL_ACTIVE) |
| 130 | ++nactive; |
| 131 | else |
| 132 | ++ninactive; |
| 133 | } |
| 134 | } |
| 135 | if (nactive + ninactive > 0) |
| 136 | out += sprintf(out, "%*s[skipped %d inactive and %d active " |
| 137 | "TDs]\n", |
| 138 | space, "", ninactive, nactive); |
| 139 | |
| 140 | return out - buf; |
| 141 | } |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space) |
| 144 | { |
| 145 | char *out = buf; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 146 | int i, nurbs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | __le32 element = qh_element(qh); |
| 148 | |
| 149 | /* Try to make sure there's enough memory */ |
| 150 | if (len < 80 * 6) |
| 151 | return 0; |
| 152 | |
| 153 | out += sprintf(out, "%*s[%p] link (%08x) element (%08x)\n", space, "", |
| 154 | qh, le32_to_cpu(qh->link), le32_to_cpu(element)); |
| 155 | |
| 156 | if (element & UHCI_PTR_QH) |
| 157 | out += sprintf(out, "%*s Element points to QH (bug?)\n", space, ""); |
| 158 | |
| 159 | if (element & UHCI_PTR_DEPTH) |
| 160 | out += sprintf(out, "%*s Depth traverse\n", space, ""); |
| 161 | |
| 162 | if (element & cpu_to_le32(8)) |
| 163 | out += sprintf(out, "%*s Bit 3 set (bug?)\n", space, ""); |
| 164 | |
| 165 | if (!(element & ~(UHCI_PTR_QH | UHCI_PTR_DEPTH))) |
| 166 | out += sprintf(out, "%*s Element is NULL (bug?)\n", space, ""); |
| 167 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 168 | if (list_empty(&qh->queue)) { |
| 169 | out += sprintf(out, "%*s queue is empty\n", space, ""); |
| 170 | } else { |
| 171 | struct urb_priv *urbp = list_entry(qh->queue.next, |
| 172 | struct urb_priv, node); |
| 173 | struct uhci_td *td = list_entry(urbp->td_list.next, |
| 174 | struct uhci_td, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 176 | if (cpu_to_le32(td->dma_handle) != (element & ~UHCI_PTR_BITS)) |
| 177 | out += sprintf(out, "%*s Element != First TD\n", |
| 178 | space, ""); |
| 179 | i = nurbs = 0; |
| 180 | list_for_each_entry(urbp, &qh->queue, node) { |
| 181 | if (++i <= 10) |
| 182 | out += uhci_show_urbp(urbp, out, |
| 183 | len - (out - buf), space + 2); |
| 184 | else |
| 185 | ++nurbs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 187 | if (nurbs > 0) |
| 188 | out += sprintf(out, "%*s Skipped %d URBs\n", |
| 189 | space, "", nurbs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | return out - buf; |
| 193 | } |
| 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | #ifdef CONFIG_PROC_FS |
Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 196 | static const char * const qh_names[] = { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 197 | "skel_unlink_qh", "skel_iso_qh", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | "skel_int128_qh", "skel_int64_qh", |
| 199 | "skel_int32_qh", "skel_int16_qh", |
| 200 | "skel_int8_qh", "skel_int4_qh", |
| 201 | "skel_int2_qh", "skel_int1_qh", |
| 202 | "skel_ls_control_qh", "skel_fs_control_qh", |
| 203 | "skel_bulk_qh", "skel_term_qh" |
| 204 | }; |
| 205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | static int uhci_show_sc(int port, unsigned short status, char *buf, int len) |
| 207 | { |
| 208 | char *out = buf; |
| 209 | |
| 210 | /* Try to make sure there's enough memory */ |
| 211 | if (len < 160) |
| 212 | return 0; |
| 213 | |
| 214 | out += sprintf(out, " stat%d = %04x %s%s%s%s%s%s%s%s%s%s\n", |
| 215 | port, |
| 216 | status, |
| 217 | (status & USBPORTSC_SUSP) ? " Suspend" : "", |
| 218 | (status & USBPORTSC_OCC) ? " OverCurrentChange" : "", |
| 219 | (status & USBPORTSC_OC) ? " OverCurrent" : "", |
| 220 | (status & USBPORTSC_PR) ? " Reset" : "", |
| 221 | (status & USBPORTSC_LSDA) ? " LowSpeed" : "", |
| 222 | (status & USBPORTSC_RD) ? " ResumeDetect" : "", |
| 223 | (status & USBPORTSC_PEC) ? " EnableChange" : "", |
| 224 | (status & USBPORTSC_PE) ? " Enabled" : "", |
| 225 | (status & USBPORTSC_CSC) ? " ConnectChange" : "", |
| 226 | (status & USBPORTSC_CCS) ? " Connected" : ""); |
| 227 | |
| 228 | return out - buf; |
| 229 | } |
| 230 | |
Alan Stern | c8f4fe4 | 2005-04-09 17:27:32 -0400 | [diff] [blame] | 231 | static int uhci_show_root_hub_state(struct uhci_hcd *uhci, char *buf, int len) |
| 232 | { |
| 233 | char *out = buf; |
| 234 | char *rh_state; |
| 235 | |
| 236 | /* Try to make sure there's enough memory */ |
| 237 | if (len < 60) |
| 238 | return 0; |
| 239 | |
| 240 | switch (uhci->rh_state) { |
| 241 | case UHCI_RH_RESET: |
| 242 | rh_state = "reset"; break; |
| 243 | case UHCI_RH_SUSPENDED: |
| 244 | rh_state = "suspended"; break; |
| 245 | case UHCI_RH_AUTO_STOPPED: |
| 246 | rh_state = "auto-stopped"; break; |
| 247 | case UHCI_RH_RESUMING: |
| 248 | rh_state = "resuming"; break; |
| 249 | case UHCI_RH_SUSPENDING: |
| 250 | rh_state = "suspending"; break; |
| 251 | case UHCI_RH_RUNNING: |
| 252 | rh_state = "running"; break; |
| 253 | case UHCI_RH_RUNNING_NODEVS: |
| 254 | rh_state = "running, no devs"; break; |
| 255 | default: |
| 256 | rh_state = "?"; break; |
| 257 | } |
| 258 | out += sprintf(out, "Root-hub state: %s\n", rh_state); |
| 259 | return out - buf; |
| 260 | } |
| 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len) |
| 263 | { |
| 264 | char *out = buf; |
| 265 | unsigned long io_addr = uhci->io_addr; |
| 266 | unsigned short usbcmd, usbstat, usbint, usbfrnum; |
| 267 | unsigned int flbaseadd; |
| 268 | unsigned char sof; |
| 269 | unsigned short portsc1, portsc2; |
| 270 | |
| 271 | /* Try to make sure there's enough memory */ |
| 272 | if (len < 80 * 6) |
| 273 | return 0; |
| 274 | |
| 275 | usbcmd = inw(io_addr + 0); |
| 276 | usbstat = inw(io_addr + 2); |
| 277 | usbint = inw(io_addr + 4); |
| 278 | usbfrnum = inw(io_addr + 6); |
| 279 | flbaseadd = inl(io_addr + 8); |
| 280 | sof = inb(io_addr + 12); |
| 281 | portsc1 = inw(io_addr + 16); |
| 282 | portsc2 = inw(io_addr + 18); |
| 283 | |
| 284 | out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n", |
| 285 | usbcmd, |
| 286 | (usbcmd & USBCMD_MAXP) ? "Maxp64 " : "Maxp32 ", |
| 287 | (usbcmd & USBCMD_CF) ? "CF " : "", |
| 288 | (usbcmd & USBCMD_SWDBG) ? "SWDBG " : "", |
| 289 | (usbcmd & USBCMD_FGR) ? "FGR " : "", |
| 290 | (usbcmd & USBCMD_EGSM) ? "EGSM " : "", |
| 291 | (usbcmd & USBCMD_GRESET) ? "GRESET " : "", |
| 292 | (usbcmd & USBCMD_HCRESET) ? "HCRESET " : "", |
| 293 | (usbcmd & USBCMD_RS) ? "RS " : ""); |
| 294 | |
| 295 | out += sprintf(out, " usbstat = %04x %s%s%s%s%s%s\n", |
| 296 | usbstat, |
| 297 | (usbstat & USBSTS_HCH) ? "HCHalted " : "", |
| 298 | (usbstat & USBSTS_HCPE) ? "HostControllerProcessError " : "", |
| 299 | (usbstat & USBSTS_HSE) ? "HostSystemError " : "", |
| 300 | (usbstat & USBSTS_RD) ? "ResumeDetect " : "", |
| 301 | (usbstat & USBSTS_ERROR) ? "USBError " : "", |
| 302 | (usbstat & USBSTS_USBINT) ? "USBINT " : ""); |
| 303 | |
| 304 | out += sprintf(out, " usbint = %04x\n", usbint); |
| 305 | out += sprintf(out, " usbfrnum = (%d)%03x\n", (usbfrnum >> 10) & 1, |
| 306 | 0xfff & (4*(unsigned int)usbfrnum)); |
| 307 | out += sprintf(out, " flbaseadd = %08x\n", flbaseadd); |
| 308 | out += sprintf(out, " sof = %02x\n", sof); |
| 309 | out += uhci_show_sc(1, portsc1, out, len - (out - buf)); |
| 310 | out += uhci_show_sc(2, portsc2, out, len - (out - buf)); |
| 311 | |
| 312 | return out - buf; |
| 313 | } |
| 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len) |
| 316 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | char *out = buf; |
| 318 | int i, j; |
| 319 | struct uhci_qh *qh; |
| 320 | struct uhci_td *td; |
| 321 | struct list_head *tmp, *head; |
| 322 | |
Alan Stern | c8f4fe4 | 2005-04-09 17:27:32 -0400 | [diff] [blame] | 323 | out += uhci_show_root_hub_state(uhci, out, len - (out - buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | out += sprintf(out, "HC status\n"); |
| 325 | out += uhci_show_status(uhci, out, len - (out - buf)); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 326 | if (debug <= 1) |
| 327 | return out - buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | out += sprintf(out, "Frame List\n"); |
| 330 | for (i = 0; i < UHCI_NUMFRAMES; ++i) { |
Alan Stern | a1d59ce | 2005-09-16 14:22:51 -0400 | [diff] [blame] | 331 | td = uhci->frame_cpu[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | if (!td) |
| 333 | continue; |
| 334 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 335 | out += sprintf(out, "- Frame %d\n", i); \ |
| 336 | if (td->dma_handle != (dma_addr_t)uhci->frame[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | out += sprintf(out, " frame list does not match td->dma_handle!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | head = &td->fl_list; |
| 340 | tmp = head; |
| 341 | do { |
| 342 | td = list_entry(tmp, struct uhci_td, fl_list); |
| 343 | tmp = tmp->next; |
| 344 | out += uhci_show_td(td, out, len - (out - buf), 4); |
| 345 | } while (tmp != head); |
| 346 | } |
| 347 | |
Alan Stern | 687f5f3 | 2005-11-30 17:16:19 -0500 | [diff] [blame] | 348 | out += sprintf(out, "Skeleton QHs\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | for (i = 0; i < UHCI_NUM_SKELQH; ++i) { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 351 | int cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | qh = uhci->skelqh[i]; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 354 | out += sprintf(out, "- %s\n", qh_names[i]); \ |
| 355 | out += uhci_show_qh(qh, out, len - (out - buf), 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | /* Last QH is the Terminating QH, it's different */ |
| 358 | if (i == UHCI_NUM_SKELQH - 1) { |
| 359 | if (qh->link != UHCI_PTR_TERM) |
| 360 | out += sprintf(out, " bandwidth reclamation on!\n"); |
| 361 | |
| 362 | if (qh_element(qh) != cpu_to_le32(uhci->term_td->dma_handle)) |
| 363 | out += sprintf(out, " skel_term_qh element is not set to term_td!\n"); |
| 364 | |
| 365 | continue; |
| 366 | } |
| 367 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 368 | j = (i < 9) ? 9 : i+1; /* Next skeleton */ |
| 369 | head = &qh->node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | tmp = head->next; |
| 371 | |
| 372 | while (tmp != head) { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 373 | qh = list_entry(tmp, struct uhci_qh, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | tmp = tmp->next; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 375 | if (++cnt <= 10) |
| 376 | out += uhci_show_qh(qh, out, |
| 377 | len - (out - buf), 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 379 | if ((cnt -= 10) > 0) |
| 380 | out += sprintf(out, " Skipped %d QHs\n", cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 382 | if (i > 1 && i < UHCI_NUM_SKELQH - 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | if (qh->link != |
| 384 | (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH)) |
| 385 | out += sprintf(out, " last QH not linked to next skeleton!\n"); |
| 386 | } |
| 387 | } |
| 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | return out - buf; |
| 390 | } |
| 391 | |
| 392 | #define MAX_OUTPUT (64 * 1024) |
| 393 | |
| 394 | struct uhci_debug { |
| 395 | int size; |
| 396 | char *data; |
| 397 | struct uhci_hcd *uhci; |
| 398 | }; |
| 399 | |
| 400 | static int uhci_debug_open(struct inode *inode, struct file *file) |
| 401 | { |
| 402 | struct uhci_hcd *uhci = inode->u.generic_ip; |
| 403 | struct uhci_debug *up; |
| 404 | int ret = -ENOMEM; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 405 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
| 407 | lock_kernel(); |
| 408 | up = kmalloc(sizeof(*up), GFP_KERNEL); |
| 409 | if (!up) |
| 410 | goto out; |
| 411 | |
| 412 | up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL); |
| 413 | if (!up->data) { |
| 414 | kfree(up); |
| 415 | goto out; |
| 416 | } |
| 417 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 418 | spin_lock_irqsave(&uhci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | up->size = uhci_sprint_schedule(uhci, up->data, MAX_OUTPUT); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame^] | 420 | spin_unlock_irqrestore(&uhci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | file->private_data = up; |
| 423 | |
| 424 | ret = 0; |
| 425 | out: |
| 426 | unlock_kernel(); |
| 427 | return ret; |
| 428 | } |
| 429 | |
| 430 | static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence) |
| 431 | { |
| 432 | struct uhci_debug *up; |
| 433 | loff_t new = -1; |
| 434 | |
| 435 | lock_kernel(); |
| 436 | up = file->private_data; |
| 437 | |
| 438 | switch (whence) { |
| 439 | case 0: |
| 440 | new = off; |
| 441 | break; |
| 442 | case 1: |
| 443 | new = file->f_pos + off; |
| 444 | break; |
| 445 | } |
| 446 | if (new < 0 || new > up->size) { |
| 447 | unlock_kernel(); |
| 448 | return -EINVAL; |
| 449 | } |
| 450 | unlock_kernel(); |
| 451 | return (file->f_pos = new); |
| 452 | } |
| 453 | |
| 454 | static ssize_t uhci_debug_read(struct file *file, char __user *buf, |
| 455 | size_t nbytes, loff_t *ppos) |
| 456 | { |
| 457 | struct uhci_debug *up = file->private_data; |
| 458 | return simple_read_from_buffer(buf, nbytes, ppos, up->data, up->size); |
| 459 | } |
| 460 | |
| 461 | static int uhci_debug_release(struct inode *inode, struct file *file) |
| 462 | { |
| 463 | struct uhci_debug *up = file->private_data; |
| 464 | |
| 465 | kfree(up->data); |
| 466 | kfree(up); |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | static struct file_operations uhci_debug_operations = { |
| 472 | .open = uhci_debug_open, |
| 473 | .llseek = uhci_debug_lseek, |
| 474 | .read = uhci_debug_read, |
| 475 | .release = uhci_debug_release, |
| 476 | }; |
| 477 | |
| 478 | #else /* CONFIG_DEBUG_FS */ |
| 479 | |
| 480 | #define uhci_debug_operations (* (struct file_operations *) NULL) |
| 481 | |
| 482 | #endif |