1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2015-2018 Atomic Rules LLC 3 */ 4 5 #ifndef _ARK_GLOBAL_H_ 6 #define _ARK_GLOBAL_H_ 7 8 #include <time.h> 9 #include <assert.h> 10 11 #include <rte_mbuf.h> 12 #include <ethdev_driver.h> 13 #include <rte_malloc.h> 14 #include <rte_memcpy.h> 15 #include <rte_string_fns.h> 16 #include <rte_cycles.h> 17 #include <rte_kvargs.h> 18 #include <rte_dev.h> 19 #include <rte_version.h> 20 21 #include "ark_pktdir.h" 22 #include "ark_pktgen.h" 23 #include "ark_pktchkr.h" 24 25 #define ETH_ARK_ARG_MAXLEN 64 26 #define ARK_SYSCTRL_BASE 0x0 27 #define ARK_PKTGEN_BASE 0x10000 28 #define ARK_MPU_RX_BASE 0x20000 29 #define ARK_UDM_BASE 0x30000 30 #define ARK_MPU_TX_BASE 0x40000 31 #define ARK_DDM_BASE 0x60000 32 #define ARK_CMAC_BASE 0x80000 33 #define ARK_PKTDIR_BASE 0xa0000 34 #define ARK_PKTCHKR_BASE 0x90000 35 #define ARK_RCPACING_BASE 0xb0000 36 #define ARK_EXTERNAL_BASE 0x100000 37 #define ARK_MPU_QOFFSET 0x00100 38 #define ARK_MAX_PORTS RTE_MAX_ETHPORTS 39 40 #define offset8(n) n 41 #define offset16(n) ((n) / 2) 42 #define offset32(n) ((n) / 4) 43 #define offset64(n) ((n) / 8) 44 45 /* Maximum length of arg list in bytes */ 46 #define ARK_MAX_ARG_LEN 256 47 48 /* 49 * Structure to store private data for each PF/VF instance. 50 */ 51 #define def_ptr(type, name) \ 52 union type { \ 53 uint64_t *t64; \ 54 uint32_t *t32; \ 55 uint16_t *t16; \ 56 uint8_t *t8; \ 57 void *v; \ 58 } name 59 60 61 /* Extension hooks for extraction and placement of user meta data 62 * during RX an TX operations. These functions are the bridge 63 * between the mbuf struct and the tuser fields on the AXIS 64 * interfaces in the FPGA 65 */ 66 /* RX hook populates mbuf fields from user defined *meta up to 20 bytes */ 67 typedef void (*rx_user_meta_hook_fn)(struct rte_mbuf *mbuf, 68 const uint32_t *meta, 69 void *ext_user_data); 70 /* TX hook poplulate *meta, with up to 20 bytes. meta_cnt 71 * returns the number of uint32_t words populated, 0 to 5 72 */ 73 typedef void (*tx_user_meta_hook_fn)(const struct rte_mbuf *mbuf, 74 uint32_t *meta, uint8_t *meta_cnt, 75 void *ext_user_data); 76 77 struct ark_user_ext { 78 void *(*dev_init)(struct rte_eth_dev *, void *abar, int port_id); 79 void (*dev_uninit)(struct rte_eth_dev *, void *); 80 int (*dev_get_port_count)(struct rte_eth_dev *, void *); 81 int (*dev_configure)(struct rte_eth_dev *, void *); 82 int (*dev_start)(struct rte_eth_dev *, void *); 83 void (*dev_stop)(struct rte_eth_dev *, void *); 84 void (*dev_close)(struct rte_eth_dev *, void *); 85 int (*link_update)(struct rte_eth_dev *, int wait_to_complete, void *); 86 int (*dev_set_link_up)(struct rte_eth_dev *, void *); 87 int (*dev_set_link_down)(struct rte_eth_dev *, void *); 88 int (*stats_get)(struct rte_eth_dev *, struct rte_eth_stats *, void *); 89 void (*stats_reset)(struct rte_eth_dev *, void *); 90 void (*mac_addr_add)(struct rte_eth_dev *, 91 struct rte_ether_addr *, 92 uint32_t, 93 uint32_t, 94 void *); 95 void (*mac_addr_remove)(struct rte_eth_dev *, uint32_t, void *); 96 void (*mac_addr_set)(struct rte_eth_dev *, struct rte_ether_addr *, 97 void *); 98 int (*set_mtu)(struct rte_eth_dev *, uint16_t, void *); 99 /* user meta, hook functions */ 100 rx_user_meta_hook_fn rx_user_meta_hook; 101 tx_user_meta_hook_fn tx_user_meta_hook; 102 }; 103 104 struct ark_adapter { 105 /* User extension private data */ 106 void *user_data[ARK_MAX_PORTS]; 107 108 /* Pointers to packet generator and checker */ 109 int start_pg; 110 ark_pkt_gen_t pg; 111 ark_pkt_chkr_t pc; 112 ark_pkt_dir_t pd; 113 114 int num_ports; 115 116 /* Packet generator/checker args */ 117 char pkt_gen_args[ARK_MAX_ARG_LEN]; 118 char pkt_chkr_args[ARK_MAX_ARG_LEN]; 119 uint32_t pkt_dir_v; 120 121 /* eth device */ 122 struct rte_eth_dev *eth_dev; 123 124 void *d_handle; 125 struct ark_user_ext user_ext; 126 127 /* Our Bar 0 */ 128 uint8_t *bar0; 129 130 /* Application Bar */ 131 uint8_t *a_bar; 132 133 /* Arkville demo block offsets */ 134 def_ptr(sys_ctrl, sysctrl); 135 def_ptr(pkt_gen, pktgen); 136 def_ptr(mpu_rx, mpurx); 137 def_ptr(UDM, udm); 138 def_ptr(mpu_tx, mputx); 139 def_ptr(DDM, ddm); 140 def_ptr(CMAC, cmac); 141 def_ptr(external, external); 142 def_ptr(pkt_dir, pktdir); 143 def_ptr(pkt_chkr, pktchkr); 144 145 int started; 146 uint16_t rx_queues; 147 uint16_t tx_queues; 148 149 struct ark_rqpace_t *rqpacing; 150 }; 151 152 typedef uint32_t *ark_t; 153 154 #endif 155