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 <dev_driver.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_EXTERNAL_BASE 0x100000 36 #define ARK_MPU_QOFFSET 0x00100 37 #define ARK_MAX_PORTS RTE_MAX_ETHPORTS 38 39 #define offset8(n) n 40 #define offset16(n) ((n) / 2) 41 #define offset32(n) ((n) / 4) 42 #define offset64(n) ((n) / 8) 43 44 /* Maximum length of arg list in bytes */ 45 #define ARK_MAX_ARG_LEN 256 46 47 /* 48 * Structure to store private data for each PF/VF instance. 49 */ 50 #define def_ptr(type, name) \ 51 union type { \ 52 uint64_t *t64; \ 53 uint32_t *t32; \ 54 uint16_t *t16; \ 55 uint8_t *t8; \ 56 void *v; \ 57 } name 58 59 60 /* Extension hooks for extraction and placement of user meta data 61 * during RX an TX operations. These functions are the bridge 62 * between the mbuf struct and the tuser fields on the AXIS 63 * interfaces in the FPGA 64 */ 65 /* RX hook populates mbuf fields from user defined *meta up to 20 bytes */ 66 typedef void (*rx_user_meta_hook_fn)(struct rte_mbuf *mbuf, 67 const uint32_t *meta, 68 void *ext_user_data); 69 /* TX hook populate *meta, with up to 20 bytes. meta_cnt 70 * returns the number of uint32_t words populated, 0 to 5 71 */ 72 typedef void (*tx_user_meta_hook_fn)(const struct rte_mbuf *mbuf, 73 uint32_t *meta, uint8_t *meta_cnt, 74 void *ext_user_data); 75 76 struct ark_user_ext { 77 void *(*dev_init)(struct rte_eth_dev *, void *abar, int port_id); 78 void (*dev_uninit)(struct rte_eth_dev *, void *); 79 int (*dev_get_port_count)(struct rte_eth_dev *, void *); 80 int (*dev_configure)(struct rte_eth_dev *, void *); 81 int (*dev_start)(struct rte_eth_dev *, void *); 82 void (*dev_stop)(struct rte_eth_dev *, void *); 83 void (*dev_close)(struct rte_eth_dev *, void *); 84 int (*link_update)(struct rte_eth_dev *, int wait_to_complete, void *); 85 int (*dev_set_link_up)(struct rte_eth_dev *, void *); 86 int (*dev_set_link_down)(struct rte_eth_dev *, void *); 87 int (*stats_get)(struct rte_eth_dev *, struct rte_eth_stats *, void *); 88 void (*stats_reset)(struct rte_eth_dev *, void *); 89 void (*mac_addr_add)(struct rte_eth_dev *, 90 struct rte_ether_addr *, 91 uint32_t, 92 uint32_t, 93 void *); 94 void (*mac_addr_remove)(struct rte_eth_dev *, uint32_t, void *); 95 void (*mac_addr_set)(struct rte_eth_dev *, struct rte_ether_addr *, 96 void *); 97 int (*set_mtu)(struct rte_eth_dev *, uint16_t, void *); 98 /* user meta, hook functions */ 99 rx_user_meta_hook_fn rx_user_meta_hook; 100 tx_user_meta_hook_fn tx_user_meta_hook; 101 }; 102 103 struct ark_adapter { 104 /* User extension private data */ 105 void *user_data[ARK_MAX_PORTS]; 106 107 /* Pointers to packet generator and checker */ 108 int start_pg; 109 uint16_t pg_running; 110 ark_pkt_gen_t pg; 111 ark_pkt_chkr_t pc; 112 ark_pkt_dir_t pd; 113 114 /* For single function, multiple ports */ 115 int num_ports; 116 uint16_t qbase; 117 118 bool isvf; 119 120 /* Packet generator/checker args */ 121 char pkt_gen_args[ARK_MAX_ARG_LEN]; 122 char pkt_chkr_args[ARK_MAX_ARG_LEN]; 123 uint32_t pkt_dir_v; 124 125 /* eth device */ 126 struct rte_eth_dev *eth_dev; 127 128 void *d_handle; 129 struct ark_user_ext user_ext; 130 131 /* Our Bar 0 */ 132 uint8_t *bar0; 133 134 /* Application Bar */ 135 uint8_t *a_bar; 136 137 /* Arkville demo block offsets */ 138 def_ptr(sys_ctrl, sysctrl); 139 def_ptr(pkt_gen, pktgen); 140 def_ptr(mpu_rx, mpurx); 141 def_ptr(UDM, udm); 142 def_ptr(mpu_tx, mputx); 143 def_ptr(DDM, ddm); 144 def_ptr(CMAC, cmac); 145 def_ptr(external, external); 146 def_ptr(pkt_dir, pktdir); 147 def_ptr(pkt_chkr, pktchkr); 148 149 int started; 150 uint16_t rx_queues; 151 uint16_t tx_queues; 152 }; 153 154 typedef uint32_t *ark_t; 155 156 #endif 157