1 #ifndef __IO_MODULE_H__ 2 #define __IO_MODULE_H__ 3 4 #include <sys/types.h> 5 #include <ifaddrs.h> 6 #include <net/if.h> 7 /*----------------------------------------------------------------------------*/ 8 /* for type def'ns */ 9 #include <stdint.h> 10 #ifdef ENABLE_PSIO 11 /* for ps lib funcs */ 12 #include "ps.h" 13 #endif 14 /*----------------------------------------------------------------------------*/ 15 /** 16 * Declaration to soothe down the warnings 17 */ 18 struct mtcp_thread_context; 19 /** 20 * io_module_funcs - contains template for the various 10Gbps pkt I/O 21 * - libraries that can be adopted. 22 * 23 * load_module() : Used to set system-wide I/O module 24 * initialization. 25 * 26 * init_handle() : Used to initialize the driver library 27 * : Also use the context to create/initialize 28 * : a private packet I/O data structures. 29 * 30 * link_devices() : Used to add link(s) to the mtcp stack. 31 * Returns 0 on success; -1 on failure. 32 * 33 * release_pkt() : release the packet if mTCP does not need 34 * to process it (e.g. non-IPv4, non-TCP pkts). 35 * 36 * get_wptr() : retrieve the next empty pkt buffer for the 37 * application for packet writing. Returns 38 * ptr to pkt buffer. 39 * 40 * set_wptr() : set the next empty pkt buffer for the 41 * application for packet writing. Returns void. 42 * Use this function if you want to share rx/tx 43 * buffer (ZERO-COPY) 44 * 45 * send_pkts() : transmit batch of packets via interface 46 * idx (=nif). 47 * Returns 0 on success; -1 on failure 48 * 49 * get_rptr() : retrieve next pkt for application for 50 * packet read. 51 * Returns ptr to pkt buffer. 52 * 53 * recv_pkts() : recieve batch of packets from the interface, 54 * ifidx. 55 * Returns no. of packets that are read from 56 * the iface. 57 * 58 * select() : for blocking I/O 59 * 60 * destroy_handle() : free up resources allocated during 61 * init_handle(). Normally called during 62 * process termination. 63 * 64 * dev_ioctl() : contains submodules for select drivers 65 * 66 */ 67 typedef struct io_module_func { 68 void (*load_module_upper_half)(void); 69 void (*load_module_lower_half)(void); 70 void (*init_handle)(struct mtcp_thread_context *ctx); 71 int32_t (*link_devices)(struct mtcp_thread_context *ctx); 72 void (*release_pkt)(struct mtcp_thread_context *ctx, int ifidx, unsigned char *pkt_data, int len); 73 uint8_t * (*get_wptr)(struct mtcp_thread_context *ctx, int ifidx, uint16_t len); 74 void (*set_wptr)(struct mtcp_thread_context *ctx, int out_ifidx, int in_ifidx, int idx); 75 int32_t (*send_pkts)(struct mtcp_thread_context *ctx, int nif); 76 uint8_t * (*get_rptr)(struct mtcp_thread_context *ctx, int ifidx, int index, uint16_t *len); 77 int (*get_nif)(struct ifreq *ifr); 78 int32_t (*recv_pkts)(struct mtcp_thread_context *ctx, int ifidx); 79 int32_t (*select)(struct mtcp_thread_context *ctx); 80 void (*destroy_handle)(struct mtcp_thread_context *ctx); 81 int32_t (*dev_ioctl)(struct mtcp_thread_context *ctx, int nif, int cmd, void *argp); 82 } io_module_func __attribute__((aligned(__WORDSIZE))); 83 /*----------------------------------------------------------------------------*/ 84 io_module_func *current_iomodule_func; 85 typedef struct { 86 int8_t pktidx; 87 uint32_t hash_value; 88 } RssInfo; 89 /*----------------------------------------------------------------------------*/ 90 #define MAX_DEVICES 16 91 /* IO-MODULE string literals */ 92 #define PSIO_STR "psio" 93 #define DPDK_STR "dpdk" 94 #define DPDKR_STR "dpdkr" 95 #define PCAP_STR "pcap" 96 /* dev_ioctl related macros */ 97 #define PKT_TX_IP_CSUM 0x01 98 #define PKT_TX_TCP_CSUM 0x02 99 #define PKT_RX_RSS 0x03 100 101 /* enable shared RX/TX buffers */ 102 //#define SHARE_IO_BUFFER 103 104 #ifdef ENABLE_PSIO 105 /* registered psio context */ 106 extern io_module_func ps_module_func; 107 struct ps_device devices[MAX_DEVICES]; 108 #endif 109 110 #ifdef ENABLE_DPDK 111 /* registered dpdk context */ 112 extern io_module_func dpdk_module_func; 113 #endif /* !ENABLE_DPDK */ 114 115 #ifdef ENABLE_DPDKR 116 extern io_module_func dpdkr_module_func; 117 #endif 118 119 #ifdef ENABLE_PCAP 120 extern io_module_func pcap_module_func; 121 #endif 122 /*----------------------------------------------------------------------------*/ 123 #endif /* !__IO_MODULE_H__ */ 124