1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2015-2018 Atomic Rules LLC 3 */ 4 5 #ifndef _ARK_MPU_H_ 6 #define _ARK_MPU_H_ 7 8 #include <stdint.h> 9 10 #include <rte_memory.h> 11 12 /* The MPU or Memory Prefetch Unit is an internal Arkville hardware 13 * module for moving data between host memory and the hardware FPGA. 14 * This module is *not* intended for end-user manipulation, hence 15 * there is minimal documentation. 16 */ 17 18 #define ARK_MPU_MODID 0x2055504d 19 #define ARK_MPU_MODVER 0x37313232 20 /* 21 * MPU hardware structures 22 * These are overlay structures to a memory mapped FPGA device. These 23 * structs will never be instantiated in ram memory 24 */ 25 26 #define ARK_MPU_ID 0x00 27 struct ark_mpu_id_t { 28 union { 29 char id[4]; 30 uint32_t idnum; 31 }; 32 union { 33 char ver[4]; 34 uint32_t vernum; 35 }; 36 uint32_t phys_id; 37 uint32_t mrr_code; 38 }; 39 40 #define ARK_MPU_HW 0x010 41 struct ark_mpu_hw_t { 42 uint16_t num_queues; 43 uint16_t reserved; 44 uint32_t hw_depth; 45 uint32_t obj_size; 46 uint32_t obj_per_mrr; 47 }; 48 49 #define ARK_MPU_CFG 0x040 50 struct ark_mpu_cfg_t { 51 rte_iova_t ring_base; /* rte_iova_t is a uint64_t */ 52 uint32_t ring_size; 53 uint32_t ring_mask; 54 uint32_t min_host_move; 55 uint32_t min_hw_move; 56 volatile uint32_t sw_prod_index; 57 volatile uint32_t hw_cons_index; 58 volatile uint32_t command; 59 }; 60 enum ARK_MPU_COMMAND { 61 MPU_CMD_IDLE = 1, 62 MPU_CMD_RUN = 2, 63 MPU_CMD_STOP = 4, 64 MPU_CMD_RESET = 8, 65 MPU_CMD_FORCE_RESET = 16, 66 MPU_COMMAND_LIMIT = 0xfFFFFFFF 67 }; 68 69 /* Consolidated structure */ 70 struct ark_mpu_t { 71 struct ark_mpu_id_t id; 72 uint8_t reserved0[(ARK_MPU_HW - ARK_MPU_ID) 73 - sizeof(struct ark_mpu_id_t)]; 74 struct ark_mpu_hw_t hw; 75 uint8_t reserved1[(ARK_MPU_CFG - ARK_MPU_HW) - 76 sizeof(struct ark_mpu_hw_t)]; 77 struct ark_mpu_cfg_t cfg; 78 }; 79 80 uint16_t ark_api_num_queues(struct ark_mpu_t *mpu); 81 uint16_t ark_api_num_queues_per_port(struct ark_mpu_t *mpu, 82 uint16_t ark_ports); 83 int ark_mpu_verify(struct ark_mpu_t *mpu, uint32_t obj_size); 84 void ark_mpu_stop(struct ark_mpu_t *mpu); 85 void ark_mpu_start(struct ark_mpu_t *mpu); 86 int ark_mpu_reset(struct ark_mpu_t *mpu); 87 int ark_mpu_configure(struct ark_mpu_t *mpu, rte_iova_t ring, 88 uint32_t ring_size, int is_tx); 89 90 void ark_mpu_dump(struct ark_mpu_t *mpu, const char *msg, uint16_t idx); 91 void ark_mpu_dump_setup(struct ark_mpu_t *mpu, uint16_t qid); 92 93 /* this action is in a performance critical path */ 94 static inline void 95 ark_mpu_set_producer(struct ark_mpu_t *mpu, uint32_t idx) 96 { 97 mpu->cfg.sw_prod_index = idx; 98 } 99 100 #endif 101