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