Vijay Kumar | a14eddd | 2008-10-19 08:58:46 +0530 | [diff] [blame] | 1 | TODO: |
Vijay Kumar | ee49abc | 2008-10-29 08:58:33 +0530 | [diff] [blame] | 2 | - Rx block size is limited to < 2048, hardware bug? |
| 3 | - Group size is limited to < page size, kernel alloc/mmap API issues |
Vijay Kumar | ee49abc | 2008-10-29 08:58:33 +0530 | [diff] [blame] | 4 | - test whether Tx is transmitting data from provided buffers |
| 5 | - handle device unplug case |
| 6 | - handle temperature above threshold |
| 7 | - use bus address instead of physical address for DMA |
| 8 | - support for snapshot mode |
Vijay Kumar | a14eddd | 2008-10-19 08:58:46 +0530 | [diff] [blame] | 9 | - audit userspace interfaces |
| 10 | - get reserved major/minor if needed |
| 11 | |
Vijay Kumar B | 763a998 | 2009-09-21 11:24:00 +0530 | [diff] [blame] | 12 | Sample Code: |
| 13 | |
| 14 | #include <sys/types.h> |
| 15 | #include <sys/stat.h> |
| 16 | #include <sys/mman.h> |
| 17 | #include <sys/ioctl.h> |
| 18 | #include <poll.h> |
| 19 | #include <stdio.h> |
| 20 | #include <error.h> |
| 21 | #include <errno.h> |
| 22 | #include <fcntl.h> |
| 23 | #include <stdint.h> |
| 24 | |
| 25 | #include <sysfs/libsysfs.h> |
| 26 | |
| 27 | #include <poch.h> |
| 28 | |
| 29 | struct pconsume { |
| 30 | uint32_t * offsets; |
| 31 | uint32_t nfetch; |
| 32 | uint32_t nflush; |
| 33 | }; |
| 34 | |
| 35 | uint32_t offsets[10]; |
| 36 | |
| 37 | void process_group(unsigned char *buf, uint32_t size) |
| 38 | { |
| 39 | uint16_t *buf16 = (uint16_t *)buf; |
| 40 | |
| 41 | printf("RX: %p %u %04x %04x %04x %04x %04x %04x\n", buf, size, |
| 42 | buf16[0], buf16[1], buf16[2], buf16[3], buf16[4], buf16[5]); |
| 43 | } |
| 44 | |
| 45 | int main() |
| 46 | { |
| 47 | struct sysfs_attribute *attr; |
| 48 | char *path; |
| 49 | int ret; |
| 50 | unsigned long mmap_size; |
| 51 | int fd; |
| 52 | unsigned char *cbuf; |
| 53 | |
| 54 | uint32_t nflush; |
| 55 | struct pollfd poll_fds; |
| 56 | int count = 0; |
| 57 | int i; |
| 58 | |
| 59 | path = "/sys/class/pocketchange/poch0/ch0/block_size"; |
| 60 | attr = sysfs_open_attribute(path); |
| 61 | ret = sysfs_write_attribute(attr, "256", strlen("256")); |
| 62 | if (ret == -1) |
| 63 | error(1, errno, "error writing attribute %s", path); |
| 64 | sysfs_close_attribute(attr); |
| 65 | |
| 66 | path = "/sys/class/pocketchange/poch0/ch0/group_size"; |
| 67 | attr = sysfs_open_attribute(path); |
| 68 | ret = sysfs_write_attribute(attr, "4096", strlen("4096")); |
| 69 | if (ret == -1) |
| 70 | error(1, errno, "error writing attribute %s", path); |
| 71 | sysfs_close_attribute(attr); |
| 72 | |
| 73 | path = "/sys/class/pocketchange/poch0/ch0/group_count"; |
| 74 | attr = sysfs_open_attribute(path); |
| 75 | ret = sysfs_write_attribute(attr, "64", strlen("64")); |
| 76 | if (ret == -1) |
| 77 | error(1, errno, "error writing attribute %s", path); |
| 78 | sysfs_close_attribute(attr); |
| 79 | |
| 80 | fd = open("/dev/ch0", O_RDWR); |
| 81 | if (fd == -1) |
| 82 | error(1, errno, "error opening device node"); |
| 83 | |
| 84 | path = "/sys/class/pocketchange/poch0/ch0/mmap_size"; |
| 85 | attr = sysfs_open_attribute(path); |
| 86 | ret = sysfs_read_attribute(attr); |
| 87 | if (ret == -1) |
| 88 | error(1, errno, "error reading attribute %s", path); |
| 89 | printf("%s", attr->value); |
| 90 | sscanf(attr->value, "%lu", &mmap_size); |
| 91 | sysfs_close_attribute(attr); |
| 92 | |
| 93 | cbuf = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, |
| 94 | MAP_PRIVATE, fd, 0); |
| 95 | if (cbuf == MAP_FAILED) |
| 96 | error(1, errno, "error mapping DMA buffers"); |
| 97 | |
| 98 | ret = ioctl(fd, POCH_IOC_TRANSFER_START, 0); |
| 99 | if (ret == -1) |
| 100 | error(1, errno, "error starting transfer"); |
| 101 | |
| 102 | nflush = 0; |
| 103 | while (1) { |
| 104 | struct pconsume consume; |
| 105 | |
| 106 | consume.offsets = offsets; |
| 107 | consume.nfetch = 10; |
| 108 | consume.nflush = nflush; |
| 109 | |
| 110 | ret = ioctl(fd, POCH_IOC_CONSUME, &consume); |
| 111 | if (ret == -1) |
| 112 | error(1, errno, "error consuming groups"); |
| 113 | |
| 114 | nflush = consume.nfetch; |
| 115 | |
| 116 | for (i = 0; i < nflush; i++) { |
| 117 | process_group(cbuf + consume.offsets[i], 4096); |
| 118 | |
| 119 | count++; |
| 120 | if (count == 1000) |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | if (count == 1000) |
| 125 | break; |
| 126 | } |
| 127 | |
| 128 | ret = ioctl(fd, POCH_IOC_TRANSFER_STOP, 0); |
| 129 | if (ret == -1) |
| 130 | error(1, errno, "error starting transfer"); |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
Vijay Kumar | a14eddd | 2008-10-19 08:58:46 +0530 | [diff] [blame] | 135 | Please send patches to Greg Kroah-Hartman <greg@kroah.com> and |
| 136 | Vijay Kumar <vijaykumar@bravegnu.org> and Jaya Kumar <jayakumar.lkml@gmail.com> |