DF-2305 / fwpcictl.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | /* * fwpcictl.c -- userland driver for the fwohci_pci.c verification rig * (/dev/fwpcictl0, root-only). Targets DF-2304 / DF-2305 / DF-2306. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> #include <sys/ioctl.h> #include "fwpci_harness.h" static void usage(void) { fprintf(stderr, "usage: fwpcictl attach [dpafail|dmatagfail|irqfail ...]\n" " fwpcictl probe <vendor> <device> <class> <subclass> <progif>\n" " fwpcictl verbose <0|1>\n" " fwpcictl stats\n" " fwpcictl forcedetach\n"); exit(1); } static void print_attach(const char *tag, struct fwp_attachreq *ar) { u_int i; printf("%s: attach rc=%d mode=0x%x\n", tag, (int)ar->rc, ar->mode); printf("%s: resource deltas: MEM %u/%u IRQ %u/%u " "setup_intr %u teardown %u live_handlers=%u\n", tag, ar->mem_allocs, ar->mem_releases, ar->irq_allocs, ar->irq_releases, ar->intr_setups, ar->intr_teardowns, ar->live_handlers); printf("%s: interposers: dpa_calls=%u dmatag_calls=%u " "mem_conflict_fails=%u\n", tag, ar->dpa_calls, ar->dmatag_calls, ar->mem_conflict_fails); printf("%s: device_delete_child calls: %u\n", tag, ar->dellog_n); for (i = 0; i < ar->dellog_n && i < FWP_DELOG_MAX; i++) printf("%s: delete#%u: fwohci_pci.c:%u child=0x%llx rc=%d\n", tag, i, ar->del_lines[i], (unsigned long long)ar->del_childs[i], (int)ar->del_rcs[i]); } int main(int argc, char **argv) { struct fwp_attachreq ar; struct fwp_probereq pr; struct fwp_ctlreq cr; int fd, i; if (argc < 2) usage(); fd = open("/dev/fwpcictl0", O_RDWR); if (fd < 0) { perror("open /dev/fwpcictl0"); exit(1); } if (!strcmp(argv[1], "attach")) { memset(&ar, 0, sizeof(ar)); for (i = 2; i < argc; i++) { if (!strcmp(argv[i], "dpafail")) ar.mode |= FWP_MODE_DPAFAIL; else if (!strcmp(argv[i], "dmatagfail")) ar.mode |= FWP_MODE_DMATAGFAIL; else if (!strcmp(argv[i], "irqfail")) ar.mode |= FWP_MODE_IRQFAIL; else usage(); } if (ioctl(fd, FWPCI_IOC_ATTACH, &ar) < 0) { perror("ioctl ATTACH"); exit(1); } print_attach("ATTACH", &ar); } else if (!strcmp(argv[1], "probe")) { if (argc != 7) usage(); memset(&pr, 0, sizeof(pr)); pr.vendor = (u_int32_t)strtoul(argv[2], NULL, 0); pr.device = (u_int32_t)strtoul(argv[3], NULL, 0); pr.class = (u_int32_t)strtoul(argv[4], NULL, 0); pr.subclass = (u_int32_t)strtoul(argv[5], NULL, 0); pr.progif = (u_int32_t)strtoul(argv[6], NULL, 0); if (ioctl(fd, FWPCI_IOC_PROBE, &pr) < 0) { perror("ioctl PROBE"); exit(1); } printf("PROBE: rc=%d\n", (int)pr.rc); } else if (!strcmp(argv[1], "verbose")) { if (argc != 3) usage(); memset(&cr, 0, sizeof(cr)); cr.op = 2; cr.arg = (u_int32_t)strtoul(argv[2], NULL, 0); if (ioctl(fd, FWPCI_IOC_CTL, &cr) < 0) { perror("ioctl CTL(verbose)"); exit(1); } printf("VERBOSE: bootverbose=%u rc=%d\n", cr.arg, (int)cr.rc); } else if (!strcmp(argv[1], "stats")) { memset(&cr, 0, sizeof(cr)); cr.op = 3; if (ioctl(fd, FWPCI_IOC_CTL, &cr) < 0) { perror("ioctl CTL(stats)"); exit(1); } printf("STATS: MEM %u/%u IRQ %u/%u setup %u teardown %u " "live=%u conflicts=%u deletes=%u\n", cr.mem_allocs, cr.mem_releases, cr.irq_allocs, cr.irq_releases, cr.intr_setups, cr.intr_teardowns, cr.live_handlers, cr.mem_conflict_fails, cr.dellog_n); } else if (!strcmp(argv[1], "forcedetach")) { memset(&cr, 0, sizeof(cr)); cr.op = 1; if (ioctl(fd, FWPCI_IOC_CTL, &cr) < 0) { perror("ioctl CTL(forcedetach)"); exit(1); } printf("FORCEDETACH: rc=%d\n", (int)cr.rc); } else usage(); close(fd); return (0); } |